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