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