2016-08-12 10:09:05 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1268962
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 1268962</title>
|
2019-04-16 06:53:28 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2016-08-12 10:09:05 +03:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1268962">Mozilla Bug 1268962</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 1268962 **/
|
|
|
|
|
|
|
|
function testPrefetchEvent(url, crossorigin, expectLoad) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
var link = document.createElement("LINK");
|
|
|
|
link.setAttribute("rel", "prefetch");
|
|
|
|
link.setAttribute("href", url);
|
|
|
|
if (crossorigin) {
|
|
|
|
link.setAttribute("crossorigin", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
link.addEventListener("load", () => {
|
|
|
|
ok(expectLoad, "not expecting load event for " + url);
|
|
|
|
link.remove();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
link.addEventListener("error", () => {
|
|
|
|
ok(!expectLoad, "not expecting error event for " + url);
|
|
|
|
link.remove();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
document.head.appendChild(link);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCancelPrefetchNotCrash(url) {
|
|
|
|
var ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(SpecialPowers.Ci.nsIIOService);
|
|
|
|
var prefetch = SpecialPowers.Cc["@mozilla.org/prefetch-service;1"].
|
|
|
|
getService(SpecialPowers.Ci.nsIPrefetchService);
|
|
|
|
|
|
|
|
var link = document.createElement("LINK");
|
|
|
|
link.setAttribute("rel", "prefetch");
|
|
|
|
link.setAttribute("href", url);
|
|
|
|
document.head.appendChild(link);
|
|
|
|
|
2017-07-10 16:05:48 +03:00
|
|
|
// Not actually verifying any value, just to ensure cancelPrefetchPreload
|
2016-08-12 10:09:05 +03:00
|
|
|
// won't cause crash.
|
2017-07-10 16:05:48 +03:00
|
|
|
prefetch.cancelPrefetchPreloadURI(ios.newURI(url), link);
|
2016-08-12 10:09:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const SJS_PATH = window.location.pathname.replace(/[^/]+$/, "file_bug1268962.sjs");
|
|
|
|
const SAME_ORIGIN = "http://mochi.test:8888" + SJS_PATH;
|
|
|
|
const CROSS_ORIGIN = "http://example.com" + SJS_PATH;
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2016-11-18 11:33:33 +03:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["network.prefetch-next.aggressive", true]]})
|
2016-08-12 10:09:05 +03:00
|
|
|
|
|
|
|
// test same origin
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?statusCode=200&cacheControl=no-cache", false, false))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?statusCode=404&cacheControl=no-cache", false, false))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", false, true))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", false, false))
|
|
|
|
|
|
|
|
// test cross origin without CORS
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache", false, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache", false, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", false, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", false, true))
|
|
|
|
|
|
|
|
// test cross origin by redirection without CORS
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=200&cacheControl=no-cache", false, true))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=404&cacheControl=no-cache", false, true))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=200&cacheControl=max-age%3D120", false, true))
|
|
|
|
.then(() => testPrefetchEvent(SAME_ORIGIN + "?redirect=crossorigin&statusCode=404&cacheControl=max-age%3D120", false, true))
|
|
|
|
|
|
|
|
// test cross origin with CORS request but no CORS response
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache", true, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache", true, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120", true, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120", true, true))
|
|
|
|
|
|
|
|
// test cross origin with CORS request and CORS response
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=no-cache&allowOrigin=*", true, false))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=no-cache&allowOrigin=*", true, false))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120&allowOrigin=*", true, true))
|
|
|
|
.then(() => testPrefetchEvent(CROSS_ORIGIN + "?statusCode=404&cacheControl=max-age%3D120&allowOrigin=*", true, false))
|
|
|
|
|
|
|
|
// test the crash issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1294159
|
|
|
|
.then(() => testCancelPrefetchNotCrash(SAME_ORIGIN + "?statusCode=200&cacheControl=max-age%3D120"))
|
|
|
|
|
|
|
|
.catch((err) => ok(false, "promise rejected: " + err))
|
|
|
|
.then(() => SimpleTest.finish());
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|