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