2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
35 static const char doc_blank[] = "<html></html>";
36 static const char doc_str1[] = "<html><body>test</body></html>";
37 static const char range_test_str[] =
38 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
39 static const char range_test2_str[] =
40 "<html><body>abc<hr />123<br /><hr />def</body></html>";
41 static const char elem_test_str[] =
42 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
43 "<body><a href=\"http://test\" name=\"x\">link</a><input />"
44 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
45 "<textarea id=\"X\">text text</textarea>"
46 "<table><tbody></tbody></table>"
47 "<script id=\"sc\" type=\"text/javascript\"></script>"
49 static const char indent_test_str[] =
50 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
52 static const WCHAR noneW[] = {'N','o','n','e',0};
54 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
55 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
56 static WCHAR wordW[] = {'w','o','r','d',0};
58 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
80 static REFIID const none_iids[] = {
85 static REFIID const elem_iids[] = {
89 &IID_IConnectionPointContainer,
93 static REFIID const body_iids[] = {
97 &IID_IHTMLTextContainer,
98 &IID_IHTMLBodyElement,
99 &IID_IConnectionPointContainer,
103 static REFIID const anchor_iids[] = {
107 &IID_IHTMLAnchorElement,
108 &IID_IConnectionPointContainer,
112 static REFIID const input_iids[] = {
116 &IID_IHTMLInputElement,
117 &IID_IHTMLInputTextElement,
118 &IID_IConnectionPointContainer,
122 static REFIID const select_iids[] = {
126 &IID_IHTMLSelectElement,
127 &IID_IConnectionPointContainer,
131 static REFIID const textarea_iids[] = {
135 &IID_IHTMLTextAreaElement,
136 &IID_IConnectionPointContainer,
140 static REFIID const option_iids[] = {
144 &IID_IHTMLOptionElement,
145 &IID_IConnectionPointContainer,
149 static REFIID const table_iids[] = {
154 &IID_IConnectionPointContainer,
158 static REFIID const script_iids[] = {
162 &IID_IHTMLScriptElement,
163 &IID_IConnectionPointContainer,
167 static REFIID const location_iids[] = {
173 static REFIID const window_iids[] = {
185 static const elem_type_info_t elem_type_infos[] = {
189 {"TITLE", elem_iids},
192 {"INPUT", input_iids},
193 {"SELECT", select_iids},
194 {"TEXTAREA", textarea_iids},
195 {"OPTION", option_iids},
196 {"STYLE", elem_iids},
197 {"BLOCKQUOTE",elem_iids},
200 {"TABLE", table_iids},
201 {"TBODY", elem_iids},
202 {"SCRIPT", script_iids}
205 static const char *dbgstr_w(LPCWSTR str)
207 static char buf[512];
210 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
214 static const char *dbgstr_guid(REFIID riid)
218 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
219 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
220 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
221 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
226 static int strcmp_wa(LPCWSTR strw, const char *stra)
229 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
230 return lstrcmpW(strw, buf);
233 static BSTR a2bstr(const char *str)
238 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
239 ret = SysAllocStringLen(NULL, len);
240 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
245 static IHTMLDocument2 *create_document(void)
250 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
251 &IID_IHTMLDocument2, (void**)&doc);
252 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
257 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
258 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
260 const IID * const *piid;
264 for(piid = iids; *piid; piid++) {
265 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
266 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
268 IUnknown_Release(unk);
272 #define test_disp(u,id) _test_disp(__LINE__,u,id)
273 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
280 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
281 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
286 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
287 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
288 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
290 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
291 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
293 if(SUCCEEDED(hres)) {
296 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
297 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
298 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
300 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
301 ITypeInfo_Release(typeinfo);
304 IDispatchEx_Release(dispex);
307 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
308 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
314 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
315 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
317 hres = IHTMLDOMNode_get_nodeName(node, &name);
318 IHTMLDOMNode_Release(node);
319 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
320 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
325 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
326 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
332 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
333 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
335 hres = IHTMLElement_get_tagName(elem, &tag);
336 IHTMLElement_Release(elem);
337 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
338 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
343 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
344 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
346 _test_elem_tag(line, unk, elem_type_infos[type].tag);
347 _test_ifaces(line, unk, elem_type_infos[type].iids);
350 static void test_doc_elem(IHTMLDocument2 *doc)
353 IHTMLDocument3 *doc3;
356 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
357 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
359 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
360 IHTMLDocument3_Release(doc3);
361 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
363 test_node_name((IUnknown*)elem, "HTML");
364 test_elem_tag((IUnknown*)elem, "HTML");
366 IHTMLElement_Release(elem);
369 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
370 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
373 IHTMLDocument3 *doc3;
376 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
377 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
378 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
379 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
380 IHTMLDocument3_Release(doc3);
385 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
386 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
391 hres = IHTMLOptionElement_get_text(option, &bstr);
392 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
393 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
397 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
398 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
404 hres = IHTMLOptionElement_put_text(option, bstr);
406 ok(hres == S_OK, "put_text failed: %08x\n", hres);
408 _test_option_text(line, option, text);
411 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
412 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
417 hres = IHTMLOptionElement_get_value(option, &bstr);
418 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
419 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
423 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
424 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
429 bstr = a2bstr(value);
430 hres = IHTMLOptionElement_put_value(option, bstr);
432 ok(hres == S_OK, "put_value failed: %08x\n", hres);
434 _test_option_value(line, option, value);
437 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
438 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
439 const char *txt, const char *val)
441 IHTMLOptionElementFactory *factory;
442 IHTMLOptionElement *option;
443 IHTMLWindow2 *window;
444 VARIANT text, value, empty;
447 hres = IHTMLDocument2_get_parentWindow(doc, &window);
448 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
450 hres = IHTMLWindow2_get_Option(window, &factory);
451 IHTMLWindow2_Release(window);
452 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
454 V_VT(&text) = VT_BSTR;
455 V_BSTR(&text) = a2bstr(txt);
456 V_VT(&value) = VT_BSTR;
457 V_BSTR(&value) = a2bstr(val);
458 V_VT(&empty) = VT_EMPTY;
460 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
461 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
463 IHTMLOptionElementFactory_Release(factory);
465 VariantClear(&value);
467 _test_option_text(line, option, txt);
468 _test_option_value(line, option, val);
473 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
474 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
476 long len = 0xdeadbeef;
479 hres = IHTMLSelectElement_get_length(select, &len);
480 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
481 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
484 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
485 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
487 long idx = 0xdeadbeef;
490 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
491 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
492 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
495 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
496 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
500 hres = IHTMLSelectElement_put_selectedIndex(select, index);
501 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
502 _test_select_selidx(line, select, index);
505 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
506 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
511 hres = IHTMLTxtRange_get_text(range, &text);
512 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
515 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
516 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
518 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
525 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
526 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
530 hres = IHTMLTxtRange_collapse(range, b);
531 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
532 _test_range_text(line, range, NULL);
535 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
536 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
537 VARIANT_BOOL exb, const char *extext)
539 VARIANT_BOOL b = 0xe0e0;
542 hres = IHTMLTxtRange_expand(range, unit, &b);
543 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
544 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
545 _test_range_text(line, range, extext);
548 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
549 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
554 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
555 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
556 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
557 _test_range_text(line, range, NULL);
560 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
561 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
562 LPWSTR unit, long cnt, long excnt)
567 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
568 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
569 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
572 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
573 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
578 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
579 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
580 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
583 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
584 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
587 BSTR bstr = a2bstr(text);
589 hres = IHTMLTxtRange_put_text(range, bstr);
590 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
592 _test_range_text(line, range, NULL);
595 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
596 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
602 hres = IHTMLTxtRange_inRange(range1, range2, &b);
603 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
604 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
607 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
608 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
614 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
615 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
616 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
619 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
620 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
621 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
624 test_range_inrange(range1, range2, VARIANT_TRUE);
625 test_range_inrange(range2, range1, VARIANT_TRUE);
629 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
630 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
635 hres = IHTMLTxtRange_parentElement(range, &elem);
636 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
638 _test_elem_type(line, (IUnknown*)elem, type);
640 IHTMLElement_Release(elem);
643 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
644 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
645 const elem_type_t *elem_types, long exlen)
653 hres = IHTMLElementCollection_get_length(col, &len);
654 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
655 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
660 V_VT(&index) = VT_EMPTY;
663 for(i=0; i<len; i++) {
665 disp = (void*)0xdeadbeef;
666 hres = IHTMLElementCollection_item(col, name, index, &disp);
667 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
668 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
669 if(FAILED(hres) || !disp)
672 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
673 IDispatch_Release(disp);
677 disp = (void*)0xdeadbeef;
678 hres = IHTMLElementCollection_item(col, name, index, &disp);
679 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
680 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
683 disp = (void*)0xdeadbeef;
684 hres = IHTMLElementCollection_item(col, name, index, &disp);
685 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
686 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
689 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
690 const elem_type_t *elem_types, long len)
692 IHTMLElementCollection *elcol;
698 V_VT(&index) = VT_EMPTY;
699 V_VT(&name) = VT_BSTR;
700 V_BSTR(&name) = SysAllocString(n);
702 hres = IHTMLElementCollection_item(col, name, index, &disp);
703 ok(hres == S_OK, "item failed: %08x\n", hres);
705 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
706 IDispatch_Release(disp);
707 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
708 test_elem_collection(elcol, elem_types, len);
709 IHTMLElementCollection_Release(elcol);
711 V_VT(&index) = VT_I4;
713 for(i=0; i<len; i++) {
715 disp = (void*)0xdeadbeef;
716 hres = IHTMLElementCollection_item(col, name, index, &disp);
717 ok(hres == S_OK, "item failed: %08x\n", hres);
718 ok(disp != NULL, "disp == NULL\n");
719 if(FAILED(hres) || !disp)
722 test_elem_type((IUnknown*)disp, elem_types[i]);
724 IDispatch_Release(disp);
728 disp = (void*)0xdeadbeef;
729 hres = IHTMLElementCollection_item(col, name, index, &disp);
730 ok(hres == S_OK, "item failed: %08x\n", hres);
731 ok(disp == NULL, "disp != NULL\n");
734 disp = (void*)0xdeadbeef;
735 hres = IHTMLElementCollection_item(col, name, index, &disp);
736 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
737 ok(disp == NULL, "disp != NULL\n");
739 SysFreeString(V_BSTR(&name));
742 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
744 IHTMLElementCollection *col;
746 IDispatch *disp = (void*)0xdeadbeef;
750 hres = IHTMLDocument2_get_all(doc, &col);
751 ok(hres == S_OK, "get_all failed: %08x\n", hres);
752 ok(col != NULL, "col == NULL\n");
753 if(FAILED(hres) || !col)
756 V_VT(&index) = VT_EMPTY;
757 V_VT(&name) = VT_BSTR;
758 V_BSTR(&name) = SysAllocString(id);
760 hres = IHTMLElementCollection_item(col, name, index, &disp);
761 IHTMLElementCollection_Release(col);
762 SysFreeString(V_BSTR(&name));
763 ok(hres == S_OK, "item failed: %08x\n", hres);
764 if(!expect_success) {
765 ok(disp == NULL, "disp != NULL\n");
769 ok(disp != NULL, "disp == NULL\n");
773 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
774 IDispatch_Release(disp);
775 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
780 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
782 IHTMLDocument3 *doc3;
787 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
788 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
790 tmp = SysAllocString(id);
791 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
793 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
795 IHTMLDocument3_Release(doc3);
800 static void test_select_elem(IHTMLSelectElement *select)
802 test_select_length(select, 2);
803 test_select_selidx(select, 0);
804 test_select_put_selidx(select, 1);
807 static void test_create_option_elem(IHTMLDocument2 *doc)
809 IHTMLOptionElement *option;
811 option = create_option_elem(doc, "test text", "test value");
813 test_option_put_text(option, "new text");
814 test_option_put_value(option, "new value");
816 IHTMLOptionElement_Release(option);
819 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
821 IHTMLBodyElement *body;
822 IHTMLTxtRange *range;
826 hres = IHTMLDocument2_get_body(doc, &elem);
827 ok(hres == S_OK, "get_body failed: %08x\n", hres);
829 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
830 IHTMLElement_Release(elem);
832 hres = IHTMLBodyElement_createTextRange(body, &range);
833 IHTMLBodyElement_Release(body);
834 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
839 static void test_txtrange(IHTMLDocument2 *doc)
841 IHTMLTxtRange *body_range, *range, *range2;
842 IHTMLSelectionObject *selection;
843 IDispatch *disp_range;
846 body_range = test_create_body_range(doc);
848 test_range_text(body_range, "test abc 123\r\nit's text");
850 hres = IHTMLTxtRange_duplicate(body_range, &range);
851 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
853 hres = IHTMLTxtRange_duplicate(body_range, &range2);
854 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
855 test_range_isequal(range, range2, VARIANT_TRUE);
857 test_range_text(range, "test abc 123\r\nit's text");
858 test_range_text(body_range, "test abc 123\r\nit's text");
860 test_range_collapse(range, TRUE);
861 test_range_isequal(range, range2, VARIANT_FALSE);
862 test_range_inrange(range, range2, VARIANT_FALSE);
863 test_range_inrange(range2, range, VARIANT_TRUE);
864 IHTMLTxtRange_Release(range2);
866 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
867 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
868 test_range_move(range, characterW, 2, 2);
869 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
871 test_range_collapse(range, FALSE);
872 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
874 test_range_collapse(range, FALSE);
875 test_range_expand(range, wordW, VARIANT_TRUE, "123");
876 test_range_expand(range, wordW, VARIANT_FALSE, "123");
877 test_range_move(range, characterW, 2, 2);
878 test_range_expand(range, wordW, VARIANT_TRUE, "123");
879 test_range_moveend(range, characterW, -5, -5);
880 test_range_text(range, NULL);
881 test_range_moveend(range, characterW, 3, 3);
882 test_range_text(range, "c 1");
883 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
884 test_range_collapse(range, TRUE);
885 test_range_move(range, characterW, 4, 4);
886 test_range_moveend(range, characterW, 1, 1);
887 test_range_text(range, " ");
888 test_range_move(range, wordW, 1, 1);
889 test_range_moveend(range, characterW, 2, 2);
890 test_range_text(range, "ab");
892 IHTMLTxtRange_Release(range);
894 hres = IHTMLTxtRange_duplicate(body_range, &range);
895 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
897 test_range_text(range, "test abc 123\r\nit's text");
898 test_range_move(range, characterW, 3, 3);
899 test_range_moveend(range, characterW, 1, 1);
900 test_range_text(range, "t");
901 test_range_moveend(range, characterW, 3, 3);
902 test_range_text(range, "t ab");
903 test_range_moveend(range, characterW, -2, -2);
904 test_range_text(range, "t ");
905 test_range_move(range, characterW, 6, 6);
906 test_range_moveend(range, characterW, 3, 3);
907 test_range_text(range, "123");
908 test_range_moveend(range, characterW, 2, 2);
909 test_range_text(range, "123\r\ni");
911 IHTMLTxtRange_Release(range);
913 hres = IHTMLTxtRange_duplicate(body_range, &range);
914 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
916 test_range_move(range, wordW, 1, 1);
917 test_range_moveend(range, characterW, 2, 2);
918 test_range_text(range, "ab");
920 test_range_move(range, characterW, -2, -2);
921 test_range_moveend(range, characterW, 2, 2);
922 test_range_text(range, "t ");
924 test_range_move(range, wordW, 3, 3);
925 test_range_move(range, wordW, -2, -2);
926 test_range_moveend(range, characterW, 2, 2);
927 test_range_text(range, "ab");
929 test_range_move(range, characterW, -6, -5);
930 test_range_moveend(range, characterW, -1, 0);
931 test_range_moveend(range, characterW, -6, 0);
932 test_range_move(range, characterW, 2, 2);
933 test_range_moveend(range, characterW, 2, 2);
934 test_range_text(range, "st");
935 test_range_moveend(range, characterW, -6, -4);
936 test_range_moveend(range, characterW, 2, 2);
938 IHTMLTxtRange_Release(range);
940 hres = IHTMLTxtRange_duplicate(body_range, &range);
941 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
943 test_range_move(range, wordW, 2, 2);
944 test_range_moveend(range, characterW, 2, 2);
945 test_range_text(range, "12");
947 test_range_move(range, characterW, 15, 14);
948 test_range_move(range, characterW, -2, -2);
949 test_range_moveend(range, characterW, 3, 2);
950 test_range_text(range, "t");
951 test_range_moveend(range, characterW, -1, -1);
952 test_range_text(range, "t");
953 test_range_expand(range, wordW, VARIANT_TRUE, "text");
954 test_range_move(range, characterW, -2, -2);
955 test_range_moveend(range, characterW, 2, 2);
956 test_range_text(range, "s ");
957 test_range_move(range, characterW, 100, 7);
958 test_range_move(range, wordW, 1, 0);
959 test_range_move(range, characterW, -2, -2);
960 test_range_moveend(range, characterW, 3, 2);
961 test_range_text(range, "t");
963 IHTMLTxtRange_Release(range);
965 hres = IHTMLTxtRange_duplicate(body_range, &range);
966 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
968 test_range_collapse(range, TRUE);
969 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
970 test_range_put_text(range, "word");
971 test_range_text(body_range, "wordabc 123\r\nit's text");
972 test_range_text(range, NULL);
973 test_range_moveend(range, characterW, 3, 3);
974 test_range_text(range, "abc");
975 test_range_movestart(range, characterW, -2, -2);
976 test_range_text(range, "rdabc");
977 test_range_movestart(range, characterW, 3, 3);
978 test_range_text(range, "bc");
979 test_range_movestart(range, characterW, 4, 4);
980 test_range_text(range, NULL);
981 test_range_movestart(range, characterW, -3, -3);
982 test_range_text(range, "c 1");
983 test_range_movestart(range, characterW, -7, -6);
984 test_range_text(range, "wordabc 1");
985 test_range_movestart(range, characterW, 100, 22);
986 test_range_text(range, NULL);
988 IHTMLTxtRange_Release(range);
989 IHTMLTxtRange_Release(body_range);
991 hres = IHTMLDocument2_get_selection(doc, &selection);
992 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
994 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
995 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
996 IHTMLSelectionObject_Release(selection);
998 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
999 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1000 IDispatch_Release(disp_range);
1002 test_range_text(range, NULL);
1003 test_range_moveend(range, characterW, 3, 3);
1004 test_range_text(range, "wor");
1005 test_range_parent(range, ET_BODY);
1006 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1007 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1008 test_range_move(range, characterW, 3, 3);
1009 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1010 test_range_moveend(range, characterW, -4, -4);
1011 test_range_put_text(range, "abc def ");
1012 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1013 test_range_move(range, wordW, 1, 1);
1014 test_range_movestart(range, characterW, -1, -1);
1015 test_range_text(range, " ");
1016 test_range_move(range, wordW, 1, 1);
1017 test_range_moveend(range, characterW, 3, 3);
1018 test_range_text(range, "def");
1019 test_range_put_text(range, "xyz");
1020 test_range_moveend(range, characterW, 1, 1);
1021 test_range_move(range, wordW, 1, 1);
1022 test_range_moveend(range, characterW, 2, 2);
1023 test_range_text(range, "ab");
1025 IHTMLTxtRange_Release(range);
1028 static void test_txtrange2(IHTMLDocument2 *doc)
1030 IHTMLTxtRange *range;
1032 range = test_create_body_range(doc);
1034 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1035 test_range_move(range, characterW, 5, 5);
1036 test_range_moveend(range, characterW, 1, 1);
1037 test_range_text(range, "2");
1038 test_range_move(range, characterW, -3, -3);
1039 test_range_moveend(range, characterW, 3, 3);
1040 test_range_text(range, "c\r\n\r\n1");
1041 test_range_collapse(range, VARIANT_FALSE);
1042 test_range_moveend(range, characterW, 4, 4);
1043 test_range_text(range, "23");
1044 test_range_moveend(range, characterW, 1, 1);
1045 test_range_text(range, "23\r\n\r\n\r\nd");
1046 test_range_moveend(range, characterW, -1, -1);
1047 test_range_text(range, "23");
1048 test_range_moveend(range, characterW, -1, -1);
1049 test_range_text(range, "23");
1050 test_range_moveend(range, characterW, -2, -2);
1051 test_range_text(range, "2");
1053 IHTMLTxtRange_Release(range);
1056 static void test_compatmode(IHTMLDocument2 *doc)
1058 IHTMLDocument5 *doc5;
1062 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1063 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1067 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1068 IHTMLDocument5_Release(doc5);
1069 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1070 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1071 SysFreeString(mode);
1074 static void test_location(IHTMLDocument2 *doc)
1076 IHTMLLocation *location, *location2;
1080 hres = IHTMLDocument2_get_location(doc, &location);
1081 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1083 hres = IHTMLDocument2_get_location(doc, &location2);
1084 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1086 ok(location == location2, "location != location2\n");
1088 test_ifaces((IUnknown*)location, location_iids);
1090 IHTMLLocation_Release(location2);
1091 ref = IHTMLLocation_Release(location);
1092 ok(!ref, "location chould be destroyed here\n");
1095 static void test_navigator(IHTMLDocument2 *doc)
1097 IHTMLWindow2 *window;
1098 IOmNavigator *navigator, *navigator2;
1102 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1103 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1105 hres = IHTMLWindow2_get_navigator(window, &navigator);
1106 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1107 ok(navigator != NULL, "navigator == NULL\n");
1108 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1110 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1111 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1112 ok(navigator != navigator2, "navigator2 != navihgator\n");
1114 IHTMLWindow2_Release(window);
1115 IOmNavigator_Release(navigator2);
1116 ref = IOmNavigator_Release(navigator);
1117 ok(!ref, "navigator should be destroyed here\n");
1120 static void test_default_style(IHTMLStyle *style)
1127 str = (void*)0xdeadbeef;
1128 hres = IHTMLStyle_get_fontFamily(style, &str);
1129 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1130 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1132 str = (void*)0xdeadbeef;
1133 hres = IHTMLStyle_get_fontWeight(style, &str);
1134 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1135 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1137 str = (void*)0xdeadbeef;
1138 hres = IHTMLStyle_get_display(style, &str);
1139 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1140 ok(!str, "display = %s\n", dbgstr_w(str));
1142 str = (void*)0xdeadbeef;
1143 hres = IHTMLStyle_get_visibility(style, &str);
1144 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1145 ok(!str, "visibility = %s\n", dbgstr_w(str));
1148 hres = IHTMLStyle_get_fontSize(style, &v);
1149 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1150 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1151 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1154 hres = IHTMLStyle_get_color(style, &v);
1155 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1156 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1157 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1160 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1161 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1162 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1165 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1166 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1167 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1170 static void test_default_selection(IHTMLDocument2 *doc)
1172 IHTMLSelectionObject *selection;
1173 IHTMLTxtRange *range;
1178 hres = IHTMLDocument2_get_selection(doc, &selection);
1179 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1181 hres = IHTMLSelectionObject_get_type(selection, &str);
1182 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1183 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1186 hres = IHTMLSelectionObject_createRange(selection, &disp);
1187 IHTMLSelectionObject_Release(selection);
1188 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1190 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1191 IDispatch_Release(disp);
1192 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1194 test_range_text(range, NULL);
1195 IHTMLTxtRange_Release(range);
1198 static void test_default_body(IHTMLBodyElement *body)
1203 bstr = (void*)0xdeadbeef;
1204 hres = IHTMLBodyElement_get_background(body, &bstr);
1205 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1206 ok(bstr == NULL, "bstr != NULL\n");
1209 static void test_window(IHTMLDocument2 *doc)
1211 IHTMLWindow2 *window;
1212 IHTMLDocument2 *doc2 = NULL;
1215 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1216 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
1217 test_ifaces((IUnknown*)window, window_iids);
1218 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
1220 hres = IHTMLWindow2_get_document(window, &doc2);
1221 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1222 ok(doc2 != NULL, "doc2 == NULL\n");
1224 IHTMLDocument_Release(doc2);
1225 IHTMLWindow2_Release(window);
1228 static void test_defaults(IHTMLDocument2 *doc)
1230 IHTMLStyleSheetsCollection *stylesheetcol;
1231 IHTMLBodyElement *body;
1237 hres = IHTMLDocument2_get_body(doc, &elem);
1238 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1240 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1241 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1242 test_default_body(body);
1243 IHTMLBodyElement_Release(body);
1245 hres = IHTMLElement_get_style(elem, &style);
1246 IHTMLElement_Release(elem);
1247 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1249 test_default_style(style);
1251 test_compatmode(doc);
1253 test_navigator(doc);
1255 IHTMLStyle_Release(style);
1257 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1258 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1261 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1262 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1263 ok(l == 0, "length = %ld\n", l);
1265 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1267 test_default_selection(doc);
1270 static void test_stylesheet(IDispatch *disp)
1272 IHTMLStyleSheetRulesCollection *col = NULL;
1273 IHTMLStyleSheet *stylesheet;
1276 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1277 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1279 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1280 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1281 ok(col != NULL, "col == NULL\n");
1283 IHTMLStyleSheetRulesCollection_Release(col);
1284 IHTMLStyleSheet_Release(stylesheet);
1287 static void test_stylesheets(IHTMLDocument2 *doc)
1289 IHTMLStyleSheetsCollection *col = NULL;
1294 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1295 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1296 ok(col != NULL, "col == NULL\n");
1298 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1299 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1300 ok(len == 1, "len=%ld\n", len);
1306 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1307 ok(hres == S_OK, "item failed: %08x\n", hres);
1308 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1309 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1310 test_stylesheet(V_DISPATCH(&res));
1317 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1318 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1319 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1320 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1323 IHTMLStyleSheetsCollection_Release(col);
1326 static void test_elems(IHTMLDocument2 *doc)
1328 IHTMLElementCollection *col;
1333 static const WCHAR xW[] = {'x',0};
1334 static const WCHAR sW[] = {'s',0};
1335 static const WCHAR scW[] = {'s','c',0};
1336 static const WCHAR xxxW[] = {'x','x','x',0};
1338 static const elem_type_t all_types[] = {
1355 static const elem_type_t item_types[] = {
1361 hres = IHTMLDocument2_get_all(doc, &col);
1362 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1363 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1364 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1365 IHTMLElementCollection_Release(col);
1367 elem = get_doc_elem(doc);
1368 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1369 hres = IHTMLElement_get_all(elem, &disp);
1370 IHTMLElement_Release(elem);
1371 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1373 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1374 IDispatch_Release(disp);
1375 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1376 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1377 IHTMLElementCollection_Release(col);
1379 get_elem_by_id(doc, xxxW, FALSE);
1380 elem = get_doc_elem_by_id(doc, xxxW);
1381 ok(!elem, "elem != NULL\n");
1383 elem = get_doc_elem_by_id(doc, sW);
1384 ok(elem != NULL, "elem == NULL\n");
1385 test_elem_type((IUnknown*)elem, ET_SELECT);
1387 IHTMLElement_Release(elem);
1389 elem = get_elem_by_id(doc, sW, TRUE);
1391 IHTMLSelectElement *select;
1393 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1394 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1396 test_select_elem(select);
1398 IHTMLSelectElement_Release(select);
1399 IHTMLElement_Release(elem);
1402 elem = get_elem_by_id(doc, scW, TRUE);
1404 IHTMLScriptElement *script;
1407 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1408 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1410 hres = IHTMLScriptElement_get_type(script, &type);
1411 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1412 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1413 SysFreeString(type);
1416 test_stylesheets(doc);
1417 test_create_option_elem(doc);
1420 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1422 IOleCommandTarget *cmdtrg;
1425 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1426 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1428 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1429 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1431 IOleCommandTarget_Release(cmdtrg);
1434 static void test_indent(IHTMLDocument2 *doc)
1436 IHTMLElementCollection *col;
1437 IHTMLTxtRange *range;
1440 static const elem_type_t all_types[] = {
1449 static const elem_type_t indent_types[] = {
1460 hres = IHTMLDocument2_get_all(doc, &col);
1461 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1462 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1463 IHTMLElementCollection_Release(col);
1465 range = test_create_body_range(doc);
1466 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1467 IHTMLTxtRange_Release(range);
1469 hres = IHTMLDocument2_get_all(doc, &col);
1470 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1471 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1472 IHTMLElementCollection_Release(col);
1475 static IHTMLDocument2 *notif_doc;
1476 static BOOL doc_complete;
1478 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1479 REFIID riid, void**ppv)
1481 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1486 ok(0, "unexpected call\n");
1487 return E_NOINTERFACE;
1490 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1495 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1500 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1502 if(dispID == DISPID_READYSTATE){
1506 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1508 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1509 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1511 if(!lstrcmpW(state, completeW))
1512 doc_complete = TRUE;
1514 SysFreeString(state);
1520 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1522 ok(0, "unexpected call\n");
1526 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1527 PropertyNotifySink_QueryInterface,
1528 PropertyNotifySink_AddRef,
1529 PropertyNotifySink_Release,
1530 PropertyNotifySink_OnChanged,
1531 PropertyNotifySink_OnRequestEdit
1534 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1536 static IHTMLDocument2 *create_doc_with_string(const char *str)
1538 IPersistStreamInit *init;
1540 IHTMLDocument2 *doc;
1544 notif_doc = doc = create_document();
1548 doc_complete = FALSE;
1550 mem = GlobalAlloc(0, len);
1551 memcpy(mem, str, len);
1552 CreateStreamOnHGlobal(mem, TRUE, &stream);
1554 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1556 IPersistStreamInit_Load(init, stream);
1557 IPersistStreamInit_Release(init);
1558 IStream_Release(stream);
1563 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1565 IConnectionPointContainer *container;
1566 IConnectionPoint *cp;
1570 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1571 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1573 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1574 IConnectionPointContainer_Release(container);
1575 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1577 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1578 IConnectionPoint_Release(cp);
1579 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1582 typedef void (*domtest_t)(IHTMLDocument2*);
1584 static void run_domtest(const char *str, domtest_t test)
1586 IHTMLDocument2 *doc;
1587 IHTMLElement *body = NULL;
1592 doc = create_doc_with_string(str);
1593 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1595 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1596 TranslateMessage(&msg);
1597 DispatchMessage(&msg);
1600 hres = IHTMLDocument2_get_body(doc, &body);
1601 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1604 IHTMLElement_Release(body);
1607 skip("Could not get document body. Assuming no Gecko installed.\n");
1610 ref = IHTMLDocument2_Release(doc);
1611 ok(!ref, "ref = %d\n", ref);
1614 static void gecko_installer_workaround(BOOL disable)
1619 static BOOL has_url = FALSE;
1620 static char url[2048];
1622 if(!disable && !has_url)
1625 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1626 if(res != ERROR_SUCCESS)
1630 DWORD type, size = sizeof(url);
1632 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1633 if(res == ERROR_SUCCESS && type == REG_SZ)
1636 RegDeleteValue(hkey, "GeckoUrl");
1638 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1646 gecko_installer_workaround(TRUE);
1649 run_domtest(doc_str1, test_doc_elem);
1650 run_domtest(range_test_str, test_txtrange);
1651 run_domtest(range_test2_str, test_txtrange2);
1652 run_domtest(elem_test_str, test_elems);
1653 run_domtest(doc_blank, test_defaults);
1654 run_domtest(indent_test_str, test_indent);
1657 gecko_installer_workaround(FALSE);