wined3d: Handle stateblock capture for default lights created while recording.
[wine] / dlls / mshtml / tests / dom.c
1 /*
2  * Copyright 2007-2008 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmcid.h"
31 #include "mshtmhst.h"
32 #include "docobj.h"
33 #include "dispex.h"
34 #include "mshtml_test.h"
35
36 static const char doc_blank[] = "<html></html>";
37 static const char doc_str1[] = "<html><body>test</body></html>";
38 static const char range_test_str[] =
39     "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n  \t</font>text<br /></body></html>";
40 static const char range_test2_str[] =
41     "<html><body>abc<hr />123<br /><hr />def</body></html>";
42 static const char elem_test_str[] =
43     "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
44     "<body onload=\"Testing()\">text test<!-- a comment -->"
45     "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
46     "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
47     "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
48     "<textarea id=\"X\">text text</textarea>"
49     "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
50     "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
51     "<test />"
52     "<img id=\"imgid\" name=\"WineImg\"/>"
53     "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
54     "<form id=\"frm\"></form>"
55     "</body></html>";
56 static const char elem_test2_str[] =
57     "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
58     "<body><div id=\"divid\"></div></body>"
59     "</html>";
60
61 static const char indent_test_str[] =
62     "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
63 static const char cond_comment_str[] =
64     "<html><head><title>test</title></head><body>"
65     "<!--[if gte IE 4]> <br> <![endif]-->"
66     "</body></html>";
67 static const char frameset_str[] =
68     "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
69     "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
70     "<frame src=\"about:blank\" id=\"fr3\">"
71     "</frameset></html>";
72
73 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
74 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
75 static WCHAR wordW[] = {'w','o','r','d',0};
76
77 typedef enum {
78     ET_NONE,
79     ET_HTML,
80     ET_HEAD,
81     ET_TITLE,
82     ET_BODY,
83     ET_A,
84     ET_INPUT,
85     ET_SELECT,
86     ET_TEXTAREA,
87     ET_OPTION,
88     ET_STYLE,
89     ET_BLOCKQUOTE,
90     ET_P,
91     ET_BR,
92     ET_TABLE,
93     ET_TBODY,
94     ET_SCRIPT,
95     ET_TEST,
96     ET_TESTG,
97     ET_COMMENT,
98     ET_IMG,
99     ET_TR,
100     ET_TD,
101     ET_IFRAME,
102     ET_FORM
103 } elem_type_t;
104
105 static const IID * const none_iids[] = {
106     &IID_IUnknown,
107     NULL
108 };
109
110 static const IID * const doc_node_iids[] = {
111     &IID_IHTMLDOMNode,
112     &IID_IHTMLDOMNode2,
113     &IID_IHTMLDocument,
114     &IID_IHTMLDocument2,
115     &IID_IHTMLDocument3,
116     &IID_IHTMLDocument4,
117     &IID_IHTMLDocument5,
118     &IID_IDispatchEx,
119     &IID_IConnectionPointContainer,
120     &IID_IInternetHostSecurityManager,
121     NULL
122 };
123
124 static const IID * const doc_obj_iids[] = {
125     &IID_IHTMLDocument,
126     &IID_IHTMLDocument2,
127     &IID_IHTMLDocument3,
128     &IID_IHTMLDocument4,
129     &IID_IHTMLDocument5,
130     &IID_IDispatchEx,
131     &IID_IConnectionPointContainer,
132     &IID_ICustomDoc,
133     NULL
134 };
135
136 static const IID * const elem_iids[] = {
137     &IID_IHTMLDOMNode,
138     &IID_IHTMLDOMNode2,
139     &IID_IHTMLElement,
140     &IID_IHTMLElement2,
141     &IID_IHTMLElement3,
142     &IID_IDispatchEx,
143     &IID_IConnectionPointContainer,
144     NULL
145 };
146
147 static const IID * const body_iids[] = {
148     &IID_IHTMLDOMNode,
149     &IID_IHTMLDOMNode2,
150     &IID_IHTMLElement,
151     &IID_IHTMLElement2,
152     &IID_IHTMLElement3,
153     &IID_IHTMLTextContainer,
154     &IID_IHTMLBodyElement,
155     &IID_IDispatchEx,
156     &IID_IConnectionPointContainer,
157     NULL
158 };
159
160 static const IID * const anchor_iids[] = {
161     &IID_IHTMLDOMNode,
162     &IID_IHTMLDOMNode2,
163     &IID_IHTMLElement,
164     &IID_IHTMLElement2,
165     &IID_IHTMLElement3,
166     &IID_IHTMLAnchorElement,
167     &IID_IDispatchEx,
168     &IID_IConnectionPointContainer,
169     NULL
170 };
171
172 static const IID * const input_iids[] = {
173     &IID_IHTMLDOMNode,
174     &IID_IHTMLDOMNode2,
175     &IID_IHTMLElement,
176     &IID_IHTMLElement2,
177     &IID_IHTMLElement3,
178     &IID_IHTMLInputElement,
179     &IID_IHTMLInputTextElement,
180     &IID_IDispatchEx,
181     &IID_IConnectionPointContainer,
182     NULL
183 };
184
185 static const IID * const select_iids[] = {
186     &IID_IHTMLDOMNode,
187     &IID_IHTMLDOMNode2,
188     &IID_IHTMLElement,
189     &IID_IHTMLElement2,
190     &IID_IHTMLElement3,
191     &IID_IHTMLSelectElement,
192     &IID_IDispatchEx,
193     &IID_IConnectionPointContainer,
194     NULL
195 };
196
197 static const IID * const textarea_iids[] = {
198     &IID_IHTMLDOMNode,
199     &IID_IHTMLDOMNode2,
200     &IID_IHTMLElement,
201     &IID_IHTMLElement2,
202     &IID_IHTMLElement3,
203     &IID_IHTMLTextAreaElement,
204     &IID_IDispatchEx,
205     &IID_IConnectionPointContainer,
206     NULL
207 };
208
209 static const IID * const option_iids[] = {
210     &IID_IHTMLDOMNode,
211     &IID_IHTMLDOMNode2,
212     &IID_IHTMLElement,
213     &IID_IHTMLElement2,
214     &IID_IHTMLElement3,
215     &IID_IHTMLOptionElement,
216     &IID_IDispatchEx,
217     &IID_IConnectionPointContainer,
218     NULL
219 };
220
221 static const IID * const table_iids[] = {
222     &IID_IHTMLDOMNode,
223     &IID_IHTMLDOMNode2,
224     &IID_IHTMLElement,
225     &IID_IHTMLElement2,
226     &IID_IHTMLElement3,
227     &IID_IHTMLTable,
228     &IID_IDispatchEx,
229     &IID_IConnectionPointContainer,
230     NULL
231 };
232
233 static const IID * const script_iids[] = {
234     &IID_IHTMLDOMNode,
235     &IID_IHTMLDOMNode2,
236     &IID_IHTMLElement,
237     &IID_IHTMLElement2,
238     &IID_IHTMLElement3,
239     &IID_IHTMLScriptElement,
240     &IID_IDispatchEx,
241     &IID_IConnectionPointContainer,
242     NULL
243 };
244
245 static const IID * const text_iids[] = {
246     &IID_IHTMLDOMNode,
247     &IID_IHTMLDOMNode2,
248     &IID_IHTMLDOMTextNode,
249     NULL
250 };
251
252 static const IID * const location_iids[] = {
253     &IID_IDispatch,
254     &IID_IHTMLLocation,
255     NULL
256 };
257
258 static const IID * const window_iids[] = {
259     &IID_IDispatch,
260     &IID_IHTMLWindow2,
261     &IID_IHTMLWindow3,
262     &IID_IDispatchEx,
263     NULL
264 };
265
266 static const IID * const comment_iids[] = {
267     &IID_IHTMLDOMNode,
268     &IID_IHTMLDOMNode2,
269     &IID_IHTMLElement,
270     &IID_IHTMLElement2,
271     &IID_IHTMLElement3,
272     &IID_IHTMLCommentElement,
273     &IID_IDispatchEx,
274     &IID_IConnectionPointContainer,
275     NULL
276 };
277
278 static const IID * const img_iids[] = {
279     &IID_IHTMLDOMNode,
280     &IID_IHTMLDOMNode2,
281     &IID_IHTMLElement,
282     &IID_IHTMLElement2,
283     &IID_IHTMLElement3,
284     &IID_IDispatchEx,
285     &IID_IHTMLImgElement,
286     &IID_IConnectionPointContainer,
287     NULL
288 };
289
290 static const IID * const tr_iids[] = {
291     &IID_IHTMLDOMNode,
292     &IID_IHTMLDOMNode2,
293     &IID_IHTMLElement,
294     &IID_IHTMLElement2,
295     &IID_IHTMLElement3,
296     &IID_IDispatchEx,
297     &IID_IHTMLTableRow,
298     &IID_IConnectionPointContainer,
299     NULL
300 };
301
302 static const IID * const td_iids[] = {
303     &IID_IHTMLDOMNode,
304     &IID_IHTMLDOMNode2,
305     &IID_IHTMLElement,
306     &IID_IHTMLElement2,
307     &IID_IHTMLElement3,
308     &IID_IDispatchEx,
309     &IID_IConnectionPointContainer,
310     NULL
311 };
312
313 static const IID * const iframe_iids[] = {
314     &IID_IHTMLDOMNode,
315     &IID_IHTMLDOMNode2,
316     &IID_IHTMLElement,
317     &IID_IHTMLElement2,
318     &IID_IHTMLElement3,
319     &IID_IHTMLFrameBase,
320     &IID_IHTMLFrameBase2,
321     &IID_IDispatchEx,
322     &IID_IConnectionPointContainer,
323     NULL
324 };
325
326 static const IID * const form_iids[] = {
327     &IID_IHTMLDOMNode,
328     &IID_IHTMLDOMNode2,
329     &IID_IHTMLElement,
330     &IID_IHTMLElement2,
331     &IID_IHTMLElement3,
332     &IID_IHTMLFormElement,
333     &IID_IDispatchEx,
334     &IID_IConnectionPointContainer,
335     NULL
336 };
337
338 static const IID * const generic_iids[] = {
339     &IID_IHTMLDOMNode,
340     &IID_IHTMLDOMNode2,
341     &IID_IHTMLElement,
342     &IID_IHTMLElement2,
343     &IID_IHTMLElement3,
344     &IID_IHTMLGenericElement,
345     &IID_IDispatchEx,
346     &IID_IConnectionPointContainer,
347     NULL
348 };
349
350 static const IID * const style_iids[] = {
351     &IID_IUnknown,
352     &IID_IDispatch,
353     &IID_IDispatchEx,
354     &IID_IHTMLStyle,
355     &IID_IHTMLStyle2,
356     &IID_IHTMLStyle3,
357     &IID_IHTMLStyle4,
358     NULL
359 };
360
361 static const IID * const cstyle_iids[] = {
362     &IID_IUnknown,
363     &IID_IDispatch,
364     &IID_IDispatchEx,
365     &IID_IHTMLCurrentStyle,
366     NULL
367 };
368
369 static const IID * const img_factory_iids[] = {
370     &IID_IUnknown,
371     &IID_IDispatch,
372     &IID_IDispatchEx,
373     &IID_IHTMLImageElementFactory,
374     NULL
375 };
376
377 typedef struct {
378     const char *tag;
379     REFIID *iids;
380     const IID *dispiid;
381 } elem_type_info_t;
382
383 static const elem_type_info_t elem_type_infos[] = {
384     {"",          none_iids,        NULL},
385     {"HTML",      elem_iids,        NULL},
386     {"HEAD",      elem_iids,        NULL},
387     {"TITLE",     elem_iids,        NULL},
388     {"BODY",      body_iids,        &DIID_DispHTMLBody},
389     {"A",         anchor_iids,      &DIID_DispHTMLAnchorElement},
390     {"INPUT",     input_iids,       &DIID_DispHTMLInputElement},
391     {"SELECT",    select_iids,      &DIID_DispHTMLSelectElement},
392     {"TEXTAREA",  textarea_iids,    NULL},
393     {"OPTION",    option_iids,      &DIID_DispHTMLOptionElement},
394     {"STYLE",     elem_iids,        NULL},
395     {"BLOCKQUOTE",elem_iids,        NULL},
396     {"P",         elem_iids,        NULL},
397     {"BR",        elem_iids,        NULL},
398     {"TABLE",     table_iids,       &DIID_DispHTMLTable},
399     {"TBODY",     elem_iids,        NULL},
400     {"SCRIPT",    script_iids,      NULL},
401     {"TEST",      elem_iids,        &DIID_DispHTMLUnknownElement},
402     {"TEST",      generic_iids,     &DIID_DispHTMLGenericElement},
403     {"!",         comment_iids,     &DIID_DispHTMLCommentElement},
404     {"IMG",       img_iids,         &DIID_DispHTMLImg},
405     {"TR",        tr_iids,          &DIID_DispHTMLTableRow},
406     {"TD",        td_iids,          NULL},
407     {"IFRAME",    iframe_iids,      &DIID_DispHTMLIFrame},
408     {"FORM",      form_iids,        &DIID_DispHTMLFormElement}
409 };
410
411 static const char *dbgstr_guid(REFIID riid)
412 {
413     static char buf[50];
414
415     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
416             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
417             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
418             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
419
420     return buf;
421 }
422
423 static int strcmp_wa(LPCWSTR strw, const char *stra)
424 {
425     CHAR buf[512];
426     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
427     return lstrcmpA(stra, buf);
428 }
429
430 static BSTR a2bstr(const char *str)
431 {
432     BSTR ret;
433     int len;
434
435     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
436     ret = SysAllocStringLen(NULL, len);
437     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
438
439     return ret;
440 }
441
442 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
443 {
444     IUnknown *unk1, *unk2;
445
446     if(iface1 == iface2)
447         return TRUE;
448
449     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
450     IUnknown_Release(unk1);
451     IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
452     IUnknown_Release(unk2);
453
454     return unk1 == unk2;
455 }
456
457 static IHTMLDocument2 *create_document(void)
458 {
459     IHTMLDocument2 *doc;
460     IHTMLDocument5 *doc5;
461     HRESULT hres;
462
463     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
464             &IID_IHTMLDocument2, (void**)&doc);
465     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
466     if(FAILED(hres))
467         return NULL;
468
469     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
470     if(FAILED(hres)) {
471         win_skip("Could not get IHTMLDocument5, probably too old IE\n");
472         IHTMLDocument2_Release(doc);
473         return NULL;
474     }
475
476     IHTMLDocument5_Release(doc5);
477     return doc;
478 }
479
480 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
481 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
482 {
483     const IID * const *piid;
484     IUnknown *unk;
485     HRESULT hres;
486
487      for(piid = iids; *piid; piid++) {
488         hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
489         ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
490         if(SUCCEEDED(hres))
491             IUnknown_Release(unk);
492     }
493 }
494
495 #define test_get_dispid(u,id) _test_disp(__LINE__,u,id)
496 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
497 {
498     IDispatchEx *dispex;
499     ITypeInfo *typeinfo;
500     BOOL ret = FALSE;
501     UINT ticnt;
502     HRESULT hres;
503
504     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
505     ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
506     if(FAILED(hres))
507         return FALSE;
508
509     ticnt = 0xdeadbeef;
510     hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
511     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
512     ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
513
514     hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
515     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
516
517     if(SUCCEEDED(hres)) {
518         TYPEATTR *type_attr;
519
520         hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
521         ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
522         if(hres == S_OK) {
523             *iid = type_attr->guid;
524             ret = TRUE;
525         }
526
527         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
528         ITypeInfo_Release(typeinfo);
529     }
530
531     IDispatchEx_Release(dispex);
532     return ret;
533 }
534
535 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
536 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
537 {
538     DISPPARAMS dp  = {NULL,NULL,0,0};
539     IDispatchEx *dispex;
540     EXCEPINFO ei;
541     VARIANT var;
542     HRESULT hres;
543
544     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
545     ok_(__FILE__,line)(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
546     if(FAILED(hres))
547         return;
548
549     hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
550     IDispatchEx_Release(dispex);
551     ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
552
553     ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
554     ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
555     VariantClear(&var);
556 }
557
558 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
559 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
560 {
561     IID iid;
562
563     if(_test_get_dispid(line, unk, &iid))
564         ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
565
566     if(val)
567         _test_disp_value(line, unk, val);
568 }
569
570 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
571 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
572 {
573     IID iid;
574
575     if(_test_get_dispid(line, unk, &iid))
576         ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
577                 "unexpected guid %s\n", dbgstr_guid(&iid));
578
579     if(val)
580         _test_disp_value(line, unk, val);
581 }
582
583 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
584 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
585 {
586     IHTMLElement *elem;
587     HRESULT hres;
588
589     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
590     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
591     return elem;
592 }
593
594 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
595 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
596 {
597     IHTMLElement2 *elem;
598     HRESULT hres;
599
600     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
601     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
602     return elem;
603 }
604
605 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
606 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
607 {
608     IHTMLElement3 *elem;
609     HRESULT hres;
610
611     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
612     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
613     return elem;
614 }
615
616 #define get_node_iface(u) _get_node_iface(__LINE__,u)
617 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
618 {
619     IHTMLDOMNode *node;
620     HRESULT hres;
621
622     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
623     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
624     return node;
625 }
626
627 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
628 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
629 {
630     IHTMLDOMNode2 *node;
631     HRESULT hres;
632
633     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
634     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
635     return node;
636 }
637
638 #define get_img_iface(u) _get_img_iface(__LINE__,u)
639 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
640 {
641     IHTMLImgElement *img;
642     HRESULT hres;
643
644     hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
645     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
646     return img;
647 }
648
649 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
650 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
651 {
652     IHTMLAnchorElement *anchor;
653     HRESULT hres;
654
655     hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
656     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
657     return anchor;
658 }
659
660 #define get_text_iface(u) _get_text_iface(__LINE__,u)
661 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
662 {
663     IHTMLDOMTextNode *text;
664     HRESULT hres;
665
666     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
667     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
668     return text;
669 }
670
671 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
672 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
673 {
674     IHTMLDOMNode *node = _get_node_iface(line, unk);
675     BSTR name;
676     HRESULT hres;
677
678     hres = IHTMLDOMNode_get_nodeName(node, &name);
679     IHTMLDOMNode_Release(node);
680     ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
681     ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
682
683     SysFreeString(name);
684 }
685
686 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
687 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
688 {
689     IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
690     IDispatch *disp = (void*)0xdeadbeef;
691     IHTMLDocument2 *doc = NULL;
692     HRESULT hres;
693
694     hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
695     IHTMLDOMNode2_Release(node);
696     ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
697
698     if(disp) {
699         hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
700         IDispatch_Release(disp);
701         ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
702     }
703
704     return doc;
705 }
706
707 #define get_doc_window(d) _get_doc_window(__LINE__,d)
708 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
709 {
710     IHTMLWindow2 *window;
711     HRESULT hres;
712
713     window = NULL;
714     hres = IHTMLDocument2_get_parentWindow(doc, &window);
715     ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
716     ok_(__FILE__,line)(window != NULL, "window == NULL\n");
717
718     return window;
719 }
720
721 #define clone_node(n,d) _clone_node(__LINE__,n,d)
722 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
723 {
724     IHTMLDOMNode *node = _get_node_iface(line, unk);
725     IHTMLDOMNode *ret = NULL;
726     HRESULT hres;
727
728     hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
729     IHTMLDOMNode_Release(node);
730     ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
731     ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
732
733     return ret;
734
735 }
736
737 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
738 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
739 {
740     IHTMLElement *elem = _get_elem_iface(line, unk);
741     BSTR tag;
742     HRESULT hres;
743
744     hres = IHTMLElement_get_tagName(elem, &tag);
745     IHTMLElement_Release(elem);
746     ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
747     ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
748
749     SysFreeString(tag);
750 }
751
752 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
753 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
754 {
755     _test_elem_tag(line, unk, elem_type_infos[type].tag);
756     _test_ifaces(line, unk, elem_type_infos[type].iids);
757
758     if(elem_type_infos[type].dispiid && type != ET_A)
759         _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
760 }
761
762 #define get_node_type(n) _get_node_type(__LINE__,n)
763 static LONG _get_node_type(unsigned line, IUnknown *unk)
764 {
765     IHTMLDOMNode *node = _get_node_iface(line, unk);
766     LONG type = -1;
767     HRESULT hres;
768
769     hres = IHTMLDOMNode_get_nodeType(node, &type);
770     ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
771
772     IHTMLDOMNode_Release(node);
773
774     return type;
775 }
776
777 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
778 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
779 {
780     IHTMLDOMNode *node = _get_node_iface(line, unk);
781     IHTMLDOMChildrenCollection *col = NULL;
782     IDispatch *disp;
783     HRESULT hres;
784
785     hres = IHTMLDOMNode_get_childNodes(node, &disp);
786     IHTMLDOMNode_Release(node);
787     ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
788     if(FAILED(hres))
789         return NULL;
790
791     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
792     IDispatch_Release(disp);
793     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
794
795     return col;
796 }
797
798 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
799 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
800 {
801     IHTMLDOMNode *node = NULL;
802     IDispatch *disp;
803     HRESULT hres;
804
805     hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
806     ok(hres == S_OK, "item failed: %08x\n", hres);
807
808     node = _get_node_iface(line, (IUnknown*)disp);
809     IDispatch_Release(disp);
810
811     return node;
812 }
813
814 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
815 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
816 {
817     VARIANT value;
818     BSTR tmp;
819     HRESULT hres;
820
821     VariantInit(&value);
822
823     tmp = a2bstr(name);
824     hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
825     SysFreeString(tmp);
826     ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
827
828     if(exval) {
829         ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
830         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
831     }else {
832         ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
833     }
834
835     VariantClear(&value);
836 }
837
838 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
839 static void _test_elem_offset(unsigned line, IUnknown *unk)
840 {
841     IHTMLElement *elem = _get_elem_iface(line, unk);
842     LONG l;
843     HRESULT hres;
844
845     hres = IHTMLElement_get_offsetTop(elem, &l);
846     ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
847
848     hres = IHTMLElement_get_offsetHeight(elem, &l);
849     ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
850
851     hres = IHTMLElement_get_offsetWidth(elem, &l);
852     ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
853
854     IHTMLElement_Release(elem);
855 }
856
857 #define get_doc_node(d) _get_doc_node(__LINE__,d)
858 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
859 {
860     IHTMLWindow2 *window;
861     IHTMLDocument2 *ret;
862     HRESULT hres;
863
864     hres = IHTMLDocument2_get_parentWindow(doc, &window);
865     ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
866
867     hres = IHTMLWindow2_get_document(window, &ret);
868     ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
869     ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
870
871     return ret;
872 }
873
874 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
875 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
876 {
877     BSTR name;
878     HRESULT hres;
879
880     hres = IHTMLWindow2_get_name(window, &name);
881     ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
882     if(exname)
883         ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
884     else
885         ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
886 }
887
888 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
889 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
890 {
891     BSTR str;
892     HRESULT hres;
893
894     str = a2bstr(name);
895     hres = IHTMLWindow2_put_name(window, str);
896     SysFreeString(str);
897     ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
898
899     _test_window_name(line, window, name);
900 }
901
902 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
903 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
904 {
905     LONG length = -1;
906     HRESULT hres;
907
908     hres = IHTMLWindow2_get_length(window, &length);
909     ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
910     ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
911 }
912
913 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
914 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
915 {
916     IHTMLFrameBase2 *base2;
917     IHTMLWindow2 *window;
918     HRESULT hres;
919
920     hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
921     ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
922
923     window = NULL;
924     hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
925     IHTMLFrameBase2_Release(base2);
926     ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
927     ok(window != NULL, "contentWindow = NULL\n");
928
929     return window;
930 }
931
932 static void test_get_set_attr(IHTMLDocument2 *doc)
933 {
934     IHTMLElement *elem;
935     IHTMLDocument3 *doc3;
936     HRESULT hres;
937     BSTR bstr;
938     VARIANT val;
939
940     /* grab an element to test with */
941     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
942     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
943
944     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
945     IHTMLDocument3_Release(doc3);
946     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
947
948     /* get a non-present attribute */
949     bstr = a2bstr("notAnAttribute");
950     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
951     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
952     ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
953     VariantClear(&val);
954     SysFreeString(bstr);
955
956     /* get a present attribute */
957     bstr = a2bstr("scrollHeight");
958     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
959     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
960     ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
961     VariantClear(&val);
962     SysFreeString(bstr);
963
964     /* create a new BSTR attribute */
965     bstr = a2bstr("newAttribute");
966
967     V_VT(&val) = VT_BSTR;
968     V_BSTR(&val) = a2bstr("the value");
969     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
970     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
971     VariantClear(&val);
972
973     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
974     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
975     ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
976     ok(strcmp_wa(V_BSTR(&val), "the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
977     VariantClear(&val);
978
979     /* overwrite the attribute with a BOOL */
980     V_VT(&val) = VT_BOOL;
981     V_BOOL(&val) = VARIANT_TRUE;
982     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
983     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
984     VariantClear(&val);
985
986     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
987     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
988     ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
989     ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
990     VariantClear(&val);
991
992     SysFreeString(bstr);
993
994     /* case-insensitive */
995     bstr = a2bstr("newattribute");
996     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
997     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
998     ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
999     ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1000     VariantClear(&val);
1001     SysFreeString(bstr);
1002
1003     IHTMLElement_Release(elem);
1004 }
1005
1006 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1007 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1008 {
1009     IHTMLElement *elem;
1010     IHTMLDocument3 *doc3;
1011     HRESULT hres;
1012
1013     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1014     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1015     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1016     ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1017     IHTMLDocument3_Release(doc3);
1018
1019     return elem;
1020 }
1021
1022 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1023 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1024 {
1025     IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1026     BSTR str;
1027     HRESULT hres;
1028
1029     hres = IHTMLAnchorElement_get_href(anchor, &str);
1030     ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1031     ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1032     SysFreeString(str);
1033
1034     _test_disp_value(line, unk, exhref);
1035 }
1036
1037 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1038 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1039 {
1040     BSTR bstr;
1041     HRESULT hres;
1042
1043     hres = IHTMLOptionElement_get_text(option, &bstr);
1044     ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1045     ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1046     SysFreeString(bstr);
1047 }
1048
1049 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1050 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1051 {
1052     BSTR bstr;
1053     HRESULT hres;
1054
1055     bstr = a2bstr(text);
1056     hres = IHTMLOptionElement_put_text(option, bstr);
1057     SysFreeString(bstr);
1058     ok(hres == S_OK, "put_text failed: %08x\n", hres);
1059
1060     _test_option_text(line, option, text);
1061 }
1062
1063 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1064 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1065 {
1066     BSTR bstr;
1067     HRESULT hres;
1068
1069     hres = IHTMLOptionElement_get_value(option, &bstr);
1070     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1071     ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1072     SysFreeString(bstr);
1073 }
1074
1075 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1076 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1077 {
1078     BSTR bstr;
1079     HRESULT hres;
1080
1081     bstr = a2bstr(value);
1082     hres = IHTMLOptionElement_put_value(option, bstr);
1083     SysFreeString(bstr);
1084     ok(hres == S_OK, "put_value failed: %08x\n", hres);
1085
1086     _test_option_value(line, option, value);
1087 }
1088
1089 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1090 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1091         const char *txt, const char *val)
1092 {
1093     IHTMLOptionElementFactory *factory;
1094     IHTMLOptionElement *option;
1095     IHTMLWindow2 *window;
1096     VARIANT text, value, empty;
1097     HRESULT hres;
1098
1099     hres = IHTMLDocument2_get_parentWindow(doc, &window);
1100     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1101
1102     hres = IHTMLWindow2_get_Option(window, &factory);
1103     IHTMLWindow2_Release(window);
1104     ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1105
1106     V_VT(&text) = VT_BSTR;
1107     V_BSTR(&text) = a2bstr(txt);
1108     V_VT(&value) = VT_BSTR;
1109     V_BSTR(&value) = a2bstr(val);
1110     V_VT(&empty) = VT_EMPTY;
1111
1112     hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1113     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1114
1115     IHTMLOptionElementFactory_Release(factory);
1116     VariantClear(&text);
1117     VariantClear(&value);
1118
1119     _test_option_text(line, option, txt);
1120     _test_option_value(line, option, val);
1121
1122     return option;
1123 }
1124
1125 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1126 static void _test_img_width(unsigned line, IHTMLImgElement *img, const long exp)
1127 {
1128     LONG found = -1;
1129     HRESULT hres;
1130
1131     hres = IHTMLImgElement_get_width(img, &found);
1132     todo_wine ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1133     todo_wine ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1134 }
1135
1136 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1137 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const long width)
1138 {
1139     HRESULT hres;
1140
1141     hres = IHTMLImgElement_put_width(img, width);
1142     todo_wine ok(hres == S_OK, "put_width failed: %08x\n", hres);
1143
1144     _test_img_width(line, img, width);
1145 }
1146
1147 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1148 static void _test_img_height(unsigned line, IHTMLImgElement *img, const long exp)
1149 {
1150     LONG found = -1;
1151     HRESULT hres;
1152
1153     hres = IHTMLImgElement_get_height(img, &found);
1154     todo_wine ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1155     todo_wine ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1156 }
1157
1158 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1159 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const long height)
1160 {
1161     HRESULT hres;
1162
1163     hres = IHTMLImgElement_put_height(img, height);
1164     todo_wine ok(hres == S_OK, "put_height failed: %08x\n", hres);
1165
1166     _test_img_height(line, img, height);
1167 }
1168
1169 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1170 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1171         LONG wdth, LONG hght)
1172 {
1173     IHTMLImageElementFactory *factory;
1174     IHTMLImgElement *img;
1175     IHTMLWindow2 *window;
1176     VARIANT width, height;
1177     char buf[16];
1178     HRESULT hres;
1179
1180     hres = IHTMLDocument2_get_parentWindow(doc, &window);
1181     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1182
1183     hres = IHTMLWindow2_get_Image(window, &factory);
1184     IHTMLWindow2_Release(window);
1185     ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1186
1187     test_ifaces((IUnknown*)factory, img_factory_iids);
1188     test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1189
1190     if(wdth >= 0){
1191         snprintf(buf, 16, "%d", wdth);
1192         V_VT(&width) = VT_BSTR;
1193         V_BSTR(&width) = a2bstr(buf);
1194     }else{
1195         V_VT(&width) = VT_EMPTY;
1196         wdth = 0;
1197     }
1198
1199     if(hght >= 0){
1200         snprintf(buf, 16, "%d", hght);
1201         V_VT(&height) = VT_BSTR;
1202         V_BSTR(&height) = a2bstr(buf);
1203     }else{
1204         V_VT(&height) = VT_EMPTY;
1205         hght = 0;
1206     }
1207
1208     hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1209     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1210
1211     IHTMLImageElementFactory_Release(factory);
1212     VariantClear(&width);
1213     VariantClear(&height);
1214
1215     if(SUCCEEDED(hres)) {
1216         _test_img_width(line, img, wdth);
1217         _test_img_height(line, img, hght);
1218         return img;
1219     }
1220
1221     return NULL;
1222 }
1223
1224 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1225 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1226 {
1227     LONG len = 0xdeadbeef;
1228     HRESULT hres;
1229
1230     hres = IHTMLSelectElement_get_length(select, &len);
1231     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1232     ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1233 }
1234
1235 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1236 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1237 {
1238     LONG idx = 0xdeadbeef;
1239     HRESULT hres;
1240
1241     hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1242     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1243     ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1244 }
1245
1246 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1247 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1248 {
1249     HRESULT hres;
1250
1251     hres = IHTMLSelectElement_put_selectedIndex(select, index);
1252     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1253     _test_select_selidx(line, select, index);
1254 }
1255
1256 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1257 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1258 {
1259     BSTR val;
1260     HRESULT hres;
1261
1262     hres = IHTMLSelectElement_get_value(select, &val);
1263     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1264     if(exval)
1265         ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1266     else
1267         ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1268 }
1269
1270 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1271 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1272 {
1273     BSTR bstr;
1274     HRESULT hres;
1275
1276     bstr = a2bstr(val);
1277     hres = IHTMLSelectElement_put_value(select, bstr);
1278     SysFreeString(bstr);
1279     ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1280 }
1281
1282 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1283 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1284 {
1285     BSTR type;
1286     HRESULT hres;
1287
1288     hres = IHTMLSelectElement_get_type(select, &type);
1289     ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1290     ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1291 }
1292
1293 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1294 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1295 {
1296     BSTR text;
1297     HRESULT hres;
1298
1299     hres = IHTMLTxtRange_get_text(range, &text);
1300     ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1301
1302     if(extext) {
1303         ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1304         ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1305     }else {
1306         ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1307     }
1308
1309     SysFreeString(text);
1310
1311 }
1312
1313 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1314 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1315 {
1316     HRESULT hres;
1317
1318     hres = IHTMLTxtRange_collapse(range, b);
1319     ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1320     _test_range_text(line, range, NULL);
1321 }
1322
1323 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1324 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1325         VARIANT_BOOL exb, const char *extext)
1326 {
1327     VARIANT_BOOL b = 0xe0e0;
1328     HRESULT hres;
1329
1330     hres = IHTMLTxtRange_expand(range, unit, &b);
1331     ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1332     ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1333     _test_range_text(line, range, extext);
1334 }
1335
1336 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1337 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1338 {
1339     LONG c = 0xdeadbeef;
1340     HRESULT hres;
1341
1342     hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1343     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1344     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1345     _test_range_text(line, range, NULL);
1346 }
1347
1348 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1349 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1350         LPWSTR unit, LONG cnt, LONG excnt)
1351 {
1352     LONG c = 0xdeadbeef;
1353     HRESULT hres;
1354
1355     hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1356     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1357     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1358 }
1359
1360 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1361 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1362 {
1363     LONG c = 0xdeadbeef;
1364     HRESULT hres;
1365
1366     hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1367     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1368     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1369 }
1370
1371 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1372 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1373 {
1374     HRESULT hres;
1375     BSTR bstr = a2bstr(text);
1376
1377     hres = IHTMLTxtRange_put_text(range, bstr);
1378     ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1379     SysFreeString(bstr);
1380     _test_range_text(line, range, NULL);
1381 }
1382
1383 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1384 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1385 {
1386     VARIANT_BOOL b;
1387     HRESULT hres;
1388
1389     b = 0xe0e0;
1390     hres = IHTMLTxtRange_inRange(range1, range2, &b);
1391     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1392     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1393 }
1394
1395 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1396 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1397 {
1398     VARIANT_BOOL b;
1399     HRESULT hres;
1400
1401     b = 0xe0e0;
1402     hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1403     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1404     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1405
1406     b = 0xe0e0;
1407     hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1408     ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1409     ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1410
1411     if(exb) {
1412         test_range_inrange(range1, range2, VARIANT_TRUE);
1413         test_range_inrange(range2, range1, VARIANT_TRUE);
1414     }
1415 }
1416
1417 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1418 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1419 {
1420     IHTMLElement *elem;
1421     HRESULT hres;
1422
1423     hres = IHTMLTxtRange_parentElement(range, &elem);
1424     ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1425
1426     _test_elem_type(line, (IUnknown*)elem, type);
1427
1428     IHTMLElement_Release(elem);
1429 }
1430
1431 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1432 static void _test_elem_collection(unsigned line, IUnknown *unk,
1433         const elem_type_t *elem_types, LONG exlen)
1434 {
1435     IHTMLElementCollection *col;
1436     LONG len;
1437     DWORD i;
1438     VARIANT name, index;
1439     IDispatch *disp, *disp2;
1440     HRESULT hres;
1441
1442     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1443     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1444
1445     test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1446
1447     hres = IHTMLElementCollection_get_length(col, &len);
1448     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1449     ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1450
1451     if(len > exlen)
1452         len = exlen;
1453
1454     V_VT(&index) = VT_EMPTY;
1455
1456     for(i=0; i<len; i++) {
1457         V_VT(&name) = VT_I4;
1458         V_I4(&name) = i;
1459         disp = (void*)0xdeadbeef;
1460         hres = IHTMLElementCollection_item(col, name, index, &disp);
1461         ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1462         ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1463         if(FAILED(hres) || !disp)
1464             continue;
1465
1466         _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1467
1468         if(!i) {
1469             V_VT(&name) = VT_UINT;
1470             V_I4(&name) = 0;
1471             disp2 = (void*)0xdeadbeef;
1472             hres = IHTMLElementCollection_item(col, name, index, &disp2);
1473             ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1474             ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1475             if(disp2)
1476                 IDispatch_Release(disp2);
1477         }
1478
1479         IDispatch_Release(disp);
1480     }
1481
1482     V_VT(&name) = VT_I4;
1483     V_I4(&name) = len;
1484     disp = (void*)0xdeadbeef;
1485     hres = IHTMLElementCollection_item(col, name, index, &disp);
1486     ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1487     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1488
1489     V_VT(&name) = VT_I4;
1490     V_I4(&name) = -1;
1491     disp = (void*)0xdeadbeef;
1492     hres = IHTMLElementCollection_item(col, name, index, &disp);
1493     ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1494     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1495
1496     IHTMLElementCollection_Release(col);
1497 }
1498
1499 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
1500 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
1501 {
1502     IHTMLElement *elem = _get_elem_iface(line, unk);
1503     IDispatch *disp;
1504     HRESULT hres;
1505
1506     hres = IHTMLElement_get_all(elem, &disp);
1507     IHTMLElement_Release(elem);
1508     ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
1509
1510     _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
1511     IDispatch_Release(disp);
1512 }
1513
1514 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1515 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1516 {
1517     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1518     IHTMLElementCollection *col = NULL;
1519     elem_type_t *types = NULL;
1520     BSTR tmp;
1521     int i;
1522     HRESULT hres;
1523
1524     tmp = a2bstr(elem_type_infos[type].tag);
1525     hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1526     SysFreeString(tmp);
1527     IHTMLElement2_Release(elem);
1528     ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1529     ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1530
1531     if(exlen) {
1532         types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1533         for(i=0; i<exlen; i++)
1534             types[i] = type;
1535     }
1536
1537     _test_elem_collection(line, (IUnknown*)col, types, exlen);
1538
1539     HeapFree(GetProcessHeap(), 0, types);
1540 }
1541
1542 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1543 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1544 {
1545     BSTR text = NULL;
1546     HRESULT hres;
1547
1548     hres = IHTMLElement_get_innerText(elem, &text);
1549     ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1550     ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1551                         wine_dbgstr_w(text), extext);
1552     SysFreeString(text);
1553 }
1554
1555 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1556 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1557 {
1558     IHTMLDOMChildrenCollection *col;
1559     BSTR str;
1560     HRESULT hres;
1561
1562     str = a2bstr(text);
1563     hres = IHTMLElement_put_innerText(elem, str);
1564     ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1565     SysFreeString(str);
1566
1567     _test_elem_innertext(line, elem, text);
1568
1569
1570     col = _get_child_nodes(line, (IUnknown*)elem);
1571     ok(col != NULL, "col == NULL\n");
1572     if(col) {
1573         LONG length = 0, type;
1574         IHTMLDOMNode *node;
1575
1576         hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1577         ok(hres == S_OK, "get_length failed: %08x\n", hres);
1578         ok(length == 1, "length = %d\n", length);
1579
1580         node = _get_child_item(line, col, 0);
1581         ok(node != NULL, "node == NULL\n");
1582         if(node) {
1583             type = _get_node_type(line, (IUnknown*)node);
1584             ok(type == 3, "type=%d\n", type);
1585             IHTMLDOMNode_Release(node);
1586         }
1587
1588         IHTMLDOMChildrenCollection_Release(col);
1589     }
1590
1591 }
1592
1593 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
1594 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1595 {
1596     IHTMLElement *elem = _get_elem_iface(line, unk);
1597     BSTR html;
1598     HRESULT hres;
1599
1600     hres = IHTMLElement_get_innerHTML(elem, &html);
1601     ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
1602     if(inner_html)
1603         ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
1604     else
1605         ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
1606
1607     IHTMLElement_Release(elem);
1608     SysFreeString(html);
1609 }
1610
1611 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
1612 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1613 {
1614     IHTMLElement *elem = _get_elem_iface(line, unk);
1615     BSTR html;
1616     HRESULT hres;
1617
1618     html = a2bstr(inner_html);
1619     hres = IHTMLElement_put_innerHTML(elem, html);
1620     ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
1621
1622     IHTMLElement_Release(elem);
1623     SysFreeString(html);
1624 }
1625
1626 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
1627 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
1628 {
1629     IHTMLElement *elem = _get_elem_iface(line, unk);
1630     BSTR html;
1631     HRESULT hres;
1632
1633     html = a2bstr(outer_html);
1634     hres = IHTMLElement_put_outerHTML(elem, html);
1635     ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
1636
1637     IHTMLElement_Release(elem);
1638     SysFreeString(html);
1639 }
1640
1641 #define get_first_child(n) _get_first_child(__LINE__,n)
1642 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1643 {
1644     IHTMLDOMNode *node = _get_node_iface(line, unk);
1645     IHTMLDOMNode *child = NULL;
1646     HRESULT hres;
1647
1648     hres = IHTMLDOMNode_get_firstChild(node, &child);
1649     IHTMLDOMNode_Release(node);
1650     ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1651
1652     return child;
1653 }
1654
1655 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1656 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1657 {
1658     IHTMLDOMNode *node = _get_node_iface(line, unk);
1659     VARIANT_BOOL b = 0xdead;
1660     HRESULT hres;
1661
1662     hres = IHTMLDOMNode_hasChildNodes(node, &b);
1663     ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1664     ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1665
1666     IHTMLDOMNode_Release(node);
1667 }
1668
1669 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1670 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1671 {
1672     IHTMLDOMNode *node = _get_node_iface(line, unk);
1673     IHTMLDOMNode *parent;
1674     HRESULT hres;
1675
1676     hres = IHTMLDOMNode_get_parentNode(node, &parent);
1677     IHTMLDOMNode_Release(node);
1678     ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1679
1680     return parent;
1681 }
1682
1683 #define node_get_next(u) _node_get_next(__LINE__,u)
1684 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
1685 {
1686     IHTMLDOMNode *node = _get_node_iface(line, unk);
1687     IHTMLDOMNode *next;
1688     HRESULT hres;
1689
1690     hres = IHTMLDOMNode_get_nextSibling(node, &next);
1691     IHTMLDOMNode_Release(node);
1692     ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
1693
1694     return next;
1695 }
1696
1697 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1698 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1699 {
1700     IHTMLElement *elem = _get_elem_iface(line, unk);
1701     IHTMLElement *parent;
1702     HRESULT hres;
1703
1704     hres = IHTMLElement_get_parentElement(elem, &parent);
1705     IHTMLElement_Release(elem);
1706     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1707
1708     return parent;
1709 }
1710
1711 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1712 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1713 {
1714     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1715     VARIANT_BOOL disabled = 100;
1716     HRESULT hres;
1717
1718     if (!elem3) return;
1719     hres = IHTMLElement3_get_disabled(elem3, &disabled);
1720     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1721     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1722     IHTMLElement3_Release(elem3);
1723 }
1724
1725 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1726 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1727 {
1728     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1729     HRESULT hres;
1730
1731     if (!elem3) return;
1732     hres = IHTMLElement3_put_disabled(elem3, b);
1733     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1734
1735     IHTMLElement3_Release(elem3);
1736     _test_elem3_get_disabled(line, unk, b);
1737 }
1738
1739 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1740 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1741 {
1742     VARIANT_BOOL disabled = 100;
1743     HRESULT hres;
1744
1745     hres = IHTMLSelectElement_get_disabled(select, &disabled);
1746     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1747     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1748
1749     _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1750 }
1751
1752 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
1753 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
1754 {
1755     IHTMLDOMTextNode *text = _get_text_iface(line, unk);
1756     LONG length;
1757     HRESULT hres;
1758
1759     hres = IHTMLDOMTextNode_get_length(text, &length);
1760     ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1761     ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
1762     IHTMLDOMTextNode_Release(text);
1763 }
1764
1765 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1766 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1767 {
1768     HRESULT hres;
1769
1770     hres = IHTMLSelectElement_put_disabled(select, b);
1771     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1772
1773     _test_select_get_disabled(line, select, b);
1774 }
1775
1776 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1777 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
1778 {
1779     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1780     IHTMLTextContainer *txtcont;
1781     LONG l = -1, l2 = -1;
1782     HRESULT hres;
1783
1784     hres = IHTMLElement2_get_scrollHeight(elem, &l);
1785     ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1786     IHTMLElement2_Release(elem);
1787
1788     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1789     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1790
1791     hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1792     IHTMLTextContainer_Release(txtcont);
1793     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
1794     ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
1795
1796     return l;
1797 }
1798
1799 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1800 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
1801 {
1802     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1803     IHTMLTextContainer *txtcont;
1804     LONG l = -1, l2 = -1;
1805     HRESULT hres;
1806
1807     hres = IHTMLElement2_get_scrollWidth(elem, &l);
1808     ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1809     IHTMLElement2_Release(elem);
1810
1811     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1812     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1813
1814     hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1815     IHTMLTextContainer_Release(txtcont);
1816     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
1817     ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
1818
1819     return l;
1820 }
1821
1822 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1823 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
1824 {
1825     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1826     IHTMLTextContainer *txtcont;
1827     LONG l = -1, l2 = -1;
1828     HRESULT hres;
1829
1830     hres = IHTMLElement2_get_scrollTop(elem, &l);
1831     ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1832     IHTMLElement2_Release(elem);
1833
1834     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1835     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1836
1837     hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1838     IHTMLTextContainer_Release(txtcont);
1839     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
1840     ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
1841
1842     return l;
1843 }
1844
1845 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1846 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1847 {
1848     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1849     IHTMLTextContainer *txtcont;
1850     LONG l = -1, l2 = -1;
1851     HRESULT hres;
1852
1853     hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1854     ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1855
1856     hres = IHTMLElement2_get_scrollLeft(elem, &l);
1857     ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1858     IHTMLElement2_Release(elem);
1859
1860     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1861     ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1862
1863     hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1864     IHTMLTextContainer_Release(txtcont);
1865     ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
1866     ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
1867 }
1868
1869 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1870 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1871 {
1872     IHTMLImgElement *img = _get_img_iface(line, unk);
1873     BSTR src;
1874     HRESULT hres;
1875
1876     hres = IHTMLImgElement_get_src(img, &src);
1877     IHTMLImgElement_Release(img);
1878     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1879     ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
1880     SysFreeString(src);
1881 }
1882
1883 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1884 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1885 {
1886     IHTMLImgElement *img = _get_img_iface(line, unk);
1887     BSTR tmp;
1888     HRESULT hres;
1889
1890     tmp = a2bstr(src);
1891     hres = IHTMLImgElement_put_src(img, tmp);
1892     IHTMLImgElement_Release(img);
1893     SysFreeString(tmp);
1894     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1895
1896     _test_img_src(line, unk, src);
1897 }
1898
1899 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1900 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1901 {
1902     IHTMLImgElement *img = _get_img_iface(line, unk);
1903     BSTR alt;
1904     HRESULT hres;
1905
1906     hres = IHTMLImgElement_get_alt(img, &alt);
1907     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1908     if(exalt)
1909         ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
1910     else
1911         ok_(__FILE__,line) (!alt, "alt != NULL\n");
1912     SysFreeString(alt);
1913 }
1914
1915 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1916 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1917 {
1918     IHTMLImgElement *img = _get_img_iface(line, unk);
1919     BSTR tmp;
1920     HRESULT hres;
1921
1922     tmp = a2bstr(alt);
1923     hres = IHTMLImgElement_put_alt(img, tmp);
1924     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1925     SysFreeString(tmp);
1926
1927     _test_img_alt(line, unk, alt);
1928 }
1929
1930 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
1931 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
1932 {
1933     IHTMLImgElement *img = _get_img_iface(line, unk);
1934     BSTR sName;
1935     HRESULT hres;
1936
1937     hres = IHTMLImgElement_get_name(img, &sName);
1938     ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
1939     ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
1940     SysFreeString(sName);
1941 }
1942
1943
1944 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1945 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1946 {
1947     VARIANT_BOOL disabled = 100;
1948     HRESULT hres;
1949
1950     hres = IHTMLInputElement_get_disabled(input, &disabled);
1951     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1952     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1953
1954     _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1955 }
1956
1957 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1958 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1959 {
1960     HRESULT hres;
1961
1962     hres = IHTMLInputElement_put_disabled(input, b);
1963     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1964
1965     _test_input_get_disabled(line, input, b);
1966 }
1967
1968 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
1969 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1970 {
1971     VARIANT_BOOL checked = 100;
1972     HRESULT hres;
1973
1974     hres = IHTMLInputElement_get_defaultChecked(input, &checked);
1975     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1976     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1977 }
1978
1979 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
1980 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1981 {
1982     HRESULT hres;
1983
1984     hres = IHTMLInputElement_put_defaultChecked(input, b);
1985     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1986
1987     _test_input_get_defaultchecked(line, input, b);
1988 }
1989
1990 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
1991 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1992 {
1993     VARIANT_BOOL checked = 100;
1994     HRESULT hres;
1995
1996     hres = IHTMLInputElement_get_checked(input, &checked);
1997     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1998     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1999 }
2000
2001 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
2002 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2003 {
2004     HRESULT hres;
2005
2006     hres = IHTMLInputElement_put_checked(input, b);
2007     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2008
2009     _test_input_get_checked(line, input, b);
2010 }
2011
2012 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
2013 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
2014 {
2015     IHTMLInputElement *input;
2016     BSTR bstr;
2017     HRESULT hres;
2018
2019     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2020     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2021     if(FAILED(hres))
2022         return;
2023
2024     hres = IHTMLInputElement_get_value(input, &bstr);
2025     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2026     if(exval)
2027         ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
2028     else
2029         ok_(__FILE__,line) (!exval, "exval != NULL\n");
2030     SysFreeString(bstr);
2031     IHTMLInputElement_Release(input);
2032 }
2033
2034 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
2035 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
2036 {
2037     IHTMLInputElement *input;
2038     BSTR bstr;
2039     HRESULT hres;
2040
2041     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2042     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2043     if(FAILED(hres))
2044         return;
2045
2046     bstr = a2bstr(val);
2047     hres = IHTMLInputElement_get_value(input, &bstr);
2048     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2049     SysFreeString(bstr);
2050     IHTMLInputElement_Release(input);
2051 }
2052
2053 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
2054 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
2055 {
2056     BSTR src;
2057     HRESULT hres;
2058
2059     hres = IHTMLInputElement_get_src(input, &src);
2060     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2061     if(exsrc)
2062         ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2063     else
2064         ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
2065     SysFreeString(src);
2066 }
2067
2068 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
2069 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
2070 {
2071     BSTR tmp;
2072     HRESULT hres;
2073
2074     tmp = a2bstr(src);
2075     hres = IHTMLInputElement_put_src(input, tmp);
2076     SysFreeString(tmp);
2077     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2078
2079     _test_input_src(line, input, src);
2080 }
2081
2082 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
2083 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
2084 {
2085     IHTMLElement *elem = _get_elem_iface(line, unk);
2086     BSTR class = (void*)0xdeadbeef;
2087     HRESULT hres;
2088
2089     hres = IHTMLElement_get_className(elem, &class);
2090     IHTMLElement_Release(elem);
2091     ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
2092     if(exclass)
2093         ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
2094     else
2095         ok_(__FILE__,line) (!class, "class != NULL\n");
2096     SysFreeString(class);
2097 }
2098
2099 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
2100 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
2101 {
2102     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2103     short index = -3;
2104     HRESULT hres;
2105
2106     hres = IHTMLElement2_get_tabIndex(elem2, &index);
2107     IHTMLElement2_Release(elem2);
2108     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2109     ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
2110 }
2111
2112 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
2113 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
2114 {
2115     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2116     HRESULT hres;
2117
2118     hres = IHTMLElement2_put_tabIndex(elem2, index);
2119     IHTMLElement2_Release(elem2);
2120     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2121
2122     _test_elem_tabindex(line, unk, index);
2123 }
2124
2125 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
2126 static void _test_elem_filters(unsigned line, IUnknown *unk)
2127 {
2128     IHTMLElement *elem = _get_elem_iface(line, unk);
2129     HRESULT hres;
2130     IHTMLFiltersCollection *filters;
2131
2132     hres = IHTMLElement_get_filters(elem, &filters);
2133     ok_(__FILE__,line) (hres == S_OK, "get_filters failed: %08x\n", hres);
2134     if(hres == S_OK)
2135     {
2136         LONG len;
2137         IDispatchEx *dispex;
2138
2139         hres = IHTMLFiltersCollection_get_length(filters, &len);
2140         ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2141         ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
2142
2143         hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
2144         ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
2145         if(SUCCEEDED(hres)) {
2146             test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
2147             IDispatchEx_Release(dispex);
2148         }
2149
2150         IHTMLFiltersCollection_Release(filters);
2151     }
2152
2153     IHTMLElement_Release(elem);
2154 }
2155
2156 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
2157 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
2158 {
2159     IHTMLElement *elem = _get_elem_iface(line, unk);
2160     BSTR tmp;
2161     HRESULT hres;
2162
2163     tmp = class ? a2bstr(class) : NULL;
2164     hres = IHTMLElement_put_className(elem, tmp);
2165     IHTMLElement_Release(elem);
2166     ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
2167     SysFreeString(tmp);
2168
2169     _test_elem_class(line, unk, class);
2170 }
2171
2172 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
2173 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
2174 {
2175     IHTMLElement *elem = _get_elem_iface(line, unk);
2176     BSTR id = (void*)0xdeadbeef;
2177     HRESULT hres;
2178
2179     hres = IHTMLElement_get_id(elem, &id);
2180     IHTMLElement_Release(elem);
2181     ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
2182
2183     if(exid)
2184         ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
2185     else
2186         ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
2187
2188     SysFreeString(id);
2189 }
2190
2191 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
2192 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
2193 {
2194     IHTMLElement *elem = _get_elem_iface(line, unk);
2195     BSTR tmp = a2bstr(new_id);
2196     HRESULT hres;
2197
2198     hres = IHTMLElement_put_id(elem, tmp);
2199     IHTMLElement_Release(elem);
2200     SysFreeString(tmp);
2201     ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
2202
2203     _test_elem_id(line, unk, new_id);
2204 }
2205
2206 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
2207 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
2208 {
2209     IHTMLElement *elem = _get_elem_iface(line, unk);
2210     BSTR title;
2211     HRESULT hres;
2212
2213     hres = IHTMLElement_get_title(elem, &title);
2214     IHTMLElement_Release(elem);
2215     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2216     if(extitle)
2217         ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2218     else
2219         ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
2220
2221     SysFreeString(title);
2222 }
2223
2224 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
2225 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
2226 {
2227     IHTMLElement *elem = _get_elem_iface(line, unk);
2228     BSTR tmp;
2229     HRESULT hres;
2230
2231     tmp = a2bstr(title);
2232     hres = IHTMLElement_put_title(elem, tmp);
2233     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2234
2235     IHTMLElement_Release(elem);
2236     SysFreeString(tmp);
2237 }
2238
2239 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
2240 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
2241 {
2242     IHTMLDOMNode *node = _get_node_iface(line, unk);
2243     VARIANT var;
2244     HRESULT hres;
2245
2246     hres = IHTMLDOMNode_get_nodeValue(node, &var);
2247     IHTMLDOMNode_Release(node);
2248     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
2249
2250     if(exval) {
2251         ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
2252         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
2253     }else {
2254         ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
2255     }
2256
2257     VariantClear(&var);
2258 }
2259
2260 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
2261 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
2262 {
2263     IHTMLDOMNode *node = _get_node_iface(line, unk);
2264     VARIANT var;
2265     HRESULT hres;
2266
2267     V_VT(&var) = VT_BSTR;
2268     V_BSTR(&var) = a2bstr(val);
2269
2270     hres = IHTMLDOMNode_put_nodeValue(node, var);
2271     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
2272     IHTMLDOMNode_Release(node);
2273     VariantClear(&var);
2274 }
2275
2276 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
2277 static void _test_elem_client_size(unsigned line, IUnknown *unk)
2278 {
2279     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2280     LONG l;
2281     HRESULT hres;
2282
2283     hres = IHTMLElement2_get_clientWidth(elem, &l);
2284     ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
2285     hres = IHTMLElement2_get_clientHeight(elem, &l);
2286     ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
2287
2288     IHTMLElement2_Release(elem);
2289 }
2290
2291 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
2292 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
2293 {
2294     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2295     LONG l;
2296     HRESULT hres;
2297
2298     hres = IHTMLElement2_get_clientLeft(elem, &l);
2299     ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
2300     ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
2301
2302     hres = IHTMLElement2_get_clientTop(elem, &l);
2303     ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
2304     ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
2305
2306     IHTMLElement2_Release(elem);
2307 }
2308
2309 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
2310 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
2311 {
2312     IHTMLElement *elem = _get_elem_iface(line, unk);
2313     IHTMLDocument2 *doc;
2314     IDispatch *disp;
2315     HRESULT hres;
2316
2317     disp = NULL;
2318     hres = IHTMLElement_get_document(elem, &disp);
2319     ok(hres == S_OK, "get_document failed: %08x\n", hres);
2320     ok(disp != NULL, "disp == NULL\n");
2321
2322     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
2323     IDispatch_Release(disp);
2324     ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
2325
2326     return doc;
2327 }
2328
2329 #define get_window_doc(e) _get_window_doc(__LINE__,e)
2330 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
2331 {
2332     IHTMLDocument2 *doc;
2333     HRESULT hres;
2334
2335     doc = NULL;
2336     hres = IHTMLWindow2_get_document(window, &doc);
2337     ok(hres == S_OK, "get_document failed: %08x\n", hres);
2338     ok(doc != NULL, "disp == NULL\n");
2339
2340     return doc;
2341 }
2342
2343 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
2344 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
2345 {
2346     IHTMLElement *elem = NULL;
2347     BSTR tmp;
2348     HRESULT hres;
2349
2350     tmp = a2bstr(tag);
2351     hres = IHTMLDocument2_createElement(doc, tmp, &elem);
2352     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
2353     ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
2354
2355     return elem;
2356 }
2357
2358 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
2359 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
2360 {
2361     IHTMLDocument3 *doc3;
2362     IHTMLDOMNode *node = NULL;
2363     BSTR tmp;
2364     HRESULT hres;
2365
2366     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2367     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
2368
2369     tmp = a2bstr(text);
2370     hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
2371     IHTMLDocument3_Release(doc3);
2372     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
2373     ok_(__FILE__,line) (node != NULL, "node == NULL\n");
2374
2375     return node;
2376 }
2377
2378 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
2379 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
2380 {
2381     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
2382     IHTMLDOMNode *child = _get_node_iface(line, child_unk);
2383     IHTMLDOMNode *new_child = NULL;
2384     HRESULT hres;
2385
2386     hres = IHTMLDOMNode_appendChild(node, child, &new_child);
2387     ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
2388     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
2389     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
2390
2391     IHTMLDOMNode_Release(node);
2392     IHTMLDOMNode_Release(child);
2393
2394     return new_child;
2395 }
2396
2397 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
2398 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
2399 {
2400     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
2401     IHTMLDOMNode *new_child = NULL;
2402     HRESULT hres;
2403
2404     hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
2405     ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
2406     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
2407     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
2408
2409     IHTMLDOMNode_Release(node);
2410
2411     return new_child;
2412 }
2413
2414 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
2415 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
2416 {
2417     IHTMLDOMNode *node = _get_node_iface(line, unk);
2418     IHTMLDOMNode *new_node = NULL;
2419     HRESULT hres;
2420
2421     hres = IHTMLDOMNode_removeChild(node, child, &new_node);
2422     ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
2423     ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
2424     /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
2425
2426     IHTMLDOMNode_Release(node);
2427     IHTMLDOMNode_Release(new_node);
2428 }
2429
2430 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
2431 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
2432 {
2433     BSTR title = NULL;
2434     HRESULT hres;
2435
2436     hres = IHTMLDocument2_get_title(doc, &title);
2437     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2438     ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2439     SysFreeString(title);
2440 }
2441
2442 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
2443 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
2444 {
2445     BSTR tmp;
2446     HRESULT hres;
2447
2448     tmp = a2bstr(title);
2449     hres = IHTMLDocument2_put_title(doc, tmp);
2450     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2451     SysFreeString(tmp);
2452 }
2453
2454 #define test_border_styles(p, n) _test_border_styles(__LINE__, p, n)
2455 static void _test_border_styles(unsigned line, IHTMLStyle *pStyle, BSTR Name)
2456 {
2457     HRESULT hres;
2458     DISPID dispid;
2459
2460     hres = IHTMLStyle_GetIDsOfNames(pStyle, &IID_NULL, &Name, 1,
2461                         LOCALE_USER_DEFAULT, &dispid);
2462     ok_(__FILE__,line) (hres == S_OK, "GetIDsOfNames: %08x\n", hres);
2463     if(hres == S_OK)
2464     {
2465         DISPPARAMS params = {NULL,NULL,0,0};
2466         DISPID dispidNamed = DISPID_PROPERTYPUT;
2467         VARIANT ret;
2468         VARIANT vDefault;
2469         VARIANTARG arg;
2470
2471         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2472             DISPATCH_PROPERTYGET, &params, &vDefault, NULL, NULL);
2473         ok_(__FILE__,line) (hres == S_OK, "get_default. ret: %08x\n", hres);
2474
2475         params.cArgs = 1;
2476         params.cNamedArgs = 1;
2477         params.rgdispidNamedArgs = &dispidNamed;
2478         V_VT(&arg) = VT_BSTR;
2479         V_BSTR(&arg) = a2bstr("none");
2480         params.rgvarg = &arg;
2481         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2482             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2483         ok_(__FILE__,line) (hres == S_OK, "none. ret: %08x\n", hres);
2484         VariantClear(&arg);
2485
2486         V_VT(&arg) = VT_BSTR;
2487         V_BSTR(&arg) = a2bstr("dotted");
2488         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2489             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2490         ok_(__FILE__,line) (hres == S_OK, "dotted. ret: %08x\n", hres);
2491         VariantClear(&arg);
2492
2493         V_VT(&arg) = VT_BSTR;
2494         V_BSTR(&arg) = a2bstr("dashed");
2495         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2496         DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2497         ok_(__FILE__,line) (hres == S_OK, "dashed. ret: %08x\n", hres);
2498         VariantClear(&arg);
2499
2500         V_VT(&arg) = VT_BSTR;
2501         V_BSTR(&arg) = a2bstr("solid");
2502         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2503             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2504         ok_(__FILE__,line) (hres == S_OK, "solid. ret: %08x\n", hres);
2505         VariantClear(&arg);
2506
2507         V_VT(&arg) = VT_BSTR;
2508         V_BSTR(&arg) = a2bstr("double");
2509         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2510             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2511         ok_(__FILE__,line) (hres == S_OK, "double. ret: %08x\n", hres);
2512         VariantClear(&arg);
2513
2514         V_VT(&arg) = VT_BSTR;
2515         V_BSTR(&arg) = a2bstr("groove");
2516         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2517             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2518         ok_(__FILE__,line) (hres == S_OK, "groove. ret: %08x\n", hres);
2519         VariantClear(&arg);
2520
2521         V_VT(&arg) = VT_BSTR;
2522         V_BSTR(&arg) = a2bstr("ridge");
2523         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2524             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2525         ok_(__FILE__,line) (hres == S_OK, "ridge. ret: %08x\n", hres);
2526         VariantClear(&arg);
2527
2528         V_VT(&arg) = VT_BSTR;
2529         V_BSTR(&arg) = a2bstr("inset");
2530         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2531             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2532         ok_(__FILE__,line) (hres == S_OK, "inset. ret: %08x\n", hres);
2533         VariantClear(&arg);
2534
2535         V_VT(&arg) = VT_BSTR;
2536         V_BSTR(&arg) = a2bstr("outset");
2537         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2538             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2539         ok_(__FILE__,line) (hres == S_OK, "outset. ret: %08x\n", hres);
2540         VariantClear(&arg);
2541
2542         V_VT(&arg) = VT_BSTR;
2543         V_BSTR(&arg) = a2bstr("invalid");
2544         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2545             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2546         ok_(__FILE__,line) (FAILED(hres), "invalid value passed.\n");
2547         VariantClear(&arg);
2548
2549         params.rgvarg = &vDefault;
2550         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2551             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2552         ok_(__FILE__,line) (hres == S_OK, "default. ret: %08x\n", hres);
2553     }
2554 }
2555
2556 #define test_style_csstext(s,t) _test_style_csstext(__LINE__,s,t)
2557 static void _test_style_csstext(unsigned line, IHTMLStyle *style, const char *extext)
2558 {
2559     BSTR text = (void*)0xdeadbeef;
2560     HRESULT hres;
2561
2562     hres = IHTMLStyle_get_cssText(style, &text);
2563     ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
2564     if(extext)
2565         ok_(__FILE__,line)(!strcmp_wa(text, extext), "cssText = %s\n", wine_dbgstr_w(text));
2566     else
2567         ok_(__FILE__,line)(!text, "cssText = %s\n", wine_dbgstr_w(text));
2568
2569     SysFreeString(text);
2570 }
2571
2572 #define test_style_set_csstext(s,t) _test_style_set_csstext(__LINE__,s,t)
2573 static void _test_style_set_csstext(unsigned line, IHTMLStyle *style, const char *text)
2574 {
2575     BSTR tmp;
2576     HRESULT hres;
2577
2578     tmp = a2bstr(text);
2579     hres = IHTMLStyle_put_cssText(style, tmp);
2580     ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
2581     SysFreeString(tmp);
2582 }
2583
2584 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
2585         const elem_type_t *elem_types, LONG len)
2586 {
2587     IDispatch *disp;
2588     VARIANT name, index;
2589     DWORD i;
2590     HRESULT hres;
2591
2592     V_VT(&index) = VT_EMPTY;
2593     V_VT(&name) = VT_BSTR;
2594     V_BSTR(&name) = a2bstr(n);
2595
2596     hres = IHTMLElementCollection_item(col, name, index, &disp);
2597     ok(hres == S_OK, "item failed: %08x\n", hres);
2598
2599     test_elem_collection((IUnknown*)disp, elem_types, len);
2600     IDispatch_Release(disp);
2601     ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
2602     if(hres != S_OK)
2603         goto cleanup;
2604
2605     V_VT(&index) = VT_I4;
2606
2607     for(i=0; i<len; i++) {
2608         V_I4(&index) = i;
2609         disp = (void*)0xdeadbeef;
2610         hres = IHTMLElementCollection_item(col, name, index, &disp);
2611         ok(hres == S_OK, "item failed: %08x\n", hres);
2612         ok(disp != NULL, "disp == NULL\n");
2613         if(FAILED(hres) || !disp)
2614             continue;
2615
2616         test_elem_type((IUnknown*)disp, elem_types[i]);
2617
2618         IDispatch_Release(disp);
2619     }
2620
2621     V_I4(&index) = len;
2622     disp = (void*)0xdeadbeef;
2623     hres = IHTMLElementCollection_item(col, name, index, &disp);
2624     ok(hres == S_OK, "item failed: %08x\n", hres);
2625     ok(disp == NULL, "disp != NULL\n");
2626
2627     V_I4(&index) = -1;
2628     disp = (void*)0xdeadbeef;
2629     hres = IHTMLElementCollection_item(col, name, index, &disp);
2630     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2631     ok(disp == NULL, "disp != NULL\n");
2632
2633 cleanup:
2634     SysFreeString(V_BSTR(&name));
2635 }
2636
2637 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
2638 {
2639     IHTMLElementCollection *col;
2640     IHTMLElement *elem;
2641     IDispatch *disp = (void*)0xdeadbeef;
2642     VARIANT name, index;
2643     HRESULT hres;
2644
2645     hres = IHTMLDocument2_get_all(doc, &col);
2646     ok(hres == S_OK, "get_all failed: %08x\n", hres);
2647     ok(col != NULL, "col == NULL\n");
2648     if(FAILED(hres) || !col)
2649         return NULL;
2650
2651     V_VT(&index) = VT_EMPTY;
2652     V_VT(&name) = VT_BSTR;
2653     V_BSTR(&name) = a2bstr(id);
2654
2655     hres = IHTMLElementCollection_item(col, name, index, &disp);
2656     IHTMLElementCollection_Release(col);
2657     SysFreeString(V_BSTR(&name));
2658     ok(hres == S_OK, "item failed: %08x\n", hres);
2659     if(!expect_success) {
2660         ok(disp == NULL, "disp != NULL\n");
2661         return NULL;
2662     }
2663
2664     ok(disp != NULL, "disp == NULL\n");
2665     if(!disp)
2666         return NULL;
2667
2668     elem = get_elem_iface((IUnknown*)disp);
2669     IDispatch_Release(disp);
2670
2671     return elem;
2672 }
2673
2674 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
2675 {
2676     IHTMLDocument3 *doc3;
2677     IHTMLElement *elem;
2678     BSTR tmp;
2679     HRESULT hres;
2680
2681     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2682     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
2683
2684     tmp = a2bstr(id);
2685     hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
2686     SysFreeString(tmp);
2687     ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
2688
2689     IHTMLDocument3_Release(doc3);
2690
2691     return elem;
2692 }
2693
2694 static void test_select_elem(IHTMLSelectElement *select)
2695 {
2696     test_select_type(select, "select-one");
2697     test_select_length(select, 2);
2698     test_select_selidx(select, 0);
2699     test_select_put_selidx(select, 1);
2700
2701     test_select_set_value(select, "val1");
2702     test_select_value(select, "val1");
2703
2704     test_select_get_disabled(select, VARIANT_FALSE);
2705     test_select_set_disabled(select, VARIANT_TRUE);
2706     test_select_set_disabled(select, VARIANT_FALSE);
2707 }
2708
2709 static void test_create_option_elem(IHTMLDocument2 *doc)
2710 {
2711     IHTMLOptionElement *option;
2712
2713     option = create_option_elem(doc, "test text", "test value");
2714
2715     test_option_put_text(option, "new text");
2716     test_option_put_value(option, "new value");
2717
2718     IHTMLOptionElement_Release(option);
2719 }
2720
2721 static void test_create_img_elem(IHTMLDocument2 *doc)
2722 {
2723     IHTMLImgElement *img;
2724
2725     img = create_img_elem(doc, 10, 15);
2726
2727     if(img){
2728         test_img_put_width(img, 5);
2729         test_img_put_height(img, 20);
2730
2731         IHTMLImgElement_Release(img);
2732         img = NULL;
2733     }
2734
2735     img = create_img_elem(doc, -1, -1);
2736
2737     if(img){
2738         test_img_put_width(img, 5);
2739         test_img_put_height(img, 20);
2740
2741         IHTMLImgElement_Release(img);
2742     }
2743 }
2744
2745 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
2746 {
2747     IHTMLBodyElement *body;
2748     IHTMLTxtRange *range;
2749     IHTMLElement *elem;
2750     HRESULT hres;
2751
2752     hres = IHTMLDocument2_get_body(doc, &elem);
2753     ok(hres == S_OK, "get_body failed: %08x\n", hres);
2754
2755     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2756     IHTMLElement_Release(elem);
2757
2758     hres = IHTMLBodyElement_createTextRange(body, &range);
2759     IHTMLBodyElement_Release(body);
2760     ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
2761
2762     return range;
2763 }
2764
2765 static void test_txtrange(IHTMLDocument2 *doc)
2766 {
2767     IHTMLTxtRange *body_range, *range, *range2;
2768     IHTMLSelectionObject *selection;
2769     IDispatch *disp_range;
2770     HRESULT hres;
2771
2772     body_range = test_create_body_range(doc);
2773
2774     test_range_text(body_range, "test abc 123\r\nit's text");
2775
2776     hres = IHTMLTxtRange_duplicate(body_range, &range);
2777     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2778
2779     hres = IHTMLTxtRange_duplicate(body_range, &range2);
2780     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2781     test_range_isequal(range, range2, VARIANT_TRUE);
2782
2783     test_range_text(range, "test abc 123\r\nit's text");
2784     test_range_text(body_range, "test abc 123\r\nit's text");
2785
2786     test_range_collapse(range, TRUE);
2787     test_range_isequal(range, range2, VARIANT_FALSE);
2788     test_range_inrange(range, range2, VARIANT_FALSE);
2789     test_range_inrange(range2, range, VARIANT_TRUE);
2790     IHTMLTxtRange_Release(range2);
2791
2792     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2793     test_range_expand(range, wordW, VARIANT_FALSE, "test ");
2794     test_range_move(range, characterW, 2, 2);
2795     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2796
2797     test_range_collapse(range, FALSE);
2798     test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
2799
2800     test_range_collapse(range, FALSE);
2801     test_range_expand(range, wordW, VARIANT_TRUE, "123");
2802     test_range_expand(range, wordW, VARIANT_FALSE, "123");
2803     test_range_move(range, characterW, 2, 2);
2804     test_range_expand(range, wordW, VARIANT_TRUE, "123");
2805     test_range_moveend(range, characterW, -5, -5);
2806     test_range_text(range, NULL);
2807     test_range_moveend(range, characterW, 3, 3);
2808     test_range_text(range, "c 1");
2809     test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
2810     test_range_collapse(range, TRUE);
2811     test_range_move(range, characterW, 4, 4);
2812     test_range_moveend(range, characterW, 1, 1);
2813     test_range_text(range, " ");
2814     test_range_move(range, wordW, 1, 1);
2815     test_range_moveend(range, characterW, 2, 2);
2816     test_range_text(range, "ab");
2817
2818     IHTMLTxtRange_Release(range);
2819
2820     hres = IHTMLTxtRange_duplicate(body_range, &range);
2821     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2822
2823     test_range_text(range, "test abc 123\r\nit's text");
2824     test_range_move(range, characterW, 3, 3);
2825     test_range_moveend(range, characterW, 1, 1);
2826     test_range_text(range, "t");
2827     test_range_moveend(range, characterW, 3, 3);
2828     test_range_text(range, "t ab");
2829     test_range_moveend(range, characterW, -2, -2);
2830     test_range_text(range, "t ");
2831     test_range_move(range, characterW, 6, 6);
2832     test_range_moveend(range, characterW, 3, 3);
2833     test_range_text(range, "123");
2834     test_range_moveend(range, characterW, 2, 2);
2835     test_range_text(range, "123\r\ni");
2836
2837     IHTMLTxtRange_Release(range);
2838
2839     hres = IHTMLTxtRange_duplicate(body_range, &range);
2840     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2841
2842     test_range_move(range, wordW, 1, 1);
2843     test_range_moveend(range, characterW, 2, 2);
2844     test_range_text(range, "ab");
2845
2846     test_range_move(range, characterW, -2, -2);
2847     test_range_moveend(range, characterW, 2, 2);
2848     test_range_text(range, "t ");
2849
2850     test_range_move(range, wordW, 3, 3);
2851     test_range_move(range, wordW, -2, -2);
2852     test_range_moveend(range, characterW, 2, 2);
2853     test_range_text(range, "ab");
2854
2855     test_range_move(range, characterW, -6, -5);
2856     test_range_moveend(range, characterW, -1, 0);
2857     test_range_moveend(range, characterW, -6, 0);
2858     test_range_move(range, characterW, 2, 2);
2859     test_range_moveend(range, characterW, 2, 2);
2860     test_range_text(range, "st");
2861     test_range_moveend(range, characterW, -6, -4);
2862     test_range_moveend(range, characterW, 2, 2);
2863
2864     IHTMLTxtRange_Release(range);
2865
2866     hres = IHTMLTxtRange_duplicate(body_range, &range);
2867     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2868
2869     test_range_move(range, wordW, 2, 2);
2870     test_range_moveend(range, characterW, 2, 2);
2871     test_range_text(range, "12");
2872
2873     test_range_move(range, characterW, 15, 14);
2874     test_range_move(range, characterW, -2, -2);
2875     test_range_moveend(range, characterW, 3, 2);
2876     test_range_text(range, "t");
2877     test_range_moveend(range, characterW, -1, -1);
2878     test_range_text(range, "t");
2879     test_range_expand(range, wordW, VARIANT_TRUE, "text");
2880     test_range_move(range, characterW, -2, -2);
2881     test_range_moveend(range, characterW, 2, 2);
2882     test_range_text(range, "s ");
2883     test_range_move(range, characterW, 100, 7);
2884     test_range_move(range, wordW, 1, 0);
2885     test_range_move(range, characterW, -2, -2);
2886     test_range_moveend(range, characterW, 3, 2);
2887     test_range_text(range, "t");
2888
2889     IHTMLTxtRange_Release(range);
2890
2891     hres = IHTMLTxtRange_duplicate(body_range, &range);
2892     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2893
2894     test_range_collapse(range, TRUE);
2895     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2896     test_range_put_text(range, "word");
2897     test_range_text(body_range, "wordabc 123\r\nit's text");
2898     test_range_text(range, NULL);
2899     test_range_moveend(range, characterW, 3, 3);
2900     test_range_text(range, "abc");
2901     test_range_movestart(range, characterW, -2, -2);
2902     test_range_text(range, "rdabc");
2903     test_range_movestart(range, characterW, 3, 3);
2904     test_range_text(range, "bc");
2905     test_range_movestart(range, characterW, 4, 4);
2906     test_range_text(range, NULL);
2907     test_range_movestart(range, characterW, -3, -3);
2908     test_range_text(range, "c 1");
2909     test_range_movestart(range, characterW, -7, -6);
2910     test_range_text(range, "wordabc 1");
2911     test_range_movestart(range, characterW, 100, 22);
2912     test_range_text(range, NULL);
2913
2914     IHTMLTxtRange_Release(range);
2915     IHTMLTxtRange_Release(body_range);
2916
2917     hres = IHTMLDocument2_get_selection(doc, &selection);
2918     ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
2919
2920     hres = IHTMLSelectionObject_createRange(selection, &disp_range);
2921     ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
2922     IHTMLSelectionObject_Release(selection);
2923
2924     hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
2925     ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
2926     IDispatch_Release(disp_range);
2927
2928     test_range_text(range, NULL);
2929     test_range_moveend(range, characterW, 3, 3);
2930     test_range_text(range, "wor");
2931     test_range_parent(range, ET_BODY);
2932     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2933     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2934     test_range_move(range, characterW, 3, 3);
2935     test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
2936     test_range_moveend(range, characterW, -4, -4);
2937     test_range_put_text(range, "abc def ");
2938     test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
2939     test_range_move(range, wordW, 1, 1);
2940     test_range_movestart(range, characterW, -1, -1);
2941     test_range_text(range, " ");
2942     test_range_move(range, wordW, 1, 1);
2943     test_range_moveend(range, characterW, 3, 3);
2944     test_range_text(range, "def");
2945     test_range_put_text(range, "xyz");
2946     test_range_moveend(range, characterW, 1, 1);
2947     test_range_move(range, wordW, 1, 1);
2948     test_range_moveend(range, characterW, 2, 2);
2949     test_range_text(range, "ab");
2950
2951     IHTMLTxtRange_Release(range);
2952 }
2953
2954 static void test_txtrange2(IHTMLDocument2 *doc)
2955 {
2956     IHTMLTxtRange *range;
2957
2958     range = test_create_body_range(doc);
2959
2960     test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
2961     test_range_move(range, characterW, 5, 5);
2962     test_range_moveend(range, characterW, 1, 1);
2963     test_range_text(range, "2");
2964     test_range_move(range, characterW, -3, -3);
2965     test_range_moveend(range, characterW, 3, 3);
2966     test_range_text(range, "c\r\n\r\n1");
2967     test_range_collapse(range, VARIANT_FALSE);
2968     test_range_moveend(range, characterW, 4, 4);
2969     test_range_text(range, "23");
2970     test_range_moveend(range, characterW, 1, 1);
2971     test_range_text(range, "23\r\n\r\n\r\nd");
2972     test_range_moveend(range, characterW, -1, -1);
2973     test_range_text(range, "23");
2974     test_range_moveend(range, characterW, -1, -1);
2975     test_range_text(range, "23");
2976     test_range_moveend(range, characterW, -2, -2);
2977     test_range_text(range, "2");
2978
2979     IHTMLTxtRange_Release(range);
2980 }
2981
2982 static void test_compatmode(IHTMLDocument2 *doc)
2983 {
2984     IHTMLDocument5 *doc5;
2985     BSTR mode;
2986     HRESULT hres;
2987
2988     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2989     ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2990     if(FAILED(hres))
2991         return;
2992
2993     hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2994     IHTMLDocument5_Release(doc5);
2995     ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2996     ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
2997     SysFreeString(mode);
2998 }
2999
3000 static void test_location(IHTMLDocument2 *doc)
3001 {
3002     IHTMLLocation *location, *location2;
3003     IHTMLWindow2 *window;
3004     BSTR str;
3005     ULONG ref;
3006     HRESULT hres;
3007
3008     hres = IHTMLDocument2_get_location(doc, &location);
3009     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3010
3011     hres = IHTMLDocument2_get_location(doc, &location2);
3012     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3013
3014     ok(location == location2, "location != location2\n");
3015     IHTMLLocation_Release(location2);
3016
3017     hres = IHTMLDocument2_get_parentWindow(doc, &window);
3018     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3019
3020     hres = IHTMLWindow2_get_location(window, &location2);
3021     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3022     ok(location == location2, "location != location2\n");
3023     IHTMLLocation_Release(location2);
3024
3025     test_ifaces((IUnknown*)location, location_iids);
3026     test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
3027
3028     hres = IHTMLLocation_get_pathname(location, &str);
3029     ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
3030     ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
3031
3032     hres = IHTMLLocation_get_href(location, NULL);
3033     ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
3034
3035     hres = IHTMLLocation_get_href(location, &str);
3036     ok(hres == S_OK, "get_href failed: %08x\n", hres);
3037     ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
3038
3039     ref = IHTMLLocation_Release(location);
3040     ok(!ref, "location chould be destroyed here\n");
3041 }
3042
3043 static void test_navigator(IHTMLDocument2 *doc)
3044 {
3045     IHTMLWindow2 *window;
3046     IOmNavigator *navigator, *navigator2;
3047     char buf[512];
3048     DWORD size;
3049     ULONG ref;
3050     BSTR bstr;
3051     HRESULT hres;
3052
3053     static const WCHAR v40[] = {'4','.','0'};
3054
3055     hres = IHTMLDocument2_get_parentWindow(doc, &window);
3056     ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
3057
3058     hres = IHTMLWindow2_get_navigator(window, &navigator);
3059     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
3060     ok(navigator != NULL, "navigator == NULL\n");
3061     test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
3062
3063     hres = IHTMLWindow2_get_navigator(window, &navigator2);
3064     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
3065     ok(navigator != navigator2, "navigator2 != navihgator\n");
3066
3067     IHTMLWindow2_Release(window);
3068     IOmNavigator_Release(navigator2);
3069
3070     hres = IOmNavigator_get_appCodeName(navigator, &bstr);
3071     ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
3072     ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
3073     SysFreeString(bstr);
3074
3075     bstr = NULL;
3076     hres = IOmNavigator_get_appName(navigator, &bstr);
3077     ok(hres == S_OK, "get_appName failed: %08x\n", hres);
3078     ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
3079     SysFreeString(bstr);
3080
3081     bstr = NULL;
3082     hres = IOmNavigator_get_platform(navigator, &bstr);
3083     ok(hres == S_OK, "get_platform failed: %08x\n", hres);
3084 #ifdef _WIN64
3085     ok(!strcmp_wa(bstr, "Win64"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
3086 #else
3087     ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
3088 #endif
3089     SysFreeString(bstr);
3090
3091     bstr = NULL;
3092     hres = IOmNavigator_get_appVersion(navigator, &bstr);
3093     ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
3094     ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
3095     SysFreeString(bstr);
3096
3097     hres = IOmNavigator_toString(navigator, NULL);
3098     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
3099
3100     bstr = NULL;
3101     hres = IOmNavigator_toString(navigator, &bstr);
3102     ok(hres == S_OK, "toString failed: %08x\n", hres);
3103     ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
3104     SysFreeString(bstr);
3105
3106     size = sizeof(buf);
3107     hres = ObtainUserAgentString(0, buf, &size);
3108     ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
3109
3110     bstr = NULL;
3111     hres = IOmNavigator_get_userAgent(navigator, &bstr);
3112     ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
3113     ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
3114     SysFreeString(bstr);
3115
3116     ref = IOmNavigator_Release(navigator);
3117     ok(!ref, "navigator should be destroyed here\n");
3118 }
3119
3120 static void test_screen(IHTMLWindow2 *window)
3121 {
3122     IHTMLScreen *screen, *screen2;
3123     IDispatchEx *dispex;
3124     LONG l, exl;
3125     HDC hdc;
3126     HRESULT hres;
3127
3128     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
3129
3130     screen = NULL;
3131     hres = IHTMLWindow2_get_screen(window, &screen);
3132     ok(hres == S_OK, "get_screen failed: %08x\n", hres);
3133     ok(screen != NULL, "screen == NULL\n");
3134
3135     screen2 = NULL;
3136     hres = IHTMLWindow2_get_screen(window, &screen2);
3137     ok(hres == S_OK, "get_screen failed: %08x\n", hres);
3138     ok(screen2 != NULL, "screen == NULL\n");
3139     ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
3140     IHTMLScreen_Release(screen2);
3141
3142     hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
3143     ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
3144     if(SUCCEEDED(hres)) {
3145         test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
3146         IDispatchEx_Release(dispex);
3147     }
3148
3149     hdc = CreateICW(displayW, NULL, NULL, NULL);
3150
3151     exl = GetDeviceCaps(hdc, HORZRES);
3152     l = 0xdeadbeef;
3153     hres = IHTMLScreen_get_width(screen, &l);
3154     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3155     ok(l == exl, "width = %d, expected %d\n", l, exl);
3156
3157     exl = GetDeviceCaps(hdc, VERTRES);
3158     l = 0xdeadbeef;
3159     hres = IHTMLScreen_get_height(screen, &l);
3160     ok(hres == S_OK, "get_height failed: %08x\n", hres);
3161     ok(l == exl, "height = %d, expected %d\n", l, exl);
3162
3163     exl = GetDeviceCaps(hdc, BITSPIXEL);
3164     l = 0xdeadbeef;
3165     hres = IHTMLScreen_get_colorDepth(screen, &l);
3166     ok(hres == S_OK, "get_height failed: %08x\n", hres);
3167     ok(l == exl, "height = %d, expected %d\n", l, exl);
3168
3169     DeleteObject(hdc);
3170
3171     IHTMLScreen_Release(screen);
3172 }
3173
3174 static void test_current_style(IHTMLCurrentStyle *current_style)
3175 {
3176     BSTR str;
3177     HRESULT hres;
3178     VARIANT v;
3179
3180     test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle, "[object]");
3181     test_ifaces((IUnknown*)current_style, cstyle_iids);
3182
3183     hres = IHTMLCurrentStyle_get_display(current_style, &str);
3184     ok(hres == S_OK, "get_display failed: %08x\n", hres);
3185     ok(!strcmp_wa(str, "block"), "get_display returned %s\n", wine_dbgstr_w(str));
3186     SysFreeString(str);
3187
3188     hres = IHTMLCurrentStyle_get_position(current_style, &str);
3189     ok(hres == S_OK, "get_position failed: %08x\n", hres);
3190     ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
3191     SysFreeString(str);
3192
3193     hres = IHTMLCurrentStyle_get_fontFamily(current_style, &str);
3194     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
3195     SysFreeString(str);
3196
3197     hres = IHTMLCurrentStyle_get_fontStyle(current_style, &str);
3198     ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
3199     ok(!strcmp_wa(str, "normal"), "get_fontStyle returned %s\n", wine_dbgstr_w(str));
3200     SysFreeString(str);
3201
3202     hres = IHTMLCurrentStyle_get_backgroundImage(current_style, &str);
3203     ok(hres == S_OK, "get_backgroundImage failed: %08x\n", hres);
3204     ok(!strcmp_wa(str, "none"), "get_backgroundImage returned %s\n", wine_dbgstr_w(str));
3205     SysFreeString(str);
3206
3207     hres = IHTMLCurrentStyle_get_fontVariant(current_style, &str);
3208     ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
3209     ok(!strcmp_wa(str, "normal"), "get_fontVariant returned %s\n", wine_dbgstr_w(str));
3210     SysFreeString(str);
3211
3212     hres = IHTMLCurrentStyle_get_borderTopStyle(current_style, &str);
3213     ok(hres == S_OK, "get_borderTopStyle failed: %08x\n", hres);
3214     ok(!strcmp_wa(str, "none"), "get_borderTopStyle returned %s\n", wine_dbgstr_w(str));
3215     SysFreeString(str);
3216
3217     hres = IHTMLCurrentStyle_get_borderRightStyle(current_style, &str);
3218     ok(hres == S_OK, "get_borderRightStyle failed: %08x\n", hres);
3219     ok(!strcmp_wa(str, "none"), "get_borderRightStyle returned %s\n", wine_dbgstr_w(str));
3220     SysFreeString(str);
3221
3222     hres = IHTMLCurrentStyle_get_borderBottomStyle(current_style, &str);
3223     ok(hres == S_OK, "get_borderBottomStyle failed: %08x\n", hres);
3224     ok(!strcmp_wa(str, "none"), "get_borderBottomStyle returned %s\n", wine_dbgstr_w(str));
3225     SysFreeString(str);
3226
3227     hres = IHTMLCurrentStyle_get_borderLeftStyle(current_style, &str);
3228     ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
3229     ok(!strcmp_wa(str, "none"), "get_borderLeftStyle returned %s\n", wine_dbgstr_w(str));
3230     SysFreeString(str);
3231
3232     hres = IHTMLCurrentStyle_get_textAlign(current_style, &str);
3233     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
3234     ok(!strcmp_wa(str, "center"), "get_textAlign returned %s\n", wine_dbgstr_w(str));
3235     SysFreeString(str);
3236
3237     hres = IHTMLCurrentStyle_get_textDecoration(current_style, &str);
3238     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3239     ok(!strcmp_wa(str, "none"), "get_textDecoration returned %s\n", wine_dbgstr_w(str));
3240     SysFreeString(str);
3241
3242     hres = IHTMLCurrentStyle_get_cursor(current_style, &str);
3243     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
3244     ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
3245     SysFreeString(str);
3246
3247     hres = IHTMLCurrentStyle_get_backgroundRepeat(current_style, &str);
3248     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
3249     ok(!strcmp_wa(str, "repeat"), "get_backgroundRepeat returned %s\n", wine_dbgstr_w(str));
3250     SysFreeString(str);
3251
3252     hres = IHTMLCurrentStyle_get_borderColor(current_style, &str);
3253     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
3254     SysFreeString(str);
3255
3256     hres = IHTMLCurrentStyle_get_borderStyle(current_style, &str);
3257     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
3258     SysFreeString(str);
3259
3260     hres = IHTMLCurrentStyle_get_visibility(current_style, &str);
3261     ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
3262     SysFreeString(str);
3263
3264     hres = IHTMLCurrentStyle_get_overflow(current_style, &str);
3265     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3266     SysFreeString(str);
3267
3268     hres = IHTMLCurrentStyle_get_borderWidth(current_style, &str);
3269     ok(hres == S_OK, "get_borderWidth failed: %08x\n", hres);
3270     SysFreeString(str);
3271
3272     hres = IHTMLCurrentStyle_get_margin(current_style, &str);
3273     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3274     SysFreeString(str);
3275
3276     hres = IHTMLCurrentStyle_get_fontWeight(current_style, &v);
3277     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3278     ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
3279     ok( V_I4(&v) == 400, "expect 400 got (%d)\n", V_I4(&v));
3280     VariantClear(&v);
3281
3282     hres = IHTMLCurrentStyle_get_fontSize(current_style, &v);
3283     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
3284     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3285     VariantClear(&v);
3286
3287     hres = IHTMLCurrentStyle_get_left(current_style, &v);
3288     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3289     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3290     VariantClear(&v);
3291
3292     hres = IHTMLCurrentStyle_get_top(current_style, &v);
3293     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3294     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3295     VariantClear(&v);
3296
3297     hres = IHTMLCurrentStyle_get_width(current_style, &v);
3298     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3299     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3300     VariantClear(&v);
3301
3302     hres = IHTMLCurrentStyle_get_height(current_style, &v);
3303     ok(hres == S_OK, "get_height failed: %08x\n", hres);
3304     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3305     VariantClear(&v);
3306
3307     hres = IHTMLCurrentStyle_get_paddingLeft(current_style, &v);
3308     ok(hres == S_OK, "get_paddingLeft failed: %08x\n", hres);
3309     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3310     VariantClear(&v);
3311
3312     hres = IHTMLCurrentStyle_get_zIndex(current_style, &v);
3313     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
3314     ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
3315     ok( V_I4(&v) == 1, "expect 1 got (%d)\n", V_I4(&v));
3316     VariantClear(&v);
3317
3318     hres = IHTMLCurrentStyle_get_verticalAlign(current_style, &v);
3319     ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
3320     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3321     ok(!strcmp_wa(V_BSTR(&v), "middle"), "get_verticalAlign returned %s\n", wine_dbgstr_w(V_BSTR(&v)));
3322     VariantClear(&v);
3323
3324     hres = IHTMLCurrentStyle_get_marginRight(current_style, &v);
3325     ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
3326     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3327     VariantClear(&v);
3328
3329     hres = IHTMLCurrentStyle_get_marginLeft(current_style, &v);
3330     ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
3331     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3332     VariantClear(&v);
3333
3334     hres = IHTMLCurrentStyle_get_borderLeftWidth(current_style, &v);
3335     ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
3336     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3337     VariantClear(&v);
3338
3339     V_BSTR(&v) = NULL;
3340     hres = IHTMLCurrentStyle_get_borderRightWidth(current_style, &v);
3341     ok(hres == S_OK, "get_borderRightWidth failed: %08x\n", hres);
3342     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3343     VariantClear(&v);
3344
3345     hres = IHTMLCurrentStyle_get_borderBottomWidth(current_style, &v);
3346     ok(hres == S_OK, "get_borderBottomWidth failed: %08x\n", hres);
3347     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3348     VariantClear(&v);
3349
3350     hres = IHTMLCurrentStyle_get_borderTopWidth(current_style, &v);
3351     ok(hres == S_OK, "get_borderTopWidth failed: %08x\n", hres);
3352     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3353     VariantClear(&v);
3354
3355     hres = IHTMLCurrentStyle_get_color(current_style, &v);
3356     ok(hres == S_OK, "get_color failed: %08x\n", hres);
3357     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3358     VariantClear(&v);
3359
3360     hres = IHTMLCurrentStyle_get_backgroundColor(current_style, &v);
3361     ok(hres == S_OK, "get_backgroundColor failed: %08x\n", hres);
3362     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3363     VariantClear(&v);
3364
3365     hres = IHTMLCurrentStyle_get_borderLeftColor(current_style, &v);
3366     ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
3367     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3368     VariantClear(&v);
3369
3370     hres = IHTMLCurrentStyle_get_borderTopColor(current_style, &v);
3371     ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
3372     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3373     VariantClear(&v);
3374
3375     hres = IHTMLCurrentStyle_get_borderRightColor(current_style, &v);
3376     ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
3377     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3378     VariantClear(&v);
3379
3380     hres = IHTMLCurrentStyle_get_borderBottomColor(current_style, &v);
3381     ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
3382     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3383     VariantClear(&v);
3384
3385     hres = IHTMLCurrentStyle_get_paddingTop(current_style, &v);
3386     ok(hres == S_OK, "get_paddingTop failed: %08x\n", hres);
3387     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3388     VariantClear(&v);
3389
3390     hres = IHTMLCurrentStyle_get_paddingRight(current_style, &v);
3391     ok(hres == S_OK, "get_paddingRight failed: %08x\n", hres);
3392     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3393     VariantClear(&v);
3394
3395     hres = IHTMLCurrentStyle_get_paddingBottom(current_style, &v);
3396     ok(hres == S_OK, "get_paddingRight failed: %08x\n", hres);
3397     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3398     VariantClear(&v);
3399
3400     hres = IHTMLCurrentStyle_get_letterSpacing(current_style, &v);
3401     ok(hres == S_OK, "get_letterSpacing failed: %08x\n", hres);
3402     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3403     VariantClear(&v);
3404
3405     hres = IHTMLCurrentStyle_get_marginTop(current_style, &v);
3406     ok(hres == S_OK, "get_marginTop failed: %08x\n", hres);
3407     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3408     VariantClear(&v);
3409
3410     hres = IHTMLCurrentStyle_get_marginBottom(current_style, &v);
3411     ok(hres == S_OK, "get_marginBottom failed: %08x\n", hres);
3412     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3413     VariantClear(&v);
3414
3415     hres = IHTMLCurrentStyle_get_right(current_style, &v);
3416     ok(hres == S_OK, "get_Right failed: %08x\n", hres);
3417     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3418     VariantClear(&v);
3419
3420     hres = IHTMLCurrentStyle_get_bottom(current_style, &v);
3421     ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
3422     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3423     VariantClear(&v);
3424
3425     hres = IHTMLCurrentStyle_get_lineHeight(current_style, &v);
3426     ok(hres == S_OK, "get_lineHeight failed: %08x\n", hres);
3427     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3428     VariantClear(&v);
3429
3430     hres = IHTMLCurrentStyle_get_textIndent(current_style, &v);
3431     ok(hres == S_OK, "get_textIndent failed: %08x\n", hres);
3432     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3433     VariantClear(&v);
3434 }
3435
3436 static void test_style2(IHTMLStyle2 *style2)
3437 {
3438     VARIANT v;
3439     BSTR str;
3440     HRESULT hres;
3441
3442     str = (void*)0xdeadbeef;
3443     hres = IHTMLStyle2_get_position(style2, &str);
3444     ok(hres == S_OK, "get_position failed: %08x\n", hres);
3445     ok(!str, "str != NULL\n");
3446
3447     str = a2bstr("absolute");
3448     hres = IHTMLStyle2_put_position(style2, str);
3449     ok(hres == S_OK, "put_position failed: %08x\n", hres);
3450     SysFreeString(str);
3451
3452     str = NULL;
3453     hres = IHTMLStyle2_get_position(style2, &str);
3454     ok(hres == S_OK, "get_position failed: %08x\n", hres);
3455     ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
3456     SysFreeString(str);
3457
3458     /* Test right */
3459     V_VT(&v) = VT_EMPTY;
3460     hres = IHTMLStyle2_get_right(style2, &v);
3461     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3462     ok(V_VT(&v) == VT_BSTR, "V_VT(right)=%d\n", V_VT(&v));
3463     ok(!V_BSTR(&v), "V_BSTR(right) != NULL\n");
3464     VariantClear(&v);
3465
3466     V_VT(&v) = VT_BSTR;
3467     V_BSTR(&v) = a2bstr("3px");
3468     hres = IHTMLStyle2_put_right(style2, v);
3469     ok(hres == S_OK, "put_right failed: %08x\n", hres);
3470     VariantClear(&v);
3471
3472     V_VT(&v) = VT_EMPTY;
3473     hres = IHTMLStyle2_get_right(style2, &v);
3474     ok(hres == S_OK, "get_right failed: %08x\n", hres);
3475     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3476     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3477     VariantClear(&v);
3478 }
3479
3480 static void test_style3(IHTMLStyle3 *style3)
3481 {
3482     BSTR str;
3483     HRESULT hres;
3484
3485     str = (void*)0xdeadbeef;
3486     hres = IHTMLStyle3_get_wordWrap(style3, &str);
3487     ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
3488     ok(!str, "str != NULL\n");
3489
3490     str = a2bstr("break-word");
3491     hres = IHTMLStyle3_put_wordWrap(style3, str);
3492     ok(hres == S_OK, "put_wordWrap failed: %08x\n", hres);
3493     SysFreeString(str);
3494
3495     str = NULL;
3496     hres = IHTMLStyle3_get_wordWrap(style3, &str);
3497     ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
3498     ok(!strcmp_wa(str, "break-word"), "get_wordWrap returned %s\n", wine_dbgstr_w(str));
3499     SysFreeString(str);
3500 }
3501
3502 static void test_style4(IHTMLStyle4 *style4)
3503 {
3504     HRESULT hres;
3505     VARIANT v;
3506     VARIANT vdefault;
3507
3508     hres = IHTMLStyle4_get_minHeight(style4, &vdefault);
3509     ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
3510
3511     V_VT(&v) = VT_BSTR;
3512     V_BSTR(&v) = a2bstr("10px");
3513     hres = IHTMLStyle4_put_minHeight(style4, v);
3514     ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
3515     VariantClear(&v);
3516
3517     hres = IHTMLStyle4_get_minHeight(style4, &v);
3518     ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
3519     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3520     ok( !strcmp_wa(V_BSTR(&v), "10px"), "expect 10px got (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
3521
3522     hres = IHTMLStyle4_put_minHeight(style4, vdefault);
3523     ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
3524     VariantClear(&vdefault);
3525 }
3526
3527 static void test_default_style(IHTMLStyle *style)
3528 {
3529     IHTMLStyle2 *style2;
3530     IHTMLStyle3 *style3;
3531     IHTMLStyle4 *style4;
3532     VARIANT_BOOL b;
3533     VARIANT v;
3534     BSTR str;
3535     HRESULT hres;
3536     float f;
3537     BSTR sOverflowDefault;
3538     BSTR sDefault;
3539     VARIANT vDefault;
3540
3541     test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
3542     test_ifaces((IUnknown*)style, style_iids);
3543
3544     test_style_csstext(style, NULL);
3545
3546     hres = IHTMLStyle_get_position(style, &str);
3547     ok(hres == S_OK, "get_position failed: %08x\n", hres);
3548     ok(!str, "str=%s\n", wine_dbgstr_w(str));
3549
3550     V_VT(&v) = VT_NULL;
3551     hres = IHTMLStyle_get_marginRight(style, &v);
3552     ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
3553     ok(V_VT(&v) == VT_BSTR, "V_VT(marginRight) = %d\n", V_VT(&v));
3554     ok(!V_BSTR(&v), "V_BSTR(marginRight) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3555
3556     V_VT(&v) = VT_NULL;
3557     hres = IHTMLStyle_get_marginLeft(style, &v);
3558     ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
3559     ok(V_VT(&v) == VT_BSTR, "V_VT(marginLeft) = %d\n", V_VT(&v));
3560     ok(!V_BSTR(&v), "V_BSTR(marginLeft) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3561
3562     str = (void*)0xdeadbeef;
3563     hres = IHTMLStyle_get_fontFamily(style, &str);
3564     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
3565     ok(!str, "fontFamily = %s\n", wine_dbgstr_w(str));
3566
3567     str = (void*)0xdeadbeef;
3568     hres = IHTMLStyle_get_fontWeight(style, &str);
3569     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3570     ok(!str, "fontWeight = %s\n", wine_dbgstr_w(str));
3571
3572     hres = IHTMLStyle_get_fontWeight(style, &sDefault);
3573     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3574
3575     str = a2bstr("test");
3576     hres = IHTMLStyle_put_fontWeight(style, str);
3577     ok(hres == E_INVALIDARG, "put_fontWeight failed: %08x\n", hres);
3578     SysFreeString(str);
3579
3580     str = a2bstr("bold");
3581     hres = IHTMLStyle_put_fontWeight(style, str);
3582     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3583     SysFreeString(str);
3584
3585     str = a2bstr("bolder");
3586     hres = IHTMLStyle_put_fontWeight(style, str);
3587     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3588     SysFreeString(str);
3589
3590     str = a2bstr("lighter");
3591     hres = IHTMLStyle_put_fontWeight(style, str);
3592     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3593     SysFreeString(str);
3594
3595     str = a2bstr("100");
3596     hres = IHTMLStyle_put_fontWeight(style, str);
3597     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3598     SysFreeString(str);
3599
3600     str = a2bstr("200");
3601     hres = IHTMLStyle_put_fontWeight(style, str);
3602     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3603     SysFreeString(str);
3604
3605     str = a2bstr("300");
3606     hres = IHTMLStyle_put_fontWeight(style, str);
3607     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3608     SysFreeString(str);
3609
3610     str = a2bstr("400");
3611     hres = IHTMLStyle_put_fontWeight(style, str);
3612     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3613     SysFreeString(str);
3614
3615     str = a2bstr("500");
3616     hres = IHTMLStyle_put_fontWeight(style, str);
3617     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3618     SysFreeString(str);
3619
3620     str = a2bstr("600");
3621     hres = IHTMLStyle_put_fontWeight(style, str);
3622     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3623     SysFreeString(str);
3624
3625     str = a2bstr("700");
3626     hres = IHTMLStyle_put_fontWeight(style, str);
3627     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3628     SysFreeString(str);
3629
3630     str = a2bstr("800");
3631     hres = IHTMLStyle_put_fontWeight(style, str);
3632     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3633     SysFreeString(str);
3634
3635     str = a2bstr("900");
3636     hres = IHTMLStyle_put_fontWeight(style, str);
3637     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3638     SysFreeString(str);
3639
3640     hres = IHTMLStyle_get_fontWeight(style, &str);
3641     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3642     ok(!strcmp_wa(str, "900"), "str != style900\n");
3643     SysFreeString(str);
3644
3645     hres = IHTMLStyle_put_fontWeight(style, sDefault);
3646     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3647     SysFreeString(sDefault);
3648
3649     /* font Variant */
3650     hres = IHTMLStyle_get_fontVariant(style, NULL);
3651     ok(hres == E_INVALIDARG, "get_fontVariant failed: %08x\n", hres);
3652
3653     hres = IHTMLStyle_get_fontVariant(style, &sDefault);
3654     ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
3655
3656     str = a2bstr("test");
3657     hres = IHTMLStyle_put_fontVariant(style, str);
3658     ok(hres == E_INVALIDARG, "fontVariant failed: %08x\n", hres);
3659     SysFreeString(str);
3660
3661     str = a2bstr("small-caps");
3662     hres = IHTMLStyle_put_fontVariant(style, str);
3663     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3664     SysFreeString(str);
3665
3666     str = a2bstr("normal");
3667     hres = IHTMLStyle_put_fontVariant(style, str);
3668     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3669     SysFreeString(str);
3670
3671     hres = IHTMLStyle_put_fontVariant(style, sDefault);
3672     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3673     SysFreeString(sDefault);
3674
3675     str = (void*)0xdeadbeef;
3676     hres = IHTMLStyle_get_display(style, &str);
3677     ok(hres == S_OK, "get_display failed: %08x\n", hres);
3678     ok(!str, "display = %s\n", wine_dbgstr_w(str));
3679
3680     str = (void*)0xdeadbeef;
3681     hres = IHTMLStyle_get_visibility(style, &str);
3682     ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
3683     ok(!str, "visibility = %s\n", wine_dbgstr_w(str));
3684
3685     V_VT(&v) = VT_NULL;
3686     hres = IHTMLStyle_get_fontSize(style, &v);
3687     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
3688     ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
3689     ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3690
3691     V_VT(&v) = VT_NULL;
3692     hres = IHTMLStyle_get_color(style, &v);
3693     ok(hres == S_OK, "get_color failed: %08x\n", hres);
3694     ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
3695     ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3696
3697     b = 0xfefe;
3698     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
3699     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
3700     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
3701
3702     hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_TRUE);
3703     ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
3704     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
3705
3706     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
3707     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
3708     ok(b == VARIANT_TRUE, "textDecorationUnderline = %x\n", b);
3709
3710     hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_FALSE);
3711     ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
3712
3713     b = 0xfefe;
3714     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
3715     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
3716     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
3717
3718     hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_TRUE);
3719     ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
3720     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
3721
3722     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
3723     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
3724     ok(b == VARIANT_TRUE, "textDecorationLineThrough = %x\n", b);
3725
3726     hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_FALSE);
3727     ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
3728
3729     b = 0xfefe;
3730     hres = IHTMLStyle_get_textDecorationNone(style, &b);
3731     ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
3732     ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
3733
3734     hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_TRUE);
3735     ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
3736     ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
3737
3738     hres = IHTMLStyle_get_textDecorationNone(style, &b);
3739     ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
3740     ok(b == VARIANT_TRUE, "textDecorationNone = %x\n", b);
3741
3742     hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_FALSE);
3743     ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
3744
3745     b = 0xfefe;
3746     hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3747     ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3748     ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3749
3750     hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_TRUE);
3751     ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3752     ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3753
3754     hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3755     ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3756     ok(b == VARIANT_TRUE, "textDecorationOverline = %x\n", b);
3757
3758     hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_FALSE);
3759     ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3760
3761     b = 0xfefe;
3762     hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3763     ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3764     ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3765
3766     hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_TRUE);
3767     ok(hres == S_OK, "put_textDecorationBlink failed: %08x\n", hres);
3768     ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3769
3770     hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3771     ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3772     ok(b == VARIANT_TRUE, "textDecorationBlink = %x\n", b);
3773
3774     hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_FALSE);
3775     ok(hres == S_OK, "textDecorationBlink failed: %08x\n", hres);
3776
3777     hres = IHTMLStyle_get_textDecoration(style, &sDefault);
3778     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3779
3780     str = a2bstr("invalid");
3781     hres = IHTMLStyle_put_textDecoration(style, str);
3782     ok(hres == E_INVALIDARG, "put_textDecoration failed: %08x\n", hres);
3783     SysFreeString(str);
3784
3785     str = a2bstr("none");
3786     hres = IHTMLStyle_put_textDecoration(style, str);
3787     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3788     SysFreeString(str);
3789
3790     str = a2bstr("underline");
3791     hres = IHTMLStyle_put_textDecoration(style, str);
3792     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3793     SysFreeString(str);
3794
3795     str = a2bstr("overline");
3796     hres = IHTMLStyle_put_textDecoration(style, str);
3797     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3798     SysFreeString(str);
3799
3800     str = a2bstr("line-through");
3801     hres = IHTMLStyle_put_textDecoration(style, str);
3802     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3803     SysFreeString(str);
3804
3805     str = a2bstr("blink");
3806     hres = IHTMLStyle_put_textDecoration(style, str);
3807     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3808     SysFreeString(str);
3809
3810     hres = IHTMLStyle_get_textDecoration(style, &str);
3811     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3812     ok(!strcmp_wa(str, "blink"), "str != blink\n");
3813     SysFreeString(str);
3814
3815     hres = IHTMLStyle_put_textDecoration(style, sDefault);
3816     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3817     SysFreeString(sDefault);
3818
3819     hres = IHTMLStyle_get_posWidth(style, NULL);
3820     ok(hres == E_POINTER, "get_posWidth failed: %08x\n", hres);
3821
3822     hres = IHTMLStyle_get_posWidth(style, &f);
3823     ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3824     ok(f == 0.0f, "f = %f\n", f);
3825
3826     V_VT(&v) = VT_EMPTY;
3827     hres = IHTMLStyle_get_width(style, &v);
3828     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3829     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3830     ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
3831
3832     hres = IHTMLStyle_put_posWidth(style, 2.2);
3833     ok(hres == S_OK, "put_posWidth failed: %08x\n", hres);
3834
3835     hres = IHTMLStyle_get_posWidth(style, &f);
3836     ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3837     ok(f == 2.0f ||
3838        f == 2.2f, /* IE8 */
3839        "f = %f\n", f);
3840
3841     V_VT(&v) = VT_BSTR;
3842     V_BSTR(&v) = a2bstr("auto");
3843     hres = IHTMLStyle_put_width(style, v);
3844     ok(hres == S_OK, "put_width failed: %08x\n", hres);
3845     VariantClear(&v);
3846
3847     V_VT(&v) = VT_EMPTY;
3848     hres = IHTMLStyle_get_width(style, &v);
3849     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3850     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3851     ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3852     VariantClear(&v);
3853
3854     /* margin tests */
3855     str = (void*)0xdeadbeef;
3856     hres = IHTMLStyle_get_margin(style, &str);
3857     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3858     ok(!str, "margin = %s\n", wine_dbgstr_w(str));
3859
3860     str = a2bstr("1");
3861     hres = IHTMLStyle_put_margin(style, str);
3862     ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3863     SysFreeString(str);
3864
3865     hres = IHTMLStyle_get_margin(style, &str);
3866     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3867     ok(!strcmp_wa(str, "1px"), "margin = %s\n", wine_dbgstr_w(str));
3868
3869     hres = IHTMLStyle_put_margin(style, NULL);
3870     ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3871
3872     str = (void*)0xdeadbeef;
3873     hres = IHTMLStyle_get_marginTop(style, &v);
3874     ok(hres == S_OK, "get_marginTop failed: %08x\n", hres);
3875     ok(V_VT(&v) == VT_BSTR, "V_VT(marginTop) = %d\n", V_VT(&v));
3876     ok(!V_BSTR(&v), "V_BSTR(marginTop) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3877
3878     V_VT(&v) = VT_BSTR;
3879     V_BSTR(&v) = a2bstr("6px");
3880     hres = IHTMLStyle_put_marginTop(style, v);
3881     SysFreeString(V_BSTR(&v));
3882     ok(hres == S_OK, "put_marginTop failed: %08x\n", hres);
3883
3884     str = (void*)0xdeadbeef;
3885     hres = IHTMLStyle_get_marginTop(style, &v);
3886     ok(hres == S_OK, "get_marginTop failed: %08x\n", hres);
3887     ok(V_VT(&v) == VT_BSTR, "V_VT(marginTop) = %d\n", V_VT(&v));
3888     ok(!strcmp_wa(V_BSTR(&v), "6px"), "V_BSTR(marginTop) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3889
3890     str = NULL;
3891     hres = IHTMLStyle_get_border(style, &str);
3892     ok(hres == S_OK, "get_border failed: %08x\n", hres);
3893     ok(!str || !*str, "str is not empty\n");
3894     SysFreeString(str);
3895
3896     str = a2bstr("1px");
3897     hres = IHTMLStyle_put_border(style, str);
3898     ok(hres == S_OK, "put_border failed: %08x\n", hres);
3899     SysFreeString(str);
3900
3901     V_VT(&v) = VT_EMPTY;
3902     hres = IHTMLStyle_get_left(style, &v);
3903     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3904     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3905     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3906     VariantClear(&v);
3907
3908     /* Test posLeft */
3909     hres = IHTMLStyle_get_posLeft(style, NULL);
3910     ok(hres == E_POINTER, "get_posLeft failed: %08x\n", hres);
3911
3912     f = 1.0f;
3913     hres = IHTMLStyle_get_posLeft(style, &f);
3914     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3915     ok(f == 0.0, "expected 0.0 got %f\n", f);
3916
3917     hres = IHTMLStyle_put_posLeft(style, 4.9f);
3918     ok(hres == S_OK, "put_posLeft failed: %08x\n", hres);
3919
3920     hres = IHTMLStyle_get_posLeft(style, &f);
3921     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3922     ok(f == 4.0 ||
3923        f == 4.9f, /* IE8 */
3924        "expected 4.0 or 4.9 (IE8) got %f\n", f);
3925
3926     /* Ensure left is updated correctly. */
3927     V_VT(&v) = VT_EMPTY;
3928     hres = IHTMLStyle_get_left(style, &v);
3929     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3930     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3931     ok(!strcmp_wa(V_BSTR(&v), "4px") ||
3932        !strcmp_wa(V_BSTR(&v), "4.9px"), /* IE8 */
3933        "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3934     VariantClear(&v);
3935
3936     /* Test left */
3937     V_VT(&v) = VT_BSTR;
3938     V_BSTR(&v) = a2bstr("3px");
3939     hres = IHTMLStyle_put_left(style, v);
3940     ok(hres == S_OK, "put_left failed: %08x\n", hres);
3941     VariantClear(&v);
3942
3943     hres = IHTMLStyle_get_posLeft(style, &f);
3944     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3945     ok(f == 3.0, "expected 3.0 got %f\n", f);
3946
3947     V_VT(&v) = VT_EMPTY;
3948     hres = IHTMLStyle_get_left(style, &v);
3949     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3950     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3951     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3952     VariantClear(&v);
3953
3954     V_VT(&v) = VT_NULL;
3955     hres = IHTMLStyle_put_left(style, v);
3956     ok(hres == S_OK, "put_left failed: %08x\n", hres);
3957
3958     V_VT(&v) = VT_EMPTY;
3959     hres = IHTMLStyle_get_left(style, &v);
3960     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3961     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3962     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3963     VariantClear(&v);
3964
3965     V_VT(&v) = VT_EMPTY;
3966     hres = IHTMLStyle_get_top(style, &v);
3967     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3968     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3969     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3970     VariantClear(&v);
3971
3972     /* Test posTop */
3973     hres = IHTMLStyle_get_posTop(style, NULL);
3974     ok(hres == E_POINTER, "get_posTop failed: %08x\n", hres);
3975
3976     f = 1.0f;
3977     hres = IHTMLStyle_get_posTop(style, &f);
3978     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3979     ok(f == 0.0, "expected 0.0 got %f\n", f);
3980
3981     hres = IHTMLStyle_put_posTop(style, 4.9f);
3982     ok(hres == S_OK, "put_posTop failed: %08x\n", hres);
3983
3984     hres = IHTMLStyle_get_posTop(style, &f);
3985     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3986     ok(f == 4.0 ||
3987        f == 4.9f, /* IE8 */
3988        "expected 4.0 or 4.9 (IE8) got %f\n", f);
3989
3990     V_VT(&v) = VT_BSTR;
3991     V_BSTR(&v) = a2bstr("3px");
3992     hres = IHTMLStyle_put_top(style, v);
3993     ok(hres == S_OK, "put_top failed: %08x\n", hres);
3994     VariantClear(&v);
3995
3996     V_VT(&v) = VT_EMPTY;
3997     hres = IHTMLStyle_get_top(style, &v);
3998     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3999     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4000     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4001     VariantClear(&v);
4002
4003     hres = IHTMLStyle_get_posTop(style, &f);
4004     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
4005     ok(f == 3.0, "expected 3.0 got %f\n", f);
4006
4007     V_VT(&v) = VT_NULL;
4008     hres = IHTMLStyle_put_top(style, v);
4009     ok(hres == S_OK, "put_top failed: %08x\n", hres);
4010
4011     V_VT(&v) = VT_EMPTY;
4012     hres = IHTMLStyle_get_top(style, &v);
4013     ok(hres == S_OK, "get_top failed: %08x\n", hres);
4014     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4015     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
4016     VariantClear(&v);
4017
4018     /* Test posHeight */
4019     hres = IHTMLStyle_get_posHeight(style, NULL);
4020     ok(hres == E_POINTER, "get_posHeight failed: %08x\n", hres);
4021
4022     V_VT(&v) = VT_EMPTY;
4023     hres = IHTMLStyle_get_height(style, &v);
4024     ok(hres == S_OK, "get_height failed: %08x\n", hres);
4025     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4026     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
4027     VariantClear(&v);
4028
4029     f = 1.0f;
4030     hres = IHTMLStyle_get_posHeight(style, &f);
4031     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
4032     ok(f == 0.0, "expected 0.0 got %f\n", f);
4033
4034     hres = IHTMLStyle_put_posHeight(style, 4.9f);
4035     ok(hres == S_OK, "put_posHeight failed: %08x\n", hres);
4036
4037     hres = IHTMLStyle_get_posHeight(style, &f);
4038     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
4039     ok(f == 4.0 ||
4040        f == 4.9f, /* IE8 */
4041        "expected 4.0 or 4.9 (IE8) got %f\n", f);
4042
4043     V_VT(&v) = VT_BSTR;
4044     V_BSTR(&v) = a2bstr("64px");
4045     hres = IHTMLStyle_put_height(style, v);
4046     ok(hres == S_OK, "put_height failed: %08x\n", hres);
4047     VariantClear(&v);
4048
4049     V_VT(&v) = VT_EMPTY;
4050     hres = IHTMLStyle_get_height(style, &v);
4051     ok(hres == S_OK, "get_height failed: %08x\n", hres);
4052     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4053     ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4054     VariantClear(&v);
4055
4056     hres = IHTMLStyle_get_posHeight(style, &f);
4057     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
4058     ok(f == 64.0, "expected 64.0 got %f\n", f);
4059
4060     str = (void*)0xdeadbeef;
4061     hres = IHTMLStyle_get_cursor(style, &str);
4062     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
4063     ok(!str, "get_cursor != NULL\n");
4064     SysFreeString(str);
4065
4066     str = a2bstr("default");
4067     hres = IHTMLStyle_put_cursor(style, str);
4068     ok(hres == S_OK, "put_cursor failed: %08x\n", hres);
4069     SysFreeString(str);
4070
4071     str = NULL;
4072     hres = IHTMLStyle_get_cursor(style, &str);
4073     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
4074     ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
4075     SysFreeString(str);
4076
4077     V_VT(&v) = VT_EMPTY;
4078     hres = IHTMLStyle_get_verticalAlign(style, &v);
4079     ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
4080     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4081     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
4082     VariantClear(&v);
4083
4084     V_VT(&v) = VT_BSTR;
4085     V_BSTR(&v) = a2bstr("middle");
4086     hres = IHTMLStyle_put_verticalAlign(style, v);
4087     ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
4088     VariantClear(&v);
4089
4090     V_VT(&v) = VT_EMPTY;
4091     hres = IHTMLStyle_get_verticalAlign(style, &v);
4092     ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
4093     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4094     ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4095     VariantClear(&v);
4096
4097     str = (void*)0xdeadbeef;
4098     hres = IHTMLStyle_get_textAlign(style, &str);
4099     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
4100     ok(!str, "textAlign != NULL\n");
4101
4102     str = a2bstr("center");
4103     hres = IHTMLStyle_put_textAlign(style, str);
4104     ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
4105     SysFreeString(str);
4106
4107     str = NULL;
4108     hres = IHTMLStyle_get_textAlign(style, &str);
4109     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
4110     ok(!strcmp_wa(str, "center"), "textAlign = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4111     SysFreeString(str);
4112
4113     str = (void*)0xdeadbeef;
4114     hres = IHTMLStyle_get_filter(style, &str);
4115     ok(hres == S_OK, "get_filter failed: %08x\n", hres);
4116     ok(!str, "filter != NULL\n");
4117
4118     str = a2bstr("alpha(opacity=100)");
4119     hres = IHTMLStyle_put_filter(style, str);
4120     ok(hres == S_OK, "put_filter failed: %08x\n", hres);
4121     SysFreeString(str);
4122
4123     V_VT(&v) = VT_EMPTY;
4124     hres = IHTMLStyle_get_zIndex(style, &v);
4125     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
4126     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
4127     ok(!V_I4(&v), "V_I4(v) != 0\n");
4128     VariantClear(&v);
4129
4130     V_VT(&v) = VT_BSTR;
4131     V_BSTR(&v) = a2bstr("1");
4132     hres = IHTMLStyle_put_zIndex(style, v);
4133     ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
4134     VariantClear(&v);
4135
4136     V_VT(&v) = VT_EMPTY;
4137     hres = IHTMLStyle_get_zIndex(style, &v);
4138     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
4139     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
4140     ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
4141     VariantClear(&v);
4142
4143     /* fontStyle */
4144     hres = IHTMLStyle_get_fontStyle(style, &sDefault);
4145     ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
4146
4147     str = a2bstr("test");
4148     hres = IHTMLStyle_put_fontStyle(style, str);
4149     ok(hres == E_INVALIDARG, "put_fontStyle failed: %08x\n", hres);
4150     SysFreeString(str);
4151
4152     str = a2bstr("italic");
4153     hres = IHTMLStyle_put_fontStyle(style, str);
4154     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
4155     SysFreeString(str);
4156
4157     str = a2bstr("oblique");
4158     hres = IHTMLStyle_put_fontStyle(style, str);
4159     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
4160     SysFreeString(str);
4161
4162     str = a2bstr("normal");
4163     hres = IHTMLStyle_put_fontStyle(style, str);
4164     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
4165     SysFreeString(str);
4166
4167     hres = IHTMLStyle_put_fontStyle(style, sDefault);
4168     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
4169     SysFreeString(sDefault);
4170
4171     /* overflow */
4172     hres = IHTMLStyle_get_overflow(style, NULL);
4173     ok(hres == E_INVALIDARG, "get_overflow failed: %08x\n", hres);
4174
4175     hres = IHTMLStyle_get_overflow(style, &sOverflowDefault);
4176     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
4177
4178     str = a2bstr("test");
4179     hres = IHTMLStyle_put_overflow(style, str);
4180     ok(hres == E_INVALIDARG, "put_overflow failed: %08x\n", hres);
4181     SysFreeString(str);
4182
4183     str = a2bstr("visible");
4184     hres = IHTMLStyle_put_overflow(style, str);
4185     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4186     SysFreeString(str);
4187
4188     str = a2bstr("scroll");
4189     hres = IHTMLStyle_put_overflow(style, str);
4190     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4191     SysFreeString(str);
4192
4193     str = a2bstr("hidden");
4194     hres = IHTMLStyle_put_overflow(style, str);
4195     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4196     SysFreeString(str);
4197
4198     str = a2bstr("auto");
4199     hres = IHTMLStyle_put_overflow(style, str);
4200     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4201     SysFreeString(str);
4202
4203     hres = IHTMLStyle_get_overflow(style, &str);
4204     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
4205     ok(!strcmp_wa(str, "auto"), "str=%s\n", wine_dbgstr_w(str));
4206     SysFreeString(str);
4207
4208     str = a2bstr("");
4209     hres = IHTMLStyle_put_overflow(style, str);
4210     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4211     SysFreeString(str);
4212
4213     hres = IHTMLStyle_get_overflow(style, &str);
4214     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
4215     ok(!str, "str=%s\n", wine_dbgstr_w(str));
4216     SysFreeString(str);
4217
4218     /* restore overflow default */
4219     hres = IHTMLStyle_put_overflow(style, sOverflowDefault);
4220     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
4221     SysFreeString(sOverflowDefault);
4222
4223     /* Attribute Tests*/
4224     hres = IHTMLStyle_getAttribute(style, NULL, 1, &v);
4225     ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
4226
4227     str = a2bstr("position");
4228     hres = IHTMLStyle_getAttribute(style, str, 1, NULL);
4229     ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
4230
4231     hres = IHTMLStyle_getAttribute(style, str, 1, &v);
4232     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
4233     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
4234     VariantClear(&v);
4235
4236     hres = IHTMLStyle_setAttribute(style, NULL, v, 1);
4237     ok(hres == E_INVALIDARG, "setAttribute failed: %08x\n", hres);
4238
4239     V_VT(&v) = VT_BSTR;
4240     V_BSTR(&v) = a2bstr("absolute");
4241     hres = IHTMLStyle_setAttribute(style, str, v, 1);
4242     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
4243     VariantClear(&v);
4244
4245     hres = IHTMLStyle_getAttribute(style, str, 1, &v);
4246     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
4247     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
4248     ok(!strcmp_wa(V_BSTR(&v), "absolute"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4249     VariantClear(&v);
4250
4251     V_VT(&v) = VT_BSTR;
4252     V_BSTR(&v) = NULL;
4253     hres = IHTMLStyle_setAttribute(style, str, v, 1);
4254     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
4255     VariantClear(&v);
4256
4257     SysFreeString(str);
4258
4259     str = a2bstr("borderLeftStyle");
4260     test_border_styles(style, str);
4261     SysFreeString(str);
4262
4263     str = a2bstr("borderbottomstyle");
4264     test_border_styles(style, str);
4265     SysFreeString(str);
4266
4267     str = a2bstr("borderrightstyle");
4268     test_border_styles(style, str);
4269     SysFreeString(str);
4270
4271     str = a2bstr("bordertopstyle");
4272     test_border_styles(style, str);
4273     SysFreeString(str);
4274
4275     hres = IHTMLStyle_get_borderStyle(style, &sDefault);
4276     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
4277
4278     str = a2bstr("none dotted dashed solid");
4279     hres = IHTMLStyle_put_borderStyle(style, str);
4280     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4281     SysFreeString(str);
4282
4283     str = a2bstr("none dotted dashed solid");
4284     hres = IHTMLStyle_get_borderStyle(style, &str);
4285     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
4286     ok(!strcmp_wa(str, "none dotted dashed solid"),
4287         "expected (none dotted dashed solid) = (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
4288     SysFreeString(str);
4289
4290     str = a2bstr("double groove ridge inset");
4291     hres = IHTMLStyle_put_borderStyle(style, str);
4292     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4293     SysFreeString(str);
4294
4295     str = a2bstr("window-inset outset ridge inset");
4296     hres = IHTMLStyle_put_borderStyle(style, str);
4297     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4298     SysFreeString(str);
4299
4300     str = a2bstr("window-inset");
4301     hres = IHTMLStyle_put_borderStyle(style, str);
4302     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4303     SysFreeString(str);
4304
4305     str = a2bstr("none none none none none");
4306     hres = IHTMLStyle_put_borderStyle(style, str);
4307     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4308     SysFreeString(str);
4309
4310     str = a2bstr("invalid none none none");
4311     hres = IHTMLStyle_put_borderStyle(style, str);
4312     ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
4313     SysFreeString(str);
4314
4315     str = a2bstr("none invalid none none");
4316     hres = IHTMLStyle_put_borderStyle(style, str);
4317     ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
4318     SysFreeString(str);
4319
4320     hres = IHTMLStyle_put_borderStyle(style, sDefault);
4321     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
4322     SysFreeString(sDefault);
4323
4324     /* backgoundColor */
4325     hres = IHTMLStyle_get_backgroundColor(style, &v);
4326     ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
4327     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
4328     ok(!V_BSTR(&v), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4329     VariantClear(&v);
4330
4331     /* PaddingLeft */
4332     hres = IHTMLStyle_get_paddingLeft(style, &vDefault);
4333     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
4334
4335     V_VT(&v) = VT_BSTR;
4336     V_BSTR(&v) = a2bstr("10");
4337     hres = IHTMLStyle_put_paddingLeft(style, v);
4338     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
4339     VariantClear(&v);
4340
4341     hres = IHTMLStyle_get_paddingLeft(style, &v);
4342     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
4343     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expecte 10 = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4344
4345     hres = IHTMLStyle_put_paddingLeft(style, vDefault);
4346     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
4347
4348     /* BackgroundRepeat */
4349     hres = IHTMLStyle_get_backgroundRepeat(style, &sDefault);
4350     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
4351
4352     str = a2bstr("invalid");
4353     hres = IHTMLStyle_put_backgroundRepeat(style, str);
4354     ok(hres == E_INVALIDARG, "put_backgroundRepeat failed: %08x\n", hres);
4355     SysFreeString(str);
4356
4357     str = a2bstr("repeat");
4358     hres = IHTMLStyle_put_backgroundRepeat(style, str);
4359     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
4360     SysFreeString(str);
4361
4362     str = a2bstr("no-repeat");
4363     hres = IHTMLStyle_put_backgroundRepeat(style, str);
4364     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
4365     SysFreeString(str);
4366
4367     str = a2bstr("repeat-x");
4368     hres = IHTMLStyle_put_backgroundRepeat(style, str);
4369     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
4370     SysFreeString(str);
4371
4372     str = a2bstr("repeat-y");
4373     hres = IHTMLStyle_put_backgroundRepeat(style, str);
4374     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
4375     SysFreeString(str);
4376
4377     hres = IHTMLStyle_get_backgroundRepeat(style, &str);
4378     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
4379     ok(!strcmp_wa(str, "repeat-y"), "str=%s\n", wine_dbgstr_w(str));
4380     SysFreeString(str);
4381
4382     hres = IHTMLStyle_put_backgroundRepeat(style, sDefault);
4383     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
4384     SysFreeString(sDefault);
4385
4386     /* BorderColor */
4387     hres = IHTMLStyle_get_borderColor(style, &sDefault);
4388     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
4389
4390     str = a2bstr("red green red blue");
4391     hres = IHTMLStyle_put_borderColor(style, str);
4392     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
4393     SysFreeString(str);
4394
4395     hres = IHTMLStyle_get_borderColor(style, &str);
4396     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
4397     ok(!strcmp_wa(str, "red green red blue"), "str=%s\n", wine_dbgstr_w(str));
4398     SysFreeString(str);
4399
4400     hres = IHTMLStyle_put_borderColor(style, sDefault);
4401     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
4402     SysFreeString(sDefault);
4403
4404     /* BorderRight */
4405     hres = IHTMLStyle_get_borderRight(style, &sDefault);
4406     ok(hres == S_OK, "get_borderRight failed: %08x\n", hres);
4407
4408     str = a2bstr("thick dotted red");
4409     hres = IHTMLStyle_put_borderRight(style, str);
4410     ok(hres == S_OK, "put_borderRight failed: %08x\n", hres);
4411     SysFreeString(str);
4412
4413     /* IHTMLStyle_get_borderRight appears to have a bug where
4414         it returns the first letter of the color.  So we check
4415         each style individually.
4416      */
4417     V_BSTR(&v) = NULL;
4418     hres = IHTMLStyle_get_borderRightColor(style, &v);
4419     todo_wine ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
4420     todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4421     VariantClear(&v);
4422
4423     V_BSTR(&v) = NULL;
4424     hres = IHTMLStyle_get_borderRightWidth(style, &v);
4425     ok(hres == S_OK, "get_borderRightWidth failed: %08x\n", hres);
4426     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4427     VariantClear(&v);
4428
4429     hres = IHTMLStyle_get_borderRightStyle(style, &str);
4430     ok(hres == S_OK, "get_borderRightStyle failed: %08x\n", hres);
4431     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
4432     SysFreeString(str);
4433
4434     hres = IHTMLStyle_put_borderRight(style, sDefault);
4435     ok(hres == S_OK, "put_borderRight failed: %08x\n", hres);
4436     SysFreeString(sDefault);
4437
4438     /* BorderTop */
4439     hres = IHTMLStyle_get_borderTop(style, &sDefault);
4440     ok(hres == S_OK, "get_borderTop failed: %08x\n", hres);
4441
4442     str = a2bstr("thick dotted red");
4443     hres = IHTMLStyle_put_borderTop(style, str);
4444     ok(hres == S_OK, "put_borderTop failed: %08x\n", hres);
4445     SysFreeString(str);
4446
4447     /* IHTMLStyle_get_borderTop appears to have a bug where
4448         it returns the first letter of the color.  So we check
4449         each style individually.
4450      */
4451     V_BSTR(&v) = NULL;
4452     hres = IHTMLStyle_get_borderTopColor(style, &v);
4453     todo_wine ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
4454     todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4455     VariantClear(&v);
4456
4457     V_BSTR(&v) = NULL;
4458     hres = IHTMLStyle_get_borderTopWidth(style, &v);
4459     ok(hres == S_OK, "get_borderTopWidth failed: %08x\n", hres);
4460     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4461     VariantClear(&v);
4462
4463     hres = IHTMLStyle_get_borderTopStyle(style, &str);
4464     ok(hres == S_OK, "get_borderTopStyle failed: %08x\n", hres);
4465     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
4466     SysFreeString(str);
4467
4468     hres = IHTMLStyle_put_borderTop(style, sDefault);
4469     ok(hres == S_OK, "put_borderTop failed: %08x\n", hres);
4470     SysFreeString(sDefault);
4471
4472     /* BorderBottom */
4473     hres = IHTMLStyle_get_borderBottom(style, &sDefault);
4474     ok(hres == S_OK, "get_borderBottom failed: %08x\n", hres);
4475
4476     str = a2bstr("thick dotted red");
4477     hres = IHTMLStyle_put_borderBottom(style, str);
4478     ok(hres == S_OK, "put_borderBottom failed: %08x\n", hres);
4479     SysFreeString(str);
4480
4481     /* IHTMLStyle_get_borderBottom appears to have a bug where
4482         it returns the first letter of the color.  So we check
4483         each style individually.
4484      */
4485     V_BSTR(&v) = NULL;
4486     hres = IHTMLStyle_get_borderBottomColor(style, &v);
4487     todo_wine ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
4488     todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4489     VariantClear(&v);
4490
4491     V_BSTR(&v) = NULL;
4492     hres = IHTMLStyle_get_borderBottomWidth(style, &v);
4493     ok(hres == S_OK, "get_borderBottomWidth failed: %08x\n", hres);
4494     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4495     VariantClear(&v);
4496
4497     hres = IHTMLStyle_get_borderBottomStyle(style, &str);
4498     ok(hres == S_OK, "get_borderBottomStyle failed: %08x\n", hres);
4499     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
4500     SysFreeString(str);
4501
4502     hres = IHTMLStyle_put_borderBottom(style, sDefault);
4503     ok(hres == S_OK, "put_borderBottom failed: %08x\n", hres);
4504     SysFreeString(sDefault);
4505
4506     /* BorderLeft */
4507     hres = IHTMLStyle_get_borderLeft(style, &sDefault);
4508     ok(hres == S_OK, "get_borderLeft failed: %08x\n", hres);
4509
4510     str = a2bstr("thick dotted red");
4511     hres = IHTMLStyle_put_borderLeft(style, str);
4512     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
4513     SysFreeString(str);
4514
4515     /* IHTMLStyle_get_borderLeft appears to have a bug where
4516         it returns the first letter of the color.  So we check
4517         each style individually.
4518      */
4519     V_BSTR(&v) = NULL;
4520     hres = IHTMLStyle_get_borderLeftColor(style, &v);
4521     todo_wine ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
4522     todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4523     VariantClear(&v);
4524
4525     V_BSTR(&v) = NULL;
4526     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
4527     ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
4528     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4529     VariantClear(&v);
4530
4531     hres = IHTMLStyle_get_borderLeftStyle(style, &str);
4532     ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
4533     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
4534     SysFreeString(str);
4535
4536     hres = IHTMLStyle_put_borderLeft(style, sDefault);
4537     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
4538     SysFreeString(sDefault);
4539
4540     /* backgroundPositionX */
4541     hres = IHTMLStyle_get_backgroundPositionX(style, &vDefault);
4542     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
4543
4544     V_VT(&v) = VT_BSTR;
4545     V_BSTR(&v) = a2bstr("10px");
4546     hres = IHTMLStyle_put_backgroundPositionX(style, v);
4547     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
4548     VariantClear(&v);
4549
4550     hres = IHTMLStyle_get_backgroundPositionX(style, &v);
4551     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
4552     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4553     VariantClear(&v);
4554
4555     hres = IHTMLStyle_put_backgroundPositionX(style, vDefault);
4556     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
4557     VariantClear(&vDefault);
4558
4559     /* backgroundPositionY */
4560     hres = IHTMLStyle_get_backgroundPositionY(style, &vDefault);
4561     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
4562
4563     V_VT(&v) = VT_BSTR;
4564     V_BSTR(&v) = a2bstr("10px");
4565     hres = IHTMLStyle_put_backgroundPositionY(style, v);
4566     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
4567     VariantClear(&v);
4568
4569     hres = IHTMLStyle_get_backgroundPositionY(style, &v);
4570     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
4571     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4572     VariantClear(&v);
4573
4574     hres = IHTMLStyle_put_backgroundPositionY(style, vDefault);
4575     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
4576     VariantClear(&vDefault);
4577
4578      /* borderTopWidth */
4579     hres = IHTMLStyle_get_borderTopWidth(style, &vDefault);
4580     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
4581
4582     V_VT(&v) = VT_BSTR;
4583     V_BSTR(&v) = a2bstr("10px");
4584     hres = IHTMLStyle_put_borderTopWidth(style, v);
4585     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
4586     VariantClear(&v);
4587
4588     hres = IHTMLStyle_get_borderTopWidth(style, &v);
4589     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
4590     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4591     VariantClear(&v);
4592
4593     hres = IHTMLStyle_put_borderTopWidth(style, vDefault);
4594     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
4595     VariantClear(&vDefault);
4596
4597     /* borderRightWidth */
4598     hres = IHTMLStyle_get_borderRightWidth(style, &vDefault);
4599     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
4600
4601     V_VT(&v) = VT_BSTR;
4602     V_BSTR(&v) = a2bstr("10");
4603     hres = IHTMLStyle_put_borderRightWidth(style, v);
4604     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
4605     VariantClear(&v);
4606
4607     hres = IHTMLStyle_get_borderRightWidth(style, &v);
4608     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
4609     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4610     VariantClear(&v);
4611
4612     hres = IHTMLStyle_put_borderRightWidth(style, vDefault);
4613     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
4614     VariantClear(&vDefault);
4615
4616     /* borderBottomWidth */
4617     hres = IHTMLStyle_get_borderBottomWidth(style, &vDefault);
4618     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
4619
4620     V_VT(&v) = VT_BSTR;
4621     V_BSTR(&v) = a2bstr("10");
4622     hres = IHTMLStyle_put_borderBottomWidth(style, v);
4623     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
4624     VariantClear(&v);
4625
4626     hres = IHTMLStyle_get_borderBottomWidth(style, &v);
4627     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
4628     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4629     VariantClear(&v);
4630
4631     hres = IHTMLStyle_put_borderBottomWidth(style, vDefault);
4632     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
4633     VariantClear(&vDefault);
4634
4635     /* borderLeftWidth */
4636     hres = IHTMLStyle_get_borderLeftWidth(style, &vDefault);
4637     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
4638
4639     V_VT(&v) = VT_BSTR;
4640     V_BSTR(&v) = a2bstr("10");
4641     hres = IHTMLStyle_put_borderLeftWidth(style, v);
4642     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
4643     VariantClear(&v);
4644
4645     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
4646     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
4647     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4648     VariantClear(&v);
4649
4650     hres = IHTMLStyle_put_borderLeftWidth(style, vDefault);
4651     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
4652     VariantClear(&vDefault);
4653
4654     /* wordSpacing */
4655     hres = IHTMLStyle_get_wordSpacing(style, &vDefault);
4656     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
4657
4658     V_VT(&v) = VT_BSTR;
4659     V_BSTR(&v) = a2bstr("10");
4660     hres = IHTMLStyle_put_wordSpacing(style, v);
4661     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
4662     VariantClear(&v);
4663
4664     hres = IHTMLStyle_get_wordSpacing(style, &v);
4665     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
4666     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4667     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4668     VariantClear(&v);
4669
4670     hres = IHTMLStyle_put_wordSpacing(style, vDefault);
4671     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
4672     VariantClear(&vDefault);
4673
4674     /* letterSpacing */
4675     hres = IHTMLStyle_get_letterSpacing(style, &vDefault);
4676     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
4677
4678     V_VT(&v) = VT_BSTR;
4679     V_BSTR(&v) = a2bstr("11");
4680     hres = IHTMLStyle_put_letterSpacing(style, v);
4681     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
4682     VariantClear(&v);
4683
4684     hres = IHTMLStyle_get_letterSpacing(style, &v);
4685     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
4686     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4687     ok(!strcmp_wa(V_BSTR(&v), "11px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4688     VariantClear(&v);
4689
4690     hres = IHTMLStyle_put_letterSpacing(style, vDefault);
4691     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
4692     VariantClear(&vDefault);
4693
4694     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
4695     ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
4696     if(SUCCEEDED(hres)) {
4697         test_style2(style2);
4698         IHTMLStyle2_Release(style2);
4699     }
4700
4701     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle3, (void**)&style3);
4702     ok(hres == S_OK, "Could not get IHTMLStyle3 iface: %08x\n", hres);
4703     if(SUCCEEDED(hres)) {
4704         test_style3(style3);
4705         IHTMLStyle3_Release(style3);
4706     }
4707
4708     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle4, (void**)&style4);
4709     ok(hres == S_OK, "Could not get IHTMLStyle4 iface: %08x\n", hres);
4710     if(SUCCEEDED(hres)) {
4711         test_style4(style4);
4712         IHTMLStyle4_Release(style4);
4713     }
4714 }
4715
4716 static void test_set_csstext(IHTMLStyle *style)
4717 {
4718     VARIANT v;
4719     HRESULT hres;
4720
4721     test_style_set_csstext(style, "background-color: black;");
4722
4723     hres = IHTMLStyle_get_backgroundColor(style, &v);
4724     ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
4725     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
4726     ok(!strcmp_wa(V_BSTR(&v), "black"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4727     VariantClear(&v);
4728 }
4729
4730 static void test_default_selection(IHTMLDocument2 *doc)
4731 {
4732     IHTMLSelectionObject *selection;
4733     IHTMLTxtRange *range;
4734     IDispatch *disp;
4735     BSTR str;
4736     HRESULT hres;
4737
4738     hres = IHTMLDocument2_get_selection(doc, &selection);
4739     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
4740
4741     hres = IHTMLSelectionObject_get_type(selection, &str);
4742     ok(hres == S_OK, "get_type failed: %08x\n", hres);
4743     ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
4744     SysFreeString(str);
4745
4746     hres = IHTMLSelectionObject_createRange(selection, &disp);
4747     IHTMLSelectionObject_Release(selection);
4748     ok(hres == S_OK, "createRange failed: %08x\n", hres);
4749
4750     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
4751     IDispatch_Release(disp);
4752     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
4753
4754     test_range_text(range, NULL);
4755     IHTMLTxtRange_Release(range);
4756 }
4757
4758 static void test_doc_elem(IHTMLDocument2 *doc)
4759 {
4760     IHTMLDocument2 *doc_node, *owner_doc;
4761     IHTMLElement *elem;
4762     IHTMLDocument3 *doc3;
4763     HRESULT hres;
4764
4765     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4766     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
4767
4768     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
4769     IHTMLDocument3_Release(doc3);
4770     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4771
4772     test_node_name((IUnknown*)elem, "HTML");
4773     test_elem_tag((IUnknown*)elem, "HTML");
4774
4775     doc_node = get_doc_node(doc);
4776     owner_doc = get_owner_doc((IUnknown*)elem);
4777     ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
4778     IHTMLDocument2_Release(owner_doc);
4779
4780     owner_doc = get_owner_doc((IUnknown*)doc_node);
4781     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4782     IHTMLDocument2_Release(doc_node);
4783
4784     test_elem_client_rect((IUnknown*)elem);
4785
4786     IHTMLElement_Release(elem);
4787 }
4788
4789 static void test_default_body(IHTMLBodyElement *body)
4790 {
4791     LONG l;
4792     BSTR bstr;
4793     HRESULT hres;
4794     VARIANT v;
4795
4796     bstr = (void*)0xdeadbeef;
4797     hres = IHTMLBodyElement_get_background(body, &bstr);
4798     ok(hres == S_OK, "get_background failed: %08x\n", hres);
4799     ok(bstr == NULL, "bstr != NULL\n");
4800
4801     l = elem_get_scroll_height((IUnknown*)body);
4802     ok(l != -1, "scrollHeight == -1\n");
4803     l = elem_get_scroll_width((IUnknown*)body);
4804     ok(l != -1, "scrollWidth == -1\n");
4805     l = elem_get_scroll_top((IUnknown*)body);
4806     ok(!l, "scrollTop = %d\n", l);
4807     elem_get_scroll_left((IUnknown*)body);
4808
4809     /* get_text tests */
4810     hres = IHTMLBodyElement_get_text(body, &v);
4811     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4812     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4813     ok(bstr == NULL, "bstr != NULL\n");
4814
4815     /* get_text - Invalid Text */
4816     V_VT(&v) = VT_BSTR;
4817     V_BSTR(&v) = a2bstr("Invalid");
4818     hres = IHTMLBodyElement_put_text(body, v);
4819     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4820     VariantClear(&v);
4821
4822     V_VT(&v) = VT_NULL;
4823     hres = IHTMLBodyElement_get_text(body, &v);
4824     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4825     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4826     ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
4827     VariantClear(&v);
4828
4829     /* get_text - Valid Text */
4830     V_VT(&v) = VT_BSTR;
4831     V_BSTR(&v) = a2bstr("#FF0000");
4832     hres = IHTMLBodyElement_put_text(body, v);
4833     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4834     VariantClear(&v);
4835
4836     V_VT(&v) = VT_NULL;
4837     hres = IHTMLBodyElement_get_text(body, &v);
4838     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4839     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4840     ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
4841     VariantClear(&v);
4842 }
4843
4844 static void test_body_funs(IHTMLBodyElement *body)
4845 {
4846     VARIANT vbg, vDefaultbg;
4847     HRESULT hres;
4848
4849     hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
4850     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4851     ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
4852     ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
4853
4854     V_VT(&vbg) = VT_BSTR;
4855     V_BSTR(&vbg) = a2bstr("red");
4856     hres = IHTMLBodyElement_put_bgColor(body, vbg);
4857     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4858     VariantClear(&vbg);
4859
4860     hres = IHTMLBodyElement_get_bgColor(body, &vbg);
4861     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4862     ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
4863     ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
4864     VariantClear(&vbg);
4865
4866     /* Restore Originial */
4867     hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
4868     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4869     VariantClear(&vDefaultbg);
4870 }
4871
4872 static void test_window(IHTMLDocument2 *doc)
4873 {
4874     IHTMLWindow2 *window, *window2, *self;
4875     IHTMLDocument2 *doc2 = NULL;
4876     IDispatch *disp;
4877     IUnknown *unk;
4878     BSTR str;
4879     HRESULT hres;
4880
4881     hres = IHTMLDocument2_get_parentWindow(doc, &window);
4882     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4883     test_ifaces((IUnknown*)window, window_iids);
4884     test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
4885
4886     hres = IHTMLWindow2_get_document(window, &doc2);
4887     ok(hres == S_OK, "get_document failed: %08x\n", hres);
4888     ok(doc2 != NULL, "doc2 == NULL\n");
4889
4890     test_ifaces((IUnknown*)doc2, doc_node_iids);
4891     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4892
4893     test_ifaces((IUnknown*)doc, doc_obj_iids);
4894     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4895
4896     unk = (void*)0xdeadbeef;
4897     hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
4898     ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
4899     ok(!unk, "unk = %p\n", unk);
4900
4901     IHTMLDocument_Release(doc2);
4902
4903     hres = IHTMLWindow2_get_window(window, &window2);
4904     ok(hres == S_OK, "get_window failed: %08x\n", hres);
4905     ok(window2 != NULL, "window2 == NULL\n");
4906
4907     hres = IHTMLWindow2_get_self(window, &self);
4908     ok(hres == S_OK, "get_self failed: %08x\n", hres);
4909     ok(window2 != NULL, "self == NULL\n");
4910
4911     ok(self == window2, "self != window2\n");
4912
4913     IHTMLWindow2_Release(window2);
4914     IHTMLWindow2_Release(self);
4915
4916     disp = NULL;
4917     hres = IHTMLDocument2_get_Script(doc, &disp);
4918     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4919     ok(disp == (void*)window, "disp != window\n");
4920     IDispatch_Release(disp);
4921
4922     hres = IHTMLWindow2_toString(window, NULL);
4923     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4924
4925     str = NULL;
4926     hres = IHTMLWindow2_toString(window, &str);
4927     ok(hres == S_OK, "toString failed: %08x\n", hres);
4928     ok(!strcmp_wa(str, "[object]"), "toString returned %s\n", wine_dbgstr_w(str));
4929     SysFreeString(str);
4930
4931     test_window_name(window, NULL);
4932     set_window_name(window, "test");
4933     test_window_length(window, 0);
4934     test_screen(window);
4935
4936     IHTMLWindow2_Release(window);
4937 }
4938
4939 static void test_defaults(IHTMLDocument2 *doc)
4940 {
4941     IHTMLStyleSheetsCollection *stylesheetcol;
4942     IHTMLCurrentStyle *cstyle;
4943     IHTMLBodyElement *body;
4944     IHTMLElement2 *elem2;
4945     IHTMLElement *elem;
4946     IHTMLStyle *style;
4947     LONG l;
4948     HRESULT hres;
4949     IHTMLElementCollection *collection;
4950
4951     hres = IHTMLDocument2_get_body(doc, &elem);
4952     ok(hres == S_OK, "get_body failed: %08x\n", hres);
4953
4954     hres = IHTMLDocument2_get_images(doc, NULL);
4955     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4956
4957     hres = IHTMLDocument2_get_images(doc, &collection);
4958     ok(hres == S_OK, "get_images failed: %08x\n", hres);
4959     if(hres == S_OK)
4960     {
4961         test_elem_collection((IUnknown*)collection, NULL, 0);
4962         IHTMLElementCollection_Release(collection);
4963     }
4964
4965     hres = IHTMLDocument2_get_applets(doc, NULL);
4966     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4967
4968     hres = IHTMLDocument2_get_applets(doc, &collection);
4969     ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4970     if(hres == S_OK)
4971     {
4972         test_elem_collection((IUnknown*)collection, NULL, 0);
4973         IHTMLElementCollection_Release(collection);
4974     }
4975
4976     hres = IHTMLDocument2_get_links(doc, NULL);
4977     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4978
4979     hres = IHTMLDocument2_get_links(doc, &collection);
4980     ok(hres == S_OK, "get_links failed: %08x\n", hres);
4981     if(hres == S_OK)
4982     {
4983         test_elem_collection((IUnknown*)collection, NULL, 0);
4984         IHTMLElementCollection_Release(collection);
4985     }
4986
4987     hres = IHTMLDocument2_get_forms(doc, NULL);
4988     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4989
4990     hres = IHTMLDocument2_get_forms(doc, &collection);
4991     ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4992     if(hres == S_OK)
4993     {
4994         test_elem_collection((IUnknown*)collection, NULL, 0);
4995         IHTMLElementCollection_Release(collection);
4996     }
4997
4998     hres = IHTMLDocument2_get_anchors(doc, NULL);
4999     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5000
5001     hres = IHTMLDocument2_get_anchors(doc, &collection);
5002     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
5003     if(hres == S_OK)
5004     {
5005         test_elem_collection((IUnknown*)collection, NULL, 0);
5006         IHTMLElementCollection_Release(collection);
5007     }
5008
5009     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
5010     ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
5011     test_default_body(body);
5012     test_body_funs(body);
5013     IHTMLBodyElement_Release(body);
5014
5015     hres = IHTMLElement_get_style(elem, &style);
5016     ok(hres == S_OK, "get_style failed: %08x\n", hres);
5017
5018     test_default_style(style);
5019     test_window(doc);
5020     test_compatmode(doc);
5021     test_location(doc);
5022     test_navigator(doc);
5023
5024     elem2 = get_elem2_iface((IUnknown*)elem);
5025     hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
5026     ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
5027     if(SUCCEEDED(hres)) {
5028         test_current_style(cstyle);
5029         IHTMLCurrentStyle_Release(cstyle);
5030     }
5031     IHTMLElement2_Release(elem2);
5032
5033     IHTMLElement_Release(elem);
5034
5035     test_set_csstext(style);
5036     IHTMLStyle_Release(style);
5037
5038     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
5039     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5040
5041     l = 0xdeadbeef;
5042     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
5043     ok(hres == S_OK, "get_length failed: %08x\n", hres);
5044     ok(l == 0, "length = %d\n", l);
5045
5046     IHTMLStyleSheetsCollection_Release(stylesheetcol);
5047
5048     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
5049     ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
5050
5051     test_default_selection(doc);
5052     test_doc_title(doc, "");
5053 }
5054
5055 static void test_tr_elem(IHTMLElement *elem)
5056 {
5057     IHTMLElementCollection *col;
5058     IHTMLTableRow *row;
5059     HRESULT hres;
5060
5061     static const elem_type_t cell_types[] = {ET_TD,ET_TD};
5062
5063     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
5064     ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
5065     if(FAILED(hres))
5066         return;
5067
5068     col = NULL;
5069     hres = IHTMLTableRow_get_cells(row, &col);
5070     ok(hres == S_OK, "get_cells failed: %08x\n", hres);
5071     ok(col != NULL, "get_cells returned NULL\n");
5072
5073     test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
5074     IHTMLElementCollection_Release(col);
5075
5076     IHTMLTable_Release(row);
5077 }
5078
5079 static void test_table_elem(IHTMLElement *elem)
5080 {
5081     IHTMLElementCollection *col;
5082     IHTMLTable *table;
5083     IHTMLDOMNode *node;
5084     HRESULT hres;
5085
5086     static const elem_type_t row_types[] = {ET_TR,ET_TR};
5087     static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
5088
5089     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
5090     ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
5091     if(FAILED(hres))
5092         return;
5093
5094     col = NULL;
5095     hres = IHTMLTable_get_rows(table, &col);
5096     ok(hres == S_OK, "get_rows failed: %08x\n", hres);
5097     ok(col != NULL, "get_ros returned NULL\n");
5098
5099     test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
5100     IHTMLElementCollection_Release(col);
5101
5102     test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
5103
5104     node = clone_node((IUnknown*)table, VARIANT_TRUE);
5105     test_elem_tag((IUnknown*)node, "TABLE");
5106     test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
5107     IHTMLDOMNode_Release(node);
5108
5109     node = clone_node((IUnknown*)table, VARIANT_FALSE);
5110     test_elem_tag((IUnknown*)node, "TABLE");
5111     test_elem_all((IUnknown*)node, NULL, 0);
5112     IHTMLDOMNode_Release(node);
5113
5114     IHTMLTable_Release(table);
5115 }
5116
5117 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
5118 {
5119     SAFEARRAYBOUND dim;
5120     SAFEARRAY *sa;
5121     VARIANT *var;
5122     BSTR str;
5123     HRESULT hres;
5124
5125     dim.lLbound = 0;
5126     dim.cElements = 1;
5127     sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
5128     SafeArrayAccessData(sa, (void**)&var);
5129     V_VT(var) = VT_BSTR;
5130     V_BSTR(var) = str = a2bstr(text);
5131     SafeArrayUnaccessData(sa);
5132
5133     if(ln)
5134         hres = IHTMLDocument2_writeln(doc, sa);
5135     else
5136         hres = IHTMLDocument2_write(doc, sa);
5137     ok(hres == S_OK, "write failed: %08x\n", hres);
5138
5139     SysFreeString(str);
5140     SafeArrayDestroy(sa);
5141 }
5142
5143 static void test_frame_doc(IUnknown *frame_elem)
5144 {
5145     IHTMLDocument2 *window_doc, *elem_doc;
5146     IHTMLWindow2 *content_window;
5147
5148     content_window = get_frame_content_window(frame_elem);
5149     window_doc = get_window_doc(content_window);
5150     IHTMLWindow2_Release(content_window);
5151
5152     elem_doc = get_elem_doc(frame_elem);
5153     ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
5154
5155     IHTMLDocument2_Release(elem_doc);
5156     IHTMLDocument2_Release(window_doc);
5157 }
5158
5159 static void test_iframe_elem(IHTMLElement *elem)
5160 {
5161     IHTMLDocument2 *content_doc, *owner_doc;
5162     IHTMLElementCollection *col;
5163     IHTMLWindow2 *content_window;
5164     IDispatch *disp;
5165     VARIANT errv;
5166     BSTR str;
5167     HRESULT hres;
5168
5169     static const elem_type_t all_types[] = {
5170         ET_HTML,
5171         ET_HEAD,
5172         ET_TITLE,
5173         ET_BODY,
5174         ET_BR
5175     };
5176
5177     test_frame_doc((IUnknown*)elem);
5178
5179     content_window = get_frame_content_window((IUnknown*)elem);
5180     test_window_length(content_window, 0);
5181
5182     content_doc = get_window_doc(content_window);
5183     IHTMLWindow2_Release(content_window);
5184
5185     str = a2bstr("text/html");
5186     V_VT(&errv) = VT_ERROR;
5187     disp = NULL;
5188     hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
5189     SysFreeString(str);
5190     ok(hres == S_OK, "open failed: %08x\n", hres);
5191     ok(disp != NULL, "disp == NULL\n");
5192     ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
5193     IDispatch_Release(disp);
5194
5195     doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
5196     doc_write(content_doc, TRUE, "</html>");
5197
5198     hres = IHTMLDocument2_get_all(content_doc, &col);
5199     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5200     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5201     IHTMLElementCollection_Release(col);
5202
5203     hres = IHTMLDocument2_close(content_doc);
5204     ok(hres == S_OK, "close failed: %08x\n", hres);
5205
5206     owner_doc = get_owner_doc((IUnknown*)content_doc);
5207     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5208
5209     IHTMLDocument2_Release(content_doc);
5210 }
5211
5212 static void test_stylesheet(IDispatch *disp)
5213 {
5214     IHTMLStyleSheetRulesCollection *col = NULL;
5215     IHTMLStyleSheet *stylesheet;
5216     HRESULT hres;
5217
5218     hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
5219     ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
5220
5221     hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
5222     ok(hres == S_OK, "get_rules failed: %08x\n", hres);
5223     ok(col != NULL, "col == NULL\n");
5224
5225     IHTMLStyleSheetRulesCollection_Release(col);
5226     IHTMLStyleSheet_Release(stylesheet);
5227 }
5228
5229 static void test_stylesheets(IHTMLDocument2 *doc)
5230 {
5231     IHTMLStyleSheetsCollection *col = NULL;
5232     VARIANT idx, res;
5233     LONG len = 0;
5234     HRESULT hres;
5235
5236     hres = IHTMLDocument2_get_styleSheets(doc, &col);
5237     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5238     ok(col != NULL, "col == NULL\n");
5239
5240     hres = IHTMLStyleSheetsCollection_get_length(col, &len);
5241     ok(hres == S_OK, "get_length failed: %08x\n", hres);
5242     ok(len == 1, "len=%d\n", len);
5243
5244     VariantInit(&res);
5245     V_VT(&idx) = VT_I4;
5246     V_I4(&idx) = 0;
5247
5248     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5249     ok(hres == S_OK, "item failed: %08x\n", hres);
5250     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
5251     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5252     test_stylesheet(V_DISPATCH(&res));
5253     VariantClear(&res);
5254
5255     V_VT(&res) = VT_I4;
5256     V_VT(&idx) = VT_I4;
5257     V_I4(&idx) = 1;
5258
5259     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5260     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5261     ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
5262     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5263     VariantClear(&res);
5264
5265     IHTMLStyleSheetsCollection_Release(col);
5266 }
5267
5268 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
5269 {
5270     IDispatchEx *dispex;
5271     IHTMLDOMNode *node;
5272     DISPPARAMS dp = {NULL, NULL, 0, 0};
5273     VARIANT var;
5274     EXCEPINFO ei;
5275     LONG type;
5276     DISPID id;
5277     BSTR bstr;
5278     HRESULT hres;
5279
5280     static const WCHAR w0[] = {'0',0};
5281     static const WCHAR w100[] = {'1','0','0',0};
5282
5283     hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
5284     ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
5285
5286     bstr = SysAllocString(w0);
5287     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5288     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5289     SysFreeString(bstr);
5290
5291     VariantInit(&var);
5292     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
5293     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
5294     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
5295     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
5296     node = get_node_iface((IUnknown*)V_DISPATCH(&var));
5297     type = get_node_type((IUnknown*)node);
5298     ok(type == 3, "type=%d\n", type);
5299     IHTMLDOMNode_Release(node);
5300     VariantClear(&var);
5301
5302     bstr = SysAllocString(w100);
5303     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5304     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
5305     SysFreeString(bstr);
5306
5307     IDispatchEx_Release(dispex);
5308 }
5309
5310
5311
5312 static void test_elems(IHTMLDocument2 *doc)
5313 {
5314     IHTMLElementCollection *col;
5315     IHTMLDOMChildrenCollection *child_col;
5316     IHTMLElement *elem, *elem2, *elem3;
5317     IHTMLDOMNode *node, *node2;
5318     IHTMLWindow2 *window;
5319     IDispatch *disp;
5320     LONG type;
5321     HRESULT hres;
5322     IHTMLElementCollection *collection;
5323     IHTMLDocument3 *doc3;
5324     BSTR str;
5325
5326     static const elem_type_t all_types[] = {
5327         ET_HTML,
5328         ET_HEAD,
5329         ET_TITLE,
5330         ET_STYLE,
5331         ET_BODY,
5332         ET_COMMENT,
5333         ET_A,
5334         ET_INPUT,
5335         ET_SELECT,
5336         ET_OPTION,
5337         ET_OPTION,
5338         ET_TEXTAREA,
5339         ET_TABLE,
5340         ET_TBODY,
5341         ET_TR,
5342         ET_TR,
5343         ET_TD,
5344         ET_TD,
5345         ET_SCRIPT,
5346         ET_TEST,
5347         ET_IMG,
5348         ET_IFRAME,
5349         ET_FORM
5350     };
5351
5352     static const elem_type_t item_types[] = {
5353         ET_A,
5354         ET_OPTION,
5355         ET_TEXTAREA
5356     };
5357
5358     hres = IHTMLDocument2_get_all(doc, &col);
5359     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5360     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5361     test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
5362     IHTMLElementCollection_Release(col);
5363
5364     hres = IHTMLDocument2_get_images(doc, &collection);
5365     ok(hres == S_OK, "get_images failed: %08x\n", hres);
5366     if(hres == S_OK)
5367     {
5368         static const elem_type_t images_types[] = {ET_IMG};
5369         test_elem_collection((IUnknown*)collection, images_types, 1);
5370
5371         IHTMLElementCollection_Release(collection);
5372     }
5373
5374     hres = IHTMLDocument2_get_links(doc, &collection);
5375     ok(hres == S_OK, "get_links failed: %08x\n", hres);
5376     if(hres == S_OK)
5377     {
5378         static const elem_type_t images_types[] = {ET_A};
5379         test_elem_collection((IUnknown*)collection, images_types, 1);
5380
5381         IHTMLElementCollection_Release(collection);
5382     }
5383
5384     hres = IHTMLDocument2_get_anchors(doc, &collection);
5385     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
5386     if(hres == S_OK)
5387     {
5388         static const elem_type_t anchor_types[] = {ET_A};
5389         test_elem_collection((IUnknown*)collection, anchor_types, 1);
5390
5391         IHTMLElementCollection_Release(collection);
5392     }
5393
5394     elem = get_doc_elem(doc);
5395     test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
5396     IHTMLElement_Release(elem);
5397
5398     get_elem_by_id(doc, "xxx", FALSE);
5399     elem = get_doc_elem_by_id(doc, "xxx");
5400     ok(!elem, "elem != NULL\n");
5401
5402     elem = get_doc_elem_by_id(doc, "s");
5403     ok(elem != NULL, "elem == NULL\n");
5404     if(elem) {
5405         test_elem_type((IUnknown*)elem, ET_SELECT);
5406         test_elem_attr(elem, "xxx", NULL);
5407         test_elem_attr(elem, "id", "s");
5408         test_elem_class((IUnknown*)elem, NULL);
5409         test_elem_set_class((IUnknown*)elem, "cl");
5410         test_elem_set_class((IUnknown*)elem, NULL);
5411         test_elem_tabindex((IUnknown*)elem, 0);
5412         test_elem_set_tabindex((IUnknown*)elem, 1);
5413         test_elem_filters((IUnknown*)elem);
5414
5415         node = test_node_get_parent((IUnknown*)elem);
5416         ok(node != NULL, "node == NULL\n");
5417         test_node_name((IUnknown*)node, "BODY");
5418         node2 = test_node_get_parent((IUnknown*)node);
5419         IHTMLDOMNode_Release(node);
5420         ok(node2 != NULL, "node == NULL\n");
5421         test_node_name((IUnknown*)node2, "HTML");
5422         node = test_node_get_parent((IUnknown*)node2);
5423         IHTMLDOMNode_Release(node2);
5424         ok(node != NULL, "node == NULL\n");
5425         if (node)
5426         {
5427             test_node_name((IUnknown*)node, "#document");
5428             type = get_node_type((IUnknown*)node);
5429             ok(type == 9, "type=%d, expected 9\n", type);
5430             node2 = test_node_get_parent((IUnknown*)node);
5431             IHTMLDOMNode_Release(node);
5432             ok(node2 == NULL, "node != NULL\n");
5433         }
5434
5435         elem2 = test_elem_get_parent((IUnknown*)elem);
5436         ok(elem2 != NULL, "elem2 == NULL\n");
5437         test_node_name((IUnknown*)elem2, "BODY");
5438         elem3 = test_elem_get_parent((IUnknown*)elem2);
5439         IHTMLElement_Release(elem2);
5440         ok(elem3 != NULL, "elem3 == NULL\n");
5441         test_node_name((IUnknown*)elem3, "HTML");
5442         elem2 = test_elem_get_parent((IUnknown*)elem3);
5443         IHTMLElement_Release(elem3);
5444         ok(elem2 == NULL, "elem2 != NULL\n");
5445
5446         test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
5447         test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
5448         test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
5449
5450         test_elem_innertext(elem, "opt1opt2");
5451
5452         IHTMLElement_Release(elem);
5453     }
5454
5455     elem = get_elem_by_id(doc, "s", TRUE);
5456     if(elem) {
5457         IHTMLSelectElement *select;
5458         IHTMLDocument2 *doc_node, *elem_doc;
5459
5460         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
5461         ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
5462
5463         test_select_elem(select);
5464
5465         test_elem_title((IUnknown*)select, NULL);
5466         test_elem_set_title((IUnknown*)select, "Title");
5467         test_elem_title((IUnknown*)select, "Title");
5468         test_elem_offset((IUnknown*)select);
5469
5470         node = get_first_child((IUnknown*)select);
5471         ok(node != NULL, "node == NULL\n");
5472         if(node) {
5473             test_elem_type((IUnknown*)node, ET_OPTION);
5474             IHTMLDOMNode_Release(node);
5475         }
5476
5477         type = get_node_type((IUnknown*)select);
5478         ok(type == 1, "type=%d\n", type);
5479
5480         IHTMLSelectElement_Release(select);
5481
5482         elem_doc = get_elem_doc((IUnknown*)elem);
5483
5484         doc_node = get_doc_node(doc);
5485         ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
5486         IHTMLDocument2_Release(doc_node);
5487         IHTMLDocument2_Release(elem_doc);
5488
5489         IHTMLElement_Release(elem);
5490     }
5491
5492     elem = get_elem_by_id(doc, "sc", TRUE);
5493     if(elem) {
5494         IHTMLScriptElement *script;
5495         BSTR type;
5496
5497         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
5498         ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
5499
5500         if(hres == S_OK)
5501         {
5502             VARIANT_BOOL vb;
5503
5504             hres = IHTMLScriptElement_get_type(script, &type);
5505             ok(hres == S_OK, "get_type failed: %08x\n", hres);
5506             ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
5507             SysFreeString(type);
5508
5509             /* test defer */
5510             hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
5511             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5512
5513             hres = IHTMLScriptElement_get_defer(script, &vb);
5514             ok(hres == S_OK, "get_defer failed: %08x\n", hres);
5515             ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
5516
5517             hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
5518             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5519         }
5520
5521         IHTMLScriptElement_Release(script);
5522     }
5523
5524     elem = get_elem_by_id(doc, "in", TRUE);
5525     if(elem) {
5526         IHTMLInputElement *input;
5527
5528         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
5529         ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
5530
5531         test_elem_id((IUnknown*)elem, "in");
5532         test_elem_put_id((IUnknown*)elem, "newin");
5533         test_input_get_disabled(input, VARIANT_FALSE);
5534         test_input_set_disabled(input, VARIANT_TRUE);
5535         test_input_set_disabled(input, VARIANT_FALSE);
5536         test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
5537         test_input_get_disabled(input, VARIANT_TRUE);
5538         test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
5539         test_input_get_disabled(input, VARIANT_FALSE);
5540         test_elem_client_size((IUnknown*)elem);
5541
5542         test_node_get_value_str((IUnknown*)elem, NULL);
5543         test_node_put_value_str((IUnknown*)elem, "test");
5544         test_node_get_value_str((IUnknown*)elem, NULL);
5545         test_input_value((IUnknown*)elem, NULL);
5546         test_input_put_value((IUnknown*)elem, "test");
5547         test_input_value((IUnknown*)elem, NULL);
5548         test_elem_class((IUnknown*)elem, "testclass");
5549         test_elem_tabindex((IUnknown*)elem, 2);
5550         test_elem_set_tabindex((IUnknown*)elem, 3);
5551         test_elem_title((IUnknown*)elem, "test title");
5552
5553         test_input_get_defaultchecked(input, VARIANT_FALSE);
5554         test_input_set_defaultchecked(input, VARIANT_TRUE);
5555         test_input_set_defaultchecked(input, VARIANT_FALSE);
5556
5557         test_input_get_checked(input, VARIANT_FALSE);
5558         test_input_set_checked(input, VARIANT_TRUE);
5559         test_input_set_checked(input, VARIANT_FALSE);
5560
5561         test_input_src(input, NULL);
5562         test_input_set_src(input, "about:blank");
5563
5564         IHTMLInputElement_Release(input);
5565         IHTMLElement_Release(elem);
5566     }
5567
5568     elem = get_elem_by_id(doc, "imgid", TRUE);
5569     if(elem) {
5570         test_img_src((IUnknown*)elem, "");
5571         test_img_set_src((IUnknown*)elem, "about:blank");
5572         test_img_alt((IUnknown*)elem, NULL);
5573         test_img_set_alt((IUnknown*)elem, "alt test");
5574         test_img_name((IUnknown*)elem, "WineImg");
5575         IHTMLElement_Release(elem);
5576     }
5577
5578     elem = get_doc_elem_by_id(doc, "tbl");
5579     ok(elem != NULL, "elem == NULL\n");
5580     if(elem) {
5581         test_table_elem(elem);
5582         IHTMLElement_Release(elem);
5583     }
5584
5585     elem = get_doc_elem_by_id(doc, "row2");
5586     ok(elem != NULL, "elem == NULL\n");
5587     if(elem) {
5588         test_tr_elem(elem);
5589         IHTMLElement_Release(elem);
5590     }
5591
5592     elem = get_doc_elem_by_id(doc, "ifr");
5593     ok(elem != NULL, "elem == NULL\n");
5594     if(elem) {
5595         test_iframe_elem(elem);
5596         IHTMLElement_Release(elem);
5597     }
5598
5599     elem = get_elem_by_id(doc, "a", TRUE);
5600     if(elem) {
5601         test_anchor_href((IUnknown*)elem, "http://test/");
5602         IHTMLElement_Release(elem);
5603     }
5604
5605     hres = IHTMLDocument2_get_body(doc, &elem);
5606     ok(hres == S_OK, "get_body failed: %08x\n", hres);
5607
5608     node = get_first_child((IUnknown*)elem);
5609     ok(node != NULL, "node == NULL\n");
5610     if(node) {
5611         test_ifaces((IUnknown*)node, text_iids);
5612         test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5613
5614         node2 = get_first_child((IUnknown*)node);
5615         ok(!node2, "node2 != NULL\n");
5616
5617         type = get_node_type((IUnknown*)node);
5618         ok(type == 3, "type=%d\n", type);
5619
5620         test_node_get_value_str((IUnknown*)node, "text test");
5621         test_node_put_value_str((IUnknown*)elem, "test text");
5622         test_node_get_value_str((IUnknown*)node, "text test");
5623
5624         IHTMLDOMNode_Release(node);
5625     }
5626
5627     child_col = get_child_nodes((IUnknown*)elem);
5628     ok(child_col != NULL, "child_coll == NULL\n");
5629     if(child_col) {
5630         LONG length = 0;
5631
5632         test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
5633
5634         hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
5635         ok(hres == S_OK, "get_length failed: %08x\n", hres);
5636         ok(length, "length=0\n");
5637
5638         node2 = NULL;
5639         node = get_child_item(child_col, 0);
5640         ok(node != NULL, "node == NULL\n");
5641         if(node) {
5642             type = get_node_type((IUnknown*)node);
5643             ok(type == 3, "type=%d\n", type);
5644             node2 = node_get_next((IUnknown*)node);
5645             IHTMLDOMNode_Release(node);
5646         }
5647
5648         node = get_child_item(child_col, 1);
5649         ok(node != NULL, "node == NULL\n");
5650         if(node) {
5651             type = get_node_type((IUnknown*)node);
5652             ok(type == 8, "type=%d\n", type);
5653
5654             test_elem_id((IUnknown*)node, NULL);
5655             ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
5656             IHTMLDOMNode_Release(node2);
5657             IHTMLDOMNode_Release(node);
5658         }
5659
5660         hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
5661         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5662
5663         hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
5664         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5665
5666         hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
5667         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5668
5669         hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
5670         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5671
5672         test_child_col_disp(child_col);
5673
5674         IHTMLDOMChildrenCollection_Release(child_col);
5675     }
5676
5677     test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
5678     test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
5679     test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
5680
5681     IHTMLElement_Release(elem);
5682
5683     test_stylesheets(doc);
5684     test_create_option_elem(doc);
5685     test_create_img_elem(doc);
5686
5687     elem = get_doc_elem_by_id(doc, "tbl");
5688     ok(elem != NULL, "elem = NULL\n");
5689     test_elem_set_innertext(elem, "inner text");
5690     IHTMLElement_Release(elem);
5691
5692     test_doc_title(doc, "test");
5693     test_doc_set_title(doc, "test title");
5694     test_doc_title(doc, "test title");
5695
5696     disp = NULL;
5697     hres = IHTMLDocument2_get_Script(doc, &disp);
5698     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5699     if(hres == S_OK)
5700     {
5701         IDispatchEx *dispex;
5702         hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
5703         ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
5704         if(hres == S_OK)
5705         {
5706             DISPID pid = -1;
5707             BSTR str = a2bstr("Testing");
5708             hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
5709             ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5710             ok(pid != -1, "pid == -1\n");
5711             SysFreeString(str);
5712             IDispatchEx_Release(dispex);
5713         }
5714     }
5715     IDispatch_Release(disp);
5716
5717     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5718     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5719
5720     str = a2bstr("img");
5721     hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
5722     ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
5723     SysFreeString(str);
5724     if(hres == S_OK)
5725     {
5726         static const elem_type_t img_types[] = { ET_IMG };
5727
5728         test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
5729         IHTMLElementCollection_Release(col);
5730     }
5731
5732     elem = get_doc_elem_by_id(doc, "y");
5733     test_elem_set_innerhtml((IUnknown*)elem, "inner html");
5734     test_elem_innerhtml((IUnknown*)elem, "inner html");
5735     test_elem_set_innerhtml((IUnknown*)elem, "");
5736     test_elem_innerhtml((IUnknown*)elem, NULL);
5737     node = node_get_next((IUnknown*)elem);
5738     ok(!node, "node = %p\n", node);
5739
5740     elem2 = get_doc_elem_by_id(doc, "x");
5741     test_elem_tag((IUnknown*)elem2, "A");
5742     node = node_get_next((IUnknown*)elem2);
5743     IHTMLDOMNode_Release(node);
5744     IHTMLElement_Release(elem2);
5745     IHTMLElement_Release(elem);
5746
5747     IHTMLDocument3_Release(doc3);
5748
5749     window = get_doc_window(doc);
5750     test_window_name(window, NULL);
5751     set_window_name(window, "test name");
5752     test_window_length(window, 1);
5753     IHTMLWindow2_Release(window);
5754 }
5755
5756 static void test_elems2(IHTMLDocument2 *doc)
5757 {
5758     IHTMLElement *elem, *elem2;
5759
5760     static const elem_type_t outer_types[] = {
5761         ET_BR,
5762         ET_A
5763     };
5764
5765     elem = get_doc_elem_by_id(doc, "divid");
5766
5767     test_elem_set_innerhtml((IUnknown*)elem, "<div id=\"innerid\"></div>");
5768     elem2 = get_doc_elem_by_id(doc, "innerid");
5769     ok(elem2 != NULL, "elem2 == NULL\n");
5770     test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
5771     test_elem_all((IUnknown*)elem, outer_types, sizeof(outer_types)/sizeof(*outer_types));
5772     IHTMLElement_Release(elem2);
5773
5774     elem2 = get_doc_elem_by_id(doc, "aid");
5775     ok(elem2 != NULL, "elem2 == NULL\n");
5776     test_elem_set_outerhtml((IUnknown*)elem2, "");
5777     test_elem_all((IUnknown*)elem, outer_types, 1);
5778     IHTMLElement_Release(elem2);
5779
5780     IHTMLElement_Release(elem);
5781 }
5782
5783 static void test_create_elems(IHTMLDocument2 *doc)
5784 {
5785     IHTMLElement *elem, *body, *elem2;
5786     IHTMLDOMNode *node, *node2, *node3, *comment;
5787     IHTMLDocument5 *doc5;
5788     IDispatch *disp;
5789     VARIANT var;
5790     LONG type;
5791     HRESULT hres;
5792     BSTR str;
5793
5794     static const elem_type_t types1[] = { ET_TESTG };
5795
5796     elem = test_create_elem(doc, "TEST");
5797     test_elem_tag((IUnknown*)elem, "TEST");
5798     type = get_node_type((IUnknown*)elem);
5799     ok(type == 1, "type=%d\n", type);
5800     test_ifaces((IUnknown*)elem, elem_iids);
5801     test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
5802
5803     hres = IHTMLDocument2_get_body(doc, &body);
5804     ok(hres == S_OK, "get_body failed: %08x\n", hres);
5805     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5806
5807     node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
5808     test_node_has_child((IUnknown*)body, VARIANT_TRUE);
5809     elem2 = get_elem_iface((IUnknown*)node);
5810     IHTMLElement_Release(elem2);
5811
5812     hres = IHTMLElement_get_all(body, &disp);
5813     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5814     test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
5815     IDispatch_Release(disp);
5816
5817     test_node_remove_child((IUnknown*)body, node);
5818
5819     hres = IHTMLElement_get_all(body, &disp);
5820     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5821     test_elem_collection((IUnknown*)disp, NULL, 0);
5822     IDispatch_Release(disp);
5823     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5824
5825     IHTMLElement_Release(elem);
5826     IHTMLDOMNode_Release(node);
5827
5828     node = test_create_text(doc, "test");
5829     test_ifaces((IUnknown*)node, text_iids);
5830     test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5831     test_text_length((IUnknown*)node, 4);
5832
5833     V_VT(&var) = VT_NULL;
5834     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5835     IHTMLDOMNode_Release(node);
5836
5837     node = test_create_text(doc, "insert ");
5838
5839     V_VT(&var) = VT_DISPATCH;
5840     V_DISPATCH(&var) = (IDispatch*)node2;
5841     node3 = test_node_insertbefore((IUnknown*)body, node, &var);
5842     IHTMLDOMNode_Release(node);
5843     IHTMLDOMNode_Release(node2);
5844     IHTMLDOMNode_Release(node3);
5845
5846     test_elem_innertext(body, "insert test");
5847     test_elem_innerhtml((IUnknown*)body, "insert test");
5848
5849     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
5850     if(hres == S_OK)
5851     {
5852         str = a2bstr("testing");
5853         hres = IHTMLDocument5_createComment(doc5, str, &comment);
5854         SysFreeString(str);
5855         ok(hres == S_OK, "createComment failed: %08x\n", hres);
5856         if(hres == S_OK)
5857         {
5858             type = get_node_type((IUnknown*)comment);
5859             ok(type == 8, "type=%d, expected 8\n", type);
5860
5861             test_node_get_value_str((IUnknown*)comment, "testing");
5862
5863             IHTMLDOMNode_Release(comment);
5864         }
5865
5866         IHTMLDocument5_Release(doc5);
5867     }
5868
5869     IHTMLElement_Release(body);
5870 }
5871
5872 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
5873 {
5874     IOleCommandTarget *cmdtrg;
5875     HRESULT hres;
5876
5877     hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
5878     ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
5879
5880     hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
5881     ok(hres == S_OK, "Exec failed: %08x\n", hres);
5882
5883     IOleCommandTarget_Release(cmdtrg);
5884 }
5885
5886 static void test_indent(IHTMLDocument2 *doc)
5887 {
5888     IHTMLElementCollection *col;
5889     IHTMLTxtRange *range;
5890     HRESULT hres;
5891
5892     static const elem_type_t all_types[] = {
5893         ET_HTML,
5894         ET_HEAD,
5895         ET_TITLE,
5896         ET_BODY,
5897         ET_BR,
5898         ET_A,
5899     };
5900
5901     static const elem_type_t indent_types[] = {
5902         ET_HTML,
5903         ET_HEAD,
5904         ET_TITLE,
5905         ET_BODY,
5906         ET_BLOCKQUOTE,
5907         ET_P,
5908         ET_BR,
5909         ET_A,
5910     };
5911
5912     hres = IHTMLDocument2_get_all(doc, &col);
5913     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5914     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5915     IHTMLElementCollection_Release(col);
5916
5917     range = test_create_body_range(doc);
5918     test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
5919     IHTMLTxtRange_Release(range);
5920
5921     hres = IHTMLDocument2_get_all(doc, &col);
5922     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5923     test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
5924     IHTMLElementCollection_Release(col);
5925 }
5926
5927 static void test_cond_comment(IHTMLDocument2 *doc)
5928 {
5929     IHTMLElementCollection *col;
5930     HRESULT hres;
5931
5932     static const elem_type_t all_types[] = {
5933         ET_HTML,
5934         ET_HEAD,
5935         ET_TITLE,
5936         ET_BODY,
5937         ET_BR
5938     };
5939
5940     hres = IHTMLDocument2_get_all(doc, &col);
5941     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5942     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5943     IHTMLElementCollection_Release(col);
5944 }
5945
5946 static void test_frame(IDispatch *disp, const char *exp_id)
5947 {
5948     IHTMLWindow2 *frame2, *parent, *top;
5949     IHTMLDocument2 *parent_doc, *top_doc;
5950     IHTMLWindow4 *frame;
5951     IHTMLFrameBase *frame_elem;
5952     HRESULT hres;
5953
5954     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
5955     ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
5956     if(FAILED(hres))
5957         return;
5958
5959     hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
5960     ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
5961     IHTMLWindow4_Release(frame);
5962     if(FAILED(hres))
5963         return;
5964
5965     test_frame_doc((IUnknown*)frame_elem);
5966     test_elem_id((IUnknown*)frame_elem, exp_id);
5967     IHTMLElement_Release(frame_elem);
5968
5969     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
5970     ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
5971     if(FAILED(hres))
5972         return;
5973
5974     hres = IHTMLWindow2_get_parent(frame2, &parent);
5975     ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
5976     if(FAILED(hres)){
5977         IHTMLWindow2_Release(frame2);
5978         return;
5979     }
5980
5981     hres = IHTMLWindow2_get_document(parent, &parent_doc);
5982     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
5983     IHTMLWindow2_Release(parent);
5984     if(FAILED(hres)){
5985         IHTMLWindow2_Release(frame2);
5986         return;
5987     }
5988
5989     test_doc_title(parent_doc, "frameset test");
5990     IHTMLDocument2_Release(parent_doc);
5991
5992     /* test get_top */
5993     hres = IHTMLWindow2_get_top(frame2, &top);
5994     ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
5995     IHTMLWindow2_Release(frame2);
5996     if(FAILED(hres))
5997         return;
5998
5999     hres = IHTMLWindow2_get_document(top, &top_doc);
6000     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
6001     IHTMLWindow2_Release(top);
6002     if(FAILED(hres))
6003         return;
6004
6005     test_doc_title(top_doc, "frameset test");
6006     IHTMLDocument2_Release(top_doc);
6007 }
6008
6009 static void test_frameset(IHTMLDocument2 *doc)
6010 {
6011     IHTMLWindow2 *window;
6012     IHTMLFramesCollection2 *frames;
6013     IHTMLElement *elem;
6014     IHTMLFrameBase *fbase;
6015     LONG length;
6016     VARIANT index_var, result_var;
6017     BSTR str;
6018     HRESULT hres;
6019
6020     window = get_doc_window(doc);
6021
6022     /* test using IHTMLFramesCollection object */
6023
6024     hres = IHTMLWindow2_get_frames(window, &frames);
6025     ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
6026     IHTMLWindow2_Release(window);
6027     if(FAILED(hres))
6028         return;
6029
6030     /* test result length */
6031     hres = IHTMLFramesCollection2_get_length(frames, &length);
6032     ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
6033     ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
6034
6035     /* test first frame */
6036     V_VT(&index_var) = VT_I4;
6037     V_I4(&index_var) = 0;
6038     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6039     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6040     if(SUCCEEDED(hres)) {
6041         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6042         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
6043     }
6044     VariantClear(&result_var);
6045
6046     /* test second frame */
6047     V_I4(&index_var) = 1;
6048     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6049     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6050     if(SUCCEEDED(hres)) {
6051         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6052         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6053     }
6054     VariantClear(&result_var);
6055
6056     /* fail on next frame */
6057     V_I4(&index_var) = 3;
6058     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6059     ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
6060            "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
6061     VariantClear(&result_var);
6062
6063     /* string argument (element id lookup) */
6064     V_VT(&index_var) = VT_BSTR;
6065     V_BSTR(&index_var) = a2bstr("fr1");
6066     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6067     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6068     if(SUCCEEDED(hres)) {
6069         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6070         test_frame(V_DISPATCH(&result_var), "fr1");
6071     }
6072     VariantClear(&result_var);
6073     VariantClear(&index_var);
6074
6075     /* invalid argument */
6076     V_VT(&index_var) = VT_BOOL;
6077     V_BOOL(&index_var) = VARIANT_TRUE;
6078     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6079     ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
6080            "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
6081     VariantClear(&result_var);
6082
6083     IHTMLFramesCollection2_Release(frames);
6084
6085     /* test using IHTMLWindow2 inheritance */
6086
6087     /* test result length */
6088     hres = IHTMLWindow2_get_length(window, &length);
6089     ok(hres == S_OK, "IHTMLWindow2_get_length failed: 0x%08x\n", hres);
6090     ok(length == 3, "IHTMLWindow2_get_length should have been 3, was: %d\n", length);
6091
6092     /* test first frame */
6093     V_VT(&index_var) = VT_I4;
6094     V_I4(&index_var) = 0;
6095     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6096     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6097     if(SUCCEEDED(hres)) {
6098         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6099         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
6100     }
6101     VariantClear(&result_var);
6102
6103     /* test second frame */
6104     V_I4(&index_var) = 1;
6105     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6106     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6107     if(SUCCEEDED(hres)) {
6108         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6109         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6110     }
6111     VariantClear(&result_var);
6112
6113     /* fail on next frame */
6114     V_I4(&index_var) = 3;
6115     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6116     ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLWindow2_item should have"
6117            "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
6118     VariantClear(&result_var);
6119
6120     /* string argument (element id lookup) */
6121     V_VT(&index_var) = VT_BSTR;
6122     V_BSTR(&index_var) = a2bstr("fr2");
6123     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6124     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6125     if(SUCCEEDED(hres)) {
6126         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6127         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6128     }
6129     VariantClear(&result_var);
6130     VariantClear(&index_var);
6131
6132     /* invalid argument */
6133     V_VT(&index_var) = VT_BOOL;
6134     V_BOOL(&index_var) = VARIANT_TRUE;
6135     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6136     ok(hres == E_INVALIDARG, "IHTMLWindow2_item should have"
6137            "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
6138     VariantClear(&result_var);
6139
6140     /* getElementById with node name attributes */
6141     elem = get_doc_elem_by_id(doc, "nm1");
6142     test_elem_id((IUnknown*)elem, "fr1");
6143
6144     /* get/put scrolling */
6145     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6146     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6147
6148     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6149     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6150     ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
6151     SysFreeString(str);
6152
6153     str = a2bstr("no");
6154     hres = IHTMLFrameBase_put_scrolling(fbase, str);
6155     ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
6156     SysFreeString(str);
6157
6158     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6159     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6160     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6161     SysFreeString(str);
6162
6163     str = a2bstr("junk");
6164     hres = IHTMLFrameBase_put_scrolling(fbase, str);
6165     ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
6166             "with E_INVALIDARG, instead: 0x%08x\n", hres);
6167     SysFreeString(str);
6168
6169     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6170     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6171     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6172     SysFreeString(str);
6173
6174     /* get_name */
6175     hres = IHTMLFrameBase_get_name(fbase, &str);
6176     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
6177     ok(!strcmp_wa(str, "nm1"), "get_name should have given 'nm1', gave: %s\n", wine_dbgstr_w(str));
6178     SysFreeString(str);
6179
6180     IHTMLFrameBase_Release(fbase);
6181     IHTMLElement_Release(elem);
6182
6183     /* get_name with no name attr */
6184     elem = get_doc_elem_by_id(doc, "fr3");
6185     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6186     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6187
6188     hres = IHTMLFrameBase_get_name(fbase, &str);
6189     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
6190     ok(str == NULL, "get_name should have given 'null', gave: %s\n", wine_dbgstr_w(str));
6191     SysFreeString(str);
6192
6193     IHTMLFrameBase_Release(fbase);
6194     IHTMLElement_Release(elem);
6195 }
6196
6197 static IHTMLDocument2 *notif_doc;
6198 static BOOL doc_complete;
6199
6200 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
6201         REFIID riid, void**ppv)
6202 {
6203     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
6204         *ppv = iface;
6205         return S_OK;
6206     }
6207
6208     ok(0, "unexpected call\n");
6209     return E_NOINTERFACE;
6210 }
6211
6212 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
6213 {
6214     return 2;
6215 }
6216
6217 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
6218 {
6219     return 1;
6220 }
6221
6222 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
6223 {
6224     if(dispID == DISPID_READYSTATE){
6225         BSTR state;
6226         HRESULT hres;
6227
6228         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
6229         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
6230
6231         if(!strcmp_wa(state, "complete"))
6232             doc_complete = TRUE;
6233
6234         SysFreeString(state);
6235     }
6236
6237     return S_OK;
6238 }
6239
6240 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
6241 {
6242     ok(0, "unexpected call\n");
6243     return E_NOTIMPL;
6244 }
6245
6246 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
6247     PropertyNotifySink_QueryInterface,
6248     PropertyNotifySink_AddRef,
6249     PropertyNotifySink_Release,
6250     PropertyNotifySink_OnChanged,
6251     PropertyNotifySink_OnRequestEdit
6252 };
6253
6254 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
6255
6256 static IHTMLDocument2 *create_doc_with_string(const char *str)
6257 {
6258     IPersistStreamInit *init;
6259     IStream *stream;
6260     IHTMLDocument2 *doc;
6261     HGLOBAL mem;
6262     SIZE_T len;
6263
6264     notif_doc = doc = create_document();
6265     if(!doc)
6266         return NULL;
6267
6268     doc_complete = FALSE;
6269     len = strlen(str);
6270     mem = GlobalAlloc(0, len);
6271     memcpy(mem, str, len);
6272     CreateStreamOnHGlobal(mem, TRUE, &stream);
6273
6274     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
6275
6276     IPersistStreamInit_Load(init, stream);
6277     IPersistStreamInit_Release(init);
6278     IStream_Release(stream);
6279
6280     return doc;
6281 }
6282
6283 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
6284 {
6285     IConnectionPointContainer *container;
6286     IConnectionPoint *cp;
6287     DWORD cookie;
6288     HRESULT hres;
6289
6290     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
6291     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
6292
6293     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
6294     IConnectionPointContainer_Release(container);
6295     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
6296
6297     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
6298     IConnectionPoint_Release(cp);
6299     ok(hres == S_OK, "Advise failed: %08x\n", hres);
6300 }
6301
6302 typedef void (*domtest_t)(IHTMLDocument2*);
6303
6304 static void run_domtest(const char *str, domtest_t test)
6305 {
6306     IHTMLDocument2 *doc;
6307     ULONG ref;
6308     MSG msg;
6309
6310     doc = create_doc_with_string(str);
6311     if(!doc)
6312         return;
6313
6314     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
6315
6316     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
6317         TranslateMessage(&msg);
6318         DispatchMessage(&msg);
6319     }
6320
6321     test(doc);
6322
6323     ref = IHTMLDocument2_Release(doc);
6324     ok(!ref ||
6325        ref == 1, /* Vista */
6326        "ref = %d\n", ref);
6327 }
6328
6329 START_TEST(dom)
6330 {
6331     CoInitialize(NULL);
6332
6333     run_domtest(doc_str1, test_doc_elem);
6334     run_domtest(doc_str1, test_get_set_attr);
6335     run_domtest(range_test_str, test_txtrange);
6336     run_domtest(range_test2_str, test_txtrange2);
6337     if (winetest_interactive || ! is_ie_hardened()) {
6338         run_domtest(elem_test_str, test_elems);
6339     }else {
6340         skip("IE running in Enhanced Security Configuration\n");
6341     }
6342     run_domtest(elem_test2_str, test_elems2);
6343     run_domtest(doc_blank, test_create_elems);
6344     run_domtest(doc_blank, test_defaults);
6345     run_domtest(indent_test_str, test_indent);
6346     run_domtest(cond_comment_str, test_cond_comment);
6347     run_domtest(frameset_str, test_frameset);
6348
6349     CoUninitialize();
6350 }