Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=669671 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 669671</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=669671">Mozilla Bug 669671</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"> |
michael@0 | 15 | |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script type="application/javascript;version=1.7"> |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * Test for Bug 669671. |
michael@0 | 22 | * |
michael@0 | 23 | * This is a bit complicated. We have a script, file_bug669671.sjs, which counts |
michael@0 | 24 | * how many times it's loaded and returns that count in the body of an HTML |
michael@0 | 25 | * document. For brevity, call this page X. |
michael@0 | 26 | * |
michael@0 | 27 | * X is sent with Cache-Control: max-age=0 and can't be bfcached (it has an |
michael@0 | 28 | * onunload handler). Our test does the following in a popup: |
michael@0 | 29 | * |
michael@0 | 30 | * 1) Load X?pushed, to prime the cache. |
michael@0 | 31 | * 2) Navigate to X. |
michael@0 | 32 | * 3) Call pushState and navigate from X to X?pushed. |
michael@0 | 33 | * 4) Navigate to X?navigated. |
michael@0 | 34 | * 5) Go back (to X?pushed). |
michael@0 | 35 | * |
michael@0 | 36 | * We do all this work so we can check that in step 5, we fetch X?pushed from |
michael@0 | 37 | * the network -- we shouldn't use our cached copy, because of the |
michael@0 | 38 | * cache-control header X sends. |
michael@0 | 39 | * |
michael@0 | 40 | * Then we go back and repeat the whole process but call history.replaceState |
michael@0 | 41 | * instead of pushState. And for good measure, we test once more, this time |
michael@0 | 42 | * modifying only the hash of the URI using replaceState. In this case, we |
michael@0 | 43 | * *should* load from the cache. |
michael@0 | 44 | * |
michael@0 | 45 | **/ |
michael@0 | 46 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 47 | |
michael@0 | 48 | function onChildLoad() |
michael@0 | 49 | { |
michael@0 | 50 | SimpleTest.executeSoon(function() { gGen.next() }); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | var _loadCount = 0; |
michael@0 | 54 | function checkPopupLoadCount() |
michael@0 | 55 | { |
michael@0 | 56 | is(popup.document.body.innerHTML, _loadCount + '', 'Load count'); |
michael@0 | 57 | |
michael@0 | 58 | // We normally want to increment _loadCount here. But if the test fails |
michael@0 | 59 | // because we didn't do a load we should have, let's not cause a cascade of |
michael@0 | 60 | // failures by incrementing _loadCount. |
michael@0 | 61 | var origCount = _loadCount; |
michael@0 | 62 | if (popup.document.body.innerHTML >= _loadCount + '') |
michael@0 | 63 | _loadCount++; |
michael@0 | 64 | return origCount; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function test() |
michael@0 | 68 | { |
michael@0 | 69 | // Step 0 - Make sure the count is reset to 0 in case of reload |
michael@0 | 70 | popup.location = 'file_bug669671.sjs?countreset'; |
michael@0 | 71 | yield; |
michael@0 | 72 | is(popup.document.body.innerHTML, '0', |
michael@0 | 73 | 'Load count should be reset to 0'); |
michael@0 | 74 | |
michael@0 | 75 | // Step 1 - The popup's body counts how many times we've requested the |
michael@0 | 76 | // resource. This is the first time we've requested it, so it should be '0'. |
michael@0 | 77 | checkPopupLoadCount(); |
michael@0 | 78 | |
michael@0 | 79 | // Step 2 - We'll get another onChildLoad when this finishes. |
michael@0 | 80 | popup.location = 'file_bug669671.sjs'; |
michael@0 | 81 | yield undefined; |
michael@0 | 82 | |
michael@0 | 83 | // Step 3 - Call pushState and change the URI back to ?pushed. |
michael@0 | 84 | checkPopupLoadCount(); |
michael@0 | 85 | popup.history.pushState('', '', '?pushed'); |
michael@0 | 86 | |
michael@0 | 87 | // Step 4 - Navigate away. This should trigger another onChildLoad. |
michael@0 | 88 | popup.location = 'file_bug669671.sjs?navigated-1'; |
michael@0 | 89 | yield undefined; |
michael@0 | 90 | |
michael@0 | 91 | // Step 5 - Go back. This should result in another onload (because the file is |
michael@0 | 92 | // not in bfcache) and should be the fourth time we've requested the sjs file. |
michael@0 | 93 | checkPopupLoadCount(); |
michael@0 | 94 | popup.back(); |
michael@0 | 95 | yield undefined; |
michael@0 | 96 | |
michael@0 | 97 | // This is the check which was failing before we fixed the bug. |
michael@0 | 98 | checkPopupLoadCount(); |
michael@0 | 99 | |
michael@0 | 100 | popup.close(); |
michael@0 | 101 | |
michael@0 | 102 | // Do the whole thing again, but with replaceState. |
michael@0 | 103 | popup = window.open('file_bug669671.sjs?replaced'); |
michael@0 | 104 | yield undefined; |
michael@0 | 105 | checkPopupLoadCount(); |
michael@0 | 106 | popup.location = 'file_bug669671.sjs'; |
michael@0 | 107 | yield undefined; |
michael@0 | 108 | checkPopupLoadCount(); |
michael@0 | 109 | popup.history.replaceState('', '', '?replaced'); |
michael@0 | 110 | popup.location = 'file_bug669671.sjs?navigated-2'; |
michael@0 | 111 | yield undefined; |
michael@0 | 112 | checkPopupLoadCount(); |
michael@0 | 113 | popup.back(); |
michael@0 | 114 | yield undefined; |
michael@0 | 115 | checkPopupLoadCount(); |
michael@0 | 116 | popup.close(); |
michael@0 | 117 | |
michael@0 | 118 | // Once more, with feeling. Notice that we don't have to prime the cache |
michael@0 | 119 | // with an extra load here, because X and X#hash share the same cache entry. |
michael@0 | 120 | popup = window.open('file_bug669671.sjs?hash-test'); |
michael@0 | 121 | yield undefined; |
michael@0 | 122 | var initialCount = checkPopupLoadCount(); |
michael@0 | 123 | popup.history.replaceState('', '', '#hash'); |
michael@0 | 124 | popup.location = 'file_bug669671.sjs?navigated-3'; |
michael@0 | 125 | yield undefined; |
michael@0 | 126 | checkPopupLoadCount(); |
michael@0 | 127 | popup.back(); |
michael@0 | 128 | yield undefined; |
michael@0 | 129 | is(popup.document.body.innerHTML, initialCount + '', |
michael@0 | 130 | 'Load count (should be cached)'); |
michael@0 | 131 | popup.close(); |
michael@0 | 132 | |
michael@0 | 133 | SimpleTest.finish(); |
michael@0 | 134 | yield undefined; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | // This will call into onChildLoad once it loads. |
michael@0 | 138 | var popup = window.open('file_bug669671.sjs?pushed'); |
michael@0 | 139 | |
michael@0 | 140 | var gGen = test(); |
michael@0 | 141 | |
michael@0 | 142 | </script> |
michael@0 | 143 | </pre> |
michael@0 | 144 | </body> |
michael@0 | 145 | </html> |