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