Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | let gNavBar = document.getElementById(CustomizableUI.AREA_NAVBAR); |
michael@0 | 8 | let gOverflowList = document.getElementById(gNavBar.getAttribute("overflowtarget")); |
michael@0 | 9 | |
michael@0 | 10 | const kBookmarksButton = "bookmarks-menu-button"; |
michael@0 | 11 | const kBookmarksItems = "personal-bookmarks"; |
michael@0 | 12 | const kOriginalWindowWidth = window.outerWidth; |
michael@0 | 13 | const kSmallWidth = 400; |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Helper function that opens the bookmarks menu, and returns a Promise that |
michael@0 | 17 | * resolves as soon as the menu is ready for interaction. |
michael@0 | 18 | */ |
michael@0 | 19 | function bookmarksMenuPanelShown() { |
michael@0 | 20 | let deferred = Promise.defer(); |
michael@0 | 21 | let bookmarksMenuPopup = document.getElementById("BMB_bookmarksPopup"); |
michael@0 | 22 | let onTransitionEnd = (e) => { |
michael@0 | 23 | if (e.target == bookmarksMenuPopup) { |
michael@0 | 24 | bookmarksMenuPopup.removeEventListener("transitionend", onTransitionEnd); |
michael@0 | 25 | deferred.resolve(); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | bookmarksMenuPopup.addEventListener("transitionend", onTransitionEnd); |
michael@0 | 29 | return deferred.promise; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Checks that the placesContext menu is correctly attached to the |
michael@0 | 34 | * controller of some view. Returns a Promise that resolves as soon |
michael@0 | 35 | * as the context menu is closed. |
michael@0 | 36 | * |
michael@0 | 37 | * @param aItemWithContextMenu the item that we need to synthesize hte |
michael@0 | 38 | * right click on in order to open the context menu. |
michael@0 | 39 | */ |
michael@0 | 40 | function checkPlacesContextMenu(aItemWithContextMenu) { |
michael@0 | 41 | return Task.spawn(function* () { |
michael@0 | 42 | let contextMenu = document.getElementById("placesContext"); |
michael@0 | 43 | let newBookmarkItem = document.getElementById("placesContext_new:bookmark"); |
michael@0 | 44 | let shownPromise = popupShown(contextMenu); |
michael@0 | 45 | EventUtils.synthesizeMouseAtCenter(aItemWithContextMenu, |
michael@0 | 46 | {type: "contextmenu", button: 2}); |
michael@0 | 47 | yield shownPromise; |
michael@0 | 48 | |
michael@0 | 49 | ok(!newBookmarkItem.hasAttribute("disabled"), |
michael@0 | 50 | "New bookmark item shouldn't be disabled"); |
michael@0 | 51 | |
michael@0 | 52 | yield closePopup(contextMenu); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * Opens the bookmarks menu panel, and then opens each of the "special" |
michael@0 | 58 | * submenus in that list. Then it checks that those submenu's context menus |
michael@0 | 59 | * are properly hooked up to a controller. |
michael@0 | 60 | */ |
michael@0 | 61 | function checkSpecialContextMenus() { |
michael@0 | 62 | return Task.spawn(function* () { |
michael@0 | 63 | let contextMenu = document.getElementById("placesContext"); |
michael@0 | 64 | let bookmarksMenuButton = document.getElementById(kBookmarksButton); |
michael@0 | 65 | let bookmarksMenuPopup = document.getElementById("BMB_bookmarksPopup"); |
michael@0 | 66 | |
michael@0 | 67 | const kSpecialItemIDs = { |
michael@0 | 68 | "BMB_bookmarksToolbar": "BMB_bookmarksToolbarPopup", |
michael@0 | 69 | "BMB_unsortedBookmarks": "BMB_unsortedBookmarksPopup", |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | // Open the bookmarks menu button context menus and ensure that |
michael@0 | 73 | // they have the proper views attached. |
michael@0 | 74 | let shownPromise = bookmarksMenuPanelShown(); |
michael@0 | 75 | let dropmarker = document.getAnonymousElementByAttribute(bookmarksMenuButton, |
michael@0 | 76 | "anonid", "dropmarker"); |
michael@0 | 77 | EventUtils.synthesizeMouseAtCenter(dropmarker, {}); |
michael@0 | 78 | info("Waiting for bookmarks menu popup to show after clicking dropmarker.") |
michael@0 | 79 | yield shownPromise; |
michael@0 | 80 | |
michael@0 | 81 | for (let menuID in kSpecialItemIDs) { |
michael@0 | 82 | let menuItem = document.getElementById(menuID); |
michael@0 | 83 | let menuPopup = document.getElementById(kSpecialItemIDs[menuID]); |
michael@0 | 84 | let shownPromise = popupShown(menuPopup); |
michael@0 | 85 | menuPopup.openPopup(menuItem, null, 0, 0, false, false, null); |
michael@0 | 86 | |
michael@0 | 87 | yield shownPromise; |
michael@0 | 88 | |
michael@0 | 89 | yield checkPlacesContextMenu(menuPopup); |
michael@0 | 90 | yield closePopup(menuPopup); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | yield closePopup(bookmarksMenuPopup); |
michael@0 | 94 | }); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Closes a focused popup by simulating pressing the Escape key, |
michael@0 | 99 | * and returns a Promise that resolves as soon as the popup is closed. |
michael@0 | 100 | * |
michael@0 | 101 | * @param aPopup the popup node to close. |
michael@0 | 102 | */ |
michael@0 | 103 | function closePopup(aPopup) { |
michael@0 | 104 | let hiddenPromise = popupHidden(aPopup); |
michael@0 | 105 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 106 | return hiddenPromise; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Helper function that checks that the context menu of the |
michael@0 | 111 | * bookmark toolbar items chevron popup is correctly hooked up |
michael@0 | 112 | * to the controller of a view. |
michael@0 | 113 | */ |
michael@0 | 114 | function checkBookmarksItemsChevronContextMenu() { |
michael@0 | 115 | return Task.spawn(function*() { |
michael@0 | 116 | let chevronPopup = document.getElementById("PlacesChevronPopup"); |
michael@0 | 117 | let shownPromise = popupShown(chevronPopup); |
michael@0 | 118 | let chevron = document.getElementById("PlacesChevron"); |
michael@0 | 119 | EventUtils.synthesizeMouseAtCenter(chevron, {}); |
michael@0 | 120 | yield shownPromise; |
michael@0 | 121 | yield waitForCondition(() => { |
michael@0 | 122 | for (let child of chevronPopup.children) { |
michael@0 | 123 | if (child.style.visibility != "hidden") |
michael@0 | 124 | return true; |
michael@0 | 125 | } |
michael@0 | 126 | }); |
michael@0 | 127 | yield checkPlacesContextMenu(chevronPopup); |
michael@0 | 128 | yield closePopup(chevronPopup); |
michael@0 | 129 | }); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | /** |
michael@0 | 133 | * Forces the window to a width that causes the nav-bar to overflow |
michael@0 | 134 | * its contents. Returns a Promise that resolves as soon as the |
michael@0 | 135 | * overflowable nav-bar is showing its chevron. |
michael@0 | 136 | */ |
michael@0 | 137 | function overflowEverything() { |
michael@0 | 138 | window.resizeTo(kSmallWidth, window.outerHeight); |
michael@0 | 139 | return waitForCondition(() => gNavBar.hasAttribute("overflowing")); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Returns the window to its original size from the start of the test, |
michael@0 | 144 | * and returns a Promise that resolves when the nav-bar is no longer |
michael@0 | 145 | * overflowing. |
michael@0 | 146 | */ |
michael@0 | 147 | function stopOverflowing() { |
michael@0 | 148 | window.resizeTo(kOriginalWindowWidth, window.outerHeight); |
michael@0 | 149 | return waitForCondition(() => !gNavBar.hasAttribute("overflowing")); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Checks that an item with ID aID is overflowing in the nav-bar. |
michael@0 | 154 | * |
michael@0 | 155 | * @param aID the ID of the node to check for overflowingness. |
michael@0 | 156 | */ |
michael@0 | 157 | function checkOverflowing(aID) { |
michael@0 | 158 | ok(!gNavBar.querySelector("#" + aID), |
michael@0 | 159 | "Item with ID " + aID + " should no longer be in the gNavBar"); |
michael@0 | 160 | let item = gOverflowList.querySelector("#" + aID); |
michael@0 | 161 | ok(item, "Item with ID " + aID + " should be overflowing"); |
michael@0 | 162 | is(item.getAttribute("overflowedItem"), "true", |
michael@0 | 163 | "Item with ID " + aID + " should have overflowedItem attribute"); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Checks that an item with ID aID is not overflowing in the nav-bar. |
michael@0 | 168 | * |
michael@0 | 169 | * @param aID the ID of hte node to check for non-overflowingness. |
michael@0 | 170 | */ |
michael@0 | 171 | function checkNotOverflowing(aID) { |
michael@0 | 172 | ok(!gOverflowList.querySelector("#" + aID), |
michael@0 | 173 | "Item with ID " + aID + " should no longer be overflowing"); |
michael@0 | 174 | let item = gNavBar.querySelector("#" + aID); |
michael@0 | 175 | ok(item, "Item with ID " + aID + " should be in the nav bar"); |
michael@0 | 176 | ok(!item.hasAttribute("overflowedItem"), |
michael@0 | 177 | "Item with ID " + aID + " should not have overflowedItem attribute"); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Test that overflowing the bookmarks menu button doesn't break the |
michael@0 | 182 | * context menus for the Unsorted and Bookmarks Toolbar menu items. |
michael@0 | 183 | */ |
michael@0 | 184 | add_task(function* testOverflowingBookmarksButtonContextMenu() { |
michael@0 | 185 | ok(!gNavBar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar."); |
michael@0 | 186 | ok(CustomizableUI.inDefaultState, "Should start in default state."); |
michael@0 | 187 | |
michael@0 | 188 | // Open the Unsorted and Bookmarks Toolbar context menus and ensure |
michael@0 | 189 | // that they have views attached. |
michael@0 | 190 | yield checkSpecialContextMenus(); |
michael@0 | 191 | |
michael@0 | 192 | yield overflowEverything(); |
michael@0 | 193 | checkOverflowing(kBookmarksButton); |
michael@0 | 194 | |
michael@0 | 195 | yield stopOverflowing(); |
michael@0 | 196 | checkNotOverflowing(kBookmarksButton); |
michael@0 | 197 | |
michael@0 | 198 | yield checkSpecialContextMenus(); |
michael@0 | 199 | }); |
michael@0 | 200 | |
michael@0 | 201 | /** |
michael@0 | 202 | * Test that the bookmarks toolbar items context menu still works if moved |
michael@0 | 203 | * to the menu from the overflow panel, and then back to the toolbar. |
michael@0 | 204 | */ |
michael@0 | 205 | add_task(function* testOverflowingBookmarksItemsContextMenu() { |
michael@0 | 206 | yield PanelUI.ensureReady(); |
michael@0 | 207 | |
michael@0 | 208 | let bookmarksToolbarItems = document.getElementById(kBookmarksItems); |
michael@0 | 209 | gCustomizeMode.addToToolbar(bookmarksToolbarItems); |
michael@0 | 210 | yield checkPlacesContextMenu(bookmarksToolbarItems); |
michael@0 | 211 | |
michael@0 | 212 | yield overflowEverything(); |
michael@0 | 213 | checkOverflowing(kBookmarksItems) |
michael@0 | 214 | |
michael@0 | 215 | gCustomizeMode.addToPanel(bookmarksToolbarItems); |
michael@0 | 216 | |
michael@0 | 217 | yield stopOverflowing(); |
michael@0 | 218 | |
michael@0 | 219 | gCustomizeMode.addToToolbar(bookmarksToolbarItems); |
michael@0 | 220 | yield checkPlacesContextMenu(bookmarksToolbarItems); |
michael@0 | 221 | }); |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * Test that overflowing the bookmarks toolbar items doesn't cause the |
michael@0 | 225 | * context menu in the bookmarks toolbar items chevron to stop working. |
michael@0 | 226 | */ |
michael@0 | 227 | add_task(function* testOverflowingBookmarksItemsChevronContextMenu() { |
michael@0 | 228 | // If it's not already there, let's move the bookmarks toolbar items to |
michael@0 | 229 | // the nav-bar. |
michael@0 | 230 | let bookmarksToolbarItems = document.getElementById(kBookmarksItems); |
michael@0 | 231 | gCustomizeMode.addToToolbar(bookmarksToolbarItems); |
michael@0 | 232 | |
michael@0 | 233 | // We make the PlacesToolbarItems element be super tiny in order to force |
michael@0 | 234 | // the bookmarks toolbar items into overflowing and making the chevron |
michael@0 | 235 | // show itself. |
michael@0 | 236 | let placesToolbarItems = document.getElementById("PlacesToolbarItems"); |
michael@0 | 237 | let placesChevron = document.getElementById("PlacesChevron"); |
michael@0 | 238 | placesToolbarItems.style.maxWidth = "10px"; |
michael@0 | 239 | yield waitForCondition(() => !placesChevron.collapsed); |
michael@0 | 240 | |
michael@0 | 241 | yield checkBookmarksItemsChevronContextMenu(); |
michael@0 | 242 | |
michael@0 | 243 | yield overflowEverything(); |
michael@0 | 244 | checkOverflowing(kBookmarksItems); |
michael@0 | 245 | |
michael@0 | 246 | yield stopOverflowing(); |
michael@0 | 247 | checkNotOverflowing(kBookmarksItems); |
michael@0 | 248 | |
michael@0 | 249 | yield checkBookmarksItemsChevronContextMenu(); |
michael@0 | 250 | |
michael@0 | 251 | placesToolbarItems.style.removeProperty("max-width"); |
michael@0 | 252 | }); |
michael@0 | 253 | |
michael@0 | 254 | add_task(function* asyncCleanup() { |
michael@0 | 255 | window.resizeTo(kOriginalWindowWidth, window.outerHeight); |
michael@0 | 256 | yield resetCustomization(); |
michael@0 | 257 | }); |