summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/browser/browser_bug581076.js
blob: b02a6cc3e8ad5c837ecff921dc919590a3516b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* 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";

const SEARCHABLE_PAGE = "addons://list/extension";

var gManagerWindow;


function test() {
  Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL);
  Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);

  waitForExplicitFinish();

  open_manager(SEARCHABLE_PAGE, function(aWindow) {
    gManagerWindow = aWindow;
    run_next_test();
  });
}

function end_test() {
  // Test generates a lot of available installs so just cancel them all
  AddonManager.getAllInstalls(function(aInstalls) {
    for (let install of aInstalls)
      install.cancel();

    close_manager(gManagerWindow, finish);
  });
}

function search(aRemoteSearch, aCallback) {
  waitForFocus(function() {
    var searchBox = gManagerWindow.document.getElementById("header-search");
    searchBox.value = SEARCH_QUERY;

    EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
    EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);

    wait_for_view_load(gManagerWindow, function() {
      let filter;
      if (aRemoteSearch)
        filter = gManagerWindow.document.getElementById("search-filter-remote");
      else
        filter = gManagerWindow.document.getElementById("search-filter-local");
      EventUtils.synthesizeMouseAtCenter(filter, { }, gManagerWindow);

      executeSoon(aCallback);
    });
  }, gManagerWindow);
}

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/addons/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, SEARCHABLE_PAGE, function(aManager) {
      gManagerWindow = aManager;
      run_next_test();
    });
  });
});

add_test(function() {
    debugger;
  info("Searching remotely - more results than cap");
  Services.prefs.setIntPref(PREF_GETADDONS_MAXRESULTS, 3);
  search(true, function() {
    check_allresultslink(true);
    restart_manager(gManagerWindow, SEARCHABLE_PAGE, 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, SEARCHABLE_PAGE, 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();
    });
  });
});