mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1530334 - Port browser_ext_themes_autocomplete_popup.js to work with QuantumBar. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D22289 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
cbc8307003
commit
9fe29aff7f
@ -145,6 +145,18 @@ var UrlbarTestUtils = {
|
||||
return urlbar.getResultCount();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the results panel object associated with the window.
|
||||
* @note generally tests should use getDetailsOfResultAt rather than
|
||||
* accessing panel elements directly.
|
||||
* @param {object} win The window containing the urlbar
|
||||
* @returns {object} the results panel object.
|
||||
*/
|
||||
getPanel(win) {
|
||||
let urlbar = getUrlbarAbstraction(win);
|
||||
return urlbar.panel;
|
||||
},
|
||||
|
||||
/**
|
||||
* Ensures at least one search suggestion is present.
|
||||
* @param {object} win The window containing the urlbar
|
||||
@ -401,6 +413,14 @@ class UrlbarAbstraction {
|
||||
action: actions.length > 0 ? actions[0].textContent : null,
|
||||
typeIcon: typeIconStyle["background-image"],
|
||||
};
|
||||
let actionElement = element.getElementsByClassName("urlbarView-action")[0];
|
||||
let urlElement = element.getElementsByClassName("urlbarView-url")[0];
|
||||
details.element = {
|
||||
action: actionElement,
|
||||
row: element,
|
||||
separator: urlElement || actionElement,
|
||||
url: urlElement,
|
||||
};
|
||||
if (details.type == UrlbarUtils.RESULT_TYPE.SEARCH) {
|
||||
details.searchParams = {
|
||||
engine: context.results[index].payload.engine,
|
||||
@ -427,6 +447,12 @@ class UrlbarAbstraction {
|
||||
action: action ? element._actionText.textContent : "",
|
||||
typeIcon: typeIconStyle.listStyleImage,
|
||||
};
|
||||
details.element = {
|
||||
action: element._actionText,
|
||||
row: element,
|
||||
separator: element._separator,
|
||||
url: element._urlText,
|
||||
};
|
||||
if (details.type == UrlbarUtils.RESULT_TYPE.SEARCH) {
|
||||
details.searchParams = {
|
||||
engine: action.params.engineName,
|
||||
|
@ -19,42 +19,9 @@ const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
|
||||
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
|
||||
});
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return new Promise(resolve => {
|
||||
if (popup.state == "open") {
|
||||
resolve();
|
||||
} else {
|
||||
popup.addEventListener("popupshown", function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function promiseAutocompleteResultPopup(inputText) {
|
||||
gURLBar.focus();
|
||||
gURLBar.value = inputText;
|
||||
gURLBar.controller.startSearch(inputText);
|
||||
await promisePopupShown(gURLBar.popup);
|
||||
await BrowserTestUtils.waitForCondition(() => {
|
||||
return gURLBar.controller.searchStatus >=
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH;
|
||||
});
|
||||
}
|
||||
|
||||
async function waitForAutocompleteResultAt(index) {
|
||||
let searchString = gURLBar.controller.searchString;
|
||||
await BrowserTestUtils.waitForCondition(
|
||||
() => gURLBar.popup.richlistbox.itemChildren.length > index &&
|
||||
gURLBar.popup.richlistbox.itemChildren[index].getAttribute("ac-text") == searchString,
|
||||
`Waiting for the autocomplete result for "${searchString}" at [${index}] to appear`);
|
||||
// Ensure the addition is complete, for proper mouse events on the entries.
|
||||
await new Promise(resolve => window.requestIdleCallback(resolve, {timeout: 1000}));
|
||||
return gURLBar.popup.richlistbox.itemChildren[index];
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await PlacesUtils.history.clear();
|
||||
const NUM_VISITS = 10;
|
||||
@ -75,6 +42,8 @@ add_task(async function setup() {
|
||||
});
|
||||
|
||||
add_task(async function test_popup_url() {
|
||||
const quantumbar = UrlbarPrefs.get("quantumbar");
|
||||
|
||||
// Load extension with brighttext not set
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
@ -116,14 +85,15 @@ add_task(async function test_popup_url() {
|
||||
}
|
||||
|
||||
await PlacesTestUtils.addVisits(visits);
|
||||
await promiseAutocompleteResultPopup("example.com/autocomplete");
|
||||
await waitForAutocompleteResultAt(maxResults - 1);
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup(window,
|
||||
"example.com/autocomplete",
|
||||
waitForFocus);
|
||||
await UrlbarTestUtils.waitForAutocompleteResultAt(window, maxResults - 1);
|
||||
|
||||
let popup = gURLBar.popup;
|
||||
let results = popup.richlistbox.itemChildren;
|
||||
is(results.length, maxResults,
|
||||
"Should get maxResults=" + maxResults + " results");
|
||||
Assert.equal(UrlbarTestUtils.getResultCount(window), maxResults,
|
||||
"Should get maxResults=" + maxResults + " results");
|
||||
|
||||
let popup = UrlbarTestUtils.getPanel(window);
|
||||
let popupCS = window.getComputedStyle(popup);
|
||||
|
||||
Assert.equal(popupCS.backgroundColor,
|
||||
@ -137,8 +107,10 @@ add_task(async function test_popup_url() {
|
||||
`Popup color should be set to ${POPUP_TEXT_COLOR_DARK}`);
|
||||
|
||||
// Set the selected attribute to true to test the highlight popup properties
|
||||
results[1].setAttribute("selected", "true");
|
||||
let resultCS = window.getComputedStyle(results[1]);
|
||||
UrlbarTestUtils.setSelectedIndex(window, 1);
|
||||
let actionResult = await UrlbarTestUtils.getDetailsOfResultAt(window, 0);
|
||||
let urlResult = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
|
||||
let resultCS = window.getComputedStyle(urlResult.element.row);
|
||||
|
||||
Assert.equal(resultCS.backgroundColor,
|
||||
`rgb(${hexToRGB(POPUP_SELECTED_COLOR).join(", ")})`,
|
||||
@ -148,15 +120,15 @@ add_task(async function test_popup_url() {
|
||||
`rgb(${hexToRGB(POPUP_SELECTED_TEXT_COLOR).join(", ")})`,
|
||||
`Popup highlight color should be set to ${POPUP_SELECTED_TEXT_COLOR}`);
|
||||
|
||||
results[1].removeAttribute("selected");
|
||||
// Now set the index to somewhere not on the first two, so that we can test both
|
||||
// url and action text colors.
|
||||
UrlbarTestUtils.setSelectedIndex(window, 2);
|
||||
|
||||
let urlText = results[1]._urlText;
|
||||
Assert.equal(window.getComputedStyle(urlText).color,
|
||||
Assert.equal(window.getComputedStyle(urlResult.element.url).color,
|
||||
`rgb(${hexToRGB(POPUP_URL_COLOR_DARK).join(", ")})`,
|
||||
`Urlbar popup url color should be set to ${POPUP_URL_COLOR_DARK}`);
|
||||
|
||||
let actionText = results[1]._actionText;
|
||||
Assert.equal(window.getComputedStyle(actionText).color,
|
||||
Assert.equal(window.getComputedStyle(actionResult.element.action).color,
|
||||
`rgb(${hexToRGB(POPUP_ACTION_COLOR_DARK).join(", ")})`,
|
||||
`Urlbar popup action color should be set to ${POPUP_ACTION_COLOR_DARK}`);
|
||||
|
||||
@ -203,20 +175,17 @@ add_task(async function test_popup_url() {
|
||||
`rgb(${hexToRGB(POPUP_TEXT_COLOR_BRIGHT).join(", ")})`,
|
||||
`Popup color should be set to ${POPUP_TEXT_COLOR_BRIGHT}`);
|
||||
|
||||
urlText = results[1]._urlText;
|
||||
Assert.equal(window.getComputedStyle(urlText).color,
|
||||
Assert.equal(window.getComputedStyle(urlResult.element.url).color,
|
||||
`rgb(${hexToRGB(POPUP_URL_COLOR_BRIGHT).join(", ")})`,
|
||||
`Urlbar popup url color should be set to ${POPUP_URL_COLOR_BRIGHT}`);
|
||||
|
||||
actionText = results[1]._actionText;
|
||||
Assert.equal(window.getComputedStyle(actionText).color,
|
||||
Assert.equal(window.getComputedStyle(actionResult.element.action).color,
|
||||
`rgb(${hexToRGB(POPUP_ACTION_COLOR_BRIGHT).join(", ")})`,
|
||||
`Urlbar popup action color should be set to ${POPUP_ACTION_COLOR_BRIGHT}`);
|
||||
|
||||
// Since brighttext is enabled, the seperator color should be
|
||||
// POPUP_TEXT_COLOR_BRIGHT with added alpha.
|
||||
let separator = results[1]._separator;
|
||||
Assert.equal(window.getComputedStyle(separator).color,
|
||||
Assert.equal(window.getComputedStyle(urlResult.element.separator, quantumbar ? ":before" : null).color,
|
||||
`rgba(${hexToRGB(POPUP_TEXT_COLOR_BRIGHT).join(", ")}, 0.5)`,
|
||||
`Urlbar popup separator color should be set to ${POPUP_TEXT_COLOR_BRIGHT} with alpha`);
|
||||
|
||||
@ -245,8 +214,7 @@ add_task(async function test_popup_url() {
|
||||
let GRAY_TEXT = window.getComputedStyle(span).color;
|
||||
span.remove();
|
||||
|
||||
separator = results[1]._separator;
|
||||
Assert.equal(window.getComputedStyle(separator).color,
|
||||
Assert.equal(window.getComputedStyle(urlResult.element.separator, quantumbar ? ":before" : null).color,
|
||||
GRAY_TEXT,
|
||||
`Urlbar popup separator color should be set to ${GRAY_TEXT}`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user