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