Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Bug 581076 - No "See all results" link present when searching for add-ons and not all are displayed (extensions.getAddons.maxResults) |
michael@0 | 6 | |
michael@0 | 7 | const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL"; |
michael@0 | 8 | const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
michael@0 | 9 | const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults"; |
michael@0 | 10 | const SEARCH_URL = TESTROOT + "browser_searching.xml"; |
michael@0 | 11 | const SEARCH_EXPECTED_TOTAL = 100; |
michael@0 | 12 | const SEARCH_QUERY = "search"; |
michael@0 | 13 | |
michael@0 | 14 | var gManagerWindow; |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); |
michael@0 | 19 | Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
michael@0 | 20 | |
michael@0 | 21 | waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 24 | gManagerWindow = aWindow; |
michael@0 | 25 | run_next_test(); |
michael@0 | 26 | }); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function end_test() { |
michael@0 | 30 | // Test generates a lot of available installs so just cancel them all |
michael@0 | 31 | AddonManager.getAllInstalls(function(aInstalls) { |
michael@0 | 32 | for (let install of aInstalls) |
michael@0 | 33 | install.cancel(); |
michael@0 | 34 | |
michael@0 | 35 | close_manager(gManagerWindow, finish); |
michael@0 | 36 | }); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function search(aRemoteSearch, aCallback) { |
michael@0 | 40 | waitForFocus(function() { |
michael@0 | 41 | var searchBox = gManagerWindow.document.getElementById("header-search"); |
michael@0 | 42 | searchBox.value = SEARCH_QUERY; |
michael@0 | 43 | |
michael@0 | 44 | EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
michael@0 | 45 | EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
michael@0 | 46 | |
michael@0 | 47 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 48 | if (aRemoteSearch) |
michael@0 | 49 | var filter = gManagerWindow.document.getElementById("search-filter-remote"); |
michael@0 | 50 | else |
michael@0 | 51 | var filter = gManagerWindow.document.getElementById("search-filter-local"); |
michael@0 | 52 | EventUtils.synthesizeMouseAtCenter(filter, { }, gManagerWindow); |
michael@0 | 53 | |
michael@0 | 54 | executeSoon(aCallback); |
michael@0 | 55 | }); |
michael@0 | 56 | }, gManagerWindow); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function check_allresultslink(aShouldShow) { |
michael@0 | 60 | var list = gManagerWindow.document.getElementById("search-list"); |
michael@0 | 61 | var link = gManagerWindow.document.getElementById("search-allresults-link"); |
michael@0 | 62 | is(link.parentNode, list.lastChild, "Footer should be at the end of the richlistbox"); |
michael@0 | 63 | if (aShouldShow) { |
michael@0 | 64 | is_element_visible(link, "All Results link should be visible"); |
michael@0 | 65 | is(link.value, "See all " + SEARCH_EXPECTED_TOTAL + " results", "All Results link should show the correct message"); |
michael@0 | 66 | var scope = {}; |
michael@0 | 67 | Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm", scope); |
michael@0 | 68 | is(link.href, scope.AddonRepository.getSearchURL(SEARCH_QUERY), "All Results link should have the correct href"); |
michael@0 | 69 | } else { |
michael@0 | 70 | is_element_hidden(link, "All Results link should be hidden"); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | add_test(function() { |
michael@0 | 75 | info("Searching locally"); |
michael@0 | 76 | search(false, function() { |
michael@0 | 77 | check_allresultslink(false); |
michael@0 | 78 | restart_manager(gManagerWindow, null, function(aManager) { |
michael@0 | 79 | gManagerWindow = aManager; |
michael@0 | 80 | run_next_test(); |
michael@0 | 81 | }); |
michael@0 | 82 | }); |
michael@0 | 83 | }); |
michael@0 | 84 | |
michael@0 | 85 | add_test(function() { |
michael@0 | 86 | info("Searching remotely - more results than cap"); |
michael@0 | 87 | Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3); |
michael@0 | 88 | search(true, function() { |
michael@0 | 89 | check_allresultslink(true); |
michael@0 | 90 | restart_manager(gManagerWindow, null, function(aManager) { |
michael@0 | 91 | gManagerWindow = aManager; |
michael@0 | 92 | run_next_test(); |
michael@0 | 93 | }); |
michael@0 | 94 | }); |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | add_test(function() { |
michael@0 | 98 | info("Searching remotely - less results than cap"); |
michael@0 | 99 | Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 200); |
michael@0 | 100 | search(true, function() { |
michael@0 | 101 | check_allresultslink(false); |
michael@0 | 102 | restart_manager(gManagerWindow, null, function(aManager) { |
michael@0 | 103 | gManagerWindow = aManager; |
michael@0 | 104 | run_next_test(); |
michael@0 | 105 | }); |
michael@0 | 106 | }); |
michael@0 | 107 | }); |
michael@0 | 108 | |
michael@0 | 109 | add_test(function() { |
michael@0 | 110 | info("Searching remotely - more results than cap"); |
michael@0 | 111 | Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3); |
michael@0 | 112 | search(true, function() { |
michael@0 | 113 | check_allresultslink(true); |
michael@0 | 114 | run_next_test(); |
michael@0 | 115 | }); |
michael@0 | 116 | }); |
michael@0 | 117 | |
michael@0 | 118 | add_test(function() { |
michael@0 | 119 | info("Switching views"); |
michael@0 | 120 | gManagerWindow.loadView("addons://list/extension"); |
michael@0 | 121 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 122 | info("Re-loading previous search"); |
michael@0 | 123 | search(true, function() { |
michael@0 | 124 | check_allresultslink(true); |
michael@0 | 125 | run_next_test(); |
michael@0 | 126 | }); |
michael@0 | 127 | }); |
michael@0 | 128 | }); |