gecko/content/base/test/test_bug482935.html
Bobby Holley 9f03f90fb7 Bug 792036 - Automated fixups. r=mccr8
find /files/mozilla/build/d/_tests/testing/mochitest/tests/ | egrep "\.(xhtml|html|xml|js)$" | grep -v SimpleTest | grep -vi mochikit | grep -v simpleThread | grep -v test_ipc_messagemanager_blob.html | grep -v "indexedDB/test" | xargs grep -l Components |  xargs grep -L enablePrivilege | perl -pe 's#.*mochitest/tests/##' | xargs perl -p -i.bakkk -e 's/Components\.interfaces(\s|;|\.|\[)/SpecialPowers\.Ci$1/g, s/SpecialPowers\.wrap\(Components\)\.(.)(lasses|tils|nterfaces|esults)/SpecialPowers.C$1/g, s/(?<![\.a-zA-Z])Components/SpecialPowers\.Components/g, s/window\.Components/window\.SpecialPowers\.Components/g'
2012-09-24 14:46:29 +02:00

69 lines
1.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test bug 482935</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" />
</head>
<body onload="onWindowLoad()">
<script class="testbody" type="text/javascript">
var url = "bug482935.sjs";
function clearCache() {
SpecialPowers.Cc["@mozilla.org/network/cache-service;1"].
getService(SpecialPowers.Ci.nsICacheService).
evictEntries(SpecialPowers.Ci.nsICache.STORE_ANYWHERE);
}
// Tests that the response is cached if the request is cancelled
// after it has reached state 4
function testCancelInPhase4() {
clearCache();
// First request - should be loaded from server
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function(e) {
if (xhr.readyState < xhr.DONE) return;
is(xhr.readyState, xhr.DONE, "wrong readyState");
xhr.abort();
SimpleTest.executeSoon(function() {
// This request was cancelled, so the responseText should be empty string
is(xhr.responseText, "", "Expected empty response to cancelled request");
// Second request - should be found in cache
var xhr2 = new XMLHttpRequest();
xhr2.addEventListener("load", function() {
is(xhr2.responseText, "0", "Received fresh value for second request");
SimpleTest.finish();
}, false);
xhr2.open("GET", url);
xhr2.setRequestHeader("X-Request", "1", false);
try { xhr2.send(); }
catch(e) {
is(xhr2.status, "200", "Exception!");
}
});
}, false);
xhr.open("GET", url, true);
xhr.setRequestHeader("X-Request", "0", false);
try { xhr.send(); }
catch(e) {
is("Nothing", "Exception", "Boom: " + e);
}
}
function onWindowLoad() {
testCancelInPhase4();
}
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>