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