4 <script src="../js/resources/js-test-pre.js"></script>
8 description("This test checks that Page Visibility state events are propagated to child frames.");
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 checkIsPageVisible() {
24 shouldBeEqualToString("document.webkitVisibilityState", "visible");
25 shouldBeFalse("document.webkitHidden");
28 function checkIsPageHidden() {
30 shouldBeEqualToString("document.webkitVisibilityState", "hidden");
31 shouldBeTrue("document.webkitHidden");
34 function checkIsChildFrameVisible() {
35 debug("Child Frame:");
36 shouldBeEqualToString("childFrame.contentDocument.webkitVisibilityState",
38 shouldBeFalse("childFrame.contentDocument.webkitHidden");
41 function checkIsChildFrameHidden() {
42 debug("Child Frame:");
43 shouldBeEqualToString("childFrame.contentDocument.webkitVisibilityState",
45 shouldBeTrue("childFrame.contentDocument.webkitHidden");
48 // We will try to change the visibility states as:
49 // 0 - visible. (Initial - i.e. on load).
52 var numVisibilityChanges = 0;
56 function startTest() {
57 childFrame = document.getElementById("childFrame");
58 childFrame.contentDocument.addEventListener(
59 "webkitvisibilitychange", onChildFrameVisibilityChange, false);
60 document.addEventListener("webkitvisibilitychange",
61 onVisibilityChange, false);
64 checkIsChildFrameVisible();
66 numVisibilityChanges++;
71 function finishTest() {
73 if (numFinishes < 2) {
77 if (window.testRunner) {
78 testRunner.resetPageVisibility();
83 function onVisibilityChange() {
84 if (numVisibilityChanges == 1) {
87 } else if (numVisibilityChanges == 2) {
92 testFailed("Too many visibility transitions");
98 function onChildFrameVisibilityChange() {
99 if (numVisibilityChanges == 1) {
100 checkIsChildFrameHidden();
101 numVisibilityChanges++;
104 } else if (numVisibilityChanges == 2) {
105 checkIsChildFrameVisible();
109 testFailed("Child Frame: Too many visibility transitions");
116 <script src="../js/resources/js-test-post.js"></script>
118 <iframe id="childFrame" onload="startTest()"></iframe>