mshtml: Add tests for supported interfaces.
[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>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\"></script>"
50     "<test />"
51     "<img id=\"imgid\"/>"
52     "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
53     "</body></html>";
54 static const char indent_test_str[] =
55     "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
56 static const char cond_comment_str[] =
57     "<html><head><title>test</title></head><body>"
58     "<!--[if gte IE 4]> <br> <![endif]-->"
59     "</body></html>";
60
61 static const WCHAR noneW[] = {'N','o','n','e',0};
62
63 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
64 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
65 static WCHAR wordW[] = {'w','o','r','d',0};
66
67 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
68
69 static const WCHAR idW[] = {'i','d',0};
70
71 typedef enum {
72     ET_NONE,
73     ET_HTML,
74     ET_HEAD,
75     ET_TITLE,
76     ET_BODY,
77     ET_A,
78     ET_INPUT,
79     ET_SELECT,
80     ET_TEXTAREA,
81     ET_OPTION,
82     ET_STYLE,
83     ET_BLOCKQUOTE,
84     ET_P,
85     ET_BR,
86     ET_TABLE,
87     ET_TBODY,
88     ET_SCRIPT,
89     ET_TEST,
90     ET_TESTG,
91     ET_COMMENT,
92     ET_IMG,
93     ET_TR,
94     ET_TD,
95     ET_IFRAME
96 } elem_type_t;
97
98 static const IID * const none_iids[] = {
99     &IID_IUnknown,
100     NULL
101 };
102
103 static const IID * const elem_iids[] = {
104     &IID_IHTMLDOMNode,
105     &IID_IHTMLDOMNode2,
106     &IID_IHTMLElement,
107     &IID_IHTMLElement2,
108     &IID_IHTMLElement3,
109     &IID_IDispatchEx,
110     &IID_IConnectionPointContainer,
111     NULL
112 };
113
114 static const IID * const body_iids[] = {
115     &IID_IHTMLDOMNode,
116     &IID_IHTMLDOMNode2,
117     &IID_IHTMLElement,
118     &IID_IHTMLElement2,
119     &IID_IHTMLElement3,
120     &IID_IHTMLTextContainer,
121     &IID_IHTMLBodyElement,
122     &IID_IDispatchEx,
123     &IID_IConnectionPointContainer,
124     NULL
125 };
126
127 static const IID * const anchor_iids[] = {
128     &IID_IHTMLDOMNode,
129     &IID_IHTMLDOMNode2,
130     &IID_IHTMLElement,
131     &IID_IHTMLElement2,
132     &IID_IHTMLElement3,
133     &IID_IHTMLAnchorElement,
134     &IID_IDispatchEx,
135     &IID_IConnectionPointContainer,
136     NULL
137 };
138
139 static const IID * const input_iids[] = {
140     &IID_IHTMLDOMNode,
141     &IID_IHTMLDOMNode2,
142     &IID_IHTMLElement,
143     &IID_IHTMLElement2,
144     &IID_IHTMLElement3,
145     &IID_IHTMLInputElement,
146     &IID_IHTMLInputTextElement,
147     &IID_IDispatchEx,
148     &IID_IConnectionPointContainer,
149     NULL
150 };
151
152 static const IID * const select_iids[] = {
153     &IID_IHTMLDOMNode,
154     &IID_IHTMLDOMNode2,
155     &IID_IHTMLElement,
156     &IID_IHTMLElement2,
157     &IID_IHTMLElement3,
158     &IID_IHTMLSelectElement,
159     &IID_IDispatchEx,
160     &IID_IConnectionPointContainer,
161     NULL
162 };
163
164 static const IID * const textarea_iids[] = {
165     &IID_IHTMLDOMNode,
166     &IID_IHTMLDOMNode2,
167     &IID_IHTMLElement,
168     &IID_IHTMLElement2,
169     &IID_IHTMLElement3,
170     &IID_IHTMLTextAreaElement,
171     &IID_IDispatchEx,
172     &IID_IConnectionPointContainer,
173     NULL
174 };
175
176 static const IID * const option_iids[] = {
177     &IID_IHTMLDOMNode,
178     &IID_IHTMLDOMNode2,
179     &IID_IHTMLElement,
180     &IID_IHTMLElement2,
181     &IID_IHTMLElement3,
182     &IID_IHTMLOptionElement,
183     &IID_IDispatchEx,
184     &IID_IConnectionPointContainer,
185     NULL
186 };
187
188 static const IID * const table_iids[] = {
189     &IID_IHTMLDOMNode,
190     &IID_IHTMLDOMNode2,
191     &IID_IHTMLElement,
192     &IID_IHTMLElement2,
193     &IID_IHTMLElement3,
194     &IID_IHTMLTable,
195     &IID_IDispatchEx,
196     &IID_IConnectionPointContainer,
197     NULL
198 };
199
200 static const IID * const script_iids[] = {
201     &IID_IHTMLDOMNode,
202     &IID_IHTMLDOMNode2,
203     &IID_IHTMLElement,
204     &IID_IHTMLElement2,
205     &IID_IHTMLElement3,
206     &IID_IHTMLScriptElement,
207     &IID_IDispatchEx,
208     &IID_IConnectionPointContainer,
209     NULL
210 };
211
212 static const IID * const text_iids[] = {
213     &IID_IHTMLDOMNode,
214     &IID_IHTMLDOMNode2,
215     &IID_IHTMLDOMTextNode,
216     NULL
217 };
218
219 static const IID * const location_iids[] = {
220     &IID_IDispatch,
221     &IID_IHTMLLocation,
222     NULL
223 };
224
225 static const IID * const window_iids[] = {
226     &IID_IDispatch,
227     &IID_IHTMLWindow2,
228     &IID_IHTMLWindow3,
229     &IID_IDispatchEx,
230     NULL
231 };
232
233 static const IID * const comment_iids[] = {
234     &IID_IHTMLDOMNode,
235     &IID_IHTMLDOMNode2,
236     &IID_IHTMLElement,
237     &IID_IHTMLElement2,
238     &IID_IHTMLElement3,
239     &IID_IHTMLCommentElement,
240     &IID_IDispatchEx,
241     &IID_IConnectionPointContainer,
242     NULL
243 };
244
245 static const IID * const img_iids[] = {
246     &IID_IHTMLDOMNode,
247     &IID_IHTMLDOMNode2,
248     &IID_IHTMLElement,
249     &IID_IHTMLElement2,
250     &IID_IHTMLElement3,
251     &IID_IDispatchEx,
252     &IID_IHTMLImgElement,
253     &IID_IConnectionPointContainer,
254     NULL
255 };
256
257 static const IID * const tr_iids[] = {
258     &IID_IHTMLDOMNode,
259     &IID_IHTMLDOMNode2,
260     &IID_IHTMLElement,
261     &IID_IHTMLElement2,
262     &IID_IHTMLElement3,
263     &IID_IDispatchEx,
264     &IID_IHTMLTableRow,
265     &IID_IConnectionPointContainer,
266     NULL
267 };
268
269 static const IID * const td_iids[] = {
270     &IID_IHTMLDOMNode,
271     &IID_IHTMLDOMNode2,
272     &IID_IHTMLElement,
273     &IID_IHTMLElement2,
274     &IID_IHTMLElement3,
275     &IID_IDispatchEx,
276     &IID_IConnectionPointContainer,
277     NULL
278 };
279
280 static const IID * const iframe_iids[] = {
281     &IID_IHTMLDOMNode,
282     &IID_IHTMLDOMNode2,
283     &IID_IHTMLElement,
284     &IID_IHTMLElement2,
285     &IID_IHTMLElement3,
286     &IID_IHTMLFrameBase2,
287     &IID_IDispatchEx,
288     &IID_IConnectionPointContainer,
289     NULL
290 };
291
292 static const IID * const generic_iids[] = {
293     &IID_IHTMLDOMNode,
294     &IID_IHTMLDOMNode2,
295     &IID_IHTMLElement,
296     &IID_IHTMLElement2,
297     &IID_IHTMLElement3,
298     &IID_IHTMLGenericElement,
299     &IID_IDispatchEx,
300     &IID_IConnectionPointContainer,
301     NULL
302 };
303
304 static const IID * const style_iids[] = {
305     &IID_IUnknown,
306     &IID_IDispatch,
307     &IID_IDispatchEx,
308     &IID_IHTMLStyle,
309     &IID_IHTMLStyle2,
310     NULL
311 };
312
313 static const IID * const cstyle_iids[] = {
314     &IID_IUnknown,
315     &IID_IDispatch,
316     &IID_IDispatchEx,
317     &IID_IHTMLCurrentStyle,
318     NULL
319 };
320
321 typedef struct {
322     const char *tag;
323     REFIID *iids;
324     const IID *dispiid;
325 } elem_type_info_t;
326
327 static const elem_type_info_t elem_type_infos[] = {
328     {"",          none_iids,        NULL},
329     {"HTML",      elem_iids,        NULL},
330     {"HEAD",      elem_iids,        NULL},
331     {"TITLE",     elem_iids,        NULL},
332     {"BODY",      body_iids,        &DIID_DispHTMLBody},
333     {"A",         anchor_iids,      NULL},
334     {"INPUT",     input_iids,       &DIID_DispHTMLInputElement},
335     {"SELECT",    select_iids,      &DIID_DispHTMLSelectElement},
336     {"TEXTAREA",  textarea_iids,    NULL},
337     {"OPTION",    option_iids,      &DIID_DispHTMLOptionElement},
338     {"STYLE",     elem_iids,        NULL},
339     {"BLOCKQUOTE",elem_iids,        NULL},
340     {"P",         elem_iids,        NULL},
341     {"BR",        elem_iids,        NULL},
342     {"TABLE",     table_iids,       &DIID_DispHTMLTable},
343     {"TBODY",     elem_iids,        NULL},
344     {"SCRIPT",    script_iids,      NULL},
345     {"TEST",      elem_iids,        &DIID_DispHTMLUnknownElement},
346     {"TEST",      generic_iids,     &DIID_DispHTMLGenericElement},
347     {"!",         comment_iids,     &DIID_DispHTMLCommentElement},
348     {"IMG",       img_iids,         &DIID_DispHTMLImg},
349     {"TR",        tr_iids,          &DIID_DispHTMLTableRow},
350     {"TD",        td_iids,          NULL},
351     {"IFRAME",    iframe_iids,      &DIID_DispHTMLIFrame}
352 };
353
354 static const char *dbgstr_w(LPCWSTR str)
355 {
356     static char buf[512];
357     if(!str)
358         return "(null)";
359     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
360     return buf;
361 }
362
363 static const char *dbgstr_guid(REFIID riid)
364 {
365     static char buf[50];
366
367     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
368             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
369             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
370             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
371
372     return buf;
373 }
374
375 static int strcmp_wa(LPCWSTR strw, const char *stra)
376 {
377     WCHAR buf[512];
378     MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
379     return lstrcmpW(strw, buf);
380 }
381
382 static BSTR a2bstr(const char *str)
383 {
384     BSTR ret;
385     int len;
386
387     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
388     ret = SysAllocStringLen(NULL, len);
389     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
390
391     return ret;
392 }
393
394 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
395 {
396     IUnknown *unk1, *unk2;
397
398     if(iface1 == iface2)
399         return TRUE;
400
401     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
402     IUnknown_Release(unk1);
403     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
404     IUnknown_Release(unk2);
405
406     return unk1 == unk2;
407 }
408
409 static IHTMLDocument2 *create_document(void)
410 {
411     IHTMLDocument2 *doc;
412     HRESULT hres;
413
414     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
415             &IID_IHTMLDocument2, (void**)&doc);
416     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
417
418     return doc;
419 }
420
421 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
422 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
423 {
424     const IID * const *piid;
425     IUnknown *unk;
426     HRESULT hres;
427
428      for(piid = iids; *piid; piid++) {
429         hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
430         ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
431         if(SUCCEEDED(hres))
432             IUnknown_Release(unk);
433     }
434 }
435
436 #define test_disp(u,id) _test_disp(__LINE__,u,id)
437 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
438 {
439     IDispatchEx *dispex;
440     ITypeInfo *typeinfo;
441     UINT ticnt;
442     HRESULT hres;
443
444     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
445     ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
446     if(FAILED(hres))
447         return;
448
449     ticnt = 0xdeadbeef;
450     hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
451     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
452     ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
453
454     hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
455     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
456
457     if(SUCCEEDED(hres)) {
458         TYPEATTR *type_attr;
459
460         hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
461         ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
462         ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
463
464         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
465         ITypeInfo_Release(typeinfo);
466     }
467
468     IDispatchEx_Release(dispex);
469 }
470
471 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
472 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
473 {
474     IHTMLElement *elem;
475     HRESULT hres;
476
477     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
478     ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
479     return elem;
480 }
481
482 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
483 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
484 {
485     IHTMLElement2 *elem;
486     HRESULT hres;
487
488     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
489     ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
490     return elem;
491 }
492
493 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
494 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
495 {
496     IHTMLElement3 *elem;
497     HRESULT hres;
498
499     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
500     ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement3: %08x\n", hres);
501     return elem;
502 }
503
504 #define get_node_iface(u) _get_node_iface(__LINE__,u)
505 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
506 {
507     IHTMLDOMNode *node;
508     HRESULT hres;
509
510     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
511     ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
512     return node;
513 }
514
515 #define get_img_iface(u) _get_img_iface(__LINE__,u)
516 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
517 {
518     IHTMLImgElement *img;
519     HRESULT hres;
520
521     hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
522     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
523     return img;
524 }
525
526 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
527 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
528 {
529     IHTMLDOMNode *node = _get_node_iface(line, unk);
530     BSTR name;
531     HRESULT hres;
532
533     hres = IHTMLDOMNode_get_nodeName(node, &name);
534     IHTMLDOMNode_Release(node);
535     ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
536     ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
537
538     SysFreeString(name);
539 }
540
541 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
542 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
543 {
544     IHTMLElement *elem = _get_elem_iface(line, unk);
545     BSTR tag;
546     HRESULT hres;
547
548     hres = IHTMLElement_get_tagName(elem, &tag);
549     IHTMLElement_Release(elem);
550     ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
551     ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
552
553     SysFreeString(tag);
554 }
555
556 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
557 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
558 {
559     _test_elem_tag(line, unk, elem_type_infos[type].tag);
560     _test_ifaces(line, unk, elem_type_infos[type].iids);
561
562     if(elem_type_infos[type].dispiid)
563         _test_disp(line, unk, elem_type_infos[type].dispiid);
564 }
565
566 #define get_node_type(n) _get_node_type(__LINE__,n)
567 static long _get_node_type(unsigned line, IUnknown *unk)
568 {
569     IHTMLDOMNode *node = _get_node_iface(line, unk);
570     long type = -1;
571     HRESULT hres;
572
573     hres = IHTMLDOMNode_get_nodeType(node, &type);
574     ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
575
576     IHTMLDOMNode_Release(node);
577
578     return type;
579 }
580
581 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
582 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
583 {
584     IHTMLDOMNode *node = _get_node_iface(line, unk);
585     IHTMLDOMChildrenCollection *col = NULL;
586     IDispatch *disp;
587     HRESULT hres;
588
589     hres = IHTMLDOMNode_get_childNodes(node, &disp);
590     IHTMLDOMNode_Release(node);
591     ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
592     if(FAILED(hres))
593         return NULL;
594
595     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
596     IDispatch_Release(disp);
597     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
598
599     return col;
600 }
601
602 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
603 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
604 {
605     IHTMLDOMNode *node = NULL;
606     IDispatch *disp;
607     HRESULT hres;
608
609     hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
610     ok(hres == S_OK, "item failed: %08x\n", hres);
611
612     node = _get_node_iface(line, (IUnknown*)disp);
613     IDispatch_Release(disp);
614
615     return node;
616 }
617
618 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
619 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
620 {
621     VARIANT value;
622     BSTR tmp;
623     HRESULT hres;
624
625     VariantInit(&value);
626
627     tmp = SysAllocString(name);
628     hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
629     SysFreeString(tmp);
630     ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
631
632     if(exval) {
633         ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
634         ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
635     }else {
636         ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
637     }
638
639     VariantClear(&value);
640 }
641
642 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
643 static void _test_elem_offset(unsigned line, IUnknown *unk)
644 {
645     IHTMLElement *elem = _get_elem_iface(line, unk);
646     long l;
647     HRESULT hres;
648
649     hres = IHTMLElement_get_offsetTop(elem, &l);
650     ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
651
652     hres = IHTMLElement_get_offsetHeight(elem, &l);
653     ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
654
655     hres = IHTMLElement_get_offsetWidth(elem, &l);
656     ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
657
658     IHTMLElement_Release(elem);
659 }
660
661 static void test_doc_elem(IHTMLDocument2 *doc)
662 {
663     IHTMLElement *elem;
664     IHTMLDocument3 *doc3;
665     HRESULT hres;
666
667     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
668     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
669
670     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
671     IHTMLDocument3_Release(doc3);
672     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
673
674     test_node_name((IUnknown*)elem, "HTML");
675     test_elem_tag((IUnknown*)elem, "HTML");
676
677     IHTMLElement_Release(elem);
678 }
679
680 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
681 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
682 {
683     IHTMLElement *elem;
684     IHTMLDocument3 *doc3;
685     HRESULT hres;
686
687     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
688     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
689     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
690     ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
691     IHTMLDocument3_Release(doc3);
692
693     return elem;
694 }
695
696 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
697 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
698 {
699     BSTR bstr;
700     HRESULT hres;
701
702     hres = IHTMLOptionElement_get_text(option, &bstr);
703     ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
704     ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
705     SysFreeString(bstr);
706 }
707
708 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
709 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
710 {
711     BSTR bstr;
712     HRESULT hres;
713
714     bstr = a2bstr(text);
715     hres = IHTMLOptionElement_put_text(option, bstr);
716     SysFreeString(bstr);
717     ok(hres == S_OK, "put_text failed: %08x\n", hres);
718
719     _test_option_text(line, option, text);
720 }
721
722 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
723 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
724 {
725     BSTR bstr;
726     HRESULT hres;
727
728     hres = IHTMLOptionElement_get_value(option, &bstr);
729     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
730     ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
731     SysFreeString(bstr);
732 }
733
734 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
735 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
736 {
737     BSTR bstr;
738     HRESULT hres;
739
740     bstr = a2bstr(value);
741     hres = IHTMLOptionElement_put_value(option, bstr);
742     SysFreeString(bstr);
743     ok(hres == S_OK, "put_value failed: %08x\n", hres);
744
745     _test_option_value(line, option, value);
746 }
747
748 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
749 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
750         const char *txt, const char *val)
751 {
752     IHTMLOptionElementFactory *factory;
753     IHTMLOptionElement *option;
754     IHTMLWindow2 *window;
755     VARIANT text, value, empty;
756     HRESULT hres;
757
758     hres = IHTMLDocument2_get_parentWindow(doc, &window);
759     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
760
761     hres = IHTMLWindow2_get_Option(window, &factory);
762     IHTMLWindow2_Release(window);
763     ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
764
765     V_VT(&text) = VT_BSTR;
766     V_BSTR(&text) = a2bstr(txt);
767     V_VT(&value) = VT_BSTR;
768     V_BSTR(&value) = a2bstr(val);
769     V_VT(&empty) = VT_EMPTY;
770
771     hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
772     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
773
774     IHTMLOptionElementFactory_Release(factory);
775     VariantClear(&text);
776     VariantClear(&value);
777
778     _test_option_text(line, option, txt);
779     _test_option_value(line, option, val);
780
781     return option;
782 }
783
784 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
785 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
786 {
787     long len = 0xdeadbeef;
788     HRESULT hres;
789
790     hres = IHTMLSelectElement_get_length(select, &len);
791     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
792     ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
793 }
794
795 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
796 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
797 {
798     long idx = 0xdeadbeef;
799     HRESULT hres;
800
801     hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
802     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
803     ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
804 }
805
806 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
807 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
808 {
809     HRESULT hres;
810
811     hres = IHTMLSelectElement_put_selectedIndex(select, index);
812     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
813     _test_select_selidx(line, select, index);
814 }
815
816 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
817 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
818 {
819     BSTR val;
820     HRESULT hres;
821
822     hres = IHTMLSelectElement_get_value(select, &val);
823     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
824     if(exval)
825         ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
826     else
827         ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
828 }
829
830 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
831 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
832 {
833     BSTR bstr;
834     HRESULT hres;
835
836     bstr = a2bstr(val);
837     hres = IHTMLSelectElement_put_value(select, bstr);
838     SysFreeString(bstr);
839     ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
840 }
841
842 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
843 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
844 {
845     BSTR type;
846     HRESULT hres;
847
848     hres = IHTMLSelectElement_get_type(select, &type);
849     ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
850     ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
851 }
852
853 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
854 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
855 {
856     BSTR text;
857     HRESULT hres;
858
859     hres = IHTMLTxtRange_get_text(range, &text);
860     ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
861
862     if(extext) {
863         ok_(__FILE__, line) (text != NULL, "text == NULL\n");
864         ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
865     }else {
866         ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
867     }
868
869     SysFreeString(text);
870
871 }
872
873 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
874 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
875 {
876     HRESULT hres;
877
878     hres = IHTMLTxtRange_collapse(range, b);
879     ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
880     _test_range_text(line, range, NULL);
881 }
882
883 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
884 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
885         VARIANT_BOOL exb, const char *extext)
886 {
887     VARIANT_BOOL b = 0xe0e0;
888     HRESULT hres;
889
890     hres = IHTMLTxtRange_expand(range, unit, &b);
891     ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
892     ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
893     _test_range_text(line, range, extext);
894 }
895
896 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
897 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
898 {
899     long c = 0xdeadbeef;
900     HRESULT hres;
901
902     hres = IHTMLTxtRange_move(range, unit, cnt, &c);
903     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
904     ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
905     _test_range_text(line, range, NULL);
906 }
907
908 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
909 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
910         LPWSTR unit, long cnt, long excnt)
911 {
912     long c = 0xdeadbeef;
913     HRESULT hres;
914
915     hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
916     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
917     ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
918 }
919
920 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
921 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
922 {
923     long c = 0xdeadbeef;
924     HRESULT hres;
925
926     hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
927     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
928     ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
929 }
930
931 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
932 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
933 {
934     HRESULT hres;
935     BSTR bstr = a2bstr(text);
936
937     hres = IHTMLTxtRange_put_text(range, bstr);
938     ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
939     SysFreeString(bstr);
940     _test_range_text(line, range, NULL);
941 }
942
943 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
944 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
945 {
946     VARIANT_BOOL b;
947     HRESULT hres;
948
949     b = 0xe0e0;
950     hres = IHTMLTxtRange_inRange(range1, range2, &b);
951     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
952     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
953 }
954
955 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
956 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
957 {
958     VARIANT_BOOL b;
959     HRESULT hres;
960
961     b = 0xe0e0;
962     hres = IHTMLTxtRange_isEqual(range1, range2, &b);
963     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
964     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
965
966     b = 0xe0e0;
967     hres = IHTMLTxtRange_isEqual(range2, range1, &b);
968     ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
969     ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
970
971     if(exb) {
972         test_range_inrange(range1, range2, VARIANT_TRUE);
973         test_range_inrange(range2, range1, VARIANT_TRUE);
974     }
975 }
976
977 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
978 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
979 {
980     IHTMLElement *elem;
981     HRESULT hres;
982
983     hres = IHTMLTxtRange_parentElement(range, &elem);
984     ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
985
986     _test_elem_type(line, (IUnknown*)elem, type);
987
988     IHTMLElement_Release(elem);
989 }
990
991 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
992 static void _test_elem_collection(unsigned line, IUnknown *unk,
993         const elem_type_t *elem_types, long exlen)
994 {
995     IHTMLElementCollection *col;
996     long len;
997     DWORD i;
998     VARIANT name, index;
999     IDispatch *disp;
1000     HRESULT hres;
1001
1002     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1003     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1004
1005     test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
1006
1007     hres = IHTMLElementCollection_get_length(col, &len);
1008     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1009     ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
1010
1011     if(len > exlen)
1012         len = exlen;
1013
1014     V_VT(&index) = VT_EMPTY;
1015     V_VT(&name) = VT_I4;
1016
1017     for(i=0; i<len; i++) {
1018         V_I4(&name) = i;
1019         disp = (void*)0xdeadbeef;
1020         hres = IHTMLElementCollection_item(col, name, index, &disp);
1021         ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1022         ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1023         if(FAILED(hres) || !disp)
1024             continue;
1025
1026         _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1027         IDispatch_Release(disp);
1028     }
1029
1030     V_I4(&name) = len;
1031     disp = (void*)0xdeadbeef;
1032     hres = IHTMLElementCollection_item(col, name, index, &disp);
1033     ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1034     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1035
1036     V_I4(&name) = -1;
1037     disp = (void*)0xdeadbeef;
1038     hres = IHTMLElementCollection_item(col, name, index, &disp);
1039     ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1040     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1041
1042     IHTMLElementCollection_Release(col);
1043 }
1044
1045 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1046 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
1047 {
1048     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1049     IHTMLElementCollection *col = NULL;
1050     elem_type_t *types = NULL;
1051     BSTR tmp;
1052     int i;
1053     HRESULT hres;
1054
1055     tmp = a2bstr(elem_type_infos[type].tag);
1056     hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1057     SysFreeString(tmp);
1058     IHTMLElement2_Release(elem);
1059     ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1060     ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1061
1062     if(exlen) {
1063         types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1064         for(i=0; i<exlen; i++)
1065             types[i] = type;
1066     }
1067
1068     _test_elem_collection(line, (IUnknown*)col, types, exlen);
1069
1070     HeapFree(GetProcessHeap(), 0, types);
1071 }
1072
1073 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1074 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1075 {
1076     BSTR text = NULL;
1077     HRESULT hres;
1078
1079     hres = IHTMLElement_get_innerText(elem, &text);
1080     ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1081     ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1082                         dbgstr_w(text), extext);
1083     SysFreeString(text);
1084 }
1085
1086 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1087 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1088 {
1089     IHTMLDOMChildrenCollection *col;
1090     BSTR str;
1091     HRESULT hres;
1092
1093     str = a2bstr(text);
1094     hres = IHTMLElement_put_innerText(elem, str);
1095     ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1096     SysFreeString(str);
1097
1098     _test_elem_innertext(line, elem, text);
1099
1100
1101     col = _get_child_nodes(line, (IUnknown*)elem);
1102     ok(col != NULL, "col == NULL\n");
1103     if(col) {
1104         long length = 0, type;
1105         IHTMLDOMNode *node;
1106
1107         hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1108         ok(hres == S_OK, "get_length failed: %08x\n", hres);
1109         ok(length == 1, "length = %ld\n", length);
1110
1111         node = _get_child_item(line, col, 0);
1112         ok(node != NULL, "node == NULL\n");
1113         if(node) {
1114             type = _get_node_type(line, (IUnknown*)node);
1115             ok(type == 3, "type=%ld\n", type);
1116             IHTMLDOMNode_Release(node);
1117         }
1118
1119         IHTMLDOMChildrenCollection_Release(col);
1120     }
1121
1122 }
1123
1124 #define get_first_child(n) _get_first_child(__LINE__,n)
1125 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1126 {
1127     IHTMLDOMNode *node = _get_node_iface(line, unk);
1128     IHTMLDOMNode *child = NULL;
1129     HRESULT hres;
1130
1131     hres = IHTMLDOMNode_get_firstChild(node, &child);
1132     IHTMLDOMNode_Release(node);
1133     ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1134
1135     return child;
1136 }
1137
1138 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1139 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1140 {
1141     IHTMLDOMNode *node = _get_node_iface(line, unk);
1142     VARIANT_BOOL b = 0xdead;
1143     HRESULT hres;
1144
1145     hres = IHTMLDOMNode_hasChildNodes(node, &b);
1146     ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1147     ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1148
1149     IHTMLDOMNode_Release(node);
1150 }
1151
1152 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1153 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1154 {
1155     IHTMLDOMNode *node = _get_node_iface(line, unk);
1156     IHTMLDOMNode *parent;
1157     HRESULT hres;
1158
1159     hres = IHTMLDOMNode_get_parentNode(node, &parent);
1160     IHTMLDOMNode_Release(node);
1161     ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1162
1163     return parent;
1164 }
1165
1166 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1167 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1168 {
1169     IHTMLElement *elem = _get_elem_iface(line, unk);
1170     IHTMLElement *parent;
1171     HRESULT hres;
1172
1173     hres = IHTMLElement_get_parentElement(elem, &parent);
1174     IHTMLElement_Release(elem);
1175     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1176
1177     return parent;
1178 }
1179
1180 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1181 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1182 {
1183     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1184     VARIANT_BOOL disabled = 100;
1185     HRESULT hres;
1186
1187     hres = IHTMLElement3_get_disabled(elem3, &disabled);
1188     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1189     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1190     IHTMLElement3_Release(elem3);
1191 }
1192
1193 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1194 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1195 {
1196     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1197     HRESULT hres;
1198
1199     hres = IHTMLElement3_put_disabled(elem3, b);
1200     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1201
1202     IHTMLElement3_Release(elem3);
1203     _test_elem3_get_disabled(line, unk, b);
1204 }
1205
1206 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1207 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1208 {
1209     VARIANT_BOOL disabled = 100;
1210     HRESULT hres;
1211
1212     hres = IHTMLSelectElement_get_disabled(select, &disabled);
1213     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1214     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1215
1216     _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1217 }
1218
1219 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1220 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1221 {
1222     HRESULT hres;
1223
1224     hres = IHTMLSelectElement_put_disabled(select, b);
1225     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1226
1227     _test_select_get_disabled(line, select, b);
1228 }
1229
1230 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1231 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1232 {
1233     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1234     IHTMLTextContainer *txtcont;
1235     long l = -1, l2 = -1;
1236     HRESULT hres;
1237
1238     hres = IHTMLElement2_get_scrollHeight(elem, &l);
1239     ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1240     IHTMLElement2_Release(elem);
1241
1242     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1243     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1244
1245     hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1246     IHTMLTextContainer_Release(txtcont);
1247     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1248     ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1249
1250     return l;
1251 }
1252
1253 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1254 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1255 {
1256     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1257     IHTMLTextContainer *txtcont;
1258     long l = -1, l2 = -1;
1259     HRESULT hres;
1260
1261     hres = IHTMLElement2_get_scrollWidth(elem, &l);
1262     ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1263     IHTMLElement2_Release(elem);
1264
1265     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1266     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1267
1268     hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1269     IHTMLTextContainer_Release(txtcont);
1270     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1271     ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1272
1273     return l;
1274 }
1275
1276 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1277 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1278 {
1279     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1280     IHTMLTextContainer *txtcont;
1281     long l = -1, l2 = -1;
1282     HRESULT hres;
1283
1284     hres = IHTMLElement2_get_scrollTop(elem, &l);
1285     ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1286     IHTMLElement2_Release(elem);
1287
1288     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1289     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1290
1291     hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1292     IHTMLTextContainer_Release(txtcont);
1293     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1294     ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1295
1296     return l;
1297 }
1298
1299 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1300 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1301 {
1302     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1303     IHTMLTextContainer *txtcont;
1304     long l = -1, l2 = -1;
1305     HRESULT hres;
1306
1307     hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1308     ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1309
1310     hres = IHTMLElement2_get_scrollLeft(elem, &l);
1311     ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1312     IHTMLElement2_Release(elem);
1313
1314     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1315     ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1316
1317     hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1318     IHTMLTextContainer_Release(txtcont);
1319     ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1320     ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1321 }
1322
1323 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1324 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1325 {
1326     IHTMLImgElement *img = _get_img_iface(line, unk);
1327     BSTR src;
1328     HRESULT hres;
1329
1330     hres = IHTMLImgElement_get_src(img, &src);
1331     IHTMLImgElement_Release(img);
1332     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1333     ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", dbgstr_w(src), exsrc);
1334     SysFreeString(src);
1335 }
1336
1337 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1338 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1339 {
1340     IHTMLImgElement *img = _get_img_iface(line, unk);
1341     BSTR tmp;
1342     HRESULT hres;
1343
1344     tmp = a2bstr(src);
1345     hres = IHTMLImgElement_put_src(img, tmp);
1346     IHTMLImgElement_Release(img);
1347     SysFreeString(tmp);
1348     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1349
1350     _test_img_src(line, unk, src);
1351 }
1352
1353 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1354 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1355 {
1356     IHTMLImgElement *img = _get_img_iface(line, unk);
1357     BSTR alt;
1358     HRESULT hres;
1359
1360     hres = IHTMLImgElement_get_alt(img, &alt);
1361     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1362     if(exalt)
1363         ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1364     else
1365         ok_(__FILE__,line) (!alt, "alt != NULL\n");
1366     SysFreeString(alt);
1367 }
1368
1369 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1370 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1371 {
1372     IHTMLImgElement *img = _get_img_iface(line, unk);
1373     BSTR tmp;
1374     HRESULT hres;
1375
1376     tmp = a2bstr(alt);
1377     hres = IHTMLImgElement_put_alt(img, tmp);
1378     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1379     SysFreeString(tmp);
1380
1381     _test_img_alt(line, unk, alt);
1382 }
1383
1384 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1385 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1386 {
1387     VARIANT_BOOL disabled = 100;
1388     HRESULT hres;
1389
1390     hres = IHTMLInputElement_get_disabled(input, &disabled);
1391     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1392     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1393
1394     _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1395 }
1396
1397 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1398 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1399 {
1400     HRESULT hres;
1401
1402     hres = IHTMLInputElement_put_disabled(input, b);
1403     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1404
1405     _test_input_get_disabled(line, input, b);
1406 }
1407
1408 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
1409 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1410 {
1411     VARIANT_BOOL checked = 100;
1412     HRESULT hres;
1413
1414     hres = IHTMLInputElement_get_defaultChecked(input, &checked);
1415     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1416     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1417 }
1418
1419 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
1420 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1421 {
1422     HRESULT hres;
1423
1424     hres = IHTMLInputElement_put_defaultChecked(input, b);
1425     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1426
1427     _test_input_get_defaultchecked(line, input, b);
1428 }
1429
1430 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
1431 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1432 {
1433     VARIANT_BOOL checked = 100;
1434     HRESULT hres;
1435
1436     hres = IHTMLInputElement_get_checked(input, &checked);
1437     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1438     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1439 }
1440
1441 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
1442 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1443 {
1444     HRESULT hres;
1445
1446     hres = IHTMLInputElement_put_checked(input, b);
1447     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1448
1449     _test_input_get_checked(line, input, b);
1450 }
1451
1452 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1453 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1454 {
1455     IHTMLInputElement *input;
1456     BSTR bstr;
1457     HRESULT hres;
1458
1459     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1460     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1461     if(FAILED(hres))
1462         return;
1463
1464     hres = IHTMLInputElement_get_value(input, &bstr);
1465     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1466     if(exval)
1467         ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1468     else
1469         ok_(__FILE__,line) (!exval, "exval != NULL\n");
1470     SysFreeString(bstr);
1471     IHTMLInputElement_Release(input);
1472 }
1473
1474 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1475 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1476 {
1477     IHTMLInputElement *input;
1478     BSTR bstr;
1479     HRESULT hres;
1480
1481     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1482     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1483     if(FAILED(hres))
1484         return;
1485
1486     bstr = a2bstr(val);
1487     hres = IHTMLInputElement_get_value(input, &bstr);
1488     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1489     SysFreeString(bstr);
1490     IHTMLInputElement_Release(input);
1491 }
1492
1493 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1494 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1495 {
1496     IHTMLElement *elem = _get_elem_iface(line, unk);
1497     BSTR class = (void*)0xdeadbeef;
1498     HRESULT hres;
1499
1500     hres = IHTMLElement_get_className(elem, &class);
1501     IHTMLElement_Release(elem);
1502     ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1503     if(exclass)
1504         ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1505     else
1506         ok_(__FILE__,line) (!class, "class != NULL\n");
1507     SysFreeString(class);
1508 }
1509
1510 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1511 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1512 {
1513     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1514     short index = -3;
1515     HRESULT hres;
1516
1517     hres = IHTMLElement2_get_tabIndex(elem2, &index);
1518     IHTMLElement2_Release(elem2);
1519     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1520     ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1521 }
1522
1523 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1524 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1525 {
1526     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1527     HRESULT hres;
1528
1529     hres = IHTMLElement2_put_tabIndex(elem2, index);
1530     IHTMLElement2_Release(elem2);
1531     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1532
1533     _test_elem_tabindex(line, unk, index);
1534 }
1535
1536 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1537 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1538 {
1539     IHTMLElement *elem = _get_elem_iface(line, unk);
1540     BSTR tmp;
1541     HRESULT hres;
1542
1543     tmp = class ? a2bstr(class) : NULL;
1544     hres = IHTMLElement_put_className(elem, tmp);
1545     IHTMLElement_Release(elem);
1546     ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1547     SysFreeString(tmp);
1548
1549     _test_elem_class(line, unk, class);
1550 }
1551
1552 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1553 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1554 {
1555     IHTMLElement *elem = _get_elem_iface(line, unk);
1556     BSTR id = (void*)0xdeadbeef;
1557     HRESULT hres;
1558
1559     hres = IHTMLElement_get_id(elem, &id);
1560     IHTMLElement_Release(elem);
1561     ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1562
1563     if(exid)
1564         ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1565     else
1566         ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1567
1568     SysFreeString(id);
1569 }
1570
1571 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1572 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1573 {
1574     IHTMLElement *elem = _get_elem_iface(line, unk);
1575     BSTR tmp = a2bstr(new_id);
1576     HRESULT hres;
1577
1578     hres = IHTMLElement_put_id(elem, tmp);
1579     IHTMLElement_Release(elem);
1580     SysFreeString(tmp);
1581     ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1582
1583     _test_elem_id(line, unk, new_id);
1584 }
1585
1586 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1587 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1588 {
1589     IHTMLElement *elem = _get_elem_iface(line, unk);
1590     BSTR title;
1591     HRESULT hres;
1592
1593     hres = IHTMLElement_get_title(elem, &title);
1594     IHTMLElement_Release(elem);
1595     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1596     if(extitle)
1597         ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1598     else
1599         ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1600
1601     SysFreeString(title);
1602 }
1603
1604 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1605 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1606 {
1607     IHTMLElement *elem = _get_elem_iface(line, unk);
1608     BSTR tmp;
1609     HRESULT hres;
1610
1611     tmp = a2bstr(title);
1612     hres = IHTMLElement_put_title(elem, tmp);
1613     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1614
1615     IHTMLElement_Release(elem);
1616     SysFreeString(tmp);
1617 }
1618
1619 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1620 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1621 {
1622     IHTMLDOMNode *node = _get_node_iface(line, unk);
1623     VARIANT var;
1624     HRESULT hres;
1625
1626     hres = IHTMLDOMNode_get_nodeValue(node, &var);
1627     IHTMLDOMNode_Release(node);
1628     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1629
1630     if(exval) {
1631         ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1632         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1633     }else {
1634         ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1635     }
1636
1637     VariantClear(&var);
1638 }
1639
1640 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1641 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1642 {
1643     IHTMLDOMNode *node = _get_node_iface(line, unk);
1644     VARIANT var;
1645     HRESULT hres;
1646
1647     V_VT(&var) = VT_BSTR;
1648     V_BSTR(&var) = a2bstr(val);
1649
1650     hres = IHTMLDOMNode_put_nodeValue(node, var);
1651     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1652     IHTMLDOMNode_Release(node);
1653     VariantClear(&var);
1654 }
1655
1656 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1657 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1658 {
1659     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1660     long l;
1661     HRESULT hres;
1662
1663     hres = IHTMLElement2_get_clientWidth(elem, &l);
1664     ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1665     hres = IHTMLElement2_get_clientHeight(elem, &l);
1666     ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1667
1668     IHTMLElement2_Release(elem);
1669 }
1670
1671 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1672 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1673 {
1674     IHTMLElement *elem = NULL;
1675     BSTR tmp;
1676     HRESULT hres;
1677
1678     tmp = a2bstr(tag);
1679     hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1680     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1681     ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1682
1683     return elem;
1684 }
1685
1686 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1687 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1688 {
1689     IHTMLDocument3 *doc3;
1690     IHTMLDOMNode *node = NULL;
1691     BSTR tmp;
1692     HRESULT hres;
1693
1694     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1695     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1696
1697     tmp = a2bstr(text);
1698     hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1699     IHTMLDocument3_Release(doc3);
1700     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1701     ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1702
1703     return node;
1704 }
1705
1706 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1707 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1708 {
1709     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1710     IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1711     IHTMLDOMNode *new_child = NULL;
1712     HRESULT hres;
1713
1714     hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1715     ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1716     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1717     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1718
1719     IHTMLDOMNode_Release(node);
1720     IHTMLDOMNode_Release(child);
1721
1722     return new_child;
1723 }
1724
1725 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
1726 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
1727 {
1728     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1729     IHTMLDOMNode *new_child = NULL;
1730     HRESULT hres;
1731
1732     hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
1733     ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
1734     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1735     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1736
1737     IHTMLDOMNode_Release(node);
1738
1739     return new_child;
1740 }
1741
1742 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1743 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1744 {
1745     IHTMLDOMNode *node = _get_node_iface(line, unk);
1746     IHTMLDOMNode *new_node = NULL;
1747     HRESULT hres;
1748
1749     hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1750     ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
1751     ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1752     /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1753
1754     IHTMLDOMNode_Release(node);
1755     IHTMLDOMNode_Release(new_node);
1756 }
1757
1758 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1759 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1760 {
1761     BSTR title = NULL;
1762     HRESULT hres;
1763
1764     hres = IHTMLDocument2_get_title(doc, &title);
1765     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1766     ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1767     SysFreeString(title);
1768 }
1769
1770 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1771 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1772 {
1773     BSTR tmp;
1774     HRESULT hres;
1775
1776     tmp = a2bstr(title);
1777     hres = IHTMLDocument2_put_title(doc, tmp);
1778     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1779     SysFreeString(tmp);
1780 }
1781
1782 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1783         const elem_type_t *elem_types, long len)
1784 {
1785     IDispatch *disp;
1786     VARIANT name, index;
1787     DWORD i;
1788     HRESULT hres;
1789
1790     V_VT(&index) = VT_EMPTY;
1791     V_VT(&name) = VT_BSTR;
1792     V_BSTR(&name) = SysAllocString(n);
1793
1794     hres = IHTMLElementCollection_item(col, name, index, &disp);
1795     ok(hres == S_OK, "item failed: %08x\n", hres);
1796
1797     test_elem_collection((IUnknown*)disp, elem_types, len);
1798     IDispatch_Release(disp);
1799     ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1800     if(hres != S_OK)
1801         goto cleanup;
1802
1803     V_VT(&index) = VT_I4;
1804
1805     for(i=0; i<len; i++) {
1806         V_I4(&index) = i;
1807         disp = (void*)0xdeadbeef;
1808         hres = IHTMLElementCollection_item(col, name, index, &disp);
1809         ok(hres == S_OK, "item failed: %08x\n", hres);
1810         ok(disp != NULL, "disp == NULL\n");
1811         if(FAILED(hres) || !disp)
1812             continue;
1813
1814         test_elem_type((IUnknown*)disp, elem_types[i]);
1815
1816         IDispatch_Release(disp);
1817     }
1818
1819     V_I4(&index) = len;
1820     disp = (void*)0xdeadbeef;
1821     hres = IHTMLElementCollection_item(col, name, index, &disp);
1822     ok(hres == S_OK, "item failed: %08x\n", hres);
1823     ok(disp == NULL, "disp != NULL\n");
1824
1825     V_I4(&index) = -1;
1826     disp = (void*)0xdeadbeef;
1827     hres = IHTMLElementCollection_item(col, name, index, &disp);
1828     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1829     ok(disp == NULL, "disp != NULL\n");
1830
1831 cleanup:
1832     SysFreeString(V_BSTR(&name));
1833 }
1834
1835 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1836 {
1837     IHTMLElementCollection *col;
1838     IHTMLElement *elem;
1839     IDispatch *disp = (void*)0xdeadbeef;
1840     VARIANT name, index;
1841     HRESULT hres;
1842
1843     hres = IHTMLDocument2_get_all(doc, &col);
1844     ok(hres == S_OK, "get_all failed: %08x\n", hres);
1845     ok(col != NULL, "col == NULL\n");
1846     if(FAILED(hres) || !col)
1847         return NULL;
1848
1849     V_VT(&index) = VT_EMPTY;
1850     V_VT(&name) = VT_BSTR;
1851     V_BSTR(&name) = SysAllocString(id);
1852
1853     hres = IHTMLElementCollection_item(col, name, index, &disp);
1854     IHTMLElementCollection_Release(col);
1855     SysFreeString(V_BSTR(&name));
1856     ok(hres == S_OK, "item failed: %08x\n", hres);
1857     if(!expect_success) {
1858         ok(disp == NULL, "disp != NULL\n");
1859         return NULL;
1860     }
1861
1862     ok(disp != NULL, "disp == NULL\n");
1863     if(!disp)
1864         return NULL;
1865
1866     elem = get_elem_iface((IUnknown*)disp);
1867     IDispatch_Release(disp);
1868
1869     return elem;
1870 }
1871
1872 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1873 {
1874     IHTMLDocument3 *doc3;
1875     IHTMLElement *elem;
1876     BSTR tmp;
1877     HRESULT hres;
1878
1879     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1880     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1881
1882     tmp = SysAllocString(id);
1883     hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1884     SysFreeString(tmp);
1885     ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1886
1887     IHTMLDocument3_Release(doc3);
1888
1889     return elem;
1890 }
1891
1892 static void test_select_elem(IHTMLSelectElement *select)
1893 {
1894     test_select_type(select, "select-one");
1895     test_select_length(select, 2);
1896     test_select_selidx(select, 0);
1897     test_select_put_selidx(select, 1);
1898
1899     test_select_set_value(select, "val1");
1900     test_select_value(select, "val1");
1901
1902     test_select_get_disabled(select, VARIANT_FALSE);
1903     test_select_set_disabled(select, VARIANT_TRUE);
1904     test_select_set_disabled(select, VARIANT_FALSE);
1905 }
1906
1907 static void test_create_option_elem(IHTMLDocument2 *doc)
1908 {
1909     IHTMLOptionElement *option;
1910
1911     option = create_option_elem(doc, "test text", "test value");
1912
1913     test_option_put_text(option, "new text");
1914     test_option_put_value(option, "new value");
1915
1916     IHTMLOptionElement_Release(option);
1917 }
1918
1919 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1920 {
1921     IHTMLBodyElement *body;
1922     IHTMLTxtRange *range;
1923     IHTMLElement *elem;
1924     HRESULT hres;
1925
1926     hres = IHTMLDocument2_get_body(doc, &elem);
1927     ok(hres == S_OK, "get_body failed: %08x\n", hres);
1928
1929     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1930     IHTMLElement_Release(elem);
1931
1932     hres = IHTMLBodyElement_createTextRange(body, &range);
1933     IHTMLBodyElement_Release(body);
1934     ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1935
1936     return range;
1937 }
1938
1939 static void test_txtrange(IHTMLDocument2 *doc)
1940 {
1941     IHTMLTxtRange *body_range, *range, *range2;
1942     IHTMLSelectionObject *selection;
1943     IDispatch *disp_range;
1944     HRESULT hres;
1945
1946     body_range = test_create_body_range(doc);
1947
1948     test_range_text(body_range, "test abc 123\r\nit's text");
1949
1950     hres = IHTMLTxtRange_duplicate(body_range, &range);
1951     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1952
1953     hres = IHTMLTxtRange_duplicate(body_range, &range2);
1954     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1955     test_range_isequal(range, range2, VARIANT_TRUE);
1956
1957     test_range_text(range, "test abc 123\r\nit's text");
1958     test_range_text(body_range, "test abc 123\r\nit's text");
1959
1960     test_range_collapse(range, TRUE);
1961     test_range_isequal(range, range2, VARIANT_FALSE);
1962     test_range_inrange(range, range2, VARIANT_FALSE);
1963     test_range_inrange(range2, range, VARIANT_TRUE);
1964     IHTMLTxtRange_Release(range2);
1965
1966     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1967     test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1968     test_range_move(range, characterW, 2, 2);
1969     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1970
1971     test_range_collapse(range, FALSE);
1972     test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1973
1974     test_range_collapse(range, FALSE);
1975     test_range_expand(range, wordW, VARIANT_TRUE, "123");
1976     test_range_expand(range, wordW, VARIANT_FALSE, "123");
1977     test_range_move(range, characterW, 2, 2);
1978     test_range_expand(range, wordW, VARIANT_TRUE, "123");
1979     test_range_moveend(range, characterW, -5, -5);
1980     test_range_text(range, NULL);
1981     test_range_moveend(range, characterW, 3, 3);
1982     test_range_text(range, "c 1");
1983     test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1984     test_range_collapse(range, TRUE);
1985     test_range_move(range, characterW, 4, 4);
1986     test_range_moveend(range, characterW, 1, 1);
1987     test_range_text(range, " ");
1988     test_range_move(range, wordW, 1, 1);
1989     test_range_moveend(range, characterW, 2, 2);
1990     test_range_text(range, "ab");
1991
1992     IHTMLTxtRange_Release(range);
1993
1994     hres = IHTMLTxtRange_duplicate(body_range, &range);
1995     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1996
1997     test_range_text(range, "test abc 123\r\nit's text");
1998     test_range_move(range, characterW, 3, 3);
1999     test_range_moveend(range, characterW, 1, 1);
2000     test_range_text(range, "t");
2001     test_range_moveend(range, characterW, 3, 3);
2002     test_range_text(range, "t ab");
2003     test_range_moveend(range, characterW, -2, -2);
2004     test_range_text(range, "t ");
2005     test_range_move(range, characterW, 6, 6);
2006     test_range_moveend(range, characterW, 3, 3);
2007     test_range_text(range, "123");
2008     test_range_moveend(range, characterW, 2, 2);
2009     test_range_text(range, "123\r\ni");
2010
2011     IHTMLTxtRange_Release(range);
2012
2013     hres = IHTMLTxtRange_duplicate(body_range, &range);
2014     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2015
2016     test_range_move(range, wordW, 1, 1);
2017     test_range_moveend(range, characterW, 2, 2);
2018     test_range_text(range, "ab");
2019
2020     test_range_move(range, characterW, -2, -2);
2021     test_range_moveend(range, characterW, 2, 2);
2022     test_range_text(range, "t ");
2023
2024     test_range_move(range, wordW, 3, 3);
2025     test_range_move(range, wordW, -2, -2);
2026     test_range_moveend(range, characterW, 2, 2);
2027     test_range_text(range, "ab");
2028
2029     test_range_move(range, characterW, -6, -5);
2030     test_range_moveend(range, characterW, -1, 0);
2031     test_range_moveend(range, characterW, -6, 0);
2032     test_range_move(range, characterW, 2, 2);
2033     test_range_moveend(range, characterW, 2, 2);
2034     test_range_text(range, "st");
2035     test_range_moveend(range, characterW, -6, -4);
2036     test_range_moveend(range, characterW, 2, 2);
2037
2038     IHTMLTxtRange_Release(range);
2039
2040     hres = IHTMLTxtRange_duplicate(body_range, &range);
2041     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2042
2043     test_range_move(range, wordW, 2, 2);
2044     test_range_moveend(range, characterW, 2, 2);
2045     test_range_text(range, "12");
2046
2047     test_range_move(range, characterW, 15, 14);
2048     test_range_move(range, characterW, -2, -2);
2049     test_range_moveend(range, characterW, 3, 2);
2050     test_range_text(range, "t");
2051     test_range_moveend(range, characterW, -1, -1);
2052     test_range_text(range, "t");
2053     test_range_expand(range, wordW, VARIANT_TRUE, "text");
2054     test_range_move(range, characterW, -2, -2);
2055     test_range_moveend(range, characterW, 2, 2);
2056     test_range_text(range, "s ");
2057     test_range_move(range, characterW, 100, 7);
2058     test_range_move(range, wordW, 1, 0);
2059     test_range_move(range, characterW, -2, -2);
2060     test_range_moveend(range, characterW, 3, 2);
2061     test_range_text(range, "t");
2062
2063     IHTMLTxtRange_Release(range);
2064
2065     hres = IHTMLTxtRange_duplicate(body_range, &range);
2066     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2067
2068     test_range_collapse(range, TRUE);
2069     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2070     test_range_put_text(range, "word");
2071     test_range_text(body_range, "wordabc 123\r\nit's text");
2072     test_range_text(range, NULL);
2073     test_range_moveend(range, characterW, 3, 3);
2074     test_range_text(range, "abc");
2075     test_range_movestart(range, characterW, -2, -2);
2076     test_range_text(range, "rdabc");
2077     test_range_movestart(range, characterW, 3, 3);
2078     test_range_text(range, "bc");
2079     test_range_movestart(range, characterW, 4, 4);
2080     test_range_text(range, NULL);
2081     test_range_movestart(range, characterW, -3, -3);
2082     test_range_text(range, "c 1");
2083     test_range_movestart(range, characterW, -7, -6);
2084     test_range_text(range, "wordabc 1");
2085     test_range_movestart(range, characterW, 100, 22);
2086     test_range_text(range, NULL);
2087
2088     IHTMLTxtRange_Release(range);
2089     IHTMLTxtRange_Release(body_range);
2090
2091     hres = IHTMLDocument2_get_selection(doc, &selection);
2092     ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
2093
2094     hres = IHTMLSelectionObject_createRange(selection, &disp_range);
2095     ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
2096     IHTMLSelectionObject_Release(selection);
2097
2098     hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
2099     ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
2100     IDispatch_Release(disp_range);
2101
2102     test_range_text(range, NULL);
2103     test_range_moveend(range, characterW, 3, 3);
2104     test_range_text(range, "wor");
2105     test_range_parent(range, ET_BODY);
2106     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2107     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2108     test_range_move(range, characterW, 3, 3);
2109     test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
2110     test_range_moveend(range, characterW, -4, -4);
2111     test_range_put_text(range, "abc def ");
2112     test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
2113     test_range_move(range, wordW, 1, 1);
2114     test_range_movestart(range, characterW, -1, -1);
2115     test_range_text(range, " ");
2116     test_range_move(range, wordW, 1, 1);
2117     test_range_moveend(range, characterW, 3, 3);
2118     test_range_text(range, "def");
2119     test_range_put_text(range, "xyz");
2120     test_range_moveend(range, characterW, 1, 1);
2121     test_range_move(range, wordW, 1, 1);
2122     test_range_moveend(range, characterW, 2, 2);
2123     test_range_text(range, "ab");
2124
2125     IHTMLTxtRange_Release(range);
2126 }
2127
2128 static void test_txtrange2(IHTMLDocument2 *doc)
2129 {
2130     IHTMLTxtRange *range;
2131
2132     range = test_create_body_range(doc);
2133
2134     test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
2135     test_range_move(range, characterW, 5, 5);
2136     test_range_moveend(range, characterW, 1, 1);
2137     test_range_text(range, "2");
2138     test_range_move(range, characterW, -3, -3);
2139     test_range_moveend(range, characterW, 3, 3);
2140     test_range_text(range, "c\r\n\r\n1");
2141     test_range_collapse(range, VARIANT_FALSE);
2142     test_range_moveend(range, characterW, 4, 4);
2143     test_range_text(range, "23");
2144     test_range_moveend(range, characterW, 1, 1);
2145     test_range_text(range, "23\r\n\r\n\r\nd");
2146     test_range_moveend(range, characterW, -1, -1);
2147     test_range_text(range, "23");
2148     test_range_moveend(range, characterW, -1, -1);
2149     test_range_text(range, "23");
2150     test_range_moveend(range, characterW, -2, -2);
2151     test_range_text(range, "2");
2152
2153     IHTMLTxtRange_Release(range);
2154 }
2155
2156 static void test_compatmode(IHTMLDocument2 *doc)
2157 {
2158     IHTMLDocument5 *doc5;
2159     BSTR mode;
2160     HRESULT hres;
2161
2162     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2163     ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2164     if(FAILED(hres))
2165         return;
2166
2167     hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2168     IHTMLDocument5_Release(doc5);
2169     ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2170     ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
2171     SysFreeString(mode);
2172 }
2173
2174 static void test_location(IHTMLDocument2 *doc)
2175 {
2176     IHTMLLocation *location, *location2;
2177     ULONG ref;
2178     HRESULT hres;
2179
2180     hres = IHTMLDocument2_get_location(doc, &location);
2181     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2182
2183     hres = IHTMLDocument2_get_location(doc, &location2);
2184     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2185
2186     ok(location == location2, "location != location2\n");
2187
2188     test_ifaces((IUnknown*)location, location_iids);
2189
2190     IHTMLLocation_Release(location2);
2191     ref = IHTMLLocation_Release(location);
2192     ok(!ref, "location chould be destroyed here\n");
2193 }
2194
2195 static void test_navigator(IHTMLDocument2 *doc)
2196 {
2197     IHTMLWindow2 *window;
2198     IOmNavigator *navigator, *navigator2;
2199     ULONG ref;
2200     BSTR bstr;
2201     HRESULT hres;
2202
2203     static const WCHAR v40[] = {'4','.','0'};
2204
2205     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2206     ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
2207
2208     hres = IHTMLWindow2_get_navigator(window, &navigator);
2209     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2210     ok(navigator != NULL, "navigator == NULL\n");
2211     test_disp((IUnknown*)navigator, &IID_IOmNavigator);
2212
2213     hres = IHTMLWindow2_get_navigator(window, &navigator2);
2214     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2215     ok(navigator != navigator2, "navigator2 != navihgator\n");
2216
2217     IHTMLWindow2_Release(window);
2218     IOmNavigator_Release(navigator2);
2219
2220     hres = IOmNavigator_get_appCodeName(navigator, &bstr);
2221     ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
2222     ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
2223     SysFreeString(bstr);
2224
2225     bstr = NULL;
2226     hres = IOmNavigator_get_platform(navigator, &bstr);
2227     ok(hres == S_OK, "get_platform failed: %08x\n", hres);
2228     ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
2229     SysFreeString(bstr);
2230
2231     bstr = NULL;
2232     hres = IOmNavigator_get_appVersion(navigator, &bstr);
2233     ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
2234     ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", dbgstr_w(bstr));
2235     SysFreeString(bstr);
2236
2237     ref = IOmNavigator_Release(navigator);
2238     ok(!ref, "navigator should be destroyed here\n");
2239 }
2240
2241 static void test_current_style(IHTMLCurrentStyle *current_style)
2242 {
2243     BSTR str;
2244     HRESULT hres;
2245
2246     test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle);
2247     test_ifaces((IUnknown*)current_style, cstyle_iids);
2248
2249     hres = IHTMLCurrentStyle_get_display(current_style, &str);
2250     ok(hres == S_OK, "get_display failed: %08x\n", hres);
2251     ok(!strcmp_wa(str, "block"), "get_display returned %s\n", dbgstr_w(str));
2252     SysFreeString(str);
2253 }
2254
2255 static void test_style2(IHTMLStyle2 *style2)
2256 {
2257     BSTR str;
2258     HRESULT hres;
2259
2260     str = (void*)0xdeadbeef;
2261     hres = IHTMLStyle2_get_position(style2, &str);
2262     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2263     ok(!str, "str != NULL\n");
2264
2265     str = a2bstr("absolute");
2266     hres = IHTMLStyle2_put_position(style2, str);
2267     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2268     SysFreeString(str);
2269
2270     str = NULL;
2271     hres = IHTMLStyle2_get_position(style2, &str);
2272     ok(hres == S_OK, "get_position failed: %08x\n", hres);
2273     ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", dbgstr_w(str));
2274     SysFreeString(str);
2275 }
2276
2277 static void test_default_style(IHTMLStyle *style)
2278 {
2279     IHTMLStyle2 *style2;
2280     VARIANT_BOOL b;
2281     VARIANT v;
2282     BSTR str;
2283     HRESULT hres;
2284     float f;
2285
2286     test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
2287     test_ifaces((IUnknown*)style, style_iids);
2288
2289     str = (void*)0xdeadbeef;
2290     hres = IHTMLStyle_get_fontFamily(style, &str);
2291     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2292     ok(!str, "fontFamily = %s\n", dbgstr_w(str));
2293
2294     str = (void*)0xdeadbeef;
2295     hres = IHTMLStyle_get_fontWeight(style, &str);
2296     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2297     ok(!str, "fontWeight = %s\n", dbgstr_w(str));
2298
2299     str = (void*)0xdeadbeef;
2300     hres = IHTMLStyle_get_display(style, &str);
2301     ok(hres == S_OK, "get_display failed: %08x\n", hres);
2302     ok(!str, "display = %s\n", dbgstr_w(str));
2303
2304     str = (void*)0xdeadbeef;
2305     hres = IHTMLStyle_get_visibility(style, &str);
2306     ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2307     ok(!str, "visibility = %s\n", dbgstr_w(str));
2308
2309     V_VT(&v) = VT_NULL;
2310     hres = IHTMLStyle_get_fontSize(style, &v);
2311     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2312     ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2313     ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
2314
2315     V_VT(&v) = VT_NULL;
2316     hres = IHTMLStyle_get_color(style, &v);
2317     ok(hres == S_OK, "get_color failed: %08x\n", hres);
2318     ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2319     ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2320
2321     b = 0xfefe;
2322     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2323     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2324     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2325
2326     b = 0xfefe;
2327     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2328     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2329     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2330
2331     V_VT(&v) = VT_EMPTY;
2332     hres = IHTMLStyle_get_width(style, &v);
2333     ok(hres == S_OK, "get_width failed: %08x\n", hres);
2334     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2335     ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2336
2337     V_VT(&v) = VT_BSTR;
2338     V_BSTR(&v) = a2bstr("auto");
2339     hres = IHTMLStyle_put_width(style, v);
2340     ok(hres == S_OK, "put_width failed: %08x\n", hres);
2341     VariantClear(&v);
2342
2343     V_VT(&v) = VT_EMPTY;
2344     hres = IHTMLStyle_get_width(style, &v);
2345     ok(hres == S_OK, "get_width failed: %08x\n", hres);
2346     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2347     ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2348     VariantClear(&v);
2349
2350     /* margin tests */
2351     str = (void*)0xdeadbeef;
2352     hres = IHTMLStyle_get_margin(style, &str);
2353     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2354     ok(!str, "margin = %s\n", dbgstr_w(str));
2355
2356     str = a2bstr("1");
2357     hres = IHTMLStyle_put_margin(style, str);
2358     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2359     SysFreeString(str);
2360
2361     hres = IHTMLStyle_get_margin(style, &str);
2362     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2363     ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2364
2365     hres = IHTMLStyle_put_margin(style, NULL);
2366     ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2367
2368     str = NULL;
2369     hres = IHTMLStyle_get_border(style, &str);
2370     ok(hres == S_OK, "get_border failed: %08x\n", hres);
2371     ok(!str || !*str, "str is not empty\n");
2372     SysFreeString(str);
2373
2374     str = a2bstr("1px");
2375     hres = IHTMLStyle_put_border(style, str);
2376     ok(hres == S_OK, "get_border failed: %08x\n", hres);
2377     SysFreeString(str);
2378
2379     V_VT(&v) = VT_EMPTY;
2380     hres = IHTMLStyle_get_left(style, &v);
2381     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2382     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2383     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2384     VariantClear(&v);
2385
2386     /* Test posLeft */
2387     hres = IHTMLStyle_get_posLeft(style, NULL);
2388     ok(hres == E_POINTER, "get_left failed: %08x\n", hres);
2389
2390     f = 1.0f;
2391     hres = IHTMLStyle_get_posLeft(style, &f);
2392     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2393     ok(f == 0.0, "expected 0.0 got %f\n", f);
2394
2395     hres = IHTMLStyle_put_posLeft(style, 4.9f);
2396     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2397
2398     hres = IHTMLStyle_get_posLeft(style, &f);
2399     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2400     ok(f == 4.0, "expected 4.0 got %f\n", f);
2401
2402     /* Ensure left is updated correctly. */
2403     V_VT(&v) = VT_EMPTY;
2404     hres = IHTMLStyle_get_left(style, &v);
2405     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2406     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2407     ok(!strcmp_wa(V_BSTR(&v), "4px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2408     VariantClear(&v);
2409
2410     /* Test left */
2411     V_VT(&v) = VT_BSTR;
2412     V_BSTR(&v) = a2bstr("3px");
2413     hres = IHTMLStyle_put_left(style, v);
2414     ok(hres == S_OK, "put_left failed: %08x\n", hres);
2415     VariantClear(&v);
2416
2417     hres = IHTMLStyle_get_posLeft(style, &f);
2418     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2419     ok(f == 3.0, "expected 3.0 got %f\n", f);
2420
2421     V_VT(&v) = VT_EMPTY;
2422     hres = IHTMLStyle_get_left(style, &v);
2423     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2424     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2425     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2426     VariantClear(&v);
2427
2428     V_VT(&v) = VT_NULL;
2429     hres = IHTMLStyle_put_left(style, v);
2430     ok(hres == S_OK, "put_left failed: %08x\n", hres);
2431
2432     V_VT(&v) = VT_EMPTY;
2433     hres = IHTMLStyle_get_left(style, &v);
2434     ok(hres == S_OK, "get_left failed: %08x\n", hres);
2435     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2436     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2437     VariantClear(&v);
2438
2439     V_VT(&v) = VT_EMPTY;
2440     hres = IHTMLStyle_get_top(style, &v);
2441     ok(hres == S_OK, "get_top failed: %08x\n", hres);
2442     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2443     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2444     VariantClear(&v);
2445
2446     V_VT(&v) = VT_BSTR;
2447     V_BSTR(&v) = a2bstr("3px");
2448     hres = IHTMLStyle_put_top(style, v);
2449     ok(hres == S_OK, "put_top failed: %08x\n", hres);
2450     VariantClear(&v);
2451
2452     V_VT(&v) = VT_EMPTY;
2453     hres = IHTMLStyle_get_top(style, &v);
2454     ok(hres == S_OK, "get_top failed: %08x\n", hres);
2455     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2456     ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2457     VariantClear(&v);
2458
2459     V_VT(&v) = VT_NULL;
2460     hres = IHTMLStyle_put_top(style, v);
2461     ok(hres == S_OK, "put_top failed: %08x\n", hres);
2462
2463     V_VT(&v) = VT_EMPTY;
2464     hres = IHTMLStyle_get_top(style, &v);
2465     ok(hres == S_OK, "get_top failed: %08x\n", hres);
2466     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2467     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2468     VariantClear(&v);
2469
2470     V_VT(&v) = VT_EMPTY;
2471     hres = IHTMLStyle_get_height(style, &v);
2472     ok(hres == S_OK, "get_height failed: %08x\n", hres);
2473     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2474     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2475     VariantClear(&v);
2476
2477     V_VT(&v) = VT_BSTR;
2478     V_BSTR(&v) = a2bstr("64px");
2479     hres = IHTMLStyle_put_height(style, v);
2480     ok(hres == S_OK, "put_height failed: %08x\n", hres);
2481     VariantClear(&v);
2482
2483     V_VT(&v) = VT_EMPTY;
2484     hres = IHTMLStyle_get_height(style, &v);
2485     ok(hres == S_OK, "get_height failed: %08x\n", hres);
2486     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2487     ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2488     VariantClear(&v);
2489
2490     str = (void*)0xdeadbeef;
2491     hres = IHTMLStyle_get_cursor(style, &str);
2492     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2493     ok(!str, "get_cursor != NULL\n");
2494     SysFreeString(str);
2495
2496     str = a2bstr("default");
2497     hres = IHTMLStyle_put_cursor(style, str);
2498     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2499     SysFreeString(str);
2500
2501     str = NULL;
2502     hres = IHTMLStyle_get_cursor(style, &str);
2503     ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2504     ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", dbgstr_w(str));
2505     SysFreeString(str);
2506
2507     V_VT(&v) = VT_EMPTY;
2508     hres = IHTMLStyle_get_verticalAlign(style, &v);
2509     ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
2510     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2511     ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2512     VariantClear(&v);
2513
2514     V_VT(&v) = VT_BSTR;
2515     V_BSTR(&v) = a2bstr("middle");
2516     hres = IHTMLStyle_put_verticalAlign(style, v);
2517     ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
2518     VariantClear(&v);
2519
2520     V_VT(&v) = VT_EMPTY;
2521     hres = IHTMLStyle_get_verticalAlign(style, &v);
2522     ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2523     ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2524     ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2525     VariantClear(&v);
2526
2527     str = (void*)0xdeadbeef;
2528     hres = IHTMLStyle_get_textAlign(style, &str);
2529     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2530     ok(!str, "textAlign != NULL\n");
2531
2532     str = a2bstr("center");
2533     hres = IHTMLStyle_put_textAlign(style, str);
2534     ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
2535     SysFreeString(str);
2536
2537     str = NULL;
2538     hres = IHTMLStyle_get_textAlign(style, &str);
2539     ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2540     ok(!strcmp_wa(str, "center"), "textAlign = %s\n", dbgstr_w(V_BSTR(&v)));
2541     SysFreeString(str);
2542
2543     str = (void*)0xdeadbeef;
2544     hres = IHTMLStyle_get_filter(style, &str);
2545     ok(hres == S_OK, "get_filter failed: %08x\n", hres);
2546     ok(!str, "filter != NULL\n");
2547
2548     str = a2bstr("alpha(opacity=100)");
2549     hres = IHTMLStyle_put_filter(style, str);
2550     ok(hres == S_OK, "put_filter failed: %08x\n", hres);
2551     SysFreeString(str);
2552
2553     V_VT(&v) = VT_EMPTY;
2554     hres = IHTMLStyle_get_zIndex(style, &v);
2555     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2556     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2557     ok(!V_I4(&v), "V_I4(v) != 0\n");
2558     VariantClear(&v);
2559
2560     V_VT(&v) = VT_BSTR;
2561     V_BSTR(&v) = a2bstr("1");
2562     hres = IHTMLStyle_put_zIndex(style, v);
2563     ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
2564     VariantClear(&v);
2565
2566     V_VT(&v) = VT_EMPTY;
2567     hres = IHTMLStyle_get_zIndex(style, &v);
2568     ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2569     ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2570     ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
2571     VariantClear(&v);
2572
2573     hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
2574     ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
2575     if(SUCCEEDED(hres)) {
2576         test_style2(style2);
2577         IHTMLStyle2_Release(style2);
2578     }
2579 }
2580
2581 static void test_default_selection(IHTMLDocument2 *doc)
2582 {
2583     IHTMLSelectionObject *selection;
2584     IHTMLTxtRange *range;
2585     IDispatch *disp;
2586     BSTR str;
2587     HRESULT hres;
2588
2589     hres = IHTMLDocument2_get_selection(doc, &selection);
2590     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2591
2592     hres = IHTMLSelectionObject_get_type(selection, &str);
2593     ok(hres == S_OK, "get_type failed: %08x\n", hres);
2594     ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2595     SysFreeString(str);
2596
2597     hres = IHTMLSelectionObject_createRange(selection, &disp);
2598     IHTMLSelectionObject_Release(selection);
2599     ok(hres == S_OK, "createRange failed: %08x\n", hres);
2600
2601     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2602     IDispatch_Release(disp);
2603     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2604
2605     test_range_text(range, NULL);
2606     IHTMLTxtRange_Release(range);
2607 }
2608
2609 static void test_default_body(IHTMLBodyElement *body)
2610 {
2611     long l;
2612     BSTR bstr;
2613     HRESULT hres;
2614     VARIANT v;
2615     WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2616     WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2617     WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2618
2619     bstr = (void*)0xdeadbeef;
2620     hres = IHTMLBodyElement_get_background(body, &bstr);
2621     ok(hres == S_OK, "get_background failed: %08x\n", hres);
2622     ok(bstr == NULL, "bstr != NULL\n");
2623
2624     l = elem_get_scroll_height((IUnknown*)body);
2625     ok(l != -1, "scrollHeight == -1\n");
2626     l = elem_get_scroll_width((IUnknown*)body);
2627     ok(l != -1, "scrollWidth == -1\n");
2628     l = elem_get_scroll_top((IUnknown*)body);
2629     ok(!l, "scrollTop = %ld\n", l);
2630     elem_get_scroll_left((IUnknown*)body);
2631
2632     /* get_text tests */
2633     hres = IHTMLBodyElement_get_text(body, &v);
2634     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2635     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2636     ok(bstr == NULL, "bstr != NULL\n");
2637
2638
2639     /* get_text - Invalid Text */
2640     V_VT(&v) = VT_BSTR;
2641     V_BSTR(&v) = SysAllocString(sTextInvalid);
2642     hres = IHTMLBodyElement_put_text(body, v);
2643     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2644
2645     V_VT(&v) = VT_NULL;
2646     hres = IHTMLBodyElement_get_text(body, &v);
2647     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2648     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2649     ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2650     VariantClear(&v);
2651
2652     /* get_text - Valid Text */
2653     V_VT(&v) = VT_BSTR;
2654     V_BSTR(&v) = SysAllocString(sBodyText);
2655     hres = IHTMLBodyElement_put_text(body, v);
2656     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2657
2658     V_VT(&v) = VT_NULL;
2659     hres = IHTMLBodyElement_get_text(body, &v);
2660     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2661     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2662     ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2663     VariantClear(&v);
2664 }
2665
2666 static void test_body_funs(IHTMLBodyElement *body)
2667 {
2668     static WCHAR sRed[] = {'r','e','d',0};
2669     static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2670     VARIANT vbg;
2671     VARIANT vDefaultbg;
2672     HRESULT hres;
2673
2674     hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2675     ok(hres == S_OK, "get_background failed: %08x\n", hres);
2676     ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2677
2678     V_VT(&vbg) = VT_BSTR;
2679     V_BSTR(&vbg) = SysAllocString(sRed);
2680     hres = IHTMLBodyElement_put_bgColor(body, vbg);
2681     ok(hres == S_OK, "get_background failed: %08x\n", hres);
2682     VariantClear(&vbg);
2683
2684     hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2685     ok(hres == S_OK, "get_background failed: %08x\n", hres);
2686     ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2687     ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2688     VariantClear(&vbg);
2689
2690     /* Restore Originial */
2691     hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2692     ok(hres == S_OK, "get_background failed: %08x\n", hres);
2693     VariantClear(&vDefaultbg);
2694 }
2695
2696 static void test_window(IHTMLDocument2 *doc)
2697 {
2698     IHTMLWindow2 *window, *window2, *self;
2699     IHTMLDocument2 *doc2 = NULL;
2700     IDispatch *disp;
2701     HRESULT hres;
2702
2703     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2704     ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2705     test_ifaces((IUnknown*)window, window_iids);
2706     test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2707
2708     hres = IHTMLWindow2_get_document(window, &doc2);
2709     ok(hres == S_OK, "get_document failed: %08x\n", hres);
2710     ok(doc2 != NULL, "doc2 == NULL\n");
2711
2712     IHTMLDocument_Release(doc2);
2713
2714     hres = IHTMLWindow2_get_window(window, &window2);
2715     ok(hres == S_OK, "get_window failed: %08x\n", hres);
2716     ok(window2 != NULL, "window2 == NULL\n");
2717
2718     hres = IHTMLWindow2_get_self(window, &self);
2719     ok(hres == S_OK, "get_window failed: %08x\n", hres);
2720     ok(window2 != NULL, "self == NULL\n");
2721
2722     ok(self == window2, "self != window2\n");
2723
2724     IHTMLWindow2_Release(window2);
2725     IHTMLWindow2_Release(self);
2726
2727     disp = NULL;
2728     hres = IHTMLDocument2_get_Script(doc, &disp);
2729     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2730     ok(disp == (void*)window, "disp != window\n");
2731     IDispatch_Release(disp);
2732
2733     IHTMLWindow2_Release(window);
2734 }
2735
2736 static void test_defaults(IHTMLDocument2 *doc)
2737 {
2738     IHTMLStyleSheetsCollection *stylesheetcol;
2739     IHTMLCurrentStyle *cstyle;
2740     IHTMLBodyElement *body;
2741     IHTMLElement2 *elem2;
2742     IHTMLElement *elem;
2743     IHTMLStyle *style;
2744     long l;
2745     HRESULT hres;
2746
2747     hres = IHTMLDocument2_get_body(doc, &elem);
2748     ok(hres == S_OK, "get_body failed: %08x\n", hres);
2749
2750     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2751     ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2752     test_default_body(body);
2753     test_body_funs(body);
2754     IHTMLBodyElement_Release(body);
2755
2756     hres = IHTMLElement_get_style(elem, &style);
2757     ok(hres == S_OK, "get_style failed: %08x\n", hres);
2758
2759     test_default_style(style);
2760     test_window(doc);
2761     test_compatmode(doc);
2762     test_location(doc);
2763     test_navigator(doc);
2764
2765     IHTMLStyle_Release(style);
2766
2767     elem2 = get_elem2_iface((IUnknown*)elem);
2768     hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
2769     ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
2770     if(SUCCEEDED(hres)) {
2771         test_current_style(cstyle);
2772         IHTMLCurrentStyle_Release(cstyle);
2773     }
2774     IHTMLElement2_Release(elem2);
2775
2776     IHTMLElement_Release(elem);
2777
2778     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2779     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2780
2781     l = 0xdeadbeef;
2782     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2783     ok(hres == S_OK, "get_length failed: %08x\n", hres);
2784     ok(l == 0, "length = %ld\n", l);
2785
2786     IHTMLStyleSheetsCollection_Release(stylesheetcol);
2787
2788     test_default_selection(doc);
2789     test_doc_title(doc, "");
2790 }
2791
2792 static void test_tr_elem(IHTMLElement *elem)
2793 {
2794     IHTMLElementCollection *col;
2795     IHTMLTableRow *row;
2796     HRESULT hres;
2797
2798     static const elem_type_t cell_types[] = {ET_TD,ET_TD};
2799
2800     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
2801     ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
2802     if(FAILED(hres))
2803         return;
2804
2805     col = NULL;
2806     hres = IHTMLTableRow_get_cells(row, &col);
2807     ok(hres == S_OK, "get_cells failed: %08x\n", hres);
2808     ok(col != NULL, "get_cells returned NULL\n");
2809
2810     test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
2811     IHTMLElementCollection_Release(col);
2812
2813     IHTMLTable_Release(row);
2814 }
2815
2816 static void test_table_elem(IHTMLElement *elem)
2817 {
2818     IHTMLElementCollection *col;
2819     IHTMLTable *table;
2820     HRESULT hres;
2821
2822     static const elem_type_t row_types[] = {ET_TR,ET_TR};
2823
2824     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2825     ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2826     if(FAILED(hres))
2827         return;
2828
2829     col = NULL;
2830     hres = IHTMLTable_get_rows(table, &col);
2831     ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2832     ok(col != NULL, "get_ros returned NULL\n");
2833
2834     test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2835     IHTMLElementCollection_Release(col);
2836
2837     IHTMLTable_Release(table);
2838 }
2839
2840 static void doc_write(IHTMLDocument2 *doc, const char *text)
2841 {
2842     SAFEARRAYBOUND dim;
2843     SAFEARRAY *sa;
2844     VARIANT *var;
2845     BSTR str;
2846     HRESULT hres;
2847
2848     dim.lLbound = 0;
2849     dim.cElements = 1;
2850     sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
2851     SafeArrayAccessData(sa, (void**)&var);
2852     V_VT(var) = VT_BSTR;
2853     V_BSTR(var) = str = a2bstr(text);
2854     SafeArrayUnaccessData(sa);
2855
2856     hres = IHTMLDocument2_write(doc, sa);
2857     ok(hres == S_OK, "write failed: %08x\n", hres);
2858
2859     SysFreeString(str);
2860     SafeArrayDestroy(sa);
2861 }
2862
2863 static void test_iframe_elem(IHTMLElement *elem)
2864 {
2865     IHTMLElementCollection *col;
2866     IHTMLDocument2 *content_doc;
2867     IHTMLWindow2 *content_window;
2868     IHTMLFrameBase2 *base2;
2869     IDispatch *disp;
2870     VARIANT errv;
2871     BSTR str;
2872     HRESULT hres;
2873
2874     static const elem_type_t all_types[] = {
2875         ET_HTML,
2876         ET_HEAD,
2877         ET_TITLE,
2878         ET_BODY,
2879         ET_BR
2880     };
2881
2882     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
2883     ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
2884
2885     content_window = NULL;
2886     hres = IHTMLFrameBase2_get_contentWindow(base2, &content_window);
2887     IHTMLFrameBase2_Release(base2);
2888     ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
2889     ok(content_window != NULL, "contentWindow = NULL\n");
2890
2891     content_doc = NULL;
2892     hres = IHTMLWindow2_get_document(content_window, &content_doc);
2893     IHTMLWindow2_Release(content_window);
2894     ok(hres == S_OK, "get_document failed: %08x\n", hres);
2895     ok(content_doc != NULL, "content_doc = NULL\n");
2896
2897     str = a2bstr("text/html");
2898     V_VT(&errv) = VT_ERROR;
2899     disp = NULL;
2900     hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
2901     SysFreeString(str);
2902     ok(hres == S_OK, "open failed: %08x\n", hres);
2903     ok(disp != NULL, "disp == NULL\n");
2904     ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
2905     IDispatch_Release(disp);
2906
2907     doc_write(content_doc, "<html><head><title>test</title></head><body><br /></body></html>");
2908
2909     hres = IHTMLDocument2_get_all(content_doc, &col);
2910     ok(hres == S_OK, "get_all failed: %08x\n", hres);
2911     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2912     IHTMLElementCollection_Release(col);
2913
2914     hres = IHTMLDocument2_close(content_doc);
2915     ok(hres == S_OK, "close failed: %08x\n", hres);
2916
2917     IHTMLDocument2_Release(content_doc);
2918 }
2919
2920 static void test_stylesheet(IDispatch *disp)
2921 {
2922     IHTMLStyleSheetRulesCollection *col = NULL;
2923     IHTMLStyleSheet *stylesheet;
2924     HRESULT hres;
2925
2926     hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2927     ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2928
2929     hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2930     ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2931     ok(col != NULL, "col == NULL\n");
2932
2933     IHTMLStyleSheetRulesCollection_Release(col);
2934     IHTMLStyleSheet_Release(stylesheet);
2935 }
2936
2937 static void test_stylesheets(IHTMLDocument2 *doc)
2938 {
2939     IHTMLStyleSheetsCollection *col = NULL;
2940     VARIANT idx, res;
2941     long len = 0;
2942     HRESULT hres;
2943
2944     hres = IHTMLDocument2_get_styleSheets(doc, &col);
2945     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2946     ok(col != NULL, "col == NULL\n");
2947
2948     hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2949     ok(hres == S_OK, "get_length failed: %08x\n", hres);
2950     ok(len == 1, "len=%ld\n", len);
2951
2952     VariantInit(&res);
2953     V_VT(&idx) = VT_I4;
2954     V_I4(&idx) = 0;
2955
2956     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2957     ok(hres == S_OK, "item failed: %08x\n", hres);
2958     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2959     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2960     test_stylesheet(V_DISPATCH(&res));
2961     VariantClear(&res);
2962
2963     V_VT(&res) = VT_I4;
2964     V_VT(&idx) = VT_I4;
2965     V_I4(&idx) = 1;
2966
2967     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2968     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2969     ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2970     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2971     VariantClear(&res);
2972
2973     IHTMLStyleSheetsCollection_Release(col);
2974 }
2975
2976 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2977 {
2978     IDispatchEx *dispex;
2979     IHTMLDOMNode *node;
2980     DISPPARAMS dp = {NULL, NULL, 0, 0};
2981     VARIANT var;
2982     EXCEPINFO ei;
2983     long type;
2984     DISPID id;
2985     BSTR bstr;
2986     HRESULT hres;
2987
2988     static const WCHAR w0[] = {'0',0};
2989     static const WCHAR w100[] = {'1','0','0',0};
2990
2991     hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2992     ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2993
2994     bstr = SysAllocString(w0);
2995     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2996     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2997     SysFreeString(bstr);
2998
2999     VariantInit(&var);
3000     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
3001     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
3002     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
3003     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
3004     node = get_node_iface((IUnknown*)V_DISPATCH(&var));
3005     type = get_node_type((IUnknown*)node);
3006     ok(type == 3, "type=%ld\n", type);
3007     IHTMLDOMNode_Release(node);
3008     VariantClear(&var);
3009
3010     bstr = SysAllocString(w100);
3011     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
3012     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
3013     SysFreeString(bstr);
3014
3015     IDispatchEx_Release(dispex);
3016 }
3017
3018
3019
3020 static void test_elems(IHTMLDocument2 *doc)
3021 {
3022     IHTMLElementCollection *col;
3023     IHTMLDOMChildrenCollection *child_col;
3024     IHTMLElement *elem, *elem2, *elem3;
3025     IHTMLDOMNode *node, *node2;
3026     IDispatch *disp;
3027     long type;
3028     HRESULT hres;
3029
3030     static const WCHAR imgidW[] = {'i','m','g','i','d',0};
3031     static const WCHAR inW[] = {'i','n',0};
3032     static const WCHAR xW[] = {'x',0};
3033     static const WCHAR sW[] = {'s',0};
3034     static const WCHAR scW[] = {'s','c',0};
3035     static const WCHAR xxxW[] = {'x','x','x',0};
3036     static const WCHAR tblW[] = {'t','b','l',0};
3037     static const WCHAR row2W[] = {'r','o','w','2',0};
3038     static const WCHAR ifrW[] = {'i','f','r',0};
3039
3040     static const elem_type_t all_types[] = {
3041         ET_HTML,
3042         ET_HEAD,
3043         ET_TITLE,
3044         ET_STYLE,
3045         ET_BODY,
3046         ET_COMMENT,
3047         ET_A,
3048         ET_INPUT,
3049         ET_SELECT,
3050         ET_OPTION,
3051         ET_OPTION,
3052         ET_TEXTAREA,
3053         ET_TABLE,
3054         ET_TBODY,
3055         ET_TR,
3056         ET_TR,
3057         ET_TD,
3058         ET_TD,
3059         ET_SCRIPT,
3060         ET_TEST,
3061         ET_IMG,
3062         ET_IFRAME
3063     };
3064
3065     static const elem_type_t item_types[] = {
3066         ET_A,
3067         ET_OPTION,
3068         ET_TEXTAREA
3069     };
3070
3071     hres = IHTMLDocument2_get_all(doc, &col);
3072     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3073     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
3074     test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
3075     IHTMLElementCollection_Release(col);
3076
3077     elem = get_doc_elem(doc);
3078     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
3079     hres = IHTMLElement_get_all(elem, &disp);
3080     IHTMLElement_Release(elem);
3081     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3082
3083     hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
3084     IDispatch_Release(disp);
3085     ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
3086     test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
3087     IHTMLElementCollection_Release(col);
3088
3089     get_elem_by_id(doc, xxxW, FALSE);
3090     elem = get_doc_elem_by_id(doc, xxxW);
3091     ok(!elem, "elem != NULL\n");
3092
3093     elem = get_doc_elem_by_id(doc, sW);
3094     ok(elem != NULL, "elem == NULL\n");
3095     if(elem) {
3096         test_elem_type((IUnknown*)elem, ET_SELECT);
3097         test_elem_attr(elem, xxxW, NULL);
3098         test_elem_attr(elem, idW, sW);
3099         test_elem_class((IUnknown*)elem, NULL);
3100         test_elem_set_class((IUnknown*)elem, "cl");
3101         test_elem_set_class((IUnknown*)elem, NULL);
3102         test_elem_tabindex((IUnknown*)elem, 0);
3103         test_elem_set_tabindex((IUnknown*)elem, 1);
3104
3105         node = test_node_get_parent((IUnknown*)elem);
3106         ok(node != NULL, "node == NULL\n");
3107         test_node_name((IUnknown*)node, "BODY");
3108         node2 = test_node_get_parent((IUnknown*)node);
3109         IHTMLDOMNode_Release(node);
3110         ok(node2 != NULL, "node == NULL\n");
3111         test_node_name((IUnknown*)node2, "HTML");
3112         node = test_node_get_parent((IUnknown*)node2);
3113         IHTMLDOMNode_Release(node2);
3114         ok(node != NULL, "node == NULL\n");
3115         test_node_name((IUnknown*)node, "#document");
3116         type = get_node_type((IUnknown*)node);
3117         ok(type == 9, "type=%ld, expected 9\n", type);
3118         node2 = test_node_get_parent((IUnknown*)node);
3119         IHTMLDOMNode_Release(node);
3120         ok(node2 == NULL, "node != NULL\n");
3121
3122         elem2 = test_elem_get_parent((IUnknown*)elem);
3123         ok(elem2 != NULL, "elem2 == NULL\n");
3124         test_node_name((IUnknown*)elem2, "BODY");
3125         elem3 = test_elem_get_parent((IUnknown*)elem2);
3126         IHTMLElement_Release(elem2);
3127         ok(elem3 != NULL, "elem3 == NULL\n");
3128         test_node_name((IUnknown*)elem3, "HTML");
3129         elem2 = test_elem_get_parent((IUnknown*)elem3);
3130         IHTMLElement_Release(elem3);
3131         ok(elem2 == NULL, "elem2 != NULL\n");
3132
3133         test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
3134         test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
3135         test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
3136
3137         test_elem_innertext(elem, "opt1opt2");
3138
3139         IHTMLElement_Release(elem);
3140     }
3141
3142     elem = get_elem_by_id(doc, sW, TRUE);
3143     if(elem) {
3144         IHTMLSelectElement *select;
3145
3146         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
3147         ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
3148
3149         test_select_elem(select);
3150
3151         test_elem_title((IUnknown*)select, NULL);
3152         test_elem_set_title((IUnknown*)select, "Title");
3153         test_elem_title((IUnknown*)select, "Title");
3154         test_elem_offset((IUnknown*)select);
3155
3156         node = get_first_child((IUnknown*)select);
3157         ok(node != NULL, "node == NULL\n");
3158         if(node) {
3159             test_elem_type((IUnknown*)node, ET_OPTION);
3160             IHTMLDOMNode_Release(node);
3161         }
3162
3163         type = get_node_type((IUnknown*)select);
3164         ok(type == 1, "type=%ld\n", type);
3165
3166         IHTMLSelectElement_Release(select);
3167         IHTMLElement_Release(elem);
3168     }
3169
3170     elem = get_elem_by_id(doc, scW, TRUE);
3171     if(elem) {
3172         IHTMLScriptElement *script;
3173         BSTR type;
3174
3175         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
3176         ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
3177
3178         hres = IHTMLScriptElement_get_type(script, &type);
3179         ok(hres == S_OK, "get_type failed: %08x\n", hres);
3180         ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
3181         SysFreeString(type);
3182
3183         IHTMLScriptElement_Release(script);
3184     }
3185
3186     elem = get_elem_by_id(doc, inW, TRUE);
3187     if(elem) {
3188         IHTMLInputElement *input;
3189
3190         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
3191         ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3192
3193         test_elem_id((IUnknown*)elem, "in");
3194         test_elem_put_id((IUnknown*)elem, "newin");
3195         test_input_get_disabled(input, VARIANT_FALSE);
3196         test_input_set_disabled(input, VARIANT_TRUE);
3197         test_input_set_disabled(input, VARIANT_FALSE);
3198         test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
3199         test_input_get_disabled(input, VARIANT_TRUE);
3200         test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
3201         test_input_get_disabled(input, VARIANT_FALSE);
3202         test_elem_client_size((IUnknown*)elem);
3203
3204         test_node_get_value_str((IUnknown*)elem, NULL);
3205         test_node_put_value_str((IUnknown*)elem, "test");
3206         test_node_get_value_str((IUnknown*)elem, NULL);
3207         test_input_value((IUnknown*)elem, NULL);
3208         test_input_put_value((IUnknown*)elem, "test");
3209         test_input_value((IUnknown*)elem, NULL);
3210         test_elem_class((IUnknown*)elem, "testclass");
3211         test_elem_tabindex((IUnknown*)elem, 2);
3212         test_elem_set_tabindex((IUnknown*)elem, 3);
3213         test_elem_title((IUnknown*)elem, "test title");
3214
3215         test_input_get_defaultchecked(input, VARIANT_FALSE);
3216         test_input_set_defaultchecked(input, VARIANT_TRUE);
3217         test_input_set_defaultchecked(input, VARIANT_FALSE);
3218
3219         test_input_get_checked(input, VARIANT_FALSE);
3220         test_input_set_checked(input, VARIANT_TRUE);
3221         test_input_set_checked(input, VARIANT_FALSE);
3222
3223         IHTMLInputElement_Release(input);
3224         IHTMLElement_Release(elem);
3225     }
3226
3227     elem = get_elem_by_id(doc, imgidW, TRUE);
3228     if(elem) {
3229         test_img_src((IUnknown*)elem, "");
3230         test_img_set_src((IUnknown*)elem, "about:blank");
3231         test_img_alt((IUnknown*)elem, NULL);
3232         test_img_set_alt((IUnknown*)elem, "alt test");
3233         IHTMLElement_Release(elem);
3234     }
3235
3236     elem = get_doc_elem_by_id(doc, tblW);
3237     ok(elem != NULL, "elem == NULL\n");
3238     if(elem) {
3239         test_table_elem(elem);
3240         IHTMLElement_Release(elem);
3241     }
3242
3243     elem = get_doc_elem_by_id(doc, row2W);
3244     ok(elem != NULL, "elem == NULL\n");
3245     if(elem) {
3246         test_tr_elem(elem);
3247         IHTMLElement_Release(elem);
3248     }
3249
3250     elem = get_doc_elem_by_id(doc, ifrW);
3251     ok(elem != NULL, "elem == NULL\n");
3252     if(elem) {
3253         test_iframe_elem(elem);
3254         IHTMLElement_Release(elem);
3255     }
3256
3257     hres = IHTMLDocument2_get_body(doc, &elem);
3258     ok(hres == S_OK, "get_body failed: %08x\n", hres);
3259
3260     node = get_first_child((IUnknown*)elem);
3261     ok(node != NULL, "node == NULL\n");
3262     if(node) {
3263         test_ifaces((IUnknown*)node, text_iids);
3264         test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
3265
3266         node2 = get_first_child((IUnknown*)node);
3267         ok(!node2, "node2 != NULL\n");
3268
3269         type = get_node_type((IUnknown*)node);
3270         ok(type == 3, "type=%ld\n", type);
3271
3272         test_node_get_value_str((IUnknown*)node, "text test");
3273         test_node_put_value_str((IUnknown*)elem, "test text");
3274         test_node_get_value_str((IUnknown*)node, "text test");
3275
3276         IHTMLDOMNode_Release(node);
3277     }
3278
3279     child_col = get_child_nodes((IUnknown*)elem);
3280     ok(child_col != NULL, "child_coll == NULL\n");
3281     if(child_col) {
3282         long length = 0;
3283
3284         test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
3285
3286         hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
3287         ok(hres == S_OK, "get_length failed: %08x\n", hres);
3288         ok(length, "length=0\n");
3289
3290         node = get_child_item(child_col, 0);
3291         ok(node != NULL, "node == NULL\n");
3292         if(node) {
3293             type = get_node_type((IUnknown*)node);
3294             ok(type == 3, "type=%ld\n", type);
3295             IHTMLDOMNode_Release(node);
3296         }
3297
3298         node = get_child_item(child_col, 1);
3299         ok(node != NULL, "node == NULL\n");
3300         if(node) {
3301             type = get_node_type((IUnknown*)node);
3302             ok(type == 8, "type=%ld\n", type);
3303
3304             test_elem_id((IUnknown*)node, NULL);
3305             IHTMLDOMNode_Release(node);
3306         }
3307
3308         disp = (void*)0xdeadbeef;
3309         hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
3310         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3311         ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3312
3313         disp = (void*)0xdeadbeef;
3314         hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
3315         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3316         ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3317
3318         test_child_col_disp(child_col);
3319
3320         IHTMLDOMChildrenCollection_Release(child_col);
3321     }
3322
3323     test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
3324     test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
3325     test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
3326
3327     IHTMLElement_Release(elem);
3328
3329     test_stylesheets(doc);
3330     test_create_option_elem(doc);
3331
3332     elem = get_doc_elem_by_id(doc, tblW);
3333     ok(elem != NULL, "elem = NULL\n");
3334     test_elem_set_innertext(elem, "inner text");
3335     IHTMLElement_Release(elem);
3336
3337     test_doc_title(doc, "test");
3338     test_doc_set_title(doc, "test title");
3339     test_doc_title(doc, "test title");
3340 }
3341
3342 static void test_create_elems(IHTMLDocument2 *doc)
3343 {
3344     IHTMLElement *elem, *body, *elem2;
3345     IHTMLDOMNode *node, *node2, *node3;
3346     IDispatch *disp;
3347     VARIANT var;
3348     long type;
3349     HRESULT hres;
3350
3351     static const elem_type_t types1[] = { ET_TESTG };
3352
3353     elem = test_create_elem(doc, "TEST");
3354     test_elem_tag((IUnknown*)elem, "TEST");
3355     type = get_node_type((IUnknown*)elem);
3356     ok(type == 1, "type=%ld\n", type);
3357     test_ifaces((IUnknown*)elem, elem_iids);
3358     test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
3359
3360     hres = IHTMLDocument2_get_body(doc, &body);
3361     ok(hres == S_OK, "get_body failed: %08x\n", hres);
3362     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3363
3364     node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
3365     test_node_has_child((IUnknown*)body, VARIANT_TRUE);
3366     elem2 = get_elem_iface((IUnknown*)node);
3367     IHTMLElement_Release(elem2);
3368
3369     hres = IHTMLElement_get_all(body, &disp);
3370     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3371     test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
3372     IDispatch_Release(disp);
3373
3374     test_node_remove_child((IUnknown*)body, node);
3375
3376     hres = IHTMLElement_get_all(body, &disp);
3377     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3378     test_elem_collection((IUnknown*)disp, NULL, 0);
3379     IDispatch_Release(disp);
3380     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3381
3382     IHTMLElement_Release(elem);
3383     IHTMLDOMNode_Release(node);
3384
3385     node = test_create_text(doc, "test");
3386     test_ifaces((IUnknown*)node, text_iids);
3387     test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
3388
3389     V_VT(&var) = VT_NULL;
3390     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
3391     IHTMLDOMNode_Release(node);
3392
3393     node = test_create_text(doc, "insert ");
3394
3395     V_VT(&var) = VT_DISPATCH;
3396     V_DISPATCH(&var) = (IDispatch*)node2;
3397     node3 = test_node_insertbefore((IUnknown*)body, node, &var);
3398     IHTMLDOMNode_Release(node);
3399     IHTMLDOMNode_Release(node2);
3400     IHTMLDOMNode_Release(node3);
3401
3402     test_elem_innertext(body, "insert test");
3403
3404     IHTMLElement_Release(body);
3405 }
3406
3407 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
3408 {
3409     IOleCommandTarget *cmdtrg;
3410     HRESULT hres;
3411
3412     hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3413     ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
3414
3415     hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
3416     ok(hres == S_OK, "Exec failed: %08x\n", hres);
3417
3418     IOleCommandTarget_Release(cmdtrg);
3419 }
3420
3421 static void test_indent(IHTMLDocument2 *doc)
3422 {
3423     IHTMLElementCollection *col;
3424     IHTMLTxtRange *range;
3425     HRESULT hres;
3426
3427     static const elem_type_t all_types[] = {
3428         ET_HTML,
3429         ET_HEAD,
3430         ET_TITLE,
3431         ET_BODY,
3432         ET_BR,
3433         ET_A,
3434     };
3435
3436     static const elem_type_t indent_types[] = {
3437         ET_HTML,
3438         ET_HEAD,
3439         ET_TITLE,
3440         ET_BODY,
3441         ET_BLOCKQUOTE,
3442         ET_P,
3443         ET_BR,
3444         ET_A,
3445     };
3446
3447     hres = IHTMLDocument2_get_all(doc, &col);
3448     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3449     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
3450     IHTMLElementCollection_Release(col);
3451
3452     range = test_create_body_range(doc);
3453     test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
3454     IHTMLTxtRange_Release(range);
3455
3456     hres = IHTMLDocument2_get_all(doc, &col);
3457     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3458     test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
3459     IHTMLElementCollection_Release(col);
3460 }
3461
3462 static void test_cond_comment(IHTMLDocument2 *doc)
3463 {
3464     IHTMLElementCollection *col;
3465     HRESULT hres;
3466
3467     static const elem_type_t all_types[] = {
3468         ET_HTML,
3469         ET_HEAD,
3470         ET_TITLE,
3471         ET_BODY,
3472         ET_BR
3473     };
3474
3475     hres = IHTMLDocument2_get_all(doc, &col);
3476     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3477     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
3478     IHTMLElementCollection_Release(col);
3479 }
3480
3481 static IHTMLDocument2 *notif_doc;
3482 static BOOL doc_complete;
3483
3484 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
3485         REFIID riid, void**ppv)
3486 {
3487     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
3488         *ppv = iface;
3489         return S_OK;
3490     }
3491
3492     ok(0, "unexpected call\n");
3493     return E_NOINTERFACE;
3494 }
3495
3496 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
3497 {
3498     return 2;
3499 }
3500
3501 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
3502 {
3503     return 1;
3504 }
3505
3506 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
3507 {
3508     if(dispID == DISPID_READYSTATE){
3509         BSTR state;
3510         HRESULT hres;
3511
3512         static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
3513
3514         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
3515         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3516
3517         if(!lstrcmpW(state, completeW))
3518             doc_complete = TRUE;
3519
3520         SysFreeString(state);
3521     }
3522
3523     return S_OK;
3524 }
3525
3526 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
3527 {
3528     ok(0, "unexpected call\n");
3529     return E_NOTIMPL;
3530 }
3531
3532 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
3533     PropertyNotifySink_QueryInterface,
3534     PropertyNotifySink_AddRef,
3535     PropertyNotifySink_Release,
3536     PropertyNotifySink_OnChanged,
3537     PropertyNotifySink_OnRequestEdit
3538 };
3539
3540 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
3541
3542 static IHTMLDocument2 *create_doc_with_string(const char *str)
3543 {
3544     IPersistStreamInit *init;
3545     IStream *stream;
3546     IHTMLDocument2 *doc;
3547     HGLOBAL mem;
3548     SIZE_T len;
3549
3550     notif_doc = doc = create_document();
3551     if(!doc)
3552         return NULL;
3553
3554     doc_complete = FALSE;
3555     len = strlen(str);
3556     mem = GlobalAlloc(0, len);
3557     memcpy(mem, str, len);
3558     CreateStreamOnHGlobal(mem, TRUE, &stream);
3559
3560     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
3561
3562     IPersistStreamInit_Load(init, stream);
3563     IPersistStreamInit_Release(init);
3564     IStream_Release(stream);
3565
3566     return doc;
3567 }
3568
3569 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
3570 {
3571     IConnectionPointContainer *container;
3572     IConnectionPoint *cp;
3573     DWORD cookie;
3574     HRESULT hres;
3575
3576     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
3577     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
3578
3579     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
3580     IConnectionPointContainer_Release(container);
3581     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
3582
3583     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
3584     IConnectionPoint_Release(cp);
3585     ok(hres == S_OK, "Advise failed: %08x\n", hres);
3586 }
3587
3588 typedef void (*domtest_t)(IHTMLDocument2*);
3589
3590 static void run_domtest(const char *str, domtest_t test)
3591 {
3592     IHTMLDocument2 *doc;
3593     IHTMLElement *body = NULL;
3594     ULONG ref;
3595     MSG msg;
3596     HRESULT hres;
3597
3598     doc = create_doc_with_string(str);
3599     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3600
3601     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
3602         TranslateMessage(&msg);
3603         DispatchMessage(&msg);
3604     }
3605
3606     hres = IHTMLDocument2_get_body(doc, &body);
3607     ok(hres == S_OK, "get_body failed: %08x\n", hres);
3608
3609     if(body) {
3610         IHTMLElement_Release(body);
3611         test(doc);
3612     }else {
3613         skip("Could not get document body. Assuming no Gecko installed.\n");
3614     }
3615
3616     ref = IHTMLDocument2_Release(doc);
3617     ok(!ref ||
3618        ref == 1, /* Vista */
3619        "ref = %d\n", ref);
3620 }
3621
3622 static void gecko_installer_workaround(BOOL disable)
3623 {
3624     HKEY hkey;
3625     DWORD res;
3626
3627     static BOOL has_url = FALSE;
3628     static char url[2048];
3629
3630     if(!disable && !has_url)
3631         return;
3632
3633     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
3634     if(res != ERROR_SUCCESS)
3635         return;
3636
3637     if(disable) {
3638         DWORD type, size = sizeof(url);
3639
3640         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
3641         if(res == ERROR_SUCCESS && type == REG_SZ)
3642             has_url = TRUE;
3643
3644         RegDeleteValue(hkey, "GeckoUrl");
3645     }else {
3646         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
3647     }
3648
3649     RegCloseKey(hkey);
3650 }
3651
3652 START_TEST(dom)
3653 {
3654     gecko_installer_workaround(TRUE);
3655     CoInitialize(NULL);
3656
3657     run_domtest(doc_str1, test_doc_elem);
3658     run_domtest(range_test_str, test_txtrange);
3659     run_domtest(range_test2_str, test_txtrange2);
3660     run_domtest(elem_test_str, test_elems);
3661     run_domtest(doc_blank, test_create_elems);
3662     run_domtest(doc_blank, test_defaults);
3663     run_domtest(indent_test_str, test_indent);
3664     run_domtest(cond_comment_str, test_cond_comment);
3665
3666     CoUninitialize();
3667     gecko_installer_workaround(FALSE);
3668 }