toolkit/mozapps/extensions/test/browser/browser_bug581076.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial