mshtml: Make empty string is a valid overflow style.
[wine.git] / dlls / mshtml / tests / dom.c
blob49f5ab18cb6a8cc4b0b86b8197e0726a13a4ea49
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 onload=\"Testing()\">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\"><!--\nfunction Testing() {}\n// -->\n</script>"
50 "<test />"
51 "<img id=\"imgid\"/>"
52 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
53 "</body></html>";
54 static const char indent_test_str[] =
55 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
56 static const char cond_comment_str[] =
57 "<html><head><title>test</title></head><body>"
58 "<!--[if gte IE 4]> <br> <![endif]-->"
59 "</body></html>";
61 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
62 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
63 static WCHAR wordW[] = {'w','o','r','d',0};
65 typedef enum {
66 ET_NONE,
67 ET_HTML,
68 ET_HEAD,
69 ET_TITLE,
70 ET_BODY,
71 ET_A,
72 ET_INPUT,
73 ET_SELECT,
74 ET_TEXTAREA,
75 ET_OPTION,
76 ET_STYLE,
77 ET_BLOCKQUOTE,
78 ET_P,
79 ET_BR,
80 ET_TABLE,
81 ET_TBODY,
82 ET_SCRIPT,
83 ET_TEST,
84 ET_TESTG,
85 ET_COMMENT,
86 ET_IMG,
87 ET_TR,
88 ET_TD,
89 ET_IFRAME
90 } elem_type_t;
92 static const IID * const none_iids[] = {
93 &IID_IUnknown,
94 NULL
97 static const IID * const elem_iids[] = {
98 &IID_IHTMLDOMNode,
99 &IID_IHTMLDOMNode2,
100 &IID_IHTMLElement,
101 &IID_IHTMLElement2,
102 &IID_IHTMLElement3,
103 &IID_IDispatchEx,
104 &IID_IConnectionPointContainer,
105 NULL
108 static const IID * const body_iids[] = {
109 &IID_IHTMLDOMNode,
110 &IID_IHTMLDOMNode2,
111 &IID_IHTMLElement,
112 &IID_IHTMLElement2,
113 &IID_IHTMLElement3,
114 &IID_IHTMLTextContainer,
115 &IID_IHTMLBodyElement,
116 &IID_IDispatchEx,
117 &IID_IConnectionPointContainer,
118 NULL
121 static const IID * const anchor_iids[] = {
122 &IID_IHTMLDOMNode,
123 &IID_IHTMLDOMNode2,
124 &IID_IHTMLElement,
125 &IID_IHTMLElement2,
126 &IID_IHTMLElement3,
127 &IID_IHTMLAnchorElement,
128 &IID_IDispatchEx,
129 &IID_IConnectionPointContainer,
130 NULL
133 static const IID * const input_iids[] = {
134 &IID_IHTMLDOMNode,
135 &IID_IHTMLDOMNode2,
136 &IID_IHTMLElement,
137 &IID_IHTMLElement2,
138 &IID_IHTMLElement3,
139 &IID_IHTMLInputElement,
140 &IID_IHTMLInputTextElement,
141 &IID_IDispatchEx,
142 &IID_IConnectionPointContainer,
143 NULL
146 static const IID * const select_iids[] = {
147 &IID_IHTMLDOMNode,
148 &IID_IHTMLDOMNode2,
149 &IID_IHTMLElement,
150 &IID_IHTMLElement2,
151 &IID_IHTMLElement3,
152 &IID_IHTMLSelectElement,
153 &IID_IDispatchEx,
154 &IID_IConnectionPointContainer,
155 NULL
158 static const IID * const textarea_iids[] = {
159 &IID_IHTMLDOMNode,
160 &IID_IHTMLDOMNode2,
161 &IID_IHTMLElement,
162 &IID_IHTMLElement2,
163 &IID_IHTMLElement3,
164 &IID_IHTMLTextAreaElement,
165 &IID_IDispatchEx,
166 &IID_IConnectionPointContainer,
167 NULL
170 static const IID * const option_iids[] = {
171 &IID_IHTMLDOMNode,
172 &IID_IHTMLDOMNode2,
173 &IID_IHTMLElement,
174 &IID_IHTMLElement2,
175 &IID_IHTMLElement3,
176 &IID_IHTMLOptionElement,
177 &IID_IDispatchEx,
178 &IID_IConnectionPointContainer,
179 NULL
182 static const IID * const table_iids[] = {
183 &IID_IHTMLDOMNode,
184 &IID_IHTMLDOMNode2,
185 &IID_IHTMLElement,
186 &IID_IHTMLElement2,
187 &IID_IHTMLElement3,
188 &IID_IHTMLTable,
189 &IID_IDispatchEx,
190 &IID_IConnectionPointContainer,
191 NULL
194 static const IID * const script_iids[] = {
195 &IID_IHTMLDOMNode,
196 &IID_IHTMLDOMNode2,
197 &IID_IHTMLElement,
198 &IID_IHTMLElement2,
199 &IID_IHTMLElement3,
200 &IID_IHTMLScriptElement,
201 &IID_IDispatchEx,
202 &IID_IConnectionPointContainer,
203 NULL
206 static const IID * const text_iids[] = {
207 &IID_IHTMLDOMNode,
208 &IID_IHTMLDOMNode2,
209 &IID_IHTMLDOMTextNode,
210 NULL
213 static const IID * const location_iids[] = {
214 &IID_IDispatch,
215 &IID_IHTMLLocation,
216 NULL
219 static const IID * const window_iids[] = {
220 &IID_IDispatch,
221 &IID_IHTMLWindow2,
222 &IID_IHTMLWindow3,
223 &IID_IDispatchEx,
224 NULL
227 static const IID * const comment_iids[] = {
228 &IID_IHTMLDOMNode,
229 &IID_IHTMLDOMNode2,
230 &IID_IHTMLElement,
231 &IID_IHTMLElement2,
232 &IID_IHTMLElement3,
233 &IID_IHTMLCommentElement,
234 &IID_IDispatchEx,
235 &IID_IConnectionPointContainer,
236 NULL
239 static const IID * const img_iids[] = {
240 &IID_IHTMLDOMNode,
241 &IID_IHTMLDOMNode2,
242 &IID_IHTMLElement,
243 &IID_IHTMLElement2,
244 &IID_IHTMLElement3,
245 &IID_IDispatchEx,
246 &IID_IHTMLImgElement,
247 &IID_IConnectionPointContainer,
248 NULL
251 static const IID * const tr_iids[] = {
252 &IID_IHTMLDOMNode,
253 &IID_IHTMLDOMNode2,
254 &IID_IHTMLElement,
255 &IID_IHTMLElement2,
256 &IID_IHTMLElement3,
257 &IID_IDispatchEx,
258 &IID_IHTMLTableRow,
259 &IID_IConnectionPointContainer,
260 NULL
263 static const IID * const td_iids[] = {
264 &IID_IHTMLDOMNode,
265 &IID_IHTMLDOMNode2,
266 &IID_IHTMLElement,
267 &IID_IHTMLElement2,
268 &IID_IHTMLElement3,
269 &IID_IDispatchEx,
270 &IID_IConnectionPointContainer,
271 NULL
274 static const IID * const iframe_iids[] = {
275 &IID_IHTMLDOMNode,
276 &IID_IHTMLDOMNode2,
277 &IID_IHTMLElement,
278 &IID_IHTMLElement2,
279 &IID_IHTMLElement3,
280 &IID_IHTMLFrameBase2,
281 &IID_IDispatchEx,
282 &IID_IConnectionPointContainer,
283 NULL
286 static const IID * const generic_iids[] = {
287 &IID_IHTMLDOMNode,
288 &IID_IHTMLDOMNode2,
289 &IID_IHTMLElement,
290 &IID_IHTMLElement2,
291 &IID_IHTMLElement3,
292 &IID_IHTMLGenericElement,
293 &IID_IDispatchEx,
294 &IID_IConnectionPointContainer,
295 NULL
298 static const IID * const style_iids[] = {
299 &IID_IUnknown,
300 &IID_IDispatch,
301 &IID_IDispatchEx,
302 &IID_IHTMLStyle,
303 &IID_IHTMLStyle2,
304 &IID_IHTMLStyle3,
305 &IID_IHTMLStyle4,
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_guid(REFIID riid)
352 static char buf[50];
354 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
355 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
356 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
357 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
359 return buf;
362 static int strcmp_wa(LPCWSTR strw, const char *stra)
364 CHAR buf[512];
365 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
366 return lstrcmpA(stra, buf);
369 static BSTR a2bstr(const char *str)
371 BSTR ret;
372 int len;
374 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
375 ret = SysAllocStringLen(NULL, len);
376 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
378 return ret;
381 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
383 IUnknown *unk1, *unk2;
385 if(iface1 == iface2)
386 return TRUE;
388 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
389 IUnknown_Release(unk1);
390 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
391 IUnknown_Release(unk2);
393 return unk1 == unk2;
396 static IHTMLDocument2 *create_document(void)
398 IHTMLDocument2 *doc;
399 IHTMLDocument5 *doc5;
400 HRESULT hres;
402 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
403 &IID_IHTMLDocument2, (void**)&doc);
404 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
406 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
407 if(FAILED(hres)) {
408 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
409 IHTMLDocument2_Release(doc);
410 return NULL;
413 IHTMLDocument5_Release(doc5);
414 return doc;
417 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
418 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
420 const IID * const *piid;
421 IUnknown *unk;
422 HRESULT hres;
424 for(piid = iids; *piid; piid++) {
425 hres = IDispatch_QueryInterface(iface, *piid, (void**)&unk);
426 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", dbgstr_guid(*piid), hres);
427 if(SUCCEEDED(hres))
428 IUnknown_Release(unk);
432 #define test_get_dispid(u,id) _test_disp(__LINE__,u,id)
433 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
435 IDispatchEx *dispex;
436 ITypeInfo *typeinfo;
437 BOOL ret = FALSE;
438 UINT ticnt;
439 HRESULT hres;
441 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
442 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
443 if(FAILED(hres))
444 return FALSE;
446 ticnt = 0xdeadbeef;
447 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
448 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
449 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
451 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
452 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
454 if(SUCCEEDED(hres)) {
455 TYPEATTR *type_attr;
457 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
458 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
459 if(hres == S_OK) {
460 *iid = type_attr->guid;
461 ret = TRUE;
464 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
465 ITypeInfo_Release(typeinfo);
468 IDispatchEx_Release(dispex);
469 return ret;
472 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
473 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
475 DISPPARAMS dp = {NULL,NULL,0,0};
476 IDispatchEx *dispex;
477 EXCEPINFO ei;
478 VARIANT var;
479 HRESULT hres;
481 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
482 ok_(__FILE__,line)(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
483 if(FAILED(hres))
484 return;
486 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
487 IDispatchEx_Release(dispex);
488 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
490 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
491 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
492 VariantClear(&var);
495 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
496 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
498 IID iid;
500 if(_test_get_dispid(line, unk, &iid))
501 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", dbgstr_guid(&iid));
503 _test_disp_value(line, unk, val);
506 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
507 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
509 IID iid;
511 if(_test_get_dispid(line, unk, &iid))
512 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
513 "unexpected guid %s\n", dbgstr_guid(&iid));
515 _test_disp_value(line, unk, val);
518 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
519 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
521 IHTMLElement *elem;
522 HRESULT hres;
524 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
525 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
526 return elem;
529 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
530 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
532 IHTMLElement2 *elem;
533 HRESULT hres;
535 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
536 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
537 return elem;
540 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
541 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
543 IHTMLElement3 *elem;
544 HRESULT hres;
546 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
547 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
548 return elem;
551 #define get_node_iface(u) _get_node_iface(__LINE__,u)
552 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
554 IHTMLDOMNode *node;
555 HRESULT hres;
557 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
558 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
559 return node;
562 #define get_img_iface(u) _get_img_iface(__LINE__,u)
563 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
565 IHTMLImgElement *img;
566 HRESULT hres;
568 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
569 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
570 return img;
573 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
574 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
576 IHTMLDOMNode *node = _get_node_iface(line, unk);
577 BSTR name;
578 HRESULT hres;
580 hres = IHTMLDOMNode_get_nodeName(node, &name);
581 IHTMLDOMNode_Release(node);
582 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
583 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
585 SysFreeString(name);
588 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
589 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
591 IHTMLElement *elem = _get_elem_iface(line, unk);
592 BSTR tag;
593 HRESULT hres;
595 hres = IHTMLElement_get_tagName(elem, &tag);
596 IHTMLElement_Release(elem);
597 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
598 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
600 SysFreeString(tag);
603 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
604 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
606 _test_elem_tag(line, unk, elem_type_infos[type].tag);
607 _test_ifaces(line, unk, elem_type_infos[type].iids);
609 if(elem_type_infos[type].dispiid)
610 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
613 #define get_node_type(n) _get_node_type(__LINE__,n)
614 static LONG _get_node_type(unsigned line, IUnknown *unk)
616 IHTMLDOMNode *node = _get_node_iface(line, unk);
617 LONG type = -1;
618 HRESULT hres;
620 hres = IHTMLDOMNode_get_nodeType(node, &type);
621 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
623 IHTMLDOMNode_Release(node);
625 return type;
628 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
629 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
631 IHTMLDOMNode *node = _get_node_iface(line, unk);
632 IHTMLDOMChildrenCollection *col = NULL;
633 IDispatch *disp;
634 HRESULT hres;
636 hres = IHTMLDOMNode_get_childNodes(node, &disp);
637 IHTMLDOMNode_Release(node);
638 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
639 if(FAILED(hres))
640 return NULL;
642 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
643 IDispatch_Release(disp);
644 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
646 return col;
649 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
650 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
652 IHTMLDOMNode *node = NULL;
653 IDispatch *disp;
654 HRESULT hres;
656 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
657 ok(hres == S_OK, "item failed: %08x\n", hres);
659 node = _get_node_iface(line, (IUnknown*)disp);
660 IDispatch_Release(disp);
662 return node;
665 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
666 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
668 VARIANT value;
669 BSTR tmp;
670 HRESULT hres;
672 VariantInit(&value);
674 tmp = a2bstr(name);
675 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
676 SysFreeString(tmp);
677 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
679 if(exval) {
680 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
681 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
682 }else {
683 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
686 VariantClear(&value);
689 #define test_elem_offset(u) _test_elem_offset(__LINE__,u)
690 static void _test_elem_offset(unsigned line, IUnknown *unk)
692 IHTMLElement *elem = _get_elem_iface(line, unk);
693 LONG l;
694 HRESULT hres;
696 hres = IHTMLElement_get_offsetTop(elem, &l);
697 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
699 hres = IHTMLElement_get_offsetHeight(elem, &l);
700 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
702 hres = IHTMLElement_get_offsetWidth(elem, &l);
703 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
705 IHTMLElement_Release(elem);
708 static void test_doc_elem(IHTMLDocument2 *doc)
710 IHTMLElement *elem;
711 IHTMLDocument3 *doc3;
712 HRESULT hres;
714 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
715 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
717 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
718 IHTMLDocument3_Release(doc3);
719 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
721 test_node_name((IUnknown*)elem, "HTML");
722 test_elem_tag((IUnknown*)elem, "HTML");
724 IHTMLElement_Release(elem);
727 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
728 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
730 IHTMLElement *elem;
731 IHTMLDocument3 *doc3;
732 HRESULT hres;
734 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
735 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
736 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
737 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
738 IHTMLDocument3_Release(doc3);
740 return elem;
743 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
744 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
746 BSTR bstr;
747 HRESULT hres;
749 hres = IHTMLOptionElement_get_text(option, &bstr);
750 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
751 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
752 SysFreeString(bstr);
755 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
756 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
758 BSTR bstr;
759 HRESULT hres;
761 bstr = a2bstr(text);
762 hres = IHTMLOptionElement_put_text(option, bstr);
763 SysFreeString(bstr);
764 ok(hres == S_OK, "put_text failed: %08x\n", hres);
766 _test_option_text(line, option, text);
769 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
770 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
772 BSTR bstr;
773 HRESULT hres;
775 hres = IHTMLOptionElement_get_value(option, &bstr);
776 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
777 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
778 SysFreeString(bstr);
781 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
782 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
784 BSTR bstr;
785 HRESULT hres;
787 bstr = a2bstr(value);
788 hres = IHTMLOptionElement_put_value(option, bstr);
789 SysFreeString(bstr);
790 ok(hres == S_OK, "put_value failed: %08x\n", hres);
792 _test_option_value(line, option, value);
795 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
796 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
797 const char *txt, const char *val)
799 IHTMLOptionElementFactory *factory;
800 IHTMLOptionElement *option;
801 IHTMLWindow2 *window;
802 VARIANT text, value, empty;
803 HRESULT hres;
805 hres = IHTMLDocument2_get_parentWindow(doc, &window);
806 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
808 hres = IHTMLWindow2_get_Option(window, &factory);
809 IHTMLWindow2_Release(window);
810 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
812 V_VT(&text) = VT_BSTR;
813 V_BSTR(&text) = a2bstr(txt);
814 V_VT(&value) = VT_BSTR;
815 V_BSTR(&value) = a2bstr(val);
816 V_VT(&empty) = VT_EMPTY;
818 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
819 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
821 IHTMLOptionElementFactory_Release(factory);
822 VariantClear(&text);
823 VariantClear(&value);
825 _test_option_text(line, option, txt);
826 _test_option_value(line, option, val);
828 return option;
831 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
832 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
834 LONG len = 0xdeadbeef;
835 HRESULT hres;
837 hres = IHTMLSelectElement_get_length(select, &len);
838 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
839 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
842 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
843 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
845 LONG idx = 0xdeadbeef;
846 HRESULT hres;
848 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
849 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
850 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
853 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
854 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
856 HRESULT hres;
858 hres = IHTMLSelectElement_put_selectedIndex(select, index);
859 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
860 _test_select_selidx(line, select, index);
863 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
864 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
866 BSTR val;
867 HRESULT hres;
869 hres = IHTMLSelectElement_get_value(select, &val);
870 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
871 if(exval)
872 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
873 else
874 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
877 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
878 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
880 BSTR bstr;
881 HRESULT hres;
883 bstr = a2bstr(val);
884 hres = IHTMLSelectElement_put_value(select, bstr);
885 SysFreeString(bstr);
886 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
889 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
890 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
892 BSTR type;
893 HRESULT hres;
895 hres = IHTMLSelectElement_get_type(select, &type);
896 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
897 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
900 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
901 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
903 BSTR text;
904 HRESULT hres;
906 hres = IHTMLTxtRange_get_text(range, &text);
907 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
909 if(extext) {
910 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
911 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
912 }else {
913 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
916 SysFreeString(text);
920 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
921 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
923 HRESULT hres;
925 hres = IHTMLTxtRange_collapse(range, b);
926 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
927 _test_range_text(line, range, NULL);
930 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
931 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
932 VARIANT_BOOL exb, const char *extext)
934 VARIANT_BOOL b = 0xe0e0;
935 HRESULT hres;
937 hres = IHTMLTxtRange_expand(range, unit, &b);
938 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
939 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
940 _test_range_text(line, range, extext);
943 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
944 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
946 LONG c = 0xdeadbeef;
947 HRESULT hres;
949 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
950 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
951 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
952 _test_range_text(line, range, NULL);
955 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
956 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
957 LPWSTR unit, LONG cnt, LONG excnt)
959 LONG c = 0xdeadbeef;
960 HRESULT hres;
962 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
963 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
964 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
967 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
968 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
970 LONG c = 0xdeadbeef;
971 HRESULT hres;
973 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
974 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
975 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
978 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
979 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
981 HRESULT hres;
982 BSTR bstr = a2bstr(text);
984 hres = IHTMLTxtRange_put_text(range, bstr);
985 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
986 SysFreeString(bstr);
987 _test_range_text(line, range, NULL);
990 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
991 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
993 VARIANT_BOOL b;
994 HRESULT hres;
996 b = 0xe0e0;
997 hres = IHTMLTxtRange_inRange(range1, range2, &b);
998 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
999 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1002 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
1003 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
1005 VARIANT_BOOL b;
1006 HRESULT hres;
1008 b = 0xe0e0;
1009 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
1010 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
1011 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
1013 b = 0xe0e0;
1014 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
1015 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
1016 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
1018 if(exb) {
1019 test_range_inrange(range1, range2, VARIANT_TRUE);
1020 test_range_inrange(range2, range1, VARIANT_TRUE);
1024 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
1025 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
1027 IHTMLElement *elem;
1028 HRESULT hres;
1030 hres = IHTMLTxtRange_parentElement(range, &elem);
1031 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
1033 _test_elem_type(line, (IUnknown*)elem, type);
1035 IHTMLElement_Release(elem);
1038 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
1039 static void _test_elem_collection(unsigned line, IUnknown *unk,
1040 const elem_type_t *elem_types, LONG exlen)
1042 IHTMLElementCollection *col;
1043 LONG len;
1044 DWORD i;
1045 VARIANT name, index;
1046 IDispatch *disp, *disp2;
1047 HRESULT hres;
1049 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
1050 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
1052 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
1054 hres = IHTMLElementCollection_get_length(col, &len);
1055 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1056 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
1058 if(len > exlen)
1059 len = exlen;
1061 V_VT(&index) = VT_EMPTY;
1063 for(i=0; i<len; i++) {
1064 V_VT(&name) = VT_I4;
1065 V_I4(&name) = i;
1066 disp = (void*)0xdeadbeef;
1067 hres = IHTMLElementCollection_item(col, name, index, &disp);
1068 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1069 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
1070 if(FAILED(hres) || !disp)
1071 continue;
1073 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
1075 if(!i) {
1076 V_VT(&name) = VT_UINT;
1077 V_I4(&name) = 0;
1078 disp2 = (void*)0xdeadbeef;
1079 hres = IHTMLElementCollection_item(col, name, index, &disp2);
1080 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
1081 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
1082 if(disp2)
1083 IDispatch_Release(disp2);
1086 IDispatch_Release(disp);
1089 V_VT(&name) = VT_I4;
1090 V_I4(&name) = len;
1091 disp = (void*)0xdeadbeef;
1092 hres = IHTMLElementCollection_item(col, name, index, &disp);
1093 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
1094 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1096 V_VT(&name) = VT_I4;
1097 V_I4(&name) = -1;
1098 disp = (void*)0xdeadbeef;
1099 hres = IHTMLElementCollection_item(col, name, index, &disp);
1100 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
1101 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
1103 IHTMLElementCollection_Release(col);
1106 #define test_elem_getelembytag(u,t,l) _test_elem_getelembytag(__LINE__,u,t,l)
1107 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen)
1109 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1110 IHTMLElementCollection *col = NULL;
1111 elem_type_t *types = NULL;
1112 BSTR tmp;
1113 int i;
1114 HRESULT hres;
1116 tmp = a2bstr(elem_type_infos[type].tag);
1117 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
1118 SysFreeString(tmp);
1119 IHTMLElement2_Release(elem);
1120 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
1121 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
1123 if(exlen) {
1124 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
1125 for(i=0; i<exlen; i++)
1126 types[i] = type;
1129 _test_elem_collection(line, (IUnknown*)col, types, exlen);
1131 HeapFree(GetProcessHeap(), 0, types);
1134 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
1135 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
1137 BSTR text = NULL;
1138 HRESULT hres;
1140 hres = IHTMLElement_get_innerText(elem, &text);
1141 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
1142 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
1143 wine_dbgstr_w(text), extext);
1144 SysFreeString(text);
1147 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
1148 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
1150 IHTMLDOMChildrenCollection *col;
1151 BSTR str;
1152 HRESULT hres;
1154 str = a2bstr(text);
1155 hres = IHTMLElement_put_innerText(elem, str);
1156 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
1157 SysFreeString(str);
1159 _test_elem_innertext(line, elem, text);
1162 col = _get_child_nodes(line, (IUnknown*)elem);
1163 ok(col != NULL, "col == NULL\n");
1164 if(col) {
1165 LONG length = 0, type;
1166 IHTMLDOMNode *node;
1168 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
1169 ok(hres == S_OK, "get_length failed: %08x\n", hres);
1170 ok(length == 1, "length = %d\n", length);
1172 node = _get_child_item(line, col, 0);
1173 ok(node != NULL, "node == NULL\n");
1174 if(node) {
1175 type = _get_node_type(line, (IUnknown*)node);
1176 ok(type == 3, "type=%d\n", type);
1177 IHTMLDOMNode_Release(node);
1180 IHTMLDOMChildrenCollection_Release(col);
1185 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
1186 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1188 IHTMLElement *elem = _get_elem_iface(line, unk);
1189 BSTR html;
1190 HRESULT hres;
1192 hres = IHTMLElement_get_innerHTML(elem, &html);
1193 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
1194 if(inner_html)
1195 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
1196 else
1197 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
1199 IHTMLElement_Release(elem);
1200 SysFreeString(html);
1203 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
1204 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
1206 IHTMLElement *elem = _get_elem_iface(line, unk);
1207 BSTR html;
1208 HRESULT hres;
1210 html = a2bstr(inner_html);
1211 hres = IHTMLElement_put_innerHTML(elem, html);
1212 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
1214 IHTMLElement_Release(elem);
1215 SysFreeString(html);
1218 #define get_first_child(n) _get_first_child(__LINE__,n)
1219 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
1221 IHTMLDOMNode *node = _get_node_iface(line, unk);
1222 IHTMLDOMNode *child = NULL;
1223 HRESULT hres;
1225 hres = IHTMLDOMNode_get_firstChild(node, &child);
1226 IHTMLDOMNode_Release(node);
1227 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
1229 return child;
1232 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
1233 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1235 IHTMLDOMNode *node = _get_node_iface(line, unk);
1236 VARIANT_BOOL b = 0xdead;
1237 HRESULT hres;
1239 hres = IHTMLDOMNode_hasChildNodes(node, &b);
1240 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
1241 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
1243 IHTMLDOMNode_Release(node);
1246 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
1247 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
1249 IHTMLDOMNode *node = _get_node_iface(line, unk);
1250 IHTMLDOMNode *parent;
1251 HRESULT hres;
1253 hres = IHTMLDOMNode_get_parentNode(node, &parent);
1254 IHTMLDOMNode_Release(node);
1255 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
1257 return parent;
1260 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
1261 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
1263 IHTMLElement *elem = _get_elem_iface(line, unk);
1264 IHTMLElement *parent;
1265 HRESULT hres;
1267 hres = IHTMLElement_get_parentElement(elem, &parent);
1268 IHTMLElement_Release(elem);
1269 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1271 return parent;
1274 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
1275 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
1277 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1278 VARIANT_BOOL disabled = 100;
1279 HRESULT hres;
1281 if (!elem3) return;
1282 hres = IHTMLElement3_get_disabled(elem3, &disabled);
1283 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1284 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1285 IHTMLElement3_Release(elem3);
1288 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
1289 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1291 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
1292 HRESULT hres;
1294 if (!elem3) return;
1295 hres = IHTMLElement3_put_disabled(elem3, b);
1296 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1298 IHTMLElement3_Release(elem3);
1299 _test_elem3_get_disabled(line, unk, b);
1302 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
1303 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
1305 VARIANT_BOOL disabled = 100;
1306 HRESULT hres;
1308 hres = IHTMLSelectElement_get_disabled(select, &disabled);
1309 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1310 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1312 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
1315 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
1316 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
1318 HRESULT hres;
1320 hres = IHTMLSelectElement_put_disabled(select, b);
1321 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1323 _test_select_get_disabled(line, select, b);
1326 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
1327 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
1329 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1330 IHTMLTextContainer *txtcont;
1331 LONG l = -1, l2 = -1;
1332 HRESULT hres;
1334 hres = IHTMLElement2_get_scrollHeight(elem, &l);
1335 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
1336 IHTMLElement2_Release(elem);
1338 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1339 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1341 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
1342 IHTMLTextContainer_Release(txtcont);
1343 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
1344 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
1346 return l;
1349 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
1350 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
1352 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1353 IHTMLTextContainer *txtcont;
1354 LONG l = -1, l2 = -1;
1355 HRESULT hres;
1357 hres = IHTMLElement2_get_scrollWidth(elem, &l);
1358 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
1359 IHTMLElement2_Release(elem);
1361 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1362 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1364 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
1365 IHTMLTextContainer_Release(txtcont);
1366 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
1367 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
1369 return l;
1372 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
1373 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
1375 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1376 IHTMLTextContainer *txtcont;
1377 LONG l = -1, l2 = -1;
1378 HRESULT hres;
1380 hres = IHTMLElement2_get_scrollTop(elem, &l);
1381 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1382 IHTMLElement2_Release(elem);
1384 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1385 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1387 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
1388 IHTMLTextContainer_Release(txtcont);
1389 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
1390 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
1392 return l;
1395 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
1396 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
1398 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1399 IHTMLTextContainer *txtcont;
1400 LONG l = -1, l2 = -1;
1401 HRESULT hres;
1403 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
1404 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
1406 hres = IHTMLElement2_get_scrollLeft(elem, &l);
1407 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
1408 IHTMLElement2_Release(elem);
1410 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
1411 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
1413 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
1414 IHTMLTextContainer_Release(txtcont);
1415 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
1416 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
1419 #define test_img_src(i,s) _test_img_src(__LINE__,i,s)
1420 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc)
1422 IHTMLImgElement *img = _get_img_iface(line, unk);
1423 BSTR src;
1424 HRESULT hres;
1426 hres = IHTMLImgElement_get_src(img, &src);
1427 IHTMLImgElement_Release(img);
1428 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
1429 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
1430 SysFreeString(src);
1433 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
1434 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
1436 IHTMLImgElement *img = _get_img_iface(line, unk);
1437 BSTR tmp;
1438 HRESULT hres;
1440 tmp = a2bstr(src);
1441 hres = IHTMLImgElement_put_src(img, tmp);
1442 IHTMLImgElement_Release(img);
1443 SysFreeString(tmp);
1444 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
1446 _test_img_src(line, unk, src);
1449 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
1450 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
1452 IHTMLImgElement *img = _get_img_iface(line, unk);
1453 BSTR alt;
1454 HRESULT hres;
1456 hres = IHTMLImgElement_get_alt(img, &alt);
1457 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1458 if(exalt)
1459 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
1460 else
1461 ok_(__FILE__,line) (!alt, "alt != NULL\n");
1462 SysFreeString(alt);
1465 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
1466 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
1468 IHTMLImgElement *img = _get_img_iface(line, unk);
1469 BSTR tmp;
1470 HRESULT hres;
1472 tmp = a2bstr(alt);
1473 hres = IHTMLImgElement_put_alt(img, tmp);
1474 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
1475 SysFreeString(tmp);
1477 _test_img_alt(line, unk, alt);
1480 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
1481 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1483 VARIANT_BOOL disabled = 100;
1484 HRESULT hres;
1486 hres = IHTMLInputElement_get_disabled(input, &disabled);
1487 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1488 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
1490 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
1493 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
1494 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1496 HRESULT hres;
1498 hres = IHTMLInputElement_put_disabled(input, b);
1499 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
1501 _test_input_get_disabled(line, input, b);
1504 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
1505 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1507 VARIANT_BOOL checked = 100;
1508 HRESULT hres;
1510 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
1511 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1512 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1515 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
1516 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1518 HRESULT hres;
1520 hres = IHTMLInputElement_put_defaultChecked(input, b);
1521 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
1523 _test_input_get_defaultchecked(line, input, b);
1526 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
1527 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
1529 VARIANT_BOOL checked = 100;
1530 HRESULT hres;
1532 hres = IHTMLInputElement_get_checked(input, &checked);
1533 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1534 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
1537 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
1538 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
1540 HRESULT hres;
1542 hres = IHTMLInputElement_put_checked(input, b);
1543 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
1545 _test_input_get_checked(line, input, b);
1548 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
1549 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
1551 IHTMLInputElement *input;
1552 BSTR bstr;
1553 HRESULT hres;
1555 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1556 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1557 if(FAILED(hres))
1558 return;
1560 hres = IHTMLInputElement_get_value(input, &bstr);
1561 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1562 if(exval)
1563 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
1564 else
1565 ok_(__FILE__,line) (!exval, "exval != NULL\n");
1566 SysFreeString(bstr);
1567 IHTMLInputElement_Release(input);
1570 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
1571 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
1573 IHTMLInputElement *input;
1574 BSTR bstr;
1575 HRESULT hres;
1577 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
1578 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
1579 if(FAILED(hres))
1580 return;
1582 bstr = a2bstr(val);
1583 hres = IHTMLInputElement_get_value(input, &bstr);
1584 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1585 SysFreeString(bstr);
1586 IHTMLInputElement_Release(input);
1589 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
1590 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
1592 IHTMLElement *elem = _get_elem_iface(line, unk);
1593 BSTR class = (void*)0xdeadbeef;
1594 HRESULT hres;
1596 hres = IHTMLElement_get_className(elem, &class);
1597 IHTMLElement_Release(elem);
1598 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
1599 if(exclass)
1600 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
1601 else
1602 ok_(__FILE__,line) (!class, "class != NULL\n");
1603 SysFreeString(class);
1606 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
1607 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
1609 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1610 short index = -3;
1611 HRESULT hres;
1613 hres = IHTMLElement2_get_tabIndex(elem2, &index);
1614 IHTMLElement2_Release(elem2);
1615 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1616 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
1619 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
1620 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
1622 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
1623 HRESULT hres;
1625 hres = IHTMLElement2_put_tabIndex(elem2, index);
1626 IHTMLElement2_Release(elem2);
1627 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
1629 _test_elem_tabindex(line, unk, index);
1632 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
1633 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
1635 IHTMLElement *elem = _get_elem_iface(line, unk);
1636 BSTR tmp;
1637 HRESULT hres;
1639 tmp = class ? a2bstr(class) : NULL;
1640 hres = IHTMLElement_put_className(elem, tmp);
1641 IHTMLElement_Release(elem);
1642 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
1643 SysFreeString(tmp);
1645 _test_elem_class(line, unk, class);
1648 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
1649 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
1651 IHTMLElement *elem = _get_elem_iface(line, unk);
1652 BSTR id = (void*)0xdeadbeef;
1653 HRESULT hres;
1655 hres = IHTMLElement_get_id(elem, &id);
1656 IHTMLElement_Release(elem);
1657 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
1659 if(exid)
1660 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
1661 else
1662 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
1664 SysFreeString(id);
1667 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
1668 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
1670 IHTMLElement *elem = _get_elem_iface(line, unk);
1671 BSTR tmp = a2bstr(new_id);
1672 HRESULT hres;
1674 hres = IHTMLElement_put_id(elem, tmp);
1675 IHTMLElement_Release(elem);
1676 SysFreeString(tmp);
1677 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
1679 _test_elem_id(line, unk, new_id);
1682 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
1683 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
1685 IHTMLElement *elem = _get_elem_iface(line, unk);
1686 BSTR title;
1687 HRESULT hres;
1689 hres = IHTMLElement_get_title(elem, &title);
1690 IHTMLElement_Release(elem);
1691 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1692 if(extitle)
1693 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
1694 else
1695 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
1697 SysFreeString(title);
1700 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
1701 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
1703 IHTMLElement *elem = _get_elem_iface(line, unk);
1704 BSTR tmp;
1705 HRESULT hres;
1707 tmp = a2bstr(title);
1708 hres = IHTMLElement_put_title(elem, tmp);
1709 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1711 IHTMLElement_Release(elem);
1712 SysFreeString(tmp);
1715 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
1716 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
1718 IHTMLDOMNode *node = _get_node_iface(line, unk);
1719 VARIANT var;
1720 HRESULT hres;
1722 hres = IHTMLDOMNode_get_nodeValue(node, &var);
1723 IHTMLDOMNode_Release(node);
1724 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1726 if(exval) {
1727 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
1728 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
1729 }else {
1730 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
1733 VariantClear(&var);
1736 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
1737 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
1739 IHTMLDOMNode *node = _get_node_iface(line, unk);
1740 VARIANT var;
1741 HRESULT hres;
1743 V_VT(&var) = VT_BSTR;
1744 V_BSTR(&var) = a2bstr(val);
1746 hres = IHTMLDOMNode_put_nodeValue(node, var);
1747 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
1748 IHTMLDOMNode_Release(node);
1749 VariantClear(&var);
1752 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
1753 static void _test_elem_client_size(unsigned line, IUnknown *unk)
1755 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
1756 LONG l;
1757 HRESULT hres;
1759 hres = IHTMLElement2_get_clientWidth(elem, &l);
1760 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
1761 hres = IHTMLElement2_get_clientHeight(elem, &l);
1762 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
1764 IHTMLElement2_Release(elem);
1767 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
1768 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
1770 IHTMLElement *elem = NULL;
1771 BSTR tmp;
1772 HRESULT hres;
1774 tmp = a2bstr(tag);
1775 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
1776 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1777 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
1779 return elem;
1782 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
1783 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
1785 IHTMLDocument3 *doc3;
1786 IHTMLDOMNode *node = NULL;
1787 BSTR tmp;
1788 HRESULT hres;
1790 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1791 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
1793 tmp = a2bstr(text);
1794 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
1795 IHTMLDocument3_Release(doc3);
1796 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
1797 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
1799 return node;
1802 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
1803 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
1805 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1806 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
1807 IHTMLDOMNode *new_child = NULL;
1808 HRESULT hres;
1810 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
1811 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
1812 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1813 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1815 IHTMLDOMNode_Release(node);
1816 IHTMLDOMNode_Release(child);
1818 return new_child;
1821 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
1822 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
1824 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
1825 IHTMLDOMNode *new_child = NULL;
1826 HRESULT hres;
1828 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
1829 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
1830 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
1831 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
1833 IHTMLDOMNode_Release(node);
1835 return new_child;
1838 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
1839 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
1841 IHTMLDOMNode *node = _get_node_iface(line, unk);
1842 IHTMLDOMNode *new_node = NULL;
1843 HRESULT hres;
1845 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
1846 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
1847 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
1848 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
1850 IHTMLDOMNode_Release(node);
1851 IHTMLDOMNode_Release(new_node);
1854 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
1855 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
1857 BSTR title = NULL;
1858 HRESULT hres;
1860 hres = IHTMLDocument2_get_title(doc, &title);
1861 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1862 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
1863 SysFreeString(title);
1866 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
1867 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
1869 BSTR tmp;
1870 HRESULT hres;
1872 tmp = a2bstr(title);
1873 hres = IHTMLDocument2_put_title(doc, tmp);
1874 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
1875 SysFreeString(tmp);
1878 #define test_border_styles(p, n) _test_border_styles(__LINE__, p, n)
1879 static void _test_border_styles(unsigned line, IHTMLStyle *pStyle, BSTR Name)
1881 HRESULT hres;
1882 DISPID dispid;
1884 hres = IHTMLStyle_GetIDsOfNames(pStyle, &IID_NULL, &Name, 1,
1885 LOCALE_USER_DEFAULT, &dispid);
1886 ok_(__FILE__,line) (hres == S_OK, "GetIDsOfNames: %08x\n", hres);
1887 if(hres == S_OK)
1889 DISPPARAMS params = {NULL,NULL,0,0};
1890 DISPID dispidNamed = DISPID_PROPERTYPUT;
1891 VARIANT ret;
1892 VARIANT vDefault;
1893 VARIANTARG arg;
1895 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1896 DISPATCH_PROPERTYGET, &params, &vDefault, NULL, NULL);
1897 ok_(__FILE__,line) (hres == S_OK, "get_default. ret: %08x\n", hres);
1899 params.cArgs = 1;
1900 params.cNamedArgs = 1;
1901 params.rgdispidNamedArgs = &dispidNamed;
1902 V_VT(&arg) = VT_BSTR;
1903 V_BSTR(&arg) = a2bstr("none");
1904 params.rgvarg = &arg;
1905 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1906 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1907 ok_(__FILE__,line) (hres == S_OK, "none. ret: %08x\n", hres);
1908 VariantClear(&arg);
1910 V_VT(&arg) = VT_BSTR;
1911 V_BSTR(&arg) = a2bstr("dotted");
1912 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1913 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1914 ok_(__FILE__,line) (hres == S_OK, "dotted. ret: %08x\n", hres);
1915 VariantClear(&arg);
1917 V_VT(&arg) = VT_BSTR;
1918 V_BSTR(&arg) = a2bstr("dashed");
1919 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1920 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1921 ok_(__FILE__,line) (hres == S_OK, "dashed. ret: %08x\n", hres);
1922 VariantClear(&arg);
1924 V_VT(&arg) = VT_BSTR;
1925 V_BSTR(&arg) = a2bstr("solid");
1926 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1927 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1928 ok_(__FILE__,line) (hres == S_OK, "solid. ret: %08x\n", hres);
1929 VariantClear(&arg);
1931 V_VT(&arg) = VT_BSTR;
1932 V_BSTR(&arg) = a2bstr("double");
1933 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1934 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1935 ok_(__FILE__,line) (hres == S_OK, "double. ret: %08x\n", hres);
1936 VariantClear(&arg);
1938 V_VT(&arg) = VT_BSTR;
1939 V_BSTR(&arg) = a2bstr("groove");
1940 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1941 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1942 ok_(__FILE__,line) (hres == S_OK, "groove. ret: %08x\n", hres);
1943 VariantClear(&arg);
1945 V_VT(&arg) = VT_BSTR;
1946 V_BSTR(&arg) = a2bstr("ridge");
1947 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1948 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1949 ok_(__FILE__,line) (hres == S_OK, "ridge. ret: %08x\n", hres);
1950 VariantClear(&arg);
1952 V_VT(&arg) = VT_BSTR;
1953 V_BSTR(&arg) = a2bstr("inset");
1954 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1955 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1956 ok_(__FILE__,line) (hres == S_OK, "inset. ret: %08x\n", hres);
1957 VariantClear(&arg);
1959 V_VT(&arg) = VT_BSTR;
1960 V_BSTR(&arg) = a2bstr("outset");
1961 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1962 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1963 ok_(__FILE__,line) (hres == S_OK, "outset. ret: %08x\n", hres);
1964 VariantClear(&arg);
1966 V_VT(&arg) = VT_BSTR;
1967 V_BSTR(&arg) = a2bstr("invalid");
1968 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1969 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1970 ok_(__FILE__,line) (FAILED(hres), "invalid value passed.\n");
1971 VariantClear(&arg);
1973 params.rgvarg = &vDefault;
1974 hres = IHTMLStyle_Invoke(pStyle, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
1975 DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
1976 ok_(__FILE__,line) (hres == S_OK, "default. ret: %08x\n", hres);
1980 #define test_style_csstext(s,t) _test_style_csstext(__LINE__,s,t)
1981 static void _test_style_csstext(unsigned line, IHTMLStyle *style, const char *extext)
1983 BSTR text = (void*)0xdeadbeef;
1984 HRESULT hres;
1986 hres = IHTMLStyle_get_cssText(style, &text);
1987 ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
1988 if(extext)
1989 ok_(__FILE__,line)(!strcmp_wa(text, extext), "cssText = %s\n", wine_dbgstr_w(text));
1990 else
1991 ok_(__FILE__,line)(!text, "cssText = %s\n", wine_dbgstr_w(text));
1993 SysFreeString(text);
1996 #define test_style_set_csstext(s,t) _test_style_set_csstext(__LINE__,s,t)
1997 static void _test_style_set_csstext(unsigned line, IHTMLStyle *style, const char *text)
1999 BSTR tmp;
2000 HRESULT hres;
2002 tmp = a2bstr(text);
2003 hres = IHTMLStyle_put_cssText(style, tmp);
2004 ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
2005 SysFreeString(tmp);
2008 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
2009 const elem_type_t *elem_types, LONG len)
2011 IDispatch *disp;
2012 VARIANT name, index;
2013 DWORD i;
2014 HRESULT hres;
2016 V_VT(&index) = VT_EMPTY;
2017 V_VT(&name) = VT_BSTR;
2018 V_BSTR(&name) = a2bstr(n);
2020 hres = IHTMLElementCollection_item(col, name, index, &disp);
2021 ok(hres == S_OK, "item failed: %08x\n", hres);
2023 test_elem_collection((IUnknown*)disp, elem_types, len);
2024 IDispatch_Release(disp);
2025 ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres);
2026 if(hres != S_OK)
2027 goto cleanup;
2029 V_VT(&index) = VT_I4;
2031 for(i=0; i<len; i++) {
2032 V_I4(&index) = i;
2033 disp = (void*)0xdeadbeef;
2034 hres = IHTMLElementCollection_item(col, name, index, &disp);
2035 ok(hres == S_OK, "item failed: %08x\n", hres);
2036 ok(disp != NULL, "disp == NULL\n");
2037 if(FAILED(hres) || !disp)
2038 continue;
2040 test_elem_type((IUnknown*)disp, elem_types[i]);
2042 IDispatch_Release(disp);
2045 V_I4(&index) = len;
2046 disp = (void*)0xdeadbeef;
2047 hres = IHTMLElementCollection_item(col, name, index, &disp);
2048 ok(hres == S_OK, "item failed: %08x\n", hres);
2049 ok(disp == NULL, "disp != NULL\n");
2051 V_I4(&index) = -1;
2052 disp = (void*)0xdeadbeef;
2053 hres = IHTMLElementCollection_item(col, name, index, &disp);
2054 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2055 ok(disp == NULL, "disp != NULL\n");
2057 cleanup:
2058 SysFreeString(V_BSTR(&name));
2061 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
2063 IHTMLElementCollection *col;
2064 IHTMLElement *elem;
2065 IDispatch *disp = (void*)0xdeadbeef;
2066 VARIANT name, index;
2067 HRESULT hres;
2069 hres = IHTMLDocument2_get_all(doc, &col);
2070 ok(hres == S_OK, "get_all failed: %08x\n", hres);
2071 ok(col != NULL, "col == NULL\n");
2072 if(FAILED(hres) || !col)
2073 return NULL;
2075 V_VT(&index) = VT_EMPTY;
2076 V_VT(&name) = VT_BSTR;
2077 V_BSTR(&name) = a2bstr(id);
2079 hres = IHTMLElementCollection_item(col, name, index, &disp);
2080 IHTMLElementCollection_Release(col);
2081 SysFreeString(V_BSTR(&name));
2082 ok(hres == S_OK, "item failed: %08x\n", hres);
2083 if(!expect_success) {
2084 ok(disp == NULL, "disp != NULL\n");
2085 return NULL;
2088 ok(disp != NULL, "disp == NULL\n");
2089 if(!disp)
2090 return NULL;
2092 elem = get_elem_iface((IUnknown*)disp);
2093 IDispatch_Release(disp);
2095 return elem;
2098 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
2100 IHTMLDocument3 *doc3;
2101 IHTMLElement *elem;
2102 BSTR tmp;
2103 HRESULT hres;
2105 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2106 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
2108 tmp = a2bstr(id);
2109 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
2110 SysFreeString(tmp);
2111 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
2113 IHTMLDocument3_Release(doc3);
2115 return elem;
2118 static void test_select_elem(IHTMLSelectElement *select)
2120 test_select_type(select, "select-one");
2121 test_select_length(select, 2);
2122 test_select_selidx(select, 0);
2123 test_select_put_selidx(select, 1);
2125 test_select_set_value(select, "val1");
2126 test_select_value(select, "val1");
2128 test_select_get_disabled(select, VARIANT_FALSE);
2129 test_select_set_disabled(select, VARIANT_TRUE);
2130 test_select_set_disabled(select, VARIANT_FALSE);
2133 static void test_create_option_elem(IHTMLDocument2 *doc)
2135 IHTMLOptionElement *option;
2137 option = create_option_elem(doc, "test text", "test value");
2139 test_option_put_text(option, "new text");
2140 test_option_put_value(option, "new value");
2142 IHTMLOptionElement_Release(option);
2145 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
2147 IHTMLBodyElement *body;
2148 IHTMLTxtRange *range;
2149 IHTMLElement *elem;
2150 HRESULT hres;
2152 hres = IHTMLDocument2_get_body(doc, &elem);
2153 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2155 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
2156 IHTMLElement_Release(elem);
2158 hres = IHTMLBodyElement_createTextRange(body, &range);
2159 IHTMLBodyElement_Release(body);
2160 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
2162 return range;
2165 static void test_txtrange(IHTMLDocument2 *doc)
2167 IHTMLTxtRange *body_range, *range, *range2;
2168 IHTMLSelectionObject *selection;
2169 IDispatch *disp_range;
2170 HRESULT hres;
2172 body_range = test_create_body_range(doc);
2174 test_range_text(body_range, "test abc 123\r\nit's text");
2176 hres = IHTMLTxtRange_duplicate(body_range, &range);
2177 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2179 hres = IHTMLTxtRange_duplicate(body_range, &range2);
2180 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2181 test_range_isequal(range, range2, VARIANT_TRUE);
2183 test_range_text(range, "test abc 123\r\nit's text");
2184 test_range_text(body_range, "test abc 123\r\nit's text");
2186 test_range_collapse(range, TRUE);
2187 test_range_isequal(range, range2, VARIANT_FALSE);
2188 test_range_inrange(range, range2, VARIANT_FALSE);
2189 test_range_inrange(range2, range, VARIANT_TRUE);
2190 IHTMLTxtRange_Release(range2);
2192 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2193 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
2194 test_range_move(range, characterW, 2, 2);
2195 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2197 test_range_collapse(range, FALSE);
2198 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
2200 test_range_collapse(range, FALSE);
2201 test_range_expand(range, wordW, VARIANT_TRUE, "123");
2202 test_range_expand(range, wordW, VARIANT_FALSE, "123");
2203 test_range_move(range, characterW, 2, 2);
2204 test_range_expand(range, wordW, VARIANT_TRUE, "123");
2205 test_range_moveend(range, characterW, -5, -5);
2206 test_range_text(range, NULL);
2207 test_range_moveend(range, characterW, 3, 3);
2208 test_range_text(range, "c 1");
2209 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
2210 test_range_collapse(range, TRUE);
2211 test_range_move(range, characterW, 4, 4);
2212 test_range_moveend(range, characterW, 1, 1);
2213 test_range_text(range, " ");
2214 test_range_move(range, wordW, 1, 1);
2215 test_range_moveend(range, characterW, 2, 2);
2216 test_range_text(range, "ab");
2218 IHTMLTxtRange_Release(range);
2220 hres = IHTMLTxtRange_duplicate(body_range, &range);
2221 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2223 test_range_text(range, "test abc 123\r\nit's text");
2224 test_range_move(range, characterW, 3, 3);
2225 test_range_moveend(range, characterW, 1, 1);
2226 test_range_text(range, "t");
2227 test_range_moveend(range, characterW, 3, 3);
2228 test_range_text(range, "t ab");
2229 test_range_moveend(range, characterW, -2, -2);
2230 test_range_text(range, "t ");
2231 test_range_move(range, characterW, 6, 6);
2232 test_range_moveend(range, characterW, 3, 3);
2233 test_range_text(range, "123");
2234 test_range_moveend(range, characterW, 2, 2);
2235 test_range_text(range, "123\r\ni");
2237 IHTMLTxtRange_Release(range);
2239 hres = IHTMLTxtRange_duplicate(body_range, &range);
2240 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2242 test_range_move(range, wordW, 1, 1);
2243 test_range_moveend(range, characterW, 2, 2);
2244 test_range_text(range, "ab");
2246 test_range_move(range, characterW, -2, -2);
2247 test_range_moveend(range, characterW, 2, 2);
2248 test_range_text(range, "t ");
2250 test_range_move(range, wordW, 3, 3);
2251 test_range_move(range, wordW, -2, -2);
2252 test_range_moveend(range, characterW, 2, 2);
2253 test_range_text(range, "ab");
2255 test_range_move(range, characterW, -6, -5);
2256 test_range_moveend(range, characterW, -1, 0);
2257 test_range_moveend(range, characterW, -6, 0);
2258 test_range_move(range, characterW, 2, 2);
2259 test_range_moveend(range, characterW, 2, 2);
2260 test_range_text(range, "st");
2261 test_range_moveend(range, characterW, -6, -4);
2262 test_range_moveend(range, characterW, 2, 2);
2264 IHTMLTxtRange_Release(range);
2266 hres = IHTMLTxtRange_duplicate(body_range, &range);
2267 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2269 test_range_move(range, wordW, 2, 2);
2270 test_range_moveend(range, characterW, 2, 2);
2271 test_range_text(range, "12");
2273 test_range_move(range, characterW, 15, 14);
2274 test_range_move(range, characterW, -2, -2);
2275 test_range_moveend(range, characterW, 3, 2);
2276 test_range_text(range, "t");
2277 test_range_moveend(range, characterW, -1, -1);
2278 test_range_text(range, "t");
2279 test_range_expand(range, wordW, VARIANT_TRUE, "text");
2280 test_range_move(range, characterW, -2, -2);
2281 test_range_moveend(range, characterW, 2, 2);
2282 test_range_text(range, "s ");
2283 test_range_move(range, characterW, 100, 7);
2284 test_range_move(range, wordW, 1, 0);
2285 test_range_move(range, characterW, -2, -2);
2286 test_range_moveend(range, characterW, 3, 2);
2287 test_range_text(range, "t");
2289 IHTMLTxtRange_Release(range);
2291 hres = IHTMLTxtRange_duplicate(body_range, &range);
2292 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
2294 test_range_collapse(range, TRUE);
2295 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
2296 test_range_put_text(range, "word");
2297 test_range_text(body_range, "wordabc 123\r\nit's text");
2298 test_range_text(range, NULL);
2299 test_range_moveend(range, characterW, 3, 3);
2300 test_range_text(range, "abc");
2301 test_range_movestart(range, characterW, -2, -2);
2302 test_range_text(range, "rdabc");
2303 test_range_movestart(range, characterW, 3, 3);
2304 test_range_text(range, "bc");
2305 test_range_movestart(range, characterW, 4, 4);
2306 test_range_text(range, NULL);
2307 test_range_movestart(range, characterW, -3, -3);
2308 test_range_text(range, "c 1");
2309 test_range_movestart(range, characterW, -7, -6);
2310 test_range_text(range, "wordabc 1");
2311 test_range_movestart(range, characterW, 100, 22);
2312 test_range_text(range, NULL);
2314 IHTMLTxtRange_Release(range);
2315 IHTMLTxtRange_Release(body_range);
2317 hres = IHTMLDocument2_get_selection(doc, &selection);
2318 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
2320 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
2321 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
2322 IHTMLSelectionObject_Release(selection);
2324 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
2325 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
2326 IDispatch_Release(disp_range);
2328 test_range_text(range, NULL);
2329 test_range_moveend(range, characterW, 3, 3);
2330 test_range_text(range, "wor");
2331 test_range_parent(range, ET_BODY);
2332 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2333 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
2334 test_range_move(range, characterW, 3, 3);
2335 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
2336 test_range_moveend(range, characterW, -4, -4);
2337 test_range_put_text(range, "abc def ");
2338 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
2339 test_range_move(range, wordW, 1, 1);
2340 test_range_movestart(range, characterW, -1, -1);
2341 test_range_text(range, " ");
2342 test_range_move(range, wordW, 1, 1);
2343 test_range_moveend(range, characterW, 3, 3);
2344 test_range_text(range, "def");
2345 test_range_put_text(range, "xyz");
2346 test_range_moveend(range, characterW, 1, 1);
2347 test_range_move(range, wordW, 1, 1);
2348 test_range_moveend(range, characterW, 2, 2);
2349 test_range_text(range, "ab");
2351 IHTMLTxtRange_Release(range);
2354 static void test_txtrange2(IHTMLDocument2 *doc)
2356 IHTMLTxtRange *range;
2358 range = test_create_body_range(doc);
2360 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
2361 test_range_move(range, characterW, 5, 5);
2362 test_range_moveend(range, characterW, 1, 1);
2363 test_range_text(range, "2");
2364 test_range_move(range, characterW, -3, -3);
2365 test_range_moveend(range, characterW, 3, 3);
2366 test_range_text(range, "c\r\n\r\n1");
2367 test_range_collapse(range, VARIANT_FALSE);
2368 test_range_moveend(range, characterW, 4, 4);
2369 test_range_text(range, "23");
2370 test_range_moveend(range, characterW, 1, 1);
2371 test_range_text(range, "23\r\n\r\n\r\nd");
2372 test_range_moveend(range, characterW, -1, -1);
2373 test_range_text(range, "23");
2374 test_range_moveend(range, characterW, -1, -1);
2375 test_range_text(range, "23");
2376 test_range_moveend(range, characterW, -2, -2);
2377 test_range_text(range, "2");
2379 IHTMLTxtRange_Release(range);
2382 static void test_compatmode(IHTMLDocument2 *doc)
2384 IHTMLDocument5 *doc5;
2385 BSTR mode;
2386 HRESULT hres;
2388 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2389 ok(hres == S_OK, "Could not get IHTMLDocument5 interface: %08x\n", hres);
2390 if(FAILED(hres))
2391 return;
2393 hres = IHTMLDocument5_get_compatMode(doc5, &mode);
2394 IHTMLDocument5_Release(doc5);
2395 ok(hres == S_OK, "get_compatMode failed: %08x\n", hres);
2396 ok(!strcmp_wa(mode, "BackCompat"), "compatMode=%s\n", wine_dbgstr_w(mode));
2397 SysFreeString(mode);
2400 static void test_location(IHTMLDocument2 *doc)
2402 IHTMLLocation *location, *location2;
2403 IHTMLWindow2 *window;
2404 BSTR str;
2405 ULONG ref;
2406 HRESULT hres;
2408 hres = IHTMLDocument2_get_location(doc, &location);
2409 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2411 hres = IHTMLDocument2_get_location(doc, &location2);
2412 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2414 ok(location == location2, "location != location2\n");
2415 IHTMLLocation_Release(location2);
2417 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2418 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2420 hres = IHTMLWindow2_get_location(window, &location2);
2421 ok(hres == S_OK, "get_location failed: %08x\n", hres);
2422 ok(location == location2, "location != location2\n");
2423 IHTMLLocation_Release(location2);
2425 test_ifaces((IUnknown*)location, location_iids);
2426 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
2428 hres = IHTMLLocation_get_pathname(location, &str);
2429 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
2430 ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
2432 hres = IHTMLLocation_get_href(location, NULL);
2433 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
2435 hres = IHTMLLocation_get_href(location, &str);
2436 ok(hres == S_OK, "get_href failed: %08x\n", hres);
2437 ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
2439 ref = IHTMLLocation_Release(location);
2440 ok(!ref, "location chould be destroyed here\n");
2443 static void test_navigator(IHTMLDocument2 *doc)
2445 IHTMLWindow2 *window;
2446 IOmNavigator *navigator, *navigator2;
2447 char buf[512];
2448 DWORD size;
2449 ULONG ref;
2450 BSTR bstr;
2451 HRESULT hres;
2453 static const WCHAR v40[] = {'4','.','0'};
2455 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2456 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
2458 hres = IHTMLWindow2_get_navigator(window, &navigator);
2459 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2460 ok(navigator != NULL, "navigator == NULL\n");
2461 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
2463 hres = IHTMLWindow2_get_navigator(window, &navigator2);
2464 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2465 ok(navigator != navigator2, "navigator2 != navihgator\n");
2467 IHTMLWindow2_Release(window);
2468 IOmNavigator_Release(navigator2);
2470 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
2471 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
2472 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
2473 SysFreeString(bstr);
2475 bstr = NULL;
2476 hres = IOmNavigator_get_appName(navigator, &bstr);
2477 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
2478 ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
2479 SysFreeString(bstr);
2481 bstr = NULL;
2482 hres = IOmNavigator_get_platform(navigator, &bstr);
2483 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
2484 #ifdef _WIN64
2485 ok(!strcmp_wa(bstr, "Win64"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
2486 #else
2487 ok(!strcmp_wa(bstr, "Win32"), "unexpected platform %s\n", wine_dbgstr_w(bstr));
2488 #endif
2489 SysFreeString(bstr);
2491 bstr = NULL;
2492 hres = IOmNavigator_get_appVersion(navigator, &bstr);
2493 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
2494 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
2495 SysFreeString(bstr);
2497 hres = IOmNavigator_toString(navigator, NULL);
2498 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
2500 bstr = NULL;
2501 hres = IOmNavigator_toString(navigator, &bstr);
2502 ok(hres == S_OK, "toString failed: %08x\n", hres);
2503 ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
2504 SysFreeString(bstr);
2506 size = sizeof(buf);
2507 hres = ObtainUserAgentString(0, buf, &size);
2508 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
2510 bstr = NULL;
2511 hres = IOmNavigator_get_userAgent(navigator, &bstr);
2512 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
2513 ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
2514 SysFreeString(bstr);
2516 ref = IOmNavigator_Release(navigator);
2517 ok(!ref, "navigator should be destroyed here\n");
2520 static void test_current_style(IHTMLCurrentStyle *current_style)
2522 BSTR str;
2523 HRESULT hres;
2524 VARIANT v;
2526 test_disp((IUnknown*)current_style, &DIID_DispHTMLCurrentStyle, "[object]");
2527 test_ifaces((IUnknown*)current_style, cstyle_iids);
2529 hres = IHTMLCurrentStyle_get_display(current_style, &str);
2530 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2531 ok(!strcmp_wa(str, "block"), "get_display returned %s\n", wine_dbgstr_w(str));
2532 SysFreeString(str);
2534 hres = IHTMLCurrentStyle_get_position(current_style, &str);
2535 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2536 ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
2537 SysFreeString(str);
2539 hres = IHTMLCurrentStyle_get_fontFamily(current_style, &str);
2540 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2541 SysFreeString(str);
2543 hres = IHTMLCurrentStyle_get_fontStyle(current_style, &str);
2544 ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
2545 ok(!strcmp_wa(str, "normal"), "get_fontStyle returned %s\n", wine_dbgstr_w(str));
2546 SysFreeString(str);
2548 hres = IHTMLCurrentStyle_get_backgroundImage(current_style, &str);
2549 ok(hres == S_OK, "get_backgroundImage failed: %08x\n", hres);
2550 ok(!strcmp_wa(str, "none"), "get_backgroundImage returned %s\n", wine_dbgstr_w(str));
2551 SysFreeString(str);
2553 hres = IHTMLCurrentStyle_get_fontVariant(current_style, &str);
2554 ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
2555 ok(!strcmp_wa(str, "normal"), "get_fontVariant returned %s\n", wine_dbgstr_w(str));
2556 SysFreeString(str);
2558 hres = IHTMLCurrentStyle_get_borderTopStyle(current_style, &str);
2559 ok(hres == S_OK, "get_borderTopStyle failed: %08x\n", hres);
2560 ok(!strcmp_wa(str, "none"), "get_borderTopStyle returned %s\n", wine_dbgstr_w(str));
2561 SysFreeString(str);
2563 hres = IHTMLCurrentStyle_get_borderRightStyle(current_style, &str);
2564 ok(hres == S_OK, "get_borderRightStyle failed: %08x\n", hres);
2565 ok(!strcmp_wa(str, "none"), "get_borderRightStyle returned %s\n", wine_dbgstr_w(str));
2566 SysFreeString(str);
2568 hres = IHTMLCurrentStyle_get_borderBottomStyle(current_style, &str);
2569 ok(hres == S_OK, "get_borderBottomStyle failed: %08x\n", hres);
2570 ok(!strcmp_wa(str, "none"), "get_borderBottomStyle returned %s\n", wine_dbgstr_w(str));
2571 SysFreeString(str);
2573 hres = IHTMLCurrentStyle_get_borderLeftStyle(current_style, &str);
2574 ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
2575 ok(!strcmp_wa(str, "none"), "get_borderLeftStyle returned %s\n", wine_dbgstr_w(str));
2576 SysFreeString(str);
2578 hres = IHTMLCurrentStyle_get_textAlign(current_style, &str);
2579 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
2580 ok(!strcmp_wa(str, "center"), "get_textAlign returned %s\n", wine_dbgstr_w(str));
2581 SysFreeString(str);
2583 hres = IHTMLCurrentStyle_get_textDecoration(current_style, &str);
2584 ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
2585 ok(!strcmp_wa(str, "none"), "get_textDecoration returned %s\n", wine_dbgstr_w(str));
2586 SysFreeString(str);
2588 hres = IHTMLCurrentStyle_get_cursor(current_style, &str);
2589 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
2590 ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
2591 SysFreeString(str);
2593 hres = IHTMLCurrentStyle_get_backgroundRepeat(current_style, &str);
2594 ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
2595 ok(!strcmp_wa(str, "repeat"), "get_backgroundRepeat returned %s\n", wine_dbgstr_w(str));
2596 SysFreeString(str);
2598 hres = IHTMLCurrentStyle_get_borderColor(current_style, &str);
2599 ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
2600 SysFreeString(str);
2602 hres = IHTMLCurrentStyle_get_borderStyle(current_style, &str);
2603 ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
2604 SysFreeString(str);
2606 hres = IHTMLCurrentStyle_get_visibility(current_style, &str);
2607 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2608 SysFreeString(str);
2610 hres = IHTMLCurrentStyle_get_overflow(current_style, &str);
2611 ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
2612 SysFreeString(str);
2614 hres = IHTMLCurrentStyle_get_borderWidth(current_style, &str);
2615 ok(hres == S_OK, "get_borderWidth failed: %08x\n", hres);
2616 SysFreeString(str);
2618 hres = IHTMLCurrentStyle_get_margin(current_style, &str);
2619 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
2620 SysFreeString(str);
2622 hres = IHTMLCurrentStyle_get_fontWeight(current_style, &v);
2623 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2624 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2625 ok( V_I4(&v) == 400, "expect 400 got (%d)\n", V_I4(&v));
2626 VariantClear(&v);
2628 hres = IHTMLCurrentStyle_get_fontSize(current_style, &v);
2629 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2630 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2631 VariantClear(&v);
2633 hres = IHTMLCurrentStyle_get_left(current_style, &v);
2634 ok(hres == S_OK, "get_left failed: %08x\n", hres);
2635 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2636 VariantClear(&v);
2638 hres = IHTMLCurrentStyle_get_top(current_style, &v);
2639 ok(hres == S_OK, "get_top failed: %08x\n", hres);
2640 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2641 VariantClear(&v);
2643 hres = IHTMLCurrentStyle_get_width(current_style, &v);
2644 ok(hres == S_OK, "get_width failed: %08x\n", hres);
2645 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2646 VariantClear(&v);
2648 hres = IHTMLCurrentStyle_get_height(current_style, &v);
2649 ok(hres == S_OK, "get_height failed: %08x\n", hres);
2650 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2651 VariantClear(&v);
2653 hres = IHTMLCurrentStyle_get_paddingLeft(current_style, &v);
2654 ok(hres == S_OK, "get_paddingLeft failed: %08x\n", hres);
2655 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2656 VariantClear(&v);
2658 hres = IHTMLCurrentStyle_get_zIndex(current_style, &v);
2659 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
2660 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2661 ok( V_I4(&v) == 1, "expect 1 got (%d)\n", V_I4(&v));
2662 VariantClear(&v);
2664 hres = IHTMLCurrentStyle_get_verticalAlign(current_style, &v);
2665 ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
2666 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2667 ok(!strcmp_wa(V_BSTR(&v), "middle"), "get_verticalAlign returned %s\n", wine_dbgstr_w(V_BSTR(&v)));
2668 VariantClear(&v);
2670 hres = IHTMLCurrentStyle_get_marginRight(current_style, &v);
2671 ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
2672 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2673 VariantClear(&v);
2675 hres = IHTMLCurrentStyle_get_marginLeft(current_style, &v);
2676 ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
2677 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2678 VariantClear(&v);
2680 hres = IHTMLCurrentStyle_get_borderLeftWidth(current_style, &v);
2681 ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
2682 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2683 VariantClear(&v);
2685 V_BSTR(&v) = NULL;
2686 hres = IHTMLCurrentStyle_get_borderRightWidth(current_style, &v);
2687 ok(hres == S_OK, "get_borderRightWidth failed: %08x\n", hres);
2688 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2689 VariantClear(&v);
2691 hres = IHTMLCurrentStyle_get_borderBottomWidth(current_style, &v);
2692 ok(hres == S_OK, "get_borderBottomWidth failed: %08x\n", hres);
2693 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2694 VariantClear(&v);
2696 hres = IHTMLCurrentStyle_get_borderTopWidth(current_style, &v);
2697 ok(hres == S_OK, "get_borderTopWidth failed: %08x\n", hres);
2698 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2699 VariantClear(&v);
2701 hres = IHTMLCurrentStyle_get_color(current_style, &v);
2702 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2703 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2704 VariantClear(&v);
2706 hres = IHTMLCurrentStyle_get_backgroundColor(current_style, &v);
2707 ok(hres == S_OK, "get_backgroundColor failed: %08x\n", hres);
2708 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2709 VariantClear(&v);
2712 static void test_style2(IHTMLStyle2 *style2)
2714 BSTR str;
2715 HRESULT hres;
2717 str = (void*)0xdeadbeef;
2718 hres = IHTMLStyle2_get_position(style2, &str);
2719 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2720 ok(!str, "str != NULL\n");
2722 str = a2bstr("absolute");
2723 hres = IHTMLStyle2_put_position(style2, str);
2724 ok(hres == S_OK, "put_position failed: %08x\n", hres);
2725 SysFreeString(str);
2727 str = NULL;
2728 hres = IHTMLStyle2_get_position(style2, &str);
2729 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2730 ok(!strcmp_wa(str, "absolute"), "get_position returned %s\n", wine_dbgstr_w(str));
2731 SysFreeString(str);
2734 static void test_style3(IHTMLStyle3 *style3)
2736 BSTR str;
2737 HRESULT hres;
2739 str = (void*)0xdeadbeef;
2740 hres = IHTMLStyle3_get_wordWrap(style3, &str);
2741 ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
2742 ok(!str, "str != NULL\n");
2744 str = a2bstr("break-word");
2745 hres = IHTMLStyle3_put_wordWrap(style3, str);
2746 ok(hres == S_OK, "put_wordWrap failed: %08x\n", hres);
2747 SysFreeString(str);
2749 str = NULL;
2750 hres = IHTMLStyle3_get_wordWrap(style3, &str);
2751 ok(hres == S_OK, "get_wordWrap failed: %08x\n", hres);
2752 ok(!strcmp_wa(str, "break-word"), "get_wordWrap returned %s\n", wine_dbgstr_w(str));
2753 SysFreeString(str);
2756 static void test_style4(IHTMLStyle4 *style4)
2758 HRESULT hres;
2759 VARIANT v;
2760 VARIANT vdefault;
2762 hres = IHTMLStyle4_get_minHeight(style4, &vdefault);
2763 ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
2765 V_VT(&v) = VT_BSTR;
2766 V_BSTR(&v) = a2bstr("10px");
2767 hres = IHTMLStyle4_put_minHeight(style4, v);
2768 ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
2769 VariantClear(&v);
2771 hres = IHTMLStyle4_get_minHeight(style4, &v);
2772 ok(hres == S_OK, "get_minHeight failed: %08x\n", hres);
2773 ok(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
2774 ok( !strcmp_wa(V_BSTR(&v), "10px"), "expect 10px got (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
2776 hres = IHTMLStyle4_put_minHeight(style4, vdefault);
2777 ok(hres == S_OK, "put_minHeight failed: %08x\n", hres);
2778 VariantClear(&vdefault);
2781 static void test_default_style(IHTMLStyle *style)
2783 IHTMLStyle2 *style2;
2784 IHTMLStyle3 *style3;
2785 IHTMLStyle4 *style4;
2786 VARIANT_BOOL b;
2787 VARIANT v;
2788 BSTR str;
2789 HRESULT hres;
2790 float f;
2791 BSTR sOverflowDefault;
2792 BSTR sDefault;
2793 VARIANT vDefault;
2795 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
2796 test_ifaces((IUnknown*)style, style_iids);
2798 test_style_csstext(style, NULL);
2800 hres = IHTMLStyle_get_position(style, &str);
2801 ok(hres == S_OK, "get_position failed: %08x\n", hres);
2802 ok(!str, "str=%s\n", wine_dbgstr_w(str));
2804 V_VT(&v) = VT_NULL;
2805 hres = IHTMLStyle_get_marginRight(style, &v);
2806 ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
2807 ok(V_VT(&v) == VT_BSTR, "V_VT(marginRight) = %d\n", V_VT(&v));
2808 ok(!V_BSTR(&v), "V_BSTR(marginRight) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2810 V_VT(&v) = VT_NULL;
2811 hres = IHTMLStyle_get_marginLeft(style, &v);
2812 ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);
2813 ok(V_VT(&v) == VT_BSTR, "V_VT(marginLeft) = %d\n", V_VT(&v));
2814 ok(!V_BSTR(&v), "V_BSTR(marginLeft) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2816 str = (void*)0xdeadbeef;
2817 hres = IHTMLStyle_get_fontFamily(style, &str);
2818 ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
2819 ok(!str, "fontFamily = %s\n", wine_dbgstr_w(str));
2821 str = (void*)0xdeadbeef;
2822 hres = IHTMLStyle_get_fontWeight(style, &str);
2823 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2824 ok(!str, "fontWeight = %s\n", wine_dbgstr_w(str));
2826 hres = IHTMLStyle_get_fontWeight(style, &sDefault);
2827 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2829 str = a2bstr("test");
2830 hres = IHTMLStyle_put_fontWeight(style, str);
2831 ok(hres == E_INVALIDARG, "put_fontWeight failed: %08x\n", hres);
2832 SysFreeString(str);
2834 str = a2bstr("bold");
2835 hres = IHTMLStyle_put_fontWeight(style, str);
2836 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2837 SysFreeString(str);
2839 str = a2bstr("bolder");
2840 hres = IHTMLStyle_put_fontWeight(style, str);
2841 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2842 SysFreeString(str);
2844 str = a2bstr("lighter");
2845 hres = IHTMLStyle_put_fontWeight(style, str);
2846 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2847 SysFreeString(str);
2849 str = a2bstr("100");
2850 hres = IHTMLStyle_put_fontWeight(style, str);
2851 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2852 SysFreeString(str);
2854 str = a2bstr("200");
2855 hres = IHTMLStyle_put_fontWeight(style, str);
2856 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2857 SysFreeString(str);
2859 str = a2bstr("300");
2860 hres = IHTMLStyle_put_fontWeight(style, str);
2861 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2862 SysFreeString(str);
2864 str = a2bstr("400");
2865 hres = IHTMLStyle_put_fontWeight(style, str);
2866 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2867 SysFreeString(str);
2869 str = a2bstr("500");
2870 hres = IHTMLStyle_put_fontWeight(style, str);
2871 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2872 SysFreeString(str);
2874 str = a2bstr("600");
2875 hres = IHTMLStyle_put_fontWeight(style, str);
2876 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2877 SysFreeString(str);
2879 str = a2bstr("700");
2880 hres = IHTMLStyle_put_fontWeight(style, str);
2881 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2882 SysFreeString(str);
2884 str = a2bstr("800");
2885 hres = IHTMLStyle_put_fontWeight(style, str);
2886 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2887 SysFreeString(str);
2889 str = a2bstr("900");
2890 hres = IHTMLStyle_put_fontWeight(style, str);
2891 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2892 SysFreeString(str);
2894 hres = IHTMLStyle_get_fontWeight(style, &str);
2895 ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
2896 ok(!strcmp_wa(str, "900"), "str != style900\n");
2897 SysFreeString(str);
2899 hres = IHTMLStyle_put_fontWeight(style, sDefault);
2900 ok(hres == S_OK, "put_fontWeight failed: %08x\n", hres);
2901 SysFreeString(sDefault);
2903 /* font Variant */
2904 hres = IHTMLStyle_get_fontVariant(style, NULL);
2905 ok(hres == E_INVALIDARG, "get_fontVariant failed: %08x\n", hres);
2907 hres = IHTMLStyle_get_fontVariant(style, &sDefault);
2908 ok(hres == S_OK, "get_fontVariant failed: %08x\n", hres);
2910 str = a2bstr("test");
2911 hres = IHTMLStyle_put_fontVariant(style, str);
2912 ok(hres == E_INVALIDARG, "fontVariant failed: %08x\n", hres);
2913 SysFreeString(str);
2915 str = a2bstr("small-caps");
2916 hres = IHTMLStyle_put_fontVariant(style, str);
2917 ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
2918 SysFreeString(str);
2920 str = a2bstr("normal");
2921 hres = IHTMLStyle_put_fontVariant(style, str);
2922 ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
2923 SysFreeString(str);
2925 hres = IHTMLStyle_put_fontVariant(style, sDefault);
2926 ok(hres == S_OK, "fontVariant failed: %08x\n", hres);
2927 SysFreeString(sDefault);
2929 str = (void*)0xdeadbeef;
2930 hres = IHTMLStyle_get_display(style, &str);
2931 ok(hres == S_OK, "get_display failed: %08x\n", hres);
2932 ok(!str, "display = %s\n", wine_dbgstr_w(str));
2934 str = (void*)0xdeadbeef;
2935 hres = IHTMLStyle_get_visibility(style, &str);
2936 ok(hres == S_OK, "get_visibility failed: %08x\n", hres);
2937 ok(!str, "visibility = %s\n", wine_dbgstr_w(str));
2939 V_VT(&v) = VT_NULL;
2940 hres = IHTMLStyle_get_fontSize(style, &v);
2941 ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
2942 ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
2943 ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2945 V_VT(&v) = VT_NULL;
2946 hres = IHTMLStyle_get_color(style, &v);
2947 ok(hres == S_OK, "get_color failed: %08x\n", hres);
2948 ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
2949 ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2951 b = 0xfefe;
2952 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2953 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2954 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2956 hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_TRUE);
2957 ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
2958 ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
2960 hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
2961 ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
2962 ok(b == VARIANT_TRUE, "textDecorationUnderline = %x\n", b);
2964 hres = IHTMLStyle_put_textDecorationUnderline(style, VARIANT_FALSE);
2965 ok(hres == S_OK, "put_textDecorationUnderline failed: %08x\n", hres);
2967 b = 0xfefe;
2968 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2969 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2970 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2972 hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_TRUE);
2973 ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
2974 ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
2976 hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
2977 ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
2978 ok(b == VARIANT_TRUE, "textDecorationLineThrough = %x\n", b);
2980 hres = IHTMLStyle_put_textDecorationLineThrough(style, VARIANT_FALSE);
2981 ok(hres == S_OK, "put_textDecorationLineThrough failed: %08x\n", hres);
2983 b = 0xfefe;
2984 hres = IHTMLStyle_get_textDecorationNone(style, &b);
2985 ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
2986 ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
2988 hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_TRUE);
2989 ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
2990 ok(b == VARIANT_FALSE, "textDecorationNone = %x\n", b);
2992 hres = IHTMLStyle_get_textDecorationNone(style, &b);
2993 ok(hres == S_OK, "get_textDecorationNone failed: %08x\n", hres);
2994 ok(b == VARIANT_TRUE, "textDecorationNone = %x\n", b);
2996 hres = IHTMLStyle_put_textDecorationNone(style, VARIANT_FALSE);
2997 ok(hres == S_OK, "put_textDecorationNone failed: %08x\n", hres);
2999 b = 0xfefe;
3000 hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3001 ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3002 ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3004 hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_TRUE);
3005 ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3006 ok(b == VARIANT_FALSE, "textDecorationOverline = %x\n", b);
3008 hres = IHTMLStyle_get_textDecorationOverline(style, &b);
3009 ok(hres == S_OK, "get_textDecorationOverline failed: %08x\n", hres);
3010 ok(b == VARIANT_TRUE, "textDecorationOverline = %x\n", b);
3012 hres = IHTMLStyle_put_textDecorationOverline(style, VARIANT_FALSE);
3013 ok(hres == S_OK, "put_textDecorationOverline failed: %08x\n", hres);
3015 b = 0xfefe;
3016 hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3017 ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3018 ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3020 hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_TRUE);
3021 ok(hres == S_OK, "put_textDecorationBlink failed: %08x\n", hres);
3022 ok(b == VARIANT_FALSE, "textDecorationBlink = %x\n", b);
3024 hres = IHTMLStyle_get_textDecorationBlink(style, &b);
3025 ok(hres == S_OK, "get_textDecorationBlink failed: %08x\n", hres);
3026 ok(b == VARIANT_TRUE, "textDecorationBlink = %x\n", b);
3028 hres = IHTMLStyle_put_textDecorationBlink(style, VARIANT_FALSE);
3029 ok(hres == S_OK, "textDecorationBlink failed: %08x\n", hres);
3031 hres = IHTMLStyle_get_textDecoration(style, &sDefault);
3032 ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3034 str = a2bstr("invalid");
3035 hres = IHTMLStyle_put_textDecoration(style, str);
3036 ok(hres == E_INVALIDARG, "put_textDecoration failed: %08x\n", hres);
3037 SysFreeString(str);
3039 str = a2bstr("none");
3040 hres = IHTMLStyle_put_textDecoration(style, str);
3041 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3042 SysFreeString(str);
3044 str = a2bstr("underline");
3045 hres = IHTMLStyle_put_textDecoration(style, str);
3046 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3047 SysFreeString(str);
3049 str = a2bstr("overline");
3050 hres = IHTMLStyle_put_textDecoration(style, str);
3051 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3052 SysFreeString(str);
3054 str = a2bstr("line-through");
3055 hres = IHTMLStyle_put_textDecoration(style, str);
3056 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3057 SysFreeString(str);
3059 str = a2bstr("blink");
3060 hres = IHTMLStyle_put_textDecoration(style, str);
3061 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3062 SysFreeString(str);
3064 hres = IHTMLStyle_get_textDecoration(style, &str);
3065 ok(hres == S_OK, "get_textDecoration failed: %08x\n", hres);
3066 ok(!strcmp_wa(str, "blink"), "str != blink\n");
3067 SysFreeString(str);
3069 hres = IHTMLStyle_put_textDecoration(style, sDefault);
3070 ok(hres == S_OK, "put_textDecoration failed: %08x\n", hres);
3071 SysFreeString(sDefault);
3073 hres = IHTMLStyle_get_posWidth(style, NULL);
3074 ok(hres == E_POINTER, "get_posWidth failed: %08x\n", hres);
3076 hres = IHTMLStyle_get_posWidth(style, &f);
3077 ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3078 ok(f == 0.0f, "f = %f\n", f);
3080 V_VT(&v) = VT_EMPTY;
3081 hres = IHTMLStyle_get_width(style, &v);
3082 ok(hres == S_OK, "get_width failed: %08x\n", hres);
3083 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3084 ok(!V_BSTR(&v), "V_BSTR(v)=%p\n", V_BSTR(&v));
3086 hres = IHTMLStyle_put_posWidth(style, 2.2);
3087 ok(hres == S_OK, "put_posWidth failed: %08x\n", hres);
3089 hres = IHTMLStyle_get_posWidth(style, &f);
3090 ok(hres == S_OK, "get_posWidth failed: %08x\n", hres);
3091 ok(f == 2.0f ||
3092 f == 2.2f, /* IE8 */
3093 "f = %f\n", f);
3095 V_VT(&v) = VT_BSTR;
3096 V_BSTR(&v) = a2bstr("auto");
3097 hres = IHTMLStyle_put_width(style, v);
3098 ok(hres == S_OK, "put_width failed: %08x\n", hres);
3099 VariantClear(&v);
3101 V_VT(&v) = VT_EMPTY;
3102 hres = IHTMLStyle_get_width(style, &v);
3103 ok(hres == S_OK, "get_width failed: %08x\n", hres);
3104 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3105 ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3106 VariantClear(&v);
3108 /* margin tests */
3109 str = (void*)0xdeadbeef;
3110 hres = IHTMLStyle_get_margin(style, &str);
3111 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3112 ok(!str, "margin = %s\n", wine_dbgstr_w(str));
3114 str = a2bstr("1");
3115 hres = IHTMLStyle_put_margin(style, str);
3116 ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3117 SysFreeString(str);
3119 hres = IHTMLStyle_get_margin(style, &str);
3120 ok(hres == S_OK, "get_margin failed: %08x\n", hres);
3121 ok(!strcmp_wa(str, "1px"), "margin = %s\n", wine_dbgstr_w(str));
3123 hres = IHTMLStyle_put_margin(style, NULL);
3124 ok(hres == S_OK, "put_margin failed: %08x\n", hres);
3126 str = NULL;
3127 hres = IHTMLStyle_get_border(style, &str);
3128 ok(hres == S_OK, "get_border failed: %08x\n", hres);
3129 ok(!str || !*str, "str is not empty\n");
3130 SysFreeString(str);
3132 str = a2bstr("1px");
3133 hres = IHTMLStyle_put_border(style, str);
3134 ok(hres == S_OK, "put_border failed: %08x\n", hres);
3135 SysFreeString(str);
3137 V_VT(&v) = VT_EMPTY;
3138 hres = IHTMLStyle_get_left(style, &v);
3139 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3140 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3141 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3142 VariantClear(&v);
3144 /* Test posLeft */
3145 hres = IHTMLStyle_get_posLeft(style, NULL);
3146 ok(hres == E_POINTER, "get_posLeft failed: %08x\n", hres);
3148 f = 1.0f;
3149 hres = IHTMLStyle_get_posLeft(style, &f);
3150 ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3151 ok(f == 0.0, "expected 0.0 got %f\n", f);
3153 hres = IHTMLStyle_put_posLeft(style, 4.9f);
3154 ok(hres == S_OK, "put_posLeft failed: %08x\n", hres);
3156 hres = IHTMLStyle_get_posLeft(style, &f);
3157 ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3158 ok(f == 4.0 ||
3159 f == 4.9f, /* IE8 */
3160 "expected 4.0 or 4.9 (IE8) got %f\n", f);
3162 /* Ensure left is updated correctly. */
3163 V_VT(&v) = VT_EMPTY;
3164 hres = IHTMLStyle_get_left(style, &v);
3165 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3166 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3167 ok(!strcmp_wa(V_BSTR(&v), "4px") ||
3168 !strcmp_wa(V_BSTR(&v), "4.9px"), /* IE8 */
3169 "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3170 VariantClear(&v);
3172 /* Test left */
3173 V_VT(&v) = VT_BSTR;
3174 V_BSTR(&v) = a2bstr("3px");
3175 hres = IHTMLStyle_put_left(style, v);
3176 ok(hres == S_OK, "put_left failed: %08x\n", hres);
3177 VariantClear(&v);
3179 hres = IHTMLStyle_get_posLeft(style, &f);
3180 ok(hres == S_OK, "get_posLeft failed: %08x\n", hres);
3181 ok(f == 3.0, "expected 3.0 got %f\n", f);
3183 V_VT(&v) = VT_EMPTY;
3184 hres = IHTMLStyle_get_left(style, &v);
3185 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3186 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3187 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3188 VariantClear(&v);
3190 V_VT(&v) = VT_NULL;
3191 hres = IHTMLStyle_put_left(style, v);
3192 ok(hres == S_OK, "put_left failed: %08x\n", hres);
3194 V_VT(&v) = VT_EMPTY;
3195 hres = IHTMLStyle_get_left(style, &v);
3196 ok(hres == S_OK, "get_left failed: %08x\n", hres);
3197 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3198 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3199 VariantClear(&v);
3201 V_VT(&v) = VT_EMPTY;
3202 hres = IHTMLStyle_get_top(style, &v);
3203 ok(hres == S_OK, "get_top failed: %08x\n", hres);
3204 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3205 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3206 VariantClear(&v);
3208 /* Test posTop */
3209 hres = IHTMLStyle_get_posTop(style, NULL);
3210 ok(hres == E_POINTER, "get_posTop failed: %08x\n", hres);
3212 f = 1.0f;
3213 hres = IHTMLStyle_get_posTop(style, &f);
3214 ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3215 ok(f == 0.0, "expected 0.0 got %f\n", f);
3217 hres = IHTMLStyle_put_posTop(style, 4.9f);
3218 ok(hres == S_OK, "put_posTop failed: %08x\n", hres);
3220 hres = IHTMLStyle_get_posTop(style, &f);
3221 ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3222 ok(f == 4.0 ||
3223 f == 4.9f, /* IE8 */
3224 "expected 4.0 or 4.9 (IE8) got %f\n", f);
3226 V_VT(&v) = VT_BSTR;
3227 V_BSTR(&v) = a2bstr("3px");
3228 hres = IHTMLStyle_put_top(style, v);
3229 ok(hres == S_OK, "put_top failed: %08x\n", hres);
3230 VariantClear(&v);
3232 V_VT(&v) = VT_EMPTY;
3233 hres = IHTMLStyle_get_top(style, &v);
3234 ok(hres == S_OK, "get_top failed: %08x\n", hres);
3235 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3236 ok(!strcmp_wa(V_BSTR(&v), "3px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3237 VariantClear(&v);
3239 hres = IHTMLStyle_get_posTop(style, &f);
3240 ok(hres == S_OK, "get_posTop failed: %08x\n", hres);
3241 ok(f == 3.0, "expected 3.0 got %f\n", f);
3243 V_VT(&v) = VT_NULL;
3244 hres = IHTMLStyle_put_top(style, v);
3245 ok(hres == S_OK, "put_top failed: %08x\n", hres);
3247 V_VT(&v) = VT_EMPTY;
3248 hres = IHTMLStyle_get_top(style, &v);
3249 ok(hres == S_OK, "get_top failed: %08x\n", hres);
3250 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3251 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3252 VariantClear(&v);
3254 /* Test posHeight */
3255 hres = IHTMLStyle_get_posHeight(style, NULL);
3256 ok(hres == E_POINTER, "get_posHeight failed: %08x\n", hres);
3258 V_VT(&v) = VT_EMPTY;
3259 hres = IHTMLStyle_get_height(style, &v);
3260 ok(hres == S_OK, "get_height failed: %08x\n", hres);
3261 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3262 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3263 VariantClear(&v);
3265 f = 1.0f;
3266 hres = IHTMLStyle_get_posHeight(style, &f);
3267 ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3268 ok(f == 0.0, "expected 0.0 got %f\n", f);
3270 hres = IHTMLStyle_put_posHeight(style, 4.9f);
3271 ok(hres == S_OK, "put_posHeight failed: %08x\n", hres);
3273 hres = IHTMLStyle_get_posHeight(style, &f);
3274 ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3275 ok(f == 4.0 ||
3276 f == 4.9f, /* IE8 */
3277 "expected 4.0 or 4.9 (IE8) got %f\n", f);
3279 V_VT(&v) = VT_BSTR;
3280 V_BSTR(&v) = a2bstr("64px");
3281 hres = IHTMLStyle_put_height(style, v);
3282 ok(hres == S_OK, "put_height failed: %08x\n", hres);
3283 VariantClear(&v);
3285 V_VT(&v) = VT_EMPTY;
3286 hres = IHTMLStyle_get_height(style, &v);
3287 ok(hres == S_OK, "get_height failed: %08x\n", hres);
3288 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3289 ok(!strcmp_wa(V_BSTR(&v), "64px"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3290 VariantClear(&v);
3292 hres = IHTMLStyle_get_posHeight(style, &f);
3293 ok(hres == S_OK, "get_posHeight failed: %08x\n", hres);
3294 ok(f == 64.0, "expected 64.0 got %f\n", f);
3296 str = (void*)0xdeadbeef;
3297 hres = IHTMLStyle_get_cursor(style, &str);
3298 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
3299 ok(!str, "get_cursor != NULL\n");
3300 SysFreeString(str);
3302 str = a2bstr("default");
3303 hres = IHTMLStyle_put_cursor(style, str);
3304 ok(hres == S_OK, "put_cursor failed: %08x\n", hres);
3305 SysFreeString(str);
3307 str = NULL;
3308 hres = IHTMLStyle_get_cursor(style, &str);
3309 ok(hres == S_OK, "get_cursor failed: %08x\n", hres);
3310 ok(!strcmp_wa(str, "default"), "get_cursor returned %s\n", wine_dbgstr_w(str));
3311 SysFreeString(str);
3313 V_VT(&v) = VT_EMPTY;
3314 hres = IHTMLStyle_get_verticalAlign(style, &v);
3315 ok(hres == S_OK, "get_vertivalAlign failed: %08x\n", hres);
3316 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3317 ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n");
3318 VariantClear(&v);
3320 V_VT(&v) = VT_BSTR;
3321 V_BSTR(&v) = a2bstr("middle");
3322 hres = IHTMLStyle_put_verticalAlign(style, v);
3323 ok(hres == S_OK, "put_vertivalAlign failed: %08x\n", hres);
3324 VariantClear(&v);
3326 V_VT(&v) = VT_EMPTY;
3327 hres = IHTMLStyle_get_verticalAlign(style, &v);
3328 ok(hres == S_OK, "get_verticalAlign failed: %08x\n", hres);
3329 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3330 ok(!strcmp_wa(V_BSTR(&v), "middle"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3331 VariantClear(&v);
3333 str = (void*)0xdeadbeef;
3334 hres = IHTMLStyle_get_textAlign(style, &str);
3335 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
3336 ok(!str, "textAlign != NULL\n");
3338 str = a2bstr("center");
3339 hres = IHTMLStyle_put_textAlign(style, str);
3340 ok(hres == S_OK, "put_textAlign failed: %08x\n", hres);
3341 SysFreeString(str);
3343 str = NULL;
3344 hres = IHTMLStyle_get_textAlign(style, &str);
3345 ok(hres == S_OK, "get_textAlign failed: %08x\n", hres);
3346 ok(!strcmp_wa(str, "center"), "textAlign = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3347 SysFreeString(str);
3349 str = (void*)0xdeadbeef;
3350 hres = IHTMLStyle_get_filter(style, &str);
3351 ok(hres == S_OK, "get_filter failed: %08x\n", hres);
3352 ok(!str, "filter != NULL\n");
3354 str = a2bstr("alpha(opacity=100)");
3355 hres = IHTMLStyle_put_filter(style, str);
3356 ok(hres == S_OK, "put_filter failed: %08x\n", hres);
3357 SysFreeString(str);
3359 V_VT(&v) = VT_EMPTY;
3360 hres = IHTMLStyle_get_zIndex(style, &v);
3361 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
3362 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
3363 ok(!V_I4(&v), "V_I4(v) != 0\n");
3364 VariantClear(&v);
3366 V_VT(&v) = VT_BSTR;
3367 V_BSTR(&v) = a2bstr("1");
3368 hres = IHTMLStyle_put_zIndex(style, v);
3369 ok(hres == S_OK, "put_zIndex failed: %08x\n", hres);
3370 VariantClear(&v);
3372 V_VT(&v) = VT_EMPTY;
3373 hres = IHTMLStyle_get_zIndex(style, &v);
3374 ok(hres == S_OK, "get_zIndex failed: %08x\n", hres);
3375 ok(V_VT(&v) == VT_I4, "V_VT(v)=%d\n", V_VT(&v));
3376 ok(V_I4(&v) == 1, "V_I4(v) = %d\n", V_I4(&v));
3377 VariantClear(&v);
3379 /* fontStyle */
3380 hres = IHTMLStyle_get_fontStyle(style, &sDefault);
3381 ok(hres == S_OK, "get_fontStyle failed: %08x\n", hres);
3383 str = a2bstr("test");
3384 hres = IHTMLStyle_put_fontStyle(style, str);
3385 ok(hres == E_INVALIDARG, "put_fontStyle failed: %08x\n", hres);
3386 SysFreeString(str);
3388 str = a2bstr("italic");
3389 hres = IHTMLStyle_put_fontStyle(style, str);
3390 ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3391 SysFreeString(str);
3393 str = a2bstr("oblique");
3394 hres = IHTMLStyle_put_fontStyle(style, str);
3395 ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3396 SysFreeString(str);
3398 str = a2bstr("normal");
3399 hres = IHTMLStyle_put_fontStyle(style, str);
3400 ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3401 SysFreeString(str);
3403 hres = IHTMLStyle_put_fontStyle(style, sDefault);
3404 ok(hres == S_OK, "put_fontStyle failed: %08x\n", hres);
3405 SysFreeString(sDefault);
3407 /* overflow */
3408 hres = IHTMLStyle_get_overflow(style, NULL);
3409 ok(hres == E_INVALIDARG, "get_overflow failed: %08x\n", hres);
3411 hres = IHTMLStyle_get_overflow(style, &sOverflowDefault);
3412 ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3414 str = a2bstr("test");
3415 hres = IHTMLStyle_put_overflow(style, str);
3416 ok(hres == E_INVALIDARG, "put_overflow failed: %08x\n", hres);
3417 SysFreeString(str);
3419 str = a2bstr("visible");
3420 hres = IHTMLStyle_put_overflow(style, str);
3421 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3422 SysFreeString(str);
3424 str = a2bstr("scroll");
3425 hres = IHTMLStyle_put_overflow(style, str);
3426 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3427 SysFreeString(str);
3429 str = a2bstr("hidden");
3430 hres = IHTMLStyle_put_overflow(style, str);
3431 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3432 SysFreeString(str);
3434 str = a2bstr("auto");
3435 hres = IHTMLStyle_put_overflow(style, str);
3436 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3437 SysFreeString(str);
3439 hres = IHTMLStyle_get_overflow(style, &str);
3440 ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3441 ok(!strcmp_wa(str, "auto"), "str=%s\n", wine_dbgstr_w(str));
3442 SysFreeString(str);
3444 str = a2bstr("");
3445 hres = IHTMLStyle_put_overflow(style, str);
3446 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3447 SysFreeString(str);
3449 hres = IHTMLStyle_get_overflow(style, &str);
3450 ok(hres == S_OK, "get_overflow failed: %08x\n", hres);
3451 ok(!str, "str=%s\n", wine_dbgstr_w(str));
3452 SysFreeString(str);
3454 /* restore overflow default */
3455 hres = IHTMLStyle_put_overflow(style, sOverflowDefault);
3456 ok(hres == S_OK, "put_overflow failed: %08x\n", hres);
3457 SysFreeString(sOverflowDefault);
3459 /* Attribute Tests*/
3460 hres = IHTMLStyle_getAttribute(style, NULL, 1, &v);
3461 ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
3463 str = a2bstr("position");
3464 hres = IHTMLStyle_getAttribute(style, str, 1, NULL);
3465 ok(hres == E_INVALIDARG, "getAttribute failed: %08x\n", hres);
3467 hres = IHTMLStyle_getAttribute(style, str, 1, &v);
3468 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
3469 ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3470 VariantClear(&v);
3472 hres = IHTMLStyle_setAttribute(style, NULL, v, 1);
3473 ok(hres == E_INVALIDARG, "setAttribute failed: %08x\n", hres);
3475 V_VT(&v) = VT_BSTR;
3476 V_BSTR(&v) = a2bstr("absolute");
3477 hres = IHTMLStyle_setAttribute(style, str, v, 1);
3478 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3479 VariantClear(&v);
3481 hres = IHTMLStyle_getAttribute(style, str, 1, &v);
3482 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
3483 ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3484 ok(!strcmp_wa(V_BSTR(&v), "absolute"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3485 VariantClear(&v);
3487 V_VT(&v) = VT_BSTR;
3488 V_BSTR(&v) = NULL;
3489 hres = IHTMLStyle_setAttribute(style, str, v, 1);
3490 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3491 VariantClear(&v);
3493 SysFreeString(str);
3495 str = a2bstr("borderLeftStyle");
3496 test_border_styles(style, str);
3497 SysFreeString(str);
3499 str = a2bstr("borderbottomstyle");
3500 test_border_styles(style, str);
3501 SysFreeString(str);
3503 str = a2bstr("borderrightstyle");
3504 test_border_styles(style, str);
3505 SysFreeString(str);
3507 str = a2bstr("bordertopstyle");
3508 test_border_styles(style, str);
3509 SysFreeString(str);
3511 hres = IHTMLStyle_get_borderStyle(style, &sDefault);
3512 ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
3514 str = a2bstr("none dotted dashed solid");
3515 hres = IHTMLStyle_put_borderStyle(style, str);
3516 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3517 SysFreeString(str);
3519 str = a2bstr("none dotted dashed solid");
3520 hres = IHTMLStyle_get_borderStyle(style, &str);
3521 ok(hres == S_OK, "get_borderStyle failed: %08x\n", hres);
3522 ok(!strcmp_wa(str, "none dotted dashed solid"),
3523 "expected (none dotted dashed solid) = (%s)\n", wine_dbgstr_w(V_BSTR(&v)));
3524 SysFreeString(str);
3526 str = a2bstr("double groove ridge inset");
3527 hres = IHTMLStyle_put_borderStyle(style, str);
3528 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3529 SysFreeString(str);
3531 str = a2bstr("window-inset outset ridge inset");
3532 hres = IHTMLStyle_put_borderStyle(style, str);
3533 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3534 SysFreeString(str);
3536 str = a2bstr("window-inset");
3537 hres = IHTMLStyle_put_borderStyle(style, str);
3538 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3539 SysFreeString(str);
3541 str = a2bstr("none none none none none");
3542 hres = IHTMLStyle_put_borderStyle(style, str);
3543 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3544 SysFreeString(str);
3546 str = a2bstr("invalid none none none");
3547 hres = IHTMLStyle_put_borderStyle(style, str);
3548 ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
3549 SysFreeString(str);
3551 str = a2bstr("none invalid none none");
3552 hres = IHTMLStyle_put_borderStyle(style, str);
3553 ok(hres == E_INVALIDARG, "put_borderStyle failed: %08x\n", hres);
3554 SysFreeString(str);
3556 hres = IHTMLStyle_put_borderStyle(style, sDefault);
3557 ok(hres == S_OK, "put_borderStyle failed: %08x\n", hres);
3558 SysFreeString(sDefault);
3560 /* backgoundColor */
3561 hres = IHTMLStyle_get_backgroundColor(style, &v);
3562 ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
3563 ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3564 ok(!V_BSTR(&v), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3565 VariantClear(&v);
3567 /* PaddingLeft */
3568 hres = IHTMLStyle_get_paddingLeft(style, &vDefault);
3569 ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
3571 V_VT(&v) = VT_BSTR;
3572 V_BSTR(&v) = a2bstr("10");
3573 hres = IHTMLStyle_put_paddingLeft(style, v);
3574 ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
3575 VariantClear(&v);
3577 hres = IHTMLStyle_get_paddingLeft(style, &v);
3578 ok(hres == S_OK, "get_paddingLeft: %08x\n", hres);
3579 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expecte 10 = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3581 hres = IHTMLStyle_put_paddingLeft(style, vDefault);
3582 ok(hres == S_OK, "put_paddingLeft: %08x\n", hres);
3584 /* BackgroundRepeat */
3585 hres = IHTMLStyle_get_backgroundRepeat(style, &sDefault);
3586 ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
3588 str = a2bstr("invalid");
3589 hres = IHTMLStyle_put_backgroundRepeat(style, str);
3590 ok(hres == E_INVALIDARG, "put_backgroundRepeat failed: %08x\n", hres);
3591 SysFreeString(str);
3593 str = a2bstr("repeat");
3594 hres = IHTMLStyle_put_backgroundRepeat(style, str);
3595 ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3596 SysFreeString(str);
3598 str = a2bstr("no-repeat");
3599 hres = IHTMLStyle_put_backgroundRepeat(style, str);
3600 ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3601 SysFreeString(str);
3603 str = a2bstr("repeat-x");
3604 hres = IHTMLStyle_put_backgroundRepeat(style, str);
3605 ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3606 SysFreeString(str);
3608 str = a2bstr("repeat-y");
3609 hres = IHTMLStyle_put_backgroundRepeat(style, str);
3610 ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3611 SysFreeString(str);
3613 hres = IHTMLStyle_get_backgroundRepeat(style, &str);
3614 ok(hres == S_OK, "get_backgroundRepeat failed: %08x\n", hres);
3615 ok(!strcmp_wa(str, "repeat-y"), "str=%s\n", wine_dbgstr_w(str));
3616 SysFreeString(str);
3618 hres = IHTMLStyle_put_backgroundRepeat(style, sDefault);
3619 ok(hres == S_OK, "put_backgroundRepeat failed: %08x\n", hres);
3620 SysFreeString(sDefault);
3622 /* BorderColor */
3623 hres = IHTMLStyle_get_borderColor(style, &sDefault);
3624 ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
3626 str = a2bstr("red green red blue");
3627 hres = IHTMLStyle_put_borderColor(style, str);
3628 ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
3629 SysFreeString(str);
3631 hres = IHTMLStyle_get_borderColor(style, &str);
3632 ok(hres == S_OK, "get_borderColor failed: %08x\n", hres);
3633 ok(!strcmp_wa(str, "red green red blue"), "str=%s\n", wine_dbgstr_w(str));
3634 SysFreeString(str);
3636 hres = IHTMLStyle_put_borderColor(style, sDefault);
3637 ok(hres == S_OK, "put_borderColor failed: %08x\n", hres);
3638 SysFreeString(sDefault);
3640 /* BorderLeft */
3641 hres = IHTMLStyle_get_borderLeft(style, &sDefault);
3642 ok(hres == S_OK, "get_borderLeft failed: %08x\n", hres);
3644 str = a2bstr("thick dotted red");
3645 hres = IHTMLStyle_put_borderLeft(style, str);
3646 ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
3647 SysFreeString(str);
3649 /* IHTMLStyle_get_borderLeft appears to have a bug where
3650 it returns the first letter of the color. So we check
3651 each style individually.
3653 V_BSTR(&v) = NULL;
3654 hres = IHTMLStyle_get_borderLeftColor(style, &v);
3655 todo_wine ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
3656 todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3657 VariantClear(&v);
3659 V_BSTR(&v) = NULL;
3660 hres = IHTMLStyle_get_borderLeftWidth(style, &v);
3661 ok(hres == S_OK, "get_borderLeftWidth failed: %08x\n", hres);
3662 ok(!strcmp_wa(V_BSTR(&v), "thick"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3663 VariantClear(&v);
3665 hres = IHTMLStyle_get_borderLeftStyle(style, &str);
3666 ok(hres == S_OK, "get_borderLeftStyle failed: %08x\n", hres);
3667 ok(!strcmp_wa(str, "dotted"), "str=%s\n", wine_dbgstr_w(str));
3668 SysFreeString(str);
3670 hres = IHTMLStyle_put_borderLeft(style, sDefault);
3671 ok(hres == S_OK, "put_borderLeft failed: %08x\n", hres);
3672 SysFreeString(sDefault);
3674 /* backgroundPositionX */
3675 hres = IHTMLStyle_get_backgroundPositionX(style, &vDefault);
3676 ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
3678 V_VT(&v) = VT_BSTR;
3679 V_BSTR(&v) = a2bstr("10px");
3680 hres = IHTMLStyle_put_backgroundPositionX(style, v);
3681 ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
3682 VariantClear(&v);
3684 hres = IHTMLStyle_get_backgroundPositionX(style, &v);
3685 ok(hres == S_OK, "get_backgroundPositionX failed: %08x\n", hres);
3686 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3687 VariantClear(&v);
3689 hres = IHTMLStyle_put_backgroundPositionX(style, vDefault);
3690 ok(hres == S_OK, "put_backgroundPositionX failed: %08x\n", hres);
3691 VariantClear(&vDefault);
3693 /* backgroundPositionY */
3694 hres = IHTMLStyle_get_backgroundPositionY(style, &vDefault);
3695 ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
3697 V_VT(&v) = VT_BSTR;
3698 V_BSTR(&v) = a2bstr("10px");
3699 hres = IHTMLStyle_put_backgroundPositionY(style, v);
3700 ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
3701 VariantClear(&v);
3703 hres = IHTMLStyle_get_backgroundPositionY(style, &v);
3704 ok(hres == S_OK, "get_backgroundPositionY failed: %08x\n", hres);
3705 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3706 VariantClear(&v);
3708 hres = IHTMLStyle_put_backgroundPositionY(style, vDefault);
3709 ok(hres == S_OK, "put_backgroundPositionY failed: %08x\n", hres);
3710 VariantClear(&vDefault);
3712 /* borderTopWidth */
3713 hres = IHTMLStyle_get_borderTopWidth(style, &vDefault);
3714 ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
3716 V_VT(&v) = VT_BSTR;
3717 V_BSTR(&v) = a2bstr("10px");
3718 hres = IHTMLStyle_put_borderTopWidth(style, v);
3719 ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
3720 VariantClear(&v);
3722 hres = IHTMLStyle_get_borderTopWidth(style, &v);
3723 ok(hres == S_OK, "get_borderTopWidth: %08x\n", hres);
3724 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3725 VariantClear(&v);
3727 hres = IHTMLStyle_put_borderTopWidth(style, vDefault);
3728 ok(hres == S_OK, "put_borderTopWidth: %08x\n", hres);
3729 VariantClear(&vDefault);
3731 /* borderRightWidth */
3732 hres = IHTMLStyle_get_borderRightWidth(style, &vDefault);
3733 ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
3735 V_VT(&v) = VT_BSTR;
3736 V_BSTR(&v) = a2bstr("10");
3737 hres = IHTMLStyle_put_borderRightWidth(style, v);
3738 ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
3739 VariantClear(&v);
3741 hres = IHTMLStyle_get_borderRightWidth(style, &v);
3742 ok(hres == S_OK, "get_borderRightWidth: %08x\n", hres);
3743 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3744 VariantClear(&v);
3746 hres = IHTMLStyle_put_borderRightWidth(style, vDefault);
3747 ok(hres == S_OK, "put_borderRightWidth: %08x\n", hres);
3748 VariantClear(&vDefault);
3750 /* borderBottomWidth */
3751 hres = IHTMLStyle_get_borderBottomWidth(style, &vDefault);
3752 ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
3754 V_VT(&v) = VT_BSTR;
3755 V_BSTR(&v) = a2bstr("10");
3756 hres = IHTMLStyle_put_borderBottomWidth(style, v);
3757 ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
3758 VariantClear(&v);
3760 hres = IHTMLStyle_get_borderBottomWidth(style, &v);
3761 ok(hres == S_OK, "get_borderBottomWidth: %08x\n", hres);
3762 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3763 VariantClear(&v);
3765 hres = IHTMLStyle_put_borderBottomWidth(style, vDefault);
3766 ok(hres == S_OK, "put_borderBottomWidth: %08x\n", hres);
3767 VariantClear(&vDefault);
3769 /* borderLeftWidth */
3770 hres = IHTMLStyle_get_borderLeftWidth(style, &vDefault);
3771 ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
3773 V_VT(&v) = VT_BSTR;
3774 V_BSTR(&v) = a2bstr("10");
3775 hres = IHTMLStyle_put_borderLeftWidth(style, v);
3776 ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
3777 VariantClear(&v);
3779 hres = IHTMLStyle_get_borderLeftWidth(style, &v);
3780 ok(hres == S_OK, "get_borderLeftWidth: %08x\n", hres);
3781 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3782 VariantClear(&v);
3784 hres = IHTMLStyle_put_borderLeftWidth(style, vDefault);
3785 ok(hres == S_OK, "put_borderLeftWidth: %08x\n", hres);
3786 VariantClear(&vDefault);
3788 /* wordSpacing */
3789 hres = IHTMLStyle_get_wordSpacing(style, &vDefault);
3790 ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
3792 V_VT(&v) = VT_BSTR;
3793 V_BSTR(&v) = a2bstr("10");
3794 hres = IHTMLStyle_put_wordSpacing(style, v);
3795 ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
3796 VariantClear(&v);
3798 hres = IHTMLStyle_get_wordSpacing(style, &v);
3799 ok(hres == S_OK, "get_wordSpacing: %08x\n", hres);
3800 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3801 ok(!strcmp_wa(V_BSTR(&v), "10px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3802 VariantClear(&v);
3804 hres = IHTMLStyle_put_wordSpacing(style, vDefault);
3805 ok(hres == S_OK, "put_wordSpacing: %08x\n", hres);
3806 VariantClear(&vDefault);
3808 /* letterSpacing */
3809 hres = IHTMLStyle_get_letterSpacing(style, &vDefault);
3810 ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
3812 V_VT(&v) = VT_BSTR;
3813 V_BSTR(&v) = a2bstr("11");
3814 hres = IHTMLStyle_put_letterSpacing(style, v);
3815 ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
3816 VariantClear(&v);
3818 hres = IHTMLStyle_get_letterSpacing(style, &v);
3819 ok(hres == S_OK, "get_letterSpacing: %08x\n", hres);
3820 ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
3821 ok(!strcmp_wa(V_BSTR(&v), "11px"), "expected 10px = %s\n", wine_dbgstr_w(V_BSTR(&v)));
3822 VariantClear(&v);
3824 hres = IHTMLStyle_put_letterSpacing(style, vDefault);
3825 ok(hres == S_OK, "put_letterSpacing: %08x\n", hres);
3826 VariantClear(&vDefault);
3828 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle2, (void**)&style2);
3829 ok(hres == S_OK, "Could not get IHTMLStyle2 iface: %08x\n", hres);
3830 if(SUCCEEDED(hres)) {
3831 test_style2(style2);
3832 IHTMLStyle2_Release(style2);
3835 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle3, (void**)&style3);
3836 ok(hres == S_OK, "Could not get IHTMLStyle3 iface: %08x\n", hres);
3837 if(SUCCEEDED(hres)) {
3838 test_style3(style3);
3839 IHTMLStyle3_Release(style3);
3842 hres = IHTMLStyle_QueryInterface(style, &IID_IHTMLStyle4, (void**)&style4);
3843 ok(hres == S_OK, "Could not get IHTMLStyle4 iface: %08x\n", hres);
3844 if(SUCCEEDED(hres)) {
3845 test_style4(style4);
3846 IHTMLStyle4_Release(style4);
3850 static void test_set_csstext(IHTMLStyle *style)
3852 VARIANT v;
3853 HRESULT hres;
3855 test_style_set_csstext(style, "background-color: black;");
3857 hres = IHTMLStyle_get_backgroundColor(style, &v);
3858 ok(hres == S_OK, "get_backgroundColor: %08x\n", hres);
3859 ok(V_VT(&v) == VT_BSTR, "type failed: %d\n", V_VT(&v));
3860 ok(!strcmp_wa(V_BSTR(&v), "black"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
3861 VariantClear(&v);
3864 static void test_default_selection(IHTMLDocument2 *doc)
3866 IHTMLSelectionObject *selection;
3867 IHTMLTxtRange *range;
3868 IDispatch *disp;
3869 BSTR str;
3870 HRESULT hres;
3872 hres = IHTMLDocument2_get_selection(doc, &selection);
3873 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
3875 hres = IHTMLSelectionObject_get_type(selection, &str);
3876 ok(hres == S_OK, "get_type failed: %08x\n", hres);
3877 ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
3878 SysFreeString(str);
3880 hres = IHTMLSelectionObject_createRange(selection, &disp);
3881 IHTMLSelectionObject_Release(selection);
3882 ok(hres == S_OK, "createRange failed: %08x\n", hres);
3884 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
3885 IDispatch_Release(disp);
3886 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
3888 test_range_text(range, NULL);
3889 IHTMLTxtRange_Release(range);
3892 static void test_default_body(IHTMLBodyElement *body)
3894 LONG l;
3895 BSTR bstr;
3896 HRESULT hres;
3897 VARIANT v;
3898 WCHAR sBodyText[] = {'#','F','F','0','0','0','0',0};
3899 WCHAR sTextInvalid[] = {'I','n','v','a','l','i','d',0};
3901 bstr = (void*)0xdeadbeef;
3902 hres = IHTMLBodyElement_get_background(body, &bstr);
3903 ok(hres == S_OK, "get_background failed: %08x\n", hres);
3904 ok(bstr == NULL, "bstr != NULL\n");
3906 l = elem_get_scroll_height((IUnknown*)body);
3907 ok(l != -1, "scrollHeight == -1\n");
3908 l = elem_get_scroll_width((IUnknown*)body);
3909 ok(l != -1, "scrollWidth == -1\n");
3910 l = elem_get_scroll_top((IUnknown*)body);
3911 ok(!l, "scrollTop = %d\n", l);
3912 elem_get_scroll_left((IUnknown*)body);
3914 /* get_text tests */
3915 hres = IHTMLBodyElement_get_text(body, &v);
3916 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
3917 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
3918 ok(bstr == NULL, "bstr != NULL\n");
3921 /* get_text - Invalid Text */
3922 V_VT(&v) = VT_BSTR;
3923 V_BSTR(&v) = SysAllocString(sTextInvalid);
3924 hres = IHTMLBodyElement_put_text(body, v);
3925 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
3926 VariantClear(&v);
3928 V_VT(&v) = VT_NULL;
3929 hres = IHTMLBodyElement_get_text(body, &v);
3930 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
3931 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
3932 ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v != '#00a0d0'\n");
3933 VariantClear(&v);
3935 /* get_text - Valid Text */
3936 V_VT(&v) = VT_BSTR;
3937 V_BSTR(&v) = SysAllocString(sBodyText);
3938 hres = IHTMLBodyElement_put_text(body, v);
3939 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
3940 VariantClear(&v);
3942 V_VT(&v) = VT_NULL;
3943 hres = IHTMLBodyElement_get_text(body, &v);
3944 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
3945 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
3946 ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v != '#ff0000'\n");
3947 VariantClear(&v);
3950 static void test_body_funs(IHTMLBodyElement *body)
3952 static WCHAR sRed[] = {'r','e','d',0};
3953 VARIANT vbg;
3954 VARIANT vDefaultbg;
3955 HRESULT hres;
3957 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
3958 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
3959 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
3961 V_VT(&vbg) = VT_BSTR;
3962 V_BSTR(&vbg) = SysAllocString(sRed);
3963 hres = IHTMLBodyElement_put_bgColor(body, vbg);
3964 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
3965 VariantClear(&vbg);
3967 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
3968 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
3969 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
3970 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
3971 VariantClear(&vbg);
3973 /* Restore Originial */
3974 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
3975 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
3976 VariantClear(&vDefaultbg);
3979 static void test_window(IHTMLDocument2 *doc)
3981 IHTMLWindow2 *window, *window2, *self;
3982 IHTMLDocument2 *doc2 = NULL;
3983 IDispatch *disp;
3984 BSTR str;
3985 HRESULT hres;
3987 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3988 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3989 test_ifaces((IUnknown*)window, window_iids);
3990 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
3992 hres = IHTMLWindow2_get_document(window, &doc2);
3993 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3994 ok(doc2 != NULL, "doc2 == NULL\n");
3996 IHTMLDocument_Release(doc2);
3998 hres = IHTMLWindow2_get_window(window, &window2);
3999 ok(hres == S_OK, "get_window failed: %08x\n", hres);
4000 ok(window2 != NULL, "window2 == NULL\n");
4002 hres = IHTMLWindow2_get_self(window, &self);
4003 ok(hres == S_OK, "get_self failed: %08x\n", hres);
4004 ok(window2 != NULL, "self == NULL\n");
4006 ok(self == window2, "self != window2\n");
4008 IHTMLWindow2_Release(window2);
4009 IHTMLWindow2_Release(self);
4011 disp = NULL;
4012 hres = IHTMLDocument2_get_Script(doc, &disp);
4013 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4014 ok(disp == (void*)window, "disp != window\n");
4015 IDispatch_Release(disp);
4017 hres = IHTMLWindow2_toString(window, NULL);
4018 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
4020 str = NULL;
4021 hres = IHTMLWindow2_toString(window, &str);
4022 ok(hres == S_OK, "toString failed: %08x\n", hres);
4023 ok(!strcmp_wa(str, "[object]"), "toString returned %s\n", wine_dbgstr_w(str));
4024 SysFreeString(str);
4026 IHTMLWindow2_Release(window);
4029 static void test_defaults(IHTMLDocument2 *doc)
4031 IHTMLStyleSheetsCollection *stylesheetcol;
4032 IHTMLCurrentStyle *cstyle;
4033 IHTMLBodyElement *body;
4034 IHTMLElement2 *elem2;
4035 IHTMLElement *elem;
4036 IHTMLStyle *style;
4037 LONG l;
4038 HRESULT hres;
4039 IHTMLElementCollection *collection;
4041 hres = IHTMLDocument2_get_body(doc, &elem);
4042 ok(hres == S_OK, "get_body failed: %08x\n", hres);
4044 hres = IHTMLDocument2_get_images(doc, NULL);
4045 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4047 hres = IHTMLDocument2_get_images(doc, &collection);
4048 ok(hres == S_OK, "get_images failed: %08x\n", hres);
4049 if(hres == S_OK)
4051 test_elem_collection((IUnknown*)collection, NULL, 0);
4052 IHTMLElementCollection_Release(collection);
4055 hres = IHTMLDocument2_get_applets(doc, NULL);
4056 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4058 hres = IHTMLDocument2_get_applets(doc, &collection);
4059 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
4060 if(hres == S_OK)
4062 test_elem_collection((IUnknown*)collection, NULL, 0);
4063 IHTMLElementCollection_Release(collection);
4066 hres = IHTMLDocument2_get_links(doc, NULL);
4067 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4069 hres = IHTMLDocument2_get_links(doc, &collection);
4070 ok(hres == S_OK, "get_links failed: %08x\n", hres);
4071 if(hres == S_OK)
4073 test_elem_collection((IUnknown*)collection, NULL, 0);
4074 IHTMLElementCollection_Release(collection);
4077 hres = IHTMLDocument2_get_forms(doc, NULL);
4078 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4080 hres = IHTMLDocument2_get_forms(doc, &collection);
4081 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
4082 if(hres == S_OK)
4084 test_elem_collection((IUnknown*)collection, NULL, 0);
4085 IHTMLElementCollection_Release(collection);
4088 hres = IHTMLDocument2_get_anchors(doc, NULL);
4089 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
4091 hres = IHTMLDocument2_get_anchors(doc, &collection);
4092 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4093 if(hres == S_OK)
4095 test_elem_collection((IUnknown*)collection, NULL, 0);
4096 IHTMLElementCollection_Release(collection);
4099 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4100 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
4101 test_default_body(body);
4102 test_body_funs(body);
4103 IHTMLBodyElement_Release(body);
4105 hres = IHTMLElement_get_style(elem, &style);
4106 ok(hres == S_OK, "get_style failed: %08x\n", hres);
4108 test_default_style(style);
4109 test_window(doc);
4110 test_compatmode(doc);
4111 test_location(doc);
4112 test_navigator(doc);
4114 elem2 = get_elem2_iface((IUnknown*)elem);
4115 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
4116 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
4117 if(SUCCEEDED(hres)) {
4118 test_current_style(cstyle);
4119 IHTMLCurrentStyle_Release(cstyle);
4121 IHTMLElement2_Release(elem2);
4123 IHTMLElement_Release(elem);
4125 test_set_csstext(style);
4126 IHTMLStyle_Release(style);
4128 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
4129 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4131 l = 0xdeadbeef;
4132 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
4133 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4134 ok(l == 0, "length = %d\n", l);
4136 IHTMLStyleSheetsCollection_Release(stylesheetcol);
4138 test_default_selection(doc);
4139 test_doc_title(doc, "");
4142 static void test_tr_elem(IHTMLElement *elem)
4144 IHTMLElementCollection *col;
4145 IHTMLTableRow *row;
4146 HRESULT hres;
4148 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
4150 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
4151 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
4152 if(FAILED(hres))
4153 return;
4155 col = NULL;
4156 hres = IHTMLTableRow_get_cells(row, &col);
4157 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
4158 ok(col != NULL, "get_cells returned NULL\n");
4160 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
4161 IHTMLElementCollection_Release(col);
4163 IHTMLTable_Release(row);
4166 static void test_table_elem(IHTMLElement *elem)
4168 IHTMLElementCollection *col;
4169 IHTMLTable *table;
4170 HRESULT hres;
4172 static const elem_type_t row_types[] = {ET_TR,ET_TR};
4174 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
4175 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
4176 if(FAILED(hres))
4177 return;
4179 col = NULL;
4180 hres = IHTMLTable_get_rows(table, &col);
4181 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
4182 ok(col != NULL, "get_ros returned NULL\n");
4184 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
4185 IHTMLElementCollection_Release(col);
4187 IHTMLTable_Release(table);
4190 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
4192 SAFEARRAYBOUND dim;
4193 SAFEARRAY *sa;
4194 VARIANT *var;
4195 BSTR str;
4196 HRESULT hres;
4198 dim.lLbound = 0;
4199 dim.cElements = 1;
4200 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
4201 SafeArrayAccessData(sa, (void**)&var);
4202 V_VT(var) = VT_BSTR;
4203 V_BSTR(var) = str = a2bstr(text);
4204 SafeArrayUnaccessData(sa);
4206 if(ln)
4207 hres = IHTMLDocument2_writeln(doc, sa);
4208 else
4209 hres = IHTMLDocument2_write(doc, sa);
4210 ok(hres == S_OK, "write failed: %08x\n", hres);
4212 SysFreeString(str);
4213 SafeArrayDestroy(sa);
4216 static void test_iframe_elem(IHTMLElement *elem)
4218 IHTMLElementCollection *col;
4219 IHTMLDocument2 *content_doc;
4220 IHTMLWindow2 *content_window;
4221 IHTMLFrameBase2 *base2;
4222 IDispatch *disp;
4223 VARIANT errv;
4224 BSTR str;
4225 HRESULT hres;
4227 static const elem_type_t all_types[] = {
4228 ET_HTML,
4229 ET_HEAD,
4230 ET_TITLE,
4231 ET_BODY,
4232 ET_BR
4235 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
4236 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
4237 if (!base2) return;
4239 content_window = NULL;
4240 hres = IHTMLFrameBase2_get_contentWindow(base2, &content_window);
4241 IHTMLFrameBase2_Release(base2);
4242 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
4243 ok(content_window != NULL, "contentWindow = NULL\n");
4245 content_doc = NULL;
4246 hres = IHTMLWindow2_get_document(content_window, &content_doc);
4247 IHTMLWindow2_Release(content_window);
4248 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4249 ok(content_doc != NULL, "content_doc = NULL\n");
4251 str = a2bstr("text/html");
4252 V_VT(&errv) = VT_ERROR;
4253 disp = NULL;
4254 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
4255 SysFreeString(str);
4256 ok(hres == S_OK, "open failed: %08x\n", hres);
4257 ok(disp != NULL, "disp == NULL\n");
4258 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
4259 IDispatch_Release(disp);
4261 doc_write(content_doc, FALSE, "<html><head><title>test</title></head><body><br /></body>");
4262 doc_write(content_doc, TRUE, "</html>");
4264 hres = IHTMLDocument2_get_all(content_doc, &col);
4265 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4266 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4267 IHTMLElementCollection_Release(col);
4269 hres = IHTMLDocument2_close(content_doc);
4270 ok(hres == S_OK, "close failed: %08x\n", hres);
4272 IHTMLDocument2_Release(content_doc);
4275 static void test_stylesheet(IDispatch *disp)
4277 IHTMLStyleSheetRulesCollection *col = NULL;
4278 IHTMLStyleSheet *stylesheet;
4279 HRESULT hres;
4281 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
4282 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
4284 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
4285 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
4286 ok(col != NULL, "col == NULL\n");
4288 IHTMLStyleSheetRulesCollection_Release(col);
4289 IHTMLStyleSheet_Release(stylesheet);
4292 static void test_stylesheets(IHTMLDocument2 *doc)
4294 IHTMLStyleSheetsCollection *col = NULL;
4295 VARIANT idx, res;
4296 LONG len = 0;
4297 HRESULT hres;
4299 hres = IHTMLDocument2_get_styleSheets(doc, &col);
4300 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
4301 ok(col != NULL, "col == NULL\n");
4303 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
4304 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4305 ok(len == 1, "len=%d\n", len);
4307 VariantInit(&res);
4308 V_VT(&idx) = VT_I4;
4309 V_I4(&idx) = 0;
4311 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4312 ok(hres == S_OK, "item failed: %08x\n", hres);
4313 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
4314 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4315 test_stylesheet(V_DISPATCH(&res));
4316 VariantClear(&res);
4318 V_VT(&res) = VT_I4;
4319 V_VT(&idx) = VT_I4;
4320 V_I4(&idx) = 1;
4322 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
4323 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4324 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
4325 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
4326 VariantClear(&res);
4328 IHTMLStyleSheetsCollection_Release(col);
4331 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
4333 IDispatchEx *dispex;
4334 IHTMLDOMNode *node;
4335 DISPPARAMS dp = {NULL, NULL, 0, 0};
4336 VARIANT var;
4337 EXCEPINFO ei;
4338 LONG type;
4339 DISPID id;
4340 BSTR bstr;
4341 HRESULT hres;
4343 static const WCHAR w0[] = {'0',0};
4344 static const WCHAR w100[] = {'1','0','0',0};
4346 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
4347 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
4349 bstr = SysAllocString(w0);
4350 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4351 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
4352 SysFreeString(bstr);
4354 VariantInit(&var);
4355 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
4356 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
4357 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
4358 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
4359 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
4360 type = get_node_type((IUnknown*)node);
4361 ok(type == 3, "type=%d\n", type);
4362 IHTMLDOMNode_Release(node);
4363 VariantClear(&var);
4365 bstr = SysAllocString(w100);
4366 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
4367 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
4368 SysFreeString(bstr);
4370 IDispatchEx_Release(dispex);
4375 static void test_elems(IHTMLDocument2 *doc)
4377 IHTMLElementCollection *col;
4378 IHTMLDOMChildrenCollection *child_col;
4379 IHTMLElement *elem, *elem2, *elem3;
4380 IHTMLDOMNode *node, *node2;
4381 IDispatch *disp;
4382 LONG type;
4383 HRESULT hres;
4384 IHTMLElementCollection *collection;
4385 IHTMLDocument3 *doc3;
4386 BSTR str;
4388 static const elem_type_t all_types[] = {
4389 ET_HTML,
4390 ET_HEAD,
4391 ET_TITLE,
4392 ET_STYLE,
4393 ET_BODY,
4394 ET_COMMENT,
4395 ET_A,
4396 ET_INPUT,
4397 ET_SELECT,
4398 ET_OPTION,
4399 ET_OPTION,
4400 ET_TEXTAREA,
4401 ET_TABLE,
4402 ET_TBODY,
4403 ET_TR,
4404 ET_TR,
4405 ET_TD,
4406 ET_TD,
4407 ET_SCRIPT,
4408 ET_TEST,
4409 ET_IMG,
4410 ET_IFRAME
4413 static const elem_type_t item_types[] = {
4414 ET_A,
4415 ET_OPTION,
4416 ET_TEXTAREA
4419 hres = IHTMLDocument2_get_all(doc, &col);
4420 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4421 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4422 test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
4423 IHTMLElementCollection_Release(col);
4425 hres = IHTMLDocument2_get_images(doc, &collection);
4426 ok(hres == S_OK, "get_images failed: %08x\n", hres);
4427 if(hres == S_OK)
4429 static const elem_type_t images_types[] = {ET_IMG};
4430 test_elem_collection((IUnknown*)collection, images_types, 1);
4432 IHTMLElementCollection_Release(collection);
4435 hres = IHTMLDocument2_get_links(doc, &collection);
4436 ok(hres == S_OK, "get_links failed: %08x\n", hres);
4437 if(hres == S_OK)
4439 static const elem_type_t images_types[] = {ET_A};
4440 test_elem_collection((IUnknown*)collection, images_types, 1);
4442 IHTMLElementCollection_Release(collection);
4445 hres = IHTMLDocument2_get_anchors(doc, &collection);
4446 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
4447 if(hres == S_OK)
4449 static const elem_type_t anchor_types[] = {ET_A};
4450 test_elem_collection((IUnknown*)collection, anchor_types, 1);
4452 IHTMLElementCollection_Release(collection);
4455 elem = get_doc_elem(doc);
4456 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
4457 hres = IHTMLElement_get_all(elem, &disp);
4458 IHTMLElement_Release(elem);
4459 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4461 hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&col);
4462 IDispatch_Release(disp);
4463 ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
4464 test_elem_collection((IUnknown*)col, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
4465 IHTMLElementCollection_Release(col);
4467 get_elem_by_id(doc, "xxx", FALSE);
4468 elem = get_doc_elem_by_id(doc, "xxx");
4469 ok(!elem, "elem != NULL\n");
4471 elem = get_doc_elem_by_id(doc, "s");
4472 ok(elem != NULL, "elem == NULL\n");
4473 if(elem) {
4474 test_elem_type((IUnknown*)elem, ET_SELECT);
4475 test_elem_attr(elem, "xxx", NULL);
4476 test_elem_attr(elem, "id", "s");
4477 test_elem_class((IUnknown*)elem, NULL);
4478 test_elem_set_class((IUnknown*)elem, "cl");
4479 test_elem_set_class((IUnknown*)elem, NULL);
4480 test_elem_tabindex((IUnknown*)elem, 0);
4481 test_elem_set_tabindex((IUnknown*)elem, 1);
4483 node = test_node_get_parent((IUnknown*)elem);
4484 ok(node != NULL, "node == NULL\n");
4485 test_node_name((IUnknown*)node, "BODY");
4486 node2 = test_node_get_parent((IUnknown*)node);
4487 IHTMLDOMNode_Release(node);
4488 ok(node2 != NULL, "node == NULL\n");
4489 test_node_name((IUnknown*)node2, "HTML");
4490 node = test_node_get_parent((IUnknown*)node2);
4491 IHTMLDOMNode_Release(node2);
4492 ok(node != NULL, "node == NULL\n");
4493 if (node)
4495 test_node_name((IUnknown*)node, "#document");
4496 type = get_node_type((IUnknown*)node);
4497 ok(type == 9, "type=%d, expected 9\n", type);
4498 node2 = test_node_get_parent((IUnknown*)node);
4499 IHTMLDOMNode_Release(node);
4500 ok(node2 == NULL, "node != NULL\n");
4503 elem2 = test_elem_get_parent((IUnknown*)elem);
4504 ok(elem2 != NULL, "elem2 == NULL\n");
4505 test_node_name((IUnknown*)elem2, "BODY");
4506 elem3 = test_elem_get_parent((IUnknown*)elem2);
4507 IHTMLElement_Release(elem2);
4508 ok(elem3 != NULL, "elem3 == NULL\n");
4509 test_node_name((IUnknown*)elem3, "HTML");
4510 elem2 = test_elem_get_parent((IUnknown*)elem3);
4511 IHTMLElement_Release(elem3);
4512 ok(elem2 == NULL, "elem2 != NULL\n");
4514 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2);
4515 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);
4516 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0);
4518 test_elem_innertext(elem, "opt1opt2");
4520 IHTMLElement_Release(elem);
4523 elem = get_elem_by_id(doc, "s", TRUE);
4524 if(elem) {
4525 IHTMLSelectElement *select;
4527 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLSelectElement, (void**)&select);
4528 ok(hres == S_OK, "Could not get IHTMLSelectElement interface: %08x\n", hres);
4530 test_select_elem(select);
4532 test_elem_title((IUnknown*)select, NULL);
4533 test_elem_set_title((IUnknown*)select, "Title");
4534 test_elem_title((IUnknown*)select, "Title");
4535 test_elem_offset((IUnknown*)select);
4537 node = get_first_child((IUnknown*)select);
4538 ok(node != NULL, "node == NULL\n");
4539 if(node) {
4540 test_elem_type((IUnknown*)node, ET_OPTION);
4541 IHTMLDOMNode_Release(node);
4544 type = get_node_type((IUnknown*)select);
4545 ok(type == 1, "type=%d\n", type);
4547 IHTMLSelectElement_Release(select);
4549 hres = IHTMLElement_get_document(elem, &disp);
4550 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4551 ok(iface_cmp((IUnknown*)disp, (IUnknown*)doc), "disp != doc\n");
4553 IHTMLElement_Release(elem);
4556 elem = get_elem_by_id(doc, "sc", TRUE);
4557 if(elem) {
4558 IHTMLScriptElement *script;
4559 BSTR type;
4561 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
4562 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
4564 if(hres == S_OK)
4566 VARIANT_BOOL vb;
4568 hres = IHTMLScriptElement_get_type(script, &type);
4569 ok(hres == S_OK, "get_type failed: %08x\n", hres);
4570 ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
4571 SysFreeString(type);
4573 /* test defer */
4574 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
4575 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
4577 hres = IHTMLScriptElement_get_defer(script, &vb);
4578 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
4579 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
4581 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
4582 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
4585 IHTMLScriptElement_Release(script);
4588 elem = get_elem_by_id(doc, "in", TRUE);
4589 if(elem) {
4590 IHTMLInputElement *input;
4592 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
4593 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4595 test_elem_id((IUnknown*)elem, "in");
4596 test_elem_put_id((IUnknown*)elem, "newin");
4597 test_input_get_disabled(input, VARIANT_FALSE);
4598 test_input_set_disabled(input, VARIANT_TRUE);
4599 test_input_set_disabled(input, VARIANT_FALSE);
4600 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
4601 test_input_get_disabled(input, VARIANT_TRUE);
4602 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
4603 test_input_get_disabled(input, VARIANT_FALSE);
4604 test_elem_client_size((IUnknown*)elem);
4606 test_node_get_value_str((IUnknown*)elem, NULL);
4607 test_node_put_value_str((IUnknown*)elem, "test");
4608 test_node_get_value_str((IUnknown*)elem, NULL);
4609 test_input_value((IUnknown*)elem, NULL);
4610 test_input_put_value((IUnknown*)elem, "test");
4611 test_input_value((IUnknown*)elem, NULL);
4612 test_elem_class((IUnknown*)elem, "testclass");
4613 test_elem_tabindex((IUnknown*)elem, 2);
4614 test_elem_set_tabindex((IUnknown*)elem, 3);
4615 test_elem_title((IUnknown*)elem, "test title");
4617 test_input_get_defaultchecked(input, VARIANT_FALSE);
4618 test_input_set_defaultchecked(input, VARIANT_TRUE);
4619 test_input_set_defaultchecked(input, VARIANT_FALSE);
4621 test_input_get_checked(input, VARIANT_FALSE);
4622 test_input_set_checked(input, VARIANT_TRUE);
4623 test_input_set_checked(input, VARIANT_FALSE);
4625 IHTMLInputElement_Release(input);
4626 IHTMLElement_Release(elem);
4629 elem = get_elem_by_id(doc, "imgid", TRUE);
4630 if(elem) {
4631 test_img_src((IUnknown*)elem, "");
4632 test_img_set_src((IUnknown*)elem, "about:blank");
4633 test_img_alt((IUnknown*)elem, NULL);
4634 test_img_set_alt((IUnknown*)elem, "alt test");
4635 IHTMLElement_Release(elem);
4638 elem = get_doc_elem_by_id(doc, "tbl");
4639 ok(elem != NULL, "elem == NULL\n");
4640 if(elem) {
4641 test_table_elem(elem);
4642 IHTMLElement_Release(elem);
4645 elem = get_doc_elem_by_id(doc, "row2");
4646 ok(elem != NULL, "elem == NULL\n");
4647 if(elem) {
4648 test_tr_elem(elem);
4649 IHTMLElement_Release(elem);
4652 elem = get_doc_elem_by_id(doc, "ifr");
4653 ok(elem != NULL, "elem == NULL\n");
4654 if(elem) {
4655 test_iframe_elem(elem);
4656 IHTMLElement_Release(elem);
4659 hres = IHTMLDocument2_get_body(doc, &elem);
4660 ok(hres == S_OK, "get_body failed: %08x\n", hres);
4662 node = get_first_child((IUnknown*)elem);
4663 ok(node != NULL, "node == NULL\n");
4664 if(node) {
4665 test_ifaces((IUnknown*)node, text_iids);
4666 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
4668 node2 = get_first_child((IUnknown*)node);
4669 ok(!node2, "node2 != NULL\n");
4671 type = get_node_type((IUnknown*)node);
4672 ok(type == 3, "type=%d\n", type);
4674 test_node_get_value_str((IUnknown*)node, "text test");
4675 test_node_put_value_str((IUnknown*)elem, "test text");
4676 test_node_get_value_str((IUnknown*)node, "text test");
4678 IHTMLDOMNode_Release(node);
4681 child_col = get_child_nodes((IUnknown*)elem);
4682 ok(child_col != NULL, "child_coll == NULL\n");
4683 if(child_col) {
4684 LONG length = 0;
4686 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
4688 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
4689 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4690 ok(length, "length=0\n");
4692 node = get_child_item(child_col, 0);
4693 ok(node != NULL, "node == NULL\n");
4694 if(node) {
4695 type = get_node_type((IUnknown*)node);
4696 ok(type == 3, "type=%d\n", type);
4697 IHTMLDOMNode_Release(node);
4700 node = get_child_item(child_col, 1);
4701 ok(node != NULL, "node == NULL\n");
4702 if(node) {
4703 type = get_node_type((IUnknown*)node);
4704 ok(type == 8, "type=%d\n", type);
4706 test_elem_id((IUnknown*)node, NULL);
4707 IHTMLDOMNode_Release(node);
4710 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
4711 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
4713 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
4714 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
4716 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
4717 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4719 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
4720 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4722 test_child_col_disp(child_col);
4724 IHTMLDOMChildrenCollection_Release(child_col);
4727 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
4728 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
4729 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
4731 IHTMLElement_Release(elem);
4733 test_stylesheets(doc);
4734 test_create_option_elem(doc);
4736 elem = get_doc_elem_by_id(doc, "tbl");
4737 ok(elem != NULL, "elem = NULL\n");
4738 test_elem_set_innertext(elem, "inner text");
4739 IHTMLElement_Release(elem);
4741 test_doc_title(doc, "test");
4742 test_doc_set_title(doc, "test title");
4743 test_doc_title(doc, "test title");
4745 disp = NULL;
4746 hres = IHTMLDocument2_get_Script(doc, &disp);
4747 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
4748 if(hres == S_OK)
4750 IDispatchEx *dispex;
4751 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
4752 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
4753 if(hres == S_OK)
4755 DISPID pid = -1;
4756 BSTR str = a2bstr("Testing");
4757 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
4758 todo_wine ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
4759 todo_wine ok(pid != -1, "pid == -1\n");
4760 SysFreeString(str);
4761 IDispatchEx_Release(dispex);
4764 IDispatch_Release(disp);
4766 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4767 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
4769 str = a2bstr("img");
4770 hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
4771 ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
4772 SysFreeString(str);
4773 if(hres == S_OK)
4775 static const elem_type_t img_types[] = { ET_IMG };
4777 test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
4778 IHTMLElementCollection_Release(col);
4781 elem = get_doc_elem_by_id(doc, "y");
4782 test_elem_set_innerhtml((IUnknown*)elem, "inner html");
4783 test_elem_innerhtml((IUnknown*)elem, "inner html");
4784 test_elem_set_innerhtml((IUnknown*)elem, "");
4785 test_elem_innerhtml((IUnknown*)elem, NULL);
4786 IHTMLElement_Release(elem);
4788 IHTMLDocument3_Release(doc3);
4791 static void test_create_elems(IHTMLDocument2 *doc)
4793 IHTMLElement *elem, *body, *elem2;
4794 IHTMLDOMNode *node, *node2, *node3, *comment;
4795 IHTMLDocument5 *doc5;
4796 IDispatch *disp;
4797 VARIANT var;
4798 LONG type;
4799 HRESULT hres;
4800 BSTR str;
4802 static const elem_type_t types1[] = { ET_TESTG };
4804 elem = test_create_elem(doc, "TEST");
4805 test_elem_tag((IUnknown*)elem, "TEST");
4806 type = get_node_type((IUnknown*)elem);
4807 ok(type == 1, "type=%d\n", type);
4808 test_ifaces((IUnknown*)elem, elem_iids);
4809 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
4811 hres = IHTMLDocument2_get_body(doc, &body);
4812 ok(hres == S_OK, "get_body failed: %08x\n", hres);
4813 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
4815 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
4816 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
4817 elem2 = get_elem_iface((IUnknown*)node);
4818 IHTMLElement_Release(elem2);
4820 hres = IHTMLElement_get_all(body, &disp);
4821 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4822 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
4823 IDispatch_Release(disp);
4825 test_node_remove_child((IUnknown*)body, node);
4827 hres = IHTMLElement_get_all(body, &disp);
4828 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4829 test_elem_collection((IUnknown*)disp, NULL, 0);
4830 IDispatch_Release(disp);
4831 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
4833 IHTMLElement_Release(elem);
4834 IHTMLDOMNode_Release(node);
4836 node = test_create_text(doc, "test");
4837 test_ifaces((IUnknown*)node, text_iids);
4838 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
4840 V_VT(&var) = VT_NULL;
4841 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
4842 IHTMLDOMNode_Release(node);
4844 node = test_create_text(doc, "insert ");
4846 V_VT(&var) = VT_DISPATCH;
4847 V_DISPATCH(&var) = (IDispatch*)node2;
4848 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
4849 IHTMLDOMNode_Release(node);
4850 IHTMLDOMNode_Release(node2);
4851 IHTMLDOMNode_Release(node3);
4853 test_elem_innertext(body, "insert test");
4854 test_elem_innerhtml((IUnknown*)body, "insert test");
4856 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
4857 if(hres == S_OK)
4859 str = a2bstr("testing");
4860 hres = IHTMLDocument5_createComment(doc5, str, &comment);
4861 SysFreeString(str);
4862 ok(hres == S_OK, "createComment failed: %08x\n", hres);
4863 if(hres == S_OK)
4865 type = get_node_type((IUnknown*)comment);
4866 ok(type == 8, "type=%d, expected 8\n", type);
4868 test_node_get_value_str((IUnknown*)comment, "testing");
4870 IHTMLDOMNode_Release(comment);
4873 IHTMLDocument5_Release(doc5);
4876 IHTMLElement_Release(body);
4879 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
4881 IOleCommandTarget *cmdtrg;
4882 HRESULT hres;
4884 hres = IHTMLTxtRange_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
4885 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
4887 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
4888 ok(hres == S_OK, "Exec failed: %08x\n", hres);
4890 IOleCommandTarget_Release(cmdtrg);
4893 static void test_indent(IHTMLDocument2 *doc)
4895 IHTMLElementCollection *col;
4896 IHTMLTxtRange *range;
4897 HRESULT hres;
4899 static const elem_type_t all_types[] = {
4900 ET_HTML,
4901 ET_HEAD,
4902 ET_TITLE,
4903 ET_BODY,
4904 ET_BR,
4905 ET_A,
4908 static const elem_type_t indent_types[] = {
4909 ET_HTML,
4910 ET_HEAD,
4911 ET_TITLE,
4912 ET_BODY,
4913 ET_BLOCKQUOTE,
4914 ET_P,
4915 ET_BR,
4916 ET_A,
4919 hres = IHTMLDocument2_get_all(doc, &col);
4920 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4921 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4922 IHTMLElementCollection_Release(col);
4924 range = test_create_body_range(doc);
4925 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
4926 IHTMLTxtRange_Release(range);
4928 hres = IHTMLDocument2_get_all(doc, &col);
4929 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4930 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
4931 IHTMLElementCollection_Release(col);
4934 static void test_cond_comment(IHTMLDocument2 *doc)
4936 IHTMLElementCollection *col;
4937 HRESULT hres;
4939 static const elem_type_t all_types[] = {
4940 ET_HTML,
4941 ET_HEAD,
4942 ET_TITLE,
4943 ET_BODY,
4944 ET_BR
4947 hres = IHTMLDocument2_get_all(doc, &col);
4948 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4949 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
4950 IHTMLElementCollection_Release(col);
4953 static IHTMLDocument2 *notif_doc;
4954 static BOOL doc_complete;
4956 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
4957 REFIID riid, void**ppv)
4959 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
4960 *ppv = iface;
4961 return S_OK;
4964 ok(0, "unexpected call\n");
4965 return E_NOINTERFACE;
4968 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
4970 return 2;
4973 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
4975 return 1;
4978 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
4980 if(dispID == DISPID_READYSTATE){
4981 BSTR state;
4982 HRESULT hres;
4984 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
4985 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
4987 if(!strcmp_wa(state, "complete"))
4988 doc_complete = TRUE;
4990 SysFreeString(state);
4993 return S_OK;
4996 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
4998 ok(0, "unexpected call\n");
4999 return E_NOTIMPL;
5002 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
5003 PropertyNotifySink_QueryInterface,
5004 PropertyNotifySink_AddRef,
5005 PropertyNotifySink_Release,
5006 PropertyNotifySink_OnChanged,
5007 PropertyNotifySink_OnRequestEdit
5010 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
5012 static IHTMLDocument2 *create_doc_with_string(const char *str)
5014 IPersistStreamInit *init;
5015 IStream *stream;
5016 IHTMLDocument2 *doc;
5017 HGLOBAL mem;
5018 SIZE_T len;
5020 notif_doc = doc = create_document();
5021 if(!doc)
5022 return NULL;
5024 doc_complete = FALSE;
5025 len = strlen(str);
5026 mem = GlobalAlloc(0, len);
5027 memcpy(mem, str, len);
5028 CreateStreamOnHGlobal(mem, TRUE, &stream);
5030 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
5032 IPersistStreamInit_Load(init, stream);
5033 IPersistStreamInit_Release(init);
5034 IStream_Release(stream);
5036 return doc;
5039 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
5041 IConnectionPointContainer *container;
5042 IConnectionPoint *cp;
5043 DWORD cookie;
5044 HRESULT hres;
5046 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
5047 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
5049 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
5050 IConnectionPointContainer_Release(container);
5051 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
5053 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
5054 IConnectionPoint_Release(cp);
5055 ok(hres == S_OK, "Advise failed: %08x\n", hres);
5058 typedef void (*domtest_t)(IHTMLDocument2*);
5060 static void run_domtest(const char *str, domtest_t test)
5062 IHTMLDocument2 *doc;
5063 IHTMLElement *body = NULL;
5064 ULONG ref;
5065 MSG msg;
5066 HRESULT hres;
5068 doc = create_doc_with_string(str);
5069 if(!doc)
5070 return;
5072 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
5074 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
5075 TranslateMessage(&msg);
5076 DispatchMessage(&msg);
5079 hres = IHTMLDocument2_get_body(doc, &body);
5080 ok(hres == S_OK, "get_body failed: %08x\n", hres);
5082 if(body) {
5083 IHTMLElement_Release(body);
5084 test(doc);
5085 }else {
5086 skip("Could not get document body. Assuming no Gecko installed.\n");
5089 ref = IHTMLDocument2_Release(doc);
5090 ok(!ref ||
5091 ref == 1, /* Vista */
5092 "ref = %d\n", ref);
5095 static void gecko_installer_workaround(BOOL disable)
5097 HKEY hkey;
5098 DWORD res;
5100 static BOOL has_url = FALSE;
5101 static char url[2048];
5103 if(!disable && !has_url)
5104 return;
5106 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
5107 if(res != ERROR_SUCCESS)
5108 return;
5110 if(disable) {
5111 DWORD type, size = sizeof(url);
5113 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
5114 if(res == ERROR_SUCCESS && type == REG_SZ)
5115 has_url = TRUE;
5117 RegDeleteValue(hkey, "GeckoUrl");
5118 }else {
5119 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
5122 RegCloseKey(hkey);
5125 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
5126 /* Note: this code is duplicated in dlls/mshtml/tests/dom.c, dlls/mshtml/tests/script.c and dlls/urlmon/tests/sec_mgr.c */
5127 static BOOL is_ie_hardened(void)
5129 HKEY zone_map;
5130 DWORD ie_harden, type, size;
5132 ie_harden = 0;
5133 if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
5134 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
5135 size = sizeof(DWORD);
5136 if (RegQueryValueEx(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
5137 type != REG_DWORD) {
5138 ie_harden = 0;
5140 RegCloseKey(zone_map);
5143 return ie_harden != 0;
5146 START_TEST(dom)
5148 gecko_installer_workaround(TRUE);
5149 CoInitialize(NULL);
5151 run_domtest(doc_str1, test_doc_elem);
5152 run_domtest(range_test_str, test_txtrange);
5153 run_domtest(range_test2_str, test_txtrange2);
5154 if (winetest_interactive || ! is_ie_hardened()) {
5155 run_domtest(elem_test_str, test_elems);
5156 }else {
5157 skip("IE running in Enhanced Security Configuration\n");
5159 run_domtest(doc_blank, test_create_elems);
5160 run_domtest(doc_blank, test_defaults);
5161 run_domtest(indent_test_str, test_indent);
5162 run_domtest(cond_comment_str, test_cond_comment);
5164 CoUninitialize();
5165 gecko_installer_workaround(FALSE);