Bug 1469696 - Part 5: Test listing and installing AMO langpacks r=aswan,jaws
authorMark Striemer <mstriemer@mozilla.com>
Tue, 02 Oct 2018 17:57:33 +0000
changeset 495134 54abaf608a606310adfebfa816051aa55bf6475a
parent 495133 4973d5d699c5f6dc29d3c7f512431d3ae49b11f9
child 495135 5b0ef00bdd7c5c98aa8eea2ffcd077fe23d10d8c
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, jaws
bugs1469696
milestone64.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 1469696 - Part 5: Test listing and installing AMO langpacks r=aswan,jaws Differential Revision: https://phabricator.services.mozilla.com/D6315
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -804,16 +804,17 @@ var gMainPane = {
       let menuitem = document.createXULElement("menuitem");
       menuitem.setAttribute("value", code);
       menuitem.setAttribute("label", name);
       fragment.appendChild(menuitem);
     }
 
     // Add an option to search for more languages.
     let menuitem = document.createXULElement("menuitem");
+    menuitem.id = "defaultBrowserLanguageSearch";
     menuitem.setAttribute(
       "label", await document.l10n.formatValue("browser-languages-search"));
     menuitem.addEventListener("command", () => {
       gMainPane.showBrowserLanguages({search: true});
     });
     fragment.appendChild(menuitem);
 
     let menulist = document.getElementById("defaultBrowserLanguage");
--- a/browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
+++ b/browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
@@ -37,24 +37,53 @@ function getManifestData(locale) {
   };
 }
 
 let testLocales = ["fr", "pl", "he"];
 let testLangpacks;
 
 function createTestLangpacks() {
   if (!testLangpacks) {
-    testLangpacks = Promise.all(testLocales.map(locale =>
-      AddonTestUtils.createTempXPIFile({
+    testLangpacks = Promise.all(testLocales.map(async locale => [
+      locale,
+      await AddonTestUtils.createTempXPIFile({
         "manifest.json": getManifestData(locale),
-      })));
+      }),
+    ]));
   }
   return testLangpacks;
 }
 
+function createLocaleResult(target_locale, url) {
+  return {
+    type: "language",
+    target_locale,
+    current_compatible_version: {
+      files: [{
+        platform: "all",
+        url,
+      }],
+    },
+  };
+}
+
+async function createLanguageToolsFile() {
+  let langpacks = await createTestLangpacks();
+  let results = langpacks.map(([locale, file]) =>
+    createLocaleResult(locale, Services.io.newFileURI(file).spec));
+
+  let filename = "language-tools.json";
+  let files = {[filename]: {results}};
+  let tempdir = AddonTestUtils.tempDir.clone();
+  let dir = await AddonTestUtils.promiseWriteFilesToDir(tempdir.path, files);
+  dir.append(filename);
+
+  return dir;
+}
+
 function assertLocaleOrder(list, locales) {
   is(list.itemCount, locales.split(",").length,
      "The right number of locales are requested");
   is(Array.from(list.children).map(child => child.value).join(","),
      locales, "The requested locales are in order");
 }
 
 function assertAvailableLocales(list, locales) {
@@ -67,19 +96,23 @@ function assertAvailableLocales(list, lo
 
 function requestLocale(localeCode, available, dialogDoc) {
   let [locale] = Array.from(available.firstElementChild.children)
     .filter(item => item.value == localeCode);
   available.selectedItem = locale;
   dialogDoc.getElementById("add").doCommand();
 }
 
-async function openDialog(doc) {
+async function openDialog(doc, search = false) {
   let dialogLoaded = promiseLoadSubDialog(BROWSER_LANGUAGES_URL);
-  doc.getElementById("manageBrowserLanguagesButton").doCommand();
+  if (search) {
+    doc.getElementById("defaultBrowserLanguageSearch").doCommand();
+  } else {
+    doc.getElementById("manageBrowserLanguagesButton").doCommand();
+  }
   let dialogWin = await dialogLoaded;
   let dialogDoc = dialogWin.document;
   return {
     dialog: dialogDoc.getElementById("BrowserLanguagesDialog"),
     dialogDoc,
     available: dialogDoc.getElementById("availableLocales"),
     requested: dialogDoc.getElementById("requestedLocales"),
   };
@@ -146,17 +179,17 @@ add_task(async function testAddAndRemove
     set: [
       ["intl.multilingual.enabled", true],
       ["intl.locale.requested", "en-US"],
       ["extensions.langpacks.signatures.required", false],
     ],
   });
 
   let langpacks = await createTestLangpacks();
-  let addons = await Promise.all(langpacks.map(async file => {
+  let addons = await Promise.all(langpacks.map(async ([locale, file]) => {
     let install = await AddonTestUtils.promiseInstallFile(file);
     return install.addon;
   }));
 
   await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
 
   let doc = gBrowser.contentDocument;
   let messageBar = doc.getElementById("confirmBrowserLanguage");
@@ -200,8 +233,70 @@ add_task(async function testAddAndRemove
   is(messageBar.hidden, false, "The message bar is now visible");
   is(messageBar.querySelector("button").getAttribute("locales"), "he,en-US",
     "The locales are set on the message bar button");
 
   await Promise.all(addons.map(addon => addon.uninstall()));
 
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
+
+add_task(async function testInstallFromAMO() {
+  let langpacks = await AddonManager.getAddonsByTypes(["locale"]);
+  is(langpacks.length, 0, "There are no langpacks installed");
+
+  let langpacksFile = await createLanguageToolsFile();
+  let langpacksUrl = Services.io.newFileURI(langpacksFile).spec;
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      ["intl.multilingual.enabled", true],
+      ["intl.locale.requested", "en-US"],
+      ["extensions.getAddons.langpacks.url", langpacksUrl],
+      ["extensions.langpacks.signatures.required", false],
+    ],
+  });
+
+  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+
+  let doc = gBrowser.contentDocument;
+  let messageBar = doc.getElementById("confirmBrowserLanguage");
+  is(messageBar.hidden, true, "The message bar is hidden at first");
+
+  // Open the dialog.
+  let {dialogDoc, available, requested} = await openDialog(doc, true);
+
+  let dropdown = dialogDoc.getElementById("availableLocales");
+  if (dropdown.itemCount == 1) {
+    await waitForMutation(
+      dropdown.firstElementChild,
+      {childList: true},
+      target => dropdown.itemCount > 1);
+  }
+
+  // The initial order is set by the pref.
+  assertLocaleOrder(requested, "en-US");
+  assertAvailableLocales(available, ["fr", "he", "pl"]);
+  is(Services.locale.availableLocales.join(","),
+     "en-US", "There is only one installed locale");
+
+  // Add Polish, this will install the langpack.
+  requestLocale("pl", available, dialogDoc);
+
+  // Wait for the langpack to install and be added to the list.
+  let requestedLocales = dialogDoc.getElementById("requestedLocales");
+  await waitForMutation(
+    requestedLocales,
+    {childList: true},
+    target => requestedLocales.itemCount == 2);
+
+  // Verify the list is correct.
+  assertLocaleOrder(requested, "pl,en-US");
+  assertAvailableLocales(available, ["fr", "he"]);
+  is(Services.locale.availableLocales.sort().join(","),
+     "en-US,pl", "Polish is now installed");
+
+  // Uninstall the langpack.
+  langpacks = await AddonManager.getAddonsByTypes(["locale"]);
+  is(langpacks.length, 1, "There is one langpacks installed");
+  await Promise.all(langpacks.map(pack => pack.uninstall()));
+
+  BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});