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
+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.
--- /dev/null
+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.
+
--- /dev/null
+<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>
--- /dev/null
+[
+ {
+ "action": {
+ "type": "block"
+ },
+ "trigger": {
+ "url-filter": "should-be-blocked"
+ }
+ }
+]
-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.
document.getElementById("console").appendChild(p);
}
+var errorCount = 0;
function handleScriptOnError()
{
log('onerror called (good!)');
+ errorCount++;
+ if (errorCount == 2 && window.testRunner)
+ testRunner.notifyDone();
}
</script>
</head>
<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";
-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.
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)
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)
+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
, 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;
m_isExternalScript = true;
}
- if (m_cachedScript) {
+ if (m_cachedScript)
return true;
- }
- dispatchErrorEvent();
+ m_errorEventTimer.startOneShot(0);
return false;
}
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
+#include "Timer.h"
#include <wtf/text/TextPosition.h>
#include <wtf/text/WTFString.h>
bool m_requestUsesAccessControl { false };
String m_characterEncoding;
String m_fallbackCharacterEncoding;
+ Timer m_errorEventTimer;
};
ScriptElement* toScriptElementIfPossible(Element*);