toolkit/mozapps/extensions/test/xpcshell/test_bug554133.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.

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

mercurial