2011-07-07 17:12:14 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=669671
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 669671</title>
|
2019-04-16 06:50:44 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2011-07-07 17:12:14 +04: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=669671">Mozilla Bug 669671</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="application/javascript">
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Bug 669671.
|
|
|
|
*
|
|
|
|
* This is a bit complicated. We have a script, file_bug669671.sjs, which counts
|
|
|
|
* how many times it's loaded and returns that count in the body of an HTML
|
|
|
|
* document. For brevity, call this page X.
|
|
|
|
*
|
|
|
|
* X is sent with Cache-Control: max-age=0 and can't be bfcached (it has an
|
|
|
|
* onunload handler). Our test does the following in a popup:
|
|
|
|
*
|
|
|
|
* 1) Load X?pushed, to prime the cache.
|
|
|
|
* 2) Navigate to X.
|
|
|
|
* 3) Call pushState and navigate from X to X?pushed.
|
|
|
|
* 4) Navigate to X?navigated.
|
|
|
|
* 5) Go back (to X?pushed).
|
|
|
|
*
|
|
|
|
* We do all this work so we can check that in step 5, we fetch X?pushed from
|
|
|
|
* the network -- we shouldn't use our cached copy, because of the
|
|
|
|
* cache-control header X sends.
|
|
|
|
*
|
|
|
|
* Then we go back and repeat the whole process but call history.replaceState
|
|
|
|
* instead of pushState. And for good measure, we test once more, this time
|
|
|
|
* modifying only the hash of the URI using replaceState. In this case, we
|
|
|
|
* *should* load from the cache.
|
|
|
|
*
|
|
|
|
**/
|
2015-05-27 19:54:17 +03:00
|
|
|
SimpleTest.requestLongerTimeout(2);
|
2011-07-07 17:12:14 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2019-03-22 21:13:25 +03:00
|
|
|
function onChildLoad() {
|
|
|
|
SimpleTest.executeSoon(function() { gGen.next(); });
|
2011-07-07 17:12:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var _loadCount = 0;
|
2019-03-22 21:13:25 +03:00
|
|
|
function checkPopupLoadCount() {
|
|
|
|
is(popup.document.body.innerHTML, _loadCount + "", "Load count");
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
// We normally want to increment _loadCount here. But if the test fails
|
|
|
|
// because we didn't do a load we should have, let's not cause a cascade of
|
|
|
|
// failures by incrementing _loadCount.
|
|
|
|
var origCount = _loadCount;
|
2019-03-22 21:13:25 +03:00
|
|
|
if (popup.document.body.innerHTML >= _loadCount + "")
|
2011-07-07 17:12:14 +04:00
|
|
|
_loadCount++;
|
|
|
|
return origCount;
|
|
|
|
}
|
|
|
|
|
2019-03-22 21:13:25 +03:00
|
|
|
function* test() {
|
2013-07-26 02:57:25 +04:00
|
|
|
// Step 0 - Make sure the count is reset to 0 in case of reload
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.location = "file_bug669671.sjs?countreset";
|
2013-07-26 02:57:25 +04:00
|
|
|
yield;
|
2019-03-22 21:13:25 +03:00
|
|
|
is(popup.document.body.innerHTML, "0",
|
|
|
|
"Load count should be reset to 0");
|
2013-07-26 02:57:25 +04:00
|
|
|
|
2011-07-07 17:12:14 +04:00
|
|
|
// Step 1 - The popup's body counts how many times we've requested the
|
|
|
|
// resource. This is the first time we've requested it, so it should be '0'.
|
|
|
|
checkPopupLoadCount();
|
|
|
|
|
|
|
|
// Step 2 - We'll get another onChildLoad when this finishes.
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.location = "file_bug669671.sjs";
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
// Step 3 - Call pushState and change the URI back to ?pushed.
|
|
|
|
checkPopupLoadCount();
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.history.pushState("", "", "?pushed");
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
// Step 4 - Navigate away. This should trigger another onChildLoad.
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.location = "file_bug669671.sjs?navigated-1";
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
// Step 5 - Go back. This should result in another onload (because the file is
|
|
|
|
// not in bfcache) and should be the fourth time we've requested the sjs file.
|
|
|
|
checkPopupLoadCount();
|
2018-08-01 00:27:03 +03:00
|
|
|
popup.history.back();
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
|
|
|
|
// This is the check which was failing before we fixed the bug.
|
|
|
|
checkPopupLoadCount();
|
|
|
|
|
|
|
|
popup.close();
|
|
|
|
|
|
|
|
// Do the whole thing again, but with replaceState.
|
2019-03-22 21:13:25 +03:00
|
|
|
popup = window.open("file_bug669671.sjs?replaced");
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
checkPopupLoadCount();
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.location = "file_bug669671.sjs";
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
checkPopupLoadCount();
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.history.replaceState("", "", "?replaced");
|
|
|
|
popup.location = "file_bug669671.sjs?navigated-2";
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
checkPopupLoadCount();
|
2018-08-01 00:27:03 +03:00
|
|
|
popup.history.back();
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
checkPopupLoadCount();
|
|
|
|
popup.close();
|
|
|
|
|
|
|
|
// Once more, with feeling. Notice that we don't have to prime the cache
|
|
|
|
// with an extra load here, because X and X#hash share the same cache entry.
|
2019-03-22 21:13:25 +03:00
|
|
|
popup = window.open("file_bug669671.sjs?hash-test");
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
var initialCount = checkPopupLoadCount();
|
2019-03-22 21:13:25 +03:00
|
|
|
popup.history.replaceState("", "", "#hash");
|
|
|
|
popup.location = "file_bug669671.sjs?navigated-3";
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2011-07-07 17:12:14 +04:00
|
|
|
checkPopupLoadCount();
|
2018-08-01 00:27:03 +03:00
|
|
|
popup.history.back();
|
2013-07-11 01:52:26 +04:00
|
|
|
yield undefined;
|
2019-03-22 21:13:25 +03:00
|
|
|
is(popup.document.body.innerHTML, initialCount + "",
|
|
|
|
"Load count (should be cached)");
|
2011-07-07 17:12:14 +04:00
|
|
|
popup.close();
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
var gGen = test();
|
2017-07-11 03:04:00 +03:00
|
|
|
var popup;
|
2011-07-07 17:12:14 +04:00
|
|
|
|
2017-07-11 03:04:00 +03:00
|
|
|
// Disable RCWN to make cache behavior deterministic.
|
|
|
|
SpecialPowers.pushPrefEnv({set: [["network.http.rcwn.enabled", false]]}, () => {
|
|
|
|
// This will call into onChildLoad once it loads.
|
2019-03-22 21:13:25 +03:00
|
|
|
popup = window.open("file_bug669671.sjs?pushed");
|
2017-07-11 03:04:00 +03:00
|
|
|
});
|
2011-07-07 17:12:14 +04:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|