michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This verifies that if the AMO response provides total_results, michael@0: // searchSucceeded is called with the correct number of total results michael@0: michael@0: Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var server; michael@0: michael@0: var TESTS = [ michael@0: { michael@0: query: "bug554133", michael@0: maxResults: 2, michael@0: length: 2, michael@0: total: 100 michael@0: }, michael@0: { michael@0: query: "bug554133", michael@0: maxResults: 10, michael@0: length: 10, michael@0: total: 100 michael@0: }, michael@0: { michael@0: query: "bug554133", michael@0: maxResults: 100, michael@0: length: 10, michael@0: total: 100 michael@0: } michael@0: ]; michael@0: michael@0: var gCurrentTest = 0; michael@0: var SearchCallback = { michael@0: searchSucceeded: function(addons, length, total) { michael@0: do_check_false(AddonRepository.isSearching); michael@0: do_check_eq(addons.length, length); michael@0: do_check_eq(length, TESTS[gCurrentTest].length); michael@0: do_check_eq(total, TESTS[gCurrentTest].total); michael@0: michael@0: gCurrentTest++; michael@0: run_current_test(); michael@0: }, michael@0: michael@0: searchFailed: function() { michael@0: server.stop(do_test_finished); michael@0: do_throw("Search results failed"); michael@0: } michael@0: }; michael@0: michael@0: function run_current_test() { michael@0: if (gCurrentTest < TESTS.length) { michael@0: var query = TESTS[gCurrentTest].query; michael@0: var maxResults = TESTS[gCurrentTest].maxResults; michael@0: AddonRepository.searchAddons(query, maxResults, SearchCallback); michael@0: } michael@0: else michael@0: server.stop(do_test_finished); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: // Setup for test michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: michael@0: startupManager(); michael@0: michael@0: server = new HttpServer(); michael@0: server.registerDirectory("/", do_get_file("data")); michael@0: mapFile("/data/test_bug554133.xml", server); michael@0: server.start(-1); michael@0: gPort = server.identity.primaryPort; michael@0: michael@0: // Point search to the test server michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, michael@0: "http://localhost:" + gPort + "/data/test_%TERMS%.xml"); michael@0: michael@0: do_check_neq(AddonRepository, null); michael@0: gCurrentTest = 0; michael@0: run_current_test(); michael@0: } michael@0: