|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 |
|
4 <window id="690056Test" |
|
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
6 width="600" |
|
7 height="600" |
|
8 onload="setTimeout(nextTest,0);" |
|
9 title="bug 6500056 test"> |
|
10 |
|
11 <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> |
|
12 <script type="application/javascript" src="docshell_helpers.js" /> |
|
13 <script type="application/javascript"><![CDATA[ |
|
14 var tests = testIterator(); |
|
15 |
|
16 function nextTest() { |
|
17 tests.next(); |
|
18 } |
|
19 |
|
20 // Makes sure that we fire the visibilitychange events |
|
21 function testIterator() { |
|
22 // Enable bfcache |
|
23 enableBFCache(8); |
|
24 |
|
25 // Load something for a start |
|
26 doPageNavigation({ |
|
27 uri: 'data:text/html,<title>initial load</title>', |
|
28 onNavComplete: nextTest |
|
29 }); |
|
30 yield undefined; |
|
31 |
|
32 // Now load a new page |
|
33 doPageNavigation({ |
|
34 uri: 'data:text/html,<title>new load</title>', |
|
35 eventsToListenFor: [ "pageshow", "pagehide", "visibilitychange" ], |
|
36 expectedEvents: [ { type: "pagehide", |
|
37 title: "initial load", |
|
38 persisted: true }, |
|
39 { type: "visibilitychange", |
|
40 title: "initial load", |
|
41 visibilityState: "hidden", |
|
42 hidden: true }, |
|
43 // No visibilitychange events fired for initial pageload |
|
44 { type: "pageshow", |
|
45 title: "new load", |
|
46 persisted: false }, // false on initial load |
|
47 ], |
|
48 onNavComplete: nextTest |
|
49 }); |
|
50 yield undefined; |
|
51 |
|
52 // Now go back |
|
53 doPageNavigation({ |
|
54 back: true, |
|
55 eventsToListenFor: [ "pageshow", "pagehide", "visibilitychange" ], |
|
56 expectedEvents: [ { type: "pagehide", |
|
57 title: "new load", |
|
58 persisted: true }, |
|
59 { type: "visibilitychange", |
|
60 title: "new load", |
|
61 visibilityState: "hidden", |
|
62 hidden: true }, |
|
63 { type: "visibilitychange", |
|
64 title: "initial load", |
|
65 visibilityState: "visible", |
|
66 hidden: false }, |
|
67 { type: "pageshow", |
|
68 title: "initial load", |
|
69 persisted: true }, |
|
70 ], |
|
71 onNavComplete: nextTest |
|
72 }); |
|
73 yield undefined; |
|
74 |
|
75 // And forward |
|
76 doPageNavigation({ |
|
77 forward: true, |
|
78 eventsToListenFor: [ "pageshow", "pagehide", "visibilitychange" ], |
|
79 expectedEvents: [ { type: "pagehide", |
|
80 title: "initial load", |
|
81 persisted: true }, |
|
82 { type: "visibilitychange", |
|
83 title: "initial load", |
|
84 visibilityState: "hidden", |
|
85 hidden: true }, |
|
86 { type: "visibilitychange", |
|
87 title: "new load", |
|
88 visibilityState: "visible", |
|
89 hidden: false }, |
|
90 { type: "pageshow", |
|
91 title: "new load", |
|
92 persisted: true }, |
|
93 ], |
|
94 onNavComplete: nextTest |
|
95 }); |
|
96 yield undefined; |
|
97 |
|
98 function generateDetector(state, hidden, title, name) { |
|
99 var detector = function (event) { |
|
100 is(event.target.hidden, hidden, |
|
101 name + " hidden value does not match"); |
|
102 is(event.target.visibilityState, state, |
|
103 name + " state value does not match"); |
|
104 is(event.target.title, title, |
|
105 name + " title value does not match"); |
|
106 document.getElementById("content") |
|
107 .removeEventListener("visibilitychange", |
|
108 detector, |
|
109 true); |
|
110 nextTest(); |
|
111 } |
|
112 |
|
113 document.getElementById("content") |
|
114 .addEventListener("visibilitychange", detector, true); |
|
115 } |
|
116 |
|
117 generateDetector("hidden", true, "new load", "Going hidden"); |
|
118 |
|
119 // Now flip our docshell to not active |
|
120 document.getElementById("content").docShellIsActive = false; |
|
121 yield undefined; |
|
122 |
|
123 // And navigate back; there should be no visibility state transitions |
|
124 doPageNavigation({ |
|
125 back: true, |
|
126 eventsToListenFor: [ "pageshow", "pagehide", "visibilitychange" ], |
|
127 expectedEvents: [ { type: "pagehide", |
|
128 title: "new load", |
|
129 persisted: true }, |
|
130 { type: "pageshow", |
|
131 title: "initial load", |
|
132 persisted: true }, |
|
133 ], |
|
134 unexpectedEvents: [ "visibilitychange" ], |
|
135 onNavComplete: nextTest |
|
136 }); |
|
137 yield undefined; |
|
138 |
|
139 generateDetector("visible", false, "initial load", "Going visible"); |
|
140 |
|
141 // Now set the docshell active again |
|
142 document.getElementById("content").docShellIsActive = true; |
|
143 yield undefined; |
|
144 |
|
145 // And forward |
|
146 doPageNavigation({ |
|
147 forward: true, |
|
148 eventsToListenFor: [ "pageshow", "pagehide", "visibilitychange" ], |
|
149 expectedEvents: [ { type: "pagehide", |
|
150 title: "initial load", |
|
151 persisted: true }, |
|
152 { type: "visibilitychange", |
|
153 title: "initial load", |
|
154 visibilityState: "hidden", |
|
155 hidden: true }, |
|
156 { type: "visibilitychange", |
|
157 title: "new load", |
|
158 visibilityState: "visible", |
|
159 hidden: false }, |
|
160 { type: "pageshow", |
|
161 title: "new load", |
|
162 persisted: true }, |
|
163 ], |
|
164 onNavComplete: nextTest |
|
165 }); |
|
166 yield undefined; |
|
167 |
|
168 // Tell the framework the test is finished. Include the final 'yield' |
|
169 // statement to prevent a StopIteration exception from being thrown. |
|
170 finish(); |
|
171 yield undefined; |
|
172 } |
|
173 ]]></script> |
|
174 |
|
175 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
176 </window> |