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>"
46 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table><tbody></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
52 static const char indent_test_str[] =
53 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
55 static const WCHAR noneW[] = {'N','o','n','e',0};
57 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
58 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
59 static WCHAR wordW[] = {'w','o','r','d',0};
61 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
63 static const WCHAR idW[] = {'i','d',0};
87 static REFIID const none_iids[] = {
92 static REFIID const elem_iids[] = {
98 &IID_IConnectionPointContainer,
102 static REFIID const body_iids[] = {
107 &IID_IHTMLTextContainer,
108 &IID_IHTMLBodyElement,
110 &IID_IConnectionPointContainer,
114 static REFIID const anchor_iids[] = {
119 &IID_IHTMLAnchorElement,
121 &IID_IConnectionPointContainer,
125 static REFIID const input_iids[] = {
130 &IID_IHTMLInputElement,
131 &IID_IHTMLInputTextElement,
133 &IID_IConnectionPointContainer,
137 static REFIID const select_iids[] = {
142 &IID_IHTMLSelectElement,
144 &IID_IConnectionPointContainer,
148 static REFIID const textarea_iids[] = {
153 &IID_IHTMLTextAreaElement,
155 &IID_IConnectionPointContainer,
159 static REFIID const option_iids[] = {
164 &IID_IHTMLOptionElement,
166 &IID_IConnectionPointContainer,
170 static REFIID const table_iids[] = {
177 &IID_IConnectionPointContainer,
181 static REFIID const script_iids[] = {
186 &IID_IHTMLScriptElement,
188 &IID_IConnectionPointContainer,
192 static REFIID const text_iids[] = {
195 &IID_IHTMLDOMTextNode,
199 static REFIID const location_iids[] = {
205 static REFIID const window_iids[] = {
213 static REFIID const comment_iids[] = {
218 &IID_IHTMLCommentElement,
220 &IID_IConnectionPointContainer,
230 static const elem_type_info_t elem_type_infos[] = {
231 {"", none_iids, NULL},
232 {"HTML", elem_iids, NULL},
233 {"HEAD", elem_iids, NULL},
234 {"TITLE", elem_iids, NULL},
235 {"BODY", body_iids, NULL},
236 {"A", anchor_iids, NULL},
237 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
238 {"SELECT", select_iids, NULL},
239 {"TEXTAREA", textarea_iids, NULL},
240 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
241 {"STYLE", elem_iids, NULL},
242 {"BLOCKQUOTE",elem_iids, NULL},
243 {"P", elem_iids, NULL},
244 {"BR", elem_iids, NULL},
245 {"TABLE", table_iids, NULL},
246 {"TBODY", elem_iids, NULL},
247 {"SCRIPT", script_iids, NULL},
248 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
249 {"!", comment_iids, NULL}
252 static const char *dbgstr_w(LPCWSTR str)
254 static char buf[512];
257 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
261 static const char *dbgstr_guid(REFIID riid)
265 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
266 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
267 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
268 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
273 static int strcmp_wa(LPCWSTR strw, const char *stra)
276 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
277 return lstrcmpW(strw, buf);
280 static BSTR a2bstr(const char *str)
285 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
286 ret = SysAllocStringLen(NULL, len);
287 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
292 static IHTMLDocument2 *create_document(void)
297 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
298 &IID_IHTMLDocument2, (void**)&doc);
299 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
304 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
305 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
307 const IID * const *piid;
311 for(piid = iids; *piid; piid++) {
312 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
313 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
315 IUnknown_Release(unk);
319 #define test_disp(u,id) _test_disp(__LINE__,u,id)
320 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
327 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
328 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
333 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
334 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
335 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
337 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
338 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
340 if(SUCCEEDED(hres)) {
343 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
344 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
345 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
347 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
348 ITypeInfo_Release(typeinfo);
351 IDispatchEx_Release(dispex);
354 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
355 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
361 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
362 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
364 hres = IHTMLDOMNode_get_nodeName(node, &name);
365 IHTMLDOMNode_Release(node);
366 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
367 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
372 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
373 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
379 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
380 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
382 hres = IHTMLElement_get_tagName(elem, &tag);
383 IHTMLElement_Release(elem);
384 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
385 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
390 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
391 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
393 _test_elem_tag(line, unk, elem_type_infos[type].tag);
394 _test_ifaces(line, unk, elem_type_infos[type].iids);
396 if(elem_type_infos[type].dispiid)
397 _test_disp(line, unk, elem_type_infos[type].dispiid);
400 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
401 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
409 tmp = SysAllocString(name);
410 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
412 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
415 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
416 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
418 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
421 VariantClear(&value);
424 static void test_doc_elem(IHTMLDocument2 *doc)
427 IHTMLDocument3 *doc3;
430 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
431 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
433 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
434 IHTMLDocument3_Release(doc3);
435 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
437 test_node_name((IUnknown*)elem, "HTML");
438 test_elem_tag((IUnknown*)elem, "HTML");
440 IHTMLElement_Release(elem);
443 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
444 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
447 IHTMLDocument3 *doc3;
450 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
451 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
452 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
453 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
454 IHTMLDocument3_Release(doc3);
459 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
460 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
465 hres = IHTMLOptionElement_get_text(option, &bstr);
466 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
467 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
471 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
472 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
478 hres = IHTMLOptionElement_put_text(option, bstr);
480 ok(hres == S_OK, "put_text failed: %08x\n", hres);
482 _test_option_text(line, option, text);
485 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
486 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
491 hres = IHTMLOptionElement_get_value(option, &bstr);
492 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
493 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
497 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
498 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
503 bstr = a2bstr(value);
504 hres = IHTMLOptionElement_put_value(option, bstr);
506 ok(hres == S_OK, "put_value failed: %08x\n", hres);
508 _test_option_value(line, option, value);
511 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
512 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
513 const char *txt, const char *val)
515 IHTMLOptionElementFactory *factory;
516 IHTMLOptionElement *option;
517 IHTMLWindow2 *window;
518 VARIANT text, value, empty;
521 hres = IHTMLDocument2_get_parentWindow(doc, &window);
522 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
524 hres = IHTMLWindow2_get_Option(window, &factory);
525 IHTMLWindow2_Release(window);
526 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
528 V_VT(&text) = VT_BSTR;
529 V_BSTR(&text) = a2bstr(txt);
530 V_VT(&value) = VT_BSTR;
531 V_BSTR(&value) = a2bstr(val);
532 V_VT(&empty) = VT_EMPTY;
534 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
535 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
537 IHTMLOptionElementFactory_Release(factory);
539 VariantClear(&value);
541 _test_option_text(line, option, txt);
542 _test_option_value(line, option, val);
547 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
548 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
550 long len = 0xdeadbeef;
553 hres = IHTMLSelectElement_get_length(select, &len);
554 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
555 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
558 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
559 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
561 long idx = 0xdeadbeef;
564 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
565 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
566 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
569 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
570 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
574 hres = IHTMLSelectElement_put_selectedIndex(select, index);
575 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
576 _test_select_selidx(line, select, index);
579 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
580 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
585 hres = IHTMLTxtRange_get_text(range, &text);
586 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
589 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
590 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
592 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
599 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
600 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
604 hres = IHTMLTxtRange_collapse(range, b);
605 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
606 _test_range_text(line, range, NULL);
609 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
610 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
611 VARIANT_BOOL exb, const char *extext)
613 VARIANT_BOOL b = 0xe0e0;
616 hres = IHTMLTxtRange_expand(range, unit, &b);
617 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
618 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
619 _test_range_text(line, range, extext);
622 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
623 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
628 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
629 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
630 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
631 _test_range_text(line, range, NULL);
634 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
635 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
636 LPWSTR unit, long cnt, long excnt)
641 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
642 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
643 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
646 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
647 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
652 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
653 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
654 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
657 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
658 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
661 BSTR bstr = a2bstr(text);
663 hres = IHTMLTxtRange_put_text(range, bstr);
664 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
666 _test_range_text(line, range, NULL);
669 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
670 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
676 hres = IHTMLTxtRange_inRange(range1, range2, &b);
677 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
678 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
681 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
682 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
688 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
689 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
690 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
693 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
694 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
695 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
698 test_range_inrange(range1, range2, VARIANT_TRUE);
699 test_range_inrange(range2, range1, VARIANT_TRUE);
703 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
704 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
709 hres = IHTMLTxtRange_parentElement(range, &elem);
710 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
712 _test_elem_type(line, (IUnknown*)elem, type);
714 IHTMLElement_Release(elem);
717 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
718 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
719 const elem_type_t *elem_types, long exlen)
727 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
729 hres = IHTMLElementCollection_get_length(col, &len);
730 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
731 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
736 V_VT(&index) = VT_EMPTY;
739 for(i=0; i<len; i++) {
741 disp = (void*)0xdeadbeef;
742 hres = IHTMLElementCollection_item(col, name, index, &disp);
743 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
744 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
745 if(FAILED(hres) || !disp)
748 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
749 IDispatch_Release(disp);
753 disp = (void*)0xdeadbeef;
754 hres = IHTMLElementCollection_item(col, name, index, &disp);
755 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
756 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
759 disp = (void*)0xdeadbeef;
760 hres = IHTMLElementCollection_item(col, name, index, &disp);
761 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
762 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
765 #define get_first_child(n) _get_first_child(__LINE__,n)
766 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
768 IHTMLDOMNode *node, *child = NULL;
771 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
772 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
776 hres = IHTMLDOMNode_get_firstChild(node, &child);
777 IHTMLDOMNode_Release(node);
778 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
783 #define get_node_type(n) _get_node_type(__LINE__,n)
784 static long _get_node_type(unsigned line, IUnknown *unk)
790 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
791 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
793 hres = IHTMLDOMNode_get_nodeType(node, &type);
794 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
796 IHTMLDOMNode_Release(node);
801 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
802 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
804 VARIANT_BOOL disabled = 100;
807 hres = IHTMLInputElement_get_disabled(input, &disabled);
808 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
809 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
812 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
813 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
815 IHTMLDOMChildrenCollection *col = NULL;
820 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
821 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
825 hres = IHTMLDOMNode_get_childNodes(node, &disp);
826 IHTMLDOMNode_Release(node);
827 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
831 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
832 IDispatch_Release(disp);
833 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
838 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
839 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
841 IHTMLDOMNode *node = NULL;
845 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
846 ok(hres == S_OK, "item failed: %08x\n", hres);
848 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMNode, (void**)&node);
849 IDispatch_Release(disp);
850 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
855 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
856 const elem_type_t *elem_types, long len)
858 IHTMLElementCollection *elcol;
864 V_VT(&index) = VT_EMPTY;
865 V_VT(&name) = VT_BSTR;
866 V_BSTR(&name) = SysAllocString(n);
868 hres = IHTMLElementCollection_item(col, name, index, &disp);
869 ok(hres == S_OK, "item failed: %08x\n", hres);
871 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
872 IDispatch_Release(disp);
873 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
874 test_elem_collection(elcol, elem_types, len);
875 IHTMLElementCollection_Release(elcol);
877 V_VT(&index) = VT_I4;
879 for(i=0; i<len; i++) {
881 disp = (void*)0xdeadbeef;
882 hres = IHTMLElementCollection_item(col, name, index, &disp);
883 ok(hres == S_OK, "item failed: %08x\n", hres);
884 ok(disp != NULL, "disp == NULL\n");
885 if(FAILED(hres) || !disp)
888 test_elem_type((IUnknown*)disp, elem_types[i]);
890 IDispatch_Release(disp);
894 disp = (void*)0xdeadbeef;
895 hres = IHTMLElementCollection_item(col, name, index, &disp);
896 ok(hres == S_OK, "item failed: %08x\n", hres);
897 ok(disp == NULL, "disp != NULL\n");
900 disp = (void*)0xdeadbeef;
901 hres = IHTMLElementCollection_item(col, name, index, &disp);
902 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
903 ok(disp == NULL, "disp != NULL\n");
905 SysFreeString(V_BSTR(&name));
908 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
910 IHTMLElementCollection *col;
912 IDispatch *disp = (void*)0xdeadbeef;
916 hres = IHTMLDocument2_get_all(doc, &col);
917 ok(hres == S_OK, "get_all failed: %08x\n", hres);
918 ok(col != NULL, "col == NULL\n");
919 if(FAILED(hres) || !col)
922 V_VT(&index) = VT_EMPTY;
923 V_VT(&name) = VT_BSTR;
924 V_BSTR(&name) = SysAllocString(id);
926 hres = IHTMLElementCollection_item(col, name, index, &disp);
927 IHTMLElementCollection_Release(col);
928 SysFreeString(V_BSTR(&name));
929 ok(hres == S_OK, "item failed: %08x\n", hres);
930 if(!expect_success) {
931 ok(disp == NULL, "disp != NULL\n");
935 ok(disp != NULL, "disp == NULL\n");
939 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
940 IDispatch_Release(disp);
941 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
946 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
948 IHTMLDocument3 *doc3;
953 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
954 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
956 tmp = SysAllocString(id);
957 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
959 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
961 IHTMLDocument3_Release(doc3);
966 static void test_select_elem(IHTMLSelectElement *select)
968 test_select_length(select, 2);
969 test_select_selidx(select, 0);
970 test_select_put_selidx(select, 1);
973 static void test_create_option_elem(IHTMLDocument2 *doc)
975 IHTMLOptionElement *option;
977 option = create_option_elem(doc, "test text", "test value");
979 test_option_put_text(option, "new text");
980 test_option_put_value(option, "new value");
982 IHTMLOptionElement_Release(option);
985 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
987 IHTMLBodyElement *body;
988 IHTMLTxtRange *range;
992 hres = IHTMLDocument2_get_body(doc, &elem);
993 ok(hres == S_OK, "get_body failed: %08x\n", hres);
995 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
996 IHTMLElement_Release(elem);
998 hres = IHTMLBodyElement_createTextRange(body, &range);
999 IHTMLBodyElement_Release(body);
1000 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1005 static void test_txtrange(IHTMLDocument2 *doc)
1007 IHTMLTxtRange *body_range, *range, *range2;
1008 IHTMLSelectionObject *selection;
1009 IDispatch *disp_range;
1012 body_range = test_create_body_range(doc);
1014 test_range_text(body_range, "test abc 123\r\nit's text");
1016 hres = IHTMLTxtRange_duplicate(body_range, &range);
1017 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1019 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1020 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1021 test_range_isequal(range, range2, VARIANT_TRUE);
1023 test_range_text(range, "test abc 123\r\nit's text");
1024 test_range_text(body_range, "test abc 123\r\nit's text");
1026 test_range_collapse(range, TRUE);
1027 test_range_isequal(range, range2, VARIANT_FALSE);
1028 test_range_inrange(range, range2, VARIANT_FALSE);
1029 test_range_inrange(range2, range, VARIANT_TRUE);
1030 IHTMLTxtRange_Release(range2);
1032 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1033 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1034 test_range_move(range, characterW, 2, 2);
1035 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1037 test_range_collapse(range, FALSE);
1038 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1040 test_range_collapse(range, FALSE);
1041 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1042 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1043 test_range_move(range, characterW, 2, 2);
1044 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1045 test_range_moveend(range, characterW, -5, -5);
1046 test_range_text(range, NULL);
1047 test_range_moveend(range, characterW, 3, 3);
1048 test_range_text(range, "c 1");
1049 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1050 test_range_collapse(range, TRUE);
1051 test_range_move(range, characterW, 4, 4);
1052 test_range_moveend(range, characterW, 1, 1);
1053 test_range_text(range, " ");
1054 test_range_move(range, wordW, 1, 1);
1055 test_range_moveend(range, characterW, 2, 2);
1056 test_range_text(range, "ab");
1058 IHTMLTxtRange_Release(range);
1060 hres = IHTMLTxtRange_duplicate(body_range, &range);
1061 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1063 test_range_text(range, "test abc 123\r\nit's text");
1064 test_range_move(range, characterW, 3, 3);
1065 test_range_moveend(range, characterW, 1, 1);
1066 test_range_text(range, "t");
1067 test_range_moveend(range, characterW, 3, 3);
1068 test_range_text(range, "t ab");
1069 test_range_moveend(range, characterW, -2, -2);
1070 test_range_text(range, "t ");
1071 test_range_move(range, characterW, 6, 6);
1072 test_range_moveend(range, characterW, 3, 3);
1073 test_range_text(range, "123");
1074 test_range_moveend(range, characterW, 2, 2);
1075 test_range_text(range, "123\r\ni");
1077 IHTMLTxtRange_Release(range);
1079 hres = IHTMLTxtRange_duplicate(body_range, &range);
1080 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1082 test_range_move(range, wordW, 1, 1);
1083 test_range_moveend(range, characterW, 2, 2);
1084 test_range_text(range, "ab");
1086 test_range_move(range, characterW, -2, -2);
1087 test_range_moveend(range, characterW, 2, 2);
1088 test_range_text(range, "t ");
1090 test_range_move(range, wordW, 3, 3);
1091 test_range_move(range, wordW, -2, -2);
1092 test_range_moveend(range, characterW, 2, 2);
1093 test_range_text(range, "ab");
1095 test_range_move(range, characterW, -6, -5);
1096 test_range_moveend(range, characterW, -1, 0);
1097 test_range_moveend(range, characterW, -6, 0);
1098 test_range_move(range, characterW, 2, 2);
1099 test_range_moveend(range, characterW, 2, 2);
1100 test_range_text(range, "st");
1101 test_range_moveend(range, characterW, -6, -4);
1102 test_range_moveend(range, characterW, 2, 2);
1104 IHTMLTxtRange_Release(range);
1106 hres = IHTMLTxtRange_duplicate(body_range, &range);
1107 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1109 test_range_move(range, wordW, 2, 2);
1110 test_range_moveend(range, characterW, 2, 2);
1111 test_range_text(range, "12");
1113 test_range_move(range, characterW, 15, 14);
1114 test_range_move(range, characterW, -2, -2);
1115 test_range_moveend(range, characterW, 3, 2);
1116 test_range_text(range, "t");
1117 test_range_moveend(range, characterW, -1, -1);
1118 test_range_text(range, "t");
1119 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1120 test_range_move(range, characterW, -2, -2);
1121 test_range_moveend(range, characterW, 2, 2);
1122 test_range_text(range, "s ");
1123 test_range_move(range, characterW, 100, 7);
1124 test_range_move(range, wordW, 1, 0);
1125 test_range_move(range, characterW, -2, -2);
1126 test_range_moveend(range, characterW, 3, 2);
1127 test_range_text(range, "t");
1129 IHTMLTxtRange_Release(range);
1131 hres = IHTMLTxtRange_duplicate(body_range, &range);
1132 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1134 test_range_collapse(range, TRUE);
1135 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1136 test_range_put_text(range, "word");
1137 test_range_text(body_range, "wordabc 123\r\nit's text");
1138 test_range_text(range, NULL);
1139 test_range_moveend(range, characterW, 3, 3);
1140 test_range_text(range, "abc");
1141 test_range_movestart(range, characterW, -2, -2);
1142 test_range_text(range, "rdabc");
1143 test_range_movestart(range, characterW, 3, 3);
1144 test_range_text(range, "bc");
1145 test_range_movestart(range, characterW, 4, 4);
1146 test_range_text(range, NULL);
1147 test_range_movestart(range, characterW, -3, -3);
1148 test_range_text(range, "c 1");
1149 test_range_movestart(range, characterW, -7, -6);
1150 test_range_text(range, "wordabc 1");
1151 test_range_movestart(range, characterW, 100, 22);
1152 test_range_text(range, NULL);
1154 IHTMLTxtRange_Release(range);
1155 IHTMLTxtRange_Release(body_range);
1157 hres = IHTMLDocument2_get_selection(doc, &selection);
1158 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1160 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1161 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1162 IHTMLSelectionObject_Release(selection);
1164 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1165 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1166 IDispatch_Release(disp_range);
1168 test_range_text(range, NULL);
1169 test_range_moveend(range, characterW, 3, 3);
1170 test_range_text(range, "wor");
1171 test_range_parent(range, ET_BODY);
1172 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1173 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1174 test_range_move(range, characterW, 3, 3);
1175 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1176 test_range_moveend(range, characterW, -4, -4);
1177 test_range_put_text(range, "abc def ");
1178 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1179 test_range_move(range, wordW, 1, 1);
1180 test_range_movestart(range, characterW, -1, -1);
1181 test_range_text(range, " ");
1182 test_range_move(range, wordW, 1, 1);
1183 test_range_moveend(range, characterW, 3, 3);
1184 test_range_text(range, "def");
1185 test_range_put_text(range, "xyz");
1186 test_range_moveend(range, characterW, 1, 1);
1187 test_range_move(range, wordW, 1, 1);
1188 test_range_moveend(range, characterW, 2, 2);
1189 test_range_text(range, "ab");
1191 IHTMLTxtRange_Release(range);
1194 static void test_txtrange2(IHTMLDocument2 *doc)
1196 IHTMLTxtRange *range;
1198 range = test_create_body_range(doc);
1200 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1201 test_range_move(range, characterW, 5, 5);
1202 test_range_moveend(range, characterW, 1, 1);
1203 test_range_text(range, "2");
1204 test_range_move(range, characterW, -3, -3);
1205 test_range_moveend(range, characterW, 3, 3);
1206 test_range_text(range, "c\r\n\r\n1");
1207 test_range_collapse(range, VARIANT_FALSE);
1208 test_range_moveend(range, characterW, 4, 4);
1209 test_range_text(range, "23");
1210 test_range_moveend(range, characterW, 1, 1);
1211 test_range_text(range, "23\r\n\r\n\r\nd");
1212 test_range_moveend(range, characterW, -1, -1);
1213 test_range_text(range, "23");
1214 test_range_moveend(range, characterW, -1, -1);
1215 test_range_text(range, "23");
1216 test_range_moveend(range, characterW, -2, -2);
1217 test_range_text(range, "2");
1219 IHTMLTxtRange_Release(range);
1222 static void test_compatmode(IHTMLDocument2 *doc)
1224 IHTMLDocument5 *doc5;
1228 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1229 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1233 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1234 IHTMLDocument5_Release(doc5);
1235 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1236 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1237 SysFreeString(mode);
1240 static void test_location(IHTMLDocument2 *doc)
1242 IHTMLLocation *location, *location2;
1246 hres = IHTMLDocument2_get_location(doc, &location);
1247 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1249 hres = IHTMLDocument2_get_location(doc, &location2);
1250 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1252 ok(location == location2, "location != location2\n");
1254 test_ifaces((IUnknown*)location, location_iids);
1256 IHTMLLocation_Release(location2);
1257 ref = IHTMLLocation_Release(location);
1258 ok(!ref, "location chould be destroyed here\n");
1261 static void test_navigator(IHTMLDocument2 *doc)
1263 IHTMLWindow2 *window;
1264 IOmNavigator *navigator, *navigator2;
1268 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1269 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1271 hres = IHTMLWindow2_get_navigator(window, &navigator);
1272 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1273 ok(navigator != NULL, "navigator == NULL\n");
1274 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1276 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1277 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1278 ok(navigator != navigator2, "navigator2 != navihgator\n");
1280 IHTMLWindow2_Release(window);
1281 IOmNavigator_Release(navigator2);
1282 ref = IOmNavigator_Release(navigator);
1283 ok(!ref, "navigator should be destroyed here\n");
1286 static void test_default_style(IHTMLStyle *style)
1293 str = (void*)0xdeadbeef;
1294 hres = IHTMLStyle_get_fontFamily(style, &str);
1295 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1296 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1298 str = (void*)0xdeadbeef;
1299 hres = IHTMLStyle_get_fontWeight(style, &str);
1300 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1301 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1303 str = (void*)0xdeadbeef;
1304 hres = IHTMLStyle_get_display(style, &str);
1305 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1306 ok(!str, "display = %s\n", dbgstr_w(str));
1308 str = (void*)0xdeadbeef;
1309 hres = IHTMLStyle_get_visibility(style, &str);
1310 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1311 ok(!str, "visibility = %s\n", dbgstr_w(str));
1314 hres = IHTMLStyle_get_fontSize(style, &v);
1315 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1316 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1317 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1320 hres = IHTMLStyle_get_color(style, &v);
1321 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1322 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1323 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1326 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1327 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1328 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1331 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1332 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1333 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1336 static void test_default_selection(IHTMLDocument2 *doc)
1338 IHTMLSelectionObject *selection;
1339 IHTMLTxtRange *range;
1344 hres = IHTMLDocument2_get_selection(doc, &selection);
1345 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1347 hres = IHTMLSelectionObject_get_type(selection, &str);
1348 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1349 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1352 hres = IHTMLSelectionObject_createRange(selection, &disp);
1353 IHTMLSelectionObject_Release(selection);
1354 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1356 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1357 IDispatch_Release(disp);
1358 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1360 test_range_text(range, NULL);
1361 IHTMLTxtRange_Release(range);
1364 static void test_default_body(IHTMLBodyElement *body)
1369 bstr = (void*)0xdeadbeef;
1370 hres = IHTMLBodyElement_get_background(body, &bstr);
1371 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1372 ok(bstr == NULL, "bstr != NULL\n");
1375 static void test_window(IHTMLDocument2 *doc)
1377 IHTMLWindow2 *window;
1378 IHTMLDocument2 *doc2 = NULL;
1381 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1382 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
1383 test_ifaces((IUnknown*)window, window_iids);
1384 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
1386 hres = IHTMLWindow2_get_document(window, &doc2);
1387 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1388 ok(doc2 != NULL, "doc2 == NULL\n");
1390 IHTMLDocument_Release(doc2);
1391 IHTMLWindow2_Release(window);
1394 static void test_defaults(IHTMLDocument2 *doc)
1396 IHTMLStyleSheetsCollection *stylesheetcol;
1397 IHTMLBodyElement *body;
1403 hres = IHTMLDocument2_get_body(doc, &elem);
1404 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1406 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1407 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1408 test_default_body(body);
1409 IHTMLBodyElement_Release(body);
1411 hres = IHTMLElement_get_style(elem, &style);
1412 IHTMLElement_Release(elem);
1413 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1415 test_default_style(style);
1417 test_compatmode(doc);
1419 test_navigator(doc);
1421 IHTMLStyle_Release(style);
1423 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1424 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1427 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1428 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1429 ok(l == 0, "length = %ld\n", l);
1431 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1433 test_default_selection(doc);
1436 static void test_stylesheet(IDispatch *disp)
1438 IHTMLStyleSheetRulesCollection *col = NULL;
1439 IHTMLStyleSheet *stylesheet;
1442 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1443 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1445 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1446 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1447 ok(col != NULL, "col == NULL\n");
1449 IHTMLStyleSheetRulesCollection_Release(col);
1450 IHTMLStyleSheet_Release(stylesheet);
1453 static void test_stylesheets(IHTMLDocument2 *doc)
1455 IHTMLStyleSheetsCollection *col = NULL;
1460 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1461 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1462 ok(col != NULL, "col == NULL\n");
1464 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1465 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1466 ok(len == 1, "len=%ld\n", len);
1472 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1473 ok(hres == S_OK, "item failed: %08x\n", hres);
1474 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1475 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1476 test_stylesheet(V_DISPATCH(&res));
1483 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1484 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1485 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1486 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1489 IHTMLStyleSheetsCollection_Release(col);
1492 static void test_elems(IHTMLDocument2 *doc)
1494 IHTMLElementCollection *col;
1495 IHTMLDOMChildrenCollection *child_col;
1497 IHTMLDOMNode *node, *node2;
1502 static const WCHAR inW[] = {'i','n',0};
1503 static const WCHAR xW[] = {'x',0};
1504 static const WCHAR sW[] = {'s',0};
1505 static const WCHAR scW[] = {'s','c',0};
1506 static const WCHAR xxxW[] = {'x','x','x',0};
1508 static const elem_type_t all_types[] = {
1527 static const elem_type_t item_types[] = {
1533 hres = IHTMLDocument2_get_all(doc, &col);
1534 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1535 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1536 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1537 IHTMLElementCollection_Release(col);
1539 elem = get_doc_elem(doc);
1540 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1541 hres = IHTMLElement_get_all(elem, &disp);
1542 IHTMLElement_Release(elem);
1543 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1545 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1546 IDispatch_Release(disp);
1547 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1548 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1549 IHTMLElementCollection_Release(col);
1551 get_elem_by_id(doc, xxxW, FALSE);
1552 elem = get_doc_elem_by_id(doc, xxxW);
1553 ok(!elem, "elem != NULL\n");
1555 elem = get_doc_elem_by_id(doc, sW);
1556 ok(elem != NULL, "elem == NULL\n");
1558 test_elem_type((IUnknown*)elem, ET_SELECT);
1559 test_elem_attr(elem, xxxW, NULL);
1560 test_elem_attr(elem, idW, sW);
1561 IHTMLElement_Release(elem);
1564 elem = get_elem_by_id(doc, sW, TRUE);
1566 IHTMLSelectElement *select;
1568 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1569 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1571 test_select_elem(select);
1573 node = get_first_child((IUnknown*)select);
1574 ok(node != NULL, "node == NULL\n");
1576 test_elem_type((IUnknown*)node, ET_OPTION);
1577 IHTMLDOMNode_Release(node);
1580 type = get_node_type((IUnknown*)select);
1581 ok(type == 1, "type=%ld\n", type);
1583 IHTMLSelectElement_Release(select);
1584 IHTMLElement_Release(elem);
1587 elem = get_elem_by_id(doc, scW, TRUE);
1589 IHTMLScriptElement *script;
1592 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1593 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1595 hres = IHTMLScriptElement_get_type(script, &type);
1596 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1597 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1598 SysFreeString(type);
1600 IHTMLScriptElement_Release(script);
1603 elem = get_elem_by_id(doc, inW, TRUE);
1605 IHTMLInputElement *input;
1607 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
1608 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1610 test_input_get_disabled(input, VARIANT_FALSE);
1612 IHTMLInputElement_Release(input);
1613 IHTMLElement_Release(elem);
1616 hres = IHTMLDocument2_get_body(doc, &elem);
1617 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1619 node = get_first_child((IUnknown*)elem);
1620 ok(node != NULL, "node == NULL\n");
1622 test_ifaces((IUnknown*)node, text_iids);
1623 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
1625 node2 = get_first_child((IUnknown*)node);
1626 ok(!node2, "node2 != NULL\n");
1628 type = get_node_type((IUnknown*)node);
1629 ok(type == 3, "type=%ld\n", type);
1631 IHTMLDOMNode_Release(node);
1634 child_col = get_child_nodes((IUnknown*)elem);
1635 ok(child_col != NULL, "child_coll == NULL\n");
1639 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
1641 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
1642 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1643 ok(length, "length=0\n");
1645 node = get_child_item(child_col, 0);
1646 ok(node != NULL, "node == NULL\n");
1648 type = get_node_type((IUnknown*)node);
1649 ok(type == 3, "type=%ld\n", type);
1650 IHTMLDOMNode_Release(node);
1653 node = get_child_item(child_col, 1);
1654 ok(node != NULL, "node == NULL\n");
1656 type = get_node_type((IUnknown*)node);
1657 ok(type == 8, "type=%ld\n", type);
1658 IHTMLDOMNode_Release(node);
1661 disp = (void*)0xdeadbeef;
1662 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
1663 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1664 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
1666 IHTMLDOMChildrenCollection_Release(child_col);
1669 IHTMLElement_Release(elem);
1671 test_stylesheets(doc);
1672 test_create_option_elem(doc);
1675 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1677 IOleCommandTarget *cmdtrg;
1680 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1681 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1683 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1684 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1686 IOleCommandTarget_Release(cmdtrg);
1689 static void test_indent(IHTMLDocument2 *doc)
1691 IHTMLElementCollection *col;
1692 IHTMLTxtRange *range;
1695 static const elem_type_t all_types[] = {
1704 static const elem_type_t indent_types[] = {
1715 hres = IHTMLDocument2_get_all(doc, &col);
1716 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1717 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1718 IHTMLElementCollection_Release(col);
1720 range = test_create_body_range(doc);
1721 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1722 IHTMLTxtRange_Release(range);
1724 hres = IHTMLDocument2_get_all(doc, &col);
1725 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1726 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1727 IHTMLElementCollection_Release(col);
1730 static IHTMLDocument2 *notif_doc;
1731 static BOOL doc_complete;
1733 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1734 REFIID riid, void**ppv)
1736 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1741 ok(0, "unexpected call\n");
1742 return E_NOINTERFACE;
1745 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1750 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1755 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1757 if(dispID == DISPID_READYSTATE){
1761 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1763 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1764 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1766 if(!lstrcmpW(state, completeW))
1767 doc_complete = TRUE;
1769 SysFreeString(state);
1775 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1777 ok(0, "unexpected call\n");
1781 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1782 PropertyNotifySink_QueryInterface,
1783 PropertyNotifySink_AddRef,
1784 PropertyNotifySink_Release,
1785 PropertyNotifySink_OnChanged,
1786 PropertyNotifySink_OnRequestEdit
1789 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1791 static IHTMLDocument2 *create_doc_with_string(const char *str)
1793 IPersistStreamInit *init;
1795 IHTMLDocument2 *doc;
1799 notif_doc = doc = create_document();
1803 doc_complete = FALSE;
1805 mem = GlobalAlloc(0, len);
1806 memcpy(mem, str, len);
1807 CreateStreamOnHGlobal(mem, TRUE, &stream);
1809 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1811 IPersistStreamInit_Load(init, stream);
1812 IPersistStreamInit_Release(init);
1813 IStream_Release(stream);
1818 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1820 IConnectionPointContainer *container;
1821 IConnectionPoint *cp;
1825 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1826 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1828 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1829 IConnectionPointContainer_Release(container);
1830 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1832 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1833 IConnectionPoint_Release(cp);
1834 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1837 typedef void (*domtest_t)(IHTMLDocument2*);
1839 static void run_domtest(const char *str, domtest_t test)
1841 IHTMLDocument2 *doc;
1842 IHTMLElement *body = NULL;
1847 doc = create_doc_with_string(str);
1848 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1850 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1851 TranslateMessage(&msg);
1852 DispatchMessage(&msg);
1855 hres = IHTMLDocument2_get_body(doc, &body);
1856 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1859 IHTMLElement_Release(body);
1862 skip("Could not get document body. Assuming no Gecko installed.\n");
1865 ref = IHTMLDocument2_Release(doc);
1866 ok(!ref, "ref = %d\n", ref);
1869 static void gecko_installer_workaround(BOOL disable)
1874 static BOOL has_url = FALSE;
1875 static char url[2048];
1877 if(!disable && !has_url)
1880 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1881 if(res != ERROR_SUCCESS)
1885 DWORD type, size = sizeof(url);
1887 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1888 if(res == ERROR_SUCCESS && type == REG_SZ)
1891 RegDeleteValue(hkey, "GeckoUrl");
1893 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1901 gecko_installer_workaround(TRUE);
1904 run_domtest(doc_str1, test_doc_elem);
1905 run_domtest(range_test_str, test_txtrange);
1906 run_domtest(range_test2_str, test_txtrange2);
1907 run_domtest(elem_test_str, test_elems);
1908 run_domtest(doc_blank, test_defaults);
1909 run_domtest(indent_test_str, test_indent);
1912 gecko_installer_workaround(FALSE);