Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g4johnib-A3 #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 7 additions & 75 deletions testing/puppeteer/firefox/firefox_puppeteer/api/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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