Bug 1387416 - Place the search bar in the customization palette for new profiles. r=Gijs

MozReview-Commit-ID: Tq8YrZWG6P

--HG--
extra : rebase_source : 2e02e0a809d08ff26291a027b73a54668d6d5f9d
This commit is contained in:
Paolo Amadini 2017-09-06 13:09:27 +01:00
parent 42a8532893
commit fe96089fe4
46 changed files with 290 additions and 146 deletions

View File

@ -409,11 +409,8 @@ pref("browser.search.context.loadInBackground", false);
// comma seperated list of of engines to hide in the search panel.
pref("browser.search.hiddenOneOffs", "");
// Mirrors whether the search-container widget is in the navigation toolbar. The
// default value of this preference must match the DEFAULT_AREA_PLACEMENTS of
// UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
// position and attributes of the search-container element in browser.xul.
pref("browser.search.widget.inNavBar", true);
// Mirrors whether the search-container widget is in the navigation toolbar.
pref("browser.search.widget.inNavBar", false);
#ifndef RELEASE_OR_BETA
pref("browser.search.reset.enabled", true);

View File

@ -931,13 +931,6 @@
</textbox>
</toolbaritem>
<toolbaritem id="search-container" title="&searchItem.title;"
align="center" class="chromeclass-toolbar-additional panel-wide-item"
cui-areatype="toolbar"
flex="100" persist="width" removable="true">
<searchbar id="searchbar" flex="1"/>
</toolbaritem>
<!-- This is a placeholder for the Downloads Indicator. It is visible
during the customization of the toolbar, in the palette, and before
the Downloads Indicator overlay is loaded. -->
@ -1087,7 +1080,6 @@
<toolbarbutton id="bookmarks-menu-button"
class="toolbarbutton-1 chromeclass-toolbar-additional"
removable="true"
type="menu"
label="&bookmarksMenuButton2.label;"
tooltip="dynamic-shortcut-tooltip"
@ -1096,7 +1088,6 @@
ondragover="PlacesMenuDNDHandler.onDragOver(event);"
ondragleave="PlacesMenuDNDHandler.onDragLeave(event);"
ondrop="PlacesMenuDNDHandler.onDrop(event);"
cui-areatype="toolbar"
oncommand="BookmarkingUI.onCommand(event);">
<observes element="bookmarkThisPageBroadcaster" attribute="starred"/>
<observes element="bookmarkThisPageBroadcaster" attribute="buttontooltiptext"/>
@ -1182,6 +1173,15 @@
key="manBookmarkKb"/>
</menupopup>
</toolbarbutton>
<toolbaritem id="search-container"
class="chromeclass-toolbar-additional panel-wide-item"
title="&searchItem.title;"
align="center"
flex="100"
persist="width">
<searchbar id="searchbar" flex="1"/>
</toolbaritem>
</toolbarpalette>
<box id="library-animatable-box" class="toolbarbutton-animatable-box">
<image class="toolbarbutton-animatable-image"/>

View File

