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