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