ReactOS  0.4.13-dev-986-g029b8f2
xmlhttprequest.c File Reference
#include "precomp.h"
Include dependency graph for xmlhttprequest.c:

Go to the source code of this file.

Classes

struct  HEADER_TYPE
 

Macros

#define DEFINE_EXPECT(func)   static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
 
#define SET_EXPECT(func)   do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
 
#define CHECK_EXPECT2(func)
 
#define CHECK_EXPECT(func)
 
#define CHECK_CALLED(func)
 
#define test_disp(u, id)   _test_disp(__LINE__,u,id)
 
#define test_event_args(a, b, c, d, e, f, g)   _test_event_args(__LINE__,a,b,c,d,e,f,g)
 

Functions

static BSTR a2bstr (const char *str)
 
static int strcmp_wa (LPCWSTR strw, const char *stra)
 
 DEFINE_EXPECT (xmlhttprequest_onreadystatechange_opened)
 
 DEFINE_EXPECT (xmlhttprequest_onreadystatechange_headers_received)
 
 DEFINE_EXPECT (xmlhttprequest_onreadystatechange_loading)
 
 DEFINE_EXPECT (xmlhttprequest_onreadystatechange_done)
 
static void _test_disp (unsigned line, IUnknown *unk, const IID *diid)
 
