Bug 1449255: Part 5 - Rename test_bug397778 to test_manifest_locales.js and modernize. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Tue, 27 Mar 2018 13:31:59 -0700
changeset 777713 f9ccbbe67876b6e6fee36d6e9c312ad47e78230f
parent 777712 70428bfb977001128b38774592b26883ae348615
child 777714 6845d3bd0b1b73c2e272e4b9359e4f936e0ea501
push id105269
push userbmo:gl@mozilla.com
push dateThu, 05 Apr 2018 08:11:19 +0000
reviewersaswan
bugs1449255, 397778
milestone61.0a1
Bug 1449255: Part 5 - Rename test_bug397778 to test_manifest_locales.js and modernize. r=aswan MozReview-Commit-ID: 6PyCcBfSofu
toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
rename from toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
rename to toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js
@@ -55,114 +55,86 @@ const ADDON = {
     {
       locale: ["en-CA"],
       name: "en-CA Name",
       description: "en-CA Description",
     },
   ],
 };
 
-const XPI = createTempXPIFile(ADDON);
+function changeLocales(locales) {
+  Services.locale.setRequestedLocales(locales);
+  return promiseRestartManager();
+}
 
-function run_test() {
-  // Setup for test
-  do_test_pending();
+add_task(async function setup() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1");
   Services.locale.setRequestedLocales(["fr-FR"]);
 
-  // Install test add-on
-  startupManager();
-  installAllFiles([XPI], function() {
-    restartManager();
-
-    run_test_1();
-  });
-}
-
-function run_test_1() {
-  AddonManager.getAddonByID(ID, callback_soon(function(addon) {
-    Assert.notEqual(addon, null);
-    Assert.equal(addon.name, "fr Name");
-    Assert.equal(addon.description, "fr Description");
-
-    // Disable item
-    addon.userDisabled = true;
-    restartManager();
-
-    AddonManager.getAddonByID(ID, function(newAddon) {
-      Assert.notEqual(newAddon, null);
-      Assert.equal(newAddon.name, "fr Name");
+  await promiseStartupManager();
+  await promiseInstallXPI(ADDON);
+});
 
-      executeSoon(run_test_2);
-    });
-  }));
-}
-
-function run_test_2() {
-  // Change locale. The more specific de-DE is the best match
-  Services.locale.setRequestedLocales(["de"]);
-  restartManager();
+add_task(async function test_1() {
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  Assert.equal(addon.name, "fr Name");
+  Assert.equal(addon.description, "fr Description");
 
-  AddonManager.getAddonByID(ID, function(addon) {
-    Assert.notEqual(addon, null);
-    Assert.equal(addon.name, "Deutsches W\u00f6rterbuch");
-    Assert.equal(addon.description, null);
-
-    executeSoon(run_test_3);
-  });
-}
-
-function run_test_3() {
-  // Change locale. Locale case should have no effect
-  Services.locale.setRequestedLocales(["DE-de"]);
+  // Disable item
+  addon.userDisabled = true;
   restartManager();
 
-  AddonManager.getAddonByID(ID, function(addon) {
-    Assert.notEqual(addon, null);
-    Assert.equal(addon.name, "Deutsches W\u00f6rterbuch");
-    Assert.equal(addon.description, null);
+  let newAddon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(newAddon, null);
+  Assert.equal(newAddon.name, "fr Name");
+});
 
-    executeSoon(run_test_4);
-  });
-}
+add_task(async function test_2() {
+  // Change locale. The more specific de-DE is the best match
+  await changeLocales(["de"]);
 
-function run_test_4() {
-  // Change locale. es-ES should closely match
-  Services.locale.setRequestedLocales(["es-AR"]);
-  restartManager();
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  Assert.equal(addon.name, "Deutsches W\u00f6rterbuch");
+  Assert.equal(addon.description, null);
+});
 
-  AddonManager.getAddonByID(ID, function(addon) {
-    Assert.notEqual(addon, null);
-    Assert.equal(addon.name, "es-ES Name");
-    Assert.equal(addon.description, "es-ES Description");
+add_task(async function test_3() {
+  // Change locale. Locale case should have no effect
+  await changeLocales(["DE-de"]);
 
-    executeSoon(run_test_5);
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  Assert.equal(addon.name, "Deutsches W\u00f6rterbuch");
+  Assert.equal(addon.description, null);
+});
 
-function run_test_5() {
-  // Change locale. Either zh-CN or zh-TW could match
-  Services.locale.setRequestedLocales(["zh"]);
-  restartManager();
+add_task(async function test_4() {
+  // Change locale. es-ES should closely match
+  await changeLocales(["es-AR"]);
 
-  AddonManager.getAddonByID(ID, function(addon) {
-    Assert.notEqual(addon, null);
-    if (addon.name != "zh-TW Name" && addon.name != "zh-CN Name")
-      do_throw("zh matched to " + addon.name);
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  Assert.equal(addon.name, "es-ES Name");
+  Assert.equal(addon.description, "es-ES Description");
+});
 
-    executeSoon(run_test_6);
-  });
-}
+add_task(async function test_5() {
+  // Change locale. Either zh-CN or zh-TW could match
+  await changeLocales(["zh"]);
 
-function run_test_6() {
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  ok(addon.name == "zh-TW Name" || addon.name == "zh-CN Name",
+     `Add-on name mismatch: ${addon.name}`);
+});
+
+add_task(async function test_6() {
   // Unknown locale should try to match against en-US as well. Of en,en-GB
   // en should match as being less specific
-  Services.locale.setRequestedLocales(["nl-NL"]);
-  restartManager();
+  await changeLocales(["nl-NL"]);
 
-  AddonManager.getAddonByID(ID, function(addon) {
-    Assert.notEqual(addon, null);
-    Assert.equal(addon.name, "en Name");
-    Assert.equal(addon.description, "en Description");
-
-    executeSoon(do_test_finished);
-  });
-}
+  let addon = await AddonManager.getAddonByID(ID);
+  Assert.notEqual(addon, null);
+  Assert.equal(addon.name, "en Name");
+  Assert.equal(addon.description, "en Description");
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -42,19 +42,16 @@ tags = blocklist
 requesttimeoutfactor = 2
 tags = blocklist
 [test_bootstrap.js]
 skip-if = true # Bug 1358846 Bug 1365021 Bug 676992
 [test_bootstrap_const.js]
 [test_bootstrap_globals.js]
 [test_bug1180901_2.js]
 skip-if = os != "win"
-[test_bug397778.js]
-# Bug 676992: test consistently hangs on Android
-skip-if = os == "android"
 [test_bug430120.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 tags = blocklist
 [test_bug449027.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 tags = blocklist
@@ -175,16 +172,19 @@ skip-if = os == "android"
 [test_invalid_install_rdf.js]
 [test_isDebuggable.js]
 [test_isReady.js]
 [test_json_updatecheck.js]
 [test_legacy.js]
 skip-if = !allow_legacy_extensions || appname == "thunderbird"
 [test_locale.js]
 [test_manifest.js]
+[test_manifest_locales.js]
+# Bug 676992: test consistently hangs on Android
+skip-if = os == "android"
 [test_migrate_state_prefs.js]
 [test_no_addons.js]
 [test_nodisable_hidden.js]
 [test_onPropertyChanged_appDisabled.js]
 [test_overrideblocklist.js]
 run-sequentially = Uses global XCurProcD dir.
 tags = blocklist
 [test_pass_symbol.js]