Bug 1493536 - Convert search-one-offs binding to custom element;r=dao

Differential Revision: https://phabricator.services.mozilla.com/D9710

--HG--
rename : browser/components/search/content/search.xml => browser/components/search/content/search-one-offs.js
extra : moz-landing-system : lando
This commit is contained in:
Brian Grinstead 2018-10-25 09:36:15 +00:00
Родитель 1de0980839
Коммит a1b87b1887
18 изменённых файлов: 1259 добавлений и 1340 удалений

Просмотреть файл

@ -51,12 +51,8 @@
-moz-binding: url("chrome://browser/content/search/search.xml#searchbar-textbox");
}
.search-one-offs {
-moz-binding: url("chrome://browser/content/search/search.xml#search-one-offs");
}
.search-setting-button[compact=true],
.search-setting-button-compact:not([compact=true]) {
.search-one-offs[compact=true] .search-setting-button,
.search-one-offs:not([compact=true]) .search-setting-button-compact {
display: none;
}

Просмотреть файл

@ -17,6 +17,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
for (let script of [
"chrome://browser/content/browser.js",
"chrome://browser/content/search/searchbar.js",
"chrome://browser/content/search/search-one-offs.js",
"chrome://browser/content/browser-captivePortal.js",
"chrome://browser/content/browser-compacttheme.js",

Просмотреть файл

@ -21,8 +21,8 @@ if (AppConstants.DEBUG ||
AppConstants.platform == "macosx") {
EXPECTED_REFLOWS_FIRST_OPEN.push({
stack: [
"_rebuild@chrome://browser/content/search/search.xml",
"set_popup@chrome://browser/content/search/search.xml",
"_rebuild@chrome://browser/content/search/search-one-offs.js",
"set popup@chrome://browser/content/search/search-one-offs.js",
"set_oneOffSearchesEnabled@chrome://browser/content/urlbarBindings.xml",
"_enableOrDisableOneOffSearches@chrome://browser/content/urlbarBindings.xml",
"@chrome://browser/content/urlbarBindings.xml",

Просмотреть файл

@ -22,8 +22,8 @@ if (AppConstants.DEBUG ||
AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
EXPECTED_REFLOWS_FIRST_OPEN.push({
stack: [
"_rebuild@chrome://browser/content/search/search.xml",
"set_popup@chrome://browser/content/search/search.xml",
"_rebuild@chrome://browser/content/search/search-one-offs.js",
"set popup@chrome://browser/content/search/search-one-offs.js",
"set_oneOffSearchesEnabled@chrome://browser/content/urlbarBindings.xml",
"_enableOrDisableOneOffSearches@chrome://browser/content/urlbarBindings.xml",
"@chrome://browser/content/urlbarBindings.xml",

Просмотреть файл

@ -59,8 +59,9 @@ add_task(async function test_open_settings_with_enter() {
await selectSettings(() => {
EventUtils.synthesizeKey("KEY_ArrowUp");
Assert.equal(gURLBar.popup.oneOffSearchButtons.selectedButton.getAttribute("anonid"),
"search-settings-compact", "Should have selected the settings button");
Assert.ok(gURLBar.popup.oneOffSearchButtons.selectedButton
.classList.contains("search-setting-button-compact"),
"Should have selected the settings button");
EventUtils.synthesizeKey("KEY_Enter");
});

Просмотреть файл

@ -1876,7 +1876,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
flex="1"/>
<xul:hbox anonid="footer">
<children/>
<xul:vbox anonid="one-off-search-buttons"
<xul:search-one-offs anonid="one-off-search-buttons"
class="search-one-offs"
compact="true"
includecurrentengine="true"

Просмотреть файл

@ -33,9 +33,7 @@ async function test_opensearch(shouldWork) {
let oneOffsContainer = document.getAnonymousElementByAttribute(searchPopup,
"anonid",
"search-one-off-buttons");
let engineListElement = document.getAnonymousElementByAttribute(oneOffsContainer,
"anonid",
"add-engines");
let engineListElement = oneOffsContainer.querySelector(".search-add-engines");
if (shouldWork) {
ok(engineListElement.firstElementChild,
"There should be search engines available to add");

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,6 +5,7 @@
browser.jar:
content/browser/search/search.xml (content/search.xml)
content/browser/search/searchbar.js (content/searchbar.js)
content/browser/search/search-one-offs.js (content/search-one-offs.js)
content/browser/search/searchReset.xhtml (content/searchReset.xhtml)
content/browser/search/searchReset.js (content/searchReset.js)

Просмотреть файл

@ -4,18 +4,12 @@ const TEST_ENGINE_NAME = "Foo";
const TEST_ENGINE_BASENAME = "testEngine.xml";
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffBinding = document.getAnonymousElementByAttribute(
const oneOffElement = document.getAnonymousElementByAttribute(
searchPopup, "anonid", "search-one-off-buttons"
);
const contextMenu = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-one-offs-context-menu"
);
const oneOffButtons = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-panel-one-offs"
);
const searchInNewTabMenuItem = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-one-offs-context-open-in-new-tab"
);
const contextMenu = oneOffElement.querySelector(".search-one-offs-context-menu");
const oneOffButtons = oneOffElement.buttons;
const searchInNewTabMenuItem = oneOffElement.querySelector(".search-one-offs-context-open-in-new-tab");
let searchbar;
let searchIcon;

Просмотреть файл

@ -9,10 +9,10 @@ const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
const urlbar = document.getElementById("urlbar");
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const urlbarPopup = document.getElementById("PopupAutoCompleteRichResult");
const searchOneOffBinding = document.getAnonymousElementByAttribute(
const searchOneOffElement = document.getAnonymousElementByAttribute(
searchPopup, "anonid", "search-one-off-buttons"
);
const urlBarOneOffBinding = document.getAnonymousElementByAttribute(
const urlBarOneOffElement = document.getAnonymousElementByAttribute(
urlbarPopup, "anonid", "one-off-search-buttons"
);
@ -40,11 +40,11 @@ add_task(async function init() {
add_task(async function test_searchBarChangeEngine() {
let oneOffButton = await openPopupAndGetEngineButton(true, searchPopup,
searchOneOffBinding,
searchOneOffElement,
SEARCHBAR_BASE_ID);
const setDefaultEngineMenuItem = document.getAnonymousElementByAttribute(
searchOneOffBinding, "anonid", "search-one-offs-context-set-default"
const setDefaultEngineMenuItem = searchOneOffElement.querySelector(
".search-one-offs-context-set-default"
);
// Click the set default engine menu item.
@ -74,11 +74,11 @@ add_task(async function test_urlBarChangeEngine() {
resetEngine();
let oneOffButton = await openPopupAndGetEngineButton(false, urlbarPopup,
urlBarOneOffBinding,
urlBarOneOffElement,
URLBAR_BASE_ID);
const setDefaultEngineMenuItem = document.getAnonymousElementByAttribute(
urlBarOneOffBinding, "anonid", "search-one-offs-context-set-default"
const setDefaultEngineMenuItem = urlBarOneOffElement.querySelector(
".search-one-offs-context-set-default"
);
// Click the set default engine menu item.
@ -128,13 +128,13 @@ function promiseCurrentEngineChanged() {
* @param {Boolean} isSearch true if the search popup should be opened; false
* for the urlbar popup.
* @param {Object} popup The expected popup.
* @param {Object} oneOffBinding The expected one-off-binding for the popup.
* @param {Object} oneOffElement The expected one-off-element for the popup.
* @param {String} baseId The expected string for the id of the current
* engine button, without the engine name.
* @return {Object} Returns an object that represents the one off button for the
* test engine.
*/
async function openPopupAndGetEngineButton(isSearch, popup, oneOffBinding, baseId) {
async function openPopupAndGetEngineButton(isSearch, popup, oneOffElement, baseId) {
// Open the popup.
let promise = promiseEvent(popup, "popupshown");
info("Opening panel");
@ -150,12 +150,8 @@ async function openPopupAndGetEngineButton(isSearch, popup, oneOffBinding, baseI
}
await promise;
const contextMenu = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-one-offs-context-menu"
);
const oneOffButtons = document.getAnonymousElementByAttribute(
oneOffBinding, "anonid", "search-panel-one-offs"
);
const contextMenu = oneOffElement.contextMenuPopup;
const oneOffButtons = oneOffElement.buttons;
// Get the one-off button for the test engine.
let oneOffButton;

Просмотреть файл

@ -10,12 +10,10 @@ const searchPopup = document.getElementById("PopupSearchAutoComplete");
const oneOffsContainer =
document.getAnonymousElementByAttribute(searchPopup, "anonid",
"search-one-off-buttons");
const searchSettings =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"search-settings");
var header =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"search-panel-one-offs-header");
const searchSettings = oneOffsContainer.querySelector(".search-setting-button");
var header = oneOffsContainer.querySelector(".search-panel-one-offs-header");
function getHeaderText() {
let headerChild = header.selectedPanel;
while (headerChild.hasChildNodes()) {

Просмотреть файл

@ -12,8 +12,7 @@ function getOpenSearchItems() {
let os = [];
let addEngineList =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"add-engines");
oneOffsContainer.querySelector(".search-add-engines");
for (let item = addEngineList.firstElementChild; item; item = item.nextElementSibling)
os.push(item);
@ -99,7 +98,7 @@ add_task(async function test_arrows() {
EventUtils.synthesizeKey("KEY_ArrowDown");
}
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
EventUtils.synthesizeKey("KEY_ArrowDown");
@ -109,7 +108,7 @@ add_task(async function test_arrows() {
info("now test the up arrow key");
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// cycle through the one-off items, the first one is already selected.
@ -143,7 +142,7 @@ add_task(async function test_typing_clears_button_selection() {
ok(!textbox.selectedButton, "no button should be selected");
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// Type a character.
@ -173,7 +172,7 @@ add_task(async function test_tab() {
// One more <tab> selects the settings button.
EventUtils.synthesizeKey("KEY_Tab");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// Pressing tab again should close the panel...
@ -198,7 +197,7 @@ add_task(async function test_shift_tab() {
// Press up once to select the last button.
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// Press up again to select the last one-off button.
@ -303,7 +302,7 @@ add_task(async function test_alt_up() {
// Cleanup for the next test.
EventUtils.synthesizeKey("KEY_ArrowDown");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
EventUtils.synthesizeKey("KEY_ArrowDown");
ok(!textbox.selectedButton, "no one-off should be selected anymore");
@ -394,7 +393,7 @@ add_task(async function test_open_search() {
// Pressing up once selects the setting button...
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// ...and then pressing up selects open search engines.
@ -421,7 +420,7 @@ add_task(async function test_open_search() {
// Pressing down on the last engine item selects the settings button.
EventUtils.synthesizeKey("KEY_ArrowDown");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
promise = promiseEvent(searchPopup, "popuphidden");

Просмотреть файл

@ -11,8 +11,7 @@ function getOpenSearchItems() {
let os = [];
let addEngineList =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"add-engines");
oneOffsContainer.querySelector(".search-add-engines");
for (let item = addEngineList.firstElementChild; item; item = item.nextElementSibling)
os.push(item);
@ -91,7 +90,7 @@ info("textbox.mController.searchString = " + textbox.mController.searchString);
EventUtils.synthesizeKey("KEY_ArrowDown");
}
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
EventUtils.synthesizeKey("KEY_ArrowDown");
@ -101,7 +100,7 @@ info("textbox.mController.searchString = " + textbox.mController.searchString);
info("now test the up arrow key");
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// cycle through the one-off items, the first one is already selected.
@ -137,7 +136,7 @@ add_task(async function test_tab() {
// One more <tab> selects the settings button.
EventUtils.synthesizeKey("KEY_Tab");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// Pressing tab again should close the panel...
@ -165,7 +164,7 @@ add_task(async function test_shift_tab() {
// Press up once to select the last button.
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// Press up again to select the last one-off button.
@ -257,7 +256,7 @@ add_task(async function test_alt_up() {
// Cleanup for the next test.
EventUtils.synthesizeKey("KEY_ArrowDown");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
EventUtils.synthesizeKey("KEY_ArrowDown");
ok(!textbox.selectedButton, "no one-off should be selected anymore");
@ -313,7 +312,7 @@ add_task(async function test_open_search() {
// Pressing up once selects the setting button...
EventUtils.synthesizeKey("KEY_ArrowUp");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
// ...and then pressing up selects open search engines.
@ -340,7 +339,7 @@ add_task(async function test_open_search() {
// Pressing down on the last engine item selects the settings button.
EventUtils.synthesizeKey("KEY_ArrowDown");
is(textbox.selectedButton.getAttribute("anonid"), "search-settings",
ok(textbox.selectedButton.classList.contains("search-setting-button"),
"the settings item should be selected");
promise = promiseEvent(searchPopup, "popuphidden");

Просмотреть файл

@ -86,9 +86,7 @@ add_task(async function test() {
function getOpenSearchItems() {
let os = [];
let addEngineList =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"add-engines");
let addEngineList = oneOffsContainer.querySelector(".search-add-engines");
for (let item = addEngineList.firstElementChild; item; item = item.nextElementSibling)
os.push(item);

Просмотреть файл

@ -188,8 +188,7 @@ function getOneOffs() {
document.getAnonymousElementByAttribute(searchPopup, "anonid",
"search-one-off-buttons");
let oneOff =
document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
"search-panel-one-offs");
oneOffsContainer.querySelector(".search-panel-one-offs");
for (oneOff = oneOff.firstChild; oneOff; oneOff = oneOff.nextSibling) {
if (oneOff.nodeType == Node.ELEMENT_NODE) {
if (oneOff.classList.contains("dummy") ||

Просмотреть файл

@ -10,6 +10,10 @@
fill: currentColor;
}
.search-one-offs {
-moz-box-orient: vertical;
}
/**
* The borders of the various elements are specified as follows.
*
@ -104,10 +108,10 @@
border-bottom: none !important;
}
.search-panel-one-offs:not([compact=true]) > .searchbar-engine-one-off-item.last-of-row,
.search-panel-one-offs[compact=true] > .searchbar-engine-one-off-item.last-of-row:not(.dummy),
.search-panel-one-offs[compact=true] > .searchbar-engine-one-off-item.dummy:not(.last-of-row),
.search-panel-one-offs[compact=true] > .searchbar-engine-one-off-item.last-engine,
.search-one-offs:not([compact=true]) .searchbar-engine-one-off-item.last-of-row,
.search-one-offs[compact=true] .searchbar-engine-one-off-item.last-of-row:not(.dummy),
.search-one-offs[compact=true] .searchbar-engine-one-off-item.dummy:not(.last-of-row),
.search-one-offs[compact=true] .searchbar-engine-one-off-item.last-engine,
.search-setting-button-compact {
background-image: none;
}