Asynchronously call onerror when a content blocker blocks ascript element's load
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Dec 2015 23:55:50 +0000 (23:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Dec 2015 23:55:50 +0000 (23:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151649

Patch by Alex Christensen <achristensen@webkit.org> on 2015-12-02
Reviewed by Brady Eidson.

Source/WebCore:

Test: http/tests/contentextensions/script-onerror.html

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::ScriptElement):
(WebCore::ScriptElement::requestScript):
* dom/ScriptElement.h:

LayoutTests:

* http/tests/contentextensions/script-onerror-expected.txt: Added.
* http/tests/contentextensions/script-onerror.html: Added.
* http/tests/contentextensions/script-onerror.html.json: Added.
* http/tests/misc/unloadable-script-expected.txt:
* http/tests/misc/unloadable-script.html:
* http/tests/security/local-JavaScript-from-remote-expected.txt:
* http/tests/security/local-JavaScript-from-remote.html:
Added testRunner.waitUntilDone and testRunner.notifyDone to reflect the fact that onerror is no longer called synchronously.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/contentextensions/script-onerror-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/script-onerror.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/script-onerror.html.json [new file with mode: 0644]
LayoutTests/http/tests/misc/unloadable-script-expected.txt
LayoutTests/http/tests/misc/unloadable-script.html
LayoutTests/http/tests/security/local-JavaScript-from-remote-expected.txt
LayoutTests/http/tests/security/local-JavaScript-from-remote.html
Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/ScriptElement.h

index 9a61166..c3693ac 100644 (file)
@@ -1,3 +1,19 @@
+2015-12-02  Alex Christensen  <achristensen@webkit.org>
+
+        Asynchronously call onerror when a content blocker blocks ascript element's load
+        https://bugs.webkit.org/show_bug.cgi?id=151649
+
+        Reviewed by Brady Eidson.
+
+        * http/tests/contentextensions/script-onerror-expected.txt: Added.
+        * http/tests/contentextensions/script-onerror.html: Added.
+        * http/tests/contentextensions/script-onerror.html.json: Added.
+        * http/tests/misc/unloadable-script-expected.txt:
+        * http/tests/misc/unloadable-script.html:
+        * http/tests/security/local-JavaScript-from-remote-expected.txt:
+        * http/tests/security/local-JavaScript-from-remote.html:
+        Added testRunner.waitUntilDone and testRunner.notifyDone to reflect the fact that onerror is no longer called synchronously.
+
 2015-12-02  Eric Carlson  <eric.carlson@apple.com>
 
         Fix flaky test added with r192954.
diff --git a/LayoutTests/http/tests/contentextensions/script-onerror-expected.txt b/LayoutTests/http/tests/contentextensions/script-onerror-expected.txt
new file mode 100644 (file)
index 0000000..d5293fa
--- /dev/null
@@ -0,0 +1,4 @@
+CONSOLE MESSAGE: line 16: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/script-onerror.html from loading a resource from http://127.0.0.1:8000/contentextensions/should-be-blocked.js
+CONSOLE MESSAGE: line 17: Done executing script.  Waiting for onerror callback.
+CONSOLE MESSAGE: line 11: onerror was correctly called on the next runloop cycle.
+
diff --git a/LayoutTests/http/tests/contentextensions/script-onerror.html b/LayoutTests/http/tests/contentextensions/script-onerror.html
new file mode 100644 (file)
index 0000000..59a3b4f
--- /dev/null
@@ -0,0 +1,18 @@
+<script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    var s = document.createElement('script');
+    s.src = "should-be-blocked.js";
+    s.onerror = function () {
+        if (window.testRunner) {
+            console.log("onerror was correctly called on the next runloop cycle.");
+            testRunner.notifyDone();
+        }
+    };
+
+    document.getElementsByTagName('head')[0].appendChild(s);
+    console.log("Done executing script.  Waiting for onerror callback.");
+</script>
diff --git a/LayoutTests/http/tests/contentextensions/script-onerror.html.json b/LayoutTests/http/tests/contentextensions/script-onerror.html.json
new file mode 100644 (file)
index 0000000..04deaa8
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": "should-be-blocked"
+        }
+    }
+]
index afdb967..30ecb0b 100644 (file)
@@ -1,5 +1,5 @@
-CONSOLE MESSAGE: line 30: Not allowed to load local resource: foobar
-CONSOLE MESSAGE: line 35: Not allowed to load local resource: foobar
+CONSOLE MESSAGE: line 36: Not allowed to load local resource: foobar
+CONSOLE MESSAGE: line 41: Not allowed to load local resource: foobar
 Test for bug 13584: <script> code wrongly assumes requests can't fail.
 
 No crash == SUCCESS.
