mshtml: Added IDispatchEx support to HTMLStyle.
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob1039ab5ad0354f34ba009a4b9d5a170fddb132c6
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmcid.h"
31 #include "mshtmhst.h"
32 #include "docobj.h"
33 #include "dispex.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\" />"
46 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table><tbody></tbody></table>"
49 "<script id=\"sc\" type=\"text/javascript\"></script>"
50 "<test />"
51 "</body></html>";
52 static const char indent_test_str[] =
53 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
55 static const WCHAR noneW[] = {'N','o','n','e',0};
57 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
58 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
59 static WCHAR wordW[] = {'w','o','r','d',0};
61 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
63 static const WCHAR idW[] = {'i','d',0};
65 typedef enum {
66 ET_NONE,
67 ET_HTML,
68 ET_HEAD,
69 ET_TITLE,
70 ET_BODY,
71 ET_A,
72 ET_INPUT,
73 ET_SELECT,
74 ET_TEXTAREA,
75 ET_OPTION,
76 ET_STYLE,
77 ET_BLOCKQUOTE,
78 ET_P,
79 ET_BR,
80 ET_TABLE,
81 ET_TBODY,
82 ET_SCRIPT,
83 ET_TEST,
84 ET_COMMENT
85 } elem_type_t;
87 static REFIID const none_iids[] = {
88 &IID_IUnknown,
89 NULL
92 static REFIID const elem_iids[] = {
93 &IID_IHTMLDOMNode,
94 &IID_IHTMLDOMNode2,
95 &IID_IHTMLElement,
96 &IID_IHTMLElement2,
97 &IID_IDispatchEx,
98 &IID_IConnectionPointContainer,
99 NULL
102 static REFIID const body_iids[] = {
103 &IID_IHTMLDOMNode,
104 &IID_IHTMLDOMNode2,
105 &IID_IHTMLElement,
106 &IID_IHTMLElement2,
107 &IID_IHTMLTextContainer,
108 &IID_IHTMLBodyElement,
109 &IID_IDispatchEx,
110 &IID_IConnectionPointContainer,
111 NULL
114 static REFIID const anchor_iids[] = {
115 &IID_IHTMLDOMNode,
116 &IID_IHTMLDOMNode2,
117 &IID_IHTMLElement,
118 &IID_IHTMLElement2,
119 &IID_IHTMLAnchorElement,
120 &IID_IDispatchEx,
121 &IID_IConnectionPointContainer,
122 NULL
125 static REFIID const input_iids[] = {
126 &IID_IHTMLDOMNode,
127 &IID_IHTMLDOMNode2,
128 &IID_IHTMLElement,
129 &IID_IHTMLElement2,
130 &IID_IHTMLInputElement,
131 &IID_IHTMLInputTextElement,
132 &IID_IDispatchEx,
133 &IID_IConnectionPointContainer,
134 NULL
137 static REFIID const select_iids[] = {
138 &IID_IHTMLDOMNode,
139 &IID_IHTMLDOMNode2,
140 &IID_IHTMLElement,
141 &IID_IHTMLElement2,
142 &IID_IHTMLSelectElement,
143 &IID_IDispatchEx,
144 &IID_IConnectionPointContainer,
145 NULL
148 static REFIID const textarea_iids[] = {
149 &IID_IHTMLDOMNode,
150 &IID_IHTMLDOMNode2,
151 &IID_IHTMLElement,
152 &IID_IHTMLElement2,
153 &IID_IHTMLTextAreaElement,
154 &IID_IDispatchEx,
155 &IID_IConnectionPointContainer,
156 NULL
159 static REFIID const option_iids[] = {
160 &IID_IHTMLDOMNode,
161 &IID_IHTMLDOMNode2,
162 &IID_IHTMLElement,
163 &IID_IHTMLElement2,
164 &IID_IHTMLOptionElement,
165 &IID_IDispatchEx,
166 &IID_IConnectionPointContainer,
167 NULL
170 static REFIID const table_iids[] = {
171 &IID_IHTMLDOMNode,
172 &IID_IHTMLDOMNode2,
173 &IID_IHTMLElement,
174 &IID_IHTMLElement2,
175 &IID_IHTMLTable,
176 &IID_IDispatchEx,
177 &IID_IConnectionPointContainer,
178 NULL
181 static REFIID const script_iids[] = {
182 &IID_IHTMLDOMNode,
183 &IID_IHTMLDOMNode2,
184 &IID_IHTMLElement,
185 &IID_IHTMLElement2,
186 &IID_IHTMLScriptElement,
187 &IID_IDispatchEx,
188 &IID_IConnectionPointContainer,
189 NULL
192 static REFIID const text_iids[] = {
193 &IID_IHTMLDOMNode,
194 &IID_IHTMLDOMNode2,
195 &IID_IHTMLDOMTextNode,
196 NULL
199 static REFIID const location_iids[] = {
200 &IID_IDispatch,
201 &IID_IHTMLLocation,
202 NULL
205 static REFIID const window_iids[] = {
206 &IID_IDispatch,
207 &IID_IHTMLWindow2,
208 &IID_IHTMLWindow3,
209 &IID_IDispatchEx,
210 NULL
213 static REFIID const comment_iids[] = {
214 &IID_IHTMLDOMNode,
215 &IID_IHTMLDOMNode2,
216 &IID_IHTMLElement,
217 &IID_IHTMLElement2,
218 &IID_IHTMLCommentElement,
219 &IID_IDispatchEx,
220 &IID_IConnectionPointContainer,
221 NULL
224 typedef struct {
225 const char *tag;
226 REFIID *iids;
227 const IID *dispiid;
228 } elem_type_info_t;
230 static const elem_type_info_t elem_type_infos[] = {
231 {"", none_iids, NULL},
232 {"HTML", elem_iids, NULL},
233 {"HEAD", elem_iids, NULL},
234 {"TITLE", elem_iids, NULL},
235 {"BODY", body_iids, NULL},
236 {"A", anchor_iids, NULL},
237 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
238 {"SELECT", select_iids, NULL},
239 {"TEXTAREA", textarea_iids, NULL},
240 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
241 {"STYLE", elem_iids, NULL},
242 {"BLOCKQUOTE",elem_iids, NULL},
243 {"P", elem_iids, NULL},
244 {"BR", elem_iids, NULL},
245 {"TABLE", table_iids, NULL},
246 {"TBODY", elem_iids, NULL},
247 {"SCRIPT", script_iids, NULL},
248 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
249 {"!", comment_iids, &DIID_DispHTMLCommentElement}
252 static const char *dbgstr_w(LPCWSTR str)
254 static char buf[512];
255 if(!str)
256 return "(null)";
257 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
258 return buf;
261 static const char *dbgstr_guid(REFIID riid)
263 static char buf[50];
265 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
266 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
267 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
268 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
270 return buf;
273 static int strcmp_wa(LPCWSTR strw, const char *stra)
275 WCHAR buf[512];
276 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
277 return lstrcmpW(strw, buf);
280 static BSTR a2bstr(const char *str)
282 BSTR ret;
283 int len;
285 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
286 ret = SysAllocStringLen(NULL, len);
287 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
289 return ret;
292 static IHTMLDocument2 *create_document(void)
294 IHTMLDocument2 *doc;
295 HRESULT hres;
297 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
298 &IID_IHTMLDocument2, (void**)&doc);
299 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
301 return doc;
304 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
305 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
307 const IID * const *piid;
308 IUnknown *unk;
309 HRESULT hres;
311 for(piid = iids; *piid; piid++) {
312 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
313 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
314 if(SUCCEEDED(hres))
315 IUnknown_Release(unk);
319 #define test_disp(u,id) _test_disp(__LINE__,u,id)
320 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
322 IDispatchEx *dispex;
323 ITypeInfo *typeinfo;
324 UINT ticnt;
325 HRESULT hres;
327 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
328 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
329 if(FAILED(hres))
330 return;
332 ticnt = 0xdeadbeef;
333 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
334 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
335 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
337 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
338 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
340 if(SUCCEEDED(hres)) {
341 TYPEATTR *type_attr;
343 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
344 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
345 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
347 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
348 ITypeInfo_Release(typeinfo);
351 IDispatchEx_Release(dispex);
354 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
355 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
357 IHTMLDOMNode *node;
358 BSTR name;
359 HRESULT hres;
361 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
362 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
364 hres = IHTMLDOMNode_get_nodeName(node, &name);
365 IHTMLDOMNode_Release(node);
366 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
367 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
369 SysFreeString(name);
372 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
373 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
375 IHTMLElement *elem;
376 BSTR tag;
377 HRESULT hres;
379 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
380 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
382 hres = IHTMLElement_get_tagName(elem, &tag);
383 IHTMLElement_Release(elem);
384 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
385 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
387 SysFreeString(tag);
390 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
391 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
393 _test_elem_tag(line, unk, elem_type_infos[type].tag);
394 _test_ifaces(line, unk, elem_type_infos[type].iids);
396 if(elem_type_infos[type].dispiid)
397 _test_disp(line, unk, elem_type_infos[type].dispiid);
400 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
401 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
403 VARIANT value;
404 BSTR tmp;
405 HRESULT hres;
407 VariantInit(&value);
409 tmp = SysAllocString(name);
410 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
411 SysFreeString(tmp);
412 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
414 if(exval) {
415 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
416 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
417 }else {
418 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
421 VariantClear(&value);
424 static void test_doc_elem(IHTMLDocument2 *doc)
426 IHTMLElement *elem;
427 IHTMLDocument3 *doc3;
428 HRESULT hres;
430 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
431 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
433 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
434 IHTMLDocument3_Release(doc3);
435 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
437 test_node_name((IUnknown*)elem, "HTML");
438 test_elem_tag((IUnknown*)elem, "HTML");
440 IHTMLElement_Release(elem);
443 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
444 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
446 IHTMLElement *elem;
447 IHTMLDocument3 *doc3;
448 HRESULT hres;
450 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
451 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
452 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
453 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
454 IHTMLDocument3_Release(doc3);
456 return elem;
459 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
460 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
462 BSTR bstr;
463 HRESULT hres;
465 hres = IHTMLOptionElement_get_text(option, &bstr);
466 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
467 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
468 SysFreeString(bstr);
471 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
472 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
474 BSTR bstr;
475 HRESULT hres;
477 bstr = a2bstr(text);
478 hres = IHTMLOptionElement_put_text(option, bstr);
479 SysFreeString(bstr);
480 ok(hres == S_OK, "put_text failed: %08x\n", hres);
482 _test_option_text(line, option, text);
485 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
486 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
488 BSTR bstr;
489 HRESULT hres;
491 hres = IHTMLOptionElement_get_value(option, &bstr);
492 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
493 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
494 SysFreeString(bstr);
497 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
498 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
500 BSTR bstr;
501 HRESULT hres;
503 bstr = a2bstr(value);
504 hres = IHTMLOptionElement_put_value(option, bstr);
505 SysFreeString(bstr);
506 ok(hres == S_OK, "put_value failed: %08x\n", hres);
508 _test_option_value(line, option, value);
511 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
512 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
513 const char *txt, const char *val)
515 IHTMLOptionElementFactory *factory;
516 IHTMLOptionElement *option;
517 IHTMLWindow2 *window;
518 VARIANT text, value, empty;
519 HRESULT hres;
521 hres = IHTMLDocument2_get_parentWindow(doc, &window);
522 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
524 hres = IHTMLWindow2_get_Option(window, &factory);
525 IHTMLWindow2_Release(window);
526 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
528 V_VT(&text) = VT_BSTR;
529 V_BSTR(&text) = a2bstr(txt);
530 V_VT(&value) = VT_BSTR;
531 V_BSTR(&value) = a2bstr(val);
532 V_VT(&empty) = VT_EMPTY;
534 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
535 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
537 IHTMLOptionElementFactory_Release(factory);
538 VariantClear(&text);
539 VariantClear(&value);
541 _test_option_text(line, option, txt);
542 _test_option_value(line, option, val);
544 return option;
547 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
548 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
550 long len = 0xdeadbeef;
551 HRESULT hres;
553 hres = IHTMLSelectElement_get_length(select, &len);
554 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
555 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
558 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
559 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
561 long idx = 0xdeadbeef;
562 HRESULT hres;
564 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
565 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
566 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
569 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
570 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
572 HRESULT hres;
574 hres = IHTMLSelectElement_put_selectedIndex(select, index);
575 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
576 _test_select_selidx(line, select, index);
579 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
580 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
582 BSTR text;
583 HRESULT hres;
585 hres = IHTMLTxtRange_get_text(range, &text);
586 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
588 if(extext) {
589 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
590 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
591 }else {
592 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
595 SysFreeString(text);
599 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
600 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
602 HRESULT hres;
604 hres = IHTMLTxtRange_collapse(range, b);
605 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
606 _test_range_text(line, range, NULL);
609 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
610 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
611 VARIANT_BOOL exb, const char *extext)
613 VARIANT_BOOL b = 0xe0e0;
614 HRESULT hres;
616 hres = IHTMLTxtRange_expand(range, unit, &b);
617 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
618 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
619 _test_range_text(line, range, extext);
622 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
623 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
625 long c = 0xdeadbeef;
626 HRESULT hres;
628 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
629 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
630 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
631 _test_range_text(line, range, NULL);
634 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
635 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
636 LPWSTR unit, long cnt, long excnt)
638 long c = 0xdeadbeef;
639 HRESULT hres;
641 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
642 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
643 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
646 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
647 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
649 long c = 0xdeadbeef;
650 HRESULT hres;
652 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
653 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
654 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
657 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
658 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
660 HRESULT hres;
661 BSTR bstr = a2bstr(text);
663 hres = IHTMLTxtRange_put_text(range, bstr);
664 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
665 SysFreeString(bstr);
666 _test_range_text(line, range, NULL);
669 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
670 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
672 VARIANT_BOOL b;
673 HRESULT hres;
675 b = 0xe0e0;
676 hres = IHTMLTxtRange_inRange(range1, range2, &b);
677 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
678 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
681 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
682 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
684 VARIANT_BOOL b;
685 HRESULT hres;
687 b = 0xe0e0;
688 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
689 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
690 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
692 b = 0xe0e0;
693 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
694 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
695 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
697 if(exb) {
698 test_range_inrange(range1, range2, VARIANT_TRUE);
699 test_range_inrange(range2, range1, VARIANT_TRUE);
703 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
704 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
706 IHTMLElement *elem;
707 HRESULT hres;
709 hres = IHTMLTxtRange_parentElement(range, &elem);
710 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
712 _test_elem_type(line, (IUnknown*)elem, type);
714 IHTMLElement_Release(elem);
717 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
718 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
719 const elem_type_t *elem_types, long exlen)
721 long len;
722 DWORD i;
723 VARIANT name, index;
724 IDispatch *disp;
725 HRESULT hres;
727 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
729 hres = IHTMLElementCollection_get_length(col, &len);
730 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
731 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
733 if(len > exlen)
734 len = exlen;
736 V_VT(&index) = VT_EMPTY;
737 V_VT(&name) = VT_I4;
739 for(i=0; i<len; i++) {
740 V_I4(&name) = i;
741 disp = (void*)0xdeadbeef;
742 hres = IHTMLElementCollection_item(col, name, index, &disp);
743 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
744 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
745 if(FAILED(hres) || !disp)
746 continue;
748 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
749 IDispatch_Release(disp);
752 V_I4(&name) = len;
753 disp = (void*)0xdeadbeef;
754 hres = IHTMLElementCollection_item(col, name, index, &disp);
755 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
756 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
758 V_I4(&name) = -1;
759 disp = (void*)0xdeadbeef;
760 hres = IHTMLElementCollection_item(col, name, index, &disp);
761 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
762 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
765 #define get_first_child(n) _get_first_child(__LINE__,n)
766 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
768 IHTMLDOMNode *node, *child = NULL;
769 HRESULT hres;
771 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
772 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
773 if(FAILED(hres))
774 return NULL;
776 hres = IHTMLDOMNode_get_firstChild(node, &child);
777 IHTMLDOMNode_Release(node);
778 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
780 return child;
783 #define get_node_type(n) _get_node_type(__LINE__,n)
784 static long _get_node_type(unsigned line, IUnknown *unk)
786 IHTMLDOMNode *node;
787 long type = -1;
788 HRESULT hres;
790 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
791 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
793 hres = IHTMLDOMNode_get_nodeType(node, &type);
794 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
796 IHTMLDOMNode_Release(node);
798 return type;
801 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
802 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
804 VARIANT_BOOL disabled = 100;
805 HRESULT hres;
807 hres = IHTMLInputElement_get_disabled(input, &disabled);
808 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
809 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
812 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
813 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
815 IHTMLDOMChildrenCollection *col = NULL;
816 IHTMLDOMNode *node;
817 IDispatch *disp;
818 HRESULT hres;
820 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
821 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
822 if(FAILED(hres))
823 return NULL;
825 hres = IHTMLDOMNode_get_childNodes(node, &disp);
826 IHTMLDOMNode_Release(node);
827 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
828 if(FAILED(hres))
829 return NULL;
831 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
832 IDispatch_Release(disp);
833 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
835 return col;
838 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
839 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
841 IHTMLDOMNode *node = NULL;
842 IDispatch *disp;
843 HRESULT hres;
845 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
846 ok(hres == S_OK, "item failed: %08x\n", hres);
848 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMNode, (void**)&node);
849 IDispatch_Release(disp);
850 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
852 return node;
855 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
856 const elem_type_t *elem_types, long len)
858 IHTMLElementCollection *elcol;
859 IDispatch *disp;
860 VARIANT name, index;
861 DWORD i;
862 HRESULT hres;
864 V_VT(&index) = VT_EMPTY;
865 V_VT(&name) = VT_BSTR;
866 V_BSTR(&name) = SysAllocString(n);
868 hres = IHTMLElementCollection_item(col, name, index, &disp);
869 ok(hres == S_OK, "item failed: %08x\n", hres);
871 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
872 IDispatch_Release(disp);
873 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
874 test_elem_collection(elcol, elem_types, len);
875 IHTMLElementCollection_Release(elcol);
877 V_VT(&index) = VT_I4;
879 for(i=0; i<len; i++) {
880 V_I4(&index) = i;
881 disp = (void*)0xdeadbeef;
882 hres = IHTMLElementCollection_item(col, name, index, &disp);
883 ok(hres == S_OK, "item failed: %08x\n", hres);
884 ok(disp != NULL, "disp == NULL\n");
885 if(FAILED(hres) || !disp)
886 continue;
888 test_elem_type((IUnknown*)disp, elem_types[i]);
890 IDispatch_Release(disp);
893 V_I4(&index) = len;
894 disp = (void*)0xdeadbeef;
895 hres = IHTMLElementCollection_item(col, name, index, &disp);
896 ok(hres == S_OK, "item failed: %08x\n", hres);
897 ok(disp == NULL, "disp != NULL\n");
899 V_I4(&index) = -1;
900 disp = (void*)0xdeadbeef;
901 hres = IHTMLElementCollection_item(col, name, index, &disp);
902 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
903 ok(disp == NULL, "disp != NULL\n");
905 SysFreeString(V_BSTR(&name));
908 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
910 IHTMLElementCollection *col;
911 IHTMLElement *elem;
912 IDispatch *disp = (void*)0xdeadbeef;
913 VARIANT name, index;
914 HRESULT hres;
916 hres = IHTMLDocument2_get_all(doc, &col);
917 ok(hres == S_OK, "get_all failed: %08x\n", hres);
918 ok(col != NULL, "col == NULL\n");
919 if(FAILED(hres) || !col)
920 return NULL;
922 V_VT(&index) = VT_EMPTY;
923 V_VT(&name) = VT_BSTR;
924 V_BSTR(&name) = SysAllocString(id);
926 hres = IHTMLElementCollection_item(col, name, index, &disp);
927 IHTMLElementCollection_Release(col);
928 SysFreeString(V_BSTR(&name));
929 ok(hres == S_OK, "item failed: %08x\n", hres);
930 if(!expect_success) {
931 ok(disp == NULL, "disp != NULL\n");
932 return NULL;
935 ok(disp != NULL, "disp == NULL\n");
936 if(!disp)
937 return NULL;
939 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
940 IDispatch_Release(disp);
941 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
943 return elem;
946 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
948 IHTMLDocument3 *doc3;
949 IHTMLElement *elem;
950 BSTR tmp;
951 HRESULT hres;
953 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
954 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
956 tmp = SysAllocString(id);
957 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
958 SysFreeString(tmp);
959 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
961 IHTMLDocument3_Release(doc3);
963 return elem;
966 static void test_select_elem(IHTMLSelectElement *select)
968 test_select_length(select, 2);
969 test_select_selidx(select, 0);
970 test_select_put_selidx(select, 1);
973 static void test_create_option_elem(IHTMLDocument2 *doc)
975 IHTMLOptionElement *option;
977 option = create_option_elem(doc, "test text", "test value");
979 test_option_put_text(option, "new text");
980 test_option_put_value(option, "new value");
982 IHTMLOptionElement_Release(option);
985 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
987 IHTMLBodyElement *body;
988 IHTMLTxtRange *range;
989 IHTMLElement *elem;
990 HRESULT hres;
992 hres = IHTMLDocument2_get_body(doc, &elem);
993 ok(hres == S_OK, "get_body failed: %08x\n", hres);
995 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
996 IHTMLElement_Release(elem);
998 hres = IHTMLBodyElement_createTextRange(body, &range);
999 IHTMLBodyElement_Release(body);
1000 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1002 return range;
1005 static void test_txtrange(IHTMLDocument2 *doc)
1007 IHTMLTxtRange *body_range, *range, *range2;
1008 IHTMLSelectionObject *selection;
1009 IDispatch *disp_range;
1010 HRESULT hres;
1012 body_range = test_create_body_range(doc);
1014 test_range_text(body_range, "test abc 123\r\nit's text");
1016 hres = IHTMLTxtRange_duplicate(body_range, &range);
1017 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1019 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1020 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1021 test_range_isequal(range, range2, VARIANT_TRUE);
1023 test_range_text(range, "test abc 123\r\nit's text");
1024 test_range_text(body_range, "test abc 123\r\nit's text");
1026 test_range_collapse(range, TRUE);
1027 test_range_isequal(range, range2, VARIANT_FALSE);
1028 test_range_inrange(range, range2, VARIANT_FALSE);
1029 test_range_inrange(range2, range, VARIANT_TRUE);
1030 IHTMLTxtRange_Release(range2);
1032 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1033 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1034 test_range_move(range, characterW, 2, 2);
1035 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1037 test_range_collapse(range, FALSE);
1038 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1040 test_range_collapse(range, FALSE);
1041 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1042 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1043 test_range_move(range, characterW, 2, 2);
1044 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1045 test_range_moveend(range, characterW, -5, -5);
1046 test_range_text(range, NULL);
1047 test_range_moveend(range, characterW, 3, 3);
1048 test_range_text(range, "c 1");
1049 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1050 test_range_collapse(range, TRUE);
1051 test_range_move(range, characterW, 4, 4);
1052 test_range_moveend(range, characterW, 1, 1);
1053 test_range_text(range, " ");
1054 test_range_move(range, wordW, 1, 1);
1055 test_range_moveend(range, characterW, 2, 2);
1056 test_range_text(range, "ab");
1058 IHTMLTxtRange_Release(range);
1060 hres = IHTMLTxtRange_duplicate(body_range, &range);
1061 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1063 test_range_text(range, "test abc 123\r\nit's text");
1064 test_range_move(range, characterW, 3, 3);
1065 test_range_moveend(range, characterW, 1, 1);
1066 test_range_text(range, "t");
1067 test_range_moveend(range, characterW, 3, 3);
1068 test_range_text(range, "t ab");
1069 test_range_moveend(range, characterW, -2, -2);
1070 test_range_text(range, "t ");
1071 test_range_move(range, characterW, 6, 6);
1072 test_range_moveend(range, characterW, 3, 3);
1073 test_range_text(range, "123");
1074 test_range_moveend(range, characterW, 2, 2);
1075 test_range_text(range, "123\r\ni");
1077 IHTMLTxtRange_Release(range);
1079 hres = IHTMLTxtRange_duplicate(body_range, &range);
1080 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1082 test_range_move(range, wordW, 1, 1);
1083 test_range_moveend(range, characterW, 2, 2);
1084 test_range_text(range, "ab");
1086 test_range_move(range, characterW, -2, -2);
1087 test_range_moveend(range, characterW, 2, 2);
1088 test_range_text(range, "t ");
1090 test_range_move(range, wordW, 3, 3);
1091 test_range_move(range, wordW, -2, -2);
1092 test_range_moveend(range, characterW, 2, 2);
1093 test_range_text(range, "ab");
1095 test_range_move(range, characterW, -6, -5);
1096 test_range_moveend(range, characterW, -1, 0);
1097 test_range_moveend(range, characterW, -6, 0);
1098 test_range_move(range, characterW, 2, 2);
1099 test_range_moveend(range, characterW, 2, 2);
1100 test_range_text(range, "st");
1101 test_range_moveend(range, characterW, -6, -4);
1102 test_range_moveend(range, characterW, 2, 2);
1104 IHTMLTxtRange_Release(range);
1106 hres = IHTMLTxtRange_duplicate(body_range, &range);
1107 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1109 test_range_move(range, wordW, 2, 2);
1110 test_range_moveend(range, characterW, 2, 2);
1111 test_range_text(range, "12");
1113 test_range_move(range, characterW, 15, 14);
1114 test_range_move(range, characterW, -2, -2);
1115 test_range_moveend(range, characterW, 3, 2);
1116 test_range_text(range, "t");
1117 test_range_moveend(range, characterW, -1, -1);
1118 test_range_text(range, "t");
1119 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1120 test_range_move(range, characterW, -2, -2);
1121 test_range_moveend(range, characterW, 2, 2);
1122 test_range_text(range, "s ");
1123 test_range_move(range, characterW, 100, 7);
1124 test_range_move(range, wordW, 1, 0);
1125 test_range_move(range, characterW, -2, -2);
1126 test_range_moveend(range, characterW, 3, 2);
1127 test_range_text(range, "t");
1129 IHTMLTxtRange_Release(range);
1131 hres = IHTMLTxtRange_duplicate(body_range, &range);
1132 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1134 test_range_collapse(range, TRUE);
1135 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1136 test_range_put_text(range, "word");
1137 test_range_text(body_range, "wordabc 123\r\nit's text");
1138 test_range_text(range, NULL);
1139 test_range_moveend(range, characterW, 3, 3);
1140 test_range_text(range, "abc");
1141 test_range_movestart(range, characterW, -2, -2);
1142 test_range_text(range, "rdabc");
1143 test_range_movestart(range, characterW, 3, 3);
1144 test_range_text(range, "bc");
1145 test_range_movestart(range, characterW, 4, 4);
1146 test_range_text(range, NULL);
1147 test_range_movestart(range, characterW, -3, -3);
1148 test_range_text(range, "c 1");
1149 test_range_movestart(range, characterW, -7, -6);
1150 test_range_text(range, "wordabc 1");
1151 test_range_movestart(range, characterW, 100, 22);
1152 test_range_text(range, NULL);
1154 IHTMLTxtRange_Release(range);
1155 IHTMLTxtRange_Release(body_range);
1157 hres = IHTMLDocument2_get_selection(doc, &selection);
1158 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1160 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1161 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1162 IHTMLSelectionObject_Release(selection);
1164 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1165 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1166 IDispatch_Release(disp_range);
1168 test_range_text(range, NULL);
1169 test_range_moveend(range, characterW, 3, 3);
1170 test_range_text(range, "wor");
1171 test_range_parent(range, ET_BODY);
1172 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1173 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1174 test_range_move(range, characterW, 3, 3);
1175 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1176 test_range_moveend(range, characterW, -4, -4);
1177 test_range_put_text(range, "abc def ");
1178 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1179 test_range_move(range, wordW, 1, 1);
1180 test_range_movestart(range, characterW, -1, -1);
1181 test_range_text(range, " ");
1182 test_range_move(range, wordW, 1, 1);
1183 test_range_moveend(range, characterW, 3, 3);
1184 test_range_text(range, "def");
1185 test_range_put_text(range, "xyz");
1186 test_range_moveend(range, characterW, 1, 1);
1187 test_range_move(range, wordW, 1, 1);
1188 test_range_moveend(range, characterW, 2, 2);
1189 test_range_text(range, "ab");
1191 IHTMLTxtRange_Release(range);
1194 static void test_txtrange2(IHTMLDocument2 *doc)
1196 IHTMLTxtRange *range;
1198 range = test_create_body_range(doc);
1200 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1201 test_range_move(range, characterW, 5, 5);
1202 test_range_moveend(range, characterW, 1, 1);
1203 test_range_text(range, "2");
1204 test_range_move(range, characterW, -3, -3);
1205 test_range_moveend(range, characterW, 3, 3);
1206 test_range_text(range, "c\r\n\r\n1");
1207 test_range_collapse(range, VARIANT_FALSE);
1208 test_range_moveend(range, characterW, 4, 4);
1209 test_range_text(range, "23");
1210 test_range_moveend(range, characterW, 1, 1);
1211 test_range_text(range, "23\r\n\r\n\r\nd");
1212 test_range_moveend(range, characterW, -1, -1);
1213 test_range_text(range, "23");
1214 test_range_moveend(range, characterW, -1, -1);
1215 test_range_text(range, "23");
1216 test_range_moveend(range, characterW, -2, -2);
1217 test_range_text(range, "2");
1219 IHTMLTxtRange_Release(range);
1222 static void test_compatmode(IHTMLDocument2 *doc)
1224 IHTMLDocument5 *doc5;
1225 BSTR mode;
1226 HRESULT hres;
1228 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1229 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1230 if(FAILED(hres))
1231 return;
1233 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1234 IHTMLDocument5_Release(doc5);
1235 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1236 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1237 SysFreeString(mode);
1240 static void test_location(IHTMLDocument2 *doc)
1242 IHTMLLocation *location, *location2;
1243 ULONG ref;
1244 HRESULT hres;
1246 hres = IHTMLDocument2_get_location(doc, &location);
1247 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1249 hres = IHTMLDocument2_get_location(doc, &location2);
1250 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1252 ok(location == location2, "location != location2\n");
1254 test_ifaces((IUnknown*)location, location_iids);
1256 IHTMLLocation_Release(location2);
1257 ref = IHTMLLocation_Release(location);
1258 ok(!ref, "location chould be destroyed here\n");
1261 static void test_navigator(IHTMLDocument2 *doc)
1263 IHTMLWindow2 *window;
1264 IOmNavigator *navigator, *navigator2;
1265 ULONG ref;
1266 HRESULT hres;
1268 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1269 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1271 hres = IHTMLWindow2_get_navigator(window, &navigator);
1272 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1273 ok(navigator != NULL, "navigator == NULL\n");
1274 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1276 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1277 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1278 ok(navigator != navigator2, "navigator2 != navihgator\n");
1280 IHTMLWindow2_Release(window);
1281 IOmNavigator_Release(navigator2);
1282 ref = IOmNavigator_Release(navigator);
1283 ok(!ref, "navigator should be destroyed here\n");
1286 static void test_default_style(IHTMLStyle *style)
1288 VARIANT_BOOL b;
1289 VARIANT v;
1290 BSTR str;
1291 HRESULT hres;
1293 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
1295 str = (void*)0xdeadbeef;
1296 hres = IHTMLStyle_get_fontFamily(style, &str);
1297 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1298 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1300 str = (void*)0xdeadbeef;
1301 hres = IHTMLStyle_get_fontWeight(style, &str);
1302 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1303 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1305 str = (void*)0xdeadbeef;
1306 hres = IHTMLStyle_get_display(style, &str);
1307 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1308 ok(!str, "display = %s\n", dbgstr_w(str));
1310 str = (void*)0xdeadbeef;
1311 hres = IHTMLStyle_get_visibility(style, &str);
1312 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1313 ok(!str, "visibility = %s\n", dbgstr_w(str));
1315 V_VT(&v) = VT_NULL;
1316 hres = IHTMLStyle_get_fontSize(style, &v);
1317 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1318 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1319 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1321 V_VT(&v) = VT_NULL;
1322 hres = IHTMLStyle_get_color(style, &v);
1323 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1324 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1325 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1327 b = 0xfefe;
1328 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1329 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1330 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1332 b = 0xfefe;
1333 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1334 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1335 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1338 static void test_default_selection(IHTMLDocument2 *doc)
1340 IHTMLSelectionObject *selection;
1341 IHTMLTxtRange *range;
1342 IDispatch *disp;
1343 BSTR str;
1344 HRESULT hres;
1346 hres = IHTMLDocument2_get_selection(doc, &selection);
1347 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1349 hres = IHTMLSelectionObject_get_type(selection, &str);
1350 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1351 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1352 SysFreeString(str);
1354 hres = IHTMLSelectionObject_createRange(selection, &disp);
1355 IHTMLSelectionObject_Release(selection);
1356 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1358 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1359 IDispatch_Release(disp);
1360 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1362 test_range_text(range, NULL);
1363 IHTMLTxtRange_Release(range);
1366 static void test_default_body(IHTMLBodyElement *body)
1368 BSTR bstr;
1369 HRESULT hres;
1371 bstr = (void*)0xdeadbeef;
1372 hres = IHTMLBodyElement_get_background(body, &bstr);
1373 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1374 ok(bstr == NULL, "bstr != NULL\n");
1377 static void test_window(IHTMLDocument2 *doc)
1379 IHTMLWindow2 *window;
1380 IHTMLDocument2 *doc2 = NULL;
1381 HRESULT hres;
1383 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1384 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
1385 test_ifaces((IUnknown*)window, window_iids);
1386 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
1388 hres = IHTMLWindow2_get_document(window, &doc2);
1389 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1390 ok(doc2 != NULL, "doc2 == NULL\n");
1392 IHTMLDocument_Release(doc2);
1393 IHTMLWindow2_Release(window);
1396 static void test_defaults(IHTMLDocument2 *doc)
1398 IHTMLStyleSheetsCollection *stylesheetcol;
1399 IHTMLBodyElement *body;
1400 IHTMLElement *elem;
1401 IHTMLStyle *style;
1402 long l;
1403 HRESULT hres;
1405 hres = IHTMLDocument2_get_body(doc, &elem);
1406 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1408 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1409 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1410 test_default_body(body);
1411 IHTMLBodyElement_Release(body);
1413 hres = IHTMLElement_get_style(elem, &style);
1414 IHTMLElement_Release(elem);
1415 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1417 test_default_style(style);
1418 test_window(doc);
1419 test_compatmode(doc);
1420 test_location(doc);
1421 test_navigator(doc);
1423 IHTMLStyle_Release(style);
1425 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1426 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1428 l = 0xdeadbeef;
1429 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1430 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1431 ok(l == 0, "length = %ld\n", l);
1433 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1435 test_default_selection(doc);
1438 static void test_stylesheet(IDispatch *disp)
1440 IHTMLStyleSheetRulesCollection *col = NULL;
1441 IHTMLStyleSheet *stylesheet;
1442 HRESULT hres;
1444 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1445 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1447 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1448 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1449 ok(col != NULL, "col == NULL\n");
1451 IHTMLStyleSheetRulesCollection_Release(col);
1452 IHTMLStyleSheet_Release(stylesheet);
1455 static void test_stylesheets(IHTMLDocument2 *doc)
1457 IHTMLStyleSheetsCollection *col = NULL;
1458 VARIANT idx, res;
1459 long len = 0;
1460 HRESULT hres;
1462 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1463 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1464 ok(col != NULL, "col == NULL\n");
1466 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1467 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1468 ok(len == 1, "len=%ld\n", len);
1470 VariantInit(&res);
1471 V_VT(&idx) = VT_I4;
1472 V_I4(&idx) = 0;
1474 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1475 ok(hres == S_OK, "item failed: %08x\n", hres);
1476 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1477 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1478 test_stylesheet(V_DISPATCH(&res));
1479 VariantClear(&res);
1481 V_VT(&res) = VT_I4;
1482 V_VT(&idx) = VT_I4;
1483 V_I4(&idx) = 1;
1485 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1486 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1487 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1488 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1489 VariantClear(&res);
1491 IHTMLStyleSheetsCollection_Release(col);
1494 static void test_elems(IHTMLDocument2 *doc)
1496 IHTMLElementCollection *col;
1497 IHTMLDOMChildrenCollection *child_col;
1498 IHTMLElement *elem;
1499 IHTMLDOMNode *node, *node2;
1500 IDispatch *disp;
1501 long type;
1502 HRESULT hres;
1504 static const WCHAR inW[] = {'i','n',0};
1505 static const WCHAR xW[] = {'x',0};
1506 static const WCHAR sW[] = {'s',0};
1507 static const WCHAR scW[] = {'s','c',0};
1508 static const WCHAR xxxW[] = {'x','x','x',0};
1510 static const elem_type_t all_types[] = {
1511 ET_HTML,
1512 ET_HEAD,
1513 ET_TITLE,
1514 ET_STYLE,
1515 ET_BODY,
1516 ET_COMMENT,
1517 ET_A,
1518 ET_INPUT,
1519 ET_SELECT,
1520 ET_OPTION,
1521 ET_OPTION,
1522 ET_TEXTAREA,
1523 ET_TABLE,
1524 ET_TBODY,
1525 ET_SCRIPT,
1526 ET_TEST,
1529 static const elem_type_t item_types[] = {
1530 ET_A,
1531 ET_OPTION,
1532 ET_TEXTAREA
1535 hres = IHTMLDocument2_get_all(doc, &col);
1536 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1537 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1538 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1539 IHTMLElementCollection_Release(col);
1541 elem = get_doc_elem(doc);
1542 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1543 hres = IHTMLElement_get_all(elem, &disp);
1544 IHTMLElement_Release(elem);
1545 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1547 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1548 IDispatch_Release(disp);
1549 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1550 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1551 IHTMLElementCollection_Release(col);
1553 get_elem_by_id(doc, xxxW, FALSE);
1554 elem = get_doc_elem_by_id(doc, xxxW);
1555 ok(!elem, "elem != NULL\n");
1557 elem = get_doc_elem_by_id(doc, sW);
1558 ok(elem != NULL, "elem == NULL\n");
1559 if(elem) {
1560 test_elem_type((IUnknown*)elem, ET_SELECT);
1561 test_elem_attr(elem, xxxW, NULL);
1562 test_elem_attr(elem, idW, sW);
1563 IHTMLElement_Release(elem);
1566 elem = get_elem_by_id(doc, sW, TRUE);
1567 if(elem) {
1568 IHTMLSelectElement *select;
1570 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1571 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1573 test_select_elem(select);
1575 node = get_first_child((IUnknown*)select);
1576 ok(node != NULL, "node == NULL\n");
1577 if(node) {
1578 test_elem_type((IUnknown*)node, ET_OPTION);
1579 IHTMLDOMNode_Release(node);
1582 type = get_node_type((IUnknown*)select);
1583 ok(type == 1, "type=%ld\n", type);
1585 IHTMLSelectElement_Release(select);
1586 IHTMLElement_Release(elem);
1589 elem = get_elem_by_id(doc, scW, TRUE);
1590 if(elem) {
1591 IHTMLScriptElement *script;
1592 BSTR type;
1594 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1595 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1597 hres = IHTMLScriptElement_get_type(script, &type);
1598 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1599 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1600 SysFreeString(type);
1602 IHTMLScriptElement_Release(script);
1605 elem = get_elem_by_id(doc, inW, TRUE);
1606 if(elem) {
1607 IHTMLInputElement *input;
1609 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
1610 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1612 test_input_get_disabled(input, VARIANT_FALSE);
1614 IHTMLInputElement_Release(input);
1615 IHTMLElement_Release(elem);
1618 hres = IHTMLDocument2_get_body(doc, &elem);
1619 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1621 node = get_first_child((IUnknown*)elem);
1622 ok(node != NULL, "node == NULL\n");
1623 if(node) {
1624 test_ifaces((IUnknown*)node, text_iids);
1625 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
1627 node2 = get_first_child((IUnknown*)node);
1628 ok(!node2, "node2 != NULL\n");
1630 type = get_node_type((IUnknown*)node);
1631 ok(type == 3, "type=%ld\n", type);
1633 IHTMLDOMNode_Release(node);
1636 child_col = get_child_nodes((IUnknown*)elem);
1637 ok(child_col != NULL, "child_coll == NULL\n");
1638 if(child_col) {
1639 long length = 0;
1641 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
1643 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
1644 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1645 ok(length, "length=0\n");
1647 node = get_child_item(child_col, 0);
1648 ok(node != NULL, "node == NULL\n");
1649 if(node) {
1650 type = get_node_type((IUnknown*)node);
1651 ok(type == 3, "type=%ld\n", type);
1652 IHTMLDOMNode_Release(node);
1655 node = get_child_item(child_col, 1);
1656 ok(node != NULL, "node == NULL\n");
1657 if(node) {
1658 type = get_node_type((IUnknown*)node);
1659 ok(type == 8, "type=%ld\n", type);
1660 IHTMLDOMNode_Release(node);
1663 disp = (void*)0xdeadbeef;
1664 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
1665 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1666 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
1668 IHTMLDOMChildrenCollection_Release(child_col);
1671 IHTMLElement_Release(elem);
1673 test_stylesheets(doc);
1674 test_create_option_elem(doc);
1677 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1679 IOleCommandTarget *cmdtrg;
1680 HRESULT hres;
1682 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1683 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1685 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1686 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1688 IOleCommandTarget_Release(cmdtrg);
1691 static void test_indent(IHTMLDocument2 *doc)
1693 IHTMLElementCollection *col;
1694 IHTMLTxtRange *range;
1695 HRESULT hres;
1697 static const elem_type_t all_types[] = {
1698 ET_HTML,
1699 ET_HEAD,
1700 ET_TITLE,
1701 ET_BODY,
1702 ET_BR,
1703 ET_A,
1706 static const elem_type_t indent_types[] = {
1707 ET_HTML,
1708 ET_HEAD,
1709 ET_TITLE,
1710 ET_BODY,
1711 ET_BLOCKQUOTE,
1712 ET_P,
1713 ET_BR,
1714 ET_A,
1717 hres = IHTMLDocument2_get_all(doc, &col);
1718 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1719 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1720 IHTMLElementCollection_Release(col);
1722 range = test_create_body_range(doc);
1723 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1724 IHTMLTxtRange_Release(range);
1726 hres = IHTMLDocument2_get_all(doc, &col);
1727 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1728 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1729 IHTMLElementCollection_Release(col);
1732 static IHTMLDocument2 *notif_doc;
1733 static BOOL doc_complete;
1735 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1736 REFIID riid, void**ppv)
1738 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1739 *ppv = iface;
1740 return S_OK;
1743 ok(0, "unexpected call\n");
1744 return E_NOINTERFACE;
1747 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1749 return 2;
1752 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1754 return 1;
1757 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1759 if(dispID == DISPID_READYSTATE){
1760 BSTR state;
1761 HRESULT hres;
1763 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1765 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1766 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1768 if(!lstrcmpW(state, completeW))
1769 doc_complete = TRUE;
1771 SysFreeString(state);
1774 return S_OK;
1777 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1779 ok(0, "unexpected call\n");
1780 return E_NOTIMPL;
1783 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1784 PropertyNotifySink_QueryInterface,
1785 PropertyNotifySink_AddRef,
1786 PropertyNotifySink_Release,
1787 PropertyNotifySink_OnChanged,
1788 PropertyNotifySink_OnRequestEdit
1791 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1793 static IHTMLDocument2 *create_doc_with_string(const char *str)
1795 IPersistStreamInit *init;
1796 IStream *stream;
1797 IHTMLDocument2 *doc;
1798 HGLOBAL mem;
1799 SIZE_T len;
1801 notif_doc = doc = create_document();
1802 if(!doc)
1803 return NULL;
1805 doc_complete = FALSE;
1806 len = strlen(str);
1807 mem = GlobalAlloc(0, len);
1808 memcpy(mem, str, len);
1809 CreateStreamOnHGlobal(mem, TRUE, &stream);
1811 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1813 IPersistStreamInit_Load(init, stream);
1814 IPersistStreamInit_Release(init);
1815 IStream_Release(stream);
1817 return doc;
1820 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1822 IConnectionPointContainer *container;
1823 IConnectionPoint *cp;
1824 DWORD cookie;
1825 HRESULT hres;
1827 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1828 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1830 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1831 IConnectionPointContainer_Release(container);
1832 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1834 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1835 IConnectionPoint_Release(cp);
1836 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1839 typedef void (*domtest_t)(IHTMLDocument2*);
1841 static void run_domtest(const char *str, domtest_t test)
1843 IHTMLDocument2 *doc;
1844 IHTMLElement *body = NULL;
1845 ULONG ref;
1846 MSG msg;
1847 HRESULT hres;
1849 doc = create_doc_with_string(str);
1850 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1852 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1853 TranslateMessage(&msg);
1854 DispatchMessage(&msg);
1857 hres = IHTMLDocument2_get_body(doc, &body);
1858 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1860 if(body) {
1861 IHTMLElement_Release(body);
1862 test(doc);
1863 }else {
1864 skip("Could not get document body. Assuming no Gecko installed.\n");
1867 ref = IHTMLDocument2_Release(doc);
1868 ok(!ref, "ref = %d\n", ref);
1871 static void gecko_installer_workaround(BOOL disable)
1873 HKEY hkey;
1874 DWORD res;
1876 static BOOL has_url = FALSE;
1877 static char url[2048];
1879 if(!disable && !has_url)
1880 return;
1882 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1883 if(res != ERROR_SUCCESS)
1884 return;
1886 if(disable) {
1887 DWORD type, size = sizeof(url);
1889 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1890 if(res == ERROR_SUCCESS && type == REG_SZ)
1891 has_url = TRUE;
1893 RegDeleteValue(hkey, "GeckoUrl");
1894 }else {
1895 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1898 RegCloseKey(hkey);
1901 START_TEST(dom)
1903 gecko_installer_workaround(TRUE);
1904 CoInitialize(NULL);
1906 run_domtest(doc_str1, test_doc_elem);
1907 run_domtest(range_test_str, test_txtrange);
1908 run_domtest(range_test2_str, test_txtrange2);
1909 run_domtest(elem_test_str, test_elems);
1910 run_domtest(doc_blank, test_defaults);
1911 run_domtest(indent_test_str, test_indent);
1913 CoUninitialize();
1914 gecko_installer_workaround(FALSE);