Index: third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html b/third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..93f419c9476b2b4fb79996d231e430e13f4dd801 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html |
@@ -0,0 +1,83 @@ |
+<!DOCTYPE html> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script> |
+ var reloadTestSuccess = false; |
+</script> |
+ |
+<script> |
+ test(function () { |
+ assert_true(window.internals !== null); |
+ }, "window.internals is required for the test to run"); |
+ |
+ internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections(true); |
+ internals.setNetworkStateNotifierTestOnly(true); |
+ internals.setNetworkConnectionInfo('cellular2g', 1.0); |
+ internals.evictAllResources(); |
+ |
+ window.addEventListener('beforeunload', function() { |
+ internals.settings.setDisallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections(false); |
+ internals.setNetworkStateNotifierTestOnly(false); |
+ // Remove localStorage items, just in case they haven't been |
+ // already removed, due to test failure. |
+ if (window.localStorage.getItem("errorCount") !== null) { |
+ window.localStorage.removeItem("errorCount"); |
+ } |
+ |
+ if (window.localStorage.getItem("successCount") !== null) { |
+ window.localStorage.removeItem("successCount"); |
+ } |
+ }, false); |
+ |
+ if (window.localStorage.getItem("errorCount") === null) { |
+ window.localStorage.setItem("errorCount", 0); |
+ } |
+ |
+ if (window.localStorage.getItem("successCount") === null) { |
+ window.localStorage.setItem("successCount", 0); |
+ } |
+ |
+ var crossOrigin = 'http://localhost:8000'; |
+ var filePath = '/loading/resources/js-loaded.js?reload'; |
+ |
+ // First time the script will be blocked and onError will reload the page. |
+ // On reload the script should not be blocked. |
+ // This tests two types of reload, one with and one without cache bypass. |
+ // The script should not be blocked in both cases. |
+ src = crossOrigin + filePath; |
+ document.write('<scr' + 'ipt src="' + src + '" onload="test(successTest,\'Load Success\')" onError="test(errorTest,\'Load Error\')"></scr' + 'ipt>'); |
+ |
+ var successTest = function() { |
+ assert_equals(+window.localStorage.getItem("errorCount"),1,"errorCount is not one"); |
jkarlin
2016/04/19 11:00:34
What does the + do before window? You use it below
jkarlin
2016/04/19 14:23:59
no need for the comment
shivanisha
2016/04/20 14:14:00
This is to convert string "1" to integer 1.
Remove
|
+ |
+ var successCount = +window.localStorage.getItem("successCount"); |
+ assert_greater_than_equal(successCount,0,"successCount is not >= zero"); |
jkarlin
2016/04/19 11:00:35
spaces between parameters
jkarlin
2016/04/19 14:23:59
no need for the comment
shivanisha
2016/04/20 14:13:59
Added spaces. removed comment.
|
+ |
+ if (successCount == 0) |
+ { |
+ window.localStorage.setItem("successCount", 1); |
+ internals.forceReload(true); |
+ return; |
+ } |
+ |
+ // This code path will only be followed for the second reload. |
jkarlin
2016/04/19 11:00:34
Comment not necessary, the assert makes that clear
shivanisha
2016/04/20 14:13:59
removed.
|
+ assert_equals(successCount, 1, "successCount is not one"); |
jkarlin
2016/04/19 14:23:59
The comment "successCount is not one" doesn't conv
shivanisha
2016/04/20 14:13:59
Agree the comments are redundant. done.
|
+ window.localStorage.removeItem("errorCount"); |
+ window.localStorage.removeItem("successCount"); |
+ reloadTestSuccess=true; |
+ } |
+ |
+ var errorTest = function() { |
+ assert_equals(+window.localStorage.getItem("errorCount"),0,"errorCount is not zero"); |
jkarlin
2016/04/19 11:00:35
spaces between parameters
jkarlin
2016/04/19 14:23:59
no need for the comment
shivanisha
2016/04/20 14:14:00
done.
|
+ assert_equals(+window.localStorage.getItem("successCount"),0,"successCount is not zero"); |
jkarlin
2016/04/19 11:00:35
spaces between parameters
jkarlin
2016/04/19 14:23:59
no need for the comment
shivanisha
2016/04/20 14:14:00
done.
|
+ window.localStorage.setItem("errorCount", 1); |
+ internals.forceReload(false); |
+ } |
+ |
+</script> |
+ |
+<script> |
+ test(function () { |
+ assert_true(reloadTestSuccess); |
+ }, "cross origin doc.written scripts are not blocked in a page reload"); |
+</script> |