Commit b8f8b95e authored by Zhenbo Li's avatar Zhenbo Li Committed by Alexandre Julliard

mshtml: Add IHTMLXMLHttpRequest::abort() method implementation.

parent 3bd0eb3e
...@@ -72,6 +72,8 @@ static int strcmp_wa(LPCWSTR strw, const char *stra) ...@@ -72,6 +72,8 @@ static int strcmp_wa(LPCWSTR strw, const char *stra)
static IHTMLXMLHttpRequest *xhr = NULL; static IHTMLXMLHttpRequest *xhr = NULL;
static BSTR content_type = NULL; static BSTR content_type = NULL;
static int loading_cnt = 0;
static int readystatechange_cnt = 0;
DEFINE_EXPECT(xmlhttprequest_onreadystatechange_opened); DEFINE_EXPECT(xmlhttprequest_onreadystatechange_opened);
DEFINE_EXPECT(xmlhttprequest_onreadystatechange_headers_received); DEFINE_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
...@@ -241,6 +243,7 @@ static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISP ...@@ -241,6 +243,7 @@ static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISP
hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val); hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
ok(hres == S_OK, "get_readyState failed: %08x\n", hres); ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
readystatechange_cnt++;
switch(val) { switch(val) {
case 1: case 1:
...@@ -250,7 +253,8 @@ static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISP ...@@ -250,7 +253,8 @@ static HRESULT WINAPI xmlhttprequest_onreadystatechange(IDispatchEx *iface, DISP
CHECK_EXPECT(xmlhttprequest_onreadystatechange_headers_received); CHECK_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
break; break;
case 3: case 3:
CHECK_EXPECT(xmlhttprequest_onreadystatechange_loading); loading_cnt++;
CHECK_EXPECT2(xmlhttprequest_onreadystatechange_loading);
break; break;
case 4: case 4:
CHECK_EXPECT(xmlhttprequest_onreadystatechange_done); CHECK_EXPECT(xmlhttprequest_onreadystatechange_done);
...@@ -375,7 +379,6 @@ static void pump_msgs(BOOL *b) ...@@ -375,7 +379,6 @@ static void pump_msgs(BOOL *b)
} }
} }
static const char EXPECT_RESPONSE_TEXT[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
struct HEADER_TYPE { struct HEADER_TYPE {
const char *key; const char *key;
...@@ -451,7 +454,7 @@ static void test_header(const struct HEADER_TYPE expect[], int num) ...@@ -451,7 +454,7 @@ static void test_header(const struct HEADER_TYPE expect[], int num)
} }
} }
static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
{ {
VARIANT vbool, vempty, var; VARIANT vbool, vempty, var;
BSTR method, url; BSTR method, url;
...@@ -566,12 +569,14 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -566,12 +569,14 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url)
SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received); SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
SET_EXPECT(xmlhttprequest_onreadystatechange_loading); SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
SET_EXPECT(xmlhttprequest_onreadystatechange_done); SET_EXPECT(xmlhttprequest_onreadystatechange_done);
loading_cnt = 0;
hres = IHTMLXMLHttpRequest_send(xhr, vempty); hres = IHTMLXMLHttpRequest_send(xhr, vempty);
ok(hres == S_OK, "send failed: %08x\n", hres); ok(hres == S_OK, "send failed: %08x\n", hres);
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened); CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received); CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
CHECK_CALLED(xmlhttprequest_onreadystatechange_loading); CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
CHECK_CALLED(xmlhttprequest_onreadystatechange_done); CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
text = NULL; text = NULL;
hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text); hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
...@@ -579,6 +584,7 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -579,6 +584,7 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url)
ok(text != NULL, "text == NULL\n"); ok(text != NULL, "text == NULL\n");
SysFreeString(text); SysFreeString(text);
if(expect_text)
test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0])); test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
val = 0xdeadbeef; val = 0xdeadbeef;
...@@ -601,15 +607,16 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -601,15 +607,16 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url)
hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text); hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
ok(hres == S_OK, "get_responseText failed: %08x\n", hres); ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
ok(text != NULL, "test == NULL\n"); ok(text != NULL, "test == NULL\n");
ok(!strcmp_wa(text, EXPECT_RESPONSE_TEXT), "expect %s, got %s\n", if(expect_text)
EXPECT_RESPONSE_TEXT, wine_dbgstr_w(text)); ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
expect_text, wine_dbgstr_w(text));
SysFreeString(text); SysFreeString(text);
IHTMLXMLHttpRequest_Release(xhr); IHTMLXMLHttpRequest_Release(xhr);
xhr = NULL; xhr = NULL;
} }
static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
{ {
VARIANT vbool, vempty, var; VARIANT vbool, vempty, var;
BSTR method, url; BSTR method, url;
...@@ -722,6 +729,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -722,6 +729,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received); SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
SET_EXPECT(xmlhttprequest_onreadystatechange_loading); SET_EXPECT(xmlhttprequest_onreadystatechange_loading);
SET_EXPECT(xmlhttprequest_onreadystatechange_done); SET_EXPECT(xmlhttprequest_onreadystatechange_done);
loading_cnt = 0;
hres = IHTMLXMLHttpRequest_send(xhr, vempty); hres = IHTMLXMLHttpRequest_send(xhr, vempty);
ok(hres == S_OK, "send failed: %08x\n", hres); ok(hres == S_OK, "send failed: %08x\n", hres);
...@@ -731,6 +739,11 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -731,6 +739,11 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received); CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received);
CHECK_CALLED(xmlhttprequest_onreadystatechange_loading); CHECK_CALLED(xmlhttprequest_onreadystatechange_loading);
CHECK_CALLED(xmlhttprequest_onreadystatechange_done); CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
/* Workaround for loading large files */
if(expect_text)
ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
else
todo_wine ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt);
if(FAILED(hres)) { if(FAILED(hres)) {
IHTMLXMLHttpRequest_Release(xhr); IHTMLXMLHttpRequest_Release(xhr);
...@@ -744,13 +757,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -744,13 +757,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
ok(text != NULL, "text == NULL\n"); ok(text != NULL, "text == NULL\n");
SysFreeString(text); SysFreeString(text);
text = NULL; if(expect_text)
hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text);
ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
ok(text != NULL, "text == NULL\n");
ok(!strcmp_wa(text, "application/xml"), "text = %s\n", wine_dbgstr_w(text));
SysFreeString(text);
test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0])); test_header(expect_headers, sizeof(expect_headers)/sizeof(expect_headers[0]));
val = 0xdeadbeef; val = 0xdeadbeef;
...@@ -774,14 +781,94 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ...@@ -774,14 +781,94 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url)
hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text); hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text);
ok(hres == S_OK, "get_responseText failed: %08x\n", hres); ok(hres == S_OK, "get_responseText failed: %08x\n", hres);
ok(text != NULL, "test == NULL\n"); ok(text != NULL, "test == NULL\n");
ok(!strcmp_wa(text, EXPECT_RESPONSE_TEXT), "expect %s, got %s\n", if(expect_text)
EXPECT_RESPONSE_TEXT, wine_dbgstr_w(text)); ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n",
expect_text, wine_dbgstr_w(text));
SysFreeString(text); SysFreeString(text);
IHTMLXMLHttpRequest_Release(xhr); IHTMLXMLHttpRequest_Release(xhr);
xhr = NULL; xhr = NULL;
} }
static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
{
VARIANT vbool, vempty, var;
BSTR method, url;
LONG val;
HRESULT hres;
method = a2bstr("GET");
url = a2bstr(xml_url);
V_VT(&vbool) = VT_BOOL;
V_BOOL(&vbool) = VARIANT_TRUE;
V_VT(&vempty) = VT_EMPTY;
trace("abort before send() is fired\n");
create_xmlhttprequest(doc);
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
ok(hres == S_OK, "open failed: %08x\n", hres);
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_abort(xhr);
ok(hres == S_OK, "abort failed: %08x\n", hres);
hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
ok(val == 0, "Expect 0, got %d\n", val);
hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
ok(val == 0, "Expect UNSENT, got %d\n", val);
IHTMLXMLHttpRequest_Release(xhr);
xhr = NULL;
trace("abort after send() is fired\n");
create_xmlhttprequest(doc);
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj;
hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty);
ok(hres == S_OK, "open failed: %08x\n", hres);
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
loading_cnt = 0;
readystatechange_cnt = 0;
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
SET_EXPECT(xmlhttprequest_onreadystatechange_done);
hres = IHTMLXMLHttpRequest_send(xhr, vempty);
ok(hres == S_OK, "send failed: %08x\n", hres);
todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_abort(xhr);
ok(hres == S_OK, "abort failed: %08x\n", hres);
CHECK_CALLED(xmlhttprequest_onreadystatechange_done);
hres = IHTMLXMLHttpRequest_get_readyState(xhr, &val);
ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
ok(val == 0, "Expect UNSENT, got %d\n", val);
hres = IHTMLXMLHttpRequest_get_status(xhr, &val);
ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres);
ok(val == 0, "Expect 0, got %d\n", val);
ok(loading_cnt == 0, "loading_cnt = %d, expect 0, loading_cnt\n", loading_cnt);
todo_wine ok(readystatechange_cnt == 2, "readystatechange_cnt = %d, expect 2\n", readystatechange_cnt);
IHTMLXMLHttpRequest_Release(xhr);
xhr = NULL;
SysFreeString(method);
SysFreeString(url);
}
static IHTMLDocument2 *create_doc_from_url(const char *start_url) static IHTMLDocument2 *create_doc_from_url(const char *start_url)
{ {
BSTR url; BSTR url;
...@@ -829,14 +916,19 @@ START_TEST(xmlhttprequest) ...@@ -829,14 +916,19 @@ START_TEST(xmlhttprequest)
IHTMLDocument2 *doc; IHTMLDocument2 *doc;
static const char start_url[] = "http://test.winehq.org/tests/hello.html"; static const char start_url[] = "http://test.winehq.org/tests/hello.html";
static const char xml_url[] = "http://test.winehq.org/tests/xmltest.xml"; static const char xml_url[] = "http://test.winehq.org/tests/xmltest.xml";
static const char large_page_url[] = "http://test.winehq.org/tests/data.php";
static const char expect_response_text[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
CoInitialize(NULL); CoInitialize(NULL);
content_type = a2bstr("Content-Type"); content_type = a2bstr("Content-Type");
doc = create_doc_from_url(start_url); doc = create_doc_from_url(start_url);
if(doc) { if(doc) {
test_sync_xhr(doc, xml_url); test_sync_xhr(doc, xml_url, expect_response_text);
test_async_xhr(doc, xml_url); test_sync_xhr(doc, large_page_url, NULL);
test_async_xhr(doc, xml_url, expect_response_text);
test_async_xhr(doc, large_page_url, NULL);
test_async_xhr_abort(doc, large_page_url);
IHTMLDocument2_Release(doc); IHTMLDocument2_Release(doc);
} }
SysFreeString(content_type); SysFreeString(content_type);
......
...@@ -408,8 +408,17 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_onreadystatechange(IHTMLXMLHttpRequ ...@@ -408,8 +408,17 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_onreadystatechange(IHTMLXMLHttpRequ
static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface) static HRESULT WINAPI HTMLXMLHttpRequest_abort(IHTMLXMLHttpRequest *iface)
{ {
HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface); HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
FIXME("(%p)->()\n", This); nsresult nsres;
return E_NOTIMPL;
TRACE("(%p)->()\n", This);
nsres = nsIXMLHttpRequest_SlowAbort(This->nsxhr);
if(NS_FAILED(nsres)) {
ERR("nsIXMLHttpRequest_SlowAbort failed: %08x\n", nsres);
return E_FAIL;
}
return S_OK;
} }
static HRESULT WINAPI HTMLXMLHttpRequest_open(IHTMLXMLHttpRequest *iface, BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync, VARIANT varUser, VARIANT varPassword) static HRESULT WINAPI HTMLXMLHttpRequest_open(IHTMLXMLHttpRequest *iface, BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync, VARIANT varUser, VARIANT varPassword)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment