hlink: Convert dll registration to the IRegistrar mechanism.
[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     /* padding */
4980     hres = IHTMLStyle_get_padding(style, &str);
4981     ok(hres == S_OK, "get_padding failed: %08x\n", hres);
4982     ok(!str, "padding = %s\n", wine_dbgstr_w(str));
4983     SysFreeString(str);
4984
4985     str = a2bstr("1");
4986     hres = IHTMLStyle_put_padding(style, str);
4987     ok(hres == S_OK, "put_padding failed: %08x\n", hres);
4988     SysFreeString(str);
4989
4990     hres = IHTMLStyle_get_padding(style, &str);
4991     ok(hres == S_OK, "get_padding failed: %08x\n", hres);
4992     ok(!strcmp_wa(str, "1px"), "padding = %s\n", wine_dbgstr_w(str));
4993     SysFreeString(str);
4994
4995     /* PaddingLeft */
4996     hres = IHTMLStyle_get_paddingLeft(style, &vDefault);
4997     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
4998
4999     V_VT(&v) = VT_BSTR;
5000     V_BSTR(&v) = a2bstr("10");
5001     hres = IHTMLStyle_put_paddingLeft(style, v);
5002     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
5003     VariantClear(&v);
5004
5005     hres = IHTMLStyle_get_paddingLeft(style, &v);
5006     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
5007     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expecte 10 = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5008     VariantClear(&v);
5009
5010     hres = IHTMLStyle_put_paddingLeft(style, vDefault);
5011     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
5012
5013     /* BackgroundRepeat */
5014     hres = IHTMLStyle_get_backgroundRepeat(style, &sDefault);
5015     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
5016
5017     str = a2bstr("invalid");
5018     hres = IHTMLStyle_put_backgroundRepeat(style, str);
5019     ok(hres == E_INVALIDARG, "put_backgroundRepeat failed: %08x\n", hres);
5020     SysFreeString(str);
5021
5022     str = a2bstr("repeat");
5023     hres = IHTMLStyle_put_backgroundRepeat(style, str);
5024     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
5025     SysFreeString(str);
5026
5027     str = a2bstr("no-repeat");
5028     hres = IHTMLStyle_put_backgroundRepeat(style, str);
5029     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
5030     SysFreeString(str);
5031
5032     str = a2bstr("repeat-x");
5033     hres = IHTMLStyle_put_backgroundRepeat(style, str);
5034     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
5035     SysFreeString(str);
5036
5037     str = a2bstr("repeat-y");
5038     hres = IHTMLStyle_put_backgroundRepeat(style, str);
5039     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
5040     SysFreeString(str);
5041
5042     hres = IHTMLStyle_get_backgroundRepeat(style, &str);
5043     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
5044     ok(!strcmp_wa(str, "repeat-y"), "str=%s\n", wine_dbgstr_w(str));
5045     SysFreeString(str);
5046
5047     hres = IHTMLStyle_put_backgroundRepeat(style, sDefault);
5048     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
5049     SysFreeString(sDefault);
5050
5051     /* BorderColor */
5052     hres = IHTMLStyle_get_borderColor(style, &sDefault);
5053     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
5054
5055     str = a2bstr("red green red blue");
5056     hres = IHTMLStyle_put_borderColor(style, str);
5057     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
5058     SysFreeString(str);
5059
5060     hres = IHTMLStyle_get_borderColor(style, &str);
5061     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
5062     ok(!strcmp_wa(str, "red green red blue"), "str=%s\n", wine_dbgstr_w(str));
5063     SysFreeString(str);
5064
5065     hres = IHTMLStyle_put_borderColor(style, sDefault);
5066     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
5067     SysFreeString(sDefault);
5068
5069     /* BorderRight */
5070     hres = IHTMLStyle_get_borderRight(style, &sDefault);
5071     ok(hres == S_OK, "get_borderRight failed: %08x\n", hres);
5072
5073     str = a2bstr("thick dotted red");
5074     hres = IHTMLStyle_put_borderRight(style, str);
5075     ok(hres == S_OK, "put_borderRight failed: %08x\n", hres);
5076     SysFreeString(str);
5077
5078     /* IHTMLStyle_get_borderRight appears to have a bug where
5079         it returns the first letter of the color.  So we check
5080         each style individually.
5081      */
5082     V_BSTR(&v) = NULL;
5083     hres = IHTMLStyle_get_borderRightColor(style, &v);
5084     ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
5085     ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5086     VariantClear(&v);
5087
5088     V_BSTR(&v) = NULL;
5089     hres = IHTMLStyle_get_borderRightWidth(style, &v);
5090     ok(hres == S_OK, "get_borderRightWidth failed: %08x\n", hres);
5091     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5092     VariantClear(&v);
5093
5094     hres = IHTMLStyle_get_borderRightStyle(style, &str);
5095     ok(hres == S_OK, "get_borderRightStyle failed: %08x\n", hres);
5096     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
5097     SysFreeString(str);
5098
5099     hres = IHTMLStyle_put_borderRight(style, sDefault);
5100     ok(hres == S_OK, "put_borderRight failed: %08x\n", hres);
5101     SysFreeString(sDefault);
5102
5103     /* BorderTop */
5104     hres = IHTMLStyle_get_borderTop(style, &sDefault);
5105     ok(hres == S_OK, "get_borderTop failed: %08x\n", hres);
5106
5107     str = a2bstr("thick dotted red");
5108     hres = IHTMLStyle_put_borderTop(style, str);
5109     ok(hres == S_OK, "put_borderTop failed: %08x\n", hres);
5110     SysFreeString(str);
5111
5112     /* IHTMLStyle_get_borderTop appears to have a bug where
5113         it returns the first letter of the color.  So we check
5114         each style individually.
5115      */
5116     V_BSTR(&v) = NULL;
5117     hres = IHTMLStyle_get_borderTopColor(style, &v);
5118     ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
5119     ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5120     VariantClear(&v);
5121
5122     V_BSTR(&v) = NULL;
5123     hres = IHTMLStyle_get_borderTopWidth(style, &v);
5124     ok(hres == S_OK, "get_borderTopWidth failed: %08x\n", hres);
5125     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5126     VariantClear(&v);
5127
5128     hres = IHTMLStyle_get_borderTopStyle(style, &str);
5129     ok(hres == S_OK, "get_borderTopStyle failed: %08x\n", hres);
5130     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
5131     SysFreeString(str);
5132
5133     hres = IHTMLStyle_put_borderTop(style, sDefault);
5134     ok(hres == S_OK, "put_borderTop failed: %08x\n", hres);
5135     SysFreeString(sDefault);
5136
5137     /* BorderBottom */
5138     hres = IHTMLStyle_get_borderBottom(style, &sDefault);
5139     ok(hres == S_OK, "get_borderBottom failed: %08x\n", hres);
5140
5141     str = a2bstr("thick dotted red");
5142     hres = IHTMLStyle_put_borderBottom(style, str);
5143     ok(hres == S_OK, "put_borderBottom failed: %08x\n", hres);
5144     SysFreeString(str);
5145
5146     /* IHTMLStyle_get_borderBottom appears to have a bug where
5147         it returns the first letter of the color.  So we check
5148         each style individually.
5149      */
5150     V_BSTR(&v) = NULL;
5151     hres = IHTMLStyle_get_borderBottomColor(style, &v);
5152     ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
5153     ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5154     VariantClear(&v);
5155
5156     V_BSTR(&v) = NULL;
5157     hres = IHTMLStyle_get_borderBottomWidth(style, &v);
5158     ok(hres == S_OK, "get_borderBottomWidth failed: %08x\n", hres);
5159     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5160     VariantClear(&v);
5161
5162     hres = IHTMLStyle_get_borderBottomStyle(style, &str);
5163     ok(hres == S_OK, "get_borderBottomStyle failed: %08x\n", hres);
5164     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
5165     SysFreeString(str);
5166
5167     hres = IHTMLStyle_put_borderBottom(style, sDefault);
5168     ok(hres == S_OK, "put_borderBottom failed: %08x\n", hres);
5169     SysFreeString(sDefault);
5170
5171     /* BorderLeft */
5172     hres = IHTMLStyle_get_borderLeft(style, &sDefault);
5173     ok(hres == S_OK, "get_borderLeft failed: %08x\n", hres);
5174
5175     str = a2bstr("thick dotted red");
5176     hres = IHTMLStyle_put_borderLeft(style, str);
5177     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
5178     SysFreeString(str);
5179
5180     /* IHTMLStyle_get_borderLeft appears to have a bug where
5181         it returns the first letter of the color.  So we check
5182         each style individually.
5183      */
5184     V_BSTR(&v) = NULL;
5185     hres = IHTMLStyle_get_borderLeftColor(style, &v);
5186     ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
5187     ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5188     VariantClear(&v);
5189
5190     V_BSTR(&v) = NULL;
5191     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
5192     ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
5193     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5194     VariantClear(&v);
5195
5196     hres = IHTMLStyle_get_borderLeftStyle(style, &str);
5197     ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
5198     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
5199     SysFreeString(str);
5200
5201     hres = IHTMLStyle_put_borderLeft(style, sDefault);
5202     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
5203     SysFreeString(sDefault);
5204
5205     /* backgroundPositionX */
5206     hres = IHTMLStyle_get_backgroundPositionX(style, &vDefault);
5207     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
5208
5209     V_VT(&v) = VT_BSTR;
5210     V_BSTR(&v) = a2bstr("10px");
5211     hres = IHTMLStyle_put_backgroundPositionX(style, v);
5212     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
5213     VariantClear(&v);
5214
5215     hres = IHTMLStyle_get_backgroundPositionX(style, &v);
5216     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
5217     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
5218     VariantClear(&v);
5219
5220     hres = IHTMLStyle_put_backgroundPositionX(style, vDefault);
5221     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
5222     VariantClear(&vDefault);
5223
5224     /* backgroundPositionY */
5225     hres = IHTMLStyle_get_backgroundPositionY(style, &vDefault);
5226     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
5227
5228     V_VT(&v) = VT_BSTR;
5229     V_BSTR(&v) = a2bstr("10px");
5230     hres = IHTMLStyle_put_backgroundPositionY(style, v);
5231     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
5232     VariantClear(&v);
5233
5234     hres = IHTMLStyle_get_backgroundPositionY(style, &v);
5235     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
5236     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
5237     VariantClear(&v);
5238
5239     hres = IHTMLStyle_put_backgroundPositionY(style, vDefault);
5240     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
5241     VariantClear(&vDefault);
5242
5243      /* borderTopWidth */
5244     hres = IHTMLStyle_get_borderTopWidth(style, &vDefault);
5245     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
5246
5247     V_VT(&v) = VT_BSTR;
5248     V_BSTR(&v) = a2bstr("10px");
5249     hres = IHTMLStyle_put_borderTopWidth(style, v);
5250     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
5251     VariantClear(&v);
5252
5253     hres = IHTMLStyle_get_borderTopWidth(style, &v);
5254     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
5255     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5256     VariantClear(&v);
5257
5258     hres = IHTMLStyle_put_borderTopWidth(style, vDefault);
5259     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
5260     VariantClear(&vDefault);
5261
5262     /* borderRightWidth */
5263     hres = IHTMLStyle_get_borderRightWidth(style, &vDefault);
5264     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
5265
5266     V_VT(&v) = VT_BSTR;
5267     V_BSTR(&v) = a2bstr("10");
5268     hres = IHTMLStyle_put_borderRightWidth(style, v);
5269     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
5270     VariantClear(&v);
5271
5272     hres = IHTMLStyle_get_borderRightWidth(style, &v);
5273     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
5274     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5275     VariantClear(&v);
5276
5277     hres = IHTMLStyle_put_borderRightWidth(style, vDefault);
5278     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
5279     VariantClear(&vDefault);
5280
5281     /* borderBottomWidth */
5282     hres = IHTMLStyle_get_borderBottomWidth(style, &vDefault);
5283     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
5284
5285     V_VT(&v) = VT_BSTR;
5286     V_BSTR(&v) = a2bstr("10");
5287     hres = IHTMLStyle_put_borderBottomWidth(style, v);
5288     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
5289     VariantClear(&v);
5290
5291     hres = IHTMLStyle_get_borderBottomWidth(style, &v);
5292     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
5293     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5294     VariantClear(&v);
5295
5296     hres = IHTMLStyle_put_borderBottomWidth(style, vDefault);
5297     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
5298     VariantClear(&vDefault);
5299
5300     /* borderLeftWidth */
5301     hres = IHTMLStyle_get_borderLeftWidth(style, &vDefault);
5302     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
5303
5304     V_VT(&v) = VT_BSTR;
5305     V_BSTR(&v) = a2bstr("10");
5306     hres = IHTMLStyle_put_borderLeftWidth(style, v);
5307     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
5308     VariantClear(&v);
5309
5310     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
5311     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
5312     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5313     VariantClear(&v);
5314
5315     hres = IHTMLStyle_put_borderLeftWidth(style, vDefault);
5316     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
5317     VariantClear(&vDefault);
5318
5319     /* wordSpacing */
5320     hres = IHTMLStyle_get_wordSpacing(style, &vDefault);
5321     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
5322
5323     V_VT(&v) = VT_BSTR;
5324     V_BSTR(&v) = a2bstr("10");
5325     hres = IHTMLStyle_put_wordSpacing(style, v);
5326     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
5327     VariantClear(&v);
5328
5329     hres = IHTMLStyle_get_wordSpacing(style, &v);
5330     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
5331     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
5332     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5333     VariantClear(&v);
5334
5335     hres = IHTMLStyle_put_wordSpacing(style, vDefault);
5336     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
5337     VariantClear(&vDefault);
5338
5339     /* letterSpacing */
5340     hres = IHTMLStyle_get_letterSpacing(style, &vDefault);
5341     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
5342
5343     V_VT(&v) = VT_BSTR;
5344     V_BSTR(&v) = a2bstr("11");
5345     hres = IHTMLStyle_put_letterSpacing(style, v);
5346     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
5347     VariantClear(&v);
5348
5349     hres = IHTMLStyle_get_letterSpacing(style, &v);
5350     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
5351     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
5352     ok(!strcmp_wa(V_BSTR(&v), "11px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5353     VariantClear(&v);
5354
5355     hres = IHTMLStyle_put_letterSpacing(style, vDefault);
5356     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
5357     VariantClear(&vDefault);
5358
5359     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
5360     ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
5361     if(SUCCEEDED(hres)) {
5362         test_style2(style2);
5363         IHTMLStyle2_Release(style2);
5364     }
5365
5366     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle3, (void**)&style3);
5367     ok(hres == S_OK, "Could not get IHTMLStyle3 iface: %08x\n", hres);
5368     if(SUCCEEDED(hres)) {
5369         test_style3(style3);
5370         IHTMLStyle3_Release(style3);
5371     }
5372
5373     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle4, (void**)&style4);
5374     ok(hres == S_OK, "Could not get IHTMLStyle4 iface: %08x\n", hres);
5375     if(SUCCEEDED(hres)) {
5376         test_style4(style4);
5377         IHTMLStyle4_Release(style4);
5378     }
5379 }
5380
5381 static void test_set_csstext(IHTMLStyle *style)
5382 {
5383     VARIANT v;
5384     HRESULT hres;
5385
5386     test_style_set_csstext(style, "background-color: black;");
5387
5388     hres = IHTMLStyle_get_backgroundColor(style, &v);
5389     ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
5390     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
5391     ok(!strcmp_wa(V_BSTR(&v), "black"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
5392     VariantClear(&v);
5393 }
5394
5395 static void test_default_selection(IHTMLDocument2 *doc)
5396 {
5397     IHTMLSelectionObject *selection;
5398     IHTMLTxtRange *range;
5399     IDispatch *disp;
5400     BSTR str;
5401     HRESULT hres;
5402
5403     hres = IHTMLDocument2_get_selection(doc, &selection);
5404     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
5405
5406     hres = IHTMLSelectionObject_get_type(selection, &str);
5407     ok(hres == S_OK, "get_type failed: %08x\n", hres);
5408     ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
5409     SysFreeString(str);
5410
5411     hres = IHTMLSelectionObject_createRange(selection, &disp);
5412     IHTMLSelectionObject_Release(selection);
5413     ok(hres == S_OK, "createRange failed: %08x\n", hres);
5414
5415     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
5416     IDispatch_Release(disp);
5417     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
5418
5419     test_range_text(range, NULL);
5420     IHTMLTxtRange_Release(range);
5421 }
5422
5423 static void test_doc_elem(IHTMLDocument2 *doc)
5424 {
5425     IHTMLDocument2 *doc_node, *owner_doc;
5426     IHTMLElement *elem;
5427     IHTMLDocument3 *doc3;
5428     HRESULT hres;
5429
5430     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5431     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
5432
5433     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
5434     IHTMLDocument3_Release(doc3);
5435     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
5436
5437     test_node_name((IUnknown*)elem, "HTML");
5438     test_elem_tag((IUnknown*)elem, "HTML");
5439
5440     doc_node = get_doc_node(doc);
5441     owner_doc = get_owner_doc((IUnknown*)elem);
5442     ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
5443     IHTMLDocument2_Release(owner_doc);
5444
5445     owner_doc = get_owner_doc((IUnknown*)doc_node);
5446     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5447     IHTMLDocument2_Release(doc_node);
5448
5449     test_elem_client_rect((IUnknown*)elem);
5450
5451     IHTMLElement_Release(elem);
5452 }
5453
5454 static void test_default_body(IHTMLBodyElement *body)
5455 {
5456     LONG l;
5457     BSTR bstr;
5458     HRESULT hres;
5459     VARIANT v;
5460
5461     bstr = (void*)0xdeadbeef;
5462     hres = IHTMLBodyElement_get_background(body, &bstr);
5463     ok(hres == S_OK, "get_background failed: %08x\n", hres);
5464     ok(bstr == NULL, "bstr != NULL\n");
5465
5466     l = elem_get_scroll_height((IUnknown*)body);
5467     ok(l != -1, "scrollHeight == -1\n");
5468     l = elem_get_scroll_width((IUnknown*)body);
5469     ok(l != -1, "scrollWidth == -1\n");
5470     l = elem_get_scroll_top((IUnknown*)body);
5471     ok(!l, "scrollTop = %d\n", l);
5472     elem_get_scroll_left((IUnknown*)body);
5473
5474     /* get_text tests */
5475     hres = IHTMLBodyElement_get_text(body, &v);
5476     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5477     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5478     ok(bstr == NULL, "bstr != NULL\n");
5479
5480     /* get_text - Invalid Text */
5481     V_VT(&v) = VT_BSTR;
5482     V_BSTR(&v) = a2bstr("Invalid");
5483     hres = IHTMLBodyElement_put_text(body, v);
5484     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5485     VariantClear(&v);
5486
5487     V_VT(&v) = VT_NULL;
5488     hres = IHTMLBodyElement_get_text(body, &v);
5489     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5490     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5491     ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
5492     VariantClear(&v);
5493
5494     /* get_text - Valid Text */
5495     V_VT(&v) = VT_BSTR;
5496     V_BSTR(&v) = a2bstr("#FF0000");
5497     hres = IHTMLBodyElement_put_text(body, v);
5498     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5499     VariantClear(&v);
5500
5501     V_VT(&v) = VT_NULL;
5502     hres = IHTMLBodyElement_get_text(body, &v);
5503     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5504     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5505     ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
5506     VariantClear(&v);
5507 }
5508
5509 static void test_body_funs(IHTMLBodyElement *body)
5510 {
5511     VARIANT vbg, vDefaultbg;
5512     HRESULT hres;
5513
5514     hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
5515     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5516     ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
5517     ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
5518
5519     V_VT(&vbg) = VT_BSTR;
5520     V_BSTR(&vbg) = a2bstr("red");
5521     hres = IHTMLBodyElement_put_bgColor(body, vbg);
5522     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5523     VariantClear(&vbg);
5524
5525     hres = IHTMLBodyElement_get_bgColor(body, &vbg);
5526     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5527     ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
5528     ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
5529     VariantClear(&vbg);
5530
5531     /* Restore Originial */
5532     hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
5533     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5534     VariantClear(&vDefaultbg);
5535 }
5536
5537 static void test_window(IHTMLDocument2 *doc)
5538 {
5539     IHTMLWindow2 *window, *window2, *self;
5540     IHTMLDocument2 *doc2 = NULL;
5541     IDispatch *disp;
5542     IUnknown *unk;
5543     BSTR str;
5544     HRESULT hres;
5545
5546     hres = IHTMLDocument2_get_parentWindow(doc, &window);
5547     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
5548     test_ifaces((IUnknown*)window, window_iids);
5549     test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
5550
5551     hres = IHTMLWindow2_get_document(window, &doc2);
5552     ok(hres == S_OK, "get_document failed: %08x\n", hres);
5553     ok(doc2 != NULL, "doc2 == NULL\n");
5554
5555     test_ifaces((IUnknown*)doc2, doc_node_iids);
5556     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
5557
5558     test_ifaces((IUnknown*)doc, doc_obj_iids);
5559     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
5560
5561     unk = (void*)0xdeadbeef;
5562     hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
5563     ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
5564     ok(!unk, "unk = %p\n", unk);
5565
5566     IHTMLDocument_Release(doc2);
5567
5568     hres = IHTMLWindow2_get_window(window, &window2);
5569     ok(hres == S_OK, "get_window failed: %08x\n", hres);
5570     ok(window2 != NULL, "window2 == NULL\n");
5571
5572     hres = IHTMLWindow2_get_self(window, &self);
5573     ok(hres == S_OK, "get_self failed: %08x\n", hres);
5574     ok(window2 != NULL, "self == NULL\n");
5575
5576     ok(self == window2, "self != window2\n");
5577
5578     IHTMLWindow2_Release(window2);
5579     IHTMLWindow2_Release(self);
5580
5581     disp = NULL;
5582     hres = IHTMLDocument2_get_Script(doc, &disp);
5583     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5584     ok(disp == (void*)window, "disp != window\n");
5585     IDispatch_Release(disp);
5586
5587     hres = IHTMLWindow2_toString(window, NULL);
5588     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
5589
5590     str = NULL;
5591     hres = IHTMLWindow2_toString(window, &str);
5592     ok(hres == S_OK, "toString failed: %08x\n", hres);
5593     ok(!strcmp_wa(str, "[object]"), "toString returned %s\n", wine_dbgstr_w(str));
5594     SysFreeString(str);
5595
5596     test_window_name(window, NULL);
5597     set_window_name(window, "test");
5598     test_window_length(window, 0);
5599     test_screen(window);
5600
5601     IHTMLWindow2_Release(window);
5602 }
5603
5604 static void test_defaults(IHTMLDocument2 *doc)
5605 {
5606     IHTMLStyleSheetsCollection *stylesheetcol;
5607     IHTMLCurrentStyle *cstyle;
5608     IHTMLBodyElement *body;
5609     IHTMLElement2 *elem2;
5610     IHTMLElement *elem;
5611     IHTMLStyle *style;
5612     LONG l;
5613     HRESULT hres;
5614     IHTMLElementCollection *collection;
5615
5616     elem = doc_get_body(doc);
5617
5618     hres = IHTMLDocument2_get_images(doc, NULL);
5619     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5620
5621     hres = IHTMLDocument2_get_images(doc, &collection);
5622     ok(hres == S_OK, "get_images failed: %08x\n", hres);
5623     if(hres == S_OK)
5624     {
5625         test_elem_collection((IUnknown*)collection, NULL, 0);
5626         IHTMLElementCollection_Release(collection);
5627     }
5628
5629     hres = IHTMLDocument2_get_applets(doc, NULL);
5630     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5631
5632     hres = IHTMLDocument2_get_applets(doc, &collection);
5633     ok(hres == S_OK, "get_applets failed: %08x\n", hres);
5634     if(hres == S_OK)
5635     {
5636         test_elem_collection((IUnknown*)collection, NULL, 0);
5637         IHTMLElementCollection_Release(collection);
5638     }
5639
5640     hres = IHTMLDocument2_get_links(doc, NULL);
5641     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5642
5643     hres = IHTMLDocument2_get_links(doc, &collection);
5644     ok(hres == S_OK, "get_links failed: %08x\n", hres);
5645     if(hres == S_OK)
5646     {
5647         test_elem_collection((IUnknown*)collection, NULL, 0);
5648         IHTMLElementCollection_Release(collection);
5649     }
5650
5651     hres = IHTMLDocument2_get_forms(doc, NULL);
5652     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5653
5654     hres = IHTMLDocument2_get_forms(doc, &collection);
5655     ok(hres == S_OK, "get_forms failed: %08x\n", hres);
5656     if(hres == S_OK)
5657     {
5658         test_elem_collection((IUnknown*)collection, NULL, 0);
5659         IHTMLElementCollection_Release(collection);
5660     }
5661
5662     hres = IHTMLDocument2_get_anchors(doc, NULL);
5663     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5664
5665     hres = IHTMLDocument2_get_anchors(doc, &collection);
5666     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
5667     if(hres == S_OK)
5668     {
5669         test_elem_collection((IUnknown*)collection, NULL, 0);
5670         IHTMLElementCollection_Release(collection);
5671     }
5672
5673     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
5674     ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
5675     test_default_body(body);
5676     test_body_funs(body);
5677     IHTMLBodyElement_Release(body);
5678
5679     hres = IHTMLElement_get_style(elem, &style);
5680     ok(hres == S_OK, "get_style failed: %08x\n", hres);
5681
5682     test_default_style(style);
5683     test_window(doc);
5684     test_compatmode(doc);
5685     test_location(doc);
5686     test_navigator(doc);
5687
5688     elem2 = get_elem2_iface((IUnknown*)elem);
5689     hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
5690     ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
5691     if(SUCCEEDED(hres)) {
5692         test_current_style(cstyle);
5693         IHTMLCurrentStyle_Release(cstyle);
5694     }
5695     IHTMLElement2_Release(elem2);
5696
5697     IHTMLElement_Release(elem);
5698
5699     test_set_csstext(style);
5700     IHTMLStyle_Release(style);
5701
5702     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
5703     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5704
5705     l = 0xdeadbeef;
5706     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
5707     ok(hres == S_OK, "get_length failed: %08x\n", hres);
5708     ok(l == 0, "length = %d\n", l);
5709
5710     IHTMLStyleSheetsCollection_Release(stylesheetcol);
5711
5712     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
5713     ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
5714
5715     test_default_selection(doc);
5716     test_doc_title(doc, "");
5717 }
5718
5719 static void test_tr_elem(IHTMLElement *elem)
5720 {
5721     IHTMLElementCollection *col;
5722     IHTMLTableRow *row;
5723     HRESULT hres;
5724
5725     static const elem_type_t cell_types[] = {ET_TD,ET_TD};
5726
5727     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
5728     ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
5729     if(FAILED(hres))
5730         return;
5731
5732     col = NULL;
5733     hres = IHTMLTableRow_get_cells(row, &col);
5734     ok(hres == S_OK, "get_cells failed: %08x\n", hres);
5735     ok(col != NULL, "get_cells returned NULL\n");
5736
5737     test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
5738     IHTMLElementCollection_Release(col);
5739
5740     IHTMLTable_Release(row);
5741 }
5742
5743 static void test_table_elem(IHTMLElement *elem)
5744 {
5745     IHTMLElementCollection *col;
5746     IHTMLTable *table;
5747     IHTMLDOMNode *node;
5748     HRESULT hres;
5749
5750     static const elem_type_t row_types[] = {ET_TR,ET_TR};
5751     static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
5752
5753     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
5754     ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
5755     if(FAILED(hres))
5756         return;
5757
5758     col = NULL;
5759     hres = IHTMLTable_get_rows(table, &col);
5760     ok(hres == S_OK, "get_rows failed: %08x\n", hres);
5761     ok(col != NULL, "get_ros returned NULL\n");
5762
5763     test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
5764     IHTMLElementCollection_Release(col);
5765
5766     test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
5767
5768     node = clone_node((IUnknown*)table, VARIANT_TRUE);
5769     test_elem_tag((IUnknown*)node, "TABLE");
5770     test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
5771     IHTMLDOMNode_Release(node);
5772
5773     node = clone_node((IUnknown*)table, VARIANT_FALSE);
5774     test_elem_tag((IUnknown*)node, "TABLE");
5775     test_elem_all((IUnknown*)node, NULL, 0);
5776     IHTMLDOMNode_Release(node);
5777
5778     IHTMLTable_Release(table);
5779 }
5780
5781 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
5782 {
5783     SAFEARRAYBOUND dim;
5784     SAFEARRAY *sa;
5785     VARIANT *var;
5786     HRESULT hres;
5787
5788     dim.lLbound = 0;
5789     dim.cElements = 1;
5790     sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
5791     SafeArrayAccessData(sa, (void**)&var);
5792     V_VT(var) = VT_BSTR;
5793     V_BSTR(var) = a2bstr(text);
5794     SafeArrayUnaccessData(sa);
5795
5796     if(ln)
5797         hres = IHTMLDocument2_writeln(doc, sa);
5798     else
5799         hres = IHTMLDocument2_write(doc, sa);
5800     ok(hres == S_OK, "write failed: %08x\n", hres);
5801
5802     SafeArrayDestroy(sa);
5803 }
5804
5805 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
5806 {
5807     IHTMLDocument2 *window_doc, *elem_doc;
5808     IHTMLFrameElement3 *frame_elem3;
5809     IHTMLWindow2 *content_window;
5810     HRESULT hres;
5811
5812     content_window = get_frame_content_window(frame_elem);
5813     window_doc = get_window_doc(content_window);
5814     IHTMLWindow2_Release(content_window);
5815
5816     elem_doc = get_elem_doc(frame_elem);
5817     ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
5818
5819     if(!iframe) {
5820         hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
5821         if(SUCCEEDED(hres)) {
5822             IDispatch *disp = NULL;
5823
5824             hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
5825             ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
5826             ok(disp != NULL, "contentDocument == NULL\n");
5827             ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
5828
5829             IDispatch_Release(disp);
5830             IHTMLFrameElement3_Release(frame_elem3);
5831         }else {
5832             win_skip("IHTMLFrameElement3 not supported\n");
5833         }
5834     }
5835
5836     IHTMLDocument2_Release(elem_doc);
5837     IHTMLDocument2_Release(window_doc);
5838 }
5839
5840 static void test_iframe_elem(IHTMLElement *elem)
5841 {
5842     IHTMLDocument2 *content_doc, *owner_doc;
5843     IHTMLElementCollection *col;
5844     IHTMLWindow2 *content_window;
5845     IDispatch *disp;
5846     VARIANT errv;
5847     BSTR str;
5848     HRESULT hres;
5849
5850     static const elem_type_t all_types[] = {
5851         ET_HTML,
5852         ET_HEAD,
5853         ET_TITLE,
5854         ET_BODY,
5855         ET_BR
5856     };
5857
5858     test_frame_doc((IUnknown*)elem, TRUE);
5859
5860     content_window = get_frame_content_window((IUnknown*)elem);
5861     test_window_length(content_window, 0);
5862
5863     content_doc = get_window_doc(content_window);
5864     IHTMLWindow2_Release(content_window);
5865
5866     str = a2bstr("text/html");
5867     V_VT(&errv) = VT_ERROR;
5868     disp = NULL;
5869     hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
5870     SysFreeString(str);
5871     ok(hres == S_OK, "open failed: %08x\n", hres);
5872     ok(disp != NULL, "disp == NULL\n");
5873     ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
5874     IDispatch_Release(disp);
5875
5876     doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
5877     doc_write(content_doc, TRUE, "</html>");
5878
5879     hres = IHTMLDocument2_get_all(content_doc, &col);
5880     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5881     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5882     IHTMLElementCollection_Release(col);
5883
5884     hres = IHTMLDocument2_close(content_doc);
5885     ok(hres == S_OK, "close failed: %08x\n", hres);
5886
5887     owner_doc = get_owner_doc((IUnknown*)content_doc);
5888     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5889
5890     IHTMLDocument2_Release(content_doc);
5891 }
5892
5893 static void test_stylesheet(IDispatch *disp)
5894 {
5895     IHTMLStyleSheetRulesCollection *col = NULL;
5896     IHTMLStyleSheet *stylesheet;
5897     HRESULT hres;
5898
5899     hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
5900     ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
5901
5902     hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
5903     ok(hres == S_OK, "get_rules failed: %08x\n", hres);
5904     ok(col != NULL, "col == NULL\n");
5905
5906     IHTMLStyleSheetRulesCollection_Release(col);
5907     IHTMLStyleSheet_Release(stylesheet);
5908 }
5909
5910 static void test_stylesheets(IHTMLDocument2 *doc)
5911 {
5912     IHTMLStyleSheetsCollection *col = NULL;
5913     VARIANT idx, res;
5914     LONG len = 0;
5915     HRESULT hres;
5916
5917     hres = IHTMLDocument2_get_styleSheets(doc, &col);
5918     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5919     ok(col != NULL, "col == NULL\n");
5920
5921     test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
5922
5923     hres = IHTMLStyleSheetsCollection_get_length(col, &len);
5924     ok(hres == S_OK, "get_length failed: %08x\n", hres);
5925     ok(len == 1, "len=%d\n", len);
5926
5927     VariantInit(&res);
5928     V_VT(&idx) = VT_I4;
5929     V_I4(&idx) = 0;
5930
5931     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5932     ok(hres == S_OK, "item failed: %08x\n", hres);
5933     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
5934     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5935     test_stylesheet(V_DISPATCH(&res));
5936     VariantClear(&res);
5937
5938     V_VT(&res) = VT_I4;
5939     V_VT(&idx) = VT_I4;
5940     V_I4(&idx) = 1;
5941
5942     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5943     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5944     ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
5945     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5946     VariantClear(&res);
5947
5948     IHTMLStyleSheetsCollection_Release(col);
5949 }
5950
5951 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
5952 {
5953     IDispatchEx *dispex;
5954     IHTMLDOMNode *node;
5955     DISPPARAMS dp = {NULL, NULL, 0, 0};
5956     VARIANT var;
5957     EXCEPINFO ei;
5958     LONG type;
5959     DISPID id;
5960     BSTR bstr;
5961     HRESULT hres;
5962
5963     static const WCHAR w0[] = {'0',0};
5964     static const WCHAR w100[] = {'1','0','0',0};
5965
5966     hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
5967     ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
5968
5969     bstr = SysAllocString(w0);
5970     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5971     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5972     SysFreeString(bstr);
5973
5974     VariantInit(&var);
5975     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
5976     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
5977     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
5978     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
5979     node = get_node_iface((IUnknown*)V_DISPATCH(&var));
5980     type = get_node_type((IUnknown*)node);
5981     ok(type == 3, "type=%d\n", type);
5982     IHTMLDOMNode_Release(node);
5983     VariantClear(&var);
5984
5985     bstr = SysAllocString(w100);
5986     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5987     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
5988     SysFreeString(bstr);
5989
5990     IDispatchEx_Release(dispex);
5991 }
5992
5993
5994
5995 static void test_elems(IHTMLDocument2 *doc)
5996 {
5997     IHTMLElementCollection *col;
5998     IHTMLDOMChildrenCollection *child_col;
5999     IHTMLElement *elem, *elem2, *elem3;
6000     IHTMLDOMNode *node, *node2;
6001     IHTMLWindow2 *window;
6002     IDispatch *disp;
6003     LONG type;
6004     HRESULT hres;
6005     IHTMLElementCollection *collection;
6006     IHTMLDocument3 *doc3;
6007     BSTR str;
6008
6009     static const elem_type_t all_types[] = {
6010         ET_HTML,
6011         ET_HEAD,
6012         ET_TITLE,
6013         ET_STYLE,
6014         ET_BODY,
6015         ET_COMMENT,
6016         ET_A,
6017         ET_INPUT,
6018         ET_SELECT,
6019         ET_OPTION,
6020         ET_OPTION,
6021         ET_TEXTAREA,
6022         ET_TABLE,
6023         ET_TBODY,
6024         ET_TR,
6025         ET_TR,
6026         ET_TD,
6027         ET_TD,
6028         ET_SCRIPT,
6029         ET_TEST,
6030         ET_OBJECT,
6031         ET_EMBED,
6032         ET_IMG,
6033         ET_IFRAME,
6034         ET_FORM
6035     };
6036
6037     static const elem_type_t item_types[] = {
6038         ET_A,
6039         ET_OPTION,
6040         ET_TEXTAREA
6041     };
6042
6043     hres = IHTMLDocument2_get_all(doc, &col);
6044     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6045     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6046     test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
6047     IHTMLElementCollection_Release(col);
6048
6049     hres = IHTMLDocument2_get_images(doc, &collection);
6050     ok(hres == S_OK, "get_images failed: %08x\n", hres);
6051     if(hres == S_OK)
6052     {
6053         static const elem_type_t images_types[] = {ET_IMG};
6054         test_elem_collection((IUnknown*)collection, images_types, 1);
6055
6056         IHTMLElementCollection_Release(collection);
6057     }
6058
6059     hres = IHTMLDocument2_get_links(doc, &collection);
6060     ok(hres == S_OK, "get_links failed: %08x\n", hres);
6061     if(hres == S_OK)
6062     {
6063         static const elem_type_t images_types[] = {ET_A};
6064         test_elem_collection((IUnknown*)collection, images_types, 1);
6065
6066         IHTMLElementCollection_Release(collection);
6067     }
6068
6069     hres = IHTMLDocument2_get_anchors(doc, &collection);
6070     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
6071     if(hres == S_OK)
6072     {
6073         static const elem_type_t anchor_types[] = {ET_A};
6074         test_elem_collection((IUnknown*)collection, anchor_types, 1);
6075
6076         IHTMLElementCollection_Release(collection);
6077     }
6078
6079     elem = get_doc_elem(doc);
6080     test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
6081     IHTMLElement_Release(elem);
6082
6083     get_elem_by_id(doc, "xxx", FALSE);
6084     elem = get_doc_elem_by_id(doc, "xxx");
6085     ok(!elem, "elem != NULL\n");
6086
6087     elem = get_doc_elem_by_id(doc, "s");
6088     ok(elem != NULL, "elem == NULL\n");
6089     if(elem) {
6090         test_elem_type((IUnknown*)elem, ET_SELECT);
6091         test_elem_attr(elem, "xxx", NULL);
6092         test_elem_attr(elem, "id", "s");
6093         test_elem_class((IUnknown*)elem, NULL);
6094         test_elem_set_class((IUnknown*)elem, "cl");
6095         test_elem_set_class((IUnknown*)elem, NULL);
6096         test_elem_tabindex((IUnknown*)elem, 0);
6097         test_elem_set_tabindex((IUnknown*)elem, 1);
6098         test_elem_filters((IUnknown*)elem);
6099
6100         node = test_node_get_parent((IUnknown*)elem);
6101         ok(node != NULL, "node == NULL\n");
6102         test_node_name((IUnknown*)node, "BODY");
6103         node2 = test_node_get_parent((IUnknown*)node);
6104         IHTMLDOMNode_Release(node);
6105         ok(node2 != NULL, "node == NULL\n");
6106         test_node_name((IUnknown*)node2, "HTML");
6107         node = test_node_get_parent((IUnknown*)node2);
6108         IHTMLDOMNode_Release(node2);
6109         ok(node != NULL, "node == NULL\n");
6110         if (node)
6111         {
6112             test_node_name((IUnknown*)node, "#document");
6113             type = get_node_type((IUnknown*)node);
6114             ok(type == 9, "type=%d, expected 9\n", type);
6115             node2 = test_node_get_parent((IUnknown*)node);
6116             IHTMLDOMNode_Release(node);
6117             ok(node2 == NULL, "node != NULL\n");
6118         }
6119
6120         elem2 = test_elem_get_parent((IUnknown*)elem);
6121         ok(elem2 != NULL, "elem2 == NULL\n");
6122         test_node_name((IUnknown*)elem2, "BODY");
6123         elem3 = test_elem_get_parent((IUnknown*)elem2);
6124         IHTMLElement_Release(elem2);
6125         ok(elem3 != NULL, "elem3 == NULL\n");
6126         test_node_name((IUnknown*)elem3, "HTML");
6127         elem2 = test_elem_get_parent((IUnknown*)elem3);
6128         IHTMLElement_Release(elem3);
6129         ok(elem2 == NULL, "elem2 != NULL\n");
6130
6131         test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
6132         test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
6133         test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
6134
6135         test_elem_innertext(elem, "opt1opt2");
6136
6137         IHTMLElement_Release(elem);
6138     }
6139
6140     elem = get_elem_by_id(doc, "s", TRUE);
6141     if(elem) {
6142         IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
6143         IHTMLDocument2 *doc_node, *elem_doc;
6144
6145         test_select_elem(select);
6146
6147         test_elem_title((IUnknown*)select, NULL);
6148         test_elem_set_title((IUnknown*)select, "Title");
6149         test_elem_title((IUnknown*)select, "Title");
6150         test_elem_offset((IUnknown*)select);
6151         test_elem_bounding_client_rect((IUnknown*)select);
6152
6153         node = get_first_child((IUnknown*)select);
6154         ok(node != NULL, "node == NULL\n");
6155         if(node) {
6156             test_elem_type((IUnknown*)node, ET_OPTION);
6157             IHTMLDOMNode_Release(node);
6158         }
6159
6160         type = get_node_type((IUnknown*)select);
6161         ok(type == 1, "type=%d\n", type);
6162
6163         IHTMLSelectElement_Release(select);
6164
6165         elem_doc = get_elem_doc((IUnknown*)elem);
6166
6167         doc_node = get_doc_node(doc);
6168         ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
6169         IHTMLDocument2_Release(doc_node);
6170         IHTMLDocument2_Release(elem_doc);
6171
6172         IHTMLElement_Release(elem);
6173     }
6174
6175     elem = get_elem_by_id(doc, "sc", TRUE);
6176     if(elem) {
6177         IHTMLScriptElement *script;
6178         BSTR type;
6179
6180         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
6181         ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
6182
6183         if(hres == S_OK)
6184         {
6185             VARIANT_BOOL vb;
6186
6187             hres = IHTMLScriptElement_put_type (script, NULL);
6188             ok(hres == S_OK, "put_type failed: %08x\n", hres);
6189             hres = IHTMLScriptElement_get_type(script, &type);
6190             ok(hres == S_OK, "get_type failed: %08x\n", hres);
6191             ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
6192
6193             hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
6194             ok(hres == S_OK, "put_type failed: %08x\n", hres);
6195             hres = IHTMLScriptElement_get_type(script, &type);
6196             ok(hres == S_OK, "get_type failed: %08x\n", hres);
6197             ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
6198
6199             SysFreeString(type);
6200
6201             /* test defer */
6202             hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
6203             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
6204
6205             hres = IHTMLScriptElement_get_defer(script, &vb);
6206             ok(hres == S_OK, "get_defer failed: %08x\n", hres);
6207             ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
6208
6209             hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
6210             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
6211         }
6212
6213         IHTMLScriptElement_Release(script);
6214     }
6215
6216     elem = get_elem_by_id(doc, "in", TRUE);
6217     if(elem) {
6218         IHTMLInputElement *input;
6219
6220         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
6221         ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
6222
6223         test_elem_id((IUnknown*)elem, "in");
6224         test_elem_put_id((IUnknown*)elem, "newin");
6225         test_input_get_disabled(input, VARIANT_FALSE);
6226         test_input_set_disabled(input, VARIANT_TRUE);
6227         test_input_set_disabled(input, VARIANT_FALSE);
6228         test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
6229         test_input_get_disabled(input, VARIANT_TRUE);
6230         test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
6231         test_input_get_disabled(input, VARIANT_FALSE);
6232         test_elem_client_size((IUnknown*)elem);
6233         test_input_type(input, "text");
6234
6235         test_node_get_value_str((IUnknown*)elem, NULL);
6236         test_node_put_value_str((IUnknown*)elem, "test");
6237         test_node_get_value_str((IUnknown*)elem, NULL);
6238         test_input_value((IUnknown*)elem, NULL);
6239         test_input_put_value((IUnknown*)elem, "test");
6240         test_input_value((IUnknown*)elem, NULL);
6241         test_elem_class((IUnknown*)elem, "testclass");
6242         test_elem_tabindex((IUnknown*)elem, 2);
6243         test_elem_set_tabindex((IUnknown*)elem, 3);
6244         test_elem_title((IUnknown*)elem, "test title");
6245
6246         test_input_get_defaultchecked(input, VARIANT_FALSE);
6247         test_input_set_defaultchecked(input, VARIANT_TRUE);
6248         test_input_set_defaultchecked(input, VARIANT_FALSE);
6249
6250         test_input_get_checked(input, VARIANT_FALSE);
6251         test_input_set_checked(input, VARIANT_TRUE);
6252         test_input_set_checked(input, VARIANT_FALSE);
6253
6254         test_input_name(input, NULL);
6255         test_input_set_name(input, "test");
6256
6257         test_input_src(input, NULL);
6258         test_input_set_src(input, "about:blank");
6259
6260         IHTMLInputElement_Release(input);
6261         IHTMLElement_Release(elem);
6262     }
6263
6264     elem = get_elem_by_id(doc, "imgid", TRUE);
6265     if(elem) {
6266         test_img_src((IUnknown*)elem, "");
6267         test_img_set_src((IUnknown*)elem, "about:blank");
6268         test_img_alt((IUnknown*)elem, NULL);
6269         test_img_set_alt((IUnknown*)elem, "alt test");
6270         test_img_name((IUnknown*)elem, "WineImg");
6271         IHTMLElement_Release(elem);
6272     }
6273
6274     elem = get_doc_elem_by_id(doc, "tbl");
6275     ok(elem != NULL, "elem == NULL\n");
6276     if(elem) {
6277         test_table_elem(elem);
6278         IHTMLElement_Release(elem);
6279     }
6280
6281     elem = get_doc_elem_by_id(doc, "row2");
6282     ok(elem != NULL, "elem == NULL\n");
6283     if(elem) {
6284         test_tr_elem(elem);
6285         IHTMLElement_Release(elem);
6286     }
6287
6288     elem = get_doc_elem_by_id(doc, "ifr");
6289     ok(elem != NULL, "elem == NULL\n");
6290     if(elem) {
6291         test_iframe_elem(elem);
6292         IHTMLElement_Release(elem);
6293     }
6294
6295     elem = get_doc_elem_by_id(doc, "objid");
6296     ok(elem != NULL, "elem == NULL\n");
6297     if(elem) {
6298         test_object_vspace((IUnknown*)elem, 100);
6299         IHTMLElement_Release(elem);
6300     }
6301
6302     elem = get_elem_by_id(doc, "a", TRUE);
6303     if(elem) {
6304         test_anchor_href((IUnknown*)elem, "http://test/");
6305         IHTMLElement_Release(elem);
6306     }
6307
6308     elem = doc_get_body(doc);
6309
6310     node = get_first_child((IUnknown*)elem);
6311     ok(node != NULL, "node == NULL\n");
6312     if(node) {
6313         test_ifaces((IUnknown*)node, text_iids);
6314         test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
6315
6316         node2 = get_first_child((IUnknown*)node);
6317         ok(!node2, "node2 != NULL\n");
6318
6319         type = get_node_type((IUnknown*)node);
6320         ok(type == 3, "type=%d\n", type);
6321
6322         test_node_get_value_str((IUnknown*)node, "text test");
6323         test_node_put_value_str((IUnknown*)elem, "test text");
6324         test_node_get_value_str((IUnknown*)node, "text test");
6325
6326         IHTMLDOMNode_Release(node);
6327     }
6328
6329     child_col = get_child_nodes((IUnknown*)elem);
6330     ok(child_col != NULL, "child_coll == NULL\n");
6331     if(child_col) {
6332         LONG length = 0;
6333
6334         test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
6335
6336         hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
6337         ok(hres == S_OK, "get_length failed: %08x\n", hres);
6338         ok(length, "length=0\n");
6339
6340         node2 = NULL;
6341         node = get_child_item(child_col, 0);
6342         ok(node != NULL, "node == NULL\n");
6343         if(node) {
6344             type = get_node_type((IUnknown*)node);
6345             ok(type == 3, "type=%d\n", type);
6346             node2 = node_get_next((IUnknown*)node);
6347             IHTMLDOMNode_Release(node);
6348         }
6349
6350         node = get_child_item(child_col, 1);
6351         ok(node != NULL, "node == NULL\n");
6352         if(node) {
6353             type = get_node_type((IUnknown*)node);
6354             ok(type == 8, "type=%d\n", type);
6355
6356             test_elem_id((IUnknown*)node, NULL);
6357             ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
6358             IHTMLDOMNode_Release(node2);
6359             IHTMLDOMNode_Release(node);
6360         }
6361
6362         hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
6363         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
6364
6365         hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
6366         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
6367
6368         hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
6369         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
6370
6371         hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
6372         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
6373
6374         test_child_col_disp(child_col);
6375
6376         IHTMLDOMChildrenCollection_Release(child_col);
6377     }
6378
6379     test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
6380     test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
6381     test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
6382
6383     IHTMLElement_Release(elem);
6384
6385     elem = get_doc_elem_by_id(doc, "frm");
6386     ok(elem != NULL, "elem == NULL\n");
6387     if(elem) {
6388         test_form_length((IUnknown*)elem, 0);
6389         IHTMLElement_Release(elem);
6390     }
6391
6392     test_stylesheets(doc);
6393     test_create_option_elem(doc);
6394     test_create_img_elem(doc);
6395
6396     elem = get_doc_elem_by_id(doc, "tbl");
6397     ok(elem != NULL, "elem = NULL\n");
6398     test_elem_set_innertext(elem, "inner text");
6399     IHTMLElement_Release(elem);
6400
6401     test_doc_title(doc, "test");
6402     test_doc_set_title(doc, "test title");
6403     test_doc_title(doc, "test title");
6404
6405     disp = NULL;
6406     hres = IHTMLDocument2_get_Script(doc, &disp);
6407     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
6408     if(hres == S_OK)
6409     {
6410         IDispatchEx *dispex;
6411         hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
6412         ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
6413         if(hres == S_OK)
6414         {
6415             DISPID pid = -1;
6416             BSTR str = a2bstr("Testing");
6417             hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
6418             ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
6419             ok(pid != -1, "pid == -1\n");
6420             SysFreeString(str);
6421             IDispatchEx_Release(dispex);
6422         }
6423     }
6424     IDispatch_Release(disp);
6425
6426     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
6427     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
6428
6429     str = a2bstr("img");
6430     hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
6431     ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
6432     SysFreeString(str);
6433     if(hres == S_OK)
6434     {
6435         static const elem_type_t img_types[] = { ET_IMG };
6436
6437         test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
6438         IHTMLElementCollection_Release(col);
6439     }
6440
6441     elem = get_doc_elem_by_id(doc, "y");
6442     test_elem_set_innerhtml((IUnknown*)elem, "inner html");
6443     test_elem_innerhtml((IUnknown*)elem, "inner html");
6444     test_elem_set_innerhtml((IUnknown*)elem, "");
6445     test_elem_innerhtml((IUnknown*)elem, NULL);
6446     node = node_get_next((IUnknown*)elem);
6447     ok(!node, "node = %p\n", node);
6448
6449     elem2 = get_doc_elem_by_id(doc, "x");
6450     test_elem_tag((IUnknown*)elem2, "A");
6451     node = node_get_next((IUnknown*)elem2);
6452     IHTMLDOMNode_Release(node);
6453     IHTMLElement_Release(elem2);
6454     IHTMLElement_Release(elem);
6455
6456     IHTMLDocument3_Release(doc3);
6457
6458     elem = get_elem_by_id(doc, "s", TRUE);
6459     if(elem) {
6460         static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
6461
6462         test_select_put_length((IUnknown*)elem, 3);
6463         test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
6464         test_select_put_length((IUnknown*)elem, 1);
6465         test_elem_all((IUnknown*)elem, select_types, 1);
6466         IHTMLElement_Release(elem);
6467     }
6468
6469     window = get_doc_window(doc);
6470     test_window_name(window, NULL);
6471     set_window_name(window, "test name");
6472     test_window_length(window, 1);
6473     IHTMLWindow2_Release(window);
6474 }
6475
6476 static void test_elems2(IHTMLDocument2 *doc)
6477 {
6478     IHTMLElement *elem, *elem2, *div;
6479
6480     static const elem_type_t outer_types[] = {
6481         ET_BR,
6482         ET_A
6483     };
6484
6485     div = get_doc_elem_by_id(doc, "divid");
6486
6487     test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
6488     elem2 = get_doc_elem_by_id(doc, "innerid");
6489     ok(elem2 != NULL, "elem2 == NULL\n");
6490     test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
6491     test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
6492     IHTMLElement_Release(elem2);
6493
6494     elem2 = get_doc_elem_by_id(doc, "aid");
6495     ok(elem2 != NULL, "elem2 == NULL\n");
6496     test_elem_set_outerhtml((IUnknown*)elem2, "");
6497     test_elem_all((IUnknown*)div, outer_types, 1);
6498     IHTMLElement_Release(elem2);
6499
6500     test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
6501     elem = get_elem_by_id(doc, "ta", TRUE);
6502     if(elem) {
6503         test_textarea_value((IUnknown*)elem, NULL);
6504         test_textarea_put_value((IUnknown*)elem, "test");
6505         test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
6506         test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
6507         test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
6508         test_textarea_type((IUnknown*)elem);
6509         IHTMLElement_Release(elem);
6510     }
6511
6512     test_elem_set_innerhtml((IUnknown*)div,
6513             "<form id=\"form\"><input type=\"button\"></input><input type=\"text\"></input></textarea>");
6514     elem = get_elem_by_id(doc, "form", TRUE);
6515     if(elem) {
6516         test_form_length((IUnknown*)elem, 2);
6517         test_form_item(elem);
6518         test_form_action((IUnknown*)elem, NULL);
6519         test_form_put_action((IUnknown*)elem, "about:blank");
6520         test_form_method((IUnknown*)elem, "get");
6521         test_form_put_method((IUnknown*)elem, S_OK, "post");
6522         test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
6523         test_form_method((IUnknown*)elem, "post");
6524         test_form_name((IUnknown*)elem, NULL);
6525         test_form_put_name((IUnknown*)elem, "Name");
6526         test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
6527         test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
6528         test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
6529         test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
6530         test_form_encoding((IUnknown*)elem, "multipart/form-data");
6531         IHTMLElement_Release(elem);
6532     }
6533
6534     IHTMLElement_Release(div);
6535 }
6536
6537 static void test_create_elems(IHTMLDocument2 *doc)
6538 {
6539     IHTMLElement *elem, *body, *elem2;
6540     IHTMLDOMNode *node, *node2, *node3, *comment;
6541     IHTMLDocument5 *doc5;
6542     IDispatch *disp;
6543     VARIANT var;
6544     LONG type;
6545     HRESULT hres;
6546     BSTR str;
6547
6548     static const elem_type_t types1[] = { ET_TESTG };
6549
6550     elem = test_create_elem(doc, "TEST");
6551     test_elem_tag((IUnknown*)elem, "TEST");
6552     type = get_node_type((IUnknown*)elem);
6553     ok(type == 1, "type=%d\n", type);
6554     test_ifaces((IUnknown*)elem, elem_iids);
6555     test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
6556
6557     body = doc_get_body(doc);
6558     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
6559
6560     node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
6561     test_node_has_child((IUnknown*)body, VARIANT_TRUE);
6562     elem2 = get_elem_iface((IUnknown*)node);
6563     IHTMLElement_Release(elem2);
6564
6565     hres = IHTMLElement_get_all(body, &disp);
6566     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6567     test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
6568     IDispatch_Release(disp);
6569
6570     test_node_remove_child((IUnknown*)body, node);
6571
6572     hres = IHTMLElement_get_all(body, &disp);
6573     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6574     test_elem_collection((IUnknown*)disp, NULL, 0);
6575     IDispatch_Release(disp);
6576     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
6577
6578     IHTMLElement_Release(elem);
6579     IHTMLDOMNode_Release(node);
6580
6581     node = test_create_text(doc, "test");
6582     test_ifaces((IUnknown*)node, text_iids);
6583     test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
6584     test_text_length((IUnknown*)node, 4);
6585
6586     V_VT(&var) = VT_NULL;
6587     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
6588     IHTMLDOMNode_Release(node);
6589
6590     node = test_create_text(doc, "insert ");
6591
6592     V_VT(&var) = VT_DISPATCH;
6593     V_DISPATCH(&var) = (IDispatch*)node2;
6594     node3 = test_node_insertbefore((IUnknown*)body, node, &var);
6595     IHTMLDOMNode_Release(node);
6596     IHTMLDOMNode_Release(node2);
6597     IHTMLDOMNode_Release(node3);
6598
6599     test_elem_innertext(body, "insert test");
6600     test_elem_innerhtml((IUnknown*)body, "insert test");
6601
6602     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
6603     if(hres == S_OK)
6604     {
6605         str = a2bstr("testing");
6606         hres = IHTMLDocument5_createComment(doc5, str, &comment);
6607         SysFreeString(str);
6608         ok(hres == S_OK, "createComment failed: %08x\n", hres);
6609         if(hres == S_OK)
6610         {
6611             type = get_node_type((IUnknown*)comment);
6612             ok(type == 8, "type=%d, expected 8\n", type);
6613
6614             test_node_get_value_str((IUnknown*)comment, "testing");
6615             test_elem_title((IUnknown*)comment, NULL);
6616             test_elem_set_title((IUnknown*)comment, "comment title");
6617             test_elem_title((IUnknown*)comment, "comment title");
6618             test_comment_text((IUnknown*)comment, "<!--testing-->");
6619             test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
6620
6621             IHTMLDOMNode_Release(comment);
6622         }
6623
6624         IHTMLDocument5_Release(doc5);
6625     }
6626
6627     IHTMLElement_Release(body);
6628 }
6629
6630 static void test_null_write(IHTMLDocument2 *doc)
6631 {
6632     HRESULT hres;
6633
6634     doc_write(doc, FALSE, NULL);
6635     doc_write(doc, TRUE, NULL);
6636
6637     hres = IHTMLDocument2_write(doc, NULL);
6638     ok(hres == S_OK,
6639        "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
6640
6641     hres = IHTMLDocument2_writeln(doc, NULL);
6642     ok(hres == S_OK,
6643        "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
6644 }
6645
6646 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
6647 {
6648     IOleCommandTarget *cmdtrg;
6649     HRESULT hres;
6650
6651     hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
6652     ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
6653
6654     hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
6655     ok(hres == S_OK, "Exec failed: %08x\n", hres);
6656
6657     IOleCommandTarget_Release(cmdtrg);
6658 }
6659
6660 static void test_indent(IHTMLDocument2 *doc)
6661 {
6662     IHTMLElementCollection *col;
6663     IHTMLTxtRange *range;
6664     HRESULT hres;
6665
6666     static const elem_type_t all_types[] = {
6667         ET_HTML,
6668         ET_HEAD,
6669         ET_TITLE,
6670         ET_BODY,
6671         ET_BR,
6672         ET_A,
6673     };
6674
6675     static const elem_type_t indent_types[] = {
6676         ET_HTML,
6677         ET_HEAD,
6678         ET_TITLE,
6679         ET_BODY,
6680         ET_BLOCKQUOTE,
6681         ET_P,
6682         ET_BR,
6683         ET_A,
6684     };
6685
6686     hres = IHTMLDocument2_get_all(doc, &col);
6687     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6688     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6689     IHTMLElementCollection_Release(col);
6690
6691     range = test_create_body_range(doc);
6692     test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
6693     IHTMLTxtRange_Release(range);
6694
6695     hres = IHTMLDocument2_get_all(doc, &col);
6696     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6697     test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
6698     IHTMLElementCollection_Release(col);
6699 }
6700
6701 static void test_cond_comment(IHTMLDocument2 *doc)
6702 {
6703     IHTMLElementCollection *col;
6704     HRESULT hres;
6705
6706     static const elem_type_t all_types[] = {
6707         ET_HTML,
6708         ET_HEAD,
6709         ET_TITLE,
6710         ET_BODY,
6711         ET_BR
6712     };
6713
6714     hres = IHTMLDocument2_get_all(doc, &col);
6715     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6716     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6717     IHTMLElementCollection_Release(col);
6718 }
6719
6720 static void test_frame(IDispatch *disp, const char *exp_id)
6721 {
6722     IHTMLWindow2 *frame2, *parent, *top;
6723     IHTMLDocument2 *parent_doc, *top_doc;
6724     IHTMLWindow4 *frame;
6725     IHTMLFrameBase *frame_elem;
6726     HRESULT hres;
6727
6728     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
6729     ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
6730     if(FAILED(hres))
6731         return;
6732
6733     hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
6734     ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
6735     IHTMLWindow4_Release(frame);
6736     if(FAILED(hres))
6737         return;
6738
6739     test_elem_type((IUnknown*)frame_elem, ET_FRAME);
6740     test_frame_doc((IUnknown*)frame_elem, FALSE);
6741     test_elem_id((IUnknown*)frame_elem, exp_id);
6742     IHTMLElement_Release(frame_elem);
6743
6744     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
6745     ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
6746     if(FAILED(hres))
6747         return;
6748
6749     hres = IHTMLWindow2_get_parent(frame2, &parent);
6750     ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
6751     if(FAILED(hres)){
6752         IHTMLWindow2_Release(frame2);
6753         return;
6754     }
6755
6756     hres = IHTMLWindow2_get_document(parent, &parent_doc);
6757     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
6758     IHTMLWindow2_Release(parent);
6759     if(FAILED(hres)){
6760         IHTMLWindow2_Release(frame2);
6761         return;
6762     }
6763
6764     test_doc_title(parent_doc, "frameset test");
6765     IHTMLDocument2_Release(parent_doc);
6766
6767     /* test get_top */
6768     hres = IHTMLWindow2_get_top(frame2, &top);
6769     ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
6770     IHTMLWindow2_Release(frame2);
6771     if(FAILED(hres))
6772         return;
6773
6774     hres = IHTMLWindow2_get_document(top, &top_doc);
6775     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
6776     IHTMLWindow2_Release(top);
6777     if(FAILED(hres))
6778         return;
6779
6780     test_doc_title(top_doc, "frameset test");
6781     IHTMLDocument2_Release(top_doc);
6782 }
6783
6784 static void test_frameset(IHTMLDocument2 *doc)
6785 {
6786     IHTMLWindow2 *window;
6787     IHTMLFramesCollection2 *frames;
6788     IHTMLElement *elem;
6789     IHTMLFrameBase *fbase;
6790     LONG length;
6791     VARIANT index_var, result_var;
6792     BSTR str;
6793     HRESULT hres;
6794
6795     window = get_doc_window(doc);
6796
6797     /* test using IHTMLFramesCollection object */
6798
6799     hres = IHTMLWindow2_get_frames(window, &frames);
6800     ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
6801     IHTMLWindow2_Release(window);
6802     if(FAILED(hres))
6803         return;
6804
6805     /* test result length */
6806     hres = IHTMLFramesCollection2_get_length(frames, &length);
6807     ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
6808     ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
6809
6810     /* test first frame */
6811     V_VT(&index_var) = VT_I4;
6812     V_I4(&index_var) = 0;
6813     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6814     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6815     if(SUCCEEDED(hres)) {
6816         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6817         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
6818     }
6819     VariantClear(&result_var);
6820
6821     /* test second frame */
6822     V_I4(&index_var) = 1;
6823     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6824     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6825     if(SUCCEEDED(hres)) {
6826         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6827         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6828     }
6829     VariantClear(&result_var);
6830
6831     /* fail on next frame */
6832     V_I4(&index_var) = 3;
6833     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6834     ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
6835            "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
6836     VariantClear(&result_var);
6837
6838     /* string argument (element id lookup) */
6839     V_VT(&index_var) = VT_BSTR;
6840     V_BSTR(&index_var) = a2bstr("fr1");
6841     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6842     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6843     if(SUCCEEDED(hres)) {
6844         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6845         test_frame(V_DISPATCH(&result_var), "fr1");
6846     }
6847     VariantClear(&result_var);
6848     VariantClear(&index_var);
6849
6850     /* invalid argument */
6851     V_VT(&index_var) = VT_BOOL;
6852     V_BOOL(&index_var) = VARIANT_TRUE;
6853     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6854     ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
6855            "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
6856     VariantClear(&result_var);
6857
6858     IHTMLFramesCollection2_Release(frames);
6859
6860     /* test using IHTMLWindow2 inheritance */
6861
6862     /* test result length */
6863     hres = IHTMLWindow2_get_length(window, &length);
6864     ok(hres == S_OK, "IHTMLWindow2_get_length failed: 0x%08x\n", hres);
6865     ok(length == 3, "IHTMLWindow2_get_length should have been 3, was: %d\n", length);
6866
6867     /* test first frame */
6868     V_VT(&index_var) = VT_I4;
6869     V_I4(&index_var) = 0;
6870     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6871     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6872     if(SUCCEEDED(hres)) {
6873         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6874         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
6875     }
6876     VariantClear(&result_var);
6877
6878     /* test second frame */
6879     V_I4(&index_var) = 1;
6880     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6881     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6882     if(SUCCEEDED(hres)) {
6883         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6884         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6885     }
6886     VariantClear(&result_var);
6887
6888     /* fail on next frame */
6889     V_I4(&index_var) = 3;
6890     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6891     ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLWindow2_item should have"
6892            "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
6893     VariantClear(&result_var);
6894
6895     /* string argument (element id lookup) */
6896     V_VT(&index_var) = VT_BSTR;
6897     V_BSTR(&index_var) = a2bstr("fr2");
6898     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6899     ok(hres == S_OK, "IHTMLWindow2_item failed: 0x%08x\n", hres);
6900     if(SUCCEEDED(hres)) {
6901         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6902         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6903     }
6904     VariantClear(&result_var);
6905     VariantClear(&index_var);
6906
6907     /* invalid argument */
6908     V_VT(&index_var) = VT_BOOL;
6909     V_BOOL(&index_var) = VARIANT_TRUE;
6910     hres = IHTMLWindow2_item(window, &index_var, &result_var);
6911     ok(hres == E_INVALIDARG, "IHTMLWindow2_item should have"
6912            "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
6913     VariantClear(&result_var);
6914
6915     /* getElementById with node name attributes */
6916     elem = get_doc_elem_by_id(doc, "nm1");
6917     test_elem_id((IUnknown*)elem, "fr1");
6918
6919     /* get/put scrolling */
6920     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6921     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6922
6923     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6924     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6925     ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
6926     SysFreeString(str);
6927
6928     str = a2bstr("no");
6929     hres = IHTMLFrameBase_put_scrolling(fbase, str);
6930     ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
6931     SysFreeString(str);
6932
6933     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6934     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6935     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6936     SysFreeString(str);
6937
6938     str = a2bstr("junk");
6939     hres = IHTMLFrameBase_put_scrolling(fbase, str);
6940     ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
6941             "with E_INVALIDARG, instead: 0x%08x\n", hres);
6942     SysFreeString(str);
6943
6944     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6945     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6946     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6947     SysFreeString(str);
6948
6949     /* get_name */
6950     hres = IHTMLFrameBase_get_name(fbase, &str);
6951     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
6952     ok(!strcmp_wa(str, "nm1"), "get_name should have given 'nm1', gave: %s\n", wine_dbgstr_w(str));
6953     SysFreeString(str);
6954
6955     IHTMLFrameBase_Release(fbase);
6956     IHTMLElement_Release(elem);
6957
6958     /* get_name with no name attr */
6959     elem = get_doc_elem_by_id(doc, "fr3");
6960     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6961     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6962
6963     hres = IHTMLFrameBase_get_name(fbase, &str);
6964     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
6965     ok(str == NULL, "get_name should have given 'null', gave: %s\n", wine_dbgstr_w(str));
6966     SysFreeString(str);
6967
6968     IHTMLFrameBase_Release(fbase);
6969     IHTMLElement_Release(elem);
6970 }
6971
6972 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
6973 {
6974     IHTMLDocument2 *frag;
6975     IHTMLDocument3 *doc3;
6976     HRESULT hres;
6977
6978     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
6979     ok(hres == S_OK, "Coult not get IHTMLDocument3 iface: %08x\n", hres);
6980
6981     hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
6982     IHTMLDocument3_Release(doc3);
6983     ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
6984     ok(frag != NULL, "frag == NULL\n");
6985
6986     return frag;
6987 }
6988
6989 static void test_docfrag(IHTMLDocument2 *doc)
6990 {
6991     IHTMLElement *div, *body, *br;
6992     IHTMLElementCollection *col;
6993     IHTMLLocation *location;
6994     IHTMLDocument2 *frag;
6995     HRESULT hres;
6996
6997     static const elem_type_t all_types[] = {
6998         ET_HTML,
6999         ET_HEAD,
7000         ET_TITLE,
7001         ET_BODY,
7002         ET_DIV,
7003         ET_BR
7004     };
7005
7006     frag = create_docfrag(doc);
7007
7008     test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
7009
7010     body = (void*)0xdeadbeef;
7011     hres = IHTMLDocument2_get_body(frag, &body);
7012     ok(hres == S_OK, "get_body failed: %08x\n", hres);
7013     ok(!body, "body != NULL\n");
7014
7015     location = (void*)0xdeadbeef;
7016     hres = IHTMLDocument2_get_location(frag, &location);
7017     ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
7018     ok(location == (void*)0xdeadbeef, "location changed\n");
7019
7020     br = test_create_elem(doc, "BR");
7021     test_node_append_child((IUnknown*)frag, (IUnknown*)br);
7022     IHTMLElement_Release(br);
7023
7024     div = get_elem_by_id(doc, "divid", TRUE);
7025     test_node_append_child((IUnknown*)div, (IUnknown*)frag);
7026     IHTMLElement_Release(div);
7027
7028     hres = IHTMLDocument2_get_all(doc, &col);
7029     ok(hres == S_OK, "get_all failed: %08x\n", hres);
7030     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7031     IHTMLElementCollection_Release(col);
7032
7033     IHTMLDocument2_Release(frag);
7034 }
7035
7036 static IHTMLDocument2 *notif_doc;
7037 static BOOL doc_complete;
7038
7039 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
7040         REFIID riid, void**ppv)
7041 {
7042     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
7043         *ppv = iface;
7044         return S_OK;
7045     }
7046
7047     ok(0, "unexpected call\n");
7048     return E_NOINTERFACE;
7049 }
7050
7051 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
7052 {
7053     return 2;
7054 }
7055
7056 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
7057 {
7058     return 1;
7059 }
7060
7061 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
7062 {
7063     if(dispID == DISPID_READYSTATE){
7064         BSTR state;
7065         HRESULT hres;
7066
7067         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
7068         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
7069
7070         if(!strcmp_wa(state, "complete"))
7071             doc_complete = TRUE;
7072
7073         SysFreeString(state);
7074     }
7075
7076     return S_OK;
7077 }
7078
7079 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
7080 {
7081     ok(0, "unexpected call\n");
7082     return E_NOTIMPL;
7083 }
7084
7085 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
7086     PropertyNotifySink_QueryInterface,
7087     PropertyNotifySink_AddRef,
7088     PropertyNotifySink_Release,
7089     PropertyNotifySink_OnChanged,
7090     PropertyNotifySink_OnRequestEdit
7091 };
7092
7093 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
7094
7095 static IHTMLDocument2 *create_doc_with_string(const char *str)
7096 {
7097     IPersistStreamInit *init;
7098     IStream *stream;
7099     IHTMLDocument2 *doc;
7100     HGLOBAL mem;
7101     SIZE_T len;
7102
7103     notif_doc = doc = create_document();
7104     if(!doc)
7105         return NULL;
7106
7107     doc_complete = FALSE;
7108     len = strlen(str);
7109     mem = GlobalAlloc(0, len);
7110     memcpy(mem, str, len);
7111     CreateStreamOnHGlobal(mem, TRUE, &stream);
7112
7113     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
7114
7115     IPersistStreamInit_Load(init, stream);
7116     IPersistStreamInit_Release(init);
7117     IStream_Release(stream);
7118
7119     return doc;
7120 }
7121
7122 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
7123 {
7124     IConnectionPointContainer *container;
7125     IConnectionPoint *cp;
7126     DWORD cookie;
7127     HRESULT hres;
7128
7129     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
7130     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
7131
7132     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
7133     IConnectionPointContainer_Release(container);
7134     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
7135
7136     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
7137     IConnectionPoint_Release(cp);
7138     ok(hres == S_OK, "Advise failed: %08x\n", hres);
7139 }
7140
7141 typedef void (*domtest_t)(IHTMLDocument2*);
7142
7143 static void run_domtest(const char *str, domtest_t test)
7144 {
7145     IHTMLDocument2 *doc;
7146     ULONG ref;
7147     MSG msg;
7148
7149     doc = create_doc_with_string(str);
7150     if(!doc)
7151         return;
7152
7153     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
7154
7155     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
7156         TranslateMessage(&msg);
7157         DispatchMessage(&msg);
7158     }
7159
7160     test(doc);
7161
7162     ref = IHTMLDocument2_Release(doc);
7163     ok(!ref || broken(ref == 1), /* Vista */
7164        "ref = %d\n", ref);
7165 }
7166
7167 START_TEST(dom)
7168 {
7169     CoInitialize(NULL);
7170
7171     run_domtest(doc_str1, test_doc_elem);
7172     run_domtest(doc_str1, test_get_set_attr);
7173     run_domtest(range_test_str, test_txtrange);
7174     run_domtest(range_test2_str, test_txtrange2);
7175     if (winetest_interactive || ! is_ie_hardened()) {
7176         run_domtest(elem_test_str, test_elems);
7177     }else {
7178         skip("IE running in Enhanced Security Configuration\n");
7179     }
7180     run_domtest(elem_test2_str, test_elems2);
7181     run_domtest(doc_blank, test_create_elems);
7182     run_domtest(doc_blank, test_defaults);
7183     run_domtest(doc_blank, test_null_write);
7184     run_domtest(indent_test_str, test_indent);
7185     run_domtest(cond_comment_str, test_cond_comment);
7186     run_domtest(frameset_str, test_frameset);
7187     run_domtest(emptydiv_str, test_docfrag);
7188
7189     CoUninitialize();
7190 }