1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug554133.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 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 +// This verifies that if the AMO response provides total_results, 1.9 +// searchSucceeded is called with the correct number of total results 1.10 + 1.11 +Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); 1.12 + 1.13 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.14 + 1.15 +Components.utils.import("resource://testing-common/httpd.js"); 1.16 +var server; 1.17 + 1.18 +var TESTS = [ 1.19 +{ 1.20 + query: "bug554133", 1.21 + maxResults: 2, 1.22 + length: 2, 1.23 + total: 100 1.24 +}, 1.25 +{ 1.26 + query: "bug554133", 1.27 + maxResults: 10, 1.28 + length: 10, 1.29 + total: 100 1.30 +}, 1.31 +{ 1.32 + query: "bug554133", 1.33 + maxResults: 100, 1.34 + length: 10, 1.35 + total: 100 1.36 +} 1.37 +]; 1.38 + 1.39 +var gCurrentTest = 0; 1.40 +var SearchCallback = { 1.41 + searchSucceeded: function(addons, length, total) { 1.42 + do_check_false(AddonRepository.isSearching); 1.43 + do_check_eq(addons.length, length); 1.44 + do_check_eq(length, TESTS[gCurrentTest].length); 1.45 + do_check_eq(total, TESTS[gCurrentTest].total); 1.46 + 1.47 + gCurrentTest++; 1.48 + run_current_test(); 1.49 + }, 1.50 + 1.51 + searchFailed: function() { 1.52 + server.stop(do_test_finished); 1.53 + do_throw("Search results failed"); 1.54 + } 1.55 +}; 1.56 + 1.57 +function run_current_test() { 1.58 + if (gCurrentTest < TESTS.length) { 1.59 + var query = TESTS[gCurrentTest].query; 1.60 + var maxResults = TESTS[gCurrentTest].maxResults; 1.61 + AddonRepository.searchAddons(query, maxResults, SearchCallback); 1.62 + } 1.63 + else 1.64 + server.stop(do_test_finished); 1.65 +} 1.66 + 1.67 +function run_test() 1.68 +{ 1.69 + // Setup for test 1.70 + do_test_pending(); 1.71 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); 1.72 + 1.73 + startupManager(); 1.74 + 1.75 + server = new HttpServer(); 1.76 + server.registerDirectory("/", do_get_file("data")); 1.77 + mapFile("/data/test_bug554133.xml", server); 1.78 + server.start(-1); 1.79 + gPort = server.identity.primaryPort; 1.80 + 1.81 + // Point search to the test server 1.82 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, 1.83 + "http://localhost:" + gPort + "/data/test_%TERMS%.xml"); 1.84 + 1.85 + do_check_neq(AddonRepository, null); 1.86 + gCurrentTest = 0; 1.87 + run_current_test(); 1.88 +} 1.89 +