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