|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that if the AMO response provides total_results, |
|
6 // searchSucceeded is called with the correct number of total results |
|
7 |
|
8 Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); |
|
9 |
|
10 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
|
11 |
|
12 Components.utils.import("resource://testing-common/httpd.js"); |
|
13 var server; |
|
14 |
|
15 var TESTS = [ |
|
16 { |
|
17 query: "bug554133", |
|
18 maxResults: 2, |
|
19 length: 2, |
|
20 total: 100 |
|
21 }, |
|
22 { |
|
23 query: "bug554133", |
|
24 maxResults: 10, |
|
25 length: 10, |
|
26 total: 100 |
|
27 }, |
|
28 { |
|
29 query: "bug554133", |
|
30 maxResults: 100, |
|
31 length: 10, |
|
32 total: 100 |
|
33 } |
|
34 ]; |
|
35 |
|
36 var gCurrentTest = 0; |
|
37 var SearchCallback = { |
|
38 searchSucceeded: function(addons, length, total) { |
|
39 do_check_false(AddonRepository.isSearching); |
|
40 do_check_eq(addons.length, length); |
|
41 do_check_eq(length, TESTS[gCurrentTest].length); |
|
42 do_check_eq(total, TESTS[gCurrentTest].total); |
|
43 |
|
44 gCurrentTest++; |
|
45 run_current_test(); |
|
46 }, |
|
47 |
|
48 searchFailed: function() { |
|
49 server.stop(do_test_finished); |
|
50 do_throw("Search results failed"); |
|
51 } |
|
52 }; |
|
53 |
|
54 function run_current_test() { |
|
55 if (gCurrentTest < TESTS.length) { |
|
56 var query = TESTS[gCurrentTest].query; |
|
57 var maxResults = TESTS[gCurrentTest].maxResults; |
|
58 AddonRepository.searchAddons(query, maxResults, SearchCallback); |
|
59 } |
|
60 else |
|
61 server.stop(do_test_finished); |
|
62 } |
|
63 |
|
64 function run_test() |
|
65 { |
|
66 // Setup for test |
|
67 do_test_pending(); |
|
68 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
|
69 |
|
70 startupManager(); |
|
71 |
|
72 server = new HttpServer(); |
|
73 server.registerDirectory("/", do_get_file("data")); |
|
74 mapFile("/data/test_bug554133.xml", server); |
|
75 server.start(-1); |
|
76 gPort = server.identity.primaryPort; |
|
77 |
|
78 // Point search to the test server |
|
79 Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, |
|
80 "http://localhost:" + gPort + "/data/test_%TERMS%.xml"); |
|
81 |
|
82 do_check_neq(AddonRepository, null); |
|
83 gCurrentTest = 0; |
|
84 run_current_test(); |
|
85 } |
|
86 |