index 1d0548d..6872b14 100644 (file)
@@ -7,9 +7,13 @@ function log(message) {
   document.getElementById("console").appendChild(p);
 }
 
+var errorCount = 0;
 function handleScriptOnError()
 {
     log('onerror called (good!)');
+    errorCount++;
+    if (errorCount == 2 && window.testRunner)
+        testRunner.notifyDone();
 }
 </script>
 </head>
@@ -23,8 +27,10 @@ function handleScriptOnError()
     <script onerror="handleScriptOnError()" id=test_script></script>
 
     <script>
-        if (window.testRunner)
+        if (window.testRunner) {
             testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
 
         <!-- we are an HTTP test so the security origin will fail the file method -->
         document.getElementById('test_script').src = "file:///foobar";
index b1e4e16..e0c2032 100644 (file)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 29: Not allowed to load local resource: localScript.js
+CONSOLE MESSAGE: line 33: Not allowed to load local resource: localScript.js
 This test is to see if a remote file can run a local script. 
 Currently this test cannot be run manually on Windows because we do not have a function like pathToLocalResource() outside of DRT. 
 
index 72346fc..cb87a37 100644 (file)
@@ -4,8 +4,10 @@
         var secretness = 0;
 
         function test() {
-            if (window.testRunner)
+            if (window.testRunner) {
                 testRunner.dumpAsText();
+                testRunner.waitUntilDone();
+            }
 
             var localScriptLocation = "file:///tmp/LayoutTests/http/tests/security/resources/localScript.js";
             if (window.testRunner)
@@ -24,6 +26,8 @@
             localScriptElement.addEventListener("error", function() {
                 var tag = document.getElementById("result");
                 tag.innerHTML = "Test Passed: Local script not loaded.";
+                if (window.testRunner)
+                    testRunner.notifyDone();
             });
 
             document.body.appendChild(localScriptElement)
index ac7f5cc..e9b8a7f 100644 (file)
@@ -1,3 +1,17 @@
+2015-12-02  Alex Christensen  <achristensen@webkit.org>
+
+        Asynchronously call onerror when a content blocker blocks ascript element's load
+        https://bugs.webkit.org/show_bug.cgi?id=151649
+
+        Reviewed by Brady Eidson.
+
+        Test: http/tests/contentextensions/script-onerror.html
+
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::ScriptElement):
+        (WebCore::ScriptElement::requestScript):
+        * dom/ScriptElement.h:
+
 2015-12-02  Jer Noble  <jer.noble@apple.com>
 
         [iOS] Abrupt transition between Fullscreen -> PiP
index b126c3d..bf3fc30 100644 (file)
@@ -61,6 +61,7 @@ ScriptElement::ScriptElement(Element& element, bool parserInserted, bool already
     , m_parserInserted(parserInserted)
     , m_alreadyStarted(alreadyStarted)
     , m_forceAsync(!parserInserted)
+    , m_errorEventTimer(*this, &ScriptElement::dispatchErrorEvent)
 {
     if (parserInserted && m_element.document().scriptableDocumentParser() && !m_element.document().isInDocumentWrite())
         m_startLineNumber = m_element.document().scriptableDocumentParser()->textPosition().m_line;
@@ -265,11 +266,10 @@ bool ScriptElement::requestScript(const String& sourceUrl)
         m_isExternalScript = true;
     }
 
-    if (m_cachedScript) {
+    if (m_cachedScript)
         return true;
-    }
 
-    dispatchErrorEvent();
+    m_errorEventTimer.startOneShot(0);
     return false;
 }
 
index 49a7722..048d6bb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "CachedResourceClient.h"
 #include "CachedResourceHandle.h"
+#include "Timer.h"
 #include <wtf/text/TextPosition.h>
 #include <wtf/text/WTFString.h>
 
@@ -109,6 +110,7 @@ private:
     bool m_requestUsesAccessControl { false };
     String m_characterEncoding;
     String m_fallbackCharacterEncoding;
+    Timer m_errorEventTimer;
 };
 
 ScriptElement* toScriptElementIfPossible(Element*);