mshtml: Fix NULL offset parent handling in IHTMLElement::get_offsetParent.
[wine/zf.git] / dlls / mshtml / tests / dom.c
blob1253e9cdea8a4dbdfad55aec94d8f3f32dd70b92
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 <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28 #include "mshtml.h"
29 #include "mshtmcid.h"
30 #include "mshtmhst.h"
31 #include "docobj.h"
32 #include "hlink.h"
33 #include "dispex.h"
34 #include "wine/test.h"
35 #include "mshtml_test.h"
36 #include "objsafe.h"
37 #include "htiface.h"
38 #include "tlogstg.h"
39 #include "mscoree.h"
41 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
42 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
44 static BOOL is_ie9plus;
46 static enum {
47 COMPAT_NONE,
48 COMPAT_IE9
49 } compat_mode = COMPAT_NONE;
51 static const char doc_blank[] =
52 "<html></html>";
54 static const char doc_blank_ie9[] =
55 "<!DOCTYPE html>\n"
56 "<html>"
57 " <head>"
58 " <meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" />"
59 " </head>"
60 " <body>"
61 " </body>"
62 "</html>";
64 static const char doc_str1[] = "<html><body>test</body></html>";
65 static const char elem_test_str[] =
66 "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
67 "<meta id=\"metaid\" name=\"meta name\" http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
68 "<link id=\"linkid\"></head>"
69 "<body onload=\"Testing()\">text test<!-- a comment -->"
70 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
71 "<label for=\"in\" id=\"labelid\">Label:</label>"
72 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
73 "<button id=\"btnid\" type=\"submit\"></button>"
74 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
75 "<textarea id=\"X\">text text</textarea>"
76 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td id=\"td1\">td1 text</td><td id=\"td2\">td2 text</td></tr></tbody></table>"
77 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
78 "<test /><object id=\"objid\" name=\"objname\" vspace=100></object><embed />"
79 "<img id=\"imgid\" name=\"WineImg\"/>"
80 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
81 "<form id=\"frm\"></form>"
82 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
83 "</body></html>";
84 static const char elem_test2_str[] =
85 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
86 "<link id=\"linkid\" rel=\"stylesheet\" href=\"about:blank\" type=\"text/css\"></head>"
87 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
88 "</html>";
90 static const char indent_test_str[] =
91 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
92 static const char cond_comment_str[] =
93 "<html><head><title>test</title></head><body>"
94 "<!--[if gte IE 4]> <br> <![endif]-->"
95 "</body></html>";
96 static const char frameset_str[] =
97 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
98 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
99 "<frame src=\"about:blank\" id=\"fr3\">"
100 "</frameset></html>";
101 static const char emptydiv_str[] =
102 "<html><head><title>emptydiv test</title></head>"
103 "<body><div id=\"divid\"></div></body></html>";
104 static const char noscript_str[] =
105 "<html><head><title>noscript test</title><noscript><style>.body { margin-right: 0px; }</style></noscript></head>"
106 "<body><noscript><div>test</div></noscript></body></html>";
107 static const char doctype_str[] =
108 "<!DOCTYPE html>"
109 "<html><head><title>emptydiv test</title></head>"
110 "<body><div id=\"divid\"></div></body></html>";
112 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
113 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
114 static WCHAR wordW[] = {'w','o','r','d',0};
116 typedef enum {
117 ET_NONE,
118 ET_HTML,
119 ET_HEAD,
120 ET_TITLE,
121 ET_BODY,
122 ET_A,
123 ET_INPUT,
124 ET_SELECT,
125 ET_TEXTAREA,
126 ET_OPTION,
127 ET_STYLE,
128 ET_BLOCKQUOTE,
129 ET_P,
130 ET_BR,
131 ET_TABLE,
132 ET_TBODY,
133 ET_SCRIPT,
134 ET_TEST,
135 ET_TESTG,
136 ET_COMMENT,
137 ET_IMG,
138 ET_TR,
139 ET_TD,
140 ET_IFRAME,
141 ET_FORM,
142 ET_FRAME,
143 ET_OBJECT,
144 ET_EMBED,
145 ET_DIV,
146 ET_META,
147 ET_NOSCRIPT,
148 ET_LINK,
149 ET_LABEL,
150 ET_BUTTON,
151 ET_AREA,
152 ET_SVG,
153 ET_CIRCLE,
154 ET_TSPAN
155 } elem_type_t;
157 static const IID * const none_iids[] = {
158 &IID_IUnknown,
159 NULL
162 static const IID * const doc_node_iids[] = {
163 &IID_IHTMLDOMNode,
164 &IID_IHTMLDOMNode2,
165 &IID_IHTMLDocument,
166 &IID_IHTMLDocument2,
167 &IID_IHTMLDocument3,
168 &IID_IHTMLDocument4,
169 &IID_IHTMLDocument5,
170 &IID_IDocumentRange,
171 &IID_IDocumentSelector,
172 &IID_IDispatchEx,
173 &IID_IDisplayServices,
174 &IID_IConnectionPointContainer,
175 &IID_IInternetHostSecurityManager,
176 &IID_IMarkupContainer,
177 &IID_IMarkupServices,
178 &IID_IOleContainer,
179 &IID_IObjectSafety,
180 &IID_IProvideClassInfo,
181 NULL
184 static const IID * const doc_obj_iids[] = {
185 &IID_IHTMLDocument,
186 &IID_IHTMLDocument2,
187 &IID_IHTMLDocument3,
188 &IID_IHTMLDocument4,
189 &IID_IHTMLDocument5,
190 &IID_IDocumentRange,
191 &IID_IDocumentSelector,
192 &IID_IDispatchEx,
193 &IID_IDisplayServices,
194 &IID_IConnectionPointContainer,
195 &IID_ICustomDoc,
196 &IID_IMarkupContainer,
197 &IID_IMarkupServices,
198 &IID_IOleContainer,
199 &IID_IObjectSafety,
200 &IID_IProvideClassInfo,
201 &IID_ITargetContainer,
202 NULL
205 #define ELEM_IFACES \
206 &IID_IHTMLDOMNode, \
207 &IID_IHTMLDOMNode2, \
208 &IID_IHTMLElement, \
209 &IID_IHTMLElement2, \
210 &IID_IHTMLElement3, \
211 &IID_IHTMLElement4, \
212 &IID_IHTMLUniqueName, \
213 &IID_IDispatchEx
215 static const IID * const elem_iids[] = {
216 ELEM_IFACES,
217 &IID_IConnectionPointContainer,
218 NULL
221 static const IID * const body_iids[] = {
222 ELEM_IFACES,
223 &IID_IHTMLTextContainer,
224 &IID_IHTMLBodyElement,
225 &IID_IConnectionPointContainer,
226 NULL
229 static const IID * const anchor_iids[] = {
230 ELEM_IFACES,
231 &IID_IHTMLAnchorElement,
232 &IID_IConnectionPointContainer,
233 NULL
236 static const IID * const input_iids[] = {
237 ELEM_IFACES,
238 &IID_IHTMLInputElement,
239 &IID_IHTMLInputTextElement,
240 &IID_IConnectionPointContainer,
241 NULL
244 static const IID *const button_iids[] = {
245 ELEM_IFACES,
246 &IID_IHTMLButtonElement,
247 &IID_IConnectionPointContainer,
248 NULL
251 static const IID *const area_iids[] = {
252 ELEM_IFACES,
253 &IID_IHTMLAreaElement,
254 &IID_IConnectionPointContainer,
255 NULL
258 static const IID * const label_iids[] = {
259 ELEM_IFACES,
260 &IID_IHTMLLabelElement,
261 &IID_IConnectionPointContainer,
262 NULL
265 static const IID * const select_iids[] = {
266 ELEM_IFACES,
267 &IID_IHTMLSelectElement,
268 &IID_IConnectionPointContainer,
269 NULL
272 static const IID * const textarea_iids[] = {
273 ELEM_IFACES,
274 &IID_IHTMLTextAreaElement,
275 &IID_IConnectionPointContainer,
276 NULL
279 static const IID * const option_iids[] = {
280 ELEM_IFACES,
281 &IID_IHTMLOptionElement,
282 &IID_IConnectionPointContainer,
283 NULL
286 static const IID * const table_iids[] = {
287 ELEM_IFACES,
288 &IID_IHTMLTable,
289 &IID_IHTMLTable2,
290 &IID_IHTMLTable3,
291 &IID_IConnectionPointContainer,
292 NULL
295 static const IID * const script_iids[] = {
296 ELEM_IFACES,
297 &IID_IHTMLScriptElement,
298 &IID_IConnectionPointContainer,
299 NULL
302 static const IID * const text_iids[] = {
303 &IID_IHTMLDOMNode,
304 &IID_IHTMLDOMNode2,
305 &IID_IHTMLDOMTextNode,
306 &IID_IHTMLDOMTextNode2,
307 NULL
310 static const IID * const attr_iids[] = {
311 &IID_IHTMLDOMAttribute,
312 &IID_IHTMLDOMAttribute2,
313 &IID_IDispatchEx,
314 NULL
317 static const IID * const location_iids[] = {
318 &IID_IDispatch,
319 &IID_IHTMLLocation,
320 NULL
323 static const IID * const window_iids[] = {
324 &IID_IDispatch,
325 &IID_IHTMLWindow2,
326 &IID_IHTMLWindow3,
327 &IID_IDispatchEx,
328 &IID_IServiceProvider,
329 NULL
332 static const IID * const comment_iids[] = {
333 ELEM_IFACES,
334 &IID_IHTMLCommentElement,
335 &IID_IConnectionPointContainer,
336 NULL
339 static const IID * const img_iids[] = {
340 ELEM_IFACES,
341 &IID_IHTMLImgElement,
342 &IID_IConnectionPointContainer,
343 NULL
346 static const IID * const tr_iids[] = {
347 ELEM_IFACES,
348 &IID_IHTMLTableRow,
349 &IID_IConnectionPointContainer,
350 NULL
353 static const IID * const td_iids[] = {
354 ELEM_IFACES,
355 &IID_IHTMLTableCell,
356 &IID_IConnectionPointContainer,
357 NULL
360 static const IID * const frame_iids[] = {
361 ELEM_IFACES,
362 &IID_IHTMLFrameBase,
363 &IID_IHTMLFrameBase2,
364 &IID_IConnectionPointContainer,
365 NULL
368 static const IID * const html_iids[] = {
369 ELEM_IFACES,
370 &IID_IHTMLHtmlElement,
371 &IID_IConnectionPointContainer,
372 NULL
375 static const IID * const head_iids[] = {
376 ELEM_IFACES,
377 &IID_IHTMLHeadElement,
378 &DIID_DispHTMLHeadElement,
379 &IID_IConnectionPointContainer,
380 NULL
383 static const IID * const title_iids[] = {
384 ELEM_IFACES,
385 &IID_IHTMLTitleElement,
386 &IID_IConnectionPointContainer,
387 NULL
390 static const IID * const meta_iids[] = {
391 ELEM_IFACES,
392 &IID_IHTMLMetaElement,
393 &IID_IConnectionPointContainer,
394 NULL
397 static const IID * const link_iids[] = {
398 ELEM_IFACES,
399 &IID_IHTMLLinkElement,
400 &IID_IConnectionPointContainer,
401 NULL
404 static const IID * const object_iids[] = {
405 ELEM_IFACES,
406 &IID_IHTMLObjectElement,
407 &IID_IHTMLObjectElement2,
408 /* FIXME: No IConnectionPointContainer */
409 NULL
412 static const IID * const embed_iids[] = {
413 ELEM_IFACES,
414 &IID_IHTMLEmbedElement,
415 /* FIXME: No IConnectionPointContainer */
416 NULL
419 static const IID * const iframe_iids[] = {
420 ELEM_IFACES,
421 &IID_IHTMLFrameBase,
422 &IID_IHTMLFrameBase2,
423 &IID_IHTMLIFrameElement,
424 &IID_IHTMLIFrameElement2,
425 &IID_IConnectionPointContainer,
426 NULL
429 static const IID * const form_iids[] = {
430 ELEM_IFACES,
431 &IID_IHTMLFormElement,
432 &IID_IConnectionPointContainer,
433 &DIID_DispHTMLFormElement,
434 NULL
437 static const IID * const styleelem_iids[] = {
438 ELEM_IFACES,
439 &IID_IHTMLStyleElement,
440 &IID_IConnectionPointContainer,
441 NULL
444 static const IID * const generic_iids[] = {
445 ELEM_IFACES,
446 &IID_IHTMLGenericElement,
447 &IID_IConnectionPointContainer,
448 NULL
451 static const IID * const svg_iids[] = {
452 ELEM_IFACES,
453 &IID_ISVGElement,
454 &IID_ISVGSVGElement,
455 NULL
458 static const IID * const circle_iids[] = {
459 ELEM_IFACES,
460 &IID_ISVGElement,
461 &IID_ISVGCircleElement,
462 NULL
465 static const IID * const tspan_iids[] = {
466 ELEM_IFACES,
467 &IID_ISVGElement,
468 &IID_ISVGTextContentElement,
469 &IID_ISVGTSpanElement,
470 NULL
473 static const IID * const style_iids[] = {
474 &IID_IUnknown,
475 &IID_IDispatch,
476 &IID_IDispatchEx,
477 &IID_IHTMLStyle,
478 &IID_IHTMLStyle2,
479 &IID_IHTMLStyle3,
480 &IID_IHTMLStyle4,
481 NULL
484 static const IID * const cstyle_iids[] = {
485 &IID_IUnknown,
486 &IID_IDispatch,
487 &IID_IDispatchEx,
488 &IID_IHTMLCurrentStyle,
489 &IID_IHTMLCurrentStyle2,
490 &IID_IHTMLCurrentStyle3,
491 NULL
494 static const IID * const computed_style_iids[] = {
495 &IID_IUnknown,
496 &IID_IDispatch,
497 &IID_IDispatchEx,
498 &IID_IHTMLCSSStyleDeclaration,
499 NULL
502 static const IID * const img_factory_iids[] = {
503 &IID_IUnknown,
504 &IID_IDispatch,
505 &IID_IDispatchEx,
506 &IID_IHTMLImageElementFactory,
507 NULL
510 static const IID * const selection_iids[] = {
511 &IID_IUnknown,
512 &IID_IDispatch,
513 &IID_IDispatchEx,
514 &IID_IHTMLSelectionObject,
515 &IID_IHTMLSelectionObject2,
516 NULL
519 typedef struct {
520 const WCHAR *tag;
521 REFIID *iids;
522 const IID *dispiid;
523 const CLSID *clsid;
524 } elem_type_info_t;
526 static const elem_type_info_t elem_type_infos[] = {
527 {L"", none_iids, NULL},
528 {L"HTML", html_iids, &DIID_DispHTMLHtmlElement, &CLSID_HTMLHtmlElement},
529 {L"HEAD", head_iids, &DIID_DispHTMLHeadElement, &CLSID_HTMLHeadElement},
530 {L"TITLE", title_iids, &DIID_DispHTMLTitleElement, &CLSID_HTMLTitleElement},
531 {L"BODY", body_iids, &DIID_DispHTMLBody, &CLSID_HTMLBody},
532 {L"A", anchor_iids, &DIID_DispHTMLAnchorElement, &CLSID_HTMLAnchorElement},
533 {L"INPUT", input_iids, &DIID_DispHTMLInputElement, &CLSID_HTMLInputElement},
534 {L"SELECT", select_iids, &DIID_DispHTMLSelectElement, &CLSID_HTMLSelectElement},
535 {L"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement, &CLSID_HTMLTextAreaElement},
536 {L"OPTION", option_iids, &DIID_DispHTMLOptionElement, &CLSID_HTMLOptionElement},
537 {L"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement, &CLSID_HTMLStyleElement},
538 {L"BLOCKQUOTE",elem_iids, NULL},
539 {L"P", elem_iids, NULL},
540 {L"BR", elem_iids, NULL},
541 {L"TABLE", table_iids, &DIID_DispHTMLTable, &CLSID_HTMLTable},
542 {L"TBODY", elem_iids, NULL},
543 {L"SCRIPT", script_iids, &DIID_DispHTMLScriptElement, &CLSID_HTMLScriptElement},
544 {L"TEST", elem_iids, &DIID_DispHTMLUnknownElement, &CLSID_HTMLUnknownElement},
545 {L"TEST", generic_iids, &DIID_DispHTMLGenericElement, &CLSID_HTMLGenericElement},
546 {L"!", comment_iids, &DIID_DispHTMLCommentElement, &CLSID_HTMLCommentElement},
547 {L"IMG", img_iids, &DIID_DispHTMLImg, &CLSID_HTMLImg},
548 {L"TR", tr_iids, &DIID_DispHTMLTableRow, &CLSID_HTMLTableRow},
549 {L"TD", td_iids, &DIID_DispHTMLTableCell, &CLSID_HTMLTableCell},
550 {L"IFRAME", iframe_iids, &DIID_DispHTMLIFrame, &CLSID_HTMLIFrame},
551 {L"FORM", form_iids, &DIID_DispHTMLFormElement, &CLSID_HTMLFormElement},
552 {L"FRAME", frame_iids, &DIID_DispHTMLFrameElement, &CLSID_HTMLFrameElement},
553 {L"OBJECT", object_iids, &DIID_DispHTMLObjectElement, &CLSID_HTMLObjectElement},
554 {L"EMBED", embed_iids, &DIID_DispHTMLEmbed, &CLSID_HTMLEmbed},
555 {L"DIV", elem_iids, NULL},
556 {L"META", meta_iids, &DIID_DispHTMLMetaElement, &CLSID_HTMLMetaElement},
557 {L"NOSCRIPT", elem_iids, /* &DIID_DispHTMLNoShowElement */},
558 {L"LINK", link_iids, &DIID_DispHTMLLinkElement, &CLSID_HTMLLinkElement},
559 {L"LABEL", label_iids, &DIID_DispHTMLLabelElement, &CLSID_HTMLLabelElement},
560 {L"BUTTON", button_iids, &DIID_DispHTMLButtonElement, &CLSID_HTMLButtonElement},
561 {L"AREA", area_iids, &DIID_DispHTMLAreaElement, &CLSID_HTMLAreaElement},
562 {L"svg", svg_iids, NULL},
563 {L"circle", circle_iids, NULL},
564 {L"tspan", tspan_iids, NULL}
567 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
569 IUnknown *unk1, *unk2;
571 if(iface1 == iface2)
572 return TRUE;
574 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
575 IUnknown_Release(unk1);
576 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
577 IUnknown_Release(unk2);
579 return unk1 == unk2;
582 static IHTMLDocument2 *create_document(void)
584 IHTMLDocument2 *doc;
585 IHTMLDocument5 *doc5;
586 HRESULT hres;
588 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
589 &IID_IHTMLDocument2, (void**)&doc);
590 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
591 if(FAILED(hres))
592 return NULL;
594 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
595 if(FAILED(hres)) {
596 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
597 IHTMLDocument2_Release(doc);
598 return NULL;
601 IHTMLDocument5_Release(doc5);
602 return doc;
605 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
606 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
608 IDispatchEx *dispex;
609 HRESULT hres;
611 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
612 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
613 return dispex;
616 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
617 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
619 const IID * const *piid;
620 IUnknown *unk;
621 HRESULT hres;
623 for(piid = iids; *piid; piid++) {
624 hres = IUnknown_QueryInterface(iface, *piid, (void**)&unk);
625 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", wine_dbgstr_guid(*piid), hres);
626 if(SUCCEEDED(hres))
627 IUnknown_Release(unk);
631 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
632 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
634 IUnknown *unk;
635 HRESULT hres;
637 unk = (void*)0xdeadbeef;
638 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
639 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
640 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
643 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
644 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
646 IDispatchEx *dispex = _get_dispex_iface(line, unk);
647 ITypeInfo *typeinfo;
648 BOOL ret = FALSE;
649 UINT ticnt;
650 HRESULT hres;
652 ticnt = 0xdeadbeef;
653 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
654 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
655 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
657 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
658 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
660 if(SUCCEEDED(hres)) {
661 TYPEATTR *type_attr;
663 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
664 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
665 if(hres == S_OK) {
666 *iid = type_attr->guid;
667 ret = TRUE;
670 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
671 ITypeInfo_Release(typeinfo);
674 IDispatchEx_Release(dispex);
675 return ret;
678 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
679 static void _test_disp_value(unsigned line, IUnknown *unk, const WCHAR *val)
681 IDispatchEx *dispex = _get_dispex_iface(line, unk);
682 DISPPARAMS dp = {NULL,NULL,0,0};
683 EXCEPINFO ei;
684 VARIANT var;
685 HRESULT hres;
687 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
688 IDispatchEx_Release(dispex);
689 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
691 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
692 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), wine_dbgstr_w(val));
693 VariantClear(&var);
696 #define test_class_info(a,b) _test_class_info(__LINE__,a,b)
697 static void _test_class_info(unsigned line, IUnknown *unk, const CLSID *clsid)
699 IProvideMultipleClassInfo *multiple_classinfo;
700 IProvideClassInfo2 *classinfo;
701 ITypeInfo *typeinfo;
702 TYPEATTR *type_attr;
703 ULONG count;
704 HRESULT hres;
706 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo2, (void**)&classinfo);
707 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo2 interface: %08x\n", hres);
708 if(FAILED(hres))
709 return;
711 hres = IProvideClassInfo2_GetClassInfo(classinfo, &typeinfo);
712 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
713 if(FAILED(hres))
715 IProvideClassInfo2_Release(classinfo);
716 return;
719 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
720 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
721 if(SUCCEEDED(hres))
723 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, clsid),
724 "unexpected guid %s\n", wine_dbgstr_guid(&type_attr->guid));
725 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
726 "unexpected typekind %d\n", type_attr->typekind);
727 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
730 ITypeInfo_Release(typeinfo);
731 IProvideClassInfo2_Release(classinfo);
733 hres = IUnknown_QueryInterface(unk, &IID_IProvideMultipleClassInfo, (void**)&multiple_classinfo);
734 if(IsEqualGUID(clsid, &CLSID_HTMLXMLHttpRequest)) {
735 ok_(__FILE__,line)(hres == E_NOINTERFACE, "Could not get IProvideClassInfo2 interface: %08x\n", hres);
736 }else {
737 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo2 interface: %08x\n", hres);
739 hres = IProvideMultipleClassInfo_GetMultiTypeInfoCount(multiple_classinfo, &count);
740 ok_(__FILE__,line)(hres == S_OK, "GetMultiTypeInfoCount failed: %08x\n", hres);
741 ok_(__FILE__,line)(count > 0, "count = %u\n", count);
743 IProvideMultipleClassInfo_Release(multiple_classinfo);
747 #define test_disp2(a,b,c,d,e) _test_disp2(__LINE__,a,b,c,d,e)
748 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const CLSID *clsid, const WCHAR *val)
750 IUnknown *u;
751 IID iid;
752 HRESULT hres;
754 if(_test_get_dispid(line, unk, &iid) && compat_mode < COMPAT_IE9)
755 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(diid2 && IsEqualGUID(&iid, diid2)),
756 "unexpected guid %s\n", wine_dbgstr_guid(&iid));
758 if(!IsEqualGUID(diid, &DIID_DispHTMLWindow2) && !IsEqualGUID(diid, &DIID_DispHTMLLocation)) {
759 u = (void*)0xdeadbeef;
760 hres = IUnknown_QueryInterface(unk, &IID_IMarshal, (void**)&u);
761 ok_(__FILE__,line)(hres == E_NOINTERFACE, "Got IMarshal iface\n");
762 ok_(__FILE__,line)(!u, "u = %p\n", u);
765 u = (void*)0xdeadbeef;
766 hres = IUnknown_QueryInterface(unk, &IID_IManagedObject, (void**)&u);
767 ok_(__FILE__,line)(hres == E_NOINTERFACE, "Got IManagedObject iface\n");
768 ok_(__FILE__,line)(!u, "u = %p\n", u);
770 if(val && compat_mode < COMPAT_IE9) /* FIXME: Enable those tests in IE9+ mode */
771 _test_disp_value(line, unk, val);
773 if(clsid) {
774 _test_class_info(line, unk, clsid);
775 }else {
776 u = (void*)0xdeadbeef;
777 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&u);
778 ok_(__FILE__,line)(hres == E_NOINTERFACE, "Got IProvideClassInfo iface\n");
779 ok_(__FILE__,line)(!u, "u = %p\n", u);
783 #define test_disp(a,b,c,d) _test_disp(__LINE__,a,b,c,d)
784 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const CLSID *clsid, const WCHAR *val)
786 return _test_disp2(line, unk, diid, NULL, clsid, val);
789 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
790 static void _set_dispex_value(unsigned line, IUnknown *unk, const WCHAR *name, VARIANT *val)
792 IDispatchEx *dispex = _get_dispex_iface(line, unk);
793 DISPPARAMS dp = {val, NULL, 1, 0};
794 EXCEPINFO ei;
795 DISPID id;
796 BSTR str;
797 HRESULT hres;
799 str = SysAllocString(name);
800 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
801 SysFreeString(str);
802 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
804 memset(&ei, 0, sizeof(ei));
805 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
806 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
810 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
811 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
813 IHTMLElement *elem;
814 HRESULT hres;
816 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
817 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
818 return elem;
821 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
822 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
824 IHTMLElement2 *elem;
825 HRESULT hres;
827 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
828 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
829 return elem;
832 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
833 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
835 IHTMLElement3 *elem;
836 HRESULT hres;
838 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
839 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
840 return elem;
843 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
844 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
846 IHTMLElement4 *elem;
847 HRESULT hres;
849 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
850 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
851 return elem;
854 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
855 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IHTMLDocument2 *doc)
857 IHTMLDocument3 *doc3;
858 HRESULT hres;
860 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
861 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
863 return doc3;
866 #define get_node_iface(u) _get_node_iface(__LINE__,u)
867 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
869 IHTMLDOMNode *node;
870 HRESULT hres;
872 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
873 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
874 return node;
877 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
878 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
880 IHTMLDOMNode2 *node;
881 HRESULT hres;
883 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
884 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
885 return node;
888 #define get_htmldoc5_iface(u) _get_htmldoc5_iface(__LINE__,u)
889 static IHTMLDocument5 *_get_htmldoc5_iface(unsigned line, IUnknown *unk)
891 IHTMLDocument5 *doc;
892 HRESULT hres;
894 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument5, (void**)&doc);
895 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument5: %08x\n", hres);
896 return doc;
899 #define get_img_iface(u) _get_img_iface(__LINE__,u)
900 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
902 IHTMLImgElement *img;
903 HRESULT hres;
905 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
906 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
907 return img;
910 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
911 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
913 IHTMLAnchorElement *anchor;
914 HRESULT hres;
916 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
917 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
918 return anchor;
921 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
922 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
924 IHTMLTextAreaElement *textarea;
925 HRESULT hres;
927 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
928 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
929 return textarea;
932 #define get_select_iface(u) _get_select_iface(__LINE__,u)
933 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
935 IHTMLSelectElement *select;
936 HRESULT hres;
938 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
939 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
940 return select;
943 #define get_option_iface(u) _get_option_iface(__LINE__,u)
944 static IHTMLOptionElement *_get_option_iface(unsigned line, IUnknown *unk)
946 IHTMLOptionElement *option;
947 HRESULT hres;
949 hres = IUnknown_QueryInterface(unk, &IID_IHTMLOptionElement, (void**)&option);
950 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLOptionElement: %08x\n", hres);
951 return option;
954 #define get_form_iface(u) _get_form_iface(__LINE__,u)
955 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
957 IHTMLFormElement *form;
958 HRESULT hres;
960 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
961 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
962 return form;
965 #define get_text_iface(u) _get_text_iface(__LINE__,u)
966 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
968 IHTMLDOMTextNode *text;
969 HRESULT hres;
971 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
972 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
973 return text;
976 #define get_text2_iface(u) _get_text2_iface(__LINE__,u)
977 static IHTMLDOMTextNode2 *_get_text2_iface(unsigned line, IUnknown *unk)
979 IHTMLDOMTextNode2 *text2;
980 HRESULT hres;
982 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode2, (void**)&text2);
983 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode2: %08x\n", hres);
984 return text2;
987 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
988 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
990 IHTMLCommentElement *comment;
991 HRESULT hres;
993 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
994 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
995 return comment;
998 #define get_object_iface(u) _get_object_iface(__LINE__,u)
999 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
1001 IHTMLObjectElement *obj;
1002 HRESULT hres;
1004 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
1005 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
1006 return obj;
1009 #define get_style_iface(u) _get_style_iface(__LINE__,u)
1010 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
1012 IHTMLStyleElement *obj;
1013 HRESULT hres;
1015 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
1016 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
1017 return obj;
1020 #define get_metaelem_iface(u) _get_metaelem_iface(__LINE__,u)
1021 static IHTMLMetaElement *_get_metaelem_iface(unsigned line, IUnknown *unk)
1023 IHTMLMetaElement *ret;
1024 HRESULT hres;
1026 hres = IUnknown_QueryInterface(unk, &IID_IHTMLMetaElement, (void**)&ret);
1027 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLMetaElement: %08x\n", hres);
1028 return ret;
1031 #define get_link_iface(u) _get_link_iface(__LINE__,u)
1032 static IHTMLLinkElement *_get_link_iface(unsigned line, IUnknown *unk)
1034 IHTMLLinkElement *ret;
1035 HRESULT hres;
1037 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLinkElement, (void**)&ret);
1038 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLinkElement: %08x\n", hres);
1039 return ret;
1042 #define get_iframe2_iface(u) _get_iframe2_iface(__LINE__,u)
1043 static IHTMLIFrameElement2 *_get_iframe2_iface(unsigned line, IUnknown *unk)
1045 IHTMLIFrameElement2 *ret;
1046 HRESULT hres;
1048 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement2, (void**)&ret);
1049 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLIFrameElement: %08x\n", hres);
1050 return ret;
1053 #define get_button_iface(u) _get_button_iface(__LINE__,u)
1054 static IHTMLButtonElement *_get_button_iface(unsigned line, IUnknown *unk)
1056 IHTMLButtonElement *ret;
1057 HRESULT hres;
1059 hres = IUnknown_QueryInterface(unk, &IID_IHTMLButtonElement, (void**)&ret);
1060 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLButtonElement: %08x\n", hres);
1061 return ret;
1064 #define get_label_iface(u) _get_label_iface(__LINE__,u)
1065 static IHTMLLabelElement *_get_label_iface(unsigned line, IUnknown *unk)
1067 IHTMLLabelElement *ret;
1068 HRESULT hres;
1070 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLabelElement, (void**)&ret);
1071 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLabelElement: %08x\n", hres);
1072 return ret;
1075 #define get_attr2_iface(u) _get_attr2_iface(__LINE__,u)
1076 static IHTMLDOMAttribute2 *_get_attr2_iface(unsigned line, IUnknown *unk)
1078 IHTMLDOMAttribute2 *ret;
1079 HRESULT hres;
1081 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMAttribute2, (void**)&ret);
1082 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMAttribute2: %08x\n", hres);
1083 return ret;
1086 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
1087 static void _test_node_name(unsigned line, IUnknown *unk, const WCHAR *exname)
1089 IHTMLDOMNode *node = _get_node_iface(line, unk);
1090 IHTMLElement6 *elem;
1091 BSTR name;
1092 HRESULT hres;
1094 hres = IHTMLDOMNode_get_nodeName(node, &name);
1095 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
1096 ok_(__FILE__, line) (!lstrcmpW(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(exname));
1097 SysFreeString(name);
1099 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement6, (void**)&elem);
1100 if(SUCCEEDED(hres)) {
1101 hres = IHTMLElement6_get_nodeName(elem, &name);
1102 ok_(__FILE__, line) (hres == S_OK, "(elem) get_nodeName failed: %08x\n", hres);
1103 ok_(__FILE__, line) (!lstrcmpW(name, exname), "(elem) got name: %s, expected %s\n",
1104 wine_dbgstr_w(name), wine_dbgstr_w(exname));
1105 SysFreeString(name);
1106 IHTMLElement6_Release(elem);
1109 IHTMLDOMNode_Release(node);
1112 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
1113 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
1115 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
1116 IDispatch *disp = (void*)0xdeadbeef;
1117 IHTMLDocument2 *doc = NULL;
1118 HRESULT hres;
1120 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
1121 IHTMLDOMNode2_Release(node);
1122 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
1124 if(disp) {
1125 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
1126 IDispatch_Release(disp);
1127 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
1130 return doc;
1133 #define get_doc_window(d) _get_doc_window(__LINE__,d)
1134 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
1136 IHTMLWindow2 *window;
1137 HRESULT hres;
1139 window = NULL;
1140 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1141 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1142 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
1144 return window;
1147 #define clone_node(n,d) _clone_node(__LINE__,n,d)
1148 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
1150 IHTMLDOMNode *node = _get_node_iface(line, unk);
1151 IHTMLDOMNode *ret = NULL;
1152 HRESULT hres;
1154 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
1155 IHTMLDOMNode_Release(node);
1156 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
1157 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
1159 return ret;
1163 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
1164 static void _test_elem_tag(unsigned line, IUnknown *unk, const WCHAR *extag)
1166 IHTMLElement *elem = _get_elem_iface(line, unk);
1167 IHTMLElement6 *elem6;
1168 BSTR tag;
1169 HRESULT hres;
1171 hres = IHTMLElement_get_tagName(elem, &tag);
1172 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
1173 ok_(__FILE__, line) (!lstrcmpW(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), wine_dbgstr_w(extag));
1174 SysFreeString(tag);
1176 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLElement6, (void**)&elem6);
1177 if(SUCCEEDED(hres)) {
1178 hres = IHTMLElement6_get_tagName(elem6, &tag);
1179 ok_(__FILE__, line)(hres == S_OK, "(elem6) get_tagName failed: %08x\n", hres);
1180 ok_(__FILE__, line)(!lstrcmpW(tag, extag), "(elem6) got tag: %s, expected %s\n",
1181 wine_dbgstr_w(tag), wine_dbgstr_w(extag));
1182 SysFreeString(tag);
1183 IHTMLElement6_Release(elem6);
1186 IHTMLElement_Release(elem);
1189 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
1190 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
1192 const WCHAR *expected_value = L"[object]";
1194 _test_elem_tag(line, unk, elem_type_infos[type].tag);
1195 _test_ifaces(line, unk, elem_type_infos[type].iids);
1197 if(elem_type_infos[type].dispiid && type != ET_A) {
1198 if(type == ET_AREA)
1199 expected_value = NULL;
1200 _test_disp(line, unk, elem_type_infos[type].dispiid, elem_type_infos[type].clsid, expected_value);
1204 #define get_node_type(n) _get_node_type(__LINE__,n)
1205 static LONG _get_node_type(unsigned line, IUnknown *unk)
1207 IHTMLDOMNode *node = _get_node_iface(line, unk);
1208 LONG type = -1;
1209 HRESULT hres;
1211 hres = IHTMLDOMNode_get_nodeType(node, &type);
1212 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1214 IHTMLDOMNode_Release(node);
1216 return type;
1219 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1220 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1222 IHTMLDOMNode *node = _get_node_iface(line, unk);
1223 IHTMLDOMChildrenCollection *col = NULL;
1224 IDispatch *disp;
1225 HRESULT hres;
1227 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1228 IHTMLDOMNode_Release(node);
1229 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1230 if(FAILED(hres))
1231 return NULL;
1233 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1234 IDispatch_Release(disp);
1235 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1237 return col;
1240 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1241 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
1243 IHTMLDOMNode *node = NULL;
1244 IDispatch *disp;
1245 HRESULT hres;
1247 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1248 ok(hres == S_OK, "item failed: %08x\n", hres);
1250 node = _get_node_iface(line, (IUnknown*)disp);
1251 IDispatch_Release(disp);
1253 return node;
1256 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
1257 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const WCHAR *name, const WCHAR *exval)
1259 VARIANT value;
1260 BSTR tmp;
1261 HRESULT hres;
1263 VariantInit(&value);
1265 tmp = SysAllocString(name);
1266 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
1267 SysFreeString(tmp);
1268 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
1270 if(exval) {
1271 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
1272 ok_(__FILE__,line) (!lstrcmpW(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
1273 }else {
1274 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
1277 VariantClear(&value);
1280 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
1281 static void _test_elem_offset(unsigned line, IUnknown *unk, const WCHAR *parent_tag)
1283 IHTMLElement *elem = _get_elem_iface(line, unk);
1284 IHTMLElement *off_parent;
1285 LONG l;
1286 HRESULT hres;
1288 hres = IHTMLElement_get_offsetTop(elem, &l);
1289 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1291 hres = IHTMLElement_get_offsetHeight(elem, &l);
1292 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1294 hres = IHTMLElement_get_offsetWidth(elem, &l);
1295 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1297 hres = IHTMLElement_get_offsetLeft(elem, &l);
1298 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1300 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1301 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1302 IHTMLElement_Release(elem);
1304 if(off_parent) {
1305 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1306 IHTMLElement_Release(off_parent);
1307 }else {
1308 ok_(__FILE__,line) (parent_tag == NULL, "Offset parent is NULL. %s expected\n", wine_dbgstr_w(parent_tag));
1312 #define test_elem_source_index(a,b) _test_elem_source_index(__LINE__,a,b)
1313 static void _test_elem_source_index(unsigned line, IHTMLElement *elem, int index)
1315 LONG l = 0xdeadbeef;
1316 HRESULT hres;
1318 hres = IHTMLElement_get_sourceIndex(elem, &l);
1319 ok_(__FILE__,line)(hres == S_OK, "get_sourceIndex failed: %08x\n", hres);
1320 ok_(__FILE__,line)(l == index, "sourceIndex = %d, expected %d\n", l, index);
1323 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1324 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1326 IHTMLWindow2 *window;
1327 IHTMLDocument2 *ret;
1328 HRESULT hres;
1330 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1331 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1333 hres = IHTMLWindow2_get_document(window, &ret);
1334 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1335 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1337 return ret;
1340 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1341 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const WCHAR *exname)
1343 BSTR name;
1344 HRESULT hres;
1346 hres = IHTMLWindow2_get_name(window, &name);
1347 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1348 if(exname)
1349 ok_(__FILE__,line)(!lstrcmpW(name, exname), "name = %s\n", wine_dbgstr_w(name));
1350 else
1351 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1352 SysFreeString(name);
1355 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1356 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const WCHAR *name)
1358 BSTR str;
1359 HRESULT hres;
1361 str = SysAllocString(name);
1362 hres = IHTMLWindow2_put_name(window, str);
1363 SysFreeString(str);
1364 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1366 _test_window_name(line, window, name);
1369 #define test_window_status(d) _test_window_status(__LINE__,d)
1370 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1372 BSTR status;
1373 HRESULT hres;
1375 status = (void*)0xdeadbeef;
1376 hres = IHTMLWindow2_get_status(window, &status);
1377 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1378 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1379 SysFreeString(status);
1382 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1383 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const WCHAR *status)
1385 BSTR str;
1386 HRESULT hres;
1388 str = SysAllocString(status);
1389 hres = IHTMLWindow2_put_status(window, str);
1390 SysFreeString(str);
1391 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1394 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1395 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1397 LONG length = -1;
1398 HRESULT hres;
1400 hres = IHTMLWindow2_get_length(window, &length);
1401 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1402 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1405 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1406 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1408 IHTMLFrameBase2 *base2;
1409 IHTMLWindow2 *window;
1410 HRESULT hres;
1412 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1413 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1415 window = NULL;
1416 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1417 IHTMLFrameBase2_Release(base2);
1418 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1419 ok(window != NULL, "contentWindow = NULL\n");
1421 return window;
1424 static void test_get_set_attr(IHTMLDocument2 *doc)
1426 IHTMLElement *elem;
1427 IHTMLDocument3 *doc3;
1428 HRESULT hres;
1429 BSTR bstr;
1430 VARIANT val;
1432 /* grab an element to test with */
1433 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1434 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1436 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1437 IHTMLDocument3_Release(doc3);
1438 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1440 /* get a non-present attribute */
1441 bstr = SysAllocString(L"notAnAttribute");
1442 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1443 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1444 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1445 VariantClear(&val);
1446 SysFreeString(bstr);
1448 /* get a present attribute */
1449 bstr = SysAllocString(L"scrollHeight");
1450 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1451 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1452 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1453 VariantClear(&val);
1454 SysFreeString(bstr);
1456 /* create a new BSTR attribute */
1457 bstr = SysAllocString(L"newAttribute");
1459 V_VT(&val) = VT_BSTR;
1460 V_BSTR(&val) = SysAllocString(L"the value");
1461 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1462 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1463 VariantClear(&val);
1465 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1466 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1467 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1468 ok(lstrcmpW(V_BSTR(&val), L"the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
1469 VariantClear(&val);
1471 /* overwrite the attribute with a BOOL */
1472 V_VT(&val) = VT_BOOL;
1473 V_BOOL(&val) = VARIANT_TRUE;
1474 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1475 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1476 VariantClear(&val);
1478 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1479 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1480 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1481 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1482 VariantClear(&val);
1484 SysFreeString(bstr);
1486 /* case-insensitive */
1487 bstr = SysAllocString(L"newattribute");
1488 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1489 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1490 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1491 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1492 VariantClear(&val);
1494 /* overwrite the attribute with null */
1495 V_VT(&val) = VT_NULL;
1496 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1497 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1499 hres = IHTMLElement_getAttribute(elem, bstr, 2, &val);
1500 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1501 ok(V_VT(&val) == VT_BSTR, "V_VT(val) = %u, expected VT_BSTR\n", V_VT(&val));
1502 ok(!lstrcmpW(V_BSTR(&val), L"null"), "V_BSTR(val) = %s, expected \"null\"\n", wine_dbgstr_w(V_BSTR(&val)));
1503 VariantClear(&val);
1505 SysFreeString(bstr);
1506 IHTMLElement_Release(elem);
1509 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1510 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1512 IHTMLElement *elem;
1513 IHTMLDocument3 *doc3;
1514 HRESULT hres;
1516 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1517 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1518 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1519 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1520 IHTMLDocument3_Release(doc3);
1522 return elem;
1525 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1526 static void _test_anchor_href(unsigned line, IUnknown *unk, const WCHAR *exhref)
1528 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1529 BSTR str;
1530 HRESULT hres;
1532 hres = IHTMLAnchorElement_get_href(anchor, &str);
1533 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1534 ok_(__FILE__,line)(!lstrcmpW(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exhref));
1535 SysFreeString(str);
1537 _test_disp_value(line, unk, exhref);
1540 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1541 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const WCHAR *exhref)
1543 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1544 BSTR str;
1545 HRESULT hres;
1547 str = SysAllocString(exhref);
1548 hres = IHTMLAnchorElement_put_href(anchor, str);
1549 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1550 SysFreeString(str);
1552 _test_disp_value(line, unk, exhref);
1555 #define test_anchor_rel(a,h) _test_anchor_rel(__LINE__,a,h)
1556 static void _test_anchor_rel(unsigned line, IUnknown *unk, const WCHAR *exrel)
1558 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1559 BSTR str;
1560 HRESULT hres;
1562 hres = IHTMLAnchorElement_get_rel(anchor, &str);
1563 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1564 if(exrel)
1565 ok_(__FILE__,line)(!lstrcmpW(str, exrel), "rel = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exrel));
1566 else
1567 ok_(__FILE__,line)(!str, "rel = %s, expected NULL\n", wine_dbgstr_w(str));
1568 SysFreeString(str);
1571 #define test_anchor_put_rel(a,h) _test_anchor_put_rel(__LINE__,a,h)
1572 static void _test_anchor_put_rel(unsigned line, IUnknown *unk, const WCHAR *exrel)
1574 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1575 BSTR str;
1576 HRESULT hres;
1578 str = SysAllocString(exrel);
1579 hres = IHTMLAnchorElement_put_rel(anchor, str);
1580 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1581 SysFreeString(str);
1584 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1585 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const WCHAR *target)
1587 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1588 BSTR str;
1589 HRESULT hres;
1591 hres = IHTMLAnchorElement_get_target(anchor, &str);
1592 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1593 if(target)
1594 ok_(__FILE__,line)(!lstrcmpW(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(target));
1595 else
1596 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1597 SysFreeString(str);
1600 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1601 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const WCHAR *target)
1603 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1604 BSTR str;
1605 HRESULT hres;
1607 str = target ? SysAllocString(target) : NULL;
1608 hres = IHTMLAnchorElement_put_target(anchor, str);
1609 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1610 SysFreeString(str);
1613 #define test_anchor_name(a,h) _test_anchor_name(__LINE__,a,h)
1614 static void _test_anchor_name(unsigned line, IUnknown *unk, const WCHAR *name)
1616 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1617 BSTR str;
1618 HRESULT hres;
1620 hres = IHTMLAnchorElement_get_name(anchor, &str);
1621 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1622 if(name)
1623 ok_(__FILE__,line)(!lstrcmpW(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(name));
1624 else
1625 ok_(__FILE__,line)(str == NULL, "name = %s, expected NULL\n", wine_dbgstr_w(str));
1626 SysFreeString(str);
1629 #define test_anchor_put_name(a,h) _test_anchor_put_name(__LINE__,a,h)
1630 static void _test_anchor_put_name(unsigned line, IUnknown *unk, const WCHAR *name)
1632 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1633 BSTR str;
1634 HRESULT hres;
1636 str = name ? SysAllocString(name) : NULL;
1637 hres = IHTMLAnchorElement_put_name(anchor, str);
1638 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1639 SysFreeString(str);
1641 _test_anchor_name(line, unk, name);
1644 #define test_anchor_hostname(a,h) _test_anchor_hostname(__LINE__,a,h)
1645 static void _test_anchor_hostname(unsigned line, IUnknown *unk, const WCHAR *hostname)
1647 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1648 BSTR str;
1649 HRESULT hres;
1651 hres = IHTMLAnchorElement_get_hostname(anchor, &str);
1652 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1653 if(hostname)
1654 ok_(__FILE__,line)(!lstrcmpW(str, hostname), "hostname = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(hostname));
1655 else
1656 ok_(__FILE__,line)(str == NULL, "hostname = %s, expected NULL\n", wine_dbgstr_w(str));
1657 SysFreeString(str);
1660 #define test_anchor_search(a,h,n) _test_anchor_search(__LINE__,a,h,n)
1661 static void _test_anchor_search(unsigned line, IUnknown *elem, const WCHAR *search, BOOL allowbroken)
1663 IHTMLAnchorElement *anchor = _get_anchor_iface(line, elem);
1664 BSTR str;
1665 HRESULT hres;
1667 hres = IHTMLAnchorElement_get_search(anchor, &str);
1668 ok_(__FILE__,line)(hres == S_OK, "get_search failed: %08x\n", hres);
1669 if ( ! str && allowbroken)
1670 win_skip("skip ie6 incorrect behavior\n");
1671 else if(search)
1672 ok_(__FILE__,line)(!lstrcmpW(str, search), "search = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(search));
1673 else
1674 ok_(__FILE__,line)(!str, "search = %s, expected NULL\n", wine_dbgstr_w(str));
1675 SysFreeString(str);
1678 #define test_anchor_put_search(a,h) _test_anchor_put_search(__LINE__,a,h)
1679 static void _test_anchor_put_search(unsigned line, IUnknown *unk, const WCHAR *search)
1681 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1682 BSTR str;
1683 HRESULT hres;
1685 str = search ? SysAllocString(search) : NULL;
1686 hres = IHTMLAnchorElement_put_search(anchor, str);
1687 ok_(__FILE__,line)(hres == S_OK, "put_search failed: %08x\n", hres);
1688 SysFreeString(str);
1691 #define test_anchor_hash(a,h) _test_anchor_hash(__LINE__,a,h)
1692 static void _test_anchor_hash(unsigned line, IHTMLElement *elem, const WCHAR *exhash)
1694 IHTMLAnchorElement *anchor = _get_anchor_iface(line, (IUnknown*)elem);
1695 BSTR str;
1696 HRESULT hres;
1698 hres = IHTMLAnchorElement_get_hash(anchor, &str);
1699 ok_(__FILE__,line)(hres == S_OK, "get_hash failed: %08x\n", hres);
1700 if(exhash)
1701 ok_(__FILE__,line)(!lstrcmpW(str, exhash), "hash = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exhash));
1702 else
1703 ok_(__FILE__,line)(!str, "hash = %s, expected NULL\n", wine_dbgstr_w(str));
1704 SysFreeString(str);
1707 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1708 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const WCHAR *text)
1710 BSTR bstr;
1711 HRESULT hres;
1713 hres = IHTMLOptionElement_get_text(option, &bstr);
1714 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1715 ok_(__FILE__,line) (!lstrcmpW(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1716 SysFreeString(bstr);
1719 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1720 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const WCHAR *text)
1722 BSTR bstr;
1723 HRESULT hres;
1725 bstr = SysAllocString(text);
1726 hres = IHTMLOptionElement_put_text(option, bstr);
1727 SysFreeString(bstr);
1728 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1730 _test_option_text(line, option, text);
1733 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1734 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const WCHAR *value)
1736 BSTR bstr;
1737 HRESULT hres;
1739 hres = IHTMLOptionElement_get_value(option, &bstr);
1740 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1741 ok_(__FILE__,line) (!lstrcmpW(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1742 SysFreeString(bstr);
1745 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1746 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const WCHAR *value)
1748 BSTR bstr;
1749 HRESULT hres;
1751 bstr = SysAllocString(value);
1752 hres = IHTMLOptionElement_put_value(option, bstr);
1753 SysFreeString(bstr);
1754 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1756 _test_option_value(line, option, value);
1759 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1760 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1762 VARIANT_BOOL b = 0x100;
1763 HRESULT hres;
1765 hres = IHTMLOptionElement_get_selected(option, &b);
1766 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1767 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1770 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1771 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1773 HRESULT hres;
1775 hres = IHTMLOptionElement_put_selected(option, b);
1776 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1777 _test_option_selected(line, option, b);
1780 #define test_option_get_index(o,s) _test_option_get_index(__LINE__,o,s)
1781 static void _test_option_get_index(unsigned line, IHTMLOptionElement *option, LONG exval)
1783 HRESULT hres;
1784 LONG val;
1786 hres = IHTMLOptionElement_get_index(option, NULL);
1787 ok_(__FILE__,line)(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
1789 val = 12345678;
1790 hres = IHTMLOptionElement_get_index(option, &val);
1791 ok_(__FILE__,line)(hres == S_OK, "get_index failed: %08x\n", hres);
1792 ok_(__FILE__,line)(val == exval || broken(val == 12345678), /* Win2k doesn't touch it*/
1793 "value = %d, expected = %d\n", val, exval);
1796 #define test_option_put_defaultSelected(o,d) _test_option_put_defaultSelected(__LINE__,o,d)
1797 static void _test_option_put_defaultSelected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1799 HRESULT hres;
1801 hres = IHTMLOptionElement_put_defaultSelected(option, b);
1802 ok_(__FILE__,line)(hres == S_OK, "put_defaultSelected %08x\n", hres);
1805 #define test_option_defaultSelected(o,e) _test_option_defaultSelected(__LINE__,o,e)
1806 static void _test_option_defaultSelected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1808 HRESULT hres;
1809 VARIANT_BOOL b;
1811 hres = IHTMLOptionElement_get_defaultSelected(option, NULL);
1812 ok_(__FILE__,line)(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
1814 b = 0x100;
1815 hres = IHTMLOptionElement_get_defaultSelected(option, &b);
1816 ok_(__FILE__,line)(hres == S_OK, "get_defaultSelected failed: %08x\n", hres);
1817 ok_(__FILE__,line)(b == ex, "b = %x, expected = %x\n", b, ex);
1820 static void test_option_defaultSelected_property(IHTMLOptionElement *option)
1822 test_option_defaultSelected(option, VARIANT_FALSE);
1823 test_option_selected(option, VARIANT_FALSE);
1825 test_option_put_defaultSelected(option, 0x100); /* Invalid value */
1826 test_option_defaultSelected(option, VARIANT_FALSE);
1827 test_option_selected(option, VARIANT_FALSE);
1829 test_option_put_defaultSelected(option, VARIANT_TRUE);
1830 test_option_defaultSelected(option, VARIANT_TRUE);
1831 test_option_selected(option, VARIANT_FALSE);
1833 test_option_put_defaultSelected(option, 0x100); /* Invalid value */
1834 test_option_defaultSelected(option, VARIANT_FALSE);
1835 test_option_selected(option, VARIANT_FALSE);
1837 test_option_put_selected(option, VARIANT_TRUE);
1838 test_option_selected(option, VARIANT_TRUE);
1839 test_option_defaultSelected(option, VARIANT_FALSE);
1841 test_option_put_defaultSelected(option, VARIANT_TRUE);
1842 test_option_defaultSelected(option, VARIANT_TRUE);
1843 test_option_selected(option, VARIANT_TRUE);
1845 /* Restore defaultSelected */
1846 test_option_put_defaultSelected(option, VARIANT_TRUE);
1847 test_option_put_selected(option, VARIANT_FALSE);
1850 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1851 static void _test_textarea_value(unsigned line, IUnknown *unk, const WCHAR *exval)
1853 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1854 BSTR value = (void*)0xdeadbeef;
1855 HRESULT hres;
1857 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1858 IHTMLTextAreaElement_Release(textarea);
1859 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1860 if(exval)
1861 ok_(__FILE__,line)(!lstrcmpW(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), wine_dbgstr_w(exval));
1862 else
1863 ok_(__FILE__,line)(!value, "value = %p\n", value);
1864 SysFreeString(value);
1867 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1868 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const WCHAR *value)
1870 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1871 BSTR tmp = SysAllocString(value);
1872 HRESULT hres;
1874 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1875 IHTMLTextAreaElement_Release(textarea);
1876 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1877 SysFreeString(tmp);
1879 _test_textarea_value(line, unk, value);
1882 #define test_textarea_defaultvalue(t,v) _test_textarea_defaultvalue(__LINE__,t,v)
1883 static void _test_textarea_defaultvalue(unsigned line, IUnknown *unk, const WCHAR *exval)
1885 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1886 BSTR value = (void*)0xdeadbeef;
1887 HRESULT hres;
1889 hres = IHTMLTextAreaElement_get_defaultValue(textarea, &value);
1890 IHTMLTextAreaElement_Release(textarea);
1891 ok_(__FILE__,line)(hres == S_OK, "get_defaultValue failed: %08x\n", hres);
1892 if(exval)
1893 ok_(__FILE__,line)(!lstrcmpW(value, exval), "defaultValue = %s, expected %s\n", wine_dbgstr_w(value), wine_dbgstr_w(exval));
1894 else
1895 ok_(__FILE__,line)(!value, "value = %p\n", value);
1896 SysFreeString(value);
1899 #define test_textarea_put_defaultvalue(t,v) _test_textarea_put_defaultvalue(__LINE__,t,v)
1900 static void _test_textarea_put_defaultvalue(unsigned line, IUnknown *unk, const WCHAR *value)
1902 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1903 BSTR tmp = SysAllocString(value);
1904 HRESULT hres;
1906 hres = IHTMLTextAreaElement_put_defaultValue(textarea, tmp);
1907 IHTMLTextAreaElement_Release(textarea);
1908 ok_(__FILE__,line)(hres == S_OK, "put_defaultValue failed: %08x\n", hres);
1909 SysFreeString(tmp);
1911 _test_textarea_defaultvalue(line, unk, value);
1914 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1915 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1917 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1918 VARIANT_BOOL b = 0x100;
1919 HRESULT hres;
1921 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1922 IHTMLTextAreaElement_Release(textarea);
1923 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1924 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1927 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1928 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1930 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1931 HRESULT hres;
1933 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1934 IHTMLTextAreaElement_Release(textarea);
1935 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1937 _test_textarea_readonly(line, unk, b);
1940 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1941 static void _test_textarea_type(unsigned line, IUnknown *unk)
1943 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1944 BSTR type = (void*)0xdeadbeef;
1945 HRESULT hres;
1947 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1948 IHTMLTextAreaElement_Release(textarea);
1949 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1950 ok_(__FILE__,line)(!lstrcmpW(type, L"textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1951 SysFreeString(type);
1954 #define get_textarea_form(t) _get_textarea_form(__LINE__,t)
1955 static IHTMLFormElement *_get_textarea_form(unsigned line, IUnknown *unk)
1957 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1958 IHTMLFormElement *form;
1959 HRESULT hres;
1961 hres = IHTMLTextAreaElement_get_form(textarea, &form);
1962 IHTMLTextAreaElement_Release(textarea);
1963 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1965 return form;
1968 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1969 static void _test_comment_text(unsigned line, IUnknown *unk, const WCHAR *extext)
1971 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1972 const WCHAR *p;
1973 BSTR text;
1974 HRESULT hres;
1976 hres = IHTMLCommentElement_get_text(comment, &text);
1977 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1978 if((p = wcsstr(extext, L"-->")) && SysStringLen(text) == p - extext) /* Some IEs drop comment ending */
1979 ok_(__FILE__,line)(!wcsncmp(text, extext, p - extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), wine_dbgstr_w(extext));
1980 else
1981 ok_(__FILE__,line)(!lstrcmpW(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), wine_dbgstr_w(extext));
1983 IHTMLCommentElement_Release(comment);
1984 SysFreeString(text);
1987 #define create_attr(a,b) _create_attr(__LINE__,a,b)
1988 static IHTMLDOMAttribute *_create_attr(unsigned line, IUnknown *unk, const char *name)
1990 IHTMLDocument5 *doc = _get_htmldoc5_iface(line, unk);
1991 BSTR str = SysAllocString(L"Test");
1992 IHTMLDOMAttribute *attr;
1993 HRESULT hres;
1995 hres = IHTMLDocument5_createAttribute(doc, str, &attr);
1996 ok_(__FILE__,line)(hres == S_OK, "createAttribute failed: %08x\n", hres);
1997 SysFreeString(str);
1998 IHTMLDocument5_Release(doc);
2000 return attr;
2003 #define test_attr_specified(a,b) _test_attr_specified(__LINE__,a,b)
2004 static void _test_attr_specified(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
2006 VARIANT_BOOL specified;
2007 HRESULT hres;
2009 hres = IHTMLDOMAttribute_get_specified(attr, &specified);
2010 ok_(__FILE__,line)(hres == S_OK, "get_specified failed: %08x\n", hres);
2011 ok_(__FILE__,line)(specified == expected, "specified = %x, expected %x\n", specified, expected);
2014 #define test_attr_expando(a,b) _test_attr_expando(__LINE__,a,b)
2015 static void _test_attr_expando(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
2017 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
2018 VARIANT_BOOL expando;
2019 HRESULT hres;
2021 hres = IHTMLDOMAttribute2_get_expando(attr2, &expando);
2022 ok_(__FILE__,line)(hres == S_OK, "get_expando failed: %08x\n", hres);
2023 ok_(__FILE__,line)(expando == expected, "expando = %x, expected %x\n", expando, expected);
2025 IHTMLDOMAttribute2_Release(attr2);
2028 #define test_attr_value(a,b) _test_attr_value(__LINE__,a,b)
2029 static void _test_attr_value(unsigned line, IHTMLDOMAttribute *attr, const WCHAR *exval)
2031 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
2032 BSTR val;
2033 HRESULT hres;
2035 hres = IHTMLDOMAttribute2_get_value(attr2, &val);
2036 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
2037 if(exval)
2038 ok_(__FILE__,line)(!lstrcmpW(val, exval), "value = %s, expected %s\n", wine_dbgstr_w(val), wine_dbgstr_w(exval));
2039 else
2040 ok_(__FILE__,line)(!val, "value = %s, expected NULL\n", wine_dbgstr_w(val));
2042 IHTMLDOMAttribute2_Release(attr2);
2043 SysFreeString(val);
2046 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
2047 static void _test_comment_attrs(unsigned line, IUnknown *unk)
2049 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
2050 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
2051 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
2052 IHTMLDOMAttribute *attr;
2053 BSTR name = SysAllocString(L"test");
2054 VARIANT val;
2055 HRESULT hres;
2057 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
2058 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
2059 ok(attr == NULL, "attr != NULL\n");
2061 V_VT(&val) = VT_I4;
2062 V_I4(&val) = 1234;
2063 hres = IHTMLElement_setAttribute(elem, name, val, 0);
2064 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
2066 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
2067 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
2068 ok(attr != NULL, "attr == NULL\n");
2070 test_attr_expando(attr, VARIANT_TRUE);
2072 IHTMLDOMAttribute_Release(attr);
2073 IHTMLCommentElement_Release(comment);
2074 IHTMLElement_Release(elem);
2075 IHTMLElement4_Release(elem4);
2076 SysFreeString(name);
2079 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
2080 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
2082 IHTMLObjectElement *object = _get_object_iface(line, unk);
2083 LONG l;
2084 HRESULT hres;
2086 l = 0xdeadbeef;
2087 hres = IHTMLObjectElement_get_vspace(object, &l);
2088 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
2089 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
2090 IHTMLObjectElement_Release(object);
2093 #define test_object_name(a,b) _test_object_name(__LINE__,a,b)
2094 static void _test_object_name(unsigned line, IHTMLElement *elem, const WCHAR *exname)
2096 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
2097 BSTR str;
2098 HRESULT hres;
2100 str = (void*)0xdeadbeef;
2101 hres = IHTMLObjectElement_get_name(object, &str);
2102 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
2103 if(exname)
2104 ok_(__FILE__,line)(!lstrcmpW(str, exname), "name=%s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exname));
2105 else
2106 ok_(__FILE__,line)(!str, "name=%s, expected NULL\n", wine_dbgstr_w(str));
2107 SysFreeString(str);
2108 IHTMLObjectElement_Release(object);
2111 #define set_object_name(a,b) _set_object_name(__LINE__,a,b)
2112 static void _set_object_name(unsigned line, IHTMLElement *elem, const WCHAR *name)
2114 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
2115 BSTR str;
2116 HRESULT hres;
2118 str = SysAllocString(name);
2119 hres = IHTMLObjectElement_put_name(object, str);
2120 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
2121 SysFreeString(str);
2122 IHTMLObjectElement_Release(object);
2124 _test_object_name(line, elem, name);
2127 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
2128 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
2129 const WCHAR *txt, const WCHAR *val)
2131 IHTMLOptionElementFactory *factory;
2132 IHTMLOptionElement *option;
2133 IHTMLWindow2 *window;
2134 VARIANT text, value, empty;
2135 HRESULT hres;
2137 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2138 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2140 hres = IHTMLWindow2_get_Option(window, &factory);
2141 IHTMLWindow2_Release(window);
2142 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
2144 test_disp((IUnknown*)factory, &IID_IHTMLOptionElementFactory, NULL, L"[object]");
2146 V_VT(&text) = VT_BSTR;
2147 V_BSTR(&text) = SysAllocString(txt);
2148 V_VT(&value) = VT_BSTR;
2149 V_BSTR(&value) = SysAllocString(val);
2150 V_VT(&empty) = VT_EMPTY;
2152 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
2153 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
2155 IHTMLOptionElementFactory_Release(factory);
2156 VariantClear(&text);
2157 VariantClear(&value);
2159 _test_option_text(line, option, txt);
2160 _test_option_value(line, option, val);
2161 _test_option_selected(line, option, VARIANT_FALSE);
2163 return option;
2166 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
2167 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
2169 LONG found = -1;
2170 HRESULT hres;
2172 hres = IHTMLImgElement_get_width(img, &found);
2173 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
2174 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
2177 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
2178 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
2180 HRESULT hres;
2182 hres = IHTMLImgElement_put_width(img, width);
2183 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2185 _test_img_width(line, img, width);
2188 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
2189 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
2191 LONG found = -1;
2192 HRESULT hres;
2194 hres = IHTMLImgElement_get_height(img, &found);
2195 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
2196 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
2199 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
2200 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
2202 HRESULT hres;
2204 hres = IHTMLImgElement_put_height(img, height);
2205 ok(hres == S_OK, "put_height failed: %08x\n", hres);
2207 _test_img_height(line, img, height);
2210 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
2211 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
2212 LONG wdth, LONG hght)
2214 IHTMLImageElementFactory *factory;
2215 IHTMLImgElement *img;
2216 IHTMLWindow2 *window;
2217 VARIANT width, height;
2218 WCHAR buf[16];
2219 HRESULT hres;
2221 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2222 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2224 hres = IHTMLWindow2_get_Image(window, &factory);
2225 IHTMLWindow2_Release(window);
2226 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
2228 test_ifaces((IUnknown*)factory, img_factory_iids);
2229 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, NULL, L"[object]");
2231 if(wdth >= 0){
2232 wsprintfW(buf, L"%d", wdth);
2233 V_VT(&width) = VT_BSTR;
2234 V_BSTR(&width) = SysAllocString(buf);
2235 }else{
2236 V_VT(&width) = VT_EMPTY;
2237 wdth = 0;
2240 if(hght >= 0){
2241 wsprintfW(buf, L"%d", hght);
2242 V_VT(&height) = VT_BSTR;
2243 V_BSTR(&height) = SysAllocString(buf);
2244 }else{
2245 V_VT(&height) = VT_EMPTY;
2246 hght = 0;
2249 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
2250 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
2252 IHTMLImageElementFactory_Release(factory);
2253 VariantClear(&width);
2254 VariantClear(&height);
2256 if(SUCCEEDED(hres)) {
2257 _test_img_width(line, img, wdth);
2258 _test_img_height(line, img, hght);
2259 return img;
2262 return NULL;
2265 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
2266 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
2268 LONG len = 0xdeadbeef;
2269 HRESULT hres;
2271 hres = IHTMLSelectElement_get_length(select, &len);
2272 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2273 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
2276 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
2277 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
2279 IHTMLSelectElement *select = _get_select_iface(line, unk);
2280 HRESULT hres;
2282 hres = IHTMLSelectElement_put_length(select, length);
2283 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
2284 _test_select_length(line, select, length);
2285 IHTMLSelectElement_Release(select);
2288 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
2289 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
2291 LONG idx = 0xdeadbeef;
2292 HRESULT hres;
2294 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
2295 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
2296 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
2299 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
2300 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
2302 HRESULT hres;
2304 hres = IHTMLSelectElement_put_selectedIndex(select, index);
2305 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
2306 _test_select_selidx(line, select, index);
2309 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
2310 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const WCHAR *exval)
2312 BSTR val;
2313 HRESULT hres;
2315 hres = IHTMLSelectElement_get_value(select, &val);
2316 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2317 if(exval)
2318 ok_(__FILE__,line) (!lstrcmpW(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
2319 else
2320 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
2321 SysFreeString(val);
2324 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
2325 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const WCHAR *val)
2327 BSTR bstr;
2328 HRESULT hres;
2330 bstr = SysAllocString(val);
2331 hres = IHTMLSelectElement_put_value(select, bstr);
2332 SysFreeString(bstr);
2333 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
2336 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
2337 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const WCHAR *extype)
2339 BSTR type;
2340 HRESULT hres;
2342 hres = IHTMLSelectElement_get_type(select, &type);
2343 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2344 ok_(__FILE__,line) (!lstrcmpW(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), wine_dbgstr_w(extype));
2345 SysFreeString(type);
2348 #define test_select_multiple(s,t) _test_select_multiple(__LINE__,s,t)
2349 static void _test_select_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exmultiple)
2351 VARIANT_BOOL b = 100;
2352 HRESULT hres;
2354 hres = IHTMLSelectElement_get_multiple(select, &b);
2355 ok_(__FILE__,line) (hres == S_OK, "get_multiple failed: %08x\n", hres);
2356 ok_(__FILE__,line) (b == exmultiple, "multiple=%x, expected %x\n", b, exmultiple);
2359 #define test_select_set_multiple(s,v) _test_select_set_multiple(__LINE__,s,v)
2360 static void _test_select_set_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL val)
2362 HRESULT hres;
2364 hres = IHTMLSelectElement_put_multiple(select, val);
2365 ok_(__FILE__,line) (hres == S_OK, "put_multiple failed: %08x\n", hres);
2367 _test_select_multiple(line, select, val);
2370 #define test_select_size(s,v) _test_select_size(__LINE__,s,v)
2371 static void _test_select_size(unsigned line, IHTMLSelectElement *select, LONG exval)
2373 HRESULT hres;
2374 LONG val;
2376 hres = IHTMLSelectElement_get_size(select, NULL);
2377 ok_(__FILE__,line) (hres == E_INVALIDARG, "got %08x, expected E_INVALIDARG\n", hres);
2379 val = 0xdeadbeef;
2380 hres = IHTMLSelectElement_get_size(select, &val);
2381 ok_(__FILE__,line) (hres == S_OK, "get_size failed: %08x\n", hres);
2382 ok_(__FILE__,line) (val == exval, "size = %d, expected %d\n", val, exval);
2385 #define test_select_set_size(s,v,e) _test_select_set_size(__LINE__,s,v,e)
2386 static void _test_select_set_size(unsigned line, IHTMLSelectElement *select, LONG val, HRESULT exhres)
2388 HRESULT hres;
2390 hres = IHTMLSelectElement_put_size(select, val);
2391 ok_(__FILE__,line) (hres == exhres, "put_size(%d) got %08x, expect %08x\n", val, hres, exhres);
2394 #define test_select_name(s,v) _test_select_name(__LINE__,s,v)
2395 static void _test_select_name(unsigned line, IHTMLSelectElement *select, const WCHAR *extext)
2397 HRESULT hres;
2398 BSTR text;
2400 text = NULL;
2401 hres = IHTMLSelectElement_get_name(select, &text);
2402 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
2403 if(extext) {
2404 ok_(__FILE__,line) (text != NULL, "text == NULL\n");
2405 ok_(__FILE__,line) (!lstrcmpW(text, extext), "name = %s, expected %s\n",
2406 wine_dbgstr_w(text), wine_dbgstr_w(extext));
2407 SysFreeString(text);
2408 } else
2409 ok_(__FILE__,line) (text == NULL, "text(%p) = %s\n", text, wine_dbgstr_w(text));
2412 #define test_select_set_name(s,v) _test_select_set_name(__LINE__,s,v)
2413 static void _test_select_set_name(unsigned line, IHTMLSelectElement *select, const WCHAR *text)
2415 HRESULT hres;
2416 BSTR bstr;
2418 bstr = SysAllocString(text);
2420 hres = IHTMLSelectElement_put_name(select, bstr);
2421 ok_(__FILE__,line) (hres == S_OK, "put_name(%s) failed: %08x\n", wine_dbgstr_w(bstr), hres);
2422 SysFreeString(bstr);
2425 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
2426 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const WCHAR *extext)
2428 BSTR text;
2429 HRESULT hres;
2431 hres = IHTMLTxtRange_get_text(range, &text);
2432 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
2434 if(extext) {
2435 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
2436 ok_(__FILE__, line) (!lstrcmpW(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), wine_dbgstr_w(extext));
2437 }else {
2438 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
2441 SysFreeString(text);
2445 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
2446 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
2448 HRESULT hres;
2450 hres = IHTMLTxtRange_collapse(range, b);
2451 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
2452 _test_range_text(line, range, NULL);
2455 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
2456 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
2457 VARIANT_BOOL exb, const WCHAR *extext)
2459 VARIANT_BOOL b = 0xe0e0;
2460 HRESULT hres;
2462 hres = IHTMLTxtRange_expand(range, unit, &b);
2463 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
2464 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
2465 _test_range_text(line, range, extext);
2468 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
2469 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2471 LONG c = 0xdeadbeef;
2472 HRESULT hres;
2474 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
2475 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2476 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2477 _test_range_text(line, range, NULL);
2480 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
2481 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
2482 LPWSTR unit, LONG cnt, LONG excnt)
2484 LONG c = 0xdeadbeef;
2485 HRESULT hres;
2487 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
2488 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2489 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2492 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
2493 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2495 LONG c = 0xdeadbeef;
2496 HRESULT hres;
2498 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
2499 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2500 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2503 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
2504 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const WCHAR *text)
2506 HRESULT hres;
2507 BSTR bstr = SysAllocString(text);
2509 hres = IHTMLTxtRange_put_text(range, bstr);
2510 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
2511 SysFreeString(bstr);
2512 _test_range_text(line, range, NULL);
2515 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
2516 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2518 VARIANT_BOOL b;
2519 HRESULT hres;
2521 b = 0xe0e0;
2522 hres = IHTMLTxtRange_inRange(range1, range2, &b);
2523 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2524 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2527 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
2528 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2530 VARIANT_BOOL b;
2531 HRESULT hres;
2533 b = 0xe0e0;
2534 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
2535 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2536 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2538 b = 0xe0e0;
2539 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
2540 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
2541 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
2543 if(exb) {
2544 test_range_inrange(range1, range2, VARIANT_TRUE);
2545 test_range_inrange(range2, range1, VARIANT_TRUE);
2549 #define test_range_paste_html(a,b) _test_range_paste_html(__LINE__,a,b)
2550 static void _test_range_paste_html(unsigned line, IHTMLTxtRange *range, const WCHAR *html)
2552 BSTR str = SysAllocString(html);
2553 HRESULT hres;
2555 hres = IHTMLTxtRange_pasteHTML(range, str);
2556 ok_(__FILE__,line)(hres == S_OK, "pasteHTML failed: %08x\n", hres);
2557 SysFreeString(str);
2560 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
2561 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
2563 IHTMLElement *elem;
2564 HRESULT hres;
2566 hres = IHTMLTxtRange_parentElement(range, &elem);
2567 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
2569 _test_elem_type(line, (IUnknown*)elem, type);
2571 IHTMLElement_Release(elem);
2574 #define get_elem_col_item_idx(a,b) _get_elem_col_item_idx(__LINE__,a,b)
2575 static IHTMLElement *_get_elem_col_item_idx(unsigned line, IHTMLElementCollection *col, int i)
2577 VARIANT name, index;
2578 IHTMLElement *elem;
2579 IDispatch *disp;
2580 HRESULT hres;
2582 V_VT(&index) = VT_EMPTY;
2583 V_VT(&name) = VT_I4;
2584 V_I4(&name) = i;
2585 hres = IHTMLElementCollection_item(col, name, index, &disp);
2586 ok_(__FILE__,line)(hres == S_OK, "item failed: %08x\n", hres);
2587 ok_(__FILE__,line)(disp != NULL, "disp == NULL\n");
2589 elem = _get_elem_iface(line, (IUnknown*)disp);
2590 IDispatch_Release(disp);
2591 return elem;
2594 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
2595 static void _test_elem_collection(unsigned line, IUnknown *unk,
2596 const elem_type_t *elem_types, LONG exlen)
2598 IHTMLElementCollection *col;
2599 IEnumVARIANT *enum_var;
2600 IUnknown *enum_unk;
2601 ULONG fetched;
2602 LONG len;
2603 DWORD i;
2604 VARIANT name, index, v, vs[5];
2605 IDispatch *disp, *disp2;
2606 HRESULT hres;
2608 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
2609 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2611 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, NULL, L"[object]");
2613 hres = IHTMLElementCollection_get_length(col, &len);
2614 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2615 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
2617 if(len > exlen)
2618 len = exlen;
2620 V_VT(&index) = VT_EMPTY;
2622 hres = IHTMLElementCollection_get__newEnum(col, &enum_unk);
2623 ok_(__FILE__,line)(hres == S_OK, "_newEnum failed: %08x\n", hres);
2625 hres = IUnknown_QueryInterface(enum_unk, &IID_IEnumVARIANT, (void**)&enum_var);
2626 IUnknown_Release(enum_unk);
2627 ok_(__FILE__,line)(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
2629 for(i=0; i<len; i++) {
2630 V_VT(&name) = VT_I4;
2631 V_I4(&name) = i;
2632 disp = (void*)0xdeadbeef;
2633 hres = IHTMLElementCollection_item(col, name, index, &disp);
2634 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2635 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
2636 if(FAILED(hres) || !disp)
2637 continue;
2639 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
2641 if(!i) {
2642 V_VT(&name) = VT_UINT;
2643 V_I4(&name) = 0;
2644 disp2 = (void*)0xdeadbeef;
2645 hres = IHTMLElementCollection_item(col, name, index, &disp2);
2646 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2647 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
2648 if(disp2)
2649 IDispatch_Release(disp2);
2652 fetched = 0;
2653 V_VT(&v) = VT_ERROR;
2654 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
2655 ok_(__FILE__,line)(hres == S_OK, "Next failed: %08x\n", hres);
2656 if(i)
2657 ok_(__FILE__,line)(fetched == 1, "fetched = %d\n", fetched);
2658 ok_(__FILE__,line)(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
2659 ok_(__FILE__,line)(iface_cmp((IUnknown*)disp, (IUnknown*)V_DISPATCH(&v)), "disp != V_DISPATCH(v)\n");
2660 IDispatch_Release(V_DISPATCH(&v));
2662 IDispatch_Release(disp);
2665 fetched = 0xdeadbeef;
2666 V_VT(&v) = VT_BOOL;
2667 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
2668 ok_(__FILE__,line)(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
2669 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2670 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2672 hres = IEnumVARIANT_Reset(enum_var);
2673 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2675 fetched = 0xdeadbeef;
2676 V_VT(&v) = VT_BOOL;
2677 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
2678 ok_(__FILE__,line)(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
2679 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2680 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2682 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
2683 ok_(__FILE__,line)(hres == S_OK, "Skip failed: %08x\n", hres);
2685 memset(vs, 0, sizeof(vs));
2686 fetched = 0;
2687 hres = IEnumVARIANT_Next(enum_var, ARRAY_SIZE(vs), vs, &fetched);
2688 ok_(__FILE__,line)(hres == S_FALSE, "Next failed: %08x\n", hres);
2689 ok_(__FILE__,line)(fetched == (len > 2 ? 2 : len), "fetched = %d\n", fetched);
2690 if(len) {
2691 ok_(__FILE__,line)(V_VT(vs) == VT_DISPATCH && V_DISPATCH(vs), "V_VT(vs[0]) = %d\n", V_VT(vs));
2692 IDispatch_Release(V_DISPATCH(vs));
2694 if(len > 1) {
2695 ok_(__FILE__,line)(V_VT(vs+1) == VT_DISPATCH && V_DISPATCH(vs+1), "V_VT(vs[1]) = %d\n", V_VT(vs+1));
2696 IDispatch_Release(V_DISPATCH(vs+1));
2699 hres = IEnumVARIANT_Reset(enum_var);
2700 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2702 hres = IEnumVARIANT_Skip(enum_var, len+1);
2703 ok_(__FILE__,line)(hres == S_FALSE, "Skip failed: %08x\n", hres);
2705 IEnumVARIANT_Release(enum_var);
2707 V_VT(&name) = VT_I4;
2708 V_I4(&name) = len;
2709 disp = (void*)0xdeadbeef;
2710 hres = IHTMLElementCollection_item(col, name, index, &disp);
2711 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2712 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2714 V_VT(&name) = VT_UI4;
2715 V_I4(&name) = len;
2716 disp = (void*)0xdeadbeef;
2717 hres = IHTMLElementCollection_item(col, name, index, &disp);
2718 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2719 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2721 V_VT(&name) = VT_INT;
2722 V_I4(&name) = len;
2723 disp = (void*)0xdeadbeef;
2724 hres = IHTMLElementCollection_item(col, name, index, &disp);
2725 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2726 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2728 V_VT(&name) = VT_UINT;
2729 V_I4(&name) = len;
2730 disp = (void*)0xdeadbeef;
2731 hres = IHTMLElementCollection_item(col, name, index, &disp);
2732 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2733 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2735 V_VT(&name) = VT_I4;
2736 V_I4(&name) = -1;
2737 disp = (void*)0xdeadbeef;
2738 hres = IHTMLElementCollection_item(col, name, index, &disp);
2739 if(compat_mode < COMPAT_IE9)
2740 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2741 else
2742 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2743 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2745 IHTMLElementCollection_Release(col);
2748 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
2749 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
2751 IHTMLElement *elem = _get_elem_iface(line, unk);
2752 IDispatch *disp;
2753 HRESULT hres;
2755 hres = IHTMLElement_get_all(elem, &disp);
2756 IHTMLElement_Release(elem);
2757 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2759 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
2760 IDispatch_Release(disp);
2763 #define test_doc_all(a,b,c) _test_doc_all(__LINE__,a,b,c)
2764 static void _test_doc_all(unsigned line, IHTMLDocument2 *doc, const elem_type_t *elem_types, LONG exlen)
2766 IHTMLElementCollection *col;
2767 HRESULT hres;
2769 hres = IHTMLDocument2_get_all(doc, &col);
2770 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2772 _test_elem_collection(line, (IUnknown*)col, elem_types, exlen);
2773 IHTMLElementCollection_Release(col);
2776 #define test_children_collection_length(a,b) _test_children_collection_length(__LINE__,a,b)
2777 static LONG _test_children_collection_length(unsigned line, IHTMLDOMChildrenCollection *collection, LONG exlen)
2779 LONG length;
2780 HRESULT hres;
2782 hres = IHTMLDOMChildrenCollection_get_length(collection, &length);
2783 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2784 if(exlen != -1)
2785 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
2787 return length;
2790 #define test_elem_getelembytag(a,b,c,d) _test_elem_getelembytag(__LINE__,a,b,c,d)
2791 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen, IHTMLElement **ret)
2793 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2794 IHTMLElementCollection *col = NULL;
2795 elem_type_t *types = NULL;
2796 BSTR tmp;
2797 int i;
2798 HRESULT hres;
2800 tmp = SysAllocString(elem_type_infos[type].tag);
2801 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
2802 SysFreeString(tmp);
2803 IHTMLElement2_Release(elem);
2804 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
2805 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
2807 if(exlen) {
2808 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
2809 for(i=0; i<exlen; i++)
2810 types[i] = type;
2813 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2815 HeapFree(GetProcessHeap(), 0, types);
2817 if(ret)
2818 *ret = get_elem_col_item_idx(col, 0);
2819 IHTMLElementCollection_Release(col);
2822 #define test_doc_getelembytag(a,b,c,d) _test_doc_getelembytag(__LINE__,a,b,c,d)
2823 static void _test_doc_getelembytag(unsigned line, IHTMLDocument2 *unk, const char *tag, elem_type_t type, LONG exlen)
2825 IHTMLDocument3 *doc = _get_doc3_iface(line, unk);
2826 IHTMLElementCollection *col = NULL;
2827 elem_type_t *types = NULL;
2828 BSTR tmp;
2829 int i;
2830 HRESULT hres;
2832 tmp = SysAllocString(elem_type_infos[type].tag);
2833 hres = IHTMLDocument3_getElementsByTagName(doc, tmp, &col);
2834 SysFreeString(tmp);
2835 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
2836 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
2838 if(exlen) {
2839 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
2840 for(i=0; i<exlen; i++)
2841 types[i] = type;
2844 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2846 HeapFree(GetProcessHeap(), 0, types);
2847 IHTMLElementCollection_Release(col);
2848 IHTMLDocument3_Release(doc);
2851 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
2852 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const WCHAR *extext)
2854 BSTR text = NULL;
2855 HRESULT hres;
2857 hres = IHTMLElement_get_innerText(elem, &text);
2858 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
2859 if(extext)
2860 ok_(__FILE__,line) (!lstrcmpW(text, extext), "get_innerText returned %s expected %s\n",
2861 wine_dbgstr_w(text), wine_dbgstr_w(extext));
2862 else
2863 ok_(__FILE__,line) (!text, "get_innerText returned %s expected NULL\n", wine_dbgstr_w(text));
2864 SysFreeString(text);
2867 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
2868 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const WCHAR *text)
2870 IHTMLDOMChildrenCollection *col;
2871 BSTR str;
2872 HRESULT hres;
2874 str = SysAllocString(text);
2875 hres = IHTMLElement_put_innerText(elem, str);
2876 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
2877 SysFreeString(str);
2879 _test_elem_innertext(line, elem, text);
2882 col = _get_child_nodes(line, (IUnknown*)elem);
2883 ok(col != NULL, "col == NULL\n");
2884 if(col) {
2885 LONG type;
2886 IHTMLDOMNode *node;
2888 _test_children_collection_length(line, col, 1);
2890 node = _get_child_item(line, col, 0);
2891 ok(node != NULL, "node == NULL\n");
2892 if(node) {
2893 type = _get_node_type(line, (IUnknown*)node);
2894 ok(type == 3, "type=%d\n", type);
2895 IHTMLDOMNode_Release(node);
2898 IHTMLDOMChildrenCollection_Release(col);
2903 #define test_elem_outertext(e,t) _test_elem_outertext(__LINE__,e,t)
2904 static void _test_elem_outertext(unsigned line, IHTMLElement *elem, const WCHAR *extext)
2906 BSTR text = NULL;
2907 HRESULT hres;
2909 hres = IHTMLElement_get_outerText(elem, &text);
2910 ok_(__FILE__,line) (hres == S_OK, "get_outerText failed: %08x\n", hres);
2911 if(extext)
2912 ok_(__FILE__,line) (!lstrcmpW(text, extext), "get_outerText returned %s expected %s\n",
2913 wine_dbgstr_w(text), wine_dbgstr_w(extext));
2914 else
2915 ok_(__FILE__,line) (!text, "get_outerText returned %s expected NULL\n", wine_dbgstr_w(text));
2916 SysFreeString(text);
2919 #define test_elem_set_outertext(e,t) _test_elem_set_outertext(__LINE__,e,t)
2920 static void _test_elem_set_outertext(unsigned line, IHTMLElement *elem, const WCHAR *text)
2922 BSTR str = SysAllocString(text);
2923 HRESULT hres;
2925 hres = IHTMLElement_put_outerText(elem, str);
2926 ok_(__FILE__,line) (hres == S_OK, "put_outerText failed: %08x\n", hres);
2927 SysFreeString(str);
2930 #define test_elem_set_outertext_fail(a) _test_elem_set_outertext_fail(__LINE__,a)
2931 static void _test_elem_set_outertext_fail(unsigned line, IHTMLElement *elem)
2933 BSTR str = SysAllocString(L"test");
2934 HRESULT hres;
2936 hres = IHTMLElement_put_outerText(elem, str);
2937 ok_(__FILE__,line) (hres == 0x800a0258, "put_outerText failed: %08x\n", hres);
2938 SysFreeString(str);
2941 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2942 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const WCHAR *inner_html)
2944 IHTMLElement *elem = _get_elem_iface(line, unk);
2945 BSTR html;
2946 HRESULT hres;
2948 hres = IHTMLElement_get_innerHTML(elem, &html);
2949 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2950 if(inner_html)
2951 ok_(__FILE__,line)(!lstrcmpW(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2952 else
2953 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2955 IHTMLElement_Release(elem);
2956 SysFreeString(html);
2959 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2960 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const WCHAR *inner_html)
2962 IHTMLElement *elem = _get_elem_iface(line, unk);
2963 BSTR html;
2964 HRESULT hres;
2966 html = SysAllocString(inner_html);
2967 hres = IHTMLElement_put_innerHTML(elem, html);
2968 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2970 IHTMLElement_Release(elem);
2971 SysFreeString(html);
2974 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2975 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const WCHAR *outer_html)
2977 IHTMLElement *elem = _get_elem_iface(line, unk);
2978 BSTR html;
2979 HRESULT hres;
2981 html = SysAllocString(outer_html);
2982 hres = IHTMLElement_put_outerHTML(elem, html);
2983 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2985 IHTMLElement_Release(elem);
2986 SysFreeString(html);
2989 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2990 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const WCHAR *outer_html)
2992 IHTMLElement *elem = _get_elem_iface(line, unk);
2993 const WCHAR *p;
2994 BSTR html;
2995 HRESULT hres;
2997 hres = IHTMLElement_get_outerHTML(elem, &html);
2998 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2999 if((p = wcsstr(outer_html, L"-->")) && !p[3] && SysStringLen(html) == p - outer_html) /* Some IEs drop comment ending */
3000 ok_(__FILE__,line)(!wcsncmp(html, outer_html, p - outer_html), "text = \"%s\", expected \"%s\"\n",
3001 wine_dbgstr_w(html), wine_dbgstr_w(outer_html));
3002 else
3003 ok_(__FILE__,line)(!lstrcmpW(html, outer_html), "outerHTML = %s, expected %s\n", wine_dbgstr_w(html), wine_dbgstr_w(outer_html));
3005 IHTMLElement_Release(elem);
3006 SysFreeString(html);
3009 #define test_elem_contains(a,b,c) _test_elem_contains(__LINE__,a,b,c)
3010 static void _test_elem_contains(unsigned line, IHTMLElement *elem, IHTMLElement *elem2, VARIANT_BOOL exval)
3012 VARIANT_BOOL b;
3013 HRESULT hres;
3015 b = 100;
3016 hres = IHTMLElement_contains(elem, elem2, &b);
3017 ok_(__FILE__,line)(hres == S_OK, "contains failed: %08x\n", hres);
3018 ok_(__FILE__,line)(b == exval, "contains returned %x, expected %x\n", b, exval);
3021 #define test_elem_istextedit(a,b) _test_elem_istextedit(__LINE__,a,b)
3022 static void _test_elem_istextedit(unsigned line, IHTMLElement *elem, VARIANT_BOOL exval)
3024 VARIANT_BOOL b;
3025 HRESULT hres;
3027 b = 100;
3028 hres = IHTMLElement_get_isTextEdit(elem, &b);
3029 ok_(__FILE__,line)(hres == S_OK, "isTextEdit failed: %08x\n", hres);
3030 ok_(__FILE__,line)(b == exval, "isTextEdit = %x\n", b);
3033 #define get_first_child(n) _get_first_child(__LINE__,n)
3034 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
3036 IHTMLDOMNode *node = _get_node_iface(line, unk);
3037 IHTMLDOMNode *child = NULL;
3038 HRESULT hres;
3040 hres = IHTMLDOMNode_get_firstChild(node, &child);
3041 IHTMLDOMNode_Release(node);
3042 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
3044 return child;
3047 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
3048 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
3050 IHTMLDOMNode *node = _get_node_iface(line, unk);
3051 VARIANT_BOOL b = 0xdead;
3052 HRESULT hres;
3054 hres = IHTMLDOMNode_hasChildNodes(node, &b);
3055 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
3056 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
3058 IHTMLDOMNode_Release(node);
3061 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
3062 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
3064 IHTMLDOMNode *node = _get_node_iface(line, unk);
3065 IHTMLDOMNode *parent;
3066 HRESULT hres;
3068 hres = IHTMLDOMNode_get_parentNode(node, &parent);
3069 IHTMLDOMNode_Release(node);
3070 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
3072 return parent;
3075 #define node_get_next(u) _node_get_next(__LINE__,u)
3076 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
3078 IHTMLDOMNode *node = _get_node_iface(line, unk);
3079 IHTMLDOMNode *next;
3080 HRESULT hres;
3082 hres = IHTMLDOMNode_get_nextSibling(node, &next);
3083 IHTMLDOMNode_Release(node);
3084 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
3086 return next;
3089 #define node_get_prev(u) _node_get_prev(__LINE__,u)
3090 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
3092 IHTMLDOMNode *node = _get_node_iface(line, unk);
3093 IHTMLDOMNode *prev;
3094 HRESULT hres;
3096 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
3097 IHTMLDOMNode_Release(node);
3098 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
3100 return prev;
3103 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
3104 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
3106 IHTMLElement *elem = _get_elem_iface(line, unk);
3107 IHTMLElement *parent;
3108 HRESULT hres;
3110 hres = IHTMLElement_get_parentElement(elem, &parent);
3111 IHTMLElement_Release(elem);
3112 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
3114 return parent;
3117 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
3118 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
3120 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
3121 VARIANT_BOOL disabled = 100;
3122 HRESULT hres;
3124 if (!elem3) return;
3125 hres = IHTMLElement3_get_disabled(elem3, &disabled);
3126 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3127 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3128 IHTMLElement3_Release(elem3);
3131 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
3132 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
3134 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
3135 HRESULT hres;
3137 if (!elem3) return;
3138 hres = IHTMLElement3_put_disabled(elem3, b);
3139 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3141 IHTMLElement3_Release(elem3);
3142 _test_elem3_get_disabled(line, unk, b);
3145 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
3146 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
3148 VARIANT_BOOL disabled = 100;
3149 HRESULT hres;
3151 hres = IHTMLSelectElement_get_disabled(select, &disabled);
3152 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3153 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3155 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
3158 static void test_select_remove(IHTMLSelectElement *select)
3160 HRESULT hres;
3162 hres = IHTMLSelectElement_remove(select, 3);
3163 ok(hres == S_OK, "remove failed: %08x, expected S_OK\n", hres);
3164 test_select_length(select, 2);
3166 hres = IHTMLSelectElement_remove(select, -1);
3167 ok(hres == E_INVALIDARG, "remove failed: %08x, expected E_INVALIDARG\n", hres);
3168 test_select_length(select, 2);
3170 hres = IHTMLSelectElement_remove(select, 0);
3171 ok(hres == S_OK, "remove failed:%08x\n", hres);
3172 test_select_length(select, 1);
3175 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
3176 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
3178 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
3179 LONG length;
3180 HRESULT hres;
3182 hres = IHTMLDOMTextNode_get_length(text, &length);
3183 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
3184 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
3185 IHTMLDOMTextNode_Release(text);
3188 #define test_text_data(a,b) _test_text_data(__LINE__,a,b)
3189 static void _test_text_data(unsigned line, IUnknown *unk, const WCHAR *exdata)
3191 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
3192 BSTR str;
3193 HRESULT hres;
3195 hres = IHTMLDOMTextNode_get_data(text, &str);
3196 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
3197 ok_(__FILE__,line)(!lstrcmpW(str, exdata), "data = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exdata));
3198 IHTMLDOMTextNode_Release(text);
3199 SysFreeString(str);
3202 #define set_text_data(a,b) _set_text_data(__LINE__,a,b)
3203 static void _set_text_data(unsigned line, IUnknown *unk, const WCHAR *data)
3205 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
3206 BSTR str = SysAllocString(data);
3207 HRESULT hres;
3209 hres = IHTMLDOMTextNode_put_data(text, str);
3210 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
3211 IHTMLDOMTextNode_Release(text);
3212 SysFreeString(str);
3215 #define text_append_data(a,b) _text_append_data(__LINE__,a,b)
3216 static void _text_append_data(unsigned line, IUnknown *unk, const WCHAR *data)
3218 IHTMLDOMTextNode2 *text = _get_text2_iface(line, unk);
3219 BSTR str = SysAllocString(data);
3220 HRESULT hres;
3222 hres = IHTMLDOMTextNode2_appendData(text, str);
3223 ok_(__FILE__,line)(hres == S_OK, "appendData failed: %08x\n", hres);
3224 IHTMLDOMTextNode2_Release(text);
3225 SysFreeString(str);
3228 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
3229 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
3231 HRESULT hres;
3233 hres = IHTMLSelectElement_put_disabled(select, b);
3234 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3236 _test_select_get_disabled(line, select, b);
3239 #define test_elem_dir(u,n) _test_elem_dir(__LINE__,u,n)
3240 static void _test_elem_dir(unsigned line, IUnknown *unk, const WCHAR *exdir)
3242 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3243 BSTR dir;
3244 HRESULT hres;
3246 hres = IHTMLElement2_get_dir(elem, &dir);
3247 IHTMLElement2_Release(elem);
3248 ok_(__FILE__, line) (hres == S_OK, "get_dir failed: %08x\n", hres);
3249 if(exdir)
3250 ok_(__FILE__, line) (!lstrcmpW(dir, exdir), "got dir: %s, expected %s\n", wine_dbgstr_w(dir), wine_dbgstr_w(exdir));
3251 else
3252 ok_(__FILE__, line) (!dir, "got dir: %s, expected NULL\n", wine_dbgstr_w(dir));
3254 SysFreeString(dir);
3257 #define set_elem_dir(u,n) _set_elem_dir(__LINE__,u,n)
3258 static void _set_elem_dir(unsigned line, IUnknown *unk, const WCHAR *d)
3260 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3261 BSTR dir = SysAllocString(d);
3262 HRESULT hres;
3264 hres = IHTMLElement2_put_dir(elem, dir);
3265 IHTMLElement2_Release(elem);
3266 ok_(__FILE__, line) (hres == S_OK, "put_dir failed: %08x\n", hres);
3267 SysFreeString(dir);
3269 _test_elem_dir(line, unk, d);
3272 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
3273 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
3275 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3276 IHTMLTextContainer *txtcont;
3277 LONG l = -1, l2 = -1;
3278 HRESULT hres;
3280 hres = IHTMLElement2_get_scrollHeight(elem, &l);
3281 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
3282 IHTMLElement2_Release(elem);
3284 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3285 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3287 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
3288 IHTMLTextContainer_Release(txtcont);
3289 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
3290 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
3292 return l;
3295 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
3296 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
3298 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3299 IHTMLTextContainer *txtcont;
3300 LONG l = -1, l2 = -1;
3301 HRESULT hres;
3303 hres = IHTMLElement2_get_scrollWidth(elem, &l);
3304 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
3305 IHTMLElement2_Release(elem);
3307 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3308 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3310 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
3311 IHTMLTextContainer_Release(txtcont);
3312 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
3313 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
3315 return l;
3318 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
3319 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
3321 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3322 IHTMLTextContainer *txtcont;
3323 LONG l = -1, l2 = -1;
3324 HRESULT hres;
3326 hres = IHTMLElement2_get_scrollTop(elem, &l);
3327 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
3328 IHTMLElement2_Release(elem);
3330 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3331 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3333 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
3334 IHTMLTextContainer_Release(txtcont);
3335 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
3336 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
3338 return l;
3341 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
3342 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
3344 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3345 IHTMLTextContainer *txtcont;
3346 LONG l = -1, l2 = -1;
3347 HRESULT hres;
3349 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
3350 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
3352 hres = IHTMLElement2_get_scrollLeft(elem, &l);
3353 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
3354 IHTMLElement2_Release(elem);
3356 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3357 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3359 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
3360 IHTMLTextContainer_Release(txtcont);
3361 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
3362 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
3365 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
3366 static void _test_img_src(unsigned line, IUnknown *unk, const WCHAR *exsrc, const WCHAR *broken_src)
3368 IHTMLImgElement *img = _get_img_iface(line, unk);
3369 BSTR src;
3370 HRESULT hres;
3372 hres = IHTMLImgElement_get_src(img, &src);
3373 IHTMLImgElement_Release(img);
3374 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
3375 ok_(__FILE__,line) (!lstrcmpW(src, exsrc) || (broken_src && broken(!lstrcmpW(src, broken_src))),
3376 "get_src returned %s expected %s\n", wine_dbgstr_w(src), wine_dbgstr_w(exsrc));
3377 SysFreeString(src);
3380 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
3381 static void _test_img_set_src(unsigned line, IUnknown *unk, const WCHAR *src)
3383 IHTMLImgElement *img = _get_img_iface(line, unk);
3384 BSTR tmp;
3385 HRESULT hres;
3387 tmp = SysAllocString(src);
3388 hres = IHTMLImgElement_put_src(img, tmp);
3389 IHTMLImgElement_Release(img);
3390 SysFreeString(tmp);
3391 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
3394 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
3395 static void _test_img_alt(unsigned line, IUnknown *unk, const WCHAR *exalt)
3397 IHTMLImgElement *img = _get_img_iface(line, unk);
3398 BSTR alt;
3399 HRESULT hres;
3401 hres = IHTMLImgElement_get_alt(img, &alt);
3402 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
3403 if(exalt)
3404 ok_(__FILE__,line) (!lstrcmpW(alt, exalt), "unexpected alt %s\n", wine_dbgstr_w(alt));
3405 else
3406 ok_(__FILE__,line) (!alt, "alt != NULL\n");
3407 SysFreeString(alt);
3410 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
3411 static void _test_img_set_alt(unsigned line, IUnknown *unk, const WCHAR *alt)
3413 IHTMLImgElement *img = _get_img_iface(line, unk);
3414 BSTR tmp;
3415 HRESULT hres;
3417 tmp = SysAllocString(alt);
3418 hres = IHTMLImgElement_put_alt(img, tmp);
3419 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
3420 SysFreeString(tmp);
3422 _test_img_alt(line, unk, alt);
3425 #define test_img_align(u,a) _test_img_align(__LINE__,u,a)
3426 static void _test_img_align(unsigned line, IUnknown *unk, const WCHAR *align)
3428 IHTMLImgElement *img = _get_img_iface(line, unk);
3429 BSTR tmp;
3430 HRESULT hres;
3432 tmp = SysAllocString(align);
3433 hres = IHTMLImgElement_put_align(img, tmp);
3434 ok_(__FILE__,line) (hres == S_OK, "put_align failed: %08x\n", hres);
3435 SysFreeString(tmp);
3437 hres = IHTMLImgElement_get_align(img, &tmp);
3438 ok_(__FILE__,line) (hres == S_OK, "put_align failed: %08x\n", hres);
3439 ok_(__FILE__,line) (!lstrcmpW(tmp, align), "Expect %s, got %s\n", wine_dbgstr_w(align), wine_dbgstr_w(tmp));
3440 SysFreeString(tmp);
3443 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
3444 static void _test_img_name(unsigned line, IUnknown *unk, const WCHAR *pValue)
3446 IHTMLImgElement *img = _get_img_iface(line, unk);
3447 BSTR sName;
3448 HRESULT hres;
3450 hres = IHTMLImgElement_get_name(img, &sName);
3451 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
3452 ok_(__FILE__,line) (!lstrcmpW (sName, pValue), "expected %s got %s\n", wine_dbgstr_w(pValue), wine_dbgstr_w(sName));
3453 IHTMLImgElement_Release(img);
3454 SysFreeString(sName);
3457 #define test_img_complete(a,b) _test_img_complete(__LINE__,a,b)
3458 static void _test_img_complete(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
3460 IHTMLImgElement *img = _get_img_iface(line, (IUnknown*)elem);
3461 VARIANT_BOOL b = 100;
3462 HRESULT hres;
3464 hres = IHTMLImgElement_get_complete(img, &b);
3465 ok_(__FILE__,line) (hres == S_OK, "get_complete failed: %08x\n", hres);
3466 ok_(__FILE__,line) (b == exb, "complete = %x, expected %x\n", b, exb);
3467 IHTMLImgElement_Release(img);
3470 #define test_img_isMap(u, c) _test_img_isMap(__LINE__,u, c)
3471 static void _test_img_isMap(unsigned line, IUnknown *unk, VARIANT_BOOL v)
3473 IHTMLImgElement *img = _get_img_iface(line, unk);
3474 VARIANT_BOOL b = 100;
3475 HRESULT hres;
3477 hres = IHTMLImgElement_put_isMap(img, v);
3478 ok_(__FILE__,line) (hres == S_OK, "put_isMap failed: %08x\n", hres);
3480 hres = IHTMLImgElement_get_isMap(img, &b);
3481 ok_(__FILE__,line) (hres == S_OK, "get_isMap failed: %08x\n", hres);
3482 ok_(__FILE__,line) (b == v, "isMap = %x, expected %x\n", b, v);
3484 hres = IHTMLImgElement_get_isMap(img, NULL);
3485 ok_(__FILE__,line) (hres == E_INVALIDARG, "ret = %08x, expected E_INVALIDARG\n", hres);
3486 IHTMLImgElement_Release(img);
3489 static void test_dynamic_properties(IHTMLElement *elem)
3491 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
3492 IDispatchEx *dispex;
3493 BSTR name, attr1 = SysAllocString(attr1W);
3494 VARIANT_BOOL succ;
3495 VARIANT val;
3496 int checked_no = 0;
3497 DISPID id = DISPID_STARTENUM;
3498 HRESULT hres;
3500 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
3501 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3503 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
3504 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
3505 ok(succ, "removeAttribute set succ to FALSE\n");
3507 while(1) {
3508 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
3509 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
3510 if(hres != S_OK)
3511 break;
3513 hres = IDispatchEx_GetMemberName(dispex, id, &name);
3514 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
3516 if(!lstrcmpW(name, L"attr1"))
3517 ok(0, "attr1 should be removed\n");
3518 else if(!lstrcmpW(name, L"attr2") || !lstrcmpW(name, L"attr3"))
3519 checked_no++;
3520 SysFreeString(name);
3522 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
3523 IDispatchEx_Release(dispex);
3525 V_VT(&val) = VT_BSTR;
3526 V_BSTR(&val) = attr1;
3527 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
3528 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3529 SysFreeString(attr1);
3532 #define test_attr_node_name(a,b) _test_attr_node_name(__LINE__,a,b)
3533 static void _test_attr_node_name(unsigned line, IHTMLDOMAttribute *attr, const WCHAR *exname)
3535 BSTR str;
3536 HRESULT hres;
3538 hres = IHTMLDOMAttribute_get_nodeName(attr, &str);
3539 ok_(__FILE__,line)(hres == S_OK, "get_nodeName failed: %08x\n", hres);
3540 ok_(__FILE__,line)(!lstrcmpW(str, exname), "node name is %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exname));
3541 SysFreeString(str);
3544 #define test_attr_parent(a) _test_attr_parent(__LINE__,a)
3545 static void _test_attr_parent(unsigned line, IHTMLDOMAttribute *attr)
3547 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
3548 IHTMLDOMNode *parent = (void*)0xdeadbeef;
3549 HRESULT hres;
3551 hres = IHTMLDOMAttribute2_get_parentNode(attr2, &parent);
3552 ok_(__FILE__,line)(hres == S_OK, "get_parentNode failed: %08x\n", hres);
3553 ok_(__FILE__,line)(!parent, "parent != NULL\n");
3554 IHTMLDOMAttribute2_Release(attr2);
3557 static void test_attr_collection_disp(IDispatch *disp)
3559 IDispatchEx *dispex;
3560 IHTMLDOMAttribute *attr;
3561 DISPPARAMS dp = {NULL, NULL, 0, 0};
3562 VARIANT var;
3563 EXCEPINFO ei;
3564 DISPID id;
3565 BSTR bstr;
3566 HRESULT hres;
3568 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
3569 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3571 bstr = SysAllocString(L"0");
3572 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
3573 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
3574 SysFreeString(bstr);
3576 VariantInit(&var);
3577 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
3578 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
3579 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
3580 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
3581 VariantClear(&var);
3583 bstr = SysAllocString(L"attr1");
3584 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
3585 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
3586 SysFreeString(bstr);
3588 VariantInit(&var);
3589 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
3590 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
3591 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
3592 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
3593 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
3594 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3596 test_attr_node_name(attr, L"attr1");
3598 IHTMLDOMAttribute_Release(attr);
3599 VariantClear(&var);
3601 IDispatchEx_Release(dispex);
3604 static void test_attr_collection(IHTMLElement *elem)
3606 static const WCHAR testW[] = {'t','e','s','t',0};
3608 IHTMLDOMNode *node;
3609 IDispatch *disp, *attr;
3610 IHTMLDOMAttribute *dom_attr;
3611 IHTMLAttributeCollection *attr_col;
3612 BSTR name = SysAllocString(testW);
3613 VARIANT id, val;
3614 LONG i, len, checked;
3615 HRESULT hres;
3617 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
3618 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3620 hres = IHTMLDOMNode_get_attributes(node, &disp);
3621 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
3623 hres = IHTMLDOMNode_get_attributes(node, &attr);
3624 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
3625 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
3626 IDispatch_Release(attr);
3627 IHTMLDOMNode_Release(node);
3629 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
3630 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3632 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
3633 ok(hres == S_OK, "get_length failed: %08x\n", hres);
3635 V_VT(&val) = VT_I4;
3636 V_I4(&val) = 1;
3637 hres = IHTMLElement_setAttribute(elem, name, val, 0);
3638 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3639 SysFreeString(name);
3641 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
3642 ok(hres == S_OK, "get_length failed: %08x\n", hres);
3643 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
3645 checked = 0;
3646 for(i=0; i<len; i++) {
3647 V_VT(&id) = VT_I4;
3648 V_I4(&id) = i;
3649 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3650 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
3652 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
3653 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
3654 IDispatch_Release(attr);
3656 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
3657 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
3659 if(!lstrcmpW(name, L"id")) {
3660 checked++;
3661 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3662 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3663 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
3664 ok(!lstrcmpW(V_BSTR(&val), L"attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3665 test_attr_expando(dom_attr, VARIANT_FALSE);
3666 test_attr_value(dom_attr, L"attr");
3667 } else if(!lstrcmpW(name, L"attr1")) {
3668 checked++;
3669 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3670 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3671 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
3672 ok(!lstrcmpW(V_BSTR(&val), L"attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3673 test_attr_expando(dom_attr, VARIANT_TRUE);
3674 test_attr_value(dom_attr, L"attr1");
3675 } else if(!lstrcmpW(name, L"attr2")) {
3676 checked++;
3677 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3678 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3679 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
3680 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
3681 test_attr_value(dom_attr, L"");
3682 } else if(!lstrcmpW(name, L"attr3")) {
3683 checked++;
3684 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3685 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3686 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
3687 ok(!lstrcmpW(V_BSTR(&val), L"attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3688 test_attr_value(dom_attr, L"attr3");
3689 } else if(!lstrcmpW(name, L"test")) {
3690 checked++;
3691 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3692 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3693 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
3694 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
3695 test_attr_value(dom_attr, L"1");
3698 IHTMLDOMAttribute_Release(dom_attr);
3699 SysFreeString(name);
3700 VariantClear(&val);
3702 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
3704 V_I4(&id) = len;
3705 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3706 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3708 V_VT(&id) = VT_BSTR;
3709 V_BSTR(&id) = SysAllocString(L"nonexisting");
3710 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3711 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3712 VariantClear(&id);
3714 test_attr_collection_disp(disp);
3716 IDispatch_Release(disp);
3717 IHTMLAttributeCollection_Release(attr_col);
3720 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
3721 static void _test_elem_id(unsigned line, IUnknown *unk, const WCHAR *exid)
3723 IHTMLElement *elem = _get_elem_iface(line, unk);
3724 BSTR id = (void*)0xdeadbeef;
3725 HRESULT hres;
3727 hres = IHTMLElement_get_id(elem, &id);
3728 IHTMLElement_Release(elem);
3729 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
3731 if(exid)
3732 ok_(__FILE__,line) (!lstrcmpW(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
3733 else
3734 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
3736 SysFreeString(id);
3739 #define test_elem_language(e,i) _test_elem_language(__LINE__,e,i)
3740 static void _test_elem_language(unsigned line, IHTMLElement *elem, const WCHAR *exlang)
3742 BSTR lang = (void*)0xdeadbeef;
3743 HRESULT hres;
3745 hres = IHTMLElement_get_language(elem, &lang);
3746 ok_(__FILE__,line) (hres == S_OK, "get_language failed: %08x\n", hres);
3748 if(exlang)
3749 ok_(__FILE__,line) (!lstrcmpW(lang, exlang), "unexpected language %s\n", wine_dbgstr_w(lang));
3750 else
3751 ok_(__FILE__,line) (!lang, "language=%s\n", wine_dbgstr_w(lang));
3753 SysFreeString(lang);
3756 #define set_elem_language(e,i) _set_elem_language(__LINE__,e,i)
3757 static void _set_elem_language(unsigned line, IHTMLElement *elem, const WCHAR *lang)
3759 BSTR str = SysAllocString(lang);
3760 HRESULT hres;
3762 hres = IHTMLElement_put_language(elem, str);
3763 ok_(__FILE__,line) (hres == S_OK, "get_language failed: %08x\n", hres);
3764 SysFreeString(str);
3766 _test_elem_language(line, elem, lang);
3769 #define test_elem_lang(e,i) _test_elem_lang(__LINE__,e,i)
3770 static void _test_elem_lang(unsigned line, IHTMLElement *elem, const WCHAR *exlang)
3772 BSTR lang = (void*)0xdeadbeef;
3773 HRESULT hres;
3775 hres = IHTMLElement_get_lang(elem, &lang);
3776 ok_(__FILE__,line) (hres == S_OK, "get_lang failed: %08x\n", hres);
3778 if(exlang)
3779 ok_(__FILE__,line) (!lstrcmpW(lang, exlang), "unexpected lang %s\n", wine_dbgstr_w(lang));
3780 else
3781 ok_(__FILE__,line) (!lang, "lang=%s\n", wine_dbgstr_w(lang));
3783 SysFreeString(lang);
3786 #define set_elem_lang(e,i) _set_elem_lang(__LINE__,e,i)
3787 static void _set_elem_lang(unsigned line, IHTMLElement *elem, const WCHAR *lang)
3789 BSTR str = SysAllocString(lang);
3790 HRESULT hres;
3792 hres = IHTMLElement_put_lang(elem, str);
3793 ok_(__FILE__,line) (hres == S_OK, "get_lang failed: %08x\n", hres);
3794 SysFreeString(str);
3796 _test_elem_lang(line, elem, lang);
3799 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
3800 static void _test_elem_put_id(unsigned line, IUnknown *unk, const WCHAR *new_id)
3802 IHTMLElement *elem = _get_elem_iface(line, unk);
3803 BSTR tmp = SysAllocString(new_id);
3804 HRESULT hres;
3806 hres = IHTMLElement_put_id(elem, tmp);
3807 IHTMLElement_Release(elem);
3808 SysFreeString(tmp);
3809 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
3811 _test_elem_id(line, unk, new_id);
3814 static void test_contenteditable(IUnknown *unk)
3816 IHTMLElement3 *elem3 = get_elem3_iface(unk);
3817 HRESULT hres;
3818 BSTR str, strDefault;
3820 hres = IHTMLElement3_get_contentEditable(elem3, &strDefault);
3821 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3823 str = SysAllocString(L"true");
3824 hres = IHTMLElement3_put_contentEditable(elem3, str);
3825 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(str), hres);
3826 SysFreeString(str);
3827 hres = IHTMLElement3_get_contentEditable(elem3, &str);
3828 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3829 ok(!lstrcmpW(str, L"true"), "Got %s, expected %s\n", wine_dbgstr_w(str), "true");
3830 SysFreeString(str);
3832 /* Restore origin contentEditable */
3833 hres = IHTMLElement3_put_contentEditable(elem3, strDefault);
3834 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(strDefault), hres);
3835 SysFreeString(strDefault);
3837 IHTMLElement3_Release(elem3);
3840 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
3841 static void _test_input_type(unsigned line, IHTMLInputElement *input, const WCHAR *extype)
3843 BSTR type;
3844 HRESULT hres;
3846 hres = IHTMLInputElement_get_type(input, &type);
3847 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
3848 ok_(__FILE__,line) (!lstrcmpW(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), wine_dbgstr_w(extype));
3849 SysFreeString(type);
3852 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
3853 static void _test_input_name(unsigned line, IHTMLInputElement *input, const WCHAR *exname)
3855 BSTR name = (BSTR)0xdeadbeef;
3856 HRESULT hres;
3858 hres = IHTMLInputElement_get_name(input, &name);
3859 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
3860 if(exname)
3861 ok_(__FILE__,line) (!lstrcmpW(name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(exname));
3862 else
3863 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
3864 SysFreeString(name);
3867 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
3868 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const WCHAR *name)
3870 BSTR tmp = SysAllocString(name);
3871 HRESULT hres;
3873 hres = IHTMLInputElement_put_name(input, tmp);
3874 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
3875 SysFreeString(tmp);
3877 _test_input_name(line, input, name);
3880 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
3881 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3883 VARIANT_BOOL disabled = 100;
3884 HRESULT hres;
3886 hres = IHTMLInputElement_get_disabled(input, &disabled);
3887 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3888 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3890 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
3893 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
3894 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3896 HRESULT hres;
3898 hres = IHTMLInputElement_put_disabled(input, b);
3899 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3901 _test_input_get_disabled(line, input, b);
3904 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
3905 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3907 VARIANT_BOOL checked = 100;
3908 HRESULT hres;
3910 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
3911 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3912 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3915 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
3916 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3918 HRESULT hres;
3920 hres = IHTMLInputElement_put_defaultChecked(input, b);
3921 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3923 _test_input_get_defaultchecked(line, input, b);
3926 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
3927 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3929 VARIANT_BOOL checked = 100;
3930 HRESULT hres;
3932 hres = IHTMLInputElement_get_checked(input, &checked);
3933 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
3934 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3937 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
3938 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3940 HRESULT hres;
3942 hres = IHTMLInputElement_put_checked(input, b);
3943 ok_(__FILE__,line) (hres == S_OK, "put_checked failed: %08x\n", hres);
3945 _test_input_get_checked(line, input, b);
3948 #define test_input_maxlength(i,b) _test_input_maxlength(__LINE__,i,b)
3949 static void _test_input_maxlength(unsigned line, IHTMLInputElement *input, LONG exl)
3951 LONG maxlength = 0xdeadbeef;
3952 HRESULT hres;
3954 hres = IHTMLInputElement_get_maxLength(input, &maxlength);
3955 ok_(__FILE__,line) (hres == S_OK, "get_maxLength failed: %08x\n", hres);
3956 ok_(__FILE__,line) (maxlength == exl, "maxLength=%x, expected %d\n", maxlength, exl);
3959 #define test_input_set_maxlength(i,b) _test_input_set_maxlength(__LINE__,i,b)
3960 static void _test_input_set_maxlength(unsigned line, IHTMLInputElement *input, LONG l)
3962 HRESULT hres;
3964 hres = IHTMLInputElement_put_maxLength(input, l);
3965 ok_(__FILE__,line) (hres == S_OK, "put_maxLength failed: %08x\n", hres);
3967 _test_input_maxlength(line, input, l);
3970 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
3971 static void _test_input_value(unsigned line, IUnknown *unk, const WCHAR *exval)
3973 IHTMLInputElement *input;
3974 BSTR bstr;
3975 HRESULT hres;
3977 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3978 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3979 if(FAILED(hres))
3980 return;
3982 hres = IHTMLInputElement_get_value(input, &bstr);
3983 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3984 if(exval)
3985 ok_(__FILE__,line) (!lstrcmpW(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
3986 else
3987 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
3988 SysFreeString(bstr);
3989 IHTMLInputElement_Release(input);
3992 #define test_input_get_form(o, t) _test_input_get_form(__LINE__, o, t)
3993 static void _test_input_get_form(unsigned line, IUnknown *unk, const WCHAR *id)
3995 IHTMLInputElement *input;
3996 IHTMLFormElement *form;
3997 IHTMLElement *elem;
3998 HRESULT hres;
4000 ok_(__FILE__,line) (unk != NULL, "unk is NULL!\n");
4001 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
4002 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4003 ok_(__FILE__,line) (input != NULL, "input == NULL\n");
4004 if(FAILED(hres) || input == NULL)
4005 return;
4007 hres = IHTMLInputElement_get_form(input, &form);
4008 ok_(__FILE__, line) (hres == S_OK, "get_form failed: %08x\n", hres);
4009 ok_(__FILE__, line) (form != NULL, "form == NULL\n");
4010 if(FAILED(hres) || form == NULL){
4011 IHTMLInputElement_Release(input);
4012 return;
4015 hres = IHTMLFormElement_QueryInterface(form, &IID_IHTMLElement, (void **)&elem);
4016 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
4017 ok_(__FILE__, line) (elem != NULL, "elem == NULL\n");
4018 if(FAILED(hres) || elem == NULL){
4019 IHTMLInputElement_Release(input);
4020 IHTMLFormElement_Release(form);
4021 return;
4024 _test_elem_id(line, (IUnknown*)elem, id);
4026 IHTMLInputElement_Release(input);
4027 IHTMLFormElement_Release(form);
4028 IHTMLElement_Release(elem);
4031 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
4032 static void _test_input_put_value(unsigned line, IUnknown *unk, const WCHAR *val)
4034 IHTMLInputElement *input;
4035 BSTR bstr;
4036 HRESULT hres;
4038 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
4039 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4040 if(FAILED(hres))
4041 return;
4043 bstr = SysAllocString(val);
4044 hres = IHTMLInputElement_put_value(input, bstr);
4045 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
4046 SysFreeString(bstr);
4047 IHTMLInputElement_Release(input);
4049 _test_input_value(line, unk, val);
4052 #define test_input_defaultValue(o,t) _test_input_defaultValue(__LINE__,o,t)
4053 static void _test_input_defaultValue(unsigned line, IUnknown *unk, const WCHAR *exval)
4055 IHTMLInputElement *input;
4056 BSTR str;
4057 HRESULT hres;
4059 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
4060 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4061 if(FAILED(hres))
4062 return;
4064 hres = IHTMLInputElement_get_defaultValue(input, &str);
4065 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
4066 if(exval)
4067 ok_(__FILE__,line) (!lstrcmpW(str, exval), "defaultValue=%s\n", wine_dbgstr_w(str));
4068 else
4069 ok_(__FILE__,line) (!str, "exval != NULL\n");
4070 SysFreeString(str);
4071 IHTMLInputElement_Release(input);
4074 #define test_input_put_defaultValue(o,v) _test_input_put_defaultValue(__LINE__,o,v)
4075 static void _test_input_put_defaultValue(unsigned line, IUnknown *unk, const WCHAR *val)
4077 IHTMLInputElement *input;
4078 BSTR str;
4079 HRESULT hres;
4081 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
4082 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
4083 if(FAILED(hres))
4084 return;
4086 str = SysAllocString(val);
4087 hres = IHTMLInputElement_put_defaultValue(input, str);
4088 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
4089 SysFreeString(str);
4090 IHTMLInputElement_Release(input);
4092 _test_input_defaultValue(line, unk, val);
4095 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
4096 static void _test_input_src(unsigned line, IHTMLInputElement *input, const WCHAR *exsrc)
4098 BSTR src;
4099 HRESULT hres;
4101 hres = IHTMLInputElement_get_src(input, &src);
4102 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
4103 if(exsrc)
4104 ok_(__FILE__,line) (!lstrcmpW(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), wine_dbgstr_w(exsrc));
4105 else
4106 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
4107 SysFreeString(src);
4110 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
4111 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const WCHAR *src)
4113 BSTR tmp;
4114 HRESULT hres;
4116 tmp = SysAllocString(src);
4117 hres = IHTMLInputElement_put_src(input, tmp);
4118 SysFreeString(tmp);
4119 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
4121 _test_input_src(line, input, src);
4124 #define test_input_set_size(u,s,r) _test_input_set_size(__LINE__,u,s,r)
4125 static void _test_input_set_size(unsigned line, IHTMLInputElement *input, LONG size, HRESULT exret)
4127 HRESULT hres;
4129 hres = IHTMLInputElement_put_size(input, size);
4130 ok_(__FILE__,line) (hres == exret, "Expect ret = %08x, got: %08x\n", exret, hres);
4133 #define test_input_get_size(u,s) _test_input_get_size(__LINE__,u,s)
4134 static void _test_input_get_size(unsigned line, IHTMLInputElement *input, LONG exsize)
4136 HRESULT hres;
4137 LONG size;
4139 hres = IHTMLInputElement_get_size(input, &size);
4140 ok_(__FILE__,line) (hres == S_OK, "get_size failed: %08x\n", hres);
4141 ok_(__FILE__,line) (size == exsize, "Expect %d, got %d\n", exsize, size);
4143 hres = IHTMLInputElement_get_size(input, NULL);
4144 ok_(__FILE__,line) (hres == E_INVALIDARG, "Expect ret E_INVALIDARG, got: %08x\n", hres);
4147 #define test_input_readOnly(u,b) _test_input_readOnly(__LINE__,u,b)
4148 static void _test_input_readOnly(unsigned line, IHTMLInputElement *input, VARIANT_BOOL v)
4150 HRESULT hres;
4151 VARIANT_BOOL b = 100;
4153 hres = IHTMLInputElement_put_readOnly(input, v);
4154 ok_(__FILE__,line)(hres == S_OK, "put readOnly failed: %08x\n", hres);
4156 hres = IHTMLInputElement_get_readOnly(input, &b);
4157 ok_(__FILE__,line)(hres == S_OK, "get readOnly failed: %08x\n", hres);
4158 ok_(__FILE__,line)(v == b, "Expect %x, got %x\n", v, b);
4161 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
4162 static void _test_elem_class(unsigned line, IUnknown *unk, const WCHAR *exclass)
4164 IHTMLElement *elem = _get_elem_iface(line, unk);
4165 BSTR class = (void*)0xdeadbeef;
4166 HRESULT hres;
4168 hres = IHTMLElement_get_className(elem, &class);
4169 IHTMLElement_Release(elem);
4170 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
4171 if(exclass)
4172 ok_(__FILE__,line) (!lstrcmpW(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
4173 else
4174 ok_(__FILE__,line) (!class, "class != NULL\n");
4175 SysFreeString(class);
4178 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
4179 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
4181 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
4182 short index = -3;
4183 HRESULT hres;
4185 hres = IHTMLElement2_get_tabIndex(elem2, &index);
4186 IHTMLElement2_Release(elem2);
4187 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
4188 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
4191 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
4192 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
4194 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
4195 HRESULT hres;
4197 hres = IHTMLElement2_put_tabIndex(elem2, index);
4198 IHTMLElement2_Release(elem2);
4199 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
4201 _test_elem_tabindex(line, unk, index);
4204 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
4205 static void _test_style_media(unsigned line, IUnknown *unk, const WCHAR *exmedia)
4207 IHTMLStyleElement *style = _get_style_iface(line, unk);
4208 BSTR media;
4209 HRESULT hres;
4211 hres = IHTMLStyleElement_get_media(style, &media);
4212 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
4213 if(exmedia)
4214 ok_(__FILE__,line)(!lstrcmpW(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), wine_dbgstr_w(exmedia));
4215 else
4216 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
4218 IHTMLStyleElement_Release(style);
4219 SysFreeString(media);
4222 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
4223 static void _test_style_put_media(unsigned line, IUnknown *unk, const WCHAR *media)
4225 IHTMLStyleElement *style = _get_style_iface(line, unk);
4226 BSTR str;
4227 HRESULT hres;
4229 str = SysAllocString(media);
4230 hres = IHTMLStyleElement_put_media(style, str);
4231 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
4232 IHTMLStyleElement_Release(style);
4233 SysFreeString(str);
4235 _test_style_media(line, unk, media);
4238 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
4239 static void _test_style_type(unsigned line, IUnknown *unk, const WCHAR *extype)
4241 IHTMLStyleElement *style = _get_style_iface(line, unk);
4242 BSTR type;
4243 HRESULT hres;
4245 hres = IHTMLStyleElement_get_type(style, &type);
4246 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
4247 if(extype)
4248 ok_(__FILE__,line)(!lstrcmpW(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), wine_dbgstr_w(extype));
4249 else
4250 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
4252 IHTMLStyleElement_Release(style);
4253 SysFreeString(type);
4256 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
4257 static void _test_style_put_type(unsigned line, IUnknown *unk, const WCHAR *type)
4259 IHTMLStyleElement *style = _get_style_iface(line, unk);
4260 BSTR str;
4261 HRESULT hres;
4263 str = SysAllocString(type);
4264 hres = IHTMLStyleElement_put_type(style, str);
4265 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
4266 IHTMLStyleElement_Release(style);
4267 SysFreeString(str);
4269 _test_style_type(line, unk, type);
4272 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
4273 static void _test_elem_filters(unsigned line, IUnknown *unk)
4275 IHTMLElement *elem = _get_elem_iface(line, unk);
4276 HRESULT hres;
4277 IHTMLFiltersCollection *filters;
4279 hres = IHTMLElement_get_filters(elem, &filters);
4280 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
4281 "get_filters failed: %08x\n", hres);
4282 if(hres == S_OK)
4284 LONG len;
4285 IDispatchEx *dispex;
4287 hres = IHTMLFiltersCollection_get_length(filters, &len);
4288 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
4289 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
4291 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
4292 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
4293 "Could not get IDispatchEx interface: %08x\n", hres);
4294 if(SUCCEEDED(hres)) {
4295 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, NULL, L"[object]");
4296 IDispatchEx_Release(dispex);
4299 IHTMLFiltersCollection_Release(filters);
4302 IHTMLElement_Release(elem);
4305 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
4306 static void _test_elem_set_class(unsigned line, IUnknown *unk, const WCHAR *class)
4308 IHTMLElement *elem = _get_elem_iface(line, unk);
4309 BSTR tmp;
4310 HRESULT hres;
4312 tmp = class ? SysAllocString(class) : NULL;
4313 hres = IHTMLElement_put_className(elem, tmp);
4314 IHTMLElement_Release(elem);
4315 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
4316 SysFreeString(tmp);
4318 _test_elem_class(line, unk, class);
4321 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
4322 static void _test_elem_title(unsigned line, IUnknown *unk, const WCHAR *extitle)
4324 IHTMLElement *elem = _get_elem_iface(line, unk);
4325 BSTR title;
4326 HRESULT hres;
4328 hres = IHTMLElement_get_title(elem, &title);
4329 IHTMLElement_Release(elem);
4330 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4331 if(extitle)
4332 ok_(__FILE__,line) (!lstrcmpW(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
4333 else
4334 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
4336 SysFreeString(title);
4339 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
4340 static void _test_elem_set_title(unsigned line, IUnknown *unk, const WCHAR *title)
4342 IHTMLElement *elem = _get_elem_iface(line, unk);
4343 BSTR tmp;
4344 HRESULT hres;
4346 tmp = SysAllocString(title);
4347 hres = IHTMLElement_put_title(elem, tmp);
4348 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4350 IHTMLElement_Release(elem);
4351 SysFreeString(tmp);
4354 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
4355 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const WCHAR *exval)
4357 IHTMLDOMNode *node = _get_node_iface(line, unk);
4358 VARIANT var;
4359 HRESULT hres;
4361 hres = IHTMLDOMNode_get_nodeValue(node, &var);
4362 IHTMLDOMNode_Release(node);
4363 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
4365 if(exval) {
4366 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
4367 ok_(__FILE__,line) (!lstrcmpW(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
4368 }else {
4369 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
4372 VariantClear(&var);
4375 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
4376 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const WCHAR *val)
4378 IHTMLDOMNode *node = _get_node_iface(line, unk);
4379 VARIANT var;
4380 HRESULT hres;
4382 V_VT(&var) = VT_BSTR;
4383 V_BSTR(&var) = SysAllocString(val);
4385 hres = IHTMLDOMNode_put_nodeValue(node, var);
4386 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
4387 IHTMLDOMNode_Release(node);
4388 VariantClear(&var);
4391 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
4392 static void _test_elem_client_size(unsigned line, IUnknown *unk)
4394 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
4395 LONG l;
4396 HRESULT hres;
4398 hres = IHTMLElement2_get_clientWidth(elem, &l);
4399 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
4400 hres = IHTMLElement2_get_clientHeight(elem, &l);
4401 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
4403 IHTMLElement2_Release(elem);
4406 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
4407 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
4409 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
4410 LONG l;
4411 HRESULT hres;
4413 hres = IHTMLElement2_get_clientLeft(elem, &l);
4414 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
4415 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
4417 hres = IHTMLElement2_get_clientTop(elem, &l);
4418 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
4419 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
4421 IHTMLElement2_Release(elem);
4424 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
4425 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
4427 IHTMLFormElement *form = _get_form_iface(line, unk);
4428 LONG len = 0xdeadbeef;
4429 HRESULT hres;
4431 hres = IHTMLFormElement_get_length(form, &len);
4432 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
4433 ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
4435 IHTMLFormElement_Release(form);
4438 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
4439 static void _test_form_action(unsigned line, IUnknown *unk, const WCHAR *ex)
4441 IHTMLFormElement *form = _get_form_iface(line, unk);
4442 BSTR action = (void*)0xdeadbeef;
4443 HRESULT hres;
4445 hres = IHTMLFormElement_get_action(form, &action);
4446 ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
4447 if(ex)
4448 ok_(__FILE__,line)(!lstrcmpW(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), wine_dbgstr_w(ex));
4449 else
4450 ok_(__FILE__,line)(!action, "action=%p\n", action);
4452 SysFreeString(action);
4453 IHTMLFormElement_Release(form);
4456 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
4457 static void _test_form_put_action(unsigned line, IUnknown *unk, const WCHAR *action)
4459 IHTMLFormElement *form = _get_form_iface(line, unk);
4460 BSTR tmp = SysAllocString(action);
4461 HRESULT hres;
4463 hres = IHTMLFormElement_put_action(form, tmp);
4464 ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
4465 SysFreeString(tmp);
4466 IHTMLFormElement_Release(form);
4468 _test_form_action(line, unk, action);
4471 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
4472 static void _test_form_method(unsigned line, IUnknown *unk, const WCHAR *ex)
4474 IHTMLFormElement *form = _get_form_iface(line, unk);
4475 BSTR method = (void*)0xdeadbeef;
4476 HRESULT hres;
4478 hres = IHTMLFormElement_get_method(form, &method);
4479 ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
4480 if(ex)
4481 ok_(__FILE__,line)(!lstrcmpW(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), wine_dbgstr_w(ex));
4482 else
4483 ok_(__FILE__,line)(!method, "method=%p\n", method);
4485 SysFreeString(method);
4486 IHTMLFormElement_Release(form);
4489 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
4490 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const WCHAR *method)
4492 IHTMLFormElement *form = _get_form_iface(line, unk);
4493 BSTR tmp = SysAllocString(method);
4494 HRESULT hres;
4496 hres = IHTMLFormElement_put_method(form, tmp);
4497 ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
4498 SysFreeString(tmp);
4499 IHTMLFormElement_Release(form);
4501 if(exp_hres == S_OK)
4502 _test_form_method(line, unk, method);
4505 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
4506 static void _test_form_name(unsigned line, IUnknown *unk, const WCHAR *ex)
4508 IHTMLFormElement *form = _get_form_iface(line, unk);
4509 BSTR name = (void*)0xdeadbeef;
4510 HRESULT hres;
4512 hres = IHTMLFormElement_get_name(form, &name);
4513 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
4514 if(ex)
4515 ok_(__FILE__,line)(!lstrcmpW(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(ex));
4516 else
4517 ok_(__FILE__,line)(!name, "name=%p\n", name);
4519 SysFreeString(name);
4520 IHTMLFormElement_Release(form);
4523 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
4524 static void _test_form_put_name(unsigned line, IUnknown *unk, const WCHAR *name)
4526 IHTMLFormElement *form = _get_form_iface(line, unk);
4527 BSTR tmp = SysAllocString(name);
4528 HRESULT hres;
4530 hres = IHTMLFormElement_put_name(form, tmp);
4531 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
4532 SysFreeString(tmp);
4533 IHTMLFormElement_Release(form);
4535 _test_form_name(line, unk, name);
4538 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
4539 static void _test_form_encoding(unsigned line, IUnknown *unk, const WCHAR *ex)
4541 IHTMLFormElement *form = _get_form_iface(line, unk);
4542 BSTR encoding = (void*)0xdeadbeef;
4543 HRESULT hres;
4545 hres = IHTMLFormElement_get_encoding(form, &encoding);
4546 ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
4547 if(ex)
4548 ok_(__FILE__,line)(!lstrcmpW(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), wine_dbgstr_w(ex));
4549 else
4550 ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
4552 SysFreeString(encoding);
4553 IHTMLFormElement_Release(form);
4556 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
4557 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const WCHAR *encoding)
4559 IHTMLFormElement *form = _get_form_iface(line, unk);
4560 BSTR tmp = SysAllocString(encoding);
4561 HRESULT hres;
4563 hres = IHTMLFormElement_put_encoding(form, tmp);
4564 ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
4565 SysFreeString(tmp);
4566 IHTMLFormElement_Release(form);
4568 if(exp_hres == S_OK)
4569 _test_form_encoding(line, unk, encoding);
4572 #define test_form_elements(a,b,c) _test_form_elements(__LINE__,a,b,c)
4573 static void _test_form_elements(unsigned line, IUnknown *unk, const elem_type_t *elem_types,
4574 LONG elem_types_cnt)
4576 IHTMLFormElement *form = _get_form_iface(line, unk);
4577 IDispatch *disp;
4578 HRESULT hres;
4580 disp = NULL;
4581 hres = IHTMLFormElement_get_elements(form, &disp);
4582 ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
4583 ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
4584 if(compat_mode < COMPAT_IE9)
4585 ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
4586 else
4587 _test_elem_collection(line, (IUnknown*)disp, elem_types, elem_types_cnt);
4589 IDispatch_Release(disp);
4590 IHTMLFormElement_Release(form);
4593 #define test_form_reset(a) _test_form_reset(__LINE__,a)
4594 static void _test_form_reset(unsigned line, IUnknown *unk)
4596 IHTMLFormElement *form = _get_form_iface(line, unk);
4597 HRESULT hres;
4599 hres = IHTMLFormElement_reset(form);
4600 ok_(__FILE__,line)(hres == S_OK, "reset failed: %08x\n", hres);
4602 IHTMLFormElement_Release(form);
4605 static void test_form_target(IUnknown *unk)
4607 IHTMLFormElement *form = get_form_iface(unk);
4608 HRESULT hres;
4609 BSTR str;
4611 str = SysAllocString(L"_blank");
4612 hres = IHTMLFormElement_put_target(form, str);
4613 ok(hres == S_OK, "put_target failed: %08x\n", hres);
4614 SysFreeString(str);
4616 hres = IHTMLFormElement_get_target(form, &str);
4617 ok(hres == S_OK, "get_target failed: %08x\n", hres);
4618 ok(!lstrcmpW(str, L"_blank"), "got %s\n", wine_dbgstr_w(str));
4619 SysFreeString(str);
4621 IHTMLFormElement_Release(form);
4624 static void test_select_form(IUnknown *uselect, IUnknown *uform)
4626 IHTMLSelectElement *select = get_select_iface(uselect);
4627 IHTMLFormElement *form;
4628 HRESULT hres;
4630 hres = IHTMLSelectElement_get_form(select, NULL);
4631 ok(hres == E_POINTER, "got %08x\n, expected E_POINTER\n", hres);
4633 hres = IHTMLSelectElement_get_form(select, &form);
4634 ok(hres == S_OK, "get_form failed: %08x\n", hres);
4635 ok(form != NULL, "form == NULL\n");
4637 test_form_length((IUnknown*)form, 2);
4638 test_form_elements((IUnknown*)form, NULL, 0);
4639 test_form_name((IUnknown*)form, L"form_name");
4641 ok(iface_cmp(uform, (IUnknown*)form), "Expected %p, got %p\n", uform, form);
4643 IHTMLSelectElement_Release(select);
4644 IHTMLFormElement_Release(form);
4647 static void test_select_form_notfound(IHTMLSelectElement *select)
4649 IHTMLFormElement *form;
4650 HRESULT hres;
4652 form = (IHTMLFormElement*)0xdeadbeef;
4653 hres = IHTMLSelectElement_get_form(select, &form);
4654 ok(hres == S_OK, "get_form failed: %08x\n", hres);
4655 ok(form == NULL, "got %p\n", form);
4658 #define test_meta_name(a,b) _test_meta_name(__LINE__,a,b)
4659 static void _test_meta_name(unsigned line, IUnknown *unk, const WCHAR *exname)
4661 IHTMLMetaElement *meta;
4662 BSTR name = NULL;
4663 HRESULT hres;
4665 meta = _get_metaelem_iface(line, unk);
4666 hres = IHTMLMetaElement_get_name(meta, &name);
4667 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
4668 ok_(__FILE__,line)(!lstrcmpW(name, exname), "name = %s, expected %s\n", wine_dbgstr_w(name), wine_dbgstr_w(exname));
4669 SysFreeString(name);
4670 IHTMLMetaElement_Release(meta);
4673 #define test_meta_content(a,b) _test_meta_content(__LINE__,a,b)
4674 static void _test_meta_content(unsigned line, IUnknown *unk, const WCHAR *excontent)
4676 IHTMLMetaElement *meta;
4677 BSTR content = NULL;
4678 HRESULT hres;
4680 meta = _get_metaelem_iface(line, unk);
4681 hres = IHTMLMetaElement_get_content(meta, &content);
4682 ok_(__FILE__,line)(hres == S_OK, "get_content failed: %08x\n", hres);
4683 ok_(__FILE__,line)(!lstrcmpW(content, excontent), "content = %s, expected %s\n", wine_dbgstr_w(content), wine_dbgstr_w(excontent));
4684 SysFreeString(content);
4685 IHTMLMetaElement_Release(meta);
4688 #define test_meta_httpequiv(a,b) _test_meta_httpequiv(__LINE__,a,b)
4689 static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const WCHAR *exval)
4691 IHTMLMetaElement *meta;
4692 BSTR val = NULL;
4693 HRESULT hres;
4695 meta = _get_metaelem_iface(line, unk);
4696 hres = IHTMLMetaElement_get_httpEquiv(meta, &val);
4697 ok_(__FILE__,line)(hres == S_OK, "get_httpEquiv failed: %08x\n", hres);
4698 ok_(__FILE__,line)(!lstrcmpW(val, exval), "httpEquiv = %s, expected %s\n", wine_dbgstr_w(val), wine_dbgstr_w(exval));
4699 SysFreeString(val);
4700 IHTMLMetaElement_Release(meta);
4703 #define test_meta_charset(a,b) _test_meta_charset(__LINE__,a,b)
4704 static void _test_meta_charset(unsigned line, IUnknown *unk, const WCHAR *exval)
4706 IHTMLMetaElement *meta;
4707 BSTR val = NULL;
4708 HRESULT hres;
4710 meta = _get_metaelem_iface(line, unk);
4711 hres = IHTMLMetaElement_get_charset(meta, &val);
4712 ok_(__FILE__,line)(hres == S_OK, "get_charset failed: %08x\n", hres);
4713 if(exval)
4714 ok_(__FILE__,line)(!lstrcmpW(val, exval), "charset = %s, expected %s\n", wine_dbgstr_w(val), wine_dbgstr_w(exval));
4715 else
4716 ok_(__FILE__,line)(!val, "charset = %s, expected NULL\n", wine_dbgstr_w(val));
4717 SysFreeString(val);
4718 IHTMLMetaElement_Release(meta);
4721 #define set_meta_charset(a,b) _set_meta_charset(__LINE__,a,b)
4722 static void _set_meta_charset(unsigned line, IUnknown *unk, const WCHAR *v)
4724 BSTR val = SysAllocString(v);
4725 IHTMLMetaElement *meta;
4726 HRESULT hres;
4728 meta = _get_metaelem_iface(line, unk);
4729 hres = IHTMLMetaElement_put_charset(meta, val);
4730 ok_(__FILE__,line)(hres == S_OK, "put_charset failed: %08x\n", hres);
4731 SysFreeString(val);
4732 IHTMLMetaElement_Release(meta);
4734 _test_meta_charset(line, unk, v);
4737 #define test_link_media(a,b) _test_link_media(__LINE__,a,b)
4738 static void _test_link_media(unsigned line, IHTMLElement *elem, const WCHAR *exval)
4740 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4741 HRESULT hres;
4742 BSTR str;
4744 str = SysAllocString(exval);
4745 hres = IHTMLLinkElement_put_media(link, str);
4746 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
4747 SysFreeString(str);
4749 hres = IHTMLLinkElement_get_media(link, &str);
4750 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
4751 ok_(__FILE__,line)(!lstrcmpW(str, exval), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exval));
4752 SysFreeString(str);
4753 IHTMLLinkElement_Release(link);
4756 #define test_link_disabled(a,b) _test_link_disabled(__LINE__,a,b)
4757 static void _test_link_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
4759 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4760 VARIANT_BOOL b = 10;
4761 HRESULT hres;
4763 hres = IHTMLLinkElement_get_disabled(link, &b);
4764 ok_(__FILE__,line)(hres == S_OK, "get_disabled failed: %08x\n", hres);
4765 ok_(__FILE__,line)(b == v, "disabled = %x, expected %x\n", b, v);
4767 IHTMLLinkElement_Release(link);
4770 #define link_put_disabled(a,b) _link_put_disabled(__LINE__,a,b)
4771 static void _link_put_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
4773 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4774 HRESULT hres;
4776 hres = IHTMLLinkElement_put_disabled(link, v);
4777 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4778 IHTMLLinkElement_Release(link);
4779 _test_link_disabled(line, elem, v);
4782 #define test_link_rel(a,b) _test_link_rel(__LINE__,a,b)
4783 static void _test_link_rel(unsigned line, IHTMLElement *elem, const WCHAR *v)
4785 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4786 BSTR rel;
4787 HRESULT hres;
4789 hres = IHTMLLinkElement_get_rel(link, &rel);
4790 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
4791 if(v)
4792 ok_(__FILE__,line)(!lstrcmpW(rel, v), "rel = %s\n", wine_dbgstr_w(rel));
4793 else
4794 ok_(__FILE__,line)(!rel, "rel = %s, expected NULL\n", wine_dbgstr_w(rel));
4795 SysFreeString(rel);
4797 IHTMLLinkElement_Release(link);
4800 #define link_put_rel(a,b) _link_put_rel(__LINE__,a,b)
4801 static void _link_put_rel(unsigned line, IHTMLElement *elem, const WCHAR *v)
4803 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4804 BSTR str = SysAllocString(v);
4805 HRESULT hres;
4807 hres = IHTMLLinkElement_put_rel(link, str);
4808 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4809 SysFreeString(str);
4810 IHTMLLinkElement_Release(link);
4811 _test_link_rel(line, elem, v);
4814 #define test_link_rev(a,b) _test_link_rev(__LINE__,a,b)
4815 static void _test_link_rev(unsigned line, IHTMLElement *elem, const WCHAR *v)
4817 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4818 BSTR rev;
4819 HRESULT hres;
4821 hres = IHTMLLinkElement_get_rev(link, &rev);
4822 ok_(__FILE__,line)(hres == S_OK, "get_rev failed: %08x\n", hres);
4823 if(v)
4824 ok_(__FILE__,line)(!lstrcmpW(rev, v), "rev = %s\n", wine_dbgstr_w(rev));
4825 else
4826 ok_(__FILE__,line)(!rev, "rev = %s, expected NULL\n", wine_dbgstr_w(rev));
4827 SysFreeString(rev);
4829 IHTMLLinkElement_Release(link);
4832 #define link_put_rev(a,b) _link_put_rev(__LINE__,a,b)
4833 static void _link_put_rev(unsigned line, IHTMLElement *elem, const WCHAR *v)
4835 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4836 BSTR str = SysAllocString(v);
4837 HRESULT hres;
4839 hres = IHTMLLinkElement_put_rev(link, str);
4840 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4841 SysFreeString(str);
4842 IHTMLLinkElement_Release(link);
4843 _test_link_rev(line, elem, v);
4846 #define test_link_type(a,b) _test_link_type(__LINE__,a,b)
4847 static void _test_link_type(unsigned line, IHTMLElement *elem, const WCHAR *v)
4849 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4850 BSTR type;
4851 HRESULT hres;
4853 hres = IHTMLLinkElement_get_type(link, &type);
4854 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
4855 if(v)
4856 ok_(__FILE__,line)(!lstrcmpW(type, v), "type = %s, expected %s\n", wine_dbgstr_w(type), wine_dbgstr_w(v));
4857 else
4858 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
4859 SysFreeString(type);
4861 IHTMLLinkElement_Release(link);
4864 #define test_script_text(a,b) _test_script_text(__LINE__,a,b)
4865 static void _test_script_text(unsigned line, IHTMLScriptElement *script, const WCHAR *extext)
4867 BSTR str;
4868 HRESULT hres;
4870 str = (void*)0xdeadbeef;
4871 hres = IHTMLScriptElement_get_text(script, &str);
4872 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
4873 ok(!lstrcmpW(str, extext), "text = %s, expected \"%s\"\n", wine_dbgstr_w(str), wine_dbgstr_w(extext));
4874 SysFreeString(str);
4877 #define link_put_type(a,b) _link_put_type(__LINE__,a,b)
4878 static void _link_put_type(unsigned line, IHTMLElement *elem, const WCHAR *v)
4880 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4881 BSTR str = SysAllocString(v);
4882 HRESULT hres;
4884 hres = IHTMLLinkElement_put_type(link, str);
4885 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4886 SysFreeString(str);
4887 IHTMLLinkElement_Release(link);
4888 _test_link_type(line, elem, v);
4891 #define test_link_href(a,b) _test_link_href(__LINE__,a,b)
4892 static void _test_link_href(unsigned line, IHTMLElement *elem, const WCHAR *v)
4894 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4895 BSTR href;
4896 HRESULT hres;
4898 hres = IHTMLLinkElement_get_href(link, &href);
4899 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
4900 if(v)
4901 ok_(__FILE__,line)(!lstrcmpW(href, v), "href = %s, expected %s\n", wine_dbgstr_w(href), wine_dbgstr_w(v));
4902 else
4903 ok_(__FILE__,line)(!href, "href = %s, expected NULL\n", wine_dbgstr_w(href));
4904 SysFreeString(href);
4906 IHTMLLinkElement_Release(link);
4909 #define link_put_href(a,b) _link_put_href(__LINE__,a,b)
4910 static void _link_put_href(unsigned line, IHTMLElement *elem, const WCHAR *v)
4912 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4913 BSTR str = SysAllocString(v);
4914 HRESULT hres;
4916 hres = IHTMLLinkElement_put_href(link, str);
4917 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4918 SysFreeString(str);
4919 IHTMLLinkElement_Release(link);
4920 _test_link_href(line, elem, v);
4923 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
4924 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
4926 IHTMLElement *elem = _get_elem_iface(line, unk);
4927 IHTMLDocument2 *doc;
4928 IDispatch *disp;
4929 HRESULT hres;
4931 disp = NULL;
4932 hres = IHTMLElement_get_document(elem, &disp);
4933 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4934 ok(disp != NULL, "disp == NULL\n");
4936 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
4937 IDispatch_Release(disp);
4938 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
4940 return doc;
4943 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
4944 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const WCHAR *attr_name, BOOL expect_success)
4946 IHTMLElement4 *elem = _get_elem4_iface(line, unk);
4947 BSTR str = SysAllocString(attr_name);
4948 IHTMLDOMAttribute *attr;
4949 HRESULT hres;
4951 attr = (void*)0xdeadbeef;
4952 hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
4953 ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
4954 if(expect_success)
4955 ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
4956 else
4957 ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
4959 IHTMLElement4_Release(elem);
4960 SysFreeString(str);
4961 return attr;
4964 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
4965 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
4967 HRESULT hres;
4969 V_VT(v) = VT_EMPTY;
4970 hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
4971 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x\n", hres);
4972 ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
4975 #define put_attr_node_value(a,b) _put_attr_node_value(__LINE__,a,b)
4976 static void _put_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT v)
4978 HRESULT hres;
4980 hres = IHTMLDOMAttribute_put_nodeValue(attr, v);
4981 ok_(__FILE__,line) (hres == S_OK, "put_nodeValue failed: %08x\n", hres);
4984 #define put_attr_value(a,b) _put_attr_value(__LINE__,a,b)
4985 static void _put_attr_value(unsigned line, IHTMLDOMAttribute *attr, const WCHAR *value)
4987 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
4988 BSTR str = SysAllocString(value);
4989 HRESULT hres;
4991 hres = IHTMLDOMAttribute2_put_value(attr2, str);
4992 ok_(__FILE__,line) (hres == S_OK, "put_nodeValue failed: %08x\n", hres);
4994 IHTMLDOMAttribute2_Release(attr2);
4995 SysFreeString(str);
4998 #define get_window_doc(e) _get_window_doc(__LINE__,e)
4999 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
5001 IHTMLDocument2 *doc;
5002 HRESULT hres;
5004 doc = NULL;
5005 hres = IHTMLWindow2_get_document(window, &doc);
5006 ok(hres == S_OK, "get_document failed: %08x\n", hres);
5007 ok(doc != NULL, "disp == NULL\n");
5009 return doc;
5012 #define doc_get_body(d) _doc_get_body(__LINE__,d)
5013 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
5015 IHTMLElement *elem;
5016 HRESULT hres;
5018 hres = IHTMLDocument2_get_body(doc, &elem);
5019 ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
5020 ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
5022 return elem;
5025 static void set_body_html(IHTMLDocument2 *doc, const WCHAR *html)
5027 IHTMLElement *body;
5028 body = doc_get_body(doc);
5029 test_elem_set_innerhtml((IUnknown*)body, html);
5030 IHTMLElement_Release(body);
5033 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
5034 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const WCHAR *tag)
5036 IHTMLElement *elem = NULL;
5037 BSTR tmp;
5038 HRESULT hres;
5040 tmp = SysAllocString(tag);
5041 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
5042 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
5043 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
5044 SysFreeString(tmp);
5046 return elem;
5049 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
5050 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const WCHAR *text)
5052 IHTMLDocument3 *doc3;
5053 IHTMLDOMNode *node = NULL;
5054 BSTR tmp;
5055 HRESULT hres;
5057 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5058 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
5060 tmp = SysAllocString(text);
5061 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
5062 IHTMLDocument3_Release(doc3);
5063 SysFreeString(tmp);
5064 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
5065 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
5067 return node;
5070 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
5071 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
5073 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
5074 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
5075 IHTMLDOMNode *new_child = NULL;
5076 HRESULT hres;
5078 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
5079 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
5080 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
5081 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
5083 IHTMLDOMNode_Release(node);
5084 IHTMLDOMNode_Release(child);
5086 return new_child;
5089 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
5090 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
5092 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
5093 IHTMLDOMNode *new_child = NULL;
5094 HRESULT hres;
5096 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
5097 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
5098 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
5099 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
5101 IHTMLDOMNode_Release(node);
5103 return new_child;
5106 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
5107 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
5109 IHTMLDOMNode *node = _get_node_iface(line, unk);
5110 IHTMLDOMNode *new_node = NULL;
5111 HRESULT hres;
5113 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
5114 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
5115 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
5116 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
5118 IHTMLDOMNode_Release(node);
5119 IHTMLDOMNode_Release(new_node);
5122 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
5123 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const WCHAR *extitle)
5125 BSTR title = NULL;
5126 HRESULT hres;
5128 hres = IHTMLDocument2_get_title(doc, &title);
5129 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
5130 ok_(__FILE__,line) (!lstrcmpW(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
5131 SysFreeString(title);
5134 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
5135 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const WCHAR *title)
5137 BSTR tmp;
5138 HRESULT hres;
5140 tmp = SysAllocString(title);
5141 hres = IHTMLDocument2_put_title(doc, tmp);
5142 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
5143 SysFreeString(tmp);
5146 static void test_elem_bounding_client_rect(IUnknown *unk)
5148 IHTMLRectCollection *rects;
5149 IHTMLRect *rect, *rect2;
5150 IHTMLElement2 *elem2;
5151 VARIANT v, index;
5152 LONG l;
5153 HRESULT hres;
5155 elem2 = get_elem2_iface(unk);
5156 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
5157 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
5158 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
5159 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
5160 ok(rect != NULL, "rect == NULL\n");
5161 ok(rect != rect2, "rect == rect2\n");
5162 IHTMLRect_Release(rect2);
5164 test_disp((IUnknown*)rect, &IID_IHTMLRect, NULL, L"[object]");
5166 l = 0xdeadbeef;
5167 hres = IHTMLRect_get_top(rect, &l);
5168 ok(hres == S_OK, "get_top failed: %08x\n", hres);
5169 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
5171 l = 0xdeadbeef;
5172 hres = IHTMLRect_get_left(rect, &l);
5173 ok(hres == S_OK, "get_left failed: %08x\n", hres);
5174 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
5176 l = 0xdeadbeef;
5177 hres = IHTMLRect_get_bottom(rect, &l);
5178 ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
5179 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
5181 l = 0xdeadbeef;
5182 hres = IHTMLRect_get_right(rect, &l);
5183 ok(hres == S_OK, "get_right failed: %08x\n", hres);
5184 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
5186 IHTMLRect_Release(rect);
5188 hres = IHTMLElement2_getClientRects(elem2, &rects);
5189 ok(hres == S_OK, "getClientRects failed: %08x\n", hres);
5191 test_disp((IUnknown*)rects, &IID_IHTMLRectCollection, NULL, L"[object]");
5193 hres = IHTMLRectCollection_get_length(rects, &l);
5194 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5195 ok(l == 1, "length = %u\n", l);
5197 V_VT(&index) = VT_I4;
5198 V_I4(&index) = 0;
5199 V_VT(&v) = VT_ERROR;
5200 hres = IHTMLRectCollection_item(rects, &index, &v);
5201 ok(hres == S_OK, "item failed: %08x\n", hres);
5202 ok(V_VT(&v) == VT_DISPATCH, "V_VT(v) = %d\n", V_VT(&v));
5203 test_disp((IUnknown*)V_DISPATCH(&v), &IID_IHTMLRect, NULL, L"[object]");
5204 VariantClear(&v);
5206 IHTMLRectCollection_Release(rects);
5207 IHTMLElement2_Release(elem2);
5210 static void test_elem_col_item(IHTMLElementCollection *col, const WCHAR *n,
5211 const elem_type_t *elem_types, LONG len)
5213 IDispatch *disp;
5214 VARIANT name, index;
5215 DWORD i;
5216 HRESULT hres;
5218 V_VT(&index) = VT_EMPTY;
5219 V_VT(&name) = VT_BSTR;
5220 V_BSTR(&name) = SysAllocString(n);
5222 hres = IHTMLElementCollection_item(col, name, index, &disp);
5223 ok(hres == S_OK, "item failed: %08x\n", hres);
5225 test_elem_collection((IUnknown*)disp, elem_types, len);
5226 IDispatch_Release(disp);
5228 V_VT(&index) = VT_I4;
5230 for(i=0; i<len; i++) {
5231 V_I4(&index) = i;
5232 disp = (void*)0xdeadbeef;
5233 hres = IHTMLElementCollection_item(col, name, index, &disp);
5234 ok(hres == S_OK, "item failed: %08x\n", hres);
5235 ok(disp != NULL, "disp == NULL\n");
5236 if(FAILED(hres) || !disp)
5237 continue;
5239 test_elem_type((IUnknown*)disp, elem_types[i]);
5241 IDispatch_Release(disp);
5244 V_I4(&index) = len;
5245 disp = (void*)0xdeadbeef;
5246 hres = IHTMLElementCollection_item(col, name, index, &disp);
5247 ok(hres == S_OK, "item failed: %08x\n", hres);
5248 ok(disp == NULL, "disp != NULL\n");
5250 V_I4(&index) = -1;
5251 disp = (void*)0xdeadbeef;
5252 hres = IHTMLElementCollection_item(col, name, index, &disp);
5253 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5254 ok(disp == NULL, "disp != NULL\n");
5256 SysFreeString(V_BSTR(&name));
5259 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const WCHAR *id, BOOL expect_success)
5261 IHTMLElementCollection *col;
5262 IHTMLElement *elem;
5263 IDispatch *disp = (void*)0xdeadbeef;
5264 VARIANT name, index;
5265 HRESULT hres;
5267 hres = IHTMLDocument2_get_all(doc, &col);
5268 ok(hres == S_OK, "get_all failed: %08x\n", hres);
5269 ok(col != NULL, "col == NULL\n");
5270 if(FAILED(hres) || !col)
5271 return NULL;
5273 V_VT(&index) = VT_EMPTY;
5274 V_VT(&name) = VT_BSTR;
5275 V_BSTR(&name) = SysAllocString(id);
5277 hres = IHTMLElementCollection_item(col, name, index, &disp);
5278 IHTMLElementCollection_Release(col);
5279 SysFreeString(V_BSTR(&name));
5280 ok(hres == S_OK, "item failed: %08x\n", hres);
5281 if(!expect_success) {
5282 ok(disp == NULL, "disp != NULL\n");
5283 return NULL;
5286 ok(disp != NULL, "disp == NULL\n");
5287 if(!disp)
5288 return NULL;
5290 elem = get_elem_iface((IUnknown*)disp);
5291 IDispatch_Release(disp);
5293 return elem;
5296 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const WCHAR *id)
5298 IHTMLDocument3 *doc3;
5299 IHTMLElement *elem;
5300 BSTR tmp;
5301 HRESULT hres;
5303 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5304 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5306 tmp = SysAllocString(id);
5307 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
5308 SysFreeString(tmp);
5309 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", wine_dbgstr_w(id), hres);
5311 IHTMLDocument3_Release(doc3);
5313 return elem;
5316 static void test_select_elem(IHTMLSelectElement *select)
5318 IDispatch *disp, *disp2;
5319 VARIANT name, index;
5320 HRESULT hres;
5322 test_select_type(select, L"select-one");
5323 test_select_length(select, 2);
5324 test_select_selidx(select, 0);
5325 test_select_put_selidx(select, 1);
5327 test_select_set_value(select, L"val1");
5328 test_select_value(select, L"val1");
5330 test_select_size(select, 0);
5331 test_select_set_size(select, 1, S_OK);
5332 test_select_size(select, 1);
5334 test_select_set_size(select, -1, CTL_E_INVALIDPROPERTYVALUE);
5335 test_select_size(select, 1);
5336 test_select_set_size(select, 3, S_OK);
5337 test_select_size(select, 3);
5339 test_select_name(select, NULL);
5340 test_select_set_name(select, L"select-name");
5341 test_select_name(select, L"select-name");
5342 test_select_form_notfound(select);
5344 test_select_get_disabled(select, VARIANT_FALSE);
5345 test_select_set_disabled(select, VARIANT_TRUE);
5346 test_select_set_disabled(select, VARIANT_FALSE);
5348 disp = NULL;
5349 hres = IHTMLSelectElement_get_options(select, &disp);
5350 ok(hres == S_OK, "get_options failed: %08x\n", hres);
5351 ok(disp != NULL, "options == NULL\n");
5352 ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
5353 IDispatch_Release(disp);
5355 V_VT(&index) = VT_EMPTY;
5356 V_VT(&name) = VT_I4;
5357 V_I4(&name) = -1;
5358 disp = (void*)0xdeadbeef;
5359 hres = IHTMLSelectElement_item(select, name, index, &disp);
5360 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5361 ok(!disp, "disp = %p\n", disp);
5363 V_I4(&name) = 2;
5364 disp = (void*)0xdeadbeef;
5365 hres = IHTMLSelectElement_item(select, name, index, &disp);
5366 ok(hres == S_OK, "item failed: %08x\n", hres);
5367 ok(!disp, "disp = %p\n", disp);
5369 V_I4(&name) = 1;
5370 hres = IHTMLSelectElement_item(select, name, index, NULL);
5371 ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
5373 disp = NULL;
5374 hres = IHTMLSelectElement_item(select, name, index, &disp);
5375 ok(hres == S_OK, "item failed: %08x\n", hres);
5376 ok(disp != NULL, "disp = NULL\n");
5377 test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, &CLSID_HTMLOptionElement, NULL);
5379 V_VT(&index) = VT_I4;
5380 V_I4(&index) = 1;
5381 disp2 = NULL;
5382 hres = IHTMLSelectElement_item(select, name, index, &disp2);
5383 ok(hres == S_OK, "item failed: %08x\n", hres);
5384 ok(disp2 != NULL, "disp = NULL\n");
5385 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
5386 IDispatch_Release(disp2);
5387 IDispatch_Release(disp);
5389 test_select_multiple(select, VARIANT_FALSE);
5390 test_select_set_multiple(select, VARIANT_TRUE);
5391 test_select_remove(select);
5394 static void test_form_item(IHTMLElement *elem)
5396 IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
5397 IDispatch *disp, *disp2;
5398 VARIANT name, index;
5399 HRESULT hres;
5401 V_VT(&index) = VT_EMPTY;
5402 V_VT(&name) = VT_I4;
5403 V_I4(&name) = -1;
5404 disp = (void*)0xdeadbeef;
5405 hres = IHTMLFormElement_item(form, name, index, &disp);
5406 if(compat_mode < COMPAT_IE9)
5407 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5408 else
5409 ok(hres == S_OK, "item failed: %08x\n", hres);
5410 ok(!disp, "disp = %p\n", disp);
5412 V_I4(&name) = 2;
5413 disp = (void*)0xdeadbeef;
5414 hres = IHTMLFormElement_item(form, name, index, &disp);
5415 ok(hres == S_OK, "item failed: %08x\n", hres);
5416 ok(!disp, "disp = %p\n", disp);
5418 V_I4(&name) = 1;
5419 hres = IHTMLFormElement_item(form, name, index, NULL);
5420 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
5422 disp = NULL;
5423 hres = IHTMLFormElement_item(form, name, index, &disp);
5424 ok(hres == S_OK, "item failed: %08x\n", hres);
5425 ok(disp != NULL, "disp = NULL\n");
5426 test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, &CLSID_HTMLInputElement, NULL);
5428 V_VT(&index) = VT_I4;
5429 V_I4(&index) = 1;
5430 disp2 = NULL;
5431 hres = IHTMLFormElement_item(form, name, index, &disp2);
5432 ok(hres == S_OK, "item failed: %08x\n", hres);
5433 ok(disp2 != NULL, "disp = NULL\n");
5434 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
5435 IDispatch_Release(disp2);
5436 IDispatch_Release(disp);
5439 static void test_create_option_elem(IHTMLDocument2 *doc)
5441 IHTMLOptionElement *option;
5443 option = create_option_elem(doc, L"test text", L"test value");
5445 test_option_put_text(option, L"new text");
5446 test_option_put_value(option, L"new value");
5447 test_option_get_index(option, 0);
5448 test_option_defaultSelected_property(option);
5449 test_option_put_selected(option, VARIANT_TRUE);
5450 test_option_put_selected(option, VARIANT_FALSE);
5452 IHTMLOptionElement_Release(option);
5455 static void test_option_form(IUnknown *uoption, IUnknown *uform)
5457 IHTMLOptionElement *option = get_option_iface(uoption);
5458 IHTMLFormElement *form;
5459 HRESULT hres;
5461 hres = IHTMLOptionElement_get_form(option, NULL);
5462 ok(hres == E_POINTER, "got %08x\n, expected E_POINTER\n", hres);
5464 hres = IHTMLOptionElement_get_form(option, &form);
5465 ok(hres == S_OK, "get_form failed: %08x\n", hres);
5466 ok(form != NULL, "form == NULL\n");
5468 ok(iface_cmp(uform, (IUnknown*)form), "Expected %p, got %p\n", uform, form);
5470 IHTMLOptionElement_Release(option);
5471 IHTMLFormElement_Release(form);
5474 static void test_create_img_elem(IHTMLDocument2 *doc)
5476 IHTMLImgElement *img;
5478 img = create_img_elem(doc, 10, 15);
5480 if(img){
5481 test_img_put_width(img, 5);
5482 test_img_put_height(img, 20);
5484 IHTMLImgElement_Release(img);
5485 img = NULL;
5488 img = create_img_elem(doc, -1, -1);
5490 if(img){
5491 test_img_put_width(img, 5);
5492 test_img_put_height(img, 20);
5494 IHTMLImgElement_Release(img);
5498 #define test_doc_selection_type(a,b) _test_doc_selection_type(__LINE__,a,b)
5499 static void _test_doc_selection_type(unsigned line, IHTMLDocument2 *doc, const WCHAR *type)
5501 IHTMLSelectionObject2 *selection2;
5502 IHTMLSelectionObject *selection;
5503 BSTR str;
5504 HRESULT hres;
5506 hres = IHTMLDocument2_get_selection(doc, &selection);
5507 ok_(__FILE__,line)(hres == S_OK, "get_selection failed: %08x\n", hres);
5509 hres = IHTMLSelectionObject_get_type(selection, &str);
5510 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
5511 ok_(__FILE__,line)(!lstrcmpW(str, type), "type = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(type));
5512 SysFreeString(str);
5514 hres = IHTMLSelectionObject_QueryInterface(selection, &IID_IHTMLSelectionObject2, (void**)&selection2);
5515 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLSelectionObject2 iface: %08x\n", hres);
5517 IHTMLSelectionObject_Release(selection);
5519 hres = IHTMLSelectionObject2_get_typeDetail(selection2, &str);
5520 ok_(__FILE__,line)(hres == S_OK, "get_typeDetail failed: %08x\n", hres);
5521 ok_(__FILE__,line)(!lstrcmpW(str, L"undefined"), "typeDetail = %s\n", wine_dbgstr_w(str));
5522 SysFreeString(str);
5524 IHTMLSelectionObject2_Release(selection2);
5527 #define insert_adjacent_elem(a,b,c) _insert_adjacent_elem(__LINE__,a,b,c)
5528 static void _insert_adjacent_elem(unsigned line, IHTMLElement *parent, const WCHAR *where, IHTMLElement *elem)
5530 IHTMLElement2 *elem2 = _get_elem2_iface(line, (IUnknown*)parent);
5531 IHTMLElement *ret_elem = NULL;
5532 BSTR str = SysAllocString(where);
5533 HRESULT hres;
5535 hres = IHTMLElement2_insertAdjacentElement(elem2, str, elem, &ret_elem);
5536 IHTMLElement2_Release(elem2);
5537 SysFreeString(str);
5538 ok_(__FILE__,line)(hres == S_OK, "insertAdjacentElement failed: %08x\n", hres);
5539 ok_(__FILE__,line)(ret_elem == elem, "ret_elem != elem\n");
5540 IHTMLElement_Release(ret_elem);
5543 static void test_insert_adjacent_elems(IHTMLDocument2 *doc, IHTMLElement *parent)
5545 IHTMLElement *elem, *elem2;
5547 static const elem_type_t br_br[] = {ET_BR, ET_BR};
5548 static const elem_type_t br_div_br[] = {ET_BR, ET_DIV, ET_BR};
5550 elem = test_create_elem(doc, L"BR");
5551 elem2 = test_elem_get_parent((IUnknown*)elem);
5552 ok(!elem2, "get_parentElement returned %p\n", elem2);
5553 insert_adjacent_elem(parent, L"BeforeEnd", elem);
5554 IHTMLElement_Release(elem);
5556 test_elem_all((IUnknown*)parent, br_br, 1);
5558 elem = test_create_elem(doc, L"BR");
5559 insert_adjacent_elem(parent, L"beforeend", elem);
5561 test_elem_all((IUnknown*)parent, br_br, 2);
5563 elem2 = test_create_elem(doc, L"DIV");
5564 insert_adjacent_elem(elem, L"beforebegin", elem2);
5565 IHTMLElement_Release(elem2);
5566 IHTMLElement_Release(elem);
5568 test_elem_all((IUnknown*)parent, br_div_br, 3);
5571 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
5573 IHTMLBodyElement *body;
5574 IHTMLTxtRange *range;
5575 IHTMLElement *elem;
5576 HRESULT hres;
5578 elem = doc_get_body(doc);
5579 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
5580 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
5581 IHTMLElement_Release(elem);
5583 hres = IHTMLBodyElement_createTextRange(body, &range);
5584 IHTMLBodyElement_Release(body);
5585 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
5587 return range;
5590 #define range_duplicate(a) _range_duplicate(__LINE__,a)
5591 static IHTMLTxtRange *_range_duplicate(unsigned line, IHTMLTxtRange *range)
5593 IHTMLTxtRange *ret;
5594 HRESULT hres;
5596 hres = IHTMLTxtRange_duplicate(range, &ret);
5597 ok_(__FILE__,line)(hres == S_OK, "duplicate failed: %08x\n", hres);
5599 return ret;
5602 #define test_range_set_end_point(a,b,c,d) _test_range_set_end_point(__LINE__,a,b,c,d)
5603 static void _test_range_set_end_point(unsigned line, IHTMLTxtRange *range, const WCHAR *how,
5604 IHTMLTxtRange *ref_range, HRESULT exhres)
5606 BSTR str = SysAllocString(how);
5607 HRESULT hres;
5609 hres = IHTMLTxtRange_setEndPoint(range, str, ref_range);
5610 ok_(__FILE__,line)(hres == exhres, "setEndPoint failed: %08x, expected %08x\n", hres, exhres);
5611 SysFreeString(str);
5614 static void test_txtrange(IHTMLDocument2 *doc)
5616 IHTMLTxtRange *body_range, *range, *range2;
5617 IHTMLSelectionObject *selection;
5618 IDispatch *disp_range;
5619 IHTMLElement *body;
5620 HRESULT hres;
5622 set_body_html(doc, L"test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br />");
5624 body_range = test_create_body_range(doc);
5626 test_disp((IUnknown*)body_range, &IID_IHTMLTxtRange, NULL, L"[object]");
5628 test_range_text(body_range, L"test abc 123\r\nit's text");
5630 range = range_duplicate(body_range);
5631 range2 = range_duplicate(body_range);
5633 test_range_isequal(range, range2, VARIANT_TRUE);
5635 test_range_text(range, L"test abc 123\r\nit's text");
5636 test_range_text(body_range, L"test abc 123\r\nit's text");
5638 test_range_collapse(range, TRUE);
5639 test_range_isequal(range, range2, VARIANT_FALSE);
5640 test_range_inrange(range, range2, VARIANT_FALSE);
5641 test_range_inrange(range2, range, VARIANT_TRUE);
5642 IHTMLTxtRange_Release(range2);
5644 test_range_expand(range, wordW, VARIANT_TRUE, L"test ");
5645 test_range_expand(range, wordW, VARIANT_FALSE, L"test ");
5646 test_range_move(range, characterW, 2, 2);
5647 test_range_expand(range, wordW, VARIANT_TRUE, L"test ");
5649 test_range_collapse(range, FALSE);
5650 test_range_expand(range, wordW, VARIANT_TRUE, L"abc ");
5652 test_range_collapse(range, FALSE);
5653 test_range_expand(range, wordW, VARIANT_TRUE, L"123");
5654 test_range_expand(range, wordW, VARIANT_FALSE, L"123");
5655 test_range_move(range, characterW, 2, 2);
5656 test_range_expand(range, wordW, VARIANT_TRUE, L"123");
5657 test_range_moveend(range, characterW, -5, -5);
5658 test_range_text(range, NULL);
5659 test_range_moveend(range, characterW, 3, 3);
5660 test_range_text(range, L"c 1");
5661 test_range_expand(range, texteditW, VARIANT_TRUE, L"test abc 123\r\nit's text");
5662 test_range_collapse(range, TRUE);
5663 test_range_move(range, characterW, 4, 4);
5664 test_range_moveend(range, characterW, 1, 1);
5665 test_range_text(range, L" ");
5666 test_range_move(range, wordW, 1, 1);
5667 test_range_moveend(range, characterW, 2, 2);
5668 test_range_text(range, L"ab");
5670 IHTMLTxtRange_Release(range);
5672 range = range_duplicate(body_range);
5674 test_range_text(range, L"test abc 123\r\nit's text");
5675 test_range_move(range, characterW, 3, 3);
5676 test_range_moveend(range, characterW, 1, 1);
5677 test_range_text(range, L"t");
5678 test_range_moveend(range, characterW, 3, 3);
5679 test_range_text(range, L"t ab");
5680 test_range_moveend(range, characterW, -2, -2);
5681 test_range_text(range, L"t ");
5682 test_range_move(range, characterW, 6, 6);
5683 test_range_moveend(range, characterW, 3, 3);
5684 test_range_text(range, L"123");
5685 test_range_moveend(range, characterW, 2, 2);
5686 test_range_text(range, L"123\r\ni");
5688 IHTMLTxtRange_Release(range);
5690 range = range_duplicate(body_range);
5692 test_range_move(range, wordW, 1, 1);
5693 test_range_moveend(range, characterW, 2, 2);
5694 test_range_text(range, L"ab");
5696 test_range_move(range, characterW, -2, -2);
5697 test_range_moveend(range, characterW, 2, 2);
5698 test_range_text(range, L"t ");
5700 test_range_move(range, wordW, 3, 3);
5701 test_range_move(range, wordW, -2, -2);
5702 test_range_moveend(range, characterW, 2, 2);
5703 test_range_text(range, L"ab");
5705 test_range_move(range, characterW, -6, -5);
5706 test_range_moveend(range, characterW, -1, 0);
5707 test_range_moveend(range, characterW, -6, 0);
5708 test_range_move(range, characterW, 2, 2);
5709 test_range_moveend(range, characterW, 2, 2);
5710 test_range_text(range, L"st");
5711 test_range_moveend(range, characterW, -6, -4);
5712 test_range_moveend(range, characterW, 2, 2);
5714 IHTMLTxtRange_Release(range);
5716 range = range_duplicate(body_range);
5718 test_range_move(range, wordW, 2, 2);
5719 test_range_moveend(range, characterW, 2, 2);
5720 test_range_text(range, L"12");
5722 test_range_move(range, characterW, 15, 14);
5723 test_range_move(range, characterW, -2, -2);
5724 test_range_moveend(range, characterW, 3, 2);
5725 test_range_text(range, L"t");
5726 test_range_moveend(range, characterW, -1, -1);
5727 test_range_text(range, L"t");
5728 test_range_expand(range, wordW, VARIANT_TRUE, L"text");
5729 test_range_move(range, characterW, -2, -2);
5730 test_range_moveend(range, characterW, 2, 2);
5731 test_range_text(range, L"s ");
5732 test_range_move(range, characterW, 100, 7);
5733 test_range_move(range, wordW, 1, 0);
5734 test_range_move(range, characterW, -2, -2);
5735 test_range_moveend(range, characterW, 3, 2);
5736 test_range_text(range, L"t");
5738 IHTMLTxtRange_Release(range);
5740 range = range_duplicate(body_range);
5742 test_range_collapse(range, TRUE);
5743 test_range_expand(range, wordW, VARIANT_TRUE, L"test ");
5744 test_range_put_text(range, L"word");
5745 test_range_text(body_range, L"wordabc 123\r\nit's text");
5746 test_range_text(range, NULL);
5747 test_range_moveend(range, characterW, 3, 3);
5748 test_range_text(range, L"abc");
5749 test_range_movestart(range, characterW, -2, -2);
5750 test_range_text(range, L"rdabc");
5751 test_range_movestart(range, characterW, 3, 3);
5752 test_range_text(range, L"bc");
5753 test_range_movestart(range, characterW, 4, 4);
5754 test_range_text(range, NULL);
5755 test_range_movestart(range, characterW, -3, -3);
5756 test_range_text(range, L"c 1");
5757 test_range_movestart(range, characterW, -7, -6);
5758 test_range_text(range, L"wordabc 1");
5759 test_range_movestart(range, characterW, 100, 22);
5760 test_range_text(range, NULL);
5762 IHTMLTxtRange_Release(range);
5764 hres = IHTMLDocument2_get_selection(doc, &selection);
5765 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
5767 test_disp((IUnknown*)selection, &IID_IHTMLSelectionObject, NULL, L"[object]");
5768 test_ifaces((IUnknown*)selection, selection_iids);
5770 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
5771 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
5772 IHTMLSelectionObject_Release(selection);
5774 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
5775 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
5776 IDispatch_Release(disp_range);
5778 test_range_text(range, NULL);
5779 test_range_moveend(range, characterW, 3, 3);
5780 test_range_text(range, L"wor");
5781 test_range_parent(range, ET_BODY);
5782 test_range_expand(range, texteditW, VARIANT_TRUE, L"wordabc 123\r\nit's text");
5783 test_range_expand(range, texteditW, VARIANT_TRUE, L"wordabc 123\r\nit's text");
5784 test_range_move(range, characterW, 3, 3);
5785 test_range_expand(range, wordW, VARIANT_TRUE, L"wordabc ");
5786 test_range_moveend(range, characterW, -4, -4);
5787 test_range_put_text(range, L"abc def ");
5788 test_range_expand(range, texteditW, VARIANT_TRUE, L"abc def abc 123\r\nit's text");
5789 test_range_move(range, wordW, 1, 1);
5790 test_range_movestart(range, characterW, -1, -1);
5791 test_range_text(range, L" ");
5792 test_range_move(range, wordW, 1, 1);
5793 test_range_moveend(range, characterW, 3, 3);
5794 test_range_text(range, L"def");
5795 test_range_put_text(range, L"xyz");
5796 test_range_moveend(range, characterW, 1, 1);
5797 test_range_move(range, wordW, 1, 1);
5798 test_range_moveend(range, characterW, 2, 2);
5799 test_range_text(range, L"ab");
5801 body = doc_get_body(doc);
5803 hres = IHTMLTxtRange_moveToElementText(range, body);
5804 ok(hres == S_OK, "moveToElementText failed: %08x\n", hres);
5806 test_range_text(range, L"abc xyz abc 123\r\nit's text");
5807 test_range_parent(range, ET_BODY);
5809 test_range_move(range, wordW, 1, 1);
5810 test_range_moveend(range, characterW, 12, 12);
5811 test_range_text(range, L"xyz abc 123");
5813 test_range_collapse(range, VARIANT_TRUE);
5814 test_range_paste_html(range, L"<br>paste<br>");
5815 test_range_text(range, NULL);
5817 test_range_moveend(range, characterW, 3, 3);
5818 test_range_text(range, L"xyz");
5820 hres = IHTMLTxtRange_moveToElementText(range, body);
5821 ok(hres == S_OK, "moveToElementText failed: %08x\n", hres);
5823 test_range_text(range, L"abc \r\npaste\r\nxyz abc 123\r\nit's text");
5825 test_range_move(range, wordW, 2, 2);
5826 test_range_collapse(range, VARIANT_TRUE);
5827 test_range_moveend(range, characterW, 5, 5);
5828 test_range_text(range, L"paste");
5830 range2 = range_duplicate(range);
5832 test_range_set_end_point(range, L"starttostart", body_range, S_OK);
5833 test_range_text(range, L"abc \r\npaste");
5835 test_range_set_end_point(range, L"endtoend", body_range, S_OK);
5836 test_range_text(range, L"abc \r\npaste\r\nxyz abc 123\r\nit's text");
5838 test_range_set_end_point(range, L"starttoend", range2, S_OK);
5839 test_range_text(range, L"\r\nxyz abc 123\r\nit's text");
5841 test_range_set_end_point(range, L"starttostart", body_range, S_OK);
5842 test_range_set_end_point(range, L"endtostart", range2, S_OK);
5843 test_range_text(range, L"abc ");
5845 test_range_set_end_point(range, L"starttoend", body_range, S_OK);
5846 test_range_text(range, L"paste\r\nxyz abc 123\r\nit's text");
5848 test_range_set_end_point(range, L"EndToStart", body_range, S_OK);
5849 test_range_text(range, L"abc ");
5851 test_range_set_end_point(range, L"xxx", body_range, E_INVALIDARG);
5853 hres = IHTMLTxtRange_select(range);
5854 ok(hres == S_OK, "select failed: %08x\n", hres);
5856 test_doc_selection_type(doc, L"Text");
5858 IHTMLTxtRange_Release(range);
5859 IHTMLTxtRange_Release(range2);
5860 IHTMLTxtRange_Release(body_range);
5861 IHTMLElement_Release(body);
5863 set_body_html(doc, L"<html><body>abc<hr />123<br /><hr />def</body></html>");
5865 range = test_create_body_range(doc);
5867 test_range_text(range, L"abc\r\n\r\n123\r\n\r\n\r\ndef");
5868 test_range_move(range, characterW, 5, 5);
5869 test_range_moveend(range, characterW, 1, 1);
5870 test_range_text(range, L"2");
5871 test_range_move(range, characterW, -3, -3);
5872 test_range_moveend(range, characterW, 3, 3);
5873 test_range_text(range, L"c\r\n\r\n1");
5874 test_range_collapse(range, VARIANT_FALSE);
5875 test_range_moveend(range, characterW, 4, 4);
5876 test_range_text(range, L"23");
5877 test_range_moveend(range, characterW, 1, 1);
5878 test_range_text(range, L"23\r\n\r\n\r\nd");
5879 test_range_moveend(range, characterW, -1, -1);
5880 test_range_text(range, L"23");
5881 test_range_moveend(range, characterW, -1, -1);
5882 test_range_text(range, L"23");
5883 test_range_moveend(range, characterW, -2, -2);
5884 test_range_text(range, L"2");
5886 IHTMLTxtRange_Release(range);
5889 static void test_markup_services(IHTMLDocument2 *doc)
5891 IMarkupServices *markup_services;
5892 IMarkupPointer *markup_pointer;
5893 IMarkupPointer2 *markup_pointer2;
5894 HRESULT hres;
5896 hres = IHTMLDocument2_QueryInterface(doc, &IID_IMarkupServices, (void**)&markup_services);
5897 ok(hres == S_OK, "Could not get IMarkupServices iface: %08x\n", hres);
5899 hres = IMarkupServices_CreateMarkupPointer(markup_services, &markup_pointer);
5900 ok(hres == S_OK, "CreateMarkupPointer failed: %08x\n", hres);
5902 hres = IMarkupPointer_QueryInterface(markup_pointer, &IID_IMarkupPointer2, (void**)&markup_pointer2);
5903 ok(hres == S_OK, "Could not get IMarkupPointer2 iface: %08x\n", hres);
5905 IMarkupPointer_Release(markup_pointer);
5906 IMarkupPointer2_Release(markup_pointer2);
5907 IMarkupServices_Release(markup_services);
5910 static void test_range(IHTMLDocument2 *doc)
5912 if(is_ie9plus) {
5913 IDocumentRange *doc_range;
5914 IHTMLDOMRange *range;
5915 HRESULT hres;
5917 hres = IHTMLDocument2_QueryInterface(doc, &IID_IDocumentRange, (void **)&doc_range);
5918 ok(hres == S_OK, "Failed to get IDocumentRange: %08x\n", hres);
5919 if (FAILED(hres))
5920 return;
5922 hres = IDocumentRange_createRange(doc_range, &range);
5923 ok(hres == S_OK, "Failed to create range, %08x\n", hres);
5925 test_disp((IUnknown *)range, &DIID_DispHTMLDOMRange, NULL, NULL);
5927 IHTMLDOMRange_Release(range);
5929 IDocumentRange_Release(doc_range);
5932 test_txtrange(doc);
5933 test_markup_services(doc);
5936 #define test_compatmode(a,b) _test_compatmode(__LINE__,a,b)
5937 static void _test_compatmode(unsigned line, IHTMLDocument2 *doc2, const WCHAR *excompat)
5939 IHTMLDocument5 *doc = get_htmldoc5_iface((IUnknown*)doc2);
5940 BSTR str;
5941 HRESULT hres;
5943 hres = IHTMLDocument5_get_compatMode(doc, &str);
5944 ok_(__FILE__,line)(hres == S_OK, "get_compatMode failed: %08x\n", hres);
5945 ok_(__FILE__,line)(!lstrcmpW(str, excompat), "compatMode = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(excompat));
5946 SysFreeString(str);
5948 IHTMLDocument5_Release(doc);
5951 static void test_location(IHTMLDocument2 *doc)
5953 IHTMLLocation *location, *location2;
5954 IHTMLWindow2 *window;
5955 BSTR str;
5956 ULONG ref;
5957 HRESULT hres;
5959 hres = IHTMLDocument2_get_location(doc, &location);
5960 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5962 hres = IHTMLDocument2_get_location(doc, &location2);
5963 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5965 ok(location == location2, "location != location2\n");
5966 IHTMLLocation_Release(location2);
5968 hres = IHTMLDocument2_get_parentWindow(doc, &window);
5969 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
5971 hres = IHTMLWindow2_get_location(window, &location2);
5972 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5973 ok(location == location2, "location != location2\n");
5974 IHTMLLocation_Release(location2);
5976 test_ifaces((IUnknown*)location, location_iids);
5977 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, NULL, L"about:blank");
5979 hres = IHTMLLocation_get_pathname(location, &str);
5980 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
5981 ok(!lstrcmpW(str, L"blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
5982 SysFreeString(str);
5984 hres = IHTMLLocation_get_href(location, NULL);
5985 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
5987 hres = IHTMLLocation_get_href(location, &str);
5988 ok(hres == S_OK, "get_href failed: %08x\n", hres);
5989 ok(!lstrcmpW(str, L"about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
5990 SysFreeString(str);
5992 ref = IHTMLLocation_Release(location);
5993 ok(!ref, "location should be destroyed here\n");
5996 static void test_plugins_col(IHTMLDocument2 *doc)
5998 IHTMLPluginsCollection *col, *col2;
5999 IHTMLWindow2 *window;
6000 IOmNavigator *nav;
6001 ULONG ref;
6002 LONG len;
6003 HRESULT hres;
6005 window = get_doc_window(doc);
6006 hres = IHTMLWindow2_get_navigator(window, &nav);
6007 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
6008 IHTMLWindow2_Release(window);
6010 hres = IOmNavigator_get_plugins(nav, &col);
6011 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
6013 hres = IOmNavigator_get_plugins(nav, &col2);
6014 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
6015 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
6016 IHTMLPluginsCollection_Release(col2);
6018 test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, NULL, L"[object]");
6020 len = 0xdeadbeef;
6021 hres = IHTMLPluginsCollection_get_length(col, &len);
6022 ok(hres == S_OK, "get_length failed: %08x\n", hres);
6023 ok(!len, "length = %d\n", len);
6025 hres = IHTMLPluginsCollection_refresh(col, VARIANT_FALSE);
6026 ok(hres == S_OK, "refresh failed: %08x\n", hres);
6028 hres = IHTMLPluginsCollection_refresh(col, VARIANT_TRUE);
6029 ok(hres == S_OK, "refresh failed: %08x\n", hres);
6031 ref = IHTMLPluginsCollection_Release(col);
6032 ok(!ref, "ref=%d\n", ref);
6034 IOmNavigator_Release(nav);
6037 static void test_mime_types_col(IOmNavigator *nav)
6039 IHTMLMimeTypesCollection *col, *col2;
6040 LONG length;
6041 ULONG ref;
6042 HRESULT hres;
6044 hres = IOmNavigator_get_mimeTypes(nav, &col);
6045 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
6047 hres = IOmNavigator_get_mimeTypes(nav, &col2);
6048 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
6049 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
6050 IHTMLMimeTypesCollection_Release(col2);
6052 test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, NULL, L"[object]");
6054 length = 0xdeadbeef;
6055 hres = IHTMLMimeTypesCollection_get_length(col, &length);
6056 ok(hres == S_OK, "get_length failed: %08x\n", hres);
6057 ok(!length, "length = %d\n", length);
6059 ref = IHTMLMimeTypesCollection_Release(col);
6060 ok(!ref, "ref=%d\n", ref);
6063 #define test_framebase_name(a,b) _test_framebase_name(__LINE__,a,b)
6064 static void _test_framebase_name(unsigned line, IHTMLElement *elem, const WCHAR *name)
6066 BSTR str = (void*)0xdeadbeef;
6067 IHTMLFrameBase *fbase;
6068 HRESULT hres;
6070 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6071 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6073 hres = IHTMLFrameBase_get_name(fbase, &str);
6074 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
6075 if(name)
6076 ok_(__FILE__,line)(!lstrcmpW(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(name));
6077 else
6078 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
6079 SysFreeString(str);
6081 IHTMLFrameBase_Release(fbase);
6084 #define test_framebase_put_name(a,b) _test_framebase_put_name(__LINE__,a,b)
6085 static void _test_framebase_put_name(unsigned line, IHTMLElement *elem, const WCHAR *name)
6087 IHTMLFrameBase *fbase;
6088 HRESULT hres;
6089 BSTR str;
6091 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6092 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6094 str = name ? SysAllocString(name) : NULL;
6095 hres = IHTMLFrameBase_put_name(fbase, str);
6096 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
6097 SysFreeString(str);
6099 _test_framebase_name(line, elem, name);
6100 IHTMLFrameBase_Release(fbase);
6103 #define test_framebase_src(a,b) _test_framebase_src(__LINE__,a,b)
6104 static void _test_framebase_src(unsigned line, IHTMLElement *elem, const WCHAR *src)
6106 BSTR str = (void*)0xdeadbeef;
6107 IHTMLFrameBase *fbase;
6108 HRESULT hres;
6110 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
6111 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6113 hres = IHTMLFrameBase_get_src(fbase, &str);
6114 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_src failed: 0x%08x\n", hres);
6115 if(src)
6116 ok_(__FILE__,line)(!lstrcmpW(str, src), "src = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(src));
6117 else
6118 ok_(__FILE__,line)(!str, "src = %s, expected NULL\n", wine_dbgstr_w(str));
6119 SysFreeString(str);
6121 IHTMLFrameBase_Release(fbase);
6124 #define test_framebase_marginheight(a,b) _test_framebase_marginheight(__LINE__,a,b)
6125 static void _test_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const WCHAR *exval)
6127 VARIANT v;
6128 HRESULT hres;
6130 hres = IHTMLFrameBase_get_marginHeight(framebase, &v);
6131 ok_(__FILE__,line)(hres == S_OK, "get_marginHeight failed: %08x\n", hres);
6132 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginHeight) = %d\n", V_VT(&v));
6133 if(exval)
6134 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exval), "marginHeight = %s\n", wine_dbgstr_w(V_BSTR(&v)));
6135 else
6136 ok_(__FILE__,line)(!V_BSTR(&v), "marginHeight = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6137 VariantClear(&v);
6140 #define set_framebase_marginheight(a,b) _set_framebase_marginheight(__LINE__,a,b)
6141 static void _set_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const WCHAR *val)
6143 VARIANT v;
6144 HRESULT hres;
6146 V_VT(&v) = VT_BSTR;
6147 V_BSTR(&v) = SysAllocString(val);
6148 hres = IHTMLFrameBase_put_marginHeight(framebase, v);
6149 ok_(__FILE__,line)(hres == S_OK, "put_marginHeight failed: %08x\n", hres);
6150 VariantClear(&v);
6153 #define test_framebase_marginwidth(a,b) _test_framebase_marginwidth(__LINE__,a,b)
6154 static void _test_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const WCHAR *exval)
6156 VARIANT v;
6157 HRESULT hres;
6159 hres = IHTMLFrameBase_get_marginWidth(framebase, &v);
6160 ok_(__FILE__,line)(hres == S_OK, "get_marginWidth failed: %08x\n", hres);
6161 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginWidth) = %d\n", V_VT(&v));
6162 if(exval)
6163 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exval), "marginWidth = %s\n", wine_dbgstr_w(V_BSTR(&v)));
6164 else
6165 ok_(__FILE__,line)(!V_BSTR(&v), "marginWidth = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6166 VariantClear(&v);
6169 #define set_framebase_marginwidth(a,b) _set_framebase_marginwidth(__LINE__,a,b)
6170 static void _set_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const WCHAR *val)
6172 VARIANT v;
6173 HRESULT hres;
6175 V_VT(&v) = VT_BSTR;
6176 V_BSTR(&v) = SysAllocString(val);
6177 hres = IHTMLFrameBase_put_marginWidth(framebase, v);
6178 ok_(__FILE__,line)(hres == S_OK, "put_marginWidth failed: %08x\n", hres);
6179 VariantClear(&v);
6182 static void test_framebase(IUnknown *unk)
6184 IHTMLFrameBase *fbase;
6185 BSTR str;
6186 HRESULT hres;
6188 /* get/put scrolling */
6189 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFrameBase, (void**)&fbase);
6190 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
6192 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6193 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6194 ok(!lstrcmpW(str, L"auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
6195 SysFreeString(str);
6197 str = SysAllocString(L"no");
6198 hres = IHTMLFrameBase_put_scrolling(fbase, str);
6199 ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
6200 SysFreeString(str);
6202 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6203 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6204 ok(!lstrcmpW(str, L"no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6205 SysFreeString(str);
6207 str = SysAllocString(L"junk");
6208 hres = IHTMLFrameBase_put_scrolling(fbase, str);
6209 ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
6210 "with E_INVALIDARG, instead: 0x%08x\n", hres);
6211 SysFreeString(str);
6213 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
6214 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
6215 ok(!lstrcmpW(str, L"no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
6216 SysFreeString(str);
6218 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
6219 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
6220 ok(!str, "frameBorder = %s\n", wine_dbgstr_w(str));
6222 str = SysAllocString(L"1");
6223 hres = IHTMLFrameBase_put_frameBorder(fbase, str);
6224 ok(hres == S_OK, "put_frameBorder failed: %08x\n", hres);
6225 SysFreeString(str);
6227 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
6228 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
6229 ok(!lstrcmpW(str, L"1"), "frameBorder = %s, expected \"1\"\n", wine_dbgstr_w(str));
6230 SysFreeString(str);
6232 test_framebase_marginheight(fbase, NULL);
6233 set_framebase_marginheight(fbase, L"1px");
6234 test_framebase_marginheight(fbase, L"1");
6236 test_framebase_marginwidth(fbase, NULL);
6237 set_framebase_marginwidth(fbase, L"2px");
6238 test_framebase_marginwidth(fbase, L"2");
6240 IHTMLFrameBase_Release(fbase);
6243 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
6244 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
6246 WCHAR buf[64];
6247 int res;
6249 if(pLCIDToLocaleName) {
6250 res = pLCIDToLocaleName(lcid, buf, ARRAY_SIZE(buf), 0);
6251 ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
6252 ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
6253 }else {
6254 win_skip("LCIDToLocaleName not available, unable to test language string\n");
6255 ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
6259 #define test_table_length(t,l) _test_table_length(__LINE__,t,l)
6260 static void _test_table_length(unsigned line, IHTMLTable *table, LONG expect)
6262 IHTMLElementCollection *col;
6263 HRESULT hres;
6264 LONG len;
6266 hres = IHTMLTable_get_rows(table, &col);
6267 ok_(__FILE__,line)(hres == S_OK, "get_rows failed: %08x\n", hres);
6268 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
6269 if (hres != S_OK || col == NULL)
6270 return;
6271 hres = IHTMLElementCollection_get_length(col, &len);
6272 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
6273 ok_(__FILE__,line)(len == expect, "Expect %d, got %d\n", expect, len);
6275 IHTMLElementCollection_Release(col);
6278 static void test_navigator(IHTMLDocument2 *doc)
6280 IHTMLWindow2 *window;
6281 IOmNavigator *navigator, *navigator2;
6282 VARIANT_BOOL b;
6283 WCHAR buf[512];
6284 char bufa[512];
6285 DWORD size;
6286 ULONG ref;
6287 BSTR bstr;
6288 HRESULT hres;
6290 static const WCHAR v40[] = {'4','.','0'};
6291 static char ua[] = "1234567890xxxABC";
6293 hres = IHTMLDocument2_get_parentWindow(doc, &window);
6294 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
6296 hres = IHTMLWindow2_get_navigator(window, &navigator);
6297 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
6298 ok(navigator != NULL, "navigator == NULL\n");
6299 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, NULL, L"[object]");
6301 hres = IHTMLWindow2_get_navigator(window, &navigator2);
6302 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
6303 todo_wine
6304 ok(navigator != navigator2, "navigator2 != navigator\n");
6305 IOmNavigator_Release(navigator2);
6307 hres = IHTMLWindow2_get_clientInformation(window, &navigator2);
6308 ok(hres == S_OK, "get_clientInformation failed: %08x\n", hres);
6309 ok(iface_cmp((IUnknown*)navigator, (IUnknown*)navigator2), "navigator2 != navigator\n");
6310 IOmNavigator_Release(navigator2);
6312 IHTMLWindow2_Release(window);
6314 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
6315 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
6316 ok(!lstrcmpW(bstr, L"Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
6317 SysFreeString(bstr);
6319 bstr = NULL;
6320 hres = IOmNavigator_get_appName(navigator, &bstr);
6321 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
6322 ok(!lstrcmpW(bstr, L"Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
6323 SysFreeString(bstr);
6325 bstr = NULL;
6326 hres = IOmNavigator_get_platform(navigator, &bstr);
6327 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
6328 ok(!lstrcmpW(bstr, sizeof(void*) == 8 ? L"Win64" : L"Win32")
6329 || (sizeof(void*) == 8 && broken(!lstrcmpW(bstr, L"Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
6330 SysFreeString(bstr);
6332 bstr = NULL;
6333 hres = IOmNavigator_get_cpuClass(navigator, &bstr);
6334 ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
6335 ok(!lstrcmpW(bstr, sizeof(void*) == 8 ? L"x64" : L"x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
6336 SysFreeString(bstr);
6338 bstr = NULL;
6339 hres = IOmNavigator_get_appVersion(navigator, &bstr);
6340 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
6341 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
6342 SysFreeString(bstr);
6344 bstr = NULL;
6345 hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
6346 ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
6347 test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
6348 SysFreeString(bstr);
6350 if (pGetUserDefaultUILanguage)
6352 bstr = NULL;
6353 hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
6354 ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
6355 test_language_string(bstr, pGetUserDefaultUILanguage());
6356 SysFreeString(bstr);
6358 else
6359 win_skip("GetUserDefaultUILanguage not available\n");
6361 bstr = NULL;
6362 hres = IOmNavigator_get_userLanguage(navigator, &bstr);
6363 ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
6364 test_language_string(bstr, LOCALE_USER_DEFAULT);
6365 SysFreeString(bstr);
6367 hres = IOmNavigator_toString(navigator, NULL);
6368 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
6370 bstr = NULL;
6371 hres = IOmNavigator_toString(navigator, &bstr);
6372 ok(hres == S_OK, "toString failed: %08x\n", hres);
6373 ok(!lstrcmpW(bstr, L"[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
6374 SysFreeString(bstr);
6376 b = 100;
6377 hres = IOmNavigator_get_onLine(navigator, &b);
6378 ok(hres == S_OK, "get_onLine failed: %08x\n", hres);
6379 ok(b == VARIANT_TRUE, "onLine = %x\n", b);
6381 size = sizeof(buf);
6382 hres = ObtainUserAgentString(0, bufa, &size);
6383 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
6385 MultiByteToWideChar(CP_ACP, 0, bufa, size, buf, ARRAY_SIZE(buf));
6387 bstr = NULL;
6388 hres = IOmNavigator_get_userAgent(navigator, &bstr);
6389 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
6390 ok(!lstrcmpW(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf));
6391 SysFreeString(bstr);
6393 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, ua, sizeof(ua), 0);
6394 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
6395 MultiByteToWideChar(CP_ACP, 0, ua, -1, buf, ARRAY_SIZE(buf));
6397 hres = IOmNavigator_get_appVersion(navigator, &bstr);
6398 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
6399 ok(!lstrcmpW(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), wine_dbgstr_w(buf+8));
6400 SysFreeString(bstr);
6402 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, buf, lstrlenW(buf), 0);
6403 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
6405 bstr = NULL;
6406 hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
6407 ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
6408 ok(bstr != NULL, "appMinorVersion returned NULL\n");
6409 SysFreeString(bstr);
6411 test_mime_types_col(navigator);
6413 ref = IOmNavigator_Release(navigator);
6414 todo_wine
6415 ok(!ref, "navigator should be destroyed here\n");
6418 static void test_screen(IHTMLWindow2 *window)
6420 IHTMLScreen *screen, *screen2;
6421 IDispatchEx *dispex;
6422 RECT work_area;
6423 LONG l, exl;
6424 HDC hdc;
6425 HRESULT hres;
6427 screen = NULL;
6428 hres = IHTMLWindow2_get_screen(window, &screen);
6429 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
6430 ok(screen != NULL, "screen == NULL\n");
6432 screen2 = NULL;
6433 hres = IHTMLWindow2_get_screen(window, &screen2);
6434 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
6435 ok(screen2 != NULL, "screen == NULL\n");
6436 ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
6437 IHTMLScreen_Release(screen2);
6439 hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
6440 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
6441 if(SUCCEEDED(hres)) {
6442 test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, NULL, L"[object]");
6443 IDispatchEx_Release(dispex);
6446 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
6448 exl = GetDeviceCaps(hdc, HORZRES);
6449 l = 0xdeadbeef;
6450 hres = IHTMLScreen_get_width(screen, &l);
6451 ok(hres == S_OK, "get_width failed: %08x\n", hres);
6452 ok(l == exl, "width = %d, expected %d\n", l, exl);
6454 exl = GetDeviceCaps(hdc, VERTRES);
6455 l = 0xdeadbeef;
6456 hres = IHTMLScreen_get_height(screen, &l);
6457 ok(hres == S_OK, "get_height failed: %08x\n", hres);
6458 ok(l == exl, "height = %d, expected %d\n", l, exl);
6460 exl = GetDeviceCaps(hdc, BITSPIXEL);
6461 l = 0xdeadbeef;
6462 hres = IHTMLScreen_get_colorDepth(screen, &l);
6463 ok(hres == S_OK, "get_height failed: %08x\n", hres);
6464 ok(l == exl, "height = %d, expected %d\n", l, exl);
6466 DeleteObject(hdc);
6468 SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
6470 l = 0xdeadbeef;
6471 hres = IHTMLScreen_get_availHeight(screen, &l);
6472 ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
6473 ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
6475 l = 0xdeadbeef;
6476 hres = IHTMLScreen_get_availWidth(screen, &l);
6477 ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
6478 ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
6480 IHTMLScreen_Release(screen);
6483 static void test_default_selection(IHTMLDocument2 *doc)
6485 IHTMLSelectionObject *selection;
6486 IHTMLTxtRange *range;
6487 IDispatch *disp;
6488 HRESULT hres;
6490 test_doc_selection_type(doc, L"None");
6492 hres = IHTMLDocument2_get_selection(doc, &selection);
6493 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
6495 hres = IHTMLSelectionObject_createRange(selection, &disp);
6496 IHTMLSelectionObject_Release(selection);
6497 ok(hres == S_OK, "createRange failed: %08x\n", hres);
6499 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
6500 IDispatch_Release(disp);
6501 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
6503 test_range_text(range, NULL);
6504 IHTMLTxtRange_Release(range);
6507 static void test_doc_dir(IHTMLDocument2 *doc2)
6509 IHTMLDocument3 *doc = get_doc3_iface(doc2);
6510 BSTR dir;
6511 HRESULT hres;
6513 dir = (BSTR)0xdeadbeef;
6514 hres = IHTMLDocument3_get_dir(doc, &dir);
6515 ok(hres == S_OK, "get_dir failed: %08x\n", hres);
6516 ok(!dir, "dir = %s\n", wine_dbgstr_w(dir));
6518 dir = SysAllocString(L"rtl");
6519 hres = IHTMLDocument3_put_dir(doc, dir);
6520 ok(hres == S_OK, "put_dir failed: %08x\n", hres);
6521 SysFreeString(dir);
6523 dir = NULL;
6524 hres = IHTMLDocument3_get_dir(doc, &dir);
6525 ok(hres == S_OK, "get_dir failed: %08x\n", hres);
6526 ok(!lstrcmpW(dir, L"rtl"), "dir = %s\n", wine_dbgstr_w(dir));
6527 SysFreeString(dir);
6529 dir = SysAllocString(L"ltr");
6530 hres = IHTMLDocument3_put_dir(doc, dir);
6531 ok(hres == S_OK, "put_dir failed: %08x\n", hres);
6532 SysFreeString(dir);
6534 dir = NULL;
6535 hres = IHTMLDocument3_get_dir(doc, &dir);
6536 ok(hres == S_OK, "get_dir failed: %08x\n", hres);
6537 ok(!lstrcmpW(dir, L"ltr"), "dir = %s\n", wine_dbgstr_w(dir));
6538 SysFreeString(dir);
6540 IHTMLDocument3_Release(doc);
6543 static void test_unique_id(IHTMLDocument2 *doc, IHTMLElement *elem)
6545 IHTMLDocument3 *doc3 = get_doc3_iface(doc);
6546 IHTMLUniqueName *unique_name;
6547 WCHAR buf[32];
6548 BSTR id, id2;
6549 LONG num;
6550 HRESULT hres;
6552 static const WCHAR prefixW[] = {'m','s','_','_','i','d',0};
6554 hres = IHTMLDocument3_get_uniqueID(doc3, &id);
6555 ok(hres == S_OK, "get_uniqueID failed: %08x\n", hres);
6556 ok(SysStringLen(id) >= ARRAY_SIZE(prefixW), "id %s too short\n", wine_dbgstr_w(id));
6558 hres = IHTMLDocument3_get_uniqueID(doc3, &id2);
6559 ok(hres == S_OK, "get_uniqueID failed: %08x\n", hres);
6560 ok(SysStringLen(id2) >= ARRAY_SIZE(prefixW), "id %s too short\n", wine_dbgstr_w(id2));
6562 ok(lstrcmpW(id, id2), "same unique ids %s\n", wine_dbgstr_w(id));
6564 id[ARRAY_SIZE(prefixW)-1] = 0;
6565 ok(!lstrcmpW(id, prefixW), "unexpected prefix %s\n", wine_dbgstr_w(id));
6566 id2[ARRAY_SIZE(prefixW)-1] = 0;
6567 ok(!lstrcmpW(id2, prefixW), "unexpected prefix %s\n", wine_dbgstr_w(id2));
6569 SysFreeString(id);
6570 SysFreeString(id2);
6572 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLUniqueName, (void**)&unique_name);
6573 ok(hres == S_OK, "Could not get IHTMLUniqueName iface: %08x\n", hres);
6575 hres = IHTMLUniqueName_get_uniqueID(unique_name, &id);
6576 ok(hres == S_OK, "get_uniqueName failed: %08x\n", hres);
6578 hres = IHTMLUniqueName_get_uniqueID(unique_name, &id2);
6579 ok(hres == S_OK, "get_uniqueName failed: %08x\n", hres);
6580 ok(!lstrcmpW(id, id2), "unique names differ\n");
6582 hres = IHTMLUniqueName_get_uniqueNumber(unique_name, &num);
6583 ok(hres == S_OK, "get_uniqueName failed: %08x\n", hres);
6584 ok(num, "num = 0\n");
6586 swprintf(buf, ARRAY_SIZE(buf), L"ms__id%u", num);
6587 ok(!lstrcmpW(id, buf), "unexpected id %s\n", wine_dbgstr_w(id));
6589 SysFreeString(id);
6590 SysFreeString(id2);
6592 IHTMLUniqueName_Release(unique_name);
6593 IHTMLDocument3_Release(doc3);
6596 static void test_doc_elem(IHTMLDocument2 *doc)
6598 IHTMLNamespaceCollection *namespaces;
6599 IHTMLDocument2 *doc_node, *owner_doc;
6600 IHTMLDocument4 *doc4;
6601 IHTMLElement *elem;
6602 IHTMLDocument3 *doc3;
6603 IDispatch *disp;
6604 LONG l;
6605 HRESULT hres;
6606 BSTR bstr;
6608 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
6609 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
6611 hres = IHTMLDocument2_toString(doc, &bstr);
6612 ok(hres == S_OK, "toString failed: %08x\n", hres);
6613 ok(!lstrcmpW(bstr, L"[object]"),
6614 "toString returned %s, expected [object]\n", wine_dbgstr_w(bstr));
6615 SysFreeString(bstr);
6617 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
6618 IHTMLDocument3_Release(doc3);
6619 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
6621 test_node_name((IUnknown*)elem, L"HTML");
6622 test_elem_tag((IUnknown*)elem, L"HTML");
6623 test_elem_set_outertext_fail(elem);
6625 doc_node = get_doc_node(doc);
6626 owner_doc = get_owner_doc((IUnknown*)elem);
6627 ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
6628 IHTMLDocument2_Release(owner_doc);
6630 owner_doc = get_owner_doc((IUnknown*)doc_node);
6631 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
6632 IHTMLDocument2_Release(doc_node);
6634 test_elem_client_rect((IUnknown*)elem);
6635 test_unique_id(doc, elem);
6636 test_doc_dir(doc);
6638 IHTMLElement_Release(elem);
6640 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument4, (void**)&doc4);
6641 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument4) failed: %08x\n", hres);
6643 hres = IHTMLDocument4_get_namespaces(doc4, &disp);
6644 ok(hres == S_OK, "get_namespaces failed: %08x\n", hres);
6646 test_disp((IUnknown*)disp, &DIID_DispHTMLNamespaceCollection, NULL, L"[object]");
6648 hres = IDispatch_QueryInterface(disp, &IID_IHTMLNamespaceCollection, (void**)&namespaces);
6649 ok(hres == S_OK, "Could not get IHTMLNamespaceCollection iface: %08x\n", hres);
6651 hres = IHTMLNamespaceCollection_get_length(namespaces, &l);
6652 ok(hres == S_OK, "get_length failed: %08x\n", hres);
6653 ok(l == 0, "length = %d\n", l);
6655 IHTMLNamespaceCollection_Release(namespaces);
6656 IDispatch_Release(disp);
6657 IHTMLDocument4_Release(doc4);
6660 static void test_default_body(IHTMLBodyElement *body)
6662 LONG l;
6663 BSTR bstr;
6664 HRESULT hres;
6665 VARIANT v;
6667 bstr = (void*)0xdeadbeef;
6668 hres = IHTMLBodyElement_get_background(body, &bstr);
6669 ok(hres == S_OK, "get_background failed: %08x\n", hres);
6670 ok(bstr == NULL, "bstr != NULL\n");
6672 l = elem_get_scroll_height((IUnknown*)body);
6673 ok(l != -1, "scrollHeight == -1\n");
6674 l = elem_get_scroll_width((IUnknown*)body);
6675 ok(l != -1, "scrollWidth == -1\n");
6676 l = elem_get_scroll_top((IUnknown*)body);
6677 ok(!l, "scrollTop = %d\n", l);
6678 elem_get_scroll_left((IUnknown*)body);
6680 test_elem_dir((IUnknown*)body, NULL);
6681 set_elem_dir((IUnknown*)body, L"ltr");
6683 /* get_text tests */
6684 hres = IHTMLBodyElement_get_text(body, &v);
6685 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6686 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6687 ok(V_BSTR(&v) == NULL, "bstr != NULL\n");
6689 /* get_text - Invalid Text */
6690 V_VT(&v) = VT_BSTR;
6691 V_BSTR(&v) = SysAllocString(L"Invalid");
6692 hres = IHTMLBodyElement_put_text(body, v);
6693 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6694 VariantClear(&v);
6696 V_VT(&v) = VT_NULL;
6697 hres = IHTMLBodyElement_get_text(body, &v);
6698 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6699 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6700 ok(!lstrcmpW(V_BSTR(&v), L"#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
6701 VariantClear(&v);
6703 /* get_text - Valid Text */
6704 V_VT(&v) = VT_BSTR;
6705 V_BSTR(&v) = SysAllocString(L"#FF0000");
6706 hres = IHTMLBodyElement_put_text(body, v);
6707 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6708 VariantClear(&v);
6710 V_VT(&v) = VT_NULL;
6711 hres = IHTMLBodyElement_get_text(body, &v);
6712 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6713 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6714 ok(!lstrcmpW(V_BSTR(&v), L"#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
6715 VariantClear(&v);
6718 #define test_body_scroll(a,b) _test_body_scroll(__LINE__,a,b)
6719 static void _test_body_scroll(unsigned line, IHTMLBodyElement *body, const WCHAR *ex)
6721 BSTR str;
6722 HRESULT hres;
6724 hres = IHTMLBodyElement_get_scroll(body, &str);
6725 ok_(__FILE__,line)(hres == S_OK, "get_scroll failed: %08x\n", hres);
6726 ok_(__FILE__,line)(ex ? !lstrcmpW(str, ex) : !str, "scroll = %s\n", wine_dbgstr_w(str));
6727 SysFreeString(str);
6730 #define set_body_scroll(a,b) _set_body_scroll(__LINE__,a,b)
6731 static void _set_body_scroll(unsigned line, IHTMLBodyElement *body, const WCHAR *val)
6733 BSTR str = SysAllocString(val);
6734 HRESULT hres;
6736 hres = IHTMLBodyElement_put_scroll(body, str);
6737 ok_(__FILE__,line)(hres == S_OK, "put_scroll failed: %08x\n", hres);
6738 SysFreeString(str);
6740 _test_body_scroll(line, body, val);
6743 static void test_body_funs(IHTMLBodyElement *body, IHTMLDocument2 *doc)
6745 VARIANT vbg, vDefaultbg;
6746 HRESULT hres;
6748 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
6749 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6750 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6751 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6753 hres = IHTMLDocument2_get_bgColor(doc, &vbg);
6754 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6755 ok(V_VT(&vbg) == VT_BSTR && V_BSTR(&vbg) && !wcscmp(V_BSTR(&vbg), L"#ffffff"), "bgColor = %s\n", wine_dbgstr_variant(&vbg));
6757 V_VT(&vbg) = VT_BSTR;
6758 V_BSTR(&vbg) = SysAllocString(L"red");
6759 hres = IHTMLBodyElement_put_bgColor(body, vbg);
6760 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6761 VariantClear(&vbg);
6763 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
6764 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6765 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6766 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6767 VariantClear(&vbg);
6769 hres = IHTMLDocument2_get_bgColor(doc, &vbg);
6770 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6771 ok(V_VT(&vbg) == VT_BSTR && V_BSTR(&vbg) && !wcscmp(V_BSTR(&vbg), L"#ff0000"), "bgColor = %s\n", wine_dbgstr_variant(&vbg));
6773 hres = IHTMLDocument2_get_bgColor(doc, &vbg);
6774 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6775 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6776 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6777 VariantClear(&vbg);
6779 /* Restore Original */
6780 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
6781 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6782 VariantClear(&vDefaultbg);
6784 /* Set via IHTMLDocument2 */
6785 V_VT(&vbg) = VT_BSTR;
6786 V_BSTR(&vbg) = SysAllocString(L"red");
6787 hres = IHTMLDocument2_put_bgColor(doc, vbg);
6788 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6789 VariantClear(&vbg);
6791 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
6792 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6793 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6794 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6795 VariantClear(&vbg);
6797 hres = IHTMLDocument2_get_bgColor(doc, &vbg);
6798 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6799 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6800 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6801 VariantClear(&vbg);
6803 /* Restore Original */
6804 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
6805 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6806 VariantClear(&vDefaultbg);
6808 test_body_scroll(body, NULL);
6809 set_body_scroll(body, L"yes");
6810 set_body_scroll(body, L"no");
6811 set_body_scroll(body, L"auto");
6814 static void test_history(IHTMLWindow2 *window)
6816 IOmHistory *history, *history2;
6817 HRESULT hres;
6819 history = NULL;
6820 hres = IHTMLWindow2_get_history(window, &history);
6821 ok(hres == S_OK, "get_history failed: %08x\n", hres);
6822 ok(history != NULL, "history = NULL\n");
6824 test_disp2((IUnknown*)history, &DIID_DispHTMLHistory, &IID_IOmHistory, NULL, L"[object]");
6826 history2 = NULL;
6827 hres = IHTMLWindow2_get_history(window, &history2);
6828 ok(hres == S_OK, "get_history failed: %08x\n", hres);
6829 ok(history2 != NULL, "history2 = NULL\n");
6830 ok(iface_cmp((IUnknown*)history, (IUnknown*)history2), "history != history2\n");
6832 IOmHistory_Release(history2);
6833 IOmHistory_Release(history);
6836 static void test_xmlhttprequest(IHTMLWindow5 *window)
6838 HRESULT hres;
6839 VARIANT var;
6840 IHTMLXMLHttpRequestFactory *factory;
6841 IHTMLXMLHttpRequest *xml;
6843 hres = IHTMLWindow5_get_XMLHttpRequest(window, &var);
6844 ok(hres == S_OK, "get_XMLHttpRequest failed: %08x\n", hres);
6845 ok(V_VT(&var) == VT_DISPATCH || broken(V_VT(&var) == VT_EMPTY), "expect VT_DISPATCH, got %s\n", debugstr_variant(&var));
6847 if (V_VT(&var) == VT_EMPTY) {
6848 win_skip("Native XMLHTTP support is missing or disabled.\n");
6849 return;
6852 factory = NULL;
6853 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLXMLHttpRequestFactory, (void**)&factory);
6854 ok(hres == S_OK, "QueryInterface(&IID_IHTMLXMLHttpRequestFactory) failed: %08x\n", hres);
6855 ok(factory != NULL, "factory == NULL\n");
6857 xml = NULL;
6858 hres = IHTMLXMLHttpRequestFactory_create(factory, &xml);
6859 ok(hres == S_OK, "create failed: %08x\n", hres);
6860 ok(xml != NULL, "xml == NULL\n");
6861 if(is_ie9plus)
6862 test_disp((IUnknown*)xml, &DIID_DispHTMLXMLHttpRequest, &CLSID_HTMLXMLHttpRequest, L"[object]");
6864 IHTMLXMLHttpRequest_Release(xml);
6865 IHTMLXMLHttpRequestFactory_Release(factory);
6866 VariantClear(&var);
6869 static void test_read_only_style(IHTMLCSSStyleDeclaration *style)
6871 BSTR none = SysAllocString(L"none"), display = SysAllocString(L"display"), str;
6872 VARIANT v;
6873 HRESULT hres;
6875 hres = IHTMLCSSStyleDeclaration_put_display(style, none);
6876 ok(hres == 0x80700007, "put_display failed: %08x\n", hres);
6878 hres = IHTMLCSSStyleDeclaration_removeProperty(style, display, &str);
6879 ok(hres == 0x80700007, "removeProperty failed: %08x\n", hres);
6881 V_VT(&v) = VT_BSTR;
6882 V_BSTR(&v) = none;
6883 hres = IHTMLCSSStyleDeclaration_setProperty(style, display, &v, NULL);
6884 ok(hres == 0x80700007, "setProperty returned: %08x\n", hres);
6886 SysFreeString(none);
6887 SysFreeString(display);
6890 static void test_window(IHTMLDocument2 *doc)
6892 IHTMLWindow2 *window, *window2, *self, *parent;
6893 IHTMLWindow5 *window5;
6894 IHTMLWindow7 *window7;
6895 IHTMLDocument2 *doc2 = NULL;
6896 IDispatch *disp;
6897 IUnknown *unk;
6898 VARIANT v;
6899 BSTR str;
6900 HRESULT hres;
6902 hres = IHTMLDocument2_get_parentWindow(doc, &window);
6903 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6904 test_ifaces((IUnknown*)window, window_iids);
6905 hres = IHTMLWindow2_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
6906 if(hres == S_OK)
6907 IUnknown_Release(unk);
6908 else
6909 win_skip("IID_ITravelLogClient not supported\n");
6911 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, &CLSID_HTMLWindow2, L"[object]");
6913 hres = IHTMLWindow2_get_document(window, &doc2);
6914 ok(hres == S_OK, "get_document failed: %08x\n", hres);
6915 ok(doc2 != NULL, "doc2 == NULL\n");
6917 if(is_ie9plus)
6918 test_ifaces((IUnknown*)doc2, doc_node_iids);
6919 test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]");
6921 if(is_ie9plus)
6922 test_ifaces((IUnknown*)doc, doc_obj_iids);
6923 test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]");
6925 unk = (void*)0xdeadbeef;
6926 hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
6927 ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
6928 ok(!unk, "unk = %p\n", unk);
6930 IHTMLDocument2_Release(doc2);
6932 hres = IHTMLWindow2_get_window(window, &window2);
6933 ok(hres == S_OK, "get_window failed: %08x\n", hres);
6934 ok(window2 != NULL, "window2 == NULL\n");
6936 hres = IHTMLWindow2_get_self(window, &self);
6937 ok(hres == S_OK, "get_self failed: %08x\n", hres);
6938 ok(window2 != NULL, "self == NULL\n");
6940 ok(self == window2, "self != window2\n");
6942 IHTMLWindow2_Release(window2);
6944 disp = NULL;
6945 hres = IHTMLDocument2_get_Script(doc, &disp);
6946 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
6947 ok(disp == (void*)window, "disp != window\n");
6948 IDispatch_Release(disp);
6950 hres = IHTMLWindow2_toString(window, NULL);
6951 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
6953 str = NULL;
6954 hres = IHTMLWindow2_toString(window, &str);
6955 ok(hres == S_OK, "toString failed: %08x\n", hres);
6956 ok(!lstrcmpW(str, L"[object]") ||
6957 !lstrcmpW(str, L"[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
6958 SysFreeString(str);
6960 V_VT(&v) = VT_ERROR;
6961 hres = IHTMLWindow2_get_opener(window, &v);
6962 ok(hres == S_OK, "get_opener failed: %08x\n", hres);
6963 ok(V_VT(&v) == VT_EMPTY, "V_VT(opener) = %d\n", V_VT(&v));
6965 parent = NULL;
6966 hres = IHTMLWindow2_get_parent(window, &parent);
6967 ok(hres == S_OK, "get_parent failed: %08x\n", hres);
6968 ok(parent != NULL, "parent == NULL\n");
6969 ok(parent == self, "parent != window\n");
6970 IHTMLWindow2_Release(parent);
6971 IHTMLWindow2_Release(self);
6973 test_window_name(window, NULL);
6974 set_window_name(window, L"test");
6975 test_window_length(window, 0);
6976 test_screen(window);
6977 test_window_status(window);
6978 set_window_status(window, L"Test!");
6979 test_history(window);
6981 hres = IHTMLWindow2_moveBy(window, 0, 0);
6982 ok(hres == S_FALSE, "moveBy failed: %08x\n", hres);
6984 hres = IHTMLWindow2_resizeBy(window, 0, 0);
6985 ok(hres == S_FALSE, "resizeBy failed: %08x\n", hres);
6987 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow5, (void**)&window5);
6988 if(SUCCEEDED(hres)) {
6989 ok(window5 != NULL, "window5 == NULL\n");
6990 test_xmlhttprequest(window5);
6991 IHTMLWindow5_Release(window5);
6992 }else {
6993 win_skip("IHTMLWindow5 not supported!\n");
6996 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow7, (void**)&window7);
6997 if(SUCCEEDED(hres)) {
6998 IHTMLCSSStyleDeclaration *computed_style;
6999 IHTMLPerformance *performance;
7000 IHTMLDOMNode *node;
7001 IHTMLElement *elem;
7002 LONG offset;
7004 ok(window7 != NULL, "window7 == NULL\n");
7006 hres = IHTMLWindow7_get_performance(window7, &v);
7007 ok(hres == S_OK, "get_performance failed: %08x\n", hres);
7008 if(SUCCEEDED(hres)) {
7009 ok(V_VT(&v) == VT_DISPATCH, "V_VT(performance) = %u\n", V_VT(&v));
7011 hres = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IHTMLPerformance,
7012 (void**)&performance);
7013 ok(hres == S_OK, "Could not get IHTMLPerformance iface: %08x\n", hres);
7015 IHTMLPerformance_Release(performance);
7017 V_VT(&v) = VT_I2;
7018 V_I2(&v) = 2;
7019 hres = IHTMLWindow7_put_performance(window7, v);
7020 ok(hres == S_OK, "put_performance failed: %08x\n", hres);
7022 V_VT(&v) = VT_ERROR;
7023 hres = IHTMLWindow7_get_performance(window7, &v);
7024 ok(hres == S_OK, "get_performance failed: %08x\n", hres);
7025 ok(V_VT(&v) == VT_I2, "V_VT(performance) = %u\n", V_VT(&v));
7026 ok(V_I2(&v) == 2, "V_I2(performance) = %d\n", V_I2(&v));
7029 hres = IHTMLWindow7_get_pageXOffset(window7, &offset);
7030 ok(hres == S_OK, "get_pageXOffset failed: %08x\n", hres);
7031 ok(!offset, "Unexpected offset %d.\n", offset);
7033 hres = IHTMLWindow7_get_pageYOffset(window7, &offset);
7034 ok(hres == S_OK, "get_pageYOffset failed: %08x\n", hres);
7035 ok(!offset, "Unexpected offset %d.\n", offset);
7037 hres = IHTMLDocument2_get_body(doc, &elem);
7038 ok(hres == S_OK, "get_body failed: %08x\n", hres);
7040 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
7041 ok(hres == S_OK, "Could not get IHTMLDOMNode iface: %08x\n", hres);
7043 hres = IHTMLWindow7_getComputedStyle(window7, node, NULL, &computed_style);
7044 ok(hres == S_OK, "getComputedStyle failed: %08x\n", hres);
7046 test_disp((IUnknown*)computed_style, &DIID_DispHTMLW3CComputedStyle, NULL, L"[object]");
7047 test_ifaces((IUnknown*)computed_style, computed_style_iids);
7049 test_read_only_style(computed_style);
7051 IHTMLCSSStyleDeclaration_Release(computed_style);
7053 IHTMLDOMNode_Release(node);
7054 IHTMLElement_Release(elem);
7056 IHTMLWindow7_Release(window7);
7057 }else {
7058 win_skip("IHTMLWindow7 not supported\n");
7061 IHTMLWindow2_Release(window);
7064 static void test_dom_implementation(IHTMLDocument2 *doc)
7066 IHTMLDocument5 *doc5 = get_htmldoc5_iface((IUnknown*)doc);
7067 IHTMLDOMImplementation2 *dom_implementation2;
7068 IHTMLDOMImplementation *dom_implementation;
7069 VARIANT_BOOL b;
7070 VARIANT v;
7071 BSTR str;
7072 HRESULT hres;
7074 hres = IHTMLDocument5_get_implementation(doc5, &dom_implementation);
7075 IHTMLDocument5_Release(doc5);
7076 ok(hres == S_OK, "get_implementation failed: %08x\n", hres);
7077 ok(dom_implementation != NULL, "dom_implementation == NULL\n");
7079 str = SysAllocString(L"test");
7080 V_VT(&v) = VT_BSTR;
7081 V_BSTR(&v) = SysAllocString(L"1.0");
7082 b = 100;
7083 hres = IHTMLDOMImplementation_hasFeature(dom_implementation, str, v, &b);
7084 SysFreeString(str);
7085 VariantClear(&v);
7086 ok(hres == S_OK, "hasFeature failed: %08x\n", hres);
7087 ok(!b, "hasFeature returned %x\n", b);
7089 hres = IHTMLDOMImplementation_QueryInterface(dom_implementation, &IID_IHTMLDOMImplementation2,
7090 (void**)&dom_implementation2);
7091 if(SUCCEEDED(hres)) {
7092 IHTMLDocument2 *new_document2;
7093 IHTMLDocument7 *new_document;
7094 IHTMLLocation *location;
7095 IHTMLWindow2 *window;
7096 VARIANT v;
7097 IDispatch *disp;
7099 test_disp((IUnknown*)dom_implementation, &DIID_DispHTMLDOMImplementation, NULL, L"[object]");
7101 str = SysAllocString(L"test");
7102 hres = IHTMLDOMImplementation2_createHTMLDocument(dom_implementation2, str, &new_document);
7103 ok(hres == S_OK, "createHTMLDocument failed: %08x\n", hres);
7105 test_disp((IUnknown*)new_document, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]");
7106 test_ifaces((IUnknown*)new_document, doc_node_iids);
7108 hres = IHTMLDocument7_get_defaultView(new_document, &window);
7109 ok(hres == S_OK, "get_defaultView returned: %08x\n", hres);
7110 ok(!window, "window = %p\n", window);
7112 hres = IHTMLDocument7_get_parentWindow(new_document, &window);
7113 ok(hres == S_OK, "get_parentWindow returned: %08x\n", hres);
7114 ok(!window, "window = %p\n", window);
7116 hres = IHTMLDocument7_QueryInterface(new_document, &IID_IHTMLDocument2, (void**)&new_document2);
7117 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
7119 hres = IHTMLDocument2_get_parentWindow(new_document2, &window);
7120 ok(hres == E_FAIL, "get_parentWindow returned: %08x\n", hres);
7122 hres = IHTMLDocument2_get_Script(new_document2, &disp);
7123 ok(hres == E_PENDING, "get_Script returned: %08x\n", hres);
7125 hres = IHTMLDocument2_get_location(new_document2, &location);
7126 ok(hres == E_UNEXPECTED, "get_location returned: %08x\n", hres);
7128 memset(&v, 0xcc, sizeof(v));
7129 hres = IHTMLDocument7_get_onmsthumbnailclick(new_document, &v);
7130 ok(hres == S_OK, "get_onmsthumbnailclick returned: %08x\n", hres);
7131 ok(V_VT(&v) == VT_NULL, "got %u\n", V_VT(&v));
7132 ok((DWORD)(DWORD_PTR)V_DISPATCH(&v) == 0xcccccccc, "got %p\n", V_DISPATCH(&v));
7134 IHTMLDocument2_Release(new_document2);
7135 IHTMLDocument7_Release(new_document);
7136 IHTMLDOMImplementation2_Release(dom_implementation2);
7137 }else {
7138 win_skip("Missing IHTMLDOMImplementation implementation\n");
7141 IHTMLDOMImplementation_Release(dom_implementation);
7144 static void test_xhr(IHTMLDocument2 *doc)
7146 IHTMLWindow2 *window;
7147 IDispatchEx *dispex;
7148 DISPID id;
7149 BSTR str;
7150 HRESULT hres;
7152 hres = IHTMLDocument2_get_parentWindow(doc, &window);
7153 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
7155 hres = IHTMLWindow2_QueryInterface(window, &IID_IDispatchEx, (void**)&dispex);
7156 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
7158 str = SysAllocString(L"XMLHttpRequest");
7159 hres = IDispatchEx_GetDispID(dispex, str, 0, &id);
7160 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
7161 SysFreeString(str);
7163 IHTMLWindow2_Release(window);
7166 static void test_defaults(IHTMLDocument2 *doc)
7168 IHTMLStyleSheetsCollection *stylesheetcol;
7169 IHTMLCurrentStyle *cstyle;
7170 IHTMLBodyElement *body;
7171 IHTMLElement2 *elem2;
7172 IHTMLElement *elem;
7173 IHTMLStyle *style;
7174 VARIANT v;
7175 BSTR str;
7176 LONG l;
7177 VARIANT_BOOL b;
7178 HRESULT hres;
7179 IHTMLElementCollection *collection;
7181 elem = doc_get_body(doc);
7183 hres = IHTMLDocument2_get_images(doc, NULL);
7184 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
7186 hres = IHTMLDocument2_get_images(doc, &collection);
7187 ok(hres == S_OK, "get_images failed: %08x\n", hres);
7188 if(hres == S_OK)
7190 test_elem_collection((IUnknown*)collection, NULL, 0);
7191 IHTMLElementCollection_Release(collection);
7194 hres = IHTMLDocument2_get_applets(doc, NULL);
7195 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
7197 hres = IHTMLDocument2_get_applets(doc, &collection);
7198 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
7199 if(hres == S_OK)
7201 test_elem_collection((IUnknown*)collection, NULL, 0);
7202 IHTMLElementCollection_Release(collection);
7205 hres = IHTMLDocument2_get_links(doc, NULL);
7206 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
7208 hres = IHTMLDocument2_get_links(doc, &collection);
7209 ok(hres == S_OK, "get_links failed: %08x\n", hres);
7210 if(hres == S_OK)
7212 test_elem_collection((IUnknown*)collection, NULL, 0);
7213 IHTMLElementCollection_Release(collection);
7216 hres = IHTMLDocument2_get_forms(doc, NULL);
7217 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
7219 hres = IHTMLDocument2_get_forms(doc, &collection);
7220 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
7221 if(hres == S_OK)
7223 test_elem_collection((IUnknown*)collection, NULL, 0);
7224 IHTMLElementCollection_Release(collection);
7227 hres = IHTMLDocument2_get_anchors(doc, NULL);
7228 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
7230 hres = IHTMLDocument2_get_anchors(doc, &collection);
7231 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
7232 if(hres == S_OK)
7234 test_elem_collection((IUnknown*)collection, NULL, 0);
7235 IHTMLElementCollection_Release(collection);
7238 test_xhr(doc);
7240 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
7241 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
7242 test_default_body(body);
7243 test_body_funs(body, doc);
7244 IHTMLBodyElement_Release(body);
7246 test_elem_set_outertext_fail(elem);
7248 test_elem_istextedit(elem, VARIANT_TRUE);
7250 hres = IHTMLElement_get_style(elem, &style);
7251 ok(hres == S_OK, "get_style failed: %08x\n", hres);
7253 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, NULL, L"[object]");
7254 test_ifaces((IUnknown*)style, style_iids);
7255 IHTMLStyle_Release(style);
7257 str = NULL;
7258 hres = IHTMLDocument2_get_charset(doc, &str);
7259 ok(hres == S_OK, "get_charset failed: %08x\n", hres);
7260 ok(str && *str, "charset is empty\n"); /* FIXME: better tests */
7261 SysFreeString(str);
7263 test_window(doc);
7264 test_compatmode(doc, L"BackCompat");
7265 test_location(doc);
7266 test_navigator(doc);
7267 test_plugins_col(doc);
7269 elem2 = get_elem2_iface((IUnknown*)elem);
7270 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
7271 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
7272 if(SUCCEEDED(hres)) {
7273 IUnknown *unk;
7275 test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, NULL, L"[object]");
7276 test_ifaces((IUnknown*)cstyle, cstyle_iids);
7278 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
7279 if(SUCCEEDED(hres)) {
7280 IHTMLCSSStyleDeclaration *css_style;
7282 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCSSStyleDeclaration, (void**)&css_style);
7283 if(SUCCEEDED(hres)) {
7284 test_read_only_style(css_style);
7285 IHTMLCSSStyleDeclaration_Release(css_style);
7286 }else {
7287 win_skip("IHTMLCSSStyleDeclaration not supported\n");
7290 IUnknown_Release(unk);
7291 }else {
7292 /*IE6 doesn't have interface */
7293 win_skip("IID_IHTMLCurrentStyle4 not supported\n");
7296 IHTMLCurrentStyle_Release(cstyle);
7298 IHTMLElement2_Release(elem2);
7300 IHTMLElement_Release(elem);
7302 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
7303 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
7305 l = 0xdeadbeef;
7306 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
7307 ok(hres == S_OK, "get_length failed: %08x\n", hres);
7308 ok(l == 0, "length = %d\n", l);
7310 IHTMLStyleSheetsCollection_Release(stylesheetcol);
7312 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
7313 ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
7315 str = SysAllocString(L"xxx");
7316 b = 100;
7317 V_VT(&v) = VT_EMPTY;
7318 hres = IHTMLDocument2_execCommand(doc, str, FALSE, v, &b);
7319 ok(hres == OLECMDERR_E_NOTSUPPORTED || hres == E_INVALIDARG,
7320 "execCommand failed: %08x, expected OLECMDERR_E_NOTSUPPORTED or E_INVALIDARG\n", hres);
7321 SysFreeString(str);
7323 str = SysAllocString(L"respectvisibilityindesign");
7324 b = 100;
7325 V_VT(&v) = VT_BOOL;
7326 V_BOOL(&v) = VARIANT_TRUE;
7327 hres = IHTMLDocument2_execCommand(doc, str, FALSE, v, &b);
7328 ok(hres == S_OK, "execCommand failed: %08x, expected DRAGDROP_E_NOTREGISTERED\n", hres);
7329 SysFreeString(str);
7331 test_default_selection(doc);
7332 test_doc_title(doc, L"");
7333 test_dom_implementation(doc);
7335 str = (BSTR)0xdeadbeef;
7336 hres = IHTMLDocument2_get_cookie(doc, &str);
7337 ok(hres == S_OK, "get_cookie failed: %08x\n", hres);
7338 ok(!str, "cookie = %s\n", wine_dbgstr_w(str));
7341 #define test_button_name(a,b) _test_button_name(__LINE__,a,b)
7342 static void _test_button_name(unsigned line, IHTMLElement *elem, const WCHAR *exname)
7344 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7345 BSTR str;
7346 HRESULT hres;
7348 str = (void*)0xdeadbeef;
7349 hres = IHTMLButtonElement_get_name(button, &str);
7350 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
7351 if(exname)
7352 ok_(__FILE__,line)(!lstrcmpW(str, exname), "name = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exname));
7353 else
7354 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
7355 SysFreeString(str);
7356 IHTMLButtonElement_Release(button);
7359 #define set_button_name(a,b) _set_button_name(__LINE__,a,b)
7360 static void _set_button_name(unsigned line, IHTMLElement *elem, const WCHAR *name)
7362 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7363 BSTR str = SysAllocString(name);
7364 HRESULT hres;
7366 hres = IHTMLButtonElement_put_name(button, str);
7367 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
7368 SysFreeString(str);
7369 IHTMLButtonElement_Release(button);
7371 _test_button_name(line, elem, name);
7374 #define test_button_get_disabled(i,b) _test_button_get_disabled(__LINE__,i,b)
7375 static void _test_button_get_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
7377 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7378 VARIANT_BOOL disabled = 100;
7379 HRESULT hres;
7381 hres = IHTMLButtonElement_get_disabled(button, &disabled);
7382 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
7383 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
7384 IHTMLButtonElement_Release(button);
7386 _test_elem3_get_disabled(line, (IUnknown*)elem, exb);
7389 #define test_button_set_disabled(i,b) _test_button_set_disabled(__LINE__,i,b)
7390 static void _test_button_set_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL b)
7392 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7393 HRESULT hres;
7395 hres = IHTMLButtonElement_put_disabled(button, b);
7396 ok_(__FILE__,line) (hres == S_OK, "put_disabled failed: %08x\n", hres);
7397 IHTMLButtonElement_Release(button);
7399 _test_button_get_disabled(line, elem, b);
7402 #define test_button_type(a,b) _test_button_type(__LINE__,a,b)
7403 static void _test_button_type(unsigned line, IHTMLElement *elem, const WCHAR *extype)
7405 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7406 BSTR str;
7407 HRESULT hres;
7409 hres = IHTMLButtonElement_get_type(button, &str);
7410 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
7411 ok_(__FILE__,line)(!lstrcmpW(str, extype), "type = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(extype));
7412 SysFreeString(str);
7414 IHTMLButtonElement_Release(button);
7417 #define test_button_value(a,b) _test_button_value(__LINE__,a,b)
7418 static void _test_button_value(unsigned line, IHTMLElement *elem, const WCHAR *exvalue)
7420 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7421 BSTR str;
7422 HRESULT hres;
7424 hres = IHTMLButtonElement_get_value(button, &str);
7425 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
7426 if(exvalue)
7427 ok_(__FILE__,line)(!lstrcmpW(str, exvalue), "value = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exvalue));
7428 else
7429 ok_(__FILE__,line)(!str, "value = %s, expected NULL\n", wine_dbgstr_w(str));
7430 SysFreeString(str);
7432 IHTMLButtonElement_Release(button);
7435 #define set_button_value(a,b) _set_button_value(__LINE__,a,b)
7436 static void _set_button_value(unsigned line, IHTMLElement *elem, const WCHAR *value)
7438 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7439 BSTR str = SysAllocString(value);
7440 HRESULT hres;
7442 hres = IHTMLButtonElement_put_value(button, str);
7443 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
7444 IHTMLButtonElement_Release(button);
7445 SysFreeString(str);
7447 _test_button_value(line, elem, value);
7450 #define get_button_form(a) _get_button_form(__LINE__,a)
7451 static IHTMLFormElement *_get_button_form(unsigned line, IHTMLElement *elem)
7453 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
7454 IHTMLFormElement *form;
7455 HRESULT hres;
7457 hres = IHTMLButtonElement_get_form(button, &form);
7458 ok_(__FILE__,line)(hres == S_OK, "get_form failed: %08x\n", hres);
7459 IHTMLButtonElement_Release(button);
7461 return form;
7464 static void test_button_elem(IHTMLElement *elem)
7466 IHTMLFormElement *form;
7468 test_button_name(elem, NULL);
7469 set_button_name(elem, L"button name");
7470 test_button_type(elem, L"submit");
7471 test_button_value(elem, NULL);
7472 set_button_value(elem, L"val");
7474 form = get_button_form(elem);
7475 ok(!form, "form != NULL\n");
7477 test_elem_istextedit(elem, VARIANT_TRUE);
7480 #define test_tr_possess(e,r,l,i) _test_tr_possess(__LINE__,e,r,l,i)
7481 static void _test_tr_possess(unsigned line, IHTMLElement *elem,
7482 IHTMLTableRow *row, LONG len, const WCHAR *id)
7484 IHTMLElementCollection *col;
7485 IDispatch *disp;
7486 HRESULT hres;
7487 LONG lval;
7488 VARIANT var;
7490 hres = IHTMLTableRow_get_cells(row, &col);
7491 ok_(__FILE__, line)(hres == S_OK, "get_cells failed: %08x\n", hres);
7492 ok_(__FILE__, line)(col != NULL, "get_cells returned NULL\n");
7494 hres = IHTMLElementCollection_get_length(col, &lval);
7495 ok_(__FILE__, line)(hres == S_OK, "get length failed: %08x\n", hres);
7496 ok_(__FILE__, line)(lval == len, "expected len = %d, got %d\n", len, lval);
7498 V_VT(&var) = VT_BSTR;
7499 V_BSTR(&var) = SysAllocString(id);
7500 hres = IHTMLElementCollection_tags(col, var, &disp);
7501 ok_(__FILE__, line)(hres == S_OK, "search by tags(%s) failed: %08x\n", wine_dbgstr_w(id), hres);
7502 ok_(__FILE__, line)(disp != NULL, "disp == NULL\n");
7504 VariantClear(&var);
7505 IDispatch_Release(disp);
7506 IHTMLElementCollection_Release(col);
7509 static void test_tr_modify(IHTMLElement *elem, IHTMLTableRow *row)
7511 HRESULT hres;
7512 IDispatch *disp;
7513 IHTMLTableCell *cell;
7515 hres = IHTMLTableRow_deleteCell(row, 0);
7516 ok(hres == S_OK, "deleteCell failed: %08x\n", hres);
7517 test_tr_possess(elem, row, 1, L"td2");
7519 hres = IHTMLTableRow_insertCell(row, 0, &disp);
7520 ok(hres == S_OK, "insertCell failed: %08x\n", hres);
7521 ok(disp != NULL, "disp == NULL\n");
7522 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableCell, (void **)&cell);
7523 ok(hres == S_OK, "Could not get IID_IHTMLTableCell interface: %08x\n", hres);
7524 ok(cell != NULL, "cell == NULL\n");
7525 if (SUCCEEDED(hres))
7526 IHTMLTableCell_Release(cell);
7527 test_tr_possess(elem, row, 2, L"td2");
7528 IDispatch_Release(disp);
7531 static void test_tr_elem(IHTMLElement *elem)
7533 IHTMLElementCollection *col;
7534 IHTMLTableRow *row;
7535 HRESULT hres;
7536 BSTR bstr;
7537 LONG lval;
7538 VARIANT vbg, vDefaultbg;
7540 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
7542 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
7543 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
7544 if(FAILED(hres))
7545 return;
7547 col = NULL;
7548 hres = IHTMLTableRow_get_cells(row, &col);
7549 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
7550 ok(col != NULL, "get_cells returned NULL\n");
7552 test_elem_collection((IUnknown*)col, cell_types, ARRAY_SIZE(cell_types));
7553 IHTMLElementCollection_Release(col);
7555 bstr = SysAllocString(L"left");
7556 hres = IHTMLTableRow_put_align(row, bstr);
7557 ok(hres == S_OK, "set_align failed: %08x\n", hres);
7558 SysFreeString(bstr);
7560 bstr = NULL;
7561 hres = IHTMLTableRow_get_align(row, &bstr);
7562 ok(hres == S_OK, "get_align failed: %08x\n", hres);
7563 ok(bstr != NULL, "get_align returned NULL\n");
7564 ok(!lstrcmpW(bstr, L"left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
7565 SysFreeString(bstr);
7567 bstr = SysAllocString(L"top");
7568 hres = IHTMLTableRow_put_vAlign(row, bstr);
7569 ok(hres == S_OK, "set_valign failed: %08x\n", hres);
7570 SysFreeString(bstr);
7572 bstr = NULL;
7573 hres = IHTMLTableRow_get_vAlign(row, &bstr);
7574 ok(hres == S_OK, "get_valign failed: %08x\n", hres);
7575 ok(bstr != NULL, "get_valign returned NULL\n");
7576 ok(!lstrcmpW(bstr, L"top"), "get_valign returned %s\n", wine_dbgstr_w(bstr));
7577 SysFreeString(bstr);
7579 lval = 0xdeadbeef;
7580 hres = IHTMLTableRow_get_rowIndex(row, &lval);
7581 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
7582 ok(lval == 1, "get_rowIndex returned %d\n", lval);
7584 lval = 0xdeadbeef;
7585 hres = IHTMLTableRow_get_sectionRowIndex(row, &lval);
7586 ok(hres == S_OK, "get_sectionRowIndex failed: %08x\n", hres);
7587 ok(lval == 1, "get_sectionRowIndex returned %d\n", lval);
7589 hres = IHTMLTableRow_get_bgColor(row, &vDefaultbg);
7590 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7591 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
7592 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
7594 V_VT(&vbg) = VT_BSTR;
7595 V_BSTR(&vbg) = SysAllocString(L"red");
7596 hres = IHTMLTableRow_put_bgColor(row, vbg);
7597 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7598 VariantClear(&vbg);
7600 hres = IHTMLTableRow_get_bgColor(row, &vbg);
7601 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7602 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
7603 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
7604 VariantClear(&vbg);
7606 V_VT(&vbg) = VT_I4;
7607 V_I4(&vbg) = 0xff0000;
7608 hres = IHTMLTableRow_put_bgColor(row, vbg);
7609 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7610 VariantClear(&vbg);
7612 hres = IHTMLTableRow_get_bgColor(row, &vbg);
7613 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7614 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
7615 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
7616 VariantClear(&vbg);
7618 /* Restore Original */
7619 hres = IHTMLTableRow_put_bgColor(row, vDefaultbg);
7620 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7621 VariantClear(&vDefaultbg);
7623 test_tr_modify(elem, row);
7625 IHTMLTableRow_Release(row);
7628 static void test_td_elem(IHTMLDocument2 *doc, IHTMLElement *div)
7630 IHTMLTableCell *cell;
7631 IHTMLElement *elem;
7632 HRESULT hres;
7633 LONG lval;
7634 BSTR str;
7635 VARIANT vbg, vDefaultbg, v;
7637 test_elem_set_innerhtml((IUnknown*)div,
7638 L"<table id=\"tbl\"><tbody>"
7639 " <tr></tr>"
7640 " <tr id=\"row2\"><td id=\"td1\">td1 text</td><td id=\"td2\">td2 text</td><td></td></tr>"
7641 " <tr></tr>"
7642 "</tbody></table>");
7644 elem = get_doc_elem_by_id(doc, L"td1");
7645 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableCell, (void**)&cell);
7646 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
7647 IHTMLElement_Release(elem);
7649 lval = 0xdeadbeef;
7650 hres = IHTMLTableCell_get_cellIndex(cell, &lval);
7651 ok(hres == S_OK, "get cellIndex failed: %08x\n", hres);
7652 ok(!lval, "Expected 0, got %d\n", lval);
7654 str = SysAllocString(L"left");
7655 hres = IHTMLTableCell_put_align(cell, str);
7656 ok(hres == S_OK, "put_align failed: %08x\n", hres);
7657 SysFreeString(str);
7659 str = NULL;
7660 hres = IHTMLTableCell_get_align(cell, &str);
7661 ok(hres == S_OK, "get_align failed: %08x\n", hres);
7662 ok(str != NULL, "str is NULL\n");
7663 if (str != NULL && hres == S_OK) {
7664 ok(!lstrcmpW(str, L"left"), "got %s\n", wine_dbgstr_w(str));
7665 SysFreeString(str);
7668 hres = IHTMLTableCell_get_bgColor(cell, &vDefaultbg);
7669 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7670 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
7671 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
7673 V_VT(&vbg) = VT_BSTR;
7674 V_BSTR(&vbg) = SysAllocString(L"red");
7675 hres = IHTMLTableCell_put_bgColor(cell, vbg);
7676 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7677 VariantClear(&vbg);
7679 hres = IHTMLTableCell_get_bgColor(cell, &vbg);
7680 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7681 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
7682 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
7683 VariantClear(&vbg);
7685 V_VT(&vbg) = VT_I4;
7686 V_I4(&vbg) = 0xff0000;
7687 hres = IHTMLTableCell_put_bgColor(cell, vbg);
7688 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7689 VariantClear(&vbg);
7691 hres = IHTMLTableCell_get_bgColor(cell, &vbg);
7692 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7693 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
7694 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
7695 VariantClear(&vbg);
7697 V_VT(&v) = VT_I4;
7698 V_I4(&v) = 100;
7699 hres = IHTMLTableCell_put_height(cell, v);
7700 ok(hres == S_OK, "put_height failed: %08x\n", hres);
7702 V_VT(&v) = VT_EMPTY;
7703 hres = IHTMLTableCell_get_height(cell, &v);
7704 ok(hres == S_OK, "get_height failed: %08x\n", hres);
7705 ok(V_VT(&v) == VT_BSTR && !lstrcmpW(V_BSTR(&v), L"100"), "height = %s\n", wine_dbgstr_variant(&v));
7706 VariantClear(&v);
7708 V_VT(&v) = VT_BSTR;
7709 V_BSTR(&v) = SysAllocString(L"110px");
7710 hres = IHTMLTableCell_put_height(cell, v);
7711 ok(hres == S_OK, "put_height failed: %08x\n", hres);
7712 SysFreeString(V_BSTR(&v));
7714 V_VT(&v) = VT_EMPTY;
7715 hres = IHTMLTableCell_get_height(cell, &v);
7716 ok(hres == S_OK, "get_height failed: %08x\n", hres);
7717 ok(V_VT(&v) == VT_BSTR && !lstrcmpW(V_BSTR(&v), L"110"), "height = %s\n", wine_dbgstr_variant(&v));
7718 VariantClear(&v);
7720 V_VT(&v) = VT_I4;
7721 V_I4(&v) = 200;
7722 hres = IHTMLTableCell_put_width(cell, v);
7723 ok(hres == S_OK, "put_width failed: %08x\n", hres);
7725 V_VT(&v) = VT_EMPTY;
7726 hres = IHTMLTableCell_get_width(cell, &v);
7727 ok(hres == S_OK, "get_width failed: %08x\n", hres);
7728 ok(V_VT(&v) == VT_BSTR && !lstrcmpW(V_BSTR(&v), L"200"), "width = %s\n", wine_dbgstr_variant(&v));
7729 VariantClear(&v);
7731 V_VT(&v) = VT_BSTR;
7732 V_BSTR(&v) = SysAllocString(L"210px");
7733 hres = IHTMLTableCell_put_width(cell, v);
7734 ok(hres == S_OK, "put_width failed: %08x\n", hres);
7735 SysFreeString(V_BSTR(&v));
7737 V_VT(&v) = VT_EMPTY;
7738 hres = IHTMLTableCell_get_width(cell, &v);
7739 ok(hres == S_OK, "get_width failed: %08x\n", hres);
7740 ok(V_VT(&v) == VT_BSTR && !lstrcmpW(V_BSTR(&v), L"210"), "width = %s\n", wine_dbgstr_variant(&v));
7741 VariantClear(&v);
7743 /* Restore Original */
7744 hres = IHTMLTableCell_put_bgColor(cell, vDefaultbg);
7745 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
7746 VariantClear(&vDefaultbg);
7748 hres = IHTMLTableCell_get_rowSpan(cell, &lval);
7749 ok(hres == S_OK, "get_rowSpan failed: %08x\n", hres);
7750 ok(lval == 1, "rowSpan = %d\n", lval);
7752 hres = IHTMLTableCell_put_rowSpan(cell, -1);
7753 ok(hres == E_INVALIDARG, "put_rowSpan failed: %08x\n", hres);
7755 hres = IHTMLTableCell_put_rowSpan(cell, 0);
7756 ok(hres == E_INVALIDARG, "put_rowSpan failed: %08x\n", hres);
7758 hres = IHTMLTableCell_put_rowSpan(cell, 2);
7759 ok(hres == S_OK, "put_rowSpan failed: %08x\n", hres);
7761 hres = IHTMLTableCell_get_rowSpan(cell, &lval);
7762 ok(hres == S_OK, "get_rowSpan failed: %08x\n", hres);
7763 ok(lval == 2, "rowSpan = %d\n", lval);
7765 hres = IHTMLTableCell_get_colSpan(cell, &lval);
7766 ok(hres == S_OK, "get_rowSpan failed: %08x\n", hres);
7767 ok(lval == 1, "rowSpan = %d\n", lval);
7769 hres = IHTMLTableCell_put_colSpan(cell, -1);
7770 ok(hres == E_INVALIDARG, "put_rowSpan failed: %08x\n", hres);
7772 hres = IHTMLTableCell_put_colSpan(cell, 0);
7773 ok(hres == E_INVALIDARG, "put_rowSpan failed: %08x\n", hres);
7775 hres = IHTMLTableCell_put_colSpan(cell, 2);
7776 ok(hres == S_OK, "put_rowSpan failed: %08x\n", hres);
7778 hres = IHTMLTableCell_get_colSpan(cell, &lval);
7779 ok(hres == S_OK, "get_rowSpan failed: %08x\n", hres);
7780 ok(lval == 2, "rowSpan = %d\n", lval);
7782 IHTMLTableCell_Release(cell);
7785 static void test_label_elem(IHTMLElement *elem)
7787 IHTMLLabelElement *label;
7788 BSTR str;
7789 HRESULT hres;
7791 label = get_label_iface((IUnknown*)elem);
7793 str = NULL;
7794 hres = IHTMLLabelElement_get_htmlFor(label, &str);
7795 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
7796 ok(!lstrcmpW(str, L"in"), "htmlFor = %s\n", wine_dbgstr_w(str));
7797 SysFreeString(str);
7799 str = SysAllocString(L"");
7800 hres = IHTMLLabelElement_put_htmlFor(label, str);
7801 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
7802 SysFreeString(str);
7804 str = (void*)0xdeadbeef;
7805 hres = IHTMLLabelElement_get_htmlFor(label, &str);
7806 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
7807 ok(!lstrcmpW(str, L""), "htmlFor = %s\n", wine_dbgstr_w(str));
7808 SysFreeString(str);
7810 str = SysAllocString(L"abc");
7811 hres = IHTMLLabelElement_put_htmlFor(label, str);
7812 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
7813 SysFreeString(str);
7815 str = NULL;
7816 hres = IHTMLLabelElement_get_htmlFor(label, &str);
7817 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
7818 ok(!lstrcmpW(str, L"abc"), "htmlFor = %s\n", wine_dbgstr_w(str));
7819 SysFreeString(str);
7821 IHTMLLabelElement_Release(label);
7824 #define test_table_cell_spacing(a,b) _test_table_cell_spacing(__LINE__,a,b)
7825 static void _test_table_cell_spacing(unsigned line, IHTMLTable *table, const WCHAR *exstr)
7827 VARIANT v;
7828 HRESULT hres;
7830 V_VT(&v) = VT_ERROR;
7831 hres = IHTMLTable_get_cellSpacing(table, &v);
7832 ok_(__FILE__,line)(hres == S_OK, "get_cellSpacing failed: %08x\n", hres);
7833 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
7834 if(exstr)
7835 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exstr), "cellSpacing = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), wine_dbgstr_w(exstr));
7836 else
7837 ok_(__FILE__,line)(!V_BSTR(&v), "cellSpacing = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
7838 VariantClear(&v);
7841 #define test_table_cell_padding(a,b) _test_table_cell_padding(__LINE__,a,b)
7842 static void _test_table_cell_padding(unsigned line, IHTMLTable *table, const WCHAR *exstr)
7844 VARIANT v;
7845 HRESULT hres;
7847 V_VT(&v) = VT_ERROR;
7848 hres = IHTMLTable_get_cellPadding(table, &v);
7849 ok_(__FILE__,line)(hres == S_OK, "get_cellPadding failed: %08x\n", hres);
7850 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
7851 if(exstr)
7852 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exstr), "cellPadding = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), wine_dbgstr_w(exstr));
7853 else
7854 ok_(__FILE__,line)(!V_BSTR(&v), "cellPadding = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
7855 VariantClear(&v);
7858 static void test_table_modify(IHTMLTable *table)
7860 IDispatch *disp;
7861 IHTMLTableRow *row;
7862 HRESULT hres;
7863 LONG index;
7865 test_table_length(table, 2);
7867 hres = IHTMLTable_insertRow(table, 0, &disp);
7868 ok(hres == S_OK, "insertRow failed: %08x\n", hres);
7869 ok(disp != NULL, "disp == NULL\n");
7870 test_table_length(table, 3);
7871 if (hres != S_OK || disp == NULL)
7872 return;
7874 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableRow, (void**)&row);
7875 IDispatch_Release(disp);
7877 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
7878 ok(row != NULL, "row == NULL\n");
7880 index = 0xdeadbeef;
7881 hres = IHTMLTableRow_get_rowIndex(row, &index);
7882 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
7883 ok(index == 0, "index = %d, expected 0\n", index);
7885 IHTMLTableRow_Release(row);
7887 hres = IHTMLTable_deleteRow(table, 0);
7888 ok(hres == S_OK, "deleteRow failed: %08x\n", hres);
7889 test_table_length(table, 2);
7892 static void test_table_elem(IHTMLElement *elem)
7894 IHTMLElementCollection *col;
7895 IHTMLTable *table;
7896 IHTMLTable3 *table3;
7897 IHTMLDOMNode *node;
7898 VARIANT v;
7899 HRESULT hres;
7900 BSTR bstr;
7901 VARIANT vbg, vDefaultbg;
7903 static const elem_type_t row_types[] = {ET_TR,ET_TR};
7904 static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
7905 static const elem_type_t tbodies_types[] = {ET_TBODY};
7907 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
7908 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
7909 if(FAILED(hres))
7910 return;
7912 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable3, (void**)&table3);
7913 ok(hres == S_OK, "Could not get IHTMLTable3 iface: %08x\n", hres);
7914 if(FAILED(hres))
7915 return;
7917 col = NULL;
7918 hres = IHTMLTable_get_rows(table, &col);
7919 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
7920 ok(col != NULL, "get_rows returned NULL\n");
7922 test_elem_collection((IUnknown*)col, row_types, ARRAY_SIZE(row_types));
7923 IHTMLElementCollection_Release(col);
7925 test_elem_all((IUnknown*)table, all_types, ARRAY_SIZE(all_types));
7927 node = clone_node((IUnknown*)table, VARIANT_TRUE);
7928 test_elem_tag((IUnknown*)node, L"TABLE");
7929 test_elem_all((IUnknown*)node, all_types, ARRAY_SIZE(all_types));
7930 IHTMLDOMNode_Release(node);
7932 node = clone_node((IUnknown*)table, VARIANT_FALSE);
7933 test_elem_tag((IUnknown*)node, L"TABLE");
7934 test_elem_all((IUnknown*)node, NULL, 0);
7935 IHTMLDOMNode_Release(node);
7937 col = NULL;
7938 hres = IHTMLTable_get_tBodies(table, &col);
7939 ok(hres == S_OK, "get_tBodies failed: %08x\n", hres);
7940 ok(col != NULL, "get_tBodies returned NULL\n");
7942 test_elem_collection((IUnknown*)col, tbodies_types, ARRAY_SIZE(tbodies_types));
7943 IHTMLElementCollection_Release(col);
7945 test_table_cell_spacing(table, NULL);
7947 V_VT(&v) = VT_I4;
7948 V_I4(&v) = 10;
7949 hres = IHTMLTable_put_cellSpacing(table, v);
7950 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
7951 test_table_cell_spacing(table, L"10");
7953 V_VT(&v) = VT_BSTR;
7954 V_BSTR(&v) = SysAllocString(L"11");
7955 hres = IHTMLTable_put_cellSpacing(table, v);
7956 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
7957 test_table_cell_spacing(table, L"11");
7958 VariantClear(&v);
7960 test_table_cell_padding(table, NULL);
7962 V_VT(&v) = VT_I4;
7963 V_I4(&v) = 10;
7964 hres = IHTMLTable_put_cellPadding(table, v);
7965 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
7966 test_table_cell_padding(table, L"10");
7968 V_VT(&v) = VT_BSTR;
7969 V_BSTR(&v) = SysAllocString(L"11");
7970 hres = IHTMLTable_put_cellPadding(table, v);
7971 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
7972 test_table_cell_padding(table, L"11");
7973 VariantClear(&v);
7975 V_VT(&v) = VT_R8;
7976 V_R8(&v) = 5;
7977 hres = IHTMLTable_put_cellPadding(table, v);
7978 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
7979 test_table_cell_padding(table, L"5");
7981 bstr = SysAllocString(L"left");
7982 hres = IHTMLTable_put_align(table, bstr);
7983 ok(hres == S_OK, "set_align failed: %08x\n", hres);
7984 SysFreeString(bstr);
7986 bstr = NULL;
7987 hres = IHTMLTable_get_align(table, &bstr);
7988 ok(hres == S_OK, "get_align failed: %08x\n", hres);
7989 ok(bstr != NULL, "get_align returned NULL\n");
7990 ok(!lstrcmpW(bstr, L"left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
7991 SysFreeString(bstr);
7993 hres = IHTMLTable_get_bgColor(table, &vDefaultbg);
7994 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
7995 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
7996 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
7998 V_VT(&vbg) = VT_BSTR;
7999 V_BSTR(&vbg) = SysAllocString(L"red");
8000 hres = IHTMLTable_put_bgColor(table, vbg);
8001 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
8002 VariantClear(&vbg);
8004 hres = IHTMLTable_get_bgColor(table, &vbg);
8005 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
8006 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
8007 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
8008 VariantClear(&vbg);
8010 V_VT(&vbg) = VT_I4;
8011 V_I4(&vbg) = 0xff0000;
8012 hres = IHTMLTable_put_bgColor(table, vbg);
8013 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
8014 VariantClear(&vbg);
8016 hres = IHTMLTable_get_bgColor(table, &vbg);
8017 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
8018 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
8019 ok(!lstrcmpW(V_BSTR(&vbg), L"#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
8020 VariantClear(&vbg);
8022 /* Restore Original */
8023 hres = IHTMLTable_put_bgColor(table, vDefaultbg);
8024 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
8025 VariantClear(&vDefaultbg);
8027 V_VT(&v) = VT_BSTR;
8028 V_BSTR(&v) = SysAllocString(L"12px");
8029 hres = IHTMLTable_put_width(table, v);
8030 ok(hres == S_OK, "put_width = %08x\n", hres);
8031 VariantClear(&v);
8032 hres = IHTMLTable_get_width(table, &v);
8033 ok(hres == S_OK, "get_width = %08x\n", hres);
8034 ok(!lstrcmpW(V_BSTR(&v), L"12"), "Expected 12, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8035 VariantClear(&v);
8037 V_VT(&v) = VT_BSTR;
8038 V_BSTR(&v) = SysAllocString(L"11");
8039 hres = IHTMLTable_put_width(table, v);
8040 ok(hres == S_OK, "put_width = %08x\n", hres);
8041 VariantClear(&v);
8042 hres = IHTMLTable_get_width(table, &v);
8043 ok(hres == S_OK, "get_width = %08x\n", hres);
8044 ok(!lstrcmpW(V_BSTR(&v), L"11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8045 VariantClear(&v);
8047 V_VT(&v) = VT_BSTR;
8048 V_BSTR(&v) = SysAllocString(L"11.9");
8049 hres = IHTMLTable_put_width(table, v);
8050 ok(hres == S_OK, "put_width = %08x\n", hres);
8051 VariantClear(&v);
8052 hres = IHTMLTable_get_width(table, &v);
8053 ok(hres == S_OK, "get_width = %08x\n", hres);
8054 ok(!lstrcmpW(V_BSTR(&v), L"11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8055 VariantClear(&v);
8057 V_VT(&v) = VT_BSTR;
8058 V_BSTR(&v) = SysAllocString(L"40.2%");
8059 hres = IHTMLTable_put_width(table, v);
8060 ok(hres == S_OK, "put_width = %08x\n", hres);
8061 VariantClear(&v);
8062 hres = IHTMLTable_get_width(table, &v);
8063 ok(hres == S_OK, "get_width = %08x\n", hres);
8064 ok(!lstrcmpW(V_BSTR(&v), L"40.2%"), "Expected 40.2%%, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8065 VariantClear(&v);
8067 V_VT(&v) = VT_I4;
8068 V_I4(&v) = 11;
8069 hres = IHTMLTable_put_width(table, v);
8070 ok(hres == S_OK, "put_width = %08x\n", hres);
8071 hres = IHTMLTable_get_width(table, &v);
8072 ok(hres == S_OK, "get_width = %08x\n", hres);
8073 ok(!lstrcmpW(V_BSTR(&v), L"11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8074 VariantClear(&v);
8076 V_VT(&v) = VT_R8;
8077 V_R8(&v) = 11.9;
8078 hres = IHTMLTable_put_width(table, v);
8079 ok(hres == S_OK, "put_width = %08x\n", hres);
8080 hres = IHTMLTable_get_width(table, &v);
8081 ok(hres == S_OK, "get_width = %08x\n", hres);
8082 ok(!lstrcmpW(V_BSTR(&v), L"11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8083 VariantClear(&v);
8085 bstr = SysAllocString(L"box");
8086 hres = IHTMLTable_put_frame(table, bstr);
8087 ok(hres == S_OK, "put_frame = %08x\n", hres);
8088 SysFreeString(bstr);
8089 hres = IHTMLTable_get_frame(table, &bstr);
8090 ok(hres == S_OK, "get_frame = %08x\n", hres);
8091 ok(!lstrcmpW(bstr, L"box"), "Expected box, got %s\n", wine_dbgstr_w(bstr));
8092 SysFreeString(bstr);
8094 test_table_modify(table);
8095 bstr = SysAllocString(L"summary");
8096 hres = IHTMLTable3_put_summary(table3, bstr);
8097 ok(hres == S_OK, "put_summary = %08x\n", hres);
8098 SysFreeString(bstr);
8100 hres = IHTMLTable3_get_summary(table3, &bstr);
8101 ok(hres == S_OK, "get_summary = %08x\n", hres);
8102 ok(!lstrcmpW(bstr, L"summary"), "Expected summary, got %s\n", wine_dbgstr_w(bstr));
8103 SysFreeString(bstr);
8105 IHTMLTable3_Release(table3);
8106 IHTMLTable_Release(table);
8109 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const WCHAR *text)
8111 SAFEARRAYBOUND dim;
8112 SAFEARRAY *sa;
8113 VARIANT *var;
8114 HRESULT hres;
8116 dim.lLbound = 0;
8117 dim.cElements = 1;
8118 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
8119 hres = SafeArrayAccessData(sa, (void**)&var);
8120 ok(hres == S_OK, "Failed to access array data: %08x\n", hres);
8121 V_VT(var) = VT_BSTR;
8122 V_BSTR(var) = SysAllocString(text);
8123 SafeArrayUnaccessData(sa);
8125 if(ln)
8126 hres = IHTMLDocument2_writeln(doc, sa);
8127 else
8128 hres = IHTMLDocument2_write(doc, sa);
8129 ok(hres == S_OK, "write failed: %08x\n", hres);
8131 SafeArrayDestroy(sa);
8134 static void doc_complex_write(IHTMLDocument2 *doc)
8136 SAFEARRAYBOUND dim = {5, 0};
8137 SAFEARRAY *sa;
8138 VARIANT *args;
8139 HRESULT hres;
8141 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
8142 hres = SafeArrayAccessData(sa, (void**)&args);
8143 ok(hres == S_OK, "Failed to access array data: %08x\n", hres);
8145 V_VT(args) = VT_BSTR;
8146 V_BSTR(args) = SysAllocString(L"<body i4val=\"");
8147 V_VT(args+1) = VT_I4;
8148 V_I4(args+1) = 4;
8149 V_VT(args+2) = VT_BSTR;
8150 V_BSTR(args+2) = SysAllocString(L"\" r8val=\"");
8151 V_VT(args+3) = VT_R8;
8152 V_R8(args+3) = 3.14;
8153 V_VT(args+4) = VT_BSTR;
8154 V_BSTR(args+4) = SysAllocString(L"\">");
8155 SafeArrayUnaccessData(sa);
8157 hres = IHTMLDocument2_write(doc, sa);
8158 ok(hres == S_OK, "write failed: %08x\n", hres);
8160 SafeArrayDestroy(sa);
8163 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
8165 IHTMLDocument2 *window_doc, *elem_doc;
8166 IHTMLFrameElement3 *frame_elem3;
8167 IHTMLWindow2 *content_window;
8168 HRESULT hres;
8170 content_window = get_frame_content_window(frame_elem);
8171 test_ifaces((IUnknown*)content_window, window_iids);
8172 window_doc = get_window_doc(content_window);
8173 IHTMLWindow2_Release(content_window);
8175 elem_doc = get_elem_doc(frame_elem);
8176 ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
8178 if(!iframe) {
8179 hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
8180 if(SUCCEEDED(hres)) {
8181 IDispatch *disp = NULL;
8183 hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
8184 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
8185 ok(disp != NULL, "contentDocument == NULL\n");
8186 ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
8188 IDispatch_Release(disp);
8189 IHTMLFrameElement3_Release(frame_elem3);
8190 }else {
8191 win_skip("IHTMLFrameElement3 not supported\n");
8195 IHTMLDocument2_Release(elem_doc);
8196 IHTMLDocument2_Release(window_doc);
8199 #define test_iframe_height(a,b) _test_iframe_height(__LINE__,a,b)
8200 static void _test_iframe_height(unsigned line, IHTMLElement *elem, const WCHAR *exval)
8202 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
8203 VARIANT v;
8204 HRESULT hres;
8206 hres = IHTMLIFrameElement2_get_height(iframe, &v);
8207 ok_(__FILE__,line)(hres == S_OK, "get_height failed: %08x\n", hres);
8208 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(height) = %d\n", V_VT(&v));
8209 if(exval)
8210 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exval), "height = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8211 else
8212 ok_(__FILE__,line)(!V_BSTR(&v), "height = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
8213 VariantClear(&v);
8214 IHTMLIFrameElement2_Release(iframe);
8217 #define set_iframe_height(a,b) _set_iframe_height(__LINE__,a,b)
8218 static void _set_iframe_height(unsigned line, IHTMLElement *elem, const WCHAR *val)
8220 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
8221 VARIANT v;
8222 HRESULT hres;
8224 V_VT(&v) = VT_BSTR;
8225 V_BSTR(&v) = SysAllocString(val);
8226 hres = IHTMLIFrameElement2_put_height(iframe, v);
8227 ok_(__FILE__,line)(hres == S_OK, "put_height failed: %08x\n", hres);
8228 VariantClear(&v);
8229 IHTMLIFrameElement2_Release(iframe);
8232 #define test_iframe_width(a,b) _test_iframe_width(__LINE__,a,b)
8233 static void _test_iframe_width(unsigned line, IHTMLElement *elem, const WCHAR *exval)
8235 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
8236 VARIANT v;
8237 HRESULT hres;
8239 hres = IHTMLIFrameElement2_get_width(iframe, &v);
8240 ok_(__FILE__,line)(hres == S_OK, "get_width failed: %08x\n", hres);
8241 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(width) = %d\n", V_VT(&v));
8242 if(exval)
8243 ok_(__FILE__,line)(!lstrcmpW(V_BSTR(&v), exval), "width = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8244 else
8245 ok_(__FILE__,line)(!V_BSTR(&v), "width = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
8246 VariantClear(&v);
8247 IHTMLIFrameElement2_Release(iframe);
8250 #define set_iframe_width(a,b) _set_iframe_width(__LINE__,a,b)
8251 static void _set_iframe_width(unsigned line, IHTMLElement *elem, const WCHAR *val)
8253 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
8254 VARIANT v;
8255 HRESULT hres;
8257 V_VT(&v) = VT_BSTR;
8258 V_BSTR(&v) = SysAllocString(val);
8259 hres = IHTMLIFrameElement2_put_width(iframe, v);
8260 ok_(__FILE__,line)(hres == S_OK, "put_width failed: %08x\n", hres);
8261 VariantClear(&v);
8262 IHTMLIFrameElement2_Release(iframe);
8265 static void test_iframe_elem(IHTMLElement *elem)
8267 IHTMLDocument2 *content_doc, *owner_doc;
8268 IHTMLIFrameElement2 *iframe2;
8269 IHTMLIFrameElement3 *iframe3;
8270 IHTMLElementCollection *col;
8271 IHTMLWindow2 *content_window;
8272 IHTMLElement *body;
8273 IDispatch *disp;
8274 VARIANT errv, v;
8275 BSTR str;
8276 HRESULT hres;
8278 static const elem_type_t all_types[] = {
8279 ET_HTML,
8280 ET_HEAD,
8281 ET_TITLE,
8282 ET_BODY,
8283 ET_BR
8286 test_frame_doc((IUnknown*)elem, TRUE);
8287 test_framebase((IUnknown*)elem);
8289 content_window = get_frame_content_window((IUnknown*)elem);
8290 test_ifaces((IUnknown*)content_window, window_iids);
8291 test_window_length(content_window, 0);
8293 content_doc = get_window_doc(content_window);
8294 IHTMLWindow2_Release(content_window);
8296 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLIFrameElement3, (void**)&iframe3);
8297 if(SUCCEEDED(hres)) {
8298 hres = IHTMLIFrameElement3_get_contentDocument(iframe3, &disp);
8299 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
8300 ok(iface_cmp((IUnknown*)content_doc, (IUnknown*)disp), "content_doc != disp\n");
8301 IDispatch_Release(disp);
8303 IHTMLIFrameElement3_Release(iframe3);
8304 }else {
8305 win_skip("IHTMLIFrameElement3 not supported\n");
8308 iframe2 = get_iframe2_iface((IUnknown*)elem);
8310 test_iframe_height(elem, NULL);
8311 set_iframe_height(elem, L"100px");
8312 set_iframe_height(elem, L"50%");
8313 test_iframe_height(elem, L"50%");
8315 V_VT(&v) = VT_I4;
8316 V_I4(&v) = 100;
8317 hres = IHTMLIFrameElement2_put_height(iframe2, v);
8318 ok(hres == S_OK, "put_height failed: %08x\n", hres);
8319 test_iframe_height(elem, L"100");
8321 test_iframe_width(elem, NULL);
8322 set_iframe_width(elem, L"150px");
8323 set_iframe_width(elem, L"70%");
8324 test_iframe_width(elem, L"70%");
8325 test_framebase_src(elem, L"about:blank");
8327 V_VT(&v) = VT_I4;
8328 V_I4(&v) = 110;
8329 hres = IHTMLIFrameElement2_put_width(iframe2, v);
8330 ok(hres == S_OK, "put_height failed: %08x\n", hres);
8331 test_iframe_width(elem, L"110");
8333 str = SysAllocString(L"text/html");
8334 V_VT(&errv) = VT_ERROR;
8335 disp = NULL;
8336 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
8337 SysFreeString(str);
8338 ok(hres == S_OK, "open failed: %08x\n", hres);
8339 ok(disp != NULL, "disp == NULL\n");
8340 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
8341 IDispatch_Release(disp);
8343 doc_write(content_doc, FALSE, L"<html><head><title>test</title></head>");
8344 doc_complex_write(content_doc);
8345 doc_write(content_doc, TRUE, L"<br />");
8346 doc_write(content_doc, TRUE, L"</html>");
8348 hres = IHTMLDocument2_get_all(content_doc, &col);
8349 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8350 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
8351 IHTMLElementCollection_Release(col);
8353 body = doc_get_body(content_doc);
8354 test_elem_attr(body, L"i4val", L"4");
8355 test_elem_attr(body, L"r8val", L"3.14");
8356 IHTMLElement_Release(body);
8357 IHTMLIFrameElement2_Release(iframe2);
8359 hres = IHTMLDocument2_close(content_doc);
8360 ok(hres == S_OK, "close failed: %08x\n", hres);
8362 owner_doc = get_owner_doc((IUnknown*)content_doc);
8363 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
8365 IHTMLDocument2_Release(content_doc);
8368 static void test_elem_spellcheck(IHTMLElement *iface)
8370 IHTMLElement7 *elem;
8371 VARIANT v;
8372 HRESULT hres;
8374 hres = IUnknown_QueryInterface(iface, &IID_IHTMLElement7, (void**)&elem);
8375 if(hres == E_NOINTERFACE) {
8376 win_skip("IHTMLElement7 not supported\n");
8377 return;
8379 ok(hres == S_OK, "Could not get IHTMLElement7 interface: %08x\n", hres);
8381 V_VT(&v) = VT_ERROR;
8382 hres = IHTMLElement7_get_spellcheck(elem, &v);
8383 ok(hres == S_OK, "get_spellcheck failed: %08x\n", hres);
8384 ok(V_VT(&v) == VT_BOOL && !V_BOOL(&v), "spellcheck = %s\n", wine_dbgstr_variant(&v));
8386 V_VT(&v) = VT_BOOL;
8387 V_BOOL(&v) = VARIANT_TRUE;
8388 hres = IHTMLElement7_put_spellcheck(elem, v);
8389 ok(hres == S_OK, "put_spellcheck failed: %08x\n", hres);
8391 V_VT(&v) = VT_ERROR;
8392 hres = IHTMLElement7_get_spellcheck(elem, &v);
8393 ok(hres == S_OK, "get_spellcheck failed: %08x\n", hres);
8394 ok(V_VT(&v) == VT_BOOL && V_BOOL(&v) == VARIANT_TRUE, "spellcheck = %s\n",
8395 wine_dbgstr_variant(&v));
8397 V_VT(&v) = VT_BOOL;
8398 V_BOOL(&v) = VARIANT_FALSE;
8399 hres = IHTMLElement7_put_spellcheck(elem, v);
8400 ok(hres == S_OK, "put_spellcheck failed: %08x\n", hres);
8402 V_VT(&v) = VT_ERROR;
8403 hres = IHTMLElement7_get_spellcheck(elem, &v);
8404 ok(hres == S_OK, "get_spellcheck failed: %08x\n", hres);
8405 ok(V_VT(&v) == VT_BOOL && !V_BOOL(&v), "spellcheck = %s\n", wine_dbgstr_variant(&v));
8407 IHTMLElement7_Release(elem);
8410 #define test_stylesheet_csstext(a,b,c) _test_stylesheet_csstext(__LINE__,a,b,c)
8411 static void _test_stylesheet_csstext(unsigned line, IHTMLStyleSheet *stylesheet, const WCHAR *exstr, BOOL is_todo)
8413 BSTR str;
8414 HRESULT hres;
8416 hres = IHTMLStyleSheet_get_cssText(stylesheet, &str);
8417 ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
8418 todo_wine_if(is_todo) {
8419 if(exstr)
8420 ok_(__FILE__,line)(str && !wcsncmp(str, exstr, lstrlenW(exstr)), "cssText = %s\n", wine_dbgstr_w(str));
8421 else
8422 ok_(__FILE__,line)(!str, "cssText = %s\n", wine_dbgstr_w(str));
8425 SysFreeString(str);
8428 #define set_stylesheet_csstext(a,b,c) _set_stylesheet_csstext(__LINE__,a,b,c)
8429 static void _set_stylesheet_csstext(unsigned line, IHTMLStyleSheet *stylesheet, const WCHAR *csstext, BOOL is_todo)
8431 BSTR str = SysAllocString(csstext);
8432 HRESULT hres;
8434 hres = IHTMLStyleSheet_put_cssText(stylesheet, str);
8435 todo_wine_if(is_todo)
8436 ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
8437 SysFreeString(str);
8440 static void test_stylesheet(IDispatch *disp)
8442 IHTMLStyleSheetRulesCollection *col = NULL;
8443 IHTMLStyleSheet *stylesheet;
8444 IHTMLStyleSheetRule *rule;
8445 HRESULT hres;
8446 BSTR href;
8448 test_disp2((IUnknown*)disp, &DIID_DispHTMLStyleSheet, &IID_IHTMLStyleSheet, NULL, L"[object]");
8450 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
8451 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
8453 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
8454 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
8455 ok(col != NULL, "col == NULL\n");
8457 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetRulesCollection, &IID_IHTMLStyleSheetRulesCollection, NULL, L"[object]");
8458 IHTMLStyleSheetRulesCollection_Release(col);
8460 href = (void*)0xdeadbeef;
8461 hres = IHTMLStyleSheet_get_href(stylesheet, &href);
8462 ok(hres == S_OK, "get_href failed: %08x\n", hres);
8463 ok(href == NULL, "got href != NULL\n");
8464 SysFreeString(href);
8466 test_stylesheet_csstext(stylesheet, L".body {", FALSE);
8467 set_stylesheet_csstext(stylesheet, L".div { margin-right: 1px; }\n.body { margin-right: 2px; }", TRUE);
8468 test_stylesheet_csstext(stylesheet, L".div {", TRUE);
8469 set_stylesheet_csstext(stylesheet, L"", FALSE);
8470 test_stylesheet_csstext(stylesheet, NULL, FALSE);
8471 set_stylesheet_csstext(stylesheet, L".div { margin-right: 1px; }", FALSE);
8472 test_stylesheet_csstext(stylesheet, L".div {", FALSE);
8474 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
8475 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
8476 ok(col != NULL, "col == NULL\n");
8478 hres = IHTMLStyleSheetRulesCollection_item(col, 0, &rule);
8479 ok(hres == S_OK, "IHTMLStyleSheetRulesCollection_item failed: %08x\n", hres);
8480 ok(rule != NULL, "rule = NULL\n");
8481 test_disp((IUnknown*)rule, &DIID_DispHTMLStyleSheetRule, NULL, L"[object]");
8482 IHTMLStyleSheetRule_Release(rule);
8484 hres = IHTMLStyleSheetRulesCollection_item(col, 1, &rule);
8485 ok(hres == E_INVALIDARG, "IHTMLStyleSheetRulesCollection_item failed: %08x\n", hres);
8487 IHTMLStyleSheetRulesCollection_Release(col);
8489 IHTMLStyleSheet_Release(stylesheet);
8492 static void test_stylesheets(IHTMLDocument2 *doc)
8494 IHTMLStyleSheetsCollection *col = NULL;
8495 VARIANT idx, res;
8496 LONG len = 0;
8497 HRESULT hres;
8499 hres = IHTMLDocument2_get_styleSheets(doc, &col);
8500 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
8501 ok(col != NULL, "col == NULL\n");
8503 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, NULL, L"[object]");
8505 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
8506 ok(hres == S_OK, "get_length failed: %08x\n", hres);
8507 ok(len == 1, "len=%d\n", len);
8509 VariantInit(&res);
8510 V_VT(&idx) = VT_I4;
8511 V_I4(&idx) = 0;
8513 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
8514 ok(hres == S_OK, "item failed: %08x\n", hres);
8515 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
8516 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
8517 test_stylesheet(V_DISPATCH(&res));
8518 VariantClear(&res);
8520 V_VT(&res) = VT_I4;
8521 V_VT(&idx) = VT_I4;
8522 V_I4(&idx) = 1;
8524 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
8525 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
8526 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
8527 VariantClear(&res);
8529 IHTMLStyleSheetsCollection_Release(col);
8532 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
8534 IDispatchEx *dispex;
8535 IHTMLDOMNode *node;
8536 DISPPARAMS dp = {NULL, NULL, 0, 0};
8537 VARIANT var;
8538 EXCEPINFO ei;
8539 LONG type;
8540 DISPID id;
8541 BSTR bstr;
8542 HRESULT hres;
8544 static const WCHAR w0[] = {'0',0};
8545 static const WCHAR w100[] = {'1','0','0',0};
8547 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
8548 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
8550 bstr = SysAllocString(w0);
8551 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
8552 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
8553 SysFreeString(bstr);
8555 VariantInit(&var);
8556 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
8557 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
8558 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
8559 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
8560 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
8561 type = get_node_type((IUnknown*)node);
8562 ok(type == 3, "type=%d\n", type);
8563 IHTMLDOMNode_Release(node);
8564 VariantClear(&var);
8566 bstr = SysAllocString(w100);
8567 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
8568 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
8569 SysFreeString(bstr);
8571 IDispatchEx_Release(dispex);
8574 static void test_enum_children(IUnknown *unk, unsigned len)
8576 IEnumVARIANT *enum_var;
8577 ULONG i, fetched;
8578 VARIANT v;
8579 HRESULT hres;
8581 hres = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&enum_var);
8582 ok(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
8584 for(i=0; i<len; i++) {
8585 fetched = 0;
8586 V_VT(&v) = VT_ERROR;
8587 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
8588 ok(hres == S_OK, "Next failed: %08x\n", hres);
8589 if(i)
8590 ok(fetched == 1, "fetched = %d\n", fetched);
8591 ok(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
8592 IDispatch_Release(V_DISPATCH(&v));
8595 fetched = 0xdeadbeef;
8596 V_VT(&v) = VT_BOOL;
8597 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
8598 ok(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
8599 ok(fetched == 0, "fetched = %d\n", fetched);
8600 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
8602 hres = IEnumVARIANT_Reset(enum_var);
8603 ok(hres == S_OK, "Reset failed: %08x\n", hres);
8605 fetched = 0xdeadbeef;
8606 V_VT(&v) = VT_BOOL;
8607 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
8608 ok(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
8609 ok(fetched == 0, "fetched = %d\n", fetched);
8610 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
8612 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
8613 ok(hres == S_OK, "Skip failed: %08x\n", hres);
8615 hres = IEnumVARIANT_Reset(enum_var);
8616 ok(hres == S_OK, "Reset failed: %08x\n", hres);
8618 hres = IEnumVARIANT_Skip(enum_var, len+1);
8619 ok(hres == S_FALSE, "Skip failed: %08x\n", hres);
8621 IEnumVARIANT_Release(enum_var);
8624 static void test_selectors(IHTMLDocument2 *doc, IHTMLElement *div)
8626 IHTMLDOMChildrenCollection *collection;
8627 IDocumentSelector *doc_selector;
8628 IElementSelector *elem_selector;
8629 BSTR str;
8630 HRESULT hres;
8632 test_elem_set_innerhtml((IUnknown*)div, L"<div class=\"cl1\"><form class=\"cl1\"></form></div><div class=\"cl2\"></div>");
8634 hres = IHTMLDocument2_QueryInterface(doc, &IID_IDocumentSelector, (void**)&doc_selector);
8635 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDocumentSelector iface: %08x\n", hres);
8636 if(FAILED(hres)) {
8637 win_skip("IDocumentSelector tests skipped.\n");
8638 return;
8641 collection = NULL;
8642 str = SysAllocString(L"nomatch");
8643 hres = IDocumentSelector_querySelectorAll(doc_selector, str, &collection);
8644 ok(hres == S_OK, "querySelectorAll failed: %08x\n", hres);
8645 ok(collection != NULL, "collection == NULL\n");
8646 test_children_collection_length(collection, 0);
8647 IHTMLDOMChildrenCollection_Release(collection);
8648 SysFreeString(str);
8650 collection = NULL;
8651 str = SysAllocString(L".cl1");
8652 hres = IDocumentSelector_querySelectorAll(doc_selector, str, &collection);
8653 ok(hres == S_OK, "querySelectorAll failed: %08x\n", hres);
8654 ok(collection != NULL, "collection == NULL\n");
8655 test_children_collection_length(collection, 2);
8656 IHTMLDOMChildrenCollection_Release(collection);
8657 SysFreeString(str);
8659 IDocumentSelector_Release(doc_selector);
8661 hres = IHTMLElement_QueryInterface(div, &IID_IElementSelector, (void**)&elem_selector);
8662 ok(hres == S_OK, "Could not get IElementSelector iface: %08x\n", hres);
8664 collection = NULL;
8665 str = SysAllocString(L"nomatch");
8666 hres = IElementSelector_querySelectorAll(elem_selector, str, &collection);
8667 ok(hres == S_OK, "querySelectorAll failed: %08x\n", hres);
8668 ok(collection != NULL, "collection == NULL\n");
8669 test_children_collection_length(collection, 0);
8670 IHTMLDOMChildrenCollection_Release(collection);
8671 SysFreeString(str);
8673 collection = NULL;
8674 str = SysAllocString(L".cl1");
8675 hres = IElementSelector_querySelectorAll(elem_selector, str, &collection);
8676 ok(hres == S_OK, "querySelectorAll failed: %08x\n", hres);
8677 ok(collection != NULL, "collection == NULL\n");
8678 test_children_collection_length(collection, 2);
8679 IHTMLDOMChildrenCollection_Release(collection);
8680 SysFreeString(str);
8682 IElementSelector_Release(elem_selector);
8685 static void test_elemsbyclass(IHTMLElement *div)
8687 IHTMLElementCollection *collection;
8688 IHTMLElement6 *elem;
8689 BSTR str;
8690 HRESULT hres;
8692 static const elem_type_t types[] = {ET_DIV, ET_FORM};
8694 test_elem_set_innerhtml((IUnknown*)div, L"<div class=\"cl1\"><form class=\"cl1\"></form></div><div class=\"cl2\"></div>");
8696 hres = IHTMLElement_QueryInterface(div, &IID_IHTMLElement6, (void**)&elem);
8697 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IHTMLElement6 iface: %08x\n", hres);
8698 if(FAILED(hres)) {
8699 win_skip("IHTMLElement6 tests skipped.\n");
8700 return;
8703 collection = NULL;
8704 str = SysAllocString(L"nomatch");
8705 hres = IHTMLElement6_getElementsByClassName(elem, str, &collection);
8706 ok(hres == S_OK, "getElementsByClassName failed: %08x\n", hres);
8707 ok(collection != NULL, "collection == NULL\n");
8708 test_elem_collection((IUnknown*)collection, NULL, 0);
8709 IHTMLElementCollection_Release(collection);
8710 SysFreeString(str);
8712 collection = NULL;
8713 str = SysAllocString(L"cl1");
8714 hres = IHTMLElement6_getElementsByClassName(elem, str, &collection);
8715 ok(hres == S_OK, "getElementsByClassName failed: %08x\n", hres);
8716 ok(collection != NULL, "collection == NULL\n");
8717 test_elem_collection((IUnknown*)collection, types, ARRAY_SIZE(types));
8718 IHTMLElementCollection_Release(collection);
8719 SysFreeString(str);
8721 IHTMLElement6_Release(elem);
8724 static void test_elems(IHTMLDocument2 *doc)
8726 IHTMLElementCollection *col;
8727 IHTMLDOMChildrenCollection *child_col;
8728 IHTMLElement *elem, *elem2, *elem3;
8729 IHTMLDOMNode *node, *node2;
8730 IHTMLWindow2 *window;
8731 IDispatch *disp;
8732 LONG type;
8733 HRESULT hres;
8734 IHTMLElementCollection *collection;
8735 IHTMLDocument3 *doc3;
8736 BSTR str;
8738 static const elem_type_t all_types[] = {
8739 ET_HTML,
8740 ET_HEAD,
8741 ET_TITLE,
8742 ET_STYLE,
8743 ET_META,
8744 ET_LINK,
8745 ET_BODY,
8746 ET_COMMENT,
8747 ET_A,
8748 ET_LABEL,
8749 ET_INPUT,
8750 ET_BUTTON,
8751 ET_SELECT,
8752 ET_OPTION,
8753 ET_OPTION,
8754 ET_TEXTAREA,
8755 ET_TABLE,
8756 ET_TBODY,
8757 ET_TR,
8758 ET_TR,
8759 ET_TD,
8760 ET_TD,
8761 ET_SCRIPT,
8762 ET_TEST,
8763 ET_OBJECT,
8764 ET_EMBED,
8765 ET_IMG,
8766 ET_IFRAME,
8767 ET_FORM,
8768 ET_DIV
8771 static const elem_type_t item_types[] = {
8772 ET_A,
8773 ET_OPTION,
8774 ET_TEXTAREA
8777 hres = IHTMLDocument2_get_all(doc, &col);
8778 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8779 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
8780 test_elem_col_item(col, L"x", item_types, ARRAY_SIZE(item_types));
8782 elem = get_elem_col_item_idx(col, 0);
8783 test_elem_source_index(elem, 0);
8784 IHTMLElement_Release(elem);
8786 elem = get_elem_col_item_idx(col, 3);
8787 test_elem_source_index(elem, 3);
8788 IHTMLElement_Release(elem);
8790 IHTMLElementCollection_Release(col);
8792 hres = IHTMLDocument2_get_images(doc, &collection);
8793 ok(hres == S_OK, "get_images failed: %08x\n", hres);
8794 if(hres == S_OK)
8796 static const elem_type_t images_types[] = {ET_IMG};
8797 test_elem_collection((IUnknown*)collection, images_types, 1);
8799 IHTMLElementCollection_Release(collection);
8802 hres = IHTMLDocument2_get_links(doc, &collection);
8803 ok(hres == S_OK, "get_links failed: %08x\n", hres);
8804 if(hres == S_OK)
8806 static const elem_type_t images_types[] = {ET_A};
8807 test_elem_collection((IUnknown*)collection, images_types, 1);
8809 IHTMLElementCollection_Release(collection);
8812 hres = IHTMLDocument2_get_anchors(doc, &collection);
8813 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
8814 if(hres == S_OK)
8816 static const elem_type_t anchor_types[] = {ET_A};
8817 test_elem_collection((IUnknown*)collection, anchor_types, 1);
8819 IHTMLElementCollection_Release(collection);
8822 hres = IHTMLDocument2_get_scripts(doc, &collection);
8823 ok(hres == S_OK, "get_scripts failed: %08x\n", hres);
8824 if(hres == S_OK) {
8825 static const elem_type_t script_types[] = {ET_SCRIPT};
8826 test_elem_collection((IUnknown*)collection, script_types, 1);
8827 IHTMLElementCollection_Release(collection);
8830 test_plugins_col(doc);
8832 elem = get_doc_elem(doc);
8833 test_elem_istextedit(elem, VARIANT_FALSE);
8834 test_elem_all((IUnknown*)elem, all_types+1, ARRAY_SIZE(all_types)-1);
8835 IHTMLElement_Release(elem);
8837 get_elem_by_id(doc, L"xxx", FALSE);
8838 elem = get_doc_elem_by_id(doc, L"xxx");
8839 ok(!elem, "elem != NULL\n");
8841 elem = get_doc_elem_by_id(doc, L"s");
8842 ok(elem != NULL, "elem == NULL\n");
8843 if(elem) {
8844 test_elem_type((IUnknown*)elem, ET_SELECT);
8845 test_elem_attr(elem, L"xxx", NULL);
8846 test_elem_attr(elem, L"id", L"s");
8847 test_elem_class((IUnknown*)elem, NULL);
8848 test_elem_set_class((IUnknown*)elem, L"cl");
8849 test_elem_set_class((IUnknown*)elem, NULL);
8850 test_elem_tabindex((IUnknown*)elem, 0);
8851 test_elem_set_tabindex((IUnknown*)elem, 1);
8852 test_elem_filters((IUnknown*)elem);
8853 test_elem_istextedit(elem, VARIANT_FALSE);
8855 node = test_node_get_parent((IUnknown*)elem);
8856 ok(node != NULL, "node == NULL\n");
8857 test_node_name((IUnknown*)node, L"BODY");
8858 node2 = test_node_get_parent((IUnknown*)node);
8859 IHTMLDOMNode_Release(node);
8860 ok(node2 != NULL, "node == NULL\n");
8861 test_node_name((IUnknown*)node2, L"HTML");
8862 node = test_node_get_parent((IUnknown*)node2);
8863 IHTMLDOMNode_Release(node2);
8864 ok(node != NULL, "node == NULL\n");
8865 if (node)
8867 test_node_name((IUnknown*)node, L"#document");
8868 type = get_node_type((IUnknown*)node);
8869 ok(type == 9, "type=%d, expected 9\n", type);
8870 node2 = test_node_get_parent((IUnknown*)node);
8871 IHTMLDOMNode_Release(node);
8872 ok(node2 == NULL, "node != NULL\n");
8875 elem2 = test_elem_get_parent((IUnknown*)elem);
8876 ok(elem2 != NULL, "elem2 == NULL\n");
8877 test_node_name((IUnknown*)elem2, L"BODY");
8879 elem3 = test_elem_get_parent((IUnknown*)elem2);
8880 ok(elem3 != NULL, "elem3 == NULL\n");
8881 test_node_name((IUnknown*)elem3, L"HTML");
8883 test_elem_contains(elem3, elem2, VARIANT_TRUE);
8884 test_elem_contains(elem3, elem, VARIANT_TRUE);
8885 test_elem_contains(elem2, elem, VARIANT_TRUE);
8886 test_elem_contains(elem2, elem3, VARIANT_FALSE);
8887 test_elem_contains(elem, elem3, VARIANT_FALSE);
8888 test_elem_contains(elem, elem2, VARIANT_FALSE);
8889 test_elem_contains(elem, elem, VARIANT_TRUE);
8890 test_elem_contains(elem, NULL, VARIANT_FALSE);
8891 IHTMLElement_Release(elem2);
8893 elem2 = test_elem_get_parent((IUnknown*)elem3);
8894 ok(elem2 == NULL, "elem2 != NULL\n");
8895 test_elem_source_index(elem3, 0);
8896 IHTMLElement_Release(elem3);
8898 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2, NULL);
8899 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0, NULL);
8900 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0, NULL);
8902 test_elem_innertext(elem, L"opt1opt2");
8904 IHTMLElement_Release(elem);
8907 elem = get_elem_by_id(doc, L"s", TRUE);
8908 if(elem) {
8909 IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
8910 IHTMLDocument2 *doc_node, *elem_doc;
8912 test_select_elem(select);
8914 test_elem_istextedit(elem, VARIANT_FALSE);
8915 test_elem_title((IUnknown*)select, NULL);
8916 test_elem_set_title((IUnknown*)select, L"Title");
8917 test_elem_title((IUnknown*)select, L"Title");
8918 test_elem_offset((IUnknown*)select, L"BODY");
8919 test_elem_bounding_client_rect((IUnknown*)select);
8921 node = get_first_child((IUnknown*)select);
8922 ok(node != NULL, "node == NULL\n");
8923 if(node) {
8924 test_elem_type((IUnknown*)node, ET_OPTION);
8925 IHTMLDOMNode_Release(node);
8928 type = get_node_type((IUnknown*)select);
8929 ok(type == 1, "type=%d\n", type);
8931 IHTMLSelectElement_Release(select);
8933 elem_doc = get_elem_doc((IUnknown*)elem);
8935 doc_node = get_doc_node(doc);
8936 ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
8937 IHTMLDocument2_Release(doc_node);
8938 IHTMLDocument2_Release(elem_doc);
8940 IHTMLElement_Release(elem);
8943 elem = doc_get_body(doc);
8944 test_elem_offset((IUnknown*)elem, NULL);
8945 IHTMLElement_Release(elem);
8947 elem = get_elem_by_id(doc, L"sc", TRUE);
8948 if(elem) {
8949 IHTMLScriptElement *script;
8950 BSTR type;
8952 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
8953 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
8955 test_elem_language(elem, NULL);
8956 test_elem_istextedit(elem, VARIANT_FALSE);
8958 if(hres == S_OK)
8960 VARIANT_BOOL vb;
8962 hres = IHTMLScriptElement_put_type (script, NULL);
8963 ok(hres == S_OK, "put_type failed: %08x\n", hres);
8964 hres = IHTMLScriptElement_get_type(script, &type);
8965 ok(hres == S_OK, "get_type failed: %08x\n", hres);
8966 ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
8968 type = SysAllocString(L"text/javascript");
8969 hres = IHTMLScriptElement_put_type (script, type);
8970 ok(hres == S_OK, "put_type failed: %08x\n", hres);
8971 SysFreeString(type);
8972 hres = IHTMLScriptElement_get_type(script, &type);
8973 ok(hres == S_OK, "get_type failed: %08x\n", hres);
8974 ok(!lstrcmpW(type, L"text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
8975 SysFreeString(type);
8977 test_script_text(script, L"<!--\nfunction Testing() {}\n// -->\n");
8979 /* test defer */
8980 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
8981 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
8983 hres = IHTMLScriptElement_get_defer(script, &vb);
8984 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
8985 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
8987 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
8988 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
8990 str = (BSTR)0xdeadbeef;
8991 hres = IHTMLScriptElement_get_src(script, &str);
8992 ok(hres == S_OK, "get_src failed: %08x\n", hres);
8993 ok(!str, "src = %s\n", wine_dbgstr_w(str));
8995 str = (BSTR)0xdeadbeef;
8996 hres = IHTMLScriptElement_get_htmlFor(script, &str);
8997 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
8998 ok(!str, "htmlFor = %s\n", wine_dbgstr_w(str));
9001 IHTMLScriptElement_Release(script);
9003 set_elem_language(elem, L"vbscript");
9004 set_elem_language(elem, L"xxx");
9007 elem = get_elem_by_id(doc, L"in", TRUE);
9008 if(elem) {
9009 IHTMLInputElement *input;
9011 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
9012 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
9014 test_elem_id((IUnknown*)elem, L"in");
9015 test_elem_put_id((IUnknown*)elem, L"newin");
9016 test_input_get_disabled(input, VARIANT_FALSE);
9017 test_input_set_disabled(input, VARIANT_TRUE);
9018 test_input_set_disabled(input, VARIANT_FALSE);
9019 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
9020 test_input_get_disabled(input, VARIANT_TRUE);
9021 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
9022 test_input_get_disabled(input, VARIANT_FALSE);
9023 test_elem_client_size((IUnknown*)elem);
9024 test_input_type(input, L"text");
9025 test_elem_istextedit(elem, VARIANT_TRUE);
9026 test_elem_spellcheck(elem);
9028 test_node_get_value_str((IUnknown*)elem, NULL);
9029 test_node_put_value_str((IUnknown*)elem, L"test");
9030 test_node_get_value_str((IUnknown*)elem, NULL);
9031 test_input_value((IUnknown*)elem, NULL);
9032 test_input_defaultValue((IUnknown*)elem, NULL);
9033 test_input_put_value((IUnknown*)elem, L"test");
9034 test_input_defaultValue((IUnknown*)elem, NULL);
9035 test_elem_class((IUnknown*)elem, L"testclass");
9036 test_elem_tabindex((IUnknown*)elem, 2);
9037 test_elem_set_tabindex((IUnknown*)elem, 3);
9038 test_elem_title((IUnknown*)elem, L"test title");
9040 test_input_get_defaultchecked(input, VARIANT_FALSE);
9041 test_input_set_defaultchecked(input, VARIANT_TRUE);
9042 test_input_set_defaultchecked(input, VARIANT_FALSE);
9044 test_input_get_checked(input, VARIANT_FALSE);
9045 test_input_set_checked(input, VARIANT_TRUE);
9046 test_input_set_checked(input, VARIANT_FALSE);
9048 test_input_maxlength(input, 0x7fffffff);
9049 test_input_set_maxlength(input, 30);
9051 test_input_name(input, NULL);
9052 test_input_set_name(input, L"test");
9054 test_input_src(input, NULL);
9055 test_input_set_src(input, L"about:blank");
9057 test_input_set_size(input, 15, S_OK);
9058 test_input_get_size(input, 15);
9059 test_input_set_size(input, -100, CTL_E_INVALIDPROPERTYVALUE);
9060 test_input_get_size(input, 15);
9061 test_input_set_size(input, 0, CTL_E_INVALIDPROPERTYVALUE);
9062 test_input_get_size(input, 15);
9064 test_input_readOnly(input, VARIANT_TRUE);
9065 test_input_readOnly(input, VARIANT_FALSE);
9067 test_elem_lang(elem, NULL);
9068 set_elem_lang(elem, L"en-us");
9070 IHTMLInputElement_Release(input);
9071 IHTMLElement_Release(elem);
9074 elem = get_elem_by_id(doc, L"imgid", TRUE);
9075 if(elem) {
9076 test_img_align((IUnknown*)elem, L"left");
9077 test_img_name((IUnknown*)elem, L"WineImg");
9078 test_img_src((IUnknown*)elem, L"", NULL);
9079 test_img_set_src((IUnknown*)elem, L"about:blank");
9080 test_img_src((IUnknown*)elem, L"about:blank", NULL);
9081 test_img_alt((IUnknown*)elem, NULL);
9082 test_img_set_alt((IUnknown*)elem, L"alt test");
9083 test_img_name((IUnknown*)elem, L"WineImg");
9084 test_img_complete(elem, VARIANT_FALSE);
9085 test_img_isMap((IUnknown*)elem, VARIANT_TRUE);
9086 test_img_isMap((IUnknown*)elem, VARIANT_FALSE);
9087 IHTMLElement_Release(elem);
9090 elem = get_elem_by_id(doc, L"attr", TRUE);
9091 if(elem) {
9092 test_dynamic_properties(elem);
9093 test_attr_collection(elem);
9094 test_contenteditable((IUnknown*)elem);
9095 IHTMLElement_Release(elem);
9098 elem = get_elem_by_id(doc, L"styleid", TRUE);
9099 if(elem) {
9100 test_style_media((IUnknown*)elem, NULL);
9101 test_style_put_media((IUnknown*)elem, L"screen");
9102 test_style_type((IUnknown*)elem, NULL);
9103 test_style_put_type((IUnknown*)elem, L"text/css");
9104 IHTMLElement_Release(elem);
9107 elem = get_doc_elem_by_id(doc, L"tbl");
9108 ok(elem != NULL, "elem == NULL\n");
9109 if(elem) {
9110 test_table_elem(elem);
9111 IHTMLElement_Release(elem);
9114 elem = get_doc_elem_by_id(doc, L"labelid");
9115 ok(elem != NULL, "elem == NULL\n");
9116 if(elem) {
9117 test_label_elem(elem);
9118 IHTMLElement_Release(elem);
9121 elem = get_doc_elem_by_id(doc, L"row2");
9122 ok(elem != NULL, "elem == NULL\n");
9123 if(elem) {
9124 test_tr_elem(elem);
9125 IHTMLElement_Release(elem);
9128 elem = get_doc_elem_by_id(doc, L"ifr");
9129 ok(elem != NULL, "elem == NULL\n");
9130 if(elem) {
9131 test_iframe_elem(elem);
9132 IHTMLElement_Release(elem);
9135 elem = get_doc_elem_by_id(doc, L"btnid");
9136 ok(elem != NULL, "elem == NULL\n");
9137 if(elem) {
9138 test_button_elem(elem);
9139 test_button_get_disabled(elem, VARIANT_FALSE);
9140 test_button_set_disabled(elem, VARIANT_TRUE);
9141 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
9142 test_button_get_disabled(elem, VARIANT_FALSE);
9143 IHTMLElement_Release(elem);
9146 elem = get_doc_elem_by_id(doc, L"objid");
9147 ok(elem != NULL, "elem == NULL\n");
9148 if(elem) {
9149 test_object_vspace((IUnknown*)elem, 100);
9150 test_object_name(elem, L"objname");
9151 set_object_name(elem, L"test");
9152 set_object_name(elem, NULL);
9153 IHTMLElement_Release(elem);
9156 elem = get_elem_by_id(doc, L"a", TRUE);
9157 if(elem) {
9158 test_anchor_href((IUnknown*)elem, L"http://test/");
9160 /* Change the href */
9161 test_anchor_put_href((IUnknown*)elem, L"http://test1/");
9162 test_anchor_href((IUnknown*)elem, L"http://test1/");
9163 test_anchor_hostname((IUnknown*)elem, L"test1");
9165 /* Restore the href */
9166 test_anchor_put_href((IUnknown*)elem, L"http://test/");
9167 test_anchor_href((IUnknown*)elem, L"http://test/");
9168 test_anchor_hostname((IUnknown*)elem, L"test");
9169 test_anchor_hash(elem, NULL);
9171 /* target */
9172 test_anchor_get_target((IUnknown*)elem, NULL);
9174 test_anchor_rel((IUnknown*)elem, NULL);
9175 test_anchor_put_rel((IUnknown*)elem, L"Next");
9176 test_anchor_rel((IUnknown*)elem, L"Next");
9178 /* Change the target */
9179 test_anchor_put_target((IUnknown*)elem, L"wine");
9180 test_anchor_get_target((IUnknown*)elem, L"wine");
9182 /* Restore the target */
9183 test_anchor_put_target((IUnknown*)elem, NULL);
9184 test_anchor_get_target((IUnknown*)elem, NULL);
9186 test_anchor_name((IUnknown*)elem, L"x");
9187 test_anchor_put_name((IUnknown*)elem, L"anchor name");
9188 test_anchor_put_name((IUnknown*)elem, NULL);
9189 test_anchor_put_name((IUnknown*)elem, L"x");
9191 test_anchor_put_href((IUnknown*)elem, L"http://test/?how#hash");
9192 test_anchor_hash(elem, L"#hash");
9193 test_anchor_search((IUnknown*)elem, L"?how", FALSE);
9195 test_anchor_put_search((IUnknown*)elem, L"?word=press");
9196 test_anchor_search((IUnknown*)elem, L"?word=press", FALSE);
9197 test_anchor_put_search((IUnknown*)elem, L"?????word???press");
9198 test_anchor_search((IUnknown*)elem, L"?????word???press", FALSE);
9200 test_anchor_put_search((IUnknown*)elem, L"?q=%E4%BD%A0%E5%A5%BD"); /* encoded cjk characters */
9201 test_anchor_search((IUnknown*)elem, L"?q=%E4%BD%A0%E5%A5%BD", FALSE);
9203 test_anchor_put_search((IUnknown*)elem, L"?how?old=are");
9204 test_anchor_search((IUnknown*)elem, L"?how?old=are", FALSE);
9206 /* due to incorrect behavior of ie6, search string without leading "?" is interpreted
9207 as part of the pathname, and cannot be accessed by get_search. */
9208 test_anchor_put_search((IUnknown*)elem, L"word=abc");
9209 test_anchor_search((IUnknown*)elem, L"?word=abc", TRUE);
9211 IHTMLElement_Release(elem);
9214 elem = get_doc_elem_by_id(doc, L"metaid");
9215 if(elem) {
9216 test_meta_name((IUnknown*)elem, L"meta name");
9217 test_meta_content((IUnknown*)elem, L"text/html; charset=utf-8");
9218 test_meta_httpequiv((IUnknown*)elem, L"Content-Type");
9219 test_meta_charset((IUnknown*)elem, NULL);
9220 set_meta_charset((IUnknown*)elem, L"utf-8");
9221 IHTMLElement_Release(elem);
9224 elem = doc_get_body(doc);
9226 node = get_first_child((IUnknown*)elem);
9227 ok(node != NULL, "node == NULL\n");
9228 if(node) {
9229 test_ifaces((IUnknown*)node, text_iids);
9230 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, NULL, L"[object]");
9232 node2 = get_first_child((IUnknown*)node);
9233 ok(!node2, "node2 != NULL\n");
9235 type = get_node_type((IUnknown*)node);
9236 ok(type == 3, "type=%d\n", type);
9238 test_node_get_value_str((IUnknown*)node, L"text test");
9239 test_node_put_value_str((IUnknown*)elem, L"test text");
9240 test_node_get_value_str((IUnknown*)node, L"text test");
9242 hres = IHTMLDOMNode_get_attributes(node, &disp);
9243 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
9244 ok(!disp, "disp != NULL\n");
9246 IHTMLDOMNode_Release(node);
9249 child_col = get_child_nodes((IUnknown*)elem);
9250 ok(child_col != NULL, "child_coll == NULL\n");
9251 if(child_col) {
9252 IUnknown *enum_unk;
9253 LONG length;
9255 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, NULL, L"[object]");
9256 length = test_children_collection_length(child_col, -1);
9258 node2 = NULL;
9259 node = get_child_item(child_col, 0);
9260 ok(node != NULL, "node == NULL\n");
9261 if(node) {
9262 IHTMLDOMNode *prev;
9264 type = get_node_type((IUnknown*)node);
9265 ok(type == 3, "type=%d\n", type);
9266 node2 = node_get_next((IUnknown*)node);
9268 prev = node_get_prev((IUnknown*)node2);
9269 ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
9270 IHTMLDOMNode_Release(prev);
9272 IHTMLDOMNode_Release(node);
9275 node = get_child_item(child_col, 1);
9276 ok(node != NULL, "node == NULL\n");
9277 if(node) {
9278 type = get_node_type((IUnknown*)node);
9279 ok(type == 8, "type=%d\n", type);
9281 test_elem_id((IUnknown*)node, NULL);
9282 ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
9283 IHTMLDOMNode_Release(node2);
9284 IHTMLDOMNode_Release(node);
9287 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
9288 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
9290 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
9291 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
9293 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
9294 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
9296 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
9297 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
9299 test_child_col_disp(child_col);
9301 hres = IHTMLDOMChildrenCollection_get__newEnum(child_col, &enum_unk);
9302 ok(hres == S_OK, "get__newEnum failed: %08x\n", hres);
9304 test_enum_children(enum_unk, length);
9306 IUnknown_Release(enum_unk);
9308 IHTMLDOMChildrenCollection_Release(child_col);
9311 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
9312 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
9313 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
9315 IHTMLElement_Release(elem);
9317 elem = get_doc_elem_by_id(doc, L"frm");
9318 ok(elem != NULL, "elem == NULL\n");
9319 if(elem) {
9320 test_form_length((IUnknown*)elem, 0);
9321 test_form_elements((IUnknown*)elem, NULL, 0);
9322 IHTMLElement_Release(elem);
9325 test_stylesheets(doc);
9326 test_create_option_elem(doc);
9327 test_create_img_elem(doc);
9329 elem = get_doc_elem_by_id(doc, L"tbl");
9330 ok(elem != NULL, "elem = NULL\n");
9331 test_elem_set_innertext(elem, L"inner text");
9332 IHTMLElement_Release(elem);
9334 test_doc_title(doc, L"test");
9335 test_doc_set_title(doc, L"test title");
9336 test_doc_title(doc, L"test title");
9338 disp = NULL;
9339 hres = IHTMLDocument2_get_Script(doc, &disp);
9340 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
9341 if(hres == S_OK)
9343 IDispatchEx *dispex;
9344 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
9345 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
9346 if(hres == S_OK)
9348 DISPID pid = -1;
9349 BSTR str = SysAllocString(L"Testing");
9350 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
9351 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
9352 ok(pid != -1, "pid == -1\n");
9353 SysFreeString(str);
9354 IDispatchEx_Release(dispex);
9357 IDispatch_Release(disp);
9359 test_doc_getelembytag(doc, "Img", ET_IMG, 1);
9361 elem = get_doc_elem_by_id(doc, L"y");
9362 test_elem_set_innerhtml((IUnknown*)elem, L"inner html");
9363 test_elem_innerhtml((IUnknown*)elem, L"inner html");
9364 test_elem_set_innerhtml((IUnknown*)elem, L"");
9365 test_elem_innerhtml((IUnknown*)elem, NULL);
9366 node = node_get_next((IUnknown*)elem);
9367 ok(!node, "node = %p\n", node);
9369 elem2 = get_doc_elem_by_id(doc, L"x");
9370 test_elem_tag((IUnknown*)elem2, L"A");
9371 node = node_get_next((IUnknown*)elem2);
9372 IHTMLDOMNode_Release(node);
9373 IHTMLElement_Release(elem2);
9374 IHTMLElement_Release(elem);
9376 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
9377 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
9379 hres = IHTMLDocument3_recalc(doc3, VARIANT_TRUE);
9380 ok(hres == S_OK, "recalc failed: %08x\n", hres);
9382 IHTMLDocument3_Release(doc3);
9384 elem = get_elem_by_id(doc, L"s", TRUE);
9385 if(elem) {
9386 static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
9388 test_select_put_length((IUnknown*)elem, 3);
9389 test_elem_all((IUnknown*)elem, select_types, ARRAY_SIZE(select_types));
9390 test_select_put_length((IUnknown*)elem, 1);
9391 test_elem_all((IUnknown*)elem, select_types, 1);
9392 IHTMLElement_Release(elem);
9395 window = get_doc_window(doc);
9396 test_window_name(window, NULL);
9397 set_window_name(window, L"test name");
9398 test_window_length(window, 1);
9399 IHTMLWindow2_Release(window);
9402 static void test_attr(IHTMLDocument2 *doc, IHTMLElement *elem)
9404 IHTMLDOMAttribute *attr, *attr2, *attr3;
9405 IHTMLElement4 *elem4;
9406 VARIANT v;
9407 HRESULT hres;
9409 get_elem_attr_node((IUnknown*)elem, L"noattr", FALSE);
9411 attr = get_elem_attr_node((IUnknown*)elem, L"id", TRUE);
9413 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, NULL, L"[object]");
9414 test_ifaces((IUnknown*)attr, attr_iids);
9415 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
9416 test_attr_specified(attr, VARIANT_TRUE);
9417 test_attr_parent(attr);
9419 attr2 = get_elem_attr_node((IUnknown*)elem, L"id", TRUE);
9420 ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
9421 IHTMLDOMAttribute_Release(attr2);
9423 get_attr_node_value(attr, &v, VT_BSTR);
9424 ok(!lstrcmpW(V_BSTR(&v), L"divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9425 VariantClear(&v);
9427 V_VT(&v) = VT_BSTR;
9428 V_BSTR(&v) = SysAllocString(L"divid2");
9429 put_attr_node_value(attr, v);
9430 VariantClear(&v);
9432 get_attr_node_value(attr, &v, VT_BSTR);
9433 ok(!lstrcmpW(V_BSTR(&v), L"divid2"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9434 VariantClear(&v);
9436 put_attr_value(attr, L"divid3");
9438 get_attr_node_value(attr, &v, VT_BSTR);
9439 ok(!lstrcmpW(V_BSTR(&v), L"divid3"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9440 VariantClear(&v);
9442 IHTMLDOMAttribute_Release(attr);
9444 attr = get_elem_attr_node((IUnknown*)elem, L"emptyattr", TRUE);
9445 get_attr_node_value(attr, &v, VT_BSTR);
9446 ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9447 VariantClear(&v);
9449 V_VT(&v) = VT_BSTR;
9450 V_BSTR(&v) = SysAllocString(L"newvalue");
9451 put_attr_node_value(attr, v);
9452 VariantClear(&v);
9454 attr = get_elem_attr_node((IUnknown*)elem, L"emptyattr", TRUE);
9455 get_attr_node_value(attr, &v, VT_BSTR);
9456 ok(!lstrcmpW(V_BSTR(&v), L"newvalue"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9457 VariantClear(&v);
9459 test_attr_specified(attr, VARIANT_TRUE);
9460 IHTMLDOMAttribute_Release(attr);
9462 V_VT(&v) = VT_I4;
9463 V_I4(&v) = 100;
9464 set_dispex_value((IUnknown*)elem, L"dispprop", &v);
9465 attr = get_elem_attr_node((IUnknown*)elem, L"dispprop", TRUE);
9466 get_attr_node_value(attr, &v, VT_I4);
9467 ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
9468 test_attr_specified(attr, VARIANT_TRUE);
9470 V_VT(&v) = VT_I4;
9471 V_I4(&v) = 150;
9472 put_attr_node_value(attr, v);
9474 get_attr_node_value(attr, &v, VT_I4);
9475 ok(V_I4(&v) == 150, "V_I4(v) = %d\n", V_I4(&v));
9477 put_attr_value(attr, L"160");
9478 get_attr_node_value(attr, &v, VT_BSTR);
9479 ok(!lstrcmpW(V_BSTR(&v), L"160"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
9480 VariantClear(&v);
9482 IHTMLDOMAttribute_Release(attr);
9484 attr = get_elem_attr_node((IUnknown*)elem, L"tabIndex", TRUE);
9485 test_attr_specified(attr, VARIANT_FALSE);
9486 test_attr_expando(attr, VARIANT_FALSE);
9487 IHTMLDOMAttribute_Release(attr);
9489 /* Test created, detached attribute. */
9490 attr = create_attr((IUnknown*)doc, "Test");
9492 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, NULL, L"[object]");
9493 test_ifaces((IUnknown*)attr, attr_iids);
9494 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
9496 test_attr_node_name(attr, L"Test");
9497 test_attr_expando(attr, VARIANT_FALSE);
9499 get_attr_node_value(attr, &v, VT_EMPTY);
9501 V_VT(&v) = VT_I4;
9502 V_I4(&v) = 1;
9503 put_attr_node_value(attr, v);
9505 get_attr_node_value(attr, &v, VT_I4);
9506 ok(V_I4(&v) == 1, "nodeValue = %d\n", V_I4(&v));
9507 test_attr_value(attr, L"1");
9509 V_VT(&v) = VT_EMPTY;
9510 put_attr_node_value(attr, v);
9511 get_attr_node_value(attr, &v, VT_EMPTY);
9513 V_VT(&v) = VT_BSTR;
9514 V_BSTR(&v) = SysAllocString(L"testing");
9515 put_attr_node_value(attr, v);
9516 SysFreeString(V_BSTR(&v));
9517 test_attr_value(attr, L"testing");
9519 elem4 = get_elem4_iface((IUnknown*)elem);
9521 hres = IHTMLElement4_setAttributeNode(elem4, attr, &attr2);
9522 ok(hres == S_OK, "setAttributeNode failed: %08x\n", hres);
9523 ok(!attr2, "attr2 != NULL\n");
9525 test_elem_attr(elem, L"Test", L"testing");
9526 put_attr_value(attr, L"new value");
9527 test_elem_attr(elem, L"Test", L"new value");
9529 attr2 = get_elem_attr_node((IUnknown*)elem, L"Test", TRUE);
9530 ok(iface_cmp((IUnknown*)attr2, (IUnknown*)attr), "attr2 != attr\n");
9531 IHTMLDOMAttribute_Release(attr2);
9533 attr3 = create_attr((IUnknown*)doc, "Test");
9534 put_attr_value(attr3, L"replace test");
9536 hres = IHTMLElement4_setAttributeNode(elem4, attr3, &attr2);
9537 ok(hres == S_OK, "setAttributeNode failed: %08x\n", hres);
9538 ok(iface_cmp((IUnknown*)attr2, (IUnknown*)attr), "attr2 != attr\n");
9539 IHTMLDOMAttribute_Release(attr2);
9541 test_elem_attr(elem, L"Test", L"replace test");
9542 test_attr_value(attr, L"new value");
9543 test_attr_value(attr3, L"replace test");
9545 attr2 = get_elem_attr_node((IUnknown*)elem, L"Test", TRUE);
9546 ok(iface_cmp((IUnknown*)attr2, (IUnknown*)attr3), "attr2 != attr3\n");
9547 IHTMLDOMAttribute_Release(attr2);
9549 put_attr_value(attr, L"new value2");
9550 test_elem_attr(elem, L"Test", L"replace test");
9551 test_attr_value(attr, L"new value2");
9552 test_attr_value(attr3, L"replace test");
9554 put_attr_value(attr3, L"new replace value");
9555 test_elem_attr(elem, L"Test", L"new replace value");
9556 test_attr_value(attr, L"new value2");
9557 test_attr_value(attr3, L"new replace value");
9559 /* Attached attributes cause errors. */
9560 hres = IHTMLElement4_setAttributeNode(elem4, attr3, &attr2);
9561 ok(hres == E_INVALIDARG, "setAttributeNode failed: %08x, expected E_INVALIDARG\n", hres);
9562 IHTMLDOMAttribute_Release(attr3);
9564 attr2 = get_elem_attr_node((IUnknown*)elem, L"id", TRUE);
9565 hres = IHTMLElement4_setAttributeNode(elem4, attr2, &attr3);
9566 ok(hres == E_INVALIDARG, "setAttributeNode failed: %08x, expected E_INVALIDARG\n", hres);
9567 IHTMLDOMAttribute_Release(attr2);
9569 IHTMLElement4_Release(elem4);
9570 IHTMLDOMAttribute_Release(attr);
9573 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
9575 IHTMLElement *elem;
9577 test_elem_set_innerhtml((IUnknown*)outer_elem,
9578 L"<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
9579 elem = get_elem_by_id(doc, L"imgid", TRUE);
9580 if(elem) {
9581 test_img_src((IUnknown*)elem, L"BLOCKED::", L"blocked::http://www.winehq.org/img.png");
9582 IHTMLElement_Release(elem);
9585 test_elem_set_innerhtml((IUnknown*)outer_elem,
9586 L"<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
9587 elem = get_elem_by_id(doc, L"imgid", TRUE);
9588 if(elem) {
9589 test_img_src((IUnknown*)elem, L"blocke::http://www.winehq.org/img.png", NULL);
9590 test_img_set_src((IUnknown*)elem, L"BLOCKED:http://www.winehq.org/img.png");
9591 test_img_src((IUnknown*)elem, L"blocked:http://www.winehq.org/img.png", NULL);
9592 test_img_set_src((IUnknown*)elem, L"blocked::http://www.winehq.org/img.png");
9593 test_img_src((IUnknown*)elem, L"BLOCKED::", L"blocked::http://www.winehq.org/img.png");
9594 IHTMLElement_Release(elem);
9598 #define doc_get_elems_by_name(a,b) _doc_get_elems_by_name(__LINE__,a,b)
9599 static IHTMLElementCollection *_doc_get_elems_by_name(unsigned line, IHTMLDocument2 *doc, const WCHAR *name)
9601 IHTMLDocument3 *doc3 = _get_doc3_iface(line, doc);
9602 IHTMLElementCollection *col;
9603 BSTR str = SysAllocString(name);
9604 HRESULT hres;
9606 hres = IHTMLDocument3_getElementsByName(doc3, str, &col);
9607 ok_(__FILE__,line)(hres == S_OK, "getElementsByName failed: %08x\n", hres);
9608 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
9610 IHTMLDocument3_Release(doc3);
9611 SysFreeString(str);
9612 return col;
9615 static void test_elem_names(IHTMLDocument2 *doc)
9617 IHTMLElementCollection *col;
9618 LONG len;
9619 HRESULT hres;
9621 static const elem_type_t test1_types[] = {ET_INPUT, ET_A, ET_DIV};
9623 set_body_html(doc, L"<input name=\"test\"><a name=\"test\"></a><a name=\"xxx\"></a><div id=\"test\"></div>");
9624 col = doc_get_elems_by_name(doc, L"test");
9625 test_elem_collection((IUnknown*)col, test1_types, ARRAY_SIZE(test1_types));
9626 IHTMLElementCollection_Release(col);
9628 col = doc_get_elems_by_name(doc, L"yyy");
9629 test_elem_collection((IUnknown*)col, NULL, 0);
9630 IHTMLElementCollection_Release(col);
9632 /* case insensivity test */
9633 col = doc_get_elems_by_name(doc, L"Xxx");
9634 hres = IHTMLElementCollection_get_length(col, &len);
9635 ok(hres == S_OK, "get_length failed: %08x\n", hres);
9636 todo_wine ok(len == 1, "len = %d\n", len);
9637 IHTMLElementCollection_Release(col);
9640 static void test_elems2(IHTMLDocument2 *doc)
9642 IHTMLElement *elem, *elem2, *div;
9644 static const elem_type_t outer_types[] = {
9645 ET_BR,
9646 ET_A
9649 div = get_doc_elem_by_id(doc, L"divid");
9651 elem = get_elem_by_id(doc, L"linkid", TRUE);
9652 if(elem) {
9653 test_link_disabled(elem, VARIANT_FALSE);
9654 test_link_rel(elem, L"stylesheet");
9655 test_link_rev(elem, NULL);
9656 test_link_type(elem, L"text/css");
9657 test_link_href(elem, L"about:blank");
9658 test_link_media(elem, L"all");
9659 link_put_disabled(elem, VARIANT_TRUE);
9660 link_put_rel(elem, L"prev");
9661 link_put_rev(elem, L"next");
9662 link_put_type(elem, L"text/plain");
9663 link_put_href(elem, L"about:prev");
9664 IHTMLElement_Release(elem);
9667 test_elem_set_innerhtml((IUnknown*)div, L"<div id=\"innerid\"></div>");
9668 elem2 = get_doc_elem_by_id(doc, L"innerid");
9669 ok(elem2 != NULL, "elem2 == NULL\n");
9670 test_elem_set_outerhtml((IUnknown*)elem2, L"<br><a href=\"about:blank\" id=\"aid\">a</a>");
9671 test_elem_all((IUnknown*)div, outer_types, ARRAY_SIZE(outer_types));
9672 IHTMLElement_Release(elem2);
9674 elem2 = get_doc_elem_by_id(doc, L"aid");
9675 ok(elem2 != NULL, "elem2 == NULL\n");
9676 test_elem_set_outerhtml((IUnknown*)elem2, L"");
9677 test_elem_all((IUnknown*)div, outer_types, 1);
9678 IHTMLElement_Release(elem2);
9680 test_elem_set_innerhtml((IUnknown*)div,
9681 L"<input value=\"val\" id =\"inputid\" />");
9682 elem = get_elem_by_id(doc, L"inputid", TRUE);
9683 if(elem) {
9684 test_input_defaultValue((IUnknown*)elem, L"val");
9685 test_input_put_value((IUnknown*)elem, L"test");
9686 test_input_put_defaultValue((IUnknown*)elem, L"new val");
9687 test_input_value((IUnknown*)elem, L"test");
9688 IHTMLElement_Release(elem);
9691 test_elem_set_innerhtml((IUnknown*)div, L"");
9692 test_insert_adjacent_elems(doc, div);
9694 test_elem_set_innerhtml((IUnknown*)div,
9695 L"<form id=\"form\" name=\"form_name\"><select id=\"sform\"><option id=\"oform\"></option></select><button id=\"btnid\"></button></form>");
9696 elem = get_elem_by_id(doc, L"sform", TRUE);
9697 elem2 = get_elem_by_id(doc, L"form", TRUE);
9698 if(elem && elem2) {
9699 IHTMLFormElement *form;
9701 test_select_form((IUnknown*)elem, (IUnknown*)elem2);
9702 IHTMLElement_Release(elem);
9704 elem = get_elem_by_id(doc, L"oform", TRUE);
9705 if(elem) {
9706 test_option_form((IUnknown*)elem, (IUnknown*)elem2);
9707 IHTMLElement_Release(elem);
9710 elem = get_elem_by_id(doc, L"btnid", TRUE);
9712 form = get_button_form(elem);
9713 ok(iface_cmp((IUnknown*)form, (IUnknown*)elem2), "form != elem2\n");
9714 IHTMLFormElement_Release(form);
9716 IHTMLElement_Release(elem);
9717 IHTMLElement_Release(elem2);
9720 test_selectors(doc, div);
9721 test_elemsbyclass(div);
9723 test_elem_set_innerhtml((IUnknown*)div, L"<div id=\"elemid\">test</div>");
9724 elem = get_elem_by_id(doc, L"elemid", TRUE);
9725 if(elem) {
9726 test_elem_outertext(elem, L"test");
9727 test_elem_set_outertext(elem, L"outer text");
9728 test_elem_outertext(elem, NULL);
9729 test_elem_all((IUnknown*)div, NULL, 0);
9730 elem2 = test_elem_get_parent((IUnknown*)elem);
9731 ok(!elem2, "parent != NULL\n");
9732 IHTMLElement_Release(elem);
9735 test_elem_set_innerhtml((IUnknown*)div, L"<map><area id=\"areaid\"></area></map>");
9736 elem = get_elem_by_id(doc, L"areaid", TRUE);
9737 if(elem) {
9738 test_elem_type((IUnknown*)elem, ET_AREA);
9739 IHTMLElement_Release(elem);
9742 test_td_elem(doc, div);
9743 test_attr(doc, div);
9744 test_blocked(doc, div);
9745 test_elem_names(doc);
9747 IHTMLElement_Release(div);
9750 static void test_textarea_element(IHTMLDocument2 *doc, IHTMLElement *parent)
9752 IHTMLElement *form_elem, *elem;
9753 IHTMLFormElement *form;
9755 test_elem_set_innerhtml((IUnknown*)parent,
9756 L"<form id=\"fid\"><textarea id=\"ta\"></textarea></form>");
9757 elem = get_elem_by_id(doc, L"ta", TRUE);
9758 test_elem_type((IUnknown*)elem, ET_TEXTAREA);
9760 form_elem = get_elem_by_id(doc, L"fid", TRUE);
9761 ok(form_elem != NULL, "form_elem == NULL\n");
9763 form = get_textarea_form((IUnknown*)elem);
9764 ok(form != NULL, "form = NULL\n");
9765 ok(iface_cmp((IUnknown*)form, (IUnknown*)form_elem), "form != form_elem\n");
9767 IHTMLFormElement_Release(form);
9768 IHTMLElement_Release(form_elem);
9769 IHTMLElement_Release(elem);
9771 test_elem_set_innerhtml((IUnknown*)parent, L"<textarea id=\"ta\"></textarea>");
9772 elem = get_elem_by_id(doc, L"ta", TRUE);
9774 test_textarea_value((IUnknown*)elem, NULL);
9775 test_textarea_put_value((IUnknown*)elem, L"test");
9776 test_textarea_defaultvalue((IUnknown*)elem, NULL);
9777 test_textarea_put_defaultvalue((IUnknown*)elem, L"defval text");
9778 test_textarea_put_value((IUnknown*)elem, L"test");
9779 test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
9780 test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
9781 test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
9782 test_textarea_type((IUnknown*)elem);
9784 form = get_textarea_form((IUnknown*)elem);
9785 ok(!form, "form = %p\n", form);
9787 test_elem_istextedit(elem, VARIANT_TRUE);
9789 IHTMLElement_Release(elem);
9791 test_elem_set_innerhtml((IUnknown*)parent, L"<textarea id=\"ta\">default text</textarea>");
9792 elem = get_elem_by_id(doc, L"ta", TRUE);
9793 test_textarea_defaultvalue((IUnknown*)elem, L"default text");
9794 IHTMLElement_Release(elem);
9797 static void test_form_element(IHTMLDocument2 *doc, IHTMLElement *parent)
9799 IHTMLElement *elem, *input_elem;
9801 static const elem_type_t elems_textarea_input[] = { ET_TEXTAREA, ET_INPUT };
9803 test_elem_set_innerhtml((IUnknown*)parent,
9804 L"<form id=\"form\">"
9805 "<textarea></textarea>"
9806 "<div><input type=\"text\" id=\"inputid\" /></div>"
9807 "</form>");
9808 elem = get_elem_by_id(doc, L"form", TRUE);
9809 test_elem_type((IUnknown*)elem, ET_FORM);
9811 test_form_length((IUnknown*)elem, 2);
9812 test_form_item(elem);
9813 test_form_action((IUnknown*)elem, NULL);
9814 test_form_put_action((IUnknown*)elem, L"about:blank");
9815 test_form_method((IUnknown*)elem, L"get");
9816 test_form_put_method((IUnknown*)elem, S_OK, L"post");
9817 test_form_put_method((IUnknown*)elem, E_INVALIDARG, L"put");
9818 test_form_method((IUnknown*)elem, L"post");
9819 test_form_name((IUnknown*)elem, NULL);
9820 test_form_put_name((IUnknown*)elem, L"Name");
9821 test_form_encoding((IUnknown*)elem, L"application/x-www-form-urlencoded");
9822 test_form_put_encoding((IUnknown*)elem, S_OK, L"text/plain");
9823 test_form_put_encoding((IUnknown*)elem, S_OK, L"multipart/form-data");
9824 test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, L"image/png");
9825 test_form_encoding((IUnknown*)elem, L"multipart/form-data");
9826 test_form_elements((IUnknown*)elem, elems_textarea_input, ARRAY_SIZE(elems_textarea_input));
9827 test_form_reset((IUnknown*)elem);
9828 test_form_target((IUnknown*)elem);
9830 input_elem = get_elem_by_id(doc, L"inputid", TRUE);
9831 test_input_get_form((IUnknown*)input_elem, L"form");
9832 IHTMLElement_Release(input_elem);
9834 IHTMLElement_Release(elem);
9837 static void test_svg_element(IHTMLDocument2 *doc, IHTMLElement *parent)
9839 IHTMLDOMNode *svg_node, *circle_node, *tspan_node;
9841 test_elem_set_innerhtml((IUnknown*)parent,
9842 L"<svg width=\"100\" height=\"100\" id=\"svgid\">"
9843 "<circle cx=\"50\" cy=\"50\" r=\"40\" fill=\"black\" />"
9844 "<tspan></tspan>"
9845 "</svg>");
9846 svg_node = get_first_child((IUnknown*)parent);
9847 if(compat_mode < COMPAT_IE9) {
9848 todo_wine
9849 ok(!svg_node, "svg_node != NULL\n");
9850 if(svg_node)
9851 IHTMLDOMNode_Release(svg_node);
9852 return;
9854 ok(svg_node != NULL, "svg_node = NULL\n");
9855 test_elem_type((IUnknown*)svg_node, ET_SVG);
9857 circle_node = get_first_child((IUnknown*)svg_node);
9858 ok(circle_node != NULL, "circle_node = NULL\n");
9859 if(!circle_node)
9860 return;
9861 test_elem_type((IUnknown*)circle_node, ET_CIRCLE);
9863 tspan_node = node_get_next((IUnknown*)circle_node);
9864 test_elem_type((IUnknown*)tspan_node, ET_TSPAN);
9866 IHTMLDOMNode_Release(tspan_node);
9867 IHTMLDOMNode_Release(circle_node);
9868 IHTMLDOMNode_Release(svg_node);
9871 static void test_dom_elements(IHTMLDocument2 *doc)
9873 IHTMLElement *div;
9875 set_body_html(doc, L"<div id=\"parentdiv\"></div>");
9876 div = get_doc_elem_by_id(doc, L"parentdiv");
9878 test_textarea_element(doc, div);
9879 test_form_element(doc, div);
9880 test_svg_element(doc, div);
9882 IHTMLElement_Release(div);
9885 static void test_create_elems(IHTMLDocument2 *doc)
9887 IHTMLElement *elem, *body, *elem2;
9888 IHTMLDOMNode *node, *node2, *node3, *comment;
9889 IHTMLDocument5 *doc5;
9890 IDispatch *disp;
9891 VARIANT var;
9892 LONG type;
9893 HRESULT hres;
9894 BSTR str;
9896 static const elem_type_t types1[] = { ET_TESTG };
9898 elem = test_create_elem(doc, L"TEST");
9899 test_elem_tag((IUnknown*)elem, L"TEST");
9900 type = get_node_type((IUnknown*)elem);
9901 ok(type == 1, "type=%d\n", type);
9902 test_ifaces((IUnknown*)elem, elem_iids);
9903 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, &CLSID_HTMLGenericElement, L"[object]");
9904 test_elem_source_index(elem, -1);
9906 body = doc_get_body(doc);
9907 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
9909 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
9910 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
9911 elem2 = get_elem_iface((IUnknown*)node);
9912 IHTMLElement_Release(elem2);
9914 hres = IHTMLElement_get_all(body, &disp);
9915 ok(hres == S_OK, "get_all failed: %08x\n", hres);
9916 test_elem_collection((IUnknown*)disp, types1, ARRAY_SIZE(types1));
9917 IDispatch_Release(disp);
9919 test_node_remove_child((IUnknown*)body, node);
9921 hres = IHTMLElement_get_all(body, &disp);
9922 ok(hres == S_OK, "get_all failed: %08x\n", hres);
9923 test_elem_collection((IUnknown*)disp, NULL, 0);
9924 IDispatch_Release(disp);
9925 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
9927 IHTMLElement_Release(elem);
9928 IHTMLDOMNode_Release(node);
9930 node = test_create_text(doc, L"abc");
9931 test_ifaces((IUnknown*)node, text_iids);
9932 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, NULL, L"[object]");
9933 test_text_length((IUnknown*)node, 3);
9934 test_text_data((IUnknown*)node, L"abc");
9935 set_text_data((IUnknown*)node, L"test");
9936 test_text_data((IUnknown*)node, L"test");
9937 text_append_data((IUnknown*)node, L" append");
9938 test_text_data((IUnknown*)node, L"test append");
9939 text_append_data((IUnknown*)node, NULL);
9940 test_text_data((IUnknown*)node, L"test append");
9941 set_text_data((IUnknown*)node, L"test");
9943 V_VT(&var) = VT_NULL;
9944 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
9945 IHTMLDOMNode_Release(node);
9947 node = test_create_text(doc, L"insert ");
9949 V_VT(&var) = VT_DISPATCH;
9950 V_DISPATCH(&var) = (IDispatch*)node2;
9951 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
9952 IHTMLDOMNode_Release(node);
9953 IHTMLDOMNode_Release(node2);
9954 IHTMLDOMNode_Release(node3);
9956 test_elem_innertext(body, L"insert test");
9957 test_elem_innerhtml((IUnknown*)body, L"insert test");
9959 node = test_create_text(doc, L" Test");
9960 V_VT(&var) = VT_DISPATCH;
9961 V_DISPATCH(&var) = NULL;
9962 test_node_insertbefore((IUnknown*)body, node, &var);
9963 test_elem_innertext(body, L"insert test Test");
9964 IHTMLDOMNode_Release(node);
9966 doc5 = get_htmldoc5_iface((IUnknown*)doc);
9967 if(doc5) {
9968 str = SysAllocString(L"testing");
9969 hres = IHTMLDocument5_createComment(doc5, str, &comment);
9970 SysFreeString(str);
9971 ok(hres == S_OK, "createComment failed: %08x\n", hres);
9972 if(hres == S_OK)
9974 type = get_node_type((IUnknown*)comment);
9975 ok(type == 8, "type=%d, expected 8\n", type);
9977 test_node_get_value_str((IUnknown*)comment, L"testing");
9978 test_elem_title((IUnknown*)comment, NULL);
9979 test_elem_set_title((IUnknown*)comment, L"comment title");
9980 test_elem_title((IUnknown*)comment, L"comment title");
9981 test_comment_text((IUnknown*)comment, L"<!--testing-->");
9982 test_elem_outerhtml((IUnknown*)comment, L"<!--testing-->");
9983 test_comment_attrs((IUnknown*)comment);
9985 node2 = clone_node((IUnknown*)comment, VARIANT_TRUE);
9986 test_comment_text((IUnknown*)node2, L"<!--testing-->");
9987 IHTMLDOMNode_Release(node2);
9989 test_elem_getelembytag((IUnknown*)comment, ET_COMMENT, 0, NULL);
9991 IHTMLDOMNode_Release(comment);
9994 IHTMLDocument5_Release(doc5);
9997 IHTMLElement_Release(body);
10000 static void test_replacechild_elems(IHTMLDocument2 *doc)
10002 IHTMLElement *body;
10003 IHTMLDOMNode *node, *node2, *node3;
10004 IHTMLDOMNode *nodeBody, *nodeNew;
10005 HRESULT hres;
10006 VARIANT var;
10008 body = doc_get_body(doc);
10010 node = test_create_text(doc, L"insert");
10012 V_VT(&var) = VT_NULL;
10013 V_DISPATCH(&var) = NULL;
10014 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
10015 IHTMLDOMNode_Release(node);
10017 test_elem_innertext(body, L"insert");
10019 node3 = test_create_text(doc, L"replaced");
10021 nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
10023 hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
10024 ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
10026 test_elem_innertext(body, L"replaced");
10028 IHTMLDOMNode_Release(node2);
10029 IHTMLDOMNode_Release(node3);
10030 IHTMLDOMNode_Release(nodeBody);
10032 IHTMLElement_Release(body);
10035 static void test_noscript(IHTMLDocument2 *doc)
10037 IHTMLElementCollection *col;
10038 IHTMLElement *body;
10039 HRESULT hres;
10041 static const elem_type_t all_types[] = {
10042 ET_HTML,
10043 ET_HEAD,
10044 ET_TITLE,
10045 ET_NOSCRIPT,
10046 ET_BODY,
10047 ET_NOSCRIPT
10050 static const elem_type_t body_all_types[] = {
10051 ET_DIV,
10052 ET_NOSCRIPT
10055 hres = IHTMLDocument2_get_all(doc, &col);
10056 ok(hres == S_OK, "get_all failed: %08x\n", hres);
10057 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
10058 IHTMLElementCollection_Release(col);
10060 body = doc_get_body(doc);
10061 test_elem_set_innerhtml((IUnknown*)body, L"<div>test</div><noscript><a href=\"about:blank\">A</a></noscript>");
10062 test_elem_all((IUnknown*)body, body_all_types, ARRAY_SIZE(body_all_types));
10063 IHTMLElement_Release(body);
10066 static void test_doctype(IHTMLDocument2 *doc)
10068 IHTMLDocument2 *doc_node;
10069 IHTMLDOMNode *doctype;
10070 int type;
10072 doc_node = get_doc_node(doc);
10073 doctype = get_first_child((IUnknown*)doc_node);
10074 IHTMLDocument2_Release(doc_node);
10076 type = get_node_type((IUnknown*)doctype);
10077 ok(type == 8, "type = %d\n", type);
10079 test_comment_text((IUnknown*)doctype, L"<!DOCTYPE html>");
10080 test_elem_type((IUnknown*)doctype, ET_COMMENT);
10081 IHTMLDOMNode_Release(doctype);
10084 static void test_null_write(IHTMLDocument2 *doc)
10086 HRESULT hres;
10088 doc_write(doc, FALSE, NULL);
10089 doc_write(doc, TRUE, NULL);
10091 hres = IHTMLDocument2_write(doc, NULL);
10092 ok(hres == S_OK,
10093 "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
10095 hres = IHTMLDocument2_writeln(doc, NULL);
10096 ok(hres == S_OK,
10097 "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
10100 static void test_create_stylesheet(IHTMLDocument2 *doc)
10102 IHTMLStyleSheet *stylesheet, *stylesheet2;
10103 IHTMLStyleElement *style_elem;
10104 IHTMLElement *doc_elem, *elem;
10105 HRESULT hres;
10107 static const elem_type_t all_types[] = {
10108 ET_HTML,
10109 ET_HEAD,
10110 ET_TITLE,
10111 ET_BODY,
10112 ET_DIV
10115 static const elem_type_t all_types2[] = {
10116 ET_HTML,
10117 ET_HEAD,
10118 ET_TITLE,
10119 ET_STYLE,
10120 ET_BODY,
10121 ET_DIV
10124 test_doc_all(doc, all_types, ARRAY_SIZE(all_types));
10126 hres = IHTMLDocument2_createStyleSheet(doc, NULL, -1, &stylesheet);
10127 ok(hres == S_OK, "createStyleSheet failed: %08x\n", hres);
10129 test_doc_all(doc, all_types2, ARRAY_SIZE(all_types2));
10131 doc_elem = get_doc_elem(doc);
10133 test_elem_getelembytag((IUnknown*)doc_elem, ET_STYLE, 1, &elem);
10134 IHTMLElement_Release(doc_elem);
10136 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLStyleElement, (void**)&style_elem);
10137 IHTMLElement_Release(elem);
10138 ok(hres == S_OK, "Could not get IHTMLStyleElement iface: %08x\n", hres);
10140 stylesheet2 = NULL;
10141 hres = IHTMLStyleElement_get_styleSheet(style_elem, &stylesheet2);
10142 ok(hres == S_OK, "get_styleSheet failed: %08x\n", hres);
10143 ok(stylesheet2 != NULL, "stylesheet2 == NULL\n");
10144 ok(iface_cmp((IUnknown*)stylesheet, (IUnknown*)stylesheet2), "stylesheet != stylesheet2\n");
10146 IHTMLStyleSheet_Release(stylesheet2);
10147 IHTMLStyleSheet_Release(stylesheet);
10149 IHTMLStyleElement_Release(style_elem);
10152 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
10154 IOleCommandTarget *cmdtrg;
10155 HRESULT hres;
10157 hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
10158 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
10160 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
10161 ok(hres == S_OK, "Exec failed: %08x\n", hres);
10163 IOleCommandTarget_Release(cmdtrg);
10166 static void test_indent(IHTMLDocument2 *doc)
10168 IHTMLElementCollection *col;
10169 IHTMLTxtRange *range;
10170 HRESULT hres;
10172 static const elem_type_t all_types[] = {
10173 ET_HTML,
10174 ET_HEAD,
10175 ET_TITLE,
10176 ET_BODY,
10177 ET_BR,
10178 ET_A,
10181 static const elem_type_t indent_types[] = {
10182 ET_HTML,
10183 ET_HEAD,
10184 ET_TITLE,
10185 ET_BODY,
10186 ET_BLOCKQUOTE,
10187 ET_P,
10188 ET_BR,
10189 ET_A,
10192 hres = IHTMLDocument2_get_all(doc, &col);
10193 ok(hres == S_OK, "get_all failed: %08x\n", hres);
10194 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
10195 IHTMLElementCollection_Release(col);
10197 range = test_create_body_range(doc);
10198 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
10199 IHTMLTxtRange_Release(range);
10201 hres = IHTMLDocument2_get_all(doc, &col);
10202 ok(hres == S_OK, "get_all failed: %08x\n", hres);
10203 test_elem_collection((IUnknown*)col, indent_types, ARRAY_SIZE(indent_types));
10204 IHTMLElementCollection_Release(col);
10207 static void test_cond_comment(IHTMLDocument2 *doc)
10209 IHTMLElementCollection *col;
10210 HRESULT hres;
10212 static const elem_type_t all_types[] = {
10213 ET_HTML,
10214 ET_HEAD,
10215 ET_TITLE,
10216 ET_BODY,
10217 ET_BR
10220 hres = IHTMLDocument2_get_all(doc, &col);
10221 ok(hres == S_OK, "get_all failed: %08x\n", hres);
10222 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
10223 IHTMLElementCollection_Release(col);
10226 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
10228 ok(IsEqualGUID(riid, &IID_IServiceProvider), "riid = %s\n", wine_dbgstr_guid(riid));
10229 return E_NOINTERFACE;
10232 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
10234 return 2;
10237 static ULONG WINAPI Unknown_Release(IUnknown *iface)
10239 return 1;
10242 static const IUnknownVtbl UnknownVtbl = {
10243 Unknown_QueryInterface,
10244 Unknown_AddRef,
10245 Unknown_Release,
10247 static IUnknown obj_ident_test = { &UnknownVtbl };
10249 static void test_frame(IDispatch *disp, const WCHAR *exp_id)
10251 IHTMLWindow2 *frame2, *parent, *top;
10252 IHTMLDocument2 *parent_doc, *top_doc;
10253 IHTMLWindow4 *frame;
10254 IHTMLFrameBase *frame_elem;
10255 IObjectIdentity *obj_ident;
10256 ITravelLogClient *tlc;
10257 HRESULT hres;
10259 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
10260 ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
10261 if(FAILED(hres))
10262 return;
10264 hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
10265 ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
10266 IHTMLWindow4_Release(frame);
10267 if(FAILED(hres))
10268 return;
10270 test_elem_type((IUnknown*)frame_elem, ET_FRAME);
10271 test_frame_doc((IUnknown*)frame_elem, FALSE);
10272 test_elem_id((IUnknown*)frame_elem, exp_id);
10273 IHTMLFrameBase_Release(frame_elem);
10275 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
10276 ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
10277 if(FAILED(hres))
10278 return;
10280 hres = IHTMLWindow2_get_parent(frame2, &parent);
10281 ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
10282 if(FAILED(hres)){
10283 IHTMLWindow2_Release(frame2);
10284 return;
10287 hres = IHTMLWindow2_QueryInterface(frame2, &IID_IObjectIdentity, (void**)&obj_ident);
10288 ok(hres == S_OK, "Could not get IObjectIdentity interface: %08x\n", hres);
10289 hres = IHTMLWindow2_QueryInterface(frame2, &IID_ITravelLogClient, (void**)&tlc);
10290 if(hres == E_NOINTERFACE) {
10291 win_skip("IID_ITravelLogClient not available\n");
10292 tlc = NULL;
10293 }else {
10294 ok(hres == S_OK, "Could not get ITravelLogClient interface: %08x\n", hres);
10296 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)tlc);
10297 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
10298 ITravelLogClient_Release(tlc);
10301 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)obj_ident);
10302 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
10303 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)parent);
10304 ok(hres == S_FALSE, "IsEqualObject returned: 0x%08x\n", hres);
10305 hres = IObjectIdentity_IsEqualObject(obj_ident, &obj_ident_test);
10306 ok(hres == E_NOINTERFACE, "IsEqualObject returned: 0x%08x\n", hres);
10308 IObjectIdentity_Release(obj_ident);
10310 hres = IHTMLWindow2_get_document(parent, &parent_doc);
10311 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
10312 IHTMLWindow2_Release(parent);
10313 if(FAILED(hres)){
10314 IHTMLWindow2_Release(frame2);
10315 return;
10318 test_doc_title(parent_doc, L"frameset test");
10319 IHTMLDocument2_Release(parent_doc);
10321 /* test get_top */
10322 hres = IHTMLWindow2_get_top(frame2, &top);
10323 ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
10324 IHTMLWindow2_Release(frame2);
10325 if(FAILED(hres))
10326 return;
10328 hres = IHTMLWindow2_get_document(top, &top_doc);
10329 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
10330 IHTMLWindow2_Release(top);
10331 if(FAILED(hres))
10332 return;
10334 test_doc_title(top_doc, L"frameset test");
10335 IHTMLDocument2_Release(top_doc);
10338 static void test_frames_collection(IHTMLFramesCollection2 *frames, const WCHAR *frid)
10340 VARIANT index_var, result_var;
10341 LONG length;
10342 HRESULT hres;
10344 /* test result length */
10345 hres = IHTMLFramesCollection2_get_length(frames, &length);
10346 ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
10347 ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
10349 /* test first frame */
10350 V_VT(&index_var) = VT_I4;
10351 V_I4(&index_var) = 0;
10352 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
10353 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
10354 if(SUCCEEDED(hres)) {
10355 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
10356 test_frame((IDispatch*)V_DISPATCH(&result_var), L"fr1");
10358 VariantClear(&result_var);
10360 /* test second frame */
10361 V_I4(&index_var) = 1;
10362 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
10363 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
10364 if(SUCCEEDED(hres)) {
10365 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
10366 test_frame((IDispatch*)V_DISPATCH(&result_var), L"fr2");
10368 VariantClear(&result_var);
10370 /* fail on next frame */
10371 V_I4(&index_var) = 3;
10372 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
10373 ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
10374 "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
10375 VariantClear(&result_var);
10377 /* string argument (element id lookup) */
10378 V_VT(&index_var) = VT_BSTR;
10379 V_BSTR(&index_var) = SysAllocString(frid);
10380 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
10381 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
10382 if(SUCCEEDED(hres)) {
10383 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
10384 test_frame(V_DISPATCH(&result_var), frid);
10386 VariantClear(&result_var);
10387 VariantClear(&index_var);
10389 /* invalid argument */
10390 V_VT(&index_var) = VT_BOOL;
10391 V_BOOL(&index_var) = VARIANT_TRUE;
10392 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
10393 ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
10394 "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
10395 VariantClear(&result_var);
10398 static void test_frameset(IHTMLDocument2 *doc)
10400 IHTMLWindow2 *window;
10401 IHTMLFramesCollection2 *frames;
10402 IHTMLDocument6 *doc6;
10403 IHTMLElement *elem;
10404 HRESULT hres;
10406 window = get_doc_window(doc);
10408 /* test using IHTMLFramesCollection object */
10410 hres = IHTMLWindow2_get_frames(window, &frames);
10411 ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
10412 if(FAILED(hres))
10413 return;
10415 test_frames_collection(frames, L"fr1");
10416 IHTMLFramesCollection2_Release(frames);
10418 hres = IHTMLDocument2_get_frames(doc, &frames);
10419 ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
10420 if(FAILED(hres))
10421 return;
10423 test_frames_collection(frames, L"fr1");
10424 IHTMLFramesCollection2_Release(frames);
10426 /* test using IHTMLWindow2 inheritance */
10427 test_frames_collection((IHTMLFramesCollection2*)window, L"fr2");
10429 /* getElementById with node name attributes */
10430 elem = get_doc_elem_by_id(doc, L"nm1");
10431 test_elem_id((IUnknown*)elem, L"fr1");
10433 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
10434 if(SUCCEEDED(hres)) {
10435 IHTMLElement2 *elem2;
10436 BSTR str;
10438 str = SysAllocString(L"nm1");
10439 hres = IHTMLDocument6_getElementById(doc6, str, &elem2);
10440 ok(hres == S_OK, "getElementById failed: %08x\n", hres);
10441 ok(!elem2, "elem = %p\n", elem2);
10442 SysFreeString(str);
10444 str = SysAllocString(L"fr1");
10445 hres = IHTMLDocument6_getElementById(doc6, str, &elem2);
10446 ok(hres == S_OK, "getElementById failed: %08x\n", hres);
10447 ok(elem2 != NULL, "elem2 is NULL\n");
10448 test_elem_id((IUnknown*)elem2, L"fr1");
10449 SysFreeString(str);
10451 IHTMLDocument6_Release(doc6);
10452 }else {
10453 win_skip("IHTMLDocument6 not supported\n");
10456 test_framebase((IUnknown*)elem);
10457 test_framebase_name(elem, L"nm1");
10458 test_framebase_put_name(elem, L"frame name");
10459 test_framebase_put_name(elem, NULL);
10460 test_framebase_put_name(elem, L"nm1");
10461 test_framebase_src(elem, L"about:blank");
10462 IHTMLElement_Release(elem);
10464 /* get_name with no name attr */
10465 elem = get_doc_elem_by_id(doc, L"fr3");
10466 test_framebase_name(elem, NULL);
10467 test_framebase_put_name(elem, L"frame name");
10468 test_framebase_put_name(elem, NULL);
10469 IHTMLElement_Release(elem);
10471 IHTMLWindow2_Release(window);
10474 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
10476 IHTMLDocument2 *frag;
10477 IHTMLDocument3 *doc3;
10478 HRESULT hres;
10480 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
10481 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
10483 hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
10484 IHTMLDocument3_Release(doc3);
10485 ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
10486 ok(frag != NULL, "frag == NULL\n");
10488 return frag;
10491 static void test_docfrag(IHTMLDocument2 *doc)
10493 IHTMLDocument2 *frag, *owner_doc, *doc_node;
10494 IHTMLElement *div, *body, *br;
10495 IHTMLElementCollection *col;
10496 IHTMLLocation *location;
10497 HRESULT hres;
10499 static const elem_type_t all_types[] = {
10500 ET_HTML,
10501 ET_HEAD,
10502 ET_TITLE,
10503 ET_BODY,
10504 ET_DIV,
10505 ET_BR
10508 frag = create_docfrag(doc);
10510 test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]");
10512 body = (void*)0xdeadbeef;
10513 hres = IHTMLDocument2_get_body(frag, &body);
10514 ok(hres == S_OK, "get_body failed: %08x\n", hres);
10515 ok(!body, "body != NULL\n");
10517 location = (void*)0xdeadbeef;
10518 hres = IHTMLDocument2_get_location(frag, &location);
10519 ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
10520 ok(location == (void*)0xdeadbeef, "location changed\n");
10522 br = test_create_elem(doc, L"BR");
10523 test_elem_source_index(br, -1);
10524 test_node_append_child((IUnknown*)frag, (IUnknown*)br);
10525 test_elem_source_index(br, 0);
10526 IHTMLElement_Release(br);
10528 test_doc_getelembytag(frag, "a", ET_A, 0);
10529 test_doc_getelembytag(frag, "Br", ET_BR, 1);
10531 div = get_elem_by_id(doc, L"divid", TRUE);
10532 test_node_append_child((IUnknown*)div, (IUnknown*)frag);
10533 IHTMLElement_Release(div);
10535 hres = IHTMLDocument2_get_all(doc, &col);
10536 ok(hres == S_OK, "get_all failed: %08x\n", hres);
10537 test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types));
10538 IHTMLElementCollection_Release(col);
10540 div = test_create_elem(frag, L"div");
10541 owner_doc = get_owner_doc((IUnknown*)div);
10542 doc_node = get_doc_node(doc);
10543 ok(iface_cmp((IUnknown*)owner_doc, (IUnknown*)doc_node), "owner_doc != doc_node\n");
10544 IHTMLDocument2_Release(doc_node);
10545 IHTMLDocument2_Release(owner_doc);
10546 IHTMLElement_Release(div);
10548 IHTMLDocument2_Release(frag);
10551 static void check_quirks_mode(IHTMLDocument2 *doc)
10553 test_compatmode(doc, L"BackCompat");
10556 static void check_strict_mode(IHTMLDocument2 *doc)
10558 test_compatmode(doc, L"CSS1Compat");
10561 static void test_quirks_mode_offsetHeight(IHTMLDocument2 *doc)
10563 IHTMLElement *elem;
10564 HRESULT hres;
10565 LONG oh;
10567 hres = IHTMLDocument2_get_body(doc, &elem);
10568 ok(hres == S_OK, "get_body fauled: %08x\n", hres);
10570 /* body.offsetHeight value depends on window size in quirks mode */
10571 hres = IHTMLElement_get_offsetHeight(elem, &oh);
10572 ok(hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
10573 todo_wine ok(oh == 500, "offsetHeight = %d\n", oh);
10574 IHTMLElement_Release(elem);
10577 static IHTMLDocument2 *notif_doc;
10578 static BOOL doc_complete;
10580 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
10581 REFIID riid, void**ppv)
10583 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
10584 *ppv = iface;
10585 return S_OK;
10588 ok(0, "unexpected call\n");
10589 return E_NOINTERFACE;
10592 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
10594 return 2;
10597 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
10599 return 1;
10602 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
10604 if(dispID == DISPID_READYSTATE){
10605 BSTR state;
10606 HRESULT hres;
10608 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
10609 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
10611 if(!lstrcmpW(state, L"complete"))
10612 doc_complete = TRUE;
10614 SysFreeString(state);
10617 return S_OK;
10620 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
10622 ok(0, "unexpected call\n");
10623 return E_NOTIMPL;
10626 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
10627 PropertyNotifySink_QueryInterface,
10628 PropertyNotifySink_AddRef,
10629 PropertyNotifySink_Release,
10630 PropertyNotifySink_OnChanged,
10631 PropertyNotifySink_OnRequestEdit
10634 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
10636 static HRESULT cs_qi(REFIID,void **);
10637 static IOleDocumentView *view;
10638 static HWND container_hwnd;
10640 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
10642 static const GUID undocumented_frame_iid = {0xfbece6c9,0x48d7,0x4a37,{0x8f,0xe3,0x6a,0xd4,0x27,0x2f,0xdd,0xac}};
10644 if(!IsEqualGUID(&undocumented_frame_iid, riid))
10645 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
10647 *ppv = NULL;
10648 return E_NOINTERFACE;
10651 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
10653 return 2;
10656 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
10658 return 1;
10661 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
10663 return E_NOTIMPL;
10666 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
10668 return E_NOTIMPL;
10671 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
10673 return E_NOTIMPL;
10676 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
10677 LPCBORDERWIDTHS pborderwidths)
10679 return E_NOTIMPL;
10682 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
10683 LPCBORDERWIDTHS pborderwidths)
10685 return S_OK;
10688 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
10689 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
10691 return S_OK;
10694 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
10695 LPOLEMENUGROUPWIDTHS lpMenuWidths)
10697 return E_NOTIMPL;
10700 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
10701 HOLEMENU holemenu, HWND hwndActiveObject)
10703 ok(0, "unexpected call\n");
10704 return E_NOTIMPL;
10707 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
10709 ok(0, "unexpected call\n");
10710 return E_NOTIMPL;
10713 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
10715 return S_OK;
10718 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
10720 return E_NOTIMPL;
10723 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
10725 ok(0, "unexpected call\n");
10726 return E_NOTIMPL;
10729 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
10730 InPlaceFrame_QueryInterface,
10731 InPlaceFrame_AddRef,
10732 InPlaceFrame_Release,
10733 InPlaceFrame_GetWindow,
10734 InPlaceFrame_ContextSensitiveHelp,
10735 InPlaceFrame_GetBorder,
10736 InPlaceFrame_RequestBorderSpace,
10737 InPlaceFrame_SetBorderSpace,
10738 InPlaceFrame_SetActiveObject,
10739 InPlaceFrame_InsertMenus,
10740 InPlaceFrame_SetMenu,
10741 InPlaceFrame_RemoveMenus,
10742 InPlaceFrame_SetStatusText,
10743 InPlaceFrame_EnableModeless,
10744 InPlaceFrame_TranslateAccelerator
10747 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
10749 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
10751 return cs_qi(riid, ppv);
10754 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
10756 return 2;
10759 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
10761 return 1;
10764 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
10766 *phwnd = container_hwnd;
10767 return S_OK;
10770 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
10772 ok(0, "unexpected call\n");
10773 return E_NOTIMPL;
10776 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
10778 return S_OK;
10781 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
10783 return S_OK;
10786 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
10788 return S_OK;
10791 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
10792 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
10793 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
10795 static const RECT rect = {0,0,500,500};
10797 *ppFrame = &InPlaceFrame;
10798 *ppDoc = NULL;
10799 *lprcPosRect = rect;
10800 *lprcClipRect = rect;
10802 lpFrameInfo->fMDIApp = FALSE;
10803 lpFrameInfo->hwndFrame = container_hwnd;
10804 lpFrameInfo->haccel = NULL;
10805 lpFrameInfo->cAccelEntries = 0;
10807 return S_OK;
10810 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
10812 return E_NOTIMPL;
10815 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
10817 return S_OK;
10820 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
10822 return S_OK;
10825 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
10827 return E_NOTIMPL;
10830 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
10832 return E_NOTIMPL;
10835 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
10837 return E_NOTIMPL;
10840 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
10841 InPlaceSite_QueryInterface,
10842 InPlaceSite_AddRef,
10843 InPlaceSite_Release,
10844 InPlaceSite_GetWindow,
10845 InPlaceSite_ContextSensitiveHelp,
10846 InPlaceSite_CanInPlaceActivate,
10847 InPlaceSite_OnInPlaceActivate,
10848 InPlaceSite_OnUIActivate,
10849 InPlaceSite_GetWindowContext,
10850 InPlaceSite_Scroll,
10851 InPlaceSite_OnUIDeactivate,
10852 InPlaceSite_OnInPlaceDeactivate,
10853 InPlaceSite_DiscardUndoState,
10854 InPlaceSite_DeactivateAndUndo,
10855 InPlaceSite_OnPosRectChange,
10858 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
10860 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
10862 return cs_qi(riid, ppv);
10865 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
10867 return 2;
10870 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
10872 return 1;
10875 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
10877 ok(0, "unexpected call\n");
10878 return E_NOTIMPL;
10881 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
10882 IMoniker **ppmon)
10884 ok(0, "unexpected call\n");
10885 return E_NOTIMPL;
10888 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
10890 return E_NOTIMPL;
10893 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
10895 ok(0, "unexpected call\n");
10896 return E_NOTIMPL;
10899 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
10901 ok(0, "unexpected call\n");
10902 return E_NOTIMPL;
10905 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
10907 ok(0, "unexpected call\n");
10908 return E_NOTIMPL;
10911 static const IOleClientSiteVtbl ClientSiteVtbl = {
10912 ClientSite_QueryInterface,
10913 ClientSite_AddRef,
10914 ClientSite_Release,
10915 ClientSite_SaveObject,
10916 ClientSite_GetMoniker,
10917 ClientSite_GetContainer,
10918 ClientSite_ShowObject,
10919 ClientSite_OnShowWindow,
10920 ClientSite_RequestNewObjectLayout
10923 static IOleClientSite ClientSite = { &ClientSiteVtbl };
10925 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
10927 return cs_qi(riid, ppv);
10930 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
10932 return 2;
10935 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
10937 return 1;
10940 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
10942 RECT rect = {0,0,500,500};
10943 IOleDocument *document;
10944 HRESULT hres;
10946 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
10947 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
10949 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
10950 IOleDocument_Release(document);
10951 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
10953 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
10954 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
10956 hres = IOleDocumentView_UIActivate(view, TRUE);
10957 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
10959 hres = IOleDocumentView_SetRect(view, &rect);
10960 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
10962 hres = IOleDocumentView_Show(view, TRUE);
10963 ok(hres == S_OK, "Show failed: %08x\n", hres);
10965 return S_OK;
10968 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
10969 DocumentSite_QueryInterface,
10970 DocumentSite_AddRef,
10971 DocumentSite_Release,
10972 DocumentSite_ActivateMe
10975 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
10977 static HRESULT cs_qi(REFIID riid, void **ppv)
10979 *ppv = NULL;
10981 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
10982 *ppv = &ClientSite;
10983 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
10984 *ppv = &DocumentSite;
10985 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
10986 *ppv = &InPlaceSite;
10988 return *ppv ? S_OK : E_NOINTERFACE;
10991 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
10993 IOleObject *oleobj;
10994 HRESULT hres;
10996 if(!set && view) {
10997 IOleDocumentView_Show(view, FALSE);
10998 IOleDocumentView_CloseView(view, 0);
10999 IOleDocumentView_SetInPlaceSite(view, NULL);
11000 IOleDocumentView_Release(view);
11001 view = NULL;
11004 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
11005 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
11007 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
11008 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
11010 if(set) {
11011 IHlinkTarget *hlink;
11013 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
11014 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
11016 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
11017 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
11019 IHlinkTarget_Release(hlink);
11022 IOleObject_Release(oleobj);
11025 static IHTMLDocument2 *create_doc_with_string(const char *str)
11027 IPersistStreamInit *init;
11028 IStream *stream;
11029 IHTMLDocument2 *doc;
11030 HGLOBAL mem;
11031 SIZE_T len;
11032 HRESULT hr;
11034 notif_doc = doc = create_document();
11035 if(!doc)
11036 return NULL;
11038 doc_complete = FALSE;
11039 len = strlen(str);
11040 mem = GlobalAlloc(0, len);
11041 memcpy(mem, str, len);
11042 hr = CreateStreamOnHGlobal(mem, TRUE, &stream);
11043 ok(hr == S_OK, "Failed to create a stream, hr %#x.\n", hr);
11045 hr = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
11046 ok(hr == S_OK, "Failed to get IPersistStreamInit, hr %#x.\n", hr);
11048 IPersistStreamInit_Load(init, stream);
11049 IPersistStreamInit_Release(init);
11050 IStream_Release(stream);
11052 return doc;
11055 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
11057 IConnectionPointContainer *container;
11058 IConnectionPoint *cp;
11059 DWORD cookie;
11060 HRESULT hres;
11062 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
11063 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
11065 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
11066 IConnectionPointContainer_Release(container);
11067 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
11069 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
11070 IConnectionPoint_Release(cp);
11071 ok(hres == S_OK, "Advise failed: %08x\n", hres);
11074 typedef void (*domtest_t)(IHTMLDocument2*);
11076 static void run_domtest(const char *str, domtest_t test)
11078 IHTMLDocument2 *doc;
11079 ULONG ref;
11080 MSG msg;
11082 doc = create_doc_with_string(str);
11083 if(!doc)
11084 return;
11086 set_client_site(doc, TRUE);
11087 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
11089 while(!doc_complete && GetMessageW(&msg, NULL, 0, 0)) {
11090 TranslateMessage(&msg);
11091 DispatchMessageW(&msg);
11094 test(doc);
11096 set_client_site(doc, FALSE);
11097 ref = IHTMLDocument2_Release(doc);
11098 ok(!ref || broken(ref == 1), /* Vista */
11099 "ref = %d\n", ref);
11102 static float expected_document_mode;
11104 static void test_document_mode(IHTMLDocument2 *doc2)
11106 IEventTarget *event_target;
11107 IHTMLDocument2 *doc_node;
11108 IHTMLDocument6 *doc;
11109 IHTMLElement *body;
11110 VARIANT v;
11111 HRESULT hres;
11113 hres = IHTMLDocument2_QueryInterface(doc2, &IID_IHTMLDocument6, (void**)&doc);
11114 if(hres == E_NOINTERFACE) {
11115 win_skip("IHTMLDocument6 not supported\n");
11116 return;
11118 ok(hres == S_OK, "Could not get IHTMLDocument6 interface: %08x\n", hres);
11120 V_VT(&v) = VT_EMPTY;
11121 hres = IHTMLDocument6_get_documentMode(doc, &v);
11122 ok(hres == S_OK, "get_documentMode failed: %08x\n", hres);
11123 ok(V_VT(&v) == VT_R4, "V_VT(documentMode) = %u\n", V_VT(&v));
11124 ok(V_R4(&v) == expected_document_mode, "documentMode = %f\n", V_R4(&v));
11125 IHTMLDocument6_Release(doc);
11127 doc_node = get_doc_node(doc2);
11129 hres = IHTMLDocument2_QueryInterface(doc_node, &IID_IEventTarget, (void**)&event_target);
11130 if(expected_document_mode >= 9) {
11131 ok(hres == S_OK, "Could not get IEventTarget interface: %08x\n", hres);
11132 IEventTarget_Release(event_target);
11133 }else {
11134 ok(hres == E_NOINTERFACE, "QI(IEventTarget) returned %08x\n", hres);
11137 IHTMLDocument2_Release(doc_node);
11140 body = doc_get_body(doc2);
11142 hres = IHTMLElement_QueryInterface(body, &IID_IEventTarget, (void**)&event_target);
11143 if(expected_document_mode >= 9) {
11144 ok(hres == S_OK, "Could not get IEventTarget interface: %08x\n", hres);
11145 IEventTarget_Release(event_target);
11146 }else {
11147 ok(hres == E_NOINTERFACE, "QI(IEventTarget) returned %08x\n", hres);
11150 IHTMLElement_Release(body);
11153 static void test_quirks_mode(void)
11155 run_domtest("<html></html>", check_quirks_mode);
11156 run_domtest("<!DOCTYPE html>\n<html></html>", check_strict_mode);
11157 run_domtest("<!-- comment --><!DOCTYPE html>\n<html></html>", check_quirks_mode);
11158 run_domtest("<html><body></body></html>", test_quirks_mode_offsetHeight);
11160 expected_document_mode = 5;
11161 run_domtest("<html><body></body></html>", test_document_mode);
11163 if(!is_ie9plus)
11164 return;
11166 expected_document_mode = 9;
11167 run_domtest("<!DOCTYPE html>\n"
11168 "<html>"
11169 " <head>"
11170 " <meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" />"
11171 " </head>"
11172 " <body>"
11173 " </body>"
11174 "</html>", test_document_mode);
11176 expected_document_mode = 8;
11177 run_domtest("<!DOCTYPE html>\n"
11178 "<html>"
11179 " <head>"
11180 " <meta http-equiv=\"x-ua-compatible\" content=\"IE=8\" />"
11181 " <meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" />"
11182 " </head>"
11183 " <body>"
11184 " </body>"
11185 "</html>", test_document_mode);
11188 static void check_ie(void)
11190 IHTMLDocument2 *doc;
11191 IHTMLDocument7 *doc7;
11192 HRESULT hres;
11194 doc = create_document();
11195 if(!doc)
11196 return;
11198 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
11199 if(SUCCEEDED(hres)) {
11200 is_ie9plus = TRUE;
11201 IHTMLDocument7_Release(doc7);
11204 trace("is_ie9plus %x\n", is_ie9plus);
11206 IHTMLDocument2_Release(doc);
11209 START_TEST(dom)
11211 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
11212 pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
11213 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
11215 CoInitialize(NULL);
11216 container_hwnd = CreateWindowA("static", NULL, WS_POPUP|WS_VISIBLE,
11217 CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, NULL, NULL);
11219 check_ie();
11221 run_domtest(doc_str1, test_doc_elem);
11222 run_domtest(doc_str1, test_get_set_attr);
11223 run_domtest(doc_blank, test_range);
11224 if (winetest_interactive || ! is_ie_hardened()) {
11225 run_domtest(elem_test_str, test_elems);
11226 run_domtest(elem_test2_str, test_elems2);
11227 run_domtest(doc_blank, test_dom_elements);
11228 if(is_ie9plus) {
11229 compat_mode = COMPAT_IE9;
11230 run_domtest(doc_blank_ie9, test_dom_elements);
11231 compat_mode = COMPAT_NONE;
11233 run_domtest(noscript_str, test_noscript);
11234 }else {
11235 skip("IE running in Enhanced Security Configuration\n");
11237 run_domtest(doc_blank, test_create_elems);
11238 run_domtest(doc_blank, test_defaults);
11239 run_domtest(doc_blank, test_null_write);
11240 run_domtest(emptydiv_str, test_create_stylesheet);
11241 run_domtest(indent_test_str, test_indent);
11242 run_domtest(cond_comment_str, test_cond_comment);
11243 run_domtest(frameset_str, test_frameset);
11244 run_domtest(emptydiv_str, test_docfrag);
11245 run_domtest(doc_blank, test_replacechild_elems);
11246 run_domtest(doctype_str, test_doctype);
11248 test_quirks_mode();
11250 DestroyWindow(container_hwnd);
11251 CoUninitialize();