@ -483,6 +483,8 @@ add_task(async function() {
add_task(async function() {
info("Cmd+k should focus the search box in the toolbar when it's present");
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
await BrowserTestUtils.withNewTab({ gBrowser, url: "about:home" }, async function(browser) {
await BrowserTestUtils.synthesizeMouseAtCenter("#brandLogo", {}, browser);
@ -494,6 +496,8 @@ add_task(async function() {
await promiseWaitForCondition(() => doc.activeElement === searchInput);
is(searchInput, doc.activeElement, "Search bar should be the active element.");
});
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
});
add_task(async function() {

View File

@ -2,16 +2,10 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function() {
// Remove the search bar from toolbar
CustomizableUI.removeWidgetFromArea("search-container");
// Test that Ctrl/Cmd + K will focus the url bar
let focusPromise = BrowserTestUtils.waitForEvent(gURLBar, "focus");
EventUtils.synthesizeKey("k", { accelKey: true });
await focusPromise;
Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused");
// Reset changes made to toolbar
CustomizableUI.reset();
});

View File

@ -193,7 +193,6 @@ var CustomizableUIInternal = {
"home-button",
"spring",
"urlbar-container",
"search-container",
"spring",
"downloads-button",
"library-button",

View File

@ -36,6 +36,10 @@ const SearchWidgetTracker = {
CustomizableUI.addListener(this);
Services.prefs.addObserver(PREF_NAME,
() => this.syncWidgetWithPreference());
// The placement of the widget always takes priority, and the preference
// should always match the actual placement when the browser starts up.
this.syncPreferenceWithWidget();
},
onCustomizeEnd() {

View File

@ -7,15 +7,8 @@ const WIDGET_ID = "search-container";
const PREF_NAME = "browser.search.widget.inNavBar";
function checkDefaults() {
// If the following defaults change, then the DEFAULT_AREA_PLACEMENTS of
// UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
// position and attributes of the search-container element in browser.xul
// should also change at the same time.
ok(Services.prefs.getBoolPref(PREF_NAME));
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
is(placement.area, CustomizableUI.AREA_NAVBAR);
is(placement.position,
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
ok(!Services.prefs.getBoolPref(PREF_NAME));
is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
}
add_task(async function test_defaults() {
@ -24,23 +17,27 @@ add_task(async function test_defaults() {
});
add_task(async function test_syncPreferenceWithWidget() {
// Moving the widget to any position outside of the navigation toolbar should
// turn the preference to false.
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
ok(!Services.prefs.getBoolPref(PREF_NAME));
// Moving the widget back to any position in the navigation toolbar should
// turn the preference to true again.
// Moving the widget to any position in the navigation toolbar should turn the
// preference to true.
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR);
ok(Services.prefs.getBoolPref(PREF_NAME));
// Moving the widget to any position outside of the navigation toolbar should
// turn the preference back to false.
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
ok(!Services.prefs.getBoolPref(PREF_NAME));
});
add_task(async function test_syncWidgetWithPreference() {
// This should move the widget the customization palette.
Services.prefs.setBoolPref(PREF_NAME, false);
is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
// This should return the widget to its default placement.
// setting the preference should move the widget to the navigation toolbar and
// place it right after the location bar.
Services.prefs.setBoolPref(PREF_NAME, true);
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
is(placement.area, CustomizableUI.AREA_NAVBAR);
is(placement.position,
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
// This should move the widget back to the customization palette.
Services.prefs.setBoolPref(PREF_NAME, false);
checkDefaults();
});

View File

@ -16,10 +16,8 @@ async function waitForSearchBarFocus() {
// Ctrl+K should open the menu panel and focus the search bar if the search bar is in the panel.
add_task(async function() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
CustomizableUI.addWidgetToArea("search-container",
CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
let shownPanelPromise = promiseOverflowShown(window);
sendWebSearchKeyCommand();
@ -35,10 +33,8 @@ add_task(async function() {
// Ctrl+K should give focus to the searchbar when the searchbar is in the menupanel and the panel is already opened.
add_task(async function() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
CustomizableUI.addWidgetToArea("search-container",
CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
await document.getElementById("nav-bar").overflowable.show();
@ -59,7 +55,9 @@ add_task(async function() {
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(360, window.outerHeight);
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.getAttribute("overflowing") == "true");
ok(!navbar.querySelector("#search-container"), "Search container should be overflowing");
@ -75,6 +73,9 @@ add_task(async function() {
let hiddenPanelPromise = promiseOverflowHidden(window);
EventUtils.synthesizeKey("VK_ESCAPE", {});
await hiddenPanelPromise;
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
window.resizeTo(this.originalWindowWidth, window.outerHeight);
await waitForCondition(() => !navbar.hasAttribute("overflowing"));
@ -83,12 +84,15 @@ add_task(async function() {
// Ctrl+K should focus the search bar if it is in the navbar and not overflowing.
add_task(async function() {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
sendWebSearchKeyCommand();
await waitForSearchBarFocus();
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
});

View File

@ -10,7 +10,7 @@ add_task(async function() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
let oldChildCount = navbar.customizationTarget.childElementCount;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");

View File

@ -13,7 +13,7 @@ add_task(async function() {
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
let oldChildCount = navbar.customizationTarget.childElementCount;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
is(navbar.currentSet, oldCurrentSet, "Currentset should be the same when overflowing.");

View File

@ -23,7 +23,7 @@ add_task(async function() {
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kSidebarBtn), "Sidebar button should no longer be in the navbar");
@ -65,7 +65,7 @@ add_task(async function() {
CustomizableUI.addWidgetToArea(kTestBtn2, navbar.id);
ok(!navbar.hasAttribute("overflowing"), "Should still have a non-overflowing toolbar.");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
@ -94,7 +94,7 @@ add_task(async function() {
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(!navbar.querySelector("#" + kSidebarBtn), "Sidebar button should no longer be in the navbar");

View File

@ -9,11 +9,11 @@ add_task(async function() {
await startCustomizing();
let devButton = document.getElementById("developer-button");
let downloadsButton = document.getElementById("downloads-button");
let searchBox = document.getElementById("search-container");
let homeButton = document.getElementById("home-button");
let palette = document.getElementById("customization-palette");
ok(devButton && downloadsButton && searchBox && palette, "Stuff should exist");
ok(devButton && downloadsButton && homeButton && palette, "Stuff should exist");
simulateItemDrag(devButton, downloadsButton);
simulateItemDrag(searchBox, palette);
simulateItemDrag(homeButton, palette);
await gCustomizeMode.reset();
ok(CustomizableUI.inDefaultState, "Should be back in default state");
await endCustomizing();

View File

@ -69,14 +69,14 @@ add_task(async function menu_button_popup() {
});
add_task(async function searchbar_in_panel() {
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
CustomizableUI.addWidgetToArea("search-container",
CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
await waitForOverflowButtonShown();
await document.getElementById("nav-bar").overflowable.show();
let searchbar = document.getElementById("searchbar");
await waitForCondition(() => "value" in searchbar && searchbar.value === "");
// Focusing a non-empty searchbox will cause us to open the

View File

@ -12,7 +12,7 @@ add_task(async function() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
ok(CustomizableUI.inDefaultState, "Should start in default state.");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");

View File

@ -67,7 +67,7 @@ add_task(async function() {
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
@ -116,7 +116,7 @@ add_task(async function() {
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
@ -166,7 +166,7 @@ add_task(async function() {
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
let testWidgetId = kTestWidgetPrefix + 3;
@ -225,7 +225,7 @@ add_task(async function() {
}
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
// Find last widget that doesn't allow overflowing
@ -286,7 +286,7 @@ add_task(async function() {
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
@ -337,7 +337,7 @@ add_task(async function() {
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
@ -386,7 +386,7 @@ add_task(async function() {
ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
let originalWindowWidth = window.outerWidth;
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");

View File

@ -35,7 +35,7 @@ add_task(async function addOverflowingToolbar() {
isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(toolbarNode.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");

View File

@ -10,7 +10,6 @@ var gOverflowList = document.getElementById(gNavBar.getAttribute("overflowtarget
const kBookmarksButton = "bookmarks-menu-button";
const kBookmarksItems = "personal-bookmarks";
const kOriginalWindowWidth = window.outerWidth;
const kSmallWidth = 400;
/**
* Helper function that opens the bookmarks menu, and returns a Promise that
@ -141,7 +140,7 @@ function checkBookmarksItemsChevronContextMenu() {
*/
function overflowEverything() {
info("Waiting for overflow");
window.resizeTo(kSmallWidth, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
return waitForCondition(() => gNavBar.hasAttribute("overflowing"));
}

View File

@ -145,6 +145,11 @@ add_task(async function urlbar_context() {
// Right-click on the searchbar and moving it to the menu
// and back should move the search-container instead.
add_task(async function searchbar_context_move_to_panel_and_back() {
// This is specifically testing the addToPanel function for the search bar, so
// we have to move it to its correct position in the navigation toolbar first.
// The preference will be restored when the customizations are reset later.
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
let searchbar = document.getElementById("searchbar");
gCustomizeMode.addToPanel(searchbar);
let placement = CustomizableUI.getPlacementOfWidget("search-container");
@ -167,7 +172,7 @@ add_task(async function searchbar_context_move_to_panel_and_back() {
is(placement, null, "Should be in palette");
CustomizableUI.reset();
placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
is(placement, null, "Should be in palette");
});
// Right-click on an item within the panel should

View File

@ -128,7 +128,7 @@ add_task(async function test_panelui_customize_to_toolbar() {
CustomizableUI.reset();
});
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));
// Mac will update the enabled state even when the buttons are overflowing,

View File

@ -23,7 +23,7 @@ add_task(async function check_developer_subview_in_overflow() {
let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
window.resizeTo(400, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForCondition(() => navbar.hasAttribute("overflowing"));

View File

@ -27,6 +27,8 @@ var {synthesizeDragStart, synthesizeDrop} = EventUtils;
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const kTabEventFailureTimeoutInMs = 20000;
const kForceOverflowWidthPx = 300;
function createDummyXULButton(id, label, win = window) {
let btn = document.createElementNS(kNSXUL, "toolbarbutton");
btn.id = id;

View File

@ -1,6 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// This is the same value used by CustomizableUI tests.
const kForceOverflowWidthPx = 200;
registerCleanupFunction(async function() {
// Clean up when the test finishes.
await task_resetState();
@ -24,16 +27,14 @@ add_task(async function test_overflow_anchor() {
.forWindow(window);
ok(!button.overflowed, "Downloads button should not be overflowed.");
// Hack - we lock the size of the default flex-y items in the nav-bar,
// namely, the URL and search inputs. That way we can resize the
// window without worrying about them flexing.
const kFlexyItems = ["urlbar-container", "search-container"];
// Hack - we lock the size of the default flex-y items in the nav-bar, namely,
// the URL input. That way we can resize the window without worrying about it
// flexing.
const kFlexyItems = ["urlbar-container"];
registerCleanupFunction(() => unlockWidth(kFlexyItems));
lockWidth(kFlexyItems);
// Resize the window to half of its original size. That should
// be enough to overflow the downloads button.
window.resizeTo(oldWidth / 2, window.outerHeight);
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await waitForOverflowed(button, true);
let promise = promisePanelOpened();

View File

@ -131,6 +131,12 @@ async function prepareTest() {
await focusPromise;
}
add_task(async function testSetup() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
});
add_task(async function testSetupEngine() {
await promiseSetEngine();
});

View File

@ -123,13 +123,15 @@ async function testSearchEngine(engineDetails) {
name: "search bar search",
searchURL: base + engineDetails.codes.submission,
run() {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
let sb = BrowserSearch.searchBar;
sb.focus();
sb.value = "foo";
registerCleanupFunction(function() {
sb.value = "";
});
EventUtils.synthesizeKey("VK_RETURN", {});
},
postTest() {
BrowserSearch.searchBar.value = "";
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
}
},
{
@ -169,6 +171,10 @@ async function testSearchEngine(engineDetails) {
let receivedURI = await stateChangePromise;
Assert.equal(receivedURI, test.searchURL);
if (test.postTest) {
await test.postTest(tab);
}
}
engine.alias = undefined;

View File

@ -120,6 +120,12 @@ add_task(async function tests() {
let engine = Services.search.getEngineByName("Google");
ok(engine, "Google");
// Show the search bar after initializing the search service, to avoid the
// synchronous initialization to interfere.
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&client=firefox-b";
// Keyword uses a slightly different code

View File

@ -120,6 +120,12 @@ add_task(async function tests() {
let engine = Services.search.getEngineByName("Google");
ok(engine, "Google");
// Show the search bar after initializing the search service, to avoid the
// synchronous initialization to interfere.
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8";
let url;

View File

@ -9,7 +9,9 @@ function test() {
waitForExplicitFinish();
resetPreferences();
let calledTestTelemetry = false;
function testTelemetry() {
calledTestTelemetry = true;
// Find the right bucket for the "Foo" engine.
let engine = Services.search.getEngineByName("Foo");
let histogramKey = (engine.identifier || "other-Foo") + ".searchbar";
@ -58,8 +60,11 @@ function test() {
break;
case "engine-current":
is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
testTelemetry();
// We may be called again when resetting the engine at the end.
if (!calledTestTelemetry) {
is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
testTelemetry();
}
break;
case "engine-removed":
@ -70,7 +75,10 @@ function test() {
}
Services.obs.addObserver(observer, "browser-search-engine-modified");
SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]}).then(function() {
SpecialPowers.pushPrefEnv({set: [
["toolkit.telemetry.enabled", true],
["browser.search.widget.inNavBar", true],
]}).then(function() {
Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml",
null, "data:image/x-icon,%00", false);
});

View File

@ -3,18 +3,26 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Tests that keyboard navigation in the search panel works as designed.
const searchbar = document.getElementById("searchbar");
const textbox = searchbar._textbox;
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
"searchbar-search-button");
const diacritic_engine = "Foo \u2661";
var Preferences =
Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
let searchbar;
let searchIcon;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
let currentEngine = Services.search.currentEngine;
await promiseNewEngine("testEngine_diacritics.xml", {setAsCurrent: false});
registerCleanupFunction(() => {

View File

@ -3,11 +3,7 @@
const TEST_ENGINE_NAME = "Foo";
const TEST_ENGINE_BASENAME = "testEngine.xml";
const searchbar = document.getElementById("searchbar");
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
const oneOffBinding = document.getAnonymousElementByAttribute(
searchPopup, "anonid", "search-one-off-buttons"
);
@ -21,7 +17,19 @@ const searchInNewTabMenuItem = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-one-offs-context-open-in-new-tab"
);
let searchbar;
let searchIcon;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
await promiseNewEngine(TEST_ENGINE_BASENAME, {
setAsCurrent: false,
});

View File

@ -6,13 +6,9 @@ const SEARCHBAR_BASE_ID = "searchbar-engine-one-off-item-";
const URLBAR_BASE_ID = "urlbar-engine-one-off-item-";
const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
const searchbar = document.getElementById("searchbar");
const urlbar = document.getElementById("urlbar");
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const urlbarPopup = document.getElementById("PopupAutoCompleteRichResult");
const searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
const searchOneOffBinding = document.getAnonymousElementByAttribute(
searchPopup, "anonid", "search-one-off-buttons"
);
@ -28,7 +24,19 @@ function resetEngine() {
registerCleanupFunction(resetEngine);
let searchbar;
let searchIcon;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
await promiseNewEngine(TEST_ENGINE_BASENAME, {
setAsCurrent: false,
});

View File

@ -5,11 +5,7 @@
const isMac = ("nsILocalFileMac" in Ci);
const searchbar = document.getElementById("searchbar");
const textbox = searchbar._textbox;
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
"searchbar-search-button");
const oneOffsContainer =
document.getAnonymousElementByAttribute(searchPopup, "anonid",
@ -55,8 +51,19 @@ function synthesizeNativeMouseMove(aElement) {
});
}
let searchbar;
let searchIcon;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
await promiseNewEngine("testEngine.xml");
});
@ -92,9 +99,9 @@ add_task(async function test_notext() {
});
add_task(async function test_text() {
textbox.value = "foo";
searchbar._textbox.value = "foo";
registerCleanupFunction(() => {
textbox.value = "";
searchbar._textbox.value = "";
});
let promise = promiseEvent(searchPopup, "popupshown");
@ -133,7 +140,8 @@ add_task(async function test_text() {
EventUtils.synthesizeMouseAtCenter(searchbarEngine, {});
});
let url = Services.search.currentEngine.getSubmission(textbox.value).uri.spec;
let url = Services.search.currentEngine
.getSubmission(searchbar._textbox.value).uri.spec;
await promiseTabLoadEvent(gBrowser.selectedTab, url);
// Move the cursor out of the panel area to avoid messing with other tests.

View File

@ -3,9 +3,9 @@
// whether there is an autocomplete entry for the private search.
add_task(async function() {
// Don't use about:home as the homepage for new windows
Services.prefs.setIntPref("browser.startup.page", 0);
registerCleanupFunction(() => Services.prefs.clearUserPref("browser.startup.page"));
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
let windowsToClose = [];

View File

@ -106,6 +106,12 @@ function promiseContentSearchReady(browser) {
});
}
add_task(async function() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
});
for (let engine of SEARCH_ENGINE_DETAILS) {
add_task(async function() {
let previouslySelectedEngine = Services.search.currentEngine;

View File

@ -1,7 +1,5 @@
// Tests that keyboard navigation in the search panel works as designed.
const searchbar = document.getElementById("searchbar");
const textbox = searchbar._textbox;
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffsContainer =
document.getAnonymousElementByAttribute(searchPopup, "anonid",
@ -22,7 +20,17 @@ function getOpenSearchItems() {
return os;
}
let searchbar;
let textbox;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
textbox = searchbar._textbox;
await promiseNewEngine("testEngine.xml");
// First cleanup the form history in case other tests left things there.

View File

@ -8,10 +8,6 @@ this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
const searchbar = document.getElementById("searchbar");
const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid", "searchbar-search-button");
const goButton = document.getAnonymousElementByAttribute(searchbar, "anonid", "search-go-button");
const textbox = searchbar._textbox;
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const kValues = ["long text", "long text 2", "long text 3"];
@ -62,7 +58,25 @@ async function startCustomizing(aWindow = window) {
return eventPromise;
}
let searchbar;
let textbox;
let searchIcon;
let goButton;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
textbox = searchbar._textbox;
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
goButton = document.getAnonymousElementByAttribute(
searchbar, "anonid", "search-go-button"
);
await promiseNewEngine("testEngine.xml");
// First cleanup the form history in case other tests left things there.

View File

@ -1,13 +1,9 @@
// Tests that keyboard navigation in the search panel works as designed.
const searchbar = document.getElementById("searchbar");
const textbox = searchbar._textbox;
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffsContainer =
document.getAnonymousElementByAttribute(searchPopup, "anonid",
"search-one-off-buttons");
const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
"searchbar-search-button");
const kValues = ["foo1", "foo2", "foo3"];
@ -23,7 +19,21 @@ function getOpenSearchItems() {
return os;
}
let searchbar;
let textbox;
let searchIcon;
add_task(async function init() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
searchbar = document.getElementById("searchbar");
textbox = searchbar._textbox;
searchIcon = document.getAnonymousElementByAttribute(
searchbar, "anonid", "searchbar-search-button"
);
await promiseNewEngine("testEngine.xml");
// First cleanup the form history in case other tests left things there.

View File

@ -4,13 +4,18 @@
// popup shows a submenu that lists them instead of showing them in the popup
// itself.
const searchbar = document.getElementById("searchbar");
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffsContainer =
document.getAnonymousElementByAttribute(searchPopup, "anonid",
"search-one-off-buttons");
add_task(async function test() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
let searchbar = document.getElementById("searchbar");
let rootDir = getRootDirectory(gTestPath);
let url = rootDir + "tooManyEnginesOffered.html";
await BrowserTestUtils.openNewForegroundTab(gBrowser, url);

View File

@ -9,7 +9,11 @@
const BROWSER_SEARCH_PREF = "browser.search.";
function test() {
add_task(async function test() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
let engine = Services.search.getEngineByName("Yahoo");
ok(engine, "Yahoo");
@ -129,4 +133,4 @@ function test() {
};
isSubObjectOf(EXPECTED_ENGINE, engine, "Yahoo");
}
});

View File

@ -273,11 +273,18 @@ var tests = [
is(icon.src, "", "Popup should have no icon");
is(buttons.hasChildNodes(), false, "Popup should have no buttons");
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
await showInfoPromise("search", "search title", "search text");
is(popup.popupBoxObject.anchorNode, document.getElementById("searchbar"), "Popup should be anchored to the searchbar");
is(title.textContent, "search title", "Popup should have correct title");
is(desc.textContent, "search text", "Popup should have correct description text");
await SpecialPowers.popPrefEnv();
}),
function test_getConfigurationVersion(done) {
function callback(result) {

View File

@ -162,6 +162,11 @@ add_UITour_task(async function test_getConfiguration_selectedSearchEngine() {
});
add_UITour_task(async function test_setSearchTerm() {
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
const TERM = "UITour Search Term";
await gContentAPI.setSearchTerm(TERM);
@ -169,13 +174,22 @@ add_UITour_task(async function test_setSearchTerm() {
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
await waitForConditionPromise(() => searchbar.value == TERM, "Correct term set");
await SpecialPowers.popPrefEnv();
});
add_UITour_task(async function test_clearSearchTerm() {
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
await gContentAPI.setSearchTerm("");
let searchbar = document.getElementById("searchbar");
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
await waitForConditionPromise(() => searchbar.value == "", "Search term cleared");
await SpecialPowers.popPrefEnv();
});

View File

@ -29,8 +29,6 @@ function getExpectedTargets() {
"privateWindow",
...(hasQuit ? ["quit"] : []),
"readerMode-urlBar",
"search",
"searchIcon",
"trackingProtection",
"urlbar",
];
@ -62,17 +60,16 @@ add_UITour_task(async function test_availableTargets_changeWidgets() {
"Targets should not be cached after reset");
});
add_UITour_task(async function test_availableTargets_exceptionFromGetTarget() {
// The query function for the "search" target will throw if it's not found.
// Make sure the callback still fires with the other available targets.
CustomizableUI.removeWidgetFromArea("search-container");
let data = await getConfigurationPromise("availableTargets");
let expecteds = getExpectedTargets();
// Default minus "search" and "searchIcon"
expecteds = expecteds.filter(target => target != "search" && target != "searchIcon");
ok_targets(data, expecteds);
CustomizableUI.reset();
add_UITour_task(async function test_availableTargets_search() {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
try {
let data = await getConfigurationPromise("availableTargets");
let expecteds = getExpectedTargets();
expecteds = ["search", "searchIcon", ...expecteds];
ok_targets(data, expecteds);
} finally {
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
}
});
add_UITour_task(async function test_availableTargets_removeUrlbarPageActionsAll() {

View File

@ -13,15 +13,17 @@ function test() {
var tests = [
function test_openSearchPanel(done) {
let searchbar = document.getElementById("searchbar");
// If suggestions are enabled, the panel will attempt to use the network to connect
// to the suggestions provider, causing the test suite to fail.
// If suggestions are enabled, the panel will attempt to use the network to
// connect to the suggestions provider, causing the test suite to fail. We
// also change the preference to display the search bar during the test.
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
Services.prefs.clearUserPref("browser.search.suggest.enabled");
});
let searchbar = document.getElementById("searchbar");
ok(!searchbar.textbox.open, "Popup starts as closed");
gContentAPI.openSearchPanel(() => {
ok(searchbar.textbox.open, "Popup was opened");

View File

@ -55,7 +55,6 @@ XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREA_PLACEMENTS", function() {
"stop-reload-button",
"home-button",
"urlbar-container",
"search-container",
"downloads-button",
"library-button",
"sidebar-button",
@ -88,6 +87,7 @@ XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREAS", function() {
XPCOMUtils.defineLazyGetter(this, "PALETTE_ITEMS", function() {
let result = [
"bookmarks-menu-button",
"search-container",
"open-file-button",
"developer-button",
"feed-button",

View File

@ -64,6 +64,10 @@ function clickSearchbarSuggestion(entryName) {
}
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({ set: [
["browser.search.widget.inNavBar", true],
]});
// Create two new search engines. Mark one as the default engine, so
// the test don't crash. We need to engines for this test as the searchbar
// doesn't display the default search engine among the one-off engines.

View File

@ -1,6 +1,7 @@
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
let searchBar = BrowserSearch.searchBar;
searchBar.focus();
@ -21,6 +22,7 @@ function test() {
EventUtils.synthesizeKey("VK_ESCAPE", {});
is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED,
"IME should be available after focus is back to the searchbar");
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
finish();
}, 0);
}, {once: true});

View File

@ -4,9 +4,10 @@
// the background color and the color of the navbar text fields are applied properly.
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.webextensions.themes.enabled", true]],
});
await SpecialPowers.pushPrefEnv({set: [
["extensions.webextensions.themes.enabled", true],
["browser.search.widget.inNavBar", true],
]});
});
add_task(async function test_support_toolbar_field_properties() {