|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 "use strict"; |
|
4 |
|
5 let tab0, tab1, tab2; |
|
6 let testStep = -1; |
|
7 |
|
8 let expected = []; |
|
9 function expect(notification, win) { |
|
10 expected.push({ notification: notification, window: win }); |
|
11 } |
|
12 |
|
13 function notification(win, topic) { |
|
14 if (expected.length == 0) { |
|
15 is(topic, null, "Shouldn't see a notification"); |
|
16 return; |
|
17 } |
|
18 |
|
19 let { notification, window } = expected.shift(); |
|
20 is(topic, notification, "Saw the expected notification"); |
|
21 is(win, window, "Saw the expected window"); |
|
22 } |
|
23 |
|
24 function after(notification, callback) { |
|
25 function observer() { |
|
26 Services.obs.removeObserver(observer, notification); |
|
27 executeSoon(callback); |
|
28 } |
|
29 Services.obs.addObserver(observer, notification, false); |
|
30 } |
|
31 |
|
32 function test() { |
|
33 if (!isTiltEnabled()) { |
|
34 info("Skipping tab switch test because Tilt isn't enabled."); |
|
35 return; |
|
36 } |
|
37 if (!isWebGLSupported()) { |
|
38 info("Skipping tab switch test because WebGL isn't supported."); |
|
39 return; |
|
40 } |
|
41 |
|
42 Services.obs.addObserver(notification, STARTUP, false); |
|
43 Services.obs.addObserver(notification, INITIALIZING, false); |
|
44 Services.obs.addObserver(notification, INITIALIZED, false); |
|
45 Services.obs.addObserver(notification, DESTROYING, false); |
|
46 Services.obs.addObserver(notification, BEFORE_DESTROYED, false); |
|
47 Services.obs.addObserver(notification, DESTROYED, false); |
|
48 Services.obs.addObserver(notification, SHOWN, false); |
|
49 Services.obs.addObserver(notification, HIDDEN, false); |
|
50 |
|
51 waitForExplicitFinish(); |
|
52 |
|
53 tab0 = gBrowser.selectedTab; |
|
54 nextStep(); |
|
55 } |
|
56 |
|
57 function createTab2() { |
|
58 } |
|
59 |
|
60 let testSteps = [ |
|
61 function step0() { |
|
62 tab1 = createTab(function() { |
|
63 expect(STARTUP, tab1.linkedBrowser.contentWindow); |
|
64 expect(INITIALIZING, tab1.linkedBrowser.contentWindow); |
|
65 expect(INITIALIZED, tab1.linkedBrowser.contentWindow); |
|
66 after(INITIALIZED, nextStep); |
|
67 |
|
68 createTilt({}, false, function suddenDeath() |
|
69 { |
|
70 info("Tilt could not be initialized properly."); |
|
71 cleanup(); |
|
72 }); |
|
73 }); |
|
74 }, |
|
75 function step1() { |
|
76 expect(HIDDEN, tab1.linkedBrowser.contentWindow); |
|
77 |
|
78 tab2 = createTab(function() { |
|
79 expect(STARTUP, tab2.linkedBrowser.contentWindow); |
|
80 expect(INITIALIZING, tab2.linkedBrowser.contentWindow); |
|
81 expect(INITIALIZED, tab2.linkedBrowser.contentWindow); |
|
82 after(INITIALIZED, nextStep); |
|
83 |
|
84 createTilt({}, false, function suddenDeath() |
|
85 { |
|
86 info("Tilt could not be initialized properly."); |
|
87 cleanup(); |
|
88 }); |
|
89 }); |
|
90 }, |
|
91 function step2() { |
|
92 expect(HIDDEN, tab2.linkedBrowser.contentWindow); |
|
93 after(HIDDEN, nextStep); |
|
94 |
|
95 gBrowser.selectedTab = tab0; |
|
96 }, |
|
97 function step3() { |
|
98 expect(SHOWN, tab2.linkedBrowser.contentWindow); |
|
99 after(SHOWN, nextStep); |
|
100 |
|
101 gBrowser.selectedTab = tab2; |
|
102 }, |
|
103 function step4() { |
|
104 expect(HIDDEN, tab2.linkedBrowser.contentWindow); |
|
105 expect(SHOWN, tab1.linkedBrowser.contentWindow); |
|
106 after(SHOWN, nextStep); |
|
107 |
|
108 gBrowser.selectedTab = tab1; |
|
109 }, |
|
110 function step5() { |
|
111 expect(HIDDEN, tab1.linkedBrowser.contentWindow); |
|
112 expect(SHOWN, tab2.linkedBrowser.contentWindow); |
|
113 after(SHOWN, nextStep); |
|
114 |
|
115 gBrowser.selectedTab = tab2; |
|
116 }, |
|
117 function step6() { |
|
118 expect(DESTROYING, tab2.linkedBrowser.contentWindow); |
|
119 expect(BEFORE_DESTROYED, tab2.linkedBrowser.contentWindow); |
|
120 expect(DESTROYED, tab2.linkedBrowser.contentWindow); |
|
121 after(DESTROYED, nextStep); |
|
122 |
|
123 Tilt.destroy(Tilt.currentWindowId, true); |
|
124 }, |
|
125 function step7() { |
|
126 expect(SHOWN, tab1.linkedBrowser.contentWindow); |
|
127 |
|
128 gBrowser.removeCurrentTab(); |
|
129 tab2 = null; |
|
130 |
|
131 expect(DESTROYING, tab1.linkedBrowser.contentWindow); |
|
132 expect(HIDDEN, tab1.linkedBrowser.contentWindow); |
|
133 expect(BEFORE_DESTROYED, tab1.linkedBrowser.contentWindow); |
|
134 expect(DESTROYED, tab1.linkedBrowser.contentWindow); |
|
135 after(DESTROYED, nextStep); |
|
136 |
|
137 gBrowser.removeCurrentTab(); |
|
138 tab1 = null; |
|
139 }, |
|
140 function step8_cleanup() { |
|
141 is(gBrowser.selectedTab, tab0, "Should be back to the first tab"); |
|
142 |
|
143 cleanup(); |
|
144 } |
|
145 ]; |
|
146 |
|
147 function cleanup() { |
|
148 if (tab1) { |
|
149 gBrowser.removeTab(tab1); |
|
150 tab1 = null; |
|
151 } |
|
152 if (tab2) { |
|
153 gBrowser.removeTab(tab2); |
|
154 tab2 = null; |
|
155 } |
|
156 |
|
157 Services.obs.removeObserver(notification, STARTUP); |
|
158 Services.obs.removeObserver(notification, INITIALIZING); |
|
159 Services.obs.removeObserver(notification, INITIALIZED); |
|
160 Services.obs.removeObserver(notification, DESTROYING); |
|
161 Services.obs.removeObserver(notification, BEFORE_DESTROYED); |
|
162 Services.obs.removeObserver(notification, DESTROYED); |
|
163 Services.obs.removeObserver(notification, SHOWN); |
|
164 Services.obs.removeObserver(notification, HIDDEN); |
|
165 |
|
166 finish(); |
|
167 } |
|
168 |
|
169 function nextStep() { |
|
170 let step = testSteps.shift(); |
|
171 info("Executing " + step.name); |
|
172 step(); |
|
173 } |