Ignore-opens-during-unload counter of a parent should apply to its children during beforeunload event
https://bugs.webkit.org/show_bug.cgi?id=189376
<rdar://problem/44282754>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline existing test now that one more check is passing.

* web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt:

Source/WebCore:

Make sure the Ignore-opens-during-unload counter of a parent stays incremented while we are firing the
beforeunload event for its descendants, as per:
- https://html.spec.whatwg.org/multipage/browsing-the-web.html#prompt-to-unload-a-document

No new tests, rebaselined existing tests.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::shouldClose):
(WebCore::FrameLoader::dispatchBeforeUnloadEvent):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@236517 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog
index 803e43d..8ced87c 100644
--- a/LayoutTests/imported/w3c/ChangeLog
+++ b/LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,15 @@
+2018-09-26  Chris Dumez  <cdumez@apple.com>
+
+        Ignore-opens-during-unload counter of a parent should apply to its children during beforeunload event
+        https://bugs.webkit.org/show_bug.cgi?id=189376
+        <rdar://problem/44282754>
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline existing test now that one more check is passing.
+
+        * web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt:
+
 2018-09-25  YUHAN WU  <yuhan_wu@apple.com>
 
         Implement MediaStreamTrack Content Hints
diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt
index 85ce203..ed7d206 100644
--- a/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt
+++ b/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/ignore-opens-during-unload.window-expected.txt
@@ -2,7 +2,7 @@
 Harness Error (TIMEOUT), message = null
 
 PASS document.open should bail out when ignore-opens-during-unload is greater than 0 during beforeunload event (in top-level browsing context) 
-FAIL document.open should bail out when ignore-opens-during-unload is greater than 0 during beforeunload event (open(parent) while unloading parent and child) assert_not_equals: got disallowed value 0
+PASS document.open should bail out when ignore-opens-during-unload is greater than 0 during beforeunload event (open(parent) while unloading parent and child) 
 PASS document.open should bail out when ignore-opens-during-unload is greater than 0 during beforeunload event (open(parent) while unloading child only) 
 PASS document.open should bail out when ignore-opens-during-unload is greater than 0 during pagehide event (in top-level browsing context) 
 PASS document.open should bail out when ignore-opens-during-unload is greater than 0 during pagehide event (open(parent) while unloading parent and child) 
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 12f8819..a9f8d6f 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,21 @@
+2018-09-26  Chris Dumez  <cdumez@apple.com>
+
+        Ignore-opens-during-unload counter of a parent should apply to its children during beforeunload event
+        https://bugs.webkit.org/show_bug.cgi?id=189376
+        <rdar://problem/44282754>
+
+        Reviewed by Ryosuke Niwa.
+
+        Make sure the Ignore-opens-during-unload counter of a parent stays incremented while we are firing the
+        beforeunload event for its descendants, as per:
+        - https://html.spec.whatwg.org/multipage/browsing-the-web.html#prompt-to-unload-a-document
+
+        No new tests, rebaselined existing tests.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::shouldClose):
+        (WebCore::FrameLoader::dispatchBeforeUnloadEvent):
+
 2018-09-26  Justin Fan  <justin_fan@apple.com>
 
         WebGL 2: Adding logging to in-progress features
diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp
index e76d0db..a91f6bd 100644
--- a/Source/WebCore/loader/FrameLoader.cpp
+++ b/Source/WebCore/loader/FrameLoader.cpp
@@ -3122,6 +3122,7 @@
     bool shouldClose = false;
     {
         NavigationDisabler navigationDisabler(&m_frame);
+        IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document());
         size_t i;
 
         for (i = 0; i < targetFrames.size(); i++) {
@@ -3229,7 +3230,6 @@
 
     {
         ForbidPromptsScope forbidPrompts(m_frame.page());
-        IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document());
         domWindow->dispatchEvent(beforeUnloadEvent, domWindow->document());
     }