fltlib: Add a stub dll.
[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 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\"/>"
53     "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
54     "</body></html>";
55 static const char indent_test_str[] =
56     "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
57 static const char cond_comment_str[] =
58     "<html><head><title>test</title></head><body>"
59     "<!--[if gte IE 4]> <br> <![endif]-->"
60     "</body></html>";
61
62 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
63 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
64 static WCHAR wordW[] = {'w','o','r','d',0};
65
66 typedef enum {
67     ET_NONE,
68     ET_HTML,
69     ET_HEAD,
70     ET_TITLE,
71     ET_BODY,
72     ET_A,
73     ET_INPUT,
74     ET_SELECT,
75     ET_TEXTAREA,
76     ET_OPTION,
77     ET_STYLE,
78     ET_BLOCKQUOTE,
79     ET_P,
80     ET_BR,
81     ET_TABLE,
82     ET_TBODY,
83     ET_SCRIPT,
84     ET_TEST,
85     ET_TESTG,
86     ET_COMMENT,
87     ET_IMG,
88     ET_TR,
89     ET_TD,
90     ET_IFRAME
91 } elem_type_t;
92
93 static const IID * const none_iids[] = {
94     &IID_IUnknown,
95     NULL
96 };
97
98 static const IID * const doc_node_iids[] = {
99     &IID_IHTMLDOMNode,
100     &IID_IHTMLDOMNode2,
101     &IID_IHTMLDocument,
102     &IID_IHTMLDocument2,
103     &IID_IHTMLDocument3,
104     &IID_IHTMLDocument4,
105     &IID_IHTMLDocument5,
106     &IID_IDispatchEx,
107     &IID_IConnectionPointContainer,
108     &IID_IInternetHostSecurityManager,
109     NULL
110 };
111
112 static const IID * const doc_obj_iids[] = {
113     &IID_IHTMLDocument,
114     &IID_IHTMLDocument2,
115     &IID_IHTMLDocument3,
116     &IID_IHTMLDocument4,
117     &IID_IHTMLDocument5,
118     &IID_IDispatchEx,
119     &IID_IConnectionPointContainer,
120     &IID_ICustomDoc,
121     NULL
122 };
123
124 static const IID * const elem_iids[] = {
125     &IID_IHTMLDOMNode,
126     &IID_IHTMLDOMNode2,
127     &IID_IHTMLElement,
128     &IID_IHTMLElement2,
129     &IID_IHTMLElement3,
130     &IID_IDispatchEx,
131     &IID_IConnectionPointContainer,
132     NULL
133 };
134
135 static const IID * const body_iids[] = {
136     &IID_IHTMLDOMNode,
137     &IID_IHTMLDOMNode2,
138     &IID_IHTMLElement,
139     &IID_IHTMLElement2,
140     &IID_IHTMLElement3,
141     &IID_IHTMLTextContainer,
142     &IID_IHTMLBodyElement,
143     &IID_IDispatchEx,
144     &IID_IConnectionPointContainer,
145     NULL
146 };
147
148 static const IID * const anchor_iids[] = {
149     &IID_IHTMLDOMNode,
150     &IID_IHTMLDOMNode2,
151     &IID_IHTMLElement,
152     &IID_IHTMLElement2,
153     &IID_IHTMLElement3,
154     &IID_IHTMLAnchorElement,
155     &IID_IDispatchEx,
156     &IID_IConnectionPointContainer,
157     NULL
158 };
159
160 static const IID * const input_iids[] = {
161     &IID_IHTMLDOMNode,
162     &IID_IHTMLDOMNode2,
163     &IID_IHTMLElement,
164     &IID_IHTMLElement2,
165     &IID_IHTMLElement3,
166     &IID_IHTMLInputElement,
167     &IID_IHTMLInputTextElement,
168     &IID_IDispatchEx,
169     &IID_IConnectionPointContainer,
170     NULL
171 };
172
173 static const IID * const select_iids[] = {
174     &IID_IHTMLDOMNode,
175     &IID_IHTMLDOMNode2,
176     &IID_IHTMLElement,
177     &IID_IHTMLElement2,
178     &IID_IHTMLElement3,
179     &IID_IHTMLSelectElement,
180     &IID_IDispatchEx,
181     &IID_IConnectionPointContainer,
182     NULL
183 };
184
185 static const IID * const textarea_iids[] = {
186     &IID_IHTMLDOMNode,
187     &IID_IHTMLDOMNode2,
188     &IID_IHTMLElement,
189     &IID_IHTMLElement2,
190     &IID_IHTMLElement3,
191     &IID_IHTMLTextAreaElement,
192     &IID_IDispatchEx,
193     &IID_IConnectionPointContainer,
194     NULL
195 };
196
197 static const IID * const option_iids[] = {
198     &IID_IHTMLDOMNode,
199     &IID_IHTMLDOMNode2,
200     &IID_IHTMLElement,
201     &IID_IHTMLElement2,
202     &IID_IHTMLElement3,
203     &IID_IHTMLOptionElement,
204     &IID_IDispatchEx,
205     &IID_IConnectionPointContainer,
206     NULL
207 };
208
209 static const IID * const table_iids[] = {
210     &IID_IHTMLDOMNode,
211     &IID_IHTMLDOMNode2,
212     &IID_IHTMLElement,
213     &IID_IHTMLElement2,
214     &IID_IHTMLElement3,
215     &IID_IHTMLTable,
216     &IID_IDispatchEx,
217     &IID_IConnectionPointContainer,
218     NULL
219 };
220
221 static const IID * const script_iids[] = {
222     &IID_IHTMLDOMNode,
223     &IID_IHTMLDOMNode2,
224     &IID_IHTMLElement,
225     &IID_IHTMLElement2,
226     &IID_IHTMLElement3,
227     &IID_IHTMLScriptElement,
228     &IID_IDispatchEx,
229     &IID_IConnectionPointContainer,
230     NULL
231 };
232
233 static const IID * const text_iids[] = {
234     &IID_IHTMLDOMNode,
235     &IID_IHTMLDOMNode2,
236     &IID_IHTMLDOMTextNode,
237     NULL
238 };
239
240 static const IID * const location_iids[] = {
241     &IID_IDispatch,
242     &IID_IHTMLLocation,
243     NULL
244 };
245
246 static const IID * const window_iids[] = {
247     &IID_IDispatch,
248     &IID_IHTMLWindow2,
249     &IID_IHTMLWindow3,
250     &IID_IDispatchEx,
251     NULL
252 };
253
254 static const IID * const comment_iids[] = {
255     &IID_IHTMLDOMNode,
256     &IID_IHTMLDOMNode2,
257     &IID_IHTMLElement,
258     &IID_IHTMLElement2,
259     &IID_IHTMLElement3,
260     &IID_IHTMLCommentElement,
261     &IID_IDispatchEx,
262     &IID_IConnectionPointContainer,
263     NULL
264 };
265
266 static const IID * const img_iids[] = {
267     &IID_IHTMLDOMNode,
268     &IID_IHTMLDOMNode2,
269     &IID_IHTMLElement,
270     &IID_IHTMLElement2,
271     &IID_IHTMLElement3,
272     &IID_IDispatchEx,
273     &IID_IHTMLImgElement,
274     &IID_IConnectionPointContainer,
275     NULL
276 };
277
278 static const IID * const tr_iids[] = {
279     &IID_IHTMLDOMNode,
280     &IID_IHTMLDOMNode2,
281     &IID_IHTMLElement,
282     &IID_IHTMLElement2,
283     &IID_IHTMLElement3,
284     &IID_IDispatchEx,
285     &IID_IHTMLTableRow,
286     &IID_IConnectionPointContainer,
287     NULL
288 };
289
290 static const IID * const td_iids[] = {
291     &IID_IHTMLDOMNode,
292     &IID_IHTMLDOMNode2,
293     &IID_IHTMLElement,
294     &IID_IHTMLElement2,
295     &IID_IHTMLElement3,
296     &IID_IDispatchEx,
297     &IID_IConnectionPointContainer,
298     NULL
299 };
300
301 static const IID * const iframe_iids[] = {
302     &IID_IHTMLDOMNode,
303     &IID_IHTMLDOMNode2,
304     &IID_IHTMLElement,
305     &IID_IHTMLElement2,
306     &IID_IHTMLElement3,
307     &IID_IHTMLFrameBase2,
308     &IID_IDispatchEx,
309     &IID_IConnectionPointContainer,
310     NULL
311 };
312
313 static const IID * const generic_iids[] = {
314     &IID_IHTMLDOMNode,
315     &IID_IHTMLDOMNode2,
316     &IID_IHTMLElement,
317     &IID_IHTMLElement2,
318     &IID_IHTMLElement3,
319     &IID_IHTMLGenericElement,
320     &IID_IDispatchEx,
321     &IID_IConnectionPointContainer,
322     NULL
323 };
324
325 static const IID * const style_iids[] = {
326     &IID_IUnknown,
327     &IID_IDispatch,
328     &IID_IDispatchEx,
329     &IID_IHTMLStyle,
330     &IID_IHTMLStyle2,
331     &IID_IHTMLStyle3,
332     &IID_IHTMLStyle4,
333     NULL
334 };
335
336 static const IID * const cstyle_iids[] = {
337     &IID_IUnknown,
338     &IID_IDispatch,
339     &IID_IDispatchEx,
340     &IID_IHTMLCurrentStyle,
341     NULL
342 };
343
344 typedef struct {
345     const char *tag;
346     REFIID *iids;
347     const IID *dispiid;
348 } elem_type_info_t;
349
350 static const elem_type_info_t elem_type_infos[] = {
351     {"",          none_iids,        NULL},
352     {"HTML",      elem_iids,        NULL},
353     {"HEAD",      elem_iids,        NULL},
354     {"TITLE",     elem_iids,        NULL},
355     {"BODY",      body_iids,        &DIID_DispHTMLBody},
356     {"A",         anchor_iids,      NULL},
357     {"INPUT",     input_iids,       &DIID_DispHTMLInputElement},
358     {"SELECT",    select_iids,      &DIID_DispHTMLSelectElement},
359     {"TEXTAREA",  textarea_iids,    NULL},
360     {"OPTION",    option_iids,      &DIID_DispHTMLOptionElement},
361     {"STYLE",     elem_iids,        NULL},
362     {"BLOCKQUOTE",elem_iids,        NULL},
363     {"P",         elem_iids,        NULL},
364     {"BR",        elem_iids,        NULL},
365     {"TABLE",     table_iids,       &DIID_DispHTMLTable},
366     {"TBODY",     elem_iids,        NULL},
367     {"SCRIPT",    script_iids,      NULL},
368     {"TEST",      elem_iids,        &DIID_DispHTMLUnknownElement},
369     {"TEST",      generic_iids,     &DIID_DispHTMLGenericElement},
370     {"!",         comment_iids,     &DIID_DispHTMLCommentElement},
371     {"IMG",       img_iids,         &DIID_DispHTMLImg},
372     {"TR",        tr_iids,          &DIID_DispHTMLTableRow},
373     {"TD",        td_iids,          NULL},
374     {"IFRAME",    iframe_iids,      &DIID_DispHTMLIFrame}
375 };
376
377 static const char *dbgstr_guid(REFIID riid)
378 {
379     static char buf[50];
380
381     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
382             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
383             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
384             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
385
386     return buf;
387 }
388
389 static int strcmp_wa(LPCWSTR strw, const char *stra)
390 {
391     CHAR buf[512];
392     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
393     return lstrcmpA(stra, buf);
394 }
395
396 static BSTR a2bstr(const char *str)
397 {
398     BSTR ret;
399     int len;
400
401     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
402     ret = SysAllocStringLen(NULL, len);
403     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
404
405     return ret;
406 }
407
408 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
409 {
410     IUnknown *unk1, *unk2;
411
412     if(iface1 == iface2)
413         return TRUE;
414
415     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
416     IUnknown_Release(unk1);
417     IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
418     IUnknown_Release(unk2);
419
420     return unk1 == unk2;
421 }
422
423 static IHTMLDocument2 *create_document(void)
424 {
425     IHTMLDocument2 *doc;
426     IHTMLDocument5 *doc5;
427     HRESULT hres;
428
429     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
430             &IID_IHTMLDocument2, (void**)&doc);
431     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
432
433     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
434     if(FAILED(hres)) {
435         win_skip("Could not get IHTMLDocument5, probably too old IE\n");
436         IHTMLDocument2_Release(doc);
437         return NULL;
438     }
439
440     IHTMLDocument5_Release(doc5);
441     return doc;
442 }
443
444 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
445 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
446 {
447     const IID * const *piid;
448     IUnknown *unk;
449     HRESULT hres;
450
451      for(piid = iids; *piid; piid++) {
452         hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
453         ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
454         if(SUCCEEDED(hres))
455             IUnknown_Release(unk);
456     }
457 }
458
459 #define test_get_dispid(u,id) _test_disp(__LINE__,u,id)
460 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
461 {
462     IDispatchEx *dispex;
463     ITypeInfo *typeinfo;
464     BOOL ret = FALSE;
465     UINT ticnt;
466     HRESULT hres;
467
468     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
469     ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
470     if(FAILED(hres))
471         return FALSE;
472
473     ticnt = 0xdeadbeef;
474     hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
475     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
476     ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
477
478     hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
479     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
480
481     if(SUCCEEDED(hres)) {
482         TYPEATTR *type_attr;
483
484         hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
485         ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
486         if(hres == S_OK) {
487             *iid = type_attr->guid;
488             ret = TRUE;
489         }
490
491         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
492         ITypeInfo_Release(typeinfo);
493     }
494
495     IDispatchEx_Release(dispex);
496     return ret;
497 }
498
499 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
500 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
501 {
502     DISPPARAMS dp  = {NULL,NULL,0,0};
503     IDispatchEx *dispex;
504     EXCEPINFO ei;
505     VARIANT var;
506     HRESULT hres;
507
508     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
509     ok_(__FILE__,line)(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
510     if(FAILED(hres))
511         return;
512
513     hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
514     IDispatchEx_Release(dispex);
515     ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
516
517     ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
518     ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
519     VariantClear(&var);
520 }
521
522 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
523 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
524 {
525     IID iid;
526
527     if(_test_get_dispid(line, unk, &iid))
528         ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
529
530     _test_disp_value(line, unk, val);
531 }
532
533 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
534 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
535 {
536     IID iid;
537
538     if(_test_get_dispid(line, unk, &iid))
539         ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
540                 "unexpected guid %s\n", dbgstr_guid(&iid));
541
542     _test_disp_value(line, unk, val);
543 }
544
545 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
546 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
547 {
548     IHTMLElement *elem;
549     HRESULT hres;
550
551     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
552     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
553     return elem;
554 }
555
556 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
557 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
558 {
559     IHTMLElement2 *elem;
560     HRESULT hres;
561
562     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
563     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
564     return elem;
565 }
566
567 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
568 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
569 {
570     IHTMLElement3 *elem;
571     HRESULT hres;
572
573     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
574     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
575     return elem;
576 }
577
578 #define get_node_iface(u) _get_node_iface(__LINE__,u)
579 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
580 {
581     IHTMLDOMNode *node;
582     HRESULT hres;
583
584     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
585     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
586     return node;
587 }
588
589 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
590 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
591 {
592     IHTMLDOMNode2 *node;
593     HRESULT hres;
594
595     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
596     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
597     return node;
598 }
599
600 #define get_img_iface(u) _get_img_iface(__LINE__,u)
601 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
602 {
603     IHTMLImgElement *img;
604     HRESULT hres;
605
606     hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
607     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
608     return img;
609 }
610
611 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
612 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
613 {
614     IHTMLDOMNode *node = _get_node_iface(line, unk);
615     BSTR name;
616     HRESULT hres;
617
618     hres = IHTMLDOMNode_get_nodeName(node, &name);
619     IHTMLDOMNode_Release(node);
620     ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
621     ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
622
623     SysFreeString(name);
624 }
625
626 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
627 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
628 {
629     IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
630     IDispatch *disp = (void*)0xdeadbeef;
631     IHTMLDocument2 *doc;
632     HRESULT hres;
633
634     hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
635     IHTMLDOMNode2_Release(node);
636     ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
637     ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
638
639     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
640     IDispatch_Release(disp);
641     ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
642
643     return doc;
644 }
645
646 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
647 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
648 {
649     IHTMLElement *elem = _get_elem_iface(line, unk);
650     BSTR tag;
651     HRESULT hres;
652
653     hres = IHTMLElement_get_tagName(elem, &tag);
654     IHTMLElement_Release(elem);
655     ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
656     ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
657
658     SysFreeString(tag);
659 }
660
661 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
662 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
663 {
664     _test_elem_tag(line, unk, elem_type_infos[type].tag);
665     _test_ifaces(line, unk, elem_type_infos[type].iids);
666
667     if(elem_type_infos[type].dispiid)
668         _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
669 }
670
671 #define get_node_type(n) _get_node_type(__LINE__,n)
672 static LONG _get_node_type(unsigned line, IUnknown *unk)
673 {
674     IHTMLDOMNode *node = _get_node_iface(line, unk);
675     LONG type = -1;
676     HRESULT hres;
677
678     hres = IHTMLDOMNode_get_nodeType(node, &type);
679     ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
680
681     IHTMLDOMNode_Release(node);
682
683     return type;
684 }
685
686 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
687 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
688 {
689     IHTMLDOMNode *node = _get_node_iface(line, unk);
690     IHTMLDOMChildrenCollection *col = NULL;
691     IDispatch *disp;
692     HRESULT hres;
693
694     hres = IHTMLDOMNode_get_childNodes(node, &disp);
695     IHTMLDOMNode_Release(node);
696     ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
697     if(FAILED(hres))
698         return NULL;
699
700     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
701     IDispatch_Release(disp);
702     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
703
704     return col;
705 }
706
707 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
708 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
709 {
710     IHTMLDOMNode *node = NULL;
711     IDispatch *disp;
712     HRESULT hres;
713
714     hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
715     ok(hres == S_OK, "item failed: %08x\n", hres);
716
717     node = _get_node_iface(line, (IUnknown*)disp);
718     IDispatch_Release(disp);
719
720     return node;
721 }
722
723 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
724 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
725 {
726     VARIANT value;
727     BSTR tmp;
728     HRESULT hres;
729
730     VariantInit(&value);
731
732     tmp = a2bstr(name);
733     hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
734     SysFreeString(tmp);
735     ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
736
737     if(exval) {
738         ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
739         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
740     }else {
741         ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
742     }
743
744     VariantClear(&value);
745 }
746
747 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
748 static void _test_elem_offset(unsigned line, IUnknown *unk)
749 {
750     IHTMLElement *elem = _get_elem_iface(line, unk);
751     LONG l;
752     HRESULT hres;
753
754     hres = IHTMLElement_get_offsetTop(elem, &l);
755     ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
756
757     hres = IHTMLElement_get_offsetHeight(elem, &l);
758     ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
759
760     hres = IHTMLElement_get_offsetWidth(elem, &l);
761     ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
762
763     IHTMLElement_Release(elem);
764 }
765
766 #define get_doc_node(d) _get_doc_node(__LINE__,d)
767 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
768 {
769     IHTMLWindow2 *window;
770     IHTMLDocument2 *ret;
771     HRESULT hres;
772
773     hres = IHTMLDocument2_get_parentWindow(doc, &window);
774     ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
775
776     hres = IHTMLWindow2_get_document(window, &ret);
777     ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
778     ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
779
780     return ret;
781 }
782
783 static void test_doc_elem(IHTMLDocument2 *doc)
784 {
785     IHTMLDocument2 *doc_node, *owner_doc;
786     IHTMLElement *elem;
787     IHTMLDocument3 *doc3;
788     HRESULT hres;
789
790     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
791     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
792
793     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
794     IHTMLDocument3_Release(doc3);
795     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
796
797     test_node_name((IUnknown*)elem, "HTML");
798     test_elem_tag((IUnknown*)elem, "HTML");
799
800     doc_node = get_doc_node(doc);
801     owner_doc = get_owner_doc((IUnknown*)elem);
802     ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
803     IHTMLDocument2_Release(doc_node);
804     IHTMLDocument2_Release(owner_doc);
805
806     IHTMLElement_Release(elem);
807 }
808
809 static void test_get_set_attr(IHTMLDocument2 *doc)
810 {
811     IHTMLElement *elem;
812     IHTMLDocument3 *doc3;
813     HRESULT hres;
814     BSTR bstr;
815     VARIANT val;
816
817     /* grab an element to test with */
818     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
819     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
820
821     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
822     IHTMLDocument3_Release(doc3);
823     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
824
825     /* get a non-present attribute */
826     bstr = a2bstr("notAnAttribute");
827     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
828     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
829     ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
830     VariantClear(&val);
831     SysFreeString(bstr);
832
833     /* get a present attribute */
834     bstr = a2bstr("scrollHeight");
835     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
836     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
837     ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
838     VariantClear(&val);
839     SysFreeString(bstr);
840
841     /* create a new BSTR attribute */
842     bstr = a2bstr("newAttribute");
843
844     V_VT(&val) = VT_BSTR;
845     V_BSTR(&val) = a2bstr("the value");
846     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
847     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
848     VariantClear(&val);
849
850     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
851     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
852     ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
853     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)));
854     VariantClear(&val);
855
856     /* overwrite the attribute with a BOOL */
857     V_VT(&val) = VT_BOOL;
858     V_BOOL(&val) = VARIANT_TRUE;
859     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
860     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
861     VariantClear(&val);
862
863     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
864     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
865     ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
866     ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
867     VariantClear(&val);
868
869     SysFreeString(bstr);
870
871     /* case-insensitive */
872     bstr = a2bstr("newattribute");
873     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
874     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
875     todo_wine ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
876     todo_wine ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
877     VariantClear(&val);
878     SysFreeString(bstr);
879
880     IHTMLElement_Release(elem);
881 }
882
883 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
884 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
885 {
886     IHTMLElement *elem;
887     IHTMLDocument3 *doc3;
888     HRESULT hres;
889
890     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
891     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
892     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
893     ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
894     IHTMLDocument3_Release(doc3);
895
896     return elem;
897 }
898
899 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
900 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
901 {
902     BSTR bstr;
903     HRESULT hres;
904
905     hres = IHTMLOptionElement_get_text(option, &bstr);
906     ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
907     ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
908     SysFreeString(bstr);
909 }
910
911 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
912 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
913 {
914     BSTR bstr;
915     HRESULT hres;
916
917     bstr = a2bstr(text);
918     hres = IHTMLOptionElement_put_text(option, bstr);
919     SysFreeString(bstr);
920     ok(hres == S_OK, "put_text failed: %08x\n", hres);
921
922     _test_option_text(line, option, text);
923 }
924
925 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
926 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
927 {
928     BSTR bstr;
929     HRESULT hres;
930
931     hres = IHTMLOptionElement_get_value(option, &bstr);
932     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
933     ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
934     SysFreeString(bstr);
935 }
936
937 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
938 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
939 {
940     BSTR bstr;
941     HRESULT hres;
942
943     bstr = a2bstr(value);
944     hres = IHTMLOptionElement_put_value(option, bstr);
945     SysFreeString(bstr);
946     ok(hres == S_OK, "put_value failed: %08x\n", hres);
947
948     _test_option_value(line, option, value);
949 }
950
951 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
952 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
953         const char *txt, const char *val)
954 {
955     IHTMLOptionElementFactory *factory;
956     IHTMLOptionElement *option;
957     IHTMLWindow2 *window;
958     VARIANT text, value, empty;
959     HRESULT hres;
960
961     hres = IHTMLDocument2_get_parentWindow(doc, &window);
962     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
963
964     hres = IHTMLWindow2_get_Option(window, &factory);
965     IHTMLWindow2_Release(window);
966     ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
967
968     V_VT(&text) = VT_BSTR;
969     V_BSTR(&text) = a2bstr(txt);
970     V_VT(&value) = VT_BSTR;
971     V_BSTR(&value) = a2bstr(val);
972     V_VT(&empty) = VT_EMPTY;
973
974     hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
975     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
976
977     IHTMLOptionElementFactory_Release(factory);
978     VariantClear(&text);
979     VariantClear(&value);
980
981     _test_option_text(line, option, txt);
982     _test_option_value(line, option, val);
983
984     return option;
985 }
986
987 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
988 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
989 {
990     LONG len = 0xdeadbeef;
991     HRESULT hres;
992
993     hres = IHTMLSelectElement_get_length(select, &len);
994     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
995     ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
996 }
997
998 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
999 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1000 {
1001     LONG idx = 0xdeadbeef;
1002     HRESULT hres;
1003
1004     hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1005     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1006     ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1007 }
1008
1009 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1010 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1011 {
1012     HRESULT hres;
1013
1014     hres = IHTMLSelectElement_put_selectedIndex(select, index);
1015     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1016     _test_select_selidx(line, select, index);
1017 }
1018
1019 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1020 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1021 {
1022     BSTR val;
1023     HRESULT hres;
1024
1025     hres = IHTMLSelectElement_get_value(select, &val);
1026     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1027     if(exval)
1028         ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1029     else
1030         ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1031 }
1032
1033 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1034 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1035 {
1036     BSTR bstr;
1037     HRESULT hres;
1038
1039     bstr = a2bstr(val);
1040     hres = IHTMLSelectElement_put_value(select, bstr);
1041     SysFreeString(bstr);
1042     ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1043 }
1044
1045 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1046 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1047 {
1048     BSTR type;
1049     HRESULT hres;
1050
1051     hres = IHTMLSelectElement_get_type(select, &type);
1052     ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1053     ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1054 }
1055
1056 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1057 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1058 {
1059     BSTR text;
1060     HRESULT hres;
1061
1062     hres = IHTMLTxtRange_get_text(range, &text);
1063     ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1064
1065     if(extext) {
1066         ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1067         ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1068     }else {
1069         ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1070     }
1071
1072     SysFreeString(text);
1073
1074 }
1075
1076 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1077 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1078 {
1079     HRESULT hres;
1080
1081     hres = IHTMLTxtRange_collapse(range, b);
1082     ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1083     _test_range_text(line, range, NULL);
1084 }
1085
1086 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1087 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1088         VARIANT_BOOL exb, const char *extext)
1089 {
1090     VARIANT_BOOL b = 0xe0e0;
1091     HRESULT hres;
1092
1093     hres = IHTMLTxtRange_expand(range, unit, &b);
1094     ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1095     ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1096     _test_range_text(line, range, extext);
1097 }
1098
1099 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1100 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1101 {
1102     LONG c = 0xdeadbeef;
1103     HRESULT hres;
1104
1105     hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1106     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1107     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1108     _test_range_text(line, range, NULL);
1109 }
1110
1111 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1112 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1113         LPWSTR unit, LONG cnt, LONG excnt)
1114 {
1115     LONG c = 0xdeadbeef;
1116     HRESULT hres;
1117
1118     hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1119     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1120     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1121 }
1122
1123 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1124 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1125 {
1126     LONG c = 0xdeadbeef;
1127     HRESULT hres;
1128
1129     hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1130     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1131     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1132 }
1133
1134 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1135 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1136 {
1137     HRESULT hres;
1138     BSTR bstr = a2bstr(text);
1139
1140     hres = IHTMLTxtRange_put_text(range, bstr);
1141     ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1142     SysFreeString(bstr);
1143     _test_range_text(line, range, NULL);
1144 }
1145
1146 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1147 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1148 {
1149     VARIANT_BOOL b;
1150     HRESULT hres;
1151
1152     b = 0xe0e0;
1153     hres = IHTMLTxtRange_inRange(range1, range2, &b);
1154     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1155     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1156 }
1157
1158 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1159 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1160 {
1161     VARIANT_BOOL b;
1162     HRESULT hres;
1163
1164     b = 0xe0e0;
1165     hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1166     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1167     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1168
1169     b = 0xe0e0;
1170     hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1171     ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1172     ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1173
1174     if(exb) {
1175         test_range_inrange(range1, range2, VARIANT_TRUE);
1176         test_range_inrange(range2, range1, VARIANT_TRUE);
1177     }
1178 }
1179
1180 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1181 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1182 {
1183     IHTMLElement *elem;
1184     HRESULT hres;
1185
1186     hres = IHTMLTxtRange_parentElement(range, &elem);
1187     ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1188
1189     _test_elem_type(line, (IUnknown*)elem, type);
1190
1191     IHTMLElement_Release(elem);
1192 }
1193
1194 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1195 static void _test_elem_collection(unsigned line, IUnknown *unk,
1196         const elem_type_t *elem_types, LONG exlen)
1197 {
1198     IHTMLElementCollection *col;
1199     LONG len;
1200     DWORD i;
1201     VARIANT name, index;
1202     IDispatch *disp, *disp2;
1203     HRESULT hres;
1204
1205     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1206     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1207
1208     test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1209
1210     hres = IHTMLElementCollection_get_length(col, &len);
1211     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1212     ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1213
1214     if(len > exlen)
1215         len = exlen;
1216
1217     V_VT(&index) = VT_EMPTY;
1218
1219     for(i=0; i<len; i++) {
1220         V_VT(&name) = VT_I4;
1221         V_I4(&name) = i;
1222         disp = (void*)0xdeadbeef;
1223         hres = IHTMLElementCollection_item(col, name, index, &disp);
1224         ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1225         ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1226         if(FAILED(hres) || !disp)
1227             continue;
1228
1229         _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1230
1231         if(!i) {
1232             V_VT(&name) = VT_UINT;
1233             V_I4(&name) = 0;
1234             disp2 = (void*)0xdeadbeef;
1235             hres = IHTMLElementCollection_item(col, name, index, &disp2);
1236             ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1237             ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1238             if(disp2)
1239                 IDispatch_Release(disp2);
1240         }
1241
1242         IDispatch_Release(disp);
1243     }
1244
1245     V_VT(&name) = VT_I4;
1246     V_I4(&name) = len;
1247     disp = (void*)0xdeadbeef;
1248     hres = IHTMLElementCollection_item(col, name, index, &disp);
1249     ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1250     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1251
1252     V_VT(&name) = VT_I4;
1253     V_I4(&name) = -1;
1254     disp = (void*)0xdeadbeef;
1255     hres = IHTMLElementCollection_item(col, name, index, &disp);
1256     ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1257     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1258
1259     IHTMLElementCollection_Release(col);
1260 }
1261
1262 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1263 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1264 {
1265     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1266     IHTMLElementCollection *col = NULL;
1267     elem_type_t *types = NULL;
1268     BSTR tmp;
1269     int i;
1270     HRESULT hres;
1271
1272     tmp = a2bstr(elem_type_infos[type].tag);
1273     hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1274     SysFreeString(tmp);
1275     IHTMLElement2_Release(elem);
1276     ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1277     ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1278
1279     if(exlen) {
1280         types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1281         for(i=0; i<exlen; i++)
1282             types[i] = type;
1283     }
1284
1285     _test_elem_collection(line, (IUnknown*)col, types, exlen);
1286
1287     HeapFree(GetProcessHeap(), 0, types);
1288 }
1289
1290 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1291 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1292 {
1293     BSTR text = NULL;
1294     HRESULT hres;
1295
1296     hres = IHTMLElement_get_innerText(elem, &text);
1297     ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1298     ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1299                         wine_dbgstr_w(text), extext);
1300     SysFreeString(text);
1301 }
1302
1303 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1304 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1305 {
1306     IHTMLDOMChildrenCollection *col;
1307     BSTR str;
1308     HRESULT hres;
1309
1310     str = a2bstr(text);
1311     hres = IHTMLElement_put_innerText(elem, str);
1312     ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1313     SysFreeString(str);
1314
1315     _test_elem_innertext(line, elem, text);
1316
1317
1318     col = _get_child_nodes(line, (IUnknown*)elem);
1319     ok(col != NULL, "col == NULL\n");
1320     if(col) {
1321         LONG length = 0, type;
1322         IHTMLDOMNode *node;
1323
1324         hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1325         ok(hres == S_OK, "get_length failed: %08x\n", hres);
1326         ok(length == 1, "length = %d\n", length);
1327
1328         node = _get_child_item(line, col, 0);
1329         ok(node != NULL, "node == NULL\n");
1330         if(node) {
1331             type = _get_node_type(line, (IUnknown*)node);
1332             ok(type == 3, "type=%d\n", type);
1333             IHTMLDOMNode_Release(node);
1334         }
1335
1336         IHTMLDOMChildrenCollection_Release(col);
1337     }
1338
1339 }
1340
1341 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
1342 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1343 {
1344     IHTMLElement *elem = _get_elem_iface(line, unk);
1345     BSTR html;
1346     HRESULT hres;
1347
1348     hres = IHTMLElement_get_innerHTML(elem, &html);
1349     ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
1350     if(inner_html)
1351         ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
1352     else
1353         ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
1354
1355     IHTMLElement_Release(elem);
1356     SysFreeString(html);
1357 }
1358
1359 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
1360 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1361 {
1362     IHTMLElement *elem = _get_elem_iface(line, unk);
1363     BSTR html;
1364     HRESULT hres;
1365
1366     html = a2bstr(inner_html);
1367     hres = IHTMLElement_put_innerHTML(elem, html);
1368     ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
1369
1370     IHTMLElement_Release(elem);
1371     SysFreeString(html);
1372 }
1373
1374 #define get_first_child(n) _get_first_child(__LINE__,n)
1375 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1376 {
1377     IHTMLDOMNode *node = _get_node_iface(line, unk);
1378     IHTMLDOMNode *child = NULL;
1379     HRESULT hres;
1380
1381     hres = IHTMLDOMNode_get_firstChild(node, &child);
1382     IHTMLDOMNode_Release(node);
1383     ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1384
1385     return child;
1386 }
1387
1388 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1389 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1390 {
1391     IHTMLDOMNode *node = _get_node_iface(line, unk);
1392     VARIANT_BOOL b = 0xdead;
1393     HRESULT hres;
1394
1395     hres = IHTMLDOMNode_hasChildNodes(node, &b);
1396     ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1397     ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1398
1399     IHTMLDOMNode_Release(node);
1400 }
1401
1402 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1403 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1404 {
1405     IHTMLDOMNode *node = _get_node_iface(line, unk);
1406     IHTMLDOMNode *parent;
1407     HRESULT hres;
1408
1409     hres = IHTMLDOMNode_get_parentNode(node, &parent);
1410     IHTMLDOMNode_Release(node);
1411     ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1412
1413     return parent;
1414 }
1415
1416 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1417 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1418 {
1419     IHTMLElement *elem = _get_elem_iface(line, unk);
1420     IHTMLElement *parent;
1421     HRESULT hres;
1422
1423     hres = IHTMLElement_get_parentElement(elem, &parent);
1424     IHTMLElement_Release(elem);
1425     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1426
1427     return parent;
1428 }
1429
1430 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1431 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1432 {
1433     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1434     VARIANT_BOOL disabled = 100;
1435     HRESULT hres;
1436
1437     if (!elem3) return;
1438     hres = IHTMLElement3_get_disabled(elem3, &disabled);
1439     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1440     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1441     IHTMLElement3_Release(elem3);
1442 }
1443
1444 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1445 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1446 {
1447     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1448     HRESULT hres;
1449
1450     if (!elem3) return;
1451     hres = IHTMLElement3_put_disabled(elem3, b);
1452     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1453
1454     IHTMLElement3_Release(elem3);
1455     _test_elem3_get_disabled(line, unk, b);
1456 }
1457
1458 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1459 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1460 {
1461     VARIANT_BOOL disabled = 100;
1462     HRESULT hres;
1463
1464     hres = IHTMLSelectElement_get_disabled(select, &disabled);
1465     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1466     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1467
1468     _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1469 }
1470
1471 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1472 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1473 {
1474     HRESULT hres;
1475
1476     hres = IHTMLSelectElement_put_disabled(select, b);
1477     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1478
1479     _test_select_get_disabled(line, select, b);
1480 }
1481
1482 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1483 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
1484 {
1485     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1486     IHTMLTextContainer *txtcont;
1487     LONG l = -1, l2 = -1;
1488     HRESULT hres;
1489
1490     hres = IHTMLElement2_get_scrollHeight(elem, &l);
1491     ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1492     IHTMLElement2_Release(elem);
1493
1494     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1495     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1496
1497     hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1498     IHTMLTextContainer_Release(txtcont);
1499     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
1500     ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
1501
1502     return l;
1503 }
1504
1505 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1506 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
1507 {
1508     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1509     IHTMLTextContainer *txtcont;
1510     LONG l = -1, l2 = -1;
1511     HRESULT hres;
1512
1513     hres = IHTMLElement2_get_scrollWidth(elem, &l);
1514     ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1515     IHTMLElement2_Release(elem);
1516
1517     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1518     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1519
1520     hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1521     IHTMLTextContainer_Release(txtcont);
1522     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
1523     ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
1524
1525     return l;
1526 }
1527
1528 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1529 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
1530 {
1531     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1532     IHTMLTextContainer *txtcont;
1533     LONG l = -1, l2 = -1;
1534     HRESULT hres;
1535
1536     hres = IHTMLElement2_get_scrollTop(elem, &l);
1537     ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1538     IHTMLElement2_Release(elem);
1539
1540     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1541     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1542
1543     hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1544     IHTMLTextContainer_Release(txtcont);
1545     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
1546     ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
1547
1548     return l;
1549 }
1550
1551 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1552 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1553 {
1554     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1555     IHTMLTextContainer *txtcont;
1556     LONG l = -1, l2 = -1;
1557     HRESULT hres;
1558
1559     hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1560     ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1561
1562     hres = IHTMLElement2_get_scrollLeft(elem, &l);
1563     ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1564     IHTMLElement2_Release(elem);
1565
1566     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1567     ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1568
1569     hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1570     IHTMLTextContainer_Release(txtcont);
1571     ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
1572     ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
1573 }
1574
1575 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1576 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1577 {
1578     IHTMLImgElement *img = _get_img_iface(line, unk);
1579     BSTR src;
1580     HRESULT hres;
1581
1582     hres = IHTMLImgElement_get_src(img, &src);
1583     IHTMLImgElement_Release(img);
1584     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1585     ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
1586     SysFreeString(src);
1587 }
1588
1589 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1590 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1591 {
1592     IHTMLImgElement *img = _get_img_iface(line, unk);
1593     BSTR tmp;
1594     HRESULT hres;
1595
1596     tmp = a2bstr(src);
1597     hres = IHTMLImgElement_put_src(img, tmp);
1598     IHTMLImgElement_Release(img);
1599     SysFreeString(tmp);
1600     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1601
1602     _test_img_src(line, unk, src);
1603 }
1604
1605 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1606 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1607 {
1608     IHTMLImgElement *img = _get_img_iface(line, unk);
1609     BSTR alt;
1610     HRESULT hres;
1611
1612     hres = IHTMLImgElement_get_alt(img, &alt);
1613     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1614     if(exalt)
1615         ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
1616     else
1617         ok_(__FILE__,line) (!alt, "alt != NULL\n");
1618     SysFreeString(alt);
1619 }
1620
1621 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1622 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1623 {
1624     IHTMLImgElement *img = _get_img_iface(line, unk);
1625     BSTR tmp;
1626     HRESULT hres;
1627
1628     tmp = a2bstr(alt);
1629     hres = IHTMLImgElement_put_alt(img, tmp);
1630     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1631     SysFreeString(tmp);
1632
1633     _test_img_alt(line, unk, alt);
1634 }
1635
1636 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1637 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1638 {
1639     VARIANT_BOOL disabled = 100;
1640     HRESULT hres;
1641
1642     hres = IHTMLInputElement_get_disabled(input, &disabled);
1643     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1644     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1645
1646     _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1647 }
1648
1649 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1650 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1651 {
1652     HRESULT hres;
1653
1654     hres = IHTMLInputElement_put_disabled(input, b);
1655     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1656
1657     _test_input_get_disabled(line, input, b);
1658 }
1659
1660 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
1661 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1662 {
1663     VARIANT_BOOL checked = 100;
1664     HRESULT hres;
1665
1666     hres = IHTMLInputElement_get_defaultChecked(input, &checked);
1667     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1668     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1669 }
1670
1671 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
1672 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1673 {
1674     HRESULT hres;
1675
1676     hres = IHTMLInputElement_put_defaultChecked(input, b);
1677     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1678
1679     _test_input_get_defaultchecked(line, input, b);
1680 }
1681
1682 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
1683 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1684 {
1685     VARIANT_BOOL checked = 100;
1686     HRESULT hres;
1687
1688     hres = IHTMLInputElement_get_checked(input, &checked);
1689     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1690     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1691 }
1692
1693 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
1694 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1695 {
1696     HRESULT hres;
1697
1698     hres = IHTMLInputElement_put_checked(input, b);
1699     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1700
1701     _test_input_get_checked(line, input, b);
1702 }
1703
1704 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1705 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1706 {
1707     IHTMLInputElement *input;
1708     BSTR bstr;
1709     HRESULT hres;
1710
1711     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1712     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1713     if(FAILED(hres))
1714         return;
1715
1716     hres = IHTMLInputElement_get_value(input, &bstr);
1717     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1718     if(exval)
1719         ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
1720     else
1721         ok_(__FILE__,line) (!exval, "exval != NULL\n");
1722     SysFreeString(bstr);
1723     IHTMLInputElement_Release(input);
1724 }
1725
1726 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1727 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1728 {
1729     IHTMLInputElement *input;
1730     BSTR bstr;
1731     HRESULT hres;
1732
1733     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1734     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1735     if(FAILED(hres))
1736         return;
1737
1738     bstr = a2bstr(val);
1739     hres = IHTMLInputElement_get_value(input, &bstr);
1740     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1741     SysFreeString(bstr);
1742     IHTMLInputElement_Release(input);
1743 }
1744
1745 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
1746 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
1747 {
1748     BSTR src;
1749     HRESULT hres;
1750
1751     hres = IHTMLInputElement_get_src(input, &src);
1752     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1753     if(exsrc)
1754         ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
1755     else
1756         ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
1757     SysFreeString(src);
1758 }
1759
1760 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
1761 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
1762 {
1763     BSTR tmp;
1764     HRESULT hres;
1765
1766     tmp = a2bstr(src);
1767     hres = IHTMLInputElement_put_src(input, tmp);
1768     SysFreeString(tmp);
1769     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1770
1771     _test_input_src(line, input, src);
1772 }
1773
1774 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1775 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1776 {
1777     IHTMLElement *elem = _get_elem_iface(line, unk);
1778     BSTR class = (void*)0xdeadbeef;
1779     HRESULT hres;
1780
1781     hres = IHTMLElement_get_className(elem, &class);
1782     IHTMLElement_Release(elem);
1783     ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1784     if(exclass)
1785         ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
1786     else
1787         ok_(__FILE__,line) (!class, "class != NULL\n");
1788     SysFreeString(class);
1789 }
1790
1791 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1792 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1793 {
1794     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1795     short index = -3;
1796     HRESULT hres;
1797
1798     hres = IHTMLElement2_get_tabIndex(elem2, &index);
1799     IHTMLElement2_Release(elem2);
1800     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1801     ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1802 }
1803
1804 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1805 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1806 {
1807     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1808     HRESULT hres;
1809
1810     hres = IHTMLElement2_put_tabIndex(elem2, index);
1811     IHTMLElement2_Release(elem2);
1812     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1813
1814     _test_elem_tabindex(line, unk, index);
1815 }
1816
1817 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1818 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1819 {
1820     IHTMLElement *elem = _get_elem_iface(line, unk);
1821     BSTR tmp;
1822     HRESULT hres;
1823
1824     tmp = class ? a2bstr(class) : NULL;
1825     hres = IHTMLElement_put_className(elem, tmp);
1826     IHTMLElement_Release(elem);
1827     ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1828     SysFreeString(tmp);
1829
1830     _test_elem_class(line, unk, class);
1831 }
1832
1833 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1834 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1835 {
1836     IHTMLElement *elem = _get_elem_iface(line, unk);
1837     BSTR id = (void*)0xdeadbeef;
1838     HRESULT hres;
1839
1840     hres = IHTMLElement_get_id(elem, &id);
1841     IHTMLElement_Release(elem);
1842     ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1843
1844     if(exid)
1845         ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
1846     else
1847         ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
1848
1849     SysFreeString(id);
1850 }
1851
1852 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1853 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1854 {
1855     IHTMLElement *elem = _get_elem_iface(line, unk);
1856     BSTR tmp = a2bstr(new_id);
1857     HRESULT hres;
1858
1859     hres = IHTMLElement_put_id(elem, tmp);
1860     IHTMLElement_Release(elem);
1861     SysFreeString(tmp);
1862     ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1863
1864     _test_elem_id(line, unk, new_id);
1865 }
1866
1867 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1868 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1869 {
1870     IHTMLElement *elem = _get_elem_iface(line, unk);
1871     BSTR title;
1872     HRESULT hres;
1873
1874     hres = IHTMLElement_get_title(elem, &title);
1875     IHTMLElement_Release(elem);
1876     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1877     if(extitle)
1878         ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
1879     else
1880         ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
1881
1882     SysFreeString(title);
1883 }
1884
1885 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1886 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1887 {
1888     IHTMLElement *elem = _get_elem_iface(line, unk);
1889     BSTR tmp;
1890     HRESULT hres;
1891
1892     tmp = a2bstr(title);
1893     hres = IHTMLElement_put_title(elem, tmp);
1894     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1895
1896     IHTMLElement_Release(elem);
1897     SysFreeString(tmp);
1898 }
1899
1900 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1901 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1902 {
1903     IHTMLDOMNode *node = _get_node_iface(line, unk);
1904     VARIANT var;
1905     HRESULT hres;
1906
1907     hres = IHTMLDOMNode_get_nodeValue(node, &var);
1908     IHTMLDOMNode_Release(node);
1909     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1910
1911     if(exval) {
1912         ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1913         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
1914     }else {
1915         ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1916     }
1917
1918     VariantClear(&var);
1919 }
1920
1921 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1922 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1923 {
1924     IHTMLDOMNode *node = _get_node_iface(line, unk);
1925     VARIANT var;
1926     HRESULT hres;
1927
1928     V_VT(&var) = VT_BSTR;
1929     V_BSTR(&var) = a2bstr(val);
1930
1931     hres = IHTMLDOMNode_put_nodeValue(node, var);
1932     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1933     IHTMLDOMNode_Release(node);
1934     VariantClear(&var);
1935 }
1936
1937 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1938 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1939 {
1940     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1941     LONG l;
1942     HRESULT hres;
1943
1944     hres = IHTMLElement2_get_clientWidth(elem, &l);
1945     ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1946     hres = IHTMLElement2_get_clientHeight(elem, &l);
1947     ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1948
1949     IHTMLElement2_Release(elem);
1950 }
1951
1952 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1953 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1954 {
1955     IHTMLElement *elem = NULL;
1956     BSTR tmp;
1957     HRESULT hres;
1958
1959     tmp = a2bstr(tag);
1960     hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1961     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1962     ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1963
1964     return elem;
1965 }
1966
1967 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1968 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1969 {
1970     IHTMLDocument3 *doc3;
1971     IHTMLDOMNode *node = NULL;
1972     BSTR tmp;
1973     HRESULT hres;
1974
1975     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1976     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1977
1978     tmp = a2bstr(text);
1979     hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1980     IHTMLDocument3_Release(doc3);
1981     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1982     ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1983
1984     return node;
1985 }
1986
1987 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1988 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1989 {
1990     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1991     IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1992     IHTMLDOMNode *new_child = NULL;
1993     HRESULT hres;
1994
1995     hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1996     ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1997     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1998     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1999
2000     IHTMLDOMNode_Release(node);
2001     IHTMLDOMNode_Release(child);
2002
2003     return new_child;
2004 }
2005
2006 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
2007 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
2008 {
2009     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
2010     IHTMLDOMNode *new_child = NULL;
2011     HRESULT hres;
2012
2013     hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
2014     ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
2015     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
2016     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
2017
2018     IHTMLDOMNode_Release(node);
2019
2020     return new_child;
2021 }
2022
2023 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
2024 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
2025 {
2026     IHTMLDOMNode *node = _get_node_iface(line, unk);
2027     IHTMLDOMNode *new_node = NULL;
2028     HRESULT hres;
2029
2030     hres = IHTMLDOMNode_removeChild(node, child, &new_node);
2031     ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
2032     ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
2033     /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
2034
2035     IHTMLDOMNode_Release(node);
2036     IHTMLDOMNode_Release(new_node);
2037 }
2038
2039 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
2040 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
2041 {
2042     BSTR title = NULL;
2043     HRESULT hres;
2044
2045     hres = IHTMLDocument2_get_title(doc, &title);
2046     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2047     ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2048     SysFreeString(title);
2049 }
2050
2051 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
2052 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
2053 {
2054     BSTR tmp;
2055     HRESULT hres;
2056
2057     tmp = a2bstr(title);
2058     hres = IHTMLDocument2_put_title(doc, tmp);
2059     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2060     SysFreeString(tmp);
2061 }
2062
2063 #define test_border_styles(p, n) _test_border_styles(__LINE__, p, n)
2064 static void _test_border_styles(unsigned line, IHTMLStyle *pStyle, BSTR Name)
2065 {
2066     HRESULT hres;
2067     DISPID dispid;
2068
2069     hres = IHTMLStyle_GetIDsOfNames(pStyle, &IID_NULL, &Name, 1,
2070                         LOCALE_USER_DEFAULT, &dispid);
2071     ok_(__FILE__,line) (hres == S_OK, "GetIDsOfNames: %08x\n", hres);
2072     if(hres == S_OK)
2073     {
2074         DISPPARAMS params = {NULL,NULL,0,0};
2075         DISPID dispidNamed = DISPID_PROPERTYPUT;
2076         VARIANT ret;
2077         VARIANT vDefault;
2078         VARIANTARG arg;
2079
2080         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2081             DISPATCH_PROPERTYGET, &params, &vDefault, NULL, NULL);
2082         ok_(__FILE__,line) (hres == S_OK, "get_default. ret: %08x\n", hres);
2083
2084         params.cArgs = 1;
2085         params.cNamedArgs = 1;
2086         params.rgdispidNamedArgs = &dispidNamed;
2087         V_VT(&arg) = VT_BSTR;
2088         V_BSTR(&arg) = a2bstr("none");
2089         params.rgvarg = &arg;
2090         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2091             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2092         ok_(__FILE__,line) (hres == S_OK, "none. ret: %08x\n", hres);
2093         VariantClear(&arg);
2094
2095         V_VT(&arg) = VT_BSTR;
2096         V_BSTR(&arg) = a2bstr("dotted");
2097         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2098             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2099         ok_(__FILE__,line) (hres == S_OK, "dotted. ret: %08x\n", hres);
2100         VariantClear(&arg);
2101
2102         V_VT(&arg) = VT_BSTR;
2103         V_BSTR(&arg) = a2bstr("dashed");
2104         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2105         DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2106         ok_(__FILE__,line) (hres == S_OK, "dashed. ret: %08x\n", hres);
2107         VariantClear(&arg);
2108
2109         V_VT(&arg) = VT_BSTR;
2110         V_BSTR(&arg) = a2bstr("solid");
2111         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2112             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2113         ok_(__FILE__,line) (hres == S_OK, "solid. ret: %08x\n", hres);
2114         VariantClear(&arg);
2115
2116         V_VT(&arg) = VT_BSTR;
2117         V_BSTR(&arg) = a2bstr("double");
2118         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2119             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2120         ok_(__FILE__,line) (hres == S_OK, "double. ret: %08x\n", hres);
2121         VariantClear(&arg);
2122
2123         V_VT(&arg) = VT_BSTR;
2124         V_BSTR(&arg) = a2bstr("groove");
2125         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2126             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2127         ok_(__FILE__,line) (hres == S_OK, "groove. ret: %08x\n", hres);
2128         VariantClear(&arg);
2129
2130         V_VT(&arg) = VT_BSTR;
2131         V_BSTR(&arg) = a2bstr("ridge");
2132         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2133             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2134         ok_(__FILE__,line) (hres == S_OK, "ridge. ret: %08x\n", hres);
2135         VariantClear(&arg);
2136
2137         V_VT(&arg) = VT_BSTR;
2138         V_BSTR(&arg) = a2bstr("inset");
2139         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2140             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2141         ok_(__FILE__,line) (hres == S_OK, "inset. ret: %08x\n", hres);
2142         VariantClear(&arg);
2143
2144         V_VT(&arg) = VT_BSTR;
2145         V_BSTR(&arg) = a2bstr("outset");
2146         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2147             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2148         ok_(__FILE__,line) (hres == S_OK, "outset. ret: %08x\n", hres);
2149         VariantClear(&arg);
2150
2151         V_VT(&arg) = VT_BSTR;
2152         V_BSTR(&arg) = a2bstr("invalid");
2153         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2154             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2155         ok_(__FILE__,line) (FAILED(hres), "invalid value passed.\n");
2156         VariantClear(&arg);
2157
2158         params.rgvarg = &vDefault;
2159         hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2160             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2161         ok_(__FILE__,line) (hres == S_OK, "default. ret: %08x\n", hres);
2162     }
2163 }
2164
2165 #define test_style_csstext(s,t) _test_style_csstext(__LINE__,s,t)
2166 static void _test_style_csstext(unsigned line, IHTMLStyle *style, const char *extext)
2167 {
2168     BSTR text = (void*)0xdeadbeef;
2169     HRESULT hres;
2170
2171     hres = IHTMLStyle_get_cssText(style, &text);
2172     ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
2173     if(extext)
2174         ok_(__FILE__,line)(!strcmp_wa(text, extext), "cssText = %s\n", wine_dbgstr_w(text));
2175     else
2176         ok_(__FILE__,line)(!text, "cssText = %s\n", wine_dbgstr_w(text));
2177
2178     SysFreeString(text);
2179 }
2180
2181 #define test_style_set_csstext(s,t) _test_style_set_csstext(__LINE__,s,t)
2182 static void _test_style_set_csstext(unsigned line, IHTMLStyle *style, const char *text)
2183 {
2184     BSTR tmp;
2185     HRESULT hres;
2186
2187     tmp = a2bstr(text);
2188     hres = IHTMLStyle_put_cssText(style, tmp);
2189     ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
2190     SysFreeString(tmp);
2191 }
2192
2193 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
2194         const elem_type_t *elem_types, LONG len)
2195 {
2196     IDispatch *disp;
2197     VARIANT name, index;
2198     DWORD i;
2199     HRESULT hres;
2200
2201     V_VT(&index) = VT_EMPTY;
2202     V_VT(&name) = VT_BSTR;
2203     V_BSTR(&name) = a2bstr(n);
2204
2205     hres = IHTMLElementCollection_item(col, name, index, &disp);
2206     ok(hres == S_OK, "item failed: %08x\n", hres);
2207
2208     test_elem_collection((IUnknown*)disp, elem_types, len);
2209     IDispatch_Release(disp);
2210     ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
2211     if(hres != S_OK)
2212         goto cleanup;
2213
2214     V_VT(&index) = VT_I4;
2215
2216     for(i=0; i<len; i++) {
2217         V_I4(&index) = i;
2218         disp = (void*)0xdeadbeef;
2219         hres = IHTMLElementCollection_item(col, name, index, &disp);
2220         ok(hres == S_OK, "item failed: %08x\n", hres);
2221         ok(disp != NULL, "disp == NULL\n");
2222         if(FAILED(hres) || !disp)
2223             continue;
2224
2225         test_elem_type((IUnknown*)disp, elem_types[i]);
2226
2227         IDispatch_Release(disp);
2228     }
2229
2230     V_I4(&index) = len;
2231     disp = (void*)0xdeadbeef;
2232     hres = IHTMLElementCollection_item(col, name, index, &disp);
2233     ok(hres == S_OK, "item failed: %08x\n", hres);
2234     ok(disp == NULL, "disp != NULL\n");
2235
2236     V_I4(&index) = -1;
2237     disp = (void*)0xdeadbeef;
2238     hres = IHTMLElementCollection_item(col, name, index, &disp);
2239     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2240     ok(disp == NULL, "disp != NULL\n");
2241
2242 cleanup:
2243     SysFreeString(V_BSTR(&name));
2244 }
2245
2246 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
2247 {
2248     IHTMLElementCollection *col;
2249     IHTMLElement *elem;
2250     IDispatch *disp = (void*)0xdeadbeef;
2251     VARIANT name, index;
2252     HRESULT hres;
2253
2254     hres = IHTMLDocument2_get_all(doc, &col);
2255     ok(hres == S_OK, "get_all failed: %08x\n", hres);
2256     ok(col != NULL, "col == NULL\n");
2257     if(FAILED(hres) || !col)
2258         return NULL;
2259
2260     V_VT(&index) = VT_EMPTY;
2261     V_VT(&name) = VT_BSTR;
2262     V_BSTR(&name) = a2bstr(id);
2263
2264     hres = IHTMLElementCollection_item(col, name, index, &disp);
2265     IHTMLElementCollection_Release(col);
2266     SysFreeString(V_BSTR(&name));
2267     ok(hres == S_OK, "item failed: %08x\n", hres);
2268     if(!expect_success) {
2269         ok(disp == NULL, "disp != NULL\n");
2270         return NULL;
2271     }
2272
2273     ok(disp != NULL, "disp == NULL\n");
2274     if(!disp)
2275         return NULL;
2276
2277     elem = get_elem_iface((IUnknown*)disp);
2278     IDispatch_Release(disp);
2279
2280     return elem;
2281 }
2282
2283 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
2284 {
2285     IHTMLDocument3 *doc3;
2286     IHTMLElement *elem;
2287     BSTR tmp;
2288     HRESULT hres;
2289
2290     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2291     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
2292
2293     tmp = a2bstr(id);
2294     hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
2295     SysFreeString(tmp);
2296     ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
2297
2298     IHTMLDocument3_Release(doc3);
2299
2300     return elem;
2301 }
2302
2303 static void test_select_elem(IHTMLSelectElement *select)
2304 {
2305     test_select_type(select, "select-one");
2306     test_select_length(select, 2);
2307     test_select_selidx(select, 0);
2308     test_select_put_selidx(select, 1);
2309
2310     test_select_set_value(select, "val1");
2311     test_select_value(select, "val1");
2312
2313     test_select_get_disabled(select, VARIANT_FALSE);
2314     test_select_set_disabled(select, VARIANT_TRUE);
2315     test_select_set_disabled(select, VARIANT_FALSE);
2316 }
2317
2318 static void test_create_option_elem(IHTMLDocument2 *doc)
2319 {
2320     IHTMLOptionElement *option;
2321
2322     option = create_option_elem(doc, "test text", "test value");
2323
2324     test_option_put_text(option, "new text");
2325     test_option_put_value(option, "new value");
2326
2327     IHTMLOptionElement_Release(option);
2328 }
2329
2330 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
2331 {
2332     IHTMLBodyElement *body;
2333     IHTMLTxtRange *range;
2334     IHTMLElement *elem;
2335     HRESULT hres;
2336
2337     hres = IHTMLDocument2_get_body(doc, &elem);
2338     ok(hres == S_OK, "get_body failed: %08x\n", hres);
2339
2340     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2341     IHTMLElement_Release(elem);
2342
2343     hres = IHTMLBodyElement_createTextRange(body, &range);
2344     IHTMLBodyElement_Release(body);
2345     ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
2346
2347     return range;
2348 }
2349
2350 static void test_txtrange(IHTMLDocument2 *doc)
2351 {
2352     IHTMLTxtRange *body_range, *range, *range2;
2353     IHTMLSelectionObject *selection;
2354     IDispatch *disp_range;
2355     HRESULT hres;
2356
2357     body_range = test_create_body_range(doc);
2358
2359     test_range_text(body_range, "test abc 123\r\nit's text");
2360
2361     hres = IHTMLTxtRange_duplicate(body_range, &range);
2362     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2363
2364     hres = IHTMLTxtRange_duplicate(body_range, &range2);
2365     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2366     test_range_isequal(range, range2, VARIANT_TRUE);
2367
2368     test_range_text(range, "test abc 123\r\nit's text");
2369     test_range_text(body_range, "test abc 123\r\nit's text");
2370
2371     test_range_collapse(range, TRUE);
2372     test_range_isequal(range, range2, VARIANT_FALSE);
2373     test_range_inrange(range, range2, VARIANT_FALSE);
2374     test_range_inrange(range2, range, VARIANT_TRUE);
2375     IHTMLTxtRange_Release(range2);
2376
2377     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2378     test_range_expand(range, wordW, VARIANT_FALSE, "test ");
2379     test_range_move(range, characterW, 2, 2);
2380     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2381
2382     test_range_collapse(range, FALSE);
2383     test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
2384
2385     test_range_collapse(range, FALSE);
2386     test_range_expand(range, wordW, VARIANT_TRUE, "123");
2387     test_range_expand(range, wordW, VARIANT_FALSE, "123");
2388     test_range_move(range, characterW, 2, 2);
2389     test_range_expand(range, wordW, VARIANT_TRUE, "123");
2390     test_range_moveend(range, characterW, -5, -5);
2391     test_range_text(range, NULL);
2392     test_range_moveend(range, characterW, 3, 3);
2393     test_range_text(range, "c 1");
2394     test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
2395     test_range_collapse(range, TRUE);
2396     test_range_move(range, characterW, 4, 4);
2397     test_range_moveend(range, characterW, 1, 1);
2398     test_range_text(range, " ");
2399     test_range_move(range, wordW, 1, 1);
2400     test_range_moveend(range, characterW, 2, 2);
2401     test_range_text(range, "ab");
2402
2403     IHTMLTxtRange_Release(range);
2404
2405     hres = IHTMLTxtRange_duplicate(body_range, &range);
2406     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2407
2408     test_range_text(range, "test abc 123\r\nit's text");
2409     test_range_move(range, characterW, 3, 3);
2410     test_range_moveend(range, characterW, 1, 1);
2411     test_range_text(range, "t");
2412     test_range_moveend(range, characterW, 3, 3);
2413     test_range_text(range, "t ab");
2414     test_range_moveend(range, characterW, -2, -2);
2415     test_range_text(range, "t ");
2416     test_range_move(range, characterW, 6, 6);
2417     test_range_moveend(range, characterW, 3, 3);
2418     test_range_text(range, "123");
2419     test_range_moveend(range, characterW, 2, 2);
2420     test_range_text(range, "123\r\ni");
2421
2422     IHTMLTxtRange_Release(range);
2423
2424     hres = IHTMLTxtRange_duplicate(body_range, &range);
2425     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2426
2427     test_range_move(range, wordW, 1, 1);
2428     test_range_moveend(range, characterW, 2, 2);
2429     test_range_text(range, "ab");
2430
2431     test_range_move(range, characterW, -2, -2);
2432     test_range_moveend(range, characterW, 2, 2);
2433     test_range_text(range, "t ");
2434
2435     test_range_move(range, wordW, 3, 3);
2436     test_range_move(range, wordW, -2, -2);
2437     test_range_moveend(range, characterW, 2, 2);
2438     test_range_text(range, "ab");
2439
2440     test_range_move(range, characterW, -6, -5);
2441     test_range_moveend(range, characterW, -1, 0);
2442     test_range_moveend(range, characterW, -6, 0);
2443     test_range_move(range, characterW, 2, 2);
2444     test_range_moveend(range, characterW, 2, 2);
2445     test_range_text(range, "st");
2446     test_range_moveend(range, characterW, -6, -4);
2447     test_range_moveend(range, characterW, 2, 2);
2448
2449     IHTMLTxtRange_Release(range);
2450
2451     hres = IHTMLTxtRange_duplicate(body_range, &range);
2452     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2453
2454     test_range_move(range, wordW, 2, 2);
2455     test_range_moveend(range, characterW, 2, 2);
2456     test_range_text(range, "12");
2457
2458     test_range_move(range, characterW, 15, 14);
2459     test_range_move(range, characterW, -2, -2);
2460     test_range_moveend(range, characterW, 3, 2);
2461     test_range_text(range, "t");
2462     test_range_moveend(range, characterW, -1, -1);
2463     test_range_text(range, "t");
2464     test_range_expand(range, wordW, VARIANT_TRUE, "text");
2465     test_range_move(range, characterW, -2, -2);
2466     test_range_moveend(range, characterW, 2, 2);
2467     test_range_text(range, "s ");
2468     test_range_move(range, characterW, 100, 7);
2469     test_range_move(range, wordW, 1, 0);
2470     test_range_move(range, characterW, -2, -2);
2471     test_range_moveend(range, characterW, 3, 2);
2472     test_range_text(range, "t");
2473
2474     IHTMLTxtRange_Release(range);
2475
2476     hres = IHTMLTxtRange_duplicate(body_range, &range);
2477     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2478
2479     test_range_collapse(range, TRUE);
2480     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2481     test_range_put_text(range, "word");
2482     test_range_text(body_range, "wordabc 123\r\nit's text");
2483     test_range_text(range, NULL);
2484     test_range_moveend(range, characterW, 3, 3);
2485     test_range_text(range, "abc");
2486     test_range_movestart(range, characterW, -2, -2);
2487     test_range_text(range, "rdabc");
2488     test_range_movestart(range, characterW, 3, 3);
2489     test_range_text(range, "bc");
2490     test_range_movestart(range, characterW, 4, 4);
2491     test_range_text(range, NULL);
2492     test_range_movestart(range, characterW, -3, -3);
2493     test_range_text(range, "c 1");
2494     test_range_movestart(range, characterW, -7, -6);
2495     test_range_text(range, "wordabc 1");
2496     test_range_movestart(range, characterW, 100, 22);
2497     test_range_text(range, NULL);
2498
2499     IHTMLTxtRange_Release(range);
2500     IHTMLTxtRange_Release(body_range);
2501
2502     hres = IHTMLDocument2_get_selection(doc, &selection);
2503     ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
2504
2505     hres = IHTMLSelectionObject_createRange(selection, &disp_range);
2506     ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
2507     IHTMLSelectionObject_Release(selection);
2508
2509     hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
2510     ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
2511     IDispatch_Release(disp_range);
2512
2513     test_range_text(range, NULL);
2514     test_range_moveend(range, characterW, 3, 3);
2515     test_range_text(range, "wor");
2516     test_range_parent(range, ET_BODY);
2517     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2518     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2519     test_range_move(range, characterW, 3, 3);
2520     test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
2521     test_range_moveend(range, characterW, -4, -4);
2522     test_range_put_text(range, "abc def ");
2523     test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
2524     test_range_move(range, wordW, 1, 1);
2525     test_range_movestart(range, characterW, -1, -1);
2526     test_range_text(range, " ");
2527     test_range_move(range, wordW, 1, 1);
2528     test_range_moveend(range, characterW, 3, 3);
2529     test_range_text(range, "def");
2530     test_range_put_text(range, "xyz");
2531     test_range_moveend(range, characterW, 1, 1);
2532     test_range_move(range, wordW, 1, 1);
2533     test_range_moveend(range, characterW, 2, 2);
2534     test_range_text(range, "ab");
2535
2536     IHTMLTxtRange_Release(range);
2537 }
2538
2539 static void test_txtrange2(IHTMLDocument2 *doc)
2540 {
2541     IHTMLTxtRange *range;
2542
2543     range = test_create_body_range(doc);
2544
2545     test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
2546     test_range_move(range, characterW, 5, 5);
2547     test_range_moveend(range, characterW, 1, 1);
2548     test_range_text(range, "2");
2549     test_range_move(range, characterW, -3, -3);
2550     test_range_moveend(range, characterW, 3, 3);
2551     test_range_text(range, "c\r\n\r\n1");
2552     test_range_collapse(range, VARIANT_FALSE);
2553     test_range_moveend(range, characterW, 4, 4);
2554     test_range_text(range, "23");
2555     test_range_moveend(range, characterW, 1, 1);
2556     test_range_text(range, "23\r\n\r\n\r\nd");
2557     test_range_moveend(range, characterW, -1, -1);
2558     test_range_text(range, "23");
2559     test_range_moveend(range, characterW, -1, -1);
2560     test_range_text(range, "23");
2561     test_range_moveend(range, characterW, -2, -2);
2562     test_range_text(range, "2");
2563
2564     IHTMLTxtRange_Release(range);
2565 }
2566
2567 static void test_compatmode(IHTMLDocument2 *doc)
2568 {
2569     IHTMLDocument5 *doc5;
2570     BSTR mode;
2571     HRESULT hres;
2572
2573     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2574     ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2575     if(FAILED(hres))
2576         return;
2577
2578     hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2579     IHTMLDocument5_Release(doc5);
2580     ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2581     ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
2582     SysFreeString(mode);
2583 }
2584
2585 static void test_location(IHTMLDocument2 *doc)
2586 {
2587     IHTMLLocation *location, *location2;
2588     IHTMLWindow2 *window;
2589     BSTR str;
2590     ULONG ref;
2591     HRESULT hres;
2592
2593     hres = IHTMLDocument2_get_location(doc, &location);
2594     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2595
2596     hres = IHTMLDocument2_get_location(doc, &location2);
2597     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2598
2599     ok(location == location2, "location != location2\n");
2600     IHTMLLocation_Release(location2);
2601
2602     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2603     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2604
2605     hres = IHTMLWindow2_get_location(window, &location2);
2606     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2607     ok(location == location2, "location != location2\n");
2608     IHTMLLocation_Release(location2);
2609
2610     test_ifaces((IUnknown*)location, location_iids);
2611     test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
2612
2613     hres = IHTMLLocation_get_pathname(location, &str);
2614     ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
2615     ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
2616
2617     hres = IHTMLLocation_get_href(location, NULL);
2618     ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
2619
2620     hres = IHTMLLocation_get_href(location, &str);
2621     ok(hres == S_OK, "get_href failed: %08x\n", hres);
2622     ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
2623
2624     ref = IHTMLLocation_Release(location);
2625     ok(!ref, "location chould be destroyed here\n");
2626 }
2627
2628 static void test_navigator(IHTMLDocument2 *doc)
2629 {
2630     IHTMLWindow2 *window;
2631     IOmNavigator *navigator, *navigator2;
2632     char buf[512];
2633     DWORD size;
2634     ULONG ref;
2635     BSTR bstr;
2636     HRESULT hres;
2637
2638     static const WCHAR v40[] = {'4','.','0'};
2639
2640     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2641     ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
2642
2643     hres = IHTMLWindow2_get_navigator(window, &navigator);
2644     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2645     ok(navigator != NULL, "navigator == NULL\n");
2646     test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
2647
2648     hres = IHTMLWindow2_get_navigator(window, &navigator2);
2649     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2650     ok(navigator != navigator2, "navigator2 != navihgator\n");
2651
2652     IHTMLWindow2_Release(window);
2653     IOmNavigator_Release(navigator2);
2654
2655     hres = IOmNavigator_get_appCodeName(navigator, &bstr);
2656     ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
2657     ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
2658     SysFreeString(bstr);
2659
2660     bstr = NULL;
2661     hres = IOmNavigator_get_appName(navigator, &bstr);
2662     ok(hres == S_OK, "get_appName failed: %08x\n", hres);
2663     ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
2664     SysFreeString(bstr);
2665
2666     bstr = NULL;
2667     hres = IOmNavigator_get_platform(navigator, &bstr);
2668     ok(hres == S_OK, "get_platform failed: %08x\n", hres);
2669 #ifdef _WIN64
2670     ok(!strcmp_wa(bstr, "Win64"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
2671 #else
2672     ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
2673 #endif
2674     SysFreeString(bstr);
2675
2676     bstr = NULL;
2677     hres = IOmNavigator_get_appVersion(navigator, &bstr);
2678     ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
2679     ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
2680     SysFreeString(bstr);
2681
2682     hres = IOmNavigator_toString(navigator, NULL);
2683     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
2684
2685     bstr = NULL;
2686     hres = IOmNavigator_toString(navigator, &bstr);
2687     ok(hres == S_OK, "toString failed: %08x\n", hres);
2688     ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
2689     SysFreeString(bstr);
2690
2691     size = sizeof(buf);
2692     hres = ObtainUserAgentString(0, buf, &size);
2693     ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
2694
2695     bstr = NULL;
2696     hres = IOmNavigator_get_userAgent(navigator, &bstr);
2697     ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
2698     ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
2699     SysFreeString(bstr);
2700
2701     ref = IOmNavigator_Release(navigator);
2702     ok(!ref, "navigator should be destroyed here\n");
2703 }
2704
2705 static void test_current_style(IHTMLCurrentStyle *current_style)
2706 {
2707     BSTR str;
2708     HRESULT hres;
2709     VARIANT v;
2710
2711     test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle, "[object]");
2712     test_ifaces((IUnknown*)current_style, cstyle_iids);
2713
2714     hres = IHTMLCurrentStyle_get_display(current_style, &str);
2715     ok(hres == S_OK, "get_display failed: %08x\n", hres);
2716     ok(!strcmp_wa(str, "block"), "get_display returned %s\n", wine_dbgstr_w(str));
2717     SysFreeString(str);
2718
2719     hres = IHTMLCurrentStyle_get_position(current_style, &str);
2720     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2721     ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
2722     SysFreeString(str);
2723
2724     hres = IHTMLCurrentStyle_get_fontFamily(current_style, &str);
2725     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2726     SysFreeString(str);
2727
2728     hres = IHTMLCurrentStyle_get_fontStyle(current_style, &str);
2729     ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
2730     ok(!strcmp_wa(str, "normal"), "get_fontStyle returned %s\n", wine_dbgstr_w(str));
2731     SysFreeString(str);
2732
2733     hres = IHTMLCurrentStyle_get_backgroundImage(current_style, &str);
2734     ok(hres == S_OK, "get_backgroundImage failed: %08x\n", hres);
2735     ok(!strcmp_wa(str, "none"), "get_backgroundImage returned %s\n", wine_dbgstr_w(str));
2736     SysFreeString(str);
2737
2738     hres = IHTMLCurrentStyle_get_fontVariant(current_style, &str);
2739     ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
2740     ok(!strcmp_wa(str, "normal"), "get_fontVariant returned %s\n", wine_dbgstr_w(str));
2741     SysFreeString(str);
2742
2743     hres = IHTMLCurrentStyle_get_borderTopStyle(current_style, &str);
2744     ok(hres == S_OK, "get_borderTopStyle failed: %08x\n", hres);
2745     ok(!strcmp_wa(str, "none"), "get_borderTopStyle returned %s\n", wine_dbgstr_w(str));
2746     SysFreeString(str);
2747
2748     hres = IHTMLCurrentStyle_get_borderRightStyle(current_style, &str);
2749     ok(hres == S_OK, "get_borderRightStyle failed: %08x\n", hres);
2750     ok(!strcmp_wa(str, "none"), "get_borderRightStyle returned %s\n", wine_dbgstr_w(str));
2751     SysFreeString(str);
2752
2753     hres = IHTMLCurrentStyle_get_borderBottomStyle(current_style, &str);
2754     ok(hres == S_OK, "get_borderBottomStyle failed: %08x\n", hres);
2755     ok(!strcmp_wa(str, "none"), "get_borderBottomStyle returned %s\n", wine_dbgstr_w(str));
2756     SysFreeString(str);
2757
2758     hres = IHTMLCurrentStyle_get_borderLeftStyle(current_style, &str);
2759     ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
2760     ok(!strcmp_wa(str, "none"), "get_borderLeftStyle returned %s\n", wine_dbgstr_w(str));
2761     SysFreeString(str);
2762
2763     hres = IHTMLCurrentStyle_get_textAlign(current_style, &str);
2764     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2765     ok(!strcmp_wa(str, "center"), "get_textAlign returned %s\n", wine_dbgstr_w(str));
2766     SysFreeString(str);
2767
2768     hres = IHTMLCurrentStyle_get_textDecoration(current_style, &str);
2769     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
2770     ok(!strcmp_wa(str, "none"), "get_textDecoration returned %s\n", wine_dbgstr_w(str));
2771     SysFreeString(str);
2772
2773     hres = IHTMLCurrentStyle_get_cursor(current_style, &str);
2774     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2775     ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
2776     SysFreeString(str);
2777
2778     hres = IHTMLCurrentStyle_get_backgroundRepeat(current_style, &str);
2779     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
2780     ok(!strcmp_wa(str, "repeat"), "get_backgroundRepeat returned %s\n", wine_dbgstr_w(str));
2781     SysFreeString(str);
2782
2783     hres = IHTMLCurrentStyle_get_borderColor(current_style, &str);
2784     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
2785     SysFreeString(str);
2786
2787     hres = IHTMLCurrentStyle_get_borderStyle(current_style, &str);
2788     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
2789     SysFreeString(str);
2790
2791     hres = IHTMLCurrentStyle_get_visibility(current_style, &str);
2792     ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2793     SysFreeString(str);
2794
2795     hres = IHTMLCurrentStyle_get_overflow(current_style, &str);
2796     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
2797     SysFreeString(str);
2798
2799     hres = IHTMLCurrentStyle_get_borderWidth(current_style, &str);
2800     ok(hres == S_OK, "get_borderWidth failed: %08x\n", hres);
2801     SysFreeString(str);
2802
2803     hres = IHTMLCurrentStyle_get_margin(current_style, &str);
2804     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2805     SysFreeString(str);
2806
2807     hres = IHTMLCurrentStyle_get_fontWeight(current_style, &v);
2808     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2809     ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2810     ok( V_I4(&v) == 400, "expect 400 got (%d)\n", V_I4(&v));
2811     VariantClear(&v);
2812
2813     hres = IHTMLCurrentStyle_get_fontSize(current_style, &v);
2814     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2815     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2816     VariantClear(&v);
2817
2818     hres = IHTMLCurrentStyle_get_left(current_style, &v);
2819     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2820     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2821     VariantClear(&v);
2822
2823     hres = IHTMLCurrentStyle_get_top(current_style, &v);
2824     ok(hres == S_OK, "get_top failed: %08x\n", hres);
2825     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2826     VariantClear(&v);
2827
2828     hres = IHTMLCurrentStyle_get_width(current_style, &v);
2829     ok(hres == S_OK, "get_width failed: %08x\n", hres);
2830     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2831     VariantClear(&v);
2832
2833     hres = IHTMLCurrentStyle_get_height(current_style, &v);
2834     ok(hres == S_OK, "get_height failed: %08x\n", hres);
2835     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2836     VariantClear(&v);
2837
2838     hres = IHTMLCurrentStyle_get_paddingLeft(current_style, &v);
2839     ok(hres == S_OK, "get_paddingLeft failed: %08x\n", hres);
2840     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2841     VariantClear(&v);
2842
2843     hres = IHTMLCurrentStyle_get_zIndex(current_style, &v);
2844     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2845     ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2846     ok( V_I4(&v) == 1, "expect 1 got (%d)\n", V_I4(&v));
2847     VariantClear(&v);
2848
2849     hres = IHTMLCurrentStyle_get_verticalAlign(current_style, &v);
2850     ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2851     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2852     ok(!strcmp_wa(V_BSTR(&v), "middle"), "get_verticalAlign returned %s\n", wine_dbgstr_w(V_BSTR(&v)));
2853     VariantClear(&v);
2854
2855     hres = IHTMLCurrentStyle_get_marginRight(current_style, &v);
2856     ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
2857     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2858     VariantClear(&v);
2859
2860     hres = IHTMLCurrentStyle_get_marginLeft(current_style, &v);
2861     ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
2862     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2863     VariantClear(&v);
2864
2865     hres = IHTMLCurrentStyle_get_borderLeftWidth(current_style, &v);
2866     ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
2867     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2868     VariantClear(&v);
2869
2870     V_BSTR(&v) = NULL;
2871     hres = IHTMLCurrentStyle_get_borderRightWidth(current_style, &v);
2872     ok(hres == S_OK, "get_borderRightWidth failed: %08x\n", hres);
2873     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2874     VariantClear(&v);
2875
2876     hres = IHTMLCurrentStyle_get_borderBottomWidth(current_style, &v);
2877     ok(hres == S_OK, "get_borderBottomWidth failed: %08x\n", hres);
2878     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2879     VariantClear(&v);
2880
2881     hres = IHTMLCurrentStyle_get_borderTopWidth(current_style, &v);
2882     ok(hres == S_OK, "get_borderTopWidth failed: %08x\n", hres);
2883     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2884     VariantClear(&v);
2885
2886     hres = IHTMLCurrentStyle_get_color(current_style, &v);
2887     ok(hres == S_OK, "get_color failed: %08x\n", hres);
2888     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2889     VariantClear(&v);
2890
2891     hres = IHTMLCurrentStyle_get_backgroundColor(current_style, &v);
2892     ok(hres == S_OK, "get_backgroundColor failed: %08x\n", hres);
2893     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2894     VariantClear(&v);
2895
2896     hres = IHTMLCurrentStyle_get_borderLeftColor(current_style, &v);
2897     ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
2898     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2899     VariantClear(&v);
2900
2901     hres = IHTMLCurrentStyle_get_borderTopColor(current_style, &v);
2902     ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
2903     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2904     VariantClear(&v);
2905
2906     hres = IHTMLCurrentStyle_get_borderRightColor(current_style, &v);
2907     ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
2908     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2909     VariantClear(&v);
2910
2911     hres = IHTMLCurrentStyle_get_borderBottomColor(current_style, &v);
2912     ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
2913     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2914     VariantClear(&v);
2915
2916     hres = IHTMLCurrentStyle_get_paddingTop(current_style, &v);
2917     ok(hres == S_OK, "get_paddingTop failed: %08x\n", hres);
2918     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2919     VariantClear(&v);
2920
2921     hres = IHTMLCurrentStyle_get_paddingRight(current_style, &v);
2922     ok(hres == S_OK, "get_paddingRight failed: %08x\n", hres);
2923     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2924     VariantClear(&v);
2925
2926     hres = IHTMLCurrentStyle_get_paddingBottom(current_style, &v);
2927     ok(hres == S_OK, "get_paddingRight failed: %08x\n", hres);
2928     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2929     VariantClear(&v);
2930
2931     hres = IHTMLCurrentStyle_get_letterSpacing(current_style, &v);
2932     ok(hres == S_OK, "get_letterSpacing failed: %08x\n", hres);
2933     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2934     VariantClear(&v);
2935
2936     hres = IHTMLCurrentStyle_get_marginTop(current_style, &v);
2937     ok(hres == S_OK, "get_marginTop failed: %08x\n", hres);
2938     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2939     VariantClear(&v);
2940
2941     hres = IHTMLCurrentStyle_get_marginBottom(current_style, &v);
2942     ok(hres == S_OK, "get_marginBottom failed: %08x\n", hres);
2943     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2944     VariantClear(&v);
2945
2946     hres = IHTMLCurrentStyle_get_right(current_style, &v);
2947     ok(hres == S_OK, "get_Right failed: %08x\n", hres);
2948     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2949     VariantClear(&v);
2950
2951     hres = IHTMLCurrentStyle_get_bottom(current_style, &v);
2952     ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
2953     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2954     VariantClear(&v);
2955
2956     hres = IHTMLCurrentStyle_get_lineHeight(current_style, &v);
2957     ok(hres == S_OK, "get_lineHeight failed: %08x\n", hres);
2958     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2959     VariantClear(&v);
2960
2961     hres = IHTMLCurrentStyle_get_textIndent(current_style, &v);
2962     ok(hres == S_OK, "get_textIndent failed: %08x\n", hres);
2963     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2964     VariantClear(&v);
2965 }
2966
2967 static void test_style2(IHTMLStyle2 *style2)
2968 {
2969     BSTR str;
2970     HRESULT hres;
2971
2972     str = (void*)0xdeadbeef;
2973     hres = IHTMLStyle2_get_position(style2, &str);
2974     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2975     ok(!str, "str != NULL\n");
2976
2977     str = a2bstr("absolute");
2978     hres = IHTMLStyle2_put_position(style2, str);
2979     ok(hres == S_OK, "put_position failed: %08x\n", hres);
2980     SysFreeString(str);
2981
2982     str = NULL;
2983     hres = IHTMLStyle2_get_position(style2, &str);
2984     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2985     ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
2986     SysFreeString(str);
2987 }
2988
2989 static void test_style3(IHTMLStyle3 *style3)
2990 {
2991     BSTR str;
2992     HRESULT hres;
2993
2994     str = (void*)0xdeadbeef;
2995     hres = IHTMLStyle3_get_wordWrap(style3, &str);
2996     ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
2997     ok(!str, "str != NULL\n");
2998
2999     str = a2bstr("break-word");
3000     hres = IHTMLStyle3_put_wordWrap(style3, str);
3001     ok(hres == S_OK, "put_wordWrap failed: %08x\n", hres);
3002     SysFreeString(str);
3003
3004     str = NULL;
3005     hres = IHTMLStyle3_get_wordWrap(style3, &str);
3006     ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
3007     ok(!strcmp_wa(str, "break-word"), "get_wordWrap returned %s\n", wine_dbgstr_w(str));
3008     SysFreeString(str);
3009 }
3010
3011 static void test_style4(IHTMLStyle4 *style4)
3012 {
3013     HRESULT hres;
3014     VARIANT v;
3015     VARIANT vdefault;
3016
3017     hres = IHTMLStyle4_get_minHeight(style4, &vdefault);
3018     ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
3019
3020     V_VT(&v) = VT_BSTR;
3021     V_BSTR(&v) = a2bstr("10px");
3022     hres = IHTMLStyle4_put_minHeight(style4, v);
3023     ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
3024     VariantClear(&v);
3025
3026     hres = IHTMLStyle4_get_minHeight(style4, &v);
3027     ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
3028     ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
3029     ok( !strcmp_wa(V_BSTR(&v), "10px"), "expect 10px got (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
3030
3031     hres = IHTMLStyle4_put_minHeight(style4, vdefault);
3032     ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
3033     VariantClear(&vdefault);
3034 }
3035
3036 static void test_default_style(IHTMLStyle *style)
3037 {
3038     IHTMLStyle2 *style2;
3039     IHTMLStyle3 *style3;
3040     IHTMLStyle4 *style4;
3041     VARIANT_BOOL b;
3042     VARIANT v;
3043     BSTR str;
3044     HRESULT hres;
3045     float f;
3046     BSTR sOverflowDefault;
3047     BSTR sDefault;
3048     VARIANT vDefault;
3049
3050     test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
3051     test_ifaces((IUnknown*)style, style_iids);
3052
3053     test_style_csstext(style, NULL);
3054
3055     hres = IHTMLStyle_get_position(style, &str);
3056     ok(hres == S_OK, "get_position failed: %08x\n", hres);
3057     ok(!str, "str=%s\n", wine_dbgstr_w(str));
3058
3059     V_VT(&v) = VT_NULL;
3060     hres = IHTMLStyle_get_marginRight(style, &v);
3061     ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
3062     ok(V_VT(&v) == VT_BSTR, "V_VT(marginRight) = %d\n", V_VT(&v));
3063     ok(!V_BSTR(&v), "V_BSTR(marginRight) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3064
3065     V_VT(&v) = VT_NULL;
3066     hres = IHTMLStyle_get_marginLeft(style, &v);
3067     ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
3068     ok(V_VT(&v) == VT_BSTR, "V_VT(marginLeft) = %d\n", V_VT(&v));
3069     ok(!V_BSTR(&v), "V_BSTR(marginLeft) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3070
3071     str = (void*)0xdeadbeef;
3072     hres = IHTMLStyle_get_fontFamily(style, &str);
3073     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
3074     ok(!str, "fontFamily = %s\n", wine_dbgstr_w(str));
3075
3076     str = (void*)0xdeadbeef;
3077     hres = IHTMLStyle_get_fontWeight(style, &str);
3078     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3079     ok(!str, "fontWeight = %s\n", wine_dbgstr_w(str));
3080
3081     hres = IHTMLStyle_get_fontWeight(style, &sDefault);
3082     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3083
3084     str = a2bstr("test");
3085     hres = IHTMLStyle_put_fontWeight(style, str);
3086     ok(hres == E_INVALIDARG, "put_fontWeight failed: %08x\n", hres);
3087     SysFreeString(str);
3088
3089     str = a2bstr("bold");
3090     hres = IHTMLStyle_put_fontWeight(style, str);
3091     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3092     SysFreeString(str);
3093
3094     str = a2bstr("bolder");
3095     hres = IHTMLStyle_put_fontWeight(style, str);
3096     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3097     SysFreeString(str);
3098
3099     str = a2bstr("lighter");
3100     hres = IHTMLStyle_put_fontWeight(style, str);
3101     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3102     SysFreeString(str);
3103
3104     str = a2bstr("100");
3105     hres = IHTMLStyle_put_fontWeight(style, str);
3106     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3107     SysFreeString(str);
3108
3109     str = a2bstr("200");
3110     hres = IHTMLStyle_put_fontWeight(style, str);
3111     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3112     SysFreeString(str);
3113
3114     str = a2bstr("300");
3115     hres = IHTMLStyle_put_fontWeight(style, str);
3116     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3117     SysFreeString(str);
3118
3119     str = a2bstr("400");
3120     hres = IHTMLStyle_put_fontWeight(style, str);
3121     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3122     SysFreeString(str);
3123
3124     str = a2bstr("500");
3125     hres = IHTMLStyle_put_fontWeight(style, str);
3126     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3127     SysFreeString(str);
3128
3129     str = a2bstr("600");
3130     hres = IHTMLStyle_put_fontWeight(style, str);
3131     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3132     SysFreeString(str);
3133
3134     str = a2bstr("700");
3135     hres = IHTMLStyle_put_fontWeight(style, str);
3136     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3137     SysFreeString(str);
3138
3139     str = a2bstr("800");
3140     hres = IHTMLStyle_put_fontWeight(style, str);
3141     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3142     SysFreeString(str);
3143
3144     str = a2bstr("900");
3145     hres = IHTMLStyle_put_fontWeight(style, str);
3146     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3147     SysFreeString(str);
3148
3149     hres = IHTMLStyle_get_fontWeight(style, &str);
3150     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
3151     ok(!strcmp_wa(str, "900"), "str != style900\n");
3152     SysFreeString(str);
3153
3154     hres = IHTMLStyle_put_fontWeight(style, sDefault);
3155     ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
3156     SysFreeString(sDefault);
3157
3158     /* font Variant */
3159     hres = IHTMLStyle_get_fontVariant(style, NULL);
3160     ok(hres == E_INVALIDARG, "get_fontVariant failed: %08x\n", hres);
3161
3162     hres = IHTMLStyle_get_fontVariant(style, &sDefault);
3163     ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
3164
3165     str = a2bstr("test");
3166     hres = IHTMLStyle_put_fontVariant(style, str);
3167     ok(hres == E_INVALIDARG, "fontVariant failed: %08x\n", hres);
3168     SysFreeString(str);
3169
3170     str = a2bstr("small-caps");
3171     hres = IHTMLStyle_put_fontVariant(style, str);
3172     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3173     SysFreeString(str);
3174
3175     str = a2bstr("normal");
3176     hres = IHTMLStyle_put_fontVariant(style, str);
3177     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3178     SysFreeString(str);
3179
3180     hres = IHTMLStyle_put_fontVariant(style, sDefault);
3181     ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
3182     SysFreeString(sDefault);
3183
3184     str = (void*)0xdeadbeef;
3185     hres = IHTMLStyle_get_display(style, &str);
3186     ok(hres == S_OK, "get_display failed: %08x\n", hres);
3187     ok(!str, "display = %s\n", wine_dbgstr_w(str));
3188
3189     str = (void*)0xdeadbeef;
3190     hres = IHTMLStyle_get_visibility(style, &str);
3191     ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
3192     ok(!str, "visibility = %s\n", wine_dbgstr_w(str));
3193
3194     V_VT(&v) = VT_NULL;
3195     hres = IHTMLStyle_get_fontSize(style, &v);
3196     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
3197     ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
3198     ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3199
3200     V_VT(&v) = VT_NULL;
3201     hres = IHTMLStyle_get_color(style, &v);
3202     ok(hres == S_OK, "get_color failed: %08x\n", hres);
3203     ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
3204     ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3205
3206     b = 0xfefe;
3207     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
3208     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
3209     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
3210
3211     hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_TRUE);
3212     ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
3213     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
3214
3215     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
3216     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
3217     ok(b == VARIANT_TRUE, "textDecorationUnderline = %x\n", b);
3218
3219     hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_FALSE);
3220     ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
3221
3222     b = 0xfefe;
3223     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
3224     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
3225     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
3226
3227     hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_TRUE);
3228     ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
3229     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
3230
3231     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
3232     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
3233     ok(b == VARIANT_TRUE, "textDecorationLineThrough = %x\n", b);
3234
3235     hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_FALSE);
3236     ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
3237
3238     b = 0xfefe;
3239     hres = IHTMLStyle_get_textDecorationNone(style, &b);
3240     ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
3241     ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
3242
3243     hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_TRUE);
3244     ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
3245     ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
3246
3247     hres = IHTMLStyle_get_textDecorationNone(style, &b);
3248     ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
3249     ok(b == VARIANT_TRUE, "textDecorationNone = %x\n", b);
3250
3251     hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_FALSE);
3252     ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
3253
3254     b = 0xfefe;
3255     hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3256     ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3257     ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3258
3259     hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_TRUE);
3260     ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3261     ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3262
3263     hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3264     ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3265     ok(b == VARIANT_TRUE, "textDecorationOverline = %x\n", b);
3266
3267     hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_FALSE);
3268     ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3269
3270     b = 0xfefe;
3271     hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3272     ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3273     ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3274
3275     hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_TRUE);
3276     ok(hres == S_OK, "put_textDecorationBlink failed: %08x\n", hres);
3277     ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3278
3279     hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3280     ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3281     ok(b == VARIANT_TRUE, "textDecorationBlink = %x\n", b);
3282
3283     hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_FALSE);
3284     ok(hres == S_OK, "textDecorationBlink failed: %08x\n", hres);
3285
3286     hres = IHTMLStyle_get_textDecoration(style, &sDefault);
3287     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3288
3289     str = a2bstr("invalid");
3290     hres = IHTMLStyle_put_textDecoration(style, str);
3291     ok(hres == E_INVALIDARG, "put_textDecoration failed: %08x\n", hres);
3292     SysFreeString(str);
3293
3294     str = a2bstr("none");
3295     hres = IHTMLStyle_put_textDecoration(style, str);
3296     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3297     SysFreeString(str);
3298
3299     str = a2bstr("underline");
3300     hres = IHTMLStyle_put_textDecoration(style, str);
3301     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3302     SysFreeString(str);
3303
3304     str = a2bstr("overline");
3305     hres = IHTMLStyle_put_textDecoration(style, str);
3306     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3307     SysFreeString(str);
3308
3309     str = a2bstr("line-through");
3310     hres = IHTMLStyle_put_textDecoration(style, str);
3311     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3312     SysFreeString(str);
3313
3314     str = a2bstr("blink");
3315     hres = IHTMLStyle_put_textDecoration(style, str);
3316     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3317     SysFreeString(str);
3318
3319     hres = IHTMLStyle_get_textDecoration(style, &str);
3320     ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3321     ok(!strcmp_wa(str, "blink"), "str != blink\n");
3322     SysFreeString(str);
3323
3324     hres = IHTMLStyle_put_textDecoration(style, sDefault);
3325     ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3326     SysFreeString(sDefault);
3327
3328     hres = IHTMLStyle_get_posWidth(style, NULL);
3329     ok(hres == E_POINTER, "get_posWidth failed: %08x\n", hres);
3330
3331     hres = IHTMLStyle_get_posWidth(style, &f);
3332     ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3333     ok(f == 0.0f, "f = %f\n", f);
3334
3335     V_VT(&v) = VT_EMPTY;
3336     hres = IHTMLStyle_get_width(style, &v);
3337     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3338     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3339     ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
3340
3341     hres = IHTMLStyle_put_posWidth(style, 2.2);
3342     ok(hres == S_OK, "put_posWidth failed: %08x\n", hres);
3343
3344     hres = IHTMLStyle_get_posWidth(style, &f);
3345     ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3346     ok(f == 2.0f ||
3347        f == 2.2f, /* IE8 */
3348        "f = %f\n", f);
3349
3350     V_VT(&v) = VT_BSTR;
3351     V_BSTR(&v) = a2bstr("auto");
3352     hres = IHTMLStyle_put_width(style, v);
3353     ok(hres == S_OK, "put_width failed: %08x\n", hres);
3354     VariantClear(&v);
3355
3356     V_VT(&v) = VT_EMPTY;
3357     hres = IHTMLStyle_get_width(style, &v);
3358     ok(hres == S_OK, "get_width failed: %08x\n", hres);
3359     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3360     ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3361     VariantClear(&v);
3362
3363     /* margin tests */
3364     str = (void*)0xdeadbeef;
3365     hres = IHTMLStyle_get_margin(style, &str);
3366     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3367     ok(!str, "margin = %s\n", wine_dbgstr_w(str));
3368
3369     str = a2bstr("1");
3370     hres = IHTMLStyle_put_margin(style, str);
3371     ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3372     SysFreeString(str);
3373
3374     hres = IHTMLStyle_get_margin(style, &str);
3375     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3376     ok(!strcmp_wa(str, "1px"), "margin = %s\n", wine_dbgstr_w(str));
3377
3378     hres = IHTMLStyle_put_margin(style, NULL);
3379     ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3380
3381     str = NULL;
3382     hres = IHTMLStyle_get_border(style, &str);
3383     ok(hres == S_OK, "get_border failed: %08x\n", hres);
3384     ok(!str || !*str, "str is not empty\n");
3385     SysFreeString(str);
3386
3387     str = a2bstr("1px");
3388     hres = IHTMLStyle_put_border(style, str);
3389     ok(hres == S_OK, "put_border failed: %08x\n", hres);
3390     SysFreeString(str);
3391
3392     V_VT(&v) = VT_EMPTY;
3393     hres = IHTMLStyle_get_left(style, &v);
3394     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3395     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3396     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3397     VariantClear(&v);
3398
3399     /* Test posLeft */
3400     hres = IHTMLStyle_get_posLeft(style, NULL);
3401     ok(hres == E_POINTER, "get_posLeft failed: %08x\n", hres);
3402
3403     f = 1.0f;
3404     hres = IHTMLStyle_get_posLeft(style, &f);
3405     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3406     ok(f == 0.0, "expected 0.0 got %f\n", f);
3407
3408     hres = IHTMLStyle_put_posLeft(style, 4.9f);
3409     ok(hres == S_OK, "put_posLeft failed: %08x\n", hres);
3410
3411     hres = IHTMLStyle_get_posLeft(style, &f);
3412     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3413     ok(f == 4.0 ||
3414        f == 4.9f, /* IE8 */
3415        "expected 4.0 or 4.9 (IE8) got %f\n", f);
3416
3417     /* Ensure left is updated correctly. */
3418     V_VT(&v) = VT_EMPTY;
3419     hres = IHTMLStyle_get_left(style, &v);
3420     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3421     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3422     ok(!strcmp_wa(V_BSTR(&v), "4px") ||
3423        !strcmp_wa(V_BSTR(&v), "4.9px"), /* IE8 */
3424        "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3425     VariantClear(&v);
3426
3427     /* Test left */
3428     V_VT(&v) = VT_BSTR;
3429     V_BSTR(&v) = a2bstr("3px");
3430     hres = IHTMLStyle_put_left(style, v);
3431     ok(hres == S_OK, "put_left failed: %08x\n", hres);
3432     VariantClear(&v);
3433
3434     hres = IHTMLStyle_get_posLeft(style, &f);
3435     ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3436     ok(f == 3.0, "expected 3.0 got %f\n", f);
3437
3438     V_VT(&v) = VT_EMPTY;
3439     hres = IHTMLStyle_get_left(style, &v);
3440     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3441     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3442     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3443     VariantClear(&v);
3444
3445     V_VT(&v) = VT_NULL;
3446     hres = IHTMLStyle_put_left(style, v);
3447     ok(hres == S_OK, "put_left failed: %08x\n", hres);
3448
3449     V_VT(&v) = VT_EMPTY;
3450     hres = IHTMLStyle_get_left(style, &v);
3451     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3452     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3453     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3454     VariantClear(&v);
3455
3456     V_VT(&v) = VT_EMPTY;
3457     hres = IHTMLStyle_get_top(style, &v);
3458     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3459     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3460     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3461     VariantClear(&v);
3462
3463     /* Test posTop */
3464     hres = IHTMLStyle_get_posTop(style, NULL);
3465     ok(hres == E_POINTER, "get_posTop failed: %08x\n", hres);
3466
3467     f = 1.0f;
3468     hres = IHTMLStyle_get_posTop(style, &f);
3469     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3470     ok(f == 0.0, "expected 0.0 got %f\n", f);
3471
3472     hres = IHTMLStyle_put_posTop(style, 4.9f);
3473     ok(hres == S_OK, "put_posTop failed: %08x\n", hres);
3474
3475     hres = IHTMLStyle_get_posTop(style, &f);
3476     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3477     ok(f == 4.0 ||
3478        f == 4.9f, /* IE8 */
3479        "expected 4.0 or 4.9 (IE8) got %f\n", f);
3480
3481     V_VT(&v) = VT_BSTR;
3482     V_BSTR(&v) = a2bstr("3px");
3483     hres = IHTMLStyle_put_top(style, v);
3484     ok(hres == S_OK, "put_top failed: %08x\n", hres);
3485     VariantClear(&v);
3486
3487     V_VT(&v) = VT_EMPTY;
3488     hres = IHTMLStyle_get_top(style, &v);
3489     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3490     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3491     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3492     VariantClear(&v);
3493
3494     hres = IHTMLStyle_get_posTop(style, &f);
3495     ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3496     ok(f == 3.0, "expected 3.0 got %f\n", f);
3497
3498     V_VT(&v) = VT_NULL;
3499     hres = IHTMLStyle_put_top(style, v);
3500     ok(hres == S_OK, "put_top failed: %08x\n", hres);
3501
3502     V_VT(&v) = VT_EMPTY;
3503     hres = IHTMLStyle_get_top(style, &v);
3504     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3505     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3506     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3507     VariantClear(&v);
3508
3509     /* Test posHeight */
3510     hres = IHTMLStyle_get_posHeight(style, NULL);
3511     ok(hres == E_POINTER, "get_posHeight failed: %08x\n", hres);
3512
3513     V_VT(&v) = VT_EMPTY;
3514     hres = IHTMLStyle_get_height(style, &v);
3515     ok(hres == S_OK, "get_height failed: %08x\n", hres);
3516     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3517     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3518     VariantClear(&v);
3519
3520     f = 1.0f;
3521     hres = IHTMLStyle_get_posHeight(style, &f);
3522     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3523     ok(f == 0.0, "expected 0.0 got %f\n", f);
3524
3525     hres = IHTMLStyle_put_posHeight(style, 4.9f);
3526     ok(hres == S_OK, "put_posHeight failed: %08x\n", hres);
3527
3528     hres = IHTMLStyle_get_posHeight(style, &f);
3529     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3530     ok(f == 4.0 ||
3531        f == 4.9f, /* IE8 */
3532        "expected 4.0 or 4.9 (IE8) got %f\n", f);
3533
3534     V_VT(&v) = VT_BSTR;
3535     V_BSTR(&v) = a2bstr("64px");
3536     hres = IHTMLStyle_put_height(style, v);
3537     ok(hres == S_OK, "put_height failed: %08x\n", hres);
3538     VariantClear(&v);
3539
3540     V_VT(&v) = VT_EMPTY;
3541     hres = IHTMLStyle_get_height(style, &v);
3542     ok(hres == S_OK, "get_height failed: %08x\n", hres);
3543     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3544     ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3545     VariantClear(&v);
3546
3547     hres = IHTMLStyle_get_posHeight(style, &f);
3548     ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3549     ok(f == 64.0, "expected 64.0 got %f\n", f);
3550
3551     str = (void*)0xdeadbeef;
3552     hres = IHTMLStyle_get_cursor(style, &str);
3553     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
3554     ok(!str, "get_cursor != NULL\n");
3555     SysFreeString(str);
3556
3557     str = a2bstr("default");
3558     hres = IHTMLStyle_put_cursor(style, str);
3559     ok(hres == S_OK, "put_cursor failed: %08x\n", hres);
3560     SysFreeString(str);
3561
3562     str = NULL;
3563     hres = IHTMLStyle_get_cursor(style, &str);
3564     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
3565     ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
3566     SysFreeString(str);
3567
3568     V_VT(&v) = VT_EMPTY;
3569     hres = IHTMLStyle_get_verticalAlign(style, &v);
3570     ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
3571     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3572     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3573     VariantClear(&v);
3574
3575     V_VT(&v) = VT_BSTR;
3576     V_BSTR(&v) = a2bstr("middle");
3577     hres = IHTMLStyle_put_verticalAlign(style, v);
3578     ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
3579     VariantClear(&v);
3580
3581     V_VT(&v) = VT_EMPTY;
3582     hres = IHTMLStyle_get_verticalAlign(style, &v);
3583     ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
3584     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3585     ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3586     VariantClear(&v);
3587
3588     str = (void*)0xdeadbeef;
3589     hres = IHTMLStyle_get_textAlign(style, &str);
3590     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
3591     ok(!str, "textAlign != NULL\n");
3592
3593     str = a2bstr("center");
3594     hres = IHTMLStyle_put_textAlign(style, str);
3595     ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
3596     SysFreeString(str);
3597
3598     str = NULL;
3599     hres = IHTMLStyle_get_textAlign(style, &str);
3600     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
3601     ok(!strcmp_wa(str, "center"), "textAlign = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3602     SysFreeString(str);
3603
3604     str = (void*)0xdeadbeef;
3605     hres = IHTMLStyle_get_filter(style, &str);
3606     ok(hres == S_OK, "get_filter failed: %08x\n", hres);
3607     ok(!str, "filter != NULL\n");
3608
3609     str = a2bstr("alpha(opacity=100)");
3610     hres = IHTMLStyle_put_filter(style, str);
3611     ok(hres == S_OK, "put_filter failed: %08x\n", hres);
3612     SysFreeString(str);
3613
3614     V_VT(&v) = VT_EMPTY;
3615     hres = IHTMLStyle_get_zIndex(style, &v);
3616     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
3617     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
3618     ok(!V_I4(&v), "V_I4(v) != 0\n");
3619     VariantClear(&v);
3620
3621     V_VT(&v) = VT_BSTR;
3622     V_BSTR(&v) = a2bstr("1");
3623     hres = IHTMLStyle_put_zIndex(style, v);
3624     ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
3625     VariantClear(&v);
3626
3627     V_VT(&v) = VT_EMPTY;
3628     hres = IHTMLStyle_get_zIndex(style, &v);
3629     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
3630     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
3631     ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
3632     VariantClear(&v);
3633
3634     /* fontStyle */
3635     hres = IHTMLStyle_get_fontStyle(style, &sDefault);
3636     ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
3637
3638     str = a2bstr("test");
3639     hres = IHTMLStyle_put_fontStyle(style, str);
3640     ok(hres == E_INVALIDARG, "put_fontStyle failed: %08x\n", hres);
3641     SysFreeString(str);
3642
3643     str = a2bstr("italic");
3644     hres = IHTMLStyle_put_fontStyle(style, str);
3645     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3646     SysFreeString(str);
3647
3648     str = a2bstr("oblique");
3649     hres = IHTMLStyle_put_fontStyle(style, str);
3650     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3651     SysFreeString(str);
3652
3653     str = a2bstr("normal");
3654     hres = IHTMLStyle_put_fontStyle(style, str);
3655     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3656     SysFreeString(str);
3657
3658     hres = IHTMLStyle_put_fontStyle(style, sDefault);
3659     ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3660     SysFreeString(sDefault);
3661
3662     /* overflow */
3663     hres = IHTMLStyle_get_overflow(style, NULL);
3664     ok(hres == E_INVALIDARG, "get_overflow failed: %08x\n", hres);
3665
3666     hres = IHTMLStyle_get_overflow(style, &sOverflowDefault);
3667     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3668
3669     str = a2bstr("test");
3670     hres = IHTMLStyle_put_overflow(style, str);
3671     ok(hres == E_INVALIDARG, "put_overflow failed: %08x\n", hres);
3672     SysFreeString(str);
3673
3674     str = a2bstr("visible");
3675     hres = IHTMLStyle_put_overflow(style, str);
3676     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3677     SysFreeString(str);
3678
3679     str = a2bstr("scroll");
3680     hres = IHTMLStyle_put_overflow(style, str);
3681     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3682     SysFreeString(str);
3683
3684     str = a2bstr("hidden");
3685     hres = IHTMLStyle_put_overflow(style, str);
3686     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3687     SysFreeString(str);
3688
3689     str = a2bstr("auto");
3690     hres = IHTMLStyle_put_overflow(style, str);
3691     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3692     SysFreeString(str);
3693
3694     hres = IHTMLStyle_get_overflow(style, &str);
3695     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3696     ok(!strcmp_wa(str, "auto"), "str=%s\n", wine_dbgstr_w(str));
3697     SysFreeString(str);
3698
3699     str = a2bstr("");
3700     hres = IHTMLStyle_put_overflow(style, str);
3701     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3702     SysFreeString(str);
3703
3704     hres = IHTMLStyle_get_overflow(style, &str);
3705     ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3706     ok(!str, "str=%s\n", wine_dbgstr_w(str));
3707     SysFreeString(str);
3708
3709     /* restore overflow default */
3710     hres = IHTMLStyle_put_overflow(style, sOverflowDefault);
3711     ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3712     SysFreeString(sOverflowDefault);
3713
3714     /* Attribute Tests*/
3715     hres = IHTMLStyle_getAttribute(style, NULL, 1, &v);
3716     ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
3717
3718     str = a2bstr("position");
3719     hres = IHTMLStyle_getAttribute(style, str, 1, NULL);
3720     ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
3721
3722     hres = IHTMLStyle_getAttribute(style, str, 1, &v);
3723     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
3724     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3725     VariantClear(&v);
3726
3727     hres = IHTMLStyle_setAttribute(style, NULL, v, 1);
3728     ok(hres == E_INVALIDARG, "setAttribute failed: %08x\n", hres);
3729
3730     V_VT(&v) = VT_BSTR;
3731     V_BSTR(&v) = a2bstr("absolute");
3732     hres = IHTMLStyle_setAttribute(style, str, v, 1);
3733     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3734     VariantClear(&v);
3735
3736     hres = IHTMLStyle_getAttribute(style, str, 1, &v);
3737     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
3738     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3739     ok(!strcmp_wa(V_BSTR(&v), "absolute"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3740     VariantClear(&v);
3741
3742     V_VT(&v) = VT_BSTR;
3743     V_BSTR(&v) = NULL;
3744     hres = IHTMLStyle_setAttribute(style, str, v, 1);
3745     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3746     VariantClear(&v);
3747
3748     SysFreeString(str);
3749
3750     str = a2bstr("borderLeftStyle");
3751     test_border_styles(style, str);
3752     SysFreeString(str);
3753
3754     str = a2bstr("borderbottomstyle");
3755     test_border_styles(style, str);
3756     SysFreeString(str);
3757
3758     str = a2bstr("borderrightstyle");
3759     test_border_styles(style, str);
3760     SysFreeString(str);
3761
3762     str = a2bstr("bordertopstyle");
3763     test_border_styles(style, str);
3764     SysFreeString(str);
3765
3766     hres = IHTMLStyle_get_borderStyle(style, &sDefault);
3767     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
3768
3769     str = a2bstr("none dotted dashed solid");
3770     hres = IHTMLStyle_put_borderStyle(style, str);
3771     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3772     SysFreeString(str);
3773
3774     str = a2bstr("none dotted dashed solid");
3775     hres = IHTMLStyle_get_borderStyle(style, &str);
3776     ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
3777     ok(!strcmp_wa(str, "none dotted dashed solid"),
3778         "expected (none dotted dashed solid) = (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
3779     SysFreeString(str);
3780
3781     str = a2bstr("double groove ridge inset");
3782     hres = IHTMLStyle_put_borderStyle(style, str);
3783     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3784     SysFreeString(str);
3785
3786     str = a2bstr("window-inset outset ridge inset");
3787     hres = IHTMLStyle_put_borderStyle(style, str);
3788     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3789     SysFreeString(str);
3790
3791     str = a2bstr("window-inset");
3792     hres = IHTMLStyle_put_borderStyle(style, str);
3793     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3794     SysFreeString(str);
3795
3796     str = a2bstr("none none none none none");
3797     hres = IHTMLStyle_put_borderStyle(style, str);
3798     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3799     SysFreeString(str);
3800
3801     str = a2bstr("invalid none none none");
3802     hres = IHTMLStyle_put_borderStyle(style, str);
3803     ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
3804     SysFreeString(str);
3805
3806     str = a2bstr("none invalid none none");
3807     hres = IHTMLStyle_put_borderStyle(style, str);
3808     ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
3809     SysFreeString(str);
3810
3811     hres = IHTMLStyle_put_borderStyle(style, sDefault);
3812     ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3813     SysFreeString(sDefault);
3814
3815     /* backgoundColor */
3816     hres = IHTMLStyle_get_backgroundColor(style, &v);
3817     ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
3818     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3819     ok(!V_BSTR(&v), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3820     VariantClear(&v);
3821
3822     /* PaddingLeft */
3823     hres = IHTMLStyle_get_paddingLeft(style, &vDefault);
3824     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
3825
3826     V_VT(&v) = VT_BSTR;
3827     V_BSTR(&v) = a2bstr("10");
3828     hres = IHTMLStyle_put_paddingLeft(style, v);
3829     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
3830     VariantClear(&v);
3831
3832     hres = IHTMLStyle_get_paddingLeft(style, &v);
3833     ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
3834     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expecte 10 = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3835
3836     hres = IHTMLStyle_put_paddingLeft(style, vDefault);
3837     ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
3838
3839     /* BackgroundRepeat */
3840     hres = IHTMLStyle_get_backgroundRepeat(style, &sDefault);
3841     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
3842
3843     str = a2bstr("invalid");
3844     hres = IHTMLStyle_put_backgroundRepeat(style, str);
3845     ok(hres == E_INVALIDARG, "put_backgroundRepeat failed: %08x\n", hres);
3846     SysFreeString(str);
3847
3848     str = a2bstr("repeat");
3849     hres = IHTMLStyle_put_backgroundRepeat(style, str);
3850     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3851     SysFreeString(str);
3852
3853     str = a2bstr("no-repeat");
3854     hres = IHTMLStyle_put_backgroundRepeat(style, str);
3855     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3856     SysFreeString(str);
3857
3858     str = a2bstr("repeat-x");
3859     hres = IHTMLStyle_put_backgroundRepeat(style, str);
3860     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3861     SysFreeString(str);
3862
3863     str = a2bstr("repeat-y");
3864     hres = IHTMLStyle_put_backgroundRepeat(style, str);
3865     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3866     SysFreeString(str);
3867
3868     hres = IHTMLStyle_get_backgroundRepeat(style, &str);
3869     ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
3870     ok(!strcmp_wa(str, "repeat-y"), "str=%s\n", wine_dbgstr_w(str));
3871     SysFreeString(str);
3872
3873     hres = IHTMLStyle_put_backgroundRepeat(style, sDefault);
3874     ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3875     SysFreeString(sDefault);
3876
3877     /* BorderColor */
3878     hres = IHTMLStyle_get_borderColor(style, &sDefault);
3879     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
3880
3881     str = a2bstr("red green red blue");
3882     hres = IHTMLStyle_put_borderColor(style, str);
3883     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
3884     SysFreeString(str);
3885
3886     hres = IHTMLStyle_get_borderColor(style, &str);
3887     ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
3888     ok(!strcmp_wa(str, "red green red blue"), "str=%s\n", wine_dbgstr_w(str));
3889     SysFreeString(str);
3890
3891     hres = IHTMLStyle_put_borderColor(style, sDefault);
3892     ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
3893     SysFreeString(sDefault);
3894
3895     /* BorderLeft */
3896     hres = IHTMLStyle_get_borderLeft(style, &sDefault);
3897     ok(hres == S_OK, "get_borderLeft failed: %08x\n", hres);
3898
3899     str = a2bstr("thick dotted red");
3900     hres = IHTMLStyle_put_borderLeft(style, str);
3901     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
3902     SysFreeString(str);
3903
3904     /* IHTMLStyle_get_borderLeft appears to have a bug where
3905         it returns the first letter of the color.  So we check
3906         each style individually.
3907      */
3908     V_BSTR(&v) = NULL;
3909     hres = IHTMLStyle_get_borderLeftColor(style, &v);
3910     todo_wine ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
3911     todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3912     VariantClear(&v);
3913
3914     V_BSTR(&v) = NULL;
3915     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
3916     ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
3917     ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3918     VariantClear(&v);
3919
3920     hres = IHTMLStyle_get_borderLeftStyle(style, &str);
3921     ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
3922     ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
3923     SysFreeString(str);
3924
3925     hres = IHTMLStyle_put_borderLeft(style, sDefault);
3926     ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
3927     SysFreeString(sDefault);
3928
3929     /* backgroundPositionX */
3930     hres = IHTMLStyle_get_backgroundPositionX(style, &vDefault);
3931     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
3932
3933     V_VT(&v) = VT_BSTR;
3934     V_BSTR(&v) = a2bstr("10px");
3935     hres = IHTMLStyle_put_backgroundPositionX(style, v);
3936     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
3937     VariantClear(&v);
3938
3939     hres = IHTMLStyle_get_backgroundPositionX(style, &v);
3940     ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
3941     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3942     VariantClear(&v);
3943
3944     hres = IHTMLStyle_put_backgroundPositionX(style, vDefault);
3945     ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
3946     VariantClear(&vDefault);
3947
3948     /* backgroundPositionY */
3949     hres = IHTMLStyle_get_backgroundPositionY(style, &vDefault);
3950     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
3951
3952     V_VT(&v) = VT_BSTR;
3953     V_BSTR(&v) = a2bstr("10px");
3954     hres = IHTMLStyle_put_backgroundPositionY(style, v);
3955     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
3956     VariantClear(&v);
3957
3958     hres = IHTMLStyle_get_backgroundPositionY(style, &v);
3959     ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
3960     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3961     VariantClear(&v);
3962
3963     hres = IHTMLStyle_put_backgroundPositionY(style, vDefault);
3964     ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
3965     VariantClear(&vDefault);
3966
3967      /* borderTopWidth */
3968     hres = IHTMLStyle_get_borderTopWidth(style, &vDefault);
3969     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
3970
3971     V_VT(&v) = VT_BSTR;
3972     V_BSTR(&v) = a2bstr("10px");
3973     hres = IHTMLStyle_put_borderTopWidth(style, v);
3974     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
3975     VariantClear(&v);
3976
3977     hres = IHTMLStyle_get_borderTopWidth(style, &v);
3978     ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
3979     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3980     VariantClear(&v);
3981
3982     hres = IHTMLStyle_put_borderTopWidth(style, vDefault);
3983     ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
3984     VariantClear(&vDefault);
3985
3986     /* borderRightWidth */
3987     hres = IHTMLStyle_get_borderRightWidth(style, &vDefault);
3988     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
3989
3990     V_VT(&v) = VT_BSTR;
3991     V_BSTR(&v) = a2bstr("10");
3992     hres = IHTMLStyle_put_borderRightWidth(style, v);
3993     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
3994     VariantClear(&v);
3995
3996     hres = IHTMLStyle_get_borderRightWidth(style, &v);
3997     ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
3998     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3999     VariantClear(&v);
4000
4001     hres = IHTMLStyle_put_borderRightWidth(style, vDefault);
4002     ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
4003     VariantClear(&vDefault);
4004
4005     /* borderBottomWidth */
4006     hres = IHTMLStyle_get_borderBottomWidth(style, &vDefault);
4007     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
4008
4009     V_VT(&v) = VT_BSTR;
4010     V_BSTR(&v) = a2bstr("10");
4011     hres = IHTMLStyle_put_borderBottomWidth(style, v);
4012     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
4013     VariantClear(&v);
4014
4015     hres = IHTMLStyle_get_borderBottomWidth(style, &v);
4016     ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
4017     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4018     VariantClear(&v);
4019
4020     hres = IHTMLStyle_put_borderBottomWidth(style, vDefault);
4021     ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
4022     VariantClear(&vDefault);
4023
4024     /* borderLeftWidth */
4025     hres = IHTMLStyle_get_borderLeftWidth(style, &vDefault);
4026     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
4027
4028     V_VT(&v) = VT_BSTR;
4029     V_BSTR(&v) = a2bstr("10");
4030     hres = IHTMLStyle_put_borderLeftWidth(style, v);
4031     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
4032     VariantClear(&v);
4033
4034     hres = IHTMLStyle_get_borderLeftWidth(style, &v);
4035     ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
4036     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4037     VariantClear(&v);
4038
4039     hres = IHTMLStyle_put_borderLeftWidth(style, vDefault);
4040     ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
4041     VariantClear(&vDefault);
4042
4043     /* wordSpacing */
4044     hres = IHTMLStyle_get_wordSpacing(style, &vDefault);
4045     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
4046
4047     V_VT(&v) = VT_BSTR;
4048     V_BSTR(&v) = a2bstr("10");
4049     hres = IHTMLStyle_put_wordSpacing(style, v);
4050     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
4051     VariantClear(&v);
4052
4053     hres = IHTMLStyle_get_wordSpacing(style, &v);
4054     ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
4055     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4056     ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4057     VariantClear(&v);
4058
4059     hres = IHTMLStyle_put_wordSpacing(style, vDefault);
4060     ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
4061     VariantClear(&vDefault);
4062
4063     /* letterSpacing */
4064     hres = IHTMLStyle_get_letterSpacing(style, &vDefault);
4065     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
4066
4067     V_VT(&v) = VT_BSTR;
4068     V_BSTR(&v) = a2bstr("11");
4069     hres = IHTMLStyle_put_letterSpacing(style, v);
4070     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
4071     VariantClear(&v);
4072
4073     hres = IHTMLStyle_get_letterSpacing(style, &v);
4074     ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
4075     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
4076     ok(!strcmp_wa(V_BSTR(&v), "11px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
4077     VariantClear(&v);
4078
4079     hres = IHTMLStyle_put_letterSpacing(style, vDefault);
4080     ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
4081     VariantClear(&vDefault);
4082
4083     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
4084     ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
4085     if(SUCCEEDED(hres)) {
4086         test_style2(style2);
4087         IHTMLStyle2_Release(style2);
4088     }
4089
4090     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle3, (void**)&style3);
4091     ok(hres == S_OK, "Could not get IHTMLStyle3 iface: %08x\n", hres);
4092     if(SUCCEEDED(hres)) {
4093         test_style3(style3);
4094         IHTMLStyle3_Release(style3);
4095     }
4096
4097     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle4, (void**)&style4);
4098     ok(hres == S_OK, "Could not get IHTMLStyle4 iface: %08x\n", hres);
4099     if(SUCCEEDED(hres)) {
4100         test_style4(style4);
4101         IHTMLStyle4_Release(style4);
4102     }
4103 }
4104
4105 static void test_set_csstext(IHTMLStyle *style)
4106 {
4107     VARIANT v;
4108     HRESULT hres;
4109
4110     test_style_set_csstext(style, "background-color: black;");
4111
4112     hres = IHTMLStyle_get_backgroundColor(style, &v);
4113     ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
4114     ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
4115     ok(!strcmp_wa(V_BSTR(&v), "black"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
4116     VariantClear(&v);
4117 }
4118
4119 static void test_default_selection(IHTMLDocument2 *doc)
4120 {
4121     IHTMLSelectionObject *selection;
4122     IHTMLTxtRange *range;
4123     IDispatch *disp;
4124     BSTR str;
4125     HRESULT hres;
4126
4127     hres = IHTMLDocument2_get_selection(doc, &selection);
4128     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
4129
4130     hres = IHTMLSelectionObject_get_type(selection, &str);
4131     ok(hres == S_OK, "get_type failed: %08x\n", hres);
4132     ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
4133     SysFreeString(str);
4134
4135     hres = IHTMLSelectionObject_createRange(selection, &disp);
4136     IHTMLSelectionObject_Release(selection);
4137     ok(hres == S_OK, "createRange failed: %08x\n", hres);
4138
4139     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
4140     IDispatch_Release(disp);
4141     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
4142
4143     test_range_text(range, NULL);
4144     IHTMLTxtRange_Release(range);
4145 }
4146
4147 static void test_default_body(IHTMLBodyElement *body)
4148 {
4149     LONG l;
4150     BSTR bstr;
4151     HRESULT hres;
4152     VARIANT v;
4153     WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
4154     WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
4155
4156     bstr = (void*)0xdeadbeef;
4157     hres = IHTMLBodyElement_get_background(body, &bstr);
4158     ok(hres == S_OK, "get_background failed: %08x\n", hres);
4159     ok(bstr == NULL, "bstr != NULL\n");
4160
4161     l = elem_get_scroll_height((IUnknown*)body);
4162     ok(l != -1, "scrollHeight == -1\n");
4163     l = elem_get_scroll_width((IUnknown*)body);
4164     ok(l != -1, "scrollWidth == -1\n");
4165     l = elem_get_scroll_top((IUnknown*)body);
4166     ok(!l, "scrollTop = %d\n", l);
4167     elem_get_scroll_left((IUnknown*)body);
4168
4169     /* get_text tests */
4170     hres = IHTMLBodyElement_get_text(body, &v);
4171     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4172     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4173     ok(bstr == NULL, "bstr != NULL\n");
4174
4175
4176     /* get_text - Invalid Text */
4177     V_VT(&v) = VT_BSTR;
4178     V_BSTR(&v) = SysAllocString(sTextInvalid);
4179     hres = IHTMLBodyElement_put_text(body, v);
4180     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4181     VariantClear(&v);
4182
4183     V_VT(&v) = VT_NULL;
4184     hres = IHTMLBodyElement_get_text(body, &v);
4185     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4186     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4187     ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v != '#00a0d0'\n");
4188     VariantClear(&v);
4189
4190     /* get_text - Valid Text */
4191     V_VT(&v) = VT_BSTR;
4192     V_BSTR(&v) = SysAllocString(sBodyText);
4193     hres = IHTMLBodyElement_put_text(body, v);
4194     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4195     VariantClear(&v);
4196
4197     V_VT(&v) = VT_NULL;
4198     hres = IHTMLBodyElement_get_text(body, &v);
4199     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4200     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4201     ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v != '#ff0000'\n");
4202     VariantClear(&v);
4203 }
4204
4205 static void test_body_funs(IHTMLBodyElement *body)
4206 {
4207     static WCHAR sRed[] = {'r','e','d',0};
4208     VARIANT vbg;
4209     VARIANT vDefaultbg;
4210     HRESULT hres;
4211
4212     hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
4213     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4214     ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
4215
4216     V_VT(&vbg) = VT_BSTR;
4217     V_BSTR(&vbg) = SysAllocString(sRed);
4218     hres = IHTMLBodyElement_put_bgColor(body, vbg);
4219     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4220     VariantClear(&vbg);
4221
4222     hres = IHTMLBodyElement_get_bgColor(body, &vbg);
4223     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4224     ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
4225     ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
4226     VariantClear(&vbg);
4227
4228     /* Restore Originial */
4229     hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
4230     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4231     VariantClear(&vDefaultbg);
4232 }
4233
4234 static void test_window(IHTMLDocument2 *doc)
4235 {
4236     IHTMLWindow2 *window, *window2, *self;
4237     IHTMLDocument2 *doc2 = NULL;
4238     IDispatch *disp;
4239     IUnknown *unk;
4240     BSTR str;
4241     HRESULT hres;
4242
4243     hres = IHTMLDocument2_get_parentWindow(doc, &window);
4244     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4245     test_ifaces((IUnknown*)window, window_iids);
4246     test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
4247
4248     hres = IHTMLWindow2_get_document(window, &doc2);
4249     ok(hres == S_OK, "get_document failed: %08x\n", hres);
4250     ok(doc2 != NULL, "doc2 == NULL\n");
4251
4252     test_ifaces((IUnknown*)doc2, doc_node_iids);
4253     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4254
4255     test_ifaces((IUnknown*)doc, doc_obj_iids);
4256     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4257
4258     unk = (void*)0xdeadbeef;
4259     hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
4260     ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
4261     ok(!unk, "unk = %p\n", unk);
4262
4263     IHTMLDocument_Release(doc2);
4264
4265     hres = IHTMLWindow2_get_window(window, &window2);
4266     ok(hres == S_OK, "get_window failed: %08x\n", hres);
4267     ok(window2 != NULL, "window2 == NULL\n");
4268
4269     hres = IHTMLWindow2_get_self(window, &self);
4270     ok(hres == S_OK, "get_self failed: %08x\n", hres);
4271     ok(window2 != NULL, "self == NULL\n");
4272
4273     ok(self == window2, "self != window2\n");
4274
4275     IHTMLWindow2_Release(window2);
4276     IHTMLWindow2_Release(self);
4277
4278     disp = NULL;
4279     hres = IHTMLDocument2_get_Script(doc, &disp);
4280     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4281     ok(disp == (void*)window, "disp != window\n");
4282     IDispatch_Release(disp);
4283
4284     hres = IHTMLWindow2_toString(window, NULL);
4285     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4286
4287     str = NULL;
4288     hres = IHTMLWindow2_toString(window, &str);
4289     ok(hres == S_OK, "toString failed: %08x\n", hres);
4290     ok(!strcmp_wa(str, "[object]"), "toString returned %s\n", wine_dbgstr_w(str));
4291     SysFreeString(str);
4292
4293     IHTMLWindow2_Release(window);
4294 }
4295
4296 static void test_defaults(IHTMLDocument2 *doc)
4297 {
4298     IHTMLStyleSheetsCollection *stylesheetcol;
4299     IHTMLCurrentStyle *cstyle;
4300     IHTMLBodyElement *body;
4301     IHTMLElement2 *elem2;
4302     IHTMLElement *elem;
4303     IHTMLStyle *style;
4304     LONG l;
4305     HRESULT hres;
4306     IHTMLElementCollection *collection;
4307
4308     hres = IHTMLDocument2_get_body(doc, &elem);
4309     ok(hres == S_OK, "get_body failed: %08x\n", hres);
4310
4311     hres = IHTMLDocument2_get_images(doc, NULL);
4312     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4313
4314     hres = IHTMLDocument2_get_images(doc, &collection);
4315     ok(hres == S_OK, "get_images failed: %08x\n", hres);
4316     if(hres == S_OK)
4317     {
4318         test_elem_collection((IUnknown*)collection, NULL, 0);
4319         IHTMLElementCollection_Release(collection);
4320     }
4321
4322     hres = IHTMLDocument2_get_applets(doc, NULL);
4323     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4324
4325     hres = IHTMLDocument2_get_applets(doc, &collection);
4326     ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4327     if(hres == S_OK)
4328     {
4329         test_elem_collection((IUnknown*)collection, NULL, 0);
4330         IHTMLElementCollection_Release(collection);
4331     }
4332
4333     hres = IHTMLDocument2_get_links(doc, NULL);
4334     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4335
4336     hres = IHTMLDocument2_get_links(doc, &collection);
4337     ok(hres == S_OK, "get_links failed: %08x\n", hres);
4338     if(hres == S_OK)
4339     {
4340         test_elem_collection((IUnknown*)collection, NULL, 0);
4341         IHTMLElementCollection_Release(collection);
4342     }
4343
4344     hres = IHTMLDocument2_get_forms(doc, NULL);
4345     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4346
4347     hres = IHTMLDocument2_get_forms(doc, &collection);
4348     ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4349     if(hres == S_OK)
4350     {
4351         test_elem_collection((IUnknown*)collection, NULL, 0);
4352         IHTMLElementCollection_Release(collection);
4353     }
4354
4355     hres = IHTMLDocument2_get_anchors(doc, NULL);
4356     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4357
4358     hres = IHTMLDocument2_get_anchors(doc, &collection);
4359     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4360     if(hres == S_OK)
4361     {
4362         test_elem_collection((IUnknown*)collection, NULL, 0);
4363         IHTMLElementCollection_Release(collection);
4364     }
4365
4366     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4367     ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
4368     test_default_body(body);
4369     test_body_funs(body);
4370     IHTMLBodyElement_Release(body);
4371
4372     hres = IHTMLElement_get_style(elem, &style);
4373     ok(hres == S_OK, "get_style failed: %08x\n", hres);
4374
4375     test_default_style(style);
4376     test_window(doc);
4377     test_compatmode(doc);
4378     test_location(doc);
4379     test_navigator(doc);
4380
4381     elem2 = get_elem2_iface((IUnknown*)elem);
4382     hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
4383     ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
4384     if(SUCCEEDED(hres)) {
4385         test_current_style(cstyle);
4386         IHTMLCurrentStyle_Release(cstyle);
4387     }
4388     IHTMLElement2_Release(elem2);
4389
4390     IHTMLElement_Release(elem);
4391
4392     test_set_csstext(style);
4393     IHTMLStyle_Release(style);
4394
4395     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
4396     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4397
4398     l = 0xdeadbeef;
4399     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
4400     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4401     ok(l == 0, "length = %d\n", l);
4402
4403     IHTMLStyleSheetsCollection_Release(stylesheetcol);
4404
4405     test_default_selection(doc);
4406     test_doc_title(doc, "");
4407 }
4408
4409 static void test_tr_elem(IHTMLElement *elem)
4410 {
4411     IHTMLElementCollection *col;
4412     IHTMLTableRow *row;
4413     HRESULT hres;
4414
4415     static const elem_type_t cell_types[] = {ET_TD,ET_TD};
4416
4417     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
4418     ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
4419     if(FAILED(hres))
4420         return;
4421
4422     col = NULL;
4423     hres = IHTMLTableRow_get_cells(row, &col);
4424     ok(hres == S_OK, "get_cells failed: %08x\n", hres);
4425     ok(col != NULL, "get_cells returned NULL\n");
4426
4427     test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
4428     IHTMLElementCollection_Release(col);
4429
4430     IHTMLTable_Release(row);
4431 }
4432
4433 static void test_table_elem(IHTMLElement *elem)
4434 {
4435     IHTMLElementCollection *col;
4436     IHTMLTable *table;
4437     HRESULT hres;
4438
4439     static const elem_type_t row_types[] = {ET_TR,ET_TR};
4440
4441     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
4442     ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
4443     if(FAILED(hres))
4444         return;
4445
4446     col = NULL;
4447     hres = IHTMLTable_get_rows(table, &col);
4448     ok(hres == S_OK, "get_rows failed: %08x\n", hres);
4449     ok(col != NULL, "get_ros returned NULL\n");
4450
4451     test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
4452     IHTMLElementCollection_Release(col);
4453
4454     IHTMLTable_Release(table);
4455 }
4456
4457 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
4458 {
4459     SAFEARRAYBOUND dim;
4460     SAFEARRAY *sa;
4461     VARIANT *var;
4462     BSTR str;
4463     HRESULT hres;
4464
4465     dim.lLbound = 0;
4466     dim.cElements = 1;
4467     sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4468     SafeArrayAccessData(sa, (void**)&var);
4469     V_VT(var) = VT_BSTR;
4470     V_BSTR(var) = str = a2bstr(text);
4471     SafeArrayUnaccessData(sa);
4472
4473     if(ln)
4474         hres = IHTMLDocument2_writeln(doc, sa);
4475     else
4476         hres = IHTMLDocument2_write(doc, sa);
4477     ok(hres == S_OK, "write failed: %08x\n", hres);
4478
4479     SysFreeString(str);
4480     SafeArrayDestroy(sa);
4481 }
4482
4483 static void test_iframe_elem(IHTMLElement *elem)
4484 {
4485     IHTMLElementCollection *col;
4486     IHTMLDocument2 *content_doc;
4487     IHTMLWindow2 *content_window;
4488     IHTMLFrameBase2 *base2;
4489     IDispatch *disp;
4490     VARIANT errv;
4491     BSTR str;
4492     HRESULT hres;
4493
4494     static const elem_type_t all_types[] = {
4495         ET_HTML,
4496         ET_HEAD,
4497         ET_TITLE,
4498         ET_BODY,
4499         ET_BR
4500     };
4501
4502     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
4503     ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
4504     if (!base2) return;
4505
4506     content_window = NULL;
4507     hres = IHTMLFrameBase2_get_contentWindow(base2, &content_window);
4508     IHTMLFrameBase2_Release(base2);
4509     ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
4510     ok(content_window != NULL, "contentWindow = NULL\n");
4511
4512     content_doc = NULL;
4513     hres = IHTMLWindow2_get_document(content_window, &content_doc);
4514     IHTMLWindow2_Release(content_window);
4515     ok(hres == S_OK, "get_document failed: %08x\n", hres);
4516     ok(content_doc != NULL, "content_doc = NULL\n");
4517
4518     str = a2bstr("text/html");
4519     V_VT(&errv) = VT_ERROR;
4520     disp = NULL;
4521     hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
4522     SysFreeString(str);
4523     ok(hres == S_OK, "open failed: %08x\n", hres);
4524     ok(disp != NULL, "disp == NULL\n");
4525     ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
4526     IDispatch_Release(disp);
4527
4528     doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
4529     doc_write(content_doc, TRUE, "</html>");
4530
4531     hres = IHTMLDocument2_get_all(content_doc, &col);
4532     ok(hres == S_OK, "get_all failed: %08x\n", hres);
4533     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4534     IHTMLElementCollection_Release(col);
4535
4536     hres = IHTMLDocument2_close(content_doc);
4537     ok(hres == S_OK, "close failed: %08x\n", hres);
4538
4539     IHTMLDocument2_Release(content_doc);
4540 }
4541
4542 static void test_stylesheet(IDispatch *disp)
4543 {
4544     IHTMLStyleSheetRulesCollection *col = NULL;
4545     IHTMLStyleSheet *stylesheet;
4546     HRESULT hres;
4547
4548     hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
4549     ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
4550
4551     hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
4552     ok(hres == S_OK, "get_rules failed: %08x\n", hres);
4553     ok(col != NULL, "col == NULL\n");
4554
4555     IHTMLStyleSheetRulesCollection_Release(col);
4556     IHTMLStyleSheet_Release(stylesheet);
4557 }
4558
4559 static void test_stylesheets(IHTMLDocument2 *doc)
4560 {
4561     IHTMLStyleSheetsCollection *col = NULL;
4562     VARIANT idx, res;
4563     LONG len = 0;
4564     HRESULT hres;
4565
4566     hres = IHTMLDocument2_get_styleSheets(doc, &col);
4567     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4568     ok(col != NULL, "col == NULL\n");
4569
4570     hres = IHTMLStyleSheetsCollection_get_length(col, &len);
4571     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4572     ok(len == 1, "len=%d\n", len);
4573
4574     VariantInit(&res);
4575     V_VT(&idx) = VT_I4;
4576     V_I4(&idx) = 0;
4577
4578     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4579     ok(hres == S_OK, "item failed: %08x\n", hres);
4580     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
4581     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4582     test_stylesheet(V_DISPATCH(&res));
4583     VariantClear(&res);
4584
4585     V_VT(&res) = VT_I4;
4586     V_VT(&idx) = VT_I4;
4587     V_I4(&idx) = 1;
4588
4589     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4590     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4591     ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
4592     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4593     VariantClear(&res);
4594
4595     IHTMLStyleSheetsCollection_Release(col);
4596 }
4597
4598 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
4599 {
4600     IDispatchEx *dispex;
4601     IHTMLDOMNode *node;
4602     DISPPARAMS dp = {NULL, NULL, 0, 0};
4603     VARIANT var;
4604     EXCEPINFO ei;
4605     LONG type;
4606     DISPID id;
4607     BSTR bstr;
4608     HRESULT hres;
4609
4610     static const WCHAR w0[] = {'0',0};
4611     static const WCHAR w100[] = {'1','0','0',0};
4612
4613     hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
4614     ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
4615
4616     bstr = SysAllocString(w0);
4617     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4618     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
4619     SysFreeString(bstr);
4620
4621     VariantInit(&var);
4622     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
4623     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
4624     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
4625     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
4626     node = get_node_iface((IUnknown*)V_DISPATCH(&var));
4627     type = get_node_type((IUnknown*)node);
4628     ok(type == 3, "type=%d\n", type);
4629     IHTMLDOMNode_Release(node);
4630     VariantClear(&var);
4631
4632     bstr = SysAllocString(w100);
4633     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4634     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
4635     SysFreeString(bstr);
4636
4637     IDispatchEx_Release(dispex);
4638 }
4639
4640
4641
4642 static void test_elems(IHTMLDocument2 *doc)
4643 {
4644     IHTMLElementCollection *col;
4645     IHTMLDOMChildrenCollection *child_col;
4646     IHTMLElement *elem, *elem2, *elem3;
4647     IHTMLDOMNode *node, *node2;
4648     IDispatch *disp;
4649     LONG type;
4650     HRESULT hres;
4651     IHTMLElementCollection *collection;
4652     IHTMLDocument3 *doc3;
4653     BSTR str;
4654
4655     static const elem_type_t all_types[] = {
4656         ET_HTML,
4657         ET_HEAD,
4658         ET_TITLE,
4659         ET_STYLE,
4660         ET_BODY,
4661         ET_COMMENT,
4662         ET_A,
4663         ET_INPUT,
4664         ET_SELECT,
4665         ET_OPTION,
4666         ET_OPTION,
4667         ET_TEXTAREA,
4668         ET_TABLE,
4669         ET_TBODY,
4670         ET_TR,
4671         ET_TR,
4672         ET_TD,
4673         ET_TD,
4674         ET_SCRIPT,
4675         ET_TEST,
4676         ET_IMG,
4677         ET_IFRAME
4678     };
4679
4680     static const elem_type_t item_types[] = {
4681         ET_A,
4682         ET_OPTION,
4683         ET_TEXTAREA
4684     };
4685
4686     hres = IHTMLDocument2_get_all(doc, &col);
4687     ok(hres == S_OK, "get_all failed: %08x\n", hres);
4688     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4689     test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
4690     IHTMLElementCollection_Release(col);
4691
4692     hres = IHTMLDocument2_get_images(doc, &collection);
4693     ok(hres == S_OK, "get_images failed: %08x\n", hres);
4694     if(hres == S_OK)
4695     {
4696         static const elem_type_t images_types[] = {ET_IMG};
4697         test_elem_collection((IUnknown*)collection, images_types, 1);
4698
4699         IHTMLElementCollection_Release(collection);
4700     }
4701
4702     hres = IHTMLDocument2_get_links(doc, &collection);
4703     ok(hres == S_OK, "get_links failed: %08x\n", hres);
4704     if(hres == S_OK)
4705     {
4706         static const elem_type_t images_types[] = {ET_A};
4707         test_elem_collection((IUnknown*)collection, images_types, 1);
4708
4709         IHTMLElementCollection_Release(collection);
4710     }
4711
4712     hres = IHTMLDocument2_get_anchors(doc, &collection);
4713     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4714     if(hres == S_OK)
4715     {
4716         static const elem_type_t anchor_types[] = {ET_A};
4717         test_elem_collection((IUnknown*)collection, anchor_types, 1);
4718
4719         IHTMLElementCollection_Release(collection);
4720     }
4721
4722     elem = get_doc_elem(doc);
4723     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4724     hres = IHTMLElement_get_all(elem, &disp);
4725     IHTMLElement_Release(elem);
4726     ok(hres == S_OK, "get_all failed: %08x\n", hres);
4727
4728     hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
4729     IDispatch_Release(disp);
4730     ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
4731     test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
4732     IHTMLElementCollection_Release(col);
4733
4734     get_elem_by_id(doc, "xxx", FALSE);
4735     elem = get_doc_elem_by_id(doc, "xxx");
4736     ok(!elem, "elem != NULL\n");
4737
4738     elem = get_doc_elem_by_id(doc, "s");
4739     ok(elem != NULL, "elem == NULL\n");
4740     if(elem) {
4741         test_elem_type((IUnknown*)elem, ET_SELECT);
4742         test_elem_attr(elem, "xxx", NULL);
4743         test_elem_attr(elem, "id", "s");
4744         test_elem_class((IUnknown*)elem, NULL);
4745         test_elem_set_class((IUnknown*)elem, "cl");
4746         test_elem_set_class((IUnknown*)elem, NULL);
4747         test_elem_tabindex((IUnknown*)elem, 0);
4748         test_elem_set_tabindex((IUnknown*)elem, 1);
4749
4750         node = test_node_get_parent((IUnknown*)elem);
4751         ok(node != NULL, "node == NULL\n");
4752         test_node_name((IUnknown*)node, "BODY");
4753         node2 = test_node_get_parent((IUnknown*)node);
4754         IHTMLDOMNode_Release(node);
4755         ok(node2 != NULL, "node == NULL\n");
4756         test_node_name((IUnknown*)node2, "HTML");
4757         node = test_node_get_parent((IUnknown*)node2);
4758         IHTMLDOMNode_Release(node2);
4759         ok(node != NULL, "node == NULL\n");
4760         if (node)
4761         {
4762             test_node_name((IUnknown*)node, "#document");
4763             type = get_node_type((IUnknown*)node);
4764             ok(type == 9, "type=%d, expected 9\n", type);
4765             node2 = test_node_get_parent((IUnknown*)node);
4766             IHTMLDOMNode_Release(node);
4767             ok(node2 == NULL, "node != NULL\n");
4768         }
4769
4770         elem2 = test_elem_get_parent((IUnknown*)elem);
4771         ok(elem2 != NULL, "elem2 == NULL\n");
4772         test_node_name((IUnknown*)elem2, "BODY");
4773         elem3 = test_elem_get_parent((IUnknown*)elem2);
4774         IHTMLElement_Release(elem2);
4775         ok(elem3 != NULL, "elem3 == NULL\n");
4776         test_node_name((IUnknown*)elem3, "HTML");
4777         elem2 = test_elem_get_parent((IUnknown*)elem3);
4778         IHTMLElement_Release(elem3);
4779         ok(elem2 == NULL, "elem2 != NULL\n");
4780
4781         test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
4782         test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
4783         test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
4784
4785         test_elem_innertext(elem, "opt1opt2");
4786
4787         IHTMLElement_Release(elem);
4788     }
4789
4790     elem = get_elem_by_id(doc, "s", TRUE);
4791     if(elem) {
4792         IHTMLSelectElement *select;
4793         IHTMLDocument2 *doc_node;
4794
4795         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
4796         ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
4797
4798         test_select_elem(select);
4799
4800         test_elem_title((IUnknown*)select, NULL);
4801         test_elem_set_title((IUnknown*)select, "Title");
4802         test_elem_title((IUnknown*)select, "Title");
4803         test_elem_offset((IUnknown*)select);
4804
4805         node = get_first_child((IUnknown*)select);
4806         ok(node != NULL, "node == NULL\n");
4807         if(node) {
4808             test_elem_type((IUnknown*)node, ET_OPTION);
4809             IHTMLDOMNode_Release(node);
4810         }
4811
4812         type = get_node_type((IUnknown*)select);
4813         ok(type == 1, "type=%d\n", type);
4814
4815         IHTMLSelectElement_Release(select);
4816
4817         hres = IHTMLElement_get_document(elem, &disp);
4818         ok(hres == S_OK, "get_document failed: %08x\n", hres);
4819
4820         doc_node = get_doc_node(doc);
4821         ok(iface_cmp((IUnknown*)disp, (IUnknown*)doc_node), "disp != doc\n");
4822         IHTMLDocument2_Release(doc_node);
4823
4824         IHTMLElement_Release(elem);
4825     }
4826
4827     elem = get_elem_by_id(doc, "sc", TRUE);
4828     if(elem) {
4829         IHTMLScriptElement *script;
4830         BSTR type;
4831
4832         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
4833         ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
4834
4835         if(hres == S_OK)
4836         {
4837             VARIANT_BOOL vb;
4838
4839             hres = IHTMLScriptElement_get_type(script, &type);
4840             ok(hres == S_OK, "get_type failed: %08x\n", hres);
4841             ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
4842             SysFreeString(type);
4843
4844             /* test defer */
4845             hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
4846             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
4847
4848             hres = IHTMLScriptElement_get_defer(script, &vb);
4849             ok(hres == S_OK, "get_defer failed: %08x\n", hres);
4850             ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
4851
4852             hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
4853             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
4854         }
4855
4856         IHTMLScriptElement_Release(script);
4857     }
4858
4859     elem = get_elem_by_id(doc, "in", TRUE);
4860     if(elem) {
4861         IHTMLInputElement *input;
4862
4863         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
4864         ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4865
4866         test_elem_id((IUnknown*)elem, "in");
4867         test_elem_put_id((IUnknown*)elem, "newin");
4868         test_input_get_disabled(input, VARIANT_FALSE);
4869         test_input_set_disabled(input, VARIANT_TRUE);
4870         test_input_set_disabled(input, VARIANT_FALSE);
4871         test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
4872         test_input_get_disabled(input, VARIANT_TRUE);
4873         test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
4874         test_input_get_disabled(input, VARIANT_FALSE);
4875         test_elem_client_size((IUnknown*)elem);
4876
4877         test_node_get_value_str((IUnknown*)elem, NULL);
4878         test_node_put_value_str((IUnknown*)elem, "test");
4879         test_node_get_value_str((IUnknown*)elem, NULL);
4880         test_input_value((IUnknown*)elem, NULL);
4881         test_input_put_value((IUnknown*)elem, "test");
4882         test_input_value((IUnknown*)elem, NULL);
4883         test_elem_class((IUnknown*)elem, "testclass");
4884         test_elem_tabindex((IUnknown*)elem, 2);
4885         test_elem_set_tabindex((IUnknown*)elem, 3);
4886         test_elem_title((IUnknown*)elem, "test title");
4887
4888         test_input_get_defaultchecked(input, VARIANT_FALSE);
4889         test_input_set_defaultchecked(input, VARIANT_TRUE);
4890         test_input_set_defaultchecked(input, VARIANT_FALSE);
4891
4892         test_input_get_checked(input, VARIANT_FALSE);
4893         test_input_set_checked(input, VARIANT_TRUE);
4894         test_input_set_checked(input, VARIANT_FALSE);
4895
4896         test_input_src(input, NULL);
4897         test_input_set_src(input, "about:blank");
4898
4899         IHTMLInputElement_Release(input);
4900         IHTMLElement_Release(elem);
4901     }
4902
4903     elem = get_elem_by_id(doc, "imgid", TRUE);
4904     if(elem) {
4905         test_img_src((IUnknown*)elem, "");
4906         test_img_set_src((IUnknown*)elem, "about:blank");
4907         test_img_alt((IUnknown*)elem, NULL);
4908         test_img_set_alt((IUnknown*)elem, "alt test");
4909         IHTMLElement_Release(elem);
4910     }
4911
4912     elem = get_doc_elem_by_id(doc, "tbl");
4913     ok(elem != NULL, "elem == NULL\n");
4914     if(elem) {
4915         test_table_elem(elem);
4916         IHTMLElement_Release(elem);
4917     }
4918
4919     elem = get_doc_elem_by_id(doc, "row2");
4920     ok(elem != NULL, "elem == NULL\n");
4921     if(elem) {
4922         test_tr_elem(elem);
4923         IHTMLElement_Release(elem);
4924     }
4925
4926     elem = get_doc_elem_by_id(doc, "ifr");
4927     ok(elem != NULL, "elem == NULL\n");
4928     if(elem) {
4929         test_iframe_elem(elem);
4930         IHTMLElement_Release(elem);
4931     }
4932
4933     hres = IHTMLDocument2_get_body(doc, &elem);
4934     ok(hres == S_OK, "get_body failed: %08x\n", hres);
4935
4936     node = get_first_child((IUnknown*)elem);
4937     ok(node != NULL, "node == NULL\n");
4938     if(node) {
4939         test_ifaces((IUnknown*)node, text_iids);
4940         test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
4941
4942         node2 = get_first_child((IUnknown*)node);
4943         ok(!node2, "node2 != NULL\n");
4944
4945         type = get_node_type((IUnknown*)node);
4946         ok(type == 3, "type=%d\n", type);
4947
4948         test_node_get_value_str((IUnknown*)node, "text test");
4949         test_node_put_value_str((IUnknown*)elem, "test text");
4950         test_node_get_value_str((IUnknown*)node, "text test");
4951
4952         IHTMLDOMNode_Release(node);
4953     }
4954
4955     child_col = get_child_nodes((IUnknown*)elem);
4956     ok(child_col != NULL, "child_coll == NULL\n");
4957     if(child_col) {
4958         LONG length = 0;
4959
4960         test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
4961
4962         hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
4963         ok(hres == S_OK, "get_length failed: %08x\n", hres);
4964         ok(length, "length=0\n");
4965
4966         node = get_child_item(child_col, 0);
4967         ok(node != NULL, "node == NULL\n");
4968         if(node) {
4969             type = get_node_type((IUnknown*)node);
4970             ok(type == 3, "type=%d\n", type);
4971             IHTMLDOMNode_Release(node);
4972         }
4973
4974         node = get_child_item(child_col, 1);
4975         ok(node != NULL, "node == NULL\n");
4976         if(node) {
4977             type = get_node_type((IUnknown*)node);
4978             ok(type == 8, "type=%d\n", type);
4979
4980             test_elem_id((IUnknown*)node, NULL);
4981             IHTMLDOMNode_Release(node);
4982         }
4983
4984         hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
4985         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
4986
4987         hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
4988         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
4989
4990         hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
4991         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4992
4993         hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
4994         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4995
4996         test_child_col_disp(child_col);
4997
4998         IHTMLDOMChildrenCollection_Release(child_col);
4999     }
5000
5001     test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
5002     test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
5003     test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
5004
5005     IHTMLElement_Release(elem);
5006
5007     test_stylesheets(doc);
5008     test_create_option_elem(doc);
5009
5010     elem = get_doc_elem_by_id(doc, "tbl");
5011     ok(elem != NULL, "elem = NULL\n");
5012     test_elem_set_innertext(elem, "inner text");
5013     IHTMLElement_Release(elem);
5014
5015     test_doc_title(doc, "test");
5016     test_doc_set_title(doc, "test title");
5017     test_doc_title(doc, "test title");
5018
5019     disp = NULL;
5020     hres = IHTMLDocument2_get_Script(doc, &disp);
5021     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5022     if(hres == S_OK)
5023     {
5024         IDispatchEx *dispex;
5025         hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
5026         ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
5027         if(hres == S_OK)
5028         {
5029             DISPID pid = -1;
5030             BSTR str = a2bstr("Testing");
5031             hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
5032             ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5033             ok(pid != -1, "pid == -1\n");
5034             SysFreeString(str);
5035             IDispatchEx_Release(dispex);
5036         }
5037     }
5038     IDispatch_Release(disp);
5039
5040     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5041     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5042
5043     str = a2bstr("img");
5044     hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
5045     ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
5046     SysFreeString(str);
5047     if(hres == S_OK)
5048     {
5049         static const elem_type_t img_types[] = { ET_IMG };
5050
5051         test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
5052         IHTMLElementCollection_Release(col);
5053     }
5054
5055     elem = get_doc_elem_by_id(doc, "y");
5056     test_elem_set_innerhtml((IUnknown*)elem, "inner html");
5057     test_elem_innerhtml((IUnknown*)elem, "inner html");
5058     test_elem_set_innerhtml((IUnknown*)elem, "");
5059     test_elem_innerhtml((IUnknown*)elem, NULL);
5060     IHTMLElement_Release(elem);
5061
5062     IHTMLDocument3_Release(doc3);
5063 }
5064
5065 static void test_create_elems(IHTMLDocument2 *doc)
5066 {
5067     IHTMLElement *elem, *body, *elem2;
5068     IHTMLDOMNode *node, *node2, *node3, *comment;
5069     IHTMLDocument5 *doc5;
5070     IDispatch *disp;
5071     VARIANT var;
5072     LONG type;
5073     HRESULT hres;
5074     BSTR str;
5075
5076     static const elem_type_t types1[] = { ET_TESTG };
5077
5078     elem = test_create_elem(doc, "TEST");
5079     test_elem_tag((IUnknown*)elem, "TEST");
5080     type = get_node_type((IUnknown*)elem);
5081     ok(type == 1, "type=%d\n", type);
5082     test_ifaces((IUnknown*)elem, elem_iids);
5083     test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
5084
5085     hres = IHTMLDocument2_get_body(doc, &body);
5086     ok(hres == S_OK, "get_body failed: %08x\n", hres);
5087     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5088
5089     node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
5090     test_node_has_child((IUnknown*)body, VARIANT_TRUE);
5091     elem2 = get_elem_iface((IUnknown*)node);
5092     IHTMLElement_Release(elem2);
5093
5094     hres = IHTMLElement_get_all(body, &disp);
5095     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5096     test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
5097     IDispatch_Release(disp);
5098
5099     test_node_remove_child((IUnknown*)body, node);
5100
5101     hres = IHTMLElement_get_all(body, &disp);
5102     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5103     test_elem_collection((IUnknown*)disp, NULL, 0);
5104     IDispatch_Release(disp);
5105     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5106
5107     IHTMLElement_Release(elem);
5108     IHTMLDOMNode_Release(node);
5109
5110     node = test_create_text(doc, "test");
5111     test_ifaces((IUnknown*)node, text_iids);
5112     test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5113
5114     V_VT(&var) = VT_NULL;
5115     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5116     IHTMLDOMNode_Release(node);
5117
5118     node = test_create_text(doc, "insert ");
5119
5120     V_VT(&var) = VT_DISPATCH;
5121     V_DISPATCH(&var) = (IDispatch*)node2;
5122     node3 = test_node_insertbefore((IUnknown*)body, node, &var);
5123     IHTMLDOMNode_Release(node);
5124     IHTMLDOMNode_Release(node2);
5125     IHTMLDOMNode_Release(node3);
5126
5127     test_elem_innertext(body, "insert test");
5128     test_elem_innerhtml((IUnknown*)body, "insert test");
5129
5130     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
5131     if(hres == S_OK)
5132     {
5133         str = a2bstr("testing");
5134         hres = IHTMLDocument5_createComment(doc5, str, &comment);
5135         SysFreeString(str);
5136         ok(hres == S_OK, "createComment failed: %08x\n", hres);
5137         if(hres == S_OK)
5138         {
5139             type = get_node_type((IUnknown*)comment);
5140             ok(type == 8, "type=%d, expected 8\n", type);
5141
5142             test_node_get_value_str((IUnknown*)comment, "testing");
5143
5144             IHTMLDOMNode_Release(comment);
5145         }
5146
5147         IHTMLDocument5_Release(doc5);
5148     }
5149
5150     IHTMLElement_Release(body);
5151 }
5152
5153 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
5154 {
5155     IOleCommandTarget *cmdtrg;
5156     HRESULT hres;
5157
5158     hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
5159     ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
5160
5161     hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
5162     ok(hres == S_OK, "Exec failed: %08x\n", hres);
5163
5164     IOleCommandTarget_Release(cmdtrg);
5165 }
5166
5167 static void test_indent(IHTMLDocument2 *doc)
5168 {
5169     IHTMLElementCollection *col;
5170     IHTMLTxtRange *range;
5171     HRESULT hres;
5172
5173     static const elem_type_t all_types[] = {
5174         ET_HTML,
5175         ET_HEAD,
5176         ET_TITLE,
5177         ET_BODY,
5178         ET_BR,
5179         ET_A,
5180     };
5181
5182     static const elem_type_t indent_types[] = {
5183         ET_HTML,
5184         ET_HEAD,
5185         ET_TITLE,
5186         ET_BODY,
5187         ET_BLOCKQUOTE,
5188         ET_P,
5189         ET_BR,
5190         ET_A,
5191     };
5192
5193     hres = IHTMLDocument2_get_all(doc, &col);
5194     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5195     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5196     IHTMLElementCollection_Release(col);
5197
5198     range = test_create_body_range(doc);
5199     test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
5200     IHTMLTxtRange_Release(range);
5201
5202     hres = IHTMLDocument2_get_all(doc, &col);
5203     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5204     test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
5205     IHTMLElementCollection_Release(col);
5206 }
5207
5208 static void test_cond_comment(IHTMLDocument2 *doc)
5209 {
5210     IHTMLElementCollection *col;
5211     HRESULT hres;
5212
5213     static const elem_type_t all_types[] = {
5214         ET_HTML,
5215         ET_HEAD,
5216         ET_TITLE,
5217         ET_BODY,
5218         ET_BR
5219     };
5220
5221     hres = IHTMLDocument2_get_all(doc, &col);
5222     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5223     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5224     IHTMLElementCollection_Release(col);
5225 }
5226
5227 static IHTMLDocument2 *notif_doc;
5228 static BOOL doc_complete;
5229
5230 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
5231         REFIID riid, void**ppv)
5232 {
5233     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
5234         *ppv = iface;
5235         return S_OK;
5236     }
5237
5238     ok(0, "unexpected call\n");
5239     return E_NOINTERFACE;
5240 }
5241
5242 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
5243 {
5244     return 2;
5245 }
5246
5247 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
5248 {
5249     return 1;
5250 }
5251
5252 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
5253 {
5254     if(dispID == DISPID_READYSTATE){
5255         BSTR state;
5256         HRESULT hres;
5257
5258         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
5259         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
5260
5261         if(!strcmp_wa(state, "complete"))
5262             doc_complete = TRUE;
5263
5264         SysFreeString(state);
5265     }
5266
5267     return S_OK;
5268 }
5269
5270 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
5271 {
5272     ok(0, "unexpected call\n");
5273     return E_NOTIMPL;
5274 }
5275
5276 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
5277     PropertyNotifySink_QueryInterface,
5278     PropertyNotifySink_AddRef,
5279     PropertyNotifySink_Release,
5280     PropertyNotifySink_OnChanged,
5281     PropertyNotifySink_OnRequestEdit
5282 };
5283
5284 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
5285
5286 static IHTMLDocument2 *create_doc_with_string(const char *str)
5287 {
5288     IPersistStreamInit *init;
5289     IStream *stream;
5290     IHTMLDocument2 *doc;
5291     HGLOBAL mem;
5292     SIZE_T len;
5293
5294     notif_doc = doc = create_document();
5295     if(!doc)
5296         return NULL;
5297
5298     doc_complete = FALSE;
5299     len = strlen(str);
5300     mem = GlobalAlloc(0, len);
5301     memcpy(mem, str, len);
5302     CreateStreamOnHGlobal(mem, TRUE, &stream);
5303
5304     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
5305
5306     IPersistStreamInit_Load(init, stream);
5307     IPersistStreamInit_Release(init);
5308     IStream_Release(stream);
5309
5310     return doc;
5311 }
5312
5313 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
5314 {
5315     IConnectionPointContainer *container;
5316     IConnectionPoint *cp;
5317     DWORD cookie;
5318     HRESULT hres;
5319
5320     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
5321     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
5322
5323     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
5324     IConnectionPointContainer_Release(container);
5325     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
5326
5327     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
5328     IConnectionPoint_Release(cp);
5329     ok(hres == S_OK, "Advise failed: %08x\n", hres);
5330 }
5331
5332 typedef void (*domtest_t)(IHTMLDocument2*);
5333
5334 static void run_domtest(const char *str, domtest_t test)
5335 {
5336     IHTMLDocument2 *doc;
5337     IHTMLElement *body = NULL;
5338     ULONG ref;
5339     MSG msg;
5340     HRESULT hres;
5341
5342     doc = create_doc_with_string(str);
5343     if(!doc)
5344         return;
5345
5346     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
5347
5348     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
5349         TranslateMessage(&msg);
5350         DispatchMessage(&msg);
5351     }
5352
5353     hres = IHTMLDocument2_get_body(doc, &body);
5354     ok(hres == S_OK, "get_body failed: %08x\n", hres);
5355
5356     if(body) {
5357         IHTMLElement_Release(body);
5358         test(doc);
5359     }else {
5360         skip("Could not get document body. Assuming no Gecko installed.\n");
5361     }
5362
5363     ref = IHTMLDocument2_Release(doc);
5364     ok(!ref ||
5365        ref == 1, /* Vista */
5366        "ref = %d\n", ref);
5367 }
5368
5369 static void gecko_installer_workaround(BOOL disable)
5370 {
5371     HKEY hkey;
5372     DWORD res;
5373
5374     static BOOL has_url = FALSE;
5375     static char url[2048];
5376
5377     if(!disable && !has_url)
5378         return;
5379
5380     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
5381     if(res != ERROR_SUCCESS)
5382         return;
5383
5384     if(disable) {
5385         DWORD type, size = sizeof(url);
5386
5387         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
5388         if(res == ERROR_SUCCESS && type == REG_SZ)
5389             has_url = TRUE;
5390
5391         RegDeleteValue(hkey, "GeckoUrl");
5392     }else {
5393         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
5394     }
5395
5396     RegCloseKey(hkey);
5397 }
5398
5399 START_TEST(dom)
5400 {
5401     gecko_installer_workaround(TRUE);
5402     CoInitialize(NULL);
5403
5404     run_domtest(doc_str1, test_doc_elem);
5405     run_domtest(doc_str1, test_get_set_attr);
5406     run_domtest(range_test_str, test_txtrange);
5407     run_domtest(range_test2_str, test_txtrange2);
5408     if (winetest_interactive || ! is_ie_hardened()) {
5409         run_domtest(elem_test_str, test_elems);
5410     }else {
5411         skip("IE running in Enhanced Security Configuration\n");
5412     }
5413     run_domtest(doc_blank, test_create_elems);
5414     run_domtest(doc_blank, test_defaults);
5415     run_domtest(indent_test_str, test_indent);
5416     run_domtest(cond_comment_str, test_cond_comment);
5417
5418     CoUninitialize();
5419     gecko_installer_workaround(FALSE);
5420 }