From d8bfb41b737a9dee46730c2baae512b8129d6fba Mon Sep 17 00:00:00 2001 From: John Ibrahim Date: Fri, 26 Feb 2016 11:23:01 -0500 Subject: [PATCH 1/4] Modified prefs and prefs_tests to use newer methods. --- .../firefox_ui_tests/puppeteer/test_prefs.py | 9 ++ .../firefox/firefox_puppeteer/api/prefs.py | 82 ++----------------- 2 files changed, 16 insertions(+), 75 deletions(-) diff --git a/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py b/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py index 1bb5ed9877b04..0d657516c58c3 100644 --- a/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py +++ b/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py @@ -2,6 +2,15 @@ # 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/. +#The import and path inserts are strictly for testing on my local machine. +import sys +sys.path.insert(0, '/Users/johnibrahim/Desktop/CSC302/' \ + 'Firefox/gecko-dev/testing/marionette/driver/') + +sys.path.insert(0, '/Users/johnibrahim/Desktop/CSC302/' \ + 'Firefox/gecko-dev/testing/puppeteer/firefox/') + + from marionette_driver.errors import MarionetteException from firefox_puppeteer.testcases import FirefoxTestCase diff --git a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py index 4ca053f5c9304..914953d87455b 100644 --- a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py +++ b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py @@ -33,40 +33,10 @@ def get_pref(self, pref_name, default_branch=False, interface=None): """ assert pref_name is not None - with self.marionette.using_context('chrome'): - return self.marionette.execute_script(""" - Components.utils.import("resource://gre/modules/Services.jsm"); - - let pref_name = arguments[0]; - let default_branch = arguments[1]; - let interface = arguments[2]; - - let prefBranch; - if (default_branch) { - prefBranch = Services.prefs.getDefaultBranch(""); - } - else { - prefBranch = Services.prefs; - } - - // If an interface has been set, handle it differently - if (interface !== null) { - return prefBranch.getComplexValue(pref_name, - Components.interfaces[interface]).data; - } - - let type = prefBranch.getPrefType(pref_name); - - switch (type) { - case prefBranch.PREF_STRING: - return prefBranch.getCharPref(pref_name); - case prefBranch.PREF_BOOL: - return prefBranch.getBoolPref(pref_name); - case prefBranch.PREF_INT: - return prefBranch.getIntPref(pref_name); - case prefBranch.PREF_INVALID: - return null; - } + with self.using_context('content'): + return self.execute_script(""" + Components.utils.import("resource://gre/modules/Preferences.jsm"); + return Preferences.get(arguments[0], arguments[1], arguments[2]); """, script_args=[pref_name, default_branch, interface]) def reset_pref(self, pref_name): @@ -153,52 +123,14 @@ def set_pref(self, pref_name, value): assert pref_name is not None assert value is not None - with self.marionette.using_context('chrome'): + with self.using_context('content'): # Backup original value only once if pref_name not in self.archive: self.archive[pref_name] = self.get_pref(pref_name) retval = self.marionette.execute_script(""" - Components.utils.import("resource://gre/modules/Services.jsm"); - let prefBranch = Services.prefs; - - let pref_name = arguments[0]; - let value = arguments[1]; - - let type = prefBranch.getPrefType(pref_name); - - // If the pref does not exist yet, get the type from the value - if (type == prefBranch.PREF_INVALID) { - switch (typeof value) { - case "boolean": - type = prefBranch.PREF_BOOL; - break; - case "number": - type = prefBranch.PREF_INT; - break; - case "string": - type = prefBranch.PREF_STRING; - break; - default: - type = prefBranch.PREF_INVALID; - } - } - - switch (type) { - case prefBranch.PREF_BOOL: - prefBranch.setBoolPref(pref_name, value); - break; - case prefBranch.PREF_STRING: - prefBranch.setCharPref(pref_name, value); - break; - case prefBranch.PREF_INT: - prefBranch.setIntPref(pref_name, value); - break; - default: - return false; - } - - return true; + Components.utils.import("resource://gre/modules/Preferences.jsm"); + Preferences.set(arguments[0], arguments[1]); """, script_args=[pref_name, value]) assert retval From 9dc680fe91174e903de31b4be506173d564dcf29 Mon Sep 17 00:00:00 2001 From: John Ibrahim Date: Fri, 26 Feb 2016 12:39:54 -0500 Subject: [PATCH 2/4] Removed added sys path lines for local testing. --- .../tests/firefox_ui_tests/puppeteer/test_prefs.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py b/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py index 0d657516c58c3..1bb5ed9877b04 100644 --- a/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py +++ b/testing/firefox-ui/tests/firefox_ui_tests/puppeteer/test_prefs.py @@ -2,15 +2,6 @@ # 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/. -#The import and path inserts are strictly for testing on my local machine. -import sys -sys.path.insert(0, '/Users/johnibrahim/Desktop/CSC302/' \ - 'Firefox/gecko-dev/testing/marionette/driver/') - -sys.path.insert(0, '/Users/johnibrahim/Desktop/CSC302/' \ - 'Firefox/gecko-dev/testing/puppeteer/firefox/') - - from marionette_driver.errors import MarionetteException from firefox_puppeteer.testcases import FirefoxTestCase From cdaf96aec8c9391cc4cccf992d571dd6ed890f74 Mon Sep 17 00:00:00 2001 From: John Ibrahim Date: Fri, 26 Feb 2016 14:18:32 -0500 Subject: [PATCH 3/4] Testing. --- .../firefox/firefox_puppeteer/api/prefs.py | 78 +++++++++++++++++-- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py index 914953d87455b..1c152de9e0a26 100644 --- a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py +++ b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py @@ -34,9 +34,39 @@ def get_pref(self, pref_name, default_branch=False, interface=None): assert pref_name is not None with self.using_context('content'): - return self.execute_script(""" - Components.utils.import("resource://gre/modules/Preferences.jsm"); - return Preferences.get(arguments[0], arguments[1], arguments[2]); + return self.marionette.execute_script(""" + Components.utils.import("resource://gre/modules/Services.jsm"); + + let pref_name = arguments[0]; + let default_branch = arguments[1]; + let interface = arguments[2]; + + let prefBranch; + if (default_branch) { + prefBranch = Services.prefs.getDefaultBranch(""); + } + else { + prefBranch = Services.prefs; + } + + // If an interface has been set, handle it differently + if (interface !== null) { + return prefBranch.getComplexValue(pref_name, + Components.interfaces[interface]).data; + } + + let type = prefBranch.getPrefType(pref_name); + + switch (type) { + case prefBranch.PREF_STRING: + return prefBranch.getCharPref(pref_name); + case prefBranch.PREF_BOOL: + return prefBranch.getBoolPref(pref_name); + case prefBranch.PREF_INT: + return prefBranch.getIntPref(pref_name); + case prefBranch.PREF_INVALID: + return null; + } """, script_args=[pref_name, default_branch, interface]) def reset_pref(self, pref_name): @@ -129,8 +159,46 @@ def set_pref(self, pref_name, value): self.archive[pref_name] = self.get_pref(pref_name) retval = self.marionette.execute_script(""" - Components.utils.import("resource://gre/modules/Preferences.jsm"); - Preferences.set(arguments[0], arguments[1]); + Components.utils.import("resource://gre/modules/Services.jsm"); + let prefBranch = Services.prefs; + + let pref_name = arguments[0]; + let value = arguments[1]; + + let type = prefBranch.getPrefType(pref_name); + + // If the pref does not exist yet, get the type from the value + if (type == prefBranch.PREF_INVALID) { + switch (typeof value) { + case "boolean": + type = prefBranch.PREF_BOOL; + break; + case "number": + type = prefBranch.PREF_INT; + break; + case "string": + type = prefBranch.PREF_STRING; + break; + default: + type = prefBranch.PREF_INVALID; + } + } + + switch (type) { + case prefBranch.PREF_BOOL: + prefBranch.setBoolPref(pref_name, value); + break; + case prefBranch.PREF_STRING: + prefBranch.setCharPref(pref_name, value); + break; + case prefBranch.PREF_INT: + prefBranch.setIntPref(pref_name, value); + break; + default: + return false; + } + + return true; """, script_args=[pref_name, value]) assert retval From 9772bc45dff901e385ef2cd29570f5d3231204ca Mon Sep 17 00:00:00 2001 From: John Ibrahim Date: Fri, 26 Feb 2016 14:21:38 -0500 Subject: [PATCH 4/4] Added the fix again for patch file purposes. --- .../firefox/firefox_puppeteer/api/prefs.py | 78 ++----------------- 1 file changed, 5 insertions(+), 73 deletions(-) diff --git a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py index 1c152de9e0a26..914953d87455b 100644 --- a/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py +++ b/testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py @@ -34,39 +34,9 @@ def get_pref(self, pref_name, default_branch=False, interface=None): assert pref_name is not None with self.using_context('content'): - return self.marionette.execute_script(""" - Components.utils.import("resource://gre/modules/Services.jsm"); - - let pref_name = arguments[0]; - let default_branch = arguments[1]; - let interface = arguments[2]; - - let prefBranch; - if (default_branch) { - prefBranch = Services.prefs.getDefaultBranch(""); - } - else { - prefBranch = Services.prefs; - } - - // If an interface has been set, handle it differently - if (interface !== null) { - return prefBranch.getComplexValue(pref_name, - Components.interfaces[interface]).data; - } - - let type = prefBranch.getPrefType(pref_name); - - switch (type) { - case prefBranch.PREF_STRING: - return prefBranch.getCharPref(pref_name); - case prefBranch.PREF_BOOL: - return prefBranch.getBoolPref(pref_name); - case prefBranch.PREF_INT: - return prefBranch.getIntPref(pref_name); - case prefBranch.PREF_INVALID: - return null; - } + return self.execute_script(""" + Components.utils.import("resource://gre/modules/Preferences.jsm"); + return Preferences.get(arguments[0], arguments[1], arguments[2]); """, script_args=[pref_name, default_branch, interface]) def reset_pref(self, pref_name): @@ -159,46 +129,8 @@ def set_pref(self, pref_name, value): self.archive[pref_name] = self.get_pref(pref_name) retval = self.marionette.execute_script(""" - Components.utils.import("resource://gre/modules/Services.jsm"); - let prefBranch = Services.prefs; - - let pref_name = arguments[0]; - let value = arguments[1]; - - let type = prefBranch.getPrefType(pref_name); - - // If the pref does not exist yet, get the type from the value - if (type == prefBranch.PREF_INVALID) { - switch (typeof value) { - case "boolean": - type = prefBranch.PREF_BOOL; - break; - case "number": - type = prefBranch.PREF_INT; - break; - case "string": - type = prefBranch.PREF_STRING; - break; - default: - type = prefBranch.PREF_INVALID; - } - } - - switch (type) { - case prefBranch.PREF_BOOL: - prefBranch.setBoolPref(pref_name, value); - break; - case prefBranch.PREF_STRING: - prefBranch.setCharPref(pref_name, value); - break; - case prefBranch.PREF_INT: - prefBranch.setIntPref(pref_name, value); - break; - default: - return false; - } - - return true; + Components.utils.import("resource://gre/modules/Preferences.jsm"); + Preferences.set(arguments[0], arguments[1]); """, script_args=[pref_name, value]) assert retval