mshtml: Added IHTMLDocument::get_Script implementation.
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob7e8c9bf6fb07c9782b60da6fbed398a8f60b3d7c
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\" tabIndex=\"2\" title=\"test title\" />"
46 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
47 "<textarea id=\"X\">text text</textarea>"
48 "<table><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 get_img_iface(u) _get_img_iface(__LINE__,u)
415 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
417 IHTMLImgElement *img;
418 HRESULT hres;
420 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
421 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
422 return img;
425 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
426 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
428 IHTMLDOMNode *node = _get_node_iface(line, unk);
429 BSTR name;
430 HRESULT hres;
432 hres = IHTMLDOMNode_get_nodeName(node, &name);
433 IHTMLDOMNode_Release(node);
434 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
435 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
437 SysFreeString(name);
440 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
441 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
443 IHTMLElement *elem = _get_elem_iface(line, unk);
444 BSTR tag;
445 HRESULT hres;
447 hres = IHTMLElement_get_tagName(elem, &tag);
448 IHTMLElement_Release(elem);
449 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
450 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
452 SysFreeString(tag);
455 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
456 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
458 _test_elem_tag(line, unk, elem_type_infos[type].tag);
459 _test_ifaces(line, unk, elem_type_infos[type].iids);
461 if(elem_type_infos[type].dispiid)
462 _test_disp(line, unk, elem_type_infos[type].dispiid);
465 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
466 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
468 VARIANT value;
469 BSTR tmp;
470 HRESULT hres;
472 VariantInit(&value);
474 tmp = SysAllocString(name);
475 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
476 SysFreeString(tmp);
477 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
479 if(exval) {
480 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
481 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
482 }else {
483 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
486 VariantClear(&value);
489 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
490 static void _test_elem_offset(unsigned line, IUnknown *unk)
492 IHTMLElement *elem = _get_elem_iface(line, unk);
493 long l;
494 HRESULT hres;
496 hres = IHTMLElement_get_offsetTop(elem, &l);
497 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
499 hres = IHTMLElement_get_offsetHeight(elem, &l);
500 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
502 IHTMLElement_Release(elem);
505 static void test_doc_elem(IHTMLDocument2 *doc)
507 IHTMLElement *elem;
508 IHTMLDocument3 *doc3;
509 HRESULT hres;
511 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
512 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
514 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
515 IHTMLDocument3_Release(doc3);
516 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
518 test_node_name((IUnknown*)elem, "HTML");
519 test_elem_tag((IUnknown*)elem, "HTML");
521 IHTMLElement_Release(elem);
524 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
525 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
527 IHTMLElement *elem;
528 IHTMLDocument3 *doc3;
529 HRESULT hres;
531 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
532 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
533 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
534 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
535 IHTMLDocument3_Release(doc3);
537 return elem;
540 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
541 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
543 BSTR bstr;
544 HRESULT hres;
546 hres = IHTMLOptionElement_get_text(option, &bstr);
547 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
548 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
549 SysFreeString(bstr);
552 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
553 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
555 BSTR bstr;
556 HRESULT hres;
558 bstr = a2bstr(text);
559 hres = IHTMLOptionElement_put_text(option, bstr);
560 SysFreeString(bstr);
561 ok(hres == S_OK, "put_text failed: %08x\n", hres);
563 _test_option_text(line, option, text);
566 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
567 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
569 BSTR bstr;
570 HRESULT hres;
572 hres = IHTMLOptionElement_get_value(option, &bstr);
573 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
574 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
575 SysFreeString(bstr);
578 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
579 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
581 BSTR bstr;
582 HRESULT hres;
584 bstr = a2bstr(value);
585 hres = IHTMLOptionElement_put_value(option, bstr);
586 SysFreeString(bstr);
587 ok(hres == S_OK, "put_value failed: %08x\n", hres);
589 _test_option_value(line, option, value);
592 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
593 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
594 const char *txt, const char *val)
596 IHTMLOptionElementFactory *factory;
597 IHTMLOptionElement *option;
598 IHTMLWindow2 *window;
599 VARIANT text, value, empty;
600 HRESULT hres;
602 hres = IHTMLDocument2_get_parentWindow(doc, &window);
603 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
605 hres = IHTMLWindow2_get_Option(window, &factory);
606 IHTMLWindow2_Release(window);
607 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
609 V_VT(&text) = VT_BSTR;
610 V_BSTR(&text) = a2bstr(txt);
611 V_VT(&value) = VT_BSTR;
612 V_BSTR(&value) = a2bstr(val);
613 V_VT(&empty) = VT_EMPTY;
615 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
616 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
618 IHTMLOptionElementFactory_Release(factory);
619 VariantClear(&text);
620 VariantClear(&value);
622 _test_option_text(line, option, txt);
623 _test_option_value(line, option, val);
625 return option;
628 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
629 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
631 long len = 0xdeadbeef;
632 HRESULT hres;
634 hres = IHTMLSelectElement_get_length(select, &len);
635 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
636 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
639 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
640 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
642 long idx = 0xdeadbeef;
643 HRESULT hres;
645 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
646 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
647 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
650 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
651 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
653 HRESULT hres;
655 hres = IHTMLSelectElement_put_selectedIndex(select, index);
656 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
657 _test_select_selidx(line, select, index);
660 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
661 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
663 BSTR val;
664 HRESULT hres;
666 hres = IHTMLSelectElement_get_value(select, &val);
667 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
668 if(exval)
669 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
670 else
671 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
674 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
675 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
677 BSTR bstr;
678 HRESULT hres;
680 bstr = a2bstr(val);
681 hres = IHTMLSelectElement_put_value(select, bstr);
682 SysFreeString(bstr);
683 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
686 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
687 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
689 BSTR type;
690 HRESULT hres;
692 hres = IHTMLSelectElement_get_type(select, &type);
693 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
694 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
697 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
698 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
700 BSTR text;
701 HRESULT hres;
703 hres = IHTMLTxtRange_get_text(range, &text);
704 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
706 if(extext) {
707 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
708 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
709 }else {
710 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
713 SysFreeString(text);
717 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
718 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
720 HRESULT hres;
722 hres = IHTMLTxtRange_collapse(range, b);
723 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
724 _test_range_text(line, range, NULL);
727 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
728 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
729 VARIANT_BOOL exb, const char *extext)
731 VARIANT_BOOL b = 0xe0e0;
732 HRESULT hres;
734 hres = IHTMLTxtRange_expand(range, unit, &b);
735 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
736 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
737 _test_range_text(line, range, extext);
740 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
741 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
743 long c = 0xdeadbeef;
744 HRESULT hres;
746 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
747 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
748 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
749 _test_range_text(line, range, NULL);
752 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
753 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
754 LPWSTR unit, long cnt, long excnt)
756 long c = 0xdeadbeef;
757 HRESULT hres;
759 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
760 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
761 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
764 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
765 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
767 long c = 0xdeadbeef;
768 HRESULT hres;
770 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
771 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
772 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
775 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
776 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
778 HRESULT hres;
779 BSTR bstr = a2bstr(text);
781 hres = IHTMLTxtRange_put_text(range, bstr);
782 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
783 SysFreeString(bstr);
784 _test_range_text(line, range, NULL);
787 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
788 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
790 VARIANT_BOOL b;
791 HRESULT hres;
793 b = 0xe0e0;
794 hres = IHTMLTxtRange_inRange(range1, range2, &b);
795 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
796 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
799 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
800 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
802 VARIANT_BOOL b;
803 HRESULT hres;
805 b = 0xe0e0;
806 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
807 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
808 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
810 b = 0xe0e0;
811 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
812 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
813 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
815 if(exb) {
816 test_range_inrange(range1, range2, VARIANT_TRUE);
817 test_range_inrange(range2, range1, VARIANT_TRUE);
821 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
822 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
824 IHTMLElement *elem;
825 HRESULT hres;
827 hres = IHTMLTxtRange_parentElement(range, &elem);
828 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
830 _test_elem_type(line, (IUnknown*)elem, type);
832 IHTMLElement_Release(elem);
835 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
836 static void _test_elem_collection(unsigned line, IUnknown *unk,
837 const elem_type_t *elem_types, long exlen)
839 IHTMLElementCollection *col;
840 long len;
841 DWORD i;
842 VARIANT name, index;
843 IDispatch *disp;
844 HRESULT hres;
846 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
847 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
849 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
851 hres = IHTMLElementCollection_get_length(col, &len);
852 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
853 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
855 if(len > exlen)
856 len = exlen;
858 V_VT(&index) = VT_EMPTY;
859 V_VT(&name) = VT_I4;
861 for(i=0; i<len; i++) {
862 V_I4(&name) = i;
863 disp = (void*)0xdeadbeef;
864 hres = IHTMLElementCollection_item(col, name, index, &disp);
865 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
866 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
867 if(FAILED(hres) || !disp)
868 continue;
870 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
871 IDispatch_Release(disp);
874 V_I4(&name) = len;
875 disp = (void*)0xdeadbeef;
876 hres = IHTMLElementCollection_item(col, name, index, &disp);
877 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
878 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
880 V_I4(&name) = -1;
881 disp = (void*)0xdeadbeef;
882 hres = IHTMLElementCollection_item(col, name, index, &disp);
883 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
884 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
886 IHTMLElementCollection_Release(col);
889 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
890 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
892 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
893 IHTMLElementCollection *col = NULL;
894 elem_type_t *types = NULL;
895 BSTR tmp;
896 int i;
897 HRESULT hres;
899 tmp = a2bstr(elem_type_infos[type].tag);
900 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
901 SysFreeString(tmp);
902 IHTMLElement2_Release(elem);
903 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
904 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
906 if(exlen) {
907 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
908 for(i=0; i<exlen; i++)
909 types[i] = type;
912 _test_elem_collection(line, (IUnknown*)col, types, exlen);
914 HeapFree(GetProcessHeap(), 0, types);
917 #define get_first_child(n) _get_first_child(__LINE__,n)
918 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
920 IHTMLDOMNode *node = _get_node_iface(line, unk);
921 IHTMLDOMNode *child = NULL;
922 HRESULT hres;
924 hres = IHTMLDOMNode_get_firstChild(node, &child);
925 IHTMLDOMNode_Release(node);
926 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
928 return child;
931 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
932 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
934 IHTMLDOMNode *node = _get_node_iface(line, unk);
935 VARIANT_BOOL b = 0xdead;
936 HRESULT hres;
938 hres = IHTMLDOMNode_hasChildNodes(node, &b);
939 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
940 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
942 IHTMLDOMNode_Release(node);
945 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
946 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
948 IHTMLDOMNode *node = _get_node_iface(line, unk);
949 IHTMLDOMNode *parent;
950 HRESULT hres;
952 hres = IHTMLDOMNode_get_parentNode(node, &parent);
953 IHTMLDOMNode_Release(node);
954 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
956 return parent;
959 #define get_node_type(n) _get_node_type(__LINE__,n)
960 static long _get_node_type(unsigned line, IUnknown *unk)
962 IHTMLDOMNode *node = _get_node_iface(line, unk);
963 long type = -1;
964 HRESULT hres;
966 hres = IHTMLDOMNode_get_nodeType(node, &type);
967 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
969 IHTMLDOMNode_Release(node);
971 return type;
974 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
975 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
977 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
978 IHTMLTextContainer *txtcont;
979 long l = -1, l2 = -1;
980 HRESULT hres;
982 hres = IHTMLElement2_get_scrollHeight(elem, &l);
983 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
984 IHTMLElement2_Release(elem);
986 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
987 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
989 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
990 IHTMLTextContainer_Release(txtcont);
991 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
992 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
994 return l;
997 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
998 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1000 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1001 IHTMLTextContainer *txtcont;
1002 long l = -1, l2 = -1;
1003 HRESULT hres;
1005 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1006 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1007 IHTMLElement2_Release(elem);
1009 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1010 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1012 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1013 IHTMLTextContainer_Release(txtcont);
1014 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1015 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1017 return l;
1020 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1021 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1023 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1024 IHTMLTextContainer *txtcont;
1025 long l = -1, l2 = -1;
1026 HRESULT hres;
1028 hres = IHTMLElement2_get_scrollTop(elem, &l);
1029 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1030 IHTMLElement2_Release(elem);
1032 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1033 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1035 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1036 IHTMLTextContainer_Release(txtcont);
1037 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1038 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1040 return l;
1043 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1044 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1046 IHTMLImgElement *img = _get_img_iface(line, unk);
1047 BSTR tmp;
1048 HRESULT hres;
1050 tmp = a2bstr(src);
1051 hres = IHTMLImgElement_put_src(img, tmp);
1052 IHTMLImgElement_Release(img);
1053 SysFreeString(tmp);
1054 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1057 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1058 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1060 IHTMLImgElement *img = _get_img_iface(line, unk);
1061 BSTR alt;
1062 HRESULT hres;
1064 hres = IHTMLImgElement_get_alt(img, &alt);
1065 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1066 if(exalt)
1067 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1068 else
1069 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1070 SysFreeString(alt);
1073 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1074 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1076 IHTMLImgElement *img = _get_img_iface(line, unk);
1077 BSTR tmp;
1078 HRESULT hres;
1080 tmp = a2bstr(alt);
1081 hres = IHTMLImgElement_put_alt(img, tmp);
1082 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1083 SysFreeString(tmp);
1085 _test_img_alt(line, unk, alt);
1088 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1089 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1091 VARIANT_BOOL disabled = 100;
1092 HRESULT hres;
1094 hres = IHTMLInputElement_get_disabled(input, &disabled);
1095 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1096 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1099 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1100 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1102 HRESULT hres;
1104 hres = IHTMLInputElement_put_disabled(input, b);
1105 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1107 _test_input_get_disabled(line, input, b);
1110 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1111 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1113 IHTMLInputElement *input;
1114 BSTR bstr;
1115 HRESULT hres;
1117 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1118 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1119 if(FAILED(hres))
1120 return;
1122 hres = IHTMLInputElement_get_value(input, &bstr);
1123 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1124 if(exval)
1125 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1126 else
1127 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1128 SysFreeString(bstr);
1129 IHTMLInputElement_Release(input);
1132 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1133 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1135 IHTMLInputElement *input;
1136 BSTR bstr;
1137 HRESULT hres;
1139 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1140 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1141 if(FAILED(hres))
1142 return;
1144 bstr = a2bstr(val);
1145 hres = IHTMLInputElement_get_value(input, &bstr);
1146 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1147 SysFreeString(bstr);
1148 IHTMLInputElement_Release(input);
1151 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1152 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1154 IHTMLDOMNode *node = _get_node_iface(line, unk);
1155 IHTMLDOMChildrenCollection *col = NULL;
1156 IDispatch *disp;
1157 HRESULT hres;
1159 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1160 IHTMLDOMNode_Release(node);
1161 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1162 if(FAILED(hres))
1163 return NULL;
1165 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1166 IDispatch_Release(disp);
1167 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1169 return col;
1172 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1173 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1175 IHTMLElement *elem = _get_elem_iface(line, unk);
1176 BSTR class = (void*)0xdeadbeef;
1177 HRESULT hres;
1179 hres = IHTMLElement_get_className(elem, &class);
1180 IHTMLElement_Release(elem);
1181 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1182 if(exclass)
1183 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1184 else
1185 ok_(__FILE__,line) (!class, "class != NULL\n");
1186 SysFreeString(class);
1189 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1190 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1192 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1193 short index = -3;
1194 HRESULT hres;
1196 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1197 IHTMLElement2_Release(elem2);
1198 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1199 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1202 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1203 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1205 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1206 HRESULT hres;
1208 hres = IHTMLElement2_put_tabIndex(elem2, index);
1209 IHTMLElement2_Release(elem2);
1210 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1212 _test_elem_tabindex(line, unk, index);
1215 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1216 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1218 IHTMLElement *elem = _get_elem_iface(line, unk);
1219 BSTR tmp;
1220 HRESULT hres;
1222 tmp = class ? a2bstr(class) : NULL;
1223 hres = IHTMLElement_put_className(elem, tmp);
1224 IHTMLElement_Release(elem);
1225 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1226 SysFreeString(tmp);
1228 _test_elem_class(line, unk, class);
1231 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1232 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
1234 IHTMLDOMNode *node = NULL;
1235 IDispatch *disp;
1236 HRESULT hres;
1238 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1239 ok(hres == S_OK, "item failed: %08x\n", hres);
1241 node = _get_node_iface(line, (IUnknown*)disp);
1242 IDispatch_Release(disp);
1244 return node;
1247 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1248 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1250 IHTMLElement *elem = _get_elem_iface(line, unk);
1251 BSTR id = (void*)0xdeadbeef;
1252 HRESULT hres;
1254 hres = IHTMLElement_get_id(elem, &id);
1255 IHTMLElement_Release(elem);
1256 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1258 if(exid)
1259 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1260 else
1261 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1263 SysFreeString(id);
1266 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1267 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1269 IHTMLElement *elem = _get_elem_iface(line, unk);
1270 BSTR tmp = a2bstr(new_id);
1271 HRESULT hres;
1273 hres = IHTMLElement_put_id(elem, tmp);
1274 IHTMLElement_Release(elem);
1275 SysFreeString(tmp);
1276 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1278 _test_elem_id(line, unk, new_id);
1281 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1282 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1284 IHTMLElement *elem = _get_elem_iface(line, unk);
1285 BSTR title;
1286 HRESULT hres;
1288 hres = IHTMLElement_get_title(elem, &title);
1289 IHTMLElement_Release(elem);
1290 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1291 if(extitle)
1292 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1293 else
1294 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1296 SysFreeString(title);
1299 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1300 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1302 IHTMLElement *elem = _get_elem_iface(line, unk);
1303 BSTR tmp;
1304 HRESULT hres;
1306 tmp = a2bstr(title);
1307 hres = IHTMLElement_put_title(elem, tmp);
1308 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1310 IHTMLElement_Release(elem);
1311 SysFreeString(tmp);
1314 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1315 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1317 IHTMLDOMNode *node = _get_node_iface(line, unk);
1318 VARIANT var;
1319 HRESULT hres;
1321 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1322 IHTMLDOMNode_Release(node);
1323 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1325 if(exval) {
1326 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1327 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1328 }else {
1329 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1332 VariantClear(&var);
1335 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1336 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1338 IHTMLDOMNode *node = _get_node_iface(line, unk);
1339 VARIANT var;
1340 HRESULT hres;
1342 V_VT(&var) = VT_BSTR;
1343 V_BSTR(&var) = a2bstr(val);
1345 hres = IHTMLDOMNode_put_nodeValue(node, var);
1346 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1347 IHTMLDOMNode_Release(node);
1348 VariantClear(&var);
1351 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1352 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1354 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1355 long l;
1356 HRESULT hres;
1358 hres = IHTMLElement2_get_clientWidth(elem, &l);
1359 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1360 hres = IHTMLElement2_get_clientHeight(elem, &l);
1361 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1363 IHTMLElement2_Release(elem);
1366 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1367 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1369 IHTMLElement *elem = NULL;
1370 BSTR tmp;
1371 HRESULT hres;
1373 tmp = a2bstr(tag);
1374 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1375 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1376 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1378 return elem;
1381 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1382 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1384 IHTMLDocument3 *doc3;
1385 IHTMLDOMNode *node = NULL;
1386 BSTR tmp;
1387 HRESULT hres;
1389 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1390 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1392 tmp = a2bstr(text);
1393 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1394 IHTMLDocument3_Release(doc3);
1395 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1396 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1398 return node;
1401 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1402 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1404 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1405 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1406 IHTMLDOMNode *new_child = NULL;
1407 HRESULT hres;
1409 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1410 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1411 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1412 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1414 IHTMLDOMNode_Release(node);
1415 IHTMLDOMNode_Release(child);
1417 return new_child;
1420 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1421 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1423 IHTMLDOMNode *node = _get_node_iface(line, unk);
1424 IHTMLDOMNode *new_node = NULL;
1425 HRESULT hres;
1427 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1428 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1429 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1430 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1432 IHTMLDOMNode_Release(node);
1433 IHTMLDOMNode_Release(new_node);
1436 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1437 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1439 BSTR title = NULL;
1440 HRESULT hres;
1442 hres = IHTMLDocument2_get_title(doc, &title);
1443 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1444 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1445 SysFreeString(title);
1448 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1449 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1451 BSTR tmp;
1452 HRESULT hres;
1454 tmp = a2bstr(title);
1455 hres = IHTMLDocument2_put_title(doc, tmp);
1456 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1457 SysFreeString(tmp);
1460 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1461 const elem_type_t *elem_types, long len)
1463 IDispatch *disp;
1464 VARIANT name, index;
1465 DWORD i;
1466 HRESULT hres;
1468 V_VT(&index) = VT_EMPTY;
1469 V_VT(&name) = VT_BSTR;
1470 V_BSTR(&name) = SysAllocString(n);
1472 hres = IHTMLElementCollection_item(col, name, index, &disp);
1473 ok(hres == S_OK, "item failed: %08x\n", hres);
1475 test_elem_collection((IUnknown*)disp, elem_types, len);
1476 IDispatch_Release(disp);
1477 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1478 if(hres != S_OK)
1479 goto cleanup;
1481 V_VT(&index) = VT_I4;
1483 for(i=0; i<len; i++) {
1484 V_I4(&index) = i;
1485 disp = (void*)0xdeadbeef;
1486 hres = IHTMLElementCollection_item(col, name, index, &disp);
1487 ok(hres == S_OK, "item failed: %08x\n", hres);
1488 ok(disp != NULL, "disp == NULL\n");
1489 if(FAILED(hres) || !disp)
1490 continue;
1492 test_elem_type((IUnknown*)disp, elem_types[i]);
1494 IDispatch_Release(disp);
1497 V_I4(&index) = len;
1498 disp = (void*)0xdeadbeef;
1499 hres = IHTMLElementCollection_item(col, name, index, &disp);
1500 ok(hres == S_OK, "item failed: %08x\n", hres);
1501 ok(disp == NULL, "disp != NULL\n");
1503 V_I4(&index) = -1;
1504 disp = (void*)0xdeadbeef;
1505 hres = IHTMLElementCollection_item(col, name, index, &disp);
1506 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1507 ok(disp == NULL, "disp != NULL\n");
1509 cleanup:
1510 SysFreeString(V_BSTR(&name));
1513 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1515 IHTMLElementCollection *col;
1516 IHTMLElement *elem;
1517 IDispatch *disp = (void*)0xdeadbeef;
1518 VARIANT name, index;
1519 HRESULT hres;
1521 hres = IHTMLDocument2_get_all(doc, &col);
1522 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1523 ok(col != NULL, "col == NULL\n");
1524 if(FAILED(hres) || !col)
1525 return NULL;
1527 V_VT(&index) = VT_EMPTY;
1528 V_VT(&name) = VT_BSTR;
1529 V_BSTR(&name) = SysAllocString(id);
1531 hres = IHTMLElementCollection_item(col, name, index, &disp);
1532 IHTMLElementCollection_Release(col);
1533 SysFreeString(V_BSTR(&name));
1534 ok(hres == S_OK, "item failed: %08x\n", hres);
1535 if(!expect_success) {
1536 ok(disp == NULL, "disp != NULL\n");
1537 return NULL;
1540 ok(disp != NULL, "disp == NULL\n");
1541 if(!disp)
1542 return NULL;
1544 elem = get_elem_iface((IUnknown*)disp);
1545 IDispatch_Release(disp);
1547 return elem;
1550 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1552 IHTMLDocument3 *doc3;
1553 IHTMLElement *elem;
1554 BSTR tmp;
1555 HRESULT hres;
1557 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1558 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1560 tmp = SysAllocString(id);
1561 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1562 SysFreeString(tmp);
1563 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1565 IHTMLDocument3_Release(doc3);
1567 return elem;
1570 static void test_select_elem(IHTMLSelectElement *select)
1572 test_select_type(select, "select-one");
1573 test_select_length(select, 2);
1574 test_select_selidx(select, 0);
1575 test_select_put_selidx(select, 1);
1577 test_select_set_value(select, "val1");
1578 test_select_value(select, "val1");
1581 static void test_create_option_elem(IHTMLDocument2 *doc)
1583 IHTMLOptionElement *option;
1585 option = create_option_elem(doc, "test text", "test value");
1587 test_option_put_text(option, "new text");
1588 test_option_put_value(option, "new value");
1590 IHTMLOptionElement_Release(option);
1593 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1595 IHTMLBodyElement *body;
1596 IHTMLTxtRange *range;
1597 IHTMLElement *elem;
1598 HRESULT hres;
1600 hres = IHTMLDocument2_get_body(doc, &elem);
1601 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1603 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1604 IHTMLElement_Release(elem);
1606 hres = IHTMLBodyElement_createTextRange(body, &range);
1607 IHTMLBodyElement_Release(body);
1608 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1610 return range;
1613 static void test_txtrange(IHTMLDocument2 *doc)
1615 IHTMLTxtRange *body_range, *range, *range2;
1616 IHTMLSelectionObject *selection;
1617 IDispatch *disp_range;
1618 HRESULT hres;
1620 body_range = test_create_body_range(doc);
1622 test_range_text(body_range, "test abc 123\r\nit's text");
1624 hres = IHTMLTxtRange_duplicate(body_range, &range);
1625 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1627 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1628 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1629 test_range_isequal(range, range2, VARIANT_TRUE);
1631 test_range_text(range, "test abc 123\r\nit's text");
1632 test_range_text(body_range, "test abc 123\r\nit's text");
1634 test_range_collapse(range, TRUE);
1635 test_range_isequal(range, range2, VARIANT_FALSE);
1636 test_range_inrange(range, range2, VARIANT_FALSE);
1637 test_range_inrange(range2, range, VARIANT_TRUE);
1638 IHTMLTxtRange_Release(range2);
1640 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1641 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1642 test_range_move(range, characterW, 2, 2);
1643 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1645 test_range_collapse(range, FALSE);
1646 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1648 test_range_collapse(range, FALSE);
1649 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1650 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1651 test_range_move(range, characterW, 2, 2);
1652 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1653 test_range_moveend(range, characterW, -5, -5);
1654 test_range_text(range, NULL);
1655 test_range_moveend(range, characterW, 3, 3);
1656 test_range_text(range, "c 1");
1657 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1658 test_range_collapse(range, TRUE);
1659 test_range_move(range, characterW, 4, 4);
1660 test_range_moveend(range, characterW, 1, 1);
1661 test_range_text(range, " ");
1662 test_range_move(range, wordW, 1, 1);
1663 test_range_moveend(range, characterW, 2, 2);
1664 test_range_text(range, "ab");
1666 IHTMLTxtRange_Release(range);
1668 hres = IHTMLTxtRange_duplicate(body_range, &range);
1669 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1671 test_range_text(range, "test abc 123\r\nit's text");
1672 test_range_move(range, characterW, 3, 3);
1673 test_range_moveend(range, characterW, 1, 1);
1674 test_range_text(range, "t");
1675 test_range_moveend(range, characterW, 3, 3);
1676 test_range_text(range, "t ab");
1677 test_range_moveend(range, characterW, -2, -2);
1678 test_range_text(range, "t ");
1679 test_range_move(range, characterW, 6, 6);
1680 test_range_moveend(range, characterW, 3, 3);
1681 test_range_text(range, "123");
1682 test_range_moveend(range, characterW, 2, 2);
1683 test_range_text(range, "123\r\ni");
1685 IHTMLTxtRange_Release(range);
1687 hres = IHTMLTxtRange_duplicate(body_range, &range);
1688 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1690 test_range_move(range, wordW, 1, 1);
1691 test_range_moveend(range, characterW, 2, 2);
1692 test_range_text(range, "ab");
1694 test_range_move(range, characterW, -2, -2);
1695 test_range_moveend(range, characterW, 2, 2);
1696 test_range_text(range, "t ");
1698 test_range_move(range, wordW, 3, 3);
1699 test_range_move(range, wordW, -2, -2);
1700 test_range_moveend(range, characterW, 2, 2);
1701 test_range_text(range, "ab");
1703 test_range_move(range, characterW, -6, -5);
1704 test_range_moveend(range, characterW, -1, 0);
1705 test_range_moveend(range, characterW, -6, 0);
1706 test_range_move(range, characterW, 2, 2);
1707 test_range_moveend(range, characterW, 2, 2);
1708 test_range_text(range, "st");
1709 test_range_moveend(range, characterW, -6, -4);
1710 test_range_moveend(range, characterW, 2, 2);
1712 IHTMLTxtRange_Release(range);
1714 hres = IHTMLTxtRange_duplicate(body_range, &range);
1715 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1717 test_range_move(range, wordW, 2, 2);
1718 test_range_moveend(range, characterW, 2, 2);
1719 test_range_text(range, "12");
1721 test_range_move(range, characterW, 15, 14);
1722 test_range_move(range, characterW, -2, -2);
1723 test_range_moveend(range, characterW, 3, 2);
1724 test_range_text(range, "t");
1725 test_range_moveend(range, characterW, -1, -1);
1726 test_range_text(range, "t");
1727 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1728 test_range_move(range, characterW, -2, -2);
1729 test_range_moveend(range, characterW, 2, 2);
1730 test_range_text(range, "s ");
1731 test_range_move(range, characterW, 100, 7);
1732 test_range_move(range, wordW, 1, 0);
1733 test_range_move(range, characterW, -2, -2);
1734 test_range_moveend(range, characterW, 3, 2);
1735 test_range_text(range, "t");
1737 IHTMLTxtRange_Release(range);
1739 hres = IHTMLTxtRange_duplicate(body_range, &range);
1740 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1742 test_range_collapse(range, TRUE);
1743 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1744 test_range_put_text(range, "word");
1745 test_range_text(body_range, "wordabc 123\r\nit's text");
1746 test_range_text(range, NULL);
1747 test_range_moveend(range, characterW, 3, 3);
1748 test_range_text(range, "abc");
1749 test_range_movestart(range, characterW, -2, -2);
1750 test_range_text(range, "rdabc");
1751 test_range_movestart(range, characterW, 3, 3);
1752 test_range_text(range, "bc");
1753 test_range_movestart(range, characterW, 4, 4);
1754 test_range_text(range, NULL);
1755 test_range_movestart(range, characterW, -3, -3);
1756 test_range_text(range, "c 1");
1757 test_range_movestart(range, characterW, -7, -6);
1758 test_range_text(range, "wordabc 1");
1759 test_range_movestart(range, characterW, 100, 22);
1760 test_range_text(range, NULL);
1762 IHTMLTxtRange_Release(range);
1763 IHTMLTxtRange_Release(body_range);
1765 hres = IHTMLDocument2_get_selection(doc, &selection);
1766 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1768 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1769 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1770 IHTMLSelectionObject_Release(selection);
1772 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1773 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1774 IDispatch_Release(disp_range);
1776 test_range_text(range, NULL);
1777 test_range_moveend(range, characterW, 3, 3);
1778 test_range_text(range, "wor");
1779 test_range_parent(range, ET_BODY);
1780 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1781 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1782 test_range_move(range, characterW, 3, 3);
1783 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1784 test_range_moveend(range, characterW, -4, -4);
1785 test_range_put_text(range, "abc def ");
1786 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1787 test_range_move(range, wordW, 1, 1);
1788 test_range_movestart(range, characterW, -1, -1);
1789 test_range_text(range, " ");
1790 test_range_move(range, wordW, 1, 1);
1791 test_range_moveend(range, characterW, 3, 3);
1792 test_range_text(range, "def");
1793 test_range_put_text(range, "xyz");
1794 test_range_moveend(range, characterW, 1, 1);
1795 test_range_move(range, wordW, 1, 1);
1796 test_range_moveend(range, characterW, 2, 2);
1797 test_range_text(range, "ab");
1799 IHTMLTxtRange_Release(range);
1802 static void test_txtrange2(IHTMLDocument2 *doc)
1804 IHTMLTxtRange *range;
1806 range = test_create_body_range(doc);
1808 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1809 test_range_move(range, characterW, 5, 5);
1810 test_range_moveend(range, characterW, 1, 1);
1811 test_range_text(range, "2");
1812 test_range_move(range, characterW, -3, -3);
1813 test_range_moveend(range, characterW, 3, 3);
1814 test_range_text(range, "c\r\n\r\n1");
1815 test_range_collapse(range, VARIANT_FALSE);
1816 test_range_moveend(range, characterW, 4, 4);
1817 test_range_text(range, "23");
1818 test_range_moveend(range, characterW, 1, 1);
1819 test_range_text(range, "23\r\n\r\n\r\nd");
1820 test_range_moveend(range, characterW, -1, -1);
1821 test_range_text(range, "23");
1822 test_range_moveend(range, characterW, -1, -1);
1823 test_range_text(range, "23");
1824 test_range_moveend(range, characterW, -2, -2);
1825 test_range_text(range, "2");
1827 IHTMLTxtRange_Release(range);
1830 static void test_compatmode(IHTMLDocument2 *doc)
1832 IHTMLDocument5 *doc5;
1833 BSTR mode;
1834 HRESULT hres;
1836 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1837 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1838 if(FAILED(hres))
1839 return;
1841 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1842 IHTMLDocument5_Release(doc5);
1843 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1844 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1845 SysFreeString(mode);
1848 static void test_location(IHTMLDocument2 *doc)
1850 IHTMLLocation *location, *location2;
1851 ULONG ref;
1852 HRESULT hres;
1854 hres = IHTMLDocument2_get_location(doc, &location);
1855 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1857 hres = IHTMLDocument2_get_location(doc, &location2);
1858 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1860 ok(location == location2, "location != location2\n");
1862 test_ifaces((IUnknown*)location, location_iids);
1864 IHTMLLocation_Release(location2);
1865 ref = IHTMLLocation_Release(location);
1866 ok(!ref, "location chould be destroyed here\n");
1869 static void test_navigator(IHTMLDocument2 *doc)
1871 IHTMLWindow2 *window;
1872 IOmNavigator *navigator, *navigator2;
1873 ULONG ref;
1874 BSTR bstr;
1875 HRESULT hres;
1877 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1878 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1880 hres = IHTMLWindow2_get_navigator(window, &navigator);
1881 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1882 ok(navigator != NULL, "navigator == NULL\n");
1883 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1885 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1886 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1887 ok(navigator != navigator2, "navigator2 != navihgator\n");
1889 IHTMLWindow2_Release(window);
1890 IOmNavigator_Release(navigator2);
1892 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
1893 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
1894 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
1895 SysFreeString(bstr);
1897 bstr = NULL;
1898 hres = IOmNavigator_get_platform(navigator, &bstr);
1899 ok(hres == S_OK, "get_appMinorVersion failed: %08x\n", hres);
1900 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
1901 SysFreeString(bstr);
1903 ref = IOmNavigator_Release(navigator);
1904 ok(!ref, "navigator should be destroyed here\n");
1907 static void test_default_style(IHTMLStyle *style)
1909 VARIANT_BOOL b;
1910 VARIANT v;
1911 BSTR str;
1912 HRESULT hres;
1914 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
1916 str = (void*)0xdeadbeef;
1917 hres = IHTMLStyle_get_fontFamily(style, &str);
1918 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
1919 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
1921 str = (void*)0xdeadbeef;
1922 hres = IHTMLStyle_get_fontWeight(style, &str);
1923 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
1924 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
1926 str = (void*)0xdeadbeef;
1927 hres = IHTMLStyle_get_display(style, &str);
1928 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1929 ok(!str, "display = %s\n", dbgstr_w(str));
1931 str = (void*)0xdeadbeef;
1932 hres = IHTMLStyle_get_visibility(style, &str);
1933 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
1934 ok(!str, "visibility = %s\n", dbgstr_w(str));
1936 V_VT(&v) = VT_NULL;
1937 hres = IHTMLStyle_get_fontSize(style, &v);
1938 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
1939 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
1940 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
1942 V_VT(&v) = VT_NULL;
1943 hres = IHTMLStyle_get_color(style, &v);
1944 ok(hres == S_OK, "get_color failed: %08x\n", hres);
1945 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
1946 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1948 b = 0xfefe;
1949 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1950 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1951 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1953 b = 0xfefe;
1954 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1955 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1956 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1958 V_VT(&v) = VT_EMPTY;
1959 hres = IHTMLStyle_get_width(style, &v);
1960 ok(hres == S_OK, "get_width failed: %08x\n", hres);
1961 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
1962 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
1964 V_VT(&v) = VT_BSTR;
1965 V_BSTR(&v) = a2bstr("auto");
1966 hres = IHTMLStyle_put_width(style, v);
1967 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1968 VariantClear(&v);
1970 V_VT(&v) = VT_EMPTY;
1971 hres = IHTMLStyle_get_width(style, &v);
1972 ok(hres == S_OK, "get_width failed: %08x\n", hres);
1973 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
1974 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
1975 VariantClear(&v);
1978 static void test_default_selection(IHTMLDocument2 *doc)
1980 IHTMLSelectionObject *selection;
1981 IHTMLTxtRange *range;
1982 IDispatch *disp;
1983 BSTR str;
1984 HRESULT hres;
1986 hres = IHTMLDocument2_get_selection(doc, &selection);
1987 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1989 hres = IHTMLSelectionObject_get_type(selection, &str);
1990 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1991 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1992 SysFreeString(str);
1994 hres = IHTMLSelectionObject_createRange(selection, &disp);
1995 IHTMLSelectionObject_Release(selection);
1996 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1998 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1999 IDispatch_Release(disp);
2000 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2002 test_range_text(range, NULL);
2003 IHTMLTxtRange_Release(range);
2006 static void test_default_body(IHTMLBodyElement *body)
2008 long l;
2009 BSTR bstr;
2010 HRESULT hres;
2012 bstr = (void*)0xdeadbeef;
2013 hres = IHTMLBodyElement_get_background(body, &bstr);
2014 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2015 ok(bstr == NULL, "bstr != NULL\n");
2017 l = elem_get_scroll_height((IUnknown*)body);
2018 ok(l != -1, "scrollHeight == -1\n");
2019 l = elem_get_scroll_width((IUnknown*)body);
2020 ok(l != -1, "scrollWidth == -1\n");
2021 l = elem_get_scroll_top((IUnknown*)body);
2022 ok(!l, "scrollWidth = %ld\n", l);
2025 static void test_window(IHTMLDocument2 *doc)
2027 IHTMLWindow2 *window, *window2, *self;
2028 IHTMLDocument2 *doc2 = NULL;
2029 IDispatch *disp;
2030 HRESULT hres;
2032 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2033 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2034 test_ifaces((IUnknown*)window, window_iids);
2035 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2037 hres = IHTMLWindow2_get_document(window, &doc2);
2038 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2039 ok(doc2 != NULL, "doc2 == NULL\n");
2041 IHTMLDocument_Release(doc2);
2043 hres = IHTMLWindow2_get_window(window, &window2);
2044 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2045 ok(window2 != NULL, "window2 == NULL\n");
2047 hres = IHTMLWindow2_get_self(window, &self);
2048 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2049 ok(window2 != NULL, "self == NULL\n");
2051 ok(self == window2, "self != window2\n");
2053 IHTMLWindow2_Release(window2);
2054 IHTMLWindow2_Release(self);
2056 disp = NULL;
2057 hres = IHTMLDocument2_get_Script(doc, &disp);
2058 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2059 ok(disp == (void*)window, "disp != window\n");
2060 IDispatch_Release(disp);
2062 IHTMLWindow2_Release(window);
2065 static void test_defaults(IHTMLDocument2 *doc)
2067 IHTMLStyleSheetsCollection *stylesheetcol;
2068 IHTMLBodyElement *body;
2069 IHTMLElement *elem;
2070 IHTMLStyle *style;
2071 long l;
2072 HRESULT hres;
2074 hres = IHTMLDocument2_get_body(doc, &elem);
2075 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2077 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2078 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2079 test_default_body(body);
2080 IHTMLBodyElement_Release(body);
2082 hres = IHTMLElement_get_style(elem, &style);
2083 IHTMLElement_Release(elem);
2084 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2086 test_default_style(style);
2087 test_window(doc);
2088 test_compatmode(doc);
2089 test_location(doc);
2090 test_navigator(doc);
2092 IHTMLStyle_Release(style);
2094 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2095 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2097 l = 0xdeadbeef;
2098 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2099 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2100 ok(l == 0, "length = %ld\n", l);
2102 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2104 test_default_selection(doc);
2105 test_doc_title(doc, "");
2108 static void test_stylesheet(IDispatch *disp)
2110 IHTMLStyleSheetRulesCollection *col = NULL;
2111 IHTMLStyleSheet *stylesheet;
2112 HRESULT hres;
2114 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2115 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2117 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2118 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2119 ok(col != NULL, "col == NULL\n");
2121 IHTMLStyleSheetRulesCollection_Release(col);
2122 IHTMLStyleSheet_Release(stylesheet);
2125 static void test_stylesheets(IHTMLDocument2 *doc)
2127 IHTMLStyleSheetsCollection *col = NULL;
2128 VARIANT idx, res;
2129 long len = 0;
2130 HRESULT hres;
2132 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2133 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2134 ok(col != NULL, "col == NULL\n");
2136 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2137 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2138 ok(len == 1, "len=%ld\n", len);
2140 VariantInit(&res);
2141 V_VT(&idx) = VT_I4;
2142 V_I4(&idx) = 0;
2144 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2145 ok(hres == S_OK, "item failed: %08x\n", hres);
2146 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2147 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2148 test_stylesheet(V_DISPATCH(&res));
2149 VariantClear(&res);
2151 V_VT(&res) = VT_I4;
2152 V_VT(&idx) = VT_I4;
2153 V_I4(&idx) = 1;
2155 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2156 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2157 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2158 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2159 VariantClear(&res);
2161 IHTMLStyleSheetsCollection_Release(col);
2164 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2166 IDispatchEx *dispex;
2167 IHTMLDOMNode *node;
2168 DISPPARAMS dp = {NULL, NULL, 0, 0};
2169 VARIANT var;
2170 EXCEPINFO ei;
2171 long type;
2172 DISPID id;
2173 BSTR bstr;
2174 HRESULT hres;
2176 static const WCHAR w0[] = {'0',0};
2177 static const WCHAR w100[] = {'1','0','0',0};
2179 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2180 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2182 bstr = SysAllocString(w0);
2183 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2184 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2185 SysFreeString(bstr);
2187 VariantInit(&var);
2188 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2189 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2190 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2191 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2192 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2193 type = get_node_type((IUnknown*)node);
2194 ok(type == 3, "type=%ld\n", type);
2195 IHTMLDOMNode_Release(node);
2196 VariantClear(&var);
2198 bstr = SysAllocString(w100);
2199 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2200 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2201 SysFreeString(bstr);
2203 IDispatchEx_Release(dispex);
2208 static void test_elems(IHTMLDocument2 *doc)
2210 IHTMLElementCollection *col;
2211 IHTMLDOMChildrenCollection *child_col;
2212 IHTMLElement *elem;
2213 IHTMLDOMNode *node, *node2;
2214 IDispatch *disp;
2215 long type;
2216 HRESULT hres;
2218 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2219 static const WCHAR inW[] = {'i','n',0};
2220 static const WCHAR xW[] = {'x',0};
2221 static const WCHAR sW[] = {'s',0};
2222 static const WCHAR scW[] = {'s','c',0};
2223 static const WCHAR xxxW[] = {'x','x','x',0};
2225 static const elem_type_t all_types[] = {
2226 ET_HTML,
2227 ET_HEAD,
2228 ET_TITLE,
2229 ET_STYLE,
2230 ET_BODY,
2231 ET_COMMENT,
2232 ET_A,
2233 ET_INPUT,
2234 ET_SELECT,
2235 ET_OPTION,
2236 ET_OPTION,
2237 ET_TEXTAREA,
2238 ET_TABLE,
2239 ET_TBODY,
2240 ET_SCRIPT,
2241 ET_TEST,
2242 ET_IMG
2245 static const elem_type_t item_types[] = {
2246 ET_A,
2247 ET_OPTION,
2248 ET_TEXTAREA
2251 hres = IHTMLDocument2_get_all(doc, &col);
2252 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2253 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2254 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2255 IHTMLElementCollection_Release(col);
2257 elem = get_doc_elem(doc);
2258 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
2259 hres = IHTMLElement_get_all(elem, &disp);
2260 IHTMLElement_Release(elem);
2261 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2263 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2264 IDispatch_Release(disp);
2265 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2266 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
2267 IHTMLElementCollection_Release(col);
2269 get_elem_by_id(doc, xxxW, FALSE);
2270 elem = get_doc_elem_by_id(doc, xxxW);
2271 ok(!elem, "elem != NULL\n");
2273 elem = get_doc_elem_by_id(doc, sW);
2274 ok(elem != NULL, "elem == NULL\n");
2275 if(elem) {
2276 test_elem_type((IUnknown*)elem, ET_SELECT);
2277 test_elem_attr(elem, xxxW, NULL);
2278 test_elem_attr(elem, idW, sW);
2279 test_elem_class((IUnknown*)elem, NULL);
2280 test_elem_set_class((IUnknown*)elem, "cl");
2281 test_elem_set_class((IUnknown*)elem, NULL);
2282 test_elem_tabindex((IUnknown*)elem, 0);
2283 test_elem_set_tabindex((IUnknown*)elem, 1);
2285 node = test_node_get_parent((IUnknown*)elem);
2286 ok(node != NULL, "node == NULL\n");
2287 test_node_name((IUnknown*)node, "BODY");
2288 node2 = test_node_get_parent((IUnknown*)node);
2289 IHTMLDOMNode_Release(node);
2290 ok(node2 != NULL, "node == NULL\n");
2291 test_node_name((IUnknown*)node2, "HTML");
2292 node = test_node_get_parent((IUnknown*)node2);
2293 IHTMLDOMNode_Release(node2);
2294 ok(node != NULL, "node == NULL\n");
2295 test_node_name((IUnknown*)node, "#document");
2296 type = get_node_type((IUnknown*)node);
2297 ok(type == 9, "type=%ld, expected 9\n", type);
2298 node2 = test_node_get_parent((IUnknown*)node);
2299 IHTMLDOMNode_Release(node);
2300 ok(node2 == NULL, "node != NULL\n");
2302 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
2303 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
2304 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
2306 IHTMLElement_Release(elem);
2309 elem = get_elem_by_id(doc, sW, TRUE);
2310 if(elem) {
2311 IHTMLSelectElement *select;
2313 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
2314 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
2316 test_select_elem(select);
2318 test_elem_title((IUnknown*)select, NULL);
2319 test_elem_set_title((IUnknown*)select, "Title");
2320 test_elem_title((IUnknown*)select, "Title");
2321 test_elem_offset((IUnknown*)select);
2323 node = get_first_child((IUnknown*)select);
2324 ok(node != NULL, "node == NULL\n");
2325 if(node) {
2326 test_elem_type((IUnknown*)node, ET_OPTION);
2327 IHTMLDOMNode_Release(node);
2330 type = get_node_type((IUnknown*)select);
2331 ok(type == 1, "type=%ld\n", type);
2333 IHTMLSelectElement_Release(select);
2334 IHTMLElement_Release(elem);
2337 elem = get_elem_by_id(doc, scW, TRUE);
2338 if(elem) {
2339 IHTMLScriptElement *script;
2340 BSTR type;
2342 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
2343 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
2345 hres = IHTMLScriptElement_get_type(script, &type);
2346 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2347 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
2348 SysFreeString(type);
2350 IHTMLScriptElement_Release(script);
2353 elem = get_elem_by_id(doc, inW, TRUE);
2354 if(elem) {
2355 IHTMLInputElement *input;
2357 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
2358 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2360 test_elem_id((IUnknown*)elem, "in");
2361 test_elem_put_id((IUnknown*)elem, "newin");
2362 test_input_get_disabled(input, VARIANT_FALSE);
2363 test_input_set_disabled(input, VARIANT_TRUE);
2364 test_input_set_disabled(input, VARIANT_FALSE);
2365 test_elem_client_size((IUnknown*)elem);
2367 test_node_get_value_str((IUnknown*)elem, NULL);
2368 test_node_put_value_str((IUnknown*)elem, "test");
2369 test_node_get_value_str((IUnknown*)elem, NULL);
2370 test_input_value((IUnknown*)elem, NULL);
2371 test_input_put_value((IUnknown*)elem, "test");
2372 test_input_value((IUnknown*)elem, NULL);
2373 test_elem_class((IUnknown*)elem, "testclass");
2374 test_elem_tabindex((IUnknown*)elem, 2);
2375 test_elem_set_tabindex((IUnknown*)elem, 3);
2376 test_elem_title((IUnknown*)elem, "test title");
2378 IHTMLInputElement_Release(input);
2379 IHTMLElement_Release(elem);
2382 elem = get_elem_by_id(doc, imgidW, TRUE);
2383 if(elem) {
2384 test_img_set_src((IUnknown*)elem, "about:blank");
2385 test_img_alt((IUnknown*)elem, NULL);
2386 test_img_set_alt((IUnknown*)elem, "alt test");
2387 IHTMLElement_Release(elem);
2390 hres = IHTMLDocument2_get_body(doc, &elem);
2391 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2393 node = get_first_child((IUnknown*)elem);
2394 ok(node != NULL, "node == NULL\n");
2395 if(node) {
2396 test_ifaces((IUnknown*)node, text_iids);
2397 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2399 node2 = get_first_child((IUnknown*)node);
2400 ok(!node2, "node2 != NULL\n");
2402 type = get_node_type((IUnknown*)node);
2403 ok(type == 3, "type=%ld\n", type);
2405 test_node_get_value_str((IUnknown*)node, "text test");
2406 test_node_put_value_str((IUnknown*)elem, "test text");
2407 test_node_get_value_str((IUnknown*)node, "text test");
2409 IHTMLDOMNode_Release(node);
2412 child_col = get_child_nodes((IUnknown*)elem);
2413 ok(child_col != NULL, "child_coll == NULL\n");
2414 if(child_col) {
2415 long length = 0;
2417 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
2419 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
2420 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2421 ok(length, "length=0\n");
2423 node = get_child_item(child_col, 0);
2424 ok(node != NULL, "node == NULL\n");
2425 if(node) {
2426 type = get_node_type((IUnknown*)node);
2427 ok(type == 3, "type=%ld\n", type);
2428 IHTMLDOMNode_Release(node);
2431 node = get_child_item(child_col, 1);
2432 ok(node != NULL, "node == NULL\n");
2433 if(node) {
2434 type = get_node_type((IUnknown*)node);
2435 ok(type == 8, "type=%ld\n", type);
2437 test_elem_id((IUnknown*)node, NULL);
2438 IHTMLDOMNode_Release(node);
2441 disp = (void*)0xdeadbeef;
2442 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
2443 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2444 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2446 disp = (void*)0xdeadbeef;
2447 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
2448 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2449 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2451 test_child_col_disp(child_col);
2453 IHTMLDOMChildrenCollection_Release(child_col);
2456 IHTMLElement_Release(elem);
2458 test_stylesheets(doc);
2459 test_create_option_elem(doc);
2461 test_doc_title(doc, "test");
2462 test_doc_set_title(doc, "test title");
2463 test_doc_title(doc, "test title");
2466 static void test_create_elems(IHTMLDocument2 *doc)
2468 IHTMLElement *elem, *body, *elem2;
2469 IHTMLDOMNode *node;
2470 IDispatch *disp;
2471 long type;
2472 HRESULT hres;
2474 static const elem_type_t types1[] = { ET_TESTG };
2476 elem = test_create_elem(doc, "TEST");
2477 test_elem_tag((IUnknown*)elem, "TEST");
2478 type = get_node_type((IUnknown*)elem);
2479 ok(type == 1, "type=%ld\n", type);
2480 test_ifaces((IUnknown*)elem, elem_iids);
2481 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
2483 hres = IHTMLDocument2_get_body(doc, &body);
2484 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2485 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2487 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
2488 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
2489 elem2 = get_elem_iface((IUnknown*)node);
2490 IHTMLElement_Release(elem2);
2492 hres = IHTMLElement_get_all(body, &disp);
2493 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2494 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
2495 IDispatch_Release(disp);
2497 test_node_remove_child((IUnknown*)body, node);
2499 hres = IHTMLElement_get_all(body, &disp);
2500 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2501 test_elem_collection((IUnknown*)disp, NULL, 0);
2502 IDispatch_Release(disp);
2503 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2505 IHTMLElement_Release(body);
2506 IHTMLElement_Release(elem);
2507 IHTMLDOMNode_Release(node);
2509 node = test_create_text(doc, "test");
2510 test_ifaces((IUnknown*)node, text_iids);
2511 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2512 IHTMLDOMNode_Release(node);
2515 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
2517 IOleCommandTarget *cmdtrg;
2518 HRESULT hres;
2520 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2521 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
2523 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
2524 ok(hres == S_OK, "Exec failed: %08x\n", hres);
2526 IOleCommandTarget_Release(cmdtrg);
2529 static void test_indent(IHTMLDocument2 *doc)
2531 IHTMLElementCollection *col;
2532 IHTMLTxtRange *range;
2533 HRESULT hres;
2535 static const elem_type_t all_types[] = {
2536 ET_HTML,
2537 ET_HEAD,
2538 ET_TITLE,
2539 ET_BODY,
2540 ET_BR,
2541 ET_A,
2544 static const elem_type_t indent_types[] = {
2545 ET_HTML,
2546 ET_HEAD,
2547 ET_TITLE,
2548 ET_BODY,
2549 ET_BLOCKQUOTE,
2550 ET_P,
2551 ET_BR,
2552 ET_A,
2555 hres = IHTMLDocument2_get_all(doc, &col);
2556 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2557 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2558 IHTMLElementCollection_Release(col);
2560 range = test_create_body_range(doc);
2561 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
2562 IHTMLTxtRange_Release(range);
2564 hres = IHTMLDocument2_get_all(doc, &col);
2565 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2566 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
2567 IHTMLElementCollection_Release(col);
2570 static IHTMLDocument2 *notif_doc;
2571 static BOOL doc_complete;
2573 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2574 REFIID riid, void**ppv)
2576 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2577 *ppv = iface;
2578 return S_OK;
2581 ok(0, "unexpected call\n");
2582 return E_NOINTERFACE;
2585 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2587 return 2;
2590 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2592 return 1;
2595 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2597 if(dispID == DISPID_READYSTATE){
2598 BSTR state;
2599 HRESULT hres;
2601 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
2603 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2604 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2606 if(!lstrcmpW(state, completeW))
2607 doc_complete = TRUE;
2609 SysFreeString(state);
2612 return S_OK;
2615 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2617 ok(0, "unexpected call\n");
2618 return E_NOTIMPL;
2621 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2622 PropertyNotifySink_QueryInterface,
2623 PropertyNotifySink_AddRef,
2624 PropertyNotifySink_Release,
2625 PropertyNotifySink_OnChanged,
2626 PropertyNotifySink_OnRequestEdit
2629 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2631 static IHTMLDocument2 *create_doc_with_string(const char *str)
2633 IPersistStreamInit *init;
2634 IStream *stream;
2635 IHTMLDocument2 *doc;
2636 HGLOBAL mem;
2637 SIZE_T len;
2639 notif_doc = doc = create_document();
2640 if(!doc)
2641 return NULL;
2643 doc_complete = FALSE;
2644 len = strlen(str);
2645 mem = GlobalAlloc(0, len);
2646 memcpy(mem, str, len);
2647 CreateStreamOnHGlobal(mem, TRUE, &stream);
2649 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2651 IPersistStreamInit_Load(init, stream);
2652 IPersistStreamInit_Release(init);
2653 IStream_Release(stream);
2655 return doc;
2658 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2660 IConnectionPointContainer *container;
2661 IConnectionPoint *cp;
2662 DWORD cookie;
2663 HRESULT hres;
2665 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2666 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2668 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2669 IConnectionPointContainer_Release(container);
2670 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2672 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2673 IConnectionPoint_Release(cp);
2674 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2677 typedef void (*domtest_t)(IHTMLDocument2*);
2679 static void run_domtest(const char *str, domtest_t test)
2681 IHTMLDocument2 *doc;
2682 IHTMLElement *body = NULL;
2683 ULONG ref;
2684 MSG msg;
2685 HRESULT hres;
2687 doc = create_doc_with_string(str);
2688 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2690 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
2691 TranslateMessage(&msg);
2692 DispatchMessage(&msg);
2695 hres = IHTMLDocument2_get_body(doc, &body);
2696 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2698 if(body) {
2699 IHTMLElement_Release(body);
2700 test(doc);
2701 }else {
2702 skip("Could not get document body. Assuming no Gecko installed.\n");
2705 ref = IHTMLDocument2_Release(doc);
2706 ok(!ref, "ref = %d\n", ref);
2709 static void gecko_installer_workaround(BOOL disable)
2711 HKEY hkey;
2712 DWORD res;
2714 static BOOL has_url = FALSE;
2715 static char url[2048];
2717 if(!disable && !has_url)
2718 return;
2720 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2721 if(res != ERROR_SUCCESS)
2722 return;
2724 if(disable) {
2725 DWORD type, size = sizeof(url);
2727 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2728 if(res == ERROR_SUCCESS && type == REG_SZ)
2729 has_url = TRUE;
2731 RegDeleteValue(hkey, "GeckoUrl");
2732 }else {
2733 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2736 RegCloseKey(hkey);
2739 START_TEST(dom)
2741 gecko_installer_workaround(TRUE);
2742 CoInitialize(NULL);
2744 run_domtest(doc_str1, test_doc_elem);
2745 run_domtest(range_test_str, test_txtrange);
2746 run_domtest(range_test2_str, test_txtrange2);
2747 run_domtest(elem_test_str, test_elems);
2748 run_domtest(doc_blank, test_create_elems);
2749 run_domtest(doc_blank, test_defaults);
2750 run_domtest(indent_test_str, test_indent);
2752 CoUninitialize();
2753 gecko_installer_workaround(FALSE);