1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/test_bug669671.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=669671 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 669671</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=669671">Mozilla Bug 669671</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script type="application/javascript;version=1.7"> 1.22 + 1.23 +/** 1.24 + * Test for Bug 669671. 1.25 + * 1.26 + * This is a bit complicated. We have a script, file_bug669671.sjs, which counts 1.27 + * how many times it's loaded and returns that count in the body of an HTML 1.28 + * document. For brevity, call this page X. 1.29 + * 1.30 + * X is sent with Cache-Control: max-age=0 and can't be bfcached (it has an 1.31 + * onunload handler). Our test does the following in a popup: 1.32 + * 1.33 + * 1) Load X?pushed, to prime the cache. 1.34 + * 2) Navigate to X. 1.35 + * 3) Call pushState and navigate from X to X?pushed. 1.36 + * 4) Navigate to X?navigated. 1.37 + * 5) Go back (to X?pushed). 1.38 + * 1.39 + * We do all this work so we can check that in step 5, we fetch X?pushed from 1.40 + * the network -- we shouldn't use our cached copy, because of the 1.41 + * cache-control header X sends. 1.42 + * 1.43 + * Then we go back and repeat the whole process but call history.replaceState 1.44 + * instead of pushState. And for good measure, we test once more, this time 1.45 + * modifying only the hash of the URI using replaceState. In this case, we 1.46 + * *should* load from the cache. 1.47 + * 1.48 + **/ 1.49 +SimpleTest.waitForExplicitFinish(); 1.50 + 1.51 +function onChildLoad() 1.52 +{ 1.53 + SimpleTest.executeSoon(function() { gGen.next() }); 1.54 +} 1.55 + 1.56 +var _loadCount = 0; 1.57 +function checkPopupLoadCount() 1.58 +{ 1.59 + is(popup.document.body.innerHTML, _loadCount + '', 'Load count'); 1.60 + 1.61 + // We normally want to increment _loadCount here. But if the test fails 1.62 + // because we didn't do a load we should have, let's not cause a cascade of 1.63 + // failures by incrementing _loadCount. 1.64 + var origCount = _loadCount; 1.65 + if (popup.document.body.innerHTML >= _loadCount + '') 1.66 + _loadCount++; 1.67 + return origCount; 1.68 +} 1.69 + 1.70 +function test() 1.71 +{ 1.72 + // Step 0 - Make sure the count is reset to 0 in case of reload 1.73 + popup.location = 'file_bug669671.sjs?countreset'; 1.74 + yield; 1.75 + is(popup.document.body.innerHTML, '0', 1.76 + 'Load count should be reset to 0'); 1.77 + 1.78 + // Step 1 - The popup's body counts how many times we've requested the 1.79 + // resource. This is the first time we've requested it, so it should be '0'. 1.80 + checkPopupLoadCount(); 1.81 + 1.82 + // Step 2 - We'll get another onChildLoad when this finishes. 1.83 + popup.location = 'file_bug669671.sjs'; 1.84 + yield undefined; 1.85 + 1.86 + // Step 3 - Call pushState and change the URI back to ?pushed. 1.87 + checkPopupLoadCount(); 1.88 + popup.history.pushState('', '', '?pushed'); 1.89 + 1.90 + // Step 4 - Navigate away. This should trigger another onChildLoad. 1.91 + popup.location = 'file_bug669671.sjs?navigated-1'; 1.92 + yield undefined; 1.93 + 1.94 + // Step 5 - Go back. This should result in another onload (because the file is 1.95 + // not in bfcache) and should be the fourth time we've requested the sjs file. 1.96 + checkPopupLoadCount(); 1.97 + popup.back(); 1.98 + yield undefined; 1.99 + 1.100 + // This is the check which was failing before we fixed the bug. 1.101 + checkPopupLoadCount(); 1.102 + 1.103 + popup.close(); 1.104 + 1.105 + // Do the whole thing again, but with replaceState. 1.106 + popup = window.open('file_bug669671.sjs?replaced'); 1.107 + yield undefined; 1.108 + checkPopupLoadCount(); 1.109 + popup.location = 'file_bug669671.sjs'; 1.110 + yield undefined; 1.111 + checkPopupLoadCount(); 1.112 + popup.history.replaceState('', '', '?replaced'); 1.113 + popup.location = 'file_bug669671.sjs?navigated-2'; 1.114 + yield undefined; 1.115 + checkPopupLoadCount(); 1.116 + popup.back(); 1.117 + yield undefined; 1.118 + checkPopupLoadCount(); 1.119 + popup.close(); 1.120 + 1.121 + // Once more, with feeling. Notice that we don't have to prime the cache 1.122 + // with an extra load here, because X and X#hash share the same cache entry. 1.123 + popup = window.open('file_bug669671.sjs?hash-test'); 1.124 + yield undefined; 1.125 + var initialCount = checkPopupLoadCount(); 1.126 + popup.history.replaceState('', '', '#hash'); 1.127 + popup.location = 'file_bug669671.sjs?navigated-3'; 1.128 + yield undefined; 1.129 + checkPopupLoadCount(); 1.130 + popup.back(); 1.131 + yield undefined; 1.132 + is(popup.document.body.innerHTML, initialCount + '', 1.133 + 'Load count (should be cached)'); 1.134 + popup.close(); 1.135 + 1.136 + SimpleTest.finish(); 1.137 + yield undefined; 1.138 +} 1.139 + 1.140 +// This will call into onChildLoad once it loads. 1.141 +var popup = window.open('file_bug669671.sjs?pushed'); 1.142 + 1.143 +var gGen = test(); 1.144 + 1.145 +</script> 1.146 +</pre> 1.147 +</body> 1.148 +</html>