Bug 1233534 - [mozprofile] unable to use a profile generated with recent firefox. r=ahal
authorJulien Pagès <j.parkouss@gmail.com>
Fri, 18 Dec 2015 08:19:41 +0100
changeset 277099 f571f0a4abc1eb6bd4c046e04bc9cdc070ffe06a
parent 277098 ca28125f2f0d36968e9fdffcccc5b817ee0ea324
child 277100 e1a98377eb38679bda820456ee6d20bdc17eaa8e
push id16724
push usercbook@mozilla.com
push dateMon, 21 Dec 2015 11:00:52 +0000
treeherderfx-team@3f3f0361567c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1233534
milestone46.0a1
Bug 1233534 - [mozprofile] unable to use a profile generated with recent firefox. r=ahal
testing/mozbase/mozprofile/mozprofile/prefs.py
testing/mozbase/mozprofile/tests/test_preferences.py
--- a/testing/mozbase/mozprofile/mozprofile/prefs.py
+++ b/testing/mozbase/mozprofile/mozprofile/prefs.py
@@ -160,20 +160,20 @@ class Preferences(object):
         :param path: The path to the preference file to read.
         :param pref_setter: The name of the function used to set preferences
                             in the preference file.
         :param interpolation: If provided, a dict that will be passed
                               to str.format to interpolate preference values.
         """
 
         marker = '##//' # magical marker
-        lines = [i.strip() for i in mozfile.load(path).readlines() if i.strip()]
+        lines = [i.strip() for i in mozfile.load(path).readlines()]
         _lines = []
         for line in lines:
-            if line.startswith(('#', '//')):
+            if not line.startswith(pref_setter):
                 continue
             if '//' in line:
                 line = line.replace('//', marker)
             _lines.append(line)
         string = '\n'.join(_lines)
 
         # skip trailing comments
         processed_tokens = []
--- a/testing/mozbase/mozprofile/tests/test_preferences.py
+++ b/testing/mozbase/mozprofile/tests/test_preferences.py
@@ -254,16 +254,44 @@ user_pref("webgl.force-enabled", true);
             del profile
 
             # make sure you have the original preferences
             prefs = Preferences.read_prefs(user_js)
             self.assertTrue(prefs == original_prefs)
         finally:
             shutil.rmtree(tempdir)
 
+    def test_can_read_prefs_with_multiline_comments(self):
+        """
+        Ensure that multiple comments in the file header do not break reading
+        the prefs (https://bugzilla.mozilla.org/show_bug.cgi?id=1233534).
+        """
+        user_js = tempfile.NamedTemporaryFile(suffix='.js', delete=False)
+        self.addCleanup(mozfile.remove, user_js.name)
+        with user_js:
+            user_js.write("""
+# Mozilla User Preferences
+
+/* Do not edit this file.
+ *
+ * If you make changes to this file while the application is running,
+ * the changes will be overwritten when the application exits.
+ *
+ * To make a manual change to preferences, you can visit the URL about:config
+ */
+
+user_pref("webgl.enabled_for_all_sites", true);
+user_pref("webgl.force-enabled", true);
+""")
+        self.assertEqual(
+            Preferences.read_prefs(user_js.name),
+            [('webgl.enabled_for_all_sites', True),
+             ('webgl.force-enabled', True)]
+        )
+
     def test_json(self):
         _prefs = {"browser.startup.homepage": "http://planet.mozilla.org/"}
         json = '{"browser.startup.homepage": "http://planet.mozilla.org/"}'
 
         # just repr it...could use the json module but we don't need it here
         with mozfile.NamedTemporaryFile(suffix='.json') as f:
             f.write(json)
             f.flush()