2 <body onload='startTest()'
>
4 <script src=
"../../resources/js-test.js"></script>
8 description("This test checks that Page Visibility state values are correct and the event changes are fired correctly.");
10 var jsTestIsAsync
= true;
12 function makePageVisible() {
13 if (window
.testRunner
)
14 testRunner
.setPageVisibility("visible");
17 function makePageHidden() {
18 if (window
.testRunner
)
19 testRunner
.setPageVisibility("hidden");
22 function makePagePrerender() {
23 if (window
.testRunner
)
24 testRunner
.setPageVisibility("prerender");
27 function checkIsPageVisible() {
28 shouldBeEqualToString("document.visibilityState", "visible");
29 shouldBeFalse("document.hidden");
32 function checkIsPageHidden() {
33 shouldBeEqualToString("document.visibilityState", "hidden");
34 shouldBeTrue("document.hidden");
37 function checkIsPagePrerendering() {
38 shouldBeEqualToString("document.visibilityState", "prerender");
39 shouldBeTrue("document.hidden");
42 // We will try to change the visibility states as:
43 // 0 - visible. (Initial - i.e. on load).
44 // 1 - hidden (should fire event).
45 // 2 - hidden (no event).
46 // 3 - prerender (should fire event).
47 // 4 - visible (should fire event).
48 var numVisibilityChanges
= 0;
50 function startTest() {
51 document
.addEventListener(
52 "visibilitychange", onVisibilityChange
, false);
54 numVisibilityChanges
++;
58 function onVisibilityChange() {
59 if (numVisibilityChanges
== 1) {
61 numVisibilityChanges
++;
64 numVisibilityChanges
++;
67 } else if (numVisibilityChanges
== 2) {
68 testFailed("Invalid event fired on same state change.");
71 } else if (numVisibilityChanges
== 3) {
72 checkIsPagePrerendering();
73 numVisibilityChanges
++;
76 } else if (numVisibilityChanges
== 4) {
78 numVisibilityChanges
++;
82 testFailed("Too many visibility transitions");