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