Skip to content

Commit

Permalink
Bug 1240576 - Use Preferences.jsm throughout Marionette; r=automatedt…
Browse files Browse the repository at this point in the history
…ester

A distinct advantage is that try...catch statements are no longer used
to control the flow of code.
  • Loading branch information
andreastt committed Jan 18, 2016
1 parent 439e7b1 commit d6ec3c7
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 175 deletions.
18 changes: 11 additions & 7 deletions testing/marionette/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* 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/. */

var {classes: Cc, interfaces: Ci, utils: Cu} = Components;

Cu.import("resource://gre/modules/Preferences.jsm");

var CONTEXT_MENU_DELAY_PREF = "ui.click_hold_context_menus.delay";
var DEFAULT_CONTEXT_MENU_DELAY = 750; // ms

this.EXPORTED_SYMBOLS = ["ActionChain"];

/**
Expand All @@ -18,8 +25,7 @@ this.ActionChain = function(utils, checkForInterrupted) {
this.scrolling = false;
// whether to send mouse event
this.mouseEventsOnly = false;
this.checkTimer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
this.checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);

// callbacks for command completion
this.onSuccess = null;
Expand Down Expand Up @@ -258,10 +264,9 @@ ActionChain.prototype.actions = function(chain, touchId, i, keyModifiers) {
let time = pack[1] * 1000;

// standard waiting time to fire contextmenu
let standard = 750;
try {
standard = Services.prefs.getIntPref("ui.click_hold_context_menus.delay");
} catch (e) {}
let standard = Preferences.get(
CONTEXT_MENU_DELAY_PREF,
DEFAULT_CONTEXT_MENU_DELAY);

if (time >= standard && this.isTap) {
chain.splice(i, 0, ["longPress"], ["wait", (time - standard) / 1000]);
Expand Down Expand Up @@ -297,7 +302,6 @@ ActionChain.prototype.actions = function(chain, touchId, i, keyModifiers) {
keyModifiers);
this.actions(chain, touchId, i, keyModifiers);
break;

}
};

Expand Down
4 changes: 2 additions & 2 deletions testing/marionette/client/marionette/marionette_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ def setup_SpecialPowers_observer(self):
self.marionette.set_context("chrome")
self.marionette.execute_script("""
let SECURITY_PREF = "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer";
Components.utils.import("resource://gre/modules/Services.jsm");
Services.prefs.setBoolPref(SECURITY_PREF, true);
Components.utils.import("resource://gre/modules/Preferences.jsm");
Preferences.set(SECURITY_PREF, true);
if (!testUtils.hasOwnProperty("specialPowersObserver")) {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
Expand Down
11 changes: 6 additions & 5 deletions testing/marionette/client/marionette/runner/mixins/browsermob.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def create_browsermob_proxy(self):
client = self.browsermob_server.create_proxy()
with self.marionette.using_context('chrome'):
self.marionette.execute_script("""
Services.prefs.setIntPref('network.proxy.type', 1);
Services.prefs.setCharPref('network.proxy.http', 'localhost');
Services.prefs.setIntPref('network.proxy.http_port', %(port)s);
Services.prefs.setCharPref('network.proxy.ssl', 'localhost');
Services.prefs.setIntPref('network.proxy.ssl_port', %(port)s);
Components.utils.import("resource://gre/modules/Preferences.jsm");
Preferences.set("network.proxy.type", 1);
Preferences.set("network.proxy.http", "localhost");
Preferences.set("network.proxy.http_port", %(port)s);
Preferences.set("network.proxy.ssl", "localhost");
Preferences.set("network.proxy.ssl_port", %(port)s);
""" % {"port": client.port})
return client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
from marionette_driver.by import By


OOP_BY_DEFAULT = "dom.ipc.browser_frames.oop_by_default"
BROWSER_FRAMES_ENABLED = "dom.mozBrowserFramesEnabeld"


class TestGetActiveFrameOOP(MarionetteTestCase):
def setUp(self):
super(TestGetActiveFrameOOP, self).setUp()
with self.marionette.using_context('chrome'):
self.oop_by_default = self.marionette.execute_script("""
try {
return Services.prefs.getBoolPref('dom.ipc.browser_frames.oop_by_default');
}
catch(e) {}
""")
self.mozBrowserFramesEnabled = self.marionette.execute_script("""
try {
return Services.prefs.getBoolPref('dom.mozBrowserFramesEnabled');
}
catch(e) {}
""")
self.marionette.execute_script("""
Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', true);
""")
self.marionette.execute_script("""
Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', true);
""")
with self.marionette.using_context("chrome"):
self.oop_by_default = self.marionette.get_pref(OOP_BY_DEFAULT)
self.mozBrowserFramesEnabled = self.marionette.get_pref(BROWSER_FRAMES_ENABLED)
self.marionette.set_pref(OOP_BY_DEFAULT, True)
self.marionette.set_pref(BROWSER_FRAMES_ENABLED, True)

def tearDown(self):
with self.marionette.using_context("chrome"):
if self.oop_by_default is None:
self.marionette.clear_pref(OOP_BY_DEFAULT)
else:
self.marionette.set_pref(OOP_BY_DEFAULT, self.oop_by_default)

if self.mozBrowserFramesEnabled is None:
self.marionette.clear_pref(BROWSER_FRAMES_ENABLED)
else:
self.marionette.set_pref(BROWSER_FRAMES_ENABLED, self.mozBrowserFramesEnabled)

def test_active_frame_oop(self):
self.marionette.navigate(self.marionette.absolute_url("test.html"))
Expand Down Expand Up @@ -94,22 +96,3 @@ def test_active_frame_oop(self):
# on a b2g device, the contents do appear
# print self.marionette.get_url()
# print self.marionette.page_source

def tearDown(self):
with self.marionette.using_context('chrome'):
if self.oop_by_default is None:
self.marionette.execute_script("""
Services.prefs.clearUserPref('dom.ipc.browser_frames.oop_by_default');
""")
else:
self.marionette.execute_script("""
Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s);
""" % 'true' if self.oop_by_default else 'false')
if self.mozBrowserFramesEnabled is None:
self.marionette.execute_script("""
Services.prefs.clearUserPref('dom.mozBrowserFramesEnabled');
""")
else:
self.marionette.execute_script("""
Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', %s);
""" % 'true' if self.mozBrowserFramesEnabled else 'false')
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_proxy_is_a_string_should_throw_invalid_argument(self):
self.marionette.start_session(capabilities)
self.fail("We should have started a session because proxy should be a dict")
except InvalidArgumentException as e:
assert e.msg == "the value of 'proxy' should be an object"
assert e.msg == "Value of 'proxy' should be an object"

def test_proxy_is_passed_in_with_no_proxy_doesnt_set_it(self):
capabilities = {"requiredCapabilities":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
from marionette import MarionetteTestCase


OOP_BY_DEFAULT = "dom.ipc.browser_frames.oop_by_default"
BROWSER_FRAMES_ENABLED = "dom.mozBrowserFramesEnabled"


class TestSwitchRemoteFrame(MarionetteTestCase):
def setUp(self):
super(TestSwitchRemoteFrame, self).setUp()
with self.marionette.using_context('chrome'):
self.oop_by_default = self.marionette.execute_script("""
try {
return Services.prefs.getBoolPref('dom.ipc.browser_frames.oop_by_default');
}
catch(e) {}
""")
self.mozBrowserFramesEnabled = self.marionette.execute_script("""
try {
return Services.prefs.getBoolPref('dom.mozBrowserFramesEnabled');
}
catch(e) {}
""")
self.marionette.execute_script("""
Services.prefs.setBoolPref("dom.ipc.browser_frames.oop_by_default", true);
Services.prefs.setBoolPref("dom.mozBrowserFramesEnabled", true);
""")
self.oop_by_default = self.marionette.get_pref(OOP_BY_DEFAULT)
self.mozBrowserFramesEnabled = self.marionette.get_pref(BROWSER_FRAMES_ENABLED)
self.marionette.set_pref(OOP_BY_DEFAULT, True)
self.marionette.set_pref(BROWSER_FRAMES_ENABLED, True)

self.multi_process_browser = self.marionette.execute_script("""
try {
Expand All @@ -33,12 +25,25 @@ def setUp(self):
return false;
}""")

def tearDown(self):
with self.marionette.using_context("chrome"):
if self.oop_by_default is None:
self.marionette.clear_pref(OOP_BY_DEFAULT)
else:
self.marionette.set_pref(OOP_BY_DEFAULT, self.oop_by_default)

if self.mozBrowserFramesEnabled is None:
self.marionette.clear_pref(BROWSER_FRAMES_ENABLED)
else:
self.marionette.set_pref(BROWSER_FRAMES_ENABLED, self.mozBrowserFramesEnabled)

@property
def is_main_process(self):
return self.marionette.execute_script("""
return Components.classes["@mozilla.org/xre/app-info;1"].
getService(Components.interfaces.nsIXULRuntime).
processType == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
""", sandbox='system')
""", sandbox="system")

def test_remote_frame(self):
self.marionette.navigate(self.marionette.absolute_url("test.html"))
Expand All @@ -55,7 +60,7 @@ def test_remote_frame(self):
""" % self.marionette.absolute_url("test.html"))
remote_iframe = self.marionette.find_element("id", "remote_iframe")
self.marionette.switch_to_frame(remote_iframe)
main_process = self.is_main_process()
main_process = self.is_main_process
self.assertFalse(main_process)

def test_remote_frame_revisit(self):
Expand All @@ -74,15 +79,15 @@ def test_remote_frame_revisit(self):
""" % self.marionette.absolute_url("test.html"))
self.marionette.switch_to_frame(self.marionette.find_element("id",
"remote_iframe"))
main_process = self.is_main_process()
main_process = self.is_main_process
self.assertFalse(main_process)
self.marionette.switch_to_frame()
main_process = self.is_main_process()
main_process = self.is_main_process
should_be_main_process = not self.multi_process_browser
self.assertEqual(main_process, should_be_main_process)
self.marionette.switch_to_frame(self.marionette.find_element("id",
"remote_iframe"))
main_process = self.is_main_process()
main_process = self.is_main_process
self.assertFalse(main_process)

def test_we_can_switch_to_a_remote_frame_by_index(self):
Expand All @@ -100,31 +105,12 @@ def test_we_can_switch_to_a_remote_frame_by_index(self):
document.body.appendChild(iframe);
""" % self.marionette.absolute_url("test.html"))
self.marionette.switch_to_frame(0)
main_process = self.is_main_process()
main_process = self.is_main_process
self.assertFalse(main_process)
self.marionette.switch_to_frame()
main_process = self.is_main_process()
main_process = self.is_main_process
should_be_main_process = not self.multi_process_browser
self.assertEqual(main_process, should_be_main_process)
self.marionette.switch_to_frame(0)
main_process = self.is_main_process()
main_process = self.is_main_process
self.assertFalse(main_process)

def tearDown(self):
with self.marionette.using_context('chrome'):
if self.oop_by_default is None:
self.marionette.execute_script("""
Services.prefs.clearUserPref('dom.ipc.browser_frames.oop_by_default');
""")
else:
self.marionette.execute_async_script(
"Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s);" %
('true' if self.oop_by_default else 'false'))
if self.mozBrowserFramesEnabled is None:
self.marionette.execute_script("""
Services.prefs.clearUserPref('dom.mozBrowserFramesEnabled');
""")
else:
self.marionette.execute_async_script(
"Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', %s);" %
('true' if self.mozBrowserFramesEnabled else 'false'))
17 changes: 5 additions & 12 deletions testing/marionette/components/marionettecomponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ MarionetteComponent.prototype.observe = function(subj, topic, data) {
// so we wait for that by adding an observer here.
this.observerService.addObserver(this, "final-ui-startup", false);
#ifdef ENABLE_MARIONETTE
try {
this.enabled = Services.prefs.getBoolPref(ENABLED_PREF);
} catch(e) {}
this.enabled = Preferences.get(ENABLED_PREF, false);
if (this.enabled) {
this.logger.debug("Marionette enabled via build flag and pref");

Expand Down Expand Up @@ -165,11 +163,9 @@ MarionetteComponent.prototype.init = function() {

this.loaded_ = true;

let forceLocal = Services.appinfo.name == "B2G" ? false : true;
try {
forceLocal = Services.prefs.getBoolPref(FORCELOCAL_PREF);
} catch (e) {}
Services.prefs.setBoolPref(FORCELOCAL_PREF, forceLocal);
let forceLocal = Preferences.get(FORCELOCAL_PREF,
Services.appinfo.name == "B2G" ? false : true);
Preferences.set(FORCELOCAL_PREF, forceLocal);

if (!forceLocal) {
// See bug 800138. Because the first socket that opens with
Expand All @@ -182,10 +178,7 @@ MarionetteComponent.prototype.init = function() {
insaneSacrificialGoat.asyncListen(this);
}

let port = DEFAULT_PORT;
try {
port = Services.prefs.getIntPref(PORT_PREF);
} catch (e) {}
let port = Preferences.get(PORT_PREF, DEFAULT_PORT);

let s;
try {
Expand Down
1 change: 1 addition & 0 deletions testing/marionette/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const {interfaces: Ci, utils: Cu} = Components;

Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Task.jsm");

Cu.import("chrome://marionette/content/driver.js");
Expand Down
Loading

0 comments on commit d6ec3c7

Please sign in to comment.