Release 1.4-rc5.
[wine] / dlls / mshtml / tests / dom.c
1 /*
2  * Copyright 2007-2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmcid.h"
31 #include "mshtmhst.h"
32 #include "docobj.h"
33 #include "dispex.h"
34 #include "mshtml_test.h"
35 #include "objsafe.h"
36 #include "htiface.h"
37 #include "tlogstg.h"
38
39 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
40 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
41
42 static const char doc_blank[] = "<html></html>";
43 static const char doc_str1[] = "<html><body>test</body></html>";
44 static const char range_test_str[] =
45     "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n  \t</font>text<br /></body></html>";
46 static const char range_test2_str[] =
47     "<html><body>abc<hr />123<br /><hr />def</body></html>";
48 static const char elem_test_str[] =
49     "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
50     "<body onload=\"Testing()\">text test<!-- a comment -->"
51     "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
52     "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
53     "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
54     "<textarea id=\"X\">text text</textarea>"
55     "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
56     "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
57     "<test /><object id=\"objid\" vspace=100></object><embed />"
58     "<img id=\"imgid\" name=\"WineImg\"/>"
59     "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
60     "<form id=\"frm\"></form>"
61     "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
62     "</body></html>";
63 static const char elem_test2_str[] =
64     "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
65     "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
66     "</html>";
67
68 static const char indent_test_str[] =
69     "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
70 static const char cond_comment_str[] =
71     "<html><head><title>test</title></head><body>"
72     "<!--[if gte IE 4]> <br> <![endif]-->"
73     "</body></html>";
74 static const char frameset_str[] =
75     "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
76     "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
77     "<frame src=\"about:blank\" id=\"fr3\">"
78     "</frameset></html>";
79 static const char emptydiv_str[] =
80     "<html><head><title>emptydiv test</title></head>"
81     "<body><div id=\"divid\"></div></body></html>";
82
83 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
84 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
85 static WCHAR wordW[] = {'w','o','r','d',0};
86
87 typedef enum {
88     ET_NONE,
89     ET_HTML,
90     ET_HEAD,
91     ET_TITLE,
92     ET_BODY,
93     ET_A,
94     ET_INPUT,
95     ET_SELECT,
96     ET_TEXTAREA,
97     ET_OPTION,
98     ET_STYLE,
99     ET_BLOCKQUOTE,
100     ET_P,
101     ET_BR,
102     ET_TABLE,
103     ET_TBODY,
104     ET_SCRIPT,
105     ET_TEST,
106     ET_TESTG,
107     ET_COMMENT,
108     ET_IMG,
109     ET_TR,
110     ET_TD,
111     ET_IFRAME,
112     ET_FORM,
113     ET_FRAME,
114     ET_OBJECT,
115     ET_EMBED,
116     ET_DIV
117 } elem_type_t;
118
119 static const IID * const none_iids[] = {
120     &IID_IUnknown,
121     NULL
122 };
123
124 static const IID * const doc_node_iids[] = {
125     &IID_IHTMLDOMNode,
126     &IID_IHTMLDOMNode2,
127     &IID_IHTMLDocument,
128     &IID_IHTMLDocument2,
129     &IID_IHTMLDocument3,
130     &IID_IHTMLDocument4,
131     &IID_IHTMLDocument5,
132     &IID_IDispatchEx,
133     &IID_IConnectionPointContainer,
134     &IID_IInternetHostSecurityManager,
135     &IID_IOleContainer,
136     &IID_IObjectSafety,
137     &IID_IProvideClassInfo,
138     NULL
139 };
140
141 static const IID * const doc_obj_iids[] = {
142     &IID_IHTMLDocument,
143     &IID_IHTMLDocument2,
144     &IID_IHTMLDocument3,
145     &IID_IHTMLDocument4,
146     &IID_IHTMLDocument5,
147     &IID_IDispatchEx,
148     &IID_IConnectionPointContainer,
149     &IID_ICustomDoc,
150     &IID_IOleContainer,
151     &IID_IObjectSafety,
152     &IID_IProvideClassInfo,
153     &IID_ITargetContainer,
154     NULL
155 };
156
157 #define ELEM_IFACES \
158     &IID_IHTMLDOMNode,  \
159     &IID_IHTMLDOMNode2, \
160     &IID_IHTMLElement,  \
161     &IID_IHTMLElement2, \
162     &IID_IHTMLElement3, \
163     &IID_IHTMLElement4, \
164     &IID_IDispatchEx
165
166 static const IID * const elem_iids[] = {
167     ELEM_IFACES,
168     &IID_IConnectionPointContainer,
169     NULL
170 };
171
172 static const IID * const body_iids[] = {
173     ELEM_IFACES,
174     &IID_IHTMLTextContainer,
175     &IID_IHTMLBodyElement,
176     &IID_IConnectionPointContainer,
177     NULL
178 };
179
180 static const IID * const anchor_iids[] = {
181     ELEM_IFACES,
182     &IID_IHTMLAnchorElement,
183     &IID_IConnectionPointContainer,
184     NULL
185 };
186
187 static const IID * const input_iids[] = {
188     ELEM_IFACES,
189     &IID_IHTMLInputElement,
190     &IID_IHTMLInputTextElement,
191     &IID_IConnectionPointContainer,
192     NULL
193 };
194
195 static const IID * const select_iids[] = {
196     ELEM_IFACES,
197     &IID_IHTMLSelectElement,
198     &IID_IConnectionPointContainer,
199     NULL
200 };
201
202 static const IID * const textarea_iids[] = {
203     ELEM_IFACES,
204     &IID_IHTMLTextAreaElement,
205     &IID_IConnectionPointContainer,
206     NULL
207 };
208
209 static const IID * const option_iids[] = {
210     ELEM_IFACES,
211     &IID_IHTMLOptionElement,
212     &IID_IConnectionPointContainer,
213     NULL
214 };
215
216 static const IID * const table_iids[] = {
217     ELEM_IFACES,
218     &IID_IHTMLTable,
219     &IID_IHTMLTable2,
220     &IID_IHTMLTable3,
221     &IID_IConnectionPointContainer,
222     NULL
223 };
224
225 static const IID * const script_iids[] = {
226     ELEM_IFACES,
227     &IID_IHTMLScriptElement,
228     &IID_IConnectionPointContainer,
229     NULL
230 };
231
232 static const IID * const text_iids[] = {
233     &IID_IHTMLDOMNode,
234     &IID_IHTMLDOMNode2,
235     &IID_IHTMLDOMTextNode,
236     NULL
237 };
238
239 static const IID * const attr_iids[] = {
240     &IID_IHTMLDOMAttribute,
241     &IID_IDispatchEx,
242     NULL
243 };
244
245 static const IID * const location_iids[] = {
246     &IID_IDispatch,
247     &IID_IHTMLLocation,
248     NULL
249 };
250
251 static const IID * const window_iids[] = {
252     &IID_IDispatch,
253     &IID_IHTMLWindow2,
254     &IID_IHTMLWindow3,
255     &IID_IDispatchEx,
256     &IID_IServiceProvider,
257     NULL
258 };
259
260 static const IID * const comment_iids[] = {
261     ELEM_IFACES,
262     &IID_IHTMLCommentElement,
263     &IID_IConnectionPointContainer,
264     NULL
265 };
266
267 static const IID * const img_iids[] = {
268     ELEM_IFACES,
269     &IID_IHTMLImgElement,
270     &IID_IConnectionPointContainer,
271     NULL
272 };
273
274 static const IID * const tr_iids[] = {
275     ELEM_IFACES,
276     &IID_IHTMLTableRow,
277     &IID_IConnectionPointContainer,
278     NULL
279 };
280
281 static const IID * const td_iids[] = {
282     ELEM_IFACES,
283     &IID_IConnectionPointContainer,
284     NULL
285 };
286
287 static const IID * const frame_iids[] = {
288     ELEM_IFACES,
289     &IID_IHTMLFrameBase,
290     &IID_IHTMLFrameBase2,
291     &IID_IConnectionPointContainer,
292     NULL
293 };
294
295 static const IID * const head_iids[] = {
296     ELEM_IFACES,
297     &IID_IHTMLHeadElement,
298     &IID_IConnectionPointContainer,
299     NULL
300 };
301
302 static const IID * const title_iids[] = {
303     ELEM_IFACES,
304     &IID_IHTMLTitleElement,
305     &IID_IConnectionPointContainer,
306     NULL
307 };
308
309 static const IID * const object_iids[] = {
310     ELEM_IFACES,
311     &IID_IHTMLObjectElement,
312     /* FIXME: No IConnectionPointContainer */
313     NULL
314 };
315
316 static const IID * const embed_iids[] = {
317     ELEM_IFACES,
318     &IID_IHTMLEmbedElement,
319     /* FIXME: No IConnectionPointContainer */
320     NULL
321 };
322
323 static const IID * const iframe_iids[] = {
324     ELEM_IFACES,
325     &IID_IHTMLFrameBase,
326     &IID_IHTMLFrameBase2,
327     &IID_IHTMLIFrameElement,
328     &IID_IConnectionPointContainer,
329     NULL
330 };
331
332 static const IID * const form_iids[] = {
333     ELEM_IFACES,
334     &IID_IHTMLFormElement,
335     &IID_IConnectionPointContainer,
336     NULL
337 };
338
339 static const IID * const styleelem_iids[] = {
340     ELEM_IFACES,
341     &IID_IHTMLStyleElement,
342     &IID_IConnectionPointContainer,
343     NULL
344 };
345
346 static const IID * const generic_iids[] = {
347     ELEM_IFACES,
348     &IID_IHTMLGenericElement,
349     &IID_IConnectionPointContainer,
350     NULL
351 };
352
353 static const IID * const style_iids[] = {
354     &IID_IUnknown,
355     &IID_IDispatch,
356     &IID_IDispatchEx,
357     &IID_IHTMLStyle,
358     &IID_IHTMLStyle2,
359     &IID_IHTMLStyle3,
360     &IID_IHTMLStyle4,
361     NULL
362 };
363
364 static const IID * const cstyle_iids[] = {
365     &IID_IUnknown,
366     &IID_IDispatch,
367     &IID_IDispatchEx,
368     &IID_IHTMLCurrentStyle,
369     &IID_IHTMLCurrentStyle2,
370     &IID_IHTMLCurrentStyle3,
371     NULL
372 };
373
374 static const IID * const img_factory_iids[] = {
375     &IID_IUnknown,
376     &IID_IDispatch,
377     &IID_IDispatchEx,
378     &IID_IHTMLImageElementFactory,
379     NULL
380 };
381
382 typedef struct {
383     const char *tag;
384     REFIID *iids;
385     const IID *dispiid;
386 } elem_type_info_t;
387
388 static const elem_type_info_t elem_type_infos[] = {
389     {"",          none_iids,        NULL},
390     {"HTML",      elem_iids,        NULL},
391     {"HEAD",      head_iids,        &DIID_DispHTMLHeadElement},
392     {"TITLE",     title_iids,       &DIID_DispHTMLTitleElement},
393     {"BODY",      body_iids,        &DIID_DispHTMLBody},
394     {"A",         anchor_iids,      &DIID_DispHTMLAnchorElement},
395     {"INPUT",     input_iids,       &DIID_DispHTMLInputElement},
396     {"SELECT",    select_iids,      &DIID_DispHTMLSelectElement},
397     {"TEXTAREA",  textarea_iids,    &DIID_DispHTMLTextAreaElement},
398     {"OPTION",    option_iids,      &DIID_DispHTMLOptionElement},
399     {"STYLE",     styleelem_iids,   &DIID_DispHTMLStyleElement},
400     {"BLOCKQUOTE",elem_iids,        NULL},
401     {"P",         elem_iids,        NULL},
402     {"BR",        elem_iids,        NULL},
403     {"TABLE",     table_iids,       &DIID_DispHTMLTable},
404     {"TBODY",     elem_iids,        NULL},
405     {"SCRIPT",    script_iids,      &DIID_DispHTMLScriptElement},
406     {"TEST",      elem_iids,        &DIID_DispHTMLUnknownElement},
407     {"TEST",      generic_iids,     &DIID_DispHTMLGenericElement},
408     {"!",         comment_iids,     &DIID_DispHTMLCommentElement},
409     {"IMG",       img_iids,         &DIID_DispHTMLImg},
410     {"TR",        tr_iids,          &DIID_DispHTMLTableRow},
411     {"TD",        td_iids,          NULL},
412     {"IFRAME",    iframe_iids,      &DIID_DispHTMLIFrame},
413     {"FORM",      form_iids,        &DIID_DispHTMLFormElement},
414     {"FRAME",     frame_iids,       &DIID_DispHTMLFrameElement},
415     {"OBJECT",    object_iids,      &DIID_DispHTMLObjectElement},
416     {"EMBED",     embed_iids,       &DIID_DispHTMLEmbed},
417     {"DIV",       elem_iids,        NULL}
418 };
419
420 static const char *dbgstr_guid(REFIID riid)
421 {
422     static char buf[50];
423
424     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
425             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
426             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
427             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
428
429     return buf;
430 }
431
432 static int strcmp_wa(LPCWSTR strw, const char *stra)
433 {
434     CHAR buf[512];
435     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
436     return lstrcmpA(stra, buf);
437 }
438
439 static BSTR a2bstr(const char *str)
440 {
441     BSTR ret;
442     int len;
443
444     if(!str)
445         return NULL;
446
447     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
448     ret = SysAllocStringLen(NULL, len);
449     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
450
451     return ret;
452 }
453
454 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
455 {
456     IUnknown *unk1, *unk2;
457
458     if(iface1 == iface2)
459         return TRUE;
460
461     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
462     IUnknown_Release(unk1);
463     IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
464     IUnknown_Release(unk2);
465
466     return unk1 == unk2;
467 }
468
469 static IHTMLDocument2 *create_document(void)
470 {
471     IHTMLDocument2 *doc;
472     IHTMLDocument5 *doc5;
473     HRESULT hres;
474
475     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
476             &IID_IHTMLDocument2, (void**)&doc);
477     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
478     if(FAILED(hres))
479         return NULL;
480
481     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
482     if(FAILED(hres)) {
483         win_skip("Could not get IHTMLDocument5, probably too old IE\n");
484         IHTMLDocument2_Release(doc);
485         return NULL;
486     }
487
488     IHTMLDocument5_Release(doc5);
489     return doc;
490 }
491
492 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
493 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
494 {
495     IDispatchEx *dispex;
496     HRESULT hres;
497
498     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
499     ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
500     return dispex;
501 }
502
503 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
504 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
505 {
506     const IID * const *piid;
507     IUnknown *unk;
508     HRESULT hres;
509
510      for(piid = iids; *piid; piid++) {
511         hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
512         ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
513         if(SUCCEEDED(hres))
514             IUnknown_Release(unk);
515     }
516 }
517
518 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
519 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
520 {
521     IUnknown *unk;
522     HRESULT hres;
523
524     unk = (void*)0xdeadbeef;
525     hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
526     ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
527     ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
528 }
529
530 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
531 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
532 {
533     IDispatchEx *dispex = _get_dispex_iface(line, unk);
534     ITypeInfo *typeinfo;
535     BOOL ret = FALSE;
536     UINT ticnt;
537     HRESULT hres;
538
539     ticnt = 0xdeadbeef;
540     hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
541     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
542     ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
543
544     hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
545     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
546
547     if(SUCCEEDED(hres)) {
548         TYPEATTR *type_attr;
549
550         hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
551         ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
552         if(hres == S_OK) {
553             *iid = type_attr->guid;
554             ret = TRUE;
555         }
556
557         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
558         ITypeInfo_Release(typeinfo);
559     }
560
561     IDispatchEx_Release(dispex);
562     return ret;
563 }
564
565 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
566 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
567 {
568     IDispatchEx *dispex = _get_dispex_iface(line, unk);
569     DISPPARAMS dp  = {NULL,NULL,0,0};
570     EXCEPINFO ei;
571     VARIANT var;
572     HRESULT hres;
573
574     hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
575     IDispatchEx_Release(dispex);
576     ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
577
578     ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
579     ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
580     VariantClear(&var);
581 }
582
583 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
584 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
585 {
586     IID iid;
587
588     if(_test_get_dispid(line, unk, &iid))
589         ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
590
591     if(val)
592         _test_disp_value(line, unk, val);
593 }
594
595 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
596 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
597 {
598     IID iid;
599
600     if(_test_get_dispid(line, unk, &iid))
601         ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
602                 "unexpected guid %s\n", dbgstr_guid(&iid));
603
604     if(val)
605         _test_disp_value(line, unk, val);
606 }
607
608 #define test_class_info(u) _test_class_info(__LINE__,u)
609 static void _test_class_info(unsigned line, IUnknown *unk)
610 {
611     IProvideClassInfo *classinfo;
612     ITypeInfo *typeinfo;
613     TYPEATTR *type_attr;
614     HRESULT hres;
615
616     hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
617     ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
618     if(FAILED(hres))
619         return;
620
621     hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
622     ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
623     if(FAILED(hres))
624     {
625         IProvideClassInfo_Release(classinfo);
626         return;
627     }
628
629     hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
630     ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
631     if(SUCCEEDED(hres))
632     {
633         ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
634                 "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
635         ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
636                 "unexpected typekind %d\n", type_attr->typekind);
637         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
638     }
639
640     ITypeInfo_Release(typeinfo);
641     IProvideClassInfo_Release(classinfo);
642 }
643
644 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
645 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
646 {
647     IDispatchEx *dispex = _get_dispex_iface(line, unk);
648     DISPPARAMS dp = {val, NULL, 1, 0};
649     EXCEPINFO ei;
650     DISPID id;
651     BSTR str;
652     HRESULT hres;
653
654     str = a2bstr(name);
655     hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
656     SysFreeString(str);
657     ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
658
659     memset(&ei, 0, sizeof(ei));
660     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
661     ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
662
663 }
664
665 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
666 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
667 {
668     IHTMLElement *elem;
669     HRESULT hres;
670
671     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
672     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
673     return elem;
674 }
675
676 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
677 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
678 {
679     IHTMLElement2 *elem;
680     HRESULT hres;
681
682     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
683     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
684     return elem;
685 }
686
687 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
688 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
689 {
690     IHTMLElement3 *elem;
691     HRESULT hres;
692
693     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
694     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
695     return elem;
696 }
697
698 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
699 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
700 {
701     IHTMLElement4 *elem;
702     HRESULT hres;
703
704     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
705     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
706     return elem;
707 }
708
709 #define get_node_iface(u) _get_node_iface(__LINE__,u)
710 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
711 {
712     IHTMLDOMNode *node;
713     HRESULT hres;
714
715     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
716     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
717     return node;
718 }
719
720 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
721 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
722 {
723     IHTMLDOMNode2 *node;
724     HRESULT hres;
725
726     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
727     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
728     return node;
729 }
730
731 #define get_img_iface(u) _get_img_iface(__LINE__,u)
732 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
733 {
734     IHTMLImgElement *img;
735     HRESULT hres;
736
737     hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
738     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
739     return img;
740 }
741
742 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
743 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
744 {
745     IHTMLAnchorElement *anchor;
746     HRESULT hres;
747
748     hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
749     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
750     return anchor;
751 }
752
753 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
754 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
755 {
756     IHTMLTextAreaElement *textarea;
757     HRESULT hres;
758
759     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
760     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
761     return textarea;
762 }
763
764 #define get_select_iface(u) _get_select_iface(__LINE__,u)
765 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
766 {
767     IHTMLSelectElement *select;
768     HRESULT hres;
769
770     hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
771     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
772     return select;
773 }
774
775 #define get_form_iface(u) _get_form_iface(__LINE__,u)
776 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
777 {
778     IHTMLFormElement *form;
779     HRESULT hres;
780
781     hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
782     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
783     return form;
784 }
785
786 #define get_text_iface(u) _get_text_iface(__LINE__,u)
787 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
788 {
789     IHTMLDOMTextNode *text;
790     HRESULT hres;
791
792     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
793     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
794     return text;
795 }
796
797 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
798 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
799 {
800     IHTMLCommentElement *comment;
801     HRESULT hres;
802
803     hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
804     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
805     return comment;
806 }
807
808 #define get_object_iface(u) _get_object_iface(__LINE__,u)
809 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
810 {
811     IHTMLObjectElement *obj;
812     HRESULT hres;
813
814     hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
815     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
816     return obj;
817 }
818
819 #define get_style_iface(u) _get_style_iface(__LINE__,u)
820 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
821 {
822     IHTMLStyleElement *obj;
823     HRESULT hres;
824
825     hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
826     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
827     return obj;
828 }
829
830 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
831 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
832 {
833     IHTMLDOMNode *node = _get_node_iface(line, unk);
834     BSTR name;
835     HRESULT hres;
836
837     hres = IHTMLDOMNode_get_nodeName(node, &name);
838     IHTMLDOMNode_Release(node);
839     ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
840     ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
841
842     SysFreeString(name);
843 }
844
845 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
846 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
847 {
848     IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
849     IDispatch *disp = (void*)0xdeadbeef;
850     IHTMLDocument2 *doc = NULL;
851     HRESULT hres;
852
853     hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
854     IHTMLDOMNode2_Release(node);
855     ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
856
857     if(disp) {
858         hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
859         IDispatch_Release(disp);
860         ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
861     }
862
863     return doc;
864 }
865
866 #define get_doc_window(d) _get_doc_window(__LINE__,d)
867 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
868 {
869     IHTMLWindow2 *window;
870     HRESULT hres;
871
872     window = NULL;
873     hres = IHTMLDocument2_get_parentWindow(doc, &window);
874     ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
875     ok_(__FILE__,line)(window != NULL, "window == NULL\n");
876
877     return window;
878 }
879
880 #define clone_node(n,d) _clone_node(__LINE__,n,d)
881 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
882 {
883     IHTMLDOMNode *node = _get_node_iface(line, unk);
884     IHTMLDOMNode *ret = NULL;
885     HRESULT hres;
886
887     hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
888     IHTMLDOMNode_Release(node);
889     ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
890     ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
891
892     return ret;
893
894 }
895
896 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
897 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
898 {
899     IHTMLElement *elem = _get_elem_iface(line, unk);
900     BSTR tag;
901     HRESULT hres;
902
903     hres = IHTMLElement_get_tagName(elem, &tag);
904     IHTMLElement_Release(elem);
905     ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
906     ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
907
908     SysFreeString(tag);
909 }
910
911 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
912 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
913 {
914     _test_elem_tag(line, unk, elem_type_infos[type].tag);
915     _test_ifaces(line, unk, elem_type_infos[type].iids);
916
917     if(elem_type_infos[type].dispiid && type != ET_A)
918         _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
919 }
920
921 #define get_node_type(n) _get_node_type(__LINE__,n)
922 static LONG _get_node_type(unsigned line, IUnknown *unk)
923 {
924     IHTMLDOMNode *node = _get_node_iface(line, unk);
925     LONG type = -1;
926     HRESULT hres;
927
928     hres = IHTMLDOMNode_get_nodeType(node, &type);
929     ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
930
931     IHTMLDOMNode_Release(node);
932
933     return type;
934 }
935
936 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
937 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
938 {
939     IHTMLDOMNode *node = _get_node_iface(line, unk);
940     IHTMLDOMChildrenCollection *col = NULL;
941     IDispatch *disp;
942     HRESULT hres;
943
944     hres = IHTMLDOMNode_get_childNodes(node, &disp);
945     IHTMLDOMNode_Release(node);
946     ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
947     if(FAILED(hres))
948         return NULL;
949
950     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
951     IDispatch_Release(disp);
952     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
953
954     return col;
955 }
956
957 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
958 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
959 {
960     IHTMLDOMNode *node = NULL;
961     IDispatch *disp;
962     HRESULT hres;
963
964     hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
965     ok(hres == S_OK, "item failed: %08x\n", hres);
966
967     node = _get_node_iface(line, (IUnknown*)disp);
968     IDispatch_Release(disp);
969
970     return node;
971 }
972
973 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
974 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
975 {
976     VARIANT value;
977     BSTR tmp;
978     HRESULT hres;
979
980     VariantInit(&value);
981
982     tmp = a2bstr(name);
983     hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
984     SysFreeString(tmp);
985     ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
986
987     if(exval) {
988         ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
989         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
990     }else {
991         ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
992     }
993
994     VariantClear(&value);
995 }
996
997 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
998 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
999 {
1000     IHTMLElement *elem = _get_elem_iface(line, unk);
1001     IHTMLElement *off_parent;
1002     LONG l;
1003     HRESULT hres;
1004
1005     hres = IHTMLElement_get_offsetTop(elem, &l);
1006     ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1007
1008     hres = IHTMLElement_get_offsetHeight(elem, &l);
1009     ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1010
1011     hres = IHTMLElement_get_offsetWidth(elem, &l);
1012     ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1013
1014     hres = IHTMLElement_get_offsetLeft(elem, &l);
1015     ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1016
1017     hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1018     ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1019
1020     _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1021     IHTMLElement_Release(off_parent);
1022
1023     IHTMLElement_Release(elem);
1024 }
1025
1026 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1027 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1028 {
1029     IHTMLWindow2 *window;
1030     IHTMLDocument2 *ret;
1031     HRESULT hres;
1032
1033     hres = IHTMLDocument2_get_parentWindow(doc, &window);
1034     ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1035
1036     hres = IHTMLWindow2_get_document(window, &ret);
1037     ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1038     ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1039
1040     return ret;
1041 }
1042
1043 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1044 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1045 {
1046     BSTR name;
1047     HRESULT hres;
1048
1049     hres = IHTMLWindow2_get_name(window, &name);
1050     ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1051     if(exname)
1052         ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1053     else
1054         ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1055     SysFreeString(name);
1056 }
1057
1058 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1059 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1060 {
1061     BSTR str;
1062     HRESULT hres;
1063
1064     str = a2bstr(name);
1065     hres = IHTMLWindow2_put_name(window, str);
1066     SysFreeString(str);
1067     ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1068
1069     _test_window_name(line, window, name);
1070 }
1071
1072 #define test_window_status(d) _test_window_status(__LINE__,d)
1073 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1074 {
1075     BSTR status;
1076     HRESULT hres;
1077
1078     status = (void*)0xdeadbeef;
1079     hres = IHTMLWindow2_get_status(window, &status);
1080     ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1081     ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1082     SysFreeString(status);
1083 }
1084
1085 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1086 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1087 {
1088     BSTR str;
1089     HRESULT hres;
1090
1091     str = a2bstr(status);
1092     hres = IHTMLWindow2_put_status(window, str);
1093     SysFreeString(str);
1094     ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1095 }
1096
1097 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1098 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1099 {
1100     LONG length = -1;
1101     HRESULT hres;
1102
1103     hres = IHTMLWindow2_get_length(window, &length);
1104     ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1105     ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1106 }
1107
1108 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1109 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1110 {
1111     IHTMLFrameBase2 *base2;
1112     IHTMLWindow2 *window;
1113     HRESULT hres;
1114
1115     hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1116     ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1117
1118     window = NULL;
1119     hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1120     IHTMLFrameBase2_Release(base2);
1121     ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1122     ok(window != NULL, "contentWindow = NULL\n");
1123
1124     return window;
1125 }
1126
1127 static void test_get_set_attr(IHTMLDocument2 *doc)
1128 {
1129     IHTMLElement *elem;
1130     IHTMLDocument3 *doc3;
1131     HRESULT hres;
1132     BSTR bstr;
1133     VARIANT val;
1134
1135     /* grab an element to test with */
1136     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1137     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1138
1139     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1140     IHTMLDocument3_Release(doc3);
1141     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1142
1143     /* get a non-present attribute */
1144     bstr = a2bstr("notAnAttribute");
1145     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1146     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1147     ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1148     VariantClear(&val);
1149     SysFreeString(bstr);
1150
1151     /* get a present attribute */
1152     bstr = a2bstr("scrollHeight");
1153     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1154     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1155     ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1156     VariantClear(&val);
1157     SysFreeString(bstr);
1158
1159     /* create a new BSTR attribute */
1160     bstr = a2bstr("newAttribute");
1161
1162     V_VT(&val) = VT_BSTR;
1163     V_BSTR(&val) = a2bstr("the value");
1164     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1165     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1166     VariantClear(&val);
1167
1168     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1169     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1170     ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1171     ok(strcmp_wa(V_BSTR(&val), "the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
1172     VariantClear(&val);
1173
1174     /* overwrite the attribute with a BOOL */
1175     V_VT(&val) = VT_BOOL;
1176     V_BOOL(&val) = VARIANT_TRUE;
1177     hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1178     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1179     VariantClear(&val);
1180
1181     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1182     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1183     ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1184     ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1185     VariantClear(&val);
1186
1187     SysFreeString(bstr);
1188
1189     /* case-insensitive */
1190     bstr = a2bstr("newattribute");
1191     hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1192     ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1193     ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1194     ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1195     VariantClear(&val);
1196     SysFreeString(bstr);
1197
1198     IHTMLElement_Release(elem);
1199 }
1200
1201 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1202 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1203 {
1204     IHTMLElement *elem;
1205     IHTMLDocument3 *doc3;
1206     HRESULT hres;
1207
1208     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1209     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1210     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1211     ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1212     IHTMLDocument3_Release(doc3);
1213
1214     return elem;
1215 }
1216
1217 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1218 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1219 {
1220     IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1221     BSTR str;
1222     HRESULT hres;
1223
1224     hres = IHTMLAnchorElement_get_href(anchor, &str);
1225     ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1226     ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1227     SysFreeString(str);
1228
1229     _test_disp_value(line, unk, exhref);
1230 }
1231
1232 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1233 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1234 {
1235     IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1236     BSTR str;
1237     HRESULT hres;
1238
1239     str = a2bstr(exhref);
1240     hres = IHTMLAnchorElement_put_href(anchor, str);
1241     ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1242     SysFreeString(str);
1243
1244     _test_disp_value(line, unk, exhref);
1245 }
1246
1247 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1248 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1249 {
1250     IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1251     BSTR str;
1252     HRESULT hres;
1253
1254     hres = IHTMLAnchorElement_get_target(anchor, &str);
1255     ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1256     if(target)
1257         ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1258     else
1259         ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1260     SysFreeString(str);
1261 }
1262
1263 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1264 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1265 {
1266     IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1267     BSTR str;
1268     HRESULT hres;
1269
1270     str = target ? a2bstr(target) : NULL;
1271     hres = IHTMLAnchorElement_put_target(anchor, str);
1272     ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1273     SysFreeString(str);
1274 }
1275
1276
1277 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1278 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1279 {
1280     BSTR bstr;
1281     HRESULT hres;
1282
1283     hres = IHTMLOptionElement_get_text(option, &bstr);
1284     ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1285     ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1286     SysFreeString(bstr);
1287 }
1288
1289 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1290 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1291 {
1292     BSTR bstr;
1293     HRESULT hres;
1294
1295     bstr = a2bstr(text);
1296     hres = IHTMLOptionElement_put_text(option, bstr);
1297     SysFreeString(bstr);
1298     ok(hres == S_OK, "put_text failed: %08x\n", hres);
1299
1300     _test_option_text(line, option, text);
1301 }
1302
1303 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1304 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1305 {
1306     BSTR bstr;
1307     HRESULT hres;
1308
1309     hres = IHTMLOptionElement_get_value(option, &bstr);
1310     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1311     ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1312     SysFreeString(bstr);
1313 }
1314
1315 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1316 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1317 {
1318     BSTR bstr;
1319     HRESULT hres;
1320
1321     bstr = a2bstr(value);
1322     hres = IHTMLOptionElement_put_value(option, bstr);
1323     SysFreeString(bstr);
1324     ok(hres == S_OK, "put_value failed: %08x\n", hres);
1325
1326     _test_option_value(line, option, value);
1327 }
1328
1329 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1330 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1331 {
1332     VARIANT_BOOL b = 0x100;
1333     HRESULT hres;
1334
1335     hres = IHTMLOptionElement_get_selected(option, &b);
1336     ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1337     ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1338 }
1339
1340 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1341 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1342 {
1343     HRESULT hres;
1344
1345     hres = IHTMLOptionElement_put_selected(option, b);
1346     ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1347     _test_option_selected(line, option, b);
1348 }
1349
1350 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1351 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1352 {
1353     IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1354     BSTR value = (void*)0xdeadbeef;
1355     HRESULT hres;
1356
1357     hres = IHTMLTextAreaElement_get_value(textarea, &value);
1358     IHTMLTextAreaElement_Release(textarea);
1359     ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1360     if(exval)
1361         ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1362     else
1363         ok_(__FILE__,line)(!value, "value = %p\n", value);
1364     SysFreeString(value);
1365 }
1366
1367 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1368 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1369 {
1370     IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1371     BSTR tmp = a2bstr(value);
1372     HRESULT hres;
1373
1374     hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1375     IHTMLTextAreaElement_Release(textarea);
1376     ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1377     SysFreeString(tmp);
1378
1379     _test_textarea_value(line, unk, value);
1380 }
1381
1382 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1383 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1384 {
1385     IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1386     VARIANT_BOOL b = 0x100;
1387     HRESULT hres;
1388
1389     hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1390     IHTMLTextAreaElement_Release(textarea);
1391     ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1392     ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1393 }
1394
1395 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1396 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1397 {
1398     IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1399     HRESULT hres;
1400
1401     hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1402     IHTMLTextAreaElement_Release(textarea);
1403     ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1404
1405     _test_textarea_readonly(line, unk, b);
1406 }
1407
1408 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1409 static void _test_textarea_type(unsigned line, IUnknown *unk)
1410 {
1411     IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1412     BSTR type = (void*)0xdeadbeef;
1413     HRESULT hres;
1414
1415     hres = IHTMLTextAreaElement_get_type(textarea, &type);
1416     IHTMLTextAreaElement_Release(textarea);
1417     ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1418     ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1419     SysFreeString(type);
1420 }
1421
1422 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1423 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1424 {
1425     IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1426     BSTR text;
1427     HRESULT hres;
1428
1429     text = a2bstr(extext);
1430     hres = IHTMLCommentElement_get_text(comment, &text);
1431     ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1432     ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1433
1434     IHTMLCommentElement_Release(comment);
1435     SysFreeString(text);
1436 }
1437
1438 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1439 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1440 {
1441     IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1442     IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1443     IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1444     IHTMLDOMAttribute *attr;
1445     BSTR name = a2bstr("test");
1446     VARIANT val;
1447     HRESULT hres;
1448
1449     hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1450     ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1451     ok(attr == NULL, "attr != NULL\n");
1452
1453     V_VT(&val) = VT_I4;
1454     V_I4(&val) = 1234;
1455     hres = IHTMLElement_setAttribute(elem, name, val, 0);
1456     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1457
1458     hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1459     ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1460     ok(attr != NULL, "attr == NULL\n");
1461
1462     IHTMLDOMAttribute_Release(attr);
1463     IHTMLCommentElement_Release(comment);
1464     IHTMLElement_Release(elem);
1465     IHTMLElement4_Release(elem);
1466     SysFreeString(name);
1467 }
1468
1469 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1470 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1471 {
1472     IHTMLObjectElement *object = _get_object_iface(line, unk);
1473     LONG l;
1474     HRESULT hres;
1475
1476     l = 0xdeadbeef;
1477     hres = IHTMLObjectElement_get_vspace(object, &l);
1478     ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1479     ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1480     IHTMLObjectElement_Release(object);
1481 }
1482
1483 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1484 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1485         const char *txt, const char *val)
1486 {
1487     IHTMLOptionElementFactory *factory;
1488     IHTMLOptionElement *option;
1489     IHTMLWindow2 *window;
1490     VARIANT text, value, empty;
1491     HRESULT hres;
1492
1493     hres = IHTMLDocument2_get_parentWindow(doc, &window);
1494     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1495
1496     hres = IHTMLWindow2_get_Option(window, &factory);
1497     IHTMLWindow2_Release(window);
1498     ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1499
1500     V_VT(&text) = VT_BSTR;
1501     V_BSTR(&text) = a2bstr(txt);
1502     V_VT(&value) = VT_BSTR;
1503     V_BSTR(&value) = a2bstr(val);
1504     V_VT(&empty) = VT_EMPTY;
1505
1506     hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1507     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1508
1509     IHTMLOptionElementFactory_Release(factory);
1510     VariantClear(&text);
1511     VariantClear(&value);
1512
1513     _test_option_text(line, option, txt);
1514     _test_option_value(line, option, val);
1515     _test_option_selected(line, option, VARIANT_FALSE);
1516
1517     return option;
1518 }
1519
1520 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1521 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1522 {
1523     LONG found = -1;
1524     HRESULT hres;
1525
1526     hres = IHTMLImgElement_get_width(img, &found);
1527     ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1528     ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1529 }
1530
1531 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1532 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
1533 {
1534     HRESULT hres;
1535
1536     hres = IHTMLImgElement_put_width(img, width);
1537     ok(hres == S_OK, "put_width failed: %08x\n", hres);
1538
1539     _test_img_width(line, img, width);
1540 }
1541
1542 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1543 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
1544 {
1545     LONG found = -1;
1546     HRESULT hres;
1547
1548     hres = IHTMLImgElement_get_height(img, &found);
1549     ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1550     ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1551 }
1552
1553 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1554 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
1555 {
1556     HRESULT hres;
1557
1558     hres = IHTMLImgElement_put_height(img, height);
1559     ok(hres == S_OK, "put_height failed: %08x\n", hres);
1560
1561     _test_img_height(line, img, height);
1562 }
1563
1564 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1565 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1566         LONG wdth, LONG hght)
1567 {
1568     IHTMLImageElementFactory *factory;
1569     IHTMLImgElement *img;
1570     IHTMLWindow2 *window;
1571     VARIANT width, height;
1572     char buf[16];
1573     HRESULT hres;
1574
1575     hres = IHTMLDocument2_get_parentWindow(doc, &window);
1576     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1577
1578     hres = IHTMLWindow2_get_Image(window, &factory);
1579     IHTMLWindow2_Release(window);
1580     ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1581
1582     test_ifaces((IUnknown*)factory, img_factory_iids);
1583     test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1584
1585     if(wdth >= 0){
1586         snprintf(buf, 16, "%d", wdth);
1587         V_VT(&width) = VT_BSTR;
1588         V_BSTR(&width) = a2bstr(buf);
1589     }else{
1590         V_VT(&width) = VT_EMPTY;
1591         wdth = 0;
1592     }
1593
1594     if(hght >= 0){
1595         snprintf(buf, 16, "%d", hght);
1596         V_VT(&height) = VT_BSTR;
1597         V_BSTR(&height) = a2bstr(buf);
1598     }else{
1599         V_VT(&height) = VT_EMPTY;
1600         hght = 0;
1601     }
1602
1603     hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1604     ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1605
1606     IHTMLImageElementFactory_Release(factory);
1607     VariantClear(&width);
1608     VariantClear(&height);
1609
1610     if(SUCCEEDED(hres)) {
1611         _test_img_width(line, img, wdth);
1612         _test_img_height(line, img, hght);
1613         return img;
1614     }
1615
1616     return NULL;
1617 }
1618
1619 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1620 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1621 {
1622     LONG len = 0xdeadbeef;
1623     HRESULT hres;
1624
1625     hres = IHTMLSelectElement_get_length(select, &len);
1626     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1627     ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1628 }
1629
1630 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
1631 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
1632 {
1633     IHTMLSelectElement *select = _get_select_iface(line, unk);
1634     HRESULT hres;
1635
1636     hres = IHTMLSelectElement_put_length(select, length);
1637     ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
1638     _test_select_length(line, select, length);
1639     IHTMLSelectElement_Release(select);
1640 }
1641
1642 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1643 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1644 {
1645     LONG idx = 0xdeadbeef;
1646     HRESULT hres;
1647
1648     hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1649     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1650     ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1651 }
1652
1653 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1654 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1655 {
1656     HRESULT hres;
1657
1658     hres = IHTMLSelectElement_put_selectedIndex(select, index);
1659     ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1660     _test_select_selidx(line, select, index);
1661 }
1662
1663 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1664 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1665 {
1666     BSTR val;
1667     HRESULT hres;
1668
1669     hres = IHTMLSelectElement_get_value(select, &val);
1670     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1671     if(exval)
1672         ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1673     else
1674         ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1675     SysFreeString(val);
1676 }
1677
1678 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1679 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1680 {
1681     BSTR bstr;
1682     HRESULT hres;
1683
1684     bstr = a2bstr(val);
1685     hres = IHTMLSelectElement_put_value(select, bstr);
1686     SysFreeString(bstr);
1687     ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1688 }
1689
1690 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1691 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1692 {
1693     BSTR type;
1694     HRESULT hres;
1695
1696     hres = IHTMLSelectElement_get_type(select, &type);
1697     ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1698     ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1699     SysFreeString(type);
1700 }
1701
1702 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1703 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1704 {
1705     BSTR text;
1706     HRESULT hres;
1707
1708     hres = IHTMLTxtRange_get_text(range, &text);
1709     ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1710
1711     if(extext) {
1712         ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1713         ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1714     }else {
1715         ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1716     }
1717
1718     SysFreeString(text);
1719
1720 }
1721
1722 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1723 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1724 {
1725     HRESULT hres;
1726
1727     hres = IHTMLTxtRange_collapse(range, b);
1728     ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1729     _test_range_text(line, range, NULL);
1730 }
1731
1732 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1733 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1734         VARIANT_BOOL exb, const char *extext)
1735 {
1736     VARIANT_BOOL b = 0xe0e0;
1737     HRESULT hres;
1738
1739     hres = IHTMLTxtRange_expand(range, unit, &b);
1740     ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1741     ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1742     _test_range_text(line, range, extext);
1743 }
1744
1745 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1746 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1747 {
1748     LONG c = 0xdeadbeef;
1749     HRESULT hres;
1750
1751     hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1752     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1753     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1754     _test_range_text(line, range, NULL);
1755 }
1756
1757 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1758 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1759         LPWSTR unit, LONG cnt, LONG excnt)
1760 {
1761     LONG c = 0xdeadbeef;
1762     HRESULT hres;
1763
1764     hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1765     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1766     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1767 }
1768
1769 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1770 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1771 {
1772     LONG c = 0xdeadbeef;
1773     HRESULT hres;
1774
1775     hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1776     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1777     ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1778 }
1779
1780 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1781 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1782 {
1783     HRESULT hres;
1784     BSTR bstr = a2bstr(text);
1785
1786     hres = IHTMLTxtRange_put_text(range, bstr);
1787     ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1788     SysFreeString(bstr);
1789     _test_range_text(line, range, NULL);
1790 }
1791
1792 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1793 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1794 {
1795     VARIANT_BOOL b;
1796     HRESULT hres;
1797
1798     b = 0xe0e0;
1799     hres = IHTMLTxtRange_inRange(range1, range2, &b);
1800     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1801     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1802 }
1803
1804 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1805 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1806 {
1807     VARIANT_BOOL b;
1808     HRESULT hres;
1809
1810     b = 0xe0e0;
1811     hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1812     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1813     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1814
1815     b = 0xe0e0;
1816     hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1817     ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1818     ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1819
1820     if(exb) {
1821         test_range_inrange(range1, range2, VARIANT_TRUE);
1822         test_range_inrange(range2, range1, VARIANT_TRUE);
1823     }
1824 }
1825
1826 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1827 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1828 {
1829     IHTMLElement *elem;
1830     HRESULT hres;
1831
1832     hres = IHTMLTxtRange_parentElement(range, &elem);
1833     ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1834
1835     _test_elem_type(line, (IUnknown*)elem, type);
1836
1837     IHTMLElement_Release(elem);
1838 }
1839
1840 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1841 static void _test_elem_collection(unsigned line, IUnknown *unk,
1842         const elem_type_t *elem_types, LONG exlen)
1843 {
1844     IHTMLElementCollection *col;
1845     LONG len;
1846     DWORD i;
1847     VARIANT name, index;
1848     IDispatch *disp, *disp2;
1849     HRESULT hres;
1850
1851     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1852     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1853
1854     test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1855
1856     hres = IHTMLElementCollection_get_length(col, &len);
1857     ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1858     ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1859
1860     if(len > exlen)
1861         len = exlen;
1862
1863     V_VT(&index) = VT_EMPTY;
1864
1865     for(i=0; i<len; i++) {
1866         V_VT(&name) = VT_I4;
1867         V_I4(&name) = i;
1868         disp = (void*)0xdeadbeef;
1869         hres = IHTMLElementCollection_item(col, name, index, &disp);
1870         ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1871         ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1872         if(FAILED(hres) || !disp)
1873             continue;
1874
1875         _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1876
1877         if(!i) {
1878             V_VT(&name) = VT_UINT;
1879             V_I4(&name) = 0;
1880             disp2 = (void*)0xdeadbeef;
1881             hres = IHTMLElementCollection_item(col, name, index, &disp2);
1882             ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1883             ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1884             if(disp2)
1885                 IDispatch_Release(disp2);
1886         }
1887
1888         IDispatch_Release(disp);
1889     }
1890
1891     V_VT(&name) = VT_I4;
1892     V_I4(&name) = len;
1893     disp = (void*)0xdeadbeef;
1894     hres = IHTMLElementCollection_item(col, name, index, &disp);
1895     ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1896     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1897
1898     V_VT(&name) = VT_I4;
1899     V_I4(&name) = -1;
1900     disp = (void*)0xdeadbeef;
1901     hres = IHTMLElementCollection_item(col, name, index, &disp);
1902     ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1903     ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1904
1905     IHTMLElementCollection_Release(col);
1906 }
1907
1908 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
1909 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
1910 {
1911     IHTMLElement *elem = _get_elem_iface(line, unk);
1912     IDispatch *disp;
1913     HRESULT hres;
1914
1915     hres = IHTMLElement_get_all(elem, &disp);
1916     IHTMLElement_Release(elem);
1917     ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
1918
1919     _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
1920     IDispatch_Release(disp);
1921 }
1922
1923 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1924 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1925 {
1926     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1927     IHTMLElementCollection *col = NULL;
1928     elem_type_t *types = NULL;
1929     BSTR tmp;
1930     int i;
1931     HRESULT hres;
1932
1933     tmp = a2bstr(elem_type_infos[type].tag);
1934     hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1935     SysFreeString(tmp);
1936     IHTMLElement2_Release(elem);
1937     ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1938     ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1939
1940     if(exlen) {
1941         types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1942         for(i=0; i<exlen; i++)
1943             types[i] = type;
1944     }
1945
1946     _test_elem_collection(line, (IUnknown*)col, types, exlen);
1947
1948     HeapFree(GetProcessHeap(), 0, types);
1949 }
1950
1951 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1952 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1953 {
1954     BSTR text = NULL;
1955     HRESULT hres;
1956
1957     hres = IHTMLElement_get_innerText(elem, &text);
1958     ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1959     ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1960                         wine_dbgstr_w(text), extext);
1961     SysFreeString(text);
1962 }
1963
1964 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1965 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1966 {
1967     IHTMLDOMChildrenCollection *col;
1968     BSTR str;
1969     HRESULT hres;
1970
1971     str = a2bstr(text);
1972     hres = IHTMLElement_put_innerText(elem, str);
1973     ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1974     SysFreeString(str);
1975
1976     _test_elem_innertext(line, elem, text);
1977
1978
1979     col = _get_child_nodes(line, (IUnknown*)elem);
1980     ok(col != NULL, "col == NULL\n");
1981     if(col) {
1982         LONG length = 0, type;
1983         IHTMLDOMNode *node;
1984
1985         hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1986         ok(hres == S_OK, "get_length failed: %08x\n", hres);
1987         ok(length == 1, "length = %d\n", length);
1988
1989         node = _get_child_item(line, col, 0);
1990         ok(node != NULL, "node == NULL\n");
1991         if(node) {
1992             type = _get_node_type(line, (IUnknown*)node);
1993             ok(type == 3, "type=%d\n", type);
1994             IHTMLDOMNode_Release(node);
1995         }
1996
1997         IHTMLDOMChildrenCollection_Release(col);
1998     }
1999
2000 }
2001
2002 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2003 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2004 {
2005     IHTMLElement *elem = _get_elem_iface(line, unk);
2006     BSTR html;
2007     HRESULT hres;
2008
2009     hres = IHTMLElement_get_innerHTML(elem, &html);
2010     ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2011     if(inner_html)
2012         ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2013     else
2014         ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2015
2016     IHTMLElement_Release(elem);
2017     SysFreeString(html);
2018 }
2019
2020 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2021 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2022 {
2023     IHTMLElement *elem = _get_elem_iface(line, unk);
2024     BSTR html;
2025     HRESULT hres;
2026
2027     html = a2bstr(inner_html);
2028     hres = IHTMLElement_put_innerHTML(elem, html);
2029     ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2030
2031     IHTMLElement_Release(elem);
2032     SysFreeString(html);
2033 }
2034
2035 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2036 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2037 {
2038     IHTMLElement *elem = _get_elem_iface(line, unk);
2039     BSTR html;
2040     HRESULT hres;
2041
2042     html = a2bstr(outer_html);
2043     hres = IHTMLElement_put_outerHTML(elem, html);
2044     ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2045
2046     IHTMLElement_Release(elem);
2047     SysFreeString(html);
2048 }
2049
2050 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2051 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2052 {
2053     IHTMLElement *elem = _get_elem_iface(line, unk);
2054     BSTR html;
2055     HRESULT hres;
2056
2057     hres = IHTMLElement_get_outerHTML(elem, &html);
2058     ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2059     ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2060
2061     IHTMLElement_Release(elem);
2062     SysFreeString(html);
2063 }
2064
2065 #define get_first_child(n) _get_first_child(__LINE__,n)
2066 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2067 {
2068     IHTMLDOMNode *node = _get_node_iface(line, unk);
2069     IHTMLDOMNode *child = NULL;
2070     HRESULT hres;
2071
2072     hres = IHTMLDOMNode_get_firstChild(node, &child);
2073     IHTMLDOMNode_Release(node);
2074     ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2075
2076     return child;
2077 }
2078
2079 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2080 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2081 {
2082     IHTMLDOMNode *node = _get_node_iface(line, unk);
2083     VARIANT_BOOL b = 0xdead;
2084     HRESULT hres;
2085
2086     hres = IHTMLDOMNode_hasChildNodes(node, &b);
2087     ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2088     ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2089
2090     IHTMLDOMNode_Release(node);
2091 }
2092
2093 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2094 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2095 {
2096     IHTMLDOMNode *node = _get_node_iface(line, unk);
2097     IHTMLDOMNode *parent;
2098     HRESULT hres;
2099
2100     hres = IHTMLDOMNode_get_parentNode(node, &parent);
2101     IHTMLDOMNode_Release(node);
2102     ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2103
2104     return parent;
2105 }
2106
2107 #define node_get_next(u) _node_get_next(__LINE__,u)
2108 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2109 {
2110     IHTMLDOMNode *node = _get_node_iface(line, unk);
2111     IHTMLDOMNode *next;
2112     HRESULT hres;
2113
2114     hres = IHTMLDOMNode_get_nextSibling(node, &next);
2115     IHTMLDOMNode_Release(node);
2116     ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2117
2118     return next;
2119 }
2120
2121 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2122 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2123 {
2124     IHTMLDOMNode *node = _get_node_iface(line, unk);
2125     IHTMLDOMNode *prev;
2126     HRESULT hres;
2127
2128     hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2129     IHTMLDOMNode_Release(node);
2130     ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2131
2132     return prev;
2133 }
2134
2135 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2136 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2137 {
2138     IHTMLElement *elem = _get_elem_iface(line, unk);
2139     IHTMLElement *parent;
2140     HRESULT hres;
2141
2142     hres = IHTMLElement_get_parentElement(elem, &parent);
2143     IHTMLElement_Release(elem);
2144     ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2145
2146     return parent;
2147 }
2148
2149 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2150 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2151 {
2152     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2153     VARIANT_BOOL disabled = 100;
2154     HRESULT hres;
2155
2156     if (!elem3) return;
2157     hres = IHTMLElement3_get_disabled(elem3, &disabled);
2158     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2159     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2160     IHTMLElement3_Release(elem3);
2161 }
2162
2163 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2164 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2165 {
2166     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2167     HRESULT hres;
2168
2169     if (!elem3) return;
2170     hres = IHTMLElement3_put_disabled(elem3, b);
2171     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2172
2173     IHTMLElement3_Release(elem3);
2174     _test_elem3_get_disabled(line, unk, b);
2175 }
2176
2177 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2178 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2179 {
2180     VARIANT_BOOL disabled = 100;
2181     HRESULT hres;
2182
2183     hres = IHTMLSelectElement_get_disabled(select, &disabled);
2184     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2185     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2186
2187     _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2188 }
2189
2190 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2191 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2192 {
2193     IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2194     LONG length;
2195     HRESULT hres;
2196
2197     hres = IHTMLDOMTextNode_get_length(text, &length);
2198     ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2199     ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2200     IHTMLDOMTextNode_Release(text);
2201 }
2202
2203 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2204 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2205 {
2206     HRESULT hres;
2207
2208     hres = IHTMLSelectElement_put_disabled(select, b);
2209     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2210
2211     _test_select_get_disabled(line, select, b);
2212 }
2213
2214 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2215 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2216 {
2217     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2218     IHTMLTextContainer *txtcont;
2219     LONG l = -1, l2 = -1;
2220     HRESULT hres;
2221
2222     hres = IHTMLElement2_get_scrollHeight(elem, &l);
2223     ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2224     IHTMLElement2_Release(elem);
2225
2226     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2227     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2228
2229     hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2230     IHTMLTextContainer_Release(txtcont);
2231     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2232     ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
2233
2234     return l;
2235 }
2236
2237 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
2238 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
2239 {
2240     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2241     IHTMLTextContainer *txtcont;
2242     LONG l = -1, l2 = -1;
2243     HRESULT hres;
2244
2245     hres = IHTMLElement2_get_scrollWidth(elem, &l);
2246     ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
2247     IHTMLElement2_Release(elem);
2248
2249     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2250     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2251
2252     hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
2253     IHTMLTextContainer_Release(txtcont);
2254     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
2255     ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
2256
2257     return l;
2258 }
2259
2260 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
2261 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
2262 {
2263     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2264     IHTMLTextContainer *txtcont;
2265     LONG l = -1, l2 = -1;
2266     HRESULT hres;
2267
2268     hres = IHTMLElement2_get_scrollTop(elem, &l);
2269     ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2270     IHTMLElement2_Release(elem);
2271
2272     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2273     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2274
2275     hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
2276     IHTMLTextContainer_Release(txtcont);
2277     ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
2278     ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
2279
2280     return l;
2281 }
2282
2283 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
2284 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
2285 {
2286     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2287     IHTMLTextContainer *txtcont;
2288     LONG l = -1, l2 = -1;
2289     HRESULT hres;
2290
2291     hres = IHTMLElement2_get_scrollLeft(elem, NULL);
2292     ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
2293
2294     hres = IHTMLElement2_get_scrollLeft(elem, &l);
2295     ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2296     IHTMLElement2_Release(elem);
2297
2298     hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2299     ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2300
2301     hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
2302     IHTMLTextContainer_Release(txtcont);
2303     ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
2304     ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
2305 }
2306
2307 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
2308 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
2309 {
2310     IHTMLImgElement *img = _get_img_iface(line, unk);
2311     BSTR src;
2312     HRESULT hres;
2313
2314     hres = IHTMLImgElement_get_src(img, &src);
2315     IHTMLImgElement_Release(img);
2316     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2317     ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
2318         "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2319     SysFreeString(src);
2320 }
2321
2322 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
2323 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
2324 {
2325     IHTMLImgElement *img = _get_img_iface(line, unk);
2326     BSTR tmp;
2327     HRESULT hres;
2328
2329     tmp = a2bstr(src);
2330     hres = IHTMLImgElement_put_src(img, tmp);
2331     IHTMLImgElement_Release(img);
2332     SysFreeString(tmp);
2333     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2334 }
2335
2336 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
2337 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
2338 {
2339     IHTMLImgElement *img = _get_img_iface(line, unk);
2340     BSTR alt;
2341     HRESULT hres;
2342
2343     hres = IHTMLImgElement_get_alt(img, &alt);
2344     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2345     if(exalt)
2346         ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
2347     else
2348         ok_(__FILE__,line) (!alt, "alt != NULL\n");
2349     SysFreeString(alt);
2350 }
2351
2352 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
2353 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
2354 {
2355     IHTMLImgElement *img = _get_img_iface(line, unk);
2356     BSTR tmp;
2357     HRESULT hres;
2358
2359     tmp = a2bstr(alt);
2360     hres = IHTMLImgElement_put_alt(img, tmp);
2361     ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2362     SysFreeString(tmp);
2363
2364     _test_img_alt(line, unk, alt);
2365 }
2366
2367 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
2368 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
2369 {
2370     IHTMLImgElement *img = _get_img_iface(line, unk);
2371     BSTR sName;
2372     HRESULT hres;
2373
2374     hres = IHTMLImgElement_get_name(img, &sName);
2375     ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
2376     ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
2377     IHTMLImgElement_Release(img);
2378     SysFreeString(sName);
2379 }
2380
2381 static void test_dynamic_properties(IHTMLElement *elem)
2382 {
2383     static const WCHAR attr1W[] = {'a','t','t','r','1',0};
2384     IDispatchEx *dispex;
2385     BSTR name, attr1 = SysAllocString(attr1W);
2386     VARIANT_BOOL succ;
2387     VARIANT val;
2388     int checked_no = 0;
2389     DISPID id = DISPID_STARTENUM;
2390     HRESULT hres;
2391
2392     hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2393     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2394
2395     hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
2396     ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
2397     ok(succ, "removeAttribute set succ to FALSE\n");
2398
2399     while(1) {
2400         hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2401         ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
2402         if(hres != S_OK)
2403             break;
2404
2405         hres = IDispatchEx_GetMemberName(dispex, id, &name);
2406         ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2407
2408         if(!strcmp_wa(name, "attr1"))
2409             ok(0, "attr1 should be removed\n");
2410         else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
2411             checked_no++;
2412         SysFreeString(name);
2413     }
2414     ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
2415     IDispatchEx_Release(dispex);
2416
2417     V_VT(&val) = VT_BSTR;
2418     V_BSTR(&val) = attr1;
2419     hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
2420     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2421     SysFreeString(attr1);
2422 }
2423
2424 static void test_attr_collection_disp(IDispatch *disp)
2425 {
2426     IDispatchEx *dispex;
2427     IHTMLDOMAttribute *attr;
2428     DISPPARAMS dp = {NULL, NULL, 0, 0};
2429     VARIANT var;
2430     EXCEPINFO ei;
2431     DISPID id;
2432     BSTR bstr;
2433     HRESULT hres;
2434
2435     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2436     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2437
2438     bstr = a2bstr("0");
2439     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2440     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2441     SysFreeString(bstr);
2442
2443     VariantInit(&var);
2444     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2445     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2446     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2447     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2448     VariantClear(&var);
2449
2450     bstr = a2bstr("attr1");
2451     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2452     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2453     SysFreeString(bstr);
2454
2455     VariantInit(&var);
2456     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2457     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2458     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2459     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2460     hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
2461     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2462     hres = IHTMLDOMAttribute_get_nodeName(attr, &bstr);
2463     ok(hres == S_OK, "get_nodeName failed: %08x\n", hres);
2464     ok(!strcmp_wa(bstr, "attr1"), "node name is %s, expected attr1\n", wine_dbgstr_w(bstr));
2465     SysFreeString(bstr);
2466     IHTMLDOMAttribute_Release(attr);
2467     VariantClear(&var);
2468
2469     IDispatchEx_Release(dispex);
2470 }
2471
2472 static void test_attr_collection(IHTMLElement *elem)
2473 {
2474     static const WCHAR testW[] = {'t','e','s','t',0};
2475
2476     IHTMLDOMNode *node;
2477     IDispatch *disp, *attr;
2478     IHTMLDOMAttribute *dom_attr;
2479     IHTMLAttributeCollection *attr_col;
2480     BSTR name = SysAllocString(testW);
2481     VARIANT id, val;
2482     LONG i, len, checked;
2483     HRESULT hres;
2484
2485     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
2486     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2487
2488     hres = IHTMLDOMNode_get_attributes(node, &disp);
2489     ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2490
2491     hres = IHTMLDOMNode_get_attributes(node, &attr);
2492     ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2493     ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
2494     IDispatch_Release(attr);
2495     IHTMLDOMNode_Release(node);
2496
2497     hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
2498     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2499
2500     hres = IHTMLAttributeCollection_get_length(attr_col, &i);
2501     ok(hres == S_OK, "get_length failed: %08x\n", hres);
2502
2503     V_VT(&val) = VT_I4;
2504     V_I4(&val) = 1;
2505     hres = IHTMLElement_setAttribute(elem, name, val, 0);
2506     ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2507     SysFreeString(name);
2508
2509     hres = IHTMLAttributeCollection_get_length(attr_col, &len);
2510     ok(hres == S_OK, "get_length failed: %08x\n", hres);
2511     ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
2512
2513     checked = 0;
2514     for(i=0; i<len; i++) {
2515         V_VT(&id) = VT_I4;
2516         V_I4(&id) = i;
2517         hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2518         ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
2519
2520         hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
2521         ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
2522         IDispatch_Release(attr);
2523
2524         hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
2525         ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
2526
2527         if(!strcmp_wa(name, "id")) {
2528             checked++;
2529             hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2530             ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2531             ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
2532             ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2533         } else if(!strcmp_wa(name, "attr1")) {
2534             checked++;
2535             hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2536             ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2537             ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
2538             ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2539         } else if(!strcmp_wa(name, "attr2")) {
2540             checked++;
2541             hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2542             ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2543             ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
2544             ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
2545         } else if(!strcmp_wa(name, "attr3")) {
2546             checked++;
2547             hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2548             ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2549             ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
2550             ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2551         } else if(!strcmp_wa(name, "test")) {
2552             checked++;
2553             hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2554             ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2555             ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
2556             ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
2557         }
2558
2559         IHTMLDOMAttribute_Release(dom_attr);
2560         SysFreeString(name);
2561         VariantClear(&val);
2562     }
2563     ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
2564
2565     V_I4(&id) = len;
2566     hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2567     ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2568
2569     V_VT(&id) = VT_BSTR;
2570     V_BSTR(&id) = a2bstr("nonexisting");
2571     hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2572     ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2573     VariantClear(&id);
2574
2575     test_attr_collection_disp(disp);
2576
2577     IDispatch_Release(disp);
2578     IHTMLAttributeCollection_Release(attr_col);
2579 }
2580
2581 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
2582 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
2583 {
2584     BSTR type;
2585     HRESULT hres;
2586
2587     hres = IHTMLInputElement_get_type(input, &type);
2588     ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2589     ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
2590     SysFreeString(type);
2591 }
2592
2593 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
2594 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
2595 {
2596     BSTR name = (BSTR)0xdeadbeef;
2597     HRESULT hres;
2598
2599     hres = IHTMLInputElement_get_name(input, &name);
2600     ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
2601     if(exname)
2602         ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
2603     else
2604         ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
2605     SysFreeString(name);
2606 }
2607
2608 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
2609 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
2610 {
2611     BSTR tmp = a2bstr(name);
2612     HRESULT hres;
2613
2614     hres = IHTMLInputElement_put_name(input, tmp);
2615     ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
2616     SysFreeString(tmp);
2617
2618     _test_input_name(line, input, name);
2619 }
2620
2621 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
2622 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2623 {
2624     VARIANT_BOOL disabled = 100;
2625     HRESULT hres;
2626
2627     hres = IHTMLInputElement_get_disabled(input, &disabled);
2628     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2629     ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2630
2631     _test_elem3_get_disabled(line, (IUnknown*)input, exb);
2632 }
2633
2634 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
2635 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2636 {
2637     HRESULT hres;
2638
2639     hres = IHTMLInputElement_put_disabled(input, b);
2640     ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2641
2642     _test_input_get_disabled(line, input, b);
2643 }
2644
2645 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
2646 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2647 {
2648     VARIANT_BOOL checked = 100;
2649     HRESULT hres;
2650
2651     hres = IHTMLInputElement_get_defaultChecked(input, &checked);
2652     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2653     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2654 }
2655
2656 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
2657 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2658 {
2659     HRESULT hres;
2660
2661     hres = IHTMLInputElement_put_defaultChecked(input, b);
2662     ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2663
2664     _test_input_get_defaultchecked(line, input, b);
2665 }
2666
2667 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
2668 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2669 {
2670     VARIANT_BOOL checked = 100;
2671     HRESULT hres;
2672
2673     hres = IHTMLInputElement_get_checked(input, &checked);
2674     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2675     ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2676 }
2677
2678 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
2679 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2680 {
2681     HRESULT hres;
2682
2683     hres = IHTMLInputElement_put_checked(input, b);
2684     ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2685
2686     _test_input_get_checked(line, input, b);
2687 }
2688
2689 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
2690 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
2691 {
2692     IHTMLInputElement *input;
2693     BSTR bstr;
2694     HRESULT hres;
2695
2696     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2697     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2698     if(FAILED(hres))
2699         return;
2700
2701     hres = IHTMLInputElement_get_value(input, &bstr);
2702     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2703     if(exval)
2704         ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
2705     else
2706         ok_(__FILE__,line) (!bstr, "exval != NULL\n");
2707     SysFreeString(bstr);
2708     IHTMLInputElement_Release(input);
2709 }
2710
2711 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
2712 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
2713 {
2714     IHTMLInputElement *input;
2715     BSTR bstr;
2716     HRESULT hres;
2717
2718     hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2719     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2720     if(FAILED(hres))
2721         return;
2722
2723     bstr = a2bstr(val);
2724     hres = IHTMLInputElement_put_value(input, bstr);
2725     ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2726     SysFreeString(bstr);
2727     IHTMLInputElement_Release(input);
2728
2729     _test_input_value(line, unk, val);
2730 }
2731
2732 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
2733 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
2734 {
2735     BSTR src;
2736     HRESULT hres;
2737
2738     hres = IHTMLInputElement_get_src(input, &src);
2739     ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2740     if(exsrc)
2741         ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2742     else
2743         ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
2744     SysFreeString(src);
2745 }
2746
2747 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
2748 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
2749 {
2750     BSTR tmp;
2751     HRESULT hres;
2752
2753     tmp = a2bstr(src);
2754     hres = IHTMLInputElement_put_src(input, tmp);
2755     SysFreeString(tmp);
2756     ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2757
2758     _test_input_src(line, input, src);
2759 }
2760
2761 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
2762 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
2763 {
2764     IHTMLElement *elem = _get_elem_iface(line, unk);
2765     BSTR class = (void*)0xdeadbeef;
2766     HRESULT hres;
2767
2768     hres = IHTMLElement_get_className(elem, &class);
2769     IHTMLElement_Release(elem);
2770     ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
2771     if(exclass)
2772         ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
2773     else
2774         ok_(__FILE__,line) (!class, "class != NULL\n");
2775     SysFreeString(class);
2776 }
2777
2778 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
2779 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
2780 {
2781     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2782     short index = -3;
2783     HRESULT hres;
2784
2785     hres = IHTMLElement2_get_tabIndex(elem2, &index);
2786     IHTMLElement2_Release(elem2);
2787     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2788     ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
2789 }
2790
2791 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
2792 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
2793 {
2794     IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2795     HRESULT hres;
2796
2797     hres = IHTMLElement2_put_tabIndex(elem2, index);
2798     IHTMLElement2_Release(elem2);
2799     ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2800
2801     _test_elem_tabindex(line, unk, index);
2802 }
2803
2804 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
2805 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
2806 {
2807     IHTMLStyleElement *style = _get_style_iface(line, unk);
2808     BSTR media;
2809     HRESULT hres;
2810
2811     hres = IHTMLStyleElement_get_media(style, &media);
2812     ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
2813     if(exmedia)
2814         ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
2815     else
2816         ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
2817
2818     IHTMLStyleElement_Release(style);
2819     SysFreeString(media);
2820 }
2821
2822 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
2823 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
2824 {
2825     IHTMLStyleElement *style = _get_style_iface(line, unk);
2826     BSTR str;
2827     HRESULT hres;
2828
2829     str = a2bstr(media);
2830     hres = IHTMLStyleElement_put_media(style, str);
2831     ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
2832     IHTMLStyleElement_Release(style);
2833     SysFreeString(str);
2834
2835     _test_style_media(line, unk, media);
2836 }
2837
2838 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
2839 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
2840 {
2841     IHTMLStyleElement *style = _get_style_iface(line, unk);
2842     BSTR type;
2843     HRESULT hres;
2844
2845     hres = IHTMLStyleElement_get_type(style, &type);
2846     ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
2847     if(extype)
2848         ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
2849     else
2850         ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
2851
2852     IHTMLStyleElement_Release(style);
2853     SysFreeString(type);
2854 }
2855
2856 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
2857 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
2858 {
2859     IHTMLStyleElement *style = _get_style_iface(line, unk);
2860     BSTR str;
2861     HRESULT hres;
2862
2863     str = a2bstr(type);
2864     hres = IHTMLStyleElement_put_type(style, str);
2865     ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
2866     IHTMLStyleElement_Release(style);
2867     SysFreeString(str);
2868
2869     _test_style_type(line, unk, type);
2870 }
2871
2872 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
2873 static void _test_elem_filters(unsigned line, IUnknown *unk)
2874 {
2875     IHTMLElement *elem = _get_elem_iface(line, unk);
2876     HRESULT hres;
2877     IHTMLFiltersCollection *filters;
2878
2879     hres = IHTMLElement_get_filters(elem, &filters);
2880     ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
2881                         "get_filters failed: %08x\n", hres);
2882     if(hres == S_OK)
2883     {
2884         LONG len;
2885         IDispatchEx *dispex;
2886
2887         hres = IHTMLFiltersCollection_get_length(filters, &len);
2888         ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2889         ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
2890
2891         hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
2892         ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
2893                             "Could not get IDispatchEx interface: %08x\n", hres);
2894         if(SUCCEEDED(hres)) {
2895             test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
2896             IDispatchEx_Release(dispex);
2897         }
2898
2899         IHTMLFiltersCollection_Release(filters);
2900     }
2901
2902     IHTMLElement_Release(elem);
2903 }
2904
2905 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
2906 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
2907 {
2908     IHTMLElement *elem = _get_elem_iface(line, unk);
2909     BSTR tmp;
2910     HRESULT hres;
2911
2912     tmp = class ? a2bstr(class) : NULL;
2913     hres = IHTMLElement_put_className(elem, tmp);
2914     IHTMLElement_Release(elem);
2915     ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
2916     SysFreeString(tmp);
2917
2918     _test_elem_class(line, unk, class);
2919 }
2920
2921 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
2922 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
2923 {
2924     IHTMLElement *elem = _get_elem_iface(line, unk);
2925     BSTR id = (void*)0xdeadbeef;
2926     HRESULT hres;
2927
2928     hres = IHTMLElement_get_id(elem, &id);
2929     IHTMLElement_Release(elem);
2930     ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
2931
2932     if(exid)
2933         ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
2934     else
2935         ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
2936
2937     SysFreeString(id);
2938 }
2939
2940 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
2941 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
2942 {
2943     IHTMLElement *elem = _get_elem_iface(line, unk);
2944     BSTR tmp = a2bstr(new_id);
2945     HRESULT hres;
2946
2947     hres = IHTMLElement_put_id(elem, tmp);
2948     IHTMLElement_Release(elem);
2949     SysFreeString(tmp);
2950     ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
2951
2952     _test_elem_id(line, unk, new_id);
2953 }
2954
2955 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
2956 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
2957 {
2958     IHTMLElement *elem = _get_elem_iface(line, unk);
2959     BSTR title;
2960     HRESULT hres;
2961
2962     hres = IHTMLElement_get_title(elem, &title);
2963     IHTMLElement_Release(elem);
2964     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2965     if(extitle)
2966         ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2967     else
2968         ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
2969
2970     SysFreeString(title);
2971 }
2972
2973 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
2974 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
2975 {
2976     IHTMLElement *elem = _get_elem_iface(line, unk);
2977     BSTR tmp;
2978     HRESULT hres;
2979
2980     tmp = a2bstr(title);
2981     hres = IHTMLElement_put_title(elem, tmp);
2982     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2983
2984     IHTMLElement_Release(elem);
2985     SysFreeString(tmp);
2986 }
2987
2988 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
2989 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
2990 {
2991     IHTMLDOMNode *node = _get_node_iface(line, unk);
2992     VARIANT var;
2993     HRESULT hres;
2994
2995     hres = IHTMLDOMNode_get_nodeValue(node, &var);
2996     IHTMLDOMNode_Release(node);
2997     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
2998
2999     if(exval) {
3000         ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
3001         ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
3002     }else {
3003         ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
3004     }
3005
3006     VariantClear(&var);
3007 }
3008
3009 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
3010 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
3011 {
3012     IHTMLDOMNode *node = _get_node_iface(line, unk);
3013     VARIANT var;
3014     HRESULT hres;
3015
3016     V_VT(&var) = VT_BSTR;
3017     V_BSTR(&var) = a2bstr(val);
3018
3019     hres = IHTMLDOMNode_put_nodeValue(node, var);
3020     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3021     IHTMLDOMNode_Release(node);
3022     VariantClear(&var);
3023 }
3024
3025 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
3026 static void _test_elem_client_size(unsigned line, IUnknown *unk)
3027 {
3028     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3029     LONG l;
3030     HRESULT hres;
3031
3032     hres = IHTMLElement2_get_clientWidth(elem, &l);
3033     ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
3034     hres = IHTMLElement2_get_clientHeight(elem, &l);
3035     ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
3036
3037     IHTMLElement2_Release(elem);
3038 }
3039
3040 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
3041 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
3042 {
3043     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3044     LONG l;
3045     HRESULT hres;
3046
3047     hres = IHTMLElement2_get_clientLeft(elem, &l);
3048     ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
3049     ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
3050
3051     hres = IHTMLElement2_get_clientTop(elem, &l);
3052     ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
3053     ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
3054
3055     IHTMLElement2_Release(elem);
3056 }
3057
3058 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
3059 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
3060 {
3061     IHTMLFormElement *form = _get_form_iface(line, unk);
3062     LONG len = 0xdeadbeef;
3063     HRESULT hres;
3064
3065     hres = IHTMLFormElement_get_length(form, &len);
3066     ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
3067     ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
3068
3069     IHTMLFormElement_Release(form);
3070 }
3071
3072 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
3073 static void _test_form_action(unsigned line, IUnknown *unk, const char *ex)
3074 {
3075     IHTMLFormElement *form = _get_form_iface(line, unk);
3076     BSTR action = (void*)0xdeadbeef;
3077     HRESULT hres;
3078
3079     hres = IHTMLFormElement_get_action(form, &action);
3080     ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
3081     if(ex)
3082         ok_(__FILE__,line)(!strcmp_wa(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), ex);
3083     else
3084         ok_(__FILE__,line)(!action, "action=%p\n", action);
3085
3086     SysFreeString(action);
3087     IHTMLFormElement_Release(form);
3088 }
3089
3090 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
3091 static void _test_form_put_action(unsigned line, IUnknown *unk, const char *action)
3092 {
3093     IHTMLFormElement *form = _get_form_iface(line, unk);
3094     BSTR tmp = a2bstr(action);
3095     HRESULT hres;
3096
3097     hres = IHTMLFormElement_put_action(form, tmp);
3098     ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
3099     SysFreeString(tmp);
3100     IHTMLFormElement_Release(form);
3101
3102     _test_form_action(line, unk, action);
3103 }
3104
3105 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
3106 static void _test_form_method(unsigned line, IUnknown *unk, const char *ex)
3107 {
3108     IHTMLFormElement *form = _get_form_iface(line, unk);
3109     BSTR method = (void*)0xdeadbeef;
3110     HRESULT hres;
3111
3112     hres = IHTMLFormElement_get_method(form, &method);
3113     ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
3114     if(ex)
3115         ok_(__FILE__,line)(!strcmp_wa(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), ex);
3116     else
3117         ok_(__FILE__,line)(!method, "method=%p\n", method);
3118
3119     SysFreeString(method);
3120     IHTMLFormElement_Release(form);
3121 }
3122
3123 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
3124 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *method)
3125 {
3126     IHTMLFormElement *form = _get_form_iface(line, unk);
3127     BSTR tmp = a2bstr(method);
3128     HRESULT hres;
3129
3130     hres = IHTMLFormElement_put_method(form, tmp);
3131     ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
3132     SysFreeString(tmp);
3133     IHTMLFormElement_Release(form);
3134
3135     if(exp_hres == S_OK)
3136         _test_form_method(line, unk, method);
3137 }
3138
3139 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
3140 static void _test_form_name(unsigned line, IUnknown *unk, const char *ex)
3141 {
3142     IHTMLFormElement *form = _get_form_iface(line, unk);
3143     BSTR name = (void*)0xdeadbeef;
3144     HRESULT hres;
3145
3146     hres = IHTMLFormElement_get_name(form, &name);
3147     ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3148     if(ex)
3149         ok_(__FILE__,line)(!strcmp_wa(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), ex);
3150     else
3151         ok_(__FILE__,line)(!name, "name=%p\n", name);
3152
3153     SysFreeString(name);
3154     IHTMLFormElement_Release(form);
3155 }
3156
3157 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
3158 static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
3159 {
3160     IHTMLFormElement *form = _get_form_iface(line, unk);
3161     BSTR tmp = a2bstr(name);
3162     HRESULT hres;
3163
3164     hres = IHTMLFormElement_put_name(form, tmp);
3165     ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
3166     SysFreeString(tmp);
3167     IHTMLFormElement_Release(form);
3168
3169     _test_form_name(line, unk, name);
3170 }
3171
3172 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
3173 static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
3174 {
3175     IHTMLFormElement *form = _get_form_iface(line, unk);
3176     BSTR encoding = (void*)0xdeadbeef;
3177     HRESULT hres;
3178
3179     hres = IHTMLFormElement_get_encoding(form, &encoding);
3180     ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
3181     if(ex)
3182         ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
3183     else
3184         ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
3185
3186     SysFreeString(encoding);
3187     IHTMLFormElement_Release(form);
3188 }
3189
3190 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
3191 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
3192 {
3193     IHTMLFormElement *form = _get_form_iface(line, unk);
3194     BSTR tmp = a2bstr(encoding);
3195     HRESULT hres;
3196
3197     hres = IHTMLFormElement_put_encoding(form, tmp);
3198     ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
3199     SysFreeString(tmp);
3200     IHTMLFormElement_Release(form);
3201
3202     if(exp_hres == S_OK)
3203         _test_form_encoding(line, unk, encoding);
3204 }
3205
3206 #define test_form_elements(a) _test_form_elements(__LINE__,a)
3207 static void _test_form_elements(unsigned line, IUnknown *unk)
3208 {
3209     IHTMLFormElement *form = _get_form_iface(line, unk);
3210     IDispatch *disp;
3211     HRESULT hres;
3212
3213     disp = NULL;
3214     hres = IHTMLFormElement_get_elements(form, &disp);
3215     ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
3216     ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
3217     ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
3218
3219     IDispatch_Release(disp);
3220     IHTMLFormElement_Release(form);
3221 }
3222
3223 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
3224 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
3225 {
3226     IHTMLElement *elem = _get_elem_iface(line, unk);
3227     IHTMLDocument2 *doc;
3228     IDispatch *disp;
3229     HRESULT hres;
3230
3231     disp = NULL;
3232     hres = IHTMLElement_get_document(elem, &disp);
3233     ok(hres == S_OK, "get_document failed: %08x\n", hres);
3234     ok(disp != NULL, "disp == NULL\n");
3235
3236     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
3237     IDispatch_Release(disp);
3238     ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
3239
3240     return doc;
3241 }
3242
3243 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
3244 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const char *attr_name, BOOL expect_success)
3245 {
3246     IHTMLElement4 *elem = _get_elem4_iface(line, unk);
3247     BSTR str = a2bstr(attr_name);
3248     IHTMLDOMAttribute *attr;
3249     HRESULT hres;
3250
3251     attr = (void*)0xdeadbeef;
3252     hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
3253     ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
3254     if(expect_success)
3255         ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
3256     else
3257         ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
3258
3259     IHTMLElement4_Release(elem);
3260     SysFreeString(str);
3261     return attr;
3262 }
3263
3264 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
3265 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
3266 {
3267     HRESULT hres;
3268
3269     hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
3270     ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3271     ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
3272 }
3273
3274 #define get_window_doc(e) _get_window_doc(__LINE__,e)
3275 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
3276 {
3277     IHTMLDocument2 *doc;
3278     HRESULT hres;
3279
3280     doc = NULL;
3281     hres = IHTMLWindow2_get_document(window, &doc);
3282     ok(hres == S_OK, "get_document failed: %08x\n", hres);
3283     ok(doc != NULL, "disp == NULL\n");
3284
3285     return doc;
3286 }
3287
3288 #define doc_get_body(d) _doc_get_body(__LINE__,d)
3289 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
3290 {
3291     IHTMLElement *elem;
3292     HRESULT hres;
3293
3294     hres = IHTMLDocument2_get_body(doc, &elem);
3295     ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
3296     ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
3297
3298     return elem;
3299 }
3300
3301 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
3302 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
3303 {
3304     IHTMLElement *elem = NULL;
3305     BSTR tmp;
3306     HRESULT hres;
3307
3308     tmp = a2bstr(tag);
3309     hres = IHTMLDocument2_createElement(doc, tmp, &elem);
3310     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3311     ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
3312     SysFreeString(tmp);
3313
3314     return elem;
3315 }
3316
3317 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
3318 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
3319 {
3320     IHTMLDocument3 *doc3;
3321     IHTMLDOMNode *node = NULL;
3322     BSTR tmp;
3323     HRESULT hres;
3324
3325     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3326     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
3327
3328     tmp = a2bstr(text);
3329     hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
3330     IHTMLDocument3_Release(doc3);
3331     SysFreeString(tmp);
3332     ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3333     ok_(__FILE__,line) (node != NULL, "node == NULL\n");
3334
3335     return node;
3336 }
3337
3338 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
3339 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
3340 {
3341     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3342     IHTMLDOMNode *child = _get_node_iface(line, child_unk);
3343     IHTMLDOMNode *new_child = NULL;
3344     HRESULT hres;
3345
3346     hres = IHTMLDOMNode_appendChild(node, child, &new_child);
3347     ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
3348     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3349     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3350
3351     IHTMLDOMNode_Release(node);
3352     IHTMLDOMNode_Release(child);
3353
3354     return new_child;
3355 }
3356
3357 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
3358 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
3359 {
3360     IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3361     IHTMLDOMNode *new_child = NULL;
3362     HRESULT hres;
3363
3364     hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
3365     ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
3366     ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3367     /* TODO  ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3368
3369     IHTMLDOMNode_Release(node);
3370
3371     return new_child;
3372 }
3373
3374 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
3375 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
3376 {
3377     IHTMLDOMNode *node = _get_node_iface(line, unk);
3378     IHTMLDOMNode *new_node = NULL;
3379     HRESULT hres;
3380
3381     hres = IHTMLDOMNode_removeChild(node, child, &new_node);
3382     ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
3383     ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
3384     /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
3385
3386     IHTMLDOMNode_Release(node);
3387     IHTMLDOMNode_Release(new_node);
3388 }
3389
3390 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
3391 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
3392 {
3393     BSTR title = NULL;
3394     HRESULT hres;
3395
3396     hres = IHTMLDocument2_get_title(doc, &title);
3397     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3398     ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3399     SysFreeString(title);
3400 }
3401
3402 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
3403 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
3404 {
3405     BSTR tmp;
3406     HRESULT hres;
3407
3408     tmp = a2bstr(title);
3409     hres = IHTMLDocument2_put_title(doc, tmp);
3410     ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3411     SysFreeString(tmp);
3412 }
3413
3414 static void test_elem_bounding_client_rect(IUnknown *unk)
3415 {
3416     IHTMLRect *rect, *rect2;
3417     IHTMLElement2 *elem2;
3418     LONG l;
3419     HRESULT hres;
3420
3421     elem2 = get_elem2_iface(unk);
3422     hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
3423     ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3424     hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
3425     IHTMLElement2_Release(elem2);
3426     ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3427     ok(rect != NULL, "rect == NULL\n");
3428     ok(rect != rect2, "rect == rect2\n");
3429     IHTMLRect_Release(rect2);
3430
3431     test_disp((IUnknown*)rect, &IID_IHTMLRect, "[object]");
3432
3433     l = 0xdeadbeef;
3434     hres = IHTMLRect_get_top(rect, &l);
3435     ok(hres == S_OK, "get_top failed: %08x\n", hres);
3436     ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3437
3438     l = 0xdeadbeef;
3439     hres = IHTMLRect_get_left(rect, &l);
3440     ok(hres == S_OK, "get_left failed: %08x\n", hres);
3441     ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3442
3443     l = 0xdeadbeef;
3444     hres = IHTMLRect_get_bottom(rect, &l);
3445     ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
3446     ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3447
3448     l = 0xdeadbeef;
3449     hres = IHTMLRect_get_right(rect, &l);
3450     ok(hres == S_OK, "get_right failed: %08x\n", hres);
3451     ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3452
3453     IHTMLRect_Release(rect);
3454 }
3455
3456 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
3457         const elem_type_t *elem_types, LONG len)
3458 {
3459     IDispatch *disp;
3460     VARIANT name, index;
3461     DWORD i;
3462     HRESULT hres;
3463
3464     V_VT(&index) = VT_EMPTY;
3465     V_VT(&name) = VT_BSTR;
3466     V_BSTR(&name) = a2bstr(n);
3467
3468     hres = IHTMLElementCollection_item(col, name, index, &disp);
3469     ok(hres == S_OK, "item failed: %08x\n", hres);
3470
3471     test_elem_collection((IUnknown*)disp, elem_types, len);
3472     IDispatch_Release(disp);
3473     ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
3474     if(hres != S_OK)
3475         goto cleanup;
3476
3477     V_VT(&index) = VT_I4;
3478
3479     for(i=0; i<len; i++) {
3480         V_I4(&index) = i;
3481         disp = (void*)0xdeadbeef;
3482         hres = IHTMLElementCollection_item(col, name, index, &disp);
3483         ok(hres == S_OK, "item failed: %08x\n", hres);
3484         ok(disp != NULL, "disp == NULL\n");
3485         if(FAILED(hres) || !disp)
3486             continue;
3487
3488         test_elem_type((IUnknown*)disp, elem_types[i]);
3489
3490         IDispatch_Release(disp);
3491     }
3492
3493     V_I4(&index) = len;
3494     disp = (void*)0xdeadbeef;
3495     hres = IHTMLElementCollection_item(col, name, index, &disp);
3496     ok(hres == S_OK, "item failed: %08x\n", hres);
3497     ok(disp == NULL, "disp != NULL\n");
3498
3499     V_I4(&index) = -1;
3500     disp = (void*)0xdeadbeef;
3501     hres = IHTMLElementCollection_item(col, name, index, &disp);
3502     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3503     ok(disp == NULL, "disp != NULL\n");
3504
3505 cleanup:
3506     SysFreeString(V_BSTR(&name));
3507 }
3508
3509 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
3510 {
3511     IHTMLElementCollection *col;
3512     IHTMLElement *elem;
3513     IDispatch *disp = (void*)0xdeadbeef;
3514     VARIANT name, index;
3515     HRESULT hres;
3516
3517     hres = IHTMLDocument2_get_all(doc, &col);
3518     ok(hres == S_OK, "get_all failed: %08x\n", hres);
3519     ok(col != NULL, "col == NULL\n");
3520     if(FAILED(hres) || !col)
3521         return NULL;
3522
3523     V_VT(&index) = VT_EMPTY;
3524     V_VT(&name) = VT_BSTR;
3525     V_BSTR(&name) = a2bstr(id);
3526
3527     hres = IHTMLElementCollection_item(col, name, index, &disp);
3528     IHTMLElementCollection_Release(col);
3529     SysFreeString(V_BSTR(&name));
3530     ok(hres == S_OK, "item failed: %08x\n", hres);
3531     if(!expect_success) {
3532         ok(disp == NULL, "disp != NULL\n");
3533         return NULL;
3534     }
3535
3536     ok(disp != NULL, "disp == NULL\n");
3537     if(!disp)
3538         return NULL;
3539
3540     elem = get_elem_iface((IUnknown*)disp);
3541     IDispatch_Release(disp);
3542
3543     return elem;
3544 }
3545
3546 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
3547 {
3548     IHTMLDocument3 *doc3;
3549     IHTMLElement *elem;
3550     BSTR tmp;
3551     HRESULT hres;
3552
3553     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3554     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
3555
3556     tmp = a2bstr(id);
3557     hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
3558     SysFreeString(tmp);
3559     ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
3560
3561     IHTMLDocument3_Release(doc3);
3562
3563     return elem;
3564 }
3565
3566 static void test_select_elem(IHTMLSelectElement *select)
3567 {
3568     IDispatch *disp, *disp2;
3569     VARIANT name, index;
3570     HRESULT hres;
3571
3572     test_select_type(select, "select-one");
3573     test_select_length(select, 2);
3574     test_select_selidx(select, 0);
3575     test_select_put_selidx(select, 1);
3576
3577     test_select_set_value(select, "val1");
3578     test_select_value(select, "val1");
3579
3580     test_select_get_disabled(select, VARIANT_FALSE);
3581     test_select_set_disabled(select, VARIANT_TRUE);
3582     test_select_set_disabled(select, VARIANT_FALSE);
3583
3584     disp = NULL;
3585     hres = IHTMLSelectElement_get_options(select, &disp);
3586     ok(hres == S_OK, "get_options failed: %08x\n", hres);
3587     ok(disp != NULL, "options == NULL\n");
3588     ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
3589     IDispatch_Release(disp);
3590
3591     V_VT(&index) = VT_EMPTY;
3592     V_VT(&name) = VT_I4;
3593     V_I4(&name) = -1;
3594     disp = (void*)0xdeadbeef;
3595     hres = IHTMLSelectElement_item(select, name, index, &disp);
3596     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3597     ok(!disp, "disp = %p\n", disp);
3598
3599     V_I4(&name) = 2;
3600     disp = (void*)0xdeadbeef;
3601     hres = IHTMLSelectElement_item(select, name, index, &disp);
3602     ok(hres == S_OK, "item failed: %08x\n", hres);
3603     ok(!disp, "disp = %p\n", disp);
3604
3605     V_I4(&name) = 1;
3606     hres = IHTMLSelectElement_item(select, name, index, NULL);
3607     ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
3608
3609     disp = NULL;
3610     hres = IHTMLSelectElement_item(select, name, index, &disp);
3611     ok(hres == S_OK, "item failed: %08x\n", hres);
3612     ok(disp != NULL, "disp = NULL\n");
3613     test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, NULL);
3614
3615     V_VT(&index) = VT_I4;
3616     V_I4(&index) = 1;
3617     disp2 = NULL;
3618     hres = IHTMLSelectElement_item(select, name, index, &disp2);
3619     ok(hres == S_OK, "item failed: %08x\n", hres);
3620     ok(disp2 != NULL, "disp = NULL\n");
3621     ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3622     IDispatch_Release(disp2);
3623     IDispatch_Release(disp);
3624 }
3625
3626 static void test_form_item(IHTMLElement *elem)
3627 {
3628     IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
3629     IDispatch *disp, *disp2;
3630     VARIANT name, index;
3631     HRESULT hres;
3632
3633     V_VT(&index) = VT_EMPTY;
3634     V_VT(&name) = VT_I4;
3635     V_I4(&name) = -1;
3636     disp = (void*)0xdeadbeef;
3637     hres = IHTMLFormElement_item(form, name, index, &disp);
3638     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3639     ok(!disp, "disp = %p\n", disp);
3640
3641     V_I4(&name) = 2;
3642     disp = (void*)0xdeadbeef;
3643     hres = IHTMLFormElement_item(form, name, index, &disp);
3644     ok(hres == S_OK, "item failed: %08x\n", hres);
3645     ok(!disp, "disp = %p\n", disp);
3646
3647     V_I4(&name) = 1;
3648     hres = IHTMLFormElement_item(form, name, index, NULL);
3649     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3650
3651     disp = NULL;
3652     hres = IHTMLFormElement_item(form, name, index, &disp);
3653     ok(hres == S_OK, "item failed: %08x\n", hres);
3654     ok(disp != NULL, "disp = NULL\n");
3655     test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, NULL);
3656
3657     V_VT(&index) = VT_I4;
3658     V_I4(&index) = 1;
3659     disp2 = NULL;
3660     hres = IHTMLFormElement_item(form, name, index, &disp2);
3661     ok(hres == S_OK, "item failed: %08x\n", hres);
3662     ok(disp2 != NULL, "disp = NULL\n");
3663     ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3664     IDispatch_Release(disp2);
3665     IDispatch_Release(disp);
3666 }
3667
3668 static void test_create_option_elem(IHTMLDocument2 *doc)
3669 {
3670     IHTMLOptionElement *option;
3671
3672     option = create_option_elem(doc, "test text", "test value");
3673
3674     test_option_put_text(option, "new text");
3675     test_option_put_value(option, "new value");
3676     test_option_put_selected(option, VARIANT_TRUE);
3677     test_option_put_selected(option, VARIANT_FALSE);
3678
3679     IHTMLOptionElement_Release(option);
3680 }
3681
3682 static void test_create_img_elem(IHTMLDocument2 *doc)
3683 {
3684     IHTMLImgElement *img;
3685
3686     img = create_img_elem(doc, 10, 15);
3687
3688     if(img){
3689         test_img_put_width(img, 5);
3690         test_img_put_height(img, 20);
3691
3692         IHTMLImgElement_Release(img);
3693         img = NULL;
3694     }
3695
3696     img = create_img_elem(doc, -1, -1);
3697
3698     if(img){
3699         test_img_put_width(img, 5);
3700         test_img_put_height(img, 20);
3701
3702         IHTMLImgElement_Release(img);
3703     }
3704 }
3705
3706 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
3707 {
3708     IHTMLBodyElement *body;
3709     IHTMLTxtRange *range;
3710     IHTMLElement *elem;
3711     HRESULT hres;
3712
3713     elem = doc_get_body(doc);
3714     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
3715     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3716     IHTMLElement_Release(elem);
3717
3718     hres = IHTMLBodyElement_createTextRange(body, &range);
3719     IHTMLBodyElement_Release(body);
3720     ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
3721
3722     return range;
3723 }
3724
3725 static void test_txtrange(IHTMLDocument2 *doc)
3726 {
3727     IHTMLTxtRange *body_range, *range, *range2;
3728     IHTMLSelectionObject *selection;
3729     IDispatch *disp_range;
3730     HRESULT hres;
3731
3732     body_range = test_create_body_range(doc);
3733
3734     test_range_text(body_range, "test abc 123\r\nit's text");
3735
3736     hres = IHTMLTxtRange_duplicate(body_range, &range);
3737     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3738
3739     hres = IHTMLTxtRange_duplicate(body_range, &range2);
3740     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3741     test_range_isequal(range, range2, VARIANT_TRUE);
3742
3743     test_range_text(range, "test abc 123\r\nit's text");
3744     test_range_text(body_range, "test abc 123\r\nit's text");
3745
3746     test_range_collapse(range, TRUE);
3747     test_range_isequal(range, range2, VARIANT_FALSE);
3748     test_range_inrange(range, range2, VARIANT_FALSE);
3749     test_range_inrange(range2, range, VARIANT_TRUE);
3750     IHTMLTxtRange_Release(range2);
3751
3752     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3753     test_range_expand(range, wordW, VARIANT_FALSE, "test ");
3754     test_range_move(range, characterW, 2, 2);
3755     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3756
3757     test_range_collapse(range, FALSE);
3758     test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
3759
3760     test_range_collapse(range, FALSE);
3761     test_range_expand(range, wordW, VARIANT_TRUE, "123");
3762     test_range_expand(range, wordW, VARIANT_FALSE, "123");
3763     test_range_move(range, characterW, 2, 2);
3764     test_range_expand(range, wordW, VARIANT_TRUE, "123");
3765     test_range_moveend(range, characterW, -5, -5);
3766     test_range_text(range, NULL);
3767     test_range_moveend(range, characterW, 3, 3);
3768     test_range_text(range, "c 1");
3769     test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
3770     test_range_collapse(range, TRUE);
3771     test_range_move(range, characterW, 4, 4);
3772     test_range_moveend(range, characterW, 1, 1);
3773     test_range_text(range, " ");
3774     test_range_move(range, wordW, 1, 1);
3775     test_range_moveend(range, characterW, 2, 2);
3776     test_range_text(range, "ab");
3777
3778     IHTMLTxtRange_Release(range);
3779
3780     hres = IHTMLTxtRange_duplicate(body_range, &range);
3781     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3782
3783     test_range_text(range, "test abc 123\r\nit's text");
3784     test_range_move(range, characterW, 3, 3);
3785     test_range_moveend(range, characterW, 1, 1);
3786     test_range_text(range, "t");
3787     test_range_moveend(range, characterW, 3, 3);
3788     test_range_text(range, "t ab");
3789     test_range_moveend(range, characterW, -2, -2);
3790     test_range_text(range, "t ");
3791     test_range_move(range, characterW, 6, 6);
3792     test_range_moveend(range, characterW, 3, 3);
3793     test_range_text(range, "123");
3794     test_range_moveend(range, characterW, 2, 2);
3795     test_range_text(range, "123\r\ni");
3796
3797     IHTMLTxtRange_Release(range);
3798
3799     hres = IHTMLTxtRange_duplicate(body_range, &range);
3800     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3801
3802     test_range_move(range, wordW, 1, 1);
3803     test_range_moveend(range, characterW, 2, 2);
3804     test_range_text(range, "ab");
3805
3806     test_range_move(range, characterW, -2, -2);
3807     test_range_moveend(range, characterW, 2, 2);
3808     test_range_text(range, "t ");
3809
3810     test_range_move(range, wordW, 3, 3);
3811     test_range_move(range, wordW, -2, -2);
3812     test_range_moveend(range, characterW, 2, 2);
3813     test_range_text(range, "ab");
3814
3815     test_range_move(range, characterW, -6, -5);
3816     test_range_moveend(range, characterW, -1, 0);
3817     test_range_moveend(range, characterW, -6, 0);
3818     test_range_move(range, characterW, 2, 2);
3819     test_range_moveend(range, characterW, 2, 2);
3820     test_range_text(range, "st");
3821     test_range_moveend(range, characterW, -6, -4);
3822     test_range_moveend(range, characterW, 2, 2);
3823
3824     IHTMLTxtRange_Release(range);
3825
3826     hres = IHTMLTxtRange_duplicate(body_range, &range);
3827     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3828
3829     test_range_move(range, wordW, 2, 2);
3830     test_range_moveend(range, characterW, 2, 2);
3831     test_range_text(range, "12");
3832
3833     test_range_move(range, characterW, 15, 14);
3834     test_range_move(range, characterW, -2, -2);
3835     test_range_moveend(range, characterW, 3, 2);
3836     test_range_text(range, "t");
3837     test_range_moveend(range, characterW, -1, -1);
3838     test_range_text(range, "t");
3839     test_range_expand(range, wordW, VARIANT_TRUE, "text");
3840     test_range_move(range, characterW, -2, -2);
3841     test_range_moveend(range, characterW, 2, 2);
3842     test_range_text(range, "s ");
3843     test_range_move(range, characterW, 100, 7);
3844     test_range_move(range, wordW, 1, 0);
3845     test_range_move(range, characterW, -2, -2);
3846     test_range_moveend(range, characterW, 3, 2);
3847     test_range_text(range, "t");
3848
3849     IHTMLTxtRange_Release(range);
3850
3851     hres = IHTMLTxtRange_duplicate(body_range, &range);
3852     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3853
3854     test_range_collapse(range, TRUE);
3855     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3856     test_range_put_text(range, "word");
3857     test_range_text(body_range, "wordabc 123\r\nit's text");
3858     test_range_text(range, NULL);
3859     test_range_moveend(range, characterW, 3, 3);
3860     test_range_text(range, "abc");
3861     test_range_movestart(range, characterW, -2, -2);
3862     test_range_text(range, "rdabc");
3863     test_range_movestart(range, characterW, 3, 3);
3864     test_range_text(range, "bc");
3865     test_range_movestart(range, characterW, 4, 4);
3866     test_range_text(range, NULL);
3867     test_range_movestart(range, characterW, -3, -3);
3868     test_range_text(range, "c 1");
3869     test_range_movestart(range, characterW, -7, -6);
3870     test_range_text(range, "wordabc 1");
3871     test_range_movestart(range, characterW, 100, 22);
3872     test_range_text(range, NULL);
3873
3874     IHTMLTxtRange_Release(range);
3875     IHTMLTxtRange_Release(body_range);
3876
3877     hres = IHTMLDocument2_get_selection(doc, &selection);
3878     ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
3879
3880     hres = IHTMLSelectionObject_createRange(selection, &disp_range);
3881     ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
3882     IHTMLSelectionObject_Release(selection);
3883
3884     hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
3885     ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
3886     IDispatch_Release(disp_range);
3887
3888     test_range_text(range, NULL);
3889     test_range_moveend(range, characterW, 3, 3);
3890     test_range_text(range, "wor");
3891     test_range_parent(range, ET_BODY);
3892     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
3893     test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
3894     test_range_move(range, characterW, 3, 3);
3895     test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
3896     test_range_moveend(range, characterW, -4, -4);
3897     test_range_put_text(range, "abc def ");
3898     test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
3899     test_range_move(range, wordW, 1, 1);
3900     test_range_movestart(range, characterW, -1, -1);
3901     test_range_text(range, " ");
3902     test_range_move(range, wordW, 1, 1);
3903     test_range_moveend(range, characterW, 3, 3);
3904     test_range_text(range, "def");
3905     test_range_put_text(range, "xyz");
3906     test_range_moveend(range, characterW, 1, 1);
3907     test_range_move(range, wordW, 1, 1);
3908     test_range_moveend(range, characterW, 2, 2);
3909     test_range_text(range, "ab");
3910
3911     IHTMLTxtRange_Release(range);
3912 }
3913
3914 static void test_txtrange2(IHTMLDocument2 *doc)
3915 {
3916     IHTMLTxtRange *range;
3917
3918     range = test_create_body_range(doc);
3919
3920     test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
3921     test_range_move(range, characterW, 5, 5);
3922     test_range_moveend(range, characterW, 1, 1);
3923     test_range_text(range, "2");
3924     test_range_move(range, characterW, -3, -3);
3925     test_range_moveend(range, characterW, 3, 3);
3926     test_range_text(range, "c\r\n\r\n1");
3927     test_range_collapse(range, VARIANT_FALSE);
3928     test_range_moveend(range, characterW, 4, 4);
3929     test_range_text(range, "23");
3930     test_range_moveend(range, characterW, 1, 1);
3931     test_range_text(range, "23\r\n\r\n\r\nd");
3932     test_range_moveend(range, characterW, -1, -1);
3933     test_range_text(range, "23");
3934     test_range_moveend(range, characterW, -1, -1);
3935     test_range_text(range, "23");
3936     test_range_moveend(range, characterW, -2, -2);
3937     test_range_text(range, "2");
3938
3939     IHTMLTxtRange_Release(range);
3940 }
3941
3942 static void test_compatmode(IHTMLDocument2 *doc)
3943 {
3944     IHTMLDocument5 *doc5;
3945     BSTR mode;
3946     HRESULT hres;
3947
3948     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
3949     ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
3950     if(FAILED(hres))
3951         return;
3952
3953     hres = IHTMLDocument5_get_compatMode(doc5, &mode);
3954     IHTMLDocument5_Release(doc5);
3955     ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
3956     ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
3957     SysFreeString(mode);
3958 }
3959
3960 static void test_location(IHTMLDocument2 *doc)
3961 {
3962     IHTMLLocation *location, *location2;
3963     IHTMLWindow2 *window;
3964     BSTR str;
3965     ULONG ref;
3966     HRESULT hres;
3967
3968     hres = IHTMLDocument2_get_location(doc, &location);
3969     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3970
3971     hres = IHTMLDocument2_get_location(doc, &location2);
3972     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3973
3974     ok(location == location2, "location != location2\n");
3975     IHTMLLocation_Release(location2);
3976
3977     hres = IHTMLDocument2_get_parentWindow(doc, &window);
3978     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3979
3980     hres = IHTMLWindow2_get_location(window, &location2);
3981     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3982     ok(location == location2, "location != location2\n");
3983     IHTMLLocation_Release(location2);
3984
3985     test_ifaces((IUnknown*)location, location_iids);
3986     test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
3987
3988     hres = IHTMLLocation_get_pathname(location, &str);
3989     ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
3990     ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
3991     SysFreeString(str);
3992
3993     hres = IHTMLLocation_get_href(location, NULL);
3994     ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
3995
3996     hres = IHTMLLocation_get_href(location, &str);
3997     ok(hres == S_OK, "get_href failed: %08x\n", hres);
3998     ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
3999     SysFreeString(str);
4000
4001     ref = IHTMLLocation_Release(location);
4002     ok(!ref, "location chould be destroyed here\n");
4003 }
4004
4005 static void test_plugins_col(IHTMLDocument2 *doc)
4006 {
4007     IHTMLPluginsCollection *col, *col2;
4008     IHTMLWindow2 *window;
4009     IOmNavigator *nav;
4010     ULONG ref;
4011     LONG len;
4012     HRESULT hres;
4013
4014     window = get_doc_window(doc);
4015     hres = IHTMLWindow2_get_navigator(window, &nav);
4016     IHTMLWindow2_Release(window);
4017
4018     hres = IOmNavigator_get_plugins(nav, &col);
4019     ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4020
4021     hres = IOmNavigator_get_plugins(nav, &col2);
4022     ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4023     ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4024     IHTMLPluginsCollection_Release(col2);
4025
4026     test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, "[object]");
4027
4028     len = 0xdeadbeef;
4029     hres = IHTMLPluginsCollection_get_length(col, &len);
4030     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4031     ok(!len, "length = %d\n", len);
4032
4033     ref = IHTMLPluginsCollection_Release(col);
4034     ok(!ref, "ref=%d\n", ref);
4035
4036     IOmNavigator_Release(nav);
4037 }
4038
4039 static void test_mime_types_col(IOmNavigator *nav)
4040 {
4041     IHTMLMimeTypesCollection *col, *col2;
4042     LONG length;
4043     ULONG ref;
4044     HRESULT hres;
4045
4046     hres = IOmNavigator_get_mimeTypes(nav, &col);
4047     ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4048
4049     hres = IOmNavigator_get_mimeTypes(nav, &col2);
4050     ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4051     ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4052     IHTMLMimeTypesCollection_Release(col2);
4053
4054     test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, "[object]");
4055
4056     length = 0xdeadbeef;
4057     hres = IHTMLMimeTypesCollection_get_length(col, &length);
4058     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4059     ok(!length, "length = %d\n", length);
4060
4061     ref = IHTMLMimeTypesCollection_Release(col);
4062     ok(!ref, "ref=%d\n", ref);
4063 }
4064
4065 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
4066 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
4067 {
4068     WCHAR buf[64];
4069     int res;
4070
4071     if(pLCIDToLocaleName) {
4072         res = pLCIDToLocaleName(lcid, buf, sizeof(buf)/sizeof(WCHAR), 0);
4073         ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
4074         ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
4075     }else {
4076         win_skip("LCIDToLocaleName not available, unable to test language string\n");
4077         ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
4078     }
4079 }
4080
4081 static void test_navigator(IHTMLDocument2 *doc)
4082 {
4083     IHTMLWindow2 *window;
4084     IOmNavigator *navigator, *navigator2;
4085     char buf[512];
4086     DWORD size;
4087     ULONG ref;
4088     BSTR bstr;
4089     HRESULT hres;
4090
4091     static const WCHAR v40[] = {'4','.','0'};
4092
4093     hres = IHTMLDocument2_get_parentWindow(doc, &window);
4094     ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
4095
4096     hres = IHTMLWindow2_get_navigator(window, &navigator);
4097     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4098     ok(navigator != NULL, "navigator == NULL\n");
4099     test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
4100
4101     hres = IHTMLWindow2_get_navigator(window, &navigator2);
4102     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4103     ok(navigator != navigator2, "navigator2 != navihgator\n");
4104
4105     IHTMLWindow2_Release(window);
4106     IOmNavigator_Release(navigator2);
4107
4108     hres = IOmNavigator_get_appCodeName(navigator, &bstr);
4109     ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
4110     ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4111     SysFreeString(bstr);
4112
4113     bstr = NULL;
4114     hres = IOmNavigator_get_appName(navigator, &bstr);
4115     ok(hres == S_OK, "get_appName failed: %08x\n", hres);
4116     ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4117     SysFreeString(bstr);
4118
4119     bstr = NULL;
4120     hres = IOmNavigator_get_platform(navigator, &bstr);
4121     ok(hres == S_OK, "get_platform failed: %08x\n", hres);
4122     ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "Win64" : "Win32")
4123        || (sizeof(void*) == 8 && broken(!strcmp_wa(bstr, "Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
4124     SysFreeString(bstr);
4125
4126     bstr = NULL;
4127     hres = IOmNavigator_get_cpuClass(navigator, &bstr);
4128     ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
4129     ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "x64" : "x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
4130     SysFreeString(bstr);
4131
4132     bstr = NULL;
4133     hres = IOmNavigator_get_appVersion(navigator, &bstr);
4134     ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4135     ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
4136     SysFreeString(bstr);
4137
4138     bstr = NULL;
4139     hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
4140     ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
4141     test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
4142     SysFreeString(bstr);
4143
4144     if (pGetUserDefaultUILanguage)
4145     {
4146         bstr = NULL;
4147         hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
4148         ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
4149         test_language_string(bstr, pGetUserDefaultUILanguage());
4150         SysFreeString(bstr);
4151     }
4152     else
4153         win_skip("GetUserDefaultUILanguage not available\n");
4154
4155     bstr = NULL;
4156     hres = IOmNavigator_get_userLanguage(navigator, &bstr);
4157     ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
4158     test_language_string(bstr, LOCALE_USER_DEFAULT);
4159     SysFreeString(bstr);
4160
4161     hres = IOmNavigator_toString(navigator, NULL);
4162     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4163
4164     bstr = NULL;
4165     hres = IOmNavigator_toString(navigator, &bstr);
4166     ok(hres == S_OK, "toString failed: %08x\n", hres);
4167     ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
4168     SysFreeString(bstr);
4169
4170     size = sizeof(buf);
4171     hres = ObtainUserAgentString(0, buf, &size);
4172     ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
4173
4174     bstr = NULL;
4175     hres = IOmNavigator_get_userAgent(navigator, &bstr);
4176     ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
4177     ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
4178     SysFreeString(bstr);
4179
4180     if(!strncmp(buf, "Mozilla/", 8)) {
4181         bstr = NULL;
4182         hres = IOmNavigator_get_appVersion(navigator, &bstr);
4183         ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4184         ok(!strcmp_wa(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf+8);
4185         SysFreeString(bstr);
4186     }else {
4187         skip("nonstandard user agent\n");
4188     }
4189
4190     bstr = NULL;
4191     hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
4192     ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
4193     ok(bstr != NULL, "appMinorVersion returned NULL\n");
4194     SysFreeString(bstr);
4195
4196     test_mime_types_col(navigator);
4197
4198     ref = IOmNavigator_Release(navigator);
4199     ok(!ref, "navigator should be destroyed here\n");
4200 }
4201
4202 static void test_screen(IHTMLWindow2 *window)
4203 {
4204     IHTMLScreen *screen, *screen2;
4205     IDispatchEx *dispex;
4206     RECT work_area;
4207     LONG l, exl;
4208     HDC hdc;
4209     HRESULT hres;
4210
4211     screen = NULL;
4212     hres = IHTMLWindow2_get_screen(window, &screen);
4213     ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4214     ok(screen != NULL, "screen == NULL\n");
4215
4216     screen2 = NULL;
4217     hres = IHTMLWindow2_get_screen(window, &screen2);
4218     ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4219     ok(screen2 != NULL, "screen == NULL\n");
4220     ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
4221     IHTMLScreen_Release(screen2);
4222
4223     hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
4224     ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
4225     if(SUCCEEDED(hres)) {
4226         test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
4227         IDispatchEx_Release(dispex);
4228     }
4229
4230     hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
4231
4232     exl = GetDeviceCaps(hdc, HORZRES);
4233     l = 0xdeadbeef;
4234     hres = IHTMLScreen_get_width(screen, &l);
4235     ok(hres == S_OK, "get_width failed: %08x\n", hres);
4236     ok(l == exl, "width = %d, expected %d\n", l, exl);
4237
4238     exl = GetDeviceCaps(hdc, VERTRES);
4239     l = 0xdeadbeef;
4240     hres = IHTMLScreen_get_height(screen, &l);
4241     ok(hres == S_OK, "get_height failed: %08x\n", hres);
4242     ok(l == exl, "height = %d, expected %d\n", l, exl);
4243
4244     exl = GetDeviceCaps(hdc, BITSPIXEL);
4245     l = 0xdeadbeef;
4246     hres = IHTMLScreen_get_colorDepth(screen, &l);
4247     ok(hres == S_OK, "get_height failed: %08x\n", hres);
4248     ok(l == exl, "height = %d, expected %d\n", l, exl);
4249
4250     DeleteObject(hdc);
4251
4252     SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
4253
4254     l = 0xdeadbeef;
4255     hres = IHTMLScreen_get_availHeight(screen, &l);
4256     ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
4257     ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
4258
4259     l = 0xdeadbeef;
4260     hres = IHTMLScreen_get_availWidth(screen, &l);
4261     ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
4262     ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
4263
4264     IHTMLScreen_Release(screen);
4265 }
4266
4267 static void test_default_selection(IHTMLDocument2 *doc)
4268 {
4269     IHTMLSelectionObject *selection;
4270     IHTMLTxtRange *range;
4271     IDispatch *disp;
4272     BSTR str;
4273     HRESULT hres;
4274
4275     hres = IHTMLDocument2_get_selection(doc, &selection);
4276     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
4277
4278     hres = IHTMLSelectionObject_get_type(selection, &str);
4279     ok(hres == S_OK, "get_type failed: %08x\n", hres);
4280     ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
4281     SysFreeString(str);
4282
4283     hres = IHTMLSelectionObject_createRange(selection, &disp);
4284     IHTMLSelectionObject_Release(selection);
4285     ok(hres == S_OK, "createRange failed: %08x\n", hres);
4286
4287     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
4288     IDispatch_Release(disp);
4289     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
4290
4291     test_range_text(range, NULL);
4292     IHTMLTxtRange_Release(range);
4293 }
4294
4295 static void test_doc_elem(IHTMLDocument2 *doc)
4296 {
4297     IHTMLDocument2 *doc_node, *owner_doc;
4298     IHTMLElement *elem;
4299     IHTMLDocument3 *doc3;
4300     HRESULT hres;
4301
4302     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4303     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
4304
4305     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
4306     IHTMLDocument3_Release(doc3);
4307     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4308
4309     test_node_name((IUnknown*)elem, "HTML");
4310     test_elem_tag((IUnknown*)elem, "HTML");
4311
4312     doc_node = get_doc_node(doc);
4313     owner_doc = get_owner_doc((IUnknown*)elem);
4314     ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
4315     IHTMLDocument2_Release(owner_doc);
4316
4317     owner_doc = get_owner_doc((IUnknown*)doc_node);
4318     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4319     IHTMLDocument2_Release(doc_node);
4320
4321     test_elem_client_rect((IUnknown*)elem);
4322
4323     IHTMLElement_Release(elem);
4324 }
4325
4326 static void test_default_body(IHTMLBodyElement *body)
4327 {
4328     LONG l;
4329     BSTR bstr;
4330     HRESULT hres;
4331     VARIANT v;
4332
4333     bstr = (void*)0xdeadbeef;
4334     hres = IHTMLBodyElement_get_background(body, &bstr);
4335     ok(hres == S_OK, "get_background failed: %08x\n", hres);
4336     ok(bstr == NULL, "bstr != NULL\n");
4337
4338     l = elem_get_scroll_height((IUnknown*)body);
4339     ok(l != -1, "scrollHeight == -1\n");
4340     l = elem_get_scroll_width((IUnknown*)body);
4341     ok(l != -1, "scrollWidth == -1\n");
4342     l = elem_get_scroll_top((IUnknown*)body);
4343     ok(!l, "scrollTop = %d\n", l);
4344     elem_get_scroll_left((IUnknown*)body);
4345
4346     /* get_text tests */
4347     hres = IHTMLBodyElement_get_text(body, &v);
4348     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4349     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4350     ok(bstr == NULL, "bstr != NULL\n");
4351
4352     /* get_text - Invalid Text */
4353     V_VT(&v) = VT_BSTR;
4354     V_BSTR(&v) = a2bstr("Invalid");
4355     hres = IHTMLBodyElement_put_text(body, v);
4356     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4357     VariantClear(&v);
4358
4359     V_VT(&v) = VT_NULL;
4360     hres = IHTMLBodyElement_get_text(body, &v);
4361     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4362     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4363     ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
4364     VariantClear(&v);
4365
4366     /* get_text - Valid Text */
4367     V_VT(&v) = VT_BSTR;
4368     V_BSTR(&v) = a2bstr("#FF0000");
4369     hres = IHTMLBodyElement_put_text(body, v);
4370     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4371     VariantClear(&v);
4372
4373     V_VT(&v) = VT_NULL;
4374     hres = IHTMLBodyElement_get_text(body, &v);
4375     ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4376     ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4377     ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
4378     VariantClear(&v);
4379 }
4380
4381 static void test_body_funs(IHTMLBodyElement *body)
4382 {
4383     VARIANT vbg, vDefaultbg;
4384     HRESULT hres;
4385
4386     hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
4387     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4388     ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
4389     ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
4390
4391     V_VT(&vbg) = VT_BSTR;
4392     V_BSTR(&vbg) = a2bstr("red");
4393     hres = IHTMLBodyElement_put_bgColor(body, vbg);
4394     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4395     VariantClear(&vbg);
4396
4397     hres = IHTMLBodyElement_get_bgColor(body, &vbg);
4398     ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4399     ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
4400     ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
4401     VariantClear(&vbg);
4402
4403     /* Restore Originial */
4404     hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
4405     ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4406     VariantClear(&vDefaultbg);
4407 }
4408
4409 static void test_window(IHTMLDocument2 *doc)
4410 {
4411     IHTMLWindow2 *window, *window2, *self;
4412     IHTMLDocument2 *doc2 = NULL;
4413     IDispatch *disp;
4414     IUnknown *unk;
4415     BSTR str;
4416     HRESULT hres;
4417
4418     hres = IHTMLDocument2_get_parentWindow(doc, &window);
4419     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4420     test_ifaces((IUnknown*)window, window_iids);
4421     hres = IDispatch_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
4422     if(hres == S_OK)
4423         IUnknown_Release(unk);
4424     else
4425         win_skip("IID_ITravelLogClient not supported\n");
4426
4427     test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
4428
4429     hres = IHTMLWindow2_get_document(window, &doc2);
4430     ok(hres == S_OK, "get_document failed: %08x\n", hres);
4431     ok(doc2 != NULL, "doc2 == NULL\n");
4432
4433     test_ifaces((IUnknown*)doc2, doc_node_iids);
4434     test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4435     test_class_info((IUnknown*)doc2);
4436
4437     test_ifaces((IUnknown*)doc, doc_obj_iids);
4438     test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, "[object]");
4439     test_class_info((IUnknown*)doc);
4440
4441     unk = (void*)0xdeadbeef;
4442     hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
4443     ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
4444     ok(!unk, "unk = %p\n", unk);
4445
4446     IHTMLDocument_Release(doc2);
4447
4448     hres = IHTMLWindow2_get_window(window, &window2);
4449     ok(hres == S_OK, "get_window failed: %08x\n", hres);
4450     ok(window2 != NULL, "window2 == NULL\n");
4451
4452     hres = IHTMLWindow2_get_self(window, &self);
4453     ok(hres == S_OK, "get_self failed: %08x\n", hres);
4454     ok(window2 != NULL, "self == NULL\n");
4455
4456     ok(self == window2, "self != window2\n");
4457
4458     IHTMLWindow2_Release(window2);
4459     IHTMLWindow2_Release(self);
4460
4461     disp = NULL;
4462     hres = IHTMLDocument2_get_Script(doc, &disp);
4463     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4464     ok(disp == (void*)window, "disp != window\n");
4465     IDispatch_Release(disp);
4466
4467     hres = IHTMLWindow2_toString(window, NULL);
4468     ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4469
4470     str = NULL;
4471     hres = IHTMLWindow2_toString(window, &str);
4472     ok(hres == S_OK, "toString failed: %08x\n", hres);
4473     ok(!strcmp_wa(str, "[object]") ||
4474        !strcmp_wa(str, "[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
4475     SysFreeString(str);
4476
4477     test_window_name(window, NULL);
4478     set_window_name(window, "test");
4479     test_window_length(window, 0);
4480     test_screen(window);
4481     test_window_status(window);
4482     set_window_status(window, "Test!");
4483
4484     IHTMLWindow2_Release(window);
4485 }
4486
4487 static void test_defaults(IHTMLDocument2 *doc)
4488 {
4489     IHTMLStyleSheetsCollection *stylesheetcol;
4490     IHTMLCurrentStyle *cstyle;
4491     IHTMLBodyElement *body;
4492     IHTMLElement2 *elem2;
4493     IHTMLElement *elem;
4494     IHTMLStyle *style;
4495     LONG l;
4496     HRESULT hres;
4497     IHTMLElementCollection *collection;
4498
4499     elem = doc_get_body(doc);
4500
4501     hres = IHTMLDocument2_get_images(doc, NULL);
4502     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4503
4504     hres = IHTMLDocument2_get_images(doc, &collection);
4505     ok(hres == S_OK, "get_images failed: %08x\n", hres);
4506     if(hres == S_OK)
4507     {
4508         test_elem_collection((IUnknown*)collection, NULL, 0);
4509         IHTMLElementCollection_Release(collection);
4510     }
4511
4512     hres = IHTMLDocument2_get_applets(doc, NULL);
4513     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4514
4515     hres = IHTMLDocument2_get_applets(doc, &collection);
4516     ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4517     if(hres == S_OK)
4518     {
4519         test_elem_collection((IUnknown*)collection, NULL, 0);
4520         IHTMLElementCollection_Release(collection);
4521     }
4522
4523     hres = IHTMLDocument2_get_links(doc, NULL);
4524     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4525
4526     hres = IHTMLDocument2_get_links(doc, &collection);
4527     ok(hres == S_OK, "get_links failed: %08x\n", hres);
4528     if(hres == S_OK)
4529     {
4530         test_elem_collection((IUnknown*)collection, NULL, 0);
4531         IHTMLElementCollection_Release(collection);
4532     }
4533
4534     hres = IHTMLDocument2_get_forms(doc, NULL);
4535     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4536
4537     hres = IHTMLDocument2_get_forms(doc, &collection);
4538     ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4539     if(hres == S_OK)
4540     {
4541         test_elem_collection((IUnknown*)collection, NULL, 0);
4542         IHTMLElementCollection_Release(collection);
4543     }
4544
4545     hres = IHTMLDocument2_get_anchors(doc, NULL);
4546     ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4547
4548     hres = IHTMLDocument2_get_anchors(doc, &collection);
4549     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4550     if(hres == S_OK)
4551     {
4552         test_elem_collection((IUnknown*)collection, NULL, 0);
4553         IHTMLElementCollection_Release(collection);
4554     }
4555
4556     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4557     ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
4558     test_default_body(body);
4559     test_body_funs(body);
4560     IHTMLBodyElement_Release(body);
4561
4562     hres = IHTMLElement_get_style(elem, &style);
4563     ok(hres == S_OK, "get_style failed: %08x\n", hres);
4564
4565     test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
4566     test_ifaces((IUnknown*)style, style_iids);
4567     IHTMLStyle_Release(style);
4568
4569     test_window(doc);
4570     test_compatmode(doc);
4571     test_location(doc);
4572     test_navigator(doc);
4573     test_plugins_col(doc);
4574
4575     elem2 = get_elem2_iface((IUnknown*)elem);
4576     hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
4577     ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
4578     if(SUCCEEDED(hres)) {
4579         IUnknown *unk;
4580
4581         test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, "[object]");
4582         test_ifaces((IUnknown*)cstyle, cstyle_iids);
4583
4584         hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
4585         if(SUCCEEDED(hres))
4586             IUnknown_Release(unk);
4587         else
4588         {
4589            /*IE6 doesn't have interface */
4590            win_skip("IID_IHTMLCurrentStyle4 not supported\n");
4591         }
4592
4593         IHTMLCurrentStyle_Release(cstyle);
4594     }
4595     IHTMLElement2_Release(elem2);
4596
4597     IHTMLElement_Release(elem);
4598
4599     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
4600     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4601
4602     l = 0xdeadbeef;
4603     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
4604     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4605     ok(l == 0, "length = %d\n", l);
4606
4607     IHTMLStyleSheetsCollection_Release(stylesheetcol);
4608
4609     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
4610     ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
4611
4612     test_default_selection(doc);
4613     test_doc_title(doc, "");
4614 }
4615
4616 static void test_tr_elem(IHTMLElement *elem)
4617 {
4618     IHTMLElementCollection *col;
4619     IHTMLTableRow *row;
4620     HRESULT hres;
4621
4622     static const elem_type_t cell_types[] = {ET_TD,ET_TD};
4623
4624     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
4625     ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
4626     if(FAILED(hres))
4627         return;
4628
4629     col = NULL;
4630     hres = IHTMLTableRow_get_cells(row, &col);
4631     ok(hres == S_OK, "get_cells failed: %08x\n", hres);
4632     ok(col != NULL, "get_cells returned NULL\n");
4633
4634     test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
4635     IHTMLElementCollection_Release(col);
4636
4637     IHTMLTable_Release(row);
4638 }
4639
4640 static void test_table_elem(IHTMLElement *elem)
4641 {
4642     IHTMLElementCollection *col;
4643     IHTMLTable *table;
4644     IHTMLDOMNode *node;
4645     HRESULT hres;
4646
4647     static const elem_type_t row_types[] = {ET_TR,ET_TR};
4648     static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
4649
4650     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
4651     ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
4652     if(FAILED(hres))
4653         return;
4654
4655     col = NULL;
4656     hres = IHTMLTable_get_rows(table, &col);
4657     ok(hres == S_OK, "get_rows failed: %08x\n", hres);
4658     ok(col != NULL, "get_ros returned NULL\n");
4659
4660     test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
4661     IHTMLElementCollection_Release(col);
4662
4663     test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
4664
4665     node = clone_node((IUnknown*)table, VARIANT_TRUE);
4666     test_elem_tag((IUnknown*)node, "TABLE");
4667     test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
4668     IHTMLDOMNode_Release(node);
4669
4670     node = clone_node((IUnknown*)table, VARIANT_FALSE);
4671     test_elem_tag((IUnknown*)node, "TABLE");
4672     test_elem_all((IUnknown*)node, NULL, 0);
4673     IHTMLDOMNode_Release(node);
4674
4675     IHTMLTable_Release(table);
4676 }
4677
4678 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
4679 {
4680     SAFEARRAYBOUND dim;
4681     SAFEARRAY *sa;
4682     VARIANT *var;
4683     HRESULT hres;
4684
4685     dim.lLbound = 0;
4686     dim.cElements = 1;
4687     sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4688     SafeArrayAccessData(sa, (void**)&var);
4689     V_VT(var) = VT_BSTR;
4690     V_BSTR(var) = a2bstr(text);
4691     SafeArrayUnaccessData(sa);
4692
4693     if(ln)
4694         hres = IHTMLDocument2_writeln(doc, sa);
4695     else
4696         hres = IHTMLDocument2_write(doc, sa);
4697     ok(hres == S_OK, "write failed: %08x\n", hres);
4698
4699     SafeArrayDestroy(sa);
4700 }
4701
4702 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
4703 {
4704     IHTMLDocument2 *window_doc, *elem_doc;
4705     IHTMLFrameElement3 *frame_elem3;
4706     IHTMLWindow2 *content_window;
4707     HRESULT hres;
4708
4709     content_window = get_frame_content_window(frame_elem);
4710     window_doc = get_window_doc(content_window);
4711     IHTMLWindow2_Release(content_window);
4712
4713     elem_doc = get_elem_doc(frame_elem);
4714     ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
4715
4716     if(!iframe) {
4717         hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
4718         if(SUCCEEDED(hres)) {
4719             IDispatch *disp = NULL;
4720
4721             hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
4722             ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
4723             ok(disp != NULL, "contentDocument == NULL\n");
4724             ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
4725
4726             IDispatch_Release(disp);
4727             IHTMLFrameElement3_Release(frame_elem3);
4728         }else {
4729             win_skip("IHTMLFrameElement3 not supported\n");
4730         }
4731     }
4732
4733     IHTMLDocument2_Release(elem_doc);
4734     IHTMLDocument2_Release(window_doc);
4735 }
4736
4737 static void test_iframe_elem(IHTMLElement *elem)
4738 {
4739     IHTMLDocument2 *content_doc, *owner_doc;
4740     IHTMLElementCollection *col;
4741     IHTMLWindow2 *content_window;
4742     IDispatch *disp;
4743     VARIANT errv;
4744     BSTR str;
4745     HRESULT hres;
4746
4747     static const elem_type_t all_types[] = {
4748         ET_HTML,
4749         ET_HEAD,
4750         ET_TITLE,
4751         ET_BODY,
4752         ET_BR
4753     };
4754
4755     test_frame_doc((IUnknown*)elem, TRUE);
4756
4757     content_window = get_frame_content_window((IUnknown*)elem);
4758     test_window_length(content_window, 0);
4759
4760     content_doc = get_window_doc(content_window);
4761     IHTMLWindow2_Release(content_window);
4762
4763     str = a2bstr("text/html");
4764     V_VT(&errv) = VT_ERROR;
4765     disp = NULL;
4766     hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
4767     SysFreeString(str);
4768     ok(hres == S_OK, "open failed: %08x\n", hres);
4769     ok(disp != NULL, "disp == NULL\n");
4770     ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
4771     IDispatch_Release(disp);
4772
4773     doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
4774     doc_write(content_doc, TRUE, "</html>");
4775
4776     hres = IHTMLDocument2_get_all(content_doc, &col);
4777     ok(hres == S_OK, "get_all failed: %08x\n", hres);
4778     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4779     IHTMLElementCollection_Release(col);
4780
4781     hres = IHTMLDocument2_close(content_doc);
4782     ok(hres == S_OK, "close failed: %08x\n", hres);
4783
4784     owner_doc = get_owner_doc((IUnknown*)content_doc);
4785     ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4786
4787     IHTMLDocument2_Release(content_doc);
4788 }
4789
4790 static void test_stylesheet(IDispatch *disp)
4791 {
4792     IHTMLStyleSheetRulesCollection *col = NULL;
4793     IHTMLStyleSheet *stylesheet;
4794     HRESULT hres;
4795
4796     hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
4797     ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
4798
4799     hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
4800     ok(hres == S_OK, "get_rules failed: %08x\n", hres);
4801     ok(col != NULL, "col == NULL\n");
4802
4803     IHTMLStyleSheetRulesCollection_Release(col);
4804     IHTMLStyleSheet_Release(stylesheet);
4805 }
4806
4807 static void test_stylesheets(IHTMLDocument2 *doc)
4808 {
4809     IHTMLStyleSheetsCollection *col = NULL;
4810     VARIANT idx, res;
4811     LONG len = 0;
4812     HRESULT hres;
4813
4814     hres = IHTMLDocument2_get_styleSheets(doc, &col);
4815     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4816     ok(col != NULL, "col == NULL\n");
4817
4818     test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
4819
4820     hres = IHTMLStyleSheetsCollection_get_length(col, &len);
4821     ok(hres == S_OK, "get_length failed: %08x\n", hres);
4822     ok(len == 1, "len=%d\n", len);
4823
4824     VariantInit(&res);
4825     V_VT(&idx) = VT_I4;
4826     V_I4(&idx) = 0;
4827
4828     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4829     ok(hres == S_OK, "item failed: %08x\n", hres);
4830     ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
4831     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4832     test_stylesheet(V_DISPATCH(&res));
4833     VariantClear(&res);
4834
4835     V_VT(&res) = VT_I4;
4836     V_VT(&idx) = VT_I4;
4837     V_I4(&idx) = 1;
4838
4839     hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4840     ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4841     ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
4842     ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4843     VariantClear(&res);
4844
4845     IHTMLStyleSheetsCollection_Release(col);
4846 }
4847
4848 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
4849 {
4850     IDispatchEx *dispex;
4851     IHTMLDOMNode *node;
4852     DISPPARAMS dp = {NULL, NULL, 0, 0};
4853     VARIANT var;
4854     EXCEPINFO ei;
4855     LONG type;
4856     DISPID id;
4857     BSTR bstr;
4858     HRESULT hres;
4859
4860     static const WCHAR w0[] = {'0',0};
4861     static const WCHAR w100[] = {'1','0','0',0};
4862
4863     hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
4864     ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
4865
4866     bstr = SysAllocString(w0);
4867     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4868     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
4869     SysFreeString(bstr);
4870
4871     VariantInit(&var);
4872     hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
4873     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
4874     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
4875     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
4876     node = get_node_iface((IUnknown*)V_DISPATCH(&var));
4877     type = get_node_type((IUnknown*)node);
4878     ok(type == 3, "type=%d\n", type);
4879     IHTMLDOMNode_Release(node);
4880     VariantClear(&var);
4881
4882     bstr = SysAllocString(w100);
4883     hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4884     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
4885     SysFreeString(bstr);
4886
4887     IDispatchEx_Release(dispex);
4888 }
4889
4890
4891
4892 static void test_elems(IHTMLDocument2 *doc)
4893 {
4894     IHTMLElementCollection *col;
4895     IHTMLDOMChildrenCollection *child_col;
4896     IHTMLElement *elem, *elem2, *elem3;
4897     IHTMLDOMNode *node, *node2;
4898     IHTMLWindow2 *window;
4899     IDispatch *disp;
4900     LONG type;
4901     HRESULT hres;
4902     IHTMLElementCollection *collection;
4903     IHTMLDocument3 *doc3;
4904     BSTR str;
4905
4906     static const elem_type_t all_types[] = {
4907         ET_HTML,
4908         ET_HEAD,
4909         ET_TITLE,
4910         ET_STYLE,
4911         ET_BODY,
4912         ET_COMMENT,
4913         ET_A,
4914         ET_INPUT,
4915         ET_SELECT,
4916         ET_OPTION,
4917         ET_OPTION,
4918         ET_TEXTAREA,
4919         ET_TABLE,
4920         ET_TBODY,
4921         ET_TR,
4922         ET_TR,
4923         ET_TD,
4924         ET_TD,
4925         ET_SCRIPT,
4926         ET_TEST,
4927         ET_OBJECT,
4928         ET_EMBED,
4929         ET_IMG,
4930         ET_IFRAME,
4931         ET_FORM,
4932         ET_DIV
4933     };
4934
4935     static const elem_type_t item_types[] = {
4936         ET_A,
4937         ET_OPTION,
4938         ET_TEXTAREA
4939     };
4940
4941     hres = IHTMLDocument2_get_all(doc, &col);
4942     ok(hres == S_OK, "get_all failed: %08x\n", hres);
4943     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4944     test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
4945     IHTMLElementCollection_Release(col);
4946
4947     hres = IHTMLDocument2_get_images(doc, &collection);
4948     ok(hres == S_OK, "get_images failed: %08x\n", hres);
4949     if(hres == S_OK)
4950     {
4951         static const elem_type_t images_types[] = {ET_IMG};
4952         test_elem_collection((IUnknown*)collection, images_types, 1);
4953
4954         IHTMLElementCollection_Release(collection);
4955     }
4956
4957     hres = IHTMLDocument2_get_links(doc, &collection);
4958     ok(hres == S_OK, "get_links failed: %08x\n", hres);
4959     if(hres == S_OK)
4960     {
4961         static const elem_type_t images_types[] = {ET_A};
4962         test_elem_collection((IUnknown*)collection, images_types, 1);
4963
4964         IHTMLElementCollection_Release(collection);
4965     }
4966
4967     hres = IHTMLDocument2_get_anchors(doc, &collection);
4968     ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4969     if(hres == S_OK)
4970     {
4971         static const elem_type_t anchor_types[] = {ET_A};
4972         test_elem_collection((IUnknown*)collection, anchor_types, 1);
4973
4974         IHTMLElementCollection_Release(collection);
4975     }
4976
4977     test_plugins_col(doc);
4978
4979     elem = get_doc_elem(doc);
4980     test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
4981     IHTMLElement_Release(elem);
4982
4983     get_elem_by_id(doc, "xxx", FALSE);
4984     elem = get_doc_elem_by_id(doc, "xxx");
4985     ok(!elem, "elem != NULL\n");
4986
4987     elem = get_doc_elem_by_id(doc, "s");
4988     ok(elem != NULL, "elem == NULL\n");
4989     if(elem) {
4990         test_elem_type((IUnknown*)elem, ET_SELECT);
4991         test_elem_attr(elem, "xxx", NULL);
4992         test_elem_attr(elem, "id", "s");
4993         test_elem_class((IUnknown*)elem, NULL);
4994         test_elem_set_class((IUnknown*)elem, "cl");
4995         test_elem_set_class((IUnknown*)elem, NULL);
4996         test_elem_tabindex((IUnknown*)elem, 0);
4997         test_elem_set_tabindex((IUnknown*)elem, 1);
4998         test_elem_filters((IUnknown*)elem);
4999
5000         node = test_node_get_parent((IUnknown*)elem);
5001         ok(node != NULL, "node == NULL\n");
5002         test_node_name((IUnknown*)node, "BODY");
5003         node2 = test_node_get_parent((IUnknown*)node);
5004         IHTMLDOMNode_Release(node);
5005         ok(node2 != NULL, "node == NULL\n");
5006         test_node_name((IUnknown*)node2, "HTML");
5007         node = test_node_get_parent((IUnknown*)node2);
5008         IHTMLDOMNode_Release(node2);
5009         ok(node != NULL, "node == NULL\n");
5010         if (node)
5011         {
5012             test_node_name((IUnknown*)node, "#document");
5013             type = get_node_type((IUnknown*)node);
5014             ok(type == 9, "type=%d, expected 9\n", type);
5015             node2 = test_node_get_parent((IUnknown*)node);
5016             IHTMLDOMNode_Release(node);
5017             ok(node2 == NULL, "node != NULL\n");
5018         }
5019
5020         elem2 = test_elem_get_parent((IUnknown*)elem);
5021         ok(elem2 != NULL, "elem2 == NULL\n");
5022         test_node_name((IUnknown*)elem2, "BODY");
5023         elem3 = test_elem_get_parent((IUnknown*)elem2);
5024         IHTMLElement_Release(elem2);
5025         ok(elem3 != NULL, "elem3 == NULL\n");
5026         test_node_name((IUnknown*)elem3, "HTML");
5027         elem2 = test_elem_get_parent((IUnknown*)elem3);
5028         IHTMLElement_Release(elem3);
5029         ok(elem2 == NULL, "elem2 != NULL\n");
5030
5031         test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
5032         test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
5033         test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
5034
5035         test_elem_innertext(elem, "opt1opt2");
5036
5037         IHTMLElement_Release(elem);
5038     }
5039
5040     elem = get_elem_by_id(doc, "s", TRUE);
5041     if(elem) {
5042         IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
5043         IHTMLDocument2 *doc_node, *elem_doc;
5044
5045         test_select_elem(select);
5046
5047         test_elem_title((IUnknown*)select, NULL);
5048         test_elem_set_title((IUnknown*)select, "Title");
5049         test_elem_title((IUnknown*)select, "Title");
5050         test_elem_offset((IUnknown*)select, "BODY");
5051         test_elem_bounding_client_rect((IUnknown*)select);
5052
5053         node = get_first_child((IUnknown*)select);
5054         ok(node != NULL, "node == NULL\n");
5055         if(node) {
5056             test_elem_type((IUnknown*)node, ET_OPTION);
5057             IHTMLDOMNode_Release(node);
5058         }
5059
5060         type = get_node_type((IUnknown*)select);
5061         ok(type == 1, "type=%d\n", type);
5062
5063         IHTMLSelectElement_Release(select);
5064
5065         elem_doc = get_elem_doc((IUnknown*)elem);
5066
5067         doc_node = get_doc_node(doc);
5068         ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
5069         IHTMLDocument2_Release(doc_node);
5070         IHTMLDocument2_Release(elem_doc);
5071
5072         IHTMLElement_Release(elem);
5073     }
5074
5075     elem = get_elem_by_id(doc, "sc", TRUE);
5076     if(elem) {
5077         IHTMLScriptElement *script;
5078         BSTR type;
5079
5080         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
5081         ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
5082
5083         if(hres == S_OK)
5084         {
5085             VARIANT_BOOL vb;
5086
5087             hres = IHTMLScriptElement_put_type (script, NULL);
5088             ok(hres == S_OK, "put_type failed: %08x\n", hres);
5089             hres = IHTMLScriptElement_get_type(script, &type);
5090             ok(hres == S_OK, "get_type failed: %08x\n", hres);
5091             ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
5092
5093             hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
5094             ok(hres == S_OK, "put_type failed: %08x\n", hres);
5095             hres = IHTMLScriptElement_get_type(script, &type);
5096             ok(hres == S_OK, "get_type failed: %08x\n", hres);
5097             ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
5098
5099             SysFreeString(type);
5100
5101             /* test defer */
5102             hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
5103             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5104
5105             hres = IHTMLScriptElement_get_defer(script, &vb);
5106             ok(hres == S_OK, "get_defer failed: %08x\n", hres);
5107             ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
5108
5109             hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
5110             ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5111
5112             str = (BSTR)0xdeadbeef;
5113             hres = IHTMLScriptElement_get_src(script, &str);
5114             ok(hres == S_OK, "get_src failed: %08x\n", hres);
5115             ok(!str, "src = %s\n", wine_dbgstr_w(str));
5116         }
5117
5118         IHTMLScriptElement_Release(script);
5119     }
5120
5121     elem = get_elem_by_id(doc, "in", TRUE);
5122     if(elem) {
5123         IHTMLInputElement *input;
5124
5125         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
5126         ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
5127
5128         test_elem_id((IUnknown*)elem, "in");
5129         test_elem_put_id((IUnknown*)elem, "newin");
5130         test_input_get_disabled(input, VARIANT_FALSE);
5131         test_input_set_disabled(input, VARIANT_TRUE);
5132         test_input_set_disabled(input, VARIANT_FALSE);
5133         test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
5134         test_input_get_disabled(input, VARIANT_TRUE);
5135         test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
5136         test_input_get_disabled(input, VARIANT_FALSE);
5137         test_elem_client_size((IUnknown*)elem);
5138         test_input_type(input, "text");
5139
5140         test_node_get_value_str((IUnknown*)elem, NULL);
5141         test_node_put_value_str((IUnknown*)elem, "test");
5142         test_node_get_value_str((IUnknown*)elem, NULL);
5143         test_input_value((IUnknown*)elem, NULL);
5144         test_input_put_value((IUnknown*)elem, "test");
5145         test_elem_class((IUnknown*)elem, "testclass");
5146         test_elem_tabindex((IUnknown*)elem, 2);
5147         test_elem_set_tabindex((IUnknown*)elem, 3);
5148         test_elem_title((IUnknown*)elem, "test title");
5149
5150         test_input_get_defaultchecked(input, VARIANT_FALSE);
5151         test_input_set_defaultchecked(input, VARIANT_TRUE);
5152         test_input_set_defaultchecked(input, VARIANT_FALSE);
5153
5154         test_input_get_checked(input, VARIANT_FALSE);
5155         test_input_set_checked(input, VARIANT_TRUE);
5156         test_input_set_checked(input, VARIANT_FALSE);
5157
5158         test_input_name(input, NULL);
5159         test_input_set_name(input, "test");
5160
5161         test_input_src(input, NULL);
5162         test_input_set_src(input, "about:blank");
5163
5164         IHTMLInputElement_Release(input);
5165         IHTMLElement_Release(elem);
5166     }
5167
5168     elem = get_elem_by_id(doc, "imgid", TRUE);
5169     if(elem) {
5170         test_img_src((IUnknown*)elem, "", NULL);
5171         test_img_set_src((IUnknown*)elem, "about:blank");
5172         test_img_src((IUnknown*)elem, "about:blank", NULL);
5173         test_img_alt((IUnknown*)elem, NULL);
5174         test_img_set_alt((IUnknown*)elem, "alt test");
5175         test_img_name((IUnknown*)elem, "WineImg");
5176         IHTMLElement_Release(elem);
5177     }
5178
5179     elem = get_elem_by_id(doc, "attr", TRUE);
5180     if(elem) {
5181         test_dynamic_properties(elem);
5182         test_attr_collection(elem);
5183         IHTMLElement_Release(elem);
5184     }
5185
5186     elem = get_elem_by_id(doc, "styleid", TRUE);
5187     if(elem) {
5188         test_style_media((IUnknown*)elem, NULL);
5189         test_style_put_media((IUnknown*)elem, "screen");
5190         test_style_type((IUnknown*)elem, NULL);
5191         test_style_put_type((IUnknown*)elem, "text/css");
5192         IHTMLElement_Release(elem);
5193     }
5194
5195     elem = get_doc_elem_by_id(doc, "tbl");
5196     ok(elem != NULL, "elem == NULL\n");
5197     if(elem) {
5198         test_table_elem(elem);
5199         IHTMLElement_Release(elem);
5200     }
5201
5202     elem = get_doc_elem_by_id(doc, "row2");
5203     ok(elem != NULL, "elem == NULL\n");
5204     if(elem) {
5205         test_tr_elem(elem);
5206         IHTMLElement_Release(elem);
5207     }
5208
5209     elem = get_doc_elem_by_id(doc, "ifr");
5210     ok(elem != NULL, "elem == NULL\n");
5211     if(elem) {
5212         test_iframe_elem(elem);
5213         IHTMLElement_Release(elem);
5214     }
5215
5216     elem = get_doc_elem_by_id(doc, "objid");
5217     ok(elem != NULL, "elem == NULL\n");
5218     if(elem) {
5219         test_object_vspace((IUnknown*)elem, 100);
5220         IHTMLElement_Release(elem);
5221     }
5222
5223     elem = get_elem_by_id(doc, "a", TRUE);
5224     if(elem) {
5225         test_anchor_href((IUnknown*)elem, "http://test/");
5226
5227         /* Change the href */
5228         test_anchor_put_href((IUnknown*)elem, "http://test1/");
5229         test_anchor_href((IUnknown*)elem, "http://test1/");
5230
5231         /* Restore the href */
5232         test_anchor_put_href((IUnknown*)elem, "http://test/");
5233         test_anchor_href((IUnknown*)elem, "http://test/");
5234
5235         /* target */
5236         test_anchor_get_target((IUnknown*)elem, NULL);
5237
5238         /* Change the target */
5239         test_anchor_put_target((IUnknown*)elem, "wine");
5240         test_anchor_get_target((IUnknown*)elem, "wine");
5241
5242         /* Restore the target */
5243         test_anchor_put_target((IUnknown*)elem, NULL);
5244         test_anchor_get_target((IUnknown*)elem, NULL);
5245
5246         IHTMLElement_Release(elem);
5247     }
5248
5249     elem = doc_get_body(doc);
5250
5251     node = get_first_child((IUnknown*)elem);
5252     ok(node != NULL, "node == NULL\n");
5253     if(node) {
5254         test_ifaces((IUnknown*)node, text_iids);
5255         test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5256
5257         node2 = get_first_child((IUnknown*)node);
5258         ok(!node2, "node2 != NULL\n");
5259
5260         type = get_node_type((IUnknown*)node);
5261         ok(type == 3, "type=%d\n", type);
5262
5263         test_node_get_value_str((IUnknown*)node, "text test");
5264         test_node_put_value_str((IUnknown*)elem, "test text");
5265         test_node_get_value_str((IUnknown*)node, "text test");
5266
5267         hres = IHTMLDOMNode_get_attributes(node, &disp);
5268         ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
5269         ok(!disp, "disp != NULL\n");
5270
5271         IHTMLDOMNode_Release(node);
5272     }
5273
5274     child_col = get_child_nodes((IUnknown*)elem);
5275     ok(child_col != NULL, "child_coll == NULL\n");
5276     if(child_col) {
5277         LONG length = 0;
5278
5279         test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
5280
5281         hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
5282         ok(hres == S_OK, "get_length failed: %08x\n", hres);
5283         ok(length, "length=0\n");
5284
5285         node2 = NULL;
5286         node = get_child_item(child_col, 0);
5287         ok(node != NULL, "node == NULL\n");
5288         if(node) {
5289             IHTMLDOMNode *prev;
5290
5291             type = get_node_type((IUnknown*)node);
5292             ok(type == 3, "type=%d\n", type);
5293             node2 = node_get_next((IUnknown*)node);
5294
5295             prev = node_get_prev((IUnknown*)node2);
5296             ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
5297             IHTMLDOMNode_Release(prev);
5298
5299             IHTMLDOMNode_Release(node);
5300         }
5301
5302         node = get_child_item(child_col, 1);
5303         ok(node != NULL, "node == NULL\n");
5304         if(node) {
5305             type = get_node_type((IUnknown*)node);
5306             ok(type == 8, "type=%d\n", type);
5307
5308             test_elem_id((IUnknown*)node, NULL);
5309             ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
5310             IHTMLDOMNode_Release(node2);
5311             IHTMLDOMNode_Release(node);
5312         }
5313
5314         hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
5315         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5316
5317         hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
5318         ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5319
5320         hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
5321         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5322
5323         hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
5324         ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5325
5326         test_child_col_disp(child_col);
5327
5328         IHTMLDOMChildrenCollection_Release(child_col);
5329     }
5330
5331     test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
5332     test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
5333     test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
5334
5335     IHTMLElement_Release(elem);
5336
5337     elem = get_doc_elem_by_id(doc, "frm");
5338     ok(elem != NULL, "elem == NULL\n");
5339     if(elem) {
5340         test_form_length((IUnknown*)elem, 0);
5341         test_form_elements((IUnknown*)elem);
5342         IHTMLElement_Release(elem);
5343     }
5344
5345     test_stylesheets(doc);
5346     test_create_option_elem(doc);
5347     test_create_img_elem(doc);
5348
5349     elem = get_doc_elem_by_id(doc, "tbl");
5350     ok(elem != NULL, "elem = NULL\n");
5351     test_elem_set_innertext(elem, "inner text");
5352     IHTMLElement_Release(elem);
5353
5354     test_doc_title(doc, "test");
5355     test_doc_set_title(doc, "test title");
5356     test_doc_title(doc, "test title");
5357
5358     disp = NULL;
5359     hres = IHTMLDocument2_get_Script(doc, &disp);
5360     ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5361     if(hres == S_OK)
5362     {
5363         IDispatchEx *dispex;
5364         hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
5365         ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
5366         if(hres == S_OK)
5367         {
5368             DISPID pid = -1;
5369             BSTR str = a2bstr("Testing");
5370             hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
5371             ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5372             ok(pid != -1, "pid == -1\n");
5373             SysFreeString(str);
5374             IDispatchEx_Release(dispex);
5375         }
5376     }
5377     IDispatch_Release(disp);
5378
5379     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5380     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5381
5382     str = a2bstr("img");
5383     hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
5384     ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
5385     SysFreeString(str);
5386     if(hres == S_OK)
5387     {
5388         static const elem_type_t img_types[] = { ET_IMG };
5389
5390         test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
5391         IHTMLElementCollection_Release(col);
5392     }
5393
5394     elem = get_doc_elem_by_id(doc, "y");
5395     test_elem_set_innerhtml((IUnknown*)elem, "inner html");
5396     test_elem_innerhtml((IUnknown*)elem, "inner html");
5397     test_elem_set_innerhtml((IUnknown*)elem, "");
5398     test_elem_innerhtml((IUnknown*)elem, NULL);
5399     node = node_get_next((IUnknown*)elem);
5400     ok(!node, "node = %p\n", node);
5401
5402     elem2 = get_doc_elem_by_id(doc, "x");
5403     test_elem_tag((IUnknown*)elem2, "A");
5404     node = node_get_next((IUnknown*)elem2);
5405     IHTMLDOMNode_Release(node);
5406     IHTMLElement_Release(elem2);
5407     IHTMLElement_Release(elem);
5408
5409     IHTMLDocument3_Release(doc3);
5410
5411     elem = get_elem_by_id(doc, "s", TRUE);
5412     if(elem) {
5413         static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
5414
5415         test_select_put_length((IUnknown*)elem, 3);
5416         test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
5417         test_select_put_length((IUnknown*)elem, 1);
5418         test_elem_all((IUnknown*)elem, select_types, 1);
5419         IHTMLElement_Release(elem);
5420     }
5421
5422     window = get_doc_window(doc);
5423     test_window_name(window, NULL);
5424     set_window_name(window, "test name");
5425     test_window_length(window, 1);
5426     IHTMLWindow2_Release(window);
5427 }
5428
5429 static void test_attr(IHTMLElement *elem)
5430 {
5431     IHTMLDOMAttribute *attr, *attr2;
5432     VARIANT v;
5433
5434     get_elem_attr_node((IUnknown*)elem, "noattr", FALSE);
5435
5436     attr = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5437
5438     test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
5439     test_ifaces((IUnknown*)attr, attr_iids);
5440     test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
5441
5442     attr2 = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5443     ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
5444     IHTMLDOMAttribute_Release(attr2);
5445
5446     get_attr_node_value(attr, &v, VT_BSTR);
5447     ok(!strcmp_wa(V_BSTR(&v), "divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5448     VariantClear(&v);
5449
5450     IHTMLDOMAttribute_Release(attr);
5451
5452     attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
5453     get_attr_node_value(attr, &v, VT_BSTR);
5454     ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5455     VariantClear(&v);
5456     IHTMLDOMAttribute_Release(attr);
5457
5458     V_VT(&v) = VT_I4;
5459     V_I4(&v) = 100;
5460     set_dispex_value((IUnknown*)elem, "dispprop", &v);
5461     attr = get_elem_attr_node((IUnknown*)elem, "dispprop", TRUE);
5462     get_attr_node_value(attr, &v, VT_I4);
5463     ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
5464     IHTMLDOMAttribute_Release(attr);
5465 }
5466
5467 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
5468 {
5469     IHTMLElement *elem;
5470
5471     test_elem_set_innerhtml((IUnknown*)outer_elem,
5472             "<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
5473     elem = get_elem_by_id(doc, "imgid", TRUE);
5474     if(elem) {
5475         test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5476         IHTMLElement_Release(elem);
5477     }
5478
5479     test_elem_set_innerhtml((IUnknown*)outer_elem,
5480             "<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
5481     elem = get_elem_by_id(doc, "imgid", TRUE);
5482     if(elem) {
5483         test_img_src((IUnknown*)elem, "blocke::http://www.winehq.org/img.png", NULL);
5484         test_img_set_src((IUnknown*)elem, "BLOCKED:http://www.winehq.org/img.png");
5485         test_img_src((IUnknown*)elem, "blocked:http://www.winehq.org/img.png", NULL);
5486         test_img_set_src((IUnknown*)elem, "blocked::http://www.winehq.org/img.png");
5487         test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5488         IHTMLElement_Release(elem);
5489     }
5490 }
5491
5492 static void test_elems2(IHTMLDocument2 *doc)
5493 {
5494     IHTMLElement *elem, *elem2, *div;
5495
5496     static const elem_type_t outer_types[] = {
5497         ET_BR,
5498         ET_A
5499     };
5500
5501     div = get_doc_elem_by_id(doc, "divid");
5502
5503     test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
5504     elem2 = get_doc_elem_by_id(doc, "innerid");
5505     ok(elem2 != NULL, "elem2 == NULL\n");
5506     test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
5507     test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
5508     IHTMLElement_Release(elem2);
5509
5510     elem2 = get_doc_elem_by_id(doc, "aid");
5511     ok(elem2 != NULL, "elem2 == NULL\n");
5512     test_elem_set_outerhtml((IUnknown*)elem2, "");
5513     test_elem_all((IUnknown*)div, outer_types, 1);
5514     IHTMLElement_Release(elem2);
5515
5516     test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
5517     elem = get_elem_by_id(doc, "ta", TRUE);
5518     if(elem) {
5519         test_textarea_value((IUnknown*)elem, NULL);
5520         test_textarea_put_value((IUnknown*)elem, "test");
5521         test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
5522         test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
5523         test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
5524         test_textarea_type((IUnknown*)elem);
5525         IHTMLElement_Release(elem);
5526     }
5527
5528     test_elem_set_innerhtml((IUnknown*)div,
5529             "<form id=\"form\"><input type=\"button\" /><div><input type=\"text\" /></div></textarea>");
5530     elem = get_elem_by_id(doc, "form", TRUE);
5531     if(elem) {
5532         test_form_length((IUnknown*)elem, 2);
5533         test_form_item(elem);
5534         test_form_action((IUnknown*)elem, NULL);
5535         test_form_put_action((IUnknown*)elem, "about:blank");
5536         test_form_method((IUnknown*)elem, "get");
5537         test_form_put_method((IUnknown*)elem, S_OK, "post");
5538         test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
5539         test_form_method((IUnknown*)elem, "post");
5540         test_form_name((IUnknown*)elem, NULL);
5541         test_form_put_name((IUnknown*)elem, "Name");
5542         test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
5543         test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
5544         test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
5545         test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
5546         test_form_encoding((IUnknown*)elem, "multipart/form-data");
5547         test_form_elements((IUnknown*)elem);
5548         IHTMLElement_Release(elem);
5549     }
5550
5551     test_attr(div);
5552     test_blocked(doc, div);
5553
5554     IHTMLElement_Release(div);
5555 }
5556
5557 static void test_create_elems(IHTMLDocument2 *doc)
5558 {
5559     IHTMLElement *elem, *body, *elem2;
5560     IHTMLDOMNode *node, *node2, *node3, *comment;
5561     IHTMLDocument5 *doc5;
5562     IDispatch *disp;
5563     VARIANT var;
5564     LONG type;
5565     HRESULT hres;
5566     BSTR str;
5567
5568     static const elem_type_t types1[] = { ET_TESTG };
5569
5570     elem = test_create_elem(doc, "TEST");
5571     test_elem_tag((IUnknown*)elem, "TEST");
5572     type = get_node_type((IUnknown*)elem);
5573     ok(type == 1, "type=%d\n", type);
5574     test_ifaces((IUnknown*)elem, elem_iids);
5575     test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
5576
5577     body = doc_get_body(doc);
5578     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5579
5580     node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
5581     test_node_has_child((IUnknown*)body, VARIANT_TRUE);
5582     elem2 = get_elem_iface((IUnknown*)node);
5583     IHTMLElement_Release(elem2);
5584
5585     hres = IHTMLElement_get_all(body, &disp);
5586     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5587     test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
5588     IDispatch_Release(disp);
5589
5590     test_node_remove_child((IUnknown*)body, node);
5591
5592     hres = IHTMLElement_get_all(body, &disp);
5593     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5594     test_elem_collection((IUnknown*)disp, NULL, 0);
5595     IDispatch_Release(disp);
5596     test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5597
5598     IHTMLElement_Release(elem);
5599     IHTMLDOMNode_Release(node);
5600
5601     node = test_create_text(doc, "test");
5602     test_ifaces((IUnknown*)node, text_iids);
5603     test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5604     test_text_length((IUnknown*)node, 4);
5605
5606     V_VT(&var) = VT_NULL;
5607     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5608     IHTMLDOMNode_Release(node);
5609
5610     node = test_create_text(doc, "insert ");
5611
5612     V_VT(&var) = VT_DISPATCH;
5613     V_DISPATCH(&var) = (IDispatch*)node2;
5614     node3 = test_node_insertbefore((IUnknown*)body, node, &var);
5615     IHTMLDOMNode_Release(node);
5616     IHTMLDOMNode_Release(node2);
5617     IHTMLDOMNode_Release(node3);
5618
5619     test_elem_innertext(body, "insert test");
5620     test_elem_innerhtml((IUnknown*)body, "insert test");
5621
5622     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
5623     if(hres == S_OK)
5624     {
5625         str = a2bstr("testing");
5626         hres = IHTMLDocument5_createComment(doc5, str, &comment);
5627         SysFreeString(str);
5628         ok(hres == S_OK, "createComment failed: %08x\n", hres);
5629         if(hres == S_OK)
5630         {
5631             type = get_node_type((IUnknown*)comment);
5632             ok(type == 8, "type=%d, expected 8\n", type);
5633
5634             test_node_get_value_str((IUnknown*)comment, "testing");
5635             test_elem_title((IUnknown*)comment, NULL);
5636             test_elem_set_title((IUnknown*)comment, "comment title");
5637             test_elem_title((IUnknown*)comment, "comment title");
5638             test_comment_text((IUnknown*)comment, "<!--testing-->");
5639             test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
5640             test_comment_attrs((IUnknown*)comment);
5641
5642             IHTMLDOMNode_Release(comment);
5643         }
5644
5645         IHTMLDocument5_Release(doc5);
5646     }
5647
5648     IHTMLElement_Release(body);
5649 }
5650
5651 static void test_replacechild_elems(IHTMLDocument2 *doc)
5652 {
5653     IHTMLElement *body;
5654     IHTMLDOMNode *node, *node2, *node3;
5655     IHTMLDOMNode *nodeBody, *nodeNew;
5656     HRESULT hres;
5657     VARIANT var;
5658
5659     body = doc_get_body(doc);
5660
5661     node = test_create_text(doc, "insert");
5662
5663     V_VT(&var) = VT_NULL;
5664     V_DISPATCH(&var) = NULL;
5665     node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5666     IHTMLDOMNode_Release(node);
5667
5668     test_elem_innertext(body, "insert");
5669
5670     node3 = test_create_text(doc, "replaced");
5671
5672     nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
5673
5674     hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
5675     ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
5676
5677     test_elem_innertext(body, "replaced");
5678
5679     IHTMLDOMNode_Release(node2);
5680     IHTMLDOMNode_Release(node3);
5681     IHTMLDOMNode_Release(nodeBody);
5682
5683     IHTMLElement_Release(body);
5684 }
5685
5686 static void test_null_write(IHTMLDocument2 *doc)
5687 {
5688     HRESULT hres;
5689
5690     doc_write(doc, FALSE, NULL);
5691     doc_write(doc, TRUE, NULL);
5692
5693     hres = IHTMLDocument2_write(doc, NULL);
5694     ok(hres == S_OK,
5695        "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
5696
5697     hres = IHTMLDocument2_writeln(doc, NULL);
5698     ok(hres == S_OK,
5699        "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
5700 }
5701
5702 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
5703 {
5704     IOleCommandTarget *cmdtrg;
5705     HRESULT hres;
5706
5707     hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
5708     ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
5709
5710     hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
5711     ok(hres == S_OK, "Exec failed: %08x\n", hres);
5712
5713     IOleCommandTarget_Release(cmdtrg);
5714 }
5715
5716 static void test_indent(IHTMLDocument2 *doc)
5717 {
5718     IHTMLElementCollection *col;
5719     IHTMLTxtRange *range;
5720     HRESULT hres;
5721
5722     static const elem_type_t all_types[] = {
5723         ET_HTML,
5724         ET_HEAD,
5725         ET_TITLE,
5726         ET_BODY,
5727         ET_BR,
5728         ET_A,
5729     };
5730
5731     static const elem_type_t indent_types[] = {
5732         ET_HTML,
5733         ET_HEAD,
5734         ET_TITLE,
5735         ET_BODY,
5736         ET_BLOCKQUOTE,
5737         ET_P,
5738         ET_BR,
5739         ET_A,
5740     };
5741
5742     hres = IHTMLDocument2_get_all(doc, &col);
5743     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5744     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5745     IHTMLElementCollection_Release(col);
5746
5747     range = test_create_body_range(doc);
5748     test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
5749     IHTMLTxtRange_Release(range);
5750
5751     hres = IHTMLDocument2_get_all(doc, &col);
5752     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5753     test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
5754     IHTMLElementCollection_Release(col);
5755 }
5756
5757 static void test_cond_comment(IHTMLDocument2 *doc)
5758 {
5759     IHTMLElementCollection *col;
5760     HRESULT hres;
5761
5762     static const elem_type_t all_types[] = {
5763         ET_HTML,
5764         ET_HEAD,
5765         ET_TITLE,
5766         ET_BODY,
5767         ET_BR
5768     };
5769
5770     hres = IHTMLDocument2_get_all(doc, &col);
5771     ok(hres == S_OK, "get_all failed: %08x\n", hres);
5772     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5773     IHTMLElementCollection_Release(col);
5774 }
5775
5776 static void test_frame(IDispatch *disp, const char *exp_id)
5777 {
5778     IHTMLWindow2 *frame2, *parent, *top;
5779     IHTMLDocument2 *parent_doc, *top_doc;
5780     IHTMLWindow4 *frame;
5781     IHTMLFrameBase *frame_elem;
5782     HRESULT hres;
5783
5784     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
5785     ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
5786     if(FAILED(hres))
5787         return;
5788
5789     hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
5790     ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
5791     IHTMLWindow4_Release(frame);
5792     if(FAILED(hres))
5793         return;
5794
5795     test_elem_type((IUnknown*)frame_elem, ET_FRAME);
5796     test_frame_doc((IUnknown*)frame_elem, FALSE);
5797     test_elem_id((IUnknown*)frame_elem, exp_id);
5798     IHTMLElement_Release(frame_elem);
5799
5800     hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
5801     ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
5802     if(FAILED(hres))
5803         return;
5804
5805     hres = IHTMLWindow2_get_parent(frame2, &parent);
5806     ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
5807     if(FAILED(hres)){
5808         IHTMLWindow2_Release(frame2);
5809         return;
5810     }
5811
5812     hres = IHTMLWindow2_get_document(parent, &parent_doc);
5813     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
5814     IHTMLWindow2_Release(parent);
5815     if(FAILED(hres)){
5816         IHTMLWindow2_Release(frame2);
5817         return;
5818     }
5819
5820     test_doc_title(parent_doc, "frameset test");
5821     IHTMLDocument2_Release(parent_doc);
5822
5823     /* test get_top */
5824     hres = IHTMLWindow2_get_top(frame2, &top);
5825     ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
5826     IHTMLWindow2_Release(frame2);
5827     if(FAILED(hres))
5828         return;
5829
5830     hres = IHTMLWindow2_get_document(top, &top_doc);
5831     ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
5832     IHTMLWindow2_Release(top);
5833     if(FAILED(hres))
5834         return;
5835
5836     test_doc_title(top_doc, "frameset test");
5837     IHTMLDocument2_Release(top_doc);
5838 }
5839
5840 static void test_frames_collection(IHTMLFramesCollection2 *frames, const char *frid)
5841 {
5842     VARIANT index_var, result_var;
5843     LONG length;
5844     HRESULT hres;
5845
5846     /* test result length */
5847     hres = IHTMLFramesCollection2_get_length(frames, &length);
5848     ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
5849     ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
5850
5851     /* test first frame */
5852     V_VT(&index_var) = VT_I4;
5853     V_I4(&index_var) = 0;
5854     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5855     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5856     if(SUCCEEDED(hres)) {
5857         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5858         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
5859     }
5860     VariantClear(&result_var);
5861
5862     /* test second frame */
5863     V_I4(&index_var) = 1;
5864     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5865     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5866     if(SUCCEEDED(hres)) {
5867         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5868         test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
5869     }
5870     VariantClear(&result_var);
5871
5872     /* fail on next frame */
5873     V_I4(&index_var) = 3;
5874     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5875     ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
5876            "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
5877     VariantClear(&result_var);
5878
5879     /* string argument (element id lookup) */
5880     V_VT(&index_var) = VT_BSTR;
5881     V_BSTR(&index_var) = a2bstr(frid);
5882     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5883     ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5884     if(SUCCEEDED(hres)) {
5885         ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5886         test_frame(V_DISPATCH(&result_var), frid);
5887     }
5888     VariantClear(&result_var);
5889     VariantClear(&index_var);
5890
5891     /* invalid argument */
5892     V_VT(&index_var) = VT_BOOL;
5893     V_BOOL(&index_var) = VARIANT_TRUE;
5894     hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5895     ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
5896            "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
5897     VariantClear(&result_var);
5898 }
5899
5900 static void test_frameset(IHTMLDocument2 *doc)
5901 {
5902     IHTMLWindow2 *window;
5903     IHTMLFramesCollection2 *frames;
5904     IHTMLElement *elem;
5905     IHTMLFrameBase *fbase;
5906     BSTR str;
5907     HRESULT hres;
5908
5909     window = get_doc_window(doc);
5910
5911     /* test using IHTMLFramesCollection object */
5912
5913     hres = IHTMLWindow2_get_frames(window, &frames);
5914     ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
5915     if(FAILED(hres))
5916         return;
5917
5918     test_frames_collection(frames, "fr1");
5919     IHTMLFramesCollection2_Release(frames);
5920
5921     hres = IHTMLDocument2_get_frames(doc, &frames);
5922     ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
5923     if(FAILED(hres))
5924         return;
5925
5926     test_frames_collection(frames, "fr1");
5927     IHTMLFramesCollection2_Release(frames);
5928
5929     /* test using IHTMLWindow2 inheritance */
5930     test_frames_collection((IHTMLFramesCollection2*)window, "fr2");
5931
5932     /* getElementById with node name attributes */
5933     elem = get_doc_elem_by_id(doc, "nm1");
5934     test_elem_id((IUnknown*)elem, "fr1");
5935
5936     /* get/put scrolling */
5937     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5938     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5939
5940     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5941     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5942     ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
5943     SysFreeString(str);
5944
5945     str = a2bstr("no");
5946     hres = IHTMLFrameBase_put_scrolling(fbase, str);
5947     ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
5948     SysFreeString(str);
5949
5950     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5951     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5952     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5953     SysFreeString(str);
5954
5955     str = a2bstr("junk");
5956     hres = IHTMLFrameBase_put_scrolling(fbase, str);
5957     ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
5958             "with E_INVALIDARG, instead: 0x%08x\n", hres);
5959     SysFreeString(str);
5960
5961     hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5962     ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5963     ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5964     SysFreeString(str);
5965
5966     /* get_name */
5967     hres = IHTMLFrameBase_get_name(fbase, &str);
5968     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
5969     ok(!strcmp_wa(str, "nm1"), "get_name should have given 'nm1', gave: %s\n", wine_dbgstr_w(str));
5970     SysFreeString(str);
5971
5972     IHTMLFrameBase_Release(fbase);
5973     IHTMLElement_Release(elem);
5974
5975     /* get_name with no name attr */
5976     elem = get_doc_elem_by_id(doc, "fr3");
5977     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5978     ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5979
5980     hres = IHTMLFrameBase_get_name(fbase, &str);
5981     ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
5982     ok(str == NULL, "get_name should have given 'null', gave: %s\n", wine_dbgstr_w(str));
5983     SysFreeString(str);
5984
5985     IHTMLFrameBase_Release(fbase);
5986     IHTMLElement_Release(elem);
5987     IHTMLWindow2_Release(window);
5988 }
5989
5990 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
5991 {
5992     IHTMLDocument2 *frag;
5993     IHTMLDocument3 *doc3;
5994     HRESULT hres;
5995
5996     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5997     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5998
5999     hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
6000     IHTMLDocument3_Release(doc3);
6001     ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
6002     ok(frag != NULL, "frag == NULL\n");
6003
6004     return frag;
6005 }
6006
6007 static void test_docfrag(IHTMLDocument2 *doc)
6008 {
6009     IHTMLElement *div, *body, *br;
6010     IHTMLElementCollection *col;
6011     IHTMLLocation *location;
6012     IHTMLDocument2 *frag;
6013     HRESULT hres;
6014
6015     static const elem_type_t all_types[] = {
6016         ET_HTML,
6017         ET_HEAD,
6018         ET_TITLE,
6019         ET_BODY,
6020         ET_DIV,
6021         ET_BR
6022     };
6023
6024     frag = create_docfrag(doc);
6025
6026     test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
6027
6028     body = (void*)0xdeadbeef;
6029     hres = IHTMLDocument2_get_body(frag, &body);
6030     ok(hres == S_OK, "get_body failed: %08x\n", hres);
6031     ok(!body, "body != NULL\n");
6032
6033     location = (void*)0xdeadbeef;
6034     hres = IHTMLDocument2_get_location(frag, &location);
6035     ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
6036     ok(location == (void*)0xdeadbeef, "location changed\n");
6037
6038     br = test_create_elem(doc, "BR");
6039     test_node_append_child((IUnknown*)frag, (IUnknown*)br);
6040     IHTMLElement_Release(br);
6041
6042     div = get_elem_by_id(doc, "divid", TRUE);
6043     test_node_append_child((IUnknown*)div, (IUnknown*)frag);
6044     IHTMLElement_Release(div);
6045
6046     hres = IHTMLDocument2_get_all(doc, &col);
6047     ok(hres == S_OK, "get_all failed: %08x\n", hres);
6048     test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6049     IHTMLElementCollection_Release(col);
6050
6051     IHTMLDocument2_Release(frag);
6052 }
6053
6054 static IHTMLDocument2 *notif_doc;
6055 static BOOL doc_complete;
6056
6057 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
6058         REFIID riid, void**ppv)
6059 {
6060     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
6061         *ppv = iface;
6062         return S_OK;
6063     }
6064
6065     ok(0, "unexpected call\n");
6066     return E_NOINTERFACE;
6067 }
6068
6069 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
6070 {
6071     return 2;
6072 }
6073
6074 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
6075 {
6076     return 1;
6077 }
6078
6079 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
6080 {
6081     if(dispID == DISPID_READYSTATE){
6082         BSTR state;
6083         HRESULT hres;
6084
6085         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
6086         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
6087
6088         if(!strcmp_wa(state, "complete"))
6089             doc_complete = TRUE;
6090
6091         SysFreeString(state);
6092     }
6093
6094     return S_OK;
6095 }
6096
6097 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
6098 {
6099     ok(0, "unexpected call\n");
6100     return E_NOTIMPL;
6101 }
6102
6103 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
6104     PropertyNotifySink_QueryInterface,
6105     PropertyNotifySink_AddRef,
6106     PropertyNotifySink_Release,
6107     PropertyNotifySink_OnChanged,
6108     PropertyNotifySink_OnRequestEdit
6109 };
6110
6111 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
6112
6113 static IHTMLDocument2 *create_doc_with_string(const char *str)
6114 {
6115     IPersistStreamInit *init;
6116     IStream *stream;
6117     IHTMLDocument2 *doc;
6118     HGLOBAL mem;
6119     SIZE_T len;
6120
6121     notif_doc = doc = create_document();
6122     if(!doc)
6123         return NULL;
6124
6125     doc_complete = FALSE;
6126     len = strlen(str);
6127     mem = GlobalAlloc(0, len);
6128     memcpy(mem, str, len);
6129     CreateStreamOnHGlobal(mem, TRUE, &stream);
6130
6131     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
6132
6133     IPersistStreamInit_Load(init, stream);
6134     IPersistStreamInit_Release(init);
6135     IStream_Release(stream);
6136
6137     return doc;
6138 }
6139
6140 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
6141 {
6142     IConnectionPointContainer *container;
6143     IConnectionPoint *cp;
6144     DWORD cookie;
6145     HRESULT hres;
6146
6147     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
6148     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
6149
6150     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
6151     IConnectionPointContainer_Release(container);
6152     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
6153
6154     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
6155     IConnectionPoint_Release(cp);
6156     ok(hres == S_OK, "Advise failed: %08x\n", hres);
6157 }
6158
6159 typedef void (*domtest_t)(IHTMLDocument2*);
6160
6161 static void run_domtest(const char *str, domtest_t test)
6162 {
6163     IHTMLDocument2 *doc;
6164     ULONG ref;
6165     MSG msg;
6166
6167     doc = create_doc_with_string(str);
6168     if(!doc)
6169         return;
6170
6171     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
6172
6173     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
6174         TranslateMessage(&msg);
6175         DispatchMessage(&msg);
6176     }
6177
6178     test(doc);
6179
6180     ref = IHTMLDocument2_Release(doc);
6181     ok(!ref || broken(ref == 1), /* Vista */
6182        "ref = %d\n", ref);
6183 }
6184
6185 START_TEST(dom)
6186 {
6187     HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
6188     pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
6189     pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
6190
6191     CoInitialize(NULL);
6192
6193     run_domtest(doc_str1, test_doc_elem);
6194     run_domtest(doc_str1, test_get_set_attr);
6195     run_domtest(range_test_str, test_txtrange);
6196     run_domtest(range_test2_str, test_txtrange2);
6197     if (winetest_interactive || ! is_ie_hardened()) {
6198         run_domtest(elem_test_str, test_elems);
6199         run_domtest(elem_test2_str, test_elems2);
6200     }else {
6201         skip("IE running in Enhanced Security Configuration\n");
6202     }
6203     run_domtest(doc_blank, test_create_elems);
6204     run_domtest(doc_blank, test_defaults);
6205     run_domtest(doc_blank, test_null_write);
6206     run_domtest(indent_test_str, test_indent);
6207     run_domtest(cond_comment_str, test_cond_comment);
6208     run_domtest(frameset_str, test_frameset);
6209     run_domtest(emptydiv_str, test_docfrag);
6210     run_domtest(doc_blank, test_replacechild_elems);
6211
6212     CoUninitialize();
6213 }