mshtml: Added IOmNavigator::get_appVersion implementation.
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob438804808fcaa3a488e22e2fa3b04e03f1b22541
1 /*
2 * Copyright 2007-2008 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 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
53 "</body></html>";
54 static const char indent_test_str[] =
55 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
57 static const WCHAR noneW[] = {'N','o','n','e',0};
59 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
60 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
61 static WCHAR wordW[] = {'w','o','r','d',0};
63 static const WCHAR text_javascriptW[] = {'t','e','x','t','/','j','a','v','a','s','c','r','i','p','t',0};
65 static const WCHAR idW[] = {'i','d',0};
67 typedef enum {
68 ET_NONE,
69 ET_HTML,
70 ET_HEAD,
71 ET_TITLE,
72 ET_BODY,
73 ET_A,
74 ET_INPUT,
75 ET_SELECT,
76 ET_TEXTAREA,
77 ET_OPTION,
78 ET_STYLE,
79 ET_BLOCKQUOTE,
80 ET_P,
81 ET_BR,
82 ET_TABLE,
83 ET_TBODY,
84 ET_SCRIPT,
85 ET_TEST,
86 ET_TESTG,
87 ET_COMMENT,
88 ET_IMG,
89 ET_TR,
90 ET_TD,
91 ET_IFRAME
92 } elem_type_t;
94 static const IID * const none_iids[] = {
95 &IID_IUnknown,
96 NULL
99 static const IID * const elem_iids[] = {
100 &IID_IHTMLDOMNode,
101 &IID_IHTMLDOMNode2,
102 &IID_IHTMLElement,
103 &IID_IHTMLElement2,
104 &IID_IHTMLElement3,
105 &IID_IDispatchEx,
106 &IID_IConnectionPointContainer,
107 NULL
110 static const IID * const body_iids[] = {
111 &IID_IHTMLDOMNode,
112 &IID_IHTMLDOMNode2,
113 &IID_IHTMLElement,
114 &IID_IHTMLElement2,
115 &IID_IHTMLElement3,
116 &IID_IHTMLTextContainer,
117 &IID_IHTMLBodyElement,
118 &IID_IDispatchEx,
119 &IID_IConnectionPointContainer,
120 NULL
123 static const IID * const anchor_iids[] = {
124 &IID_IHTMLDOMNode,
125 &IID_IHTMLDOMNode2,
126 &IID_IHTMLElement,
127 &IID_IHTMLElement2,
128 &IID_IHTMLElement3,
129 &IID_IHTMLAnchorElement,
130 &IID_IDispatchEx,
131 &IID_IConnectionPointContainer,
132 NULL
135 static const IID * const input_iids[] = {
136 &IID_IHTMLDOMNode,
137 &IID_IHTMLDOMNode2,
138 &IID_IHTMLElement,
139 &IID_IHTMLElement2,
140 &IID_IHTMLElement3,
141 &IID_IHTMLInputElement,
142 &IID_IHTMLInputTextElement,
143 &IID_IDispatchEx,
144 &IID_IConnectionPointContainer,
145 NULL
148 static const IID * const select_iids[] = {
149 &IID_IHTMLDOMNode,
150 &IID_IHTMLDOMNode2,
151 &IID_IHTMLElement,
152 &IID_IHTMLElement2,
153 &IID_IHTMLElement3,
154 &IID_IHTMLSelectElement,
155 &IID_IDispatchEx,
156 &IID_IConnectionPointContainer,
157 NULL
160 static const IID * const textarea_iids[] = {
161 &IID_IHTMLDOMNode,
162 &IID_IHTMLDOMNode2,
163 &IID_IHTMLElement,
164 &IID_IHTMLElement2,
165 &IID_IHTMLElement3,
166 &IID_IHTMLTextAreaElement,
167 &IID_IDispatchEx,
168 &IID_IConnectionPointContainer,
169 NULL
172 static const IID * const option_iids[] = {
173 &IID_IHTMLDOMNode,
174 &IID_IHTMLDOMNode2,
175 &IID_IHTMLElement,
176 &IID_IHTMLElement2,
177 &IID_IHTMLElement3,
178 &IID_IHTMLOptionElement,
179 &IID_IDispatchEx,
180 &IID_IConnectionPointContainer,
181 NULL
184 static const IID * const table_iids[] = {
185 &IID_IHTMLDOMNode,
186 &IID_IHTMLDOMNode2,
187 &IID_IHTMLElement,
188 &IID_IHTMLElement2,
189 &IID_IHTMLElement3,
190 &IID_IHTMLTable,
191 &IID_IDispatchEx,
192 &IID_IConnectionPointContainer,
193 NULL
196 static const IID * const script_iids[] = {
197 &IID_IHTMLDOMNode,
198 &IID_IHTMLDOMNode2,
199 &IID_IHTMLElement,
200 &IID_IHTMLElement2,
201 &IID_IHTMLElement3,
202 &IID_IHTMLScriptElement,
203 &IID_IDispatchEx,
204 &IID_IConnectionPointContainer,
205 NULL
208 static const IID * const text_iids[] = {
209 &IID_IHTMLDOMNode,
210 &IID_IHTMLDOMNode2,
211 &IID_IHTMLDOMTextNode,
212 NULL
215 static const IID * const location_iids[] = {
216 &IID_IDispatch,
217 &IID_IHTMLLocation,
218 NULL
221 static const IID * const window_iids[] = {
222 &IID_IDispatch,
223 &IID_IHTMLWindow2,
224 &IID_IHTMLWindow3,
225 &IID_IDispatchEx,
226 NULL
229 static const IID * const comment_iids[] = {
230 &IID_IHTMLDOMNode,
231 &IID_IHTMLDOMNode2,
232 &IID_IHTMLElement,
233 &IID_IHTMLElement2,
234 &IID_IHTMLElement3,
235 &IID_IHTMLCommentElement,
236 &IID_IDispatchEx,
237 &IID_IConnectionPointContainer,
238 NULL
241 static const IID * const img_iids[] = {
242 &IID_IHTMLDOMNode,
243 &IID_IHTMLDOMNode2,
244 &IID_IHTMLElement,
245 &IID_IHTMLElement2,
246 &IID_IHTMLElement3,
247 &IID_IDispatchEx,
248 &IID_IHTMLImgElement,
249 &IID_IConnectionPointContainer,
250 NULL
253 static const IID * const tr_iids[] = {
254 &IID_IHTMLDOMNode,
255 &IID_IHTMLDOMNode2,
256 &IID_IHTMLElement,
257 &IID_IHTMLElement2,
258 &IID_IHTMLElement3,
259 &IID_IDispatchEx,
260 &IID_IHTMLTableRow,
261 &IID_IConnectionPointContainer,
262 NULL
265 static const IID * const td_iids[] = {
266 &IID_IHTMLDOMNode,
267 &IID_IHTMLDOMNode2,
268 &IID_IHTMLElement,
269 &IID_IHTMLElement2,
270 &IID_IHTMLElement3,
271 &IID_IDispatchEx,
272 &IID_IConnectionPointContainer,
273 NULL
276 static const IID * const iframe_iids[] = {
277 &IID_IHTMLDOMNode,
278 &IID_IHTMLDOMNode2,
279 &IID_IHTMLElement,
280 &IID_IHTMLElement2,
281 &IID_IHTMLElement3,
282 &IID_IHTMLFrameBase2,
283 &IID_IDispatchEx,
284 &IID_IConnectionPointContainer,
285 NULL
288 static const IID * const generic_iids[] = {
289 &IID_IHTMLDOMNode,
290 &IID_IHTMLDOMNode2,
291 &IID_IHTMLElement,
292 &IID_IHTMLElement2,
293 &IID_IHTMLElement3,
294 &IID_IHTMLGenericElement,
295 &IID_IDispatchEx,
296 &IID_IConnectionPointContainer,
297 NULL
300 static const IID * const style_iids[] = {
301 &IID_IUnknown,
302 &IID_IDispatch,
303 &IID_IDispatchEx,
304 &IID_IHTMLStyle,
305 &IID_IHTMLStyle2,
306 NULL
309 static const IID * const cstyle_iids[] = {
310 &IID_IUnknown,
311 &IID_IDispatch,
312 &IID_IDispatchEx,
313 &IID_IHTMLCurrentStyle,
314 NULL
317 typedef struct {
318 const char *tag;
319 REFIID *iids;
320 const IID *dispiid;
321 } elem_type_info_t;
323 static const elem_type_info_t elem_type_infos[] = {
324 {"", none_iids, NULL},
325 {"HTML", elem_iids, NULL},
326 {"HEAD", elem_iids, NULL},
327 {"TITLE", elem_iids, NULL},
328 {"BODY", body_iids, &DIID_DispHTMLBody},
329 {"A", anchor_iids, NULL},
330 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
331 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
332 {"TEXTAREA", textarea_iids, NULL},
333 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
334 {"STYLE", elem_iids, NULL},
335 {"BLOCKQUOTE",elem_iids, NULL},
336 {"P", elem_iids, NULL},
337 {"BR", elem_iids, NULL},
338 {"TABLE", table_iids, &DIID_DispHTMLTable},
339 {"TBODY", elem_iids, NULL},
340 {"SCRIPT", script_iids, NULL},
341 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
342 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
343 {"!", comment_iids, &DIID_DispHTMLCommentElement},
344 {"IMG", img_iids, &DIID_DispHTMLImg},
345 {"TR", tr_iids, &DIID_DispHTMLTableRow},
346 {"TD", td_iids, NULL},
347 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame}
350 static const char *dbgstr_w(LPCWSTR str)
352 static char buf[512];
353 if(!str)
354 return "(null)";
355 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
356 return buf;
359 static const char *dbgstr_guid(REFIID riid)
361 static char buf[50];
363 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
364 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
365 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
366 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
368 return buf;
371 static int strcmp_wa(LPCWSTR strw, const char *stra)
373 WCHAR buf[512];
374 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
375 return lstrcmpW(strw, buf);
378 static BSTR a2bstr(const char *str)
380 BSTR ret;
381 int len;
383 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
384 ret = SysAllocStringLen(NULL, len);
385 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
387 return ret;
390 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
392 IUnknown *unk1, *unk2;
394 if(iface1 == iface2)
395 return TRUE;
397 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
398 IUnknown_Release(unk1);
399 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
400 IUnknown_Release(unk2);
402 return unk1 == unk2;
405 static IHTMLDocument2 *create_document(void)
407 IHTMLDocument2 *doc;
408 HRESULT hres;
410 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
411 &IID_IHTMLDocument2, (void**)&doc);
412 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
414 return doc;
417 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
418 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
420 const IID * const *piid;
421 IUnknown *unk;
422 HRESULT hres;
424 for(piid = iids; *piid; piid++) {
425 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
426 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
427 if(SUCCEEDED(hres))
428 IUnknown_Release(unk);
432 #define test_disp(u,id) _test_disp(__LINE__,u,id)
433 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
435 IDispatchEx *dispex;
436 ITypeInfo *typeinfo;
437 UINT ticnt;
438 HRESULT hres;
440 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
441 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
442 if(FAILED(hres))
443 return;
445 ticnt = 0xdeadbeef;
446 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
447 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
448 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
450 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
451 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
453 if(SUCCEEDED(hres)) {
454 TYPEATTR *type_attr;
456 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
457 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
458 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
460 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
461 ITypeInfo_Release(typeinfo);
464 IDispatchEx_Release(dispex);
467 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
468 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
470 IHTMLElement *elem;
471 HRESULT hres;
473 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
474 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
475 return elem;
478 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
479 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
481 IHTMLElement2 *elem;
482 HRESULT hres;
484 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
485 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
486 return elem;
489 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
490 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
492 IHTMLElement3 *elem;
493 HRESULT hres;
495 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
496 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement3: %08x\n", hres);
497 return elem;
500 #define get_node_iface(u) _get_node_iface(__LINE__,u)
501 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
503 IHTMLDOMNode *node;
504 HRESULT hres;
506 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
507 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
508 return node;
511 #define get_img_iface(u) _get_img_iface(__LINE__,u)
512 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
514 IHTMLImgElement *img;
515 HRESULT hres;
517 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
518 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
519 return img;
522 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
523 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
525 IHTMLDOMNode *node = _get_node_iface(line, unk);
526 BSTR name;
527 HRESULT hres;
529 hres = IHTMLDOMNode_get_nodeName(node, &name);
530 IHTMLDOMNode_Release(node);
531 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
532 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
534 SysFreeString(name);
537 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
538 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
540 IHTMLElement *elem = _get_elem_iface(line, unk);
541 BSTR tag;
542 HRESULT hres;
544 hres = IHTMLElement_get_tagName(elem, &tag);
545 IHTMLElement_Release(elem);
546 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
547 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
549 SysFreeString(tag);
552 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
553 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
555 _test_elem_tag(line, unk, elem_type_infos[type].tag);
556 _test_ifaces(line, unk, elem_type_infos[type].iids);
558 if(elem_type_infos[type].dispiid)
559 _test_disp(line, unk, elem_type_infos[type].dispiid);
562 #define get_node_type(n) _get_node_type(__LINE__,n)
563 static long _get_node_type(unsigned line, IUnknown *unk)
565 IHTMLDOMNode *node = _get_node_iface(line, unk);
566 long type = -1;
567 HRESULT hres;
569 hres = IHTMLDOMNode_get_nodeType(node, &type);
570 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
572 IHTMLDOMNode_Release(node);
574 return type;
577 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
578 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
580 IHTMLDOMNode *node = _get_node_iface(line, unk);
581 IHTMLDOMChildrenCollection *col = NULL;
582 IDispatch *disp;
583 HRESULT hres;
585 hres = IHTMLDOMNode_get_childNodes(node, &disp);
586 IHTMLDOMNode_Release(node);
587 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
588 if(FAILED(hres))
589 return NULL;
591 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
592 IDispatch_Release(disp);
593 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
595 return col;
598 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
599 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
601 IHTMLDOMNode *node = NULL;
602 IDispatch *disp;
603 HRESULT hres;
605 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
606 ok(hres == S_OK, "item failed: %08x\n", hres);
608 node = _get_node_iface(line, (IUnknown*)disp);
609 IDispatch_Release(disp);
611 return node;
614 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
615 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
617 VARIANT value;
618 BSTR tmp;
619 HRESULT hres;
621 VariantInit(&value);
623 tmp = SysAllocString(name);
624 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
625 SysFreeString(tmp);
626 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
628 if(exval) {
629 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
630 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
631 }else {
632 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
635 VariantClear(&value);
638 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
639 static void _test_elem_offset(unsigned line, IUnknown *unk)
641 IHTMLElement *elem = _get_elem_iface(line, unk);
642 long l;
643 HRESULT hres;
645 hres = IHTMLElement_get_offsetTop(elem, &l);
646 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
648 hres = IHTMLElement_get_offsetHeight(elem, &l);
649 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
651 hres = IHTMLElement_get_offsetWidth(elem, &l);
652 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
654 IHTMLElement_Release(elem);
657 static void test_doc_elem(IHTMLDocument2 *doc)
659 IHTMLElement *elem;
660 IHTMLDocument3 *doc3;
661 HRESULT hres;
663 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
664 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
666 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
667 IHTMLDocument3_Release(doc3);
668 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
670 test_node_name((IUnknown*)elem, "HTML");
671 test_elem_tag((IUnknown*)elem, "HTML");
673 IHTMLElement_Release(elem);
676 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
677 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
679 IHTMLElement *elem;
680 IHTMLDocument3 *doc3;
681 HRESULT hres;
683 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
684 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
685 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
686 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
687 IHTMLDocument3_Release(doc3);
689 return elem;
692 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
693 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
695 BSTR bstr;
696 HRESULT hres;
698 hres = IHTMLOptionElement_get_text(option, &bstr);
699 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
700 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
701 SysFreeString(bstr);
704 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
705 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
707 BSTR bstr;
708 HRESULT hres;
710 bstr = a2bstr(text);
711 hres = IHTMLOptionElement_put_text(option, bstr);
712 SysFreeString(bstr);
713 ok(hres == S_OK, "put_text failed: %08x\n", hres);
715 _test_option_text(line, option, text);
718 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
719 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
721 BSTR bstr;
722 HRESULT hres;
724 hres = IHTMLOptionElement_get_value(option, &bstr);
725 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
726 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
727 SysFreeString(bstr);
730 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
731 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
733 BSTR bstr;
734 HRESULT hres;
736 bstr = a2bstr(value);
737 hres = IHTMLOptionElement_put_value(option, bstr);
738 SysFreeString(bstr);
739 ok(hres == S_OK, "put_value failed: %08x\n", hres);
741 _test_option_value(line, option, value);
744 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
745 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
746 const char *txt, const char *val)
748 IHTMLOptionElementFactory *factory;
749 IHTMLOptionElement *option;
750 IHTMLWindow2 *window;
751 VARIANT text, value, empty;
752 HRESULT hres;
754 hres = IHTMLDocument2_get_parentWindow(doc, &window);
755 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
757 hres = IHTMLWindow2_get_Option(window, &factory);
758 IHTMLWindow2_Release(window);
759 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
761 V_VT(&text) = VT_BSTR;
762 V_BSTR(&text) = a2bstr(txt);
763 V_VT(&value) = VT_BSTR;
764 V_BSTR(&value) = a2bstr(val);
765 V_VT(&empty) = VT_EMPTY;
767 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
768 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
770 IHTMLOptionElementFactory_Release(factory);
771 VariantClear(&text);
772 VariantClear(&value);
774 _test_option_text(line, option, txt);
775 _test_option_value(line, option, val);
777 return option;
780 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
781 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
783 long len = 0xdeadbeef;
784 HRESULT hres;
786 hres = IHTMLSelectElement_get_length(select, &len);
787 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
788 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
791 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
792 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
794 long idx = 0xdeadbeef;
795 HRESULT hres;
797 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
798 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
799 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
802 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
803 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
805 HRESULT hres;
807 hres = IHTMLSelectElement_put_selectedIndex(select, index);
808 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
809 _test_select_selidx(line, select, index);
812 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
813 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
815 BSTR val;
816 HRESULT hres;
818 hres = IHTMLSelectElement_get_value(select, &val);
819 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
820 if(exval)
821 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
822 else
823 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
826 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
827 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
829 BSTR bstr;
830 HRESULT hres;
832 bstr = a2bstr(val);
833 hres = IHTMLSelectElement_put_value(select, bstr);
834 SysFreeString(bstr);
835 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
838 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
839 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
841 BSTR type;
842 HRESULT hres;
844 hres = IHTMLSelectElement_get_type(select, &type);
845 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
846 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
849 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
850 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
852 BSTR text;
853 HRESULT hres;
855 hres = IHTMLTxtRange_get_text(range, &text);
856 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
858 if(extext) {
859 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
860 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
861 }else {
862 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
865 SysFreeString(text);
869 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
870 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
872 HRESULT hres;
874 hres = IHTMLTxtRange_collapse(range, b);
875 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
876 _test_range_text(line, range, NULL);
879 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
880 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
881 VARIANT_BOOL exb, const char *extext)
883 VARIANT_BOOL b = 0xe0e0;
884 HRESULT hres;
886 hres = IHTMLTxtRange_expand(range, unit, &b);
887 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
888 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
889 _test_range_text(line, range, extext);
892 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
893 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
895 long c = 0xdeadbeef;
896 HRESULT hres;
898 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
899 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
900 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
901 _test_range_text(line, range, NULL);
904 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
905 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
906 LPWSTR unit, long cnt, long excnt)
908 long c = 0xdeadbeef;
909 HRESULT hres;
911 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
912 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
913 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
916 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
917 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
919 long c = 0xdeadbeef;
920 HRESULT hres;
922 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
923 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
924 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
927 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
928 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
930 HRESULT hres;
931 BSTR bstr = a2bstr(text);
933 hres = IHTMLTxtRange_put_text(range, bstr);
934 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
935 SysFreeString(bstr);
936 _test_range_text(line, range, NULL);
939 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
940 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
942 VARIANT_BOOL b;
943 HRESULT hres;
945 b = 0xe0e0;
946 hres = IHTMLTxtRange_inRange(range1, range2, &b);
947 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
948 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
951 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
952 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
954 VARIANT_BOOL b;
955 HRESULT hres;
957 b = 0xe0e0;
958 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
959 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
960 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
962 b = 0xe0e0;
963 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
964 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
965 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
967 if(exb) {
968 test_range_inrange(range1, range2, VARIANT_TRUE);
969 test_range_inrange(range2, range1, VARIANT_TRUE);
973 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
974 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
976 IHTMLElement *elem;
977 HRESULT hres;
979 hres = IHTMLTxtRange_parentElement(range, &elem);
980 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
982 _test_elem_type(line, (IUnknown*)elem, type);
984 IHTMLElement_Release(elem);
987 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
988 static void _test_elem_collection(unsigned line, IUnknown *unk,
989 const elem_type_t *elem_types, long exlen)
991 IHTMLElementCollection *col;
992 long len;
993 DWORD i;
994 VARIANT name, index;
995 IDispatch *disp;
996 HRESULT hres;
998 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
999 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1001 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
1003 hres = IHTMLElementCollection_get_length(col, &len);
1004 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1005 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
1007 if(len > exlen)
1008 len = exlen;
1010 V_VT(&index) = VT_EMPTY;
1011 V_VT(&name) = VT_I4;
1013 for(i=0; i<len; i++) {
1014 V_I4(&name) = i;
1015 disp = (void*)0xdeadbeef;
1016 hres = IHTMLElementCollection_item(col, name, index, &disp);
1017 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1018 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1019 if(FAILED(hres) || !disp)
1020 continue;
1022 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1023 IDispatch_Release(disp);
1026 V_I4(&name) = len;
1027 disp = (void*)0xdeadbeef;
1028 hres = IHTMLElementCollection_item(col, name, index, &disp);
1029 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1030 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1032 V_I4(&name) = -1;
1033 disp = (void*)0xdeadbeef;
1034 hres = IHTMLElementCollection_item(col, name, index, &disp);
1035 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1036 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1038 IHTMLElementCollection_Release(col);
1041 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1042 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
1044 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1045 IHTMLElementCollection *col = NULL;
1046 elem_type_t *types = NULL;
1047 BSTR tmp;
1048 int i;
1049 HRESULT hres;
1051 tmp = a2bstr(elem_type_infos[type].tag);
1052 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1053 SysFreeString(tmp);
1054 IHTMLElement2_Release(elem);
1055 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1056 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1058 if(exlen) {
1059 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1060 for(i=0; i<exlen; i++)
1061 types[i] = type;
1064 _test_elem_collection(line, (IUnknown*)col, types, exlen);
1066 HeapFree(GetProcessHeap(), 0, types);
1069 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1070 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1072 BSTR text = NULL;
1073 HRESULT hres;
1075 hres = IHTMLElement_get_innerText(elem, &text);
1076 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1077 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1078 dbgstr_w(text), extext);
1079 SysFreeString(text);
1082 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1083 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1085 IHTMLDOMChildrenCollection *col;
1086 BSTR str;
1087 HRESULT hres;
1089 str = a2bstr(text);
1090 hres = IHTMLElement_put_innerText(elem, str);
1091 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1092 SysFreeString(str);
1094 _test_elem_innertext(line, elem, text);
1097 col = _get_child_nodes(line, (IUnknown*)elem);
1098 ok(col != NULL, "col == NULL\n");
1099 if(col) {
1100 long length = 0, type;
1101 IHTMLDOMNode *node;
1103 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1104 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1105 ok(length == 1, "length = %ld\n", length);
1107 node = _get_child_item(line, col, 0);
1108 ok(node != NULL, "node == NULL\n");
1109 if(node) {
1110 type = _get_node_type(line, (IUnknown*)node);
1111 ok(type == 3, "type=%ld\n", type);
1112 IHTMLDOMNode_Release(node);
1115 IHTMLDOMChildrenCollection_Release(col);
1120 #define get_first_child(n) _get_first_child(__LINE__,n)
1121 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1123 IHTMLDOMNode *node = _get_node_iface(line, unk);
1124 IHTMLDOMNode *child = NULL;
1125 HRESULT hres;
1127 hres = IHTMLDOMNode_get_firstChild(node, &child);
1128 IHTMLDOMNode_Release(node);
1129 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1131 return child;
1134 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1135 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1137 IHTMLDOMNode *node = _get_node_iface(line, unk);
1138 VARIANT_BOOL b = 0xdead;
1139 HRESULT hres;
1141 hres = IHTMLDOMNode_hasChildNodes(node, &b);
1142 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1143 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1145 IHTMLDOMNode_Release(node);
1148 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1149 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1151 IHTMLDOMNode *node = _get_node_iface(line, unk);
1152 IHTMLDOMNode *parent;
1153 HRESULT hres;
1155 hres = IHTMLDOMNode_get_parentNode(node, &parent);
1156 IHTMLDOMNode_Release(node);
1157 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1159 return parent;
1162 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1163 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1165 IHTMLElement *elem = _get_elem_iface(line, unk);
1166 IHTMLElement *parent;
1167 HRESULT hres;
1169 hres = IHTMLElement_get_parentElement(elem, &parent);
1170 IHTMLElement_Release(elem);
1171 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1173 return parent;
1176 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1177 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1179 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1180 VARIANT_BOOL disabled = 100;
1181 HRESULT hres;
1183 hres = IHTMLElement3_get_disabled(elem3, &disabled);
1184 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1185 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1186 IHTMLElement3_Release(elem3);
1189 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1190 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1192 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1193 HRESULT hres;
1195 hres = IHTMLElement3_put_disabled(elem3, b);
1196 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1198 IHTMLElement3_Release(elem3);
1199 _test_elem3_get_disabled(line, unk, b);
1202 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1203 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1205 VARIANT_BOOL disabled = 100;
1206 HRESULT hres;
1208 hres = IHTMLSelectElement_get_disabled(select, &disabled);
1209 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1210 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1212 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1215 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1216 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1218 HRESULT hres;
1220 hres = IHTMLSelectElement_put_disabled(select, b);
1221 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1223 _test_select_get_disabled(line, select, b);
1226 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1227 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1229 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1230 IHTMLTextContainer *txtcont;
1231 long l = -1, l2 = -1;
1232 HRESULT hres;
1234 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1235 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1236 IHTMLElement2_Release(elem);
1238 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1239 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1241 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1242 IHTMLTextContainer_Release(txtcont);
1243 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1244 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1246 return l;
1249 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1250 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1252 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1253 IHTMLTextContainer *txtcont;
1254 long l = -1, l2 = -1;
1255 HRESULT hres;
1257 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1258 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1259 IHTMLElement2_Release(elem);
1261 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1262 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1264 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1265 IHTMLTextContainer_Release(txtcont);
1266 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1267 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1269 return l;
1272 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1273 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1275 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1276 IHTMLTextContainer *txtcont;
1277 long l = -1, l2 = -1;
1278 HRESULT hres;
1280 hres = IHTMLElement2_get_scrollTop(elem, &l);
1281 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1282 IHTMLElement2_Release(elem);
1284 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1285 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1287 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1288 IHTMLTextContainer_Release(txtcont);
1289 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1290 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1292 return l;
1295 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1296 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1298 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1299 IHTMLTextContainer *txtcont;
1300 long l = -1, l2 = -1;
1301 HRESULT hres;
1303 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1304 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1306 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1307 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1308 IHTMLElement2_Release(elem);
1310 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1311 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1313 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1314 IHTMLTextContainer_Release(txtcont);
1315 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1316 ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1319 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1320 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1322 IHTMLImgElement *img = _get_img_iface(line, unk);
1323 BSTR src;
1324 HRESULT hres;
1326 hres = IHTMLImgElement_get_src(img, &src);
1327 IHTMLImgElement_Release(img);
1328 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1329 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", dbgstr_w(src), exsrc);
1330 SysFreeString(src);
1333 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1334 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1336 IHTMLImgElement *img = _get_img_iface(line, unk);
1337 BSTR tmp;
1338 HRESULT hres;
1340 tmp = a2bstr(src);
1341 hres = IHTMLImgElement_put_src(img, tmp);
1342 IHTMLImgElement_Release(img);
1343 SysFreeString(tmp);
1344 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1346 _test_img_src(line, unk, src);
1349 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1350 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1352 IHTMLImgElement *img = _get_img_iface(line, unk);
1353 BSTR alt;
1354 HRESULT hres;
1356 hres = IHTMLImgElement_get_alt(img, &alt);
1357 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1358 if(exalt)
1359 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1360 else
1361 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1362 SysFreeString(alt);
1365 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1366 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1368 IHTMLImgElement *img = _get_img_iface(line, unk);
1369 BSTR tmp;
1370 HRESULT hres;
1372 tmp = a2bstr(alt);
1373 hres = IHTMLImgElement_put_alt(img, tmp);
1374 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1375 SysFreeString(tmp);
1377 _test_img_alt(line, unk, alt);
1380 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1381 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1383 VARIANT_BOOL disabled = 100;
1384 HRESULT hres;
1386 hres = IHTMLInputElement_get_disabled(input, &disabled);
1387 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1388 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1390 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1393 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1394 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1396 HRESULT hres;
1398 hres = IHTMLInputElement_put_disabled(input, b);
1399 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1401 _test_input_get_disabled(line, input, b);
1404 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1405 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1407 IHTMLInputElement *input;
1408 BSTR bstr;
1409 HRESULT hres;
1411 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1412 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1413 if(FAILED(hres))
1414 return;
1416 hres = IHTMLInputElement_get_value(input, &bstr);
1417 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1418 if(exval)
1419 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1420 else
1421 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1422 SysFreeString(bstr);
1423 IHTMLInputElement_Release(input);
1426 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1427 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1429 IHTMLInputElement *input;
1430 BSTR bstr;
1431 HRESULT hres;
1433 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1434 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1435 if(FAILED(hres))
1436 return;
1438 bstr = a2bstr(val);
1439 hres = IHTMLInputElement_get_value(input, &bstr);
1440 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1441 SysFreeString(bstr);
1442 IHTMLInputElement_Release(input);
1445 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1446 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1448 IHTMLElement *elem = _get_elem_iface(line, unk);
1449 BSTR class = (void*)0xdeadbeef;
1450 HRESULT hres;
1452 hres = IHTMLElement_get_className(elem, &class);
1453 IHTMLElement_Release(elem);
1454 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1455 if(exclass)
1456 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1457 else
1458 ok_(__FILE__,line) (!class, "class != NULL\n");
1459 SysFreeString(class);
1462 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1463 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1465 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1466 short index = -3;
1467 HRESULT hres;
1469 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1470 IHTMLElement2_Release(elem2);
1471 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1472 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1475 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1476 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1478 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1479 HRESULT hres;
1481 hres = IHTMLElement2_put_tabIndex(elem2, index);
1482 IHTMLElement2_Release(elem2);
1483 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1485 _test_elem_tabindex(line, unk, index);
1488 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1489 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1491 IHTMLElement *elem = _get_elem_iface(line, unk);
1492 BSTR tmp;
1493 HRESULT hres;
1495 tmp = class ? a2bstr(class) : NULL;
1496 hres = IHTMLElement_put_className(elem, tmp);
1497 IHTMLElement_Release(elem);
1498 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1499 SysFreeString(tmp);
1501 _test_elem_class(line, unk, class);
1504 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1505 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1507 IHTMLElement *elem = _get_elem_iface(line, unk);
1508 BSTR id = (void*)0xdeadbeef;
1509 HRESULT hres;
1511 hres = IHTMLElement_get_id(elem, &id);
1512 IHTMLElement_Release(elem);
1513 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1515 if(exid)
1516 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1517 else
1518 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1520 SysFreeString(id);
1523 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1524 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1526 IHTMLElement *elem = _get_elem_iface(line, unk);
1527 BSTR tmp = a2bstr(new_id);
1528 HRESULT hres;
1530 hres = IHTMLElement_put_id(elem, tmp);
1531 IHTMLElement_Release(elem);
1532 SysFreeString(tmp);
1533 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1535 _test_elem_id(line, unk, new_id);
1538 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1539 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1541 IHTMLElement *elem = _get_elem_iface(line, unk);
1542 BSTR title;
1543 HRESULT hres;
1545 hres = IHTMLElement_get_title(elem, &title);
1546 IHTMLElement_Release(elem);
1547 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1548 if(extitle)
1549 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1550 else
1551 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1553 SysFreeString(title);
1556 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1557 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1559 IHTMLElement *elem = _get_elem_iface(line, unk);
1560 BSTR tmp;
1561 HRESULT hres;
1563 tmp = a2bstr(title);
1564 hres = IHTMLElement_put_title(elem, tmp);
1565 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1567 IHTMLElement_Release(elem);
1568 SysFreeString(tmp);
1571 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1572 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1574 IHTMLDOMNode *node = _get_node_iface(line, unk);
1575 VARIANT var;
1576 HRESULT hres;
1578 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1579 IHTMLDOMNode_Release(node);
1580 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1582 if(exval) {
1583 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1584 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1585 }else {
1586 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1589 VariantClear(&var);
1592 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1593 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1595 IHTMLDOMNode *node = _get_node_iface(line, unk);
1596 VARIANT var;
1597 HRESULT hres;
1599 V_VT(&var) = VT_BSTR;
1600 V_BSTR(&var) = a2bstr(val);
1602 hres = IHTMLDOMNode_put_nodeValue(node, var);
1603 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1604 IHTMLDOMNode_Release(node);
1605 VariantClear(&var);
1608 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1609 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1611 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1612 long l;
1613 HRESULT hres;
1615 hres = IHTMLElement2_get_clientWidth(elem, &l);
1616 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1617 hres = IHTMLElement2_get_clientHeight(elem, &l);
1618 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1620 IHTMLElement2_Release(elem);
1623 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1624 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1626 IHTMLElement *elem = NULL;
1627 BSTR tmp;
1628 HRESULT hres;
1630 tmp = a2bstr(tag);
1631 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1632 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1633 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1635 return elem;
1638 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1639 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1641 IHTMLDocument3 *doc3;
1642 IHTMLDOMNode *node = NULL;
1643 BSTR tmp;
1644 HRESULT hres;
1646 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1647 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1649 tmp = a2bstr(text);
1650 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1651 IHTMLDocument3_Release(doc3);
1652 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1653 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1655 return node;
1658 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1659 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1661 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1662 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1663 IHTMLDOMNode *new_child = NULL;
1664 HRESULT hres;
1666 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1667 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1668 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1669 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1671 IHTMLDOMNode_Release(node);
1672 IHTMLDOMNode_Release(child);
1674 return new_child;
1677 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
1678 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
1680 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1681 IHTMLDOMNode *new_child = NULL;
1682 HRESULT hres;
1684 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
1685 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
1686 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1687 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1689 IHTMLDOMNode_Release(node);
1691 return new_child;
1694 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1695 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1697 IHTMLDOMNode *node = _get_node_iface(line, unk);
1698 IHTMLDOMNode *new_node = NULL;
1699 HRESULT hres;
1701 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1702 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
1703 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1704 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1706 IHTMLDOMNode_Release(node);
1707 IHTMLDOMNode_Release(new_node);
1710 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1711 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1713 BSTR title = NULL;
1714 HRESULT hres;
1716 hres = IHTMLDocument2_get_title(doc, &title);
1717 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1718 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1719 SysFreeString(title);
1722 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1723 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1725 BSTR tmp;
1726 HRESULT hres;
1728 tmp = a2bstr(title);
1729 hres = IHTMLDocument2_put_title(doc, tmp);
1730 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1731 SysFreeString(tmp);
1734 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1735 const elem_type_t *elem_types, long len)
1737 IDispatch *disp;
1738 VARIANT name, index;
1739 DWORD i;
1740 HRESULT hres;
1742 V_VT(&index) = VT_EMPTY;
1743 V_VT(&name) = VT_BSTR;
1744 V_BSTR(&name) = SysAllocString(n);
1746 hres = IHTMLElementCollection_item(col, name, index, &disp);
1747 ok(hres == S_OK, "item failed: %08x\n", hres);
1749 test_elem_collection((IUnknown*)disp, elem_types, len);
1750 IDispatch_Release(disp);
1751 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1752 if(hres != S_OK)
1753 goto cleanup;
1755 V_VT(&index) = VT_I4;
1757 for(i=0; i<len; i++) {
1758 V_I4(&index) = i;
1759 disp = (void*)0xdeadbeef;
1760 hres = IHTMLElementCollection_item(col, name, index, &disp);
1761 ok(hres == S_OK, "item failed: %08x\n", hres);
1762 ok(disp != NULL, "disp == NULL\n");
1763 if(FAILED(hres) || !disp)
1764 continue;
1766 test_elem_type((IUnknown*)disp, elem_types[i]);
1768 IDispatch_Release(disp);
1771 V_I4(&index) = len;
1772 disp = (void*)0xdeadbeef;
1773 hres = IHTMLElementCollection_item(col, name, index, &disp);
1774 ok(hres == S_OK, "item failed: %08x\n", hres);
1775 ok(disp == NULL, "disp != NULL\n");
1777 V_I4(&index) = -1;
1778 disp = (void*)0xdeadbeef;
1779 hres = IHTMLElementCollection_item(col, name, index, &disp);
1780 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1781 ok(disp == NULL, "disp != NULL\n");
1783 cleanup:
1784 SysFreeString(V_BSTR(&name));
1787 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1789 IHTMLElementCollection *col;
1790 IHTMLElement *elem;
1791 IDispatch *disp = (void*)0xdeadbeef;
1792 VARIANT name, index;
1793 HRESULT hres;
1795 hres = IHTMLDocument2_get_all(doc, &col);
1796 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1797 ok(col != NULL, "col == NULL\n");
1798 if(FAILED(hres) || !col)
1799 return NULL;
1801 V_VT(&index) = VT_EMPTY;
1802 V_VT(&name) = VT_BSTR;
1803 V_BSTR(&name) = SysAllocString(id);
1805 hres = IHTMLElementCollection_item(col, name, index, &disp);
1806 IHTMLElementCollection_Release(col);
1807 SysFreeString(V_BSTR(&name));
1808 ok(hres == S_OK, "item failed: %08x\n", hres);
1809 if(!expect_success) {
1810 ok(disp == NULL, "disp != NULL\n");
1811 return NULL;
1814 ok(disp != NULL, "disp == NULL\n");
1815 if(!disp)
1816 return NULL;
1818 elem = get_elem_iface((IUnknown*)disp);
1819 IDispatch_Release(disp);
1821 return elem;
1824 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1826 IHTMLDocument3 *doc3;
1827 IHTMLElement *elem;
1828 BSTR tmp;
1829 HRESULT hres;
1831 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1832 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1834 tmp = SysAllocString(id);
1835 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1836 SysFreeString(tmp);
1837 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1839 IHTMLDocument3_Release(doc3);
1841 return elem;
1844 static void test_select_elem(IHTMLSelectElement *select)
1846 test_select_type(select, "select-one");
1847 test_select_length(select, 2);
1848 test_select_selidx(select, 0);
1849 test_select_put_selidx(select, 1);
1851 test_select_set_value(select, "val1");
1852 test_select_value(select, "val1");
1854 test_select_get_disabled(select, VARIANT_FALSE);
1855 test_select_set_disabled(select, VARIANT_TRUE);
1856 test_select_set_disabled(select, VARIANT_FALSE);
1859 static void test_create_option_elem(IHTMLDocument2 *doc)
1861 IHTMLOptionElement *option;
1863 option = create_option_elem(doc, "test text", "test value");
1865 test_option_put_text(option, "new text");
1866 test_option_put_value(option, "new value");
1868 IHTMLOptionElement_Release(option);
1871 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1873 IHTMLBodyElement *body;
1874 IHTMLTxtRange *range;
1875 IHTMLElement *elem;
1876 HRESULT hres;
1878 hres = IHTMLDocument2_get_body(doc, &elem);
1879 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1881 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1882 IHTMLElement_Release(elem);
1884 hres = IHTMLBodyElement_createTextRange(body, &range);
1885 IHTMLBodyElement_Release(body);
1886 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1888 return range;
1891 static void test_txtrange(IHTMLDocument2 *doc)
1893 IHTMLTxtRange *body_range, *range, *range2;
1894 IHTMLSelectionObject *selection;
1895 IDispatch *disp_range;
1896 HRESULT hres;
1898 body_range = test_create_body_range(doc);
1900 test_range_text(body_range, "test abc 123\r\nit's text");
1902 hres = IHTMLTxtRange_duplicate(body_range, &range);
1903 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1905 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1906 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1907 test_range_isequal(range, range2, VARIANT_TRUE);
1909 test_range_text(range, "test abc 123\r\nit's text");
1910 test_range_text(body_range, "test abc 123\r\nit's text");
1912 test_range_collapse(range, TRUE);
1913 test_range_isequal(range, range2, VARIANT_FALSE);
1914 test_range_inrange(range, range2, VARIANT_FALSE);
1915 test_range_inrange(range2, range, VARIANT_TRUE);
1916 IHTMLTxtRange_Release(range2);
1918 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1919 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1920 test_range_move(range, characterW, 2, 2);
1921 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1923 test_range_collapse(range, FALSE);
1924 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1926 test_range_collapse(range, FALSE);
1927 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1928 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1929 test_range_move(range, characterW, 2, 2);
1930 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1931 test_range_moveend(range, characterW, -5, -5);
1932 test_range_text(range, NULL);
1933 test_range_moveend(range, characterW, 3, 3);
1934 test_range_text(range, "c 1");
1935 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1936 test_range_collapse(range, TRUE);
1937 test_range_move(range, characterW, 4, 4);
1938 test_range_moveend(range, characterW, 1, 1);
1939 test_range_text(range, " ");
1940 test_range_move(range, wordW, 1, 1);
1941 test_range_moveend(range, characterW, 2, 2);
1942 test_range_text(range, "ab");
1944 IHTMLTxtRange_Release(range);
1946 hres = IHTMLTxtRange_duplicate(body_range, &range);
1947 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1949 test_range_text(range, "test abc 123\r\nit's text");
1950 test_range_move(range, characterW, 3, 3);
1951 test_range_moveend(range, characterW, 1, 1);
1952 test_range_text(range, "t");
1953 test_range_moveend(range, characterW, 3, 3);
1954 test_range_text(range, "t ab");
1955 test_range_moveend(range, characterW, -2, -2);
1956 test_range_text(range, "t ");
1957 test_range_move(range, characterW, 6, 6);
1958 test_range_moveend(range, characterW, 3, 3);
1959 test_range_text(range, "123");
1960 test_range_moveend(range, characterW, 2, 2);
1961 test_range_text(range, "123\r\ni");
1963 IHTMLTxtRange_Release(range);
1965 hres = IHTMLTxtRange_duplicate(body_range, &range);
1966 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1968 test_range_move(range, wordW, 1, 1);
1969 test_range_moveend(range, characterW, 2, 2);
1970 test_range_text(range, "ab");
1972 test_range_move(range, characterW, -2, -2);
1973 test_range_moveend(range, characterW, 2, 2);
1974 test_range_text(range, "t ");
1976 test_range_move(range, wordW, 3, 3);
1977 test_range_move(range, wordW, -2, -2);
1978 test_range_moveend(range, characterW, 2, 2);
1979 test_range_text(range, "ab");
1981 test_range_move(range, characterW, -6, -5);
1982 test_range_moveend(range, characterW, -1, 0);
1983 test_range_moveend(range, characterW, -6, 0);
1984 test_range_move(range, characterW, 2, 2);
1985 test_range_moveend(range, characterW, 2, 2);
1986 test_range_text(range, "st");
1987 test_range_moveend(range, characterW, -6, -4);
1988 test_range_moveend(range, characterW, 2, 2);
1990 IHTMLTxtRange_Release(range);
1992 hres = IHTMLTxtRange_duplicate(body_range, &range);
1993 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1995 test_range_move(range, wordW, 2, 2);
1996 test_range_moveend(range, characterW, 2, 2);
1997 test_range_text(range, "12");
1999 test_range_move(range, characterW, 15, 14);
2000 test_range_move(range, characterW, -2, -2);
2001 test_range_moveend(range, characterW, 3, 2);
2002 test_range_text(range, "t");
2003 test_range_moveend(range, characterW, -1, -1);
2004 test_range_text(range, "t");
2005 test_range_expand(range, wordW, VARIANT_TRUE, "text");
2006 test_range_move(range, characterW, -2, -2);
2007 test_range_moveend(range, characterW, 2, 2);
2008 test_range_text(range, "s ");
2009 test_range_move(range, characterW, 100, 7);
2010 test_range_move(range, wordW, 1, 0);
2011 test_range_move(range, characterW, -2, -2);
2012 test_range_moveend(range, characterW, 3, 2);
2013 test_range_text(range, "t");
2015 IHTMLTxtRange_Release(range);
2017 hres = IHTMLTxtRange_duplicate(body_range, &range);
2018 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2020 test_range_collapse(range, TRUE);
2021 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2022 test_range_put_text(range, "word");
2023 test_range_text(body_range, "wordabc 123\r\nit's text");
2024 test_range_text(range, NULL);
2025 test_range_moveend(range, characterW, 3, 3);
2026 test_range_text(range, "abc");
2027 test_range_movestart(range, characterW, -2, -2);
2028 test_range_text(range, "rdabc");
2029 test_range_movestart(range, characterW, 3, 3);
2030 test_range_text(range, "bc");
2031 test_range_movestart(range, characterW, 4, 4);
2032 test_range_text(range, NULL);
2033 test_range_movestart(range, characterW, -3, -3);
2034 test_range_text(range, "c 1");
2035 test_range_movestart(range, characterW, -7, -6);
2036 test_range_text(range, "wordabc 1");
2037 test_range_movestart(range, characterW, 100, 22);
2038 test_range_text(range, NULL);
2040 IHTMLTxtRange_Release(range);
2041 IHTMLTxtRange_Release(body_range);
2043 hres = IHTMLDocument2_get_selection(doc, &selection);
2044 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
2046 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
2047 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
2048 IHTMLSelectionObject_Release(selection);
2050 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
2051 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
2052 IDispatch_Release(disp_range);
2054 test_range_text(range, NULL);
2055 test_range_moveend(range, characterW, 3, 3);
2056 test_range_text(range, "wor");
2057 test_range_parent(range, ET_BODY);
2058 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2059 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2060 test_range_move(range, characterW, 3, 3);
2061 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
2062 test_range_moveend(range, characterW, -4, -4);
2063 test_range_put_text(range, "abc def ");
2064 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
2065 test_range_move(range, wordW, 1, 1);
2066 test_range_movestart(range, characterW, -1, -1);
2067 test_range_text(range, " ");
2068 test_range_move(range, wordW, 1, 1);
2069 test_range_moveend(range, characterW, 3, 3);
2070 test_range_text(range, "def");
2071 test_range_put_text(range, "xyz");
2072 test_range_moveend(range, characterW, 1, 1);
2073 test_range_move(range, wordW, 1, 1);
2074 test_range_moveend(range, characterW, 2, 2);
2075 test_range_text(range, "ab");
2077 IHTMLTxtRange_Release(range);
2080 static void test_txtrange2(IHTMLDocument2 *doc)
2082 IHTMLTxtRange *range;
2084 range = test_create_body_range(doc);
2086 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
2087 test_range_move(range, characterW, 5, 5);
2088 test_range_moveend(range, characterW, 1, 1);
2089 test_range_text(range, "2");
2090 test_range_move(range, characterW, -3, -3);
2091 test_range_moveend(range, characterW, 3, 3);
2092 test_range_text(range, "c\r\n\r\n1");
2093 test_range_collapse(range, VARIANT_FALSE);
2094 test_range_moveend(range, characterW, 4, 4);
2095 test_range_text(range, "23");
2096 test_range_moveend(range, characterW, 1, 1);
2097 test_range_text(range, "23\r\n\r\n\r\nd");
2098 test_range_moveend(range, characterW, -1, -1);
2099 test_range_text(range, "23");
2100 test_range_moveend(range, characterW, -1, -1);
2101 test_range_text(range, "23");
2102 test_range_moveend(range, characterW, -2, -2);
2103 test_range_text(range, "2");
2105 IHTMLTxtRange_Release(range);
2108 static void test_compatmode(IHTMLDocument2 *doc)
2110 IHTMLDocument5 *doc5;
2111 BSTR mode;
2112 HRESULT hres;
2114 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2115 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2116 if(FAILED(hres))
2117 return;
2119 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2120 IHTMLDocument5_Release(doc5);
2121 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2122 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
2123 SysFreeString(mode);
2126 static void test_location(IHTMLDocument2 *doc)
2128 IHTMLLocation *location, *location2;
2129 ULONG ref;
2130 HRESULT hres;
2132 hres = IHTMLDocument2_get_location(doc, &location);
2133 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2135 hres = IHTMLDocument2_get_location(doc, &location2);
2136 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2138 ok(location == location2, "location != location2\n");
2140 test_ifaces((IUnknown*)location, location_iids);
2142 IHTMLLocation_Release(location2);
2143 ref = IHTMLLocation_Release(location);
2144 ok(!ref, "location chould be destroyed here\n");
2147 static void test_navigator(IHTMLDocument2 *doc)
2149 IHTMLWindow2 *window;
2150 IOmNavigator *navigator, *navigator2;
2151 ULONG ref;
2152 BSTR bstr;
2153 HRESULT hres;
2155 static const WCHAR v40[] = {'4','.','0'};
2157 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2158 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
2160 hres = IHTMLWindow2_get_navigator(window, &navigator);
2161 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2162 ok(navigator != NULL, "navigator == NULL\n");
2163 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
2165 hres = IHTMLWindow2_get_navigator(window, &navigator2);
2166 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2167 ok(navigator != navigator2, "navigator2 != navihgator\n");
2169 IHTMLWindow2_Release(window);
2170 IOmNavigator_Release(navigator2);
2172 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
2173 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
2174 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
2175 SysFreeString(bstr);
2177 bstr = NULL;
2178 hres = IOmNavigator_get_platform(navigator, &bstr);
2179 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
2180 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
2181 SysFreeString(bstr);
2183 bstr = NULL;
2184 hres = IOmNavigator_get_appVersion(navigator, &bstr);
2185 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
2186 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", dbgstr_w(bstr));
2187 SysFreeString(bstr);
2189 ref = IOmNavigator_Release(navigator);
2190 ok(!ref, "navigator should be destroyed here\n");
2193 static void test_current_style(IHTMLCurrentStyle *current_style)
2195 BSTR str;
2196 HRESULT hres;
2198 test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle);
2199 test_ifaces((IUnknown*)current_style, cstyle_iids);
2201 hres = IHTMLCurrentStyle_get_display(current_style, &str);
2202 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2203 ok(!strcmp_wa(str, "block"), "get_display returned %s\n", dbgstr_w(str));
2204 SysFreeString(str);
2207 static void test_style2(IHTMLStyle2 *style2)
2209 BSTR str;
2210 HRESULT hres;
2212 str = (void*)0xdeadbeef;
2213 hres = IHTMLStyle2_get_position(style2, &str);
2214 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2215 ok(!str, "str != NULL\n");
2217 str = a2bstr("absolute");
2218 hres = IHTMLStyle2_put_position(style2, str);
2219 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2220 SysFreeString(str);
2222 str = NULL;
2223 hres = IHTMLStyle2_get_position(style2, &str);
2224 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2225 ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", dbgstr_w(str));
2226 SysFreeString(str);
2229 static void test_default_style(IHTMLStyle *style)
2231 IHTMLStyle2 *style2;
2232 VARIANT_BOOL b;
2233 VARIANT v;
2234 BSTR str;
2235 HRESULT hres;
2237 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
2238 test_ifaces((IUnknown*)style, style_iids);
2240 str = (void*)0xdeadbeef;
2241 hres = IHTMLStyle_get_fontFamily(style, &str);
2242 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2243 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
2245 str = (void*)0xdeadbeef;
2246 hres = IHTMLStyle_get_fontWeight(style, &str);
2247 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2248 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
2250 str = (void*)0xdeadbeef;
2251 hres = IHTMLStyle_get_display(style, &str);
2252 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2253 ok(!str, "display = %s\n", dbgstr_w(str));
2255 str = (void*)0xdeadbeef;
2256 hres = IHTMLStyle_get_visibility(style, &str);
2257 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2258 ok(!str, "visibility = %s\n", dbgstr_w(str));
2260 V_VT(&v) = VT_NULL;
2261 hres = IHTMLStyle_get_fontSize(style, &v);
2262 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2263 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2264 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
2266 V_VT(&v) = VT_NULL;
2267 hres = IHTMLStyle_get_color(style, &v);
2268 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2269 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2270 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2272 b = 0xfefe;
2273 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2274 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2275 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2277 b = 0xfefe;
2278 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2279 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2280 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2282 V_VT(&v) = VT_EMPTY;
2283 hres = IHTMLStyle_get_width(style, &v);
2284 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2285 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2286 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2288 V_VT(&v) = VT_BSTR;
2289 V_BSTR(&v) = a2bstr("auto");
2290 hres = IHTMLStyle_put_width(style, v);
2291 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2292 VariantClear(&v);
2294 V_VT(&v) = VT_EMPTY;
2295 hres = IHTMLStyle_get_width(style, &v);
2296 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2297 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2298 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2299 VariantClear(&v);
2301 /* margin tests */
2302 str = (void*)0xdeadbeef;
2303 hres = IHTMLStyle_get_margin(style, &str);
2304 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2305 ok(!str, "margin = %s\n", dbgstr_w(str));
2307 str = a2bstr("1");
2308 hres = IHTMLStyle_put_margin(style, str);
2309 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2310 SysFreeString(str);
2312 hres = IHTMLStyle_get_margin(style, &str);
2313 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2314 ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2316 hres = IHTMLStyle_put_margin(style, NULL);
2317 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2319 str = NULL;
2320 hres = IHTMLStyle_get_border(style, &str);
2321 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2322 ok(!str || !*str, "str is not empty\n");
2323 SysFreeString(str);
2325 str = a2bstr("1px");
2326 hres = IHTMLStyle_put_border(style, str);
2327 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2328 SysFreeString(str);
2330 V_VT(&v) = VT_EMPTY;
2331 hres = IHTMLStyle_get_left(style, &v);
2332 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2333 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2334 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2335 VariantClear(&v);
2337 V_VT(&v) = VT_BSTR;
2338 V_BSTR(&v) = a2bstr("3px");
2339 hres = IHTMLStyle_put_left(style, v);
2340 ok(hres == S_OK, "put_left failed: %08x\n", hres);
2341 VariantClear(&v);
2343 V_VT(&v) = VT_EMPTY;
2344 hres = IHTMLStyle_get_left(style, &v);
2345 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2346 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2347 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2348 VariantClear(&v);
2350 V_VT(&v) = VT_NULL;
2351 hres = IHTMLStyle_put_left(style, v);
2352 ok(hres == S_OK, "put_left failed: %08x\n", hres);
2354 V_VT(&v) = VT_EMPTY;
2355 hres = IHTMLStyle_get_left(style, &v);
2356 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2357 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2358 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2359 VariantClear(&v);
2361 V_VT(&v) = VT_EMPTY;
2362 hres = IHTMLStyle_get_top(style, &v);
2363 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2364 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2365 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2366 VariantClear(&v);
2368 V_VT(&v) = VT_BSTR;
2369 V_BSTR(&v) = a2bstr("3px");
2370 hres = IHTMLStyle_put_top(style, v);
2371 ok(hres == S_OK, "put_top failed: %08x\n", hres);
2372 VariantClear(&v);
2374 V_VT(&v) = VT_EMPTY;
2375 hres = IHTMLStyle_get_top(style, &v);
2376 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2377 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2378 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2379 VariantClear(&v);
2381 V_VT(&v) = VT_NULL;
2382 hres = IHTMLStyle_put_top(style, v);
2383 ok(hres == S_OK, "put_top failed: %08x\n", hres);
2385 V_VT(&v) = VT_EMPTY;
2386 hres = IHTMLStyle_get_top(style, &v);
2387 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2388 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2389 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2390 VariantClear(&v);
2392 V_VT(&v) = VT_EMPTY;
2393 hres = IHTMLStyle_get_height(style, &v);
2394 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2395 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2396 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2397 VariantClear(&v);
2399 V_VT(&v) = VT_BSTR;
2400 V_BSTR(&v) = a2bstr("64px");
2401 hres = IHTMLStyle_put_height(style, v);
2402 ok(hres == S_OK, "put_height failed: %08x\n", hres);
2403 VariantClear(&v);
2405 V_VT(&v) = VT_EMPTY;
2406 hres = IHTMLStyle_get_height(style, &v);
2407 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2408 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2409 ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2410 VariantClear(&v);
2412 str = (void*)0xdeadbeef;
2413 hres = IHTMLStyle_get_cursor(style, &str);
2414 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2415 ok(!str, "get_cursor != NULL\n");
2416 SysFreeString(str);
2418 str = a2bstr("default");
2419 hres = IHTMLStyle_put_cursor(style, str);
2420 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2421 SysFreeString(str);
2423 str = NULL;
2424 hres = IHTMLStyle_get_cursor(style, &str);
2425 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2426 ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", dbgstr_w(str));
2427 SysFreeString(str);
2429 V_VT(&v) = VT_EMPTY;
2430 hres = IHTMLStyle_get_verticalAlign(style, &v);
2431 ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
2432 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2433 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2434 VariantClear(&v);
2436 V_VT(&v) = VT_BSTR;
2437 V_BSTR(&v) = a2bstr("middle");
2438 hres = IHTMLStyle_put_verticalAlign(style, v);
2439 ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
2440 VariantClear(&v);
2442 V_VT(&v) = VT_EMPTY;
2443 hres = IHTMLStyle_get_verticalAlign(style, &v);
2444 ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2445 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2446 ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2447 VariantClear(&v);
2449 str = (void*)0xdeadbeef;
2450 hres = IHTMLStyle_get_textAlign(style, &str);
2451 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2452 ok(!str, "textAlign != NULL\n");
2454 str = a2bstr("center");
2455 hres = IHTMLStyle_put_textAlign(style, str);
2456 ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
2457 SysFreeString(str);
2459 str = NULL;
2460 hres = IHTMLStyle_get_textAlign(style, &str);
2461 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2462 ok(!strcmp_wa(str, "center"), "textAlign = %s\n", dbgstr_w(V_BSTR(&v)));
2463 SysFreeString(str);
2465 str = (void*)0xdeadbeef;
2466 hres = IHTMLStyle_get_filter(style, &str);
2467 ok(hres == S_OK, "get_filter failed: %08x\n", hres);
2468 ok(!str, "filter != NULL\n");
2470 str = a2bstr("alpha(opacity=100)");
2471 hres = IHTMLStyle_put_filter(style, str);
2472 ok(hres == S_OK, "put_filter failed: %08x\n", hres);
2473 SysFreeString(str);
2475 V_VT(&v) = VT_EMPTY;
2476 hres = IHTMLStyle_get_zIndex(style, &v);
2477 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2478 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2479 ok(!V_I4(&v), "V_I4(v) != 0\n");
2480 VariantClear(&v);
2482 V_VT(&v) = VT_BSTR;
2483 V_BSTR(&v) = a2bstr("1");
2484 hres = IHTMLStyle_put_zIndex(style, v);
2485 ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
2486 VariantClear(&v);
2488 V_VT(&v) = VT_EMPTY;
2489 hres = IHTMLStyle_get_zIndex(style, &v);
2490 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2491 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2492 ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
2493 VariantClear(&v);
2495 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
2496 ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
2497 if(SUCCEEDED(hres)) {
2498 test_style2(style2);
2499 IHTMLStyle2_Release(style2);
2503 static void test_default_selection(IHTMLDocument2 *doc)
2505 IHTMLSelectionObject *selection;
2506 IHTMLTxtRange *range;
2507 IDispatch *disp;
2508 BSTR str;
2509 HRESULT hres;
2511 hres = IHTMLDocument2_get_selection(doc, &selection);
2512 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2514 hres = IHTMLSelectionObject_get_type(selection, &str);
2515 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2516 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2517 SysFreeString(str);
2519 hres = IHTMLSelectionObject_createRange(selection, &disp);
2520 IHTMLSelectionObject_Release(selection);
2521 ok(hres == S_OK, "createRange failed: %08x\n", hres);
2523 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2524 IDispatch_Release(disp);
2525 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2527 test_range_text(range, NULL);
2528 IHTMLTxtRange_Release(range);
2531 static void test_default_body(IHTMLBodyElement *body)
2533 long l;
2534 BSTR bstr;
2535 HRESULT hres;
2536 VARIANT v;
2537 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2538 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2539 WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2541 bstr = (void*)0xdeadbeef;
2542 hres = IHTMLBodyElement_get_background(body, &bstr);
2543 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2544 ok(bstr == NULL, "bstr != NULL\n");
2546 l = elem_get_scroll_height((IUnknown*)body);
2547 ok(l != -1, "scrollHeight == -1\n");
2548 l = elem_get_scroll_width((IUnknown*)body);
2549 ok(l != -1, "scrollWidth == -1\n");
2550 l = elem_get_scroll_top((IUnknown*)body);
2551 ok(!l, "scrollTop = %ld\n", l);
2552 elem_get_scroll_left((IUnknown*)body);
2554 /* get_text tests */
2555 hres = IHTMLBodyElement_get_text(body, &v);
2556 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2557 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2558 ok(bstr == NULL, "bstr != NULL\n");
2561 /* get_text - Invalid Text */
2562 V_VT(&v) = VT_BSTR;
2563 V_BSTR(&v) = SysAllocString(sTextInvalid);
2564 hres = IHTMLBodyElement_put_text(body, v);
2565 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2567 V_VT(&v) = VT_NULL;
2568 hres = IHTMLBodyElement_get_text(body, &v);
2569 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2570 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2571 ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2572 VariantClear(&v);
2574 /* get_text - Valid Text */
2575 V_VT(&v) = VT_BSTR;
2576 V_BSTR(&v) = SysAllocString(sBodyText);
2577 hres = IHTMLBodyElement_put_text(body, v);
2578 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2580 V_VT(&v) = VT_NULL;
2581 hres = IHTMLBodyElement_get_text(body, &v);
2582 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2583 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2584 ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2585 VariantClear(&v);
2588 static void test_body_funs(IHTMLBodyElement *body)
2590 static WCHAR sRed[] = {'r','e','d',0};
2591 static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2592 VARIANT vbg;
2593 VARIANT vDefaultbg;
2594 HRESULT hres;
2596 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2597 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2598 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2600 V_VT(&vbg) = VT_BSTR;
2601 V_BSTR(&vbg) = SysAllocString(sRed);
2602 hres = IHTMLBodyElement_put_bgColor(body, vbg);
2603 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2604 VariantClear(&vbg);
2606 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2607 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2608 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2609 ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2610 VariantClear(&vbg);
2612 /* Restore Originial */
2613 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2614 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2615 VariantClear(&vDefaultbg);
2618 static void test_window(IHTMLDocument2 *doc)
2620 IHTMLWindow2 *window, *window2, *self;
2621 IHTMLDocument2 *doc2 = NULL;
2622 IDispatch *disp;
2623 HRESULT hres;
2625 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2626 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2627 test_ifaces((IUnknown*)window, window_iids);
2628 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2630 hres = IHTMLWindow2_get_document(window, &doc2);
2631 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2632 ok(doc2 != NULL, "doc2 == NULL\n");
2634 IHTMLDocument_Release(doc2);
2636 hres = IHTMLWindow2_get_window(window, &window2);
2637 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2638 ok(window2 != NULL, "window2 == NULL\n");
2640 hres = IHTMLWindow2_get_self(window, &self);
2641 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2642 ok(window2 != NULL, "self == NULL\n");
2644 ok(self == window2, "self != window2\n");
2646 IHTMLWindow2_Release(window2);
2647 IHTMLWindow2_Release(self);
2649 disp = NULL;
2650 hres = IHTMLDocument2_get_Script(doc, &disp);
2651 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2652 ok(disp == (void*)window, "disp != window\n");
2653 IDispatch_Release(disp);
2655 IHTMLWindow2_Release(window);
2658 static void test_defaults(IHTMLDocument2 *doc)
2660 IHTMLStyleSheetsCollection *stylesheetcol;
2661 IHTMLCurrentStyle *cstyle;
2662 IHTMLBodyElement *body;
2663 IHTMLElement2 *elem2;
2664 IHTMLElement *elem;
2665 IHTMLStyle *style;
2666 long l;
2667 HRESULT hres;
2669 hres = IHTMLDocument2_get_body(doc, &elem);
2670 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2672 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2673 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2674 test_default_body(body);
2675 test_body_funs(body);
2676 IHTMLBodyElement_Release(body);
2678 hres = IHTMLElement_get_style(elem, &style);
2679 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2681 test_default_style(style);
2682 test_window(doc);
2683 test_compatmode(doc);
2684 test_location(doc);
2685 test_navigator(doc);
2687 IHTMLStyle_Release(style);
2689 elem2 = get_elem2_iface((IUnknown*)elem);
2690 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
2691 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
2692 if(SUCCEEDED(hres)) {
2693 test_current_style(cstyle);
2694 IHTMLCurrentStyle_Release(cstyle);
2696 IHTMLElement2_Release(elem2);
2698 IHTMLElement_Release(elem);
2700 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2701 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2703 l = 0xdeadbeef;
2704 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2705 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2706 ok(l == 0, "length = %ld\n", l);
2708 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2710 test_default_selection(doc);
2711 test_doc_title(doc, "");
2714 static void test_tr_elem(IHTMLElement *elem)
2716 IHTMLElementCollection *col;
2717 IHTMLTableRow *row;
2718 HRESULT hres;
2720 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
2722 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
2723 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
2724 if(FAILED(hres))
2725 return;
2727 col = NULL;
2728 hres = IHTMLTableRow_get_cells(row, &col);
2729 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
2730 ok(col != NULL, "get_cells returned NULL\n");
2732 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
2733 IHTMLElementCollection_Release(col);
2735 IHTMLTable_Release(row);
2738 static void test_table_elem(IHTMLElement *elem)
2740 IHTMLElementCollection *col;
2741 IHTMLTable *table;
2742 HRESULT hres;
2744 static const elem_type_t row_types[] = {ET_TR,ET_TR};
2746 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2747 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2748 if(FAILED(hres))
2749 return;
2751 col = NULL;
2752 hres = IHTMLTable_get_rows(table, &col);
2753 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2754 ok(col != NULL, "get_ros returned NULL\n");
2756 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2757 IHTMLElementCollection_Release(col);
2759 IHTMLTable_Release(table);
2762 static void doc_write(IHTMLDocument2 *doc, const char *text)
2764 SAFEARRAYBOUND dim;
2765 SAFEARRAY *sa;
2766 VARIANT *var;
2767 BSTR str;
2768 HRESULT hres;
2770 dim.lLbound = 0;
2771 dim.cElements = 1;
2772 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
2773 SafeArrayAccessData(sa, (void**)&var);
2774 V_VT(var) = VT_BSTR;
2775 V_BSTR(var) = str = a2bstr(text);
2776 SafeArrayUnaccessData(sa);
2778 hres = IHTMLDocument2_write(doc, sa);
2779 ok(hres == S_OK, "write failed: %08x\n", hres);
2781 SysFreeString(str);
2782 SafeArrayDestroy(sa);
2785 static void test_iframe_elem(IHTMLElement *elem)
2787 IHTMLElementCollection *col;
2788 IHTMLDocument2 *content_doc;
2789 IHTMLWindow2 *content_window;
2790 IHTMLFrameBase2 *base2;
2791 IDispatch *disp;
2792 VARIANT errv;
2793 BSTR str;
2794 HRESULT hres;
2796 static const elem_type_t all_types[] = {
2797 ET_HTML,
2798 ET_HEAD,
2799 ET_TITLE,
2800 ET_BODY,
2801 ET_BR
2804 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
2805 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
2807 content_window = NULL;
2808 hres = IHTMLFrameBase2_get_contentWindow(base2, &content_window);
2809 IHTMLFrameBase2_Release(base2);
2810 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
2811 ok(content_window != NULL, "contentWindow = NULL\n");
2813 content_doc = NULL;
2814 hres = IHTMLWindow2_get_document(content_window, &content_doc);
2815 IHTMLWindow2_Release(content_window);
2816 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2817 ok(content_doc != NULL, "content_doc = NULL\n");
2819 str = a2bstr("text/html");
2820 V_VT(&errv) = VT_ERROR;
2821 disp = NULL;
2822 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
2823 SysFreeString(str);
2824 ok(hres == S_OK, "open failed: %08x\n", hres);
2825 ok(disp != NULL, "disp == NULL\n");
2826 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
2827 IDispatch_Release(disp);
2829 doc_write(content_doc, "<html><head><title>test</title></head><body><br /></body></html>");
2831 hres = IHTMLDocument2_get_all(content_doc, &col);
2832 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2833 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2834 IHTMLElementCollection_Release(col);
2836 hres = IHTMLDocument2_close(content_doc);
2837 ok(hres == S_OK, "close failed: %08x\n", hres);
2839 IHTMLDocument2_Release(content_doc);
2842 static void test_stylesheet(IDispatch *disp)
2844 IHTMLStyleSheetRulesCollection *col = NULL;
2845 IHTMLStyleSheet *stylesheet;
2846 HRESULT hres;
2848 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2849 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2851 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2852 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2853 ok(col != NULL, "col == NULL\n");
2855 IHTMLStyleSheetRulesCollection_Release(col);
2856 IHTMLStyleSheet_Release(stylesheet);
2859 static void test_stylesheets(IHTMLDocument2 *doc)
2861 IHTMLStyleSheetsCollection *col = NULL;
2862 VARIANT idx, res;
2863 long len = 0;
2864 HRESULT hres;
2866 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2867 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2868 ok(col != NULL, "col == NULL\n");
2870 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2871 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2872 ok(len == 1, "len=%ld\n", len);
2874 VariantInit(&res);
2875 V_VT(&idx) = VT_I4;
2876 V_I4(&idx) = 0;
2878 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2879 ok(hres == S_OK, "item failed: %08x\n", hres);
2880 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2881 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2882 test_stylesheet(V_DISPATCH(&res));
2883 VariantClear(&res);
2885 V_VT(&res) = VT_I4;
2886 V_VT(&idx) = VT_I4;
2887 V_I4(&idx) = 1;
2889 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2890 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2891 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2892 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2893 VariantClear(&res);
2895 IHTMLStyleSheetsCollection_Release(col);
2898 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2900 IDispatchEx *dispex;
2901 IHTMLDOMNode *node;
2902 DISPPARAMS dp = {NULL, NULL, 0, 0};
2903 VARIANT var;
2904 EXCEPINFO ei;
2905 long type;
2906 DISPID id;
2907 BSTR bstr;
2908 HRESULT hres;
2910 static const WCHAR w0[] = {'0',0};
2911 static const WCHAR w100[] = {'1','0','0',0};
2913 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2914 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2916 bstr = SysAllocString(w0);
2917 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2918 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2919 SysFreeString(bstr);
2921 VariantInit(&var);
2922 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2923 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2924 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2925 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2926 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2927 type = get_node_type((IUnknown*)node);
2928 ok(type == 3, "type=%ld\n", type);
2929 IHTMLDOMNode_Release(node);
2930 VariantClear(&var);
2932 bstr = SysAllocString(w100);
2933 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2934 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2935 SysFreeString(bstr);
2937 IDispatchEx_Release(dispex);
2942 static void test_elems(IHTMLDocument2 *doc)
2944 IHTMLElementCollection *col;
2945 IHTMLDOMChildrenCollection *child_col;
2946 IHTMLElement *elem, *elem2, *elem3;
2947 IHTMLDOMNode *node, *node2;
2948 IDispatch *disp;
2949 long type;
2950 HRESULT hres;
2952 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2953 static const WCHAR inW[] = {'i','n',0};
2954 static const WCHAR xW[] = {'x',0};
2955 static const WCHAR sW[] = {'s',0};
2956 static const WCHAR scW[] = {'s','c',0};
2957 static const WCHAR xxxW[] = {'x','x','x',0};
2958 static const WCHAR tblW[] = {'t','b','l',0};
2959 static const WCHAR row2W[] = {'r','o','w','2',0};
2960 static const WCHAR ifrW[] = {'i','f','r',0};
2962 static const elem_type_t all_types[] = {
2963 ET_HTML,
2964 ET_HEAD,
2965 ET_TITLE,
2966 ET_STYLE,
2967 ET_BODY,
2968 ET_COMMENT,
2969 ET_A,
2970 ET_INPUT,
2971 ET_SELECT,
2972 ET_OPTION,
2973 ET_OPTION,
2974 ET_TEXTAREA,
2975 ET_TABLE,
2976 ET_TBODY,
2977 ET_TR,
2978 ET_TR,
2979 ET_TD,
2980 ET_TD,
2981 ET_SCRIPT,
2982 ET_TEST,
2983 ET_IMG,
2984 ET_IFRAME
2987 static const elem_type_t item_types[] = {
2988 ET_A,
2989 ET_OPTION,
2990 ET_TEXTAREA
2993 hres = IHTMLDocument2_get_all(doc, &col);
2994 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2995 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2996 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2997 IHTMLElementCollection_Release(col);
2999 elem = get_doc_elem(doc);
3000 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
3001 hres = IHTMLElement_get_all(elem, &disp);
3002 IHTMLElement_Release(elem);
3003 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3005 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
3006 IDispatch_Release(disp);
3007 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
3008 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
3009 IHTMLElementCollection_Release(col);
3011 get_elem_by_id(doc, xxxW, FALSE);
3012 elem = get_doc_elem_by_id(doc, xxxW);
3013 ok(!elem, "elem != NULL\n");
3015 elem = get_doc_elem_by_id(doc, sW);
3016 ok(elem != NULL, "elem == NULL\n");
3017 if(elem) {
3018 test_elem_type((IUnknown*)elem, ET_SELECT);
3019 test_elem_attr(elem, xxxW, NULL);
3020 test_elem_attr(elem, idW, sW);
3021 test_elem_class((IUnknown*)elem, NULL);
3022 test_elem_set_class((IUnknown*)elem, "cl");
3023 test_elem_set_class((IUnknown*)elem, NULL);
3024 test_elem_tabindex((IUnknown*)elem, 0);
3025 test_elem_set_tabindex((IUnknown*)elem, 1);
3027 node = test_node_get_parent((IUnknown*)elem);
3028 ok(node != NULL, "node == NULL\n");
3029 test_node_name((IUnknown*)node, "BODY");
3030 node2 = test_node_get_parent((IUnknown*)node);
3031 IHTMLDOMNode_Release(node);
3032 ok(node2 != NULL, "node == NULL\n");
3033 test_node_name((IUnknown*)node2, "HTML");
3034 node = test_node_get_parent((IUnknown*)node2);
3035 IHTMLDOMNode_Release(node2);
3036 ok(node != NULL, "node == NULL\n");
3037 test_node_name((IUnknown*)node, "#document");
3038 type = get_node_type((IUnknown*)node);
3039 ok(type == 9, "type=%ld, expected 9\n", type);
3040 node2 = test_node_get_parent((IUnknown*)node);
3041 IHTMLDOMNode_Release(node);
3042 ok(node2 == NULL, "node != NULL\n");
3044 elem2 = test_elem_get_parent((IUnknown*)elem);
3045 ok(elem2 != NULL, "elem2 == NULL\n");
3046 test_node_name((IUnknown*)elem2, "BODY");
3047 elem3 = test_elem_get_parent((IUnknown*)elem2);
3048 IHTMLElement_Release(elem2);
3049 ok(elem3 != NULL, "elem3 == NULL\n");
3050 test_node_name((IUnknown*)elem3, "HTML");
3051 elem2 = test_elem_get_parent((IUnknown*)elem3);
3052 IHTMLElement_Release(elem3);
3053 ok(elem2 == NULL, "elem2 != NULL\n");
3055 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
3056 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
3057 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
3059 test_elem_innertext(elem, "opt1opt2");
3061 IHTMLElement_Release(elem);
3064 elem = get_elem_by_id(doc, sW, TRUE);
3065 if(elem) {
3066 IHTMLSelectElement *select;
3068 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
3069 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
3071 test_select_elem(select);
3073 test_elem_title((IUnknown*)select, NULL);
3074 test_elem_set_title((IUnknown*)select, "Title");
3075 test_elem_title((IUnknown*)select, "Title");
3076 test_elem_offset((IUnknown*)select);
3078 node = get_first_child((IUnknown*)select);
3079 ok(node != NULL, "node == NULL\n");
3080 if(node) {
3081 test_elem_type((IUnknown*)node, ET_OPTION);
3082 IHTMLDOMNode_Release(node);
3085 type = get_node_type((IUnknown*)select);
3086 ok(type == 1, "type=%ld\n", type);
3088 IHTMLSelectElement_Release(select);
3089 IHTMLElement_Release(elem);
3092 elem = get_elem_by_id(doc, scW, TRUE);
3093 if(elem) {
3094 IHTMLScriptElement *script;
3095 BSTR type;
3097 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
3098 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
3100 hres = IHTMLScriptElement_get_type(script, &type);
3101 ok(hres == S_OK, "get_type failed: %08x\n", hres);
3102 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
3103 SysFreeString(type);
3105 IHTMLScriptElement_Release(script);
3108 elem = get_elem_by_id(doc, inW, TRUE);
3109 if(elem) {
3110 IHTMLInputElement *input;
3112 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
3113 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3115 test_elem_id((IUnknown*)elem, "in");
3116 test_elem_put_id((IUnknown*)elem, "newin");
3117 test_input_get_disabled(input, VARIANT_FALSE);
3118 test_input_set_disabled(input, VARIANT_TRUE);
3119 test_input_set_disabled(input, VARIANT_FALSE);
3120 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
3121 test_input_get_disabled(input, VARIANT_TRUE);
3122 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
3123 test_input_get_disabled(input, VARIANT_FALSE);
3124 test_elem_client_size((IUnknown*)elem);
3126 test_node_get_value_str((IUnknown*)elem, NULL);
3127 test_node_put_value_str((IUnknown*)elem, "test");
3128 test_node_get_value_str((IUnknown*)elem, NULL);
3129 test_input_value((IUnknown*)elem, NULL);
3130 test_input_put_value((IUnknown*)elem, "test");
3131 test_input_value((IUnknown*)elem, NULL);
3132 test_elem_class((IUnknown*)elem, "testclass");
3133 test_elem_tabindex((IUnknown*)elem, 2);
3134 test_elem_set_tabindex((IUnknown*)elem, 3);
3135 test_elem_title((IUnknown*)elem, "test title");
3137 IHTMLInputElement_Release(input);
3138 IHTMLElement_Release(elem);
3141 elem = get_elem_by_id(doc, imgidW, TRUE);
3142 if(elem) {
3143 test_img_src((IUnknown*)elem, "");
3144 test_img_set_src((IUnknown*)elem, "about:blank");
3145 test_img_alt((IUnknown*)elem, NULL);
3146 test_img_set_alt((IUnknown*)elem, "alt test");
3147 IHTMLElement_Release(elem);
3150 elem = get_doc_elem_by_id(doc, tblW);
3151 ok(elem != NULL, "elem == NULL\n");
3152 if(elem) {
3153 test_table_elem(elem);
3154 IHTMLElement_Release(elem);
3157 elem = get_doc_elem_by_id(doc, row2W);
3158 ok(elem != NULL, "elem == NULL\n");
3159 if(elem) {
3160 test_tr_elem(elem);
3161 IHTMLElement_Release(elem);
3164 elem = get_doc_elem_by_id(doc, ifrW);
3165 ok(elem != NULL, "elem == NULL\n");
3166 if(elem) {
3167 test_iframe_elem(elem);
3168 IHTMLElement_Release(elem);
3171 hres = IHTMLDocument2_get_body(doc, &elem);
3172 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3174 node = get_first_child((IUnknown*)elem);
3175 ok(node != NULL, "node == NULL\n");
3176 if(node) {
3177 test_ifaces((IUnknown*)node, text_iids);
3178 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
3180 node2 = get_first_child((IUnknown*)node);
3181 ok(!node2, "node2 != NULL\n");
3183 type = get_node_type((IUnknown*)node);
3184 ok(type == 3, "type=%ld\n", type);
3186 test_node_get_value_str((IUnknown*)node, "text test");
3187 test_node_put_value_str((IUnknown*)elem, "test text");
3188 test_node_get_value_str((IUnknown*)node, "text test");
3190 IHTMLDOMNode_Release(node);
3193 child_col = get_child_nodes((IUnknown*)elem);
3194 ok(child_col != NULL, "child_coll == NULL\n");
3195 if(child_col) {
3196 long length = 0;
3198 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
3200 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
3201 ok(hres == S_OK, "get_length failed: %08x\n", hres);
3202 ok(length, "length=0\n");
3204 node = get_child_item(child_col, 0);
3205 ok(node != NULL, "node == NULL\n");
3206 if(node) {
3207 type = get_node_type((IUnknown*)node);
3208 ok(type == 3, "type=%ld\n", type);
3209 IHTMLDOMNode_Release(node);
3212 node = get_child_item(child_col, 1);
3213 ok(node != NULL, "node == NULL\n");
3214 if(node) {
3215 type = get_node_type((IUnknown*)node);
3216 ok(type == 8, "type=%ld\n", type);
3218 test_elem_id((IUnknown*)node, NULL);
3219 IHTMLDOMNode_Release(node);
3222 disp = (void*)0xdeadbeef;
3223 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
3224 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3225 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3227 disp = (void*)0xdeadbeef;
3228 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
3229 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3230 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3232 test_child_col_disp(child_col);
3234 IHTMLDOMChildrenCollection_Release(child_col);
3237 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
3238 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
3239 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
3241 IHTMLElement_Release(elem);
3243 test_stylesheets(doc);
3244 test_create_option_elem(doc);
3246 elem = get_doc_elem_by_id(doc, tblW);
3247 ok(elem != NULL, "elem = NULL\n");
3248 test_elem_set_innertext(elem, "inner text");
3249 IHTMLElement_Release(elem);
3251 test_doc_title(doc, "test");
3252 test_doc_set_title(doc, "test title");
3253 test_doc_title(doc, "test title");
3256 static void test_create_elems(IHTMLDocument2 *doc)
3258 IHTMLElement *elem, *body, *elem2;
3259 IHTMLDOMNode *node, *node2, *node3;
3260 IDispatch *disp;
3261 VARIANT var;
3262 long type;
3263 HRESULT hres;
3265 static const elem_type_t types1[] = { ET_TESTG };
3267 elem = test_create_elem(doc, "TEST");
3268 test_elem_tag((IUnknown*)elem, "TEST");
3269 type = get_node_type((IUnknown*)elem);
3270 ok(type == 1, "type=%ld\n", type);
3271 test_ifaces((IUnknown*)elem, elem_iids);
3272 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
3274 hres = IHTMLDocument2_get_body(doc, &body);
3275 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3276 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3278 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
3279 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
3280 elem2 = get_elem_iface((IUnknown*)node);
3281 IHTMLElement_Release(elem2);
3283 hres = IHTMLElement_get_all(body, &disp);
3284 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3285 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
3286 IDispatch_Release(disp);
3288 test_node_remove_child((IUnknown*)body, node);
3290 hres = IHTMLElement_get_all(body, &disp);
3291 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3292 test_elem_collection((IUnknown*)disp, NULL, 0);
3293 IDispatch_Release(disp);
3294 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3296 IHTMLElement_Release(elem);
3297 IHTMLDOMNode_Release(node);
3299 node = test_create_text(doc, "test");
3300 test_ifaces((IUnknown*)node, text_iids);
3301 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
3303 V_VT(&var) = VT_NULL;
3304 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
3305 IHTMLDOMNode_Release(node);
3307 node = test_create_text(doc, "insert ");
3309 V_VT(&var) = VT_DISPATCH;
3310 V_DISPATCH(&var) = (IDispatch*)node2;
3311 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
3312 IHTMLDOMNode_Release(node);
3313 IHTMLDOMNode_Release(node2);
3314 IHTMLDOMNode_Release(node3);
3316 test_elem_innertext(body, "insert test");
3318 IHTMLElement_Release(body);
3321 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
3323 IOleCommandTarget *cmdtrg;
3324 HRESULT hres;
3326 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3327 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
3329 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
3330 ok(hres == S_OK, "Exec failed: %08x\n", hres);
3332 IOleCommandTarget_Release(cmdtrg);
3335 static void test_indent(IHTMLDocument2 *doc)
3337 IHTMLElementCollection *col;
3338 IHTMLTxtRange *range;
3339 HRESULT hres;
3341 static const elem_type_t all_types[] = {
3342 ET_HTML,
3343 ET_HEAD,
3344 ET_TITLE,
3345 ET_BODY,
3346 ET_BR,
3347 ET_A,
3350 static const elem_type_t indent_types[] = {
3351 ET_HTML,
3352 ET_HEAD,
3353 ET_TITLE,
3354 ET_BODY,
3355 ET_BLOCKQUOTE,
3356 ET_P,
3357 ET_BR,
3358 ET_A,
3361 hres = IHTMLDocument2_get_all(doc, &col);
3362 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3363 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
3364 IHTMLElementCollection_Release(col);
3366 range = test_create_body_range(doc);
3367 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
3368 IHTMLTxtRange_Release(range);
3370 hres = IHTMLDocument2_get_all(doc, &col);
3371 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3372 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
3373 IHTMLElementCollection_Release(col);
3376 static IHTMLDocument2 *notif_doc;
3377 static BOOL doc_complete;
3379 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
3380 REFIID riid, void**ppv)
3382 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
3383 *ppv = iface;
3384 return S_OK;
3387 ok(0, "unexpected call\n");
3388 return E_NOINTERFACE;
3391 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
3393 return 2;
3396 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
3398 return 1;
3401 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
3403 if(dispID == DISPID_READYSTATE){
3404 BSTR state;
3405 HRESULT hres;
3407 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
3409 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
3410 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3412 if(!lstrcmpW(state, completeW))
3413 doc_complete = TRUE;
3415 SysFreeString(state);
3418 return S_OK;
3421 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
3423 ok(0, "unexpected call\n");
3424 return E_NOTIMPL;
3427 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
3428 PropertyNotifySink_QueryInterface,
3429 PropertyNotifySink_AddRef,
3430 PropertyNotifySink_Release,
3431 PropertyNotifySink_OnChanged,
3432 PropertyNotifySink_OnRequestEdit
3435 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
3437 static IHTMLDocument2 *create_doc_with_string(const char *str)
3439 IPersistStreamInit *init;
3440 IStream *stream;
3441 IHTMLDocument2 *doc;
3442 HGLOBAL mem;
3443 SIZE_T len;
3445 notif_doc = doc = create_document();
3446 if(!doc)
3447 return NULL;
3449 doc_complete = FALSE;
3450 len = strlen(str);
3451 mem = GlobalAlloc(0, len);
3452 memcpy(mem, str, len);
3453 CreateStreamOnHGlobal(mem, TRUE, &stream);
3455 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
3457 IPersistStreamInit_Load(init, stream);
3458 IPersistStreamInit_Release(init);
3459 IStream_Release(stream);
3461 return doc;
3464 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
3466 IConnectionPointContainer *container;
3467 IConnectionPoint *cp;
3468 DWORD cookie;
3469 HRESULT hres;
3471 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
3472 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
3474 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
3475 IConnectionPointContainer_Release(container);
3476 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
3478 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
3479 IConnectionPoint_Release(cp);
3480 ok(hres == S_OK, "Advise failed: %08x\n", hres);
3483 typedef void (*domtest_t)(IHTMLDocument2*);
3485 static void run_domtest(const char *str, domtest_t test)
3487 IHTMLDocument2 *doc;
3488 IHTMLElement *body = NULL;
3489 ULONG ref;
3490 MSG msg;
3491 HRESULT hres;
3493 doc = create_doc_with_string(str);
3494 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3496 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
3497 TranslateMessage(&msg);
3498 DispatchMessage(&msg);
3501 hres = IHTMLDocument2_get_body(doc, &body);
3502 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3504 if(body) {
3505 IHTMLElement_Release(body);
3506 test(doc);
3507 }else {
3508 skip("Could not get document body. Assuming no Gecko installed.\n");
3511 ref = IHTMLDocument2_Release(doc);
3512 ok(!ref ||
3513 ref == 1, /* Vista */
3514 "ref = %d\n", ref);
3517 static void gecko_installer_workaround(BOOL disable)
3519 HKEY hkey;
3520 DWORD res;
3522 static BOOL has_url = FALSE;
3523 static char url[2048];
3525 if(!disable && !has_url)
3526 return;
3528 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
3529 if(res != ERROR_SUCCESS)
3530 return;
3532 if(disable) {
3533 DWORD type, size = sizeof(url);
3535 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
3536 if(res == ERROR_SUCCESS && type == REG_SZ)
3537 has_url = TRUE;
3539 RegDeleteValue(hkey, "GeckoUrl");
3540 }else {
3541 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
3544 RegCloseKey(hkey);
3547 START_TEST(dom)
3549 gecko_installer_workaround(TRUE);
3550 CoInitialize(NULL);
3552 run_domtest(doc_str1, test_doc_elem);
3553 run_domtest(range_test_str, test_txtrange);
3554 run_domtest(range_test2_str, test_txtrange2);
3555 run_domtest(elem_test_str, test_elems);
3556 run_domtest(doc_blank, test_create_elems);
3557 run_domtest(doc_blank, test_defaults);
3558 run_domtest(indent_test_str, test_indent);
3560 CoUninitialize();
3561 gecko_installer_workaround(FALSE);