Loading toolkit/mozapps/extensions/internal/AddonRepository.jsm +27 −0 Original line number Diff line number Diff line Loading @@ -865,6 +865,33 @@ this.AddonRepository = { return this._repopulateCacheInternal(true); }, /** * Begins a search for recommended add-ons in this repository. Results will * be passed to the given callback. * * @param aMaxResults * The maximum number of results to return * @param aCallback * The callback to pass results to */ retrieveRecommendedAddons(aMaxResults, aCallback) { let url = this._formatURLPref(PREF_GETADDONS_GETRECOMMENDED, { API_VERSION, // Get twice as many results to account for potential filtering MAX_RESULTS: 2 * aMaxResults }); let handleResults = (aElements, aTotalResults) => { this._getLocalAddonIds(aLocalAddonIds => { // aTotalResults irrelevant this._parseAddons(aElements, -1, aLocalAddonIds); }); } this._beginSearch(url, aMaxResults, aCallback, handleResults); }, /** * Begins a search for add-ons in this repository. Results will be passed to * the given callback. Loading toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js +43 −2 Original line number Diff line number Diff line Loading @@ -523,8 +523,7 @@ function run_test_getAddonsByID_succeeds() { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_check_eq(aTotalResults, -1); check_results(aAddonsList, GET_RESULTS, aAddonCount, true); run_test_searchAddons_fails(); //run_test_retrieveRecommended_fails(); run_test_retrieveRecommended_fails(); }, searchFailed() { Loading @@ -538,6 +537,47 @@ function run_test_getAddonsByID_succeeds() { }, callback); } // Tests failure of AddonRepository.retrieveRecommendedAddons() function run_test_retrieveRecommended_fails() { Services.prefs.setCharPref(RECOMMENDED_TEST.preference, RECOMMENDED_TEST.preferenceValue); var callback = { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_throw("retrieveRecommendedAddons should not have succeeded"); end_test(); }, searchFailed() { do_check_false(AddonRepository.isSearching); run_test_retrieveRecommended_succeed(); } }; complete_search(function retrieveRecommended_failing_callback(aCallback) { AddonRepository.retrieveRecommendedAddons(FAILED_MAX_RESULTS, aCallback); }, callback); } // Tests success of AddonRepository.retrieveRecommendedAddons() function run_test_retrieveRecommended_succeed() { var callback = { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_check_eq(aTotalResults, -1); check_results(aAddonsList, SEARCH_RESULTS, aAddonCount); run_test_searchAddons_fails(); }, searchFailed() { do_throw("retrieveRecommendedAddons should not have failed"); end_test(); } }; complete_search(function retrieveRecommended_succeed_callback(aCallback) { AddonRepository.retrieveRecommendedAddons(MAX_RESULTS, aCallback); }, callback); } // Tests failure of AddonRepository.searchAddons() function run_test_searchAddons_fails() { Services.prefs.setCharPref(SEARCH_TEST.preference, SEARCH_TEST.preferenceValue); Loading Loading @@ -579,3 +619,4 @@ function run_test_searchAddons_succeeds() { AddonRepository.searchAddons(searchTerms, MAX_RESULTS, aCallback); }, callback); } toolkit/mozapps/extensions/test/xpcshell/test_bug424262.js 0 → 100644 +61 −0 Original line number Diff line number Diff line /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url"; Components.utils.import("resource://testing-common/httpd.js"); var server; var RESULTS = [ null, null, 0, 2, 4, 5, 5, 5 ]; var RecommendedCallback = { searchSucceeded(addons, length, total) { dump("loaded"); // Search is complete do_check_eq(length, RESULTS.length); for (var i = 0; i < length; i++) { if (addons[i].averageRating != RESULTS[i]) do_throw("Rating for " + addons[i].id + " was " + addons[i].averageRating + ", should have been " + RESULTS[i]); } server.stop(do_test_finished); }, searchFailed() { server.stop(do_test_finished); do_throw("Recommended results failed"); } }; function run_test() { // EM needs to be running. createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); startupManager(); server = new HttpServer(); server.start(-1); gPort = server.identity.primaryPort; mapFile("/data/test_bug424262.xml", server); // Point the addons repository to the test server Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" + gPort + "/data/test_bug424262.xml"); do_check_neq(AddonRepository, null); do_test_pending(); // Pull some results. AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback); } toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini +4 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,9 @@ skip-if = os == "android" # Bug 676992: test consistently hangs on Android skip-if = os == "android" tags = blocklist [test_bug424262.js] # Bug 676992: test consistently hangs on Android skip-if = os == "android" [test_bug425657.js] # Bug 676992: test consistently hangs on Android skip-if = os == "android" Loading Loading @@ -347,3 +350,4 @@ tags = blocklist [test_ext_management.js] skip-if = appname == "thunderbird" tags = webextensions Loading
toolkit/mozapps/extensions/internal/AddonRepository.jsm +27 −0 Original line number Diff line number Diff line Loading @@ -865,6 +865,33 @@ this.AddonRepository = { return this._repopulateCacheInternal(true); }, /** * Begins a search for recommended add-ons in this repository. Results will * be passed to the given callback. * * @param aMaxResults * The maximum number of results to return * @param aCallback * The callback to pass results to */ retrieveRecommendedAddons(aMaxResults, aCallback) { let url = this._formatURLPref(PREF_GETADDONS_GETRECOMMENDED, { API_VERSION, // Get twice as many results to account for potential filtering MAX_RESULTS: 2 * aMaxResults }); let handleResults = (aElements, aTotalResults) => { this._getLocalAddonIds(aLocalAddonIds => { // aTotalResults irrelevant this._parseAddons(aElements, -1, aLocalAddonIds); }); } this._beginSearch(url, aMaxResults, aCallback, handleResults); }, /** * Begins a search for add-ons in this repository. Results will be passed to * the given callback. Loading
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js +43 −2 Original line number Diff line number Diff line Loading @@ -523,8 +523,7 @@ function run_test_getAddonsByID_succeeds() { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_check_eq(aTotalResults, -1); check_results(aAddonsList, GET_RESULTS, aAddonCount, true); run_test_searchAddons_fails(); //run_test_retrieveRecommended_fails(); run_test_retrieveRecommended_fails(); }, searchFailed() { Loading @@ -538,6 +537,47 @@ function run_test_getAddonsByID_succeeds() { }, callback); } // Tests failure of AddonRepository.retrieveRecommendedAddons() function run_test_retrieveRecommended_fails() { Services.prefs.setCharPref(RECOMMENDED_TEST.preference, RECOMMENDED_TEST.preferenceValue); var callback = { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_throw("retrieveRecommendedAddons should not have succeeded"); end_test(); }, searchFailed() { do_check_false(AddonRepository.isSearching); run_test_retrieveRecommended_succeed(); } }; complete_search(function retrieveRecommended_failing_callback(aCallback) { AddonRepository.retrieveRecommendedAddons(FAILED_MAX_RESULTS, aCallback); }, callback); } // Tests success of AddonRepository.retrieveRecommendedAddons() function run_test_retrieveRecommended_succeed() { var callback = { searchSucceeded(aAddonsList, aAddonCount, aTotalResults) { do_check_eq(aTotalResults, -1); check_results(aAddonsList, SEARCH_RESULTS, aAddonCount); run_test_searchAddons_fails(); }, searchFailed() { do_throw("retrieveRecommendedAddons should not have failed"); end_test(); } }; complete_search(function retrieveRecommended_succeed_callback(aCallback) { AddonRepository.retrieveRecommendedAddons(MAX_RESULTS, aCallback); }, callback); } // Tests failure of AddonRepository.searchAddons() function run_test_searchAddons_fails() { Services.prefs.setCharPref(SEARCH_TEST.preference, SEARCH_TEST.preferenceValue); Loading Loading @@ -579,3 +619,4 @@ function run_test_searchAddons_succeeds() { AddonRepository.searchAddons(searchTerms, MAX_RESULTS, aCallback); }, callback); }
toolkit/mozapps/extensions/test/xpcshell/test_bug424262.js 0 → 100644 +61 −0 Original line number Diff line number Diff line /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm"); const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url"; Components.utils.import("resource://testing-common/httpd.js"); var server; var RESULTS = [ null, null, 0, 2, 4, 5, 5, 5 ]; var RecommendedCallback = { searchSucceeded(addons, length, total) { dump("loaded"); // Search is complete do_check_eq(length, RESULTS.length); for (var i = 0; i < length; i++) { if (addons[i].averageRating != RESULTS[i]) do_throw("Rating for " + addons[i].id + " was " + addons[i].averageRating + ", should have been " + RESULTS[i]); } server.stop(do_test_finished); }, searchFailed() { server.stop(do_test_finished); do_throw("Recommended results failed"); } }; function run_test() { // EM needs to be running. createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); startupManager(); server = new HttpServer(); server.start(-1); gPort = server.identity.primaryPort; mapFile("/data/test_bug424262.xml", server); // Point the addons repository to the test server Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, "http://localhost:" + gPort + "/data/test_bug424262.xml"); do_check_neq(AddonRepository, null); do_test_pending(); // Pull some results. AddonRepository.retrieveRecommendedAddons(RESULTS.length, RecommendedCallback); }
toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini +4 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,9 @@ skip-if = os == "android" # Bug 676992: test consistently hangs on Android skip-if = os == "android" tags = blocklist [test_bug424262.js] # Bug 676992: test consistently hangs on Android skip-if = os == "android" [test_bug425657.js] # Bug 676992: test consistently hangs on Android skip-if = os == "android" Loading Loading @@ -347,3 +350,4 @@ tags = blocklist [test_ext_management.js] skip-if = appname == "thunderbird" tags = webextensions