Title: [267589] trunk
Revision
267589
Author
[email protected]
Date
2020-09-25 13:11:48 -0700 (Fri, 25 Sep 2020)

Log Message

visibilitychange:hidden doesn't fire during page navigations
https://bugs.webkit.org/show_bug.cgi?id=151234
<rdar://problem/23688763>

Reviewed by Darin Adler and Ryosuke Niwa.

LayoutTests/imported/w3c:

Import page-visibility WPT tests from upstream.

* resources/import-expectations.json:
* web-platform-tests/page-visibility/*: Added.

Source/WebCore:

Fire a visibilitychange during document unload, as per the specification:
- https://www.w3.org/TR/page-visibility/#reacting-to-visibilitychange-changes
- https://html.spec.whatwg.org/multipage/browsing-the-web.html#unloading-document-visibility-change-steps

Tests: imported/w3c/web-platform-tests/page-visibility/idlharness.window.html
       imported/w3c/web-platform-tests/page-visibility/iframe-unload.html
       imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html
       imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html
       imported/w3c/web-platform-tests/page-visibility/test_child_document.html
       imported/w3c/web-platform-tests/page-visibility/test_default_view.html
       imported/w3c/web-platform-tests/page-visibility/test_read_only.html
       imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html
       imported/w3c/web-platform-tests/page-visibility/unload.html

* dom/Document.cpp:
(WebCore::Document::visibilityState const):
* dom/Document.h:
(WebCore::Document::setIsUnloadingOrUnloaded):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::dispatchUnloadEvents):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (267588 => 267589)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-25 20:11:48 UTC (rev 267589)
@@ -1,3 +1,16 @@
+2020-09-25  Chris Dumez  <[email protected]>
+
+        visibilitychange:hidden doesn't fire during page navigations
+        https://bugs.webkit.org/show_bug.cgi?id=151234
+        <rdar://problem/23688763>
+
+        Reviewed by Darin Adler and Ryosuke Niwa.
+
+        Import page-visibility WPT tests from upstream.
+
+        * resources/import-expectations.json:
+        * web-platform-tests/page-visibility/*: Added.
+
 2020-09-25  Frederic Wang  <[email protected]>
 
         Bug 216702 - Implement the CSS math-style property

Modified: trunk/LayoutTests/imported/w3c/resources/import-expectations.json (267588 => 267589)


--- trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/LayoutTests/imported/w3c/resources/import-expectations.json	2020-09-25 20:11:48 UTC (rev 267589)
@@ -336,7 +336,7 @@
     "web-platform-tests/old-tests": "skip", 
     "web-platform-tests/orientation-event": "skip", 
     "web-platform-tests/orientation-sensor": "skip", 
-    "web-platform-tests/page-visibility": "skip", 
+    "web-platform-tests/page-visibility": "import", 
     "web-platform-tests/paint-timing": "skip", 
     "web-platform-tests/payment-handler": "skip", 
     "web-platform-tests/payment-method-basic-card": "skip", 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt (267588 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/no_window_open_when_term_nesting_level_nonzero.window-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Error: assert_equals: expected no popup during visibilitychange expected null but got object "[object Window]"
 CONSOLE MESSAGE: Error: assert_equals: expected no popup during pagehide expected null but got object "[object Window]"
 CONSOLE MESSAGE: Error: assert_equals: expected no popup during unload expected null but got object "[object Window]"
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/META.yml (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/META.yml	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/META.yml	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,4 @@
+spec: https://w3c.github.io/page-visibility/
+suggested_reviewers:
+  - plehegar
+  - igrigorik

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,19 @@
+
+PASS idl_test setup 
+PASS idl_test validation 
+PASS Partial interface Document: original interface defined 
+PASS Partial interface Document: member names are unique 
+PASS Partial interface Document[2]: member names are unique 
+PASS Partial interface Document[3]: member names are unique 
+PASS Document includes NonElementParentNode: member names are unique 
+PASS Document includes ParentNode: member names are unique 
+PASS Document includes XPathEvaluatorBase: member names are unique 
+PASS Document includes GlobalEventHandlers: member names are unique 
+PASS Document includes DocumentAndElementEventHandlers: member names are unique 
+PASS Document interface: attribute hidden 
+PASS Document interface: attribute visibilityState 
+PASS Document interface: attribute onvisibilitychange 
+PASS Document interface: document must inherit property "hidden" with the proper type 
+PASS Document interface: document must inherit property "visibilityState" with the proper type 
+PASS Document interface: document must inherit property "onvisibilitychange" with the proper type 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.js (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.js	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,17 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+'use strict';
+
+// https://w3c.github.io/page-visibility/
+
+idl_test(
+  ['page-visibility'],
+  ['dom', 'html'],
+  idl_array => {
+    idl_array.add_objects({
+      Document: ['document'],
+    });
+  }
+);

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,3 @@
+
+PASS visibilitychange fires on unload with iframes 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,49 @@
+<html>
+<title>visibilitychange fires on unload with iframes</title>
+<script src=""
+<script src=""
+<div id="log"></div>
+<script>
+
+var frameDocs = [];
+var docsLoaded = 0;
+var numFrames = 3;
+
+var ast = new async_test("visibilitychange fires on unload with iframes");
+
+function startTest() {
+  if (++docsLoaded < numFrames)
+    return;
+
+  ast.step(function () {
+    frameDocs.push(window[0].document);
+    frameDocs.push(window[0][0].document);
+    frameDocs.push(window[0][1].document);
+
+    for (var i = 0; i < frameDocs.length; ++i) {
+      frameDocs[i].addEventListener(
+          "visibilitychange",
+          onVisibilityChange.bind(null, i), false);
+    }
+
+    document.body.removeChild(document.getElementById("frame1"));
+  });
+}
+
+var checkedFrames = 0;
+
+function onVisibilityChange(i) {
+  ast.step(function () {
+    assert_equals(frameDocs[i].visibilityState, "hidden");
+  });
+  if (++checkedFrames >= numFrames) {
+    ast.done();
+  }
+}
+
+
+
+</script>
+<iframe id="frame1" src=""
+</body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,3 @@
+
+PASS onvisibilitychange attribute is a proper event handler 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,16 @@
+<!doctype html>
+<title>onvisibilitychange attribute is a proper event handler</title>
+<script src=""
+<script src=""
+<div id="log"></div>
+<script>
+var ast = new async_test("onvisibilitychange attribute is a proper event handler");
+function startTest() {
+  var iframe1 = document.getElementById("frame1");
+  iframe1.contentWindow.document._onvisibilitychange_ = ast.step_func(function() {
+    ast.done();
+  });
+  frame1.parentNode.removeChild(frame1);
+}
+</script>
+<iframe id="frame1" src=''></iframe>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/blank_page_green.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/blank_page_green.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/blank_page_green.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
+        <title>Green Test Page</title>
+    </head>
+    <body style="background-color:#00FF00;">
+        <h1>Placeholder</h1>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe-with-subframes.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe-with-subframes.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe-with-subframes.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,6 @@
+<html>
+<body _onload_="parent.startTest()">
+<iframe id="subIframe1" _onload_="parent.parent.startTest()"></iframe>
+<iframe id="subIframe2" _onload_="parent.parent.startTest()"></iframe>
+</body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,12 @@
+<!doctype html>
+<html>
+<head><title>Document</title></head>
+<body>
+<h1>Document</h1>
+<script>
+_onload_ = function() {
+  parent.startTest();
+}
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/pagevistestharness.js (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/pagevistestharness.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/pagevistestharness.js	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,121 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+*/
+
+//
+// Helper Functions for PageVisibility W3C tests
+//
+var VISIBILITY_STATES =
+{
+    HIDDEN: "hidden",
+    VISIBLE: "visible"
+};
+
+var feature_check = false;
+
+//
+// All test() functions in the WebPerf PageVis test suite should use pv_test() instead.
+//
+// pv_test() validates the document.hidden and document.visibilityState attributes
+// exist prior to running tests and immediately shows a failure if they do not.
+//
+
+function pv_test(func, msg, doc)
+{
+    if (!doc)
+    {
+        doc = document;
+    }
+
+    // only run the feature check once, unless func == null, in which case,
+    // this call is intended as a feature check
+    if (!feature_check)
+    {
+        feature_check = true;
+
+        var hiddenVal = doc.hidden;
+        var visStateVal = doc.visibilityState;
+
+        // show a single error that the Page Visibility feature is undefined
+        test(function()
+        {
+            assert_true(hiddenVal !== undefined && hiddenVal != null,
+                        "document.hidden is defined and not null.");},
+                        "document.hidden is defined and not null.");
+
+        test(function()
+        {
+            assert_true(visStateVal !== undefined && hiddenVal != null,
+                        "document.visibilityState is defined and not null.");},
+                        "document.visibilityState is defined and not null.");
+
+    }
+
+    if (func)
+    {
+        test(func, msg);
+    }
+}
+
+
+function test_feature_exists(doc, msg)
+{
+    if (!msg)
+    {
+        msg = "";
+    }
+    var hiddenMsg = "document.hidden is defined" + msg + ".";
+    var stateMsg = "document.visibilityState is defined" + msg + ".";
+    pv_test(function(){assert_true(document.hidden !== undefined, hiddenMsg);}, hiddenMsg, doc);
+    pv_test(function(){assert_true(document.visibilityState !== undefined, stateMsg);}, stateMsg, doc);
+}
+
+//
+// Common helper functions
+//
+
+function test_true(value, msg)
+{
+    pv_test(function() { assert_true(value, msg); }, msg);
+}
+
+function test_equals(value, equals, msg)
+{
+    pv_test(function() { assert_equals(value, equals, msg); }, msg);
+}
+
+//
+// asynchronous test helper functions
+//
+
+function add_async_result(test_obj, pass_state)
+{
+    // add assertion to manual test for the pass state
+    test_obj.step(function() { assert_true(pass_state) });
+
+    // end manual test
+    test_obj.done();
+}
+
+function add_async_result_assert(test_obj, func)
+{
+    // add assertion to manual test for the pass state
+    test_obj.step(func);
+
+    // end manual test
+    test_obj.done();
+}
+
+var open_link;
+function TabSwitch()
+{
+    //var open_link = window.open("http://www.bing.com");
+    open_link = window.open('', '_blank');
+    step_timeout(function() { open_link.close(); }, 2000);
+}

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload-bubbles.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload-bubbles.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload-bubbles.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,15 @@
+<!doctype html>
+<html>
+<head><title>Document</title></head>
+<body>
+<h1>Document</h1>
+<script>
+window.addEventListener("load", function() {
+  window.addEventListener("visibilitychange", function() {
+    opener.postMessage(document.visibilityState, "*");
+  });
+  opener.postMessage("close", "*");
+});
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+<head><title>Document</title></head>
+<body>
+<h1>Document</h1>
+<script>
+_onload_ = function() {
+  document.addEventListener("visibilitychange", onVisibilityChange, false);
+  opener.postMessage("close", "*");
+}
+
+function onVisibilityChange() {
+  opener.postMessage(document.visibilityState, "*");
+}
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/w3c-import.log (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/w3c-import.log	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/w3c-import.log	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,22 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+	https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/blank_page_green.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe-with-subframes.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/iframe.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/pagevistestharness.js
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload-bubbles.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/resources/unload.html

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,10 @@
+Description
+
+This test validates that all of the attributes associated with the Page Visibility feature exist (but does not validate that their values are correct).
+
+
+PASS document.hidden is defined and not null. 
+PASS document.visibilityState is defined and not null. 
+PASS document.hidden is defined. 
+PASS document.visibilityState is defined. 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <title>Page Visibility API Definition</title>
+
+        <script type="text/_javascript_" src=""
+        <script src=""
+        <script type="text/_javascript_" src=""
+    </head>
+    <body>
+        <h1>Description</h1>
+        <p>This test validates that all of the attributes associated with the Page Visibility feature exist
+           (but does not validate that their values are correct).</p>
+
+        <div id="log"></div>
+
+        <script type="text/_javascript_" >
+            test_feature_exists();
+        </script>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,24 @@
+Description
+
+This test validates that, within child documents, all of the Page Visibility API attributes exist, are read-only, and match the value of the attributes within the parent document.
+
+
+PASS document.hidden is defined and not null. 
+PASS document.visibilityState is defined and not null. 
+PASS Page Visibility API Child Document Test 
+PASS document.hidden is defined for frame with no style attribute. 
+PASS document.visibilityState is defined for frame with no style attribute. 
+PASS document.visibilityState for frame with no style attribute == visible 
+PASS Page Visibility API Child Document Test 1 
+PASS document.hidden is defined for frame with 'display:none' style. 
+PASS document.visibilityState is defined for frame with 'display:none' style. 
+PASS document.visibilityState for frame with 'display:none' style == visible 
+PASS Page Visibility API Child Document Test 2 
+PASS document.hidden is defined for frame with 'visibility:hidden' style. 
+PASS document.visibilityState is defined for frame with 'visibility:hidden' style. 
+PASS document.visibilityState for frame with 'visibility:hidden' style == visible 
+
+IFrame with no style attribute 
+IFrame with "display:none" style
+IFrame with "visibility:hidden" style 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <title>Page Visibility API Child Document Test</title>
+
+        <script src=""
+        <script src=""
+        <script type="text/_javascript_" src=""
+
+        <style type="text/css">
+            iframe
+            {
+                width:250px;
+                height:250px;
+                margin-left:5px;
+            }
+
+            div.docs
+            {
+                position:relative;
+                float:left;
+                text-align:center;
+                margin:10px;
+                border:solid 1px black;
+                padding:3px;
+            }
+        </style>
+
+        <script type="text/_javascript_" >
+            setup({explicit_done: true});
+
+            function onload_test()
+            {
+                pv_test();
+
+                var frames = document.getElementsByTagName("iframe");
+                var doc, doc_name;
+
+                for (var i = 0; i < frames.length; i++)
+                {
+                    doc = frames[i].contentDocument;
+                    doc_name = "IFrame with " + frames[i].id;
+
+                    pv_test(function()
+                    {
+                        test_feature_exists(doc, " for frame with " + frames[i].id);
+                    });
+
+                    test_equals(doc.visibilityState, VISIBILITY_STATES.VISIBLE,
+                                "document.visibilityState for frame with " +
+                                frames[i].id + " == " +
+                                VISIBILITY_STATES.VISIBLE);
+                }
+
+                done();
+            }
+        </script>
+    </head>
+    <body _onload_="onload_test()">
+        <h1>Description</h1>
+        <p>This test validates that, within child documents, all of the Page Visibility API attributes exist,
+           are read-only, and match the value of the attributes within the parent document.</p>
+
+        <div id="log"></div>
+
+        <br/>
+
+        <div class="docs">
+            IFrame with no style attribute
+            <br/>
+            <iframe id="no style attribute" src=""
+                iframes unsupported
+            </iframe>
+        </div>
+
+        <div class="docs">
+            IFrame with "display:none" style<br/>
+            <iframe id="'display:none' style" style="display:none"
+                    src=""
+                iframes unsupported
+            </iframe>
+        </div>
+
+        <div class="docs">
+            IFrame with "visibility:hidden" style
+            <br/>
+            <iframe id="'visibility:hidden' style" style="visibility:hidden"
+                    src=""
+                iframes unsupported
+            </iframe>
+        </div>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,13 @@
+Description
+
+This test validates that document.hidden == false and document.visibilityState == "visible" for windowless subdocuments.
+
+
+PASS document.hidden is defined and not null. 
+PASS document.visibilityState is defined and not null. 
+PASS windowless subdocument generated for test has a null default view 
+PASS document.hidden is definedwindowless subdocument. 
+PASS document.visibilityState is definedwindowless subdocument. 
+PASS hidden == true for windowless subdocuments with a null default view 
+PASS visibilityState == hidden for windowless subdocuments with a null default view 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <title>Page Visibility Null Default View Test</title>
+        <link rel="author" title="Microsoft" href="" />
+
+        <script src=""
+        <script src=""
+        <script type="text/_javascript_" src=""
+
+        <script type="text/_javascript_" >
+            setup({explicit_done: true});
+
+            function onload_test()
+            {
+                // inject a windowless subdocument as a child of the root document <html> element
+                var subDoc = document.implementation.createDocument('resources/blank_page_green.html', 'html', null);
+
+                // Test precondition: ensure subdocument has a null default view
+                test_true(subDoc.defaultView == null, "windowless subdocument generated for test has a null default view");
+
+                // check that feature exists within subdocument
+                test_feature_exists(subDoc, 'windowless subdocument');
+
+                // check that the subdocument has a hidden visibility state
+                test_true(subDoc.hidden,
+                          "hidden == true for windowless subdocuments with a null default view");
+                test_equals(subDoc.visibilityState, VISIBILITY_STATES.HIDDEN,
+                            "visibilityState == " + VISIBILITY_STATES.HIDDEN +
+                            " for windowless subdocuments with a null default view");
+
+                done();
+            }
+        </script>
+    </head>
+    <body _onload_="onload_test()">
+        <h1>Description</h1>
+        <p>This test validates that document.hidden == false and
+           document.visibilityState == "visible" for windowless subdocuments.</p>
+        <div id="log"></div>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,10 @@
+Description
+
+This test validates that the Page Visibility attributes are read only.
+
+
+PASS document.hidden is defined and not null. 
+PASS document.visibilityState is defined and not null. 
+PASS document.hidden is read only. 
+PASS document.visibilityState is read only. 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <title>Page Visibility API is Read Only</title>
+
+        <script src=""
+        <script src=""
+        <script type="text/_javascript_" src=""
+
+        <script type="text/_javascript_">
+            setup({ explicit_done: true });
+            function onload_test()
+            {
+                //check for feature definition first before attempting to overwrite
+                pv_test();
+
+                //Check document.hidden
+                document.hidden = "new value";
+                test_true(document.hidden !== "new value", 'document.hidden is read only.');
+
+                //Check document.visibilityState
+                document.visibilityState = "new value";
+                test_true(document.visibilityState !== "new value",
+                                "document.visibilityState is read only.");
+
+                done();
+            }
+        </script>
+    </head>
+    <body _onload_="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the Page Visibility attributes are read only.</p>
+
+        <div id="log"></div>
+    </body>
+</html>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,3 @@
+
+PASS visibilitychange event bubbles when fired on unload 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,18 @@
+<!doctype html>
+<title>visibilitychange event bubbles when fired on unload</title>
+<script src=""
+<script src=""
+<div id="log"></div>
+<script>
+async_test(function(t) {
+  var w = window.open("resources/unload-bubbles.html");
+  window._onmessage_ = t.step_func(function(event) {
+    if (event.data ="" "close") {
+      w.close();
+      return;
+    }
+    assert_equals(event.data, "hidden");
+    t.done();
+  });
+});
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-expected.txt (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-expected.txt	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,3 @@
+
+PASS visibilitychange fires on unload 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload.html (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload.html	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,18 @@
+<!doctype html>
+<title>visibilitychange fires on unload</title>
+<script src=""
+<script src=""
+<div id="log"></div>
+<script>
+async_test(function(t) {
+  var w = window.open("resources/unload.html");
+  window._onmessage_ = t.step_func(function(event) {
+    if (event.data ="" "close") {
+      w.close();
+      return;
+    }
+    assert_equals(event.data, "hidden");
+    t.done();
+  });
+});
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/w3c-import.log (0 => 267589)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/w3c-import.log	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/page-visibility/w3c-import.log	2020-09-25 20:11:48 UTC (rev 267589)
@@ -0,0 +1,26 @@
+The tests in this directory were imported from the W3C repository.
+Do NOT modify these tests directly in WebKit.
+Instead, create a pull request on the WPT github:
+	https://github.com/web-platform-tests/wpt
+
+Then run the Tools/Scripts/import-w3c-tests in WebKit to reimport
+
+Do NOT modify or remove this file.
+
+------------------------------------------------------------------------
+Properties requiring vendor prefixes:
+None
+Property values requiring vendor prefixes:
+None
+------------------------------------------------------------------------
+List of files:
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/META.yml
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/idlharness.window.js
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/iframe-unload.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_child_document.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_default_view.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/test_read_only.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html
+/LayoutTests/imported/w3c/web-platform-tests/page-visibility/unload.html

Modified: trunk/Source/WebCore/ChangeLog (267588 => 267589)


--- trunk/Source/WebCore/ChangeLog	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/Source/WebCore/ChangeLog	2020-09-25 20:11:48 UTC (rev 267589)
@@ -1,3 +1,32 @@
+2020-09-25  Chris Dumez  <[email protected]>
+
+        visibilitychange:hidden doesn't fire during page navigations
+        https://bugs.webkit.org/show_bug.cgi?id=151234
+        <rdar://problem/23688763>
+
+        Reviewed by Darin Adler and Ryosuke Niwa.
+
+        Fire a visibilitychange during document unload, as per the specification:
+        - https://www.w3.org/TR/page-visibility/#reacting-to-visibilitychange-changes
+        - https://html.spec.whatwg.org/multipage/browsing-the-web.html#unloading-document-visibility-change-steps
+
+        Tests: imported/w3c/web-platform-tests/page-visibility/idlharness.window.html
+               imported/w3c/web-platform-tests/page-visibility/iframe-unload.html
+               imported/w3c/web-platform-tests/page-visibility/onvisibilitychange.html
+               imported/w3c/web-platform-tests/page-visibility/test_attributes_exist.html
+               imported/w3c/web-platform-tests/page-visibility/test_child_document.html
+               imported/w3c/web-platform-tests/page-visibility/test_default_view.html
+               imported/w3c/web-platform-tests/page-visibility/test_read_only.html
+               imported/w3c/web-platform-tests/page-visibility/unload-bubbles.html
+               imported/w3c/web-platform-tests/page-visibility/unload.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::visibilityState const):
+        * dom/Document.h:
+        (WebCore::Document::setIsUnloadingOrUnloaded):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::dispatchUnloadEvents):
+
 2020-09-25  Fujii Hironori  <[email protected]>
 
         make_names.pl no longer needs C preprocessor

Modified: trunk/Source/WebCore/dom/Document.cpp (267588 => 267589)


--- trunk/Source/WebCore/dom/Document.cpp	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/Source/WebCore/dom/Document.cpp	2020-09-25 20:11:48 UTC (rev 267589)
@@ -1772,7 +1772,7 @@
     // page. If there is no page associated with the document, we will assume
     // that the page is hidden, as specified by the spec:
     // https://w3c.github.io/page-visibility/#visibilitystate-attribute
-    if (!m_frame || !m_frame->page())
+    if (!m_frame || !m_frame->page() || m_isUnloadingOrUnloaded)
         return VisibilityState::Hidden;
     return m_frame->page()->visibilityState();
 }

