2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
35 static const char doc_blank[] = "<html></html>";
36 static const char doc_str1[] = "<html><body>test</body></html>";
37 static const char range_test_str[] =
38 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
39 static const char range_test2_str[] =
40 "<html><body>abc<hr />123<br /><hr />def</body></html>";
41 static const char elem_test_str[] =
42 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
43 "<body>text test<!-- a comment -->"
44 "<a href=\"http://test\" name=\"x\">link</a>"
45 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
46 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"></tr></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
53 static const char indent_test_str[] =
54 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
56 static const WCHAR noneW[] = {'N','o','n','e',0};
58 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
59 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
60 static WCHAR wordW[] = {'w','o','r','d',0};
62 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
64 static const WCHAR idW[] = {'i','d',0};
91 static const IID * const none_iids[] = {
96 static const IID * const elem_iids[] = {
102 &IID_IConnectionPointContainer,
106 static const IID * const body_iids[] = {
111 &IID_IHTMLTextContainer,
112 &IID_IHTMLBodyElement,
114 &IID_IConnectionPointContainer,
118 static const IID * const anchor_iids[] = {
123 &IID_IHTMLAnchorElement,
125 &IID_IConnectionPointContainer,
129 static const IID * const input_iids[] = {
134 &IID_IHTMLInputElement,
135 &IID_IHTMLInputTextElement,
137 &IID_IConnectionPointContainer,
141 static const IID * const select_iids[] = {
146 &IID_IHTMLSelectElement,
148 &IID_IConnectionPointContainer,
152 static const IID * const textarea_iids[] = {
157 &IID_IHTMLTextAreaElement,
159 &IID_IConnectionPointContainer,
163 static const IID * const option_iids[] = {
168 &IID_IHTMLOptionElement,
170 &IID_IConnectionPointContainer,
174 static const IID * const table_iids[] = {
181 &IID_IConnectionPointContainer,
185 static const IID * const script_iids[] = {
190 &IID_IHTMLScriptElement,
192 &IID_IConnectionPointContainer,
196 static const IID * const text_iids[] = {
199 &IID_IHTMLDOMTextNode,
203 static const IID * const location_iids[] = {
209 static const IID * const window_iids[] = {
217 static const IID * const comment_iids[] = {
222 &IID_IHTMLCommentElement,
224 &IID_IConnectionPointContainer,
228 static const IID * const img_iids[] = {
234 &IID_IHTMLImgElement,
235 &IID_IConnectionPointContainer,
239 static const IID * const tr_iids[] = {
246 &IID_IConnectionPointContainer,
250 static const IID * const generic_iids[] = {
255 &IID_IHTMLGenericElement,
257 &IID_IConnectionPointContainer,
267 static const elem_type_info_t elem_type_infos[] = {
268 {"", none_iids, NULL},
269 {"HTML", elem_iids, NULL},
270 {"HEAD", elem_iids, NULL},
271 {"TITLE", elem_iids, NULL},
272 {"BODY", body_iids, &DIID_DispHTMLBody},
273 {"A", anchor_iids, NULL},
274 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
275 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
276 {"TEXTAREA", textarea_iids, NULL},
277 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
278 {"STYLE", elem_iids, NULL},
279 {"BLOCKQUOTE",elem_iids, NULL},
280 {"P", elem_iids, NULL},
281 {"BR", elem_iids, NULL},
282 {"TABLE", table_iids, &DIID_DispHTMLTable},
283 {"TBODY", elem_iids, NULL},
284 {"SCRIPT", script_iids, NULL},
285 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
286 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
287 {"!", comment_iids, &DIID_DispHTMLCommentElement},
288 {"IMG", img_iids, &DIID_DispHTMLImg},
289 {"TR", tr_iids, &DIID_DispHTMLTableRow}
292 static const char *dbgstr_w(LPCWSTR str)
294 static char buf[512];
297 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
301 static const char *dbgstr_guid(REFIID riid)
305 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
306 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
307 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
308 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
313 static int strcmp_wa(LPCWSTR strw, const char *stra)
316 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
317 return lstrcmpW(strw, buf);
320 static BSTR a2bstr(const char *str)
325 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
326 ret = SysAllocStringLen(NULL, len);
327 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
332 static IHTMLDocument2 *create_document(void)
337 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
338 &IID_IHTMLDocument2, (void**)&doc);
339 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
344 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
345 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
347 const IID * const *piid;
351 for(piid = iids; *piid; piid++) {
352 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
353 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
355 IUnknown_Release(unk);
359 #define test_disp(u,id) _test_disp(__LINE__,u,id)
360 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
367 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
368 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
373 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
374 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
375 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
377 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
378 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
380 if(SUCCEEDED(hres)) {
383 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
384 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
385 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
387 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
388 ITypeInfo_Release(typeinfo);
391 IDispatchEx_Release(dispex);
394 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
395 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
400 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
401 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
405 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
406 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
411 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
412 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
416 #define get_node_iface(u) _get_node_iface(__LINE__,u)
417 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
422 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
423 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
427 #define get_img_iface(u) _get_img_iface(__LINE__,u)
428 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
430 IHTMLImgElement *img;
433 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
434 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
438 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
439 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
441 IHTMLDOMNode *node = _get_node_iface(line, unk);
445 hres = IHTMLDOMNode_get_nodeName(node, &name);
446 IHTMLDOMNode_Release(node);
447 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
448 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
453 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
454 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
456 IHTMLElement *elem = _get_elem_iface(line, unk);
460 hres = IHTMLElement_get_tagName(elem, &tag);
461 IHTMLElement_Release(elem);
462 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
463 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
468 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
469 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
471 _test_elem_tag(line, unk, elem_type_infos[type].tag);
472 _test_ifaces(line, unk, elem_type_infos[type].iids);
474 if(elem_type_infos[type].dispiid)
475 _test_disp(line, unk, elem_type_infos[type].dispiid);
478 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
479 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
487 tmp = SysAllocString(name);
488 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
490 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
493 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
494 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
496 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
499 VariantClear(&value);
502 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
503 static void _test_elem_offset(unsigned line, IUnknown *unk)
505 IHTMLElement *elem = _get_elem_iface(line, unk);
509 hres = IHTMLElement_get_offsetTop(elem, &l);
510 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
512 hres = IHTMLElement_get_offsetHeight(elem, &l);
513 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
515 IHTMLElement_Release(elem);
518 static void test_doc_elem(IHTMLDocument2 *doc)
521 IHTMLDocument3 *doc3;
524 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
525 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
527 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
528 IHTMLDocument3_Release(doc3);
529 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
531 test_node_name((IUnknown*)elem, "HTML");
532 test_elem_tag((IUnknown*)elem, "HTML");
534 IHTMLElement_Release(elem);
537 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
538 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
541 IHTMLDocument3 *doc3;
544 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
545 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
546 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
547 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
548 IHTMLDocument3_Release(doc3);
553 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
554 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
559 hres = IHTMLOptionElement_get_text(option, &bstr);
560 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
561 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
565 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
566 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
572 hres = IHTMLOptionElement_put_text(option, bstr);
574 ok(hres == S_OK, "put_text failed: %08x\n", hres);
576 _test_option_text(line, option, text);
579 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
580 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
585 hres = IHTMLOptionElement_get_value(option, &bstr);
586 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
587 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
591 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
592 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
597 bstr = a2bstr(value);
598 hres = IHTMLOptionElement_put_value(option, bstr);
600 ok(hres == S_OK, "put_value failed: %08x\n", hres);
602 _test_option_value(line, option, value);
605 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
606 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
607 const char *txt, const char *val)
609 IHTMLOptionElementFactory *factory;
610 IHTMLOptionElement *option;
611 IHTMLWindow2 *window;
612 VARIANT text, value, empty;
615 hres = IHTMLDocument2_get_parentWindow(doc, &window);
616 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
618 hres = IHTMLWindow2_get_Option(window, &factory);
619 IHTMLWindow2_Release(window);
620 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
622 V_VT(&text) = VT_BSTR;
623 V_BSTR(&text) = a2bstr(txt);
624 V_VT(&value) = VT_BSTR;
625 V_BSTR(&value) = a2bstr(val);
626 V_VT(&empty) = VT_EMPTY;
628 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
629 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
631 IHTMLOptionElementFactory_Release(factory);
633 VariantClear(&value);
635 _test_option_text(line, option, txt);
636 _test_option_value(line, option, val);
641 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
642 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
644 long len = 0xdeadbeef;
647 hres = IHTMLSelectElement_get_length(select, &len);
648 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
649 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
652 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
653 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
655 long idx = 0xdeadbeef;
658 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
659 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
660 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
663 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
664 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
668 hres = IHTMLSelectElement_put_selectedIndex(select, index);
669 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
670 _test_select_selidx(line, select, index);
673 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
674 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
679 hres = IHTMLSelectElement_get_value(select, &val);
680 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
682 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
684 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
687 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
688 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
694 hres = IHTMLSelectElement_put_value(select, bstr);
696 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
699 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
700 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
705 hres = IHTMLSelectElement_get_type(select, &type);
706 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
707 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
710 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
711 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
716 hres = IHTMLTxtRange_get_text(range, &text);
717 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
720 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
721 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
723 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
730 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
731 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
735 hres = IHTMLTxtRange_collapse(range, b);
736 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
737 _test_range_text(line, range, NULL);
740 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
741 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
742 VARIANT_BOOL exb, const char *extext)
744 VARIANT_BOOL b = 0xe0e0;
747 hres = IHTMLTxtRange_expand(range, unit, &b);
748 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
749 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
750 _test_range_text(line, range, extext);
753 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
754 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
759 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
760 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
761 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
762 _test_range_text(line, range, NULL);
765 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
766 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
767 LPWSTR unit, long cnt, long excnt)
772 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
773 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
774 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
777 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
778 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
783 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
784 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
785 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
788 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
789 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
792 BSTR bstr = a2bstr(text);
794 hres = IHTMLTxtRange_put_text(range, bstr);
795 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
797 _test_range_text(line, range, NULL);
800 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
801 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
807 hres = IHTMLTxtRange_inRange(range1, range2, &b);
808 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
809 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
812 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
813 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
819 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
820 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
821 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
824 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
825 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
826 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
829 test_range_inrange(range1, range2, VARIANT_TRUE);
830 test_range_inrange(range2, range1, VARIANT_TRUE);
834 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
835 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
840 hres = IHTMLTxtRange_parentElement(range, &elem);
841 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
843 _test_elem_type(line, (IUnknown*)elem, type);
845 IHTMLElement_Release(elem);
848 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
849 static void _test_elem_collection(unsigned line, IUnknown *unk,
850 const elem_type_t *elem_types, long exlen)
852 IHTMLElementCollection *col;
859 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
860 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
862 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
864 hres = IHTMLElementCollection_get_length(col, &len);
865 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
866 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
871 V_VT(&index) = VT_EMPTY;
874 for(i=0; i<len; i++) {
876 disp = (void*)0xdeadbeef;
877 hres = IHTMLElementCollection_item(col, name, index, &disp);
878 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
879 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
880 if(FAILED(hres) || !disp)
883 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
884 IDispatch_Release(disp);
888 disp = (void*)0xdeadbeef;
889 hres = IHTMLElementCollection_item(col, name, index, &disp);
890 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
891 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
894 disp = (void*)0xdeadbeef;
895 hres = IHTMLElementCollection_item(col, name, index, &disp);
896 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
897 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
899 IHTMLElementCollection_Release(col);
902 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
903 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
905 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
906 IHTMLElementCollection *col = NULL;
907 elem_type_t *types = NULL;
912 tmp = a2bstr(elem_type_infos[type].tag);
913 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
915 IHTMLElement2_Release(elem);
916 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
917 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
920 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
921 for(i=0; i<exlen; i++)
925 _test_elem_collection(line, (IUnknown*)col, types, exlen);
927 HeapFree(GetProcessHeap(), 0, types);
930 #define get_first_child(n) _get_first_child(__LINE__,n)
931 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
933 IHTMLDOMNode *node = _get_node_iface(line, unk);
934 IHTMLDOMNode *child = NULL;
937 hres = IHTMLDOMNode_get_firstChild(node, &child);
938 IHTMLDOMNode_Release(node);
939 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
944 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
945 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
947 IHTMLDOMNode *node = _get_node_iface(line, unk);
948 VARIANT_BOOL b = 0xdead;
951 hres = IHTMLDOMNode_hasChildNodes(node, &b);
952 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
953 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
955 IHTMLDOMNode_Release(node);
958 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
959 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
961 IHTMLDOMNode *node = _get_node_iface(line, unk);
962 IHTMLDOMNode *parent;
965 hres = IHTMLDOMNode_get_parentNode(node, &parent);
966 IHTMLDOMNode_Release(node);
967 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
972 #define get_node_type(n) _get_node_type(__LINE__,n)
973 static long _get_node_type(unsigned line, IUnknown *unk)
975 IHTMLDOMNode *node = _get_node_iface(line, unk);
979 hres = IHTMLDOMNode_get_nodeType(node, &type);
980 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
982 IHTMLDOMNode_Release(node);
987 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
988 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
990 IHTMLElement *elem = _get_elem_iface(line, unk);
991 IHTMLElement *parent;
994 hres = IHTMLElement_get_parentElement(elem, &parent);
995 IHTMLElement_Release(elem);
996 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1001 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1002 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1004 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1005 IHTMLTextContainer *txtcont;
1006 long l = -1, l2 = -1;
1009 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1010 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1011 IHTMLElement2_Release(elem);
1013 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1014 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1016 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1017 IHTMLTextContainer_Release(txtcont);
1018 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1019 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1024 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1025 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1027 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1028 IHTMLTextContainer *txtcont;
1029 long l = -1, l2 = -1;
1032 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1033 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1034 IHTMLElement2_Release(elem);
1036 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1037 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1039 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1040 IHTMLTextContainer_Release(txtcont);
1041 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1042 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1047 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1048 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1050 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1051 IHTMLTextContainer *txtcont;
1052 long l = -1, l2 = -1;
1055 hres = IHTMLElement2_get_scrollTop(elem, &l);
1056 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1057 IHTMLElement2_Release(elem);
1059 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1060 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1062 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1063 IHTMLTextContainer_Release(txtcont);
1064 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1065 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1070 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1071 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1073 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1074 IHTMLTextContainer *txtcont;
1075 long l = -1, l2 = -1;
1078 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1079 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1081 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1082 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1083 IHTMLElement2_Release(elem);
1085 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1086 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1088 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1089 IHTMLTextContainer_Release(txtcont);
1090 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1091 ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1094 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1095 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1097 IHTMLImgElement *img = _get_img_iface(line, unk);
1102 hres = IHTMLImgElement_put_src(img, tmp);
1103 IHTMLImgElement_Release(img);
1105 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1108 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1109 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1111 IHTMLImgElement *img = _get_img_iface(line, unk);
1115 hres = IHTMLImgElement_get_alt(img, &alt);
1116 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1118 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1120 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1124 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1125 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1127 IHTMLImgElement *img = _get_img_iface(line, unk);
1132 hres = IHTMLImgElement_put_alt(img, tmp);
1133 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1136 _test_img_alt(line, unk, alt);
1139 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1140 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1142 VARIANT_BOOL disabled = 100;
1145 hres = IHTMLInputElement_get_disabled(input, &disabled);
1146 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1147 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1150 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1151 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1155 hres = IHTMLInputElement_put_disabled(input, b);
1156 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1158 _test_input_get_disabled(line, input, b);
1161 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1162 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1164 IHTMLInputElement *input;
1168 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1169 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1173 hres = IHTMLInputElement_get_value(input, &bstr);
1174 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1176 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1178 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1179 SysFreeString(bstr);
1180 IHTMLInputElement_Release(input);
1183 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1184 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1186 IHTMLInputElement *input;
1190 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1191 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1196 hres = IHTMLInputElement_get_value(input, &bstr);
1197 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1198 SysFreeString(bstr);
1199 IHTMLInputElement_Release(input);
1202 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1203 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1205 IHTMLDOMNode *node = _get_node_iface(line, unk);
1206 IHTMLDOMChildrenCollection *col = NULL;
1210 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1211 IHTMLDOMNode_Release(node);
1212 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1216 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1217 IDispatch_Release(disp);
1218 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1223 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1224 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1226 IHTMLElement *elem = _get_elem_iface(line, unk);
1227 BSTR class = (void*)0xdeadbeef;
1230 hres = IHTMLElement_get_className(elem, &class);
1231 IHTMLElement_Release(elem);
1232 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1234 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1236 ok_(__FILE__,line) (!class, "class != NULL\n");
1237 SysFreeString(class);
1240 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1241 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1243 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1247 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1248 IHTMLElement2_Release(elem2);
1249 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1250 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1253 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1254 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1256 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1259 hres = IHTMLElement2_put_tabIndex(elem2, index);
1260 IHTMLElement2_Release(elem2);
1261 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1263 _test_elem_tabindex(line, unk, index);
1266 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1267 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1269 IHTMLElement *elem = _get_elem_iface(line, unk);
1273 tmp = class ? a2bstr(class) : NULL;
1274 hres = IHTMLElement_put_className(elem, tmp);
1275 IHTMLElement_Release(elem);
1276 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1279 _test_elem_class(line, unk, class);
1282 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1283 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
1285 IHTMLDOMNode *node = NULL;
1289 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1290 ok(hres == S_OK, "item failed: %08x\n", hres);
1292 node = _get_node_iface(line, (IUnknown*)disp);
1293 IDispatch_Release(disp);
1298 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1299 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1301 IHTMLElement *elem = _get_elem_iface(line, unk);
1302 BSTR id = (void*)0xdeadbeef;
1305 hres = IHTMLElement_get_id(elem, &id);
1306 IHTMLElement_Release(elem);
1307 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1310 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1312 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1317 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1318 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1320 IHTMLElement *elem = _get_elem_iface(line, unk);
1321 BSTR tmp = a2bstr(new_id);
1324 hres = IHTMLElement_put_id(elem, tmp);
1325 IHTMLElement_Release(elem);
1327 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1329 _test_elem_id(line, unk, new_id);
1332 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1333 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1335 IHTMLElement *elem = _get_elem_iface(line, unk);
1339 hres = IHTMLElement_get_title(elem, &title);
1340 IHTMLElement_Release(elem);
1341 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1343 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1345 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1347 SysFreeString(title);
1350 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1351 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1353 IHTMLElement *elem = _get_elem_iface(line, unk);
1357 tmp = a2bstr(title);
1358 hres = IHTMLElement_put_title(elem, tmp);
1359 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1361 IHTMLElement_Release(elem);
1365 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1366 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1368 IHTMLDOMNode *node = _get_node_iface(line, unk);
1372 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1373 IHTMLDOMNode_Release(node);
1374 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1377 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1378 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1380 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1386 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1387 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1389 IHTMLDOMNode *node = _get_node_iface(line, unk);
1393 V_VT(&var) = VT_BSTR;
1394 V_BSTR(&var) = a2bstr(val);
1396 hres = IHTMLDOMNode_put_nodeValue(node, var);
1397 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1398 IHTMLDOMNode_Release(node);
1402 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1403 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1405 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1409 hres = IHTMLElement2_get_clientWidth(elem, &l);
1410 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1411 hres = IHTMLElement2_get_clientHeight(elem, &l);
1412 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1414 IHTMLElement2_Release(elem);
1417 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1418 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1420 IHTMLElement *elem = NULL;
1425 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1426 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1427 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1432 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1433 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1435 IHTMLDocument3 *doc3;
1436 IHTMLDOMNode *node = NULL;
1440 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1441 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1444 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1445 IHTMLDocument3_Release(doc3);
1446 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1447 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1452 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1453 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1455 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1456 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1457 IHTMLDOMNode *new_child = NULL;
1460 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1461 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1462 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1463 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1465 IHTMLDOMNode_Release(node);
1466 IHTMLDOMNode_Release(child);
1471 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1472 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1474 IHTMLDOMNode *node = _get_node_iface(line, unk);
1475 IHTMLDOMNode *new_node = NULL;
1478 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1479 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1480 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1481 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1483 IHTMLDOMNode_Release(node);
1484 IHTMLDOMNode_Release(new_node);
1487 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1488 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1493 hres = IHTMLDocument2_get_title(doc, &title);
1494 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1495 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1496 SysFreeString(title);
1499 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1500 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1505 tmp = a2bstr(title);
1506 hres = IHTMLDocument2_put_title(doc, tmp);
1507 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1511 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1512 const elem_type_t *elem_types, long len)
1515 VARIANT name, index;
1519 V_VT(&index) = VT_EMPTY;
1520 V_VT(&name) = VT_BSTR;
1521 V_BSTR(&name) = SysAllocString(n);
1523 hres = IHTMLElementCollection_item(col, name, index, &disp);
1524 ok(hres == S_OK, "item failed: %08x\n", hres);
1526 test_elem_collection((IUnknown*)disp, elem_types, len);
1527 IDispatch_Release(disp);
1528 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1532 V_VT(&index) = VT_I4;
1534 for(i=0; i<len; i++) {
1536 disp = (void*)0xdeadbeef;
1537 hres = IHTMLElementCollection_item(col, name, index, &disp);
1538 ok(hres == S_OK, "item failed: %08x\n", hres);
1539 ok(disp != NULL, "disp == NULL\n");
1540 if(FAILED(hres) || !disp)
1543 test_elem_type((IUnknown*)disp, elem_types[i]);
1545 IDispatch_Release(disp);
1549 disp = (void*)0xdeadbeef;
1550 hres = IHTMLElementCollection_item(col, name, index, &disp);
1551 ok(hres == S_OK, "item failed: %08x\n", hres);
1552 ok(disp == NULL, "disp != NULL\n");
1555 disp = (void*)0xdeadbeef;
1556 hres = IHTMLElementCollection_item(col, name, index, &disp);
1557 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1558 ok(disp == NULL, "disp != NULL\n");
1561 SysFreeString(V_BSTR(&name));
1564 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1566 IHTMLElementCollection *col;
1568 IDispatch *disp = (void*)0xdeadbeef;
1569 VARIANT name, index;
1572 hres = IHTMLDocument2_get_all(doc, &col);
1573 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1574 ok(col != NULL, "col == NULL\n");
1575 if(FAILED(hres) || !col)
1578 V_VT(&index) = VT_EMPTY;
1579 V_VT(&name) = VT_BSTR;
1580 V_BSTR(&name) = SysAllocString(id);
1582 hres = IHTMLElementCollection_item(col, name, index, &disp);
1583 IHTMLElementCollection_Release(col);
1584 SysFreeString(V_BSTR(&name));
1585 ok(hres == S_OK, "item failed: %08x\n", hres);
1586 if(!expect_success) {
1587 ok(disp == NULL, "disp != NULL\n");
1591 ok(disp != NULL, "disp == NULL\n");
1595 elem = get_elem_iface((IUnknown*)disp);
1596 IDispatch_Release(disp);
1601 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1603 IHTMLDocument3 *doc3;
1608 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1609 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1611 tmp = SysAllocString(id);
1612 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1614 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1616 IHTMLDocument3_Release(doc3);
1621 static void test_select_elem(IHTMLSelectElement *select)
1623 test_select_type(select, "select-one");
1624 test_select_length(select, 2);
1625 test_select_selidx(select, 0);
1626 test_select_put_selidx(select, 1);
1628 test_select_set_value(select, "val1");
1629 test_select_value(select, "val1");
1632 static void test_create_option_elem(IHTMLDocument2 *doc)
1634 IHTMLOptionElement *option;
1636 option = create_option_elem(doc, "test text", "test value");
1638 test_option_put_text(option, "new text");
1639 test_option_put_value(option, "new value");
1641 IHTMLOptionElement_Release(option);
1644 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1646 IHTMLBodyElement *body;
1647 IHTMLTxtRange *range;
1651 hres = IHTMLDocument2_get_body(doc, &elem);
1652 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1654 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1655 IHTMLElement_Release(elem);
1657 hres = IHTMLBodyElement_createTextRange(body, &range);
1658 IHTMLBodyElement_Release(body);
1659 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1664 static void test_txtrange(IHTMLDocument2 *doc)
1666 IHTMLTxtRange *body_range, *range, *range2;
1667 IHTMLSelectionObject *selection;
1668 IDispatch *disp_range;
1671 body_range = test_create_body_range(doc);
1673 test_range_text(body_range, "test abc 123\r\nit's text");
1675 hres = IHTMLTxtRange_duplicate(body_range, &range);
1676 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1678 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1679 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1680 test_range_isequal(range, range2, VARIANT_TRUE);
1682 test_range_text(range, "test abc 123\r\nit's text");
1683 test_range_text(body_range, "test abc 123\r\nit's text");
1685 test_range_collapse(range, TRUE);
1686 test_range_isequal(range, range2, VARIANT_FALSE);
1687 test_range_inrange(range, range2, VARIANT_FALSE);
1688 test_range_inrange(range2, range, VARIANT_TRUE);
1689 IHTMLTxtRange_Release(range2);
1691 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1692 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1693 test_range_move(range, characterW, 2, 2);
1694 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1696 test_range_collapse(range, FALSE);
1697 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1699 test_range_collapse(range, FALSE);
1700 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1701 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1702 test_range_move(range, characterW, 2, 2);
1703 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1704 test_range_moveend(range, characterW, -5, -5);
1705 test_range_text(range, NULL);
1706 test_range_moveend(range, characterW, 3, 3);
1707 test_range_text(range, "c 1");
1708 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1709 test_range_collapse(range, TRUE);
1710 test_range_move(range, characterW, 4, 4);
1711 test_range_moveend(range, characterW, 1, 1);
1712 test_range_text(range, " ");
1713 test_range_move(range, wordW, 1, 1);
1714 test_range_moveend(range, characterW, 2, 2);
1715 test_range_text(range, "ab");
1717 IHTMLTxtRange_Release(range);
1719 hres = IHTMLTxtRange_duplicate(body_range, &range);
1720 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1722 test_range_text(range, "test abc 123\r\nit's text");
1723 test_range_move(range, characterW, 3, 3);
1724 test_range_moveend(range, characterW, 1, 1);
1725 test_range_text(range, "t");
1726 test_range_moveend(range, characterW, 3, 3);
1727 test_range_text(range, "t ab");
1728 test_range_moveend(range, characterW, -2, -2);
1729 test_range_text(range, "t ");
1730 test_range_move(range, characterW, 6, 6);
1731 test_range_moveend(range, characterW, 3, 3);
1732 test_range_text(range, "123");
1733 test_range_moveend(range, characterW, 2, 2);
1734 test_range_text(range, "123\r\ni");
1736 IHTMLTxtRange_Release(range);
1738 hres = IHTMLTxtRange_duplicate(body_range, &range);
1739 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1741 test_range_move(range, wordW, 1, 1);
1742 test_range_moveend(range, characterW, 2, 2);
1743 test_range_text(range, "ab");
1745 test_range_move(range, characterW, -2, -2);
1746 test_range_moveend(range, characterW, 2, 2);
1747 test_range_text(range, "t ");
1749 test_range_move(range, wordW, 3, 3);
1750 test_range_move(range, wordW, -2, -2);
1751 test_range_moveend(range, characterW, 2, 2);
1752 test_range_text(range, "ab");
1754 test_range_move(range, characterW, -6, -5);
1755 test_range_moveend(range, characterW, -1, 0);
1756 test_range_moveend(range, characterW, -6, 0);
1757 test_range_move(range, characterW, 2, 2);
1758 test_range_moveend(range, characterW, 2, 2);
1759 test_range_text(range, "st");
1760 test_range_moveend(range, characterW, -6, -4);
1761 test_range_moveend(range, characterW, 2, 2);
1763 IHTMLTxtRange_Release(range);
1765 hres = IHTMLTxtRange_duplicate(body_range, &range);
1766 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1768 test_range_move(range, wordW, 2, 2);
1769 test_range_moveend(range, characterW, 2, 2);
1770 test_range_text(range, "12");
1772 test_range_move(range, characterW, 15, 14);
1773 test_range_move(range, characterW, -2, -2);
1774 test_range_moveend(range, characterW, 3, 2);
1775 test_range_text(range, "t");
1776 test_range_moveend(range, characterW, -1, -1);
1777 test_range_text(range, "t");
1778 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1779 test_range_move(range, characterW, -2, -2);
1780 test_range_moveend(range, characterW, 2, 2);
1781 test_range_text(range, "s ");
1782 test_range_move(range, characterW, 100, 7);
1783 test_range_move(range, wordW, 1, 0);
1784 test_range_move(range, characterW, -2, -2);
1785 test_range_moveend(range, characterW, 3, 2);
1786 test_range_text(range, "t");
1788 IHTMLTxtRange_Release(range);
1790 hres = IHTMLTxtRange_duplicate(body_range, &range);
1791 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1793 test_range_collapse(range, TRUE);
1794 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1795 test_range_put_text(range, "word");
1796 test_range_text(body_range, "wordabc 123\r\nit's text");
1797 test_range_text(range, NULL);
1798 test_range_moveend(range, characterW, 3, 3);
1799 test_range_text(range, "abc");
1800 test_range_movestart(range, characterW, -2, -2);
1801 test_range_text(range, "rdabc");
1802 test_range_movestart(range, characterW, 3, 3);
1803 test_range_text(range, "bc");
1804 test_range_movestart(range, characterW, 4, 4);
1805 test_range_text(range, NULL);
1806 test_range_movestart(range, characterW, -3, -3);
1807 test_range_text(range, "c 1");
1808 test_range_movestart(range, characterW, -7, -6);
1809 test_range_text(range, "wordabc 1");
1810 test_range_movestart(range, characterW, 100, 22);
1811 test_range_text(range, NULL);
1813 IHTMLTxtRange_Release(range);
1814 IHTMLTxtRange_Release(body_range);
1816 hres = IHTMLDocument2_get_selection(doc, &selection);
1817 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1819 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1820 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1821 IHTMLSelectionObject_Release(selection);
1823 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1824 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1825 IDispatch_Release(disp_range);
1827 test_range_text(range, NULL);
1828 test_range_moveend(range, characterW, 3, 3);
1829 test_range_text(range, "wor");
1830 test_range_parent(range, ET_BODY);
1831 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1832 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1833 test_range_move(range, characterW, 3, 3);
1834 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1835 test_range_moveend(range, characterW, -4, -4);
1836 test_range_put_text(range, "abc def ");
1837 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1838 test_range_move(range, wordW, 1, 1);
1839 test_range_movestart(range, characterW, -1, -1);
1840 test_range_text(range, " ");
1841 test_range_move(range, wordW, 1, 1);
1842 test_range_moveend(range, characterW, 3, 3);
1843 test_range_text(range, "def");
1844 test_range_put_text(range, "xyz");
1845 test_range_moveend(range, characterW, 1, 1);
1846 test_range_move(range, wordW, 1, 1);
1847 test_range_moveend(range, characterW, 2, 2);
1848 test_range_text(range, "ab");
1850 IHTMLTxtRange_Release(range);
1853 static void test_txtrange2(IHTMLDocument2 *doc)
1855 IHTMLTxtRange *range;
1857 range = test_create_body_range(doc);
1859 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1860 test_range_move(range, characterW, 5, 5);
1861 test_range_moveend(range, characterW, 1, 1);
1862 test_range_text(range, "2");
1863 test_range_move(range, characterW, -3, -3);
1864 test_range_moveend(range, characterW, 3, 3);
1865 test_range_text(range, "c\r\n\r\n1");
1866 test_range_collapse(range, VARIANT_FALSE);
1867 test_range_moveend(range, characterW, 4, 4);
1868 test_range_text(range, "23");
1869 test_range_moveend(range, characterW, 1, 1);
1870 test_range_text(range, "23\r\n\r\n\r\nd");
1871 test_range_moveend(range, characterW, -1, -1);
1872 test_range_text(range, "23");
1873 test_range_moveend(range, characterW, -1, -1);
1874 test_range_text(range, "23");
1875 test_range_moveend(range, characterW, -2, -2);
1876 test_range_text(range, "2");
1878 IHTMLTxtRange_Release(range);
1881 static void test_compatmode(IHTMLDocument2 *doc)
1883 IHTMLDocument5 *doc5;
1887 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1888 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1892 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1893 IHTMLDocument5_Release(doc5);
1894 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1895 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1896 SysFreeString(mode);
1899 static void test_location(IHTMLDocument2 *doc)
1901 IHTMLLocation *location, *location2;
1905 hres = IHTMLDocument2_get_location(doc, &location);
1906 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1908 hres = IHTMLDocument2_get_location(doc, &location2);
1909 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1911 ok(location == location2, "location != location2\n");
1913 test_ifaces((IUnknown*)location, location_iids);
1915 IHTMLLocation_Release(location2);
1916 ref = IHTMLLocation_Release(location);
1917 ok(!ref, "location chould be destroyed here\n");
1920 static void test_navigator(IHTMLDocument2 *doc)
1922 IHTMLWindow2 *window;
1923 IOmNavigator *navigator, *navigator2;
1928 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1929 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1931 hres = IHTMLWindow2_get_navigator(window, &navigator);
1932 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1933 ok(navigator != NULL, "navigator == NULL\n");
1934 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1936 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1937 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1938 ok(navigator != navigator2, "navigator2 != navihgator\n");
1940 IHTMLWindow2_Release(window);
1941 IOmNavigator_Release(navigator2);
1943 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
1944 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
1945 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
1946 SysFreeString(bstr);
1949 hres = IOmNavigator_get_platform(navigator, &bstr);
1950 ok(hres == S_OK, "get_appMinorVersion failed: %08x\n", hres);
1951 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
1952 SysFreeString(bstr);
1954 ref = IOmNavigator_Release(navigator);
1955 ok(!ref, "navigator should be destroyed here\n");
1958 static void test_default_style(IHTMLStyle *style)
1965 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
1967 str = (void*)0xdeadbeef;
1968 hres = IHTMLStyle_get_fontFamily(style, &str);
1969 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1970 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1972 str = (void*)0xdeadbeef;
1973 hres = IHTMLStyle_get_fontWeight(style, &str);
1974 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1975 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1977 str = (void*)0xdeadbeef;
1978 hres = IHTMLStyle_get_display(style, &str);
1979 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1980 ok(!str, "display = %s\n", dbgstr_w(str));
1982 str = (void*)0xdeadbeef;
1983 hres = IHTMLStyle_get_visibility(style, &str);
1984 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1985 ok(!str, "visibility = %s\n", dbgstr_w(str));
1988 hres = IHTMLStyle_get_fontSize(style, &v);
1989 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1990 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1991 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1994 hres = IHTMLStyle_get_color(style, &v);
1995 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1996 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1997 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2000 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2001 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2002 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2005 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2006 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2007 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2009 V_VT(&v) = VT_EMPTY;
2010 hres = IHTMLStyle_get_width(style, &v);
2011 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2012 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2013 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2016 V_BSTR(&v) = a2bstr("auto");
2017 hres = IHTMLStyle_put_width(style, v);
2018 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2021 V_VT(&v) = VT_EMPTY;
2022 hres = IHTMLStyle_get_width(style, &v);
2023 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2024 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2025 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2029 str = (void*)0xdeadbeef;
2030 hres = IHTMLStyle_get_margin(style, &str);
2031 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2032 ok(!str, "margin = %s\n", dbgstr_w(str));
2035 hres = IHTMLStyle_put_margin(style, str);
2036 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2039 hres = IHTMLStyle_get_margin(style, &str);
2040 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2041 ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2043 hres = IHTMLStyle_put_margin(style, NULL);
2044 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2047 static void test_default_selection(IHTMLDocument2 *doc)
2049 IHTMLSelectionObject *selection;
2050 IHTMLTxtRange *range;
2055 hres = IHTMLDocument2_get_selection(doc, &selection);
2056 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2058 hres = IHTMLSelectionObject_get_type(selection, &str);
2059 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2060 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2063 hres = IHTMLSelectionObject_createRange(selection, &disp);
2064 IHTMLSelectionObject_Release(selection);
2065 ok(hres == S_OK, "createRange failed: %08x\n", hres);
2067 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2068 IDispatch_Release(disp);
2069 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2071 test_range_text(range, NULL);
2072 IHTMLTxtRange_Release(range);
2075 static void test_default_body(IHTMLBodyElement *body)
2081 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2082 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2083 WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2085 bstr = (void*)0xdeadbeef;
2086 hres = IHTMLBodyElement_get_background(body, &bstr);
2087 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2088 ok(bstr == NULL, "bstr != NULL\n");
2090 l = elem_get_scroll_height((IUnknown*)body);
2091 ok(l != -1, "scrollHeight == -1\n");
2092 l = elem_get_scroll_width((IUnknown*)body);
2093 ok(l != -1, "scrollWidth == -1\n");
2094 l = elem_get_scroll_top((IUnknown*)body);
2095 ok(!l, "scrollTop = %ld\n", l);
2096 elem_get_scroll_left((IUnknown*)body);
2098 /* get_text tests */
2099 hres = IHTMLBodyElement_get_text(body, &v);
2100 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2101 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2102 ok(bstr == NULL, "bstr != NULL\n");
2105 /* get_text - Invalid Text */
2107 V_BSTR(&v) = SysAllocString(sTextInvalid);
2108 hres = IHTMLBodyElement_put_text(body, v);
2109 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2112 hres = IHTMLBodyElement_get_text(body, &v);
2113 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2114 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2115 ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2118 /* get_text - Valid Text */
2120 V_BSTR(&v) = SysAllocString(sBodyText);
2121 hres = IHTMLBodyElement_put_text(body, v);
2122 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2125 hres = IHTMLBodyElement_get_text(body, &v);
2126 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2127 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2128 ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2132 static void test_body_funs(IHTMLBodyElement *body)
2134 static WCHAR sRed[] = {'r','e','d',0};
2135 static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2140 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2141 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2142 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2144 V_VT(&vbg) = VT_BSTR;
2145 V_BSTR(&vbg) = SysAllocString(sRed);
2146 hres = IHTMLBodyElement_put_bgColor(body, vbg);
2147 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2150 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2151 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2152 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2153 ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2156 /* Restore Originial */
2157 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2158 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2159 VariantClear(&vDefaultbg);
2162 static void test_window(IHTMLDocument2 *doc)
2164 IHTMLWindow2 *window, *window2, *self;
2165 IHTMLDocument2 *doc2 = NULL;
2169 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2170 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2171 test_ifaces((IUnknown*)window, window_iids);
2172 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2174 hres = IHTMLWindow2_get_document(window, &doc2);
2175 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2176 ok(doc2 != NULL, "doc2 == NULL\n");
2178 IHTMLDocument_Release(doc2);
2180 hres = IHTMLWindow2_get_window(window, &window2);
2181 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2182 ok(window2 != NULL, "window2 == NULL\n");
2184 hres = IHTMLWindow2_get_self(window, &self);
2185 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2186 ok(window2 != NULL, "self == NULL\n");
2188 ok(self == window2, "self != window2\n");
2190 IHTMLWindow2_Release(window2);
2191 IHTMLWindow2_Release(self);
2194 hres = IHTMLDocument2_get_Script(doc, &disp);
2195 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2196 ok(disp == (void*)window, "disp != window\n");
2197 IDispatch_Release(disp);
2199 IHTMLWindow2_Release(window);
2202 static void test_defaults(IHTMLDocument2 *doc)
2204 IHTMLStyleSheetsCollection *stylesheetcol;
2205 IHTMLBodyElement *body;
2211 hres = IHTMLDocument2_get_body(doc, &elem);
2212 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2214 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2215 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2216 test_default_body(body);
2217 test_body_funs(body);
2218 IHTMLBodyElement_Release(body);
2220 hres = IHTMLElement_get_style(elem, &style);
2221 IHTMLElement_Release(elem);
2222 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2224 test_default_style(style);
2226 test_compatmode(doc);
2228 test_navigator(doc);
2230 IHTMLStyle_Release(style);
2232 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2233 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2236 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2237 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2238 ok(l == 0, "length = %ld\n", l);
2240 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2242 test_default_selection(doc);
2243 test_doc_title(doc, "");
2246 static void test_table_elem(IHTMLElement *elem)
2248 IHTMLElementCollection *col;
2252 static const elem_type_t row_types[] = {ET_TR,ET_TR};
2254 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2255 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2260 hres = IHTMLTable_get_rows(table, &col);
2261 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2262 ok(col != NULL, "get_ros returned NULL\n");
2264 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2265 IHTMLElementCollection_Release(col);
2267 IHTMLTable_Release(table);
2270 static void test_stylesheet(IDispatch *disp)
2272 IHTMLStyleSheetRulesCollection *col = NULL;
2273 IHTMLStyleSheet *stylesheet;
2276 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2277 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2279 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2280 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2281 ok(col != NULL, "col == NULL\n");
2283 IHTMLStyleSheetRulesCollection_Release(col);
2284 IHTMLStyleSheet_Release(stylesheet);
2287 static void test_stylesheets(IHTMLDocument2 *doc)
2289 IHTMLStyleSheetsCollection *col = NULL;
2294 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2295 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2296 ok(col != NULL, "col == NULL\n");
2298 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2299 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2300 ok(len == 1, "len=%ld\n", len);
2306 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2307 ok(hres == S_OK, "item failed: %08x\n", hres);
2308 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2309 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2310 test_stylesheet(V_DISPATCH(&res));
2317 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2318 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2319 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2320 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2323 IHTMLStyleSheetsCollection_Release(col);
2326 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2328 IDispatchEx *dispex;
2330 DISPPARAMS dp = {NULL, NULL, 0, 0};
2338 static const WCHAR w0[] = {'0',0};
2339 static const WCHAR w100[] = {'1','0','0',0};
2341 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2342 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2344 bstr = SysAllocString(w0);
2345 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2346 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2347 SysFreeString(bstr);
2350 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2351 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2352 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2353 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2354 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2355 type = get_node_type((IUnknown*)node);
2356 ok(type == 3, "type=%ld\n", type);
2357 IHTMLDOMNode_Release(node);
2360 bstr = SysAllocString(w100);
2361 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2362 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2363 SysFreeString(bstr);
2365 IDispatchEx_Release(dispex);
2370 static void test_elems(IHTMLDocument2 *doc)
2372 IHTMLElementCollection *col;
2373 IHTMLDOMChildrenCollection *child_col;
2374 IHTMLElement *elem, *elem2, *elem3;
2375 IHTMLDOMNode *node, *node2;
2380 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2381 static const WCHAR inW[] = {'i','n',0};
2382 static const WCHAR xW[] = {'x',0};
2383 static const WCHAR sW[] = {'s',0};
2384 static const WCHAR scW[] = {'s','c',0};
2385 static const WCHAR xxxW[] = {'x','x','x',0};
2386 static const WCHAR tblW[] = {'t','b','l',0};
2388 static const elem_type_t all_types[] = {
2410 static const elem_type_t item_types[] = {
2416 hres = IHTMLDocument2_get_all(doc, &col);
2417 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2418 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2419 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2420 IHTMLElementCollection_Release(col);
2422 elem = get_doc_elem(doc);
2423 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
2424 hres = IHTMLElement_get_all(elem, &disp);
2425 IHTMLElement_Release(elem);
2426 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2428 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2429 IDispatch_Release(disp);
2430 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2431 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
2432 IHTMLElementCollection_Release(col);
2434 get_elem_by_id(doc, xxxW, FALSE);
2435 elem = get_doc_elem_by_id(doc, xxxW);
2436 ok(!elem, "elem != NULL\n");
2438 elem = get_doc_elem_by_id(doc, sW);
2439 ok(elem != NULL, "elem == NULL\n");
2441 test_elem_type((IUnknown*)elem, ET_SELECT);
2442 test_elem_attr(elem, xxxW, NULL);
2443 test_elem_attr(elem, idW, sW);
2444 test_elem_class((IUnknown*)elem, NULL);
2445 test_elem_set_class((IUnknown*)elem, "cl");
2446 test_elem_set_class((IUnknown*)elem, NULL);
2447 test_elem_tabindex((IUnknown*)elem, 0);
2448 test_elem_set_tabindex((IUnknown*)elem, 1);
2450 node = test_node_get_parent((IUnknown*)elem);
2451 ok(node != NULL, "node == NULL\n");
2452 test_node_name((IUnknown*)node, "BODY");
2453 node2 = test_node_get_parent((IUnknown*)node);
2454 IHTMLDOMNode_Release(node);
2455 ok(node2 != NULL, "node == NULL\n");
2456 test_node_name((IUnknown*)node2, "HTML");
2457 node = test_node_get_parent((IUnknown*)node2);
2458 IHTMLDOMNode_Release(node2);
2459 ok(node != NULL, "node == NULL\n");
2460 test_node_name((IUnknown*)node, "#document");
2461 type = get_node_type((IUnknown*)node);
2462 ok(type == 9, "type=%ld, expected 9\n", type);
2463 node2 = test_node_get_parent((IUnknown*)node);
2464 IHTMLDOMNode_Release(node);
2465 ok(node2 == NULL, "node != NULL\n");
2467 elem2 = test_elem_get_parent((IUnknown*)elem);
2468 ok(elem2 != NULL, "elem2 == NULL\n");
2469 test_node_name((IUnknown*)elem2, "BODY");
2470 elem3 = test_elem_get_parent((IUnknown*)elem2);
2471 IHTMLElement_Release(elem2);
2472 ok(elem3 != NULL, "elem3 == NULL\n");
2473 test_node_name((IUnknown*)elem3, "HTML");
2474 elem2 = test_elem_get_parent((IUnknown*)elem3);
2475 IHTMLElement_Release(elem3);
2476 ok(elem2 == NULL, "elem2 != NULL\n");
2478 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
2479 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
2480 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
2482 IHTMLElement_Release(elem);
2485 elem = get_elem_by_id(doc, sW, TRUE);
2487 IHTMLSelectElement *select;
2489 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
2490 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
2492 test_select_elem(select);
2494 test_elem_title((IUnknown*)select, NULL);
2495 test_elem_set_title((IUnknown*)select, "Title");
2496 test_elem_title((IUnknown*)select, "Title");
2497 test_elem_offset((IUnknown*)select);
2499 node = get_first_child((IUnknown*)select);
2500 ok(node != NULL, "node == NULL\n");
2502 test_elem_type((IUnknown*)node, ET_OPTION);
2503 IHTMLDOMNode_Release(node);
2506 type = get_node_type((IUnknown*)select);
2507 ok(type == 1, "type=%ld\n", type);
2509 IHTMLSelectElement_Release(select);
2510 IHTMLElement_Release(elem);
2513 elem = get_elem_by_id(doc, scW, TRUE);
2515 IHTMLScriptElement *script;
2518 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
2519 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
2521 hres = IHTMLScriptElement_get_type(script, &type);
2522 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2523 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
2524 SysFreeString(type);
2526 IHTMLScriptElement_Release(script);
2529 elem = get_elem_by_id(doc, inW, TRUE);
2531 IHTMLInputElement *input;
2533 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
2534 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2536 test_elem_id((IUnknown*)elem, "in");
2537 test_elem_put_id((IUnknown*)elem, "newin");
2538 test_input_get_disabled(input, VARIANT_FALSE);
2539 test_input_set_disabled(input, VARIANT_TRUE);
2540 test_input_set_disabled(input, VARIANT_FALSE);
2541 test_elem_client_size((IUnknown*)elem);
2543 test_node_get_value_str((IUnknown*)elem, NULL);
2544 test_node_put_value_str((IUnknown*)elem, "test");
2545 test_node_get_value_str((IUnknown*)elem, NULL);
2546 test_input_value((IUnknown*)elem, NULL);
2547 test_input_put_value((IUnknown*)elem, "test");
2548 test_input_value((IUnknown*)elem, NULL);
2549 test_elem_class((IUnknown*)elem, "testclass");
2550 test_elem_tabindex((IUnknown*)elem, 2);
2551 test_elem_set_tabindex((IUnknown*)elem, 3);
2552 test_elem_title((IUnknown*)elem, "test title");
2554 IHTMLInputElement_Release(input);
2555 IHTMLElement_Release(elem);
2558 elem = get_elem_by_id(doc, imgidW, TRUE);
2560 test_img_set_src((IUnknown*)elem, "about:blank");
2561 test_img_alt((IUnknown*)elem, NULL);
2562 test_img_set_alt((IUnknown*)elem, "alt test");
2563 IHTMLElement_Release(elem);
2566 elem = get_doc_elem_by_id(doc, tblW);
2567 ok(elem != NULL, "elem == NULL\n");
2569 test_table_elem(elem);
2570 IHTMLElement_Release(elem);
2573 hres = IHTMLDocument2_get_body(doc, &elem);
2574 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2576 node = get_first_child((IUnknown*)elem);
2577 ok(node != NULL, "node == NULL\n");
2579 test_ifaces((IUnknown*)node, text_iids);
2580 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2582 node2 = get_first_child((IUnknown*)node);
2583 ok(!node2, "node2 != NULL\n");
2585 type = get_node_type((IUnknown*)node);
2586 ok(type == 3, "type=%ld\n", type);
2588 test_node_get_value_str((IUnknown*)node, "text test");
2589 test_node_put_value_str((IUnknown*)elem, "test text");
2590 test_node_get_value_str((IUnknown*)node, "text test");
2592 IHTMLDOMNode_Release(node);
2595 child_col = get_child_nodes((IUnknown*)elem);
2596 ok(child_col != NULL, "child_coll == NULL\n");
2600 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
2602 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
2603 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2604 ok(length, "length=0\n");
2606 node = get_child_item(child_col, 0);
2607 ok(node != NULL, "node == NULL\n");
2609 type = get_node_type((IUnknown*)node);
2610 ok(type == 3, "type=%ld\n", type);
2611 IHTMLDOMNode_Release(node);
2614 node = get_child_item(child_col, 1);
2615 ok(node != NULL, "node == NULL\n");
2617 type = get_node_type((IUnknown*)node);
2618 ok(type == 8, "type=%ld\n", type);
2620 test_elem_id((IUnknown*)node, NULL);
2621 IHTMLDOMNode_Release(node);
2624 disp = (void*)0xdeadbeef;
2625 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
2626 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2627 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2629 disp = (void*)0xdeadbeef;
2630 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
2631 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2632 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2634 test_child_col_disp(child_col);
2636 IHTMLDOMChildrenCollection_Release(child_col);
2639 IHTMLElement_Release(elem);
2641 test_stylesheets(doc);
2642 test_create_option_elem(doc);
2644 test_doc_title(doc, "test");
2645 test_doc_set_title(doc, "test title");
2646 test_doc_title(doc, "test title");
2649 static void test_create_elems(IHTMLDocument2 *doc)
2651 IHTMLElement *elem, *body, *elem2;
2657 static const elem_type_t types1[] = { ET_TESTG };
2659 elem = test_create_elem(doc, "TEST");
2660 test_elem_tag((IUnknown*)elem, "TEST");
2661 type = get_node_type((IUnknown*)elem);
2662 ok(type == 1, "type=%ld\n", type);
2663 test_ifaces((IUnknown*)elem, elem_iids);
2664 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
2666 hres = IHTMLDocument2_get_body(doc, &body);
2667 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2668 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2670 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
2671 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
2672 elem2 = get_elem_iface((IUnknown*)node);
2673 IHTMLElement_Release(elem2);
2675 hres = IHTMLElement_get_all(body, &disp);
2676 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2677 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
2678 IDispatch_Release(disp);
2680 test_node_remove_child((IUnknown*)body, node);
2682 hres = IHTMLElement_get_all(body, &disp);
2683 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2684 test_elem_collection((IUnknown*)disp, NULL, 0);
2685 IDispatch_Release(disp);
2686 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2688 IHTMLElement_Release(body);
2689 IHTMLElement_Release(elem);
2690 IHTMLDOMNode_Release(node);
2692 node = test_create_text(doc, "test");
2693 test_ifaces((IUnknown*)node, text_iids);
2694 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2695 IHTMLDOMNode_Release(node);
2698 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
2700 IOleCommandTarget *cmdtrg;
2703 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2704 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
2706 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
2707 ok(hres == S_OK, "Exec failed: %08x\n", hres);
2709 IOleCommandTarget_Release(cmdtrg);
2712 static void test_indent(IHTMLDocument2 *doc)
2714 IHTMLElementCollection *col;
2715 IHTMLTxtRange *range;
2718 static const elem_type_t all_types[] = {
2727 static const elem_type_t indent_types[] = {
2738 hres = IHTMLDocument2_get_all(doc, &col);
2739 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2740 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2741 IHTMLElementCollection_Release(col);
2743 range = test_create_body_range(doc);
2744 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
2745 IHTMLTxtRange_Release(range);
2747 hres = IHTMLDocument2_get_all(doc, &col);
2748 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2749 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
2750 IHTMLElementCollection_Release(col);
2753 static IHTMLDocument2 *notif_doc;
2754 static BOOL doc_complete;
2756 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2757 REFIID riid, void**ppv)
2759 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2764 ok(0, "unexpected call\n");
2765 return E_NOINTERFACE;
2768 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2773 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2778 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2780 if(dispID == DISPID_READYSTATE){
2784 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
2786 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2787 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2789 if(!lstrcmpW(state, completeW))
2790 doc_complete = TRUE;
2792 SysFreeString(state);
2798 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2800 ok(0, "unexpected call\n");
2804 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2805 PropertyNotifySink_QueryInterface,
2806 PropertyNotifySink_AddRef,
2807 PropertyNotifySink_Release,
2808 PropertyNotifySink_OnChanged,
2809 PropertyNotifySink_OnRequestEdit
2812 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2814 static IHTMLDocument2 *create_doc_with_string(const char *str)
2816 IPersistStreamInit *init;
2818 IHTMLDocument2 *doc;
2822 notif_doc = doc = create_document();
2826 doc_complete = FALSE;
2828 mem = GlobalAlloc(0, len);
2829 memcpy(mem, str, len);
2830 CreateStreamOnHGlobal(mem, TRUE, &stream);
2832 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2834 IPersistStreamInit_Load(init, stream);
2835 IPersistStreamInit_Release(init);
2836 IStream_Release(stream);
2841 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2843 IConnectionPointContainer *container;
2844 IConnectionPoint *cp;
2848 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2849 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2851 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2852 IConnectionPointContainer_Release(container);
2853 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2855 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2856 IConnectionPoint_Release(cp);
2857 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2860 typedef void (*domtest_t)(IHTMLDocument2*);
2862 static void run_domtest(const char *str, domtest_t test)
2864 IHTMLDocument2 *doc;
2865 IHTMLElement *body = NULL;
2870 doc = create_doc_with_string(str);
2871 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2873 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
2874 TranslateMessage(&msg);
2875 DispatchMessage(&msg);
2878 hres = IHTMLDocument2_get_body(doc, &body);
2879 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2882 IHTMLElement_Release(body);
2885 skip("Could not get document body. Assuming no Gecko installed.\n");
2888 ref = IHTMLDocument2_Release(doc);
2890 ref == 1, /* Vista */
2894 static void gecko_installer_workaround(BOOL disable)
2899 static BOOL has_url = FALSE;
2900 static char url[2048];
2902 if(!disable && !has_url)
2905 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2906 if(res != ERROR_SUCCESS)
2910 DWORD type, size = sizeof(url);
2912 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2913 if(res == ERROR_SUCCESS && type == REG_SZ)
2916 RegDeleteValue(hkey, "GeckoUrl");
2918 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2926 gecko_installer_workaround(TRUE);
2929 run_domtest(doc_str1, test_doc_elem);
2930 run_domtest(range_test_str, test_txtrange);
2931 run_domtest(range_test2_str, test_txtrange2);
2932 run_domtest(elem_test_str, test_elems);
2933 run_domtest(doc_blank, test_create_elems);
2934 run_domtest(doc_blank, test_defaults);
2935 run_domtest(indent_test_str, test_indent);
2938 gecko_installer_workaround(FALSE);