Bug 581076 - No "See all results" link present when searching for add-ons and not all are displayed (extensions.getAddons.maxResults). r=dtownsend, a=blocking-beta6

This commit is contained in:
Blair McBride 2010-08-28 14:45:11 +12:00
parent f57e7fa2e6
commit b6b7d4f7a9
11 changed files with 189 additions and 19 deletions

View File

@ -56,13 +56,12 @@ pref("browser.hiddenWindowChromeURL", "chrome://browser/content/hiddenWindow.xul
// Enables some extra Extension System Logging (can reduce performance)
pref("extensions.logging.enabled", false);
// Preferences for the Addon Repository
// Preferences for AMO integration
pref("extensions.getAddons.cache.enabled", true);
pref("extensions.getAddons.maxResults", 15);
pref("extensions.getAddons.get.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/guid:%IDS%");
pref("extensions.getAddons.search.browseURL", "https://addons.mozilla.org/%LOCALE%/%APP%/search?q=%TERMS%");
pref("extensions.getAddons.search.url", "https://services.addons.mozilla.org/%LOCALE%/%APP%/api/%API_VERSION%/search/%TERMS%/all/%MAX_RESULTS%/%OS%/%VERSION%");
// Preferences for AMO integration
pref("extensions.webservice.discoverURL", "https://services.addons.mozilla.org/%LOCALE%/%APP%/discovery/%VERSION%/%OS%");
// Blocklist preferences

View File

@ -81,3 +81,6 @@ enableAddonTooltip=Enable this add-on
enableAddonRestartRequiredTooltip=Enable this add-on (restart required)
disableAddonTooltip=Disable this add-on
disableAddonRestartRequiredTooltip=Disable this add-on (restart required)
#LOCALIZATION NOTE (showAllSearchResults) #1 is the total number of search results
showAllSearchResults=See one result;See all #1 results

View File

@ -115,7 +115,8 @@ xhtml|link {
#detail-view:not([upgrade="true"]) .update-postfix,
#detail-view[active="true"] .disabled-postfix,
#detail-view[loading] > .detail-view-container,
.detail-row:not([value]) {
.detail-row:not([value]),
#search-list[remote="false"] #search-allresults-link {
display: none;
}

View File

@ -1201,7 +1201,9 @@ var gSearchView = {
_sorters: null,
_listBox: null,
_emptyNotice: null,
_allResultsLink: null,
_lastQuery: null,
_lastRemoteTotal: 0,
_pendingSearches: 0,
initialize: function() {
@ -1211,6 +1213,7 @@ var gSearchView = {
this._sorters.handler = this;
this._listBox = document.getElementById("search-list");
this._emptyNotice = document.getElementById("search-list-empty");
this._allResultsLink = document.getElementById("search-allresults-link");
var self = this;
this._listBox.addEventListener("keydown", function(aEvent) {
@ -1237,6 +1240,7 @@ var gSearchView = {
show: function(aQuery, aRequest) {
gHeader.isSearching = true;
this.showEmptyNotice(false);
this.showAllResultsLink(0);
gHeader.searchQuery = aQuery;
aQuery = aQuery.trim().toLocaleLowerCase();
@ -1250,8 +1254,8 @@ var gSearchView = {
if (AddonRepository.isSearching)
AddonRepository.cancelSearch();
while (this._listBox.lastChild.localName == "richlistitem")
this._listBox.removeChild(this._listBox.lastChild);
while (this._listBox.firstChild.localName == "richlistitem")
this._listBox.removeChild(this._listBox.firstChild);
var self = this;
gCachedAddons = {};
@ -1273,7 +1277,7 @@ var gSearchView = {
if (aIsRemote)
gCachedAddons[aObj.id] = aObj;
self._listBox.appendChild(item);
self._listBox.insertBefore(item, self._listBox.lastChild);
createdCount++;
});
@ -1315,6 +1319,8 @@ var gSearchView = {
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
self._lastRemoteTotal = 0;
// XXXunf Better handling of AMO search failure. See bug 579502
finishSearch(0); // Silently fail
},
@ -1323,6 +1329,11 @@ var gSearchView = {
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
if (aTotalResults > maxRemoteResults)
self._lastRemoteTotal = aTotalResults;
else
self._lastRemoteTotal = 0;
var createdCount = createSearchResults(aAddonsList, false, true);
finishSearch(createdCount);
}
@ -1347,6 +1358,7 @@ var gSearchView = {
}
this.showEmptyNotice(isEmpty);
this.showAllResultsLink(this._lastRemoteTotal);
}
gViewController.updateCommands();
@ -1407,9 +1419,24 @@ var gSearchView = {
this._emptyNotice.hidden = !aShow;
},
showAllResultsLink: function(aTotalResults) {
if (aTotalResults == 0) {
this._allResultsLink.hidden = true;
return;
}
var linkStr = gStrings.ext.GetStringFromName("showAllSearchResults");
linkStr = PluralForm.get(aTotalResults, linkStr);
linkStr = linkStr.replace("#1", aTotalResults);
this._allResultsLink.value = linkStr;
this._allResultsLink.href = AddonRepository.getSearchURL(this._lastQuery);
this._allResultsLink.hidden = false;
},
onSortChanged: function(aSortBy, aAscending) {
var header = this._listBox.firstChild;
this._listBox.removeChild(header);
var footer = this._listBox.lastChild;
this._listBox.removeChild(footer);
var hints = aAscending ? "ascending" : "descending";
if (INTEGER_FIELDS.indexOf(aSortBy) >= 0)
@ -1419,7 +1446,7 @@ var gSearchView = {
getService(Ci.nsIXULSortService);
sortService.sort(this._listBox, aSortBy, hints);
this._listBox.insertBefore(header, this._listBox.firstChild);
this._listBox.appendChild(footer);
},
getSelectedAddon: function() {

View File

@ -238,15 +238,18 @@
<hbox id="search-sorters" class="sort-controls"
showrelevance="true" sortby="relevancescore" ascending="false"/>
</hbox>
<vbox id="search-list-empty" class="empty-list-notice"
flex="1" hidden="true">
<spacer flex="1"/>
<label value="&listEmpty.search.label;"/>
<button label="&listEmpty.button.label;" class="addon-control"
command="cmd_goToDiscoverPane"/>
<spacer flex="3"/>
</vbox>
<richlistbox id="search-list" class="list" flex="1">
<vbox id="search-list-empty" class="empty-list-notice"
flex="1" hidden="true">
<spacer flex="1"/>
<label value="&listEmpty.search.label;"/>
<button label="&listEmpty.button.label;" class="addon-control"
command="cmd_goToDiscoverPane"/>
<spacer flex="3"/>
</vbox>
<hbox pack="center">
<label id="search-allresults-link" class="text-link"/>
</hbox>
</richlistbox>
</vbox>

View File

@ -60,6 +60,7 @@ _TEST_FILES = \
browser_bug567137.js \
browser_bug572561.js \
browser_bug577990.js \
browser_bug581076.js \
browser_details.js \
browser_dragdrop.js \
browser_list.js \

View File

@ -0,0 +1,121 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Bug 581076 - No "See all results" link present when searching for add-ons and not all are displayed (extensions.getAddons.maxResults)
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults";
const SEARCH_URL = TESTROOT + "browser_searching.xml";
const SEARCH_EXPECTED_TOTAL = 100;
const SEARCH_QUERY = "search";
var gManagerWindow;
function test() {
Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL);
Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
waitForExplicitFinish();
open_manager(null, function(aWindow) {
gManagerWindow = aWindow;
run_next_test();
});
}
function end_test() {
Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
close_manager(gManagerWindow, finish);
}
function search(aRemoteSearch, aCallback) {
var searchBox = gManagerWindow.document.getElementById("header-search");
searchBox.value = SEARCH_QUERY;
EventUtils.synthesizeMouse(searchBox, 2, 2, { }, gManagerWindow);
EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
wait_for_view_load(gManagerWindow, function() {
if (aRemoteSearch)
var filter = gManagerWindow.document.getElementById("search-filter-remote");
else
var filter = gManagerWindow.document.getElementById("search-filter-local");
EventUtils.synthesizeMouse(filter, 2, 2, { }, gManagerWindow);
executeSoon(aCallback);
});
}
function check_allresultslink(aShouldShow) {
var list = gManagerWindow.document.getElementById("search-list");
var link = gManagerWindow.document.getElementById("search-allresults-link");
is(link.parentNode, list.lastChild, "Footer should be at the end of the richlistbox");
if (aShouldShow) {
is_element_visible(link, "All Results link should be visible");
is(link.value, "See all " + SEARCH_EXPECTED_TOTAL + " results", "All Results link should show the correct message");
var scope = {};
Components.utils.import("resource://gre/modules/AddonRepository.jsm", scope);
is(link.href, scope.AddonRepository.getSearchURL(SEARCH_QUERY), "All Results link should have the correct href");
} else {
is_element_hidden(link, "All Results link should be hidden");
}
}
add_test(function() {
info("Searching locally");
search(false, function() {
check_allresultslink(false);
restart_manager(gManagerWindow, null, function(aManager) {
gManagerWindow = aManager;
run_next_test();
});
});
});
add_test(function() {
info("Searching remotely - more results than cap");
Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3);
search(true, function() {
check_allresultslink(true);
restart_manager(gManagerWindow, null, function(aManager) {
gManagerWindow = aManager;
run_next_test();
});
});
});
add_test(function() {
info("Searching remotely - less results than cap");
Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 200);
search(true, function() {
check_allresultslink(false);
restart_manager(gManagerWindow, null, function(aManager) {
gManagerWindow = aManager;
run_next_test();
});
});
});
add_test(function() {
info("Searching remotely - more results than cap");
Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3);
search(true, function() {
check_allresultslink(true);
run_next_test();
});
});
add_test(function() {
info("Switching views");
gManagerWindow.loadView("addons://list/extension");
wait_for_view_load(gManagerWindow, function() {
info("Re-loading previous search");
search(true, function() {
check_allresultslink(true);
run_next_test();
});
});
});

View File

@ -389,7 +389,7 @@ function run_test_1() {
urlTests: urlTests,
getURL: function() AddonRepository.getRecommendedURL()
}, {
initiallyUndefined: true,
initiallyUndefined: false,
preference: PREF_GETADDONS_BROWSESEARCHRESULTS,
urlTests: urlTests.concat(searchURLTests),
getURL: function getSearchURL(aTest) {

View File

@ -507,6 +507,11 @@
display: none;
}
#search-allresults-link {
margin-top: 1em;
margin-bottom: 2em;
}
/*** detail view ***/
#detail-view[active="false"] .fade {

View File

@ -531,6 +531,11 @@
display: none;
}
#search-allresults-link {
margin-top: 1em;
margin-bottom: 2em;
}
/*** detail view ***/
#detail-view[active="false"] .fade {

View File

@ -498,6 +498,11 @@
display: none;
}
#search-allresults-link {
margin-top: 1em;
margin-bottom: 2em;
}
/*** detail view ***/
#detail-view[active="false"] .fade {