OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script> |
| 5 var reloadTestSuccess = false; |
| 6 </script> |
| 7 |
| 8 <script> |
| 9 test(function () { |
| 10 assert_true(window.internals !== null); |
| 11 }, "window.internals is required for the test to run"); |
| 12 |
| 13 internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrameOnSlowConn
ections(true); |
| 14 internals.setNetworkStateNotifierTestOnly(true); |
| 15 internals.setNetworkConnectionInfo('cellular2g', 1.0); |
| 16 internals.evictAllResources(); |
| 17 |
| 18 window.addEventListener('beforeunload', function() { |
| 19 internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrameOnSlow
Connections(false); |
| 20 internals.setNetworkStateNotifierTestOnly(false); |
| 21 // Remove localStorage items, just in case they haven't been |
| 22 // already removed, due to test failure. |
| 23 if (window.localStorage.getItem("errorCount") !== null) { |
| 24 window.localStorage.removeItem("errorCount"); |
| 25 } |
| 26 |
| 27 if (window.localStorage.getItem("successCount") !== null) { |
| 28 window.localStorage.removeItem("successCount"); |
| 29 } |
| 30 }, false); |
| 31 |
| 32 if (window.localStorage.getItem("errorCount") === null) { |
| 33 window.localStorage.setItem("errorCount", 0); |
| 34 } |
| 35 |
| 36 if (window.localStorage.getItem("successCount") === null) { |
| 37 window.localStorage.setItem("successCount", 0); |
| 38 } |
| 39 |
| 40 var crossOrigin = 'http://localhost:8000'; |
| 41 var filePath = '/loading/resources/js-loaded.js?reload'; |
| 42 |
| 43 // First time the script will be blocked and onError will reload the page. |
| 44 // On reload the script should not be blocked. |
| 45 // This tests two types of reload, one with and one without cache bypass. |
| 46 // The script should not be blocked in both cases. |
| 47 src = crossOrigin + filePath; |
| 48 document.write('<scr' + 'ipt src="' + src + '" onload="test(successTest,\'Lo
ad Success\')" onError="test(errorTest,\'Load Error\')"></scr' + 'ipt>'); |
| 49 |
| 50 var successTest = function() { |
| 51 assert_equals(+window.localStorage.getItem("errorCount"), 1); |
| 52 |
| 53 var successCount = +window.localStorage.getItem("successCount"); |
| 54 assert_greater_than_equal(successCount, 0); |
| 55 |
| 56 if (successCount == 0) |
| 57 { |
| 58 window.localStorage.setItem("successCount", 1); |
| 59 internals.forceReload(true); |
| 60 return; |
| 61 } |
| 62 |
| 63 assert_equals(successCount, 1); |
| 64 window.localStorage.removeItem("errorCount"); |
| 65 window.localStorage.removeItem("successCount"); |
| 66 reloadTestSuccess=true; |
| 67 } |
| 68 |
| 69 var errorTest = function() { |
| 70 assert_equals(+window.localStorage.getItem("errorCount"), 0); |
| 71 assert_equals(+window.localStorage.getItem("successCount"), 0); |
| 72 window.localStorage.setItem("errorCount", 1); |
| 73 internals.forceReload(false); |
| 74 } |
| 75 |
| 76 </script> |
| 77 |
| 78 <script> |
| 79 test(function () { |
| 80 assert_true(reloadTestSuccess); |
| 81 }, "cross origin doc.written scripts are not blocked in a page reload"); |
| 82 </script> |
OLD | NEW |