|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 let gTestTab; |
|
7 let gContentAPI; |
|
8 let gContentWindow; |
|
9 |
|
10 Components.utils.import("resource:///modules/UITour.jsm"); |
|
11 |
|
12 function test() { |
|
13 UITourTest(); |
|
14 } |
|
15 |
|
16 let tests = [ |
|
17 function test_untrusted_host(done) { |
|
18 loadUITourTestPage(function() { |
|
19 let bookmarksMenu = document.getElementById("bookmarks-menu-button"); |
|
20 ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); |
|
21 |
|
22 gContentAPI.showMenu("bookmarks"); |
|
23 ise(bookmarksMenu.open, false, "Bookmark menu should not open on a untrusted host"); |
|
24 |
|
25 done(); |
|
26 }, "http://mochi.test:8888/"); |
|
27 }, |
|
28 function test_unsecure_host(done) { |
|
29 loadUITourTestPage(function() { |
|
30 let bookmarksMenu = document.getElementById("bookmarks-menu-button"); |
|
31 ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); |
|
32 |
|
33 gContentAPI.showMenu("bookmarks"); |
|
34 ise(bookmarksMenu.open, false, "Bookmark menu should not open on a unsecure host"); |
|
35 |
|
36 done(); |
|
37 }, "http://example.com/"); |
|
38 }, |
|
39 function test_unsecure_host_override(done) { |
|
40 Services.prefs.setBoolPref("browser.uitour.requireSecure", false); |
|
41 loadUITourTestPage(function() { |
|
42 let highlight = document.getElementById("UITourHighlight"); |
|
43 is_element_hidden(highlight, "Highlight should initially be hidden"); |
|
44 |
|
45 gContentAPI.showHighlight("urlbar"); |
|
46 waitForElementToBeVisible(highlight, done, "Highlight should be shown on a unsecure host when override pref is set"); |
|
47 |
|
48 Services.prefs.setBoolPref("browser.uitour.requireSecure", true); |
|
49 }, "http://example.com/"); |
|
50 }, |
|
51 function test_disabled(done) { |
|
52 Services.prefs.setBoolPref("browser.uitour.enabled", false); |
|
53 |
|
54 let bookmarksMenu = document.getElementById("bookmarks-menu-button"); |
|
55 ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); |
|
56 |
|
57 gContentAPI.showMenu("bookmarks"); |
|
58 ise(bookmarksMenu.open, false, "Bookmark menu should not open when feature is disabled"); |
|
59 |
|
60 Services.prefs.setBoolPref("browser.uitour.enabled", true); |
|
61 done(); |
|
62 }, |
|
63 function test_highlight(done) { |
|
64 function test_highlight_2() { |
|
65 let highlight = document.getElementById("UITourHighlight"); |
|
66 gContentAPI.hideHighlight(); |
|
67 is_element_hidden(highlight, "Highlight should be hidden after hideHighlight()"); |
|
68 |
|
69 gContentAPI.showHighlight("urlbar"); |
|
70 waitForElementToBeVisible(highlight, test_highlight_3, "Highlight should be shown after showHighlight()"); |
|
71 } |
|
72 function test_highlight_3() { |
|
73 let highlight = document.getElementById("UITourHighlight"); |
|
74 gContentAPI.showHighlight("backForward"); |
|
75 waitForElementToBeVisible(highlight, done, "Highlight should be shown after showHighlight()"); |
|
76 } |
|
77 |
|
78 let highlight = document.getElementById("UITourHighlight"); |
|
79 is_element_hidden(highlight, "Highlight should initially be hidden"); |
|
80 |
|
81 gContentAPI.showHighlight("urlbar"); |
|
82 waitForElementToBeVisible(highlight, test_highlight_2, "Highlight should be shown after showHighlight()"); |
|
83 }, |
|
84 function test_highlight_circle(done) { |
|
85 function check_highlight_size() { |
|
86 let panel = highlight.parentElement; |
|
87 let anchor = panel.anchorNode; |
|
88 let anchorRect = anchor.getBoundingClientRect(); |
|
89 info("addons target: width: " + anchorRect.width + " height: " + anchorRect.height); |
|
90 let maxDimension = Math.round(Math.max(anchorRect.width, anchorRect.height)); |
|
91 let highlightRect = highlight.getBoundingClientRect(); |
|
92 info("highlight: width: " + highlightRect.width + " height: " + highlightRect.height); |
|
93 is(Math.round(highlightRect.width), maxDimension, "The width of the highlight should be equal to the largest dimension of the target"); |
|
94 is(Math.round(highlightRect.height), maxDimension, "The height of the highlight should be equal to the largest dimension of the target"); |
|
95 is(Math.round(highlightRect.height), Math.round(highlightRect.width), "The height and width of the highlight should be the same to create a circle"); |
|
96 is(highlight.style.borderRadius, "100%", "The border-radius should be 100% to create a circle"); |
|
97 done(); |
|
98 } |
|
99 let highlight = document.getElementById("UITourHighlight"); |
|
100 is_element_hidden(highlight, "Highlight should initially be hidden"); |
|
101 |
|
102 gContentAPI.showHighlight("addons"); |
|
103 waitForElementToBeVisible(highlight, check_highlight_size, "Highlight should be shown after showHighlight()"); |
|
104 }, |
|
105 function test_highlight_customize_auto_open_close(done) { |
|
106 let highlight = document.getElementById("UITourHighlight"); |
|
107 gContentAPI.showHighlight("customize"); |
|
108 waitForElementToBeVisible(highlight, function checkPanelIsOpen() { |
|
109 isnot(PanelUI.panel.state, "closed", "Panel should have opened"); |
|
110 |
|
111 // Move the highlight outside which should close the app menu. |
|
112 gContentAPI.showHighlight("appMenu"); |
|
113 waitForElementToBeVisible(highlight, function checkPanelIsClosed() { |
|
114 isnot(PanelUI.panel.state, "open", |
|
115 "Panel should have closed after the highlight moved elsewhere."); |
|
116 done(); |
|
117 }, "Highlight should move to the appMenu button"); |
|
118 }, "Highlight should be shown after showHighlight() for fixed panel items"); |
|
119 }, |
|
120 function test_highlight_customize_manual_open_close(done) { |
|
121 let highlight = document.getElementById("UITourHighlight"); |
|
122 // Manually open the app menu then show a highlight there. The menu should remain open. |
|
123 let shownPromise = promisePanelShown(window); |
|
124 gContentAPI.showMenu("appMenu"); |
|
125 shownPromise.then(() => { |
|
126 isnot(PanelUI.panel.state, "closed", "Panel should have opened"); |
|
127 gContentAPI.showHighlight("customize"); |
|
128 |
|
129 waitForElementToBeVisible(highlight, function checkPanelIsStillOpen() { |
|
130 isnot(PanelUI.panel.state, "closed", "Panel should still be open"); |
|
131 |
|
132 // Move the highlight outside which shouldn't close the app menu since it was manually opened. |
|
133 gContentAPI.showHighlight("appMenu"); |
|
134 waitForElementToBeVisible(highlight, function () { |
|
135 isnot(PanelUI.panel.state, "closed", |
|
136 "Panel should remain open since UITour didn't open it in the first place"); |
|
137 gContentAPI.hideMenu("appMenu"); |
|
138 done(); |
|
139 }, "Highlight should move to the appMenu button"); |
|
140 }, "Highlight should be shown after showHighlight() for fixed panel items"); |
|
141 }).then(null, Components.utils.reportError); |
|
142 }, |
|
143 function test_highlight_effect(done) { |
|
144 function waitForHighlightWithEffect(highlightEl, effect, next, error) { |
|
145 return waitForCondition(() => highlightEl.getAttribute("active") == effect, |
|
146 next, |
|
147 error); |
|
148 } |
|
149 function checkDefaultEffect() { |
|
150 is(highlight.getAttribute("active"), "none", "The default should be no effect"); |
|
151 |
|
152 gContentAPI.showHighlight("urlbar", "none"); |
|
153 waitForHighlightWithEffect(highlight, "none", checkZoomEffect, "There should be no effect"); |
|
154 } |
|
155 function checkZoomEffect() { |
|
156 gContentAPI.showHighlight("urlbar", "zoom"); |
|
157 waitForHighlightWithEffect(highlight, "zoom", () => { |
|
158 let style = window.getComputedStyle(highlight); |
|
159 is(style.animationName, "uitour-zoom", "The animation-name should be uitour-zoom"); |
|
160 checkSameEffectOnDifferentTarget(); |
|
161 }, "There should be a zoom effect"); |
|
162 } |
|
163 function checkSameEffectOnDifferentTarget() { |
|
164 gContentAPI.showHighlight("appMenu", "wobble"); |
|
165 waitForHighlightWithEffect(highlight, "wobble", () => { |
|
166 highlight.addEventListener("animationstart", function onAnimationStart(aEvent) { |
|
167 highlight.removeEventListener("animationstart", onAnimationStart); |
|
168 ok(true, "Animation occurred again even though the effect was the same"); |
|
169 checkRandomEffect(); |
|
170 }); |
|
171 gContentAPI.showHighlight("backForward", "wobble"); |
|
172 }, "There should be a wobble effect"); |
|
173 } |
|
174 function checkRandomEffect() { |
|
175 function waitForActiveHighlight(highlightEl, next, error) { |
|
176 return waitForCondition(() => highlightEl.hasAttribute("active"), |
|
177 next, |
|
178 error); |
|
179 } |
|
180 |
|
181 gContentAPI.hideHighlight(); |
|
182 gContentAPI.showHighlight("urlbar", "random"); |
|
183 waitForActiveHighlight(highlight, () => { |
|
184 ok(highlight.hasAttribute("active"), "The highlight should be active"); |
|
185 isnot(highlight.getAttribute("active"), "none", "A random effect other than none should have been chosen"); |
|
186 isnot(highlight.getAttribute("active"), "random", "The random effect shouldn't be 'random'"); |
|
187 isnot(UITour.highlightEffects.indexOf(highlight.getAttribute("active")), -1, "Check that a supported effect was randomly chosen"); |
|
188 done(); |
|
189 }, "There should be an active highlight with a random effect"); |
|
190 } |
|
191 |
|
192 let highlight = document.getElementById("UITourHighlight"); |
|
193 is_element_hidden(highlight, "Highlight should initially be hidden"); |
|
194 |
|
195 gContentAPI.showHighlight("urlbar"); |
|
196 waitForElementToBeVisible(highlight, checkDefaultEffect, "Highlight should be shown after showHighlight()"); |
|
197 }, |
|
198 function test_highlight_effect_unsupported(done) { |
|
199 function checkUnsupportedEffect() { |
|
200 is(highlight.getAttribute("active"), "none", "No effect should be used when an unsupported effect is requested"); |
|
201 done(); |
|
202 } |
|
203 |
|
204 let highlight = document.getElementById("UITourHighlight"); |
|
205 is_element_hidden(highlight, "Highlight should initially be hidden"); |
|
206 |
|
207 gContentAPI.showHighlight("urlbar", "__UNSUPPORTED__"); |
|
208 waitForElementToBeVisible(highlight, checkUnsupportedEffect, "Highlight should be shown after showHighlight()"); |
|
209 }, |
|
210 function test_info_1(done) { |
|
211 let popup = document.getElementById("UITourTooltip"); |
|
212 let title = document.getElementById("UITourTooltipTitle"); |
|
213 let desc = document.getElementById("UITourTooltipDescription"); |
|
214 let icon = document.getElementById("UITourTooltipIcon"); |
|
215 let buttons = document.getElementById("UITourTooltipButtons"); |
|
216 |
|
217 popup.addEventListener("popupshown", function onPopupShown() { |
|
218 popup.removeEventListener("popupshown", onPopupShown); |
|
219 is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar"); |
|
220 is(title.textContent, "test title", "Popup should have correct title"); |
|
221 is(desc.textContent, "test text", "Popup should have correct description text"); |
|
222 is(icon.src, "", "Popup should have no icon"); |
|
223 is(buttons.hasChildNodes(), false, "Popup should have no buttons"); |
|
224 |
|
225 popup.addEventListener("popuphidden", function onPopupHidden() { |
|
226 popup.removeEventListener("popuphidden", onPopupHidden); |
|
227 |
|
228 popup.addEventListener("popupshown", function onPopupShown() { |
|
229 popup.removeEventListener("popupshown", onPopupShown); |
|
230 done(); |
|
231 }); |
|
232 |
|
233 gContentAPI.showInfo("urlbar", "test title", "test text"); |
|
234 |
|
235 }); |
|
236 gContentAPI.hideInfo(); |
|
237 }); |
|
238 |
|
239 gContentAPI.showInfo("urlbar", "test title", "test text"); |
|
240 }, |
|
241 function test_info_2(done) { |
|
242 let popup = document.getElementById("UITourTooltip"); |
|
243 let title = document.getElementById("UITourTooltipTitle"); |
|
244 let desc = document.getElementById("UITourTooltipDescription"); |
|
245 let icon = document.getElementById("UITourTooltipIcon"); |
|
246 let buttons = document.getElementById("UITourTooltipButtons"); |
|
247 |
|
248 popup.addEventListener("popupshown", function onPopupShown() { |
|
249 popup.removeEventListener("popupshown", onPopupShown); |
|
250 is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar"); |
|
251 is(title.textContent, "urlbar title", "Popup should have correct title"); |
|
252 is(desc.textContent, "urlbar text", "Popup should have correct description text"); |
|
253 is(icon.src, "", "Popup should have no icon"); |
|
254 is(buttons.hasChildNodes(), false, "Popup should have no buttons"); |
|
255 |
|
256 gContentAPI.showInfo("search", "search title", "search text"); |
|
257 executeSoon(function() { |
|
258 is(popup.popupBoxObject.anchorNode, document.getElementById("searchbar"), "Popup should be anchored to the searchbar"); |
|
259 is(title.textContent, "search title", "Popup should have correct title"); |
|
260 is(desc.textContent, "search text", "Popup should have correct description text"); |
|
261 |
|
262 done(); |
|
263 }); |
|
264 }); |
|
265 |
|
266 gContentAPI.showInfo("urlbar", "urlbar title", "urlbar text"); |
|
267 }, |
|
268 |
|
269 // Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down. |
|
270 function cleanupMenus(done) { |
|
271 gContentAPI.showMenu("appMenu"); |
|
272 done(); |
|
273 }, |
|
274 ]; |