|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=669671 |
|
5 --> |
|
6 <head> |
|
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"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=669671">Mozilla Bug 669671</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script type="application/javascript;version=1.7"> |
|
19 |
|
20 /** |
|
21 * Test for Bug 669671. |
|
22 * |
|
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. |
|
26 * |
|
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: |
|
29 * |
|
30 * 1) Load X?pushed, to prime the cache. |
|
31 * 2) Navigate to X. |
|
32 * 3) Call pushState and navigate from X to X?pushed. |
|
33 * 4) Navigate to X?navigated. |
|
34 * 5) Go back (to X?pushed). |
|
35 * |
|
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. |
|
39 * |
|
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. |
|
44 * |
|
45 **/ |
|
46 SimpleTest.waitForExplicitFinish(); |
|
47 |
|
48 function onChildLoad() |
|
49 { |
|
50 SimpleTest.executeSoon(function() { gGen.next() }); |
|
51 } |
|
52 |
|
53 var _loadCount = 0; |
|
54 function checkPopupLoadCount() |
|
55 { |
|
56 is(popup.document.body.innerHTML, _loadCount + '', 'Load count'); |
|
57 |
|
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 + '') |
|
63 _loadCount++; |
|
64 return origCount; |
|
65 } |
|
66 |
|
67 function test() |
|
68 { |
|
69 // Step 0 - Make sure the count is reset to 0 in case of reload |
|
70 popup.location = 'file_bug669671.sjs?countreset'; |
|
71 yield; |
|
72 is(popup.document.body.innerHTML, '0', |
|
73 'Load count should be reset to 0'); |
|
74 |
|
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(); |
|
78 |
|
79 // Step 2 - We'll get another onChildLoad when this finishes. |
|
80 popup.location = 'file_bug669671.sjs'; |
|
81 yield undefined; |
|
82 |
|
83 // Step 3 - Call pushState and change the URI back to ?pushed. |
|
84 checkPopupLoadCount(); |
|
85 popup.history.pushState('', '', '?pushed'); |
|
86 |
|
87 // Step 4 - Navigate away. This should trigger another onChildLoad. |
|
88 popup.location = 'file_bug669671.sjs?navigated-1'; |
|
89 yield undefined; |
|
90 |
|
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 popup.back(); |
|
95 yield undefined; |
|
96 |
|
97 // This is the check which was failing before we fixed the bug. |
|
98 checkPopupLoadCount(); |
|
99 |
|
100 popup.close(); |
|
101 |
|
102 // Do the whole thing again, but with replaceState. |
|
103 popup = window.open('file_bug669671.sjs?replaced'); |
|
104 yield undefined; |
|
105 checkPopupLoadCount(); |
|
106 popup.location = 'file_bug669671.sjs'; |
|
107 yield undefined; |
|
108 checkPopupLoadCount(); |
|
109 popup.history.replaceState('', '', '?replaced'); |
|
110 popup.location = 'file_bug669671.sjs?navigated-2'; |
|
111 yield undefined; |
|
112 checkPopupLoadCount(); |
|
113 popup.back(); |
|
114 yield undefined; |
|
115 checkPopupLoadCount(); |
|
116 popup.close(); |
|
117 |
|
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'); |
|
121 yield undefined; |
|
122 var initialCount = checkPopupLoadCount(); |
|
123 popup.history.replaceState('', '', '#hash'); |
|
124 popup.location = 'file_bug669671.sjs?navigated-3'; |
|
125 yield undefined; |
|
126 checkPopupLoadCount(); |
|
127 popup.back(); |
|
128 yield undefined; |
|
129 is(popup.document.body.innerHTML, initialCount + '', |
|
130 'Load count (should be cached)'); |
|
131 popup.close(); |
|
132 |
|
133 SimpleTest.finish(); |
|
134 yield undefined; |
|
135 } |
|
136 |
|
137 // This will call into onChildLoad once it loads. |
|
138 var popup = window.open('file_bug669671.sjs?pushed'); |
|
139 |
|
140 var gGen = test(); |
|
141 |
|
142 </script> |
|
143 </pre> |
|
144 </body> |
|
145 </html> |