Bug 1071164 - Display magnifying glass for search results in awesomebar (follow-up of bug 1040725). r=Unfocused

This commit is contained in:
Alex Bardas 2014-09-27 16:58:00 +02:00
parent c9105d54de
commit 9bd668bd8a
3 changed files with 128 additions and 1 deletions

View File

@ -109,6 +109,7 @@ skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliabil
skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliability on Linux
[browser_addKeywordSearch.js]
skip-if = e10s
[browser_search_favicon.js]
[browser_alltabslistener.js]
skip-if = os == "linux" || e10s # Linux: Intermittent failures, bug 951680; e10s: Bug ?????? - notifications don't work correctly.
[browser_autocomplete_a11y_label.js]

View File

@ -0,0 +1,121 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
let gOriginalEngine;
let gEngine;
let gUnifiedCompletePref = "browser.urlbar.unifiedcomplete";
/**
* Asynchronously adds visits to a page.
*
* @param aPlaceInfo
* Can be an nsIURI, in such a case a single LINK visit will be added.
* Otherwise can be an object describing the visit to add, or an array
* of these objects:
* { uri: nsIURI of the page,
* transition: one of the TRANSITION_* from nsINavHistoryService,
* [optional] title: title of the page,
* [optional] visitDate: visit date in microseconds from the epoch
* [optional] referrer: nsIURI of the referrer for this visit
* }
*
* @return {Promise}
* @resolves When all visits have been added successfully.
* @rejects JavaScript exception.
*/
function promiseAddVisits(aPlaceInfo) {
return new Promise((resolve, reject) => {
let places = [];
if (aPlaceInfo instanceof Ci.nsIURI) {
places.push({ uri: aPlaceInfo });
}
else if (Array.isArray(aPlaceInfo)) {
places = places.concat(aPlaceInfo);
} else {
places.push(aPlaceInfo)
}
// Create mozIVisitInfo for each entry.
let now = Date.now();
for (let i = 0, len = places.length; i < len; ++i) {
if (!places[i].title) {
places[i].title = "test visit for " + places[i].uri.spec;
}
places[i].visits = [{
transitionType: places[i].transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK
: places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}];
}
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError(aResultCode, aPlaceInfo) {
let ex = new Components.Exception("Unexpected error in adding visits.",
aResultCode);
reject(ex);
},
handleResult: function () {},
handleCompletion: function UP_handleCompletion() {
resolve();
}
}
);
});
}
function* promiseAutocompleteResultPopup(inputText) {
gURLBar.focus();
gURLBar.value = inputText.slice(0, -1);
EventUtils.synthesizeKey(inputText.slice(-1) , {});
yield promiseSearchComplete();
return gURLBar.popup.richlistbox.children;
}
registerCleanupFunction(() => {
Services.prefs.clearUserPref(gUnifiedCompletePref);
Services.search.currentEngine = gOriginalEngine;
Services.search.removeEngine(gEngine);
return promiseClearHistory();
});
add_task(function*() {
Services.prefs.setBoolPref(gUnifiedCompletePref, true);
});
add_task(function*() {
Services.search.addEngineWithDetails("SearchEngine", "", "", "",
"GET", "http://s.example.com/search");
gEngine = Services.search.getEngineByName("SearchEngine");
gEngine.addParam("q", "{searchTerms}", null);
gOriginalEngine = Services.search.currentEngine;
Services.search.currentEngine = gEngine;
let uri = NetUtil.newURI("http://s.example.com/search?q=foo&client=1");
yield promiseAddVisits({ uri: uri, title: "Foo - SearchEngine Search" });
// The first autocomplete result has the action searchengine, while
// the second result is the "search favicon" element.
let result = yield promiseAutocompleteResultPopup("foo");
result = result[1];
isnot(result, null, "Expect a search result");
is(result.getAttribute("type"), "search favicon", "Expect correct `type` attribute");
is_element_visible(result._title, "Title element should be visible");
is_element_visible(result._extraBox, "Extra box element should be visible");
is(result._extraBox.pack, "start", "Extra box element should start after the title");
let iconElem = result._extraBox.nextSibling;
is_element_visible(iconElem,
"The element containing the magnifying glass icon should be visible");
ok(iconElem.classList.contains("ac-result-type-keyword"),
"That icon should have the same class use for `keyword` results");
is_element_visible(result._url, "URL element should be visible");
is(result._url.textContent, "Search with SearchEngine");
});

View File

@ -1567,6 +1567,7 @@ extends="chrome://global/content/bindings/popup.xml#popup">
this._titleOverflowEllipsis.hidden = false;
let types = new Set(type.split(/\s+/));
let initialTypes = new Set(types);
// If the type includes an action, set up the item appropriately.
if (types.has("action")) {
@ -1655,7 +1656,8 @@ extends="chrome://global/content/bindings/popup.xml#popup">
type = "bookmark";
// keyword and favicon type results for search engines
// have an extra magnifying glass icon after them
} else if (type == "keyword" || type == "search favicon") {
} else if (type == "keyword" || (initialTypes.has("search") &&
initialTypes.has("favicon"))) {
// Configure the extra box for keyword display
this._extraBox.hidden = false;
this._extraBox.childNodes[0].hidden = true;
@ -1680,6 +1682,9 @@ extends="chrome://global/content/bindings/popup.xml#popup">
// Don't emphasize keyword searches in the title or url
this.setAttribute("text", "");
} else {
// Don't show any description for non keyword types.
this._setUpDescription(this._extra, "", true);
}
// If the result has the type favicon and a known search provider,
// customize it the same way as a keyword result.