change default iSmCaptionWidth to 12
[wine/kumbayo.git] / dlls / mshtml / tests / dom.c
blobcb7faa33daa4cf7cc2fe9ef148577d96d25c5ae8
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"
34 static const char doc_blank[] = "<html></html>";
35 static const char doc_str1[] = "<html><body>test</body></html>";
36 static const char doc_str2[] =
37 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
38 static const char elem_test_str[] =
39 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
40 "<body><a href=\"http://test\" name=\"x\">link</a><input />"
41 "<select id=\"s\"><option id=\"x\">opt1</option><option id=\"y\">opt2</option></select>"
42 "<textarea id=\"X\">text text</textarea>"
43 "<table><tbody></tbody></table>"
44 "</body></html>";
45 static const char indent_test_str[] =
46 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
48 static const WCHAR noneW[] = {'N','o','n','e',0};
50 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
51 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
52 static WCHAR wordW[] = {'w','o','r','d',0};
54 typedef enum {
55 ET_NONE,
56 ET_HTML,
57 ET_HEAD,
58 ET_TITLE,
59 ET_BODY,
60 ET_A,
61 ET_INPUT,
62 ET_SELECT,
63 ET_TEXTAREA,
64 ET_OPTION,
65 ET_STYLE,
66 ET_BLOCKQUOTE,
67 ET_P,
68 ET_BR,
69 ET_TABLE,
70 ET_TBODY
71 } elem_type_t;
73 static REFIID const none_iids[] = {
74 &IID_IUnknown,
75 NULL
78 static REFIID const elem_iids[] = {
79 &IID_IHTMLDOMNode,
80 &IID_IHTMLElement,
81 &IID_IHTMLElement2,
82 &IID_IConnectionPointContainer,
83 NULL
86 static REFIID const body_iids[] = {
87 &IID_IHTMLDOMNode,
88 &IID_IHTMLElement,
89 &IID_IHTMLElement2,
90 &IID_IHTMLTextContainer,
91 &IID_IHTMLBodyElement,
92 &IID_IConnectionPointContainer,
93 NULL
96 static REFIID const anchor_iids[] = {
97 &IID_IHTMLDOMNode,
98 &IID_IHTMLElement,
99 &IID_IHTMLElement2,
100 &IID_IHTMLAnchorElement,
101 &IID_IConnectionPointContainer,
102 NULL
105 static REFIID const input_iids[] = {
106 &IID_IHTMLDOMNode,
107 &IID_IHTMLElement,
108 &IID_IHTMLElement2,
109 &IID_IHTMLInputElement,
110 &IID_IHTMLInputTextElement,
111 &IID_IConnectionPointContainer,
112 NULL
115 static REFIID const select_iids[] = {
116 &IID_IHTMLDOMNode,
117 &IID_IHTMLElement,
118 &IID_IHTMLElement2,
119 &IID_IHTMLSelectElement,
120 &IID_IConnectionPointContainer,
121 NULL
124 static REFIID const textarea_iids[] = {
125 &IID_IHTMLDOMNode,
126 &IID_IHTMLElement,
127 &IID_IHTMLElement2,
128 &IID_IHTMLTextAreaElement,
129 &IID_IConnectionPointContainer,
130 NULL
133 static REFIID const option_iids[] = {
134 &IID_IHTMLDOMNode,
135 &IID_IHTMLElement,
136 &IID_IHTMLElement2,
137 &IID_IHTMLOptionElement,
138 &IID_IConnectionPointContainer,
139 NULL
142 static REFIID const table_iids[] = {
143 &IID_IHTMLDOMNode,
144 &IID_IHTMLElement,
145 &IID_IHTMLElement2,
146 &IID_IHTMLTable,
147 &IID_IConnectionPointContainer,
148 NULL
151 typedef struct {
152 const char *tag;
153 REFIID *iids;
154 } elem_type_info_t;
156 static const elem_type_info_t elem_type_infos[] = {
157 {"", none_iids},
158 {"HTML", elem_iids},
159 {"HEAD", elem_iids},
160 {"TITLE", elem_iids},
161 {"BODY", body_iids},
162 {"A", anchor_iids},
163 {"INPUT", input_iids},
164 {"SELECT", select_iids},
165 {"TEXTAREA", textarea_iids},
166 {"OPTION", option_iids},
167 {"STYLE", elem_iids},
168 {"BLOCKQUOTE",elem_iids},
169 {"P", elem_iids},
170 {"BR", elem_iids},
171 {"TABLE", table_iids},
172 {"TBODY", elem_iids}
175 static const char *dbgstr_w(LPCWSTR str)
177 static char buf[512];
178 if(!str)
179 return "(null)";
180 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
181 return buf;
184 static const char *dbgstr_guid(REFIID riid)
186 static char buf[50];
188 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
189 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
190 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
191 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
193 return buf;
196 static int strcmp_wa(LPCWSTR strw, const char *stra)
198 WCHAR buf[512];
199 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
200 return lstrcmpW(strw, buf);
203 static BSTR a2bstr(const char *str)
205 BSTR ret;
206 int len;
208 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
209 ret = SysAllocStringLen(NULL, len);
210 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
212 return ret;
215 static IHTMLDocument2 *create_document(void)
217 IHTMLDocument2 *doc;
218 HRESULT hres;
220 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
221 &IID_IHTMLDocument2, (void**)&doc);
222 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
224 return doc;
227 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
228 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
230 const IID * const *piid;
231 IUnknown *unk;
232 HRESULT hres;
234 for(piid = iids; *piid; piid++) {
235 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
236 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
237 if(SUCCEEDED(hres))
238 IUnknown_Release(unk);
242 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
243 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
245 IHTMLDOMNode *node;
246 BSTR name;
247 HRESULT hres;
249 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
250 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
252 hres = IHTMLDOMNode_get_nodeName(node, &name);
253 IHTMLDOMNode_Release(node);
254 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
255 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
257 SysFreeString(name);
260 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
261 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
263 IHTMLElement *elem;
264 BSTR tag;
265 HRESULT hres;
267 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
268 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
270 hres = IHTMLElement_get_tagName(elem, &tag);
271 IHTMLElement_Release(elem);
272 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
273 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
275 SysFreeString(tag);
278 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
279 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
281 _test_elem_tag(line, unk, elem_type_infos[type].tag);
282 _test_ifaces(line, unk, elem_type_infos[type].iids);
285 static void test_doc_elem(IHTMLDocument2 *doc)
287 IHTMLElement *elem;
288 IHTMLDocument3 *doc3;
289 HRESULT hres;
291 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
292 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
294 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
295 IHTMLDocument3_Release(doc3);
296 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
298 test_node_name((IUnknown*)elem, "HTML");
299 test_elem_tag((IUnknown*)elem, "HTML");
301 IHTMLElement_Release(elem);
304 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
305 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
307 IHTMLElement *elem;
308 IHTMLDocument3 *doc3;
309 HRESULT hres;
311 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
312 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
313 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
314 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
315 IHTMLDocument3_Release(doc3);
317 return elem;
320 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
321 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
323 BSTR bstr;
324 HRESULT hres;
326 hres = IHTMLOptionElement_get_text(option, &bstr);
327 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
328 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
329 SysFreeString(bstr);
332 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
333 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
335 BSTR bstr;
336 HRESULT hres;
338 bstr = a2bstr(text);
339 hres = IHTMLOptionElement_put_text(option, bstr);
340 SysFreeString(bstr);
341 ok(hres == S_OK, "put_text failed: %08x\n", hres);
343 _test_option_text(line, option, text);
346 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
347 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
349 BSTR bstr;
350 HRESULT hres;
352 hres = IHTMLOptionElement_get_value(option, &bstr);
353 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
354 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
355 SysFreeString(bstr);
358 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
359 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
361 BSTR bstr;
362 HRESULT hres;
364 bstr = a2bstr(value);
365 hres = IHTMLOptionElement_put_value(option, bstr);
366 SysFreeString(bstr);
367 ok(hres == S_OK, "put_value failed: %08x\n", hres);
369 _test_option_value(line, option, value);
372 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
373 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
374 const char *txt, const char *val)
376 IHTMLOptionElementFactory *factory;
377 IHTMLOptionElement *option;
378 IHTMLWindow2 *window;
379 VARIANT text, value, empty;
380 HRESULT hres;
382 hres = IHTMLDocument2_get_parentWindow(doc, &window);
383 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
385 hres = IHTMLWindow2_get_Option(window, &factory);
386 IHTMLWindow2_Release(window);
387 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
389 V_VT(&text) = VT_BSTR;
390 V_BSTR(&text) = a2bstr(txt);
391 V_VT(&value) = VT_BSTR;
392 V_BSTR(&value) = a2bstr(val);
393 V_VT(&empty) = VT_EMPTY;
395 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
396 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
398 IHTMLOptionElementFactory_Release(factory);
399 VariantClear(&text);
400 VariantClear(&value);
402 _test_option_text(line, option, txt);
403 _test_option_value(line, option, val);
405 return option;
408 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
409 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
411 long len = 0xdeadbeef;
412 HRESULT hres;
414 hres = IHTMLSelectElement_get_length(select, &len);
415 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
416 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
419 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
420 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
422 long idx = 0xdeadbeef;
423 HRESULT hres;
425 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
426 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
427 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
430 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
431 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
433 HRESULT hres;
435 hres = IHTMLSelectElement_put_selectedIndex(select, index);
436 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
437 _test_select_selidx(line, select, index);
440 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
441 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
443 BSTR text;
444 HRESULT hres;
446 hres = IHTMLTxtRange_get_text(range, &text);
447 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
449 if(extext) {
450 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
451 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
452 }else {
453 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
456 SysFreeString(text);
460 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
461 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
463 HRESULT hres;
465 hres = IHTMLTxtRange_collapse(range, b);
466 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
467 _test_range_text(line, range, NULL);
470 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
471 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
472 VARIANT_BOOL exb, const char *extext)
474 VARIANT_BOOL b = 0xe0e0;
475 HRESULT hres;
477 hres = IHTMLTxtRange_expand(range, unit, &b);
478 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
479 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
480 _test_range_text(line, range, extext);
483 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
484 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
486 long c = 0xdeadbeef;
487 HRESULT hres;
489 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
490 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
491 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
492 _test_range_text(line, range, NULL);
495 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
496 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
497 LPWSTR unit, long cnt, long excnt)
499 long c = 0xdeadbeef;
500 HRESULT hres;
502 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
503 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
504 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
507 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
508 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
510 long c = 0xdeadbeef;
511 HRESULT hres;
513 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
514 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
515 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
518 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
519 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
521 HRESULT hres;
522 BSTR bstr = a2bstr(text);
524 hres = IHTMLTxtRange_put_text(range, bstr);
525 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
526 SysFreeString(bstr);
527 _test_range_text(line, range, NULL);
530 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
531 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
533 VARIANT_BOOL b;
534 HRESULT hres;
536 b = 0xe0e0;
537 hres = IHTMLTxtRange_inRange(range1, range2, &b);
538 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
539 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
542 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
543 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
545 VARIANT_BOOL b;
546 HRESULT hres;
548 b = 0xe0e0;
549 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
550 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
551 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
553 b = 0xe0e0;
554 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
555 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
556 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
558 if(exb) {
559 test_range_inrange(range1, range2, VARIANT_TRUE);
560 test_range_inrange(range2, range1, VARIANT_TRUE);
564 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
565 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
567 IHTMLElement *elem;
568 HRESULT hres;
570 hres = IHTMLTxtRange_parentElement(range, &elem);
571 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
573 _test_elem_type(line, (IUnknown*)elem, type);
575 IHTMLElement_Release(elem);
578 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
579 static void _test_elem_collection(unsigned line, IHTMLElementCollection *col,
580 const elem_type_t *elem_types, long exlen)
582 long len;
583 DWORD i;
584 VARIANT name, index;
585 IDispatch *disp;
586 HRESULT hres;
588 hres = IHTMLElementCollection_get_length(col, &len);
589 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
590 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
592 if(len > exlen)
593 len = exlen;
595 V_VT(&index) = VT_EMPTY;
596 V_VT(&name) = VT_I4;
598 for(i=0; i<len; i++) {
599 V_I4(&name) = i;
600 disp = (void*)0xdeadbeef;
601 hres = IHTMLElementCollection_item(col, name, index, &disp);
602 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
603 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
604 if(FAILED(hres) || !disp)
605 continue;
607 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
608 IDispatch_Release(disp);
611 V_I4(&name) = len;
612 disp = (void*)0xdeadbeef;
613 hres = IHTMLElementCollection_item(col, name, index, &disp);
614 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
615 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
617 V_I4(&name) = -1;
618 disp = (void*)0xdeadbeef;
619 hres = IHTMLElementCollection_item(col, name, index, &disp);
620 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
621 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
624 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
625 const elem_type_t *elem_types, long len)
627 IHTMLElementCollection *elcol;
628 IDispatch *disp;
629 VARIANT name, index;
630 DWORD i;
631 HRESULT hres;
633 V_VT(&index) = VT_EMPTY;
634 V_VT(&name) = VT_BSTR;
635 V_BSTR(&name) = SysAllocString(n);
637 hres = IHTMLElementCollection_item(col, name, index, &disp);
638 ok(hres == S_OK, "item failed: %08x\n", hres);
640 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol);
641 IDispatch_Release(disp);
642 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
643 test_elem_collection(elcol, elem_types, len);
644 IHTMLElementCollection_Release(elcol);
646 V_VT(&index) = VT_I4;
648 for(i=0; i<len; i++) {
649 V_I4(&index) = i;
650 disp = (void*)0xdeadbeef;
651 hres = IHTMLElementCollection_item(col, name, index, &disp);
652 ok(hres == S_OK, "item failed: %08x\n", hres);
653 ok(disp != NULL, "disp == NULL\n");
654 if(FAILED(hres) || !disp)
655 continue;
657 test_elem_type((IUnknown*)disp, elem_types[i]);
659 IDispatch_Release(disp);
662 V_I4(&index) = len;
663 disp = (void*)0xdeadbeef;
664 hres = IHTMLElementCollection_item(col, name, index, &disp);
665 ok(hres == S_OK, "item failed: %08x\n", hres);
666 ok(disp == NULL, "disp != NULL\n");
668 V_I4(&index) = -1;
669 disp = (void*)0xdeadbeef;
670 hres = IHTMLElementCollection_item(col, name, index, &disp);
671 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
672 ok(disp == NULL, "disp != NULL\n");
674 SysFreeString(V_BSTR(&name));
677 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
679 IHTMLElementCollection *col;
680 IHTMLElement *elem;
681 IDispatch *disp = (void*)0xdeadbeef;
682 VARIANT name, index;
683 HRESULT hres;
685 hres = IHTMLDocument2_get_all(doc, &col);
686 ok(hres == S_OK, "get_all failed: %08x\n", hres);
687 ok(col != NULL, "col == NULL\n");
688 if(FAILED(hres) || !col)
689 return NULL;
691 V_VT(&index) = VT_EMPTY;
692 V_VT(&name) = VT_BSTR;
693 V_BSTR(&name) = SysAllocString(id);
695 hres = IHTMLElementCollection_item(col, name, index, &disp);
696 IHTMLElementCollection_Release(col);
697 SysFreeString(V_BSTR(&name));
698 ok(hres == S_OK, "item failed: %08x\n", hres);
699 if(!expect_success) {
700 ok(disp == NULL, "disp != NULL\n");
701 return NULL;
704 ok(disp != NULL, "disp == NULL\n");
705 if(!disp)
706 return NULL;
708 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElement, (void**)&elem);
709 IDispatch_Release(disp);
710 ok(hres == S_OK, "Could not get IHTMLElement interface: %08x\n", hres);
712 return elem;
715 static void test_select_elem(IHTMLSelectElement *select)
717 test_select_length(select, 2);
718 test_select_selidx(select, 0);
719 test_select_put_selidx(select, 1);
722 static void test_create_option_elem(IHTMLDocument2 *doc)
724 IHTMLOptionElement *option;
726 option = create_option_elem(doc, "test text", "test value");
728 test_option_put_text(option, "new text");
729 test_option_put_value(option, "new value");
731 IHTMLOptionElement_Release(option);
734 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
736 IHTMLBodyElement *body;
737 IHTMLTxtRange *range;
738 IHTMLElement *elem;
739 HRESULT hres;
741 hres = IHTMLDocument2_get_body(doc, &elem);
742 ok(hres == S_OK, "get_body failed: %08x\n", hres);
744 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
745 IHTMLElement_Release(elem);
747 hres = IHTMLBodyElement_createTextRange(body, &range);
748 IHTMLBodyElement_Release(body);
749 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
751 return range;
754 static void test_txtrange(IHTMLDocument2 *doc)
756 IHTMLTxtRange *body_range, *range, *range2;
757 IHTMLSelectionObject *selection;
758 IDispatch *disp_range;
759 HRESULT hres;
761 body_range = test_create_body_range(doc);
763 test_range_text(body_range, "test abc 123\r\nit's text");
765 hres = IHTMLTxtRange_duplicate(body_range, &range);
766 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
768 hres = IHTMLTxtRange_duplicate(body_range, &range2);
769 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
770 test_range_isequal(range, range2, VARIANT_TRUE);
772 test_range_text(range, "test abc 123\r\nit's text");
773 test_range_text(body_range, "test abc 123\r\nit's text");
775 test_range_collapse(range, TRUE);
776 test_range_isequal(range, range2, VARIANT_FALSE);
777 test_range_inrange(range, range2, VARIANT_FALSE);
778 test_range_inrange(range2, range, VARIANT_TRUE);
779 IHTMLTxtRange_Release(range2);
781 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
782 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
783 test_range_move(range, characterW, 2, 2);
784 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
786 test_range_collapse(range, FALSE);
787 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
789 test_range_collapse(range, FALSE);
790 test_range_expand(range, wordW, VARIANT_TRUE, "123");
791 test_range_expand(range, wordW, VARIANT_FALSE, "123");
792 test_range_move(range, characterW, 2, 2);
793 test_range_expand(range, wordW, VARIANT_TRUE, "123");
794 test_range_moveend(range, characterW, -5, -5);
795 test_range_text(range, NULL);
796 test_range_moveend(range, characterW, 3, 3);
797 test_range_text(range, "c 1");
798 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
799 test_range_collapse(range, TRUE);
800 test_range_move(range, characterW, 4, 4);
801 test_range_moveend(range, characterW, 1, 1);
802 test_range_text(range, " ");
803 test_range_move(range, wordW, 1, 1);
804 test_range_moveend(range, characterW, 2, 2);
805 test_range_text(range, "ab");
807 IHTMLTxtRange_Release(range);
809 hres = IHTMLTxtRange_duplicate(body_range, &range);
810 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
812 test_range_text(range, "test abc 123\r\nit's text");
813 test_range_move(range, characterW, 3, 3);
814 test_range_moveend(range, characterW, 1, 1);
815 test_range_text(range, "t");
816 test_range_moveend(range, characterW, 3, 3);
817 test_range_text(range, "t ab");
818 test_range_moveend(range, characterW, -2, -2);
819 test_range_text(range, "t ");
820 test_range_move(range, characterW, 6, 6);
821 test_range_moveend(range, characterW, 3, 3);
822 test_range_text(range, "123");
823 test_range_moveend(range, characterW, 2, 2);
824 test_range_text(range, "123\r\ni");
826 IHTMLTxtRange_Release(range);
828 hres = IHTMLTxtRange_duplicate(body_range, &range);
829 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
831 test_range_move(range, wordW, 1, 1);
832 test_range_moveend(range, characterW, 2, 2);
833 test_range_text(range, "ab");
835 test_range_move(range, characterW, -2, -2);
836 test_range_moveend(range, characterW, 2, 2);
837 test_range_text(range, "t ");
839 test_range_move(range, wordW, 3, 3);
840 test_range_move(range, wordW, -2, -2);
841 test_range_moveend(range, characterW, 2, 2);
842 test_range_text(range, "ab");
844 test_range_move(range, characterW, -6, -5);
845 test_range_moveend(range, characterW, -1, 0);
846 test_range_moveend(range, characterW, -6, 0);
847 test_range_move(range, characterW, 2, 2);
848 test_range_moveend(range, characterW, 2, 2);
849 test_range_text(range, "st");
850 test_range_moveend(range, characterW, -6, -4);
851 test_range_moveend(range, characterW, 2, 2);
853 IHTMLTxtRange_Release(range);
855 hres = IHTMLTxtRange_duplicate(body_range, &range);
856 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
858 test_range_move(range, wordW, 2, 2);
859 test_range_moveend(range, characterW, 2, 2);
860 test_range_text(range, "12");
862 test_range_move(range, characterW, 15, 14);
863 test_range_move(range, characterW, -2, -2);
864 test_range_moveend(range, characterW, 3, 2);
865 test_range_text(range, "t");
866 test_range_moveend(range, characterW, -1, -1);
867 test_range_text(range, "t");
868 test_range_expand(range, wordW, VARIANT_TRUE, "text");
869 test_range_move(range, characterW, -2, -2);
870 test_range_moveend(range, characterW, 2, 2);
871 test_range_text(range, "s ");
872 test_range_move(range, characterW, 100, 7);
873 test_range_move(range, wordW, 1, 0);
874 test_range_move(range, characterW, -2, -2);
875 test_range_moveend(range, characterW, 3, 2);
876 test_range_text(range, "t");
878 IHTMLTxtRange_Release(range);
880 hres = IHTMLTxtRange_duplicate(body_range, &range);
881 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
883 test_range_collapse(range, TRUE);
884 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
885 test_range_put_text(range, "word");
886 test_range_text(body_range, "wordabc 123\r\nit's text");
887 test_range_text(range, NULL);
888 test_range_moveend(range, characterW, 3, 3);
889 test_range_text(range, "abc");
890 test_range_movestart(range, characterW, -2, -2);
891 test_range_text(range, "rdabc");
892 test_range_movestart(range, characterW, 3, 3);
893 test_range_text(range, "bc");
894 test_range_movestart(range, characterW, 4, 4);
895 test_range_text(range, NULL);
896 test_range_movestart(range, characterW, -3, -3);
897 test_range_text(range, "c 1");
898 test_range_movestart(range, characterW, -7, -6);
899 test_range_text(range, "wordabc 1");
900 test_range_movestart(range, characterW, 100, 22);
901 test_range_text(range, NULL);
903 IHTMLTxtRange_Release(range);
904 IHTMLTxtRange_Release(body_range);
906 hres = IHTMLDocument2_get_selection(doc, &selection);
907 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
909 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
910 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
911 IHTMLSelectionObject_Release(selection);
913 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
914 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
915 IDispatch_Release(disp_range);
917 test_range_text(range, NULL);
918 test_range_moveend(range, characterW, 3, 3);
919 test_range_text(range, "wor");
920 test_range_parent(range, ET_BODY);
921 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
922 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
923 test_range_move(range, characterW, 3, 3);
924 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
925 test_range_moveend(range, characterW, -4, -4);
926 test_range_put_text(range, "abc def ");
927 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
928 test_range_move(range, wordW, 1, 1);
929 test_range_movestart(range, characterW, -1, -1);
930 test_range_text(range, " ");
931 test_range_move(range, wordW, 1, 1);
932 test_range_moveend(range, characterW, 3, 3);
933 test_range_text(range, "def");
934 test_range_put_text(range, "xyz");
935 test_range_moveend(range, characterW, 1, 1);
936 test_range_move(range, wordW, 1, 1);
937 test_range_moveend(range, characterW, 2, 2);
938 test_range_text(range, "ab");
940 IHTMLTxtRange_Release(range);
943 static void test_compatmode(IHTMLDocument2 *doc)
945 IHTMLDocument5 *doc5;
946 BSTR mode;
947 HRESULT hres;
949 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
950 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
951 if(FAILED(hres))
952 return;
954 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
955 IHTMLDocument5_Release(doc5);
956 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
957 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
958 SysFreeString(mode);
961 static void test_default_style(IHTMLStyle *style)
963 VARIANT_BOOL b;
964 VARIANT v;
965 BSTR str;
966 HRESULT hres;
968 str = (void*)0xdeadbeef;
969 hres = IHTMLStyle_get_fontFamily(style, &str);
970 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
971 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
973 str = (void*)0xdeadbeef;
974 hres = IHTMLStyle_get_fontWeight(style, &str);
975 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
976 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
978 str = (void*)0xdeadbeef;
979 hres = IHTMLStyle_get_display(style, &str);
980 ok(hres == S_OK, "get_display failed: %08x\n", hres);
981 ok(!str, "display = %s\n", dbgstr_w(str));
983 str = (void*)0xdeadbeef;
984 hres = IHTMLStyle_get_visibility(style, &str);
985 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
986 ok(!str, "visibility = %s\n", dbgstr_w(str));
988 V_VT(&v) = VT_NULL;
989 hres = IHTMLStyle_get_fontSize(style, &v);
990 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
991 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
992 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
994 V_VT(&v) = VT_NULL;
995 hres = IHTMLStyle_get_color(style, &v);
996 ok(hres == S_OK, "get_color failed: %08x\n", hres);
997 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
998 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
1000 b = 0xfefe;
1001 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
1002 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
1003 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
1005 b = 0xfefe;
1006 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
1007 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
1008 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
1011 static void test_default_selection(IHTMLDocument2 *doc)
1013 IHTMLSelectionObject *selection;
1014 IHTMLTxtRange *range;
1015 IDispatch *disp;
1016 BSTR str;
1017 HRESULT hres;
1019 hres = IHTMLDocument2_get_selection(doc, &selection);
1020 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
1022 hres = IHTMLSelectionObject_get_type(selection, &str);
1023 ok(hres == S_OK, "get_type failed: %08x\n", hres);
1024 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
1025 SysFreeString(str);
1027 hres = IHTMLSelectionObject_createRange(selection, &disp);
1028 IHTMLSelectionObject_Release(selection);
1029 ok(hres == S_OK, "createRange failed: %08x\n", hres);
1031 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
1032 IDispatch_Release(disp);
1033 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
1035 test_range_text(range, NULL);
1036 IHTMLTxtRange_Release(range);
1039 static void test_default_body(IHTMLBodyElement *body)
1041 BSTR bstr;
1042 HRESULT hres;
1044 bstr = (void*)0xdeadbeef;
1045 hres = IHTMLBodyElement_get_background(body, &bstr);
1046 ok(hres == S_OK, "get_background failed: %08x\n", hres);
1047 ok(bstr == NULL, "bstr != NULL\n");
1050 static void test_defaults(IHTMLDocument2 *doc)
1052 IHTMLStyleSheetsCollection *stylesheetcol;
1053 IHTMLBodyElement *body;
1054 IHTMLElement *elem;
1055 IHTMLStyle *style;
1056 long l;
1057 HRESULT hres;
1059 hres = IHTMLDocument2_get_body(doc, &elem);
1060 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1062 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1063 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
1064 test_default_body(body);
1065 IHTMLBodyElement_Release(body);
1067 hres = IHTMLElement_get_style(elem, &style);
1068 IHTMLElement_Release(elem);
1069 ok(hres == S_OK, "get_style failed: %08x\n", hres);
1071 test_default_style(style);
1072 test_compatmode(doc);
1074 IHTMLStyle_Release(style);
1076 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
1077 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1079 l = 0xdeadbeef;
1080 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
1081 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1082 ok(l == 0, "length = %ld\n", l);
1084 IHTMLStyleSheetsCollection_Release(stylesheetcol);
1086 test_default_selection(doc);
1089 static void test_stylesheet(IDispatch *disp)
1091 IHTMLStyleSheetRulesCollection *col = NULL;
1092 IHTMLStyleSheet *stylesheet;
1093 HRESULT hres;
1095 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
1096 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
1098 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
1099 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
1100 ok(col != NULL, "col == NULL\n");
1102 IHTMLStyleSheetRulesCollection_Release(col);
1103 IHTMLStyleSheet_Release(stylesheet);
1106 static void test_stylesheets(IHTMLDocument2 *doc)
1108 IHTMLStyleSheetsCollection *col = NULL;
1109 VARIANT idx, res;
1110 long len = 0;
1111 HRESULT hres;
1113 hres = IHTMLDocument2_get_styleSheets(doc, &col);
1114 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
1115 ok(col != NULL, "col == NULL\n");
1117 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
1118 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1119 ok(len == 1, "len=%ld\n", len);
1121 VariantInit(&res);
1122 V_VT(&idx) = VT_I4;
1123 V_I4(&idx) = 0;
1125 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1126 ok(hres == S_OK, "item failed: %08x\n", hres);
1127 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
1128 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1129 test_stylesheet(V_DISPATCH(&res));
1130 VariantClear(&res);
1132 V_VT(&res) = VT_I4;
1133 V_VT(&idx) = VT_I4;
1134 V_I4(&idx) = 1;
1136 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
1137 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1138 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
1139 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
1140 VariantClear(&res);
1142 IHTMLStyleSheetsCollection_Release(col);
1145 static void test_elems(IHTMLDocument2 *doc)
1147 IHTMLElementCollection *col;
1148 IHTMLElement *elem;
1149 IDispatch *disp;
1150 HRESULT hres;
1152 static const WCHAR xW[] = {'x',0};
1153 static const WCHAR sW[] = {'s',0};
1154 static const WCHAR xxxW[] = {'x','x','x',0};
1156 static const elem_type_t all_types[] = {
1157 ET_HTML,
1158 ET_HEAD,
1159 ET_TITLE,
1160 ET_STYLE,
1161 ET_BODY,
1162 ET_A,
1163 ET_INPUT,
1164 ET_SELECT,
1165 ET_OPTION,
1166 ET_OPTION,
1167 ET_TEXTAREA,
1168 ET_TABLE,
1169 ET_TBODY
1172 static const elem_type_t item_types[] = {
1173 ET_A,
1174 ET_OPTION,
1175 ET_TEXTAREA
1178 hres = IHTMLDocument2_get_all(doc, &col);
1179 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1180 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1181 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
1182 IHTMLElementCollection_Release(col);
1184 elem = get_doc_elem(doc);
1185 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1186 hres = IHTMLElement_get_all(elem, &disp);
1187 IHTMLElement_Release(elem);
1188 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1190 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
1191 IDispatch_Release(disp);
1192 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1193 test_elem_collection(col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
1194 IHTMLElementCollection_Release(col);
1196 get_elem_by_id(doc, xxxW, FALSE);
1197 elem = get_elem_by_id(doc, sW, TRUE);
1198 if(elem) {
1199 IHTMLSelectElement *select;
1201 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
1202 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
1204 test_select_elem(select);
1206 IHTMLSelectElement_Release(select);
1207 IHTMLElement_Release(elem);
1210 test_stylesheets(doc);
1211 test_create_option_elem(doc);
1214 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
1216 IOleCommandTarget *cmdtrg;
1217 HRESULT hres;
1219 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1220 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
1222 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
1223 ok(hres == S_OK, "Exec failed: %08x\n", hres);
1225 IOleCommandTarget_Release(cmdtrg);
1228 static void test_indent(IHTMLDocument2 *doc)
1230 IHTMLElementCollection *col;
1231 IHTMLTxtRange *range;
1232 HRESULT hres;
1234 static const elem_type_t all_types[] = {
1235 ET_HTML,
1236 ET_HEAD,
1237 ET_TITLE,
1238 ET_BODY,
1239 ET_BR,
1240 ET_A,
1243 static const elem_type_t indent_types[] = {
1244 ET_HTML,
1245 ET_HEAD,
1246 ET_TITLE,
1247 ET_BODY,
1248 ET_BLOCKQUOTE,
1249 ET_P,
1250 ET_BR,
1251 ET_A,
1254 hres = IHTMLDocument2_get_all(doc, &col);
1255 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1256 test_elem_collection(col, all_types, sizeof(all_types)/sizeof(all_types[0]));
1257 IHTMLElementCollection_Release(col);
1259 range = test_create_body_range(doc);
1260 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
1261 IHTMLTxtRange_Release(range);
1263 hres = IHTMLDocument2_get_all(doc, &col);
1264 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1265 test_elem_collection(col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
1266 IHTMLElementCollection_Release(col);
1269 static IHTMLDocument2 *notif_doc;
1270 static BOOL doc_complete;
1272 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1273 REFIID riid, void**ppv)
1275 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1276 *ppv = iface;
1277 return S_OK;
1280 ok(0, "unexpected call\n");
1281 return E_NOINTERFACE;
1284 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1286 return 2;
1289 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1291 return 1;
1294 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1296 if(dispID == DISPID_READYSTATE){
1297 BSTR state;
1298 HRESULT hres;
1300 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
1302 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1303 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1305 if(!lstrcmpW(state, completeW))
1306 doc_complete = TRUE;
1308 SysFreeString(state);
1311 return S_OK;
1314 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1316 ok(0, "unexpected call\n");
1317 return E_NOTIMPL;
1320 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1321 PropertyNotifySink_QueryInterface,
1322 PropertyNotifySink_AddRef,
1323 PropertyNotifySink_Release,
1324 PropertyNotifySink_OnChanged,
1325 PropertyNotifySink_OnRequestEdit
1328 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1330 static IHTMLDocument2 *create_doc_with_string(const char *str)
1332 IPersistStreamInit *init;
1333 IStream *stream;
1334 IHTMLDocument2 *doc;
1335 HGLOBAL mem;
1336 SIZE_T len;
1338 notif_doc = doc = create_document();
1339 if(!doc)
1340 return NULL;
1342 doc_complete = FALSE;
1343 len = strlen(str);
1344 mem = GlobalAlloc(0, len);
1345 memcpy(mem, str, len);
1346 CreateStreamOnHGlobal(mem, TRUE, &stream);
1348 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1350 IPersistStreamInit_Load(init, stream);
1351 IPersistStreamInit_Release(init);
1352 IStream_Release(stream);
1354 return doc;
1357 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1359 IConnectionPointContainer *container;
1360 IConnectionPoint *cp;
1361 DWORD cookie;
1362 HRESULT hres;
1364 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1365 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1367 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1368 IConnectionPointContainer_Release(container);
1369 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1371 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1372 IConnectionPoint_Release(cp);
1373 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1376 typedef void (*domtest_t)(IHTMLDocument2*);
1378 static void run_domtest(const char *str, domtest_t test)
1380 IHTMLDocument2 *doc;
1381 IHTMLElement *body = NULL;
1382 ULONG ref;
1383 MSG msg;
1384 HRESULT hres;
1386 doc = create_doc_with_string(str);
1387 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1389 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1390 TranslateMessage(&msg);
1391 DispatchMessage(&msg);
1394 hres = IHTMLDocument2_get_body(doc, &body);
1395 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1397 if(body) {
1398 IHTMLElement_Release(body);
1399 test(doc);
1400 }else {
1401 skip("Could not get document body. Assuming no Gecko installed.\n");
1404 ref = IHTMLDocument2_Release(doc);
1405 ok(!ref, "ref = %d\n", ref);
1408 static void gecko_installer_workaround(BOOL disable)
1410 HKEY hkey;
1411 DWORD res;
1413 static BOOL has_url = FALSE;
1414 static char url[2048];
1416 if(!disable && !has_url)
1417 return;
1419 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1420 if(res != ERROR_SUCCESS)
1421 return;
1423 if(disable) {
1424 DWORD type, size = sizeof(url);
1426 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1427 if(res == ERROR_SUCCESS && type == REG_SZ)
1428 has_url = TRUE;
1430 RegDeleteValue(hkey, "GeckoUrl");
1431 }else {
1432 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1435 RegCloseKey(hkey);
1438 START_TEST(dom)
1440 gecko_installer_workaround(TRUE);
1441 CoInitialize(NULL);
1443 run_domtest(doc_str1, test_doc_elem);
1444 run_domtest(doc_str2, test_txtrange);
1445 run_domtest(elem_test_str, test_elems);
1446 run_domtest(doc_blank, test_defaults);
1447 run_domtest(indent_test_str, test_indent);
1449 CoUninitialize();
1450 gecko_installer_workaround(FALSE);