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