4 * Copyright 2010-2012 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "msxml2did.h"
38 #include "wine/test.h"
40 #define EXPECT_HR(hr,hr_exp) \
41 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
43 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
44 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
46 ULONG rc = IUnknown_AddRef(obj);
47 IUnknown_Release(obj);
48 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
51 DEFINE_GUID(SID_SContainerDispatch, 0xb722be00, 0x4e68, 0x101b, 0xa2, 0xbc, 0x00, 0xaa, 0x00, 0x40, 0x47, 0x70);
52 DEFINE_GUID(SID_UnknownSID, 0x75dd09cb, 0x6c40, 0x11d5, 0x85, 0x43, 0x00, 0xc0, 0x4f, 0xa0, 0xfb, 0xa3);
54 #define DEFINE_EXPECT(func) \
55 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
57 #define SET_EXPECT(func) \
58 expect_ ## func = TRUE
60 #define CHECK_EXPECT2(func) \
62 ok(expect_ ##func, "unexpected call " #func "\n"); \
63 called_ ## func = TRUE; \
66 #define CHECK_CALLED(func) \
68 ok(called_ ## func, "expected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
73 DEFINE_EXPECT(site_qi_IServiceProvider);
74 DEFINE_EXPECT(site_qi_IXMLDOMDocument);
75 DEFINE_EXPECT(site_qi_IOleClientSite);
77 DEFINE_EXPECT(sp_queryservice_SID_SBindHost);
78 DEFINE_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
79 DEFINE_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
80 DEFINE_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
81 DEFINE_EXPECT(sp_queryservice_SID_secmgr_secmgr);
83 DEFINE_EXPECT(htmldoc2_get_all);
84 DEFINE_EXPECT(htmldoc2_get_url);
85 DEFINE_EXPECT(collection_get_length);
87 static const char *debugstr_guid(REFIID riid)
94 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
95 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
96 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
97 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
102 static int g_unexpectedcall, g_expectedcall;
104 static BSTR alloc_str_from_narrow(const char *str)
106 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
107 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
108 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len-1);
112 static BSTR alloced_bstrs[256];
113 static int alloced_bstrs_count;
115 static BSTR _bstr_(const char *str)
120 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
121 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
122 return alloced_bstrs[alloced_bstrs_count++];
125 static void free_bstrs(void)
128 for (i = 0; i < alloced_bstrs_count; i++)
129 SysFreeString(alloced_bstrs[i]);
130 alloced_bstrs_count = 0;
133 static BSTR a2bstr(const char *str)
141 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
142 ret = SysAllocStringLen(NULL, len);
143 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
150 IServiceProvider IServiceProvider_iface;
155 static HRESULT WINAPI site_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
159 if (IsEqualGUID(riid, &IID_IServiceProvider))
160 CHECK_EXPECT2(site_qi_IServiceProvider);
162 if (IsEqualGUID(riid, &IID_IXMLDOMDocument))
163 CHECK_EXPECT2(site_qi_IXMLDOMDocument);
165 if (IsEqualGUID(riid, &IID_IOleClientSite))
166 CHECK_EXPECT2(site_qi_IOleClientSite);
168 if (IsEqualGUID(riid, &IID_IUnknown))
170 else if (IsEqualGUID(riid, &IID_IServiceProvider))
171 *ppvObject = &testprov.IServiceProvider_iface;
173 if (*ppvObject) IUnknown_AddRef(iface);
175 return *ppvObject ? S_OK : E_NOINTERFACE;
178 static ULONG WINAPI site_AddRef(IUnknown *iface)
183 static ULONG WINAPI site_Release(IUnknown *iface)
188 static const IUnknownVtbl testsiteVtbl =
197 IUnknown IUnknown_iface;
200 static testsite_t testsite = { { &testsiteVtbl } };
202 /* test IHTMLElementCollection */
203 static HRESULT WINAPI htmlecoll_QueryInterface(IHTMLElementCollection *iface, REFIID riid, void **ppvObject)
205 ok(0, "unexpected call\n");
207 return E_NOINTERFACE;
210 static ULONG WINAPI htmlecoll_AddRef(IHTMLElementCollection *iface)
215 static ULONG WINAPI htmlecoll_Release(IHTMLElementCollection *iface)
220 static HRESULT WINAPI htmlecoll_GetTypeInfoCount(IHTMLElementCollection *iface, UINT *pctinfo)
222 ok(0, "unexpected call\n");
226 static HRESULT WINAPI htmlecoll_GetTypeInfo(IHTMLElementCollection *iface, UINT iTInfo,
227 LCID lcid, ITypeInfo **ppTInfo)
229 ok(0, "unexpected call\n");
233 static HRESULT WINAPI htmlecoll_GetIDsOfNames(IHTMLElementCollection *iface, REFIID riid,
234 LPOLESTR *rgszNames, UINT cNames,
235 LCID lcid, DISPID *rgDispId)
237 ok(0, "unexpected call\n");
241 static HRESULT WINAPI htmlecoll_Invoke(IHTMLElementCollection *iface, DISPID dispIdMember,
242 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
243 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
245 ok(0, "unexpected call\n");
249 static HRESULT WINAPI htmlecoll_toString(IHTMLElementCollection *iface, BSTR *String)
251 ok(0, "unexpected call\n");
255 static HRESULT WINAPI htmlecoll_put_length(IHTMLElementCollection *iface, LONG v)
257 ok(0, "unexpected call\n");
261 static HRESULT WINAPI htmlecoll_get_length(IHTMLElementCollection *iface, LONG *v)
263 CHECK_EXPECT2(collection_get_length);
267 static HRESULT WINAPI htmlecoll_get__newEnum(IHTMLElementCollection *iface, IUnknown **p)
269 ok(0, "unexpected call\n");
273 static HRESULT WINAPI htmlecoll_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp)
275 ok(0, "unexpected call\n");
279 static HRESULT WINAPI htmlecoll_tags(IHTMLElementCollection *iface, VARIANT tagName, IDispatch **pdisp)
281 ok(0, "unexpected call\n");
285 static const IHTMLElementCollectionVtbl TestHTMLECollectionVtbl = {
286 htmlecoll_QueryInterface,
289 htmlecoll_GetTypeInfoCount,
290 htmlecoll_GetTypeInfo,
291 htmlecoll_GetIDsOfNames,
295 htmlecoll_put_length,
296 htmlecoll_get_length,
297 htmlecoll_get__newEnum,
304 IHTMLElementCollection IHTMLElementCollection_iface;
307 static testhtmlecoll_t htmlecoll = { { &TestHTMLECollectionVtbl } };
309 /* test IHTMLDocument2 */
310 static HRESULT WINAPI htmldoc2_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
314 return E_NOINTERFACE;
317 static ULONG WINAPI htmldoc2_AddRef(IHTMLDocument2 *iface)
322 static ULONG WINAPI htmldoc2_Release(IHTMLDocument2 *iface)
327 static HRESULT WINAPI htmldoc2_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
329 ok(0, "unexpected call\n");
333 static HRESULT WINAPI htmldoc2_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
334 LCID lcid, ITypeInfo **ppTInfo)
336 ok(0, "unexpected call\n");
340 static HRESULT WINAPI htmldoc2_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
341 LPOLESTR *rgszNames, UINT cNames,
342 LCID lcid, DISPID *rgDispId)
344 ok(0, "unexpected call\n");
348 static HRESULT WINAPI htmldoc2_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
349 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
350 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
352 ok(0, "unexpected call\n");
356 static HRESULT WINAPI htmldoc2_get_Script(IHTMLDocument2 *iface, IDispatch **p)
358 ok(0, "unexpected call\n");
362 static HRESULT WINAPI htmldoc2_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
364 CHECK_EXPECT2(htmldoc2_get_all);
365 *p = &htmlecoll.IHTMLElementCollection_iface;
369 static HRESULT WINAPI htmldoc2_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
371 ok(0, "unexpected call\n");
375 static HRESULT WINAPI htmldoc2_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
377 ok(0, "unexpected call\n");
381 static HRESULT WINAPI htmldoc2_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
383 ok(0, "unexpected call\n");
387 static HRESULT WINAPI htmldoc2_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
389 ok(0, "unexpected call\n");
393 static HRESULT WINAPI htmldoc2_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
395 ok(0, "unexpected call\n");
399 static HRESULT WINAPI htmldoc2_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
401 ok(0, "unexpected call\n");
405 static HRESULT WINAPI htmldoc2_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
407 ok(0, "unexpected call\n");
411 static HRESULT WINAPI htmldoc2_put_title(IHTMLDocument2 *iface, BSTR v)
413 ok(0, "unexpected call\n");
417 static HRESULT WINAPI htmldoc2_get_title(IHTMLDocument2 *iface, BSTR *p)
419 ok(0, "unexpected call\n");
423 static HRESULT WINAPI htmldoc2_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
425 ok(0, "unexpected call\n");
429 static HRESULT WINAPI htmldoc2_put_designMode(IHTMLDocument2 *iface, BSTR v)
431 ok(0, "unexpected call\n");
435 static HRESULT WINAPI htmldoc2_get_designMode(IHTMLDocument2 *iface, BSTR *p)
437 ok(0, "unexpected call\n");
441 static HRESULT WINAPI htmldoc2_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
443 ok(0, "unexpected call\n");
447 static HRESULT WINAPI htmldoc2_get_readyState(IHTMLDocument2 *iface, BSTR *p)
449 ok(0, "unexpected call\n");
453 static HRESULT WINAPI htmldoc2_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
455 ok(0, "unexpected call\n");
459 static HRESULT WINAPI htmldoc2_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
461 ok(0, "unexpected call\n");
465 static HRESULT WINAPI htmldoc2_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
467 ok(0, "unexpected call\n");
471 static HRESULT WINAPI htmldoc2_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
473 ok(0, "unexpected call\n");
477 static HRESULT WINAPI htmldoc2_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
479 ok(0, "unexpected call\n");
483 static HRESULT WINAPI htmldoc2_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
485 ok(0, "unexpected call\n");
489 static HRESULT WINAPI htmldoc2_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
491 ok(0, "unexpected call\n");
495 static HRESULT WINAPI htmldoc2_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
497 ok(0, "unexpected call\n");
501 static HRESULT WINAPI htmldoc2_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
503 ok(0, "unexpected call\n");
507 static HRESULT WINAPI htmldoc2_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
509 ok(0, "unexpected call\n");
513 static HRESULT WINAPI htmldoc2_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
515 ok(0, "unexpected call\n");
519 static HRESULT WINAPI htmldoc2_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
521 ok(0, "unexpected call\n");
525 static HRESULT WINAPI htmldoc2_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
527 ok(0, "unexpected call\n");
531 static HRESULT WINAPI htmldoc2_get_referrer(IHTMLDocument2 *iface, BSTR *p)
533 ok(0, "unexpected call\n");
537 static HRESULT WINAPI htmldoc2_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
539 ok(0, "unexpected call\n");
543 static HRESULT WINAPI htmldoc2_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
545 ok(0, "unexpected call\n");
549 static HRESULT WINAPI htmldoc2_put_URL(IHTMLDocument2 *iface, BSTR v)
551 ok(0, "unexpected call\n");
555 static HRESULT WINAPI htmldoc2_get_URL(IHTMLDocument2 *iface, BSTR *p)
557 CHECK_EXPECT2(htmldoc2_get_url);
558 *p = a2bstr("http://test.winehq.org/");
562 static HRESULT WINAPI htmldoc2_put_domain(IHTMLDocument2 *iface, BSTR v)
564 ok(0, "unexpected call\n");
568 static HRESULT WINAPI htmldoc2_get_domain(IHTMLDocument2 *iface, BSTR *p)
570 ok(0, "unexpected call\n");
574 static HRESULT WINAPI htmldoc2_put_cookie(IHTMLDocument2 *iface, BSTR v)
576 ok(0, "unexpected call\n");
580 static HRESULT WINAPI htmldoc2_get_cookie(IHTMLDocument2 *iface, BSTR *p)
582 ok(0, "unexpected call\n");
586 static HRESULT WINAPI htmldoc2_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
588 ok(0, "unexpected call\n");
592 static HRESULT WINAPI htmldoc2_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
594 ok(0, "unexpected call\n");
598 static HRESULT WINAPI htmldoc2_put_charset(IHTMLDocument2 *iface, BSTR v)
600 ok(0, "unexpected call\n");
604 static HRESULT WINAPI htmldoc2_get_charset(IHTMLDocument2 *iface, BSTR *p)
606 ok(0, "unexpected call\n");
610 static HRESULT WINAPI htmldoc2_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
612 ok(0, "unexpected call\n");
616 static HRESULT WINAPI htmldoc2_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
618 ok(0, "unexpected call\n");
622 static HRESULT WINAPI htmldoc2_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
624 ok(0, "unexpected call\n");
628 static HRESULT WINAPI htmldoc2_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
630 ok(0, "unexpected call\n");
634 static HRESULT WINAPI htmldoc2_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
636 ok(0, "unexpected call\n");
640 static HRESULT WINAPI htmldoc2_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
642 ok(0, "unexpected call\n");
646 static HRESULT WINAPI htmldoc2_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
648 ok(0, "unexpected call\n");
652 static HRESULT WINAPI htmldoc2_get_security(IHTMLDocument2 *iface, BSTR *p)
654 ok(0, "unexpected call\n");
658 static HRESULT WINAPI htmldoc2_get_protocol(IHTMLDocument2 *iface, BSTR *p)
660 ok(0, "unexpected call\n");
664 static HRESULT WINAPI htmldoc2_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
666 ok(0, "unexpected call\n");
670 static HRESULT WINAPI htmldoc2_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
672 ok(0, "unexpected call\n");
676 static HRESULT WINAPI htmldoc2_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
678 ok(0, "unexpected call\n");
682 static HRESULT WINAPI htmldoc2_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
683 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
685 ok(0, "unexpected call\n");
689 static HRESULT WINAPI htmldoc2_close(IHTMLDocument2 *iface)
691 ok(0, "unexpected call\n");
695 static HRESULT WINAPI htmldoc2_clear(IHTMLDocument2 *iface)
697 ok(0, "unexpected call\n");
701 static HRESULT WINAPI htmldoc2_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
704 ok(0, "unexpected call\n");
708 static HRESULT WINAPI htmldoc2_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
711 ok(0, "unexpected call\n");
715 static HRESULT WINAPI htmldoc2_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
718 ok(0, "unexpected call\n");
722 static HRESULT WINAPI htmldoc2_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
725 ok(0, "unexpected call\n");
729 static HRESULT WINAPI htmldoc2_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
732 ok(0, "unexpected call\n");
736 static HRESULT WINAPI htmldoc2_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
739 ok(0, "unexpected call\n");
743 static HRESULT WINAPI htmldoc2_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
744 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
746 ok(0, "unexpected call\n");
750 static HRESULT WINAPI htmldoc2_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
753 ok(0, "unexpected call\n");
757 static HRESULT WINAPI htmldoc2_createElement(IHTMLDocument2 *iface, BSTR eTag,
758 IHTMLElement **newElem)
760 ok(0, "unexpected call\n");
764 static HRESULT WINAPI htmldoc2_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
766 ok(0, "unexpected call\n");
770 static HRESULT WINAPI htmldoc2_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
772 ok(0, "unexpected call\n");
776 static HRESULT WINAPI htmldoc2_put_onclick(IHTMLDocument2 *iface, VARIANT v)
778 ok(0, "unexpected call\n");
782 static HRESULT WINAPI htmldoc2_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
784 ok(0, "unexpected call\n");
788 static HRESULT WINAPI htmldoc2_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
790 ok(0, "unexpected call\n");
794 static HRESULT WINAPI htmldoc2_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
796 ok(0, "unexpected call\n");
800 static HRESULT WINAPI htmldoc2_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
802 ok(0, "unexpected call\n");
806 static HRESULT WINAPI htmldoc2_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
808 ok(0, "unexpected call\n");
812 static HRESULT WINAPI htmldoc2_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
814 ok(0, "unexpected call\n");
818 static HRESULT WINAPI htmldoc2_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
820 ok(0, "unexpected call\n");
824 static HRESULT WINAPI htmldoc2_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
826 ok(0, "unexpected call\n");
830 static HRESULT WINAPI htmldoc2_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
832 ok(0, "unexpected call\n");
836 static HRESULT WINAPI htmldoc2_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
838 ok(0, "unexpected call\n");
842 static HRESULT WINAPI htmldoc2_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
844 ok(0, "unexpected call\n");
848 static HRESULT WINAPI htmldoc2_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
850 ok(0, "unexpected call\n");
854 static HRESULT WINAPI htmldoc2_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
856 ok(0, "unexpected call\n");
860 static HRESULT WINAPI htmldoc2_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
862 ok(0, "unexpected call\n");
866 static HRESULT WINAPI htmldoc2_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
868 ok(0, "unexpected call\n");
872 static HRESULT WINAPI htmldoc2_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
874 ok(0, "unexpected call\n");
878 static HRESULT WINAPI htmldoc2_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
880 ok(0, "unexpected call\n");
884 static HRESULT WINAPI htmldoc2_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
886 ok(0, "unexpected call\n");
890 static HRESULT WINAPI htmldoc2_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
892 ok(0, "unexpected call\n");
896 static HRESULT WINAPI htmldoc2_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
898 ok(0, "unexpected call\n");
902 static HRESULT WINAPI htmldoc2_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
904 ok(0, "unexpected call\n");
908 static HRESULT WINAPI htmldoc2_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
910 ok(0, "unexpected call\n");
914 static HRESULT WINAPI htmldoc2_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
916 ok(0, "unexpected call\n");
920 static HRESULT WINAPI htmldoc2_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
922 ok(0, "unexpected call\n");
926 static HRESULT WINAPI htmldoc2_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
928 ok(0, "unexpected call\n");
932 static HRESULT WINAPI htmldoc2_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
934 ok(0, "unexpected call\n");
938 static HRESULT WINAPI htmldoc2_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
940 ok(0, "unexpected call\n");
944 static HRESULT WINAPI htmldoc2_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
946 ok(0, "unexpected call\n");
950 static HRESULT WINAPI htmldoc2_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
952 ok(0, "unexpected call\n");
956 static HRESULT WINAPI htmldoc2_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
958 ok(0, "unexpected call\n");
962 static HRESULT WINAPI htmldoc2_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
964 ok(0, "unexpected call\n");
968 static HRESULT WINAPI htmldoc2_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
969 IHTMLElement **elementHit)
971 ok(0, "unexpected call\n");
975 static HRESULT WINAPI htmldoc2_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
977 ok(0, "unexpected call\n");
981 static HRESULT WINAPI htmldoc2_get_styleSheets(IHTMLDocument2 *iface,
982 IHTMLStyleSheetsCollection **p)
984 ok(0, "unexpected call\n");
988 static HRESULT WINAPI htmldoc2_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
990 ok(0, "unexpected call\n");
994 static HRESULT WINAPI htmldoc2_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
996 ok(0, "unexpected call\n");
1000 static HRESULT WINAPI htmldoc2_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1002 ok(0, "unexpected call\n");
1006 static HRESULT WINAPI htmldoc2_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1008 ok(0, "unexpected call\n");
1012 static HRESULT WINAPI htmldoc2_toString(IHTMLDocument2 *iface, BSTR *String)
1014 ok(0, "unexpected call\n");
1018 static HRESULT WINAPI htmldoc2_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1019 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1021 ok(0, "unexpected call\n");
1025 static const IHTMLDocument2Vtbl TestHTMLDocumentVtbl = {
1026 htmldoc2_QueryInterface,
1029 htmldoc2_GetTypeInfoCount,
1030 htmldoc2_GetTypeInfo,
1031 htmldoc2_GetIDsOfNames,
1033 htmldoc2_get_Script,
1036 htmldoc2_get_activeElement,
1037 htmldoc2_get_images,
1038 htmldoc2_get_applets,
1041 htmldoc2_get_anchors,
1044 htmldoc2_get_scripts,
1045 htmldoc2_put_designMode,
1046 htmldoc2_get_designMode,
1047 htmldoc2_get_selection,
1048 htmldoc2_get_readyState,
1049 htmldoc2_get_frames,
1050 htmldoc2_get_embeds,
1051 htmldoc2_get_plugins,
1052 htmldoc2_put_alinkColor,
1053 htmldoc2_get_alinkColor,
1054 htmldoc2_put_bgColor,
1055 htmldoc2_get_bgColor,
1056 htmldoc2_put_fgColor,
1057 htmldoc2_get_fgColor,
1058 htmldoc2_put_linkColor,
1059 htmldoc2_get_linkColor,
1060 htmldoc2_put_vlinkColor,
1061 htmldoc2_get_vlinkColor,
1062 htmldoc2_get_referrer,
1063 htmldoc2_get_location,
1064 htmldoc2_get_lastModified,
1067 htmldoc2_put_domain,
1068 htmldoc2_get_domain,
1069 htmldoc2_put_cookie,
1070 htmldoc2_get_cookie,
1071 htmldoc2_put_expando,
1072 htmldoc2_get_expando,
1073 htmldoc2_put_charset,
1074 htmldoc2_get_charset,
1075 htmldoc2_put_defaultCharset,
1076 htmldoc2_get_defaultCharset,
1077 htmldoc2_get_mimeType,
1078 htmldoc2_get_fileSize,
1079 htmldoc2_get_fileCreatedDate,
1080 htmldoc2_get_fileModifiedDate,
1081 htmldoc2_get_fileUpdatedDate,
1082 htmldoc2_get_security,
1083 htmldoc2_get_protocol,
1084 htmldoc2_get_nameProp,
1090 htmldoc2_queryCommandSupported,
1091 htmldoc2_queryCommandEnabled,
1092 htmldoc2_queryCommandState,
1093 htmldoc2_queryCommandIndeterm,
1094 htmldoc2_queryCommandText,
1095 htmldoc2_queryCommandValue,
1096 htmldoc2_execCommand,
1097 htmldoc2_execCommandShowHelp,
1098 htmldoc2_createElement,
1099 htmldoc2_put_onhelp,
1100 htmldoc2_get_onhelp,
1101 htmldoc2_put_onclick,
1102 htmldoc2_get_onclick,
1103 htmldoc2_put_ondblclick,
1104 htmldoc2_get_ondblclick,
1105 htmldoc2_put_onkeyup,
1106 htmldoc2_get_onkeyup,
1107 htmldoc2_put_onkeydown,
1108 htmldoc2_get_onkeydown,
1109 htmldoc2_put_onkeypress,
1110 htmldoc2_get_onkeypress,
1111 htmldoc2_put_onmouseup,
1112 htmldoc2_get_onmouseup,
1113 htmldoc2_put_onmousedown,
1114 htmldoc2_get_onmousedown,
1115 htmldoc2_put_onmousemove,
1116 htmldoc2_get_onmousemove,
1117 htmldoc2_put_onmouseout,
1118 htmldoc2_get_onmouseout,
1119 htmldoc2_put_onmouseover,
1120 htmldoc2_get_onmouseover,
1121 htmldoc2_put_onreadystatechange,
1122 htmldoc2_get_onreadystatechange,
1123 htmldoc2_put_onafterupdate,
1124 htmldoc2_get_onafterupdate,
1125 htmldoc2_put_onrowexit,
1126 htmldoc2_get_onrowexit,
1127 htmldoc2_put_onrowenter,
1128 htmldoc2_get_onrowenter,
1129 htmldoc2_put_ondragstart,
1130 htmldoc2_get_ondragstart,
1131 htmldoc2_put_onselectstart,
1132 htmldoc2_get_onselectstart,
1133 htmldoc2_elementFromPoint,
1134 htmldoc2_get_parentWindow,
1135 htmldoc2_get_styleSheets,
1136 htmldoc2_put_onbeforeupdate,
1137 htmldoc2_get_onbeforeupdate,
1138 htmldoc2_put_onerrorupdate,
1139 htmldoc2_get_onerrorupdate,
1141 htmldoc2_createStyleSheet
1146 IHTMLDocument2 IHTMLDocument2_iface;
1149 static testhtmldoc2_t htmldoc2 = { { &TestHTMLDocumentVtbl } };
1151 static HRESULT WINAPI sp_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppvObject)
1155 if (IsEqualGUID(riid, &IID_IUnknown) ||
1156 IsEqualGUID(riid, &IID_IServiceProvider))
1159 IServiceProvider_AddRef(iface);
1163 ok(0, "unexpected query interface: %s\n", debugstr_guid(riid));
1165 return E_NOINTERFACE;
1168 static ULONG WINAPI sp_AddRef(IServiceProvider *iface)
1173 static ULONG WINAPI sp_Release(IServiceProvider *iface)
1178 static HRESULT WINAPI sp_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
1182 if (IsEqualGUID(service, &SID_SBindHost) &&
1183 IsEqualGUID(riid, &IID_IBindHost))
1185 CHECK_EXPECT2(sp_queryservice_SID_SBindHost);
1187 else if (IsEqualGUID(service, &SID_SContainerDispatch) &&
1188 IsEqualGUID(riid, &IID_IHTMLDocument2))
1190 CHECK_EXPECT2(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1192 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1193 IsEqualGUID(riid, &IID_IHTMLDocument2))
1195 CHECK_EXPECT2(sp_queryservice_SID_secmgr_htmldoc2);
1196 *obj = &htmldoc2.IHTMLDocument2_iface;
1199 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1200 IsEqualGUID(riid, &IID_IXMLDOMDocument))
1202 CHECK_EXPECT2(sp_queryservice_SID_secmgr_xmldomdoc);
1204 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1205 IsEqualGUID(riid, &IID_IInternetHostSecurityManager))
1207 CHECK_EXPECT2(sp_queryservice_SID_secmgr_secmgr);
1209 else if (IsEqualGUID(service, &SID_UnknownSID) &&
1210 IsEqualGUID(riid, &IID_IStream))
1212 /* FIXME: unidentified service id */
1215 ok(0, "unexpected request: sid %s, riid %s\n", debugstr_guid(service), debugstr_guid(riid));
1220 static const IServiceProviderVtbl testprovVtbl =
1228 testprov_t testprov = { { &testprovVtbl } };
1232 IDispatch IDispatch_iface;
1236 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
1238 return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
1241 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
1245 if ( IsEqualGUID( riid, &IID_IDispatch) ||
1246 IsEqualGUID( riid, &IID_IUnknown) )
1251 return E_NOINTERFACE;
1253 IDispatch_AddRef( iface );
1258 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
1260 dispevent *This = impl_from_IDispatch( iface );
1261 return InterlockedIncrement( &This->ref );
1264 static ULONG WINAPI dispevent_Release(IDispatch *iface)
1266 dispevent *This = impl_from_IDispatch( iface );
1267 ULONG ref = InterlockedDecrement( &This->ref );
1270 HeapFree(GetProcessHeap(), 0, This);
1275 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1282 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
1283 LCID lcid, ITypeInfo **ppTInfo)
1289 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
1290 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1296 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
1297 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
1298 EXCEPINFO *excepInfo, UINT *argErr)
1300 ok(member == 0, "expected 0 member, got %d\n", member);
1301 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
1302 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
1304 ok(params->cArgs == 0, "got %d\n", params->cArgs);
1305 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
1306 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
1307 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
1309 ok(result == NULL, "got %p\n", result);
1310 ok(excepInfo == NULL, "got %p\n", excepInfo);
1311 ok(argErr == NULL, "got %p\n", argErr);
1317 static const IDispatchVtbl dispeventVtbl =
1319 dispevent_QueryInterface,
1322 dispevent_GetTypeInfoCount,
1323 dispevent_GetTypeInfo,
1324 dispevent_GetIDsOfNames,
1328 static IDispatch* create_dispevent(void)
1330 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
1332 event->IDispatch_iface.lpVtbl = &dispeventVtbl;
1335 return (IDispatch*)&event->IDispatch_iface;
1338 static IXMLHttpRequest *create_xhr(void)
1340 IXMLHttpRequest *ret;
1343 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
1344 &IID_IXMLHttpRequest, (void**)&ret);
1346 return SUCCEEDED(hr) ? ret : NULL;
1349 static void set_safety_opt(IUnknown *unk, DWORD mask, DWORD opts)
1351 IObjectSafety *obj_safety;
1354 hr = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&obj_safety);
1355 ok(hr == S_OK, "Could not get IObjectSafety iface: %08x\n", hr);
1357 hr = IObjectSafety_SetInterfaceSafetyOptions(obj_safety, &IID_IDispatch, mask, mask&opts);
1358 ok(hr == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hr);
1360 IObjectSafety_Release(obj_safety);
1363 static void set_xhr_site(IXMLHttpRequest *xhr)
1365 IObjectWithSite *obj_site;
1368 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
1369 ok(hr == S_OK, "Could not get IObjectWithSite iface: %08x\n", hr);
1371 SET_EXPECT(site_qi_IServiceProvider);
1372 SET_EXPECT(sp_queryservice_SID_SBindHost);
1373 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1374 SET_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
1375 SET_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
1376 SET_EXPECT(sp_queryservice_SID_secmgr_secmgr);
1378 /* calls to IHTMLDocument2 */
1379 SET_EXPECT(htmldoc2_get_all);
1380 SET_EXPECT(collection_get_length);
1381 SET_EXPECT(htmldoc2_get_url);
1383 SET_EXPECT(site_qi_IXMLDOMDocument);
1384 SET_EXPECT(site_qi_IOleClientSite);
1386 hr = IObjectWithSite_SetSite(obj_site, &testsite.IUnknown_iface);
1387 EXPECT_HR(hr, S_OK);
1389 CHECK_CALLED(site_qi_IServiceProvider);
1391 CHECK_CALLED(sp_queryservice_SID_SBindHost);
1392 CHECK_CALLED(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1394 CHECK_CALLED(sp_queryservice_SID_secmgr_htmldoc2);
1395 CHECK_CALLED(sp_queryservice_SID_secmgr_xmldomdoc);
1396 /* this one isn't very reliable
1397 CHECK_CALLED(sp_queryservice_SID_secmgr_secmgr); */
1399 CHECK_CALLED(htmldoc2_get_all);
1400 CHECK_CALLED(collection_get_length);
1401 CHECK_CALLED(htmldoc2_get_url);
1403 CHECK_CALLED(site_qi_IXMLDOMDocument);
1404 CHECK_CALLED(site_qi_IOleClientSite);
1407 IObjectWithSite_Release(obj_site);
1410 #define test_open(a,b,c,d) _test_open(__LINE__,a,b,c,d)
1411 static void _test_open(unsigned line, IXMLHttpRequest *xhr, const char *method, const char *url, HRESULT exhres)
1413 VARIANT empty, vfalse;
1416 V_VT(&empty) = VT_EMPTY;
1417 V_VT(&vfalse) = VT_BOOL;
1418 V_BOOL(&vfalse) = VARIANT_FALSE;
1420 hr = IXMLHttpRequest_open(xhr, _bstr_(method), _bstr_(url), vfalse, empty, empty);
1421 ok_(__FILE__,line)(hr == exhres, "open(%s %s) failed: %08x, expected %08x\n", method, url, hr, exhres);
1424 static void test_XMLHTTP(void)
1426 static const char bodyA[] = "mode=Test";
1427 static const char urlA[] = "http://crossover.codeweavers.com/posttest.php";
1428 static const char xmltestA[] = "http://crossover.codeweavers.com/xmltest.xml";
1429 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1430 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
1432 IXMLHttpRequest *xhr;
1433 IObjectWithSite *obj_site, *obj_site2;
1434 BSTR bstrResponse, str, str1;
1435 VARIANT varbody, varbody_ref;
1437 LONG state, status, bound;
1445 VariantInit(&dummy);
1446 V_VT(&dummy) = VT_ERROR;
1447 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1449 hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL);
1450 EXPECT_HR(hr, S_OK);
1452 hr = IXMLHttpRequest_abort(xhr);
1453 EXPECT_HR(hr, S_OK);
1455 V_VT(&varbody) = VT_I2;
1457 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
1458 EXPECT_HR(hr, E_PENDING);
1459 ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
1460 ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
1462 V_VT(&varbody) = VT_I2;
1464 hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
1465 EXPECT_HR(hr, E_PENDING);
1466 ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
1467 ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
1469 /* send before open */
1470 hr = IXMLHttpRequest_send(xhr, dummy);
1471 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1473 /* initial status code */
1474 hr = IXMLHttpRequest_get_status(xhr, NULL);
1475 EXPECT_HR(hr, E_INVALIDARG);
1477 status = 0xdeadbeef;
1478 hr = IXMLHttpRequest_get_status(xhr, &status);
1479 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1480 ok(status == 0xdeadbeef, "got %d\n", status);
1482 hr = IXMLHttpRequest_get_statusText(xhr, &str);
1483 ok(hr == E_FAIL, "got 0x%08x\n", hr);
1485 /* invalid parameters */
1486 test_open(xhr, NULL, NULL, E_INVALIDARG);
1487 test_open(xhr, "POST", NULL, E_INVALIDARG);
1488 test_open(xhr, NULL, urlA, E_INVALIDARG);
1490 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL);
1491 EXPECT_HR(hr, E_INVALIDARG);
1493 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL);
1494 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1496 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
1497 EXPECT_HR(hr, E_INVALIDARG);
1499 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
1500 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1502 hr = IXMLHttpRequest_get_readyState(xhr, NULL);
1503 EXPECT_HR(hr, E_INVALIDARG);
1506 hr = IXMLHttpRequest_get_readyState(xhr, &state);
1507 EXPECT_HR(hr, S_OK);
1508 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
1510 event = create_dispevent();
1512 EXPECT_REF(event, 1);
1513 hr = IXMLHttpRequest_put_onreadystatechange(xhr, event);
1514 EXPECT_HR(hr, S_OK);
1515 EXPECT_REF(event, 2);
1517 g_unexpectedcall = g_expectedcall = 0;
1519 test_open(xhr, "POST", urlA, S_OK);
1521 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
1522 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
1524 /* status code after ::open() */
1525 status = 0xdeadbeef;
1526 hr = IXMLHttpRequest_get_status(xhr, &status);
1527 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1528 ok(status == 0xdeadbeef, "got %d\n", status);
1531 hr = IXMLHttpRequest_get_readyState(xhr, &state);
1532 EXPECT_HR(hr, S_OK);
1533 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
1535 hr = IXMLHttpRequest_abort(xhr);
1536 EXPECT_HR(hr, S_OK);
1539 hr = IXMLHttpRequest_get_readyState(xhr, &state);
1540 EXPECT_HR(hr, S_OK);
1541 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
1542 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
1544 test_open(xhr, "POST", urlA, S_OK);
1546 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
1547 EXPECT_HR(hr, S_OK);
1549 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
1550 EXPECT_HR(hr, E_INVALIDARG);
1552 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1"));
1553 EXPECT_HR(hr, E_INVALIDARG);
1555 V_VT(&varbody) = VT_BSTR;
1556 V_BSTR(&varbody) = _bstr_(bodyA);
1558 hr = IXMLHttpRequest_send(xhr, varbody);
1559 if (hr == INET_E_RESOURCE_NOT_FOUND)
1561 skip("No connection could be made with crossover.codeweavers.com\n");
1562 IXMLHttpRequest_Release(xhr);
1565 EXPECT_HR(hr, S_OK);
1567 /* response headers */
1568 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, NULL);
1569 EXPECT_HR(hr, E_INVALIDARG);
1570 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str);
1571 EXPECT_HR(hr, S_OK);
1572 /* status line is stripped already */
1573 ok(memcmp(str, _bstr_("HTTP"), 4*sizeof(WCHAR)), "got response headers %s\n", wine_dbgstr_w(str));
1574 ok(*str, "got empty headers\n");
1575 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str1);
1576 EXPECT_HR(hr, S_OK);
1577 ok(str1 != str, "got %p\n", str1);
1578 SysFreeString(str1);
1581 hr = IXMLHttpRequest_getResponseHeader(xhr, NULL, NULL);
1582 EXPECT_HR(hr, E_INVALIDARG);
1583 hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), NULL);
1584 EXPECT_HR(hr, E_INVALIDARG);
1585 hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), &str);
1586 EXPECT_HR(hr, S_OK);
1587 ok(*str != ' ', "got leading space in header %s\n", wine_dbgstr_w(str));
1590 /* status code after ::send() */
1591 status = 0xdeadbeef;
1592 hr = IXMLHttpRequest_get_status(xhr, &status);
1593 EXPECT_HR(hr, S_OK);
1594 ok(status == 200, "got %d\n", status);
1596 hr = IXMLHttpRequest_get_statusText(xhr, NULL);
1597 EXPECT_HR(hr, E_INVALIDARG);
1599 hr = IXMLHttpRequest_get_statusText(xhr, &str);
1600 EXPECT_HR(hr, S_OK);
1601 ok(!lstrcmpW(str, _bstr_("OK")), "got status %s\n", wine_dbgstr_w(str));
1604 /* another ::send() after completed request */
1605 V_VT(&varbody) = VT_BSTR;
1606 V_BSTR(&varbody) = _bstr_(bodyA);
1608 hr = IXMLHttpRequest_send(xhr, varbody);
1609 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1611 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
1612 EXPECT_HR(hr, S_OK);
1613 /* the server currently returns "FAILED" because the Content-Type header is
1614 * not what the server expects */
1617 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
1618 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
1619 SysFreeString(bstrResponse);
1622 /* POST: VT_VARIANT|VT_BYREF body */
1623 test_open(xhr, "POST", urlA, S_OK);
1625 V_VT(&varbody_ref) = VT_VARIANT|VT_BYREF;
1626 V_VARIANTREF(&varbody_ref) = &varbody;
1627 hr = IXMLHttpRequest_send(xhr, varbody_ref);
1628 EXPECT_HR(hr, S_OK);
1631 test_open(xhr, "GET", xmltestA, S_OK);
1633 V_VT(&varbody) = VT_EMPTY;
1635 hr = IXMLHttpRequest_send(xhr, varbody);
1636 if (hr == INET_E_RESOURCE_NOT_FOUND)
1638 skip("No connection could be made with crossover.codeweavers.com\n");
1639 IXMLHttpRequest_Release(xhr);
1642 EXPECT_HR(hr, S_OK);
1644 hr = IXMLHttpRequest_get_responseText(xhr, NULL);
1645 EXPECT_HR(hr, E_INVALIDARG);
1647 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
1648 EXPECT_HR(hr, S_OK);
1649 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
1650 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
1651 SysFreeString(bstrResponse);
1653 hr = IXMLHttpRequest_get_responseBody(xhr, NULL);
1654 EXPECT_HR(hr, E_INVALIDARG);
1656 V_VT(&varbody) = VT_EMPTY;
1657 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
1658 EXPECT_HR(hr, S_OK);
1659 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
1660 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
1663 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
1664 EXPECT_HR(hr, S_OK);
1665 ok(bound == 0, "got %d, expected zero bound\n", bound);
1667 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
1668 EXPECT_HR(hr, S_OK);
1669 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n");
1670 SafeArrayUnaccessData(V_ARRAY(&varbody));
1672 VariantClear(&varbody);
1674 /* get_responseStream */
1675 hr = IXMLHttpRequest_get_responseStream(xhr, NULL);
1676 EXPECT_HR(hr, E_INVALIDARG);
1678 V_VT(&varbody) = VT_EMPTY;
1679 hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
1680 ok(V_VT(&varbody) == VT_UNKNOWN, "got type %d\n", V_VT(&varbody));
1681 EXPECT_HR(hr, S_OK);
1682 EXPECT_REF(V_UNKNOWN(&varbody), 1);
1685 hr = GetHGlobalFromStream((IStream*)V_UNKNOWN(&varbody), &g);
1686 EXPECT_HR(hr, S_OK);
1687 ok(g != NULL, "got %p\n", g);
1689 IDispatch_Release(event);
1691 /* interaction with object site */
1693 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
1694 EXPECT_HR(hr, S_OK);
1697 EXPECT_REF(obj_site, 1);
1700 hr = IObjectWithSite_SetSite(obj_site, NULL);
1701 ok(hr == S_OK, "got 0x%08x\n", hr);
1703 IObjectWithSite_AddRef(obj_site);
1705 EXPECT_REF(obj_site, 2);
1708 IObjectWithSite_Release(obj_site);
1710 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2);
1711 EXPECT_HR(hr, S_OK);
1714 EXPECT_REF(obj_site, 1);
1715 EXPECT_REF(obj_site2, 1);
1716 ok(obj_site != obj_site2, "expected new instance\n");
1718 IObjectWithSite_Release(obj_site);
1722 /* try to set site another time */
1724 /* to be removed once IObjectWithSite is properly separated */
1725 SET_EXPECT(site_qi_IServiceProvider);
1726 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1728 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
1729 EXPECT_HR(hr, S_OK);
1731 todo_wine EXPECT_REF(xhr, 1);
1732 IXMLHttpRequest_Release(xhr);
1734 /* still works after request is released */
1736 /* to be removed once IObjectWithSite is properly separated */
1737 SET_EXPECT(site_qi_IServiceProvider);
1738 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1740 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
1741 EXPECT_HR(hr, S_OK);
1742 IObjectWithSite_Release(obj_site2);
1747 static void test_safe_httpreq(void)
1749 IXMLHttpRequest *xhr;
1753 set_safety_opt((IUnknown*)xhr, INTERFACESAFE_FOR_UNTRUSTED_DATA, -1);
1756 /* different scheme */
1757 test_open(xhr, "GET", "https://test.winehq.org/tests/hello.html", E_ACCESSDENIED);
1759 /* different host */
1760 test_open(xhr, "GET", "http://tests.winehq.org/tests/hello.html", E_ACCESSDENIED);
1761 test_open(xhr, "GET", "http://www.test.winehq.org/tests/hello.html", E_ACCESSDENIED);
1763 IXMLHttpRequest_Release(xhr);
1768 IXMLHttpRequest *xhr;
1772 if((xhr = create_xhr())) {
1773 IXMLHttpRequest_Release(xhr);
1776 test_safe_httpreq();
1778 win_skip("IXMLHTTPRequest is not available\n");