Bug 1438035 - [marionette] Add Unicode support for profile path in switch_profile().
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
--- 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):