|
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; |
|
6 let testStep = -1; |
|
7 let tabEvents = ""; |
|
8 |
|
9 function test() { |
|
10 if (!isTiltEnabled()) { |
|
11 info("Skipping notifications test because Tilt isn't enabled."); |
|
12 return; |
|
13 } |
|
14 if (!isWebGLSupported()) { |
|
15 info("Skipping notifications test because WebGL isn't supported."); |
|
16 return; |
|
17 } |
|
18 |
|
19 requestLongerTimeout(10); |
|
20 waitForExplicitFinish(); |
|
21 |
|
22 gBrowser.tabContainer.addEventListener("TabSelect", tabSelect, false); |
|
23 createNewTab(); |
|
24 } |
|
25 |
|
26 function createNewTab() { |
|
27 tab0 = gBrowser.selectedTab; |
|
28 |
|
29 tab1 = createTab(function() { |
|
30 Services.obs.addObserver(finalize, DESTROYED, false); |
|
31 Services.obs.addObserver(tab_STARTUP, STARTUP, false); |
|
32 Services.obs.addObserver(tab_INITIALIZING, INITIALIZING, false); |
|
33 Services.obs.addObserver(tab_DESTROYING, DESTROYING, false); |
|
34 Services.obs.addObserver(tab_SHOWN, SHOWN, false); |
|
35 Services.obs.addObserver(tab_HIDDEN, HIDDEN, false); |
|
36 |
|
37 info("Starting up the Tilt notifications test."); |
|
38 createTilt({ |
|
39 onTiltOpen: function() |
|
40 { |
|
41 testStep = 0; |
|
42 tabSelect(); |
|
43 } |
|
44 }, false, function suddenDeath() |
|
45 { |
|
46 info("Tilt could not be initialized properly."); |
|
47 cleanup(); |
|
48 }); |
|
49 }); |
|
50 } |
|
51 |
|
52 function tab_STARTUP(win) { |
|
53 info("Handling the STARTUP notification."); |
|
54 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
55 tabEvents += "STARTUP;"; |
|
56 } |
|
57 |
|
58 function tab_INITIALIZING(win) { |
|
59 info("Handling the INITIALIZING notification."); |
|
60 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
61 tabEvents += "INITIALIZING;"; |
|
62 } |
|
63 |
|
64 function tab_DESTROYING(win) { |
|
65 info("Handling the DESTROYING notification."); |
|
66 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
67 tabEvents += "DESTROYING;"; |
|
68 } |
|
69 |
|
70 function tab_SHOWN(win) { |
|
71 info("Handling the SHOWN notification."); |
|
72 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
73 tabEvents += "SHOWN;"; |
|
74 } |
|
75 |
|
76 function tab_HIDDEN(win) { |
|
77 info("Handling the HIDDEN notification."); |
|
78 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
79 tabEvents += "HIDDEN;"; |
|
80 } |
|
81 |
|
82 let testSteps = [ |
|
83 function step0() { |
|
84 info("Selecting tab0."); |
|
85 gBrowser.selectedTab = tab0; |
|
86 }, |
|
87 function step1() { |
|
88 info("Selecting tab1."); |
|
89 gBrowser.selectedTab = tab1; |
|
90 }, |
|
91 function step2() { |
|
92 info("Killing it."); |
|
93 Tilt.destroy(Tilt.currentWindowId, true); |
|
94 } |
|
95 ]; |
|
96 |
|
97 function finalize(win) { |
|
98 if (!tabEvents) { |
|
99 return; |
|
100 } |
|
101 |
|
102 is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); |
|
103 |
|
104 is(tabEvents, "STARTUP;INITIALIZING;HIDDEN;SHOWN;DESTROYING;", |
|
105 "The notifications weren't fired in the correct order."); |
|
106 |
|
107 cleanup(); |
|
108 } |
|
109 |
|
110 function cleanup() { |
|
111 info("Cleaning up the notifications test."); |
|
112 |
|
113 tab0 = null; |
|
114 tab1 = null; |
|
115 |
|
116 Services.obs.removeObserver(finalize, DESTROYED); |
|
117 Services.obs.removeObserver(tab_INITIALIZING, INITIALIZING); |
|
118 Services.obs.removeObserver(tab_DESTROYING, DESTROYING); |
|
119 Services.obs.removeObserver(tab_SHOWN, SHOWN); |
|
120 Services.obs.removeObserver(tab_HIDDEN, HIDDEN); |
|
121 Services.obs.removeObserver(tab_STARTUP, STARTUP); |
|
122 |
|
123 gBrowser.tabContainer.removeEventListener("TabSelect", tabSelect); |
|
124 gBrowser.removeCurrentTab(); |
|
125 finish(); |
|
126 } |
|
127 |
|
128 function tabSelect() { |
|
129 if (testStep !== -1) { |
|
130 executeSoon(testSteps[testStep]); |
|
131 testStep++; |
|
132 } |
|
133 } |