mshtml: Added IHTMLImgElement::put_src implementation.
[wine/gsoc_dplay.git] / dlls / mshtml / tests / dom.c
blob6ff42010a85beeb28b7b2827a3b19f6cda21d581
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\" class=\"testclass\"/>"
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 id=\"imgid\"/>"
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_TESTG,
86 ET_COMMENT,
87 ET_IMG
88 } elem_type_t;
90 static REFIID const none_iids[] = {
91 &IID_IUnknown,
92 NULL
95 static REFIID const elem_iids[] = {
96 &IID_IHTMLDOMNode,
97 &IID_IHTMLDOMNode2,
98 &IID_IHTMLElement,
99 &IID_IHTMLElement2,
100 &IID_IDispatchEx,
101 &IID_IConnectionPointContainer,
102 NULL
105 static REFIID const body_iids[] = {
106 &IID_IHTMLDOMNode,
107 &IID_IHTMLDOMNode2,
108 &IID_IHTMLElement,
109 &IID_IHTMLElement2,
110 &IID_IHTMLTextContainer,
111 &IID_IHTMLBodyElement,
112 &IID_IDispatchEx,
113 &IID_IConnectionPointContainer,
114 NULL
117 static REFIID const anchor_iids[] = {
118 &IID_IHTMLDOMNode,
119 &IID_IHTMLDOMNode2,
120 &IID_IHTMLElement,
121 &IID_IHTMLElement2,
122 &IID_IHTMLAnchorElement,
123 &IID_IDispatchEx,
124 &IID_IConnectionPointContainer,
125 NULL
128 static REFIID const input_iids[] = {
129 &IID_IHTMLDOMNode,
130 &IID_IHTMLDOMNode2,
131 &IID_IHTMLElement,
132 &IID_IHTMLElement2,
133 &IID_IHTMLInputElement,
134 &IID_IHTMLInputTextElement,
135 &IID_IDispatchEx,
136 &IID_IConnectionPointContainer,
137 NULL
140 static REFIID const select_iids[] = {
141 &IID_IHTMLDOMNode,
142 &IID_IHTMLDOMNode2,
143 &IID_IHTMLElement,
144 &IID_IHTMLElement2,
145 &IID_IHTMLSelectElement,
146 &IID_IDispatchEx,
147 &IID_IConnectionPointContainer,
148 NULL
151 static REFIID const textarea_iids[] = {
152 &IID_IHTMLDOMNode,
153 &IID_IHTMLDOMNode2,
154 &IID_IHTMLElement,
155 &IID_IHTMLElement2,
156 &IID_IHTMLTextAreaElement,
157 &IID_IDispatchEx,
158 &IID_IConnectionPointContainer,
159 NULL
162 static REFIID const option_iids[] = {
163 &IID_IHTMLDOMNode,
164 &IID_IHTMLDOMNode2,
165 &IID_IHTMLElement,
166 &IID_IHTMLElement2,
167 &IID_IHTMLOptionElement,
168 &IID_IDispatchEx,
169 &IID_IConnectionPointContainer,
170 NULL
173 static REFIID const table_iids[] = {
174 &IID_IHTMLDOMNode,
175 &IID_IHTMLDOMNode2,
176 &IID_IHTMLElement,
177 &IID_IHTMLElement2,
178 &IID_IHTMLTable,
179 &IID_IDispatchEx,
180 &IID_IConnectionPointContainer,
181 NULL
184 static REFIID const script_iids[] = {
185 &IID_IHTMLDOMNode,
186 &IID_IHTMLDOMNode2,
187 &IID_IHTMLElement,
188 &IID_IHTMLElement2,
189 &IID_IHTMLScriptElement,
190 &IID_IDispatchEx,
191 &IID_IConnectionPointContainer,
192 NULL
195 static REFIID const text_iids[] = {
196 &IID_IHTMLDOMNode,
197 &IID_IHTMLDOMNode2,
198 &IID_IHTMLDOMTextNode,
199 NULL
202 static REFIID const location_iids[] = {
203 &IID_IDispatch,
204 &IID_IHTMLLocation,
205 NULL
208 static REFIID const window_iids[] = {
209 &IID_IDispatch,
210 &IID_IHTMLWindow2,
211 &IID_IHTMLWindow3,
212 &IID_IDispatchEx,
213 NULL
216 static REFIID const comment_iids[] = {
217 &IID_IHTMLDOMNode,
218 &IID_IHTMLDOMNode2,
219 &IID_IHTMLElement,
220 &IID_IHTMLElement2,
221 &IID_IHTMLCommentElement,
222 &IID_IDispatchEx,
223 &IID_IConnectionPointContainer,
224 NULL
227 static REFIID const img_iids[] = {
228 &IID_IHTMLDOMNode,
229 &IID_IHTMLDOMNode2,
230 &IID_IHTMLElement,
231 &IID_IHTMLElement2,
232 &IID_IDispatchEx,
233 &IID_IHTMLImgElement,
234 &IID_IConnectionPointContainer,
235 NULL
238 static REFIID const generic_iids[] = {
239 &IID_IHTMLDOMNode,
240 &IID_IHTMLDOMNode2,
241 &IID_IHTMLElement,
242 &IID_IHTMLElement2,
243 &IID_IHTMLGenericElement,
244 &IID_IDispatchEx,
245 &IID_IConnectionPointContainer,
246 NULL
249 typedef struct {
250 const char *tag;
251 REFIID *iids;
252 const IID *dispiid;
253 } elem_type_info_t;
255 static const elem_type_info_t elem_type_infos[] = {
256 {"", none_iids, NULL},
257 {"HTML", elem_iids, NULL},
258 {"HEAD", elem_iids, NULL},
259 {"TITLE", elem_iids, NULL},
260 {"BODY", body_iids, NULL},
261 {"A", anchor_iids, NULL},
262 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
263 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
264 {"TEXTAREA", textarea_iids, NULL},
265 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
266 {"STYLE", elem_iids, NULL},
267 {"BLOCKQUOTE",elem_iids, NULL},
268 {"P", elem_iids, NULL},
269 {"BR", elem_iids, NULL},
270 {"TABLE", table_iids, NULL},
271 {"TBODY", elem_iids, NULL},
272 {"SCRIPT", script_iids, NULL},
273 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
274 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
275 {"!", comment_iids, &DIID_DispHTMLCommentElement},
276 {"IMG", img_iids, &DIID_DispHTMLImg}
279 static const char *dbgstr_w(LPCWSTR str)
281 static char buf[512];
282 if(!str)
283 return "(null)";
284 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
285 return buf;
288 static const char *dbgstr_guid(REFIID riid)
290 static char buf[50];
292 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
293 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
294 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
295 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
297 return buf;
300 static int strcmp_wa(LPCWSTR strw, const char *stra)
302 WCHAR buf[512];
303 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
304 return lstrcmpW(strw, buf);
307 static BSTR a2bstr(const char *str)
309 BSTR ret;
310 int len;
312 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
313 ret = SysAllocStringLen(NULL, len);
314 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
316 return ret;
319 static IHTMLDocument2 *create_document(void)
321 IHTMLDocument2 *doc;
322 HRESULT hres;
324 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
325 &IID_IHTMLDocument2, (void**)&doc);
326 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
328 return doc;
331 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
332 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
334 const IID * const *piid;
335 IUnknown *unk;
336 HRESULT hres;
338 for(piid = iids; *piid; piid++) {
339 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
340 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
341 if(SUCCEEDED(hres))
342 IUnknown_Release(unk);
346 #define test_disp(u,id) _test_disp(__LINE__,u,id)
347 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
349 IDispatchEx *dispex;
350 ITypeInfo *typeinfo;
351 UINT ticnt;
352 HRESULT hres;
354 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
355 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
356 if(FAILED(hres))
357 return;
359 ticnt = 0xdeadbeef;
360 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
361 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
362 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
364 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
365 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
367 if(SUCCEEDED(hres)) {
368 TYPEATTR *type_attr;
370 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
371 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
372 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
374 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
375 ITypeInfo_Release(typeinfo);
378 IDispatchEx_Release(dispex);
381 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
382 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
384 IHTMLElement *elem;
385 HRESULT hres;
387 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
388 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
389 return elem;
392 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
393 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
395 IHTMLElement2 *elem;
396 HRESULT hres;
398 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
399 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
400 return elem;
403 #define get_node_iface(u) _get_node_iface(__LINE__,u)
404 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
406 IHTMLDOMNode *node;
407 HRESULT hres;
409 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
410 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
411 return node;
414 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
415 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
417 IHTMLDOMNode *node = _get_node_iface(line, unk);
418 BSTR name;
419 HRESULT hres;
421 hres = IHTMLDOMNode_get_nodeName(node, &name);
422 IHTMLDOMNode_Release(node);
423 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
424 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
426 SysFreeString(name);
429 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
430 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
432 IHTMLElement *elem = _get_elem_iface(line, unk);
433 BSTR tag;
434 HRESULT hres;
436 hres = IHTMLElement_get_tagName(elem, &tag);
437 IHTMLElement_Release(elem);
438 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
439 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
441 SysFreeString(tag);
444 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
445 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
447 _test_elem_tag(line, unk, elem_type_infos[type].tag);
448 _test_ifaces(line, unk, elem_type_infos[type].iids);
450 if(elem_type_infos[type].dispiid)
451 _test_disp(line, unk, elem_type_infos[type].dispiid);
454 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
455 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
457 VARIANT value;
458 BSTR tmp;
459 HRESULT hres;
461 VariantInit(&value);
463 tmp = SysAllocString(name);
464 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
465 SysFreeString(tmp);
466 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
468 if(exval) {
469 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
470 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
471 }else {
472 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
475 VariantClear(&value);
478 static void test_doc_elem(IHTMLDocument2 *doc)
480 IHTMLElement *elem;
481 IHTMLDocument3 *doc3;
482 HRESULT hres;
484 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
485 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
487 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
488 IHTMLDocument3_Release(doc3);
489 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
491 test_node_name((IUnknown*)elem, "HTML");
492 test_elem_tag((IUnknown*)elem, "HTML");
494 IHTMLElement_Release(elem);
497 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
498 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
500 IHTMLElement *elem;
501 IHTMLDocument3 *doc3;
502 HRESULT hres;
504 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
505 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
506 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
507 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
508 IHTMLDocument3_Release(doc3);
510 return elem;
513 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
514 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
516 BSTR bstr;
517 HRESULT hres;
519 hres = IHTMLOptionElement_get_text(option, &bstr);
520 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
521 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
522 SysFreeString(bstr);
525 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
526 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
528 BSTR bstr;
529 HRESULT hres;
531 bstr = a2bstr(text);
532 hres = IHTMLOptionElement_put_text(option, bstr);
533 SysFreeString(bstr);
534 ok(hres == S_OK, "put_text failed: %08x\n", hres);
536 _test_option_text(line, option, text);
539 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
540 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
542 BSTR bstr;
543 HRESULT hres;
545 hres = IHTMLOptionElement_get_value(option, &bstr);
546 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
547 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
548 SysFreeString(bstr);
551 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
552 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
554 BSTR bstr;
555 HRESULT hres;
557 bstr = a2bstr(value);
558 hres = IHTMLOptionElement_put_value(option, bstr);
559 SysFreeString(bstr);
560 ok(hres == S_OK, "put_value failed: %08x\n", hres);
562 _test_option_value(line, option, value);
565 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
566 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
567 const char *txt, const char *val)
569 IHTMLOptionElementFactory *factory;
570 IHTMLOptionElement *option;
571 IHTMLWindow2 *window;
572 VARIANT text, value, empty;
573 HRESULT hres;
575 hres = IHTMLDocument2_get_parentWindow(doc, &window);
576 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
578 hres = IHTMLWindow2_get_Option(window, &factory);
579 IHTMLWindow2_Release(window);
580 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
582 V_VT(&text) = VT_BSTR;
583 V_BSTR(&text) = a2bstr(txt);
584 V_VT(&value) = VT_BSTR;
585 V_BSTR(&value) = a2bstr(val);
586 V_VT(&empty) = VT_EMPTY;
588 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
589 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
591 IHTMLOptionElementFactory_Release(factory);
592 VariantClear(&text);
593 VariantClear(&value);
595 _test_option_text(line, option, txt);
596 _test_option_value(line, option, val);
598 return option;
601 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
602 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
604 long len = 0xdeadbeef;
605 HRESULT hres;
607 hres = IHTMLSelectElement_get_length(select, &len);
608 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
609 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
612 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
613 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
615 long idx = 0xdeadbeef;
616 HRESULT hres;
618 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
619 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
620 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
623 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
624 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
626 HRESULT hres;
628 hres = IHTMLSelectElement_put_selectedIndex(select, index);
629 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
630 _test_select_selidx(line, select, index);
633 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
634 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
636 BSTR text;
637 HRESULT hres;
639 hres = IHTMLTxtRange_get_text(range, &text);
640 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
642 if(extext) {
643 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
644 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
645 }else {
646 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
649 SysFreeString(text);
653 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
654 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
656 HRESULT hres;
658 hres = IHTMLTxtRange_collapse(range, b);
659 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
660 _test_range_text(line, range, NULL);
663 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
664 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
665 VARIANT_BOOL exb, const char *extext)
667 VARIANT_BOOL b = 0xe0e0;
668 HRESULT hres;
670 hres = IHTMLTxtRange_expand(range, unit, &b);
671 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
672 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
673 _test_range_text(line, range, extext);
676 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
677 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
679 long c = 0xdeadbeef;
680 HRESULT hres;
682 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
683 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
684 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
685 _test_range_text(line, range, NULL);
688 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
689 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
690 LPWSTR unit, long cnt, long excnt)
692 long c = 0xdeadbeef;
693 HRESULT hres;
695 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
696 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
697 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
700 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
701 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
703 long c = 0xdeadbeef;
704 HRESULT hres;
706 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
707 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
708 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
711 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
712 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
714 HRESULT hres;
715 BSTR bstr = a2bstr(text);
717 hres = IHTMLTxtRange_put_text(range, bstr);
718 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
719 SysFreeString(bstr);
720 _test_range_text(line, range, NULL);
723 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
724 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
726 VARIANT_BOOL b;
727 HRESULT hres;
729 b = 0xe0e0;
730 hres = IHTMLTxtRange_inRange(range1, range2, &b);
731 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
732 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
735 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
736 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
738 VARIANT_BOOL b;
739 HRESULT hres;
741 b = 0xe0e0;
742 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
743 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
744 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
746 b = 0xe0e0;
747 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
748 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
749 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
751 if(exb) {
752 test_range_inrange(range1, range2, VARIANT_TRUE);
753 test_range_inrange(range2, range1, VARIANT_TRUE);
757 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
758 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
760 IHTMLElement *elem;
761 HRESULT hres;
763 hres = IHTMLTxtRange_parentElement(range, &elem);
764 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
766 _test_elem_type(line, (IUnknown*)elem, type);
768 IHTMLElement_Release(elem);
771 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
772 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
773 const elem_type_t *elem_types, long exlen)
775 long len;
776 DWORD i;
777 VARIANT name, index;
778 IDispatch *disp;
779 HRESULT hres;
781 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
783 hres = IHTMLElementCollection_get_length(col, &len);
784 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
785 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
787 if(len > exlen)
788 len = exlen;
790 V_VT(&index) = VT_EMPTY;
791 V_VT(&name) = VT_I4;
793 for(i=0; i<len; i++) {
794 V_I4(&name) = i;
795 disp = (void*)0xdeadbeef;
796 hres = IHTMLElementCollection_item(col, name, index, &disp);
797 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
798 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
799 if(FAILED(hres) || !disp)
800 continue;
802 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
803 IDispatch_Release(disp);
806 V_I4(&name) = len;
807 disp = (void*)0xdeadbeef;
808 hres = IHTMLElementCollection_item(col, name, index, &disp);
809 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
810 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
812 V_I4(&name) = -1;
813 disp = (void*)0xdeadbeef;
814 hres = IHTMLElementCollection_item(col, name, index, &disp);
815 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
816 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
819 #define get_first_child(n) _get_first_child(__LINE__,n)
820 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
822 IHTMLDOMNode *node = _get_node_iface(line, unk);
823 IHTMLDOMNode *child = NULL;
824 HRESULT hres;
826 hres = IHTMLDOMNode_get_firstChild(node, &child);
827 IHTMLDOMNode_Release(node);
828 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
830 return child;
833 #define get_node_type(n) _get_node_type(__LINE__,n)
834 static long _get_node_type(unsigned line, IUnknown *unk)
836 IHTMLDOMNode *node = _get_node_iface(line, unk);
837 long type = -1;
838 HRESULT hres;
840 hres = IHTMLDOMNode_get_nodeType(node, &type);
841 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
843 IHTMLDOMNode_Release(node);
845 return type;
848 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
849 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
851 IHTMLImgElement *img;
852 BSTR tmp;
853 HRESULT hres;
855 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
856 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
858 tmp = a2bstr(src);
859 hres = IHTMLImgElement_put_src(img, tmp);
860 IHTMLImgElement_Release(img);
861 SysFreeString(tmp);
862 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
865 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
866 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
868 VARIANT_BOOL disabled = 100;
869 HRESULT hres;
871 hres = IHTMLInputElement_get_disabled(input, &disabled);
872 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
873 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
876 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
877 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
879 IHTMLInputElement *input;
880 BSTR bstr;
881 HRESULT hres;
883 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
884 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
885 if(FAILED(hres))
886 return;
888 hres = IHTMLInputElement_get_value(input, &bstr);
889 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
890 if(exval)
891 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
892 else
893 ok_(__FILE__,line) (!exval, "exval != NULL\n");
894 SysFreeString(bstr);
895 IHTMLInputElement_Release(input);
898 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
899 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
901 IHTMLInputElement *input;
902 BSTR bstr;
903 HRESULT hres;
905 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
906 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
907 if(FAILED(hres))
908 return;
910 bstr = a2bstr(val);
911 hres = IHTMLInputElement_get_value(input, &bstr);
912 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
913 SysFreeString(bstr);
914 IHTMLInputElement_Release(input);
917 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
918 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
920 IHTMLDOMNode *node = _get_node_iface(line, unk);
921 IHTMLDOMChildrenCollection *col = NULL;
922 IDispatch *disp;
923 HRESULT hres;
925 hres = IHTMLDOMNode_get_childNodes(node, &disp);
926 IHTMLDOMNode_Release(node);
927 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
928 if(FAILED(hres))
929 return NULL;
931 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
932 IDispatch_Release(disp);
933 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
935 return col;
938 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
939 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
941 IHTMLElement *elem = _get_elem_iface(line, unk);
942 BSTR class = (void*)0xdeadbeef;
943 HRESULT hres;
945 hres = IHTMLElement_get_className(elem, &class);
946 IHTMLElement_Release(elem);
947 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
948 if(exclass)
949 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
950 else
951 ok_(__FILE__,line) (!class, "class != NULL\n");
952 SysFreeString(class);
955 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
956 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
958 IHTMLElement *elem = _get_elem_iface(line, unk);
959 BSTR tmp;
960 HRESULT hres;
962 tmp = class ? a2bstr(class) : NULL;
963 hres = IHTMLElement_put_className(elem, tmp);
964 IHTMLElement_Release(elem);
965 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
966 SysFreeString(tmp);
968 _test_elem_class(line, unk, class);
971 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
972 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
974 IHTMLDOMNode *node = NULL;
975 IDispatch *disp;
976 HRESULT hres;
978 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
979 ok(hres == S_OK, "item failed: %08x\n", hres);
981 node = _get_node_iface(line, (IUnknown*)disp);
982 IDispatch_Release(disp);
984 return node;
987 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
988 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
990 IHTMLElement *elem = _get_elem_iface(line, unk);
991 BSTR id = (void*)0xdeadbeef;
992 HRESULT hres;
994 hres = IHTMLElement_get_id(elem, &id);
995 IHTMLElement_Release(elem);
996 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
998 if(exid)
999 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1000 else
1001 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1003 SysFreeString(id);
1006 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1007 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1009 IHTMLElement *elem = _get_elem_iface(line, unk);
1010 BSTR tmp = a2bstr(new_id);
1011 HRESULT hres;
1013 hres = IHTMLElement_put_id(elem, tmp);
1014 IHTMLElement_Release(elem);
1015 SysFreeString(tmp);
1016 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1018 _test_elem_id(line, unk, new_id);
1021 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1022 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1024 IHTMLDOMNode *node = _get_node_iface(line, unk);
1025 VARIANT var;
1026 HRESULT hres;
1028 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1029 IHTMLDOMNode_Release(node);
1030 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1032 if(exval) {
1033 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1034 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1035 }else {
1036 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1039 VariantClear(&var);
1042 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1043 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1045 IHTMLDOMNode *node = _get_node_iface(line, unk);
1046 VARIANT var;
1047 HRESULT hres;
1049 V_VT(&var) = VT_BSTR;
1050 V_BSTR(&var) = a2bstr(val);
1052 hres = IHTMLDOMNode_put_nodeValue(node, var);
1053 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1054 IHTMLDOMNode_Release(node);
1055 VariantClear(&var);
1058 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1059 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1061 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1062 long l;
1063 HRESULT hres;
1065 hres = IHTMLElement2_get_clientWidth(elem, &l);
1066 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1067 hres = IHTMLElement2_get_clientHeight(elem, &l);
1068 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1070 IHTMLElement2_Release(elem);
1073 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1074 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1076 IHTMLElement *elem = NULL;
1077 BSTR tmp;
1078 HRESULT hres;
1080 tmp = a2bstr(tag);
1081 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1082 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1083 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1085 return elem;
1088 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1089 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1091 IHTMLDocument3 *doc3;
1092 IHTMLDOMNode *node = NULL;
1093 BSTR tmp;
1094 HRESULT hres;
1096 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1097 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1099 tmp = a2bstr(text);
1100 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1101 IHTMLDocument3_Release(doc3);
1102 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1103 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1105 return node;
1108 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1109 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1111 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1112 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1113 IHTMLDOMNode *new_child = NULL;
1114 HRESULT hres;
1116 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1117 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1118 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1119 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1121 IHTMLDOMNode_Release(node);
1122 IHTMLDOMNode_Release(child);
1124 return new_child;
1127 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1128 const elem_type_t *elem_types, long len)
1130 IHTMLElementCollection *elcol;
1131 IDispatch *disp;
1132 VARIANT name, index;
1133 DWORD i;
1134 HRESULT hres;
1136 V_VT(&index) = VT_EMPTY;
1137 V_VT(&name) = VT_BSTR;
1138 V_BSTR(&name) = SysAllocString(n);
1140 hres = IHTMLElementCollection_item(col, name, index, &disp);
1141 ok(hres == S_OK, "item failed: %08x\n", hres);
1143 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
1144 IDispatch_Release(disp);
1145 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1146 if(hres != S_OK)
1147 goto cleanup;
1149 test_elem_collection(elcol, elem_types, len);
1150 IHTMLElementCollection_Release(elcol);
1152 V_VT(&index) = VT_I4;
1154 for(i=0; i<len; i++) {
1155 V_I4(&index) = i;
1156 disp = (void*)0xdeadbeef;
1157 hres = IHTMLElementCollection_item(col, name, index, &disp);
1158 ok(hres == S_OK, "item failed: %08x\n", hres);
1159 ok(disp != NULL, "disp == NULL\n");
1160 if(FAILED(hres) || !disp)
1161 continue;
1163 test_elem_type((IUnknown*)disp, elem_types[i]);
1165 IDispatch_Release(disp);
1168 V_I4(&index) = len;
1169 disp = (void*)0xdeadbeef;
1170 hres = IHTMLElementCollection_item(col, name, index, &disp);
1171 ok(hres == S_OK, "item failed: %08x\n", hres);
1172 ok(disp == NULL, "disp != NULL\n");
1174 V_I4(&index) = -1;
1175 disp = (void*)0xdeadbeef;
1176 hres = IHTMLElementCollection_item(col, name, index, &disp);
1177 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1178 ok(disp == NULL, "disp != NULL\n");
1180 cleanup:
1181 SysFreeString(V_BSTR(&name));
1184 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1186 IHTMLElementCollection *col;
1187 IHTMLElement *elem;
1188 IDispatch *disp = (void*)0xdeadbeef;
1189 VARIANT name, index;
1190 HRESULT hres;
1192 hres = IHTMLDocument2_get_all(doc, &col);
1193 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1194 ok(col != NULL, "col == NULL\n");
1195 if(FAILED(hres) || !col)
1196 return NULL;
1198 V_VT(&index) = VT_EMPTY;
1199 V_VT(&name) = VT_BSTR;
1200 V_BSTR(&name) = SysAllocString(id);
1202 hres = IHTMLElementCollection_item(col, name, index, &disp);
1203 IHTMLElementCollection_Release(col);
1204 SysFreeString(V_BSTR(&name));
1205 ok(hres == S_OK, "item failed: %08x\n", hres);
1206 if(!expect_success) {
1207 ok(disp == NULL, "disp != NULL\n");
1208 return NULL;
1211 ok(disp != NULL, "disp == NULL\n");
1212 if(!disp)
1213 return NULL;
1215 elem = get_elem_iface((IUnknown*)disp);
1216 IDispatch_Release(disp);
1218 return elem;
1221 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1223 IHTMLDocument3 *doc3;
1224 IHTMLElement *elem;
1225 BSTR tmp;
1226 HRESULT hres;
1228 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1229 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1231 tmp = SysAllocString(id);
1232 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1233 SysFreeString(tmp);
1234 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1236 IHTMLDocument3_Release(doc3);
1238 return elem;
1241 static void test_select_elem(IHTMLSelectElement *select)
1243 test_select_length(select, 2);
1244 test_select_selidx(select, 0);
1245 test_select_put_selidx(select, 1);
1248 static void test_create_option_elem(IHTMLDocument2 *doc)
1250 IHTMLOptionElement *option;
1252 option = create_option_elem(doc, "test text", "test value");
1254 test_option_put_text(option, "new text");
1255 test_option_put_value(option, "new value");
1257 IHTMLOptionElement_Release(option);
1260 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1262 IHTMLBodyElement *body;
1263 IHTMLTxtRange *range;
1264 IHTMLElement *elem;
1265 HRESULT hres;
1267 hres = IHTMLDocument2_get_body(doc, &elem);
1268 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1270 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1271 IHTMLElement_Release(elem);
1273 hres = IHTMLBodyElement_createTextRange(body, &range);
1274 IHTMLBodyElement_Release(body);
1275 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1277 return range;
1280 static void test_txtrange(IHTMLDocument2 *doc)
1282 IHTMLTxtRange *body_range, *range, *range2;
1283 IHTMLSelectionObject *selection;
1284 IDispatch *disp_range;
1285 HRESULT hres;
1287 body_range = test_create_body_range(doc);
1289 test_range_text(body_range, "test abc 123\r\nit's text");
1291 hres = IHTMLTxtRange_duplicate(body_range, &range);
1292 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1294 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1295 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1296 test_range_isequal(range, range2, VARIANT_TRUE);
1298 test_range_text(range, "test abc 123\r\nit's text");
1299 test_range_text(body_range, "test abc 123\r\nit's text");
1301 test_range_collapse(range, TRUE);
1302 test_range_isequal(range, range2, VARIANT_FALSE);
1303 test_range_inrange(range, range2, VARIANT_FALSE);
1304 test_range_inrange(range2, range, VARIANT_TRUE);
1305 IHTMLTxtRange_Release(range2);
1307 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1308 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1309 test_range_move(range, characterW, 2, 2);
1310 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1312 test_range_collapse(range, FALSE);
1313 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1315 test_range_collapse(range, FALSE);
1316 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1317 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1318 test_range_move(range, characterW, 2, 2);
1319 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1320 test_range_moveend(range, characterW, -5, -5);
1321 test_range_text(range, NULL);
1322 test_range_moveend(range, characterW, 3, 3);
1323 test_range_text(range, "c 1");
1324 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1325 test_range_collapse(range, TRUE);
1326 test_range_move(range, characterW, 4, 4);
1327 test_range_moveend(range, characterW, 1, 1);
1328 test_range_text(range, " ");
1329 test_range_move(range, wordW, 1, 1);
1330 test_range_moveend(range, characterW, 2, 2);
1331 test_range_text(range, "ab");
1333 IHTMLTxtRange_Release(range);
1335 hres = IHTMLTxtRange_duplicate(body_range, &range);
1336 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1338 test_range_text(range, "test abc 123\r\nit's text");
1339 test_range_move(range, characterW, 3, 3);
1340 test_range_moveend(range, characterW, 1, 1);
1341 test_range_text(range, "t");
1342 test_range_moveend(range, characterW, 3, 3);
1343 test_range_text(range, "t ab");
1344 test_range_moveend(range, characterW, -2, -2);
1345 test_range_text(range, "t ");
1346 test_range_move(range, characterW, 6, 6);
1347 test_range_moveend(range, characterW, 3, 3);
1348 test_range_text(range, "123");
1349 test_range_moveend(range, characterW, 2, 2);
1350 test_range_text(range, "123\r\ni");
1352 IHTMLTxtRange_Release(range);
1354 hres = IHTMLTxtRange_duplicate(body_range, &range);
1355 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1357 test_range_move(range, wordW, 1, 1);
1358 test_range_moveend(range, characterW, 2, 2);
1359 test_range_text(range, "ab");
1361 test_range_move(range, characterW, -2, -2);
1362 test_range_moveend(range, characterW, 2, 2);
1363 test_range_text(range, "t ");
1365 test_range_move(range, wordW, 3, 3);
1366 test_range_move(range, wordW, -2, -2);
1367 test_range_moveend(range, characterW, 2, 2);
1368 test_range_text(range, "ab");
1370 test_range_move(range, characterW, -6, -5);
1371 test_range_moveend(range, characterW, -1, 0);
1372 test_range_moveend(range, characterW, -6, 0);
1373 test_range_move(range, characterW, 2, 2);
1374 test_range_moveend(range, characterW, 2, 2);
1375 test_range_text(range, "st");
1376 test_range_moveend(range, characterW, -6, -4);
1377 test_range_moveend(range, characterW, 2, 2);
1379 IHTMLTxtRange_Release(range);
1381 hres = IHTMLTxtRange_duplicate(body_range, &range);
1382 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1384 test_range_move(range, wordW, 2, 2);
1385 test_range_moveend(range, characterW, 2, 2);
1386 test_range_text(range, "12");
1388 test_range_move(range, characterW, 15, 14);
1389 test_range_move(range, characterW, -2, -2);
1390 test_range_moveend(range, characterW, 3, 2);
1391 test_range_text(range, "t");
1392 test_range_moveend(range, characterW, -1, -1);
1393 test_range_text(range, "t");
1394 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1395 test_range_move(range, characterW, -2, -2);
1396 test_range_moveend(range, characterW, 2, 2);
1397 test_range_text(range, "s ");
1398 test_range_move(range, characterW, 100, 7);
1399 test_range_move(range, wordW, 1, 0);
1400 test_range_move(range, characterW, -2, -2);
1401 test_range_moveend(range, characterW, 3, 2);
1402 test_range_text(range, "t");
1404 IHTMLTxtRange_Release(range);
1406 hres = IHTMLTxtRange_duplicate(body_range, &range);
1407 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1409 test_range_collapse(range, TRUE);
1410 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1411 test_range_put_text(range, "word");
1412 test_range_text(body_range, "wordabc 123\r\nit's text");
1413 test_range_text(range, NULL);
1414 test_range_moveend(range, characterW, 3, 3);
1415 test_range_text(range, "abc");
1416 test_range_movestart(range, characterW, -2, -2);
1417 test_range_text(range, "rdabc");
1418 test_range_movestart(range, characterW, 3, 3);
1419 test_range_text(range, "bc");
1420 test_range_movestart(range, characterW, 4, 4);
1421 test_range_text(range, NULL);
1422 test_range_movestart(range, characterW, -3, -3);
1423 test_range_text(range, "c 1");
1424 test_range_movestart(range, characterW, -7, -6);
1425 test_range_text(range, "wordabc 1");
1426 test_range_movestart(range, characterW, 100, 22);
1427 test_range_text(range, NULL);
1429 IHTMLTxtRange_Release(range);
1430 IHTMLTxtRange_Release(body_range);
1432 hres = IHTMLDocument2_get_selection(doc, &selection);
1433 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1435 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1436 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1437 IHTMLSelectionObject_Release(selection);
1439 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1440 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1441 IDispatch_Release(disp_range);
1443 test_range_text(range, NULL);
1444 test_range_moveend(range, characterW, 3, 3);
1445 test_range_text(range, "wor");
1446 test_range_parent(range, ET_BODY);
1447 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1448 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1449 test_range_move(range, characterW, 3, 3);
1450 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1451 test_range_moveend(range, characterW, -4, -4);
1452 test_range_put_text(range, "abc def ");
1453 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1454 test_range_move(range, wordW, 1, 1);
1455 test_range_movestart(range, characterW, -1, -1);
1456 test_range_text(range, " ");
1457 test_range_move(range, wordW, 1, 1);
1458 test_range_moveend(range, characterW, 3, 3);
1459 test_range_text(range, "def");
1460 test_range_put_text(range, "xyz");
1461 test_range_moveend(range, characterW, 1, 1);
1462 test_range_move(range, wordW, 1, 1);
1463 test_range_moveend(range, characterW, 2, 2);
1464 test_range_text(range, "ab");
1466 IHTMLTxtRange_Release(range);
1469 static void test_txtrange2(IHTMLDocument2 *doc)
1471 IHTMLTxtRange *range;
1473 range = test_create_body_range(doc);
1475 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1476 test_range_move(range, characterW, 5, 5);
1477 test_range_moveend(range, characterW, 1, 1);
1478 test_range_text(range, "2");
1479 test_range_move(range, characterW, -3, -3);
1480 test_range_moveend(range, characterW, 3, 3);
1481 test_range_text(range, "c\r\n\r\n1");
1482 test_range_collapse(range, VARIANT_FALSE);
1483 test_range_moveend(range, characterW, 4, 4);
1484 test_range_text(range, "23");
1485 test_range_moveend(range, characterW, 1, 1);
1486 test_range_text(range, "23\r\n\r\n\r\nd");
1487 test_range_moveend(range, characterW, -1, -1);
1488 test_range_text(range, "23");
1489 test_range_moveend(range, characterW, -1, -1);
1490 test_range_text(range, "23");
1491 test_range_moveend(range, characterW, -2, -2);
1492 test_range_text(range, "2");
1494 IHTMLTxtRange_Release(range);
1497 static void test_compatmode(IHTMLDocument2 *doc)
1499 IHTMLDocument5 *doc5;
1500 BSTR mode;
1501 HRESULT hres;
1503 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1504 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1505 if(FAILED(hres))
1506 return;
1508 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1509 IHTMLDocument5_Release(doc5);
1510 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1511 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1512 SysFreeString(mode);
1515 static void test_location(IHTMLDocument2 *doc)
1517 IHTMLLocation *location, *location2;
1518 ULONG ref;
1519 HRESULT hres;
1521 hres = IHTMLDocument2_get_location(doc, &location);
1522 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1524 hres = IHTMLDocument2_get_location(doc, &location2);
1525 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1527 ok(location == location2, "location != location2\n");
1529 test_ifaces((IUnknown*)location, location_iids);
1531 IHTMLLocation_Release(location2);
1532 ref = IHTMLLocation_Release(location);
1533 ok(!ref, "location chould be destroyed here\n");
1536 static void test_navigator(IHTMLDocument2 *doc)
1538 IHTMLWindow2 *window;
1539 IOmNavigator *navigator, *navigator2;
1540 ULONG ref;
1541 HRESULT hres;
1543 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1544 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1546 hres = IHTMLWindow2_get_navigator(window, &navigator);
1547 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1548 ok(navigator != NULL, "navigator == NULL\n");
1549 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1551 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1552 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1553 ok(navigator != navigator2, "navigator2 != navihgator\n");
1555 IHTMLWindow2_Release(window);
1556 IOmNavigator_Release(navigator2);
1557 ref = IOmNavigator_Release(navigator);
1558 ok(!ref, "navigator should be destroyed here\n");
1561 static void test_default_style(IHTMLStyle *style)
1563 VARIANT_BOOL b;
1564 VARIANT v;
1565 BSTR str;
1566 HRESULT hres;
1568 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
1570 str = (void*)0xdeadbeef;
1571 hres = IHTMLStyle_get_fontFamily(style, &str);
1572 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1573 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1575 str = (void*)0xdeadbeef;
1576 hres = IHTMLStyle_get_fontWeight(style, &str);
1577 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1578 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1580 str = (void*)0xdeadbeef;
1581 hres = IHTMLStyle_get_display(style, &str);
1582 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1583 ok(!str, "display = %s\n", dbgstr_w(str));
1585 str = (void*)0xdeadbeef;
1586 hres = IHTMLStyle_get_visibility(style, &str);
1587 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1588 ok(!str, "visibility = %s\n", dbgstr_w(str));
1590 V_VT(&v) = VT_NULL;
1591 hres = IHTMLStyle_get_fontSize(style, &v);
1592 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1593 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1594 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1596 V_VT(&v) = VT_NULL;
1597 hres = IHTMLStyle_get_color(style, &v);
1598 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1599 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1600 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1602 b = 0xfefe;
1603 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1604 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1605 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1607 b = 0xfefe;
1608 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1609 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1610 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1613 static void test_default_selection(IHTMLDocument2 *doc)
1615 IHTMLSelectionObject *selection;
1616 IHTMLTxtRange *range;
1617 IDispatch *disp;
1618 BSTR str;
1619 HRESULT hres;
1621 hres = IHTMLDocument2_get_selection(doc, &selection);
1622 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1624 hres = IHTMLSelectionObject_get_type(selection, &str);
1625 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1626 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1627 SysFreeString(str);
1629 hres = IHTMLSelectionObject_createRange(selection, &disp);
1630 IHTMLSelectionObject_Release(selection);
1631 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1633 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1634 IDispatch_Release(disp);
1635 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1637 test_range_text(range, NULL);
1638 IHTMLTxtRange_Release(range);
1641 static void test_default_body(IHTMLBodyElement *body)
1643 BSTR bstr;
1644 HRESULT hres;
1646 bstr = (void*)0xdeadbeef;
1647 hres = IHTMLBodyElement_get_background(body, &bstr);
1648 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1649 ok(bstr == NULL, "bstr != NULL\n");
1652 static void test_window(IHTMLDocument2 *doc)
1654 IHTMLWindow2 *window;
1655 IHTMLDocument2 *doc2 = NULL;
1656 HRESULT hres;
1658 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1659 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
1660 test_ifaces((IUnknown*)window, window_iids);
1661 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
1663 hres = IHTMLWindow2_get_document(window, &doc2);
1664 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1665 ok(doc2 != NULL, "doc2 == NULL\n");
1667 IHTMLDocument_Release(doc2);
1668 IHTMLWindow2_Release(window);
1671 static void test_defaults(IHTMLDocument2 *doc)
1673 IHTMLStyleSheetsCollection *stylesheetcol;
1674 IHTMLBodyElement *body;
1675 IHTMLElement *elem;
1676 IHTMLStyle *style;
1677 long l;
1678 HRESULT hres;
1680 hres = IHTMLDocument2_get_body(doc, &elem);
1681 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1683 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1684 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1685 test_default_body(body);
1686 IHTMLBodyElement_Release(body);
1688 hres = IHTMLElement_get_style(elem, &style);
1689 IHTMLElement_Release(elem);
1690 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1692 test_default_style(style);
1693 test_window(doc);
1694 test_compatmode(doc);
1695 test_location(doc);
1696 test_navigator(doc);
1698 IHTMLStyle_Release(style);
1700 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1701 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1703 l = 0xdeadbeef;
1704 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1705 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1706 ok(l == 0, "length = %ld\n", l);
1708 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1710 test_default_selection(doc);
1713 static void test_stylesheet(IDispatch *disp)
1715 IHTMLStyleSheetRulesCollection *col = NULL;
1716 IHTMLStyleSheet *stylesheet;
1717 HRESULT hres;
1719 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1720 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1722 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1723 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1724 ok(col != NULL, "col == NULL\n");
1726 IHTMLStyleSheetRulesCollection_Release(col);
1727 IHTMLStyleSheet_Release(stylesheet);
1730 static void test_stylesheets(IHTMLDocument2 *doc)
1732 IHTMLStyleSheetsCollection *col = NULL;
1733 VARIANT idx, res;
1734 long len = 0;
1735 HRESULT hres;
1737 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1738 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1739 ok(col != NULL, "col == NULL\n");
1741 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1742 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1743 ok(len == 1, "len=%ld\n", len);
1745 VariantInit(&res);
1746 V_VT(&idx) = VT_I4;
1747 V_I4(&idx) = 0;
1749 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1750 ok(hres == S_OK, "item failed: %08x\n", hres);
1751 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1752 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1753 test_stylesheet(V_DISPATCH(&res));
1754 VariantClear(&res);
1756 V_VT(&res) = VT_I4;
1757 V_VT(&idx) = VT_I4;
1758 V_I4(&idx) = 1;
1760 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1761 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1762 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1763 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1764 VariantClear(&res);
1766 IHTMLStyleSheetsCollection_Release(col);
1769 static void test_elems(IHTMLDocument2 *doc)
1771 IHTMLElementCollection *col;
1772 IHTMLDOMChildrenCollection *child_col;
1773 IHTMLElement *elem;
1774 IHTMLDOMNode *node, *node2;
1775 IDispatch *disp;
1776 long type;
1777 HRESULT hres;
1779 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
1780 static const WCHAR inW[] = {'i','n',0};
1781 static const WCHAR xW[] = {'x',0};
1782 static const WCHAR sW[] = {'s',0};
1783 static const WCHAR scW[] = {'s','c',0};
1784 static const WCHAR xxxW[] = {'x','x','x',0};
1786 static const elem_type_t all_types[] = {
1787 ET_HTML,
1788 ET_HEAD,
1789 ET_TITLE,
1790 ET_STYLE,
1791 ET_BODY,
1792 ET_COMMENT,
1793 ET_A,
1794 ET_INPUT,
1795 ET_SELECT,
1796 ET_OPTION,
1797 ET_OPTION,
1798 ET_TEXTAREA,
1799 ET_TABLE,
1800 ET_TBODY,
1801 ET_SCRIPT,
1802 ET_TEST,
1803 ET_IMG
1806 static const elem_type_t item_types[] = {
1807 ET_A,
1808 ET_OPTION,
1809 ET_TEXTAREA
1812 hres = IHTMLDocument2_get_all(doc, &col);
1813 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1814 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1815 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1816 IHTMLElementCollection_Release(col);
1818 elem = get_doc_elem(doc);
1819 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1820 hres = IHTMLElement_get_all(elem, &disp);
1821 IHTMLElement_Release(elem);
1822 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1824 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1825 IDispatch_Release(disp);
1826 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1827 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1828 IHTMLElementCollection_Release(col);
1830 get_elem_by_id(doc, xxxW, FALSE);
1831 elem = get_doc_elem_by_id(doc, xxxW);
1832 ok(!elem, "elem != NULL\n");
1834 elem = get_doc_elem_by_id(doc, sW);
1835 ok(elem != NULL, "elem == NULL\n");
1836 if(elem) {
1837 test_elem_type((IUnknown*)elem, ET_SELECT);
1838 test_elem_attr(elem, xxxW, NULL);
1839 test_elem_attr(elem, idW, sW);
1840 test_elem_class((IUnknown*)elem, NULL);
1841 test_elem_set_class((IUnknown*)elem, "cl");
1842 test_elem_set_class((IUnknown*)elem, NULL);
1843 IHTMLElement_Release(elem);
1846 elem = get_elem_by_id(doc, sW, TRUE);
1847 if(elem) {
1848 IHTMLSelectElement *select;
1850 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1851 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1853 test_select_elem(select);
1855 node = get_first_child((IUnknown*)select);
1856 ok(node != NULL, "node == NULL\n");
1857 if(node) {
1858 test_elem_type((IUnknown*)node, ET_OPTION);
1859 IHTMLDOMNode_Release(node);
1862 type = get_node_type((IUnknown*)select);
1863 ok(type == 1, "type=%ld\n", type);
1865 IHTMLSelectElement_Release(select);
1866 IHTMLElement_Release(elem);
1869 elem = get_elem_by_id(doc, scW, TRUE);
1870 if(elem) {
1871 IHTMLScriptElement *script;
1872 BSTR type;
1874 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
1875 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
1877 hres = IHTMLScriptElement_get_type(script, &type);
1878 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1879 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
1880 SysFreeString(type);
1882 IHTMLScriptElement_Release(script);
1885 elem = get_elem_by_id(doc, inW, TRUE);
1886 if(elem) {
1887 IHTMLInputElement *input;
1889 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
1890 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1892 test_elem_id((IUnknown*)elem, "in");
1893 test_elem_put_id((IUnknown*)elem, "newin");
1894 test_input_get_disabled(input, VARIANT_FALSE);
1895 test_elem_client_size((IUnknown*)elem);
1897 test_node_get_value_str((IUnknown*)elem, NULL);
1898 test_node_put_value_str((IUnknown*)elem, "test");
1899 test_node_get_value_str((IUnknown*)elem, NULL);
1900 test_input_value((IUnknown*)elem, NULL);
1901 test_input_put_value((IUnknown*)elem, "test");
1902 test_input_value((IUnknown*)elem, NULL);
1903 test_elem_class((IUnknown*)elem, "testclass");
1905 IHTMLInputElement_Release(input);
1906 IHTMLElement_Release(elem);
1909 elem = get_elem_by_id(doc, imgidW, TRUE);
1910 if(elem) {
1911 test_img_set_src((IUnknown*)elem, "about:blank");
1912 IHTMLElement_Release(elem);
1915 hres = IHTMLDocument2_get_body(doc, &elem);
1916 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1918 node = get_first_child((IUnknown*)elem);
1919 ok(node != NULL, "node == NULL\n");
1920 if(node) {
1921 test_ifaces((IUnknown*)node, text_iids);
1922 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
1924 node2 = get_first_child((IUnknown*)node);
1925 ok(!node2, "node2 != NULL\n");
1927 type = get_node_type((IUnknown*)node);
1928 ok(type == 3, "type=%ld\n", type);
1930 test_node_get_value_str((IUnknown*)node, "text test");
1931 test_node_put_value_str((IUnknown*)elem, "test text");
1932 test_node_get_value_str((IUnknown*)node, "text test");
1934 IHTMLDOMNode_Release(node);
1937 child_col = get_child_nodes((IUnknown*)elem);
1938 ok(child_col != NULL, "child_coll == NULL\n");
1939 if(child_col) {
1940 long length = 0;
1942 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
1944 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
1945 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1946 ok(length, "length=0\n");
1948 node = get_child_item(child_col, 0);
1949 ok(node != NULL, "node == NULL\n");
1950 if(node) {
1951 type = get_node_type((IUnknown*)node);
1952 ok(type == 3, "type=%ld\n", type);
1953 IHTMLDOMNode_Release(node);
1956 node = get_child_item(child_col, 1);
1957 ok(node != NULL, "node == NULL\n");
1958 if(node) {
1959 type = get_node_type((IUnknown*)node);
1960 ok(type == 8, "type=%ld\n", type);
1962 test_elem_id((IUnknown*)node, NULL);
1963 IHTMLDOMNode_Release(node);
1966 disp = (void*)0xdeadbeef;
1967 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
1968 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1969 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
1971 IHTMLDOMChildrenCollection_Release(child_col);
1974 IHTMLElement_Release(elem);
1976 test_stylesheets(doc);
1977 test_create_option_elem(doc);
1980 static void test_create_elems(IHTMLDocument2 *doc)
1982 IHTMLElementCollection *col;
1983 IHTMLElement *elem, *body, *elem2;
1984 IHTMLDOMNode *node;
1985 IDispatch *disp;
1986 long type;
1987 HRESULT hres;
1989 static const elem_type_t types1[] = { ET_TESTG };
1991 elem = test_create_elem(doc, "TEST");
1992 test_elem_tag((IUnknown*)elem, "TEST");
1993 type = get_node_type((IUnknown*)elem);
1994 ok(type == 1, "type=%ld\n", type);
1995 test_ifaces((IUnknown*)elem, elem_iids);
1996 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
1998 hres = IHTMLDocument2_get_body(doc, &body);
1999 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2001 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
2002 elem2 = get_elem_iface((IUnknown*)node);
2003 IHTMLDOMNode_Release(node);
2005 hres = IHTMLElement_get_all(body, &disp);
2006 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2007 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2008 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2009 IDispatch_Release(disp);
2011 test_elem_collection(col, types1, sizeof(types1)/sizeof(types1[0]));
2013 IHTMLElement_Release(elem2);
2014 IHTMLElement_Release(body);
2015 IHTMLElement_Release(elem);
2017 node = test_create_text(doc, "test");
2018 test_ifaces((IUnknown*)node, text_iids);
2019 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2020 IHTMLDOMNode_Release(node);
2023 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
2025 IOleCommandTarget *cmdtrg;
2026 HRESULT hres;
2028 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2029 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
2031 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
2032 ok(hres == S_OK, "Exec failed: %08x\n", hres);
2034 IOleCommandTarget_Release(cmdtrg);
2037 static void test_indent(IHTMLDocument2 *doc)
2039 IHTMLElementCollection *col;
2040 IHTMLTxtRange *range;
2041 HRESULT hres;
2043 static const elem_type_t all_types[] = {
2044 ET_HTML,
2045 ET_HEAD,
2046 ET_TITLE,
2047 ET_BODY,
2048 ET_BR,
2049 ET_A,
2052 static const elem_type_t indent_types[] = {
2053 ET_HTML,
2054 ET_HEAD,
2055 ET_TITLE,
2056 ET_BODY,
2057 ET_BLOCKQUOTE,
2058 ET_P,
2059 ET_BR,
2060 ET_A,
2063 hres = IHTMLDocument2_get_all(doc, &col);
2064 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2065 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2066 IHTMLElementCollection_Release(col);
2068 range = test_create_body_range(doc);
2069 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
2070 IHTMLTxtRange_Release(range);
2072 hres = IHTMLDocument2_get_all(doc, &col);
2073 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2074 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
2075 IHTMLElementCollection_Release(col);
2078 static IHTMLDocument2 *notif_doc;
2079 static BOOL doc_complete;
2081 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2082 REFIID riid, void**ppv)
2084 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2085 *ppv = iface;
2086 return S_OK;
2089 ok(0, "unexpected call\n");
2090 return E_NOINTERFACE;
2093 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2095 return 2;
2098 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2100 return 1;
2103 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2105 if(dispID == DISPID_READYSTATE){
2106 BSTR state;
2107 HRESULT hres;
2109 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
2111 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2112 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2114 if(!lstrcmpW(state, completeW))
2115 doc_complete = TRUE;
2117 SysFreeString(state);
2120 return S_OK;
2123 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2125 ok(0, "unexpected call\n");
2126 return E_NOTIMPL;
2129 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2130 PropertyNotifySink_QueryInterface,
2131 PropertyNotifySink_AddRef,
2132 PropertyNotifySink_Release,
2133 PropertyNotifySink_OnChanged,
2134 PropertyNotifySink_OnRequestEdit
2137 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2139 static IHTMLDocument2 *create_doc_with_string(const char *str)
2141 IPersistStreamInit *init;
2142 IStream *stream;
2143 IHTMLDocument2 *doc;
2144 HGLOBAL mem;
2145 SIZE_T len;
2147 notif_doc = doc = create_document();
2148 if(!doc)
2149 return NULL;
2151 doc_complete = FALSE;
2152 len = strlen(str);
2153 mem = GlobalAlloc(0, len);
2154 memcpy(mem, str, len);
2155 CreateStreamOnHGlobal(mem, TRUE, &stream);
2157 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2159 IPersistStreamInit_Load(init, stream);
2160 IPersistStreamInit_Release(init);
2161 IStream_Release(stream);
2163 return doc;
2166 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2168 IConnectionPointContainer *container;
2169 IConnectionPoint *cp;
2170 DWORD cookie;
2171 HRESULT hres;
2173 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2174 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2176 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2177 IConnectionPointContainer_Release(container);
2178 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2180 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2181 IConnectionPoint_Release(cp);
2182 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2185 typedef void (*domtest_t)(IHTMLDocument2*);
2187 static void run_domtest(const char *str, domtest_t test)
2189 IHTMLDocument2 *doc;
2190 IHTMLElement *body = NULL;
2191 ULONG ref;
2192 MSG msg;
2193 HRESULT hres;
2195 doc = create_doc_with_string(str);
2196 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2198 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
2199 TranslateMessage(&msg);
2200 DispatchMessage(&msg);
2203 hres = IHTMLDocument2_get_body(doc, &body);
2204 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2206 if(body) {
2207 IHTMLElement_Release(body);
2208 test(doc);
2209 }else {
2210 skip("Could not get document body. Assuming no Gecko installed.\n");
2213 ref = IHTMLDocument2_Release(doc);
2214 ok(!ref, "ref = %d\n", ref);
2217 static void gecko_installer_workaround(BOOL disable)
2219 HKEY hkey;
2220 DWORD res;
2222 static BOOL has_url = FALSE;
2223 static char url[2048];
2225 if(!disable && !has_url)
2226 return;
2228 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2229 if(res != ERROR_SUCCESS)
2230 return;
2232 if(disable) {
2233 DWORD type, size = sizeof(url);
2235 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2236 if(res == ERROR_SUCCESS && type == REG_SZ)
2237 has_url = TRUE;
2239 RegDeleteValue(hkey, "GeckoUrl");
2240 }else {
2241 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2244 RegCloseKey(hkey);
2247 START_TEST(dom)
2249 gecko_installer_workaround(TRUE);
2250 CoInitialize(NULL);
2252 run_domtest(doc_str1, test_doc_elem);
2253 run_domtest(range_test_str, test_txtrange);
2254 run_domtest(range_test2_str, test_txtrange2);
2255 run_domtest(elem_test_str, test_elems);
2256 run_domtest(doc_blank, test_create_elems);
2257 run_domtest(doc_blank, test_defaults);
2258 run_domtest(indent_test_str, test_indent);
2260 CoUninitialize();
2261 gecko_installer_workaround(FALSE);