Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html

Issue 1883873002: Do not block document.written scripts in page reloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback incorporated. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..12a52806d38dee8f7dad23094ada843e1af52ae9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/loading/doc-write-sync-third-party-script-reload.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script>
+ var reloadTestSuccess = false;
+</script>
+
jkarlin 2016/04/18 17:42:27 This script won't work without window.internals.
shivanisha 2016/04/18 19:33:42 done.
+<script>
+ if (window.internals) {
+ 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("errCount") !== null) {
+ window.localStorage.removeItem("errCount");
+ }
+
+ if (window.localStorage.getItem("succCount") !== null) {
+ window.localStorage.removeItem("succCount");
+ }
+ }, false);
+ }
+
+ if (window.localStorage.getItem("errCount") === null) {
+ window.localStorage.setItem("errCount", 0);
+ }
+
+ if (window.localStorage.getItem("succCount") === null) {
+ window.localStorage.setItem("succCount", 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="succTest()" onError="errTest()"></scr' + 'ipt>');
+
+ function succTest() {
jkarlin 2016/04/18 17:42:26 Layout tests have looser style, but can you use fu
shivanisha 2016/04/18 19:33:42 done.
+ console.assert(window.localStorage.getItem("errCount") == 1,"errCount is not one");
jkarlin 2016/04/18 17:42:26 I've not seen console.assert used in tests much. C
shivanisha 2016/04/18 19:33:43 done.
+
+ var succCount = window.localStorage.getItem("succCount");
+ console.assert(succCount >= 0,"succCount is not >= zero");
jkarlin 2016/04/18 17:42:26 assert_greather_than_equal
shivanisha 2016/04/18 19:33:42 done.
+
+ if (succCount == 0)
+ {
+ window.localStorage.setItem("succCount", 1);
+ if (window.internals) {
+ internals.forceReload(true);
+ }
+ }
+
+ else if (succCount == 1) {
jkarlin 2016/04/18 17:42:26 It's an error if succCount isn't 1. So either retu
jkarlin 2016/04/18 17:43:37 The assert_equals(succCount, 1) should be there in
shivanisha 2016/04/18 19:33:43 Adding the return. It will never be reachable beca
+ window.localStorage.removeItem("errCount");
+ window.localStorage.removeItem("succCount");
+ reloadTestSuccess=true;
+ }
+ }
+
+ function errTest() {
+ console.assert(window.localStorage.getItem("errCount") == 0,"errCount is not zero");
jkarlin 2016/04/18 17:42:26 assert_equals
shivanisha 2016/04/18 19:33:43 done.
+ console.assert(window.localStorage.getItem("succCount") == 0,"succCount is not zero");
jkarlin 2016/04/18 17:42:26 assert_equals
shivanisha 2016/04/18 19:33:43 done.
+ window.localStorage.setItem("errCount", 1);
+ if (window.internals) {
+ internals.forceReload(false);
+ }
+ }
+
+</script>
+
+<script>
+ test(function () {
+ assert_true(reloadTestSuccess);
+ }, "cross origin doc.written scripts are not blocked in a page reload");
+</script>

Powered by Google App Engine
This is Rietveld 408576698