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 openUILinkInCalled = false; |
michael@0 | 8 | let expectOpenUILinkInCall = false; |
michael@0 | 9 | this.originalOpenUILinkIn = openUILinkIn; |
michael@0 | 10 | openUILinkIn = (aUrl, aWhichTab) => { |
michael@0 | 11 | is(aUrl, "about:home", "about:home should be requested to open."); |
michael@0 | 12 | is(aWhichTab, "current", "Should use the current tab for the search page."); |
michael@0 | 13 | openUILinkInCalled = true; |
michael@0 | 14 | if (!expectOpenUILinkInCall) { |
michael@0 | 15 | ok(false, "OpenUILinkIn was called when it shouldn't have been."); |
michael@0 | 16 | } |
michael@0 | 17 | }; |
michael@0 | 18 | logActiveElement(); |
michael@0 | 19 | |
michael@0 | 20 | function* waitForSearchBarFocus() |
michael@0 | 21 | { |
michael@0 | 22 | let searchbar = document.getElementById("searchbar"); |
michael@0 | 23 | yield waitForCondition(function () { |
michael@0 | 24 | logActiveElement(); |
michael@0 | 25 | return document.activeElement === searchbar.textbox.inputField; |
michael@0 | 26 | }); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | // Ctrl+K should open the menu panel and focus the search bar if the search bar is in the panel. |
michael@0 | 30 | add_task(function() { |
michael@0 | 31 | let searchbar = document.getElementById("searchbar"); |
michael@0 | 32 | gCustomizeMode.addToPanel(searchbar); |
michael@0 | 33 | let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
michael@0 | 34 | is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel"); |
michael@0 | 35 | |
michael@0 | 36 | let shownPanelPromise = promisePanelShown(window); |
michael@0 | 37 | sendWebSearchKeyCommand(); |
michael@0 | 38 | yield shownPanelPromise; |
michael@0 | 39 | |
michael@0 | 40 | yield waitForSearchBarFocus(); |
michael@0 | 41 | |
michael@0 | 42 | let hiddenPanelPromise = promisePanelHidden(window); |
michael@0 | 43 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 44 | yield hiddenPanelPromise; |
michael@0 | 45 | CustomizableUI.reset(); |
michael@0 | 46 | }); |
michael@0 | 47 | |
michael@0 | 48 | // Ctrl+K should give focus to the searchbar when the searchbar is in the menupanel and the panel is already opened. |
michael@0 | 49 | add_task(function() { |
michael@0 | 50 | let searchbar = document.getElementById("searchbar"); |
michael@0 | 51 | gCustomizeMode.addToPanel(searchbar); |
michael@0 | 52 | let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
michael@0 | 53 | is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel"); |
michael@0 | 54 | |
michael@0 | 55 | let shownPanelPromise = promisePanelShown(window); |
michael@0 | 56 | PanelUI.toggle({type: "command"}); |
michael@0 | 57 | yield shownPanelPromise; |
michael@0 | 58 | |
michael@0 | 59 | sendWebSearchKeyCommand(); |
michael@0 | 60 | |
michael@0 | 61 | yield waitForSearchBarFocus(); |
michael@0 | 62 | |
michael@0 | 63 | let hiddenPanelPromise = promisePanelHidden(window); |
michael@0 | 64 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 65 | yield hiddenPanelPromise; |
michael@0 | 66 | CustomizableUI.reset(); |
michael@0 | 67 | }); |
michael@0 | 68 | |
michael@0 | 69 | // Ctrl+K should open the overflow panel and focus the search bar if the search bar is overflowed. |
michael@0 | 70 | add_task(function() { |
michael@0 | 71 | this.originalWindowWidth = window.outerWidth; |
michael@0 | 72 | let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR); |
michael@0 | 73 | ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar."); |
michael@0 | 74 | ok(CustomizableUI.inDefaultState, "Should start in default state."); |
michael@0 | 75 | |
michael@0 | 76 | window.resizeTo(360, window.outerHeight); |
michael@0 | 77 | yield waitForCondition(() => navbar.getAttribute("overflowing") == "true"); |
michael@0 | 78 | ok(!navbar.querySelector("#search-container"), "Search container should be overflowing"); |
michael@0 | 79 | |
michael@0 | 80 | let shownPanelPromise = promiseOverflowShown(window); |
michael@0 | 81 | sendWebSearchKeyCommand(); |
michael@0 | 82 | yield shownPanelPromise; |
michael@0 | 83 | |
michael@0 | 84 | let chevron = document.getElementById("nav-bar-overflow-button"); |
michael@0 | 85 | yield waitForCondition(function() chevron.open); |
michael@0 | 86 | |
michael@0 | 87 | yield waitForSearchBarFocus(); |
michael@0 | 88 | |
michael@0 | 89 | let hiddenPanelPromise = promiseOverflowHidden(window); |
michael@0 | 90 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 91 | yield hiddenPanelPromise; |
michael@0 | 92 | let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR); |
michael@0 | 93 | window.resizeTo(this.originalWindowWidth, window.outerHeight); |
michael@0 | 94 | yield waitForCondition(() => !navbar.hasAttribute("overflowing")); |
michael@0 | 95 | ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar."); |
michael@0 | 96 | }); |
michael@0 | 97 | |
michael@0 | 98 | // Ctrl+K should focus the search bar if it is in the navbar and not overflowing. |
michael@0 | 99 | add_task(function() { |
michael@0 | 100 | let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
michael@0 | 101 | is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar"); |
michael@0 | 102 | |
michael@0 | 103 | sendWebSearchKeyCommand(); |
michael@0 | 104 | |
michael@0 | 105 | yield waitForSearchBarFocus(); |
michael@0 | 106 | }); |
michael@0 | 107 | |
michael@0 | 108 | // Ctrl+K should open the search page if the search bar has been customized out. |
michael@0 | 109 | add_task(function() { |
michael@0 | 110 | try { |
michael@0 | 111 | expectOpenUILinkInCall = true; |
michael@0 | 112 | CustomizableUI.removeWidgetFromArea("search-container"); |
michael@0 | 113 | let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
michael@0 | 114 | is(placement, null, "Search container should be in palette"); |
michael@0 | 115 | |
michael@0 | 116 | openUILinkInCalled = false; |
michael@0 | 117 | |
michael@0 | 118 | sendWebSearchKeyCommand(); |
michael@0 | 119 | yield waitForCondition(function() openUILinkInCalled); |
michael@0 | 120 | ok(openUILinkInCalled, "The search page should have been opened.") |
michael@0 | 121 | expectOpenUILinkInCall = false; |
michael@0 | 122 | } catch (e) { |
michael@0 | 123 | ok(false, e); |
michael@0 | 124 | } |
michael@0 | 125 | CustomizableUI.reset(); |
michael@0 | 126 | }); |
michael@0 | 127 | |
michael@0 | 128 | registerCleanupFunction(function() { |
michael@0 | 129 | openUILinkIn = this.originalOpenUILinkIn; |
michael@0 | 130 | delete this.originalOpenUILinkIn; |
michael@0 | 131 | }); |
michael@0 | 132 | |
michael@0 | 133 | function sendWebSearchKeyCommand() { |
michael@0 | 134 | if (Services.appinfo.OS === "Darwin") |
michael@0 | 135 | EventUtils.synthesizeKey("k", { accelKey: true }); |
michael@0 | 136 | else |
michael@0 | 137 | EventUtils.synthesizeKey("k", { ctrlKey: true }); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function logActiveElement() { |
michael@0 | 141 | let element = document.activeElement; |
michael@0 | 142 | let str = ""; |
michael@0 | 143 | while (element && element.parentNode) { |
michael@0 | 144 | str = " (" + element.localName + "#" + element.id + "." + [...element.classList].join(".") + ") >" + str; |
michael@0 | 145 | element = element.parentNode; |
michael@0 | 146 | } |
michael@0 | 147 | info("Active element: " + element ? str : "null"); |
michael@0 | 148 | } |