From da610554358bc9cfcdb8c40c2cebc0194a4fcfca Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 11 Nov 2010 23:39:14 +0200 Subject: [PATCH] Bug 608939 - XMLHttpRequest.statusText and getAllResponseHeaders shouldn't throw, r=sicking, a=sicking --HG-- extra : rebase_source : 5dc42964f6a216c4f10127d0ad74fe52674601d7 --- content/base/src/nsXMLHttpRequest.cpp | 20 +++++++++---------- content/base/test/test_CrossSiteXHR.html | 6 +++--- .../base/test/test_CrossSiteXHR_origin.html | 2 +- content/base/test/test_XHR.html | 19 ++++++++++++++++++ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index aebc1cdf6421..34ce73145f71 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -1321,15 +1321,15 @@ nsXMLHttpRequest::GetStatusText(nsACString& aStatusText) nsresult status; mChannel->GetStatus(&status); if (NS_FAILED(status)) { - return NS_ERROR_NOT_AVAILABLE; + return NS_OK; } } } - rv = httpChannel->GetResponseStatusText(aStatusText); + httpChannel->GetResponseStatusText(aStatusText); } - return rv; + return NS_OK; } /* void abort (); */ @@ -1388,23 +1388,21 @@ nsXMLHttpRequest::GetAllResponseHeaders(char **_retval) *_retval = nsnull; if (mState & XML_HTTP_REQUEST_USE_XSITE_AC) { + *_retval = ToNewCString(EmptyString()); return NS_OK; } nsCOMPtr httpChannel = GetCurrentHttpChannel(); if (httpChannel) { - nsHeaderVisitor *visitor = new nsHeaderVisitor(); - if (!visitor) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(visitor); - + nsRefPtr visitor = new nsHeaderVisitor(); nsresult rv = httpChannel->VisitResponseHeaders(visitor); if (NS_SUCCEEDED(rv)) *_retval = ToNewCString(visitor->Headers()); - - NS_RELEASE(visitor); - return rv; + } + + if (!*_retval) { + *_retval = ToNewCString(EmptyString()); } return NS_OK; diff --git a/content/base/test/test_CrossSiteXHR.html b/content/base/test/test_CrossSiteXHR.html index 5e347faafa90..abbf85131927 100644 --- a/content/base/test/test_CrossSiteXHR.html +++ b/content/base/test/test_CrossSiteXHR.html @@ -648,7 +648,7 @@ function runTest() { is(res.didFail, true, "should have failed in test for " + test.toSource()); is(res.status, 0, "wrong status in test for " + test.toSource()); - is(res.statusText, undefined, "wrong status in test for " + test.toSource()); + is(res.statusText, "", "wrong status in test for " + test.toSource()); is(res.responseXML, null, "wrong responseXML in test for " + test.toSource()); is(res.responseText, "", @@ -788,7 +788,7 @@ function runTest() { is(res.didFail, true, "should have failed in test for " + test.toSource()); is(res.status, 0, "wrong status in test for " + test.toSource()); - is(res.statusText, undefined, "wrong status in test for " + test.toSource()); + is(res.statusText, "", "wrong status in test for " + test.toSource()); is(res.responseXML, null, "wrong responseXML in test for " + test.toSource()); is(res.responseText, "", @@ -1057,7 +1057,7 @@ function runTest() { is(res.didFail, true, "should have failed in test for " + test.toSource()); is(res.status, 0, "wrong status in test for " + test.toSource()); - is(res.statusText, undefined, "wrong status in test for " + test.toSource()); + is(res.statusText, "", "wrong status in test for " + test.toSource()); is(res.responseXML, null, "wrong responseXML in test for " + test.toSource()); is(res.responseText, "", diff --git a/content/base/test/test_CrossSiteXHR_origin.html b/content/base/test/test_CrossSiteXHR_origin.html index 4549697b4eee..aa5bb4933550 100644 --- a/content/base/test/test_CrossSiteXHR_origin.html +++ b/content/base/test/test_CrossSiteXHR_origin.html @@ -149,7 +149,7 @@ function runTest() { is(res.didFail, true, "should have failed for " + allowOrigin); is(res.responseText, "", "should have no text for " + allowOrigin); is(res.status, 0, "should have no status for " + allowOrigin); - is(res.statusText, undefined, "wrong status text for " + allowOrigin); + is(res.statusText, "", "wrong status text for " + allowOrigin); is(res.responseXML, null, "should have no XML for " + allowOrigin); is(res.events.join(","), "opening,rs1,sending,rs1,loadstart,rs2,rs4,error", diff --git a/content/base/test/test_XHR.html b/content/base/test/test_XHR.html index e727372957f6..ce5af69d161a 100644 --- a/content/base/test/test_XHR.html +++ b/content/base/test/test_XHR.html @@ -90,6 +90,25 @@ ok(u8v[0] == 0xaa && u8v[1] == 0xee && u8v[2] == 0x00 && u8v[3] == 0x03, "wrong is(i32v[1], -1, "wrong value, expected -1 (0xffffffff)"); is(u32v[0], 0xbbbbbbbb, "wrong value, expected 0xbbbbbbbb"); +var client = new XMLHttpRequest(); +client.onreadystatechange = function() { + if(client.readyState == 4) { + try { + is(client.responseXML, null, "responseXML should be null."); + is(client.responseText, "", "responseText should be empty string."); + is(client.status, 0, "status should be 0."); + is(client.statusText, "", "statusText should be empty string."); + is(client.getAllResponseHeaders(), "", + "getAllResponseHeaders() should return empty string."); + } catch(ex) { + ok(false, "Shouldn't throw! [" + ex + "]"); + } + } + } +client.open("GET", "file_XHR_pass1.xml", true); +client.send(); +client.abort(); +