4 https://bugzilla.mozilla.org/show_bug.cgi?id=669671
7 <title>Test for Bug
669671</title>
8 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=669671">Mozilla Bug
669671</a>
14 <div id=
"content" style=
"display: none">
18 <script type=
"application/javascript;version=1.7">
21 * Test for Bug
669671.
23 * This is a bit complicated. We have a script, file_bug669671.sjs, which counts
24 * how many times it's loaded and returns that count in the body of an HTML
25 * document. For brevity, call this page X.
27 * X is sent with Cache-Control: max-age=
0 and can't be bfcached (it has an
28 * onunload handler). Our test does the following in a popup:
30 *
1) Load X?pushed, to prime the cache.
32 *
3) Call pushState and navigate from X to X?pushed.
33 *
4) Navigate to X?navigated.
34 *
5) Go back (to X?pushed).
36 * We do all this work so we can check that in step
5, we fetch X?pushed from
37 * the network -- we shouldn't use our cached copy, because of the
38 * cache-control header X sends.
40 * Then we go back and repeat the whole process but call history.replaceState
41 * instead of pushState. And for good measure, we test once more, this time
42 * modifying only the hash of the URI using replaceState. In this case, we
43 * *should* load from the cache.
46 SimpleTest.waitForExplicitFinish();
48 function onChildLoad()
50 SimpleTest.executeSoon(function() { gGen.next() });
54 function checkPopupLoadCount()
56 is(popup.document.body.innerHTML, _loadCount + '', 'Load count');
58 // We normally want to increment _loadCount here. But if the test fails
59 // because we didn't do a load we should have, let's not cause a cascade of
60 // failures by incrementing _loadCount.
61 var origCount = _loadCount;
62 if (popup.document.body.innerHTML
>= _loadCount + '')
69 // Step
0 - Make sure the count is reset to
0 in case of reload
70 popup.location = 'file_bug669671.sjs?countreset';
72 is(popup.document.body.innerHTML, '
0',
73 'Load count should be reset to
0');
75 // Step
1 - The popup's body counts how many times we've requested the
76 // resource. This is the first time we've requested it, so it should be '
0'.
77 checkPopupLoadCount();
79 // Step
2 - We'll get another onChildLoad when this finishes.
80 popup.location = 'file_bug669671.sjs';
83 // Step
3 - Call pushState and change the URI back to ?pushed.
84 checkPopupLoadCount();
85 popup.history.pushState('', '', '?pushed');
87 // Step
4 - Navigate away. This should trigger another onChildLoad.
88 popup.location = 'file_bug669671.sjs?navigated-
1';
91 // Step
5 - Go back. This should result in another onload (because the file is
92 // not in bfcache) and should be the fourth time we've requested the sjs file.
93 checkPopupLoadCount();
94 SpecialPowers.wrap(popup).back();
97 // This is the check which was failing before we fixed the bug.
98 checkPopupLoadCount();
102 // Do the whole thing again, but with replaceState.
103 popup = window.open('file_bug669671.sjs?replaced');
105 checkPopupLoadCount();
106 popup.location = 'file_bug669671.sjs';
108 checkPopupLoadCount();
109 popup.history.replaceState('', '', '?replaced');
110 popup.location = 'file_bug669671.sjs?navigated-
2';
112 checkPopupLoadCount();
113 SpecialPowers.wrap(popup).back();
115 checkPopupLoadCount();
118 // Once more, with feeling. Notice that we don't have to prime the cache
119 // with an extra load here, because X and X#hash share the same cache entry.
120 popup = window.open('file_bug669671.sjs?hash-test');
122 var initialCount = checkPopupLoadCount();
123 popup.history.replaceState('', '', '#hash');
124 popup.location = 'file_bug669671.sjs?navigated-
3';
126 checkPopupLoadCount();
127 SpecialPowers.wrap(popup).back();
129 is(popup.document.body.innerHTML, initialCount + '',
130 'Load count (should be cached)');
137 // This will call into onChildLoad once it loads.
138 var popup = window.open('file_bug669671.sjs?pushed');