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,
171 static const elem_type_info_t elem_type_infos[] = {
175 {"TITLE", elem_iids},
178 {"INPUT", input_iids},
179 {"SELECT", select_iids},
180 {"TEXTAREA", textarea_iids},
181 {"OPTION", option_iids},
182 {"STYLE", elem_iids},
183 {"BLOCKQUOTE",elem_iids},
186 {"TABLE", table_iids},
187 {"TBODY", elem_iids},
188 {"SCRIPT", script_iids}
191 static const char *dbgstr_w(LPCWSTR str)
193 static char buf[512];
196 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
200 static const char *dbgstr_guid(REFIID riid)
204 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
205 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
206 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
207 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
212 static int strcmp_wa(LPCWSTR strw, const char *stra)
215 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
216 return lstrcmpW(strw, buf);
219 static BSTR a2bstr(const char *str)
224 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
225 ret = SysAllocStringLen(NULL, len);
226 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
231 static IHTMLDocument2 *create_document(void)
236 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
237 &IID_IHTMLDocument2, (void**)&doc);
238 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
243 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
244 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
246 const IID * const *piid;
250 for(piid = iids; *piid; piid++) {
251 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
252 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
254 IUnknown_Release(unk);
258 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
259 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
265 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
266 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
268 hres = IHTMLDOMNode_get_nodeName(node, &name);
269 IHTMLDOMNode_Release(node);
270 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
271 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
276 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
277 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
283 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
284 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
286 hres = IHTMLElement_get_tagName(elem, &tag);
287 IHTMLElement_Release(elem);
288 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
289 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
294 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
295 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
297 _test_elem_tag(line, unk, elem_type_infos[type].tag);
298 _test_ifaces(line, unk, elem_type_infos[type].iids);
301 static void test_doc_elem(IHTMLDocument2 *doc)
304 IHTMLDocument3 *doc3;
307 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
308 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
310 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
311 IHTMLDocument3_Release(doc3);
312 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
314 test_node_name((IUnknown*)elem, "HTML");
315 test_elem_tag((IUnknown*)elem, "HTML");
317 IHTMLElement_Release(elem);
320 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
321 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
324 IHTMLDocument3 *doc3;
327 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
328 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
329 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
330 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
331 IHTMLDocument3_Release(doc3);
336 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
337 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
342 hres = IHTMLOptionElement_get_text(option, &bstr);
343 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
344 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
348 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
349 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
355 hres = IHTMLOptionElement_put_text(option, bstr);
357 ok(hres == S_OK, "put_text failed: %08x\n", hres);
359 _test_option_text(line, option, text);
362 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
363 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
368 hres = IHTMLOptionElement_get_value(option, &bstr);
369 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
370 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
374 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
375 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
380 bstr = a2bstr(value);
381 hres = IHTMLOptionElement_put_value(option, bstr);
383 ok(hres == S_OK, "put_value failed: %08x\n", hres);
385 _test_option_value(line, option, value);
388 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
389 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
390 const char *txt, const char *val)
392 IHTMLOptionElementFactory *factory;
393 IHTMLOptionElement *option;
394 IHTMLWindow2 *window;
395 VARIANT text, value, empty;
398 hres = IHTMLDocument2_get_parentWindow(doc, &window);
399 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
401 hres = IHTMLWindow2_get_Option(window, &factory);
402 IHTMLWindow2_Release(window);
403 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
405 V_VT(&text) = VT_BSTR;
406 V_BSTR(&text) = a2bstr(txt);
407 V_VT(&value) = VT_BSTR;
408 V_BSTR(&value) = a2bstr(val);
409 V_VT(&empty) = VT_EMPTY;
411 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
412 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
414 IHTMLOptionElementFactory_Release(factory);
416 VariantClear(&value);
418 _test_option_text(line, option, txt);
419 _test_option_value(line, option, val);
424 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
425 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
427 long len = 0xdeadbeef;
430 hres = IHTMLSelectElement_get_length(select, &len);
431 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
432 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
435 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
436 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
438 long idx = 0xdeadbeef;
441 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
442 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
443 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
446 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
447 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
451 hres = IHTMLSelectElement_put_selectedIndex(select, index);
452 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
453 _test_select_selidx(line, select, index);
456 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
457 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
462 hres = IHTMLTxtRange_get_text(range, &text);
463 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
466 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
467 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
469 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
476 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
477 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
481 hres = IHTMLTxtRange_collapse(range, b);
482 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
483 _test_range_text(line, range, NULL);
486 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
487 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
488 VARIANT_BOOL exb, const char *extext)
490 VARIANT_BOOL b = 0xe0e0;
493 hres = IHTMLTxtRange_expand(range, unit, &b);
494 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
495 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
496 _test_range_text(line, range, extext);
499 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
500 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
505 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
506 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
507 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
508 _test_range_text(line, range, NULL);
511 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
512 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
513 LPWSTR unit, long cnt, long excnt)
518 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
519 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
520 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
523 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
524 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
529 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
530 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
531 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
534 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
535 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
538 BSTR bstr = a2bstr(text);
540 hres = IHTMLTxtRange_put_text(range, bstr);
541 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
543 _test_range_text(line, range, NULL);
546 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
547 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
553 hres = IHTMLTxtRange_inRange(range1, range2, &b);
554 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
555 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
558 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
559 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
565 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
566 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
567 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
570 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
571 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
572 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
575 test_range_inrange(range1, range2, VARIANT_TRUE);
576 test_range_inrange(range2, range1, VARIANT_TRUE);
580 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
581 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
586 hres = IHTMLTxtRange_parentElement(range, &elem);
587 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
589 _test_elem_type(line, (IUnknown*)elem, type);
591 IHTMLElement_Release(elem);
594 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
595 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
596 const elem_type_t *elem_types, long exlen)
604 hres = IHTMLElementCollection_get_length(col, &len);
605 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
606 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
611 V_VT(&index) = VT_EMPTY;
614 for(i=0; i<len; i++) {
616 disp = (void*)0xdeadbeef;
617 hres = IHTMLElementCollection_item(col, name, index, &disp);
618 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
619 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
620 if(FAILED(hres) || !disp)
623 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
624 IDispatch_Release(disp);
628 disp = (void*)0xdeadbeef;
629 hres = IHTMLElementCollection_item(col, name, index, &disp);
630 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
631 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
634 disp = (void*)0xdeadbeef;
635 hres = IHTMLElementCollection_item(col, name, index, &disp);
636 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
637 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
640 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
641 const elem_type_t *elem_types, long len)
643 IHTMLElementCollection *elcol;
649 V_VT(&index) = VT_EMPTY;
650 V_VT(&name) = VT_BSTR;
651 V_BSTR(&name) = SysAllocString(n);
653 hres = IHTMLElementCollection_item(col, name, index, &disp);
654 ok(hres == S_OK, "item failed: %08x\n", hres);
656 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
657 IDispatch_Release(disp);
658 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
659 test_elem_collection(elcol, elem_types, len);
660 IHTMLElementCollection_Release(elcol);
662 V_VT(&index) = VT_I4;
664 for(i=0; i<len; i++) {
666 disp = (void*)0xdeadbeef;
667 hres = IHTMLElementCollection_item(col, name, index, &disp);
668 ok(hres == S_OK, "item failed: %08x\n", hres);
669 ok(disp != NULL, "disp == NULL\n");
670 if(FAILED(hres) || !disp)
673 test_elem_type((IUnknown*)disp, elem_types[i]);
675 IDispatch_Release(disp);
679 disp = (void*)0xdeadbeef;
680 hres = IHTMLElementCollection_item(col, name, index, &disp);
681 ok(hres == S_OK, "item failed: %08x\n", hres);
682 ok(disp == NULL, "disp != NULL\n");
685 disp = (void*)0xdeadbeef;
686 hres = IHTMLElementCollection_item(col, name, index, &disp);
687 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
688 ok(disp == NULL, "disp != NULL\n");
690 SysFreeString(V_BSTR(&name));
693 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
695 IHTMLElementCollection *col;
697 IDispatch *disp = (void*)0xdeadbeef;
701 hres = IHTMLDocument2_get_all(doc, &col);
702 ok(hres == S_OK, "get_all failed: %08x\n", hres);
703 ok(col != NULL, "col == NULL\n");
704 if(FAILED(hres) || !col)
707 V_VT(&index) = VT_EMPTY;
708 V_VT(&name) = VT_BSTR;
709 V_BSTR(&name) = SysAllocString(id);
711 hres = IHTMLElementCollection_item(col, name, index, &disp);
712 IHTMLElementCollection_Release(col);
713 SysFreeString(V_BSTR(&name));
714 ok(hres == S_OK, "item failed: %08x\n", hres);
715 if(!expect_success) {
716 ok(disp == NULL, "disp != NULL\n");
720 ok(disp != NULL, "disp == NULL\n");
724 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
725 IDispatch_Release(disp);
726 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
731 static void test_select_elem(IHTMLSelectElement *select)
733 test_select_length(select, 2);
734 test_select_selidx(select, 0);
735 test_select_put_selidx(select, 1);
738 static void test_create_option_elem(IHTMLDocument2 *doc)
740 IHTMLOptionElement *option;
742 option = create_option_elem(doc, "test text", "test value");
744 test_option_put_text(option, "new text");
745 test_option_put_value(option, "new value");
747 IHTMLOptionElement_Release(option);
750 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
752 IHTMLBodyElement *body;
753 IHTMLTxtRange *range;
757 hres = IHTMLDocument2_get_body(doc, &elem);
758 ok(hres == S_OK, "get_body failed: %08x\n", hres);
760 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
761 IHTMLElement_Release(elem);
763 hres = IHTMLBodyElement_createTextRange(body, &range);
764 IHTMLBodyElement_Release(body);
765 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
770 static void test_txtrange(IHTMLDocument2 *doc)
772 IHTMLTxtRange *body_range, *range, *range2;
773 IHTMLSelectionObject *selection;
774 IDispatch *disp_range;
777 body_range = test_create_body_range(doc);
779 test_range_text(body_range, "test abc 123\r\nit's text");
781 hres = IHTMLTxtRange_duplicate(body_range, &range);
782 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
784 hres = IHTMLTxtRange_duplicate(body_range, &range2);
785 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
786 test_range_isequal(range, range2, VARIANT_TRUE);
788 test_range_text(range, "test abc 123\r\nit's text");
789 test_range_text(body_range, "test abc 123\r\nit's text");
791 test_range_collapse(range, TRUE);
792 test_range_isequal(range, range2, VARIANT_FALSE);
793 test_range_inrange(range, range2, VARIANT_FALSE);
794 test_range_inrange(range2, range, VARIANT_TRUE);
795 IHTMLTxtRange_Release(range2);
797 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
798 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
799 test_range_move(range, characterW, 2, 2);
800 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
802 test_range_collapse(range, FALSE);
803 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
805 test_range_collapse(range, FALSE);
806 test_range_expand(range, wordW, VARIANT_TRUE, "123");
807 test_range_expand(range, wordW, VARIANT_FALSE, "123");
808 test_range_move(range, characterW, 2, 2);
809 test_range_expand(range, wordW, VARIANT_TRUE, "123");
810 test_range_moveend(range, characterW, -5, -5);
811 test_range_text(range, NULL);
812 test_range_moveend(range, characterW, 3, 3);
813 test_range_text(range, "c 1");
814 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
815 test_range_collapse(range, TRUE);
816 test_range_move(range, characterW, 4, 4);
817 test_range_moveend(range, characterW, 1, 1);
818 test_range_text(range, " ");
819 test_range_move(range, wordW, 1, 1);
820 test_range_moveend(range, characterW, 2, 2);
821 test_range_text(range, "ab");
823 IHTMLTxtRange_Release(range);
825 hres = IHTMLTxtRange_duplicate(body_range, &range);
826 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
828 test_range_text(range, "test abc 123\r\nit's text");
829 test_range_move(range, characterW, 3, 3);
830 test_range_moveend(range, characterW, 1, 1);
831 test_range_text(range, "t");
832 test_range_moveend(range, characterW, 3, 3);
833 test_range_text(range, "t ab");
834 test_range_moveend(range, characterW, -2, -2);
835 test_range_text(range, "t ");
836 test_range_move(range, characterW, 6, 6);
837 test_range_moveend(range, characterW, 3, 3);
838 test_range_text(range, "123");
839 test_range_moveend(range, characterW, 2, 2);
840 test_range_text(range, "123\r\ni");
842 IHTMLTxtRange_Release(range);
844 hres = IHTMLTxtRange_duplicate(body_range, &range);
845 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
847 test_range_move(range, wordW, 1, 1);
848 test_range_moveend(range, characterW, 2, 2);
849 test_range_text(range, "ab");
851 test_range_move(range, characterW, -2, -2);
852 test_range_moveend(range, characterW, 2, 2);
853 test_range_text(range, "t ");
855 test_range_move(range, wordW, 3, 3);
856 test_range_move(range, wordW, -2, -2);
857 test_range_moveend(range, characterW, 2, 2);
858 test_range_text(range, "ab");
860 test_range_move(range, characterW, -6, -5);
861 test_range_moveend(range, characterW, -1, 0);
862 test_range_moveend(range, characterW, -6, 0);
863 test_range_move(range, characterW, 2, 2);
864 test_range_moveend(range, characterW, 2, 2);
865 test_range_text(range, "st");
866 test_range_moveend(range, characterW, -6, -4);
867 test_range_moveend(range, characterW, 2, 2);
869 IHTMLTxtRange_Release(range);
871 hres = IHTMLTxtRange_duplicate(body_range, &range);
872 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
874 test_range_move(range, wordW, 2, 2);
875 test_range_moveend(range, characterW, 2, 2);
876 test_range_text(range, "12");
878 test_range_move(range, characterW, 15, 14);
879 test_range_move(range, characterW, -2, -2);
880 test_range_moveend(range, characterW, 3, 2);
881 test_range_text(range, "t");
882 test_range_moveend(range, characterW, -1, -1);
883 test_range_text(range, "t");
884 test_range_expand(range, wordW, VARIANT_TRUE, "text");
885 test_range_move(range, characterW, -2, -2);
886 test_range_moveend(range, characterW, 2, 2);
887 test_range_text(range, "s ");
888 test_range_move(range, characterW, 100, 7);
889 test_range_move(range, wordW, 1, 0);
890 test_range_move(range, characterW, -2, -2);
891 test_range_moveend(range, characterW, 3, 2);
892 test_range_text(range, "t");
894 IHTMLTxtRange_Release(range);
896 hres = IHTMLTxtRange_duplicate(body_range, &range);
897 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
899 test_range_collapse(range, TRUE);
900 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
901 test_range_put_text(range, "word");
902 test_range_text(body_range, "wordabc 123\r\nit's text");
903 test_range_text(range, NULL);
904 test_range_moveend(range, characterW, 3, 3);
905 test_range_text(range, "abc");
906 test_range_movestart(range, characterW, -2, -2);
907 test_range_text(range, "rdabc");
908 test_range_movestart(range, characterW, 3, 3);
909 test_range_text(range, "bc");
910 test_range_movestart(range, characterW, 4, 4);
911 test_range_text(range, NULL);
912 test_range_movestart(range, characterW, -3, -3);
913 test_range_text(range, "c 1");
914 test_range_movestart(range, characterW, -7, -6);
915 test_range_text(range, "wordabc 1");
916 test_range_movestart(range, characterW, 100, 22);
917 test_range_text(range, NULL);
919 IHTMLTxtRange_Release(range);
920 IHTMLTxtRange_Release(body_range);
922 hres = IHTMLDocument2_get_selection(doc, &selection);
923 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
925 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
926 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
927 IHTMLSelectionObject_Release(selection);
929 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
930 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
931 IDispatch_Release(disp_range);
933 test_range_text(range, NULL);
934 test_range_moveend(range, characterW, 3, 3);
935 test_range_text(range, "wor");
936 test_range_parent(range, ET_BODY);
937 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
938 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
939 test_range_move(range, characterW, 3, 3);
940 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
941 test_range_moveend(range, characterW, -4, -4);
942 test_range_put_text(range, "abc def ");
943 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
944 test_range_move(range, wordW, 1, 1);
945 test_range_movestart(range, characterW, -1, -1);
946 test_range_text(range, " ");
947 test_range_move(range, wordW, 1, 1);
948 test_range_moveend(range, characterW, 3, 3);
949 test_range_text(range, "def");
950 test_range_put_text(range, "xyz");
951 test_range_moveend(range, characterW, 1, 1);
952 test_range_move(range, wordW, 1, 1);
953 test_range_moveend(range, characterW, 2, 2);
954 test_range_text(range, "ab");
956 IHTMLTxtRange_Release(range);
959 static void test_txtrange2(IHTMLDocument2 *doc)
961 IHTMLTxtRange *range;
963 range = test_create_body_range(doc);
965 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
966 test_range_move(range, characterW, 5, 5);
967 test_range_moveend(range, characterW, 1, 1);
968 test_range_text(range, "2");
969 test_range_move(range, characterW, -3, -3);
970 test_range_moveend(range, characterW, 3, 3);
971 test_range_text(range, "c\r\n\r\n1");
972 test_range_collapse(range, VARIANT_FALSE);
973 test_range_moveend(range, characterW, 4, 4);
974 test_range_text(range, "23");
975 test_range_moveend(range, characterW, 1, 1);
976 test_range_text(range, "23\r\n\r\n\r\nd");
977 test_range_moveend(range, characterW, -1, -1);
978 test_range_text(range, "23");
979 test_range_moveend(range, characterW, -1, -1);
980 test_range_text(range, "23");
981 test_range_moveend(range, characterW, -2, -2);
982 test_range_text(range, "2");
984 IHTMLTxtRange_Release(range);
987 static void test_compatmode(IHTMLDocument2 *doc)
989 IHTMLDocument5 *doc5;
993 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
994 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
998 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
999 IHTMLDocument5_Release(doc5);
1000 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1001 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1002 SysFreeString(mode);
1005 static void test_default_style(IHTMLStyle *style)
1012 str = (void*)0xdeadbeef;
1013 hres = IHTMLStyle_get_fontFamily(style, &str);
1014 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1015 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1017 str = (void*)0xdeadbeef;
1018 hres = IHTMLStyle_get_fontWeight(style, &str);
1019 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1020 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1022 str = (void*)0xdeadbeef;
1023 hres = IHTMLStyle_get_display(style, &str);
1024 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1025 ok(!str, "display = %s\n", dbgstr_w(str));
1027 str = (void*)0xdeadbeef;
1028 hres = IHTMLStyle_get_visibility(style, &str);
1029 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1030 ok(!str, "visibility = %s\n", dbgstr_w(str));
1033 hres = IHTMLStyle_get_fontSize(style, &v);
1034 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1035 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1036 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1039 hres = IHTMLStyle_get_color(style, &v);
1040 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1041 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1042 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1045 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1046 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1047 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1050 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1051 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1052 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1055 static void test_default_selection(IHTMLDocument2 *doc)
1057 IHTMLSelectionObject *selection;
1058 IHTMLTxtRange *range;
1063 hres = IHTMLDocument2_get_selection(doc, &selection);
1064 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1066 hres = IHTMLSelectionObject_get_type(selection, &str);
1067 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1068 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1071 hres = IHTMLSelectionObject_createRange(selection, &disp);
1072 IHTMLSelectionObject_Release(selection);
1073 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1075 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1076 IDispatch_Release(disp);
1077 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1079 test_range_text(range, NULL);
1080 IHTMLTxtRange_Release(range);
1083 static void test_default_body(IHTMLBodyElement *body)
1088 bstr = (void*)0xdeadbeef;
1089 hres = IHTMLBodyElement_get_background(body, &bstr);
1090 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1091 ok(bstr == NULL, "bstr != NULL\n");
1094 static void test_defaults(IHTMLDocument2 *doc)
1096 IHTMLStyleSheetsCollection *stylesheetcol;
1097 IHTMLBodyElement *body;
1103 hres = IHTMLDocument2_get_body(doc, &elem);
1104 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1106 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1107 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1108 test_default_body(body);
1109 IHTMLBodyElement_Release(body);
1111 hres = IHTMLElement_get_style(elem, &style);
1112 IHTMLElement_Release(elem);
1113 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1115 test_default_style(style);
1116 test_compatmode(doc);
1118 IHTMLStyle_Release(style);
1120 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1121 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1124 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1125 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1126 ok(l == 0, "length = %ld\n", l);
1128 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1130 test_default_selection(doc);
1133 static void test_stylesheet(IDispatch *disp)
1135 IHTMLStyleSheetRulesCollection *col = NULL;
1136 IHTMLStyleSheet *stylesheet;
1139 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1140 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1142 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1143 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1144 ok(col != NULL, "col == NULL\n");
1146 IHTMLStyleSheetRulesCollection_Release(col);
1147 IHTMLStyleSheet_Release(stylesheet);
1150 static void test_stylesheets(IHTMLDocument2 *doc)
1152 IHTMLStyleSheetsCollection *col = NULL;
1157 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1158 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1159 ok(col != NULL, "col == NULL\n");
1161 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1162 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1163 ok(len == 1, "len=%ld\n", len);
1169 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1170 ok(hres == S_OK, "item failed: %08x\n", hres);
1171 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1172 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1173 test_stylesheet(V_DISPATCH(&res));
1180 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1181 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1182 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1183 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1186 IHTMLStyleSheetsCollection_Release(col);
1189 static void test_elems(IHTMLDocument2 *doc)
1191 IHTMLElementCollection *col;
1196 static const WCHAR xW[] = {'x',0};
1197 static const WCHAR sW[] = {'s',0};
1198 static const WCHAR scW[] = {'s','c',0};
1199 static const WCHAR xxxW[] = {'x','x','x',0};
1201 static const elem_type_t all_types[] = {
1218 static const elem_type_t item_types[] = {
1224 hres = IHTMLDocument2_get_all(doc, &col);
1225 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1226 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1227 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1228 IHTMLElementCollection_Release(col);
1230 elem = get_doc_elem(doc);
1231 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1232 hres = IHTMLElement_get_all(elem, &disp);
1233 IHTMLElement_Release(elem);
1234 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1236 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1237 IDispatch_Release(disp);
1238 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1239 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1240 IHTMLElementCollection_Release(col);
1242 get_elem_by_id(doc, xxxW, FALSE);
1243 elem = get_elem_by_id(doc, sW, TRUE);
1245 IHTMLSelectElement *select;
1247 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1248 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1250 test_select_elem(select);
1252 IHTMLSelectElement_Release(select);
1253 IHTMLElement_Release(elem);
1256 elem = get_elem_by_id(doc, scW, TRUE);
1258 IHTMLScriptElement *script;
1261 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1262 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1264 hres = IHTMLScriptElement_get_type(script, &type);
1265 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1266 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1267 SysFreeString(type);
1270 test_stylesheets(doc);
1271 test_create_option_elem(doc);
1274 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1276 IOleCommandTarget *cmdtrg;
1279 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1280 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1282 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1283 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1285 IOleCommandTarget_Release(cmdtrg);
1288 static void test_indent(IHTMLDocument2 *doc)
1290 IHTMLElementCollection *col;
1291 IHTMLTxtRange *range;
1294 static const elem_type_t all_types[] = {
1303 static const elem_type_t indent_types[] = {
1314 hres = IHTMLDocument2_get_all(doc, &col);
1315 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1316 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1317 IHTMLElementCollection_Release(col);
1319 range = test_create_body_range(doc);
1320 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1321 IHTMLTxtRange_Release(range);
1323 hres = IHTMLDocument2_get_all(doc, &col);
1324 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1325 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1326 IHTMLElementCollection_Release(col);
1329 static IHTMLDocument2 *notif_doc;
1330 static BOOL doc_complete;
1332 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1333 REFIID riid, void**ppv)
1335 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1340 ok(0, "unexpected call\n");
1341 return E_NOINTERFACE;
1344 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1349 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1354 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1356 if(dispID == DISPID_READYSTATE){
1360 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1362 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1363 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1365 if(!lstrcmpW(state, completeW))
1366 doc_complete = TRUE;
1368 SysFreeString(state);
1374 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1376 ok(0, "unexpected call\n");
1380 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1381 PropertyNotifySink_QueryInterface,
1382 PropertyNotifySink_AddRef,
1383 PropertyNotifySink_Release,
1384 PropertyNotifySink_OnChanged,
1385 PropertyNotifySink_OnRequestEdit
1388 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1390 static IHTMLDocument2 *create_doc_with_string(const char *str)
1392 IPersistStreamInit *init;
1394 IHTMLDocument2 *doc;
1398 notif_doc = doc = create_document();
1402 doc_complete = FALSE;
1404 mem = GlobalAlloc(0, len);
1405 memcpy(mem, str, len);
1406 CreateStreamOnHGlobal(mem, TRUE, &stream);
1408 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1410 IPersistStreamInit_Load(init, stream);
1411 IPersistStreamInit_Release(init);
1412 IStream_Release(stream);
1417 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1419 IConnectionPointContainer *container;
1420 IConnectionPoint *cp;
1424 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1425 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1427 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1428 IConnectionPointContainer_Release(container);
1429 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1431 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1432 IConnectionPoint_Release(cp);
1433 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1436 typedef void (*domtest_t)(IHTMLDocument2*);
1438 static void run_domtest(const char *str, domtest_t test)
1440 IHTMLDocument2 *doc;
1441 IHTMLElement *body = NULL;
1446 doc = create_doc_with_string(str);
1447 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1449 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1450 TranslateMessage(&msg);
1451 DispatchMessage(&msg);
1454 hres = IHTMLDocument2_get_body(doc, &body);
1455 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1458 IHTMLElement_Release(body);
1461 skip("Could not get document body. Assuming no Gecko installed.\n");
1464 ref = IHTMLDocument2_Release(doc);
1465 ok(!ref, "ref = %d\n", ref);
1468 static void gecko_installer_workaround(BOOL disable)
1473 static BOOL has_url = FALSE;
1474 static char url[2048];
1476 if(!disable && !has_url)
1479 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1480 if(res != ERROR_SUCCESS)
1484 DWORD type, size = sizeof(url);
1486 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1487 if(res == ERROR_SUCCESS && type == REG_SZ)
1490 RegDeleteValue(hkey, "GeckoUrl");
1492 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1500 gecko_installer_workaround(TRUE);
1503 run_domtest(doc_str1, test_doc_elem);
1504 run_domtest(range_test_str, test_txtrange);
1505 run_domtest(range_test2_str, test_txtrange2);
1506 run_domtest(elem_test_str, test_elems);
1507 run_domtest(doc_blank, test_defaults);
1508 run_domtest(indent_test_str, test_indent);
1511 gecko_installer_workaround(FALSE);