2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
35 static const char doc_blank
[] = "<html></html>";
36 static const char doc_str1
[] = "<html><body>test</body></html>";
37 static const char range_test_str
[] =
38 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
39 static const char range_test2_str
[] =
40 "<html><body>abc<hr />123<br /><hr />def</body></html>";
41 static const char elem_test_str
[] =
42 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
43 "<body>text test<!-- a comment -->"
44 "<a href=\"http://test\" name=\"x\">link</a>"
46 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table><tbody></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
52 static const char indent_test_str
[] =
53 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
55 static const WCHAR noneW
[] = {'N','o','n','e',0};
57 static WCHAR characterW
[] = {'c','h','a','r','a','c','t','e','r',0};
58 static WCHAR texteditW
[] = {'t','e','x','t','e','d','i','t',0};
59 static WCHAR wordW
[] = {'w','o','r','d',0};
61 static const WCHAR text_javascriptW
[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
63 static const WCHAR idW
[] = {'i','d',0};
87 static REFIID
const none_iids
[] = {
92 static REFIID
const elem_iids
[] = {
98 &IID_IConnectionPointContainer
,
102 static REFIID
const body_iids
[] = {
107 &IID_IHTMLTextContainer
,
108 &IID_IHTMLBodyElement
,
110 &IID_IConnectionPointContainer
,
114 static REFIID
const anchor_iids
[] = {
119 &IID_IHTMLAnchorElement
,
121 &IID_IConnectionPointContainer
,
125 static REFIID
const input_iids
[] = {
130 &IID_IHTMLInputElement
,
131 &IID_IHTMLInputTextElement
,
133 &IID_IConnectionPointContainer
,
137 static REFIID
const select_iids
[] = {
142 &IID_IHTMLSelectElement
,
144 &IID_IConnectionPointContainer
,
148 static REFIID
const textarea_iids
[] = {
153 &IID_IHTMLTextAreaElement
,
155 &IID_IConnectionPointContainer
,
159 static REFIID
const option_iids
[] = {
164 &IID_IHTMLOptionElement
,
166 &IID_IConnectionPointContainer
,
170 static REFIID
const table_iids
[] = {
177 &IID_IConnectionPointContainer
,
181 static REFIID
const script_iids
[] = {
186 &IID_IHTMLScriptElement
,
188 &IID_IConnectionPointContainer
,
192 static REFIID
const text_iids
[] = {
195 &IID_IHTMLDOMTextNode
,
199 static REFIID
const location_iids
[] = {
205 static REFIID
const window_iids
[] = {
213 static REFIID
const comment_iids
[] = {
218 &IID_IHTMLCommentElement
,
220 &IID_IConnectionPointContainer
,
230 static const elem_type_info_t elem_type_infos
[] = {
231 {"", none_iids
, NULL
},
232 {"HTML", elem_iids
, NULL
},
233 {"HEAD", elem_iids
, NULL
},
234 {"TITLE", elem_iids
, NULL
},
235 {"BODY", body_iids
, NULL
},
236 {"A", anchor_iids
, NULL
},
237 {"INPUT", input_iids
, &DIID_DispHTMLInputElement
},
238 {"SELECT", select_iids
, NULL
},
239 {"TEXTAREA", textarea_iids
, NULL
},
240 {"OPTION", option_iids
, &DIID_DispHTMLOptionElement
},
241 {"STYLE", elem_iids
, NULL
},
242 {"BLOCKQUOTE",elem_iids
, NULL
},
243 {"P", elem_iids
, NULL
},
244 {"BR", elem_iids
, NULL
},
245 {"TABLE", table_iids
, NULL
},
246 {"TBODY", elem_iids
, NULL
},
247 {"SCRIPT", script_iids
, NULL
},
248 {"TEST", elem_iids
, &DIID_DispHTMLUnknownElement
},
249 {"!", comment_iids
, &DIID_DispHTMLCommentElement
}
252 static const char *dbgstr_w(LPCWSTR str
)
254 static char buf
[512];
257 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
261 static const char *dbgstr_guid(REFIID riid
)
265 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
266 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
267 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
268 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
273 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
276 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
277 return lstrcmpW(strw
, buf
);
280 static BSTR
a2bstr(const char *str
)
285 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
286 ret
= SysAllocStringLen(NULL
, len
);
287 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
292 static IHTMLDocument2
*create_document(void)
297 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
298 &IID_IHTMLDocument2
, (void**)&doc
);
299 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
304 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
305 static void _test_ifaces(unsigned line
, IUnknown
*iface
, REFIID
*iids
)
307 const IID
* const *piid
;
311 for(piid
= iids
; *piid
; piid
++) {
312 hres
= IDispatch_QueryInterface(iface
, *piid
, (void**)&unk
);
313 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get %s interface: %08x\n", dbgstr_guid(*piid
), hres
);
315 IUnknown_Release(unk
);
319 #define test_disp(u,id) _test_disp(__LINE__,u,id)
320 static void _test_disp(unsigned line
, IUnknown
*unk
, const IID
*diid
)
327 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
328 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IDispatch: %08x\n", hres
);
333 hres
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
334 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfoCount failed: %08x\n", hres
);
335 ok_(__FILE__
,line
) (ticnt
== 1, "ticnt=%u\n", ticnt
);
337 hres
= IDispatchEx_GetTypeInfo(dispex
, 0, 0, &typeinfo
);
338 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfo failed: %08x\n", hres
);
340 if(SUCCEEDED(hres
)) {
343 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &type_attr
);
344 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeAttr failed: %08x\n", hres
);
345 ok_(__FILE__
,line
) (IsEqualGUID(&type_attr
->guid
, diid
), "unexpected guid %s\n", dbgstr_guid(&type_attr
->guid
));
347 ITypeInfo_ReleaseTypeAttr(typeinfo
, type_attr
);
348 ITypeInfo_Release(typeinfo
);
351 IDispatchEx_Release(dispex
);
354 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
355 static void _test_node_name(unsigned line
, IUnknown
*unk
, const char *exname
)
361 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
362 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres
);
364 hres
= IHTMLDOMNode_get_nodeName(node
, &name
);
365 IHTMLDOMNode_Release(node
);
366 ok_(__FILE__
, line
) (hres
== S_OK
, "get_nodeName failed: %08x\n", hres
);
367 ok_(__FILE__
, line
) (!strcmp_wa(name
, exname
), "got name: %s, expected %s\n", dbgstr_w(name
), exname
);
372 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
373 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
379 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
380 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres
);
382 hres
= IHTMLElement_get_tagName(elem
, &tag
);
383 IHTMLElement_Release(elem
);
384 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
385 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", dbgstr_w(tag
), extag
);
390 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
391 static void _test_elem_type(unsigned line
, IUnknown
*unk
, elem_type_t type
)
393 _test_elem_tag(line
, unk
, elem_type_infos
[type
].tag
);
394 _test_ifaces(line
, unk
, elem_type_infos
[type
].iids
);
396 if(elem_type_infos
[type
].dispiid
)
397 _test_disp(line
, unk
, elem_type_infos
[type
].dispiid
);
400 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
401 static void _test_elem_attr(unsigned line
, IHTMLElement
*elem
, LPCWSTR name
, LPCWSTR exval
)
409 tmp
= SysAllocString(name
);
410 hres
= IHTMLElement_getAttribute(elem
, tmp
, 0, &value
);
412 ok_(__FILE__
,line
) (hres
== S_OK
, "getAttribute failed: %08x\n", hres
);
415 ok_(__FILE__
,line
) (V_VT(&value
) == VT_BSTR
, "vt=%d\n", V_VT(&value
));
416 ok_(__FILE__
,line
) (!lstrcmpW(exval
, V_BSTR(&value
)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value
)));
418 ok_(__FILE__
,line
) (V_VT(&value
) == VT_NULL
, "vt=%d\n", V_VT(&value
));
421 VariantClear(&value
);
424 static void test_doc_elem(IHTMLDocument2
*doc
)
427 IHTMLDocument3
*doc3
;
430 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
431 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres
);
433 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
434 IHTMLDocument3_Release(doc3
);
435 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
437 test_node_name((IUnknown
*)elem
, "HTML");
438 test_elem_tag((IUnknown
*)elem
, "HTML");
440 IHTMLElement_Release(elem
);
443 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
444 static IHTMLElement
*_get_doc_elem(unsigned line
, IHTMLDocument2
*doc
)
447 IHTMLDocument3
*doc3
;
450 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
451 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 interface: %08x\n", hres
);
452 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
453 ok_(__FILE__
,line
) (hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
454 IHTMLDocument3_Release(doc3
);
459 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
460 static void _test_option_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
465 hres
= IHTMLOptionElement_get_text(option
, &bstr
);
466 ok_(__FILE__
,line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
467 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, text
), "text=%s\n", dbgstr_w(bstr
));
471 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
472 static void _test_option_put_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
478 hres
= IHTMLOptionElement_put_text(option
, bstr
);
480 ok(hres
== S_OK
, "put_text failed: %08x\n", hres
);
482 _test_option_text(line
, option
, text
);
485 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
486 static void _test_option_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
491 hres
= IHTMLOptionElement_get_value(option
, &bstr
);
492 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
493 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, value
), "value=%s\n", dbgstr_w(bstr
));
497 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
498 static void _test_option_put_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
503 bstr
= a2bstr(value
);
504 hres
= IHTMLOptionElement_put_value(option
, bstr
);
506 ok(hres
== S_OK
, "put_value failed: %08x\n", hres
);
508 _test_option_value(line
, option
, value
);
511 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
512 static IHTMLOptionElement
*_create_option_elem(unsigned line
, IHTMLDocument2
*doc
,
513 const char *txt
, const char *val
)
515 IHTMLOptionElementFactory
*factory
;
516 IHTMLOptionElement
*option
;
517 IHTMLWindow2
*window
;
518 VARIANT text
, value
, empty
;
521 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
522 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
524 hres
= IHTMLWindow2_get_Option(window
, &factory
);
525 IHTMLWindow2_Release(window
);
526 ok_(__FILE__
,line
) (hres
== S_OK
, "get_Option failed: %08x\n", hres
);
528 V_VT(&text
) = VT_BSTR
;
529 V_BSTR(&text
) = a2bstr(txt
);
530 V_VT(&value
) = VT_BSTR
;
531 V_BSTR(&value
) = a2bstr(val
);
532 V_VT(&empty
) = VT_EMPTY
;
534 hres
= IHTMLOptionElementFactory_create(factory
, text
, value
, empty
, empty
, &option
);
535 ok_(__FILE__
,line
) (hres
== S_OK
, "create failed: %08x\n", hres
);
537 IHTMLOptionElementFactory_Release(factory
);
539 VariantClear(&value
);
541 _test_option_text(line
, option
, txt
);
542 _test_option_value(line
, option
, val
);
547 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
548 static void _test_select_length(unsigned line
, IHTMLSelectElement
*select
, long length
)
550 long len
= 0xdeadbeef;
553 hres
= IHTMLSelectElement_get_length(select
, &len
);
554 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
555 ok_(__FILE__
,line
) (len
== length
, "len=%ld, expected %ld\n", len
, length
);
558 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
559 static void _test_select_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
561 long idx
= 0xdeadbeef;
564 hres
= IHTMLSelectElement_get_selectedIndex(select
, &idx
);
565 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
566 ok_(__FILE__
,line
) (idx
== index
, "idx=%ld, expected %ld\n", idx
, index
);
569 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
570 static void _test_select_put_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
574 hres
= IHTMLSelectElement_put_selectedIndex(select
, index
);
575 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
576 _test_select_selidx(line
, select
, index
);
579 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
580 static void _test_range_text(unsigned line
, IHTMLTxtRange
*range
, const char *extext
)
585 hres
= IHTMLTxtRange_get_text(range
, &text
);
586 ok_(__FILE__
, line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
589 ok_(__FILE__
, line
) (text
!= NULL
, "text == NULL\n");
590 ok_(__FILE__
, line
) (!strcmp_wa(text
, extext
), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text
), extext
);
592 ok_(__FILE__
, line
) (text
== NULL
, "text=\"%s\", expected NULL\n", dbgstr_w(text
));
599 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
600 static void _test_range_collapse(unsigned line
, IHTMLTxtRange
*range
, BOOL b
)
604 hres
= IHTMLTxtRange_collapse(range
, b
);
605 ok_(__FILE__
, line
) (hres
== S_OK
, "collapse failed: %08x\n", hres
);
606 _test_range_text(line
, range
, NULL
);
609 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
610 static void _test_range_expand(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
,
611 VARIANT_BOOL exb
, const char *extext
)
613 VARIANT_BOOL b
= 0xe0e0;
616 hres
= IHTMLTxtRange_expand(range
, unit
, &b
);
617 ok_(__FILE__
,line
) (hres
== S_OK
, "expand failed: %08x\n", hres
);
618 ok_(__FILE__
,line
) (b
== exb
, "b=%x, expected %x\n", b
, exb
);
619 _test_range_text(line
, range
, extext
);
622 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
623 static void _test_range_move(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
628 hres
= IHTMLTxtRange_move(range
, unit
, cnt
, &c
);
629 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
630 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
631 _test_range_text(line
, range
, NULL
);
634 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
635 static void _test_range_movestart(unsigned line
, IHTMLTxtRange
*range
,
636 LPWSTR unit
, long cnt
, long excnt
)
641 hres
= IHTMLTxtRange_moveStart(range
, unit
, cnt
, &c
);
642 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
643 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
646 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
647 static void _test_range_moveend(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
652 hres
= IHTMLTxtRange_moveEnd(range
, unit
, cnt
, &c
);
653 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
654 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
657 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
658 static void _test_range_put_text(unsigned line
, IHTMLTxtRange
*range
, const char *text
)
661 BSTR bstr
= a2bstr(text
);
663 hres
= IHTMLTxtRange_put_text(range
, bstr
);
664 ok_(__FILE__
,line
) (hres
== S_OK
, "put_text failed: %08x\n", hres
);
666 _test_range_text(line
, range
, NULL
);
669 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
670 static void _test_range_inrange(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
676 hres
= IHTMLTxtRange_inRange(range1
, range2
, &b
);
677 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
678 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
681 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
682 static void _test_range_isequal(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
688 hres
= IHTMLTxtRange_isEqual(range1
, range2
, &b
);
689 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
690 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
693 hres
= IHTMLTxtRange_isEqual(range2
, range1
, &b
);
694 ok_(__FILE__
,line
) (hres
== S_OK
, "(2->1) isEqual failed: %08x\n", hres
);
695 ok_(__FILE__
,line
) (b
== exb
, "(2->1) b=%x, expected %x\n", b
, exb
);
698 test_range_inrange(range1
, range2
, VARIANT_TRUE
);
699 test_range_inrange(range2
, range1
, VARIANT_TRUE
);
703 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
704 static void _test_range_parent(unsigned line
, IHTMLTxtRange
*range
, elem_type_t type
)
709 hres
= IHTMLTxtRange_parentElement(range
, &elem
);
710 ok_(__FILE__
,line
) (hres
== S_OK
, "parentElement failed: %08x\n", hres
);
712 _test_elem_type(line
, (IUnknown
*)elem
, type
);
714 IHTMLElement_Release(elem
);
717 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
718 static void _test_elem_collection(unsigned line
, IHTMLElementCollection
*col
,
719 const elem_type_t
*elem_types
, long exlen
)
727 test_disp((IUnknown
*)col
, &DIID_DispHTMLElementCollection
);
729 hres
= IHTMLElementCollection_get_length(col
, &len
);
730 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
731 ok_(__FILE__
,line
) (len
== exlen
, "len=%ld, expected %ld\n", len
, exlen
);
736 V_VT(&index
) = VT_EMPTY
;
739 for(i
=0; i
<len
; i
++) {
741 disp
= (void*)0xdeadbeef;
742 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
743 ok_(__FILE__
,line
) (hres
== S_OK
, "item(%d) failed: %08x\n", i
, hres
);
744 ok_(__FILE__
,line
) (disp
!= NULL
, "item returned NULL\n");
745 if(FAILED(hres
) || !disp
)
748 _test_elem_type(line
, (IUnknown
*)disp
, elem_types
[i
]);
749 IDispatch_Release(disp
);
753 disp
= (void*)0xdeadbeef;
754 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
755 ok_(__FILE__
,line
) (hres
== S_OK
, "item failed: %08x\n", hres
);
756 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
759 disp
= (void*)0xdeadbeef;
760 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
761 ok_(__FILE__
,line
) (hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
762 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
765 #define get_first_child(n) _get_first_child(__LINE__,n)
766 static IHTMLDOMNode
*_get_first_child(unsigned line
, IUnknown
*unk
)
768 IHTMLDOMNode
*node
, *child
= NULL
;
771 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
772 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
776 hres
= IHTMLDOMNode_get_firstChild(node
, &child
);
777 IHTMLDOMNode_Release(node
);
778 ok_(__FILE__
,line
) (hres
== S_OK
, "get_firstChild failed: %08x\n", hres
);
783 #define get_node_type(n) _get_node_type(__LINE__,n)
784 static long _get_node_type(unsigned line
, IUnknown
*unk
)
790 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
791 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
793 hres
= IHTMLDOMNode_get_nodeType(node
, &type
);
794 ok(hres
== S_OK
, "get_nodeType failed: %08x\n", hres
);
796 IHTMLDOMNode_Release(node
);
801 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
802 static void _test_input_get_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL exb
)
804 VARIANT_BOOL disabled
= 100;
807 hres
= IHTMLInputElement_get_disabled(input
, &disabled
);
808 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
809 ok_(__FILE__
,line
) (disabled
== exb
, "disabled=%x, expected %x\n", disabled
, exb
);
812 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
813 static IHTMLDOMChildrenCollection
*_get_child_nodes(unsigned line
, IUnknown
*unk
)
815 IHTMLDOMChildrenCollection
*col
= NULL
;
820 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
821 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
825 hres
= IHTMLDOMNode_get_childNodes(node
, &disp
);
826 IHTMLDOMNode_Release(node
);
827 ok_(__FILE__
,line
) (hres
== S_OK
, "get_childNodes failed: %08x\n", hres
);
831 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMChildrenCollection
, (void**)&col
);
832 IDispatch_Release(disp
);
833 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres
);
838 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
839 static IHTMLDOMNode
*_get_child_item(unsigned line
, IHTMLDOMChildrenCollection
*col
, long idx
)
841 IHTMLDOMNode
*node
= NULL
;
845 hres
= IHTMLDOMChildrenCollection_item(col
, idx
, &disp
);
846 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
848 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMNode
, (void**)&node
);
849 IDispatch_Release(disp
);
850 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
855 static void test_elem_col_item(IHTMLElementCollection
*col
, LPCWSTR n
,
856 const elem_type_t
*elem_types
, long len
)
858 IHTMLElementCollection
*elcol
;
864 V_VT(&index
) = VT_EMPTY
;
865 V_VT(&name
) = VT_BSTR
;
866 V_BSTR(&name
) = SysAllocString(n
);
868 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
869 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
871 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&elcol
);
872 IDispatch_Release(disp
);
873 ok(hres
== S_OK
, "Could not get IHTMLElementCollection interface: %08x\n", hres
);
874 test_elem_collection(elcol
, elem_types
, len
);
875 IHTMLElementCollection_Release(elcol
);
877 V_VT(&index
) = VT_I4
;
879 for(i
=0; i
<len
; i
++) {
881 disp
= (void*)0xdeadbeef;
882 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
883 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
884 ok(disp
!= NULL
, "disp == NULL\n");
885 if(FAILED(hres
) || !disp
)
888 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
890 IDispatch_Release(disp
);
894 disp
= (void*)0xdeadbeef;
895 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
896 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
897 ok(disp
== NULL
, "disp != NULL\n");
900 disp
= (void*)0xdeadbeef;
901 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
902 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
903 ok(disp
== NULL
, "disp != NULL\n");
905 SysFreeString(V_BSTR(&name
));
908 static IHTMLElement
*get_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
, BOOL expect_success
)
910 IHTMLElementCollection
*col
;
912 IDispatch
*disp
= (void*)0xdeadbeef;
916 hres
= IHTMLDocument2_get_all(doc
, &col
);
917 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
918 ok(col
!= NULL
, "col == NULL\n");
919 if(FAILED(hres
) || !col
)
922 V_VT(&index
) = VT_EMPTY
;
923 V_VT(&name
) = VT_BSTR
;
924 V_BSTR(&name
) = SysAllocString(id
);
926 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
927 IHTMLElementCollection_Release(col
);
928 SysFreeString(V_BSTR(&name
));
929 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
930 if(!expect_success
) {
931 ok(disp
== NULL
, "disp != NULL\n");
935 ok(disp
!= NULL
, "disp == NULL\n");
939 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElement
, (void**)&elem
);
940 IDispatch_Release(disp
);
941 ok(hres
== S_OK
, "Could not get IHTMLElement interface: %08x\n", hres
);
946 static IHTMLElement
*get_doc_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
)
948 IHTMLDocument3
*doc3
;
953 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
954 ok(hres
== S_OK
, "Could not get IHTMLDocument3 iface: %08x\n", hres
);
956 tmp
= SysAllocString(id
);
957 hres
= IHTMLDocument3_getElementById(doc3
, tmp
, &elem
);
959 ok(hres
== S_OK
, "getElementById(%s) failed: %08x\n", dbgstr_w(id
), hres
);
961 IHTMLDocument3_Release(doc3
);
966 static void test_select_elem(IHTMLSelectElement
*select
)
968 test_select_length(select
, 2);
969 test_select_selidx(select
, 0);
970 test_select_put_selidx(select
, 1);
973 static void test_create_option_elem(IHTMLDocument2
*doc
)
975 IHTMLOptionElement
*option
;
977 option
= create_option_elem(doc
, "test text", "test value");
979 test_option_put_text(option
, "new text");
980 test_option_put_value(option
, "new value");
982 IHTMLOptionElement_Release(option
);
985 static IHTMLTxtRange
*test_create_body_range(IHTMLDocument2
*doc
)
987 IHTMLBodyElement
*body
;
988 IHTMLTxtRange
*range
;
992 hres
= IHTMLDocument2_get_body(doc
, &elem
);
993 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
995 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
996 IHTMLElement_Release(elem
);
998 hres
= IHTMLBodyElement_createTextRange(body
, &range
);
999 IHTMLBodyElement_Release(body
);
1000 ok(hres
== S_OK
, "createTextRange failed: %08x\n", hres
);
1005 static void test_txtrange(IHTMLDocument2
*doc
)
1007 IHTMLTxtRange
*body_range
, *range
, *range2
;
1008 IHTMLSelectionObject
*selection
;
1009 IDispatch
*disp_range
;
1012 body_range
= test_create_body_range(doc
);
1014 test_range_text(body_range
, "test abc 123\r\nit's text");
1016 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1017 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1019 hres
= IHTMLTxtRange_duplicate(body_range
, &range2
);
1020 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1021 test_range_isequal(range
, range2
, VARIANT_TRUE
);
1023 test_range_text(range
, "test abc 123\r\nit's text");
1024 test_range_text(body_range
, "test abc 123\r\nit's text");
1026 test_range_collapse(range
, TRUE
);
1027 test_range_isequal(range
, range2
, VARIANT_FALSE
);
1028 test_range_inrange(range
, range2
, VARIANT_FALSE
);
1029 test_range_inrange(range2
, range
, VARIANT_TRUE
);
1030 IHTMLTxtRange_Release(range2
);
1032 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1033 test_range_expand(range
, wordW
, VARIANT_FALSE
, "test ");
1034 test_range_move(range
, characterW
, 2, 2);
1035 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1037 test_range_collapse(range
, FALSE
);
1038 test_range_expand(range
, wordW
, VARIANT_TRUE
, "abc ");
1040 test_range_collapse(range
, FALSE
);
1041 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1042 test_range_expand(range
, wordW
, VARIANT_FALSE
, "123");
1043 test_range_move(range
, characterW
, 2, 2);
1044 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1045 test_range_moveend(range
, characterW
, -5, -5);
1046 test_range_text(range
, NULL
);
1047 test_range_moveend(range
, characterW
, 3, 3);
1048 test_range_text(range
, "c 1");
1049 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "test abc 123\r\nit's text");
1050 test_range_collapse(range
, TRUE
);
1051 test_range_move(range
, characterW
, 4, 4);
1052 test_range_moveend(range
, characterW
, 1, 1);
1053 test_range_text(range
, " ");
1054 test_range_move(range
, wordW
, 1, 1);
1055 test_range_moveend(range
, characterW
, 2, 2);
1056 test_range_text(range
, "ab");
1058 IHTMLTxtRange_Release(range
);
1060 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1061 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1063 test_range_text(range
, "test abc 123\r\nit's text");
1064 test_range_move(range
, characterW
, 3, 3);
1065 test_range_moveend(range
, characterW
, 1, 1);
1066 test_range_text(range
, "t");
1067 test_range_moveend(range
, characterW
, 3, 3);
1068 test_range_text(range
, "t ab");
1069 test_range_moveend(range
, characterW
, -2, -2);
1070 test_range_text(range
, "t ");
1071 test_range_move(range
, characterW
, 6, 6);
1072 test_range_moveend(range
, characterW
, 3, 3);
1073 test_range_text(range
, "123");
1074 test_range_moveend(range
, characterW
, 2, 2);
1075 test_range_text(range
, "123\r\ni");
1077 IHTMLTxtRange_Release(range
);
1079 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1080 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1082 test_range_move(range
, wordW
, 1, 1);
1083 test_range_moveend(range
, characterW
, 2, 2);
1084 test_range_text(range
, "ab");
1086 test_range_move(range
, characterW
, -2, -2);
1087 test_range_moveend(range
, characterW
, 2, 2);
1088 test_range_text(range
, "t ");
1090 test_range_move(range
, wordW
, 3, 3);
1091 test_range_move(range
, wordW
, -2, -2);
1092 test_range_moveend(range
, characterW
, 2, 2);
1093 test_range_text(range
, "ab");
1095 test_range_move(range
, characterW
, -6, -5);
1096 test_range_moveend(range
, characterW
, -1, 0);
1097 test_range_moveend(range
, characterW
, -6, 0);
1098 test_range_move(range
, characterW
, 2, 2);
1099 test_range_moveend(range
, characterW
, 2, 2);
1100 test_range_text(range
, "st");
1101 test_range_moveend(range
, characterW
, -6, -4);
1102 test_range_moveend(range
, characterW
, 2, 2);
1104 IHTMLTxtRange_Release(range
);
1106 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1107 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1109 test_range_move(range
, wordW
, 2, 2);
1110 test_range_moveend(range
, characterW
, 2, 2);
1111 test_range_text(range
, "12");
1113 test_range_move(range
, characterW
, 15, 14);
1114 test_range_move(range
, characterW
, -2, -2);
1115 test_range_moveend(range
, characterW
, 3, 2);
1116 test_range_text(range
, "t");
1117 test_range_moveend(range
, characterW
, -1, -1);
1118 test_range_text(range
, "t");
1119 test_range_expand(range
, wordW
, VARIANT_TRUE
, "text");
1120 test_range_move(range
, characterW
, -2, -2);
1121 test_range_moveend(range
, characterW
, 2, 2);
1122 test_range_text(range
, "s ");
1123 test_range_move(range
, characterW
, 100, 7);
1124 test_range_move(range
, wordW
, 1, 0);
1125 test_range_move(range
, characterW
, -2, -2);
1126 test_range_moveend(range
, characterW
, 3, 2);
1127 test_range_text(range
, "t");
1129 IHTMLTxtRange_Release(range
);
1131 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1132 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1134 test_range_collapse(range
, TRUE
);
1135 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1136 test_range_put_text(range
, "word");
1137 test_range_text(body_range
, "wordabc 123\r\nit's text");
1138 test_range_text(range
, NULL
);
1139 test_range_moveend(range
, characterW
, 3, 3);
1140 test_range_text(range
, "abc");
1141 test_range_movestart(range
, characterW
, -2, -2);
1142 test_range_text(range
, "rdabc");
1143 test_range_movestart(range
, characterW
, 3, 3);
1144 test_range_text(range
, "bc");
1145 test_range_movestart(range
, characterW
, 4, 4);
1146 test_range_text(range
, NULL
);
1147 test_range_movestart(range
, characterW
, -3, -3);
1148 test_range_text(range
, "c 1");
1149 test_range_movestart(range
, characterW
, -7, -6);
1150 test_range_text(range
, "wordabc 1");
1151 test_range_movestart(range
, characterW
, 100, 22);
1152 test_range_text(range
, NULL
);
1154 IHTMLTxtRange_Release(range
);
1155 IHTMLTxtRange_Release(body_range
);
1157 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1158 ok(hres
== S_OK
, "IHTMLDocument2_get_selection failed: %08x\n", hres
);
1160 hres
= IHTMLSelectionObject_createRange(selection
, &disp_range
);
1161 ok(hres
== S_OK
, "IHTMLSelectionObject_createRange failed: %08x\n", hres
);
1162 IHTMLSelectionObject_Release(selection
);
1164 hres
= IDispatch_QueryInterface(disp_range
, &IID_IHTMLTxtRange
, (void **)&range
);
1165 ok(hres
== S_OK
, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres
);
1166 IDispatch_Release(disp_range
);
1168 test_range_text(range
, NULL
);
1169 test_range_moveend(range
, characterW
, 3, 3);
1170 test_range_text(range
, "wor");
1171 test_range_parent(range
, ET_BODY
);
1172 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1173 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1174 test_range_move(range
, characterW
, 3, 3);
1175 test_range_expand(range
, wordW
, VARIANT_TRUE
, "wordabc ");
1176 test_range_moveend(range
, characterW
, -4, -4);
1177 test_range_put_text(range
, "abc def ");
1178 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "abc def abc 123\r\nit's text");
1179 test_range_move(range
, wordW
, 1, 1);
1180 test_range_movestart(range
, characterW
, -1, -1);
1181 test_range_text(range
, " ");
1182 test_range_move(range
, wordW
, 1, 1);
1183 test_range_moveend(range
, characterW
, 3, 3);
1184 test_range_text(range
, "def");
1185 test_range_put_text(range
, "xyz");
1186 test_range_moveend(range
, characterW
, 1, 1);
1187 test_range_move(range
, wordW
, 1, 1);
1188 test_range_moveend(range
, characterW
, 2, 2);
1189 test_range_text(range
, "ab");
1191 IHTMLTxtRange_Release(range
);
1194 static void test_txtrange2(IHTMLDocument2
*doc
)
1196 IHTMLTxtRange
*range
;
1198 range
= test_create_body_range(doc
);
1200 test_range_text(range
, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1201 test_range_move(range
, characterW
, 5, 5);
1202 test_range_moveend(range
, characterW
, 1, 1);
1203 test_range_text(range
, "2");
1204 test_range_move(range
, characterW
, -3, -3);
1205 test_range_moveend(range
, characterW
, 3, 3);
1206 test_range_text(range
, "c\r\n\r\n1");
1207 test_range_collapse(range
, VARIANT_FALSE
);
1208 test_range_moveend(range
, characterW
, 4, 4);
1209 test_range_text(range
, "23");
1210 test_range_moveend(range
, characterW
, 1, 1);
1211 test_range_text(range
, "23\r\n\r\n\r\nd");
1212 test_range_moveend(range
, characterW
, -1, -1);
1213 test_range_text(range
, "23");
1214 test_range_moveend(range
, characterW
, -1, -1);
1215 test_range_text(range
, "23");
1216 test_range_moveend(range
, characterW
, -2, -2);
1217 test_range_text(range
, "2");
1219 IHTMLTxtRange_Release(range
);
1222 static void test_compatmode(IHTMLDocument2
*doc
)
1224 IHTMLDocument5
*doc5
;
1228 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
1229 ok(hres
== S_OK
, "Could not get IHTMLDocument5 interface: %08x\n", hres
);
1233 hres
= IHTMLDocument5_get_compatMode(doc5
, &mode
);
1234 IHTMLDocument5_Release(doc5
);
1235 ok(hres
== S_OK
, "get_compatMode failed: %08x\n", hres
);
1236 ok(!strcmp_wa(mode
, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode
));
1237 SysFreeString(mode
);
1240 static void test_location(IHTMLDocument2
*doc
)
1242 IHTMLLocation
*location
, *location2
;
1246 hres
= IHTMLDocument2_get_location(doc
, &location
);
1247 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1249 hres
= IHTMLDocument2_get_location(doc
, &location2
);
1250 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1252 ok(location
== location2
, "location != location2\n");
1254 test_ifaces((IUnknown
*)location
, location_iids
);
1256 IHTMLLocation_Release(location2
);
1257 ref
= IHTMLLocation_Release(location
);
1258 ok(!ref
, "location chould be destroyed here\n");
1261 static void test_navigator(IHTMLDocument2
*doc
)
1263 IHTMLWindow2
*window
;
1264 IOmNavigator
*navigator
, *navigator2
;
1268 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1269 ok(hres
== S_OK
, "parentWidnow failed: %08x\n", hres
);
1271 hres
= IHTMLWindow2_get_navigator(window
, &navigator
);
1272 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1273 ok(navigator
!= NULL
, "navigator == NULL\n");
1274 test_disp((IUnknown
*)navigator
, &IID_IOmNavigator
);
1276 hres
= IHTMLWindow2_get_navigator(window
, &navigator2
);
1277 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1278 ok(navigator
!= navigator2
, "navigator2 != navihgator\n");
1280 IHTMLWindow2_Release(window
);
1281 IOmNavigator_Release(navigator2
);
1282 ref
= IOmNavigator_Release(navigator
);
1283 ok(!ref
, "navigator should be destroyed here\n");
1286 static void test_default_style(IHTMLStyle
*style
)
1293 test_disp((IUnknown
*)style
, &DIID_DispHTMLStyle
);
1295 str
= (void*)0xdeadbeef;
1296 hres
= IHTMLStyle_get_fontFamily(style
, &str
);
1297 ok(hres
== S_OK
, "get_fontFamily failed: %08x\n", hres
);
1298 ok(!str
, "fontFamily = %s\n", dbgstr_w(str
));
1300 str
= (void*)0xdeadbeef;
1301 hres
= IHTMLStyle_get_fontWeight(style
, &str
);
1302 ok(hres
== S_OK
, "get_fontWeight failed: %08x\n", hres
);
1303 ok(!str
, "fontWeight = %s\n", dbgstr_w(str
));
1305 str
= (void*)0xdeadbeef;
1306 hres
= IHTMLStyle_get_display(style
, &str
);
1307 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
1308 ok(!str
, "display = %s\n", dbgstr_w(str
));
1310 str
= (void*)0xdeadbeef;
1311 hres
= IHTMLStyle_get_visibility(style
, &str
);
1312 ok(hres
== S_OK
, "get_visibility failed: %08x\n", hres
);
1313 ok(!str
, "visibility = %s\n", dbgstr_w(str
));
1316 hres
= IHTMLStyle_get_fontSize(style
, &v
);
1317 ok(hres
== S_OK
, "get_fontSize failed: %08x\n", hres
);
1318 ok(V_VT(&v
) == VT_BSTR
, "V_VT(fontSize) = %d\n", V_VT(&v
));
1319 ok(!V_BSTR(&v
), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v
)));
1322 hres
= IHTMLStyle_get_color(style
, &v
);
1323 ok(hres
== S_OK
, "get_color failed: %08x\n", hres
);
1324 ok(V_VT(&v
) == VT_BSTR
, "V_VT(color) = %d\n", V_VT(&v
));
1325 ok(!V_BSTR(&v
), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v
)));
1328 hres
= IHTMLStyle_get_textDecorationUnderline(style
, &b
);
1329 ok(hres
== S_OK
, "get_textDecorationUnderline failed: %08x\n", hres
);
1330 ok(b
== VARIANT_FALSE
, "textDecorationUnderline = %x\n", b
);
1333 hres
= IHTMLStyle_get_textDecorationLineThrough(style
, &b
);
1334 ok(hres
== S_OK
, "get_textDecorationLineThrough failed: %08x\n", hres
);
1335 ok(b
== VARIANT_FALSE
, "textDecorationLineThrough = %x\n", b
);
1338 static void test_default_selection(IHTMLDocument2
*doc
)
1340 IHTMLSelectionObject
*selection
;
1341 IHTMLTxtRange
*range
;
1346 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1347 ok(hres
== S_OK
, "get_selection failed: %08x\n", hres
);
1349 hres
= IHTMLSelectionObject_get_type(selection
, &str
);
1350 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
1351 ok(!lstrcmpW(str
, noneW
), "type = %s\n", dbgstr_w(str
));
1354 hres
= IHTMLSelectionObject_createRange(selection
, &disp
);
1355 IHTMLSelectionObject_Release(selection
);
1356 ok(hres
== S_OK
, "createRange failed: %08x\n", hres
);
1358 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLTxtRange
, (void**)&range
);
1359 IDispatch_Release(disp
);
1360 ok(hres
== S_OK
, "Could not get IHTMLTxtRange interface: %08x\n", hres
);
1362 test_range_text(range
, NULL
);
1363 IHTMLTxtRange_Release(range
);
1366 static void test_default_body(IHTMLBodyElement
*body
)
1371 bstr
= (void*)0xdeadbeef;
1372 hres
= IHTMLBodyElement_get_background(body
, &bstr
);
1373 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
1374 ok(bstr
== NULL
, "bstr != NULL\n");
1377 static void test_window(IHTMLDocument2
*doc
)
1379 IHTMLWindow2
*window
;
1380 IHTMLDocument2
*doc2
= NULL
;
1383 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1384 ok(hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
1385 test_ifaces((IUnknown
*)window
, window_iids
);
1386 test_disp((IUnknown
*)window
, &DIID_DispHTMLWindow2
);
1388 hres
= IHTMLWindow2_get_document(window
, &doc2
);
1389 ok(hres
== S_OK
, "get_document failed: %08x\n", hres
);
1390 ok(doc2
!= NULL
, "doc2 == NULL\n");
1392 IHTMLDocument_Release(doc2
);
1393 IHTMLWindow2_Release(window
);
1396 static void test_defaults(IHTMLDocument2
*doc
)
1398 IHTMLStyleSheetsCollection
*stylesheetcol
;
1399 IHTMLBodyElement
*body
;
1405 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1406 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1408 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
1409 ok(hres
== S_OK
, "Could not get IHTMBodyElement: %08x\n", hres
);
1410 test_default_body(body
);
1411 IHTMLBodyElement_Release(body
);
1413 hres
= IHTMLElement_get_style(elem
, &style
);
1414 IHTMLElement_Release(elem
);
1415 ok(hres
== S_OK
, "get_style failed: %08x\n", hres
);
1417 test_default_style(style
);
1419 test_compatmode(doc
);
1421 test_navigator(doc
);
1423 IHTMLStyle_Release(style
);
1425 hres
= IHTMLDocument2_get_styleSheets(doc
, &stylesheetcol
);
1426 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
1429 hres
= IHTMLStyleSheetsCollection_get_length(stylesheetcol
, &l
);
1430 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1431 ok(l
== 0, "length = %ld\n", l
);
1433 IHTMLStyleSheetsCollection_Release(stylesheetcol
);
1435 test_default_selection(doc
);
1438 static void test_stylesheet(IDispatch
*disp
)
1440 IHTMLStyleSheetRulesCollection
*col
= NULL
;
1441 IHTMLStyleSheet
*stylesheet
;
1444 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLStyleSheet
, (void**)&stylesheet
);
1445 ok(hres
== S_OK
, "Could not get IHTMLStyleSheet: %08x\n", hres
);
1447 hres
= IHTMLStyleSheet_get_rules(stylesheet
, &col
);
1448 ok(hres
== S_OK
, "get_rules failed: %08x\n", hres
);
1449 ok(col
!= NULL
, "col == NULL\n");
1451 IHTMLStyleSheetRulesCollection_Release(col
);
1452 IHTMLStyleSheet_Release(stylesheet
);
1455 static void test_stylesheets(IHTMLDocument2
*doc
)
1457 IHTMLStyleSheetsCollection
*col
= NULL
;
1462 hres
= IHTMLDocument2_get_styleSheets(doc
, &col
);
1463 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
1464 ok(col
!= NULL
, "col == NULL\n");
1466 hres
= IHTMLStyleSheetsCollection_get_length(col
, &len
);
1467 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1468 ok(len
== 1, "len=%ld\n", len
);
1474 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
1475 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1476 ok(V_VT(&res
) == VT_DISPATCH
, "V_VT(res) = %d\n", V_VT(&res
));
1477 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
1478 test_stylesheet(V_DISPATCH(&res
));
1485 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
1486 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1487 ok(V_VT(&res
) == VT_EMPTY
, "V_VT(res) = %d\n", V_VT(&res
));
1488 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
1491 IHTMLStyleSheetsCollection_Release(col
);
1494 static void test_elems(IHTMLDocument2
*doc
)
1496 IHTMLElementCollection
*col
;
1497 IHTMLDOMChildrenCollection
*child_col
;
1499 IHTMLDOMNode
*node
, *node2
;
1504 static const WCHAR inW
[] = {'i','n',0};
1505 static const WCHAR xW
[] = {'x',0};
1506 static const WCHAR sW
[] = {'s',0};
1507 static const WCHAR scW
[] = {'s','c',0};
1508 static const WCHAR xxxW
[] = {'x','x','x',0};
1510 static const elem_type_t all_types
[] = {
1529 static const elem_type_t item_types
[] = {
1535 hres
= IHTMLDocument2_get_all(doc
, &col
);
1536 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1537 test_elem_collection(col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
1538 test_elem_col_item(col
, xW
, item_types
, sizeof(item_types
)/sizeof(item_types
[0]));
1539 IHTMLElementCollection_Release(col
);
1541 elem
= get_doc_elem(doc
);
1542 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
1543 hres
= IHTMLElement_get_all(elem
, &disp
);
1544 IHTMLElement_Release(elem
);
1545 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1547 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&col
);
1548 IDispatch_Release(disp
);
1549 ok(hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
1550 test_elem_collection(col
, all_types
+1, sizeof(all_types
)/sizeof(all_types
[0])-1);
1551 IHTMLElementCollection_Release(col
);
1553 get_elem_by_id(doc
, xxxW
, FALSE
);
1554 elem
= get_doc_elem_by_id(doc
, xxxW
);
1555 ok(!elem
, "elem != NULL\n");
1557 elem
= get_doc_elem_by_id(doc
, sW
);
1558 ok(elem
!= NULL
, "elem == NULL\n");
1560 test_elem_type((IUnknown
*)elem
, ET_SELECT
);
1561 test_elem_attr(elem
, xxxW
, NULL
);
1562 test_elem_attr(elem
, idW
, sW
);
1563 IHTMLElement_Release(elem
);
1566 elem
= get_elem_by_id(doc
, sW
, TRUE
);
1568 IHTMLSelectElement
*select
;
1570 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLSelectElement
, (void**)&select
);
1571 ok(hres
== S_OK
, "Could not get IHTMLSelectElement interface: %08x\n", hres
);
1573 test_select_elem(select
);
1575 node
= get_first_child((IUnknown
*)select
);
1576 ok(node
!= NULL
, "node == NULL\n");
1578 test_elem_type((IUnknown
*)node
, ET_OPTION
);
1579 IHTMLDOMNode_Release(node
);
1582 type
= get_node_type((IUnknown
*)select
);
1583 ok(type
== 1, "type=%ld\n", type
);
1585 IHTMLSelectElement_Release(select
);
1586 IHTMLElement_Release(elem
);
1589 elem
= get_elem_by_id(doc
, scW
, TRUE
);
1591 IHTMLScriptElement
*script
;
1594 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLScriptElement
, (void**)&script
);
1595 ok(hres
== S_OK
, "Could not get IHTMLScriptElement interface: %08x\n", hres
);
1597 hres
= IHTMLScriptElement_get_type(script
, &type
);
1598 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
1599 ok(!lstrcmpW(type
, text_javascriptW
), "Unexpected type %s\n", dbgstr_w(type
));
1600 SysFreeString(type
);
1602 IHTMLScriptElement_Release(script
);
1605 elem
= get_elem_by_id(doc
, inW
, TRUE
);
1607 IHTMLInputElement
*input
;
1609 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLInputElement
, (void**)&input
);
1610 ok(hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1612 test_input_get_disabled(input
, VARIANT_FALSE
);
1614 IHTMLInputElement_Release(input
);
1615 IHTMLElement_Release(elem
);
1618 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1619 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1621 node
= get_first_child((IUnknown
*)elem
);
1622 ok(node
!= NULL
, "node == NULL\n");
1624 test_ifaces((IUnknown
*)node
, text_iids
);
1625 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
1627 node2
= get_first_child((IUnknown
*)node
);
1628 ok(!node2
, "node2 != NULL\n");
1630 type
= get_node_type((IUnknown
*)node
);
1631 ok(type
== 3, "type=%ld\n", type
);
1633 IHTMLDOMNode_Release(node
);
1636 child_col
= get_child_nodes((IUnknown
*)elem
);
1637 ok(child_col
!= NULL
, "child_coll == NULL\n");
1641 test_disp((IUnknown
*)child_col
, &DIID_DispDOMChildrenCollection
);
1643 hres
= IHTMLDOMChildrenCollection_get_length(child_col
, &length
);
1644 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1645 ok(length
, "length=0\n");
1647 node
= get_child_item(child_col
, 0);
1648 ok(node
!= NULL
, "node == NULL\n");
1650 type
= get_node_type((IUnknown
*)node
);
1651 ok(type
== 3, "type=%ld\n", type
);
1652 IHTMLDOMNode_Release(node
);
1655 node
= get_child_item(child_col
, 1);
1656 ok(node
!= NULL
, "node == NULL\n");
1658 type
= get_node_type((IUnknown
*)node
);
1659 ok(type
== 8, "type=%ld\n", type
);
1660 IHTMLDOMNode_Release(node
);
1663 disp
= (void*)0xdeadbeef;
1664 hres
= IHTMLDOMChildrenCollection_item(child_col
, 6000, &disp
);
1665 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1666 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
1668 IHTMLDOMChildrenCollection_Release(child_col
);
1671 IHTMLElement_Release(elem
);
1673 test_stylesheets(doc
);
1674 test_create_option_elem(doc
);
1677 static void test_exec(IUnknown
*unk
, const GUID
*grpid
, DWORD cmdid
, VARIANT
*in
, VARIANT
*out
)
1679 IOleCommandTarget
*cmdtrg
;
1682 hres
= IHTMLTxtRange_QueryInterface(unk
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1683 ok(hres
== S_OK
, "Could not get IOleCommandTarget interface: %08x\n", hres
);
1685 hres
= IOleCommandTarget_Exec(cmdtrg
, grpid
, cmdid
, 0, in
, out
);
1686 ok(hres
== S_OK
, "Exec failed: %08x\n", hres
);
1688 IOleCommandTarget_Release(cmdtrg
);
1691 static void test_indent(IHTMLDocument2
*doc
)
1693 IHTMLElementCollection
*col
;
1694 IHTMLTxtRange
*range
;
1697 static const elem_type_t all_types
[] = {
1706 static const elem_type_t indent_types
[] = {
1717 hres
= IHTMLDocument2_get_all(doc
, &col
);
1718 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1719 test_elem_collection(col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
1720 IHTMLElementCollection_Release(col
);
1722 range
= test_create_body_range(doc
);
1723 test_exec((IUnknown
*)range
, &CGID_MSHTML
, IDM_INDENT
, NULL
, NULL
);
1724 IHTMLTxtRange_Release(range
);
1726 hres
= IHTMLDocument2_get_all(doc
, &col
);
1727 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1728 test_elem_collection(col
, indent_types
, sizeof(indent_types
)/sizeof(indent_types
[0]));
1729 IHTMLElementCollection_Release(col
);
1732 static IHTMLDocument2
*notif_doc
;
1733 static BOOL doc_complete
;
1735 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
1736 REFIID riid
, void**ppv
)
1738 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
1743 ok(0, "unexpected call\n");
1744 return E_NOINTERFACE
;
1747 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
1752 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
1757 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
1759 if(dispID
== DISPID_READYSTATE
){
1763 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
1765 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
1766 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
1768 if(!lstrcmpW(state
, completeW
))
1769 doc_complete
= TRUE
;
1771 SysFreeString(state
);
1777 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
1779 ok(0, "unexpected call\n");
1783 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
1784 PropertyNotifySink_QueryInterface
,
1785 PropertyNotifySink_AddRef
,
1786 PropertyNotifySink_Release
,
1787 PropertyNotifySink_OnChanged
,
1788 PropertyNotifySink_OnRequestEdit
1791 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
1793 static IHTMLDocument2
*create_doc_with_string(const char *str
)
1795 IPersistStreamInit
*init
;
1797 IHTMLDocument2
*doc
;
1801 notif_doc
= doc
= create_document();
1805 doc_complete
= FALSE
;
1807 mem
= GlobalAlloc(0, len
);
1808 memcpy(mem
, str
, len
);
1809 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
1811 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
1813 IPersistStreamInit_Load(init
, stream
);
1814 IPersistStreamInit_Release(init
);
1815 IStream_Release(stream
);
1820 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
1822 IConnectionPointContainer
*container
;
1823 IConnectionPoint
*cp
;
1827 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
1828 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
1830 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
1831 IConnectionPointContainer_Release(container
);
1832 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
1834 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
1835 IConnectionPoint_Release(cp
);
1836 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
1839 typedef void (*domtest_t
)(IHTMLDocument2
*);
1841 static void run_domtest(const char *str
, domtest_t test
)
1843 IHTMLDocument2
*doc
;
1844 IHTMLElement
*body
= NULL
;
1849 doc
= create_doc_with_string(str
);
1850 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
1852 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
1853 TranslateMessage(&msg
);
1854 DispatchMessage(&msg
);
1857 hres
= IHTMLDocument2_get_body(doc
, &body
);
1858 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1861 IHTMLElement_Release(body
);
1864 skip("Could not get document body. Assuming no Gecko installed.\n");
1867 ref
= IHTMLDocument2_Release(doc
);
1868 ok(!ref
, "ref = %d\n", ref
);
1871 static void gecko_installer_workaround(BOOL disable
)
1876 static BOOL has_url
= FALSE
;
1877 static char url
[2048];
1879 if(!disable
&& !has_url
)
1882 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
1883 if(res
!= ERROR_SUCCESS
)
1887 DWORD type
, size
= sizeof(url
);
1889 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
1890 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
1893 RegDeleteValue(hkey
, "GeckoUrl");
1895 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
1903 gecko_installer_workaround(TRUE
);
1906 run_domtest(doc_str1
, test_doc_elem
);
1907 run_domtest(range_test_str
, test_txtrange
);
1908 run_domtest(range_test2_str
, test_txtrange2
);
1909 run_domtest(elem_test_str
, test_elems
);
1910 run_domtest(doc_blank
, test_defaults
);
1911 run_domtest(indent_test_str
, test_indent
);
1914 gecko_installer_workaround(FALSE
);