4 <script src=
"../../resources/js-test.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.visibilityState", "visible");
25 shouldBeFalse("document.hidden");
28 function checkIsPageHidden() {
30 shouldBeEqualToString("document.visibilityState", "hidden");
31 shouldBeTrue("document.hidden");
34 function checkIsChildFrameVisible() {
35 debug("Child Frame:");
36 shouldBeEqualToString("childFrame.contentDocument.visibilityState",
38 shouldBeFalse("childFrame.contentDocument.hidden");
41 function checkIsChildFrameHidden() {
42 debug("Child Frame:");
43 shouldBeEqualToString("childFrame.contentDocument.visibilityState",
45 shouldBeTrue("childFrame.contentDocument.hidden");
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 "visibilitychange", onChildFrameVisibilityChange
, false);
60 document
.addEventListener("visibilitychange",
61 onVisibilityChange
, false);
64 checkIsChildFrameVisible();
66 numVisibilityChanges
++;
71 function finishTest() {
73 if (numFinishes
< 2) {
79 function onVisibilityChange() {
80 if (numVisibilityChanges
== 1) {
83 } else if (numVisibilityChanges
== 2) {
88 testFailed("Too many visibility transitions");
94 function onChildFrameVisibilityChange() {
95 if (numVisibilityChanges
== 1) {
96 checkIsChildFrameHidden();
97 numVisibilityChanges
++;
100 } else if (numVisibilityChanges
== 2) {
101 checkIsChildFrameVisible();
105 testFailed("Child Frame: Too many visibility transitions");
113 <iframe id=
"childFrame" onload=
"startTest()"></iframe>