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>"
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};
89 static REFIID
const none_iids
[] = {
94 static REFIID
const elem_iids
[] = {
100 &IID_IConnectionPointContainer
,
104 static REFIID
const body_iids
[] = {
109 &IID_IHTMLTextContainer
,
110 &IID_IHTMLBodyElement
,
112 &IID_IConnectionPointContainer
,
116 static REFIID
const anchor_iids
[] = {
121 &IID_IHTMLAnchorElement
,
123 &IID_IConnectionPointContainer
,
127 static REFIID
const input_iids
[] = {
132 &IID_IHTMLInputElement
,
133 &IID_IHTMLInputTextElement
,
135 &IID_IConnectionPointContainer
,
139 static REFIID
const select_iids
[] = {
144 &IID_IHTMLSelectElement
,
146 &IID_IConnectionPointContainer
,
150 static REFIID
const textarea_iids
[] = {
155 &IID_IHTMLTextAreaElement
,
157 &IID_IConnectionPointContainer
,
161 static REFIID
const option_iids
[] = {
166 &IID_IHTMLOptionElement
,
168 &IID_IConnectionPointContainer
,
172 static REFIID
const table_iids
[] = {
179 &IID_IConnectionPointContainer
,
183 static REFIID
const script_iids
[] = {
188 &IID_IHTMLScriptElement
,
190 &IID_IConnectionPointContainer
,
194 static REFIID
const text_iids
[] = {
197 &IID_IHTMLDOMTextNode
,
201 static REFIID
const location_iids
[] = {
207 static REFIID
const window_iids
[] = {
215 static REFIID
const comment_iids
[] = {
220 &IID_IHTMLCommentElement
,
222 &IID_IConnectionPointContainer
,
226 static REFIID
const img_iids
[] = {
232 &IID_IHTMLImgElement
,
233 &IID_IConnectionPointContainer
,
243 static const elem_type_info_t elem_type_infos
[] = {
244 {"", none_iids
, NULL
},
245 {"HTML", elem_iids
, NULL
},
246 {"HEAD", elem_iids
, NULL
},
247 {"TITLE", elem_iids
, NULL
},
248 {"BODY", body_iids
, NULL
},
249 {"A", anchor_iids
, NULL
},
250 {"INPUT", input_iids
, &DIID_DispHTMLInputElement
},
251 {"SELECT", select_iids
, NULL
},
252 {"TEXTAREA", textarea_iids
, NULL
},
253 {"OPTION", option_iids
, &DIID_DispHTMLOptionElement
},
254 {"STYLE", elem_iids
, NULL
},
255 {"BLOCKQUOTE",elem_iids
, NULL
},
256 {"P", elem_iids
, NULL
},
257 {"BR", elem_iids
, NULL
},
258 {"TABLE", table_iids
, NULL
},
259 {"TBODY", elem_iids
, NULL
},
260 {"SCRIPT", script_iids
, NULL
},
261 {"TEST", elem_iids
, &DIID_DispHTMLUnknownElement
},
262 {"!", comment_iids
, &DIID_DispHTMLCommentElement
},
263 {"IMG", img_iids
, &DIID_DispHTMLImg
}
266 static const char *dbgstr_w(LPCWSTR str
)
268 static char buf
[512];
271 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
275 static const char *dbgstr_guid(REFIID riid
)
279 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
280 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
281 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
282 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
287 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
290 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
291 return lstrcmpW(strw
, buf
);
294 static BSTR
a2bstr(const char *str
)
299 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
300 ret
= SysAllocStringLen(NULL
, len
);
301 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
306 static IHTMLDocument2
*create_document(void)
311 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
312 &IID_IHTMLDocument2
, (void**)&doc
);
313 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
318 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
319 static void _test_ifaces(unsigned line
, IUnknown
*iface
, REFIID
*iids
)
321 const IID
* const *piid
;
325 for(piid
= iids
; *piid
; piid
++) {
326 hres
= IDispatch_QueryInterface(iface
, *piid
, (void**)&unk
);
327 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get %s interface: %08x\n", dbgstr_guid(*piid
), hres
);
329 IUnknown_Release(unk
);
333 #define test_disp(u,id) _test_disp(__LINE__,u,id)
334 static void _test_disp(unsigned line
, IUnknown
*unk
, const IID
*diid
)
341 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
342 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IDispatch: %08x\n", hres
);
347 hres
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
348 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfoCount failed: %08x\n", hres
);
349 ok_(__FILE__
,line
) (ticnt
== 1, "ticnt=%u\n", ticnt
);
351 hres
= IDispatchEx_GetTypeInfo(dispex
, 0, 0, &typeinfo
);
352 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfo failed: %08x\n", hres
);
354 if(SUCCEEDED(hres
)) {
357 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &type_attr
);
358 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeAttr failed: %08x\n", hres
);
359 ok_(__FILE__
,line
) (IsEqualGUID(&type_attr
->guid
, diid
), "unexpected guid %s\n", dbgstr_guid(&type_attr
->guid
));
361 ITypeInfo_ReleaseTypeAttr(typeinfo
, type_attr
);
362 ITypeInfo_Release(typeinfo
);
365 IDispatchEx_Release(dispex
);
368 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
369 static void _test_node_name(unsigned line
, IUnknown
*unk
, const char *exname
)
375 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
376 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres
);
378 hres
= IHTMLDOMNode_get_nodeName(node
, &name
);
379 IHTMLDOMNode_Release(node
);
380 ok_(__FILE__
, line
) (hres
== S_OK
, "get_nodeName failed: %08x\n", hres
);
381 ok_(__FILE__
, line
) (!strcmp_wa(name
, exname
), "got name: %s, expected %s\n", dbgstr_w(name
), exname
);
386 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
387 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
393 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
394 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres
);
396 hres
= IHTMLElement_get_tagName(elem
, &tag
);
397 IHTMLElement_Release(elem
);
398 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
399 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", dbgstr_w(tag
), extag
);
404 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
405 static void _test_elem_type(unsigned line
, IUnknown
*unk
, elem_type_t type
)
407 _test_elem_tag(line
, unk
, elem_type_infos
[type
].tag
);
408 _test_ifaces(line
, unk
, elem_type_infos
[type
].iids
);
410 if(elem_type_infos
[type
].dispiid
)
411 _test_disp(line
, unk
, elem_type_infos
[type
].dispiid
);
414 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
415 static void _test_elem_attr(unsigned line
, IHTMLElement
*elem
, LPCWSTR name
, LPCWSTR exval
)
423 tmp
= SysAllocString(name
);
424 hres
= IHTMLElement_getAttribute(elem
, tmp
, 0, &value
);
426 ok_(__FILE__
,line
) (hres
== S_OK
, "getAttribute failed: %08x\n", hres
);
429 ok_(__FILE__
,line
) (V_VT(&value
) == VT_BSTR
, "vt=%d\n", V_VT(&value
));
430 ok_(__FILE__
,line
) (!lstrcmpW(exval
, V_BSTR(&value
)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value
)));
432 ok_(__FILE__
,line
) (V_VT(&value
) == VT_NULL
, "vt=%d\n", V_VT(&value
));
435 VariantClear(&value
);
438 static void test_doc_elem(IHTMLDocument2
*doc
)
441 IHTMLDocument3
*doc3
;
444 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
445 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres
);
447 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
448 IHTMLDocument3_Release(doc3
);
449 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
451 test_node_name((IUnknown
*)elem
, "HTML");
452 test_elem_tag((IUnknown
*)elem
, "HTML");
454 IHTMLElement_Release(elem
);
457 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
458 static IHTMLElement
*_get_doc_elem(unsigned line
, IHTMLDocument2
*doc
)
461 IHTMLDocument3
*doc3
;
464 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
465 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 interface: %08x\n", hres
);
466 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
467 ok_(__FILE__
,line
) (hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
468 IHTMLDocument3_Release(doc3
);
473 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
474 static void _test_option_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
479 hres
= IHTMLOptionElement_get_text(option
, &bstr
);
480 ok_(__FILE__
,line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
481 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, text
), "text=%s\n", dbgstr_w(bstr
));
485 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
486 static void _test_option_put_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
492 hres
= IHTMLOptionElement_put_text(option
, bstr
);
494 ok(hres
== S_OK
, "put_text failed: %08x\n", hres
);
496 _test_option_text(line
, option
, text
);
499 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
500 static void _test_option_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
505 hres
= IHTMLOptionElement_get_value(option
, &bstr
);
506 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
507 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, value
), "value=%s\n", dbgstr_w(bstr
));
511 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
512 static void _test_option_put_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
517 bstr
= a2bstr(value
);
518 hres
= IHTMLOptionElement_put_value(option
, bstr
);
520 ok(hres
== S_OK
, "put_value failed: %08x\n", hres
);
522 _test_option_value(line
, option
, value
);
525 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
526 static IHTMLOptionElement
*_create_option_elem(unsigned line
, IHTMLDocument2
*doc
,
527 const char *txt
, const char *val
)
529 IHTMLOptionElementFactory
*factory
;
530 IHTMLOptionElement
*option
;
531 IHTMLWindow2
*window
;
532 VARIANT text
, value
, empty
;
535 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
536 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
538 hres
= IHTMLWindow2_get_Option(window
, &factory
);
539 IHTMLWindow2_Release(window
);
540 ok_(__FILE__
,line
) (hres
== S_OK
, "get_Option failed: %08x\n", hres
);
542 V_VT(&text
) = VT_BSTR
;
543 V_BSTR(&text
) = a2bstr(txt
);
544 V_VT(&value
) = VT_BSTR
;
545 V_BSTR(&value
) = a2bstr(val
);
546 V_VT(&empty
) = VT_EMPTY
;
548 hres
= IHTMLOptionElementFactory_create(factory
, text
, value
, empty
, empty
, &option
);
549 ok_(__FILE__
,line
) (hres
== S_OK
, "create failed: %08x\n", hres
);
551 IHTMLOptionElementFactory_Release(factory
);
553 VariantClear(&value
);
555 _test_option_text(line
, option
, txt
);
556 _test_option_value(line
, option
, val
);
561 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
562 static void _test_select_length(unsigned line
, IHTMLSelectElement
*select
, long length
)
564 long len
= 0xdeadbeef;
567 hres
= IHTMLSelectElement_get_length(select
, &len
);
568 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
569 ok_(__FILE__
,line
) (len
== length
, "len=%ld, expected %ld\n", len
, length
);
572 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
573 static void _test_select_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
575 long idx
= 0xdeadbeef;
578 hres
= IHTMLSelectElement_get_selectedIndex(select
, &idx
);
579 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
580 ok_(__FILE__
,line
) (idx
== index
, "idx=%ld, expected %ld\n", idx
, index
);
583 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
584 static void _test_select_put_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
588 hres
= IHTMLSelectElement_put_selectedIndex(select
, index
);
589 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
590 _test_select_selidx(line
, select
, index
);
593 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
594 static void _test_range_text(unsigned line
, IHTMLTxtRange
*range
, const char *extext
)
599 hres
= IHTMLTxtRange_get_text(range
, &text
);
600 ok_(__FILE__
, line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
603 ok_(__FILE__
, line
) (text
!= NULL
, "text == NULL\n");
604 ok_(__FILE__
, line
) (!strcmp_wa(text
, extext
), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text
), extext
);
606 ok_(__FILE__
, line
) (text
== NULL
, "text=\"%s\", expected NULL\n", dbgstr_w(text
));
613 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
614 static void _test_range_collapse(unsigned line
, IHTMLTxtRange
*range
, BOOL b
)
618 hres
= IHTMLTxtRange_collapse(range
, b
);
619 ok_(__FILE__
, line
) (hres
== S_OK
, "collapse failed: %08x\n", hres
);
620 _test_range_text(line
, range
, NULL
);
623 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
624 static void _test_range_expand(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
,
625 VARIANT_BOOL exb
, const char *extext
)
627 VARIANT_BOOL b
= 0xe0e0;
630 hres
= IHTMLTxtRange_expand(range
, unit
, &b
);
631 ok_(__FILE__
,line
) (hres
== S_OK
, "expand failed: %08x\n", hres
);
632 ok_(__FILE__
,line
) (b
== exb
, "b=%x, expected %x\n", b
, exb
);
633 _test_range_text(line
, range
, extext
);
636 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
637 static void _test_range_move(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
642 hres
= IHTMLTxtRange_move(range
, unit
, cnt
, &c
);
643 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
644 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
645 _test_range_text(line
, range
, NULL
);
648 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
649 static void _test_range_movestart(unsigned line
, IHTMLTxtRange
*range
,
650 LPWSTR unit
, long cnt
, long excnt
)
655 hres
= IHTMLTxtRange_moveStart(range
, unit
, cnt
, &c
);
656 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
657 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
660 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
661 static void _test_range_moveend(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
666 hres
= IHTMLTxtRange_moveEnd(range
, unit
, cnt
, &c
);
667 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
668 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
671 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
672 static void _test_range_put_text(unsigned line
, IHTMLTxtRange
*range
, const char *text
)
675 BSTR bstr
= a2bstr(text
);
677 hres
= IHTMLTxtRange_put_text(range
, bstr
);
678 ok_(__FILE__
,line
) (hres
== S_OK
, "put_text failed: %08x\n", hres
);
680 _test_range_text(line
, range
, NULL
);
683 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
684 static void _test_range_inrange(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
690 hres
= IHTMLTxtRange_inRange(range1
, range2
, &b
);
691 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
692 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
695 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
696 static void _test_range_isequal(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
702 hres
= IHTMLTxtRange_isEqual(range1
, range2
, &b
);
703 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
704 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
707 hres
= IHTMLTxtRange_isEqual(range2
, range1
, &b
);
708 ok_(__FILE__
,line
) (hres
== S_OK
, "(2->1) isEqual failed: %08x\n", hres
);
709 ok_(__FILE__
,line
) (b
== exb
, "(2->1) b=%x, expected %x\n", b
, exb
);
712 test_range_inrange(range1
, range2
, VARIANT_TRUE
);
713 test_range_inrange(range2
, range1
, VARIANT_TRUE
);
717 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
718 static void _test_range_parent(unsigned line
, IHTMLTxtRange
*range
, elem_type_t type
)
723 hres
= IHTMLTxtRange_parentElement(range
, &elem
);
724 ok_(__FILE__
,line
) (hres
== S_OK
, "parentElement failed: %08x\n", hres
);
726 _test_elem_type(line
, (IUnknown
*)elem
, type
);
728 IHTMLElement_Release(elem
);
731 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
732 static void _test_elem_collection(unsigned line
, IHTMLElementCollection
*col
,
733 const elem_type_t
*elem_types
, long exlen
)
741 test_disp((IUnknown
*)col
, &DIID_DispHTMLElementCollection
);
743 hres
= IHTMLElementCollection_get_length(col
, &len
);
744 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
745 ok_(__FILE__
,line
) (len
== exlen
, "len=%ld, expected %ld\n", len
, exlen
);
750 V_VT(&index
) = VT_EMPTY
;
753 for(i
=0; i
<len
; i
++) {
755 disp
= (void*)0xdeadbeef;
756 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
757 ok_(__FILE__
,line
) (hres
== S_OK
, "item(%d) failed: %08x\n", i
, hres
);
758 ok_(__FILE__
,line
) (disp
!= NULL
, "item returned NULL\n");
759 if(FAILED(hres
) || !disp
)
762 _test_elem_type(line
, (IUnknown
*)disp
, elem_types
[i
]);
763 IDispatch_Release(disp
);
767 disp
= (void*)0xdeadbeef;
768 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
769 ok_(__FILE__
,line
) (hres
== S_OK
, "item failed: %08x\n", hres
);
770 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
773 disp
= (void*)0xdeadbeef;
774 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
775 ok_(__FILE__
,line
) (hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
776 ok_(__FILE__
,line
) (disp
== NULL
, "disp != NULL\n");
779 #define get_first_child(n) _get_first_child(__LINE__,n)
780 static IHTMLDOMNode
*_get_first_child(unsigned line
, IUnknown
*unk
)
782 IHTMLDOMNode
*node
, *child
= NULL
;
785 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
786 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
790 hres
= IHTMLDOMNode_get_firstChild(node
, &child
);
791 IHTMLDOMNode_Release(node
);
792 ok_(__FILE__
,line
) (hres
== S_OK
, "get_firstChild failed: %08x\n", hres
);
797 #define get_node_type(n) _get_node_type(__LINE__,n)
798 static long _get_node_type(unsigned line
, IUnknown
*unk
)
804 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
805 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
807 hres
= IHTMLDOMNode_get_nodeType(node
, &type
);
808 ok(hres
== S_OK
, "get_nodeType failed: %08x\n", hres
);
810 IHTMLDOMNode_Release(node
);
815 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
816 static void _test_input_get_disabled(unsigned line
, IHTMLInputElement
*input
, VARIANT_BOOL exb
)
818 VARIANT_BOOL disabled
= 100;
821 hres
= IHTMLInputElement_get_disabled(input
, &disabled
);
822 ok_(__FILE__
,line
) (hres
== S_OK
, "get_disabled failed: %08x\n", hres
);
823 ok_(__FILE__
,line
) (disabled
== exb
, "disabled=%x, expected %x\n", disabled
, exb
);
826 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
827 static IHTMLDOMChildrenCollection
*_get_child_nodes(unsigned line
, IUnknown
*unk
)
829 IHTMLDOMChildrenCollection
*col
= NULL
;
834 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
835 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
839 hres
= IHTMLDOMNode_get_childNodes(node
, &disp
);
840 IHTMLDOMNode_Release(node
);
841 ok_(__FILE__
,line
) (hres
== S_OK
, "get_childNodes failed: %08x\n", hres
);
845 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMChildrenCollection
, (void**)&col
);
846 IDispatch_Release(disp
);
847 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres
);
852 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
853 static IHTMLDOMNode
*_get_child_item(unsigned line
, IHTMLDOMChildrenCollection
*col
, long idx
)
855 IHTMLDOMNode
*node
= NULL
;
859 hres
= IHTMLDOMChildrenCollection_item(col
, idx
, &disp
);
860 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
862 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLDOMNode
, (void**)&node
);
863 IDispatch_Release(disp
);
864 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDOMNode: %08x\n", hres
);
869 static void test_elem_col_item(IHTMLElementCollection
*col
, LPCWSTR n
,
870 const elem_type_t
*elem_types
, long len
)
872 IHTMLElementCollection
*elcol
;
878 V_VT(&index
) = VT_EMPTY
;
879 V_VT(&name
) = VT_BSTR
;
880 V_BSTR(&name
) = SysAllocString(n
);
882 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
883 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
885 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&elcol
);
886 IDispatch_Release(disp
);
887 ok(hres
== S_OK
, "Could not get IHTMLElementCollection interface: %08x\n", hres
);
891 test_elem_collection(elcol
, elem_types
, len
);
892 IHTMLElementCollection_Release(elcol
);
894 V_VT(&index
) = VT_I4
;
896 for(i
=0; i
<len
; i
++) {
898 disp
= (void*)0xdeadbeef;
899 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
900 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
901 ok(disp
!= NULL
, "disp == NULL\n");
902 if(FAILED(hres
) || !disp
)
905 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
907 IDispatch_Release(disp
);
911 disp
= (void*)0xdeadbeef;
912 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
913 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
914 ok(disp
== NULL
, "disp != NULL\n");
917 disp
= (void*)0xdeadbeef;
918 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
919 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
920 ok(disp
== NULL
, "disp != NULL\n");
923 SysFreeString(V_BSTR(&name
));
926 static IHTMLElement
*get_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
, BOOL expect_success
)
928 IHTMLElementCollection
*col
;
930 IDispatch
*disp
= (void*)0xdeadbeef;
934 hres
= IHTMLDocument2_get_all(doc
, &col
);
935 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
936 ok(col
!= NULL
, "col == NULL\n");
937 if(FAILED(hres
) || !col
)
940 V_VT(&index
) = VT_EMPTY
;
941 V_VT(&name
) = VT_BSTR
;
942 V_BSTR(&name
) = SysAllocString(id
);
944 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
945 IHTMLElementCollection_Release(col
);
946 SysFreeString(V_BSTR(&name
));
947 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
948 if(!expect_success
) {
949 ok(disp
== NULL
, "disp != NULL\n");
953 ok(disp
!= NULL
, "disp == NULL\n");
957 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElement
, (void**)&elem
);
958 IDispatch_Release(disp
);
959 ok(hres
== S_OK
, "Could not get IHTMLElement interface: %08x\n", hres
);
964 static IHTMLElement
*get_doc_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
)
966 IHTMLDocument3
*doc3
;
971 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
972 ok(hres
== S_OK
, "Could not get IHTMLDocument3 iface: %08x\n", hres
);
974 tmp
= SysAllocString(id
);
975 hres
= IHTMLDocument3_getElementById(doc3
, tmp
, &elem
);
977 ok(hres
== S_OK
, "getElementById(%s) failed: %08x\n", dbgstr_w(id
), hres
);
979 IHTMLDocument3_Release(doc3
);
984 static void test_select_elem(IHTMLSelectElement
*select
)
986 test_select_length(select
, 2);
987 test_select_selidx(select
, 0);
988 test_select_put_selidx(select
, 1);
991 static void test_create_option_elem(IHTMLDocument2
*doc
)
993 IHTMLOptionElement
*option
;
995 option
= create_option_elem(doc
, "test text", "test value");
997 test_option_put_text(option
, "new text");
998 test_option_put_value(option
, "new value");
1000 IHTMLOptionElement_Release(option
);
1003 static IHTMLTxtRange
*test_create_body_range(IHTMLDocument2
*doc
)
1005 IHTMLBodyElement
*body
;
1006 IHTMLTxtRange
*range
;
1010 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1011 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1013 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
1014 IHTMLElement_Release(elem
);
1016 hres
= IHTMLBodyElement_createTextRange(body
, &range
);
1017 IHTMLBodyElement_Release(body
);
1018 ok(hres
== S_OK
, "createTextRange failed: %08x\n", hres
);
1023 static void test_txtrange(IHTMLDocument2
*doc
)
1025 IHTMLTxtRange
*body_range
, *range
, *range2
;
1026 IHTMLSelectionObject
*selection
;
1027 IDispatch
*disp_range
;
1030 body_range
= test_create_body_range(doc
);
1032 test_range_text(body_range
, "test abc 123\r\nit's text");
1034 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1035 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1037 hres
= IHTMLTxtRange_duplicate(body_range
, &range2
);
1038 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1039 test_range_isequal(range
, range2
, VARIANT_TRUE
);
1041 test_range_text(range
, "test abc 123\r\nit's text");
1042 test_range_text(body_range
, "test abc 123\r\nit's text");
1044 test_range_collapse(range
, TRUE
);
1045 test_range_isequal(range
, range2
, VARIANT_FALSE
);
1046 test_range_inrange(range
, range2
, VARIANT_FALSE
);
1047 test_range_inrange(range2
, range
, VARIANT_TRUE
);
1048 IHTMLTxtRange_Release(range2
);
1050 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1051 test_range_expand(range
, wordW
, VARIANT_FALSE
, "test ");
1052 test_range_move(range
, characterW
, 2, 2);
1053 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1055 test_range_collapse(range
, FALSE
);
1056 test_range_expand(range
, wordW
, VARIANT_TRUE
, "abc ");
1058 test_range_collapse(range
, FALSE
);
1059 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1060 test_range_expand(range
, wordW
, VARIANT_FALSE
, "123");
1061 test_range_move(range
, characterW
, 2, 2);
1062 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
1063 test_range_moveend(range
, characterW
, -5, -5);
1064 test_range_text(range
, NULL
);
1065 test_range_moveend(range
, characterW
, 3, 3);
1066 test_range_text(range
, "c 1");
1067 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "test abc 123\r\nit's text");
1068 test_range_collapse(range
, TRUE
);
1069 test_range_move(range
, characterW
, 4, 4);
1070 test_range_moveend(range
, characterW
, 1, 1);
1071 test_range_text(range
, " ");
1072 test_range_move(range
, wordW
, 1, 1);
1073 test_range_moveend(range
, characterW
, 2, 2);
1074 test_range_text(range
, "ab");
1076 IHTMLTxtRange_Release(range
);
1078 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1079 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1081 test_range_text(range
, "test abc 123\r\nit's text");
1082 test_range_move(range
, characterW
, 3, 3);
1083 test_range_moveend(range
, characterW
, 1, 1);
1084 test_range_text(range
, "t");
1085 test_range_moveend(range
, characterW
, 3, 3);
1086 test_range_text(range
, "t ab");
1087 test_range_moveend(range
, characterW
, -2, -2);
1088 test_range_text(range
, "t ");
1089 test_range_move(range
, characterW
, 6, 6);
1090 test_range_moveend(range
, characterW
, 3, 3);
1091 test_range_text(range
, "123");
1092 test_range_moveend(range
, characterW
, 2, 2);
1093 test_range_text(range
, "123\r\ni");
1095 IHTMLTxtRange_Release(range
);
1097 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1098 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1100 test_range_move(range
, wordW
, 1, 1);
1101 test_range_moveend(range
, characterW
, 2, 2);
1102 test_range_text(range
, "ab");
1104 test_range_move(range
, characterW
, -2, -2);
1105 test_range_moveend(range
, characterW
, 2, 2);
1106 test_range_text(range
, "t ");
1108 test_range_move(range
, wordW
, 3, 3);
1109 test_range_move(range
, wordW
, -2, -2);
1110 test_range_moveend(range
, characterW
, 2, 2);
1111 test_range_text(range
, "ab");
1113 test_range_move(range
, characterW
, -6, -5);
1114 test_range_moveend(range
, characterW
, -1, 0);
1115 test_range_moveend(range
, characterW
, -6, 0);
1116 test_range_move(range
, characterW
, 2, 2);
1117 test_range_moveend(range
, characterW
, 2, 2);
1118 test_range_text(range
, "st");
1119 test_range_moveend(range
, characterW
, -6, -4);
1120 test_range_moveend(range
, characterW
, 2, 2);
1122 IHTMLTxtRange_Release(range
);
1124 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1125 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1127 test_range_move(range
, wordW
, 2, 2);
1128 test_range_moveend(range
, characterW
, 2, 2);
1129 test_range_text(range
, "12");
1131 test_range_move(range
, characterW
, 15, 14);
1132 test_range_move(range
, characterW
, -2, -2);
1133 test_range_moveend(range
, characterW
, 3, 2);
1134 test_range_text(range
, "t");
1135 test_range_moveend(range
, characterW
, -1, -1);
1136 test_range_text(range
, "t");
1137 test_range_expand(range
, wordW
, VARIANT_TRUE
, "text");
1138 test_range_move(range
, characterW
, -2, -2);
1139 test_range_moveend(range
, characterW
, 2, 2);
1140 test_range_text(range
, "s ");
1141 test_range_move(range
, characterW
, 100, 7);
1142 test_range_move(range
, wordW
, 1, 0);
1143 test_range_move(range
, characterW
, -2, -2);
1144 test_range_moveend(range
, characterW
, 3, 2);
1145 test_range_text(range
, "t");
1147 IHTMLTxtRange_Release(range
);
1149 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
1150 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
1152 test_range_collapse(range
, TRUE
);
1153 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
1154 test_range_put_text(range
, "word");
1155 test_range_text(body_range
, "wordabc 123\r\nit's text");
1156 test_range_text(range
, NULL
);
1157 test_range_moveend(range
, characterW
, 3, 3);
1158 test_range_text(range
, "abc");
1159 test_range_movestart(range
, characterW
, -2, -2);
1160 test_range_text(range
, "rdabc");
1161 test_range_movestart(range
, characterW
, 3, 3);
1162 test_range_text(range
, "bc");
1163 test_range_movestart(range
, characterW
, 4, 4);
1164 test_range_text(range
, NULL
);
1165 test_range_movestart(range
, characterW
, -3, -3);
1166 test_range_text(range
, "c 1");
1167 test_range_movestart(range
, characterW
, -7, -6);
1168 test_range_text(range
, "wordabc 1");
1169 test_range_movestart(range
, characterW
, 100, 22);
1170 test_range_text(range
, NULL
);
1172 IHTMLTxtRange_Release(range
);
1173 IHTMLTxtRange_Release(body_range
);
1175 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1176 ok(hres
== S_OK
, "IHTMLDocument2_get_selection failed: %08x\n", hres
);
1178 hres
= IHTMLSelectionObject_createRange(selection
, &disp_range
);
1179 ok(hres
== S_OK
, "IHTMLSelectionObject_createRange failed: %08x\n", hres
);
1180 IHTMLSelectionObject_Release(selection
);
1182 hres
= IDispatch_QueryInterface(disp_range
, &IID_IHTMLTxtRange
, (void **)&range
);
1183 ok(hres
== S_OK
, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres
);
1184 IDispatch_Release(disp_range
);
1186 test_range_text(range
, NULL
);
1187 test_range_moveend(range
, characterW
, 3, 3);
1188 test_range_text(range
, "wor");
1189 test_range_parent(range
, ET_BODY
);
1190 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1191 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
1192 test_range_move(range
, characterW
, 3, 3);
1193 test_range_expand(range
, wordW
, VARIANT_TRUE
, "wordabc ");
1194 test_range_moveend(range
, characterW
, -4, -4);
1195 test_range_put_text(range
, "abc def ");
1196 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "abc def abc 123\r\nit's text");
1197 test_range_move(range
, wordW
, 1, 1);
1198 test_range_movestart(range
, characterW
, -1, -1);
1199 test_range_text(range
, " ");
1200 test_range_move(range
, wordW
, 1, 1);
1201 test_range_moveend(range
, characterW
, 3, 3);
1202 test_range_text(range
, "def");
1203 test_range_put_text(range
, "xyz");
1204 test_range_moveend(range
, characterW
, 1, 1);
1205 test_range_move(range
, wordW
, 1, 1);
1206 test_range_moveend(range
, characterW
, 2, 2);
1207 test_range_text(range
, "ab");
1209 IHTMLTxtRange_Release(range
);
1212 static void test_txtrange2(IHTMLDocument2
*doc
)
1214 IHTMLTxtRange
*range
;
1216 range
= test_create_body_range(doc
);
1218 test_range_text(range
, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1219 test_range_move(range
, characterW
, 5, 5);
1220 test_range_moveend(range
, characterW
, 1, 1);
1221 test_range_text(range
, "2");
1222 test_range_move(range
, characterW
, -3, -3);
1223 test_range_moveend(range
, characterW
, 3, 3);
1224 test_range_text(range
, "c\r\n\r\n1");
1225 test_range_collapse(range
, VARIANT_FALSE
);
1226 test_range_moveend(range
, characterW
, 4, 4);
1227 test_range_text(range
, "23");
1228 test_range_moveend(range
, characterW
, 1, 1);
1229 test_range_text(range
, "23\r\n\r\n\r\nd");
1230 test_range_moveend(range
, characterW
, -1, -1);
1231 test_range_text(range
, "23");
1232 test_range_moveend(range
, characterW
, -1, -1);
1233 test_range_text(range
, "23");
1234 test_range_moveend(range
, characterW
, -2, -2);
1235 test_range_text(range
, "2");
1237 IHTMLTxtRange_Release(range
);
1240 static void test_compatmode(IHTMLDocument2
*doc
)
1242 IHTMLDocument5
*doc5
;
1246 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
1247 ok(hres
== S_OK
, "Could not get IHTMLDocument5 interface: %08x\n", hres
);
1251 hres
= IHTMLDocument5_get_compatMode(doc5
, &mode
);
1252 IHTMLDocument5_Release(doc5
);
1253 ok(hres
== S_OK
, "get_compatMode failed: %08x\n", hres
);
1254 ok(!strcmp_wa(mode
, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode
));
1255 SysFreeString(mode
);
1258 static void test_location(IHTMLDocument2
*doc
)
1260 IHTMLLocation
*location
, *location2
;
1264 hres
= IHTMLDocument2_get_location(doc
, &location
);
1265 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1267 hres
= IHTMLDocument2_get_location(doc
, &location2
);
1268 ok(hres
== S_OK
, "get_location failed: %08x\n", hres
);
1270 ok(location
== location2
, "location != location2\n");
1272 test_ifaces((IUnknown
*)location
, location_iids
);
1274 IHTMLLocation_Release(location2
);
1275 ref
= IHTMLLocation_Release(location
);
1276 ok(!ref
, "location chould be destroyed here\n");
1279 static void test_navigator(IHTMLDocument2
*doc
)
1281 IHTMLWindow2
*window
;
1282 IOmNavigator
*navigator
, *navigator2
;
1286 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1287 ok(hres
== S_OK
, "parentWidnow failed: %08x\n", hres
);
1289 hres
= IHTMLWindow2_get_navigator(window
, &navigator
);
1290 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1291 ok(navigator
!= NULL
, "navigator == NULL\n");
1292 test_disp((IUnknown
*)navigator
, &IID_IOmNavigator
);
1294 hres
= IHTMLWindow2_get_navigator(window
, &navigator2
);
1295 ok(hres
== S_OK
, "get_navigator failed: %08x\n", hres
);
1296 ok(navigator
!= navigator2
, "navigator2 != navihgator\n");
1298 IHTMLWindow2_Release(window
);
1299 IOmNavigator_Release(navigator2
);
1300 ref
= IOmNavigator_Release(navigator
);
1301 ok(!ref
, "navigator should be destroyed here\n");
1304 static void test_default_style(IHTMLStyle
*style
)
1311 test_disp((IUnknown
*)style
, &DIID_DispHTMLStyle
);
1313 str
= (void*)0xdeadbeef;
1314 hres
= IHTMLStyle_get_fontFamily(style
, &str
);
1315 ok(hres
== S_OK
, "get_fontFamily failed: %08x\n", hres
);
1316 ok(!str
, "fontFamily = %s\n", dbgstr_w(str
));
1318 str
= (void*)0xdeadbeef;
1319 hres
= IHTMLStyle_get_fontWeight(style
, &str
);
1320 ok(hres
== S_OK
, "get_fontWeight failed: %08x\n", hres
);
1321 ok(!str
, "fontWeight = %s\n", dbgstr_w(str
));
1323 str
= (void*)0xdeadbeef;
1324 hres
= IHTMLStyle_get_display(style
, &str
);
1325 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
1326 ok(!str
, "display = %s\n", dbgstr_w(str
));
1328 str
= (void*)0xdeadbeef;
1329 hres
= IHTMLStyle_get_visibility(style
, &str
);
1330 ok(hres
== S_OK
, "get_visibility failed: %08x\n", hres
);
1331 ok(!str
, "visibility = %s\n", dbgstr_w(str
));
1334 hres
= IHTMLStyle_get_fontSize(style
, &v
);
1335 ok(hres
== S_OK
, "get_fontSize failed: %08x\n", hres
);
1336 ok(V_VT(&v
) == VT_BSTR
, "V_VT(fontSize) = %d\n", V_VT(&v
));
1337 ok(!V_BSTR(&v
), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v
)));
1340 hres
= IHTMLStyle_get_color(style
, &v
);
1341 ok(hres
== S_OK
, "get_color failed: %08x\n", hres
);
1342 ok(V_VT(&v
) == VT_BSTR
, "V_VT(color) = %d\n", V_VT(&v
));
1343 ok(!V_BSTR(&v
), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v
)));
1346 hres
= IHTMLStyle_get_textDecorationUnderline(style
, &b
);
1347 ok(hres
== S_OK
, "get_textDecorationUnderline failed: %08x\n", hres
);
1348 ok(b
== VARIANT_FALSE
, "textDecorationUnderline = %x\n", b
);
1351 hres
= IHTMLStyle_get_textDecorationLineThrough(style
, &b
);
1352 ok(hres
== S_OK
, "get_textDecorationLineThrough failed: %08x\n", hres
);
1353 ok(b
== VARIANT_FALSE
, "textDecorationLineThrough = %x\n", b
);
1356 static void test_default_selection(IHTMLDocument2
*doc
)
1358 IHTMLSelectionObject
*selection
;
1359 IHTMLTxtRange
*range
;
1364 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
1365 ok(hres
== S_OK
, "get_selection failed: %08x\n", hres
);
1367 hres
= IHTMLSelectionObject_get_type(selection
, &str
);
1368 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
1369 ok(!lstrcmpW(str
, noneW
), "type = %s\n", dbgstr_w(str
));
1372 hres
= IHTMLSelectionObject_createRange(selection
, &disp
);
1373 IHTMLSelectionObject_Release(selection
);
1374 ok(hres
== S_OK
, "createRange failed: %08x\n", hres
);
1376 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLTxtRange
, (void**)&range
);
1377 IDispatch_Release(disp
);
1378 ok(hres
== S_OK
, "Could not get IHTMLTxtRange interface: %08x\n", hres
);
1380 test_range_text(range
, NULL
);
1381 IHTMLTxtRange_Release(range
);
1384 static void test_default_body(IHTMLBodyElement
*body
)
1389 bstr
= (void*)0xdeadbeef;
1390 hres
= IHTMLBodyElement_get_background(body
, &bstr
);
1391 ok(hres
== S_OK
, "get_background failed: %08x\n", hres
);
1392 ok(bstr
== NULL
, "bstr != NULL\n");
1395 static void test_window(IHTMLDocument2
*doc
)
1397 IHTMLWindow2
*window
;
1398 IHTMLDocument2
*doc2
= NULL
;
1401 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
1402 ok(hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
1403 test_ifaces((IUnknown
*)window
, window_iids
);
1404 test_disp((IUnknown
*)window
, &DIID_DispHTMLWindow2
);
1406 hres
= IHTMLWindow2_get_document(window
, &doc2
);
1407 ok(hres
== S_OK
, "get_document failed: %08x\n", hres
);
1408 ok(doc2
!= NULL
, "doc2 == NULL\n");
1410 IHTMLDocument_Release(doc2
);
1411 IHTMLWindow2_Release(window
);
1414 static void test_defaults(IHTMLDocument2
*doc
)
1416 IHTMLStyleSheetsCollection
*stylesheetcol
;
1417 IHTMLBodyElement
*body
;
1423 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1424 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1426 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
1427 ok(hres
== S_OK
, "Could not get IHTMBodyElement: %08x\n", hres
);
1428 test_default_body(body
);
1429 IHTMLBodyElement_Release(body
);
1431 hres
= IHTMLElement_get_style(elem
, &style
);
1432 IHTMLElement_Release(elem
);
1433 ok(hres
== S_OK
, "get_style failed: %08x\n", hres
);
1435 test_default_style(style
);
1437 test_compatmode(doc
);
1439 test_navigator(doc
);
1441 IHTMLStyle_Release(style
);
1443 hres
= IHTMLDocument2_get_styleSheets(doc
, &stylesheetcol
);
1444 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
1447 hres
= IHTMLStyleSheetsCollection_get_length(stylesheetcol
, &l
);
1448 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1449 ok(l
== 0, "length = %ld\n", l
);
1451 IHTMLStyleSheetsCollection_Release(stylesheetcol
);
1453 test_default_selection(doc
);
1456 static void test_stylesheet(IDispatch
*disp
)
1458 IHTMLStyleSheetRulesCollection
*col
= NULL
;
1459 IHTMLStyleSheet
*stylesheet
;
1462 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLStyleSheet
, (void**)&stylesheet
);
1463 ok(hres
== S_OK
, "Could not get IHTMLStyleSheet: %08x\n", hres
);
1465 hres
= IHTMLStyleSheet_get_rules(stylesheet
, &col
);
1466 ok(hres
== S_OK
, "get_rules failed: %08x\n", hres
);
1467 ok(col
!= NULL
, "col == NULL\n");
1469 IHTMLStyleSheetRulesCollection_Release(col
);
1470 IHTMLStyleSheet_Release(stylesheet
);
1473 static void test_stylesheets(IHTMLDocument2
*doc
)
1475 IHTMLStyleSheetsCollection
*col
= NULL
;
1480 hres
= IHTMLDocument2_get_styleSheets(doc
, &col
);
1481 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
1482 ok(col
!= NULL
, "col == NULL\n");
1484 hres
= IHTMLStyleSheetsCollection_get_length(col
, &len
);
1485 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1486 ok(len
== 1, "len=%ld\n", len
);
1492 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
1493 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
1494 ok(V_VT(&res
) == VT_DISPATCH
, "V_VT(res) = %d\n", V_VT(&res
));
1495 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
1496 test_stylesheet(V_DISPATCH(&res
));
1503 hres
= IHTMLStyleSheetsCollection_item(col
, &idx
, &res
);
1504 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1505 ok(V_VT(&res
) == VT_EMPTY
, "V_VT(res) = %d\n", V_VT(&res
));
1506 ok(V_DISPATCH(&res
) != NULL
, "V_DISPATCH(&res) == NULL\n");
1509 IHTMLStyleSheetsCollection_Release(col
);
1512 static void test_elems(IHTMLDocument2
*doc
)
1514 IHTMLElementCollection
*col
;
1515 IHTMLDOMChildrenCollection
*child_col
;
1517 IHTMLDOMNode
*node
, *node2
;
1522 static const WCHAR inW
[] = {'i','n',0};
1523 static const WCHAR xW
[] = {'x',0};
1524 static const WCHAR sW
[] = {'s',0};
1525 static const WCHAR scW
[] = {'s','c',0};
1526 static const WCHAR xxxW
[] = {'x','x','x',0};
1528 static const elem_type_t all_types
[] = {
1548 static const elem_type_t item_types
[] = {
1554 hres
= IHTMLDocument2_get_all(doc
, &col
);
1555 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1556 test_elem_collection(col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
1557 test_elem_col_item(col
, xW
, item_types
, sizeof(item_types
)/sizeof(item_types
[0]));
1558 IHTMLElementCollection_Release(col
);
1560 elem
= get_doc_elem(doc
);
1561 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
1562 hres
= IHTMLElement_get_all(elem
, &disp
);
1563 IHTMLElement_Release(elem
);
1564 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1566 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&col
);
1567 IDispatch_Release(disp
);
1568 ok(hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
1569 test_elem_collection(col
, all_types
+1, sizeof(all_types
)/sizeof(all_types
[0])-1);
1570 IHTMLElementCollection_Release(col
);
1572 get_elem_by_id(doc
, xxxW
, FALSE
);
1573 elem
= get_doc_elem_by_id(doc
, xxxW
);
1574 ok(!elem
, "elem != NULL\n");
1576 elem
= get_doc_elem_by_id(doc
, sW
);
1577 ok(elem
!= NULL
, "elem == NULL\n");
1579 test_elem_type((IUnknown
*)elem
, ET_SELECT
);
1580 test_elem_attr(elem
, xxxW
, NULL
);
1581 test_elem_attr(elem
, idW
, sW
);
1582 IHTMLElement_Release(elem
);
1585 elem
= get_elem_by_id(doc
, sW
, TRUE
);
1587 IHTMLSelectElement
*select
;
1589 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLSelectElement
, (void**)&select
);
1590 ok(hres
== S_OK
, "Could not get IHTMLSelectElement interface: %08x\n", hres
);
1592 test_select_elem(select
);
1594 node
= get_first_child((IUnknown
*)select
);
1595 ok(node
!= NULL
, "node == NULL\n");
1597 test_elem_type((IUnknown
*)node
, ET_OPTION
);
1598 IHTMLDOMNode_Release(node
);
1601 type
= get_node_type((IUnknown
*)select
);
1602 ok(type
== 1, "type=%ld\n", type
);
1604 IHTMLSelectElement_Release(select
);
1605 IHTMLElement_Release(elem
);
1608 elem
= get_elem_by_id(doc
, scW
, TRUE
);
1610 IHTMLScriptElement
*script
;
1613 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLScriptElement
, (void**)&script
);
1614 ok(hres
== S_OK
, "Could not get IHTMLScriptElement interface: %08x\n", hres
);
1616 hres
= IHTMLScriptElement_get_type(script
, &type
);
1617 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
1618 ok(!lstrcmpW(type
, text_javascriptW
), "Unexpected type %s\n", dbgstr_w(type
));
1619 SysFreeString(type
);
1621 IHTMLScriptElement_Release(script
);
1624 elem
= get_elem_by_id(doc
, inW
, TRUE
);
1626 IHTMLInputElement
*input
;
1628 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLInputElement
, (void**)&input
);
1629 ok(hres
== S_OK
, "Could not get IHTMLInputElement: %08x\n", hres
);
1631 test_input_get_disabled(input
, VARIANT_FALSE
);
1633 IHTMLInputElement_Release(input
);
1634 IHTMLElement_Release(elem
);
1637 hres
= IHTMLDocument2_get_body(doc
, &elem
);
1638 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1640 node
= get_first_child((IUnknown
*)elem
);
1641 ok(node
!= NULL
, "node == NULL\n");
1643 test_ifaces((IUnknown
*)node
, text_iids
);
1644 test_disp((IUnknown
*)node
, &DIID_DispHTMLDOMTextNode
);
1646 node2
= get_first_child((IUnknown
*)node
);
1647 ok(!node2
, "node2 != NULL\n");
1649 type
= get_node_type((IUnknown
*)node
);
1650 ok(type
== 3, "type=%ld\n", type
);
1652 IHTMLDOMNode_Release(node
);
1655 child_col
= get_child_nodes((IUnknown
*)elem
);
1656 ok(child_col
!= NULL
, "child_coll == NULL\n");
1660 test_disp((IUnknown
*)child_col
, &DIID_DispDOMChildrenCollection
);
1662 hres
= IHTMLDOMChildrenCollection_get_length(child_col
, &length
);
1663 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1664 ok(length
, "length=0\n");
1666 node
= get_child_item(child_col
, 0);
1667 ok(node
!= NULL
, "node == NULL\n");
1669 type
= get_node_type((IUnknown
*)node
);
1670 ok(type
== 3, "type=%ld\n", type
);
1671 IHTMLDOMNode_Release(node
);
1674 node
= get_child_item(child_col
, 1);
1675 ok(node
!= NULL
, "node == NULL\n");
1677 type
= get_node_type((IUnknown
*)node
);
1678 ok(type
== 8, "type=%ld\n", type
);
1679 IHTMLDOMNode_Release(node
);
1682 disp
= (void*)0xdeadbeef;
1683 hres
= IHTMLDOMChildrenCollection_item(child_col
, 6000, &disp
);
1684 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
1685 ok(disp
== (void*)0xdeadbeef, "disp=%p\n", disp
);
1687 IHTMLDOMChildrenCollection_Release(child_col
);
1690 IHTMLElement_Release(elem
);
1692 test_stylesheets(doc
);
1693 test_create_option_elem(doc
);
1696 static void test_exec(IUnknown
*unk
, const GUID
*grpid
, DWORD cmdid
, VARIANT
*in
, VARIANT
*out
)
1698 IOleCommandTarget
*cmdtrg
;
1701 hres
= IHTMLTxtRange_QueryInterface(unk
, &IID_IOleCommandTarget
, (void**)&cmdtrg
);
1702 ok(hres
== S_OK
, "Could not get IOleCommandTarget interface: %08x\n", hres
);
1704 hres
= IOleCommandTarget_Exec(cmdtrg
, grpid
, cmdid
, 0, in
, out
);
1705 ok(hres
== S_OK
, "Exec failed: %08x\n", hres
);
1707 IOleCommandTarget_Release(cmdtrg
);
1710 static void test_indent(IHTMLDocument2
*doc
)
1712 IHTMLElementCollection
*col
;
1713 IHTMLTxtRange
*range
;
1716 static const elem_type_t all_types
[] = {
1725 static const elem_type_t indent_types
[] = {
1736 hres
= IHTMLDocument2_get_all(doc
, &col
);
1737 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1738 test_elem_collection(col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
1739 IHTMLElementCollection_Release(col
);
1741 range
= test_create_body_range(doc
);
1742 test_exec((IUnknown
*)range
, &CGID_MSHTML
, IDM_INDENT
, NULL
, NULL
);
1743 IHTMLTxtRange_Release(range
);
1745 hres
= IHTMLDocument2_get_all(doc
, &col
);
1746 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1747 test_elem_collection(col
, indent_types
, sizeof(indent_types
)/sizeof(indent_types
[0]));
1748 IHTMLElementCollection_Release(col
);
1751 static IHTMLDocument2
*notif_doc
;
1752 static BOOL doc_complete
;
1754 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
1755 REFIID riid
, void**ppv
)
1757 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
1762 ok(0, "unexpected call\n");
1763 return E_NOINTERFACE
;
1766 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
1771 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
1776 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
1778 if(dispID
== DISPID_READYSTATE
){
1782 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
1784 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
1785 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
1787 if(!lstrcmpW(state
, completeW
))
1788 doc_complete
= TRUE
;
1790 SysFreeString(state
);
1796 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
1798 ok(0, "unexpected call\n");
1802 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
1803 PropertyNotifySink_QueryInterface
,
1804 PropertyNotifySink_AddRef
,
1805 PropertyNotifySink_Release
,
1806 PropertyNotifySink_OnChanged
,
1807 PropertyNotifySink_OnRequestEdit
1810 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
1812 static IHTMLDocument2
*create_doc_with_string(const char *str
)
1814 IPersistStreamInit
*init
;
1816 IHTMLDocument2
*doc
;
1820 notif_doc
= doc
= create_document();
1824 doc_complete
= FALSE
;
1826 mem
= GlobalAlloc(0, len
);
1827 memcpy(mem
, str
, len
);
1828 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
1830 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
1832 IPersistStreamInit_Load(init
, stream
);
1833 IPersistStreamInit_Release(init
);
1834 IStream_Release(stream
);
1839 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
1841 IConnectionPointContainer
*container
;
1842 IConnectionPoint
*cp
;
1846 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
1847 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
1849 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
1850 IConnectionPointContainer_Release(container
);
1851 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
1853 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
1854 IConnectionPoint_Release(cp
);
1855 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
1858 typedef void (*domtest_t
)(IHTMLDocument2
*);
1860 static void run_domtest(const char *str
, domtest_t test
)
1862 IHTMLDocument2
*doc
;
1863 IHTMLElement
*body
= NULL
;
1868 doc
= create_doc_with_string(str
);
1869 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
1871 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
1872 TranslateMessage(&msg
);
1873 DispatchMessage(&msg
);
1876 hres
= IHTMLDocument2_get_body(doc
, &body
);
1877 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1880 IHTMLElement_Release(body
);
1883 skip("Could not get document body. Assuming no Gecko installed.\n");
1886 ref
= IHTMLDocument2_Release(doc
);
1887 ok(!ref
, "ref = %d\n", ref
);
1890 static void gecko_installer_workaround(BOOL disable
)
1895 static BOOL has_url
= FALSE
;
1896 static char url
[2048];
1898 if(!disable
&& !has_url
)
1901 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
1902 if(res
!= ERROR_SUCCESS
)
1906 DWORD type
, size
= sizeof(url
);
1908 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
1909 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
1912 RegDeleteValue(hkey
, "GeckoUrl");
1914 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
1922 gecko_installer_workaround(TRUE
);
1925 run_domtest(doc_str1
, test_doc_elem
);
1926 run_domtest(range_test_str
, test_txtrange
);
1927 run_domtest(range_test2_str
, test_txtrange2
);
1928 run_domtest(elem_test_str
, test_elems
);
1929 run_domtest(doc_blank
, test_defaults
);
1930 run_domtest(indent_test_str
, test_indent
);
1933 gecko_installer_workaround(FALSE
);