Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / page-visibility-transition-test.html
blob0084edf225fe13c6f9d2e88e1e9c9ff03db181fb
1 <html>
2 <body onload='startTest()'>
4 <script src="../../resources/js-test.js"></script>
6 <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);
53 checkIsPageVisible();
54 numVisibilityChanges++;
55 makePageHidden();
58 function onVisibilityChange() {
59 if (numVisibilityChanges == 1) {
60 checkIsPageHidden();
61 numVisibilityChanges++;
62 makePageHidden();
63 checkIsPageHidden();
64 numVisibilityChanges++;
65 makePagePrerender();
66 return;
67 } else if (numVisibilityChanges == 2) {
68 testFailed("Invalid event fired on same state change.");
69 finishJSTest();
70 return;
71 } else if (numVisibilityChanges == 3) {
72 checkIsPagePrerendering();
73 numVisibilityChanges++;
74 makePageVisible();
75 return;
76 } else if (numVisibilityChanges == 4) {
77 checkIsPageVisible();
78 numVisibilityChanges++;
79 finishJSTest();
80 return;
81 } else {
82 testFailed("Too many visibility transitions");
83 finishJSTest();
84 return;
88 </script>
91 </body>
92 </html>