Nested calls to setDocument can omit firing 'unload' events
https://bugs.webkit.org/show_bug.cgi?id=166422
<rdar://problem/29763012>
Reviewed by Alex Christensen.
Source/WebCore:
Test: fast/loader/nested-document-handling.html
Only allow a single document change to be taking place during a given runloop cycle.
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::executeIfJavaScriptURL): Block script changing the document
when we are in the middle of changing the document.
* page/Frame.cpp:
(WebCore::Frame::setDocument): Keep track of document change state.
* page/Frame.h:
LayoutTests:
* fast/loader/nested-document-handling-expected.txt: Added.
* fast/loader/nested-document-handling.html: Added.
* fast/loader/resources/subframe-success.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@210122 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/loader/nested-document-handling-expected.txt b/LayoutTests/fast/loader/nested-document-handling-expected.txt
new file mode 100644
index 0000000..202839d
--- /dev/null
+++ b/LayoutTests/fast/loader/nested-document-handling-expected.txt
@@ -0,0 +1,10 @@
+Check that we properly handle nested document loads during unload events. Passes if we do not debug assert.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Load succeeded.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/loader/nested-document-handling.html b/LayoutTests/fast/loader/nested-document-handling.html
new file mode 100644
index 0000000..3e81697
--- /dev/null
+++ b/LayoutTests/fast/loader/nested-document-handling.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script>
+"use strict";
+
+description('Check that we properly handle nested document loads during unload events. Passes if we do not debug assert.');
+
+window.jsTestIsAsync = true;
+
+function finishTest() {
+ testPassed('Load succeeded.');
+ finishJSTest();
+}
+
+function runTest() {
+ let topFrame = document.documentElement.appendChild(document.createElement("iframe"));
+ topFrame.id = 'topFrame';
+
+ let aFrame = topFrame.contentDocument.documentElement.appendChild(document.createElement("iframe"));
+ aFrame.id = 'aFrame';
+
+ aFrame.contentWindow.onunload = () => {
+ topFrame.src = "javascript:''";
+
+ let bFrame = topFrame.contentDocument.appendChild(document.createElement("iframe"));
+ bFrame.id = 'bFrame';
+
+ bFrame.contentWindow.onunload = () => {
+ topFrame.src = "javascript:''";
+
+ let doc = topFrame.contentDocument;
+
+ topFrame.onload = () => {
+ topFrame.onload = () => {
+ topFrame.onload = null;
+ let s = doc.createElement("form");
+ s.action = "javascript:alert(location)";
+ s.submit();
+ };
+
+ topFrame.src = "resources/subframe-success.html";
+ };
+
+ };
+ };
+
+ topFrame.src = "javascript:''";
+}
+</script>
+</head>
+<body onload="runTest()">
+</body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/fast/loader/resources/subframe-success.html b/LayoutTests/fast/loader/resources/subframe-success.html
new file mode 100644
index 0000000..817e350
--- /dev/null
+++ b/LayoutTests/fast/loader/resources/subframe-success.html
@@ -0,0 +1,5 @@
+<html>
+<body onload="parent.finishTest();">
+I am a simple document that completes the test when loaded
+</body>
+</html>