Bug 1011748 - Added logic to GetStatusText to ensure the statusText value is available after all redirects (if any) have been followed. Added mochitest unit test which is disabled for b2g and e10. r=bzbarsky

This commit is contained in:
Michael A. Milazzo 2014-06-24 23:33:03 -07:00
parent 68704f422f
commit 0c7f378d31
5 changed files with 80 additions and 1 deletions

View File

@ -1171,7 +1171,17 @@ nsXMLHttpRequest::GetStatusText(nsCString& aStatusText)
return;
}
httpChannel->GetResponseStatusText(aStatusText);
// Check the current XHR state to see if it is valid to obtain the statusText
// value. This check is to prevent the status text for redirects from being
// available before all the redirects have been followed and HTTP headers have
// been received.
uint16_t readyState;
GetReadyState(&readyState);
if (readyState != OPENED && readyState != UNSENT) {
httpChannel->GetResponseStatusText(aStatusText);
}
}

View File

@ -0,0 +1,4 @@
// Function to indicate HTTP 200 OK after redirect from file_bug1011748_redirect.sjs
function handleRequest(request, response) {
response.setStatusLine(null, 200, "OK");
}

View File

@ -0,0 +1,5 @@
// SJS handler to redirect the XMLHttpRequest object to file_bug1011748_OK.sjs
function handleRequest(request, response) {
response.setStatusLine(null, 302, "Moved Temporarily");
response.setHeader("Location", "file_bug1011748_OK.sjs", false);
}

View File

@ -646,3 +646,6 @@ support-files = bug444546.sjs
[test_bug503473.html]
disabled = Disabled due to making the harness time out
support-files = file_bug503473-frame.sjs
[test_bug1011748.html]
skip-if = buildapp == 'b2g' || e10s
support-files = file_bug1011748_redirect.sjs file_bug1011748_OK.sjs

View File

@ -0,0 +1,57 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1011748
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1011748</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 1011748 **/
"use strict";
var observer = {
observe: function (aSubject, aTopic, aData) {
try {
var channel = aSubject.QueryInterface(SpecialPowers.Ci.nsIHttpChannel);
channel.getResponseHeader("Location");
} catch (e) {
return;
}
statusTexts.push(xhr.statusText);
}
};
var statusTexts = [];
SpecialPowers.addObserver(observer, "http-on-examine-response", false);
SimpleTest.waitForExplicitFinish();
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function() {
statusTexts.push(this.statusText);
SpecialPowers.removeObserver(observer, "http-on-examine-response");
is(statusTexts[0], "", "Empty statusText value for HTTP 302");
is(statusTexts[1], "OK", "OK statusText value for the redirect.");
SimpleTest.finish();
});
xhr.open("GET", "file_bug1011748_redirect.sjs", true);
xhr.send();
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1011748">Mozilla Bug 1011748</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>