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