Bug 1408066 - Addon.js install fails if path is incorrect. r?davehunt draft
authorBenjamin Forehand Jr <bennyjr169@gmail.com>
Thu, 19 Oct 2017 13:58:27 -0700
changeset 683494 d718db98838a2c4cb2b46301cc955d5e3cb1e805
parent 683411 ffe39c8025387d2cfd92005bc51b7269400b7420
child 736669 11066f70a204ed87ad5d18f50e0b6b775551d32d
push id85400
push userbmo:bforehand@mozilla.com
push dateThu, 19 Oct 2017 20:58:53 +0000
reviewersdavehunt
bugs1408066
milestone58.0a1
Bug 1408066 - Addon.js install fails if path is incorrect. r?davehunt MozReview-Commit-ID: L1uDoXDmg2V
testing/marionette/addon.js
testing/marionette/harness/marionette_harness/tests/unit/test_addons.py
--- a/testing/marionette/addon.js
+++ b/testing/marionette/addon.js
@@ -84,28 +84,29 @@ async function installAddon(file) {
  * @return {Promise.<string>}
  *     Addon ID.
  *
  * @throws {UnknownError}
  *     If there is a problem installing the addon.
  */
 addon.install = async function(path, temporary = false) {
   let addon;
+  var file;
 
   try {
-    let file = new FileUtils.File(path);
-    if (!file.exists()) {
-      throw new UnknownError();
-    }
+    file = new FileUtils.File(path);
   } catch (e) {
     throw new UnknownError(
-        `Could not find add-on at '${path}'`);
+        `Bad path. Please provide the full path to the add-on.`);
   }
 
-  let file = new FileUtils.File(path);
+  if (!file.exists()) {
+    throw new UnknownError(
+      `Could not find add-on at '${path}'`);
+  }
 
   try {
     if (temporary) {
       addon = await AddonManager.installTemporaryAddon(file);
     } else {
       addon = await installAddon(file);
     }
   } catch (e) {
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py
@@ -93,13 +93,13 @@ class TestAddons(MarionetteTestCase):
             self.addons.install(addon_path)
 
     def test_install_nonexistent_addon(self):
         addon_path = os.path.join(here, "does-not-exist.xpi")
 
         with self.assertRaisesRegexp(AddonInstallException, "Could not find add-on at"):
             self.addons.install(addon_path)
 
-    def test_install_incorrect_path(self):
-        addon_path = os.path.join('bad/path', 'does-not-exist.xpi')
+    def test_install_incorrect_relative_path(self):
+        addon_path = os.path.join('bad/path', 'webextension.xpi')
 
-        with self.assertRaisesRegexp(AddonInstallException, "Could not find add-on at"):
+        with self.assertRaisesRegexp(AddonInstallException, "Bad path. The path must be the full path to the add-on."):
             self.addons.install(addon_path)