mshtml: Added IHTMLTableCell::align property implementation.
[wine.git] / dlls / mshtml / tests / dom.c
blobcfde7ac29c15a5522b52c48915c51c4b40a2a2fb
1 /*
2 * Copyright 2007-2011 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"
34 #include "mshtml_test.h"
35 #include "objsafe.h"
36 #include "htiface.h"
37 #include "tlogstg.h"
39 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
40 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
42 static const char doc_blank[] = "<html></html>";
43 static const char doc_str1[] = "<html><body>test</body></html>";
44 static const char range_test_str[] =
45 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
46 static const char range_test2_str[] =
47 "<html><body>abc<hr />123<br /><hr />def</body></html>";
48 static const char elem_test_str[] =
49 "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
50 "<meta id=\"metaid\" name=\"meta name\" http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
51 "<link id=\"linkid\"></head>"
52 "<body onload=\"Testing()\">text test<!-- a comment -->"
53 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
54 "<label for=\"in\" id=\"labelid\">Label:</label>"
55 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
56 "<button id=\"btnid\"></button>"
57 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
58 "<textarea id=\"X\">text text</textarea>"
59 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td id=\"td1\">td1 text</td><td id=\"td2\">td2 text</td></tr></tbody></table>"
60 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
61 "<test /><object id=\"objid\" name=\"objname\" vspace=100></object><embed />"
62 "<img id=\"imgid\" name=\"WineImg\"/>"
63 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
64 "<form id=\"frm\"></form>"
65 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
66 "</body></html>";
67 static const char elem_test2_str[] =
68 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
69 "<link id=\"linkid\" rel=\"stylesheet\" href=\"about:blank\" type=\"text/css\"></head>"
70 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
71 "</html>";
73 static const char indent_test_str[] =
74 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
75 static const char cond_comment_str[] =
76 "<html><head><title>test</title></head><body>"
77 "<!--[if gte IE 4]> <br> <![endif]-->"
78 "</body></html>";
79 static const char frameset_str[] =
80 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
81 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
82 "<frame src=\"about:blank\" id=\"fr3\">"
83 "</frameset></html>";
84 static const char emptydiv_str[] =
85 "<html><head><title>emptydiv test</title></head>"
86 "<body><div id=\"divid\"></div></body></html>";
87 static const char noscript_str[] =
88 "<html><head><title>noscript test</title><noscript><style>.body { margin-right: 0px; }</style></noscript></head>"
89 "<body><noscript><div>test</div></noscript></body></html>";
90 static const char doctype_str[] =
91 "<!DOCTYPE html>"
92 "<html><head><title>emptydiv test</title></head>"
93 "<body><div id=\"divid\"></div></body></html>";
95 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
96 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
97 static WCHAR wordW[] = {'w','o','r','d',0};
99 typedef enum {
100 ET_NONE,
101 ET_HTML,
102 ET_HEAD,
103 ET_TITLE,
104 ET_BODY,
105 ET_A,
106 ET_INPUT,
107 ET_SELECT,
108 ET_TEXTAREA,
109 ET_OPTION,
110 ET_STYLE,
111 ET_BLOCKQUOTE,
112 ET_P,
113 ET_BR,
114 ET_TABLE,
115 ET_TBODY,
116 ET_SCRIPT,
117 ET_TEST,
118 ET_TESTG,
119 ET_COMMENT,
120 ET_IMG,
121 ET_TR,
122 ET_TD,
123 ET_IFRAME,
124 ET_FORM,
125 ET_FRAME,
126 ET_OBJECT,
127 ET_EMBED,
128 ET_DIV,
129 ET_META,
130 ET_NOSCRIPT,
131 ET_LINK,
132 ET_LABEL,
133 ET_BUTTON
134 } elem_type_t;
136 static const IID * const none_iids[] = {
137 &IID_IUnknown,
138 NULL
141 static const IID * const doc_node_iids[] = {
142 &IID_IHTMLDOMNode,
143 &IID_IHTMLDOMNode2,
144 &IID_IHTMLDocument,
145 &IID_IHTMLDocument2,
146 &IID_IHTMLDocument3,
147 &IID_IHTMLDocument4,
148 &IID_IHTMLDocument5,
149 &IID_IDispatchEx,
150 &IID_IConnectionPointContainer,
151 &IID_IInternetHostSecurityManager,
152 &IID_IOleContainer,
153 &IID_IObjectSafety,
154 &IID_IProvideClassInfo,
155 NULL
158 static const IID * const doc_obj_iids[] = {
159 &IID_IHTMLDocument,
160 &IID_IHTMLDocument2,
161 &IID_IHTMLDocument3,
162 &IID_IHTMLDocument4,
163 &IID_IHTMLDocument5,
164 &IID_IDispatchEx,
165 &IID_IConnectionPointContainer,
166 &IID_ICustomDoc,
167 &IID_IOleContainer,
168 &IID_IObjectSafety,
169 &IID_IProvideClassInfo,
170 &IID_ITargetContainer,
171 NULL
174 #define ELEM_IFACES \
175 &IID_IHTMLDOMNode, \
176 &IID_IHTMLDOMNode2, \
177 &IID_IHTMLElement, \
178 &IID_IHTMLElement2, \
179 &IID_IHTMLElement3, \
180 &IID_IHTMLElement4, \
181 &IID_IDispatchEx
183 static const IID * const elem_iids[] = {
184 ELEM_IFACES,
185 &IID_IConnectionPointContainer,
186 NULL
189 static const IID * const body_iids[] = {
190 ELEM_IFACES,
191 &IID_IHTMLTextContainer,
192 &IID_IHTMLBodyElement,
193 &IID_IConnectionPointContainer,
194 NULL
197 static const IID * const anchor_iids[] = {
198 ELEM_IFACES,
199 &IID_IHTMLAnchorElement,
200 &IID_IConnectionPointContainer,
201 NULL
204 static const IID * const input_iids[] = {
205 ELEM_IFACES,
206 &IID_IHTMLInputElement,
207 &IID_IHTMLInputTextElement,
208 &IID_IConnectionPointContainer,
209 NULL
212 static const IID *const button_iids[] = {
213 ELEM_IFACES,
214 &IID_IHTMLButtonElement,
215 &IID_IConnectionPointContainer,
216 NULL
219 static const IID * const label_iids[] = {
220 ELEM_IFACES,
221 &IID_IHTMLLabelElement,
222 &IID_IConnectionPointContainer,
223 NULL
226 static const IID * const select_iids[] = {
227 ELEM_IFACES,
228 &IID_IHTMLSelectElement,
229 &IID_IConnectionPointContainer,
230 NULL
233 static const IID * const textarea_iids[] = {
234 ELEM_IFACES,
235 &IID_IHTMLTextAreaElement,
236 &IID_IConnectionPointContainer,
237 NULL
240 static const IID * const option_iids[] = {
241 ELEM_IFACES,
242 &IID_IHTMLOptionElement,
243 &IID_IConnectionPointContainer,
244 NULL
247 static const IID * const table_iids[] = {
248 ELEM_IFACES,
249 &IID_IHTMLTable,
250 &IID_IHTMLTable2,
251 &IID_IHTMLTable3,
252 &IID_IConnectionPointContainer,
253 NULL
256 static const IID * const script_iids[] = {
257 ELEM_IFACES,
258 &IID_IHTMLScriptElement,
259 &IID_IConnectionPointContainer,
260 NULL
263 static const IID * const text_iids[] = {
264 &IID_IHTMLDOMNode,
265 &IID_IHTMLDOMNode2,
266 &IID_IHTMLDOMTextNode,
267 NULL
270 static const IID * const attr_iids[] = {
271 &IID_IHTMLDOMAttribute,
272 &IID_IDispatchEx,
273 NULL
276 static const IID * const location_iids[] = {
277 &IID_IDispatch,
278 &IID_IHTMLLocation,
279 NULL
282 static const IID * const window_iids[] = {
283 &IID_IDispatch,
284 &IID_IHTMLWindow2,
285 &IID_IHTMLWindow3,
286 &IID_IDispatchEx,
287 &IID_IServiceProvider,
288 NULL
291 static const IID * const comment_iids[] = {
292 ELEM_IFACES,
293 &IID_IHTMLCommentElement,
294 &IID_IConnectionPointContainer,
295 NULL
298 static const IID * const img_iids[] = {
299 ELEM_IFACES,
300 &IID_IHTMLImgElement,
301 &IID_IConnectionPointContainer,
302 NULL
305 static const IID * const tr_iids[] = {
306 ELEM_IFACES,
307 &IID_IHTMLTableRow,
308 &IID_IConnectionPointContainer,
309 NULL
312 static const IID * const td_iids[] = {
313 ELEM_IFACES,
314 &IID_IHTMLTableCell,
315 &IID_IConnectionPointContainer,
316 NULL
319 static const IID * const frame_iids[] = {
320 ELEM_IFACES,
321 &IID_IHTMLFrameBase,
322 &IID_IHTMLFrameBase2,
323 &IID_IConnectionPointContainer,
324 NULL
327 static const IID * const head_iids[] = {
328 ELEM_IFACES,
329 &IID_IHTMLHeadElement,
330 &IID_IConnectionPointContainer,
331 NULL
334 static const IID * const title_iids[] = {
335 ELEM_IFACES,
336 &IID_IHTMLTitleElement,
337 &IID_IConnectionPointContainer,
338 NULL
341 static const IID * const meta_iids[] = {
342 ELEM_IFACES,
343 &IID_IHTMLMetaElement,
344 &IID_IConnectionPointContainer,
345 NULL
348 static const IID * const link_iids[] = {
349 ELEM_IFACES,
350 &IID_IHTMLLinkElement,
351 &IID_IConnectionPointContainer,
352 NULL
355 static const IID * const object_iids[] = {
356 ELEM_IFACES,
357 &IID_IHTMLObjectElement,
358 &IID_IHTMLObjectElement2,
359 /* FIXME: No IConnectionPointContainer */
360 NULL
363 static const IID * const embed_iids[] = {
364 ELEM_IFACES,
365 &IID_IHTMLEmbedElement,
366 /* FIXME: No IConnectionPointContainer */
367 NULL
370 static const IID * const iframe_iids[] = {
371 ELEM_IFACES,
372 &IID_IHTMLFrameBase,
373 &IID_IHTMLFrameBase2,
374 &IID_IHTMLIFrameElement,
375 &IID_IHTMLIFrameElement2,
376 &IID_IConnectionPointContainer,
377 NULL
380 static const IID * const form_iids[] = {
381 ELEM_IFACES,
382 &IID_IHTMLFormElement,
383 &IID_IConnectionPointContainer,
384 NULL
387 static const IID * const styleelem_iids[] = {
388 ELEM_IFACES,
389 &IID_IHTMLStyleElement,
390 &IID_IConnectionPointContainer,
391 NULL
394 static const IID * const generic_iids[] = {
395 ELEM_IFACES,
396 &IID_IHTMLGenericElement,
397 &IID_IConnectionPointContainer,
398 NULL
401 static const IID * const style_iids[] = {
402 &IID_IUnknown,
403 &IID_IDispatch,
404 &IID_IDispatchEx,
405 &IID_IHTMLStyle,
406 &IID_IHTMLStyle2,
407 &IID_IHTMLStyle3,
408 &IID_IHTMLStyle4,
409 NULL
412 static const IID * const cstyle_iids[] = {
413 &IID_IUnknown,
414 &IID_IDispatch,
415 &IID_IDispatchEx,
416 &IID_IHTMLCurrentStyle,
417 &IID_IHTMLCurrentStyle2,
418 &IID_IHTMLCurrentStyle3,
419 NULL
422 static const IID * const img_factory_iids[] = {
423 &IID_IUnknown,
424 &IID_IDispatch,
425 &IID_IDispatchEx,
426 &IID_IHTMLImageElementFactory,
427 NULL
430 typedef struct {
431 const char *tag;
432 REFIID *iids;
433 const IID *dispiid;
434 } elem_type_info_t;
436 static const elem_type_info_t elem_type_infos[] = {
437 {"", none_iids, NULL},
438 {"HTML", elem_iids, NULL},
439 {"HEAD", head_iids, &DIID_DispHTMLHeadElement},
440 {"TITLE", title_iids, &DIID_DispHTMLTitleElement},
441 {"BODY", body_iids, &DIID_DispHTMLBody},
442 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
443 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
444 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
445 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
446 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
447 {"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement},
448 {"BLOCKQUOTE",elem_iids, NULL},
449 {"P", elem_iids, NULL},
450 {"BR", elem_iids, NULL},
451 {"TABLE", table_iids, &DIID_DispHTMLTable},
452 {"TBODY", elem_iids, NULL},
453 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
454 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
455 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
456 {"!", comment_iids, &DIID_DispHTMLCommentElement},
457 {"IMG", img_iids, &DIID_DispHTMLImg},
458 {"TR", tr_iids, &DIID_DispHTMLTableRow},
459 {"TD", td_iids, &DIID_DispHTMLTableCell},
460 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
461 {"FORM", form_iids, &DIID_DispHTMLFormElement},
462 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement},
463 {"OBJECT", object_iids, &DIID_DispHTMLObjectElement},
464 {"EMBED", embed_iids, &DIID_DispHTMLEmbed},
465 {"DIV", elem_iids, NULL},
466 {"META", meta_iids, &DIID_DispHTMLMetaElement},
467 {"NOSCRIPT", elem_iids, NULL /*&DIID_DispHTMLNoShowElement*/},
468 {"LINK", link_iids, &DIID_DispHTMLLinkElement},
469 {"LABEL", label_iids, &DIID_DispHTMLLabelElement},
470 {"BUTTON", button_iids, &DIID_DispHTMLButtonElement}
473 static int strcmp_wa(LPCWSTR strw, const char *stra)
475 CHAR buf[512];
476 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
477 return lstrcmpA(stra, buf);
480 static BSTR a2bstr(const char *str)
482 BSTR ret;
483 int len;
485 if(!str)
486 return NULL;
488 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
489 ret = SysAllocStringLen(NULL, len);
490 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
492 return ret;
495 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
497 IUnknown *unk1, *unk2;
499 if(iface1 == iface2)
500 return TRUE;
502 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
503 IUnknown_Release(unk1);
504 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
505 IUnknown_Release(unk2);
507 return unk1 == unk2;
510 static IHTMLDocument2 *create_document(void)
512 IHTMLDocument2 *doc;
513 IHTMLDocument5 *doc5;
514 HRESULT hres;
516 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
517 &IID_IHTMLDocument2, (void**)&doc);
518 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
519 if(FAILED(hres))
520 return NULL;
522 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
523 if(FAILED(hres)) {
524 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
525 IHTMLDocument2_Release(doc);
526 return NULL;
529 IHTMLDocument5_Release(doc5);
530 return doc;
533 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
534 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
536 IDispatchEx *dispex;
537 HRESULT hres;
539 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
540 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
541 return dispex;
544 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
545 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
547 const IID * const *piid;
548 IUnknown *unk;
549 HRESULT hres;
551 for(piid = iids; *piid; piid++) {
552 hres = IUnknown_QueryInterface(iface, *piid, (void**)&unk);
553 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", wine_dbgstr_guid(*piid), hres);
554 if(SUCCEEDED(hres))
555 IUnknown_Release(unk);
559 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
560 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
562 IUnknown *unk;
563 HRESULT hres;
565 unk = (void*)0xdeadbeef;
566 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
567 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
568 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
571 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
572 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
574 IDispatchEx *dispex = _get_dispex_iface(line, unk);
575 ITypeInfo *typeinfo;
576 BOOL ret = FALSE;
577 UINT ticnt;
578 HRESULT hres;
580 ticnt = 0xdeadbeef;
581 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
582 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
583 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
585 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
586 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
588 if(SUCCEEDED(hres)) {
589 TYPEATTR *type_attr;
591 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
592 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
593 if(hres == S_OK) {
594 *iid = type_attr->guid;
595 ret = TRUE;
598 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
599 ITypeInfo_Release(typeinfo);
602 IDispatchEx_Release(dispex);
603 return ret;
606 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
607 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
609 IDispatchEx *dispex = _get_dispex_iface(line, unk);
610 DISPPARAMS dp = {NULL,NULL,0,0};
611 EXCEPINFO ei;
612 VARIANT var;
613 HRESULT hres;
615 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
616 IDispatchEx_Release(dispex);
617 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
619 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
620 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
621 VariantClear(&var);
624 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
625 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
627 IID iid;
629 if(_test_get_dispid(line, unk, &iid))
630 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", wine_dbgstr_guid(&iid));
632 if(val)
633 _test_disp_value(line, unk, val);
636 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
637 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
639 IID iid;
641 if(_test_get_dispid(line, unk, &iid))
642 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
643 "unexpected guid %s\n", wine_dbgstr_guid(&iid));
645 if(val)
646 _test_disp_value(line, unk, val);
649 #define test_class_info(u) _test_class_info(__LINE__,u)
650 static void _test_class_info(unsigned line, IUnknown *unk)
652 IProvideClassInfo *classinfo;
653 ITypeInfo *typeinfo;
654 TYPEATTR *type_attr;
655 HRESULT hres;
657 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
658 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
659 if(FAILED(hres))
660 return;
662 hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
663 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
664 if(FAILED(hres))
666 IProvideClassInfo_Release(classinfo);
667 return;
670 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
671 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
672 if(SUCCEEDED(hres))
674 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
675 "unexpected guid %s\n", wine_dbgstr_guid(&type_attr->guid));
676 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
677 "unexpected typekind %d\n", type_attr->typekind);
678 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
681 ITypeInfo_Release(typeinfo);
682 IProvideClassInfo_Release(classinfo);
685 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
686 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
688 IDispatchEx *dispex = _get_dispex_iface(line, unk);
689 DISPPARAMS dp = {val, NULL, 1, 0};
690 EXCEPINFO ei;
691 DISPID id;
692 BSTR str;
693 HRESULT hres;
695 str = a2bstr(name);
696 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
697 SysFreeString(str);
698 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
700 memset(&ei, 0, sizeof(ei));
701 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
702 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
706 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
707 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
709 IHTMLElement *elem;
710 HRESULT hres;
712 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
713 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
714 return elem;
717 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
718 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
720 IHTMLElement2 *elem;
721 HRESULT hres;
723 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
724 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
725 return elem;
728 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
729 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
731 IHTMLElement3 *elem;
732 HRESULT hres;
734 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
735 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
736 return elem;
739 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
740 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
742 IHTMLElement4 *elem;
743 HRESULT hres;
745 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
746 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
747 return elem;
750 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
751 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IHTMLDocument2 *doc)
753 IHTMLDocument3 *doc3;
754 HRESULT hres;
756 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
757 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
759 return doc3;
762 #define get_node_iface(u) _get_node_iface(__LINE__,u)
763 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
765 IHTMLDOMNode *node;
766 HRESULT hres;
768 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
769 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
770 return node;
773 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
774 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
776 IHTMLDOMNode2 *node;
777 HRESULT hres;
779 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
780 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
781 return node;
784 #define get_htmldoc5_iface(u) _get_htmldoc5_iface(__LINE__,u)
785 static IHTMLDocument5 *_get_htmldoc5_iface(unsigned line, IUnknown *unk)
787 IHTMLDocument5 *doc;
788 HRESULT hres;
790 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument5, (void**)&doc);
791 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument5: %08x\n", hres);
792 return doc;
795 #define get_img_iface(u) _get_img_iface(__LINE__,u)
796 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
798 IHTMLImgElement *img;
799 HRESULT hres;
801 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
802 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
803 return img;
806 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
807 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
809 IHTMLAnchorElement *anchor;
810 HRESULT hres;
812 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
813 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
814 return anchor;
817 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
818 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
820 IHTMLTextAreaElement *textarea;
821 HRESULT hres;
823 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
824 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
825 return textarea;
828 #define get_select_iface(u) _get_select_iface(__LINE__,u)
829 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
831 IHTMLSelectElement *select;
832 HRESULT hres;
834 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
835 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
836 return select;
839 #define get_form_iface(u) _get_form_iface(__LINE__,u)
840 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
842 IHTMLFormElement *form;
843 HRESULT hres;
845 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
846 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
847 return form;
850 #define get_text_iface(u) _get_text_iface(__LINE__,u)
851 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
853 IHTMLDOMTextNode *text;
854 HRESULT hres;
856 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
857 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
858 return text;
861 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
862 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
864 IHTMLCommentElement *comment;
865 HRESULT hres;
867 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
868 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
869 return comment;
872 #define get_object_iface(u) _get_object_iface(__LINE__,u)
873 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
875 IHTMLObjectElement *obj;
876 HRESULT hres;
878 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
879 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
880 return obj;
883 #define get_style_iface(u) _get_style_iface(__LINE__,u)
884 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
886 IHTMLStyleElement *obj;
887 HRESULT hres;
889 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
890 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
891 return obj;
894 #define get_metaelem_iface(u) _get_metaelem_iface(__LINE__,u)
895 static IHTMLMetaElement *_get_metaelem_iface(unsigned line, IUnknown *unk)
897 IHTMLMetaElement *ret;
898 HRESULT hres;
900 hres = IUnknown_QueryInterface(unk, &IID_IHTMLMetaElement, (void**)&ret);
901 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLMetaElement: %08x\n", hres);
902 return ret;
905 #define get_link_iface(u) _get_link_iface(__LINE__,u)
906 static IHTMLLinkElement *_get_link_iface(unsigned line, IUnknown *unk)
908 IHTMLLinkElement *ret;
909 HRESULT hres;
911 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLinkElement, (void**)&ret);
912 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLinkElement: %08x\n", hres);
913 return ret;
916 #define get_iframe2_iface(u) _get_iframe2_iface(__LINE__,u)
917 static IHTMLIFrameElement2 *_get_iframe2_iface(unsigned line, IUnknown *unk)
919 IHTMLIFrameElement2 *ret;
920 HRESULT hres;
922 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement2, (void**)&ret);
923 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLIFrameElement: %08x\n", hres);
924 return ret;
927 #define get_button_iface(u) _get_button_iface(__LINE__,u)
928 static IHTMLButtonElement *_get_button_iface(unsigned line, IUnknown *unk)
930 IHTMLButtonElement *ret;
931 HRESULT hres;
933 hres = IUnknown_QueryInterface(unk, &IID_IHTMLButtonElement, (void**)&ret);
934 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLButtonElement: %08x\n", hres);
935 return ret;
938 #define get_label_iface(u) _get_label_iface(__LINE__,u)
939 static IHTMLLabelElement *_get_label_iface(unsigned line, IUnknown *unk)
941 IHTMLLabelElement *ret;
942 HRESULT hres;
944 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLabelElement, (void**)&ret);
945 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLabelElement: %08x\n", hres);
946 return ret;
949 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
950 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
952 IHTMLDOMNode *node = _get_node_iface(line, unk);
953 BSTR name;
954 HRESULT hres;
956 hres = IHTMLDOMNode_get_nodeName(node, &name);
957 IHTMLDOMNode_Release(node);
958 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
959 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
961 SysFreeString(name);
964 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
965 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
967 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
968 IDispatch *disp = (void*)0xdeadbeef;
969 IHTMLDocument2 *doc = NULL;
970 HRESULT hres;
972 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
973 IHTMLDOMNode2_Release(node);
974 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
976 if(disp) {
977 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
978 IDispatch_Release(disp);
979 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
982 return doc;
985 #define get_doc_window(d) _get_doc_window(__LINE__,d)
986 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
988 IHTMLWindow2 *window;
989 HRESULT hres;
991 window = NULL;
992 hres = IHTMLDocument2_get_parentWindow(doc, &window);
993 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
994 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
996 return window;
999 #define clone_node(n,d) _clone_node(__LINE__,n,d)
1000 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
1002 IHTMLDOMNode *node = _get_node_iface(line, unk);
1003 IHTMLDOMNode *ret = NULL;
1004 HRESULT hres;
1006 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
1007 IHTMLDOMNode_Release(node);
1008 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
1009 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
1011 return ret;
1015 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
1016 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
1018 IHTMLElement *elem = _get_elem_iface(line, unk);
1019 BSTR tag;
1020 HRESULT hres;
1022 hres = IHTMLElement_get_tagName(elem, &tag);
1023 IHTMLElement_Release(elem);
1024 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
1025 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
1027 SysFreeString(tag);
1030 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
1031 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
1033 _test_elem_tag(line, unk, elem_type_infos[type].tag);
1034 _test_ifaces(line, unk, elem_type_infos[type].iids);
1036 if(elem_type_infos[type].dispiid && type != ET_A)
1037 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
1040 #define get_node_type(n) _get_node_type(__LINE__,n)
1041 static LONG _get_node_type(unsigned line, IUnknown *unk)
1043 IHTMLDOMNode *node = _get_node_iface(line, unk);
1044 LONG type = -1;
1045 HRESULT hres;
1047 hres = IHTMLDOMNode_get_nodeType(node, &type);
1048 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1050 IHTMLDOMNode_Release(node);
1052 return type;
1055 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1056 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1058 IHTMLDOMNode *node = _get_node_iface(line, unk);
1059 IHTMLDOMChildrenCollection *col = NULL;
1060 IDispatch *disp;
1061 HRESULT hres;
1063 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1064 IHTMLDOMNode_Release(node);
1065 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1066 if(FAILED(hres))
1067 return NULL;
1069 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1070 IDispatch_Release(disp);
1071 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1073 return col;
1076 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1077 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
1079 IHTMLDOMNode *node = NULL;
1080 IDispatch *disp;
1081 HRESULT hres;
1083 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1084 ok(hres == S_OK, "item failed: %08x\n", hres);
1086 node = _get_node_iface(line, (IUnknown*)disp);
1087 IDispatch_Release(disp);
1089 return node;
1092 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
1093 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
1095 VARIANT value;
1096 BSTR tmp;
1097 HRESULT hres;
1099 VariantInit(&value);
1101 tmp = a2bstr(name);
1102 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
1103 SysFreeString(tmp);
1104 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
1106 if(exval) {
1107 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
1108 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
1109 }else {
1110 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
1113 VariantClear(&value);
1116 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
1117 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
1119 IHTMLElement *elem = _get_elem_iface(line, unk);
1120 IHTMLElement *off_parent;
1121 LONG l;
1122 HRESULT hres;
1124 hres = IHTMLElement_get_offsetTop(elem, &l);
1125 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1127 hres = IHTMLElement_get_offsetHeight(elem, &l);
1128 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1130 hres = IHTMLElement_get_offsetWidth(elem, &l);
1131 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1133 hres = IHTMLElement_get_offsetLeft(elem, &l);
1134 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1136 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1137 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1139 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1140 IHTMLElement_Release(off_parent);
1142 IHTMLElement_Release(elem);
1145 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1146 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1148 IHTMLWindow2 *window;
1149 IHTMLDocument2 *ret;
1150 HRESULT hres;
1152 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1153 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1155 hres = IHTMLWindow2_get_document(window, &ret);
1156 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1157 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1159 return ret;
1162 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1163 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1165 BSTR name;
1166 HRESULT hres;
1168 hres = IHTMLWindow2_get_name(window, &name);
1169 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1170 if(exname)
1171 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1172 else
1173 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1174 SysFreeString(name);
1177 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1178 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1180 BSTR str;
1181 HRESULT hres;
1183 str = a2bstr(name);
1184 hres = IHTMLWindow2_put_name(window, str);
1185 SysFreeString(str);
1186 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1188 _test_window_name(line, window, name);
1191 #define test_window_status(d) _test_window_status(__LINE__,d)
1192 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1194 BSTR status;
1195 HRESULT hres;
1197 status = (void*)0xdeadbeef;
1198 hres = IHTMLWindow2_get_status(window, &status);
1199 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1200 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1201 SysFreeString(status);
1204 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1205 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1207 BSTR str;
1208 HRESULT hres;
1210 str = a2bstr(status);
1211 hres = IHTMLWindow2_put_status(window, str);
1212 SysFreeString(str);
1213 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1216 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1217 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1219 LONG length = -1;
1220 HRESULT hres;
1222 hres = IHTMLWindow2_get_length(window, &length);
1223 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1224 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1227 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1228 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1230 IHTMLFrameBase2 *base2;
1231 IHTMLWindow2 *window;
1232 HRESULT hres;
1234 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1235 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1237 window = NULL;
1238 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1239 IHTMLFrameBase2_Release(base2);
1240 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1241 ok(window != NULL, "contentWindow = NULL\n");
1243 return window;
1246 static void test_get_set_attr(IHTMLDocument2 *doc)
1248 IHTMLElement *elem;
1249 IHTMLDocument3 *doc3;
1250 HRESULT hres;
1251 BSTR bstr;
1252 VARIANT val;
1254 /* grab an element to test with */
1255 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1256 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1258 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1259 IHTMLDocument3_Release(doc3);
1260 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1262 /* get a non-present attribute */
1263 bstr = a2bstr("notAnAttribute");
1264 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1265 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1266 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1267 VariantClear(&val);
1268 SysFreeString(bstr);
1270 /* get a present attribute */
1271 bstr = a2bstr("scrollHeight");
1272 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1273 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1274 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1275 VariantClear(&val);
1276 SysFreeString(bstr);
1278 /* create a new BSTR attribute */
1279 bstr = a2bstr("newAttribute");
1281 V_VT(&val) = VT_BSTR;
1282 V_BSTR(&val) = a2bstr("the value");
1283 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1284 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1285 VariantClear(&val);
1287 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1288 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1289 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1290 ok(strcmp_wa(V_BSTR(&val), "the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
1291 VariantClear(&val);
1293 /* overwrite the attribute with a BOOL */
1294 V_VT(&val) = VT_BOOL;
1295 V_BOOL(&val) = VARIANT_TRUE;
1296 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1297 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1298 VariantClear(&val);
1300 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1301 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1302 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1303 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1304 VariantClear(&val);
1306 SysFreeString(bstr);
1308 /* case-insensitive */
1309 bstr = a2bstr("newattribute");
1310 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1311 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1312 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1313 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1314 VariantClear(&val);
1315 SysFreeString(bstr);
1317 IHTMLElement_Release(elem);
1320 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1321 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1323 IHTMLElement *elem;
1324 IHTMLDocument3 *doc3;
1325 HRESULT hres;
1327 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1328 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1329 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1330 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1331 IHTMLDocument3_Release(doc3);
1333 return elem;
1336 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1337 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1339 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1340 BSTR str;
1341 HRESULT hres;
1343 hres = IHTMLAnchorElement_get_href(anchor, &str);
1344 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1345 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1346 SysFreeString(str);
1348 _test_disp_value(line, unk, exhref);
1351 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1352 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1354 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1355 BSTR str;
1356 HRESULT hres;
1358 str = a2bstr(exhref);
1359 hres = IHTMLAnchorElement_put_href(anchor, str);
1360 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1361 SysFreeString(str);
1363 _test_disp_value(line, unk, exhref);
1366 #define test_anchor_rel(a,h) _test_anchor_rel(__LINE__,a,h)
1367 static void _test_anchor_rel(unsigned line, IUnknown *unk, const char *exrel)
1369 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1370 BSTR str;
1371 HRESULT hres;
1373 hres = IHTMLAnchorElement_get_rel(anchor, &str);
1374 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1375 if(exrel)
1376 ok_(__FILE__,line)(!strcmp_wa(str, exrel), "rel = %s, expected %s\n", wine_dbgstr_w(str), exrel);
1377 else
1378 ok_(__FILE__,line)(!str, "rel = %s, expected NULL\n", wine_dbgstr_w(str));
1379 SysFreeString(str);
1382 #define test_anchor_put_rel(a,h) _test_anchor_put_rel(__LINE__,a,h)
1383 static void _test_anchor_put_rel(unsigned line, IUnknown *unk, const char *exrel)
1385 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1386 BSTR str;
1387 HRESULT hres;
1389 str = a2bstr(exrel);
1390 hres = IHTMLAnchorElement_put_rel(anchor, str);
1391 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1392 SysFreeString(str);
1395 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1396 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1398 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1399 BSTR str;
1400 HRESULT hres;
1402 hres = IHTMLAnchorElement_get_target(anchor, &str);
1403 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1404 if(target)
1405 ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1406 else
1407 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1408 SysFreeString(str);
1411 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1412 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1414 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1415 BSTR str;
1416 HRESULT hres;
1418 str = target ? a2bstr(target) : NULL;
1419 hres = IHTMLAnchorElement_put_target(anchor, str);
1420 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1421 SysFreeString(str);
1424 #define test_anchor_name(a,h) _test_anchor_name(__LINE__,a,h)
1425 static void _test_anchor_name(unsigned line, IUnknown *unk, const char *name)
1427 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1428 BSTR str;
1429 HRESULT hres;
1431 hres = IHTMLAnchorElement_get_name(anchor, &str);
1432 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1433 if(name)
1434 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
1435 else
1436 ok_(__FILE__,line)(str == NULL, "name = %s, expected NULL\n", wine_dbgstr_w(str));
1437 SysFreeString(str);
1440 #define test_anchor_put_name(a,h) _test_anchor_put_name(__LINE__,a,h)
1441 static void _test_anchor_put_name(unsigned line, IUnknown *unk, const char *name)
1443 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1444 BSTR str;
1445 HRESULT hres;
1447 str = name ? a2bstr(name) : NULL;
1448 hres = IHTMLAnchorElement_put_name(anchor, str);
1449 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1450 SysFreeString(str);
1452 _test_anchor_name(line, unk, name);
1455 #define test_anchor_hostname(a,h) _test_anchor_hostname(__LINE__,a,h)
1456 static void _test_anchor_hostname(unsigned line, IUnknown *unk, const char *hostname)
1458 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1459 BSTR str;
1460 HRESULT hres;
1462 hres = IHTMLAnchorElement_get_hostname(anchor, &str);
1463 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1464 if(hostname)
1465 ok_(__FILE__,line)(!strcmp_wa(str, hostname), "hostname = %s, expected %s\n", wine_dbgstr_w(str), hostname);
1466 else
1467 ok_(__FILE__,line)(str == NULL, "hostname = %s, expected NULL\n", wine_dbgstr_w(str));
1468 SysFreeString(str);
1471 #define test_anchor_hash(a,h) _test_anchor_hash(__LINE__,a,h)
1472 static void _test_anchor_hash(unsigned line, IHTMLElement *elem, const char *exhash)
1474 IHTMLAnchorElement *anchor = _get_anchor_iface(line, (IUnknown*)elem);
1475 BSTR str;
1476 HRESULT hres;
1478 hres = IHTMLAnchorElement_get_hash(anchor, &str);
1479 ok_(__FILE__,line)(hres == S_OK, "get_hash failed: %08x\n", hres);
1480 if(exhash)
1481 ok_(__FILE__,line)(!strcmp_wa(str, exhash), "hash = %s, expected %s\n", wine_dbgstr_w(str), exhash);
1482 else
1483 ok_(__FILE__,line)(!str, "hash = %s, expected NULL\n", wine_dbgstr_w(str));
1484 SysFreeString(str);
1487 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1488 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1490 BSTR bstr;
1491 HRESULT hres;
1493 hres = IHTMLOptionElement_get_text(option, &bstr);
1494 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1495 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1496 SysFreeString(bstr);
1499 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1500 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1502 BSTR bstr;
1503 HRESULT hres;
1505 bstr = a2bstr(text);
1506 hres = IHTMLOptionElement_put_text(option, bstr);
1507 SysFreeString(bstr);
1508 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1510 _test_option_text(line, option, text);
1513 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1514 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1516 BSTR bstr;
1517 HRESULT hres;
1519 hres = IHTMLOptionElement_get_value(option, &bstr);
1520 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1521 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1522 SysFreeString(bstr);
1525 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1526 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1528 BSTR bstr;
1529 HRESULT hres;
1531 bstr = a2bstr(value);
1532 hres = IHTMLOptionElement_put_value(option, bstr);
1533 SysFreeString(bstr);
1534 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1536 _test_option_value(line, option, value);
1539 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1540 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1542 VARIANT_BOOL b = 0x100;
1543 HRESULT hres;
1545 hres = IHTMLOptionElement_get_selected(option, &b);
1546 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1547 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1550 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1551 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1553 HRESULT hres;
1555 hres = IHTMLOptionElement_put_selected(option, b);
1556 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1557 _test_option_selected(line, option, b);
1560 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1561 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1563 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1564 BSTR value = (void*)0xdeadbeef;
1565 HRESULT hres;
1567 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1568 IHTMLTextAreaElement_Release(textarea);
1569 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1570 if(exval)
1571 ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1572 else
1573 ok_(__FILE__,line)(!value, "value = %p\n", value);
1574 SysFreeString(value);
1577 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1578 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1580 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1581 BSTR tmp = a2bstr(value);
1582 HRESULT hres;
1584 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1585 IHTMLTextAreaElement_Release(textarea);
1586 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1587 SysFreeString(tmp);
1589 _test_textarea_value(line, unk, value);
1592 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1593 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1595 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1596 VARIANT_BOOL b = 0x100;
1597 HRESULT hres;
1599 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1600 IHTMLTextAreaElement_Release(textarea);
1601 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1602 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1605 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1606 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1608 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1609 HRESULT hres;
1611 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1612 IHTMLTextAreaElement_Release(textarea);
1613 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1615 _test_textarea_readonly(line, unk, b);
1618 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1619 static void _test_textarea_type(unsigned line, IUnknown *unk)
1621 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1622 BSTR type = (void*)0xdeadbeef;
1623 HRESULT hres;
1625 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1626 IHTMLTextAreaElement_Release(textarea);
1627 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1628 ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1629 SysFreeString(type);
1632 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1633 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1635 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1636 BSTR text;
1637 HRESULT hres;
1639 text = a2bstr(extext);
1640 hres = IHTMLCommentElement_get_text(comment, &text);
1641 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1642 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1644 IHTMLCommentElement_Release(comment);
1645 SysFreeString(text);
1648 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1649 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1651 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1652 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1653 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1654 IHTMLDOMAttribute *attr;
1655 BSTR name = a2bstr("test");
1656 VARIANT val;
1657 HRESULT hres;
1659 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1660 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1661 ok(attr == NULL, "attr != NULL\n");
1663 V_VT(&val) = VT_I4;
1664 V_I4(&val) = 1234;
1665 hres = IHTMLElement_setAttribute(elem, name, val, 0);
1666 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1668 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1669 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1670 ok(attr != NULL, "attr == NULL\n");
1672 IHTMLDOMAttribute_Release(attr);
1673 IHTMLCommentElement_Release(comment);
1674 IHTMLElement_Release(elem);
1675 IHTMLElement4_Release(elem4);
1676 SysFreeString(name);
1679 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1680 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1682 IHTMLObjectElement *object = _get_object_iface(line, unk);
1683 LONG l;
1684 HRESULT hres;
1686 l = 0xdeadbeef;
1687 hres = IHTMLObjectElement_get_vspace(object, &l);
1688 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1689 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1690 IHTMLObjectElement_Release(object);
1693 #define test_object_name(a,b) _test_object_name(__LINE__,a,b)
1694 static void _test_object_name(unsigned line, IHTMLElement *elem, const char *exname)
1696 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1697 BSTR str;
1698 HRESULT hres;
1700 str = (void*)0xdeadbeef;
1701 hres = IHTMLObjectElement_get_name(object, &str);
1702 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1703 if(exname)
1704 ok_(__FILE__,line)(!strcmp_wa(str, exname), "name=%s, expected %s\n", wine_dbgstr_w(str), exname);
1705 else
1706 ok_(__FILE__,line)(!str, "name=%s, expected NULL\n", wine_dbgstr_w(str));
1707 SysFreeString(str);
1708 IHTMLObjectElement_Release(object);
1711 #define set_object_name(a,b) _set_object_name(__LINE__,a,b)
1712 static void _set_object_name(unsigned line, IHTMLElement *elem, const char *name)
1714 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1715 BSTR str;
1716 HRESULT hres;
1718 str = a2bstr(name);
1719 hres = IHTMLObjectElement_put_name(object, str);
1720 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1721 SysFreeString(str);
1722 IHTMLObjectElement_Release(object);
1724 _test_object_name(line, elem, name);
1727 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1728 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1729 const char *txt, const char *val)
1731 IHTMLOptionElementFactory *factory;
1732 IHTMLOptionElement *option;
1733 IHTMLWindow2 *window;
1734 VARIANT text, value, empty;
1735 HRESULT hres;
1737 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1738 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1740 hres = IHTMLWindow2_get_Option(window, &factory);
1741 IHTMLWindow2_Release(window);
1742 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1744 test_disp((IUnknown*)factory, &IID_IHTMLOptionElementFactory, "[object]");
1746 V_VT(&text) = VT_BSTR;
1747 V_BSTR(&text) = a2bstr(txt);
1748 V_VT(&value) = VT_BSTR;
1749 V_BSTR(&value) = a2bstr(val);
1750 V_VT(&empty) = VT_EMPTY;
1752 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1753 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1755 IHTMLOptionElementFactory_Release(factory);
1756 VariantClear(&text);
1757 VariantClear(&value);
1759 _test_option_text(line, option, txt);
1760 _test_option_value(line, option, val);
1761 _test_option_selected(line, option, VARIANT_FALSE);
1763 return option;
1766 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1767 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1769 LONG found = -1;
1770 HRESULT hres;
1772 hres = IHTMLImgElement_get_width(img, &found);
1773 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
1774 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
1777 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
1778 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
1780 HRESULT hres;
1782 hres = IHTMLImgElement_put_width(img, width);
1783 ok(hres == S_OK, "put_width failed: %08x\n", hres);
1785 _test_img_width(line, img, width);
1788 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
1789 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
1791 LONG found = -1;
1792 HRESULT hres;
1794 hres = IHTMLImgElement_get_height(img, &found);
1795 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
1796 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
1799 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
1800 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
1802 HRESULT hres;
1804 hres = IHTMLImgElement_put_height(img, height);
1805 ok(hres == S_OK, "put_height failed: %08x\n", hres);
1807 _test_img_height(line, img, height);
1810 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
1811 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
1812 LONG wdth, LONG hght)
1814 IHTMLImageElementFactory *factory;
1815 IHTMLImgElement *img;
1816 IHTMLWindow2 *window;
1817 VARIANT width, height;
1818 char buf[16];
1819 HRESULT hres;
1821 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1822 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1824 hres = IHTMLWindow2_get_Image(window, &factory);
1825 IHTMLWindow2_Release(window);
1826 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
1828 test_ifaces((IUnknown*)factory, img_factory_iids);
1829 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
1831 if(wdth >= 0){
1832 snprintf(buf, 16, "%d", wdth);
1833 V_VT(&width) = VT_BSTR;
1834 V_BSTR(&width) = a2bstr(buf);
1835 }else{
1836 V_VT(&width) = VT_EMPTY;
1837 wdth = 0;
1840 if(hght >= 0){
1841 snprintf(buf, 16, "%d", hght);
1842 V_VT(&height) = VT_BSTR;
1843 V_BSTR(&height) = a2bstr(buf);
1844 }else{
1845 V_VT(&height) = VT_EMPTY;
1846 hght = 0;
1849 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
1850 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1852 IHTMLImageElementFactory_Release(factory);
1853 VariantClear(&width);
1854 VariantClear(&height);
1856 if(SUCCEEDED(hres)) {
1857 _test_img_width(line, img, wdth);
1858 _test_img_height(line, img, hght);
1859 return img;
1862 return NULL;
1865 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
1866 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
1868 LONG len = 0xdeadbeef;
1869 HRESULT hres;
1871 hres = IHTMLSelectElement_get_length(select, &len);
1872 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
1873 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
1876 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
1877 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
1879 IHTMLSelectElement *select = _get_select_iface(line, unk);
1880 HRESULT hres;
1882 hres = IHTMLSelectElement_put_length(select, length);
1883 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
1884 _test_select_length(line, select, length);
1885 IHTMLSelectElement_Release(select);
1888 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
1889 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1891 LONG idx = 0xdeadbeef;
1892 HRESULT hres;
1894 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
1895 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1896 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
1899 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
1900 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
1902 HRESULT hres;
1904 hres = IHTMLSelectElement_put_selectedIndex(select, index);
1905 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
1906 _test_select_selidx(line, select, index);
1909 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
1910 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
1912 BSTR val;
1913 HRESULT hres;
1915 hres = IHTMLSelectElement_get_value(select, &val);
1916 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1917 if(exval)
1918 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
1919 else
1920 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
1921 SysFreeString(val);
1924 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
1925 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
1927 BSTR bstr;
1928 HRESULT hres;
1930 bstr = a2bstr(val);
1931 hres = IHTMLSelectElement_put_value(select, bstr);
1932 SysFreeString(bstr);
1933 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
1936 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
1937 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
1939 BSTR type;
1940 HRESULT hres;
1942 hres = IHTMLSelectElement_get_type(select, &type);
1943 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
1944 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
1945 SysFreeString(type);
1948 #define test_select_multiple(s,t) _test_select_multiple(__LINE__,s,t)
1949 static void _test_select_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exmultiple)
1951 VARIANT_BOOL b = 100;
1952 HRESULT hres;
1954 hres = IHTMLSelectElement_get_multiple(select, &b);
1955 ok_(__FILE__,line) (hres == S_OK, "get_multiple failed: %08x\n", hres);
1956 ok_(__FILE__,line) (b == exmultiple, "multiple=%x, expected %x\n", b, exmultiple);
1959 #define test_select_set_multiple(s,v) _test_select_set_multiple(__LINE__,s,v)
1960 static void _test_select_set_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL val)
1962 HRESULT hres;
1964 hres = IHTMLSelectElement_put_multiple(select, val);
1965 ok_(__FILE__,line) (hres == S_OK, "put_multiple failed: %08x\n", hres);
1967 _test_select_multiple(line, select, val);
1970 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
1971 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
1973 BSTR text;
1974 HRESULT hres;
1976 hres = IHTMLTxtRange_get_text(range, &text);
1977 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
1979 if(extext) {
1980 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
1981 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
1982 }else {
1983 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
1986 SysFreeString(text);
1990 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
1991 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
1993 HRESULT hres;
1995 hres = IHTMLTxtRange_collapse(range, b);
1996 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
1997 _test_range_text(line, range, NULL);
2000 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
2001 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
2002 VARIANT_BOOL exb, const char *extext)
2004 VARIANT_BOOL b = 0xe0e0;
2005 HRESULT hres;
2007 hres = IHTMLTxtRange_expand(range, unit, &b);
2008 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
2009 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
2010 _test_range_text(line, range, extext);
2013 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
2014 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2016 LONG c = 0xdeadbeef;
2017 HRESULT hres;
2019 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
2020 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2021 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2022 _test_range_text(line, range, NULL);
2025 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
2026 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
2027 LPWSTR unit, LONG cnt, LONG excnt)
2029 LONG c = 0xdeadbeef;
2030 HRESULT hres;
2032 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
2033 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2034 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2037 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
2038 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2040 LONG c = 0xdeadbeef;
2041 HRESULT hres;
2043 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
2044 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2045 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2048 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
2049 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
2051 HRESULT hres;
2052 BSTR bstr = a2bstr(text);
2054 hres = IHTMLTxtRange_put_text(range, bstr);
2055 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
2056 SysFreeString(bstr);
2057 _test_range_text(line, range, NULL);
2060 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
2061 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2063 VARIANT_BOOL b;
2064 HRESULT hres;
2066 b = 0xe0e0;
2067 hres = IHTMLTxtRange_inRange(range1, range2, &b);
2068 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2069 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2072 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
2073 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2075 VARIANT_BOOL b;
2076 HRESULT hres;
2078 b = 0xe0e0;
2079 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
2080 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2081 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2083 b = 0xe0e0;
2084 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
2085 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
2086 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
2088 if(exb) {
2089 test_range_inrange(range1, range2, VARIANT_TRUE);
2090 test_range_inrange(range2, range1, VARIANT_TRUE);
2094 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
2095 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
2097 IHTMLElement *elem;
2098 HRESULT hres;
2100 hres = IHTMLTxtRange_parentElement(range, &elem);
2101 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
2103 _test_elem_type(line, (IUnknown*)elem, type);
2105 IHTMLElement_Release(elem);
2108 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
2109 static void _test_elem_collection(unsigned line, IUnknown *unk,
2110 const elem_type_t *elem_types, LONG exlen)
2112 IHTMLElementCollection *col;
2113 IEnumVARIANT *enum_var;
2114 IUnknown *enum_unk;
2115 ULONG fetched;
2116 LONG len;
2117 DWORD i;
2118 VARIANT name, index, v, vs[5];
2119 IDispatch *disp, *disp2;
2120 HRESULT hres;
2122 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
2123 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2125 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
2127 hres = IHTMLElementCollection_get_length(col, &len);
2128 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2129 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
2131 if(len > exlen)
2132 len = exlen;
2134 V_VT(&index) = VT_EMPTY;
2136 hres = IHTMLElementCollection_get__newEnum(col, &enum_unk);
2137 ok_(__FILE__,line)(hres == S_OK, "_newEnum failed: %08x\n", hres);
2139 hres = IUnknown_QueryInterface(enum_unk, &IID_IEnumVARIANT, (void**)&enum_var);
2140 IUnknown_Release(enum_unk);
2141 ok_(__FILE__,line)(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
2143 for(i=0; i<len; i++) {
2144 V_VT(&name) = VT_I4;
2145 V_I4(&name) = i;
2146 disp = (void*)0xdeadbeef;
2147 hres = IHTMLElementCollection_item(col, name, index, &disp);
2148 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2149 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
2150 if(FAILED(hres) || !disp)
2151 continue;
2153 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
2155 if(!i) {
2156 V_VT(&name) = VT_UINT;
2157 V_I4(&name) = 0;
2158 disp2 = (void*)0xdeadbeef;
2159 hres = IHTMLElementCollection_item(col, name, index, &disp2);
2160 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2161 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
2162 if(disp2)
2163 IDispatch_Release(disp2);
2166 fetched = 0;
2167 V_VT(&v) = VT_ERROR;
2168 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
2169 ok_(__FILE__,line)(hres == S_OK, "Next failed: %08x\n", hres);
2170 if(i)
2171 ok_(__FILE__,line)(fetched == 1, "fetched = %d\n", fetched);
2172 ok_(__FILE__,line)(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
2173 ok_(__FILE__,line)(iface_cmp((IUnknown*)disp, (IUnknown*)V_DISPATCH(&v)), "disp != V_DISPATCH(v)\n");
2174 IDispatch_Release(V_DISPATCH(&v));
2176 IDispatch_Release(disp);
2179 fetched = 0xdeadbeef;
2180 V_VT(&v) = VT_BOOL;
2181 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
2182 ok_(__FILE__,line)(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
2183 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2184 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2186 hres = IEnumVARIANT_Reset(enum_var);
2187 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2189 fetched = 0xdeadbeef;
2190 V_VT(&v) = VT_BOOL;
2191 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
2192 ok_(__FILE__,line)(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
2193 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2194 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2196 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
2197 ok_(__FILE__,line)(hres == S_OK, "Skip failed: %08x\n", hres);
2199 memset(vs, 0, sizeof(vs));
2200 fetched = 0;
2201 hres = IEnumVARIANT_Next(enum_var, sizeof(vs)/sizeof(*vs), vs, &fetched);
2202 ok_(__FILE__,line)(hres == S_FALSE, "Next failed: %08x\n", hres);
2203 ok_(__FILE__,line)(fetched == (len > 2 ? 2 : len), "fetched = %d\n", fetched);
2204 if(len) {
2205 ok_(__FILE__,line)(V_VT(vs) == VT_DISPATCH && V_DISPATCH(vs), "V_VT(vs[0]) = %d\n", V_VT(vs));
2206 IDispatch_Release(V_DISPATCH(vs));
2208 if(len > 1) {
2209 ok_(__FILE__,line)(V_VT(vs+1) == VT_DISPATCH && V_DISPATCH(vs+1), "V_VT(vs[1]) = %d\n", V_VT(vs+1));
2210 IDispatch_Release(V_DISPATCH(vs+1));
2213 hres = IEnumVARIANT_Reset(enum_var);
2214 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2216 hres = IEnumVARIANT_Skip(enum_var, len+1);
2217 ok_(__FILE__,line)(hres == S_FALSE, "Skip failed: %08x\n", hres);
2219 IEnumVARIANT_Release(enum_var);
2221 V_VT(&name) = VT_I4;
2222 V_I4(&name) = len;
2223 disp = (void*)0xdeadbeef;
2224 hres = IHTMLElementCollection_item(col, name, index, &disp);
2225 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2226 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2228 V_VT(&name) = VT_I4;
2229 V_I4(&name) = -1;
2230 disp = (void*)0xdeadbeef;
2231 hres = IHTMLElementCollection_item(col, name, index, &disp);
2232 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2233 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2235 IHTMLElementCollection_Release(col);
2238 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
2239 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
2241 IHTMLElement *elem = _get_elem_iface(line, unk);
2242 IDispatch *disp;
2243 HRESULT hres;
2245 hres = IHTMLElement_get_all(elem, &disp);
2246 IHTMLElement_Release(elem);
2247 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2249 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
2250 IDispatch_Release(disp);
2253 #define test_doc_all(a,b,c) _test_doc_all(__LINE__,a,b,c)
2254 static void _test_doc_all(unsigned line, IHTMLDocument2 *doc, const elem_type_t *elem_types, LONG exlen)
2256 IHTMLElementCollection *col;
2257 HRESULT hres;
2259 hres = IHTMLDocument2_get_all(doc, &col);
2260 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2262 _test_elem_collection(line, (IUnknown*)col, elem_types, exlen);
2263 IHTMLElementCollection_Release(col);
2266 #define test_elem_getelembytag(a,b,c,d) _test_elem_getelembytag(__LINE__,a,b,c,d)
2267 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen, IHTMLElement **ret)
2269 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2270 IHTMLElementCollection *col = NULL;
2271 elem_type_t *types = NULL;
2272 BSTR tmp;
2273 int i;
2274 HRESULT hres;
2276 tmp = a2bstr(elem_type_infos[type].tag);
2277 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
2278 SysFreeString(tmp);
2279 IHTMLElement2_Release(elem);
2280 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
2281 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
2283 if(exlen) {
2284 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
2285 for(i=0; i<exlen; i++)
2286 types[i] = type;
2289 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2291 HeapFree(GetProcessHeap(), 0, types);
2293 if(ret) {
2294 IDispatch *disp;
2295 VARIANT v;
2297 V_VT(&v) = VT_I4;
2298 V_I4(&v) = 0;
2299 disp = NULL;
2300 hres = IHTMLElementCollection_item(col, v, v, &disp);
2301 ok(hres == S_OK, "item failed: %08x\n", hres);
2302 ok(disp != NULL, "disp == NULL\n");
2303 *ret = _get_elem_iface(line, (IUnknown*)disp);
2304 IDispatch_Release(disp);
2307 IHTMLElementCollection_Release(col);
2310 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
2311 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
2313 BSTR text = NULL;
2314 HRESULT hres;
2316 hres = IHTMLElement_get_innerText(elem, &text);
2317 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
2318 if(extext)
2319 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
2320 wine_dbgstr_w(text), extext);
2321 else
2322 ok_(__FILE__,line) (!text, "get_innerText returned %s expected NULL\n", wine_dbgstr_w(text));
2323 SysFreeString(text);
2326 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
2327 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
2329 IHTMLDOMChildrenCollection *col;
2330 BSTR str;
2331 HRESULT hres;
2333 str = a2bstr(text);
2334 hres = IHTMLElement_put_innerText(elem, str);
2335 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
2336 SysFreeString(str);
2338 _test_elem_innertext(line, elem, text);
2341 col = _get_child_nodes(line, (IUnknown*)elem);
2342 ok(col != NULL, "col == NULL\n");
2343 if(col) {
2344 LONG length = 0, type;
2345 IHTMLDOMNode *node;
2347 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
2348 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2349 ok(length == 1, "length = %d\n", length);
2351 node = _get_child_item(line, col, 0);
2352 ok(node != NULL, "node == NULL\n");
2353 if(node) {
2354 type = _get_node_type(line, (IUnknown*)node);
2355 ok(type == 3, "type=%d\n", type);
2356 IHTMLDOMNode_Release(node);
2359 IHTMLDOMChildrenCollection_Release(col);
2364 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2365 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2367 IHTMLElement *elem = _get_elem_iface(line, unk);
2368 BSTR html;
2369 HRESULT hres;
2371 hres = IHTMLElement_get_innerHTML(elem, &html);
2372 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2373 if(inner_html)
2374 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2375 else
2376 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2378 IHTMLElement_Release(elem);
2379 SysFreeString(html);
2382 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2383 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2385 IHTMLElement *elem = _get_elem_iface(line, unk);
2386 BSTR html;
2387 HRESULT hres;
2389 html = a2bstr(inner_html);
2390 hres = IHTMLElement_put_innerHTML(elem, html);
2391 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2393 IHTMLElement_Release(elem);
2394 SysFreeString(html);
2397 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2398 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2400 IHTMLElement *elem = _get_elem_iface(line, unk);
2401 BSTR html;
2402 HRESULT hres;
2404 html = a2bstr(outer_html);
2405 hres = IHTMLElement_put_outerHTML(elem, html);
2406 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2408 IHTMLElement_Release(elem);
2409 SysFreeString(html);
2412 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2413 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2415 IHTMLElement *elem = _get_elem_iface(line, unk);
2416 BSTR html;
2417 HRESULT hres;
2419 hres = IHTMLElement_get_outerHTML(elem, &html);
2420 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2421 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2423 IHTMLElement_Release(elem);
2424 SysFreeString(html);
2427 #define test_elem_contains(a,b,c) _test_elem_contains(__LINE__,a,b,c)
2428 static void _test_elem_contains(unsigned line, IHTMLElement *elem, IHTMLElement *elem2, VARIANT_BOOL exval)
2430 VARIANT_BOOL b;
2431 HRESULT hres;
2433 b = 100;
2434 hres = IHTMLElement_contains(elem, elem2, &b);
2435 ok_(__FILE__,line)(hres == S_OK, "contains failed: %08x\n", hres);
2436 ok_(__FILE__,line)(b == exval, "contains returned %x, expected %x\n", b, exval);
2439 #define get_first_child(n) _get_first_child(__LINE__,n)
2440 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2442 IHTMLDOMNode *node = _get_node_iface(line, unk);
2443 IHTMLDOMNode *child = NULL;
2444 HRESULT hres;
2446 hres = IHTMLDOMNode_get_firstChild(node, &child);
2447 IHTMLDOMNode_Release(node);
2448 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2450 return child;
2453 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2454 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2456 IHTMLDOMNode *node = _get_node_iface(line, unk);
2457 VARIANT_BOOL b = 0xdead;
2458 HRESULT hres;
2460 hres = IHTMLDOMNode_hasChildNodes(node, &b);
2461 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2462 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2464 IHTMLDOMNode_Release(node);
2467 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2468 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2470 IHTMLDOMNode *node = _get_node_iface(line, unk);
2471 IHTMLDOMNode *parent;
2472 HRESULT hres;
2474 hres = IHTMLDOMNode_get_parentNode(node, &parent);
2475 IHTMLDOMNode_Release(node);
2476 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2478 return parent;
2481 #define node_get_next(u) _node_get_next(__LINE__,u)
2482 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2484 IHTMLDOMNode *node = _get_node_iface(line, unk);
2485 IHTMLDOMNode *next;
2486 HRESULT hres;
2488 hres = IHTMLDOMNode_get_nextSibling(node, &next);
2489 IHTMLDOMNode_Release(node);
2490 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2492 return next;
2495 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2496 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2498 IHTMLDOMNode *node = _get_node_iface(line, unk);
2499 IHTMLDOMNode *prev;
2500 HRESULT hres;
2502 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2503 IHTMLDOMNode_Release(node);
2504 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2506 return prev;
2509 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2510 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2512 IHTMLElement *elem = _get_elem_iface(line, unk);
2513 IHTMLElement *parent;
2514 HRESULT hres;
2516 hres = IHTMLElement_get_parentElement(elem, &parent);
2517 IHTMLElement_Release(elem);
2518 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2520 return parent;
2523 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2524 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2526 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2527 VARIANT_BOOL disabled = 100;
2528 HRESULT hres;
2530 if (!elem3) return;
2531 hres = IHTMLElement3_get_disabled(elem3, &disabled);
2532 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2533 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2534 IHTMLElement3_Release(elem3);
2537 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2538 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2540 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2541 HRESULT hres;
2543 if (!elem3) return;
2544 hres = IHTMLElement3_put_disabled(elem3, b);
2545 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2547 IHTMLElement3_Release(elem3);
2548 _test_elem3_get_disabled(line, unk, b);
2551 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2552 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2554 VARIANT_BOOL disabled = 100;
2555 HRESULT hres;
2557 hres = IHTMLSelectElement_get_disabled(select, &disabled);
2558 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2559 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2561 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2564 static void test_select_remove(IHTMLSelectElement *select)
2566 HRESULT hres;
2568 hres = IHTMLSelectElement_remove(select, 3);
2569 ok(hres == S_OK, "remove failed: %08x, expected S_OK\n", hres);
2570 test_select_length(select, 2);
2572 hres = IHTMLSelectElement_remove(select, -1);
2573 todo_wine
2574 ok(hres == E_INVALIDARG, "remove failed: %08x, expected E_INVALIDARG\n", hres);
2575 test_select_length(select, 2);
2577 hres = IHTMLSelectElement_remove(select, 0);
2578 ok(hres == S_OK, "remove failed:%08x\n", hres);
2579 test_select_length(select, 1);
2582 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2583 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2585 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2586 LONG length;
2587 HRESULT hres;
2589 hres = IHTMLDOMTextNode_get_length(text, &length);
2590 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2591 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2592 IHTMLDOMTextNode_Release(text);
2595 #define test_text_data(a,b) _test_text_data(__LINE__,a,b)
2596 static void _test_text_data(unsigned line, IUnknown *unk, const char *exdata)
2598 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2599 BSTR str;
2600 HRESULT hres;
2602 hres = IHTMLDOMTextNode_get_data(text, &str);
2603 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2604 ok_(__FILE__,line)(!strcmp_wa(str, exdata), "data = %s, expected %s\n", wine_dbgstr_w(str), exdata);
2605 IHTMLDOMTextNode_Release(text);
2606 SysFreeString(str);
2609 #define set_text_data(a,b) _set_text_data(__LINE__,a,b)
2610 static void _set_text_data(unsigned line, IUnknown *unk, const char *data)
2612 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2613 BSTR str = a2bstr(data);
2614 HRESULT hres;
2616 hres = IHTMLDOMTextNode_put_data(text, str);
2617 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2618 IHTMLDOMTextNode_Release(text);
2619 SysFreeString(str);
2622 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2623 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2625 HRESULT hres;
2627 hres = IHTMLSelectElement_put_disabled(select, b);
2628 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2630 _test_select_get_disabled(line, select, b);
2633 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2634 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2636 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2637 IHTMLTextContainer *txtcont;
2638 LONG l = -1, l2 = -1;
2639 HRESULT hres;
2641 hres = IHTMLElement2_get_scrollHeight(elem, &l);
2642 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2643 IHTMLElement2_Release(elem);
2645 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2646 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2648 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2649 IHTMLTextContainer_Release(txtcont);
2650 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2651 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
2653 return l;
2656 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
2657 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
2659 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2660 IHTMLTextContainer *txtcont;
2661 LONG l = -1, l2 = -1;
2662 HRESULT hres;
2664 hres = IHTMLElement2_get_scrollWidth(elem, &l);
2665 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
2666 IHTMLElement2_Release(elem);
2668 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2669 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2671 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
2672 IHTMLTextContainer_Release(txtcont);
2673 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
2674 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
2676 return l;
2679 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
2680 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
2682 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2683 IHTMLTextContainer *txtcont;
2684 LONG l = -1, l2 = -1;
2685 HRESULT hres;
2687 hres = IHTMLElement2_get_scrollTop(elem, &l);
2688 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2689 IHTMLElement2_Release(elem);
2691 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2692 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2694 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
2695 IHTMLTextContainer_Release(txtcont);
2696 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
2697 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
2699 return l;
2702 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
2703 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
2705 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2706 IHTMLTextContainer *txtcont;
2707 LONG l = -1, l2 = -1;
2708 HRESULT hres;
2710 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
2711 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
2713 hres = IHTMLElement2_get_scrollLeft(elem, &l);
2714 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
2715 IHTMLElement2_Release(elem);
2717 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2718 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2720 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
2721 IHTMLTextContainer_Release(txtcont);
2722 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
2723 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
2726 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
2727 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
2729 IHTMLImgElement *img = _get_img_iface(line, unk);
2730 BSTR src;
2731 HRESULT hres;
2733 hres = IHTMLImgElement_get_src(img, &src);
2734 IHTMLImgElement_Release(img);
2735 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
2736 ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
2737 "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
2738 SysFreeString(src);
2741 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
2742 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
2744 IHTMLImgElement *img = _get_img_iface(line, unk);
2745 BSTR tmp;
2746 HRESULT hres;
2748 tmp = a2bstr(src);
2749 hres = IHTMLImgElement_put_src(img, tmp);
2750 IHTMLImgElement_Release(img);
2751 SysFreeString(tmp);
2752 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
2755 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
2756 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
2758 IHTMLImgElement *img = _get_img_iface(line, unk);
2759 BSTR alt;
2760 HRESULT hres;
2762 hres = IHTMLImgElement_get_alt(img, &alt);
2763 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2764 if(exalt)
2765 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
2766 else
2767 ok_(__FILE__,line) (!alt, "alt != NULL\n");
2768 SysFreeString(alt);
2771 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
2772 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
2774 IHTMLImgElement *img = _get_img_iface(line, unk);
2775 BSTR tmp;
2776 HRESULT hres;
2778 tmp = a2bstr(alt);
2779 hres = IHTMLImgElement_put_alt(img, tmp);
2780 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
2781 SysFreeString(tmp);
2783 _test_img_alt(line, unk, alt);
2786 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
2787 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
2789 IHTMLImgElement *img = _get_img_iface(line, unk);
2790 BSTR sName;
2791 HRESULT hres;
2793 hres = IHTMLImgElement_get_name(img, &sName);
2794 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
2795 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
2796 IHTMLImgElement_Release(img);
2797 SysFreeString(sName);
2800 #define test_img_complete(a,b) _test_img_complete(__LINE__,a,b)
2801 static void _test_img_complete(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
2803 IHTMLImgElement *img = _get_img_iface(line, (IUnknown*)elem);
2804 VARIANT_BOOL b = 100;
2805 HRESULT hres;
2807 hres = IHTMLImgElement_get_complete(img, &b);
2808 ok_(__FILE__,line) (hres == S_OK, "get_complete failed: %08x\n", hres);
2809 ok_(__FILE__,line) (b == exb, "complete = %x, expected %x\n", b, exb);
2810 IHTMLImgElement_Release(img);
2813 static void test_dynamic_properties(IHTMLElement *elem)
2815 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
2816 IDispatchEx *dispex;
2817 BSTR name, attr1 = SysAllocString(attr1W);
2818 VARIANT_BOOL succ;
2819 VARIANT val;
2820 int checked_no = 0;
2821 DISPID id = DISPID_STARTENUM;
2822 HRESULT hres;
2824 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2825 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2827 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
2828 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
2829 ok(succ, "removeAttribute set succ to FALSE\n");
2831 while(1) {
2832 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2833 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
2834 if(hres != S_OK)
2835 break;
2837 hres = IDispatchEx_GetMemberName(dispex, id, &name);
2838 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2840 if(!strcmp_wa(name, "attr1"))
2841 ok(0, "attr1 should be removed\n");
2842 else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
2843 checked_no++;
2844 SysFreeString(name);
2846 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
2847 IDispatchEx_Release(dispex);
2849 V_VT(&val) = VT_BSTR;
2850 V_BSTR(&val) = attr1;
2851 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
2852 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2853 SysFreeString(attr1);
2856 #define test_attr_node_name(a,b) _test_attr_node_name(__LINE__,a,b)
2857 static void _test_attr_node_name(unsigned line, IHTMLDOMAttribute *attr, const char *exname)
2859 BSTR str;
2860 HRESULT hres;
2862 hres = IHTMLDOMAttribute_get_nodeName(attr, &str);
2863 ok_(__FILE__,line)(hres == S_OK, "get_nodeName failed: %08x\n", hres);
2864 ok_(__FILE__,line)(!strcmp_wa(str, exname), "node name is %s, expected %s\n", wine_dbgstr_w(str), exname);
2865 SysFreeString(str);
2868 static void test_attr_collection_disp(IDispatch *disp)
2870 IDispatchEx *dispex;
2871 IHTMLDOMAttribute *attr;
2872 DISPPARAMS dp = {NULL, NULL, 0, 0};
2873 VARIANT var;
2874 EXCEPINFO ei;
2875 DISPID id;
2876 BSTR bstr;
2877 HRESULT hres;
2879 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
2880 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2882 bstr = a2bstr("0");
2883 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2884 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2885 SysFreeString(bstr);
2887 VariantInit(&var);
2888 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2889 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2890 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2891 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2892 VariantClear(&var);
2894 bstr = a2bstr("attr1");
2895 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
2896 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2897 SysFreeString(bstr);
2899 VariantInit(&var);
2900 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2901 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2902 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2903 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
2904 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
2905 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2907 test_attr_node_name(attr, "attr1");
2909 IHTMLDOMAttribute_Release(attr);
2910 VariantClear(&var);
2912 IDispatchEx_Release(dispex);
2915 static void test_attr_collection(IHTMLElement *elem)
2917 static const WCHAR testW[] = {'t','e','s','t',0};
2919 IHTMLDOMNode *node;
2920 IDispatch *disp, *attr;
2921 IHTMLDOMAttribute *dom_attr;
2922 IHTMLAttributeCollection *attr_col;
2923 BSTR name = SysAllocString(testW);
2924 VARIANT id, val;
2925 LONG i, len, checked;
2926 HRESULT hres;
2928 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
2929 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2931 hres = IHTMLDOMNode_get_attributes(node, &disp);
2932 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2934 hres = IHTMLDOMNode_get_attributes(node, &attr);
2935 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
2936 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
2937 IDispatch_Release(attr);
2938 IHTMLDOMNode_Release(node);
2940 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
2941 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
2943 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
2944 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2946 V_VT(&val) = VT_I4;
2947 V_I4(&val) = 1;
2948 hres = IHTMLElement_setAttribute(elem, name, val, 0);
2949 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2950 SysFreeString(name);
2952 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
2953 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2954 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
2956 checked = 0;
2957 for(i=0; i<len; i++) {
2958 V_VT(&id) = VT_I4;
2959 V_I4(&id) = i;
2960 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
2961 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
2963 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
2964 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
2965 IDispatch_Release(attr);
2967 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
2968 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
2970 if(!strcmp_wa(name, "id")) {
2971 checked++;
2972 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2973 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2974 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
2975 ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2976 } else if(!strcmp_wa(name, "attr1")) {
2977 checked++;
2978 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2979 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2980 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
2981 ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2982 } else if(!strcmp_wa(name, "attr2")) {
2983 checked++;
2984 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2985 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2986 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
2987 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
2988 } else if(!strcmp_wa(name, "attr3")) {
2989 checked++;
2990 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2991 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2992 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
2993 ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
2994 } else if(!strcmp_wa(name, "test")) {
2995 checked++;
2996 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
2997 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
2998 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
2999 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
3002 IHTMLDOMAttribute_Release(dom_attr);
3003 SysFreeString(name);
3004 VariantClear(&val);
3006 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
3008 V_I4(&id) = len;
3009 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3010 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3012 V_VT(&id) = VT_BSTR;
3013 V_BSTR(&id) = a2bstr("nonexisting");
3014 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3015 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3016 VariantClear(&id);
3018 test_attr_collection_disp(disp);
3020 IDispatch_Release(disp);
3021 IHTMLAttributeCollection_Release(attr_col);
3024 #define test_attr_specified(a,b) _test_attr_specified(__LINE__,a,b)
3025 static void _test_attr_specified(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
3027 VARIANT_BOOL specified;
3028 HRESULT hres;
3030 hres = IHTMLDOMAttribute_get_specified(attr, &specified);
3031 ok_(__FILE__,line)(hres == S_OK, "get_specified failed: %08x\n", hres);
3032 ok_(__FILE__,line)(specified == expected, "specified = %x, expected %x\n", specified, expected);
3035 static void test_contenteditable(IUnknown *unk)
3037 IHTMLElement3 *elem3 = get_elem3_iface(unk);
3038 HRESULT hres;
3039 BSTR str, strDefault;
3041 hres = IHTMLElement3_get_contentEditable(elem3, &strDefault);
3042 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3044 str = a2bstr("true");
3045 hres = IHTMLElement3_put_contentEditable(elem3, str);
3046 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(str), hres);
3047 SysFreeString(str);
3048 hres = IHTMLElement3_get_contentEditable(elem3, &str);
3049 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3050 ok(!strcmp_wa(str, "true"), "Got %s, expected %s\n", wine_dbgstr_w(str), "true");
3052 /* Restore origin contentEditable */
3053 hres = IHTMLElement3_put_contentEditable(elem3, strDefault);
3054 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(strDefault), hres);
3055 SysFreeString(strDefault);
3057 IHTMLElement3_Release(elem3);
3060 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
3061 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
3063 BSTR type;
3064 HRESULT hres;
3066 hres = IHTMLInputElement_get_type(input, &type);
3067 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
3068 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
3069 SysFreeString(type);
3072 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
3073 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
3075 BSTR name = (BSTR)0xdeadbeef;
3076 HRESULT hres;
3078 hres = IHTMLInputElement_get_name(input, &name);
3079 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
3080 if(exname)
3081 ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
3082 else
3083 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
3084 SysFreeString(name);
3087 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
3088 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
3090 BSTR tmp = a2bstr(name);
3091 HRESULT hres;
3093 hres = IHTMLInputElement_put_name(input, tmp);
3094 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
3095 SysFreeString(tmp);
3097 _test_input_name(line, input, name);
3100 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
3101 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3103 VARIANT_BOOL disabled = 100;
3104 HRESULT hres;
3106 hres = IHTMLInputElement_get_disabled(input, &disabled);
3107 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3108 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3110 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
3113 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
3114 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3116 HRESULT hres;
3118 hres = IHTMLInputElement_put_disabled(input, b);
3119 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3121 _test_input_get_disabled(line, input, b);
3124 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
3125 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3127 VARIANT_BOOL checked = 100;
3128 HRESULT hres;
3130 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
3131 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3132 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3135 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
3136 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3138 HRESULT hres;
3140 hres = IHTMLInputElement_put_defaultChecked(input, b);
3141 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3143 _test_input_get_defaultchecked(line, input, b);
3146 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
3147 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3149 VARIANT_BOOL checked = 100;
3150 HRESULT hres;
3152 hres = IHTMLInputElement_get_checked(input, &checked);
3153 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
3154 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3157 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
3158 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3160 HRESULT hres;
3162 hres = IHTMLInputElement_put_checked(input, b);
3163 ok_(__FILE__,line) (hres == S_OK, "put_checked failed: %08x\n", hres);
3165 _test_input_get_checked(line, input, b);
3168 #define test_input_maxlength(i,b) _test_input_maxlength(__LINE__,i,b)
3169 static void _test_input_maxlength(unsigned line, IHTMLInputElement *input, LONG exl)
3171 LONG maxlength = 0xdeadbeef;
3172 HRESULT hres;
3174 hres = IHTMLInputElement_get_maxLength(input, &maxlength);
3175 ok_(__FILE__,line) (hres == S_OK, "get_maxLength failed: %08x\n", hres);
3176 ok_(__FILE__,line) (maxlength == exl, "maxLength=%x, expected %d\n", maxlength, exl);
3179 #define test_input_set_maxlength(i,b) _test_input_set_maxlength(__LINE__,i,b)
3180 static void _test_input_set_maxlength(unsigned line, IHTMLInputElement *input, LONG l)
3182 HRESULT hres;
3184 hres = IHTMLInputElement_put_maxLength(input, l);
3185 ok_(__FILE__,line) (hres == S_OK, "put_maxLength failed: %08x\n", hres);
3187 _test_input_maxlength(line, input, l);
3190 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
3191 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
3193 IHTMLInputElement *input;
3194 BSTR bstr;
3195 HRESULT hres;
3197 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3198 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3199 if(FAILED(hres))
3200 return;
3202 hres = IHTMLInputElement_get_value(input, &bstr);
3203 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3204 if(exval)
3205 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
3206 else
3207 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
3208 SysFreeString(bstr);
3209 IHTMLInputElement_Release(input);
3212 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
3213 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
3215 IHTMLInputElement *input;
3216 BSTR bstr;
3217 HRESULT hres;
3219 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3220 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3221 if(FAILED(hres))
3222 return;
3224 bstr = a2bstr(val);
3225 hres = IHTMLInputElement_put_value(input, bstr);
3226 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3227 SysFreeString(bstr);
3228 IHTMLInputElement_Release(input);
3230 _test_input_value(line, unk, val);
3233 #define test_input_defaultValue(o,t) _test_input_defaultValue(__LINE__,o,t)
3234 static void _test_input_defaultValue(unsigned line, IUnknown *unk, const char *exval)
3236 IHTMLInputElement *input;
3237 BSTR str;
3238 HRESULT hres;
3240 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3241 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3242 if(FAILED(hres))
3243 return;
3245 hres = IHTMLInputElement_get_defaultValue(input, &str);
3246 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3247 if(exval)
3248 ok_(__FILE__,line) (!strcmp_wa(str, exval), "defaultValue=%s\n", wine_dbgstr_w(str));
3249 else
3250 ok_(__FILE__,line) (!str, "exval != NULL\n");
3251 SysFreeString(str);
3252 IHTMLInputElement_Release(input);
3255 #define test_input_put_defaultValue(o,v) _test_input_put_defaultValue(__LINE__,o,v)
3256 static void _test_input_put_defaultValue(unsigned line, IUnknown *unk, const char *val)
3258 IHTMLInputElement *input;
3259 BSTR str;
3260 HRESULT hres;
3262 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3263 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3264 if(FAILED(hres))
3265 return;
3267 str = a2bstr(val);
3268 hres = IHTMLInputElement_put_defaultValue(input, str);
3269 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3270 SysFreeString(str);
3271 IHTMLInputElement_Release(input);
3273 _test_input_defaultValue(line, unk, val);
3276 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
3277 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
3279 BSTR src;
3280 HRESULT hres;
3282 hres = IHTMLInputElement_get_src(input, &src);
3283 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
3284 if(exsrc)
3285 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
3286 else
3287 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
3288 SysFreeString(src);
3291 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
3292 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
3294 BSTR tmp;
3295 HRESULT hres;
3297 tmp = a2bstr(src);
3298 hres = IHTMLInputElement_put_src(input, tmp);
3299 SysFreeString(tmp);
3300 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
3302 _test_input_src(line, input, src);
3305 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
3306 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
3308 IHTMLElement *elem = _get_elem_iface(line, unk);
3309 BSTR class = (void*)0xdeadbeef;
3310 HRESULT hres;
3312 hres = IHTMLElement_get_className(elem, &class);
3313 IHTMLElement_Release(elem);
3314 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
3315 if(exclass)
3316 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
3317 else
3318 ok_(__FILE__,line) (!class, "class != NULL\n");
3319 SysFreeString(class);
3322 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
3323 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
3325 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3326 short index = -3;
3327 HRESULT hres;
3329 hres = IHTMLElement2_get_tabIndex(elem2, &index);
3330 IHTMLElement2_Release(elem2);
3331 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3332 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
3335 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
3336 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
3338 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3339 HRESULT hres;
3341 hres = IHTMLElement2_put_tabIndex(elem2, index);
3342 IHTMLElement2_Release(elem2);
3343 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3345 _test_elem_tabindex(line, unk, index);
3348 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
3349 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
3351 IHTMLStyleElement *style = _get_style_iface(line, unk);
3352 BSTR media;
3353 HRESULT hres;
3355 hres = IHTMLStyleElement_get_media(style, &media);
3356 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
3357 if(exmedia)
3358 ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
3359 else
3360 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
3362 IHTMLStyleElement_Release(style);
3363 SysFreeString(media);
3366 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
3367 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
3369 IHTMLStyleElement *style = _get_style_iface(line, unk);
3370 BSTR str;
3371 HRESULT hres;
3373 str = a2bstr(media);
3374 hres = IHTMLStyleElement_put_media(style, str);
3375 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
3376 IHTMLStyleElement_Release(style);
3377 SysFreeString(str);
3379 _test_style_media(line, unk, media);
3382 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
3383 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
3385 IHTMLStyleElement *style = _get_style_iface(line, unk);
3386 BSTR type;
3387 HRESULT hres;
3389 hres = IHTMLStyleElement_get_type(style, &type);
3390 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
3391 if(extype)
3392 ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
3393 else
3394 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
3396 IHTMLStyleElement_Release(style);
3397 SysFreeString(type);
3400 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
3401 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
3403 IHTMLStyleElement *style = _get_style_iface(line, unk);
3404 BSTR str;
3405 HRESULT hres;
3407 str = a2bstr(type);
3408 hres = IHTMLStyleElement_put_type(style, str);
3409 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
3410 IHTMLStyleElement_Release(style);
3411 SysFreeString(str);
3413 _test_style_type(line, unk, type);
3416 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
3417 static void _test_elem_filters(unsigned line, IUnknown *unk)
3419 IHTMLElement *elem = _get_elem_iface(line, unk);
3420 HRESULT hres;
3421 IHTMLFiltersCollection *filters;
3423 hres = IHTMLElement_get_filters(elem, &filters);
3424 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
3425 "get_filters failed: %08x\n", hres);
3426 if(hres == S_OK)
3428 LONG len;
3429 IDispatchEx *dispex;
3431 hres = IHTMLFiltersCollection_get_length(filters, &len);
3432 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
3433 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
3435 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
3436 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
3437 "Could not get IDispatchEx interface: %08x\n", hres);
3438 if(SUCCEEDED(hres)) {
3439 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
3440 IDispatchEx_Release(dispex);
3443 IHTMLFiltersCollection_Release(filters);
3446 IHTMLElement_Release(elem);
3449 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
3450 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
3452 IHTMLElement *elem = _get_elem_iface(line, unk);
3453 BSTR tmp;
3454 HRESULT hres;
3456 tmp = class ? a2bstr(class) : NULL;
3457 hres = IHTMLElement_put_className(elem, tmp);
3458 IHTMLElement_Release(elem);
3459 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
3460 SysFreeString(tmp);
3462 _test_elem_class(line, unk, class);
3465 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
3466 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
3468 IHTMLElement *elem = _get_elem_iface(line, unk);
3469 BSTR id = (void*)0xdeadbeef;
3470 HRESULT hres;
3472 hres = IHTMLElement_get_id(elem, &id);
3473 IHTMLElement_Release(elem);
3474 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
3476 if(exid)
3477 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
3478 else
3479 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
3481 SysFreeString(id);
3484 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
3485 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
3487 IHTMLElement *elem = _get_elem_iface(line, unk);
3488 BSTR tmp = a2bstr(new_id);
3489 HRESULT hres;
3491 hres = IHTMLElement_put_id(elem, tmp);
3492 IHTMLElement_Release(elem);
3493 SysFreeString(tmp);
3494 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
3496 _test_elem_id(line, unk, new_id);
3499 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
3500 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
3502 IHTMLElement *elem = _get_elem_iface(line, unk);
3503 BSTR title;
3504 HRESULT hres;
3506 hres = IHTMLElement_get_title(elem, &title);
3507 IHTMLElement_Release(elem);
3508 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3509 if(extitle)
3510 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3511 else
3512 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
3514 SysFreeString(title);
3517 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
3518 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
3520 IHTMLElement *elem = _get_elem_iface(line, unk);
3521 BSTR tmp;
3522 HRESULT hres;
3524 tmp = a2bstr(title);
3525 hres = IHTMLElement_put_title(elem, tmp);
3526 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3528 IHTMLElement_Release(elem);
3529 SysFreeString(tmp);
3532 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
3533 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
3535 IHTMLDOMNode *node = _get_node_iface(line, unk);
3536 VARIANT var;
3537 HRESULT hres;
3539 hres = IHTMLDOMNode_get_nodeValue(node, &var);
3540 IHTMLDOMNode_Release(node);
3541 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3543 if(exval) {
3544 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
3545 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
3546 }else {
3547 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
3550 VariantClear(&var);
3553 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
3554 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
3556 IHTMLDOMNode *node = _get_node_iface(line, unk);
3557 VARIANT var;
3558 HRESULT hres;
3560 V_VT(&var) = VT_BSTR;
3561 V_BSTR(&var) = a2bstr(val);
3563 hres = IHTMLDOMNode_put_nodeValue(node, var);
3564 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
3565 IHTMLDOMNode_Release(node);
3566 VariantClear(&var);
3569 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
3570 static void _test_elem_client_size(unsigned line, IUnknown *unk)
3572 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3573 LONG l;
3574 HRESULT hres;
3576 hres = IHTMLElement2_get_clientWidth(elem, &l);
3577 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
3578 hres = IHTMLElement2_get_clientHeight(elem, &l);
3579 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
3581 IHTMLElement2_Release(elem);
3584 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
3585 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
3587 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3588 LONG l;
3589 HRESULT hres;
3591 hres = IHTMLElement2_get_clientLeft(elem, &l);
3592 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
3593 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
3595 hres = IHTMLElement2_get_clientTop(elem, &l);
3596 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
3597 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
3599 IHTMLElement2_Release(elem);
3602 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
3603 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
3605 IHTMLFormElement *form = _get_form_iface(line, unk);
3606 LONG len = 0xdeadbeef;
3607 HRESULT hres;
3609 hres = IHTMLFormElement_get_length(form, &len);
3610 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
3611 ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
3613 IHTMLFormElement_Release(form);
3616 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
3617 static void _test_form_action(unsigned line, IUnknown *unk, const char *ex)
3619 IHTMLFormElement *form = _get_form_iface(line, unk);
3620 BSTR action = (void*)0xdeadbeef;
3621 HRESULT hres;
3623 hres = IHTMLFormElement_get_action(form, &action);
3624 ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
3625 if(ex)
3626 ok_(__FILE__,line)(!strcmp_wa(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), ex);
3627 else
3628 ok_(__FILE__,line)(!action, "action=%p\n", action);
3630 SysFreeString(action);
3631 IHTMLFormElement_Release(form);
3634 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
3635 static void _test_form_put_action(unsigned line, IUnknown *unk, const char *action)
3637 IHTMLFormElement *form = _get_form_iface(line, unk);
3638 BSTR tmp = a2bstr(action);
3639 HRESULT hres;
3641 hres = IHTMLFormElement_put_action(form, tmp);
3642 ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
3643 SysFreeString(tmp);
3644 IHTMLFormElement_Release(form);
3646 _test_form_action(line, unk, action);
3649 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
3650 static void _test_form_method(unsigned line, IUnknown *unk, const char *ex)
3652 IHTMLFormElement *form = _get_form_iface(line, unk);
3653 BSTR method = (void*)0xdeadbeef;
3654 HRESULT hres;
3656 hres = IHTMLFormElement_get_method(form, &method);
3657 ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
3658 if(ex)
3659 ok_(__FILE__,line)(!strcmp_wa(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), ex);
3660 else
3661 ok_(__FILE__,line)(!method, "method=%p\n", method);
3663 SysFreeString(method);
3664 IHTMLFormElement_Release(form);
3667 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
3668 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *method)
3670 IHTMLFormElement *form = _get_form_iface(line, unk);
3671 BSTR tmp = a2bstr(method);
3672 HRESULT hres;
3674 hres = IHTMLFormElement_put_method(form, tmp);
3675 ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
3676 SysFreeString(tmp);
3677 IHTMLFormElement_Release(form);
3679 if(exp_hres == S_OK)
3680 _test_form_method(line, unk, method);
3683 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
3684 static void _test_form_name(unsigned line, IUnknown *unk, const char *ex)
3686 IHTMLFormElement *form = _get_form_iface(line, unk);
3687 BSTR name = (void*)0xdeadbeef;
3688 HRESULT hres;
3690 hres = IHTMLFormElement_get_name(form, &name);
3691 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3692 if(ex)
3693 ok_(__FILE__,line)(!strcmp_wa(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), ex);
3694 else
3695 ok_(__FILE__,line)(!name, "name=%p\n", name);
3697 SysFreeString(name);
3698 IHTMLFormElement_Release(form);
3701 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
3702 static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
3704 IHTMLFormElement *form = _get_form_iface(line, unk);
3705 BSTR tmp = a2bstr(name);
3706 HRESULT hres;
3708 hres = IHTMLFormElement_put_name(form, tmp);
3709 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
3710 SysFreeString(tmp);
3711 IHTMLFormElement_Release(form);
3713 _test_form_name(line, unk, name);
3716 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
3717 static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
3719 IHTMLFormElement *form = _get_form_iface(line, unk);
3720 BSTR encoding = (void*)0xdeadbeef;
3721 HRESULT hres;
3723 hres = IHTMLFormElement_get_encoding(form, &encoding);
3724 ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
3725 if(ex)
3726 ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
3727 else
3728 ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
3730 SysFreeString(encoding);
3731 IHTMLFormElement_Release(form);
3734 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
3735 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
3737 IHTMLFormElement *form = _get_form_iface(line, unk);
3738 BSTR tmp = a2bstr(encoding);
3739 HRESULT hres;
3741 hres = IHTMLFormElement_put_encoding(form, tmp);
3742 ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
3743 SysFreeString(tmp);
3744 IHTMLFormElement_Release(form);
3746 if(exp_hres == S_OK)
3747 _test_form_encoding(line, unk, encoding);
3750 #define test_form_elements(a) _test_form_elements(__LINE__,a)
3751 static void _test_form_elements(unsigned line, IUnknown *unk)
3753 IHTMLFormElement *form = _get_form_iface(line, unk);
3754 IDispatch *disp;
3755 HRESULT hres;
3757 disp = NULL;
3758 hres = IHTMLFormElement_get_elements(form, &disp);
3759 ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
3760 ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
3761 ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
3763 IDispatch_Release(disp);
3764 IHTMLFormElement_Release(form);
3767 #define test_form_reset(a) _test_form_reset(__LINE__,a)
3768 static void _test_form_reset(unsigned line, IUnknown *unk)
3770 IHTMLFormElement *form = _get_form_iface(line, unk);
3771 HRESULT hres;
3773 hres = IHTMLFormElement_reset(form);
3774 ok_(__FILE__,line)(hres == S_OK, "reset failed: %08x\n", hres);
3776 IHTMLFormElement_Release(form);
3779 static void test_form_target(IUnknown *unk)
3781 IHTMLFormElement *form = get_form_iface(unk);
3782 HRESULT hres;
3783 BSTR str;
3784 static const char target[] = "_blank";
3786 str = a2bstr(target);
3787 hres = IHTMLFormElement_put_target(form, str);
3788 ok(hres == S_OK, "put_target(%s) failed: %08x\n", target, hres);
3789 SysFreeString(str);
3791 hres = IHTMLFormElement_get_target(form, &str);
3792 ok(hres == S_OK, "get_target failed: %08x\n", hres);
3793 ok(!strcmp_wa(str, target), "Expected %s, got %s\n", target, wine_dbgstr_w(str));
3794 SysFreeString(str);
3796 IHTMLFormElement_Release(form);
3799 #define test_meta_name(a,b) _test_meta_name(__LINE__,a,b)
3800 static void _test_meta_name(unsigned line, IUnknown *unk, const char *exname)
3802 IHTMLMetaElement *meta;
3803 BSTR name = NULL;
3804 HRESULT hres;
3806 meta = _get_metaelem_iface(line, unk);
3807 hres = IHTMLMetaElement_get_name(meta, &name);
3808 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
3809 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s, expected %s\n", wine_dbgstr_w(name), exname);
3810 SysFreeString(name);
3811 IHTMLMetaElement_Release(meta);
3814 #define test_meta_content(a,b) _test_meta_content(__LINE__,a,b)
3815 static void _test_meta_content(unsigned line, IUnknown *unk, const char *excontent)
3817 IHTMLMetaElement *meta;
3818 BSTR content = NULL;
3819 HRESULT hres;
3821 meta = _get_metaelem_iface(line, unk);
3822 hres = IHTMLMetaElement_get_content(meta, &content);
3823 ok_(__FILE__,line)(hres == S_OK, "get_content failed: %08x\n", hres);
3824 ok_(__FILE__,line)(!strcmp_wa(content, excontent), "content = %s, expected %s\n", wine_dbgstr_w(content), excontent);
3825 SysFreeString(content);
3826 IHTMLMetaElement_Release(meta);
3829 #define test_meta_httpequiv(a,b) _test_meta_httpequiv(__LINE__,a,b)
3830 static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const char *exval)
3832 IHTMLMetaElement *meta;
3833 BSTR val = NULL;
3834 HRESULT hres;
3836 meta = _get_metaelem_iface(line, unk);
3837 hres = IHTMLMetaElement_get_httpEquiv(meta, &val);
3838 ok_(__FILE__,line)(hres == S_OK, "get_httpEquiv failed: %08x\n", hres);
3839 ok_(__FILE__,line)(!strcmp_wa(val, exval), "httpEquiv = %s, expected %s\n", wine_dbgstr_w(val), exval);
3840 SysFreeString(val);
3841 IHTMLMetaElement_Release(meta);
3844 #define test_meta_charset(a,b) _test_meta_charset(__LINE__,a,b)
3845 static void _test_meta_charset(unsigned line, IUnknown *unk, const char *exval)
3847 IHTMLMetaElement *meta;
3848 BSTR val = NULL;
3849 HRESULT hres;
3851 meta = _get_metaelem_iface(line, unk);
3852 hres = IHTMLMetaElement_get_charset(meta, &val);
3853 ok_(__FILE__,line)(hres == S_OK, "get_charset failed: %08x\n", hres);
3854 if(exval)
3855 ok_(__FILE__,line)(!strcmp_wa(val, exval), "charset = %s, expected %s\n", wine_dbgstr_w(val), exval);
3856 else
3857 ok_(__FILE__,line)(!val, "charset = %s, expected NULL\n", wine_dbgstr_w(val));
3858 SysFreeString(val);
3859 IHTMLMetaElement_Release(meta);
3862 #define set_meta_charset(a,b) _set_meta_charset(__LINE__,a,b)
3863 static void _set_meta_charset(unsigned line, IUnknown *unk, const char *vala)
3865 BSTR val = a2bstr(vala);
3866 IHTMLMetaElement *meta;
3867 HRESULT hres;
3869 meta = _get_metaelem_iface(line, unk);
3870 hres = IHTMLMetaElement_put_charset(meta, val);
3871 ok_(__FILE__,line)(hres == S_OK, "put_charset failed: %08x\n", hres);
3872 SysFreeString(val);
3873 IHTMLMetaElement_Release(meta);
3875 _test_meta_charset(line, unk, vala);
3878 #define test_link_media(a,b) _test_link_media(__LINE__,a,b)
3879 static void _test_link_media(unsigned line, IHTMLElement *elem, const char *exval)
3881 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3882 HRESULT hres;
3883 BSTR str;
3885 str = a2bstr(exval);
3886 hres = IHTMLLinkElement_put_media(link, str);
3887 ok_(__FILE__,line)(hres == S_OK, "put_media(%s) failed: %08x\n", exval, hres);
3888 SysFreeString(str);
3890 hres = IHTMLLinkElement_get_media(link, &str);
3891 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
3892 ok_(__FILE__,line)(!strcmp_wa(str, exval), "got %s, expected %s\n", wine_dbgstr_w(str), exval);
3893 SysFreeString(str);
3894 IHTMLLinkElement_Release(link);
3897 #define test_link_disabled(a,b) _test_link_disabled(__LINE__,a,b)
3898 static void _test_link_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
3900 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3901 VARIANT_BOOL b = 10;
3902 HRESULT hres;
3904 hres = IHTMLLinkElement_get_disabled(link, &b);
3905 ok_(__FILE__,line)(hres == S_OK, "get_disabled failed: %08x\n", hres);
3906 ok_(__FILE__,line)(b == v, "disabled = %x, expected %x\n", b, v);
3908 IHTMLLinkElement_Release(link);
3911 #define link_put_disabled(a,b) _link_put_disabled(__LINE__,a,b)
3912 static void _link_put_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
3914 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3915 HRESULT hres;
3917 hres = IHTMLLinkElement_put_disabled(link, v);
3918 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
3919 IHTMLLinkElement_Release(link);
3920 _test_link_disabled(line, elem, v);
3923 #define test_link_rel(a,b) _test_link_rel(__LINE__,a,b)
3924 static void _test_link_rel(unsigned line, IHTMLElement *elem, const char *v)
3926 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3927 BSTR rel;
3928 HRESULT hres;
3930 hres = IHTMLLinkElement_get_rel(link, &rel);
3931 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
3932 if(v)
3933 ok_(__FILE__,line)(!strcmp_wa(rel, v), "rel = %s, expected %s\n", wine_dbgstr_w(rel), v);
3934 else
3935 ok_(__FILE__,line)(!rel, "rel = %s, expected NULL\n", wine_dbgstr_w(rel));
3937 IHTMLLinkElement_Release(link);
3940 #define link_put_rel(a,b) _link_put_rel(__LINE__,a,b)
3941 static void _link_put_rel(unsigned line, IHTMLElement *elem, const char *v)
3943 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3944 BSTR str = a2bstr(v);
3945 HRESULT hres;
3947 hres = IHTMLLinkElement_put_rel(link, str);
3948 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
3949 SysFreeString(str);
3950 IHTMLLinkElement_Release(link);
3951 _test_link_rel(line, elem, v);
3954 #define test_link_type(a,b) _test_link_type(__LINE__,a,b)
3955 static void _test_link_type(unsigned line, IHTMLElement *elem, const char *v)
3957 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3958 BSTR type;
3959 HRESULT hres;
3961 hres = IHTMLLinkElement_get_type(link, &type);
3962 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
3963 if(v)
3964 ok_(__FILE__,line)(!strcmp_wa(type, v), "type = %s, expected %s\n", wine_dbgstr_w(type), v);
3965 else
3966 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
3968 IHTMLLinkElement_Release(link);
3971 #define test_script_text(a,b) _test_script_text(__LINE__,a,b)
3972 static void _test_script_text(unsigned line, IHTMLScriptElement *script, const char *extext)
3974 BSTR str;
3975 HRESULT hres;
3977 str = (void*)0xdeadbeef;
3978 hres = IHTMLScriptElement_get_text(script, &str);
3979 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
3980 ok(!strcmp_wa(str, extext), "text = %s, expected \"%s\"\n", wine_dbgstr_w(str), extext);
3981 SysFreeString(str);
3984 #define link_put_type(a,b) _link_put_type(__LINE__,a,b)
3985 static void _link_put_type(unsigned line, IHTMLElement *elem, const char *v)
3987 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
3988 BSTR str = a2bstr(v);
3989 HRESULT hres;
3991 hres = IHTMLLinkElement_put_type(link, str);
3992 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
3993 SysFreeString(str);
3994 IHTMLLinkElement_Release(link);
3995 _test_link_type(line, elem, v);
3998 #define test_link_href(a,b) _test_link_href(__LINE__,a,b)
3999 static void _test_link_href(unsigned line, IHTMLElement *elem, const char *v)
4001 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4002 BSTR href;
4003 HRESULT hres;
4005 hres = IHTMLLinkElement_get_href(link, &href);
4006 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
4007 if(v)
4008 ok_(__FILE__,line)(!strcmp_wa(href, v), "href = %s, expected %s\n", wine_dbgstr_w(href), v);
4009 else
4010 ok_(__FILE__,line)(!href, "href = %s, expected NULL\n", wine_dbgstr_w(href));
4012 IHTMLLinkElement_Release(link);
4015 #define link_put_href(a,b) _link_put_href(__LINE__,a,b)
4016 static void _link_put_href(unsigned line, IHTMLElement *elem, const char *v)
4018 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4019 BSTR str = a2bstr(v);
4020 HRESULT hres;
4022 hres = IHTMLLinkElement_put_href(link, str);
4023 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4024 SysFreeString(str);
4025 IHTMLLinkElement_Release(link);
4026 _test_link_href(line, elem, v);
4029 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
4030 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
4032 IHTMLElement *elem = _get_elem_iface(line, unk);
4033 IHTMLDocument2 *doc;
4034 IDispatch *disp;
4035 HRESULT hres;
4037 disp = NULL;
4038 hres = IHTMLElement_get_document(elem, &disp);
4039 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4040 ok(disp != NULL, "disp == NULL\n");
4042 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
4043 IDispatch_Release(disp);
4044 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
4046 return doc;
4049 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
4050 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const char *attr_name, BOOL expect_success)
4052 IHTMLElement4 *elem = _get_elem4_iface(line, unk);
4053 BSTR str = a2bstr(attr_name);
4054 IHTMLDOMAttribute *attr;
4055 HRESULT hres;
4057 attr = (void*)0xdeadbeef;
4058 hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
4059 ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
4060 if(expect_success)
4061 ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
4062 else
4063 ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
4065 IHTMLElement4_Release(elem);
4066 SysFreeString(str);
4067 return attr;
4070 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
4071 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
4073 HRESULT hres;
4075 hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
4076 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
4077 ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
4080 #define get_window_doc(e) _get_window_doc(__LINE__,e)
4081 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
4083 IHTMLDocument2 *doc;
4084 HRESULT hres;
4086 doc = NULL;
4087 hres = IHTMLWindow2_get_document(window, &doc);
4088 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4089 ok(doc != NULL, "disp == NULL\n");
4091 return doc;
4094 #define doc_get_body(d) _doc_get_body(__LINE__,d)
4095 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
4097 IHTMLElement *elem;
4098 HRESULT hres;
4100 hres = IHTMLDocument2_get_body(doc, &elem);
4101 ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
4102 ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
4104 return elem;
4107 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
4108 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
4110 IHTMLElement *elem = NULL;
4111 BSTR tmp;
4112 HRESULT hres;
4114 tmp = a2bstr(tag);
4115 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
4116 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
4117 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
4118 SysFreeString(tmp);
4120 return elem;
4123 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
4124 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
4126 IHTMLDocument3 *doc3;
4127 IHTMLDOMNode *node = NULL;
4128 BSTR tmp;
4129 HRESULT hres;
4131 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4132 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
4134 tmp = a2bstr(text);
4135 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
4136 IHTMLDocument3_Release(doc3);
4137 SysFreeString(tmp);
4138 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
4139 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
4141 return node;
4144 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
4145 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
4147 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
4148 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
4149 IHTMLDOMNode *new_child = NULL;
4150 HRESULT hres;
4152 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
4153 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
4154 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
4155 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
4157 IHTMLDOMNode_Release(node);
4158 IHTMLDOMNode_Release(child);
4160 return new_child;
4163 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
4164 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
4166 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
4167 IHTMLDOMNode *new_child = NULL;
4168 HRESULT hres;
4170 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
4171 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
4172 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
4173 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
4175 IHTMLDOMNode_Release(node);
4177 return new_child;
4180 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
4181 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
4183 IHTMLDOMNode *node = _get_node_iface(line, unk);
4184 IHTMLDOMNode *new_node = NULL;
4185 HRESULT hres;
4187 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
4188 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
4189 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
4190 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
4192 IHTMLDOMNode_Release(node);
4193 IHTMLDOMNode_Release(new_node);
4196 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
4197 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
4199 BSTR title = NULL;
4200 HRESULT hres;
4202 hres = IHTMLDocument2_get_title(doc, &title);
4203 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4204 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
4205 SysFreeString(title);
4208 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
4209 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
4211 BSTR tmp;
4212 HRESULT hres;
4214 tmp = a2bstr(title);
4215 hres = IHTMLDocument2_put_title(doc, tmp);
4216 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4217 SysFreeString(tmp);
4220 static void test_elem_bounding_client_rect(IUnknown *unk)
4222 IHTMLRect *rect, *rect2;
4223 IHTMLElement2 *elem2;
4224 LONG l;
4225 HRESULT hres;
4227 elem2 = get_elem2_iface(unk);
4228 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
4229 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
4230 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
4231 IHTMLElement2_Release(elem2);
4232 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
4233 ok(rect != NULL, "rect == NULL\n");
4234 ok(rect != rect2, "rect == rect2\n");
4235 IHTMLRect_Release(rect2);
4237 test_disp((IUnknown*)rect, &IID_IHTMLRect, "[object]");
4239 l = 0xdeadbeef;
4240 hres = IHTMLRect_get_top(rect, &l);
4241 ok(hres == S_OK, "get_top failed: %08x\n", hres);
4242 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4244 l = 0xdeadbeef;
4245 hres = IHTMLRect_get_left(rect, &l);
4246 ok(hres == S_OK, "get_left failed: %08x\n", hres);
4247 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4249 l = 0xdeadbeef;
4250 hres = IHTMLRect_get_bottom(rect, &l);
4251 ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
4252 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4254 l = 0xdeadbeef;
4255 hres = IHTMLRect_get_right(rect, &l);
4256 ok(hres == S_OK, "get_right failed: %08x\n", hres);
4257 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4259 IHTMLRect_Release(rect);
4262 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
4263 const elem_type_t *elem_types, LONG len)
4265 IDispatch *disp;
4266 VARIANT name, index;
4267 DWORD i;
4268 HRESULT hres;
4270 V_VT(&index) = VT_EMPTY;
4271 V_VT(&name) = VT_BSTR;
4272 V_BSTR(&name) = a2bstr(n);
4274 hres = IHTMLElementCollection_item(col, name, index, &disp);
4275 ok(hres == S_OK, "item failed: %08x\n", hres);
4277 test_elem_collection((IUnknown*)disp, elem_types, len);
4278 IDispatch_Release(disp);
4280 V_VT(&index) = VT_I4;
4282 for(i=0; i<len; i++) {
4283 V_I4(&index) = i;
4284 disp = (void*)0xdeadbeef;
4285 hres = IHTMLElementCollection_item(col, name, index, &disp);
4286 ok(hres == S_OK, "item failed: %08x\n", hres);
4287 ok(disp != NULL, "disp == NULL\n");
4288 if(FAILED(hres) || !disp)
4289 continue;
4291 test_elem_type((IUnknown*)disp, elem_types[i]);
4293 IDispatch_Release(disp);
4296 V_I4(&index) = len;
4297 disp = (void*)0xdeadbeef;
4298 hres = IHTMLElementCollection_item(col, name, index, &disp);
4299 ok(hres == S_OK, "item failed: %08x\n", hres);
4300 ok(disp == NULL, "disp != NULL\n");
4302 V_I4(&index) = -1;
4303 disp = (void*)0xdeadbeef;
4304 hres = IHTMLElementCollection_item(col, name, index, &disp);
4305 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4306 ok(disp == NULL, "disp != NULL\n");
4308 SysFreeString(V_BSTR(&name));
4311 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
4313 IHTMLElementCollection *col;
4314 IHTMLElement *elem;
4315 IDispatch *disp = (void*)0xdeadbeef;
4316 VARIANT name, index;
4317 HRESULT hres;
4319 hres = IHTMLDocument2_get_all(doc, &col);
4320 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4321 ok(col != NULL, "col == NULL\n");
4322 if(FAILED(hres) || !col)
4323 return NULL;
4325 V_VT(&index) = VT_EMPTY;
4326 V_VT(&name) = VT_BSTR;
4327 V_BSTR(&name) = a2bstr(id);
4329 hres = IHTMLElementCollection_item(col, name, index, &disp);
4330 IHTMLElementCollection_Release(col);
4331 SysFreeString(V_BSTR(&name));
4332 ok(hres == S_OK, "item failed: %08x\n", hres);
4333 if(!expect_success) {
4334 ok(disp == NULL, "disp != NULL\n");
4335 return NULL;
4338 ok(disp != NULL, "disp == NULL\n");
4339 if(!disp)
4340 return NULL;
4342 elem = get_elem_iface((IUnknown*)disp);
4343 IDispatch_Release(disp);
4345 return elem;
4348 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
4350 IHTMLDocument3 *doc3;
4351 IHTMLElement *elem;
4352 BSTR tmp;
4353 HRESULT hres;
4355 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4356 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
4358 tmp = a2bstr(id);
4359 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
4360 SysFreeString(tmp);
4361 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
4363 IHTMLDocument3_Release(doc3);
4365 return elem;
4368 static void test_select_elem(IHTMLSelectElement *select)
4370 IDispatch *disp, *disp2;
4371 VARIANT name, index;
4372 HRESULT hres;
4374 test_select_type(select, "select-one");
4375 test_select_length(select, 2);
4376 test_select_selidx(select, 0);
4377 test_select_put_selidx(select, 1);
4379 test_select_set_value(select, "val1");
4380 test_select_value(select, "val1");
4382 test_select_get_disabled(select, VARIANT_FALSE);
4383 test_select_set_disabled(select, VARIANT_TRUE);
4384 test_select_set_disabled(select, VARIANT_FALSE);
4386 disp = NULL;
4387 hres = IHTMLSelectElement_get_options(select, &disp);
4388 ok(hres == S_OK, "get_options failed: %08x\n", hres);
4389 ok(disp != NULL, "options == NULL\n");
4390 ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
4391 IDispatch_Release(disp);
4393 V_VT(&index) = VT_EMPTY;
4394 V_VT(&name) = VT_I4;
4395 V_I4(&name) = -1;
4396 disp = (void*)0xdeadbeef;
4397 hres = IHTMLSelectElement_item(select, name, index, &disp);
4398 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4399 ok(!disp, "disp = %p\n", disp);
4401 V_I4(&name) = 2;
4402 disp = (void*)0xdeadbeef;
4403 hres = IHTMLSelectElement_item(select, name, index, &disp);
4404 ok(hres == S_OK, "item failed: %08x\n", hres);
4405 ok(!disp, "disp = %p\n", disp);
4407 V_I4(&name) = 1;
4408 hres = IHTMLSelectElement_item(select, name, index, NULL);
4409 ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
4411 disp = NULL;
4412 hres = IHTMLSelectElement_item(select, name, index, &disp);
4413 ok(hres == S_OK, "item failed: %08x\n", hres);
4414 ok(disp != NULL, "disp = NULL\n");
4415 test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, NULL);
4417 V_VT(&index) = VT_I4;
4418 V_I4(&index) = 1;
4419 disp2 = NULL;
4420 hres = IHTMLSelectElement_item(select, name, index, &disp2);
4421 ok(hres == S_OK, "item failed: %08x\n", hres);
4422 ok(disp2 != NULL, "disp = NULL\n");
4423 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
4424 IDispatch_Release(disp2);
4425 IDispatch_Release(disp);
4427 test_select_multiple(select, VARIANT_FALSE);
4428 test_select_set_multiple(select, VARIANT_TRUE);
4429 test_select_remove(select);
4432 static void test_form_item(IHTMLElement *elem)
4434 IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
4435 IDispatch *disp, *disp2;
4436 VARIANT name, index;
4437 HRESULT hres;
4439 V_VT(&index) = VT_EMPTY;
4440 V_VT(&name) = VT_I4;
4441 V_I4(&name) = -1;
4442 disp = (void*)0xdeadbeef;
4443 hres = IHTMLFormElement_item(form, name, index, &disp);
4444 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4445 ok(!disp, "disp = %p\n", disp);
4447 V_I4(&name) = 2;
4448 disp = (void*)0xdeadbeef;
4449 hres = IHTMLFormElement_item(form, name, index, &disp);
4450 ok(hres == S_OK, "item failed: %08x\n", hres);
4451 ok(!disp, "disp = %p\n", disp);
4453 V_I4(&name) = 1;
4454 hres = IHTMLFormElement_item(form, name, index, NULL);
4455 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4457 disp = NULL;
4458 hres = IHTMLFormElement_item(form, name, index, &disp);
4459 ok(hres == S_OK, "item failed: %08x\n", hres);
4460 ok(disp != NULL, "disp = NULL\n");
4461 test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, NULL);
4463 V_VT(&index) = VT_I4;
4464 V_I4(&index) = 1;
4465 disp2 = NULL;
4466 hres = IHTMLFormElement_item(form, name, index, &disp2);
4467 ok(hres == S_OK, "item failed: %08x\n", hres);
4468 ok(disp2 != NULL, "disp = NULL\n");
4469 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
4470 IDispatch_Release(disp2);
4471 IDispatch_Release(disp);
4474 static void test_create_option_elem(IHTMLDocument2 *doc)
4476 IHTMLOptionElement *option;
4478 option = create_option_elem(doc, "test text", "test value");
4480 test_option_put_text(option, "new text");
4481 test_option_put_value(option, "new value");
4482 test_option_put_selected(option, VARIANT_TRUE);
4483 test_option_put_selected(option, VARIANT_FALSE);
4485 IHTMLOptionElement_Release(option);
4488 static void test_create_img_elem(IHTMLDocument2 *doc)
4490 IHTMLImgElement *img;
4492 img = create_img_elem(doc, 10, 15);
4494 if(img){
4495 test_img_put_width(img, 5);
4496 test_img_put_height(img, 20);
4498 IHTMLImgElement_Release(img);
4499 img = NULL;
4502 img = create_img_elem(doc, -1, -1);
4504 if(img){
4505 test_img_put_width(img, 5);
4506 test_img_put_height(img, 20);
4508 IHTMLImgElement_Release(img);
4512 #define insert_adjacent_elem(a,b,c) _insert_adjacent_elem(__LINE__,a,b,c)
4513 static void _insert_adjacent_elem(unsigned line, IHTMLElement *parent, const char *where, IHTMLElement *elem)
4515 IHTMLElement2 *elem2 = _get_elem2_iface(line, (IUnknown*)parent);
4516 IHTMLElement *ret_elem = NULL;
4517 BSTR str = a2bstr(where);
4518 HRESULT hres;
4520 hres = IHTMLElement2_insertAdjacentElement(elem2, str, elem, &ret_elem);
4521 IHTMLElement2_Release(elem2);
4522 SysFreeString(str);
4523 ok_(__FILE__,line)(hres == S_OK, "insertAdjacentElement failed: %08x\n", hres);
4524 ok_(__FILE__,line)(ret_elem == elem, "ret_elem != elem\n");
4525 IHTMLElement_Release(ret_elem);
4528 static void test_insert_adjacent_elems(IHTMLDocument2 *doc, IHTMLElement *parent)
4530 IHTMLElement *elem, *elem2;
4532 static const elem_type_t br_br[] = {ET_BR, ET_BR};
4533 static const elem_type_t br_div_br[] = {ET_BR, ET_DIV, ET_BR};
4535 elem = test_create_elem(doc, "BR");
4536 insert_adjacent_elem(parent, "BeforeEnd", elem);
4537 IHTMLElement_Release(elem);
4539 test_elem_all((IUnknown*)parent, br_br, 1);
4541 elem = test_create_elem(doc, "BR");
4542 insert_adjacent_elem(parent, "beforeend", elem);
4544 test_elem_all((IUnknown*)parent, br_br, 2);
4546 elem2 = test_create_elem(doc, "DIV");
4547 insert_adjacent_elem(elem, "beforebegin", elem2);
4548 IHTMLElement_Release(elem2);
4549 IHTMLElement_Release(elem);
4551 test_elem_all((IUnknown*)parent, br_div_br, 3);
4554 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
4556 IHTMLBodyElement *body;
4557 IHTMLTxtRange *range;
4558 IHTMLElement *elem;
4559 HRESULT hres;
4561 elem = doc_get_body(doc);
4562 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
4563 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
4564 IHTMLElement_Release(elem);
4566 hres = IHTMLBodyElement_createTextRange(body, &range);
4567 IHTMLBodyElement_Release(body);
4568 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
4570 return range;
4573 static void test_txtrange(IHTMLDocument2 *doc)
4575 IHTMLTxtRange *body_range, *range, *range2;
4576 IHTMLSelectionObject *selection;
4577 IDispatch *disp_range;
4578 HRESULT hres;
4580 body_range = test_create_body_range(doc);
4582 test_range_text(body_range, "test abc 123\r\nit's text");
4584 hres = IHTMLTxtRange_duplicate(body_range, &range);
4585 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4587 hres = IHTMLTxtRange_duplicate(body_range, &range2);
4588 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4589 test_range_isequal(range, range2, VARIANT_TRUE);
4591 test_range_text(range, "test abc 123\r\nit's text");
4592 test_range_text(body_range, "test abc 123\r\nit's text");
4594 test_range_collapse(range, TRUE);
4595 test_range_isequal(range, range2, VARIANT_FALSE);
4596 test_range_inrange(range, range2, VARIANT_FALSE);
4597 test_range_inrange(range2, range, VARIANT_TRUE);
4598 IHTMLTxtRange_Release(range2);
4600 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
4601 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
4602 test_range_move(range, characterW, 2, 2);
4603 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
4605 test_range_collapse(range, FALSE);
4606 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
4608 test_range_collapse(range, FALSE);
4609 test_range_expand(range, wordW, VARIANT_TRUE, "123");
4610 test_range_expand(range, wordW, VARIANT_FALSE, "123");
4611 test_range_move(range, characterW, 2, 2);
4612 test_range_expand(range, wordW, VARIANT_TRUE, "123");
4613 test_range_moveend(range, characterW, -5, -5);
4614 test_range_text(range, NULL);
4615 test_range_moveend(range, characterW, 3, 3);
4616 test_range_text(range, "c 1");
4617 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
4618 test_range_collapse(range, TRUE);
4619 test_range_move(range, characterW, 4, 4);
4620 test_range_moveend(range, characterW, 1, 1);
4621 test_range_text(range, " ");
4622 test_range_move(range, wordW, 1, 1);
4623 test_range_moveend(range, characterW, 2, 2);
4624 test_range_text(range, "ab");
4626 IHTMLTxtRange_Release(range);
4628 hres = IHTMLTxtRange_duplicate(body_range, &range);
4629 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4631 test_range_text(range, "test abc 123\r\nit's text");
4632 test_range_move(range, characterW, 3, 3);
4633 test_range_moveend(range, characterW, 1, 1);
4634 test_range_text(range, "t");
4635 test_range_moveend(range, characterW, 3, 3);
4636 test_range_text(range, "t ab");
4637 test_range_moveend(range, characterW, -2, -2);
4638 test_range_text(range, "t ");
4639 test_range_move(range, characterW, 6, 6);
4640 test_range_moveend(range, characterW, 3, 3);
4641 test_range_text(range, "123");
4642 test_range_moveend(range, characterW, 2, 2);
4643 test_range_text(range, "123\r\ni");
4645 IHTMLTxtRange_Release(range);
4647 hres = IHTMLTxtRange_duplicate(body_range, &range);
4648 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4650 test_range_move(range, wordW, 1, 1);
4651 test_range_moveend(range, characterW, 2, 2);
4652 test_range_text(range, "ab");
4654 test_range_move(range, characterW, -2, -2);
4655 test_range_moveend(range, characterW, 2, 2);
4656 test_range_text(range, "t ");
4658 test_range_move(range, wordW, 3, 3);
4659 test_range_move(range, wordW, -2, -2);
4660 test_range_moveend(range, characterW, 2, 2);
4661 test_range_text(range, "ab");
4663 test_range_move(range, characterW, -6, -5);
4664 test_range_moveend(range, characterW, -1, 0);
4665 test_range_moveend(range, characterW, -6, 0);
4666 test_range_move(range, characterW, 2, 2);
4667 test_range_moveend(range, characterW, 2, 2);
4668 test_range_text(range, "st");
4669 test_range_moveend(range, characterW, -6, -4);
4670 test_range_moveend(range, characterW, 2, 2);
4672 IHTMLTxtRange_Release(range);
4674 hres = IHTMLTxtRange_duplicate(body_range, &range);
4675 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4677 test_range_move(range, wordW, 2, 2);
4678 test_range_moveend(range, characterW, 2, 2);
4679 test_range_text(range, "12");
4681 test_range_move(range, characterW, 15, 14);
4682 test_range_move(range, characterW, -2, -2);
4683 test_range_moveend(range, characterW, 3, 2);
4684 test_range_text(range, "t");
4685 test_range_moveend(range, characterW, -1, -1);
4686 test_range_text(range, "t");
4687 test_range_expand(range, wordW, VARIANT_TRUE, "text");
4688 test_range_move(range, characterW, -2, -2);
4689 test_range_moveend(range, characterW, 2, 2);
4690 test_range_text(range, "s ");
4691 test_range_move(range, characterW, 100, 7);
4692 test_range_move(range, wordW, 1, 0);
4693 test_range_move(range, characterW, -2, -2);
4694 test_range_moveend(range, characterW, 3, 2);
4695 test_range_text(range, "t");
4697 IHTMLTxtRange_Release(range);
4699 hres = IHTMLTxtRange_duplicate(body_range, &range);
4700 ok(hres == S_OK, "duplicate failed: %08x\n", hres);
4702 test_range_collapse(range, TRUE);
4703 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
4704 test_range_put_text(range, "word");
4705 test_range_text(body_range, "wordabc 123\r\nit's text");
4706 test_range_text(range, NULL);
4707 test_range_moveend(range, characterW, 3, 3);
4708 test_range_text(range, "abc");
4709 test_range_movestart(range, characterW, -2, -2);
4710 test_range_text(range, "rdabc");
4711 test_range_movestart(range, characterW, 3, 3);
4712 test_range_text(range, "bc");
4713 test_range_movestart(range, characterW, 4, 4);
4714 test_range_text(range, NULL);
4715 test_range_movestart(range, characterW, -3, -3);
4716 test_range_text(range, "c 1");
4717 test_range_movestart(range, characterW, -7, -6);
4718 test_range_text(range, "wordabc 1");
4719 test_range_movestart(range, characterW, 100, 22);
4720 test_range_text(range, NULL);
4722 IHTMLTxtRange_Release(range);
4723 IHTMLTxtRange_Release(body_range);
4725 hres = IHTMLDocument2_get_selection(doc, &selection);
4726 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
4728 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
4729 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
4730 IHTMLSelectionObject_Release(selection);
4732 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
4733 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
4734 IDispatch_Release(disp_range);
4736 test_range_text(range, NULL);
4737 test_range_moveend(range, characterW, 3, 3);
4738 test_range_text(range, "wor");
4739 test_range_parent(range, ET_BODY);
4740 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
4741 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
4742 test_range_move(range, characterW, 3, 3);
4743 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
4744 test_range_moveend(range, characterW, -4, -4);
4745 test_range_put_text(range, "abc def ");
4746 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
4747 test_range_move(range, wordW, 1, 1);
4748 test_range_movestart(range, characterW, -1, -1);
4749 test_range_text(range, " ");
4750 test_range_move(range, wordW, 1, 1);
4751 test_range_moveend(range, characterW, 3, 3);
4752 test_range_text(range, "def");
4753 test_range_put_text(range, "xyz");
4754 test_range_moveend(range, characterW, 1, 1);
4755 test_range_move(range, wordW, 1, 1);
4756 test_range_moveend(range, characterW, 2, 2);
4757 test_range_text(range, "ab");
4759 IHTMLTxtRange_Release(range);
4762 static void test_txtrange2(IHTMLDocument2 *doc)
4764 IHTMLTxtRange *range;
4766 range = test_create_body_range(doc);
4768 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
4769 test_range_move(range, characterW, 5, 5);
4770 test_range_moveend(range, characterW, 1, 1);
4771 test_range_text(range, "2");
4772 test_range_move(range, characterW, -3, -3);
4773 test_range_moveend(range, characterW, 3, 3);
4774 test_range_text(range, "c\r\n\r\n1");
4775 test_range_collapse(range, VARIANT_FALSE);
4776 test_range_moveend(range, characterW, 4, 4);
4777 test_range_text(range, "23");
4778 test_range_moveend(range, characterW, 1, 1);
4779 test_range_text(range, "23\r\n\r\n\r\nd");
4780 test_range_moveend(range, characterW, -1, -1);
4781 test_range_text(range, "23");
4782 test_range_moveend(range, characterW, -1, -1);
4783 test_range_text(range, "23");
4784 test_range_moveend(range, characterW, -2, -2);
4785 test_range_text(range, "2");
4787 IHTMLTxtRange_Release(range);
4790 #define test_compatmode(a,b) _test_compatmode(__LINE__,a,b)
4791 static void _test_compatmode(unsigned line, IHTMLDocument2 *doc2, const char *excompat)
4793 IHTMLDocument5 *doc = get_htmldoc5_iface((IUnknown*)doc2);
4794 BSTR str;
4795 HRESULT hres;
4797 hres = IHTMLDocument5_get_compatMode(doc, &str);
4798 ok_(__FILE__,line)(hres == S_OK, "get_compatMode failed: %08x\n", hres);
4799 ok_(__FILE__,line)(!strcmp_wa(str, excompat), "compatMode = %s, expected %s\n", wine_dbgstr_w(str), excompat);
4801 IHTMLDocument5_Release(doc);
4804 static void test_location(IHTMLDocument2 *doc)
4806 IHTMLLocation *location, *location2;
4807 IHTMLWindow2 *window;
4808 BSTR str;
4809 ULONG ref;
4810 HRESULT hres;
4812 hres = IHTMLDocument2_get_location(doc, &location);
4813 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4815 hres = IHTMLDocument2_get_location(doc, &location2);
4816 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4818 ok(location == location2, "location != location2\n");
4819 IHTMLLocation_Release(location2);
4821 hres = IHTMLDocument2_get_parentWindow(doc, &window);
4822 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
4824 hres = IHTMLWindow2_get_location(window, &location2);
4825 ok(hres == S_OK, "get_location failed: %08x\n", hres);
4826 ok(location == location2, "location != location2\n");
4827 IHTMLLocation_Release(location2);
4829 test_ifaces((IUnknown*)location, location_iids);
4830 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
4832 hres = IHTMLLocation_get_pathname(location, &str);
4833 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
4834 ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
4835 SysFreeString(str);
4837 hres = IHTMLLocation_get_href(location, NULL);
4838 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
4840 hres = IHTMLLocation_get_href(location, &str);
4841 ok(hres == S_OK, "get_href failed: %08x\n", hres);
4842 ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
4843 SysFreeString(str);
4845 ref = IHTMLLocation_Release(location);
4846 ok(!ref, "location chould be destroyed here\n");
4849 static void test_plugins_col(IHTMLDocument2 *doc)
4851 IHTMLPluginsCollection *col, *col2;
4852 IHTMLWindow2 *window;
4853 IOmNavigator *nav;
4854 ULONG ref;
4855 LONG len;
4856 HRESULT hres;
4858 window = get_doc_window(doc);
4859 hres = IHTMLWindow2_get_navigator(window, &nav);
4860 IHTMLWindow2_Release(window);
4862 hres = IOmNavigator_get_plugins(nav, &col);
4863 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4865 hres = IOmNavigator_get_plugins(nav, &col2);
4866 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
4867 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4868 IHTMLPluginsCollection_Release(col2);
4870 test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, "[object]");
4872 len = 0xdeadbeef;
4873 hres = IHTMLPluginsCollection_get_length(col, &len);
4874 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4875 ok(!len, "length = %d\n", len);
4877 ref = IHTMLPluginsCollection_Release(col);
4878 ok(!ref, "ref=%d\n", ref);
4880 IOmNavigator_Release(nav);
4883 static void test_mime_types_col(IOmNavigator *nav)
4885 IHTMLMimeTypesCollection *col, *col2;
4886 LONG length;
4887 ULONG ref;
4888 HRESULT hres;
4890 hres = IOmNavigator_get_mimeTypes(nav, &col);
4891 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4893 hres = IOmNavigator_get_mimeTypes(nav, &col2);
4894 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
4895 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
4896 IHTMLMimeTypesCollection_Release(col2);
4898 test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, "[object]");
4900 length = 0xdeadbeef;
4901 hres = IHTMLMimeTypesCollection_get_length(col, &length);
4902 ok(hres == S_OK, "get_length failed: %08x\n", hres);
4903 ok(!length, "length = %d\n", length);
4905 ref = IHTMLMimeTypesCollection_Release(col);
4906 ok(!ref, "ref=%d\n", ref);
4909 #define test_framebase_name(a,b) _test_framebase_name(__LINE__,a,b)
4910 static void _test_framebase_name(unsigned line, IHTMLElement *elem, const char *name)
4912 BSTR str = (void*)0xdeadbeef;
4913 IHTMLFrameBase *fbase;
4914 HRESULT hres;
4916 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
4917 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
4919 hres = IHTMLFrameBase_get_name(fbase, &str);
4920 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
4921 if(name)
4922 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
4923 else
4924 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
4925 SysFreeString(str);
4927 IHTMLFrameBase_Release(fbase);
4930 #define test_framebase_put_name(a,b) _test_framebase_put_name(__LINE__,a,b)
4931 static void _test_framebase_put_name(unsigned line, IHTMLElement *elem, const char *name)
4933 IHTMLFrameBase *fbase;
4934 HRESULT hres;
4935 BSTR str;
4937 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
4938 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
4940 str = name ? a2bstr(name) : NULL;
4941 hres = IHTMLFrameBase_put_name(fbase, str);
4942 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
4943 SysFreeString(str);
4945 _test_framebase_name(line, elem, name);
4946 IHTMLFrameBase_Release(fbase);
4949 #define test_framebase_marginheight(a,b) _test_framebase_marginheight(__LINE__,a,b)
4950 static void _test_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const char *exval)
4952 VARIANT v;
4953 HRESULT hres;
4955 hres = IHTMLFrameBase_get_marginHeight(framebase, &v);
4956 ok_(__FILE__,line)(hres == S_OK, "get_marginHeight failed: %08x\n", hres);
4957 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginHeight) = %d\n", V_VT(&v));
4958 if(exval)
4959 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "marginHeight = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
4960 else
4961 ok_(__FILE__,line)(!V_BSTR(&v), "marginHeight = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
4962 VariantClear(&v);
4965 #define set_framebase_marginheight(a,b) _set_framebase_marginheight(__LINE__,a,b)
4966 static void _set_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const char *val)
4968 VARIANT v;
4969 HRESULT hres;
4971 V_VT(&v) = VT_BSTR;
4972 V_BSTR(&v) = a2bstr(val);
4973 hres = IHTMLFrameBase_put_marginHeight(framebase, v);
4974 ok_(__FILE__,line)(hres == S_OK, "put_marginHeight failed: %08x\n", hres);
4975 VariantClear(&v);
4978 #define test_framebase_marginwidth(a,b) _test_framebase_marginwidth(__LINE__,a,b)
4979 static void _test_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const char *exval)
4981 VARIANT v;
4982 HRESULT hres;
4984 hres = IHTMLFrameBase_get_marginWidth(framebase, &v);
4985 ok_(__FILE__,line)(hres == S_OK, "get_marginWidth failed: %08x\n", hres);
4986 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginWidth) = %d\n", V_VT(&v));
4987 if(exval)
4988 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "marginWidth = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
4989 else
4990 ok_(__FILE__,line)(!V_BSTR(&v), "marginWidth = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
4991 VariantClear(&v);
4994 #define set_framebase_marginwidth(a,b) _set_framebase_marginwidth(__LINE__,a,b)
4995 static void _set_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const char *val)
4997 VARIANT v;
4998 HRESULT hres;
5000 V_VT(&v) = VT_BSTR;
5001 V_BSTR(&v) = a2bstr(val);
5002 hres = IHTMLFrameBase_put_marginWidth(framebase, v);
5003 ok_(__FILE__,line)(hres == S_OK, "put_marginWidth failed: %08x\n", hres);
5004 VariantClear(&v);
5007 static void test_framebase(IUnknown *unk)
5009 IHTMLFrameBase *fbase;
5010 BSTR str;
5011 HRESULT hres;
5013 /* get/put scrolling */
5014 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFrameBase, (void**)&fbase);
5015 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5017 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5018 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5019 ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
5020 SysFreeString(str);
5022 str = a2bstr("no");
5023 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5024 ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
5025 SysFreeString(str);
5027 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5028 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5029 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5030 SysFreeString(str);
5032 str = a2bstr("junk");
5033 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5034 ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
5035 "with E_INVALIDARG, instead: 0x%08x\n", hres);
5036 SysFreeString(str);
5038 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5039 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5040 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5041 SysFreeString(str);
5043 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
5044 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
5045 ok(!str, "frameBorder = %s\n", wine_dbgstr_w(str));
5047 str = a2bstr("1");
5048 hres = IHTMLFrameBase_put_frameBorder(fbase, str);
5049 ok(hres == S_OK, "put_frameBorder failed: %08x\n", hres);
5050 SysFreeString(str);
5052 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
5053 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
5054 ok(!strcmp_wa(str, "1"), "frameBorder = %s, expected \"1\"\n", wine_dbgstr_w(str));
5056 test_framebase_marginheight(fbase, NULL);
5057 set_framebase_marginheight(fbase, "1px");
5058 test_framebase_marginheight(fbase, "1");
5060 test_framebase_marginwidth(fbase, NULL);
5061 set_framebase_marginwidth(fbase, "2px");
5062 test_framebase_marginwidth(fbase, "2");
5064 IHTMLFrameBase_Release(fbase);
5067 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
5068 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
5070 WCHAR buf[64];
5071 int res;
5073 if(pLCIDToLocaleName) {
5074 res = pLCIDToLocaleName(lcid, buf, sizeof(buf)/sizeof(WCHAR), 0);
5075 ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
5076 ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
5077 }else {
5078 win_skip("LCIDToLocaleName not available, unable to test language string\n");
5079 ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
5083 #define test_table_length(t,l) _test_table_length(__LINE__,t,l)
5084 static void _test_table_length(unsigned line, IHTMLTable *table, LONG expect)
5086 IHTMLElementCollection *col;
5087 HRESULT hres;
5088 LONG len;
5090 hres = IHTMLTable_get_rows(table, &col);
5091 ok_(__FILE__,line)(hres == S_OK, "get_rows failed: %08x\n", hres);
5092 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
5093 if (hres != S_OK || col == NULL)
5094 return;
5095 hres = IHTMLElementCollection_get_length(col, &len);
5096 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
5097 ok_(__FILE__,line)(len == expect, "Expect %d, got %d\n", expect, len);
5099 IHTMLElementCollection_Release(col);
5102 static void test_navigator(IHTMLDocument2 *doc)
5104 IHTMLWindow2 *window;
5105 IOmNavigator *navigator, *navigator2;
5106 VARIANT_BOOL b;
5107 char buf[512];
5108 DWORD size;
5109 ULONG ref;
5110 BSTR bstr;
5111 HRESULT hres;
5113 static const WCHAR v40[] = {'4','.','0'};
5115 hres = IHTMLDocument2_get_parentWindow(doc, &window);
5116 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
5118 hres = IHTMLWindow2_get_navigator(window, &navigator);
5119 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
5120 ok(navigator != NULL, "navigator == NULL\n");
5121 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
5123 hres = IHTMLWindow2_get_navigator(window, &navigator2);
5124 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
5125 ok(navigator != navigator2, "navigator2 != navihgator\n");
5127 IHTMLWindow2_Release(window);
5128 IOmNavigator_Release(navigator2);
5130 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
5131 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
5132 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
5133 SysFreeString(bstr);
5135 bstr = NULL;
5136 hres = IOmNavigator_get_appName(navigator, &bstr);
5137 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
5138 ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
5139 SysFreeString(bstr);
5141 bstr = NULL;
5142 hres = IOmNavigator_get_platform(navigator, &bstr);
5143 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
5144 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "Win64" : "Win32")
5145 || (sizeof(void*) == 8 && broken(!strcmp_wa(bstr, "Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
5146 SysFreeString(bstr);
5148 bstr = NULL;
5149 hres = IOmNavigator_get_cpuClass(navigator, &bstr);
5150 ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
5151 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "x64" : "x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
5152 SysFreeString(bstr);
5154 bstr = NULL;
5155 hres = IOmNavigator_get_appVersion(navigator, &bstr);
5156 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
5157 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
5158 SysFreeString(bstr);
5160 bstr = NULL;
5161 hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
5162 ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
5163 test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
5164 SysFreeString(bstr);
5166 if (pGetUserDefaultUILanguage)
5168 bstr = NULL;
5169 hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
5170 ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
5171 test_language_string(bstr, pGetUserDefaultUILanguage());
5172 SysFreeString(bstr);
5174 else
5175 win_skip("GetUserDefaultUILanguage not available\n");
5177 bstr = NULL;
5178 hres = IOmNavigator_get_userLanguage(navigator, &bstr);
5179 ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
5180 test_language_string(bstr, LOCALE_USER_DEFAULT);
5181 SysFreeString(bstr);
5183 hres = IOmNavigator_toString(navigator, NULL);
5184 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
5186 bstr = NULL;
5187 hres = IOmNavigator_toString(navigator, &bstr);
5188 ok(hres == S_OK, "toString failed: %08x\n", hres);
5189 ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
5190 SysFreeString(bstr);
5192 b = 100;
5193 hres = IOmNavigator_get_onLine(navigator, &b);
5194 ok(hres == S_OK, "get_onLine failed: %08x\n", hres);
5195 ok(b == VARIANT_TRUE, "onLine = %x\n", b);
5197 size = sizeof(buf);
5198 hres = ObtainUserAgentString(0, buf, &size);
5199 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
5201 bstr = NULL;
5202 hres = IOmNavigator_get_userAgent(navigator, &bstr);
5203 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
5204 ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
5205 SysFreeString(bstr);
5207 if(!strncmp(buf, "Mozilla/", 8)) {
5208 bstr = NULL;
5209 hres = IOmNavigator_get_appVersion(navigator, &bstr);
5210 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
5211 ok(!strcmp_wa(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf+8);
5212 SysFreeString(bstr);
5213 }else {
5214 skip("nonstandard user agent\n");
5217 bstr = NULL;
5218 hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
5219 ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
5220 ok(bstr != NULL, "appMinorVersion returned NULL\n");
5221 SysFreeString(bstr);
5223 test_mime_types_col(navigator);
5225 ref = IOmNavigator_Release(navigator);
5226 ok(!ref, "navigator should be destroyed here\n");
5229 static void test_screen(IHTMLWindow2 *window)
5231 IHTMLScreen *screen, *screen2;
5232 IDispatchEx *dispex;
5233 RECT work_area;
5234 LONG l, exl;
5235 HDC hdc;
5236 HRESULT hres;
5238 screen = NULL;
5239 hres = IHTMLWindow2_get_screen(window, &screen);
5240 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
5241 ok(screen != NULL, "screen == NULL\n");
5243 screen2 = NULL;
5244 hres = IHTMLWindow2_get_screen(window, &screen2);
5245 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
5246 ok(screen2 != NULL, "screen == NULL\n");
5247 ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
5248 IHTMLScreen_Release(screen2);
5250 hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
5251 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
5252 if(SUCCEEDED(hres)) {
5253 test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
5254 IDispatchEx_Release(dispex);
5257 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
5259 exl = GetDeviceCaps(hdc, HORZRES);
5260 l = 0xdeadbeef;
5261 hres = IHTMLScreen_get_width(screen, &l);
5262 ok(hres == S_OK, "get_width failed: %08x\n", hres);
5263 ok(l == exl, "width = %d, expected %d\n", l, exl);
5265 exl = GetDeviceCaps(hdc, VERTRES);
5266 l = 0xdeadbeef;
5267 hres = IHTMLScreen_get_height(screen, &l);
5268 ok(hres == S_OK, "get_height failed: %08x\n", hres);
5269 ok(l == exl, "height = %d, expected %d\n", l, exl);
5271 exl = GetDeviceCaps(hdc, BITSPIXEL);
5272 l = 0xdeadbeef;
5273 hres = IHTMLScreen_get_colorDepth(screen, &l);
5274 ok(hres == S_OK, "get_height failed: %08x\n", hres);
5275 ok(l == exl, "height = %d, expected %d\n", l, exl);
5277 DeleteObject(hdc);
5279 SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
5281 l = 0xdeadbeef;
5282 hres = IHTMLScreen_get_availHeight(screen, &l);
5283 ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
5284 ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
5286 l = 0xdeadbeef;
5287 hres = IHTMLScreen_get_availWidth(screen, &l);
5288 ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
5289 ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
5291 IHTMLScreen_Release(screen);
5294 static void test_default_selection(IHTMLDocument2 *doc)
5296 IHTMLSelectionObject *selection;
5297 IHTMLTxtRange *range;
5298 IDispatch *disp;
5299 BSTR str;
5300 HRESULT hres;
5302 hres = IHTMLDocument2_get_selection(doc, &selection);
5303 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
5305 hres = IHTMLSelectionObject_get_type(selection, &str);
5306 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5307 ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
5308 SysFreeString(str);
5310 hres = IHTMLSelectionObject_createRange(selection, &disp);
5311 IHTMLSelectionObject_Release(selection);
5312 ok(hres == S_OK, "createRange failed: %08x\n", hres);
5314 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
5315 IDispatch_Release(disp);
5316 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
5318 test_range_text(range, NULL);
5319 IHTMLTxtRange_Release(range);
5322 static void test_doc_elem(IHTMLDocument2 *doc)
5324 IHTMLDocument2 *doc_node, *owner_doc;
5325 IHTMLElement *elem;
5326 IHTMLDocument3 *doc3;
5327 HRESULT hres;
5328 BSTR bstr;
5330 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5331 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
5333 hres = IHTMLDocument2_toString(doc, &bstr);
5334 ok(hres == S_OK, "toString failed: %08x\n", hres);
5335 ok(!strcmp_wa(bstr, "[object]"),
5336 "toString returned %s, expected [object]\n", wine_dbgstr_w(bstr));
5337 SysFreeString(bstr);
5339 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
5340 IHTMLDocument3_Release(doc3);
5341 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
5343 test_node_name((IUnknown*)elem, "HTML");
5344 test_elem_tag((IUnknown*)elem, "HTML");
5346 doc_node = get_doc_node(doc);
5347 owner_doc = get_owner_doc((IUnknown*)elem);
5348 ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
5349 IHTMLDocument2_Release(owner_doc);
5351 owner_doc = get_owner_doc((IUnknown*)doc_node);
5352 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5353 IHTMLDocument2_Release(doc_node);
5355 test_elem_client_rect((IUnknown*)elem);
5357 IHTMLElement_Release(elem);
5360 static void test_default_body(IHTMLBodyElement *body)
5362 LONG l;
5363 BSTR bstr;
5364 HRESULT hres;
5365 VARIANT v;
5367 bstr = (void*)0xdeadbeef;
5368 hres = IHTMLBodyElement_get_background(body, &bstr);
5369 ok(hres == S_OK, "get_background failed: %08x\n", hres);
5370 ok(bstr == NULL, "bstr != NULL\n");
5372 l = elem_get_scroll_height((IUnknown*)body);
5373 ok(l != -1, "scrollHeight == -1\n");
5374 l = elem_get_scroll_width((IUnknown*)body);
5375 ok(l != -1, "scrollWidth == -1\n");
5376 l = elem_get_scroll_top((IUnknown*)body);
5377 ok(!l, "scrollTop = %d\n", l);
5378 elem_get_scroll_left((IUnknown*)body);
5380 /* get_text tests */
5381 hres = IHTMLBodyElement_get_text(body, &v);
5382 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5383 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5384 ok(V_BSTR(&v) == NULL, "bstr != NULL\n");
5386 /* get_text - Invalid Text */
5387 V_VT(&v) = VT_BSTR;
5388 V_BSTR(&v) = a2bstr("Invalid");
5389 hres = IHTMLBodyElement_put_text(body, v);
5390 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5391 VariantClear(&v);
5393 V_VT(&v) = VT_NULL;
5394 hres = IHTMLBodyElement_get_text(body, &v);
5395 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5396 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5397 ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
5398 VariantClear(&v);
5400 /* get_text - Valid Text */
5401 V_VT(&v) = VT_BSTR;
5402 V_BSTR(&v) = a2bstr("#FF0000");
5403 hres = IHTMLBodyElement_put_text(body, v);
5404 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5405 VariantClear(&v);
5407 V_VT(&v) = VT_NULL;
5408 hres = IHTMLBodyElement_get_text(body, &v);
5409 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
5410 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
5411 ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
5412 VariantClear(&v);
5415 #define test_body_scroll(a,b) _test_body_scroll(__LINE__,a,b)
5416 static void _test_body_scroll(unsigned line, IHTMLBodyElement *body, const char *ex)
5418 BSTR str;
5419 HRESULT hres;
5421 hres = IHTMLBodyElement_get_scroll(body, &str);
5422 ok_(__FILE__,line)(hres == S_OK, "get_scroll failed: %08x\n", hres);
5423 ok_(__FILE__,line)(ex ? !strcmp_wa(str, ex) : !str, "scroll = %s\n", wine_dbgstr_w(str));
5424 SysFreeString(str);
5427 #define set_body_scroll(a,b) _set_body_scroll(__LINE__,a,b)
5428 static void _set_body_scroll(unsigned line, IHTMLBodyElement *body, const char *val)
5430 BSTR str = a2bstr(val);
5431 HRESULT hres;
5433 hres = IHTMLBodyElement_put_scroll(body, str);
5434 ok_(__FILE__,line)(hres == S_OK, "put_scroll failed: %08x\n", hres);
5435 SysFreeString(str);
5437 _test_body_scroll(line, body, val);
5440 static void test_body_funs(IHTMLBodyElement *body)
5442 VARIANT vbg, vDefaultbg;
5443 HRESULT hres;
5445 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
5446 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5447 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
5448 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
5450 V_VT(&vbg) = VT_BSTR;
5451 V_BSTR(&vbg) = a2bstr("red");
5452 hres = IHTMLBodyElement_put_bgColor(body, vbg);
5453 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5454 VariantClear(&vbg);
5456 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
5457 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5458 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
5459 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
5460 VariantClear(&vbg);
5462 /* Restore Originial */
5463 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
5464 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5465 VariantClear(&vDefaultbg);
5467 test_body_scroll(body, NULL);
5468 set_body_scroll(body, "yes");
5469 set_body_scroll(body, "no");
5470 set_body_scroll(body, "auto");
5473 static void test_history(IHTMLWindow2 *window)
5475 IOmHistory *history, *history2;
5476 HRESULT hres;
5478 history = NULL;
5479 hres = IHTMLWindow2_get_history(window, &history);
5480 ok(hres == S_OK, "get_history failed: %08x\n", hres);
5481 ok(history != NULL, "history = NULL\n");
5483 test_disp2((IUnknown*)history, &DIID_DispHTMLHistory, &IID_IOmHistory, "[object]");
5485 history2 = NULL;
5486 hres = IHTMLWindow2_get_history(window, &history2);
5487 ok(hres == S_OK, "get_history failed: %08x\n", hres);
5488 ok(history2 != NULL, "history2 = NULL\n");
5489 ok(iface_cmp((IUnknown*)history, (IUnknown*)history2), "history != history2\n");
5491 IOmHistory_Release(history2);
5492 IOmHistory_Release(history);
5495 static void test_window(IHTMLDocument2 *doc)
5497 IHTMLWindow2 *window, *window2, *self, *parent;
5498 IHTMLDocument2 *doc2 = NULL;
5499 IDispatch *disp;
5500 IUnknown *unk;
5501 VARIANT v;
5502 BSTR str;
5503 HRESULT hres;
5505 hres = IHTMLDocument2_get_parentWindow(doc, &window);
5506 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
5507 test_ifaces((IUnknown*)window, window_iids);
5508 hres = IHTMLWindow2_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
5509 if(hres == S_OK)
5510 IUnknown_Release(unk);
5511 else
5512 win_skip("IID_ITravelLogClient not supported\n");
5514 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
5516 hres = IHTMLWindow2_get_document(window, &doc2);
5517 ok(hres == S_OK, "get_document failed: %08x\n", hres);
5518 ok(doc2 != NULL, "doc2 == NULL\n");
5520 test_ifaces((IUnknown*)doc2, doc_node_iids);
5521 test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
5522 test_class_info((IUnknown*)doc2);
5524 test_ifaces((IUnknown*)doc, doc_obj_iids);
5525 test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, "[object]");
5526 test_class_info((IUnknown*)doc);
5528 unk = (void*)0xdeadbeef;
5529 hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
5530 ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
5531 ok(!unk, "unk = %p\n", unk);
5533 IHTMLDocument2_Release(doc2);
5535 hres = IHTMLWindow2_get_window(window, &window2);
5536 ok(hres == S_OK, "get_window failed: %08x\n", hres);
5537 ok(window2 != NULL, "window2 == NULL\n");
5539 hres = IHTMLWindow2_get_self(window, &self);
5540 ok(hres == S_OK, "get_self failed: %08x\n", hres);
5541 ok(window2 != NULL, "self == NULL\n");
5543 ok(self == window2, "self != window2\n");
5545 IHTMLWindow2_Release(window2);
5547 disp = NULL;
5548 hres = IHTMLDocument2_get_Script(doc, &disp);
5549 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
5550 ok(disp == (void*)window, "disp != window\n");
5551 IDispatch_Release(disp);
5553 hres = IHTMLWindow2_toString(window, NULL);
5554 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
5556 str = NULL;
5557 hres = IHTMLWindow2_toString(window, &str);
5558 ok(hres == S_OK, "toString failed: %08x\n", hres);
5559 ok(!strcmp_wa(str, "[object]") ||
5560 !strcmp_wa(str, "[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
5561 SysFreeString(str);
5563 V_VT(&v) = VT_ERROR;
5564 hres = IHTMLWindow2_get_opener(window, &v);
5565 ok(hres == S_OK, "get_opener failed: %08x\n", hres);
5566 ok(V_VT(&v) == VT_EMPTY, "V_VT(opener) = %d\n", V_VT(&v));
5568 parent = NULL;
5569 hres = IHTMLWindow2_get_parent(window, &parent);
5570 ok(hres == S_OK, "get_parent failed: %08x\n", hres);
5571 ok(parent != NULL, "parent == NULL\n");
5572 ok(parent == self, "parent != window\n");
5573 IHTMLWindow2_Release(parent);
5574 IHTMLWindow2_Release(self);
5576 test_window_name(window, NULL);
5577 set_window_name(window, "test");
5578 test_window_length(window, 0);
5579 test_screen(window);
5580 test_window_status(window);
5581 set_window_status(window, "Test!");
5582 test_history(window);
5584 IHTMLWindow2_Release(window);
5587 static void test_defaults(IHTMLDocument2 *doc)
5589 IHTMLStyleSheetsCollection *stylesheetcol;
5590 IHTMLCurrentStyle *cstyle;
5591 IHTMLBodyElement *body;
5592 IHTMLElement2 *elem2;
5593 IHTMLElement *elem;
5594 IHTMLStyle *style;
5595 BSTR str;
5596 LONG l;
5597 HRESULT hres;
5598 IHTMLElementCollection *collection;
5600 elem = doc_get_body(doc);
5602 hres = IHTMLDocument2_get_images(doc, NULL);
5603 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5605 hres = IHTMLDocument2_get_images(doc, &collection);
5606 ok(hres == S_OK, "get_images failed: %08x\n", hres);
5607 if(hres == S_OK)
5609 test_elem_collection((IUnknown*)collection, NULL, 0);
5610 IHTMLElementCollection_Release(collection);
5613 hres = IHTMLDocument2_get_applets(doc, NULL);
5614 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5616 hres = IHTMLDocument2_get_applets(doc, &collection);
5617 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
5618 if(hres == S_OK)
5620 test_elem_collection((IUnknown*)collection, NULL, 0);
5621 IHTMLElementCollection_Release(collection);
5624 hres = IHTMLDocument2_get_links(doc, NULL);
5625 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5627 hres = IHTMLDocument2_get_links(doc, &collection);
5628 ok(hres == S_OK, "get_links failed: %08x\n", hres);
5629 if(hres == S_OK)
5631 test_elem_collection((IUnknown*)collection, NULL, 0);
5632 IHTMLElementCollection_Release(collection);
5635 hres = IHTMLDocument2_get_forms(doc, NULL);
5636 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5638 hres = IHTMLDocument2_get_forms(doc, &collection);
5639 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
5640 if(hres == S_OK)
5642 test_elem_collection((IUnknown*)collection, NULL, 0);
5643 IHTMLElementCollection_Release(collection);
5646 hres = IHTMLDocument2_get_anchors(doc, NULL);
5647 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
5649 hres = IHTMLDocument2_get_anchors(doc, &collection);
5650 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
5651 if(hres == S_OK)
5653 test_elem_collection((IUnknown*)collection, NULL, 0);
5654 IHTMLElementCollection_Release(collection);
5657 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
5658 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
5659 test_default_body(body);
5660 test_body_funs(body);
5661 IHTMLBodyElement_Release(body);
5663 hres = IHTMLElement_get_style(elem, &style);
5664 ok(hres == S_OK, "get_style failed: %08x\n", hres);
5666 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
5667 test_ifaces((IUnknown*)style, style_iids);
5668 IHTMLStyle_Release(style);
5670 str = NULL;
5671 hres = IHTMLDocument2_get_charset(doc, &str);
5672 ok(hres == S_OK, "get_charset failed: %08x\n", hres);
5673 ok(str && *str, "charset is empty\n"); /* FIXME: better tests */
5674 SysFreeString(str);
5676 test_window(doc);
5677 test_compatmode(doc, "BackCompat");
5678 test_location(doc);
5679 test_navigator(doc);
5680 test_plugins_col(doc);
5682 elem2 = get_elem2_iface((IUnknown*)elem);
5683 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
5684 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
5685 if(SUCCEEDED(hres)) {
5686 IUnknown *unk;
5688 test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, "[object]");
5689 test_ifaces((IUnknown*)cstyle, cstyle_iids);
5691 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
5692 if(SUCCEEDED(hres))
5693 IUnknown_Release(unk);
5694 else
5696 /*IE6 doesn't have interface */
5697 win_skip("IID_IHTMLCurrentStyle4 not supported\n");
5700 IHTMLCurrentStyle_Release(cstyle);
5702 IHTMLElement2_Release(elem2);
5704 IHTMLElement_Release(elem);
5706 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
5707 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
5709 l = 0xdeadbeef;
5710 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
5711 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5712 ok(l == 0, "length = %d\n", l);
5714 IHTMLStyleSheetsCollection_Release(stylesheetcol);
5716 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
5717 ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
5719 test_default_selection(doc);
5720 test_doc_title(doc, "");
5723 #define test_button_name(a,b) _test_button_name(__LINE__,a,b)
5724 static void _test_button_name(unsigned line, IHTMLElement *elem, const char *exname)
5726 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
5727 BSTR str;
5728 HRESULT hres;
5730 str = (void*)0xdeadbeef;
5731 hres = IHTMLButtonElement_get_name(button, &str);
5732 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
5733 if(exname)
5734 ok_(__FILE__,line)(!strcmp_wa(str, exname), "name = %s, expected %s\n", wine_dbgstr_w(str), exname);
5735 else
5736 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
5737 SysFreeString(str);
5738 IHTMLButtonElement_Release(button);
5741 #define set_button_name(a,b) _set_button_name(__LINE__,a,b)
5742 static void _set_button_name(unsigned line, IHTMLElement *elem, const char *name)
5744 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
5745 BSTR str = a2bstr(name);
5746 HRESULT hres;
5748 hres = IHTMLButtonElement_put_name(button, str);
5749 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
5750 SysFreeString(str);
5751 IHTMLButtonElement_Release(button);
5753 _test_button_name(line, elem, name);
5756 #define test_button_get_disabled(i,b) _test_button_get_disabled(__LINE__,i,b)
5757 static void _test_button_get_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
5759 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
5760 VARIANT_BOOL disabled = 100;
5761 HRESULT hres;
5763 hres = IHTMLButtonElement_get_disabled(button, &disabled);
5764 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
5765 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
5766 IHTMLButtonElement_Release(button);
5768 _test_elem3_get_disabled(line, (IUnknown*)elem, exb);
5771 #define test_button_set_disabled(i,b) _test_button_set_disabled(__LINE__,i,b)
5772 static void _test_button_set_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL b)
5774 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
5775 HRESULT hres;
5777 hres = IHTMLButtonElement_put_disabled(button, b);
5778 ok_(__FILE__,line) (hres == S_OK, "put_disabled failed: %08x\n", hres);
5779 IHTMLButtonElement_Release(button);
5781 _test_button_get_disabled(line, elem, b);
5784 static void test_button_elem(IHTMLElement *elem)
5786 test_button_name(elem, NULL);
5787 set_button_name(elem, "button name");
5790 #define test_tr_possess(e,r,l,i) _test_tr_possess(__LINE__,e,r,l,i)
5791 static void _test_tr_possess(unsigned line, IHTMLElement *elem,
5792 IHTMLTableRow *row, LONG len, const char *id)
5794 IHTMLElementCollection *col;
5795 IDispatch *disp;
5796 HRESULT hres;
5797 LONG lval;
5798 VARIANT var;
5800 hres = IHTMLTableRow_get_cells(row, &col);
5801 ok_(__FILE__, line)(hres == S_OK, "get_cells failed: %08x\n", hres);
5802 ok_(__FILE__, line)(col != NULL, "get_cells returned NULL\n");
5804 hres = IHTMLElementCollection_get_length(col, &lval);
5805 ok_(__FILE__, line)(hres == S_OK, "get length failed: %08x\n", hres);
5806 ok_(__FILE__, line)(lval == len, "expected len = %d, got %d\n", len, lval);
5808 V_VT(&var) = VT_BSTR;
5809 V_BSTR(&var) = a2bstr(id);
5810 hres = IHTMLElementCollection_tags(col, var, &disp);
5811 ok_(__FILE__, line)(hres == S_OK, "search by tags(%s) failed: %08x\n", id, hres);
5812 ok_(__FILE__, line)(disp != NULL, "disp == NULL\n");
5814 VariantClear(&var);
5815 IDispatch_Release(disp);
5816 IHTMLElementCollection_Release(col);
5819 static void test_tr_modify(IHTMLElement *elem, IHTMLTableRow *row)
5821 HRESULT hres;
5822 IDispatch *disp;
5823 IHTMLTableCell *cell;
5825 hres = IHTMLTableRow_deleteCell(row, 0);
5826 ok(hres == S_OK, "deleteCell failed: %08x\n", hres);
5827 test_tr_possess(elem, row, 1, "td2");
5829 hres = IHTMLTableRow_insertCell(row, 0, &disp);
5830 ok(hres == S_OK, "insertCell failed: %08x\n", hres);
5831 ok(disp != NULL, "disp == NULL\n");
5832 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableCell, (void **)&cell);
5833 ok(hres == S_OK, "Could not get IID_IHTMLTableCell interface: %08x\n", hres);
5834 ok(cell != NULL, "cell == NULL\n");
5835 if (SUCCEEDED(hres))
5836 IHTMLTableCell_Release(cell);
5837 test_tr_possess(elem, row, 2, "td2");
5838 IDispatch_Release(disp);
5841 static void test_tr_elem(IHTMLElement *elem)
5843 IHTMLElementCollection *col;
5844 IHTMLTableRow *row;
5845 HRESULT hres;
5846 BSTR bstr;
5847 LONG lval;
5848 VARIANT vbg, vDefaultbg;
5850 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
5852 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
5853 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
5854 if(FAILED(hres))
5855 return;
5857 col = NULL;
5858 hres = IHTMLTableRow_get_cells(row, &col);
5859 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
5860 ok(col != NULL, "get_cells returned NULL\n");
5862 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
5863 IHTMLElementCollection_Release(col);
5865 bstr = a2bstr("left");
5866 hres = IHTMLTableRow_put_align(row, bstr);
5867 ok(hres == S_OK, "set_align failed: %08x\n", hres);
5868 SysFreeString(bstr);
5870 bstr = NULL;
5871 hres = IHTMLTableRow_get_align(row, &bstr);
5872 ok(hres == S_OK, "get_align failed: %08x\n", hres);
5873 ok(bstr != NULL, "get_align returned NULL\n");
5874 ok(!strcmp_wa(bstr, "left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
5875 SysFreeString(bstr);
5877 bstr = a2bstr("top");
5878 hres = IHTMLTableRow_put_vAlign(row, bstr);
5879 ok(hres == S_OK, "set_valign failed: %08x\n", hres);
5880 SysFreeString(bstr);
5882 bstr = NULL;
5883 hres = IHTMLTableRow_get_vAlign(row, &bstr);
5884 ok(hres == S_OK, "get_valign failed: %08x\n", hres);
5885 ok(bstr != NULL, "get_valign returned NULL\n");
5886 ok(!strcmp_wa(bstr, "top"), "get_valign returned %s\n", wine_dbgstr_w(bstr));
5887 SysFreeString(bstr);
5889 lval = 0xdeadbeef;
5890 hres = IHTMLTableRow_get_rowIndex(row, &lval);
5891 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
5892 ok(lval == 1, "get_rowIndex returned %d\n", lval);
5894 lval = 0xdeadbeef;
5895 hres = IHTMLTableRow_get_sectionRowIndex(row, &lval);
5896 ok(hres == S_OK, "get_sectionRowIndex failed: %08x\n", hres);
5897 ok(lval == 1, "get_sectionRowIndex returned %d\n", lval);
5899 hres = IHTMLTableRow_get_bgColor(row, &vDefaultbg);
5900 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5901 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
5902 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
5904 V_VT(&vbg) = VT_BSTR;
5905 V_BSTR(&vbg) = a2bstr("red");
5906 hres = IHTMLTableRow_put_bgColor(row, vbg);
5907 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5908 VariantClear(&vbg);
5910 hres = IHTMLTableRow_get_bgColor(row, &vbg);
5911 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5912 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
5913 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
5914 VariantClear(&vbg);
5916 V_VT(&vbg) = VT_I4;
5917 V_I4(&vbg) = 0xff0000;
5918 hres = IHTMLTableRow_put_bgColor(row, vbg);
5919 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5920 VariantClear(&vbg);
5922 hres = IHTMLTableRow_get_bgColor(row, &vbg);
5923 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
5924 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
5925 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
5926 VariantClear(&vbg);
5928 /* Restore Originial */
5929 hres = IHTMLTableRow_put_bgColor(row, vDefaultbg);
5930 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
5931 VariantClear(&vDefaultbg);
5933 test_tr_modify(elem, row);
5935 IHTMLTableRow_Release(row);
5938 static void test_td_elem(IHTMLElement *elem)
5940 IHTMLTableCell *cell;
5941 HRESULT hres;
5942 LONG lval;
5943 BSTR str;
5945 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableCell, (void**)&cell);
5946 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
5947 if(FAILED(hres))
5948 return;
5950 lval = 0xdeadbeef;
5951 hres = IHTMLTableCell_get_cellIndex(cell, &lval);
5952 ok(hres == S_OK, "get cellIndex failed: %08x\n", hres);
5953 ok(lval == 1, "Expected 1, got %d\n", lval);
5955 str = a2bstr("left");
5956 hres = IHTMLTableCell_put_align(cell, str);
5957 ok(hres == S_OK, "put_align failed: %08x\n", hres);
5958 SysFreeString(str);
5960 str = NULL;
5961 hres = IHTMLTableCell_get_align(cell, &str);
5962 ok(hres == S_OK, "get_align failed: %08x\n", hres);
5963 ok(str != NULL, "str is NULL\n");
5964 if (str != NULL && hres == S_OK) {
5965 ok(!strcmp_wa(str, "left"), "got %s\n", wine_dbgstr_w(str));
5966 SysFreeString(str);
5969 IHTMLTableCell_Release(cell);
5972 static void test_label_elem(IHTMLElement *elem)
5974 IHTMLLabelElement *label;
5975 BSTR str;
5976 HRESULT hres;
5978 label = get_label_iface((IUnknown*)elem);
5980 str = NULL;
5981 hres = IHTMLLabelElement_get_htmlFor(label, &str);
5982 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
5983 ok(!strcmp_wa(str, "in"), "htmlFor = %s\n", wine_dbgstr_w(str));
5984 SysFreeString(str);
5986 str = a2bstr("");
5987 hres = IHTMLLabelElement_put_htmlFor(label, str);
5988 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
5989 SysFreeString(str);
5991 str = (void*)0xdeadbeef;
5992 hres = IHTMLLabelElement_get_htmlFor(label, &str);
5993 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
5994 ok(!strcmp_wa(str, ""), "htmlFor = %s\n", wine_dbgstr_w(str));
5996 str = a2bstr("abc");
5997 hres = IHTMLLabelElement_put_htmlFor(label, str);
5998 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
5999 SysFreeString(str);
6001 str = NULL;
6002 hres = IHTMLLabelElement_get_htmlFor(label, &str);
6003 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
6004 ok(!strcmp_wa(str, "abc"), "htmlFor = %s\n", wine_dbgstr_w(str));
6005 SysFreeString(str);
6007 IHTMLLabelElement_Release(label);
6010 #define test_table_cell_spacing(a,b) _test_table_cell_spacing(__LINE__,a,b)
6011 static void _test_table_cell_spacing(unsigned line, IHTMLTable *table, const char *exstr)
6013 VARIANT v;
6014 HRESULT hres;
6016 V_VT(&v) = VT_ERROR;
6017 hres = IHTMLTable_get_cellSpacing(table, &v);
6018 ok_(__FILE__,line)(hres == S_OK, "get_cellSpacing failed: %08x\n", hres);
6019 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
6020 if(exstr)
6021 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exstr), "cellSpacing = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exstr);
6022 else
6023 ok_(__FILE__,line)(!V_BSTR(&v), "cellSpacing = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6024 VariantClear(&v);
6027 static void test_table_modify(IHTMLTable *table)
6029 IDispatch *disp;
6030 IHTMLTableRow *row;
6031 HRESULT hres;
6032 LONG index;
6034 test_table_length(table, 2);
6036 hres = IHTMLTable_insertRow(table, 0, &disp);
6037 ok(hres == S_OK, "insertRow failed: %08x\n", hres);
6038 ok(disp != NULL, "disp == NULL\n");
6039 test_table_length(table, 3);
6040 if (hres != S_OK || disp == NULL)
6041 return;
6043 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableRow, (void**)&row);
6044 IDispatch_Release(disp);
6046 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
6047 ok(row != NULL, "row == NULL\n");
6049 index = 0xdeadbeef;
6050 hres = IHTMLTableRow_get_rowIndex(row, &index);
6051 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
6052 ok(index == 0, "index = %d, expected 0\n", index);
6054 IHTMLTableRow_Release(row);
6056 hres = IHTMLTable_deleteRow(table, 0);
6057 ok(hres == S_OK, "deleteRow failed: %08x\n", hres);
6058 test_table_length(table, 2);
6061 static void test_table_elem(IHTMLElement *elem)
6063 IHTMLElementCollection *col;
6064 IHTMLTable *table;
6065 IHTMLTable3 *table3;
6066 IHTMLDOMNode *node;
6067 VARIANT v;
6068 HRESULT hres;
6069 BSTR bstr;
6070 VARIANT vbg, vDefaultbg;
6072 static const elem_type_t row_types[] = {ET_TR,ET_TR};
6073 static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
6074 static const elem_type_t tbodies_types[] = {ET_TBODY};
6076 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
6077 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
6078 if(FAILED(hres))
6079 return;
6081 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable3, (void**)&table3);
6082 ok(hres == S_OK, "Could not get IHTMLTable3 iface: %08x\n", hres);
6083 if(FAILED(hres))
6084 return;
6086 col = NULL;
6087 hres = IHTMLTable_get_rows(table, &col);
6088 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
6089 ok(col != NULL, "get_rows returned NULL\n");
6091 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
6092 IHTMLElementCollection_Release(col);
6094 test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
6096 node = clone_node((IUnknown*)table, VARIANT_TRUE);
6097 test_elem_tag((IUnknown*)node, "TABLE");
6098 test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
6099 IHTMLDOMNode_Release(node);
6101 node = clone_node((IUnknown*)table, VARIANT_FALSE);
6102 test_elem_tag((IUnknown*)node, "TABLE");
6103 test_elem_all((IUnknown*)node, NULL, 0);
6104 IHTMLDOMNode_Release(node);
6106 col = NULL;
6107 hres = IHTMLTable_get_tBodies(table, &col);
6108 ok(hres == S_OK, "get_tBodies failed: %08x\n", hres);
6109 ok(col != NULL, "get_tBodies returned NULL\n");
6111 test_elem_collection((IUnknown*)col, tbodies_types, sizeof(tbodies_types)/sizeof(*tbodies_types));
6112 IHTMLElementCollection_Release(col);
6114 test_table_cell_spacing(table, NULL);
6116 V_VT(&v) = VT_I4;
6117 V_I4(&v) = 10;
6118 hres = IHTMLTable_put_cellSpacing(table, v);
6119 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
6120 test_table_cell_spacing(table, "10");
6122 V_VT(&v) = VT_BSTR;
6123 V_BSTR(&v) = a2bstr("11");
6124 hres = IHTMLTable_put_cellSpacing(table, v);
6125 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
6126 test_table_cell_spacing(table, "11");
6127 VariantClear(&v);
6129 bstr = a2bstr("left");
6130 hres = IHTMLTable_put_align(table, bstr);
6131 ok(hres == S_OK, "set_align failed: %08x\n", hres);
6132 SysFreeString(bstr);
6134 bstr = NULL;
6135 hres = IHTMLTable_get_align(table, &bstr);
6136 ok(hres == S_OK, "get_align failed: %08x\n", hres);
6137 ok(bstr != NULL, "get_align returned NULL\n");
6138 ok(!strcmp_wa(bstr, "left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
6139 SysFreeString(bstr);
6141 hres = IHTMLTable_get_bgColor(table, &vDefaultbg);
6142 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6143 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6144 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6146 V_VT(&vbg) = VT_BSTR;
6147 V_BSTR(&vbg) = a2bstr("red");
6148 hres = IHTMLTable_put_bgColor(table, vbg);
6149 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6150 VariantClear(&vbg);
6152 hres = IHTMLTable_get_bgColor(table, &vbg);
6153 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6154 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
6155 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6156 VariantClear(&vbg);
6158 V_VT(&vbg) = VT_I4;
6159 V_I4(&vbg) = 0xff0000;
6160 hres = IHTMLTable_put_bgColor(table, vbg);
6161 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6162 VariantClear(&vbg);
6164 hres = IHTMLTable_get_bgColor(table, &vbg);
6165 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6166 ok(V_VT(&vDefaultbg) == VT_BSTR, "V_VT(&vDefaultbg) != VT_BSTR\n");
6167 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6168 VariantClear(&vbg);
6170 /* Restore Originial */
6171 hres = IHTMLTable_put_bgColor(table, vDefaultbg);
6172 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6173 VariantClear(&vDefaultbg);
6175 V_VT(&v) = VT_BSTR;
6176 V_BSTR(&v) = a2bstr("11");
6177 hres = IHTMLTable_put_width(table, v);
6178 ok(hres == S_OK, "put_width = %08x\n", hres);
6179 VariantClear(&v);
6180 IHTMLTable_get_width(table, &v);
6181 ok(hres == S_OK, "get_width = %08x\n", hres);
6182 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6183 VariantClear(&v);
6185 V_VT(&v) = VT_BSTR;
6186 V_BSTR(&v) = a2bstr("11.9");
6187 hres = IHTMLTable_put_width(table, v);
6188 ok(hres == S_OK, "put_width = %08x\n", hres);
6189 VariantClear(&v);
6190 IHTMLTable_get_width(table, &v);
6191 ok(hres == S_OK, "get_width = %08x\n", hres);
6192 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6193 VariantClear(&v);
6195 V_VT(&v) = VT_BSTR;
6196 V_BSTR(&v) = a2bstr("40.2%");
6197 hres = IHTMLTable_put_width(table, v);
6198 ok(hres == S_OK, "put_width = %08x\n", hres);
6199 VariantClear(&v);
6200 IHTMLTable_get_width(table, &v);
6201 ok(hres == S_OK, "get_width = %08x\n", hres);
6202 ok(!strcmp_wa(V_BSTR(&v), "40.2%"), "Expected 40.2%%, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6203 VariantClear(&v);
6205 V_VT(&v) = VT_I4;
6206 V_I4(&v) = 11;
6207 hres = IHTMLTable_put_width(table, v);
6208 ok(hres == S_OK, "put_width = %08x\n", hres);
6209 IHTMLTable_get_width(table, &v);
6210 ok(hres == S_OK, "get_width = %08x\n", hres);
6211 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6212 VariantClear(&v);
6214 V_VT(&v) = VT_R8;
6215 V_R8(&v) = 11.9;
6216 hres = IHTMLTable_put_width(table, v);
6217 ok(hres == S_OK, "put_width = %08x\n", hres);
6218 IHTMLTable_get_width(table, &v);
6219 ok(hres == S_OK, "get_width = %08x\n", hres);
6220 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6221 VariantClear(&v);
6224 bstr = a2bstr("box");
6225 hres = IHTMLTable_put_frame(table, bstr);
6226 ok(hres == S_OK, "put_frame = %08x\n", hres);
6227 SysFreeString(bstr);
6228 hres = IHTMLTable_get_frame(table, &bstr);
6229 ok(hres == S_OK, "get_frame = %08x\n", hres);
6230 ok(!strcmp_wa(bstr, "box"), "Expected box, got %s\n", wine_dbgstr_w(bstr));
6231 SysFreeString(bstr);
6233 test_table_modify(table);
6234 bstr = a2bstr("summary");
6235 hres = IHTMLTable3_put_summary(table3, bstr);
6236 ok(hres == S_OK, "put_summary = %08x\n", hres);
6237 SysFreeString(bstr);
6239 hres = IHTMLTable3_get_summary(table3, &bstr);
6240 ok(hres == S_OK, "get_summary = %08x\n", hres);
6241 ok(!strcmp_wa(bstr, "summary"), "Expected summary, got %s\n", wine_dbgstr_w(bstr));
6242 SysFreeString(bstr);
6244 IHTMLTable3_Release(table3);
6245 IHTMLTable_Release(table);
6248 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
6250 SAFEARRAYBOUND dim;
6251 SAFEARRAY *sa;
6252 VARIANT *var;
6253 HRESULT hres;
6255 dim.lLbound = 0;
6256 dim.cElements = 1;
6257 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
6258 SafeArrayAccessData(sa, (void**)&var);
6259 V_VT(var) = VT_BSTR;
6260 V_BSTR(var) = a2bstr(text);
6261 SafeArrayUnaccessData(sa);
6263 if(ln)
6264 hres = IHTMLDocument2_writeln(doc, sa);
6265 else
6266 hres = IHTMLDocument2_write(doc, sa);
6267 ok(hres == S_OK, "write failed: %08x\n", hres);
6269 SafeArrayDestroy(sa);
6272 static void doc_complex_write(IHTMLDocument2 *doc)
6274 SAFEARRAYBOUND dim = {5, 0};
6275 SAFEARRAY *sa;
6276 VARIANT *args;
6277 HRESULT hres;
6279 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
6280 SafeArrayAccessData(sa, (void**)&args);
6282 V_VT(args) = VT_BSTR;
6283 V_BSTR(args) = a2bstr("<body i4val=\"");
6284 V_VT(args+1) = VT_I4;
6285 V_I4(args+1) = 4;
6286 V_VT(args+2) = VT_BSTR;
6287 V_BSTR(args+2) = a2bstr("\" r8val=\"");
6288 V_VT(args+3) = VT_R8;
6289 V_R8(args+3) = 3.14;
6290 V_VT(args+4) = VT_BSTR;
6291 V_BSTR(args+4) = a2bstr("\">");
6292 SafeArrayUnaccessData(sa);
6294 hres = IHTMLDocument2_write(doc, sa);
6295 ok(hres == S_OK, "write failed: %08x\n", hres);
6297 SafeArrayDestroy(sa);
6300 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
6302 IHTMLDocument2 *window_doc, *elem_doc;
6303 IHTMLFrameElement3 *frame_elem3;
6304 IHTMLWindow2 *content_window;
6305 HRESULT hres;
6307 content_window = get_frame_content_window(frame_elem);
6308 test_ifaces((IUnknown*)content_window, window_iids);
6309 window_doc = get_window_doc(content_window);
6310 IHTMLWindow2_Release(content_window);
6312 elem_doc = get_elem_doc(frame_elem);
6313 ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
6315 if(!iframe) {
6316 hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
6317 if(SUCCEEDED(hres)) {
6318 IDispatch *disp = NULL;
6320 hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
6321 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
6322 ok(disp != NULL, "contentDocument == NULL\n");
6323 ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
6325 IDispatch_Release(disp);
6326 IHTMLFrameElement3_Release(frame_elem3);
6327 }else {
6328 win_skip("IHTMLFrameElement3 not supported\n");
6332 IHTMLDocument2_Release(elem_doc);
6333 IHTMLDocument2_Release(window_doc);
6336 #define test_iframe_height(a,b) _test_iframe_height(__LINE__,a,b)
6337 static void _test_iframe_height(unsigned line, IHTMLElement *elem, const char *exval)
6339 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
6340 VARIANT v;
6341 HRESULT hres;
6343 hres = IHTMLIFrameElement2_get_height(iframe, &v);
6344 ok_(__FILE__,line)(hres == S_OK, "get_height failed: %08x\n", hres);
6345 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(height) = %d\n", V_VT(&v));
6346 if(exval)
6347 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "height = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
6348 else
6349 ok_(__FILE__,line)(!V_BSTR(&v), "height = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6350 VariantClear(&v);
6351 IHTMLIFrameElement2_Release(iframe);
6354 #define set_iframe_height(a,b) _set_iframe_height(__LINE__,a,b)
6355 static void _set_iframe_height(unsigned line, IHTMLElement *elem, const char *val)
6357 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
6358 VARIANT v;
6359 HRESULT hres;
6361 V_VT(&v) = VT_BSTR;
6362 V_BSTR(&v) = a2bstr(val);
6363 hres = IHTMLIFrameElement2_put_height(iframe, v);
6364 ok_(__FILE__,line)(hres == S_OK, "put_height failed: %08x\n", hres);
6365 VariantClear(&v);
6366 IHTMLIFrameElement2_Release(iframe);
6369 #define test_iframe_width(a,b) _test_iframe_width(__LINE__,a,b)
6370 static void _test_iframe_width(unsigned line, IHTMLElement *elem, const char *exval)
6372 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
6373 VARIANT v;
6374 HRESULT hres;
6376 hres = IHTMLIFrameElement2_get_width(iframe, &v);
6377 ok_(__FILE__,line)(hres == S_OK, "get_width failed: %08x\n", hres);
6378 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(width) = %d\n", V_VT(&v));
6379 if(exval)
6380 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "width = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
6381 else
6382 ok_(__FILE__,line)(!V_BSTR(&v), "width = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6383 VariantClear(&v);
6384 IHTMLIFrameElement2_Release(iframe);
6387 #define set_iframe_width(a,b) _set_iframe_width(__LINE__,a,b)
6388 static void _set_iframe_width(unsigned line, IHTMLElement *elem, const char *val)
6390 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
6391 VARIANT v;
6392 HRESULT hres;
6394 V_VT(&v) = VT_BSTR;
6395 V_BSTR(&v) = a2bstr(val);
6396 hres = IHTMLIFrameElement2_put_width(iframe, v);
6397 ok_(__FILE__,line)(hres == S_OK, "put_width failed: %08x\n", hres);
6398 VariantClear(&v);
6399 IHTMLIFrameElement2_Release(iframe);
6402 static void test_iframe_elem(IHTMLElement *elem)
6404 IHTMLDocument2 *content_doc, *owner_doc;
6405 IHTMLIFrameElement3 *iframe3;
6406 IHTMLElementCollection *col;
6407 IHTMLWindow2 *content_window;
6408 IHTMLElement *body;
6409 IDispatch *disp;
6410 VARIANT errv;
6411 BSTR str;
6412 HRESULT hres;
6414 static const elem_type_t all_types[] = {
6415 ET_HTML,
6416 ET_HEAD,
6417 ET_TITLE,
6418 ET_BODY,
6419 ET_BR
6422 test_frame_doc((IUnknown*)elem, TRUE);
6423 test_framebase((IUnknown*)elem);
6425 content_window = get_frame_content_window((IUnknown*)elem);
6426 test_ifaces((IUnknown*)content_window, window_iids);
6427 test_window_length(content_window, 0);
6429 content_doc = get_window_doc(content_window);
6430 IHTMLWindow2_Release(content_window);
6432 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLIFrameElement3, (void**)&iframe3);
6433 if(SUCCEEDED(hres)) {
6434 hres = IHTMLIFrameElement3_get_contentDocument(iframe3, &disp);
6435 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
6436 ok(iface_cmp((IUnknown*)content_doc, (IUnknown*)disp), "content_doc != disp\n");
6437 IDispatch_Release(disp);
6439 IHTMLIFrameElement3_Release(iframe3);
6440 }else {
6441 win_skip("IHTMLIFrameElement3 not supported\n");
6444 test_iframe_height(elem, NULL);
6445 set_iframe_height(elem, "100px");
6446 set_iframe_height(elem, "50%");
6447 test_iframe_height(elem, "50%");
6449 test_iframe_width(elem, NULL);
6450 set_iframe_width(elem, "150px");
6451 set_iframe_width(elem, "70%");
6452 test_iframe_width(elem, "70%");
6454 str = a2bstr("text/html");
6455 V_VT(&errv) = VT_ERROR;
6456 disp = NULL;
6457 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
6458 SysFreeString(str);
6459 ok(hres == S_OK, "open failed: %08x\n", hres);
6460 ok(disp != NULL, "disp == NULL\n");
6461 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
6462 IDispatch_Release(disp);
6464 doc_write(content_doc, FALSE, "<html><head><title>test</title></head>");
6465 doc_complex_write(content_doc);
6466 doc_write(content_doc, TRUE, "<br />");
6467 doc_write(content_doc, TRUE, "</html>");
6469 hres = IHTMLDocument2_get_all(content_doc, &col);
6470 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6471 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6472 IHTMLElementCollection_Release(col);
6474 body = doc_get_body(content_doc);
6475 test_elem_attr(body, "i4val", "4");
6476 test_elem_attr(body, "r8val", "3.14");
6477 IHTMLElement_Release(body);
6479 hres = IHTMLDocument2_close(content_doc);
6480 ok(hres == S_OK, "close failed: %08x\n", hres);
6482 owner_doc = get_owner_doc((IUnknown*)content_doc);
6483 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
6485 IHTMLDocument2_Release(content_doc);
6488 static void test_stylesheet(IDispatch *disp)
6490 IHTMLStyleSheetRulesCollection *col = NULL;
6491 IHTMLStyleSheet *stylesheet;
6492 HRESULT hres;
6493 BSTR href;
6495 test_disp2((IUnknown*)disp, &DIID_DispHTMLStyleSheet, &IID_IHTMLStyleSheet, "[object]");
6497 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
6498 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
6500 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
6501 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
6502 ok(col != NULL, "col == NULL\n");
6504 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetRulesCollection, &IID_IHTMLStyleSheetRulesCollection, "[object]");
6505 IHTMLStyleSheetRulesCollection_Release(col);
6507 href = (void*)0xdeadbeef;
6508 hres = IHTMLStyleSheet_get_href(stylesheet, &href);
6509 ok(hres == S_OK, "get_href failed: %08x\n", hres);
6510 ok(href == NULL, "got href != NULL\n");
6511 SysFreeString(href);
6513 IHTMLStyleSheet_Release(stylesheet);
6516 static void test_stylesheets(IHTMLDocument2 *doc)
6518 IHTMLStyleSheetsCollection *col = NULL;
6519 VARIANT idx, res;
6520 LONG len = 0;
6521 HRESULT hres;
6523 hres = IHTMLDocument2_get_styleSheets(doc, &col);
6524 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
6525 ok(col != NULL, "col == NULL\n");
6527 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
6529 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
6530 ok(hres == S_OK, "get_length failed: %08x\n", hres);
6531 ok(len == 1, "len=%d\n", len);
6533 VariantInit(&res);
6534 V_VT(&idx) = VT_I4;
6535 V_I4(&idx) = 0;
6537 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
6538 ok(hres == S_OK, "item failed: %08x\n", hres);
6539 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
6540 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
6541 test_stylesheet(V_DISPATCH(&res));
6542 VariantClear(&res);
6544 V_VT(&res) = VT_I4;
6545 V_VT(&idx) = VT_I4;
6546 V_I4(&idx) = 1;
6548 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
6549 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
6550 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
6551 VariantClear(&res);
6553 IHTMLStyleSheetsCollection_Release(col);
6556 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
6558 IDispatchEx *dispex;
6559 IHTMLDOMNode *node;
6560 DISPPARAMS dp = {NULL, NULL, 0, 0};
6561 VARIANT var;
6562 EXCEPINFO ei;
6563 LONG type;
6564 DISPID id;
6565 BSTR bstr;
6566 HRESULT hres;
6568 static const WCHAR w0[] = {'0',0};
6569 static const WCHAR w100[] = {'1','0','0',0};
6571 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
6572 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
6574 bstr = SysAllocString(w0);
6575 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
6576 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
6577 SysFreeString(bstr);
6579 VariantInit(&var);
6580 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
6581 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
6582 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
6583 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
6584 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
6585 type = get_node_type((IUnknown*)node);
6586 ok(type == 3, "type=%d\n", type);
6587 IHTMLDOMNode_Release(node);
6588 VariantClear(&var);
6590 bstr = SysAllocString(w100);
6591 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
6592 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
6593 SysFreeString(bstr);
6595 IDispatchEx_Release(dispex);
6598 static void test_enum_children(IUnknown *unk, unsigned len)
6600 IEnumVARIANT *enum_var;
6601 ULONG i, fetched;
6602 VARIANT v;
6603 HRESULT hres;
6605 hres = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&enum_var);
6606 ok(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
6608 for(i=0; i<len; i++) {
6609 fetched = 0;
6610 V_VT(&v) = VT_ERROR;
6611 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
6612 ok(hres == S_OK, "Next failed: %08x\n", hres);
6613 if(i)
6614 ok(fetched == 1, "fetched = %d\n", fetched);
6615 ok(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
6616 IDispatch_Release(V_DISPATCH(&v));
6619 fetched = 0xdeadbeef;
6620 V_VT(&v) = VT_BOOL;
6621 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
6622 ok(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
6623 ok(fetched == 0, "fetched = %d\n", fetched);
6624 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
6626 hres = IEnumVARIANT_Reset(enum_var);
6627 ok(hres == S_OK, "Reset failed: %08x\n", hres);
6629 fetched = 0xdeadbeef;
6630 V_VT(&v) = VT_BOOL;
6631 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
6632 ok(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
6633 ok(fetched == 0, "fetched = %d\n", fetched);
6634 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
6636 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
6637 ok(hres == S_OK, "Skip failed: %08x\n", hres);
6639 hres = IEnumVARIANT_Reset(enum_var);
6640 ok(hres == S_OK, "Reset failed: %08x\n", hres);
6642 hres = IEnumVARIANT_Skip(enum_var, len+1);
6643 ok(hres == S_FALSE, "Skip failed: %08x\n", hres);
6645 IEnumVARIANT_Release(enum_var);
6648 static void test_elems(IHTMLDocument2 *doc)
6650 IHTMLElementCollection *col;
6651 IHTMLDOMChildrenCollection *child_col;
6652 IHTMLElement *elem, *elem2, *elem3;
6653 IHTMLDOMNode *node, *node2;
6654 IHTMLWindow2 *window;
6655 IDispatch *disp;
6656 LONG type;
6657 HRESULT hres;
6658 IHTMLElementCollection *collection;
6659 IHTMLDocument3 *doc3;
6660 BSTR str;
6662 static const elem_type_t all_types[] = {
6663 ET_HTML,
6664 ET_HEAD,
6665 ET_TITLE,
6666 ET_STYLE,
6667 ET_META,
6668 ET_LINK,
6669 ET_BODY,
6670 ET_COMMENT,
6671 ET_A,
6672 ET_LABEL,
6673 ET_INPUT,
6674 ET_BUTTON,
6675 ET_SELECT,
6676 ET_OPTION,
6677 ET_OPTION,
6678 ET_TEXTAREA,
6679 ET_TABLE,
6680 ET_TBODY,
6681 ET_TR,
6682 ET_TR,
6683 ET_TD,
6684 ET_TD,
6685 ET_SCRIPT,
6686 ET_TEST,
6687 ET_OBJECT,
6688 ET_EMBED,
6689 ET_IMG,
6690 ET_IFRAME,
6691 ET_FORM,
6692 ET_DIV
6695 static const elem_type_t item_types[] = {
6696 ET_A,
6697 ET_OPTION,
6698 ET_TEXTAREA
6701 hres = IHTMLDocument2_get_all(doc, &col);
6702 ok(hres == S_OK, "get_all failed: %08x\n", hres);
6703 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
6704 test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
6705 IHTMLElementCollection_Release(col);
6707 hres = IHTMLDocument2_get_images(doc, &collection);
6708 ok(hres == S_OK, "get_images failed: %08x\n", hres);
6709 if(hres == S_OK)
6711 static const elem_type_t images_types[] = {ET_IMG};
6712 test_elem_collection((IUnknown*)collection, images_types, 1);
6714 IHTMLElementCollection_Release(collection);
6717 hres = IHTMLDocument2_get_links(doc, &collection);
6718 ok(hres == S_OK, "get_links failed: %08x\n", hres);
6719 if(hres == S_OK)
6721 static const elem_type_t images_types[] = {ET_A};
6722 test_elem_collection((IUnknown*)collection, images_types, 1);
6724 IHTMLElementCollection_Release(collection);
6727 hres = IHTMLDocument2_get_anchors(doc, &collection);
6728 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
6729 if(hres == S_OK)
6731 static const elem_type_t anchor_types[] = {ET_A};
6732 test_elem_collection((IUnknown*)collection, anchor_types, 1);
6734 IHTMLElementCollection_Release(collection);
6737 hres = IHTMLDocument2_get_scripts(doc, &collection);
6738 ok(hres == S_OK, "get_scripts failed: %08x\n", hres);
6739 if(hres == S_OK) {
6740 static const elem_type_t script_types[] = {ET_SCRIPT};
6741 test_elem_collection((IUnknown*)collection, script_types, 1);
6742 IHTMLElementCollection_Release(collection);
6745 test_plugins_col(doc);
6747 elem = get_doc_elem(doc);
6748 test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
6749 IHTMLElement_Release(elem);
6751 get_elem_by_id(doc, "xxx", FALSE);
6752 elem = get_doc_elem_by_id(doc, "xxx");
6753 ok(!elem, "elem != NULL\n");
6755 elem = get_doc_elem_by_id(doc, "s");
6756 ok(elem != NULL, "elem == NULL\n");
6757 if(elem) {
6758 test_elem_type((IUnknown*)elem, ET_SELECT);
6759 test_elem_attr(elem, "xxx", NULL);
6760 test_elem_attr(elem, "id", "s");
6761 test_elem_class((IUnknown*)elem, NULL);
6762 test_elem_set_class((IUnknown*)elem, "cl");
6763 test_elem_set_class((IUnknown*)elem, NULL);
6764 test_elem_tabindex((IUnknown*)elem, 0);
6765 test_elem_set_tabindex((IUnknown*)elem, 1);
6766 test_elem_filters((IUnknown*)elem);
6768 node = test_node_get_parent((IUnknown*)elem);
6769 ok(node != NULL, "node == NULL\n");
6770 test_node_name((IUnknown*)node, "BODY");
6771 node2 = test_node_get_parent((IUnknown*)node);
6772 IHTMLDOMNode_Release(node);
6773 ok(node2 != NULL, "node == NULL\n");
6774 test_node_name((IUnknown*)node2, "HTML");
6775 node = test_node_get_parent((IUnknown*)node2);
6776 IHTMLDOMNode_Release(node2);
6777 ok(node != NULL, "node == NULL\n");
6778 if (node)
6780 test_node_name((IUnknown*)node, "#document");
6781 type = get_node_type((IUnknown*)node);
6782 ok(type == 9, "type=%d, expected 9\n", type);
6783 node2 = test_node_get_parent((IUnknown*)node);
6784 IHTMLDOMNode_Release(node);
6785 ok(node2 == NULL, "node != NULL\n");
6788 elem2 = test_elem_get_parent((IUnknown*)elem);
6789 ok(elem2 != NULL, "elem2 == NULL\n");
6790 test_node_name((IUnknown*)elem2, "BODY");
6792 elem3 = test_elem_get_parent((IUnknown*)elem2);
6793 ok(elem3 != NULL, "elem3 == NULL\n");
6794 test_node_name((IUnknown*)elem3, "HTML");
6796 test_elem_contains(elem3, elem2, VARIANT_TRUE);
6797 test_elem_contains(elem3, elem, VARIANT_TRUE);
6798 test_elem_contains(elem2, elem, VARIANT_TRUE);
6799 test_elem_contains(elem2, elem3, VARIANT_FALSE);
6800 test_elem_contains(elem, elem3, VARIANT_FALSE);
6801 test_elem_contains(elem, elem2, VARIANT_FALSE);
6802 test_elem_contains(elem, elem, VARIANT_TRUE);
6803 IHTMLElement_Release(elem2);
6805 elem2 = test_elem_get_parent((IUnknown*)elem3);
6806 ok(elem2 == NULL, "elem2 != NULL\n");
6807 IHTMLElement_Release(elem3);
6809 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2, NULL);
6810 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0, NULL);
6811 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0, NULL);
6813 test_elem_innertext(elem, "opt1opt2");
6815 IHTMLElement_Release(elem);
6818 elem = get_elem_by_id(doc, "s", TRUE);
6819 if(elem) {
6820 IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
6821 IHTMLDocument2 *doc_node, *elem_doc;
6823 test_select_elem(select);
6825 test_elem_title((IUnknown*)select, NULL);
6826 test_elem_set_title((IUnknown*)select, "Title");
6827 test_elem_title((IUnknown*)select, "Title");
6828 test_elem_offset((IUnknown*)select, "BODY");
6829 test_elem_bounding_client_rect((IUnknown*)select);
6831 node = get_first_child((IUnknown*)select);
6832 ok(node != NULL, "node == NULL\n");
6833 if(node) {
6834 test_elem_type((IUnknown*)node, ET_OPTION);
6835 IHTMLDOMNode_Release(node);
6838 type = get_node_type((IUnknown*)select);
6839 ok(type == 1, "type=%d\n", type);
6841 IHTMLSelectElement_Release(select);
6843 elem_doc = get_elem_doc((IUnknown*)elem);
6845 doc_node = get_doc_node(doc);
6846 ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
6847 IHTMLDocument2_Release(doc_node);
6848 IHTMLDocument2_Release(elem_doc);
6850 IHTMLElement_Release(elem);
6853 elem = get_elem_by_id(doc, "sc", TRUE);
6854 if(elem) {
6855 IHTMLScriptElement *script;
6856 BSTR type;
6858 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
6859 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
6861 if(hres == S_OK)
6863 VARIANT_BOOL vb;
6865 hres = IHTMLScriptElement_put_type (script, NULL);
6866 ok(hres == S_OK, "put_type failed: %08x\n", hres);
6867 hres = IHTMLScriptElement_get_type(script, &type);
6868 ok(hres == S_OK, "get_type failed: %08x\n", hres);
6869 ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
6871 hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
6872 ok(hres == S_OK, "put_type failed: %08x\n", hres);
6873 hres = IHTMLScriptElement_get_type(script, &type);
6874 ok(hres == S_OK, "get_type failed: %08x\n", hres);
6875 ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
6876 SysFreeString(type);
6878 test_script_text(script, "<!--\nfunction Testing() {}\n// -->\n");
6880 /* test defer */
6881 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
6882 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
6884 hres = IHTMLScriptElement_get_defer(script, &vb);
6885 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
6886 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
6888 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
6889 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
6891 str = (BSTR)0xdeadbeef;
6892 hres = IHTMLScriptElement_get_src(script, &str);
6893 ok(hres == S_OK, "get_src failed: %08x\n", hres);
6894 ok(!str, "src = %s\n", wine_dbgstr_w(str));
6897 IHTMLScriptElement_Release(script);
6900 elem = get_elem_by_id(doc, "in", TRUE);
6901 if(elem) {
6902 IHTMLInputElement *input;
6904 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
6905 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
6907 test_elem_id((IUnknown*)elem, "in");
6908 test_elem_put_id((IUnknown*)elem, "newin");
6909 test_input_get_disabled(input, VARIANT_FALSE);
6910 test_input_set_disabled(input, VARIANT_TRUE);
6911 test_input_set_disabled(input, VARIANT_FALSE);
6912 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
6913 test_input_get_disabled(input, VARIANT_TRUE);
6914 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
6915 test_input_get_disabled(input, VARIANT_FALSE);
6916 test_elem_client_size((IUnknown*)elem);
6917 test_input_type(input, "text");
6919 test_node_get_value_str((IUnknown*)elem, NULL);
6920 test_node_put_value_str((IUnknown*)elem, "test");
6921 test_node_get_value_str((IUnknown*)elem, NULL);
6922 test_input_value((IUnknown*)elem, NULL);
6923 test_input_defaultValue((IUnknown*)elem, NULL);
6924 test_input_put_value((IUnknown*)elem, "test");
6925 test_input_defaultValue((IUnknown*)elem, NULL);
6926 test_elem_class((IUnknown*)elem, "testclass");
6927 test_elem_tabindex((IUnknown*)elem, 2);
6928 test_elem_set_tabindex((IUnknown*)elem, 3);
6929 test_elem_title((IUnknown*)elem, "test title");
6931 test_input_get_defaultchecked(input, VARIANT_FALSE);
6932 test_input_set_defaultchecked(input, VARIANT_TRUE);
6933 test_input_set_defaultchecked(input, VARIANT_FALSE);
6935 test_input_get_checked(input, VARIANT_FALSE);
6936 test_input_set_checked(input, VARIANT_TRUE);
6937 test_input_set_checked(input, VARIANT_FALSE);
6939 test_input_maxlength(input, 0x7fffffff);
6940 test_input_set_maxlength(input, 30);
6942 test_input_name(input, NULL);
6943 test_input_set_name(input, "test");
6945 test_input_src(input, NULL);
6946 test_input_set_src(input, "about:blank");
6948 IHTMLInputElement_Release(input);
6949 IHTMLElement_Release(elem);
6952 elem = get_elem_by_id(doc, "imgid", TRUE);
6953 if(elem) {
6954 test_img_src((IUnknown*)elem, "", NULL);
6955 test_img_set_src((IUnknown*)elem, "about:blank");
6956 test_img_src((IUnknown*)elem, "about:blank", NULL);
6957 test_img_alt((IUnknown*)elem, NULL);
6958 test_img_set_alt((IUnknown*)elem, "alt test");
6959 test_img_name((IUnknown*)elem, "WineImg");
6960 test_img_complete(elem, VARIANT_FALSE);
6961 IHTMLElement_Release(elem);
6964 elem = get_elem_by_id(doc, "attr", TRUE);
6965 if(elem) {
6966 test_dynamic_properties(elem);
6967 test_attr_collection(elem);
6968 test_contenteditable((IUnknown*)elem);
6969 IHTMLElement_Release(elem);
6972 elem = get_elem_by_id(doc, "styleid", TRUE);
6973 if(elem) {
6974 test_style_media((IUnknown*)elem, NULL);
6975 test_style_put_media((IUnknown*)elem, "screen");
6976 test_style_type((IUnknown*)elem, NULL);
6977 test_style_put_type((IUnknown*)elem, "text/css");
6978 IHTMLElement_Release(elem);
6981 elem = get_doc_elem_by_id(doc, "tbl");
6982 ok(elem != NULL, "elem == NULL\n");
6983 if(elem) {
6984 test_table_elem(elem);
6985 IHTMLElement_Release(elem);
6988 elem = get_doc_elem_by_id(doc, "labelid");
6989 ok(elem != NULL, "elem == NULL\n");
6990 if(elem) {
6991 test_label_elem(elem);
6992 IHTMLElement_Release(elem);
6995 elem = get_doc_elem_by_id(doc, "td2");
6996 ok(elem != NULL, "elem == NULL\n");
6997 if(elem) {
6998 test_td_elem(elem);
6999 IHTMLElement_Release(elem);
7002 elem = get_doc_elem_by_id(doc, "row2");
7003 ok(elem != NULL, "elem == NULL\n");
7004 if(elem) {
7005 test_tr_elem(elem);
7006 IHTMLElement_Release(elem);
7009 elem = get_doc_elem_by_id(doc, "ifr");
7010 ok(elem != NULL, "elem == NULL\n");
7011 if(elem) {
7012 test_iframe_elem(elem);
7013 IHTMLElement_Release(elem);
7016 elem = get_doc_elem_by_id(doc, "btnid");
7017 ok(elem != NULL, "elem == NULL\n");
7018 if(elem) {
7019 test_button_elem(elem);
7020 test_button_get_disabled(elem, VARIANT_FALSE);
7021 test_button_set_disabled(elem, VARIANT_TRUE);
7022 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
7023 test_button_get_disabled(elem, VARIANT_FALSE);
7024 IHTMLElement_Release(elem);
7027 elem = get_doc_elem_by_id(doc, "objid");
7028 ok(elem != NULL, "elem == NULL\n");
7029 if(elem) {
7030 test_object_vspace((IUnknown*)elem, 100);
7031 test_object_name(elem, "objname");
7032 set_object_name(elem, "test");
7033 set_object_name(elem, NULL);
7034 IHTMLElement_Release(elem);
7037 elem = get_elem_by_id(doc, "a", TRUE);
7038 if(elem) {
7039 test_anchor_href((IUnknown*)elem, "http://test/");
7041 /* Change the href */
7042 test_anchor_put_href((IUnknown*)elem, "http://test1/");
7043 test_anchor_href((IUnknown*)elem, "http://test1/");
7044 test_anchor_hostname((IUnknown*)elem, "test1");
7046 /* Restore the href */
7047 test_anchor_put_href((IUnknown*)elem, "http://test/");
7048 test_anchor_href((IUnknown*)elem, "http://test/");
7049 test_anchor_hostname((IUnknown*)elem, "test");
7050 test_anchor_hash(elem, NULL);
7052 /* target */
7053 test_anchor_get_target((IUnknown*)elem, NULL);
7055 test_anchor_rel((IUnknown*)elem, NULL);
7056 test_anchor_put_rel((IUnknown*)elem, "Next");
7057 test_anchor_rel((IUnknown*)elem, "Next");
7059 /* Change the target */
7060 test_anchor_put_target((IUnknown*)elem, "wine");
7061 test_anchor_get_target((IUnknown*)elem, "wine");
7063 /* Restore the target */
7064 test_anchor_put_target((IUnknown*)elem, NULL);
7065 test_anchor_get_target((IUnknown*)elem, NULL);
7067 test_anchor_name((IUnknown*)elem, "x");
7068 test_anchor_put_name((IUnknown*)elem, "anchor name");
7069 test_anchor_put_name((IUnknown*)elem, NULL);
7070 test_anchor_put_name((IUnknown*)elem, "x");
7072 test_anchor_put_href((IUnknown*)elem, "http://test/#hash");
7073 test_anchor_hash(elem, "#hash");
7075 IHTMLElement_Release(elem);
7078 elem = get_doc_elem_by_id(doc, "metaid");
7079 if(elem) {
7080 test_meta_name((IUnknown*)elem, "meta name");
7081 test_meta_content((IUnknown*)elem, "text/html; charset=utf-8");
7082 test_meta_httpequiv((IUnknown*)elem, "Content-Type");
7083 test_meta_charset((IUnknown*)elem, NULL);
7084 set_meta_charset((IUnknown*)elem, "utf-8");
7085 IHTMLElement_Release(elem);
7088 elem = doc_get_body(doc);
7090 node = get_first_child((IUnknown*)elem);
7091 ok(node != NULL, "node == NULL\n");
7092 if(node) {
7093 test_ifaces((IUnknown*)node, text_iids);
7094 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
7096 node2 = get_first_child((IUnknown*)node);
7097 ok(!node2, "node2 != NULL\n");
7099 type = get_node_type((IUnknown*)node);
7100 ok(type == 3, "type=%d\n", type);
7102 test_node_get_value_str((IUnknown*)node, "text test");
7103 test_node_put_value_str((IUnknown*)elem, "test text");
7104 test_node_get_value_str((IUnknown*)node, "text test");
7106 hres = IHTMLDOMNode_get_attributes(node, &disp);
7107 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
7108 ok(!disp, "disp != NULL\n");
7110 IHTMLDOMNode_Release(node);
7113 child_col = get_child_nodes((IUnknown*)elem);
7114 ok(child_col != NULL, "child_coll == NULL\n");
7115 if(child_col) {
7116 IUnknown *enum_unk;
7117 LONG length = 0;
7119 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
7121 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
7122 ok(hres == S_OK, "get_length failed: %08x\n", hres);
7123 ok(length, "length=0\n");
7125 node2 = NULL;
7126 node = get_child_item(child_col, 0);
7127 ok(node != NULL, "node == NULL\n");
7128 if(node) {
7129 IHTMLDOMNode *prev;
7131 type = get_node_type((IUnknown*)node);
7132 ok(type == 3, "type=%d\n", type);
7133 node2 = node_get_next((IUnknown*)node);
7135 prev = node_get_prev((IUnknown*)node2);
7136 ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
7137 IHTMLDOMNode_Release(prev);
7139 IHTMLDOMNode_Release(node);
7142 node = get_child_item(child_col, 1);
7143 ok(node != NULL, "node == NULL\n");
7144 if(node) {
7145 type = get_node_type((IUnknown*)node);
7146 ok(type == 8, "type=%d\n", type);
7148 test_elem_id((IUnknown*)node, NULL);
7149 ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
7150 IHTMLDOMNode_Release(node2);
7151 IHTMLDOMNode_Release(node);
7154 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
7155 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
7157 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
7158 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
7160 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
7161 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
7163 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
7164 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
7166 test_child_col_disp(child_col);
7168 hres = IHTMLDOMChildrenCollection_get__newEnum(child_col, &enum_unk);
7169 ok(hres == S_OK, "get__newEnum failed: %08x\n", hres);
7171 test_enum_children(enum_unk, length);
7173 IUnknown_Release(enum_unk);
7175 IHTMLDOMChildrenCollection_Release(child_col);
7178 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
7179 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
7180 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
7182 IHTMLElement_Release(elem);
7184 elem = get_doc_elem_by_id(doc, "frm");
7185 ok(elem != NULL, "elem == NULL\n");
7186 if(elem) {
7187 test_form_length((IUnknown*)elem, 0);
7188 test_form_elements((IUnknown*)elem);
7189 IHTMLElement_Release(elem);
7192 test_stylesheets(doc);
7193 test_create_option_elem(doc);
7194 test_create_img_elem(doc);
7196 elem = get_doc_elem_by_id(doc, "tbl");
7197 ok(elem != NULL, "elem = NULL\n");
7198 test_elem_set_innertext(elem, "inner text");
7199 IHTMLElement_Release(elem);
7201 test_doc_title(doc, "test");
7202 test_doc_set_title(doc, "test title");
7203 test_doc_title(doc, "test title");
7205 disp = NULL;
7206 hres = IHTMLDocument2_get_Script(doc, &disp);
7207 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
7208 if(hres == S_OK)
7210 IDispatchEx *dispex;
7211 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
7212 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
7213 if(hres == S_OK)
7215 DISPID pid = -1;
7216 BSTR str = a2bstr("Testing");
7217 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
7218 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
7219 ok(pid != -1, "pid == -1\n");
7220 SysFreeString(str);
7221 IDispatchEx_Release(dispex);
7224 IDispatch_Release(disp);
7226 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
7227 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
7229 str = a2bstr("Img");
7230 hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
7231 ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
7232 SysFreeString(str);
7233 if(hres == S_OK)
7235 static const elem_type_t img_types[] = { ET_IMG };
7237 test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
7238 IHTMLElementCollection_Release(col);
7241 elem = get_doc_elem_by_id(doc, "y");
7242 test_elem_set_innerhtml((IUnknown*)elem, "inner html");
7243 test_elem_innerhtml((IUnknown*)elem, "inner html");
7244 test_elem_set_innerhtml((IUnknown*)elem, "");
7245 test_elem_innerhtml((IUnknown*)elem, NULL);
7246 node = node_get_next((IUnknown*)elem);
7247 ok(!node, "node = %p\n", node);
7249 elem2 = get_doc_elem_by_id(doc, "x");
7250 test_elem_tag((IUnknown*)elem2, "A");
7251 node = node_get_next((IUnknown*)elem2);
7252 IHTMLDOMNode_Release(node);
7253 IHTMLElement_Release(elem2);
7254 IHTMLElement_Release(elem);
7256 IHTMLDocument3_Release(doc3);
7258 elem = get_elem_by_id(doc, "s", TRUE);
7259 if(elem) {
7260 static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
7262 test_select_put_length((IUnknown*)elem, 3);
7263 test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
7264 test_select_put_length((IUnknown*)elem, 1);
7265 test_elem_all((IUnknown*)elem, select_types, 1);
7266 IHTMLElement_Release(elem);
7269 window = get_doc_window(doc);
7270 test_window_name(window, NULL);
7271 set_window_name(window, "test name");
7272 test_window_length(window, 1);
7273 IHTMLWindow2_Release(window);
7276 static void test_attr(IHTMLElement *elem)
7278 IHTMLDOMAttribute *attr, *attr2;
7279 VARIANT v;
7281 get_elem_attr_node((IUnknown*)elem, "noattr", FALSE);
7283 attr = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
7285 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
7286 test_ifaces((IUnknown*)attr, attr_iids);
7287 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
7288 test_attr_specified(attr, VARIANT_TRUE);
7290 attr2 = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
7291 ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
7292 IHTMLDOMAttribute_Release(attr2);
7294 get_attr_node_value(attr, &v, VT_BSTR);
7295 ok(!strcmp_wa(V_BSTR(&v), "divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
7296 VariantClear(&v);
7298 IHTMLDOMAttribute_Release(attr);
7300 attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
7301 get_attr_node_value(attr, &v, VT_BSTR);
7302 ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
7303 VariantClear(&v);
7304 test_attr_specified(attr, VARIANT_TRUE);
7305 IHTMLDOMAttribute_Release(attr);
7307 V_VT(&v) = VT_I4;
7308 V_I4(&v) = 100;
7309 set_dispex_value((IUnknown*)elem, "dispprop", &v);
7310 attr = get_elem_attr_node((IUnknown*)elem, "dispprop", TRUE);
7311 get_attr_node_value(attr, &v, VT_I4);
7312 ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
7313 test_attr_specified(attr, VARIANT_TRUE);
7314 IHTMLDOMAttribute_Release(attr);
7316 attr = get_elem_attr_node((IUnknown*)elem, "tabIndex", TRUE);
7317 test_attr_specified(attr, VARIANT_FALSE);
7318 IHTMLDOMAttribute_Release(attr);
7321 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
7323 IHTMLElement *elem;
7325 test_elem_set_innerhtml((IUnknown*)outer_elem,
7326 "<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
7327 elem = get_elem_by_id(doc, "imgid", TRUE);
7328 if(elem) {
7329 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
7330 IHTMLElement_Release(elem);
7333 test_elem_set_innerhtml((IUnknown*)outer_elem,
7334 "<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
7335 elem = get_elem_by_id(doc, "imgid", TRUE);
7336 if(elem) {
7337 test_img_src((IUnknown*)elem, "blocke::http://www.winehq.org/img.png", NULL);
7338 test_img_set_src((IUnknown*)elem, "BLOCKED:http://www.winehq.org/img.png");
7339 test_img_src((IUnknown*)elem, "blocked:http://www.winehq.org/img.png", NULL);
7340 test_img_set_src((IUnknown*)elem, "blocked::http://www.winehq.org/img.png");
7341 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
7342 IHTMLElement_Release(elem);
7346 #define doc_get_elems_by_name(a,b) _doc_get_elems_by_name(__LINE__,a,b)
7347 static IHTMLElementCollection *_doc_get_elems_by_name(unsigned line, IHTMLDocument2 *doc, const char *name)
7349 IHTMLDocument3 *doc3 = _get_doc3_iface(line, doc);
7350 IHTMLElementCollection *col;
7351 BSTR str = a2bstr(name);
7352 HRESULT hres;
7354 hres = IHTMLDocument3_getElementsByName(doc3, str, &col);
7355 ok_(__FILE__,line)(hres == S_OK, "getElementsByName failed: %08x\n", hres);
7356 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
7358 IHTMLDocument3_Release(doc3);
7359 SysFreeString(str);
7360 return col;
7363 static void test_elem_names(IHTMLDocument2 *doc)
7365 IHTMLElementCollection *col;
7366 IHTMLElement *body;
7367 LONG len;
7368 HRESULT hres;
7370 static const elem_type_t test1_types[] = {ET_INPUT, ET_A, ET_DIV};
7372 body = doc_get_body(doc);
7374 test_elem_set_innerhtml((IUnknown*)body,
7375 "<input name=\"test\"><a name=\"test\"></a><a name=\"xxx\"></a><div id=\"test\"></div>");
7376 col = doc_get_elems_by_name(doc, "test");
7377 test_elem_collection((IUnknown*)col, test1_types, sizeof(test1_types)/sizeof(*test1_types));
7378 IHTMLElementCollection_Release(col);
7380 col = doc_get_elems_by_name(doc, "yyy");
7381 test_elem_collection((IUnknown*)col, NULL, 0);
7382 IHTMLElementCollection_Release(col);
7384 /* case insensivity test */
7385 col = doc_get_elems_by_name(doc, "Xxx");
7386 hres = IHTMLElementCollection_get_length(col, &len);
7387 ok(hres == S_OK, "get_length failed: %08x\n", hres);
7388 todo_wine ok(len == 1, "len = %d\n", len);
7389 IHTMLElementCollection_Release(col);
7391 IHTMLElement_Release(body);
7394 static void test_elems2(IHTMLDocument2 *doc)
7396 IHTMLElement *elem, *elem2, *div;
7398 static const elem_type_t outer_types[] = {
7399 ET_BR,
7400 ET_A
7403 div = get_doc_elem_by_id(doc, "divid");
7405 elem = get_elem_by_id(doc, "linkid", TRUE);
7406 if(elem) {
7407 test_link_disabled(elem, VARIANT_FALSE);
7408 test_link_rel(elem, "stylesheet");
7409 test_link_type(elem, "text/css");
7410 test_link_href(elem, "about:blank");
7411 test_link_media(elem, "all");
7412 link_put_disabled(elem, VARIANT_TRUE);
7413 link_put_rel(elem, "prev");
7414 link_put_type(elem, "text/plain");
7415 link_put_href(elem, "about:prev");
7416 IHTMLElement_Release(elem);
7419 test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
7420 elem2 = get_doc_elem_by_id(doc, "innerid");
7421 ok(elem2 != NULL, "elem2 == NULL\n");
7422 test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
7423 test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
7424 IHTMLElement_Release(elem2);
7426 elem2 = get_doc_elem_by_id(doc, "aid");
7427 ok(elem2 != NULL, "elem2 == NULL\n");
7428 test_elem_set_outerhtml((IUnknown*)elem2, "");
7429 test_elem_all((IUnknown*)div, outer_types, 1);
7430 IHTMLElement_Release(elem2);
7432 test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
7433 elem = get_elem_by_id(doc, "ta", TRUE);
7434 if(elem) {
7435 test_textarea_value((IUnknown*)elem, NULL);
7436 test_textarea_put_value((IUnknown*)elem, "test");
7437 test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
7438 test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
7439 test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
7440 test_textarea_type((IUnknown*)elem);
7441 IHTMLElement_Release(elem);
7444 test_elem_set_innerhtml((IUnknown*)div,
7445 "<input value=\"val\" id =\"inputid\" />");
7446 elem = get_elem_by_id(doc, "inputid", TRUE);
7447 if(elem) {
7448 test_input_defaultValue((IUnknown*)elem, "val");
7449 test_input_put_value((IUnknown*)elem, "test");
7450 test_input_put_defaultValue((IUnknown*)elem, "new val");
7451 test_input_value((IUnknown*)elem, "test");
7452 IHTMLElement_Release(elem);
7455 test_elem_set_innerhtml((IUnknown*)div, "");
7456 test_insert_adjacent_elems(doc, div);
7458 test_elem_set_innerhtml((IUnknown*)div,
7459 "<form id=\"form\"><input type=\"button\" /><div><input type=\"text\" /></div></textarea>");
7460 elem = get_elem_by_id(doc, "form", TRUE);
7461 if(elem) {
7462 test_form_length((IUnknown*)elem, 2);
7463 test_form_item(elem);
7464 test_form_action((IUnknown*)elem, NULL);
7465 test_form_put_action((IUnknown*)elem, "about:blank");
7466 test_form_method((IUnknown*)elem, "get");
7467 test_form_put_method((IUnknown*)elem, S_OK, "post");
7468 test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
7469 test_form_method((IUnknown*)elem, "post");
7470 test_form_name((IUnknown*)elem, NULL);
7471 test_form_put_name((IUnknown*)elem, "Name");
7472 test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
7473 test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
7474 test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
7475 test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
7476 test_form_encoding((IUnknown*)elem, "multipart/form-data");
7477 test_form_elements((IUnknown*)elem);
7478 test_form_reset((IUnknown*)elem);
7479 test_form_target((IUnknown*)elem);
7480 IHTMLElement_Release(elem);
7483 test_attr(div);
7484 test_blocked(doc, div);
7485 test_elem_names(doc);
7487 IHTMLElement_Release(div);
7490 static void test_create_elems(IHTMLDocument2 *doc)
7492 IHTMLElement *elem, *body, *elem2;
7493 IHTMLDOMNode *node, *node2, *node3, *comment;
7494 IHTMLDOMAttribute *attr;
7495 IHTMLDocument5 *doc5;
7496 IDispatch *disp;
7497 VARIANT var;
7498 LONG type;
7499 HRESULT hres;
7500 BSTR str;
7502 static const elem_type_t types1[] = { ET_TESTG };
7504 elem = test_create_elem(doc, "TEST");
7505 test_elem_tag((IUnknown*)elem, "TEST");
7506 type = get_node_type((IUnknown*)elem);
7507 ok(type == 1, "type=%d\n", type);
7508 test_ifaces((IUnknown*)elem, elem_iids);
7509 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
7511 body = doc_get_body(doc);
7512 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
7514 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
7515 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
7516 elem2 = get_elem_iface((IUnknown*)node);
7517 IHTMLElement_Release(elem2);
7519 hres = IHTMLElement_get_all(body, &disp);
7520 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7521 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
7522 IDispatch_Release(disp);
7524 test_node_remove_child((IUnknown*)body, node);
7526 hres = IHTMLElement_get_all(body, &disp);
7527 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7528 test_elem_collection((IUnknown*)disp, NULL, 0);
7529 IDispatch_Release(disp);
7530 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
7532 IHTMLElement_Release(elem);
7533 IHTMLDOMNode_Release(node);
7535 node = test_create_text(doc, "abc");
7536 test_ifaces((IUnknown*)node, text_iids);
7537 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
7538 test_text_length((IUnknown*)node, 3);
7539 test_text_data((IUnknown*)node, "abc");
7540 set_text_data((IUnknown*)node, "test");
7541 test_text_data((IUnknown*)node, "test");
7543 V_VT(&var) = VT_NULL;
7544 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
7545 IHTMLDOMNode_Release(node);
7547 node = test_create_text(doc, "insert ");
7549 V_VT(&var) = VT_DISPATCH;
7550 V_DISPATCH(&var) = (IDispatch*)node2;
7551 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
7552 IHTMLDOMNode_Release(node);
7553 IHTMLDOMNode_Release(node2);
7554 IHTMLDOMNode_Release(node3);
7556 test_elem_innertext(body, "insert test");
7557 test_elem_innerhtml((IUnknown*)body, "insert test");
7559 node = test_create_text(doc, " Test");
7560 V_VT(&var) = VT_DISPATCH;
7561 V_DISPATCH(&var) = NULL;
7562 test_node_insertbefore((IUnknown*)body, node, &var);
7563 test_elem_innertext(body, "insert test Test");
7564 IHTMLDOMNode_Release(node);
7566 doc5 = get_htmldoc5_iface((IUnknown*)doc);
7567 if(doc5) {
7568 str = a2bstr("testing");
7569 hres = IHTMLDocument5_createComment(doc5, str, &comment);
7570 SysFreeString(str);
7571 ok(hres == S_OK, "createComment failed: %08x\n", hres);
7572 if(hres == S_OK)
7574 type = get_node_type((IUnknown*)comment);
7575 ok(type == 8, "type=%d, expected 8\n", type);
7577 test_node_get_value_str((IUnknown*)comment, "testing");
7578 test_elem_title((IUnknown*)comment, NULL);
7579 test_elem_set_title((IUnknown*)comment, "comment title");
7580 test_elem_title((IUnknown*)comment, "comment title");
7581 test_comment_text((IUnknown*)comment, "<!--testing-->");
7582 test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
7583 test_comment_attrs((IUnknown*)comment);
7585 IHTMLDOMNode_Release(comment);
7588 str = a2bstr("Test");
7589 hres = IHTMLDocument5_createAttribute(doc5, str, &attr);
7590 ok(hres == S_OK, "createAttribute dailed: %08x\n", hres);
7591 SysFreeString(str);
7592 if(SUCCEEDED(hres)) {
7593 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
7594 test_ifaces((IUnknown*)attr, attr_iids);
7595 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
7597 test_attr_node_name(attr, "Test");
7599 IHTMLDOMAttribute_Release(attr);
7602 IHTMLDocument5_Release(doc5);
7605 IHTMLElement_Release(body);
7608 static void test_replacechild_elems(IHTMLDocument2 *doc)
7610 IHTMLElement *body;
7611 IHTMLDOMNode *node, *node2, *node3;
7612 IHTMLDOMNode *nodeBody, *nodeNew;
7613 HRESULT hres;
7614 VARIANT var;
7616 body = doc_get_body(doc);
7618 node = test_create_text(doc, "insert");
7620 V_VT(&var) = VT_NULL;
7621 V_DISPATCH(&var) = NULL;
7622 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
7623 IHTMLDOMNode_Release(node);
7625 test_elem_innertext(body, "insert");
7627 node3 = test_create_text(doc, "replaced");
7629 nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
7631 hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
7632 ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
7634 test_elem_innertext(body, "replaced");
7636 IHTMLDOMNode_Release(node2);
7637 IHTMLDOMNode_Release(node3);
7638 IHTMLDOMNode_Release(nodeBody);
7640 IHTMLElement_Release(body);
7643 static void test_noscript(IHTMLDocument2 *doc)
7645 IHTMLElementCollection *col;
7646 IHTMLElement *body;
7647 HRESULT hres;
7649 static const elem_type_t all_types[] = {
7650 ET_HTML,
7651 ET_HEAD,
7652 ET_TITLE,
7653 ET_NOSCRIPT,
7654 ET_BODY,
7655 ET_NOSCRIPT
7658 static const elem_type_t body_all_types[] = {
7659 ET_DIV,
7660 ET_NOSCRIPT
7663 hres = IHTMLDocument2_get_all(doc, &col);
7664 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7665 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7666 IHTMLElementCollection_Release(col);
7668 body = doc_get_body(doc);
7669 test_elem_set_innerhtml((IUnknown*)body, "<div>test</div><noscript><a href=\"about:blank\">A</a></noscript>");
7670 test_elem_all((IUnknown*)body, body_all_types, sizeof(body_all_types)/sizeof(*body_all_types));
7671 IHTMLElement_Release(body);
7674 static void test_doctype(IHTMLDocument2 *doc)
7676 IHTMLDocument2 *doc_node;
7677 IHTMLDOMNode *doctype;
7678 int type;
7680 doc_node = get_doc_node(doc);
7681 doctype = get_first_child((IUnknown*)doc_node);
7682 IHTMLDocument2_Release(doc_node);
7684 type = get_node_type((IUnknown*)doctype);
7685 ok(type == 8, "type = %d\n", type);
7687 test_comment_text((IUnknown*)doctype, "<!DOCTYPE html>");
7688 test_elem_type((IUnknown*)doctype, ET_COMMENT);
7689 IHTMLDOMNode_Release(doctype);
7692 static void test_null_write(IHTMLDocument2 *doc)
7694 HRESULT hres;
7696 doc_write(doc, FALSE, NULL);
7697 doc_write(doc, TRUE, NULL);
7699 hres = IHTMLDocument2_write(doc, NULL);
7700 ok(hres == S_OK,
7701 "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
7703 hres = IHTMLDocument2_writeln(doc, NULL);
7704 ok(hres == S_OK,
7705 "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
7708 static void test_create_stylesheet(IHTMLDocument2 *doc)
7710 IHTMLStyleSheet *stylesheet, *stylesheet2;
7711 IHTMLStyleElement *style_elem;
7712 IHTMLElement *doc_elem, *elem;
7713 HRESULT hres;
7715 static const elem_type_t all_types[] = {
7716 ET_HTML,
7717 ET_HEAD,
7718 ET_TITLE,
7719 ET_BODY,
7720 ET_DIV
7723 static const elem_type_t all_types2[] = {
7724 ET_HTML,
7725 ET_HEAD,
7726 ET_TITLE,
7727 ET_STYLE,
7728 ET_BODY,
7729 ET_DIV
7732 test_doc_all(doc, all_types, sizeof(all_types)/sizeof(*all_types));
7734 hres = IHTMLDocument2_createStyleSheet(doc, NULL, -1, &stylesheet);
7735 ok(hres == S_OK, "createStyleSheet failed: %08x\n", hres);
7737 test_doc_all(doc, all_types2, sizeof(all_types2)/sizeof(*all_types2));
7739 doc_elem = get_doc_elem(doc);
7741 test_elem_getelembytag((IUnknown*)doc_elem, ET_STYLE, 1, &elem);
7742 IHTMLElement_Release(doc_elem);
7744 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLStyleElement, (void**)&style_elem);
7745 IHTMLElement_Release(elem);
7746 ok(hres == S_OK, "Could not get IHTMLStyleElement iface: %08x\n", hres);
7748 stylesheet2 = NULL;
7749 hres = IHTMLStyleElement_get_styleSheet(style_elem, &stylesheet2);
7750 ok(hres == S_OK, "get_styleSheet failed: %08x\n", hres);
7751 ok(stylesheet2 != NULL, "stylesheet2 == NULL\n");
7752 ok(iface_cmp((IUnknown*)stylesheet, (IUnknown*)stylesheet2), "stylesheet != stylesheet2\n");
7754 IHTMLStyleSheet_Release(stylesheet2);
7755 IHTMLStyleSheet_Release(stylesheet);
7757 IHTMLStyleElement_Release(style_elem);
7760 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
7762 IOleCommandTarget *cmdtrg;
7763 HRESULT hres;
7765 hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
7766 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
7768 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
7769 ok(hres == S_OK, "Exec failed: %08x\n", hres);
7771 IOleCommandTarget_Release(cmdtrg);
7774 static void test_indent(IHTMLDocument2 *doc)
7776 IHTMLElementCollection *col;
7777 IHTMLTxtRange *range;
7778 HRESULT hres;
7780 static const elem_type_t all_types[] = {
7781 ET_HTML,
7782 ET_HEAD,
7783 ET_TITLE,
7784 ET_BODY,
7785 ET_BR,
7786 ET_A,
7789 static const elem_type_t indent_types[] = {
7790 ET_HTML,
7791 ET_HEAD,
7792 ET_TITLE,
7793 ET_BODY,
7794 ET_BLOCKQUOTE,
7795 ET_P,
7796 ET_BR,
7797 ET_A,
7800 hres = IHTMLDocument2_get_all(doc, &col);
7801 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7802 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7803 IHTMLElementCollection_Release(col);
7805 range = test_create_body_range(doc);
7806 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
7807 IHTMLTxtRange_Release(range);
7809 hres = IHTMLDocument2_get_all(doc, &col);
7810 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7811 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
7812 IHTMLElementCollection_Release(col);
7815 static void test_cond_comment(IHTMLDocument2 *doc)
7817 IHTMLElementCollection *col;
7818 HRESULT hres;
7820 static const elem_type_t all_types[] = {
7821 ET_HTML,
7822 ET_HEAD,
7823 ET_TITLE,
7824 ET_BODY,
7825 ET_BR
7828 hres = IHTMLDocument2_get_all(doc, &col);
7829 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7830 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7831 IHTMLElementCollection_Release(col);
7834 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
7836 ok(IsEqualGUID(riid, &IID_IServiceProvider), "riid = %s\n", wine_dbgstr_guid(riid));
7837 return E_NOINTERFACE;
7840 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
7842 return 2;
7845 static ULONG WINAPI Unknown_Release(IUnknown *iface)
7847 return 1;
7850 static const IUnknownVtbl UnknownVtbl = {
7851 Unknown_QueryInterface,
7852 Unknown_AddRef,
7853 Unknown_Release,
7855 static IUnknown obj_ident_test = { &UnknownVtbl };
7857 static void test_frame(IDispatch *disp, const char *exp_id)
7859 IHTMLWindow2 *frame2, *parent, *top;
7860 IHTMLDocument2 *parent_doc, *top_doc;
7861 IHTMLWindow4 *frame;
7862 IHTMLFrameBase *frame_elem;
7863 IObjectIdentity *obj_ident;
7864 ITravelLogClient *tlc;
7865 HRESULT hres;
7867 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
7868 ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
7869 if(FAILED(hres))
7870 return;
7872 hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
7873 ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
7874 IHTMLWindow4_Release(frame);
7875 if(FAILED(hres))
7876 return;
7878 test_elem_type((IUnknown*)frame_elem, ET_FRAME);
7879 test_frame_doc((IUnknown*)frame_elem, FALSE);
7880 test_elem_id((IUnknown*)frame_elem, exp_id);
7881 IHTMLFrameBase_Release(frame_elem);
7883 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
7884 ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
7885 if(FAILED(hres))
7886 return;
7888 hres = IHTMLWindow2_get_parent(frame2, &parent);
7889 ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
7890 if(FAILED(hres)){
7891 IHTMLWindow2_Release(frame2);
7892 return;
7895 hres = IHTMLWindow2_QueryInterface(frame2, &IID_IObjectIdentity, (void**)&obj_ident);
7896 ok(hres == S_OK, "Could not get IObjectIdentity interface: %08x\n", hres);
7897 hres = IHTMLWindow2_QueryInterface(frame2, &IID_ITravelLogClient, (void**)&tlc);
7898 if(hres == E_NOINTERFACE) {
7899 win_skip("IID_ITravelLogClient not available\n");
7900 tlc = NULL;
7901 }else {
7902 ok(hres == S_OK, "Could not get ITravelLogClient interface: %08x\n", hres);
7904 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)tlc);
7905 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
7906 ITravelLogClient_Release(tlc);
7909 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)obj_ident);
7910 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
7911 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)parent);
7912 ok(hres == S_FALSE, "IsEqualObject returned: 0x%08x\n", hres);
7913 hres = IObjectIdentity_IsEqualObject(obj_ident, &obj_ident_test);
7914 ok(hres == E_NOINTERFACE, "IsEqualObject returned: 0x%08x\n", hres);
7916 IObjectIdentity_Release(obj_ident);
7918 hres = IHTMLWindow2_get_document(parent, &parent_doc);
7919 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
7920 IHTMLWindow2_Release(parent);
7921 if(FAILED(hres)){
7922 IHTMLWindow2_Release(frame2);
7923 return;
7926 test_doc_title(parent_doc, "frameset test");
7927 IHTMLDocument2_Release(parent_doc);
7929 /* test get_top */
7930 hres = IHTMLWindow2_get_top(frame2, &top);
7931 ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
7932 IHTMLWindow2_Release(frame2);
7933 if(FAILED(hres))
7934 return;
7936 hres = IHTMLWindow2_get_document(top, &top_doc);
7937 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
7938 IHTMLWindow2_Release(top);
7939 if(FAILED(hres))
7940 return;
7942 test_doc_title(top_doc, "frameset test");
7943 IHTMLDocument2_Release(top_doc);
7946 static void test_frames_collection(IHTMLFramesCollection2 *frames, const char *frid)
7948 VARIANT index_var, result_var;
7949 LONG length;
7950 HRESULT hres;
7952 /* test result length */
7953 hres = IHTMLFramesCollection2_get_length(frames, &length);
7954 ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
7955 ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
7957 /* test first frame */
7958 V_VT(&index_var) = VT_I4;
7959 V_I4(&index_var) = 0;
7960 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
7961 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
7962 if(SUCCEEDED(hres)) {
7963 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
7964 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
7966 VariantClear(&result_var);
7968 /* test second frame */
7969 V_I4(&index_var) = 1;
7970 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
7971 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
7972 if(SUCCEEDED(hres)) {
7973 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
7974 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
7976 VariantClear(&result_var);
7978 /* fail on next frame */
7979 V_I4(&index_var) = 3;
7980 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
7981 ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
7982 "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
7983 VariantClear(&result_var);
7985 /* string argument (element id lookup) */
7986 V_VT(&index_var) = VT_BSTR;
7987 V_BSTR(&index_var) = a2bstr(frid);
7988 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
7989 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
7990 if(SUCCEEDED(hres)) {
7991 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
7992 test_frame(V_DISPATCH(&result_var), frid);
7994 VariantClear(&result_var);
7995 VariantClear(&index_var);
7997 /* invalid argument */
7998 V_VT(&index_var) = VT_BOOL;
7999 V_BOOL(&index_var) = VARIANT_TRUE;
8000 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8001 ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
8002 "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
8003 VariantClear(&result_var);
8006 static void test_frameset(IHTMLDocument2 *doc)
8008 IHTMLWindow2 *window;
8009 IHTMLFramesCollection2 *frames;
8010 IHTMLElement *elem;
8011 HRESULT hres;
8013 window = get_doc_window(doc);
8015 /* test using IHTMLFramesCollection object */
8017 hres = IHTMLWindow2_get_frames(window, &frames);
8018 ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
8019 if(FAILED(hres))
8020 return;
8022 test_frames_collection(frames, "fr1");
8023 IHTMLFramesCollection2_Release(frames);
8025 hres = IHTMLDocument2_get_frames(doc, &frames);
8026 ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
8027 if(FAILED(hres))
8028 return;
8030 test_frames_collection(frames, "fr1");
8031 IHTMLFramesCollection2_Release(frames);
8033 /* test using IHTMLWindow2 inheritance */
8034 test_frames_collection((IHTMLFramesCollection2*)window, "fr2");
8036 /* getElementById with node name attributes */
8037 elem = get_doc_elem_by_id(doc, "nm1");
8038 test_elem_id((IUnknown*)elem, "fr1");
8040 test_framebase((IUnknown*)elem);
8041 test_framebase_name(elem, "nm1");
8042 test_framebase_put_name(elem, "frame name");
8043 test_framebase_put_name(elem, NULL);
8044 test_framebase_put_name(elem, "nm1");
8045 IHTMLElement_Release(elem);
8047 /* get_name with no name attr */
8048 elem = get_doc_elem_by_id(doc, "fr3");
8049 test_framebase_name(elem, NULL);
8050 test_framebase_put_name(elem, "frame name");
8051 test_framebase_put_name(elem, NULL);
8052 IHTMLElement_Release(elem);
8054 IHTMLWindow2_Release(window);
8057 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
8059 IHTMLDocument2 *frag;
8060 IHTMLDocument3 *doc3;
8061 HRESULT hres;
8063 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
8064 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
8066 hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
8067 IHTMLDocument3_Release(doc3);
8068 ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
8069 ok(frag != NULL, "frag == NULL\n");
8071 return frag;
8074 static void test_docfrag(IHTMLDocument2 *doc)
8076 IHTMLDocument2 *frag, *owner_doc, *doc_node;
8077 IHTMLElement *div, *body, *br;
8078 IHTMLElementCollection *col;
8079 IHTMLLocation *location;
8080 HRESULT hres;
8082 static const elem_type_t all_types[] = {
8083 ET_HTML,
8084 ET_HEAD,
8085 ET_TITLE,
8086 ET_BODY,
8087 ET_DIV,
8088 ET_BR
8091 frag = create_docfrag(doc);
8093 test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
8095 body = (void*)0xdeadbeef;
8096 hres = IHTMLDocument2_get_body(frag, &body);
8097 ok(hres == S_OK, "get_body failed: %08x\n", hres);
8098 ok(!body, "body != NULL\n");
8100 location = (void*)0xdeadbeef;
8101 hres = IHTMLDocument2_get_location(frag, &location);
8102 ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
8103 ok(location == (void*)0xdeadbeef, "location changed\n");
8105 br = test_create_elem(doc, "BR");
8106 test_node_append_child((IUnknown*)frag, (IUnknown*)br);
8107 IHTMLElement_Release(br);
8109 div = get_elem_by_id(doc, "divid", TRUE);
8110 test_node_append_child((IUnknown*)div, (IUnknown*)frag);
8111 IHTMLElement_Release(div);
8113 hres = IHTMLDocument2_get_all(doc, &col);
8114 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8115 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
8116 IHTMLElementCollection_Release(col);
8118 div = test_create_elem(frag, "div");
8119 owner_doc = get_owner_doc((IUnknown*)div);
8120 doc_node = get_doc_node(doc);
8121 ok(iface_cmp((IUnknown*)owner_doc, (IUnknown*)doc_node), "owner_doc != doc_node\n");
8122 IHTMLDocument2_Release(doc_node);
8123 IHTMLDocument2_Release(owner_doc);
8124 IHTMLElement_Release(div);
8126 IHTMLDocument2_Release(frag);
8129 static void check_quirks_mode(IHTMLDocument2 *doc)
8131 test_compatmode(doc, "BackCompat");
8134 static void check_strict_mode(IHTMLDocument2 *doc)
8136 test_compatmode(doc, "CSS1Compat");
8139 static IHTMLDocument2 *notif_doc;
8140 static BOOL doc_complete;
8142 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
8143 REFIID riid, void**ppv)
8145 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
8146 *ppv = iface;
8147 return S_OK;
8150 ok(0, "unexpected call\n");
8151 return E_NOINTERFACE;
8154 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
8156 return 2;
8159 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
8161 return 1;
8164 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
8166 if(dispID == DISPID_READYSTATE){
8167 BSTR state;
8168 HRESULT hres;
8170 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
8171 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
8173 if(!strcmp_wa(state, "complete"))
8174 doc_complete = TRUE;
8176 SysFreeString(state);
8179 return S_OK;
8182 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
8184 ok(0, "unexpected call\n");
8185 return E_NOTIMPL;
8188 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
8189 PropertyNotifySink_QueryInterface,
8190 PropertyNotifySink_AddRef,
8191 PropertyNotifySink_Release,
8192 PropertyNotifySink_OnChanged,
8193 PropertyNotifySink_OnRequestEdit
8196 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
8198 static IHTMLDocument2 *create_doc_with_string(const char *str)
8200 IPersistStreamInit *init;
8201 IStream *stream;
8202 IHTMLDocument2 *doc;
8203 HGLOBAL mem;
8204 SIZE_T len;
8206 notif_doc = doc = create_document();
8207 if(!doc)
8208 return NULL;
8210 doc_complete = FALSE;
8211 len = strlen(str);
8212 mem = GlobalAlloc(0, len);
8213 memcpy(mem, str, len);
8214 CreateStreamOnHGlobal(mem, TRUE, &stream);
8216 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
8218 IPersistStreamInit_Load(init, stream);
8219 IPersistStreamInit_Release(init);
8220 IStream_Release(stream);
8222 return doc;
8225 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
8227 IConnectionPointContainer *container;
8228 IConnectionPoint *cp;
8229 DWORD cookie;
8230 HRESULT hres;
8232 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
8233 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
8235 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
8236 IConnectionPointContainer_Release(container);
8237 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
8239 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
8240 IConnectionPoint_Release(cp);
8241 ok(hres == S_OK, "Advise failed: %08x\n", hres);
8244 typedef void (*domtest_t)(IHTMLDocument2*);
8246 static void run_domtest(const char *str, domtest_t test)
8248 IHTMLDocument2 *doc;
8249 ULONG ref;
8250 MSG msg;
8252 doc = create_doc_with_string(str);
8253 if(!doc)
8254 return;
8256 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
8258 while(!doc_complete && GetMessageW(&msg, NULL, 0, 0)) {
8259 TranslateMessage(&msg);
8260 DispatchMessageW(&msg);
8263 test(doc);
8265 ref = IHTMLDocument2_Release(doc);
8266 ok(!ref || broken(ref == 1), /* Vista */
8267 "ref = %d\n", ref);
8270 static void test_quirks_mode(void)
8272 run_domtest("<html></html>", check_quirks_mode);
8273 run_domtest("<!DOCTYPE html>\n<html></html>", check_strict_mode);
8274 run_domtest("<!-- comment --><!DOCTYPE html>\n<html></html>", check_quirks_mode);
8277 START_TEST(dom)
8279 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
8280 pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
8281 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
8283 CoInitialize(NULL);
8285 run_domtest(doc_str1, test_doc_elem);
8286 run_domtest(doc_str1, test_get_set_attr);
8287 run_domtest(range_test_str, test_txtrange);
8288 run_domtest(range_test2_str, test_txtrange2);
8289 if (winetest_interactive || ! is_ie_hardened()) {
8290 run_domtest(elem_test_str, test_elems);
8291 run_domtest(elem_test2_str, test_elems2);
8292 run_domtest(noscript_str, test_noscript);
8293 }else {
8294 skip("IE running in Enhanced Security Configuration\n");
8296 run_domtest(doc_blank, test_create_elems);
8297 run_domtest(doc_blank, test_defaults);
8298 run_domtest(doc_blank, test_null_write);
8299 run_domtest(emptydiv_str, test_create_stylesheet);
8300 run_domtest(indent_test_str, test_indent);
8301 run_domtest(cond_comment_str, test_cond_comment);
8302 run_domtest(frameset_str, test_frameset);
8303 run_domtest(emptydiv_str, test_docfrag);
8304 run_domtest(doc_blank, test_replacechild_elems);
8305 run_domtest(doctype_str, test_doctype);
8307 test_quirks_mode();
8309 CoUninitialize();