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>
32 static const char doc_blank
[] = "<html></html>";
33 static const char doc_str1
[] = "<html><body>test</body></html>";
34 static const char doc_str2
[] =
35 "<html><body>test a<font size=\"2\">bc 123<br />it's </font>text<br /></body></html>";
36 static const char doc_str3
[] =
37 "<html><head><title>test</title><body>"
38 "<a href=\"http://test\" name=\"x\">link</a><input />"
39 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
40 "<textarea id=\"X\">text text</textarea>"
43 static const WCHAR noneW
[] = {'N','o','n','e',0};
45 static WCHAR characterW
[] = {'c','h','a','r','a','c','t','e','r',0};
46 static WCHAR texteditW
[] = {'t','e','x','t','e','d','i','t',0};
47 static WCHAR wordW
[] = {'w','o','r','d',0};
62 static REFIID
const none_iids
[] = {
67 static REFIID
const html_iids
[] = {
74 static REFIID
const head_iids
[] = {
81 static REFIID
const title_iids
[] = {
88 static REFIID
const body_iids
[] = {
92 &IID_IHTMLTextContainer
,
93 &IID_IHTMLBodyElement
,
97 static REFIID
const anchor_iids
[] = {
101 &IID_IHTMLAnchorElement
,
105 static REFIID
const input_iids
[] = {
109 &IID_IHTMLInputElement
,
110 &IID_IHTMLInputTextElement
,
114 static REFIID
const select_iids
[] = {
118 &IID_IHTMLSelectElement
,
122 static REFIID
const textarea_iids
[] = {
126 &IID_IHTMLTextAreaElement
,
130 static REFIID
const option_iids
[] = {
134 &IID_IHTMLOptionElement
,
143 static const elem_type_info_t elem_type_infos
[] = {
147 {"TITLE", title_iids
},
150 {"INPUT", input_iids
},
151 {"SELECT", select_iids
},
152 {"TEXTAREA", textarea_iids
},
153 {"OPTION", option_iids
}
156 static const char *dbgstr_w(LPCWSTR str
)
158 static char buf
[512];
161 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
165 static const char *dbgstr_guid(REFIID riid
)
169 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
170 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
171 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
172 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
177 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
180 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
181 return lstrcmpW(strw
, buf
);
184 static BSTR
a2bstr(const char *str
)
189 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
190 ret
= SysAllocStringLen(NULL
, len
);
191 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
196 static IHTMLDocument2
*create_document(void)
201 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
202 &IID_IHTMLDocument2
, (void**)&doc
);
203 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
208 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
209 static void _test_ifaces(unsigned line
, IUnknown
*iface
, REFIID
*iids
)
211 const IID
* const *piid
;
215 for(piid
= iids
; *piid
; piid
++) {
216 hres
= IDispatch_QueryInterface(iface
, *piid
, (void**)&unk
);
217 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get %s interface: %08x\n", dbgstr_guid(*piid
), hres
);
219 IUnknown_Release(unk
);
223 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
224 static void _test_node_name(unsigned line
, IUnknown
*unk
, const char *exname
)
230 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDOMNode
, (void**)&node
);
231 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres
);
233 hres
= IHTMLDOMNode_get_nodeName(node
, &name
);
234 IHTMLDOMNode_Release(node
);
235 ok_(__FILE__
, line
) (hres
== S_OK
, "get_nodeName failed: %08x\n", hres
);
236 ok_(__FILE__
, line
) (!strcmp_wa(name
, exname
), "got name: %s, expected %s\n", dbgstr_w(name
), exname
);
241 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
242 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
248 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
249 ok_(__FILE__
, line
) (hres
== S_OK
, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres
);
251 hres
= IHTMLElement_get_tagName(elem
, &tag
);
252 IHTMLElement_Release(elem
);
253 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
254 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", dbgstr_w(tag
), extag
);
259 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
260 static void _test_elem_type(unsigned line
, IUnknown
*unk
, elem_type_t type
)
262 _test_elem_tag(line
, unk
, elem_type_infos
[type
].tag
);
263 _test_ifaces(line
, unk
, elem_type_infos
[type
].iids
);
266 static void test_doc_elem(IHTMLDocument2
*doc
)
269 IHTMLDocument3
*doc3
;
272 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
273 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres
);
275 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
276 IHTMLDocument3_Release(doc3
);
277 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
279 test_node_name((IUnknown
*)elem
, "HTML");
280 test_elem_tag((IUnknown
*)elem
, "HTML");
282 IHTMLElement_Release(elem
);
285 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
286 static IHTMLElement
*_get_doc_elem(unsigned line
, IHTMLDocument2
*doc
)
289 IHTMLDocument3
*doc3
;
292 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument3
, (void**)&doc3
);
293 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 interface: %08x\n", hres
);
294 hres
= IHTMLDocument3_get_documentElement(doc3
, &elem
);
295 ok_(__FILE__
,line
) (hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
296 IHTMLDocument3_Release(doc3
);
301 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
302 static void _test_option_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
307 hres
= IHTMLOptionElement_get_text(option
, &bstr
);
308 ok_(__FILE__
,line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
309 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, text
), "text=%s\n", dbgstr_w(bstr
));
313 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
314 static void _test_option_put_text(unsigned line
, IHTMLOptionElement
*option
, const char *text
)
320 hres
= IHTMLOptionElement_put_text(option
, bstr
);
322 ok(hres
== S_OK
, "put_text failed: %08x\n", hres
);
324 _test_option_text(line
, option
, text
);
327 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
328 static void _test_option_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
333 hres
= IHTMLOptionElement_get_value(option
, &bstr
);
334 ok_(__FILE__
,line
) (hres
== S_OK
, "get_value failed: %08x\n", hres
);
335 ok_(__FILE__
,line
) (!strcmp_wa(bstr
, value
), "value=%s\n", dbgstr_w(bstr
));
339 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
340 static void _test_option_put_value(unsigned line
, IHTMLOptionElement
*option
, const char *value
)
345 bstr
= a2bstr(value
);
346 hres
= IHTMLOptionElement_put_value(option
, bstr
);
348 ok(hres
== S_OK
, "put_value failed: %08x\n", hres
);
350 _test_option_value(line
, option
, value
);
353 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
354 static IHTMLOptionElement
*_create_option_elem(unsigned line
, IHTMLDocument2
*doc
,
355 const char *txt
, const char *val
)
357 IHTMLOptionElementFactory
*factory
;
358 IHTMLOptionElement
*option
;
359 IHTMLWindow2
*window
;
360 VARIANT text
, value
, empty
;
363 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
364 ok_(__FILE__
,line
) (hres
== S_OK
, "get_parentElement failed: %08x\n", hres
);
366 hres
= IHTMLWindow2_get_Option(window
, &factory
);
367 IHTMLWindow2_Release(window
);
368 ok_(__FILE__
,line
) (hres
== S_OK
, "get_Option failed: %08x\n", hres
);
370 V_VT(&text
) = VT_BSTR
;
371 V_BSTR(&text
) = a2bstr(txt
);
372 V_VT(&value
) = VT_BSTR
;
373 V_BSTR(&value
) = a2bstr(val
);
374 V_VT(&empty
) = VT_EMPTY
;
376 hres
= IHTMLOptionElementFactory_create(factory
, text
, value
, empty
, empty
, &option
);
377 ok_(__FILE__
,line
) (hres
== S_OK
, "create failed: %08x\n", hres
);
379 IHTMLOptionElementFactory_Release(factory
);
381 VariantClear(&value
);
383 _test_option_text(line
, option
, txt
);
384 _test_option_value(line
, option
, val
);
389 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
390 static void _test_select_length(unsigned line
, IHTMLSelectElement
*select
, long length
)
392 long len
= 0xdeadbeef;
395 hres
= IHTMLSelectElement_get_length(select
, &len
);
396 ok_(__FILE__
,line
) (hres
== S_OK
, "get_length failed: %08x\n", hres
);
397 ok_(__FILE__
,line
) (len
== length
, "len=%ld, expected %ld\n", len
, length
);
400 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
401 static void _test_select_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
403 long idx
= 0xdeadbeef;
406 hres
= IHTMLSelectElement_get_selectedIndex(select
, &idx
);
407 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
408 ok_(__FILE__
,line
) (idx
== index
, "idx=%ld, expected %ld\n", idx
, index
);
411 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
412 static void _test_select_put_selidx(unsigned line
, IHTMLSelectElement
*select
, long index
)
416 hres
= IHTMLSelectElement_put_selectedIndex(select
, index
);
417 ok_(__FILE__
,line
) (hres
== S_OK
, "get_selectedIndex failed: %08x\n", hres
);
418 _test_select_selidx(line
, select
, index
);
421 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
422 static void _test_range_text(unsigned line
, IHTMLTxtRange
*range
, const char *extext
)
427 hres
= IHTMLTxtRange_get_text(range
, &text
);
428 ok_(__FILE__
, line
) (hres
== S_OK
, "get_text failed: %08x\n", hres
);
431 ok_(__FILE__
, line
) (text
!= NULL
, "text == NULL\n");
432 ok_(__FILE__
, line
) (!strcmp_wa(text
, extext
), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text
), extext
);
434 ok_(__FILE__
, line
) (text
== NULL
, "text=\"%s\", expected NULL\n", dbgstr_w(text
));
441 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
442 static void _test_range_collapse(unsigned line
, IHTMLTxtRange
*range
, BOOL b
)
446 hres
= IHTMLTxtRange_collapse(range
, b
);
447 ok_(__FILE__
, line
) (hres
== S_OK
, "collapse failed: %08x\n", hres
);
448 _test_range_text(line
, range
, NULL
);
451 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
452 static void _test_range_expand(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
,
453 VARIANT_BOOL exb
, const char *extext
)
455 VARIANT_BOOL b
= 0xe0e0;
458 hres
= IHTMLTxtRange_expand(range
, unit
, &b
);
459 ok_(__FILE__
,line
) (hres
== S_OK
, "expand failed: %08x\n", hres
);
460 ok_(__FILE__
,line
) (b
== exb
, "b=%x, expected %x\n", b
, exb
);
461 _test_range_text(line
, range
, extext
);
464 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
465 static void _test_range_move(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
470 hres
= IHTMLTxtRange_move(range
, unit
, cnt
, &c
);
471 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
472 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
473 _test_range_text(line
, range
, NULL
);
476 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
477 static void _test_range_movestart(unsigned line
, IHTMLTxtRange
*range
,
478 LPWSTR unit
, long cnt
, long excnt
)
483 hres
= IHTMLTxtRange_moveStart(range
, unit
, cnt
, &c
);
484 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
485 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
488 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
489 static void _test_range_moveend(unsigned line
, IHTMLTxtRange
*range
, LPWSTR unit
, long cnt
, long excnt
)
494 hres
= IHTMLTxtRange_moveEnd(range
, unit
, cnt
, &c
);
495 ok_(__FILE__
,line
) (hres
== S_OK
, "move failed: %08x\n", hres
);
496 ok_(__FILE__
,line
) (c
== excnt
, "count=%ld, expected %ld\n", c
, excnt
);
499 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
500 static void _test_range_put_text(unsigned line
, IHTMLTxtRange
*range
, LPCWSTR text
)
504 hres
= IHTMLTxtRange_put_text(range
, (BSTR
)text
);
505 ok_(__FILE__
,line
) (hres
== S_OK
, "put_text failed: %08x\n", hres
);
506 _test_range_text(line
, range
, NULL
);
509 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
510 static void _test_range_inrange(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
516 hres
= IHTMLTxtRange_inRange(range1
, range2
, &b
);
517 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
518 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
521 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
522 static void _test_range_isequal(unsigned line
, IHTMLTxtRange
*range1
, IHTMLTxtRange
*range2
, VARIANT_BOOL exb
)
528 hres
= IHTMLTxtRange_isEqual(range1
, range2
, &b
);
529 ok_(__FILE__
,line
) (hres
== S_OK
, "(1->2) isEqual failed: %08x\n", hres
);
530 ok_(__FILE__
,line
) (b
== exb
, "(1->2) b=%x, expected %x\n", b
, exb
);
533 hres
= IHTMLTxtRange_isEqual(range2
, range1
, &b
);
534 ok_(__FILE__
,line
) (hres
== S_OK
, "(2->1) isEqual failed: %08x\n", hres
);
535 ok_(__FILE__
,line
) (b
== exb
, "(2->1) b=%x, expected %x\n", b
, exb
);
538 test_range_inrange(range1
, range2
, VARIANT_TRUE
);
539 test_range_inrange(range2
, range1
, VARIANT_TRUE
);
543 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
544 static void _test_range_parent(unsigned line
, IHTMLTxtRange
*range
, elem_type_t type
)
549 hres
= IHTMLTxtRange_parentElement(range
, &elem
);
550 ok_(__FILE__
,line
) (hres
== S_OK
, "parentElement failed: %08x\n", hres
);
552 _test_elem_type(line
, (IUnknown
*)elem
, type
);
554 IHTMLElement_Release(elem
);
557 static void test_elem_collection(IHTMLElementCollection
*col
, const elem_type_t
*elem_types
, long exlen
)
565 hres
= IHTMLElementCollection_get_length(col
, &len
);
566 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
567 ok(len
== exlen
, "len=%ld, expected %ld\n", len
, exlen
);
569 V_VT(&index
) = VT_EMPTY
;
572 for(i
=0; i
<len
; i
++) {
574 disp
= (void*)0xdeadbeef;
575 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
576 ok(hres
== S_OK
, "item(%d) failed: %08x\n", i
, hres
);
577 ok(disp
!= NULL
, "item returned NULL\n");
578 if(FAILED(hres
) || !disp
)
581 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
582 IDispatch_Release(disp
);
586 disp
= (void*)0xdeadbeef;
587 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
588 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
589 ok(disp
== NULL
, "disp != NULL\n");
592 disp
= (void*)0xdeadbeef;
593 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
594 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
595 ok(disp
== NULL
, "disp != NULL\n");
598 static void test_elem_col_item(IHTMLElementCollection
*col
, LPCWSTR n
,
599 const elem_type_t
*elem_types
, long len
)
601 IHTMLElementCollection
*elcol
;
607 V_VT(&index
) = VT_EMPTY
;
608 V_VT(&name
) = VT_BSTR
;
609 V_BSTR(&name
) = SysAllocString(n
);
611 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
612 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
614 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&elcol
);
615 IDispatch_Release(disp
);
616 ok(hres
== S_OK
, "Could not get IHTMLElementCollection interface: %08x\n", hres
);
617 test_elem_collection(elcol
, elem_types
, len
);
618 IHTMLElementCollection_Release(elcol
);
620 V_VT(&index
) = VT_I4
;
622 for(i
=0; i
<len
; i
++) {
624 disp
= (void*)0xdeadbeef;
625 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
626 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
627 ok(disp
!= NULL
, "disp == NULL\n");
628 if(FAILED(hres
) || !disp
)
631 test_elem_type((IUnknown
*)disp
, elem_types
[i
]);
633 IDispatch_Release(disp
);
637 disp
= (void*)0xdeadbeef;
638 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
639 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
640 ok(disp
== NULL
, "disp != NULL\n");
643 disp
= (void*)0xdeadbeef;
644 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
645 ok(hres
== E_INVALIDARG
, "item failed: %08x, expected E_INVALIDARG\n", hres
);
646 ok(disp
== NULL
, "disp != NULL\n");
648 SysFreeString(V_BSTR(&name
));
651 static IHTMLElement
*get_elem_by_id(IHTMLDocument2
*doc
, LPCWSTR id
, BOOL expect_success
)
653 IHTMLElementCollection
*col
;
655 IDispatch
*disp
= (void*)0xdeadbeef;
659 hres
= IHTMLDocument2_get_all(doc
, &col
);
660 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
661 ok(col
!= NULL
, "col == NULL\n");
662 if(FAILED(hres
) || !col
)
665 V_VT(&index
) = VT_EMPTY
;
666 V_VT(&name
) = VT_BSTR
;
667 V_BSTR(&name
) = SysAllocString(id
);
669 hres
= IHTMLElementCollection_item(col
, name
, index
, &disp
);
670 IHTMLElementCollection_Release(col
);
671 SysFreeString(V_BSTR(&name
));
672 ok(hres
== S_OK
, "item failed: %08x\n", hres
);
673 if(!expect_success
) {
674 ok(disp
== NULL
, "disp != NULL\n");
678 ok(disp
!= NULL
, "disp == NULL\n");
682 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElement
, (void**)&elem
);
683 IDispatch_Release(disp
);
684 ok(hres
== S_OK
, "Could not get IHTMLElement interface: %08x\n", hres
);
689 static void test_select_elem(IHTMLSelectElement
*select
)
691 test_select_length(select
, 2);
692 test_select_selidx(select
, 0);
693 test_select_put_selidx(select
, 1);
696 static void test_create_option_elem(IHTMLDocument2
*doc
)
698 IHTMLOptionElement
*option
;
700 option
= create_option_elem(doc
, "test text", "test value");
702 test_option_put_text(option
, "new text");
703 test_option_put_value(option
, "new value");
705 IHTMLOptionElement_Release(option
);
708 static void test_txtrange(IHTMLDocument2
*doc
)
711 IHTMLBodyElement
*body
;
712 IHTMLTxtRange
*body_range
, *range
, *range2
;
713 IHTMLSelectionObject
*selection
;
714 IDispatch
*disp_range
;
717 hres
= IHTMLDocument2_get_body(doc
, &elem
);
718 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
720 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLBodyElement
, (void**)&body
);
721 IHTMLElement_Release(elem
);
723 hres
= IHTMLBodyElement_createTextRange(body
, &body_range
);
724 IHTMLBodyElement_Release(body
);
725 ok(hres
== S_OK
, "createTextRange failed: %08x\n", hres
);
727 test_range_text(body_range
, "test abc 123\r\nit's text");
729 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
730 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
732 hres
= IHTMLTxtRange_duplicate(body_range
, &range2
);
733 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
734 test_range_isequal(range
, range2
, VARIANT_TRUE
);
736 test_range_text(range
, "test abc 123\r\nit's text");
737 test_range_text(body_range
, "test abc 123\r\nit's text");
739 test_range_collapse(range
, TRUE
);
740 test_range_isequal(range
, range2
, VARIANT_FALSE
);
741 test_range_inrange(range
, range2
, VARIANT_FALSE
);
742 test_range_inrange(range2
, range
, VARIANT_TRUE
);
743 IHTMLTxtRange_Release(range2
);
745 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
746 test_range_expand(range
, wordW
, VARIANT_FALSE
, "test ");
747 test_range_move(range
, characterW
, 2, 2);
748 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
750 test_range_collapse(range
, FALSE
);
751 test_range_expand(range
, wordW
, VARIANT_TRUE
, "abc ");
753 test_range_collapse(range
, FALSE
);
754 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
755 test_range_expand(range
, wordW
, VARIANT_FALSE
, "123");
756 test_range_move(range
, characterW
, 2, 2);
757 test_range_expand(range
, wordW
, VARIANT_TRUE
, "123");
758 test_range_moveend(range
, characterW
, -5, -5);
759 test_range_text(range
, NULL
);
760 test_range_moveend(range
, characterW
, 3, 3);
761 test_range_text(range
, "c 1");
763 IHTMLTxtRange_Release(range
);
765 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
766 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
768 test_range_text(range
, "test abc 123\r\nit's text");
769 test_range_move(range
, characterW
, 3, 3);
770 test_range_moveend(range
, characterW
, 1, 1);
771 test_range_text(range
, "t");
772 test_range_moveend(range
, characterW
, 3, 3);
773 test_range_text(range
, "t ab");
774 test_range_moveend(range
, characterW
, -2, -2);
775 test_range_text(range
, "t ");
776 test_range_move(range
, characterW
, 6, 6);
777 test_range_moveend(range
, characterW
, 3, 3);
778 test_range_text(range
, "123");
779 test_range_moveend(range
, characterW
, 2, 2);
780 test_range_text(range
, "123\r\ni");
782 IHTMLTxtRange_Release(range
);
784 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
785 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
787 test_range_move(range
, wordW
, 1, 1);
788 test_range_moveend(range
, characterW
, 2, 2);
789 test_range_text(range
, "ab");
791 test_range_move(range
, characterW
, -2, -2);
792 test_range_moveend(range
, characterW
, 2, 2);
793 test_range_text(range
, "t ");
795 test_range_move(range
, wordW
, 3, 3);
796 test_range_move(range
, wordW
, -2, -2);
797 test_range_moveend(range
, characterW
, 2, 2);
798 test_range_text(range
, "ab");
800 test_range_move(range
, characterW
, -6, -5);
801 test_range_moveend(range
, characterW
, -1, 0);
802 test_range_moveend(range
, characterW
, -6, 0);
803 test_range_move(range
, characterW
, 2, 2);
804 test_range_moveend(range
, characterW
, 2, 2);
805 test_range_text(range
, "st");
806 test_range_moveend(range
, characterW
, -6, -4);
807 test_range_moveend(range
, characterW
, 2, 2);
809 IHTMLTxtRange_Release(range
);
811 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
812 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
814 test_range_move(range
, wordW
, 2, 2);
815 test_range_moveend(range
, characterW
, 2, 2);
816 test_range_text(range
, "12");
818 test_range_move(range
, characterW
, 15, 14);
819 test_range_move(range
, characterW
, -2, -2);
820 test_range_moveend(range
, characterW
, 3, 2);
821 test_range_text(range
, "t");
822 test_range_moveend(range
, characterW
, -1, -1);
823 test_range_text(range
, "t");
824 test_range_expand(range
, wordW
, VARIANT_TRUE
, "text");
825 test_range_move(range
, characterW
, -2, -2);
826 test_range_moveend(range
, characterW
, 2, 2);
827 test_range_text(range
, "s ");
828 test_range_move(range
, characterW
, 100, 7);
829 test_range_move(range
, wordW
, 1, 0);
830 test_range_move(range
, characterW
, -2, -2);
831 test_range_moveend(range
, characterW
, 3, 2);
832 test_range_text(range
, "t");
834 IHTMLTxtRange_Release(range
);
836 hres
= IHTMLTxtRange_duplicate(body_range
, &range
);
837 ok(hres
== S_OK
, "duplicate failed: %08x\n", hres
);
839 test_range_collapse(range
, TRUE
);
840 test_range_expand(range
, wordW
, VARIANT_TRUE
, "test ");
841 test_range_put_text(range
, wordW
);
842 test_range_text(body_range
, "wordabc 123\r\nit's text");
843 test_range_text(range
, NULL
);
844 test_range_moveend(range
, characterW
, 3, 3);
845 test_range_text(range
, "abc");
846 test_range_movestart(range
, characterW
, -2, -2);
847 test_range_text(range
, "rdabc");
848 test_range_movestart(range
, characterW
, 3, 3);
849 test_range_text(range
, "bc");
850 test_range_movestart(range
, characterW
, 4, 4);
851 test_range_text(range
, NULL
);
852 test_range_movestart(range
, characterW
, -3, -3);
853 test_range_text(range
, "c 1");
854 test_range_movestart(range
, characterW
, -7, -6);
855 test_range_text(range
, "wordabc 1");
856 test_range_movestart(range
, characterW
, 100, 22);
857 test_range_text(range
, NULL
);
859 IHTMLTxtRange_Release(range
);
860 IHTMLTxtRange_Release(body_range
);
862 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
863 ok(hres
== S_OK
, "IHTMLDocument2_get_selection failed: %08x\n", hres
);
865 hres
= IHTMLSelectionObject_createRange(selection
, &disp_range
);
866 ok(hres
== S_OK
, "IHTMLSelectionObject_createRange failed: %08x\n", hres
);
867 IHTMLSelectionObject_Release(selection
);
869 hres
= IDispatch_QueryInterface(disp_range
, &IID_IHTMLTxtRange
, (void **)&range
);
870 ok(hres
== S_OK
, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres
);
871 IDispatch_Release(disp_range
);
873 test_range_text(range
, NULL
);
874 test_range_moveend(range
, characterW
, 3, 3);
875 test_range_text(range
, "wor");
876 test_range_parent(range
, ET_BODY
);
877 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
878 test_range_expand(range
, texteditW
, VARIANT_TRUE
, "wordabc 123\r\nit's text");
880 IHTMLTxtRange_Release(range
);
883 static void test_compatmode(IHTMLDocument2
*doc
)
885 IHTMLDocument5
*doc5
;
889 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
890 ok(hres
== S_OK
, "Could not get IHTMLDocument5 interface: %08x\n", hres
);
894 hres
= IHTMLDocument5_get_compatMode(doc5
, &mode
);
895 IHTMLDocument5_Release(doc5
);
896 ok(hres
== S_OK
, "get_compatMode failed: %08x\n", hres
);
897 ok(!strcmp_wa(mode
, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode
));
901 static void test_default_style(IHTMLStyle
*style
)
908 str
= (void*)0xdeadbeef;
909 hres
= IHTMLStyle_get_fontFamily(style
, &str
);
910 ok(hres
== S_OK
, "get_fontFamily failed: %08x\n", hres
);
911 ok(!str
, "fontFamily = %s\n", dbgstr_w(str
));
913 str
= (void*)0xdeadbeef;
914 hres
= IHTMLStyle_get_fontWeight(style
, &str
);
915 ok(hres
== S_OK
, "get_fontWeight failed: %08x\n", hres
);
916 ok(!str
, "fontWeight = %s\n", dbgstr_w(str
));
918 str
= (void*)0xdeadbeef;
919 hres
= IHTMLStyle_get_display(style
, &str
);
920 ok(hres
== S_OK
, "get_display failed: %08x\n", hres
);
921 ok(!str
, "display = %s\n", dbgstr_w(str
));
923 str
= (void*)0xdeadbeef;
924 hres
= IHTMLStyle_get_visibility(style
, &str
);
925 ok(hres
== S_OK
, "get_visibility failed: %08x\n", hres
);
926 ok(!str
, "visibility = %s\n", dbgstr_w(str
));
929 hres
= IHTMLStyle_get_fontSize(style
, &v
);
930 ok(hres
== S_OK
, "get_fontSize failed: %08x\n", hres
);
931 ok(V_VT(&v
) == VT_BSTR
, "V_VT(fontSize) = %d\n", V_VT(&v
));
932 ok(!V_BSTR(&v
), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v
)));
935 hres
= IHTMLStyle_get_color(style
, &v
);
936 ok(hres
== S_OK
, "get_color failed: %08x\n", hres
);
937 ok(V_VT(&v
) == VT_BSTR
, "V_VT(color) = %d\n", V_VT(&v
));
938 ok(!V_BSTR(&v
), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v
)));
941 hres
= IHTMLStyle_get_textDecorationUnderline(style
, &b
);
942 ok(hres
== S_OK
, "get_textDecorationUnderline failed: %08x\n", hres
);
943 ok(b
== VARIANT_FALSE
, "textDecorationUnderline = %x\n", b
);
946 hres
= IHTMLStyle_get_textDecorationLineThrough(style
, &b
);
947 ok(hres
== S_OK
, "get_textDecorationLineThrough failed: %08x\n", hres
);
948 ok(b
== VARIANT_FALSE
, "textDecorationLineThrough = %x\n", b
);
951 static void test_default_selection(IHTMLDocument2
*doc
)
953 IHTMLSelectionObject
*selection
;
954 IHTMLTxtRange
*range
;
959 hres
= IHTMLDocument2_get_selection(doc
, &selection
);
960 ok(hres
== S_OK
, "get_selection failed: %08x\n", hres
);
962 hres
= IHTMLSelectionObject_get_type(selection
, &str
);
963 ok(hres
== S_OK
, "get_type failed: %08x\n", hres
);
964 ok(!lstrcmpW(str
, noneW
), "type = %s\n", dbgstr_w(str
));
967 hres
= IHTMLSelectionObject_createRange(selection
, &disp
);
968 IHTMLSelectionObject_Release(selection
);
969 ok(hres
== S_OK
, "createRange failed: %08x\n", hres
);
971 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLTxtRange
, (void**)&range
);
972 IDispatch_Release(disp
);
973 ok(hres
== S_OK
, "Could not get IHTMLTxtRange interface: %08x\n", hres
);
975 test_range_text(range
, NULL
);
976 IHTMLTxtRange_Release(range
);
979 static void test_defaults(IHTMLDocument2
*doc
)
981 IHTMLStyleSheetsCollection
*stylesheetcol
;
987 hres
= IHTMLDocument2_get_body(doc
, &elem
);
988 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
990 hres
= IHTMLElement_get_style(elem
, &style
);
991 IHTMLElement_Release(elem
);
992 ok(hres
== S_OK
, "get_style failed: %08x\n", hres
);
994 test_default_style(style
);
995 test_compatmode(doc
);
997 IHTMLStyle_Release(style
);
999 hres
= IHTMLDocument2_get_styleSheets(doc
, &stylesheetcol
);
1000 ok(hres
== S_OK
, "get_styleSheets failed: %08x\n", hres
);
1003 hres
= IHTMLStyleSheetsCollection_get_length(stylesheetcol
, &l
);
1004 ok(hres
== S_OK
, "get_length failed: %08x\n", hres
);
1005 ok(l
== 0, "length = %ld\n", l
);
1007 IHTMLStyleSheetsCollection_Release(stylesheetcol
);
1009 test_default_selection(doc
);
1012 static void test_elems(IHTMLDocument2
*doc
)
1014 IHTMLElementCollection
*col
;
1019 static const WCHAR xW
[] = {'x',0};
1020 static const WCHAR sW
[] = {'s',0};
1021 static const WCHAR xxxW
[] = {'x','x','x',0};
1023 static const elem_type_t all_types
[] = {
1036 static const elem_type_t item_types
[] = {
1042 hres
= IHTMLDocument2_get_all(doc
, &col
);
1043 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1044 test_elem_collection(col
, all_types
, sizeof(all_types
)/sizeof(all_types
[0]));
1045 test_elem_col_item(col
, xW
, item_types
, sizeof(item_types
)/sizeof(item_types
[0]));
1046 IHTMLElementCollection_Release(col
);
1048 elem
= get_doc_elem(doc
);
1049 ok(hres
== S_OK
, "get_documentElement failed: %08x\n", hres
);
1050 hres
= IHTMLElement_get_all(elem
, &disp
);
1051 IHTMLElement_Release(elem
);
1052 ok(hres
== S_OK
, "get_all failed: %08x\n", hres
);
1054 hres
= IDispatch_QueryInterface(disp
, &IID_IHTMLElementCollection
, (void**)&col
);
1055 IDispatch_Release(disp
);
1056 ok(hres
== S_OK
, "Could not get IHTMLElementCollection: %08x\n", hres
);
1057 test_elem_collection(col
, all_types
+1, sizeof(all_types
)/sizeof(all_types
[0])-1);
1058 IHTMLElementCollection_Release(col
);
1060 get_elem_by_id(doc
, xxxW
, FALSE
);
1061 elem
= get_elem_by_id(doc
, sW
, TRUE
);
1063 IHTMLSelectElement
*select
;
1065 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLSelectElement
, (void**)&select
);
1066 ok(hres
== S_OK
, "Could not get IHTMLSelectElement interface: %08x\n", hres
);
1068 test_select_elem(select
);
1070 IHTMLSelectElement_Release(select
);
1071 IHTMLElement_Release(elem
);
1074 test_create_option_elem(doc
);
1077 static IHTMLDocument2
*notif_doc
;
1078 static BOOL doc_complete
;
1080 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
1081 REFIID riid
, void**ppv
)
1083 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
1088 ok(0, "unexpected call\n");
1089 return E_NOINTERFACE
;
1092 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
1097 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
1102 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
1104 if(dispID
== DISPID_READYSTATE
){
1108 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
1110 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
1111 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
1113 if(!lstrcmpW(state
, completeW
))
1114 doc_complete
= TRUE
;
1116 SysFreeString(state
);
1122 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
1124 ok(0, "unexpected call\n");
1128 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
1129 PropertyNotifySink_QueryInterface
,
1130 PropertyNotifySink_AddRef
,
1131 PropertyNotifySink_Release
,
1132 PropertyNotifySink_OnChanged
,
1133 PropertyNotifySink_OnRequestEdit
1136 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
1138 static IHTMLDocument2
*create_doc_with_string(const char *str
)
1140 IPersistStreamInit
*init
;
1142 IHTMLDocument2
*doc
;
1146 notif_doc
= doc
= create_document();
1150 doc_complete
= FALSE
;
1152 mem
= GlobalAlloc(0, len
);
1153 memcpy(mem
, str
, len
);
1154 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
1156 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
1158 IPersistStreamInit_Load(init
, stream
);
1159 IPersistStreamInit_Release(init
);
1160 IStream_Release(stream
);
1165 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
1167 IConnectionPointContainer
*container
;
1168 IConnectionPoint
*cp
;
1172 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
1173 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
1175 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
1176 IConnectionPointContainer_Release(container
);
1177 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
1179 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
1180 IConnectionPoint_Release(cp
);
1181 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
1184 typedef void (*domtest_t
)(IHTMLDocument2
*);
1186 static void run_domtest(const char *str
, domtest_t test
)
1188 IHTMLDocument2
*doc
;
1189 IHTMLElement
*body
= NULL
;
1194 doc
= create_doc_with_string(str
);
1195 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
1197 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
1198 TranslateMessage(&msg
);
1199 DispatchMessage(&msg
);
1202 hres
= IHTMLDocument2_get_body(doc
, &body
);
1203 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
1206 IHTMLElement_Release(body
);
1209 skip("Could not get document body. Assuming no Gecko installed.\n");
1212 ref
= IHTMLDocument2_Release(doc
);
1213 ok(!ref
, "ref = %d\n", ref
);
1216 static void gecko_installer_workaround(BOOL disable
)
1221 static BOOL has_url
= FALSE
;
1222 static char url
[2048];
1224 if(!disable
&& !has_url
)
1227 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
1228 if(res
!= ERROR_SUCCESS
)
1232 DWORD type
, size
= sizeof(url
);
1234 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
1235 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
1238 RegDeleteValue(hkey
, "GeckoUrl");
1240 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
1248 gecko_installer_workaround(TRUE
);
1251 run_domtest(doc_str1
, test_doc_elem
);
1252 run_domtest(doc_str2
, test_txtrange
);
1253 run_domtest(doc_str3
, test_elems
);
1254 run_domtest(doc_blank
, test_defaults
);
1257 gecko_installer_workaround(FALSE
);