1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2015 Zhenbo Li
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19ba54c564SAmine Khaldi #include "precomp.h"
20c2c66affSColin Finck
a2bstr(const char * str)21c2c66affSColin Finck static BSTR a2bstr(const char *str)
22c2c66affSColin Finck {
23c2c66affSColin Finck BSTR ret;
24c2c66affSColin Finck int len;
25c2c66affSColin Finck
26c2c66affSColin Finck len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
27c2c66affSColin Finck ret = SysAllocStringLen(NULL, len);
28c2c66affSColin Finck MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
29c2c66affSColin Finck
30c2c66affSColin Finck return ret;
31c2c66affSColin Finck }
32c2c66affSColin Finck
strcmp_wa(LPCWSTR strw,const char * stra)33c2c66affSColin Finck static int strcmp_wa(LPCWSTR strw, const char *stra)
34c2c66affSColin Finck {
35c2c66affSColin Finck CHAR buf[512];
36c2c66affSColin Finck WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
37c2c66affSColin Finck return lstrcmpA(stra, buf);
38c2c66affSColin Finck }
39c2c66affSColin Finck
40c2c66affSColin Finck #define DEFINE_EXPECT(func) \
41c2c66affSColin Finck static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
42c2c66affSColin Finck
43c2c66affSColin Finck #define SET_EXPECT(func) \
44c2c66affSColin Finck do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
45c2c66affSColin Finck
46c2c66affSColin Finck #define CHECK_EXPECT2(func) \
47c2c66affSColin Finck do { \
48c2c66affSColin Finck trace(#func "\n"); \
49c2c66affSColin Finck ok(expect_ ##func, "unexpected call " #func "\n"); \
50c2c66affSColin Finck called_ ## func = TRUE; \
51c2c66affSColin Finck }while(0)
52c2c66affSColin Finck
53c2c66affSColin Finck #define CHECK_EXPECT(func) \
54c2c66affSColin Finck do { \
55c2c66affSColin Finck CHECK_EXPECT2(func); \
56c2c66affSColin Finck expect_ ## func = FALSE; \
57c2c66affSColin Finck }while(0)
58c2c66affSColin Finck
59c2c66affSColin Finck #define CHECK_CALLED(func) \
60c2c66affSColin Finck do { \
61c2c66affSColin Finck ok(called_ ## func, "expected " #func "\n"); \
62c2c66affSColin Finck expect_ ## func = called_ ## func = FALSE; \
63c2c66affSColin Finck }while(0)
64c2c66affSColin Finck
65c2c66affSColin Finck static IHTMLXMLHttpRequest *xhr = NULL;
66c2c66affSColin Finck static BSTR content_type = NULL;
67c2c66affSColin Finck static int loading_cnt = 0;
68c2c66affSColin Finck static int readystatechange_cnt = 0;
69c2c66affSColin Finck
70c2c66affSColin Finck DEFINE_EXPECT(xmlhttprequest_onreadystatechange_opened);
71c2c66affSColin Finck DEFINE_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
72c2c66affSColin Finck DEFINE_EXPECT(xmlhttprequest_onreadystatechange_loading);
73c2c66affSColin Finck DEFINE_EXPECT(xmlhttprequest_onreadystatechange_done);
74c2c66affSColin Finck
75c2c66affSColin Finck #define test_disp(u,id) _test_disp(__LINE__,u,id)
_test_disp(unsigned line,IUnknown * unk,const IID * diid)76c2c66affSColin Finck static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
77c2c66affSColin Finck {
78c2c66affSColin Finck IDispatchEx *dispex;
79c2c66affSColin Finck ITypeInfo *typeinfo;
80c2c66affSColin Finck UINT ticnt;
81c2c66affSColin Finck HRESULT hres;
82c2c66affSColin Finck
83c2c66affSColin Finck hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
84c2c66affSColin Finck ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
85c2c66affSColin Finck if(FAILED(hres))
86c2c66affSColin Finck return;
87c2c66affSColin Finck
88c2c66affSColin Finck ticnt = 0xdeadbeef;
89c2c66affSColin Finck hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
90c2c66affSColin Finck ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
91c2c66affSColin Finck ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
92c2c66affSColin Finck
93c2c66affSColin Finck hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
94c2c66affSColin Finck ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
95c2c66affSColin Finck
96c2c66affSColin Finck if(SUCCEEDED(hres)) {
97c2c66affSColin Finck TYPEATTR *type_attr;
98c2c66affSColin Finck
99c2c66affSColin Finck hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
100c2c66affSColin Finck ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
101c2c66affSColin Finck ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
102c2c66affSColin Finck wine_dbgstr_guid(&type_attr->guid));
103c2c66affSColin Finck
104c2c66affSColin Finck ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
105c2c66affSColin Finck ITypeInfo_Release(typeinfo);
106c2c66affSColin Finck }
107c2c66affSColin Finck
108c2c66affSColin Finck IDispatchEx_Release(dispex);
109c2c66affSColin Finck }
110c2c66affSColin Finck
111c2c66affSColin Finck #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
_test_event_args(unsigned line,const IID * dispiid,DISPID id,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)112c2c66affSColin Finck static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
113c2c66affSColin Finck VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
114c2c66affSColin Finck {
115c2c66affSColin Finck ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
116c2c66affSColin Finck ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
117c2c66affSColin Finck ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
118c2c66affSColin Finck ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
119c2c66affSColin Finck ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
120c2c66affSColin Finck ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
121c2c66affSColin Finck pdp->rgdispidNamedArgs[0]);
122c2c66affSColin Finck ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
123c2c66affSColin Finck ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
124c2c66affSColin Finck ok_(__FILE__,line) (pei != NULL, "pei == NULL");
125c2c66affSColin Finck ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
126c2c66affSColin Finck
127c2c66affSColin Finck if(dispiid)
128c2c66affSColin Finck _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
129c2c66affSColin Finck }
130c2c66affSColin Finck
DispatchEx_QueryInterface(IDispatchEx * iface,REFIID riid,void ** ppv)131c2c66affSColin Finck static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
132c2c66affSColin Finck {
133c2c66affSColin Finck *ppv = NULL;
134c2c66affSColin Finck
135c2c66affSColin Finck if(IsEqualGUID(riid, &IID_IUnknown)
136c2c66affSColin Finck || IsEqualGUID(riid, &IID_IDispatch)
137c2c66affSColin Finck || IsEqualGUID(riid, &IID_IDispatchEx))
138c2c66affSColin Finck *ppv = iface;
139c2c66affSColin Finck else {
140c2c66affSColin Finck ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
141c2c66affSColin Finck return E_NOINTERFACE;
142c2c66affSColin Finck }
143c2c66affSColin Finck
144c2c66affSColin Finck return S_OK;
145c2c66affSColin Finck }
146c2c66affSColin Finck
DispatchEx_AddRef(IDispatchEx * iface)147c2c66affSColin Finck static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
148c2c66affSColin Finck {
149c2c66affSColin Finck return 2;
150c2c66affSColin Finck }
151c2c66affSColin Finck
DispatchEx_Release(IDispatchEx * iface)152c2c66affSColin Finck static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
153c2c66affSColin Finck {
154c2c66affSColin Finck return 1;
155c2c66affSColin Finck }
156c2c66affSColin Finck
DispatchEx_GetTypeInfoCount(IDispatchEx * iface,UINT * pctinfo)157c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
158c2c66affSColin Finck {
159c2c66affSColin Finck ok(0, "unexpected call\n");
160c2c66affSColin Finck return E_NOTIMPL;
161c2c66affSColin Finck }
162c2c66affSColin Finck
DispatchEx_GetTypeInfo(IDispatchEx * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)163c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
164c2c66affSColin Finck LCID lcid, ITypeInfo **ppTInfo)
165c2c66affSColin Finck {
166c2c66affSColin Finck ok(0, "unexpected call\n");
167c2c66affSColin Finck return E_NOTIMPL;
168c2c66affSColin Finck }
169c2c66affSColin Finck
DispatchEx_GetIDsOfNames(IDispatchEx * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)170c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
171c2c66affSColin Finck LPOLESTR *rgszNames, UINT cNames,
172c2c66affSColin Finck LCID lcid, DISPID *rgDispId)
173c2c66affSColin Finck {
174c2c66affSColin Finck ok(0, "unexpected call\n");
175c2c66affSColin Finck return E_NOTIMPL;
176c2c66affSColin Finck }
177c2c66affSColin Finck
DispatchEx_Invoke(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)178c2c66affSColin Finck static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
179c2c66affSColin Finck REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
180c2c66affSColin Finck VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
181c2c66affSColin Finck {
182c2c66affSColin Finck ok(0, "unexpected call\n");
183c2c66affSColin Finck return E_NOTIMPL;
184c2c66affSColin Finck }
185c2c66affSColin Finck
DispatchEx_GetDispID(IDispatchEx * iface,BSTR bstrName,DWORD grfdex,DISPID * pid)186c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
187c2c66affSColin Finck {
188c2c66affSColin Finck ok(0, "unexpected call\n");
189c2c66affSColin Finck return E_NOTIMPL;
190c2c66affSColin Finck }
191c2c66affSColin Finck
DispatchEx_DeleteMemberByName(IDispatchEx * iface,BSTR bstrName,DWORD grfdex)192c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
193c2c66affSColin Finck {
194c2c66affSColin Finck ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
195c2c66affSColin Finck return E_NOTIMPL;
196c2c66affSColin Finck }
197c2c66affSColin Finck
DispatchEx_DeleteMemberByDispID(IDispatchEx * iface,DISPID id)198c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
199c2c66affSColin Finck {
200c2c66affSColin Finck ok(0, "unexpected call\n");
201c2c66affSColin Finck return E_NOTIMPL;
202c2c66affSColin Finck }
203c2c66affSColin Finck
DispatchEx_GetMemberProperties(IDispatchEx * iface,DISPID id,DWORD grfdexFetch,DWORD * pgrfdex)204c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
205c2c66affSColin Finck {
206c2c66affSColin Finck ok(0, "unexpected call\n");
207c2c66affSColin Finck return E_NOTIMPL;
208c2c66affSColin Finck }
209c2c66affSColin Finck
DispatchEx_GetMemberName(IDispatchEx * iface,DISPID id,BSTR * pbstrName)210c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
211c2c66affSColin Finck {
212c2c66affSColin Finck ok(0, "unexpected call\n");
213c2c66affSColin Finck return E_NOTIMPL;
214c2c66affSColin Finck }
215c2c66affSColin Finck
DispatchEx_GetNextDispID(IDispatchEx * iface,DWORD grfdex,DISPID id,DISPID * pid)216c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
217c2c66affSColin Finck {
218c2c66affSColin Finck ok(0, "unexpected call\n");
219c2c66affSColin Finck return E_NOTIMPL;
220c2c66affSColin Finck }
221c2c66affSColin Finck
DispatchEx_GetNameSpaceParent(IDispatchEx * iface,IUnknown ** ppunk)222c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
223c2c66affSColin Finck {
224c2c66affSColin Finck ok(0, "unexpected call\n");
225c2c66affSColin Finck return E_NOTIMPL;
226c2c66affSColin Finck }
227c2c66affSColin Finck
xmlhttprequest_onreadystatechange(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)228c2c66affSColin Finck static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
229c2c66affSColin Finck VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
230c2c66affSColin Finck {
231c2c66affSColin Finck LONG val;
232c2c66affSColin Finck HRESULT hres;
233c2c66affSColin Finck
234*e26c8bc6STimo Kreuzer if (!expect_xmlhttprequest_onreadystatechange_loading)
235c2c66affSColin Finck test_event_args(&DIID_DispHTMLXMLHttpRequest, id, wFlags, pdp, pvarRes, pei, pspCaller);
236c2c66affSColin Finck
237c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
238*e26c8bc6STimo Kreuzer disable_success_count
239c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
240c2c66affSColin Finck readystatechange_cnt++;
241c2c66affSColin Finck
242c2c66affSColin Finck switch(val) {
243c2c66affSColin Finck case 1:
244c2c66affSColin Finck CHECK_EXPECT(xmlhttprequest_onreadystatechange_opened);
245c2c66affSColin Finck break;
246c2c66affSColin Finck case 2:
247c2c66affSColin Finck CHECK_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
248c2c66affSColin Finck break;
249c2c66affSColin Finck case 3:
250c2c66affSColin Finck loading_cnt++;
251*e26c8bc6STimo Kreuzer disable_success_count
252c2c66affSColin Finck CHECK_EXPECT2(xmlhttprequest_onreadystatechange_loading);
253c2c66affSColin Finck break;
254c2c66affSColin Finck case 4:
255c2c66affSColin Finck CHECK_EXPECT(xmlhttprequest_onreadystatechange_done);
256c2c66affSColin Finck break;
257c2c66affSColin Finck default:
258c2c66affSColin Finck ok(0, "unexpected readyState: %d\n", val);
259c2c66affSColin Finck }
260c2c66affSColin Finck return S_OK;
261c2c66affSColin Finck }
262c2c66affSColin Finck
263c2c66affSColin Finck static IDispatchExVtbl xmlhttprequest_onreadystatechangeFuncVtbl = {
264c2c66affSColin Finck DispatchEx_QueryInterface,
265c2c66affSColin Finck DispatchEx_AddRef,
266c2c66affSColin Finck DispatchEx_Release,
267c2c66affSColin Finck DispatchEx_GetTypeInfoCount,
268c2c66affSColin Finck DispatchEx_GetTypeInfo,
269c2c66affSColin Finck DispatchEx_GetIDsOfNames,
270c2c66affSColin Finck DispatchEx_Invoke,
271c2c66affSColin Finck DispatchEx_GetDispID,
272c2c66affSColin Finck xmlhttprequest_onreadystatechange,
273c2c66affSColin Finck DispatchEx_DeleteMemberByName,
274c2c66affSColin Finck DispatchEx_DeleteMemberByDispID,
275c2c66affSColin Finck DispatchEx_GetMemberProperties,
276c2c66affSColin Finck DispatchEx_GetMemberName,
277c2c66affSColin Finck DispatchEx_GetNextDispID,
278c2c66affSColin Finck DispatchEx_GetNameSpaceParent
279c2c66affSColin Finck };
280c2c66affSColin Finck static IDispatchEx xmlhttprequest_onreadystatechange_obj = { &xmlhttprequest_onreadystatechangeFuncVtbl };
281c2c66affSColin Finck
282c2c66affSColin Finck static BOOL doc_complete;
283c2c66affSColin Finck static IHTMLDocument2 *notif_doc;
284c2c66affSColin Finck
PropertyNotifySink_QueryInterface(IPropertyNotifySink * iface,REFIID riid,void ** ppv)285c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
286c2c66affSColin Finck REFIID riid, void**ppv)
287c2c66affSColin Finck {
288c2c66affSColin Finck if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
289c2c66affSColin Finck *ppv = iface;
290c2c66affSColin Finck return S_OK;
291c2c66affSColin Finck }
292c2c66affSColin Finck
293c2c66affSColin Finck ok(0, "unexpected call\n");
294c2c66affSColin Finck return E_NOINTERFACE;
295c2c66affSColin Finck }
296c2c66affSColin Finck
PropertyNotifySink_AddRef(IPropertyNotifySink * iface)297c2c66affSColin Finck static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
298c2c66affSColin Finck {
299c2c66affSColin Finck return 2;
300c2c66affSColin Finck }
301c2c66affSColin Finck
PropertyNotifySink_Release(IPropertyNotifySink * iface)302c2c66affSColin Finck static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
303c2c66affSColin Finck {
304c2c66affSColin Finck return 1;
305c2c66affSColin Finck }
306c2c66affSColin Finck
PropertyNotifySink_OnChanged(IPropertyNotifySink * iface,DISPID dispID)307c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
308c2c66affSColin Finck {
309c2c66affSColin Finck if(dispID == DISPID_READYSTATE){
310c2c66affSColin Finck BSTR state;
311c2c66affSColin Finck HRESULT hres;
312c2c66affSColin Finck
313c2c66affSColin Finck hres = IHTMLDocument2_get_readyState(notif_doc, &state);
314c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
315c2c66affSColin Finck
316c2c66affSColin Finck if(!strcmp_wa(state, "complete"))
317c2c66affSColin Finck doc_complete = TRUE;
318c2c66affSColin Finck
319c2c66affSColin Finck SysFreeString(state);
320c2c66affSColin Finck }
321c2c66affSColin Finck
322c2c66affSColin Finck return S_OK;
323c2c66affSColin Finck }
324c2c66affSColin Finck
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink * iface,DISPID dispID)325c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
326c2c66affSColin Finck {
327c2c66affSColin Finck ok(0, "unexpected call\n");
328c2c66affSColin Finck return E_NOTIMPL;
329c2c66affSColin Finck }
330c2c66affSColin Finck
331c2c66affSColin Finck static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
332c2c66affSColin Finck PropertyNotifySink_QueryInterface,
333c2c66affSColin Finck PropertyNotifySink_AddRef,
334c2c66affSColin Finck PropertyNotifySink_Release,
335c2c66affSColin Finck PropertyNotifySink_OnChanged,
336c2c66affSColin Finck PropertyNotifySink_OnRequestEdit
337c2c66affSColin Finck };
338c2c66affSColin Finck
339c2c66affSColin Finck static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
340c2c66affSColin Finck
do_advise(IUnknown * unk,REFIID riid,IUnknown * unk_advise)341c2c66affSColin Finck static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
342c2c66affSColin Finck {
343c2c66affSColin Finck IConnectionPointContainer *container;
344c2c66affSColin Finck IConnectionPoint *cp;
345c2c66affSColin Finck DWORD cookie;
346c2c66affSColin Finck HRESULT hres;
347c2c66affSColin Finck
348c2c66affSColin Finck hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
349c2c66affSColin Finck ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
350c2c66affSColin Finck
351c2c66affSColin Finck hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
352c2c66affSColin Finck IConnectionPointContainer_Release(container);
353c2c66affSColin Finck ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
354c2c66affSColin Finck
355c2c66affSColin Finck hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
356c2c66affSColin Finck IConnectionPoint_Release(cp);
357c2c66affSColin Finck ok(hres == S_OK, "Advise failed: %08x\n", hres);
358c2c66affSColin Finck }
359c2c66affSColin Finck
pump_msgs(BOOL * b)360c2c66affSColin Finck static void pump_msgs(BOOL *b)
361c2c66affSColin Finck {
362c2c66affSColin Finck MSG msg;
363c2c66affSColin Finck
364c2c66affSColin Finck if(b) {
365c2c66affSColin Finck while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
366c2c66affSColin Finck TranslateMessage(&msg);
367c2c66affSColin Finck DispatchMessageW(&msg);
368c2c66affSColin Finck }
369c2c66affSColin Finck }else {
370c2c66affSColin Finck while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
371c2c66affSColin Finck TranslateMessage(&msg);
372c2c66affSColin Finck DispatchMessageW(&msg);
373c2c66affSColin Finck }
374c2c66affSColin Finck }
375c2c66affSColin Finck }
376c2c66affSColin Finck
377c2c66affSColin Finck
378c2c66affSColin Finck struct HEADER_TYPE {
379c2c66affSColin Finck const char *key;
380c2c66affSColin Finck const char *value;
381c2c66affSColin Finck };
382c2c66affSColin Finck
create_xmlhttprequest(IHTMLDocument2 * doc)383c2c66affSColin Finck static void create_xmlhttprequest(IHTMLDocument2 *doc)
384c2c66affSColin Finck {
385c2c66affSColin Finck IHTMLWindow2 *window;
386c2c66affSColin Finck IHTMLWindow5 *window5;
387c2c66affSColin Finck VARIANT var;
388c2c66affSColin Finck IHTMLXMLHttpRequestFactory *factory;
389c2c66affSColin Finck HRESULT hres;
390c2c66affSColin Finck
391c2c66affSColin Finck hres = IHTMLDocument2_get_parentWindow(doc, &window);
392c2c66affSColin Finck ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
393c2c66affSColin Finck ok(window != NULL, "window == NULL\n");
394c2c66affSColin Finck
395c2c66affSColin Finck hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow5, (void**)&window5);
396c2c66affSColin Finck IHTMLWindow2_Release(window);
397c2c66affSColin Finck if(FAILED(hres)) {
398c2c66affSColin Finck win_skip("IHTMLWindow5 not supported\n");
399c2c66affSColin Finck return;
400c2c66affSColin Finck }
401c2c66affSColin Finck
402c2c66affSColin Finck VariantInit(&var);
403c2c66affSColin Finck hres = IHTMLWindow5_get_XMLHttpRequest(window5, &var);
404c2c66affSColin Finck IHTMLWindow5_Release(window5);
405c2c66affSColin Finck ok(hres == S_OK, "get_XMLHttpRequest failed: %08x\n", hres);
406c2c66affSColin Finck ok(V_VT(&var) == VT_DISPATCH, "V_VT(&var) is %08x, expected VT_DISPATCH\n", V_VT(&var));
407c2c66affSColin Finck
408c2c66affSColin Finck hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLXMLHttpRequestFactory, (void**)&factory);
409c2c66affSColin Finck VariantClear(&var);
410c2c66affSColin Finck ok(hres == S_OK, "QueryInterface(IID_IHTMLXMLHttpRequestFactory) failed: %08x\n", hres);
411c2c66affSColin Finck ok(factory != NULL, "factory == NULL\n");
412c2c66affSColin Finck
413c2c66affSColin Finck hres = IHTMLXMLHttpRequestFactory_create(factory, &xhr);
414c2c66affSColin Finck IHTMLXMLHttpRequestFactory_Release(factory);
415c2c66affSColin Finck ok(hres == S_OK, "create failed: %08x\n", hres);
416c2c66affSColin Finck ok(xhr != NULL, "xhr == NULL\n");
417c2c66affSColin Finck }
418c2c66affSColin Finck
test_header(const struct HEADER_TYPE expect[],int num)419c2c66affSColin Finck static void test_header(const struct HEADER_TYPE expect[], int num)
420c2c66affSColin Finck {
421c2c66affSColin Finck int i;
422c2c66affSColin Finck BSTR key, text, all_header;
423c2c66affSColin Finck HRESULT hres;
424c2c66affSColin Finck char all[4096], buf[512];
425c2c66affSColin Finck
426c2c66affSColin Finck all_header = NULL;
427c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &all_header);
428c2c66affSColin Finck ok(hres == S_OK, "getAllResponseHeader failed: %08x\n", hres);
429c2c66affSColin Finck ok(all_header != NULL, "all_header == NULL\n");
430c2c66affSColin Finck
431c2c66affSColin Finck WideCharToMultiByte(CP_UTF8, 0, all_header, -1, all, sizeof(all), NULL, NULL);
432c2c66affSColin Finck SysFreeString(all_header);
433c2c66affSColin Finck
434c2c66affSColin Finck for(i = 0; i < num; ++i) {
435c2c66affSColin Finck text = NULL;
436c2c66affSColin Finck key = a2bstr(expect[i].key);
437c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, key, &text);
438c2c66affSColin Finck ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
439c2c66affSColin Finck ok(text != NULL, "text == NULL\n");
440c2c66affSColin Finck ok(!strcmp_wa(text, expect[i].value),
441c2c66affSColin Finck "Expect %s: %s, got %s\n", expect[i].key, expect[i].value, wine_dbgstr_w(text));
442c2c66affSColin Finck SysFreeString(key);
443c2c66affSColin Finck SysFreeString(text);
444c2c66affSColin Finck
445c2c66affSColin Finck strcpy(buf, expect[i].key);
446c2c66affSColin Finck strcat(buf, ": ");
447c2c66affSColin Finck strcat(buf, expect[i].value);
448c2c66affSColin Finck ok(strstr(all, buf) != NULL, "AllResponseHeaders(%s) don't have expected substr(%s)\n", all, buf);
449c2c66affSColin Finck }
450c2c66affSColin Finck }
451c2c66affSColin Finck
test_sync_xhr(IHTMLDocument2 * doc,const char * xml_url,const char * expect_text)452c2c66affSColin Finck static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
453c2c66affSColin Finck {
454c2c66affSColin Finck VARIANT vbool, vempty, var;
455c2c66affSColin Finck BSTR method, url;
456c2c66affSColin Finck BSTR text;
457c2c66affSColin Finck LONG val;
458c2c66affSColin Finck HRESULT hres;
459c2c66affSColin Finck static const struct HEADER_TYPE expect_headers[] = {
460c2c66affSColin Finck {"Server", "Apache"},
461c2c66affSColin Finck {"Accept-Ranges", "bytes"},
462c2c66affSColin Finck {"Content-Length", "51"},
463c2c66affSColin Finck {"Content-Type", "application/xml"}
464c2c66affSColin Finck };
465c2c66affSColin Finck
466c2c66affSColin Finck create_xmlhttprequest(doc);
467c2c66affSColin Finck if(!xhr)
468c2c66affSColin Finck return;
469c2c66affSColin Finck
470c2c66affSColin Finck V_VT(&var) = VT_EMPTY;
471c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
472c2c66affSColin Finck ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
473c2c66affSColin Finck ok(V_VT(&var) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
474c2c66affSColin Finck
475c2c66affSColin Finck V_VT(&var) = VT_DISPATCH;
476c2c66affSColin Finck V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
477c2c66affSColin Finck hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
478c2c66affSColin Finck ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
479c2c66affSColin Finck
480c2c66affSColin Finck V_VT(&var) = VT_EMPTY;
481c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
482c2c66affSColin Finck ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
483c2c66affSColin Finck ok(V_VT(&var) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
484c2c66affSColin Finck ok(V_DISPATCH(&var) == (IDispatch*)&xmlhttprequest_onreadystatechange_obj, "unexpected onreadystatechange value\n");
485c2c66affSColin Finck
486c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, NULL);
487c2c66affSColin Finck ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
488c2c66affSColin Finck
489c2c66affSColin Finck val = 0xdeadbeef;
490c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
491c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
492c2c66affSColin Finck ok(val == 0, "Expect UNSENT, got %d\n", val);
493c2c66affSColin Finck
494c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, NULL);
495c2c66affSColin Finck ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
496c2c66affSColin Finck
497c2c66affSColin Finck val = 0xdeadbeef;
498c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
499c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
500c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
501c2c66affSColin Finck
502c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, NULL);
503c2c66affSColin Finck ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
504c2c66affSColin Finck
505c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
506c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
507c2c66affSColin Finck ok(text == NULL, "Expect NULL, got %p\n", text);
508c2c66affSColin Finck
509c2c66affSColin Finck text = (BSTR)0xdeadbeef;
510c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
511c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
512c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
513c2c66affSColin Finck
514c2c66affSColin Finck text = (BSTR)0xdeadbeef;
515c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
516c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
517c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
518c2c66affSColin Finck
519c2c66affSColin Finck method = a2bstr("GET");
520c2c66affSColin Finck url = a2bstr(xml_url);
521c2c66affSColin Finck V_VT(&vbool) = VT_BOOL;
522c2c66affSColin Finck V_BOOL(&vbool) = VARIANT_FALSE;
523c2c66affSColin Finck V_VT(&vempty) = VT_EMPTY;
524c2c66affSColin Finck
525c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
526c2c66affSColin Finck hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
527c2c66affSColin Finck todo_wine ok(hres == S_OK, "open failed: %08x\n", hres); /* Gecko 30+ only supports async */
528c2c66affSColin Finck todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
529c2c66affSColin Finck
530c2c66affSColin Finck SysFreeString(method);
531c2c66affSColin Finck SysFreeString(url);
532c2c66affSColin Finck
533c2c66affSColin Finck if(FAILED(hres)) {
534c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
535c2c66affSColin Finck xhr = NULL;
536c2c66affSColin Finck return;
537c2c66affSColin Finck }
538c2c66affSColin Finck
539c2c66affSColin Finck text = (BSTR)0xdeadbeef;
540c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
541c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
542c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
543c2c66affSColin Finck
544c2c66affSColin Finck text = (BSTR)0xdeadbeef;
545c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
546c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
547c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
548c2c66affSColin Finck
549c2c66affSColin Finck val = 0xdeadbeef;
550c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
551c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
552c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
553c2c66affSColin Finck
554c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
555c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
556c2c66affSColin Finck ok(text == NULL, "Expect NULL, got %p\n", text);
557c2c66affSColin Finck
558c2c66affSColin Finck val = 0xdeadbeef;
559c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
560c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
561c2c66affSColin Finck ok(val == 1, "Expect OPENED, got %d\n", val);
562c2c66affSColin Finck
563c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
564c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
565c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
566c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_done);
567c2c66affSColin Finck loading_cnt = 0;
568c2c66affSColin Finck hres = IHTMLXMLHttpRequest_send(xhr, vempty);
569c2c66affSColin Finck ok(hres == S_OK, "send failed: %08x\n", hres);
570c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
571c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
572c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
573c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
574c2c66affSColin Finck ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
575c2c66affSColin Finck
576c2c66affSColin Finck text = NULL;
577c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
578c2c66affSColin Finck ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
579c2c66affSColin Finck ok(text != NULL, "text == NULL\n");
580c2c66affSColin Finck SysFreeString(text);
581c2c66affSColin Finck
582c2c66affSColin Finck if(expect_text)
583c2c66affSColin Finck test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
584c2c66affSColin Finck
585c2c66affSColin Finck val = 0xdeadbeef;
586c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
587c2c66affSColin Finck ok(hres == S_OK, "get_status failed: %08x\n", hres);
588c2c66affSColin Finck ok(val == 200, "Expect 200, got %d\n", val);
589c2c66affSColin Finck
590c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
591c2c66affSColin Finck ok(hres == S_OK, "get_statusText failed: %08x\n", hres);
592c2c66affSColin Finck ok(text != NULL, "text == NULL\n");
593c2c66affSColin Finck ok(!strcmp_wa(text, "OK"),
594c2c66affSColin Finck "Expected \"OK\", got %s\n", wine_dbgstr_w(text));
595c2c66affSColin Finck SysFreeString(text);
596c2c66affSColin Finck
597c2c66affSColin Finck val = 0xdeadbeef;
598c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
599c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
600c2c66affSColin Finck ok(val == 4, "Expect DONE, got %d\n", val);
601c2c66affSColin Finck
602c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
603c2c66affSColin Finck ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
604c2c66affSColin Finck ok(text != NULL, "test == NULL\n");
605c2c66affSColin Finck if(expect_text)
606c2c66affSColin Finck ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
607c2c66affSColin Finck expect_text, wine_dbgstr_w(text));
608c2c66affSColin Finck SysFreeString(text);
609c2c66affSColin Finck
610c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
611c2c66affSColin Finck xhr = NULL;
612c2c66affSColin Finck }
613c2c66affSColin Finck
test_async_xhr(IHTMLDocument2 * doc,const char * xml_url,const char * expect_text)614c2c66affSColin Finck static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
615c2c66affSColin Finck {
616c2c66affSColin Finck VARIANT vbool, vempty, var;
617c2c66affSColin Finck BSTR method, url;
618c2c66affSColin Finck BSTR text;
619c2c66affSColin Finck LONG val;
620c2c66affSColin Finck HRESULT hres;
621c2c66affSColin Finck static const struct HEADER_TYPE expect_headers[] = {
622c2c66affSColin Finck {"Content-Length", "51"},
623c2c66affSColin Finck {"Content-Type", "application/xml"}
624c2c66affSColin Finck };
625c2c66affSColin Finck
626c2c66affSColin Finck create_xmlhttprequest(doc);
627c2c66affSColin Finck if(!xhr)
628c2c66affSColin Finck return;
629c2c66affSColin Finck
630c2c66affSColin Finck V_VT(&var) = VT_DISPATCH;
631c2c66affSColin Finck V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
632c2c66affSColin Finck hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
633c2c66affSColin Finck ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
634c2c66affSColin Finck
635c2c66affSColin Finck V_VT(&var) = VT_EMPTY;
636c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
637c2c66affSColin Finck ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
638c2c66affSColin Finck ok(V_VT(&var) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
639c2c66affSColin Finck ok(V_DISPATCH(&var) == (IDispatch*)&xmlhttprequest_onreadystatechange_obj, "unexpected onreadystatechange value\n");
640c2c66affSColin Finck
641c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, NULL, &text);
642c2c66affSColin Finck ok(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
643c2c66affSColin Finck
644c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, NULL);
645c2c66affSColin Finck ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
646c2c66affSColin Finck
647c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, NULL, NULL);
648c2c66affSColin Finck ok(hres == E_POINTER || broken(hres == E_INVALIDARG), /* Vista and before */
649c2c66affSColin Finck "Expect E_POINTER, got %08x\n", hres);
650c2c66affSColin Finck
651c2c66affSColin Finck text = (BSTR)0xdeadbeef;
652c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
653c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
654c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
655c2c66affSColin Finck
656c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, NULL);
657c2c66affSColin Finck ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
658c2c66affSColin Finck
659c2c66affSColin Finck text = (BSTR)0xdeadbeef;
660c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
661c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
662c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
663c2c66affSColin Finck
664c2c66affSColin Finck val = 0xdeadbeef;
665c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
666c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
667c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
668c2c66affSColin Finck
669c2c66affSColin Finck text = (BSTR)0xdeadbeef;
670c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
671c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
672c2c66affSColin Finck ok(text == NULL, "Expect NULL, got %p\n", text);
673c2c66affSColin Finck
674c2c66affSColin Finck val = 0xdeadbeef;
675c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
676c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
677c2c66affSColin Finck ok(val == 0, "Expect UNSENT, got %d\n", val);
678c2c66affSColin Finck
679c2c66affSColin Finck method = a2bstr("GET");
680c2c66affSColin Finck url = a2bstr(xml_url);
681c2c66affSColin Finck V_VT(&vbool) = VT_BOOL;
682c2c66affSColin Finck V_BOOL(&vbool) = VARIANT_TRUE;
683c2c66affSColin Finck V_VT(&vempty) = VT_EMPTY;
684c2c66affSColin Finck
685c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
686c2c66affSColin Finck hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
687c2c66affSColin Finck ok(hres == S_OK, "open failed: %08x\n", hres);
688c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
689c2c66affSColin Finck
690c2c66affSColin Finck SysFreeString(method);
691c2c66affSColin Finck SysFreeString(url);
692c2c66affSColin Finck
693c2c66affSColin Finck if(FAILED(hres)) {
694c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
695c2c66affSColin Finck xhr = NULL;
696c2c66affSColin Finck return;
697c2c66affSColin Finck }
698c2c66affSColin Finck
699c2c66affSColin Finck text = (BSTR)0xdeadbeef;
700c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
701c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
702c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
703c2c66affSColin Finck
704c2c66affSColin Finck text = (BSTR)0xdeadbeef;
705c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
706c2c66affSColin Finck ok(hres == E_FAIL, "got %08x\n", hres);
707c2c66affSColin Finck ok(text == NULL, "text = %p\n", text);
708c2c66affSColin Finck
709c2c66affSColin Finck val = 0xdeadbeef;
710c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
711c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
712c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
713c2c66affSColin Finck
714c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
715c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
716c2c66affSColin Finck ok(text == NULL, "Expect NULL, got %p\n", text);
717c2c66affSColin Finck
718c2c66affSColin Finck val = 0xdeadbeef;
719c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
720c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
721c2c66affSColin Finck ok(val == 1, "Expect OPENED, got %d\n", val);
722c2c66affSColin Finck
723c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
724c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
725c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
726c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_done);
727c2c66affSColin Finck loading_cnt = 0;
728c2c66affSColin Finck hres = IHTMLXMLHttpRequest_send(xhr, vempty);
729c2c66affSColin Finck
730c2c66affSColin Finck ok(hres == S_OK, "send failed: %08x\n", hres);
731c2c66affSColin Finck if(SUCCEEDED(hres))
732c2c66affSColin Finck pump_msgs(&called_xmlhttprequest_onreadystatechange_done);
733c2c66affSColin Finck todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
734c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
735c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
736c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
737c2c66affSColin Finck /* Workaround for loading large files */
738c2c66affSColin Finck if(expect_text)
739c2c66affSColin Finck ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
740c2c66affSColin Finck else
741c2c66affSColin Finck todo_wine ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
742c2c66affSColin Finck
743c2c66affSColin Finck if(FAILED(hres)) {
744c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
745c2c66affSColin Finck xhr = NULL;
746c2c66affSColin Finck return;
747c2c66affSColin Finck }
748c2c66affSColin Finck
749c2c66affSColin Finck text = NULL;
750c2c66affSColin Finck hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
751c2c66affSColin Finck ok(hres == S_OK, "getAllResponseHeader failed, got %08x\n", hres);
752c2c66affSColin Finck ok(text != NULL, "text == NULL\n");
753c2c66affSColin Finck SysFreeString(text);
754c2c66affSColin Finck
755c2c66affSColin Finck if(expect_text)
756c2c66affSColin Finck test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
757c2c66affSColin Finck
758c2c66affSColin Finck val = 0xdeadbeef;
759c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
760c2c66affSColin Finck ok(hres == S_OK, "get_status failed: %08x\n", hres);
761c2c66affSColin Finck ok(val == 200, "Expect 200, got %d\n", val);
762c2c66affSColin Finck
763c2c66affSColin Finck text = NULL;
764c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
765c2c66affSColin Finck ok(hres == S_OK, "get_statusText failed: %08x\n", hres);
766c2c66affSColin Finck ok(text != NULL, "text == NULL\n");
767c2c66affSColin Finck ok(!strcmp_wa(text, "OK"), "Expected \"OK\", got %s\n", wine_dbgstr_w(text));
768c2c66affSColin Finck SysFreeString(text);
769c2c66affSColin Finck
770c2c66affSColin Finck val = 0xdeadbeef;
771c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
772c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
773c2c66affSColin Finck ok(val == 4, "Expect DONE, got %d\n", val);
774c2c66affSColin Finck
775c2c66affSColin Finck text = NULL;
776c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
777c2c66affSColin Finck ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
778c2c66affSColin Finck ok(text != NULL, "test == NULL\n");
779c2c66affSColin Finck if(expect_text)
780c2c66affSColin Finck ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
781c2c66affSColin Finck expect_text, wine_dbgstr_w(text));
782c2c66affSColin Finck SysFreeString(text);
783c2c66affSColin Finck
784c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
785c2c66affSColin Finck xhr = NULL;
786c2c66affSColin Finck }
787c2c66affSColin Finck
test_async_xhr_abort(IHTMLDocument2 * doc,const char * xml_url)788c2c66affSColin Finck static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
789c2c66affSColin Finck {
790c2c66affSColin Finck VARIANT vbool, vempty, var;
791c2c66affSColin Finck BSTR method, url;
792c2c66affSColin Finck LONG val;
793c2c66affSColin Finck HRESULT hres;
794c2c66affSColin Finck
795c2c66affSColin Finck method = a2bstr("GET");
796c2c66affSColin Finck url = a2bstr(xml_url);
797c2c66affSColin Finck V_VT(&vbool) = VT_BOOL;
798c2c66affSColin Finck V_BOOL(&vbool) = VARIANT_TRUE;
799c2c66affSColin Finck V_VT(&vempty) = VT_EMPTY;
800c2c66affSColin Finck
801c2c66affSColin Finck trace("abort before send() is fired\n");
802c2c66affSColin Finck create_xmlhttprequest(doc);
803c2c66affSColin Finck if(!xhr)
804c2c66affSColin Finck return;
805c2c66affSColin Finck
806c2c66affSColin Finck V_VT(&var) = VT_DISPATCH;
807c2c66affSColin Finck V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
808c2c66affSColin Finck hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
809c2c66affSColin Finck
810c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
811c2c66affSColin Finck hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
812c2c66affSColin Finck ok(hres == S_OK, "open failed: %08x\n", hres);
813c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
814c2c66affSColin Finck
815c2c66affSColin Finck hres = IHTMLXMLHttpRequest_abort(xhr);
816c2c66affSColin Finck ok(hres == S_OK, "abort failed: %08x\n", hres);
817c2c66affSColin Finck
818c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
819c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
820c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
821c2c66affSColin Finck
822c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
823c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
824c2c66affSColin Finck ok(val == 0, "Expect UNSENT, got %d\n", val);
825c2c66affSColin Finck
826c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
827c2c66affSColin Finck xhr = NULL;
828c2c66affSColin Finck
829c2c66affSColin Finck trace("abort after send() is fired\n");
830c2c66affSColin Finck create_xmlhttprequest(doc);
831c2c66affSColin Finck V_VT(&var) = VT_DISPATCH;
832c2c66affSColin Finck V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
833c2c66affSColin Finck hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
834c2c66affSColin Finck
835c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
836c2c66affSColin Finck hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
837c2c66affSColin Finck ok(hres == S_OK, "open failed: %08x\n", hres);
838c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
839c2c66affSColin Finck
840c2c66affSColin Finck loading_cnt = 0;
841c2c66affSColin Finck readystatechange_cnt = 0;
842c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
843c2c66affSColin Finck SET_EXPECT(xmlhttprequest_onreadystatechange_done);
844c2c66affSColin Finck hres = IHTMLXMLHttpRequest_send(xhr, vempty);
845c2c66affSColin Finck ok(hres == S_OK, "send failed: %08x\n", hres);
846c2c66affSColin Finck todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
847c2c66affSColin Finck
848c2c66affSColin Finck hres = IHTMLXMLHttpRequest_abort(xhr);
849c2c66affSColin Finck ok(hres == S_OK, "abort failed: %08x\n", hres);
850c2c66affSColin Finck CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
851c2c66affSColin Finck
852c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
853c2c66affSColin Finck ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
854c2c66affSColin Finck ok(val == 0, "Expect UNSENT, got %d\n", val);
855c2c66affSColin Finck
856c2c66affSColin Finck hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
857c2c66affSColin Finck ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
858c2c66affSColin Finck ok(val == 0, "Expect 0, got %d\n", val);
859c2c66affSColin Finck
860c2c66affSColin Finck ok(loading_cnt == 0, "loading_cnt = %d, expect 0, loading_cnt\n", loading_cnt);
861c2c66affSColin Finck todo_wine ok(readystatechange_cnt == 2, "readystatechange_cnt = %d, expect 2\n", readystatechange_cnt);
862c2c66affSColin Finck
863c2c66affSColin Finck IHTMLXMLHttpRequest_Release(xhr);
864c2c66affSColin Finck xhr = NULL;
865c2c66affSColin Finck
866c2c66affSColin Finck SysFreeString(method);
867c2c66affSColin Finck SysFreeString(url);
868c2c66affSColin Finck }
869c2c66affSColin Finck
create_doc_from_url(const char * start_url)870c2c66affSColin Finck static IHTMLDocument2 *create_doc_from_url(const char *start_url)
871c2c66affSColin Finck {
872c2c66affSColin Finck BSTR url;
873c2c66affSColin Finck IBindCtx *bc;
874c2c66affSColin Finck IMoniker *url_mon;
875c2c66affSColin Finck IPersistMoniker *persist_mon;
876c2c66affSColin Finck IHTMLDocument2 *doc;
877c2c66affSColin Finck HRESULT hres;
878c2c66affSColin Finck
879c2c66affSColin Finck hres = CreateBindCtx(0, &bc);
880c2c66affSColin Finck ok(hres == S_OK, "CreateBindCtx failed: 0x%08x\n", hres);
881c2c66affSColin Finck
882c2c66affSColin Finck url = a2bstr(start_url);
883c2c66affSColin Finck hres = CreateURLMoniker(NULL, url, &url_mon);
884c2c66affSColin Finck ok(hres == S_OK, "CreateURLMoniker failed: 0x%08x\n", hres);
885c2c66affSColin Finck
886c2c66affSColin Finck hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
887c2c66affSColin Finck CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
888c2c66affSColin Finck (void**)&doc);
889c2c66affSColin Finck ok(hres == S_OK, "CoCreateInstance failed: 0x%08x\n", hres);
890c2c66affSColin Finck
891c2c66affSColin Finck hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker,
892c2c66affSColin Finck (void**)&persist_mon);
893c2c66affSColin Finck ok(hres == S_OK, "IHTMLDocument2_QueryInterface failed: 0x%08x\n", hres);
894c2c66affSColin Finck
895c2c66affSColin Finck hres = IPersistMoniker_Load(persist_mon, FALSE, url_mon, bc,
896c2c66affSColin Finck STGM_SHARE_EXCLUSIVE | STGM_READWRITE);
897c2c66affSColin Finck ok(hres == S_OK, "IPersistMoniker_Load failed: 0x%08x\n", hres);
898c2c66affSColin Finck
899c2c66affSColin Finck IPersistMoniker_Release(persist_mon);
900c2c66affSColin Finck IMoniker_Release(url_mon);
901c2c66affSColin Finck IBindCtx_Release(bc);
902c2c66affSColin Finck SysFreeString(url);
903c2c66affSColin Finck
904c2c66affSColin Finck doc_complete = FALSE;
905c2c66affSColin Finck notif_doc = doc;
906c2c66affSColin Finck do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
907c2c66affSColin Finck pump_msgs(&doc_complete);
908c2c66affSColin Finck
909c2c66affSColin Finck return doc;
910c2c66affSColin Finck }
911c2c66affSColin Finck
START_TEST(xmlhttprequest)912c2c66affSColin Finck START_TEST(xmlhttprequest)
913c2c66affSColin Finck {
914c2c66affSColin Finck IHTMLDocument2 *doc;
915c2c66affSColin Finck static const char start_url[] = "http://test.winehq.org/tests/hello.html";
916c2c66affSColin Finck static const char xml_url[] = "http://test.winehq.org/tests/xmltest.xml";
917c2c66affSColin Finck static const char large_page_url[] = "http://test.winehq.org/tests/data.php";
918c2c66affSColin Finck static const char expect_response_text[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
919c2c66affSColin Finck
920c2c66affSColin Finck CoInitialize(NULL);
921c2c66affSColin Finck
922c2c66affSColin Finck content_type = a2bstr("Content-Type");
923c2c66affSColin Finck doc = create_doc_from_url(start_url);
924c2c66affSColin Finck if(doc) {
925c2c66affSColin Finck test_sync_xhr(doc, xml_url, expect_response_text);
926c2c66affSColin Finck test_sync_xhr(doc, large_page_url, NULL);
927c2c66affSColin Finck test_async_xhr(doc, xml_url, expect_response_text);
928c2c66affSColin Finck test_async_xhr(doc, large_page_url, NULL);
929c2c66affSColin Finck test_async_xhr_abort(doc, large_page_url);
930c2c66affSColin Finck IHTMLDocument2_Release(doc);
931c2c66affSColin Finck }
932c2c66affSColin Finck SysFreeString(content_type);
933c2c66affSColin Finck
934c2c66affSColin Finck CoUninitialize();
935c2c66affSColin Finck }
936