Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | let bookmarksMenuButton = document.getElementById("bookmarks-menu-button"); |
michael@0 | 2 | let BMB_menuPopup = document.getElementById("BMB_bookmarksPopup"); |
michael@0 | 3 | let BMB_showAllBookmarks = document.getElementById("BMB_bookmarksShowAll"); |
michael@0 | 4 | let contextMenu = document.getElementById("placesContext"); |
michael@0 | 5 | let newBookmarkItem = document.getElementById("placesContext_new:bookmark"); |
michael@0 | 6 | |
michael@0 | 7 | waitForExplicitFinish(); |
michael@0 | 8 | add_task(function testPopup() { |
michael@0 | 9 | info("Checking popup context menu before moving the bookmarks button"); |
michael@0 | 10 | yield checkPopupContextMenu(); |
michael@0 | 11 | let pos = CustomizableUI.getPlacementOfWidget("bookmarks-menu-button").position; |
michael@0 | 12 | CustomizableUI.addWidgetToArea("bookmarks-menu-button", CustomizableUI.AREA_PANEL); |
michael@0 | 13 | CustomizableUI.addWidgetToArea("bookmarks-menu-button", CustomizableUI.AREA_NAVBAR, pos); |
michael@0 | 14 | info("Checking popup context menu after moving the bookmarks button"); |
michael@0 | 15 | yield checkPopupContextMenu(); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | function* checkPopupContextMenu() { |
michael@0 | 19 | let dropmarker = document.getAnonymousElementByAttribute(bookmarksMenuButton, "anonid", "dropmarker"); |
michael@0 | 20 | BMB_menuPopup.setAttribute("style", "transition: none;"); |
michael@0 | 21 | let popupShownPromise = onPopupEvent(BMB_menuPopup, "shown"); |
michael@0 | 22 | EventUtils.synthesizeMouseAtCenter(dropmarker, {}); |
michael@0 | 23 | info("Waiting for bookmarks menu to be shown."); |
michael@0 | 24 | yield popupShownPromise; |
michael@0 | 25 | let contextMenuShownPromise = onPopupEvent(contextMenu, "shown"); |
michael@0 | 26 | EventUtils.synthesizeMouseAtCenter(BMB_showAllBookmarks, {type: "contextmenu", button: 2 }); |
michael@0 | 27 | info("Waiting for context menu on bookmarks menu to be shown."); |
michael@0 | 28 | yield contextMenuShownPromise; |
michael@0 | 29 | ok(!newBookmarkItem.hasAttribute("disabled"), "New bookmark item shouldn't be disabled"); |
michael@0 | 30 | let contextMenuHiddenPromise = onPopupEvent(contextMenu, "hidden"); |
michael@0 | 31 | contextMenu.hidePopup(); |
michael@0 | 32 | BMB_menuPopup.removeAttribute("style"); |
michael@0 | 33 | info("Waiting for context menu on bookmarks menu to be hidden."); |
michael@0 | 34 | yield contextMenuHiddenPromise; |
michael@0 | 35 | let popupHiddenPromise = onPopupEvent(BMB_menuPopup, "hidden"); |
michael@0 | 36 | // Can't use synthesizeMouseAtCenter because the dropdown panel is in the way |
michael@0 | 37 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 38 | info("Waiting for bookmarks menu to be hidden."); |
michael@0 | 39 | yield popupHiddenPromise; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function onPopupEvent(popup, evt) { |
michael@0 | 43 | let fullEvent = "popup" + evt; |
michael@0 | 44 | let deferred = new Promise.defer(); |
michael@0 | 45 | let onPopupHandler = (e) => { |
michael@0 | 46 | if (e.target == popup) { |
michael@0 | 47 | popup.removeEventListener(fullEvent, onPopupHandler); |
michael@0 | 48 | deferred.resolve(); |
michael@0 | 49 | } |
michael@0 | 50 | }; |
michael@0 | 51 | popup.addEventListener(fullEvent, onPopupHandler); |
michael@0 | 52 | return deferred.promise; |
michael@0 | 53 | } |