2 * Copyright 2007 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>
35 static const char doc_blank[] = "<html></html>";
36 static const char doc_str1[] = "<html><body>test</body></html>";
37 static const char range_test_str[] =
38 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
39 static const char range_test2_str[] =
40 "<html><body>abc<hr />123<br /><hr />def</body></html>";
41 static const char elem_test_str[] =
42 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
43 "<body>text test<!-- a comment -->"
44 "<a href=\"http://test\" name=\"x\">link</a>"
45 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
46 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
53 static const char indent_test_str[] =
54 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
56 static const WCHAR noneW[] = {'N','o','n','e',0};
58 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
59 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
60 static WCHAR wordW[] = {'w','o','r','d',0};
62 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
64 static const WCHAR idW[] = {'i','d',0};
92 static const IID * const none_iids[] = {
97 static const IID * const elem_iids[] = {
103 &IID_IConnectionPointContainer,
107 static const IID * const body_iids[] = {
112 &IID_IHTMLTextContainer,
113 &IID_IHTMLBodyElement,
115 &IID_IConnectionPointContainer,
119 static const IID * const anchor_iids[] = {
124 &IID_IHTMLAnchorElement,
126 &IID_IConnectionPointContainer,
130 static const IID * const input_iids[] = {
135 &IID_IHTMLInputElement,
136 &IID_IHTMLInputTextElement,
138 &IID_IConnectionPointContainer,
142 static const IID * const select_iids[] = {
147 &IID_IHTMLSelectElement,
149 &IID_IConnectionPointContainer,
153 static const IID * const textarea_iids[] = {
158 &IID_IHTMLTextAreaElement,
160 &IID_IConnectionPointContainer,
164 static const IID * const option_iids[] = {
169 &IID_IHTMLOptionElement,
171 &IID_IConnectionPointContainer,
175 static const IID * const table_iids[] = {
182 &IID_IConnectionPointContainer,
186 static const IID * const script_iids[] = {
191 &IID_IHTMLScriptElement,
193 &IID_IConnectionPointContainer,
197 static const IID * const text_iids[] = {
200 &IID_IHTMLDOMTextNode,
204 static const IID * const location_iids[] = {
210 static const IID * const window_iids[] = {
218 static const IID * const comment_iids[] = {
223 &IID_IHTMLCommentElement,
225 &IID_IConnectionPointContainer,
229 static const IID * const img_iids[] = {
235 &IID_IHTMLImgElement,
236 &IID_IConnectionPointContainer,
240 static const IID * const tr_iids[] = {
247 &IID_IConnectionPointContainer,
251 static const IID * const td_iids[] = {
257 &IID_IConnectionPointContainer,
261 static const IID * const generic_iids[] = {
266 &IID_IHTMLGenericElement,
268 &IID_IConnectionPointContainer,
272 static const IID * const style_iids[] = {
281 static const IID * const cstyle_iids[] = {
285 &IID_IHTMLCurrentStyle,
295 static const elem_type_info_t elem_type_infos[] = {
296 {"", none_iids, NULL},
297 {"HTML", elem_iids, NULL},
298 {"HEAD", elem_iids, NULL},
299 {"TITLE", elem_iids, NULL},
300 {"BODY", body_iids, &DIID_DispHTMLBody},
301 {"A", anchor_iids, NULL},
302 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
303 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
304 {"TEXTAREA", textarea_iids, NULL},
305 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
306 {"STYLE", elem_iids, NULL},
307 {"BLOCKQUOTE",elem_iids, NULL},
308 {"P", elem_iids, NULL},
309 {"BR", elem_iids, NULL},
310 {"TABLE", table_iids, &DIID_DispHTMLTable},
311 {"TBODY", elem_iids, NULL},
312 {"SCRIPT", script_iids, NULL},
313 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
314 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
315 {"!", comment_iids, &DIID_DispHTMLCommentElement},
316 {"IMG", img_iids, &DIID_DispHTMLImg},
317 {"TR", tr_iids, &DIID_DispHTMLTableRow},
318 {"TD", td_iids, NULL}
321 static const char *dbgstr_w(LPCWSTR str)
323 static char buf[512];
326 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
330 static const char *dbgstr_guid(REFIID riid)
334 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
335 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
336 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
337 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
342 static int strcmp_wa(LPCWSTR strw, const char *stra)
345 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
346 return lstrcmpW(strw, buf);
349 static BSTR a2bstr(const char *str)
354 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
355 ret = SysAllocStringLen(NULL, len);
356 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
361 static IHTMLDocument2 *create_document(void)
366 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
367 &IID_IHTMLDocument2, (void**)&doc);
368 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
373 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
374 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
376 const IID * const *piid;
380 for(piid = iids; *piid; piid++) {
381 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
382 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
384 IUnknown_Release(unk);
388 #define test_disp(u,id) _test_disp(__LINE__,u,id)
389 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
396 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
397 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
402 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
403 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
404 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
406 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
407 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
409 if(SUCCEEDED(hres)) {
412 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
413 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
414 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
416 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
417 ITypeInfo_Release(typeinfo);
420 IDispatchEx_Release(dispex);
423 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
424 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
429 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
430 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
434 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
435 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
440 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
441 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
445 #define get_node_iface(u) _get_node_iface(__LINE__,u)
446 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
451 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
452 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
456 #define get_img_iface(u) _get_img_iface(__LINE__,u)
457 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
459 IHTMLImgElement *img;
462 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
463 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
467 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
468 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
470 IHTMLDOMNode *node = _get_node_iface(line, unk);
474 hres = IHTMLDOMNode_get_nodeName(node, &name);
475 IHTMLDOMNode_Release(node);
476 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
477 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
482 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
483 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
485 IHTMLElement *elem = _get_elem_iface(line, unk);
489 hres = IHTMLElement_get_tagName(elem, &tag);
490 IHTMLElement_Release(elem);
491 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
492 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
497 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
498 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
500 _test_elem_tag(line, unk, elem_type_infos[type].tag);
501 _test_ifaces(line, unk, elem_type_infos[type].iids);
503 if(elem_type_infos[type].dispiid)
504 _test_disp(line, unk, elem_type_infos[type].dispiid);
507 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
508 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
516 tmp = SysAllocString(name);
517 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
519 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
522 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
523 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
525 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
528 VariantClear(&value);
531 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
532 static void _test_elem_offset(unsigned line, IUnknown *unk)
534 IHTMLElement *elem = _get_elem_iface(line, unk);
538 hres = IHTMLElement_get_offsetTop(elem, &l);
539 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
541 hres = IHTMLElement_get_offsetHeight(elem, &l);
542 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
544 IHTMLElement_Release(elem);
547 static void test_doc_elem(IHTMLDocument2 *doc)
550 IHTMLDocument3 *doc3;
553 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
554 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
556 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
557 IHTMLDocument3_Release(doc3);
558 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
560 test_node_name((IUnknown*)elem, "HTML");
561 test_elem_tag((IUnknown*)elem, "HTML");
563 IHTMLElement_Release(elem);
566 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
567 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
570 IHTMLDocument3 *doc3;
573 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
574 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
575 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
576 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
577 IHTMLDocument3_Release(doc3);
582 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
583 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
588 hres = IHTMLOptionElement_get_text(option, &bstr);
589 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
590 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
594 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
595 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
601 hres = IHTMLOptionElement_put_text(option, bstr);
603 ok(hres == S_OK, "put_text failed: %08x\n", hres);
605 _test_option_text(line, option, text);
608 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
609 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
614 hres = IHTMLOptionElement_get_value(option, &bstr);
615 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
616 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
620 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
621 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
626 bstr = a2bstr(value);
627 hres = IHTMLOptionElement_put_value(option, bstr);
629 ok(hres == S_OK, "put_value failed: %08x\n", hres);
631 _test_option_value(line, option, value);
634 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
635 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
636 const char *txt, const char *val)
638 IHTMLOptionElementFactory *factory;
639 IHTMLOptionElement *option;
640 IHTMLWindow2 *window;
641 VARIANT text, value, empty;
644 hres = IHTMLDocument2_get_parentWindow(doc, &window);
645 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
647 hres = IHTMLWindow2_get_Option(window, &factory);
648 IHTMLWindow2_Release(window);
649 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
651 V_VT(&text) = VT_BSTR;
652 V_BSTR(&text) = a2bstr(txt);
653 V_VT(&value) = VT_BSTR;
654 V_BSTR(&value) = a2bstr(val);
655 V_VT(&empty) = VT_EMPTY;
657 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
658 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
660 IHTMLOptionElementFactory_Release(factory);
662 VariantClear(&value);
664 _test_option_text(line, option, txt);
665 _test_option_value(line, option, val);
670 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
671 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
673 long len = 0xdeadbeef;
676 hres = IHTMLSelectElement_get_length(select, &len);
677 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
678 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
681 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
682 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
684 long idx = 0xdeadbeef;
687 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
688 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
689 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
692 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
693 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
697 hres = IHTMLSelectElement_put_selectedIndex(select, index);
698 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
699 _test_select_selidx(line, select, index);
702 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
703 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
708 hres = IHTMLSelectElement_get_value(select, &val);
709 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
711 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
713 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
716 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
717 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
723 hres = IHTMLSelectElement_put_value(select, bstr);
725 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
728 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
729 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
734 hres = IHTMLSelectElement_get_type(select, &type);
735 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
736 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
739 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
740 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
745 hres = IHTMLTxtRange_get_text(range, &text);
746 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
749 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
750 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
752 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
759 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
760 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
764 hres = IHTMLTxtRange_collapse(range, b);
765 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
766 _test_range_text(line, range, NULL);
769 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
770 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
771 VARIANT_BOOL exb, const char *extext)
773 VARIANT_BOOL b = 0xe0e0;
776 hres = IHTMLTxtRange_expand(range, unit, &b);
777 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
778 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
779 _test_range_text(line, range, extext);
782 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
783 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
788 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
789 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
790 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
791 _test_range_text(line, range, NULL);
794 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
795 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
796 LPWSTR unit, long cnt, long excnt)
801 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
802 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
803 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
806 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
807 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
812 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
813 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
814 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
817 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
818 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
821 BSTR bstr = a2bstr(text);
823 hres = IHTMLTxtRange_put_text(range, bstr);
824 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
826 _test_range_text(line, range, NULL);
829 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
830 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
836 hres = IHTMLTxtRange_inRange(range1, range2, &b);
837 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
838 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
841 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
842 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
848 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
849 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
850 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
853 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
854 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
855 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
858 test_range_inrange(range1, range2, VARIANT_TRUE);
859 test_range_inrange(range2, range1, VARIANT_TRUE);
863 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
864 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
869 hres = IHTMLTxtRange_parentElement(range, &elem);
870 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
872 _test_elem_type(line, (IUnknown*)elem, type);
874 IHTMLElement_Release(elem);
877 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
878 static void _test_elem_collection(unsigned line, IUnknown *unk,
879 const elem_type_t *elem_types, long exlen)
881 IHTMLElementCollection *col;
888 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
889 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
891 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
893 hres = IHTMLElementCollection_get_length(col, &len);
894 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
895 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
900 V_VT(&index) = VT_EMPTY;
903 for(i=0; i<len; i++) {
905 disp = (void*)0xdeadbeef;
906 hres = IHTMLElementCollection_item(col, name, index, &disp);
907 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
908 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
909 if(FAILED(hres) || !disp)
912 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
913 IDispatch_Release(disp);
917 disp = (void*)0xdeadbeef;
918 hres = IHTMLElementCollection_item(col, name, index, &disp);
919 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
920 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
923 disp = (void*)0xdeadbeef;
924 hres = IHTMLElementCollection_item(col, name, index, &disp);
925 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
926 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
928 IHTMLElementCollection_Release(col);
931 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
932 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
934 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
935 IHTMLElementCollection *col = NULL;
936 elem_type_t *types = NULL;
941 tmp = a2bstr(elem_type_infos[type].tag);
942 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
944 IHTMLElement2_Release(elem);
945 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
946 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
949 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
950 for(i=0; i<exlen; i++)
954 _test_elem_collection(line, (IUnknown*)col, types, exlen);
956 HeapFree(GetProcessHeap(), 0, types);
959 #define get_first_child(n) _get_first_child(__LINE__,n)
960 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
962 IHTMLDOMNode *node = _get_node_iface(line, unk);
963 IHTMLDOMNode *child = NULL;
966 hres = IHTMLDOMNode_get_firstChild(node, &child);
967 IHTMLDOMNode_Release(node);
968 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
973 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
974 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
976 IHTMLDOMNode *node = _get_node_iface(line, unk);
977 VARIANT_BOOL b = 0xdead;
980 hres = IHTMLDOMNode_hasChildNodes(node, &b);
981 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
982 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
984 IHTMLDOMNode_Release(node);
987 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
988 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
990 IHTMLDOMNode *node = _get_node_iface(line, unk);
991 IHTMLDOMNode *parent;
994 hres = IHTMLDOMNode_get_parentNode(node, &parent);
995 IHTMLDOMNode_Release(node);
996 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1001 #define get_node_type(n) _get_node_type(__LINE__,n)
1002 static long _get_node_type(unsigned line, IUnknown *unk)
1004 IHTMLDOMNode *node = _get_node_iface(line, unk);
1008 hres = IHTMLDOMNode_get_nodeType(node, &type);
1009 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1011 IHTMLDOMNode_Release(node);
1016 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1017 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1019 IHTMLElement *elem = _get_elem_iface(line, unk);
1020 IHTMLElement *parent;
1023 hres = IHTMLElement_get_parentElement(elem, &parent);
1024 IHTMLElement_Release(elem);
1025 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1030 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1031 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1033 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1034 IHTMLTextContainer *txtcont;
1035 long l = -1, l2 = -1;
1038 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1039 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1040 IHTMLElement2_Release(elem);
1042 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1043 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1045 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1046 IHTMLTextContainer_Release(txtcont);
1047 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1048 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1053 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1054 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1056 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1057 IHTMLTextContainer *txtcont;
1058 long l = -1, l2 = -1;
1061 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1062 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1063 IHTMLElement2_Release(elem);
1065 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1066 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1068 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1069 IHTMLTextContainer_Release(txtcont);
1070 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1071 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1076 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1077 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1079 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1080 IHTMLTextContainer *txtcont;
1081 long l = -1, l2 = -1;
1084 hres = IHTMLElement2_get_scrollTop(elem, &l);
1085 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1086 IHTMLElement2_Release(elem);
1088 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1089 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1091 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1092 IHTMLTextContainer_Release(txtcont);
1093 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1094 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1099 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1100 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1102 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1103 IHTMLTextContainer *txtcont;
1104 long l = -1, l2 = -1;
1107 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1108 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1110 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1111 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1112 IHTMLElement2_Release(elem);
1114 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1115 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1117 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1118 IHTMLTextContainer_Release(txtcont);
1119 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1120 ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1123 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1124 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1126 IHTMLImgElement *img = _get_img_iface(line, unk);
1131 hres = IHTMLImgElement_put_src(img, tmp);
1132 IHTMLImgElement_Release(img);
1134 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1137 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1138 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1140 IHTMLImgElement *img = _get_img_iface(line, unk);
1144 hres = IHTMLImgElement_get_alt(img, &alt);
1145 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1147 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1149 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1153 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1154 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1156 IHTMLImgElement *img = _get_img_iface(line, unk);
1161 hres = IHTMLImgElement_put_alt(img, tmp);
1162 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1165 _test_img_alt(line, unk, alt);
1168 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1169 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1171 VARIANT_BOOL disabled = 100;
1174 hres = IHTMLInputElement_get_disabled(input, &disabled);
1175 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1176 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1179 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1180 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1184 hres = IHTMLInputElement_put_disabled(input, b);
1185 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1187 _test_input_get_disabled(line, input, b);
1190 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1191 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1193 IHTMLInputElement *input;
1197 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1198 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1202 hres = IHTMLInputElement_get_value(input, &bstr);
1203 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1205 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1207 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1208 SysFreeString(bstr);
1209 IHTMLInputElement_Release(input);
1212 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1213 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1215 IHTMLInputElement *input;
1219 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1220 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1225 hres = IHTMLInputElement_get_value(input, &bstr);
1226 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1227 SysFreeString(bstr);
1228 IHTMLInputElement_Release(input);
1231 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1232 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1234 IHTMLDOMNode *node = _get_node_iface(line, unk);
1235 IHTMLDOMChildrenCollection *col = NULL;
1239 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1240 IHTMLDOMNode_Release(node);
1241 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1245 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1246 IDispatch_Release(disp);
1247 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1252 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1253 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1255 IHTMLElement *elem = _get_elem_iface(line, unk);
1256 BSTR class = (void*)0xdeadbeef;
1259 hres = IHTMLElement_get_className(elem, &class);
1260 IHTMLElement_Release(elem);
1261 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1263 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1265 ok_(__FILE__,line) (!class, "class != NULL\n");
1266 SysFreeString(class);
1269 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1270 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1272 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1276 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1277 IHTMLElement2_Release(elem2);
1278 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1279 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1282 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1283 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1285 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1288 hres = IHTMLElement2_put_tabIndex(elem2, index);
1289 IHTMLElement2_Release(elem2);
1290 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1292 _test_elem_tabindex(line, unk, index);
1295 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1296 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1298 IHTMLElement *elem = _get_elem_iface(line, unk);
1302 tmp = class ? a2bstr(class) : NULL;
1303 hres = IHTMLElement_put_className(elem, tmp);
1304 IHTMLElement_Release(elem);
1305 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1308 _test_elem_class(line, unk, class);
1311 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1312 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
1314 IHTMLDOMNode *node = NULL;
1318 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1319 ok(hres == S_OK, "item failed: %08x\n", hres);
1321 node = _get_node_iface(line, (IUnknown*)disp);
1322 IDispatch_Release(disp);
1327 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1328 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1330 IHTMLElement *elem = _get_elem_iface(line, unk);
1331 BSTR id = (void*)0xdeadbeef;
1334 hres = IHTMLElement_get_id(elem, &id);
1335 IHTMLElement_Release(elem);
1336 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1339 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1341 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1346 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1347 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1349 IHTMLElement *elem = _get_elem_iface(line, unk);
1350 BSTR tmp = a2bstr(new_id);
1353 hres = IHTMLElement_put_id(elem, tmp);
1354 IHTMLElement_Release(elem);
1356 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1358 _test_elem_id(line, unk, new_id);
1361 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1362 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1364 IHTMLElement *elem = _get_elem_iface(line, unk);
1368 hres = IHTMLElement_get_title(elem, &title);
1369 IHTMLElement_Release(elem);
1370 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1372 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1374 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1376 SysFreeString(title);
1379 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1380 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1382 IHTMLElement *elem = _get_elem_iface(line, unk);
1386 tmp = a2bstr(title);
1387 hres = IHTMLElement_put_title(elem, tmp);
1388 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1390 IHTMLElement_Release(elem);
1394 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1395 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1397 IHTMLDOMNode *node = _get_node_iface(line, unk);
1401 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1402 IHTMLDOMNode_Release(node);
1403 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1406 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1407 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1409 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1415 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1416 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1418 IHTMLDOMNode *node = _get_node_iface(line, unk);
1422 V_VT(&var) = VT_BSTR;
1423 V_BSTR(&var) = a2bstr(val);
1425 hres = IHTMLDOMNode_put_nodeValue(node, var);
1426 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1427 IHTMLDOMNode_Release(node);
1431 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1432 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1434 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1438 hres = IHTMLElement2_get_clientWidth(elem, &l);
1439 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1440 hres = IHTMLElement2_get_clientHeight(elem, &l);
1441 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1443 IHTMLElement2_Release(elem);
1446 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1447 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1449 IHTMLElement *elem = NULL;
1454 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1455 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1456 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1461 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1462 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1464 IHTMLDocument3 *doc3;
1465 IHTMLDOMNode *node = NULL;
1469 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1470 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1473 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1474 IHTMLDocument3_Release(doc3);
1475 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1476 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1481 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1482 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1484 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1485 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1486 IHTMLDOMNode *new_child = NULL;
1489 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1490 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1491 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1492 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1494 IHTMLDOMNode_Release(node);
1495 IHTMLDOMNode_Release(child);
1500 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1501 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1503 IHTMLDOMNode *node = _get_node_iface(line, unk);
1504 IHTMLDOMNode *new_node = NULL;
1507 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1508 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1509 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1510 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1512 IHTMLDOMNode_Release(node);
1513 IHTMLDOMNode_Release(new_node);
1516 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1517 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1522 hres = IHTMLDocument2_get_title(doc, &title);
1523 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1524 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1525 SysFreeString(title);
1528 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1529 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1534 tmp = a2bstr(title);
1535 hres = IHTMLDocument2_put_title(doc, tmp);
1536 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1540 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1541 const elem_type_t *elem_types, long len)
1544 VARIANT name, index;
1548 V_VT(&index) = VT_EMPTY;
1549 V_VT(&name) = VT_BSTR;
1550 V_BSTR(&name) = SysAllocString(n);
1552 hres = IHTMLElementCollection_item(col, name, index, &disp);
1553 ok(hres == S_OK, "item failed: %08x\n", hres);
1555 test_elem_collection((IUnknown*)disp, elem_types, len);
1556 IDispatch_Release(disp);
1557 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1561 V_VT(&index) = VT_I4;
1563 for(i=0; i<len; i++) {
1565 disp = (void*)0xdeadbeef;
1566 hres = IHTMLElementCollection_item(col, name, index, &disp);
1567 ok(hres == S_OK, "item failed: %08x\n", hres);
1568 ok(disp != NULL, "disp == NULL\n");
1569 if(FAILED(hres) || !disp)
1572 test_elem_type((IUnknown*)disp, elem_types[i]);
1574 IDispatch_Release(disp);
1578 disp = (void*)0xdeadbeef;
1579 hres = IHTMLElementCollection_item(col, name, index, &disp);
1580 ok(hres == S_OK, "item failed: %08x\n", hres);
1581 ok(disp == NULL, "disp != NULL\n");
1584 disp = (void*)0xdeadbeef;
1585 hres = IHTMLElementCollection_item(col, name, index, &disp);
1586 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1587 ok(disp == NULL, "disp != NULL\n");
1590 SysFreeString(V_BSTR(&name));
1593 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1595 IHTMLElementCollection *col;
1597 IDispatch *disp = (void*)0xdeadbeef;
1598 VARIANT name, index;
1601 hres = IHTMLDocument2_get_all(doc, &col);
1602 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1603 ok(col != NULL, "col == NULL\n");
1604 if(FAILED(hres) || !col)
1607 V_VT(&index) = VT_EMPTY;
1608 V_VT(&name) = VT_BSTR;
1609 V_BSTR(&name) = SysAllocString(id);
1611 hres = IHTMLElementCollection_item(col, name, index, &disp);
1612 IHTMLElementCollection_Release(col);
1613 SysFreeString(V_BSTR(&name));
1614 ok(hres == S_OK, "item failed: %08x\n", hres);
1615 if(!expect_success) {
1616 ok(disp == NULL, "disp != NULL\n");
1620 ok(disp != NULL, "disp == NULL\n");
1624 elem = get_elem_iface((IUnknown*)disp);
1625 IDispatch_Release(disp);
1630 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1632 IHTMLDocument3 *doc3;
1637 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1638 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1640 tmp = SysAllocString(id);
1641 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1643 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1645 IHTMLDocument3_Release(doc3);
1650 static void test_select_elem(IHTMLSelectElement *select)
1652 test_select_type(select, "select-one");
1653 test_select_length(select, 2);
1654 test_select_selidx(select, 0);
1655 test_select_put_selidx(select, 1);
1657 test_select_set_value(select, "val1");
1658 test_select_value(select, "val1");
1661 static void test_create_option_elem(IHTMLDocument2 *doc)
1663 IHTMLOptionElement *option;
1665 option = create_option_elem(doc, "test text", "test value");
1667 test_option_put_text(option, "new text");
1668 test_option_put_value(option, "new value");
1670 IHTMLOptionElement_Release(option);
1673 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1675 IHTMLBodyElement *body;
1676 IHTMLTxtRange *range;
1680 hres = IHTMLDocument2_get_body(doc, &elem);
1681 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1683 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1684 IHTMLElement_Release(elem);
1686 hres = IHTMLBodyElement_createTextRange(body, &range);
1687 IHTMLBodyElement_Release(body);
1688 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1693 static void test_txtrange(IHTMLDocument2 *doc)
1695 IHTMLTxtRange *body_range, *range, *range2;
1696 IHTMLSelectionObject *selection;
1697 IDispatch *disp_range;
1700 body_range = test_create_body_range(doc);
1702 test_range_text(body_range, "test abc 123\r\nit's text");
1704 hres = IHTMLTxtRange_duplicate(body_range, &range);
1705 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1707 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1708 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1709 test_range_isequal(range, range2, VARIANT_TRUE);
1711 test_range_text(range, "test abc 123\r\nit's text");
1712 test_range_text(body_range, "test abc 123\r\nit's text");
1714 test_range_collapse(range, TRUE);
1715 test_range_isequal(range, range2, VARIANT_FALSE);
1716 test_range_inrange(range, range2, VARIANT_FALSE);
1717 test_range_inrange(range2, range, VARIANT_TRUE);
1718 IHTMLTxtRange_Release(range2);
1720 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1721 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1722 test_range_move(range, characterW, 2, 2);
1723 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1725 test_range_collapse(range, FALSE);
1726 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1728 test_range_collapse(range, FALSE);
1729 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1730 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1731 test_range_move(range, characterW, 2, 2);
1732 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1733 test_range_moveend(range, characterW, -5, -5);
1734 test_range_text(range, NULL);
1735 test_range_moveend(range, characterW, 3, 3);
1736 test_range_text(range, "c 1");
1737 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1738 test_range_collapse(range, TRUE);
1739 test_range_move(range, characterW, 4, 4);
1740 test_range_moveend(range, characterW, 1, 1);
1741 test_range_text(range, " ");
1742 test_range_move(range, wordW, 1, 1);
1743 test_range_moveend(range, characterW, 2, 2);
1744 test_range_text(range, "ab");
1746 IHTMLTxtRange_Release(range);
1748 hres = IHTMLTxtRange_duplicate(body_range, &range);
1749 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1751 test_range_text(range, "test abc 123\r\nit's text");
1752 test_range_move(range, characterW, 3, 3);
1753 test_range_moveend(range, characterW, 1, 1);
1754 test_range_text(range, "t");
1755 test_range_moveend(range, characterW, 3, 3);
1756 test_range_text(range, "t ab");
1757 test_range_moveend(range, characterW, -2, -2);
1758 test_range_text(range, "t ");
1759 test_range_move(range, characterW, 6, 6);
1760 test_range_moveend(range, characterW, 3, 3);
1761 test_range_text(range, "123");
1762 test_range_moveend(range, characterW, 2, 2);
1763 test_range_text(range, "123\r\ni");
1765 IHTMLTxtRange_Release(range);
1767 hres = IHTMLTxtRange_duplicate(body_range, &range);
1768 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1770 test_range_move(range, wordW, 1, 1);
1771 test_range_moveend(range, characterW, 2, 2);
1772 test_range_text(range, "ab");
1774 test_range_move(range, characterW, -2, -2);
1775 test_range_moveend(range, characterW, 2, 2);
1776 test_range_text(range, "t ");
1778 test_range_move(range, wordW, 3, 3);
1779 test_range_move(range, wordW, -2, -2);
1780 test_range_moveend(range, characterW, 2, 2);
1781 test_range_text(range, "ab");
1783 test_range_move(range, characterW, -6, -5);
1784 test_range_moveend(range, characterW, -1, 0);
1785 test_range_moveend(range, characterW, -6, 0);
1786 test_range_move(range, characterW, 2, 2);
1787 test_range_moveend(range, characterW, 2, 2);
1788 test_range_text(range, "st");
1789 test_range_moveend(range, characterW, -6, -4);
1790 test_range_moveend(range, characterW, 2, 2);
1792 IHTMLTxtRange_Release(range);
1794 hres = IHTMLTxtRange_duplicate(body_range, &range);
1795 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1797 test_range_move(range, wordW, 2, 2);
1798 test_range_moveend(range, characterW, 2, 2);
1799 test_range_text(range, "12");
1801 test_range_move(range, characterW, 15, 14);
1802 test_range_move(range, characterW, -2, -2);
1803 test_range_moveend(range, characterW, 3, 2);
1804 test_range_text(range, "t");
1805 test_range_moveend(range, characterW, -1, -1);
1806 test_range_text(range, "t");
1807 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1808 test_range_move(range, characterW, -2, -2);
1809 test_range_moveend(range, characterW, 2, 2);
1810 test_range_text(range, "s ");
1811 test_range_move(range, characterW, 100, 7);
1812 test_range_move(range, wordW, 1, 0);
1813 test_range_move(range, characterW, -2, -2);
1814 test_range_moveend(range, characterW, 3, 2);
1815 test_range_text(range, "t");
1817 IHTMLTxtRange_Release(range);
1819 hres = IHTMLTxtRange_duplicate(body_range, &range);
1820 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1822 test_range_collapse(range, TRUE);
1823 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1824 test_range_put_text(range, "word");
1825 test_range_text(body_range, "wordabc 123\r\nit's text");
1826 test_range_text(range, NULL);
1827 test_range_moveend(range, characterW, 3, 3);
1828 test_range_text(range, "abc");
1829 test_range_movestart(range, characterW, -2, -2);
1830 test_range_text(range, "rdabc");
1831 test_range_movestart(range, characterW, 3, 3);
1832 test_range_text(range, "bc");
1833 test_range_movestart(range, characterW, 4, 4);
1834 test_range_text(range, NULL);
1835 test_range_movestart(range, characterW, -3, -3);
1836 test_range_text(range, "c 1");
1837 test_range_movestart(range, characterW, -7, -6);
1838 test_range_text(range, "wordabc 1");
1839 test_range_movestart(range, characterW, 100, 22);
1840 test_range_text(range, NULL);
1842 IHTMLTxtRange_Release(range);
1843 IHTMLTxtRange_Release(body_range);
1845 hres = IHTMLDocument2_get_selection(doc, &selection);
1846 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1848 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1849 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1850 IHTMLSelectionObject_Release(selection);
1852 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1853 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1854 IDispatch_Release(disp_range);
1856 test_range_text(range, NULL);
1857 test_range_moveend(range, characterW, 3, 3);
1858 test_range_text(range, "wor");
1859 test_range_parent(range, ET_BODY);
1860 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1861 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1862 test_range_move(range, characterW, 3, 3);
1863 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1864 test_range_moveend(range, characterW, -4, -4);
1865 test_range_put_text(range, "abc def ");
1866 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1867 test_range_move(range, wordW, 1, 1);
1868 test_range_movestart(range, characterW, -1, -1);
1869 test_range_text(range, " ");
1870 test_range_move(range, wordW, 1, 1);
1871 test_range_moveend(range, characterW, 3, 3);
1872 test_range_text(range, "def");
1873 test_range_put_text(range, "xyz");
1874 test_range_moveend(range, characterW, 1, 1);
1875 test_range_move(range, wordW, 1, 1);
1876 test_range_moveend(range, characterW, 2, 2);
1877 test_range_text(range, "ab");
1879 IHTMLTxtRange_Release(range);
1882 static void test_txtrange2(IHTMLDocument2 *doc)
1884 IHTMLTxtRange *range;
1886 range = test_create_body_range(doc);
1888 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1889 test_range_move(range, characterW, 5, 5);
1890 test_range_moveend(range, characterW, 1, 1);
1891 test_range_text(range, "2");
1892 test_range_move(range, characterW, -3, -3);
1893 test_range_moveend(range, characterW, 3, 3);
1894 test_range_text(range, "c\r\n\r\n1");
1895 test_range_collapse(range, VARIANT_FALSE);
1896 test_range_moveend(range, characterW, 4, 4);
1897 test_range_text(range, "23");
1898 test_range_moveend(range, characterW, 1, 1);
1899 test_range_text(range, "23\r\n\r\n\r\nd");
1900 test_range_moveend(range, characterW, -1, -1);
1901 test_range_text(range, "23");
1902 test_range_moveend(range, characterW, -1, -1);
1903 test_range_text(range, "23");
1904 test_range_moveend(range, characterW, -2, -2);
1905 test_range_text(range, "2");
1907 IHTMLTxtRange_Release(range);
1910 static void test_compatmode(IHTMLDocument2 *doc)
1912 IHTMLDocument5 *doc5;
1916 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1917 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1921 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1922 IHTMLDocument5_Release(doc5);
1923 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1924 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1925 SysFreeString(mode);
1928 static void test_location(IHTMLDocument2 *doc)
1930 IHTMLLocation *location, *location2;
1934 hres = IHTMLDocument2_get_location(doc, &location);
1935 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1937 hres = IHTMLDocument2_get_location(doc, &location2);
1938 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1940 ok(location == location2, "location != location2\n");
1942 test_ifaces((IUnknown*)location, location_iids);
1944 IHTMLLocation_Release(location2);
1945 ref = IHTMLLocation_Release(location);
1946 ok(!ref, "location chould be destroyed here\n");
1949 static void test_navigator(IHTMLDocument2 *doc)
1951 IHTMLWindow2 *window;
1952 IOmNavigator *navigator, *navigator2;
1957 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1958 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1960 hres = IHTMLWindow2_get_navigator(window, &navigator);
1961 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1962 ok(navigator != NULL, "navigator == NULL\n");
1963 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1965 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1966 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1967 ok(navigator != navigator2, "navigator2 != navihgator\n");
1969 IHTMLWindow2_Release(window);
1970 IOmNavigator_Release(navigator2);
1972 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
1973 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
1974 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
1975 SysFreeString(bstr);
1978 hres = IOmNavigator_get_platform(navigator, &bstr);
1979 ok(hres == S_OK, "get_appMinorVersion failed: %08x\n", hres);
1980 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
1981 SysFreeString(bstr);
1983 ref = IOmNavigator_Release(navigator);
1984 ok(!ref, "navigator should be destroyed here\n");
1987 static void test_current_style(IHTMLCurrentStyle *current_style)
1992 test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle);
1993 test_ifaces((IUnknown*)current_style, cstyle_iids);
1995 hres = IHTMLCurrentStyle_get_display(current_style, &str);
1996 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1997 ok(!strcmp_wa(str, "block"), "get_display returned %s\n", dbgstr_w(str));
2001 static void test_style2(IHTMLStyle2 *style2)
2006 str = (void*)0xdeadbeef;
2007 hres = IHTMLStyle2_get_position(style2, &str);
2008 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2009 ok(!str, "str != NULL\n");
2011 str = a2bstr("absolute");
2012 hres = IHTMLStyle2_put_position(style2, str);
2013 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2017 hres = IHTMLStyle2_get_position(style2, &str);
2018 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2019 ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", dbgstr_w(str));
2023 static void test_default_style(IHTMLStyle *style)
2025 IHTMLStyle2 *style2;
2031 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
2032 test_ifaces((IUnknown*)style, style_iids);
2034 str = (void*)0xdeadbeef;
2035 hres = IHTMLStyle_get_fontFamily(style, &str);
2036 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2037 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
2039 str = (void*)0xdeadbeef;
2040 hres = IHTMLStyle_get_fontWeight(style, &str);
2041 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2042 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
2044 str = (void*)0xdeadbeef;
2045 hres = IHTMLStyle_get_display(style, &str);
2046 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2047 ok(!str, "display = %s\n", dbgstr_w(str));
2049 str = (void*)0xdeadbeef;
2050 hres = IHTMLStyle_get_visibility(style, &str);
2051 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2052 ok(!str, "visibility = %s\n", dbgstr_w(str));
2055 hres = IHTMLStyle_get_fontSize(style, &v);
2056 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2057 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2058 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
2061 hres = IHTMLStyle_get_color(style, &v);
2062 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2063 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2064 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2067 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2068 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2069 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2072 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2073 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2074 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2076 V_VT(&v) = VT_EMPTY;
2077 hres = IHTMLStyle_get_width(style, &v);
2078 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2079 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2080 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2083 V_BSTR(&v) = a2bstr("auto");
2084 hres = IHTMLStyle_put_width(style, v);
2085 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2088 V_VT(&v) = VT_EMPTY;
2089 hres = IHTMLStyle_get_width(style, &v);
2090 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2091 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2092 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2096 str = (void*)0xdeadbeef;
2097 hres = IHTMLStyle_get_margin(style, &str);
2098 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2099 ok(!str, "margin = %s\n", dbgstr_w(str));
2102 hres = IHTMLStyle_put_margin(style, str);
2103 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2106 hres = IHTMLStyle_get_margin(style, &str);
2107 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2108 ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2110 hres = IHTMLStyle_put_margin(style, NULL);
2111 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2114 hres = IHTMLStyle_get_border(style, &str);
2115 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2116 ok(!str || !*str, "str is not empty\n");
2119 str = a2bstr("1px");
2120 hres = IHTMLStyle_put_border(style, str);
2121 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2124 V_VT(&v) = VT_EMPTY;
2125 hres = IHTMLStyle_get_left(style, &v);
2126 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2127 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2128 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2132 V_BSTR(&v) = a2bstr("3px");
2133 hres = IHTMLStyle_put_left(style, v);
2134 ok(hres == S_OK, "put_left failed: %08x\n", hres);
2137 V_VT(&v) = VT_EMPTY;
2138 hres = IHTMLStyle_get_left(style, &v);
2139 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2140 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2141 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2144 V_VT(&v) = VT_EMPTY;
2145 hres = IHTMLStyle_get_top(style, &v);
2146 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2147 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2148 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2152 V_BSTR(&v) = a2bstr("3px");
2153 hres = IHTMLStyle_put_top(style, v);
2154 ok(hres == S_OK, "put_top failed: %08x\n", hres);
2157 V_VT(&v) = VT_EMPTY;
2158 hres = IHTMLStyle_get_top(style, &v);
2159 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2160 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2161 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2164 V_VT(&v) = VT_EMPTY;
2165 hres = IHTMLStyle_get_height(style, &v);
2166 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2167 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2168 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2172 V_BSTR(&v) = a2bstr("64px");
2173 hres = IHTMLStyle_put_height(style, v);
2174 ok(hres == S_OK, "put_height failed: %08x\n", hres);
2177 V_VT(&v) = VT_EMPTY;
2178 hres = IHTMLStyle_get_height(style, &v);
2179 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2180 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2181 ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2184 str = (void*)0xdeadbeef;
2185 hres = IHTMLStyle_get_cursor(style, &str);
2186 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2187 ok(!str, "get_cursor != NULL\n");
2190 str = a2bstr("default");
2191 hres = IHTMLStyle_put_cursor(style, str);
2192 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2196 hres = IHTMLStyle_get_cursor(style, &str);
2197 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2198 ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", dbgstr_w(str));
2201 V_VT(&v) = VT_EMPTY;
2202 hres = IHTMLStyle_get_verticalAlign(style, &v);
2203 ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
2204 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2205 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2209 V_BSTR(&v) = a2bstr("middle");
2210 hres = IHTMLStyle_put_verticalAlign(style, v);
2211 ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
2214 V_VT(&v) = VT_EMPTY;
2215 hres = IHTMLStyle_get_verticalAlign(style, &v);
2216 ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2217 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2218 ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2221 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
2222 ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
2223 if(SUCCEEDED(hres)) {
2224 test_style2(style2);
2225 IHTMLStyle2_Release(style2);
2229 static void test_default_selection(IHTMLDocument2 *doc)
2231 IHTMLSelectionObject *selection;
2232 IHTMLTxtRange *range;
2237 hres = IHTMLDocument2_get_selection(doc, &selection);
2238 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2240 hres = IHTMLSelectionObject_get_type(selection, &str);
2241 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2242 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2245 hres = IHTMLSelectionObject_createRange(selection, &disp);
2246 IHTMLSelectionObject_Release(selection);
2247 ok(hres == S_OK, "createRange failed: %08x\n", hres);
2249 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2250 IDispatch_Release(disp);
2251 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2253 test_range_text(range, NULL);
2254 IHTMLTxtRange_Release(range);
2257 static void test_default_body(IHTMLBodyElement *body)
2263 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2264 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2265 WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2267 bstr = (void*)0xdeadbeef;
2268 hres = IHTMLBodyElement_get_background(body, &bstr);
2269 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2270 ok(bstr == NULL, "bstr != NULL\n");
2272 l = elem_get_scroll_height((IUnknown*)body);
2273 ok(l != -1, "scrollHeight == -1\n");
2274 l = elem_get_scroll_width((IUnknown*)body);
2275 ok(l != -1, "scrollWidth == -1\n");
2276 l = elem_get_scroll_top((IUnknown*)body);
2277 ok(!l, "scrollTop = %ld\n", l);
2278 elem_get_scroll_left((IUnknown*)body);
2280 /* get_text tests */
2281 hres = IHTMLBodyElement_get_text(body, &v);
2282 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2283 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2284 ok(bstr == NULL, "bstr != NULL\n");
2287 /* get_text - Invalid Text */
2289 V_BSTR(&v) = SysAllocString(sTextInvalid);
2290 hres = IHTMLBodyElement_put_text(body, v);
2291 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2294 hres = IHTMLBodyElement_get_text(body, &v);
2295 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2296 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2297 ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2300 /* get_text - Valid Text */
2302 V_BSTR(&v) = SysAllocString(sBodyText);
2303 hres = IHTMLBodyElement_put_text(body, v);
2304 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2307 hres = IHTMLBodyElement_get_text(body, &v);
2308 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2309 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2310 ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2314 static void test_body_funs(IHTMLBodyElement *body)
2316 static WCHAR sRed[] = {'r','e','d',0};
2317 static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2322 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2323 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2324 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2326 V_VT(&vbg) = VT_BSTR;
2327 V_BSTR(&vbg) = SysAllocString(sRed);
2328 hres = IHTMLBodyElement_put_bgColor(body, vbg);
2329 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2332 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2333 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2334 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2335 ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2338 /* Restore Originial */
2339 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2340 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2341 VariantClear(&vDefaultbg);
2344 static void test_window(IHTMLDocument2 *doc)
2346 IHTMLWindow2 *window, *window2, *self;
2347 IHTMLDocument2 *doc2 = NULL;
2351 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2352 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2353 test_ifaces((IUnknown*)window, window_iids);
2354 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2356 hres = IHTMLWindow2_get_document(window, &doc2);
2357 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2358 ok(doc2 != NULL, "doc2 == NULL\n");
2360 IHTMLDocument_Release(doc2);
2362 hres = IHTMLWindow2_get_window(window, &window2);
2363 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2364 ok(window2 != NULL, "window2 == NULL\n");
2366 hres = IHTMLWindow2_get_self(window, &self);
2367 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2368 ok(window2 != NULL, "self == NULL\n");
2370 ok(self == window2, "self != window2\n");
2372 IHTMLWindow2_Release(window2);
2373 IHTMLWindow2_Release(self);
2376 hres = IHTMLDocument2_get_Script(doc, &disp);
2377 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2378 ok(disp == (void*)window, "disp != window\n");
2379 IDispatch_Release(disp);
2381 IHTMLWindow2_Release(window);
2384 static void test_defaults(IHTMLDocument2 *doc)
2386 IHTMLStyleSheetsCollection *stylesheetcol;
2387 IHTMLCurrentStyle *cstyle;
2388 IHTMLBodyElement *body;
2389 IHTMLElement2 *elem2;
2395 hres = IHTMLDocument2_get_body(doc, &elem);
2396 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2398 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2399 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2400 test_default_body(body);
2401 test_body_funs(body);
2402 IHTMLBodyElement_Release(body);
2404 hres = IHTMLElement_get_style(elem, &style);
2405 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2407 test_default_style(style);
2409 test_compatmode(doc);
2411 test_navigator(doc);
2413 IHTMLStyle_Release(style);
2415 elem2 = get_elem2_iface((IUnknown*)elem);
2416 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
2417 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
2418 if(SUCCEEDED(hres)) {
2419 test_current_style(cstyle);
2420 IHTMLCurrentStyle_Release(cstyle);
2422 IHTMLElement2_Release(elem2);
2424 IHTMLElement_Release(elem);
2426 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2427 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2430 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2431 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2432 ok(l == 0, "length = %ld\n", l);
2434 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2436 test_default_selection(doc);
2437 test_doc_title(doc, "");
2440 static void test_tr_elem(IHTMLElement *elem)
2442 IHTMLElementCollection *col;
2446 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
2448 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
2449 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
2454 hres = IHTMLTableRow_get_cells(row, &col);
2455 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
2456 ok(col != NULL, "get_cells returned NULL\n");
2458 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
2459 IHTMLElementCollection_Release(col);
2461 IHTMLTable_Release(row);
2464 static void test_table_elem(IHTMLElement *elem)
2466 IHTMLElementCollection *col;
2470 static const elem_type_t row_types[] = {ET_TR,ET_TR};
2472 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2473 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2478 hres = IHTMLTable_get_rows(table, &col);
2479 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2480 ok(col != NULL, "get_ros returned NULL\n");
2482 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2483 IHTMLElementCollection_Release(col);
2485 IHTMLTable_Release(table);
2488 static void test_stylesheet(IDispatch *disp)
2490 IHTMLStyleSheetRulesCollection *col = NULL;
2491 IHTMLStyleSheet *stylesheet;
2494 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2495 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2497 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2498 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2499 ok(col != NULL, "col == NULL\n");
2501 IHTMLStyleSheetRulesCollection_Release(col);
2502 IHTMLStyleSheet_Release(stylesheet);
2505 static void test_stylesheets(IHTMLDocument2 *doc)
2507 IHTMLStyleSheetsCollection *col = NULL;
2512 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2513 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2514 ok(col != NULL, "col == NULL\n");
2516 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2517 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2518 ok(len == 1, "len=%ld\n", len);
2524 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2525 ok(hres == S_OK, "item failed: %08x\n", hres);
2526 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2527 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2528 test_stylesheet(V_DISPATCH(&res));
2535 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2536 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2537 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2538 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2541 IHTMLStyleSheetsCollection_Release(col);
2544 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2546 IDispatchEx *dispex;
2548 DISPPARAMS dp = {NULL, NULL, 0, 0};
2556 static const WCHAR w0[] = {'0',0};
2557 static const WCHAR w100[] = {'1','0','0',0};
2559 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2560 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2562 bstr = SysAllocString(w0);
2563 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2564 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2565 SysFreeString(bstr);
2568 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2569 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2570 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2571 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2572 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2573 type = get_node_type((IUnknown*)node);
2574 ok(type == 3, "type=%ld\n", type);
2575 IHTMLDOMNode_Release(node);
2578 bstr = SysAllocString(w100);
2579 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2580 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2581 SysFreeString(bstr);
2583 IDispatchEx_Release(dispex);
2588 static void test_elems(IHTMLDocument2 *doc)
2590 IHTMLElementCollection *col;
2591 IHTMLDOMChildrenCollection *child_col;
2592 IHTMLElement *elem, *elem2, *elem3;
2593 IHTMLDOMNode *node, *node2;
2598 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2599 static const WCHAR inW[] = {'i','n',0};
2600 static const WCHAR xW[] = {'x',0};
2601 static const WCHAR sW[] = {'s',0};
2602 static const WCHAR scW[] = {'s','c',0};
2603 static const WCHAR xxxW[] = {'x','x','x',0};
2604 static const WCHAR tblW[] = {'t','b','l',0};
2605 static const WCHAR row2W[] = {'r','o','w','2',0};
2607 static const elem_type_t all_types[] = {
2631 static const elem_type_t item_types[] = {
2637 hres = IHTMLDocument2_get_all(doc, &col);
2638 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2639 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2640 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2641 IHTMLElementCollection_Release(col);
2643 elem = get_doc_elem(doc);
2644 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
2645 hres = IHTMLElement_get_all(elem, &disp);
2646 IHTMLElement_Release(elem);
2647 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2649 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2650 IDispatch_Release(disp);
2651 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2652 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
2653 IHTMLElementCollection_Release(col);
2655 get_elem_by_id(doc, xxxW, FALSE);
2656 elem = get_doc_elem_by_id(doc, xxxW);
2657 ok(!elem, "elem != NULL\n");
2659 elem = get_doc_elem_by_id(doc, sW);
2660 ok(elem != NULL, "elem == NULL\n");
2662 test_elem_type((IUnknown*)elem, ET_SELECT);
2663 test_elem_attr(elem, xxxW, NULL);
2664 test_elem_attr(elem, idW, sW);
2665 test_elem_class((IUnknown*)elem, NULL);
2666 test_elem_set_class((IUnknown*)elem, "cl");
2667 test_elem_set_class((IUnknown*)elem, NULL);
2668 test_elem_tabindex((IUnknown*)elem, 0);
2669 test_elem_set_tabindex((IUnknown*)elem, 1);
2671 node = test_node_get_parent((IUnknown*)elem);
2672 ok(node != NULL, "node == NULL\n");
2673 test_node_name((IUnknown*)node, "BODY");
2674 node2 = test_node_get_parent((IUnknown*)node);
2675 IHTMLDOMNode_Release(node);
2676 ok(node2 != NULL, "node == NULL\n");
2677 test_node_name((IUnknown*)node2, "HTML");
2678 node = test_node_get_parent((IUnknown*)node2);
2679 IHTMLDOMNode_Release(node2);
2680 ok(node != NULL, "node == NULL\n");
2681 test_node_name((IUnknown*)node, "#document");
2682 type = get_node_type((IUnknown*)node);
2683 ok(type == 9, "type=%ld, expected 9\n", type);
2684 node2 = test_node_get_parent((IUnknown*)node);
2685 IHTMLDOMNode_Release(node);
2686 ok(node2 == NULL, "node != NULL\n");
2688 elem2 = test_elem_get_parent((IUnknown*)elem);
2689 ok(elem2 != NULL, "elem2 == NULL\n");
2690 test_node_name((IUnknown*)elem2, "BODY");
2691 elem3 = test_elem_get_parent((IUnknown*)elem2);
2692 IHTMLElement_Release(elem2);
2693 ok(elem3 != NULL, "elem3 == NULL\n");
2694 test_node_name((IUnknown*)elem3, "HTML");
2695 elem2 = test_elem_get_parent((IUnknown*)elem3);
2696 IHTMLElement_Release(elem3);
2697 ok(elem2 == NULL, "elem2 != NULL\n");
2699 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
2700 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
2701 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
2703 IHTMLElement_Release(elem);
2706 elem = get_elem_by_id(doc, sW, TRUE);
2708 IHTMLSelectElement *select;
2710 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
2711 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
2713 test_select_elem(select);
2715 test_elem_title((IUnknown*)select, NULL);
2716 test_elem_set_title((IUnknown*)select, "Title");
2717 test_elem_title((IUnknown*)select, "Title");
2718 test_elem_offset((IUnknown*)select);
2720 node = get_first_child((IUnknown*)select);
2721 ok(node != NULL, "node == NULL\n");
2723 test_elem_type((IUnknown*)node, ET_OPTION);
2724 IHTMLDOMNode_Release(node);
2727 type = get_node_type((IUnknown*)select);
2728 ok(type == 1, "type=%ld\n", type);
2730 IHTMLSelectElement_Release(select);
2731 IHTMLElement_Release(elem);
2734 elem = get_elem_by_id(doc, scW, TRUE);
2736 IHTMLScriptElement *script;
2739 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
2740 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
2742 hres = IHTMLScriptElement_get_type(script, &type);
2743 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2744 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
2745 SysFreeString(type);
2747 IHTMLScriptElement_Release(script);
2750 elem = get_elem_by_id(doc, inW, TRUE);
2752 IHTMLInputElement *input;
2754 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
2755 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2757 test_elem_id((IUnknown*)elem, "in");
2758 test_elem_put_id((IUnknown*)elem, "newin");
2759 test_input_get_disabled(input, VARIANT_FALSE);
2760 test_input_set_disabled(input, VARIANT_TRUE);
2761 test_input_set_disabled(input, VARIANT_FALSE);
2762 test_elem_client_size((IUnknown*)elem);
2764 test_node_get_value_str((IUnknown*)elem, NULL);
2765 test_node_put_value_str((IUnknown*)elem, "test");
2766 test_node_get_value_str((IUnknown*)elem, NULL);
2767 test_input_value((IUnknown*)elem, NULL);
2768 test_input_put_value((IUnknown*)elem, "test");
2769 test_input_value((IUnknown*)elem, NULL);
2770 test_elem_class((IUnknown*)elem, "testclass");
2771 test_elem_tabindex((IUnknown*)elem, 2);
2772 test_elem_set_tabindex((IUnknown*)elem, 3);
2773 test_elem_title((IUnknown*)elem, "test title");
2775 IHTMLInputElement_Release(input);
2776 IHTMLElement_Release(elem);
2779 elem = get_elem_by_id(doc, imgidW, TRUE);
2781 test_img_set_src((IUnknown*)elem, "about:blank");
2782 test_img_alt((IUnknown*)elem, NULL);
2783 test_img_set_alt((IUnknown*)elem, "alt test");
2784 IHTMLElement_Release(elem);
2787 elem = get_doc_elem_by_id(doc, tblW);
2788 ok(elem != NULL, "elem == NULL\n");
2790 test_table_elem(elem);
2791 IHTMLElement_Release(elem);
2794 elem = get_doc_elem_by_id(doc, row2W);
2795 ok(elem != NULL, "elem == NULL\n");
2798 IHTMLElement_Release(elem);
2801 hres = IHTMLDocument2_get_body(doc, &elem);
2802 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2804 node = get_first_child((IUnknown*)elem);
2805 ok(node != NULL, "node == NULL\n");
2807 test_ifaces((IUnknown*)node, text_iids);
2808 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2810 node2 = get_first_child((IUnknown*)node);
2811 ok(!node2, "node2 != NULL\n");
2813 type = get_node_type((IUnknown*)node);
2814 ok(type == 3, "type=%ld\n", type);
2816 test_node_get_value_str((IUnknown*)node, "text test");
2817 test_node_put_value_str((IUnknown*)elem, "test text");
2818 test_node_get_value_str((IUnknown*)node, "text test");
2820 IHTMLDOMNode_Release(node);
2823 child_col = get_child_nodes((IUnknown*)elem);
2824 ok(child_col != NULL, "child_coll == NULL\n");
2828 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
2830 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
2831 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2832 ok(length, "length=0\n");
2834 node = get_child_item(child_col, 0);
2835 ok(node != NULL, "node == NULL\n");
2837 type = get_node_type((IUnknown*)node);
2838 ok(type == 3, "type=%ld\n", type);
2839 IHTMLDOMNode_Release(node);
2842 node = get_child_item(child_col, 1);
2843 ok(node != NULL, "node == NULL\n");
2845 type = get_node_type((IUnknown*)node);
2846 ok(type == 8, "type=%ld\n", type);
2848 test_elem_id((IUnknown*)node, NULL);
2849 IHTMLDOMNode_Release(node);
2852 disp = (void*)0xdeadbeef;
2853 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
2854 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2855 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2857 disp = (void*)0xdeadbeef;
2858 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
2859 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2860 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2862 test_child_col_disp(child_col);
2864 IHTMLDOMChildrenCollection_Release(child_col);
2867 IHTMLElement_Release(elem);
2869 test_stylesheets(doc);
2870 test_create_option_elem(doc);
2872 test_doc_title(doc, "test");
2873 test_doc_set_title(doc, "test title");
2874 test_doc_title(doc, "test title");
2877 static void test_create_elems(IHTMLDocument2 *doc)
2879 IHTMLElement *elem, *body, *elem2;
2885 static const elem_type_t types1[] = { ET_TESTG };
2887 elem = test_create_elem(doc, "TEST");
2888 test_elem_tag((IUnknown*)elem, "TEST");
2889 type = get_node_type((IUnknown*)elem);
2890 ok(type == 1, "type=%ld\n", type);
2891 test_ifaces((IUnknown*)elem, elem_iids);
2892 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
2894 hres = IHTMLDocument2_get_body(doc, &body);
2895 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2896 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2898 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
2899 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
2900 elem2 = get_elem_iface((IUnknown*)node);
2901 IHTMLElement_Release(elem2);
2903 hres = IHTMLElement_get_all(body, &disp);
2904 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2905 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
2906 IDispatch_Release(disp);
2908 test_node_remove_child((IUnknown*)body, node);
2910 hres = IHTMLElement_get_all(body, &disp);
2911 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2912 test_elem_collection((IUnknown*)disp, NULL, 0);
2913 IDispatch_Release(disp);
2914 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2916 IHTMLElement_Release(body);
2917 IHTMLElement_Release(elem);
2918 IHTMLDOMNode_Release(node);
2920 node = test_create_text(doc, "test");
2921 test_ifaces((IUnknown*)node, text_iids);
2922 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2923 IHTMLDOMNode_Release(node);
2926 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
2928 IOleCommandTarget *cmdtrg;
2931 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2932 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
2934 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
2935 ok(hres == S_OK, "Exec failed: %08x\n", hres);
2937 IOleCommandTarget_Release(cmdtrg);
2940 static void test_indent(IHTMLDocument2 *doc)
2942 IHTMLElementCollection *col;
2943 IHTMLTxtRange *range;
2946 static const elem_type_t all_types[] = {
2955 static const elem_type_t indent_types[] = {
2966 hres = IHTMLDocument2_get_all(doc, &col);
2967 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2968 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2969 IHTMLElementCollection_Release(col);
2971 range = test_create_body_range(doc);
2972 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
2973 IHTMLTxtRange_Release(range);
2975 hres = IHTMLDocument2_get_all(doc, &col);
2976 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2977 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
2978 IHTMLElementCollection_Release(col);
2981 static IHTMLDocument2 *notif_doc;
2982 static BOOL doc_complete;
2984 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2985 REFIID riid, void**ppv)
2987 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2992 ok(0, "unexpected call\n");
2993 return E_NOINTERFACE;
2996 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
3001 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
3006 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
3008 if(dispID == DISPID_READYSTATE){
3012 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
3014 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
3015 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3017 if(!lstrcmpW(state, completeW))
3018 doc_complete = TRUE;
3020 SysFreeString(state);
3026 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
3028 ok(0, "unexpected call\n");
3032 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
3033 PropertyNotifySink_QueryInterface,
3034 PropertyNotifySink_AddRef,
3035 PropertyNotifySink_Release,
3036 PropertyNotifySink_OnChanged,
3037 PropertyNotifySink_OnRequestEdit
3040 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
3042 static IHTMLDocument2 *create_doc_with_string(const char *str)
3044 IPersistStreamInit *init;
3046 IHTMLDocument2 *doc;
3050 notif_doc = doc = create_document();
3054 doc_complete = FALSE;
3056 mem = GlobalAlloc(0, len);
3057 memcpy(mem, str, len);
3058 CreateStreamOnHGlobal(mem, TRUE, &stream);
3060 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
3062 IPersistStreamInit_Load(init, stream);
3063 IPersistStreamInit_Release(init);
3064 IStream_Release(stream);
3069 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
3071 IConnectionPointContainer *container;
3072 IConnectionPoint *cp;
3076 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
3077 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
3079 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
3080 IConnectionPointContainer_Release(container);
3081 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
3083 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
3084 IConnectionPoint_Release(cp);
3085 ok(hres == S_OK, "Advise failed: %08x\n", hres);
3088 typedef void (*domtest_t)(IHTMLDocument2*);
3090 static void run_domtest(const char *str, domtest_t test)
3092 IHTMLDocument2 *doc;
3093 IHTMLElement *body = NULL;
3098 doc = create_doc_with_string(str);
3099 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3101 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
3102 TranslateMessage(&msg);
3103 DispatchMessage(&msg);
3106 hres = IHTMLDocument2_get_body(doc, &body);
3107 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3110 IHTMLElement_Release(body);
3113 skip("Could not get document body. Assuming no Gecko installed.\n");
3116 ref = IHTMLDocument2_Release(doc);
3118 ref == 1, /* Vista */
3122 static void gecko_installer_workaround(BOOL disable)
3127 static BOOL has_url = FALSE;
3128 static char url[2048];
3130 if(!disable && !has_url)
3133 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
3134 if(res != ERROR_SUCCESS)
3138 DWORD type, size = sizeof(url);
3140 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
3141 if(res == ERROR_SUCCESS && type == REG_SZ)
3144 RegDeleteValue(hkey, "GeckoUrl");
3146 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
3154 gecko_installer_workaround(TRUE);
3157 run_domtest(doc_str1, test_doc_elem);
3158 run_domtest(range_test_str, test_txtrange);
3159 run_domtest(range_test2_str, test_txtrange2);
3160 run_domtest(elem_test_str, test_elems);
3161 run_domtest(doc_blank, test_create_elems);
3162 run_domtest(doc_blank, test_defaults);
3163 run_domtest(indent_test_str, test_indent);
3166 gecko_installer_workaround(FALSE);