Module: wine Branch: master Commit: 8c00ee2ac69b44d082023d3af9e477a08ec60ccf URL: http://source.winehq.org/git/wine.git/?a=commit;h=8c00ee2ac69b44d082023d3af9...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Apr 7 15:33:44 2016 +0200
mshtml: Added more IHTMLXMLHttpRequst::send tests.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/mshtml/tests/xmlhttprequest.c | 143 ++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 43 deletions(-)
diff --git a/dlls/mshtml/tests/xmlhttprequest.c b/dlls/mshtml/tests/xmlhttprequest.c index e1c2ef1..df5d644 100644 --- a/dlls/mshtml/tests/xmlhttprequest.c +++ b/dlls/mshtml/tests/xmlhttprequest.c @@ -573,6 +573,47 @@ static void test_responseXML(const char *expect_text) IDispatch_Release(disp); }
+#define xhr_open(a,b) _xhr_open(__LINE__,a,b) +static HRESULT _xhr_open(unsigned line, const char *url_a, const char *method_a) +{ + BSTR method = a2bstr(method_a); + BSTR url = a2bstr(url_a); + VARIANT async, empty; + HRESULT hres; + + V_VT(&async) = VT_BOOL; + V_BOOL(&async) = VARIANT_TRUE; + V_VT(&empty) = VT_EMPTY; + + hres = IHTMLXMLHttpRequest_open(xhr, method, url, async, empty, empty); + ok_(__FILE__,line)(hres == S_OK, "open failed: %08x\n", hres); + + SysFreeString(method); + SysFreeString(url); + return hres; +} + +#define test_response_text(a) _test_response_text(__LINE__,a) +static void _test_response_text(unsigned line, const char *expect_text) +{ + BSTR text = NULL; + HRESULT hres; + + hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text); + ok(hres == S_OK, "get_responseText failed: %08x\n", hres); + ok(text != NULL, "test == NULL\n"); + if(expect_text) { + unsigned len; + /* Some recent version of IE strip trailing '\n' from post.php response, while others don't. */ + len = SysStringLen(text); + if(text[len-1] == '\n') + text[len-1] = 0; + ok_(__FILE__,line)(!strcmp_wa(text, expect_text), "expect %s, got %s\n", + expect_text, wine_dbgstr_w(text)); + } + SysFreeString(text); +} + static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text) { VARIANT vbool, vempty, var; @@ -725,14 +766,7 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char * ok(hres == S_OK, "get_readyState failed: %08x\n", hres); ok(val == 4, "Expect DONE, got %d\n", val);
- hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text); - ok(hres == S_OK, "get_responseText failed: %08x\n", hres); - ok(text != NULL, "test == NULL\n"); - if(expect_text) - ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n", - expect_text, wine_dbgstr_w(text)); - SysFreeString(text); - + test_response_text(expect_text); test_responseXML(expect_text);
IHTMLXMLHttpRequest_Release(xhr); @@ -741,8 +775,7 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *
static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text) { - VARIANT vbool, vempty, var; - BSTR method, url; + VARIANT var, vempty; BSTR text; LONG val; HRESULT hres; @@ -804,20 +837,10 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char ok(hres == S_OK, "get_readyState failed: %08x\n", hres); ok(val == 0, "Expect UNSENT, got %d\n", val);
- method = a2bstr("GET"); - url = a2bstr(xml_url); - V_VT(&vbool) = VT_BOOL; - V_BOOL(&vbool) = VARIANT_TRUE; - V_VT(&vempty) = VT_EMPTY; - SET_EXPECT(xmlhttprequest_onreadystatechange_opened); - hres = IHTMLXMLHttpRequest_open(xhr, method, url, vbool, vempty, vempty); - ok(hres == S_OK, "open failed: %08x\n", hres); + hres = xhr_open(xml_url, "GET"); CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
- SysFreeString(method); - SysFreeString(url); - if(FAILED(hres)) { IHTMLXMLHttpRequest_Release(xhr); xhr = NULL; @@ -855,6 +878,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char SET_EXPECT(xmlhttprequest_onreadystatechange_loading); SET_EXPECT(xmlhttprequest_onreadystatechange_done); loading_cnt = 0; + V_VT(&vempty) = VT_EMPTY; hres = IHTMLXMLHttpRequest_send(xhr, vempty);
ok(hres == S_OK, "send failed: %08x\n", hres); @@ -900,15 +924,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char ok(hres == S_OK, "get_readyState failed: %08x\n", hres); ok(val == 4, "Expect DONE, got %d\n", val);
- text = NULL; - hres = IHTMLXMLHttpRequest_get_responseText(xhr, &text); - ok(hres == S_OK, "get_responseText failed: %08x\n", hres); - ok(text != NULL, "test == NULL\n"); - if(expect_text) - ok(!strcmp_wa(text, expect_text), "expect %s, got %s\n", - expect_text, wine_dbgstr_w(text)); - SysFreeString(text); - + test_response_text(expect_text); test_responseXML(expect_text);
IHTMLXMLHttpRequest_Release(xhr); @@ -917,15 +933,10 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char
static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url) { - VARIANT vbool, vempty, var; - BSTR method, url; + VARIANT vempty, var; 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"); @@ -938,8 +949,7 @@ static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url) 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); + xhr_open(xml_url, "GET"); CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_abort(xhr); @@ -963,8 +973,7 @@ static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url) 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); + xhr_open(xml_url, "GET"); CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
loading_cnt = 0; @@ -992,9 +1001,56 @@ static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
IHTMLXMLHttpRequest_Release(xhr); xhr = NULL; +}
- SysFreeString(method); - SysFreeString(url); +static void test_xhr_post(IHTMLDocument2 *doc) +{ + VARIANT v; + HRESULT hres; + + trace("send string...\n"); + + create_xmlhttprequest(doc); + if(!xhr) + return; + + V_VT(&v) = VT_DISPATCH; + V_DISPATCH(&v) = (IDispatch*)&xmlhttprequest_onreadystatechange_obj; + hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, v); + ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres); + + SET_EXPECT(xmlhttprequest_onreadystatechange_opened); + xhr_open("http://test.winehq.org/tests/post.php", "POST"); + CHECK_CALLED(xmlhttprequest_onreadystatechange_opened); + + set_request_header(xhr, "Content-Type", "application/x-www-form-urlencoded"); + + V_VT(&v) = VT_BSTR; + V_BSTR(&v) = a2bstr("X=Testing"); + + loading_cnt = 0; + SET_EXPECT(xmlhttprequest_onreadystatechange_opened); + SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received); + SET_EXPECT(xmlhttprequest_onreadystatechange_loading); + SET_EXPECT(xmlhttprequest_onreadystatechange_done); + + hres = IHTMLXMLHttpRequest_send(xhr, v); + ok(hres == S_OK, "send failed: %08x\n", hres); + if(SUCCEEDED(hres)) + pump_msgs(&called_xmlhttprequest_onreadystatechange_done); + + todo_wine CHECK_CALLED(xmlhttprequest_onreadystatechange_opened); + CHECK_CALLED(xmlhttprequest_onreadystatechange_headers_received); + CHECK_CALLED(xmlhttprequest_onreadystatechange_loading); + CHECK_CALLED(xmlhttprequest_onreadystatechange_done); + ok(loading_cnt == 1, "loading_cnt = %d\n", loading_cnt); + + SysFreeString(V_BSTR(&v)); + + test_response_text("X => Testing"); + + IHTMLXMLHttpRequest_Release(xhr); + xhr = NULL; }
static IHTMLDocument2 *create_doc_from_url(const char *start_url) @@ -1045,7 +1101,7 @@ START_TEST(xmlhttprequest) 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 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"; + static const char expect_response_text[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>";
CoInitialize(NULL);
@@ -1057,6 +1113,7 @@ START_TEST(xmlhttprequest) 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); + test_xhr_post(doc); IHTMLDocument2_Release(doc); } SysFreeString(content_type);