Bug 1530816 support RTA IDs in AddonRepository r=aswan
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 27 Feb 2019 17:18:46 +0000
changeset 519370 4d4fca2edcb5c8184a3eea20366c43cb8d2a59cb
parent 519369 f7619694f8839321d720ed90f26bd2c56c9e277c
child 519371 5580674b0d5fb1fe26d9d47b56f49e8e28635804
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1530816
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530816 support RTA IDs in AddonRepository r=aswan AddonRepository validates IDs that are returned from AMO. We need to handle the case where we are using rta prefix for ReturnToAMO. Differential Revision: https://phabricator.services.mozilla.com/D21389
toolkit/mozapps/extensions/internal/AddonRepository.jsm
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
--- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm
@@ -439,16 +439,22 @@ var AddonRepository = {
    *                   on the particular API being called of course).
    *
    * @returns Promise{array} An array of all the individual results from
    *                         the API call(s).
    */
   _fetchPaged(ids, pref, handler) {
     let startURL = this._formatURLPref(pref, {IDS: ids.join(",")});
     let results = [];
+    let idCheck = ids.map(id => {
+      if (id.startsWith("rta:")) {
+        return atob(id.split(":")[1]);
+      }
+      return id;
+    });
 
     const fetchNextPage = (url) => {
       return new Promise((resolve, reject) => {
         let request = new ServiceRequest({mozAnon: true});
         request.mozBackgroundRequest = true;
         request.open("GET", url, true);
         request.responseType = "json";
 
@@ -461,17 +467,17 @@ var AddonRepository = {
         request.addEventListener("load", aEvent => {
           let response = request.response;
           if (!response || (request.status != 200 && request.status != 0)) {
             reject(new Error(`GET ${url} failed (status ${request.status})`));
             return;
           }
 
           try {
-            let newResults = handler(response.results).filter(e => ids.includes(e.id));
+            let newResults = handler(response.results).filter(e => idCheck.includes(e.id));
             results.push(...newResults);
           } catch (err) {
             reject(err);
           }
 
           if (response.next) {
             resolve(fetchNextPage(response.next));
           }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
@@ -113,16 +113,20 @@ var GET_TEST = {
   successfulIDs:  ["test1@tests.mozilla.org",
                    "test2@tests.mozilla.org",
                    "{00000000-1111-2222-3333-444444444444}",
                    "test_AddonRepository_1@tests.mozilla.org"],
   successfulURL:    "/XPCShell/1/test1%40tests.mozilla.org%2C" +
                     "test2%40tests.mozilla.org%2C" +
                     "%7B00000000-1111-2222-3333-444444444444%7D%2C" +
                     "test_AddonRepository_1%40tests.mozilla.org",
+  successfulRTAURL: "/XPCShell/1/rta%3AdGVzdDFAdGVzdHMubW96aWxsYS5vcmc%2C" +
+                    "test2%40tests.mozilla.org%2C" +
+                    "%7B00000000-1111-2222-3333-444444444444%7D%2C" +
+                    "test_AddonRepository_1%40tests.mozilla.org",
 };
 
 // Test that actual results and expected results are equal
 function check_results(aActualAddons, aExpectedAddons) {
   do_check_addons(aActualAddons, aExpectedAddons, ADDON_PROPERTIES);
 
   // Additional tests
   aActualAddons.forEach(function check_each_addon(aActualAddon) {
@@ -146,16 +150,19 @@ add_task(async function setup() {
 
   // Register files used to test search failure
   gServer.registerFile(GET_TEST.failedURL,
                        do_get_file("data/test_AddonRepository_fail.json"));
 
   // Register files used to test search success
   gServer.registerFile(GET_TEST.successfulURL,
                        do_get_file("data/test_AddonRepository_getAddonsByIDs.json"));
+  // Register file for RTA test
+  gServer.registerFile(GET_TEST.successfulRTAURL,
+                       do_get_file("data/test_AddonRepository_getAddonsByIDs.json"));
 
   await promiseStartupManager();
 
   // Install an add-on so can check that it isn't returned in the results
   await promiseInstallFile(xpis[0]);
   await promiseRestartManager();
 
   // Create an active AddonInstall so can check that it isn't returned in the results
@@ -238,8 +245,17 @@ add_task(async function test_getAddonsBy
 });
 
 // Tests success of AddonRepository.getAddonsByIDs()
 add_task(async function test_getAddonsByID_succeeds() {
   let result = await AddonRepository.getAddonsByIDs(GET_TEST.successfulIDs);
 
   check_results(result, GET_RESULTS);
 });
+
+// Tests success of AddonRepository.getAddonsByIDs() with rta ID.
+add_task(async function test_getAddonsByID_rta() {
+  let id = `rta:${btoa(GET_TEST.successfulIDs[0])}`.slice(0, -1);
+  GET_TEST.successfulIDs[0] = id;
+  let result = await AddonRepository.getAddonsByIDs(GET_TEST.successfulIDs);
+
+  check_results(result, GET_RESULTS);
+});