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>
34 static const char doc_blank[] = "<html></html>";
35 static const char doc_str1[] = "<html><body>test</body></html>";
36 static const char range_test_str[] =
37 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
38 static const char range_test2_str[] =
39 "<html><body>abc<hr />123<br /><hr />def</body></html>";
40 static const char elem_test_str[] =
41 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
42 "<body><a href=\"http://test\" name=\"x\">link</a><input />"
43 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
44 "<textarea id=\"X\">text text</textarea>"
45 "<table><tbody></tbody></table>"
46 "<script id=\"sc\" type=\"text/javascript\"></script>"
48 static const char indent_test_str[] =
49 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
51 static const WCHAR noneW[] = {'N','o','n','e',0};
53 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
54 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
55 static WCHAR wordW[] = {'w','o','r','d',0};
57 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
79 static REFIID const none_iids[] = {
84 static REFIID const elem_iids[] = {
88 &IID_IConnectionPointContainer,
92 static REFIID const body_iids[] = {
96 &IID_IHTMLTextContainer,
97 &IID_IHTMLBodyElement,
98 &IID_IConnectionPointContainer,
102 static REFIID const anchor_iids[] = {
106 &IID_IHTMLAnchorElement,
107 &IID_IConnectionPointContainer,
111 static REFIID const input_iids[] = {
115 &IID_IHTMLInputElement,
116 &IID_IHTMLInputTextElement,
117 &IID_IConnectionPointContainer,
121 static REFIID const select_iids[] = {
125 &IID_IHTMLSelectElement,
126 &IID_IConnectionPointContainer,
130 static REFIID const textarea_iids[] = {
134 &IID_IHTMLTextAreaElement,
135 &IID_IConnectionPointContainer,
139 static REFIID const option_iids[] = {
143 &IID_IHTMLOptionElement,
144 &IID_IConnectionPointContainer,
148 static REFIID const table_iids[] = {
153 &IID_IConnectionPointContainer,
157 static REFIID const script_iids[] = {
161 &IID_IHTMLScriptElement,
162 &IID_IConnectionPointContainer,
166 static REFIID const location_iids[] = {
177 static const elem_type_info_t elem_type_infos[] = {
181 {"TITLE", elem_iids},
184 {"INPUT", input_iids},
185 {"SELECT", select_iids},
186 {"TEXTAREA", textarea_iids},
187 {"OPTION", option_iids},
188 {"STYLE", elem_iids},
189 {"BLOCKQUOTE",elem_iids},
192 {"TABLE", table_iids},
193 {"TBODY", elem_iids},
194 {"SCRIPT", script_iids}
197 static const char *dbgstr_w(LPCWSTR str)
199 static char buf[512];
202 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
206 static const char *dbgstr_guid(REFIID riid)
210 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
211 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
212 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
213 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
218 static int strcmp_wa(LPCWSTR strw, const char *stra)
221 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
222 return lstrcmpW(strw, buf);
225 static BSTR a2bstr(const char *str)
230 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
231 ret = SysAllocStringLen(NULL, len);
232 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
237 static IHTMLDocument2 *create_document(void)
242 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
243 &IID_IHTMLDocument2, (void**)&doc);
244 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
249 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
250 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
252 const IID * const *piid;
256 for(piid = iids; *piid; piid++) {
257 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
258 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
260 IUnknown_Release(unk);
264 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
265 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
271 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
272 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
274 hres = IHTMLDOMNode_get_nodeName(node, &name);
275 IHTMLDOMNode_Release(node);
276 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
277 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
282 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
283 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
289 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
290 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
292 hres = IHTMLElement_get_tagName(elem, &tag);
293 IHTMLElement_Release(elem);
294 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
295 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
300 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
301 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
303 _test_elem_tag(line, unk, elem_type_infos[type].tag);
304 _test_ifaces(line, unk, elem_type_infos[type].iids);
307 static void test_doc_elem(IHTMLDocument2 *doc)
310 IHTMLDocument3 *doc3;
313 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
314 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
316 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
317 IHTMLDocument3_Release(doc3);
318 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
320 test_node_name((IUnknown*)elem, "HTML");
321 test_elem_tag((IUnknown*)elem, "HTML");
323 IHTMLElement_Release(elem);
326 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
327 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
330 IHTMLDocument3 *doc3;
333 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
334 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
335 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
336 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
337 IHTMLDocument3_Release(doc3);
342 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
343 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
348 hres = IHTMLOptionElement_get_text(option, &bstr);
349 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
350 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
354 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
355 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
361 hres = IHTMLOptionElement_put_text(option, bstr);
363 ok(hres == S_OK, "put_text failed: %08x\n", hres);
365 _test_option_text(line, option, text);
368 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
369 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
374 hres = IHTMLOptionElement_get_value(option, &bstr);
375 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
376 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
380 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
381 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
386 bstr = a2bstr(value);
387 hres = IHTMLOptionElement_put_value(option, bstr);
389 ok(hres == S_OK, "put_value failed: %08x\n", hres);
391 _test_option_value(line, option, value);
394 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
395 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
396 const char *txt, const char *val)
398 IHTMLOptionElementFactory *factory;
399 IHTMLOptionElement *option;
400 IHTMLWindow2 *window;
401 VARIANT text, value, empty;
404 hres = IHTMLDocument2_get_parentWindow(doc, &window);
405 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
407 hres = IHTMLWindow2_get_Option(window, &factory);
408 IHTMLWindow2_Release(window);
409 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
411 V_VT(&text) = VT_BSTR;
412 V_BSTR(&text) = a2bstr(txt);
413 V_VT(&value) = VT_BSTR;
414 V_BSTR(&value) = a2bstr(val);
415 V_VT(&empty) = VT_EMPTY;
417 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
418 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
420 IHTMLOptionElementFactory_Release(factory);
422 VariantClear(&value);
424 _test_option_text(line, option, txt);
425 _test_option_value(line, option, val);
430 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
431 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
433 long len = 0xdeadbeef;
436 hres = IHTMLSelectElement_get_length(select, &len);
437 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
438 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
441 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
442 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
444 long idx = 0xdeadbeef;
447 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
448 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
449 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
452 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
453 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
457 hres = IHTMLSelectElement_put_selectedIndex(select, index);
458 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
459 _test_select_selidx(line, select, index);
462 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
463 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
468 hres = IHTMLTxtRange_get_text(range, &text);
469 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
472 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
473 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
475 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
482 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
483 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
487 hres = IHTMLTxtRange_collapse(range, b);
488 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
489 _test_range_text(line, range, NULL);
492 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
493 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
494 VARIANT_BOOL exb, const char *extext)
496 VARIANT_BOOL b = 0xe0e0;
499 hres = IHTMLTxtRange_expand(range, unit, &b);
500 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
501 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
502 _test_range_text(line, range, extext);
505 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
506 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
511 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
512 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
513 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
514 _test_range_text(line, range, NULL);
517 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
518 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
519 LPWSTR unit, long cnt, long excnt)
524 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
525 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
526 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
529 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
530 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
535 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
536 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
537 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
540 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
541 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
544 BSTR bstr = a2bstr(text);
546 hres = IHTMLTxtRange_put_text(range, bstr);
547 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
549 _test_range_text(line, range, NULL);
552 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
553 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
559 hres = IHTMLTxtRange_inRange(range1, range2, &b);
560 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
561 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
564 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
565 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
571 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
572 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
573 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
576 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
577 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
578 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
581 test_range_inrange(range1, range2, VARIANT_TRUE);
582 test_range_inrange(range2, range1, VARIANT_TRUE);
586 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
587 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
592 hres = IHTMLTxtRange_parentElement(range, &elem);
593 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
595 _test_elem_type(line, (IUnknown*)elem, type);
597 IHTMLElement_Release(elem);
600 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
601 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
602 const elem_type_t *elem_types, long exlen)
610 hres = IHTMLElementCollection_get_length(col, &len);
611 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
612 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
617 V_VT(&index) = VT_EMPTY;
620 for(i=0; i<len; i++) {
622 disp = (void*)0xdeadbeef;
623 hres = IHTMLElementCollection_item(col, name, index, &disp);
624 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
625 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
626 if(FAILED(hres) || !disp)
629 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
630 IDispatch_Release(disp);
634 disp = (void*)0xdeadbeef;
635 hres = IHTMLElementCollection_item(col, name, index, &disp);
636 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
637 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
640 disp = (void*)0xdeadbeef;
641 hres = IHTMLElementCollection_item(col, name, index, &disp);
642 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
643 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
646 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
647 const elem_type_t *elem_types, long len)
649 IHTMLElementCollection *elcol;
655 V_VT(&index) = VT_EMPTY;
656 V_VT(&name) = VT_BSTR;
657 V_BSTR(&name) = SysAllocString(n);
659 hres = IHTMLElementCollection_item(col, name, index, &disp);
660 ok(hres == S_OK, "item failed: %08x\n", hres);
662 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
663 IDispatch_Release(disp);
664 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
665 test_elem_collection(elcol, elem_types, len);
666 IHTMLElementCollection_Release(elcol);
668 V_VT(&index) = VT_I4;
670 for(i=0; i<len; i++) {
672 disp = (void*)0xdeadbeef;
673 hres = IHTMLElementCollection_item(col, name, index, &disp);
674 ok(hres == S_OK, "item failed: %08x\n", hres);
675 ok(disp != NULL, "disp == NULL\n");
676 if(FAILED(hres) || !disp)
679 test_elem_type((IUnknown*)disp, elem_types[i]);
681 IDispatch_Release(disp);
685 disp = (void*)0xdeadbeef;
686 hres = IHTMLElementCollection_item(col, name, index, &disp);
687 ok(hres == S_OK, "item failed: %08x\n", hres);
688 ok(disp == NULL, "disp != NULL\n");
691 disp = (void*)0xdeadbeef;
692 hres = IHTMLElementCollection_item(col, name, index, &disp);
693 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
694 ok(disp == NULL, "disp != NULL\n");
696 SysFreeString(V_BSTR(&name));
699 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
701 IHTMLElementCollection *col;
703 IDispatch *disp = (void*)0xdeadbeef;
707 hres = IHTMLDocument2_get_all(doc, &col);
708 ok(hres == S_OK, "get_all failed: %08x\n", hres);
709 ok(col != NULL, "col == NULL\n");
710 if(FAILED(hres) || !col)
713 V_VT(&index) = VT_EMPTY;
714 V_VT(&name) = VT_BSTR;
715 V_BSTR(&name) = SysAllocString(id);
717 hres = IHTMLElementCollection_item(col, name, index, &disp);
718 IHTMLElementCollection_Release(col);
719 SysFreeString(V_BSTR(&name));
720 ok(hres == S_OK, "item failed: %08x\n", hres);
721 if(!expect_success) {
722 ok(disp == NULL, "disp != NULL\n");
726 ok(disp != NULL, "disp == NULL\n");
730 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
731 IDispatch_Release(disp);
732 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
737 static void test_select_elem(IHTMLSelectElement *select)
739 test_select_length(select, 2);
740 test_select_selidx(select, 0);
741 test_select_put_selidx(select, 1);
744 static void test_create_option_elem(IHTMLDocument2 *doc)
746 IHTMLOptionElement *option;
748 option = create_option_elem(doc, "test text", "test value");
750 test_option_put_text(option, "new text");
751 test_option_put_value(option, "new value");
753 IHTMLOptionElement_Release(option);
756 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
758 IHTMLBodyElement *body;
759 IHTMLTxtRange *range;
763 hres = IHTMLDocument2_get_body(doc, &elem);
764 ok(hres == S_OK, "get_body failed: %08x\n", hres);
766 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
767 IHTMLElement_Release(elem);
769 hres = IHTMLBodyElement_createTextRange(body, &range);
770 IHTMLBodyElement_Release(body);
771 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
776 static void test_txtrange(IHTMLDocument2 *doc)
778 IHTMLTxtRange *body_range, *range, *range2;
779 IHTMLSelectionObject *selection;
780 IDispatch *disp_range;
783 body_range = test_create_body_range(doc);
785 test_range_text(body_range, "test abc 123\r\nit's text");
787 hres = IHTMLTxtRange_duplicate(body_range, &range);
788 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
790 hres = IHTMLTxtRange_duplicate(body_range, &range2);
791 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
792 test_range_isequal(range, range2, VARIANT_TRUE);
794 test_range_text(range, "test abc 123\r\nit's text");
795 test_range_text(body_range, "test abc 123\r\nit's text");
797 test_range_collapse(range, TRUE);
798 test_range_isequal(range, range2, VARIANT_FALSE);
799 test_range_inrange(range, range2, VARIANT_FALSE);
800 test_range_inrange(range2, range, VARIANT_TRUE);
801 IHTMLTxtRange_Release(range2);
803 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
804 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
805 test_range_move(range, characterW, 2, 2);
806 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
808 test_range_collapse(range, FALSE);
809 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
811 test_range_collapse(range, FALSE);
812 test_range_expand(range, wordW, VARIANT_TRUE, "123");
813 test_range_expand(range, wordW, VARIANT_FALSE, "123");
814 test_range_move(range, characterW, 2, 2);
815 test_range_expand(range, wordW, VARIANT_TRUE, "123");
816 test_range_moveend(range, characterW, -5, -5);
817 test_range_text(range, NULL);
818 test_range_moveend(range, characterW, 3, 3);
819 test_range_text(range, "c 1");
820 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
821 test_range_collapse(range, TRUE);
822 test_range_move(range, characterW, 4, 4);
823 test_range_moveend(range, characterW, 1, 1);
824 test_range_text(range, " ");
825 test_range_move(range, wordW, 1, 1);
826 test_range_moveend(range, characterW, 2, 2);
827 test_range_text(range, "ab");
829 IHTMLTxtRange_Release(range);
831 hres = IHTMLTxtRange_duplicate(body_range, &range);
832 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
834 test_range_text(range, "test abc 123\r\nit's text");
835 test_range_move(range, characterW, 3, 3);
836 test_range_moveend(range, characterW, 1, 1);
837 test_range_text(range, "t");
838 test_range_moveend(range, characterW, 3, 3);
839 test_range_text(range, "t ab");
840 test_range_moveend(range, characterW, -2, -2);
841 test_range_text(range, "t ");
842 test_range_move(range, characterW, 6, 6);
843 test_range_moveend(range, characterW, 3, 3);
844 test_range_text(range, "123");
845 test_range_moveend(range, characterW, 2, 2);
846 test_range_text(range, "123\r\ni");
848 IHTMLTxtRange_Release(range);
850 hres = IHTMLTxtRange_duplicate(body_range, &range);
851 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
853 test_range_move(range, wordW, 1, 1);
854 test_range_moveend(range, characterW, 2, 2);
855 test_range_text(range, "ab");
857 test_range_move(range, characterW, -2, -2);
858 test_range_moveend(range, characterW, 2, 2);
859 test_range_text(range, "t ");
861 test_range_move(range, wordW, 3, 3);
862 test_range_move(range, wordW, -2, -2);
863 test_range_moveend(range, characterW, 2, 2);
864 test_range_text(range, "ab");
866 test_range_move(range, characterW, -6, -5);
867 test_range_moveend(range, characterW, -1, 0);
868 test_range_moveend(range, characterW, -6, 0);
869 test_range_move(range, characterW, 2, 2);
870 test_range_moveend(range, characterW, 2, 2);
871 test_range_text(range, "st");
872 test_range_moveend(range, characterW, -6, -4);
873 test_range_moveend(range, characterW, 2, 2);
875 IHTMLTxtRange_Release(range);
877 hres = IHTMLTxtRange_duplicate(body_range, &range);
878 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
880 test_range_move(range, wordW, 2, 2);
881 test_range_moveend(range, characterW, 2, 2);
882 test_range_text(range, "12");
884 test_range_move(range, characterW, 15, 14);
885 test_range_move(range, characterW, -2, -2);
886 test_range_moveend(range, characterW, 3, 2);
887 test_range_text(range, "t");
888 test_range_moveend(range, characterW, -1, -1);
889 test_range_text(range, "t");
890 test_range_expand(range, wordW, VARIANT_TRUE, "text");
891 test_range_move(range, characterW, -2, -2);
892 test_range_moveend(range, characterW, 2, 2);
893 test_range_text(range, "s ");
894 test_range_move(range, characterW, 100, 7);
895 test_range_move(range, wordW, 1, 0);
896 test_range_move(range, characterW, -2, -2);
897 test_range_moveend(range, characterW, 3, 2);
898 test_range_text(range, "t");
900 IHTMLTxtRange_Release(range);
902 hres = IHTMLTxtRange_duplicate(body_range, &range);
903 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
905 test_range_collapse(range, TRUE);
906 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
907 test_range_put_text(range, "word");
908 test_range_text(body_range, "wordabc 123\r\nit's text");
909 test_range_text(range, NULL);
910 test_range_moveend(range, characterW, 3, 3);
911 test_range_text(range, "abc");
912 test_range_movestart(range, characterW, -2, -2);
913 test_range_text(range, "rdabc");
914 test_range_movestart(range, characterW, 3, 3);
915 test_range_text(range, "bc");
916 test_range_movestart(range, characterW, 4, 4);
917 test_range_text(range, NULL);
918 test_range_movestart(range, characterW, -3, -3);
919 test_range_text(range, "c 1");
920 test_range_movestart(range, characterW, -7, -6);
921 test_range_text(range, "wordabc 1");
922 test_range_movestart(range, characterW, 100, 22);
923 test_range_text(range, NULL);
925 IHTMLTxtRange_Release(range);
926 IHTMLTxtRange_Release(body_range);
928 hres = IHTMLDocument2_get_selection(doc, &selection);
929 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
931 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
932 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
933 IHTMLSelectionObject_Release(selection);
935 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
936 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
937 IDispatch_Release(disp_range);
939 test_range_text(range, NULL);
940 test_range_moveend(range, characterW, 3, 3);
941 test_range_text(range, "wor");
942 test_range_parent(range, ET_BODY);
943 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
944 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
945 test_range_move(range, characterW, 3, 3);
946 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
947 test_range_moveend(range, characterW, -4, -4);
948 test_range_put_text(range, "abc def ");
949 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
950 test_range_move(range, wordW, 1, 1);
951 test_range_movestart(range, characterW, -1, -1);
952 test_range_text(range, " ");
953 test_range_move(range, wordW, 1, 1);
954 test_range_moveend(range, characterW, 3, 3);
955 test_range_text(range, "def");
956 test_range_put_text(range, "xyz");
957 test_range_moveend(range, characterW, 1, 1);
958 test_range_move(range, wordW, 1, 1);
959 test_range_moveend(range, characterW, 2, 2);
960 test_range_text(range, "ab");
962 IHTMLTxtRange_Release(range);
965 static void test_txtrange2(IHTMLDocument2 *doc)
967 IHTMLTxtRange *range;
969 range = test_create_body_range(doc);
971 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
972 test_range_move(range, characterW, 5, 5);
973 test_range_moveend(range, characterW, 1, 1);
974 test_range_text(range, "2");
975 test_range_move(range, characterW, -3, -3);
976 test_range_moveend(range, characterW, 3, 3);
977 test_range_text(range, "c\r\n\r\n1");
978 test_range_collapse(range, VARIANT_FALSE);
979 test_range_moveend(range, characterW, 4, 4);
980 test_range_text(range, "23");
981 test_range_moveend(range, characterW, 1, 1);
982 test_range_text(range, "23\r\n\r\n\r\nd");
983 test_range_moveend(range, characterW, -1, -1);
984 test_range_text(range, "23");
985 test_range_moveend(range, characterW, -1, -1);
986 test_range_text(range, "23");
987 test_range_moveend(range, characterW, -2, -2);
988 test_range_text(range, "2");
990 IHTMLTxtRange_Release(range);
993 static void test_compatmode(IHTMLDocument2 *doc)
995 IHTMLDocument5 *doc5;
999 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1000 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1004 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1005 IHTMLDocument5_Release(doc5);
1006 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1007 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1008 SysFreeString(mode);
1011 static void test_location(IHTMLDocument2 *doc)
1013 IHTMLLocation *location, *location2;
1017 hres = IHTMLDocument2_get_location(doc, &location);
1018 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1020 hres = IHTMLDocument2_get_location(doc, &location2);
1021 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1023 ok(location == location2, "location != location2\n");
1025 test_ifaces((IUnknown*)location, location_iids);
1027 IHTMLLocation_Release(location2);
1028 ref = IHTMLLocation_Release(location);
1029 ok(!ref, "location chould be destroyed here\n");
1032 static void test_navigator(IHTMLDocument2 *doc)
1034 IHTMLWindow2 *window;
1035 IOmNavigator *navigator, *navigator2;
1039 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1040 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1042 hres = IHTMLWindow2_get_navigator(window, &navigator);
1043 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1044 ok(navigator != NULL, "navigator == NULL\n");
1046 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1047 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1048 ok(navigator != navigator2, "navigator2 != navihgator\n");
1050 IHTMLWindow2_Release(window);
1051 IOmNavigator_Release(navigator2);
1052 ref = IOmNavigator_Release(navigator);
1053 ok(!ref, "navigator should be destroyed here\n");
1056 static void test_default_style(IHTMLStyle *style)
1063 str = (void*)0xdeadbeef;
1064 hres = IHTMLStyle_get_fontFamily(style, &str);
1065 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1066 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1068 str = (void*)0xdeadbeef;
1069 hres = IHTMLStyle_get_fontWeight(style, &str);
1070 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1071 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1073 str = (void*)0xdeadbeef;
1074 hres = IHTMLStyle_get_display(style, &str);
1075 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1076 ok(!str, "display = %s\n", dbgstr_w(str));
1078 str = (void*)0xdeadbeef;
1079 hres = IHTMLStyle_get_visibility(style, &str);
1080 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1081 ok(!str, "visibility = %s\n", dbgstr_w(str));
1084 hres = IHTMLStyle_get_fontSize(style, &v);
1085 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1086 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1087 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1090 hres = IHTMLStyle_get_color(style, &v);
1091 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1092 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1093 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1096 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1097 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1098 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1101 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1102 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1103 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1106 static void test_default_selection(IHTMLDocument2 *doc)
1108 IHTMLSelectionObject *selection;
1109 IHTMLTxtRange *range;
1114 hres = IHTMLDocument2_get_selection(doc, &selection);
1115 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1117 hres = IHTMLSelectionObject_get_type(selection, &str);
1118 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1119 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1122 hres = IHTMLSelectionObject_createRange(selection, &disp);
1123 IHTMLSelectionObject_Release(selection);
1124 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1126 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1127 IDispatch_Release(disp);
1128 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1130 test_range_text(range, NULL);
1131 IHTMLTxtRange_Release(range);
1134 static void test_default_body(IHTMLBodyElement *body)
1139 bstr = (void*)0xdeadbeef;
1140 hres = IHTMLBodyElement_get_background(body, &bstr);
1141 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1142 ok(bstr == NULL, "bstr != NULL\n");
1145 static void test_defaults(IHTMLDocument2 *doc)
1147 IHTMLStyleSheetsCollection *stylesheetcol;
1148 IHTMLBodyElement *body;
1154 hres = IHTMLDocument2_get_body(doc, &elem);
1155 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1157 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1158 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1159 test_default_body(body);
1160 IHTMLBodyElement_Release(body);
1162 hres = IHTMLElement_get_style(elem, &style);
1163 IHTMLElement_Release(elem);
1164 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1166 test_default_style(style);
1167 test_compatmode(doc);
1169 test_navigator(doc);
1171 IHTMLStyle_Release(style);
1173 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1174 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1177 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1178 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1179 ok(l == 0, "length = %ld\n", l);
1181 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1183 test_default_selection(doc);
1186 static void test_stylesheet(IDispatch *disp)
1188 IHTMLStyleSheetRulesCollection *col = NULL;
1189 IHTMLStyleSheet *stylesheet;
1192 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1193 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1195 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1196 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1197 ok(col != NULL, "col == NULL\n");
1199 IHTMLStyleSheetRulesCollection_Release(col);
1200 IHTMLStyleSheet_Release(stylesheet);
1203 static void test_stylesheets(IHTMLDocument2 *doc)
1205 IHTMLStyleSheetsCollection *col = NULL;
1210 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1211 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1212 ok(col != NULL, "col == NULL\n");
1214 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1215 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1216 ok(len == 1, "len=%ld\n", len);
1222 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1223 ok(hres == S_OK, "item failed: %08x\n", hres);
1224 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1225 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1226 test_stylesheet(V_DISPATCH(&res));
1233 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1234 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1235 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1236 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1239 IHTMLStyleSheetsCollection_Release(col);
1242 static void test_elems(IHTMLDocument2 *doc)
1244 IHTMLElementCollection *col;
1249 static const WCHAR xW[] = {'x',0};
1250 static const WCHAR sW[] = {'s',0};
1251 static const WCHAR scW[] = {'s','c',0};
1252 static const WCHAR xxxW[] = {'x','x','x',0};
1254 static const elem_type_t all_types[] = {
1271 static const elem_type_t item_types[] = {
1277 hres = IHTMLDocument2_get_all(doc, &col);
1278 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1279 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1280 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1281 IHTMLElementCollection_Release(col);
1283 elem = get_doc_elem(doc);
1284 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1285 hres = IHTMLElement_get_all(elem, &disp);
1286 IHTMLElement_Release(elem);
1287 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1289 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1290 IDispatch_Release(disp);
1291 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1292 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1293 IHTMLElementCollection_Release(col);
1295 get_elem_by_id(doc, xxxW, FALSE);
1296 elem = get_elem_by_id(doc, sW, TRUE);
1298 IHTMLSelectElement *select;
1300 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1301 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1303 test_select_elem(select);
1305 IHTMLSelectElement_Release(select);
1306 IHTMLElement_Release(elem);
1309 elem = get_elem_by_id(doc, scW, TRUE);
1311 IHTMLScriptElement *script;
1314 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1315 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1317 hres = IHTMLScriptElement_get_type(script, &type);
1318 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1319 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1320 SysFreeString(type);
1323 test_stylesheets(doc);
1324 test_create_option_elem(doc);
1327 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1329 IOleCommandTarget *cmdtrg;
1332 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1333 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1335 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1336 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1338 IOleCommandTarget_Release(cmdtrg);
1341 static void test_indent(IHTMLDocument2 *doc)
1343 IHTMLElementCollection *col;
1344 IHTMLTxtRange *range;
1347 static const elem_type_t all_types[] = {
1356 static const elem_type_t indent_types[] = {
1367 hres = IHTMLDocument2_get_all(doc, &col);
1368 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1369 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1370 IHTMLElementCollection_Release(col);
1372 range = test_create_body_range(doc);
1373 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1374 IHTMLTxtRange_Release(range);
1376 hres = IHTMLDocument2_get_all(doc, &col);
1377 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1378 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1379 IHTMLElementCollection_Release(col);
1382 static IHTMLDocument2 *notif_doc;
1383 static BOOL doc_complete;
1385 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1386 REFIID riid, void**ppv)
1388 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1393 ok(0, "unexpected call\n");
1394 return E_NOINTERFACE;
1397 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1402 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1407 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1409 if(dispID == DISPID_READYSTATE){
1413 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1415 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1416 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1418 if(!lstrcmpW(state, completeW))
1419 doc_complete = TRUE;
1421 SysFreeString(state);
1427 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1429 ok(0, "unexpected call\n");
1433 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1434 PropertyNotifySink_QueryInterface,
1435 PropertyNotifySink_AddRef,
1436 PropertyNotifySink_Release,
1437 PropertyNotifySink_OnChanged,
1438 PropertyNotifySink_OnRequestEdit
1441 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1443 static IHTMLDocument2 *create_doc_with_string(const char *str)
1445 IPersistStreamInit *init;
1447 IHTMLDocument2 *doc;
1451 notif_doc = doc = create_document();
1455 doc_complete = FALSE;
1457 mem = GlobalAlloc(0, len);
1458 memcpy(mem, str, len);
1459 CreateStreamOnHGlobal(mem, TRUE, &stream);
1461 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1463 IPersistStreamInit_Load(init, stream);
1464 IPersistStreamInit_Release(init);
1465 IStream_Release(stream);
1470 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1472 IConnectionPointContainer *container;
1473 IConnectionPoint *cp;
1477 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1478 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1480 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1481 IConnectionPointContainer_Release(container);
1482 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1484 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1485 IConnectionPoint_Release(cp);
1486 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1489 typedef void (*domtest_t)(IHTMLDocument2*);
1491 static void run_domtest(const char *str, domtest_t test)
1493 IHTMLDocument2 *doc;
1494 IHTMLElement *body = NULL;
1499 doc = create_doc_with_string(str);
1500 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1502 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1503 TranslateMessage(&msg);
1504 DispatchMessage(&msg);
1507 hres = IHTMLDocument2_get_body(doc, &body);
1508 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1511 IHTMLElement_Release(body);
1514 skip("Could not get document body. Assuming no Gecko installed.\n");
1517 ref = IHTMLDocument2_Release(doc);
1518 ok(!ref, "ref = %d\n", ref);
1521 static void gecko_installer_workaround(BOOL disable)
1526 static BOOL has_url = FALSE;
1527 static char url[2048];
1529 if(!disable && !has_url)
1532 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1533 if(res != ERROR_SUCCESS)
1537 DWORD type, size = sizeof(url);
1539 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1540 if(res == ERROR_SUCCESS && type == REG_SZ)
1543 RegDeleteValue(hkey, "GeckoUrl");
1545 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1553 gecko_installer_workaround(TRUE);
1556 run_domtest(doc_str1, test_doc_elem);
1557 run_domtest(range_test_str, test_txtrange);
1558 run_domtest(range_test2_str, test_txtrange2);
1559 run_domtest(elem_test_str, test_elems);
1560 run_domtest(doc_blank, test_defaults);
1561 run_domtest(indent_test_str, test_indent);
1564 gecko_installer_workaround(FALSE);