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>"
52 "<iframe src=\"about:blank\"></iframe>"
54 static const char indent_test_str
[] =
55 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
57 static const WCHAR noneW
[] = {'N','o','n','e',0};
59 static WCHAR characterW
[] = {'c','h','a','r','a','c','t','e','r',0};
60 static WCHAR texteditW
[] = {'t','e','x','t','e','d','i','t',0};
61 static WCHAR wordW
[] = {'w','o','r','d',0};
63 static const WCHAR text_javascriptW
[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
65 static const WCHAR idW
[] = {'i','d',0};
94 static const IID
* const none_iids
[] = {
99 static const IID
* const elem_iids
[] = {
106 &IID_IConnectionPointContainer
,
110 static const IID
* const body_iids
[] = {
116 &IID_IHTMLTextContainer
,
117 &IID_IHTMLBodyElement
,
119 &IID_IConnectionPointContainer
,
123 static const IID
* const anchor_iids
[] = {
129 &IID_IHTMLAnchorElement
,
131 &IID_IConnectionPointContainer
,
135 static const IID
* const input_iids
[] = {
141 &IID_IHTMLInputElement
,
142 &IID_IHTMLInputTextElement
,
144 &IID_IConnectionPointContainer
,
148 static const IID
* const select_iids
[] = {
154 &IID_IHTMLSelectElement
,
156 &IID_IConnectionPointContainer
,
160 static const IID
* const textarea_iids
[] = {
166 &IID_IHTMLTextAreaElement
,
168 &IID_IConnectionPointContainer
,
172 static const IID
* const option_iids
[] = {
178 &IID_IHTMLOptionElement
,
180 &IID_IConnectionPointContainer
,
184 static const IID
* const table_iids
[] = {
192 &IID_IConnectionPointContainer
,
196 static const IID
* const script_iids
[] = {
202 &IID_IHTMLScriptElement
,
204 &IID_IConnectionPointContainer
,
208 static const IID
* const text_iids
[] = {
211 &IID_IHTMLDOMTextNode
,
215 static const IID
* const location_iids
[] = {
221 static const IID
* const window_iids
[] = {
229 static const IID
* const comment_iids
[] = {
235 &IID_IHTMLCommentElement
,
237 &IID_IConnectionPointContainer
,
241 static const IID
* const img_iids
[] = {
248 &IID_IHTMLImgElement
,
249 &IID_IConnectionPointContainer
,
253 static const IID
* const tr_iids
[] = {
261 &IID_IConnectionPointContainer
,
265 static const IID
* const td_iids
[] = {
272 &IID_IConnectionPointContainer
,
276 static const IID
* const iframe_iids
[] = {
282 &IID_IHTMLFrameBase2
,
284 &IID_IConnectionPointContainer
,
288 static const IID
* const generic_iids
[] = {
294 &IID_IHTMLGenericElement
,
296 &IID_IConnectionPointContainer
,
300 static const IID
* const style_iids
[] = {
309 static const IID
* const cstyle_iids
[] = {
313 &IID_IHTMLCurrentStyle
,
323 static const elem_type_info_t elem_type_infos
[] = {
324 {"", none_iids
, NULL
},
325 {"HTML", elem_iids
, NULL
},
326 {"HEAD", elem_iids
, NULL
},
327 {"TITLE", elem_iids
, NULL
},
328 {"BODY", body_iids
, &DIID_DispHTMLBody
},
329 {"A", anchor_iids
, NULL
},
330 {"INPUT", input_iids
, &DIID_DispHTMLInputElement
},
331 {"SELECT", select_iids
, &DIID_DispHTMLSelectElement
},
332 {"TEXTAREA", textarea_iids
, NULL
},
333 {"OPTION", option_iids
, &DIID_DispHTMLOptionElement
},
334 {"STYLE", elem_iids
, NULL
},
335 {"BLOCKQUOTE",elem_iids
, NULL
},
336 {"P", elem_iids
, NULL
},
337 {"BR", elem_iids
, NULL
},
338 {"TABLE", table_iids
, &DIID_DispHTMLTable
},
339 {"TBODY", elem_iids
, NULL
},
340 {"SCRIPT", script_iids
, NULL
},
341 {"TEST", elem_iids
, &DIID_DispHTMLUnknownElement
},
342 {"TEST", generic_iids
, &DIID_DispHTMLGenericElement
},
343 {"!", comment_iids
, &DIID_DispHTMLCommentElement
},
344 {"IMG", img_iids
, &DIID_DispHTMLImg
},
345 {"TR", tr_iids
, &DIID_DispHTMLTableRow
},
346 {"TD", td_iids
, NULL
},
347 {"IFRAME", iframe_iids
, &DIID_DispHTMLIFrame
}
350 static const char *dbgstr_w(LPCWSTR str
)
352 static char buf
[512];
355 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
359 static const char *dbgstr_guid(REFIID riid
)
363 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
364 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
365 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
366 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
371 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
374 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
375 return lstrcmpW(strw
, buf
);
378 static BSTR
a2bstr(const char *str
)
383 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
384 ret
= SysAllocStringLen(NULL
, len
);
385 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
390 static IHTMLDocument2
*create_document(void)
395 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
396 &IID_IHTMLDocument2
, (void**)&doc
);
397 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
402 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
403 static void _test_ifaces(unsigned line
, IUnknown
*iface
, REFIID
*iids
)
405 const IID
* const *piid
;
409 for(piid
= iids
; *piid
; piid
++) {
410 hres
= IDispatch_QueryInterface(iface
, *piid
, (void**)&unk
);
411 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get %s interface: %08x\n", dbgstr_guid(*piid
), hres
);
413 IUnknown_Release(unk
);
417 #define test_disp(u,id) _test_disp(__LINE__,u,id)
418 static void _test_disp(unsigned line
, IUnknown
*unk
, const IID
*diid
)
425 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
426 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IDispatch: %08x\n", hres
);
431 hres
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
432 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfoCount failed: %08x\n", hres
);
433 ok_(__FILE__
,line
) (ticnt
== 1, "ticnt=%u\n", ticnt
);
435 hres
= IDispatchEx_GetTypeInfo(dispex
, 0, 0, &typeinfo
);
436 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfo failed: %08x\n", hres
);
438 if(SUCCEEDED(hres
)) {
441 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &type_attr
);
442 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeAttr failed: %08x\n", hres
);
443 ok_(__FILE__
,line
) (IsEqualGUID(&type_attr
->guid
, diid
), "unexpected guid %s\n", dbgstr_guid(&type_attr
->guid
));
445 ITypeInfo_ReleaseTypeAttr(typeinfo
, type_attr
);
446 ITypeInfo_Release(typeinfo
);
449 IDispatchEx_Release(dispex
);
452 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
453 static IHTMLElement
*_get_elem_iface(unsigned line
, IUnknown
*unk
)
458 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
459 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLElement: %08x\n", hres
);
463 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
464 static IHTMLElement2
*_get_elem2_iface(unsigned line
, IUnknown
*unk
)
469 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement2
, (void**)&elem
);
470 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLElement2: %08x\n", hres
);
474 #define get_node_iface(u) _get_node_iface(__LINE__,u)
475 static IHTMLDOMNode
*_get_node_iface(unsigned line
, IUnknown
*unk
)
480 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
481 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLDOMNode: %08x\n", hres
);
485 #define get_img_iface(u) _get_img_iface(__LINE__,u)
486 static IHTMLImgElement
*_get_img_iface(unsigned line
, IUnknown
*unk
)
488 IHTMLImgElement
*img
;
491 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLImgElement
, (void**)&img
);
492 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLImgElement: %08x\n", hres
);
496 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
497 static void _test_node_name(unsigned line
, IUnknown
*unk
, const char *exname
)
499 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
503 hres
= IHTMLDOMNode_get_nodeName(node
, &name
);
504 IHTMLDOMNode_Release(node
);
505 ok_(__FILE__
, line
) (hres
== S_OK
, "get_nodeName failed: %08x\n", hres
);
506 ok_(__FILE__
, line
) (!strcmp_wa(name
, exname
), "got name: %s, expected %s\n", dbgstr_w(name
), exname
);
511 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
512 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
514 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
518 hres
= IHTMLElement_get_tagName(elem
, &tag
);
519 IHTMLElement_Release(elem
);
520 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
521 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", dbgstr_w(tag
), extag
);
526 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
527 static void _test_elem_type(unsigned line
, IUnknown
*unk
, elem_type_t type
)
529 _test_elem_tag(line
, unk
, elem_type_infos
[type
].tag
);
530 _test_ifaces(line
, unk
, elem_type_infos
[type
].iids
);
532 if(elem_type_infos
[type
].dispiid
)
533 _test_disp(line
, unk
, elem_type_infos
[type
].dispiid
);
536 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
537 static void _test_elem_attr(unsigned line
, IHTMLElement
*elem
, LPCWSTR name
, LPCWSTR exval
)
545 tmp
= SysAllocString(name
);
546 hres
= IHTMLElement_getAttribute(elem
, tmp
, 0, &value
);
548 ok_(__FILE__
,line
) (hres
== S_OK
, "getAttribute failed: %08x\n", hres
);
551 ok_(__FILE__
,line
) (V_VT(&value
) == VT_BSTR
, "vt=%d\n", V_VT(&value
));
552 ok_(__FILE__
,line
) (!lstrcmpW(exval
, V_BSTR(&value
)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value
)));
554 ok_(__FILE__
,line
) (V_VT(&value
) == VT_NULL
, "vt=%d\n", V_VT(&value
));
557 VariantClear(&value
);
560 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
561 static void _test_elem_offset(unsigned line
, IUnknown
*unk
)
563 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
567 hres
= IHTMLElement_get_offsetTop(elem
, &l
);
568 ok_(__FILE__
,line
) (hres
== S_OK
, "get_offsetTop failed: %08x\n", hres
);
570 hres
= IHTMLElement_get_offsetHeight(elem
, &l
);
571 ok_(__FILE__
,line
) (hres
== S_OK
, "get_offsetHeight failed: %08x\n", hres
);
573 hres
= IHTMLElement_get_offsetWidth(elem
, &l
);
574 ok_(__FILE__
,line
) (hres
== S_OK
, "get_offsetWidth failed: %08x\n", hres
);
576 IHTMLElement_Release(elem
);
579 static void test_doc_elem(IHTMLDocument2
*doc
)
582 IHTMLDocument3
*doc3
;
585 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
586 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres
);
588 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
589 IHTMLDocument3_Release(doc3
);
590 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
592 test_node_name((IUnknown
*)elem
, "HTML");
593 test_elem_tag((IUnknown
*)elem
, "HTML");
595 IHTMLElement_Release(elem
);
598 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
599 static IHTMLElement
*_get_doc_elem(unsigned line
, IHTMLDocument2
*doc
)
602 IHTMLDocument3
*doc3
;
605 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
606 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 interface: %08x\n", hres
);
607 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
608 ok_(__FILE__
,line
) (hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
609 IHTMLDocument3_Release(doc3
);
614 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
615 static void _test_option_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
620 hres
= IHTMLOptionElement_get_text(option
, &bstr
);
621 ok_(__FILE__
,line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
622 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, text
), "text=%s\n", dbgstr_w(bstr
));
626 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
627 static void _test_option_put_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
633 hres
= IHTMLOptionElement_put_text(option
, bstr
);
635 ok(hres
== S_OK
, "put_text failed: %08x\n", hres
);
637 _test_option_text(line
, option
, text
);
640 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
641 static void _test_option_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
646 hres
= IHTMLOptionElement_get_value(option
, &bstr
);
647 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
648 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, value
), "value=%s\n", dbgstr_w(bstr
));
652 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
653 static void _test_option_put_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
658 bstr
= a2bstr(value
);
659 hres
= IHTMLOptionElement_put_value(option
, bstr
);
661 ok(hres
== S_OK
, "put_value failed: %08x\n", hres
);
663 _test_option_value(line
, option
, value
);
666 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
667 static IHTMLOptionElement
*_create_option_elem(unsigned line
, IHTMLDocument2
*doc
,
668 const char *txt
, const char *val
)
670 IHTMLOptionElementFactory
*factory
;
671 IHTMLOptionElement
*option
;
672 IHTMLWindow2
*window
;
673 VARIANT text
, value
, empty
;
676 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
677 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
679 hres
= IHTMLWindow2_get_Option(window
, &factory
);
680 IHTMLWindow2_Release(window
);
681 ok_(__FILE__
,line
) (hres
== S_OK
, "get_Option failed: %08x\n", hres
);
683 V_VT(&text
) = VT_BSTR
;
684 V_BSTR(&text
) = a2bstr(txt
);
685 V_VT(&value
) = VT_BSTR
;
686 V_BSTR(&value
) = a2bstr(val
);
687 V_VT(&empty
) = VT_EMPTY
;
689 hres
= IHTMLOptionElementFactory_create(factory
, text
, value
, empty
, empty
, &option
);
690 ok_(__FILE__
,line
) (hres
== S_OK
, "create failed: %08x\n", hres
);
692 IHTMLOptionElementFactory_Release(factory
);
694 VariantClear(&value
);
696 _test_option_text(line
, option
, txt
);
697 _test_option_value(line
, option
, val
);
702 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
703 static void _test_select_length(unsigned line
, IHTMLSelectElement
*select
, long length
)
705 long len
= 0xdeadbeef;
708 hres
= IHTMLSelectElement_get_length(select
, &len
);
709 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
710 ok_(__FILE__
,line
) (len
== length
, "len=%ld, expected %ld\n", len
, length
);
713 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
714 static void _test_select_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
716 long idx
= 0xdeadbeef;
719 hres
= IHTMLSelectElement_get_selectedIndex(select
, &idx
);
720 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
721 ok_(__FILE__
,line
) (idx
== index
, "idx=%ld, expected %ld\n", idx
, index
);
724 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
725 static void _test_select_put_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
729 hres
= IHTMLSelectElement_put_selectedIndex(select
, index
);
730 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
731 _test_select_selidx(line
, select
, index
);
734 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
735 static void _test_select_value(unsigned line
, IHTMLSelectElement
*select
, const char *exval
)
740 hres
= IHTMLSelectElement_get_value(select
, &val
);
741 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
743 ok_(__FILE__
,line
) (!strcmp_wa(val
, exval
), "unexpected value %s\n", dbgstr_w(val
));
745 ok_(__FILE__
,line
) (val
== NULL
, "val=%s, expected NULL\n", dbgstr_w(val
));
748 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
749 static void _test_select_set_value(unsigned line
, IHTMLSelectElement
*select
, const char *val
)
755 hres
= IHTMLSelectElement_put_value(select
, bstr
);
757 ok_(__FILE__
,line
) (hres
== S_OK
, "put_value failed: %08x\n", hres
);
760 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
761 static void _test_select_type(unsigned line
, IHTMLSelectElement
*select
, const char *extype
)
766 hres
= IHTMLSelectElement_get_type(select
, &type
);
767 ok_(__FILE__
,line
) (hres
== S_OK
, "get_type failed: %08x\n", hres
);
768 ok_(__FILE__
,line
) (!strcmp_wa(type
, extype
), "type=%s, expected %s\n", dbgstr_w(type
), extype
);
771 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
772 static void _test_range_text(unsigned line
, IHTMLTxtRange
*range
, const char *extext
)
777 hres
= IHTMLTxtRange_get_text(range
, &text
);
778 ok_(__FILE__
, line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
781 ok_(__FILE__
, line
) (text
!= NULL
, "text == NULL\n");
782 ok_(__FILE__
, line
) (!strcmp_wa(text
, extext
), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text
), extext
);
784 ok_(__FILE__
, line
) (text
== NULL
, "text=\"%s\", expected NULL\n", dbgstr_w(text
));
791 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
792 static void _test_range_collapse(unsigned line
, IHTMLTxtRange
*range
, BOOL b
)
796 hres
= IHTMLTxtRange_collapse(range
, b
);
797 ok_(__FILE__
, line
) (hres
== S_OK
, "collapse failed: %08x\n", hres
);
798 _test_range_text(line
, range
, NULL
);
801 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
802 static void _test_range_expand(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
,
803 VARIANT_BOOL exb
, const char *extext
)
805 VARIANT_BOOL b
= 0xe0e0;
808 hres
= IHTMLTxtRange_expand(range
, unit
, &b
);
809 ok_(__FILE__
,line
) (hres
== S_OK
, "expand failed: %08x\n", hres
);
810 ok_(__FILE__
,line
) (b
== exb
, "b=%x, expected %x\n", b
, exb
);
811 _test_range_text(line
, range
, extext
);
814 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
815 static void _test_range_move(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
820 hres
= IHTMLTxtRange_move(range
, unit
, cnt
, &c
);
821 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
822 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
823 _test_range_text(line
, range
, NULL
);
826 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
827 static void _test_range_movestart(unsigned line
, IHTMLTxtRange
*range
,
828 LPWSTR unit
, long cnt
, long excnt
)
833 hres
= IHTMLTxtRange_moveStart(range
, unit
, cnt
, &c
);
834 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
835 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
838 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
839 static void _test_range_moveend(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
844 hres
= IHTMLTxtRange_moveEnd(range
, unit
, cnt
, &c
);
845 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
846 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
849 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
850 static void _test_range_put_text(unsigned line
, IHTMLTxtRange
*range
, const char *text
)
853 BSTR bstr
= a2bstr(text
);
855 hres
= IHTMLTxtRange_put_text(range
, bstr
);
856 ok_(__FILE__
,line
) (hres
== S_OK
, "put_text failed: %08x\n", hres
);
858 _test_range_text(line
, range
, NULL
);
861 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
862 static void _test_range_inrange(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
868 hres
= IHTMLTxtRange_inRange(range1
, range2
, &b
);
869 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
870 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
873 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
874 static void _test_range_isequal(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
880 hres
= IHTMLTxtRange_isEqual(range1
, range2
, &b
);
881 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
882 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
885 hres
= IHTMLTxtRange_isEqual(range2
, range1
, &b
);
886 ok_(__FILE__
,line
) (hres
== S_OK
, "(2->1) isEqual failed: %08x\n", hres
);
887 ok_(__FILE__
,line
) (b
== exb
, "(2->1) b=%x, expected %x\n", b
, exb
);
890 test_range_inrange(range1
, range2
, VARIANT_TRUE
);
891 test_range_inrange(range2
, range1
, VARIANT_TRUE
);
895 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
896 static void _test_range_parent(unsigned line
, IHTMLTxtRange
*range
, elem_type_t type
)
901 hres
= IHTMLTxtRange_parentElement(range
, &elem
);
902 ok_(__FILE__
,line
) (hres
== S_OK
, "parentElement failed: %08x\n", hres
);
904 _test_elem_type(line
, (IUnknown
*)elem
, type
);
906 IHTMLElement_Release(elem
);
909 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
910 static void _test_elem_collection(unsigned line
, IUnknown
*unk
,
911 const elem_type_t
*elem_types
, long exlen
)
913 IHTMLElementCollection
*col
;
920 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElementCollection
, (void**)&col
);
921 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
923 test_disp((IUnknown
*)col
, &DIID_DispHTMLElementCollection
);
925 hres
= IHTMLElementCollection_get_length(col
, &len
);
926 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
927 ok_(__FILE__
,line
) (len
== exlen
, "len=%ld, expected %ld\n", len
, exlen
);
932 V_VT(&index
) = VT_EMPTY
;
935 for(i
=0; i
<len
; i
++) {
937 disp
= (void*)0xdeadbeef;
938 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
939 ok_(__FILE__
,line
) (hres
== S_OK
, "item(%d) failed: %08x\n", i
, hres
);
940 ok_(__FILE__
,line
) (disp
!= NULL
, "item returned NULL\n");
941 if(FAILED(hres
) || !disp
)
944 _test_elem_type(line
, (IUnknown
*)disp
, elem_types
[i
]);
945 IDispatch_Release(disp
);
949 disp
= (void*)0xdeadbeef;
950 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
951 ok_(__FILE__
,line
) (hres
== S_OK
, "item failed: %08x\n", hres
);
952 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
955 disp
= (void*)0xdeadbeef;
956 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
957 ok_(__FILE__
,line
) (hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
958 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
960 IHTMLElementCollection_Release(col
);
963 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
964 static void _test_elem_getelembytag(unsigned line
, IUnknown
*unk
, elem_type_t type
, long exlen
)
966 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
967 IHTMLElementCollection
*col
= NULL
;
968 elem_type_t
*types
= NULL
;
973 tmp
= a2bstr(elem_type_infos
[type
].tag
);
974 hres
= IHTMLElement2_getElementsByTagName(elem
, tmp
, &col
);
976 IHTMLElement2_Release(elem
);
977 ok_(__FILE__
,line
) (hres
== S_OK
, "getElementByTagName failed: %08x\n", hres
);
978 ok_(__FILE__
,line
) (col
!= NULL
, "col == NULL\n");
981 types
= HeapAlloc(GetProcessHeap(), 0, exlen
*sizeof(elem_type_t
));
982 for(i
=0; i
<exlen
; i
++)
986 _test_elem_collection(line
, (IUnknown
*)col
, types
, exlen
);
988 HeapFree(GetProcessHeap(), 0, types
);
991 #define get_first_child(n) _get_first_child(__LINE__,n)
992 static IHTMLDOMNode
*_get_first_child(unsigned line
, IUnknown
*unk
)
994 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
995 IHTMLDOMNode
*child
= NULL
;
998 hres
= IHTMLDOMNode_get_firstChild(node
, &child
);
999 IHTMLDOMNode_Release(node
);
1000 ok_(__FILE__
,line
) (hres
== S_OK
, "get_firstChild failed: %08x\n", hres
);
1005 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1006 static void _test_node_has_child(unsigned line
, IUnknown
*unk
, VARIANT_BOOL exb
)
1008 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1009 VARIANT_BOOL b
= 0xdead;
1012 hres
= IHTMLDOMNode_hasChildNodes(node
, &b
);
1013 ok_(__FILE__
,line
) (hres
== S_OK
, "hasChildNodes failed: %08x\n", hres
);
1014 ok_(__FILE__
,line
) (b
== exb
, "hasChildNodes=%x, expected %x\n", b
, exb
);
1016 IHTMLDOMNode_Release(node
);
1019 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1020 static IHTMLDOMNode
*_test_node_get_parent(unsigned line
, IUnknown
*unk
)
1022 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1023 IHTMLDOMNode
*parent
;
1026 hres
= IHTMLDOMNode_get_parentNode(node
, &parent
);
1027 IHTMLDOMNode_Release(node
);
1028 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentNode failed: %08x\n", hres
);
1033 #define get_node_type(n) _get_node_type(__LINE__,n)
1034 static long _get_node_type(unsigned line
, IUnknown
*unk
)
1036 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1040 hres
= IHTMLDOMNode_get_nodeType(node
, &type
);
1041 ok(hres
== S_OK
, "get_nodeType failed: %08x\n", hres
);
1043 IHTMLDOMNode_Release(node
);
1048 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1049 static IHTMLElement
*_test_elem_get_parent(unsigned line
, IUnknown
*unk
)
1051 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1052 IHTMLElement
*parent
;
1055 hres
= IHTMLElement_get_parentElement(elem
, &parent
);
1056 IHTMLElement_Release(elem
);
1057 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
1062 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1063 static long _elem_get_scroll_height(unsigned line
, IUnknown
*unk
)
1065 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1066 IHTMLTextContainer
*txtcont
;
1067 long l
= -1, l2
= -1;
1070 hres
= IHTMLElement2_get_scrollHeight(elem
, &l
);
1071 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollHeight failed: %08x\n", hres
);
1072 IHTMLElement2_Release(elem
);
1074 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1075 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1077 hres
= IHTMLTextContainer_get_scrollHeight(txtcont
, &l2
);
1078 IHTMLTextContainer_Release(txtcont
);
1079 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2
);
1080 ok_(__FILE__
,line
) (l
== l2
, "unexpected height %ld, expected %ld\n", l2
, l
);
1085 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1086 static long _elem_get_scroll_width(unsigned line
, IUnknown
*unk
)
1088 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1089 IHTMLTextContainer
*txtcont
;
1090 long l
= -1, l2
= -1;
1093 hres
= IHTMLElement2_get_scrollWidth(elem
, &l
);
1094 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollWidth failed: %08x\n", hres
);
1095 IHTMLElement2_Release(elem
);
1097 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1098 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1100 hres
= IHTMLTextContainer_get_scrollWidth(txtcont
, &l2
);
1101 IHTMLTextContainer_Release(txtcont
);
1102 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2
);
1103 ok_(__FILE__
,line
) (l
== l2
, "unexpected width %ld, expected %ld\n", l2
, l
);
1108 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1109 static long _elem_get_scroll_top(unsigned line
, IUnknown
*unk
)
1111 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1112 IHTMLTextContainer
*txtcont
;
1113 long l
= -1, l2
= -1;
1116 hres
= IHTMLElement2_get_scrollTop(elem
, &l
);
1117 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollTop failed: %08x\n", hres
);
1118 IHTMLElement2_Release(elem
);
1120 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1121 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1123 hres
= IHTMLTextContainer_get_scrollTop(txtcont
, &l2
);
1124 IHTMLTextContainer_Release(txtcont
);
1125 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2
);
1126 ok_(__FILE__
,line
) (l
== l2
, "unexpected top %ld, expected %ld\n", l2
, l
);
1131 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1132 static void _elem_get_scroll_left(unsigned line
, IUnknown
*unk
)
1134 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1135 IHTMLTextContainer
*txtcont
;
1136 long l
= -1, l2
= -1;
1139 hres
= IHTMLElement2_get_scrollLeft(elem
, NULL
);
1140 ok(hres
== E_INVALIDARG
, "expect E_INVALIDARG got 0x%08x\n", hres
);
1142 hres
= IHTMLElement2_get_scrollLeft(elem
, &l
);
1143 ok(hres
== S_OK
, "get_scrollTop failed: %08x\n", hres
);
1144 IHTMLElement2_Release(elem
);
1146 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1147 ok(hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1149 hres
= IHTMLTextContainer_get_scrollLeft(txtcont
, &l2
);
1150 IHTMLTextContainer_Release(txtcont
);
1151 ok(hres
== S_OK
, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2
);
1152 ok(l
== l2
, "unexpected left %ld, expected %ld\n", l2
, l
);
1155 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1156 static void _test_img_set_src(unsigned line
, IUnknown
*unk
, const char *src
)
1158 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1163 hres
= IHTMLImgElement_put_src(img
, tmp
);
1164 IHTMLImgElement_Release(img
);
1166 ok_(__FILE__
,line
) (hres
== S_OK
, "put_src failed: %08x\n", hres
);
1169 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1170 static void _test_img_alt(unsigned line
, IUnknown
*unk
, const char *exalt
)
1172 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1176 hres
= IHTMLImgElement_get_alt(img
, &alt
);
1177 ok_(__FILE__
,line
) (hres
== S_OK
, "get_alt failed: %08x\n", hres
);
1179 ok_(__FILE__
,line
) (!strcmp_wa(alt
, exalt
), "inexopected alt %s\n", dbgstr_w(alt
));
1181 ok_(__FILE__
,line
) (!alt
, "alt != NULL\n");
1185 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1186 static void _test_img_set_alt(unsigned line
, IUnknown
*unk
, const char *alt
)
1188 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1193 hres
= IHTMLImgElement_put_alt(img
, tmp
);
1194 ok_(__FILE__
,line
) (hres
== S_OK
, "get_alt failed: %08x\n", hres
);
1197 _test_img_alt(line
, unk
, alt
);
1200 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1201 static void _test_input_get_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL exb
)
1203 VARIANT_BOOL disabled
= 100;
1206 hres
= IHTMLInputElement_get_disabled(input
, &disabled
);
1207 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
1208 ok_(__FILE__
,line
) (disabled
== exb
, "disabled=%x, expected %x\n", disabled
, exb
);
1211 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1212 static void _test_input_set_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL b
)
1216 hres
= IHTMLInputElement_put_disabled(input
, b
);
1217 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
1219 _test_input_get_disabled(line
, input
, b
);
1222 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1223 static void _test_input_value(unsigned line
, IUnknown
*unk
, const char *exval
)
1225 IHTMLInputElement
*input
;
1229 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLInputElement
, (void**)&input
);
1230 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1234 hres
= IHTMLInputElement_get_value(input
, &bstr
);
1235 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
1237 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, exval
), "value=%s\n", dbgstr_w(bstr
));
1239 ok_(__FILE__
,line
) (!exval
, "exval != NULL\n");
1240 SysFreeString(bstr
);
1241 IHTMLInputElement_Release(input
);
1244 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1245 static void _test_input_put_value(unsigned line
, IUnknown
*unk
, const char *val
)
1247 IHTMLInputElement
*input
;
1251 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLInputElement
, (void**)&input
);
1252 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1257 hres
= IHTMLInputElement_get_value(input
, &bstr
);
1258 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
1259 SysFreeString(bstr
);
1260 IHTMLInputElement_Release(input
);
1263 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1264 static IHTMLDOMChildrenCollection
*_get_child_nodes(unsigned line
, IUnknown
*unk
)
1266 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1267 IHTMLDOMChildrenCollection
*col
= NULL
;
1271 hres
= IHTMLDOMNode_get_childNodes(node
, &disp
);
1272 IHTMLDOMNode_Release(node
);
1273 ok_(__FILE__
,line
) (hres
== S_OK
, "get_childNodes failed: %08x\n", hres
);
1277 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMChildrenCollection
, (void**)&col
);
1278 IDispatch_Release(disp
);
1279 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres
);
1284 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1285 static void _test_elem_class(unsigned line
, IUnknown
*unk
, const char *exclass
)
1287 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1288 BSTR
class = (void*)0xdeadbeef;
1291 hres
= IHTMLElement_get_className(elem
, &class);
1292 IHTMLElement_Release(elem
);
1293 ok_(__FILE__
,line
) (hres
== S_OK
, "get_className failed: %08x\n", hres
);
1295 ok_(__FILE__
,line
) (!strcmp_wa(class, exclass
), "unexpected className %s\n", dbgstr_w(class));
1297 ok_(__FILE__
,line
) (!class, "class != NULL\n");
1298 SysFreeString(class);
1301 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1302 static void _test_elem_tabindex(unsigned line
, IUnknown
*unk
, short exindex
)
1304 IHTMLElement2
*elem2
= _get_elem2_iface(line
, unk
);
1308 hres
= IHTMLElement2_get_tabIndex(elem2
, &index
);
1309 IHTMLElement2_Release(elem2
);
1310 ok_(__FILE__
,line
) (hres
== S_OK
, "get_tabIndex failed: %08x\n", hres
);
1311 ok_(__FILE__
,line
) (index
== exindex
, "unexpected index %d\n", index
);
1314 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1315 static void _test_elem_set_tabindex(unsigned line
, IUnknown
*unk
, short index
)
1317 IHTMLElement2
*elem2
= _get_elem2_iface(line
, unk
);
1320 hres
= IHTMLElement2_put_tabIndex(elem2
, index
);
1321 IHTMLElement2_Release(elem2
);
1322 ok_(__FILE__
,line
) (hres
== S_OK
, "get_tabIndex failed: %08x\n", hres
);
1324 _test_elem_tabindex(line
, unk
, index
);
1327 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1328 static void _test_elem_set_class(unsigned line
, IUnknown
*unk
, const char *class)
1330 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1334 tmp
= class ? a2bstr(class) : NULL
;
1335 hres
= IHTMLElement_put_className(elem
, tmp
);
1336 IHTMLElement_Release(elem
);
1337 ok_(__FILE__
,line
) (hres
== S_OK
, "put_className failed: %08x\n", hres
);
1340 _test_elem_class(line
, unk
, class);
1343 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1344 static IHTMLDOMNode
*_get_child_item(unsigned line
, IHTMLDOMChildrenCollection
*col
, long idx
)
1346 IHTMLDOMNode
*node
= NULL
;
1350 hres
= IHTMLDOMChildrenCollection_item(col
, idx
, &disp
);
1351 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1353 node
= _get_node_iface(line
, (IUnknown
*)disp
);
1354 IDispatch_Release(disp
);
1359 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1360 static void _test_elem_id(unsigned line
, IUnknown
*unk
, const char *exid
)
1362 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1363 BSTR id
= (void*)0xdeadbeef;
1366 hres
= IHTMLElement_get_id(elem
, &id
);
1367 IHTMLElement_Release(elem
);
1368 ok_(__FILE__
,line
) (hres
== S_OK
, "get_id failed: %08x\n", hres
);
1371 ok_(__FILE__
,line
) (!strcmp_wa(id
, exid
), "unexpected id %s\n", dbgstr_w(id
));
1373 ok_(__FILE__
,line
) (!id
, "id=%s\n", dbgstr_w(id
));
1378 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1379 static void _test_elem_put_id(unsigned line
, IUnknown
*unk
, const char *new_id
)
1381 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1382 BSTR tmp
= a2bstr(new_id
);
1385 hres
= IHTMLElement_put_id(elem
, tmp
);
1386 IHTMLElement_Release(elem
);
1388 ok_(__FILE__
,line
) (hres
== S_OK
, "put_id failed: %08x\n", hres
);
1390 _test_elem_id(line
, unk
, new_id
);
1393 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1394 static void _test_elem_title(unsigned line
, IUnknown
*unk
, const char *extitle
)
1396 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1400 hres
= IHTMLElement_get_title(elem
, &title
);
1401 IHTMLElement_Release(elem
);
1402 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1404 ok_(__FILE__
,line
) (!strcmp_wa(title
, extitle
), "unexpected title %s\n", dbgstr_w(title
));
1406 ok_(__FILE__
,line
) (!title
, "title=%s, expected NULL\n", dbgstr_w(title
));
1408 SysFreeString(title
);
1411 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1412 static void _test_elem_set_title(unsigned line
, IUnknown
*unk
, const char *title
)
1414 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1418 tmp
= a2bstr(title
);
1419 hres
= IHTMLElement_put_title(elem
, tmp
);
1420 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1422 IHTMLElement_Release(elem
);
1426 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1427 static void _test_node_get_value_str(unsigned line
, IUnknown
*unk
, const char *exval
)
1429 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1433 hres
= IHTMLDOMNode_get_nodeValue(node
, &var
);
1434 IHTMLDOMNode_Release(node
);
1435 ok_(__FILE__
,line
) (hres
== S_OK
, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres
);
1438 ok_(__FILE__
,line
) (V_VT(&var
) == VT_BSTR
, "vt=%d\n", V_VT(&var
));
1439 ok_(__FILE__
,line
) (!strcmp_wa(V_BSTR(&var
), exval
), "unexpected value %s\n", dbgstr_w(V_BSTR(&var
)));
1441 ok_(__FILE__
,line
) (V_VT(&var
) == VT_NULL
, "vt=%d, expected VT_NULL\n", V_VT(&var
));
1447 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1448 static void _test_node_put_value_str(unsigned line
, IUnknown
*unk
, const char *val
)
1450 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1454 V_VT(&var
) = VT_BSTR
;
1455 V_BSTR(&var
) = a2bstr(val
);
1457 hres
= IHTMLDOMNode_put_nodeValue(node
, var
);
1458 ok_(__FILE__
,line
) (hres
== S_OK
, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres
);
1459 IHTMLDOMNode_Release(node
);
1463 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1464 static void _test_elem_client_size(unsigned line
, IUnknown
*unk
)
1466 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1470 hres
= IHTMLElement2_get_clientWidth(elem
, &l
);
1471 ok_(__FILE__
,line
) (hres
== S_OK
, "get_clientWidth failed: %08x\n", hres
);
1472 hres
= IHTMLElement2_get_clientHeight(elem
, &l
);
1473 ok_(__FILE__
,line
) (hres
== S_OK
, "get_clientHeight failed: %08x\n", hres
);
1475 IHTMLElement2_Release(elem
);
1478 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1479 static IHTMLElement
*_test_create_elem(unsigned line
, IHTMLDocument2
*doc
, const char *tag
)
1481 IHTMLElement
*elem
= NULL
;
1486 hres
= IHTMLDocument2_createElement(doc
, tmp
, &elem
);
1487 ok_(__FILE__
,line
) (hres
== S_OK
, "createElement failed: %08x\n", hres
);
1488 ok_(__FILE__
,line
) (elem
!= NULL
, "elem == NULL\n");
1493 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1494 static IHTMLDOMNode
*_test_create_text(unsigned line
, IHTMLDocument2
*doc
, const char *text
)
1496 IHTMLDocument3
*doc3
;
1497 IHTMLDOMNode
*node
= NULL
;
1501 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
1502 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3: %08x\n", hres
);
1505 hres
= IHTMLDocument3_createTextNode(doc3
, tmp
, &node
);
1506 IHTMLDocument3_Release(doc3
);
1507 ok_(__FILE__
,line
) (hres
== S_OK
, "createElement failed: %08x\n", hres
);
1508 ok_(__FILE__
,line
) (node
!= NULL
, "node == NULL\n");
1513 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1514 static IHTMLDOMNode
*_test_node_append_child(unsigned line
, IUnknown
*node_unk
, IUnknown
*child_unk
)
1516 IHTMLDOMNode
*node
= _get_node_iface(line
, node_unk
);
1517 IHTMLDOMNode
*child
= _get_node_iface(line
, child_unk
);
1518 IHTMLDOMNode
*new_child
= NULL
;
1521 hres
= IHTMLDOMNode_appendChild(node
, child
, &new_child
);
1522 ok_(__FILE__
,line
) (hres
== S_OK
, "appendChild failed: %08x\n", hres
);
1523 ok_(__FILE__
,line
) (new_child
!= NULL
, "new_child == NULL\n");
1524 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1526 IHTMLDOMNode_Release(node
);
1527 IHTMLDOMNode_Release(child
);
1532 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1533 static void _test_node_remove_child(unsigned line
, IUnknown
*unk
, IHTMLDOMNode
*child
)
1535 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1536 IHTMLDOMNode
*new_node
= NULL
;
1539 hres
= IHTMLDOMNode_removeChild(node
, child
, &new_node
);
1540 ok_(__FILE__
,line
) (hres
== S_OK
, "appendChild failed: %08x\n", hres
);
1541 ok_(__FILE__
,line
) (new_node
!= NULL
, "new_node == NULL\n");
1542 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1544 IHTMLDOMNode_Release(node
);
1545 IHTMLDOMNode_Release(new_node
);
1548 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1549 static void _test_doc_title(unsigned line
, IHTMLDocument2
*doc
, const char *extitle
)
1554 hres
= IHTMLDocument2_get_title(doc
, &title
);
1555 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1556 ok_(__FILE__
,line
) (!strcmp_wa(title
, extitle
), "unexpected title %s\n", dbgstr_w(title
));
1557 SysFreeString(title
);
1560 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1561 static void _test_doc_set_title(unsigned line
, IHTMLDocument2
*doc
, const char *title
)
1566 tmp
= a2bstr(title
);
1567 hres
= IHTMLDocument2_put_title(doc
, tmp
);
1568 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1572 static void test_elem_col_item(IHTMLElementCollection
*col
, LPCWSTR n
,
1573 const elem_type_t
*elem_types
, long len
)
1576 VARIANT name
, index
;
1580 V_VT(&index
) = VT_EMPTY
;
1581 V_VT(&name
) = VT_BSTR
;
1582 V_BSTR(&name
) = SysAllocString(n
);
1584 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1585 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1587 test_elem_collection((IUnknown
*)disp
, elem_types
, len
);
1588 IDispatch_Release(disp
);
1589 ok(hres
== S_OK
, "Could not get IHTMLElementCollection interface: %08x\n", hres
);
1593 V_VT(&index
) = VT_I4
;
1595 for(i
=0; i
<len
; i
++) {
1597 disp
= (void*)0xdeadbeef;
1598 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1599 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1600 ok(disp
!= NULL
, "disp == NULL\n");
1601 if(FAILED(hres
) || !disp
)
1604 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
1606 IDispatch_Release(disp
);
1610 disp
= (void*)0xdeadbeef;
1611 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1612 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1613 ok(disp
== NULL
, "disp != NULL\n");
1616 disp
= (void*)0xdeadbeef;
1617 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1618 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1619 ok(disp
== NULL
, "disp != NULL\n");
1622 SysFreeString(V_BSTR(&name
));
1625 static IHTMLElement
*get_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
, BOOL expect_success
)
1627 IHTMLElementCollection
*col
;
1629 IDispatch
*disp
= (void*)0xdeadbeef;
1630 VARIANT name
, index
;
1633 hres
= IHTMLDocument2_get_all(doc
, &col
);
1634 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1635 ok(col
!= NULL
, "col == NULL\n");
1636 if(FAILED(hres
) || !col
)
1639 V_VT(&index
) = VT_EMPTY
;
1640 V_VT(&name
) = VT_BSTR
;
1641 V_BSTR(&name
) = SysAllocString(id
);
1643 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1644 IHTMLElementCollection_Release(col
);
1645 SysFreeString(V_BSTR(&name
));
1646 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1647 if(!expect_success
) {
1648 ok(disp
== NULL
, "disp != NULL\n");
1652 ok(disp
!= NULL
, "disp == NULL\n");
1656 elem
= get_elem_iface((IUnknown
*)disp
);
1657 IDispatch_Release(disp
);
1662 static IHTMLElement
*get_doc_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
)
1664 IHTMLDocument3
*doc3
;
1669 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
1670 ok(hres
== S_OK
, "Could not get IHTMLDocument3 iface: %08x\n", hres
);
1672 tmp
= SysAllocString(id
);
1673 hres
= IHTMLDocument3_getElementById(doc3
, tmp
, &elem
);
1675 ok(hres
== S_OK
, "getElementById(%s) failed: %08x\n", dbgstr_w(id
), hres
);
1677 IHTMLDocument3_Release(doc3
);
1682 static void test_select_elem(IHTMLSelectElement
*select
)
1684 test_select_type(select
, "select-one");
1685 test_select_length(select
, 2);
1686 test_select_selidx(select
, 0);
1687 test_select_put_selidx(select
, 1);
1689 test_select_set_value(select
, "val1");
1690 test_select_value(select
, "val1");
1693 static void test_create_option_elem(IHTMLDocument2
*doc
)
1695 IHTMLOptionElement
*option
;
1697 option
= create_option_elem(doc
, "test text", "test value");
1699 test_option_put_text(option
, "new text");
1700 test_option_put_value(option
, "new value");
1702 IHTMLOptionElement_Release(option
);
1705 static IHTMLTxtRange
*test_create_body_range(IHTMLDocument2
*doc
)
1707 IHTMLBodyElement
*body
;
1708 IHTMLTxtRange
*range
;
1712 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1713 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1715 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
1716 IHTMLElement_Release(elem
);
1718 hres
= IHTMLBodyElement_createTextRange(body
, &range
);
1719 IHTMLBodyElement_Release(body
);
1720 ok(hres
== S_OK
, "createTextRange failed: %08x\n", hres
);
1725 static void test_txtrange(IHTMLDocument2
*doc
)
1727 IHTMLTxtRange
*body_range
, *range
, *range2
;
1728 IHTMLSelectionObject
*selection
;
1729 IDispatch
*disp_range
;
1732 body_range
= test_create_body_range(doc
);
1734 test_range_text(body_range
, "test abc 123\r\nit's text");
1736 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1737 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1739 hres
= IHTMLTxtRange_duplicate(body_range
, &range2
);
1740 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1741 test_range_isequal(range
, range2
, VARIANT_TRUE
);
1743 test_range_text(range
, "test abc 123\r\nit's text");
1744 test_range_text(body_range
, "test abc 123\r\nit's text");
1746 test_range_collapse(range
, TRUE
);
1747 test_range_isequal(range
, range2
, VARIANT_FALSE
);
1748 test_range_inrange(range
, range2
, VARIANT_FALSE
);
1749 test_range_inrange(range2
, range
, VARIANT_TRUE
);
1750 IHTMLTxtRange_Release(range2
);
1752 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1753 test_range_expand(range
, wordW
, VARIANT_FALSE
, "test ");
1754 test_range_move(range
, characterW
, 2, 2);
1755 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1757 test_range_collapse(range
, FALSE
);
1758 test_range_expand(range
, wordW
, VARIANT_TRUE
, "abc ");
1760 test_range_collapse(range
, FALSE
);
1761 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1762 test_range_expand(range
, wordW
, VARIANT_FALSE
, "123");
1763 test_range_move(range
, characterW
, 2, 2);
1764 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1765 test_range_moveend(range
, characterW
, -5, -5);
1766 test_range_text(range
, NULL
);
1767 test_range_moveend(range
, characterW
, 3, 3);
1768 test_range_text(range
, "c 1");
1769 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "test abc 123\r\nit's text");
1770 test_range_collapse(range
, TRUE
);
1771 test_range_move(range
, characterW
, 4, 4);
1772 test_range_moveend(range
, characterW
, 1, 1);
1773 test_range_text(range
, " ");
1774 test_range_move(range
, wordW
, 1, 1);
1775 test_range_moveend(range
, characterW
, 2, 2);
1776 test_range_text(range
, "ab");
1778 IHTMLTxtRange_Release(range
);
1780 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1781 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1783 test_range_text(range
, "test abc 123\r\nit's text");
1784 test_range_move(range
, characterW
, 3, 3);
1785 test_range_moveend(range
, characterW
, 1, 1);
1786 test_range_text(range
, "t");
1787 test_range_moveend(range
, characterW
, 3, 3);
1788 test_range_text(range
, "t ab");
1789 test_range_moveend(range
, characterW
, -2, -2);
1790 test_range_text(range
, "t ");
1791 test_range_move(range
, characterW
, 6, 6);
1792 test_range_moveend(range
, characterW
, 3, 3);
1793 test_range_text(range
, "123");
1794 test_range_moveend(range
, characterW
, 2, 2);
1795 test_range_text(range
, "123\r\ni");
1797 IHTMLTxtRange_Release(range
);
1799 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1800 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1802 test_range_move(range
, wordW
, 1, 1);
1803 test_range_moveend(range
, characterW
, 2, 2);
1804 test_range_text(range
, "ab");
1806 test_range_move(range
, characterW
, -2, -2);
1807 test_range_moveend(range
, characterW
, 2, 2);
1808 test_range_text(range
, "t ");
1810 test_range_move(range
, wordW
, 3, 3);
1811 test_range_move(range
, wordW
, -2, -2);
1812 test_range_moveend(range
, characterW
, 2, 2);
1813 test_range_text(range
, "ab");
1815 test_range_move(range
, characterW
, -6, -5);
1816 test_range_moveend(range
, characterW
, -1, 0);
1817 test_range_moveend(range
, characterW
, -6, 0);
1818 test_range_move(range
, characterW
, 2, 2);
1819 test_range_moveend(range
, characterW
, 2, 2);
1820 test_range_text(range
, "st");
1821 test_range_moveend(range
, characterW
, -6, -4);
1822 test_range_moveend(range
, characterW
, 2, 2);
1824 IHTMLTxtRange_Release(range
);
1826 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1827 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1829 test_range_move(range
, wordW
, 2, 2);
1830 test_range_moveend(range
, characterW
, 2, 2);
1831 test_range_text(range
, "12");
1833 test_range_move(range
, characterW
, 15, 14);
1834 test_range_move(range
, characterW
, -2, -2);
1835 test_range_moveend(range
, characterW
, 3, 2);
1836 test_range_text(range
, "t");
1837 test_range_moveend(range
, characterW
, -1, -1);
1838 test_range_text(range
, "t");
1839 test_range_expand(range
, wordW
, VARIANT_TRUE
, "text");
1840 test_range_move(range
, characterW
, -2, -2);
1841 test_range_moveend(range
, characterW
, 2, 2);
1842 test_range_text(range
, "s ");
1843 test_range_move(range
, characterW
, 100, 7);
1844 test_range_move(range
, wordW
, 1, 0);
1845 test_range_move(range
, characterW
, -2, -2);
1846 test_range_moveend(range
, characterW
, 3, 2);
1847 test_range_text(range
, "t");
1849 IHTMLTxtRange_Release(range
);
1851 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1852 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1854 test_range_collapse(range
, TRUE
);
1855 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1856 test_range_put_text(range
, "word");
1857 test_range_text(body_range
, "wordabc 123\r\nit's text");
1858 test_range_text(range
, NULL
);
1859 test_range_moveend(range
, characterW
, 3, 3);
1860 test_range_text(range
, "abc");
1861 test_range_movestart(range
, characterW
, -2, -2);
1862 test_range_text(range
, "rdabc");
1863 test_range_movestart(range
, characterW
, 3, 3);
1864 test_range_text(range
, "bc");
1865 test_range_movestart(range
, characterW
, 4, 4);
1866 test_range_text(range
, NULL
);
1867 test_range_movestart(range
, characterW
, -3, -3);
1868 test_range_text(range
, "c 1");
1869 test_range_movestart(range
, characterW
, -7, -6);
1870 test_range_text(range
, "wordabc 1");
1871 test_range_movestart(range
, characterW
, 100, 22);
1872 test_range_text(range
, NULL
);
1874 IHTMLTxtRange_Release(range
);
1875 IHTMLTxtRange_Release(body_range
);
1877 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1878 ok(hres
== S_OK
, "IHTMLDocument2_get_selection failed: %08x\n", hres
);
1880 hres
= IHTMLSelectionObject_createRange(selection
, &disp_range
);
1881 ok(hres
== S_OK
, "IHTMLSelectionObject_createRange failed: %08x\n", hres
);
1882 IHTMLSelectionObject_Release(selection
);
1884 hres
= IDispatch_QueryInterface(disp_range
, &IID_IHTMLTxtRange
, (void **)&range
);
1885 ok(hres
== S_OK
, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres
);
1886 IDispatch_Release(disp_range
);
1888 test_range_text(range
, NULL
);
1889 test_range_moveend(range
, characterW
, 3, 3);
1890 test_range_text(range
, "wor");
1891 test_range_parent(range
, ET_BODY
);
1892 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1893 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1894 test_range_move(range
, characterW
, 3, 3);
1895 test_range_expand(range
, wordW
, VARIANT_TRUE
, "wordabc ");
1896 test_range_moveend(range
, characterW
, -4, -4);
1897 test_range_put_text(range
, "abc def ");
1898 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "abc def abc 123\r\nit's text");
1899 test_range_move(range
, wordW
, 1, 1);
1900 test_range_movestart(range
, characterW
, -1, -1);
1901 test_range_text(range
, " ");
1902 test_range_move(range
, wordW
, 1, 1);
1903 test_range_moveend(range
, characterW
, 3, 3);
1904 test_range_text(range
, "def");
1905 test_range_put_text(range
, "xyz");
1906 test_range_moveend(range
, characterW
, 1, 1);
1907 test_range_move(range
, wordW
, 1, 1);
1908 test_range_moveend(range
, characterW
, 2, 2);
1909 test_range_text(range
, "ab");
1911 IHTMLTxtRange_Release(range
);
1914 static void test_txtrange2(IHTMLDocument2
*doc
)
1916 IHTMLTxtRange
*range
;
1918 range
= test_create_body_range(doc
);
1920 test_range_text(range
, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1921 test_range_move(range
, characterW
, 5, 5);
1922 test_range_moveend(range
, characterW
, 1, 1);
1923 test_range_text(range
, "2");
1924 test_range_move(range
, characterW
, -3, -3);
1925 test_range_moveend(range
, characterW
, 3, 3);
1926 test_range_text(range
, "c\r\n\r\n1");
1927 test_range_collapse(range
, VARIANT_FALSE
);
1928 test_range_moveend(range
, characterW
, 4, 4);
1929 test_range_text(range
, "23");
1930 test_range_moveend(range
, characterW
, 1, 1);
1931 test_range_text(range
, "23\r\n\r\n\r\nd");
1932 test_range_moveend(range
, characterW
, -1, -1);
1933 test_range_text(range
, "23");
1934 test_range_moveend(range
, characterW
, -1, -1);
1935 test_range_text(range
, "23");
1936 test_range_moveend(range
, characterW
, -2, -2);
1937 test_range_text(range
, "2");
1939 IHTMLTxtRange_Release(range
);
1942 static void test_compatmode(IHTMLDocument2
*doc
)
1944 IHTMLDocument5
*doc5
;
1948 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
1949 ok(hres
== S_OK
, "Could not get IHTMLDocument5 interface: %08x\n", hres
);
1953 hres
= IHTMLDocument5_get_compatMode(doc5
, &mode
);
1954 IHTMLDocument5_Release(doc5
);
1955 ok(hres
== S_OK
, "get_compatMode failed: %08x\n", hres
);
1956 ok(!strcmp_wa(mode
, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode
));
1957 SysFreeString(mode
);
1960 static void test_location(IHTMLDocument2
*doc
)
1962 IHTMLLocation
*location
, *location2
;
1966 hres
= IHTMLDocument2_get_location(doc
, &location
);
1967 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1969 hres
= IHTMLDocument2_get_location(doc
, &location2
);
1970 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1972 ok(location
== location2
, "location != location2\n");
1974 test_ifaces((IUnknown
*)location
, location_iids
);
1976 IHTMLLocation_Release(location2
);
1977 ref
= IHTMLLocation_Release(location
);
1978 ok(!ref
, "location chould be destroyed here\n");
1981 static void test_navigator(IHTMLDocument2
*doc
)
1983 IHTMLWindow2
*window
;
1984 IOmNavigator
*navigator
, *navigator2
;
1989 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1990 ok(hres
== S_OK
, "parentWidnow failed: %08x\n", hres
);
1992 hres
= IHTMLWindow2_get_navigator(window
, &navigator
);
1993 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1994 ok(navigator
!= NULL
, "navigator == NULL\n");
1995 test_disp((IUnknown
*)navigator
, &IID_IOmNavigator
);
1997 hres
= IHTMLWindow2_get_navigator(window
, &navigator2
);
1998 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1999 ok(navigator
!= navigator2
, "navigator2 != navihgator\n");
2001 IHTMLWindow2_Release(window
);
2002 IOmNavigator_Release(navigator2
);
2004 hres
= IOmNavigator_get_appCodeName(navigator
, &bstr
);
2005 ok(hres
== S_OK
, "get_appCodeName failed: %08x\n", hres
);
2006 ok(!strcmp_wa(bstr
, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr
));
2007 SysFreeString(bstr
);
2010 hres
= IOmNavigator_get_platform(navigator
, &bstr
);
2011 ok(hres
== S_OK
, "get_appMinorVersion failed: %08x\n", hres
);
2012 ok(!strcmp_wa(bstr
, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr
));
2013 SysFreeString(bstr
);
2015 ref
= IOmNavigator_Release(navigator
);
2016 ok(!ref
, "navigator should be destroyed here\n");
2019 static void test_current_style(IHTMLCurrentStyle
*current_style
)
2024 test_disp((IUnknown
*)current_style
, &DIID_DispHTMLCurrentStyle
);
2025 test_ifaces((IUnknown
*)current_style
, cstyle_iids
);
2027 hres
= IHTMLCurrentStyle_get_display(current_style
, &str
);
2028 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
2029 ok(!strcmp_wa(str
, "block"), "get_display returned %s\n", dbgstr_w(str
));
2033 static void test_style2(IHTMLStyle2
*style2
)
2038 str
= (void*)0xdeadbeef;
2039 hres
= IHTMLStyle2_get_position(style2
, &str
);
2040 ok(hres
== S_OK
, "get_position failed: %08x\n", hres
);
2041 ok(!str
, "str != NULL\n");
2043 str
= a2bstr("absolute");
2044 hres
= IHTMLStyle2_put_position(style2
, str
);
2045 ok(hres
== S_OK
, "get_position failed: %08x\n", hres
);
2049 hres
= IHTMLStyle2_get_position(style2
, &str
);
2050 ok(hres
== S_OK
, "get_position failed: %08x\n", hres
);
2051 ok(!strcmp_wa(str
, "absolute"), "get_position returned %s\n", dbgstr_w(str
));
2055 static void test_default_style(IHTMLStyle
*style
)
2057 IHTMLStyle2
*style2
;
2063 test_disp((IUnknown
*)style
, &DIID_DispHTMLStyle
);
2064 test_ifaces((IUnknown
*)style
, style_iids
);
2066 str
= (void*)0xdeadbeef;
2067 hres
= IHTMLStyle_get_fontFamily(style
, &str
);
2068 ok(hres
== S_OK
, "get_fontFamily failed: %08x\n", hres
);
2069 ok(!str
, "fontFamily = %s\n", dbgstr_w(str
));
2071 str
= (void*)0xdeadbeef;
2072 hres
= IHTMLStyle_get_fontWeight(style
, &str
);
2073 ok(hres
== S_OK
, "get_fontWeight failed: %08x\n", hres
);
2074 ok(!str
, "fontWeight = %s\n", dbgstr_w(str
));
2076 str
= (void*)0xdeadbeef;
2077 hres
= IHTMLStyle_get_display(style
, &str
);
2078 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
2079 ok(!str
, "display = %s\n", dbgstr_w(str
));
2081 str
= (void*)0xdeadbeef;
2082 hres
= IHTMLStyle_get_visibility(style
, &str
);
2083 ok(hres
== S_OK
, "get_visibility failed: %08x\n", hres
);
2084 ok(!str
, "visibility = %s\n", dbgstr_w(str
));
2087 hres
= IHTMLStyle_get_fontSize(style
, &v
);
2088 ok(hres
== S_OK
, "get_fontSize failed: %08x\n", hres
);
2089 ok(V_VT(&v
) == VT_BSTR
, "V_VT(fontSize) = %d\n", V_VT(&v
));
2090 ok(!V_BSTR(&v
), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v
)));
2093 hres
= IHTMLStyle_get_color(style
, &v
);
2094 ok(hres
== S_OK
, "get_color failed: %08x\n", hres
);
2095 ok(V_VT(&v
) == VT_BSTR
, "V_VT(color) = %d\n", V_VT(&v
));
2096 ok(!V_BSTR(&v
), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v
)));
2099 hres
= IHTMLStyle_get_textDecorationUnderline(style
, &b
);
2100 ok(hres
== S_OK
, "get_textDecorationUnderline failed: %08x\n", hres
);
2101 ok(b
== VARIANT_FALSE
, "textDecorationUnderline = %x\n", b
);
2104 hres
= IHTMLStyle_get_textDecorationLineThrough(style
, &b
);
2105 ok(hres
== S_OK
, "get_textDecorationLineThrough failed: %08x\n", hres
);
2106 ok(b
== VARIANT_FALSE
, "textDecorationLineThrough = %x\n", b
);
2108 V_VT(&v
) = VT_EMPTY
;
2109 hres
= IHTMLStyle_get_width(style
, &v
);
2110 ok(hres
== S_OK
, "get_width failed: %08x\n", hres
);
2111 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2112 ok(!V_BSTR(&v
), "V_BSTR(v)=%p\n", V_BSTR(&v
));
2115 V_BSTR(&v
) = a2bstr("auto");
2116 hres
= IHTMLStyle_put_width(style
, v
);
2117 ok(hres
== S_OK
, "put_width failed: %08x\n", hres
);
2120 V_VT(&v
) = VT_EMPTY
;
2121 hres
= IHTMLStyle_get_width(style
, &v
);
2122 ok(hres
== S_OK
, "get_width failed: %08x\n", hres
);
2123 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2124 ok(!strcmp_wa(V_BSTR(&v
), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v
)));
2128 str
= (void*)0xdeadbeef;
2129 hres
= IHTMLStyle_get_margin(style
, &str
);
2130 ok(hres
== S_OK
, "get_margin failed: %08x\n", hres
);
2131 ok(!str
, "margin = %s\n", dbgstr_w(str
));
2134 hres
= IHTMLStyle_put_margin(style
, str
);
2135 ok(hres
== S_OK
, "get_margin failed: %08x\n", hres
);
2138 hres
= IHTMLStyle_get_margin(style
, &str
);
2139 ok(hres
== S_OK
, "get_margin failed: %08x\n", hres
);
2140 ok(strcmp_wa(str
, "1"), "margin = %s\n", dbgstr_w(str
));
2142 hres
= IHTMLStyle_put_margin(style
, NULL
);
2143 ok(hres
== S_OK
, "get_margin failed: %08x\n", hres
);
2146 hres
= IHTMLStyle_get_border(style
, &str
);
2147 ok(hres
== S_OK
, "get_border failed: %08x\n", hres
);
2148 ok(!str
|| !*str
, "str is not empty\n");
2151 str
= a2bstr("1px");
2152 hres
= IHTMLStyle_put_border(style
, str
);
2153 ok(hres
== S_OK
, "get_border failed: %08x\n", hres
);
2156 V_VT(&v
) = VT_EMPTY
;
2157 hres
= IHTMLStyle_get_left(style
, &v
);
2158 ok(hres
== S_OK
, "get_left failed: %08x\n", hres
);
2159 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2160 ok(!V_BSTR(&v
), "V_BSTR(v) != NULL\n");
2164 V_BSTR(&v
) = a2bstr("3px");
2165 hres
= IHTMLStyle_put_left(style
, v
);
2166 ok(hres
== S_OK
, "put_left failed: %08x\n", hres
);
2169 V_VT(&v
) = VT_EMPTY
;
2170 hres
= IHTMLStyle_get_left(style
, &v
);
2171 ok(hres
== S_OK
, "get_left failed: %08x\n", hres
);
2172 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2173 ok(!strcmp_wa(V_BSTR(&v
), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v
)));
2176 V_VT(&v
) = VT_EMPTY
;
2177 hres
= IHTMLStyle_get_top(style
, &v
);
2178 ok(hres
== S_OK
, "get_top failed: %08x\n", hres
);
2179 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2180 ok(!V_BSTR(&v
), "V_BSTR(v) != NULL\n");
2184 V_BSTR(&v
) = a2bstr("3px");
2185 hres
= IHTMLStyle_put_top(style
, v
);
2186 ok(hres
== S_OK
, "put_top failed: %08x\n", hres
);
2189 V_VT(&v
) = VT_EMPTY
;
2190 hres
= IHTMLStyle_get_top(style
, &v
);
2191 ok(hres
== S_OK
, "get_top failed: %08x\n", hres
);
2192 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2193 ok(!strcmp_wa(V_BSTR(&v
), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v
)));
2196 V_VT(&v
) = VT_EMPTY
;
2197 hres
= IHTMLStyle_get_height(style
, &v
);
2198 ok(hres
== S_OK
, "get_height failed: %08x\n", hres
);
2199 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2200 ok(!V_BSTR(&v
), "V_BSTR(v) != NULL\n");
2204 V_BSTR(&v
) = a2bstr("64px");
2205 hres
= IHTMLStyle_put_height(style
, v
);
2206 ok(hres
== S_OK
, "put_height failed: %08x\n", hres
);
2209 V_VT(&v
) = VT_EMPTY
;
2210 hres
= IHTMLStyle_get_height(style
, &v
);
2211 ok(hres
== S_OK
, "get_height failed: %08x\n", hres
);
2212 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2213 ok(!strcmp_wa(V_BSTR(&v
), "64px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v
)));
2216 str
= (void*)0xdeadbeef;
2217 hres
= IHTMLStyle_get_cursor(style
, &str
);
2218 ok(hres
== S_OK
, "get_cursor failed: %08x\n", hres
);
2219 ok(!str
, "get_cursor != NULL\n");
2222 str
= a2bstr("default");
2223 hres
= IHTMLStyle_put_cursor(style
, str
);
2224 ok(hres
== S_OK
, "get_cursor failed: %08x\n", hres
);
2228 hres
= IHTMLStyle_get_cursor(style
, &str
);
2229 ok(hres
== S_OK
, "get_cursor failed: %08x\n", hres
);
2230 ok(!strcmp_wa(str
, "default"), "get_cursor returned %s\n", dbgstr_w(str
));
2233 V_VT(&v
) = VT_EMPTY
;
2234 hres
= IHTMLStyle_get_verticalAlign(style
, &v
);
2235 ok(hres
== S_OK
, "get_vertivalAlign failed: %08x\n", hres
);
2236 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2237 ok(!V_BSTR(&v
), "V_BSTR(v) != NULL\n");
2241 V_BSTR(&v
) = a2bstr("middle");
2242 hres
= IHTMLStyle_put_verticalAlign(style
, v
);
2243 ok(hres
== S_OK
, "put_vertivalAlign failed: %08x\n", hres
);
2246 V_VT(&v
) = VT_EMPTY
;
2247 hres
= IHTMLStyle_get_verticalAlign(style
, &v
);
2248 ok(hres
== S_OK
, "get_verticalAlign failed: %08x\n", hres
);
2249 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
2250 ok(!strcmp_wa(V_BSTR(&v
), "middle"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v
)));
2253 str
= (void*)0xdeadbeef;
2254 hres
= IHTMLStyle_get_textAlign(style
, &str
);
2255 ok(hres
== S_OK
, "get_textAlign failed: %08x\n", hres
);
2256 ok(!str
, "textAlign != NULL\n");
2258 str
= a2bstr("center");
2259 hres
= IHTMLStyle_put_textAlign(style
, str
);
2260 ok(hres
== S_OK
, "put_textAlign failed: %08x\n", hres
);
2264 hres
= IHTMLStyle_get_textAlign(style
, &str
);
2265 ok(hres
== S_OK
, "get_textAlign failed: %08x\n", hres
);
2266 ok(!strcmp_wa(str
, "center"), "textAlign = %s\n", dbgstr_w(V_BSTR(&v
)));
2269 str
= (void*)0xdeadbeef;
2270 hres
= IHTMLStyle_get_filter(style
, &str
);
2271 ok(hres
== S_OK
, "get_filter failed: %08x\n", hres
);
2272 ok(!str
, "filter != NULL\n");
2274 str
= a2bstr("alpha(opacity=100)");
2275 hres
= IHTMLStyle_put_filter(style
, str
);
2276 ok(hres
== S_OK
, "put_filter failed: %08x\n", hres
);
2279 V_VT(&v
) = VT_EMPTY
;
2280 hres
= IHTMLStyle_get_zIndex(style
, &v
);
2281 ok(hres
== S_OK
, "get_zIndex failed: %08x\n", hres
);
2282 ok(V_VT(&v
) == VT_I4
, "V_VT(v)=%d\n", V_VT(&v
));
2283 ok(!V_I4(&v
), "V_I4(v) != 0\n");
2287 V_BSTR(&v
) = a2bstr("1");
2288 hres
= IHTMLStyle_put_zIndex(style
, v
);
2289 ok(hres
== S_OK
, "put_zIndex failed: %08x\n", hres
);
2292 V_VT(&v
) = VT_EMPTY
;
2293 hres
= IHTMLStyle_get_zIndex(style
, &v
);
2294 ok(hres
== S_OK
, "get_zIndex failed: %08x\n", hres
);
2295 ok(V_VT(&v
) == VT_I4
, "V_VT(v)=%d\n", V_VT(&v
));
2296 ok(V_I4(&v
) == 1, "V_I4(v) = %d\n", V_I4(&v
));
2299 hres
= IHTMLStyle_QueryInterface(style
, &IID_IHTMLStyle2
, (void**)&style2
);
2300 ok(hres
== S_OK
, "Could not get IHTMLStyle2 iface: %08x\n", hres
);
2301 if(SUCCEEDED(hres
)) {
2302 test_style2(style2
);
2303 IHTMLStyle2_Release(style2
);
2307 static void test_default_selection(IHTMLDocument2
*doc
)
2309 IHTMLSelectionObject
*selection
;
2310 IHTMLTxtRange
*range
;
2315 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
2316 ok(hres
== S_OK
, "get_selection failed: %08x\n", hres
);
2318 hres
= IHTMLSelectionObject_get_type(selection
, &str
);
2319 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
2320 ok(!lstrcmpW(str
, noneW
), "type = %s\n", dbgstr_w(str
));
2323 hres
= IHTMLSelectionObject_createRange(selection
, &disp
);
2324 IHTMLSelectionObject_Release(selection
);
2325 ok(hres
== S_OK
, "createRange failed: %08x\n", hres
);
2327 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLTxtRange
, (void**)&range
);
2328 IDispatch_Release(disp
);
2329 ok(hres
== S_OK
, "Could not get IHTMLTxtRange interface: %08x\n", hres
);
2331 test_range_text(range
, NULL
);
2332 IHTMLTxtRange_Release(range
);
2335 static void test_default_body(IHTMLBodyElement
*body
)
2341 WCHAR sBodyText
[] = {'#','F','F','0','0','0','0',0};
2342 WCHAR sTextInvalid
[] = {'I','n','v','a','l','i','d',0};
2343 WCHAR sResInvalid
[] = {'#','0','0','a','0','d','0',0};
2345 bstr
= (void*)0xdeadbeef;
2346 hres
= IHTMLBodyElement_get_background(body
, &bstr
);
2347 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2348 ok(bstr
== NULL
, "bstr != NULL\n");
2350 l
= elem_get_scroll_height((IUnknown
*)body
);
2351 ok(l
!= -1, "scrollHeight == -1\n");
2352 l
= elem_get_scroll_width((IUnknown
*)body
);
2353 ok(l
!= -1, "scrollWidth == -1\n");
2354 l
= elem_get_scroll_top((IUnknown
*)body
);
2355 ok(!l
, "scrollTop = %ld\n", l
);
2356 elem_get_scroll_left((IUnknown
*)body
);
2358 /* get_text tests */
2359 hres
= IHTMLBodyElement_get_text(body
, &v
);
2360 ok(hres
== S_OK
, "expect S_OK got 0x%08d\n", hres
);
2361 ok(V_VT(&v
) == VT_BSTR
, "Expected VT_BSTR got %d\n", V_VT(&v
));
2362 ok(bstr
== NULL
, "bstr != NULL\n");
2365 /* get_text - Invalid Text */
2367 V_BSTR(&v
) = SysAllocString(sTextInvalid
);
2368 hres
= IHTMLBodyElement_put_text(body
, v
);
2369 ok(hres
== S_OK
, "expect S_OK got 0x%08d\n", hres
);
2372 hres
= IHTMLBodyElement_get_text(body
, &v
);
2373 ok(hres
== S_OK
, "expect S_OK got 0x%08d\n", hres
);
2374 ok(V_VT(&v
) == VT_BSTR
, "Expected VT_BSTR got %d\n", V_VT(&v
));
2375 ok(!lstrcmpW(sResInvalid
, V_BSTR(&v
)), "bstr != sResInvalid\n");
2378 /* get_text - Valid Text */
2380 V_BSTR(&v
) = SysAllocString(sBodyText
);
2381 hres
= IHTMLBodyElement_put_text(body
, v
);
2382 ok(hres
== S_OK
, "expect S_OK got 0x%08d\n", hres
);
2385 hres
= IHTMLBodyElement_get_text(body
, &v
);
2386 ok(hres
== S_OK
, "expect S_OK got 0x%08d\n", hres
);
2387 ok(V_VT(&v
) == VT_BSTR
, "Expected VT_BSTR got %d\n", V_VT(&v
));
2388 ok(lstrcmpW(bstr
, V_BSTR(&v
)), "bstr != V_BSTR(&v)\n");
2392 static void test_body_funs(IHTMLBodyElement
*body
)
2394 static WCHAR sRed
[] = {'r','e','d',0};
2395 static WCHAR sRedbg
[] = {'#','f','f','0','0','0','0',0};
2400 hres
= IHTMLBodyElement_get_bgColor(body
, &vDefaultbg
);
2401 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2402 ok(V_VT(&vDefaultbg
) == VT_BSTR
, "bstr != NULL\n");
2404 V_VT(&vbg
) = VT_BSTR
;
2405 V_BSTR(&vbg
) = SysAllocString(sRed
);
2406 hres
= IHTMLBodyElement_put_bgColor(body
, vbg
);
2407 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2410 hres
= IHTMLBodyElement_get_bgColor(body
, &vbg
);
2411 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2412 ok(V_VT(&vDefaultbg
) == VT_BSTR
, "V_VT(&vDefaultbg) != VT_BSTR\n");
2413 ok(!lstrcmpW(V_BSTR(&vbg
), sRedbg
), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg
)));
2416 /* Restore Originial */
2417 hres
= IHTMLBodyElement_put_bgColor(body
, vDefaultbg
);
2418 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2419 VariantClear(&vDefaultbg
);
2422 static void test_window(IHTMLDocument2
*doc
)
2424 IHTMLWindow2
*window
, *window2
, *self
;
2425 IHTMLDocument2
*doc2
= NULL
;
2429 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
2430 ok(hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
2431 test_ifaces((IUnknown
*)window
, window_iids
);
2432 test_disp((IUnknown
*)window
, &DIID_DispHTMLWindow2
);
2434 hres
= IHTMLWindow2_get_document(window
, &doc2
);
2435 ok(hres
== S_OK
, "get_document failed: %08x\n", hres
);
2436 ok(doc2
!= NULL
, "doc2 == NULL\n");
2438 IHTMLDocument_Release(doc2
);
2440 hres
= IHTMLWindow2_get_window(window
, &window2
);
2441 ok(hres
== S_OK
, "get_window failed: %08x\n", hres
);
2442 ok(window2
!= NULL
, "window2 == NULL\n");
2444 hres
= IHTMLWindow2_get_self(window
, &self
);
2445 ok(hres
== S_OK
, "get_window failed: %08x\n", hres
);
2446 ok(window2
!= NULL
, "self == NULL\n");
2448 ok(self
== window2
, "self != window2\n");
2450 IHTMLWindow2_Release(window2
);
2451 IHTMLWindow2_Release(self
);
2454 hres
= IHTMLDocument2_get_Script(doc
, &disp
);
2455 ok(hres
== S_OK
, "get_Script failed: %08x\n", hres
);
2456 ok(disp
== (void*)window
, "disp != window\n");
2457 IDispatch_Release(disp
);
2459 IHTMLWindow2_Release(window
);
2462 static void test_defaults(IHTMLDocument2
*doc
)
2464 IHTMLStyleSheetsCollection
*stylesheetcol
;
2465 IHTMLCurrentStyle
*cstyle
;
2466 IHTMLBodyElement
*body
;
2467 IHTMLElement2
*elem2
;
2473 hres
= IHTMLDocument2_get_body(doc
, &elem
);
2474 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2476 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
2477 ok(hres
== S_OK
, "Could not get IHTMBodyElement: %08x\n", hres
);
2478 test_default_body(body
);
2479 test_body_funs(body
);
2480 IHTMLBodyElement_Release(body
);
2482 hres
= IHTMLElement_get_style(elem
, &style
);
2483 ok(hres
== S_OK
, "get_style failed: %08x\n", hres
);
2485 test_default_style(style
);
2487 test_compatmode(doc
);
2489 test_navigator(doc
);
2491 IHTMLStyle_Release(style
);
2493 elem2
= get_elem2_iface((IUnknown
*)elem
);
2494 hres
= IHTMLElement2_get_currentStyle(elem2
, &cstyle
);
2495 ok(hres
== S_OK
, "get_currentStyle failed: %08x\n", hres
);
2496 if(SUCCEEDED(hres
)) {
2497 test_current_style(cstyle
);
2498 IHTMLCurrentStyle_Release(cstyle
);
2500 IHTMLElement2_Release(elem2
);
2502 IHTMLElement_Release(elem
);
2504 hres
= IHTMLDocument2_get_styleSheets(doc
, &stylesheetcol
);
2505 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
2508 hres
= IHTMLStyleSheetsCollection_get_length(stylesheetcol
, &l
);
2509 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2510 ok(l
== 0, "length = %ld\n", l
);
2512 IHTMLStyleSheetsCollection_Release(stylesheetcol
);
2514 test_default_selection(doc
);
2515 test_doc_title(doc
, "");
2518 static void test_tr_elem(IHTMLElement
*elem
)
2520 IHTMLElementCollection
*col
;
2524 static const elem_type_t cell_types
[] = {ET_TD
,ET_TD
};
2526 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLTableRow
, (void**)&row
);
2527 ok(hres
== S_OK
, "Could not get IHTMLTableRow iface: %08x\n", hres
);
2532 hres
= IHTMLTableRow_get_cells(row
, &col
);
2533 ok(hres
== S_OK
, "get_cells failed: %08x\n", hres
);
2534 ok(col
!= NULL
, "get_cells returned NULL\n");
2536 test_elem_collection((IUnknown
*)col
, cell_types
, sizeof(cell_types
)/sizeof(*cell_types
));
2537 IHTMLElementCollection_Release(col
);
2539 IHTMLTable_Release(row
);
2542 static void test_table_elem(IHTMLElement
*elem
)
2544 IHTMLElementCollection
*col
;
2548 static const elem_type_t row_types
[] = {ET_TR
,ET_TR
};
2550 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLTable
, (void**)&table
);
2551 ok(hres
== S_OK
, "Could not get IHTMLTable iface: %08x\n", hres
);
2556 hres
= IHTMLTable_get_rows(table
, &col
);
2557 ok(hres
== S_OK
, "get_rows failed: %08x\n", hres
);
2558 ok(col
!= NULL
, "get_ros returned NULL\n");
2560 test_elem_collection((IUnknown
*)col
, row_types
, sizeof(row_types
)/sizeof(*row_types
));
2561 IHTMLElementCollection_Release(col
);
2563 IHTMLTable_Release(table
);
2566 static void test_stylesheet(IDispatch
*disp
)
2568 IHTMLStyleSheetRulesCollection
*col
= NULL
;
2569 IHTMLStyleSheet
*stylesheet
;
2572 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLStyleSheet
, (void**)&stylesheet
);
2573 ok(hres
== S_OK
, "Could not get IHTMLStyleSheet: %08x\n", hres
);
2575 hres
= IHTMLStyleSheet_get_rules(stylesheet
, &col
);
2576 ok(hres
== S_OK
, "get_rules failed: %08x\n", hres
);
2577 ok(col
!= NULL
, "col == NULL\n");
2579 IHTMLStyleSheetRulesCollection_Release(col
);
2580 IHTMLStyleSheet_Release(stylesheet
);
2583 static void test_stylesheets(IHTMLDocument2
*doc
)
2585 IHTMLStyleSheetsCollection
*col
= NULL
;
2590 hres
= IHTMLDocument2_get_styleSheets(doc
, &col
);
2591 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
2592 ok(col
!= NULL
, "col == NULL\n");
2594 hres
= IHTMLStyleSheetsCollection_get_length(col
, &len
);
2595 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2596 ok(len
== 1, "len=%ld\n", len
);
2602 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
2603 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
2604 ok(V_VT(&res
) == VT_DISPATCH
, "V_VT(res) = %d\n", V_VT(&res
));
2605 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
2606 test_stylesheet(V_DISPATCH(&res
));
2613 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
2614 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2615 ok(V_VT(&res
) == VT_EMPTY
, "V_VT(res) = %d\n", V_VT(&res
));
2616 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
2619 IHTMLStyleSheetsCollection_Release(col
);
2622 static void test_child_col_disp(IHTMLDOMChildrenCollection
*col
)
2624 IDispatchEx
*dispex
;
2626 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
2634 static const WCHAR w0
[] = {'0',0};
2635 static const WCHAR w100
[] = {'1','0','0',0};
2637 hres
= IHTMLDOMChildrenCollection_QueryInterface(col
, &IID_IDispatchEx
, (void**)&dispex
);
2638 ok(hres
== S_OK
, "Could not get IDispatchEx: %08x\n", hres
);
2640 bstr
= SysAllocString(w0
);
2641 hres
= IDispatchEx_GetDispID(dispex
, bstr
, fdexNameCaseSensitive
, &id
);
2642 ok(hres
== S_OK
, "GetDispID failed: %08x\n", hres
);
2643 SysFreeString(bstr
);
2646 hres
= IDispatchEx_InvokeEx(dispex
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYGET
, &dp
, &var
, &ei
, NULL
);
2647 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
2648 ok(V_VT(&var
) == VT_DISPATCH
, "V_VT(var)=%d\n", V_VT(&var
));
2649 ok(V_DISPATCH(&var
) != NULL
, "V_DISPATCH(var) == NULL\n");
2650 node
= get_node_iface((IUnknown
*)V_DISPATCH(&var
));
2651 type
= get_node_type((IUnknown
*)node
);
2652 ok(type
== 3, "type=%ld\n", type
);
2653 IHTMLDOMNode_Release(node
);
2656 bstr
= SysAllocString(w100
);
2657 hres
= IDispatchEx_GetDispID(dispex
, bstr
, fdexNameCaseSensitive
, &id
);
2658 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
2659 SysFreeString(bstr
);
2661 IDispatchEx_Release(dispex
);
2666 static void test_elems(IHTMLDocument2
*doc
)
2668 IHTMLElementCollection
*col
;
2669 IHTMLDOMChildrenCollection
*child_col
;
2670 IHTMLElement
*elem
, *elem2
, *elem3
;
2671 IHTMLDOMNode
*node
, *node2
;
2676 static const WCHAR imgidW
[] = {'i','m','g','i','d',0};
2677 static const WCHAR inW
[] = {'i','n',0};
2678 static const WCHAR xW
[] = {'x',0};
2679 static const WCHAR sW
[] = {'s',0};
2680 static const WCHAR scW
[] = {'s','c',0};
2681 static const WCHAR xxxW
[] = {'x','x','x',0};
2682 static const WCHAR tblW
[] = {'t','b','l',0};
2683 static const WCHAR row2W
[] = {'r','o','w','2',0};
2685 static const elem_type_t all_types
[] = {
2710 static const elem_type_t item_types
[] = {
2716 hres
= IHTMLDocument2_get_all(doc
, &col
);
2717 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2718 test_elem_collection((IUnknown
*)col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
2719 test_elem_col_item(col
, xW
, item_types
, sizeof(item_types
)/sizeof(item_types
[0]));
2720 IHTMLElementCollection_Release(col
);
2722 elem
= get_doc_elem(doc
);
2723 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
2724 hres
= IHTMLElement_get_all(elem
, &disp
);
2725 IHTMLElement_Release(elem
);
2726 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2728 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&col
);
2729 IDispatch_Release(disp
);
2730 ok(hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
2731 test_elem_collection((IUnknown
*)col
, all_types
+1, sizeof(all_types
)/sizeof(all_types
[0])-1);
2732 IHTMLElementCollection_Release(col
);
2734 get_elem_by_id(doc
, xxxW
, FALSE
);
2735 elem
= get_doc_elem_by_id(doc
, xxxW
);
2736 ok(!elem
, "elem != NULL\n");
2738 elem
= get_doc_elem_by_id(doc
, sW
);
2739 ok(elem
!= NULL
, "elem == NULL\n");
2741 test_elem_type((IUnknown
*)elem
, ET_SELECT
);
2742 test_elem_attr(elem
, xxxW
, NULL
);
2743 test_elem_attr(elem
, idW
, sW
);
2744 test_elem_class((IUnknown
*)elem
, NULL
);
2745 test_elem_set_class((IUnknown
*)elem
, "cl");
2746 test_elem_set_class((IUnknown
*)elem
, NULL
);
2747 test_elem_tabindex((IUnknown
*)elem
, 0);
2748 test_elem_set_tabindex((IUnknown
*)elem
, 1);
2750 node
= test_node_get_parent((IUnknown
*)elem
);
2751 ok(node
!= NULL
, "node == NULL\n");
2752 test_node_name((IUnknown
*)node
, "BODY");
2753 node2
= test_node_get_parent((IUnknown
*)node
);
2754 IHTMLDOMNode_Release(node
);
2755 ok(node2
!= NULL
, "node == NULL\n");
2756 test_node_name((IUnknown
*)node2
, "HTML");
2757 node
= test_node_get_parent((IUnknown
*)node2
);
2758 IHTMLDOMNode_Release(node2
);
2759 ok(node
!= NULL
, "node == NULL\n");
2760 test_node_name((IUnknown
*)node
, "#document");
2761 type
= get_node_type((IUnknown
*)node
);
2762 ok(type
== 9, "type=%ld, expected 9\n", type
);
2763 node2
= test_node_get_parent((IUnknown
*)node
);
2764 IHTMLDOMNode_Release(node
);
2765 ok(node2
== NULL
, "node != NULL\n");
2767 elem2
= test_elem_get_parent((IUnknown
*)elem
);
2768 ok(elem2
!= NULL
, "elem2 == NULL\n");
2769 test_node_name((IUnknown
*)elem2
, "BODY");
2770 elem3
= test_elem_get_parent((IUnknown
*)elem2
);
2771 IHTMLElement_Release(elem2
);
2772 ok(elem3
!= NULL
, "elem3 == NULL\n");
2773 test_node_name((IUnknown
*)elem3
, "HTML");
2774 elem2
= test_elem_get_parent((IUnknown
*)elem3
);
2775 IHTMLElement_Release(elem3
);
2776 ok(elem2
== NULL
, "elem2 != NULL\n");
2778 test_elem_getelembytag((IUnknown
*)elem
, ET_OPTION
, 2);
2779 test_elem_getelembytag((IUnknown
*)elem
, ET_SELECT
, 0);
2780 test_elem_getelembytag((IUnknown
*)elem
, ET_HTML
, 0);
2782 IHTMLElement_Release(elem
);
2785 elem
= get_elem_by_id(doc
, sW
, TRUE
);
2787 IHTMLSelectElement
*select
;
2789 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLSelectElement
, (void**)&select
);
2790 ok(hres
== S_OK
, "Could not get IHTMLSelectElement interface: %08x\n", hres
);
2792 test_select_elem(select
);
2794 test_elem_title((IUnknown
*)select
, NULL
);
2795 test_elem_set_title((IUnknown
*)select
, "Title");
2796 test_elem_title((IUnknown
*)select
, "Title");
2797 test_elem_offset((IUnknown
*)select
);
2799 node
= get_first_child((IUnknown
*)select
);
2800 ok(node
!= NULL
, "node == NULL\n");
2802 test_elem_type((IUnknown
*)node
, ET_OPTION
);
2803 IHTMLDOMNode_Release(node
);
2806 type
= get_node_type((IUnknown
*)select
);
2807 ok(type
== 1, "type=%ld\n", type
);
2809 IHTMLSelectElement_Release(select
);
2810 IHTMLElement_Release(elem
);
2813 elem
= get_elem_by_id(doc
, scW
, TRUE
);
2815 IHTMLScriptElement
*script
;
2818 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLScriptElement
, (void**)&script
);
2819 ok(hres
== S_OK
, "Could not get IHTMLScriptElement interface: %08x\n", hres
);
2821 hres
= IHTMLScriptElement_get_type(script
, &type
);
2822 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
2823 ok(!lstrcmpW(type
, text_javascriptW
), "Unexpected type %s\n", dbgstr_w(type
));
2824 SysFreeString(type
);
2826 IHTMLScriptElement_Release(script
);
2829 elem
= get_elem_by_id(doc
, inW
, TRUE
);
2831 IHTMLInputElement
*input
;
2833 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLInputElement
, (void**)&input
);
2834 ok(hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
2836 test_elem_id((IUnknown
*)elem
, "in");
2837 test_elem_put_id((IUnknown
*)elem
, "newin");
2838 test_input_get_disabled(input
, VARIANT_FALSE
);
2839 test_input_set_disabled(input
, VARIANT_TRUE
);
2840 test_input_set_disabled(input
, VARIANT_FALSE
);
2841 test_elem_client_size((IUnknown
*)elem
);
2843 test_node_get_value_str((IUnknown
*)elem
, NULL
);
2844 test_node_put_value_str((IUnknown
*)elem
, "test");
2845 test_node_get_value_str((IUnknown
*)elem
, NULL
);
2846 test_input_value((IUnknown
*)elem
, NULL
);
2847 test_input_put_value((IUnknown
*)elem
, "test");
2848 test_input_value((IUnknown
*)elem
, NULL
);
2849 test_elem_class((IUnknown
*)elem
, "testclass");
2850 test_elem_tabindex((IUnknown
*)elem
, 2);
2851 test_elem_set_tabindex((IUnknown
*)elem
, 3);
2852 test_elem_title((IUnknown
*)elem
, "test title");
2854 IHTMLInputElement_Release(input
);
2855 IHTMLElement_Release(elem
);
2858 elem
= get_elem_by_id(doc
, imgidW
, TRUE
);
2860 test_img_set_src((IUnknown
*)elem
, "about:blank");
2861 test_img_alt((IUnknown
*)elem
, NULL
);
2862 test_img_set_alt((IUnknown
*)elem
, "alt test");
2863 IHTMLElement_Release(elem
);
2866 elem
= get_doc_elem_by_id(doc
, tblW
);
2867 ok(elem
!= NULL
, "elem == NULL\n");
2869 test_table_elem(elem
);
2870 IHTMLElement_Release(elem
);
2873 elem
= get_doc_elem_by_id(doc
, row2W
);
2874 ok(elem
!= NULL
, "elem == NULL\n");
2877 IHTMLElement_Release(elem
);
2880 hres
= IHTMLDocument2_get_body(doc
, &elem
);
2881 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2883 node
= get_first_child((IUnknown
*)elem
);
2884 ok(node
!= NULL
, "node == NULL\n");
2886 test_ifaces((IUnknown
*)node
, text_iids
);
2887 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
2889 node2
= get_first_child((IUnknown
*)node
);
2890 ok(!node2
, "node2 != NULL\n");
2892 type
= get_node_type((IUnknown
*)node
);
2893 ok(type
== 3, "type=%ld\n", type
);
2895 test_node_get_value_str((IUnknown
*)node
, "text test");
2896 test_node_put_value_str((IUnknown
*)elem
, "test text");
2897 test_node_get_value_str((IUnknown
*)node
, "text test");
2899 IHTMLDOMNode_Release(node
);
2902 child_col
= get_child_nodes((IUnknown
*)elem
);
2903 ok(child_col
!= NULL
, "child_coll == NULL\n");
2907 test_disp((IUnknown
*)child_col
, &DIID_DispDOMChildrenCollection
);
2909 hres
= IHTMLDOMChildrenCollection_get_length(child_col
, &length
);
2910 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2911 ok(length
, "length=0\n");
2913 node
= get_child_item(child_col
, 0);
2914 ok(node
!= NULL
, "node == NULL\n");
2916 type
= get_node_type((IUnknown
*)node
);
2917 ok(type
== 3, "type=%ld\n", type
);
2918 IHTMLDOMNode_Release(node
);
2921 node
= get_child_item(child_col
, 1);
2922 ok(node
!= NULL
, "node == NULL\n");
2924 type
= get_node_type((IUnknown
*)node
);
2925 ok(type
== 8, "type=%ld\n", type
);
2927 test_elem_id((IUnknown
*)node
, NULL
);
2928 IHTMLDOMNode_Release(node
);
2931 disp
= (void*)0xdeadbeef;
2932 hres
= IHTMLDOMChildrenCollection_item(child_col
, 6000, &disp
);
2933 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2934 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
2936 disp
= (void*)0xdeadbeef;
2937 hres
= IHTMLDOMChildrenCollection_item(child_col
, length
, &disp
);
2938 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2939 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
2941 test_child_col_disp(child_col
);
2943 IHTMLDOMChildrenCollection_Release(child_col
);
2946 IHTMLElement_Release(elem
);
2948 test_stylesheets(doc
);
2949 test_create_option_elem(doc
);
2951 test_doc_title(doc
, "test");
2952 test_doc_set_title(doc
, "test title");
2953 test_doc_title(doc
, "test title");
2956 static void test_create_elems(IHTMLDocument2
*doc
)
2958 IHTMLElement
*elem
, *body
, *elem2
;
2964 static const elem_type_t types1
[] = { ET_TESTG
};
2966 elem
= test_create_elem(doc
, "TEST");
2967 test_elem_tag((IUnknown
*)elem
, "TEST");
2968 type
= get_node_type((IUnknown
*)elem
);
2969 ok(type
== 1, "type=%ld\n", type
);
2970 test_ifaces((IUnknown
*)elem
, elem_iids
);
2971 test_disp((IUnknown
*)elem
, &DIID_DispHTMLGenericElement
);
2973 hres
= IHTMLDocument2_get_body(doc
, &body
);
2974 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2975 test_node_has_child((IUnknown
*)body
, VARIANT_FALSE
);
2977 node
= test_node_append_child((IUnknown
*)body
, (IUnknown
*)elem
);
2978 test_node_has_child((IUnknown
*)body
, VARIANT_TRUE
);
2979 elem2
= get_elem_iface((IUnknown
*)node
);
2980 IHTMLElement_Release(elem2
);
2982 hres
= IHTMLElement_get_all(body
, &disp
);
2983 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2984 test_elem_collection((IUnknown
*)disp
, types1
, sizeof(types1
)/sizeof(types1
[0]));
2985 IDispatch_Release(disp
);
2987 test_node_remove_child((IUnknown
*)body
, node
);
2989 hres
= IHTMLElement_get_all(body
, &disp
);
2990 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2991 test_elem_collection((IUnknown
*)disp
, NULL
, 0);
2992 IDispatch_Release(disp
);
2993 test_node_has_child((IUnknown
*)body
, VARIANT_FALSE
);
2995 IHTMLElement_Release(body
);
2996 IHTMLElement_Release(elem
);
2997 IHTMLDOMNode_Release(node
);
2999 node
= test_create_text(doc
, "test");
3000 test_ifaces((IUnknown
*)node
, text_iids
);
3001 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
3002 IHTMLDOMNode_Release(node
);
3005 static void test_exec(IUnknown
*unk
, const GUID
*grpid
, DWORD cmdid
, VARIANT
*in
, VARIANT
*out
)
3007 IOleCommandTarget
*cmdtrg
;
3010 hres
= IHTMLTxtRange_QueryInterface(unk
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
3011 ok(hres
== S_OK
, "Could not get IOleCommandTarget interface: %08x\n", hres
);
3013 hres
= IOleCommandTarget_Exec(cmdtrg
, grpid
, cmdid
, 0, in
, out
);
3014 ok(hres
== S_OK
, "Exec failed: %08x\n", hres
);
3016 IOleCommandTarget_Release(cmdtrg
);
3019 static void test_indent(IHTMLDocument2
*doc
)
3021 IHTMLElementCollection
*col
;
3022 IHTMLTxtRange
*range
;
3025 static const elem_type_t all_types
[] = {
3034 static const elem_type_t indent_types
[] = {
3045 hres
= IHTMLDocument2_get_all(doc
, &col
);
3046 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
3047 test_elem_collection((IUnknown
*)col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
3048 IHTMLElementCollection_Release(col
);
3050 range
= test_create_body_range(doc
);
3051 test_exec((IUnknown
*)range
, &CGID_MSHTML
, IDM_INDENT
, NULL
, NULL
);
3052 IHTMLTxtRange_Release(range
);
3054 hres
= IHTMLDocument2_get_all(doc
, &col
);
3055 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
3056 test_elem_collection((IUnknown
*)col
, indent_types
, sizeof(indent_types
)/sizeof(indent_types
[0]));
3057 IHTMLElementCollection_Release(col
);
3060 static IHTMLDocument2
*notif_doc
;
3061 static BOOL doc_complete
;
3063 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
3064 REFIID riid
, void**ppv
)
3066 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
3071 ok(0, "unexpected call\n");
3072 return E_NOINTERFACE
;
3075 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
3080 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
3085 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
3087 if(dispID
== DISPID_READYSTATE
){
3091 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
3093 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
3094 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
3096 if(!lstrcmpW(state
, completeW
))
3097 doc_complete
= TRUE
;
3099 SysFreeString(state
);
3105 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
3107 ok(0, "unexpected call\n");
3111 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
3112 PropertyNotifySink_QueryInterface
,
3113 PropertyNotifySink_AddRef
,
3114 PropertyNotifySink_Release
,
3115 PropertyNotifySink_OnChanged
,
3116 PropertyNotifySink_OnRequestEdit
3119 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
3121 static IHTMLDocument2
*create_doc_with_string(const char *str
)
3123 IPersistStreamInit
*init
;
3125 IHTMLDocument2
*doc
;
3129 notif_doc
= doc
= create_document();
3133 doc_complete
= FALSE
;
3135 mem
= GlobalAlloc(0, len
);
3136 memcpy(mem
, str
, len
);
3137 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
3139 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
3141 IPersistStreamInit_Load(init
, stream
);
3142 IPersistStreamInit_Release(init
);
3143 IStream_Release(stream
);
3148 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
3150 IConnectionPointContainer
*container
;
3151 IConnectionPoint
*cp
;
3155 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
3156 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
3158 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
3159 IConnectionPointContainer_Release(container
);
3160 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
3162 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
3163 IConnectionPoint_Release(cp
);
3164 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
3167 typedef void (*domtest_t
)(IHTMLDocument2
*);
3169 static void run_domtest(const char *str
, domtest_t test
)
3171 IHTMLDocument2
*doc
;
3172 IHTMLElement
*body
= NULL
;
3177 doc
= create_doc_with_string(str
);
3178 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
3180 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
3181 TranslateMessage(&msg
);
3182 DispatchMessage(&msg
);
3185 hres
= IHTMLDocument2_get_body(doc
, &body
);
3186 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
3189 IHTMLElement_Release(body
);
3192 skip("Could not get document body. Assuming no Gecko installed.\n");
3195 ref
= IHTMLDocument2_Release(doc
);
3197 ref
== 1, /* Vista */
3201 static void gecko_installer_workaround(BOOL disable
)
3206 static BOOL has_url
= FALSE
;
3207 static char url
[2048];
3209 if(!disable
&& !has_url
)
3212 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
3213 if(res
!= ERROR_SUCCESS
)
3217 DWORD type
, size
= sizeof(url
);
3219 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
3220 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
3223 RegDeleteValue(hkey
, "GeckoUrl");
3225 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
3233 gecko_installer_workaround(TRUE
);
3236 run_domtest(doc_str1
, test_doc_elem
);
3237 run_domtest(range_test_str
, test_txtrange
);
3238 run_domtest(range_test2_str
, test_txtrange2
);
3239 run_domtest(elem_test_str
, test_elems
);
3240 run_domtest(doc_blank
, test_create_elems
);
3241 run_domtest(doc_blank
, test_defaults
);
3242 run_domtest(indent_test_str
, test_indent
);
3245 gecko_installer_workaround(FALSE
);