Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / page-visibility-iframe-propagation-test.html
blobd9e6f6515cec22f321b59040763bfb18fb3612b5
1 <html>
2 <body>
4 <script src="../../resources/js-test.js"></script>
6 <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() {
23 debug("Main Page:");
24 shouldBeEqualToString("document.visibilityState", "visible");
25 shouldBeFalse("document.hidden");
28 function checkIsPageHidden() {
29 debug("Main Page:");
30 shouldBeEqualToString("document.visibilityState", "hidden");
31 shouldBeTrue("document.hidden");
34 function checkIsChildFrameVisible() {
35 debug("Child Frame:");
36 shouldBeEqualToString("childFrame.contentDocument.visibilityState",
37 "visible");
38 shouldBeFalse("childFrame.contentDocument.hidden");
41 function checkIsChildFrameHidden() {
42 debug("Child Frame:");
43 shouldBeEqualToString("childFrame.contentDocument.visibilityState",
44 "hidden");
45 shouldBeTrue("childFrame.contentDocument.hidden");
48 // We will try to change the visibility states as:
49 // 0 - visible. (Initial - i.e. on load).
50 // 1 - hidden
51 // 2 - visible
52 var numVisibilityChanges = 0;
54 var childFrame;
56 function startTest() {
57 childFrame = document.getElementById("childFrame");
58 childFrame.contentDocument.addEventListener(
59 "visibilitychange", onChildFrameVisibilityChange, false);
60 document.addEventListener("visibilitychange",
61 onVisibilityChange, false);
63 checkIsPageVisible();
64 checkIsChildFrameVisible();
66 numVisibilityChanges++;
67 makePageHidden();
70 var numFinishes = 0;
71 function finishTest() {
72 numFinishes++;
73 if (numFinishes < 2) {
74 return;
76 finishJSTest();
79 function onVisibilityChange() {
80 if (numVisibilityChanges == 1) {
81 checkIsPageHidden();
82 return;
83 } else if (numVisibilityChanges == 2) {
84 checkIsPageVisible();
85 finishTest();
86 return;
87 } else {
88 testFailed("Too many visibility transitions");
89 finishTest();
90 return;
94 function onChildFrameVisibilityChange() {
95 if (numVisibilityChanges == 1) {
96 checkIsChildFrameHidden();
97 numVisibilityChanges++;
98 makePageVisible();
99 return;
100 } else if (numVisibilityChanges == 2) {
101 checkIsChildFrameVisible();
102 finishTest();
103 return;
104 } else {
105 testFailed("Child Frame: Too many visibility transitions");
106 finishTest();
110 </script>
113 <iframe id="childFrame" onload="startTest()"></iframe>
114 </body>
115 </html>