mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 05:35:31 +00:00
a25701a3f7
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'
287 lines
6.5 KiB
HTML
287 lines
6.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=475156
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 475156</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="drive(tests.shift());">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var path = "http://mochi.test:8888/tests/content/base/test/";
|
|
|
|
function fromCache(xhr)
|
|
{
|
|
var ch = SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsICachingChannel);
|
|
return ch.isFromCache();
|
|
}
|
|
|
|
var tests = [
|
|
// First just init the file with an ETag
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs?etag=a1");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
},
|
|
},
|
|
|
|
// Try to load the file the first time regularly, we have to get 200 OK
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), false, "Not coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We get a fresh version of the file");
|
|
is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
|
|
is(xhr.responseText, "a1", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the second time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a1");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
|
|
is(xhr.responseText, "a1", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the third time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a1");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
|
|
is(xhr.responseText, "a1", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Now modify the ETag
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs?etag=a2");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
},
|
|
},
|
|
|
|
// Try to load the file, we have to get 200 OK with the new content
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a2");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), false, "Not coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We get a fresh version of the file");
|
|
is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
|
|
is(xhr.responseText, "a2", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the second time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a2");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
|
|
is(xhr.responseText, "a2", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the third time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a2");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
|
|
is(xhr.responseText, "a2", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Now modify the ETag ones more
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs?etag=a3");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
},
|
|
},
|
|
|
|
// Try to load the file, we have to get 200 OK with the new content
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a3");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), false, "Not coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We get a fresh version of the file");
|
|
is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
|
|
is(xhr.responseText, "a3", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the second time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a3");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
|
|
is(xhr.responseText, "a3", "We got the expected file body");
|
|
},
|
|
},
|
|
|
|
// Try to load the file the third time regularly, we have to get 304 Not Modified
|
|
{
|
|
init: function(xhr)
|
|
{
|
|
xhr.open("GET", path + "bug475156.sjs");
|
|
xhr.setRequestHeader("If-Match", "a3");
|
|
},
|
|
|
|
loading: function(xhr)
|
|
{
|
|
is(fromCache(xhr), true, "Coming from the cache");
|
|
},
|
|
|
|
done: function(xhr)
|
|
{
|
|
is(xhr.status, 200, "We got cached version");
|
|
is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
|
|
is(xhr.responseText, "a3", "We got the expected file body");
|
|
},
|
|
},
|
|
]
|
|
|
|
|
|
function drive(test)
|
|
{
|
|
var xhr = new XMLHttpRequest();
|
|
test.init(xhr);
|
|
xhr.onreadystatechange = function() {
|
|
if (this.readyState == 3) {
|
|
test.loading(this);
|
|
}
|
|
if (this.readyState == 4) {
|
|
test.done(this);
|
|
if (tests.length == 0)
|
|
SimpleTest.finish();
|
|
else
|
|
drive(tests.shift());
|
|
}
|
|
}
|
|
xhr.send();
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|
|
|