Bug 1438035 - [marionette] Add Unicode support for profile path in switch_profile(). r=ato
authorHenrik Skupin <mail@hskupin.info>
Wed, 14 Feb 2018 21:32:04 +0100
changeset 404016 2eecb43376bae5c0520247c7b1df2c34ad40336e
parent 404015 ccfb3473baff618bfdfdcba5976eb1d555b7f949
child 404017 30f5526389d4009041da3d19bba5c56953a52556
push id99924
push userebalazs@mozilla.com
push dateThu, 15 Feb 2018 20:43:51 +0000
treeherdermozilla-inbound@a7d2a49f46fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1438035
milestone60.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 1438035 - [marionette] Add Unicode support for profile path in switch_profile(). r=ato The format string for the profile path in _update_profile caused encoding problems if the profile name is a unicode string. MozReview-Commit-ID: 9mTntFIcCtZ
testing/marionette/client/marionette_driver/geckoinstance.py
testing/marionette/harness/marionette_harness/tests/unit/test_profile_management.py
--- a/testing/marionette/client/marionette_driver/geckoinstance.py
+++ b/testing/marionette/client/marionette_driver/geckoinstance.py
@@ -197,27 +197,27 @@ class GeckoInstance(object):
         else:
             profile_args = self.profile_args
             profile_path = profile
 
             # If a path to a profile is given then clone it
             if isinstance(profile_path, basestring):
                 profile_args["path_from"] = profile_path
                 profile_args["path_to"] = tempfile.mkdtemp(
-                    suffix=".{}".format(profile_name or os.path.basename(profile_path)),
+                    suffix=u".{}".format(profile_name or os.path.basename(profile_path)),
                     dir=self.workspace)
                 # The target must not exist yet
                 os.rmdir(profile_args["path_to"])
 
                 profile = Profile.clone(**profile_args)
 
             # Otherwise create a new profile
             else:
                 profile_args["profile"] = tempfile.mkdtemp(
-                    suffix=".{}".format(profile_name or "mozrunner"),
+                    suffix=u".{}".format(profile_name or "mozrunner"),
                     dir=self.workspace)
                 profile = Profile(**profile_args)
                 profile.create_new = True
 
         if isinstance(self.profile, Profile):
             self.profile.cleanup()
 
         self._profile = profile
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_profile_management.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_profile_management.py
@@ -1,8 +1,10 @@
+# coding=UTF-8
+
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 import os
 import shutil
@@ -167,16 +169,34 @@ class TestSwitchProfileWithoutWorkspace(
     def test_new_named_profile(self):
         self.marionette.instance.switch_profile("foobar")
         self.marionette.start_session()
 
         self.assertNotEqual(self.profile_path, self.orig_profile_path)
         self.assertIn("foobar", self.profile_path)
         self.assertFalse(os.path.exists(self.orig_profile_path))
 
+    def test_new_named_profile_unicode(self):
+        """Test using unicode string with 1-4 bytes encoding works."""
+        self.marionette.instance.switch_profile(u"$¢€🍪")
+        self.marionette.start_session()
+
+        self.assertNotEqual(self.profile_path, self.orig_profile_path)
+        self.assertIn(u"$¢€🍪", self.profile_path)
+        self.assertFalse(os.path.exists(self.orig_profile_path))
+
+    def test_new_named_profile_unicode_escape_characters(self):
+        """Test using escaped unicode string with 1-4 bytes encoding works."""
+        self.marionette.instance.switch_profile(u"\u0024\u00A2\u20AC\u1F36A")
+        self.marionette.start_session()
+
+        self.assertNotEqual(self.profile_path, self.orig_profile_path)
+        self.assertIn(u"\u0024\u00A2\u20AC\u1F36A", self.profile_path)
+        self.assertFalse(os.path.exists(self.orig_profile_path))
+
     def test_clone_existing_profile(self):
         self.marionette.instance.switch_profile(clone_from=self.external_profile)
         self.marionette.start_session()
 
         self.assertIn(os.path.basename(self.external_profile.profile), self.profile_path)
         self.assertTrue(os.path.exists(self.external_profile.profile))
 
     def test_replace_with_current_profile(self):