Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 let openUILinkInCalled = false;
8 let expectOpenUILinkInCall = false;
9 this.originalOpenUILinkIn = openUILinkIn;
10 openUILinkIn = (aUrl, aWhichTab) => {
11 is(aUrl, "about:home", "about:home should be requested to open.");
12 is(aWhichTab, "current", "Should use the current tab for the search page.");
13 openUILinkInCalled = true;
14 if (!expectOpenUILinkInCall) {
15 ok(false, "OpenUILinkIn was called when it shouldn't have been.");
16 }
17 };
18 logActiveElement();
20 function* waitForSearchBarFocus()
21 {
22 let searchbar = document.getElementById("searchbar");
23 yield waitForCondition(function () {
24 logActiveElement();
25 return document.activeElement === searchbar.textbox.inputField;
26 });
27 }
29 // Ctrl+K should open the menu panel and focus the search bar if the search bar is in the panel.
30 add_task(function() {
31 let searchbar = document.getElementById("searchbar");
32 gCustomizeMode.addToPanel(searchbar);
33 let placement = CustomizableUI.getPlacementOfWidget("search-container");
34 is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
36 let shownPanelPromise = promisePanelShown(window);
37 sendWebSearchKeyCommand();
38 yield shownPanelPromise;
40 yield waitForSearchBarFocus();
42 let hiddenPanelPromise = promisePanelHidden(window);
43 EventUtils.synthesizeKey("VK_ESCAPE", {});
44 yield hiddenPanelPromise;
45 CustomizableUI.reset();
46 });
48 // Ctrl+K should give focus to the searchbar when the searchbar is in the menupanel and the panel is already opened.
49 add_task(function() {
50 let searchbar = document.getElementById("searchbar");
51 gCustomizeMode.addToPanel(searchbar);
52 let placement = CustomizableUI.getPlacementOfWidget("search-container");
53 is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel");
55 let shownPanelPromise = promisePanelShown(window);
56 PanelUI.toggle({type: "command"});
57 yield shownPanelPromise;
59 sendWebSearchKeyCommand();
61 yield waitForSearchBarFocus();
63 let hiddenPanelPromise = promisePanelHidden(window);
64 EventUtils.synthesizeKey("VK_ESCAPE", {});
65 yield hiddenPanelPromise;
66 CustomizableUI.reset();
67 });
69 // Ctrl+K should open the overflow panel and focus the search bar if the search bar is overflowed.
70 add_task(function() {
71 this.originalWindowWidth = window.outerWidth;
72 let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
73 ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
74 ok(CustomizableUI.inDefaultState, "Should start in default state.");
76 window.resizeTo(360, window.outerHeight);
77 yield waitForCondition(() => navbar.getAttribute("overflowing") == "true");
78 ok(!navbar.querySelector("#search-container"), "Search container should be overflowing");
80 let shownPanelPromise = promiseOverflowShown(window);
81 sendWebSearchKeyCommand();
82 yield shownPanelPromise;
84 let chevron = document.getElementById("nav-bar-overflow-button");
85 yield waitForCondition(function() chevron.open);
87 yield waitForSearchBarFocus();
89 let hiddenPanelPromise = promiseOverflowHidden(window);
90 EventUtils.synthesizeKey("VK_ESCAPE", {});
91 yield hiddenPanelPromise;
92 let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
93 window.resizeTo(this.originalWindowWidth, window.outerHeight);
94 yield waitForCondition(() => !navbar.hasAttribute("overflowing"));
95 ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
96 });
98 // Ctrl+K should focus the search bar if it is in the navbar and not overflowing.
99 add_task(function() {
100 let placement = CustomizableUI.getPlacementOfWidget("search-container");
101 is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
103 sendWebSearchKeyCommand();
105 yield waitForSearchBarFocus();
106 });
108 // Ctrl+K should open the search page if the search bar has been customized out.
109 add_task(function() {
110 try {
111 expectOpenUILinkInCall = true;
112 CustomizableUI.removeWidgetFromArea("search-container");
113 let placement = CustomizableUI.getPlacementOfWidget("search-container");
114 is(placement, null, "Search container should be in palette");
116 openUILinkInCalled = false;
118 sendWebSearchKeyCommand();
119 yield waitForCondition(function() openUILinkInCalled);
120 ok(openUILinkInCalled, "The search page should have been opened.")
121 expectOpenUILinkInCall = false;
122 } catch (e) {
123 ok(false, e);
124 }
125 CustomizableUI.reset();
126 });
128 registerCleanupFunction(function() {
129 openUILinkIn = this.originalOpenUILinkIn;
130 delete this.originalOpenUILinkIn;
131 });
133 function sendWebSearchKeyCommand() {
134 if (Services.appinfo.OS === "Darwin")
135 EventUtils.synthesizeKey("k", { accelKey: true });
136 else
137 EventUtils.synthesizeKey("k", { ctrlKey: true });
138 }
140 function logActiveElement() {
141 let element = document.activeElement;
142 let str = "";
143 while (element && element.parentNode) {
144 str = " (" + element.localName + "#" + element.id + "." + [...element.classList].join(".") + ") >" + str;
145 element = element.parentNode;
146 }
147 info("Active element: " + element ? str : "null");
148 }