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