Modified: trunk/Source/WebCore/dom/Document.h (267588 => 267589)


--- trunk/Source/WebCore/dom/Document.h	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/Source/WebCore/dom/Document.h	2020-09-25 20:11:48 UTC (rev 267589)
@@ -491,6 +491,8 @@
     void setTimerThrottlingEnabled(bool);
     bool isTimerThrottlingEnabled() const { return m_isTimerThrottlingEnabled; }
 
+    void markAsUnloadingOrUnloaded() { m_isUnloadingOrUnloaded = true; }
+
     WEBCORE_EXPORT ExceptionOr<Ref<Node>> adoptNode(Node& source);
 
     WEBCORE_EXPORT Ref<HTMLCollection> images();
@@ -2127,6 +2129,7 @@
     bool m_hasStartedApplePaySession { false };
 #endif
     bool m_hasVisuallyNonEmptyCustomContent { false };
+    bool m_isUnloadingOrUnloaded { false };
 
     Ref<UndoManager> m_undoManager;
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (267588 => 267589)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2020-09-25 19:49:23 UTC (rev 267588)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2020-09-25 20:11:48 UTC (rev 267589)
@@ -3275,14 +3275,15 @@
         if (is<HTMLInputElement>(currentFocusedElement))
             downcast<HTMLInputElement>(*currentFocusedElement).endEditing();
         if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) {
+            m_frame.document()->markAsUnloadingOrUnloaded();
+
+            m_frame.document()->dispatchEvent(Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
+
             if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) {
                 m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide;
                 m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->backForwardCacheState() == Document::AboutToEnterBackForwardCache), m_frame.document());
             }
 
-            // FIXME: update Page Visibility state here.
-            // https://bugs.webkit.org/show_bug.cgi?id=116770
-
             if (m_frame.document()->backForwardCacheState() == Document::NotInBackForwardCache) {
                 Ref<Event> unloadEvent(Event::create(eventNames().unloadEvent, Event::CanBubble::No, Event::IsCancelable::No));
                 // The DocumentLoader (and thus its LoadTiming) might get destroyed
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to