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><tbody></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
53 static const char indent_test_str
[] =
54 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
56 static const WCHAR noneW
[] = {'N','o','n','e',0};
58 static WCHAR characterW
[] = {'c','h','a','r','a','c','t','e','r',0};
59 static WCHAR texteditW
[] = {'t','e','x','t','e','d','i','t',0};
60 static WCHAR wordW
[] = {'w','o','r','d',0};
62 static const WCHAR text_javascriptW
[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
64 static const WCHAR idW
[] = {'i','d',0};
90 static REFIID
const none_iids
[] = {
95 static REFIID
const elem_iids
[] = {
101 &IID_IConnectionPointContainer
,
105 static REFIID
const body_iids
[] = {
110 &IID_IHTMLTextContainer
,
111 &IID_IHTMLBodyElement
,
113 &IID_IConnectionPointContainer
,
117 static REFIID
const anchor_iids
[] = {
122 &IID_IHTMLAnchorElement
,
124 &IID_IConnectionPointContainer
,
128 static REFIID
const input_iids
[] = {
133 &IID_IHTMLInputElement
,
134 &IID_IHTMLInputTextElement
,
136 &IID_IConnectionPointContainer
,
140 static REFIID
const select_iids
[] = {
145 &IID_IHTMLSelectElement
,
147 &IID_IConnectionPointContainer
,
151 static REFIID
const textarea_iids
[] = {
156 &IID_IHTMLTextAreaElement
,
158 &IID_IConnectionPointContainer
,
162 static REFIID
const option_iids
[] = {
167 &IID_IHTMLOptionElement
,
169 &IID_IConnectionPointContainer
,
173 static REFIID
const table_iids
[] = {
180 &IID_IConnectionPointContainer
,
184 static REFIID
const script_iids
[] = {
189 &IID_IHTMLScriptElement
,
191 &IID_IConnectionPointContainer
,
195 static REFIID
const text_iids
[] = {
198 &IID_IHTMLDOMTextNode
,
202 static REFIID
const location_iids
[] = {
208 static REFIID
const window_iids
[] = {
216 static REFIID
const comment_iids
[] = {
221 &IID_IHTMLCommentElement
,
223 &IID_IConnectionPointContainer
,
227 static REFIID
const img_iids
[] = {
233 &IID_IHTMLImgElement
,
234 &IID_IConnectionPointContainer
,
238 static REFIID
const generic_iids
[] = {
243 &IID_IHTMLGenericElement
,
245 &IID_IConnectionPointContainer
,
255 static const elem_type_info_t elem_type_infos
[] = {
256 {"", none_iids
, NULL
},
257 {"HTML", elem_iids
, NULL
},
258 {"HEAD", elem_iids
, NULL
},
259 {"TITLE", elem_iids
, NULL
},
260 {"BODY", body_iids
, NULL
},
261 {"A", anchor_iids
, NULL
},
262 {"INPUT", input_iids
, &DIID_DispHTMLInputElement
},
263 {"SELECT", select_iids
, &DIID_DispHTMLSelectElement
},
264 {"TEXTAREA", textarea_iids
, NULL
},
265 {"OPTION", option_iids
, &DIID_DispHTMLOptionElement
},
266 {"STYLE", elem_iids
, NULL
},
267 {"BLOCKQUOTE",elem_iids
, NULL
},
268 {"P", elem_iids
, NULL
},
269 {"BR", elem_iids
, NULL
},
270 {"TABLE", table_iids
, NULL
},
271 {"TBODY", elem_iids
, NULL
},
272 {"SCRIPT", script_iids
, NULL
},
273 {"TEST", elem_iids
, &DIID_DispHTMLUnknownElement
},
274 {"TEST", generic_iids
, &DIID_DispHTMLGenericElement
},
275 {"!", comment_iids
, &DIID_DispHTMLCommentElement
},
276 {"IMG", img_iids
, &DIID_DispHTMLImg
}
279 static const char *dbgstr_w(LPCWSTR str
)
281 static char buf
[512];
284 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
288 static const char *dbgstr_guid(REFIID riid
)
292 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
293 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
294 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
295 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
300 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
303 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
304 return lstrcmpW(strw
, buf
);
307 static BSTR
a2bstr(const char *str
)
312 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
313 ret
= SysAllocStringLen(NULL
, len
);
314 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
319 static IHTMLDocument2
*create_document(void)
324 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
325 &IID_IHTMLDocument2
, (void**)&doc
);
326 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
331 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
332 static void _test_ifaces(unsigned line
, IUnknown
*iface
, REFIID
*iids
)
334 const IID
* const *piid
;
338 for(piid
= iids
; *piid
; piid
++) {
339 hres
= IDispatch_QueryInterface(iface
, *piid
, (void**)&unk
);
340 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get %s interface: %08x\n", dbgstr_guid(*piid
), hres
);
342 IUnknown_Release(unk
);
346 #define test_disp(u,id) _test_disp(__LINE__,u,id)
347 static void _test_disp(unsigned line
, IUnknown
*unk
, const IID
*diid
)
354 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
355 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IDispatch: %08x\n", hres
);
360 hres
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
361 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfoCount failed: %08x\n", hres
);
362 ok_(__FILE__
,line
) (ticnt
== 1, "ticnt=%u\n", ticnt
);
364 hres
= IDispatchEx_GetTypeInfo(dispex
, 0, 0, &typeinfo
);
365 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfo failed: %08x\n", hres
);
367 if(SUCCEEDED(hres
)) {
370 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &type_attr
);
371 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeAttr failed: %08x\n", hres
);
372 ok_(__FILE__
,line
) (IsEqualGUID(&type_attr
->guid
, diid
), "unexpected guid %s\n", dbgstr_guid(&type_attr
->guid
));
374 ITypeInfo_ReleaseTypeAttr(typeinfo
, type_attr
);
375 ITypeInfo_Release(typeinfo
);
378 IDispatchEx_Release(dispex
);
381 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
382 static IHTMLElement
*_get_elem_iface(unsigned line
, IUnknown
*unk
)
387 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
388 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLElement: %08x\n", hres
);
392 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
393 static IHTMLElement2
*_get_elem2_iface(unsigned line
, IUnknown
*unk
)
398 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement2
, (void**)&elem
);
399 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLElement2: %08x\n", hres
);
403 #define get_node_iface(u) _get_node_iface(__LINE__,u)
404 static IHTMLDOMNode
*_get_node_iface(unsigned line
, IUnknown
*unk
)
409 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
410 ok_(__FILE__
,line
) (hres
== S_OK
, "Coule not get IHTMLDOMNode: %08x\n", hres
);
414 #define get_img_iface(u) _get_img_iface(__LINE__,u)
415 static IHTMLImgElement
*_get_img_iface(unsigned line
, IUnknown
*unk
)
417 IHTMLImgElement
*img
;
420 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLImgElement
, (void**)&img
);
421 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLImgElement: %08x\n", hres
);
425 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
426 static void _test_node_name(unsigned line
, IUnknown
*unk
, const char *exname
)
428 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
432 hres
= IHTMLDOMNode_get_nodeName(node
, &name
);
433 IHTMLDOMNode_Release(node
);
434 ok_(__FILE__
, line
) (hres
== S_OK
, "get_nodeName failed: %08x\n", hres
);
435 ok_(__FILE__
, line
) (!strcmp_wa(name
, exname
), "got name: %s, expected %s\n", dbgstr_w(name
), exname
);
440 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
441 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
443 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
447 hres
= IHTMLElement_get_tagName(elem
, &tag
);
448 IHTMLElement_Release(elem
);
449 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
450 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", dbgstr_w(tag
), extag
);
455 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
456 static void _test_elem_type(unsigned line
, IUnknown
*unk
, elem_type_t type
)
458 _test_elem_tag(line
, unk
, elem_type_infos
[type
].tag
);
459 _test_ifaces(line
, unk
, elem_type_infos
[type
].iids
);
461 if(elem_type_infos
[type
].dispiid
)
462 _test_disp(line
, unk
, elem_type_infos
[type
].dispiid
);
465 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
466 static void _test_elem_attr(unsigned line
, IHTMLElement
*elem
, LPCWSTR name
, LPCWSTR exval
)
474 tmp
= SysAllocString(name
);
475 hres
= IHTMLElement_getAttribute(elem
, tmp
, 0, &value
);
477 ok_(__FILE__
,line
) (hres
== S_OK
, "getAttribute failed: %08x\n", hres
);
480 ok_(__FILE__
,line
) (V_VT(&value
) == VT_BSTR
, "vt=%d\n", V_VT(&value
));
481 ok_(__FILE__
,line
) (!lstrcmpW(exval
, V_BSTR(&value
)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value
)));
483 ok_(__FILE__
,line
) (V_VT(&value
) == VT_NULL
, "vt=%d\n", V_VT(&value
));
486 VariantClear(&value
);
489 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
490 static void _test_elem_offset(unsigned line
, IUnknown
*unk
)
492 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
496 hres
= IHTMLElement_get_offsetTop(elem
, &l
);
497 ok_(__FILE__
,line
) (hres
== S_OK
, "get_offsetTop failed: %08x\n", hres
);
499 hres
= IHTMLElement_get_offsetHeight(elem
, &l
);
500 ok_(__FILE__
,line
) (hres
== S_OK
, "get_offsetHeight failed: %08x\n", hres
);
502 IHTMLElement_Release(elem
);
505 static void test_doc_elem(IHTMLDocument2
*doc
)
508 IHTMLDocument3
*doc3
;
511 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
512 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres
);
514 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
515 IHTMLDocument3_Release(doc3
);
516 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
518 test_node_name((IUnknown
*)elem
, "HTML");
519 test_elem_tag((IUnknown
*)elem
, "HTML");
521 IHTMLElement_Release(elem
);
524 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
525 static IHTMLElement
*_get_doc_elem(unsigned line
, IHTMLDocument2
*doc
)
528 IHTMLDocument3
*doc3
;
531 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
532 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 interface: %08x\n", hres
);
533 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
534 ok_(__FILE__
,line
) (hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
535 IHTMLDocument3_Release(doc3
);
540 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
541 static void _test_option_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
546 hres
= IHTMLOptionElement_get_text(option
, &bstr
);
547 ok_(__FILE__
,line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
548 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, text
), "text=%s\n", dbgstr_w(bstr
));
552 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
553 static void _test_option_put_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
559 hres
= IHTMLOptionElement_put_text(option
, bstr
);
561 ok(hres
== S_OK
, "put_text failed: %08x\n", hres
);
563 _test_option_text(line
, option
, text
);
566 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
567 static void _test_option_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
572 hres
= IHTMLOptionElement_get_value(option
, &bstr
);
573 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
574 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, value
), "value=%s\n", dbgstr_w(bstr
));
578 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
579 static void _test_option_put_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
584 bstr
= a2bstr(value
);
585 hres
= IHTMLOptionElement_put_value(option
, bstr
);
587 ok(hres
== S_OK
, "put_value failed: %08x\n", hres
);
589 _test_option_value(line
, option
, value
);
592 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
593 static IHTMLOptionElement
*_create_option_elem(unsigned line
, IHTMLDocument2
*doc
,
594 const char *txt
, const char *val
)
596 IHTMLOptionElementFactory
*factory
;
597 IHTMLOptionElement
*option
;
598 IHTMLWindow2
*window
;
599 VARIANT text
, value
, empty
;
602 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
603 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
605 hres
= IHTMLWindow2_get_Option(window
, &factory
);
606 IHTMLWindow2_Release(window
);
607 ok_(__FILE__
,line
) (hres
== S_OK
, "get_Option failed: %08x\n", hres
);
609 V_VT(&text
) = VT_BSTR
;
610 V_BSTR(&text
) = a2bstr(txt
);
611 V_VT(&value
) = VT_BSTR
;
612 V_BSTR(&value
) = a2bstr(val
);
613 V_VT(&empty
) = VT_EMPTY
;
615 hres
= IHTMLOptionElementFactory_create(factory
, text
, value
, empty
, empty
, &option
);
616 ok_(__FILE__
,line
) (hres
== S_OK
, "create failed: %08x\n", hres
);
618 IHTMLOptionElementFactory_Release(factory
);
620 VariantClear(&value
);
622 _test_option_text(line
, option
, txt
);
623 _test_option_value(line
, option
, val
);
628 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
629 static void _test_select_length(unsigned line
, IHTMLSelectElement
*select
, long length
)
631 long len
= 0xdeadbeef;
634 hres
= IHTMLSelectElement_get_length(select
, &len
);
635 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
636 ok_(__FILE__
,line
) (len
== length
, "len=%ld, expected %ld\n", len
, length
);
639 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
640 static void _test_select_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
642 long idx
= 0xdeadbeef;
645 hres
= IHTMLSelectElement_get_selectedIndex(select
, &idx
);
646 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
647 ok_(__FILE__
,line
) (idx
== index
, "idx=%ld, expected %ld\n", idx
, index
);
650 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
651 static void _test_select_put_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
655 hres
= IHTMLSelectElement_put_selectedIndex(select
, index
);
656 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
657 _test_select_selidx(line
, select
, index
);
660 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
661 static void _test_select_value(unsigned line
, IHTMLSelectElement
*select
, const char *exval
)
666 hres
= IHTMLSelectElement_get_value(select
, &val
);
667 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
669 ok_(__FILE__
,line
) (!strcmp_wa(val
, exval
), "unexpected value %s\n", dbgstr_w(val
));
671 ok_(__FILE__
,line
) (val
== NULL
, "val=%s, expected NULL\n", dbgstr_w(val
));
674 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
675 static void _test_select_set_value(unsigned line
, IHTMLSelectElement
*select
, const char *val
)
681 hres
= IHTMLSelectElement_put_value(select
, bstr
);
683 ok_(__FILE__
,line
) (hres
== S_OK
, "put_value failed: %08x\n", hres
);
686 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
687 static void _test_select_type(unsigned line
, IHTMLSelectElement
*select
, const char *extype
)
692 hres
= IHTMLSelectElement_get_type(select
, &type
);
693 ok_(__FILE__
,line
) (hres
== S_OK
, "get_type failed: %08x\n", hres
);
694 ok_(__FILE__
,line
) (!strcmp_wa(type
, extype
), "type=%s, expected %s\n", dbgstr_w(type
), extype
);
697 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
698 static void _test_range_text(unsigned line
, IHTMLTxtRange
*range
, const char *extext
)
703 hres
= IHTMLTxtRange_get_text(range
, &text
);
704 ok_(__FILE__
, line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
707 ok_(__FILE__
, line
) (text
!= NULL
, "text == NULL\n");
708 ok_(__FILE__
, line
) (!strcmp_wa(text
, extext
), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text
), extext
);
710 ok_(__FILE__
, line
) (text
== NULL
, "text=\"%s\", expected NULL\n", dbgstr_w(text
));
717 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
718 static void _test_range_collapse(unsigned line
, IHTMLTxtRange
*range
, BOOL b
)
722 hres
= IHTMLTxtRange_collapse(range
, b
);
723 ok_(__FILE__
, line
) (hres
== S_OK
, "collapse failed: %08x\n", hres
);
724 _test_range_text(line
, range
, NULL
);
727 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
728 static void _test_range_expand(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
,
729 VARIANT_BOOL exb
, const char *extext
)
731 VARIANT_BOOL b
= 0xe0e0;
734 hres
= IHTMLTxtRange_expand(range
, unit
, &b
);
735 ok_(__FILE__
,line
) (hres
== S_OK
, "expand failed: %08x\n", hres
);
736 ok_(__FILE__
,line
) (b
== exb
, "b=%x, expected %x\n", b
, exb
);
737 _test_range_text(line
, range
, extext
);
740 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
741 static void _test_range_move(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
746 hres
= IHTMLTxtRange_move(range
, unit
, cnt
, &c
);
747 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
748 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
749 _test_range_text(line
, range
, NULL
);
752 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
753 static void _test_range_movestart(unsigned line
, IHTMLTxtRange
*range
,
754 LPWSTR unit
, long cnt
, long excnt
)
759 hres
= IHTMLTxtRange_moveStart(range
, unit
, cnt
, &c
);
760 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
761 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
764 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
765 static void _test_range_moveend(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
770 hres
= IHTMLTxtRange_moveEnd(range
, unit
, cnt
, &c
);
771 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
772 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
775 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
776 static void _test_range_put_text(unsigned line
, IHTMLTxtRange
*range
, const char *text
)
779 BSTR bstr
= a2bstr(text
);
781 hres
= IHTMLTxtRange_put_text(range
, bstr
);
782 ok_(__FILE__
,line
) (hres
== S_OK
, "put_text failed: %08x\n", hres
);
784 _test_range_text(line
, range
, NULL
);
787 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
788 static void _test_range_inrange(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
794 hres
= IHTMLTxtRange_inRange(range1
, range2
, &b
);
795 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
796 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
799 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
800 static void _test_range_isequal(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
806 hres
= IHTMLTxtRange_isEqual(range1
, range2
, &b
);
807 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
808 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
811 hres
= IHTMLTxtRange_isEqual(range2
, range1
, &b
);
812 ok_(__FILE__
,line
) (hres
== S_OK
, "(2->1) isEqual failed: %08x\n", hres
);
813 ok_(__FILE__
,line
) (b
== exb
, "(2->1) b=%x, expected %x\n", b
, exb
);
816 test_range_inrange(range1
, range2
, VARIANT_TRUE
);
817 test_range_inrange(range2
, range1
, VARIANT_TRUE
);
821 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
822 static void _test_range_parent(unsigned line
, IHTMLTxtRange
*range
, elem_type_t type
)
827 hres
= IHTMLTxtRange_parentElement(range
, &elem
);
828 ok_(__FILE__
,line
) (hres
== S_OK
, "parentElement failed: %08x\n", hres
);
830 _test_elem_type(line
, (IUnknown
*)elem
, type
);
832 IHTMLElement_Release(elem
);
835 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
836 static void _test_elem_collection(unsigned line
, IUnknown
*unk
,
837 const elem_type_t
*elem_types
, long exlen
)
839 IHTMLElementCollection
*col
;
846 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElementCollection
, (void**)&col
);
847 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
849 test_disp((IUnknown
*)col
, &DIID_DispHTMLElementCollection
);
851 hres
= IHTMLElementCollection_get_length(col
, &len
);
852 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
853 ok_(__FILE__
,line
) (len
== exlen
, "len=%ld, expected %ld\n", len
, exlen
);
858 V_VT(&index
) = VT_EMPTY
;
861 for(i
=0; i
<len
; i
++) {
863 disp
= (void*)0xdeadbeef;
864 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
865 ok_(__FILE__
,line
) (hres
== S_OK
, "item(%d) failed: %08x\n", i
, hres
);
866 ok_(__FILE__
,line
) (disp
!= NULL
, "item returned NULL\n");
867 if(FAILED(hres
) || !disp
)
870 _test_elem_type(line
, (IUnknown
*)disp
, elem_types
[i
]);
871 IDispatch_Release(disp
);
875 disp
= (void*)0xdeadbeef;
876 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
877 ok_(__FILE__
,line
) (hres
== S_OK
, "item failed: %08x\n", hres
);
878 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
881 disp
= (void*)0xdeadbeef;
882 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
883 ok_(__FILE__
,line
) (hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
884 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
886 IHTMLElementCollection_Release(col
);
889 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
890 static void _test_elem_getelembytag(unsigned line
, IUnknown
*unk
, elem_type_t type
, long exlen
)
892 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
893 IHTMLElementCollection
*col
= NULL
;
894 elem_type_t
*types
= NULL
;
899 tmp
= a2bstr(elem_type_infos
[type
].tag
);
900 hres
= IHTMLElement2_getElementsByTagName(elem
, tmp
, &col
);
902 IHTMLElement2_Release(elem
);
903 ok_(__FILE__
,line
) (hres
== S_OK
, "getElementByTagName failed: %08x\n", hres
);
904 ok_(__FILE__
,line
) (col
!= NULL
, "col == NULL\n");
907 types
= HeapAlloc(GetProcessHeap(), 0, exlen
*sizeof(elem_type_t
));
908 for(i
=0; i
<exlen
; i
++)
912 _test_elem_collection(line
, (IUnknown
*)col
, types
, exlen
);
914 HeapFree(GetProcessHeap(), 0, types
);
917 #define get_first_child(n) _get_first_child(__LINE__,n)
918 static IHTMLDOMNode
*_get_first_child(unsigned line
, IUnknown
*unk
)
920 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
921 IHTMLDOMNode
*child
= NULL
;
924 hres
= IHTMLDOMNode_get_firstChild(node
, &child
);
925 IHTMLDOMNode_Release(node
);
926 ok_(__FILE__
,line
) (hres
== S_OK
, "get_firstChild failed: %08x\n", hres
);
931 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
932 static void _test_node_has_child(unsigned line
, IUnknown
*unk
, VARIANT_BOOL exb
)
934 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
935 VARIANT_BOOL b
= 0xdead;
938 hres
= IHTMLDOMNode_hasChildNodes(node
, &b
);
939 ok_(__FILE__
,line
) (hres
== S_OK
, "hasChildNodes failed: %08x\n", hres
);
940 ok_(__FILE__
,line
) (b
== exb
, "hasChildNodes=%x, expected %x\n", b
, exb
);
942 IHTMLDOMNode_Release(node
);
945 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
946 static IHTMLDOMNode
*_test_node_get_parent(unsigned line
, IUnknown
*unk
)
948 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
949 IHTMLDOMNode
*parent
;
952 hres
= IHTMLDOMNode_get_parentNode(node
, &parent
);
953 IHTMLDOMNode_Release(node
);
954 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentNode failed: %08x\n", hres
);
959 #define get_node_type(n) _get_node_type(__LINE__,n)
960 static long _get_node_type(unsigned line
, IUnknown
*unk
)
962 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
966 hres
= IHTMLDOMNode_get_nodeType(node
, &type
);
967 ok(hres
== S_OK
, "get_nodeType failed: %08x\n", hres
);
969 IHTMLDOMNode_Release(node
);
974 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
975 static IHTMLElement
*_test_elem_get_parent(unsigned line
, IUnknown
*unk
)
977 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
978 IHTMLElement
*parent
;
981 hres
= IHTMLElement_get_parentElement(elem
, &parent
);
982 IHTMLElement_Release(elem
);
983 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
988 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
989 static long _elem_get_scroll_height(unsigned line
, IUnknown
*unk
)
991 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
992 IHTMLTextContainer
*txtcont
;
993 long l
= -1, l2
= -1;
996 hres
= IHTMLElement2_get_scrollHeight(elem
, &l
);
997 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollHeight failed: %08x\n", hres
);
998 IHTMLElement2_Release(elem
);
1000 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1001 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1003 hres
= IHTMLTextContainer_get_scrollHeight(txtcont
, &l2
);
1004 IHTMLTextContainer_Release(txtcont
);
1005 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2
);
1006 ok_(__FILE__
,line
) (l
== l2
, "unexpected height %ld, expected %ld\n", l2
, l
);
1011 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1012 static long _elem_get_scroll_width(unsigned line
, IUnknown
*unk
)
1014 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1015 IHTMLTextContainer
*txtcont
;
1016 long l
= -1, l2
= -1;
1019 hres
= IHTMLElement2_get_scrollWidth(elem
, &l
);
1020 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollWidth failed: %08x\n", hres
);
1021 IHTMLElement2_Release(elem
);
1023 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1024 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1026 hres
= IHTMLTextContainer_get_scrollWidth(txtcont
, &l2
);
1027 IHTMLTextContainer_Release(txtcont
);
1028 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2
);
1029 ok_(__FILE__
,line
) (l
== l2
, "unexpected width %ld, expected %ld\n", l2
, l
);
1034 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1035 static long _elem_get_scroll_top(unsigned line
, IUnknown
*unk
)
1037 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1038 IHTMLTextContainer
*txtcont
;
1039 long l
= -1, l2
= -1;
1042 hres
= IHTMLElement2_get_scrollTop(elem
, &l
);
1043 ok_(__FILE__
,line
) (hres
== S_OK
, "get_scrollTop failed: %08x\n", hres
);
1044 IHTMLElement2_Release(elem
);
1046 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLTextContainer
, (void**)&txtcont
);
1047 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLTextContainer: %08x\n", hres
);
1049 hres
= IHTMLTextContainer_get_scrollTop(txtcont
, &l2
);
1050 IHTMLTextContainer_Release(txtcont
);
1051 ok_(__FILE__
,line
) (hres
== S_OK
, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2
);
1052 ok_(__FILE__
,line
) (l
== l2
, "unexpected top %ld, expected %ld\n", l2
, l
);
1057 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1058 static void _test_img_set_src(unsigned line
, IUnknown
*unk
, const char *src
)
1060 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1065 hres
= IHTMLImgElement_put_src(img
, tmp
);
1066 IHTMLImgElement_Release(img
);
1068 ok_(__FILE__
,line
) (hres
== S_OK
, "put_src failed: %08x\n", hres
);
1071 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1072 static void _test_img_alt(unsigned line
, IUnknown
*unk
, const char *exalt
)
1074 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1078 hres
= IHTMLImgElement_get_alt(img
, &alt
);
1079 ok_(__FILE__
,line
) (hres
== S_OK
, "get_alt failed: %08x\n", hres
);
1081 ok_(__FILE__
,line
) (!strcmp_wa(alt
, exalt
), "inexopected alt %s\n", dbgstr_w(alt
));
1083 ok_(__FILE__
,line
) (!alt
, "alt != NULL\n");
1087 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1088 static void _test_img_set_alt(unsigned line
, IUnknown
*unk
, const char *alt
)
1090 IHTMLImgElement
*img
= _get_img_iface(line
, unk
);
1095 hres
= IHTMLImgElement_put_alt(img
, tmp
);
1096 ok_(__FILE__
,line
) (hres
== S_OK
, "get_alt failed: %08x\n", hres
);
1099 _test_img_alt(line
, unk
, alt
);
1102 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1103 static void _test_input_get_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL exb
)
1105 VARIANT_BOOL disabled
= 100;
1108 hres
= IHTMLInputElement_get_disabled(input
, &disabled
);
1109 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
1110 ok_(__FILE__
,line
) (disabled
== exb
, "disabled=%x, expected %x\n", disabled
, exb
);
1113 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1114 static void _test_input_set_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL b
)
1118 hres
= IHTMLInputElement_put_disabled(input
, b
);
1119 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
1121 _test_input_get_disabled(line
, input
, b
);
1124 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1125 static void _test_input_value(unsigned line
, IUnknown
*unk
, const char *exval
)
1127 IHTMLInputElement
*input
;
1131 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLInputElement
, (void**)&input
);
1132 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1136 hres
= IHTMLInputElement_get_value(input
, &bstr
);
1137 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
1139 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, exval
), "value=%s\n", dbgstr_w(bstr
));
1141 ok_(__FILE__
,line
) (!exval
, "exval != NULL\n");
1142 SysFreeString(bstr
);
1143 IHTMLInputElement_Release(input
);
1146 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1147 static void _test_input_put_value(unsigned line
, IUnknown
*unk
, const char *val
)
1149 IHTMLInputElement
*input
;
1153 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLInputElement
, (void**)&input
);
1154 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1159 hres
= IHTMLInputElement_get_value(input
, &bstr
);
1160 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
1161 SysFreeString(bstr
);
1162 IHTMLInputElement_Release(input
);
1165 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1166 static IHTMLDOMChildrenCollection
*_get_child_nodes(unsigned line
, IUnknown
*unk
)
1168 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1169 IHTMLDOMChildrenCollection
*col
= NULL
;
1173 hres
= IHTMLDOMNode_get_childNodes(node
, &disp
);
1174 IHTMLDOMNode_Release(node
);
1175 ok_(__FILE__
,line
) (hres
== S_OK
, "get_childNodes failed: %08x\n", hres
);
1179 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMChildrenCollection
, (void**)&col
);
1180 IDispatch_Release(disp
);
1181 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres
);
1186 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1187 static void _test_elem_class(unsigned line
, IUnknown
*unk
, const char *exclass
)
1189 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1190 BSTR
class = (void*)0xdeadbeef;
1193 hres
= IHTMLElement_get_className(elem
, &class);
1194 IHTMLElement_Release(elem
);
1195 ok_(__FILE__
,line
) (hres
== S_OK
, "get_className failed: %08x\n", hres
);
1197 ok_(__FILE__
,line
) (!strcmp_wa(class, exclass
), "unexpected className %s\n", dbgstr_w(class));
1199 ok_(__FILE__
,line
) (!class, "class != NULL\n");
1200 SysFreeString(class);
1203 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1204 static void _test_elem_tabindex(unsigned line
, IUnknown
*unk
, short exindex
)
1206 IHTMLElement2
*elem2
= _get_elem2_iface(line
, unk
);
1210 hres
= IHTMLElement2_get_tabIndex(elem2
, &index
);
1211 IHTMLElement2_Release(elem2
);
1212 ok_(__FILE__
,line
) (hres
== S_OK
, "get_tabIndex failed: %08x\n", hres
);
1213 ok_(__FILE__
,line
) (index
== exindex
, "unexpected index %d\n", index
);
1216 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1217 static void _test_elem_set_tabindex(unsigned line
, IUnknown
*unk
, short index
)
1219 IHTMLElement2
*elem2
= _get_elem2_iface(line
, unk
);
1222 hres
= IHTMLElement2_put_tabIndex(elem2
, index
);
1223 IHTMLElement2_Release(elem2
);
1224 ok_(__FILE__
,line
) (hres
== S_OK
, "get_tabIndex failed: %08x\n", hres
);
1226 _test_elem_tabindex(line
, unk
, index
);
1229 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1230 static void _test_elem_set_class(unsigned line
, IUnknown
*unk
, const char *class)
1232 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1236 tmp
= class ? a2bstr(class) : NULL
;
1237 hres
= IHTMLElement_put_className(elem
, tmp
);
1238 IHTMLElement_Release(elem
);
1239 ok_(__FILE__
,line
) (hres
== S_OK
, "put_className failed: %08x\n", hres
);
1242 _test_elem_class(line
, unk
, class);
1245 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1246 static IHTMLDOMNode
*_get_child_item(unsigned line
, IHTMLDOMChildrenCollection
*col
, long idx
)
1248 IHTMLDOMNode
*node
= NULL
;
1252 hres
= IHTMLDOMChildrenCollection_item(col
, idx
, &disp
);
1253 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1255 node
= _get_node_iface(line
, (IUnknown
*)disp
);
1256 IDispatch_Release(disp
);
1261 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1262 static void _test_elem_id(unsigned line
, IUnknown
*unk
, const char *exid
)
1264 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1265 BSTR id
= (void*)0xdeadbeef;
1268 hres
= IHTMLElement_get_id(elem
, &id
);
1269 IHTMLElement_Release(elem
);
1270 ok_(__FILE__
,line
) (hres
== S_OK
, "get_id failed: %08x\n", hres
);
1273 ok_(__FILE__
,line
) (!strcmp_wa(id
, exid
), "unexpected id %s\n", dbgstr_w(id
));
1275 ok_(__FILE__
,line
) (!id
, "id=%s\n", dbgstr_w(id
));
1280 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1281 static void _test_elem_put_id(unsigned line
, IUnknown
*unk
, const char *new_id
)
1283 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1284 BSTR tmp
= a2bstr(new_id
);
1287 hres
= IHTMLElement_put_id(elem
, tmp
);
1288 IHTMLElement_Release(elem
);
1290 ok_(__FILE__
,line
) (hres
== S_OK
, "put_id failed: %08x\n", hres
);
1292 _test_elem_id(line
, unk
, new_id
);
1295 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1296 static void _test_elem_title(unsigned line
, IUnknown
*unk
, const char *extitle
)
1298 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1302 hres
= IHTMLElement_get_title(elem
, &title
);
1303 IHTMLElement_Release(elem
);
1304 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1306 ok_(__FILE__
,line
) (!strcmp_wa(title
, extitle
), "unexpected title %s\n", dbgstr_w(title
));
1308 ok_(__FILE__
,line
) (!title
, "title=%s, expected NULL\n", dbgstr_w(title
));
1310 SysFreeString(title
);
1313 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1314 static void _test_elem_set_title(unsigned line
, IUnknown
*unk
, const char *title
)
1316 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
1320 tmp
= a2bstr(title
);
1321 hres
= IHTMLElement_put_title(elem
, tmp
);
1322 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1324 IHTMLElement_Release(elem
);
1328 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1329 static void _test_node_get_value_str(unsigned line
, IUnknown
*unk
, const char *exval
)
1331 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1335 hres
= IHTMLDOMNode_get_nodeValue(node
, &var
);
1336 IHTMLDOMNode_Release(node
);
1337 ok_(__FILE__
,line
) (hres
== S_OK
, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres
);
1340 ok_(__FILE__
,line
) (V_VT(&var
) == VT_BSTR
, "vt=%d\n", V_VT(&var
));
1341 ok_(__FILE__
,line
) (!strcmp_wa(V_BSTR(&var
), exval
), "unexpected value %s\n", dbgstr_w(V_BSTR(&var
)));
1343 ok_(__FILE__
,line
) (V_VT(&var
) == VT_NULL
, "vt=%d, expected VT_NULL\n", V_VT(&var
));
1349 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1350 static void _test_node_put_value_str(unsigned line
, IUnknown
*unk
, const char *val
)
1352 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1356 V_VT(&var
) = VT_BSTR
;
1357 V_BSTR(&var
) = a2bstr(val
);
1359 hres
= IHTMLDOMNode_put_nodeValue(node
, var
);
1360 ok_(__FILE__
,line
) (hres
== S_OK
, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres
);
1361 IHTMLDOMNode_Release(node
);
1365 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1366 static void _test_elem_client_size(unsigned line
, IUnknown
*unk
)
1368 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
1372 hres
= IHTMLElement2_get_clientWidth(elem
, &l
);
1373 ok_(__FILE__
,line
) (hres
== S_OK
, "get_clientWidth failed: %08x\n", hres
);
1374 hres
= IHTMLElement2_get_clientHeight(elem
, &l
);
1375 ok_(__FILE__
,line
) (hres
== S_OK
, "get_clientHeight failed: %08x\n", hres
);
1377 IHTMLElement2_Release(elem
);
1380 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1381 static IHTMLElement
*_test_create_elem(unsigned line
, IHTMLDocument2
*doc
, const char *tag
)
1383 IHTMLElement
*elem
= NULL
;
1388 hres
= IHTMLDocument2_createElement(doc
, tmp
, &elem
);
1389 ok_(__FILE__
,line
) (hres
== S_OK
, "createElement failed: %08x\n", hres
);
1390 ok_(__FILE__
,line
) (elem
!= NULL
, "elem == NULL\n");
1395 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1396 static IHTMLDOMNode
*_test_create_text(unsigned line
, IHTMLDocument2
*doc
, const char *text
)
1398 IHTMLDocument3
*doc3
;
1399 IHTMLDOMNode
*node
= NULL
;
1403 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
1404 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3: %08x\n", hres
);
1407 hres
= IHTMLDocument3_createTextNode(doc3
, tmp
, &node
);
1408 IHTMLDocument3_Release(doc3
);
1409 ok_(__FILE__
,line
) (hres
== S_OK
, "createElement failed: %08x\n", hres
);
1410 ok_(__FILE__
,line
) (node
!= NULL
, "node == NULL\n");
1415 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1416 static IHTMLDOMNode
*_test_node_append_child(unsigned line
, IUnknown
*node_unk
, IUnknown
*child_unk
)
1418 IHTMLDOMNode
*node
= _get_node_iface(line
, node_unk
);
1419 IHTMLDOMNode
*child
= _get_node_iface(line
, child_unk
);
1420 IHTMLDOMNode
*new_child
= NULL
;
1423 hres
= IHTMLDOMNode_appendChild(node
, child
, &new_child
);
1424 ok_(__FILE__
,line
) (hres
== S_OK
, "appendChild failed: %08x\n", hres
);
1425 ok_(__FILE__
,line
) (new_child
!= NULL
, "new_child == NULL\n");
1426 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1428 IHTMLDOMNode_Release(node
);
1429 IHTMLDOMNode_Release(child
);
1434 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1435 static void _test_node_remove_child(unsigned line
, IUnknown
*unk
, IHTMLDOMNode
*child
)
1437 IHTMLDOMNode
*node
= _get_node_iface(line
, unk
);
1438 IHTMLDOMNode
*new_node
= NULL
;
1441 hres
= IHTMLDOMNode_removeChild(node
, child
, &new_node
);
1442 ok_(__FILE__
,line
) (hres
== S_OK
, "appendChild failed: %08x\n", hres
);
1443 ok_(__FILE__
,line
) (new_node
!= NULL
, "new_node == NULL\n");
1444 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1446 IHTMLDOMNode_Release(node
);
1447 IHTMLDOMNode_Release(new_node
);
1450 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1451 static void _test_doc_title(unsigned line
, IHTMLDocument2
*doc
, const char *extitle
)
1456 hres
= IHTMLDocument2_get_title(doc
, &title
);
1457 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1458 ok_(__FILE__
,line
) (!strcmp_wa(title
, extitle
), "unexpected title %s\n", dbgstr_w(title
));
1459 SysFreeString(title
);
1462 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1463 static void _test_doc_set_title(unsigned line
, IHTMLDocument2
*doc
, const char *title
)
1468 tmp
= a2bstr(title
);
1469 hres
= IHTMLDocument2_put_title(doc
, tmp
);
1470 ok_(__FILE__
,line
) (hres
== S_OK
, "get_title failed: %08x\n", hres
);
1474 static void test_elem_col_item(IHTMLElementCollection
*col
, LPCWSTR n
,
1475 const elem_type_t
*elem_types
, long len
)
1478 VARIANT name
, index
;
1482 V_VT(&index
) = VT_EMPTY
;
1483 V_VT(&name
) = VT_BSTR
;
1484 V_BSTR(&name
) = SysAllocString(n
);
1486 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1487 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1489 test_elem_collection((IUnknown
*)disp
, elem_types
, len
);
1490 IDispatch_Release(disp
);
1491 ok(hres
== S_OK
, "Could not get IHTMLElementCollection interface: %08x\n", hres
);
1495 V_VT(&index
) = VT_I4
;
1497 for(i
=0; i
<len
; i
++) {
1499 disp
= (void*)0xdeadbeef;
1500 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1501 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1502 ok(disp
!= NULL
, "disp == NULL\n");
1503 if(FAILED(hres
) || !disp
)
1506 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
1508 IDispatch_Release(disp
);
1512 disp
= (void*)0xdeadbeef;
1513 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1514 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1515 ok(disp
== NULL
, "disp != NULL\n");
1518 disp
= (void*)0xdeadbeef;
1519 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1520 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1521 ok(disp
== NULL
, "disp != NULL\n");
1524 SysFreeString(V_BSTR(&name
));
1527 static IHTMLElement
*get_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
, BOOL expect_success
)
1529 IHTMLElementCollection
*col
;
1531 IDispatch
*disp
= (void*)0xdeadbeef;
1532 VARIANT name
, index
;
1535 hres
= IHTMLDocument2_get_all(doc
, &col
);
1536 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1537 ok(col
!= NULL
, "col == NULL\n");
1538 if(FAILED(hres
) || !col
)
1541 V_VT(&index
) = VT_EMPTY
;
1542 V_VT(&name
) = VT_BSTR
;
1543 V_BSTR(&name
) = SysAllocString(id
);
1545 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
1546 IHTMLElementCollection_Release(col
);
1547 SysFreeString(V_BSTR(&name
));
1548 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1549 if(!expect_success
) {
1550 ok(disp
== NULL
, "disp != NULL\n");
1554 ok(disp
!= NULL
, "disp == NULL\n");
1558 elem
= get_elem_iface((IUnknown
*)disp
);
1559 IDispatch_Release(disp
);
1564 static IHTMLElement
*get_doc_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
)
1566 IHTMLDocument3
*doc3
;
1571 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
1572 ok(hres
== S_OK
, "Could not get IHTMLDocument3 iface: %08x\n", hres
);
1574 tmp
= SysAllocString(id
);
1575 hres
= IHTMLDocument3_getElementById(doc3
, tmp
, &elem
);
1577 ok(hres
== S_OK
, "getElementById(%s) failed: %08x\n", dbgstr_w(id
), hres
);
1579 IHTMLDocument3_Release(doc3
);
1584 static void test_select_elem(IHTMLSelectElement
*select
)
1586 test_select_type(select
, "select-one");
1587 test_select_length(select
, 2);
1588 test_select_selidx(select
, 0);
1589 test_select_put_selidx(select
, 1);
1591 test_select_set_value(select
, "val1");
1592 test_select_value(select
, "val1");
1595 static void test_create_option_elem(IHTMLDocument2
*doc
)
1597 IHTMLOptionElement
*option
;
1599 option
= create_option_elem(doc
, "test text", "test value");
1601 test_option_put_text(option
, "new text");
1602 test_option_put_value(option
, "new value");
1604 IHTMLOptionElement_Release(option
);
1607 static IHTMLTxtRange
*test_create_body_range(IHTMLDocument2
*doc
)
1609 IHTMLBodyElement
*body
;
1610 IHTMLTxtRange
*range
;
1614 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1615 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1617 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
1618 IHTMLElement_Release(elem
);
1620 hres
= IHTMLBodyElement_createTextRange(body
, &range
);
1621 IHTMLBodyElement_Release(body
);
1622 ok(hres
== S_OK
, "createTextRange failed: %08x\n", hres
);
1627 static void test_txtrange(IHTMLDocument2
*doc
)
1629 IHTMLTxtRange
*body_range
, *range
, *range2
;
1630 IHTMLSelectionObject
*selection
;
1631 IDispatch
*disp_range
;
1634 body_range
= test_create_body_range(doc
);
1636 test_range_text(body_range
, "test abc 123\r\nit's text");
1638 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1639 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1641 hres
= IHTMLTxtRange_duplicate(body_range
, &range2
);
1642 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1643 test_range_isequal(range
, range2
, VARIANT_TRUE
);
1645 test_range_text(range
, "test abc 123\r\nit's text");
1646 test_range_text(body_range
, "test abc 123\r\nit's text");
1648 test_range_collapse(range
, TRUE
);
1649 test_range_isequal(range
, range2
, VARIANT_FALSE
);
1650 test_range_inrange(range
, range2
, VARIANT_FALSE
);
1651 test_range_inrange(range2
, range
, VARIANT_TRUE
);
1652 IHTMLTxtRange_Release(range2
);
1654 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1655 test_range_expand(range
, wordW
, VARIANT_FALSE
, "test ");
1656 test_range_move(range
, characterW
, 2, 2);
1657 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1659 test_range_collapse(range
, FALSE
);
1660 test_range_expand(range
, wordW
, VARIANT_TRUE
, "abc ");
1662 test_range_collapse(range
, FALSE
);
1663 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1664 test_range_expand(range
, wordW
, VARIANT_FALSE
, "123");
1665 test_range_move(range
, characterW
, 2, 2);
1666 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1667 test_range_moveend(range
, characterW
, -5, -5);
1668 test_range_text(range
, NULL
);
1669 test_range_moveend(range
, characterW
, 3, 3);
1670 test_range_text(range
, "c 1");
1671 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "test abc 123\r\nit's text");
1672 test_range_collapse(range
, TRUE
);
1673 test_range_move(range
, characterW
, 4, 4);
1674 test_range_moveend(range
, characterW
, 1, 1);
1675 test_range_text(range
, " ");
1676 test_range_move(range
, wordW
, 1, 1);
1677 test_range_moveend(range
, characterW
, 2, 2);
1678 test_range_text(range
, "ab");
1680 IHTMLTxtRange_Release(range
);
1682 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1683 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1685 test_range_text(range
, "test abc 123\r\nit's text");
1686 test_range_move(range
, characterW
, 3, 3);
1687 test_range_moveend(range
, characterW
, 1, 1);
1688 test_range_text(range
, "t");
1689 test_range_moveend(range
, characterW
, 3, 3);
1690 test_range_text(range
, "t ab");
1691 test_range_moveend(range
, characterW
, -2, -2);
1692 test_range_text(range
, "t ");
1693 test_range_move(range
, characterW
, 6, 6);
1694 test_range_moveend(range
, characterW
, 3, 3);
1695 test_range_text(range
, "123");
1696 test_range_moveend(range
, characterW
, 2, 2);
1697 test_range_text(range
, "123\r\ni");
1699 IHTMLTxtRange_Release(range
);
1701 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1702 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1704 test_range_move(range
, wordW
, 1, 1);
1705 test_range_moveend(range
, characterW
, 2, 2);
1706 test_range_text(range
, "ab");
1708 test_range_move(range
, characterW
, -2, -2);
1709 test_range_moveend(range
, characterW
, 2, 2);
1710 test_range_text(range
, "t ");
1712 test_range_move(range
, wordW
, 3, 3);
1713 test_range_move(range
, wordW
, -2, -2);
1714 test_range_moveend(range
, characterW
, 2, 2);
1715 test_range_text(range
, "ab");
1717 test_range_move(range
, characterW
, -6, -5);
1718 test_range_moveend(range
, characterW
, -1, 0);
1719 test_range_moveend(range
, characterW
, -6, 0);
1720 test_range_move(range
, characterW
, 2, 2);
1721 test_range_moveend(range
, characterW
, 2, 2);
1722 test_range_text(range
, "st");
1723 test_range_moveend(range
, characterW
, -6, -4);
1724 test_range_moveend(range
, characterW
, 2, 2);
1726 IHTMLTxtRange_Release(range
);
1728 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1729 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1731 test_range_move(range
, wordW
, 2, 2);
1732 test_range_moveend(range
, characterW
, 2, 2);
1733 test_range_text(range
, "12");
1735 test_range_move(range
, characterW
, 15, 14);
1736 test_range_move(range
, characterW
, -2, -2);
1737 test_range_moveend(range
, characterW
, 3, 2);
1738 test_range_text(range
, "t");
1739 test_range_moveend(range
, characterW
, -1, -1);
1740 test_range_text(range
, "t");
1741 test_range_expand(range
, wordW
, VARIANT_TRUE
, "text");
1742 test_range_move(range
, characterW
, -2, -2);
1743 test_range_moveend(range
, characterW
, 2, 2);
1744 test_range_text(range
, "s ");
1745 test_range_move(range
, characterW
, 100, 7);
1746 test_range_move(range
, wordW
, 1, 0);
1747 test_range_move(range
, characterW
, -2, -2);
1748 test_range_moveend(range
, characterW
, 3, 2);
1749 test_range_text(range
, "t");
1751 IHTMLTxtRange_Release(range
);
1753 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1754 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1756 test_range_collapse(range
, TRUE
);
1757 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1758 test_range_put_text(range
, "word");
1759 test_range_text(body_range
, "wordabc 123\r\nit's text");
1760 test_range_text(range
, NULL
);
1761 test_range_moveend(range
, characterW
, 3, 3);
1762 test_range_text(range
, "abc");
1763 test_range_movestart(range
, characterW
, -2, -2);
1764 test_range_text(range
, "rdabc");
1765 test_range_movestart(range
, characterW
, 3, 3);
1766 test_range_text(range
, "bc");
1767 test_range_movestart(range
, characterW
, 4, 4);
1768 test_range_text(range
, NULL
);
1769 test_range_movestart(range
, characterW
, -3, -3);
1770 test_range_text(range
, "c 1");
1771 test_range_movestart(range
, characterW
, -7, -6);
1772 test_range_text(range
, "wordabc 1");
1773 test_range_movestart(range
, characterW
, 100, 22);
1774 test_range_text(range
, NULL
);
1776 IHTMLTxtRange_Release(range
);
1777 IHTMLTxtRange_Release(body_range
);
1779 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1780 ok(hres
== S_OK
, "IHTMLDocument2_get_selection failed: %08x\n", hres
);
1782 hres
= IHTMLSelectionObject_createRange(selection
, &disp_range
);
1783 ok(hres
== S_OK
, "IHTMLSelectionObject_createRange failed: %08x\n", hres
);
1784 IHTMLSelectionObject_Release(selection
);
1786 hres
= IDispatch_QueryInterface(disp_range
, &IID_IHTMLTxtRange
, (void **)&range
);
1787 ok(hres
== S_OK
, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres
);
1788 IDispatch_Release(disp_range
);
1790 test_range_text(range
, NULL
);
1791 test_range_moveend(range
, characterW
, 3, 3);
1792 test_range_text(range
, "wor");
1793 test_range_parent(range
, ET_BODY
);
1794 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1795 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1796 test_range_move(range
, characterW
, 3, 3);
1797 test_range_expand(range
, wordW
, VARIANT_TRUE
, "wordabc ");
1798 test_range_moveend(range
, characterW
, -4, -4);
1799 test_range_put_text(range
, "abc def ");
1800 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "abc def abc 123\r\nit's text");
1801 test_range_move(range
, wordW
, 1, 1);
1802 test_range_movestart(range
, characterW
, -1, -1);
1803 test_range_text(range
, " ");
1804 test_range_move(range
, wordW
, 1, 1);
1805 test_range_moveend(range
, characterW
, 3, 3);
1806 test_range_text(range
, "def");
1807 test_range_put_text(range
, "xyz");
1808 test_range_moveend(range
, characterW
, 1, 1);
1809 test_range_move(range
, wordW
, 1, 1);
1810 test_range_moveend(range
, characterW
, 2, 2);
1811 test_range_text(range
, "ab");
1813 IHTMLTxtRange_Release(range
);
1816 static void test_txtrange2(IHTMLDocument2
*doc
)
1818 IHTMLTxtRange
*range
;
1820 range
= test_create_body_range(doc
);
1822 test_range_text(range
, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1823 test_range_move(range
, characterW
, 5, 5);
1824 test_range_moveend(range
, characterW
, 1, 1);
1825 test_range_text(range
, "2");
1826 test_range_move(range
, characterW
, -3, -3);
1827 test_range_moveend(range
, characterW
, 3, 3);
1828 test_range_text(range
, "c\r\n\r\n1");
1829 test_range_collapse(range
, VARIANT_FALSE
);
1830 test_range_moveend(range
, characterW
, 4, 4);
1831 test_range_text(range
, "23");
1832 test_range_moveend(range
, characterW
, 1, 1);
1833 test_range_text(range
, "23\r\n\r\n\r\nd");
1834 test_range_moveend(range
, characterW
, -1, -1);
1835 test_range_text(range
, "23");
1836 test_range_moveend(range
, characterW
, -1, -1);
1837 test_range_text(range
, "23");
1838 test_range_moveend(range
, characterW
, -2, -2);
1839 test_range_text(range
, "2");
1841 IHTMLTxtRange_Release(range
);
1844 static void test_compatmode(IHTMLDocument2
*doc
)
1846 IHTMLDocument5
*doc5
;
1850 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
1851 ok(hres
== S_OK
, "Could not get IHTMLDocument5 interface: %08x\n", hres
);
1855 hres
= IHTMLDocument5_get_compatMode(doc5
, &mode
);
1856 IHTMLDocument5_Release(doc5
);
1857 ok(hres
== S_OK
, "get_compatMode failed: %08x\n", hres
);
1858 ok(!strcmp_wa(mode
, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode
));
1859 SysFreeString(mode
);
1862 static void test_location(IHTMLDocument2
*doc
)
1864 IHTMLLocation
*location
, *location2
;
1868 hres
= IHTMLDocument2_get_location(doc
, &location
);
1869 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1871 hres
= IHTMLDocument2_get_location(doc
, &location2
);
1872 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1874 ok(location
== location2
, "location != location2\n");
1876 test_ifaces((IUnknown
*)location
, location_iids
);
1878 IHTMLLocation_Release(location2
);
1879 ref
= IHTMLLocation_Release(location
);
1880 ok(!ref
, "location chould be destroyed here\n");
1883 static void test_navigator(IHTMLDocument2
*doc
)
1885 IHTMLWindow2
*window
;
1886 IOmNavigator
*navigator
, *navigator2
;
1891 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1892 ok(hres
== S_OK
, "parentWidnow failed: %08x\n", hres
);
1894 hres
= IHTMLWindow2_get_navigator(window
, &navigator
);
1895 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1896 ok(navigator
!= NULL
, "navigator == NULL\n");
1897 test_disp((IUnknown
*)navigator
, &IID_IOmNavigator
);
1899 hres
= IHTMLWindow2_get_navigator(window
, &navigator2
);
1900 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1901 ok(navigator
!= navigator2
, "navigator2 != navihgator\n");
1903 IHTMLWindow2_Release(window
);
1904 IOmNavigator_Release(navigator2
);
1906 hres
= IOmNavigator_get_appCodeName(navigator
, &bstr
);
1907 ok(hres
== S_OK
, "get_appCodeName failed: %08x\n", hres
);
1908 ok(!strcmp_wa(bstr
, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr
));
1909 SysFreeString(bstr
);
1912 hres
= IOmNavigator_get_platform(navigator
, &bstr
);
1913 ok(hres
== S_OK
, "get_appMinorVersion failed: %08x\n", hres
);
1914 ok(!strcmp_wa(bstr
, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr
));
1915 SysFreeString(bstr
);
1917 ref
= IOmNavigator_Release(navigator
);
1918 ok(!ref
, "navigator should be destroyed here\n");
1921 static void test_default_style(IHTMLStyle
*style
)
1928 test_disp((IUnknown
*)style
, &DIID_DispHTMLStyle
);
1930 str
= (void*)0xdeadbeef;
1931 hres
= IHTMLStyle_get_fontFamily(style
, &str
);
1932 ok(hres
== S_OK
, "get_fontFamily failed: %08x\n", hres
);
1933 ok(!str
, "fontFamily = %s\n", dbgstr_w(str
));
1935 str
= (void*)0xdeadbeef;
1936 hres
= IHTMLStyle_get_fontWeight(style
, &str
);
1937 ok(hres
== S_OK
, "get_fontWeight failed: %08x\n", hres
);
1938 ok(!str
, "fontWeight = %s\n", dbgstr_w(str
));
1940 str
= (void*)0xdeadbeef;
1941 hres
= IHTMLStyle_get_display(style
, &str
);
1942 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
1943 ok(!str
, "display = %s\n", dbgstr_w(str
));
1945 str
= (void*)0xdeadbeef;
1946 hres
= IHTMLStyle_get_visibility(style
, &str
);
1947 ok(hres
== S_OK
, "get_visibility failed: %08x\n", hres
);
1948 ok(!str
, "visibility = %s\n", dbgstr_w(str
));
1951 hres
= IHTMLStyle_get_fontSize(style
, &v
);
1952 ok(hres
== S_OK
, "get_fontSize failed: %08x\n", hres
);
1953 ok(V_VT(&v
) == VT_BSTR
, "V_VT(fontSize) = %d\n", V_VT(&v
));
1954 ok(!V_BSTR(&v
), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v
)));
1957 hres
= IHTMLStyle_get_color(style
, &v
);
1958 ok(hres
== S_OK
, "get_color failed: %08x\n", hres
);
1959 ok(V_VT(&v
) == VT_BSTR
, "V_VT(color) = %d\n", V_VT(&v
));
1960 ok(!V_BSTR(&v
), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v
)));
1963 hres
= IHTMLStyle_get_textDecorationUnderline(style
, &b
);
1964 ok(hres
== S_OK
, "get_textDecorationUnderline failed: %08x\n", hres
);
1965 ok(b
== VARIANT_FALSE
, "textDecorationUnderline = %x\n", b
);
1968 hres
= IHTMLStyle_get_textDecorationLineThrough(style
, &b
);
1969 ok(hres
== S_OK
, "get_textDecorationLineThrough failed: %08x\n", hres
);
1970 ok(b
== VARIANT_FALSE
, "textDecorationLineThrough = %x\n", b
);
1972 V_VT(&v
) = VT_EMPTY
;
1973 hres
= IHTMLStyle_get_width(style
, &v
);
1974 ok(hres
== S_OK
, "get_width failed: %08x\n", hres
);
1975 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
1976 ok(!V_BSTR(&v
), "V_BSTR(v)=%p\n", V_BSTR(&v
));
1979 V_BSTR(&v
) = a2bstr("auto");
1980 hres
= IHTMLStyle_put_width(style
, v
);
1981 ok(hres
== S_OK
, "put_width failed: %08x\n", hres
);
1984 V_VT(&v
) = VT_EMPTY
;
1985 hres
= IHTMLStyle_get_width(style
, &v
);
1986 ok(hres
== S_OK
, "get_width failed: %08x\n", hres
);
1987 ok(V_VT(&v
) == VT_BSTR
, "V_VT(v)=%d\n", V_VT(&v
));
1988 ok(!strcmp_wa(V_BSTR(&v
), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v
)));
1992 static void test_default_selection(IHTMLDocument2
*doc
)
1994 IHTMLSelectionObject
*selection
;
1995 IHTMLTxtRange
*range
;
2000 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
2001 ok(hres
== S_OK
, "get_selection failed: %08x\n", hres
);
2003 hres
= IHTMLSelectionObject_get_type(selection
, &str
);
2004 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
2005 ok(!lstrcmpW(str
, noneW
), "type = %s\n", dbgstr_w(str
));
2008 hres
= IHTMLSelectionObject_createRange(selection
, &disp
);
2009 IHTMLSelectionObject_Release(selection
);
2010 ok(hres
== S_OK
, "createRange failed: %08x\n", hres
);
2012 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLTxtRange
, (void**)&range
);
2013 IDispatch_Release(disp
);
2014 ok(hres
== S_OK
, "Could not get IHTMLTxtRange interface: %08x\n", hres
);
2016 test_range_text(range
, NULL
);
2017 IHTMLTxtRange_Release(range
);
2020 static void test_default_body(IHTMLBodyElement
*body
)
2026 bstr
= (void*)0xdeadbeef;
2027 hres
= IHTMLBodyElement_get_background(body
, &bstr
);
2028 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2029 ok(bstr
== NULL
, "bstr != NULL\n");
2031 l
= elem_get_scroll_height((IUnknown
*)body
);
2032 ok(l
!= -1, "scrollHeight == -1\n");
2033 l
= elem_get_scroll_width((IUnknown
*)body
);
2034 ok(l
!= -1, "scrollWidth == -1\n");
2035 l
= elem_get_scroll_top((IUnknown
*)body
);
2036 ok(!l
, "scrollWidth = %ld\n", l
);
2039 static void test_body_funs(IHTMLBodyElement
*body
)
2041 static WCHAR sRed
[] = {'r','e','d',0};
2042 static WCHAR sRedbg
[] = {'#','f','f','0','0','0','0',0};
2047 hres
= IHTMLBodyElement_get_bgColor(body
, &vDefaultbg
);
2048 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2049 ok(V_VT(&vDefaultbg
) == VT_BSTR
, "bstr != NULL\n");
2051 V_VT(&vbg
) = VT_BSTR
;
2052 V_BSTR(&vbg
) = SysAllocString(sRed
);
2053 hres
= IHTMLBodyElement_put_bgColor(body
, vbg
);
2054 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2057 hres
= IHTMLBodyElement_get_bgColor(body
, &vbg
);
2058 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2059 ok(V_VT(&vDefaultbg
) == VT_BSTR
, "V_VT(&vDefaultbg) != VT_BSTR\n");
2060 ok(!lstrcmpW(V_BSTR(&vbg
), sRedbg
), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg
)));
2063 /* Restore Originial */
2064 hres
= IHTMLBodyElement_put_bgColor(body
, vDefaultbg
);
2065 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
2066 VariantClear(&vDefaultbg
);
2069 static void test_window(IHTMLDocument2
*doc
)
2071 IHTMLWindow2
*window
, *window2
, *self
;
2072 IHTMLDocument2
*doc2
= NULL
;
2076 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
2077 ok(hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
2078 test_ifaces((IUnknown
*)window
, window_iids
);
2079 test_disp((IUnknown
*)window
, &DIID_DispHTMLWindow2
);
2081 hres
= IHTMLWindow2_get_document(window
, &doc2
);
2082 ok(hres
== S_OK
, "get_document failed: %08x\n", hres
);
2083 ok(doc2
!= NULL
, "doc2 == NULL\n");
2085 IHTMLDocument_Release(doc2
);
2087 hres
= IHTMLWindow2_get_window(window
, &window2
);
2088 ok(hres
== S_OK
, "get_window failed: %08x\n", hres
);
2089 ok(window2
!= NULL
, "window2 == NULL\n");
2091 hres
= IHTMLWindow2_get_self(window
, &self
);
2092 ok(hres
== S_OK
, "get_window failed: %08x\n", hres
);
2093 ok(window2
!= NULL
, "self == NULL\n");
2095 ok(self
== window2
, "self != window2\n");
2097 IHTMLWindow2_Release(window2
);
2098 IHTMLWindow2_Release(self
);
2101 hres
= IHTMLDocument2_get_Script(doc
, &disp
);
2102 ok(hres
== S_OK
, "get_Script failed: %08x\n", hres
);
2103 ok(disp
== (void*)window
, "disp != window\n");
2104 IDispatch_Release(disp
);
2106 IHTMLWindow2_Release(window
);
2109 static void test_defaults(IHTMLDocument2
*doc
)
2111 IHTMLStyleSheetsCollection
*stylesheetcol
;
2112 IHTMLBodyElement
*body
;
2118 hres
= IHTMLDocument2_get_body(doc
, &elem
);
2119 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2121 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
2122 ok(hres
== S_OK
, "Could not get IHTMBodyElement: %08x\n", hres
);
2123 test_default_body(body
);
2124 test_body_funs(body
);
2125 IHTMLBodyElement_Release(body
);
2127 hres
= IHTMLElement_get_style(elem
, &style
);
2128 IHTMLElement_Release(elem
);
2129 ok(hres
== S_OK
, "get_style failed: %08x\n", hres
);
2131 test_default_style(style
);
2133 test_compatmode(doc
);
2135 test_navigator(doc
);
2137 IHTMLStyle_Release(style
);
2139 hres
= IHTMLDocument2_get_styleSheets(doc
, &stylesheetcol
);
2140 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
2143 hres
= IHTMLStyleSheetsCollection_get_length(stylesheetcol
, &l
);
2144 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2145 ok(l
== 0, "length = %ld\n", l
);
2147 IHTMLStyleSheetsCollection_Release(stylesheetcol
);
2149 test_default_selection(doc
);
2150 test_doc_title(doc
, "");
2153 static void test_stylesheet(IDispatch
*disp
)
2155 IHTMLStyleSheetRulesCollection
*col
= NULL
;
2156 IHTMLStyleSheet
*stylesheet
;
2159 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLStyleSheet
, (void**)&stylesheet
);
2160 ok(hres
== S_OK
, "Could not get IHTMLStyleSheet: %08x\n", hres
);
2162 hres
= IHTMLStyleSheet_get_rules(stylesheet
, &col
);
2163 ok(hres
== S_OK
, "get_rules failed: %08x\n", hres
);
2164 ok(col
!= NULL
, "col == NULL\n");
2166 IHTMLStyleSheetRulesCollection_Release(col
);
2167 IHTMLStyleSheet_Release(stylesheet
);
2170 static void test_stylesheets(IHTMLDocument2
*doc
)
2172 IHTMLStyleSheetsCollection
*col
= NULL
;
2177 hres
= IHTMLDocument2_get_styleSheets(doc
, &col
);
2178 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
2179 ok(col
!= NULL
, "col == NULL\n");
2181 hres
= IHTMLStyleSheetsCollection_get_length(col
, &len
);
2182 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2183 ok(len
== 1, "len=%ld\n", len
);
2189 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
2190 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
2191 ok(V_VT(&res
) == VT_DISPATCH
, "V_VT(res) = %d\n", V_VT(&res
));
2192 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
2193 test_stylesheet(V_DISPATCH(&res
));
2200 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
2201 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2202 ok(V_VT(&res
) == VT_EMPTY
, "V_VT(res) = %d\n", V_VT(&res
));
2203 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
2206 IHTMLStyleSheetsCollection_Release(col
);
2209 static void test_child_col_disp(IHTMLDOMChildrenCollection
*col
)
2211 IDispatchEx
*dispex
;
2213 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
2221 static const WCHAR w0
[] = {'0',0};
2222 static const WCHAR w100
[] = {'1','0','0',0};
2224 hres
= IHTMLDOMChildrenCollection_QueryInterface(col
, &IID_IDispatchEx
, (void**)&dispex
);
2225 ok(hres
== S_OK
, "Could not get IDispatchEx: %08x\n", hres
);
2227 bstr
= SysAllocString(w0
);
2228 hres
= IDispatchEx_GetDispID(dispex
, bstr
, fdexNameCaseSensitive
, &id
);
2229 ok(hres
== S_OK
, "GetDispID failed: %08x\n", hres
);
2230 SysFreeString(bstr
);
2233 hres
= IDispatchEx_InvokeEx(dispex
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYGET
, &dp
, &var
, &ei
, NULL
);
2234 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
2235 ok(V_VT(&var
) == VT_DISPATCH
, "V_VT(var)=%d\n", V_VT(&var
));
2236 ok(V_DISPATCH(&var
) != NULL
, "V_DISPATCH(var) == NULL\n");
2237 node
= get_node_iface((IUnknown
*)V_DISPATCH(&var
));
2238 type
= get_node_type((IUnknown
*)node
);
2239 ok(type
== 3, "type=%ld\n", type
);
2240 IHTMLDOMNode_Release(node
);
2243 bstr
= SysAllocString(w100
);
2244 hres
= IDispatchEx_GetDispID(dispex
, bstr
, fdexNameCaseSensitive
, &id
);
2245 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
2246 SysFreeString(bstr
);
2248 IDispatchEx_Release(dispex
);
2253 static void test_elems(IHTMLDocument2
*doc
)
2255 IHTMLElementCollection
*col
;
2256 IHTMLDOMChildrenCollection
*child_col
;
2257 IHTMLElement
*elem
, *elem2
, *elem3
;
2258 IHTMLDOMNode
*node
, *node2
;
2263 static const WCHAR imgidW
[] = {'i','m','g','i','d',0};
2264 static const WCHAR inW
[] = {'i','n',0};
2265 static const WCHAR xW
[] = {'x',0};
2266 static const WCHAR sW
[] = {'s',0};
2267 static const WCHAR scW
[] = {'s','c',0};
2268 static const WCHAR xxxW
[] = {'x','x','x',0};
2270 static const elem_type_t all_types
[] = {
2290 static const elem_type_t item_types
[] = {
2296 hres
= IHTMLDocument2_get_all(doc
, &col
);
2297 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2298 test_elem_collection((IUnknown
*)col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
2299 test_elem_col_item(col
, xW
, item_types
, sizeof(item_types
)/sizeof(item_types
[0]));
2300 IHTMLElementCollection_Release(col
);
2302 elem
= get_doc_elem(doc
);
2303 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
2304 hres
= IHTMLElement_get_all(elem
, &disp
);
2305 IHTMLElement_Release(elem
);
2306 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2308 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&col
);
2309 IDispatch_Release(disp
);
2310 ok(hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
2311 test_elem_collection((IUnknown
*)col
, all_types
+1, sizeof(all_types
)/sizeof(all_types
[0])-1);
2312 IHTMLElementCollection_Release(col
);
2314 get_elem_by_id(doc
, xxxW
, FALSE
);
2315 elem
= get_doc_elem_by_id(doc
, xxxW
);
2316 ok(!elem
, "elem != NULL\n");
2318 elem
= get_doc_elem_by_id(doc
, sW
);
2319 ok(elem
!= NULL
, "elem == NULL\n");
2321 test_elem_type((IUnknown
*)elem
, ET_SELECT
);
2322 test_elem_attr(elem
, xxxW
, NULL
);
2323 test_elem_attr(elem
, idW
, sW
);
2324 test_elem_class((IUnknown
*)elem
, NULL
);
2325 test_elem_set_class((IUnknown
*)elem
, "cl");
2326 test_elem_set_class((IUnknown
*)elem
, NULL
);
2327 test_elem_tabindex((IUnknown
*)elem
, 0);
2328 test_elem_set_tabindex((IUnknown
*)elem
, 1);
2330 node
= test_node_get_parent((IUnknown
*)elem
);
2331 ok(node
!= NULL
, "node == NULL\n");
2332 test_node_name((IUnknown
*)node
, "BODY");
2333 node2
= test_node_get_parent((IUnknown
*)node
);
2334 IHTMLDOMNode_Release(node
);
2335 ok(node2
!= NULL
, "node == NULL\n");
2336 test_node_name((IUnknown
*)node2
, "HTML");
2337 node
= test_node_get_parent((IUnknown
*)node2
);
2338 IHTMLDOMNode_Release(node2
);
2339 ok(node
!= NULL
, "node == NULL\n");
2340 test_node_name((IUnknown
*)node
, "#document");
2341 type
= get_node_type((IUnknown
*)node
);
2342 ok(type
== 9, "type=%ld, expected 9\n", type
);
2343 node2
= test_node_get_parent((IUnknown
*)node
);
2344 IHTMLDOMNode_Release(node
);
2345 ok(node2
== NULL
, "node != NULL\n");
2347 elem2
= test_elem_get_parent((IUnknown
*)elem
);
2348 ok(elem2
!= NULL
, "elem2 == NULL\n");
2349 test_node_name((IUnknown
*)elem2
, "BODY");
2350 elem3
= test_elem_get_parent((IUnknown
*)elem2
);
2351 IHTMLElement_Release(elem2
);
2352 ok(elem3
!= NULL
, "elem3 == NULL\n");
2353 test_node_name((IUnknown
*)elem3
, "HTML");
2354 elem2
= test_elem_get_parent((IUnknown
*)elem3
);
2355 IHTMLElement_Release(elem3
);
2356 ok(elem2
== NULL
, "elem2 != NULL\n");
2358 test_elem_getelembytag((IUnknown
*)elem
, ET_OPTION
, 2);
2359 test_elem_getelembytag((IUnknown
*)elem
, ET_SELECT
, 0);
2360 test_elem_getelembytag((IUnknown
*)elem
, ET_HTML
, 0);
2362 IHTMLElement_Release(elem
);
2365 elem
= get_elem_by_id(doc
, sW
, TRUE
);
2367 IHTMLSelectElement
*select
;
2369 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLSelectElement
, (void**)&select
);
2370 ok(hres
== S_OK
, "Could not get IHTMLSelectElement interface: %08x\n", hres
);
2372 test_select_elem(select
);
2374 test_elem_title((IUnknown
*)select
, NULL
);
2375 test_elem_set_title((IUnknown
*)select
, "Title");
2376 test_elem_title((IUnknown
*)select
, "Title");
2377 test_elem_offset((IUnknown
*)select
);
2379 node
= get_first_child((IUnknown
*)select
);
2380 ok(node
!= NULL
, "node == NULL\n");
2382 test_elem_type((IUnknown
*)node
, ET_OPTION
);
2383 IHTMLDOMNode_Release(node
);
2386 type
= get_node_type((IUnknown
*)select
);
2387 ok(type
== 1, "type=%ld\n", type
);
2389 IHTMLSelectElement_Release(select
);
2390 IHTMLElement_Release(elem
);
2393 elem
= get_elem_by_id(doc
, scW
, TRUE
);
2395 IHTMLScriptElement
*script
;
2398 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLScriptElement
, (void**)&script
);
2399 ok(hres
== S_OK
, "Could not get IHTMLScriptElement interface: %08x\n", hres
);
2401 hres
= IHTMLScriptElement_get_type(script
, &type
);
2402 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
2403 ok(!lstrcmpW(type
, text_javascriptW
), "Unexpected type %s\n", dbgstr_w(type
));
2404 SysFreeString(type
);
2406 IHTMLScriptElement_Release(script
);
2409 elem
= get_elem_by_id(doc
, inW
, TRUE
);
2411 IHTMLInputElement
*input
;
2413 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLInputElement
, (void**)&input
);
2414 ok(hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
2416 test_elem_id((IUnknown
*)elem
, "in");
2417 test_elem_put_id((IUnknown
*)elem
, "newin");
2418 test_input_get_disabled(input
, VARIANT_FALSE
);
2419 test_input_set_disabled(input
, VARIANT_TRUE
);
2420 test_input_set_disabled(input
, VARIANT_FALSE
);
2421 test_elem_client_size((IUnknown
*)elem
);
2423 test_node_get_value_str((IUnknown
*)elem
, NULL
);
2424 test_node_put_value_str((IUnknown
*)elem
, "test");
2425 test_node_get_value_str((IUnknown
*)elem
, NULL
);
2426 test_input_value((IUnknown
*)elem
, NULL
);
2427 test_input_put_value((IUnknown
*)elem
, "test");
2428 test_input_value((IUnknown
*)elem
, NULL
);
2429 test_elem_class((IUnknown
*)elem
, "testclass");
2430 test_elem_tabindex((IUnknown
*)elem
, 2);
2431 test_elem_set_tabindex((IUnknown
*)elem
, 3);
2432 test_elem_title((IUnknown
*)elem
, "test title");
2434 IHTMLInputElement_Release(input
);
2435 IHTMLElement_Release(elem
);
2438 elem
= get_elem_by_id(doc
, imgidW
, TRUE
);
2440 test_img_set_src((IUnknown
*)elem
, "about:blank");
2441 test_img_alt((IUnknown
*)elem
, NULL
);
2442 test_img_set_alt((IUnknown
*)elem
, "alt test");
2443 IHTMLElement_Release(elem
);
2446 hres
= IHTMLDocument2_get_body(doc
, &elem
);
2447 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2449 node
= get_first_child((IUnknown
*)elem
);
2450 ok(node
!= NULL
, "node == NULL\n");
2452 test_ifaces((IUnknown
*)node
, text_iids
);
2453 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
2455 node2
= get_first_child((IUnknown
*)node
);
2456 ok(!node2
, "node2 != NULL\n");
2458 type
= get_node_type((IUnknown
*)node
);
2459 ok(type
== 3, "type=%ld\n", type
);
2461 test_node_get_value_str((IUnknown
*)node
, "text test");
2462 test_node_put_value_str((IUnknown
*)elem
, "test text");
2463 test_node_get_value_str((IUnknown
*)node
, "text test");
2465 IHTMLDOMNode_Release(node
);
2468 child_col
= get_child_nodes((IUnknown
*)elem
);
2469 ok(child_col
!= NULL
, "child_coll == NULL\n");
2473 test_disp((IUnknown
*)child_col
, &DIID_DispDOMChildrenCollection
);
2475 hres
= IHTMLDOMChildrenCollection_get_length(child_col
, &length
);
2476 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
2477 ok(length
, "length=0\n");
2479 node
= get_child_item(child_col
, 0);
2480 ok(node
!= NULL
, "node == NULL\n");
2482 type
= get_node_type((IUnknown
*)node
);
2483 ok(type
== 3, "type=%ld\n", type
);
2484 IHTMLDOMNode_Release(node
);
2487 node
= get_child_item(child_col
, 1);
2488 ok(node
!= NULL
, "node == NULL\n");
2490 type
= get_node_type((IUnknown
*)node
);
2491 ok(type
== 8, "type=%ld\n", type
);
2493 test_elem_id((IUnknown
*)node
, NULL
);
2494 IHTMLDOMNode_Release(node
);
2497 disp
= (void*)0xdeadbeef;
2498 hres
= IHTMLDOMChildrenCollection_item(child_col
, 6000, &disp
);
2499 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2500 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
2502 disp
= (void*)0xdeadbeef;
2503 hres
= IHTMLDOMChildrenCollection_item(child_col
, length
, &disp
);
2504 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
2505 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
2507 test_child_col_disp(child_col
);
2509 IHTMLDOMChildrenCollection_Release(child_col
);
2512 IHTMLElement_Release(elem
);
2514 test_stylesheets(doc
);
2515 test_create_option_elem(doc
);
2517 test_doc_title(doc
, "test");
2518 test_doc_set_title(doc
, "test title");
2519 test_doc_title(doc
, "test title");
2522 static void test_create_elems(IHTMLDocument2
*doc
)
2524 IHTMLElement
*elem
, *body
, *elem2
;
2530 static const elem_type_t types1
[] = { ET_TESTG
};
2532 elem
= test_create_elem(doc
, "TEST");
2533 test_elem_tag((IUnknown
*)elem
, "TEST");
2534 type
= get_node_type((IUnknown
*)elem
);
2535 ok(type
== 1, "type=%ld\n", type
);
2536 test_ifaces((IUnknown
*)elem
, elem_iids
);
2537 test_disp((IUnknown
*)elem
, &DIID_DispHTMLGenericElement
);
2539 hres
= IHTMLDocument2_get_body(doc
, &body
);
2540 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2541 test_node_has_child((IUnknown
*)body
, VARIANT_FALSE
);
2543 node
= test_node_append_child((IUnknown
*)body
, (IUnknown
*)elem
);
2544 test_node_has_child((IUnknown
*)body
, VARIANT_TRUE
);
2545 elem2
= get_elem_iface((IUnknown
*)node
);
2546 IHTMLElement_Release(elem2
);
2548 hres
= IHTMLElement_get_all(body
, &disp
);
2549 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2550 test_elem_collection((IUnknown
*)disp
, types1
, sizeof(types1
)/sizeof(types1
[0]));
2551 IDispatch_Release(disp
);
2553 test_node_remove_child((IUnknown
*)body
, node
);
2555 hres
= IHTMLElement_get_all(body
, &disp
);
2556 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2557 test_elem_collection((IUnknown
*)disp
, NULL
, 0);
2558 IDispatch_Release(disp
);
2559 test_node_has_child((IUnknown
*)body
, VARIANT_FALSE
);
2561 IHTMLElement_Release(body
);
2562 IHTMLElement_Release(elem
);
2563 IHTMLDOMNode_Release(node
);
2565 node
= test_create_text(doc
, "test");
2566 test_ifaces((IUnknown
*)node
, text_iids
);
2567 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
2568 IHTMLDOMNode_Release(node
);
2571 static void test_exec(IUnknown
*unk
, const GUID
*grpid
, DWORD cmdid
, VARIANT
*in
, VARIANT
*out
)
2573 IOleCommandTarget
*cmdtrg
;
2576 hres
= IHTMLTxtRange_QueryInterface(unk
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
2577 ok(hres
== S_OK
, "Could not get IOleCommandTarget interface: %08x\n", hres
);
2579 hres
= IOleCommandTarget_Exec(cmdtrg
, grpid
, cmdid
, 0, in
, out
);
2580 ok(hres
== S_OK
, "Exec failed: %08x\n", hres
);
2582 IOleCommandTarget_Release(cmdtrg
);
2585 static void test_indent(IHTMLDocument2
*doc
)
2587 IHTMLElementCollection
*col
;
2588 IHTMLTxtRange
*range
;
2591 static const elem_type_t all_types
[] = {
2600 static const elem_type_t indent_types
[] = {
2611 hres
= IHTMLDocument2_get_all(doc
, &col
);
2612 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2613 test_elem_collection((IUnknown
*)col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
2614 IHTMLElementCollection_Release(col
);
2616 range
= test_create_body_range(doc
);
2617 test_exec((IUnknown
*)range
, &CGID_MSHTML
, IDM_INDENT
, NULL
, NULL
);
2618 IHTMLTxtRange_Release(range
);
2620 hres
= IHTMLDocument2_get_all(doc
, &col
);
2621 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
2622 test_elem_collection((IUnknown
*)col
, indent_types
, sizeof(indent_types
)/sizeof(indent_types
[0]));
2623 IHTMLElementCollection_Release(col
);
2626 static IHTMLDocument2
*notif_doc
;
2627 static BOOL doc_complete
;
2629 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
2630 REFIID riid
, void**ppv
)
2632 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
2637 ok(0, "unexpected call\n");
2638 return E_NOINTERFACE
;
2641 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
2646 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
2651 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
2653 if(dispID
== DISPID_READYSTATE
){
2657 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
2659 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
2660 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
2662 if(!lstrcmpW(state
, completeW
))
2663 doc_complete
= TRUE
;
2665 SysFreeString(state
);
2671 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
2673 ok(0, "unexpected call\n");
2677 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
2678 PropertyNotifySink_QueryInterface
,
2679 PropertyNotifySink_AddRef
,
2680 PropertyNotifySink_Release
,
2681 PropertyNotifySink_OnChanged
,
2682 PropertyNotifySink_OnRequestEdit
2685 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
2687 static IHTMLDocument2
*create_doc_with_string(const char *str
)
2689 IPersistStreamInit
*init
;
2691 IHTMLDocument2
*doc
;
2695 notif_doc
= doc
= create_document();
2699 doc_complete
= FALSE
;
2701 mem
= GlobalAlloc(0, len
);
2702 memcpy(mem
, str
, len
);
2703 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
2705 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
2707 IPersistStreamInit_Load(init
, stream
);
2708 IPersistStreamInit_Release(init
);
2709 IStream_Release(stream
);
2714 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
2716 IConnectionPointContainer
*container
;
2717 IConnectionPoint
*cp
;
2721 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
2722 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
2724 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
2725 IConnectionPointContainer_Release(container
);
2726 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
2728 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
2729 IConnectionPoint_Release(cp
);
2730 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
2733 typedef void (*domtest_t
)(IHTMLDocument2
*);
2735 static void run_domtest(const char *str
, domtest_t test
)
2737 IHTMLDocument2
*doc
;
2738 IHTMLElement
*body
= NULL
;
2743 doc
= create_doc_with_string(str
);
2744 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
2746 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
2747 TranslateMessage(&msg
);
2748 DispatchMessage(&msg
);
2751 hres
= IHTMLDocument2_get_body(doc
, &body
);
2752 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2755 IHTMLElement_Release(body
);
2758 skip("Could not get document body. Assuming no Gecko installed.\n");
2761 ref
= IHTMLDocument2_Release(doc
);
2763 ref
== 1, /* Vista */
2767 static void gecko_installer_workaround(BOOL disable
)
2772 static BOOL has_url
= FALSE
;
2773 static char url
[2048];
2775 if(!disable
&& !has_url
)
2778 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
2779 if(res
!= ERROR_SUCCESS
)
2783 DWORD type
, size
= sizeof(url
);
2785 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
2786 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
2789 RegDeleteValue(hkey
, "GeckoUrl");
2791 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
2799 gecko_installer_workaround(TRUE
);
2802 run_domtest(doc_str1
, test_doc_elem
);
2803 run_domtest(range_test_str
, test_txtrange
);
2804 run_domtest(range_test2_str
, test_txtrange2
);
2805 run_domtest(elem_test_str
, test_elems
);
2806 run_domtest(doc_blank
, test_create_elems
);
2807 run_domtest(doc_blank
, test_defaults
);
2808 run_domtest(indent_test_str
, test_indent
);
2811 gecko_installer_workaround(FALSE
);