mshtml: Fix error handler in IHTMLSelectElement::remove().
[wine/multimedia.git] / dlls / mshtml / tests / dom.c
blob7088c522aea8d6c5a147f2e867b002a67b3b34f0
1 /*
2 * Copyright 2007-2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmcid.h"
31 #include "mshtmhst.h"
32 #include "docobj.h"
33 #include "hlink.h"
34 #include "dispex.h"
35 #include "mshtml_test.h"
36 #include "objsafe.h"
37 #include "htiface.h"
38 #include "tlogstg.h"
40 static INT (WINAPI *pLCIDToLocaleName)(LCID,LPWSTR,INT,DWORD);
41 static LANGID (WINAPI *pGetUserDefaultUILanguage)(void);
43 static const char doc_blank[] = "<html></html>";
44 static const char doc_str1[] = "<html><body>test</body></html>";
45 static const char range_test_str[] =
46 "<html><body>test \na<font size=\"2\">bc\t123<br /> it's\r\n \t</font>text<br /></body></html>";
47 static const char range_test2_str[] =
48 "<html><body>abc<hr />123<br /><hr />def</body></html>";
49 static const char elem_test_str[] =
50 "<html><head><title>test</title><style id=\"styleid\">.body { margin-right: 0px; }</style>"
51 "<meta id=\"metaid\" name=\"meta name\" http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
52 "<link id=\"linkid\"></head>"
53 "<body onload=\"Testing()\">text test<!-- a comment -->"
54 "<a id=\"a\" href=\"http://test\" name=\"x\">link</a>"
55 "<label for=\"in\" id=\"labelid\">Label:</label>"
56 "<input id=\"in\" class=\"testclass\" tabIndex=\"2\" title=\"test title\" />"
57 "<button id=\"btnid\"></button>"
58 "<select id=\"s\"><option id=\"x\" value=\"val1\">opt1</option><option id=\"y\">opt2</option></select>"
59 "<textarea id=\"X\">text text</textarea>"
60 "<table id=\"tbl\"><tbody><tr></tr><tr id=\"row2\"><td id=\"td1\">td1 text</td><td id=\"td2\">td2 text</td></tr></tbody></table>"
61 "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
62 "<test /><object id=\"objid\" name=\"objname\" vspace=100></object><embed />"
63 "<img id=\"imgid\" name=\"WineImg\"/>"
64 "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
65 "<form id=\"frm\"></form>"
66 "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
67 "</body></html>";
68 static const char elem_test2_str[] =
69 "<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
70 "<link id=\"linkid\" rel=\"stylesheet\" href=\"about:blank\" type=\"text/css\"></head>"
71 "<body><div id=\"divid\" emptyattr=\"\" onclick=\"parseInt();\"></div></body>"
72 "</html>";
74 static const char indent_test_str[] =
75 "<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
76 static const char cond_comment_str[] =
77 "<html><head><title>test</title></head><body>"
78 "<!--[if gte IE 4]> <br> <![endif]-->"
79 "</body></html>";
80 static const char frameset_str[] =
81 "<html><head><title>frameset test</title></head><frameset rows=\"25, 25, *\">"
82 "<frame src=\"about:blank\" name=\"nm1\" id=\"fr1\"><frame src=\"about:blank\" name=\"nm2\" id=\"fr2\">"
83 "<frame src=\"about:blank\" id=\"fr3\">"
84 "</frameset></html>";
85 static const char emptydiv_str[] =
86 "<html><head><title>emptydiv test</title></head>"
87 "<body><div id=\"divid\"></div></body></html>";
88 static const char noscript_str[] =
89 "<html><head><title>noscript test</title><noscript><style>.body { margin-right: 0px; }</style></noscript></head>"
90 "<body><noscript><div>test</div></noscript></body></html>";
91 static const char doctype_str[] =
92 "<!DOCTYPE html>"
93 "<html><head><title>emptydiv test</title></head>"
94 "<body><div id=\"divid\"></div></body></html>";
96 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
97 static WCHAR texteditW[] = {'t','e','x','t','e','d','i','t',0};
98 static WCHAR wordW[] = {'w','o','r','d',0};
100 typedef enum {
101 ET_NONE,
102 ET_HTML,
103 ET_HEAD,
104 ET_TITLE,
105 ET_BODY,
106 ET_A,
107 ET_INPUT,
108 ET_SELECT,
109 ET_TEXTAREA,
110 ET_OPTION,
111 ET_STYLE,
112 ET_BLOCKQUOTE,
113 ET_P,
114 ET_BR,
115 ET_TABLE,
116 ET_TBODY,
117 ET_SCRIPT,
118 ET_TEST,
119 ET_TESTG,
120 ET_COMMENT,
121 ET_IMG,
122 ET_TR,
123 ET_TD,
124 ET_IFRAME,
125 ET_FORM,
126 ET_FRAME,
127 ET_OBJECT,
128 ET_EMBED,
129 ET_DIV,
130 ET_META,
131 ET_NOSCRIPT,
132 ET_LINK,
133 ET_LABEL,
134 ET_BUTTON
135 } elem_type_t;
137 static const IID * const none_iids[] = {
138 &IID_IUnknown,
139 NULL
142 static const IID * const doc_node_iids[] = {
143 &IID_IHTMLDOMNode,
144 &IID_IHTMLDOMNode2,
145 &IID_IHTMLDocument,
146 &IID_IHTMLDocument2,
147 &IID_IHTMLDocument3,
148 &IID_IHTMLDocument4,
149 &IID_IHTMLDocument5,
150 &IID_IDispatchEx,
151 &IID_IConnectionPointContainer,
152 &IID_IInternetHostSecurityManager,
153 &IID_IOleContainer,
154 &IID_IObjectSafety,
155 &IID_IProvideClassInfo,
156 NULL
159 static const IID * const doc_obj_iids[] = {
160 &IID_IHTMLDocument,
161 &IID_IHTMLDocument2,
162 &IID_IHTMLDocument3,
163 &IID_IHTMLDocument4,
164 &IID_IHTMLDocument5,
165 &IID_IDispatchEx,
166 &IID_IConnectionPointContainer,
167 &IID_ICustomDoc,
168 &IID_IOleContainer,
169 &IID_IObjectSafety,
170 &IID_IProvideClassInfo,
171 &IID_ITargetContainer,
172 NULL
175 #define ELEM_IFACES \
176 &IID_IHTMLDOMNode, \
177 &IID_IHTMLDOMNode2, \
178 &IID_IHTMLElement, \
179 &IID_IHTMLElement2, \
180 &IID_IHTMLElement3, \
181 &IID_IHTMLElement4, \
182 &IID_IDispatchEx
184 static const IID * const elem_iids[] = {
185 ELEM_IFACES,
186 &IID_IConnectionPointContainer,
187 NULL
190 static const IID * const body_iids[] = {
191 ELEM_IFACES,
192 &IID_IHTMLTextContainer,
193 &IID_IHTMLBodyElement,
194 &IID_IConnectionPointContainer,
195 NULL
198 static const IID * const anchor_iids[] = {
199 ELEM_IFACES,
200 &IID_IHTMLAnchorElement,
201 &IID_IConnectionPointContainer,
202 NULL
205 static const IID * const input_iids[] = {
206 ELEM_IFACES,
207 &IID_IHTMLInputElement,
208 &IID_IHTMLInputTextElement,
209 &IID_IConnectionPointContainer,
210 NULL
213 static const IID *const button_iids[] = {
214 ELEM_IFACES,
215 &IID_IHTMLButtonElement,
216 &IID_IConnectionPointContainer,
217 NULL
220 static const IID * const label_iids[] = {
221 ELEM_IFACES,
222 &IID_IHTMLLabelElement,
223 &IID_IConnectionPointContainer,
224 NULL
227 static const IID * const select_iids[] = {
228 ELEM_IFACES,
229 &IID_IHTMLSelectElement,
230 &IID_IConnectionPointContainer,
231 NULL
234 static const IID * const textarea_iids[] = {
235 ELEM_IFACES,
236 &IID_IHTMLTextAreaElement,
237 &IID_IConnectionPointContainer,
238 NULL
241 static const IID * const option_iids[] = {
242 ELEM_IFACES,
243 &IID_IHTMLOptionElement,
244 &IID_IConnectionPointContainer,
245 NULL
248 static const IID * const table_iids[] = {
249 ELEM_IFACES,
250 &IID_IHTMLTable,
251 &IID_IHTMLTable2,
252 &IID_IHTMLTable3,
253 &IID_IConnectionPointContainer,
254 NULL
257 static const IID * const script_iids[] = {
258 ELEM_IFACES,
259 &IID_IHTMLScriptElement,
260 &IID_IConnectionPointContainer,
261 NULL
264 static const IID * const text_iids[] = {
265 &IID_IHTMLDOMNode,
266 &IID_IHTMLDOMNode2,
267 &IID_IHTMLDOMTextNode,
268 &IID_IHTMLDOMTextNode2,
269 NULL
272 static const IID * const attr_iids[] = {
273 &IID_IHTMLDOMAttribute,
274 &IID_IHTMLDOMAttribute2,
275 &IID_IDispatchEx,
276 NULL
279 static const IID * const location_iids[] = {
280 &IID_IDispatch,
281 &IID_IHTMLLocation,
282 NULL
285 static const IID * const window_iids[] = {
286 &IID_IDispatch,
287 &IID_IHTMLWindow2,
288 &IID_IHTMLWindow3,
289 &IID_IDispatchEx,
290 &IID_IServiceProvider,
291 NULL
294 static const IID * const comment_iids[] = {
295 ELEM_IFACES,
296 &IID_IHTMLCommentElement,
297 &IID_IConnectionPointContainer,
298 NULL
301 static const IID * const img_iids[] = {
302 ELEM_IFACES,
303 &IID_IHTMLImgElement,
304 &IID_IConnectionPointContainer,
305 NULL
308 static const IID * const tr_iids[] = {
309 ELEM_IFACES,
310 &IID_IHTMLTableRow,
311 &IID_IConnectionPointContainer,
312 NULL
315 static const IID * const td_iids[] = {
316 ELEM_IFACES,
317 &IID_IHTMLTableCell,
318 &IID_IConnectionPointContainer,
319 NULL
322 static const IID * const frame_iids[] = {
323 ELEM_IFACES,
324 &IID_IHTMLFrameBase,
325 &IID_IHTMLFrameBase2,
326 &IID_IConnectionPointContainer,
327 NULL
330 static const IID * const head_iids[] = {
331 ELEM_IFACES,
332 &IID_IHTMLHeadElement,
333 &IID_IConnectionPointContainer,
334 NULL
337 static const IID * const title_iids[] = {
338 ELEM_IFACES,
339 &IID_IHTMLTitleElement,
340 &IID_IConnectionPointContainer,
341 NULL
344 static const IID * const meta_iids[] = {
345 ELEM_IFACES,
346 &IID_IHTMLMetaElement,
347 &IID_IConnectionPointContainer,
348 NULL
351 static const IID * const link_iids[] = {
352 ELEM_IFACES,
353 &IID_IHTMLLinkElement,
354 &IID_IConnectionPointContainer,
355 NULL
358 static const IID * const object_iids[] = {
359 ELEM_IFACES,
360 &IID_IHTMLObjectElement,
361 &IID_IHTMLObjectElement2,
362 /* FIXME: No IConnectionPointContainer */
363 NULL
366 static const IID * const embed_iids[] = {
367 ELEM_IFACES,
368 &IID_IHTMLEmbedElement,
369 /* FIXME: No IConnectionPointContainer */
370 NULL
373 static const IID * const iframe_iids[] = {
374 ELEM_IFACES,
375 &IID_IHTMLFrameBase,
376 &IID_IHTMLFrameBase2,
377 &IID_IHTMLIFrameElement,
378 &IID_IHTMLIFrameElement2,
379 &IID_IConnectionPointContainer,
380 NULL
383 static const IID * const form_iids[] = {
384 ELEM_IFACES,
385 &IID_IHTMLFormElement,
386 &IID_IConnectionPointContainer,
387 &DIID_DispHTMLFormElement,
388 NULL
391 static const IID * const styleelem_iids[] = {
392 ELEM_IFACES,
393 &IID_IHTMLStyleElement,
394 &IID_IConnectionPointContainer,
395 NULL
398 static const IID * const generic_iids[] = {
399 ELEM_IFACES,
400 &IID_IHTMLGenericElement,
401 &IID_IConnectionPointContainer,
402 NULL
405 static const IID * const style_iids[] = {
406 &IID_IUnknown,
407 &IID_IDispatch,
408 &IID_IDispatchEx,
409 &IID_IHTMLStyle,
410 &IID_IHTMLStyle2,
411 &IID_IHTMLStyle3,
412 &IID_IHTMLStyle4,
413 NULL
416 static const IID * const cstyle_iids[] = {
417 &IID_IUnknown,
418 &IID_IDispatch,
419 &IID_IDispatchEx,
420 &IID_IHTMLCurrentStyle,
421 &IID_IHTMLCurrentStyle2,
422 &IID_IHTMLCurrentStyle3,
423 NULL
426 static const IID * const img_factory_iids[] = {
427 &IID_IUnknown,
428 &IID_IDispatch,
429 &IID_IDispatchEx,
430 &IID_IHTMLImageElementFactory,
431 NULL
434 static const IID * const selection_iids[] = {
435 &IID_IUnknown,
436 &IID_IDispatch,
437 &IID_IDispatchEx,
438 &IID_IHTMLSelectionObject,
439 &IID_IHTMLSelectionObject2,
440 NULL
443 typedef struct {
444 const char *tag;
445 REFIID *iids;
446 const IID *dispiid;
447 } elem_type_info_t;
449 static const elem_type_info_t elem_type_infos[] = {
450 {"", none_iids, NULL},
451 {"HTML", elem_iids, NULL},
452 {"HEAD", head_iids, &DIID_DispHTMLHeadElement},
453 {"TITLE", title_iids, &DIID_DispHTMLTitleElement},
454 {"BODY", body_iids, &DIID_DispHTMLBody},
455 {"A", anchor_iids, &DIID_DispHTMLAnchorElement},
456 {"INPUT", input_iids, &DIID_DispHTMLInputElement},
457 {"SELECT", select_iids, &DIID_DispHTMLSelectElement},
458 {"TEXTAREA", textarea_iids, &DIID_DispHTMLTextAreaElement},
459 {"OPTION", option_iids, &DIID_DispHTMLOptionElement},
460 {"STYLE", styleelem_iids, &DIID_DispHTMLStyleElement},
461 {"BLOCKQUOTE",elem_iids, NULL},
462 {"P", elem_iids, NULL},
463 {"BR", elem_iids, NULL},
464 {"TABLE", table_iids, &DIID_DispHTMLTable},
465 {"TBODY", elem_iids, NULL},
466 {"SCRIPT", script_iids, &DIID_DispHTMLScriptElement},
467 {"TEST", elem_iids, &DIID_DispHTMLUnknownElement},
468 {"TEST", generic_iids, &DIID_DispHTMLGenericElement},
469 {"!", comment_iids, &DIID_DispHTMLCommentElement},
470 {"IMG", img_iids, &DIID_DispHTMLImg},
471 {"TR", tr_iids, &DIID_DispHTMLTableRow},
472 {"TD", td_iids, &DIID_DispHTMLTableCell},
473 {"IFRAME", iframe_iids, &DIID_DispHTMLIFrame},
474 {"FORM", form_iids, &DIID_DispHTMLFormElement},
475 {"FRAME", frame_iids, &DIID_DispHTMLFrameElement},
476 {"OBJECT", object_iids, &DIID_DispHTMLObjectElement},
477 {"EMBED", embed_iids, &DIID_DispHTMLEmbed},
478 {"DIV", elem_iids, NULL},
479 {"META", meta_iids, &DIID_DispHTMLMetaElement},
480 {"NOSCRIPT", elem_iids, NULL /*&DIID_DispHTMLNoShowElement*/},
481 {"LINK", link_iids, &DIID_DispHTMLLinkElement},
482 {"LABEL", label_iids, &DIID_DispHTMLLabelElement},
483 {"BUTTON", button_iids, &DIID_DispHTMLButtonElement}
486 static int strcmp_wa(LPCWSTR strw, const char *stra)
488 CHAR buf[512];
489 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
490 return lstrcmpA(stra, buf);
493 static BOOL is_prefix_wa(const WCHAR *strw, const char *prefix)
495 int len, prefix_len;
496 CHAR buf[512];
498 len = WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL)-1;
499 prefix_len = lstrlenA(prefix);
500 if(len < prefix_len)
501 return FALSE;
503 buf[prefix_len] = 0;
504 return !lstrcmpA(buf, prefix);
507 static BSTR a2bstr(const char *str)
509 BSTR ret;
510 int len;
512 if(!str)
513 return NULL;
515 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
516 ret = SysAllocStringLen(NULL, len);
517 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
519 return ret;
522 static const char *debugstr_variant(const VARIANT *var)
524 static char buf[400];
526 if (!var)
527 return "(null)";
529 switch (V_VT(var))
531 case VT_EMPTY:
532 return "{VT_EMPTY}";
533 case VT_BSTR:
534 sprintf(buf, "{VT_BSTR: %s}", wine_dbgstr_w(V_BSTR(var)));
535 break;
536 case VT_BOOL:
537 sprintf(buf, "{VT_BOOL: %x}", V_BOOL(var));
538 break;
539 case VT_UI4:
540 sprintf(buf, "{VT_UI4: %u}", V_UI4(var));
541 break;
542 default:
543 sprintf(buf, "{vt %d}", V_VT(var));
544 break;
547 return buf;
550 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
552 IUnknown *unk1, *unk2;
554 if(iface1 == iface2)
555 return TRUE;
557 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
558 IUnknown_Release(unk1);
559 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
560 IUnknown_Release(unk2);
562 return unk1 == unk2;
565 static IHTMLDocument2 *create_document(void)
567 IHTMLDocument2 *doc;
568 IHTMLDocument5 *doc5;
569 HRESULT hres;
571 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
572 &IID_IHTMLDocument2, (void**)&doc);
573 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
574 if(FAILED(hres))
575 return NULL;
577 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
578 if(FAILED(hres)) {
579 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
580 IHTMLDocument2_Release(doc);
581 return NULL;
584 IHTMLDocument5_Release(doc5);
585 return doc;
588 #define get_dispex_iface(u) _get_dispex_iface(__LINE__,u)
589 static IDispatchEx *_get_dispex_iface(unsigned line, IUnknown *unk)
591 IDispatchEx *dispex;
592 HRESULT hres;
594 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
595 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
596 return dispex;
599 #define test_ifaces(i,ids) _test_ifaces(__LINE__,i,ids)
600 static void _test_ifaces(unsigned line, IUnknown *iface, REFIID *iids)
602 const IID * const *piid;
603 IUnknown *unk;
604 HRESULT hres;
606 for(piid = iids; *piid; piid++) {
607 hres = IUnknown_QueryInterface(iface, *piid, (void**)&unk);
608 ok_(__FILE__,line) (hres == S_OK, "Could not get %s interface: %08x\n", wine_dbgstr_guid(*piid), hres);
609 if(SUCCEEDED(hres))
610 IUnknown_Release(unk);
614 #define test_no_iface(a,b) _test_no_iface(__LINE__,a,b)
615 static void _test_no_iface(unsigned line, IUnknown *iface, REFIID iid)
617 IUnknown *unk;
618 HRESULT hres;
620 unk = (void*)0xdeadbeef;
621 hres = IUnknown_QueryInterface(iface, iid, (void**)&unk);
622 ok_(__FILE__,line)(hres == E_NOINTERFACE, "hres = %08x, expected E_NOINTERFACE\n", hres);
623 ok_(__FILE__,line)(!unk, "unk = %p\n", unk);
626 #define test_get_dispid(u,id) _test_get_dispid(__LINE__,u,id)
627 static BOOL _test_get_dispid(unsigned line, IUnknown *unk, IID *iid)
629 IDispatchEx *dispex = _get_dispex_iface(line, unk);
630 ITypeInfo *typeinfo;
631 BOOL ret = FALSE;
632 UINT ticnt;
633 HRESULT hres;
635 ticnt = 0xdeadbeef;
636 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
637 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
638 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
640 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
641 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
643 if(SUCCEEDED(hres)) {
644 TYPEATTR *type_attr;
646 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
647 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
648 if(hres == S_OK) {
649 *iid = type_attr->guid;
650 ret = TRUE;
653 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
654 ITypeInfo_Release(typeinfo);
657 IDispatchEx_Release(dispex);
658 return ret;
661 #define test_disp_value(u) _test_disp_value(__LINE__,u,v)
662 static void _test_disp_value(unsigned line, IUnknown *unk, const char *val)
664 IDispatchEx *dispex = _get_dispex_iface(line, unk);
665 DISPPARAMS dp = {NULL,NULL,0,0};
666 EXCEPINFO ei;
667 VARIANT var;
668 HRESULT hres;
670 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
671 IDispatchEx_Release(dispex);
672 ok_(__FILE__,line)(hres == S_OK, "InvokeEx(DISPID_VALUE) returned: %08x\n", hres);
674 ok_(__FILE__,line)(V_VT(&var) == VT_BSTR, "V_VT(value) = %d\n", V_VT(&var));
675 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&var), val), "value = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&var)), val);
676 VariantClear(&var);
679 #define test_disp(u,id,v) _test_disp(__LINE__,u,id,v)
680 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid, const char *val)
682 IID iid;
684 if(_test_get_dispid(line, unk, &iid))
685 ok_(__FILE__,line) (IsEqualGUID(&iid, diid), "unexpected guid %s\n", wine_dbgstr_guid(&iid));
687 if(val)
688 _test_disp_value(line, unk, val);
691 #define test_disp2(u,id,id2,v) _test_disp2(__LINE__,u,id,id2,v)
692 static void _test_disp2(unsigned line, IUnknown *unk, const IID *diid, const IID *diid2, const char *val)
694 IID iid;
696 if(_test_get_dispid(line, unk, &iid))
697 ok_(__FILE__,line) (IsEqualGUID(&iid, diid) || broken(IsEqualGUID(&iid, diid2)),
698 "unexpected guid %s\n", wine_dbgstr_guid(&iid));
700 if(val)
701 _test_disp_value(line, unk, val);
704 #define test_class_info(u) _test_class_info(__LINE__,u)
705 static void _test_class_info(unsigned line, IUnknown *unk)
707 IProvideClassInfo *classinfo;
708 ITypeInfo *typeinfo;
709 TYPEATTR *type_attr;
710 HRESULT hres;
712 hres = IUnknown_QueryInterface(unk, &IID_IProvideClassInfo, (void**)&classinfo);
713 ok_(__FILE__,line)(hres == S_OK, "Could not get IProvideClassInfo interface: %08x\n", hres);
714 if(FAILED(hres))
715 return;
717 hres = IProvideClassInfo_GetClassInfo(classinfo, &typeinfo);
718 ok_(__FILE__,line)(hres == S_OK, "Could not get ITypeInfo interface: %08x\n", hres);
719 if(FAILED(hres))
721 IProvideClassInfo_Release(classinfo);
722 return;
725 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
726 ok_(__FILE__,line)(hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
727 if(SUCCEEDED(hres))
729 ok_(__FILE__,line)(IsEqualGUID(&type_attr->guid, &CLSID_HTMLDocument),
730 "unexpected guid %s\n", wine_dbgstr_guid(&type_attr->guid));
731 ok_(__FILE__,line)(type_attr->typekind == TKIND_COCLASS,
732 "unexpected typekind %d\n", type_attr->typekind);
733 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
736 ITypeInfo_Release(typeinfo);
737 IProvideClassInfo_Release(classinfo);
740 #define set_dispex_value(a,b,c) _set_dispex_value(__LINE__,a,b,c)
741 static void _set_dispex_value(unsigned line, IUnknown *unk, const char *name, VARIANT *val)
743 IDispatchEx *dispex = _get_dispex_iface(line, unk);
744 DISPPARAMS dp = {val, NULL, 1, 0};
745 EXCEPINFO ei;
746 DISPID id;
747 BSTR str;
748 HRESULT hres;
750 str = a2bstr(name);
751 hres = IDispatchEx_GetDispID(dispex, str, fdexNameEnsure|fdexNameCaseInsensitive, &id);
752 SysFreeString(str);
753 ok_(__FILE__,line)(hres == S_OK, "GetDispID failed: %08x\n", hres);
755 memset(&ei, 0, sizeof(ei));
756 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
757 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
761 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
762 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
764 IHTMLElement *elem;
765 HRESULT hres;
767 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
768 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement: %08x\n", hres);
769 return elem;
772 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
773 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
775 IHTMLElement2 *elem;
776 HRESULT hres;
778 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem);
779 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2: %08x\n", hres);
780 return elem;
783 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
784 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
786 IHTMLElement3 *elem;
787 HRESULT hres;
789 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem);
790 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3: %08x\n", hres);
791 return elem;
794 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
795 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
797 IHTMLElement4 *elem;
798 HRESULT hres;
800 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem);
801 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4: %08x\n", hres);
802 return elem;
805 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
806 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IHTMLDocument2 *doc)
808 IHTMLDocument3 *doc3;
809 HRESULT hres;
811 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
812 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
814 return doc3;
817 #define get_node_iface(u) _get_node_iface(__LINE__,u)
818 static IHTMLDOMNode *_get_node_iface(unsigned line, IUnknown *unk)
820 IHTMLDOMNode *node;
821 HRESULT hres;
823 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
824 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode: %08x\n", hres);
825 return node;
828 #define get_node2_iface(u) _get_node2_iface(__LINE__,u)
829 static IHTMLDOMNode2 *_get_node2_iface(unsigned line, IUnknown *unk)
831 IHTMLDOMNode2 *node;
832 HRESULT hres;
834 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&node);
835 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMNode2: %08x\n", hres);
836 return node;
839 #define get_htmldoc5_iface(u) _get_htmldoc5_iface(__LINE__,u)
840 static IHTMLDocument5 *_get_htmldoc5_iface(unsigned line, IUnknown *unk)
842 IHTMLDocument5 *doc;
843 HRESULT hres;
845 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument5, (void**)&doc);
846 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument5: %08x\n", hres);
847 return doc;
850 #define get_img_iface(u) _get_img_iface(__LINE__,u)
851 static IHTMLImgElement *_get_img_iface(unsigned line, IUnknown *unk)
853 IHTMLImgElement *img;
854 HRESULT hres;
856 hres = IUnknown_QueryInterface(unk, &IID_IHTMLImgElement, (void**)&img);
857 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLImgElement: %08x\n", hres);
858 return img;
861 #define get_anchor_iface(u) _get_anchor_iface(__LINE__,u)
862 static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
864 IHTMLAnchorElement *anchor;
865 HRESULT hres;
867 hres = IUnknown_QueryInterface(unk, &IID_IHTMLAnchorElement, (void**)&anchor);
868 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAnchorElement: %08x\n", hres);
869 return anchor;
872 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
873 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
875 IHTMLTextAreaElement *textarea;
876 HRESULT hres;
878 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextAreaElement, (void**)&textarea);
879 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextAreaElement: %08x\n", hres);
880 return textarea;
883 #define get_select_iface(u) _get_select_iface(__LINE__,u)
884 static IHTMLSelectElement *_get_select_iface(unsigned line, IUnknown *unk)
886 IHTMLSelectElement *select;
887 HRESULT hres;
889 hres = IUnknown_QueryInterface(unk, &IID_IHTMLSelectElement, (void**)&select);
890 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLSelectElement: %08x\n", hres);
891 return select;
894 #define get_form_iface(u) _get_form_iface(__LINE__,u)
895 static IHTMLFormElement *_get_form_iface(unsigned line, IUnknown *unk)
897 IHTMLFormElement *form;
898 HRESULT hres;
900 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFormElement, (void**)&form);
901 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
902 return form;
905 #define get_text_iface(u) _get_text_iface(__LINE__,u)
906 static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
908 IHTMLDOMTextNode *text;
909 HRESULT hres;
911 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode, (void**)&text);
912 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode: %08x\n", hres);
913 return text;
916 #define get_text2_iface(u) _get_text2_iface(__LINE__,u)
917 static IHTMLDOMTextNode2 *_get_text2_iface(unsigned line, IUnknown *unk)
919 IHTMLDOMTextNode2 *text2;
920 HRESULT hres;
922 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMTextNode2, (void**)&text2);
923 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMTextNode2: %08x\n", hres);
924 return text2;
927 #define get_comment_iface(u) _get_comment_iface(__LINE__,u)
928 static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
930 IHTMLCommentElement *comment;
931 HRESULT hres;
933 hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
934 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
935 return comment;
938 #define get_object_iface(u) _get_object_iface(__LINE__,u)
939 static IHTMLObjectElement *_get_object_iface(unsigned line, IUnknown *unk)
941 IHTMLObjectElement *obj;
942 HRESULT hres;
944 hres = IUnknown_QueryInterface(unk, &IID_IHTMLObjectElement, (void**)&obj);
945 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLObjectElement: %08x\n", hres);
946 return obj;
949 #define get_style_iface(u) _get_style_iface(__LINE__,u)
950 static IHTMLStyleElement *_get_style_iface(unsigned line, IUnknown *unk)
952 IHTMLStyleElement *obj;
953 HRESULT hres;
955 hres = IUnknown_QueryInterface(unk, &IID_IHTMLStyleElement, (void**)&obj);
956 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLStyleElement: %08x\n", hres);
957 return obj;
960 #define get_metaelem_iface(u) _get_metaelem_iface(__LINE__,u)
961 static IHTMLMetaElement *_get_metaelem_iface(unsigned line, IUnknown *unk)
963 IHTMLMetaElement *ret;
964 HRESULT hres;
966 hres = IUnknown_QueryInterface(unk, &IID_IHTMLMetaElement, (void**)&ret);
967 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLMetaElement: %08x\n", hres);
968 return ret;
971 #define get_link_iface(u) _get_link_iface(__LINE__,u)
972 static IHTMLLinkElement *_get_link_iface(unsigned line, IUnknown *unk)
974 IHTMLLinkElement *ret;
975 HRESULT hres;
977 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLinkElement, (void**)&ret);
978 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLinkElement: %08x\n", hres);
979 return ret;
982 #define get_iframe2_iface(u) _get_iframe2_iface(__LINE__,u)
983 static IHTMLIFrameElement2 *_get_iframe2_iface(unsigned line, IUnknown *unk)
985 IHTMLIFrameElement2 *ret;
986 HRESULT hres;
988 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement2, (void**)&ret);
989 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLIFrameElement: %08x\n", hres);
990 return ret;
993 #define get_button_iface(u) _get_button_iface(__LINE__,u)
994 static IHTMLButtonElement *_get_button_iface(unsigned line, IUnknown *unk)
996 IHTMLButtonElement *ret;
997 HRESULT hres;
999 hres = IUnknown_QueryInterface(unk, &IID_IHTMLButtonElement, (void**)&ret);
1000 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLButtonElement: %08x\n", hres);
1001 return ret;
1004 #define get_label_iface(u) _get_label_iface(__LINE__,u)
1005 static IHTMLLabelElement *_get_label_iface(unsigned line, IUnknown *unk)
1007 IHTMLLabelElement *ret;
1008 HRESULT hres;
1010 hres = IUnknown_QueryInterface(unk, &IID_IHTMLLabelElement, (void**)&ret);
1011 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLLabelElement: %08x\n", hres);
1012 return ret;
1015 #define get_attr2_iface(u) _get_attr2_iface(__LINE__,u)
1016 static IHTMLDOMAttribute2 *_get_attr2_iface(unsigned line, IUnknown *unk)
1018 IHTMLDOMAttribute2 *ret;
1019 HRESULT hres;
1021 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMAttribute2, (void**)&ret);
1022 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMAttribute2: %08x\n", hres);
1023 return ret;
1026 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
1027 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
1029 IHTMLDOMNode *node = _get_node_iface(line, unk);
1030 BSTR name;
1031 HRESULT hres;
1033 hres = IHTMLDOMNode_get_nodeName(node, &name);
1034 IHTMLDOMNode_Release(node);
1035 ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
1036 ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected %s\n", wine_dbgstr_w(name), exname);
1038 SysFreeString(name);
1041 #define get_owner_doc(u) _get_owner_doc(__LINE__,u)
1042 static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk)
1044 IHTMLDOMNode2 *node = _get_node2_iface(line, unk);
1045 IDispatch *disp = (void*)0xdeadbeef;
1046 IHTMLDocument2 *doc = NULL;
1047 HRESULT hres;
1049 hres = IHTMLDOMNode2_get_ownerDocument(node, &disp);
1050 IHTMLDOMNode2_Release(node);
1051 ok_(__FILE__,line)(hres == S_OK, "get_ownerDocument failed: %08x\n", hres);
1053 if(disp) {
1054 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
1055 IDispatch_Release(disp);
1056 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
1059 return doc;
1062 #define get_doc_window(d) _get_doc_window(__LINE__,d)
1063 static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc)
1065 IHTMLWindow2 *window;
1066 HRESULT hres;
1068 window = NULL;
1069 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1070 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1071 ok_(__FILE__,line)(window != NULL, "window == NULL\n");
1073 return window;
1076 #define clone_node(n,d) _clone_node(__LINE__,n,d)
1077 static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep)
1079 IHTMLDOMNode *node = _get_node_iface(line, unk);
1080 IHTMLDOMNode *ret = NULL;
1081 HRESULT hres;
1083 hres = IHTMLDOMNode_cloneNode(node, deep, &ret);
1084 IHTMLDOMNode_Release(node);
1085 ok_(__FILE__,line)(hres == S_OK, "cloneNode failed: %08x\n", hres);
1086 ok_(__FILE__,line)(ret != NULL, "ret == NULL\n");
1088 return ret;
1092 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
1093 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
1095 IHTMLElement *elem = _get_elem_iface(line, unk);
1096 BSTR tag;
1097 HRESULT hres;
1099 hres = IHTMLElement_get_tagName(elem, &tag);
1100 IHTMLElement_Release(elem);
1101 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
1102 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
1104 SysFreeString(tag);
1107 #define test_elem_type(ifc,t) _test_elem_type(__LINE__,ifc,t)
1108 static void _test_elem_type(unsigned line, IUnknown *unk, elem_type_t type)
1110 _test_elem_tag(line, unk, elem_type_infos[type].tag);
1111 _test_ifaces(line, unk, elem_type_infos[type].iids);
1113 if(elem_type_infos[type].dispiid && type != ET_A)
1114 _test_disp(line, unk, elem_type_infos[type].dispiid, "[object]");
1117 #define get_node_type(n) _get_node_type(__LINE__,n)
1118 static LONG _get_node_type(unsigned line, IUnknown *unk)
1120 IHTMLDOMNode *node = _get_node_iface(line, unk);
1121 LONG type = -1;
1122 HRESULT hres;
1124 hres = IHTMLDOMNode_get_nodeType(node, &type);
1125 ok(hres == S_OK, "get_nodeType failed: %08x\n", hres);
1127 IHTMLDOMNode_Release(node);
1129 return type;
1132 #define get_child_nodes(u) _get_child_nodes(__LINE__,u)
1133 static IHTMLDOMChildrenCollection *_get_child_nodes(unsigned line, IUnknown *unk)
1135 IHTMLDOMNode *node = _get_node_iface(line, unk);
1136 IHTMLDOMChildrenCollection *col = NULL;
1137 IDispatch *disp;
1138 HRESULT hres;
1140 hres = IHTMLDOMNode_get_childNodes(node, &disp);
1141 IHTMLDOMNode_Release(node);
1142 ok_(__FILE__,line) (hres == S_OK, "get_childNodes failed: %08x\n", hres);
1143 if(FAILED(hres))
1144 return NULL;
1146 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDOMChildrenCollection, (void**)&col);
1147 IDispatch_Release(disp);
1148 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDOMChildrenCollection: %08x\n", hres);
1150 return col;
1153 #define get_child_item(c,i) _get_child_item(__LINE__,c,i)
1154 static IHTMLDOMNode *_get_child_item(unsigned line, IHTMLDOMChildrenCollection *col, LONG idx)
1156 IHTMLDOMNode *node = NULL;
1157 IDispatch *disp;
1158 HRESULT hres;
1160 hres = IHTMLDOMChildrenCollection_item(col, idx, &disp);
1161 ok(hres == S_OK, "item failed: %08x\n", hres);
1163 node = _get_node_iface(line, (IUnknown*)disp);
1164 IDispatch_Release(disp);
1166 return node;
1169 #define test_elem_attr(e,n,v) _test_elem_attr(__LINE__,e,n,v)
1170 static void _test_elem_attr(unsigned line, IHTMLElement *elem, const char *name, const char *exval)
1172 VARIANT value;
1173 BSTR tmp;
1174 HRESULT hres;
1176 VariantInit(&value);
1178 tmp = a2bstr(name);
1179 hres = IHTMLElement_getAttribute(elem, tmp, 0, &value);
1180 SysFreeString(tmp);
1181 ok_(__FILE__,line) (hres == S_OK, "getAttribute failed: %08x\n", hres);
1183 if(exval) {
1184 ok_(__FILE__,line) (V_VT(&value) == VT_BSTR, "vt=%d\n", V_VT(&value));
1185 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&value), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&value)));
1186 }else {
1187 ok_(__FILE__,line) (V_VT(&value) == VT_NULL, "vt=%d\n", V_VT(&value));
1190 VariantClear(&value);
1193 #define test_elem_offset(a,b) _test_elem_offset(__LINE__,a,b)
1194 static void _test_elem_offset(unsigned line, IUnknown *unk, const char *parent_tag)
1196 IHTMLElement *elem = _get_elem_iface(line, unk);
1197 IHTMLElement *off_parent;
1198 LONG l;
1199 HRESULT hres;
1201 hres = IHTMLElement_get_offsetTop(elem, &l);
1202 ok_(__FILE__,line) (hres == S_OK, "get_offsetTop failed: %08x\n", hres);
1204 hres = IHTMLElement_get_offsetHeight(elem, &l);
1205 ok_(__FILE__,line) (hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
1207 hres = IHTMLElement_get_offsetWidth(elem, &l);
1208 ok_(__FILE__,line) (hres == S_OK, "get_offsetWidth failed: %08x\n", hres);
1210 hres = IHTMLElement_get_offsetLeft(elem, &l);
1211 ok_(__FILE__,line) (hres == S_OK, "get_offsetLeft failed: %08x\n", hres);
1213 hres = IHTMLElement_get_offsetParent(elem, &off_parent);
1214 ok_(__FILE__,line) (hres == S_OK, "get_offsetParent failed: %08x\n", hres);
1216 _test_elem_tag(line, (IUnknown*)off_parent, parent_tag);
1217 IHTMLElement_Release(off_parent);
1219 IHTMLElement_Release(elem);
1222 #define test_elem_source_index(a,b) _test_elem_source_index(__LINE__,a,b)
1223 static void _test_elem_source_index(unsigned line, IHTMLElement *elem, int index)
1225 LONG l = 0xdeadbeef;
1226 HRESULT hres;
1228 hres = IHTMLElement_get_sourceIndex(elem, &l);
1229 ok_(__FILE__,line)(hres == S_OK, "get_sourceIndex failed: %08x\n", hres);
1230 ok_(__FILE__,line)(l == index, "sourceIndex = %d, expected %d\n", l, index);
1233 #define get_doc_node(d) _get_doc_node(__LINE__,d)
1234 static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc)
1236 IHTMLWindow2 *window;
1237 IHTMLDocument2 *ret;
1238 HRESULT hres;
1240 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1241 ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1243 hres = IHTMLWindow2_get_document(window, &ret);
1244 ok_(__FILE__,line)(hres == S_OK, "get_document failed: %08x\n", hres);
1245 ok_(__FILE__,line)(ret != NULL, "document = NULL\n");
1247 return ret;
1250 #define test_window_name(d,e) _test_window_name(__LINE__,d,e)
1251 static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname)
1253 BSTR name;
1254 HRESULT hres;
1256 hres = IHTMLWindow2_get_name(window, &name);
1257 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1258 if(exname)
1259 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name));
1260 else
1261 ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name));
1262 SysFreeString(name);
1265 #define set_window_name(w,n) _set_window_name(__LINE__,w,n)
1266 static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name)
1268 BSTR str;
1269 HRESULT hres;
1271 str = a2bstr(name);
1272 hres = IHTMLWindow2_put_name(window, str);
1273 SysFreeString(str);
1274 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1276 _test_window_name(line, window, name);
1279 #define test_window_status(d) _test_window_status(__LINE__,d)
1280 static void _test_window_status(unsigned line, IHTMLWindow2 *window)
1282 BSTR status;
1283 HRESULT hres;
1285 status = (void*)0xdeadbeef;
1286 hres = IHTMLWindow2_get_status(window, &status);
1287 ok_(__FILE__,line)(hres == S_OK, "get_status failed: %08x\n", hres);
1288 ok_(__FILE__,line)(!status, "status = %s\n", wine_dbgstr_w(status));
1289 SysFreeString(status);
1292 #define set_window_status(w,n) _set_window_status(__LINE__,w,n)
1293 static void _set_window_status(unsigned line, IHTMLWindow2 *window, const char *status)
1295 BSTR str;
1296 HRESULT hres;
1298 str = a2bstr(status);
1299 hres = IHTMLWindow2_put_status(window, str);
1300 SysFreeString(str);
1301 ok_(__FILE__,line)(hres == S_OK, "put_status failed: %08x\n", hres);
1304 #define test_window_length(w,l) _test_window_length(__LINE__,w,l)
1305 static void _test_window_length(unsigned line, IHTMLWindow2 *window, LONG exlen)
1307 LONG length = -1;
1308 HRESULT hres;
1310 hres = IHTMLWindow2_get_length(window, &length);
1311 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
1312 ok_(__FILE__,line)(length == exlen, "length = %d, expected %d\n", length, exlen);
1315 #define get_frame_content_window(e) _get_frame_content_window(__LINE__,e)
1316 static IHTMLWindow2 *_get_frame_content_window(unsigned line, IUnknown *elem)
1318 IHTMLFrameBase2 *base2;
1319 IHTMLWindow2 *window;
1320 HRESULT hres;
1322 hres = IUnknown_QueryInterface(elem, &IID_IHTMLFrameBase2, (void**)&base2);
1323 ok(hres == S_OK, "Could not get IHTMFrameBase2 iface: %08x\n", hres);
1325 window = NULL;
1326 hres = IHTMLFrameBase2_get_contentWindow(base2, &window);
1327 IHTMLFrameBase2_Release(base2);
1328 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1329 ok(window != NULL, "contentWindow = NULL\n");
1331 return window;
1334 static void test_get_set_attr(IHTMLDocument2 *doc)
1336 IHTMLElement *elem;
1337 IHTMLDocument3 *doc3;
1338 HRESULT hres;
1339 BSTR bstr;
1340 VARIANT val;
1342 /* grab an element to test with */
1343 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1344 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1346 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1347 IHTMLDocument3_Release(doc3);
1348 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
1350 /* get a non-present attribute */
1351 bstr = a2bstr("notAnAttribute");
1352 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1353 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1354 ok(V_VT(&val) == VT_NULL, "variant type should have been VT_NULL (0x%x), was: 0x%x\n", VT_NULL, V_VT(&val));
1355 VariantClear(&val);
1356 SysFreeString(bstr);
1358 /* get a present attribute */
1359 bstr = a2bstr("scrollHeight");
1360 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1361 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1362 ok(V_VT(&val) == VT_I4, "variant type should have been VT_I4 (0x%x), was: 0x%x\n", VT_I4, V_VT(&val));
1363 VariantClear(&val);
1364 SysFreeString(bstr);
1366 /* create a new BSTR attribute */
1367 bstr = a2bstr("newAttribute");
1369 V_VT(&val) = VT_BSTR;
1370 V_BSTR(&val) = a2bstr("the value");
1371 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1372 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1373 VariantClear(&val);
1375 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1376 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1377 ok(V_VT(&val) == VT_BSTR, "variant type should have been VT_BSTR (0x%x), was: 0x%x\n", VT_BSTR, V_VT(&val));
1378 ok(strcmp_wa(V_BSTR(&val), "the value") == 0, "variant value should have been L\"the value\", was %s\n", wine_dbgstr_w(V_BSTR(&val)));
1379 VariantClear(&val);
1381 /* overwrite the attribute with a BOOL */
1382 V_VT(&val) = VT_BOOL;
1383 V_BOOL(&val) = VARIANT_TRUE;
1384 hres = IHTMLElement_setAttribute(elem, bstr, val, 0);
1385 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1386 VariantClear(&val);
1388 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1389 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1390 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1391 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1392 VariantClear(&val);
1394 SysFreeString(bstr);
1396 /* case-insensitive */
1397 bstr = a2bstr("newattribute");
1398 hres = IHTMLElement_getAttribute(elem, bstr, 0, &val);
1399 ok(hres == S_OK, "getAttribute failed: %08x\n", hres);
1400 ok(V_VT(&val) == VT_BOOL, "variant type should have been VT_BOOL (0x%x), was: 0x%x\n", VT_BOOL, V_VT(&val));
1401 ok(V_BOOL(&val) == VARIANT_TRUE, "variant value should have been VARIANT_TRUE (0x%x), was %d\n", VARIANT_TRUE, V_BOOL(&val));
1402 VariantClear(&val);
1403 SysFreeString(bstr);
1405 IHTMLElement_Release(elem);
1408 #define get_doc_elem(d) _get_doc_elem(__LINE__,d)
1409 static IHTMLElement *_get_doc_elem(unsigned line, IHTMLDocument2 *doc)
1411 IHTMLElement *elem;
1412 IHTMLDocument3 *doc3;
1413 HRESULT hres;
1415 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1416 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 interface: %08x\n", hres);
1417 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
1418 ok_(__FILE__,line) (hres == S_OK, "get_documentElement failed: %08x\n", hres);
1419 IHTMLDocument3_Release(doc3);
1421 return elem;
1424 #define test_anchor_href(a,h) _test_anchor_href(__LINE__,a,h)
1425 static void _test_anchor_href(unsigned line, IUnknown *unk, const char *exhref)
1427 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1428 BSTR str;
1429 HRESULT hres;
1431 hres = IHTMLAnchorElement_get_href(anchor, &str);
1432 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1433 ok_(__FILE__,line)(!strcmp_wa(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), exhref);
1434 SysFreeString(str);
1436 _test_disp_value(line, unk, exhref);
1439 #define test_anchor_put_href(a,h) _test_anchor_put_href(__LINE__,a,h)
1440 static void _test_anchor_put_href(unsigned line, IUnknown *unk, const char *exhref)
1442 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1443 BSTR str;
1444 HRESULT hres;
1446 str = a2bstr(exhref);
1447 hres = IHTMLAnchorElement_put_href(anchor, str);
1448 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
1449 SysFreeString(str);
1451 _test_disp_value(line, unk, exhref);
1454 #define test_anchor_rel(a,h) _test_anchor_rel(__LINE__,a,h)
1455 static void _test_anchor_rel(unsigned line, IUnknown *unk, const char *exrel)
1457 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1458 BSTR str;
1459 HRESULT hres;
1461 hres = IHTMLAnchorElement_get_rel(anchor, &str);
1462 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1463 if(exrel)
1464 ok_(__FILE__,line)(!strcmp_wa(str, exrel), "rel = %s, expected %s\n", wine_dbgstr_w(str), exrel);
1465 else
1466 ok_(__FILE__,line)(!str, "rel = %s, expected NULL\n", wine_dbgstr_w(str));
1467 SysFreeString(str);
1470 #define test_anchor_put_rel(a,h) _test_anchor_put_rel(__LINE__,a,h)
1471 static void _test_anchor_put_rel(unsigned line, IUnknown *unk, const char *exrel)
1473 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1474 BSTR str;
1475 HRESULT hres;
1477 str = a2bstr(exrel);
1478 hres = IHTMLAnchorElement_put_rel(anchor, str);
1479 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
1480 SysFreeString(str);
1483 #define test_anchor_get_target(a,h) _test_anchor_get_target(__LINE__,a,h)
1484 static void _test_anchor_get_target(unsigned line, IUnknown *unk, const char *target)
1486 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1487 BSTR str;
1488 HRESULT hres;
1490 hres = IHTMLAnchorElement_get_target(anchor, &str);
1491 ok_(__FILE__,line)(hres == S_OK, "get_target failed: %08x\n", hres);
1492 if(target)
1493 ok_(__FILE__,line)(!strcmp_wa(str, target), "target = %s, expected %s\n", wine_dbgstr_w(str), target);
1494 else
1495 ok_(__FILE__,line)(str == NULL, "target = %s, expected NULL\n", wine_dbgstr_w(str));
1496 SysFreeString(str);
1499 #define test_anchor_put_target(a,h) _test_anchor_put_target(__LINE__,a,h)
1500 static void _test_anchor_put_target(unsigned line, IUnknown *unk, const char *target)
1502 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1503 BSTR str;
1504 HRESULT hres;
1506 str = target ? a2bstr(target) : NULL;
1507 hres = IHTMLAnchorElement_put_target(anchor, str);
1508 ok_(__FILE__,line)(hres == S_OK, "put_target failed: %08x\n", hres);
1509 SysFreeString(str);
1512 #define test_anchor_name(a,h) _test_anchor_name(__LINE__,a,h)
1513 static void _test_anchor_name(unsigned line, IUnknown *unk, const char *name)
1515 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1516 BSTR str;
1517 HRESULT hres;
1519 hres = IHTMLAnchorElement_get_name(anchor, &str);
1520 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1521 if(name)
1522 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
1523 else
1524 ok_(__FILE__,line)(str == NULL, "name = %s, expected NULL\n", wine_dbgstr_w(str));
1525 SysFreeString(str);
1528 #define test_anchor_put_name(a,h) _test_anchor_put_name(__LINE__,a,h)
1529 static void _test_anchor_put_name(unsigned line, IUnknown *unk, const char *name)
1531 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1532 BSTR str;
1533 HRESULT hres;
1535 str = name ? a2bstr(name) : NULL;
1536 hres = IHTMLAnchorElement_put_name(anchor, str);
1537 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1538 SysFreeString(str);
1540 _test_anchor_name(line, unk, name);
1543 #define test_anchor_hostname(a,h) _test_anchor_hostname(__LINE__,a,h)
1544 static void _test_anchor_hostname(unsigned line, IUnknown *unk, const char *hostname)
1546 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1547 BSTR str;
1548 HRESULT hres;
1550 hres = IHTMLAnchorElement_get_hostname(anchor, &str);
1551 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1552 if(hostname)
1553 ok_(__FILE__,line)(!strcmp_wa(str, hostname), "hostname = %s, expected %s\n", wine_dbgstr_w(str), hostname);
1554 else
1555 ok_(__FILE__,line)(str == NULL, "hostname = %s, expected NULL\n", wine_dbgstr_w(str));
1556 SysFreeString(str);
1559 #define test_anchor_search(a,h,n) _test_anchor_search(__LINE__,a,h,n)
1560 static void _test_anchor_search(unsigned line, IUnknown *elem, const char *search, BOOL allowbroken)
1562 IHTMLAnchorElement *anchor = _get_anchor_iface(line, elem);
1563 BSTR str;
1564 HRESULT hres;
1566 hres = IHTMLAnchorElement_get_search(anchor, &str);
1567 ok_(__FILE__,line)(hres == S_OK, "get_search failed: %08x\n", hres);
1568 if ( ! str && allowbroken)
1569 win_skip("skip ie6 incorrect behavior\n");
1570 else if(search)
1571 ok_(__FILE__,line)(!strcmp_wa(str, search), "search = %s, expected %s\n", wine_dbgstr_w(str), search);
1572 else
1573 ok_(__FILE__,line)(!str, "search = %s, expected NULL\n", wine_dbgstr_w(str));
1574 SysFreeString(str);
1577 #define test_anchor_put_search(a,h) _test_anchor_put_search(__LINE__,a,h)
1578 static void _test_anchor_put_search(unsigned line, IUnknown *unk, const char *search)
1580 IHTMLAnchorElement *anchor = _get_anchor_iface(line, unk);
1581 BSTR str;
1582 HRESULT hres;
1584 str = search ? a2bstr(search) : NULL;
1585 hres = IHTMLAnchorElement_put_search(anchor, str);
1586 ok_(__FILE__,line)(hres == S_OK, "put_search failed: %08x\n", hres);
1587 SysFreeString(str);
1590 #define test_anchor_hash(a,h) _test_anchor_hash(__LINE__,a,h)
1591 static void _test_anchor_hash(unsigned line, IHTMLElement *elem, const char *exhash)
1593 IHTMLAnchorElement *anchor = _get_anchor_iface(line, (IUnknown*)elem);
1594 BSTR str;
1595 HRESULT hres;
1597 hres = IHTMLAnchorElement_get_hash(anchor, &str);
1598 ok_(__FILE__,line)(hres == S_OK, "get_hash failed: %08x\n", hres);
1599 if(exhash)
1600 ok_(__FILE__,line)(!strcmp_wa(str, exhash), "hash = %s, expected %s\n", wine_dbgstr_w(str), exhash);
1601 else
1602 ok_(__FILE__,line)(!str, "hash = %s, expected NULL\n", wine_dbgstr_w(str));
1603 SysFreeString(str);
1606 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
1607 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const char *text)
1609 BSTR bstr;
1610 HRESULT hres;
1612 hres = IHTMLOptionElement_get_text(option, &bstr);
1613 ok_(__FILE__,line) (hres == S_OK, "get_text failed: %08x\n", hres);
1614 ok_(__FILE__,line) (!strcmp_wa(bstr, text), "text=%s\n", wine_dbgstr_w(bstr));
1615 SysFreeString(bstr);
1618 #define test_option_put_text(o,t) _test_option_put_text(__LINE__,o,t)
1619 static void _test_option_put_text(unsigned line, IHTMLOptionElement *option, const char *text)
1621 BSTR bstr;
1622 HRESULT hres;
1624 bstr = a2bstr(text);
1625 hres = IHTMLOptionElement_put_text(option, bstr);
1626 SysFreeString(bstr);
1627 ok(hres == S_OK, "put_text failed: %08x\n", hres);
1629 _test_option_text(line, option, text);
1632 #define test_option_value(o,t) _test_option_value(__LINE__,o,t)
1633 static void _test_option_value(unsigned line, IHTMLOptionElement *option, const char *value)
1635 BSTR bstr;
1636 HRESULT hres;
1638 hres = IHTMLOptionElement_get_value(option, &bstr);
1639 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
1640 ok_(__FILE__,line) (!strcmp_wa(bstr, value), "value=%s\n", wine_dbgstr_w(bstr));
1641 SysFreeString(bstr);
1644 #define test_option_put_value(o,t) _test_option_put_value(__LINE__,o,t)
1645 static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, const char *value)
1647 BSTR bstr;
1648 HRESULT hres;
1650 bstr = a2bstr(value);
1651 hres = IHTMLOptionElement_put_value(option, bstr);
1652 SysFreeString(bstr);
1653 ok(hres == S_OK, "put_value failed: %08x\n", hres);
1655 _test_option_value(line, option, value);
1658 #define test_option_selected(o,s) _test_option_selected(__LINE__,o,s)
1659 static void _test_option_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
1661 VARIANT_BOOL b = 0x100;
1662 HRESULT hres;
1664 hres = IHTMLOptionElement_get_selected(option, &b);
1665 ok_(__FILE__,line)(hres == S_OK, "get_selected failed: %08x\n", hres);
1666 ok_(__FILE__,line)(b == ex, "selected = %x, expected %x\n", b, ex);
1669 #define test_option_put_selected(o,s) _test_option_put_selected(__LINE__,o,s)
1670 static void _test_option_put_selected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
1672 HRESULT hres;
1674 hres = IHTMLOptionElement_put_selected(option, b);
1675 ok_(__FILE__,line)(hres == S_OK, "put_selected failed: %08x\n", hres);
1676 _test_option_selected(line, option, b);
1679 #define test_option_get_index(o,s) _test_option_get_index(__LINE__,o,s)
1680 static void _test_option_get_index(unsigned line, IHTMLOptionElement *option, LONG exval)
1682 HRESULT hres;
1683 LONG val;
1685 hres = IHTMLOptionElement_get_index(option, NULL);
1686 ok_(__FILE__,line)(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
1688 val = 12345678;
1689 hres = IHTMLOptionElement_get_index(option, &val);
1690 ok_(__FILE__,line)(hres == S_OK, "get_index failed: %08x\n", hres);
1691 ok_(__FILE__,line)(val == exval || broken(val == 12345678), /* Win2k doesn't touch it*/
1692 "value = %d, expected = %d\n", val, exval);
1695 #define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
1696 static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
1698 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1699 BSTR value = (void*)0xdeadbeef;
1700 HRESULT hres;
1702 hres = IHTMLTextAreaElement_get_value(textarea, &value);
1703 IHTMLTextAreaElement_Release(textarea);
1704 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1705 if(exval)
1706 ok_(__FILE__,line)(!strcmp_wa(value, exval), "value = %s, expected %s\n", wine_dbgstr_w(value), exval);
1707 else
1708 ok_(__FILE__,line)(!value, "value = %p\n", value);
1709 SysFreeString(value);
1712 #define test_textarea_put_value(t,v) _test_textarea_put_value(__LINE__,t,v)
1713 static void _test_textarea_put_value(unsigned line, IUnknown *unk, const char *value)
1715 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1716 BSTR tmp = a2bstr(value);
1717 HRESULT hres;
1719 hres = IHTMLTextAreaElement_put_value(textarea, tmp);
1720 IHTMLTextAreaElement_Release(textarea);
1721 ok_(__FILE__,line)(hres == S_OK, "put_value failed: %08x\n", hres);
1722 SysFreeString(tmp);
1724 _test_textarea_value(line, unk, value);
1727 #define test_textarea_defaultvalue(t,v) _test_textarea_defaultvalue(__LINE__,t,v)
1728 static void _test_textarea_defaultvalue(unsigned line, IUnknown *unk, const char *exval)
1730 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1731 BSTR value = (void*)0xdeadbeef;
1732 HRESULT hres;
1734 hres = IHTMLTextAreaElement_get_defaultValue(textarea, &value);
1735 IHTMLTextAreaElement_Release(textarea);
1736 ok_(__FILE__,line)(hres == S_OK, "get_defaultValue failed: %08x\n", hres);
1737 if(exval)
1738 ok_(__FILE__,line)(!strcmp_wa(value, exval), "defaultValue = %s, expected %s\n", wine_dbgstr_w(value), exval);
1739 else
1740 ok_(__FILE__,line)(!value, "value = %p\n", value);
1741 SysFreeString(value);
1744 #define test_textarea_put_defaultvalue(t,v) _test_textarea_put_defaultvalue(__LINE__,t,v)
1745 static void _test_textarea_put_defaultvalue(unsigned line, IUnknown *unk, const char *value)
1747 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1748 BSTR tmp = a2bstr(value);
1749 HRESULT hres;
1751 hres = IHTMLTextAreaElement_put_defaultValue(textarea, tmp);
1752 IHTMLTextAreaElement_Release(textarea);
1753 ok_(__FILE__,line)(hres == S_OK, "put_defaultValue failed: %08x\n", hres);
1754 SysFreeString(tmp);
1756 _test_textarea_defaultvalue(line, unk, value);
1759 #define test_textarea_readonly(t,v) _test_textarea_readonly(__LINE__,t,v)
1760 static void _test_textarea_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL ex)
1762 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1763 VARIANT_BOOL b = 0x100;
1764 HRESULT hres;
1766 hres = IHTMLTextAreaElement_get_readOnly(textarea, &b);
1767 IHTMLTextAreaElement_Release(textarea);
1768 ok_(__FILE__,line)(hres == S_OK, "get_readOnly failed: %08x\n", hres);
1769 ok_(__FILE__,line)(b == ex, "readOnly = %x, expected %x\n", b, ex);
1772 #define test_textarea_put_readonly(t,v) _test_textarea_put_readonly(__LINE__,t,v)
1773 static void _test_textarea_put_readonly(unsigned line, IUnknown *unk, VARIANT_BOOL b)
1775 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1776 HRESULT hres;
1778 hres = IHTMLTextAreaElement_put_readOnly(textarea, b);
1779 IHTMLTextAreaElement_Release(textarea);
1780 ok_(__FILE__,line)(hres == S_OK, "put_readOnly failed: %08x\n", hres);
1782 _test_textarea_readonly(line, unk, b);
1785 #define test_textarea_type(t) _test_textarea_type(__LINE__,t)
1786 static void _test_textarea_type(unsigned line, IUnknown *unk)
1788 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1789 BSTR type = (void*)0xdeadbeef;
1790 HRESULT hres;
1792 hres = IHTMLTextAreaElement_get_type(textarea, &type);
1793 IHTMLTextAreaElement_Release(textarea);
1794 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1795 ok_(__FILE__,line)(!strcmp_wa(type, "textarea"), "type = %s, expected textarea\n", wine_dbgstr_w(type));
1796 SysFreeString(type);
1799 #define get_textarea_form(t) _get_textarea_form(__LINE__,t)
1800 static IHTMLFormElement *_get_textarea_form(unsigned line, IUnknown *unk)
1802 IHTMLTextAreaElement *textarea = _get_textarea_iface(line, unk);
1803 IHTMLFormElement *form;
1804 HRESULT hres;
1806 hres = IHTMLTextAreaElement_get_form(textarea, &form);
1807 IHTMLTextAreaElement_Release(textarea);
1808 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
1810 return form;
1813 #define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
1814 static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
1816 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1817 BSTR text;
1818 HRESULT hres;
1820 text = a2bstr(extext);
1821 hres = IHTMLCommentElement_get_text(comment, &text);
1822 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
1823 ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
1825 IHTMLCommentElement_Release(comment);
1826 SysFreeString(text);
1829 #define test_attr_specified(a,b) _test_attr_specified(__LINE__,a,b)
1830 static void _test_attr_specified(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
1832 VARIANT_BOOL specified;
1833 HRESULT hres;
1835 hres = IHTMLDOMAttribute_get_specified(attr, &specified);
1836 ok_(__FILE__,line)(hres == S_OK, "get_specified failed: %08x\n", hres);
1837 ok_(__FILE__,line)(specified == expected, "specified = %x, expected %x\n", specified, expected);
1840 #define test_attr_expando(a,b) _test_attr_expando(__LINE__,a,b)
1841 static void _test_attr_expando(unsigned line, IHTMLDOMAttribute *attr, VARIANT_BOOL expected)
1843 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
1844 VARIANT_BOOL expando;
1845 HRESULT hres;
1847 hres = IHTMLDOMAttribute2_get_expando(attr2, &expando);
1848 ok_(__FILE__,line)(hres == S_OK, "get_expando failed: %08x\n", hres);
1849 ok_(__FILE__,line)(expando == expected, "expando = %x, expected %x\n", expando, expected);
1851 IHTMLDOMAttribute2_Release(attr2);
1854 #define test_attr_value(a,b) _test_attr_value(__LINE__,a,b)
1855 static void _test_attr_value(unsigned line, IHTMLDOMAttribute *attr, const char *exval)
1857 IHTMLDOMAttribute2 *attr2 = _get_attr2_iface(line, (IUnknown*)attr);
1858 BSTR val;
1859 HRESULT hres;
1861 hres = IHTMLDOMAttribute2_get_value(attr2, &val);
1862 ok_(__FILE__,line)(hres == S_OK, "get_value failed: %08x\n", hres);
1863 if(exval)
1864 ok_(__FILE__,line)(!strcmp_wa(val, exval), "value = %s, expected %s\n", wine_dbgstr_w(val), exval);
1865 else
1866 ok_(__FILE__,line)(!val, "value = %s, expected NULL\n", wine_dbgstr_w(val));
1868 IHTMLDOMAttribute2_Release(attr2);
1869 SysFreeString(val);
1872 #define test_comment_attrs(c) _test_comment_attrs(__LINE__,c)
1873 static void _test_comment_attrs(unsigned line, IUnknown *unk)
1875 IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
1876 IHTMLElement *elem = _get_elem_iface(__LINE__,unk);
1877 IHTMLElement4 *elem4 = _get_elem4_iface(__LINE__,unk);
1878 IHTMLDOMAttribute *attr;
1879 BSTR name = a2bstr("test");
1880 VARIANT val;
1881 HRESULT hres;
1883 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1884 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1885 ok(attr == NULL, "attr != NULL\n");
1887 V_VT(&val) = VT_I4;
1888 V_I4(&val) = 1234;
1889 hres = IHTMLElement_setAttribute(elem, name, val, 0);
1890 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
1892 hres = IHTMLElement4_getAttributeNode(elem4, name, &attr);
1893 ok(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
1894 ok(attr != NULL, "attr == NULL\n");
1896 test_attr_expando(attr, VARIANT_TRUE);
1898 IHTMLDOMAttribute_Release(attr);
1899 IHTMLCommentElement_Release(comment);
1900 IHTMLElement_Release(elem);
1901 IHTMLElement4_Release(elem4);
1902 SysFreeString(name);
1905 #define test_object_vspace(u,s) _test_object_vspace(__LINE__,u,s)
1906 static void _test_object_vspace(unsigned line, IUnknown *unk, LONG exl)
1908 IHTMLObjectElement *object = _get_object_iface(line, unk);
1909 LONG l;
1910 HRESULT hres;
1912 l = 0xdeadbeef;
1913 hres = IHTMLObjectElement_get_vspace(object, &l);
1914 ok_(__FILE__,line)(hres == S_OK, "get_vspace failed: %08x\n", hres);
1915 ok_(__FILE__,line)(l == exl, "vspace=%d, expected %d\n", l, exl);
1916 IHTMLObjectElement_Release(object);
1919 #define test_object_name(a,b) _test_object_name(__LINE__,a,b)
1920 static void _test_object_name(unsigned line, IHTMLElement *elem, const char *exname)
1922 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1923 BSTR str;
1924 HRESULT hres;
1926 str = (void*)0xdeadbeef;
1927 hres = IHTMLObjectElement_get_name(object, &str);
1928 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
1929 if(exname)
1930 ok_(__FILE__,line)(!strcmp_wa(str, exname), "name=%s, expected %s\n", wine_dbgstr_w(str), exname);
1931 else
1932 ok_(__FILE__,line)(!str, "name=%s, expected NULL\n", wine_dbgstr_w(str));
1933 SysFreeString(str);
1934 IHTMLObjectElement_Release(object);
1937 #define set_object_name(a,b) _set_object_name(__LINE__,a,b)
1938 static void _set_object_name(unsigned line, IHTMLElement *elem, const char *name)
1940 IHTMLObjectElement *object = _get_object_iface(line, (IUnknown*)elem);
1941 BSTR str;
1942 HRESULT hres;
1944 str = a2bstr(name);
1945 hres = IHTMLObjectElement_put_name(object, str);
1946 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
1947 SysFreeString(str);
1948 IHTMLObjectElement_Release(object);
1950 _test_object_name(line, elem, name);
1953 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
1954 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
1955 const char *txt, const char *val)
1957 IHTMLOptionElementFactory *factory;
1958 IHTMLOptionElement *option;
1959 IHTMLWindow2 *window;
1960 VARIANT text, value, empty;
1961 HRESULT hres;
1963 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1964 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
1966 hres = IHTMLWindow2_get_Option(window, &factory);
1967 IHTMLWindow2_Release(window);
1968 ok_(__FILE__,line) (hres == S_OK, "get_Option failed: %08x\n", hres);
1970 test_disp((IUnknown*)factory, &IID_IHTMLOptionElementFactory, "[object]");
1972 V_VT(&text) = VT_BSTR;
1973 V_BSTR(&text) = a2bstr(txt);
1974 V_VT(&value) = VT_BSTR;
1975 V_BSTR(&value) = a2bstr(val);
1976 V_VT(&empty) = VT_EMPTY;
1978 hres = IHTMLOptionElementFactory_create(factory, text, value, empty, empty, &option);
1979 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
1981 IHTMLOptionElementFactory_Release(factory);
1982 VariantClear(&text);
1983 VariantClear(&value);
1985 _test_option_text(line, option, txt);
1986 _test_option_value(line, option, val);
1987 _test_option_selected(line, option, VARIANT_FALSE);
1989 return option;
1992 #define test_img_width(o,w) _test_img_width(__LINE__,o,w)
1993 static void _test_img_width(unsigned line, IHTMLImgElement *img, const LONG exp)
1995 LONG found = -1;
1996 HRESULT hres;
1998 hres = IHTMLImgElement_get_width(img, &found);
1999 ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
2000 ok_(__FILE__,line) (found == exp, "width=%d\n", found);
2003 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
2004 static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const LONG width)
2006 HRESULT hres;
2008 hres = IHTMLImgElement_put_width(img, width);
2009 ok(hres == S_OK, "put_width failed: %08x\n", hres);
2011 _test_img_width(line, img, width);
2014 #define test_img_height(o,h) _test_img_height(__LINE__,o,h)
2015 static void _test_img_height(unsigned line, IHTMLImgElement *img, const LONG exp)
2017 LONG found = -1;
2018 HRESULT hres;
2020 hres = IHTMLImgElement_get_height(img, &found);
2021 ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
2022 ok_(__FILE__,line) (found == exp, "height=%d\n", found);
2025 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
2026 static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const LONG height)
2028 HRESULT hres;
2030 hres = IHTMLImgElement_put_height(img, height);
2031 ok(hres == S_OK, "put_height failed: %08x\n", hres);
2033 _test_img_height(line, img, height);
2036 #define create_img_elem(d,t,v) _create_img_elem(__LINE__,d,t,v)
2037 static IHTMLImgElement *_create_img_elem(unsigned line, IHTMLDocument2 *doc,
2038 LONG wdth, LONG hght)
2040 IHTMLImageElementFactory *factory;
2041 IHTMLImgElement *img;
2042 IHTMLWindow2 *window;
2043 VARIANT width, height;
2044 char buf[16];
2045 HRESULT hres;
2047 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2048 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2050 hres = IHTMLWindow2_get_Image(window, &factory);
2051 IHTMLWindow2_Release(window);
2052 ok_(__FILE__,line) (hres == S_OK, "get_Image failed: %08x\n", hres);
2054 test_ifaces((IUnknown*)factory, img_factory_iids);
2055 test_disp((IUnknown*)factory, &IID_IHTMLImageElementFactory, "[object]");
2057 if(wdth >= 0){
2058 snprintf(buf, 16, "%d", wdth);
2059 V_VT(&width) = VT_BSTR;
2060 V_BSTR(&width) = a2bstr(buf);
2061 }else{
2062 V_VT(&width) = VT_EMPTY;
2063 wdth = 0;
2066 if(hght >= 0){
2067 snprintf(buf, 16, "%d", hght);
2068 V_VT(&height) = VT_BSTR;
2069 V_BSTR(&height) = a2bstr(buf);
2070 }else{
2071 V_VT(&height) = VT_EMPTY;
2072 hght = 0;
2075 hres = IHTMLImageElementFactory_create(factory, width, height, &img);
2076 ok_(__FILE__,line) (hres == S_OK, "create failed: %08x\n", hres);
2078 IHTMLImageElementFactory_Release(factory);
2079 VariantClear(&width);
2080 VariantClear(&height);
2082 if(SUCCEEDED(hres)) {
2083 _test_img_width(line, img, wdth);
2084 _test_img_height(line, img, hght);
2085 return img;
2088 return NULL;
2091 #define test_select_length(s,l) _test_select_length(__LINE__,s,l)
2092 static void _test_select_length(unsigned line, IHTMLSelectElement *select, LONG length)
2094 LONG len = 0xdeadbeef;
2095 HRESULT hres;
2097 hres = IHTMLSelectElement_get_length(select, &len);
2098 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2099 ok_(__FILE__,line) (len == length, "len=%d, expected %d\n", len, length);
2102 #define test_select_put_length(s,l) _test_select_put_length(__LINE__,s,l)
2103 static void _test_select_put_length(unsigned line, IUnknown *unk, LONG length)
2105 IHTMLSelectElement *select = _get_select_iface(line, unk);
2106 HRESULT hres;
2108 hres = IHTMLSelectElement_put_length(select, length);
2109 ok_(__FILE__,line) (hres == S_OK, "put_length failed: %08x\n", hres);
2110 _test_select_length(line, select, length);
2111 IHTMLSelectElement_Release(select);
2114 #define test_select_selidx(s,i) _test_select_selidx(__LINE__,s,i)
2115 static void _test_select_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
2117 LONG idx = 0xdeadbeef;
2118 HRESULT hres;
2120 hres = IHTMLSelectElement_get_selectedIndex(select, &idx);
2121 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
2122 ok_(__FILE__,line) (idx == index, "idx=%d, expected %d\n", idx, index);
2125 #define test_select_put_selidx(s,i) _test_select_put_selidx(__LINE__,s,i)
2126 static void _test_select_put_selidx(unsigned line, IHTMLSelectElement *select, LONG index)
2128 HRESULT hres;
2130 hres = IHTMLSelectElement_put_selectedIndex(select, index);
2131 ok_(__FILE__,line) (hres == S_OK, "get_selectedIndex failed: %08x\n", hres);
2132 _test_select_selidx(line, select, index);
2135 #define test_select_value(s,v) _test_select_value(__LINE__,s,v)
2136 static void _test_select_value(unsigned line, IHTMLSelectElement *select, const char *exval)
2138 BSTR val;
2139 HRESULT hres;
2141 hres = IHTMLSelectElement_get_value(select, &val);
2142 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
2143 if(exval)
2144 ok_(__FILE__,line) (!strcmp_wa(val, exval), "unexpected value %s\n", wine_dbgstr_w(val));
2145 else
2146 ok_(__FILE__,line) (val == NULL, "val=%s, expected NULL\n", wine_dbgstr_w(val));
2147 SysFreeString(val);
2150 #define test_select_set_value(s,v) _test_select_set_value(__LINE__,s,v)
2151 static void _test_select_set_value(unsigned line, IHTMLSelectElement *select, const char *val)
2153 BSTR bstr;
2154 HRESULT hres;
2156 bstr = a2bstr(val);
2157 hres = IHTMLSelectElement_put_value(select, bstr);
2158 SysFreeString(bstr);
2159 ok_(__FILE__,line) (hres == S_OK, "put_value failed: %08x\n", hres);
2162 #define test_select_type(s,t) _test_select_type(__LINE__,s,t)
2163 static void _test_select_type(unsigned line, IHTMLSelectElement *select, const char *extype)
2165 BSTR type;
2166 HRESULT hres;
2168 hres = IHTMLSelectElement_get_type(select, &type);
2169 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
2170 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
2171 SysFreeString(type);
2174 #define test_select_multiple(s,t) _test_select_multiple(__LINE__,s,t)
2175 static void _test_select_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exmultiple)
2177 VARIANT_BOOL b = 100;
2178 HRESULT hres;
2180 hres = IHTMLSelectElement_get_multiple(select, &b);
2181 ok_(__FILE__,line) (hres == S_OK, "get_multiple failed: %08x\n", hres);
2182 ok_(__FILE__,line) (b == exmultiple, "multiple=%x, expected %x\n", b, exmultiple);
2185 #define test_select_set_multiple(s,v) _test_select_set_multiple(__LINE__,s,v)
2186 static void _test_select_set_multiple(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL val)
2188 HRESULT hres;
2190 hres = IHTMLSelectElement_put_multiple(select, val);
2191 ok_(__FILE__,line) (hres == S_OK, "put_multiple failed: %08x\n", hres);
2193 _test_select_multiple(line, select, val);
2196 #define test_select_size(s,v) _test_select_size(__LINE__,s,v)
2197 static void _test_select_size(unsigned line, IHTMLSelectElement *select, LONG exval)
2199 HRESULT hres;
2200 LONG val;
2202 hres = IHTMLSelectElement_get_size(select, NULL);
2203 ok_(__FILE__,line) (hres == E_INVALIDARG, "got %08x, expected E_INVALIDARG\n", hres);
2205 val = 0xdeadbeef;
2206 hres = IHTMLSelectElement_get_size(select, &val);
2207 ok_(__FILE__,line) (hres == S_OK, "get_size failed: %08x\n", hres);
2208 ok_(__FILE__,line) (val == exval, "size = %d, expected %d\n", val, exval);
2211 #define test_select_set_size(s,v,e) _test_select_set_size(__LINE__,s,v,e)
2212 static void _test_select_set_size(unsigned line, IHTMLSelectElement *select, LONG val, HRESULT exhres)
2214 HRESULT hres;
2216 hres = IHTMLSelectElement_put_size(select, val);
2217 ok_(__FILE__,line) (hres == exhres, "put_size(%d) got %08x, expect %08x\n", val, hres, exhres);
2220 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
2221 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
2223 BSTR text;
2224 HRESULT hres;
2226 hres = IHTMLTxtRange_get_text(range, &text);
2227 ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
2229 if(extext) {
2230 ok_(__FILE__, line) (text != NULL, "text == NULL\n");
2231 ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=%s, expected %s\n", wine_dbgstr_w(text), extext);
2232 }else {
2233 ok_(__FILE__, line) (text == NULL, "text=%s, expected NULL\n", wine_dbgstr_w(text));
2236 SysFreeString(text);
2240 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
2241 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
2243 HRESULT hres;
2245 hres = IHTMLTxtRange_collapse(range, b);
2246 ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
2247 _test_range_text(line, range, NULL);
2250 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
2251 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
2252 VARIANT_BOOL exb, const char *extext)
2254 VARIANT_BOOL b = 0xe0e0;
2255 HRESULT hres;
2257 hres = IHTMLTxtRange_expand(range, unit, &b);
2258 ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
2259 ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
2260 _test_range_text(line, range, extext);
2263 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
2264 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2266 LONG c = 0xdeadbeef;
2267 HRESULT hres;
2269 hres = IHTMLTxtRange_move(range, unit, cnt, &c);
2270 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2271 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2272 _test_range_text(line, range, NULL);
2275 #define test_range_movestart(r,u,c,e) _test_range_movestart(__LINE__,r,u,c,e)
2276 static void _test_range_movestart(unsigned line, IHTMLTxtRange *range,
2277 LPWSTR unit, LONG cnt, LONG excnt)
2279 LONG c = 0xdeadbeef;
2280 HRESULT hres;
2282 hres = IHTMLTxtRange_moveStart(range, unit, cnt, &c);
2283 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2284 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2287 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
2288 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, LONG cnt, LONG excnt)
2290 LONG c = 0xdeadbeef;
2291 HRESULT hres;
2293 hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
2294 ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
2295 ok_(__FILE__,line) (c == excnt, "count=%d, expected %d\n", c, excnt);
2298 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
2299 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, const char *text)
2301 HRESULT hres;
2302 BSTR bstr = a2bstr(text);
2304 hres = IHTMLTxtRange_put_text(range, bstr);
2305 ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
2306 SysFreeString(bstr);
2307 _test_range_text(line, range, NULL);
2310 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
2311 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2313 VARIANT_BOOL b;
2314 HRESULT hres;
2316 b = 0xe0e0;
2317 hres = IHTMLTxtRange_inRange(range1, range2, &b);
2318 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2319 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2322 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
2323 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
2325 VARIANT_BOOL b;
2326 HRESULT hres;
2328 b = 0xe0e0;
2329 hres = IHTMLTxtRange_isEqual(range1, range2, &b);
2330 ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
2331 ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
2333 b = 0xe0e0;
2334 hres = IHTMLTxtRange_isEqual(range2, range1, &b);
2335 ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
2336 ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
2338 if(exb) {
2339 test_range_inrange(range1, range2, VARIANT_TRUE);
2340 test_range_inrange(range2, range1, VARIANT_TRUE);
2344 #define test_range_paste_html(a,b) _test_range_paste_html(__LINE__,a,b)
2345 static void _test_range_paste_html(unsigned line, IHTMLTxtRange *range, const char *html)
2347 BSTR str = a2bstr(html);
2348 HRESULT hres;
2350 hres = IHTMLTxtRange_pasteHTML(range, str);
2351 ok_(__FILE__,line)(hres == S_OK, "pasteHTML failed: %08x\n", hres);
2352 SysFreeString(str);
2355 #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t)
2356 static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type)
2358 IHTMLElement *elem;
2359 HRESULT hres;
2361 hres = IHTMLTxtRange_parentElement(range, &elem);
2362 ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres);
2364 _test_elem_type(line, (IUnknown*)elem, type);
2366 IHTMLElement_Release(elem);
2369 #define get_elem_col_item_idx(a,b) _get_elem_col_item_idx(__LINE__,a,b)
2370 static IHTMLElement *_get_elem_col_item_idx(unsigned line, IHTMLElementCollection *col, int i)
2372 VARIANT name, index;
2373 IHTMLElement *elem;
2374 IDispatch *disp;
2375 HRESULT hres;
2377 V_VT(&index) = VT_EMPTY;
2378 V_VT(&name) = VT_I4;
2379 V_I4(&name) = i;
2380 hres = IHTMLElementCollection_item(col, name, index, &disp);
2381 ok_(__FILE__,line)(hres == S_OK, "item failed: %08x\n", hres);
2382 ok_(__FILE__,line)(disp != NULL, "disp == NULL\n");
2384 elem = _get_elem_iface(line, (IUnknown*)disp);
2385 IDispatch_Release(disp);
2386 return elem;
2389 #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l)
2390 static void _test_elem_collection(unsigned line, IUnknown *unk,
2391 const elem_type_t *elem_types, LONG exlen)
2393 IHTMLElementCollection *col;
2394 IEnumVARIANT *enum_var;
2395 IUnknown *enum_unk;
2396 ULONG fetched;
2397 LONG len;
2398 DWORD i;
2399 VARIANT name, index, v, vs[5];
2400 IDispatch *disp, *disp2;
2401 HRESULT hres;
2403 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col);
2404 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres);
2406 test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection, "[object]");
2408 hres = IHTMLElementCollection_get_length(col, &len);
2409 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
2410 ok_(__FILE__,line) (len == exlen, "len=%d, expected %d\n", len, exlen);
2412 if(len > exlen)
2413 len = exlen;
2415 V_VT(&index) = VT_EMPTY;
2417 hres = IHTMLElementCollection_get__newEnum(col, &enum_unk);
2418 ok_(__FILE__,line)(hres == S_OK, "_newEnum failed: %08x\n", hres);
2420 hres = IUnknown_QueryInterface(enum_unk, &IID_IEnumVARIANT, (void**)&enum_var);
2421 IUnknown_Release(enum_unk);
2422 ok_(__FILE__,line)(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
2424 for(i=0; i<len; i++) {
2425 V_VT(&name) = VT_I4;
2426 V_I4(&name) = i;
2427 disp = (void*)0xdeadbeef;
2428 hres = IHTMLElementCollection_item(col, name, index, &disp);
2429 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2430 ok_(__FILE__,line) (disp != NULL, "item returned NULL\n");
2431 if(FAILED(hres) || !disp)
2432 continue;
2434 _test_elem_type(line, (IUnknown*)disp, elem_types[i]);
2436 if(!i) {
2437 V_VT(&name) = VT_UINT;
2438 V_I4(&name) = 0;
2439 disp2 = (void*)0xdeadbeef;
2440 hres = IHTMLElementCollection_item(col, name, index, &disp2);
2441 ok_(__FILE__,line) (hres == S_OK, "item(%d) failed: %08x\n", i, hres);
2442 ok_(__FILE__,line) (iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
2443 if(disp2)
2444 IDispatch_Release(disp2);
2447 fetched = 0;
2448 V_VT(&v) = VT_ERROR;
2449 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
2450 ok_(__FILE__,line)(hres == S_OK, "Next failed: %08x\n", hres);
2451 if(i)
2452 ok_(__FILE__,line)(fetched == 1, "fetched = %d\n", fetched);
2453 ok_(__FILE__,line)(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
2454 ok_(__FILE__,line)(iface_cmp((IUnknown*)disp, (IUnknown*)V_DISPATCH(&v)), "disp != V_DISPATCH(v)\n");
2455 IDispatch_Release(V_DISPATCH(&v));
2457 IDispatch_Release(disp);
2460 fetched = 0xdeadbeef;
2461 V_VT(&v) = VT_BOOL;
2462 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
2463 ok_(__FILE__,line)(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
2464 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2465 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2467 hres = IEnumVARIANT_Reset(enum_var);
2468 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2470 fetched = 0xdeadbeef;
2471 V_VT(&v) = VT_BOOL;
2472 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
2473 ok_(__FILE__,line)(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
2474 ok_(__FILE__,line)(fetched == 0, "fetched = %d\n", fetched);
2475 ok_(__FILE__,line)(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
2477 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
2478 ok_(__FILE__,line)(hres == S_OK, "Skip failed: %08x\n", hres);
2480 memset(vs, 0, sizeof(vs));
2481 fetched = 0;
2482 hres = IEnumVARIANT_Next(enum_var, sizeof(vs)/sizeof(*vs), vs, &fetched);
2483 ok_(__FILE__,line)(hres == S_FALSE, "Next failed: %08x\n", hres);
2484 ok_(__FILE__,line)(fetched == (len > 2 ? 2 : len), "fetched = %d\n", fetched);
2485 if(len) {
2486 ok_(__FILE__,line)(V_VT(vs) == VT_DISPATCH && V_DISPATCH(vs), "V_VT(vs[0]) = %d\n", V_VT(vs));
2487 IDispatch_Release(V_DISPATCH(vs));
2489 if(len > 1) {
2490 ok_(__FILE__,line)(V_VT(vs+1) == VT_DISPATCH && V_DISPATCH(vs+1), "V_VT(vs[1]) = %d\n", V_VT(vs+1));
2491 IDispatch_Release(V_DISPATCH(vs+1));
2494 hres = IEnumVARIANT_Reset(enum_var);
2495 ok_(__FILE__,line)(hres == S_OK, "Reset failed: %08x\n", hres);
2497 hres = IEnumVARIANT_Skip(enum_var, len+1);
2498 ok_(__FILE__,line)(hres == S_FALSE, "Skip failed: %08x\n", hres);
2500 IEnumVARIANT_Release(enum_var);
2502 V_VT(&name) = VT_I4;
2503 V_I4(&name) = len;
2504 disp = (void*)0xdeadbeef;
2505 hres = IHTMLElementCollection_item(col, name, index, &disp);
2506 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2507 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2509 V_VT(&name) = VT_UI4;
2510 V_I4(&name) = len;
2511 disp = (void*)0xdeadbeef;
2512 hres = IHTMLElementCollection_item(col, name, index, &disp);
2513 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2514 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2516 V_VT(&name) = VT_INT;
2517 V_I4(&name) = len;
2518 disp = (void*)0xdeadbeef;
2519 hres = IHTMLElementCollection_item(col, name, index, &disp);
2520 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2521 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2523 V_VT(&name) = VT_UINT;
2524 V_I4(&name) = len;
2525 disp = (void*)0xdeadbeef;
2526 hres = IHTMLElementCollection_item(col, name, index, &disp);
2527 ok_(__FILE__,line) (hres == S_OK, "item failed: %08x\n", hres);
2528 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2530 V_VT(&name) = VT_I4;
2531 V_I4(&name) = -1;
2532 disp = (void*)0xdeadbeef;
2533 hres = IHTMLElementCollection_item(col, name, index, &disp);
2534 ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
2535 ok_(__FILE__,line) (disp == NULL, "disp != NULL\n");
2537 IHTMLElementCollection_Release(col);
2540 #define test_elem_all(c,t,l) _test_elem_all(__LINE__,c,t,l)
2541 static void _test_elem_all(unsigned line, IUnknown *unk, const elem_type_t *elem_types, LONG exlen)
2543 IHTMLElement *elem = _get_elem_iface(line, unk);
2544 IDispatch *disp;
2545 HRESULT hres;
2547 hres = IHTMLElement_get_all(elem, &disp);
2548 IHTMLElement_Release(elem);
2549 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2551 _test_elem_collection(line, (IUnknown*)disp, elem_types, exlen);
2552 IDispatch_Release(disp);
2555 #define test_doc_all(a,b,c) _test_doc_all(__LINE__,a,b,c)
2556 static void _test_doc_all(unsigned line, IHTMLDocument2 *doc, const elem_type_t *elem_types, LONG exlen)
2558 IHTMLElementCollection *col;
2559 HRESULT hres;
2561 hres = IHTMLDocument2_get_all(doc, &col);
2562 ok_(__FILE__,line)(hres == S_OK, "get_all failed: %08x\n", hres);
2564 _test_elem_collection(line, (IUnknown*)col, elem_types, exlen);
2565 IHTMLElementCollection_Release(col);
2568 #define test_elem_getelembytag(a,b,c,d) _test_elem_getelembytag(__LINE__,a,b,c,d)
2569 static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t type, LONG exlen, IHTMLElement **ret)
2571 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2572 IHTMLElementCollection *col = NULL;
2573 elem_type_t *types = NULL;
2574 BSTR tmp;
2575 int i;
2576 HRESULT hres;
2578 tmp = a2bstr(elem_type_infos[type].tag);
2579 hres = IHTMLElement2_getElementsByTagName(elem, tmp, &col);
2580 SysFreeString(tmp);
2581 IHTMLElement2_Release(elem);
2582 ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
2583 ok_(__FILE__,line) (col != NULL, "col == NULL\n");
2585 if(exlen) {
2586 types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
2587 for(i=0; i<exlen; i++)
2588 types[i] = type;
2591 _test_elem_collection(line, (IUnknown*)col, types, exlen);
2593 HeapFree(GetProcessHeap(), 0, types);
2595 if(ret)
2596 *ret = get_elem_col_item_idx(col, 0);
2597 IHTMLElementCollection_Release(col);
2600 #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
2601 static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
2603 BSTR text = NULL;
2604 HRESULT hres;
2606 hres = IHTMLElement_get_innerText(elem, &text);
2607 ok_(__FILE__,line) (hres == S_OK, "get_innerText failed: %08x\n", hres);
2608 if(extext)
2609 ok_(__FILE__,line) (!strcmp_wa(text, extext), "get_innerText returned %s expected %s\n",
2610 wine_dbgstr_w(text), extext);
2611 else
2612 ok_(__FILE__,line) (!text, "get_innerText returned %s expected NULL\n", wine_dbgstr_w(text));
2613 SysFreeString(text);
2616 #define test_elem_set_innertext(e,t) _test_elem_set_innertext(__LINE__,e,t)
2617 static void _test_elem_set_innertext(unsigned line, IHTMLElement *elem, const char *text)
2619 IHTMLDOMChildrenCollection *col;
2620 BSTR str;
2621 HRESULT hres;
2623 str = a2bstr(text);
2624 hres = IHTMLElement_put_innerText(elem, str);
2625 ok_(__FILE__,line) (hres == S_OK, "put_innerText failed: %08x\n", hres);
2626 SysFreeString(str);
2628 _test_elem_innertext(line, elem, text);
2631 col = _get_child_nodes(line, (IUnknown*)elem);
2632 ok(col != NULL, "col == NULL\n");
2633 if(col) {
2634 LONG length = 0, type;
2635 IHTMLDOMNode *node;
2637 hres = IHTMLDOMChildrenCollection_get_length(col, &length);
2638 ok(hres == S_OK, "get_length failed: %08x\n", hres);
2639 ok(length == 1, "length = %d\n", length);
2641 node = _get_child_item(line, col, 0);
2642 ok(node != NULL, "node == NULL\n");
2643 if(node) {
2644 type = _get_node_type(line, (IUnknown*)node);
2645 ok(type == 3, "type=%d\n", type);
2646 IHTMLDOMNode_Release(node);
2649 IHTMLDOMChildrenCollection_Release(col);
2654 #define test_elem_innerhtml(e,t) _test_elem_innerhtml(__LINE__,e,t)
2655 static void _test_elem_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2657 IHTMLElement *elem = _get_elem_iface(line, unk);
2658 BSTR html;
2659 HRESULT hres;
2661 hres = IHTMLElement_get_innerHTML(elem, &html);
2662 ok_(__FILE__,line)(hres == S_OK, "get_innerHTML failed: %08x\n", hres);
2663 if(inner_html)
2664 ok_(__FILE__,line)(!strcmp_wa(html, inner_html), "unexpected innerHTML: %s\n", wine_dbgstr_w(html));
2665 else
2666 ok_(__FILE__,line)(!html, "innerHTML = %s\n", wine_dbgstr_w(html));
2668 IHTMLElement_Release(elem);
2669 SysFreeString(html);
2672 #define test_elem_set_innerhtml(e,t) _test_elem_set_innerhtml(__LINE__,e,t)
2673 static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *inner_html)
2675 IHTMLElement *elem = _get_elem_iface(line, unk);
2676 BSTR html;
2677 HRESULT hres;
2679 html = a2bstr(inner_html);
2680 hres = IHTMLElement_put_innerHTML(elem, html);
2681 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
2683 IHTMLElement_Release(elem);
2684 SysFreeString(html);
2687 #define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
2688 static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2690 IHTMLElement *elem = _get_elem_iface(line, unk);
2691 BSTR html;
2692 HRESULT hres;
2694 html = a2bstr(outer_html);
2695 hres = IHTMLElement_put_outerHTML(elem, html);
2696 ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
2698 IHTMLElement_Release(elem);
2699 SysFreeString(html);
2702 #define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
2703 static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
2705 IHTMLElement *elem = _get_elem_iface(line, unk);
2706 BSTR html;
2707 HRESULT hres;
2709 hres = IHTMLElement_get_outerHTML(elem, &html);
2710 ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
2711 ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
2713 IHTMLElement_Release(elem);
2714 SysFreeString(html);
2717 #define test_elem_contains(a,b,c) _test_elem_contains(__LINE__,a,b,c)
2718 static void _test_elem_contains(unsigned line, IHTMLElement *elem, IHTMLElement *elem2, VARIANT_BOOL exval)
2720 VARIANT_BOOL b;
2721 HRESULT hres;
2723 b = 100;
2724 hres = IHTMLElement_contains(elem, elem2, &b);
2725 ok_(__FILE__,line)(hres == S_OK, "contains failed: %08x\n", hres);
2726 ok_(__FILE__,line)(b == exval, "contains returned %x, expected %x\n", b, exval);
2729 #define test_elem_istextedit(a,b) _test_elem_istextedit(__LINE__,a,b)
2730 static void _test_elem_istextedit(unsigned line, IHTMLElement *elem, VARIANT_BOOL exval)
2732 VARIANT_BOOL b;
2733 HRESULT hres;
2735 b = 100;
2736 hres = IHTMLElement_get_isTextEdit(elem, &b);
2737 ok_(__FILE__,line)(hres == S_OK, "isTextEdit failed: %08x\n", hres);
2738 ok_(__FILE__,line)(b == exval, "isTextEdit = %x\n", b);
2741 #define get_first_child(n) _get_first_child(__LINE__,n)
2742 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
2744 IHTMLDOMNode *node = _get_node_iface(line, unk);
2745 IHTMLDOMNode *child = NULL;
2746 HRESULT hres;
2748 hres = IHTMLDOMNode_get_firstChild(node, &child);
2749 IHTMLDOMNode_Release(node);
2750 ok_(__FILE__,line) (hres == S_OK, "get_firstChild failed: %08x\n", hres);
2752 return child;
2755 #define test_node_has_child(u,b) _test_node_has_child(__LINE__,u,b)
2756 static void _test_node_has_child(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2758 IHTMLDOMNode *node = _get_node_iface(line, unk);
2759 VARIANT_BOOL b = 0xdead;
2760 HRESULT hres;
2762 hres = IHTMLDOMNode_hasChildNodes(node, &b);
2763 ok_(__FILE__,line) (hres == S_OK, "hasChildNodes failed: %08x\n", hres);
2764 ok_(__FILE__,line) (b == exb, "hasChildNodes=%x, expected %x\n", b, exb);
2766 IHTMLDOMNode_Release(node);
2769 #define test_node_get_parent(u) _test_node_get_parent(__LINE__,u)
2770 static IHTMLDOMNode *_test_node_get_parent(unsigned line, IUnknown *unk)
2772 IHTMLDOMNode *node = _get_node_iface(line, unk);
2773 IHTMLDOMNode *parent;
2774 HRESULT hres;
2776 hres = IHTMLDOMNode_get_parentNode(node, &parent);
2777 IHTMLDOMNode_Release(node);
2778 ok_(__FILE__,line) (hres == S_OK, "get_parentNode failed: %08x\n", hres);
2780 return parent;
2783 #define node_get_next(u) _node_get_next(__LINE__,u)
2784 static IHTMLDOMNode *_node_get_next(unsigned line, IUnknown *unk)
2786 IHTMLDOMNode *node = _get_node_iface(line, unk);
2787 IHTMLDOMNode *next;
2788 HRESULT hres;
2790 hres = IHTMLDOMNode_get_nextSibling(node, &next);
2791 IHTMLDOMNode_Release(node);
2792 ok_(__FILE__,line) (hres == S_OK, "get_nextSiblibg failed: %08x\n", hres);
2794 return next;
2797 #define node_get_prev(u) _node_get_prev(__LINE__,u)
2798 static IHTMLDOMNode *_node_get_prev(unsigned line, IUnknown *unk)
2800 IHTMLDOMNode *node = _get_node_iface(line, unk);
2801 IHTMLDOMNode *prev;
2802 HRESULT hres;
2804 hres = IHTMLDOMNode_get_previousSibling(node, &prev);
2805 IHTMLDOMNode_Release(node);
2806 ok_(__FILE__,line) (hres == S_OK, "get_previousSibling failed: %08x\n", hres);
2808 return prev;
2811 #define test_elem_get_parent(u) _test_elem_get_parent(__LINE__,u)
2812 static IHTMLElement *_test_elem_get_parent(unsigned line, IUnknown *unk)
2814 IHTMLElement *elem = _get_elem_iface(line, unk);
2815 IHTMLElement *parent;
2816 HRESULT hres;
2818 hres = IHTMLElement_get_parentElement(elem, &parent);
2819 IHTMLElement_Release(elem);
2820 ok_(__FILE__,line) (hres == S_OK, "get_parentElement failed: %08x\n", hres);
2822 return parent;
2825 #define test_elem3_get_disabled(i,b) _test_elem3_get_disabled(__LINE__,i,b)
2826 static void _test_elem3_get_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL exb)
2828 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2829 VARIANT_BOOL disabled = 100;
2830 HRESULT hres;
2832 if (!elem3) return;
2833 hres = IHTMLElement3_get_disabled(elem3, &disabled);
2834 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2835 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2836 IHTMLElement3_Release(elem3);
2839 #define test_elem3_set_disabled(i,b) _test_elem3_set_disabled(__LINE__,i,b)
2840 static void _test_elem3_set_disabled(unsigned line, IUnknown *unk, VARIANT_BOOL b)
2842 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
2843 HRESULT hres;
2845 if (!elem3) return;
2846 hres = IHTMLElement3_put_disabled(elem3, b);
2847 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2849 IHTMLElement3_Release(elem3);
2850 _test_elem3_get_disabled(line, unk, b);
2853 #define test_select_get_disabled(i,b) _test_select_get_disabled(__LINE__,i,b)
2854 static void _test_select_get_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL exb)
2856 VARIANT_BOOL disabled = 100;
2857 HRESULT hres;
2859 hres = IHTMLSelectElement_get_disabled(select, &disabled);
2860 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2861 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
2863 _test_elem3_get_disabled(line, (IUnknown*)select, exb);
2866 static void test_select_remove(IHTMLSelectElement *select)
2868 HRESULT hres;
2870 hres = IHTMLSelectElement_remove(select, 3);
2871 ok(hres == S_OK, "remove failed: %08x, expected S_OK\n", hres);
2872 test_select_length(select, 2);
2874 hres = IHTMLSelectElement_remove(select, -1);
2875 ok(hres == E_INVALIDARG, "remove failed: %08x, expected E_INVALIDARG\n", hres);
2876 test_select_length(select, 2);
2878 hres = IHTMLSelectElement_remove(select, 0);
2879 ok(hres == S_OK, "remove failed:%08x\n", hres);
2880 test_select_length(select, 1);
2883 #define test_text_length(u,l) _test_text_length(__LINE__,u,l)
2884 static void _test_text_length(unsigned line, IUnknown *unk, LONG l)
2886 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2887 LONG length;
2888 HRESULT hres;
2890 hres = IHTMLDOMTextNode_get_length(text, &length);
2891 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
2892 ok_(__FILE__,line)(length == l, "length = %d, expected %d\n", length, l);
2893 IHTMLDOMTextNode_Release(text);
2896 #define test_text_data(a,b) _test_text_data(__LINE__,a,b)
2897 static void _test_text_data(unsigned line, IUnknown *unk, const char *exdata)
2899 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2900 BSTR str;
2901 HRESULT hres;
2903 hres = IHTMLDOMTextNode_get_data(text, &str);
2904 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2905 ok_(__FILE__,line)(!strcmp_wa(str, exdata), "data = %s, expected %s\n", wine_dbgstr_w(str), exdata);
2906 IHTMLDOMTextNode_Release(text);
2907 SysFreeString(str);
2910 #define set_text_data(a,b) _set_text_data(__LINE__,a,b)
2911 static void _set_text_data(unsigned line, IUnknown *unk, const char *data)
2913 IHTMLDOMTextNode *text = _get_text_iface(line, unk);
2914 BSTR str = a2bstr(data);
2915 HRESULT hres;
2917 hres = IHTMLDOMTextNode_put_data(text, str);
2918 ok_(__FILE__,line)(hres == S_OK, "get_data failed: %08x\n", hres);
2919 IHTMLDOMTextNode_Release(text);
2920 SysFreeString(str);
2923 #define text_append_data(a,b) _text_append_data(__LINE__,a,b)
2924 static void _text_append_data(unsigned line, IUnknown *unk, const char *data)
2926 IHTMLDOMTextNode2 *text = _get_text2_iface(line, unk);
2927 BSTR str = a2bstr(data);
2928 HRESULT hres;
2930 hres = IHTMLDOMTextNode2_appendData(text, str);
2931 ok_(__FILE__,line)(hres == S_OK, "appendData failed: %08x\n", hres);
2932 IHTMLDOMTextNode2_Release(text);
2933 SysFreeString(str);
2936 #define test_select_set_disabled(i,b) _test_select_set_disabled(__LINE__,i,b)
2937 static void _test_select_set_disabled(unsigned line, IHTMLSelectElement *select, VARIANT_BOOL b)
2939 HRESULT hres;
2941 hres = IHTMLSelectElement_put_disabled(select, b);
2942 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
2944 _test_select_get_disabled(line, select, b);
2947 #define test_elem_dir(u,n) _test_elem_dir(__LINE__,u,n)
2948 static void _test_elem_dir(unsigned line, IUnknown *unk, const char *exdir)
2950 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2951 BSTR dir;
2952 HRESULT hres;
2954 hres = IHTMLElement2_get_dir(elem, &dir);
2955 IHTMLElement2_Release(elem);
2956 ok_(__FILE__, line) (hres == S_OK, "get_dir failed: %08x\n", hres);
2957 if(exdir)
2958 ok_(__FILE__, line) (!strcmp_wa(dir, exdir), "got dir: %s, expected %s\n", wine_dbgstr_w(dir), exdir);
2959 else
2960 ok_(__FILE__, line) (!dir, "got dir: %s, expected NULL\n", wine_dbgstr_w(dir));
2962 SysFreeString(dir);
2965 #define set_elem_dir(u,n) _set_elem_dir(__LINE__,u,n)
2966 static void _set_elem_dir(unsigned line, IUnknown *unk, const char *dira)
2968 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2969 BSTR dir = a2bstr(dira);
2970 HRESULT hres;
2972 hres = IHTMLElement2_put_dir(elem, dir);
2973 IHTMLElement2_Release(elem);
2974 ok_(__FILE__, line) (hres == S_OK, "put_dir failed: %08x\n", hres);
2975 SysFreeString(dir);
2977 _test_elem_dir(line, unk, dira);
2980 #define elem_get_scroll_height(u) _elem_get_scroll_height(__LINE__,u)
2981 static LONG _elem_get_scroll_height(unsigned line, IUnknown *unk)
2983 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
2984 IHTMLTextContainer *txtcont;
2985 LONG l = -1, l2 = -1;
2986 HRESULT hres;
2988 hres = IHTMLElement2_get_scrollHeight(elem, &l);
2989 ok_(__FILE__,line) (hres == S_OK, "get_scrollHeight failed: %08x\n", hres);
2990 IHTMLElement2_Release(elem);
2992 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
2993 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
2995 hres = IHTMLTextContainer_get_scrollHeight(txtcont, &l2);
2996 IHTMLTextContainer_Release(txtcont);
2997 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollHeight failed: %d\n", l2);
2998 ok_(__FILE__,line) (l == l2, "unexpected height %d, expected %d\n", l2, l);
3000 return l;
3003 #define elem_get_scroll_width(u) _elem_get_scroll_width(__LINE__,u)
3004 static LONG _elem_get_scroll_width(unsigned line, IUnknown *unk)
3006 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3007 IHTMLTextContainer *txtcont;
3008 LONG l = -1, l2 = -1;
3009 HRESULT hres;
3011 hres = IHTMLElement2_get_scrollWidth(elem, &l);
3012 ok_(__FILE__,line) (hres == S_OK, "get_scrollWidth failed: %08x\n", hres);
3013 IHTMLElement2_Release(elem);
3015 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3016 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3018 hres = IHTMLTextContainer_get_scrollWidth(txtcont, &l2);
3019 IHTMLTextContainer_Release(txtcont);
3020 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollWidth failed: %d\n", l2);
3021 ok_(__FILE__,line) (l == l2, "unexpected width %d, expected %d\n", l2, l);
3023 return l;
3026 #define elem_get_scroll_top(u) _elem_get_scroll_top(__LINE__,u)
3027 static LONG _elem_get_scroll_top(unsigned line, IUnknown *unk)
3029 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3030 IHTMLTextContainer *txtcont;
3031 LONG l = -1, l2 = -1;
3032 HRESULT hres;
3034 hres = IHTMLElement2_get_scrollTop(elem, &l);
3035 ok_(__FILE__,line) (hres == S_OK, "get_scrollTop failed: %08x\n", hres);
3036 IHTMLElement2_Release(elem);
3038 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3039 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3041 hres = IHTMLTextContainer_get_scrollTop(txtcont, &l2);
3042 IHTMLTextContainer_Release(txtcont);
3043 ok_(__FILE__,line) (hres == S_OK, "IHTMLTextContainer::get_scrollTop failed: %d\n", l2);
3044 ok_(__FILE__,line) (l == l2, "unexpected top %d, expected %d\n", l2, l);
3046 return l;
3049 #define elem_get_scroll_left(u) _elem_get_scroll_left(__LINE__,u)
3050 static void _elem_get_scroll_left(unsigned line, IUnknown *unk)
3052 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
3053 IHTMLTextContainer *txtcont;
3054 LONG l = -1, l2 = -1;
3055 HRESULT hres;
3057 hres = IHTMLElement2_get_scrollLeft(elem, NULL);
3058 ok(hres == E_INVALIDARG, "expect E_INVALIDARG got 0x%08x\n", hres);
3060 hres = IHTMLElement2_get_scrollLeft(elem, &l);
3061 ok(hres == S_OK, "get_scrollTop failed: %08x\n", hres);
3062 IHTMLElement2_Release(elem);
3064 hres = IUnknown_QueryInterface(unk, &IID_IHTMLTextContainer, (void**)&txtcont);
3065 ok(hres == S_OK, "Could not get IHTMLTextContainer: %08x\n", hres);
3067 hres = IHTMLTextContainer_get_scrollLeft(txtcont, &l2);
3068 IHTMLTextContainer_Release(txtcont);
3069 ok(hres == S_OK, "IHTMLTextContainer::get_scrollLeft failed: %d\n", l2);
3070 ok(l == l2, "unexpected left %d, expected %d\n", l2, l);
3073 #define test_img_src(a,b,c) _test_img_src(__LINE__,a,b,c)
3074 static void _test_img_src(unsigned line, IUnknown *unk, const char *exsrc, const char *broken_src)
3076 IHTMLImgElement *img = _get_img_iface(line, unk);
3077 BSTR src;
3078 HRESULT hres;
3080 hres = IHTMLImgElement_get_src(img, &src);
3081 IHTMLImgElement_Release(img);
3082 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
3083 ok_(__FILE__,line) (!strcmp_wa(src, exsrc) || (broken_src && broken(!strcmp_wa(src, broken_src))),
3084 "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
3085 SysFreeString(src);
3088 #define test_img_set_src(u,s) _test_img_set_src(__LINE__,u,s)
3089 static void _test_img_set_src(unsigned line, IUnknown *unk, const char *src)
3091 IHTMLImgElement *img = _get_img_iface(line, unk);
3092 BSTR tmp;
3093 HRESULT hres;
3095 tmp = a2bstr(src);
3096 hres = IHTMLImgElement_put_src(img, tmp);
3097 IHTMLImgElement_Release(img);
3098 SysFreeString(tmp);
3099 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
3102 #define test_img_alt(u,a) _test_img_alt(__LINE__,u,a)
3103 static void _test_img_alt(unsigned line, IUnknown *unk, const char *exalt)
3105 IHTMLImgElement *img = _get_img_iface(line, unk);
3106 BSTR alt;
3107 HRESULT hres;
3109 hres = IHTMLImgElement_get_alt(img, &alt);
3110 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
3111 if(exalt)
3112 ok_(__FILE__,line) (!strcmp_wa(alt, exalt), "inexopected alt %s\n", wine_dbgstr_w(alt));
3113 else
3114 ok_(__FILE__,line) (!alt, "alt != NULL\n");
3115 SysFreeString(alt);
3118 #define test_img_set_alt(u,a) _test_img_set_alt(__LINE__,u,a)
3119 static void _test_img_set_alt(unsigned line, IUnknown *unk, const char *alt)
3121 IHTMLImgElement *img = _get_img_iface(line, unk);
3122 BSTR tmp;
3123 HRESULT hres;
3125 tmp = a2bstr(alt);
3126 hres = IHTMLImgElement_put_alt(img, tmp);
3127 ok_(__FILE__,line) (hres == S_OK, "get_alt failed: %08x\n", hres);
3128 SysFreeString(tmp);
3130 _test_img_alt(line, unk, alt);
3133 #define test_img_align(u,a) _test_img_align(__LINE__,u,a)
3134 static void _test_img_align(unsigned line, IUnknown *unk, const char *align)
3136 IHTMLImgElement *img = _get_img_iface(line, unk);
3137 BSTR tmp;
3138 HRESULT hres;
3140 tmp = a2bstr(align);
3141 hres = IHTMLImgElement_put_align(img, tmp);
3142 ok_(__FILE__,line) (hres == S_OK, "put_align failed: %08x\n", hres);
3143 SysFreeString(tmp);
3145 hres = IHTMLImgElement_get_align(img, &tmp);
3146 ok_(__FILE__,line) (hres == S_OK, "put_align failed: %08x\n", hres);
3147 ok_(__FILE__,line) (!strcmp_wa(tmp, align), "Expect %s, got %s\n", align, wine_dbgstr_w(tmp));
3148 SysFreeString(tmp);
3151 #define test_img_name(u, c) _test_img_name(__LINE__,u, c)
3152 static void _test_img_name(unsigned line, IUnknown *unk, const char *pValue)
3154 IHTMLImgElement *img = _get_img_iface(line, unk);
3155 BSTR sName;
3156 HRESULT hres;
3158 hres = IHTMLImgElement_get_name(img, &sName);
3159 ok_(__FILE__,line) (hres == S_OK, "get_Name failed: %08x\n", hres);
3160 ok_(__FILE__,line) (!strcmp_wa (sName, pValue), "expected '%s' got '%s'\n", pValue, wine_dbgstr_w(sName));
3161 IHTMLImgElement_Release(img);
3162 SysFreeString(sName);
3165 #define test_img_complete(a,b) _test_img_complete(__LINE__,a,b)
3166 static void _test_img_complete(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
3168 IHTMLImgElement *img = _get_img_iface(line, (IUnknown*)elem);
3169 VARIANT_BOOL b = 100;
3170 HRESULT hres;
3172 hres = IHTMLImgElement_get_complete(img, &b);
3173 ok_(__FILE__,line) (hres == S_OK, "get_complete failed: %08x\n", hres);
3174 ok_(__FILE__,line) (b == exb, "complete = %x, expected %x\n", b, exb);
3175 IHTMLImgElement_Release(img);
3178 #define test_img_isMap(u, c) _test_img_isMap(__LINE__,u, c)
3179 static void _test_img_isMap(unsigned line, IUnknown *unk, VARIANT_BOOL v)
3181 IHTMLImgElement *img = _get_img_iface(line, unk);
3182 VARIANT_BOOL b = 100;
3183 HRESULT hres;
3185 hres = IHTMLImgElement_put_isMap(img, v);
3186 ok_(__FILE__,line) (hres == S_OK, "put_isMap failed: %08x\n", hres);
3188 hres = IHTMLImgElement_get_isMap(img, &b);
3189 ok_(__FILE__,line) (hres == S_OK, "get_isMap failed: %08x\n", hres);
3190 ok_(__FILE__,line) (b == v, "isMap = %x, expected %x\n", b, v);
3192 hres = IHTMLImgElement_get_isMap(img, NULL);
3193 ok_(__FILE__,line) (hres == E_INVALIDARG, "ret = %08x, expected E_INVALIDARG\n", hres);
3194 IHTMLImgElement_Release(img);
3197 static void test_dynamic_properties(IHTMLElement *elem)
3199 static const WCHAR attr1W[] = {'a','t','t','r','1',0};
3200 IDispatchEx *dispex;
3201 BSTR name, attr1 = SysAllocString(attr1W);
3202 VARIANT_BOOL succ;
3203 VARIANT val;
3204 int checked_no = 0;
3205 DISPID id = DISPID_STARTENUM;
3206 HRESULT hres;
3208 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
3209 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3211 hres = IHTMLElement_removeAttribute(elem, attr1, 0, &succ);
3212 ok(hres == S_OK, "removeAttribute failed: %08x\n", hres);
3213 ok(succ, "removeAttribute set succ to FALSE\n");
3215 while(1) {
3216 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
3217 ok(hres==S_OK || hres==S_FALSE, "GetNextDispID failed: %08x\n", hres);
3218 if(hres != S_OK)
3219 break;
3221 hres = IDispatchEx_GetMemberName(dispex, id, &name);
3222 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
3224 if(!strcmp_wa(name, "attr1"))
3225 ok(0, "attr1 should be removed\n");
3226 else if(!strcmp_wa(name, "attr2") || !strcmp_wa(name, "attr3"))
3227 checked_no++;
3228 SysFreeString(name);
3230 ok(checked_no == 2, "checked_no=%d, expected 2\n", checked_no);
3231 IDispatchEx_Release(dispex);
3233 V_VT(&val) = VT_BSTR;
3234 V_BSTR(&val) = attr1;
3235 hres = IHTMLElement_setAttribute(elem, attr1, val, 0);
3236 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3237 SysFreeString(attr1);
3240 #define test_attr_node_name(a,b) _test_attr_node_name(__LINE__,a,b)
3241 static void _test_attr_node_name(unsigned line, IHTMLDOMAttribute *attr, const char *exname)
3243 BSTR str;
3244 HRESULT hres;
3246 hres = IHTMLDOMAttribute_get_nodeName(attr, &str);
3247 ok_(__FILE__,line)(hres == S_OK, "get_nodeName failed: %08x\n", hres);
3248 ok_(__FILE__,line)(!strcmp_wa(str, exname), "node name is %s, expected %s\n", wine_dbgstr_w(str), exname);
3249 SysFreeString(str);
3252 static void test_attr_collection_disp(IDispatch *disp)
3254 IDispatchEx *dispex;
3255 IHTMLDOMAttribute *attr;
3256 DISPPARAMS dp = {NULL, NULL, 0, 0};
3257 VARIANT var;
3258 EXCEPINFO ei;
3259 DISPID id;
3260 BSTR bstr;
3261 HRESULT hres;
3263 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
3264 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3266 bstr = a2bstr("0");
3267 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
3268 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
3269 SysFreeString(bstr);
3271 VariantInit(&var);
3272 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
3273 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
3274 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
3275 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
3276 VariantClear(&var);
3278 bstr = a2bstr("attr1");
3279 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
3280 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
3281 SysFreeString(bstr);
3283 VariantInit(&var);
3284 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
3285 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
3286 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
3287 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
3288 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLDOMAttribute, (void**)&attr);
3289 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3291 test_attr_node_name(attr, "attr1");
3293 IHTMLDOMAttribute_Release(attr);
3294 VariantClear(&var);
3296 IDispatchEx_Release(dispex);
3299 static void test_attr_collection(IHTMLElement *elem)
3301 static const WCHAR testW[] = {'t','e','s','t',0};
3303 IHTMLDOMNode *node;
3304 IDispatch *disp, *attr;
3305 IHTMLDOMAttribute *dom_attr;
3306 IHTMLAttributeCollection *attr_col;
3307 BSTR name = SysAllocString(testW);
3308 VARIANT id, val;
3309 LONG i, len, checked;
3310 HRESULT hres;
3312 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLDOMNode, (void**)&node);
3313 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3315 hres = IHTMLDOMNode_get_attributes(node, &disp);
3316 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
3318 hres = IHTMLDOMNode_get_attributes(node, &attr);
3319 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
3320 ok(iface_cmp((IUnknown*)disp, (IUnknown*)attr), "disp != attr\n");
3321 IDispatch_Release(attr);
3322 IHTMLDOMNode_Release(node);
3324 hres = IDispatch_QueryInterface(disp, &IID_IHTMLAttributeCollection, (void**)&attr_col);
3325 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3327 hres = IHTMLAttributeCollection_get_length(attr_col, &i);
3328 ok(hres == S_OK, "get_length failed: %08x\n", hres);
3330 V_VT(&val) = VT_I4;
3331 V_I4(&val) = 1;
3332 hres = IHTMLElement_setAttribute(elem, name, val, 0);
3333 ok(hres == S_OK, "setAttribute failed: %08x\n", hres);
3334 SysFreeString(name);
3336 hres = IHTMLAttributeCollection_get_length(attr_col, &len);
3337 ok(hres == S_OK, "get_length failed: %08x\n", hres);
3338 ok(len == i+1, "get_length returned %d, expected %d\n", len, i+1);
3340 checked = 0;
3341 for(i=0; i<len; i++) {
3342 V_VT(&id) = VT_I4;
3343 V_I4(&id) = i;
3344 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3345 ok(hres == S_OK, "%d) item failed: %08x\n", i, hres);
3347 hres = IDispatch_QueryInterface(attr, &IID_IHTMLDOMAttribute, (void**)&dom_attr);
3348 ok(hres == S_OK, "%d) QueryInterface failed: %08x\n", i, hres);
3349 IDispatch_Release(attr);
3351 hres = IHTMLDOMAttribute_get_nodeName(dom_attr, &name);
3352 ok(hres == S_OK, "%d) get_nodeName failed: %08x\n", i, hres);
3354 if(!strcmp_wa(name, "id")) {
3355 checked++;
3356 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3357 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3358 ok(V_VT(&val) == VT_BSTR, "id: V_VT(&val) = %d\n", V_VT(&val));
3359 ok(!strcmp_wa(V_BSTR(&val), "attr"), "id: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3360 test_attr_expando(dom_attr, VARIANT_FALSE);
3361 test_attr_value(dom_attr, "attr");
3362 } else if(!strcmp_wa(name, "attr1")) {
3363 checked++;
3364 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3365 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3366 ok(V_VT(&val) == VT_BSTR, "attr1: V_VT(&val) = %d\n", V_VT(&val));
3367 ok(!strcmp_wa(V_BSTR(&val), "attr1"), "attr1: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3368 test_attr_expando(dom_attr, VARIANT_TRUE);
3369 test_attr_value(dom_attr, "attr1");
3370 } else if(!strcmp_wa(name, "attr2")) {
3371 checked++;
3372 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3373 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3374 ok(V_VT(&val) == VT_BSTR, "attr2: V_VT(&val) = %d\n", V_VT(&val));
3375 ok(!V_BSTR(&val), "attr2: V_BSTR(&val) != NULL\n");
3376 test_attr_value(dom_attr, "");
3377 } else if(!strcmp_wa(name, "attr3")) {
3378 checked++;
3379 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3380 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3381 ok(V_VT(&val) == VT_BSTR, "attr3: V_VT(&val) = %d\n", V_VT(&val));
3382 ok(!strcmp_wa(V_BSTR(&val), "attr3"), "attr3: V_BSTR(&val) = %s\n", wine_dbgstr_w(V_BSTR(&val)));
3383 test_attr_value(dom_attr, "attr3");
3384 } else if(!strcmp_wa(name, "test")) {
3385 checked++;
3386 hres = IHTMLDOMAttribute_get_nodeValue(dom_attr, &val);
3387 ok(hres == S_OK, "%d) get_nodeValue failed: %08x\n", i, hres);
3388 ok(V_VT(&val) == VT_I4, "test: V_VT(&val) = %d\n", V_VT(&val));
3389 ok(V_I4(&val) == 1, "test: V_I4(&val) = %d\n", V_I4(&val));
3390 test_attr_value(dom_attr, "1");
3393 IHTMLDOMAttribute_Release(dom_attr);
3394 SysFreeString(name);
3395 VariantClear(&val);
3397 ok(checked==5, "invalid number of specified attributes (%d)\n", checked);
3399 V_I4(&id) = len;
3400 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3401 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3403 V_VT(&id) = VT_BSTR;
3404 V_BSTR(&id) = a2bstr("nonexisting");
3405 hres = IHTMLAttributeCollection_item(attr_col, &id, &attr);
3406 ok(hres == E_INVALIDARG, "item failed: %08x\n", hres);
3407 VariantClear(&id);
3409 test_attr_collection_disp(disp);
3411 IDispatch_Release(disp);
3412 IHTMLAttributeCollection_Release(attr_col);
3415 #define test_elem_id(e,i) _test_elem_id(__LINE__,e,i)
3416 static void _test_elem_id(unsigned line, IUnknown *unk, const char *exid)
3418 IHTMLElement *elem = _get_elem_iface(line, unk);
3419 BSTR id = (void*)0xdeadbeef;
3420 HRESULT hres;
3422 hres = IHTMLElement_get_id(elem, &id);
3423 IHTMLElement_Release(elem);
3424 ok_(__FILE__,line) (hres == S_OK, "get_id failed: %08x\n", hres);
3426 if(exid)
3427 ok_(__FILE__,line) (!strcmp_wa(id, exid), "unexpected id %s\n", wine_dbgstr_w(id));
3428 else
3429 ok_(__FILE__,line) (!id, "id=%s\n", wine_dbgstr_w(id));
3431 SysFreeString(id);
3434 #define test_elem_language(e,i) _test_elem_language(__LINE__,e,i)
3435 static void _test_elem_language(unsigned line, IHTMLElement *elem, const char *exlang)
3437 BSTR lang = (void*)0xdeadbeef;
3438 HRESULT hres;
3440 hres = IHTMLElement_get_language(elem, &lang);
3441 ok_(__FILE__,line) (hres == S_OK, "get_language failed: %08x\n", hres);
3443 if(exlang)
3444 ok_(__FILE__,line) (!strcmp_wa(lang, exlang), "unexpected language %s\n", wine_dbgstr_w(lang));
3445 else
3446 ok_(__FILE__,line) (!lang, "language=%s\n", wine_dbgstr_w(lang));
3448 SysFreeString(lang);
3451 #define set_elem_language(e,i) _set_elem_language(__LINE__,e,i)
3452 static void _set_elem_language(unsigned line, IHTMLElement *elem, const char *lang)
3454 BSTR str = a2bstr(lang);
3455 HRESULT hres;
3457 hres = IHTMLElement_put_language(elem, str);
3458 ok_(__FILE__,line) (hres == S_OK, "get_language failed: %08x\n", hres);
3459 SysFreeString(str);
3461 _test_elem_language(line, elem, lang);
3464 #define test_elem_put_id(u,i) _test_elem_put_id(__LINE__,u,i)
3465 static void _test_elem_put_id(unsigned line, IUnknown *unk, const char *new_id)
3467 IHTMLElement *elem = _get_elem_iface(line, unk);
3468 BSTR tmp = a2bstr(new_id);
3469 HRESULT hres;
3471 hres = IHTMLElement_put_id(elem, tmp);
3472 IHTMLElement_Release(elem);
3473 SysFreeString(tmp);
3474 ok_(__FILE__,line) (hres == S_OK, "put_id failed: %08x\n", hres);
3476 _test_elem_id(line, unk, new_id);
3479 static void test_contenteditable(IUnknown *unk)
3481 IHTMLElement3 *elem3 = get_elem3_iface(unk);
3482 HRESULT hres;
3483 BSTR str, strDefault;
3485 hres = IHTMLElement3_get_contentEditable(elem3, &strDefault);
3486 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3488 str = a2bstr("true");
3489 hres = IHTMLElement3_put_contentEditable(elem3, str);
3490 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(str), hres);
3491 SysFreeString(str);
3492 hres = IHTMLElement3_get_contentEditable(elem3, &str);
3493 ok(hres == S_OK, "get_contentEditable failed: 0x%08x\n", hres);
3494 ok(!strcmp_wa(str, "true"), "Got %s, expected %s\n", wine_dbgstr_w(str), "true");
3496 /* Restore origin contentEditable */
3497 hres = IHTMLElement3_put_contentEditable(elem3, strDefault);
3498 ok(hres == S_OK, "put_contentEditable(%s) failed: 0x%08x\n", wine_dbgstr_w(strDefault), hres);
3499 SysFreeString(strDefault);
3501 IHTMLElement3_Release(elem3);
3504 #define test_input_type(i,t) _test_input_type(__LINE__,i,t)
3505 static void _test_input_type(unsigned line, IHTMLInputElement *input, const char *extype)
3507 BSTR type;
3508 HRESULT hres;
3510 hres = IHTMLInputElement_get_type(input, &type);
3511 ok_(__FILE__,line) (hres == S_OK, "get_type failed: %08x\n", hres);
3512 ok_(__FILE__,line) (!strcmp_wa(type, extype), "type=%s, expected %s\n", wine_dbgstr_w(type), extype);
3513 SysFreeString(type);
3516 #define test_input_name(u, c) _test_input_name(__LINE__,u, c)
3517 static void _test_input_name(unsigned line, IHTMLInputElement *input, const char *exname)
3519 BSTR name = (BSTR)0xdeadbeef;
3520 HRESULT hres;
3522 hres = IHTMLInputElement_get_name(input, &name);
3523 ok_(__FILE__,line) (hres == S_OK, "get_name failed: %08x\n", hres);
3524 if(exname)
3525 ok_(__FILE__,line) (!strcmp_wa (name, exname), "name=%s, expected %s\n", wine_dbgstr_w(name), exname);
3526 else
3527 ok_(__FILE__,line) (!name, "name=%p, expected NULL\n", name);
3528 SysFreeString(name);
3531 #define test_input_set_name(u, c) _test_input_set_name(__LINE__,u, c)
3532 static void _test_input_set_name(unsigned line, IHTMLInputElement *input, const char *name)
3534 BSTR tmp = a2bstr(name);
3535 HRESULT hres;
3537 hres = IHTMLInputElement_put_name(input, tmp);
3538 ok_(__FILE__,line) (hres == S_OK, "put_name failed: %08x\n", hres);
3539 SysFreeString(tmp);
3541 _test_input_name(line, input, name);
3544 #define test_input_get_disabled(i,b) _test_input_get_disabled(__LINE__,i,b)
3545 static void _test_input_get_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3547 VARIANT_BOOL disabled = 100;
3548 HRESULT hres;
3550 hres = IHTMLInputElement_get_disabled(input, &disabled);
3551 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3552 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
3554 _test_elem3_get_disabled(line, (IUnknown*)input, exb);
3557 #define test_input_set_disabled(i,b) _test_input_set_disabled(__LINE__,i,b)
3558 static void _test_input_set_disabled(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3560 HRESULT hres;
3562 hres = IHTMLInputElement_put_disabled(input, b);
3563 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
3565 _test_input_get_disabled(line, input, b);
3568 #define test_input_get_defaultchecked(i,b) _test_input_get_defaultchecked(__LINE__,i,b)
3569 static void _test_input_get_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3571 VARIANT_BOOL checked = 100;
3572 HRESULT hres;
3574 hres = IHTMLInputElement_get_defaultChecked(input, &checked);
3575 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3576 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3579 #define test_input_set_defaultchecked(i,b) _test_input_set_defaultchecked(__LINE__,i,b)
3580 static void _test_input_set_defaultchecked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3582 HRESULT hres;
3584 hres = IHTMLInputElement_put_defaultChecked(input, b);
3585 ok_(__FILE__,line) (hres == S_OK, "get_defaultChecked failed: %08x\n", hres);
3587 _test_input_get_defaultchecked(line, input, b);
3590 #define test_input_get_checked(i,b) _test_input_get_checked(__LINE__,i,b)
3591 static void _test_input_get_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL exb)
3593 VARIANT_BOOL checked = 100;
3594 HRESULT hres;
3596 hres = IHTMLInputElement_get_checked(input, &checked);
3597 ok_(__FILE__,line) (hres == S_OK, "get_checked failed: %08x\n", hres);
3598 ok_(__FILE__,line) (checked == exb, "checked=%x, expected %x\n", checked, exb);
3601 #define test_input_set_checked(i,b) _test_input_set_checked(__LINE__,i,b)
3602 static void _test_input_set_checked(unsigned line, IHTMLInputElement *input, VARIANT_BOOL b)
3604 HRESULT hres;
3606 hres = IHTMLInputElement_put_checked(input, b);
3607 ok_(__FILE__,line) (hres == S_OK, "put_checked failed: %08x\n", hres);
3609 _test_input_get_checked(line, input, b);
3612 #define test_input_maxlength(i,b) _test_input_maxlength(__LINE__,i,b)
3613 static void _test_input_maxlength(unsigned line, IHTMLInputElement *input, LONG exl)
3615 LONG maxlength = 0xdeadbeef;
3616 HRESULT hres;
3618 hres = IHTMLInputElement_get_maxLength(input, &maxlength);
3619 ok_(__FILE__,line) (hres == S_OK, "get_maxLength failed: %08x\n", hres);
3620 ok_(__FILE__,line) (maxlength == exl, "maxLength=%x, expected %d\n", maxlength, exl);
3623 #define test_input_set_maxlength(i,b) _test_input_set_maxlength(__LINE__,i,b)
3624 static void _test_input_set_maxlength(unsigned line, IHTMLInputElement *input, LONG l)
3626 HRESULT hres;
3628 hres = IHTMLInputElement_put_maxLength(input, l);
3629 ok_(__FILE__,line) (hres == S_OK, "put_maxLength failed: %08x\n", hres);
3631 _test_input_maxlength(line, input, l);
3634 #define test_input_value(o,t) _test_input_value(__LINE__,o,t)
3635 static void _test_input_value(unsigned line, IUnknown *unk, const char *exval)
3637 IHTMLInputElement *input;
3638 BSTR bstr;
3639 HRESULT hres;
3641 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3642 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3643 if(FAILED(hres))
3644 return;
3646 hres = IHTMLInputElement_get_value(input, &bstr);
3647 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3648 if(exval)
3649 ok_(__FILE__,line) (!strcmp_wa(bstr, exval), "value=%s\n", wine_dbgstr_w(bstr));
3650 else
3651 ok_(__FILE__,line) (!bstr, "exval != NULL\n");
3652 SysFreeString(bstr);
3653 IHTMLInputElement_Release(input);
3656 #define test_input_get_form(o, t) _test_input_get_form(__LINE__, o, t)
3657 static void _test_input_get_form(unsigned line, IUnknown *unk, const char *id)
3659 IHTMLInputElement *input;
3660 IHTMLFormElement *form;
3661 IHTMLElement *elem;
3662 HRESULT hres;
3664 ok_(__FILE__,line) (unk != NULL, "unk is NULL!\n");
3665 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3666 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3667 ok_(__FILE__,line) (input != NULL, "input == NULL\n");
3668 if(FAILED(hres) || input == NULL)
3669 return;
3671 hres = IHTMLInputElement_get_form(input, &form);
3672 ok_(__FILE__, line) (hres == S_OK, "get_form failed: %08x\n", hres);
3673 ok_(__FILE__, line) (form != NULL, "form == NULL\n");
3674 if(FAILED(hres) || form == NULL){
3675 IHTMLInputElement_Release(input);
3676 return;
3679 hres = IHTMLFormElement_QueryInterface(form, &IID_IHTMLElement, (void **)&elem);
3680 ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLElement) failed: %08x\n", hres);
3681 ok_(__FILE__, line) (elem != NULL, "elem == NULL\n");
3682 if(FAILED(hres) || elem == NULL){
3683 IHTMLInputElement_Release(input);
3684 IHTMLFormElement_Release(form);
3685 return;
3688 _test_elem_id(line, (IUnknown*)elem, id);
3690 IHTMLInputElement_Release(input);
3691 IHTMLFormElement_Release(form);
3692 IHTMLElement_Release(elem);
3695 #define test_input_put_value(o,v) _test_input_put_value(__LINE__,o,v)
3696 static void _test_input_put_value(unsigned line, IUnknown *unk, const char *val)
3698 IHTMLInputElement *input;
3699 BSTR bstr;
3700 HRESULT hres;
3702 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3703 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3704 if(FAILED(hres))
3705 return;
3707 bstr = a2bstr(val);
3708 hres = IHTMLInputElement_put_value(input, bstr);
3709 ok_(__FILE__,line) (hres == S_OK, "get_value failed: %08x\n", hres);
3710 SysFreeString(bstr);
3711 IHTMLInputElement_Release(input);
3713 _test_input_value(line, unk, val);
3716 #define test_input_defaultValue(o,t) _test_input_defaultValue(__LINE__,o,t)
3717 static void _test_input_defaultValue(unsigned line, IUnknown *unk, const char *exval)
3719 IHTMLInputElement *input;
3720 BSTR str;
3721 HRESULT hres;
3723 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3724 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3725 if(FAILED(hres))
3726 return;
3728 hres = IHTMLInputElement_get_defaultValue(input, &str);
3729 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3730 if(exval)
3731 ok_(__FILE__,line) (!strcmp_wa(str, exval), "defaultValue=%s\n", wine_dbgstr_w(str));
3732 else
3733 ok_(__FILE__,line) (!str, "exval != NULL\n");
3734 SysFreeString(str);
3735 IHTMLInputElement_Release(input);
3738 #define test_input_put_defaultValue(o,v) _test_input_put_defaultValue(__LINE__,o,v)
3739 static void _test_input_put_defaultValue(unsigned line, IUnknown *unk, const char *val)
3741 IHTMLInputElement *input;
3742 BSTR str;
3743 HRESULT hres;
3745 hres = IUnknown_QueryInterface(unk, &IID_IHTMLInputElement, (void**)&input);
3746 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
3747 if(FAILED(hres))
3748 return;
3750 str = a2bstr(val);
3751 hres = IHTMLInputElement_put_defaultValue(input, str);
3752 ok_(__FILE__,line) (hres == S_OK, "get_defaultValue failed: %08x\n", hres);
3753 SysFreeString(str);
3754 IHTMLInputElement_Release(input);
3756 _test_input_defaultValue(line, unk, val);
3759 #define test_input_src(i,s) _test_input_src(__LINE__,i,s)
3760 static void _test_input_src(unsigned line, IHTMLInputElement *input, const char *exsrc)
3762 BSTR src;
3763 HRESULT hres;
3765 hres = IHTMLInputElement_get_src(input, &src);
3766 ok_(__FILE__,line) (hres == S_OK, "get_src failed: %08x\n", hres);
3767 if(exsrc)
3768 ok_(__FILE__,line) (!strcmp_wa(src, exsrc), "get_src returned %s expected %s\n", wine_dbgstr_w(src), exsrc);
3769 else
3770 ok_(__FILE__,line) (!src, "get_src returned %s expected NULL\n", wine_dbgstr_w(src));
3771 SysFreeString(src);
3774 #define test_input_set_src(u,s) _test_input_set_src(__LINE__,u,s)
3775 static void _test_input_set_src(unsigned line, IHTMLInputElement *input, const char *src)
3777 BSTR tmp;
3778 HRESULT hres;
3780 tmp = a2bstr(src);
3781 hres = IHTMLInputElement_put_src(input, tmp);
3782 SysFreeString(tmp);
3783 ok_(__FILE__,line) (hres == S_OK, "put_src failed: %08x\n", hres);
3785 _test_input_src(line, input, src);
3788 #define test_input_set_size(u,s,r) _test_input_set_size(__LINE__,u,s,r)
3789 static void _test_input_set_size(unsigned line, IHTMLInputElement *input, LONG size, HRESULT exret)
3791 HRESULT hres;
3793 hres = IHTMLInputElement_put_size(input, size);
3794 ok_(__FILE__,line) (hres == exret, "Expect ret = %08x, got: %08x\n", exret, hres);
3797 #define test_input_get_size(u,s) _test_input_get_size(__LINE__,u,s)
3798 static void _test_input_get_size(unsigned line, IHTMLInputElement *input, LONG exsize)
3800 HRESULT hres;
3801 LONG size;
3803 hres = IHTMLInputElement_get_size(input, &size);
3804 ok_(__FILE__,line) (hres == S_OK, "get_size failed: %08x\n", hres);
3805 ok_(__FILE__,line) (size == exsize, "Expect %d, got %d\n", exsize, size);
3807 hres = IHTMLInputElement_get_size(input, NULL);
3808 ok_(__FILE__,line) (hres == E_INVALIDARG, "Expect ret E_INVALIDARG, got: %08x\n", hres);
3811 #define test_input_readOnly(u,b) _test_input_readOnly(__LINE__,u,b)
3812 static void _test_input_readOnly(unsigned line, IHTMLInputElement *input, VARIANT_BOOL v)
3814 HRESULT hres;
3815 VARIANT_BOOL b = 100;
3817 hres = IHTMLInputElement_put_readOnly(input, v);
3818 ok_(__FILE__,line)(hres == S_OK, "put readOnly failed: %08x\n", hres);
3820 hres = IHTMLInputElement_get_readOnly(input, &b);
3821 ok_(__FILE__,line)(hres == S_OK, "get readOnly failed: %08x\n", hres);
3822 ok_(__FILE__,line)(v == b, "Expect %x, got %x\n", v, b);
3825 #define test_elem_class(u,c) _test_elem_class(__LINE__,u,c)
3826 static void _test_elem_class(unsigned line, IUnknown *unk, const char *exclass)
3828 IHTMLElement *elem = _get_elem_iface(line, unk);
3829 BSTR class = (void*)0xdeadbeef;
3830 HRESULT hres;
3832 hres = IHTMLElement_get_className(elem, &class);
3833 IHTMLElement_Release(elem);
3834 ok_(__FILE__,line) (hres == S_OK, "get_className failed: %08x\n", hres);
3835 if(exclass)
3836 ok_(__FILE__,line) (!strcmp_wa(class, exclass), "unexpected className %s\n", wine_dbgstr_w(class));
3837 else
3838 ok_(__FILE__,line) (!class, "class != NULL\n");
3839 SysFreeString(class);
3842 #define test_elem_tabindex(u,i) _test_elem_tabindex(__LINE__,u,i)
3843 static void _test_elem_tabindex(unsigned line, IUnknown *unk, short exindex)
3845 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3846 short index = -3;
3847 HRESULT hres;
3849 hres = IHTMLElement2_get_tabIndex(elem2, &index);
3850 IHTMLElement2_Release(elem2);
3851 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3852 ok_(__FILE__,line) (index == exindex, "unexpected index %d\n", index);
3855 #define test_elem_set_tabindex(u,i) _test_elem_set_tabindex(__LINE__,u,i)
3856 static void _test_elem_set_tabindex(unsigned line, IUnknown *unk, short index)
3858 IHTMLElement2 *elem2 = _get_elem2_iface(line, unk);
3859 HRESULT hres;
3861 hres = IHTMLElement2_put_tabIndex(elem2, index);
3862 IHTMLElement2_Release(elem2);
3863 ok_(__FILE__,line) (hres == S_OK, "get_tabIndex failed: %08x\n", hres);
3865 _test_elem_tabindex(line, unk, index);
3868 #define test_style_media(s,m) _test_style_media(__LINE__,s,m)
3869 static void _test_style_media(unsigned line, IUnknown *unk, const char *exmedia)
3871 IHTMLStyleElement *style = _get_style_iface(line, unk);
3872 BSTR media;
3873 HRESULT hres;
3875 hres = IHTMLStyleElement_get_media(style, &media);
3876 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
3877 if(exmedia)
3878 ok_(__FILE__,line)(!strcmp_wa(media, exmedia), "media = %s, expected %s\n", wine_dbgstr_w(media), exmedia);
3879 else
3880 ok_(__FILE__,line)(!media, "media = %s, expected NULL\n", wine_dbgstr_w(media));
3882 IHTMLStyleElement_Release(style);
3883 SysFreeString(media);
3886 #define test_style_put_media(s,m) _test_style_put_media(__LINE__,s,m)
3887 static void _test_style_put_media(unsigned line, IUnknown *unk, const char *media)
3889 IHTMLStyleElement *style = _get_style_iface(line, unk);
3890 BSTR str;
3891 HRESULT hres;
3893 str = a2bstr(media);
3894 hres = IHTMLStyleElement_put_media(style, str);
3895 ok_(__FILE__,line)(hres == S_OK, "put_media failed: %08x\n", hres);
3896 IHTMLStyleElement_Release(style);
3897 SysFreeString(str);
3899 _test_style_media(line, unk, media);
3902 #define test_style_type(s,m) _test_style_type(__LINE__,s,m)
3903 static void _test_style_type(unsigned line, IUnknown *unk, const char *extype)
3905 IHTMLStyleElement *style = _get_style_iface(line, unk);
3906 BSTR type;
3907 HRESULT hres;
3909 hres = IHTMLStyleElement_get_type(style, &type);
3910 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
3911 if(extype)
3912 ok_(__FILE__,line)(!strcmp_wa(type, extype), "type = %s, expected %s\n", wine_dbgstr_w(type), extype);
3913 else
3914 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
3916 IHTMLStyleElement_Release(style);
3917 SysFreeString(type);
3920 #define test_style_put_type(s,m) _test_style_put_type(__LINE__,s,m)
3921 static void _test_style_put_type(unsigned line, IUnknown *unk, const char *type)
3923 IHTMLStyleElement *style = _get_style_iface(line, unk);
3924 BSTR str;
3925 HRESULT hres;
3927 str = a2bstr(type);
3928 hres = IHTMLStyleElement_put_type(style, str);
3929 ok_(__FILE__,line)(hres == S_OK, "put_type failed: %08x\n", hres);
3930 IHTMLStyleElement_Release(style);
3931 SysFreeString(str);
3933 _test_style_type(line, unk, type);
3936 #define test_elem_filters(u) _test_elem_filters(__LINE__,u)
3937 static void _test_elem_filters(unsigned line, IUnknown *unk)
3939 IHTMLElement *elem = _get_elem_iface(line, unk);
3940 HRESULT hres;
3941 IHTMLFiltersCollection *filters;
3943 hres = IHTMLElement_get_filters(elem, &filters);
3944 ok_(__FILE__,line) (hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG) /* NT4 */,
3945 "get_filters failed: %08x\n", hres);
3946 if(hres == S_OK)
3948 LONG len;
3949 IDispatchEx *dispex;
3951 hres = IHTMLFiltersCollection_get_length(filters, &len);
3952 ok_(__FILE__,line) (hres == S_OK, "get_length failed: %08x\n", hres);
3953 ok_(__FILE__,line) (len == 0, "expect 0 got %d\n", len);
3955 hres = IHTMLFiltersCollection_QueryInterface(filters, &IID_IDispatchEx, (void**)&dispex);
3956 ok_(__FILE__,line) (hres == S_OK || broken(hres == E_NOINTERFACE),
3957 "Could not get IDispatchEx interface: %08x\n", hres);
3958 if(SUCCEEDED(hres)) {
3959 test_disp((IUnknown*)filters, &IID_IHTMLFiltersCollection, "[object]");
3960 IDispatchEx_Release(dispex);
3963 IHTMLFiltersCollection_Release(filters);
3966 IHTMLElement_Release(elem);
3969 #define test_elem_set_class(u,c) _test_elem_set_class(__LINE__,u,c)
3970 static void _test_elem_set_class(unsigned line, IUnknown *unk, const char *class)
3972 IHTMLElement *elem = _get_elem_iface(line, unk);
3973 BSTR tmp;
3974 HRESULT hres;
3976 tmp = class ? a2bstr(class) : NULL;
3977 hres = IHTMLElement_put_className(elem, tmp);
3978 IHTMLElement_Release(elem);
3979 ok_(__FILE__,line) (hres == S_OK, "put_className failed: %08x\n", hres);
3980 SysFreeString(tmp);
3982 _test_elem_class(line, unk, class);
3985 #define test_elem_title(u,t) _test_elem_title(__LINE__,u,t)
3986 static void _test_elem_title(unsigned line, IUnknown *unk, const char *extitle)
3988 IHTMLElement *elem = _get_elem_iface(line, unk);
3989 BSTR title;
3990 HRESULT hres;
3992 hres = IHTMLElement_get_title(elem, &title);
3993 IHTMLElement_Release(elem);
3994 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
3995 if(extitle)
3996 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
3997 else
3998 ok_(__FILE__,line) (!title, "title=%s, expected NULL\n", wine_dbgstr_w(title));
4000 SysFreeString(title);
4003 #define test_elem_set_title(u,t) _test_elem_set_title(__LINE__,u,t)
4004 static void _test_elem_set_title(unsigned line, IUnknown *unk, const char *title)
4006 IHTMLElement *elem = _get_elem_iface(line, unk);
4007 BSTR tmp;
4008 HRESULT hres;
4010 tmp = a2bstr(title);
4011 hres = IHTMLElement_put_title(elem, tmp);
4012 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4014 IHTMLElement_Release(elem);
4015 SysFreeString(tmp);
4018 #define test_node_get_value_str(u,e) _test_node_get_value_str(__LINE__,u,e)
4019 static void _test_node_get_value_str(unsigned line, IUnknown *unk, const char *exval)
4021 IHTMLDOMNode *node = _get_node_iface(line, unk);
4022 VARIANT var;
4023 HRESULT hres;
4025 hres = IHTMLDOMNode_get_nodeValue(node, &var);
4026 IHTMLDOMNode_Release(node);
4027 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
4029 if(exval) {
4030 ok_(__FILE__,line) (V_VT(&var) == VT_BSTR, "vt=%d\n", V_VT(&var));
4031 ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&var), exval), "unexpected value %s\n", wine_dbgstr_w(V_BSTR(&var)));
4032 }else {
4033 ok_(__FILE__,line) (V_VT(&var) == VT_NULL, "vt=%d, expected VT_NULL\n", V_VT(&var));
4036 VariantClear(&var);
4039 #define test_node_put_value_str(u,v) _test_node_put_value_str(__LINE__,u,v)
4040 static void _test_node_put_value_str(unsigned line, IUnknown *unk, const char *val)
4042 IHTMLDOMNode *node = _get_node_iface(line, unk);
4043 VARIANT var;
4044 HRESULT hres;
4046 V_VT(&var) = VT_BSTR;
4047 V_BSTR(&var) = a2bstr(val);
4049 hres = IHTMLDOMNode_put_nodeValue(node, var);
4050 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x, expected VT_BSTR\n", hres);
4051 IHTMLDOMNode_Release(node);
4052 VariantClear(&var);
4055 #define test_elem_client_size(u) _test_elem_client_size(__LINE__,u)
4056 static void _test_elem_client_size(unsigned line, IUnknown *unk)
4058 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
4059 LONG l;
4060 HRESULT hres;
4062 hres = IHTMLElement2_get_clientWidth(elem, &l);
4063 ok_(__FILE__,line) (hres == S_OK, "get_clientWidth failed: %08x\n", hres);
4064 hres = IHTMLElement2_get_clientHeight(elem, &l);
4065 ok_(__FILE__,line) (hres == S_OK, "get_clientHeight failed: %08x\n", hres);
4067 IHTMLElement2_Release(elem);
4070 #define test_elem_client_rect(u) _test_elem_client_rect(__LINE__,u)
4071 static void _test_elem_client_rect(unsigned line, IUnknown *unk)
4073 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
4074 LONG l;
4075 HRESULT hres;
4077 hres = IHTMLElement2_get_clientLeft(elem, &l);
4078 ok_(__FILE__,line) (hres == S_OK, "get_clientLeft failed: %08x\n", hres);
4079 ok_(__FILE__,line) (!l, "clientLeft = %d\n", l);
4081 hres = IHTMLElement2_get_clientTop(elem, &l);
4082 ok_(__FILE__,line) (hres == S_OK, "get_clientTop failed: %08x\n", hres);
4083 ok_(__FILE__,line) (!l, "clientTop = %d\n", l);
4085 IHTMLElement2_Release(elem);
4088 #define test_form_length(e,l) _test_form_length(__LINE__,e,l)
4089 static void _test_form_length(unsigned line, IUnknown *unk, LONG exlen)
4091 IHTMLFormElement *form = _get_form_iface(line, unk);
4092 LONG len = 0xdeadbeef;
4093 HRESULT hres;
4095 hres = IHTMLFormElement_get_length(form, &len);
4096 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
4097 ok_(__FILE__,line)(len == exlen, "length=%d, expected %d\n", len, exlen);
4099 IHTMLFormElement_Release(form);
4102 #define test_form_action(f,a) _test_form_action(__LINE__,f,a)
4103 static void _test_form_action(unsigned line, IUnknown *unk, const char *ex)
4105 IHTMLFormElement *form = _get_form_iface(line, unk);
4106 BSTR action = (void*)0xdeadbeef;
4107 HRESULT hres;
4109 hres = IHTMLFormElement_get_action(form, &action);
4110 ok_(__FILE__,line)(hres == S_OK, "get_action failed: %08x\n", hres);
4111 if(ex)
4112 ok_(__FILE__,line)(!strcmp_wa(action, ex), "action=%s, expected %s\n", wine_dbgstr_w(action), ex);
4113 else
4114 ok_(__FILE__,line)(!action, "action=%p\n", action);
4116 SysFreeString(action);
4117 IHTMLFormElement_Release(form);
4120 #define test_form_put_action(f,a) _test_form_put_action(__LINE__,f,a)
4121 static void _test_form_put_action(unsigned line, IUnknown *unk, const char *action)
4123 IHTMLFormElement *form = _get_form_iface(line, unk);
4124 BSTR tmp = a2bstr(action);
4125 HRESULT hres;
4127 hres = IHTMLFormElement_put_action(form, tmp);
4128 ok_(__FILE__,line)(hres == S_OK, "put_action failed: %08x\n", hres);
4129 SysFreeString(tmp);
4130 IHTMLFormElement_Release(form);
4132 _test_form_action(line, unk, action);
4135 #define test_form_method(f,a) _test_form_method(__LINE__,f,a)
4136 static void _test_form_method(unsigned line, IUnknown *unk, const char *ex)
4138 IHTMLFormElement *form = _get_form_iface(line, unk);
4139 BSTR method = (void*)0xdeadbeef;
4140 HRESULT hres;
4142 hres = IHTMLFormElement_get_method(form, &method);
4143 ok_(__FILE__,line)(hres == S_OK, "get_method failed: %08x\n", hres);
4144 if(ex)
4145 ok_(__FILE__,line)(!strcmp_wa(method, ex), "method=%s, expected %s\n", wine_dbgstr_w(method), ex);
4146 else
4147 ok_(__FILE__,line)(!method, "method=%p\n", method);
4149 SysFreeString(method);
4150 IHTMLFormElement_Release(form);
4153 #define test_form_put_method(f,r,a) _test_form_put_method(__LINE__,f,r,a)
4154 static void _test_form_put_method(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *method)
4156 IHTMLFormElement *form = _get_form_iface(line, unk);
4157 BSTR tmp = a2bstr(method);
4158 HRESULT hres;
4160 hres = IHTMLFormElement_put_method(form, tmp);
4161 ok_(__FILE__,line)(hres == exp_hres, "put_method returned: %08x, expected %08x\n", hres, exp_hres);
4162 SysFreeString(tmp);
4163 IHTMLFormElement_Release(form);
4165 if(exp_hres == S_OK)
4166 _test_form_method(line, unk, method);
4169 #define test_form_name(f,a) _test_form_name(__LINE__,f,a)
4170 static void _test_form_name(unsigned line, IUnknown *unk, const char *ex)
4172 IHTMLFormElement *form = _get_form_iface(line, unk);
4173 BSTR name = (void*)0xdeadbeef;
4174 HRESULT hres;
4176 hres = IHTMLFormElement_get_name(form, &name);
4177 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
4178 if(ex)
4179 ok_(__FILE__,line)(!strcmp_wa(name, ex), "name=%s, expected %s\n", wine_dbgstr_w(name), ex);
4180 else
4181 ok_(__FILE__,line)(!name, "name=%p\n", name);
4183 SysFreeString(name);
4184 IHTMLFormElement_Release(form);
4187 #define test_form_put_name(f,a) _test_form_put_name(__LINE__,f,a)
4188 static void _test_form_put_name(unsigned line, IUnknown *unk, const char *name)
4190 IHTMLFormElement *form = _get_form_iface(line, unk);
4191 BSTR tmp = a2bstr(name);
4192 HRESULT hres;
4194 hres = IHTMLFormElement_put_name(form, tmp);
4195 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
4196 SysFreeString(tmp);
4197 IHTMLFormElement_Release(form);
4199 _test_form_name(line, unk, name);
4202 #define test_form_encoding(f,a) _test_form_encoding(__LINE__,f,a)
4203 static void _test_form_encoding(unsigned line, IUnknown *unk, const char *ex)
4205 IHTMLFormElement *form = _get_form_iface(line, unk);
4206 BSTR encoding = (void*)0xdeadbeef;
4207 HRESULT hres;
4209 hres = IHTMLFormElement_get_encoding(form, &encoding);
4210 ok_(__FILE__,line)(hres == S_OK, "get_encoding failed: %08x\n", hres);
4211 if(ex)
4212 ok_(__FILE__,line)(!strcmp_wa(encoding, ex), "encoding=%s, expected %s\n", wine_dbgstr_w(encoding), ex);
4213 else
4214 ok_(__FILE__,line)(!encoding, "encoding=%p\n", encoding);
4216 SysFreeString(encoding);
4217 IHTMLFormElement_Release(form);
4220 #define test_form_put_encoding(f,r,a) _test_form_put_encoding(__LINE__,f,r,a)
4221 static void _test_form_put_encoding(unsigned line, IUnknown *unk, HRESULT exp_hres, const char *encoding)
4223 IHTMLFormElement *form = _get_form_iface(line, unk);
4224 BSTR tmp = a2bstr(encoding);
4225 HRESULT hres;
4227 hres = IHTMLFormElement_put_encoding(form, tmp);
4228 ok_(__FILE__,line)(hres == exp_hres, "put_encoding returned: %08x, expected %08x\n", hres, exp_hres);
4229 SysFreeString(tmp);
4230 IHTMLFormElement_Release(form);
4232 if(exp_hres == S_OK)
4233 _test_form_encoding(line, unk, encoding);
4236 #define test_form_elements(a) _test_form_elements(__LINE__,a)
4237 static void _test_form_elements(unsigned line, IUnknown *unk)
4239 IHTMLFormElement *form = _get_form_iface(line, unk);
4240 IDispatch *disp;
4241 HRESULT hres;
4243 disp = NULL;
4244 hres = IHTMLFormElement_get_elements(form, &disp);
4245 ok_(__FILE__,line)(hres == S_OK, "get_elements failed: %08x\n", hres);
4246 ok_(__FILE__,line)(disp != NULL, "disp = NULL\n");
4247 ok_(__FILE__,line)(iface_cmp((IUnknown*)form, (IUnknown*)disp), "disp != form\n");
4249 IDispatch_Release(disp);
4250 IHTMLFormElement_Release(form);
4253 #define test_form_reset(a) _test_form_reset(__LINE__,a)
4254 static void _test_form_reset(unsigned line, IUnknown *unk)
4256 IHTMLFormElement *form = _get_form_iface(line, unk);
4257 HRESULT hres;
4259 hres = IHTMLFormElement_reset(form);
4260 ok_(__FILE__,line)(hres == S_OK, "reset failed: %08x\n", hres);
4262 IHTMLFormElement_Release(form);
4265 static void test_form_target(IUnknown *unk)
4267 IHTMLFormElement *form = get_form_iface(unk);
4268 HRESULT hres;
4269 BSTR str;
4270 static const char target[] = "_blank";
4272 str = a2bstr(target);
4273 hres = IHTMLFormElement_put_target(form, str);
4274 ok(hres == S_OK, "put_target(%s) failed: %08x\n", target, hres);
4275 SysFreeString(str);
4277 hres = IHTMLFormElement_get_target(form, &str);
4278 ok(hres == S_OK, "get_target failed: %08x\n", hres);
4279 ok(!strcmp_wa(str, target), "Expected %s, got %s\n", target, wine_dbgstr_w(str));
4280 SysFreeString(str);
4282 IHTMLFormElement_Release(form);
4285 #define test_meta_name(a,b) _test_meta_name(__LINE__,a,b)
4286 static void _test_meta_name(unsigned line, IUnknown *unk, const char *exname)
4288 IHTMLMetaElement *meta;
4289 BSTR name = NULL;
4290 HRESULT hres;
4292 meta = _get_metaelem_iface(line, unk);
4293 hres = IHTMLMetaElement_get_name(meta, &name);
4294 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
4295 ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s, expected %s\n", wine_dbgstr_w(name), exname);
4296 SysFreeString(name);
4297 IHTMLMetaElement_Release(meta);
4300 #define test_meta_content(a,b) _test_meta_content(__LINE__,a,b)
4301 static void _test_meta_content(unsigned line, IUnknown *unk, const char *excontent)
4303 IHTMLMetaElement *meta;
4304 BSTR content = NULL;
4305 HRESULT hres;
4307 meta = _get_metaelem_iface(line, unk);
4308 hres = IHTMLMetaElement_get_content(meta, &content);
4309 ok_(__FILE__,line)(hres == S_OK, "get_content failed: %08x\n", hres);
4310 ok_(__FILE__,line)(!strcmp_wa(content, excontent), "content = %s, expected %s\n", wine_dbgstr_w(content), excontent);
4311 SysFreeString(content);
4312 IHTMLMetaElement_Release(meta);
4315 #define test_meta_httpequiv(a,b) _test_meta_httpequiv(__LINE__,a,b)
4316 static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const char *exval)
4318 IHTMLMetaElement *meta;
4319 BSTR val = NULL;
4320 HRESULT hres;
4322 meta = _get_metaelem_iface(line, unk);
4323 hres = IHTMLMetaElement_get_httpEquiv(meta, &val);
4324 ok_(__FILE__,line)(hres == S_OK, "get_httpEquiv failed: %08x\n", hres);
4325 ok_(__FILE__,line)(!strcmp_wa(val, exval), "httpEquiv = %s, expected %s\n", wine_dbgstr_w(val), exval);
4326 SysFreeString(val);
4327 IHTMLMetaElement_Release(meta);
4330 #define test_meta_charset(a,b) _test_meta_charset(__LINE__,a,b)
4331 static void _test_meta_charset(unsigned line, IUnknown *unk, const char *exval)
4333 IHTMLMetaElement *meta;
4334 BSTR val = NULL;
4335 HRESULT hres;
4337 meta = _get_metaelem_iface(line, unk);
4338 hres = IHTMLMetaElement_get_charset(meta, &val);
4339 ok_(__FILE__,line)(hres == S_OK, "get_charset failed: %08x\n", hres);
4340 if(exval)
4341 ok_(__FILE__,line)(!strcmp_wa(val, exval), "charset = %s, expected %s\n", wine_dbgstr_w(val), exval);
4342 else
4343 ok_(__FILE__,line)(!val, "charset = %s, expected NULL\n", wine_dbgstr_w(val));
4344 SysFreeString(val);
4345 IHTMLMetaElement_Release(meta);
4348 #define set_meta_charset(a,b) _set_meta_charset(__LINE__,a,b)
4349 static void _set_meta_charset(unsigned line, IUnknown *unk, const char *vala)
4351 BSTR val = a2bstr(vala);
4352 IHTMLMetaElement *meta;
4353 HRESULT hres;
4355 meta = _get_metaelem_iface(line, unk);
4356 hres = IHTMLMetaElement_put_charset(meta, val);
4357 ok_(__FILE__,line)(hres == S_OK, "put_charset failed: %08x\n", hres);
4358 SysFreeString(val);
4359 IHTMLMetaElement_Release(meta);
4361 _test_meta_charset(line, unk, vala);
4364 #define test_link_media(a,b) _test_link_media(__LINE__,a,b)
4365 static void _test_link_media(unsigned line, IHTMLElement *elem, const char *exval)
4367 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4368 HRESULT hres;
4369 BSTR str;
4371 str = a2bstr(exval);
4372 hres = IHTMLLinkElement_put_media(link, str);
4373 ok_(__FILE__,line)(hres == S_OK, "put_media(%s) failed: %08x\n", exval, hres);
4374 SysFreeString(str);
4376 hres = IHTMLLinkElement_get_media(link, &str);
4377 ok_(__FILE__,line)(hres == S_OK, "get_media failed: %08x\n", hres);
4378 ok_(__FILE__,line)(!strcmp_wa(str, exval), "got %s, expected %s\n", wine_dbgstr_w(str), exval);
4379 SysFreeString(str);
4380 IHTMLLinkElement_Release(link);
4383 #define test_link_disabled(a,b) _test_link_disabled(__LINE__,a,b)
4384 static void _test_link_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
4386 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4387 VARIANT_BOOL b = 10;
4388 HRESULT hres;
4390 hres = IHTMLLinkElement_get_disabled(link, &b);
4391 ok_(__FILE__,line)(hres == S_OK, "get_disabled failed: %08x\n", hres);
4392 ok_(__FILE__,line)(b == v, "disabled = %x, expected %x\n", b, v);
4394 IHTMLLinkElement_Release(link);
4397 #define link_put_disabled(a,b) _link_put_disabled(__LINE__,a,b)
4398 static void _link_put_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL v)
4400 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4401 HRESULT hres;
4403 hres = IHTMLLinkElement_put_disabled(link, v);
4404 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4405 IHTMLLinkElement_Release(link);
4406 _test_link_disabled(line, elem, v);
4409 #define test_link_rel(a,b) _test_link_rel(__LINE__,a,b)
4410 static void _test_link_rel(unsigned line, IHTMLElement *elem, const char *v)
4412 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4413 BSTR rel;
4414 HRESULT hres;
4416 hres = IHTMLLinkElement_get_rel(link, &rel);
4417 ok_(__FILE__,line)(hres == S_OK, "get_rel failed: %08x\n", hres);
4418 if(v)
4419 ok_(__FILE__,line)(!strcmp_wa(rel, v), "rel = %s, expected %s\n", wine_dbgstr_w(rel), v);
4420 else
4421 ok_(__FILE__,line)(!rel, "rel = %s, expected NULL\n", wine_dbgstr_w(rel));
4423 IHTMLLinkElement_Release(link);
4426 #define link_put_rel(a,b) _link_put_rel(__LINE__,a,b)
4427 static void _link_put_rel(unsigned line, IHTMLElement *elem, const char *v)
4429 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4430 BSTR str = a2bstr(v);
4431 HRESULT hres;
4433 hres = IHTMLLinkElement_put_rel(link, str);
4434 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4435 SysFreeString(str);
4436 IHTMLLinkElement_Release(link);
4437 _test_link_rel(line, elem, v);
4440 #define test_link_rev(a,b) _test_link_rev(__LINE__,a,b)
4441 static void _test_link_rev(unsigned line, IHTMLElement *elem, const char *v)
4443 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4444 BSTR rev;
4445 HRESULT hres;
4447 hres = IHTMLLinkElement_get_rev(link, &rev);
4448 ok_(__FILE__,line)(hres == S_OK, "get_rev failed: %08x\n", hres);
4449 if(v)
4450 ok_(__FILE__,line)(!strcmp_wa(rev, v), "rev = %s, expected %s\n", wine_dbgstr_w(rev), v);
4451 else
4452 ok_(__FILE__,line)(!rev, "rev = %s, expected NULL\n", wine_dbgstr_w(rev));
4454 IHTMLLinkElement_Release(link);
4457 #define link_put_rev(a,b) _link_put_rev(__LINE__,a,b)
4458 static void _link_put_rev(unsigned line, IHTMLElement *elem, const char *v)
4460 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4461 BSTR str = a2bstr(v);
4462 HRESULT hres;
4464 hres = IHTMLLinkElement_put_rev(link, str);
4465 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4466 SysFreeString(str);
4467 IHTMLLinkElement_Release(link);
4468 _test_link_rev(line, elem, v);
4471 #define test_link_type(a,b) _test_link_type(__LINE__,a,b)
4472 static void _test_link_type(unsigned line, IHTMLElement *elem, const char *v)
4474 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4475 BSTR type;
4476 HRESULT hres;
4478 hres = IHTMLLinkElement_get_type(link, &type);
4479 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
4480 if(v)
4481 ok_(__FILE__,line)(!strcmp_wa(type, v), "type = %s, expected %s\n", wine_dbgstr_w(type), v);
4482 else
4483 ok_(__FILE__,line)(!type, "type = %s, expected NULL\n", wine_dbgstr_w(type));
4485 IHTMLLinkElement_Release(link);
4488 #define test_script_text(a,b) _test_script_text(__LINE__,a,b)
4489 static void _test_script_text(unsigned line, IHTMLScriptElement *script, const char *extext)
4491 BSTR str;
4492 HRESULT hres;
4494 str = (void*)0xdeadbeef;
4495 hres = IHTMLScriptElement_get_text(script, &str);
4496 ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
4497 ok(!strcmp_wa(str, extext), "text = %s, expected \"%s\"\n", wine_dbgstr_w(str), extext);
4498 SysFreeString(str);
4501 #define link_put_type(a,b) _link_put_type(__LINE__,a,b)
4502 static void _link_put_type(unsigned line, IHTMLElement *elem, const char *v)
4504 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4505 BSTR str = a2bstr(v);
4506 HRESULT hres;
4508 hres = IHTMLLinkElement_put_type(link, str);
4509 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4510 SysFreeString(str);
4511 IHTMLLinkElement_Release(link);
4512 _test_link_type(line, elem, v);
4515 #define test_link_href(a,b) _test_link_href(__LINE__,a,b)
4516 static void _test_link_href(unsigned line, IHTMLElement *elem, const char *v)
4518 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4519 BSTR href;
4520 HRESULT hres;
4522 hres = IHTMLLinkElement_get_href(link, &href);
4523 ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
4524 if(v)
4525 ok_(__FILE__,line)(!strcmp_wa(href, v), "href = %s, expected %s\n", wine_dbgstr_w(href), v);
4526 else
4527 ok_(__FILE__,line)(!href, "href = %s, expected NULL\n", wine_dbgstr_w(href));
4529 IHTMLLinkElement_Release(link);
4532 #define link_put_href(a,b) _link_put_href(__LINE__,a,b)
4533 static void _link_put_href(unsigned line, IHTMLElement *elem, const char *v)
4535 IHTMLLinkElement *link = _get_link_iface(line, (IUnknown*)elem);
4536 BSTR str = a2bstr(v);
4537 HRESULT hres;
4539 hres = IHTMLLinkElement_put_href(link, str);
4540 ok_(__FILE__,line)(hres == S_OK, "put_disabled failed: %08x\n", hres);
4541 SysFreeString(str);
4542 IHTMLLinkElement_Release(link);
4543 _test_link_href(line, elem, v);
4546 #define get_elem_doc(e) _get_elem_doc(__LINE__,e)
4547 static IHTMLDocument2 *_get_elem_doc(unsigned line, IUnknown *unk)
4549 IHTMLElement *elem = _get_elem_iface(line, unk);
4550 IHTMLDocument2 *doc;
4551 IDispatch *disp;
4552 HRESULT hres;
4554 disp = NULL;
4555 hres = IHTMLElement_get_document(elem, &disp);
4556 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4557 ok(disp != NULL, "disp == NULL\n");
4559 hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&doc);
4560 IDispatch_Release(disp);
4561 ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
4563 return doc;
4566 #define get_elem_attr_node(a,b,c) _get_elem_attr_node(__LINE__,a,b,c)
4567 static IHTMLDOMAttribute *_get_elem_attr_node(unsigned line, IUnknown *unk, const char *attr_name, BOOL expect_success)
4569 IHTMLElement4 *elem = _get_elem4_iface(line, unk);
4570 BSTR str = a2bstr(attr_name);
4571 IHTMLDOMAttribute *attr;
4572 HRESULT hres;
4574 attr = (void*)0xdeadbeef;
4575 hres = IHTMLElement4_getAttributeNode(elem, str, &attr);
4576 ok_(__FILE__,line)(hres == S_OK, "getAttributeNode failed: %08x\n", hres);
4577 if(expect_success)
4578 ok_(__FILE__,line)(attr != NULL, "attr = NULL\n");
4579 else
4580 ok_(__FILE__,line)(!attr, "attr = %p\n", attr);
4582 IHTMLElement4_Release(elem);
4583 SysFreeString(str);
4584 return attr;
4587 #define get_attr_node_value(a,b,c) _get_attr_node_value(__LINE__,a,b,c)
4588 static void _get_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT *v, VARTYPE vt)
4590 HRESULT hres;
4592 hres = IHTMLDOMAttribute_get_nodeValue(attr, v);
4593 ok_(__FILE__,line) (hres == S_OK, "get_nodeValue failed: %08x\n", hres);
4594 ok_(__FILE__,line) (V_VT(v) == vt, "vt=%d, expected %d\n", V_VT(v), vt);
4597 #define put_attr_node_value(a,b) _put_attr_node_value(__LINE__,a,b)
4598 static void _put_attr_node_value(unsigned line, IHTMLDOMAttribute *attr, VARIANT v)
4600 HRESULT hres;
4602 hres = IHTMLDOMAttribute_put_nodeValue(attr, v);
4603 ok_(__FILE__,line) (hres == S_OK, "put_nodeValue failed: %08x\n", hres);
4606 #define get_window_doc(e) _get_window_doc(__LINE__,e)
4607 static IHTMLDocument2 *_get_window_doc(unsigned line, IHTMLWindow2 *window)
4609 IHTMLDocument2 *doc;
4610 HRESULT hres;
4612 doc = NULL;
4613 hres = IHTMLWindow2_get_document(window, &doc);
4614 ok(hres == S_OK, "get_document failed: %08x\n", hres);
4615 ok(doc != NULL, "disp == NULL\n");
4617 return doc;
4620 #define doc_get_body(d) _doc_get_body(__LINE__,d)
4621 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
4623 IHTMLElement *elem;
4624 HRESULT hres;
4626 hres = IHTMLDocument2_get_body(doc, &elem);
4627 ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
4628 ok_(__FILE__,line)(elem != NULL, "body == NULL\n");
4630 return elem;
4633 #define test_create_elem(d,t) _test_create_elem(__LINE__,d,t)
4634 static IHTMLElement *_test_create_elem(unsigned line, IHTMLDocument2 *doc, const char *tag)
4636 IHTMLElement *elem = NULL;
4637 BSTR tmp;
4638 HRESULT hres;
4640 tmp = a2bstr(tag);
4641 hres = IHTMLDocument2_createElement(doc, tmp, &elem);
4642 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
4643 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
4644 SysFreeString(tmp);
4646 return elem;
4649 #define test_create_text(d,t) _test_create_text(__LINE__,d,t)
4650 static IHTMLDOMNode *_test_create_text(unsigned line, IHTMLDocument2 *doc, const char *text)
4652 IHTMLDocument3 *doc3;
4653 IHTMLDOMNode *node = NULL;
4654 BSTR tmp;
4655 HRESULT hres;
4657 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4658 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3: %08x\n", hres);
4660 tmp = a2bstr(text);
4661 hres = IHTMLDocument3_createTextNode(doc3, tmp, &node);
4662 IHTMLDocument3_Release(doc3);
4663 SysFreeString(tmp);
4664 ok_(__FILE__,line) (hres == S_OK, "createElement failed: %08x\n", hres);
4665 ok_(__FILE__,line) (node != NULL, "node == NULL\n");
4667 return node;
4670 #define test_node_append_child(n,c) _test_node_append_child(__LINE__,n,c)
4671 static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, IUnknown *child_unk)
4673 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
4674 IHTMLDOMNode *child = _get_node_iface(line, child_unk);
4675 IHTMLDOMNode *new_child = NULL;
4676 HRESULT hres;
4678 hres = IHTMLDOMNode_appendChild(node, child, &new_child);
4679 ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres);
4680 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
4681 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
4683 IHTMLDOMNode_Release(node);
4684 IHTMLDOMNode_Release(child);
4686 return new_child;
4689 #define test_node_insertbefore(n,c,v) _test_node_insertbefore(__LINE__,n,c,v)
4690 static IHTMLDOMNode *_test_node_insertbefore(unsigned line, IUnknown *node_unk, IHTMLDOMNode *child, VARIANT *var)
4692 IHTMLDOMNode *node = _get_node_iface(line, node_unk);
4693 IHTMLDOMNode *new_child = NULL;
4694 HRESULT hres;
4696 hres = IHTMLDOMNode_insertBefore(node, child, *var, &new_child);
4697 ok_(__FILE__,line) (hres == S_OK, "insertBefore failed: %08x\n", hres);
4698 ok_(__FILE__,line) (new_child != NULL, "new_child == NULL\n");
4699 /* TODO ok_(__FILE__,line) (new_child != child, "new_child == child\n"); */
4701 IHTMLDOMNode_Release(node);
4703 return new_child;
4706 #define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c)
4707 static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child)
4709 IHTMLDOMNode *node = _get_node_iface(line, unk);
4710 IHTMLDOMNode *new_node = NULL;
4711 HRESULT hres;
4713 hres = IHTMLDOMNode_removeChild(node, child, &new_node);
4714 ok_(__FILE__,line) (hres == S_OK, "removeChild failed: %08x\n", hres);
4715 ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n");
4716 /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */
4718 IHTMLDOMNode_Release(node);
4719 IHTMLDOMNode_Release(new_node);
4722 #define test_doc_title(d,t) _test_doc_title(__LINE__,d,t)
4723 static void _test_doc_title(unsigned line, IHTMLDocument2 *doc, const char *extitle)
4725 BSTR title = NULL;
4726 HRESULT hres;
4728 hres = IHTMLDocument2_get_title(doc, &title);
4729 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4730 ok_(__FILE__,line) (!strcmp_wa(title, extitle), "unexpected title %s\n", wine_dbgstr_w(title));
4731 SysFreeString(title);
4734 #define test_doc_set_title(d,t) _test_doc_set_title(__LINE__,d,t)
4735 static void _test_doc_set_title(unsigned line, IHTMLDocument2 *doc, const char *title)
4737 BSTR tmp;
4738 HRESULT hres;
4740 tmp = a2bstr(title);
4741 hres = IHTMLDocument2_put_title(doc, tmp);
4742 ok_(__FILE__,line) (hres == S_OK, "get_title failed: %08x\n", hres);
4743 SysFreeString(tmp);
4746 static void test_elem_bounding_client_rect(IUnknown *unk)
4748 IHTMLRect *rect, *rect2;
4749 IHTMLElement2 *elem2;
4750 LONG l;
4751 HRESULT hres;
4753 elem2 = get_elem2_iface(unk);
4754 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect);
4755 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
4756 hres = IHTMLElement2_getBoundingClientRect(elem2, &rect2);
4757 IHTMLElement2_Release(elem2);
4758 ok(hres == S_OK, "getBoundingClientRect failed: %08x\n", hres);
4759 ok(rect != NULL, "rect == NULL\n");
4760 ok(rect != rect2, "rect == rect2\n");
4761 IHTMLRect_Release(rect2);
4763 test_disp((IUnknown*)rect, &IID_IHTMLRect, "[object]");
4765 l = 0xdeadbeef;
4766 hres = IHTMLRect_get_top(rect, &l);
4767 ok(hres == S_OK, "get_top failed: %08x\n", hres);
4768 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4770 l = 0xdeadbeef;
4771 hres = IHTMLRect_get_left(rect, &l);
4772 ok(hres == S_OK, "get_left failed: %08x\n", hres);
4773 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4775 l = 0xdeadbeef;
4776 hres = IHTMLRect_get_bottom(rect, &l);
4777 ok(hres == S_OK, "get_bottom failed: %08x\n", hres);
4778 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4780 l = 0xdeadbeef;
4781 hres = IHTMLRect_get_right(rect, &l);
4782 ok(hres == S_OK, "get_right failed: %08x\n", hres);
4783 ok(l != 0xdeadbeef, "l = 0xdeadbeef\n");
4785 IHTMLRect_Release(rect);
4788 static void test_elem_col_item(IHTMLElementCollection *col, const char *n,
4789 const elem_type_t *elem_types, LONG len)
4791 IDispatch *disp;
4792 VARIANT name, index;
4793 DWORD i;
4794 HRESULT hres;
4796 V_VT(&index) = VT_EMPTY;
4797 V_VT(&name) = VT_BSTR;
4798 V_BSTR(&name) = a2bstr(n);
4800 hres = IHTMLElementCollection_item(col, name, index, &disp);
4801 ok(hres == S_OK, "item failed: %08x\n", hres);
4803 test_elem_collection((IUnknown*)disp, elem_types, len);
4804 IDispatch_Release(disp);
4806 V_VT(&index) = VT_I4;
4808 for(i=0; i<len; i++) {
4809 V_I4(&index) = i;
4810 disp = (void*)0xdeadbeef;
4811 hres = IHTMLElementCollection_item(col, name, index, &disp);
4812 ok(hres == S_OK, "item failed: %08x\n", hres);
4813 ok(disp != NULL, "disp == NULL\n");
4814 if(FAILED(hres) || !disp)
4815 continue;
4817 test_elem_type((IUnknown*)disp, elem_types[i]);
4819 IDispatch_Release(disp);
4822 V_I4(&index) = len;
4823 disp = (void*)0xdeadbeef;
4824 hres = IHTMLElementCollection_item(col, name, index, &disp);
4825 ok(hres == S_OK, "item failed: %08x\n", hres);
4826 ok(disp == NULL, "disp != NULL\n");
4828 V_I4(&index) = -1;
4829 disp = (void*)0xdeadbeef;
4830 hres = IHTMLElementCollection_item(col, name, index, &disp);
4831 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4832 ok(disp == NULL, "disp != NULL\n");
4834 SysFreeString(V_BSTR(&name));
4837 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id, BOOL expect_success)
4839 IHTMLElementCollection *col;
4840 IHTMLElement *elem;
4841 IDispatch *disp = (void*)0xdeadbeef;
4842 VARIANT name, index;
4843 HRESULT hres;
4845 hres = IHTMLDocument2_get_all(doc, &col);
4846 ok(hres == S_OK, "get_all failed: %08x\n", hres);
4847 ok(col != NULL, "col == NULL\n");
4848 if(FAILED(hres) || !col)
4849 return NULL;
4851 V_VT(&index) = VT_EMPTY;
4852 V_VT(&name) = VT_BSTR;
4853 V_BSTR(&name) = a2bstr(id);
4855 hres = IHTMLElementCollection_item(col, name, index, &disp);
4856 IHTMLElementCollection_Release(col);
4857 SysFreeString(V_BSTR(&name));
4858 ok(hres == S_OK, "item failed: %08x\n", hres);
4859 if(!expect_success) {
4860 ok(disp == NULL, "disp != NULL\n");
4861 return NULL;
4864 ok(disp != NULL, "disp == NULL\n");
4865 if(!disp)
4866 return NULL;
4868 elem = get_elem_iface((IUnknown*)disp);
4869 IDispatch_Release(disp);
4871 return elem;
4874 static IHTMLElement *get_doc_elem_by_id(IHTMLDocument2 *doc, const char *id)
4876 IHTMLDocument3 *doc3;
4877 IHTMLElement *elem;
4878 BSTR tmp;
4879 HRESULT hres;
4881 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
4882 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
4884 tmp = a2bstr(id);
4885 hres = IHTMLDocument3_getElementById(doc3, tmp, &elem);
4886 SysFreeString(tmp);
4887 ok(hres == S_OK, "getElementById(%s) failed: %08x\n", id, hres);
4889 IHTMLDocument3_Release(doc3);
4891 return elem;
4894 static void test_select_elem(IHTMLSelectElement *select)
4896 IDispatch *disp, *disp2;
4897 VARIANT name, index;
4898 HRESULT hres;
4900 test_select_type(select, "select-one");
4901 test_select_length(select, 2);
4902 test_select_selidx(select, 0);
4903 test_select_put_selidx(select, 1);
4905 test_select_set_value(select, "val1");
4906 test_select_value(select, "val1");
4908 test_select_size(select, 0);
4909 test_select_set_size(select, 1, S_OK);
4910 test_select_size(select, 1);
4912 test_select_set_size(select, -1, CTL_E_INVALIDPROPERTYVALUE);
4913 test_select_size(select, 1);
4914 test_select_set_size(select, 3, S_OK);
4915 test_select_size(select, 3);
4917 test_select_get_disabled(select, VARIANT_FALSE);
4918 test_select_set_disabled(select, VARIANT_TRUE);
4919 test_select_set_disabled(select, VARIANT_FALSE);
4921 disp = NULL;
4922 hres = IHTMLSelectElement_get_options(select, &disp);
4923 ok(hres == S_OK, "get_options failed: %08x\n", hres);
4924 ok(disp != NULL, "options == NULL\n");
4925 ok(iface_cmp((IUnknown*)disp, (IUnknown*)select), "disp != select\n");
4926 IDispatch_Release(disp);
4928 V_VT(&index) = VT_EMPTY;
4929 V_VT(&name) = VT_I4;
4930 V_I4(&name) = -1;
4931 disp = (void*)0xdeadbeef;
4932 hres = IHTMLSelectElement_item(select, name, index, &disp);
4933 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4934 ok(!disp, "disp = %p\n", disp);
4936 V_I4(&name) = 2;
4937 disp = (void*)0xdeadbeef;
4938 hres = IHTMLSelectElement_item(select, name, index, &disp);
4939 ok(hres == S_OK, "item failed: %08x\n", hres);
4940 ok(!disp, "disp = %p\n", disp);
4942 V_I4(&name) = 1;
4943 hres = IHTMLSelectElement_item(select, name, index, NULL);
4944 ok(hres == E_POINTER || broken(hres == E_INVALIDARG), "item failed: %08x, expected E_POINTER\n", hres);
4946 disp = NULL;
4947 hres = IHTMLSelectElement_item(select, name, index, &disp);
4948 ok(hres == S_OK, "item failed: %08x\n", hres);
4949 ok(disp != NULL, "disp = NULL\n");
4950 test_disp((IUnknown*)disp, &DIID_DispHTMLOptionElement, NULL);
4952 V_VT(&index) = VT_I4;
4953 V_I4(&index) = 1;
4954 disp2 = NULL;
4955 hres = IHTMLSelectElement_item(select, name, index, &disp2);
4956 ok(hres == S_OK, "item failed: %08x\n", hres);
4957 ok(disp2 != NULL, "disp = NULL\n");
4958 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
4959 IDispatch_Release(disp2);
4960 IDispatch_Release(disp);
4962 test_select_multiple(select, VARIANT_FALSE);
4963 test_select_set_multiple(select, VARIANT_TRUE);
4964 test_select_remove(select);
4967 static void test_form_item(IHTMLElement *elem)
4969 IHTMLFormElement *form = get_form_iface((IUnknown*)elem);
4970 IDispatch *disp, *disp2;
4971 VARIANT name, index;
4972 HRESULT hres;
4974 V_VT(&index) = VT_EMPTY;
4975 V_VT(&name) = VT_I4;
4976 V_I4(&name) = -1;
4977 disp = (void*)0xdeadbeef;
4978 hres = IHTMLFormElement_item(form, name, index, &disp);
4979 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4980 ok(!disp, "disp = %p\n", disp);
4982 V_I4(&name) = 2;
4983 disp = (void*)0xdeadbeef;
4984 hres = IHTMLFormElement_item(form, name, index, &disp);
4985 ok(hres == S_OK, "item failed: %08x\n", hres);
4986 ok(!disp, "disp = %p\n", disp);
4988 V_I4(&name) = 1;
4989 hres = IHTMLFormElement_item(form, name, index, NULL);
4990 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
4992 disp = NULL;
4993 hres = IHTMLFormElement_item(form, name, index, &disp);
4994 ok(hres == S_OK, "item failed: %08x\n", hres);
4995 ok(disp != NULL, "disp = NULL\n");
4996 test_disp((IUnknown*)disp, &DIID_DispHTMLInputElement, NULL);
4998 V_VT(&index) = VT_I4;
4999 V_I4(&index) = 1;
5000 disp2 = NULL;
5001 hres = IHTMLFormElement_item(form, name, index, &disp2);
5002 ok(hres == S_OK, "item failed: %08x\n", hres);
5003 ok(disp2 != NULL, "disp = NULL\n");
5004 ok(iface_cmp((IUnknown*)disp, (IUnknown*)disp2), "disp != disp2\n");
5005 IDispatch_Release(disp2);
5006 IDispatch_Release(disp);
5009 static void test_create_option_elem(IHTMLDocument2 *doc)
5011 IHTMLOptionElement *option;
5013 option = create_option_elem(doc, "test text", "test value");
5015 test_option_put_text(option, "new text");
5016 test_option_put_value(option, "new value");
5017 test_option_get_index(option, 0);
5018 test_option_put_selected(option, VARIANT_TRUE);
5019 test_option_put_selected(option, VARIANT_FALSE);
5021 IHTMLOptionElement_Release(option);
5024 static void test_create_img_elem(IHTMLDocument2 *doc)
5026 IHTMLImgElement *img;
5028 img = create_img_elem(doc, 10, 15);
5030 if(img){
5031 test_img_put_width(img, 5);
5032 test_img_put_height(img, 20);
5034 IHTMLImgElement_Release(img);
5035 img = NULL;
5038 img = create_img_elem(doc, -1, -1);
5040 if(img){
5041 test_img_put_width(img, 5);
5042 test_img_put_height(img, 20);
5044 IHTMLImgElement_Release(img);
5048 #define insert_adjacent_elem(a,b,c) _insert_adjacent_elem(__LINE__,a,b,c)
5049 static void _insert_adjacent_elem(unsigned line, IHTMLElement *parent, const char *where, IHTMLElement *elem)
5051 IHTMLElement2 *elem2 = _get_elem2_iface(line, (IUnknown*)parent);
5052 IHTMLElement *ret_elem = NULL;
5053 BSTR str = a2bstr(where);
5054 HRESULT hres;
5056 hres = IHTMLElement2_insertAdjacentElement(elem2, str, elem, &ret_elem);
5057 IHTMLElement2_Release(elem2);
5058 SysFreeString(str);
5059 ok_(__FILE__,line)(hres == S_OK, "insertAdjacentElement failed: %08x\n", hres);
5060 ok_(__FILE__,line)(ret_elem == elem, "ret_elem != elem\n");
5061 IHTMLElement_Release(ret_elem);
5064 static void test_insert_adjacent_elems(IHTMLDocument2 *doc, IHTMLElement *parent)
5066 IHTMLElement *elem, *elem2;
5068 static const elem_type_t br_br[] = {ET_BR, ET_BR};
5069 static const elem_type_t br_div_br[] = {ET_BR, ET_DIV, ET_BR};
5071 elem = test_create_elem(doc, "BR");
5072 insert_adjacent_elem(parent, "BeforeEnd", elem);
5073 IHTMLElement_Release(elem);
5075 test_elem_all((IUnknown*)parent, br_br, 1);
5077 elem = test_create_elem(doc, "BR");
5078 insert_adjacent_elem(parent, "beforeend", elem);
5080 test_elem_all((IUnknown*)parent, br_br, 2);
5082 elem2 = test_create_elem(doc, "DIV");
5083 insert_adjacent_elem(elem, "beforebegin", elem2);
5084 IHTMLElement_Release(elem2);
5085 IHTMLElement_Release(elem);
5087 test_elem_all((IUnknown*)parent, br_div_br, 3);
5090 static IHTMLTxtRange *test_create_body_range(IHTMLDocument2 *doc)
5092 IHTMLBodyElement *body;
5093 IHTMLTxtRange *range;
5094 IHTMLElement *elem;
5095 HRESULT hres;
5097 elem = doc_get_body(doc);
5098 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
5099 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
5100 IHTMLElement_Release(elem);
5102 hres = IHTMLBodyElement_createTextRange(body, &range);
5103 IHTMLBodyElement_Release(body);
5104 ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
5106 return range;
5109 #define range_duplicate(a) _range_duplicate(__LINE__,a)
5110 static IHTMLTxtRange *_range_duplicate(unsigned line, IHTMLTxtRange *range)
5112 IHTMLTxtRange *ret;
5113 HRESULT hres;
5115 hres = IHTMLTxtRange_duplicate(range, &ret);
5116 ok_(__FILE__,line)(hres == S_OK, "duplicate failed: %08x\n", hres);
5118 return ret;
5121 #define test_range_set_end_point(a,b,c,d) _test_range_set_end_point(__LINE__,a,b,c,d)
5122 static void _test_range_set_end_point(unsigned line, IHTMLTxtRange *range, const char *how,
5123 IHTMLTxtRange *ref_range, HRESULT exhres)
5125 BSTR str = a2bstr(how);
5126 HRESULT hres;
5128 hres = IHTMLTxtRange_setEndPoint(range, str, ref_range);
5129 ok_(__FILE__,line)(hres == exhres, "setEndPoint failed: %08x, expected %08x\n", hres, exhres);
5130 SysFreeString(str);
5133 static void test_txtrange(IHTMLDocument2 *doc)
5135 IHTMLTxtRange *body_range, *range, *range2;
5136 IHTMLSelectionObject *selection;
5137 IDispatch *disp_range;
5138 IHTMLElement *body;
5139 HRESULT hres;
5141 body_range = test_create_body_range(doc);
5143 test_disp((IUnknown*)body_range, &IID_IHTMLTxtRange, "[object]");
5145 test_range_text(body_range, "test abc 123\r\nit's text");
5147 range = range_duplicate(body_range);
5148 range2 = range_duplicate(body_range);
5150 test_range_isequal(range, range2, VARIANT_TRUE);
5152 test_range_text(range, "test abc 123\r\nit's text");
5153 test_range_text(body_range, "test abc 123\r\nit's text");
5155 test_range_collapse(range, TRUE);
5156 test_range_isequal(range, range2, VARIANT_FALSE);
5157 test_range_inrange(range, range2, VARIANT_FALSE);
5158 test_range_inrange(range2, range, VARIANT_TRUE);
5159 IHTMLTxtRange_Release(range2);
5161 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
5162 test_range_expand(range, wordW, VARIANT_FALSE, "test ");
5163 test_range_move(range, characterW, 2, 2);
5164 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
5166 test_range_collapse(range, FALSE);
5167 test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
5169 test_range_collapse(range, FALSE);
5170 test_range_expand(range, wordW, VARIANT_TRUE, "123");
5171 test_range_expand(range, wordW, VARIANT_FALSE, "123");
5172 test_range_move(range, characterW, 2, 2);
5173 test_range_expand(range, wordW, VARIANT_TRUE, "123");
5174 test_range_moveend(range, characterW, -5, -5);
5175 test_range_text(range, NULL);
5176 test_range_moveend(range, characterW, 3, 3);
5177 test_range_text(range, "c 1");
5178 test_range_expand(range, texteditW, VARIANT_TRUE, "test abc 123\r\nit's text");
5179 test_range_collapse(range, TRUE);
5180 test_range_move(range, characterW, 4, 4);
5181 test_range_moveend(range, characterW, 1, 1);
5182 test_range_text(range, " ");
5183 test_range_move(range, wordW, 1, 1);
5184 test_range_moveend(range, characterW, 2, 2);
5185 test_range_text(range, "ab");
5187 IHTMLTxtRange_Release(range);
5189 range = range_duplicate(body_range);
5191 test_range_text(range, "test abc 123\r\nit's text");
5192 test_range_move(range, characterW, 3, 3);
5193 test_range_moveend(range, characterW, 1, 1);
5194 test_range_text(range, "t");
5195 test_range_moveend(range, characterW, 3, 3);
5196 test_range_text(range, "t ab");
5197 test_range_moveend(range, characterW, -2, -2);
5198 test_range_text(range, "t ");
5199 test_range_move(range, characterW, 6, 6);
5200 test_range_moveend(range, characterW, 3, 3);
5201 test_range_text(range, "123");
5202 test_range_moveend(range, characterW, 2, 2);
5203 test_range_text(range, "123\r\ni");
5205 IHTMLTxtRange_Release(range);
5207 range = range_duplicate(body_range);
5209 test_range_move(range, wordW, 1, 1);
5210 test_range_moveend(range, characterW, 2, 2);
5211 test_range_text(range, "ab");
5213 test_range_move(range, characterW, -2, -2);
5214 test_range_moveend(range, characterW, 2, 2);
5215 test_range_text(range, "t ");
5217 test_range_move(range, wordW, 3, 3);
5218 test_range_move(range, wordW, -2, -2);
5219 test_range_moveend(range, characterW, 2, 2);
5220 test_range_text(range, "ab");
5222 test_range_move(range, characterW, -6, -5);
5223 test_range_moveend(range, characterW, -1, 0);
5224 test_range_moveend(range, characterW, -6, 0);
5225 test_range_move(range, characterW, 2, 2);
5226 test_range_moveend(range, characterW, 2, 2);
5227 test_range_text(range, "st");
5228 test_range_moveend(range, characterW, -6, -4);
5229 test_range_moveend(range, characterW, 2, 2);
5231 IHTMLTxtRange_Release(range);
5233 range = range_duplicate(body_range);
5235 test_range_move(range, wordW, 2, 2);
5236 test_range_moveend(range, characterW, 2, 2);
5237 test_range_text(range, "12");
5239 test_range_move(range, characterW, 15, 14);
5240 test_range_move(range, characterW, -2, -2);
5241 test_range_moveend(range, characterW, 3, 2);
5242 test_range_text(range, "t");
5243 test_range_moveend(range, characterW, -1, -1);
5244 test_range_text(range, "t");
5245 test_range_expand(range, wordW, VARIANT_TRUE, "text");
5246 test_range_move(range, characterW, -2, -2);
5247 test_range_moveend(range, characterW, 2, 2);
5248 test_range_text(range, "s ");
5249 test_range_move(range, characterW, 100, 7);
5250 test_range_move(range, wordW, 1, 0);
5251 test_range_move(range, characterW, -2, -2);
5252 test_range_moveend(range, characterW, 3, 2);
5253 test_range_text(range, "t");
5255 IHTMLTxtRange_Release(range);
5257 range = range_duplicate(body_range);
5259 test_range_collapse(range, TRUE);
5260 test_range_expand(range, wordW, VARIANT_TRUE, "test ");
5261 test_range_put_text(range, "word");
5262 test_range_text(body_range, "wordabc 123\r\nit's text");
5263 test_range_text(range, NULL);
5264 test_range_moveend(range, characterW, 3, 3);
5265 test_range_text(range, "abc");
5266 test_range_movestart(range, characterW, -2, -2);
5267 test_range_text(range, "rdabc");
5268 test_range_movestart(range, characterW, 3, 3);
5269 test_range_text(range, "bc");
5270 test_range_movestart(range, characterW, 4, 4);
5271 test_range_text(range, NULL);
5272 test_range_movestart(range, characterW, -3, -3);
5273 test_range_text(range, "c 1");
5274 test_range_movestart(range, characterW, -7, -6);
5275 test_range_text(range, "wordabc 1");
5276 test_range_movestart(range, characterW, 100, 22);
5277 test_range_text(range, NULL);
5279 IHTMLTxtRange_Release(range);
5281 hres = IHTMLDocument2_get_selection(doc, &selection);
5282 ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres);
5284 test_disp((IUnknown*)selection, &IID_IHTMLSelectionObject, "[object]");
5285 test_ifaces((IUnknown*)selection, selection_iids);
5287 hres = IHTMLSelectionObject_createRange(selection, &disp_range);
5288 ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres);
5289 IHTMLSelectionObject_Release(selection);
5291 hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range);
5292 ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres);
5293 IDispatch_Release(disp_range);
5295 test_range_text(range, NULL);
5296 test_range_moveend(range, characterW, 3, 3);
5297 test_range_text(range, "wor");
5298 test_range_parent(range, ET_BODY);
5299 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
5300 test_range_expand(range, texteditW, VARIANT_TRUE, "wordabc 123\r\nit's text");
5301 test_range_move(range, characterW, 3, 3);
5302 test_range_expand(range, wordW, VARIANT_TRUE, "wordabc ");
5303 test_range_moveend(range, characterW, -4, -4);
5304 test_range_put_text(range, "abc def ");
5305 test_range_expand(range, texteditW, VARIANT_TRUE, "abc def abc 123\r\nit's text");
5306 test_range_move(range, wordW, 1, 1);
5307 test_range_movestart(range, characterW, -1, -1);
5308 test_range_text(range, " ");
5309 test_range_move(range, wordW, 1, 1);
5310 test_range_moveend(range, characterW, 3, 3);
5311 test_range_text(range, "def");
5312 test_range_put_text(range, "xyz");
5313 test_range_moveend(range, characterW, 1, 1);
5314 test_range_move(range, wordW, 1, 1);
5315 test_range_moveend(range, characterW, 2, 2);
5316 test_range_text(range, "ab");
5318 body = doc_get_body(doc);
5320 hres = IHTMLTxtRange_moveToElementText(range, body);
5321 ok(hres == S_OK, "moveToElementText failed: %08x\n", hres);
5323 test_range_text(range, "abc xyz abc 123\r\nit's text");
5324 test_range_parent(range, ET_BODY);
5326 test_range_move(range, wordW, 1, 1);
5327 test_range_moveend(range, characterW, 12, 12);
5328 test_range_text(range, "xyz abc 123");
5330 test_range_collapse(range, VARIANT_TRUE);
5331 test_range_paste_html(range, "<br>paste<br>");
5332 test_range_text(range, NULL);
5334 test_range_moveend(range, characterW, 3, 3);
5335 test_range_text(range, "xyz");
5337 hres = IHTMLTxtRange_moveToElementText(range, body);
5338 ok(hres == S_OK, "moveToElementText failed: %08x\n", hres);
5340 test_range_text(range, "abc \r\npaste\r\nxyz abc 123\r\nit's text");
5342 test_range_move(range, wordW, 2, 2);
5343 test_range_collapse(range, VARIANT_TRUE);
5344 test_range_moveend(range, characterW, 5, 5);
5345 test_range_text(range, "paste");
5347 range2 = range_duplicate(range);
5349 test_range_set_end_point(range, "starttostart", body_range, S_OK);
5350 test_range_text(range, "abc \r\npaste");
5352 test_range_set_end_point(range, "endtoend", body_range, S_OK);
5353 test_range_text(range, "abc \r\npaste\r\nxyz abc 123\r\nit's text");
5355 test_range_set_end_point(range, "starttoend", range2, S_OK);
5356 test_range_text(range, "\r\nxyz abc 123\r\nit's text");
5358 test_range_set_end_point(range, "starttostart", body_range, S_OK);
5359 test_range_set_end_point(range, "endtostart", range2, S_OK);
5360 test_range_text(range, "abc ");
5362 test_range_set_end_point(range, "starttoend", body_range, S_OK);
5363 test_range_text(range, "paste\r\nxyz abc 123\r\nit's text");
5365 test_range_set_end_point(range, "EndToStart", body_range, S_OK);
5366 test_range_text(range, "abc ");
5368 test_range_set_end_point(range, "xxx", body_range, E_INVALIDARG);
5370 IHTMLTxtRange_Release(range);
5371 IHTMLTxtRange_Release(range2);
5372 IHTMLTxtRange_Release(body_range);
5373 IHTMLElement_Release(body);
5377 static void test_txtrange2(IHTMLDocument2 *doc)
5379 IHTMLTxtRange *range;
5381 range = test_create_body_range(doc);
5383 test_range_text(range, "abc\r\n\r\n123\r\n\r\n\r\ndef");
5384 test_range_move(range, characterW, 5, 5);
5385 test_range_moveend(range, characterW, 1, 1);
5386 test_range_text(range, "2");
5387 test_range_move(range, characterW, -3, -3);
5388 test_range_moveend(range, characterW, 3, 3);
5389 test_range_text(range, "c\r\n\r\n1");
5390 test_range_collapse(range, VARIANT_FALSE);
5391 test_range_moveend(range, characterW, 4, 4);
5392 test_range_text(range, "23");
5393 test_range_moveend(range, characterW, 1, 1);
5394 test_range_text(range, "23\r\n\r\n\r\nd");
5395 test_range_moveend(range, characterW, -1, -1);
5396 test_range_text(range, "23");
5397 test_range_moveend(range, characterW, -1, -1);
5398 test_range_text(range, "23");
5399 test_range_moveend(range, characterW, -2, -2);
5400 test_range_text(range, "2");
5402 IHTMLTxtRange_Release(range);
5405 #define test_compatmode(a,b) _test_compatmode(__LINE__,a,b)
5406 static void _test_compatmode(unsigned line, IHTMLDocument2 *doc2, const char *excompat)
5408 IHTMLDocument5 *doc = get_htmldoc5_iface((IUnknown*)doc2);
5409 BSTR str;
5410 HRESULT hres;
5412 hres = IHTMLDocument5_get_compatMode(doc, &str);
5413 ok_(__FILE__,line)(hres == S_OK, "get_compatMode failed: %08x\n", hres);
5414 ok_(__FILE__,line)(!strcmp_wa(str, excompat), "compatMode = %s, expected %s\n", wine_dbgstr_w(str), excompat);
5416 IHTMLDocument5_Release(doc);
5419 static void test_location(IHTMLDocument2 *doc)
5421 IHTMLLocation *location, *location2;
5422 IHTMLWindow2 *window;
5423 BSTR str;
5424 ULONG ref;
5425 HRESULT hres;
5427 hres = IHTMLDocument2_get_location(doc, &location);
5428 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5430 hres = IHTMLDocument2_get_location(doc, &location2);
5431 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5433 ok(location == location2, "location != location2\n");
5434 IHTMLLocation_Release(location2);
5436 hres = IHTMLDocument2_get_parentWindow(doc, &window);
5437 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
5439 hres = IHTMLWindow2_get_location(window, &location2);
5440 ok(hres == S_OK, "get_location failed: %08x\n", hres);
5441 ok(location == location2, "location != location2\n");
5442 IHTMLLocation_Release(location2);
5444 test_ifaces((IUnknown*)location, location_iids);
5445 test_disp2((IUnknown*)location, &DIID_DispHTMLLocation, &IID_IHTMLLocation, "about:blank");
5447 hres = IHTMLLocation_get_pathname(location, &str);
5448 ok(hres == S_OK, "get_pathname failed: %08x\n", hres);
5449 ok(!strcmp_wa(str, "blank"), "unexpected pathname %s\n", wine_dbgstr_w(str));
5450 SysFreeString(str);
5452 hres = IHTMLLocation_get_href(location, NULL);
5453 ok(hres == E_POINTER, "get_href passed: %08x\n", hres);
5455 hres = IHTMLLocation_get_href(location, &str);
5456 ok(hres == S_OK, "get_href failed: %08x\n", hres);
5457 ok(!strcmp_wa(str, "about:blank"), "unexpected href %s\n", wine_dbgstr_w(str));
5458 SysFreeString(str);
5460 ref = IHTMLLocation_Release(location);
5461 ok(!ref, "location chould be destroyed here\n");
5464 static void test_plugins_col(IHTMLDocument2 *doc)
5466 IHTMLPluginsCollection *col, *col2;
5467 IHTMLWindow2 *window;
5468 IOmNavigator *nav;
5469 ULONG ref;
5470 LONG len;
5471 HRESULT hres;
5473 window = get_doc_window(doc);
5474 hres = IHTMLWindow2_get_navigator(window, &nav);
5475 IHTMLWindow2_Release(window);
5477 hres = IOmNavigator_get_plugins(nav, &col);
5478 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
5480 hres = IOmNavigator_get_plugins(nav, &col2);
5481 ok(hres == S_OK, "get_plugins failed: %08x\n", hres);
5482 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
5483 IHTMLPluginsCollection_Release(col2);
5485 test_disp2((IUnknown*)col, &DIID_DispCPlugins, &IID_IHTMLPluginsCollection, "[object]");
5487 len = 0xdeadbeef;
5488 hres = IHTMLPluginsCollection_get_length(col, &len);
5489 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5490 ok(!len, "length = %d\n", len);
5492 hres = IHTMLPluginsCollection_refresh(col, VARIANT_FALSE);
5493 ok(hres == S_OK, "refresh failed: %08x\n", hres);
5495 hres = IHTMLPluginsCollection_refresh(col, VARIANT_TRUE);
5496 ok(hres == S_OK, "refresh failed: %08x\n", hres);
5498 ref = IHTMLPluginsCollection_Release(col);
5499 ok(!ref, "ref=%d\n", ref);
5501 IOmNavigator_Release(nav);
5504 static void test_mime_types_col(IOmNavigator *nav)
5506 IHTMLMimeTypesCollection *col, *col2;
5507 LONG length;
5508 ULONG ref;
5509 HRESULT hres;
5511 hres = IOmNavigator_get_mimeTypes(nav, &col);
5512 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
5514 hres = IOmNavigator_get_mimeTypes(nav, &col2);
5515 ok(hres == S_OK, "get_mimeTypes failed: %08x\n", hres);
5516 ok(iface_cmp((IUnknown*)col, (IUnknown*)col2), "col != col2\n");
5517 IHTMLMimeTypesCollection_Release(col2);
5519 test_disp((IUnknown*)col, &IID_IHTMLMimeTypesCollection, "[object]");
5521 length = 0xdeadbeef;
5522 hres = IHTMLMimeTypesCollection_get_length(col, &length);
5523 ok(hres == S_OK, "get_length failed: %08x\n", hres);
5524 ok(!length, "length = %d\n", length);
5526 ref = IHTMLMimeTypesCollection_Release(col);
5527 ok(!ref, "ref=%d\n", ref);
5530 #define test_framebase_name(a,b) _test_framebase_name(__LINE__,a,b)
5531 static void _test_framebase_name(unsigned line, IHTMLElement *elem, const char *name)
5533 BSTR str = (void*)0xdeadbeef;
5534 IHTMLFrameBase *fbase;
5535 HRESULT hres;
5537 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5538 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5540 hres = IHTMLFrameBase_get_name(fbase, &str);
5541 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_name failed: 0x%08x\n", hres);
5542 if(name)
5543 ok_(__FILE__,line)(!strcmp_wa(str, name), "name = %s, expected %s\n", wine_dbgstr_w(str), name);
5544 else
5545 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
5546 SysFreeString(str);
5548 IHTMLFrameBase_Release(fbase);
5551 #define test_framebase_put_name(a,b) _test_framebase_put_name(__LINE__,a,b)
5552 static void _test_framebase_put_name(unsigned line, IHTMLElement *elem, const char *name)
5554 IHTMLFrameBase *fbase;
5555 HRESULT hres;
5556 BSTR str;
5558 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5559 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5561 str = name ? a2bstr(name) : NULL;
5562 hres = IHTMLFrameBase_put_name(fbase, str);
5563 ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres);
5564 SysFreeString(str);
5566 _test_framebase_name(line, elem, name);
5567 IHTMLFrameBase_Release(fbase);
5570 #define test_framebase_src(a,b) _test_framebase_src(__LINE__,a,b)
5571 static void _test_framebase_src(unsigned line, IHTMLElement *elem, const char *src)
5573 BSTR str = (void*)0xdeadbeef;
5574 IHTMLFrameBase *fbase;
5575 HRESULT hres;
5577 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFrameBase, (void**)&fbase);
5578 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5580 hres = IHTMLFrameBase_get_src(fbase, &str);
5581 ok_(__FILE__,line)(hres == S_OK, "IHTMLFrameBase_get_src failed: 0x%08x\n", hres);
5582 if(src)
5583 ok_(__FILE__,line)(!strcmp_wa(str, src), "src = %s, expected %s\n", wine_dbgstr_w(str), src);
5584 else
5585 ok_(__FILE__,line)(!str, "src = %s, expected NULL\n", wine_dbgstr_w(str));
5586 SysFreeString(str);
5588 IHTMLFrameBase_Release(fbase);
5591 #define test_framebase_marginheight(a,b) _test_framebase_marginheight(__LINE__,a,b)
5592 static void _test_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const char *exval)
5594 VARIANT v;
5595 HRESULT hres;
5597 hres = IHTMLFrameBase_get_marginHeight(framebase, &v);
5598 ok_(__FILE__,line)(hres == S_OK, "get_marginHeight failed: %08x\n", hres);
5599 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginHeight) = %d\n", V_VT(&v));
5600 if(exval)
5601 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "marginHeight = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
5602 else
5603 ok_(__FILE__,line)(!V_BSTR(&v), "marginHeight = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
5604 VariantClear(&v);
5607 #define set_framebase_marginheight(a,b) _set_framebase_marginheight(__LINE__,a,b)
5608 static void _set_framebase_marginheight(unsigned line, IHTMLFrameBase *framebase, const char *val)
5610 VARIANT v;
5611 HRESULT hres;
5613 V_VT(&v) = VT_BSTR;
5614 V_BSTR(&v) = a2bstr(val);
5615 hres = IHTMLFrameBase_put_marginHeight(framebase, v);
5616 ok_(__FILE__,line)(hres == S_OK, "put_marginHeight failed: %08x\n", hres);
5617 VariantClear(&v);
5620 #define test_framebase_marginwidth(a,b) _test_framebase_marginwidth(__LINE__,a,b)
5621 static void _test_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const char *exval)
5623 VARIANT v;
5624 HRESULT hres;
5626 hres = IHTMLFrameBase_get_marginWidth(framebase, &v);
5627 ok_(__FILE__,line)(hres == S_OK, "get_marginWidth failed: %08x\n", hres);
5628 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(marginWidth) = %d\n", V_VT(&v));
5629 if(exval)
5630 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "marginWidth = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
5631 else
5632 ok_(__FILE__,line)(!V_BSTR(&v), "marginWidth = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
5633 VariantClear(&v);
5636 #define set_framebase_marginwidth(a,b) _set_framebase_marginwidth(__LINE__,a,b)
5637 static void _set_framebase_marginwidth(unsigned line, IHTMLFrameBase *framebase, const char *val)
5639 VARIANT v;
5640 HRESULT hres;
5642 V_VT(&v) = VT_BSTR;
5643 V_BSTR(&v) = a2bstr(val);
5644 hres = IHTMLFrameBase_put_marginWidth(framebase, v);
5645 ok_(__FILE__,line)(hres == S_OK, "put_marginWidth failed: %08x\n", hres);
5646 VariantClear(&v);
5649 static void test_framebase(IUnknown *unk)
5651 IHTMLFrameBase *fbase;
5652 BSTR str;
5653 HRESULT hres;
5655 /* get/put scrolling */
5656 hres = IUnknown_QueryInterface(unk, &IID_IHTMLFrameBase, (void**)&fbase);
5657 ok(hres == S_OK, "Could not get IHTMLFrameBase interface: 0x%08x\n", hres);
5659 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5660 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5661 ok(!strcmp_wa(str, "auto"), "get_scrolling should have given 'auto', gave: %s\n", wine_dbgstr_w(str));
5662 SysFreeString(str);
5664 str = a2bstr("no");
5665 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5666 ok(hres == S_OK, "IHTMLFrameBase_put_scrolling failed: 0x%08x\n", hres);
5667 SysFreeString(str);
5669 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5670 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5671 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5672 SysFreeString(str);
5674 str = a2bstr("junk");
5675 hres = IHTMLFrameBase_put_scrolling(fbase, str);
5676 ok(hres == E_INVALIDARG, "IHTMLFrameBase_put_scrolling should have failed "
5677 "with E_INVALIDARG, instead: 0x%08x\n", hres);
5678 SysFreeString(str);
5680 hres = IHTMLFrameBase_get_scrolling(fbase, &str);
5681 ok(hres == S_OK, "IHTMLFrameBase_get_scrolling failed: 0x%08x\n", hres);
5682 ok(!strcmp_wa(str, "no"), "get_scrolling should have given 'no', gave: %s\n", wine_dbgstr_w(str));
5683 SysFreeString(str);
5685 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
5686 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
5687 ok(!str, "frameBorder = %s\n", wine_dbgstr_w(str));
5689 str = a2bstr("1");
5690 hres = IHTMLFrameBase_put_frameBorder(fbase, str);
5691 ok(hres == S_OK, "put_frameBorder failed: %08x\n", hres);
5692 SysFreeString(str);
5694 hres = IHTMLFrameBase_get_frameBorder(fbase, &str);
5695 ok(hres == S_OK, "get_frameBorder failed: %08x\n", hres);
5696 ok(!strcmp_wa(str, "1"), "frameBorder = %s, expected \"1\"\n", wine_dbgstr_w(str));
5698 test_framebase_marginheight(fbase, NULL);
5699 set_framebase_marginheight(fbase, "1px");
5700 test_framebase_marginheight(fbase, "1");
5702 test_framebase_marginwidth(fbase, NULL);
5703 set_framebase_marginwidth(fbase, "2px");
5704 test_framebase_marginwidth(fbase, "2");
5706 IHTMLFrameBase_Release(fbase);
5709 #define test_language_string(a,b) _test_language_string(__LINE__,a,b)
5710 static void _test_language_string(unsigned line, const WCHAR *lang, LCID lcid)
5712 WCHAR buf[64];
5713 int res;
5715 if(pLCIDToLocaleName) {
5716 res = pLCIDToLocaleName(lcid, buf, sizeof(buf)/sizeof(WCHAR), 0);
5717 ok_(__FILE__,line)(res, "LCIDToLocaleName failed: %u\n", GetLastError());
5718 ok_(__FILE__,line)(!lstrcmpW(lang, buf), "lang = %s, expected %s\n", wine_dbgstr_w(lang), wine_dbgstr_w(buf));
5719 }else {
5720 win_skip("LCIDToLocaleName not available, unable to test language string\n");
5721 ok_(__FILE__,line)(lang != NULL, "lang == NULL\n");
5725 #define test_table_length(t,l) _test_table_length(__LINE__,t,l)
5726 static void _test_table_length(unsigned line, IHTMLTable *table, LONG expect)
5728 IHTMLElementCollection *col;
5729 HRESULT hres;
5730 LONG len;
5732 hres = IHTMLTable_get_rows(table, &col);
5733 ok_(__FILE__,line)(hres == S_OK, "get_rows failed: %08x\n", hres);
5734 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
5735 if (hres != S_OK || col == NULL)
5736 return;
5737 hres = IHTMLElementCollection_get_length(col, &len);
5738 ok_(__FILE__,line)(hres == S_OK, "get_length failed: %08x\n", hres);
5739 ok_(__FILE__,line)(len == expect, "Expect %d, got %d\n", expect, len);
5741 IHTMLElementCollection_Release(col);
5744 static void test_navigator(IHTMLDocument2 *doc)
5746 IHTMLWindow2 *window;
5747 IOmNavigator *navigator, *navigator2;
5748 VARIANT_BOOL b;
5749 char buf[512];
5750 DWORD size;
5751 ULONG ref;
5752 BSTR bstr;
5753 HRESULT hres;
5755 static const WCHAR v40[] = {'4','.','0'};
5757 hres = IHTMLDocument2_get_parentWindow(doc, &window);
5758 ok(hres == S_OK, "parentWidnow failed: %08x\n", hres);
5760 hres = IHTMLWindow2_get_navigator(window, &navigator);
5761 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
5762 ok(navigator != NULL, "navigator == NULL\n");
5763 test_disp2((IUnknown*)navigator, &DIID_DispHTMLNavigator, &IID_IOmNavigator, "[object]");
5765 hres = IHTMLWindow2_get_navigator(window, &navigator2);
5766 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
5767 ok(navigator != navigator2, "navigator2 != navihgator\n");
5769 IHTMLWindow2_Release(window);
5770 IOmNavigator_Release(navigator2);
5772 hres = IOmNavigator_get_appCodeName(navigator, &bstr);
5773 ok(hres == S_OK, "get_appCodeName failed: %08x\n", hres);
5774 ok(!strcmp_wa(bstr, "Mozilla"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
5775 SysFreeString(bstr);
5777 bstr = NULL;
5778 hres = IOmNavigator_get_appName(navigator, &bstr);
5779 ok(hres == S_OK, "get_appName failed: %08x\n", hres);
5780 ok(!strcmp_wa(bstr, "Microsoft Internet Explorer"), "Unexpected appCodeName %s\n", wine_dbgstr_w(bstr));
5781 SysFreeString(bstr);
5783 bstr = NULL;
5784 hres = IOmNavigator_get_platform(navigator, &bstr);
5785 ok(hres == S_OK, "get_platform failed: %08x\n", hres);
5786 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "Win64" : "Win32")
5787 || (sizeof(void*) == 8 && broken(!strcmp_wa(bstr, "Win32") /* IE6 */)), "unexpected platform %s\n", wine_dbgstr_w(bstr));
5788 SysFreeString(bstr);
5790 bstr = NULL;
5791 hres = IOmNavigator_get_cpuClass(navigator, &bstr);
5792 ok(hres == S_OK, "get_cpuClass failed: %08x\n", hres);
5793 ok(!strcmp_wa(bstr, sizeof(void*) == 8 ? "x64" : "x86"), "unexpected cpuClass %s\n", wine_dbgstr_w(bstr));
5794 SysFreeString(bstr);
5796 bstr = NULL;
5797 hres = IOmNavigator_get_appVersion(navigator, &bstr);
5798 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
5799 ok(!memcmp(bstr, v40, sizeof(v40)), "appVersion is %s\n", wine_dbgstr_w(bstr));
5800 SysFreeString(bstr);
5802 bstr = NULL;
5803 hres = IOmNavigator_get_systemLanguage(navigator, &bstr);
5804 ok(hres == S_OK, "get_systemLanguage failed: %08x\n", hres);
5805 test_language_string(bstr, LOCALE_SYSTEM_DEFAULT);
5806 SysFreeString(bstr);
5808 if (pGetUserDefaultUILanguage)
5810 bstr = NULL;
5811 hres = IOmNavigator_get_browserLanguage(navigator, &bstr);
5812 ok(hres == S_OK, "get_browserLanguage failed: %08x\n", hres);
5813 test_language_string(bstr, pGetUserDefaultUILanguage());
5814 SysFreeString(bstr);
5816 else
5817 win_skip("GetUserDefaultUILanguage not available\n");
5819 bstr = NULL;
5820 hres = IOmNavigator_get_userLanguage(navigator, &bstr);
5821 ok(hres == S_OK, "get_userLanguage failed: %08x\n", hres);
5822 test_language_string(bstr, LOCALE_USER_DEFAULT);
5823 SysFreeString(bstr);
5825 hres = IOmNavigator_toString(navigator, NULL);
5826 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
5828 bstr = NULL;
5829 hres = IOmNavigator_toString(navigator, &bstr);
5830 ok(hres == S_OK, "toString failed: %08x\n", hres);
5831 ok(!strcmp_wa(bstr, "[object]"), "toString returned %s\n", wine_dbgstr_w(bstr));
5832 SysFreeString(bstr);
5834 b = 100;
5835 hres = IOmNavigator_get_onLine(navigator, &b);
5836 ok(hres == S_OK, "get_onLine failed: %08x\n", hres);
5837 ok(b == VARIANT_TRUE, "onLine = %x\n", b);
5839 size = sizeof(buf);
5840 hres = ObtainUserAgentString(0, buf, &size);
5841 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
5843 bstr = NULL;
5844 hres = IOmNavigator_get_userAgent(navigator, &bstr);
5845 ok(hres == S_OK, "get_userAgent failed: %08x\n", hres);
5846 ok(!strcmp_wa(bstr, buf), "userAgent returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf);
5847 SysFreeString(bstr);
5849 if(!strncmp(buf, "Mozilla/", 8)) {
5850 bstr = NULL;
5851 hres = IOmNavigator_get_appVersion(navigator, &bstr);
5852 ok(hres == S_OK, "get_appVersion failed: %08x\n", hres);
5853 ok(!strcmp_wa(bstr, buf+8), "appVersion returned %s, expected \"%s\"\n", wine_dbgstr_w(bstr), buf+8);
5854 SysFreeString(bstr);
5855 }else {
5856 skip("nonstandard user agent\n");
5859 bstr = NULL;
5860 hres = IOmNavigator_get_appMinorVersion(navigator, &bstr);
5861 ok(hres == S_OK, "get_appMonorVersion failed: %08x\n", hres);
5862 ok(bstr != NULL, "appMinorVersion returned NULL\n");
5863 SysFreeString(bstr);
5865 test_mime_types_col(navigator);
5867 ref = IOmNavigator_Release(navigator);
5868 ok(!ref, "navigator should be destroyed here\n");
5871 static void test_screen(IHTMLWindow2 *window)
5873 IHTMLScreen *screen, *screen2;
5874 IDispatchEx *dispex;
5875 RECT work_area;
5876 LONG l, exl;
5877 HDC hdc;
5878 HRESULT hres;
5880 screen = NULL;
5881 hres = IHTMLWindow2_get_screen(window, &screen);
5882 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
5883 ok(screen != NULL, "screen == NULL\n");
5885 screen2 = NULL;
5886 hres = IHTMLWindow2_get_screen(window, &screen2);
5887 ok(hres == S_OK, "get_screen failed: %08x\n", hres);
5888 ok(screen2 != NULL, "screen == NULL\n");
5889 ok(iface_cmp((IUnknown*)screen2, (IUnknown*)screen), "screen2 != screen\n");
5890 IHTMLScreen_Release(screen2);
5892 hres = IHTMLScreen_QueryInterface(screen, &IID_IDispatchEx, (void**)&dispex);
5893 ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IDispatchEx interface: %08x\n", hres);
5894 if(SUCCEEDED(hres)) {
5895 test_disp((IUnknown*)screen, &DIID_DispHTMLScreen, "[object]");
5896 IDispatchEx_Release(dispex);
5899 hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
5901 exl = GetDeviceCaps(hdc, HORZRES);
5902 l = 0xdeadbeef;
5903 hres = IHTMLScreen_get_width(screen, &l);
5904 ok(hres == S_OK, "get_width failed: %08x\n", hres);
5905 ok(l == exl, "width = %d, expected %d\n", l, exl);
5907 exl = GetDeviceCaps(hdc, VERTRES);
5908 l = 0xdeadbeef;
5909 hres = IHTMLScreen_get_height(screen, &l);
5910 ok(hres == S_OK, "get_height failed: %08x\n", hres);
5911 ok(l == exl, "height = %d, expected %d\n", l, exl);
5913 exl = GetDeviceCaps(hdc, BITSPIXEL);
5914 l = 0xdeadbeef;
5915 hres = IHTMLScreen_get_colorDepth(screen, &l);
5916 ok(hres == S_OK, "get_height failed: %08x\n", hres);
5917 ok(l == exl, "height = %d, expected %d\n", l, exl);
5919 DeleteObject(hdc);
5921 SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
5923 l = 0xdeadbeef;
5924 hres = IHTMLScreen_get_availHeight(screen, &l);
5925 ok(hres == S_OK, "get_availHeight failed: %08x\n", hres);
5926 ok(l == work_area.bottom-work_area.top, "availHeight = %d, expected %d\n", l, work_area.bottom-work_area.top);
5928 l = 0xdeadbeef;
5929 hres = IHTMLScreen_get_availWidth(screen, &l);
5930 ok(hres == S_OK, "get_availWidth failed: %08x\n", hres);
5931 ok(l == work_area.right-work_area.left, "availWidth = %d, expected %d\n", l, work_area.right-work_area.left);
5933 IHTMLScreen_Release(screen);
5936 static void test_default_selection(IHTMLDocument2 *doc)
5938 IHTMLSelectionObject *selection;
5939 IHTMLTxtRange *range;
5940 IDispatch *disp;
5941 BSTR str;
5942 HRESULT hres;
5944 hres = IHTMLDocument2_get_selection(doc, &selection);
5945 ok(hres == S_OK, "get_selection failed: %08x\n", hres);
5947 hres = IHTMLSelectionObject_get_type(selection, &str);
5948 ok(hres == S_OK, "get_type failed: %08x\n", hres);
5949 ok(!strcmp_wa(str, "None"), "type = %s\n", wine_dbgstr_w(str));
5950 SysFreeString(str);
5952 hres = IHTMLSelectionObject_createRange(selection, &disp);
5953 IHTMLSelectionObject_Release(selection);
5954 ok(hres == S_OK, "createRange failed: %08x\n", hres);
5956 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
5957 IDispatch_Release(disp);
5958 ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
5960 test_range_text(range, NULL);
5961 IHTMLTxtRange_Release(range);
5964 static void test_doc_elem(IHTMLDocument2 *doc)
5966 IHTMLDocument2 *doc_node, *owner_doc;
5967 IHTMLElement *elem;
5968 IHTMLDocument3 *doc3;
5969 HRESULT hres;
5970 BSTR bstr;
5972 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
5973 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
5975 hres = IHTMLDocument2_toString(doc, &bstr);
5976 ok(hres == S_OK, "toString failed: %08x\n", hres);
5977 ok(!strcmp_wa(bstr, "[object]"),
5978 "toString returned %s, expected [object]\n", wine_dbgstr_w(bstr));
5979 SysFreeString(bstr);
5981 hres = IHTMLDocument3_get_documentElement(doc3, &elem);
5982 IHTMLDocument3_Release(doc3);
5983 ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
5985 test_node_name((IUnknown*)elem, "HTML");
5986 test_elem_tag((IUnknown*)elem, "HTML");
5988 doc_node = get_doc_node(doc);
5989 owner_doc = get_owner_doc((IUnknown*)elem);
5990 ok(iface_cmp((IUnknown *)doc_node, (IUnknown *)owner_doc), "doc_node != owner_doc\n");
5991 IHTMLDocument2_Release(owner_doc);
5993 owner_doc = get_owner_doc((IUnknown*)doc_node);
5994 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
5995 IHTMLDocument2_Release(doc_node);
5997 test_elem_client_rect((IUnknown*)elem);
5999 IHTMLElement_Release(elem);
6002 static void test_default_body(IHTMLBodyElement *body)
6004 LONG l;
6005 BSTR bstr;
6006 HRESULT hres;
6007 VARIANT v;
6009 bstr = (void*)0xdeadbeef;
6010 hres = IHTMLBodyElement_get_background(body, &bstr);
6011 ok(hres == S_OK, "get_background failed: %08x\n", hres);
6012 ok(bstr == NULL, "bstr != NULL\n");
6014 l = elem_get_scroll_height((IUnknown*)body);
6015 ok(l != -1, "scrollHeight == -1\n");
6016 l = elem_get_scroll_width((IUnknown*)body);
6017 ok(l != -1, "scrollWidth == -1\n");
6018 l = elem_get_scroll_top((IUnknown*)body);
6019 ok(!l, "scrollTop = %d\n", l);
6020 elem_get_scroll_left((IUnknown*)body);
6022 test_elem_dir((IUnknown*)body, NULL);
6023 set_elem_dir((IUnknown*)body, "ltr");
6025 /* get_text tests */
6026 hres = IHTMLBodyElement_get_text(body, &v);
6027 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6028 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6029 ok(V_BSTR(&v) == NULL, "bstr != NULL\n");
6031 /* get_text - Invalid Text */
6032 V_VT(&v) = VT_BSTR;
6033 V_BSTR(&v) = a2bstr("Invalid");
6034 hres = IHTMLBodyElement_put_text(body, v);
6035 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6036 VariantClear(&v);
6038 V_VT(&v) = VT_NULL;
6039 hres = IHTMLBodyElement_get_text(body, &v);
6040 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6041 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6042 ok(!strcmp_wa(V_BSTR(&v), "#00a0d0"), "v = %s, expected '#00a0d0'\n", wine_dbgstr_w(V_BSTR(&v)));
6043 VariantClear(&v);
6045 /* get_text - Valid Text */
6046 V_VT(&v) = VT_BSTR;
6047 V_BSTR(&v) = a2bstr("#FF0000");
6048 hres = IHTMLBodyElement_put_text(body, v);
6049 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6050 VariantClear(&v);
6052 V_VT(&v) = VT_NULL;
6053 hres = IHTMLBodyElement_get_text(body, &v);
6054 ok(hres == S_OK, "expect S_OK got 0x%08d\n", hres);
6055 ok(V_VT(&v) == VT_BSTR, "Expected VT_BSTR got %d\n", V_VT(&v));
6056 ok(!strcmp_wa(V_BSTR(&v), "#ff0000"), "v = %s, expected '#ff0000'\n", wine_dbgstr_w(V_BSTR(&v)));
6057 VariantClear(&v);
6060 #define test_body_scroll(a,b) _test_body_scroll(__LINE__,a,b)
6061 static void _test_body_scroll(unsigned line, IHTMLBodyElement *body, const char *ex)
6063 BSTR str;
6064 HRESULT hres;
6066 hres = IHTMLBodyElement_get_scroll(body, &str);
6067 ok_(__FILE__,line)(hres == S_OK, "get_scroll failed: %08x\n", hres);
6068 ok_(__FILE__,line)(ex ? !strcmp_wa(str, ex) : !str, "scroll = %s\n", wine_dbgstr_w(str));
6069 SysFreeString(str);
6072 #define set_body_scroll(a,b) _set_body_scroll(__LINE__,a,b)
6073 static void _set_body_scroll(unsigned line, IHTMLBodyElement *body, const char *val)
6075 BSTR str = a2bstr(val);
6076 HRESULT hres;
6078 hres = IHTMLBodyElement_put_scroll(body, str);
6079 ok_(__FILE__,line)(hres == S_OK, "put_scroll failed: %08x\n", hres);
6080 SysFreeString(str);
6082 _test_body_scroll(line, body, val);
6085 static void test_body_funs(IHTMLBodyElement *body)
6087 VARIANT vbg, vDefaultbg;
6088 HRESULT hres;
6090 hres = IHTMLBodyElement_get_bgColor(body, &vDefaultbg);
6091 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6092 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6093 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6095 V_VT(&vbg) = VT_BSTR;
6096 V_BSTR(&vbg) = a2bstr("red");
6097 hres = IHTMLBodyElement_put_bgColor(body, vbg);
6098 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6099 VariantClear(&vbg);
6101 hres = IHTMLBodyElement_get_bgColor(body, &vbg);
6102 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6103 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6104 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6105 VariantClear(&vbg);
6107 /* Restore Originial */
6108 hres = IHTMLBodyElement_put_bgColor(body, vDefaultbg);
6109 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6110 VariantClear(&vDefaultbg);
6112 test_body_scroll(body, NULL);
6113 set_body_scroll(body, "yes");
6114 set_body_scroll(body, "no");
6115 set_body_scroll(body, "auto");
6118 static void test_history(IHTMLWindow2 *window)
6120 IOmHistory *history, *history2;
6121 HRESULT hres;
6123 history = NULL;
6124 hres = IHTMLWindow2_get_history(window, &history);
6125 ok(hres == S_OK, "get_history failed: %08x\n", hres);
6126 ok(history != NULL, "history = NULL\n");
6128 test_disp2((IUnknown*)history, &DIID_DispHTMLHistory, &IID_IOmHistory, "[object]");
6130 history2 = NULL;
6131 hres = IHTMLWindow2_get_history(window, &history2);
6132 ok(hres == S_OK, "get_history failed: %08x\n", hres);
6133 ok(history2 != NULL, "history2 = NULL\n");
6134 ok(iface_cmp((IUnknown*)history, (IUnknown*)history2), "history != history2\n");
6136 IOmHistory_Release(history2);
6137 IOmHistory_Release(history);
6140 static void test_xmlhttprequest(IHTMLWindow5 *window)
6142 HRESULT hres;
6143 VARIANT var;
6144 IHTMLXMLHttpRequestFactory *factory;
6145 IHTMLXMLHttpRequest *xml;
6147 hres = IHTMLWindow5_get_XMLHttpRequest(window, &var);
6148 ok(hres == S_OK, "get_XMLHttpRequest failed: %08x\n", hres);
6149 ok(V_VT(&var) == VT_DISPATCH, "expect VT_DISPATCH, got %s\n", debugstr_variant(&var));
6151 factory = NULL;
6152 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLXMLHttpRequestFactory, (void**)&factory);
6153 ok(hres == S_OK, "QueryInterface(&IID_IHTMLXMLHttpRequestFactory) failed: %08x\n", hres);
6154 ok(factory != NULL, "factory == NULL\n");
6156 xml = NULL;
6157 hres = IHTMLXMLHttpRequestFactory_create(factory, &xml);
6158 ok(hres == S_OK, "create failed: %08x\n", hres);
6159 ok(xml != NULL, "xml == NULL\n");
6160 test_disp((IUnknown*)xml, &DIID_DispHTMLXMLHttpRequest, "[object]");
6162 IHTMLXMLHttpRequest_Release(xml);
6163 IHTMLXMLHttpRequestFactory_Release(factory);
6164 VariantClear(&var);
6167 static void test_window(IHTMLDocument2 *doc)
6169 IHTMLWindow2 *window, *window2, *self, *parent;
6170 IHTMLWindow5 *window5;
6171 IHTMLDocument2 *doc2 = NULL;
6172 IDispatch *disp;
6173 IUnknown *unk;
6174 VARIANT v;
6175 BSTR str;
6176 HRESULT hres;
6178 hres = IHTMLDocument2_get_parentWindow(doc, &window);
6179 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6180 test_ifaces((IUnknown*)window, window_iids);
6181 hres = IHTMLWindow2_QueryInterface(window, &IID_ITravelLogClient, (void**)&unk);
6182 if(hres == S_OK)
6183 IUnknown_Release(unk);
6184 else
6185 win_skip("IID_ITravelLogClient not supported\n");
6187 test_disp((IUnknown*)window, &DIID_DispHTMLWindow2, "[object]");
6189 hres = IHTMLWindow2_get_document(window, &doc2);
6190 ok(hres == S_OK, "get_document failed: %08x\n", hres);
6191 ok(doc2 != NULL, "doc2 == NULL\n");
6193 test_ifaces((IUnknown*)doc2, doc_node_iids);
6194 test_disp((IUnknown*)doc2, &DIID_DispHTMLDocument, "[object]");
6195 test_class_info((IUnknown*)doc2);
6197 test_ifaces((IUnknown*)doc, doc_obj_iids);
6198 test_disp((IUnknown*)doc, &DIID_DispHTMLDocument, "[object]");
6199 test_class_info((IUnknown*)doc);
6201 unk = (void*)0xdeadbeef;
6202 hres = IHTMLDocument2_QueryInterface(doc2, &IID_ICustomDoc, (void**)&unk);
6203 ok(hres == E_NOINTERFACE, "QueryInterface(IID_ICustomDoc) returned: %08x\n", hres);
6204 ok(!unk, "unk = %p\n", unk);
6206 IHTMLDocument2_Release(doc2);
6208 hres = IHTMLWindow2_get_window(window, &window2);
6209 ok(hres == S_OK, "get_window failed: %08x\n", hres);
6210 ok(window2 != NULL, "window2 == NULL\n");
6212 hres = IHTMLWindow2_get_self(window, &self);
6213 ok(hres == S_OK, "get_self failed: %08x\n", hres);
6214 ok(window2 != NULL, "self == NULL\n");
6216 ok(self == window2, "self != window2\n");
6218 IHTMLWindow2_Release(window2);
6220 disp = NULL;
6221 hres = IHTMLDocument2_get_Script(doc, &disp);
6222 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
6223 ok(disp == (void*)window, "disp != window\n");
6224 IDispatch_Release(disp);
6226 hres = IHTMLWindow2_toString(window, NULL);
6227 ok(hres == E_INVALIDARG, "toString failed: %08x\n", hres);
6229 str = NULL;
6230 hres = IHTMLWindow2_toString(window, &str);
6231 ok(hres == S_OK, "toString failed: %08x\n", hres);
6232 ok(!strcmp_wa(str, "[object]") ||
6233 !strcmp_wa(str, "[object Window]") /* win7 ie9 */, "toString returned %s\n", wine_dbgstr_w(str));
6234 SysFreeString(str);
6236 V_VT(&v) = VT_ERROR;
6237 hres = IHTMLWindow2_get_opener(window, &v);
6238 ok(hres == S_OK, "get_opener failed: %08x\n", hres);
6239 ok(V_VT(&v) == VT_EMPTY, "V_VT(opener) = %d\n", V_VT(&v));
6241 parent = NULL;
6242 hres = IHTMLWindow2_get_parent(window, &parent);
6243 ok(hres == S_OK, "get_parent failed: %08x\n", hres);
6244 ok(parent != NULL, "parent == NULL\n");
6245 ok(parent == self, "parent != window\n");
6246 IHTMLWindow2_Release(parent);
6247 IHTMLWindow2_Release(self);
6249 test_window_name(window, NULL);
6250 set_window_name(window, "test");
6251 test_window_length(window, 0);
6252 test_screen(window);
6253 test_window_status(window);
6254 set_window_status(window, "Test!");
6255 test_history(window);
6257 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow5, (void**)&window5);
6258 if(SUCCEEDED(hres)) {
6259 ok(window5 != NULL, "window5 == NULL\n");
6260 test_xmlhttprequest(window5);
6261 IHTMLWindow5_Release(window5);
6262 }else {
6263 win_skip("IHTMLWindow5 not supported!\n");
6266 IHTMLWindow2_Release(window);
6269 static void test_dom_implementation(IHTMLDocument2 *doc)
6271 IHTMLDocument5 *doc5 = get_htmldoc5_iface((IUnknown*)doc);
6272 IHTMLDOMImplementation *dom_implementation;
6273 VARIANT_BOOL b;
6274 VARIANT v;
6275 BSTR str;
6276 HRESULT hres;
6278 hres = IHTMLDocument5_get_implementation(doc5, &dom_implementation);
6279 IHTMLDocument5_Release(doc5);
6280 ok(hres == S_OK, "get_implementation failed: %08x\n", hres);
6281 ok(dom_implementation != NULL, "dom_implementation == NULL\n");
6283 str = a2bstr("test");
6284 V_VT(&v) = VT_BSTR;
6285 V_BSTR(&v) = a2bstr("1.0");
6286 b = 100;
6287 hres = IHTMLDOMImplementation_hasFeature(dom_implementation, str, v, &b);
6288 SysFreeString(str);
6289 VariantClear(&v);
6290 ok(hres == S_OK, "hasFeature failed: %08x\n", hres);
6291 ok(!b, "hasFeature returned %x\n", b);
6293 IHTMLDOMImplementation_Release(dom_implementation);
6296 static void test_defaults(IHTMLDocument2 *doc)
6298 IHTMLStyleSheetsCollection *stylesheetcol;
6299 IHTMLCurrentStyle *cstyle;
6300 IHTMLBodyElement *body;
6301 IHTMLElement2 *elem2;
6302 IHTMLElement *elem;
6303 IHTMLStyle *style;
6304 VARIANT v;
6305 BSTR str;
6306 LONG l;
6307 VARIANT_BOOL b;
6308 HRESULT hres;
6309 IHTMLElementCollection *collection;
6311 elem = doc_get_body(doc);
6313 hres = IHTMLDocument2_get_images(doc, NULL);
6314 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
6316 hres = IHTMLDocument2_get_images(doc, &collection);
6317 ok(hres == S_OK, "get_images failed: %08x\n", hres);
6318 if(hres == S_OK)
6320 test_elem_collection((IUnknown*)collection, NULL, 0);
6321 IHTMLElementCollection_Release(collection);
6324 hres = IHTMLDocument2_get_applets(doc, NULL);
6325 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
6327 hres = IHTMLDocument2_get_applets(doc, &collection);
6328 ok(hres == S_OK, "get_applets failed: %08x\n", hres);
6329 if(hres == S_OK)
6331 test_elem_collection((IUnknown*)collection, NULL, 0);
6332 IHTMLElementCollection_Release(collection);
6335 hres = IHTMLDocument2_get_links(doc, NULL);
6336 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
6338 hres = IHTMLDocument2_get_links(doc, &collection);
6339 ok(hres == S_OK, "get_links failed: %08x\n", hres);
6340 if(hres == S_OK)
6342 test_elem_collection((IUnknown*)collection, NULL, 0);
6343 IHTMLElementCollection_Release(collection);
6346 hres = IHTMLDocument2_get_forms(doc, NULL);
6347 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
6349 hres = IHTMLDocument2_get_forms(doc, &collection);
6350 ok(hres == S_OK, "get_forms failed: %08x\n", hres);
6351 if(hres == S_OK)
6353 test_elem_collection((IUnknown*)collection, NULL, 0);
6354 IHTMLElementCollection_Release(collection);
6357 hres = IHTMLDocument2_get_anchors(doc, NULL);
6358 ok(hres == E_INVALIDARG, "hres %08x\n", hres);
6360 hres = IHTMLDocument2_get_anchors(doc, &collection);
6361 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
6362 if(hres == S_OK)
6364 test_elem_collection((IUnknown*)collection, NULL, 0);
6365 IHTMLElementCollection_Release(collection);
6368 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
6369 ok(hres == S_OK, "Could not get IHTMBodyElement: %08x\n", hres);
6370 test_default_body(body);
6371 test_body_funs(body);
6372 IHTMLBodyElement_Release(body);
6374 test_elem_istextedit(elem, VARIANT_TRUE);
6376 hres = IHTMLElement_get_style(elem, &style);
6377 ok(hres == S_OK, "get_style failed: %08x\n", hres);
6379 test_disp((IUnknown*)style, &DIID_DispHTMLStyle, "[object]");
6380 test_ifaces((IUnknown*)style, style_iids);
6381 IHTMLStyle_Release(style);
6383 str = NULL;
6384 hres = IHTMLDocument2_get_charset(doc, &str);
6385 ok(hres == S_OK, "get_charset failed: %08x\n", hres);
6386 ok(str && *str, "charset is empty\n"); /* FIXME: better tests */
6387 SysFreeString(str);
6389 test_window(doc);
6390 test_compatmode(doc, "BackCompat");
6391 test_location(doc);
6392 test_navigator(doc);
6393 test_plugins_col(doc);
6395 elem2 = get_elem2_iface((IUnknown*)elem);
6396 hres = IHTMLElement2_get_currentStyle(elem2, &cstyle);
6397 ok(hres == S_OK, "get_currentStyle failed: %08x\n", hres);
6398 if(SUCCEEDED(hres)) {
6399 IUnknown *unk;
6401 test_disp((IUnknown*)cstyle, &DIID_DispHTMLCurrentStyle, "[object]");
6402 test_ifaces((IUnknown*)cstyle, cstyle_iids);
6404 hres = IHTMLCurrentStyle_QueryInterface(cstyle, &IID_IHTMLCurrentStyle4, (void**)&unk);
6405 if(SUCCEEDED(hres))
6406 IUnknown_Release(unk);
6407 else
6409 /*IE6 doesn't have interface */
6410 win_skip("IID_IHTMLCurrentStyle4 not supported\n");
6413 IHTMLCurrentStyle_Release(cstyle);
6415 IHTMLElement2_Release(elem2);
6417 IHTMLElement_Release(elem);
6419 hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
6420 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
6422 l = 0xdeadbeef;
6423 hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
6424 ok(hres == S_OK, "get_length failed: %08x\n", hres);
6425 ok(l == 0, "length = %d\n", l);
6427 IHTMLStyleSheetsCollection_Release(stylesheetcol);
6429 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFiltersCollection, (void**)&body);
6430 ok(hres == E_NOINTERFACE, "got interface IHTMLFiltersCollection\n");
6432 str = a2bstr("xxx");
6433 b = 100;
6434 V_VT(&v) = VT_EMPTY;
6435 hres = IHTMLDocument2_execCommand(doc, str, FALSE, v, &b);
6436 ok(hres == OLECMDERR_E_NOTSUPPORTED || hres == E_INVALIDARG,
6437 "execCommand failed: %08x, expected OLECMDERR_E_NOTSUPPORTED or E_INVALIDARG\n", hres);
6438 SysFreeString(str);
6440 str = a2bstr("respectvisibilityindesign");
6441 b = 100;
6442 V_VT(&v) = VT_BOOL;
6443 V_BOOL(&v) = VARIANT_TRUE;
6444 hres = IHTMLDocument2_execCommand(doc, str, FALSE, v, &b);
6445 ok(hres == S_OK, "execCommand failed: %08x, expected DRAGDROP_E_NOTREGISTERED\n", hres);
6446 SysFreeString(str);
6448 test_default_selection(doc);
6449 test_doc_title(doc, "");
6450 test_dom_implementation(doc);
6453 #define test_button_name(a,b) _test_button_name(__LINE__,a,b)
6454 static void _test_button_name(unsigned line, IHTMLElement *elem, const char *exname)
6456 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
6457 BSTR str;
6458 HRESULT hres;
6460 str = (void*)0xdeadbeef;
6461 hres = IHTMLButtonElement_get_name(button, &str);
6462 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
6463 if(exname)
6464 ok_(__FILE__,line)(!strcmp_wa(str, exname), "name = %s, expected %s\n", wine_dbgstr_w(str), exname);
6465 else
6466 ok_(__FILE__,line)(!str, "name = %s, expected NULL\n", wine_dbgstr_w(str));
6467 SysFreeString(str);
6468 IHTMLButtonElement_Release(button);
6471 #define set_button_name(a,b) _set_button_name(__LINE__,a,b)
6472 static void _set_button_name(unsigned line, IHTMLElement *elem, const char *name)
6474 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
6475 BSTR str = a2bstr(name);
6476 HRESULT hres;
6478 hres = IHTMLButtonElement_put_name(button, str);
6479 ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
6480 SysFreeString(str);
6481 IHTMLButtonElement_Release(button);
6483 _test_button_name(line, elem, name);
6486 #define test_button_get_disabled(i,b) _test_button_get_disabled(__LINE__,i,b)
6487 static void _test_button_get_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
6489 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
6490 VARIANT_BOOL disabled = 100;
6491 HRESULT hres;
6493 hres = IHTMLButtonElement_get_disabled(button, &disabled);
6494 ok_(__FILE__,line) (hres == S_OK, "get_disabled failed: %08x\n", hres);
6495 ok_(__FILE__,line) (disabled == exb, "disabled=%x, expected %x\n", disabled, exb);
6496 IHTMLButtonElement_Release(button);
6498 _test_elem3_get_disabled(line, (IUnknown*)elem, exb);
6501 #define test_button_set_disabled(i,b) _test_button_set_disabled(__LINE__,i,b)
6502 static void _test_button_set_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL b)
6504 IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
6505 HRESULT hres;
6507 hres = IHTMLButtonElement_put_disabled(button, b);
6508 ok_(__FILE__,line) (hres == S_OK, "put_disabled failed: %08x\n", hres);
6509 IHTMLButtonElement_Release(button);
6511 _test_button_get_disabled(line, elem, b);
6514 static void test_button_elem(IHTMLElement *elem)
6516 test_button_name(elem, NULL);
6517 set_button_name(elem, "button name");
6519 test_elem_istextedit(elem, VARIANT_TRUE);
6522 #define test_tr_possess(e,r,l,i) _test_tr_possess(__LINE__,e,r,l,i)
6523 static void _test_tr_possess(unsigned line, IHTMLElement *elem,
6524 IHTMLTableRow *row, LONG len, const char *id)
6526 IHTMLElementCollection *col;
6527 IDispatch *disp;
6528 HRESULT hres;
6529 LONG lval;
6530 VARIANT var;
6532 hres = IHTMLTableRow_get_cells(row, &col);
6533 ok_(__FILE__, line)(hres == S_OK, "get_cells failed: %08x\n", hres);
6534 ok_(__FILE__, line)(col != NULL, "get_cells returned NULL\n");
6536 hres = IHTMLElementCollection_get_length(col, &lval);
6537 ok_(__FILE__, line)(hres == S_OK, "get length failed: %08x\n", hres);
6538 ok_(__FILE__, line)(lval == len, "expected len = %d, got %d\n", len, lval);
6540 V_VT(&var) = VT_BSTR;
6541 V_BSTR(&var) = a2bstr(id);
6542 hres = IHTMLElementCollection_tags(col, var, &disp);
6543 ok_(__FILE__, line)(hres == S_OK, "search by tags(%s) failed: %08x\n", id, hres);
6544 ok_(__FILE__, line)(disp != NULL, "disp == NULL\n");
6546 VariantClear(&var);
6547 IDispatch_Release(disp);
6548 IHTMLElementCollection_Release(col);
6551 static void test_tr_modify(IHTMLElement *elem, IHTMLTableRow *row)
6553 HRESULT hres;
6554 IDispatch *disp;
6555 IHTMLTableCell *cell;
6557 hres = IHTMLTableRow_deleteCell(row, 0);
6558 ok(hres == S_OK, "deleteCell failed: %08x\n", hres);
6559 test_tr_possess(elem, row, 1, "td2");
6561 hres = IHTMLTableRow_insertCell(row, 0, &disp);
6562 ok(hres == S_OK, "insertCell failed: %08x\n", hres);
6563 ok(disp != NULL, "disp == NULL\n");
6564 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableCell, (void **)&cell);
6565 ok(hres == S_OK, "Could not get IID_IHTMLTableCell interface: %08x\n", hres);
6566 ok(cell != NULL, "cell == NULL\n");
6567 if (SUCCEEDED(hres))
6568 IHTMLTableCell_Release(cell);
6569 test_tr_possess(elem, row, 2, "td2");
6570 IDispatch_Release(disp);
6573 static void test_tr_elem(IHTMLElement *elem)
6575 IHTMLElementCollection *col;
6576 IHTMLTableRow *row;
6577 HRESULT hres;
6578 BSTR bstr;
6579 LONG lval;
6580 VARIANT vbg, vDefaultbg;
6582 static const elem_type_t cell_types[] = {ET_TD,ET_TD};
6584 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableRow, (void**)&row);
6585 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
6586 if(FAILED(hres))
6587 return;
6589 col = NULL;
6590 hres = IHTMLTableRow_get_cells(row, &col);
6591 ok(hres == S_OK, "get_cells failed: %08x\n", hres);
6592 ok(col != NULL, "get_cells returned NULL\n");
6594 test_elem_collection((IUnknown*)col, cell_types, sizeof(cell_types)/sizeof(*cell_types));
6595 IHTMLElementCollection_Release(col);
6597 bstr = a2bstr("left");
6598 hres = IHTMLTableRow_put_align(row, bstr);
6599 ok(hres == S_OK, "set_align failed: %08x\n", hres);
6600 SysFreeString(bstr);
6602 bstr = NULL;
6603 hres = IHTMLTableRow_get_align(row, &bstr);
6604 ok(hres == S_OK, "get_align failed: %08x\n", hres);
6605 ok(bstr != NULL, "get_align returned NULL\n");
6606 ok(!strcmp_wa(bstr, "left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
6607 SysFreeString(bstr);
6609 bstr = a2bstr("top");
6610 hres = IHTMLTableRow_put_vAlign(row, bstr);
6611 ok(hres == S_OK, "set_valign failed: %08x\n", hres);
6612 SysFreeString(bstr);
6614 bstr = NULL;
6615 hres = IHTMLTableRow_get_vAlign(row, &bstr);
6616 ok(hres == S_OK, "get_valign failed: %08x\n", hres);
6617 ok(bstr != NULL, "get_valign returned NULL\n");
6618 ok(!strcmp_wa(bstr, "top"), "get_valign returned %s\n", wine_dbgstr_w(bstr));
6619 SysFreeString(bstr);
6621 lval = 0xdeadbeef;
6622 hres = IHTMLTableRow_get_rowIndex(row, &lval);
6623 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
6624 ok(lval == 1, "get_rowIndex returned %d\n", lval);
6626 lval = 0xdeadbeef;
6627 hres = IHTMLTableRow_get_sectionRowIndex(row, &lval);
6628 ok(hres == S_OK, "get_sectionRowIndex failed: %08x\n", hres);
6629 ok(lval == 1, "get_sectionRowIndex returned %d\n", lval);
6631 hres = IHTMLTableRow_get_bgColor(row, &vDefaultbg);
6632 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6633 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6634 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6636 V_VT(&vbg) = VT_BSTR;
6637 V_BSTR(&vbg) = a2bstr("red");
6638 hres = IHTMLTableRow_put_bgColor(row, vbg);
6639 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6640 VariantClear(&vbg);
6642 hres = IHTMLTableRow_get_bgColor(row, &vbg);
6643 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6644 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6645 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6646 VariantClear(&vbg);
6648 V_VT(&vbg) = VT_I4;
6649 V_I4(&vbg) = 0xff0000;
6650 hres = IHTMLTableRow_put_bgColor(row, vbg);
6651 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6652 VariantClear(&vbg);
6654 hres = IHTMLTableRow_get_bgColor(row, &vbg);
6655 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6656 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6657 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6658 VariantClear(&vbg);
6660 /* Restore Originial */
6661 hres = IHTMLTableRow_put_bgColor(row, vDefaultbg);
6662 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6663 VariantClear(&vDefaultbg);
6665 test_tr_modify(elem, row);
6667 IHTMLTableRow_Release(row);
6670 static void test_td_elem(IHTMLElement *elem)
6672 IHTMLTableCell *cell;
6673 HRESULT hres;
6674 LONG lval;
6675 BSTR str;
6676 VARIANT vbg, vDefaultbg;
6678 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTableCell, (void**)&cell);
6679 ok(hres == S_OK, "Could not get IHTMLTableRow iface: %08x\n", hres);
6680 if(FAILED(hres))
6681 return;
6683 lval = 0xdeadbeef;
6684 hres = IHTMLTableCell_get_cellIndex(cell, &lval);
6685 ok(hres == S_OK, "get cellIndex failed: %08x\n", hres);
6686 ok(lval == 1, "Expected 1, got %d\n", lval);
6688 str = a2bstr("left");
6689 hres = IHTMLTableCell_put_align(cell, str);
6690 ok(hres == S_OK, "put_align failed: %08x\n", hres);
6691 SysFreeString(str);
6693 str = NULL;
6694 hres = IHTMLTableCell_get_align(cell, &str);
6695 ok(hres == S_OK, "get_align failed: %08x\n", hres);
6696 ok(str != NULL, "str is NULL\n");
6697 if (str != NULL && hres == S_OK) {
6698 ok(!strcmp_wa(str, "left"), "got %s\n", wine_dbgstr_w(str));
6699 SysFreeString(str);
6702 hres = IHTMLTableCell_get_bgColor(cell, &vDefaultbg);
6703 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6704 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6705 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6707 V_VT(&vbg) = VT_BSTR;
6708 V_BSTR(&vbg) = a2bstr("red");
6709 hres = IHTMLTableCell_put_bgColor(cell, vbg);
6710 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6711 VariantClear(&vbg);
6713 hres = IHTMLTableCell_get_bgColor(cell, &vbg);
6714 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6715 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6716 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6717 VariantClear(&vbg);
6719 V_VT(&vbg) = VT_I4;
6720 V_I4(&vbg) = 0xff0000;
6721 hres = IHTMLTableCell_put_bgColor(cell, vbg);
6722 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6723 VariantClear(&vbg);
6725 hres = IHTMLTableCell_get_bgColor(cell, &vbg);
6726 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6727 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6728 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6729 VariantClear(&vbg);
6731 /* Restore Originial */
6732 hres = IHTMLTableCell_put_bgColor(cell, vDefaultbg);
6733 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6734 VariantClear(&vDefaultbg);
6736 IHTMLTableCell_Release(cell);
6739 static void test_label_elem(IHTMLElement *elem)
6741 IHTMLLabelElement *label;
6742 BSTR str;
6743 HRESULT hres;
6745 label = get_label_iface((IUnknown*)elem);
6747 str = NULL;
6748 hres = IHTMLLabelElement_get_htmlFor(label, &str);
6749 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
6750 ok(!strcmp_wa(str, "in"), "htmlFor = %s\n", wine_dbgstr_w(str));
6751 SysFreeString(str);
6753 str = a2bstr("");
6754 hres = IHTMLLabelElement_put_htmlFor(label, str);
6755 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
6756 SysFreeString(str);
6758 str = (void*)0xdeadbeef;
6759 hres = IHTMLLabelElement_get_htmlFor(label, &str);
6760 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
6761 ok(!strcmp_wa(str, ""), "htmlFor = %s\n", wine_dbgstr_w(str));
6763 str = a2bstr("abc");
6764 hres = IHTMLLabelElement_put_htmlFor(label, str);
6765 ok(hres == S_OK, "put_htmlFor failed: %08x\n", hres);
6766 SysFreeString(str);
6768 str = NULL;
6769 hres = IHTMLLabelElement_get_htmlFor(label, &str);
6770 ok(hres == S_OK, "get_htmlFor failed: %08x\n", hres);
6771 ok(!strcmp_wa(str, "abc"), "htmlFor = %s\n", wine_dbgstr_w(str));
6772 SysFreeString(str);
6774 IHTMLLabelElement_Release(label);
6777 #define test_table_cell_spacing(a,b) _test_table_cell_spacing(__LINE__,a,b)
6778 static void _test_table_cell_spacing(unsigned line, IHTMLTable *table, const char *exstr)
6780 VARIANT v;
6781 HRESULT hres;
6783 V_VT(&v) = VT_ERROR;
6784 hres = IHTMLTable_get_cellSpacing(table, &v);
6785 ok_(__FILE__,line)(hres == S_OK, "get_cellSpacing failed: %08x\n", hres);
6786 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
6787 if(exstr)
6788 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exstr), "cellSpacing = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exstr);
6789 else
6790 ok_(__FILE__,line)(!V_BSTR(&v), "cellSpacing = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6791 VariantClear(&v);
6794 #define test_table_cell_padding(a,b) _test_table_cell_padding(__LINE__,a,b)
6795 static void _test_table_cell_padding(unsigned line, IHTMLTable *table, const char *exstr)
6797 VARIANT v;
6798 HRESULT hres;
6800 V_VT(&v) = VT_ERROR;
6801 hres = IHTMLTable_get_cellPadding(table, &v);
6802 ok_(__FILE__,line)(hres == S_OK, "get_cellPadding failed: %08x\n", hres);
6803 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(v) = %d\n", V_VT(&v));
6804 if(exstr)
6805 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exstr), "cellPadding = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exstr);
6806 else
6807 ok_(__FILE__,line)(!V_BSTR(&v), "cellPadding = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
6808 VariantClear(&v);
6811 static void test_table_modify(IHTMLTable *table)
6813 IDispatch *disp;
6814 IHTMLTableRow *row;
6815 HRESULT hres;
6816 LONG index;
6818 test_table_length(table, 2);
6820 hres = IHTMLTable_insertRow(table, 0, &disp);
6821 ok(hres == S_OK, "insertRow failed: %08x\n", hres);
6822 ok(disp != NULL, "disp == NULL\n");
6823 test_table_length(table, 3);
6824 if (hres != S_OK || disp == NULL)
6825 return;
6827 hres = IDispatch_QueryInterface(disp, &IID_IHTMLTableRow, (void**)&row);
6828 IDispatch_Release(disp);
6830 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
6831 ok(row != NULL, "row == NULL\n");
6833 index = 0xdeadbeef;
6834 hres = IHTMLTableRow_get_rowIndex(row, &index);
6835 ok(hres == S_OK, "get_rowIndex failed: %08x\n", hres);
6836 ok(index == 0, "index = %d, expected 0\n", index);
6838 IHTMLTableRow_Release(row);
6840 hres = IHTMLTable_deleteRow(table, 0);
6841 ok(hres == S_OK, "deleteRow failed: %08x\n", hres);
6842 test_table_length(table, 2);
6845 static void test_table_elem(IHTMLElement *elem)
6847 IHTMLElementCollection *col;
6848 IHTMLTable *table;
6849 IHTMLTable3 *table3;
6850 IHTMLDOMNode *node;
6851 VARIANT v;
6852 HRESULT hres;
6853 BSTR bstr;
6854 VARIANT vbg, vDefaultbg;
6856 static const elem_type_t row_types[] = {ET_TR,ET_TR};
6857 static const elem_type_t all_types[] = {ET_TBODY,ET_TR,ET_TR,ET_TD,ET_TD};
6858 static const elem_type_t tbodies_types[] = {ET_TBODY};
6860 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable, (void**)&table);
6861 ok(hres == S_OK, "Could not get IHTMLTable iface: %08x\n", hres);
6862 if(FAILED(hres))
6863 return;
6865 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLTable3, (void**)&table3);
6866 ok(hres == S_OK, "Could not get IHTMLTable3 iface: %08x\n", hres);
6867 if(FAILED(hres))
6868 return;
6870 col = NULL;
6871 hres = IHTMLTable_get_rows(table, &col);
6872 ok(hres == S_OK, "get_rows failed: %08x\n", hres);
6873 ok(col != NULL, "get_rows returned NULL\n");
6875 test_elem_collection((IUnknown*)col, row_types, sizeof(row_types)/sizeof(*row_types));
6876 IHTMLElementCollection_Release(col);
6878 test_elem_all((IUnknown*)table, all_types, sizeof(all_types)/sizeof(*all_types));
6880 node = clone_node((IUnknown*)table, VARIANT_TRUE);
6881 test_elem_tag((IUnknown*)node, "TABLE");
6882 test_elem_all((IUnknown*)node, all_types, sizeof(all_types)/sizeof(*all_types));
6883 IHTMLDOMNode_Release(node);
6885 node = clone_node((IUnknown*)table, VARIANT_FALSE);
6886 test_elem_tag((IUnknown*)node, "TABLE");
6887 test_elem_all((IUnknown*)node, NULL, 0);
6888 IHTMLDOMNode_Release(node);
6890 col = NULL;
6891 hres = IHTMLTable_get_tBodies(table, &col);
6892 ok(hres == S_OK, "get_tBodies failed: %08x\n", hres);
6893 ok(col != NULL, "get_tBodies returned NULL\n");
6895 test_elem_collection((IUnknown*)col, tbodies_types, sizeof(tbodies_types)/sizeof(*tbodies_types));
6896 IHTMLElementCollection_Release(col);
6898 test_table_cell_spacing(table, NULL);
6900 V_VT(&v) = VT_I4;
6901 V_I4(&v) = 10;
6902 hres = IHTMLTable_put_cellSpacing(table, v);
6903 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
6904 test_table_cell_spacing(table, "10");
6906 V_VT(&v) = VT_BSTR;
6907 V_BSTR(&v) = a2bstr("11");
6908 hres = IHTMLTable_put_cellSpacing(table, v);
6909 ok(hres == S_OK, "put_cellSpacing = %08x\n", hres);
6910 test_table_cell_spacing(table, "11");
6911 VariantClear(&v);
6913 test_table_cell_padding(table, NULL);
6915 V_VT(&v) = VT_I4;
6916 V_I4(&v) = 10;
6917 hres = IHTMLTable_put_cellPadding(table, v);
6918 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
6919 test_table_cell_padding(table, "10");
6921 V_VT(&v) = VT_BSTR;
6922 V_BSTR(&v) = a2bstr("11");
6923 hres = IHTMLTable_put_cellPadding(table, v);
6924 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
6925 test_table_cell_padding(table, "11");
6926 VariantClear(&v);
6928 V_VT(&v) = VT_R8;
6929 V_R8(&v) = 5;
6930 hres = IHTMLTable_put_cellPadding(table, v);
6931 ok(hres == S_OK, "put_cellPadding = %08x\n", hres);
6932 test_table_cell_padding(table, "5");
6934 bstr = a2bstr("left");
6935 hres = IHTMLTable_put_align(table, bstr);
6936 ok(hres == S_OK, "set_align failed: %08x\n", hres);
6937 SysFreeString(bstr);
6939 bstr = NULL;
6940 hres = IHTMLTable_get_align(table, &bstr);
6941 ok(hres == S_OK, "get_align failed: %08x\n", hres);
6942 ok(bstr != NULL, "get_align returned NULL\n");
6943 ok(!strcmp_wa(bstr, "left"), "get_align returned %s\n", wine_dbgstr_w(bstr));
6944 SysFreeString(bstr);
6946 hres = IHTMLTable_get_bgColor(table, &vDefaultbg);
6947 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6948 ok(V_VT(&vDefaultbg) == VT_BSTR, "bstr != NULL\n");
6949 ok(!V_BSTR(&vDefaultbg), "V_BSTR(bgColor) = %s\n", wine_dbgstr_w(V_BSTR(&vDefaultbg)));
6951 V_VT(&vbg) = VT_BSTR;
6952 V_BSTR(&vbg) = a2bstr("red");
6953 hres = IHTMLTable_put_bgColor(table, vbg);
6954 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6955 VariantClear(&vbg);
6957 hres = IHTMLTable_get_bgColor(table, &vbg);
6958 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6959 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6960 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6961 VariantClear(&vbg);
6963 V_VT(&vbg) = VT_I4;
6964 V_I4(&vbg) = 0xff0000;
6965 hres = IHTMLTable_put_bgColor(table, vbg);
6966 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6967 VariantClear(&vbg);
6969 hres = IHTMLTable_get_bgColor(table, &vbg);
6970 ok(hres == S_OK, "get_bgColor failed: %08x\n", hres);
6971 ok(V_VT(&vbg) == VT_BSTR, "V_VT(&vbg) != VT_BSTR\n");
6972 ok(!strcmp_wa(V_BSTR(&vbg), "#ff0000"), "Unexpected bgcolor %s\n", wine_dbgstr_w(V_BSTR(&vbg)));
6973 VariantClear(&vbg);
6975 /* Restore Originial */
6976 hres = IHTMLTable_put_bgColor(table, vDefaultbg);
6977 ok(hres == S_OK, "put_bgColor failed: %08x\n", hres);
6978 VariantClear(&vDefaultbg);
6980 V_VT(&v) = VT_BSTR;
6981 V_BSTR(&v) = a2bstr("11");
6982 hres = IHTMLTable_put_width(table, v);
6983 ok(hres == S_OK, "put_width = %08x\n", hres);
6984 VariantClear(&v);
6985 hres = IHTMLTable_get_width(table, &v);
6986 ok(hres == S_OK, "get_width = %08x\n", hres);
6987 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6988 VariantClear(&v);
6990 V_VT(&v) = VT_BSTR;
6991 V_BSTR(&v) = a2bstr("11.9");
6992 hres = IHTMLTable_put_width(table, v);
6993 ok(hres == S_OK, "put_width = %08x\n", hres);
6994 VariantClear(&v);
6995 hres = IHTMLTable_get_width(table, &v);
6996 ok(hres == S_OK, "get_width = %08x\n", hres);
6997 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
6998 VariantClear(&v);
7000 V_VT(&v) = VT_BSTR;
7001 V_BSTR(&v) = a2bstr("40.2%");
7002 hres = IHTMLTable_put_width(table, v);
7003 ok(hres == S_OK, "put_width = %08x\n", hres);
7004 VariantClear(&v);
7005 hres = IHTMLTable_get_width(table, &v);
7006 ok(hres == S_OK, "get_width = %08x\n", hres);
7007 ok(!strcmp_wa(V_BSTR(&v), "40.2%"), "Expected 40.2%%, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7008 VariantClear(&v);
7010 V_VT(&v) = VT_I4;
7011 V_I4(&v) = 11;
7012 hres = IHTMLTable_put_width(table, v);
7013 ok(hres == S_OK, "put_width = %08x\n", hres);
7014 hres = IHTMLTable_get_width(table, &v);
7015 ok(hres == S_OK, "get_width = %08x\n", hres);
7016 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7017 VariantClear(&v);
7019 V_VT(&v) = VT_R8;
7020 V_R8(&v) = 11.9;
7021 hres = IHTMLTable_put_width(table, v);
7022 ok(hres == S_OK, "put_width = %08x\n", hres);
7023 hres = IHTMLTable_get_width(table, &v);
7024 ok(hres == S_OK, "get_width = %08x\n", hres);
7025 ok(!strcmp_wa(V_BSTR(&v), "11"), "Expected 11, got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7026 VariantClear(&v);
7028 bstr = a2bstr("box");
7029 hres = IHTMLTable_put_frame(table, bstr);
7030 ok(hres == S_OK, "put_frame = %08x\n", hres);
7031 SysFreeString(bstr);
7032 hres = IHTMLTable_get_frame(table, &bstr);
7033 ok(hres == S_OK, "get_frame = %08x\n", hres);
7034 ok(!strcmp_wa(bstr, "box"), "Expected box, got %s\n", wine_dbgstr_w(bstr));
7035 SysFreeString(bstr);
7037 test_table_modify(table);
7038 bstr = a2bstr("summary");
7039 hres = IHTMLTable3_put_summary(table3, bstr);
7040 ok(hres == S_OK, "put_summary = %08x\n", hres);
7041 SysFreeString(bstr);
7043 hres = IHTMLTable3_get_summary(table3, &bstr);
7044 ok(hres == S_OK, "get_summary = %08x\n", hres);
7045 ok(!strcmp_wa(bstr, "summary"), "Expected summary, got %s\n", wine_dbgstr_w(bstr));
7046 SysFreeString(bstr);
7048 IHTMLTable3_Release(table3);
7049 IHTMLTable_Release(table);
7052 static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
7054 SAFEARRAYBOUND dim;
7055 SAFEARRAY *sa;
7056 VARIANT *var;
7057 HRESULT hres;
7059 dim.lLbound = 0;
7060 dim.cElements = 1;
7061 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
7062 SafeArrayAccessData(sa, (void**)&var);
7063 V_VT(var) = VT_BSTR;
7064 V_BSTR(var) = a2bstr(text);
7065 SafeArrayUnaccessData(sa);
7067 if(ln)
7068 hres = IHTMLDocument2_writeln(doc, sa);
7069 else
7070 hres = IHTMLDocument2_write(doc, sa);
7071 ok(hres == S_OK, "write failed: %08x\n", hres);
7073 SafeArrayDestroy(sa);
7076 static void doc_complex_write(IHTMLDocument2 *doc)
7078 SAFEARRAYBOUND dim = {5, 0};
7079 SAFEARRAY *sa;
7080 VARIANT *args;
7081 HRESULT hres;
7083 sa = SafeArrayCreate(VT_VARIANT, 1, &dim);
7084 SafeArrayAccessData(sa, (void**)&args);
7086 V_VT(args) = VT_BSTR;
7087 V_BSTR(args) = a2bstr("<body i4val=\"");
7088 V_VT(args+1) = VT_I4;
7089 V_I4(args+1) = 4;
7090 V_VT(args+2) = VT_BSTR;
7091 V_BSTR(args+2) = a2bstr("\" r8val=\"");
7092 V_VT(args+3) = VT_R8;
7093 V_R8(args+3) = 3.14;
7094 V_VT(args+4) = VT_BSTR;
7095 V_BSTR(args+4) = a2bstr("\">");
7096 SafeArrayUnaccessData(sa);
7098 hres = IHTMLDocument2_write(doc, sa);
7099 ok(hres == S_OK, "write failed: %08x\n", hres);
7101 SafeArrayDestroy(sa);
7104 static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
7106 IHTMLDocument2 *window_doc, *elem_doc;
7107 IHTMLFrameElement3 *frame_elem3;
7108 IHTMLWindow2 *content_window;
7109 HRESULT hres;
7111 content_window = get_frame_content_window(frame_elem);
7112 test_ifaces((IUnknown*)content_window, window_iids);
7113 window_doc = get_window_doc(content_window);
7114 IHTMLWindow2_Release(content_window);
7116 elem_doc = get_elem_doc(frame_elem);
7117 ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
7119 if(!iframe) {
7120 hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
7121 if(SUCCEEDED(hres)) {
7122 IDispatch *disp = NULL;
7124 hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
7125 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
7126 ok(disp != NULL, "contentDocument == NULL\n");
7127 ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
7129 IDispatch_Release(disp);
7130 IHTMLFrameElement3_Release(frame_elem3);
7131 }else {
7132 win_skip("IHTMLFrameElement3 not supported\n");
7136 IHTMLDocument2_Release(elem_doc);
7137 IHTMLDocument2_Release(window_doc);
7140 #define test_iframe_height(a,b) _test_iframe_height(__LINE__,a,b)
7141 static void _test_iframe_height(unsigned line, IHTMLElement *elem, const char *exval)
7143 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
7144 VARIANT v;
7145 HRESULT hres;
7147 hres = IHTMLIFrameElement2_get_height(iframe, &v);
7148 ok_(__FILE__,line)(hres == S_OK, "get_height failed: %08x\n", hres);
7149 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(height) = %d\n", V_VT(&v));
7150 if(exval)
7151 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "height = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
7152 else
7153 ok_(__FILE__,line)(!V_BSTR(&v), "height = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
7154 VariantClear(&v);
7155 IHTMLIFrameElement2_Release(iframe);
7158 #define set_iframe_height(a,b) _set_iframe_height(__LINE__,a,b)
7159 static void _set_iframe_height(unsigned line, IHTMLElement *elem, const char *val)
7161 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
7162 VARIANT v;
7163 HRESULT hres;
7165 V_VT(&v) = VT_BSTR;
7166 V_BSTR(&v) = a2bstr(val);
7167 hres = IHTMLIFrameElement2_put_height(iframe, v);
7168 ok_(__FILE__,line)(hres == S_OK, "put_height failed: %08x\n", hres);
7169 VariantClear(&v);
7170 IHTMLIFrameElement2_Release(iframe);
7173 #define test_iframe_width(a,b) _test_iframe_width(__LINE__,a,b)
7174 static void _test_iframe_width(unsigned line, IHTMLElement *elem, const char *exval)
7176 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
7177 VARIANT v;
7178 HRESULT hres;
7180 hres = IHTMLIFrameElement2_get_width(iframe, &v);
7181 ok_(__FILE__,line)(hres == S_OK, "get_width failed: %08x\n", hres);
7182 ok_(__FILE__,line)(V_VT(&v) == VT_BSTR, "V_VT(width) = %d\n", V_VT(&v));
7183 if(exval)
7184 ok_(__FILE__,line)(!strcmp_wa(V_BSTR(&v), exval), "width = %s, expected %s\n", wine_dbgstr_w(V_BSTR(&v)), exval);
7185 else
7186 ok_(__FILE__,line)(!V_BSTR(&v), "width = %s, expected NULL\n", wine_dbgstr_w(V_BSTR(&v)));
7187 VariantClear(&v);
7188 IHTMLIFrameElement2_Release(iframe);
7191 #define set_iframe_width(a,b) _set_iframe_width(__LINE__,a,b)
7192 static void _set_iframe_width(unsigned line, IHTMLElement *elem, const char *val)
7194 IHTMLIFrameElement2 *iframe = _get_iframe2_iface(line, (IUnknown*)elem);
7195 VARIANT v;
7196 HRESULT hres;
7198 V_VT(&v) = VT_BSTR;
7199 V_BSTR(&v) = a2bstr(val);
7200 hres = IHTMLIFrameElement2_put_width(iframe, v);
7201 ok_(__FILE__,line)(hres == S_OK, "put_width failed: %08x\n", hres);
7202 VariantClear(&v);
7203 IHTMLIFrameElement2_Release(iframe);
7206 static void test_iframe_elem(IHTMLElement *elem)
7208 IHTMLDocument2 *content_doc, *owner_doc;
7209 IHTMLIFrameElement3 *iframe3;
7210 IHTMLElementCollection *col;
7211 IHTMLWindow2 *content_window;
7212 IHTMLElement *body;
7213 IDispatch *disp;
7214 VARIANT errv;
7215 BSTR str;
7216 HRESULT hres;
7218 static const elem_type_t all_types[] = {
7219 ET_HTML,
7220 ET_HEAD,
7221 ET_TITLE,
7222 ET_BODY,
7223 ET_BR
7226 test_frame_doc((IUnknown*)elem, TRUE);
7227 test_framebase((IUnknown*)elem);
7229 content_window = get_frame_content_window((IUnknown*)elem);
7230 test_ifaces((IUnknown*)content_window, window_iids);
7231 test_window_length(content_window, 0);
7233 content_doc = get_window_doc(content_window);
7234 IHTMLWindow2_Release(content_window);
7236 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLIFrameElement3, (void**)&iframe3);
7237 if(SUCCEEDED(hres)) {
7238 hres = IHTMLIFrameElement3_get_contentDocument(iframe3, &disp);
7239 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
7240 ok(iface_cmp((IUnknown*)content_doc, (IUnknown*)disp), "content_doc != disp\n");
7241 IDispatch_Release(disp);
7243 IHTMLIFrameElement3_Release(iframe3);
7244 }else {
7245 win_skip("IHTMLIFrameElement3 not supported\n");
7248 test_iframe_height(elem, NULL);
7249 set_iframe_height(elem, "100px");
7250 set_iframe_height(elem, "50%");
7251 test_iframe_height(elem, "50%");
7253 test_iframe_width(elem, NULL);
7254 set_iframe_width(elem, "150px");
7255 set_iframe_width(elem, "70%");
7256 test_iframe_width(elem, "70%");
7257 test_framebase_src(elem, "about:blank");
7259 str = a2bstr("text/html");
7260 V_VT(&errv) = VT_ERROR;
7261 disp = NULL;
7262 hres = IHTMLDocument2_open(content_doc, str, errv, errv, errv, &disp);
7263 SysFreeString(str);
7264 ok(hres == S_OK, "open failed: %08x\n", hres);
7265 ok(disp != NULL, "disp == NULL\n");
7266 ok(iface_cmp((IUnknown*)disp, (IUnknown*)content_window), "disp != content_window\n");
7267 IDispatch_Release(disp);
7269 doc_write(content_doc, FALSE, "<html><head><title>test</title></head>");
7270 doc_complex_write(content_doc);
7271 doc_write(content_doc, TRUE, "<br />");
7272 doc_write(content_doc, TRUE, "</html>");
7274 hres = IHTMLDocument2_get_all(content_doc, &col);
7275 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7276 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7277 IHTMLElementCollection_Release(col);
7279 body = doc_get_body(content_doc);
7280 test_elem_attr(body, "i4val", "4");
7281 test_elem_attr(body, "r8val", "3.14");
7282 IHTMLElement_Release(body);
7284 hres = IHTMLDocument2_close(content_doc);
7285 ok(hres == S_OK, "close failed: %08x\n", hres);
7287 owner_doc = get_owner_doc((IUnknown*)content_doc);
7288 ok(!owner_doc, "owner_doc = %p\n", owner_doc);
7290 IHTMLDocument2_Release(content_doc);
7293 #define test_stylesheet_csstext(a,b,c) _test_stylesheet_csstext(__LINE__,a,b,c)
7294 static void _test_stylesheet_csstext(unsigned line, IHTMLStyleSheet *stylesheet, const char *exstr, BOOL is_todo)
7296 BSTR str;
7297 HRESULT hres;
7299 hres = IHTMLStyleSheet_get_cssText(stylesheet, &str);
7300 ok_(__FILE__,line)(hres == S_OK, "get_cssText failed: %08x\n", hres);
7301 if(!is_todo) {
7302 if(exstr)
7303 ok_(__FILE__,line)(is_prefix_wa(str, exstr), "cssText = %s\n", wine_dbgstr_w(str));
7304 else
7305 ok_(__FILE__,line)(!str, "cssText = %s\n", wine_dbgstr_w(str));
7306 }else todo_wine {
7307 if(exstr)
7308 ok_(__FILE__,line)(is_prefix_wa(str, exstr), "cssText = %s\n", wine_dbgstr_w(str));
7309 else
7310 ok_(__FILE__,line)(!str, "cssText = %s\n", wine_dbgstr_w(str));
7313 SysFreeString(str);
7316 #define set_stylesheet_csstext(a,b,c) _set_stylesheet_csstext(__LINE__,a,b,c)
7317 static void _set_stylesheet_csstext(unsigned line, IHTMLStyleSheet *stylesheet, const char *csstext, BOOL is_todo)
7319 BSTR str = a2bstr(csstext);
7320 HRESULT hres;
7322 hres = IHTMLStyleSheet_put_cssText(stylesheet, str);
7323 if(!is_todo)
7324 ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
7325 else
7326 todo_wine ok_(__FILE__,line)(hres == S_OK, "put_cssText failed: %08x\n", hres);
7327 SysFreeString(str);
7330 static void test_stylesheet(IDispatch *disp)
7332 IHTMLStyleSheetRulesCollection *col = NULL;
7333 IHTMLStyleSheet *stylesheet;
7334 HRESULT hres;
7335 BSTR href;
7337 test_disp2((IUnknown*)disp, &DIID_DispHTMLStyleSheet, &IID_IHTMLStyleSheet, "[object]");
7339 hres = IDispatch_QueryInterface(disp, &IID_IHTMLStyleSheet, (void**)&stylesheet);
7340 ok(hres == S_OK, "Could not get IHTMLStyleSheet: %08x\n", hres);
7342 hres = IHTMLStyleSheet_get_rules(stylesheet, &col);
7343 ok(hres == S_OK, "get_rules failed: %08x\n", hres);
7344 ok(col != NULL, "col == NULL\n");
7346 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetRulesCollection, &IID_IHTMLStyleSheetRulesCollection, "[object]");
7347 IHTMLStyleSheetRulesCollection_Release(col);
7349 href = (void*)0xdeadbeef;
7350 hres = IHTMLStyleSheet_get_href(stylesheet, &href);
7351 ok(hres == S_OK, "get_href failed: %08x\n", hres);
7352 ok(href == NULL, "got href != NULL\n");
7353 SysFreeString(href);
7355 test_stylesheet_csstext(stylesheet, ".body {", FALSE);
7356 set_stylesheet_csstext(stylesheet, ".div { margin-right: 1px; }\n.body { margin-right: 2px; }", TRUE);
7357 test_stylesheet_csstext(stylesheet, ".div {", TRUE);
7358 set_stylesheet_csstext(stylesheet, "", FALSE);
7359 test_stylesheet_csstext(stylesheet, NULL, FALSE);
7360 set_stylesheet_csstext(stylesheet, ".div { margin-right: 1px; }", FALSE);
7361 test_stylesheet_csstext(stylesheet, ".div {", FALSE);
7363 IHTMLStyleSheet_Release(stylesheet);
7366 static void test_stylesheets(IHTMLDocument2 *doc)
7368 IHTMLStyleSheetsCollection *col = NULL;
7369 VARIANT idx, res;
7370 LONG len = 0;
7371 HRESULT hres;
7373 hres = IHTMLDocument2_get_styleSheets(doc, &col);
7374 ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
7375 ok(col != NULL, "col == NULL\n");
7377 test_disp2((IUnknown*)col, &DIID_DispHTMLStyleSheetsCollection, &IID_IHTMLStyleSheetsCollection, "[object]");
7379 hres = IHTMLStyleSheetsCollection_get_length(col, &len);
7380 ok(hres == S_OK, "get_length failed: %08x\n", hres);
7381 ok(len == 1, "len=%d\n", len);
7383 VariantInit(&res);
7384 V_VT(&idx) = VT_I4;
7385 V_I4(&idx) = 0;
7387 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
7388 ok(hres == S_OK, "item failed: %08x\n", hres);
7389 ok(V_VT(&res) == VT_DISPATCH, "V_VT(res) = %d\n", V_VT(&res));
7390 ok(V_DISPATCH(&res) != NULL, "V_DISPATCH(&res) == NULL\n");
7391 test_stylesheet(V_DISPATCH(&res));
7392 VariantClear(&res);
7394 V_VT(&res) = VT_I4;
7395 V_VT(&idx) = VT_I4;
7396 V_I4(&idx) = 1;
7398 hres = IHTMLStyleSheetsCollection_item(col, &idx, &res);
7399 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
7400 ok(V_VT(&res) == VT_EMPTY, "V_VT(res) = %d\n", V_VT(&res));
7401 VariantClear(&res);
7403 IHTMLStyleSheetsCollection_Release(col);
7406 static void test_child_col_disp(IHTMLDOMChildrenCollection *col)
7408 IDispatchEx *dispex;
7409 IHTMLDOMNode *node;
7410 DISPPARAMS dp = {NULL, NULL, 0, 0};
7411 VARIANT var;
7412 EXCEPINFO ei;
7413 LONG type;
7414 DISPID id;
7415 BSTR bstr;
7416 HRESULT hres;
7418 static const WCHAR w0[] = {'0',0};
7419 static const WCHAR w100[] = {'1','0','0',0};
7421 hres = IHTMLDOMChildrenCollection_QueryInterface(col, &IID_IDispatchEx, (void**)&dispex);
7422 ok(hres == S_OK, "Could not get IDispatchEx: %08x\n", hres);
7424 bstr = SysAllocString(w0);
7425 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
7426 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
7427 SysFreeString(bstr);
7429 VariantInit(&var);
7430 hres = IDispatchEx_InvokeEx(dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
7431 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
7432 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
7433 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
7434 node = get_node_iface((IUnknown*)V_DISPATCH(&var));
7435 type = get_node_type((IUnknown*)node);
7436 ok(type == 3, "type=%d\n", type);
7437 IHTMLDOMNode_Release(node);
7438 VariantClear(&var);
7440 bstr = SysAllocString(w100);
7441 hres = IDispatchEx_GetDispID(dispex, bstr, fdexNameCaseSensitive, &id);
7442 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
7443 SysFreeString(bstr);
7445 IDispatchEx_Release(dispex);
7448 static void test_enum_children(IUnknown *unk, unsigned len)
7450 IEnumVARIANT *enum_var;
7451 ULONG i, fetched;
7452 VARIANT v;
7453 HRESULT hres;
7455 hres = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&enum_var);
7456 ok(hres == S_OK, "Could not get IEnumVARIANT iface: %08x\n", hres);
7458 for(i=0; i<len; i++) {
7459 fetched = 0;
7460 V_VT(&v) = VT_ERROR;
7461 hres = IEnumVARIANT_Next(enum_var, 1, &v, i ? &fetched : NULL);
7462 ok(hres == S_OK, "Next failed: %08x\n", hres);
7463 if(i)
7464 ok(fetched == 1, "fetched = %d\n", fetched);
7465 ok(V_VT(&v) == VT_DISPATCH && V_DISPATCH(&v), "V_VT(v) = %d\n", V_VT(&v));
7466 IDispatch_Release(V_DISPATCH(&v));
7469 fetched = 0xdeadbeef;
7470 V_VT(&v) = VT_BOOL;
7471 hres = IEnumVARIANT_Next(enum_var, 1, &v, &fetched);
7472 ok(hres == S_FALSE, "Next returned %08x, expected S_FALSE\n", hres);
7473 ok(fetched == 0, "fetched = %d\n", fetched);
7474 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
7476 hres = IEnumVARIANT_Reset(enum_var);
7477 ok(hres == S_OK, "Reset failed: %08x\n", hres);
7479 fetched = 0xdeadbeef;
7480 V_VT(&v) = VT_BOOL;
7481 hres = IEnumVARIANT_Next(enum_var, 0, &v, &fetched);
7482 ok(hres == S_OK, "Next returned %08x, expected S_FALSE\n", hres);
7483 ok(fetched == 0, "fetched = %d\n", fetched);
7484 ok(V_VT(&v) == VT_BOOL, "V_VT(v) = %d\n", V_VT(&v));
7486 hres = IEnumVARIANT_Skip(enum_var, len > 2 ? len-2 : 0);
7487 ok(hres == S_OK, "Skip failed: %08x\n", hres);
7489 hres = IEnumVARIANT_Reset(enum_var);
7490 ok(hres == S_OK, "Reset failed: %08x\n", hres);
7492 hres = IEnumVARIANT_Skip(enum_var, len+1);
7493 ok(hres == S_FALSE, "Skip failed: %08x\n", hres);
7495 IEnumVARIANT_Release(enum_var);
7498 static void test_elems(IHTMLDocument2 *doc)
7500 IHTMLElementCollection *col;
7501 IHTMLDOMChildrenCollection *child_col;
7502 IHTMLElement *elem, *elem2, *elem3;
7503 IHTMLDOMNode *node, *node2;
7504 IHTMLWindow2 *window;
7505 IDispatch *disp;
7506 LONG type;
7507 HRESULT hres;
7508 IHTMLElementCollection *collection;
7509 IHTMLDocument3 *doc3;
7510 BSTR str;
7512 static const elem_type_t all_types[] = {
7513 ET_HTML,
7514 ET_HEAD,
7515 ET_TITLE,
7516 ET_STYLE,
7517 ET_META,
7518 ET_LINK,
7519 ET_BODY,
7520 ET_COMMENT,
7521 ET_A,
7522 ET_LABEL,
7523 ET_INPUT,
7524 ET_BUTTON,
7525 ET_SELECT,
7526 ET_OPTION,
7527 ET_OPTION,
7528 ET_TEXTAREA,
7529 ET_TABLE,
7530 ET_TBODY,
7531 ET_TR,
7532 ET_TR,
7533 ET_TD,
7534 ET_TD,
7535 ET_SCRIPT,
7536 ET_TEST,
7537 ET_OBJECT,
7538 ET_EMBED,
7539 ET_IMG,
7540 ET_IFRAME,
7541 ET_FORM,
7542 ET_DIV
7545 static const elem_type_t item_types[] = {
7546 ET_A,
7547 ET_OPTION,
7548 ET_TEXTAREA
7551 hres = IHTMLDocument2_get_all(doc, &col);
7552 ok(hres == S_OK, "get_all failed: %08x\n", hres);
7553 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
7554 test_elem_col_item(col, "x", item_types, sizeof(item_types)/sizeof(item_types[0]));
7556 elem = get_elem_col_item_idx(col, 0);
7557 test_elem_source_index(elem, 0);
7558 IHTMLElement_Release(elem);
7560 elem = get_elem_col_item_idx(col, 3);
7561 test_elem_source_index(elem, 3);
7562 IHTMLElement_Release(elem);
7564 IHTMLElementCollection_Release(col);
7566 hres = IHTMLDocument2_get_images(doc, &collection);
7567 ok(hres == S_OK, "get_images failed: %08x\n", hres);
7568 if(hres == S_OK)
7570 static const elem_type_t images_types[] = {ET_IMG};
7571 test_elem_collection((IUnknown*)collection, images_types, 1);
7573 IHTMLElementCollection_Release(collection);
7576 hres = IHTMLDocument2_get_links(doc, &collection);
7577 ok(hres == S_OK, "get_links failed: %08x\n", hres);
7578 if(hres == S_OK)
7580 static const elem_type_t images_types[] = {ET_A};
7581 test_elem_collection((IUnknown*)collection, images_types, 1);
7583 IHTMLElementCollection_Release(collection);
7586 hres = IHTMLDocument2_get_anchors(doc, &collection);
7587 ok(hres == S_OK, "get_anchors failed: %08x\n", hres);
7588 if(hres == S_OK)
7590 static const elem_type_t anchor_types[] = {ET_A};
7591 test_elem_collection((IUnknown*)collection, anchor_types, 1);
7593 IHTMLElementCollection_Release(collection);
7596 hres = IHTMLDocument2_get_scripts(doc, &collection);
7597 ok(hres == S_OK, "get_scripts failed: %08x\n", hres);
7598 if(hres == S_OK) {
7599 static const elem_type_t script_types[] = {ET_SCRIPT};
7600 test_elem_collection((IUnknown*)collection, script_types, 1);
7601 IHTMLElementCollection_Release(collection);
7604 test_plugins_col(doc);
7606 elem = get_doc_elem(doc);
7607 test_elem_istextedit(elem, VARIANT_FALSE);
7608 test_elem_all((IUnknown*)elem, all_types+1, sizeof(all_types)/sizeof(all_types[0])-1);
7609 IHTMLElement_Release(elem);
7611 get_elem_by_id(doc, "xxx", FALSE);
7612 elem = get_doc_elem_by_id(doc, "xxx");
7613 ok(!elem, "elem != NULL\n");
7615 elem = get_doc_elem_by_id(doc, "s");
7616 ok(elem != NULL, "elem == NULL\n");
7617 if(elem) {
7618 test_elem_type((IUnknown*)elem, ET_SELECT);
7619 test_elem_attr(elem, "xxx", NULL);
7620 test_elem_attr(elem, "id", "s");
7621 test_elem_class((IUnknown*)elem, NULL);
7622 test_elem_set_class((IUnknown*)elem, "cl");
7623 test_elem_set_class((IUnknown*)elem, NULL);
7624 test_elem_tabindex((IUnknown*)elem, 0);
7625 test_elem_set_tabindex((IUnknown*)elem, 1);
7626 test_elem_filters((IUnknown*)elem);
7627 test_elem_istextedit(elem, VARIANT_FALSE);
7629 node = test_node_get_parent((IUnknown*)elem);
7630 ok(node != NULL, "node == NULL\n");
7631 test_node_name((IUnknown*)node, "BODY");
7632 node2 = test_node_get_parent((IUnknown*)node);
7633 IHTMLDOMNode_Release(node);
7634 ok(node2 != NULL, "node == NULL\n");
7635 test_node_name((IUnknown*)node2, "HTML");
7636 node = test_node_get_parent((IUnknown*)node2);
7637 IHTMLDOMNode_Release(node2);
7638 ok(node != NULL, "node == NULL\n");
7639 if (node)
7641 test_node_name((IUnknown*)node, "#document");
7642 type = get_node_type((IUnknown*)node);
7643 ok(type == 9, "type=%d, expected 9\n", type);
7644 node2 = test_node_get_parent((IUnknown*)node);
7645 IHTMLDOMNode_Release(node);
7646 ok(node2 == NULL, "node != NULL\n");
7649 elem2 = test_elem_get_parent((IUnknown*)elem);
7650 ok(elem2 != NULL, "elem2 == NULL\n");
7651 test_node_name((IUnknown*)elem2, "BODY");
7653 elem3 = test_elem_get_parent((IUnknown*)elem2);
7654 ok(elem3 != NULL, "elem3 == NULL\n");
7655 test_node_name((IUnknown*)elem3, "HTML");
7657 test_elem_contains(elem3, elem2, VARIANT_TRUE);
7658 test_elem_contains(elem3, elem, VARIANT_TRUE);
7659 test_elem_contains(elem2, elem, VARIANT_TRUE);
7660 test_elem_contains(elem2, elem3, VARIANT_FALSE);
7661 test_elem_contains(elem, elem3, VARIANT_FALSE);
7662 test_elem_contains(elem, elem2, VARIANT_FALSE);
7663 test_elem_contains(elem, elem, VARIANT_TRUE);
7664 test_elem_contains(elem, NULL, VARIANT_FALSE);
7665 IHTMLElement_Release(elem2);
7667 elem2 = test_elem_get_parent((IUnknown*)elem3);
7668 ok(elem2 == NULL, "elem2 != NULL\n");
7669 test_elem_source_index(elem3, 0);
7670 IHTMLElement_Release(elem3);
7672 test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2, NULL);
7673 test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0, NULL);
7674 test_elem_getelembytag((IUnknown*)elem, ET_HTML, 0, NULL);
7676 test_elem_innertext(elem, "opt1opt2");
7678 IHTMLElement_Release(elem);
7681 elem = get_elem_by_id(doc, "s", TRUE);
7682 if(elem) {
7683 IHTMLSelectElement *select = get_select_iface((IUnknown*)elem);
7684 IHTMLDocument2 *doc_node, *elem_doc;
7686 test_select_elem(select);
7688 test_elem_istextedit(elem, VARIANT_FALSE);
7689 test_elem_title((IUnknown*)select, NULL);
7690 test_elem_set_title((IUnknown*)select, "Title");
7691 test_elem_title((IUnknown*)select, "Title");
7692 test_elem_offset((IUnknown*)select, "BODY");
7693 test_elem_bounding_client_rect((IUnknown*)select);
7695 node = get_first_child((IUnknown*)select);
7696 ok(node != NULL, "node == NULL\n");
7697 if(node) {
7698 test_elem_type((IUnknown*)node, ET_OPTION);
7699 IHTMLDOMNode_Release(node);
7702 type = get_node_type((IUnknown*)select);
7703 ok(type == 1, "type=%d\n", type);
7705 IHTMLSelectElement_Release(select);
7707 elem_doc = get_elem_doc((IUnknown*)elem);
7709 doc_node = get_doc_node(doc);
7710 ok(iface_cmp((IUnknown*)elem_doc, (IUnknown*)doc_node), "disp != doc\n");
7711 IHTMLDocument2_Release(doc_node);
7712 IHTMLDocument2_Release(elem_doc);
7714 IHTMLElement_Release(elem);
7717 elem = get_elem_by_id(doc, "sc", TRUE);
7718 if(elem) {
7719 IHTMLScriptElement *script;
7720 BSTR type;
7722 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLScriptElement, (void**)&script);
7723 ok(hres == S_OK, "Could not get IHTMLScriptElement interface: %08x\n", hres);
7725 test_elem_language(elem, NULL);
7726 test_elem_istextedit(elem, VARIANT_FALSE);
7728 if(hres == S_OK)
7730 VARIANT_BOOL vb;
7732 hres = IHTMLScriptElement_put_type (script, NULL);
7733 ok(hres == S_OK, "put_type failed: %08x\n", hres);
7734 hres = IHTMLScriptElement_get_type(script, &type);
7735 ok(hres == S_OK, "get_type failed: %08x\n", hres);
7736 ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
7738 type = a2bstr("text/javascript");
7739 hres = IHTMLScriptElement_put_type (script, type);
7740 ok(hres == S_OK, "put_type failed: %08x\n", hres);
7741 SysFreeString(type);
7742 hres = IHTMLScriptElement_get_type(script, &type);
7743 ok(hres == S_OK, "get_type failed: %08x\n", hres);
7744 ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
7745 SysFreeString(type);
7747 test_script_text(script, "<!--\nfunction Testing() {}\n// -->\n");
7749 /* test defer */
7750 hres = IHTMLScriptElement_put_defer(script, VARIANT_TRUE);
7751 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
7753 hres = IHTMLScriptElement_get_defer(script, &vb);
7754 ok(hres == S_OK, "get_defer failed: %08x\n", hres);
7755 ok(vb == VARIANT_TRUE, "get_defer result is %08x\n", hres);
7757 hres = IHTMLScriptElement_put_defer(script, VARIANT_FALSE);
7758 ok(hres == S_OK, "put_defer failed: %08x\n", hres);
7760 str = (BSTR)0xdeadbeef;
7761 hres = IHTMLScriptElement_get_src(script, &str);
7762 ok(hres == S_OK, "get_src failed: %08x\n", hres);
7763 ok(!str, "src = %s\n", wine_dbgstr_w(str));
7766 IHTMLScriptElement_Release(script);
7768 set_elem_language(elem, "vbscript");
7769 set_elem_language(elem, "xxx");
7772 elem = get_elem_by_id(doc, "in", TRUE);
7773 if(elem) {
7774 IHTMLInputElement *input;
7776 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLInputElement, (void**)&input);
7777 ok(hres == S_OK, "Could not get IHTMLInputElement: %08x\n", hres);
7779 test_elem_id((IUnknown*)elem, "in");
7780 test_elem_put_id((IUnknown*)elem, "newin");
7781 test_input_get_disabled(input, VARIANT_FALSE);
7782 test_input_set_disabled(input, VARIANT_TRUE);
7783 test_input_set_disabled(input, VARIANT_FALSE);
7784 test_elem3_set_disabled((IUnknown*)input, VARIANT_TRUE);
7785 test_input_get_disabled(input, VARIANT_TRUE);
7786 test_elem3_set_disabled((IUnknown*)input, VARIANT_FALSE);
7787 test_input_get_disabled(input, VARIANT_FALSE);
7788 test_elem_client_size((IUnknown*)elem);
7789 test_input_type(input, "text");
7790 test_elem_istextedit(elem, VARIANT_TRUE);
7792 test_node_get_value_str((IUnknown*)elem, NULL);
7793 test_node_put_value_str((IUnknown*)elem, "test");
7794 test_node_get_value_str((IUnknown*)elem, NULL);
7795 test_input_value((IUnknown*)elem, NULL);
7796 test_input_defaultValue((IUnknown*)elem, NULL);
7797 test_input_put_value((IUnknown*)elem, "test");
7798 test_input_defaultValue((IUnknown*)elem, NULL);
7799 test_elem_class((IUnknown*)elem, "testclass");
7800 test_elem_tabindex((IUnknown*)elem, 2);
7801 test_elem_set_tabindex((IUnknown*)elem, 3);
7802 test_elem_title((IUnknown*)elem, "test title");
7804 test_input_get_defaultchecked(input, VARIANT_FALSE);
7805 test_input_set_defaultchecked(input, VARIANT_TRUE);
7806 test_input_set_defaultchecked(input, VARIANT_FALSE);
7808 test_input_get_checked(input, VARIANT_FALSE);
7809 test_input_set_checked(input, VARIANT_TRUE);
7810 test_input_set_checked(input, VARIANT_FALSE);
7812 test_input_maxlength(input, 0x7fffffff);
7813 test_input_set_maxlength(input, 30);
7815 test_input_name(input, NULL);
7816 test_input_set_name(input, "test");
7818 test_input_src(input, NULL);
7819 test_input_set_src(input, "about:blank");
7821 test_input_set_size(input, 15, S_OK);
7822 test_input_get_size(input, 15);
7823 test_input_set_size(input, -100, CTL_E_INVALIDPROPERTYVALUE);
7824 test_input_get_size(input, 15);
7825 test_input_set_size(input, 0, CTL_E_INVALIDPROPERTYVALUE);
7826 test_input_get_size(input, 15);
7828 test_input_readOnly(input, VARIANT_TRUE);
7829 test_input_readOnly(input, VARIANT_FALSE);
7831 IHTMLInputElement_Release(input);
7832 IHTMLElement_Release(elem);
7835 elem = get_elem_by_id(doc, "imgid", TRUE);
7836 if(elem) {
7837 test_img_align((IUnknown*)elem, "left");
7838 test_img_name((IUnknown*)elem, "WineImg");
7839 test_img_src((IUnknown*)elem, "", NULL);
7840 test_img_set_src((IUnknown*)elem, "about:blank");
7841 test_img_src((IUnknown*)elem, "about:blank", NULL);
7842 test_img_alt((IUnknown*)elem, NULL);
7843 test_img_set_alt((IUnknown*)elem, "alt test");
7844 test_img_name((IUnknown*)elem, "WineImg");
7845 test_img_complete(elem, VARIANT_FALSE);
7846 test_img_isMap((IUnknown*)elem, VARIANT_TRUE);
7847 test_img_isMap((IUnknown*)elem, VARIANT_FALSE);
7848 IHTMLElement_Release(elem);
7851 elem = get_elem_by_id(doc, "attr", TRUE);
7852 if(elem) {
7853 test_dynamic_properties(elem);
7854 test_attr_collection(elem);
7855 test_contenteditable((IUnknown*)elem);
7856 IHTMLElement_Release(elem);
7859 elem = get_elem_by_id(doc, "styleid", TRUE);
7860 if(elem) {
7861 test_style_media((IUnknown*)elem, NULL);
7862 test_style_put_media((IUnknown*)elem, "screen");
7863 test_style_type((IUnknown*)elem, NULL);
7864 test_style_put_type((IUnknown*)elem, "text/css");
7865 IHTMLElement_Release(elem);
7868 elem = get_doc_elem_by_id(doc, "tbl");
7869 ok(elem != NULL, "elem == NULL\n");
7870 if(elem) {
7871 test_table_elem(elem);
7872 IHTMLElement_Release(elem);
7875 elem = get_doc_elem_by_id(doc, "labelid");
7876 ok(elem != NULL, "elem == NULL\n");
7877 if(elem) {
7878 test_label_elem(elem);
7879 IHTMLElement_Release(elem);
7882 elem = get_doc_elem_by_id(doc, "td2");
7883 ok(elem != NULL, "elem == NULL\n");
7884 if(elem) {
7885 test_td_elem(elem);
7886 IHTMLElement_Release(elem);
7889 elem = get_doc_elem_by_id(doc, "row2");
7890 ok(elem != NULL, "elem == NULL\n");
7891 if(elem) {
7892 test_tr_elem(elem);
7893 IHTMLElement_Release(elem);
7896 elem = get_doc_elem_by_id(doc, "ifr");
7897 ok(elem != NULL, "elem == NULL\n");
7898 if(elem) {
7899 test_iframe_elem(elem);
7900 IHTMLElement_Release(elem);
7903 elem = get_doc_elem_by_id(doc, "btnid");
7904 ok(elem != NULL, "elem == NULL\n");
7905 if(elem) {
7906 test_button_elem(elem);
7907 test_button_get_disabled(elem, VARIANT_FALSE);
7908 test_button_set_disabled(elem, VARIANT_TRUE);
7909 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
7910 test_button_get_disabled(elem, VARIANT_FALSE);
7911 IHTMLElement_Release(elem);
7914 elem = get_doc_elem_by_id(doc, "objid");
7915 ok(elem != NULL, "elem == NULL\n");
7916 if(elem) {
7917 test_object_vspace((IUnknown*)elem, 100);
7918 test_object_name(elem, "objname");
7919 set_object_name(elem, "test");
7920 set_object_name(elem, NULL);
7921 IHTMLElement_Release(elem);
7924 elem = get_elem_by_id(doc, "a", TRUE);
7925 if(elem) {
7926 test_anchor_href((IUnknown*)elem, "http://test/");
7928 /* Change the href */
7929 test_anchor_put_href((IUnknown*)elem, "http://test1/");
7930 test_anchor_href((IUnknown*)elem, "http://test1/");
7931 test_anchor_hostname((IUnknown*)elem, "test1");
7933 /* Restore the href */
7934 test_anchor_put_href((IUnknown*)elem, "http://test/");
7935 test_anchor_href((IUnknown*)elem, "http://test/");
7936 test_anchor_hostname((IUnknown*)elem, "test");
7937 test_anchor_hash(elem, NULL);
7939 /* target */
7940 test_anchor_get_target((IUnknown*)elem, NULL);
7942 test_anchor_rel((IUnknown*)elem, NULL);
7943 test_anchor_put_rel((IUnknown*)elem, "Next");
7944 test_anchor_rel((IUnknown*)elem, "Next");
7946 /* Change the target */
7947 test_anchor_put_target((IUnknown*)elem, "wine");
7948 test_anchor_get_target((IUnknown*)elem, "wine");
7950 /* Restore the target */
7951 test_anchor_put_target((IUnknown*)elem, NULL);
7952 test_anchor_get_target((IUnknown*)elem, NULL);
7954 test_anchor_name((IUnknown*)elem, "x");
7955 test_anchor_put_name((IUnknown*)elem, "anchor name");
7956 test_anchor_put_name((IUnknown*)elem, NULL);
7957 test_anchor_put_name((IUnknown*)elem, "x");
7959 test_anchor_put_href((IUnknown*)elem, "http://test/?how#hash");
7960 test_anchor_hash(elem, "#hash");
7961 test_anchor_search((IUnknown*)elem, "?how", FALSE);
7963 test_anchor_put_search((IUnknown*)elem, "?word=press");
7964 test_anchor_search((IUnknown*)elem, "?word=press", FALSE);
7965 test_anchor_put_search((IUnknown*)elem, "?????word???press");
7966 test_anchor_search((IUnknown*)elem, "?????word???press", FALSE);
7968 test_anchor_put_search((IUnknown*)elem, "?q=%E4%BD%A0%E5%A5%BD"); /* encoded cjk characters */
7969 test_anchor_search((IUnknown*)elem, "?q=%E4%BD%A0%E5%A5%BD", FALSE);
7971 test_anchor_put_search((IUnknown*)elem, "?how?old=are");
7972 test_anchor_search((IUnknown*)elem, "?how?old=are", FALSE);
7974 /* due to incorrect behavior of ie6, search string without leading "?" is interpreted
7975 as part of the pathname, and cannot be accessed by get_search. */
7976 test_anchor_put_search((IUnknown*)elem, "word=abc");
7977 test_anchor_search((IUnknown*)elem, "?word=abc", TRUE);
7979 IHTMLElement_Release(elem);
7982 elem = get_doc_elem_by_id(doc, "metaid");
7983 if(elem) {
7984 test_meta_name((IUnknown*)elem, "meta name");
7985 test_meta_content((IUnknown*)elem, "text/html; charset=utf-8");
7986 test_meta_httpequiv((IUnknown*)elem, "Content-Type");
7987 test_meta_charset((IUnknown*)elem, NULL);
7988 set_meta_charset((IUnknown*)elem, "utf-8");
7989 IHTMLElement_Release(elem);
7992 elem = doc_get_body(doc);
7994 node = get_first_child((IUnknown*)elem);
7995 ok(node != NULL, "node == NULL\n");
7996 if(node) {
7997 test_ifaces((IUnknown*)node, text_iids);
7998 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
8000 node2 = get_first_child((IUnknown*)node);
8001 ok(!node2, "node2 != NULL\n");
8003 type = get_node_type((IUnknown*)node);
8004 ok(type == 3, "type=%d\n", type);
8006 test_node_get_value_str((IUnknown*)node, "text test");
8007 test_node_put_value_str((IUnknown*)elem, "test text");
8008 test_node_get_value_str((IUnknown*)node, "text test");
8010 hres = IHTMLDOMNode_get_attributes(node, &disp);
8011 ok(hres == S_OK, "get_attributes failed: %08x\n", hres);
8012 ok(!disp, "disp != NULL\n");
8014 IHTMLDOMNode_Release(node);
8017 child_col = get_child_nodes((IUnknown*)elem);
8018 ok(child_col != NULL, "child_coll == NULL\n");
8019 if(child_col) {
8020 IUnknown *enum_unk;
8021 LONG length = 0;
8023 test_disp((IUnknown*)child_col, &DIID_DispDOMChildrenCollection, "[object]");
8025 hres = IHTMLDOMChildrenCollection_get_length(child_col, &length);
8026 ok(hres == S_OK, "get_length failed: %08x\n", hres);
8027 ok(length, "length=0\n");
8029 node2 = NULL;
8030 node = get_child_item(child_col, 0);
8031 ok(node != NULL, "node == NULL\n");
8032 if(node) {
8033 IHTMLDOMNode *prev;
8035 type = get_node_type((IUnknown*)node);
8036 ok(type == 3, "type=%d\n", type);
8037 node2 = node_get_next((IUnknown*)node);
8039 prev = node_get_prev((IUnknown*)node2);
8040 ok(iface_cmp((IUnknown*)node, (IUnknown*)prev), "node != prev\n");
8041 IHTMLDOMNode_Release(prev);
8043 IHTMLDOMNode_Release(node);
8046 node = get_child_item(child_col, 1);
8047 ok(node != NULL, "node == NULL\n");
8048 if(node) {
8049 type = get_node_type((IUnknown*)node);
8050 ok(type == 8, "type=%d\n", type);
8052 test_elem_id((IUnknown*)node, NULL);
8053 ok(iface_cmp((IUnknown*)node2, (IUnknown*)node), "node2 != node\n");
8054 IHTMLDOMNode_Release(node2);
8055 IHTMLDOMNode_Release(node);
8058 hres = IHTMLDOMChildrenCollection_item(child_col, length - 1, NULL);
8059 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
8061 hres = IHTMLDOMChildrenCollection_item(child_col, length, NULL);
8062 ok(hres == E_POINTER, "item failed: %08x, expected E_POINTER\n", hres);
8064 hres = IHTMLDOMChildrenCollection_item(child_col, 6000, &disp);
8065 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
8067 hres = IHTMLDOMChildrenCollection_item(child_col, length, &disp);
8068 ok(hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres);
8070 test_child_col_disp(child_col);
8072 hres = IHTMLDOMChildrenCollection_get__newEnum(child_col, &enum_unk);
8073 ok(hres == S_OK, "get__newEnum failed: %08x\n", hres);
8075 test_enum_children(enum_unk, length);
8077 IUnknown_Release(enum_unk);
8079 IHTMLDOMChildrenCollection_Release(child_col);
8082 test_elem3_get_disabled((IUnknown*)elem, VARIANT_FALSE);
8083 test_elem3_set_disabled((IUnknown*)elem, VARIANT_TRUE);
8084 test_elem3_set_disabled((IUnknown*)elem, VARIANT_FALSE);
8086 IHTMLElement_Release(elem);
8088 elem = get_doc_elem_by_id(doc, "frm");
8089 ok(elem != NULL, "elem == NULL\n");
8090 if(elem) {
8091 test_form_length((IUnknown*)elem, 0);
8092 test_form_elements((IUnknown*)elem);
8093 IHTMLElement_Release(elem);
8096 test_stylesheets(doc);
8097 test_create_option_elem(doc);
8098 test_create_img_elem(doc);
8100 elem = get_doc_elem_by_id(doc, "tbl");
8101 ok(elem != NULL, "elem = NULL\n");
8102 test_elem_set_innertext(elem, "inner text");
8103 IHTMLElement_Release(elem);
8105 test_doc_title(doc, "test");
8106 test_doc_set_title(doc, "test title");
8107 test_doc_title(doc, "test title");
8109 disp = NULL;
8110 hres = IHTMLDocument2_get_Script(doc, &disp);
8111 ok(hres == S_OK, "get_Script failed: %08x\n", hres);
8112 if(hres == S_OK)
8114 IDispatchEx *dispex;
8115 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
8116 ok(hres == S_OK, "IDispatch_QueryInterface failed: %08x\n", hres);
8117 if(hres == S_OK)
8119 DISPID pid = -1;
8120 BSTR str = a2bstr("Testing");
8121 hres = IDispatchEx_GetDispID(dispex, str, 1, &pid);
8122 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
8123 ok(pid != -1, "pid == -1\n");
8124 SysFreeString(str);
8125 IDispatchEx_Release(dispex);
8128 IDispatch_Release(disp);
8130 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
8131 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
8133 str = a2bstr("Img");
8134 hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
8135 ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
8136 SysFreeString(str);
8137 if(hres == S_OK)
8139 static const elem_type_t img_types[] = { ET_IMG };
8141 test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
8142 IHTMLElementCollection_Release(col);
8145 elem = get_doc_elem_by_id(doc, "y");
8146 test_elem_set_innerhtml((IUnknown*)elem, "inner html");
8147 test_elem_innerhtml((IUnknown*)elem, "inner html");
8148 test_elem_set_innerhtml((IUnknown*)elem, "");
8149 test_elem_innerhtml((IUnknown*)elem, NULL);
8150 node = node_get_next((IUnknown*)elem);
8151 ok(!node, "node = %p\n", node);
8153 elem2 = get_doc_elem_by_id(doc, "x");
8154 test_elem_tag((IUnknown*)elem2, "A");
8155 node = node_get_next((IUnknown*)elem2);
8156 IHTMLDOMNode_Release(node);
8157 IHTMLElement_Release(elem2);
8158 IHTMLElement_Release(elem);
8160 hres = IHTMLDocument3_recalc(doc3, VARIANT_TRUE);
8161 ok(hres == S_OK, "recalc failed: %08x\n", hres);
8163 IHTMLDocument3_Release(doc3);
8165 elem = get_elem_by_id(doc, "s", TRUE);
8166 if(elem) {
8167 static const elem_type_t select_types[] = { ET_OPTION, ET_OPTION, ET_OPTION };
8169 test_select_put_length((IUnknown*)elem, 3);
8170 test_elem_all((IUnknown*)elem, select_types, sizeof(select_types)/sizeof(*select_types));
8171 test_select_put_length((IUnknown*)elem, 1);
8172 test_elem_all((IUnknown*)elem, select_types, 1);
8173 IHTMLElement_Release(elem);
8176 window = get_doc_window(doc);
8177 test_window_name(window, NULL);
8178 set_window_name(window, "test name");
8179 test_window_length(window, 1);
8180 IHTMLWindow2_Release(window);
8183 static void test_attr(IHTMLElement *elem)
8185 IHTMLDOMAttribute *attr, *attr2;
8186 VARIANT v;
8188 get_elem_attr_node((IUnknown*)elem, "noattr", FALSE);
8190 attr = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
8192 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
8193 test_ifaces((IUnknown*)attr, attr_iids);
8194 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
8195 test_attr_specified(attr, VARIANT_TRUE);
8197 attr2 = get_elem_attr_node((IUnknown*)elem, "id", TRUE);
8198 ok(iface_cmp((IUnknown*)attr, (IUnknown*)attr2), "attr != attr2\n");
8199 IHTMLDOMAttribute_Release(attr2);
8201 get_attr_node_value(attr, &v, VT_BSTR);
8202 ok(!strcmp_wa(V_BSTR(&v), "divid"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8203 VariantClear(&v);
8205 V_VT(&v) = VT_BSTR;
8206 V_BSTR(&v) = a2bstr("divid2");
8207 put_attr_node_value(attr, v);
8209 get_attr_node_value(attr, &v, VT_BSTR);
8210 ok(!strcmp_wa(V_BSTR(&v), "divid2"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8211 VariantClear(&v);
8213 IHTMLDOMAttribute_Release(attr);
8215 attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
8216 get_attr_node_value(attr, &v, VT_BSTR);
8217 ok(!V_BSTR(&v), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8218 VariantClear(&v);
8220 V_VT(&v) = VT_BSTR;
8221 V_BSTR(&v) = a2bstr("newvalue");
8222 put_attr_node_value(attr, v);
8223 VariantClear(&v);
8225 attr = get_elem_attr_node((IUnknown*)elem, "emptyattr", TRUE);
8226 get_attr_node_value(attr, &v, VT_BSTR);
8227 ok(!strcmp_wa(V_BSTR(&v), "newvalue"), "V_BSTR(v) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
8228 VariantClear(&v);
8230 test_attr_specified(attr, VARIANT_TRUE);
8231 IHTMLDOMAttribute_Release(attr);
8233 V_VT(&v) = VT_I4;
8234 V_I4(&v) = 100;
8235 set_dispex_value((IUnknown*)elem, "dispprop", &v);
8236 attr = get_elem_attr_node((IUnknown*)elem, "dispprop", TRUE);
8237 get_attr_node_value(attr, &v, VT_I4);
8238 ok(V_I4(&v) == 100, "V_I4(v) = %d\n", V_I4(&v));
8239 test_attr_specified(attr, VARIANT_TRUE);
8241 V_VT(&v) = VT_I4;
8242 V_I4(&v) = 150;
8243 put_attr_node_value(attr, v);
8245 get_attr_node_value(attr, &v, VT_I4);
8246 ok(V_I4(&v) == 150, "V_I4(v) = %d\n", V_I4(&v));
8248 IHTMLDOMAttribute_Release(attr);
8250 attr = get_elem_attr_node((IUnknown*)elem, "tabIndex", TRUE);
8251 test_attr_specified(attr, VARIANT_FALSE);
8252 test_attr_expando(attr, VARIANT_FALSE);
8253 IHTMLDOMAttribute_Release(attr);
8256 static void test_blocked(IHTMLDocument2 *doc, IHTMLElement *outer_elem)
8258 IHTMLElement *elem;
8260 test_elem_set_innerhtml((IUnknown*)outer_elem,
8261 "<img id=\"imgid\" src=\"BLOCKED::http://www.winehq.org/img.png\" />");
8262 elem = get_elem_by_id(doc, "imgid", TRUE);
8263 if(elem) {
8264 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
8265 IHTMLElement_Release(elem);
8268 test_elem_set_innerhtml((IUnknown*)outer_elem,
8269 "<img id=\"imgid\" src=\"BLOCKE::http://www.winehq.org/img.png\" />");
8270 elem = get_elem_by_id(doc, "imgid", TRUE);
8271 if(elem) {
8272 test_img_src((IUnknown*)elem, "blocke::http://www.winehq.org/img.png", NULL);
8273 test_img_set_src((IUnknown*)elem, "BLOCKED:http://www.winehq.org/img.png");
8274 test_img_src((IUnknown*)elem, "blocked:http://www.winehq.org/img.png", NULL);
8275 test_img_set_src((IUnknown*)elem, "blocked::http://www.winehq.org/img.png");
8276 test_img_src((IUnknown*)elem, "BLOCKED::", "blocked::http://www.winehq.org/img.png");
8277 IHTMLElement_Release(elem);
8281 #define doc_get_elems_by_name(a,b) _doc_get_elems_by_name(__LINE__,a,b)
8282 static IHTMLElementCollection *_doc_get_elems_by_name(unsigned line, IHTMLDocument2 *doc, const char *name)
8284 IHTMLDocument3 *doc3 = _get_doc3_iface(line, doc);
8285 IHTMLElementCollection *col;
8286 BSTR str = a2bstr(name);
8287 HRESULT hres;
8289 hres = IHTMLDocument3_getElementsByName(doc3, str, &col);
8290 ok_(__FILE__,line)(hres == S_OK, "getElementsByName failed: %08x\n", hres);
8291 ok_(__FILE__,line)(col != NULL, "col = NULL\n");
8293 IHTMLDocument3_Release(doc3);
8294 SysFreeString(str);
8295 return col;
8298 static void test_elem_names(IHTMLDocument2 *doc)
8300 IHTMLElementCollection *col;
8301 IHTMLElement *body;
8302 LONG len;
8303 HRESULT hres;
8305 static const elem_type_t test1_types[] = {ET_INPUT, ET_A, ET_DIV};
8307 body = doc_get_body(doc);
8309 test_elem_set_innerhtml((IUnknown*)body,
8310 "<input name=\"test\"><a name=\"test\"></a><a name=\"xxx\"></a><div id=\"test\"></div>");
8311 col = doc_get_elems_by_name(doc, "test");
8312 test_elem_collection((IUnknown*)col, test1_types, sizeof(test1_types)/sizeof(*test1_types));
8313 IHTMLElementCollection_Release(col);
8315 col = doc_get_elems_by_name(doc, "yyy");
8316 test_elem_collection((IUnknown*)col, NULL, 0);
8317 IHTMLElementCollection_Release(col);
8319 /* case insensivity test */
8320 col = doc_get_elems_by_name(doc, "Xxx");
8321 hres = IHTMLElementCollection_get_length(col, &len);
8322 ok(hres == S_OK, "get_length failed: %08x\n", hres);
8323 todo_wine ok(len == 1, "len = %d\n", len);
8324 IHTMLElementCollection_Release(col);
8326 IHTMLElement_Release(body);
8329 static void test_elems2(IHTMLDocument2 *doc)
8331 IHTMLElement *elem, *elem2, *div;
8333 static const elem_type_t outer_types[] = {
8334 ET_BR,
8335 ET_A
8338 div = get_doc_elem_by_id(doc, "divid");
8340 elem = get_elem_by_id(doc, "linkid", TRUE);
8341 if(elem) {
8342 test_link_disabled(elem, VARIANT_FALSE);
8343 test_link_rel(elem, "stylesheet");
8344 test_link_rev(elem, NULL);
8345 test_link_type(elem, "text/css");
8346 test_link_href(elem, "about:blank");
8347 test_link_media(elem, "all");
8348 link_put_disabled(elem, VARIANT_TRUE);
8349 link_put_rel(elem, "prev");
8350 link_put_rev(elem, "next");
8351 link_put_type(elem, "text/plain");
8352 link_put_href(elem, "about:prev");
8353 IHTMLElement_Release(elem);
8356 test_elem_set_innerhtml((IUnknown*)div, "<div id=\"innerid\"></div>");
8357 elem2 = get_doc_elem_by_id(doc, "innerid");
8358 ok(elem2 != NULL, "elem2 == NULL\n");
8359 test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
8360 test_elem_all((IUnknown*)div, outer_types, sizeof(outer_types)/sizeof(*outer_types));
8361 IHTMLElement_Release(elem2);
8363 elem2 = get_doc_elem_by_id(doc, "aid");
8364 ok(elem2 != NULL, "elem2 == NULL\n");
8365 test_elem_set_outerhtml((IUnknown*)elem2, "");
8366 test_elem_all((IUnknown*)div, outer_types, 1);
8367 IHTMLElement_Release(elem2);
8369 test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\"></textarea>");
8370 elem = get_elem_by_id(doc, "ta", TRUE);
8371 if(elem) {
8372 IHTMLFormElement *form;
8374 test_textarea_value((IUnknown*)elem, NULL);
8375 test_textarea_put_value((IUnknown*)elem, "test");
8376 test_textarea_defaultvalue((IUnknown*)elem, NULL);
8377 test_textarea_put_defaultvalue((IUnknown*)elem, "defval text");
8378 test_textarea_put_value((IUnknown*)elem, "test");
8379 test_textarea_readonly((IUnknown*)elem, VARIANT_FALSE);
8380 test_textarea_put_readonly((IUnknown*)elem, VARIANT_TRUE);
8381 test_textarea_put_readonly((IUnknown*)elem, VARIANT_FALSE);
8382 test_textarea_type((IUnknown*)elem);
8384 form = get_textarea_form((IUnknown*)elem);
8385 ok(!form, "form = %p\n", form);
8387 test_elem_istextedit(elem, VARIANT_TRUE);
8389 IHTMLElement_Release(elem);
8392 test_elem_set_innerhtml((IUnknown*)div, "<textarea id=\"ta\">default text</textarea>");
8393 elem = get_elem_by_id(doc, "ta", TRUE);
8394 if(elem) {
8395 test_textarea_defaultvalue((IUnknown*)elem, "default text");
8396 IHTMLElement_Release(elem);
8399 test_elem_set_innerhtml((IUnknown*)div, "<form id=\"fid\"><textarea id=\"ta\"></textarea></form>");
8400 elem = get_elem_by_id(doc, "ta", TRUE);
8401 if(elem) {
8402 IHTMLFormElement *form;
8404 elem2 = get_elem_by_id(doc, "fid", TRUE);
8405 ok(elem2 != NULL, "elem2 == NULL\n");
8407 form = get_textarea_form((IUnknown*)elem);
8408 ok(form != NULL, "form = NULL\n");
8409 ok(iface_cmp((IUnknown*)form, (IUnknown*)elem2), "form != elem2\n");
8411 IHTMLFormElement_Release(form);
8412 IHTMLElement_Release(elem2);
8413 IHTMLElement_Release(elem);
8416 test_elem_set_innerhtml((IUnknown*)div,
8417 "<input value=\"val\" id =\"inputid\" />");
8418 elem = get_elem_by_id(doc, "inputid", TRUE);
8419 if(elem) {
8420 test_input_defaultValue((IUnknown*)elem, "val");
8421 test_input_put_value((IUnknown*)elem, "test");
8422 test_input_put_defaultValue((IUnknown*)elem, "new val");
8423 test_input_value((IUnknown*)elem, "test");
8424 IHTMLElement_Release(elem);
8427 test_elem_set_innerhtml((IUnknown*)div, "");
8428 test_insert_adjacent_elems(doc, div);
8430 test_elem_set_innerhtml((IUnknown*)div,
8431 "<form id=\"form\"><input type=\"button\" /><div><input type=\"text\" id=\"inputid\"/></div></textarea>");
8432 elem = get_elem_by_id(doc, "form", TRUE);
8433 if(elem) {
8434 test_form_length((IUnknown*)elem, 2);
8435 test_form_item(elem);
8436 test_form_action((IUnknown*)elem, NULL);
8437 test_form_put_action((IUnknown*)elem, "about:blank");
8438 test_form_method((IUnknown*)elem, "get");
8439 test_form_put_method((IUnknown*)elem, S_OK, "post");
8440 test_form_put_method((IUnknown*)elem, E_INVALIDARG, "put");
8441 test_form_method((IUnknown*)elem, "post");
8442 test_form_name((IUnknown*)elem, NULL);
8443 test_form_put_name((IUnknown*)elem, "Name");
8444 test_form_encoding((IUnknown*)elem, "application/x-www-form-urlencoded");
8445 test_form_put_encoding((IUnknown*)elem, S_OK, "text/plain");
8446 test_form_put_encoding((IUnknown*)elem, S_OK, "multipart/form-data");
8447 test_form_put_encoding((IUnknown*)elem, E_INVALIDARG, "image/png");
8448 test_form_encoding((IUnknown*)elem, "multipart/form-data");
8449 test_form_elements((IUnknown*)elem);
8450 test_form_reset((IUnknown*)elem);
8451 test_form_target((IUnknown*)elem);
8452 IHTMLElement_Release(elem);
8454 elem = get_elem_by_id(doc, "inputid", TRUE);
8455 test_input_get_form((IUnknown*)elem, "form");
8456 IHTMLElement_Release(elem);
8459 test_attr(div);
8460 test_blocked(doc, div);
8461 test_elem_names(doc);
8463 IHTMLElement_Release(div);
8466 static void test_create_elems(IHTMLDocument2 *doc)
8468 IHTMLElement *elem, *body, *elem2;
8469 IHTMLDOMNode *node, *node2, *node3, *comment;
8470 IHTMLDOMAttribute *attr;
8471 IHTMLDocument5 *doc5;
8472 IDispatch *disp;
8473 VARIANT var;
8474 LONG type;
8475 HRESULT hres;
8476 BSTR str;
8478 static const elem_type_t types1[] = { ET_TESTG };
8480 elem = test_create_elem(doc, "TEST");
8481 test_elem_tag((IUnknown*)elem, "TEST");
8482 type = get_node_type((IUnknown*)elem);
8483 ok(type == 1, "type=%d\n", type);
8484 test_ifaces((IUnknown*)elem, elem_iids);
8485 test_disp((IUnknown*)elem, &DIID_DispHTMLGenericElement, "[object]");
8486 test_elem_source_index(elem, -1);
8488 body = doc_get_body(doc);
8489 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
8491 node = test_node_append_child((IUnknown*)body, (IUnknown*)elem);
8492 test_node_has_child((IUnknown*)body, VARIANT_TRUE);
8493 elem2 = get_elem_iface((IUnknown*)node);
8494 IHTMLElement_Release(elem2);
8496 hres = IHTMLElement_get_all(body, &disp);
8497 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8498 test_elem_collection((IUnknown*)disp, types1, sizeof(types1)/sizeof(types1[0]));
8499 IDispatch_Release(disp);
8501 test_node_remove_child((IUnknown*)body, node);
8503 hres = IHTMLElement_get_all(body, &disp);
8504 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8505 test_elem_collection((IUnknown*)disp, NULL, 0);
8506 IDispatch_Release(disp);
8507 test_node_has_child((IUnknown*)body, VARIANT_FALSE);
8509 IHTMLElement_Release(elem);
8510 IHTMLDOMNode_Release(node);
8512 node = test_create_text(doc, "abc");
8513 test_ifaces((IUnknown*)node, text_iids);
8514 test_disp((IUnknown*)node, &DIID_DispHTMLDOMTextNode, "[object]");
8515 test_text_length((IUnknown*)node, 3);
8516 test_text_data((IUnknown*)node, "abc");
8517 set_text_data((IUnknown*)node, "test");
8518 test_text_data((IUnknown*)node, "test");
8519 text_append_data((IUnknown*)node, " append");
8520 test_text_data((IUnknown*)node, "test append");
8521 text_append_data((IUnknown*)node, NULL);
8522 test_text_data((IUnknown*)node, "test append");
8523 set_text_data((IUnknown*)node, "test");
8525 V_VT(&var) = VT_NULL;
8526 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
8527 IHTMLDOMNode_Release(node);
8529 node = test_create_text(doc, "insert ");
8531 V_VT(&var) = VT_DISPATCH;
8532 V_DISPATCH(&var) = (IDispatch*)node2;
8533 node3 = test_node_insertbefore((IUnknown*)body, node, &var);
8534 IHTMLDOMNode_Release(node);
8535 IHTMLDOMNode_Release(node2);
8536 IHTMLDOMNode_Release(node3);
8538 test_elem_innertext(body, "insert test");
8539 test_elem_innerhtml((IUnknown*)body, "insert test");
8541 node = test_create_text(doc, " Test");
8542 V_VT(&var) = VT_DISPATCH;
8543 V_DISPATCH(&var) = NULL;
8544 test_node_insertbefore((IUnknown*)body, node, &var);
8545 test_elem_innertext(body, "insert test Test");
8546 IHTMLDOMNode_Release(node);
8548 doc5 = get_htmldoc5_iface((IUnknown*)doc);
8549 if(doc5) {
8550 str = a2bstr("testing");
8551 hres = IHTMLDocument5_createComment(doc5, str, &comment);
8552 SysFreeString(str);
8553 ok(hres == S_OK, "createComment failed: %08x\n", hres);
8554 if(hres == S_OK)
8556 type = get_node_type((IUnknown*)comment);
8557 ok(type == 8, "type=%d, expected 8\n", type);
8559 test_node_get_value_str((IUnknown*)comment, "testing");
8560 test_elem_title((IUnknown*)comment, NULL);
8561 test_elem_set_title((IUnknown*)comment, "comment title");
8562 test_elem_title((IUnknown*)comment, "comment title");
8563 test_comment_text((IUnknown*)comment, "<!--testing-->");
8564 test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
8565 test_comment_attrs((IUnknown*)comment);
8567 IHTMLDOMNode_Release(comment);
8570 str = a2bstr("Test");
8571 hres = IHTMLDocument5_createAttribute(doc5, str, &attr);
8572 ok(hres == S_OK, "createAttribute dailed: %08x\n", hres);
8573 SysFreeString(str);
8574 if(SUCCEEDED(hres)) {
8575 test_disp((IUnknown*)attr, &DIID_DispHTMLDOMAttribute, "[object]");
8576 test_ifaces((IUnknown*)attr, attr_iids);
8577 test_no_iface((IUnknown*)attr, &IID_IHTMLDOMNode);
8579 test_attr_node_name(attr, "Test");
8581 IHTMLDOMAttribute_Release(attr);
8584 IHTMLDocument5_Release(doc5);
8587 IHTMLElement_Release(body);
8590 static void test_replacechild_elems(IHTMLDocument2 *doc)
8592 IHTMLElement *body;
8593 IHTMLDOMNode *node, *node2, *node3;
8594 IHTMLDOMNode *nodeBody, *nodeNew;
8595 HRESULT hres;
8596 VARIANT var;
8598 body = doc_get_body(doc);
8600 node = test_create_text(doc, "insert");
8602 V_VT(&var) = VT_NULL;
8603 V_DISPATCH(&var) = NULL;
8604 node2 = test_node_insertbefore((IUnknown*)body, node, &var);
8605 IHTMLDOMNode_Release(node);
8607 test_elem_innertext(body, "insert");
8609 node3 = test_create_text(doc, "replaced");
8611 nodeBody = _get_node_iface(__LINE__, (IUnknown *)body);
8613 hres = IHTMLDOMNode_replaceChild(nodeBody, node3, node2, &nodeNew);
8614 ok(hres == S_OK, "Expected S_OK, got 0x%08x\n", hres);
8616 test_elem_innertext(body, "replaced");
8618 IHTMLDOMNode_Release(node2);
8619 IHTMLDOMNode_Release(node3);
8620 IHTMLDOMNode_Release(nodeBody);
8622 IHTMLElement_Release(body);
8625 static void test_noscript(IHTMLDocument2 *doc)
8627 IHTMLElementCollection *col;
8628 IHTMLElement *body;
8629 HRESULT hres;
8631 static const elem_type_t all_types[] = {
8632 ET_HTML,
8633 ET_HEAD,
8634 ET_TITLE,
8635 ET_NOSCRIPT,
8636 ET_BODY,
8637 ET_NOSCRIPT
8640 static const elem_type_t body_all_types[] = {
8641 ET_DIV,
8642 ET_NOSCRIPT
8645 hres = IHTMLDocument2_get_all(doc, &col);
8646 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8647 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
8648 IHTMLElementCollection_Release(col);
8650 body = doc_get_body(doc);
8651 test_elem_set_innerhtml((IUnknown*)body, "<div>test</div><noscript><a href=\"about:blank\">A</a></noscript>");
8652 test_elem_all((IUnknown*)body, body_all_types, sizeof(body_all_types)/sizeof(*body_all_types));
8653 IHTMLElement_Release(body);
8656 static void test_doctype(IHTMLDocument2 *doc)
8658 IHTMLDocument2 *doc_node;
8659 IHTMLDOMNode *doctype;
8660 int type;
8662 doc_node = get_doc_node(doc);
8663 doctype = get_first_child((IUnknown*)doc_node);
8664 IHTMLDocument2_Release(doc_node);
8666 type = get_node_type((IUnknown*)doctype);
8667 ok(type == 8, "type = %d\n", type);
8669 test_comment_text((IUnknown*)doctype, "<!DOCTYPE html>");
8670 test_elem_type((IUnknown*)doctype, ET_COMMENT);
8671 IHTMLDOMNode_Release(doctype);
8674 static void test_null_write(IHTMLDocument2 *doc)
8676 HRESULT hres;
8678 doc_write(doc, FALSE, NULL);
8679 doc_write(doc, TRUE, NULL);
8681 hres = IHTMLDocument2_write(doc, NULL);
8682 ok(hres == S_OK,
8683 "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
8685 hres = IHTMLDocument2_writeln(doc, NULL);
8686 ok(hres == S_OK,
8687 "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
8690 static void test_create_stylesheet(IHTMLDocument2 *doc)
8692 IHTMLStyleSheet *stylesheet, *stylesheet2;
8693 IHTMLStyleElement *style_elem;
8694 IHTMLElement *doc_elem, *elem;
8695 HRESULT hres;
8697 static const elem_type_t all_types[] = {
8698 ET_HTML,
8699 ET_HEAD,
8700 ET_TITLE,
8701 ET_BODY,
8702 ET_DIV
8705 static const elem_type_t all_types2[] = {
8706 ET_HTML,
8707 ET_HEAD,
8708 ET_TITLE,
8709 ET_STYLE,
8710 ET_BODY,
8711 ET_DIV
8714 test_doc_all(doc, all_types, sizeof(all_types)/sizeof(*all_types));
8716 hres = IHTMLDocument2_createStyleSheet(doc, NULL, -1, &stylesheet);
8717 ok(hres == S_OK, "createStyleSheet failed: %08x\n", hres);
8719 test_doc_all(doc, all_types2, sizeof(all_types2)/sizeof(*all_types2));
8721 doc_elem = get_doc_elem(doc);
8723 test_elem_getelembytag((IUnknown*)doc_elem, ET_STYLE, 1, &elem);
8724 IHTMLElement_Release(doc_elem);
8726 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLStyleElement, (void**)&style_elem);
8727 IHTMLElement_Release(elem);
8728 ok(hres == S_OK, "Could not get IHTMLStyleElement iface: %08x\n", hres);
8730 stylesheet2 = NULL;
8731 hres = IHTMLStyleElement_get_styleSheet(style_elem, &stylesheet2);
8732 ok(hres == S_OK, "get_styleSheet failed: %08x\n", hres);
8733 ok(stylesheet2 != NULL, "stylesheet2 == NULL\n");
8734 ok(iface_cmp((IUnknown*)stylesheet, (IUnknown*)stylesheet2), "stylesheet != stylesheet2\n");
8736 IHTMLStyleSheet_Release(stylesheet2);
8737 IHTMLStyleSheet_Release(stylesheet);
8739 IHTMLStyleElement_Release(style_elem);
8742 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
8744 IOleCommandTarget *cmdtrg;
8745 HRESULT hres;
8747 hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
8748 ok(hres == S_OK, "Could not get IOleCommandTarget interface: %08x\n", hres);
8750 hres = IOleCommandTarget_Exec(cmdtrg, grpid, cmdid, 0, in, out);
8751 ok(hres == S_OK, "Exec failed: %08x\n", hres);
8753 IOleCommandTarget_Release(cmdtrg);
8756 static void test_indent(IHTMLDocument2 *doc)
8758 IHTMLElementCollection *col;
8759 IHTMLTxtRange *range;
8760 HRESULT hres;
8762 static const elem_type_t all_types[] = {
8763 ET_HTML,
8764 ET_HEAD,
8765 ET_TITLE,
8766 ET_BODY,
8767 ET_BR,
8768 ET_A,
8771 static const elem_type_t indent_types[] = {
8772 ET_HTML,
8773 ET_HEAD,
8774 ET_TITLE,
8775 ET_BODY,
8776 ET_BLOCKQUOTE,
8777 ET_P,
8778 ET_BR,
8779 ET_A,
8782 hres = IHTMLDocument2_get_all(doc, &col);
8783 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8784 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
8785 IHTMLElementCollection_Release(col);
8787 range = test_create_body_range(doc);
8788 test_exec((IUnknown*)range, &CGID_MSHTML, IDM_INDENT, NULL, NULL);
8789 IHTMLTxtRange_Release(range);
8791 hres = IHTMLDocument2_get_all(doc, &col);
8792 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8793 test_elem_collection((IUnknown*)col, indent_types, sizeof(indent_types)/sizeof(indent_types[0]));
8794 IHTMLElementCollection_Release(col);
8797 static void test_cond_comment(IHTMLDocument2 *doc)
8799 IHTMLElementCollection *col;
8800 HRESULT hres;
8802 static const elem_type_t all_types[] = {
8803 ET_HTML,
8804 ET_HEAD,
8805 ET_TITLE,
8806 ET_BODY,
8807 ET_BR
8810 hres = IHTMLDocument2_get_all(doc, &col);
8811 ok(hres == S_OK, "get_all failed: %08x\n", hres);
8812 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
8813 IHTMLElementCollection_Release(col);
8816 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
8818 ok(IsEqualGUID(riid, &IID_IServiceProvider), "riid = %s\n", wine_dbgstr_guid(riid));
8819 return E_NOINTERFACE;
8822 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
8824 return 2;
8827 static ULONG WINAPI Unknown_Release(IUnknown *iface)
8829 return 1;
8832 static const IUnknownVtbl UnknownVtbl = {
8833 Unknown_QueryInterface,
8834 Unknown_AddRef,
8835 Unknown_Release,
8837 static IUnknown obj_ident_test = { &UnknownVtbl };
8839 static void test_frame(IDispatch *disp, const char *exp_id)
8841 IHTMLWindow2 *frame2, *parent, *top;
8842 IHTMLDocument2 *parent_doc, *top_doc;
8843 IHTMLWindow4 *frame;
8844 IHTMLFrameBase *frame_elem;
8845 IObjectIdentity *obj_ident;
8846 ITravelLogClient *tlc;
8847 HRESULT hres;
8849 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow4, (void**)&frame);
8850 ok(hres == S_OK, "Could not get IHTMLWindow4 interface: 0x%08x\n", hres);
8851 if(FAILED(hres))
8852 return;
8854 hres = IHTMLWindow4_get_frameElement(frame, &frame_elem);
8855 ok(hres == S_OK, "IHTMLWindow4_get_frameElement failed: 0x%08x\n", hres);
8856 IHTMLWindow4_Release(frame);
8857 if(FAILED(hres))
8858 return;
8860 test_elem_type((IUnknown*)frame_elem, ET_FRAME);
8861 test_frame_doc((IUnknown*)frame_elem, FALSE);
8862 test_elem_id((IUnknown*)frame_elem, exp_id);
8863 IHTMLFrameBase_Release(frame_elem);
8865 hres = IDispatch_QueryInterface(disp, &IID_IHTMLWindow2, (void**)&frame2);
8866 ok(hres == S_OK, "Could not get IHTMLWindow2 interface: 0x%08x\n", hres);
8867 if(FAILED(hres))
8868 return;
8870 hres = IHTMLWindow2_get_parent(frame2, &parent);
8871 ok(hres == S_OK, "IHTMLWindow2_get_parent failed: 0x%08x\n", hres);
8872 if(FAILED(hres)){
8873 IHTMLWindow2_Release(frame2);
8874 return;
8877 hres = IHTMLWindow2_QueryInterface(frame2, &IID_IObjectIdentity, (void**)&obj_ident);
8878 ok(hres == S_OK, "Could not get IObjectIdentity interface: %08x\n", hres);
8879 hres = IHTMLWindow2_QueryInterface(frame2, &IID_ITravelLogClient, (void**)&tlc);
8880 if(hres == E_NOINTERFACE) {
8881 win_skip("IID_ITravelLogClient not available\n");
8882 tlc = NULL;
8883 }else {
8884 ok(hres == S_OK, "Could not get ITravelLogClient interface: %08x\n", hres);
8886 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)tlc);
8887 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
8888 ITravelLogClient_Release(tlc);
8891 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)obj_ident);
8892 ok(hres == S_OK, "IsEqualObject returned: 0x%08x\n", hres);
8893 hres = IObjectIdentity_IsEqualObject(obj_ident, (IUnknown*)parent);
8894 ok(hres == S_FALSE, "IsEqualObject returned: 0x%08x\n", hres);
8895 hres = IObjectIdentity_IsEqualObject(obj_ident, &obj_ident_test);
8896 ok(hres == E_NOINTERFACE, "IsEqualObject returned: 0x%08x\n", hres);
8898 IObjectIdentity_Release(obj_ident);
8900 hres = IHTMLWindow2_get_document(parent, &parent_doc);
8901 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
8902 IHTMLWindow2_Release(parent);
8903 if(FAILED(hres)){
8904 IHTMLWindow2_Release(frame2);
8905 return;
8908 test_doc_title(parent_doc, "frameset test");
8909 IHTMLDocument2_Release(parent_doc);
8911 /* test get_top */
8912 hres = IHTMLWindow2_get_top(frame2, &top);
8913 ok(hres == S_OK, "IHTMLWindow2_get_top failed: 0x%08x\n", hres);
8914 IHTMLWindow2_Release(frame2);
8915 if(FAILED(hres))
8916 return;
8918 hres = IHTMLWindow2_get_document(top, &top_doc);
8919 ok(hres == S_OK, "IHTMLWindow2_get_document failed: 0x%08x\n", hres);
8920 IHTMLWindow2_Release(top);
8921 if(FAILED(hres))
8922 return;
8924 test_doc_title(top_doc, "frameset test");
8925 IHTMLDocument2_Release(top_doc);
8928 static void test_frames_collection(IHTMLFramesCollection2 *frames, const char *frid)
8930 VARIANT index_var, result_var;
8931 LONG length;
8932 HRESULT hres;
8934 /* test result length */
8935 hres = IHTMLFramesCollection2_get_length(frames, &length);
8936 ok(hres == S_OK, "IHTMLFramesCollection2_get_length failed: 0x%08x\n", hres);
8937 ok(length == 3, "IHTMLFramesCollection2_get_length should have been 3, was: %d\n", length);
8939 /* test first frame */
8940 V_VT(&index_var) = VT_I4;
8941 V_I4(&index_var) = 0;
8942 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8943 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
8944 if(SUCCEEDED(hres)) {
8945 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
8946 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr1");
8948 VariantClear(&result_var);
8950 /* test second frame */
8951 V_I4(&index_var) = 1;
8952 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8953 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
8954 if(SUCCEEDED(hres)) {
8955 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
8956 test_frame((IDispatch*)V_DISPATCH(&result_var), "fr2");
8958 VariantClear(&result_var);
8960 /* fail on next frame */
8961 V_I4(&index_var) = 3;
8962 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8963 ok(hres == DISP_E_MEMBERNOTFOUND, "IHTMLFramesCollection2_item should have"
8964 "failed with DISP_E_MEMBERNOTFOUND, instead: 0x%08x\n", hres);
8965 VariantClear(&result_var);
8967 /* string argument (element id lookup) */
8968 V_VT(&index_var) = VT_BSTR;
8969 V_BSTR(&index_var) = a2bstr(frid);
8970 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8971 ok(hres == S_OK, "IHTMLFramesCollection2_item failed: 0x%08x\n", hres);
8972 if(SUCCEEDED(hres)) {
8973 ok(V_VT(&result_var) == VT_DISPATCH, "result type should have been VT_DISPATCH, was: 0x%x\n", V_VT(&result_var));
8974 test_frame(V_DISPATCH(&result_var), frid);
8976 VariantClear(&result_var);
8977 VariantClear(&index_var);
8979 /* invalid argument */
8980 V_VT(&index_var) = VT_BOOL;
8981 V_BOOL(&index_var) = VARIANT_TRUE;
8982 hres = IHTMLFramesCollection2_item(frames, &index_var, &result_var);
8983 ok(hres == E_INVALIDARG, "IHTMLFramesCollection2_item should have"
8984 "failed with E_INVALIDARG, instead: 0x%08x\n", hres);
8985 VariantClear(&result_var);
8988 static void test_frameset(IHTMLDocument2 *doc)
8990 IHTMLWindow2 *window;
8991 IHTMLFramesCollection2 *frames;
8992 IHTMLElement *elem;
8993 HRESULT hres;
8995 window = get_doc_window(doc);
8997 /* test using IHTMLFramesCollection object */
8999 hres = IHTMLWindow2_get_frames(window, &frames);
9000 ok(hres == S_OK, "IHTMLWindow2_get_frames failed: 0x%08x\n", hres);
9001 if(FAILED(hres))
9002 return;
9004 test_frames_collection(frames, "fr1");
9005 IHTMLFramesCollection2_Release(frames);
9007 hres = IHTMLDocument2_get_frames(doc, &frames);
9008 ok(hres == S_OK, "IHTMLDocument2_get_frames failed: 0x%08x\n", hres);
9009 if(FAILED(hres))
9010 return;
9012 test_frames_collection(frames, "fr1");
9013 IHTMLFramesCollection2_Release(frames);
9015 /* test using IHTMLWindow2 inheritance */
9016 test_frames_collection((IHTMLFramesCollection2*)window, "fr2");
9018 /* getElementById with node name attributes */
9019 elem = get_doc_elem_by_id(doc, "nm1");
9020 test_elem_id((IUnknown*)elem, "fr1");
9022 test_framebase((IUnknown*)elem);
9023 test_framebase_name(elem, "nm1");
9024 test_framebase_put_name(elem, "frame name");
9025 test_framebase_put_name(elem, NULL);
9026 test_framebase_put_name(elem, "nm1");
9027 test_framebase_src(elem, "about:blank");
9028 IHTMLElement_Release(elem);
9030 /* get_name with no name attr */
9031 elem = get_doc_elem_by_id(doc, "fr3");
9032 test_framebase_name(elem, NULL);
9033 test_framebase_put_name(elem, "frame name");
9034 test_framebase_put_name(elem, NULL);
9035 IHTMLElement_Release(elem);
9037 IHTMLWindow2_Release(window);
9040 static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc)
9042 IHTMLDocument2 *frag;
9043 IHTMLDocument3 *doc3;
9044 HRESULT hres;
9046 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
9047 ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
9049 hres = IHTMLDocument3_createDocumentFragment(doc3, &frag);
9050 IHTMLDocument3_Release(doc3);
9051 ok(hres == S_OK, "createDocumentFragment failed: %08x\n", hres);
9052 ok(frag != NULL, "frag == NULL\n");
9054 return frag;
9057 static void test_docfrag(IHTMLDocument2 *doc)
9059 IHTMLDocument2 *frag, *owner_doc, *doc_node;
9060 IHTMLElement *div, *body, *br;
9061 IHTMLElementCollection *col;
9062 IHTMLLocation *location;
9063 HRESULT hres;
9065 static const elem_type_t all_types[] = {
9066 ET_HTML,
9067 ET_HEAD,
9068 ET_TITLE,
9069 ET_BODY,
9070 ET_DIV,
9071 ET_BR
9074 frag = create_docfrag(doc);
9076 test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, "[object]");
9078 body = (void*)0xdeadbeef;
9079 hres = IHTMLDocument2_get_body(frag, &body);
9080 ok(hres == S_OK, "get_body failed: %08x\n", hres);
9081 ok(!body, "body != NULL\n");
9083 location = (void*)0xdeadbeef;
9084 hres = IHTMLDocument2_get_location(frag, &location);
9085 ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
9086 ok(location == (void*)0xdeadbeef, "location changed\n");
9088 br = test_create_elem(doc, "BR");
9089 test_elem_source_index(br, -1);
9090 test_node_append_child((IUnknown*)frag, (IUnknown*)br);
9091 test_elem_source_index(br, 0);
9092 IHTMLElement_Release(br);
9094 div = get_elem_by_id(doc, "divid", TRUE);
9095 test_node_append_child((IUnknown*)div, (IUnknown*)frag);
9096 IHTMLElement_Release(div);
9098 hres = IHTMLDocument2_get_all(doc, &col);
9099 ok(hres == S_OK, "get_all failed: %08x\n", hres);
9100 test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0]));
9101 IHTMLElementCollection_Release(col);
9103 div = test_create_elem(frag, "div");
9104 owner_doc = get_owner_doc((IUnknown*)div);
9105 doc_node = get_doc_node(doc);
9106 ok(iface_cmp((IUnknown*)owner_doc, (IUnknown*)doc_node), "owner_doc != doc_node\n");
9107 IHTMLDocument2_Release(doc_node);
9108 IHTMLDocument2_Release(owner_doc);
9109 IHTMLElement_Release(div);
9111 IHTMLDocument2_Release(frag);
9114 static void check_quirks_mode(IHTMLDocument2 *doc)
9116 test_compatmode(doc, "BackCompat");
9119 static void check_strict_mode(IHTMLDocument2 *doc)
9121 test_compatmode(doc, "CSS1Compat");
9124 static void test_quirks_mode_offsetHeight(IHTMLDocument2 *doc)
9126 IHTMLElement *elem;
9127 HRESULT hres;
9128 LONG oh;
9130 hres = IHTMLDocument2_get_body(doc, &elem);
9131 ok(hres == S_OK, "get_body fauled: %08x\n", hres);
9133 /* body.offsetHeight value depends on window size in quirks mode */
9134 hres = IHTMLElement_get_offsetHeight(elem, &oh);
9135 ok(hres == S_OK, "get_offsetHeight failed: %08x\n", hres);
9136 todo_wine ok(oh == 500, "offsetHeight = %d\n", oh);
9137 IHTMLElement_Release(elem);
9140 static IHTMLDocument2 *notif_doc;
9141 static BOOL doc_complete;
9143 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
9144 REFIID riid, void**ppv)
9146 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
9147 *ppv = iface;
9148 return S_OK;
9151 ok(0, "unexpected call\n");
9152 return E_NOINTERFACE;
9155 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
9157 return 2;
9160 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
9162 return 1;
9165 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
9167 if(dispID == DISPID_READYSTATE){
9168 BSTR state;
9169 HRESULT hres;
9171 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
9172 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
9174 if(!strcmp_wa(state, "complete"))
9175 doc_complete = TRUE;
9177 SysFreeString(state);
9180 return S_OK;
9183 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
9185 ok(0, "unexpected call\n");
9186 return E_NOTIMPL;
9189 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
9190 PropertyNotifySink_QueryInterface,
9191 PropertyNotifySink_AddRef,
9192 PropertyNotifySink_Release,
9193 PropertyNotifySink_OnChanged,
9194 PropertyNotifySink_OnRequestEdit
9197 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
9199 static HRESULT cs_qi(REFIID,void **);
9200 static IOleDocumentView *view;
9201 static HWND container_hwnd;
9203 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
9205 static const GUID undocumented_frame_iid = {0xfbece6c9,0x48d7,0x4a37,{0x8f,0xe3,0x6a,0xd4,0x27,0x2f,0xdd,0xac}};
9207 if(!IsEqualGUID(&undocumented_frame_iid, riid))
9208 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
9210 *ppv = NULL;
9211 return E_NOINTERFACE;
9214 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
9216 return 2;
9219 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
9221 return 1;
9224 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
9226 return E_NOTIMPL;
9229 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
9231 return E_NOTIMPL;
9234 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
9236 return E_NOTIMPL;
9239 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
9240 LPCBORDERWIDTHS pborderwidths)
9242 return E_NOTIMPL;
9245 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
9246 LPCBORDERWIDTHS pborderwidths)
9248 return S_OK;
9251 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
9252 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
9254 return S_OK;
9257 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
9258 LPOLEMENUGROUPWIDTHS lpMenuWidths)
9260 return E_NOTIMPL;
9263 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
9264 HOLEMENU holemenu, HWND hwndActiveObject)
9266 ok(0, "unexpected call\n");
9267 return E_NOTIMPL;
9270 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
9272 ok(0, "unexpected call\n");
9273 return E_NOTIMPL;
9276 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
9278 return S_OK;
9281 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
9283 return E_NOTIMPL;
9286 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
9288 ok(0, "unexpected call\n");
9289 return E_NOTIMPL;
9292 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
9293 InPlaceFrame_QueryInterface,
9294 InPlaceFrame_AddRef,
9295 InPlaceFrame_Release,
9296 InPlaceFrame_GetWindow,
9297 InPlaceFrame_ContextSensitiveHelp,
9298 InPlaceFrame_GetBorder,
9299 InPlaceFrame_RequestBorderSpace,
9300 InPlaceFrame_SetBorderSpace,
9301 InPlaceFrame_SetActiveObject,
9302 InPlaceFrame_InsertMenus,
9303 InPlaceFrame_SetMenu,
9304 InPlaceFrame_RemoveMenus,
9305 InPlaceFrame_SetStatusText,
9306 InPlaceFrame_EnableModeless,
9307 InPlaceFrame_TranslateAccelerator
9310 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
9312 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
9314 return cs_qi(riid, ppv);
9317 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
9319 return 2;
9322 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
9324 return 1;
9327 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
9329 *phwnd = container_hwnd;
9330 return S_OK;
9333 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
9335 ok(0, "unexpected call\n");
9336 return E_NOTIMPL;
9339 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
9341 return S_OK;
9344 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
9346 return S_OK;
9349 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
9351 return S_OK;
9354 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
9355 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
9356 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
9358 static const RECT rect = {0,0,500,500};
9360 *ppFrame = &InPlaceFrame;
9361 *ppDoc = NULL;
9362 *lprcPosRect = rect;
9363 *lprcClipRect = rect;
9365 lpFrameInfo->fMDIApp = FALSE;
9366 lpFrameInfo->hwndFrame = container_hwnd;
9367 lpFrameInfo->haccel = NULL;
9368 lpFrameInfo->cAccelEntries = 0;
9370 return S_OK;
9373 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
9375 return E_NOTIMPL;
9378 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
9380 return S_OK;
9383 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
9385 return S_OK;
9388 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
9390 return E_NOTIMPL;
9393 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
9395 return E_NOTIMPL;
9398 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
9400 return E_NOTIMPL;
9403 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
9404 InPlaceSite_QueryInterface,
9405 InPlaceSite_AddRef,
9406 InPlaceSite_Release,
9407 InPlaceSite_GetWindow,
9408 InPlaceSite_ContextSensitiveHelp,
9409 InPlaceSite_CanInPlaceActivate,
9410 InPlaceSite_OnInPlaceActivate,
9411 InPlaceSite_OnUIActivate,
9412 InPlaceSite_GetWindowContext,
9413 InPlaceSite_Scroll,
9414 InPlaceSite_OnUIDeactivate,
9415 InPlaceSite_OnInPlaceDeactivate,
9416 InPlaceSite_DiscardUndoState,
9417 InPlaceSite_DeactivateAndUndo,
9418 InPlaceSite_OnPosRectChange,
9421 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
9423 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
9425 return cs_qi(riid, ppv);
9428 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
9430 return 2;
9433 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
9435 return 1;
9438 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
9440 ok(0, "unexpected call\n");
9441 return E_NOTIMPL;
9444 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
9445 IMoniker **ppmon)
9447 ok(0, "unexpected call\n");
9448 return E_NOTIMPL;
9451 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
9453 return E_NOTIMPL;
9456 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
9458 ok(0, "unexpected call\n");
9459 return E_NOTIMPL;
9462 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
9464 ok(0, "unexpected call\n");
9465 return E_NOTIMPL;
9468 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
9470 ok(0, "unexpected call\n");
9471 return E_NOTIMPL;
9474 static const IOleClientSiteVtbl ClientSiteVtbl = {
9475 ClientSite_QueryInterface,
9476 ClientSite_AddRef,
9477 ClientSite_Release,
9478 ClientSite_SaveObject,
9479 ClientSite_GetMoniker,
9480 ClientSite_GetContainer,
9481 ClientSite_ShowObject,
9482 ClientSite_OnShowWindow,
9483 ClientSite_RequestNewObjectLayout
9486 static IOleClientSite ClientSite = { &ClientSiteVtbl };
9488 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
9490 return cs_qi(riid, ppv);
9493 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
9495 return 2;
9498 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
9500 return 1;
9503 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
9505 RECT rect = {0,0,500,500};
9506 IOleDocument *document;
9507 HRESULT hres;
9509 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
9510 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
9512 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
9513 IOleDocument_Release(document);
9514 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
9516 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
9517 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
9519 hres = IOleDocumentView_UIActivate(view, TRUE);
9520 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
9522 hres = IOleDocumentView_SetRect(view, &rect);
9523 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
9525 hres = IOleDocumentView_Show(view, TRUE);
9526 ok(hres == S_OK, "Show failed: %08x\n", hres);
9528 return S_OK;
9531 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
9532 DocumentSite_QueryInterface,
9533 DocumentSite_AddRef,
9534 DocumentSite_Release,
9535 DocumentSite_ActivateMe
9538 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
9540 static HRESULT cs_qi(REFIID riid, void **ppv)
9542 *ppv = NULL;
9544 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
9545 *ppv = &ClientSite;
9546 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
9547 *ppv = &DocumentSite;
9548 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
9549 *ppv = &InPlaceSite;
9551 return *ppv ? S_OK : E_NOINTERFACE;
9554 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
9556 IOleObject *oleobj;
9557 HRESULT hres;
9559 if(!set && view) {
9560 IOleDocumentView_Show(view, FALSE);
9561 IOleDocumentView_CloseView(view, 0);
9562 IOleDocumentView_SetInPlaceSite(view, NULL);
9563 IOleDocumentView_Release(view);
9564 view = NULL;
9567 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
9568 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
9570 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
9571 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
9573 if(set) {
9574 IHlinkTarget *hlink;
9576 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
9577 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
9579 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
9580 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
9582 IHlinkTarget_Release(hlink);
9585 IOleObject_Release(oleobj);
9588 static IHTMLDocument2 *create_doc_with_string(const char *str)
9590 IPersistStreamInit *init;
9591 IStream *stream;
9592 IHTMLDocument2 *doc;
9593 HGLOBAL mem;
9594 SIZE_T len;
9596 notif_doc = doc = create_document();
9597 if(!doc)
9598 return NULL;
9600 doc_complete = FALSE;
9601 len = strlen(str);
9602 mem = GlobalAlloc(0, len);
9603 memcpy(mem, str, len);
9604 CreateStreamOnHGlobal(mem, TRUE, &stream);
9606 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
9608 IPersistStreamInit_Load(init, stream);
9609 IPersistStreamInit_Release(init);
9610 IStream_Release(stream);
9612 return doc;
9615 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
9617 IConnectionPointContainer *container;
9618 IConnectionPoint *cp;
9619 DWORD cookie;
9620 HRESULT hres;
9622 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
9623 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
9625 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
9626 IConnectionPointContainer_Release(container);
9627 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
9629 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
9630 IConnectionPoint_Release(cp);
9631 ok(hres == S_OK, "Advise failed: %08x\n", hres);
9634 typedef void (*domtest_t)(IHTMLDocument2*);
9636 static void run_domtest(const char *str, domtest_t test)
9638 IHTMLDocument2 *doc;
9639 ULONG ref;
9640 MSG msg;
9642 doc = create_doc_with_string(str);
9643 if(!doc)
9644 return;
9646 set_client_site(doc, TRUE);
9647 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
9649 while(!doc_complete && GetMessageW(&msg, NULL, 0, 0)) {
9650 TranslateMessage(&msg);
9651 DispatchMessageW(&msg);
9654 test(doc);
9656 set_client_site(doc, FALSE);
9657 ref = IHTMLDocument2_Release(doc);
9658 ok(!ref || broken(ref == 1), /* Vista */
9659 "ref = %d\n", ref);
9662 static void test_quirks_mode(void)
9664 run_domtest("<html></html>", check_quirks_mode);
9665 run_domtest("<!DOCTYPE html>\n<html></html>", check_strict_mode);
9666 run_domtest("<!-- comment --><!DOCTYPE html>\n<html></html>", check_quirks_mode);
9667 run_domtest("<html><body></body></html>", test_quirks_mode_offsetHeight);
9670 START_TEST(dom)
9672 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
9673 pLCIDToLocaleName = (void*)GetProcAddress(hkernel32, "LCIDToLocaleName");
9674 pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
9676 CoInitialize(NULL);
9677 container_hwnd = CreateWindowA("static", NULL, WS_POPUP|WS_VISIBLE,
9678 CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, NULL, NULL);
9680 run_domtest(doc_str1, test_doc_elem);
9681 run_domtest(doc_str1, test_get_set_attr);
9682 run_domtest(range_test_str, test_txtrange);
9683 run_domtest(range_test2_str, test_txtrange2);
9684 if (winetest_interactive || ! is_ie_hardened()) {
9685 run_domtest(elem_test_str, test_elems);
9686 run_domtest(elem_test2_str, test_elems2);
9687 run_domtest(noscript_str, test_noscript);
9688 }else {
9689 skip("IE running in Enhanced Security Configuration\n");
9691 run_domtest(doc_blank, test_create_elems);
9692 run_domtest(doc_blank, test_defaults);
9693 run_domtest(doc_blank, test_null_write);
9694 run_domtest(emptydiv_str, test_create_stylesheet);
9695 run_domtest(indent_test_str, test_indent);
9696 run_domtest(cond_comment_str, test_cond_comment);
9697 run_domtest(frameset_str, test_frameset);
9698 run_domtest(emptydiv_str, test_docfrag);
9699 run_domtest(doc_blank, test_replacechild_elems);
9700 run_domtest(doctype_str, test_doctype);
9702 test_quirks_mode();
9704 DestroyWindow(container_hwnd);
9705 CoUninitialize();