push 5bdbf5929ff53e78410b88336df0dc6549434b50
[wine/hacks.git] / dlls / mshtml / tests / dom.c
blobe15b6077b23f04b55ece308eea14d762070df76a
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\"></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 IHTMLDocument2 *create_document(void)
392 IHTMLDocument2 *doc;
393 HRESULT hres;
395 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
396 &IID_IHTMLDocument2, (void**)&doc);
397 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
399 return doc;
402 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
403 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
405 const IID * const *piid;
406 IUnknown *unk;
407 HRESULT hres;
409 for(piid = iids; *piid; piid++) {
410 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
411 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
412 if(SUCCEEDED(hres))
413 IUnknown_Release(unk);
417 #define test_disp(u,id) _test_disp(__LINE__,u,id)
418 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
420 IDispatchEx *dispex;
421 ITypeInfo *typeinfo;
422 UINT ticnt;
423 HRESULT hres;
425 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
426 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
427 if(FAILED(hres))
428 return;
430 ticnt = 0xdeadbeef;
431 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
432 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
433 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
435 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
436 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
438 if(SUCCEEDED(hres)) {
439 TYPEATTR *type_attr;
441 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
442 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
443 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n", dbgstr_guid(&type_attr->guid));
445 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
446 ITypeInfo_Release(typeinfo);
449 IDispatchEx_Release(dispex);
452 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
453 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
455 IHTMLElement *elem;
456 HRESULT hres;
458 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
459 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement: %08x\n", hres);
460 return elem;
463 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
464 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
466 IHTMLElement2 *elem;
467 HRESULT hres;
469 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
470 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement2: %08x\n", hres);
471 return elem;
474 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
475 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
477 IHTMLElement3 *elem;
478 HRESULT hres;
480 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
481 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLElement3: %08x\n", hres);
482 return elem;
485 #define get_node_iface(u) _get_node_iface(__LINE__,u)
486 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
488 IHTMLDOMNode *node;
489 HRESULT hres;
491 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
492 ok_(__FILE__,line) (hres == S_OK, "Coule not get IHTMLDOMNode: %08x\n", hres);
493 return node;
496 #define get_img_iface(u) _get_img_iface(__LINE__,u)
497 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
499 IHTMLImgElement *img;
500 HRESULT hres;
502 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
503 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
504 return img;
507 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
508 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
510 IHTMLDOMNode *node = _get_node_iface(line, unk);
511 BSTR name;
512 HRESULT hres;
514 hres = IHTMLDOMNode_get_nodeName(node, &name);
515 IHTMLDOMNode_Release(node);
516 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
517 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", dbgstr_w(name), exname);
519 SysFreeString(name);
522 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
523 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
525 IHTMLElement *elem = _get_elem_iface(line, unk);
526 BSTR tag;
527 HRESULT hres;
529 hres = IHTMLElement_get_tagName(elem, &tag);
530 IHTMLElement_Release(elem);
531 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
532 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", dbgstr_w(tag), extag);
534 SysFreeString(tag);
537 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
538 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
540 _test_elem_tag(line, unk, elem_type_infos[type].tag);
541 _test_ifaces(line, unk, elem_type_infos[type].iids);
543 if(elem_type_infos[type].dispiid)
544 _test_disp(line, unk, elem_type_infos[type].dispiid);
547 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
548 static void _test_elem_attr(unsigned line, IHTMLElement *elem, LPCWSTR name, LPCWSTR exval)
550 VARIANT value;
551 BSTR tmp;
552 HRESULT hres;
554 VariantInit(&value);
556 tmp = SysAllocString(name);
557 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
558 SysFreeString(tmp);
559 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
561 if(exval) {
562 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
563 ok_(__FILE__,line) (!lstrcmpW(exval, V_BSTR(&value)), "unexpected value %s\n", dbgstr_w(V_BSTR(&value)));
564 }else {
565 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
568 VariantClear(&value);
571 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
572 static void _test_elem_offset(unsigned line, IUnknown *unk)
574 IHTMLElement *elem = _get_elem_iface(line, unk);
575 long l;
576 HRESULT hres;
578 hres = IHTMLElement_get_offsetTop(elem, &l);
579 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
581 hres = IHTMLElement_get_offsetHeight(elem, &l);
582 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
584 hres = IHTMLElement_get_offsetWidth(elem, &l);
585 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
587 IHTMLElement_Release(elem);
590 static void test_doc_elem(IHTMLDocument2 *doc)
592 IHTMLElement *elem;
593 IHTMLDocument3 *doc3;
594 HRESULT hres;
596 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
597 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
599 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
600 IHTMLDocument3_Release(doc3);
601 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
603 test_node_name((IUnknown*)elem, "HTML");
604 test_elem_tag((IUnknown*)elem, "HTML");
606 IHTMLElement_Release(elem);
609 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
610 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
612 IHTMLElement *elem;
613 IHTMLDocument3 *doc3;
614 HRESULT hres;
616 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
617 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
618 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
619 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
620 IHTMLDocument3_Release(doc3);
622 return elem;
625 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
626 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
628 BSTR bstr;
629 HRESULT hres;
631 hres = IHTMLOptionElement_get_text(option, &bstr);
632 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
633 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", dbgstr_w(bstr));
634 SysFreeString(bstr);
637 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
638 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
640 BSTR bstr;
641 HRESULT hres;
643 bstr = a2bstr(text);
644 hres = IHTMLOptionElement_put_text(option, bstr);
645 SysFreeString(bstr);
646 ok(hres == S_OK, "put_text failed: %08x\n", hres);
648 _test_option_text(line, option, text);
651 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
652 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
654 BSTR bstr;
655 HRESULT hres;
657 hres = IHTMLOptionElement_get_value(option, &bstr);
658 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
659 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", dbgstr_w(bstr));
660 SysFreeString(bstr);
663 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
664 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
666 BSTR bstr;
667 HRESULT hres;
669 bstr = a2bstr(value);
670 hres = IHTMLOptionElement_put_value(option, bstr);
671 SysFreeString(bstr);
672 ok(hres == S_OK, "put_value failed: %08x\n", hres);
674 _test_option_value(line, option, value);
677 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
678 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
679 const char *txt, const char *val)
681 IHTMLOptionElementFactory *factory;
682 IHTMLOptionElement *option;
683 IHTMLWindow2 *window;
684 VARIANT text, value, empty;
685 HRESULT hres;
687 hres = IHTMLDocument2_get_parentWindow(doc, &window);
688 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
690 hres = IHTMLWindow2_get_Option(window, &factory);
691 IHTMLWindow2_Release(window);
692 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
694 V_VT(&text) = VT_BSTR;
695 V_BSTR(&text) = a2bstr(txt);
696 V_VT(&value) = VT_BSTR;
697 V_BSTR(&value) = a2bstr(val);
698 V_VT(&empty) = VT_EMPTY;
700 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
701 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
703 IHTMLOptionElementFactory_Release(factory);
704 VariantClear(&text);
705 VariantClear(&value);
707 _test_option_text(line, option, txt);
708 _test_option_value(line, option, val);
710 return option;
713 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
714 static void _test_select_length(unsigned line, IHTMLSelectElement *select, long length)
716 long len = 0xdeadbeef;
717 HRESULT hres;
719 hres = IHTMLSelectElement_get_length(select, &len);
720 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
721 ok_(__FILE__,line) (len == length, "len=%ld, expected %ld\n", len, length);
724 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
725 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, long index)
727 long idx = 0xdeadbeef;
728 HRESULT hres;
730 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
731 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
732 ok_(__FILE__,line) (idx == index, "idx=%ld, expected %ld\n", idx, index);
735 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
736 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, long index)
738 HRESULT hres;
740 hres = IHTMLSelectElement_put_selectedIndex(select, index);
741 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
742 _test_select_selidx(line, select, index);
745 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
746 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
748 BSTR val;
749 HRESULT hres;
751 hres = IHTMLSelectElement_get_value(select, &val);
752 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
753 if(exval)
754 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", dbgstr_w(val));
755 else
756 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", dbgstr_w(val));
759 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
760 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
762 BSTR bstr;
763 HRESULT hres;
765 bstr = a2bstr(val);
766 hres = IHTMLSelectElement_put_value(select, bstr);
767 SysFreeString(bstr);
768 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
771 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
772 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
774 BSTR type;
775 HRESULT hres;
777 hres = IHTMLSelectElement_get_type(select, &type);
778 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
779 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", dbgstr_w(type), extype);
782 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
783 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
785 BSTR text;
786 HRESULT hres;
788 hres = IHTMLTxtRange_get_text(range, &text);
789 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
791 if(extext) {
792 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
793 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
794 }else {
795 ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
798 SysFreeString(text);
802 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
803 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
805 HRESULT hres;
807 hres = IHTMLTxtRange_collapse(range, b);
808 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
809 _test_range_text(line, range, NULL);
812 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
813 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
814 VARIANT_BOOL exb, const char *extext)
816 VARIANT_BOOL b = 0xe0e0;
817 HRESULT hres;
819 hres = IHTMLTxtRange_expand(range, unit, &b);
820 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
821 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
822 _test_range_text(line, range, extext);
825 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
826 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
828 long c = 0xdeadbeef;
829 HRESULT hres;
831 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
832 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
833 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
834 _test_range_text(line, range, NULL);
837 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
838 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
839 LPWSTR unit, long cnt, long excnt)
841 long c = 0xdeadbeef;
842 HRESULT hres;
844 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
845 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
846 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
849 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
850 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
852 long c = 0xdeadbeef;
853 HRESULT hres;
855 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
856 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
857 ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
860 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
861 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
863 HRESULT hres;
864 BSTR bstr = a2bstr(text);
866 hres = IHTMLTxtRange_put_text(range, bstr);
867 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
868 SysFreeString(bstr);
869 _test_range_text(line, range, NULL);
872 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
873 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
875 VARIANT_BOOL b;
876 HRESULT hres;
878 b = 0xe0e0;
879 hres = IHTMLTxtRange_inRange(range1, range2, &b);
880 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
881 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
884 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
885 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
887 VARIANT_BOOL b;
888 HRESULT hres;
890 b = 0xe0e0;
891 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
892 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
893 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
895 b = 0xe0e0;
896 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
897 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
898 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
900 if(exb) {
901 test_range_inrange(range1, range2, VARIANT_TRUE);
902 test_range_inrange(range2, range1, VARIANT_TRUE);
906 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
907 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
909 IHTMLElement *elem;
910 HRESULT hres;
912 hres = IHTMLTxtRange_parentElement(range, &elem);
913 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
915 _test_elem_type(line, (IUnknown*)elem, type);
917 IHTMLElement_Release(elem);
920 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
921 static void _test_elem_collection(unsigned line, IUnknown *unk,
922 const elem_type_t *elem_types, long exlen)
924 IHTMLElementCollection *col;
925 long len;
926 DWORD i;
927 VARIANT name, index;
928 IDispatch *disp;
929 HRESULT hres;
931 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
932 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
934 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection);
936 hres = IHTMLElementCollection_get_length(col, &len);
937 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
938 ok_(__FILE__,line) (len == exlen, "len=%ld, expected %ld\n", len, exlen);
940 if(len > exlen)
941 len = exlen;
943 V_VT(&index) = VT_EMPTY;
944 V_VT(&name) = VT_I4;
946 for(i=0; i<len; i++) {
947 V_I4(&name) = i;
948 disp = (void*)0xdeadbeef;
949 hres = IHTMLElementCollection_item(col, name, index, &disp);
950 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
951 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
952 if(FAILED(hres) || !disp)
953 continue;
955 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
956 IDispatch_Release(disp);
959 V_I4(&name) = len;
960 disp = (void*)0xdeadbeef;
961 hres = IHTMLElementCollection_item(col, name, index, &disp);
962 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
963 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
965 V_I4(&name) = -1;
966 disp = (void*)0xdeadbeef;
967 hres = IHTMLElementCollection_item(col, name, index, &disp);
968 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
969 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
971 IHTMLElementCollection_Release(col);
974 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
975 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, long exlen)
977 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
978 IHTMLElementCollection *col = NULL;
979 elem_type_t *types = NULL;
980 BSTR tmp;
981 int i;
982 HRESULT hres;
984 tmp = a2bstr(elem_type_infos[type].tag);
985 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
986 SysFreeString(tmp);
987 IHTMLElement2_Release(elem);
988 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
989 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
991 if(exlen) {
992 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
993 for(i=0; i<exlen; i++)
994 types[i] = type;
997 _test_elem_collection(line, (IUnknown*)col, types, exlen);
999 HeapFree(GetProcessHeap(), 0, types);
1002 #define get_first_child(n) _get_first_child(__LINE__,n)
1003 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1005 IHTMLDOMNode *node = _get_node_iface(line, unk);
1006 IHTMLDOMNode *child = NULL;
1007 HRESULT hres;
1009 hres = IHTMLDOMNode_get_firstChild(node, &child);
1010 IHTMLDOMNode_Release(node);
1011 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1013 return child;
1016 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1017 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1019 IHTMLDOMNode *node = _get_node_iface(line, unk);
1020 VARIANT_BOOL b = 0xdead;
1021 HRESULT hres;
1023 hres = IHTMLDOMNode_hasChildNodes(node, &b);
1024 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1025 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1027 IHTMLDOMNode_Release(node);
1030 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1031 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1033 IHTMLDOMNode *node = _get_node_iface(line, unk);
1034 IHTMLDOMNode *parent;
1035 HRESULT hres;
1037 hres = IHTMLDOMNode_get_parentNode(node, &parent);
1038 IHTMLDOMNode_Release(node);
1039 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1041 return parent;
1044 #define get_node_type(n) _get_node_type(__LINE__,n)
1045 static long _get_node_type(unsigned line, IUnknown *unk)
1047 IHTMLDOMNode *node = _get_node_iface(line, unk);
1048 long type = -1;
1049 HRESULT hres;
1051 hres = IHTMLDOMNode_get_nodeType(node, &type);
1052 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1054 IHTMLDOMNode_Release(node);
1056 return type;
1059 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1060 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1062 IHTMLElement *elem = _get_elem_iface(line, unk);
1063 IHTMLElement *parent;
1064 HRESULT hres;
1066 hres = IHTMLElement_get_parentElement(elem, &parent);
1067 IHTMLElement_Release(elem);
1068 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1070 return parent;
1073 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1074 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1076 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1077 VARIANT_BOOL disabled = 100;
1078 HRESULT hres;
1080 hres = IHTMLElement3_get_disabled(elem3, &disabled);
1081 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1082 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1083 IHTMLElement3_Release(elem3);
1086 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1087 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1089 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1090 HRESULT hres;
1092 hres = IHTMLElement3_put_disabled(elem3, b);
1093 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1095 IHTMLElement3_Release(elem3);
1096 _test_elem3_get_disabled(line, unk, b);
1099 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1100 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1102 VARIANT_BOOL disabled = 100;
1103 HRESULT hres;
1105 hres = IHTMLSelectElement_get_disabled(select, &disabled);
1106 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1107 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1109 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1112 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1113 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1115 HRESULT hres;
1117 hres = IHTMLSelectElement_put_disabled(select, b);
1118 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1120 _test_select_get_disabled(line, select, b);
1123 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1124 static long _elem_get_scroll_height(unsigned line, IUnknown *unk)
1126 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1127 IHTMLTextContainer *txtcont;
1128 long l = -1, l2 = -1;
1129 HRESULT hres;
1131 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1132 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1133 IHTMLElement2_Release(elem);
1135 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1136 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1138 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1139 IHTMLTextContainer_Release(txtcont);
1140 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %ld\n", l2);
1141 ok_(__FILE__,line) (l == l2, "unexpected height %ld, expected %ld\n", l2, l);
1143 return l;
1146 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1147 static long _elem_get_scroll_width(unsigned line, IUnknown *unk)
1149 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1150 IHTMLTextContainer *txtcont;
1151 long l = -1, l2 = -1;
1152 HRESULT hres;
1154 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1155 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1156 IHTMLElement2_Release(elem);
1158 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1159 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1161 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1162 IHTMLTextContainer_Release(txtcont);
1163 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %ld\n", l2);
1164 ok_(__FILE__,line) (l == l2, "unexpected width %ld, expected %ld\n", l2, l);
1166 return l;
1169 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1170 static long _elem_get_scroll_top(unsigned line, IUnknown *unk)
1172 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1173 IHTMLTextContainer *txtcont;
1174 long l = -1, l2 = -1;
1175 HRESULT hres;
1177 hres = IHTMLElement2_get_scrollTop(elem, &l);
1178 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1179 IHTMLElement2_Release(elem);
1181 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1182 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1184 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1185 IHTMLTextContainer_Release(txtcont);
1186 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %ld\n", l2);
1187 ok_(__FILE__,line) (l == l2, "unexpected top %ld, expected %ld\n", l2, l);
1189 return l;
1192 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1193 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1195 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1196 IHTMLTextContainer *txtcont;
1197 long l = -1, l2 = -1;
1198 HRESULT hres;
1200 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1201 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1203 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1204 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1205 IHTMLElement2_Release(elem);
1207 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1208 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1210 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1211 IHTMLTextContainer_Release(txtcont);
1212 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %ld\n", l2);
1213 ok(l == l2, "unexpected left %ld, expected %ld\n", l2, l);
1216 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1217 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1219 IHTMLImgElement *img = _get_img_iface(line, unk);
1220 BSTR tmp;
1221 HRESULT hres;
1223 tmp = a2bstr(src);
1224 hres = IHTMLImgElement_put_src(img, tmp);
1225 IHTMLImgElement_Release(img);
1226 SysFreeString(tmp);
1227 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1230 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1231 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1233 IHTMLImgElement *img = _get_img_iface(line, unk);
1234 BSTR alt;
1235 HRESULT hres;
1237 hres = IHTMLImgElement_get_alt(img, &alt);
1238 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1239 if(exalt)
1240 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", dbgstr_w(alt));
1241 else
1242 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1243 SysFreeString(alt);
1246 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1247 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1249 IHTMLImgElement *img = _get_img_iface(line, unk);
1250 BSTR tmp;
1251 HRESULT hres;
1253 tmp = a2bstr(alt);
1254 hres = IHTMLImgElement_put_alt(img, tmp);
1255 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1256 SysFreeString(tmp);
1258 _test_img_alt(line, unk, alt);
1261 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1262 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1264 VARIANT_BOOL disabled = 100;
1265 HRESULT hres;
1267 hres = IHTMLInputElement_get_disabled(input, &disabled);
1268 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1269 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1271 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1274 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1275 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1277 HRESULT hres;
1279 hres = IHTMLInputElement_put_disabled(input, b);
1280 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1282 _test_input_get_disabled(line, input, b);
1285 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1286 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1288 IHTMLInputElement *input;
1289 BSTR bstr;
1290 HRESULT hres;
1292 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1293 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1294 if(FAILED(hres))
1295 return;
1297 hres = IHTMLInputElement_get_value(input, &bstr);
1298 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1299 if(exval)
1300 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", dbgstr_w(bstr));
1301 else
1302 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1303 SysFreeString(bstr);
1304 IHTMLInputElement_Release(input);
1307 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1308 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1310 IHTMLInputElement *input;
1311 BSTR bstr;
1312 HRESULT hres;
1314 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1315 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1316 if(FAILED(hres))
1317 return;
1319 bstr = a2bstr(val);
1320 hres = IHTMLInputElement_get_value(input, &bstr);
1321 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1322 SysFreeString(bstr);
1323 IHTMLInputElement_Release(input);
1326 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1327 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1329 IHTMLDOMNode *node = _get_node_iface(line, unk);
1330 IHTMLDOMChildrenCollection *col = NULL;
1331 IDispatch *disp;
1332 HRESULT hres;
1334 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1335 IHTMLDOMNode_Release(node);
1336 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1337 if(FAILED(hres))
1338 return NULL;
1340 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1341 IDispatch_Release(disp);
1342 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1344 return col;
1347 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1348 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1350 IHTMLElement *elem = _get_elem_iface(line, unk);
1351 BSTR class = (void*)0xdeadbeef;
1352 HRESULT hres;
1354 hres = IHTMLElement_get_className(elem, &class);
1355 IHTMLElement_Release(elem);
1356 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1357 if(exclass)
1358 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", dbgstr_w(class));
1359 else
1360 ok_(__FILE__,line) (!class, "class != NULL\n");
1361 SysFreeString(class);
1364 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1365 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1367 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1368 short index = -3;
1369 HRESULT hres;
1371 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1372 IHTMLElement2_Release(elem2);
1373 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1374 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1377 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1378 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1380 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1381 HRESULT hres;
1383 hres = IHTMLElement2_put_tabIndex(elem2, index);
1384 IHTMLElement2_Release(elem2);
1385 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1387 _test_elem_tabindex(line, unk, index);
1390 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1391 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1393 IHTMLElement *elem = _get_elem_iface(line, unk);
1394 BSTR tmp;
1395 HRESULT hres;
1397 tmp = class ? a2bstr(class) : NULL;
1398 hres = IHTMLElement_put_className(elem, tmp);
1399 IHTMLElement_Release(elem);
1400 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1401 SysFreeString(tmp);
1403 _test_elem_class(line, unk, class);
1406 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1407 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, long idx)
1409 IHTMLDOMNode *node = NULL;
1410 IDispatch *disp;
1411 HRESULT hres;
1413 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1414 ok(hres == S_OK, "item failed: %08x\n", hres);
1416 node = _get_node_iface(line, (IUnknown*)disp);
1417 IDispatch_Release(disp);
1419 return node;
1422 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1423 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1425 IHTMLElement *elem = _get_elem_iface(line, unk);
1426 BSTR id = (void*)0xdeadbeef;
1427 HRESULT hres;
1429 hres = IHTMLElement_get_id(elem, &id);
1430 IHTMLElement_Release(elem);
1431 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1433 if(exid)
1434 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", dbgstr_w(id));
1435 else
1436 ok_(__FILE__,line) (!id, "id=%s\n", dbgstr_w(id));
1438 SysFreeString(id);
1441 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1442 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1444 IHTMLElement *elem = _get_elem_iface(line, unk);
1445 BSTR tmp = a2bstr(new_id);
1446 HRESULT hres;
1448 hres = IHTMLElement_put_id(elem, tmp);
1449 IHTMLElement_Release(elem);
1450 SysFreeString(tmp);
1451 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1453 _test_elem_id(line, unk, new_id);
1456 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1457 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1459 IHTMLElement *elem = _get_elem_iface(line, unk);
1460 BSTR title;
1461 HRESULT hres;
1463 hres = IHTMLElement_get_title(elem, &title);
1464 IHTMLElement_Release(elem);
1465 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1466 if(extitle)
1467 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1468 else
1469 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", dbgstr_w(title));
1471 SysFreeString(title);
1474 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1475 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1477 IHTMLElement *elem = _get_elem_iface(line, unk);
1478 BSTR tmp;
1479 HRESULT hres;
1481 tmp = a2bstr(title);
1482 hres = IHTMLElement_put_title(elem, tmp);
1483 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1485 IHTMLElement_Release(elem);
1486 SysFreeString(tmp);
1489 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1490 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1492 IHTMLDOMNode *node = _get_node_iface(line, unk);
1493 VARIANT var;
1494 HRESULT hres;
1496 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1497 IHTMLDOMNode_Release(node);
1498 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1500 if(exval) {
1501 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1502 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", dbgstr_w(V_BSTR(&var)));
1503 }else {
1504 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1507 VariantClear(&var);
1510 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1511 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1513 IHTMLDOMNode *node = _get_node_iface(line, unk);
1514 VARIANT var;
1515 HRESULT hres;
1517 V_VT(&var) = VT_BSTR;
1518 V_BSTR(&var) = a2bstr(val);
1520 hres = IHTMLDOMNode_put_nodeValue(node, var);
1521 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1522 IHTMLDOMNode_Release(node);
1523 VariantClear(&var);
1526 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1527 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1529 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1530 long l;
1531 HRESULT hres;
1533 hres = IHTMLElement2_get_clientWidth(elem, &l);
1534 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1535 hres = IHTMLElement2_get_clientHeight(elem, &l);
1536 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1538 IHTMLElement2_Release(elem);
1541 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1542 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1544 IHTMLElement *elem = NULL;
1545 BSTR tmp;
1546 HRESULT hres;
1548 tmp = a2bstr(tag);
1549 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1550 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1551 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1553 return elem;
1556 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1557 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1559 IHTMLDocument3 *doc3;
1560 IHTMLDOMNode *node = NULL;
1561 BSTR tmp;
1562 HRESULT hres;
1564 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1565 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1567 tmp = a2bstr(text);
1568 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1569 IHTMLDocument3_Release(doc3);
1570 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1571 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1573 return node;
1576 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1577 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1579 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1580 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1581 IHTMLDOMNode *new_child = NULL;
1582 HRESULT hres;
1584 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1585 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1586 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1587 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1589 IHTMLDOMNode_Release(node);
1590 IHTMLDOMNode_Release(child);
1592 return new_child;
1595 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1596 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1598 IHTMLDOMNode *node = _get_node_iface(line, unk);
1599 IHTMLDOMNode *new_node = NULL;
1600 HRESULT hres;
1602 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1603 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1604 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1605 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1607 IHTMLDOMNode_Release(node);
1608 IHTMLDOMNode_Release(new_node);
1611 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1612 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1614 BSTR title = NULL;
1615 HRESULT hres;
1617 hres = IHTMLDocument2_get_title(doc, &title);
1618 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1619 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", dbgstr_w(title));
1620 SysFreeString(title);
1623 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1624 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1626 BSTR tmp;
1627 HRESULT hres;
1629 tmp = a2bstr(title);
1630 hres = IHTMLDocument2_put_title(doc, tmp);
1631 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1632 SysFreeString(tmp);
1635 static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n,
1636 const elem_type_t *elem_types, long len)
1638 IDispatch *disp;
1639 VARIANT name, index;
1640 DWORD i;
1641 HRESULT hres;
1643 V_VT(&index) = VT_EMPTY;
1644 V_VT(&name) = VT_BSTR;
1645 V_BSTR(&name) = SysAllocString(n);
1647 hres = IHTMLElementCollection_item(col, name, index, &disp);
1648 ok(hres == S_OK, "item failed: %08x\n", hres);
1650 test_elem_collection((IUnknown*)disp, elem_types, len);
1651 IDispatch_Release(disp);
1652 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
1653 if(hres != S_OK)
1654 goto cleanup;
1656 V_VT(&index) = VT_I4;
1658 for(i=0; i<len; i++) {
1659 V_I4(&index) = i;
1660 disp = (void*)0xdeadbeef;
1661 hres = IHTMLElementCollection_item(col, name, index, &disp);
1662 ok(hres == S_OK, "item failed: %08x\n", hres);
1663 ok(disp != NULL, "disp == NULL\n");
1664 if(FAILED(hres) || !disp)
1665 continue;
1667 test_elem_type((IUnknown*)disp, elem_types[i]);
1669 IDispatch_Release(disp);
1672 V_I4(&index) = len;
1673 disp = (void*)0xdeadbeef;
1674 hres = IHTMLElementCollection_item(col, name, index, &disp);
1675 ok(hres == S_OK, "item failed: %08x\n", hres);
1676 ok(disp == NULL, "disp != NULL\n");
1678 V_I4(&index) = -1;
1679 disp = (void*)0xdeadbeef;
1680 hres = IHTMLElementCollection_item(col, name, index, &disp);
1681 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1682 ok(disp == NULL, "disp != NULL\n");
1684 cleanup:
1685 SysFreeString(V_BSTR(&name));
1688 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id, BOOL expect_success)
1690 IHTMLElementCollection *col;
1691 IHTMLElement *elem;
1692 IDispatch *disp = (void*)0xdeadbeef;
1693 VARIANT name, index;
1694 HRESULT hres;
1696 hres = IHTMLDocument2_get_all(doc, &col);
1697 ok(hres == S_OK, "get_all failed: %08x\n", hres);
1698 ok(col != NULL, "col == NULL\n");
1699 if(FAILED(hres) || !col)
1700 return NULL;
1702 V_VT(&index) = VT_EMPTY;
1703 V_VT(&name) = VT_BSTR;
1704 V_BSTR(&name) = SysAllocString(id);
1706 hres = IHTMLElementCollection_item(col, name, index, &disp);
1707 IHTMLElementCollection_Release(col);
1708 SysFreeString(V_BSTR(&name));
1709 ok(hres == S_OK, "item failed: %08x\n", hres);
1710 if(!expect_success) {
1711 ok(disp == NULL, "disp != NULL\n");
1712 return NULL;
1715 ok(disp != NULL, "disp == NULL\n");
1716 if(!disp)
1717 return NULL;
1719 elem = get_elem_iface((IUnknown*)disp);
1720 IDispatch_Release(disp);
1722 return elem;
1725 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, LPCWSTR id)
1727 IHTMLDocument3 *doc3;
1728 IHTMLElement *elem;
1729 BSTR tmp;
1730 HRESULT hres;
1732 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1733 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
1735 tmp = SysAllocString(id);
1736 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
1737 SysFreeString(tmp);
1738 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", dbgstr_w(id), hres);
1740 IHTMLDocument3_Release(doc3);
1742 return elem;
1745 static void test_select_elem(IHTMLSelectElement *select)
1747 test_select_type(select, "select-one");
1748 test_select_length(select, 2);
1749 test_select_selidx(select, 0);
1750 test_select_put_selidx(select, 1);
1752 test_select_set_value(select, "val1");
1753 test_select_value(select, "val1");
1755 test_select_get_disabled(select, VARIANT_FALSE);
1756 test_select_set_disabled(select, VARIANT_TRUE);
1757 test_select_set_disabled(select, VARIANT_FALSE);
1760 static void test_create_option_elem(IHTMLDocument2 *doc)
1762 IHTMLOptionElement *option;
1764 option = create_option_elem(doc, "test text", "test value");
1766 test_option_put_text(option, "new text");
1767 test_option_put_value(option, "new value");
1769 IHTMLOptionElement_Release(option);
1772 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
1774 IHTMLBodyElement *body;
1775 IHTMLTxtRange *range;
1776 IHTMLElement *elem;
1777 HRESULT hres;
1779 hres = IHTMLDocument2_get_body(doc, &elem);
1780 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1782 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
1783 IHTMLElement_Release(elem);
1785 hres = IHTMLBodyElement_createTextRange(body, &range);
1786 IHTMLBodyElement_Release(body);
1787 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
1789 return range;
1792 static void test_txtrange(IHTMLDocument2 *doc)
1794 IHTMLTxtRange *body_range, *range, *range2;
1795 IHTMLSelectionObject *selection;
1796 IDispatch *disp_range;
1797 HRESULT hres;
1799 body_range = test_create_body_range(doc);
1801 test_range_text(body_range, "test abc 123\r\nit's text");
1803 hres = IHTMLTxtRange_duplicate(body_range, &range);
1804 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1806 hres = IHTMLTxtRange_duplicate(body_range, &range2);
1807 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1808 test_range_isequal(range, range2, VARIANT_TRUE);
1810 test_range_text(range, "test abc 123\r\nit's text");
1811 test_range_text(body_range, "test abc 123\r\nit's text");
1813 test_range_collapse(range, TRUE);
1814 test_range_isequal(range, range2, VARIANT_FALSE);
1815 test_range_inrange(range, range2, VARIANT_FALSE);
1816 test_range_inrange(range2, range, VARIANT_TRUE);
1817 IHTMLTxtRange_Release(range2);
1819 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1820 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
1821 test_range_move(range, characterW, 2, 2);
1822 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1824 test_range_collapse(range, FALSE);
1825 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
1827 test_range_collapse(range, FALSE);
1828 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1829 test_range_expand(range, wordW, VARIANT_FALSE, "123");
1830 test_range_move(range, characterW, 2, 2);
1831 test_range_expand(range, wordW, VARIANT_TRUE, "123");
1832 test_range_moveend(range, characterW, -5, -5);
1833 test_range_text(range, NULL);
1834 test_range_moveend(range, characterW, 3, 3);
1835 test_range_text(range, "c 1");
1836 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
1837 test_range_collapse(range, TRUE);
1838 test_range_move(range, characterW, 4, 4);
1839 test_range_moveend(range, characterW, 1, 1);
1840 test_range_text(range, " ");
1841 test_range_move(range, wordW, 1, 1);
1842 test_range_moveend(range, characterW, 2, 2);
1843 test_range_text(range, "ab");
1845 IHTMLTxtRange_Release(range);
1847 hres = IHTMLTxtRange_duplicate(body_range, &range);
1848 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1850 test_range_text(range, "test abc 123\r\nit's text");
1851 test_range_move(range, characterW, 3, 3);
1852 test_range_moveend(range, characterW, 1, 1);
1853 test_range_text(range, "t");
1854 test_range_moveend(range, characterW, 3, 3);
1855 test_range_text(range, "t ab");
1856 test_range_moveend(range, characterW, -2, -2);
1857 test_range_text(range, "t ");
1858 test_range_move(range, characterW, 6, 6);
1859 test_range_moveend(range, characterW, 3, 3);
1860 test_range_text(range, "123");
1861 test_range_moveend(range, characterW, 2, 2);
1862 test_range_text(range, "123\r\ni");
1864 IHTMLTxtRange_Release(range);
1866 hres = IHTMLTxtRange_duplicate(body_range, &range);
1867 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1869 test_range_move(range, wordW, 1, 1);
1870 test_range_moveend(range, characterW, 2, 2);
1871 test_range_text(range, "ab");
1873 test_range_move(range, characterW, -2, -2);
1874 test_range_moveend(range, characterW, 2, 2);
1875 test_range_text(range, "t ");
1877 test_range_move(range, wordW, 3, 3);
1878 test_range_move(range, wordW, -2, -2);
1879 test_range_moveend(range, characterW, 2, 2);
1880 test_range_text(range, "ab");
1882 test_range_move(range, characterW, -6, -5);
1883 test_range_moveend(range, characterW, -1, 0);
1884 test_range_moveend(range, characterW, -6, 0);
1885 test_range_move(range, characterW, 2, 2);
1886 test_range_moveend(range, characterW, 2, 2);
1887 test_range_text(range, "st");
1888 test_range_moveend(range, characterW, -6, -4);
1889 test_range_moveend(range, characterW, 2, 2);
1891 IHTMLTxtRange_Release(range);
1893 hres = IHTMLTxtRange_duplicate(body_range, &range);
1894 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1896 test_range_move(range, wordW, 2, 2);
1897 test_range_moveend(range, characterW, 2, 2);
1898 test_range_text(range, "12");
1900 test_range_move(range, characterW, 15, 14);
1901 test_range_move(range, characterW, -2, -2);
1902 test_range_moveend(range, characterW, 3, 2);
1903 test_range_text(range, "t");
1904 test_range_moveend(range, characterW, -1, -1);
1905 test_range_text(range, "t");
1906 test_range_expand(range, wordW, VARIANT_TRUE, "text");
1907 test_range_move(range, characterW, -2, -2);
1908 test_range_moveend(range, characterW, 2, 2);
1909 test_range_text(range, "s ");
1910 test_range_move(range, characterW, 100, 7);
1911 test_range_move(range, wordW, 1, 0);
1912 test_range_move(range, characterW, -2, -2);
1913 test_range_moveend(range, characterW, 3, 2);
1914 test_range_text(range, "t");
1916 IHTMLTxtRange_Release(range);
1918 hres = IHTMLTxtRange_duplicate(body_range, &range);
1919 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
1921 test_range_collapse(range, TRUE);
1922 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
1923 test_range_put_text(range, "word");
1924 test_range_text(body_range, "wordabc 123\r\nit's text");
1925 test_range_text(range, NULL);
1926 test_range_moveend(range, characterW, 3, 3);
1927 test_range_text(range, "abc");
1928 test_range_movestart(range, characterW, -2, -2);
1929 test_range_text(range, "rdabc");
1930 test_range_movestart(range, characterW, 3, 3);
1931 test_range_text(range, "bc");
1932 test_range_movestart(range, characterW, 4, 4);
1933 test_range_text(range, NULL);
1934 test_range_movestart(range, characterW, -3, -3);
1935 test_range_text(range, "c 1");
1936 test_range_movestart(range, characterW, -7, -6);
1937 test_range_text(range, "wordabc 1");
1938 test_range_movestart(range, characterW, 100, 22);
1939 test_range_text(range, NULL);
1941 IHTMLTxtRange_Release(range);
1942 IHTMLTxtRange_Release(body_range);
1944 hres = IHTMLDocument2_get_selection(doc, &selection);
1945 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
1947 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
1948 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
1949 IHTMLSelectionObject_Release(selection);
1951 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
1952 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
1953 IDispatch_Release(disp_range);
1955 test_range_text(range, NULL);
1956 test_range_moveend(range, characterW, 3, 3);
1957 test_range_text(range, "wor");
1958 test_range_parent(range, ET_BODY);
1959 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1960 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
1961 test_range_move(range, characterW, 3, 3);
1962 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
1963 test_range_moveend(range, characterW, -4, -4);
1964 test_range_put_text(range, "abc def ");
1965 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
1966 test_range_move(range, wordW, 1, 1);
1967 test_range_movestart(range, characterW, -1, -1);
1968 test_range_text(range, " ");
1969 test_range_move(range, wordW, 1, 1);
1970 test_range_moveend(range, characterW, 3, 3);
1971 test_range_text(range, "def");
1972 test_range_put_text(range, "xyz");
1973 test_range_moveend(range, characterW, 1, 1);
1974 test_range_move(range, wordW, 1, 1);
1975 test_range_moveend(range, characterW, 2, 2);
1976 test_range_text(range, "ab");
1978 IHTMLTxtRange_Release(range);
1981 static void test_txtrange2(IHTMLDocument2 *doc)
1983 IHTMLTxtRange *range;
1985 range = test_create_body_range(doc);
1987 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
1988 test_range_move(range, characterW, 5, 5);
1989 test_range_moveend(range, characterW, 1, 1);
1990 test_range_text(range, "2");
1991 test_range_move(range, characterW, -3, -3);
1992 test_range_moveend(range, characterW, 3, 3);
1993 test_range_text(range, "c\r\n\r\n1");
1994 test_range_collapse(range, VARIANT_FALSE);
1995 test_range_moveend(range, characterW, 4, 4);
1996 test_range_text(range, "23");
1997 test_range_moveend(range, characterW, 1, 1);
1998 test_range_text(range, "23\r\n\r\n\r\nd");
1999 test_range_moveend(range, characterW, -1, -1);
2000 test_range_text(range, "23");
2001 test_range_moveend(range, characterW, -1, -1);
2002 test_range_text(range, "23");
2003 test_range_moveend(range, characterW, -2, -2);
2004 test_range_text(range, "2");
2006 IHTMLTxtRange_Release(range);
2009 static void test_compatmode(IHTMLDocument2 *doc)
2011 IHTMLDocument5 *doc5;
2012 BSTR mode;
2013 HRESULT hres;
2015 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2016 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2017 if(FAILED(hres))
2018 return;
2020 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2021 IHTMLDocument5_Release(doc5);
2022 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2023 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", dbgstr_w(mode));
2024 SysFreeString(mode);
2027 static void test_location(IHTMLDocument2 *doc)
2029 IHTMLLocation *location, *location2;
2030 ULONG ref;
2031 HRESULT hres;
2033 hres = IHTMLDocument2_get_location(doc, &location);
2034 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2036 hres = IHTMLDocument2_get_location(doc, &location2);
2037 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2039 ok(location == location2, "location != location2\n");
2041 test_ifaces((IUnknown*)location, location_iids);
2043 IHTMLLocation_Release(location2);
2044 ref = IHTMLLocation_Release(location);
2045 ok(!ref, "location chould be destroyed here\n");
2048 static void test_navigator(IHTMLDocument2 *doc)
2050 IHTMLWindow2 *window;
2051 IOmNavigator *navigator, *navigator2;
2052 ULONG ref;
2053 BSTR bstr;
2054 HRESULT hres;
2056 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2057 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
2059 hres = IHTMLWindow2_get_navigator(window, &navigator);
2060 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2061 ok(navigator != NULL, "navigator == NULL\n");
2062 test_disp((IUnknown*)navigator, &IID_IOmNavigator);
2064 hres = IHTMLWindow2_get_navigator(window, &navigator2);
2065 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2066 ok(navigator != navigator2, "navigator2 != navihgator\n");
2068 IHTMLWindow2_Release(window);
2069 IOmNavigator_Release(navigator2);
2071 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
2072 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
2073 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", dbgstr_w(bstr));
2074 SysFreeString(bstr);
2076 bstr = NULL;
2077 hres = IOmNavigator_get_platform(navigator, &bstr);
2078 ok(hres == S_OK, "get_appMinorVersion failed: %08x\n", hres);
2079 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", dbgstr_w(bstr));
2080 SysFreeString(bstr);
2082 ref = IOmNavigator_Release(navigator);
2083 ok(!ref, "navigator should be destroyed here\n");
2086 static void test_current_style(IHTMLCurrentStyle *current_style)
2088 BSTR str;
2089 HRESULT hres;
2091 test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle);
2092 test_ifaces((IUnknown*)current_style, cstyle_iids);
2094 hres = IHTMLCurrentStyle_get_display(current_style, &str);
2095 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2096 ok(!strcmp_wa(str, "block"), "get_display returned %s\n", dbgstr_w(str));
2097 SysFreeString(str);
2100 static void test_style2(IHTMLStyle2 *style2)
2102 BSTR str;
2103 HRESULT hres;
2105 str = (void*)0xdeadbeef;
2106 hres = IHTMLStyle2_get_position(style2, &str);
2107 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2108 ok(!str, "str != NULL\n");
2110 str = a2bstr("absolute");
2111 hres = IHTMLStyle2_put_position(style2, str);
2112 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2113 SysFreeString(str);
2115 str = NULL;
2116 hres = IHTMLStyle2_get_position(style2, &str);
2117 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2118 ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", dbgstr_w(str));
2119 SysFreeString(str);
2122 static void test_default_style(IHTMLStyle *style)
2124 IHTMLStyle2 *style2;
2125 VARIANT_BOOL b;
2126 VARIANT v;
2127 BSTR str;
2128 HRESULT hres;
2130 test_disp((IUnknown*)style, &DIID_DispHTMLStyle);
2131 test_ifaces((IUnknown*)style, style_iids);
2133 str = (void*)0xdeadbeef;
2134 hres = IHTMLStyle_get_fontFamily(style, &str);
2135 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2136 ok(!str, "fontFamily = %s\n", dbgstr_w(str));
2138 str = (void*)0xdeadbeef;
2139 hres = IHTMLStyle_get_fontWeight(style, &str);
2140 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2141 ok(!str, "fontWeight = %s\n", dbgstr_w(str));
2143 str = (void*)0xdeadbeef;
2144 hres = IHTMLStyle_get_display(style, &str);
2145 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2146 ok(!str, "display = %s\n", dbgstr_w(str));
2148 str = (void*)0xdeadbeef;
2149 hres = IHTMLStyle_get_visibility(style, &str);
2150 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2151 ok(!str, "visibility = %s\n", dbgstr_w(str));
2153 V_VT(&v) = VT_NULL;
2154 hres = IHTMLStyle_get_fontSize(style, &v);
2155 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2156 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2157 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
2159 V_VT(&v) = VT_NULL;
2160 hres = IHTMLStyle_get_color(style, &v);
2161 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2162 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2163 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
2165 b = 0xfefe;
2166 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2167 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2168 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2170 b = 0xfefe;
2171 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2172 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2173 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2175 V_VT(&v) = VT_EMPTY;
2176 hres = IHTMLStyle_get_width(style, &v);
2177 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2178 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2179 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
2181 V_VT(&v) = VT_BSTR;
2182 V_BSTR(&v) = a2bstr("auto");
2183 hres = IHTMLStyle_put_width(style, v);
2184 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2185 VariantClear(&v);
2187 V_VT(&v) = VT_EMPTY;
2188 hres = IHTMLStyle_get_width(style, &v);
2189 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2190 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2191 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", dbgstr_w(V_BSTR(&v)));
2192 VariantClear(&v);
2194 /* margin tests */
2195 str = (void*)0xdeadbeef;
2196 hres = IHTMLStyle_get_margin(style, &str);
2197 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2198 ok(!str, "margin = %s\n", dbgstr_w(str));
2200 str = a2bstr("1");
2201 hres = IHTMLStyle_put_margin(style, str);
2202 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2203 SysFreeString(str);
2205 hres = IHTMLStyle_get_margin(style, &str);
2206 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2207 ok(strcmp_wa(str, "1"), "margin = %s\n", dbgstr_w(str));
2209 hres = IHTMLStyle_put_margin(style, NULL);
2210 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2212 str = NULL;
2213 hres = IHTMLStyle_get_border(style, &str);
2214 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2215 ok(!str || !*str, "str is not empty\n");
2216 SysFreeString(str);
2218 str = a2bstr("1px");
2219 hres = IHTMLStyle_put_border(style, str);
2220 ok(hres == S_OK, "get_border failed: %08x\n", hres);
2221 SysFreeString(str);
2223 V_VT(&v) = VT_EMPTY;
2224 hres = IHTMLStyle_get_left(style, &v);
2225 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2226 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2227 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2228 VariantClear(&v);
2230 V_VT(&v) = VT_BSTR;
2231 V_BSTR(&v) = a2bstr("3px");
2232 hres = IHTMLStyle_put_left(style, v);
2233 ok(hres == S_OK, "put_left failed: %08x\n", hres);
2234 VariantClear(&v);
2236 V_VT(&v) = VT_EMPTY;
2237 hres = IHTMLStyle_get_left(style, &v);
2238 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2239 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2240 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2241 VariantClear(&v);
2243 V_VT(&v) = VT_EMPTY;
2244 hres = IHTMLStyle_get_top(style, &v);
2245 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2246 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2247 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2248 VariantClear(&v);
2250 V_VT(&v) = VT_BSTR;
2251 V_BSTR(&v) = a2bstr("3px");
2252 hres = IHTMLStyle_put_top(style, v);
2253 ok(hres == S_OK, "put_top failed: %08x\n", hres);
2254 VariantClear(&v);
2256 V_VT(&v) = VT_EMPTY;
2257 hres = IHTMLStyle_get_top(style, &v);
2258 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2259 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2260 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2261 VariantClear(&v);
2263 V_VT(&v) = VT_EMPTY;
2264 hres = IHTMLStyle_get_height(style, &v);
2265 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2266 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2267 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2268 VariantClear(&v);
2270 V_VT(&v) = VT_BSTR;
2271 V_BSTR(&v) = a2bstr("64px");
2272 hres = IHTMLStyle_put_height(style, v);
2273 ok(hres == S_OK, "put_height failed: %08x\n", hres);
2274 VariantClear(&v);
2276 V_VT(&v) = VT_EMPTY;
2277 hres = IHTMLStyle_get_height(style, &v);
2278 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2279 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2280 ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2281 VariantClear(&v);
2283 str = (void*)0xdeadbeef;
2284 hres = IHTMLStyle_get_cursor(style, &str);
2285 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2286 ok(!str, "get_cursor != NULL\n");
2287 SysFreeString(str);
2289 str = a2bstr("default");
2290 hres = IHTMLStyle_put_cursor(style, str);
2291 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2292 SysFreeString(str);
2294 str = NULL;
2295 hres = IHTMLStyle_get_cursor(style, &str);
2296 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2297 ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", dbgstr_w(str));
2298 SysFreeString(str);
2300 V_VT(&v) = VT_EMPTY;
2301 hres = IHTMLStyle_get_verticalAlign(style, &v);
2302 ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
2303 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2304 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
2305 VariantClear(&v);
2307 V_VT(&v) = VT_BSTR;
2308 V_BSTR(&v) = a2bstr("middle");
2309 hres = IHTMLStyle_put_verticalAlign(style, v);
2310 ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
2311 VariantClear(&v);
2313 V_VT(&v) = VT_EMPTY;
2314 hres = IHTMLStyle_get_verticalAlign(style, &v);
2315 ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2316 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
2317 ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v)));
2318 VariantClear(&v);
2320 str = (void*)0xdeadbeef;
2321 hres = IHTMLStyle_get_textAlign(style, &str);
2322 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2323 ok(!str, "textAlign != NULL\n");
2325 str = a2bstr("center");
2326 hres = IHTMLStyle_put_textAlign(style, str);
2327 ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
2328 SysFreeString(str);
2330 str = NULL;
2331 hres = IHTMLStyle_get_textAlign(style, &str);
2332 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2333 ok(!strcmp_wa(str, "center"), "textAlign = %s\n", dbgstr_w(V_BSTR(&v)));
2334 SysFreeString(str);
2336 str = (void*)0xdeadbeef;
2337 hres = IHTMLStyle_get_filter(style, &str);
2338 ok(hres == S_OK, "get_filter failed: %08x\n", hres);
2339 ok(!str, "filter != NULL\n");
2341 str = a2bstr("alpha(opacity=100)");
2342 hres = IHTMLStyle_put_filter(style, str);
2343 ok(hres == S_OK, "put_filter failed: %08x\n", hres);
2344 SysFreeString(str);
2346 V_VT(&v) = VT_EMPTY;
2347 hres = IHTMLStyle_get_zIndex(style, &v);
2348 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2349 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2350 ok(!V_I4(&v), "V_I4(v) != 0\n");
2351 VariantClear(&v);
2353 V_VT(&v) = VT_BSTR;
2354 V_BSTR(&v) = a2bstr("1");
2355 hres = IHTMLStyle_put_zIndex(style, v);
2356 ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
2357 VariantClear(&v);
2359 V_VT(&v) = VT_EMPTY;
2360 hres = IHTMLStyle_get_zIndex(style, &v);
2361 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2362 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
2363 ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
2364 VariantClear(&v);
2366 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
2367 ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
2368 if(SUCCEEDED(hres)) {
2369 test_style2(style2);
2370 IHTMLStyle2_Release(style2);
2374 static void test_default_selection(IHTMLDocument2 *doc)
2376 IHTMLSelectionObject *selection;
2377 IHTMLTxtRange *range;
2378 IDispatch *disp;
2379 BSTR str;
2380 HRESULT hres;
2382 hres = IHTMLDocument2_get_selection(doc, &selection);
2383 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
2385 hres = IHTMLSelectionObject_get_type(selection, &str);
2386 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2387 ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
2388 SysFreeString(str);
2390 hres = IHTMLSelectionObject_createRange(selection, &disp);
2391 IHTMLSelectionObject_Release(selection);
2392 ok(hres == S_OK, "createRange failed: %08x\n", hres);
2394 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
2395 IDispatch_Release(disp);
2396 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
2398 test_range_text(range, NULL);
2399 IHTMLTxtRange_Release(range);
2402 static void test_default_body(IHTMLBodyElement *body)
2404 long l;
2405 BSTR bstr;
2406 HRESULT hres;
2407 VARIANT v;
2408 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
2409 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
2410 WCHAR sResInvalid[] = {'#','0','0','a','0','d','0',0};
2412 bstr = (void*)0xdeadbeef;
2413 hres = IHTMLBodyElement_get_background(body, &bstr);
2414 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2415 ok(bstr == NULL, "bstr != NULL\n");
2417 l = elem_get_scroll_height((IUnknown*)body);
2418 ok(l != -1, "scrollHeight == -1\n");
2419 l = elem_get_scroll_width((IUnknown*)body);
2420 ok(l != -1, "scrollWidth == -1\n");
2421 l = elem_get_scroll_top((IUnknown*)body);
2422 ok(!l, "scrollTop = %ld\n", l);
2423 elem_get_scroll_left((IUnknown*)body);
2425 /* get_text tests */
2426 hres = IHTMLBodyElement_get_text(body, &v);
2427 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2428 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2429 ok(bstr == NULL, "bstr != NULL\n");
2432 /* get_text - Invalid Text */
2433 V_VT(&v) = VT_BSTR;
2434 V_BSTR(&v) = SysAllocString(sTextInvalid);
2435 hres = IHTMLBodyElement_put_text(body, v);
2436 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2438 V_VT(&v) = VT_NULL;
2439 hres = IHTMLBodyElement_get_text(body, &v);
2440 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2441 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2442 ok(!lstrcmpW(sResInvalid, V_BSTR(&v)), "bstr != sResInvalid\n");
2443 VariantClear(&v);
2445 /* get_text - Valid Text */
2446 V_VT(&v) = VT_BSTR;
2447 V_BSTR(&v) = SysAllocString(sBodyText);
2448 hres = IHTMLBodyElement_put_text(body, v);
2449 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2451 V_VT(&v) = VT_NULL;
2452 hres = IHTMLBodyElement_get_text(body, &v);
2453 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
2454 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
2455 ok(lstrcmpW(bstr, V_BSTR(&v)), "bstr != V_BSTR(&v)\n");
2456 VariantClear(&v);
2459 static void test_body_funs(IHTMLBodyElement *body)
2461 static WCHAR sRed[] = {'r','e','d',0};
2462 static WCHAR sRedbg[] = {'#','f','f','0','0','0','0',0};
2463 VARIANT vbg;
2464 VARIANT vDefaultbg;
2465 HRESULT hres;
2467 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
2468 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2469 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
2471 V_VT(&vbg) = VT_BSTR;
2472 V_BSTR(&vbg) = SysAllocString(sRed);
2473 hres = IHTMLBodyElement_put_bgColor(body, vbg);
2474 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2475 VariantClear(&vbg);
2477 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
2478 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2479 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
2480 ok(!lstrcmpW(V_BSTR(&vbg), sRedbg), "Unexpected type %s\n", dbgstr_w(V_BSTR(&vbg)));
2481 VariantClear(&vbg);
2483 /* Restore Originial */
2484 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
2485 ok(hres == S_OK, "get_background failed: %08x\n", hres);
2486 VariantClear(&vDefaultbg);
2489 static void test_window(IHTMLDocument2 *doc)
2491 IHTMLWindow2 *window, *window2, *self;
2492 IHTMLDocument2 *doc2 = NULL;
2493 IDispatch *disp;
2494 HRESULT hres;
2496 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2497 ok(hres == S_OK, "get_parentElement failed: %08x\n", hres);
2498 test_ifaces((IUnknown*)window, window_iids);
2499 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2);
2501 hres = IHTMLWindow2_get_document(window, &doc2);
2502 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2503 ok(doc2 != NULL, "doc2 == NULL\n");
2505 IHTMLDocument_Release(doc2);
2507 hres = IHTMLWindow2_get_window(window, &window2);
2508 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2509 ok(window2 != NULL, "window2 == NULL\n");
2511 hres = IHTMLWindow2_get_self(window, &self);
2512 ok(hres == S_OK, "get_window failed: %08x\n", hres);
2513 ok(window2 != NULL, "self == NULL\n");
2515 ok(self == window2, "self != window2\n");
2517 IHTMLWindow2_Release(window2);
2518 IHTMLWindow2_Release(self);
2520 disp = NULL;
2521 hres = IHTMLDocument2_get_Script(doc, &disp);
2522 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
2523 ok(disp == (void*)window, "disp != window\n");
2524 IDispatch_Release(disp);
2526 IHTMLWindow2_Release(window);
2529 static void test_defaults(IHTMLDocument2 *doc)
2531 IHTMLStyleSheetsCollection *stylesheetcol;
2532 IHTMLCurrentStyle *cstyle;
2533 IHTMLBodyElement *body;
2534 IHTMLElement2 *elem2;
2535 IHTMLElement *elem;
2536 IHTMLStyle *style;
2537 long l;
2538 HRESULT hres;
2540 hres = IHTMLDocument2_get_body(doc, &elem);
2541 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2543 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2544 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
2545 test_default_body(body);
2546 test_body_funs(body);
2547 IHTMLBodyElement_Release(body);
2549 hres = IHTMLElement_get_style(elem, &style);
2550 ok(hres == S_OK, "get_style failed: %08x\n", hres);
2552 test_default_style(style);
2553 test_window(doc);
2554 test_compatmode(doc);
2555 test_location(doc);
2556 test_navigator(doc);
2558 IHTMLStyle_Release(style);
2560 elem2 = get_elem2_iface((IUnknown*)elem);
2561 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
2562 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
2563 if(SUCCEEDED(hres)) {
2564 test_current_style(cstyle);
2565 IHTMLCurrentStyle_Release(cstyle);
2567 IHTMLElement2_Release(elem2);
2569 IHTMLElement_Release(elem);
2571 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
2572 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2574 l = 0xdeadbeef;
2575 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
2576 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2577 ok(l == 0, "length = %ld\n", l);
2579 IHTMLStyleSheetsCollection_Release(stylesheetcol);
2581 test_default_selection(doc);
2582 test_doc_title(doc, "");
2585 static void test_tr_elem(IHTMLElement *elem)
2587 IHTMLElementCollection *col;
2588 IHTMLTableRow *row;
2589 HRESULT hres;
2591 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
2593 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
2594 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
2595 if(FAILED(hres))
2596 return;
2598 col = NULL;
2599 hres = IHTMLTableRow_get_cells(row, &col);
2600 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
2601 ok(col != NULL, "get_cells returned NULL\n");
2603 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
2604 IHTMLElementCollection_Release(col);
2606 IHTMLTable_Release(row);
2609 static void test_table_elem(IHTMLElement *elem)
2611 IHTMLElementCollection *col;
2612 IHTMLTable *table;
2613 HRESULT hres;
2615 static const elem_type_t row_types[] = {ET_TR,ET_TR};
2617 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
2618 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
2619 if(FAILED(hres))
2620 return;
2622 col = NULL;
2623 hres = IHTMLTable_get_rows(table, &col);
2624 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
2625 ok(col != NULL, "get_ros returned NULL\n");
2627 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
2628 IHTMLElementCollection_Release(col);
2630 IHTMLTable_Release(table);
2633 static void test_stylesheet(IDispatch *disp)
2635 IHTMLStyleSheetRulesCollection *col = NULL;
2636 IHTMLStyleSheet *stylesheet;
2637 HRESULT hres;
2639 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
2640 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
2642 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
2643 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
2644 ok(col != NULL, "col == NULL\n");
2646 IHTMLStyleSheetRulesCollection_Release(col);
2647 IHTMLStyleSheet_Release(stylesheet);
2650 static void test_stylesheets(IHTMLDocument2 *doc)
2652 IHTMLStyleSheetsCollection *col = NULL;
2653 VARIANT idx, res;
2654 long len = 0;
2655 HRESULT hres;
2657 hres = IHTMLDocument2_get_styleSheets(doc, &col);
2658 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
2659 ok(col != NULL, "col == NULL\n");
2661 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
2662 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2663 ok(len == 1, "len=%ld\n", len);
2665 VariantInit(&res);
2666 V_VT(&idx) = VT_I4;
2667 V_I4(&idx) = 0;
2669 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2670 ok(hres == S_OK, "item failed: %08x\n", hres);
2671 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
2672 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2673 test_stylesheet(V_DISPATCH(&res));
2674 VariantClear(&res);
2676 V_VT(&res) = VT_I4;
2677 V_VT(&idx) = VT_I4;
2678 V_I4(&idx) = 1;
2680 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
2681 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2682 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
2683 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
2684 VariantClear(&res);
2686 IHTMLStyleSheetsCollection_Release(col);
2689 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
2691 IDispatchEx *dispex;
2692 IHTMLDOMNode *node;
2693 DISPPARAMS dp = {NULL, NULL, 0, 0};
2694 VARIANT var;
2695 EXCEPINFO ei;
2696 long type;
2697 DISPID id;
2698 BSTR bstr;
2699 HRESULT hres;
2701 static const WCHAR w0[] = {'0',0};
2702 static const WCHAR w100[] = {'1','0','0',0};
2704 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
2705 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
2707 bstr = SysAllocString(w0);
2708 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2709 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2710 SysFreeString(bstr);
2712 VariantInit(&var);
2713 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2714 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2715 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2716 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2717 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
2718 type = get_node_type((IUnknown*)node);
2719 ok(type == 3, "type=%ld\n", type);
2720 IHTMLDOMNode_Release(node);
2721 VariantClear(&var);
2723 bstr = SysAllocString(w100);
2724 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2725 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2726 SysFreeString(bstr);
2728 IDispatchEx_Release(dispex);
2733 static void test_elems(IHTMLDocument2 *doc)
2735 IHTMLElementCollection *col;
2736 IHTMLDOMChildrenCollection *child_col;
2737 IHTMLElement *elem, *elem2, *elem3;
2738 IHTMLDOMNode *node, *node2;
2739 IDispatch *disp;
2740 long type;
2741 HRESULT hres;
2743 static const WCHAR imgidW[] = {'i','m','g','i','d',0};
2744 static const WCHAR inW[] = {'i','n',0};
2745 static const WCHAR xW[] = {'x',0};
2746 static const WCHAR sW[] = {'s',0};
2747 static const WCHAR scW[] = {'s','c',0};
2748 static const WCHAR xxxW[] = {'x','x','x',0};
2749 static const WCHAR tblW[] = {'t','b','l',0};
2750 static const WCHAR row2W[] = {'r','o','w','2',0};
2752 static const elem_type_t all_types[] = {
2753 ET_HTML,
2754 ET_HEAD,
2755 ET_TITLE,
2756 ET_STYLE,
2757 ET_BODY,
2758 ET_COMMENT,
2759 ET_A,
2760 ET_INPUT,
2761 ET_SELECT,
2762 ET_OPTION,
2763 ET_OPTION,
2764 ET_TEXTAREA,
2765 ET_TABLE,
2766 ET_TBODY,
2767 ET_TR,
2768 ET_TR,
2769 ET_TD,
2770 ET_TD,
2771 ET_SCRIPT,
2772 ET_TEST,
2773 ET_IMG,
2774 ET_IFRAME
2777 static const elem_type_t item_types[] = {
2778 ET_A,
2779 ET_OPTION,
2780 ET_TEXTAREA
2783 hres = IHTMLDocument2_get_all(doc, &col);
2784 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2785 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
2786 test_elem_col_item(col, xW, item_types, sizeof(item_types)/sizeof(item_types[0]));
2787 IHTMLElementCollection_Release(col);
2789 elem = get_doc_elem(doc);
2790 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
2791 hres = IHTMLElement_get_all(elem, &disp);
2792 IHTMLElement_Release(elem);
2793 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2795 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
2796 IDispatch_Release(disp);
2797 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2798 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
2799 IHTMLElementCollection_Release(col);
2801 get_elem_by_id(doc, xxxW, FALSE);
2802 elem = get_doc_elem_by_id(doc, xxxW);
2803 ok(!elem, "elem != NULL\n");
2805 elem = get_doc_elem_by_id(doc, sW);
2806 ok(elem != NULL, "elem == NULL\n");
2807 if(elem) {
2808 test_elem_type((IUnknown*)elem, ET_SELECT);
2809 test_elem_attr(elem, xxxW, NULL);
2810 test_elem_attr(elem, idW, sW);
2811 test_elem_class((IUnknown*)elem, NULL);
2812 test_elem_set_class((IUnknown*)elem, "cl");
2813 test_elem_set_class((IUnknown*)elem, NULL);
2814 test_elem_tabindex((IUnknown*)elem, 0);
2815 test_elem_set_tabindex((IUnknown*)elem, 1);
2817 node = test_node_get_parent((IUnknown*)elem);
2818 ok(node != NULL, "node == NULL\n");
2819 test_node_name((IUnknown*)node, "BODY");
2820 node2 = test_node_get_parent((IUnknown*)node);
2821 IHTMLDOMNode_Release(node);
2822 ok(node2 != NULL, "node == NULL\n");
2823 test_node_name((IUnknown*)node2, "HTML");
2824 node = test_node_get_parent((IUnknown*)node2);
2825 IHTMLDOMNode_Release(node2);
2826 ok(node != NULL, "node == NULL\n");
2827 test_node_name((IUnknown*)node, "#document");
2828 type = get_node_type((IUnknown*)node);
2829 ok(type == 9, "type=%ld, expected 9\n", type);
2830 node2 = test_node_get_parent((IUnknown*)node);
2831 IHTMLDOMNode_Release(node);
2832 ok(node2 == NULL, "node != NULL\n");
2834 elem2 = test_elem_get_parent((IUnknown*)elem);
2835 ok(elem2 != NULL, "elem2 == NULL\n");
2836 test_node_name((IUnknown*)elem2, "BODY");
2837 elem3 = test_elem_get_parent((IUnknown*)elem2);
2838 IHTMLElement_Release(elem2);
2839 ok(elem3 != NULL, "elem3 == NULL\n");
2840 test_node_name((IUnknown*)elem3, "HTML");
2841 elem2 = test_elem_get_parent((IUnknown*)elem3);
2842 IHTMLElement_Release(elem3);
2843 ok(elem2 == NULL, "elem2 != NULL\n");
2845 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
2846 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
2847 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
2849 IHTMLElement_Release(elem);
2852 elem = get_elem_by_id(doc, sW, TRUE);
2853 if(elem) {
2854 IHTMLSelectElement *select;
2856 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
2857 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
2859 test_select_elem(select);
2861 test_elem_title((IUnknown*)select, NULL);
2862 test_elem_set_title((IUnknown*)select, "Title");
2863 test_elem_title((IUnknown*)select, "Title");
2864 test_elem_offset((IUnknown*)select);
2866 node = get_first_child((IUnknown*)select);
2867 ok(node != NULL, "node == NULL\n");
2868 if(node) {
2869 test_elem_type((IUnknown*)node, ET_OPTION);
2870 IHTMLDOMNode_Release(node);
2873 type = get_node_type((IUnknown*)select);
2874 ok(type == 1, "type=%ld\n", type);
2876 IHTMLSelectElement_Release(select);
2877 IHTMLElement_Release(elem);
2880 elem = get_elem_by_id(doc, scW, TRUE);
2881 if(elem) {
2882 IHTMLScriptElement *script;
2883 BSTR type;
2885 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
2886 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
2888 hres = IHTMLScriptElement_get_type(script, &type);
2889 ok(hres == S_OK, "get_type failed: %08x\n", hres);
2890 ok(!lstrcmpW(type, text_javascriptW), "Unexpected type %s\n", dbgstr_w(type));
2891 SysFreeString(type);
2893 IHTMLScriptElement_Release(script);
2896 elem = get_elem_by_id(doc, inW, TRUE);
2897 if(elem) {
2898 IHTMLInputElement *input;
2900 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
2901 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
2903 test_elem_id((IUnknown*)elem, "in");
2904 test_elem_put_id((IUnknown*)elem, "newin");
2905 test_input_get_disabled(input, VARIANT_FALSE);
2906 test_input_set_disabled(input, VARIANT_TRUE);
2907 test_input_set_disabled(input, VARIANT_FALSE);
2908 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
2909 test_input_get_disabled(input, VARIANT_TRUE);
2910 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
2911 test_input_get_disabled(input, VARIANT_FALSE);
2912 test_elem_client_size((IUnknown*)elem);
2914 test_node_get_value_str((IUnknown*)elem, NULL);
2915 test_node_put_value_str((IUnknown*)elem, "test");
2916 test_node_get_value_str((IUnknown*)elem, NULL);
2917 test_input_value((IUnknown*)elem, NULL);
2918 test_input_put_value((IUnknown*)elem, "test");
2919 test_input_value((IUnknown*)elem, NULL);
2920 test_elem_class((IUnknown*)elem, "testclass");
2921 test_elem_tabindex((IUnknown*)elem, 2);
2922 test_elem_set_tabindex((IUnknown*)elem, 3);
2923 test_elem_title((IUnknown*)elem, "test title");
2925 IHTMLInputElement_Release(input);
2926 IHTMLElement_Release(elem);
2929 elem = get_elem_by_id(doc, imgidW, TRUE);
2930 if(elem) {
2931 test_img_set_src((IUnknown*)elem, "about:blank");
2932 test_img_alt((IUnknown*)elem, NULL);
2933 test_img_set_alt((IUnknown*)elem, "alt test");
2934 IHTMLElement_Release(elem);
2937 elem = get_doc_elem_by_id(doc, tblW);
2938 ok(elem != NULL, "elem == NULL\n");
2939 if(elem) {
2940 test_table_elem(elem);
2941 IHTMLElement_Release(elem);
2944 elem = get_doc_elem_by_id(doc, row2W);
2945 ok(elem != NULL, "elem == NULL\n");
2946 if(elem) {
2947 test_tr_elem(elem);
2948 IHTMLElement_Release(elem);
2951 hres = IHTMLDocument2_get_body(doc, &elem);
2952 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2954 node = get_first_child((IUnknown*)elem);
2955 ok(node != NULL, "node == NULL\n");
2956 if(node) {
2957 test_ifaces((IUnknown*)node, text_iids);
2958 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
2960 node2 = get_first_child((IUnknown*)node);
2961 ok(!node2, "node2 != NULL\n");
2963 type = get_node_type((IUnknown*)node);
2964 ok(type == 3, "type=%ld\n", type);
2966 test_node_get_value_str((IUnknown*)node, "text test");
2967 test_node_put_value_str((IUnknown*)elem, "test text");
2968 test_node_get_value_str((IUnknown*)node, "text test");
2970 IHTMLDOMNode_Release(node);
2973 child_col = get_child_nodes((IUnknown*)elem);
2974 ok(child_col != NULL, "child_coll == NULL\n");
2975 if(child_col) {
2976 long length = 0;
2978 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection);
2980 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
2981 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2982 ok(length, "length=0\n");
2984 node = get_child_item(child_col, 0);
2985 ok(node != NULL, "node == NULL\n");
2986 if(node) {
2987 type = get_node_type((IUnknown*)node);
2988 ok(type == 3, "type=%ld\n", type);
2989 IHTMLDOMNode_Release(node);
2992 node = get_child_item(child_col, 1);
2993 ok(node != NULL, "node == NULL\n");
2994 if(node) {
2995 type = get_node_type((IUnknown*)node);
2996 ok(type == 8, "type=%ld\n", type);
2998 test_elem_id((IUnknown*)node, NULL);
2999 IHTMLDOMNode_Release(node);
3002 disp = (void*)0xdeadbeef;
3003 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
3004 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3005 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3007 disp = (void*)0xdeadbeef;
3008 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
3009 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
3010 ok(disp == (void*)0xdeadbeef, "disp=%p\n", disp);
3012 test_child_col_disp(child_col);
3014 IHTMLDOMChildrenCollection_Release(child_col);
3017 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
3018 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
3019 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
3021 IHTMLElement_Release(elem);
3023 test_stylesheets(doc);
3024 test_create_option_elem(doc);
3026 test_doc_title(doc, "test");
3027 test_doc_set_title(doc, "test title");
3028 test_doc_title(doc, "test title");
3031 static void test_create_elems(IHTMLDocument2 *doc)
3033 IHTMLElement *elem, *body, *elem2;
3034 IHTMLDOMNode *node;
3035 IDispatch *disp;
3036 long type;
3037 HRESULT hres;
3039 static const elem_type_t types1[] = { ET_TESTG };
3041 elem = test_create_elem(doc, "TEST");
3042 test_elem_tag((IUnknown*)elem, "TEST");
3043 type = get_node_type((IUnknown*)elem);
3044 ok(type == 1, "type=%ld\n", type);
3045 test_ifaces((IUnknown*)elem, elem_iids);
3046 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement);
3048 hres = IHTMLDocument2_get_body(doc, &body);
3049 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3050 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3052 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
3053 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
3054 elem2 = get_elem_iface((IUnknown*)node);
3055 IHTMLElement_Release(elem2);
3057 hres = IHTMLElement_get_all(body, &disp);
3058 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3059 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
3060 IDispatch_Release(disp);
3062 test_node_remove_child((IUnknown*)body, node);
3064 hres = IHTMLElement_get_all(body, &disp);
3065 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3066 test_elem_collection((IUnknown*)disp, NULL, 0);
3067 IDispatch_Release(disp);
3068 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
3070 IHTMLElement_Release(body);
3071 IHTMLElement_Release(elem);
3072 IHTMLDOMNode_Release(node);
3074 node = test_create_text(doc, "test");
3075 test_ifaces((IUnknown*)node, text_iids);
3076 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode);
3077 IHTMLDOMNode_Release(node);
3080 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
3082 IOleCommandTarget *cmdtrg;
3083 HRESULT hres;
3085 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3086 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
3088 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
3089 ok(hres == S_OK, "Exec failed: %08x\n", hres);
3091 IOleCommandTarget_Release(cmdtrg);
3094 static void test_indent(IHTMLDocument2 *doc)
3096 IHTMLElementCollection *col;
3097 IHTMLTxtRange *range;
3098 HRESULT hres;
3100 static const elem_type_t all_types[] = {
3101 ET_HTML,
3102 ET_HEAD,
3103 ET_TITLE,
3104 ET_BODY,
3105 ET_BR,
3106 ET_A,
3109 static const elem_type_t indent_types[] = {
3110 ET_HTML,
3111 ET_HEAD,
3112 ET_TITLE,
3113 ET_BODY,
3114 ET_BLOCKQUOTE,
3115 ET_P,
3116 ET_BR,
3117 ET_A,
3120 hres = IHTMLDocument2_get_all(doc, &col);
3121 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3122 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
3123 IHTMLElementCollection_Release(col);
3125 range = test_create_body_range(doc);
3126 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
3127 IHTMLTxtRange_Release(range);
3129 hres = IHTMLDocument2_get_all(doc, &col);
3130 ok(hres == S_OK, "get_all failed: %08x\n", hres);
3131 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
3132 IHTMLElementCollection_Release(col);
3135 static IHTMLDocument2 *notif_doc;
3136 static BOOL doc_complete;
3138 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
3139 REFIID riid, void**ppv)
3141 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
3142 *ppv = iface;
3143 return S_OK;
3146 ok(0, "unexpected call\n");
3147 return E_NOINTERFACE;
3150 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
3152 return 2;
3155 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
3157 return 1;
3160 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
3162 if(dispID == DISPID_READYSTATE){
3163 BSTR state;
3164 HRESULT hres;
3166 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
3168 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
3169 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3171 if(!lstrcmpW(state, completeW))
3172 doc_complete = TRUE;
3174 SysFreeString(state);
3177 return S_OK;
3180 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
3182 ok(0, "unexpected call\n");
3183 return E_NOTIMPL;
3186 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
3187 PropertyNotifySink_QueryInterface,
3188 PropertyNotifySink_AddRef,
3189 PropertyNotifySink_Release,
3190 PropertyNotifySink_OnChanged,
3191 PropertyNotifySink_OnRequestEdit
3194 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
3196 static IHTMLDocument2 *create_doc_with_string(const char *str)
3198 IPersistStreamInit *init;
3199 IStream *stream;
3200 IHTMLDocument2 *doc;
3201 HGLOBAL mem;
3202 SIZE_T len;
3204 notif_doc = doc = create_document();
3205 if(!doc)
3206 return NULL;
3208 doc_complete = FALSE;
3209 len = strlen(str);
3210 mem = GlobalAlloc(0, len);
3211 memcpy(mem, str, len);
3212 CreateStreamOnHGlobal(mem, TRUE, &stream);
3214 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
3216 IPersistStreamInit_Load(init, stream);
3217 IPersistStreamInit_Release(init);
3218 IStream_Release(stream);
3220 return doc;
3223 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
3225 IConnectionPointContainer *container;
3226 IConnectionPoint *cp;
3227 DWORD cookie;
3228 HRESULT hres;
3230 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
3231 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
3233 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
3234 IConnectionPointContainer_Release(container);
3235 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
3237 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
3238 IConnectionPoint_Release(cp);
3239 ok(hres == S_OK, "Advise failed: %08x\n", hres);
3242 typedef void (*domtest_t)(IHTMLDocument2*);
3244 static void run_domtest(const char *str, domtest_t test)
3246 IHTMLDocument2 *doc;
3247 IHTMLElement *body = NULL;
3248 ULONG ref;
3249 MSG msg;
3250 HRESULT hres;
3252 doc = create_doc_with_string(str);
3253 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3255 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
3256 TranslateMessage(&msg);
3257 DispatchMessage(&msg);
3260 hres = IHTMLDocument2_get_body(doc, &body);
3261 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3263 if(body) {
3264 IHTMLElement_Release(body);
3265 test(doc);
3266 }else {
3267 skip("Could not get document body. Assuming no Gecko installed.\n");
3270 ref = IHTMLDocument2_Release(doc);
3271 ok(!ref ||
3272 ref == 1, /* Vista */
3273 "ref = %d\n", ref);
3276 static void gecko_installer_workaround(BOOL disable)
3278 HKEY hkey;
3279 DWORD res;
3281 static BOOL has_url = FALSE;
3282 static char url[2048];
3284 if(!disable && !has_url)
3285 return;
3287 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
3288 if(res != ERROR_SUCCESS)
3289 return;
3291 if(disable) {
3292 DWORD type, size = sizeof(url);
3294 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
3295 if(res == ERROR_SUCCESS && type == REG_SZ)
3296 has_url = TRUE;
3298 RegDeleteValue(hkey, "GeckoUrl");
3299 }else {
3300 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
3303 RegCloseKey(hkey);
3306 START_TEST(dom)
3308 gecko_installer_workaround(TRUE);
3309 CoInitialize(NULL);
3311 run_domtest(doc_str1, test_doc_elem);
3312 run_domtest(range_test_str, test_txtrange);
3313 run_domtest(range_test2_str, test_txtrange2);
3314 run_domtest(elem_test_str, test_elems);
3315 run_domtest(doc_blank, test_create_elems);
3316 run_domtest(doc_blank, test_defaults);
3317 run_domtest(indent_test_str, test_indent);
3319 CoUninitialize();
3320 gecko_installer_workaround(FALSE);