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