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