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