2011-05-09 11:00:47 +00:00
|
|
|
<html>
|
|
|
|
<body onload='startTest()'>
|
|
|
|
|
2013-09-07 23:07:25 +00:00
|
|
|
<script src="../../resources/js-test-pre.js"></script>
|
2011-05-09 11:00:47 +00:00
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
description("This test checks that Page Visibility state values are correct and the event changes are fired correctly.");
|
|
|
|
|
|
|
|
var jsTestIsAsync = true;
|
|
|
|
|
|
|
|
function makePageVisible() {
|
2012-06-20 03:28:42 +00:00
|
|
|
if (window.testRunner)
|
|
|
|
testRunner.setPageVisibility("visible");
|
2011-05-09 11:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function makePageHidden() {
|
2012-06-20 03:28:42 +00:00
|
|
|
if (window.testRunner)
|
|
|
|
testRunner.setPageVisibility("hidden");
|
2011-05-09 11:00:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-25 23:56:01 +00:00
|
|
|
function makePageUnloaded() {
|
2012-06-20 03:28:42 +00:00
|
|
|
if (window.testRunner)
|
2013-05-25 23:56:01 +00:00
|
|
|
testRunner.setPageVisibility("unloaded");
|
2012-03-30 14:04:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-09 11:00:47 +00:00
|
|
|
function checkIsPageVisible() {
|
2013-05-25 23:56:01 +00:00
|
|
|
shouldBeEqualToString("document.visibilityState", "visible");
|
|
|
|
shouldBeFalse("document.hidden");
|
2017-06-23 15:44:30 +00:00
|
|
|
shouldBeFalse("internals.scriptedAnimationsAreSuspended");
|
2011-05-09 11:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkIsPageHidden() {
|
2013-05-25 23:56:01 +00:00
|
|
|
shouldBeEqualToString("document.visibilityState", "hidden");
|
|
|
|
shouldBeTrue("document.hidden");
|
2017-06-23 15:44:30 +00:00
|
|
|
shouldBeTrue("internals.scriptedAnimationsAreSuspended");
|
2011-05-09 11:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We will try to change the visibility states as:
|
|
|
|
// 0 - visible. (Initial - i.e. on load).
|
|
|
|
// 1 - hidden (should fire event).
|
|
|
|
// 2 - hidden (no event).
|
Merge PageVisibilityState & ViewState::IsVisible in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=126214
Reviewed by Alexey Proskuryakov.
WebKit2 redundantly tracks the visibility of the view through two mechanisms - the visibility
state, and the view state. Remove visibility state from the WebKit2 layer. The visibility
state also tracks the prerender state - so split this out and handle it separately (a change
we should make in WebCore, too).
Source/WebCore:
WebCore - changes the API tests exposed a bug, a view should only ever come out of the
prerender state when it becomes visible - redundant notifications that the view is still
hidden should be ignored.
* page/Page.cpp:
(WebCore::Page::setVisibilityState):
- ignore visibility state change to hidden, if the current state is prerender.
Source/WebKit2:
Removing the redundancy also removes the ability from the API to set a fake visibility state
(IsVisible tracks the actual visibility of the view). Through private API
(WKPageSetVisibilityState) a client could previously request the view be reported as hidden or
visible, but this didn't really work - the override was not enforced and the API may reset the
state at an arbitrary point. The mechanism is only used by testing code, which instead should
actually update the view visibility (this tests more of the actual visibility mechanisms used
by the browser). The one aspect of the API relied on by existing clients is the ability to
initialize a hidden view as prerender - continue to support this specific functionality via
WKPageSetVisibilityState, to maintain backwards compatibility.
- WebKit2 - remove internal state that tracks page visibility separately from the view state
visibility. For backwards compatibility continue to support the WKPageSetVisibilityState API,
but only to initialize the state to prerender.
* UIProcess/API/C/WKPage.cpp:
(WKPageSetVisibilityState):
- only support initializing the visibility state to prerender.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
- remove m_visibilityState
(WebKit::WebPageProxy::initializeWebPage):
- no need to send initial visibility state (this is sent as a part of the creation parameters).
(WebKit::WebPageProxy::viewStateDidChange):
- no need to send visibility state change (this is sent as a part of view state).
(WebKit::WebPageProxy::setVisibilityStatePrerender):
- setVisibilityState -> setVisibilityStatePrerender.
* UIProcess/WebPageProxy.h:
- remove m_visibilityState, setVisibilityState -> setVisibilityStatePrerender.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
- added call to updateVisibilityState.
(WebKit::WebPage::setViewIsVisible):
- added call to updateVisibilityState.
(WebKit::WebPage::updateVisibilityState):
- previously setVisibilityState, updates the page visibility state according to the view state.
(WebKit::WebPage::setVisibilityStatePrerender):
- set visibility state to prerender.
* WebProcess/WebPage/WebPage.h:
- remove m_visibilityState, setVisibilityState -> setVisibilityStatePrerender.
* WebProcess/WebPage/WebPage.messages.in:
- SetVisibilityState -> SetVisibilityStatePrerender.
Tools:
Tools - WebKit2 no longer (poorly) supports a fake visibility state, so to test the page
visibility mechanisms we should actually be changing characteristics of the view that will
be detected by WebKit2 as a visibility change. This affects three things:
1) On setVisibilityState WebKitTestRunner must actually change visibility of the view.
2) The 'PageVisibilityState' test in the API tests is useless (as evidenced by the fact
that page visibility has been broken in WebKit2 for a couple of months, and didn't
catch this fact). Removed in favour of:
3) 'PageVisibilityStateWithWindowChanges' - this is the good stuff. This actually tests
the visibility mechanism. Beef this test up by adding coverage for: a) the prerender
state, b) document.hidden, and c) too many state change notifications (it already looks
for too few).
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp: Removed.
- Removed PageVisibilityState - this test was ineffective, API no longer supports this
test, and behaviour is covered by PageVisibilityStateWithWindowChanges.
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm:
(-[PageVisibilityStateDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
(runJavaScriptAlert):
- Add checking for too many calls to the alert.
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::setPrerender):
- Added methods to set visibility to prerender.
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::runTest):
- Added checking of 'document.hidden'.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setVisibilityState):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/efl/TestControllerEfl.cpp:
(WTR::TestController::setHidden):
* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::setHidden):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::TestController::setHidden):
- Add setHidden method; call this from setVisibilityState.
LayoutTests:
LayoutTests - remove test for notification on visibility state change to preerender. This test
was covering something nonsensical, and not supported by the spec - the page should never see
a visibility change to prerender, this should only be an initial state. WebKit2 API now only
allows the client to change the state to prerender without sending a notification, and there
is no sense in continuing to support the current test case, since the behaviour is neither
allowed by API nor available in web content.
The prerender state is now properly covered by API tests.
* fast/events/page-visibility-transition-test-expected.txt:
* fast/events/page-visibility-transition-test.html:
- remove test for notification on visibility state change to preerender.
Canonical link: https://commits.webkit.org/144195@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161105 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-12-27 19:46:00 +00:00
|
|
|
// 3 - visible (should fire event).
|
2011-05-09 11:00:47 +00:00
|
|
|
var numVisibilityChanges = 0;
|
|
|
|
|
|
|
|
function startTest() {
|
|
|
|
document.addEventListener(
|
2013-05-25 23:56:01 +00:00
|
|
|
"visibilitychange", onVisibilityChange, false);
|
2011-05-09 11:00:47 +00:00
|
|
|
checkIsPageVisible();
|
|
|
|
numVisibilityChanges++;
|
|
|
|
makePageHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest() {
|
2012-06-20 03:28:42 +00:00
|
|
|
if (window.testRunner) {
|
|
|
|
testRunner.resetPageVisibility();
|
2011-05-09 11:00:47 +00:00
|
|
|
}
|
|
|
|
finishJSTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onVisibilityChange() {
|
2020-04-22 01:34:57 +00:00
|
|
|
shouldBeTrue("event.bubbles");
|
2011-05-09 11:00:47 +00:00
|
|
|
if (numVisibilityChanges == 1) {
|
|
|
|
checkIsPageHidden();
|
|
|
|
numVisibilityChanges++;
|
|
|
|
makePageHidden();
|
|
|
|
checkIsPageHidden();
|
|
|
|
numVisibilityChanges++;
|
Merge PageVisibilityState & ViewState::IsVisible in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=126214
Reviewed by Alexey Proskuryakov.
WebKit2 redundantly tracks the visibility of the view through two mechanisms - the visibility
state, and the view state. Remove visibility state from the WebKit2 layer. The visibility
state also tracks the prerender state - so split this out and handle it separately (a change
we should make in WebCore, too).
Source/WebCore:
WebCore - changes the API tests exposed a bug, a view should only ever come out of the
prerender state when it becomes visible - redundant notifications that the view is still
hidden should be ignored.
* page/Page.cpp:
(WebCore::Page::setVisibilityState):
- ignore visibility state change to hidden, if the current state is prerender.
Source/WebKit2:
Removing the redundancy also removes the ability from the API to set a fake visibility state
(IsVisible tracks the actual visibility of the view). Through private API
(WKPageSetVisibilityState) a client could previously request the view be reported as hidden or
visible, but this didn't really work - the override was not enforced and the API may reset the
state at an arbitrary point. The mechanism is only used by testing code, which instead should
actually update the view visibility (this tests more of the actual visibility mechanisms used
by the browser). The one aspect of the API relied on by existing clients is the ability to
initialize a hidden view as prerender - continue to support this specific functionality via
WKPageSetVisibilityState, to maintain backwards compatibility.
- WebKit2 - remove internal state that tracks page visibility separately from the view state
visibility. For backwards compatibility continue to support the WKPageSetVisibilityState API,
but only to initialize the state to prerender.
* UIProcess/API/C/WKPage.cpp:
(WKPageSetVisibilityState):
- only support initializing the visibility state to prerender.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
- remove m_visibilityState
(WebKit::WebPageProxy::initializeWebPage):
- no need to send initial visibility state (this is sent as a part of the creation parameters).
(WebKit::WebPageProxy::viewStateDidChange):
- no need to send visibility state change (this is sent as a part of view state).
(WebKit::WebPageProxy::setVisibilityStatePrerender):
- setVisibilityState -> setVisibilityStatePrerender.
* UIProcess/WebPageProxy.h:
- remove m_visibilityState, setVisibilityState -> setVisibilityStatePrerender.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
- added call to updateVisibilityState.
(WebKit::WebPage::setViewIsVisible):
- added call to updateVisibilityState.
(WebKit::WebPage::updateVisibilityState):
- previously setVisibilityState, updates the page visibility state according to the view state.
(WebKit::WebPage::setVisibilityStatePrerender):
- set visibility state to prerender.
* WebProcess/WebPage/WebPage.h:
- remove m_visibilityState, setVisibilityState -> setVisibilityStatePrerender.
* WebProcess/WebPage/WebPage.messages.in:
- SetVisibilityState -> SetVisibilityStatePrerender.
Tools:
Tools - WebKit2 no longer (poorly) supports a fake visibility state, so to test the page
visibility mechanisms we should actually be changing characteristics of the view that will
be detected by WebKit2 as a visibility change. This affects three things:
1) On setVisibilityState WebKitTestRunner must actually change visibility of the view.
2) The 'PageVisibilityState' test in the API tests is useless (as evidenced by the fact
that page visibility has been broken in WebKit2 for a couple of months, and didn't
catch this fact). Removed in favour of:
3) 'PageVisibilityStateWithWindowChanges' - this is the good stuff. This actually tests
the visibility mechanism. Beef this test up by adding coverage for: a) the prerender
state, b) document.hidden, and c) too many state change notifications (it already looks
for too few).
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/PageVisibilityState.cpp: Removed.
- Removed PageVisibilityState - this test was ineffective, API no longer supports this
test, and behaviour is covered by PageVisibilityStateWithWindowChanges.
* TestWebKitAPI/Tests/mac/PageVisibilityStateWithWindowChanges.mm:
(-[PageVisibilityStateDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
(runJavaScriptAlert):
- Add checking for too many calls to the alert.
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::setPrerender):
- Added methods to set visibility to prerender.
(TestWebKitAPI::PageVisibilityStateWithWindowChanges::runTest):
- Added checking of 'document.hidden'.
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setVisibilityState):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/efl/TestControllerEfl.cpp:
(WTR::TestController::setHidden):
* WebKitTestRunner/gtk/TestControllerGtk.cpp:
(WTR::TestController::setHidden):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::TestController::setHidden):
- Add setHidden method; call this from setVisibilityState.
LayoutTests:
LayoutTests - remove test for notification on visibility state change to preerender. This test
was covering something nonsensical, and not supported by the spec - the page should never see
a visibility change to prerender, this should only be an initial state. WebKit2 API now only
allows the client to change the state to prerender without sending a notification, and there
is no sense in continuing to support the current test case, since the behaviour is neither
allowed by API nor available in web content.
The prerender state is now properly covered by API tests.
* fast/events/page-visibility-transition-test-expected.txt:
* fast/events/page-visibility-transition-test.html:
- remove test for notification on visibility state change to preerender.
Canonical link: https://commits.webkit.org/144195@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161105 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-12-27 19:46:00 +00:00
|
|
|
makePageVisible();
|
2011-05-09 11:00:47 +00:00
|
|
|
return;
|
|
|
|
} else if (numVisibilityChanges == 2) {
|
|
|
|
testFailed("Invalid event fired on same state change.");
|
|
|
|
finishTest();
|
|
|
|
return;
|
|
|
|
} else if (numVisibilityChanges == 3) {
|
|
|
|
checkIsPageVisible();
|
|
|
|
numVisibilityChanges++;
|
|
|
|
finishTest();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
testFailed("Too many visibility transitions");
|
|
|
|
finishTest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-10-15 23:46:03 +00:00
|
|
|
|
2011-05-09 11:00:47 +00:00
|
|
|
</script>
|
|
|
|
|
2013-09-07 23:07:25 +00:00
|
|
|
<script src="../../resources/js-test-post.js"></script>
|
2011-05-09 11:00:47 +00:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|