From: Zhenbo Li Subject: [PATCH 3/3] mshtml: Add IHTMLXMLHttpRequest::getAllResponseHeaders() method implementation. Message-Id: <55C1659F.9090605@gmail.com> Date: Wed, 05 Aug 2015 09:23:43 +0800 --- dlls/mshtml/tests/xmlhttprequest.c | 45 +++++++++++++++++++++++++++++++++++++- dlls/mshtml/xmlhttprequest.c | 24 ++++++++++++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/dlls/mshtml/tests/xmlhttprequest.c b/dlls/mshtml/tests/xmlhttprequest.c index 3ee54ac..b7ecb49 100644 --- a/dlls/mshtml/tests/xmlhttprequest.c +++ b/dlls/mshtml/tests/xmlhttprequest.c @@ -421,8 +421,17 @@ static void create_xmlhttprequest(IHTMLDocument2 *doc) static void test_header(const struct HEADER_TYPE expect[], int num) { int i; - BSTR key, text; + BSTR key, text, all_header; HRESULT hres; + char all[4096], buf[512]; + + all_header = NULL; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &all_header); + ok(hres == S_OK, "getAllResponseHeader failed: %08x\n", hres); + ok(all_header != NULL, "all_header == NULL\n"); + + WideCharToMultiByte(CP_UTF8, 0, all_header, -1, all, sizeof(all), NULL, NULL); + SysFreeString(all_header); for(i = 0; i < num; ++i) { text = NULL; @@ -434,6 +443,11 @@ static void test_header(const struct HEADER_TYPE expect[], int num) "Expect %s: %s, got %s\n", expect[i].key, expect[i].value, wine_dbgstr_w(text)); SysFreeString(key); SysFreeString(text); + + strcpy(buf, expect[i].key); + strcat(buf, ": "); + strcat(buf, expect[i].value); + ok(strstr(all, buf) != NULL, "AllResponseHeaders(%s) don't have expected substr(%s)\n", all, buf); } } @@ -495,6 +509,11 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) ok(text == NULL, "Expect NULL, got %p\n", text); text = (BSTR)0xdeadbeef; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text); + ok(hres == E_FAIL, "got %08x\n", hres); + ok(text == NULL, "text = %p\n", text); + + text = (BSTR)0xdeadbeef; hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text); ok(hres == E_FAIL, "got %08x\n", hres); ok(text == NULL, "text = %p\n", text); @@ -520,6 +539,11 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url) } text = (BSTR)0xdeadbeef; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text); + ok(hres == E_FAIL, "got %08x\n", hres); + ok(text == NULL, "text = %p\n", text); + + text = (BSTR)0xdeadbeef; hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text); ok(hres == E_FAIL, "got %08x\n", hres); ok(text == NULL, "text = %p\n", text); @@ -627,6 +651,14 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) ok(hres == E_FAIL, "got %08x\n", hres); ok(text == NULL, "text = %p\n", text); + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, NULL); + ok(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres); + + text = (BSTR)0xdeadbeef; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text); + ok(hres == E_FAIL, "got %08x\n", hres); + ok(text == NULL, "text = %p\n", text); + val = 0xdeadbeef; hres = IHTMLXMLHttpRequest_get_status(xhr, &val); ok(hres == E_FAIL, "Expect E_FAIL, got: %08x\n", hres); @@ -663,6 +695,11 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) } text = (BSTR)0xdeadbeef; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text); + ok(hres == E_FAIL, "got %08x\n", hres); + ok(text == NULL, "text = %p\n", text); + + text = (BSTR)0xdeadbeef; hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text); ok(hres == E_FAIL, "got %08x\n", hres); ok(text == NULL, "text = %p\n", text); @@ -702,6 +739,12 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url) } text = NULL; + hres = IHTMLXMLHttpRequest_getAllResponseHeaders(xhr, &text); + ok(hres == S_OK, "getAllResponseHeader failed, got %08x\n", hres); + ok(text != NULL, "text == NULL\n"); + SysFreeString(text); + + text = NULL; hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, content_type, &text); ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres); ok(text != NULL, "text == NULL\n"); diff --git a/dlls/mshtml/xmlhttprequest.c b/dlls/mshtml/xmlhttprequest.c index 0321944..ea420c3 100644 --- a/dlls/mshtml/xmlhttprequest.c +++ b/dlls/mshtml/xmlhttprequest.c @@ -505,8 +505,28 @@ static HRESULT WINAPI HTMLXMLHttpRequest_send(IHTMLXMLHttpRequest *iface, VARIAN static HRESULT WINAPI HTMLXMLHttpRequest_getAllResponseHeaders(IHTMLXMLHttpRequest *iface, BSTR *p) { HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface); - FIXME("(%p)->(%p)\n", This, p); - return E_NOTIMPL; + nsACString nscstr; + nsresult nsres; + HRESULT hres; + LONG state; + + TRACE("(%p)->(%p)\n", This, p); + + if(!p) + return E_POINTER; + + hres = IHTMLXMLHttpRequest_get_readyState(iface, &state); + if(FAILED(hres)) + return hres; + + if(state < 2) { + *p = NULL; + return E_FAIL; + } + + nsACString_Init(&nscstr, NULL); + nsres = nsIXMLHttpRequest_GetAllResponseHeaders(This->nsxhr, &nscstr); + return return_nscstr(nsres, &nscstr, p); } static HRESULT WINAPI HTMLXMLHttpRequest_getResponseHeader(IHTMLXMLHttpRequest *iface, BSTR bstrHeader, BSTR *p)