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