mshtml: Added IHTMLStyle::[get|put]_left implementation.
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob1105f0f7773475089450fe03039ea82a94a54f49
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 id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td>td1 text</td><td>td2 text</td></tr></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 ET_TR,
89 ET_TD
90 } elem_type_t;
92 static const IID * const none_iids[] = {
93 &IID_IUnknown,
94 NULL
97 static const IID * const elem_iids[] = {
98 &IID_IHTMLDOMNode,
99 &IID_IHTMLDOMNode2,
100 &IID_IHTMLElement,
101 &IID_IHTMLElement2,
102 &IID_IDispatchEx,
103 &IID_IConnectionPointContainer,
104 NULL
107 static const IID * const body_iids[] = {
108 &IID_IHTMLDOMNode,
109 &IID_IHTMLDOMNode2,
110 &IID_IHTMLElement,
111 &IID_IHTMLElement2,
112 &IID_IHTMLTextContainer,
113 &IID_IHTMLBodyElement,
114 &IID_IDispatchEx,
115 &IID_IConnectionPointContainer,
116 NULL
119 static const IID * const anchor_iids[] = {
120 &IID_IHTMLDOMNode,
121 &IID_IHTMLDOMNode2,
122 &IID_IHTMLElement,
123 &IID_IHTMLElement2,
124 &IID_IHTMLAnchorElement,
125 &IID_IDispatchEx,
126 &IID_IConnectionPointContainer,
127 NULL
130 static const IID * const input_iids[] = {
131 &IID_IHTMLDOMNode,
132 &IID_IHTMLDOMNode2,
133 &IID_IHTMLElement,
134 &IID_IHTMLElement2,
135 &IID_IHTMLInputElement,
136 &IID_IHTMLInputTextElement,
137 &IID_IDispatchEx,
138 &IID_IConnectionPointContainer,
139 NULL
142 static const IID * const select_iids[] = {
143 &IID_IHTMLDOMNode,
144 &IID_IHTMLDOMNode2,
145 &IID_IHTMLElement,
146 &IID_IHTMLElement2,
147 &IID_IHTMLSelectElement,
148 &IID_IDispatchEx,
149 &IID_IConnectionPointContainer,
150 NULL
153 static const IID * const textarea_iids[] = {
154 &IID_IHTMLDOMNode,
155 &IID_IHTMLDOMNode2,
156 &IID_IHTMLElement,
157 &IID_IHTMLElement2,
158 &IID_IHTMLTextAreaElement,
159 &IID_IDispatchEx,
160 &IID_IConnectionPointContainer,
161 NULL
164 static const IID * const option_iids[] = {
165 &IID_IHTMLDOMNode,
166 &IID_IHTMLDOMNode2,
167 &IID_IHTMLElement,
168 &IID_IHTMLElement2,
169 &IID_IHTMLOptionElement,
170 &IID_IDispatchEx,
171 &IID_IConnectionPointContainer,
172 NULL
175 static const IID * const table_iids[] = {
176 &IID_IHTMLDOMNode,
177 &IID_IHTMLDOMNode2,
178 &IID_IHTMLElement,
179 &IID_IHTMLElement2,
180 &IID_IHTMLTable,
181 &IID_IDispatchEx,
182 &IID_IConnectionPointContainer,
183 NULL
186 static const IID * const script_iids[] = {
187 &IID_IHTMLDOMNode,
188 &IID_IHTMLDOMNode2,
189 &IID_IHTMLElement,
190 &IID_IHTMLElement2,
191 &IID_IHTMLScriptElement,
192 &IID_IDispatchEx,
193 &IID_IConnectionPointContainer,
194 NULL
197 static const IID * const text_iids[] = {
198 &IID_IHTMLDOMNode,
199 &IID_IHTMLDOMNode2,
200 &IID_IHTMLDOMTextNode,
201 NULL
204 static const IID * const location_iids[] = {
205 &IID_IDispatch,
206 &IID_IHTMLLocation,
207 NULL
210 static const IID * const window_iids[] = {
211 &IID_IDispatch,
212 &IID_IHTMLWindow2,
213 &IID_IHTMLWindow3,
214 &IID_IDispatchEx,
215 NULL
218 static const IID * const comment_iids[] = {
219 &IID_IHTMLDOMNode,
220 &IID_IHTMLDOMNode2,
221 &IID_IHTMLElement,
222 &IID_IHTMLElement2,
223 &IID_IHTMLCommentElement,
224 &IID_IDispatchEx,
225 &IID_IConnectionPointContainer,
226 NULL
229 static const IID * const img_iids[] = {
230 &IID_IHTMLDOMNode,
231 &IID_IHTMLDOMNode2,
232 &IID_IHTMLElement,
233 &IID_IHTMLElement2,
234 &IID_IDispatchEx,
235 &IID_IHTMLImgElement,
236 &IID_IConnectionPointContainer,
237 NULL
240 static const IID * const tr_iids[] = {
241 &IID_IHTMLDOMNode,
242 &IID_IHTMLDOMNode2,
243 &IID_IHTMLElement,
244 &IID_IHTMLElement2,
245 &IID_IDispatchEx,
246 &IID_IHTMLTableRow,
247 &IID_IConnectionPointContainer,
248 NULL
251 static const IID * const td_iids[] = {
252 &IID_IHTMLDOMNode,
253 &IID_IHTMLDOMNode2,
254 &IID_IHTMLElement,
255 &IID_IHTMLElement2,
256 &IID_IDispatchEx,
257 &IID_IConnectionPointContainer,
258 NULL
261 static const IID * const generic_iids[] = {
262 &IID_IHTMLDOMNode,
263 &IID_IHTMLDOMNode2,
264 &IID_IHTMLElement,
265 &IID_IHTMLElement2,
266 &IID_IHTMLGenericElement,
267 &IID_IDispatchEx,
268 &IID_IConnectionPointContainer,
269 NULL
272 static const IID * const style_iids[] = {
273 &IID_IUnknown,
274 &IID_IDispatch,
275 &IID_IDispatchEx,
276 &IID_IHTMLStyle,
277 &IID_IHTMLStyle2,
278 NULL
281 static const IID * const cstyle_iids[] = {
282 &IID_IUnknown,
283 &IID_IDispatch,
284 &IID_IDispatchEx,
285 &IID_IHTMLCurrentStyle,
286 NULL
289 typedef struct {
290 const char *tag;
291 REFIID *iids;
292 const IID *dispiid;
293 } elem_type_info_t;
295 static const elem_type_info_t elem_type_infos[] = {
296 {"", none_iids, NULL},
297 {"HTML", elem_iids, NULL},
298 {"HEAD", elem_iids, NULL},
299 {"TITLE", elem_iids, NULL},
300 {"BODY", body_iids, &DIID_DispHTMLBody},
301 {"A", anchor_iids, NULL},
302 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
303 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
304 {"TEXTAREA", textarea_iids, NULL},
305 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
306 {"STYLE", elem_iids, NULL},
307 {"BLOCKQUOTE",elem_iids, NULL},
308 {"P", elem_iids, NULL},
309 {"BR", elem_iids, NULL},
310 {"TABLE", table_iids, &DIID_DispHTMLTable},
311 {"TBODY", elem_iids, NULL},
312 {"SCRIPT", script_iids, NULL},
313 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
314 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
315 {"!", comment_iids, &DIID_DispHTMLCommentElement},
316 {"IMG", img_iids, &DIID_DispHTMLImg},
317 {"TR", tr_iids, &DIID_DispHTMLTableRow},
318 {"TD", td_iids, NULL}
321 static const char *dbgstr_w(LPCWSTR str)
323 static char buf[512];
324 if(!str)
325 return "(null)";
326 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
327 return buf;
330 static const char *dbgstr_guid(REFIID riid)
332 static char buf[50];
334 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
335 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
336 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
337 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
339 return buf;
342 static int strcmp_wa(LPCWSTR strw, const char *stra)
344 WCHAR buf[512];
345 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
346 return lstrcmpW(strw, buf);
349 static BSTR a2bstr(const char *str)
351 BSTR ret;
352 int len;
354 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
355 ret = SysAllocStringLen(NULL, len);
356 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
358 return ret;
361 static IHTMLDocument2 *create_document(void)
363 IHTMLDocument2 *doc;
364 HRESULT hres;
366 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
367 &IID_IHTMLDocument2, (void**)&doc);
368 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
370 return doc;
373 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
374 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
376 const IID * const *piid;
377 IUnknown *unk;
378 HRESULT hres;
380 for(piid = iids; *piid; piid++) {
381 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
382 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
383 if(SUCCEEDED(hres))
384 IUnknown_Release(unk);
388 #define test_disp(u,id) _test_disp(__LINE__,u,id)
389 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
391 IDispatchEx *dispex;
392 ITypeInfo *typeinfo;
393 UINT ticnt;
394 HRESULT hres;
396 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
397 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
398 if(FAILED(hres))
399 return;
401 ticnt = 0xdeadbeef;
402 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
403 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
404 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
406 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
407 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
409 if(SUCCEEDED(hres)) {
410 TYPEATTR *type_attr;
412 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
413 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
414 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
416 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
417 ITypeInfo_Release(typeinfo);
420 IDispatchEx_Release(dispex);
423 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
424 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
426 IHTMLElement *elem;
427 HRESULT hres;
429 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
430 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
431 return elem;
434 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
435 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
437 IHTMLElement2 *elem;
438 HRESULT hres;
440 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
441 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
442 return elem;
445 #define get_node_iface(u) _get_node_iface(__LINE__,u)
446 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
448 IHTMLDOMNode *node;
449 HRESULT hres;
451 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
452 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
453 return node;
456 #define get_img_iface(u) _get_img_iface(__LINE__,u)
457 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
459 IHTMLImgElement *img;
460 HRESULT hres;
462 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
463 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
464 return img;
467 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
468 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
470 IHTMLDOMNode *node = _get_node_iface(line, unk);
471 BSTR name;
472 HRESULT hres;
474 hres = IHTMLDOMNode_get_nodeName(node, &name);
475 IHTMLDOMNode_Release(node);
476 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
477 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
479 SysFreeString(name);
482 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
483 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
485 IHTMLElement *elem = _get_elem_iface(line, unk);
486 BSTR tag;
487 HRESULT hres;
489 hres = IHTMLElement_get_tagName(elem, &tag);
490 IHTMLElement_Release(elem);
491 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
492 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
494 SysFreeString(tag);
497 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
498 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
500 _test_elem_tag(line, unk, elem_type_infos[type].tag);
501 _test_ifaces(line, unk, elem_type_infos[type].iids);
503 if(elem_type_infos[type].dispiid)
504 _test_disp(line, unk, elem_type_infos[type].dispiid);
507 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
508 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
510 VARIANT value;
511 BSTR tmp;
512 HRESULT hres;
514 VariantInit(&value);
516 tmp = SysAllocString(name);
517 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
518 SysFreeString(tmp);
519 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
521 if(exval) {
522 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
523 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
524 }else {
525 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
528 VariantClear(&value);
531 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
532 static void _test_elem_offset(unsigned line, IUnknown *unk)
534 IHTMLElement *elem = _get_elem_iface(line, unk);
535 long l;
536 HRESULT hres;
538 hres = IHTMLElement_get_offsetTop(elem, &l);
539 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
541 hres = IHTMLElement_get_offsetHeight(elem, &l);
542 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
544 IHTMLElement_Release(elem);
547 static void test_doc_elem(IHTMLDocument2 *doc)
549 IHTMLElement *elem;
550 IHTMLDocument3 *doc3;
551 HRESULT hres;
553 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
554 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
556 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
557 IHTMLDocument3_Release(doc3);
558 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
560 test_node_name((IUnknown*)elem, "HTML");
561 test_elem_tag((IUnknown*)elem, "HTML");
563 IHTMLElement_Release(elem);
566 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
567 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
569 IHTMLElement *elem;
570 IHTMLDocument3 *doc3;
571 HRESULT hres;
573 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
574 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
575 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
576 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
577 IHTMLDocument3_Release(doc3);
579 return elem;
582 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
583 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
585 BSTR bstr;
586 HRESULT hres;
588 hres = IHTMLOptionElement_get_text(option, &bstr);
589 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
590 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
591 SysFreeString(bstr);
594 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
595 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
597 BSTR bstr;
598 HRESULT hres;
600 bstr = a2bstr(text);
601 hres = IHTMLOptionElement_put_text(option, bstr);
602 SysFreeString(bstr);
603 ok(hres == S_OK, "put_text failed: %08x\n", hres);
605 _test_option_text(line, option, text);
608 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
609 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
611 BSTR bstr;
612 HRESULT hres;
614 hres = IHTMLOptionElement_get_value(option, &bstr);
615 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
616 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
617 SysFreeString(bstr);
620 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
621 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
623 BSTR bstr;
624 HRESULT hres;
626 bstr = a2bstr(value);
627 hres = IHTMLOptionElement_put_value(option, bstr);
628 SysFreeString(bstr);
629 ok(hres == S_OK, "put_value failed: %08x\n", hres);
631 _test_option_value(line, option, value);
634 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
635 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
636 const char *txt, const char *val)
638 IHTMLOptionElementFactory *factory;
639 IHTMLOptionElement *option;
640 IHTMLWindow2 *window;
641 VARIANT text, value, empty;
642 HRESULT hres;
644 hres = IHTMLDocument2_get_parentWindow(doc, &window);
645 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
647 hres = IHTMLWindow2_get_Option(window, &factory);
648 IHTMLWindow2_Release(window);
649 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
651 V_VT(&text) = VT_BSTR;
652 V_BSTR(&text) = a2bstr(txt);
653 V_VT(&value) = VT_BSTR;
654 V_BSTR(&value) = a2bstr(val);
655 V_VT(&empty) = VT_EMPTY;
657 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
658 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
660 IHTMLOptionElementFactory_Release(factory);
661 VariantClear(&text);
662 VariantClear(&value);
664 _test_option_text(line, option, txt);
665 _test_option_value(line, option, val);
667 return option;
670 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
671 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
673 long len = 0xdeadbeef;
674 HRESULT hres;
676 hres = IHTMLSelectElement_get_length(select, &len);
677 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
678 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
681 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
682 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
684 long idx = 0xdeadbeef;
685 HRESULT hres;
687 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
688 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
689 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
692 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
693 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
695 HRESULT hres;
697 hres = IHTMLSelectElement_put_selectedIndex(select, index);
698 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
699 _test_select_selidx(line, select, index);
702 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
703 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
705 BSTR val;
706 HRESULT hres;
708 hres = IHTMLSelectElement_get_value(select, &val);
709 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
710 if(exval)
711 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
712 else
713 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
716 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
717 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
719 BSTR bstr;
720 HRESULT hres;
722 bstr = a2bstr(val);
723 hres = IHTMLSelectElement_put_value(select, bstr);
724 SysFreeString(bstr);
725 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
728 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
729 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
731 BSTR type;
732 HRESULT hres;
734 hres = IHTMLSelectElement_get_type(select, &type);
735 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
736 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
739 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
740 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
742 BSTR text;
743 HRESULT hres;
745 hres = IHTMLTxtRange_get_text(range, &text);
746 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
748 if(extext) {
749 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
750 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
751 }else {
752 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
755 SysFreeString(text);
759 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
760 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
762 HRESULT hres;
764 hres = IHTMLTxtRange_collapse(range, b);
765 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
766 _test_range_text(line, range, NULL);
769 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
770 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
771 VARIANT_BOOL exb, const char *extext)
773 VARIANT_BOOL b = 0xe0e0;
774 HRESULT hres;
776 hres = IHTMLTxtRange_expand(range, unit, &b);
777 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
778 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
779 _test_range_text(line, range, extext);
782 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
783 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
785 long c = 0xdeadbeef;
786 HRESULT hres;
788 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
789 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
790 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
791 _test_range_text(line, range, NULL);
794 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
795 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
796 LPWSTR unit, long cnt, long excnt)
798 long c = 0xdeadbeef;
799 HRESULT hres;
801 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
802 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
803 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
806 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
807 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
809 long c = 0xdeadbeef;
810 HRESULT hres;
812 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
813 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
814 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
817 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
818 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
820 HRESULT hres;
821 BSTR bstr = a2bstr(text);
823 hres = IHTMLTxtRange_put_text(range, bstr);
824 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
825 SysFreeString(bstr);
826 _test_range_text(line, range, NULL);
829 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
830 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
832 VARIANT_BOOL b;
833 HRESULT hres;
835 b = 0xe0e0;
836 hres = IHTMLTxtRange_inRange(range1, range2, &b);
837 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
838 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
841 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
842 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
844 VARIANT_BOOL b;
845 HRESULT hres;
847 b = 0xe0e0;
848 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
849 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
850 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
852 b = 0xe0e0;
853 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
854 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
855 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
857 if(exb) {
858 test_range_inrange(range1, range2, VARIANT_TRUE);
859 test_range_inrange(range2, range1, VARIANT_TRUE);
863 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
864 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
866 IHTMLElement *elem;
867 HRESULT hres;
869 hres = IHTMLTxtRange_parentElement(range, &elem);
870 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
872 _test_elem_type(line, (IUnknown*)elem, type);
874 IHTMLElement_Release(elem);
877 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
878 static void _test_elem_collection(unsigned line, IUnknown *unk,
879 const elem_type_t *elem_types, long exlen)
881 IHTMLElementCollection *col;
882 long len;
883 DWORD i;
884 VARIANT name, index;
885 IDispatch *disp;
886 HRESULT hres;
888 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
889 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
891 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
893 hres = IHTMLElementCollection_get_length(col, &len);
894 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
895 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
897 if(len > exlen)
898 len = exlen;
900 V_VT(&index) = VT_EMPTY;
901 V_VT(&name) = VT_I4;
903 for(i=0; i<len; i++) {
904 V_I4(&name) = i;
905 disp = (void*)0xdeadbeef;
906 hres = IHTMLElementCollection_item(col, name, index, &disp);
907 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
908 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
909 if(FAILED(hres) || !disp)
910 continue;
912 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
913 IDispatch_Release(disp);
916 V_I4(&name) = len;
917 disp = (void*)0xdeadbeef;
918 hres = IHTMLElementCollection_item(col, name, index, &disp);
919 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
920 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
922 V_I4(&name) = -1;
923 disp = (void*)0xdeadbeef;
924 hres = IHTMLElementCollection_item(col, name, index, &disp);
925 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
926 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
928 IHTMLElementCollection_Release(col);
931 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
932 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
934 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
935 IHTMLElementCollection *col = NULL;
936 elem_type_t *types = NULL;
937 BSTR tmp;
938 int i;
939 HRESULT hres;
941 tmp = a2bstr(elem_type_infos[type].tag);
942 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
943 SysFreeString(tmp);
944 IHTMLElement2_Release(elem);
945 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
946 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
948 if(exlen) {
949 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
950 for(i=0; i<exlen; i++)
951 types[i] = type;
954 _test_elem_collection(line, (IUnknown*)col, types, exlen);
956 HeapFree(GetProcessHeap(), 0, types);
959 #define get_first_child(n) _get_first_child(__LINE__,n)
960 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
962 IHTMLDOMNode *node = _get_node_iface(line, unk);
963 IHTMLDOMNode *child = NULL;
964 HRESULT hres;
966 hres = IHTMLDOMNode_get_firstChild(node, &child);
967 IHTMLDOMNode_Release(node);
968 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
970 return child;
973 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
974 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
976 IHTMLDOMNode *node = _get_node_iface(line, unk);
977 VARIANT_BOOL b = 0xdead;
978 HRESULT hres;
980 hres = IHTMLDOMNode_hasChildNodes(node, &b);
981 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
982 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
984 IHTMLDOMNode_Release(node);
987 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
988 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
990 IHTMLDOMNode *node = _get_node_iface(line, unk);
991 IHTMLDOMNode *parent;
992 HRESULT hres;
994 hres = IHTMLDOMNode_get_parentNode(node, &parent);
995 IHTMLDOMNode_Release(node);
996 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
998 return parent;
1001 #define get_node_type(n) _get_node_type(__LINE__,n)
1002 static long _get_node_type(unsigned line, IUnknown *unk)
1004 IHTMLDOMNode *node = _get_node_iface(line, unk);
1005 long type = -1;
1006 HRESULT hres;
1008 hres = IHTMLDOMNode_get_nodeType(node, &type);
1009 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1011 IHTMLDOMNode_Release(node);
1013 return type;
1016 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1017 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1019 IHTMLElement *elem = _get_elem_iface(line, unk);
1020 IHTMLElement *parent;
1021 HRESULT hres;
1023 hres = IHTMLElement_get_parentElement(elem, &parent);
1024 IHTMLElement_Release(elem);
1025 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1027 return parent;
1030 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1031 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1033 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1034 IHTMLTextContainer *txtcont;
1035 long l = -1, l2 = -1;
1036 HRESULT hres;
1038 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1039 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1040 IHTMLElement2_Release(elem);
1042 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1043 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1045 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1046 IHTMLTextContainer_Release(txtcont);
1047 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1048 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1050 return l;
1053 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1054 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1056 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1057 IHTMLTextContainer *txtcont;
1058 long l = -1, l2 = -1;
1059 HRESULT hres;
1061 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1062 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1063 IHTMLElement2_Release(elem);
1065 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1066 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1068 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1069 IHTMLTextContainer_Release(txtcont);
1070 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1071 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1073 return l;
1076 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1077 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1079 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1080 IHTMLTextContainer *txtcont;
1081 long l = -1, l2 = -1;
1082 HRESULT hres;
1084 hres = IHTMLElement2_get_scrollTop(elem, &l);
1085 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1086 IHTMLElement2_Release(elem);
1088 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1089 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1091 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1092 IHTMLTextContainer_Release(txtcont);
1093 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1094 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1096 return l;
1099 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1100 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1102 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1103 IHTMLTextContainer *txtcont;
1104 long l = -1, l2 = -1;
1105 HRESULT hres;
1107 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1108 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1110 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1111 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1112 IHTMLElement2_Release(elem);
1114 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1115 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1117 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1118 IHTMLTextContainer_Release(txtcont);
1119 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1120 ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1123 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1124 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1126 IHTMLImgElement *img = _get_img_iface(line, unk);
1127 BSTR tmp;
1128 HRESULT hres;
1130 tmp = a2bstr(src);
1131 hres = IHTMLImgElement_put_src(img, tmp);
1132 IHTMLImgElement_Release(img);
1133 SysFreeString(tmp);
1134 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1137 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1138 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1140 IHTMLImgElement *img = _get_img_iface(line, unk);
1141 BSTR alt;
1142 HRESULT hres;
1144 hres = IHTMLImgElement_get_alt(img, &alt);
1145 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1146 if(exalt)
1147 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1148 else
1149 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1150 SysFreeString(alt);
1153 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1154 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1156 IHTMLImgElement *img = _get_img_iface(line, unk);
1157 BSTR tmp;
1158 HRESULT hres;
1160 tmp = a2bstr(alt);
1161 hres = IHTMLImgElement_put_alt(img, tmp);
1162 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1163 SysFreeString(tmp);
1165 _test_img_alt(line, unk, alt);
1168 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1169 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1171 VARIANT_BOOL disabled = 100;
1172 HRESULT hres;
1174 hres = IHTMLInputElement_get_disabled(input, &disabled);
1175 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1176 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1179 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1180 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1182 HRESULT hres;
1184 hres = IHTMLInputElement_put_disabled(input, b);
1185 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1187 _test_input_get_disabled(line, input, b);
1190 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1191 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1193 IHTMLInputElement *input;
1194 BSTR bstr;
1195 HRESULT hres;
1197 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1198 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1199 if(FAILED(hres))
1200 return;
1202 hres = IHTMLInputElement_get_value(input, &bstr);
1203 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1204 if(exval)
1205 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1206 else
1207 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1208 SysFreeString(bstr);
1209 IHTMLInputElement_Release(input);
1212 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1213 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1215 IHTMLInputElement *input;
1216 BSTR bstr;
1217 HRESULT hres;
1219 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1220 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1221 if(FAILED(hres))
1222 return;
1224 bstr = a2bstr(val);
1225 hres = IHTMLInputElement_get_value(input, &bstr);
1226 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1227 SysFreeString(bstr);
1228 IHTMLInputElement_Release(input);
1231 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1232 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1234 IHTMLDOMNode *node = _get_node_iface(line, unk);
1235 IHTMLDOMChildrenCollection *col = NULL;
1236 IDispatch *disp;
1237 HRESULT hres;
1239 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1240 IHTMLDOMNode_Release(node);
1241 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1242 if(FAILED(hres))
1243 return NULL;
1245 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1246 IDispatch_Release(disp);
1247 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1249 return col;
1252 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1253 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1255 IHTMLElement *elem = _get_elem_iface(line, unk);
1256 BSTR class = (void*)0xdeadbeef;
1257 HRESULT hres;
1259 hres = IHTMLElement_get_className(elem, &class);
1260 IHTMLElement_Release(elem);
1261 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1262 if(exclass)
1263 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1264 else
1265 ok_(__FILE__,line) (!class, "class != NULL\n");
1266 SysFreeString(class);
1269 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1270 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1272 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1273 short index = -3;
1274 HRESULT hres;
1276 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1277 IHTMLElement2_Release(elem2);
1278 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1279 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1282 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1283 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1285 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1286 HRESULT hres;
1288 hres = IHTMLElement2_put_tabIndex(elem2, index);
1289 IHTMLElement2_Release(elem2);
1290 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1292 _test_elem_tabindex(line, unk, index);
1295 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1296 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1298 IHTMLElement *elem = _get_elem_iface(line, unk);
1299 BSTR tmp;
1300 HRESULT hres;
1302 tmp = class ? a2bstr(class) : NULL;
1303 hres = IHTMLElement_put_className(elem, tmp);
1304 IHTMLElement_Release(elem);
1305 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1306 SysFreeString(tmp);
1308 _test_elem_class(line, unk, class);
1311 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1312 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
1314 IHTMLDOMNode *node = NULL;
1315 IDispatch *disp;
1316 HRESULT hres;
1318 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1319 ok(hres == S_OK, "item failed: %08x\n", hres);
1321 node = _get_node_iface(line, (IUnknown*)disp);
1322 IDispatch_Release(disp);
1324 return node;
1327 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1328 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1330 IHTMLElement *elem = _get_elem_iface(line, unk);
1331 BSTR id = (void*)0xdeadbeef;
1332 HRESULT hres;
1334 hres = IHTMLElement_get_id(elem, &id);
1335 IHTMLElement_Release(elem);
1336 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1338 if(exid)
1339 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1340 else
1341 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1343 SysFreeString(id);
1346 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1347 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1349 IHTMLElement *elem = _get_elem_iface(line, unk);
1350 BSTR tmp = a2bstr(new_id);
1351 HRESULT hres;
1353 hres = IHTMLElement_put_id(elem, tmp);
1354 IHTMLElement_Release(elem);
1355 SysFreeString(tmp);
1356 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1358 _test_elem_id(line, unk, new_id);
1361 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1362 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1364 IHTMLElement *elem = _get_elem_iface(line, unk);
1365 BSTR title;
1366 HRESULT hres;
1368 hres = IHTMLElement_get_title(elem, &title);
1369 IHTMLElement_Release(elem);
1370 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1371 if(extitle)
1372 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1373 else
1374 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1376 SysFreeString(title);
1379 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1380 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1382 IHTMLElement *elem = _get_elem_iface(line, unk);
1383 BSTR tmp;
1384 HRESULT hres;
1386 tmp = a2bstr(title);
1387 hres = IHTMLElement_put_title(elem, tmp);
1388 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1390 IHTMLElement_Release(elem);
1391 SysFreeString(tmp);
1394 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1395 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1397 IHTMLDOMNode *node = _get_node_iface(line, unk);
1398 VARIANT var;
1399 HRESULT hres;
1401 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1402 IHTMLDOMNode_Release(node);
1403 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1405 if(exval) {
1406 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1407 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1408 }else {
1409 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1412 VariantClear(&var);
1415 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1416 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1418 IHTMLDOMNode *node = _get_node_iface(line, unk);
1419 VARIANT var;
1420 HRESULT hres;
1422 V_VT(&var) = VT_BSTR;
1423 V_BSTR(&var) = a2bstr(val);
1425 hres = IHTMLDOMNode_put_nodeValue(node, var);
1426 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1427 IHTMLDOMNode_Release(node);
1428 VariantClear(&var);
1431 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1432 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1434 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1435 long l;
1436 HRESULT hres;
1438 hres = IHTMLElement2_get_clientWidth(elem, &l);
1439 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1440 hres = IHTMLElement2_get_clientHeight(elem, &l);
1441 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1443 IHTMLElement2_Release(elem);
1446 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1447 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1449 IHTMLElement *elem = NULL;
1450 BSTR tmp;
1451 HRESULT hres;
1453 tmp = a2bstr(tag);
1454 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1455 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1456 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1458 return elem;
1461 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1462 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1464 IHTMLDocument3 *doc3;
1465 IHTMLDOMNode *node = NULL;
1466 BSTR tmp;
1467 HRESULT hres;
1469 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1470 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1472 tmp = a2bstr(text);
1473 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1474 IHTMLDocument3_Release(doc3);
1475 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1476 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1478 return node;
1481 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1482 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1484 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1485 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1486 IHTMLDOMNode *new_child = NULL;
1487 HRESULT hres;
1489 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1490 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1491 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1492 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1494 IHTMLDOMNode_Release(node);
1495 IHTMLDOMNode_Release(child);
1497 return new_child;
1500 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1501 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1503 IHTMLDOMNode *node = _get_node_iface(line, unk);
1504 IHTMLDOMNode *new_node = NULL;
1505 HRESULT hres;
1507 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1508 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1509 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1510 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1512 IHTMLDOMNode_Release(node);
1513 IHTMLDOMNode_Release(new_node);
1516 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1517 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1519 BSTR title = NULL;
1520 HRESULT hres;
1522 hres = IHTMLDocument2_get_title(doc, &title);
1523 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1524 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1525 SysFreeString(title);
1528 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1529 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1531 BSTR tmp;
1532 HRESULT hres;
1534 tmp = a2bstr(title);
1535 hres = IHTMLDocument2_put_title(doc, tmp);
1536 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1537 SysFreeString(tmp);
1540 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1541 const elem_type_t *elem_types, long len)
1543 IDispatch *disp;
1544 VARIANT name, index;
1545 DWORD i;
1546 HRESULT hres;
1548 V_VT(&index) = VT_EMPTY;
1549 V_VT(&name) = VT_BSTR;
1550 V_BSTR(&name) = SysAllocString(n);
1552 hres = IHTMLElementCollection_item(col, name, index, &disp);
1553 ok(hres == S_OK, "item failed: %08x\n", hres);
1555 test_elem_collection((IUnknown*)disp, elem_types, len);
1556 IDispatch_Release(disp);
1557 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1558 if(hres != S_OK)
1559 goto cleanup;
1561 V_VT(&index) = VT_I4;
1563 for(i=0; i<len; i++) {
1564 V_I4(&index) = i;
1565 disp = (void*)0xdeadbeef;
1566 hres = IHTMLElementCollection_item(col, name, index, &disp);
1567 ok(hres == S_OK, "item failed: %08x\n", hres);
1568 ok(disp != NULL, "disp == NULL\n");
1569 if(FAILED(hres) || !disp)
1570 continue;
1572 test_elem_type((IUnknown*)disp, elem_types[i]);
1574 IDispatch_Release(disp);
1577 V_I4(&index) = len;
1578 disp = (void*)0xdeadbeef;
1579 hres = IHTMLElementCollection_item(col, name, index, &disp);
1580 ok(hres == S_OK, "item failed: %08x\n", hres);
1581 ok(disp == NULL, "disp != NULL\n");
1583 V_I4(&index) = -1;
1584 disp = (void*)0xdeadbeef;
1585 hres = IHTMLElementCollection_item(col, name, index, &disp);
1586 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1587 ok(disp == NULL, "disp != NULL\n");
1589 cleanup:
1590 SysFreeString(V_BSTR(&name));
1593 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1595 IHTMLElementCollection *col;
1596 IHTMLElement *elem;
1597 IDispatch *disp = (void*)0xdeadbeef;
1598 VARIANT name, index;
1599 HRESULT hres;
1601 hres = IHTMLDocument2_get_all(doc, &col);
1602 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1603 ok(col != NULL, "col == NULL\n");
1604 if(FAILED(hres) || !col)
1605 return NULL;
1607 V_VT(&index) = VT_EMPTY;
1608 V_VT(&name) = VT_BSTR;
1609 V_BSTR(&name) = SysAllocString(id);
1611 hres = IHTMLElementCollection_item(col, name, index, &disp);
1612 IHTMLElementCollection_Release(col);
1613 SysFreeString(V_BSTR(&name));
1614 ok(hres == S_OK, "item failed: %08x\n", hres);
1615 if(!expect_success) {
1616 ok(disp == NULL, "disp != NULL\n");
1617 return NULL;
1620 ok(disp != NULL, "disp == NULL\n");
1621 if(!disp)
1622 return NULL;
1624 elem = get_elem_iface((IUnknown*)disp);
1625 IDispatch_Release(disp);
1627 return elem;
1630 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1632 IHTMLDocument3 *doc3;
1633 IHTMLElement *elem;
1634 BSTR tmp;
1635 HRESULT hres;
1637 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1638 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1640 tmp = SysAllocString(id);
1641 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1642 SysFreeString(tmp);
1643 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1645 IHTMLDocument3_Release(doc3);
1647 return elem;
1650 static void test_select_elem(IHTMLSelectElement *select)
1652 test_select_type(select, "select-one");
1653 test_select_length(select, 2);
1654 test_select_selidx(select, 0);
1655 test_select_put_selidx(select, 1);
1657 test_select_set_value(select, "val1");
1658 test_select_value(select, "val1");
1661 static void test_create_option_elem(IHTMLDocument2 *doc)
1663 IHTMLOptionElement *option;
1665 option = create_option_elem(doc, "test text", "test value");
1667 test_option_put_text(option, "new text");
1668 test_option_put_value(option, "new value");
1670 IHTMLOptionElement_Release(option);
1673 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1675 IHTMLBodyElement *body;
1676 IHTMLTxtRange *range;
1677 IHTMLElement *elem;
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 IHTMLElement_Release(elem);
1686 hres = IHTMLBodyElement_createTextRange(body, &range);
1687 IHTMLBodyElement_Release(body);
1688 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1690 return range;
1693 static void test_txtrange(IHTMLDocument2 *doc)
1695 IHTMLTxtRange *body_range, *range, *range2;
1696 IHTMLSelectionObject *selection;
1697 IDispatch *disp_range;
1698 HRESULT hres;
1700 body_range = test_create_body_range(doc);
1702 test_range_text(body_range, "test abc 123\r\nit's text");
1704 hres = IHTMLTxtRange_duplicate(body_range, &range);
1705 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1707 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1708 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1709 test_range_isequal(range, range2, VARIANT_TRUE);
1711 test_range_text(range, "test abc 123\r\nit's text");
1712 test_range_text(body_range, "test abc 123\r\nit's text");
1714 test_range_collapse(range, TRUE);
1715 test_range_isequal(range, range2, VARIANT_FALSE);
1716 test_range_inrange(range, range2, VARIANT_FALSE);
1717 test_range_inrange(range2, range, VARIANT_TRUE);
1718 IHTMLTxtRange_Release(range2);
1720 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1721 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1722 test_range_move(range, characterW, 2, 2);
1723 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1725 test_range_collapse(range, FALSE);
1726 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1728 test_range_collapse(range, FALSE);
1729 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1730 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1731 test_range_move(range, characterW, 2, 2);
1732 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1733 test_range_moveend(range, characterW, -5, -5);
1734 test_range_text(range, NULL);
1735 test_range_moveend(range, characterW, 3, 3);
1736 test_range_text(range, "c 1");
1737 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1738 test_range_collapse(range, TRUE);
1739 test_range_move(range, characterW, 4, 4);
1740 test_range_moveend(range, characterW, 1, 1);
1741 test_range_text(range, " ");
1742 test_range_move(range, wordW, 1, 1);
1743 test_range_moveend(range, characterW, 2, 2);
1744 test_range_text(range, "ab");
1746 IHTMLTxtRange_Release(range);
1748 hres = IHTMLTxtRange_duplicate(body_range, &range);
1749 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1751 test_range_text(range, "test abc 123\r\nit's text");
1752 test_range_move(range, characterW, 3, 3);
1753 test_range_moveend(range, characterW, 1, 1);
1754 test_range_text(range, "t");
1755 test_range_moveend(range, characterW, 3, 3);
1756 test_range_text(range, "t ab");
1757 test_range_moveend(range, characterW, -2, -2);
1758 test_range_text(range, "t ");
1759 test_range_move(range, characterW, 6, 6);
1760 test_range_moveend(range, characterW, 3, 3);
1761 test_range_text(range, "123");
1762 test_range_moveend(range, characterW, 2, 2);
1763 test_range_text(range, "123\r\ni");
1765 IHTMLTxtRange_Release(range);
1767 hres = IHTMLTxtRange_duplicate(body_range, &range);
1768 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1770 test_range_move(range, wordW, 1, 1);
1771 test_range_moveend(range, characterW, 2, 2);
1772 test_range_text(range, "ab");
1774 test_range_move(range, characterW, -2, -2);
1775 test_range_moveend(range, characterW, 2, 2);
1776 test_range_text(range, "t ");
1778 test_range_move(range, wordW, 3, 3);
1779 test_range_move(range, wordW, -2, -2);
1780 test_range_moveend(range, characterW, 2, 2);
1781 test_range_text(range, "ab");
1783 test_range_move(range, characterW, -6, -5);
1784 test_range_moveend(range, characterW, -1, 0);
1785 test_range_moveend(range, characterW, -6, 0);
1786 test_range_move(range, characterW, 2, 2);
1787 test_range_moveend(range, characterW, 2, 2);
1788 test_range_text(range, "st");
1789 test_range_moveend(range, characterW, -6, -4);
1790 test_range_moveend(range, characterW, 2, 2);
1792 IHTMLTxtRange_Release(range);
1794 hres = IHTMLTxtRange_duplicate(body_range, &range);
1795 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1797 test_range_move(range, wordW, 2, 2);
1798 test_range_moveend(range, characterW, 2, 2);
1799 test_range_text(range, "12");
1801 test_range_move(range, characterW, 15, 14);
1802 test_range_move(range, characterW, -2, -2);
1803 test_range_moveend(range, characterW, 3, 2);
1804 test_range_text(range, "t");
1805 test_range_moveend(range, characterW, -1, -1);
1806 test_range_text(range, "t");
1807 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1808 test_range_move(range, characterW, -2, -2);
1809 test_range_moveend(range, characterW, 2, 2);
1810 test_range_text(range, "s ");
1811 test_range_move(range, characterW, 100, 7);
1812 test_range_move(range, wordW, 1, 0);
1813 test_range_move(range, characterW, -2, -2);
1814 test_range_moveend(range, characterW, 3, 2);
1815 test_range_text(range, "t");
1817 IHTMLTxtRange_Release(range);
1819 hres = IHTMLTxtRange_duplicate(body_range, &range);
1820 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1822 test_range_collapse(range, TRUE);
1823 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1824 test_range_put_text(range, "word");
1825 test_range_text(body_range, "wordabc 123\r\nit's text");
1826 test_range_text(range, NULL);
1827 test_range_moveend(range, characterW, 3, 3);
1828 test_range_text(range, "abc");
1829 test_range_movestart(range, characterW, -2, -2);
1830 test_range_text(range, "rdabc");
1831 test_range_movestart(range, characterW, 3, 3);
1832 test_range_text(range, "bc");
1833 test_range_movestart(range, characterW, 4, 4);
1834 test_range_text(range, NULL);
1835 test_range_movestart(range, characterW, -3, -3);
1836 test_range_text(range, "c 1");
1837 test_range_movestart(range, characterW, -7, -6);
1838 test_range_text(range, "wordabc 1");
1839 test_range_movestart(range, characterW, 100, 22);
1840 test_range_text(range, NULL);
1842 IHTMLTxtRange_Release(range);
1843 IHTMLTxtRange_Release(body_range);
1845 hres = IHTMLDocument2_get_selection(doc, &selection);
1846 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1848 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1849 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1850 IHTMLSelectionObject_Release(selection);
1852 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1853 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1854 IDispatch_Release(disp_range);
1856 test_range_text(range, NULL);
1857 test_range_moveend(range, characterW, 3, 3);
1858 test_range_text(range, "wor");
1859 test_range_parent(range, ET_BODY);
1860 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1861 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1862 test_range_move(range, characterW, 3, 3);
1863 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1864 test_range_moveend(range, characterW, -4, -4);
1865 test_range_put_text(range, "abc def ");
1866 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1867 test_range_move(range, wordW, 1, 1);
1868 test_range_movestart(range, characterW, -1, -1);
1869 test_range_text(range, " ");
1870 test_range_move(range, wordW, 1, 1);
1871 test_range_moveend(range, characterW, 3, 3);
1872 test_range_text(range, "def");
1873 test_range_put_text(range, "xyz");
1874 test_range_moveend(range, characterW, 1, 1);
1875 test_range_move(range, wordW, 1, 1);
1876 test_range_moveend(range, characterW, 2, 2);
1877 test_range_text(range, "ab");
1879 IHTMLTxtRange_Release(range);
1882 static void test_txtrange2(IHTMLDocument2 *doc)
1884 IHTMLTxtRange *range;
1886 range = test_create_body_range(doc);
1888 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1889 test_range_move(range, characterW, 5, 5);
1890 test_range_moveend(range, characterW, 1, 1);
1891 test_range_text(range, "2");
1892 test_range_move(range, characterW, -3, -3);
1893 test_range_moveend(range, characterW, 3, 3);
1894 test_range_text(range, "c\r\n\r\n1");
1895 test_range_collapse(range, VARIANT_FALSE);
1896 test_range_moveend(range, characterW, 4, 4);
1897 test_range_text(range, "23");
1898 test_range_moveend(range, characterW, 1, 1);
1899 test_range_text(range, "23\r\n\r\n\r\nd");
1900 test_range_moveend(range, characterW, -1, -1);
1901 test_range_text(range, "23");
1902 test_range_moveend(range, characterW, -1, -1);
1903 test_range_text(range, "23");
1904 test_range_moveend(range, characterW, -2, -2);
1905 test_range_text(range, "2");
1907 IHTMLTxtRange_Release(range);
1910 static void test_compatmode(IHTMLDocument2 *doc)
1912 IHTMLDocument5 *doc5;
1913 BSTR mode;
1914 HRESULT hres;
1916 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1917 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
1918 if(FAILED(hres))
1919 return;
1921 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
1922 IHTMLDocument5_Release(doc5);
1923 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
1924 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
1925 SysFreeString(mode);
1928 static void test_location(IHTMLDocument2 *doc)
1930 IHTMLLocation *location, *location2;
1931 ULONG ref;
1932 HRESULT hres;
1934 hres = IHTMLDocument2_get_location(doc, &location);
1935 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1937 hres = IHTMLDocument2_get_location(doc, &location2);
1938 ok(hres == S_OK, "get_location failed: %08x\n", hres);
1940 ok(location == location2, "location != location2\n");
1942 test_ifaces((IUnknown*)location, location_iids);
1944 IHTMLLocation_Release(location2);
1945 ref = IHTMLLocation_Release(location);
1946 ok(!ref, "location chould be destroyed here\n");
1949 static void test_navigator(IHTMLDocument2 *doc)
1951 IHTMLWindow2 *window;
1952 IOmNavigator *navigator, *navigator2;
1953 ULONG ref;
1954 BSTR bstr;
1955 HRESULT hres;
1957 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1958 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
1960 hres = IHTMLWindow2_get_navigator(window, &navigator);
1961 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1962 ok(navigator != NULL, "navigator == NULL\n");
1963 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
1965 hres = IHTMLWindow2_get_navigator(window, &navigator2);
1966 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1967 ok(navigator != navigator2, "navigator2 != navihgator\n");
1969 IHTMLWindow2_Release(window);
1970 IOmNavigator_Release(navigator2);
1972 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
1973 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
1974 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
1975 SysFreeString(bstr);
1977 bstr = NULL;
1978 hres = IOmNavigator_get_platform(navigator, &bstr);
1979 ok(hres == S_OK, "get_appMinorVersion failed: %08x\n", hres);
1980 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
1981 SysFreeString(bstr);
1983 ref = IOmNavigator_Release(navigator);
1984 ok(!ref, "navigator should be destroyed here\n");
1987 static void test_current_style(IHTMLCurrentStyle *current_style)
1989 BSTR str;
1990 HRESULT hres;
1992 test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle);
1993 test_ifaces((IUnknown*)current_style, cstyle_iids);
1995 hres = IHTMLCurrentStyle_get_display(current_style, &str);
1996 ok(hres == S_OK, "get_display failed: %08x\n", hres);
1997 ok(!strcmp_wa(str, "block"), "get_display returned %s\n", dbgstr_w(str));
1998 SysFreeString(str);
2001 static void test_default_style(IHTMLStyle *style)
2003 VARIANT_BOOL b;
2004 VARIANT v;
2005 BSTR str;
2006 HRESULT hres;
2008 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
2009 test_ifaces((IUnknown*)style, style_iids);
2011 str = (void*)0xdeadbeef;
2012 hres = IHTMLStyle_get_fontFamily(style, &str);
2013 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2014 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
2016 str = (void*)0xdeadbeef;
2017 hres = IHTMLStyle_get_fontWeight(style, &str);
2018 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2019 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
2021 str = (void*)0xdeadbeef;
2022 hres = IHTMLStyle_get_display(style, &str);
2023 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2024 ok(!str, "display = %s\n", dbgstr_w(str));
2026 str = (void*)0xdeadbeef;
2027 hres = IHTMLStyle_get_visibility(style, &str);
2028 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2029 ok(!str, "visibility = %s\n", dbgstr_w(str));
2031 V_VT(&v) = VT_NULL;
2032 hres = IHTMLStyle_get_fontSize(style, &v);
2033 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2034 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2035 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
2037 V_VT(&v) = VT_NULL;
2038 hres = IHTMLStyle_get_color(style, &v);
2039 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2040 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2041 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2043 b = 0xfefe;
2044 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2045 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2046 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2048 b = 0xfefe;
2049 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2050 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2051 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2053 V_VT(&v) = VT_EMPTY;
2054 hres = IHTMLStyle_get_width(style, &v);
2055 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2056 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2057 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2059 V_VT(&v) = VT_BSTR;
2060 V_BSTR(&v) = a2bstr("auto");
2061 hres = IHTMLStyle_put_width(style, v);
2062 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2063 VariantClear(&v);
2065 V_VT(&v) = VT_EMPTY;
2066 hres = IHTMLStyle_get_width(style, &v);
2067 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2068 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2069 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2070 VariantClear(&v);
2072 /* margin tests */
2073 str = (void*)0xdeadbeef;
2074 hres = IHTMLStyle_get_margin(style, &str);
2075 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2076 ok(!str, "margin = %s\n", dbgstr_w(str));
2078 str = a2bstr("1");
2079 hres = IHTMLStyle_put_margin(style, str);
2080 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2081 SysFreeString(str);
2083 hres = IHTMLStyle_get_margin(style, &str);
2084 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2085 ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2087 hres = IHTMLStyle_put_margin(style, NULL);
2088 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2090 str = NULL;
2091 hres = IHTMLStyle_get_border(style, &str);
2092 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2093 ok(!str || !*str, "str is not empty\n");
2094 SysFreeString(str);
2096 str = a2bstr("1px");
2097 hres = IHTMLStyle_put_border(style, str);
2098 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2099 SysFreeString(str);
2101 V_VT(&v) = VT_EMPTY;
2102 hres = IHTMLStyle_get_left(style, &v);
2103 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2104 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2105 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2106 VariantClear(&v);
2108 V_VT(&v) = VT_BSTR;
2109 V_BSTR(&v) = a2bstr("3px");
2110 hres = IHTMLStyle_put_left(style, v);
2111 ok(hres == S_OK, "put_left failed: %08x\n", hres);
2112 VariantClear(&v);
2114 V_VT(&v) = VT_EMPTY;
2115 hres = IHTMLStyle_get_left(style, &v);
2116 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2117 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2118 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2119 VariantClear(&v);
2123 static void test_default_selection(IHTMLDocument2 *doc)
2125 IHTMLSelectionObject *selection;
2126 IHTMLTxtRange *range;
2127 IDispatch *disp;
2128 BSTR str;
2129 HRESULT hres;
2131 hres = IHTMLDocument2_get_selection(doc, &selection);
2132 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2134 hres = IHTMLSelectionObject_get_type(selection, &str);
2135 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2136 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2137 SysFreeString(str);
2139 hres = IHTMLSelectionObject_createRange(selection, &disp);
2140 IHTMLSelectionObject_Release(selection);
2141 ok(hres == S_OK, "createRange failed: %08x\n", hres);
2143 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2144 IDispatch_Release(disp);
2145 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2147 test_range_text(range, NULL);
2148 IHTMLTxtRange_Release(range);
2151 static void test_default_body(IHTMLBodyElement *body)
2153 long l;
2154 BSTR bstr;
2155 HRESULT hres;
2156 VARIANT v;
2157 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2158 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2159 WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2161 bstr = (void*)0xdeadbeef;
2162 hres = IHTMLBodyElement_get_background(body, &bstr);
2163 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2164 ok(bstr == NULL, "bstr != NULL\n");
2166 l = elem_get_scroll_height((IUnknown*)body);
2167 ok(l != -1, "scrollHeight == -1\n");
2168 l = elem_get_scroll_width((IUnknown*)body);
2169 ok(l != -1, "scrollWidth == -1\n");
2170 l = elem_get_scroll_top((IUnknown*)body);
2171 ok(!l, "scrollTop = %ld\n", l);
2172 elem_get_scroll_left((IUnknown*)body);
2174 /* get_text tests */
2175 hres = IHTMLBodyElement_get_text(body, &v);
2176 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2177 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2178 ok(bstr == NULL, "bstr != NULL\n");
2181 /* get_text - Invalid Text */
2182 V_VT(&v) = VT_BSTR;
2183 V_BSTR(&v) = SysAllocString(sTextInvalid);
2184 hres = IHTMLBodyElement_put_text(body, v);
2185 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2187 V_VT(&v) = VT_NULL;
2188 hres = IHTMLBodyElement_get_text(body, &v);
2189 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2190 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2191 ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2192 VariantClear(&v);
2194 /* get_text - Valid Text */
2195 V_VT(&v) = VT_BSTR;
2196 V_BSTR(&v) = SysAllocString(sBodyText);
2197 hres = IHTMLBodyElement_put_text(body, v);
2198 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2200 V_VT(&v) = VT_NULL;
2201 hres = IHTMLBodyElement_get_text(body, &v);
2202 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2203 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2204 ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2205 VariantClear(&v);
2208 static void test_body_funs(IHTMLBodyElement *body)
2210 static WCHAR sRed[] = {'r','e','d',0};
2211 static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2212 VARIANT vbg;
2213 VARIANT vDefaultbg;
2214 HRESULT hres;
2216 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2217 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2218 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2220 V_VT(&vbg) = VT_BSTR;
2221 V_BSTR(&vbg) = SysAllocString(sRed);
2222 hres = IHTMLBodyElement_put_bgColor(body, vbg);
2223 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2224 VariantClear(&vbg);
2226 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2227 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2228 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2229 ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2230 VariantClear(&vbg);
2232 /* Restore Originial */
2233 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2234 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2235 VariantClear(&vDefaultbg);
2238 static void test_window(IHTMLDocument2 *doc)
2240 IHTMLWindow2 *window, *window2, *self;
2241 IHTMLDocument2 *doc2 = NULL;
2242 IDispatch *disp;
2243 HRESULT hres;
2245 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2246 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2247 test_ifaces((IUnknown*)window, window_iids);
2248 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2250 hres = IHTMLWindow2_get_document(window, &doc2);
2251 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2252 ok(doc2 != NULL, "doc2 == NULL\n");
2254 IHTMLDocument_Release(doc2);
2256 hres = IHTMLWindow2_get_window(window, &window2);
2257 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2258 ok(window2 != NULL, "window2 == NULL\n");
2260 hres = IHTMLWindow2_get_self(window, &self);
2261 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2262 ok(window2 != NULL, "self == NULL\n");
2264 ok(self == window2, "self != window2\n");
2266 IHTMLWindow2_Release(window2);
2267 IHTMLWindow2_Release(self);
2269 disp = NULL;
2270 hres = IHTMLDocument2_get_Script(doc, &disp);
2271 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2272 ok(disp == (void*)window, "disp != window\n");
2273 IDispatch_Release(disp);
2275 IHTMLWindow2_Release(window);
2278 static void test_defaults(IHTMLDocument2 *doc)
2280 IHTMLStyleSheetsCollection *stylesheetcol;
2281 IHTMLCurrentStyle *cstyle;
2282 IHTMLBodyElement *body;
2283 IHTMLElement2 *elem2;
2284 IHTMLElement *elem;
2285 IHTMLStyle *style;
2286 long l;
2287 HRESULT hres;
2289 hres = IHTMLDocument2_get_body(doc, &elem);
2290 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2292 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2293 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2294 test_default_body(body);
2295 test_body_funs(body);
2296 IHTMLBodyElement_Release(body);
2298 hres = IHTMLElement_get_style(elem, &style);
2299 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2301 test_default_style(style);
2302 test_window(doc);
2303 test_compatmode(doc);
2304 test_location(doc);
2305 test_navigator(doc);
2307 IHTMLStyle_Release(style);
2309 elem2 = get_elem2_iface((IUnknown*)elem);
2310 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
2311 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
2312 if(SUCCEEDED(hres)) {
2313 test_current_style(cstyle);
2314 IHTMLCurrentStyle_Release(cstyle);
2316 IHTMLElement2_Release(elem2);
2318 IHTMLElement_Release(elem);
2320 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2321 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2323 l = 0xdeadbeef;
2324 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2325 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2326 ok(l == 0, "length = %ld\n", l);
2328 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2330 test_default_selection(doc);
2331 test_doc_title(doc, "");
2334 static void test_tr_elem(IHTMLElement *elem)
2336 IHTMLElementCollection *col;
2337 IHTMLTableRow *row;
2338 HRESULT hres;
2340 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
2342 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
2343 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
2344 if(FAILED(hres))
2345 return;
2347 col = NULL;
2348 hres = IHTMLTableRow_get_cells(row, &col);
2349 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
2350 ok(col != NULL, "get_cells returned NULL\n");
2352 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
2353 IHTMLElementCollection_Release(col);
2355 IHTMLTable_Release(row);
2358 static void test_table_elem(IHTMLElement *elem)
2360 IHTMLElementCollection *col;
2361 IHTMLTable *table;
2362 HRESULT hres;
2364 static const elem_type_t row_types[] = {ET_TR,ET_TR};
2366 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2367 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2368 if(FAILED(hres))
2369 return;
2371 col = NULL;
2372 hres = IHTMLTable_get_rows(table, &col);
2373 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2374 ok(col != NULL, "get_ros returned NULL\n");
2376 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2377 IHTMLElementCollection_Release(col);
2379 IHTMLTable_Release(table);
2382 static void test_stylesheet(IDispatch *disp)
2384 IHTMLStyleSheetRulesCollection *col = NULL;
2385 IHTMLStyleSheet *stylesheet;
2386 HRESULT hres;
2388 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2389 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2391 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2392 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2393 ok(col != NULL, "col == NULL\n");
2395 IHTMLStyleSheetRulesCollection_Release(col);
2396 IHTMLStyleSheet_Release(stylesheet);
2399 static void test_stylesheets(IHTMLDocument2 *doc)
2401 IHTMLStyleSheetsCollection *col = NULL;
2402 VARIANT idx, res;
2403 long len = 0;
2404 HRESULT hres;
2406 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2407 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2408 ok(col != NULL, "col == NULL\n");
2410 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2411 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2412 ok(len == 1, "len=%ld\n", len);
2414 VariantInit(&res);
2415 V_VT(&idx) = VT_I4;
2416 V_I4(&idx) = 0;
2418 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2419 ok(hres == S_OK, "item failed: %08x\n", hres);
2420 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2421 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2422 test_stylesheet(V_DISPATCH(&res));
2423 VariantClear(&res);
2425 V_VT(&res) = VT_I4;
2426 V_VT(&idx) = VT_I4;
2427 V_I4(&idx) = 1;
2429 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2430 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2431 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2432 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2433 VariantClear(&res);
2435 IHTMLStyleSheetsCollection_Release(col);
2438 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2440 IDispatchEx *dispex;
2441 IHTMLDOMNode *node;
2442 DISPPARAMS dp = {NULL, NULL, 0, 0};
2443 VARIANT var;
2444 EXCEPINFO ei;
2445 long type;
2446 DISPID id;
2447 BSTR bstr;
2448 HRESULT hres;
2450 static const WCHAR w0[] = {'0',0};
2451 static const WCHAR w100[] = {'1','0','0',0};
2453 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2454 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2456 bstr = SysAllocString(w0);
2457 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2458 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2459 SysFreeString(bstr);
2461 VariantInit(&var);
2462 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2463 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2464 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2465 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2466 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2467 type = get_node_type((IUnknown*)node);
2468 ok(type == 3, "type=%ld\n", type);
2469 IHTMLDOMNode_Release(node);
2470 VariantClear(&var);
2472 bstr = SysAllocString(w100);
2473 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2474 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2475 SysFreeString(bstr);
2477 IDispatchEx_Release(dispex);
2482 static void test_elems(IHTMLDocument2 *doc)
2484 IHTMLElementCollection *col;
2485 IHTMLDOMChildrenCollection *child_col;
2486 IHTMLElement *elem, *elem2, *elem3;
2487 IHTMLDOMNode *node, *node2;
2488 IDispatch *disp;
2489 long type;
2490 HRESULT hres;
2492 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2493 static const WCHAR inW[] = {'i','n',0};
2494 static const WCHAR xW[] = {'x',0};
2495 static const WCHAR sW[] = {'s',0};
2496 static const WCHAR scW[] = {'s','c',0};
2497 static const WCHAR xxxW[] = {'x','x','x',0};
2498 static const WCHAR tblW[] = {'t','b','l',0};
2499 static const WCHAR row2W[] = {'r','o','w','2',0};
2501 static const elem_type_t all_types[] = {
2502 ET_HTML,
2503 ET_HEAD,
2504 ET_TITLE,
2505 ET_STYLE,
2506 ET_BODY,
2507 ET_COMMENT,
2508 ET_A,
2509 ET_INPUT,
2510 ET_SELECT,
2511 ET_OPTION,
2512 ET_OPTION,
2513 ET_TEXTAREA,
2514 ET_TABLE,
2515 ET_TBODY,
2516 ET_TR,
2517 ET_TR,
2518 ET_TD,
2519 ET_TD,
2520 ET_SCRIPT,
2521 ET_TEST,
2522 ET_IMG
2525 static const elem_type_t item_types[] = {
2526 ET_A,
2527 ET_OPTION,
2528 ET_TEXTAREA
2531 hres = IHTMLDocument2_get_all(doc, &col);
2532 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2533 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2534 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2535 IHTMLElementCollection_Release(col);
2537 elem = get_doc_elem(doc);
2538 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
2539 hres = IHTMLElement_get_all(elem, &disp);
2540 IHTMLElement_Release(elem);
2541 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2543 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2544 IDispatch_Release(disp);
2545 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2546 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
2547 IHTMLElementCollection_Release(col);
2549 get_elem_by_id(doc, xxxW, FALSE);
2550 elem = get_doc_elem_by_id(doc, xxxW);
2551 ok(!elem, "elem != NULL\n");
2553 elem = get_doc_elem_by_id(doc, sW);
2554 ok(elem != NULL, "elem == NULL\n");
2555 if(elem) {
2556 test_elem_type((IUnknown*)elem, ET_SELECT);
2557 test_elem_attr(elem, xxxW, NULL);
2558 test_elem_attr(elem, idW, sW);
2559 test_elem_class((IUnknown*)elem, NULL);
2560 test_elem_set_class((IUnknown*)elem, "cl");
2561 test_elem_set_class((IUnknown*)elem, NULL);
2562 test_elem_tabindex((IUnknown*)elem, 0);
2563 test_elem_set_tabindex((IUnknown*)elem, 1);
2565 node = test_node_get_parent((IUnknown*)elem);
2566 ok(node != NULL, "node == NULL\n");
2567 test_node_name((IUnknown*)node, "BODY");
2568 node2 = test_node_get_parent((IUnknown*)node);
2569 IHTMLDOMNode_Release(node);
2570 ok(node2 != NULL, "node == NULL\n");
2571 test_node_name((IUnknown*)node2, "HTML");
2572 node = test_node_get_parent((IUnknown*)node2);
2573 IHTMLDOMNode_Release(node2);
2574 ok(node != NULL, "node == NULL\n");
2575 test_node_name((IUnknown*)node, "#document");
2576 type = get_node_type((IUnknown*)node);
2577 ok(type == 9, "type=%ld, expected 9\n", type);
2578 node2 = test_node_get_parent((IUnknown*)node);
2579 IHTMLDOMNode_Release(node);
2580 ok(node2 == NULL, "node != NULL\n");
2582 elem2 = test_elem_get_parent((IUnknown*)elem);
2583 ok(elem2 != NULL, "elem2 == NULL\n");
2584 test_node_name((IUnknown*)elem2, "BODY");
2585 elem3 = test_elem_get_parent((IUnknown*)elem2);
2586 IHTMLElement_Release(elem2);
2587 ok(elem3 != NULL, "elem3 == NULL\n");
2588 test_node_name((IUnknown*)elem3, "HTML");
2589 elem2 = test_elem_get_parent((IUnknown*)elem3);
2590 IHTMLElement_Release(elem3);
2591 ok(elem2 == NULL, "elem2 != NULL\n");
2593 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
2594 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
2595 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
2597 IHTMLElement_Release(elem);
2600 elem = get_elem_by_id(doc, sW, TRUE);
2601 if(elem) {
2602 IHTMLSelectElement *select;
2604 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
2605 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
2607 test_select_elem(select);
2609 test_elem_title((IUnknown*)select, NULL);
2610 test_elem_set_title((IUnknown*)select, "Title");
2611 test_elem_title((IUnknown*)select, "Title");
2612 test_elem_offset((IUnknown*)select);
2614 node = get_first_child((IUnknown*)select);
2615 ok(node != NULL, "node == NULL\n");
2616 if(node) {
2617 test_elem_type((IUnknown*)node, ET_OPTION);
2618 IHTMLDOMNode_Release(node);
2621 type = get_node_type((IUnknown*)select);
2622 ok(type == 1, "type=%ld\n", type);
2624 IHTMLSelectElement_Release(select);
2625 IHTMLElement_Release(elem);
2628 elem = get_elem_by_id(doc, scW, TRUE);
2629 if(elem) {
2630 IHTMLScriptElement *script;
2631 BSTR type;
2633 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
2634 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
2636 hres = IHTMLScriptElement_get_type(script, &type);
2637 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2638 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
2639 SysFreeString(type);
2641 IHTMLScriptElement_Release(script);
2644 elem = get_elem_by_id(doc, inW, TRUE);
2645 if(elem) {
2646 IHTMLInputElement *input;
2648 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
2649 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2651 test_elem_id((IUnknown*)elem, "in");
2652 test_elem_put_id((IUnknown*)elem, "newin");
2653 test_input_get_disabled(input, VARIANT_FALSE);
2654 test_input_set_disabled(input, VARIANT_TRUE);
2655 test_input_set_disabled(input, VARIANT_FALSE);
2656 test_elem_client_size((IUnknown*)elem);
2658 test_node_get_value_str((IUnknown*)elem, NULL);
2659 test_node_put_value_str((IUnknown*)elem, "test");
2660 test_node_get_value_str((IUnknown*)elem, NULL);
2661 test_input_value((IUnknown*)elem, NULL);
2662 test_input_put_value((IUnknown*)elem, "test");
2663 test_input_value((IUnknown*)elem, NULL);
2664 test_elem_class((IUnknown*)elem, "testclass");
2665 test_elem_tabindex((IUnknown*)elem, 2);
2666 test_elem_set_tabindex((IUnknown*)elem, 3);
2667 test_elem_title((IUnknown*)elem, "test title");
2669 IHTMLInputElement_Release(input);
2670 IHTMLElement_Release(elem);
2673 elem = get_elem_by_id(doc, imgidW, TRUE);
2674 if(elem) {
2675 test_img_set_src((IUnknown*)elem, "about:blank");
2676 test_img_alt((IUnknown*)elem, NULL);
2677 test_img_set_alt((IUnknown*)elem, "alt test");
2678 IHTMLElement_Release(elem);
2681 elem = get_doc_elem_by_id(doc, tblW);
2682 ok(elem != NULL, "elem == NULL\n");
2683 if(elem) {
2684 test_table_elem(elem);
2685 IHTMLElement_Release(elem);
2688 elem = get_doc_elem_by_id(doc, row2W);
2689 ok(elem != NULL, "elem == NULL\n");
2690 if(elem) {
2691 test_tr_elem(elem);
2692 IHTMLElement_Release(elem);
2695 hres = IHTMLDocument2_get_body(doc, &elem);
2696 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2698 node = get_first_child((IUnknown*)elem);
2699 ok(node != NULL, "node == NULL\n");
2700 if(node) {
2701 test_ifaces((IUnknown*)node, text_iids);
2702 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2704 node2 = get_first_child((IUnknown*)node);
2705 ok(!node2, "node2 != NULL\n");
2707 type = get_node_type((IUnknown*)node);
2708 ok(type == 3, "type=%ld\n", type);
2710 test_node_get_value_str((IUnknown*)node, "text test");
2711 test_node_put_value_str((IUnknown*)elem, "test text");
2712 test_node_get_value_str((IUnknown*)node, "text test");
2714 IHTMLDOMNode_Release(node);
2717 child_col = get_child_nodes((IUnknown*)elem);
2718 ok(child_col != NULL, "child_coll == NULL\n");
2719 if(child_col) {
2720 long length = 0;
2722 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
2724 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
2725 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2726 ok(length, "length=0\n");
2728 node = get_child_item(child_col, 0);
2729 ok(node != NULL, "node == NULL\n");
2730 if(node) {
2731 type = get_node_type((IUnknown*)node);
2732 ok(type == 3, "type=%ld\n", type);
2733 IHTMLDOMNode_Release(node);
2736 node = get_child_item(child_col, 1);
2737 ok(node != NULL, "node == NULL\n");
2738 if(node) {
2739 type = get_node_type((IUnknown*)node);
2740 ok(type == 8, "type=%ld\n", type);
2742 test_elem_id((IUnknown*)node, NULL);
2743 IHTMLDOMNode_Release(node);
2746 disp = (void*)0xdeadbeef;
2747 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
2748 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2749 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2751 disp = (void*)0xdeadbeef;
2752 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
2753 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2754 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
2756 test_child_col_disp(child_col);
2758 IHTMLDOMChildrenCollection_Release(child_col);
2761 IHTMLElement_Release(elem);
2763 test_stylesheets(doc);
2764 test_create_option_elem(doc);
2766 test_doc_title(doc, "test");
2767 test_doc_set_title(doc, "test title");
2768 test_doc_title(doc, "test title");
2771 static void test_create_elems(IHTMLDocument2 *doc)
2773 IHTMLElement *elem, *body, *elem2;
2774 IHTMLDOMNode *node;
2775 IDispatch *disp;
2776 long type;
2777 HRESULT hres;
2779 static const elem_type_t types1[] = { ET_TESTG };
2781 elem = test_create_elem(doc, "TEST");
2782 test_elem_tag((IUnknown*)elem, "TEST");
2783 type = get_node_type((IUnknown*)elem);
2784 ok(type == 1, "type=%ld\n", type);
2785 test_ifaces((IUnknown*)elem, elem_iids);
2786 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
2788 hres = IHTMLDocument2_get_body(doc, &body);
2789 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2790 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2792 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
2793 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
2794 elem2 = get_elem_iface((IUnknown*)node);
2795 IHTMLElement_Release(elem2);
2797 hres = IHTMLElement_get_all(body, &disp);
2798 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2799 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
2800 IDispatch_Release(disp);
2802 test_node_remove_child((IUnknown*)body, node);
2804 hres = IHTMLElement_get_all(body, &disp);
2805 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2806 test_elem_collection((IUnknown*)disp, NULL, 0);
2807 IDispatch_Release(disp);
2808 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
2810 IHTMLElement_Release(body);
2811 IHTMLElement_Release(elem);
2812 IHTMLDOMNode_Release(node);
2814 node = test_create_text(doc, "test");
2815 test_ifaces((IUnknown*)node, text_iids);
2816 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2817 IHTMLDOMNode_Release(node);
2820 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
2822 IOleCommandTarget *cmdtrg;
2823 HRESULT hres;
2825 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2826 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
2828 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
2829 ok(hres == S_OK, "Exec failed: %08x\n", hres);
2831 IOleCommandTarget_Release(cmdtrg);
2834 static void test_indent(IHTMLDocument2 *doc)
2836 IHTMLElementCollection *col;
2837 IHTMLTxtRange *range;
2838 HRESULT hres;
2840 static const elem_type_t all_types[] = {
2841 ET_HTML,
2842 ET_HEAD,
2843 ET_TITLE,
2844 ET_BODY,
2845 ET_BR,
2846 ET_A,
2849 static const elem_type_t indent_types[] = {
2850 ET_HTML,
2851 ET_HEAD,
2852 ET_TITLE,
2853 ET_BODY,
2854 ET_BLOCKQUOTE,
2855 ET_P,
2856 ET_BR,
2857 ET_A,
2860 hres = IHTMLDocument2_get_all(doc, &col);
2861 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2862 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2863 IHTMLElementCollection_Release(col);
2865 range = test_create_body_range(doc);
2866 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
2867 IHTMLTxtRange_Release(range);
2869 hres = IHTMLDocument2_get_all(doc, &col);
2870 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2871 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
2872 IHTMLElementCollection_Release(col);
2875 static IHTMLDocument2 *notif_doc;
2876 static BOOL doc_complete;
2878 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2879 REFIID riid, void**ppv)
2881 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2882 *ppv = iface;
2883 return S_OK;
2886 ok(0, "unexpected call\n");
2887 return E_NOINTERFACE;
2890 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2892 return 2;
2895 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2897 return 1;
2900 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2902 if(dispID == DISPID_READYSTATE){
2903 BSTR state;
2904 HRESULT hres;
2906 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
2908 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2909 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2911 if(!lstrcmpW(state, completeW))
2912 doc_complete = TRUE;
2914 SysFreeString(state);
2917 return S_OK;
2920 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2922 ok(0, "unexpected call\n");
2923 return E_NOTIMPL;
2926 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2927 PropertyNotifySink_QueryInterface,
2928 PropertyNotifySink_AddRef,
2929 PropertyNotifySink_Release,
2930 PropertyNotifySink_OnChanged,
2931 PropertyNotifySink_OnRequestEdit
2934 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2936 static IHTMLDocument2 *create_doc_with_string(const char *str)
2938 IPersistStreamInit *init;
2939 IStream *stream;
2940 IHTMLDocument2 *doc;
2941 HGLOBAL mem;
2942 SIZE_T len;
2944 notif_doc = doc = create_document();
2945 if(!doc)
2946 return NULL;
2948 doc_complete = FALSE;
2949 len = strlen(str);
2950 mem = GlobalAlloc(0, len);
2951 memcpy(mem, str, len);
2952 CreateStreamOnHGlobal(mem, TRUE, &stream);
2954 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2956 IPersistStreamInit_Load(init, stream);
2957 IPersistStreamInit_Release(init);
2958 IStream_Release(stream);
2960 return doc;
2963 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2965 IConnectionPointContainer *container;
2966 IConnectionPoint *cp;
2967 DWORD cookie;
2968 HRESULT hres;
2970 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2971 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2973 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2974 IConnectionPointContainer_Release(container);
2975 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2977 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2978 IConnectionPoint_Release(cp);
2979 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2982 typedef void (*domtest_t)(IHTMLDocument2*);
2984 static void run_domtest(const char *str, domtest_t test)
2986 IHTMLDocument2 *doc;
2987 IHTMLElement *body = NULL;
2988 ULONG ref;
2989 MSG msg;
2990 HRESULT hres;
2992 doc = create_doc_with_string(str);
2993 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2995 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
2996 TranslateMessage(&msg);
2997 DispatchMessage(&msg);
3000 hres = IHTMLDocument2_get_body(doc, &body);
3001 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3003 if(body) {
3004 IHTMLElement_Release(body);
3005 test(doc);
3006 }else {
3007 skip("Could not get document body. Assuming no Gecko installed.\n");
3010 ref = IHTMLDocument2_Release(doc);
3011 ok(!ref ||
3012 ref == 1, /* Vista */
3013 "ref = %d\n", ref);
3016 static void gecko_installer_workaround(BOOL disable)
3018 HKEY hkey;
3019 DWORD res;
3021 static BOOL has_url = FALSE;
3022 static char url[2048];
3024 if(!disable && !has_url)
3025 return;
3027 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
3028 if(res != ERROR_SUCCESS)
3029 return;
3031 if(disable) {
3032 DWORD type, size = sizeof(url);
3034 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
3035 if(res == ERROR_SUCCESS && type == REG_SZ)
3036 has_url = TRUE;
3038 RegDeleteValue(hkey, "GeckoUrl");
3039 }else {
3040 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
3043 RegCloseKey(hkey);
3046 START_TEST(dom)
3048 gecko_installer_workaround(TRUE);
3049 CoInitialize(NULL);
3051 run_domtest(doc_str1, test_doc_elem);
3052 run_domtest(range_test_str, test_txtrange);
3053 run_domtest(range_test2_str, test_txtrange2);
3054 run_domtest(elem_test_str, test_elems);
3055 run_domtest(doc_blank, test_create_elems);
3056 run_domtest(doc_blank, test_defaults);
3057 run_domtest(indent_test_str, test_indent);
3059 CoUninitialize();
3060 gecko_installer_workaround(FALSE);