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
22 #include <wine/test.h>
34 #include "mshtml_test.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 "<body onload=\"Testing()\">text test<!-- a comment -->"
51 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
52 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
53 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
54 "<textarea id=\"X\">text text</textarea>"
55 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
56 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
57 "<test /><object id=\"objid\" vspace=100></object><embed />"
58 "<img id=\"imgid\" name=\"WineImg\"/>"
59 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
60 "<form id=\"frm\"></form>"
61 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
63 static const char elem_test2_str[] =
64 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
65 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
68 static const char indent_test_str[] =
69 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
70 static const char cond_comment_str[] =
71 "<html><head><title>test</title></head><body>"
72 "<!--[if gte IE 4]> <br> <![endif]-->"
74 static const char frameset_str[] =
75 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
76 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
77 "<frame src=\"about:blank\" id=\"fr3\">"
79 static const char emptydiv_str[] =
80 "<html><head><title>emptydiv test</title></head>"
81 "<body><div id=\"divid\"></div></body></html>";
83 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
84 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
85 static WCHAR wordW[] = {'w','o','r','d',0};
119 static const IID * const none_iids[] = {
124 static const IID * const doc_node_iids[] = {
133 &IID_IConnectionPointContainer,
134 &IID_IInternetHostSecurityManager,
137 &IID_IProvideClassInfo,
141 static const IID * const doc_obj_iids[] = {
148 &IID_IConnectionPointContainer,
152 &IID_IProvideClassInfo,
153 &IID_ITargetContainer,
157 #define ELEM_IFACES \
159 &IID_IHTMLDOMNode2, \
161 &IID_IHTMLElement2, \
162 &IID_IHTMLElement3, \
163 &IID_IHTMLElement4, \
166 static const IID * const elem_iids[] = {
168 &IID_IConnectionPointContainer,
172 static const IID * const body_iids[] = {
174 &IID_IHTMLTextContainer,
175 &IID_IHTMLBodyElement,
176 &IID_IConnectionPointContainer,
180 static const IID * const anchor_iids[] = {
182 &IID_IHTMLAnchorElement,
183 &IID_IConnectionPointContainer,
187 static const IID * const input_iids[] = {
189 &IID_IHTMLInputElement,
190 &IID_IHTMLInputTextElement,
191 &IID_IConnectionPointContainer,
195 static const IID * const select_iids[] = {
197 &IID_IHTMLSelectElement,
198 &IID_IConnectionPointContainer,
202 static const IID * const textarea_iids[] = {
204 &IID_IHTMLTextAreaElement,
205 &IID_IConnectionPointContainer,
209 static const IID * const option_iids[] = {
211 &IID_IHTMLOptionElement,
212 &IID_IConnectionPointContainer,
216 static const IID * const table_iids[] = {
221 &IID_IConnectionPointContainer,
225 static const IID * const script_iids[] = {
227 &IID_IHTMLScriptElement,
228 &IID_IConnectionPointContainer,
232 static const IID * const text_iids[] = {
235 &IID_IHTMLDOMTextNode,
239 static const IID * const attr_iids[] = {
240 &IID_IHTMLDOMAttribute,
245 static const IID * const location_iids[] = {
251 static const IID * const window_iids[] = {
256 &IID_IServiceProvider,
260 static const IID * const comment_iids[] = {
262 &IID_IHTMLCommentElement,
263 &IID_IConnectionPointContainer,
267 static const IID * const img_iids[] = {
269 &IID_IHTMLImgElement,
270 &IID_IConnectionPointContainer,
274 static const IID * const tr_iids[] = {
277 &IID_IConnectionPointContainer,
281 static const IID * const td_iids[] = {
283 &IID_IConnectionPointContainer,
287 static const IID * const frame_iids[] = {
290 &IID_IHTMLFrameBase2,
291 &IID_IConnectionPointContainer,
295 static const IID * const head_iids[] = {
297 &IID_IHTMLHeadElement,
298 &IID_IConnectionPointContainer,
302 static const IID * const title_iids[] = {
304 &IID_IHTMLTitleElement,
305 &IID_IConnectionPointContainer,
309 static const IID * const object_iids[] = {
311 &IID_IHTMLObjectElement,
312 &IID_IHTMLObjectElement2,
313 /* FIXME: No IConnectionPointContainer */
317 static const IID * const embed_iids[] = {
319 &IID_IHTMLEmbedElement,
320 /* FIXME: No IConnectionPointContainer */
324 static const IID * const iframe_iids[] = {
327 &IID_IHTMLFrameBase2,
328 &IID_IHTMLIFrameElement,
329 &IID_IConnectionPointContainer,
333 static const IID * const form_iids[] = {
335 &IID_IHTMLFormElement,
336 &IID_IConnectionPointContainer,
340 static const IID * const styleelem_iids[] = {
342 &IID_IHTMLStyleElement,
343 &IID_IConnectionPointContainer,
347 static const IID * const generic_iids[] = {
349 &IID_IHTMLGenericElement,
350 &IID_IConnectionPointContainer,
354 static const IID * const style_iids[] = {
365 static const IID * const cstyle_iids[] = {
369 &IID_IHTMLCurrentStyle,
370 &IID_IHTMLCurrentStyle2,
371 &IID_IHTMLCurrentStyle3,
375 static const IID * const img_factory_iids[] = {
379 &IID_IHTMLImageElementFactory,
389 static const elem_type_info_t elem_type_infos[] = {
390 {"", none_iids, NULL},
391 {"HTML", elem_iids, NULL},
392 {"HEAD", head_iids, &DIID_DispHTMLHeadElement},
393 {"TITLE", title_iids, &DIID_DispHTMLTitleElement},
394 {"BODY", body_iids, &DIID_DispHTMLBody},
395 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
396 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
397 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
398 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
399 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
400 {"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement},
401 {"BLOCKQUOTE",elem_iids, NULL},
402 {"P", elem_iids, NULL},
403 {"BR", elem_iids, NULL},
404 {"TABLE", table_iids, &DIID_DispHTMLTable},
405 {"TBODY", elem_iids, NULL},
406 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
407 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
408 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
409 {"!", comment_iids, &DIID_DispHTMLCommentElement},
410 {"IMG", img_iids, &DIID_DispHTMLImg},
411 {"TR", tr_iids, &DIID_DispHTMLTableRow},
412 {"TD", td_iids, NULL},
413 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
414 {"FORM", form_iids, &DIID_DispHTMLFormElement},
415 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement},
416 {"OBJECT", object_iids, &DIID_DispHTMLObjectElement},
417 {"EMBED", embed_iids, &DIID_DispHTMLEmbed},
418 {"DIV", elem_iids, NULL}
421 static const char *dbgstr_guid(REFIID riid)
425 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
426 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
427 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
428 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
433 static int strcmp_wa(LPCWSTR strw, const char *stra)
436 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
437 return lstrcmpA(stra, buf);
440 static BSTR a2bstr(const char *str)
448 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
449 ret = SysAllocStringLen(NULL, len);
450 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
455 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
457 IUnknown *unk1, *unk2;
462 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
463 IUnknown_Release(unk1);
464 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
465 IUnknown_Release(unk2);
470 static IHTMLDocument2 *create_document(void)
473 IHTMLDocument5 *doc5;
476 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
477 &IID_IHTMLDocument2, (void**)&doc);
478 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
482 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
484 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
485 IHTMLDocument2_Release(doc);
489 IHTMLDocument5_Release(doc5);
493 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
494 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
499 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
500 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
504 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
505 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
507 const IID * const *piid;
511 for(piid = iids; *piid; piid++) {
512 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
513 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
515 IUnknown_Release(unk);
519 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
520 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
525 unk = (void*)0xdeadbeef;
526 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
527 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
528 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
531 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
532 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
534 IDispatchEx *dispex = _get_dispex_iface(line, unk);
541 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
542 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
543 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
545 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
546 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
548 if(SUCCEEDED(hres)) {
551 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
552 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
554 *iid = type_attr->guid;
558 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
559 ITypeInfo_Release(typeinfo);
562 IDispatchEx_Release(dispex);
566 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
567 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
569 IDispatchEx *dispex = _get_dispex_iface(line, unk);
570 DISPPARAMS dp = {NULL,NULL,0,0};
575 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
576 IDispatchEx_Release(dispex);
577 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
579 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
580 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
584 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
585 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
589 if(_test_get_dispid(line, unk, &iid))
590 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
593 _test_disp_value(line, unk, val);
596 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
597 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
601 if(_test_get_dispid(line, unk, &iid))
602 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
603 "unexpected guid %s\n", dbgstr_guid(&iid));
606 _test_disp_value(line, unk, val);
609 #define test_class_info(u) _test_class_info(__LINE__,u)
610 static void _test_class_info(unsigned line, IUnknown *unk)
612 IProvideClassInfo *classinfo;
617 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
618 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
622 hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
623 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
626 IProvideClassInfo_Release(classinfo);
630 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
631 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
634 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
635 "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
636 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
637 "unexpected typekind %d\n", type_attr->typekind);
638 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
641 ITypeInfo_Release(typeinfo);
642 IProvideClassInfo_Release(classinfo);
645 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
646 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
648 IDispatchEx *dispex = _get_dispex_iface(line, unk);
649 DISPPARAMS dp = {val, NULL, 1, 0};
656 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
658 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
660 memset(&ei, 0, sizeof(ei));
661 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
662 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
666 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
667 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
672 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
673 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
677 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
678 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
683 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
684 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
688 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
689 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
694 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
695 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
699 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
700 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
705 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
706 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
710 #define get_node_iface(u) _get_node_iface(__LINE__,u)
711 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
716 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
717 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
721 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
722 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
727 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
728 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
732 #define get_img_iface(u) _get_img_iface(__LINE__,u)
733 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
735 IHTMLImgElement *img;
738 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
739 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
743 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
744 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
746 IHTMLAnchorElement *anchor;
749 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
750 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
754 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
755 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
757 IHTMLTextAreaElement *textarea;
760 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
761 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
765 #define get_select_iface(u) _get_select_iface(__LINE__,u)
766 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
768 IHTMLSelectElement *select;
771 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
772 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
776 #define get_form_iface(u) _get_form_iface(__LINE__,u)
777 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
779 IHTMLFormElement *form;
782 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
783 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
787 #define get_text_iface(u) _get_text_iface(__LINE__,u)
788 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
790 IHTMLDOMTextNode *text;
793 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
794 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
798 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
799 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
801 IHTMLCommentElement *comment;
804 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
805 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
809 #define get_object_iface(u) _get_object_iface(__LINE__,u)
810 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
812 IHTMLObjectElement *obj;
815 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
816 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
820 #define get_style_iface(u) _get_style_iface(__LINE__,u)
821 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
823 IHTMLStyleElement *obj;
826 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
827 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
831 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
832 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
834 IHTMLDOMNode *node = _get_node_iface(line, unk);
838 hres = IHTMLDOMNode_get_nodeName(node, &name);
839 IHTMLDOMNode_Release(node);
840 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
841 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
846 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
847 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
849 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
850 IDispatch *disp = (void*)0xdeadbeef;
851 IHTMLDocument2 *doc = NULL;
854 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
855 IHTMLDOMNode2_Release(node);
856 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
859 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
860 IDispatch_Release(disp);
861 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
867 #define get_doc_window(d) _get_doc_window(__LINE__,d)
868 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
870 IHTMLWindow2 *window;
874 hres = IHTMLDocument2_get_parentWindow(doc, &window);
875 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
876 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
881 #define clone_node(n,d) _clone_node(__LINE__,n,d)
882 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
884 IHTMLDOMNode *node = _get_node_iface(line, unk);
885 IHTMLDOMNode *ret = NULL;
888 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
889 IHTMLDOMNode_Release(node);
890 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
891 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
897 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
898 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
900 IHTMLElement *elem = _get_elem_iface(line, unk);
904 hres = IHTMLElement_get_tagName(elem, &tag);
905 IHTMLElement_Release(elem);
906 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
907 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
912 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
913 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
915 _test_elem_tag(line, unk, elem_type_infos[type].tag);
916 _test_ifaces(line, unk, elem_type_infos[type].iids);
918 if(elem_type_infos[type].dispiid && type != ET_A)
919 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
922 #define get_node_type(n) _get_node_type(__LINE__,n)
923 static LONG _get_node_type(unsigned line, IUnknown *unk)
925 IHTMLDOMNode *node = _get_node_iface(line, unk);
929 hres = IHTMLDOMNode_get_nodeType(node, &type);
930 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
932 IHTMLDOMNode_Release(node);
937 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
938 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
940 IHTMLDOMNode *node = _get_node_iface(line, unk);
941 IHTMLDOMChildrenCollection *col = NULL;
945 hres = IHTMLDOMNode_get_childNodes(node, &disp);
946 IHTMLDOMNode_Release(node);
947 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
951 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
952 IDispatch_Release(disp);
953 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
958 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
959 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
961 IHTMLDOMNode *node = NULL;
965 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
966 ok(hres == S_OK, "item failed: %08x\n", hres);
968 node = _get_node_iface(line, (IUnknown*)disp);
969 IDispatch_Release(disp);
974 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
975 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
984 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
986 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
989 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
990 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
992 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
995 VariantClear(&value);
998 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
999 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
1001 IHTMLElement *elem = _get_elem_iface(line, unk);
1002 IHTMLElement *off_parent;
1006 hres = IHTMLElement_get_offsetTop(elem, &l);
1007 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1009 hres = IHTMLElement_get_offsetHeight(elem, &l);
1010 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1012 hres = IHTMLElement_get_offsetWidth(elem, &l);
1013 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1015 hres = IHTMLElement_get_offsetLeft(elem, &l);
1016 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1018 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1019 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1021 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1022 IHTMLElement_Release(off_parent);
1024 IHTMLElement_Release(elem);
1027 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1028 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1030 IHTMLWindow2 *window;
1031 IHTMLDocument2 *ret;
1034 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1035 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1037 hres = IHTMLWindow2_get_document(window, &ret);
1038 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1039 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1044 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1045 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1050 hres = IHTMLWindow2_get_name(window, &name);
1051 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1053 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1055 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1056 SysFreeString(name);
1059 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1060 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1066 hres = IHTMLWindow2_put_name(window, str);
1068 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1070 _test_window_name(line, window, name);
1073 #define test_window_status(d) _test_window_status(__LINE__,d)
1074 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1079 status = (void*)0xdeadbeef;
1080 hres = IHTMLWindow2_get_status(window, &status);
1081 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1082 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1083 SysFreeString(status);
1086 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1087 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1092 str = a2bstr(status);
1093 hres = IHTMLWindow2_put_status(window, str);
1095 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1098 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1099 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1104 hres = IHTMLWindow2_get_length(window, &length);
1105 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1106 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1109 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1110 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1112 IHTMLFrameBase2 *base2;
1113 IHTMLWindow2 *window;
1116 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1117 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1120 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1121 IHTMLFrameBase2_Release(base2);
1122 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1123 ok(window != NULL, "contentWindow = NULL\n");
1128 static void test_get_set_attr(IHTMLDocument2 *doc)
1131 IHTMLDocument3 *doc3;
1136 /* grab an element to test with */
1137 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1138 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1140 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1141 IHTMLDocument3_Release(doc3);
1142 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1144 /* get a non-present attribute */
1145 bstr = a2bstr("notAnAttribute");
1146 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1147 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1148 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1150 SysFreeString(bstr);
1152 /* get a present attribute */
1153 bstr = a2bstr("scrollHeight");
1154 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1155 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1156 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1158 SysFreeString(bstr);
1160 /* create a new BSTR attribute */
1161 bstr = a2bstr("newAttribute");
1163 V_VT(&val) = VT_BSTR;
1164 V_BSTR(&val) = a2bstr("the value");
1165 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1166 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1169 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1170 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1171 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1172 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)));
1175 /* overwrite the attribute with a BOOL */
1176 V_VT(&val) = VT_BOOL;
1177 V_BOOL(&val) = VARIANT_TRUE;
1178 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1179 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1182 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1183 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1184 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1185 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1188 SysFreeString(bstr);
1190 /* case-insensitive */
1191 bstr = a2bstr("newattribute");
1192 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1193 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1194 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1195 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1197 SysFreeString(bstr);
1199 IHTMLElement_Release(elem);
1202 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1203 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1206 IHTMLDocument3 *doc3;
1209 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1210 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1211 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1212 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1213 IHTMLDocument3_Release(doc3);
1218 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1219 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1221 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1225 hres = IHTMLAnchorElement_get_href(anchor, &str);
1226 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1227 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1230 _test_disp_value(line, unk, exhref);
1233 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1234 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1236 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1240 str = a2bstr(exhref);
1241 hres = IHTMLAnchorElement_put_href(anchor, str);
1242 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1245 _test_disp_value(line, unk, exhref);
1248 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1249 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1251 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1255 hres = IHTMLAnchorElement_get_target(anchor, &str);
1256 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1258 ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1260 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1264 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1265 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1267 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1271 str = target ? a2bstr(target) : NULL;
1272 hres = IHTMLAnchorElement_put_target(anchor, str);
1273 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1278 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1279 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1284 hres = IHTMLOptionElement_get_text(option, &bstr);
1285 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1286 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1287 SysFreeString(bstr);
1290 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1291 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1296 bstr = a2bstr(text);
1297 hres = IHTMLOptionElement_put_text(option, bstr);
1298 SysFreeString(bstr);
1299 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1301 _test_option_text(line, option, text);
1304 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1305 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1310 hres = IHTMLOptionElement_get_value(option, &bstr);
1311 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1312 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1313 SysFreeString(bstr);
1316 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1317 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1322 bstr = a2bstr(value);
1323 hres = IHTMLOptionElement_put_value(option, bstr);
1324 SysFreeString(bstr);
1325 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1327 _test_option_value(line, option, value);
1330 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1331 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1333 VARIANT_BOOL b = 0x100;
1336 hres = IHTMLOptionElement_get_selected(option, &b);
1337 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1338 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1341 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1342 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1346 hres = IHTMLOptionElement_put_selected(option, b);
1347 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1348 _test_option_selected(line, option, b);
1351 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1352 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1354 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1355 BSTR value = (void*)0xdeadbeef;
1358 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1359 IHTMLTextAreaElement_Release(textarea);
1360 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1362 ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1364 ok_(__FILE__,line)(!value, "value = %p\n", value);
1365 SysFreeString(value);
1368 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1369 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1371 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1372 BSTR tmp = a2bstr(value);
1375 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1376 IHTMLTextAreaElement_Release(textarea);
1377 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1380 _test_textarea_value(line, unk, value);
1383 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1384 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1386 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1387 VARIANT_BOOL b = 0x100;
1390 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1391 IHTMLTextAreaElement_Release(textarea);
1392 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1393 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1396 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1397 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1399 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1402 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1403 IHTMLTextAreaElement_Release(textarea);
1404 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1406 _test_textarea_readonly(line, unk, b);
1409 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1410 static void _test_textarea_type(unsigned line, IUnknown *unk)
1412 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1413 BSTR type = (void*)0xdeadbeef;
1416 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1417 IHTMLTextAreaElement_Release(textarea);
1418 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1419 ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1420 SysFreeString(type);
1423 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1424 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1426 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1430 text = a2bstr(extext);
1431 hres = IHTMLCommentElement_get_text(comment, &text);
1432 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1433 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1435 IHTMLCommentElement_Release(comment);
1436 SysFreeString(text);
1439 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1440 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1442 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1443 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1444 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1445 IHTMLDOMAttribute *attr;
1446 BSTR name = a2bstr("test");
1450 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1451 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1452 ok(attr == NULL, "attr != NULL\n");
1456 hres = IHTMLElement_setAttribute(elem, name, val, 0);
1457 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1459 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1460 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1461 ok(attr != NULL, "attr == NULL\n");
1463 IHTMLDOMAttribute_Release(attr);
1464 IHTMLCommentElement_Release(comment);
1465 IHTMLElement_Release(elem);
1466 IHTMLElement4_Release(elem);
1467 SysFreeString(name);
1470 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1471 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1473 IHTMLObjectElement *object = _get_object_iface(line, unk);
1478 hres = IHTMLObjectElement_get_vspace(object, &l);
1479 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1480 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1481 IHTMLObjectElement_Release(object);
1484 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1485 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1486 const char *txt, const char *val)
1488 IHTMLOptionElementFactory *factory;
1489 IHTMLOptionElement *option;
1490 IHTMLWindow2 *window;
1491 VARIANT text, value, empty;
1494 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1495 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1497 hres = IHTMLWindow2_get_Option(window, &factory);
1498 IHTMLWindow2_Release(window);
1499 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1501 V_VT(&text) = VT_BSTR;
1502 V_BSTR(&text) = a2bstr(txt);
1503 V_VT(&value) = VT_BSTR;
1504 V_BSTR(&value) = a2bstr(val);
1505 V_VT(&empty) = VT_EMPTY;
1507 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1508 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1510 IHTMLOptionElementFactory_Release(factory);
1511 VariantClear(&text);
1512 VariantClear(&value);
1514 _test_option_text(line, option, txt);
1515 _test_option_value(line, option, val);
1516 _test_option_selected(line, option, VARIANT_FALSE);
1521 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1522 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1527 hres = IHTMLImgElement_get_width(img, &found);
1528 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1529 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1532 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1533 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
1537 hres = IHTMLImgElement_put_width(img, width);
1538 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1540 _test_img_width(line, img, width);
1543 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1544 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
1549 hres = IHTMLImgElement_get_height(img, &found);
1550 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1551 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1554 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1555 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
1559 hres = IHTMLImgElement_put_height(img, height);
1560 ok(hres == S_OK, "put_height failed: %08x\n", hres);
1562 _test_img_height(line, img, height);
1565 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1566 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1567 LONG wdth, LONG hght)
1569 IHTMLImageElementFactory *factory;
1570 IHTMLImgElement *img;
1571 IHTMLWindow2 *window;
1572 VARIANT width, height;
1576 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1577 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1579 hres = IHTMLWindow2_get_Image(window, &factory);
1580 IHTMLWindow2_Release(window);
1581 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1583 test_ifaces((IUnknown*)factory, img_factory_iids);
1584 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1587 snprintf(buf, 16, "%d", wdth);
1588 V_VT(&width) = VT_BSTR;
1589 V_BSTR(&width) = a2bstr(buf);
1591 V_VT(&width) = VT_EMPTY;
1596 snprintf(buf, 16, "%d", hght);
1597 V_VT(&height) = VT_BSTR;
1598 V_BSTR(&height) = a2bstr(buf);
1600 V_VT(&height) = VT_EMPTY;
1604 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1605 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1607 IHTMLImageElementFactory_Release(factory);
1608 VariantClear(&width);
1609 VariantClear(&height);
1611 if(SUCCEEDED(hres)) {
1612 _test_img_width(line, img, wdth);
1613 _test_img_height(line, img, hght);
1620 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1621 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1623 LONG len = 0xdeadbeef;
1626 hres = IHTMLSelectElement_get_length(select, &len);
1627 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1628 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1631 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
1632 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
1634 IHTMLSelectElement *select = _get_select_iface(line, unk);
1637 hres = IHTMLSelectElement_put_length(select, length);
1638 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
1639 _test_select_length(line, select, length);
1640 IHTMLSelectElement_Release(select);
1643 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1644 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1646 LONG idx = 0xdeadbeef;
1649 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1650 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1651 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1654 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1655 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1659 hres = IHTMLSelectElement_put_selectedIndex(select, index);
1660 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1661 _test_select_selidx(line, select, index);
1664 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1665 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1670 hres = IHTMLSelectElement_get_value(select, &val);
1671 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1673 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1675 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1679 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1680 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1686 hres = IHTMLSelectElement_put_value(select, bstr);
1687 SysFreeString(bstr);
1688 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1691 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1692 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1697 hres = IHTMLSelectElement_get_type(select, &type);
1698 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1699 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1700 SysFreeString(type);
1703 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1704 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1709 hres = IHTMLTxtRange_get_text(range, &text);
1710 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1713 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1714 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1716 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1719 SysFreeString(text);
1723 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1724 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1728 hres = IHTMLTxtRange_collapse(range, b);
1729 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1730 _test_range_text(line, range, NULL);
1733 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
1734 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
1735 VARIANT_BOOL exb, const char *extext)
1737 VARIANT_BOOL b = 0xe0e0;
1740 hres = IHTMLTxtRange_expand(range, unit, &b);
1741 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
1742 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
1743 _test_range_text(line, range, extext);
1746 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
1747 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1749 LONG c = 0xdeadbeef;
1752 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
1753 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1754 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1755 _test_range_text(line, range, NULL);
1758 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
1759 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
1760 LPWSTR unit, LONG cnt, LONG excnt)
1762 LONG c = 0xdeadbeef;
1765 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
1766 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1767 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1770 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
1771 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
1773 LONG c = 0xdeadbeef;
1776 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
1777 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
1778 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
1781 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
1782 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
1785 BSTR bstr = a2bstr(text);
1787 hres = IHTMLTxtRange_put_text(range, bstr);
1788 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
1789 SysFreeString(bstr);
1790 _test_range_text(line, range, NULL);
1793 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
1794 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1800 hres = IHTMLTxtRange_inRange(range1, range2, &b);
1801 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1802 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1805 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1806 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1812 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1813 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1814 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1817 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1818 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1819 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1822 test_range_inrange(range1, range2, VARIANT_TRUE);
1823 test_range_inrange(range2, range1, VARIANT_TRUE);
1827 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1828 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1833 hres = IHTMLTxtRange_parentElement(range, &elem);
1834 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1836 _test_elem_type(line, (IUnknown*)elem, type);
1838 IHTMLElement_Release(elem);
1841 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1842 static void _test_elem_collection(unsigned line, IUnknown *unk,
1843 const elem_type_t *elem_types, LONG exlen)
1845 IHTMLElementCollection *col;
1848 VARIANT name, index;
1849 IDispatch *disp, *disp2;
1852 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1853 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1855 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1857 hres = IHTMLElementCollection_get_length(col, &len);
1858 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1859 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1864 V_VT(&index) = VT_EMPTY;
1866 for(i=0; i<len; i++) {
1867 V_VT(&name) = VT_I4;
1869 disp = (void*)0xdeadbeef;
1870 hres = IHTMLElementCollection_item(col, name, index, &disp);
1871 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1872 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1873 if(FAILED(hres) || !disp)
1876 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1879 V_VT(&name) = VT_UINT;
1881 disp2 = (void*)0xdeadbeef;
1882 hres = IHTMLElementCollection_item(col, name, index, &disp2);
1883 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1884 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1886 IDispatch_Release(disp2);
1889 IDispatch_Release(disp);
1892 V_VT(&name) = VT_I4;
1894 disp = (void*)0xdeadbeef;
1895 hres = IHTMLElementCollection_item(col, name, index, &disp);
1896 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1897 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1899 V_VT(&name) = VT_I4;
1901 disp = (void*)0xdeadbeef;
1902 hres = IHTMLElementCollection_item(col, name, index, &disp);
1903 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1904 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1906 IHTMLElementCollection_Release(col);
1909 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
1910 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
1912 IHTMLElement *elem = _get_elem_iface(line, unk);
1916 hres = IHTMLElement_get_all(elem, &disp);
1917 IHTMLElement_Release(elem);
1918 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
1920 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
1921 IDispatch_Release(disp);
1924 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1925 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1927 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1928 IHTMLElementCollection *col = NULL;
1929 elem_type_t *types = NULL;
1934 tmp = a2bstr(elem_type_infos[type].tag);
1935 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1937 IHTMLElement2_Release(elem);
1938 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1939 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1942 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1943 for(i=0; i<exlen; i++)
1947 _test_elem_collection(line, (IUnknown*)col, types, exlen);
1949 HeapFree(GetProcessHeap(), 0, types);
1952 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1953 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1958 hres = IHTMLElement_get_innerText(elem, &text);
1959 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1960 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1961 wine_dbgstr_w(text), extext);
1962 SysFreeString(text);
1965 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1966 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1968 IHTMLDOMChildrenCollection *col;
1973 hres = IHTMLElement_put_innerText(elem, str);
1974 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1977 _test_elem_innertext(line, elem, text);
1980 col = _get_child_nodes(line, (IUnknown*)elem);
1981 ok(col != NULL, "col == NULL\n");
1983 LONG length = 0, type;
1986 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1987 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1988 ok(length == 1, "length = %d\n", length);
1990 node = _get_child_item(line, col, 0);
1991 ok(node != NULL, "node == NULL\n");
1993 type = _get_node_type(line, (IUnknown*)node);
1994 ok(type == 3, "type=%d\n", type);
1995 IHTMLDOMNode_Release(node);
1998 IHTMLDOMChildrenCollection_Release(col);
2003 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2004 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2006 IHTMLElement *elem = _get_elem_iface(line, unk);
2010 hres = IHTMLElement_get_innerHTML(elem, &html);
2011 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2013 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2015 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2017 IHTMLElement_Release(elem);
2018 SysFreeString(html);
2021 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2022 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2024 IHTMLElement *elem = _get_elem_iface(line, unk);
2028 html = a2bstr(inner_html);
2029 hres = IHTMLElement_put_innerHTML(elem, html);
2030 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2032 IHTMLElement_Release(elem);
2033 SysFreeString(html);
2036 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2037 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2039 IHTMLElement *elem = _get_elem_iface(line, unk);
2043 html = a2bstr(outer_html);
2044 hres = IHTMLElement_put_outerHTML(elem, html);
2045 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2047 IHTMLElement_Release(elem);
2048 SysFreeString(html);
2051 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2052 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2054 IHTMLElement *elem = _get_elem_iface(line, unk);
2058 hres = IHTMLElement_get_outerHTML(elem, &html);
2059 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2060 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2062 IHTMLElement_Release(elem);
2063 SysFreeString(html);
2066 #define get_first_child(n) _get_first_child(__LINE__,n)
2067 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2069 IHTMLDOMNode *node = _get_node_iface(line, unk);
2070 IHTMLDOMNode *child = NULL;
2073 hres = IHTMLDOMNode_get_firstChild(node, &child);
2074 IHTMLDOMNode_Release(node);
2075 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2080 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2081 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2083 IHTMLDOMNode *node = _get_node_iface(line, unk);
2084 VARIANT_BOOL b = 0xdead;
2087 hres = IHTMLDOMNode_hasChildNodes(node, &b);
2088 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2089 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2091 IHTMLDOMNode_Release(node);
2094 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2095 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2097 IHTMLDOMNode *node = _get_node_iface(line, unk);
2098 IHTMLDOMNode *parent;
2101 hres = IHTMLDOMNode_get_parentNode(node, &parent);
2102 IHTMLDOMNode_Release(node);
2103 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2108 #define node_get_next(u) _node_get_next(__LINE__,u)
2109 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2111 IHTMLDOMNode *node = _get_node_iface(line, unk);
2115 hres = IHTMLDOMNode_get_nextSibling(node, &next);
2116 IHTMLDOMNode_Release(node);
2117 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2122 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2123 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2125 IHTMLDOMNode *node = _get_node_iface(line, unk);
2129 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2130 IHTMLDOMNode_Release(node);
2131 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2136 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2137 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2139 IHTMLElement *elem = _get_elem_iface(line, unk);
2140 IHTMLElement *parent;
2143 hres = IHTMLElement_get_parentElement(elem, &parent);
2144 IHTMLElement_Release(elem);
2145 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2150 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2151 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2153 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2154 VARIANT_BOOL disabled = 100;
2158 hres = IHTMLElement3_get_disabled(elem3, &disabled);
2159 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2160 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2161 IHTMLElement3_Release(elem3);
2164 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2165 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2167 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2171 hres = IHTMLElement3_put_disabled(elem3, b);
2172 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2174 IHTMLElement3_Release(elem3);
2175 _test_elem3_get_disabled(line, unk, b);
2178 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2179 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2181 VARIANT_BOOL disabled = 100;
2184 hres = IHTMLSelectElement_get_disabled(select, &disabled);
2185 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2186 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2188 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2191 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2192 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2194 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2198 hres = IHTMLDOMTextNode_get_length(text, &length);
2199 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2200 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2201 IHTMLDOMTextNode_Release(text);
2204 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2205 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2209 hres = IHTMLSelectElement_put_disabled(select, b);
2210 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2212 _test_select_get_disabled(line, select, b);
2215 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2216 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2218 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2219 IHTMLTextContainer *txtcont;
2220 LONG l = -1, l2 = -1;
2223 hres = IHTMLElement2_get_scrollHeight(elem, &l);
2224 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2225 IHTMLElement2_Release(elem);
2227 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2228 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2230 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2231 IHTMLTextContainer_Release(txtcont);
2232 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2233 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
2238 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
2239 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
2241 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2242 IHTMLTextContainer *txtcont;
2243 LONG l = -1, l2 = -1;
2246 hres = IHTMLElement2_get_scrollWidth(elem, &l);
2247 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
2248 IHTMLElement2_Release(elem);
2250 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2251 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2253 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
2254 IHTMLTextContainer_Release(txtcont);
2255 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
2256 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
2261 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
2262 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
2264 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2265 IHTMLTextContainer *txtcont;
2266 LONG l = -1, l2 = -1;
2269 hres = IHTMLElement2_get_scrollTop(elem, &l);
2270 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2271 IHTMLElement2_Release(elem);
2273 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2274 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2276 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
2277 IHTMLTextContainer_Release(txtcont);
2278 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
2279 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
2284 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
2285 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
2287 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2288 IHTMLTextContainer *txtcont;
2289 LONG l = -1, l2 = -1;
2292 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
2293 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
2295 hres = IHTMLElement2_get_scrollLeft(elem, &l);
2296 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2297 IHTMLElement2_Release(elem);
2299 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2300 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2302 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
2303 IHTMLTextContainer_Release(txtcont);
2304 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
2305 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
2308 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
2309 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
2311 IHTMLImgElement *img = _get_img_iface(line, unk);
2315 hres = IHTMLImgElement_get_src(img, &src);
2316 IHTMLImgElement_Release(img);
2317 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2318 ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
2319 "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2323 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
2324 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
2326 IHTMLImgElement *img = _get_img_iface(line, unk);
2331 hres = IHTMLImgElement_put_src(img, tmp);
2332 IHTMLImgElement_Release(img);
2334 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2337 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
2338 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
2340 IHTMLImgElement *img = _get_img_iface(line, unk);
2344 hres = IHTMLImgElement_get_alt(img, &alt);
2345 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2347 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
2349 ok_(__FILE__,line) (!alt, "alt != NULL\n");
2353 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
2354 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
2356 IHTMLImgElement *img = _get_img_iface(line, unk);
2361 hres = IHTMLImgElement_put_alt(img, tmp);
2362 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2365 _test_img_alt(line, unk, alt);
2368 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
2369 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
2371 IHTMLImgElement *img = _get_img_iface(line, unk);
2375 hres = IHTMLImgElement_get_name(img, &sName);
2376 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
2377 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
2378 IHTMLImgElement_Release(img);
2379 SysFreeString(sName);
2382 static void test_dynamic_properties(IHTMLElement *elem)
2384 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
2385 IDispatchEx *dispex;
2386 BSTR name, attr1 = SysAllocString(attr1W);
2390 DISPID id = DISPID_STARTENUM;
2393 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2394 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2396 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
2397 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
2398 ok(succ, "removeAttribute set succ to FALSE\n");
2401 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2402 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
2406 hres = IDispatchEx_GetMemberName(dispex, id, &name);
2407 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2409 if(!strcmp_wa(name, "attr1"))
2410 ok(0, "attr1 should be removed\n");
2411 else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
2413 SysFreeString(name);
2415 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
2416 IDispatchEx_Release(dispex);
2418 V_VT(&val) = VT_BSTR;
2419 V_BSTR(&val) = attr1;
2420 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
2421 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2422 SysFreeString(attr1);
2425 static void test_attr_collection_disp(IDispatch *disp)
2427 IDispatchEx *dispex;
2428 IHTMLDOMAttribute *attr;
2429 DISPPARAMS dp = {NULL, NULL, 0, 0};
2436 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2437 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2440 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2441 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2442 SysFreeString(bstr);
2445 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2446 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2447 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2448 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2451 bstr = a2bstr("attr1");
2452 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2453 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2454 SysFreeString(bstr);
2457 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2458 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2459 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2460 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2461 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
2462 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2463 hres = IHTMLDOMAttribute_get_nodeName(attr, &bstr);
2464 ok(hres == S_OK, "get_nodeName failed: %08x\n", hres);
2465 ok(!strcmp_wa(bstr, "attr1"), "node name is %s, expected attr1\n", wine_dbgstr_w(bstr));
2466 SysFreeString(bstr);
2467 IHTMLDOMAttribute_Release(attr);
2470 IDispatchEx_Release(dispex);
2473 static void test_attr_collection(IHTMLElement *elem)
2475 static const WCHAR testW[] = {'t','e','s','t',0};
2478 IDispatch *disp, *attr;
2479 IHTMLDOMAttribute *dom_attr;
2480 IHTMLAttributeCollection *attr_col;
2481 BSTR name = SysAllocString(testW);
2483 LONG i, len, checked;
2486 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
2487 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2489 hres = IHTMLDOMNode_get_attributes(node, &disp);
2490 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2492 hres = IHTMLDOMNode_get_attributes(node, &attr);
2493 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2494 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
2495 IDispatch_Release(attr);
2496 IHTMLDOMNode_Release(node);
2498 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
2499 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2501 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
2502 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2506 hres = IHTMLElement_setAttribute(elem, name, val, 0);
2507 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2508 SysFreeString(name);
2510 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
2511 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2512 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
2515 for(i=0; i<len; i++) {
2518 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2519 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
2521 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
2522 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
2523 IDispatch_Release(attr);
2525 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
2526 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
2528 if(!strcmp_wa(name, "id")) {
2530 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2531 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2532 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
2533 ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2534 } else if(!strcmp_wa(name, "attr1")) {
2536 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2537 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2538 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
2539 ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2540 } else if(!strcmp_wa(name, "attr2")) {
2542 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2543 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2544 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
2545 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
2546 } else if(!strcmp_wa(name, "attr3")) {
2548 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2549 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2550 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
2551 ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2552 } else if(!strcmp_wa(name, "test")) {
2554 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2555 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2556 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
2557 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
2560 IHTMLDOMAttribute_Release(dom_attr);
2561 SysFreeString(name);
2564 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
2567 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2568 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2570 V_VT(&id) = VT_BSTR;
2571 V_BSTR(&id) = a2bstr("nonexisting");
2572 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2573 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
2576 test_attr_collection_disp(disp);
2578 IDispatch_Release(disp);
2579 IHTMLAttributeCollection_Release(attr_col);
2582 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
2583 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
2588 hres = IHTMLInputElement_get_type(input, &type);
2589 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2590 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
2591 SysFreeString(type);
2594 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
2595 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
2597 BSTR name = (BSTR)0xdeadbeef;
2600 hres = IHTMLInputElement_get_name(input, &name);
2601 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
2603 ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
2605 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
2606 SysFreeString(name);
2609 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
2610 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
2612 BSTR tmp = a2bstr(name);
2615 hres = IHTMLInputElement_put_name(input, tmp);
2616 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
2619 _test_input_name(line, input, name);
2622 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
2623 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2625 VARIANT_BOOL disabled = 100;
2628 hres = IHTMLInputElement_get_disabled(input, &disabled);
2629 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2630 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2632 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
2635 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
2636 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2640 hres = IHTMLInputElement_put_disabled(input, b);
2641 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2643 _test_input_get_disabled(line, input, b);
2646 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
2647 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2649 VARIANT_BOOL checked = 100;
2652 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
2653 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2654 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2657 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
2658 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2662 hres = IHTMLInputElement_put_defaultChecked(input, b);
2663 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
2665 _test_input_get_defaultchecked(line, input, b);
2668 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
2669 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
2671 VARIANT_BOOL checked = 100;
2674 hres = IHTMLInputElement_get_checked(input, &checked);
2675 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2676 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
2679 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
2680 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
2684 hres = IHTMLInputElement_put_checked(input, b);
2685 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
2687 _test_input_get_checked(line, input, b);
2690 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
2691 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
2693 IHTMLInputElement *input;
2697 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2698 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2702 hres = IHTMLInputElement_get_value(input, &bstr);
2703 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2705 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
2707 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
2708 SysFreeString(bstr);
2709 IHTMLInputElement_Release(input);
2712 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
2713 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
2715 IHTMLInputElement *input;
2719 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
2720 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2725 hres = IHTMLInputElement_put_value(input, bstr);
2726 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2727 SysFreeString(bstr);
2728 IHTMLInputElement_Release(input);
2730 _test_input_value(line, unk, val);
2733 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
2734 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
2739 hres = IHTMLInputElement_get_src(input, &src);
2740 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2742 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2744 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
2748 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
2749 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
2755 hres = IHTMLInputElement_put_src(input, tmp);
2757 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2759 _test_input_src(line, input, src);
2762 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
2763 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
2765 IHTMLElement *elem = _get_elem_iface(line, unk);
2766 BSTR class = (void*)0xdeadbeef;
2769 hres = IHTMLElement_get_className(elem, &class);
2770 IHTMLElement_Release(elem);
2771 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
2773 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
2775 ok_(__FILE__,line) (!class, "class != NULL\n");
2776 SysFreeString(class);
2779 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
2780 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
2782 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2786 hres = IHTMLElement2_get_tabIndex(elem2, &index);
2787 IHTMLElement2_Release(elem2);
2788 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2789 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
2792 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
2793 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
2795 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
2798 hres = IHTMLElement2_put_tabIndex(elem2, index);
2799 IHTMLElement2_Release(elem2);
2800 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
2802 _test_elem_tabindex(line, unk, index);
2805 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
2806 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
2808 IHTMLStyleElement *style = _get_style_iface(line, unk);
2812 hres = IHTMLStyleElement_get_media(style, &media);
2813 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
2815 ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
2817 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
2819 IHTMLStyleElement_Release(style);
2820 SysFreeString(media);
2823 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
2824 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
2826 IHTMLStyleElement *style = _get_style_iface(line, unk);
2830 str = a2bstr(media);
2831 hres = IHTMLStyleElement_put_media(style, str);
2832 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
2833 IHTMLStyleElement_Release(style);
2836 _test_style_media(line, unk, media);
2839 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
2840 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
2842 IHTMLStyleElement *style = _get_style_iface(line, unk);
2846 hres = IHTMLStyleElement_get_type(style, &type);
2847 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
2849 ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
2851 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
2853 IHTMLStyleElement_Release(style);
2854 SysFreeString(type);
2857 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
2858 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
2860 IHTMLStyleElement *style = _get_style_iface(line, unk);
2865 hres = IHTMLStyleElement_put_type(style, str);
2866 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
2867 IHTMLStyleElement_Release(style);
2870 _test_style_type(line, unk, type);
2873 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
2874 static void _test_elem_filters(unsigned line, IUnknown *unk)
2876 IHTMLElement *elem = _get_elem_iface(line, unk);
2878 IHTMLFiltersCollection *filters;
2880 hres = IHTMLElement_get_filters(elem, &filters);
2881 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
2882 "get_filters failed: %08x\n", hres);
2886 IDispatchEx *dispex;
2888 hres = IHTMLFiltersCollection_get_length(filters, &len);
2889 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2890 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
2892 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
2893 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
2894 "Could not get IDispatchEx interface: %08x\n", hres);
2895 if(SUCCEEDED(hres)) {
2896 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
2897 IDispatchEx_Release(dispex);
2900 IHTMLFiltersCollection_Release(filters);
2903 IHTMLElement_Release(elem);
2906 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
2907 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
2909 IHTMLElement *elem = _get_elem_iface(line, unk);
2913 tmp = class ? a2bstr(class) : NULL;
2914 hres = IHTMLElement_put_className(elem, tmp);
2915 IHTMLElement_Release(elem);
2916 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
2919 _test_elem_class(line, unk, class);
2922 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
2923 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
2925 IHTMLElement *elem = _get_elem_iface(line, unk);
2926 BSTR id = (void*)0xdeadbeef;
2929 hres = IHTMLElement_get_id(elem, &id);
2930 IHTMLElement_Release(elem);
2931 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
2934 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
2936 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
2941 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
2942 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
2944 IHTMLElement *elem = _get_elem_iface(line, unk);
2945 BSTR tmp = a2bstr(new_id);
2948 hres = IHTMLElement_put_id(elem, tmp);
2949 IHTMLElement_Release(elem);
2951 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
2953 _test_elem_id(line, unk, new_id);
2956 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
2957 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
2959 IHTMLElement *elem = _get_elem_iface(line, unk);
2963 hres = IHTMLElement_get_title(elem, &title);
2964 IHTMLElement_Release(elem);
2965 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2967 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
2969 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
2971 SysFreeString(title);
2974 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
2975 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
2977 IHTMLElement *elem = _get_elem_iface(line, unk);
2981 tmp = a2bstr(title);
2982 hres = IHTMLElement_put_title(elem, tmp);
2983 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
2985 IHTMLElement_Release(elem);
2989 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
2990 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
2992 IHTMLDOMNode *node = _get_node_iface(line, unk);
2996 hres = IHTMLDOMNode_get_nodeValue(node, &var);
2997 IHTMLDOMNode_Release(node);
2998 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3001 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
3002 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
3004 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
3010 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
3011 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
3013 IHTMLDOMNode *node = _get_node_iface(line, unk);
3017 V_VT(&var) = VT_BSTR;
3018 V_BSTR(&var) = a2bstr(val);
3020 hres = IHTMLDOMNode_put_nodeValue(node, var);
3021 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3022 IHTMLDOMNode_Release(node);
3026 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
3027 static void _test_elem_client_size(unsigned line, IUnknown *unk)
3029 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3033 hres = IHTMLElement2_get_clientWidth(elem, &l);
3034 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
3035 hres = IHTMLElement2_get_clientHeight(elem, &l);
3036 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
3038 IHTMLElement2_Release(elem);
3041 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
3042 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
3044 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3048 hres = IHTMLElement2_get_clientLeft(elem, &l);
3049 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
3050 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
3052 hres = IHTMLElement2_get_clientTop(elem, &l);
3053 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
3054 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
3056 IHTMLElement2_Release(elem);
3059 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
3060 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
3062 IHTMLFormElement *form = _get_form_iface(line, unk);
3063 LONG len = 0xdeadbeef;
3066 hres = IHTMLFormElement_get_length(form, &len);
3067 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
3068 ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
3070 IHTMLFormElement_Release(form);
3073 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
3074 static void _test_form_action(unsigned line, IUnknown *unk, const char *ex)
3076 IHTMLFormElement *form = _get_form_iface(line, unk);
3077 BSTR action = (void*)0xdeadbeef;
3080 hres = IHTMLFormElement_get_action(form, &action);
3081 ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
3083 ok_(__FILE__,line)(!strcmp_wa(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), ex);
3085 ok_(__FILE__,line)(!action, "action=%p\n", action);
3087 SysFreeString(action);
3088 IHTMLFormElement_Release(form);
3091 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
3092 static void _test_form_put_action(unsigned line, IUnknown *unk, const char *action)
3094 IHTMLFormElement *form = _get_form_iface(line, unk);
3095 BSTR tmp = a2bstr(action);
3098 hres = IHTMLFormElement_put_action(form, tmp);
3099 ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
3101 IHTMLFormElement_Release(form);
3103 _test_form_action(line, unk, action);
3106 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
3107 static void _test_form_method(unsigned line, IUnknown *unk, const char *ex)
3109 IHTMLFormElement *form = _get_form_iface(line, unk);
3110 BSTR method = (void*)0xdeadbeef;
3113 hres = IHTMLFormElement_get_method(form, &method);
3114 ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
3116 ok_(__FILE__,line)(!strcmp_wa(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), ex);
3118 ok_(__FILE__,line)(!method, "method=%p\n", method);
3120 SysFreeString(method);
3121 IHTMLFormElement_Release(form);
3124 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
3125 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *method)
3127 IHTMLFormElement *form = _get_form_iface(line, unk);
3128 BSTR tmp = a2bstr(method);
3131 hres = IHTMLFormElement_put_method(form, tmp);
3132 ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
3134 IHTMLFormElement_Release(form);
3136 if(exp_hres == S_OK)
3137 _test_form_method(line, unk, method);
3140 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
3141 static void _test_form_name(unsigned line, IUnknown *unk, const char *ex)
3143 IHTMLFormElement *form = _get_form_iface(line, unk);
3144 BSTR name = (void*)0xdeadbeef;
3147 hres = IHTMLFormElement_get_name(form, &name);
3148 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3150 ok_(__FILE__,line)(!strcmp_wa(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), ex);
3152 ok_(__FILE__,line)(!name, "name=%p\n", name);
3154 SysFreeString(name);
3155 IHTMLFormElement_Release(form);
3158 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
3159 static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
3161 IHTMLFormElement *form = _get_form_iface(line, unk);
3162 BSTR tmp = a2bstr(name);
3165 hres = IHTMLFormElement_put_name(form, tmp);
3166 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
3168 IHTMLFormElement_Release(form);
3170 _test_form_name(line, unk, name);
3173 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
3174 static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
3176 IHTMLFormElement *form = _get_form_iface(line, unk);
3177 BSTR encoding = (void*)0xdeadbeef;
3180 hres = IHTMLFormElement_get_encoding(form, &encoding);
3181 ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
3183 ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
3185 ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
3187 SysFreeString(encoding);
3188 IHTMLFormElement_Release(form);
3191 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
3192 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
3194 IHTMLFormElement *form = _get_form_iface(line, unk);
3195 BSTR tmp = a2bstr(encoding);
3198 hres = IHTMLFormElement_put_encoding(form, tmp);
3199 ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
3201 IHTMLFormElement_Release(form);
3203 if(exp_hres == S_OK)
3204 _test_form_encoding(line, unk, encoding);
3207 #define test_form_elements(a) _test_form_elements(__LINE__,a)
3208 static void _test_form_elements(unsigned line, IUnknown *unk)
3210 IHTMLFormElement *form = _get_form_iface(line, unk);
3215 hres = IHTMLFormElement_get_elements(form, &disp);
3216 ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
3217 ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
3218 ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
3220 IDispatch_Release(disp);
3221 IHTMLFormElement_Release(form);
3224 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
3225 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
3227 IHTMLElement *elem = _get_elem_iface(line, unk);
3228 IHTMLDocument2 *doc;
3233 hres = IHTMLElement_get_document(elem, &disp);
3234 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3235 ok(disp != NULL, "disp == NULL\n");
3237 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
3238 IDispatch_Release(disp);
3239 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
3244 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
3245 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const char *attr_name, BOOL expect_success)
3247 IHTMLElement4 *elem = _get_elem4_iface(line, unk);
3248 BSTR str = a2bstr(attr_name);
3249 IHTMLDOMAttribute *attr;
3252 attr = (void*)0xdeadbeef;
3253 hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
3254 ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
3256 ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
3258 ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
3260 IHTMLElement4_Release(elem);
3265 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
3266 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
3270 hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
3271 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3272 ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
3275 #define get_window_doc(e) _get_window_doc(__LINE__,e)
3276 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
3278 IHTMLDocument2 *doc;
3282 hres = IHTMLWindow2_get_document(window, &doc);
3283 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3284 ok(doc != NULL, "disp == NULL\n");
3289 #define doc_get_body(d) _doc_get_body(__LINE__,d)
3290 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
3295 hres = IHTMLDocument2_get_body(doc, &elem);
3296 ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
3297 ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
3302 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
3303 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
3305 IHTMLElement *elem = NULL;
3310 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
3311 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3312 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
3318 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
3319 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
3321 IHTMLDocument3 *doc3;
3322 IHTMLDOMNode *node = NULL;
3326 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3327 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
3330 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
3331 IHTMLDocument3_Release(doc3);
3333 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
3334 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
3339 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
3340 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
3342 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3343 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
3344 IHTMLDOMNode *new_child = NULL;
3347 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
3348 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
3349 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3350 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3352 IHTMLDOMNode_Release(node);
3353 IHTMLDOMNode_Release(child);
3358 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
3359 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
3361 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
3362 IHTMLDOMNode *new_child = NULL;
3365 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
3366 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
3367 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
3368 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
3370 IHTMLDOMNode_Release(node);
3375 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
3376 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
3378 IHTMLDOMNode *node = _get_node_iface(line, unk);
3379 IHTMLDOMNode *new_node = NULL;
3382 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
3383 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
3384 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
3385 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
3387 IHTMLDOMNode_Release(node);
3388 IHTMLDOMNode_Release(new_node);
3391 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
3392 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
3397 hres = IHTMLDocument2_get_title(doc, &title);
3398 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3399 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3400 SysFreeString(title);
3403 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
3404 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
3409 tmp = a2bstr(title);
3410 hres = IHTMLDocument2_put_title(doc, tmp);
3411 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3415 static void test_elem_bounding_client_rect(IUnknown *unk)
3417 IHTMLRect *rect, *rect2;
3418 IHTMLElement2 *elem2;
3422 elem2 = get_elem2_iface(unk);
3423 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
3424 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3425 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
3426 IHTMLElement2_Release(elem2);
3427 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
3428 ok(rect != NULL, "rect == NULL\n");
3429 ok(rect != rect2, "rect == rect2\n");
3430 IHTMLRect_Release(rect2);
3432 test_disp((IUnknown*)rect, &IID_IHTMLRect, "[object]");
3435 hres = IHTMLRect_get_top(rect, &l);
3436 ok(hres == S_OK, "get_top failed: %08x\n", hres);
3437 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3440 hres = IHTMLRect_get_left(rect, &l);
3441 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3442 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3445 hres = IHTMLRect_get_bottom(rect, &l);
3446 ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
3447 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3450 hres = IHTMLRect_get_right(rect, &l);
3451 ok(hres == S_OK, "get_right failed: %08x\n", hres);
3452 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
3454 IHTMLRect_Release(rect);
3457 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
3458 const elem_type_t *elem_types, LONG len)
3461 VARIANT name, index;
3465 V_VT(&index) = VT_EMPTY;
3466 V_VT(&name) = VT_BSTR;
3467 V_BSTR(&name) = a2bstr(n);
3469 hres = IHTMLElementCollection_item(col, name, index, &disp);
3470 ok(hres == S_OK, "item failed: %08x\n", hres);
3472 test_elem_collection((IUnknown*)disp, elem_types, len);
3473 IDispatch_Release(disp);
3474 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
3478 V_VT(&index) = VT_I4;
3480 for(i=0; i<len; i++) {
3482 disp = (void*)0xdeadbeef;
3483 hres = IHTMLElementCollection_item(col, name, index, &disp);
3484 ok(hres == S_OK, "item failed: %08x\n", hres);
3485 ok(disp != NULL, "disp == NULL\n");
3486 if(FAILED(hres) || !disp)
3489 test_elem_type((IUnknown*)disp, elem_types[i]);
3491 IDispatch_Release(disp);
3495 disp = (void*)0xdeadbeef;
3496 hres = IHTMLElementCollection_item(col, name, index, &disp);
3497 ok(hres == S_OK, "item failed: %08x\n", hres);
3498 ok(disp == NULL, "disp != NULL\n");
3501 disp = (void*)0xdeadbeef;
3502 hres = IHTMLElementCollection_item(col, name, index, &disp);
3503 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3504 ok(disp == NULL, "disp != NULL\n");
3507 SysFreeString(V_BSTR(&name));
3510 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
3512 IHTMLElementCollection *col;
3514 IDispatch *disp = (void*)0xdeadbeef;
3515 VARIANT name, index;
3518 hres = IHTMLDocument2_get_all(doc, &col);
3519 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3520 ok(col != NULL, "col == NULL\n");
3521 if(FAILED(hres) || !col)
3524 V_VT(&index) = VT_EMPTY;
3525 V_VT(&name) = VT_BSTR;
3526 V_BSTR(&name) = a2bstr(id);
3528 hres = IHTMLElementCollection_item(col, name, index, &disp);
3529 IHTMLElementCollection_Release(col);
3530 SysFreeString(V_BSTR(&name));
3531 ok(hres == S_OK, "item failed: %08x\n", hres);
3532 if(!expect_success) {
3533 ok(disp == NULL, "disp != NULL\n");
3537 ok(disp != NULL, "disp == NULL\n");
3541 elem = get_elem_iface((IUnknown*)disp);
3542 IDispatch_Release(disp);
3547 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
3549 IHTMLDocument3 *doc3;
3554 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
3555 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
3558 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
3560 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
3562 IHTMLDocument3_Release(doc3);
3567 static void test_select_elem(IHTMLSelectElement *select)
3569 IDispatch *disp, *disp2;
3570 VARIANT name, index;
3573 test_select_type(select, "select-one");
3574 test_select_length(select, 2);
3575 test_select_selidx(select, 0);
3576 test_select_put_selidx(select, 1);
3578 test_select_set_value(select, "val1");
3579 test_select_value(select, "val1");
3581 test_select_get_disabled(select, VARIANT_FALSE);
3582 test_select_set_disabled(select, VARIANT_TRUE);
3583 test_select_set_disabled(select, VARIANT_FALSE);
3586 hres = IHTMLSelectElement_get_options(select, &disp);
3587 ok(hres == S_OK, "get_options failed: %08x\n", hres);
3588 ok(disp != NULL, "options == NULL\n");
3589 ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
3590 IDispatch_Release(disp);
3592 V_VT(&index) = VT_EMPTY;
3593 V_VT(&name) = VT_I4;
3595 disp = (void*)0xdeadbeef;
3596 hres = IHTMLSelectElement_item(select, name, index, &disp);
3597 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3598 ok(!disp, "disp = %p\n", disp);
3601 disp = (void*)0xdeadbeef;
3602 hres = IHTMLSelectElement_item(select, name, index, &disp);
3603 ok(hres == S_OK, "item failed: %08x\n", hres);
3604 ok(!disp, "disp = %p\n", disp);
3607 hres = IHTMLSelectElement_item(select, name, index, NULL);
3608 ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
3611 hres = IHTMLSelectElement_item(select, name, index, &disp);
3612 ok(hres == S_OK, "item failed: %08x\n", hres);
3613 ok(disp != NULL, "disp = NULL\n");
3614 test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, NULL);
3616 V_VT(&index) = VT_I4;
3619 hres = IHTMLSelectElement_item(select, name, index, &disp2);
3620 ok(hres == S_OK, "item failed: %08x\n", hres);
3621 ok(disp2 != NULL, "disp = NULL\n");
3622 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3623 IDispatch_Release(disp2);
3624 IDispatch_Release(disp);
3627 static void test_form_item(IHTMLElement *elem)
3629 IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
3630 IDispatch *disp, *disp2;
3631 VARIANT name, index;
3634 V_VT(&index) = VT_EMPTY;
3635 V_VT(&name) = VT_I4;
3637 disp = (void*)0xdeadbeef;
3638 hres = IHTMLFormElement_item(form, name, index, &disp);
3639 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3640 ok(!disp, "disp = %p\n", disp);
3643 disp = (void*)0xdeadbeef;
3644 hres = IHTMLFormElement_item(form, name, index, &disp);
3645 ok(hres == S_OK, "item failed: %08x\n", hres);
3646 ok(!disp, "disp = %p\n", disp);
3649 hres = IHTMLFormElement_item(form, name, index, NULL);
3650 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3653 hres = IHTMLFormElement_item(form, name, index, &disp);
3654 ok(hres == S_OK, "item failed: %08x\n", hres);
3655 ok(disp != NULL, "disp = NULL\n");
3656 test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, NULL);
3658 V_VT(&index) = VT_I4;
3661 hres = IHTMLFormElement_item(form, name, index, &disp2);
3662 ok(hres == S_OK, "item failed: %08x\n", hres);
3663 ok(disp2 != NULL, "disp = NULL\n");
3664 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
3665 IDispatch_Release(disp2);
3666 IDispatch_Release(disp);
3669 static void test_create_option_elem(IHTMLDocument2 *doc)
3671 IHTMLOptionElement *option;
3673 option = create_option_elem(doc, "test text", "test value");
3675 test_option_put_text(option, "new text");
3676 test_option_put_value(option, "new value");
3677 test_option_put_selected(option, VARIANT_TRUE);
3678 test_option_put_selected(option, VARIANT_FALSE);
3680 IHTMLOptionElement_Release(option);
3683 static void test_create_img_elem(IHTMLDocument2 *doc)
3685 IHTMLImgElement *img;
3687 img = create_img_elem(doc, 10, 15);
3690 test_img_put_width(img, 5);
3691 test_img_put_height(img, 20);
3693 IHTMLImgElement_Release(img);
3697 img = create_img_elem(doc, -1, -1);
3700 test_img_put_width(img, 5);
3701 test_img_put_height(img, 20);
3703 IHTMLImgElement_Release(img);
3707 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
3709 IHTMLBodyElement *body;
3710 IHTMLTxtRange *range;
3714 elem = doc_get_body(doc);
3715 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
3716 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3717 IHTMLElement_Release(elem);
3719 hres = IHTMLBodyElement_createTextRange(body, &range);
3720 IHTMLBodyElement_Release(body);
3721 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
3726 static void test_txtrange(IHTMLDocument2 *doc)
3728 IHTMLTxtRange *body_range, *range, *range2;
3729 IHTMLSelectionObject *selection;
3730 IDispatch *disp_range;
3733 body_range = test_create_body_range(doc);
3735 test_range_text(body_range, "test abc 123\r\nit's text");
3737 hres = IHTMLTxtRange_duplicate(body_range, &range);
3738 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3740 hres = IHTMLTxtRange_duplicate(body_range, &range2);
3741 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3742 test_range_isequal(range, range2, VARIANT_TRUE);
3744 test_range_text(range, "test abc 123\r\nit's text");
3745 test_range_text(body_range, "test abc 123\r\nit's text");
3747 test_range_collapse(range, TRUE);
3748 test_range_isequal(range, range2, VARIANT_FALSE);
3749 test_range_inrange(range, range2, VARIANT_FALSE);
3750 test_range_inrange(range2, range, VARIANT_TRUE);
3751 IHTMLTxtRange_Release(range2);
3753 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3754 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
3755 test_range_move(range, characterW, 2, 2);
3756 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3758 test_range_collapse(range, FALSE);
3759 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
3761 test_range_collapse(range, FALSE);
3762 test_range_expand(range, wordW, VARIANT_TRUE, "123");
3763 test_range_expand(range, wordW, VARIANT_FALSE, "123");
3764 test_range_move(range, characterW, 2, 2);
3765 test_range_expand(range, wordW, VARIANT_TRUE, "123");
3766 test_range_moveend(range, characterW, -5, -5);
3767 test_range_text(range, NULL);
3768 test_range_moveend(range, characterW, 3, 3);
3769 test_range_text(range, "c 1");
3770 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
3771 test_range_collapse(range, TRUE);
3772 test_range_move(range, characterW, 4, 4);
3773 test_range_moveend(range, characterW, 1, 1);
3774 test_range_text(range, " ");
3775 test_range_move(range, wordW, 1, 1);
3776 test_range_moveend(range, characterW, 2, 2);
3777 test_range_text(range, "ab");
3779 IHTMLTxtRange_Release(range);
3781 hres = IHTMLTxtRange_duplicate(body_range, &range);
3782 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3784 test_range_text(range, "test abc 123\r\nit's text");
3785 test_range_move(range, characterW, 3, 3);
3786 test_range_moveend(range, characterW, 1, 1);
3787 test_range_text(range, "t");
3788 test_range_moveend(range, characterW, 3, 3);
3789 test_range_text(range, "t ab");
3790 test_range_moveend(range, characterW, -2, -2);
3791 test_range_text(range, "t ");
3792 test_range_move(range, characterW, 6, 6);
3793 test_range_moveend(range, characterW, 3, 3);
3794 test_range_text(range, "123");
3795 test_range_moveend(range, characterW, 2, 2);
3796 test_range_text(range, "123\r\ni");
3798 IHTMLTxtRange_Release(range);
3800 hres = IHTMLTxtRange_duplicate(body_range, &range);
3801 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3803 test_range_move(range, wordW, 1, 1);
3804 test_range_moveend(range, characterW, 2, 2);
3805 test_range_text(range, "ab");
3807 test_range_move(range, characterW, -2, -2);
3808 test_range_moveend(range, characterW, 2, 2);
3809 test_range_text(range, "t ");
3811 test_range_move(range, wordW, 3, 3);
3812 test_range_move(range, wordW, -2, -2);
3813 test_range_moveend(range, characterW, 2, 2);
3814 test_range_text(range, "ab");
3816 test_range_move(range, characterW, -6, -5);
3817 test_range_moveend(range, characterW, -1, 0);
3818 test_range_moveend(range, characterW, -6, 0);
3819 test_range_move(range, characterW, 2, 2);
3820 test_range_moveend(range, characterW, 2, 2);
3821 test_range_text(range, "st");
3822 test_range_moveend(range, characterW, -6, -4);
3823 test_range_moveend(range, characterW, 2, 2);
3825 IHTMLTxtRange_Release(range);
3827 hres = IHTMLTxtRange_duplicate(body_range, &range);
3828 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3830 test_range_move(range, wordW, 2, 2);
3831 test_range_moveend(range, characterW, 2, 2);
3832 test_range_text(range, "12");
3834 test_range_move(range, characterW, 15, 14);
3835 test_range_move(range, characterW, -2, -2);
3836 test_range_moveend(range, characterW, 3, 2);
3837 test_range_text(range, "t");
3838 test_range_moveend(range, characterW, -1, -1);
3839 test_range_text(range, "t");
3840 test_range_expand(range, wordW, VARIANT_TRUE, "text");
3841 test_range_move(range, characterW, -2, -2);
3842 test_range_moveend(range, characterW, 2, 2);
3843 test_range_text(range, "s ");
3844 test_range_move(range, characterW, 100, 7);
3845 test_range_move(range, wordW, 1, 0);
3846 test_range_move(range, characterW, -2, -2);
3847 test_range_moveend(range, characterW, 3, 2);
3848 test_range_text(range, "t");
3850 IHTMLTxtRange_Release(range);
3852 hres = IHTMLTxtRange_duplicate(body_range, &range);
3853 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
3855 test_range_collapse(range, TRUE);
3856 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
3857 test_range_put_text(range, "word");
3858 test_range_text(body_range, "wordabc 123\r\nit's text");
3859 test_range_text(range, NULL);
3860 test_range_moveend(range, characterW, 3, 3);
3861 test_range_text(range, "abc");
3862 test_range_movestart(range, characterW, -2, -2);
3863 test_range_text(range, "rdabc");
3864 test_range_movestart(range, characterW, 3, 3);
3865 test_range_text(range, "bc");
3866 test_range_movestart(range, characterW, 4, 4);
3867 test_range_text(range, NULL);
3868 test_range_movestart(range, characterW, -3, -3);
3869 test_range_text(range, "c 1");
3870 test_range_movestart(range, characterW, -7, -6);
3871 test_range_text(range, "wordabc 1");
3872 test_range_movestart(range, characterW, 100, 22);
3873 test_range_text(range, NULL);
3875 IHTMLTxtRange_Release(range);
3876 IHTMLTxtRange_Release(body_range);
3878 hres = IHTMLDocument2_get_selection(doc, &selection);
3879 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
3881 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
3882 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
3883 IHTMLSelectionObject_Release(selection);
3885 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
3886 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
3887 IDispatch_Release(disp_range);
3889 test_range_text(range, NULL);
3890 test_range_moveend(range, characterW, 3, 3);
3891 test_range_text(range, "wor");
3892 test_range_parent(range, ET_BODY);
3893 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
3894 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
3895 test_range_move(range, characterW, 3, 3);
3896 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
3897 test_range_moveend(range, characterW, -4, -4);
3898 test_range_put_text(range, "abc def ");
3899 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
3900 test_range_move(range, wordW, 1, 1);
3901 test_range_movestart(range, characterW, -1, -1);
3902 test_range_text(range, " ");
3903 test_range_move(range, wordW, 1, 1);
3904 test_range_moveend(range, characterW, 3, 3);
3905 test_range_text(range, "def");
3906 test_range_put_text(range, "xyz");
3907 test_range_moveend(range, characterW, 1, 1);
3908 test_range_move(range, wordW, 1, 1);
3909 test_range_moveend(range, characterW, 2, 2);
3910 test_range_text(range, "ab");
3912 IHTMLTxtRange_Release(range);
3915 static void test_txtrange2(IHTMLDocument2 *doc)
3917 IHTMLTxtRange *range;
3919 range = test_create_body_range(doc);
3921 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
3922 test_range_move(range, characterW, 5, 5);
3923 test_range_moveend(range, characterW, 1, 1);
3924 test_range_text(range, "2");
3925 test_range_move(range, characterW, -3, -3);
3926 test_range_moveend(range, characterW, 3, 3);
3927 test_range_text(range, "c\r\n\r\n1");
3928 test_range_collapse(range, VARIANT_FALSE);
3929 test_range_moveend(range, characterW, 4, 4);
3930 test_range_text(range, "23");
3931 test_range_moveend(range, characterW, 1, 1);
3932 test_range_text(range, "23\r\n\r\n\r\nd");
3933 test_range_moveend(range, characterW, -1, -1);
3934 test_range_text(range, "23");
3935 test_range_moveend(range, characterW, -1, -1);
3936 test_range_text(range, "23");
3937 test_range_moveend(range, characterW, -2, -2);
3938 test_range_text(range, "2");
3940 IHTMLTxtRange_Release(range);
3943 static void test_compatmode(IHTMLDocument2 *doc)
3945 IHTMLDocument5 *doc5;
3949 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
3950 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
3954 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
3955 IHTMLDocument5_Release(doc5);
3956 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
3957 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
3958 SysFreeString(mode);
3961 static void test_location(IHTMLDocument2 *doc)
3963 IHTMLLocation *location, *location2;
3964 IHTMLWindow2 *window;
3969 hres = IHTMLDocument2_get_location(doc, &location);
3970 ok(hres == S_OK, "get_location failed: %08x\n", hres);
3972 hres = IHTMLDocument2_get_location(doc, &location2);
3973 ok(hres == S_OK, "get_location failed: %08x\n", hres);
3975 ok(location == location2, "location != location2\n");
3976 IHTMLLocation_Release(location2);
3978 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3979 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3981 hres = IHTMLWindow2_get_location(window, &location2);
3982 ok(hres == S_OK, "get_location failed: %08x\n", hres);
3983 ok(location == location2, "location != location2\n");
3984 IHTMLLocation_Release(location2);
3986 test_ifaces((IUnknown*)location, location_iids);
3987 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
3989 hres = IHTMLLocation_get_pathname(location, &str);
3990 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
3991 ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
3994 hres = IHTMLLocation_get_href(location, NULL);
3995 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
3997 hres = IHTMLLocation_get_href(location, &str);
3998 ok(hres == S_OK, "get_href failed: %08x\n", hres);
3999 ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
4002 ref = IHTMLLocation_Release(location);
4003 ok(!ref, "location chould be destroyed here\n");
4006 static void test_plugins_col(IHTMLDocument2 *doc)
4008 IHTMLPluginsCollection *col, *col2;
4009 IHTMLWindow2 *window;
4015 window = get_doc_window(doc);
4016 hres = IHTMLWindow2_get_navigator(window, &nav);
4017 IHTMLWindow2_Release(window);
4019 hres = IOmNavigator_get_plugins(nav, &col);
4020 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4022 hres = IOmNavigator_get_plugins(nav, &col2);
4023 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4024 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4025 IHTMLPluginsCollection_Release(col2);
4027 test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, "[object]");
4030 hres = IHTMLPluginsCollection_get_length(col, &len);
4031 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4032 ok(!len, "length = %d\n", len);
4034 ref = IHTMLPluginsCollection_Release(col);
4035 ok(!ref, "ref=%d\n", ref);
4037 IOmNavigator_Release(nav);
4040 static void test_mime_types_col(IOmNavigator *nav)
4042 IHTMLMimeTypesCollection *col, *col2;
4047 hres = IOmNavigator_get_mimeTypes(nav, &col);
4048 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4050 hres = IOmNavigator_get_mimeTypes(nav, &col2);
4051 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4052 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4053 IHTMLMimeTypesCollection_Release(col2);
4055 test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, "[object]");
4057 length = 0xdeadbeef;
4058 hres = IHTMLMimeTypesCollection_get_length(col, &length);
4059 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4060 ok(!length, "length = %d\n", length);
4062 ref = IHTMLMimeTypesCollection_Release(col);
4063 ok(!ref, "ref=%d\n", ref);
4066 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
4067 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
4072 if(pLCIDToLocaleName) {
4073 res = pLCIDToLocaleName(lcid, buf, sizeof(buf)/sizeof(WCHAR), 0);
4074 ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
4075 ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
4077 win_skip("LCIDToLocaleName not available, unable to test language string\n");
4078 ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
4082 static void test_navigator(IHTMLDocument2 *doc)
4084 IHTMLWindow2 *window;
4085 IOmNavigator *navigator, *navigator2;
4092 static const WCHAR v40[] = {'4','.','0'};
4094 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4095 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
4097 hres = IHTMLWindow2_get_navigator(window, &navigator);
4098 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4099 ok(navigator != NULL, "navigator == NULL\n");
4100 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
4102 hres = IHTMLWindow2_get_navigator(window, &navigator2);
4103 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
4104 ok(navigator != navigator2, "navigator2 != navihgator\n");
4106 IHTMLWindow2_Release(window);
4107 IOmNavigator_Release(navigator2);
4109 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
4110 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
4111 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4112 SysFreeString(bstr);
4115 hres = IOmNavigator_get_appName(navigator, &bstr);
4116 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
4117 ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
4118 SysFreeString(bstr);
4121 hres = IOmNavigator_get_platform(navigator, &bstr);
4122 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
4123 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "Win64" : "Win32")
4124 || (sizeof(void*) == 8 && broken(!strcmp_wa(bstr, "Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
4125 SysFreeString(bstr);
4128 hres = IOmNavigator_get_cpuClass(navigator, &bstr);
4129 ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
4130 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "x64" : "x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
4131 SysFreeString(bstr);
4134 hres = IOmNavigator_get_appVersion(navigator, &bstr);
4135 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4136 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
4137 SysFreeString(bstr);
4140 hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
4141 ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
4142 test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
4143 SysFreeString(bstr);
4145 if (pGetUserDefaultUILanguage)
4148 hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
4149 ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
4150 test_language_string(bstr, pGetUserDefaultUILanguage());
4151 SysFreeString(bstr);
4154 win_skip("GetUserDefaultUILanguage not available\n");
4157 hres = IOmNavigator_get_userLanguage(navigator, &bstr);
4158 ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
4159 test_language_string(bstr, LOCALE_USER_DEFAULT);
4160 SysFreeString(bstr);
4162 hres = IOmNavigator_toString(navigator, NULL);
4163 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4166 hres = IOmNavigator_toString(navigator, &bstr);
4167 ok(hres == S_OK, "toString failed: %08x\n", hres);
4168 ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
4169 SysFreeString(bstr);
4172 hres = ObtainUserAgentString(0, buf, &size);
4173 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
4176 hres = IOmNavigator_get_userAgent(navigator, &bstr);
4177 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
4178 ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
4179 SysFreeString(bstr);
4181 if(!strncmp(buf, "Mozilla/", 8)) {
4183 hres = IOmNavigator_get_appVersion(navigator, &bstr);
4184 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
4185 ok(!strcmp_wa(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf+8);
4186 SysFreeString(bstr);
4188 skip("nonstandard user agent\n");
4192 hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
4193 ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
4194 ok(bstr != NULL, "appMinorVersion returned NULL\n");
4195 SysFreeString(bstr);
4197 test_mime_types_col(navigator);
4199 ref = IOmNavigator_Release(navigator);
4200 ok(!ref, "navigator should be destroyed here\n");
4203 static void test_screen(IHTMLWindow2 *window)
4205 IHTMLScreen *screen, *screen2;
4206 IDispatchEx *dispex;
4213 hres = IHTMLWindow2_get_screen(window, &screen);
4214 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4215 ok(screen != NULL, "screen == NULL\n");
4218 hres = IHTMLWindow2_get_screen(window, &screen2);
4219 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
4220 ok(screen2 != NULL, "screen == NULL\n");
4221 ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
4222 IHTMLScreen_Release(screen2);
4224 hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
4225 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
4226 if(SUCCEEDED(hres)) {
4227 test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
4228 IDispatchEx_Release(dispex);
4231 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
4233 exl = GetDeviceCaps(hdc, HORZRES);
4235 hres = IHTMLScreen_get_width(screen, &l);
4236 ok(hres == S_OK, "get_width failed: %08x\n", hres);
4237 ok(l == exl, "width = %d, expected %d\n", l, exl);
4239 exl = GetDeviceCaps(hdc, VERTRES);
4241 hres = IHTMLScreen_get_height(screen, &l);
4242 ok(hres == S_OK, "get_height failed: %08x\n", hres);
4243 ok(l == exl, "height = %d, expected %d\n", l, exl);
4245 exl = GetDeviceCaps(hdc, BITSPIXEL);
4247 hres = IHTMLScreen_get_colorDepth(screen, &l);
4248 ok(hres == S_OK, "get_height failed: %08x\n", hres);
4249 ok(l == exl, "height = %d, expected %d\n", l, exl);
4253 SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
4256 hres = IHTMLScreen_get_availHeight(screen, &l);
4257 ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
4258 ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
4261 hres = IHTMLScreen_get_availWidth(screen, &l);
4262 ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
4263 ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
4265 IHTMLScreen_Release(screen);
4268 static void test_default_selection(IHTMLDocument2 *doc)
4270 IHTMLSelectionObject *selection;
4271 IHTMLTxtRange *range;
4276 hres = IHTMLDocument2_get_selection(doc, &selection);
4277 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
4279 hres = IHTMLSelectionObject_get_type(selection, &str);
4280 ok(hres == S_OK, "get_type failed: %08x\n", hres);
4281 ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
4284 hres = IHTMLSelectionObject_createRange(selection, &disp);
4285 IHTMLSelectionObject_Release(selection);
4286 ok(hres == S_OK, "createRange failed: %08x\n", hres);
4288 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
4289 IDispatch_Release(disp);
4290 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
4292 test_range_text(range, NULL);
4293 IHTMLTxtRange_Release(range);
4296 static void test_doc_elem(IHTMLDocument2 *doc)
4298 IHTMLDocument2 *doc_node, *owner_doc;
4300 IHTMLDocument3 *doc3;
4303 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4304 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
4306 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
4307 IHTMLDocument3_Release(doc3);
4308 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4310 test_node_name((IUnknown*)elem, "HTML");
4311 test_elem_tag((IUnknown*)elem, "HTML");
4313 doc_node = get_doc_node(doc);
4314 owner_doc = get_owner_doc((IUnknown*)elem);
4315 ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
4316 IHTMLDocument2_Release(owner_doc);
4318 owner_doc = get_owner_doc((IUnknown*)doc_node);
4319 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4320 IHTMLDocument2_Release(doc_node);
4322 test_elem_client_rect((IUnknown*)elem);
4324 IHTMLElement_Release(elem);
4327 static void test_default_body(IHTMLBodyElement *body)
4334 bstr = (void*)0xdeadbeef;
4335 hres = IHTMLBodyElement_get_background(body, &bstr);
4336 ok(hres == S_OK, "get_background failed: %08x\n", hres);
4337 ok(bstr == NULL, "bstr != NULL\n");
4339 l = elem_get_scroll_height((IUnknown*)body);
4340 ok(l != -1, "scrollHeight == -1\n");
4341 l = elem_get_scroll_width((IUnknown*)body);
4342 ok(l != -1, "scrollWidth == -1\n");
4343 l = elem_get_scroll_top((IUnknown*)body);
4344 ok(!l, "scrollTop = %d\n", l);
4345 elem_get_scroll_left((IUnknown*)body);
4347 /* get_text tests */
4348 hres = IHTMLBodyElement_get_text(body, &v);
4349 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4350 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4351 ok(bstr == NULL, "bstr != NULL\n");
4353 /* get_text - Invalid Text */
4355 V_BSTR(&v) = a2bstr("Invalid");
4356 hres = IHTMLBodyElement_put_text(body, v);
4357 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4361 hres = IHTMLBodyElement_get_text(body, &v);
4362 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4363 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4364 ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
4367 /* get_text - Valid Text */
4369 V_BSTR(&v) = a2bstr("#FF0000");
4370 hres = IHTMLBodyElement_put_text(body, v);
4371 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4375 hres = IHTMLBodyElement_get_text(body, &v);
4376 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
4377 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
4378 ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
4382 static void test_body_funs(IHTMLBodyElement *body)
4384 VARIANT vbg, vDefaultbg;
4387 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
4388 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4389 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
4390 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
4392 V_VT(&vbg) = VT_BSTR;
4393 V_BSTR(&vbg) = a2bstr("red");
4394 hres = IHTMLBodyElement_put_bgColor(body, vbg);
4395 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4398 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
4399 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
4400 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
4401 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
4404 /* Restore Originial */
4405 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
4406 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
4407 VariantClear(&vDefaultbg);
4410 static void test_window(IHTMLDocument2 *doc)
4412 IHTMLWindow2 *window, *window2, *self;
4413 IHTMLDocument2 *doc2 = NULL;
4419 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4420 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4421 test_ifaces((IUnknown*)window, window_iids);
4422 hres = IDispatch_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
4424 IUnknown_Release(unk);
4426 win_skip("IID_ITravelLogClient not supported\n");
4428 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
4430 hres = IHTMLWindow2_get_document(window, &doc2);
4431 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4432 ok(doc2 != NULL, "doc2 == NULL\n");
4434 test_ifaces((IUnknown*)doc2, doc_node_iids);
4435 test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
4436 test_class_info((IUnknown*)doc2);
4438 test_ifaces((IUnknown*)doc, doc_obj_iids);
4439 test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, "[object]");
4440 test_class_info((IUnknown*)doc);
4442 unk = (void*)0xdeadbeef;
4443 hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
4444 ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
4445 ok(!unk, "unk = %p\n", unk);
4447 IHTMLDocument_Release(doc2);
4449 hres = IHTMLWindow2_get_window(window, &window2);
4450 ok(hres == S_OK, "get_window failed: %08x\n", hres);
4451 ok(window2 != NULL, "window2 == NULL\n");
4453 hres = IHTMLWindow2_get_self(window, &self);
4454 ok(hres == S_OK, "get_self failed: %08x\n", hres);
4455 ok(window2 != NULL, "self == NULL\n");
4457 ok(self == window2, "self != window2\n");
4459 IHTMLWindow2_Release(window2);
4460 IHTMLWindow2_Release(self);
4463 hres = IHTMLDocument2_get_Script(doc, &disp);
4464 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4465 ok(disp == (void*)window, "disp != window\n");
4466 IDispatch_Release(disp);
4468 hres = IHTMLWindow2_toString(window, NULL);
4469 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4472 hres = IHTMLWindow2_toString(window, &str);
4473 ok(hres == S_OK, "toString failed: %08x\n", hres);
4474 ok(!strcmp_wa(str, "[object]") ||
4475 !strcmp_wa(str, "[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
4478 test_window_name(window, NULL);
4479 set_window_name(window, "test");
4480 test_window_length(window, 0);
4481 test_screen(window);
4482 test_window_status(window);
4483 set_window_status(window, "Test!");
4485 IHTMLWindow2_Release(window);
4488 static void test_defaults(IHTMLDocument2 *doc)
4490 IHTMLStyleSheetsCollection *stylesheetcol;
4491 IHTMLCurrentStyle *cstyle;
4492 IHTMLBodyElement *body;
4493 IHTMLElement2 *elem2;
4498 IHTMLElementCollection *collection;
4500 elem = doc_get_body(doc);
4502 hres = IHTMLDocument2_get_images(doc, NULL);
4503 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4505 hres = IHTMLDocument2_get_images(doc, &collection);
4506 ok(hres == S_OK, "get_images failed: %08x\n", hres);
4509 test_elem_collection((IUnknown*)collection, NULL, 0);
4510 IHTMLElementCollection_Release(collection);
4513 hres = IHTMLDocument2_get_applets(doc, NULL);
4514 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4516 hres = IHTMLDocument2_get_applets(doc, &collection);
4517 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4520 test_elem_collection((IUnknown*)collection, NULL, 0);
4521 IHTMLElementCollection_Release(collection);
4524 hres = IHTMLDocument2_get_links(doc, NULL);
4525 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4527 hres = IHTMLDocument2_get_links(doc, &collection);
4528 ok(hres == S_OK, "get_links failed: %08x\n", hres);
4531 test_elem_collection((IUnknown*)collection, NULL, 0);
4532 IHTMLElementCollection_Release(collection);
4535 hres = IHTMLDocument2_get_forms(doc, NULL);
4536 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4538 hres = IHTMLDocument2_get_forms(doc, &collection);
4539 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4542 test_elem_collection((IUnknown*)collection, NULL, 0);
4543 IHTMLElementCollection_Release(collection);
4546 hres = IHTMLDocument2_get_anchors(doc, NULL);
4547 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4549 hres = IHTMLDocument2_get_anchors(doc, &collection);
4550 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4553 test_elem_collection((IUnknown*)collection, NULL, 0);
4554 IHTMLElementCollection_Release(collection);
4557 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4558 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
4559 test_default_body(body);
4560 test_body_funs(body);
4561 IHTMLBodyElement_Release(body);
4563 hres = IHTMLElement_get_style(elem, &style);
4564 ok(hres == S_OK, "get_style failed: %08x\n", hres);
4566 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
4567 test_ifaces((IUnknown*)style, style_iids);
4568 IHTMLStyle_Release(style);
4571 test_compatmode(doc);
4573 test_navigator(doc);
4574 test_plugins_col(doc);
4576 elem2 = get_elem2_iface((IUnknown*)elem);
4577 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
4578 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
4579 if(SUCCEEDED(hres)) {
4582 test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, "[object]");
4583 test_ifaces((IUnknown*)cstyle, cstyle_iids);
4585 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
4587 IUnknown_Release(unk);
4590 /*IE6 doesn't have interface */
4591 win_skip("IID_IHTMLCurrentStyle4 not supported\n");
4594 IHTMLCurrentStyle_Release(cstyle);
4596 IHTMLElement2_Release(elem2);
4598 IHTMLElement_Release(elem);
4600 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
4601 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4604 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
4605 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4606 ok(l == 0, "length = %d\n", l);
4608 IHTMLStyleSheetsCollection_Release(stylesheetcol);
4610 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
4611 ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
4613 test_default_selection(doc);
4614 test_doc_title(doc, "");
4617 static void test_tr_elem(IHTMLElement *elem)
4619 IHTMLElementCollection *col;
4623 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
4625 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
4626 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
4631 hres = IHTMLTableRow_get_cells(row, &col);
4632 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
4633 ok(col != NULL, "get_cells returned NULL\n");
4635 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
4636 IHTMLElementCollection_Release(col);
4638 IHTMLTable_Release(row);
4641 static void test_table_elem(IHTMLElement *elem)
4643 IHTMLElementCollection *col;
4648 static const elem_type_t row_types[] = {ET_TR,ET_TR};
4649 static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
4651 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
4652 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
4657 hres = IHTMLTable_get_rows(table, &col);
4658 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
4659 ok(col != NULL, "get_ros returned NULL\n");
4661 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
4662 IHTMLElementCollection_Release(col);
4664 test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
4666 node = clone_node((IUnknown*)table, VARIANT_TRUE);
4667 test_elem_tag((IUnknown*)node, "TABLE");
4668 test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
4669 IHTMLDOMNode_Release(node);
4671 node = clone_node((IUnknown*)table, VARIANT_FALSE);
4672 test_elem_tag((IUnknown*)node, "TABLE");
4673 test_elem_all((IUnknown*)node, NULL, 0);
4674 IHTMLDOMNode_Release(node);
4676 IHTMLTable_Release(table);
4679 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
4688 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4689 SafeArrayAccessData(sa, (void**)&var);
4690 V_VT(var) = VT_BSTR;
4691 V_BSTR(var) = a2bstr(text);
4692 SafeArrayUnaccessData(sa);
4695 hres = IHTMLDocument2_writeln(doc, sa);
4697 hres = IHTMLDocument2_write(doc, sa);
4698 ok(hres == S_OK, "write failed: %08x\n", hres);
4700 SafeArrayDestroy(sa);
4703 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
4705 IHTMLDocument2 *window_doc, *elem_doc;
4706 IHTMLFrameElement3 *frame_elem3;
4707 IHTMLWindow2 *content_window;
4710 content_window = get_frame_content_window(frame_elem);
4711 window_doc = get_window_doc(content_window);
4712 IHTMLWindow2_Release(content_window);
4714 elem_doc = get_elem_doc(frame_elem);
4715 ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
4718 hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
4719 if(SUCCEEDED(hres)) {
4720 IDispatch *disp = NULL;
4722 hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
4723 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
4724 ok(disp != NULL, "contentDocument == NULL\n");
4725 ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
4727 IDispatch_Release(disp);
4728 IHTMLFrameElement3_Release(frame_elem3);
4730 win_skip("IHTMLFrameElement3 not supported\n");
4734 IHTMLDocument2_Release(elem_doc);
4735 IHTMLDocument2_Release(window_doc);
4738 static void test_iframe_elem(IHTMLElement *elem)
4740 IHTMLDocument2 *content_doc, *owner_doc;
4741 IHTMLElementCollection *col;
4742 IHTMLWindow2 *content_window;
4748 static const elem_type_t all_types[] = {
4756 test_frame_doc((IUnknown*)elem, TRUE);
4758 content_window = get_frame_content_window((IUnknown*)elem);
4759 test_window_length(content_window, 0);
4761 content_doc = get_window_doc(content_window);
4762 IHTMLWindow2_Release(content_window);
4764 str = a2bstr("text/html");
4765 V_VT(&errv) = VT_ERROR;
4767 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
4769 ok(hres == S_OK, "open failed: %08x\n", hres);
4770 ok(disp != NULL, "disp == NULL\n");
4771 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
4772 IDispatch_Release(disp);
4774 doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
4775 doc_write(content_doc, TRUE, "</html>");
4777 hres = IHTMLDocument2_get_all(content_doc, &col);
4778 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4779 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4780 IHTMLElementCollection_Release(col);
4782 hres = IHTMLDocument2_close(content_doc);
4783 ok(hres == S_OK, "close failed: %08x\n", hres);
4785 owner_doc = get_owner_doc((IUnknown*)content_doc);
4786 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
4788 IHTMLDocument2_Release(content_doc);
4791 static void test_stylesheet(IDispatch *disp)
4793 IHTMLStyleSheetRulesCollection *col = NULL;
4794 IHTMLStyleSheet *stylesheet;
4797 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
4798 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
4800 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
4801 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
4802 ok(col != NULL, "col == NULL\n");
4804 IHTMLStyleSheetRulesCollection_Release(col);
4805 IHTMLStyleSheet_Release(stylesheet);
4808 static void test_stylesheets(IHTMLDocument2 *doc)
4810 IHTMLStyleSheetsCollection *col = NULL;
4815 hres = IHTMLDocument2_get_styleSheets(doc, &col);
4816 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4817 ok(col != NULL, "col == NULL\n");
4819 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
4821 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
4822 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4823 ok(len == 1, "len=%d\n", len);
4829 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4830 ok(hres == S_OK, "item failed: %08x\n", hres);
4831 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
4832 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4833 test_stylesheet(V_DISPATCH(&res));
4840 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4841 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4842 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
4843 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4846 IHTMLStyleSheetsCollection_Release(col);
4849 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
4851 IDispatchEx *dispex;
4853 DISPPARAMS dp = {NULL, NULL, 0, 0};
4861 static const WCHAR w0[] = {'0',0};
4862 static const WCHAR w100[] = {'1','0','0',0};
4864 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
4865 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
4867 bstr = SysAllocString(w0);
4868 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4869 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
4870 SysFreeString(bstr);
4873 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
4874 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
4875 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
4876 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
4877 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
4878 type = get_node_type((IUnknown*)node);
4879 ok(type == 3, "type=%d\n", type);
4880 IHTMLDOMNode_Release(node);
4883 bstr = SysAllocString(w100);
4884 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4885 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
4886 SysFreeString(bstr);
4888 IDispatchEx_Release(dispex);
4893 static void test_elems(IHTMLDocument2 *doc)
4895 IHTMLElementCollection *col;
4896 IHTMLDOMChildrenCollection *child_col;
4897 IHTMLElement *elem, *elem2, *elem3;
4898 IHTMLDOMNode *node, *node2;
4899 IHTMLWindow2 *window;
4903 IHTMLElementCollection *collection;
4904 IHTMLDocument3 *doc3;
4907 static const elem_type_t all_types[] = {
4936 static const elem_type_t item_types[] = {
4942 hres = IHTMLDocument2_get_all(doc, &col);
4943 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4944 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4945 test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
4946 IHTMLElementCollection_Release(col);
4948 hres = IHTMLDocument2_get_images(doc, &collection);
4949 ok(hres == S_OK, "get_images failed: %08x\n", hres);
4952 static const elem_type_t images_types[] = {ET_IMG};
4953 test_elem_collection((IUnknown*)collection, images_types, 1);
4955 IHTMLElementCollection_Release(collection);
4958 hres = IHTMLDocument2_get_links(doc, &collection);
4959 ok(hres == S_OK, "get_links failed: %08x\n", hres);
4962 static const elem_type_t images_types[] = {ET_A};
4963 test_elem_collection((IUnknown*)collection, images_types, 1);
4965 IHTMLElementCollection_Release(collection);
4968 hres = IHTMLDocument2_get_anchors(doc, &collection);
4969 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4972 static const elem_type_t anchor_types[] = {ET_A};
4973 test_elem_collection((IUnknown*)collection, anchor_types, 1);
4975 IHTMLElementCollection_Release(collection);
4978 test_plugins_col(doc);
4980 elem = get_doc_elem(doc);
4981 test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
4982 IHTMLElement_Release(elem);
4984 get_elem_by_id(doc, "xxx", FALSE);
4985 elem = get_doc_elem_by_id(doc, "xxx");
4986 ok(!elem, "elem != NULL\n");
4988 elem = get_doc_elem_by_id(doc, "s");
4989 ok(elem != NULL, "elem == NULL\n");
4991 test_elem_type((IUnknown*)elem, ET_SELECT);
4992 test_elem_attr(elem, "xxx", NULL);
4993 test_elem_attr(elem, "id", "s");
4994 test_elem_class((IUnknown*)elem, NULL);
4995 test_elem_set_class((IUnknown*)elem, "cl");
4996 test_elem_set_class((IUnknown*)elem, NULL);
4997 test_elem_tabindex((IUnknown*)elem, 0);
4998 test_elem_set_tabindex((IUnknown*)elem, 1);
4999 test_elem_filters((IUnknown*)elem);
5001 node = test_node_get_parent((IUnknown*)elem);
5002 ok(node != NULL, "node == NULL\n");
5003 test_node_name((IUnknown*)node, "BODY");
5004 node2 = test_node_get_parent((IUnknown*)node);
5005 IHTMLDOMNode_Release(node);
5006 ok(node2 != NULL, "node == NULL\n");
5007 test_node_name((IUnknown*)node2, "HTML");
5008 node = test_node_get_parent((IUnknown*)node2);
5009 IHTMLDOMNode_Release(node2);
5010 ok(node != NULL, "node == NULL\n");
5013 test_node_name((IUnknown*)node, "#document");
5014 type = get_node_type((IUnknown*)node);
5015 ok(type == 9, "type=%d, expected 9\n", type);
5016 node2 = test_node_get_parent((IUnknown*)node);
5017 IHTMLDOMNode_Release(node);
5018 ok(node2 == NULL, "node != NULL\n");
5021 elem2 = test_elem_get_parent((IUnknown*)elem);
5022 ok(elem2 != NULL, "elem2 == NULL\n");
5023 test_node_name((IUnknown*)elem2, "BODY");
5024 elem3 = test_elem_get_parent((IUnknown*)elem2);
5025 IHTMLElement_Release(elem2);
5026 ok(elem3 != NULL, "elem3 == NULL\n");
5027 test_node_name((IUnknown*)elem3, "HTML");
5028 elem2 = test_elem_get_parent((IUnknown*)elem3);
5029 IHTMLElement_Release(elem3);
5030 ok(elem2 == NULL, "elem2 != NULL\n");
5032 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
5033 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
5034 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
5036 test_elem_innertext(elem, "opt1opt2");
5038 IHTMLElement_Release(elem);
5041 elem = get_elem_by_id(doc, "s", TRUE);
5043 IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
5044 IHTMLDocument2 *doc_node, *elem_doc;
5046 test_select_elem(select);
5048 test_elem_title((IUnknown*)select, NULL);
5049 test_elem_set_title((IUnknown*)select, "Title");
5050 test_elem_title((IUnknown*)select, "Title");
5051 test_elem_offset((IUnknown*)select, "BODY");
5052 test_elem_bounding_client_rect((IUnknown*)select);
5054 node = get_first_child((IUnknown*)select);
5055 ok(node != NULL, "node == NULL\n");
5057 test_elem_type((IUnknown*)node, ET_OPTION);
5058 IHTMLDOMNode_Release(node);
5061 type = get_node_type((IUnknown*)select);
5062 ok(type == 1, "type=%d\n", type);
5064 IHTMLSelectElement_Release(select);
5066 elem_doc = get_elem_doc((IUnknown*)elem);
5068 doc_node = get_doc_node(doc);
5069 ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
5070 IHTMLDocument2_Release(doc_node);
5071 IHTMLDocument2_Release(elem_doc);
5073 IHTMLElement_Release(elem);
5076 elem = get_elem_by_id(doc, "sc", TRUE);
5078 IHTMLScriptElement *script;
5081 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
5082 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
5088 hres = IHTMLScriptElement_put_type (script, NULL);
5089 ok(hres == S_OK, "put_type failed: %08x\n", hres);
5090 hres = IHTMLScriptElement_get_type(script, &type);
5091 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5092 ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
5094 hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
5095 ok(hres == S_OK, "put_type failed: %08x\n", hres);
5096 hres = IHTMLScriptElement_get_type(script, &type);
5097 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5098 ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
5100 SysFreeString(type);
5103 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
5104 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5106 hres = IHTMLScriptElement_get_defer(script, &vb);
5107 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
5108 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
5110 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
5111 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
5113 str = (BSTR)0xdeadbeef;
5114 hres = IHTMLScriptElement_get_src(script, &str);
5115 ok(hres == S_OK, "get_src failed: %08x\n", hres);
5116 ok(!str, "src = %s\n", wine_dbgstr_w(str));
5119 IHTMLScriptElement_Release(script);
5122 elem = get_elem_by_id(doc, "in", TRUE);
5124 IHTMLInputElement *input;
5126 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
5127 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
5129 test_elem_id((IUnknown*)elem, "in");
5130 test_elem_put_id((IUnknown*)elem, "newin");
5131 test_input_get_disabled(input, VARIANT_FALSE);
5132 test_input_set_disabled(input, VARIANT_TRUE);
5133 test_input_set_disabled(input, VARIANT_FALSE);
5134 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
5135 test_input_get_disabled(input, VARIANT_TRUE);
5136 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
5137 test_input_get_disabled(input, VARIANT_FALSE);
5138 test_elem_client_size((IUnknown*)elem);
5139 test_input_type(input, "text");
5141 test_node_get_value_str((IUnknown*)elem, NULL);
5142 test_node_put_value_str((IUnknown*)elem, "test");
5143 test_node_get_value_str((IUnknown*)elem, NULL);
5144 test_input_value((IUnknown*)elem, NULL);
5145 test_input_put_value((IUnknown*)elem, "test");
5146 test_elem_class((IUnknown*)elem, "testclass");
5147 test_elem_tabindex((IUnknown*)elem, 2);
5148 test_elem_set_tabindex((IUnknown*)elem, 3);
5149 test_elem_title((IUnknown*)elem, "test title");
5151 test_input_get_defaultchecked(input, VARIANT_FALSE);
5152 test_input_set_defaultchecked(input, VARIANT_TRUE);
5153 test_input_set_defaultchecked(input, VARIANT_FALSE);
5155 test_input_get_checked(input, VARIANT_FALSE);
5156 test_input_set_checked(input, VARIANT_TRUE);
5157 test_input_set_checked(input, VARIANT_FALSE);
5159 test_input_name(input, NULL);
5160 test_input_set_name(input, "test");
5162 test_input_src(input, NULL);
5163 test_input_set_src(input, "about:blank");
5165 IHTMLInputElement_Release(input);
5166 IHTMLElement_Release(elem);
5169 elem = get_elem_by_id(doc, "imgid", TRUE);
5171 test_img_src((IUnknown*)elem, "", NULL);
5172 test_img_set_src((IUnknown*)elem, "about:blank");
5173 test_img_src((IUnknown*)elem, "about:blank", NULL);
5174 test_img_alt((IUnknown*)elem, NULL);
5175 test_img_set_alt((IUnknown*)elem, "alt test");
5176 test_img_name((IUnknown*)elem, "WineImg");
5177 IHTMLElement_Release(elem);
5180 elem = get_elem_by_id(doc, "attr", TRUE);
5182 test_dynamic_properties(elem);
5183 test_attr_collection(elem);
5184 IHTMLElement_Release(elem);
5187 elem = get_elem_by_id(doc, "styleid", TRUE);
5189 test_style_media((IUnknown*)elem, NULL);
5190 test_style_put_media((IUnknown*)elem, "screen");
5191 test_style_type((IUnknown*)elem, NULL);
5192 test_style_put_type((IUnknown*)elem, "text/css");
5193 IHTMLElement_Release(elem);
5196 elem = get_doc_elem_by_id(doc, "tbl");
5197 ok(elem != NULL, "elem == NULL\n");
5199 test_table_elem(elem);
5200 IHTMLElement_Release(elem);
5203 elem = get_doc_elem_by_id(doc, "row2");
5204 ok(elem != NULL, "elem == NULL\n");
5207 IHTMLElement_Release(elem);
5210 elem = get_doc_elem_by_id(doc, "ifr");
5211 ok(elem != NULL, "elem == NULL\n");
5213 test_iframe_elem(elem);
5214 IHTMLElement_Release(elem);
5217 elem = get_doc_elem_by_id(doc, "objid");
5218 ok(elem != NULL, "elem == NULL\n");
5220 test_object_vspace((IUnknown*)elem, 100);
5221 IHTMLElement_Release(elem);
5224 elem = get_elem_by_id(doc, "a", TRUE);
5226 test_anchor_href((IUnknown*)elem, "http://test/");
5228 /* Change the href */
5229 test_anchor_put_href((IUnknown*)elem, "http://test1/");
5230 test_anchor_href((IUnknown*)elem, "http://test1/");
5232 /* Restore the href */
5233 test_anchor_put_href((IUnknown*)elem, "http://test/");
5234 test_anchor_href((IUnknown*)elem, "http://test/");
5237 test_anchor_get_target((IUnknown*)elem, NULL);
5239 /* Change the target */
5240 test_anchor_put_target((IUnknown*)elem, "wine");
5241 test_anchor_get_target((IUnknown*)elem, "wine");
5243 /* Restore the target */
5244 test_anchor_put_target((IUnknown*)elem, NULL);
5245 test_anchor_get_target((IUnknown*)elem, NULL);
5247 IHTMLElement_Release(elem);
5250 elem = doc_get_body(doc);
5252 node = get_first_child((IUnknown*)elem);
5253 ok(node != NULL, "node == NULL\n");
5255 test_ifaces((IUnknown*)node, text_iids);
5256 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5258 node2 = get_first_child((IUnknown*)node);
5259 ok(!node2, "node2 != NULL\n");
5261 type = get_node_type((IUnknown*)node);
5262 ok(type == 3, "type=%d\n", type);
5264 test_node_get_value_str((IUnknown*)node, "text test");
5265 test_node_put_value_str((IUnknown*)elem, "test text");
5266 test_node_get_value_str((IUnknown*)node, "text test");
5268 hres = IHTMLDOMNode_get_attributes(node, &disp);
5269 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
5270 ok(!disp, "disp != NULL\n");
5272 IHTMLDOMNode_Release(node);
5275 child_col = get_child_nodes((IUnknown*)elem);
5276 ok(child_col != NULL, "child_coll == NULL\n");
5280 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
5282 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
5283 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5284 ok(length, "length=0\n");
5287 node = get_child_item(child_col, 0);
5288 ok(node != NULL, "node == NULL\n");
5292 type = get_node_type((IUnknown*)node);
5293 ok(type == 3, "type=%d\n", type);
5294 node2 = node_get_next((IUnknown*)node);
5296 prev = node_get_prev((IUnknown*)node2);
5297 ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
5298 IHTMLDOMNode_Release(prev);
5300 IHTMLDOMNode_Release(node);
5303 node = get_child_item(child_col, 1);
5304 ok(node != NULL, "node == NULL\n");
5306 type = get_node_type((IUnknown*)node);
5307 ok(type == 8, "type=%d\n", type);
5309 test_elem_id((IUnknown*)node, NULL);
5310 ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
5311 IHTMLDOMNode_Release(node2);
5312 IHTMLDOMNode_Release(node);
5315 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
5316 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5318 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
5319 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
5321 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
5322 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5324 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
5325 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5327 test_child_col_disp(child_col);
5329 IHTMLDOMChildrenCollection_Release(child_col);
5332 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
5333 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
5334 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
5336 IHTMLElement_Release(elem);
5338 elem = get_doc_elem_by_id(doc, "frm");
5339 ok(elem != NULL, "elem == NULL\n");
5341 test_form_length((IUnknown*)elem, 0);
5342 test_form_elements((IUnknown*)elem);
5343 IHTMLElement_Release(elem);
5346 test_stylesheets(doc);
5347 test_create_option_elem(doc);
5348 test_create_img_elem(doc);
5350 elem = get_doc_elem_by_id(doc, "tbl");
5351 ok(elem != NULL, "elem = NULL\n");
5352 test_elem_set_innertext(elem, "inner text");
5353 IHTMLElement_Release(elem);
5355 test_doc_title(doc, "test");
5356 test_doc_set_title(doc, "test title");
5357 test_doc_title(doc, "test title");
5360 hres = IHTMLDocument2_get_Script(doc, &disp);
5361 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5364 IDispatchEx *dispex;
5365 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
5366 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
5370 BSTR str = a2bstr("Testing");
5371 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
5372 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
5373 ok(pid != -1, "pid == -1\n");
5375 IDispatchEx_Release(dispex);
5378 IDispatch_Release(disp);
5380 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5381 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5383 str = a2bstr("img");
5384 hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
5385 ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
5389 static const elem_type_t img_types[] = { ET_IMG };
5391 test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
5392 IHTMLElementCollection_Release(col);
5395 elem = get_doc_elem_by_id(doc, "y");
5396 test_elem_set_innerhtml((IUnknown*)elem, "inner html");
5397 test_elem_innerhtml((IUnknown*)elem, "inner html");
5398 test_elem_set_innerhtml((IUnknown*)elem, "");
5399 test_elem_innerhtml((IUnknown*)elem, NULL);
5400 node = node_get_next((IUnknown*)elem);
5401 ok(!node, "node = %p\n", node);
5403 elem2 = get_doc_elem_by_id(doc, "x");
5404 test_elem_tag((IUnknown*)elem2, "A");
5405 node = node_get_next((IUnknown*)elem2);
5406 IHTMLDOMNode_Release(node);
5407 IHTMLElement_Release(elem2);
5408 IHTMLElement_Release(elem);
5410 IHTMLDocument3_Release(doc3);
5412 elem = get_elem_by_id(doc, "s", TRUE);
5414 static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
5416 test_select_put_length((IUnknown*)elem, 3);
5417 test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
5418 test_select_put_length((IUnknown*)elem, 1);
5419 test_elem_all((IUnknown*)elem, select_types, 1);
5420 IHTMLElement_Release(elem);
5423 window = get_doc_window(doc);
5424 test_window_name(window, NULL);
5425 set_window_name(window, "test name");
5426 test_window_length(window, 1);
5427 IHTMLWindow2_Release(window);
5430 static void test_attr(IHTMLElement *elem)
5432 IHTMLDOMAttribute *attr, *attr2;
5435 get_elem_attr_node((IUnknown*)elem, "noattr", FALSE);
5437 attr = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5439 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
5440 test_ifaces((IUnknown*)attr, attr_iids);
5441 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
5443 attr2 = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
5444 ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
5445 IHTMLDOMAttribute_Release(attr2);
5447 get_attr_node_value(attr, &v, VT_BSTR);
5448 ok(!strcmp_wa(V_BSTR(&v), "divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5451 IHTMLDOMAttribute_Release(attr);
5453 attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
5454 get_attr_node_value(attr, &v, VT_BSTR);
5455 ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
5457 IHTMLDOMAttribute_Release(attr);
5461 set_dispex_value((IUnknown*)elem, "dispprop", &v);
5462 attr = get_elem_attr_node((IUnknown*)elem, "dispprop", TRUE);
5463 get_attr_node_value(attr, &v, VT_I4);
5464 ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
5465 IHTMLDOMAttribute_Release(attr);
5468 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
5472 test_elem_set_innerhtml((IUnknown*)outer_elem,
5473 "<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
5474 elem = get_elem_by_id(doc, "imgid", TRUE);
5476 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5477 IHTMLElement_Release(elem);
5480 test_elem_set_innerhtml((IUnknown*)outer_elem,
5481 "<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
5482 elem = get_elem_by_id(doc, "imgid", TRUE);
5484 test_img_src((IUnknown*)elem, "blocke::http://www.winehq.org/img.png", NULL);
5485 test_img_set_src((IUnknown*)elem, "BLOCKED:http://www.winehq.org/img.png");
5486 test_img_src((IUnknown*)elem, "blocked:http://www.winehq.org/img.png", NULL);
5487 test_img_set_src((IUnknown*)elem, "blocked::http://www.winehq.org/img.png");
5488 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
5489 IHTMLElement_Release(elem);
5493 static void test_elems2(IHTMLDocument2 *doc)
5495 IHTMLElement *elem, *elem2, *div;
5497 static const elem_type_t outer_types[] = {
5502 div = get_doc_elem_by_id(doc, "divid");
5504 test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
5505 elem2 = get_doc_elem_by_id(doc, "innerid");
5506 ok(elem2 != NULL, "elem2 == NULL\n");
5507 test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
5508 test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
5509 IHTMLElement_Release(elem2);
5511 elem2 = get_doc_elem_by_id(doc, "aid");
5512 ok(elem2 != NULL, "elem2 == NULL\n");
5513 test_elem_set_outerhtml((IUnknown*)elem2, "");
5514 test_elem_all((IUnknown*)div, outer_types, 1);
5515 IHTMLElement_Release(elem2);
5517 test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
5518 elem = get_elem_by_id(doc, "ta", TRUE);
5520 test_textarea_value((IUnknown*)elem, NULL);
5521 test_textarea_put_value((IUnknown*)elem, "test");
5522 test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
5523 test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
5524 test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
5525 test_textarea_type((IUnknown*)elem);
5526 IHTMLElement_Release(elem);
5529 test_elem_set_innerhtml((IUnknown*)div,
5530 "<form id=\"form\"><input type=\"button\" /><div><input type=\"text\" /></div></textarea>");
5531 elem = get_elem_by_id(doc, "form", TRUE);
5533 test_form_length((IUnknown*)elem, 2);
5534 test_form_item(elem);
5535 test_form_action((IUnknown*)elem, NULL);
5536 test_form_put_action((IUnknown*)elem, "about:blank");
5537 test_form_method((IUnknown*)elem, "get");
5538 test_form_put_method((IUnknown*)elem, S_OK, "post");
5539 test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
5540 test_form_method((IUnknown*)elem, "post");
5541 test_form_name((IUnknown*)elem, NULL);
5542 test_form_put_name((IUnknown*)elem, "Name");
5543 test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
5544 test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
5545 test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
5546 test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
5547 test_form_encoding((IUnknown*)elem, "multipart/form-data");
5548 test_form_elements((IUnknown*)elem);
5549 IHTMLElement_Release(elem);
5553 test_blocked(doc, div);
5555 IHTMLElement_Release(div);
5558 static void test_create_elems(IHTMLDocument2 *doc)
5560 IHTMLElement *elem, *body, *elem2;
5561 IHTMLDOMNode *node, *node2, *node3, *comment;
5562 IHTMLDocument5 *doc5;
5569 static const elem_type_t types1[] = { ET_TESTG };
5571 elem = test_create_elem(doc, "TEST");
5572 test_elem_tag((IUnknown*)elem, "TEST");
5573 type = get_node_type((IUnknown*)elem);
5574 ok(type == 1, "type=%d\n", type);
5575 test_ifaces((IUnknown*)elem, elem_iids);
5576 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
5578 body = doc_get_body(doc);
5579 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5581 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
5582 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
5583 elem2 = get_elem_iface((IUnknown*)node);
5584 IHTMLElement_Release(elem2);
5586 hres = IHTMLElement_get_all(body, &disp);
5587 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5588 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
5589 IDispatch_Release(disp);
5591 test_node_remove_child((IUnknown*)body, node);
5593 hres = IHTMLElement_get_all(body, &disp);
5594 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5595 test_elem_collection((IUnknown*)disp, NULL, 0);
5596 IDispatch_Release(disp);
5597 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
5599 IHTMLElement_Release(elem);
5600 IHTMLDOMNode_Release(node);
5602 node = test_create_text(doc, "test");
5603 test_ifaces((IUnknown*)node, text_iids);
5604 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
5605 test_text_length((IUnknown*)node, 4);
5607 V_VT(&var) = VT_NULL;
5608 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5609 IHTMLDOMNode_Release(node);
5611 node = test_create_text(doc, "insert ");
5613 V_VT(&var) = VT_DISPATCH;
5614 V_DISPATCH(&var) = (IDispatch*)node2;
5615 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
5616 IHTMLDOMNode_Release(node);
5617 IHTMLDOMNode_Release(node2);
5618 IHTMLDOMNode_Release(node3);
5620 test_elem_innertext(body, "insert test");
5621 test_elem_innerhtml((IUnknown*)body, "insert test");
5623 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
5626 str = a2bstr("testing");
5627 hres = IHTMLDocument5_createComment(doc5, str, &comment);
5629 ok(hres == S_OK, "createComment failed: %08x\n", hres);
5632 type = get_node_type((IUnknown*)comment);
5633 ok(type == 8, "type=%d, expected 8\n", type);
5635 test_node_get_value_str((IUnknown*)comment, "testing");
5636 test_elem_title((IUnknown*)comment, NULL);
5637 test_elem_set_title((IUnknown*)comment, "comment title");
5638 test_elem_title((IUnknown*)comment, "comment title");
5639 test_comment_text((IUnknown*)comment, "<!--testing-->");
5640 test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
5641 test_comment_attrs((IUnknown*)comment);
5643 IHTMLDOMNode_Release(comment);
5646 IHTMLDocument5_Release(doc5);
5649 IHTMLElement_Release(body);
5652 static void test_replacechild_elems(IHTMLDocument2 *doc)
5655 IHTMLDOMNode *node, *node2, *node3;
5656 IHTMLDOMNode *nodeBody, *nodeNew;
5660 body = doc_get_body(doc);
5662 node = test_create_text(doc, "insert");
5664 V_VT(&var) = VT_NULL;
5665 V_DISPATCH(&var) = NULL;
5666 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
5667 IHTMLDOMNode_Release(node);
5669 test_elem_innertext(body, "insert");
5671 node3 = test_create_text(doc, "replaced");
5673 nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
5675 hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
5676 ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
5678 test_elem_innertext(body, "replaced");
5680 IHTMLDOMNode_Release(node2);
5681 IHTMLDOMNode_Release(node3);
5682 IHTMLDOMNode_Release(nodeBody);
5684 IHTMLElement_Release(body);
5687 static void test_null_write(IHTMLDocument2 *doc)
5691 doc_write(doc, FALSE, NULL);
5692 doc_write(doc, TRUE, NULL);
5694 hres = IHTMLDocument2_write(doc, NULL);
5696 "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
5698 hres = IHTMLDocument2_writeln(doc, NULL);
5700 "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
5703 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
5705 IOleCommandTarget *cmdtrg;
5708 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
5709 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
5711 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
5712 ok(hres == S_OK, "Exec failed: %08x\n", hres);
5714 IOleCommandTarget_Release(cmdtrg);
5717 static void test_indent(IHTMLDocument2 *doc)
5719 IHTMLElementCollection *col;
5720 IHTMLTxtRange *range;
5723 static const elem_type_t all_types[] = {
5732 static const elem_type_t indent_types[] = {
5743 hres = IHTMLDocument2_get_all(doc, &col);
5744 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5745 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5746 IHTMLElementCollection_Release(col);
5748 range = test_create_body_range(doc);
5749 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
5750 IHTMLTxtRange_Release(range);
5752 hres = IHTMLDocument2_get_all(doc, &col);
5753 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5754 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
5755 IHTMLElementCollection_Release(col);
5758 static void test_cond_comment(IHTMLDocument2 *doc)
5760 IHTMLElementCollection *col;
5763 static const elem_type_t all_types[] = {
5771 hres = IHTMLDocument2_get_all(doc, &col);
5772 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5773 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
5774 IHTMLElementCollection_Release(col);
5777 static void test_frame(IDispatch *disp, const char *exp_id)
5779 IHTMLWindow2 *frame2, *parent, *top;
5780 IHTMLDocument2 *parent_doc, *top_doc;
5781 IHTMLWindow4 *frame;
5782 IHTMLFrameBase *frame_elem;
5785 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
5786 ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
5790 hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
5791 ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
5792 IHTMLWindow4_Release(frame);
5796 test_elem_type((IUnknown*)frame_elem, ET_FRAME);
5797 test_frame_doc((IUnknown*)frame_elem, FALSE);
5798 test_elem_id((IUnknown*)frame_elem, exp_id);
5799 IHTMLElement_Release(frame_elem);
5801 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
5802 ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
5806 hres = IHTMLWindow2_get_parent(frame2, &parent);
5807 ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
5809 IHTMLWindow2_Release(frame2);
5813 hres = IHTMLWindow2_get_document(parent, &parent_doc);
5814 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
5815 IHTMLWindow2_Release(parent);
5817 IHTMLWindow2_Release(frame2);
5821 test_doc_title(parent_doc, "frameset test");
5822 IHTMLDocument2_Release(parent_doc);
5825 hres = IHTMLWindow2_get_top(frame2, &top);
5826 ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
5827 IHTMLWindow2_Release(frame2);
5831 hres = IHTMLWindow2_get_document(top, &top_doc);
5832 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
5833 IHTMLWindow2_Release(top);
5837 test_doc_title(top_doc, "frameset test");
5838 IHTMLDocument2_Release(top_doc);
5841 static void test_frames_collection(IHTMLFramesCollection2 *frames, const char *frid)
5843 VARIANT index_var, result_var;
5847 /* test result length */
5848 hres = IHTMLFramesCollection2_get_length(frames, &length);
5849 ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
5850 ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
5852 /* test first frame */
5853 V_VT(&index_var) = VT_I4;
5854 V_I4(&index_var) = 0;
5855 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5856 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5857 if(SUCCEEDED(hres)) {
5858 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5859 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
5861 VariantClear(&result_var);
5863 /* test second frame */
5864 V_I4(&index_var) = 1;
5865 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5866 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5867 if(SUCCEEDED(hres)) {
5868 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5869 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
5871 VariantClear(&result_var);
5873 /* fail on next frame */
5874 V_I4(&index_var) = 3;
5875 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5876 ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
5877 "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
5878 VariantClear(&result_var);
5880 /* string argument (element id lookup) */
5881 V_VT(&index_var) = VT_BSTR;
5882 V_BSTR(&index_var) = a2bstr(frid);
5883 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5884 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
5885 if(SUCCEEDED(hres)) {
5886 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
5887 test_frame(V_DISPATCH(&result_var), frid);
5889 VariantClear(&result_var);
5890 VariantClear(&index_var);
5892 /* invalid argument */
5893 V_VT(&index_var) = VT_BOOL;
5894 V_BOOL(&index_var) = VARIANT_TRUE;
5895 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
5896 ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
5897 "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
5898 VariantClear(&result_var);
5901 static void test_frameset(IHTMLDocument2 *doc)
5903 IHTMLWindow2 *window;
5904 IHTMLFramesCollection2 *frames;
5906 IHTMLFrameBase *fbase;
5910 window = get_doc_window(doc);
5912 /* test using IHTMLFramesCollection object */
5914 hres = IHTMLWindow2_get_frames(window, &frames);
5915 ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
5919 test_frames_collection(frames, "fr1");
5920 IHTMLFramesCollection2_Release(frames);
5922 hres = IHTMLDocument2_get_frames(doc, &frames);
5923 ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
5927 test_frames_collection(frames, "fr1");
5928 IHTMLFramesCollection2_Release(frames);
5930 /* test using IHTMLWindow2 inheritance */
5931 test_frames_collection((IHTMLFramesCollection2*)window, "fr2");
5933 /* getElementById with node name attributes */
5934 elem = get_doc_elem_by_id(doc, "nm1");
5935 test_elem_id((IUnknown*)elem, "fr1");
5937 /* get/put scrolling */
5938 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5939 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5941 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5942 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5943 ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
5947 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5948 ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
5951 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5952 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5953 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5956 str = a2bstr("junk");
5957 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5958 ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
5959 "with E_INVALIDARG, instead: 0x%08x\n", hres);
5962 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5963 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5964 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5968 hres = IHTMLFrameBase_get_name(fbase, &str);
5969 ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
5970 ok(!strcmp_wa(str, "nm1"), "get_name should have given 'nm1', gave: %s\n", wine_dbgstr_w(str));
5973 IHTMLFrameBase_Release(fbase);
5974 IHTMLElement_Release(elem);
5976 /* get_name with no name attr */
5977 elem = get_doc_elem_by_id(doc, "fr3");
5978 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5979 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5981 hres = IHTMLFrameBase_get_name(fbase, &str);
5982 ok(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
5983 ok(str == NULL, "get_name should have given 'null', gave: %s\n", wine_dbgstr_w(str));
5986 IHTMLFrameBase_Release(fbase);
5987 IHTMLElement_Release(elem);
5988 IHTMLWindow2_Release(window);
5991 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
5993 IHTMLDocument2 *frag;
5994 IHTMLDocument3 *doc3;
5997 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5998 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
6000 hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
6001 IHTMLDocument3_Release(doc3);
6002 ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
6003 ok(frag != NULL, "frag == NULL\n");
6008 static void test_docfrag(IHTMLDocument2 *doc)
6010 IHTMLElement *div, *body, *br;
6011 IHTMLElementCollection *col;
6012 IHTMLLocation *location;
6013 IHTMLDocument2 *frag;
6016 static const elem_type_t all_types[] = {
6025 frag = create_docfrag(doc);
6027 test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
6029 body = (void*)0xdeadbeef;
6030 hres = IHTMLDocument2_get_body(frag, &body);
6031 ok(hres == S_OK, "get_body failed: %08x\n", hres);
6032 ok(!body, "body != NULL\n");
6034 location = (void*)0xdeadbeef;
6035 hres = IHTMLDocument2_get_location(frag, &location);
6036 ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
6037 ok(location == (void*)0xdeadbeef, "location changed\n");
6039 br = test_create_elem(doc, "BR");
6040 test_node_append_child((IUnknown*)frag, (IUnknown*)br);
6041 IHTMLElement_Release(br);
6043 div = get_elem_by_id(doc, "divid", TRUE);
6044 test_node_append_child((IUnknown*)div, (IUnknown*)frag);
6045 IHTMLElement_Release(div);
6047 hres = IHTMLDocument2_get_all(doc, &col);
6048 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6049 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6050 IHTMLElementCollection_Release(col);
6052 IHTMLDocument2_Release(frag);
6055 static IHTMLDocument2 *notif_doc;
6056 static BOOL doc_complete;
6058 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
6059 REFIID riid, void**ppv)
6061 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
6066 ok(0, "unexpected call\n");
6067 return E_NOINTERFACE;
6070 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
6075 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
6080 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
6082 if(dispID == DISPID_READYSTATE){
6086 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
6087 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
6089 if(!strcmp_wa(state, "complete"))
6090 doc_complete = TRUE;
6092 SysFreeString(state);
6098 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
6100 ok(0, "unexpected call\n");
6104 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
6105 PropertyNotifySink_QueryInterface,
6106 PropertyNotifySink_AddRef,
6107 PropertyNotifySink_Release,
6108 PropertyNotifySink_OnChanged,
6109 PropertyNotifySink_OnRequestEdit
6112 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
6114 static IHTMLDocument2 *create_doc_with_string(const char *str)
6116 IPersistStreamInit *init;
6118 IHTMLDocument2 *doc;
6122 notif_doc = doc = create_document();
6126 doc_complete = FALSE;
6128 mem = GlobalAlloc(0, len);
6129 memcpy(mem, str, len);
6130 CreateStreamOnHGlobal(mem, TRUE, &stream);
6132 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
6134 IPersistStreamInit_Load(init, stream);
6135 IPersistStreamInit_Release(init);
6136 IStream_Release(stream);
6141 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
6143 IConnectionPointContainer *container;
6144 IConnectionPoint *cp;
6148 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
6149 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
6151 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
6152 IConnectionPointContainer_Release(container);
6153 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
6155 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
6156 IConnectionPoint_Release(cp);
6157 ok(hres == S_OK, "Advise failed: %08x\n", hres);
6160 typedef void (*domtest_t)(IHTMLDocument2*);
6162 static void run_domtest(const char *str, domtest_t test)
6164 IHTMLDocument2 *doc;
6168 doc = create_doc_with_string(str);
6172 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
6174 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
6175 TranslateMessage(&msg);
6176 DispatchMessage(&msg);
6181 ref = IHTMLDocument2_Release(doc);
6182 ok(!ref || broken(ref == 1), /* Vista */
6188 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
6189 pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
6190 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
6194 run_domtest(doc_str1, test_doc_elem);
6195 run_domtest(doc_str1, test_get_set_attr);
6196 run_domtest(range_test_str, test_txtrange);
6197 run_domtest(range_test2_str, test_txtrange2);
6198 if (winetest_interactive || ! is_ie_hardened()) {
6199 run_domtest(elem_test_str, test_elems);
6200 run_domtest(elem_test2_str, test_elems2);
6202 skip("IE running in Enhanced Security Configuration\n");
6204 run_domtest(doc_blank, test_create_elems);
6205 run_domtest(doc_blank, test_defaults);
6206 run_domtest(doc_blank, test_null_write);
6207 run_domtest(indent_test_str, test_indent);
6208 run_domtest(cond_comment_str, test_cond_comment);
6209 run_domtest(frameset_str, test_frameset);
6210 run_domtest(emptydiv_str, test_docfrag);
6211 run_domtest(doc_blank, test_replacechild_elems);