From 780b07487f3229db85686ba13294d7d508138be2 Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 6 Oct 2020 14:01:26 +0000 Subject: [PATCH] Bug 1668458 - Ensure paths passed to Addons.install use os path separators only, r=marionette-reviewers,whimboo On Windows we can end up with a mixture of / and \ which makes the install fail. Differential Revision: https://phabricator.services.mozilla.com/D92229 --- .../marionette/client/marionette_driver/addons.py | 5 +++++ .../marionette_harness/tests/unit/test_addons.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/testing/marionette/client/marionette_driver/addons.py b/testing/marionette/client/marionette_driver/addons.py index e4cb6de2ba25..3bdb989f06d1 100644 --- a/testing/marionette/client/marionette_driver/addons.py +++ b/testing/marionette/client/marionette_driver/addons.py @@ -3,6 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import +import os from . import errors @@ -47,6 +48,10 @@ class Addons(object): :raises: :exc:`AddonInstallException` """ + # On windows we can end up with a path with mixed \ and / + # which Firefox doesn't like + path = path.replace("/", os.path.sep) + body = {"path": path, "temporary": temp} try: return self._mn._send_message("Addon:Install", diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py b/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py index 7feef81bb484..f27564154f61 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_addons.py @@ -5,6 +5,8 @@ from __future__ import absolute_import import os +import sys +from unittest import skipIf from marionette_driver.addons import Addons, AddonInstallException from marionette_harness import MarionetteTestCase @@ -106,3 +108,16 @@ class TestAddons(MarionetteTestCase): def test_install_with_relative_path(self): with self.assertRaises(AddonInstallException): self.addons.install('webextension.xpi') + + @skipIf(sys.platform != "win32", "Only makes sense on Windows") + def test_install_mixed_separator_windows(self): + # Ensure the base path has only \ + addon_path = here.replace("/", "\\") + addon_path += "/webextension-signed.xpi" + + addon_id = self.addons.install(addon_path, temp=True) + self.assertIn(addon_id, self.all_addon_ids) + self.assertEqual(addon_id, "{d3e7c1f1-2e35-4a49-89fe-9f46eb8abf0a}") + + self.addons.uninstall(addon_id) + self.assertNotIn(addon_id, self.all_addon_ids)