2 <body onload="startTest()">
4 <script src="../js/resources/js-test-pre.js"></script>
8 description("This test checks that the page visibility event proagation does not crash the browser when frames are added / deleted.");
10 var jsTestIsAsync = true;
12 var numVisibilityChanges = 0;
13 var frame1, frame2, frame3, frame4, frame5, subframe1, subFrame2, subFrame3;
16 var mainPageVisibilityChangeDone = false;
17 var frame2VisiblityChangeDone = false;
19 function startTest() {
25 debug("Loaded all frames.");
27 frame1 = document.getElementById("topFrame1");
28 frame2 = document.getElementById("topFrame2");
29 frame3 = document.getElementById("topFrame3");
30 frame4 = document.getElementById("topFrame4");
31 subFrame1 = frame3.contentDocument.getElementById("subIframe1");
32 subFrame2 = frame3.contentDocument.getElementById("subIframe2");
34 document.addEventListener(
35 "webkitvisibilitychange", onMainPageVisibilityChange, false);
36 frame2.contentDocument.addEventListener(
37 "webkitvisibilitychange", onFrame2VisibilityChange, false);
38 // Change the visibility of the current page to invisible.
39 if (window.testRunner) {
40 numVisibilityChanges++;
41 testRunner.setPageVisibility("hidden");
45 function finishTest() {
46 if (window.testRunner)
47 testRunner.resetPageVisibility();
51 function onMainPageVisibilityChange() {
52 if (mainPageVisibilityChangeDone && frame2VisiblityChangeDone) {
54 } else if (!mainPageVisibilityChangeDone) {
55 debug("Visibility of main document changed.");
57 document.body.removeChild(frame4);
60 frame3.contentDocument.body.removeChild(subFrame2);
62 // Add a new frame to top level.
63 frame5 = document.createElement("iframe");
65 document.body.appendChild(frame5);
67 // Add a new frame to frame2.
68 subFrame3 = frame2.contentDocument.createElement("iframe");
70 frame2.contentDocument.body.appendChild(subFrame3);
72 mainPageVisibilityChangeDone = true;
75 if (mainPageVisibilityChangeDone && frame2VisiblityChangeDone) {
80 function onFrame2VisibilityChange() {
81 if (mainPageVisibilityChangeDone && frame2VisiblityChangeDone) {
83 } else if (!frame2VisiblityChangeDone) {
84 debug("Visibility of sub frame 2 changed.");
87 document.body.removeChild(frame1);
89 frame2VisiblityChangeDone = true;
92 if (mainPageVisibilityChangeDone && frame2VisiblityChangeDone) {
99 <script src="../js/resources/js-test-post.js"></script>
101 <iframe id="topFrame1" onload="startTest()" ></iframe>
102 <iframe id="topFrame2" onload="startTest()" ></iframe>
103 <iframe id="topFrame3" onload="startTest()" src="resources/page-visibility-iframe-delete-test-frame.html"></iframe>
104 <iframe id="topFrame4" onload="startTest()" ></iframe>