mshtml: Added IHTMLFrameBase::frameBorder implementation.
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob8907a98859971e7c6df2f8f377fb0a3c56fe563d
1 /*
2 * Copyright 2007-2011 Jacek Caban for CodeWeavers
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.
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.
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmcid.h"
31 #include "mshtmhst.h"
32 #include "docobj.h"
33 #include "dispex.h"
34 #include "mshtml_test.h"
35 #include "objsafe.h"
36 #include "htiface.h"
37 #include "tlogstg.h"
39 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
40 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
42 static const char doc_blank[] = "<html></html>";
43 static const char doc_str1[] = "<html><body>test</body></html>";
44 static const char range_test_str[] =
45 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
46 static const char range_test2_str[] =
47 "<html><body>abc<hr />123<br /><hr />def</body></html>";
48 static const char elem_test_str[] =
49 "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
50 "<meta id=\"metaid\" name=\"meta name\" http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
51 "<body onload=\"Testing()\">text test<!-- a comment -->"
52 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
53 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
54 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
55 "<textarea id=\"X\">text text</textarea>"
56 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
57 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
58 "<test /><object id=\"objid\" vspace=100></object><embed />"
59 "<img id=\"imgid\" name=\"WineImg\"/>"
60 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
61 "<form id=\"frm\"></form>"
62 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
63 "</body></html>";
64 static const char elem_test2_str[] =
65 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
66 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
67 "</html>";
69 static const char indent_test_str[] =
70 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
71 static const char cond_comment_str[] =
72 "<html><head><title>test</title></head><body>"
73 "<!--[if gte IE 4]> <br> <![endif]-->"
74 "</body></html>";
75 static const char frameset_str[] =
76 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
77 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
78 "<frame src=\"about:blank\" id=\"fr3\">"
79 "</frameset></html>";
80 static const char emptydiv_str[] =
81 "<html><head><title>emptydiv test</title></head>"
82 "<body><div id=\"divid\"></div></body></html>";
84 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
85 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
86 static WCHAR wordW[] = {'w','o','r','d',0};
88 typedef enum {
89 ET_NONE,
90 ET_HTML,
91 ET_HEAD,
92 ET_TITLE,
93 ET_BODY,
94 ET_A,
95 ET_INPUT,
96 ET_SELECT,
97 ET_TEXTAREA,
98 ET_OPTION,
99 ET_STYLE,
100 ET_BLOCKQUOTE,
101 ET_P,
102 ET_BR,
103 ET_TABLE,
104 ET_TBODY,
105 ET_SCRIPT,
106 ET_TEST,
107 ET_TESTG,
108 ET_COMMENT,
109 ET_IMG,
110 ET_TR,
111 ET_TD,
112 ET_IFRAME,
113 ET_FORM,
114 ET_FRAME,
115 ET_OBJECT,
116 ET_EMBED,
117 ET_DIV,
118 ET_META
119 } elem_type_t;
121 static const IID * const none_iids[] = {
122 &IID_IUnknown,
123 NULL
126 static const IID * const doc_node_iids[] = {
127 &IID_IHTMLDOMNode,
128 &IID_IHTMLDOMNode2,
129 &IID_IHTMLDocument,
130 &IID_IHTMLDocument2,
131 &IID_IHTMLDocument3,
132 &IID_IHTMLDocument4,
133 &IID_IHTMLDocument5,
134 &IID_IDispatchEx,
135 &IID_IConnectionPointContainer,
136 &IID_IInternetHostSecurityManager,
137 &IID_IOleContainer,
138 &IID_IObjectSafety,
139 &IID_IProvideClassInfo,
140 NULL
143 static const IID * const doc_obj_iids[] = {
144 &IID_IHTMLDocument,
145 &IID_IHTMLDocument2,
146 &IID_IHTMLDocument3,
147 &IID_IHTMLDocument4,
148 &IID_IHTMLDocument5,
149 &IID_IDispatchEx,
150 &IID_IConnectionPointContainer,
151 &IID_ICustomDoc,
152 &IID_IOleContainer,
153 &IID_IObjectSafety,
154 &IID_IProvideClassInfo,
155 &IID_ITargetContainer,
156 NULL
159 #define ELEM_IFACES \
160 &IID_IHTMLDOMNode, \
161 &IID_IHTMLDOMNode2, \
162 &IID_IHTMLElement, \
163 &IID_IHTMLElement2, \
164 &IID_IHTMLElement3, \
165 &IID_IHTMLElement4, \
166 &IID_IDispatchEx
168 static const IID * const elem_iids[] = {
169 ELEM_IFACES,
170 &IID_IConnectionPointContainer,
171 NULL
174 static const IID * const body_iids[] = {
175 ELEM_IFACES,
176 &IID_IHTMLTextContainer,
177 &IID_IHTMLBodyElement,
178 &IID_IConnectionPointContainer,
179 NULL
182 static const IID * const anchor_iids[] = {
183 ELEM_IFACES,
184 &IID_IHTMLAnchorElement,
185 &IID_IConnectionPointContainer,
186 NULL
189 static const IID * const input_iids[] = {
190 ELEM_IFACES,
191 &IID_IHTMLInputElement,
192 &IID_IHTMLInputTextElement,
193 &IID_IConnectionPointContainer,
194 NULL
197 static const IID * const select_iids[] = {
198 ELEM_IFACES,
199 &IID_IHTMLSelectElement,
200 &IID_IConnectionPointContainer,
201 NULL
204 static const IID * const textarea_iids[] = {
205 ELEM_IFACES,
206 &IID_IHTMLTextAreaElement,
207 &IID_IConnectionPointContainer,
208 NULL
211 static const IID * const option_iids[] = {
212 ELEM_IFACES,
213 &IID_IHTMLOptionElement,
214 &IID_IConnectionPointContainer,
215 NULL
218 static const IID * const table_iids[] = {
219 ELEM_IFACES,
220 &IID_IHTMLTable,
221 &IID_IHTMLTable2,
222 &IID_IHTMLTable3,
223 &IID_IConnectionPointContainer,
224 NULL
227 static const IID * const script_iids[] = {
228 ELEM_IFACES,
229 &IID_IHTMLScriptElement,
230 &IID_IConnectionPointContainer,
231 NULL
234 static const IID * const text_iids[] = {
235 &IID_IHTMLDOMNode,
236 &IID_IHTMLDOMNode2,
237 &IID_IHTMLDOMTextNode,
238 NULL
241 static const IID * const attr_iids[] = {
242 &IID_IHTMLDOMAttribute,
243 &IID_IDispatchEx,
244 NULL
247 static const IID * const location_iids[] = {
248 &IID_IDispatch,
249 &IID_IHTMLLocation,
250 NULL
253 static const IID * const window_iids[] = {
254 &IID_IDispatch,
255 &IID_IHTMLWindow2,
256 &IID_IHTMLWindow3,
257 &IID_IDispatchEx,
258 &IID_IServiceProvider,
259 NULL
262 static const IID * const comment_iids[] = {
263 ELEM_IFACES,
264 &IID_IHTMLCommentElement,
265 &IID_IConnectionPointContainer,
266 NULL
269 static const IID * const img_iids[] = {
270 ELEM_IFACES,
271 &IID_IHTMLImgElement,
272 &IID_IConnectionPointContainer,
273 NULL
276 static const IID * const tr_iids[] = {
277 ELEM_IFACES,
278 &IID_IHTMLTableRow,
279 &IID_IConnectionPointContainer,
280 NULL
283 static const IID * const td_iids[] = {
284 ELEM_IFACES,
285 &IID_IHTMLTableCell,
286 &IID_IConnectionPointContainer,
287 NULL
290 static const IID * const frame_iids[] = {
291 ELEM_IFACES,
292 &IID_IHTMLFrameBase,
293 &IID_IHTMLFrameBase2,
294 &IID_IConnectionPointContainer,
295 NULL
298 static const IID * const head_iids[] = {
299 ELEM_IFACES,
300 &IID_IHTMLHeadElement,
301 &IID_IConnectionPointContainer,
302 NULL
305 static const IID * const title_iids[] = {
306 ELEM_IFACES,
307 &IID_IHTMLTitleElement,
308 &IID_IConnectionPointContainer,
309 NULL
312 static const IID * const meta_iids[] = {
313 ELEM_IFACES,
314 &IID_IHTMLMetaElement,
315 &IID_IConnectionPointContainer,
316 NULL
319 static const IID * const object_iids[] = {
320 ELEM_IFACES,
321 &IID_IHTMLObjectElement,
322 &IID_IHTMLObjectElement2,
323 /* FIXME: No IConnectionPointContainer */
324 NULL
327 static const IID * const embed_iids[] = {
328 ELEM_IFACES,
329 &IID_IHTMLEmbedElement,
330 /* FIXME: No IConnectionPointContainer */
331 NULL
334 static const IID * const iframe_iids[] = {
335 ELEM_IFACES,
336 &IID_IHTMLFrameBase,
337 &IID_IHTMLFrameBase2,
338 &IID_IHTMLIFrameElement,
339 &IID_IConnectionPointContainer,
340 NULL
343 static const IID * const form_iids[] = {
344 ELEM_IFACES,
345 &IID_IHTMLFormElement,
346 &IID_IConnectionPointContainer,
347 NULL
350 static const IID * const styleelem_iids[] = {
351 ELEM_IFACES,
352 &IID_IHTMLStyleElement,
353 &IID_IConnectionPointContainer,
354 NULL
357 static const IID * const generic_iids[] = {
358 ELEM_IFACES,
359 &IID_IHTMLGenericElement,
360 &IID_IConnectionPointContainer,
361 NULL
364 static const IID * const style_iids[] = {
365 &IID_IUnknown,
366 &IID_IDispatch,
367 &IID_IDispatchEx,
368 &IID_IHTMLStyle,
369 &IID_IHTMLStyle2,
370 &IID_IHTMLStyle3,
371 &IID_IHTMLStyle4,
372 NULL
375 static const IID * const cstyle_iids[] = {
376 &IID_IUnknown,
377 &IID_IDispatch,
378 &IID_IDispatchEx,
379 &IID_IHTMLCurrentStyle,
380 &IID_IHTMLCurrentStyle2,
381 &IID_IHTMLCurrentStyle3,
382 NULL
385 static const IID * const img_factory_iids[] = {
386 &IID_IUnknown,
387 &IID_IDispatch,
388 &IID_IDispatchEx,
389 &IID_IHTMLImageElementFactory,
390 NULL
393 typedef struct {
394 const char *tag;
395 REFIID *iids;
396 const IID *dispiid;
397 } elem_type_info_t;
399 static const elem_type_info_t elem_type_infos[] = {
400 {"", none_iids, NULL},
401 {"HTML", elem_iids, NULL},
402 {"HEAD", head_iids, &DIID_DispHTMLHeadElement},
403 {"TITLE", title_iids, &DIID_DispHTMLTitleElement},
404 {"BODY", body_iids, &DIID_DispHTMLBody},
405 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
406 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
407 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
408 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
409 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
410 {"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement},
411 {"BLOCKQUOTE",elem_iids, NULL},
412 {"P", elem_iids, NULL},
413 {"BR", elem_iids, NULL},
414 {"TABLE", table_iids, &DIID_DispHTMLTable},
415 {"TBODY", elem_iids, NULL},
416 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
417 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
418 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
419 {"!", comment_iids, &DIID_DispHTMLCommentElement},
420 {"IMG", img_iids, &DIID_DispHTMLImg},
421 {"TR", tr_iids, &DIID_DispHTMLTableRow},
422 {"TD", td_iids, &DIID_DispHTMLTableCell},
423 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
424 {"FORM", form_iids, &DIID_DispHTMLFormElement},
425 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement},
426 {"OBJECT", object_iids, &DIID_DispHTMLObjectElement},
427 {"EMBED", embed_iids, &DIID_DispHTMLEmbed},
428 {"DIV", elem_iids, NULL},
429 {"META", meta_iids, &DIID_DispHTMLMetaElement}
432 static const char *dbgstr_guid(REFIID riid)
434 static char buf[50];
436 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
437 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
438 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
439 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
441 return buf;
444 static int strcmp_wa(LPCWSTR strw, const char *stra)
446 CHAR buf[512];
447 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
448 return lstrcmpA(stra, buf);
451 static BSTR a2bstr(const char *str)
453 BSTR ret;
454 int len;
456 if(!str)
457 return NULL;
459 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
460 ret = SysAllocStringLen(NULL, len);
461 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
463 return ret;
466 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
468 IUnknown *unk1, *unk2;
470 if(iface1 == iface2)
471 return TRUE;
473 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
474 IUnknown_Release(unk1);
475 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
476 IUnknown_Release(unk2);
478 return unk1 == unk2;
481 static IHTMLDocument2 *create_document(void)
483 IHTMLDocument2 *doc;
484 IHTMLDocument5 *doc5;
485 HRESULT hres;
487 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
488 &IID_IHTMLDocument2, (void**)&doc);
489 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
490 if(FAILED(hres))
491 return NULL;
493 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
494 if(FAILED(hres)) {
495 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
496 IHTMLDocument2_Release(doc);
497 return NULL;
500 IHTMLDocument5_Release(doc5);
501 return doc;
504 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
505 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
507 IDispatchEx *dispex;
508 HRESULT hres;
510 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
511 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
512 return dispex;
515 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
516 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
518 const IID * const *piid;
519 IUnknown *unk;
520 HRESULT hres;
522 for(piid = iids; *piid; piid++) {
523 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
524 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
525 if(SUCCEEDED(hres))
526 IUnknown_Release(unk);
530 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
531 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
533 IUnknown *unk;
534 HRESULT hres;
536 unk = (void*)0xdeadbeef;
537 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
538 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
539 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
542 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
543 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
545 IDispatchEx *dispex = _get_dispex_iface(line, unk);
546 ITypeInfo *typeinfo;
547 BOOL ret = FALSE;
548 UINT ticnt;
549 HRESULT hres;
551 ticnt = 0xdeadbeef;
552 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
553 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
554 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
556 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
557 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
559 if(SUCCEEDED(hres)) {
560 TYPEATTR *type_attr;
562 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
563 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
564 if(hres == S_OK) {
565 *iid = type_attr->guid;
566 ret = TRUE;
569 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
570 ITypeInfo_Release(typeinfo);
573 IDispatchEx_Release(dispex);
574 return ret;
577 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
578 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
580 IDispatchEx *dispex = _get_dispex_iface(line, unk);
581 DISPPARAMS dp = {NULL,NULL,0,0};
582 EXCEPINFO ei;
583 VARIANT var;
584 HRESULT hres;
586 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
587 IDispatchEx_Release(dispex);
588 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
590 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
591 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
592 VariantClear(&var);
595 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
596 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
598 IID iid;
600 if(_test_get_dispid(line, unk, &iid))
601 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
603 if(val)
604 _test_disp_value(line, unk, val);
607 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
608 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
610 IID iid;
612 if(_test_get_dispid(line, unk, &iid))
613 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
614 "unexpected guid %s\n", dbgstr_guid(&iid));
616 if(val)
617 _test_disp_value(line, unk, val);
620 #define test_class_info(u) _test_class_info(__LINE__,u)
621 static void _test_class_info(unsigned line, IUnknown *unk)
623 IProvideClassInfo *classinfo;
624 ITypeInfo *typeinfo;
625 TYPEATTR *type_attr;
626 HRESULT hres;
628 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
629 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
630 if(FAILED(hres))
631 return;
633 hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
634 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
635 if(FAILED(hres))
637 IProvideClassInfo_Release(classinfo);
638 return;
641 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
642 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
643 if(SUCCEEDED(hres))
645 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
646 "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
647 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
648 "unexpected typekind %d\n", type_attr->typekind);
649 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
652 ITypeInfo_Release(typeinfo);
653 IProvideClassInfo_Release(classinfo);
656 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
657 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
659 IDispatchEx *dispex = _get_dispex_iface(line, unk);
660 DISPPARAMS dp = {val, NULL, 1, 0};
661 EXCEPINFO ei;
662 DISPID id;
663 BSTR str;
664 HRESULT hres;
666 str = a2bstr(name);
667 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
668 SysFreeString(str);
669 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
671 memset(&ei, 0, sizeof(ei));
672 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
673 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
677 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
678 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
680 IHTMLElement *elem;
681 HRESULT hres;
683 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
684 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
685 return elem;
688 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
689 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
691 IHTMLElement2 *elem;
692 HRESULT hres;
694 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
695 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
696 return elem;
699 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
700 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
702 IHTMLElement3 *elem;
703 HRESULT hres;
705 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
706 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
707 return elem;
710 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
711 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
713 IHTMLElement4 *elem;
714 HRESULT hres;
716 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
717 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
718 return elem;
721 #define get_node_iface(u) _get_node_iface(__LINE__,u)
722 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
724 IHTMLDOMNode *node;
725 HRESULT hres;
727 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
728 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
729 return node;
732 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
733 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
735 IHTMLDOMNode2 *node;
736 HRESULT hres;
738 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
739 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
740 return node;
743 #define get_img_iface(u) _get_img_iface(__LINE__,u)
744 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
746 IHTMLImgElement *img;
747 HRESULT hres;
749 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
750 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
751 return img;
754 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
755 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
757 IHTMLAnchorElement *anchor;
758 HRESULT hres;
760 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
761 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
762 return anchor;
765 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
766 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
768 IHTMLTextAreaElement *textarea;
769 HRESULT hres;
771 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
772 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
773 return textarea;
776 #define get_select_iface(u) _get_select_iface(__LINE__,u)
777 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
779 IHTMLSelectElement *select;
780 HRESULT hres;
782 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
783 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
784 return select;
787 #define get_form_iface(u) _get_form_iface(__LINE__,u)
788 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
790 IHTMLFormElement *form;
791 HRESULT hres;
793 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
794 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
795 return form;
798 #define get_text_iface(u) _get_text_iface(__LINE__,u)
799 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
801 IHTMLDOMTextNode *text;
802 HRESULT hres;
804 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
805 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
806 return text;
809 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
810 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
812 IHTMLCommentElement *comment;
813 HRESULT hres;
815 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
816 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
817 return comment;
820 #define get_object_iface(u) _get_object_iface(__LINE__,u)
821 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
823 IHTMLObjectElement *obj;
824 HRESULT hres;
826 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
827 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
828 return obj;
831 #define get_style_iface(u) _get_style_iface(__LINE__,u)
832 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
834 IHTMLStyleElement *obj;
835 HRESULT hres;
837 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
838 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
839 return obj;
842 #define get_metaelem_iface(u) _get_metaelem_iface(__LINE__,u)
843 static IHTMLMetaElement *_get_metaelem_iface(unsigned line, IUnknown *unk)
845 IHTMLMetaElement *ret;
846 HRESULT hres;
848 hres = IUnknown_QueryInterface(unk, &IID_IHTMLMetaElement, (void**)&ret);
849 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLMetaElement: %08x\n", hres);
850 return ret;
853 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
854 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
856 IHTMLDOMNode *node = _get_node_iface(line, unk);
857 BSTR name;
858 HRESULT hres;
860 hres = IHTMLDOMNode_get_nodeName(node, &name);
861 IHTMLDOMNode_Release(node);
862 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
863 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
865 SysFreeString(name);
868 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
869 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
871 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
872 IDispatch *disp = (void*)0xdeadbeef;
873 IHTMLDocument2 *doc = NULL;
874 HRESULT hres;
876 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
877 IHTMLDOMNode2_Release(node);
878 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
880 if(disp) {
881 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
882 IDispatch_Release(disp);
883 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
886 return doc;
889 #define get_doc_window(d) _get_doc_window(__LINE__,d)
890 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
892 IHTMLWindow2 *window;
893 HRESULT hres;
895 window = NULL;
896 hres = IHTMLDocument2_get_parentWindow(doc, &window);
897 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
898 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
900 return window;
903 #define clone_node(n,d) _clone_node(__LINE__,n,d)
904 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
906 IHTMLDOMNode *node = _get_node_iface(line, unk);
907 IHTMLDOMNode *ret = NULL;
908 HRESULT hres;
910 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
911 IHTMLDOMNode_Release(node);
912 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
913 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
915 return ret;
919 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
920 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
922 IHTMLElement *elem = _get_elem_iface(line, unk);
923 BSTR tag;
924 HRESULT hres;
926 hres = IHTMLElement_get_tagName(elem, &tag);
927 IHTMLElement_Release(elem);
928 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
929 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
931 SysFreeString(tag);
934 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
935 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
937 _test_elem_tag(line, unk, elem_type_infos[type].tag);
938 _test_ifaces(line, unk, elem_type_infos[type].iids);
940 if(elem_type_infos[type].dispiid && type != ET_A)
941 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
944 #define get_node_type(n) _get_node_type(__LINE__,n)
945 static LONG _get_node_type(unsigned line, IUnknown *unk)
947 IHTMLDOMNode *node = _get_node_iface(line, unk);
948 LONG type = -1;
949 HRESULT hres;
951 hres = IHTMLDOMNode_get_nodeType(node, &type);
952 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
954 IHTMLDOMNode_Release(node);
956 return type;
959 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
960 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
962 IHTMLDOMNode *node = _get_node_iface(line, unk);
963 IHTMLDOMChildrenCollection *col = NULL;
964 IDispatch *disp;
965 HRESULT hres;
967 hres = IHTMLDOMNode_get_childNodes(node, &disp);
968 IHTMLDOMNode_Release(node);
969 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
970 if(FAILED(hres))
971 return NULL;
973 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
974 IDispatch_Release(disp);
975 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
977 return col;
980 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
981 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
983 IHTMLDOMNode *node = NULL;
984 IDispatch *disp;
985 HRESULT hres;
987 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
988 ok(hres == S_OK, "item failed: %08x\n", hres);
990 node = _get_node_iface(line, (IUnknown*)disp);
991 IDispatch_Release(disp);
993 return node;
996 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
997 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
999 VARIANT value;
1000 BSTR tmp;
1001 HRESULT hres;
1003 VariantInit(&value);
1005 tmp = a2bstr(name);
1006 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
1007 SysFreeString(tmp);
1008 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
1010 if(exval) {
1011 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
1012 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
1013 }else {
1014 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
1017 VariantClear(&value);
1020 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
1021 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
1023 IHTMLElement *elem = _get_elem_iface(line, unk);
1024 IHTMLElement *off_parent;
1025 LONG l;
1026 HRESULT hres;
1028 hres = IHTMLElement_get_offsetTop(elem, &l);
1029 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1031 hres = IHTMLElement_get_offsetHeight(elem, &l);
1032 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1034 hres = IHTMLElement_get_offsetWidth(elem, &l);
1035 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1037 hres = IHTMLElement_get_offsetLeft(elem, &l);
1038 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1040 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1041 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1043 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1044 IHTMLElement_Release(off_parent);
1046 IHTMLElement_Release(elem);
1049 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1050 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1052 IHTMLWindow2 *window;
1053 IHTMLDocument2 *ret;
1054 HRESULT hres;
1056 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1057 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1059 hres = IHTMLWindow2_get_document(window, &ret);
1060 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1061 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1063 return ret;
1066 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1067 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1069 BSTR name;
1070 HRESULT hres;
1072 hres = IHTMLWindow2_get_name(window, &name);
1073 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1074 if(exname)
1075 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1076 else
1077 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1078 SysFreeString(name);
1081 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1082 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1084 BSTR str;
1085 HRESULT hres;
1087 str = a2bstr(name);
1088 hres = IHTMLWindow2_put_name(window, str);
1089 SysFreeString(str);
1090 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1092 _test_window_name(line, window, name);
1095 #define test_window_status(d) _test_window_status(__LINE__,d)
1096 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1098 BSTR status;
1099 HRESULT hres;
1101 status = (void*)0xdeadbeef;
1102 hres = IHTMLWindow2_get_status(window, &status);
1103 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1104 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1105 SysFreeString(status);
1108 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1109 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1111 BSTR str;
1112 HRESULT hres;
1114 str = a2bstr(status);
1115 hres = IHTMLWindow2_put_status(window, str);
1116 SysFreeString(str);
1117 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1120 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1121 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1123 LONG length = -1;
1124 HRESULT hres;
1126 hres = IHTMLWindow2_get_length(window, &length);
1127 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1128 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1131 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1132 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1134 IHTMLFrameBase2 *base2;
1135 IHTMLWindow2 *window;
1136 HRESULT hres;
1138 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1139 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1141 window = NULL;
1142 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1143 IHTMLFrameBase2_Release(base2);
1144 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1145 ok(window != NULL, "contentWindow = NULL\n");
1147 return window;
1150 static void test_get_set_attr(IHTMLDocument2 *doc)
1152 IHTMLElement *elem;
1153 IHTMLDocument3 *doc3;
1154 HRESULT hres;
1155 BSTR bstr;
1156 VARIANT val;
1158 /* grab an element to test with */
1159 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1160 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1162 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1163 IHTMLDocument3_Release(doc3);
1164 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1166 /* get a non-present attribute */
1167 bstr = a2bstr("notAnAttribute");
1168 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1169 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1170 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1171 VariantClear(&val);
1172 SysFreeString(bstr);
1174 /* get a present attribute */
1175 bstr = a2bstr("scrollHeight");
1176 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1177 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1178 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1179 VariantClear(&val);
1180 SysFreeString(bstr);
1182 /* create a new BSTR attribute */
1183 bstr = a2bstr("newAttribute");
1185 V_VT(&val) = VT_BSTR;
1186 V_BSTR(&val) = a2bstr("the value");
1187 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1188 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1189 VariantClear(&val);
1191 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1192 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1193 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1194 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)));
1195 VariantClear(&val);
1197 /* overwrite the attribute with a BOOL */
1198 V_VT(&val) = VT_BOOL;
1199 V_BOOL(&val) = VARIANT_TRUE;
1200 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1201 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1202 VariantClear(&val);
1204 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1205 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1206 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1207 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1208 VariantClear(&val);
1210 SysFreeString(bstr);
1212 /* case-insensitive */
1213 bstr = a2bstr("newattribute");
1214 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1215 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1216 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1217 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1218 VariantClear(&val);
1219 SysFreeString(bstr);
1221 IHTMLElement_Release(elem);
1224 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1225 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1227 IHTMLElement *elem;
1228 IHTMLDocument3 *doc3;
1229 HRESULT hres;
1231 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1232 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1233 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1234 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1235 IHTMLDocument3_Release(doc3);
1237 return elem;
1240 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1241 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1243 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1244 BSTR str;
1245 HRESULT hres;
1247 hres = IHTMLAnchorElement_get_href(anchor, &str);
1248 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1249 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1250 SysFreeString(str);
1252 _test_disp_value(line, unk, exhref);
1255 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1256 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1258 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1259 BSTR str;
1260 HRESULT hres;
1262 str = a2bstr(exhref);
1263 hres = IHTMLAnchorElement_put_href(anchor, str);
1264 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1265 SysFreeString(str);
1267 _test_disp_value(line, unk, exhref);
1270 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1271 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1273 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1274 BSTR str;
1275 HRESULT hres;
1277 hres = IHTMLAnchorElement_get_target(anchor, &str);
1278 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1279 if(target)
1280 ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1281 else
1282 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1283 SysFreeString(str);
1286 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1287 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1289 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1290 BSTR str;
1291 HRESULT hres;
1293 str = target ? a2bstr(target) : NULL;
1294 hres = IHTMLAnchorElement_put_target(anchor, str);
1295 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1296 SysFreeString(str);
1299 #define test_anchor_name(a,h) _test_anchor_name(__LINE__,a,h)
1300 static void _test_anchor_name(unsigned line, IUnknown *unk, const char *name)
1302 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1303 BSTR str;
1304 HRESULT hres;
1306 hres = IHTMLAnchorElement_get_name(anchor, &str);
1307 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1308 if(name)
1309 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
1310 else
1311 ok_(__FILE__,line)(str == NULL, "name = %s, expected NULL\n", wine_dbgstr_w(str));
1312 SysFreeString(str);
1315 #define test_anchor_put_name(a,h) _test_anchor_put_name(__LINE__,a,h)
1316 static void _test_anchor_put_name(unsigned line, IUnknown *unk, const char *name)
1318 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1319 BSTR str;
1320 HRESULT hres;
1322 str = name ? a2bstr(name) : NULL;
1323 hres = IHTMLAnchorElement_put_name(anchor, str);
1324 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1325 SysFreeString(str);
1327 _test_anchor_name(line, unk, name);
1331 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1332 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1334 BSTR bstr;
1335 HRESULT hres;
1337 hres = IHTMLOptionElement_get_text(option, &bstr);
1338 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1339 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1340 SysFreeString(bstr);
1343 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1344 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1346 BSTR bstr;
1347 HRESULT hres;
1349 bstr = a2bstr(text);
1350 hres = IHTMLOptionElement_put_text(option, bstr);
1351 SysFreeString(bstr);
1352 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1354 _test_option_text(line, option, text);
1357 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1358 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1360 BSTR bstr;
1361 HRESULT hres;
1363 hres = IHTMLOptionElement_get_value(option, &bstr);
1364 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1365 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1366 SysFreeString(bstr);
1369 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1370 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1372 BSTR bstr;
1373 HRESULT hres;
1375 bstr = a2bstr(value);
1376 hres = IHTMLOptionElement_put_value(option, bstr);
1377 SysFreeString(bstr);
1378 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1380 _test_option_value(line, option, value);
1383 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1384 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1386 VARIANT_BOOL b = 0x100;
1387 HRESULT hres;
1389 hres = IHTMLOptionElement_get_selected(option, &b);
1390 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1391 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1394 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1395 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1397 HRESULT hres;
1399 hres = IHTMLOptionElement_put_selected(option, b);
1400 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1401 _test_option_selected(line, option, b);
1404 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1405 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1407 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1408 BSTR value = (void*)0xdeadbeef;
1409 HRESULT hres;
1411 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1412 IHTMLTextAreaElement_Release(textarea);
1413 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1414 if(exval)
1415 ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1416 else
1417 ok_(__FILE__,line)(!value, "value = %p\n", value);
1418 SysFreeString(value);
1421 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1422 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1424 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1425 BSTR tmp = a2bstr(value);
1426 HRESULT hres;
1428 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1429 IHTMLTextAreaElement_Release(textarea);
1430 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1431 SysFreeString(tmp);
1433 _test_textarea_value(line, unk, value);
1436 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1437 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1439 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1440 VARIANT_BOOL b = 0x100;
1441 HRESULT hres;
1443 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1444 IHTMLTextAreaElement_Release(textarea);
1445 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1446 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1449 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1450 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1452 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1453 HRESULT hres;
1455 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1456 IHTMLTextAreaElement_Release(textarea);
1457 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1459 _test_textarea_readonly(line, unk, b);
1462 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1463 static void _test_textarea_type(unsigned line, IUnknown *unk)
1465 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1466 BSTR type = (void*)0xdeadbeef;
1467 HRESULT hres;
1469 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1470 IHTMLTextAreaElement_Release(textarea);
1471 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1472 ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1473 SysFreeString(type);
1476 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1477 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1479 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1480 BSTR text;
1481 HRESULT hres;
1483 text = a2bstr(extext);
1484 hres = IHTMLCommentElement_get_text(comment, &text);
1485 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1486 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1488 IHTMLCommentElement_Release(comment);
1489 SysFreeString(text);
1492 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1493 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1495 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1496 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1497 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1498 IHTMLDOMAttribute *attr;
1499 BSTR name = a2bstr("test");
1500 VARIANT val;
1501 HRESULT hres;
1503 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1504 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1505 ok(attr == NULL, "attr != NULL\n");
1507 V_VT(&val) = VT_I4;
1508 V_I4(&val) = 1234;
1509 hres = IHTMLElement_setAttribute(elem, name, val, 0);
1510 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1512 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1513 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1514 ok(attr != NULL, "attr == NULL\n");
1516 IHTMLDOMAttribute_Release(attr);
1517 IHTMLCommentElement_Release(comment);
1518 IHTMLElement_Release(elem);
1519 IHTMLElement4_Release(elem);
1520 SysFreeString(name);
1523 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1524 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1526 IHTMLObjectElement *object = _get_object_iface(line, unk);
1527 LONG l;
1528 HRESULT hres;
1530 l = 0xdeadbeef;
1531 hres = IHTMLObjectElement_get_vspace(object, &l);
1532 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1533 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1534 IHTMLObjectElement_Release(object);
1537 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1538 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1539 const char *txt, const char *val)
1541 IHTMLOptionElementFactory *factory;
1542 IHTMLOptionElement *option;
1543 IHTMLWindow2 *window;
1544 VARIANT text, value, empty;
1545 HRESULT hres;
1547 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1548 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1550 hres = IHTMLWindow2_get_Option(window, &factory);
1551 IHTMLWindow2_Release(window);
1552 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1554 V_VT(&text) = VT_BSTR;
1555 V_BSTR(&text) = a2bstr(txt);
1556 V_VT(&value) = VT_BSTR;
1557 V_BSTR(&value) = a2bstr(val);
1558 V_VT(&empty) = VT_EMPTY;
1560 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1561 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1563 IHTMLOptionElementFactory_Release(factory);
1564 VariantClear(&text);
1565 VariantClear(&value);
1567 _test_option_text(line, option, txt);
1568 _test_option_value(line, option, val);
1569 _test_option_selected(line, option, VARIANT_FALSE);
1571 return option;
1574 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1575 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1577 LONG found = -1;
1578 HRESULT hres;
1580 hres = IHTMLImgElement_get_width(img, &found);
1581 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1582 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1585 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1586 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
1588 HRESULT hres;
1590 hres = IHTMLImgElement_put_width(img, width);
1591 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1593 _test_img_width(line, img, width);
1596 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1597 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
1599 LONG found = -1;
1600 HRESULT hres;
1602 hres = IHTMLImgElement_get_height(img, &found);
1603 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1604 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1607 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1608 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
1610 HRESULT hres;
1612 hres = IHTMLImgElement_put_height(img, height);
1613 ok(hres == S_OK, "put_height failed: %08x\n", hres);
1615 _test_img_height(line, img, height);
1618 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1619 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1620 LONG wdth, LONG hght)
1622 IHTMLImageElementFactory *factory;
1623 IHTMLImgElement *img;
1624 IHTMLWindow2 *window;
1625 VARIANT width, height;
1626 char buf[16];
1627 HRESULT hres;
1629 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1630 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1632 hres = IHTMLWindow2_get_Image(window, &factory);
1633 IHTMLWindow2_Release(window);
1634 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1636 test_ifaces((IUnknown*)factory, img_factory_iids);
1637 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1639 if(wdth >= 0){
1640 snprintf(buf, 16, "%d", wdth);
1641 V_VT(&width) = VT_BSTR;
1642 V_BSTR(&width) = a2bstr(buf);
1643 }else{
1644 V_VT(&width) = VT_EMPTY;
1645 wdth = 0;
1648 if(hght >= 0){
1649 snprintf(buf, 16, "%d", hght);
1650 V_VT(&height) = VT_BSTR;
1651 V_BSTR(&height) = a2bstr(buf);
1652 }else{
1653 V_VT(&height) = VT_EMPTY;
1654 hght = 0;
1657 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1658 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1660 IHTMLImageElementFactory_Release(factory);
1661 VariantClear(&width);
1662 VariantClear(&height);
1664 if(SUCCEEDED(hres)) {
1665 _test_img_width(line, img, wdth);
1666 _test_img_height(line, img, hght);
1667 return img;
1670 return NULL;
1673 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1674 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1676 LONG len = 0xdeadbeef;
1677 HRESULT hres;
1679 hres = IHTMLSelectElement_get_length(select, &len);
1680 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1681 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1684 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
1685 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
1687 IHTMLSelectElement *select = _get_select_iface(line, unk);
1688 HRESULT hres;
1690 hres = IHTMLSelectElement_put_length(select, length);
1691 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
1692 _test_select_length(line, select, length);
1693 IHTMLSelectElement_Release(select);
1696 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1697 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1699 LONG idx = 0xdeadbeef;
1700 HRESULT hres;
1702 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1703 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1704 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1707 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1708 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1710 HRESULT hres;
1712 hres = IHTMLSelectElement_put_selectedIndex(select, index);
1713 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1714 _test_select_selidx(line, select, index);
1717 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1718 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1720 BSTR val;
1721 HRESULT hres;
1723 hres = IHTMLSelectElement_get_value(select, &val);
1724 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1725 if(exval)
1726 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1727 else
1728 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1729 SysFreeString(val);
1732 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1733 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1735 BSTR bstr;
1736 HRESULT hres;
1738 bstr = a2bstr(val);
1739 hres = IHTMLSelectElement_put_value(select, bstr);
1740 SysFreeString(bstr);
1741 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1744 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1745 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1747 BSTR type;
1748 HRESULT hres;
1750 hres = IHTMLSelectElement_get_type(select, &type);
1751 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1752 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1753 SysFreeString(type);
1756 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1757 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1759 BSTR text;
1760 HRESULT hres;
1762 hres = IHTMLTxtRange_get_text(range, &text);
1763 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1765 if(extext) {
1766 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1767 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1768 }else {
1769 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1772 SysFreeString(text);
1776 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1777 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1779 HRESULT hres;
1781 hres = IHTMLTxtRange_collapse(range, b);
1782 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1783 _test_range_text(line, range, NULL);
1786 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1787 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1788 VARIANT_BOOL exb, const char *extext)
1790 VARIANT_BOOL b = 0xe0e0;
1791 HRESULT hres;
1793 hres = IHTMLTxtRange_expand(range, unit, &b);
1794 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1795 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1796 _test_range_text(line, range, extext);
1799 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1800 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1802 LONG c = 0xdeadbeef;
1803 HRESULT hres;
1805 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1806 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1807 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1808 _test_range_text(line, range, NULL);
1811 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1812 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1813 LPWSTR unit, LONG cnt, LONG excnt)
1815 LONG c = 0xdeadbeef;
1816 HRESULT hres;
1818 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1819 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1820 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1823 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1824 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1826 LONG c = 0xdeadbeef;
1827 HRESULT hres;
1829 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1830 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1831 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1834 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1835 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1837 HRESULT hres;
1838 BSTR bstr = a2bstr(text);
1840 hres = IHTMLTxtRange_put_text(range, bstr);
1841 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1842 SysFreeString(bstr);
1843 _test_range_text(line, range, NULL);
1846 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1847 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1849 VARIANT_BOOL b;
1850 HRESULT hres;
1852 b = 0xe0e0;
1853 hres = IHTMLTxtRange_inRange(range1, range2, &b);
1854 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1855 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1858 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1859 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1861 VARIANT_BOOL b;
1862 HRESULT hres;
1864 b = 0xe0e0;
1865 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1866 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1867 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1869 b = 0xe0e0;
1870 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1871 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1872 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1874 if(exb) {
1875 test_range_inrange(range1, range2, VARIANT_TRUE);
1876 test_range_inrange(range2, range1, VARIANT_TRUE);
1880 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1881 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1883 IHTMLElement *elem;
1884 HRESULT hres;
1886 hres = IHTMLTxtRange_parentElement(range, &elem);
1887 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1889 _test_elem_type(line, (IUnknown*)elem, type);
1891 IHTMLElement_Release(elem);
1894 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1895 static void _test_elem_collection(unsigned line, IUnknown *unk,
1896 const elem_type_t *elem_types, LONG exlen)
1898 IHTMLElementCollection *col;
1899 LONG len;
1900 DWORD i;
1901 VARIANT name, index;
1902 IDispatch *disp, *disp2;
1903 HRESULT hres;
1905 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1906 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1908 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1910 hres = IHTMLElementCollection_get_length(col, &len);
1911 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1912 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1914 if(len > exlen)
1915 len = exlen;
1917 V_VT(&index) = VT_EMPTY;
1919 for(i=0; i<len; i++) {
1920 V_VT(&name) = VT_I4;
1921 V_I4(&name) = i;
1922 disp = (void*)0xdeadbeef;
1923 hres = IHTMLElementCollection_item(col, name, index, &disp);
1924 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1925 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1926 if(FAILED(hres) || !disp)
1927 continue;
1929 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1931 if(!i) {
1932 V_VT(&name) = VT_UINT;
1933 V_I4(&name) = 0;
1934 disp2 = (void*)0xdeadbeef;
1935 hres = IHTMLElementCollection_item(col, name, index, &disp2);
1936 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1937 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1938 if(disp2)
1939 IDispatch_Release(disp2);
1942 IDispatch_Release(disp);
1945 V_VT(&name) = VT_I4;
1946 V_I4(&name) = len;
1947 disp = (void*)0xdeadbeef;
1948 hres = IHTMLElementCollection_item(col, name, index, &disp);
1949 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1950 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1952 V_VT(&name) = VT_I4;
1953 V_I4(&name) = -1;
1954 disp = (void*)0xdeadbeef;
1955 hres = IHTMLElementCollection_item(col, name, index, &disp);
1956 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1957 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1959 IHTMLElementCollection_Release(col);
1962 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
1963 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
1965 IHTMLElement *elem = _get_elem_iface(line, unk);
1966 IDispatch *disp;
1967 HRESULT hres;
1969 hres = IHTMLElement_get_all(elem, &disp);
1970 IHTMLElement_Release(elem);
1971 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
1973 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
1974 IDispatch_Release(disp);
1977 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1978 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1980 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1981 IHTMLElementCollection *col = NULL;
1982 elem_type_t *types = NULL;
1983 BSTR tmp;
1984 int i;
1985 HRESULT hres;
1987 tmp = a2bstr(elem_type_infos[type].tag);
1988 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1989 SysFreeString(tmp);
1990 IHTMLElement2_Release(elem);
1991 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1992 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1994 if(exlen) {
1995 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1996 for(i=0; i<exlen; i++)
1997 types[i] = type;
2000 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2002 HeapFree(GetProcessHeap(), 0, types);
2005 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
2006 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
2008 BSTR text = NULL;
2009 HRESULT hres;
2011 hres = IHTMLElement_get_innerText(elem, &text);
2012 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
2013 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
2014 wine_dbgstr_w(text), extext);
2015 SysFreeString(text);
2018 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
2019 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
2021 IHTMLDOMChildrenCollection *col;
2022 BSTR str;
2023 HRESULT hres;
2025 str = a2bstr(text);
2026 hres = IHTMLElement_put_innerText(elem, str);
2027 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
2028 SysFreeString(str);
2030 _test_elem_innertext(line, elem, text);
2033 col = _get_child_nodes(line, (IUnknown*)elem);
2034 ok(col != NULL, "col == NULL\n");
2035 if(col) {
2036 LONG length = 0, type;
2037 IHTMLDOMNode *node;
2039 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
2040 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2041 ok(length == 1, "length = %d\n", length);
2043 node = _get_child_item(line, col, 0);
2044 ok(node != NULL, "node == NULL\n");
2045 if(node) {
2046 type = _get_node_type(line, (IUnknown*)node);
2047 ok(type == 3, "type=%d\n", type);
2048 IHTMLDOMNode_Release(node);
2051 IHTMLDOMChildrenCollection_Release(col);
2056 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2057 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2059 IHTMLElement *elem = _get_elem_iface(line, unk);
2060 BSTR html;
2061 HRESULT hres;
2063 hres = IHTMLElement_get_innerHTML(elem, &html);
2064 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2065 if(inner_html)
2066 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2067 else
2068 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2070 IHTMLElement_Release(elem);
2071 SysFreeString(html);
2074 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2075 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2077 IHTMLElement *elem = _get_elem_iface(line, unk);
2078 BSTR html;
2079 HRESULT hres;
2081 html = a2bstr(inner_html);
2082 hres = IHTMLElement_put_innerHTML(elem, html);
2083 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2085 IHTMLElement_Release(elem);
2086 SysFreeString(html);
2089 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2090 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2092 IHTMLElement *elem = _get_elem_iface(line, unk);
2093 BSTR html;
2094 HRESULT hres;
2096 html = a2bstr(outer_html);
2097 hres = IHTMLElement_put_outerHTML(elem, html);
2098 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2100 IHTMLElement_Release(elem);
2101 SysFreeString(html);
2104 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2105 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2107 IHTMLElement *elem = _get_elem_iface(line, unk);
2108 BSTR html;
2109 HRESULT hres;
2111 hres = IHTMLElement_get_outerHTML(elem, &html);
2112 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2113 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2115 IHTMLElement_Release(elem);
2116 SysFreeString(html);
2119 #define get_first_child(n) _get_first_child(__LINE__,n)
2120 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2122 IHTMLDOMNode *node = _get_node_iface(line, unk);
2123 IHTMLDOMNode *child = NULL;
2124 HRESULT hres;
2126 hres = IHTMLDOMNode_get_firstChild(node, &child);
2127 IHTMLDOMNode_Release(node);
2128 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2130 return child;
2133 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2134 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2136 IHTMLDOMNode *node = _get_node_iface(line, unk);
2137 VARIANT_BOOL b = 0xdead;
2138 HRESULT hres;
2140 hres = IHTMLDOMNode_hasChildNodes(node, &b);
2141 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2142 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2144 IHTMLDOMNode_Release(node);
2147 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2148 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2150 IHTMLDOMNode *node = _get_node_iface(line, unk);
2151 IHTMLDOMNode *parent;
2152 HRESULT hres;
2154 hres = IHTMLDOMNode_get_parentNode(node, &parent);
2155 IHTMLDOMNode_Release(node);
2156 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2158 return parent;
2161 #define node_get_next(u) _node_get_next(__LINE__,u)
2162 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2164 IHTMLDOMNode *node = _get_node_iface(line, unk);
2165 IHTMLDOMNode *next;
2166 HRESULT hres;
2168 hres = IHTMLDOMNode_get_nextSibling(node, &next);
2169 IHTMLDOMNode_Release(node);
2170 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2172 return next;
2175 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2176 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2178 IHTMLDOMNode *node = _get_node_iface(line, unk);
2179 IHTMLDOMNode *prev;
2180 HRESULT hres;
2182 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2183 IHTMLDOMNode_Release(node);
2184 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2186 return prev;
2189 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2190 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2192 IHTMLElement *elem = _get_elem_iface(line, unk);
2193 IHTMLElement *parent;
2194 HRESULT hres;
2196 hres = IHTMLElement_get_parentElement(elem, &parent);
2197 IHTMLElement_Release(elem);
2198 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2200 return parent;
2203 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2204 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2206 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2207 VARIANT_BOOL disabled = 100;
2208 HRESULT hres;
2210 if (!elem3) return;
2211 hres = IHTMLElement3_get_disabled(elem3, &disabled);
2212 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2213 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2214 IHTMLElement3_Release(elem3);
2217 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2218 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2220 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2221 HRESULT hres;
2223 if (!elem3) return;
2224 hres = IHTMLElement3_put_disabled(elem3, b);
2225 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2227 IHTMLElement3_Release(elem3);
2228 _test_elem3_get_disabled(line, unk, b);
2231 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2232 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2234 VARIANT_BOOL disabled = 100;
2235 HRESULT hres;
2237 hres = IHTMLSelectElement_get_disabled(select, &disabled);
2238 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2239 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2241 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2244 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2245 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2247 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2248 LONG length;
2249 HRESULT hres;
2251 hres = IHTMLDOMTextNode_get_length(text, &length);
2252 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2253 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2254 IHTMLDOMTextNode_Release(text);
2257 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2258 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2260 HRESULT hres;
2262 hres = IHTMLSelectElement_put_disabled(select, b);
2263 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2265 _test_select_get_disabled(line, select, b);
2268 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2269 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2271 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2272 IHTMLTextContainer *txtcont;
2273 LONG l = -1, l2 = -1;
2274 HRESULT hres;
2276 hres = IHTMLElement2_get_scrollHeight(elem, &l);
2277 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2278 IHTMLElement2_Release(elem);
2280 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2281 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2283 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2284 IHTMLTextContainer_Release(txtcont);
2285 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2286 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
2288 return l;
2291 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
2292 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
2294 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2295 IHTMLTextContainer *txtcont;
2296 LONG l = -1, l2 = -1;
2297 HRESULT hres;
2299 hres = IHTMLElement2_get_scrollWidth(elem, &l);
2300 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
2301 IHTMLElement2_Release(elem);
2303 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2304 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2306 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
2307 IHTMLTextContainer_Release(txtcont);
2308 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
2309 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
2311 return l;
2314 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
2315 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
2317 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2318 IHTMLTextContainer *txtcont;
2319 LONG l = -1, l2 = -1;
2320 HRESULT hres;
2322 hres = IHTMLElement2_get_scrollTop(elem, &l);
2323 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2324 IHTMLElement2_Release(elem);
2326 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2327 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2329 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
2330 IHTMLTextContainer_Release(txtcont);
2331 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
2332 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
2334 return l;
2337 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
2338 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
2340 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2341 IHTMLTextContainer *txtcont;
2342 LONG l = -1, l2 = -1;
2343 HRESULT hres;
2345 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
2346 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
2348 hres = IHTMLElement2_get_scrollLeft(elem, &l);
2349 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2350 IHTMLElement2_Release(elem);
2352 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2353 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2355 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
2356 IHTMLTextContainer_Release(txtcont);
2357 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
2358 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
2361 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
2362 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
2364 IHTMLImgElement *img = _get_img_iface(line, unk);
2365 BSTR src;
2366 HRESULT hres;
2368 hres = IHTMLImgElement_get_src(img, &src);
2369 IHTMLImgElement_Release(img);
2370 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2371 ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
2372 "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2373 SysFreeString(src);
2376 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
2377 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
2379 IHTMLImgElement *img = _get_img_iface(line, unk);
2380 BSTR tmp;
2381 HRESULT hres;
2383 tmp = a2bstr(src);
2384 hres = IHTMLImgElement_put_src(img, tmp);
2385 IHTMLImgElement_Release(img);
2386 SysFreeString(tmp);
2387 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2390 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
2391 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
2393 IHTMLImgElement *img = _get_img_iface(line, unk);
2394 BSTR alt;
2395 HRESULT hres;
2397 hres = IHTMLImgElement_get_alt(img, &alt);
2398 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2399 if(exalt)
2400 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
2401 else
2402 ok_(__FILE__,line) (!alt, "alt != NULL\n");
2403 SysFreeString(alt);
2406 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
2407 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
2409 IHTMLImgElement *img = _get_img_iface(line, unk);
2410 BSTR tmp;
2411 HRESULT hres;
2413 tmp = a2bstr(alt);
2414 hres = IHTMLImgElement_put_alt(img, tmp);
2415 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2416 SysFreeString(tmp);
2418 _test_img_alt(line, unk, alt);
2421 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
2422 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
2424 IHTMLImgElement *img = _get_img_iface(line, unk);
2425 BSTR sName;
2426 HRESULT hres;
2428 hres = IHTMLImgElement_get_name(img, &sName);
2429 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
2430 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
2431 IHTMLImgElement_Release(img);
2432 SysFreeString(sName);
2435 static void test_dynamic_properties(IHTMLElement *elem)
2437 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
2438 IDispatchEx *dispex;
2439 BSTR name, attr1 = SysAllocString(attr1W);
2440 VARIANT_BOOL succ;
2441 VARIANT val;
2442 int checked_no = 0;
2443 DISPID id = DISPID_STARTENUM;
2444 HRESULT hres;
2446 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2447 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2449 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
2450 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
2451 ok(succ, "removeAttribute set succ to FALSE\n");
2453 while(1) {
2454 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2455 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
2456 if(hres != S_OK)
2457 break;
2459 hres = IDispatchEx_GetMemberName(dispex, id, &name);
2460 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2462 if(!strcmp_wa(name, "attr1"))
2463 ok(0, "attr1 should be removed\n");
2464 else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
2465 checked_no++;
2466 SysFreeString(name);
2468 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
2469 IDispatchEx_Release(dispex);
2471 V_VT(&val) = VT_BSTR;
2472 V_BSTR(&val) = attr1;
2473 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
2474 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2475 SysFreeString(attr1);
2478 static void test_attr_collection_disp(IDispatch *disp)
2480 IDispatchEx *dispex;
2481 IHTMLDOMAttribute *attr;
2482 DISPPARAMS dp = {NULL, NULL, 0, 0};
2483 VARIANT var;
2484 EXCEPINFO ei;
2485 DISPID id;
2486 BSTR bstr;
2487 HRESULT hres;
2489 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2490 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2492 bstr = a2bstr("0");
2493 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2494 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2495 SysFreeString(bstr);
2497 VariantInit(&var);
2498 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2499 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2500 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2501 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2502 VariantClear(&var);
2504 bstr = a2bstr("attr1");
2505 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2506 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2507 SysFreeString(bstr);
2509 VariantInit(&var);
2510 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2511 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2512 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2513 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2514 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
2515 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2516 hres = IHTMLDOMAttribute_get_nodeName(attr, &bstr);
2517 ok(hres == S_OK, "get_nodeName failed: %08x\n", hres);
2518 ok(!strcmp_wa(bstr, "attr1"), "node name is %s, expected attr1\n", wine_dbgstr_w(bstr));
2519 SysFreeString(bstr);
2520 IHTMLDOMAttribute_Release(attr);
2521 VariantClear(&var);
2523 IDispatchEx_Release(dispex);
2526 static void test_attr_collection(IHTMLElement *elem)
2528 static const WCHAR testW[] = {'t','e','s','t',0};
2530 IHTMLDOMNode *node;
2531 IDispatch *disp, *attr;
2532 IHTMLDOMAttribute *dom_attr;
2533 IHTMLAttributeCollection *attr_col;
2534 BSTR name = SysAllocString(testW);
2535 VARIANT id, val;
2536 LONG i, len, checked;
2537 HRESULT hres;
2539 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
2540 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2542 hres = IHTMLDOMNode_get_attributes(node, &disp);
2543 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2545 hres = IHTMLDOMNode_get_attributes(node, &attr);
2546 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2547 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
2548 IDispatch_Release(attr);
2549 IHTMLDOMNode_Release(node);
2551 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
2552 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2554 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
2555 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2557 V_VT(&val) = VT_I4;
2558 V_I4(&val) = 1;
2559 hres = IHTMLElement_setAttribute(elem, name, val, 0);
2560 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2561 SysFreeString(name);
2563 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
2564 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2565 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
2567 checked = 0;
2568 for(i=0; i<len; i++) {
2569 V_VT(&id) = VT_I4;
2570 V_I4(&id) = i;
2571 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2572 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
2574 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
2575 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
2576 IDispatch_Release(attr);
2578 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
2579 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
2581 if(!strcmp_wa(name, "id")) {
2582 checked++;
2583 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2584 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2585 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
2586 ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2587 } else if(!strcmp_wa(name, "attr1")) {
2588 checked++;
2589 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2590 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2591 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
2592 ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2593 } else if(!strcmp_wa(name, "attr2")) {
2594 checked++;
2595 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2596 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2597 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
2598 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
2599 } else if(!strcmp_wa(name, "attr3")) {
2600 checked++;
2601 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2602 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2603 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
2604 ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2605 } else if(!strcmp_wa(name, "test")) {
2606 checked++;
2607 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2608 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2609 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
2610 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
2613 IHTMLDOMAttribute_Release(dom_attr);
2614 SysFreeString(name);
2615 VariantClear(&val);
2617 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
2619 V_I4(&id) = len;
2620 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2621 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2623 V_VT(&id) = VT_BSTR;
2624 V_BSTR(&id) = a2bstr("nonexisting");
2625 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2626 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2627 VariantClear(&id);
2629 test_attr_collection_disp(disp);
2631 IDispatch_Release(disp);
2632 IHTMLAttributeCollection_Release(attr_col);
2635 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
2636 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
2638 BSTR type;
2639 HRESULT hres;
2641 hres = IHTMLInputElement_get_type(input, &type);
2642 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2643 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
2644 SysFreeString(type);
2647 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
2648 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
2650 BSTR name = (BSTR)0xdeadbeef;
2651 HRESULT hres;
2653 hres = IHTMLInputElement_get_name(input, &name);
2654 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
2655 if(exname)
2656 ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
2657 else
2658 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
2659 SysFreeString(name);
2662 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
2663 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
2665 BSTR tmp = a2bstr(name);
2666 HRESULT hres;
2668 hres = IHTMLInputElement_put_name(input, tmp);
2669 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
2670 SysFreeString(tmp);
2672 _test_input_name(line, input, name);
2675 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
2676 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2678 VARIANT_BOOL disabled = 100;
2679 HRESULT hres;
2681 hres = IHTMLInputElement_get_disabled(input, &disabled);
2682 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2683 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2685 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
2688 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
2689 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2691 HRESULT hres;
2693 hres = IHTMLInputElement_put_disabled(input, b);
2694 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2696 _test_input_get_disabled(line, input, b);
2699 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
2700 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2702 VARIANT_BOOL checked = 100;
2703 HRESULT hres;
2705 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
2706 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2707 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2710 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
2711 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2713 HRESULT hres;
2715 hres = IHTMLInputElement_put_defaultChecked(input, b);
2716 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2718 _test_input_get_defaultchecked(line, input, b);
2721 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
2722 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2724 VARIANT_BOOL checked = 100;
2725 HRESULT hres;
2727 hres = IHTMLInputElement_get_checked(input, &checked);
2728 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2729 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2732 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
2733 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2735 HRESULT hres;
2737 hres = IHTMLInputElement_put_checked(input, b);
2738 ok_(__FILE__,line) (hres == S_OK, "put_checked failed: %08x\n", hres);
2740 _test_input_get_checked(line, input, b);
2743 #define test_input_maxlength(i,b) _test_input_maxlength(__LINE__,i,b)
2744 static void _test_input_maxlength(unsigned line, IHTMLInputElement *input, LONG exl)
2746 LONG maxlength = 0xdeadbeef;
2747 HRESULT hres;
2749 hres = IHTMLInputElement_get_maxLength(input, &maxlength);
2750 ok_(__FILE__,line) (hres == S_OK, "get_maxLength failed: %08x\n", hres);
2751 ok_(__FILE__,line) (maxlength == exl, "maxLength=%x, expected %d\n", maxlength, exl);
2754 #define test_input_set_maxlength(i,b) _test_input_set_maxlength(__LINE__,i,b)
2755 static void _test_input_set_maxlength(unsigned line, IHTMLInputElement *input, LONG l)
2757 HRESULT hres;
2759 hres = IHTMLInputElement_put_maxLength(input, l);
2760 ok_(__FILE__,line) (hres == S_OK, "put_maxLength failed: %08x\n", hres);
2762 _test_input_maxlength(line, input, l);
2765 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
2766 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
2768 IHTMLInputElement *input;
2769 BSTR bstr;
2770 HRESULT hres;
2772 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2773 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2774 if(FAILED(hres))
2775 return;
2777 hres = IHTMLInputElement_get_value(input, &bstr);
2778 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2779 if(exval)
2780 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
2781 else
2782 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
2783 SysFreeString(bstr);
2784 IHTMLInputElement_Release(input);
2787 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
2788 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
2790 IHTMLInputElement *input;
2791 BSTR bstr;
2792 HRESULT hres;
2794 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2795 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2796 if(FAILED(hres))
2797 return;
2799 bstr = a2bstr(val);
2800 hres = IHTMLInputElement_put_value(input, bstr);
2801 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2802 SysFreeString(bstr);
2803 IHTMLInputElement_Release(input);
2805 _test_input_value(line, unk, val);
2808 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
2809 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
2811 BSTR src;
2812 HRESULT hres;
2814 hres = IHTMLInputElement_get_src(input, &src);
2815 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2816 if(exsrc)
2817 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2818 else
2819 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
2820 SysFreeString(src);
2823 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
2824 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
2826 BSTR tmp;
2827 HRESULT hres;
2829 tmp = a2bstr(src);
2830 hres = IHTMLInputElement_put_src(input, tmp);
2831 SysFreeString(tmp);
2832 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2834 _test_input_src(line, input, src);
2837 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
2838 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
2840 IHTMLElement *elem = _get_elem_iface(line, unk);
2841 BSTR class = (void*)0xdeadbeef;
2842 HRESULT hres;
2844 hres = IHTMLElement_get_className(elem, &class);
2845 IHTMLElement_Release(elem);
2846 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
2847 if(exclass)
2848 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
2849 else
2850 ok_(__FILE__,line) (!class, "class != NULL\n");
2851 SysFreeString(class);
2854 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
2855 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
2857 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2858 short index = -3;
2859 HRESULT hres;
2861 hres = IHTMLElement2_get_tabIndex(elem2, &index);
2862 IHTMLElement2_Release(elem2);
2863 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2864 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
2867 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
2868 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
2870 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2871 HRESULT hres;
2873 hres = IHTMLElement2_put_tabIndex(elem2, index);
2874 IHTMLElement2_Release(elem2);
2875 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2877 _test_elem_tabindex(line, unk, index);
2880 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
2881 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
2883 IHTMLStyleElement *style = _get_style_iface(line, unk);
2884 BSTR media;
2885 HRESULT hres;
2887 hres = IHTMLStyleElement_get_media(style, &media);
2888 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
2889 if(exmedia)
2890 ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
2891 else
2892 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
2894 IHTMLStyleElement_Release(style);
2895 SysFreeString(media);
2898 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
2899 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
2901 IHTMLStyleElement *style = _get_style_iface(line, unk);
2902 BSTR str;
2903 HRESULT hres;
2905 str = a2bstr(media);
2906 hres = IHTMLStyleElement_put_media(style, str);
2907 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
2908 IHTMLStyleElement_Release(style);
2909 SysFreeString(str);
2911 _test_style_media(line, unk, media);
2914 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
2915 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
2917 IHTMLStyleElement *style = _get_style_iface(line, unk);
2918 BSTR type;
2919 HRESULT hres;
2921 hres = IHTMLStyleElement_get_type(style, &type);
2922 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
2923 if(extype)
2924 ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
2925 else
2926 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
2928 IHTMLStyleElement_Release(style);
2929 SysFreeString(type);
2932 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
2933 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
2935 IHTMLStyleElement *style = _get_style_iface(line, unk);
2936 BSTR str;
2937 HRESULT hres;
2939 str = a2bstr(type);
2940 hres = IHTMLStyleElement_put_type(style, str);
2941 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
2942 IHTMLStyleElement_Release(style);
2943 SysFreeString(str);
2945 _test_style_type(line, unk, type);
2948 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
2949 static void _test_elem_filters(unsigned line, IUnknown *unk)
2951 IHTMLElement *elem = _get_elem_iface(line, unk);
2952 HRESULT hres;
2953 IHTMLFiltersCollection *filters;
2955 hres = IHTMLElement_get_filters(elem, &filters);
2956 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
2957 "get_filters failed: %08x\n", hres);
2958 if(hres == S_OK)
2960 LONG len;
2961 IDispatchEx *dispex;
2963 hres = IHTMLFiltersCollection_get_length(filters, &len);
2964 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2965 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
2967 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
2968 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
2969 "Could not get IDispatchEx interface: %08x\n", hres);
2970 if(SUCCEEDED(hres)) {
2971 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
2972 IDispatchEx_Release(dispex);
2975 IHTMLFiltersCollection_Release(filters);
2978 IHTMLElement_Release(elem);
2981 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
2982 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
2984 IHTMLElement *elem = _get_elem_iface(line, unk);
2985 BSTR tmp;
2986 HRESULT hres;
2988 tmp = class ? a2bstr(class) : NULL;
2989 hres = IHTMLElement_put_className(elem, tmp);
2990 IHTMLElement_Release(elem);
2991 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
2992 SysFreeString(tmp);
2994 _test_elem_class(line, unk, class);
2997 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
2998 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
3000 IHTMLElement *elem = _get_elem_iface(line, unk);
3001 BSTR id = (void*)0xdeadbeef;
3002 HRESULT hres;
3004 hres = IHTMLElement_get_id(elem, &id);
3005 IHTMLElement_Release(elem);
3006 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
3008 if(exid)
3009 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
3010 else
3011 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
3013 SysFreeString(id);
3016 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
3017 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
3019 IHTMLElement *elem = _get_elem_iface(line, unk);
3020 BSTR tmp = a2bstr(new_id);
3021 HRESULT hres;
3023 hres = IHTMLElement_put_id(elem, tmp);
3024 IHTMLElement_Release(elem);
3025 SysFreeString(tmp);
3026 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
3028 _test_elem_id(line, unk, new_id);
3031 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
3032 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
3034 IHTMLElement *elem = _get_elem_iface(line, unk);
3035 BSTR title;
3036 HRESULT hres;
3038 hres = IHTMLElement_get_title(elem, &title);
3039 IHTMLElement_Release(elem);
3040 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3041 if(extitle)
3042 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3043 else
3044 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
3046 SysFreeString(title);
3049 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
3050 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
3052 IHTMLElement *elem = _get_elem_iface(line, unk);
3053 BSTR tmp;
3054 HRESULT hres;
3056 tmp = a2bstr(title);
3057 hres = IHTMLElement_put_title(elem, tmp);
3058 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3060 IHTMLElement_Release(elem);
3061 SysFreeString(tmp);
3064 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
3065 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
3067 IHTMLDOMNode *node = _get_node_iface(line, unk);
3068 VARIANT var;
3069 HRESULT hres;
3071 hres = IHTMLDOMNode_get_nodeValue(node, &var);
3072 IHTMLDOMNode_Release(node);
3073 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3075 if(exval) {
3076 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
3077 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
3078 }else {
3079 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
3082 VariantClear(&var);
3085 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
3086 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
3088 IHTMLDOMNode *node = _get_node_iface(line, unk);
3089 VARIANT var;
3090 HRESULT hres;
3092 V_VT(&var) = VT_BSTR;
3093 V_BSTR(&var) = a2bstr(val);
3095 hres = IHTMLDOMNode_put_nodeValue(node, var);
3096 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3097 IHTMLDOMNode_Release(node);
3098 VariantClear(&var);
3101 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
3102 static void _test_elem_client_size(unsigned line, IUnknown *unk)
3104 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3105 LONG l;
3106 HRESULT hres;
3108 hres = IHTMLElement2_get_clientWidth(elem, &l);
3109 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
3110 hres = IHTMLElement2_get_clientHeight(elem, &l);
3111 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
3113 IHTMLElement2_Release(elem);
3116 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
3117 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
3119 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3120 LONG l;
3121 HRESULT hres;
3123 hres = IHTMLElement2_get_clientLeft(elem, &l);
3124 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
3125 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
3127 hres = IHTMLElement2_get_clientTop(elem, &l);
3128 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
3129 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
3131 IHTMLElement2_Release(elem);
3134 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
3135 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
3137 IHTMLFormElement *form = _get_form_iface(line, unk);
3138 LONG len = 0xdeadbeef;
3139 HRESULT hres;
3141 hres = IHTMLFormElement_get_length(form, &len);
3142 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
3143 ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
3145 IHTMLFormElement_Release(form);
3148 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
3149 static void _test_form_action(unsigned line, IUnknown *unk, const char *ex)
3151 IHTMLFormElement *form = _get_form_iface(line, unk);
3152 BSTR action = (void*)0xdeadbeef;
3153 HRESULT hres;
3155 hres = IHTMLFormElement_get_action(form, &action);
3156 ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
3157 if(ex)
3158 ok_(__FILE__,line)(!strcmp_wa(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), ex);
3159 else
3160 ok_(__FILE__,line)(!action, "action=%p\n", action);
3162 SysFreeString(action);
3163 IHTMLFormElement_Release(form);
3166 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
3167 static void _test_form_put_action(unsigned line, IUnknown *unk, const char *action)
3169 IHTMLFormElement *form = _get_form_iface(line, unk);
3170 BSTR tmp = a2bstr(action);
3171 HRESULT hres;
3173 hres = IHTMLFormElement_put_action(form, tmp);
3174 ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
3175 SysFreeString(tmp);
3176 IHTMLFormElement_Release(form);
3178 _test_form_action(line, unk, action);
3181 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
3182 static void _test_form_method(unsigned line, IUnknown *unk, const char *ex)
3184 IHTMLFormElement *form = _get_form_iface(line, unk);
3185 BSTR method = (void*)0xdeadbeef;
3186 HRESULT hres;
3188 hres = IHTMLFormElement_get_method(form, &method);
3189 ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
3190 if(ex)
3191 ok_(__FILE__,line)(!strcmp_wa(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), ex);
3192 else
3193 ok_(__FILE__,line)(!method, "method=%p\n", method);
3195 SysFreeString(method);
3196 IHTMLFormElement_Release(form);
3199 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
3200 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *method)
3202 IHTMLFormElement *form = _get_form_iface(line, unk);
3203 BSTR tmp = a2bstr(method);
3204 HRESULT hres;
3206 hres = IHTMLFormElement_put_method(form, tmp);
3207 ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
3208 SysFreeString(tmp);
3209 IHTMLFormElement_Release(form);
3211 if(exp_hres == S_OK)
3212 _test_form_method(line, unk, method);
3215 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
3216 static void _test_form_name(unsigned line, IUnknown *unk, const char *ex)
3218 IHTMLFormElement *form = _get_form_iface(line, unk);
3219 BSTR name = (void*)0xdeadbeef;
3220 HRESULT hres;
3222 hres = IHTMLFormElement_get_name(form, &name);
3223 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3224 if(ex)
3225 ok_(__FILE__,line)(!strcmp_wa(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), ex);
3226 else
3227 ok_(__FILE__,line)(!name, "name=%p\n", name);
3229 SysFreeString(name);
3230 IHTMLFormElement_Release(form);
3233 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
3234 static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
3236 IHTMLFormElement *form = _get_form_iface(line, unk);
3237 BSTR tmp = a2bstr(name);
3238 HRESULT hres;
3240 hres = IHTMLFormElement_put_name(form, tmp);
3241 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
3242 SysFreeString(tmp);
3243 IHTMLFormElement_Release(form);
3245 _test_form_name(line, unk, name);
3248 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
3249 static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
3251 IHTMLFormElement *form = _get_form_iface(line, unk);
3252 BSTR encoding = (void*)0xdeadbeef;
3253 HRESULT hres;
3255 hres = IHTMLFormElement_get_encoding(form, &encoding);
3256 ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
3257 if(ex)
3258 ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
3259 else
3260 ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
3262 SysFreeString(encoding);
3263 IHTMLFormElement_Release(form);
3266 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
3267 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
3269 IHTMLFormElement *form = _get_form_iface(line, unk);
3270 BSTR tmp = a2bstr(encoding);
3271 HRESULT hres;
3273 hres = IHTMLFormElement_put_encoding(form, tmp);
3274 ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
3275 SysFreeString(tmp);
3276 IHTMLFormElement_Release(form);
3278 if(exp_hres == S_OK)
3279 _test_form_encoding(line, unk, encoding);
3282 #define test_form_elements(a) _test_form_elements(__LINE__,a)
3283 static void _test_form_elements(unsigned line, IUnknown *unk)
3285 IHTMLFormElement *form = _get_form_iface(line, unk);
3286 IDispatch *disp;
3287 HRESULT hres;
3289 disp = NULL;
3290 hres = IHTMLFormElement_get_elements(form, &disp);
3291 ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
3292 ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
3293 ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
3295 IDispatch_Release(disp);
3296 IHTMLFormElement_Release(form);
3299 #define test_meta_name(a,b) _test_meta_name(__LINE__,a,b)
3300 static void _test_meta_name(unsigned line, IUnknown *unk, const char *exname)
3302 IHTMLMetaElement *meta;
3303 BSTR name = NULL;
3304 HRESULT hres;
3307 meta = _get_metaelem_iface(line, unk);
3308 hres = IHTMLMetaElement_get_name(meta, &name);
3309 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3310 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s, expected %s\n", wine_dbgstr_w(name), exname);
3311 SysFreeString(name);
3312 IHTMLMetaElement_Release(meta);
3315 #define test_meta_content(a,b) _test_meta_content(__LINE__,a,b)
3316 static void _test_meta_content(unsigned line, IUnknown *unk, const char *excontent)
3318 IHTMLMetaElement *meta;
3319 BSTR content = NULL;
3320 HRESULT hres;
3323 meta = _get_metaelem_iface(line, unk);
3324 hres = IHTMLMetaElement_get_content(meta, &content);
3325 ok_(__FILE__,line)(hres == S_OK, "get_content failed: %08x\n", hres);
3326 ok_(__FILE__,line)(!strcmp_wa(content, excontent), "content = %s, expected %s\n", wine_dbgstr_w(content), excontent);
3327 SysFreeString(content);
3328 IHTMLMetaElement_Release(meta);
3331 #define test_meta_httpequiv(a,b) _test_meta_httpequiv(__LINE__,a,b)
3332 static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const char *exval)
3334 IHTMLMetaElement *meta;
3335 BSTR val = NULL;
3336 HRESULT hres;
3339 meta = _get_metaelem_iface(line, unk);
3340 hres = IHTMLMetaElement_get_httpEquiv(meta, &val);
3341 ok_(__FILE__,line)(hres == S_OK, "get_httpEquiv failed: %08x\n", hres);
3342 ok_(__FILE__,line)(!strcmp_wa(val, exval), "httpEquiv = %s, expected %s\n", wine_dbgstr_w(val), exval);
3343 SysFreeString(val);
3344 IHTMLMetaElement_Release(meta);
3347 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
3348 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
3350 IHTMLElement *elem = _get_elem_iface(line, unk);
3351 IHTMLDocument2 *doc;
3352 IDispatch *disp;
3353 HRESULT hres;
3355 disp = NULL;
3356 hres = IHTMLElement_get_document(elem, &disp);
3357 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3358 ok(disp != NULL, "disp == NULL\n");
3360 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
3361 IDispatch_Release(disp);
3362 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
3364 return doc;
3367 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
3368 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const char *attr_name, BOOL expect_success)
3370 IHTMLElement4 *elem = _get_elem4_iface(line, unk);
3371 BSTR str = a2bstr(attr_name);
3372 IHTMLDOMAttribute *attr;
3373 HRESULT hres;
3375 attr = (void*)0xdeadbeef;
3376 hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
3377 ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
3378 if(expect_success)
3379 ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
3380 else
3381 ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
3383 IHTMLElement4_Release(elem);
3384 SysFreeString(str);
3385 return attr;
3388 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
3389 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
3391 HRESULT hres;
3393 hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
3394 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3395 ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
3398 #define get_window_doc(e) _get_window_doc(__LINE__,e)
3399 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
3401 IHTMLDocument2 *doc;
3402 HRESULT hres;
3404 doc = NULL;
3405 hres = IHTMLWindow2_get_document(window, &doc);
3406 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3407 ok(doc != NULL, "disp == NULL\n");
3409 return doc;
3412 #define doc_get_body(d) _doc_get_body(__LINE__,d)
3413 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
3415 IHTMLElement *elem;
3416 HRESULT hres;
3418 hres = IHTMLDocument2_get_body(doc, &elem);
3419 ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
3420 ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
3422 return elem;
3425 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
3426 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
3428 IHTMLElement *elem = NULL;
3429 BSTR tmp;
3430 HRESULT hres;
3432 tmp = a2bstr(tag);
3433 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
3434 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3435 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
3436 SysFreeString(tmp);
3438 return elem;
3441 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
3442 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
3444 IHTMLDocument3 *doc3;
3445 IHTMLDOMNode *node = NULL;
3446 BSTR tmp;
3447 HRESULT hres;
3449 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3450 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
3452 tmp = a2bstr(text);
3453 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
3454 IHTMLDocument3_Release(doc3);
3455 SysFreeString(tmp);
3456 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3457 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
3459 return node;
3462 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
3463 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
3465 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3466 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
3467 IHTMLDOMNode *new_child = NULL;
3468 HRESULT hres;
3470 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
3471 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
3472 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3473 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3475 IHTMLDOMNode_Release(node);
3476 IHTMLDOMNode_Release(child);
3478 return new_child;
3481 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
3482 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
3484 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3485 IHTMLDOMNode *new_child = NULL;
3486 HRESULT hres;
3488 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
3489 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
3490 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3491 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3493 IHTMLDOMNode_Release(node);
3495 return new_child;
3498 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
3499 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
3501 IHTMLDOMNode *node = _get_node_iface(line, unk);
3502 IHTMLDOMNode *new_node = NULL;
3503 HRESULT hres;
3505 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
3506 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
3507 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
3508 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
3510 IHTMLDOMNode_Release(node);
3511 IHTMLDOMNode_Release(new_node);
3514 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
3515 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
3517 BSTR title = NULL;
3518 HRESULT hres;
3520 hres = IHTMLDocument2_get_title(doc, &title);
3521 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3522 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3523 SysFreeString(title);
3526 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
3527 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
3529 BSTR tmp;
3530 HRESULT hres;
3532 tmp = a2bstr(title);
3533 hres = IHTMLDocument2_put_title(doc, tmp);
3534 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3535 SysFreeString(tmp);
3538 static void test_elem_bounding_client_rect(IUnknown *unk)
3540 IHTMLRect *rect, *rect2;
3541 IHTMLElement2 *elem2;
3542 LONG l;
3543 HRESULT hres;
3545 elem2 = get_elem2_iface(unk);
3546 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
3547 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3548 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
3549 IHTMLElement2_Release(elem2);
3550 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3551 ok(rect != NULL, "rect == NULL\n");
3552 ok(rect != rect2, "rect == rect2\n");
3553 IHTMLRect_Release(rect2);
3555 test_disp((IUnknown*)rect, &IID_IHTMLRect, "[object]");
3557 l = 0xdeadbeef;
3558 hres = IHTMLRect_get_top(rect, &l);
3559 ok(hres == S_OK, "get_top failed: %08x\n", hres);
3560 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3562 l = 0xdeadbeef;
3563 hres = IHTMLRect_get_left(rect, &l);
3564 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3565 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3567 l = 0xdeadbeef;
3568 hres = IHTMLRect_get_bottom(rect, &l);
3569 ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
3570 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3572 l = 0xdeadbeef;
3573 hres = IHTMLRect_get_right(rect, &l);
3574 ok(hres == S_OK, "get_right failed: %08x\n", hres);
3575 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3577 IHTMLRect_Release(rect);
3580 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
3581 const elem_type_t *elem_types, LONG len)
3583 IDispatch *disp;
3584 VARIANT name, index;
3585 DWORD i;
3586 HRESULT hres;
3588 V_VT(&index) = VT_EMPTY;
3589 V_VT(&name) = VT_BSTR;
3590 V_BSTR(&name) = a2bstr(n);
3592 hres = IHTMLElementCollection_item(col, name, index, &disp);
3593 ok(hres == S_OK, "item failed: %08x\n", hres);
3595 test_elem_collection((IUnknown*)disp, elem_types, len);
3596 IDispatch_Release(disp);
3598 V_VT(&index) = VT_I4;
3600 for(i=0; i<len; i++) {
3601 V_I4(&index) = i;
3602 disp = (void*)0xdeadbeef;
3603 hres = IHTMLElementCollection_item(col, name, index, &disp);
3604 ok(hres == S_OK, "item failed: %08x\n", hres);
3605 ok(disp != NULL, "disp == NULL\n");
3606 if(FAILED(hres) || !disp)
3607 continue;
3609 test_elem_type((IUnknown*)disp, elem_types[i]);
3611 IDispatch_Release(disp);
3614 V_I4(&index) = len;
3615 disp = (void*)0xdeadbeef;
3616 hres = IHTMLElementCollection_item(col, name, index, &disp);
3617 ok(hres == S_OK, "item failed: %08x\n", hres);
3618 ok(disp == NULL, "disp != NULL\n");
3620 V_I4(&index) = -1;
3621 disp = (void*)0xdeadbeef;
3622 hres = IHTMLElementCollection_item(col, name, index, &disp);
3623 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3624 ok(disp == NULL, "disp != NULL\n");
3626 SysFreeString(V_BSTR(&name));
3629 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
3631 IHTMLElementCollection *col;
3632 IHTMLElement *elem;
3633 IDispatch *disp = (void*)0xdeadbeef;
3634 VARIANT name, index;
3635 HRESULT hres;
3637 hres = IHTMLDocument2_get_all(doc, &col);
3638 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3639 ok(col != NULL, "col == NULL\n");
3640 if(FAILED(hres) || !col)
3641 return NULL;
3643 V_VT(&index) = VT_EMPTY;
3644 V_VT(&name) = VT_BSTR;
3645 V_BSTR(&name) = a2bstr(id);
3647 hres = IHTMLElementCollection_item(col, name, index, &disp);
3648 IHTMLElementCollection_Release(col);
3649 SysFreeString(V_BSTR(&name));
3650 ok(hres == S_OK, "item failed: %08x\n", hres);
3651 if(!expect_success) {
3652 ok(disp == NULL, "disp != NULL\n");
3653 return NULL;
3656 ok(disp != NULL, "disp == NULL\n");
3657 if(!disp)
3658 return NULL;
3660 elem = get_elem_iface((IUnknown*)disp);
3661 IDispatch_Release(disp);
3663 return elem;
3666 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
3668 IHTMLDocument3 *doc3;
3669 IHTMLElement *elem;
3670 BSTR tmp;
3671 HRESULT hres;
3673 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3674 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
3676 tmp = a2bstr(id);
3677 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
3678 SysFreeString(tmp);
3679 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
3681 IHTMLDocument3_Release(doc3);
3683 return elem;
3686 static void test_select_elem(IHTMLSelectElement *select)
3688 IDispatch *disp, *disp2;
3689 VARIANT name, index;
3690 HRESULT hres;
3692 test_select_type(select, "select-one");
3693 test_select_length(select, 2);
3694 test_select_selidx(select, 0);
3695 test_select_put_selidx(select, 1);
3697 test_select_set_value(select, "val1");
3698 test_select_value(select, "val1");
3700 test_select_get_disabled(select, VARIANT_FALSE);
3701 test_select_set_disabled(select, VARIANT_TRUE);
3702 test_select_set_disabled(select, VARIANT_FALSE);
3704 disp = NULL;
3705 hres = IHTMLSelectElement_get_options(select, &disp);
3706 ok(hres == S_OK, "get_options failed: %08x\n", hres);
3707 ok(disp != NULL, "options == NULL\n");
3708 ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
3709 IDispatch_Release(disp);
3711 V_VT(&index) = VT_EMPTY;
3712 V_VT(&name) = VT_I4;
3713 V_I4(&name) = -1;
3714 disp = (void*)0xdeadbeef;
3715 hres = IHTMLSelectElement_item(select, name, index, &disp);
3716 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3717 ok(!disp, "disp = %p\n", disp);
3719 V_I4(&name) = 2;
3720 disp = (void*)0xdeadbeef;
3721 hres = IHTMLSelectElement_item(select, name, index, &disp);
3722 ok(hres == S_OK, "item failed: %08x\n", hres);
3723 ok(!disp, "disp = %p\n", disp);
3725 V_I4(&name) = 1;
3726 hres = IHTMLSelectElement_item(select, name, index, NULL);
3727 ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
3729 disp = NULL;
3730 hres = IHTMLSelectElement_item(select, name, index, &disp);
3731 ok(hres == S_OK, "item failed: %08x\n", hres);
3732 ok(disp != NULL, "disp = NULL\n");
3733 test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, NULL);
3735 V_VT(&index) = VT_I4;
3736 V_I4(&index) = 1;
3737 disp2 = NULL;
3738 hres = IHTMLSelectElement_item(select, name, index, &disp2);
3739 ok(hres == S_OK, "item failed: %08x\n", hres);
3740 ok(disp2 != NULL, "disp = NULL\n");
3741 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3742 IDispatch_Release(disp2);
3743 IDispatch_Release(disp);
3746 static void test_form_item(IHTMLElement *elem)
3748 IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
3749 IDispatch *disp, *disp2;
3750 VARIANT name, index;
3751 HRESULT hres;
3753 V_VT(&index) = VT_EMPTY;
3754 V_VT(&name) = VT_I4;
3755 V_I4(&name) = -1;
3756 disp = (void*)0xdeadbeef;
3757 hres = IHTMLFormElement_item(form, name, index, &disp);
3758 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3759 ok(!disp, "disp = %p\n", disp);
3761 V_I4(&name) = 2;
3762 disp = (void*)0xdeadbeef;
3763 hres = IHTMLFormElement_item(form, name, index, &disp);
3764 ok(hres == S_OK, "item failed: %08x\n", hres);
3765 ok(!disp, "disp = %p\n", disp);
3767 V_I4(&name) = 1;
3768 hres = IHTMLFormElement_item(form, name, index, NULL);
3769 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3771 disp = NULL;
3772 hres = IHTMLFormElement_item(form, name, index, &disp);
3773 ok(hres == S_OK, "item failed: %08x\n", hres);
3774 ok(disp != NULL, "disp = NULL\n");
3775 test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, NULL);
3777 V_VT(&index) = VT_I4;
3778 V_I4(&index) = 1;
3779 disp2 = NULL;
3780 hres = IHTMLFormElement_item(form, name, index, &disp2);
3781 ok(hres == S_OK, "item failed: %08x\n", hres);
3782 ok(disp2 != NULL, "disp = NULL\n");
3783 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3784 IDispatch_Release(disp2);
3785 IDispatch_Release(disp);
3788 static void test_create_option_elem(IHTMLDocument2 *doc)
3790 IHTMLOptionElement *option;
3792 option = create_option_elem(doc, "test text", "test value");
3794 test_option_put_text(option, "new text");
3795 test_option_put_value(option, "new value");
3796 test_option_put_selected(option, VARIANT_TRUE);
3797 test_option_put_selected(option, VARIANT_FALSE);
3799 IHTMLOptionElement_Release(option);
3802 static void test_create_img_elem(IHTMLDocument2 *doc)
3804 IHTMLImgElement *img;
3806 img = create_img_elem(doc, 10, 15);
3808 if(img){
3809 test_img_put_width(img, 5);
3810 test_img_put_height(img, 20);
3812 IHTMLImgElement_Release(img);
3813 img = NULL;
3816 img = create_img_elem(doc, -1, -1);
3818 if(img){
3819 test_img_put_width(img, 5);
3820 test_img_put_height(img, 20);
3822 IHTMLImgElement_Release(img);
3826 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
3828 IHTMLBodyElement *body;
3829 IHTMLTxtRange *range;
3830 IHTMLElement *elem;
3831 HRESULT hres;
3833 elem = doc_get_body(doc);
3834 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
3835 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3836 IHTMLElement_Release(elem);
3838 hres = IHTMLBodyElement_createTextRange(body, &range);
3839 IHTMLBodyElement_Release(body);
3840 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
3842 return range;
3845 static void test_txtrange(IHTMLDocument2 *doc)
3847 IHTMLTxtRange *body_range, *range, *range2;
3848 IHTMLSelectionObject *selection;
3849 IDispatch *disp_range;
3850 HRESULT hres;
3852 body_range = test_create_body_range(doc);
3854 test_range_text(body_range, "test abc 123\r\nit's text");
3856 hres = IHTMLTxtRange_duplicate(body_range, &range);
3857 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3859 hres = IHTMLTxtRange_duplicate(body_range, &range2);
3860 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3861 test_range_isequal(range, range2, VARIANT_TRUE);
3863 test_range_text(range, "test abc 123\r\nit's text");
3864 test_range_text(body_range, "test abc 123\r\nit's text");
3866 test_range_collapse(range, TRUE);
3867 test_range_isequal(range, range2, VARIANT_FALSE);
3868 test_range_inrange(range, range2, VARIANT_FALSE);
3869 test_range_inrange(range2, range, VARIANT_TRUE);
3870 IHTMLTxtRange_Release(range2);
3872 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3873 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
3874 test_range_move(range, characterW, 2, 2);
3875 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3877 test_range_collapse(range, FALSE);
3878 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
3880 test_range_collapse(range, FALSE);
3881 test_range_expand(range, wordW, VARIANT_TRUE, "123");
3882 test_range_expand(range, wordW, VARIANT_FALSE, "123");
3883 test_range_move(range, characterW, 2, 2);
3884 test_range_expand(range, wordW, VARIANT_TRUE, "123");
3885 test_range_moveend(range, characterW, -5, -5);
3886 test_range_text(range, NULL);
3887 test_range_moveend(range, characterW, 3, 3);
3888 test_range_text(range, "c 1");
3889 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
3890 test_range_collapse(range, TRUE);
3891 test_range_move(range, characterW, 4, 4);
3892 test_range_moveend(range, characterW, 1, 1);
3893 test_range_text(range, " ");
3894 test_range_move(range, wordW, 1, 1);
3895 test_range_moveend(range, characterW, 2, 2);
3896 test_range_text(range, "ab");
3898 IHTMLTxtRange_Release(range);
3900 hres = IHTMLTxtRange_duplicate(body_range, &range);
3901 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3903 test_range_text(range, "test abc 123\r\nit's text");
3904 test_range_move(range, characterW, 3, 3);
3905 test_range_moveend(range, characterW, 1, 1);
3906 test_range_text(range, "t");
3907 test_range_moveend(range, characterW, 3, 3);
3908 test_range_text(range, "t ab");
3909 test_range_moveend(range, characterW, -2, -2);
3910 test_range_text(range, "t ");
3911 test_range_move(range, characterW, 6, 6);
3912 test_range_moveend(range, characterW, 3, 3);
3913 test_range_text(range, "123");
3914 test_range_moveend(range, characterW, 2, 2);
3915 test_range_text(range, "123\r\ni");
3917 IHTMLTxtRange_Release(range);
3919 hres = IHTMLTxtRange_duplicate(body_range, &range);
3920 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3922 test_range_move(range, wordW, 1, 1);
3923 test_range_moveend(range, characterW, 2, 2);
3924 test_range_text(range, "ab");
3926 test_range_move(range, characterW, -2, -2);
3927 test_range_moveend(range, characterW, 2, 2);
3928 test_range_text(range, "t ");
3930 test_range_move(range, wordW, 3, 3);
3931 test_range_move(range, wordW, -2, -2);
3932 test_range_moveend(range, characterW, 2, 2);
3933 test_range_text(range, "ab");
3935 test_range_move(range, characterW, -6, -5);
3936 test_range_moveend(range, characterW, -1, 0);
3937 test_range_moveend(range, characterW, -6, 0);
3938 test_range_move(range, characterW, 2, 2);
3939 test_range_moveend(range, characterW, 2, 2);
3940 test_range_text(range, "st");
3941 test_range_moveend(range, characterW, -6, -4);
3942 test_range_moveend(range, characterW, 2, 2);
3944 IHTMLTxtRange_Release(range);
3946 hres = IHTMLTxtRange_duplicate(body_range, &range);
3947 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3949 test_range_move(range, wordW, 2, 2);
3950 test_range_moveend(range, characterW, 2, 2);
3951 test_range_text(range, "12");
3953 test_range_move(range, characterW, 15, 14);
3954 test_range_move(range, characterW, -2, -2);
3955 test_range_moveend(range, characterW, 3, 2);
3956 test_range_text(range, "t");
3957 test_range_moveend(range, characterW, -1, -1);
3958 test_range_text(range, "t");
3959 test_range_expand(range, wordW, VARIANT_TRUE, "text");
3960 test_range_move(range, characterW, -2, -2);
3961 test_range_moveend(range, characterW, 2, 2);
3962 test_range_text(range, "s ");
3963 test_range_move(range, characterW, 100, 7);
3964 test_range_move(range, wordW, 1, 0);
3965 test_range_move(range, characterW, -2, -2);
3966 test_range_moveend(range, characterW, 3, 2);
3967 test_range_text(range, "t");
3969 IHTMLTxtRange_Release(range);
3971 hres = IHTMLTxtRange_duplicate(body_range, &range);
3972 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3974 test_range_collapse(range, TRUE);
3975 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3976 test_range_put_text(range, "word");
3977 test_range_text(body_range, "wordabc 123\r\nit's text");
3978 test_range_text(range, NULL);
3979 test_range_moveend(range, characterW, 3, 3);
3980 test_range_text(range, "abc");
3981 test_range_movestart(range, characterW, -2, -2);
3982 test_range_text(range, "rdabc");
3983 test_range_movestart(range, characterW, 3, 3);
3984 test_range_text(range, "bc");
3985 test_range_movestart(range, characterW, 4, 4);
3986 test_range_text(range, NULL);
3987 test_range_movestart(range, characterW, -3, -3);
3988 test_range_text(range, "c 1");
3989 test_range_movestart(range, characterW, -7, -6);
3990 test_range_text(range, "wordabc 1");
3991 test_range_movestart(range, characterW, 100, 22);
3992 test_range_text(range, NULL);
3994 IHTMLTxtRange_Release(range);
3995 IHTMLTxtRange_Release(body_range);
3997 hres = IHTMLDocument2_get_selection(doc, &selection);
3998 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
4000 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
4001 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
4002 IHTMLSelectionObject_Release(selection);
4004 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
4005 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
4006 IDispatch_Release(disp_range);
4008 test_range_text(range, NULL);
4009 test_range_moveend(range, characterW, 3, 3);
4010 test_range_text(range, "wor");
4011 test_range_parent(range, ET_BODY);
4012 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
4013 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
4014 test_range_move(range, characterW, 3, 3);
4015 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
4016 test_range_moveend(range, characterW, -4, -4);
4017 test_range_put_text(range, "abc def ");
4018 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
4019 test_range_move(range, wordW, 1, 1);
4020 test_range_movestart(range, characterW, -1, -1);
4021 test_range_text(range, " ");
4022 test_range_move(range, wordW, 1, 1);
4023 test_range_moveend(range, characterW, 3, 3);
4024 test_range_text(range, "def");
4025 test_range_put_text(range, "xyz");
4026 test_range_moveend(range, characterW, 1, 1);
4027 test_range_move(range, wordW, 1, 1);
4028 test_range_moveend(range, characterW, 2, 2);
4029 test_range_text(range, "ab");
4031 IHTMLTxtRange_Release(range);
4034 static void test_txtrange2(IHTMLDocument2 *doc)
4036 IHTMLTxtRange *range;
4038 range = test_create_body_range(doc);
4040 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
4041 test_range_move(range, characterW, 5, 5);
4042 test_range_moveend(range, characterW, 1, 1);
4043 test_range_text(range, "2");
4044 test_range_move(range, characterW, -3, -3);
4045 test_range_moveend(range, characterW, 3, 3);
4046 test_range_text(range, "c\r\n\r\n1");
4047 test_range_collapse(range, VARIANT_FALSE);
4048 test_range_moveend(range, characterW, 4, 4);
4049 test_range_text(range, "23");
4050 test_range_moveend(range, characterW, 1, 1);
4051 test_range_text(range, "23\r\n\r\n\r\nd");
4052 test_range_moveend(range, characterW, -1, -1);
4053 test_range_text(range, "23");
4054 test_range_moveend(range, characterW, -1, -1);
4055 test_range_text(range, "23");
4056 test_range_moveend(range, characterW, -2, -2);
4057 test_range_text(range, "2");
4059 IHTMLTxtRange_Release(range);
4062 static void test_compatmode(IHTMLDocument2 *doc)
4064 IHTMLDocument5 *doc5;
4065 BSTR mode;
4066 HRESULT hres;
4068 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
4069 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
4070 if(FAILED(hres))
4071 return;
4073 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
4074 IHTMLDocument5_Release(doc5);
4075 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
4076 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
4077 SysFreeString(mode);
4080 static void test_location(IHTMLDocument2 *doc)
4082 IHTMLLocation *location, *location2;
4083 IHTMLWindow2 *window;
4084 BSTR str;
4085 ULONG ref;
4086 HRESULT hres;
4088 hres = IHTMLDocument2_get_location(doc, &location);
4089 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4091 hres = IHTMLDocument2_get_location(doc, &location2);
4092 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4094 ok(location == location2, "location != location2\n");
4095 IHTMLLocation_Release(location2);
4097 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4098 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4100 hres = IHTMLWindow2_get_location(window, &location2);
4101 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4102 ok(location == location2, "location != location2\n");
4103 IHTMLLocation_Release(location2);
4105 test_ifaces((IUnknown*)location, location_iids);
4106 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
4108 hres = IHTMLLocation_get_pathname(location, &str);
4109 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
4110 ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
4111 SysFreeString(str);
4113 hres = IHTMLLocation_get_href(location, NULL);
4114 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
4116 hres = IHTMLLocation_get_href(location, &str);
4117 ok(hres == S_OK, "get_href failed: %08x\n", hres);
4118 ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
4119 SysFreeString(str);
4121 ref = IHTMLLocation_Release(location);
4122 ok(!ref, "location chould be destroyed here\n");
4125 static void test_plugins_col(IHTMLDocument2 *doc)
4127 IHTMLPluginsCollection *col, *col2;
4128 IHTMLWindow2 *window;
4129 IOmNavigator *nav;
4130 ULONG ref;
4131 LONG len;
4132 HRESULT hres;
4134 window = get_doc_window(doc);
4135 hres = IHTMLWindow2_get_navigator(window, &nav);
4136 IHTMLWindow2_Release(window);
4138 hres = IOmNavigator_get_plugins(nav, &col);
4139 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4141 hres = IOmNavigator_get_plugins(nav, &col2);
4142 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4143 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4144 IHTMLPluginsCollection_Release(col2);
4146 test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, "[object]");
4148 len = 0xdeadbeef;
4149 hres = IHTMLPluginsCollection_get_length(col, &len);
4150 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4151 ok(!len, "length = %d\n", len);
4153 ref = IHTMLPluginsCollection_Release(col);
4154 ok(!ref, "ref=%d\n", ref);
4156 IOmNavigator_Release(nav);
4159 static void test_mime_types_col(IOmNavigator *nav)
4161 IHTMLMimeTypesCollection *col, *col2;
4162 LONG length;
4163 ULONG ref;
4164 HRESULT hres;
4166 hres = IOmNavigator_get_mimeTypes(nav, &col);
4167 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4169 hres = IOmNavigator_get_mimeTypes(nav, &col2);
4170 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4171 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4172 IHTMLMimeTypesCollection_Release(col2);
4174 test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, "[object]");
4176 length = 0xdeadbeef;
4177 hres = IHTMLMimeTypesCollection_get_length(col, &length);
4178 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4179 ok(!length, "length = %d\n", length);
4181 ref = IHTMLMimeTypesCollection_Release(col);
4182 ok(!ref, "ref=%d\n", ref);
4185 #define test_framebase_name(a,b) _test_framebase_name(__LINE__,a,b)
4186 static void _test_framebase_name(unsigned line, IHTMLElement *elem, const char *name)
4188 BSTR str = (void*)0xdeadbeef;
4189 IHTMLFrameBase *fbase;
4190 HRESULT hres;
4192 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
4193 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
4195 hres = IHTMLFrameBase_get_name(fbase, &str);
4196 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
4197 if(name)
4198 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
4199 else
4200 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
4201 SysFreeString(str);
4203 IHTMLFrameBase_Release(fbase);
4206 static void test_framebase(IUnknown *unk)
4208 IHTMLFrameBase *fbase;
4209 BSTR str;
4210 HRESULT hres;
4212 /* get/put scrolling */
4213 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFrameBase, (void**)&fbase);
4214 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
4216 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
4217 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
4218 ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
4219 SysFreeString(str);
4221 str = a2bstr("no");
4222 hres = IHTMLFrameBase_put_scrolling(fbase, str);
4223 ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
4224 SysFreeString(str);
4226 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
4227 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
4228 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
4229 SysFreeString(str);
4231 str = a2bstr("junk");
4232 hres = IHTMLFrameBase_put_scrolling(fbase, str);
4233 ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
4234 "with E_INVALIDARG, instead: 0x%08x\n", hres);
4235 SysFreeString(str);
4237 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
4238 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
4239 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
4240 SysFreeString(str);
4242 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
4243 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
4244 ok(!str, "frameBorder = %s\n", wine_dbgstr_w(str));
4246 str = a2bstr("1");
4247 hres = IHTMLFrameBase_put_frameBorder(fbase, str);
4248 ok(hres == S_OK, "put_frameBorder failed: %08x\n", hres);
4249 SysFreeString(str);
4251 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
4252 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
4253 ok(!strcmp_wa(str, "1"), "frameBorder = %s, expected \"1\"\n", wine_dbgstr_w(str));
4255 IHTMLFrameBase_Release(fbase);
4258 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
4259 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
4261 WCHAR buf[64];
4262 int res;
4264 if(pLCIDToLocaleName) {
4265 res = pLCIDToLocaleName(lcid, buf, sizeof(buf)/sizeof(WCHAR), 0);
4266 ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
4267 ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
4268 }else {
4269 win_skip("LCIDToLocaleName not available, unable to test language string\n");
4270 ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
4274 static void test_navigator(IHTMLDocument2 *doc)
4276 IHTMLWindow2 *window;
4277 IOmNavigator *navigator, *navigator2;
4278 char buf[512];
4279 DWORD size;
4280 ULONG ref;
4281 BSTR bstr;
4282 HRESULT hres;
4284 static const WCHAR v40[] = {'4','.','0'};
4286 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4287 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
4289 hres = IHTMLWindow2_get_navigator(window, &navigator);
4290 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4291 ok(navigator != NULL, "navigator == NULL\n");
4292 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
4294 hres = IHTMLWindow2_get_navigator(window, &navigator2);
4295 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4296 ok(navigator != navigator2, "navigator2 != navihgator\n");
4298 IHTMLWindow2_Release(window);
4299 IOmNavigator_Release(navigator2);
4301 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
4302 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
4303 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4304 SysFreeString(bstr);
4306 bstr = NULL;
4307 hres = IOmNavigator_get_appName(navigator, &bstr);
4308 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
4309 ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4310 SysFreeString(bstr);
4312 bstr = NULL;
4313 hres = IOmNavigator_get_platform(navigator, &bstr);
4314 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
4315 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "Win64" : "Win32")
4316 || (sizeof(void*) == 8 && broken(!strcmp_wa(bstr, "Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
4317 SysFreeString(bstr);
4319 bstr = NULL;
4320 hres = IOmNavigator_get_cpuClass(navigator, &bstr);
4321 ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
4322 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "x64" : "x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
4323 SysFreeString(bstr);
4325 bstr = NULL;
4326 hres = IOmNavigator_get_appVersion(navigator, &bstr);
4327 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4328 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
4329 SysFreeString(bstr);
4331 bstr = NULL;
4332 hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
4333 ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
4334 test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
4335 SysFreeString(bstr);
4337 if (pGetUserDefaultUILanguage)
4339 bstr = NULL;
4340 hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
4341 ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
4342 test_language_string(bstr, pGetUserDefaultUILanguage());
4343 SysFreeString(bstr);
4345 else
4346 win_skip("GetUserDefaultUILanguage not available\n");
4348 bstr = NULL;
4349 hres = IOmNavigator_get_userLanguage(navigator, &bstr);
4350 ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
4351 test_language_string(bstr, LOCALE_USER_DEFAULT);
4352 SysFreeString(bstr);
4354 hres = IOmNavigator_toString(navigator, NULL);
4355 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4357 bstr = NULL;
4358 hres = IOmNavigator_toString(navigator, &bstr);
4359 ok(hres == S_OK, "toString failed: %08x\n", hres);
4360 ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
4361 SysFreeString(bstr);
4363 size = sizeof(buf);
4364 hres = ObtainUserAgentString(0, buf, &size);
4365 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
4367 bstr = NULL;
4368 hres = IOmNavigator_get_userAgent(navigator, &bstr);
4369 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
4370 ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
4371 SysFreeString(bstr);
4373 if(!strncmp(buf, "Mozilla/", 8)) {
4374 bstr = NULL;
4375 hres = IOmNavigator_get_appVersion(navigator, &bstr);
4376 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4377 ok(!strcmp_wa(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf+8);
4378 SysFreeString(bstr);
4379 }else {
4380 skip("nonstandard user agent\n");
4383 bstr = NULL;
4384 hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
4385 ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
4386 ok(bstr != NULL, "appMinorVersion returned NULL\n");
4387 SysFreeString(bstr);
4389 test_mime_types_col(navigator);
4391 ref = IOmNavigator_Release(navigator);
4392 ok(!ref, "navigator should be destroyed here\n");
4395 static void test_screen(IHTMLWindow2 *window)
4397 IHTMLScreen *screen, *screen2;
4398 IDispatchEx *dispex;
4399 RECT work_area;
4400 LONG l, exl;
4401 HDC hdc;
4402 HRESULT hres;
4404 screen = NULL;
4405 hres = IHTMLWindow2_get_screen(window, &screen);
4406 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4407 ok(screen != NULL, "screen == NULL\n");
4409 screen2 = NULL;
4410 hres = IHTMLWindow2_get_screen(window, &screen2);
4411 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4412 ok(screen2 != NULL, "screen == NULL\n");
4413 ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
4414 IHTMLScreen_Release(screen2);
4416 hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
4417 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
4418 if(SUCCEEDED(hres)) {
4419 test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
4420 IDispatchEx_Release(dispex);
4423 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
4425 exl = GetDeviceCaps(hdc, HORZRES);
4426 l = 0xdeadbeef;
4427 hres = IHTMLScreen_get_width(screen, &l);
4428 ok(hres == S_OK, "get_width failed: %08x\n", hres);
4429 ok(l == exl, "width = %d, expected %d\n", l, exl);
4431 exl = GetDeviceCaps(hdc, VERTRES);
4432 l = 0xdeadbeef;
4433 hres = IHTMLScreen_get_height(screen, &l);
4434 ok(hres == S_OK, "get_height failed: %08x\n", hres);
4435 ok(l == exl, "height = %d, expected %d\n", l, exl);
4437 exl = GetDeviceCaps(hdc, BITSPIXEL);
4438 l = 0xdeadbeef;
4439 hres = IHTMLScreen_get_colorDepth(screen, &l);
4440 ok(hres == S_OK, "get_height failed: %08x\n", hres);
4441 ok(l == exl, "height = %d, expected %d\n", l, exl);
4443 DeleteObject(hdc);
4445 SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
4447 l = 0xdeadbeef;
4448 hres = IHTMLScreen_get_availHeight(screen, &l);
4449 ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
4450 ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
4452 l = 0xdeadbeef;
4453 hres = IHTMLScreen_get_availWidth(screen, &l);
4454 ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
4455 ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
4457 IHTMLScreen_Release(screen);
4460 static void test_default_selection(IHTMLDocument2 *doc)
4462 IHTMLSelectionObject *selection;
4463 IHTMLTxtRange *range;
4464 IDispatch *disp;
4465 BSTR str;
4466 HRESULT hres;
4468 hres = IHTMLDocument2_get_selection(doc, &selection);
4469 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
4471 hres = IHTMLSelectionObject_get_type(selection, &str);
4472 ok(hres == S_OK, "get_type failed: %08x\n", hres);
4473 ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
4474 SysFreeString(str);
4476 hres = IHTMLSelectionObject_createRange(selection, &disp);
4477 IHTMLSelectionObject_Release(selection);
4478 ok(hres == S_OK, "createRange failed: %08x\n", hres);
4480 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
4481 IDispatch_Release(disp);
4482 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
4484 test_range_text(range, NULL);
4485 IHTMLTxtRange_Release(range);
4488 static void test_doc_elem(IHTMLDocument2 *doc)
4490 IHTMLDocument2 *doc_node, *owner_doc;
4491 IHTMLElement *elem;
4492 IHTMLDocument3 *doc3;
4493 HRESULT hres;
4495 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4496 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
4498 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
4499 IHTMLDocument3_Release(doc3);
4500 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4502 test_node_name((IUnknown*)elem, "HTML");
4503 test_elem_tag((IUnknown*)elem, "HTML");
4505 doc_node = get_doc_node(doc);
4506 owner_doc = get_owner_doc((IUnknown*)elem);
4507 ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
4508 IHTMLDocument2_Release(owner_doc);
4510 owner_doc = get_owner_doc((IUnknown*)doc_node);
4511 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4512 IHTMLDocument2_Release(doc_node);
4514 test_elem_client_rect((IUnknown*)elem);
4516 IHTMLElement_Release(elem);
4519 static void test_default_body(IHTMLBodyElement *body)
4521 LONG l;
4522 BSTR bstr;
4523 HRESULT hres;
4524 VARIANT v;
4526 bstr = (void*)0xdeadbeef;
4527 hres = IHTMLBodyElement_get_background(body, &bstr);
4528 ok(hres == S_OK, "get_background failed: %08x\n", hres);
4529 ok(bstr == NULL, "bstr != NULL\n");
4531 l = elem_get_scroll_height((IUnknown*)body);
4532 ok(l != -1, "scrollHeight == -1\n");
4533 l = elem_get_scroll_width((IUnknown*)body);
4534 ok(l != -1, "scrollWidth == -1\n");
4535 l = elem_get_scroll_top((IUnknown*)body);
4536 ok(!l, "scrollTop = %d\n", l);
4537 elem_get_scroll_left((IUnknown*)body);
4539 /* get_text tests */
4540 hres = IHTMLBodyElement_get_text(body, &v);
4541 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4542 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4543 ok(V_BSTR(&v) == NULL, "bstr != NULL\n");
4545 /* get_text - Invalid Text */
4546 V_VT(&v) = VT_BSTR;
4547 V_BSTR(&v) = a2bstr("Invalid");
4548 hres = IHTMLBodyElement_put_text(body, v);
4549 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4550 VariantClear(&v);
4552 V_VT(&v) = VT_NULL;
4553 hres = IHTMLBodyElement_get_text(body, &v);
4554 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4555 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4556 ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
4557 VariantClear(&v);
4559 /* get_text - Valid Text */
4560 V_VT(&v) = VT_BSTR;
4561 V_BSTR(&v) = a2bstr("#FF0000");
4562 hres = IHTMLBodyElement_put_text(body, v);
4563 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4564 VariantClear(&v);
4566 V_VT(&v) = VT_NULL;
4567 hres = IHTMLBodyElement_get_text(body, &v);
4568 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4569 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4570 ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
4571 VariantClear(&v);
4574 static void test_body_funs(IHTMLBodyElement *body)
4576 VARIANT vbg, vDefaultbg;
4577 HRESULT hres;
4579 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
4580 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4581 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
4582 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
4584 V_VT(&vbg) = VT_BSTR;
4585 V_BSTR(&vbg) = a2bstr("red");
4586 hres = IHTMLBodyElement_put_bgColor(body, vbg);
4587 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4588 VariantClear(&vbg);
4590 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
4591 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4592 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
4593 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
4594 VariantClear(&vbg);
4596 /* Restore Originial */
4597 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
4598 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4599 VariantClear(&vDefaultbg);
4602 static void test_history(IHTMLWindow2 *window)
4604 IOmHistory *history, *history2;
4605 HRESULT hres;
4607 history = NULL;
4608 hres = IHTMLWindow2_get_history(window, &history);
4609 ok(hres == S_OK, "get_history failed: %08x\n", hres);
4610 ok(history != NULL, "history = NULL\n");
4612 test_disp2((IUnknown*)history, &DIID_DispHTMLHistory, &IID_IOmHistory, "[object]");
4614 history2 = NULL;
4615 hres = IHTMLWindow2_get_history(window, &history2);
4616 ok(hres == S_OK, "get_history failed: %08x\n", hres);
4617 ok(history2 != NULL, "history2 = NULL\n");
4618 ok(iface_cmp((IUnknown*)history, (IUnknown*)history2), "history != history2\n");
4620 IOmHistory_Release(history2);
4621 IOmHistory_Release(history);
4624 static void test_window(IHTMLDocument2 *doc)
4626 IHTMLWindow2 *window, *window2, *self, *parent;
4627 IHTMLDocument2 *doc2 = NULL;
4628 IDispatch *disp;
4629 IUnknown *unk;
4630 VARIANT v;
4631 BSTR str;
4632 HRESULT hres;
4634 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4635 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4636 test_ifaces((IUnknown*)window, window_iids);
4637 hres = IDispatch_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
4638 if(hres == S_OK)
4639 IUnknown_Release(unk);
4640 else
4641 win_skip("IID_ITravelLogClient not supported\n");
4643 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
4645 hres = IHTMLWindow2_get_document(window, &doc2);
4646 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4647 ok(doc2 != NULL, "doc2 == NULL\n");
4649 test_ifaces((IUnknown*)doc2, doc_node_iids);
4650 test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4651 test_class_info((IUnknown*)doc2);
4653 test_ifaces((IUnknown*)doc, doc_obj_iids);
4654 test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, "[object]");
4655 test_class_info((IUnknown*)doc);
4657 unk = (void*)0xdeadbeef;
4658 hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
4659 ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
4660 ok(!unk, "unk = %p\n", unk);
4662 IHTMLDocument_Release(doc2);
4664 hres = IHTMLWindow2_get_window(window, &window2);
4665 ok(hres == S_OK, "get_window failed: %08x\n", hres);
4666 ok(window2 != NULL, "window2 == NULL\n");
4668 hres = IHTMLWindow2_get_self(window, &self);
4669 ok(hres == S_OK, "get_self failed: %08x\n", hres);
4670 ok(window2 != NULL, "self == NULL\n");
4672 ok(self == window2, "self != window2\n");
4674 IHTMLWindow2_Release(window2);
4676 disp = NULL;
4677 hres = IHTMLDocument2_get_Script(doc, &disp);
4678 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4679 ok(disp == (void*)window, "disp != window\n");
4680 IDispatch_Release(disp);
4682 hres = IHTMLWindow2_toString(window, NULL);
4683 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4685 str = NULL;
4686 hres = IHTMLWindow2_toString(window, &str);
4687 ok(hres == S_OK, "toString failed: %08x\n", hres);
4688 ok(!strcmp_wa(str, "[object]") ||
4689 !strcmp_wa(str, "[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
4690 SysFreeString(str);
4692 V_VT(&v) = VT_ERROR;
4693 hres = IHTMLWindow2_get_opener(window, &v);
4694 ok(hres == S_OK, "get_opener failed: %08x\n", hres);
4695 ok(V_VT(&v) == VT_EMPTY, "V_VT(opener) = %d\n", V_VT(&v));
4697 parent = NULL;
4698 hres = IHTMLWindow2_get_parent(window, &parent);
4699 ok(hres == S_OK, "get_parent failed: %08x\n", hres);
4700 ok(parent != NULL, "parent == NULL\n");
4701 ok(parent == self, "parent != window\n");
4702 IHTMLWindow2_Release(parent);
4703 IHTMLWindow2_Release(self);
4705 test_window_name(window, NULL);
4706 set_window_name(window, "test");
4707 test_window_length(window, 0);
4708 test_screen(window);
4709 test_window_status(window);
4710 set_window_status(window, "Test!");
4711 test_history(window);
4713 IHTMLWindow2_Release(window);
4716 static void test_defaults(IHTMLDocument2 *doc)
4718 IHTMLStyleSheetsCollection *stylesheetcol;
4719 IHTMLCurrentStyle *cstyle;
4720 IHTMLBodyElement *body;
4721 IHTMLElement2 *elem2;
4722 IHTMLElement *elem;
4723 IHTMLStyle *style;
4724 LONG l;
4725 HRESULT hres;
4726 IHTMLElementCollection *collection;
4728 elem = doc_get_body(doc);
4730 hres = IHTMLDocument2_get_images(doc, NULL);
4731 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4733 hres = IHTMLDocument2_get_images(doc, &collection);
4734 ok(hres == S_OK, "get_images failed: %08x\n", hres);
4735 if(hres == S_OK)
4737 test_elem_collection((IUnknown*)collection, NULL, 0);
4738 IHTMLElementCollection_Release(collection);
4741 hres = IHTMLDocument2_get_applets(doc, NULL);
4742 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4744 hres = IHTMLDocument2_get_applets(doc, &collection);
4745 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4746 if(hres == S_OK)
4748 test_elem_collection((IUnknown*)collection, NULL, 0);
4749 IHTMLElementCollection_Release(collection);
4752 hres = IHTMLDocument2_get_links(doc, NULL);
4753 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4755 hres = IHTMLDocument2_get_links(doc, &collection);
4756 ok(hres == S_OK, "get_links failed: %08x\n", hres);
4757 if(hres == S_OK)
4759 test_elem_collection((IUnknown*)collection, NULL, 0);
4760 IHTMLElementCollection_Release(collection);
4763 hres = IHTMLDocument2_get_forms(doc, NULL);
4764 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4766 hres = IHTMLDocument2_get_forms(doc, &collection);
4767 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4768 if(hres == S_OK)
4770 test_elem_collection((IUnknown*)collection, NULL, 0);
4771 IHTMLElementCollection_Release(collection);
4774 hres = IHTMLDocument2_get_anchors(doc, NULL);
4775 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4777 hres = IHTMLDocument2_get_anchors(doc, &collection);
4778 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4779 if(hres == S_OK)
4781 test_elem_collection((IUnknown*)collection, NULL, 0);
4782 IHTMLElementCollection_Release(collection);
4785 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4786 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
4787 test_default_body(body);
4788 test_body_funs(body);
4789 IHTMLBodyElement_Release(body);
4791 hres = IHTMLElement_get_style(elem, &style);
4792 ok(hres == S_OK, "get_style failed: %08x\n", hres);
4794 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
4795 test_ifaces((IUnknown*)style, style_iids);
4796 IHTMLStyle_Release(style);
4798 test_window(doc);
4799 test_compatmode(doc);
4800 test_location(doc);
4801 test_navigator(doc);
4802 test_plugins_col(doc);
4804 elem2 = get_elem2_iface((IUnknown*)elem);
4805 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
4806 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
4807 if(SUCCEEDED(hres)) {
4808 IUnknown *unk;
4810 test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, "[object]");
4811 test_ifaces((IUnknown*)cstyle, cstyle_iids);
4813 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
4814 if(SUCCEEDED(hres))
4815 IUnknown_Release(unk);
4816 else
4818 /*IE6 doesn't have interface */
4819 win_skip("IID_IHTMLCurrentStyle4 not supported\n");
4822 IHTMLCurrentStyle_Release(cstyle);
4824 IHTMLElement2_Release(elem2);
4826 IHTMLElement_Release(elem);
4828 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
4829 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4831 l = 0xdeadbeef;
4832 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
4833 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4834 ok(l == 0, "length = %d\n", l);
4836 IHTMLStyleSheetsCollection_Release(stylesheetcol);
4838 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
4839 ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
4841 test_default_selection(doc);
4842 test_doc_title(doc, "");
4845 static void test_tr_elem(IHTMLElement *elem)
4847 IHTMLElementCollection *col;
4848 IHTMLTableRow *row;
4849 HRESULT hres;
4851 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
4853 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
4854 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
4855 if(FAILED(hres))
4856 return;
4858 col = NULL;
4859 hres = IHTMLTableRow_get_cells(row, &col);
4860 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
4861 ok(col != NULL, "get_cells returned NULL\n");
4863 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
4864 IHTMLElementCollection_Release(col);
4866 IHTMLTable_Release(row);
4869 static void test_table_elem(IHTMLElement *elem)
4871 IHTMLElementCollection *col;
4872 IHTMLTable *table;
4873 IHTMLDOMNode *node;
4874 HRESULT hres;
4876 static const elem_type_t row_types[] = {ET_TR,ET_TR};
4877 static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
4879 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
4880 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
4881 if(FAILED(hres))
4882 return;
4884 col = NULL;
4885 hres = IHTMLTable_get_rows(table, &col);
4886 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
4887 ok(col != NULL, "get_ros returned NULL\n");
4889 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
4890 IHTMLElementCollection_Release(col);
4892 test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
4894 node = clone_node((IUnknown*)table, VARIANT_TRUE);
4895 test_elem_tag((IUnknown*)node, "TABLE");
4896 test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
4897 IHTMLDOMNode_Release(node);
4899 node = clone_node((IUnknown*)table, VARIANT_FALSE);
4900 test_elem_tag((IUnknown*)node, "TABLE");
4901 test_elem_all((IUnknown*)node, NULL, 0);
4902 IHTMLDOMNode_Release(node);
4904 IHTMLTable_Release(table);
4907 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
4909 SAFEARRAYBOUND dim;
4910 SAFEARRAY *sa;
4911 VARIANT *var;
4912 HRESULT hres;
4914 dim.lLbound = 0;
4915 dim.cElements = 1;
4916 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4917 SafeArrayAccessData(sa, (void**)&var);
4918 V_VT(var) = VT_BSTR;
4919 V_BSTR(var) = a2bstr(text);
4920 SafeArrayUnaccessData(sa);
4922 if(ln)
4923 hres = IHTMLDocument2_writeln(doc, sa);
4924 else
4925 hres = IHTMLDocument2_write(doc, sa);
4926 ok(hres == S_OK, "write failed: %08x\n", hres);
4928 SafeArrayDestroy(sa);
4931 static void doc_complex_write(IHTMLDocument2 *doc)
4933 SAFEARRAYBOUND dim = {5, 0};
4934 SAFEARRAY *sa;
4935 VARIANT *args;
4936 HRESULT hres;
4938 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4939 SafeArrayAccessData(sa, (void**)&args);
4941 V_VT(args) = VT_BSTR;
4942 V_BSTR(args) = a2bstr("<body i4val=\"");
4943 V_VT(args+1) = VT_I4;
4944 V_I4(args+1) = 4;
4945 V_VT(args+2) = VT_BSTR;
4946 V_BSTR(args+2) = a2bstr("\" r8val=\"");
4947 V_VT(args+3) = VT_R8;
4948 V_R8(args+3) = 3.14;
4949 V_VT(args+4) = VT_BSTR;
4950 V_BSTR(args+4) = a2bstr("\">");
4951 SafeArrayUnaccessData(sa);
4953 hres = IHTMLDocument2_write(doc, sa);
4954 ok(hres == S_OK, "write failed: %08x\n", hres);
4956 SafeArrayDestroy(sa);
4959 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
4961 IHTMLDocument2 *window_doc, *elem_doc;
4962 IHTMLFrameElement3 *frame_elem3;
4963 IHTMLWindow2 *content_window;
4964 HRESULT hres;
4966 content_window = get_frame_content_window(frame_elem);
4967 window_doc = get_window_doc(content_window);
4968 IHTMLWindow2_Release(content_window);
4970 elem_doc = get_elem_doc(frame_elem);
4971 ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
4973 if(!iframe) {
4974 hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
4975 if(SUCCEEDED(hres)) {
4976 IDispatch *disp = NULL;
4978 hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
4979 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
4980 ok(disp != NULL, "contentDocument == NULL\n");
4981 ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
4983 IDispatch_Release(disp);
4984 IHTMLFrameElement3_Release(frame_elem3);
4985 }else {
4986 win_skip("IHTMLFrameElement3 not supported\n");
4990 IHTMLDocument2_Release(elem_doc);
4991 IHTMLDocument2_Release(window_doc);
4994 static void test_iframe_elem(IHTMLElement *elem)
4996 IHTMLDocument2 *content_doc, *owner_doc;
4997 IHTMLElementCollection *col;
4998 IHTMLWindow2 *content_window;
4999 IHTMLElement *body;
5000 IDispatch *disp;
5001 VARIANT errv;
5002 BSTR str;
5003 HRESULT hres;
5005 static const elem_type_t all_types[] = {
5006 ET_HTML,
5007 ET_HEAD,
5008 ET_TITLE,
5009 ET_BODY,
5010 ET_BR
5013 test_frame_doc((IUnknown*)elem, TRUE);
5014 test_framebase((IUnknown*)elem);
5016 content_window = get_frame_content_window((IUnknown*)elem);
5017 test_window_length(content_window, 0);
5019 content_doc = get_window_doc(content_window);
5020 IHTMLWindow2_Release(content_window);
5022 str = a2bstr("text/html");
5023 V_VT(&errv) = VT_ERROR;
5024 disp = NULL;
5025 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
5026 SysFreeString(str);
5027 ok(hres == S_OK, "open failed: %08x\n", hres);
5028 ok(disp != NULL, "disp == NULL\n");
5029 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
5030 IDispatch_Release(disp);
5032 doc_write(content_doc, FALSE, "<html><head><title>test</title></head>");
5033 doc_complex_write(content_doc);
5034 doc_write(content_doc, TRUE, "<br />");
5035 doc_write(content_doc, TRUE, "</html>");
5037 hres = IHTMLDocument2_get_all(content_doc, &col);
5038 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5039 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5040 IHTMLElementCollection_Release(col);
5042 body = doc_get_body(content_doc);
5043 test_elem_attr(body, "i4val", "4");
5044 test_elem_attr(body, "r8val", "3.14");
5045 IHTMLElement_Release(body);
5047 hres = IHTMLDocument2_close(content_doc);
5048 ok(hres == S_OK, "close failed: %08x\n", hres);
5050 owner_doc = get_owner_doc((IUnknown*)content_doc);
5051 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5053 IHTMLDocument2_Release(content_doc);
5056 static void test_stylesheet(IDispatch *disp)
5058 IHTMLStyleSheetRulesCollection *col = NULL;
5059 IHTMLStyleSheet *stylesheet;
5060 HRESULT hres;
5062 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
5063 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
5065 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
5066 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
5067 ok(col != NULL, "col == NULL\n");
5069 IHTMLStyleSheetRulesCollection_Release(col);
5070 IHTMLStyleSheet_Release(stylesheet);
5073 static void test_stylesheets(IHTMLDocument2 *doc)
5075 IHTMLStyleSheetsCollection *col = NULL;
5076 VARIANT idx, res;
5077 LONG len = 0;
5078 HRESULT hres;
5080 hres = IHTMLDocument2_get_styleSheets(doc, &col);
5081 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5082 ok(col != NULL, "col == NULL\n");
5084 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
5086 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
5087 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5088 ok(len == 1, "len=%d\n", len);
5090 VariantInit(&res);
5091 V_VT(&idx) = VT_I4;
5092 V_I4(&idx) = 0;
5094 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5095 ok(hres == S_OK, "item failed: %08x\n", hres);
5096 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
5097 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5098 test_stylesheet(V_DISPATCH(&res));
5099 VariantClear(&res);
5101 V_VT(&res) = VT_I4;
5102 V_VT(&idx) = VT_I4;
5103 V_I4(&idx) = 1;
5105 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
5106 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5107 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
5108 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
5109 VariantClear(&res);
5111 IHTMLStyleSheetsCollection_Release(col);
5114 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
5116 IDispatchEx *dispex;
5117 IHTMLDOMNode *node;
5118 DISPPARAMS dp = {NULL, NULL, 0, 0};
5119 VARIANT var;
5120 EXCEPINFO ei;
5121 LONG type;
5122 DISPID id;
5123 BSTR bstr;
5124 HRESULT hres;
5126 static const WCHAR w0[] = {'0',0};
5127 static const WCHAR w100[] = {'1','0','0',0};
5129 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
5130 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
5132 bstr = SysAllocString(w0);
5133 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5134 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5135 SysFreeString(bstr);
5137 VariantInit(&var);
5138 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
5139 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
5140 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
5141 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
5142 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
5143 type = get_node_type((IUnknown*)node);
5144 ok(type == 3, "type=%d\n", type);
5145 IHTMLDOMNode_Release(node);
5146 VariantClear(&var);
5148 bstr = SysAllocString(w100);
5149 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
5150 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
5151 SysFreeString(bstr);
5153 IDispatchEx_Release(dispex);
5158 static void test_elems(IHTMLDocument2 *doc)
5160 IHTMLElementCollection *col;
5161 IHTMLDOMChildrenCollection *child_col;
5162 IHTMLElement *elem, *elem2, *elem3;
5163 IHTMLDOMNode *node, *node2;
5164 IHTMLWindow2 *window;
5165 IDispatch *disp;
5166 LONG type;
5167 HRESULT hres;
5168 IHTMLElementCollection *collection;
5169 IHTMLDocument3 *doc3;
5170 BSTR str;
5172 static const elem_type_t all_types[] = {
5173 ET_HTML,
5174 ET_HEAD,
5175 ET_TITLE,
5176 ET_STYLE,
5177 ET_META,
5178 ET_BODY,
5179 ET_COMMENT,
5180 ET_A,
5181 ET_INPUT,
5182 ET_SELECT,
5183 ET_OPTION,
5184 ET_OPTION,
5185 ET_TEXTAREA,
5186 ET_TABLE,
5187 ET_TBODY,
5188 ET_TR,
5189 ET_TR,
5190 ET_TD,
5191 ET_TD,
5192 ET_SCRIPT,
5193 ET_TEST,
5194 ET_OBJECT,
5195 ET_EMBED,
5196 ET_IMG,
5197 ET_IFRAME,
5198 ET_FORM,
5199 ET_DIV
5202 static const elem_type_t item_types[] = {
5203 ET_A,
5204 ET_OPTION,
5205 ET_TEXTAREA
5208 hres = IHTMLDocument2_get_all(doc, &col);
5209 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5210 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5211 test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
5212 IHTMLElementCollection_Release(col);
5214 hres = IHTMLDocument2_get_images(doc, &collection);
5215 ok(hres == S_OK, "get_images failed: %08x\n", hres);
5216 if(hres == S_OK)
5218 static const elem_type_t images_types[] = {ET_IMG};
5219 test_elem_collection((IUnknown*)collection, images_types, 1);
5221 IHTMLElementCollection_Release(collection);
5224 hres = IHTMLDocument2_get_links(doc, &collection);
5225 ok(hres == S_OK, "get_links failed: %08x\n", hres);
5226 if(hres == S_OK)
5228 static const elem_type_t images_types[] = {ET_A};
5229 test_elem_collection((IUnknown*)collection, images_types, 1);
5231 IHTMLElementCollection_Release(collection);
5234 hres = IHTMLDocument2_get_anchors(doc, &collection);
5235 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
5236 if(hres == S_OK)
5238 static const elem_type_t anchor_types[] = {ET_A};
5239 test_elem_collection((IUnknown*)collection, anchor_types, 1);
5241 IHTMLElementCollection_Release(collection);
5244 test_plugins_col(doc);
5246 elem = get_doc_elem(doc);
5247 test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
5248 IHTMLElement_Release(elem);
5250 get_elem_by_id(doc, "xxx", FALSE);
5251 elem = get_doc_elem_by_id(doc, "xxx");
5252 ok(!elem, "elem != NULL\n");
5254 elem = get_doc_elem_by_id(doc, "s");
5255 ok(elem != NULL, "elem == NULL\n");
5256 if(elem) {
5257 test_elem_type((IUnknown*)elem, ET_SELECT);
5258 test_elem_attr(elem, "xxx", NULL);
5259 test_elem_attr(elem, "id", "s");
5260 test_elem_class((IUnknown*)elem, NULL);
5261 test_elem_set_class((IUnknown*)elem, "cl");
5262 test_elem_set_class((IUnknown*)elem, NULL);
5263 test_elem_tabindex((IUnknown*)elem, 0);
5264 test_elem_set_tabindex((IUnknown*)elem, 1);
5265 test_elem_filters((IUnknown*)elem);
5267 node = test_node_get_parent((IUnknown*)elem);
5268 ok(node != NULL, "node == NULL\n");
5269 test_node_name((IUnknown*)node, "BODY");
5270 node2 = test_node_get_parent((IUnknown*)node);
5271 IHTMLDOMNode_Release(node);
5272 ok(node2 != NULL, "node == NULL\n");
5273 test_node_name((IUnknown*)node2, "HTML");
5274 node = test_node_get_parent((IUnknown*)node2);
5275 IHTMLDOMNode_Release(node2);
5276 ok(node != NULL, "node == NULL\n");
5277 if (node)
5279 test_node_name((IUnknown*)node, "#document");
5280 type = get_node_type((IUnknown*)node);
5281 ok(type == 9, "type=%d, expected 9\n", type);
5282 node2 = test_node_get_parent((IUnknown*)node);
5283 IHTMLDOMNode_Release(node);
5284 ok(node2 == NULL, "node != NULL\n");
5287 elem2 = test_elem_get_parent((IUnknown*)elem);
5288 ok(elem2 != NULL, "elem2 == NULL\n");
5289 test_node_name((IUnknown*)elem2, "BODY");
5290 elem3 = test_elem_get_parent((IUnknown*)elem2);
5291 IHTMLElement_Release(elem2);
5292 ok(elem3 != NULL, "elem3 == NULL\n");
5293 test_node_name((IUnknown*)elem3, "HTML");
5294 elem2 = test_elem_get_parent((IUnknown*)elem3);
5295 IHTMLElement_Release(elem3);
5296 ok(elem2 == NULL, "elem2 != NULL\n");
5298 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
5299 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
5300 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
5302 test_elem_innertext(elem, "opt1opt2");
5304 IHTMLElement_Release(elem);
5307 elem = get_elem_by_id(doc, "s", TRUE);
5308 if(elem) {
5309 IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
5310 IHTMLDocument2 *doc_node, *elem_doc;
5312 test_select_elem(select);
5314 test_elem_title((IUnknown*)select, NULL);
5315 test_elem_set_title((IUnknown*)select, "Title");
5316 test_elem_title((IUnknown*)select, "Title");
5317 test_elem_offset((IUnknown*)select, "BODY");
5318 test_elem_bounding_client_rect((IUnknown*)select);
5320 node = get_first_child((IUnknown*)select);
5321 ok(node != NULL, "node == NULL\n");
5322 if(node) {
5323 test_elem_type((IUnknown*)node, ET_OPTION);
5324 IHTMLDOMNode_Release(node);
5327 type = get_node_type((IUnknown*)select);
5328 ok(type == 1, "type=%d\n", type);
5330 IHTMLSelectElement_Release(select);
5332 elem_doc = get_elem_doc((IUnknown*)elem);
5334 doc_node = get_doc_node(doc);
5335 ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
5336 IHTMLDocument2_Release(doc_node);
5337 IHTMLDocument2_Release(elem_doc);
5339 IHTMLElement_Release(elem);
5342 elem = get_elem_by_id(doc, "sc", TRUE);
5343 if(elem) {
5344 IHTMLScriptElement *script;
5345 BSTR type;
5347 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
5348 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
5350 if(hres == S_OK)
5352 VARIANT_BOOL vb;
5354 hres = IHTMLScriptElement_put_type (script, NULL);
5355 ok(hres == S_OK, "put_type failed: %08x\n", hres);
5356 hres = IHTMLScriptElement_get_type(script, &type);
5357 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5358 ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
5360 hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
5361 ok(hres == S_OK, "put_type failed: %08x\n", hres);
5362 hres = IHTMLScriptElement_get_type(script, &type);
5363 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5364 ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
5366 SysFreeString(type);
5368 /* test defer */
5369 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
5370 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5372 hres = IHTMLScriptElement_get_defer(script, &vb);
5373 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
5374 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
5376 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
5377 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5379 str = (BSTR)0xdeadbeef;
5380 hres = IHTMLScriptElement_get_src(script, &str);
5381 ok(hres == S_OK, "get_src failed: %08x\n", hres);
5382 ok(!str, "src = %s\n", wine_dbgstr_w(str));
5385 IHTMLScriptElement_Release(script);
5388 elem = get_elem_by_id(doc, "in", TRUE);
5389 if(elem) {
5390 IHTMLInputElement *input;
5392 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
5393 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
5395 test_elem_id((IUnknown*)elem, "in");
5396 test_elem_put_id((IUnknown*)elem, "newin");
5397 test_input_get_disabled(input, VARIANT_FALSE);
5398 test_input_set_disabled(input, VARIANT_TRUE);
5399 test_input_set_disabled(input, VARIANT_FALSE);
5400 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
5401 test_input_get_disabled(input, VARIANT_TRUE);
5402 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
5403 test_input_get_disabled(input, VARIANT_FALSE);
5404 test_elem_client_size((IUnknown*)elem);
5405 test_input_type(input, "text");
5407 test_node_get_value_str((IUnknown*)elem, NULL);
5408 test_node_put_value_str((IUnknown*)elem, "test");
5409 test_node_get_value_str((IUnknown*)elem, NULL);
5410 test_input_value((IUnknown*)elem, NULL);
5411 test_input_put_value((IUnknown*)elem, "test");
5412 test_elem_class((IUnknown*)elem, "testclass");
5413 test_elem_tabindex((IUnknown*)elem, 2);
5414 test_elem_set_tabindex((IUnknown*)elem, 3);
5415 test_elem_title((IUnknown*)elem, "test title");
5417 test_input_get_defaultchecked(input, VARIANT_FALSE);
5418 test_input_set_defaultchecked(input, VARIANT_TRUE);
5419 test_input_set_defaultchecked(input, VARIANT_FALSE);
5421 test_input_get_checked(input, VARIANT_FALSE);
5422 test_input_set_checked(input, VARIANT_TRUE);
5423 test_input_set_checked(input, VARIANT_FALSE);
5425 test_input_maxlength(input, 0x7fffffff);
5426 test_input_set_maxlength(input, 30);
5428 test_input_name(input, NULL);
5429 test_input_set_name(input, "test");
5431 test_input_src(input, NULL);
5432 test_input_set_src(input, "about:blank");
5434 IHTMLInputElement_Release(input);
5435 IHTMLElement_Release(elem);
5438 elem = get_elem_by_id(doc, "imgid", TRUE);
5439 if(elem) {
5440 test_img_src((IUnknown*)elem, "", NULL);
5441 test_img_set_src((IUnknown*)elem, "about:blank");
5442 test_img_src((IUnknown*)elem, "about:blank", NULL);
5443 test_img_alt((IUnknown*)elem, NULL);
5444 test_img_set_alt((IUnknown*)elem, "alt test");
5445 test_img_name((IUnknown*)elem, "WineImg");
5446 IHTMLElement_Release(elem);
5449 elem = get_elem_by_id(doc, "attr", TRUE);
5450 if(elem) {
5451 test_dynamic_properties(elem);
5452 test_attr_collection(elem);
5453 IHTMLElement_Release(elem);
5456 elem = get_elem_by_id(doc, "styleid", TRUE);
5457 if(elem) {
5458 test_style_media((IUnknown*)elem, NULL);
5459 test_style_put_media((IUnknown*)elem, "screen");
5460 test_style_type((IUnknown*)elem, NULL);
5461 test_style_put_type((IUnknown*)elem, "text/css");
5462 IHTMLElement_Release(elem);
5465 elem = get_doc_elem_by_id(doc, "tbl");
5466 ok(elem != NULL, "elem == NULL\n");
5467 if(elem) {
5468 test_table_elem(elem);
5469 IHTMLElement_Release(elem);
5472 elem = get_doc_elem_by_id(doc, "row2");
5473 ok(elem != NULL, "elem == NULL\n");
5474 if(elem) {
5475 test_tr_elem(elem);
5476 IHTMLElement_Release(elem);
5479 elem = get_doc_elem_by_id(doc, "ifr");
5480 ok(elem != NULL, "elem == NULL\n");
5481 if(elem) {
5482 test_iframe_elem(elem);
5483 IHTMLElement_Release(elem);
5486 elem = get_doc_elem_by_id(doc, "objid");
5487 ok(elem != NULL, "elem == NULL\n");
5488 if(elem) {
5489 test_object_vspace((IUnknown*)elem, 100);
5490 IHTMLElement_Release(elem);
5493 elem = get_elem_by_id(doc, "a", TRUE);
5494 if(elem) {
5495 test_anchor_href((IUnknown*)elem, "http://test/");
5497 /* Change the href */
5498 test_anchor_put_href((IUnknown*)elem, "http://test1/");
5499 test_anchor_href((IUnknown*)elem, "http://test1/");
5501 /* Restore the href */
5502 test_anchor_put_href((IUnknown*)elem, "http://test/");
5503 test_anchor_href((IUnknown*)elem, "http://test/");
5505 /* target */
5506 test_anchor_get_target((IUnknown*)elem, NULL);
5508 /* Change the target */
5509 test_anchor_put_target((IUnknown*)elem, "wine");
5510 test_anchor_get_target((IUnknown*)elem, "wine");
5512 /* Restore the target */
5513 test_anchor_put_target((IUnknown*)elem, NULL);
5514 test_anchor_get_target((IUnknown*)elem, NULL);
5516 test_anchor_name((IUnknown*)elem, "x");
5517 test_anchor_put_name((IUnknown*)elem, "anchor name");
5518 test_anchor_put_name((IUnknown*)elem, NULL);
5519 test_anchor_put_name((IUnknown*)elem, "x");
5521 IHTMLElement_Release(elem);
5524 elem = get_doc_elem_by_id(doc, "metaid");
5525 if(elem) {
5526 test_meta_name((IUnknown*)elem, "meta name");
5527 test_meta_content((IUnknown*)elem, "text/html; charset=utf-8");
5528 test_meta_httpequiv((IUnknown*)elem, "Content-Type");
5529 IHTMLElement_Release(elem);
5532 elem = doc_get_body(doc);
5534 node = get_first_child((IUnknown*)elem);
5535 ok(node != NULL, "node == NULL\n");
5536 if(node) {
5537 test_ifaces((IUnknown*)node, text_iids);
5538 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5540 node2 = get_first_child((IUnknown*)node);
5541 ok(!node2, "node2 != NULL\n");
5543 type = get_node_type((IUnknown*)node);
5544 ok(type == 3, "type=%d\n", type);
5546 test_node_get_value_str((IUnknown*)node, "text test");
5547 test_node_put_value_str((IUnknown*)elem, "test text");
5548 test_node_get_value_str((IUnknown*)node, "text test");
5550 hres = IHTMLDOMNode_get_attributes(node, &disp);
5551 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
5552 ok(!disp, "disp != NULL\n");
5554 IHTMLDOMNode_Release(node);
5557 child_col = get_child_nodes((IUnknown*)elem);
5558 ok(child_col != NULL, "child_coll == NULL\n");
5559 if(child_col) {
5560 LONG length = 0;
5562 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
5564 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
5565 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5566 ok(length, "length=0\n");
5568 node2 = NULL;
5569 node = get_child_item(child_col, 0);
5570 ok(node != NULL, "node == NULL\n");
5571 if(node) {
5572 IHTMLDOMNode *prev;
5574 type = get_node_type((IUnknown*)node);
5575 ok(type == 3, "type=%d\n", type);
5576 node2 = node_get_next((IUnknown*)node);
5578 prev = node_get_prev((IUnknown*)node2);
5579 ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
5580 IHTMLDOMNode_Release(prev);
5582 IHTMLDOMNode_Release(node);
5585 node = get_child_item(child_col, 1);
5586 ok(node != NULL, "node == NULL\n");
5587 if(node) {
5588 type = get_node_type((IUnknown*)node);
5589 ok(type == 8, "type=%d\n", type);
5591 test_elem_id((IUnknown*)node, NULL);
5592 ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
5593 IHTMLDOMNode_Release(node2);
5594 IHTMLDOMNode_Release(node);
5597 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
5598 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5600 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
5601 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5603 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
5604 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5606 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
5607 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5609 test_child_col_disp(child_col);
5611 IHTMLDOMChildrenCollection_Release(child_col);
5614 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
5615 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
5616 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
5618 IHTMLElement_Release(elem);
5620 elem = get_doc_elem_by_id(doc, "frm");
5621 ok(elem != NULL, "elem == NULL\n");
5622 if(elem) {
5623 test_form_length((IUnknown*)elem, 0);
5624 test_form_elements((IUnknown*)elem);
5625 IHTMLElement_Release(elem);
5628 test_stylesheets(doc);
5629 test_create_option_elem(doc);
5630 test_create_img_elem(doc);
5632 elem = get_doc_elem_by_id(doc, "tbl");
5633 ok(elem != NULL, "elem = NULL\n");
5634 test_elem_set_innertext(elem, "inner text");
5635 IHTMLElement_Release(elem);
5637 test_doc_title(doc, "test");
5638 test_doc_set_title(doc, "test title");
5639 test_doc_title(doc, "test title");
5641 disp = NULL;
5642 hres = IHTMLDocument2_get_Script(doc, &disp);
5643 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5644 if(hres == S_OK)
5646 IDispatchEx *dispex;
5647 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
5648 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
5649 if(hres == S_OK)
5651 DISPID pid = -1;
5652 BSTR str = a2bstr("Testing");
5653 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
5654 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5655 ok(pid != -1, "pid == -1\n");
5656 SysFreeString(str);
5657 IDispatchEx_Release(dispex);
5660 IDispatch_Release(disp);
5662 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5663 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5665 str = a2bstr("img");
5666 hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
5667 ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
5668 SysFreeString(str);
5669 if(hres == S_OK)
5671 static const elem_type_t img_types[] = { ET_IMG };
5673 test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
5674 IHTMLElementCollection_Release(col);
5677 elem = get_doc_elem_by_id(doc, "y");
5678 test_elem_set_innerhtml((IUnknown*)elem, "inner html");
5679 test_elem_innerhtml((IUnknown*)elem, "inner html");
5680 test_elem_set_innerhtml((IUnknown*)elem, "");
5681 test_elem_innerhtml((IUnknown*)elem, NULL);
5682 node = node_get_next((IUnknown*)elem);
5683 ok(!node, "node = %p\n", node);
5685 elem2 = get_doc_elem_by_id(doc, "x");
5686 test_elem_tag((IUnknown*)elem2, "A");
5687 node = node_get_next((IUnknown*)elem2);
5688 IHTMLDOMNode_Release(node);
5689 IHTMLElement_Release(elem2);
5690 IHTMLElement_Release(elem);
5692 IHTMLDocument3_Release(doc3);
5694 elem = get_elem_by_id(doc, "s", TRUE);
5695 if(elem) {
5696 static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
5698 test_select_put_length((IUnknown*)elem, 3);
5699 test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
5700 test_select_put_length((IUnknown*)elem, 1);
5701 test_elem_all((IUnknown*)elem, select_types, 1);
5702 IHTMLElement_Release(elem);
5705 window = get_doc_window(doc);
5706 test_window_name(window, NULL);
5707 set_window_name(window, "test name");
5708 test_window_length(window, 1);
5709 IHTMLWindow2_Release(window);
5712 static void test_attr(IHTMLElement *elem)
5714 IHTMLDOMAttribute *attr, *attr2;
5715 VARIANT v;
5717 get_elem_attr_node((IUnknown*)elem, "noattr", FALSE);
5719 attr = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5721 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
5722 test_ifaces((IUnknown*)attr, attr_iids);
5723 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
5725 attr2 = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5726 ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
5727 IHTMLDOMAttribute_Release(attr2);
5729 get_attr_node_value(attr, &v, VT_BSTR);
5730 ok(!strcmp_wa(V_BSTR(&v), "divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5731 VariantClear(&v);
5733 IHTMLDOMAttribute_Release(attr);
5735 attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
5736 get_attr_node_value(attr, &v, VT_BSTR);
5737 ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5738 VariantClear(&v);
5739 IHTMLDOMAttribute_Release(attr);
5741 V_VT(&v) = VT_I4;
5742 V_I4(&v) = 100;
5743 set_dispex_value((IUnknown*)elem, "dispprop", &v);
5744 attr = get_elem_attr_node((IUnknown*)elem, "dispprop", TRUE);
5745 get_attr_node_value(attr, &v, VT_I4);
5746 ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
5747 IHTMLDOMAttribute_Release(attr);
5750 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
5752 IHTMLElement *elem;
5754 test_elem_set_innerhtml((IUnknown*)outer_elem,
5755 "<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
5756 elem = get_elem_by_id(doc, "imgid", TRUE);
5757 if(elem) {
5758 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5759 IHTMLElement_Release(elem);
5762 test_elem_set_innerhtml((IUnknown*)outer_elem,
5763 "<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
5764 elem = get_elem_by_id(doc, "imgid", TRUE);
5765 if(elem) {
5766 test_img_src((IUnknown*)elem, "blocke::http://www.winehq.org/img.png", NULL);
5767 test_img_set_src((IUnknown*)elem, "BLOCKED:http://www.winehq.org/img.png");
5768 test_img_src((IUnknown*)elem, "blocked:http://www.winehq.org/img.png", NULL);
5769 test_img_set_src((IUnknown*)elem, "blocked::http://www.winehq.org/img.png");
5770 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5771 IHTMLElement_Release(elem);
5775 static void test_elems2(IHTMLDocument2 *doc)
5777 IHTMLElement *elem, *elem2, *div;
5779 static const elem_type_t outer_types[] = {
5780 ET_BR,
5781 ET_A
5784 div = get_doc_elem_by_id(doc, "divid");
5786 test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
5787 elem2 = get_doc_elem_by_id(doc, "innerid");
5788 ok(elem2 != NULL, "elem2 == NULL\n");
5789 test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
5790 test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
5791 IHTMLElement_Release(elem2);
5793 elem2 = get_doc_elem_by_id(doc, "aid");
5794 ok(elem2 != NULL, "elem2 == NULL\n");
5795 test_elem_set_outerhtml((IUnknown*)elem2, "");
5796 test_elem_all((IUnknown*)div, outer_types, 1);
5797 IHTMLElement_Release(elem2);
5799 test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
5800 elem = get_elem_by_id(doc, "ta", TRUE);
5801 if(elem) {
5802 test_textarea_value((IUnknown*)elem, NULL);
5803 test_textarea_put_value((IUnknown*)elem, "test");
5804 test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
5805 test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
5806 test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
5807 test_textarea_type((IUnknown*)elem);
5808 IHTMLElement_Release(elem);
5811 test_elem_set_innerhtml((IUnknown*)div,
5812 "<form id=\"form\"><input type=\"button\" /><div><input type=\"text\" /></div></textarea>");
5813 elem = get_elem_by_id(doc, "form", TRUE);
5814 if(elem) {
5815 test_form_length((IUnknown*)elem, 2);
5816 test_form_item(elem);
5817 test_form_action((IUnknown*)elem, NULL);
5818 test_form_put_action((IUnknown*)elem, "about:blank");
5819 test_form_method((IUnknown*)elem, "get");
5820 test_form_put_method((IUnknown*)elem, S_OK, "post");
5821 test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
5822 test_form_method((IUnknown*)elem, "post");
5823 test_form_name((IUnknown*)elem, NULL);
5824 test_form_put_name((IUnknown*)elem, "Name");
5825 test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
5826 test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
5827 test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
5828 test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
5829 test_form_encoding((IUnknown*)elem, "multipart/form-data");
5830 test_form_elements((IUnknown*)elem);
5831 IHTMLElement_Release(elem);
5834 test_attr(div);
5835 test_blocked(doc, div);
5837 IHTMLElement_Release(div);
5840 static void test_create_elems(IHTMLDocument2 *doc)
5842 IHTMLElement *elem, *body, *elem2;
5843 IHTMLDOMNode *node, *node2, *node3, *comment;
5844 IHTMLDocument5 *doc5;
5845 IDispatch *disp;
5846 VARIANT var;
5847 LONG type;
5848 HRESULT hres;
5849 BSTR str;
5851 static const elem_type_t types1[] = { ET_TESTG };
5853 elem = test_create_elem(doc, "TEST");
5854 test_elem_tag((IUnknown*)elem, "TEST");
5855 type = get_node_type((IUnknown*)elem);
5856 ok(type == 1, "type=%d\n", type);
5857 test_ifaces((IUnknown*)elem, elem_iids);
5858 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
5860 body = doc_get_body(doc);
5861 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5863 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
5864 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
5865 elem2 = get_elem_iface((IUnknown*)node);
5866 IHTMLElement_Release(elem2);
5868 hres = IHTMLElement_get_all(body, &disp);
5869 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5870 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
5871 IDispatch_Release(disp);
5873 test_node_remove_child((IUnknown*)body, node);
5875 hres = IHTMLElement_get_all(body, &disp);
5876 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5877 test_elem_collection((IUnknown*)disp, NULL, 0);
5878 IDispatch_Release(disp);
5879 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5881 IHTMLElement_Release(elem);
5882 IHTMLDOMNode_Release(node);
5884 node = test_create_text(doc, "test");
5885 test_ifaces((IUnknown*)node, text_iids);
5886 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5887 test_text_length((IUnknown*)node, 4);
5889 V_VT(&var) = VT_NULL;
5890 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5891 IHTMLDOMNode_Release(node);
5893 node = test_create_text(doc, "insert ");
5895 V_VT(&var) = VT_DISPATCH;
5896 V_DISPATCH(&var) = (IDispatch*)node2;
5897 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
5898 IHTMLDOMNode_Release(node);
5899 IHTMLDOMNode_Release(node2);
5900 IHTMLDOMNode_Release(node3);
5902 test_elem_innertext(body, "insert test");
5903 test_elem_innerhtml((IUnknown*)body, "insert test");
5905 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
5906 if(hres == S_OK)
5908 str = a2bstr("testing");
5909 hres = IHTMLDocument5_createComment(doc5, str, &comment);
5910 SysFreeString(str);
5911 ok(hres == S_OK, "createComment failed: %08x\n", hres);
5912 if(hres == S_OK)
5914 type = get_node_type((IUnknown*)comment);
5915 ok(type == 8, "type=%d, expected 8\n", type);
5917 test_node_get_value_str((IUnknown*)comment, "testing");
5918 test_elem_title((IUnknown*)comment, NULL);
5919 test_elem_set_title((IUnknown*)comment, "comment title");
5920 test_elem_title((IUnknown*)comment, "comment title");
5921 test_comment_text((IUnknown*)comment, "<!--testing-->");
5922 test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
5923 test_comment_attrs((IUnknown*)comment);
5925 IHTMLDOMNode_Release(comment);
5928 IHTMLDocument5_Release(doc5);
5931 IHTMLElement_Release(body);
5934 static void test_replacechild_elems(IHTMLDocument2 *doc)
5936 IHTMLElement *body;
5937 IHTMLDOMNode *node, *node2, *node3;
5938 IHTMLDOMNode *nodeBody, *nodeNew;
5939 HRESULT hres;
5940 VARIANT var;
5942 body = doc_get_body(doc);
5944 node = test_create_text(doc, "insert");
5946 V_VT(&var) = VT_NULL;
5947 V_DISPATCH(&var) = NULL;
5948 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5949 IHTMLDOMNode_Release(node);
5951 test_elem_innertext(body, "insert");
5953 node3 = test_create_text(doc, "replaced");
5955 nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
5957 hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
5958 ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
5960 test_elem_innertext(body, "replaced");
5962 IHTMLDOMNode_Release(node2);
5963 IHTMLDOMNode_Release(node3);
5964 IHTMLDOMNode_Release(nodeBody);
5966 IHTMLElement_Release(body);
5969 static void test_null_write(IHTMLDocument2 *doc)
5971 HRESULT hres;
5973 doc_write(doc, FALSE, NULL);
5974 doc_write(doc, TRUE, NULL);
5976 hres = IHTMLDocument2_write(doc, NULL);
5977 ok(hres == S_OK,
5978 "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
5980 hres = IHTMLDocument2_writeln(doc, NULL);
5981 ok(hres == S_OK,
5982 "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
5985 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
5987 IOleCommandTarget *cmdtrg;
5988 HRESULT hres;
5990 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
5991 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
5993 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
5994 ok(hres == S_OK, "Exec failed: %08x\n", hres);
5996 IOleCommandTarget_Release(cmdtrg);
5999 static void test_indent(IHTMLDocument2 *doc)
6001 IHTMLElementCollection *col;
6002 IHTMLTxtRange *range;
6003 HRESULT hres;
6005 static const elem_type_t all_types[] = {
6006 ET_HTML,
6007 ET_HEAD,
6008 ET_TITLE,
6009 ET_BODY,
6010 ET_BR,
6011 ET_A,
6014 static const elem_type_t indent_types[] = {
6015 ET_HTML,
6016 ET_HEAD,
6017 ET_TITLE,
6018 ET_BODY,
6019 ET_BLOCKQUOTE,
6020 ET_P,
6021 ET_BR,
6022 ET_A,
6025 hres = IHTMLDocument2_get_all(doc, &col);
6026 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6027 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6028 IHTMLElementCollection_Release(col);
6030 range = test_create_body_range(doc);
6031 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
6032 IHTMLTxtRange_Release(range);
6034 hres = IHTMLDocument2_get_all(doc, &col);
6035 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6036 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
6037 IHTMLElementCollection_Release(col);
6040 static void test_cond_comment(IHTMLDocument2 *doc)
6042 IHTMLElementCollection *col;
6043 HRESULT hres;
6045 static const elem_type_t all_types[] = {
6046 ET_HTML,
6047 ET_HEAD,
6048 ET_TITLE,
6049 ET_BODY,
6050 ET_BR
6053 hres = IHTMLDocument2_get_all(doc, &col);
6054 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6055 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6056 IHTMLElementCollection_Release(col);
6059 static void test_frame(IDispatch *disp, const char *exp_id)
6061 IHTMLWindow2 *frame2, *parent, *top;
6062 IHTMLDocument2 *parent_doc, *top_doc;
6063 IHTMLWindow4 *frame;
6064 IHTMLFrameBase *frame_elem;
6065 HRESULT hres;
6067 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
6068 ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
6069 if(FAILED(hres))
6070 return;
6072 hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
6073 ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
6074 IHTMLWindow4_Release(frame);
6075 if(FAILED(hres))
6076 return;
6078 test_elem_type((IUnknown*)frame_elem, ET_FRAME);
6079 test_frame_doc((IUnknown*)frame_elem, FALSE);
6080 test_elem_id((IUnknown*)frame_elem, exp_id);
6081 IHTMLElement_Release(frame_elem);
6083 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
6084 ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
6085 if(FAILED(hres))
6086 return;
6088 hres = IHTMLWindow2_get_parent(frame2, &parent);
6089 ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
6090 if(FAILED(hres)){
6091 IHTMLWindow2_Release(frame2);
6092 return;
6095 hres = IHTMLWindow2_get_document(parent, &parent_doc);
6096 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
6097 IHTMLWindow2_Release(parent);
6098 if(FAILED(hres)){
6099 IHTMLWindow2_Release(frame2);
6100 return;
6103 test_doc_title(parent_doc, "frameset test");
6104 IHTMLDocument2_Release(parent_doc);
6106 /* test get_top */
6107 hres = IHTMLWindow2_get_top(frame2, &top);
6108 ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
6109 IHTMLWindow2_Release(frame2);
6110 if(FAILED(hres))
6111 return;
6113 hres = IHTMLWindow2_get_document(top, &top_doc);
6114 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
6115 IHTMLWindow2_Release(top);
6116 if(FAILED(hres))
6117 return;
6119 test_doc_title(top_doc, "frameset test");
6120 IHTMLDocument2_Release(top_doc);
6123 static void test_frames_collection(IHTMLFramesCollection2 *frames, const char *frid)
6125 VARIANT index_var, result_var;
6126 LONG length;
6127 HRESULT hres;
6129 /* test result length */
6130 hres = IHTMLFramesCollection2_get_length(frames, &length);
6131 ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
6132 ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
6134 /* test first frame */
6135 V_VT(&index_var) = VT_I4;
6136 V_I4(&index_var) = 0;
6137 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6138 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6139 if(SUCCEEDED(hres)) {
6140 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6141 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
6143 VariantClear(&result_var);
6145 /* test second frame */
6146 V_I4(&index_var) = 1;
6147 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6148 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6149 if(SUCCEEDED(hres)) {
6150 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6151 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
6153 VariantClear(&result_var);
6155 /* fail on next frame */
6156 V_I4(&index_var) = 3;
6157 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6158 ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
6159 "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
6160 VariantClear(&result_var);
6162 /* string argument (element id lookup) */
6163 V_VT(&index_var) = VT_BSTR;
6164 V_BSTR(&index_var) = a2bstr(frid);
6165 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6166 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
6167 if(SUCCEEDED(hres)) {
6168 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
6169 test_frame(V_DISPATCH(&result_var), frid);
6171 VariantClear(&result_var);
6172 VariantClear(&index_var);
6174 /* invalid argument */
6175 V_VT(&index_var) = VT_BOOL;
6176 V_BOOL(&index_var) = VARIANT_TRUE;
6177 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
6178 ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
6179 "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
6180 VariantClear(&result_var);
6183 static void test_frameset(IHTMLDocument2 *doc)
6185 IHTMLWindow2 *window;
6186 IHTMLFramesCollection2 *frames;
6187 IHTMLElement *elem;
6188 HRESULT hres;
6190 window = get_doc_window(doc);
6192 /* test using IHTMLFramesCollection object */
6194 hres = IHTMLWindow2_get_frames(window, &frames);
6195 ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
6196 if(FAILED(hres))
6197 return;
6199 test_frames_collection(frames, "fr1");
6200 IHTMLFramesCollection2_Release(frames);
6202 hres = IHTMLDocument2_get_frames(doc, &frames);
6203 ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
6204 if(FAILED(hres))
6205 return;
6207 test_frames_collection(frames, "fr1");
6208 IHTMLFramesCollection2_Release(frames);
6210 /* test using IHTMLWindow2 inheritance */
6211 test_frames_collection((IHTMLFramesCollection2*)window, "fr2");
6213 /* getElementById with node name attributes */
6214 elem = get_doc_elem_by_id(doc, "nm1");
6215 test_elem_id((IUnknown*)elem, "fr1");
6217 test_framebase((IUnknown*)elem);
6218 test_framebase_name(elem, "nm1");
6220 IHTMLElement_Release(elem);
6222 /* get_name with no name attr */
6223 elem = get_doc_elem_by_id(doc, "fr3");
6224 test_framebase_name(elem, NULL);
6225 IHTMLElement_Release(elem);
6227 IHTMLWindow2_Release(window);
6230 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
6232 IHTMLDocument2 *frag;
6233 IHTMLDocument3 *doc3;
6234 HRESULT hres;
6236 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
6237 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
6239 hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
6240 IHTMLDocument3_Release(doc3);
6241 ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
6242 ok(frag != NULL, "frag == NULL\n");
6244 return frag;
6247 static void test_docfrag(IHTMLDocument2 *doc)
6249 IHTMLElement *div, *body, *br;
6250 IHTMLElementCollection *col;
6251 IHTMLLocation *location;
6252 IHTMLDocument2 *frag;
6253 HRESULT hres;
6255 static const elem_type_t all_types[] = {
6256 ET_HTML,
6257 ET_HEAD,
6258 ET_TITLE,
6259 ET_BODY,
6260 ET_DIV,
6261 ET_BR
6264 frag = create_docfrag(doc);
6266 test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
6268 body = (void*)0xdeadbeef;
6269 hres = IHTMLDocument2_get_body(frag, &body);
6270 ok(hres == S_OK, "get_body failed: %08x\n", hres);
6271 ok(!body, "body != NULL\n");
6273 location = (void*)0xdeadbeef;
6274 hres = IHTMLDocument2_get_location(frag, &location);
6275 ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
6276 ok(location == (void*)0xdeadbeef, "location changed\n");
6278 br = test_create_elem(doc, "BR");
6279 test_node_append_child((IUnknown*)frag, (IUnknown*)br);
6280 IHTMLElement_Release(br);
6282 div = get_elem_by_id(doc, "divid", TRUE);
6283 test_node_append_child((IUnknown*)div, (IUnknown*)frag);
6284 IHTMLElement_Release(div);
6286 hres = IHTMLDocument2_get_all(doc, &col);
6287 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6288 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6289 IHTMLElementCollection_Release(col);
6291 IHTMLDocument2_Release(frag);
6294 static IHTMLDocument2 *notif_doc;
6295 static BOOL doc_complete;
6297 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
6298 REFIID riid, void**ppv)
6300 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
6301 *ppv = iface;
6302 return S_OK;
6305 ok(0, "unexpected call\n");
6306 return E_NOINTERFACE;
6309 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
6311 return 2;
6314 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
6316 return 1;
6319 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
6321 if(dispID == DISPID_READYSTATE){
6322 BSTR state;
6323 HRESULT hres;
6325 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
6326 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
6328 if(!strcmp_wa(state, "complete"))
6329 doc_complete = TRUE;
6331 SysFreeString(state);
6334 return S_OK;
6337 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
6339 ok(0, "unexpected call\n");
6340 return E_NOTIMPL;
6343 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
6344 PropertyNotifySink_QueryInterface,
6345 PropertyNotifySink_AddRef,
6346 PropertyNotifySink_Release,
6347 PropertyNotifySink_OnChanged,
6348 PropertyNotifySink_OnRequestEdit
6351 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
6353 static IHTMLDocument2 *create_doc_with_string(const char *str)
6355 IPersistStreamInit *init;
6356 IStream *stream;
6357 IHTMLDocument2 *doc;
6358 HGLOBAL mem;
6359 SIZE_T len;
6361 notif_doc = doc = create_document();
6362 if(!doc)
6363 return NULL;
6365 doc_complete = FALSE;
6366 len = strlen(str);
6367 mem = GlobalAlloc(0, len);
6368 memcpy(mem, str, len);
6369 CreateStreamOnHGlobal(mem, TRUE, &stream);
6371 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
6373 IPersistStreamInit_Load(init, stream);
6374 IPersistStreamInit_Release(init);
6375 IStream_Release(stream);
6377 return doc;
6380 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
6382 IConnectionPointContainer *container;
6383 IConnectionPoint *cp;
6384 DWORD cookie;
6385 HRESULT hres;
6387 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
6388 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
6390 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
6391 IConnectionPointContainer_Release(container);
6392 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
6394 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
6395 IConnectionPoint_Release(cp);
6396 ok(hres == S_OK, "Advise failed: %08x\n", hres);
6399 typedef void (*domtest_t)(IHTMLDocument2*);
6401 static void run_domtest(const char *str, domtest_t test)
6403 IHTMLDocument2 *doc;
6404 ULONG ref;
6405 MSG msg;
6407 doc = create_doc_with_string(str);
6408 if(!doc)
6409 return;
6411 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
6413 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
6414 TranslateMessage(&msg);
6415 DispatchMessage(&msg);
6418 test(doc);
6420 ref = IHTMLDocument2_Release(doc);
6421 ok(!ref || broken(ref == 1), /* Vista */
6422 "ref = %d\n", ref);
6425 START_TEST(dom)
6427 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
6428 pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
6429 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
6431 CoInitialize(NULL);
6433 run_domtest(doc_str1, test_doc_elem);
6434 run_domtest(doc_str1, test_get_set_attr);
6435 run_domtest(range_test_str, test_txtrange);
6436 run_domtest(range_test2_str, test_txtrange2);
6437 if (winetest_interactive || ! is_ie_hardened()) {
6438 run_domtest(elem_test_str, test_elems);
6439 run_domtest(elem_test2_str, test_elems2);
6440 }else {
6441 skip("IE running in Enhanced Security Configuration\n");
6443 run_domtest(doc_blank, test_create_elems);
6444 run_domtest(doc_blank, test_defaults);
6445 run_domtest(doc_blank, test_null_write);
6446 run_domtest(indent_test_str, test_indent);
6447 run_domtest(cond_comment_str, test_cond_comment);
6448 run_domtest(frameset_str, test_frameset);
6449 run_domtest(emptydiv_str, test_docfrag);
6450 run_domtest(doc_blank, test_replacechild_elems);
6452 CoUninitialize();