mshtml: Stop test crash on error condition.
[wine/wine-gecko.git] / dlls / mshtml / tests / dom.c
blobad06e5bf264f33c104c85f726fee6fa41edd5ead
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 "<img /"
52 "</body></html>";
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};
66 typedef enum {
67 ET_NONE,
68 ET_HTML,
69 ET_HEAD,
70 ET_TITLE,
71 ET_BODY,
72 ET_A,
73 ET_INPUT,
74 ET_SELECT,
75 ET_TEXTAREA,
76 ET_OPTION,
77 ET_STYLE,
78 ET_BLOCKQUOTE,
79 ET_P,
80 ET_BR,
81 ET_TABLE,
82 ET_TBODY,
83 ET_SCRIPT,
84 ET_TEST,
85 ET_COMMENT,
86 ET_IMG
87 } elem_type_t;
89 static REFIID const none_iids[] = {
90 &IID_IUnknown,
91 NULL
94 static REFIID const elem_iids[] = {
95 &IID_IHTMLDOMNode,
96 &IID_IHTMLDOMNode2,
97 &IID_IHTMLElement,
98 &IID_IHTMLElement2,
99 &IID_IDispatchEx,
100 &IID_IConnectionPointContainer,
101 NULL
104 static REFIID const body_iids[] = {
105 &IID_IHTMLDOMNode,
106 &IID_IHTMLDOMNode2,
107 &IID_IHTMLElement,
108 &IID_IHTMLElement2,
109 &IID_IHTMLTextContainer,
110 &IID_IHTMLBodyElement,
111 &IID_IDispatchEx,
112 &IID_IConnectionPointContainer,
113 NULL
116 static REFIID const anchor_iids[] = {
117 &IID_IHTMLDOMNode,
118 &IID_IHTMLDOMNode2,
119 &IID_IHTMLElement,
120 &IID_IHTMLElement2,
121 &IID_IHTMLAnchorElement,
122 &IID_IDispatchEx,
123 &IID_IConnectionPointContainer,
124 NULL
127 static REFIID const input_iids[] = {
128 &IID_IHTMLDOMNode,
129 &IID_IHTMLDOMNode2,
130 &IID_IHTMLElement,
131 &IID_IHTMLElement2,
132 &IID_IHTMLInputElement,
133 &IID_IHTMLInputTextElement,
134 &IID_IDispatchEx,
135 &IID_IConnectionPointContainer,
136 NULL
139 static REFIID const select_iids[] = {
140 &IID_IHTMLDOMNode,
141 &IID_IHTMLDOMNode2,
142 &IID_IHTMLElement,
143 &IID_IHTMLElement2,
144 &IID_IHTMLSelectElement,
145 &IID_IDispatchEx,
146 &IID_IConnectionPointContainer,
147 NULL
150 static REFIID const textarea_iids[] = {
151 &IID_IHTMLDOMNode,
152 &IID_IHTMLDOMNode2,
153 &IID_IHTMLElement,
154 &IID_IHTMLElement2,
155 &IID_IHTMLTextAreaElement,
156 &IID_IDispatchEx,
157 &IID_IConnectionPointContainer,
158 NULL
161 static REFIID const option_iids[] = {
162 &IID_IHTMLDOMNode,
163 &IID_IHTMLDOMNode2,
164 &IID_IHTMLElement,
165 &IID_IHTMLElement2,
166 &IID_IHTMLOptionElement,
167 &IID_IDispatchEx,
168 &IID_IConnectionPointContainer,
169 NULL
172 static REFIID const table_iids[] = {
173 &IID_IHTMLDOMNode,
174 &IID_IHTMLDOMNode2,
175 &IID_IHTMLElement,
176 &IID_IHTMLElement2,
177 &IID_IHTMLTable,
178 &IID_IDispatchEx,
179 &IID_IConnectionPointContainer,
180 NULL
183 static REFIID const script_iids[] = {
184 &IID_IHTMLDOMNode,
185 &IID_IHTMLDOMNode2,
186 &IID_IHTMLElement,
187 &IID_IHTMLElement2,
188 &IID_IHTMLScriptElement,
189 &IID_IDispatchEx,
190 &IID_IConnectionPointContainer,
191 NULL
194 static REFIID const text_iids[] = {
195 &IID_IHTMLDOMNode,
196 &IID_IHTMLDOMNode2,
197 &IID_IHTMLDOMTextNode,
198 NULL
201 static REFIID const location_iids[] = {
202 &IID_IDispatch,
203 &IID_IHTMLLocation,
204 NULL
207 static REFIID const window_iids[] = {
208 &IID_IDispatch,
209 &IID_IHTMLWindow2,
210 &IID_IHTMLWindow3,
211 &IID_IDispatchEx,
212 NULL
215 static REFIID const comment_iids[] = {
216 &IID_IHTMLDOMNode,
217 &IID_IHTMLDOMNode2,
218 &IID_IHTMLElement,
219 &IID_IHTMLElement2,
220 &IID_IHTMLCommentElement,
221 &IID_IDispatchEx,
222 &IID_IConnectionPointContainer,
223 NULL
226 static REFIID const img_iids[] = {
227 &IID_IHTMLDOMNode,
228 &IID_IHTMLDOMNode2,
229 &IID_IHTMLElement,
230 &IID_IHTMLElement2,
231 &IID_IDispatchEx,
232 &IID_IHTMLImgElement,
233 &IID_IConnectionPointContainer,
234 NULL
237 typedef struct {
238 const char *tag;
239 REFIID *iids;
240 const IID *dispiid;
241 } elem_type_info_t;
243 static const elem_type_info_t elem_type_infos[] = {
244 {"", none_iids, NULL},
245 {"HTML", elem_iids, NULL},
246 {"HEAD", elem_iids, NULL},
247 {"TITLE", elem_iids, NULL},
248 {"BODY", body_iids, NULL},
249 {"A", anchor_iids, NULL},
250 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
251 {"SELECT", select_iids, NULL},
252 {"TEXTAREA", textarea_iids, NULL},
253 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
254 {"STYLE", elem_iids, NULL},
255 {"BLOCKQUOTE",elem_iids, NULL},
256 {"P", elem_iids, NULL},
257 {"BR", elem_iids, NULL},
258 {"TABLE", table_iids, NULL},
259 {"TBODY", elem_iids, NULL},
260 {"SCRIPT", script_iids, NULL},
261 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
262 {"!", comment_iids, &DIID_DispHTMLCommentElement},
263 {"IMG", img_iids, &DIID_DispHTMLImg}
266 static const char *dbgstr_w(LPCWSTR str)
268 static char buf[512];
269 if(!str)
270 return "(null)";
271 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
272 return buf;
275 static const char *dbgstr_guid(REFIID riid)
277 static char buf[50];
279 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
280 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
281 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
282 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
284 return buf;
287 static int strcmp_wa(LPCWSTR strw, const char *stra)
289 WCHAR buf[512];
290 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
291 return lstrcmpW(strw, buf);
294 static BSTR a2bstr(const char *str)
296 BSTR ret;
297 int len;
299 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
300 ret = SysAllocStringLen(NULL, len);
301 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
303 return ret;
306 static IHTMLDocument2 *create_document(void)
308 IHTMLDocument2 *doc;
309 HRESULT hres;
311 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
312 &IID_IHTMLDocument2, (void**)&doc);
313 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
315 return doc;
318 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
319 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
321 const IID * const *piid;
322 IUnknown *unk;
323 HRESULT hres;
325 for(piid = iids; *piid; piid++) {
326 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
327 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
328 if(SUCCEEDED(hres))
329 IUnknown_Release(unk);
333 #define test_disp(u,id) _test_disp(__LINE__,u,id)
334 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
336 IDispatchEx *dispex;
337 ITypeInfo *typeinfo;
338 UINT ticnt;
339 HRESULT hres;
341 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
342 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
343 if(FAILED(hres))
344 return;
346 ticnt = 0xdeadbeef;
347 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
348 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
349 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
351 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
352 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
354 if(SUCCEEDED(hres)) {
355 TYPEATTR *type_attr;
357 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
358 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
359 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
361 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
362 ITypeInfo_Release(typeinfo);
365 IDispatchEx_Release(dispex);
368 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
369 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
371 IHTMLDOMNode *node;
372 BSTR name;
373 HRESULT hres;
375 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
376 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
378 hres = IHTMLDOMNode_get_nodeName(node, &name);
379 IHTMLDOMNode_Release(node);
380 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
381 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
383 SysFreeString(name);
386 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
387 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
389 IHTMLElement *elem;
390 BSTR tag;
391 HRESULT hres;
393 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
394 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
396 hres = IHTMLElement_get_tagName(elem, &tag);
397 IHTMLElement_Release(elem);
398 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
399 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
401 SysFreeString(tag);
404 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
405 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
407 _test_elem_tag(line, unk, elem_type_infos[type].tag);
408 _test_ifaces(line, unk, elem_type_infos[type].iids);
410 if(elem_type_infos[type].dispiid)
411 _test_disp(line, unk, elem_type_infos[type].dispiid);
414 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
415 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
417 VARIANT value;
418 BSTR tmp;
419 HRESULT hres;
421 VariantInit(&value);
423 tmp = SysAllocString(name);
424 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
425 SysFreeString(tmp);
426 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
428 if(exval) {
429 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
430 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
431 }else {
432 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
435 VariantClear(&value);
438 static void test_doc_elem(IHTMLDocument2 *doc)
440 IHTMLElement *elem;
441 IHTMLDocument3 *doc3;
442 HRESULT hres;
444 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
445 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
447 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
448 IHTMLDocument3_Release(doc3);
449 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
451 test_node_name((IUnknown*)elem, "HTML");
452 test_elem_tag((IUnknown*)elem, "HTML");
454 IHTMLElement_Release(elem);
457 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
458 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
460 IHTMLElement *elem;
461 IHTMLDocument3 *doc3;
462 HRESULT hres;
464 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
465 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
466 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
467 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
468 IHTMLDocument3_Release(doc3);
470 return elem;
473 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
474 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
476 BSTR bstr;
477 HRESULT hres;
479 hres = IHTMLOptionElement_get_text(option, &bstr);
480 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
481 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
482 SysFreeString(bstr);
485 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
486 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
488 BSTR bstr;
489 HRESULT hres;
491 bstr = a2bstr(text);
492 hres = IHTMLOptionElement_put_text(option, bstr);
493 SysFreeString(bstr);
494 ok(hres == S_OK, "put_text failed: %08x\n", hres);
496 _test_option_text(line, option, text);
499 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
500 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
502 BSTR bstr;
503 HRESULT hres;
505 hres = IHTMLOptionElement_get_value(option, &bstr);
506 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
507 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
508 SysFreeString(bstr);
511 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
512 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
514 BSTR bstr;
515 HRESULT hres;
517 bstr = a2bstr(value);
518 hres = IHTMLOptionElement_put_value(option, bstr);
519 SysFreeString(bstr);
520 ok(hres == S_OK, "put_value failed: %08x\n", hres);
522 _test_option_value(line, option, value);
525 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
526 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
527 const char *txt, const char *val)
529 IHTMLOptionElementFactory *factory;
530 IHTMLOptionElement *option;
531 IHTMLWindow2 *window;
532 VARIANT text, value, empty;
533 HRESULT hres;
535 hres = IHTMLDocument2_get_parentWindow(doc, &window);
536 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
538 hres = IHTMLWindow2_get_Option(window, &factory);
539 IHTMLWindow2_Release(window);
540 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
542 V_VT(&text) = VT_BSTR;
543 V_BSTR(&text) = a2bstr(txt);
544 V_VT(&value) = VT_BSTR;
545 V_BSTR(&value) = a2bstr(val);
546 V_VT(&empty) = VT_EMPTY;
548 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
549 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
551 IHTMLOptionElementFactory_Release(factory);
552 VariantClear(&text);
553 VariantClear(&value);
555 _test_option_text(line, option, txt);
556 _test_option_value(line, option, val);
558 return option;
561 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
562 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
564 long len = 0xdeadbeef;
565 HRESULT hres;
567 hres = IHTMLSelectElement_get_length(select, &len);
568 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
569 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
572 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
573 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
575 long idx = 0xdeadbeef;
576 HRESULT hres;
578 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
579 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
580 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
583 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
584 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
586 HRESULT hres;
588 hres = IHTMLSelectElement_put_selectedIndex(select, index);
589 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
590 _test_select_selidx(line, select, index);
593 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
594 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
596 BSTR text;
597 HRESULT hres;
599 hres = IHTMLTxtRange_get_text(range, &text);
600 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
602 if(extext) {
603 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
604 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
605 }else {
606 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
609 SysFreeString(text);
613 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
614 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
616 HRESULT hres;
618 hres = IHTMLTxtRange_collapse(range, b);
619 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
620 _test_range_text(line, range, NULL);
623 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
624 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
625 VARIANT_BOOL exb, const char *extext)
627 VARIANT_BOOL b = 0xe0e0;
628 HRESULT hres;
630 hres = IHTMLTxtRange_expand(range, unit, &b);
631 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
632 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
633 _test_range_text(line, range, extext);
636 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
637 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
639 long c = 0xdeadbeef;
640 HRESULT hres;
642 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
643 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
644 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
645 _test_range_text(line, range, NULL);
648 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
649 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
650 LPWSTR unit, long cnt, long excnt)
652 long c = 0xdeadbeef;
653 HRESULT hres;
655 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
656 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
657 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
660 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
661 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
663 long c = 0xdeadbeef;
664 HRESULT hres;
666 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
667 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
668 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
671 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
672 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
674 HRESULT hres;
675 BSTR bstr = a2bstr(text);
677 hres = IHTMLTxtRange_put_text(range, bstr);
678 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
679 SysFreeString(bstr);
680 _test_range_text(line, range, NULL);
683 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
684 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
686 VARIANT_BOOL b;
687 HRESULT hres;
689 b = 0xe0e0;
690 hres = IHTMLTxtRange_inRange(range1, range2, &b);
691 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
692 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
695 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
696 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
698 VARIANT_BOOL b;
699 HRESULT hres;
701 b = 0xe0e0;
702 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
703 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
704 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
706 b = 0xe0e0;
707 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
708 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
709 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
711 if(exb) {
712 test_range_inrange(range1, range2, VARIANT_TRUE);
713 test_range_inrange(range2, range1, VARIANT_TRUE);
717 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
718 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
720 IHTMLElement *elem;
721 HRESULT hres;
723 hres = IHTMLTxtRange_parentElement(range, &elem);
724 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
726 _test_elem_type(line, (IUnknown*)elem, type);
728 IHTMLElement_Release(elem);
731 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
732 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
733 const elem_type_t *elem_types, long exlen)
735 long len;
736 DWORD i;
737 VARIANT name, index;
738 IDispatch *disp;
739 HRESULT hres;
741 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
743 hres = IHTMLElementCollection_get_length(col, &len);
744 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
745 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
747 if(len > exlen)
748 len = exlen;
750 V_VT(&index) = VT_EMPTY;
751 V_VT(&name) = VT_I4;
753 for(i=0; i<len; i++) {
754 V_I4(&name) = i;
755 disp = (void*)0xdeadbeef;
756 hres = IHTMLElementCollection_item(col, name, index, &disp);
757 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
758 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
759 if(FAILED(hres) || !disp)
760 continue;
762 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
763 IDispatch_Release(disp);
766 V_I4(&name) = len;
767 disp = (void*)0xdeadbeef;
768 hres = IHTMLElementCollection_item(col, name, index, &disp);
769 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
770 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
772 V_I4(&name) = -1;
773 disp = (void*)0xdeadbeef;
774 hres = IHTMLElementCollection_item(col, name, index, &disp);
775 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
776 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
779 #define get_first_child(n) _get_first_child(__LINE__,n)
780 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
782 IHTMLDOMNode *node, *child = NULL;
783 HRESULT hres;
785 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
786 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
787 if(FAILED(hres))
788 return NULL;
790 hres = IHTMLDOMNode_get_firstChild(node, &child);
791 IHTMLDOMNode_Release(node);
792 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
794 return child;
797 #define get_node_type(n) _get_node_type(__LINE__,n)
798 static long _get_node_type(unsigned line, IUnknown *unk)
800 IHTMLDOMNode *node;
801 long type = -1;
802 HRESULT hres;
804 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
805 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
807 hres = IHTMLDOMNode_get_nodeType(node, &type);
808 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
810 IHTMLDOMNode_Release(node);
812 return type;
815 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
816 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
818 VARIANT_BOOL disabled = 100;
819 HRESULT hres;
821 hres = IHTMLInputElement_get_disabled(input, &disabled);
822 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
823 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
826 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
827 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
829 IHTMLDOMChildrenCollection *col = NULL;
830 IHTMLDOMNode *node;
831 IDispatch *disp;
832 HRESULT hres;
834 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
835 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
836 if(FAILED(hres))
837 return NULL;
839 hres = IHTMLDOMNode_get_childNodes(node, &disp);
840 IHTMLDOMNode_Release(node);
841 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
842 if(FAILED(hres))
843 return NULL;
845 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
846 IDispatch_Release(disp);
847 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
849 return col;
852 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
853 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
855 IHTMLDOMNode *node = NULL;
856 IDispatch *disp;
857 HRESULT hres;
859 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
860 ok(hres == S_OK, "item failed: %08x\n", hres);
862 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMNode, (void**)&node);
863 IDispatch_Release(disp);
864 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
866 return node;
869 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
870 const elem_type_t *elem_types, long len)
872 IHTMLElementCollection *elcol;
873 IDispatch *disp;
874 VARIANT name, index;
875 DWORD i;
876 HRESULT hres;
878 V_VT(&index) = VT_EMPTY;
879 V_VT(&name) = VT_BSTR;
880 V_BSTR(&name) = SysAllocString(n);
882 hres = IHTMLElementCollection_item(col, name, index, &disp);
883 ok(hres == S_OK, "item failed: %08x\n", hres);
885 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
886 IDispatch_Release(disp);
887 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
888 if(hres != S_OK)
889 goto cleanup;
891 test_elem_collection(elcol, elem_types, len);
892 IHTMLElementCollection_Release(elcol);
894 V_VT(&index) = VT_I4;
896 for(i=0; i<len; i++) {
897 V_I4(&index) = i;
898 disp = (void*)0xdeadbeef;
899 hres = IHTMLElementCollection_item(col, name, index, &disp);
900 ok(hres == S_OK, "item failed: %08x\n", hres);
901 ok(disp != NULL, "disp == NULL\n");
902 if(FAILED(hres) || !disp)
903 continue;
905 test_elem_type((IUnknown*)disp, elem_types[i]);
907 IDispatch_Release(disp);
910 V_I4(&index) = len;
911 disp = (void*)0xdeadbeef;
912 hres = IHTMLElementCollection_item(col, name, index, &disp);
913 ok(hres == S_OK, "item failed: %08x\n", hres);
914 ok(disp == NULL, "disp != NULL\n");
916 V_I4(&index) = -1;
917 disp = (void*)0xdeadbeef;
918 hres = IHTMLElementCollection_item(col, name, index, &disp);
919 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
920 ok(disp == NULL, "disp != NULL\n");
922 cleanup:
923 SysFreeString(V_BSTR(&name));
926 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
928 IHTMLElementCollection *col;
929 IHTMLElement *elem;
930 IDispatch *disp = (void*)0xdeadbeef;
931 VARIANT name, index;
932 HRESULT hres;
934 hres = IHTMLDocument2_get_all(doc, &col);
935 ok(hres == S_OK, "get_all failed: %08x\n", hres);
936 ok(col != NULL, "col == NULL\n");
937 if(FAILED(hres) || !col)
938 return NULL;
940 V_VT(&index) = VT_EMPTY;
941 V_VT(&name) = VT_BSTR;
942 V_BSTR(&name) = SysAllocString(id);
944 hres = IHTMLElementCollection_item(col, name, index, &disp);
945 IHTMLElementCollection_Release(col);
946 SysFreeString(V_BSTR(&name));
947 ok(hres == S_OK, "item failed: %08x\n", hres);
948 if(!expect_success) {
949 ok(disp == NULL, "disp != NULL\n");
950 return NULL;
953 ok(disp != NULL, "disp == NULL\n");
954 if(!disp)
955 return NULL;
957 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
958 IDispatch_Release(disp);
959 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
961 return elem;
964 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
966 IHTMLDocument3 *doc3;
967 IHTMLElement *elem;
968 BSTR tmp;
969 HRESULT hres;
971 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
972 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
974 tmp = SysAllocString(id);
975 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
976 SysFreeString(tmp);
977 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
979 IHTMLDocument3_Release(doc3);
981 return elem;
984 static void test_select_elem(IHTMLSelectElement *select)
986 test_select_length(select, 2);
987 test_select_selidx(select, 0);
988 test_select_put_selidx(select, 1);
991 static void test_create_option_elem(IHTMLDocument2 *doc)
993 IHTMLOptionElement *option;
995 option = create_option_elem(doc, "test text", "test value");
997 test_option_put_text(option, "new text");
998 test_option_put_value(option, "new value");
1000 IHTMLOptionElement_Release(option);
1003 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1005 IHTMLBodyElement *body;
1006 IHTMLTxtRange *range;
1007 IHTMLElement *elem;
1008 HRESULT hres;
1010 hres = IHTMLDocument2_get_body(doc, &elem);
1011 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1013 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1014 IHTMLElement_Release(elem);
1016 hres = IHTMLBodyElement_createTextRange(body, &range);
1017 IHTMLBodyElement_Release(body);
1018 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1020 return range;
1023 static void test_txtrange(IHTMLDocument2 *doc)
1025 IHTMLTxtRange *body_range, *range, *range2;
1026 IHTMLSelectionObject *selection;
1027 IDispatch *disp_range;
1028 HRESULT hres;
1030 body_range = test_create_body_range(doc);
1032 test_range_text(body_range, "test abc 123\r\nit's text");
1034 hres = IHTMLTxtRange_duplicate(body_range, &range);
1035 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1037 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1038 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1039 test_range_isequal(range, range2, VARIANT_TRUE);
1041 test_range_text(range, "test abc 123\r\nit's text");
1042 test_range_text(body_range, "test abc 123\r\nit's text");
1044 test_range_collapse(range, TRUE);
1045 test_range_isequal(range, range2, VARIANT_FALSE);
1046 test_range_inrange(range, range2, VARIANT_FALSE);
1047 test_range_inrange(range2, range, VARIANT_TRUE);
1048 IHTMLTxtRange_Release(range2);
1050 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1051 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1052 test_range_move(range, characterW, 2, 2);
1053 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1055 test_range_collapse(range, FALSE);
1056 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1058 test_range_collapse(range, FALSE);
1059 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1060 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1061 test_range_move(range, characterW, 2, 2);
1062 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1063 test_range_moveend(range, characterW, -5, -5);
1064 test_range_text(range, NULL);
1065 test_range_moveend(range, characterW, 3, 3);
1066 test_range_text(range, "c 1");
1067 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1068 test_range_collapse(range, TRUE);
1069 test_range_move(range, characterW, 4, 4);
1070 test_range_moveend(range, characterW, 1, 1);
1071 test_range_text(range, " ");
1072 test_range_move(range, wordW, 1, 1);
1073 test_range_moveend(range, characterW, 2, 2);
1074 test_range_text(range, "ab");
1076 IHTMLTxtRange_Release(range);
1078 hres = IHTMLTxtRange_duplicate(body_range, &range);
1079 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1081 test_range_text(range, "test abc 123\r\nit's text");
1082 test_range_move(range, characterW, 3, 3);
1083 test_range_moveend(range, characterW, 1, 1);
1084 test_range_text(range, "t");
1085 test_range_moveend(range, characterW, 3, 3);
1086 test_range_text(range, "t ab");
1087 test_range_moveend(range, characterW, -2, -2);
1088 test_range_text(range, "t ");
1089 test_range_move(range, characterW, 6, 6);
1090 test_range_moveend(range, characterW, 3, 3);
1091 test_range_text(range, "123");
1092 test_range_moveend(range, characterW, 2, 2);
1093 test_range_text(range, "123\r\ni");
1095 IHTMLTxtRange_Release(range);
1097 hres = IHTMLTxtRange_duplicate(body_range, &range);
1098 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1100 test_range_move(range, wordW, 1, 1);
1101 test_range_moveend(range, characterW, 2, 2);
1102 test_range_text(range, "ab");
1104 test_range_move(range, characterW, -2, -2);
1105 test_range_moveend(range, characterW, 2, 2);
1106 test_range_text(range, "t ");
1108 test_range_move(range, wordW, 3, 3);
1109 test_range_move(range, wordW, -2, -2);
1110 test_range_moveend(range, characterW, 2, 2);
1111 test_range_text(range, "ab");
1113 test_range_move(range, characterW, -6, -5);
1114 test_range_moveend(range, characterW, -1, 0);
1115 test_range_moveend(range, characterW, -6, 0);
1116 test_range_move(range, characterW, 2, 2);
1117 test_range_moveend(range, characterW, 2, 2);
1118 test_range_text(range, "st");
1119 test_range_moveend(range, characterW, -6, -4);
1120 test_range_moveend(range, characterW, 2, 2);
1122 IHTMLTxtRange_Release(range);
1124 hres = IHTMLTxtRange_duplicate(body_range, &range);
1125 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1127 test_range_move(range, wordW, 2, 2);
1128 test_range_moveend(range, characterW, 2, 2);
1129 test_range_text(range, "12");
1131 test_range_move(range, characterW, 15, 14);
1132 test_range_move(range, characterW, -2, -2);
1133 test_range_moveend(range, characterW, 3, 2);
1134 test_range_text(range, "t");
1135 test_range_moveend(range, characterW, -1, -1);
1136 test_range_text(range, "t");
1137 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1138 test_range_move(range, characterW, -2, -2);
1139 test_range_moveend(range, characterW, 2, 2);
1140 test_range_text(range, "s ");
1141 test_range_move(range, characterW, 100, 7);
1142 test_range_move(range, wordW, 1, 0);
1143 test_range_move(range, characterW, -2, -2);
1144 test_range_moveend(range, characterW, 3, 2);
1145 test_range_text(range, "t");
1147 IHTMLTxtRange_Release(range);
1149 hres = IHTMLTxtRange_duplicate(body_range, &range);
1150 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1152 test_range_collapse(range, TRUE);
1153 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1154 test_range_put_text(range, "word");
1155 test_range_text(body_range, "wordabc 123\r\nit's text");
1156 test_range_text(range, NULL);
1157 test_range_moveend(range, characterW, 3, 3);
1158 test_range_text(range, "abc");
1159 test_range_movestart(range, characterW, -2, -2);
1160 test_range_text(range, "rdabc");
1161 test_range_movestart(range, characterW, 3, 3);
1162 test_range_text(range, "bc");
1163 test_range_movestart(range, characterW, 4, 4);
1164 test_range_text(range, NULL);
1165 test_range_movestart(range, characterW, -3, -3);
1166 test_range_text(range, "c 1");
1167 test_range_movestart(range, characterW, -7, -6);
1168 test_range_text(range, "wordabc 1");
1169 test_range_movestart(range, characterW, 100, 22);
1170 test_range_text(range, NULL);
1172 IHTMLTxtRange_Release(range);
1173 IHTMLTxtRange_Release(body_range);
1175 hres = IHTMLDocument2_get_selection(doc, &selection);
1176 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1178 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1179 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1180 IHTMLSelectionObject_Release(selection);
1182 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1183 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1184 IDispatch_Release(disp_range);
1186 test_range_text(range, NULL);
1187 test_range_moveend(range, characterW, 3, 3);
1188 test_range_text(range, "wor");
1189 test_range_parent(range, ET_BODY);
1190 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1191 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1192 test_range_move(range, characterW, 3, 3);
1193 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1194 test_range_moveend(range, characterW, -4, -4);
1195 test_range_put_text(range, "abc def ");
1196 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1197 test_range_move(range, wordW, 1, 1);
1198 test_range_movestart(range, characterW, -1, -1);
1199 test_range_text(range, " ");
1200 test_range_move(range, wordW, 1, 1);
1201 test_range_moveend(range, characterW, 3, 3);
1202 test_range_text(range, "def");
1203 test_range_put_text(range, "xyz");
1204 test_range_moveend(range, characterW, 1, 1);
1205 test_range_move(range, wordW, 1, 1);
1206 test_range_moveend(range, characterW, 2, 2);
1207 test_range_text(range, "ab");
1209 IHTMLTxtRange_Release(range);
1212 static void test_txtrange2(IHTMLDocument2 *doc)
1214 IHTMLTxtRange *range;
1216 range = test_create_body_range(doc);
1218 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1219 test_range_move(range, characterW, 5, 5);
1220 test_range_moveend(range, characterW, 1, 1);
1221 test_range_text(range, "2");
1222 test_range_move(range, characterW, -3, -3);
1223 test_range_moveend(range, characterW, 3, 3);
1224 test_range_text(range, "c\r\n\r\n1");
1225 test_range_collapse(range, VARIANT_FALSE);
1226 test_range_moveend(range, characterW, 4, 4);
1227 test_range_text(range, "23");
1228 test_range_moveend(range, characterW, 1, 1);
1229 test_range_text(range, "23\r\n\r\n\r\nd");
1230 test_range_moveend(range, characterW, -1, -1);
1231 test_range_text(range, "23");
1232 test_range_moveend(range, characterW, -1, -1);
1233 test_range_text(range, "23");
1234 test_range_moveend(range, characterW, -2, -2);
1235 test_range_text(range, "2");
1237 IHTMLTxtRange_Release(range);
1240 static void test_compatmode(IHTMLDocument2 *doc)
1242 IHTMLDocument5 *doc5;
1243 BSTR mode;
1244 HRESULT hres;
1246 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1247 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1248 if(FAILED(hres))
1249 return;
1251 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1252 IHTMLDocument5_Release(doc5);
1253 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1254 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1255 SysFreeString(mode);
1258 static void test_location(IHTMLDocument2 *doc)
1260 IHTMLLocation *location, *location2;
1261 ULONG ref;
1262 HRESULT hres;
1264 hres = IHTMLDocument2_get_location(doc, &location);
1265 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1267 hres = IHTMLDocument2_get_location(doc, &location2);
1268 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1270 ok(location == location2, "location != location2\n");
1272 test_ifaces((IUnknown*)location, location_iids);
1274 IHTMLLocation_Release(location2);
1275 ref = IHTMLLocation_Release(location);
1276 ok(!ref, "location chould be destroyed here\n");
1279 static void test_navigator(IHTMLDocument2 *doc)
1281 IHTMLWindow2 *window;
1282 IOmNavigator *navigator, *navigator2;
1283 ULONG ref;
1284 HRESULT hres;
1286 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1287 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1289 hres = IHTMLWindow2_get_navigator(window, &navigator);
1290 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1291 ok(navigator != NULL, "navigator == NULL\n");
1292 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1294 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1295 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1296 ok(navigator != navigator2, "navigator2 != navihgator\n");
1298 IHTMLWindow2_Release(window);
1299 IOmNavigator_Release(navigator2);
1300 ref = IOmNavigator_Release(navigator);
1301 ok(!ref, "navigator should be destroyed here\n");
1304 static void test_default_style(IHTMLStyle *style)
1306 VARIANT_BOOL b;
1307 VARIANT v;
1308 BSTR str;
1309 HRESULT hres;
1311 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
1313 str = (void*)0xdeadbeef;
1314 hres = IHTMLStyle_get_fontFamily(style, &str);
1315 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1316 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1318 str = (void*)0xdeadbeef;
1319 hres = IHTMLStyle_get_fontWeight(style, &str);
1320 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1321 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1323 str = (void*)0xdeadbeef;
1324 hres = IHTMLStyle_get_display(style, &str);
1325 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1326 ok(!str, "display = %s\n", dbgstr_w(str));
1328 str = (void*)0xdeadbeef;
1329 hres = IHTMLStyle_get_visibility(style, &str);
1330 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1331 ok(!str, "visibility = %s\n", dbgstr_w(str));
1333 V_VT(&v) = VT_NULL;
1334 hres = IHTMLStyle_get_fontSize(style, &v);
1335 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1336 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1337 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1339 V_VT(&v) = VT_NULL;
1340 hres = IHTMLStyle_get_color(style, &v);
1341 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1342 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1343 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1345 b = 0xfefe;
1346 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1347 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1348 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1350 b = 0xfefe;
1351 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1352 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1353 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1356 static void test_default_selection(IHTMLDocument2 *doc)
1358 IHTMLSelectionObject *selection;
1359 IHTMLTxtRange *range;
1360 IDispatch *disp;
1361 BSTR str;
1362 HRESULT hres;
1364 hres = IHTMLDocument2_get_selection(doc, &selection);
1365 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1367 hres = IHTMLSelectionObject_get_type(selection, &str);
1368 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1369 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1370 SysFreeString(str);
1372 hres = IHTMLSelectionObject_createRange(selection, &disp);
1373 IHTMLSelectionObject_Release(selection);
1374 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1376 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1377 IDispatch_Release(disp);
1378 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1380 test_range_text(range, NULL);
1381 IHTMLTxtRange_Release(range);
1384 static void test_default_body(IHTMLBodyElement *body)
1386 BSTR bstr;
1387 HRESULT hres;
1389 bstr = (void*)0xdeadbeef;
1390 hres = IHTMLBodyElement_get_background(body, &bstr);
1391 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1392 ok(bstr == NULL, "bstr != NULL\n");
1395 static void test_window(IHTMLDocument2 *doc)
1397 IHTMLWindow2 *window;
1398 IHTMLDocument2 *doc2 = NULL;
1399 HRESULT hres;
1401 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1402 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
1403 test_ifaces((IUnknown*)window, window_iids);
1404 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
1406 hres = IHTMLWindow2_get_document(window, &doc2);
1407 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1408 ok(doc2 != NULL, "doc2 == NULL\n");
1410 IHTMLDocument_Release(doc2);
1411 IHTMLWindow2_Release(window);
1414 static void test_defaults(IHTMLDocument2 *doc)
1416 IHTMLStyleSheetsCollection *stylesheetcol;
1417 IHTMLBodyElement *body;
1418 IHTMLElement *elem;
1419 IHTMLStyle *style;
1420 long l;
1421 HRESULT hres;
1423 hres = IHTMLDocument2_get_body(doc, &elem);
1424 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1426 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1427 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1428 test_default_body(body);
1429 IHTMLBodyElement_Release(body);
1431 hres = IHTMLElement_get_style(elem, &style);
1432 IHTMLElement_Release(elem);
1433 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1435 test_default_style(style);
1436 test_window(doc);
1437 test_compatmode(doc);
1438 test_location(doc);
1439 test_navigator(doc);
1441 IHTMLStyle_Release(style);
1443 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1444 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1446 l = 0xdeadbeef;
1447 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1448 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1449 ok(l == 0, "length = %ld\n", l);
1451 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1453 test_default_selection(doc);
1456 static void test_stylesheet(IDispatch *disp)
1458 IHTMLStyleSheetRulesCollection *col = NULL;
1459 IHTMLStyleSheet *stylesheet;
1460 HRESULT hres;
1462 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1463 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1465 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1466 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1467 ok(col != NULL, "col == NULL\n");
1469 IHTMLStyleSheetRulesCollection_Release(col);
1470 IHTMLStyleSheet_Release(stylesheet);
1473 static void test_stylesheets(IHTMLDocument2 *doc)
1475 IHTMLStyleSheetsCollection *col = NULL;
1476 VARIANT idx, res;
1477 long len = 0;
1478 HRESULT hres;
1480 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1481 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1482 ok(col != NULL, "col == NULL\n");
1484 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1485 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1486 ok(len == 1, "len=%ld\n", len);
1488 VariantInit(&res);
1489 V_VT(&idx) = VT_I4;
1490 V_I4(&idx) = 0;
1492 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1493 ok(hres == S_OK, "item failed: %08x\n", hres);
1494 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1495 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1496 test_stylesheet(V_DISPATCH(&res));
1497 VariantClear(&res);
1499 V_VT(&res) = VT_I4;
1500 V_VT(&idx) = VT_I4;
1501 V_I4(&idx) = 1;
1503 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1504 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1505 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1506 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1507 VariantClear(&res);
1509 IHTMLStyleSheetsCollection_Release(col);
1512 static void test_elems(IHTMLDocument2 *doc)
1514 IHTMLElementCollection *col;
1515 IHTMLDOMChildrenCollection *child_col;
1516 IHTMLElement *elem;
1517 IHTMLDOMNode *node, *node2;
1518 IDispatch *disp;
1519 long type;
1520 HRESULT hres;
1522 static const WCHAR inW[] = {'i','n',0};
1523 static const WCHAR xW[] = {'x',0};
1524 static const WCHAR sW[] = {'s',0};
1525 static const WCHAR scW[] = {'s','c',0};
1526 static const WCHAR xxxW[] = {'x','x','x',0};
1528 static const elem_type_t all_types[] = {
1529 ET_HTML,
1530 ET_HEAD,
1531 ET_TITLE,
1532 ET_STYLE,
1533 ET_BODY,
1534 ET_COMMENT,
1535 ET_A,
1536 ET_INPUT,
1537 ET_SELECT,
1538 ET_OPTION,
1539 ET_OPTION,
1540 ET_TEXTAREA,
1541 ET_TABLE,
1542 ET_TBODY,
1543 ET_SCRIPT,
1544 ET_TEST,
1545 ET_IMG
1548 static const elem_type_t item_types[] = {
1549 ET_A,
1550 ET_OPTION,
1551 ET_TEXTAREA
1554 hres = IHTMLDocument2_get_all(doc, &col);
1555 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1556 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1557 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1558 IHTMLElementCollection_Release(col);
1560 elem = get_doc_elem(doc);
1561 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1562 hres = IHTMLElement_get_all(elem, &disp);
1563 IHTMLElement_Release(elem);
1564 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1566 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1567 IDispatch_Release(disp);
1568 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1569 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1570 IHTMLElementCollection_Release(col);
1572 get_elem_by_id(doc, xxxW, FALSE);
1573 elem = get_doc_elem_by_id(doc, xxxW);
1574 ok(!elem, "elem != NULL\n");
1576 elem = get_doc_elem_by_id(doc, sW);
1577 ok(elem != NULL, "elem == NULL\n");
1578 if(elem) {
1579 test_elem_type((IUnknown*)elem, ET_SELECT);
1580 test_elem_attr(elem, xxxW, NULL);
1581 test_elem_attr(elem, idW, sW);
1582 IHTMLElement_Release(elem);
1585 elem = get_elem_by_id(doc, sW, TRUE);
1586 if(elem) {
1587 IHTMLSelectElement *select;
1589 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1590 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1592 test_select_elem(select);
1594 node = get_first_child((IUnknown*)select);
1595 ok(node != NULL, "node == NULL\n");
1596 if(node) {
1597 test_elem_type((IUnknown*)node, ET_OPTION);
1598 IHTMLDOMNode_Release(node);
1601 type = get_node_type((IUnknown*)select);
1602 ok(type == 1, "type=%ld\n", type);
1604 IHTMLSelectElement_Release(select);
1605 IHTMLElement_Release(elem);
1608 elem = get_elem_by_id(doc, scW, TRUE);
1609 if(elem) {
1610 IHTMLScriptElement *script;
1611 BSTR type;
1613 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1614 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1616 hres = IHTMLScriptElement_get_type(script, &type);
1617 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1618 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1619 SysFreeString(type);
1621 IHTMLScriptElement_Release(script);
1624 elem = get_elem_by_id(doc, inW, TRUE);
1625 if(elem) {
1626 IHTMLInputElement *input;
1628 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
1629 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1631 test_input_get_disabled(input, VARIANT_FALSE);
1633 IHTMLInputElement_Release(input);
1634 IHTMLElement_Release(elem);
1637 hres = IHTMLDocument2_get_body(doc, &elem);
1638 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1640 node = get_first_child((IUnknown*)elem);
1641 ok(node != NULL, "node == NULL\n");
1642 if(node) {
1643 test_ifaces((IUnknown*)node, text_iids);
1644 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
1646 node2 = get_first_child((IUnknown*)node);
1647 ok(!node2, "node2 != NULL\n");
1649 type = get_node_type((IUnknown*)node);
1650 ok(type == 3, "type=%ld\n", type);
1652 IHTMLDOMNode_Release(node);
1655 child_col = get_child_nodes((IUnknown*)elem);
1656 ok(child_col != NULL, "child_coll == NULL\n");
1657 if(child_col) {
1658 long length = 0;
1660 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
1662 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
1663 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1664 ok(length, "length=0\n");
1666 node = get_child_item(child_col, 0);
1667 ok(node != NULL, "node == NULL\n");
1668 if(node) {
1669 type = get_node_type((IUnknown*)node);
1670 ok(type == 3, "type=%ld\n", type);
1671 IHTMLDOMNode_Release(node);
1674 node = get_child_item(child_col, 1);
1675 ok(node != NULL, "node == NULL\n");
1676 if(node) {
1677 type = get_node_type((IUnknown*)node);
1678 ok(type == 8, "type=%ld\n", type);
1679 IHTMLDOMNode_Release(node);
1682 disp = (void*)0xdeadbeef;
1683 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
1684 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1685 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
1687 IHTMLDOMChildrenCollection_Release(child_col);
1690 IHTMLElement_Release(elem);
1692 test_stylesheets(doc);
1693 test_create_option_elem(doc);
1696 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1698 IOleCommandTarget *cmdtrg;
1699 HRESULT hres;
1701 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1702 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1704 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1705 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1707 IOleCommandTarget_Release(cmdtrg);
1710 static void test_indent(IHTMLDocument2 *doc)
1712 IHTMLElementCollection *col;
1713 IHTMLTxtRange *range;
1714 HRESULT hres;
1716 static const elem_type_t all_types[] = {
1717 ET_HTML,
1718 ET_HEAD,
1719 ET_TITLE,
1720 ET_BODY,
1721 ET_BR,
1722 ET_A,
1725 static const elem_type_t indent_types[] = {
1726 ET_HTML,
1727 ET_HEAD,
1728 ET_TITLE,
1729 ET_BODY,
1730 ET_BLOCKQUOTE,
1731 ET_P,
1732 ET_BR,
1733 ET_A,
1736 hres = IHTMLDocument2_get_all(doc, &col);
1737 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1738 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1739 IHTMLElementCollection_Release(col);
1741 range = test_create_body_range(doc);
1742 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1743 IHTMLTxtRange_Release(range);
1745 hres = IHTMLDocument2_get_all(doc, &col);
1746 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1747 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1748 IHTMLElementCollection_Release(col);
1751 static IHTMLDocument2 *notif_doc;
1752 static BOOL doc_complete;
1754 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1755 REFIID riid, void**ppv)
1757 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1758 *ppv = iface;
1759 return S_OK;
1762 ok(0, "unexpected call\n");
1763 return E_NOINTERFACE;
1766 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1768 return 2;
1771 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1773 return 1;
1776 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1778 if(dispID == DISPID_READYSTATE){
1779 BSTR state;
1780 HRESULT hres;
1782 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1784 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1785 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1787 if(!lstrcmpW(state, completeW))
1788 doc_complete = TRUE;
1790 SysFreeString(state);
1793 return S_OK;
1796 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1798 ok(0, "unexpected call\n");
1799 return E_NOTIMPL;
1802 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1803 PropertyNotifySink_QueryInterface,
1804 PropertyNotifySink_AddRef,
1805 PropertyNotifySink_Release,
1806 PropertyNotifySink_OnChanged,
1807 PropertyNotifySink_OnRequestEdit
1810 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1812 static IHTMLDocument2 *create_doc_with_string(const char *str)
1814 IPersistStreamInit *init;
1815 IStream *stream;
1816 IHTMLDocument2 *doc;
1817 HGLOBAL mem;
1818 SIZE_T len;
1820 notif_doc = doc = create_document();
1821 if(!doc)
1822 return NULL;
1824 doc_complete = FALSE;
1825 len = strlen(str);
1826 mem = GlobalAlloc(0, len);
1827 memcpy(mem, str, len);
1828 CreateStreamOnHGlobal(mem, TRUE, &stream);
1830 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1832 IPersistStreamInit_Load(init, stream);
1833 IPersistStreamInit_Release(init);
1834 IStream_Release(stream);
1836 return doc;
1839 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1841 IConnectionPointContainer *container;
1842 IConnectionPoint *cp;
1843 DWORD cookie;
1844 HRESULT hres;
1846 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1847 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1849 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1850 IConnectionPointContainer_Release(container);
1851 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1853 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1854 IConnectionPoint_Release(cp);
1855 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1858 typedef void (*domtest_t)(IHTMLDocument2*);
1860 static void run_domtest(const char *str, domtest_t test)
1862 IHTMLDocument2 *doc;
1863 IHTMLElement *body = NULL;
1864 ULONG ref;
1865 MSG msg;
1866 HRESULT hres;
1868 doc = create_doc_with_string(str);
1869 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1871 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1872 TranslateMessage(&msg);
1873 DispatchMessage(&msg);
1876 hres = IHTMLDocument2_get_body(doc, &body);
1877 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1879 if(body) {
1880 IHTMLElement_Release(body);
1881 test(doc);
1882 }else {
1883 skip("Could not get document body. Assuming no Gecko installed.\n");
1886 ref = IHTMLDocument2_Release(doc);
1887 ok(!ref, "ref = %d\n", ref);
1890 static void gecko_installer_workaround(BOOL disable)
1892 HKEY hkey;
1893 DWORD res;
1895 static BOOL has_url = FALSE;
1896 static char url[2048];
1898 if(!disable && !has_url)
1899 return;
1901 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1902 if(res != ERROR_SUCCESS)
1903 return;
1905 if(disable) {
1906 DWORD type, size = sizeof(url);
1908 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1909 if(res == ERROR_SUCCESS && type == REG_SZ)
1910 has_url = TRUE;
1912 RegDeleteValue(hkey, "GeckoUrl");
1913 }else {
1914 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1917 RegCloseKey(hkey);
1920 START_TEST(dom)
1922 gecko_installer_workaround(TRUE);
1923 CoInitialize(NULL);
1925 run_domtest(doc_str1, test_doc_elem);
1926 run_domtest(range_test_str, test_txtrange);
1927 run_domtest(range_test2_str, test_txtrange2);
1928 run_domtest(elem_test_str, test_elems);
1929 run_domtest(doc_blank, test_defaults);
1930 run_domtest(indent_test_str, test_indent);
1932 CoUninitialize();
1933 gecko_installer_workaround(FALSE);