From fddea5b60248ccb433a8a9ae65ca086402efe4a3 Mon Sep 17 00:00:00 2001 From: "annie.sullivan%gmail.com" Date: Thu, 17 Aug 2006 21:03:32 +0000 Subject: [PATCH] Fixes bug where string and bool prefs were not being written correctly. bug=349063 r=rhelmer@mozilla.org git-svn-id: svn://10.0.0.236/trunk@207774 18797224-902f-48f8-a5cc-f745e15eee43 --- .../testing/performance/win32/ffprofile.py | 36 +++++++------------ .../testing/performance/win32/sample.config | 6 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/mozilla/testing/performance/win32/ffprofile.py b/mozilla/testing/performance/win32/ffprofile.py index d74f8ef0893..e11fc8f6920 100755 --- a/mozilla/testing/performance/win32/ffprofile.py +++ b/mozilla/testing/performance/win32/ffprofile.py @@ -71,7 +71,14 @@ def PrefString(name, value, newline): String containing 'user_pref("name", value);' """ - return 'user_pref("' + name + '", ' + str(value) + ');' + newline + out_value = str(value) + if type(value) == bool: + # Write bools as "true"/"false", not "True"/"False". + out_value = out_value.lower() + if type(value) == str: + # Write strings with quotes around them. + out_value = '"%s"' % value + return 'user_pref("%s", %s);%s' % (name, out_value, newline) def MakeDirectoryContentsWritable(dirname): @@ -111,29 +118,12 @@ def CreateTempProfileDir(source_profile, prefs, extensions): shutil.copytree(source_profile, profile_dir) MakeDirectoryContentsWritable(profile_dir) - # Make sure all the preferences are set correctly in the prefs.js file - pref_filename = os.path.join(profile_dir, 'prefs.js') - pref_file = open(pref_filename, 'rU') - pref_lines = pref_file.readlines() - newline = pref_file.newlines - pref_file.close() - pref_re = re.compile('user_pref\(\"([^\"]*)\"\,\s*([^\)]*)\);') + # Copy the user-set prefs to user.js + user_js_filename = os.path.join(profile_dir, 'user.js') + user_js_file = open(user_js_filename, 'w') for pref in prefs: - # Check each line to check if the pref is already there. - found = False - for i in range(0, len(pref_lines)): - match = pref_re.search(pref_lines[i]) - if match and match.group(1) == pref: - pref_lines[i] = PrefString(pref, prefs[pref], newline) - found = True - break - if not found: - pref_lines.append(PrefString(pref, prefs[pref], newline)) - # Write the prefs back out - pref_file = open(pref_filename, 'w') - for line in pref_lines: - pref_file.write(line) - pref_file.close() + user_js_file.write(PrefString(pref, prefs[pref], '\n')) + user_js_file.close() # Add links to all the extensions. extension_dir = os.path.join(profile_dir, "extensions") diff --git a/mozilla/testing/performance/win32/sample.config b/mozilla/testing/performance/win32/sample.config index e71fdf0123b..db025c6ebfe 100755 --- a/mozilla/testing/performance/win32/sample.config +++ b/mozilla/testing/performance/win32/sample.config @@ -26,9 +26,11 @@ Firefox 2.0 beta 1: firefox: "C:\\Program Files\Mozilla Firefox 2 Beta 1\\firefox.exe" # Turn on prefs to enable safe browsing with no remote lookups + # As an example of a string pref, make the selected search eBay preferences: browser.safebrowsing.enabled: true - browser.safebrowsing.remoteLookups: false1 + browser.safebrowsing.remoteLookups: false + browser.search.selectedEngine: "eBay" # No extensions - extensions: {} \ No newline at end of file + extensions: {}