1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug581076.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Bug 581076 - No "See all results" link present when searching for add-ons and not all are displayed (extensions.getAddons.maxResults) 1.9 + 1.10 +const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL"; 1.11 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.12 +const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults"; 1.13 +const SEARCH_URL = TESTROOT + "browser_searching.xml"; 1.14 +const SEARCH_EXPECTED_TOTAL = 100; 1.15 +const SEARCH_QUERY = "search"; 1.16 + 1.17 +var gManagerWindow; 1.18 + 1.19 + 1.20 +function test() { 1.21 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); 1.22 + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); 1.23 + 1.24 + waitForExplicitFinish(); 1.25 + 1.26 + open_manager("addons://list/extension", function(aWindow) { 1.27 + gManagerWindow = aWindow; 1.28 + run_next_test(); 1.29 + }); 1.30 +} 1.31 + 1.32 +function end_test() { 1.33 + // Test generates a lot of available installs so just cancel them all 1.34 + AddonManager.getAllInstalls(function(aInstalls) { 1.35 + for (let install of aInstalls) 1.36 + install.cancel(); 1.37 + 1.38 + close_manager(gManagerWindow, finish); 1.39 + }); 1.40 +} 1.41 + 1.42 +function search(aRemoteSearch, aCallback) { 1.43 + waitForFocus(function() { 1.44 + var searchBox = gManagerWindow.document.getElementById("header-search"); 1.45 + searchBox.value = SEARCH_QUERY; 1.46 + 1.47 + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); 1.48 + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); 1.49 + 1.50 + wait_for_view_load(gManagerWindow, function() { 1.51 + if (aRemoteSearch) 1.52 + var filter = gManagerWindow.document.getElementById("search-filter-remote"); 1.53 + else 1.54 + var filter = gManagerWindow.document.getElementById("search-filter-local"); 1.55 + EventUtils.synthesizeMouseAtCenter(filter, { }, gManagerWindow); 1.56 + 1.57 + executeSoon(aCallback); 1.58 + }); 1.59 + }, gManagerWindow); 1.60 +} 1.61 + 1.62 +function check_allresultslink(aShouldShow) { 1.63 + var list = gManagerWindow.document.getElementById("search-list"); 1.64 + var link = gManagerWindow.document.getElementById("search-allresults-link"); 1.65 + is(link.parentNode, list.lastChild, "Footer should be at the end of the richlistbox"); 1.66 + if (aShouldShow) { 1.67 + is_element_visible(link, "All Results link should be visible"); 1.68 + is(link.value, "See all " + SEARCH_EXPECTED_TOTAL + " results", "All Results link should show the correct message"); 1.69 + var scope = {}; 1.70 + Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", scope); 1.71 + is(link.href, scope.AddonRepository.getSearchURL(SEARCH_QUERY), "All Results link should have the correct href"); 1.72 + } else { 1.73 + is_element_hidden(link, "All Results link should be hidden"); 1.74 + } 1.75 +} 1.76 + 1.77 +add_test(function() { 1.78 + info("Searching locally"); 1.79 + search(false, function() { 1.80 + check_allresultslink(false); 1.81 + restart_manager(gManagerWindow, null, function(aManager) { 1.82 + gManagerWindow = aManager; 1.83 + run_next_test(); 1.84 + }); 1.85 + }); 1.86 +}); 1.87 + 1.88 +add_test(function() { 1.89 + info("Searching remotely - more results than cap"); 1.90 + Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3); 1.91 + search(true, function() { 1.92 + check_allresultslink(true); 1.93 + restart_manager(gManagerWindow, null, function(aManager) { 1.94 + gManagerWindow = aManager; 1.95 + run_next_test(); 1.96 + }); 1.97 + }); 1.98 +}); 1.99 + 1.100 +add_test(function() { 1.101 + info("Searching remotely - less results than cap"); 1.102 + Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 200); 1.103 + search(true, function() { 1.104 + check_allresultslink(false); 1.105 + restart_manager(gManagerWindow, null, function(aManager) { 1.106 + gManagerWindow = aManager; 1.107 + run_next_test(); 1.108 + }); 1.109 + }); 1.110 +}); 1.111 + 1.112 +add_test(function() { 1.113 + info("Searching remotely - more results than cap"); 1.114 + Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3); 1.115 + search(true, function() { 1.116 + check_allresultslink(true); 1.117 + run_next_test(); 1.118 + }); 1.119 +}); 1.120 + 1.121 +add_test(function() { 1.122 + info("Switching views"); 1.123 + gManagerWindow.loadView("addons://list/extension"); 1.124 + wait_for_view_load(gManagerWindow, function() { 1.125 + info("Re-loading previous search"); 1.126 + search(true, function() { 1.127 + check_allresultslink(true); 1.128 + run_next_test(); 1.129 + }); 1.130 + }); 1.131 +});