1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,624 @@ 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 +// Tests AddonRepository.jsm 1.9 + 1.10 +Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); 1.11 + 1.12 +Components.utils.import("resource://testing-common/httpd.js"); 1.13 +var gServer = new HttpServer(); 1.14 +gServer.start(-1); 1.15 + 1.16 +const PREF_GETADDONS_BROWSEADDONS = "extensions.getAddons.browseAddons"; 1.17 +const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL"; 1.18 +const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url"; 1.19 +const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL"; 1.20 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.21 + 1.22 +const PORT = gServer.identity.primaryPort; 1.23 +const BASE_URL = "http://localhost:" + PORT; 1.24 +const DEFAULT_URL = "about:blank"; 1.25 + 1.26 +gPort = PORT; 1.27 + 1.28 +// Path to source URI of installed add-on 1.29 +const INSTALL_URL1 = "/addons/test_AddonRepository_1.xpi"; 1.30 +// Path to source URI of installing add-on 1.31 +const INSTALL_URL2 = "/addons/test_AddonRepository_2.xpi"; 1.32 +// Path to source URI of non-active add-on (state = STATE_AVAILABLE) 1.33 +const INSTALL_URL3 = "/addons/test_AddonRepository_3.xpi"; 1.34 + 1.35 +// Properties of an individual add-on that should be checked 1.36 +// Note: name is checked separately 1.37 +var ADDON_PROPERTIES = ["id", "type", "version", "creator", "developers", 1.38 + "description", "fullDescription", "developerComments", 1.39 + "eula", "iconURL", "icons", "screenshots", "homepageURL", 1.40 + "supportURL", "contributionURL", "contributionAmount", 1.41 + "averageRating", "reviewCount", "reviewURL", 1.42 + "totalDownloads", "weeklyDownloads", "dailyUsers", 1.43 + "sourceURI", "repositoryStatus", "size", "updateDate", 1.44 + "purchaseURL", "purchaseAmount", "purchaseDisplayAmount", 1.45 + "compatibilityOverrides"]; 1.46 + 1.47 +// Results of getAddonsByIDs 1.48 +var GET_RESULTS = [{ 1.49 + id: "test1@tests.mozilla.org", 1.50 + type: "extension", 1.51 + version: "1.1", 1.52 + creator: { 1.53 + name: "Test Creator 1", 1.54 + url: BASE_URL + "/creator1.html" 1.55 + }, 1.56 + developers: [{ 1.57 + name: "Test Developer 1", 1.58 + url: BASE_URL + "/developer1.html" 1.59 + }], 1.60 + description: "Test Summary 1", 1.61 + fullDescription: "Test Description 1", 1.62 + developerComments: "Test Developer Comments 1", 1.63 + eula: "Test EULA 1", 1.64 + iconURL: BASE_URL + "/icon1.png", 1.65 + icons: { "32": BASE_URL + "/icon1.png" }, 1.66 + screenshots: [{ 1.67 + url: BASE_URL + "/full1-1.png", 1.68 + width: 400, 1.69 + height: 300, 1.70 + thumbnailURL: BASE_URL + "/thumbnail1-1.png", 1.71 + thumbnailWidth: 200, 1.72 + thumbnailHeight: 150, 1.73 + caption: "Caption 1 - 1" 1.74 + }, { 1.75 + url: BASE_URL + "/full2-1.png", 1.76 + thumbnailURL: BASE_URL + "/thumbnail2-1.png", 1.77 + caption: "Caption 2 - 1" 1.78 + }], 1.79 + homepageURL: BASE_URL + "/learnmore1.html", 1.80 + learnmoreURL: BASE_URL + "/learnmore1.html", 1.81 + supportURL: BASE_URL + "/support1.html", 1.82 + contributionURL: BASE_URL + "/meetDevelopers1.html", 1.83 + contributionAmount: "$11.11", 1.84 + averageRating: 4, 1.85 + reviewCount: 1111, 1.86 + reviewURL: BASE_URL + "/review1.html", 1.87 + totalDownloads: 2222, 1.88 + weeklyDownloads: 3333, 1.89 + dailyUsers: 4444, 1.90 + sourceURI: BASE_URL + INSTALL_URL2, 1.91 + repositoryStatus: 8, 1.92 + size: 5555, 1.93 + updateDate: new Date(1265033045000), 1.94 + compatibilityOverrides: [{ 1.95 + type: "incompatible", 1.96 + minVersion: 0.1, 1.97 + maxVersion: 0.2, 1.98 + appID: "xpcshell@tests.mozilla.org", 1.99 + appMinVersion: 3.0, 1.100 + appMaxVersion: 4.0 1.101 + }, { 1.102 + type: "incompatible", 1.103 + minVersion: 0.2, 1.104 + maxVersion: 0.3, 1.105 + appID: "xpcshell@tests.mozilla.org", 1.106 + appMinVersion: 5.0, 1.107 + appMaxVersion: 6.0 1.108 + }] 1.109 +}, { 1.110 + id: "test_AddonRepository_1@tests.mozilla.org", 1.111 + version: "1.4", 1.112 + repositoryStatus: 9999, 1.113 + icons: {} 1.114 +}]; 1.115 + 1.116 +// Results of retrieveRecommendedAddons and searchAddons 1.117 +var SEARCH_RESULTS = [{ 1.118 + id: "test1@tests.mozilla.org", 1.119 + type: "extension", 1.120 + version: "1.1", 1.121 + creator: { 1.122 + name: "Test Creator 1", 1.123 + url: BASE_URL + "/creator1.html" 1.124 + }, 1.125 + repositoryStatus: 8, 1.126 + sourceURI: BASE_URL + "/test1.xpi", 1.127 + icons: {} 1.128 +}, { 1.129 + id: "test2@tests.mozilla.org", 1.130 + type: "extension", 1.131 + version: "1.2", 1.132 + creator: { 1.133 + name: "Test Creator 2", 1.134 + url: BASE_URL + "/creator2.html" 1.135 + }, 1.136 + developers: [{ 1.137 + name: "Test Developer 2", 1.138 + url: BASE_URL + "/developer2.html" 1.139 + }], 1.140 + description: "Test Summary 2\n\nparagraph", 1.141 + fullDescription: "Test Description 2\nnewline", 1.142 + developerComments: "Test Developer\nComments 2", 1.143 + eula: "Test EULA 2", 1.144 + iconURL: BASE_URL + "/icon2-32.png", 1.145 + icons: { 1.146 + "32": BASE_URL + "/icon2-32.png", 1.147 + "48": BASE_URL + "/icon2-48.png", 1.148 + "64": BASE_URL + "/icon2-64.png" 1.149 + }, 1.150 + screenshots: [{ 1.151 + url: BASE_URL + "/full1-2.png", 1.152 + thumbnailURL: BASE_URL + "/thumbnail1-2.png" 1.153 + }, { 1.154 + url: BASE_URL + "/full2-2.png", 1.155 + thumbnailURL: BASE_URL + "/thumbnail2-2.png", 1.156 + caption: "Caption 2" 1.157 + }], 1.158 + homepageURL: BASE_URL + "/learnmore2.html", 1.159 + supportURL: BASE_URL + "/support2.html", 1.160 + learnmoreURL: BASE_URL + "/learnmore2.html", 1.161 + contributionURL: BASE_URL + "/meetDevelopers2.html", 1.162 + contributionAmount: null, 1.163 + repositoryStatus: 4, 1.164 + sourceURI: BASE_URL + "/test2.xpi" 1.165 +}, { 1.166 + id: "test3@tests.mozilla.org", 1.167 + type: "theme", 1.168 + version: "1.3", 1.169 + creator: { 1.170 + name: "Test Creator 3", 1.171 + url: BASE_URL + "/creator3.html" 1.172 + }, 1.173 + developers: [{ 1.174 + name: "First Test Developer 3", 1.175 + url: BASE_URL + "/developer1-3.html" 1.176 + }, { 1.177 + name: "Second Test Developer 3", 1.178 + url: BASE_URL + "/developer2-3.html" 1.179 + }], 1.180 + description: "Test Summary 3", 1.181 + fullDescription: "Test Description 3\n\n List item 1\n List item 2", 1.182 + developerComments: "Test Developer Comments 3", 1.183 + eula: "Test EULA 3", 1.184 + iconURL: BASE_URL + "/icon3.png", 1.185 + icons: { "32": BASE_URL + "/icon3.png" }, 1.186 + screenshots: [{ 1.187 + url: BASE_URL + "/full1-3.png", 1.188 + thumbnailURL: BASE_URL + "/thumbnail1-3.png", 1.189 + caption: "Caption 1 - 3" 1.190 + }, { 1.191 + url: BASE_URL + "/full2-3.png", 1.192 + caption: "Caption 2 - 3" 1.193 + }, { 1.194 + url: BASE_URL + "/full3-3.png", 1.195 + thumbnailURL: BASE_URL + "/thumbnail3-3.png", 1.196 + caption: "Caption 3 - 3" 1.197 + }], 1.198 + homepageURL: BASE_URL + "/homepage3.html", 1.199 + supportURL: BASE_URL + "/support3.html", 1.200 + learnmoreURL: BASE_URL + "/learnmore3.html", 1.201 + contributionURL: BASE_URL + "/meetDevelopers3.html", 1.202 + contributionAmount: "$11.11", 1.203 + averageRating: 2, 1.204 + reviewCount: 1111, 1.205 + reviewURL: BASE_URL + "/review3.html", 1.206 + totalDownloads: 2222, 1.207 + weeklyDownloads: 3333, 1.208 + dailyUsers: 4444, 1.209 + sourceURI: BASE_URL + "/test3.xpi", 1.210 + repositoryStatus: 8, 1.211 + size: 5555, 1.212 + updateDate: new Date(1265033045000), 1.213 + 1.214 +}, { 1.215 + id: "purchase1@tests.mozilla.org", 1.216 + type: "extension", 1.217 + version: "2.0", 1.218 + creator: { 1.219 + name: "Test Creator - Last Passing", 1.220 + url: BASE_URL + "/creatorLastPassing.html" 1.221 + }, 1.222 + averageRating: 5, 1.223 + repositoryStatus: 4, 1.224 + purchaseURL: "http://localhost:" + PORT + "/purchaseURL1", 1.225 + purchaseAmount: 5, 1.226 + purchaseDisplayAmount: "$5", 1.227 + icons: {} 1.228 +}, { 1.229 + id: "purchase2@tests.mozilla.org", 1.230 + type: "extension", 1.231 + version: "2.0", 1.232 + creator: { 1.233 + name: "Test Creator - Last Passing", 1.234 + url: BASE_URL + "/creatorLastPassing.html" 1.235 + }, 1.236 + averageRating: 5, 1.237 + repositoryStatus: 4, 1.238 + purchaseURL: "http://localhost:" + PORT + "/purchaseURL2", 1.239 + purchaseAmount: 10, 1.240 + purchaseDisplayAmount: "$10", 1.241 + icons: {} 1.242 +}, { 1.243 + id: "test-lastPassing@tests.mozilla.org", 1.244 + type: "extension", 1.245 + version: "2.0", 1.246 + creator: { 1.247 + name: "Test Creator - Last Passing", 1.248 + url: BASE_URL + "/creatorLastPassing.html" 1.249 + }, 1.250 + averageRating: 5, 1.251 + repositoryStatus: 4, 1.252 + sourceURI: BASE_URL + "/addons/test_AddonRepository_3.xpi", 1.253 + icons: {} 1.254 +}]; 1.255 + 1.256 +const TOTAL_RESULTS = 1111; 1.257 +const MAX_RESULTS = SEARCH_RESULTS.length; 1.258 + 1.259 +// Used to differentiate between testing that a search success 1.260 +// or a search failure for retrieveRecommendedAddons and searchAddons 1.261 +const FAILED_MAX_RESULTS = 9999; 1.262 + 1.263 +// Values for testing AddonRepository.getAddonsByIDs() 1.264 +var GET_TEST = { 1.265 + preference: PREF_GETADDONS_BYIDS, 1.266 + preferenceValue: BASE_URL + "/%OS%/%VERSION%/%API_VERSION%/" + 1.267 + "%API_VERSION%/%IDS%", 1.268 + failedIDs: ["test1@tests.mozilla.org"], 1.269 + failedURL: "/XPCShell/1/1.5/1.5/test1%40tests.mozilla.org", 1.270 + successfulIDs: ["test1@tests.mozilla.org", 1.271 + "{00000000-1111-2222-3333-444444444444}", 1.272 + "test_AddonRepository_1@tests.mozilla.org"], 1.273 + successfulURL: "/XPCShell/1/1.5/1.5/test1%40tests.mozilla.org," + 1.274 + "%7B00000000-1111-2222-3333-444444444444%7D," + 1.275 + "test_AddonRepository_1%40tests.mozilla.org" 1.276 +}; 1.277 + 1.278 +// Values for testing AddonRepository.retrieveRecommendedAddons() 1.279 +var RECOMMENDED_TEST = { 1.280 + preference: PREF_GETADDONS_GETRECOMMENDED, 1.281 + preferenceValue: BASE_URL + "/%OS%/%VERSION%/%API_VERSION%/" + 1.282 + "%API_VERSION%/%MAX_RESULTS%", 1.283 + failedURL: "/XPCShell/1/1.5/1.5/" + (2 * FAILED_MAX_RESULTS), 1.284 + successfulURL: "/XPCShell/1/1.5/1.5/" + (2 * MAX_RESULTS) 1.285 +}; 1.286 + 1.287 +// Values for testing AddonRepository.searchAddons() 1.288 +var SEARCH_TEST = { 1.289 + searchTerms: "odd=search:with&weird\"characters", 1.290 + preference: PREF_GETADDONS_GETSEARCHRESULTS, 1.291 + preferenceValue: BASE_URL + "/%OS%/%VERSION%/%API_VERSION%/" + 1.292 + "%API_VERSION%/%MAX_RESULTS%/%TERMS%", 1.293 + failedURL: "/XPCShell/1/1.5/1.5/" + (2 * FAILED_MAX_RESULTS) + 1.294 + "/odd%3Dsearch%3Awith%26weird%22characters", 1.295 + successfulURL: "/XPCShell/1/1.5/1.5/" + (2 * MAX_RESULTS) + 1.296 + "/odd%3Dsearch%3Awith%26weird%22characters" 1.297 +}; 1.298 + 1.299 +// Test that actual results and expected results are equal 1.300 +function check_results(aActualAddons, aExpectedAddons, aAddonCount, aInstallNull) { 1.301 + do_check_false(AddonRepository.isSearching); 1.302 + 1.303 + do_check_eq(aActualAddons.length, aAddonCount); 1.304 + do_check_addons(aActualAddons, aExpectedAddons, ADDON_PROPERTIES); 1.305 + 1.306 + // Additional tests 1.307 + aActualAddons.forEach(function check_each_addon(aActualAddon) { 1.308 + // Separately check name so better messages are output when test fails 1.309 + if (aActualAddon.name == "FAIL") 1.310 + do_throw(aActualAddon.id + " - " + aActualAddon.description); 1.311 + if (aActualAddon.name != "PASS") 1.312 + do_throw(aActualAddon.id + " - " + "invalid add-on name " + aActualAddon.name); 1.313 + 1.314 + do_check_eq(aActualAddon.install == null, !!aInstallNull || !aActualAddon.sourceURI); 1.315 + 1.316 + // Check that sourceURI property consistent within actual addon 1.317 + if (aActualAddon.install) 1.318 + do_check_eq(aActualAddon.install.sourceURI.spec, aActualAddon.sourceURI.spec); 1.319 + }); 1.320 +} 1.321 + 1.322 +// Complete a search, also testing cancelSearch() and isSearching 1.323 +function complete_search(aSearch, aSearchCallback) { 1.324 + var failCallback = { 1.325 + searchSucceeded: function(addons, length, total) { 1.326 + do_throw("failCallback.searchSucceeded should not be called"); 1.327 + end_test(); 1.328 + }, 1.329 + 1.330 + searchFailed: function() { 1.331 + do_throw("failCallback.searchFailed should not be called"); 1.332 + end_test(); 1.333 + } 1.334 + }; 1.335 + 1.336 + var callbackCalled = false; 1.337 + var testCallback = { 1.338 + searchSucceeded: function(addons, length, total) { 1.339 + do_throw("testCallback.searchSucceeded should not be called"); 1.340 + end_test(); 1.341 + }, 1.342 + 1.343 + searchFailed: function() { 1.344 + callbackCalled = true; 1.345 + } 1.346 + }; 1.347 + 1.348 + // Should fail because cancelled it immediately 1.349 + aSearch(failCallback); 1.350 + do_check_true(AddonRepository.isSearching); 1.351 + AddonRepository.cancelSearch(); 1.352 + do_check_false(AddonRepository.isSearching); 1.353 + 1.354 + aSearch(aSearchCallback); 1.355 + do_check_true(AddonRepository.isSearching); 1.356 + 1.357 + // searchFailed should be called immediately because already searching 1.358 + aSearch(testCallback); 1.359 + do_check_true(callbackCalled); 1.360 + do_check_true(AddonRepository.isSearching); 1.361 +} 1.362 + 1.363 + 1.364 +function run_test() { 1.365 + // Setup for test 1.366 + do_test_pending(); 1.367 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); 1.368 + 1.369 + startupManager(); 1.370 + 1.371 + // Install an add-on so can check that it isn't returned in the results 1.372 + installAllFiles([do_get_addon("test_AddonRepository_1")], function addon_1_install_callback() { 1.373 + restartManager(); 1.374 + 1.375 + // Register other add-on XPI files 1.376 + gServer.registerFile(INSTALL_URL2, 1.377 + do_get_addon("test_AddonRepository_2")); 1.378 + gServer.registerFile(INSTALL_URL3, 1.379 + do_get_addon("test_AddonRepository_3")); 1.380 + 1.381 + // Register files used to test search failure 1.382 + mapUrlToFile(GET_TEST.failedURL, 1.383 + do_get_file("data/test_AddonRepository_failed.xml"), 1.384 + gServer); 1.385 + mapUrlToFile(RECOMMENDED_TEST.failedURL, 1.386 + do_get_file("data/test_AddonRepository_failed.xml"), 1.387 + gServer); 1.388 + mapUrlToFile(SEARCH_TEST.failedURL, 1.389 + do_get_file("data/test_AddonRepository_failed.xml"), 1.390 + gServer); 1.391 + 1.392 + // Register files used to test search success 1.393 + mapUrlToFile(GET_TEST.successfulURL, 1.394 + do_get_file("data/test_AddonRepository_getAddonsByIDs.xml"), 1.395 + gServer); 1.396 + mapUrlToFile(RECOMMENDED_TEST.successfulURL, 1.397 + do_get_file("data/test_AddonRepository.xml"), 1.398 + gServer); 1.399 + mapUrlToFile(SEARCH_TEST.successfulURL, 1.400 + do_get_file("data/test_AddonRepository.xml"), 1.401 + gServer); 1.402 + 1.403 + // Create an active AddonInstall so can check that it isn't returned in the results 1.404 + AddonManager.getInstallForURL(BASE_URL + INSTALL_URL2, function addon_2_get(aInstall) { 1.405 + try { 1.406 + aInstall.install(); 1.407 + } 1.408 + catch(e) { 1.409 + do_print("Failed to install add-on " + aInstall.sourceURI.spec); 1.410 + do_report_unexpected_exception(e); 1.411 + } 1.412 + 1.413 + // Create a non-active AddonInstall so can check that it is returned in the results 1.414 + AddonManager.getInstallForURL(BASE_URL + INSTALL_URL3, 1.415 + run_test_1, "application/x-xpinstall"); 1.416 + }, "application/x-xpinstall"); 1.417 + }); 1.418 +} 1.419 + 1.420 +function end_test() { 1.421 + let testDir = gProfD.clone(); 1.422 + testDir.append("extensions"); 1.423 + testDir.append("staged"); 1.424 + gServer.stop(function() { 1.425 + function loop() { 1.426 + if (!testDir.exists()) { 1.427 + do_print("Staged directory has been cleaned up"); 1.428 + do_test_finished(); 1.429 + } 1.430 + do_print("Waiting 1 second until cleanup is complete"); 1.431 + do_timeout(1000, loop); 1.432 + } 1.433 + loop(); 1.434 + }); 1.435 +} 1.436 + 1.437 +// Tests homepageURL, getRecommendedURL() and getSearchURL() 1.438 +function run_test_1() { 1.439 + function check_urls(aPreference, aGetURL, aTests) { 1.440 + aTests.forEach(function(aTest) { 1.441 + Services.prefs.setCharPref(aPreference, aTest.preferenceValue); 1.442 + do_check_eq(aGetURL(aTest), aTest.expectedURL); 1.443 + }); 1.444 + } 1.445 + 1.446 + var urlTests = [{ 1.447 + preferenceValue: BASE_URL, 1.448 + expectedURL: BASE_URL 1.449 + }, { 1.450 + preferenceValue: BASE_URL + "/%OS%/%VERSION%", 1.451 + expectedURL: BASE_URL + "/XPCShell/1" 1.452 + }]; 1.453 + 1.454 + // Extra tests for AddonRepository.getSearchURL(); 1.455 + var searchURLTests = [{ 1.456 + searchTerms: "test", 1.457 + preferenceValue: BASE_URL + "/search?q=%TERMS%", 1.458 + expectedURL: BASE_URL + "/search?q=test" 1.459 + }, { 1.460 + searchTerms: "test search", 1.461 + preferenceValue: BASE_URL + "/%TERMS%", 1.462 + expectedURL: BASE_URL + "/test%20search" 1.463 + }, { 1.464 + searchTerms: "odd=search:with&weird\"characters", 1.465 + preferenceValue: BASE_URL + "/%TERMS%", 1.466 + expectedURL: BASE_URL + "/odd%3Dsearch%3Awith%26weird%22characters" 1.467 + }]; 1.468 + 1.469 + // Setup tests for homepageURL, getRecommendedURL() and getSearchURL() 1.470 + var tests = [{ 1.471 + initiallyUndefined: true, 1.472 + preference: PREF_GETADDONS_BROWSEADDONS, 1.473 + urlTests: urlTests, 1.474 + getURL: function() AddonRepository.homepageURL 1.475 + }, { 1.476 + initiallyUndefined: true, 1.477 + preference: PREF_GETADDONS_BROWSERECOMMENDED, 1.478 + urlTests: urlTests, 1.479 + getURL: function() AddonRepository.getRecommendedURL() 1.480 + }, { 1.481 + initiallyUndefined: false, 1.482 + preference: PREF_GETADDONS_BROWSESEARCHRESULTS, 1.483 + urlTests: urlTests.concat(searchURLTests), 1.484 + getURL: function getSearchURL(aTest) { 1.485 + var searchTerms = aTest && aTest.searchTerms ? aTest.searchTerms 1.486 + : "unused terms"; 1.487 + return AddonRepository.getSearchURL(searchTerms); 1.488 + } 1.489 + }]; 1.490 + 1.491 + tests.forEach(function url_test(aTest) { 1.492 + if (aTest.initiallyUndefined) { 1.493 + // Preference is not defined by default 1.494 + do_check_eq(Services.prefs.getPrefType(aTest.preference), 1.495 + Services.prefs.PREF_INVALID); 1.496 + do_check_eq(aTest.getURL(), DEFAULT_URL); 1.497 + } 1.498 + 1.499 + check_urls(aTest.preference, aTest.getURL, aTest.urlTests); 1.500 + }); 1.501 + 1.502 + run_test_getAddonsByID_fails(); 1.503 +} 1.504 + 1.505 +// Tests failure of AddonRepository.getAddonsByIDs() 1.506 +function run_test_getAddonsByID_fails() { 1.507 + Services.prefs.setCharPref(GET_TEST.preference, GET_TEST.preferenceValue); 1.508 + var callback = { 1.509 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.510 + do_throw("searchAddons should not have succeeded"); 1.511 + end_test(); 1.512 + }, 1.513 + 1.514 + searchFailed: function() { 1.515 + do_check_false(AddonRepository.isSearching); 1.516 + run_test_getAddonsByID_succeeds(); 1.517 + } 1.518 + }; 1.519 + 1.520 + complete_search(function complete_search_fail_callback(aCallback) { 1.521 + AddonRepository.getAddonsByIDs(GET_TEST.failedIDs, aCallback); 1.522 + }, callback); 1.523 +} 1.524 + 1.525 +// Tests success of AddonRepository.getAddonsByIDs() 1.526 +function run_test_getAddonsByID_succeeds() { 1.527 + var callback = { 1.528 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.529 + do_check_eq(aTotalResults, -1); 1.530 + check_results(aAddonsList, GET_RESULTS, aAddonCount, true); 1.531 + run_test_retrieveRecommended_fails(); 1.532 + }, 1.533 + 1.534 + searchFailed: function() { 1.535 + do_throw("searchAddons should not have failed"); 1.536 + end_test(); 1.537 + } 1.538 + }; 1.539 + 1.540 + complete_search(function complete_search_succeed_callback(aCallback) { 1.541 + AddonRepository.getAddonsByIDs(GET_TEST.successfulIDs, aCallback); 1.542 + }, callback); 1.543 +} 1.544 + 1.545 +// Tests failure of AddonRepository.retrieveRecommendedAddons() 1.546 +function run_test_retrieveRecommended_fails() { 1.547 + Services.prefs.setCharPref(RECOMMENDED_TEST.preference, 1.548 + RECOMMENDED_TEST.preferenceValue); 1.549 + var callback = { 1.550 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.551 + do_throw("retrieveRecommendedAddons should not have succeeded"); 1.552 + end_test(); 1.553 + }, 1.554 + 1.555 + searchFailed: function() { 1.556 + do_check_false(AddonRepository.isSearching); 1.557 + run_test_retrieveRecommended_succeed(); 1.558 + } 1.559 + }; 1.560 + 1.561 + complete_search(function retrieveRecommended_failing_callback(aCallback) { 1.562 + AddonRepository.retrieveRecommendedAddons(FAILED_MAX_RESULTS, aCallback); 1.563 + }, callback); 1.564 +} 1.565 + 1.566 +// Tests success of AddonRepository.retrieveRecommendedAddons() 1.567 +function run_test_retrieveRecommended_succeed() { 1.568 + var callback = { 1.569 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.570 + do_check_eq(aTotalResults, -1); 1.571 + check_results(aAddonsList, SEARCH_RESULTS, aAddonCount); 1.572 + run_test_searchAddons_fails(); 1.573 + }, 1.574 + 1.575 + searchFailed: function() { 1.576 + do_throw("retrieveRecommendedAddons should not have failed"); 1.577 + end_test(); 1.578 + } 1.579 + }; 1.580 + 1.581 + complete_search(function retrieveRecommended_succeed_callback(aCallback) { 1.582 + AddonRepository.retrieveRecommendedAddons(MAX_RESULTS, aCallback); 1.583 + }, callback); 1.584 +} 1.585 + 1.586 +// Tests failure of AddonRepository.searchAddons() 1.587 +function run_test_searchAddons_fails() { 1.588 + Services.prefs.setCharPref(SEARCH_TEST.preference, SEARCH_TEST.preferenceValue); 1.589 + var callback = { 1.590 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.591 + do_throw("searchAddons should not have succeeded"); 1.592 + end_test(); 1.593 + }, 1.594 + 1.595 + searchFailed: function() { 1.596 + do_check_false(AddonRepository.isSearching); 1.597 + run_test_searchAddons_succeeds(); 1.598 + } 1.599 + }; 1.600 + 1.601 + complete_search(function(aCallback) { 1.602 + var searchTerms = SEARCH_TEST.searchTerms; 1.603 + AddonRepository.searchAddons(searchTerms, FAILED_MAX_RESULTS, aCallback); 1.604 + }, callback); 1.605 +} 1.606 + 1.607 +// Tests success of AddonRepository.searchAddons() 1.608 +function run_test_searchAddons_succeeds() { 1.609 + var callback = { 1.610 + searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) { 1.611 + do_check_eq(aTotalResults, TOTAL_RESULTS); 1.612 + check_results(aAddonsList, SEARCH_RESULTS, aAddonCount); 1.613 + end_test(); 1.614 + }, 1.615 + 1.616 + searchFailed: function() { 1.617 + do_throw("searchAddons should not have failed"); 1.618 + end_test(); 1.619 + } 1.620 + }; 1.621 + 1.622 + complete_search(function(aCallback) { 1.623 + var searchTerms = SEARCH_TEST.searchTerms; 1.624 + AddonRepository.searchAddons(searchTerms, MAX_RESULTS, aCallback); 1.625 + }, callback); 1.626 +} 1.627 +