Commit fc6186bd authored by chongz's avatar chongz Committed by Commit bot

Changed 'visibilitychange' event to a bubble event as defined in w3c docs.

Also changed the API for the prefixed version to maintain compatibility between the two.

This is an interop issue, Firefox bubbles the event while Safari does not, but I think we should match Firefox.

See http://www.w3.org/TR/page-visibility/#sec-processing-model

BUG=501821

Review URL: https://codereview.chromium.org/1435893003

Cr-Commit-Position: refs/heads/master@{#361352}
parent 97a8817d
This test checks that 'visibilitychange' event bubbles.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS document.visibilityState is "visible"
PASS document.hidden is false
PASS event.bubbles is true
PASS event.bubbles is true
PASS document.visibilityState is "hidden"
PASS document.hidden is true
PASS event.bubbles is true
PASS event.bubbles is true
PASS successfullyParsed is true
TEST COMPLETE
<html>
<body onload='startTest()'>
<script src="../../resources/js-test.js"></script>
<script>
// 'visibilitychange' event should bubble as defined in http://www.w3.org/TR/page-visibility/#sec-processing-model
// See: http://crbug.com/501821
description("This test checks that 'visibilitychange' event bubbles.");
var jsTestIsAsync = true;
function makePageVisible() {
if (window.testRunner)
testRunner.setPageVisibility("visible");
}
function makePageHidden() {
if (window.testRunner)
testRunner.setPageVisibility("hidden");
}
function checkIsPageVisible() {
shouldBeEqualToString("document.visibilityState", "visible");
shouldBeFalse("document.hidden");
}
function checkIsPageHidden() {
shouldBeEqualToString("document.visibilityState", "hidden");
shouldBeTrue("document.hidden");
}
// We will try to change the visibility states as:
// 0 - visible. (Initial - i.e. on load).
// 1 - hidden (should fire event and bubbles).
// 2 - visible (should fire event and bubbles).
var numVisibilityChanges = 0;
function startTest() {
// Document listener will be fired first
document.addEventListener(
"visibilitychange", onVisibilityChangeDocument, false);
window.addEventListener(
"visibilitychange", onVisibilityChangeWindow, false);
checkIsPageVisible();
numVisibilityChanges++;
makePageHidden();
}
function onVisibilityChangeDocument(event) {
shouldBeTrue("event.bubbles");
}
function onVisibilityChangeWindow(event) {
shouldBeTrue("event.bubbles");
if (numVisibilityChanges == 1) {
numVisibilityChanges++;
checkIsPageHidden();
makePageVisible();
} else if (numVisibilityChanges == 2) {
finishJSTest();
} else {
testFailed("Invalid number of visibility transitions");
finishJSTest();
}
}
</script>
</body>
</html>
......@@ -1377,9 +1377,9 @@ bool Document::hidden() const
void Document::didChangeVisibilityState()
{
dispatchEvent(Event::create(EventTypeNames::visibilitychange));
dispatchEvent(Event::createBubble(EventTypeNames::visibilitychange));
// Also send out the deprecated version until it can be removed.
dispatchEvent(Event::create(EventTypeNames::webkitvisibilitychange));
dispatchEvent(Event::createBubble(EventTypeNames::webkitvisibilitychange));
PageVisibilityState state = pageVisibilityState();
for (DocumentVisibilityObserver* observer : m_visibilityObservers)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment