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