static void _test_event_args (unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
 
static HRESULT WINAPI DispatchEx_QueryInterface (IDispatchEx *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI DispatchEx_AddRef (IDispatchEx *iface)
 
static ULONG WINAPI DispatchEx_Release (IDispatchEx *iface)
 
static HRESULT WINAPI DispatchEx_GetTypeInfoCount (IDispatchEx *iface, UINT *pctinfo)
 
static HRESULT WINAPI DispatchEx_GetTypeInfo (IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
 
static HRESULT WINAPI DispatchEx_GetIDsOfNames (IDispatchEx *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
 
static HRESULT WINAPI DispatchEx_Invoke (IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
 
static HRESULT WINAPI DispatchEx_GetDispID (IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
 
static HRESULT WINAPI DispatchEx_DeleteMemberByName (IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
 
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID (IDispatchEx *iface, DISPID id)
 
static HRESULT WINAPI DispatchEx_GetMemberProperties (IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
 
static HRESULT WINAPI DispatchEx_GetMemberName (IDispatchEx *iface, DISPID id, BSTR *pbstrName)
 
static HRESULT WINAPI DispatchEx_GetNextDispID (IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
 
static HRESULT WINAPI DispatchEx_GetNameSpaceParent (IDispatchEx *iface, IUnknown **ppunk)
 
static HRESULT WINAPI xmlhttprequest_onreadystatechange (IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
 
static HRESULT WINAPI PropertyNotifySink_QueryInterface (IPropertyNotifySink *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI PropertyNotifySink_AddRef (IPropertyNotifySink *iface)
 
static ULONG WINAPI PropertyNotifySink_Release (IPropertyNotifySink *iface)
 
static HRESULT WINAPI PropertyNotifySink_OnChanged (IPropertyNotifySink *iface, DISPID dispID)
 
static HRESULT WINAPI PropertyNotifySink_OnRequestEdit (IPropertyNotifySink *iface, DISPID dispID)
 
static void do_advise (IUnknown *unk, REFIID riid, IUnknown *unk_advise)
 
static void pump_msgs (BOOL *b)
 
static void create_xmlhttprequest (IHTMLDocument2 *doc)
 
static void test_header (const struct HEADER_TYPE expect[], int num)
 
static void test_sync_xhr (IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
 
static void test_async_xhr (IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
 
static void test_async_xhr_abort (IHTMLDocument2 *doc, const char *xml_url)
 
static IHTMLDocument2 * create_doc_from_url (const char *start_url)
 
 START_TEST (xmlhttprequest)
 

Variables

static IHTMLXMLHttpRequest * xhr = NULL
 
static BSTR content_type = NULL
 
static int loading_cnt = 0
 
static int readystatechange_cnt = 0
 
static IDispatchExVtbl xmlhttprequest_onreadystatechangeFuncVtbl
 
static IDispatchEx xmlhttprequest_onreadystatechange_obj = { &xmlhttprequest_onreadystatechangeFuncVtbl }
 
static BOOL doc_complete
 
static IHTMLDocument2 * notif_doc
 
static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
 
static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl }
 

Macro Definition Documentation

◆ CHECK_CALLED

#define CHECK_CALLED (   func)
Value:
do { \
ok(called_ ## func, "expected " #func "\n"); \
expect_ ## func = called_ ## func = FALSE; \
}while(0)
GLenum func
Definition: glext.h:6028

Definition at line 59 of file xmlhttprequest.c.

◆ CHECK_EXPECT

#define CHECK_EXPECT (   func)
Value:
do { \
CHECK_EXPECT2(func); \
expect_ ## func = FALSE; \
}while(0)
GLenum func
Definition: glext.h:6028

Definition at line 53 of file xmlhttprequest.c.

◆ CHECK_EXPECT2

#define CHECK_EXPECT2 (   func)
Value:
do { \
trace(#func "\n"); \
ok(expect_ ##func, "unexpected call " #func "\n"); \
called_ ## func = TRUE; \
}while(0)
GLenum func
Definition: glext.h:6028
#define TRUE
Definition: types.h:120
#define expect_(expected, got, precision)
Definition: font.c:29

Definition at line 46 of file xmlhttprequest.c.

◆ DEFINE_EXPECT

#define DEFINE_EXPECT (   func)    static BOOL expect_ ## func = FALSE, called_ ## func = FALSE

Definition at line 40 of file xmlhttprequest.c.

◆ SET_EXPECT

#define SET_EXPECT (   func)    do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)

Definition at line 43 of file xmlhttprequest.c.

◆ test_disp

#define test_disp (   u,
  id 
)    _test_disp(__LINE__,u,id)

Definition at line 75 of file xmlhttprequest.c.

◆ test_event_args

#define test_event_args (   a,
  b,
  c,
  d,
  e,
  f,
  g 
)    _test_event_args(__LINE__,a,b,c,d,e,f,g)

Definition at line 111 of file xmlhttprequest.c.

Function Documentation

◆ _test_disp()

static void _test_disp ( unsigned  line,
IUnknown unk,
const IID diid 
)
static

Definition at line 76 of file xmlhttprequest.c.

77 {
78  IDispatchEx *dispex;
80  UINT ticnt;
81  HRESULT hres;
82 
83  hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
84  ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
85  if(FAILED(hres))
86  return;
87 
88  ticnt = 0xdeadbeef;
89  hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
90  ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
91  ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
92 
93  hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
94  ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
95 
96  if(SUCCEEDED(hres)) {
97  TYPEATTR *type_attr;
98 
99  hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
100  ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
101  ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
102  wine_dbgstr_guid(&type_attr->guid));
103 
104  ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
105  ITypeInfo_Release(typeinfo);
106  }
107 
108  IDispatchEx_Release(dispex);
109 }
const char * wine_dbgstr_guid(const GUID *guid)
Definition: parser.c:48
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
static ITypeInfo * typeinfo[last_tid]
Definition: apps.c:106
#define S_OK
Definition: intsafe.h:59
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define ok_(x1, x2)
Definition: atltest.h:61

Referenced by _test_event_args().

◆ _test_event_args()

static void _test_event_args ( unsigned  line,
const IID dispiid,
DISPID  id,
WORD  wFlags,
DISPPARAMS *  pdp,
VARIANT pvarRes,
EXCEPINFO *  pei,
IServiceProvider pspCaller 
)
static

Definition at line 112 of file xmlhttprequest.c.

114 {
115  ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
116  ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
117  ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
118  ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
119  ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
120  ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
121  pdp->rgdispidNamedArgs[0]);
122  ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
123  ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
124  ok_(__FILE__,line) (pei != NULL, "pei == NULL");
125  ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
126 
127  if(dispiid)
128  _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
129 }
#define DISPATCH_METHOD
Definition: oleauto.h:1006
#define V_DISPATCH(A)
Definition: oleauto.h:239
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
#define V_VT(A)
Definition: oleauto.h:211
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:519
#define DISPID_THIS
Definition: olectl.h:395
GLenum GLuint id
Definition: glext.h:5579
static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
#define ok_(x1, x2)
Definition: atltest.h:61

◆ a2bstr()

static BSTR a2bstr ( const char str)
static

Definition at line 21 of file xmlhttprequest.c.

22 {
23  BSTR ret;
24  int len;
25 
26  len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
29 
30  return ret;
31 }
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:342
#define CP_ACP
Definition: compat.h:99
OLECHAR * BSTR
Definition: compat.h:1934
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define MultiByteToWideChar
Definition: compat.h:100

Referenced by create_doc_from_url(), START_TEST(), test_async_xhr(), test_async_xhr_abort(), test_header(), and test_sync_xhr().

◆ create_doc_from_url()

static IHTMLDocument2* create_doc_from_url ( const char start_url)
static

Definition at line 867 of file xmlhttprequest.c.

868 {
869  BSTR url;
870  IBindCtx *bc;
871  IMoniker *url_mon;
872  IPersistMoniker *persist_mon;
873  IHTMLDocument2 *doc;
874  HRESULT hres;
875 
876  hres = CreateBindCtx(0, &bc);
877  ok(hres == S_OK, "CreateBindCtx failed: 0x%08x\n", hres);
878 
879  url = a2bstr(start_url);
880  hres = CreateURLMoniker(NULL, url, &url_mon);
881  ok(hres == S_OK, "CreateURLMoniker failed: 0x%08x\n", hres);
882 
883  hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
884  CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
885  (void**)&doc);
886  ok(hres == S_OK, "CoCreateInstance failed: 0x%08x\n", hres);
887 
888  hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker,
889  (void**)&persist_mon);
890  ok(hres == S_OK, "IHTMLDocument2_QueryInterface failed: 0x%08x\n", hres);
891 
892  hres = IPersistMoniker_Load(persist_mon, FALSE, url_mon, bc,
894  ok(hres == S_OK, "IPersistMoniker_Load failed: 0x%08x\n", hres);
895 
896  IPersistMoniker_Release(persist_mon);
897  IMoniker_Release(url_mon);
898  IBindCtx_Release(bc);
900 
902  notif_doc = doc;
905 
906  return doc;
907 }
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
LPBATCH_CONTEXT bc
Definition: batch.c:66
OLECHAR * BSTR
Definition: compat.h:1934
static IHTMLDocument2 * notif_doc
smooth NULL
Definition: ftsmooth.c:416
HRESULT hres
Definition: protocol.c:465
HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC *ppbc)
Definition: bindctx.c:556
static BOOL doc_complete
static void pump_msgs(BOOL *b)
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR url[]
Definition: encode.c:1432
#define STGM_READWRITE
Definition: objbase.h:918
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
const GUID IID_IPropertyNotifySink
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
Definition: umon.c:732
static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
static IPropertyNotifySink PropertyNotifySink

Referenced by START_TEST().

◆ create_xmlhttprequest()

static void create_xmlhttprequest ( IHTMLDocument2 *  doc)
static

Definition at line 380 of file xmlhttprequest.c.

381 {
383  IHTMLWindow5 *window5;
384  VARIANT var;
385  IHTMLXMLHttpRequestFactory *factory;
386  HRESULT hres;
387 
388  hres = IHTMLDocument2_get_parentWindow(doc, &window);
389  ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
390  ok(window != NULL, "window == NULL\n");
391 
392  hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow5, (void**)&window5);
393  IHTMLWindow2_Release(window);
394  if(FAILED(hres)) {
395  win_skip("IHTMLWindow5 not supported\n");
396  return;
397  }
398 
399  VariantInit(&var);
400  hres = IHTMLWindow5_get_XMLHttpRequest(window5, &var);
401  IHTMLWindow5_Release(window5);
402  ok(hres == S_OK, "get_XMLHttpRequest failed: %08x\n", hres);
403  ok(V_VT(&var) == VT_DISPATCH, "V_VT(&var) is %08x, expected VT_DISPATCH\n", V_VT(&var));
404 
405  hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IHTMLXMLHttpRequestFactory, (void**)&factory);
406  VariantClear(&var);
407  ok(hres == S_OK, "QueryInterface(IID_IHTMLXMLHttpRequestFactory) failed: %08x\n", hres);
408  ok(factory != NULL, "factory == NULL\n");
409 
410  hres = IHTMLXMLHttpRequestFactory_create(factory, &xhr);
411  IHTMLXMLHttpRequestFactory_Release(factory);
412  ok(hres == S_OK, "create failed: %08x\n", hres);
413  ok(xhr != NULL, "xhr == NULL\n");
414 }
static IHTMLXMLHttpRequest * xhr
__IHTMLWindow2_FWD_DEFINED__ typedef interface IHTMLWindow2 IHTMLWindow2
Definition: mshtmhst.idl:64
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:571
#define V_DISPATCH(A)
Definition: oleauto.h:239
Definition: main.c:440
smooth NULL
Definition: ftsmooth.c:416
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
#define V_VT(A)
Definition: oleauto.h:211
static IHTMLWindow2 * window
Definition: events.c:77
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static ClassFactoryImpl factory
Definition: ole_server.c:234
#define win_skip
Definition: test.h:141

Referenced by test_async_xhr(), test_async_xhr_abort(), and test_sync_xhr().

◆ DEFINE_EXPECT() [1/4]

DEFINE_EXPECT ( xmlhttprequest_onreadystatechange_opened  )

◆ DEFINE_EXPECT() [2/4]

DEFINE_EXPECT ( xmlhttprequest_onreadystatechange_headers_received  )

◆ DEFINE_EXPECT() [3/4]

DEFINE_EXPECT ( xmlhttprequest_onreadystatechange_loading  )

◆ DEFINE_EXPECT() [4/4]

DEFINE_EXPECT ( xmlhttprequest_onreadystatechange_done  )

◆ DispatchEx_AddRef()

static ULONG WINAPI DispatchEx_AddRef ( IDispatchEx *  iface)
static

Definition at line 147 of file xmlhttprequest.c.

148 {
149  return 2;
150 }

◆ DispatchEx_DeleteMemberByDispID()

static HRESULT WINAPI DispatchEx_DeleteMemberByDispID ( IDispatchEx *  iface,
DISPID  id 
)
static

Definition at line 198 of file xmlhttprequest.c.

199 {
200  ok(0, "unexpected call\n");
201  return E_NOTIMPL;
202 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_DeleteMemberByName()

static HRESULT WINAPI DispatchEx_DeleteMemberByName ( IDispatchEx *  iface,
BSTR  bstrName,
DWORD  grfdex 
)
static

Definition at line 192 of file xmlhttprequest.c.

193 {
194  ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
195  return E_NOTIMPL;
196 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetDispID()

static HRESULT WINAPI DispatchEx_GetDispID ( IDispatchEx *  iface,
BSTR  bstrName,
DWORD  grfdex,
DISPID pid 
)
static

Definition at line 186 of file xmlhttprequest.c.

187 {
188  ok(0, "unexpected call\n");
189  return E_NOTIMPL;
190 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetIDsOfNames()

static HRESULT WINAPI DispatchEx_GetIDsOfNames ( IDispatchEx *  iface,
REFIID  riid,
LPOLESTR rgszNames,
UINT  cNames,
LCID  lcid,
DISPID rgDispId 
)
static

Definition at line 170 of file xmlhttprequest.c.

173 {
174  ok(0, "unexpected call\n");
175  return E_NOTIMPL;
176 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetMemberName()

static HRESULT WINAPI DispatchEx_GetMemberName ( IDispatchEx *  iface,
DISPID  id,
BSTR pbstrName 
)
static

Definition at line 210 of file xmlhttprequest.c.

211 {
212  ok(0, "unexpected call\n");
213  return E_NOTIMPL;
214 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetMemberProperties()

static HRESULT WINAPI DispatchEx_GetMemberProperties ( IDispatchEx *  iface,
DISPID  id,
DWORD  grfdexFetch,
DWORD pgrfdex 
)
static

Definition at line 204 of file xmlhttprequest.c.

205 {
206  ok(0, "unexpected call\n");
207  return E_NOTIMPL;
208 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetNameSpaceParent()

static HRESULT WINAPI DispatchEx_GetNameSpaceParent ( IDispatchEx *  iface,
IUnknown **  ppunk 
)
static

Definition at line 222 of file xmlhttprequest.c.

223 {
224  ok(0, "unexpected call\n");
225  return E_NOTIMPL;
226 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetNextDispID()

static HRESULT WINAPI DispatchEx_GetNextDispID ( IDispatchEx *  iface,
DWORD  grfdex,
DISPID  id,
DISPID pid 
)
static

Definition at line 216 of file xmlhttprequest.c.

217 {
218  ok(0, "unexpected call\n");
219  return E_NOTIMPL;
220 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetTypeInfo()

static HRESULT WINAPI DispatchEx_GetTypeInfo ( IDispatchEx *  iface,
UINT  iTInfo,
LCID  lcid,
ITypeInfo **  ppTInfo 
)
static

Definition at line 163 of file xmlhttprequest.c.

165 {
166  ok(0, "unexpected call\n");
167  return E_NOTIMPL;
168 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_GetTypeInfoCount()

static HRESULT WINAPI DispatchEx_GetTypeInfoCount ( IDispatchEx *  iface,
UINT pctinfo 
)
static

Definition at line 157 of file xmlhttprequest.c.

158 {
159  ok(0, "unexpected call\n");
160  return E_NOTIMPL;
161 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_Invoke()

static HRESULT WINAPI DispatchEx_Invoke ( IDispatchEx *  iface,
DISPID  dispIdMember,
REFIID  riid,
LCID  lcid,
WORD  wFlags,
DISPPARAMS *  pDispParams,
VARIANT pVarResult,
EXCEPINFO *  pExcepInfo,
UINT puArgErr 
)
static

Definition at line 178 of file xmlhttprequest.c.

181 {
182  ok(0, "unexpected call\n");
183  return E_NOTIMPL;
184 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ DispatchEx_QueryInterface()

static HRESULT WINAPI DispatchEx_QueryInterface ( IDispatchEx *  iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 131 of file xmlhttprequest.c.

132 {
133  *ppv = NULL;
134 
137  || IsEqualGUID(riid, &IID_IDispatchEx))
138  *ppv = iface;
139  else {
140  ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
141  return E_NOINTERFACE;
142  }
143 
144  return S_OK;
145 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
const char * wine_dbgstr_guid(const GUID *guid)
smooth NULL
Definition: ftsmooth.c:416
const GUID IID_IUnknown
const GUID IID_IDispatch
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021

◆ DispatchEx_Release()

static ULONG WINAPI DispatchEx_Release ( IDispatchEx *  iface)
static

Definition at line 152 of file xmlhttprequest.c.

153 {
154  return 1;
155 }

◆ do_advise()

static void do_advise ( IUnknown unk,
REFIID  riid,
IUnknown unk_advise 
)
static

Definition at line 338 of file xmlhttprequest.c.

339 {
342  DWORD cookie;
343  HRESULT hres;
344 
345  hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
346  ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
347 
348  hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
349  IConnectionPointContainer_Release(container);
350  ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
351 
352  hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
353  IConnectionPoint_Release(cp);
354  ok(hres == S_OK, "Advise failed: %08x\n", hres);
355 }
REFIID riid
Definition: precomp.h:44
const GUID IID_IConnectionPointContainer
struct container container
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
POINT cp
Definition: magnifier.c:59

Referenced by create_doc_from_url().

◆ PropertyNotifySink_AddRef()

static ULONG WINAPI PropertyNotifySink_AddRef ( IPropertyNotifySink iface)
static

Definition at line 294 of file xmlhttprequest.c.

295 {
296  return 2;
297 }

◆ PropertyNotifySink_OnChanged()

static HRESULT WINAPI PropertyNotifySink_OnChanged ( IPropertyNotifySink iface,
DISPID  dispID 
)
static

Definition at line 304 of file xmlhttprequest.c.

305 {
306  if(dispID == DISPID_READYSTATE){
307  BSTR state;
308  HRESULT hres;
309 
310  hres = IHTMLDocument2_get_readyState(notif_doc, &state);
311  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
312 
313  if(!strcmp_wa(state, "complete"))
314  doc_complete = TRUE;
315 
317  }
318 
319  return S_OK;
320 }
#define TRUE
Definition: types.h:120
OLECHAR * BSTR
Definition: compat.h:1934
static IHTMLDocument2 * notif_doc
HRESULT hres
Definition: protocol.c:465
static BOOL doc_complete
LONG HRESULT
Definition: typedefs.h:77
static int strcmp_wa(LPCWSTR strw, const char *stra)
static int state
Definition: maze.c:121
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define DISPID_READYSTATE
Definition: idispids.h:22
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274

◆ PropertyNotifySink_OnRequestEdit()

static HRESULT WINAPI PropertyNotifySink_OnRequestEdit ( IPropertyNotifySink iface,
DISPID  dispID 
)
static

Definition at line 322 of file xmlhttprequest.c.

323 {
324  ok(0, "unexpected call\n");
325  return E_NOTIMPL;
326 }
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ PropertyNotifySink_QueryInterface()

static HRESULT WINAPI PropertyNotifySink_QueryInterface ( IPropertyNotifySink iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 282 of file xmlhttprequest.c.

284 {
286  *ppv = iface;
287  return S_OK;
288  }
289 
290  ok(0, "unexpected call\n");
291  return E_NOINTERFACE;
292 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
const GUID IID_IPropertyNotifySink
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021

◆ PropertyNotifySink_Release()

static ULONG WINAPI PropertyNotifySink_Release ( IPropertyNotifySink iface)
static

Definition at line 299 of file xmlhttprequest.c.

300 {
301  return 1;
302 }

◆ pump_msgs()

static void pump_msgs ( BOOL b)
static

Definition at line 357 of file xmlhttprequest.c.

358 {
359  MSG msg;
360 
361  if(b) {
362  while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
365  }
366  }else {
367  while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
370  }
371  }
372 }
BOOL WINAPI TranslateMessage(_In_ const MSG *)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
smooth NULL
Definition: ftsmooth.c:416
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1182

Referenced by create_doc_from_url(), and test_async_xhr().

◆ START_TEST()

START_TEST ( xmlhttprequest  )

Definition at line 909 of file xmlhttprequest.c.

910 {
911  IHTMLDocument2 *doc;
912  static const char start_url[] = "http://test.winehq.org/tests/hello.html";
913  static const char xml_url[] = "http://test.winehq.org/tests/xmltest.xml";
914  static const char large_page_url[] = "http://test.winehq.org/tests/data.php";
915  static const char expect_response_text[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
916 
918 
919  content_type = a2bstr("Content-Type");
920  doc = create_doc_from_url(start_url);
921  if(doc) {
922  test_sync_xhr(doc, xml_url, expect_response_text);
923  test_sync_xhr(doc, large_page_url, NULL);
924  test_async_xhr(doc, xml_url, expect_response_text);
925  test_async_xhr(doc, large_page_url, NULL);
926  test_async_xhr_abort(doc, large_page_url);
927  IHTMLDocument2_Release(doc);
928  }
930 
931  CoUninitialize();
932 }
static IHTMLDocument2 * create_doc_from_url(const char *start_url)
static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
smooth NULL
Definition: ftsmooth.c:416
static BSTR content_type
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)

◆ strcmp_wa()

static int strcmp_wa ( LPCWSTR  strw,
const char stra 
)
static

Definition at line 33 of file xmlhttprequest.c.

34 {
35  CHAR buf[512];
36  WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
37  return lstrcmpA(stra, buf);
38 }
#define WideCharToMultiByte
Definition: compat.h:101
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
int WINAPI lstrcmpA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:18
smooth NULL
Definition: ftsmooth.c:416
static const char * strw(LPCWSTR x)
Definition: actctx.c:49

Referenced by PropertyNotifySink_OnChanged(), test_async_xhr(), test_header(), and test_sync_xhr().

◆ test_async_xhr()

static void test_async_xhr ( IHTMLDocument2 *  doc,
const char xml_url,
const char expect_text 
)
static

Definition at line 611 of file xmlhttprequest.c.

612 {
613  VARIANT vbool, vempty, var;
614  BSTR method, url;
615  BSTR text;
616  LONG val;
617  HRESULT hres;
618  static const struct HEADER_TYPE expect_headers[] = {
619  {"Content-Length", "51"},
620  {"Content-Type", "application/xml"}
621  };
622 
624  if(!xhr)
625  return;
626 
627  V_VT(&var) = VT_DISPATCH;
629  hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
630  ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
631 
632  V_VT(&var) = VT_EMPTY;
633  hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
634  ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
635  ok(V_VT(&var) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
636  ok(V_DISPATCH(&var) == (IDispatch*)&xmlhttprequest_onreadystatechange_obj, "unexpected onreadystatechange value\n");
637 
638  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, NULL, &text);
639  ok(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
640 
641  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, NULL);
642  ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
643 
644  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, NULL, NULL);
645  ok(hres == E_POINTER || broken(hres == E_INVALIDARG), /* Vista and before */
646  "Expect E_POINTER, got %08x\n", hres);
647 
648  text = (BSTR)0xdeadbeef;
649  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
650  ok(hres == E_FAIL, "got %08x\n", hres);
651  ok(text == NULL, "text = %p\n", text);
652 
653  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, NULL);
654  ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
655 
656  text = (BSTR)0xdeadbeef;
657  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
658  ok(hres == E_FAIL, "got %08x\n", hres);
659  ok(text == NULL, "text = %p\n", text);
660 
661  val = 0xdeadbeef;
662  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
663  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
664  ok(val == 0, "Expect 0, got %d\n", val);
665 
666  text = (BSTR)0xdeadbeef;
667  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
668  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
669  ok(text == NULL, "Expect NULL, got %p\n", text);
670 
671  val = 0xdeadbeef;
672  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
673  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
674  ok(val == 0, "Expect UNSENT, got %d\n", val);
675 
676  method = a2bstr("GET");
677  url = a2bstr(xml_url);
678  V_VT(&vbool) = VT_BOOL;
679  V_BOOL(&vbool) = VARIANT_TRUE;
680  V_VT(&vempty) = VT_EMPTY;
681 
682  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
683  hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
684  ok(hres == S_OK, "open failed: %08x\n", hres);
685  CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
686 
689 
690  if(FAILED(hres)) {
691  IHTMLXMLHttpRequest_Release(xhr);
692  xhr = NULL;
693  return;
694  }
695 
696  text = (BSTR)0xdeadbeef;
697  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
698  ok(hres == E_FAIL, "got %08x\n", hres);
699  ok(text == NULL, "text = %p\n", text);
700 
701  text = (BSTR)0xdeadbeef;
702  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
703  ok(hres == E_FAIL, "got %08x\n", hres);
704  ok(text == NULL, "text = %p\n", text);
705 
706  val = 0xdeadbeef;
707  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
708  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
709  ok(val == 0, "Expect 0, got %d\n", val);
710 
711  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
712  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
713  ok(text == NULL, "Expect NULL, got %p\n", text);
714 
715  val = 0xdeadbeef;
716  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
717  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
718  ok(val == 1, "Expect OPENED, got %d\n", val);
719 
720  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
721  SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
722  SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
723  SET_EXPECT(xmlhttprequest_onreadystatechange_done);
724  loading_cnt = 0;
725  hres = IHTMLXMLHttpRequest_send(xhr, vempty);
726 
727  ok(hres == S_OK, "send failed: %08x\n", hres);
728  if(SUCCEEDED(hres))
729  pump_msgs(&called_xmlhttprequest_onreadystatechange_done);
730  todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
731  CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
732  CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
733  CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
734  /* Workaround for loading large files */
735  if(expect_text)
736  ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
737  else
738  todo_wine ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
739 
740  if(FAILED(hres)) {
741  IHTMLXMLHttpRequest_Release(xhr);
742  xhr = NULL;
743  return;
744  }
745 
746  text = NULL;
747  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
748  ok(hres == S_OK, "getAllResponseHeader failed, got %08x\n", hres);
749  ok(text != NULL, "text == NULL\n");
751 
752  if(expect_text)
753  test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
754 
755  val = 0xdeadbeef;
756  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
757  ok(hres == S_OK, "get_status failed: %08x\n", hres);
758  ok(val == 200, "Expect 200, got %d\n", val);
759 
760  text = NULL;
761  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
762  ok(hres == S_OK, "get_statusText failed: %08x\n", hres);
763  ok(text != NULL, "text == NULL\n");
764  ok(!strcmp_wa(text, "OK"), "Expected \"OK\", got %s\n", wine_dbgstr_w(text));
766 
767  val = 0xdeadbeef;
768  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
769  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
770  ok(val == 4, "Expect DONE, got %d\n", val);
771 
772  text = NULL;
773  hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
774  ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
775  ok(text != NULL, "test == NULL\n");
776  if(expect_text)
777  ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
778  expect_text, wine_dbgstr_w(text));
780 
781  IHTMLXMLHttpRequest_Release(xhr);
782  xhr = NULL;
783 }
static IHTMLXMLHttpRequest * xhr
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
const WCHAR * text
Definition: package.c:1827
OLECHAR * BSTR
Definition: compat.h:1934
#define CHECK_CALLED(func)
#define E_FAIL
Definition: ddrawi.h:102
static int loading_cnt
#define V_DISPATCH(A)
Definition: oleauto.h:239
long LONG
Definition: pedump.c:60
#define E_INVALIDARG
Definition: ddrawi.h:101
#define SET_EXPECT(func)
smooth NULL
Definition: ftsmooth.c:416
static void create_xmlhttprequest(IHTMLDocument2 *doc)
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
static void pump_msgs(BOOL *b)
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR url[]
Definition: encode.c:1432
static int strcmp_wa(LPCWSTR strw, const char *stra)
#define V_BOOL(A)
Definition: oleauto.h:224
method
Definition: dragdrop.c:53
#define todo_wine
Definition: test.h:154
#define V_VT(A)
Definition: oleauto.h:211
static IDispatchEx xmlhttprequest_onreadystatechange_obj
static BSTR content_type
#define broken(x)
Definition: _sntprintf.h:21
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static void test_header(const struct HEADER_TYPE expect[], int num)
#define E_POINTER
Definition: winerror.h:2365
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ test_async_xhr_abort()

static void test_async_xhr_abort ( IHTMLDocument2 *  doc,
const char xml_url 
)
static

Definition at line 785 of file xmlhttprequest.c.

786 {
787  VARIANT vbool, vempty, var;
788  BSTR method, url;
789  LONG val;
790  HRESULT hres;
791 
792  method = a2bstr("GET");
793  url = a2bstr(xml_url);
794  V_VT(&vbool) = VT_BOOL;
795  V_BOOL(&vbool) = VARIANT_TRUE;
796  V_VT(&vempty) = VT_EMPTY;
797 
798  trace("abort before send() is fired\n");
800  if(!xhr)
801  return;
802 
803  V_VT(&var) = VT_DISPATCH;
805  hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
806 
807  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
808  hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
809  ok(hres == S_OK, "open failed: %08x\n", hres);
810  CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
811 
812  hres = IHTMLXMLHttpRequest_abort(xhr);
813  ok(hres == S_OK, "abort failed: %08x\n", hres);
814 
815  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
816  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
817  ok(val == 0, "Expect 0, got %d\n", val);
818 
819  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
820  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
821  ok(val == 0, "Expect UNSENT, got %d\n", val);
822 
823  IHTMLXMLHttpRequest_Release(xhr);
824  xhr = NULL;
825 
826  trace("abort after send() is fired\n");
828  V_VT(&var) = VT_DISPATCH;
830  hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
831 
832  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
833  hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
834  ok(hres == S_OK, "open failed: %08x\n", hres);
835  CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
836 
837  loading_cnt = 0;
839  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
840  SET_EXPECT(xmlhttprequest_onreadystatechange_done);
841  hres = IHTMLXMLHttpRequest_send(xhr, vempty);
842  ok(hres == S_OK, "send failed: %08x\n", hres);
843  todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
844 
845  hres = IHTMLXMLHttpRequest_abort(xhr);
846  ok(hres == S_OK, "abort failed: %08x\n", hres);
847  CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
848 
849  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
850  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
851  ok(val == 0, "Expect UNSENT, got %d\n", val);
852 
853  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
854  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
855  ok(val == 0, "Expect 0, got %d\n", val);
856 
857  ok(loading_cnt == 0, "loading_cnt = %d, expect 0, loading_cnt\n", loading_cnt);
858  todo_wine ok(readystatechange_cnt == 2, "readystatechange_cnt = %d, expect 2\n", readystatechange_cnt);
859 
860  IHTMLXMLHttpRequest_Release(xhr);
861  xhr = NULL;
862 
865 }
static IHTMLXMLHttpRequest * xhr
static int readystatechange_cnt
OLECHAR * BSTR
Definition: compat.h:1934
#define CHECK_CALLED(func)
#define E_FAIL
Definition: ddrawi.h:102
static int loading_cnt
#define V_DISPATCH(A)
Definition: oleauto.h:239
long LONG
Definition: pedump.c:60
#define SET_EXPECT(func)
smooth NULL
Definition: ftsmooth.c:416
static void create_xmlhttprequest(IHTMLDocument2 *doc)
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
#define trace
Definition: atltest.h:70
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR url[]
Definition: encode.c:1432
#define V_BOOL(A)
Definition: oleauto.h:224
method
Definition: dragdrop.c:53
#define todo_wine
Definition: test.h:154
#define V_VT(A)
Definition: oleauto.h:211
static IDispatchEx xmlhttprequest_onreadystatechange_obj
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274

Referenced by START_TEST().

◆ test_header()

static void test_header ( const struct HEADER_TYPE  expect[],
int  num 
)
static

Definition at line 416 of file xmlhttprequest.c.

417 {
418  int i;
419  BSTR key, text, all_header;
420  HRESULT hres;
421  char all[4096], buf[512];
422 
423  all_header = NULL;
424  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &all_header);
425  ok(hres == S_OK, "getAllResponseHeader failed: %08x\n", hres);
426  ok(all_header != NULL, "all_header == NULL\n");
427 
428  WideCharToMultiByte(CP_UTF8, 0, all_header, -1, all, sizeof(all), NULL, NULL);
429  SysFreeString(all_header);
430 
431  for(i = 0; i < num; ++i) {
432  text = NULL;
433  key = a2bstr(expect[i].key);
434  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, key, &text);
435  ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
436  ok(text != NULL, "text == NULL\n");
438  "Expect %s: %s, got %s\n", expect[i].key, expect[i].value, wine_dbgstr_w(text));
441 
442  strcpy(buf, expect[i].key);
443  strcat(buf, ": ");
444  strcat(buf, expect[i].value);
445  ok(strstr(all, buf) != NULL, "AllResponseHeaders(%s) don't have expected substr(%s)\n", all, buf);
446  }
447 }
static IHTMLXMLHttpRequest * xhr
#define WideCharToMultiByte
Definition: compat.h:101
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
const WCHAR * text
Definition: package.c:1827
OLECHAR * BSTR
Definition: compat.h:1934
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CP_UTF8
Definition: nls.h:20
smooth NULL
Definition: ftsmooth.c:416
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
static int strcmp_wa(LPCWSTR strw, const char *stra)
GLuint GLuint num
Definition: glext.h:9618
HKEY key
Definition: reg.c:42
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define expect(expected, got)
Definition: combo.c:36
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
Definition: path.c:42

Referenced by test_async_xhr(), and test_sync_xhr().

◆ test_sync_xhr()

static void test_sync_xhr ( IHTMLDocument2 *  doc,
const char xml_url,
const char expect_text 
)
static

Definition at line 449 of file xmlhttprequest.c.

450 {
451  VARIANT vbool, vempty, var;
452  BSTR method, url;
453  BSTR text;
454  LONG val;
455  HRESULT hres;
456  static const struct HEADER_TYPE expect_headers[] = {
457  {"Server", "Apache"},
458  {"Accept-Ranges", "bytes"},
459  {"Content-Length", "51"},
460  {"Content-Type", "application/xml"}
461  };
462 
464  if(!xhr)
465  return;
466 
467  V_VT(&var) = VT_EMPTY;
468  hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
469  ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
470  ok(V_VT(&var) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
471 
472  V_VT(&var) = VT_DISPATCH;
474  hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
475  ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
476 
477  V_VT(&var) = VT_EMPTY;
478  hres = IHTMLXMLHttpRequest_get_onreadystatechange(xhr, &var);
479  ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
480  ok(V_VT(&var) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&var));
481  ok(V_DISPATCH(&var) == (IDispatch*)&xmlhttprequest_onreadystatechange_obj, "unexpected onreadystatechange value\n");
482 
483  hres = IHTMLXMLHttpRequest_get_readyState(xhr, NULL);
484  ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
485 
486  val = 0xdeadbeef;
487  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
488  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
489  ok(val == 0, "Expect UNSENT, got %d\n", val);
490 
491  hres = IHTMLXMLHttpRequest_get_status(xhr, NULL);
492  ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
493 
494  val = 0xdeadbeef;
495  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
496  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
497  ok(val == 0, "Expect 0, got %d\n", val);
498 
499  hres = IHTMLXMLHttpRequest_get_statusText(xhr, NULL);
500  ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
501 
502  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
503  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
504  ok(text == NULL, "Expect NULL, got %p\n", text);
505 
506  text = (BSTR)0xdeadbeef;
507  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
508  ok(hres == E_FAIL, "got %08x\n", hres);
509  ok(text == NULL, "text = %p\n", text);
510 
511  text = (BSTR)0xdeadbeef;
512  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
513  ok(hres == E_FAIL, "got %08x\n", hres);
514  ok(text == NULL, "text = %p\n", text);
515 
516  method = a2bstr("GET");
517  url = a2bstr(xml_url);
518  V_VT(&vbool) = VT_BOOL;
519  V_BOOL(&vbool) = VARIANT_FALSE;
520  V_VT(&vempty) = VT_EMPTY;
521 
522  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
523  hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
524  todo_wine ok(hres == S_OK, "open failed: %08x\n", hres); /* Gecko 30+ only supports async */
525  todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
526 
529 
530  if(FAILED(hres)) {
531  IHTMLXMLHttpRequest_Release(xhr);
532  xhr = NULL;
533  return;
534  }
535 
536  text = (BSTR)0xdeadbeef;
537  hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text);
538  ok(hres == E_FAIL, "got %08x\n", hres);
539  ok(text == NULL, "text = %p\n", text);
540 
541  text = (BSTR)0xdeadbeef;
542  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
543  ok(hres == E_FAIL, "got %08x\n", hres);
544  ok(text == NULL, "text = %p\n", text);
545 
546  val = 0xdeadbeef;
547  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
548  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
549  ok(val == 0, "Expect 0, got %d\n", val);
550 
551  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
552  ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
553  ok(text == NULL, "Expect NULL, got %p\n", text);
554 
555  val = 0xdeadbeef;
556  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
557  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
558  ok(val == 1, "Expect OPENED, got %d\n", val);
559 
560  SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
561  SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
562  SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
563  SET_EXPECT(xmlhttprequest_onreadystatechange_done);
564  loading_cnt = 0;
565  hres = IHTMLXMLHttpRequest_send(xhr, vempty);
566  ok(hres == S_OK, "send failed: %08x\n", hres);
567  CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
568  CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
569  CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
570  CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
571  ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
572 
573  text = NULL;
574  hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
575  ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
576  ok(text != NULL, "text == NULL\n");
578 
579  if(expect_text)
580  test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
581 
582  val = 0xdeadbeef;
583  hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
584  ok(hres == S_OK, "get_status failed: %08x\n", hres);
585  ok(val == 200, "Expect 200, got %d\n", val);
586 
587  hres = IHTMLXMLHttpRequest_get_statusText(xhr, &text);
588  ok(hres == S_OK, "get_statusText failed: %08x\n", hres);
589  ok(text != NULL, "text == NULL\n");
590  ok(!strcmp_wa(text, "OK"),
591  "Expected \"OK\", got %s\n", wine_dbgstr_w(text));
593 
594  val = 0xdeadbeef;
595  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
596  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
597  ok(val == 4, "Expect DONE, got %d\n", val);
598 
599  hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
600  ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
601  ok(text != NULL, "test == NULL\n");
602  if(expect_text)
603  ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
604  expect_text, wine_dbgstr_w(text));
606 
607  IHTMLXMLHttpRequest_Release(xhr);
608  xhr = NULL;
609 }
static IHTMLXMLHttpRequest * xhr
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
const WCHAR * text
Definition: package.c:1827
OLECHAR * BSTR
Definition: compat.h:1934
#define CHECK_CALLED(func)
#define E_FAIL
Definition: ddrawi.h:102
static int loading_cnt
#define V_DISPATCH(A)
Definition: oleauto.h:239
long LONG
Definition: pedump.c:60
#define SET_EXPECT(func)
smooth NULL
Definition: ftsmooth.c:416
static void create_xmlhttprequest(IHTMLDocument2 *doc)
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR url[]
Definition: encode.c:1432
static int strcmp_wa(LPCWSTR strw, const char *stra)
#define V_BOOL(A)
Definition: oleauto.h:224
method
Definition: dragdrop.c:53
#define todo_wine
Definition: test.h:154
#define V_VT(A)
Definition: oleauto.h:211
static IDispatchEx xmlhttprequest_onreadystatechange_obj
static BSTR content_type
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static BSTR a2bstr(const char *str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
static void test_header(const struct HEADER_TYPE expect[], int num)
#define E_POINTER
Definition: winerror.h:2365

Referenced by START_TEST().

◆ xmlhttprequest_onreadystatechange()

static HRESULT WINAPI xmlhttprequest_onreadystatechange ( IDispatchEx *  iface,
DISPID  id,
LCID  lcid,
WORD  wFlags,
DISPPARAMS *  pdp,
VARIANT pvarRes,
EXCEPINFO *  pei,
IServiceProvider pspCaller 
)
static

Definition at line 228 of file xmlhttprequest.c.

230 {
231  LONG val;
232  HRESULT hres;
233 
234  test_event_args(&DIID_DispHTMLXMLHttpRequest, id, wFlags, pdp, pvarRes, pei, pspCaller);
235 
236  hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
237  ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
239 
240  switch(val) {
241  case 1:
242  CHECK_EXPECT(xmlhttprequest_onreadystatechange_opened);
243  break;
244  case 2:
245  CHECK_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
246  break;
247  case 3:
248  loading_cnt++;
249  CHECK_EXPECT2(xmlhttprequest_onreadystatechange_loading);
250  break;
251  case 4:
252  CHECK_EXPECT(xmlhttprequest_onreadystatechange_done);
253  break;
254  default:
255  ok(0, "unexpected readyState: %d\n", val);
256  }
257  return S_OK;
258 }
static IHTMLXMLHttpRequest * xhr
static int readystatechange_cnt
static int loading_cnt
long LONG
Definition: pedump.c:60
GLuint GLfloat * val
Definition: glext.h:7180
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:519
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
#define CHECK_EXPECT(func)
#define test_event_args(a, b, c, d, e, f, g)
#define CHECK_EXPECT2(func)

Variable Documentation

◆ content_type

◆ doc_complete

BOOL doc_complete
static

Definition at line 279 of file xmlhttprequest.c.

Referenced by create_doc_from_url(), and PropertyNotifySink_OnChanged().

◆ loading_cnt

int loading_cnt = 0
static

◆ notif_doc

IHTMLDocument2* notif_doc
static

Definition at line 280 of file xmlhttprequest.c.

Referenced by create_doc_from_url(), and PropertyNotifySink_OnChanged().

◆ PropertyNotifySink

IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl }
static

Definition at line 336 of file xmlhttprequest.c.

Referenced by create_doc_from_url().

◆ PropertyNotifySinkVtbl

IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
static
Initial value:
= {
}
static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface, REFIID riid, void **ppv)
static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)

Definition at line 328 of file xmlhttprequest.c.

◆ readystatechange_cnt

int readystatechange_cnt = 0
static

Definition at line 68 of file xmlhttprequest.c.

Referenced by test_async_xhr_abort(), and xmlhttprequest_onreadystatechange().

◆ xhr

◆ xmlhttprequest_onreadystatechange_obj

IDispatchEx xmlhttprequest_onreadystatechange_obj = { &xmlhttprequest_onreadystatechangeFuncVtbl }
static

Definition at line 277 of file xmlhttprequest.c.

Referenced by test_async_xhr(), test_async_xhr_abort(), and test_sync_xhr().

◆ xmlhttprequest_onreadystatechangeFuncVtbl

IDispatchExVtbl xmlhttprequest_onreadystatechangeFuncVtbl
static
Initial value:
= {
}
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)

Definition at line 260 of file xmlhttprequest.c.