Preloads should be cleared when JavaScript cancels loading prematurely.
authorsimonjam@chromium.org <simonjam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Feb 2013 22:00:09 +0000 (22:00 +0000)
committersimonjam@chromium.org <simonjam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Feb 2013 22:00:09 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=110388

Reviewed by Antti Koivisto.

Source/WebCore:

If a page preloads a resource, but JavaScript aborts parsing for any reason (for example, a
redirect or document.write()), the resource is forever marked a preload and won't be reloaded
even if it's explicitly marked no-cache and the page is reloaded.

Test: http/tests/cache/preload-cleared-after-parrsing-canceled-by-js.html

* dom/Document.cpp:
(WebCore::Document::implicitClose):
(WebCore::Document::finishedParsing):

LayoutTests:

* http/tests/cache/preload-cleared-after-parrsing-canceled-by-js-expected.txt: Added.
* http/tests/cache/preload-cleared-after-parrsing-canceled-by-js.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143789 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp

index 43e8474..8594374 100644 (file)
@@ -1,3 +1,13 @@
+2013-02-22  James Simonsen  <simonjam@chromium.org>
+
+        Preloads should be cleared when JavaScript cancels loading prematurely.
+        https://bugs.webkit.org/show_bug.cgi?id=110388
+
+        Reviewed by Antti Koivisto.
+
+        * http/tests/cache/preload-cleared-after-parrsing-canceled-by-js-expected.txt: Added.
+        * http/tests/cache/preload-cleared-after-parrsing-canceled-by-js.html: Added.
+
 2013-02-22  Rouslan Solomakhin  <rouslan@chromium.org>
 
         Expect editing/spelling/spelling-changed-text.html to fail on Qt and GTK
diff --git a/LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js-expected.txt b/LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js-expected.txt
new file mode 100644 (file)
index 0000000..e5b1d82
--- /dev/null
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: line 22: Reloading
+PASS
diff --git a/LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js.html b/LayoutTests/http/tests/cache/preload-cleared-after-parsing-canceled-by-js.html
new file mode 100644 (file)
index 0000000..8f8c2d5
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+  <head>
+    <script>
+      function saveAndCheckRandomNumber() {
+        if (!sessionStorage.lastRandom) {
+          sessionStorage.lastRandom = randomNumber;
+        } else {
+          window.passed = sessionStorage.lastRandom != randomNumber;
+        }
+      }
+    </script>
+    <script type="text/javascript" src="resources/cache-simulator.cgi?uniqueId=1&Cache-control=no-store,no-cache,private,must-revalidate,max-age=0"></script>
+    <script type="text/javascript" src="resources/cache-simulator.cgi?uniqueId=2&Cache-control=no-store,no-cache,private,must-revalidate,max-age=0" onload="saveAndCheckRandomNumber();"></script>
+  </head>
+  <body>
+    <script type="text/javascript">
+      if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+      }
+      if (document.referrer != document.location.toString()) {
+        console.log('Reloading');
+        document.location.reload();
+      } else {
+        if (window.passed === true) {
+          document.body.innerText = "PASS";
+        } else if (window.passed === false) {
+          document.body.innerText = "FAIL";
+        } else {
+          document.body.innerText = "ERROR";
+        }
+        delete sessionStorage.lastRandom;
+        if (window.testRunner) {
+          testRunner.notifyDone();
+        }
+      }
+    </script>
+  </body>
+</html>
index 678d962..c9803d8 100644 (file)
@@ -1,3 +1,20 @@
+2013-02-22  James Simonsen  <simonjam@chromium.org>
+
+        Preloads should be cleared when JavaScript cancels loading prematurely.
+        https://bugs.webkit.org/show_bug.cgi?id=110388
+
+        Reviewed by Antti Koivisto.
+
+        If a page preloads a resource, but JavaScript aborts parsing for any reason (for example, a
+        redirect or document.write()), the resource is forever marked a preload and won't be reloaded
+        even if it's explicitly marked no-cache and the page is reloaded.
+
+        Test: http/tests/cache/preload-cleared-after-parrsing-canceled-by-js.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::implicitClose):
+        (WebCore::Document::finishedParsing):
+
 2013-02-22  Antoine Quint  <graouts@apple.com>
 
         Expose a list of all reasons that qualify a RenderLayer to be composited
index 821b820..5aa1b32 100644 (file)
@@ -2362,9 +2362,6 @@ void Document::implicitClose()
     // onLoad event handler, as in Radar 3206524.
     detachParser();
 
-    // Parser should have picked up all preloads by now
-    m_cachedResourceLoader->clearPreloads();
-
     // FIXME: We kick off the icon loader when the Document is done parsing.
     // There are earlier opportunities we could start it:
     //  -When the <head> finishes parsing
@@ -4405,6 +4402,9 @@ void Document::finishedParsing()
     // alive indefinitely by something innocuous like JS setting .innerHTML repeatedly on a timer.
     static const int timeToKeepSharedObjectPoolAliveAfterParsingFinishedInSeconds = 10;
     m_sharedObjectPoolClearTimer.startOneShot(timeToKeepSharedObjectPoolAliveAfterParsingFinishedInSeconds);
+
+    // Parser should have picked up all preloads by now
+    m_cachedResourceLoader->clearPreloads();
 }
 
 void Document::sharedObjectPoolClearTimerFired(Timer<Document>*)