Bug 1149618 - Remove SpecialPowers from Marionette, r=dburns

This commit is contained in:
Jonathan Griffin 2015-05-18 16:36:15 -07:00
Родитель d6a44b8e13
Коммит ac2f6d8d6e
18 изменённых файлов: 284 добавлений и 296 удалений

Просмотреть файл

@ -276,9 +276,24 @@ class B2GRemoteAutomation(Automation):
if 'b2g' not in session: if 'b2g' not in session:
raise Exception("bad session value %s returned by start_session" % session) raise Exception("bad session value %s returned by start_session" % session)
if self.context_chrome: self.marionette.set_context(self.marionette.CONTEXT_CHROME)
self.marionette.set_context(self.marionette.CONTEXT_CHROME) self.marionette.execute_script("""
else: 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);
if (!testUtils.hasOwnProperty("specialPowersObserver")) {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
testUtils);
testUtils.specialPowersObserver = new testUtils.SpecialPowersObserver();
testUtils.specialPowersObserver.init();
testUtils.specialPowersObserver._loadFrameScript();
}
""")
if not self.context_chrome:
self.marionette.set_context(self.marionette.CONTEXT_CONTENT) self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
# run the script that starts the tests # run the script that starts the tests

Просмотреть файл

@ -109,8 +109,8 @@ class ResourceUriFileReader:
} }
CODE_OPEN_CHANNEL_BY_URI = ''' CODE_OPEN_CHANNEL_BY_URI = '''
var Cc = SpecialPowers.Cc; var Cc = Components.classes;
var Ci = SpecialPowers.Ci; var Ci = Components.interfaces;
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
global.uri = '%(uri)s'; global.uri = '%(uri)s';
@ -129,8 +129,8 @@ class ResourceUriFileReader:
''' '''
CODE_READ_CONTENT = ''' CODE_READ_CONTENT = '''
var Cc = SpecialPowers.Cc; var Cc = Components.classes;
var Ci = SpecialPowers.Ci; var Ci = Components.interfaces;
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader); var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
var inputStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream); var inputStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
@ -155,7 +155,9 @@ class ResourceUriFileReader:
return cls.URI_PREFIX + cls.URI_PATH[filename] return cls.URI_PREFIX + cls.URI_PATH[filename]
def __init__(self, marionette): def __init__(self, marionette):
self.runjs = lambda x: marionette.execute_script(x, new_sandbox=False) self.runjs = lambda x: marionette.execute_script(x,
new_sandbox=False,
sandbox='system')
def read_file(self, filename): def read_file(self, filename):
"""Read file and return the contents as string.""" """Read file and return the contents as string."""
@ -210,7 +212,9 @@ class JSHintEngine:
for line in config.splitlines()]) for line in config.splitlines()])
# Set global (JSHINT, options, global) in js environment. # Set global (JSHINT, options, global) in js environment.
self.runjs = lambda x: marionette.execute_script(x, new_sandbox=False) self.runjs = lambda x: marionette.execute_script(x,
new_sandbox=False,
sandbox='system')
self.runjs(self.CODE_INIT_JSHINT % self.runjs(self.CODE_INIT_JSHINT %
{'script': script, 'config_string': repr(config)}) {'script': script, 'config_string': repr(config)})

Просмотреть файл

@ -238,8 +238,7 @@ class B2GUpdateTestCase(MarionetteTestCase):
self.print_status(status, os.path.basename(path)) self.print_status(status, os.path.basename(path))
results = self.marionette.execute_async_script(data, results = self.marionette.execute_async_script(data,
script_args=[self.testvars], script_args=[self.testvars])
special_powers=True)
self.handle_results(path, stage, results) self.handle_results(path, stage, results)
def handle_results(self, path, stage, results): def handle_results(self, path, stage, results):

Просмотреть файл

@ -502,6 +502,24 @@ setReq.onerror = function() {
'iframe[src*="app://test-container.gaiamobile.org/index.html"]' 'iframe[src*="app://test-container.gaiamobile.org/index.html"]'
)) ))
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);
if (!testUtils.hasOwnProperty("specialPowersObserver")) {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
testUtils);
testUtils.specialPowersObserver = new testUtils.SpecialPowersObserver();
testUtils.specialPowersObserver.init();
testUtils.specialPowersObserver._loadFrameScript();
}
""")
def run_js_test(self, filename, marionette=None): def run_js_test(self, filename, marionette=None):
''' '''
Run a JavaScript test file and collect its set of assertions Run a JavaScript test file and collect its set of assertions
@ -537,6 +555,23 @@ setReq.onerror = function() {
context = context.group(3) context = context.group(3)
else: else:
context = 'content' context = 'content'
if 'SpecialPowers' in js:
self.setup_SpecialPowers_observer()
if context == 'content':
js = "var SpecialPowers = window.wrappedJSObject.SpecialPowers;\n" + js
else:
marionette.execute_script("""
if (typeof(SpecialPowers) == 'undefined') {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js");
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js");
loader.loadSubScript("chrome://specialpowers/content/ChromePowers.js");
}
""")
marionette.set_context(context) marionette.set_context(context)
if context != 'chrome': if context != 'chrome':
@ -555,7 +590,6 @@ setReq.onerror = function() {
results = marionette.execute_js_script( results = marionette.execute_js_script(
js, js,
args, args,
special_powers=True,
inactivity_timeout=inactivity_timeout, inactivity_timeout=inactivity_timeout,
filename=os.path.basename(filename) filename=os.path.basename(filename)
) )

Просмотреть файл

@ -3,29 +3,31 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
from marionette import MarionetteTestCase from marionette import MarionetteTestCase
from marionette_driver.by import By
class TestGetActiveFrameOOP(MarionetteTestCase): class TestGetActiveFrameOOP(MarionetteTestCase):
def setUp(self): def setUp(self):
super(TestGetActiveFrameOOP, self).setUp() super(TestGetActiveFrameOOP, self).setUp()
self.oop_by_default = self.marionette.execute_script(""" with self.marionette.using_context('chrome'):
try { self.oop_by_default = self.marionette.execute_script("""
return SpecialPowers.getBoolPref('dom.ipc.browser_frames.oop_by_default'); try {
} return Services.prefs.getBoolPref('dom.ipc.browser_frames.oop_by_default');
catch(e) {} }
""") catch(e) {}
self.mozBrowserFramesEnabled = self.marionette.execute_script(""" """)
try { self.mozBrowserFramesEnabled = self.marionette.execute_script("""
return SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled'); try {
} return Services.prefs.getBoolPref('dom.mozBrowserFramesEnabled');
catch(e) {} }
""") catch(e) {}
self.marionette.execute_script(""" """)
SpecialPowers.setBoolPref('dom.ipc.browser_frames.oop_by_default', true); self.marionette.execute_script("""
""") Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', true);
self.marionette.execute_script(""" """)
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true); self.marionette.execute_script("""
""") Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', true);
""")
def test_active_frame_oop(self): def test_active_frame_oop(self):
self.marionette.navigate(self.marionette.absolute_url("test.html")) self.marionette.navigate(self.marionette.absolute_url("test.html"))
@ -34,9 +36,9 @@ class TestGetActiveFrameOOP(MarionetteTestCase):
# Create first OOP frame # Create first OOP frame
self.marionette.execute_script(""" self.marionette.execute_script("""
let iframe1 = document.createElement("iframe"); let iframe1 = document.createElement("iframe");
SpecialPowers.wrap(iframe1).mozbrowser = true;
SpecialPowers.wrap(iframe1).remote = true;
iframe1.id = "remote_iframe1"; iframe1.id = "remote_iframe1";
iframe1.setAttribute('remote', true);
iframe1.setAttribute('mozbrowser', true);
iframe1.style.height = "100px"; iframe1.style.height = "100px";
iframe1.style.width = "100%%"; iframe1.style.width = "100%%";
iframe1.src = "%s"; iframe1.src = "%s";
@ -48,7 +50,8 @@ class TestGetActiveFrameOOP(MarionetteTestCase):
self.assertTrue("test.html" in self.marionette.get_url()) self.assertTrue("test.html" in self.marionette.get_url())
# Switch to iframe1, get active frame # Switch to iframe1, get active frame
self.marionette.switch_to_frame('remote_iframe1') frame = self.marionette.find_element(By.ID, 'remote_iframe1')
self.marionette.switch_to_frame(frame)
active_frame1 = self.marionette.get_active_frame() active_frame1 = self.marionette.get_active_frame()
self.assertNotEqual(active_frame1.id, None) self.assertNotEqual(active_frame1.id, None)
@ -61,8 +64,8 @@ class TestGetActiveFrameOOP(MarionetteTestCase):
self.marionette.switch_to_frame() self.marionette.switch_to_frame()
self.marionette.execute_script(""" self.marionette.execute_script("""
let iframe2 = document.createElement("iframe"); let iframe2 = document.createElement("iframe");
SpecialPowers.wrap(iframe2).mozbrowser = true; iframe2.setAttribute('mozbrowser', true);
SpecialPowers.wrap(iframe2).remote = true; iframe2.setAttribute('remote', true);
iframe2.id = "remote_iframe2"; iframe2.id = "remote_iframe2";
iframe2.style.height = "100px"; iframe2.style.height = "100px";
iframe2.style.width = "100%%"; iframe2.style.width = "100%%";
@ -71,7 +74,8 @@ class TestGetActiveFrameOOP(MarionetteTestCase):
""" % self.marionette.absolute_url("test_oop_2.html")) """ % self.marionette.absolute_url("test_oop_2.html"))
# Switch to iframe2, get active frame # Switch to iframe2, get active frame
self.marionette.switch_to_frame('remote_iframe2') frame2 = self.marionette.find_element(By.ID, 'remote_iframe2')
self.marionette.switch_to_frame(frame2)
active_frame2 = self.marionette.get_active_frame() active_frame2 = self.marionette.get_active_frame()
self.assertNotEqual(active_frame2.id, None) self.assertNotEqual(active_frame2.id, None)
@ -92,19 +96,20 @@ class TestGetActiveFrameOOP(MarionetteTestCase):
# print self.marionette.page_source # print self.marionette.page_source
def tearDown(self): def tearDown(self):
if self.oop_by_default is None: with self.marionette.using_context('chrome'):
self.marionette.execute_script(""" if self.oop_by_default is None:
SpecialPowers.clearUserPref('dom.ipc.browser_frames.oop_by_default'); self.marionette.execute_script("""
""") Services.prefs.clearUserPref('dom.ipc.browser_frames.oop_by_default');
else: """)
self.marionette.execute_script(""" else:
SpecialPowers.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s); self.marionette.execute_script("""
""" % 'true' if self.oop_by_default else 'false') Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s);
if self.mozBrowserFramesEnabled is None: """ % 'true' if self.oop_by_default else 'false')
self.marionette.execute_script(""" if self.mozBrowserFramesEnabled is None:
SpecialPowers.clearUserPref('dom.mozBrowserFramesEnabled'); self.marionette.execute_script("""
""") Services.prefs.clearUserPref('dom.mozBrowserFramesEnabled');
else: """)
self.marionette.execute_script(""" else:
SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', %s); self.marionette.execute_script("""
""" % 'true' if self.mozBrowserFramesEnabled else 'false') Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', %s);
""" % 'true' if self.mozBrowserFramesEnabled else 'false')

Просмотреть файл

@ -17,17 +17,17 @@ class TestImportScript(MarionetteTestCase):
def check_file_exists(self): def check_file_exists(self):
return self.marionette.execute_script(""" return self.marionette.execute_script("""
let FileUtils = SpecialPowers.Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; let FileUtils = Components.utils.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils;
let importedScripts = FileUtils.getFile('TmpD', ['marionetteContentScripts']); let importedScripts = FileUtils.getFile('TmpD', ['marionetteContentScripts']);
return importedScripts.exists(); return importedScripts.exists();
""", special_powers=True) """, sandbox='system')
def get_file_size(self): def get_file_size(self):
return self.marionette.execute_script(""" return self.marionette.execute_script("""
let FileUtils = SpecialPowers.Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; let FileUtils = Components.utils.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils;
let importedScripts = FileUtils.getFile('TmpD', ['marionetteContentScripts']); let importedScripts = FileUtils.getFile('TmpD', ['marionetteContentScripts']);
return importedScripts.fileSize; return importedScripts.fileSize;
""", special_powers=True) """, sandbox='system')
def test_import_script(self): def test_import_script(self):
js = os.path.abspath(os.path.join(__file__, os.path.pardir, "importscript.js")) js = os.path.abspath(os.path.join(__file__, os.path.pardir, "importscript.js"))

Просмотреть файл

@ -10,46 +10,51 @@ class TestLog(MarionetteTestCase):
def setUp(self): def setUp(self):
MarionetteTestCase.setUp(self) MarionetteTestCase.setUp(self)
self.marionette.enforce_gecko_prefs({"marionette.test.bool": True, "marionette.test.string": "testing", "marionette.test.int": 3}) self.marionette.enforce_gecko_prefs({"marionette.test.bool": True, "marionette.test.string": "testing", "marionette.test.int": 3})
self.marionette.set_context('chrome')
def test_preferences_are_set(self): def test_preferences_are_set(self):
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.bool');") bool_value = self.marionette.execute_script("return Services.prefs.getBoolPref('marionette.test.bool');")
string_value = self.marionette.execute_script("return SpecialPowers.getCharPref('marionette.test.string');") string_value = self.marionette.execute_script("return Services.prefs.getCharPref('marionette.test.string');")
int_value = self.marionette.execute_script("return SpecialPowers.getIntPref('marionette.test.int');") int_value = self.marionette.execute_script("return Services.prefs.getIntPref('marionette.test.int');")
self.assertTrue(bool_value) self.assertTrue(bool_value)
self.assertEqual(string_value, "testing") self.assertEqual(string_value, "testing")
self.assertEqual(int_value, 3) self.assertEqual(int_value, 3)
def test_change_preset(self): def test_change_preset(self):
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.bool');") bool_value = self.marionette.execute_script("return Services.prefs.getBoolPref('marionette.test.bool');")
self.assertTrue(bool_value) self.assertTrue(bool_value)
self.marionette.enforce_gecko_prefs({"marionette.test.bool": False}) self.marionette.enforce_gecko_prefs({"marionette.test.bool": False})
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.bool');") self.marionette.set_context('chrome')
bool_value = self.marionette.execute_script("return Services.prefs.getBoolPref('marionette.test.bool');")
self.assertFalse(bool_value) self.assertFalse(bool_value)
def test_clean_profile(self): def test_clean_profile(self):
self.marionette.restart(clean=True) self.marionette.restart(clean=True)
with self.assertRaisesRegexp(JavascriptException, "Error getting pref"): self.marionette.set_context('chrome')
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.bool');") with self.assertRaisesRegexp(JavascriptException, "NS_ERROR_UNEXPECTED"):
bool_value = self.marionette.execute_script("return Services.prefs.getBoolPref('marionette.test.bool');")
def test_can_restart_the_browser(self): def test_can_restart_the_browser(self):
self.marionette.enforce_gecko_prefs({"marionette.test.restart": True}) self.marionette.enforce_gecko_prefs({"marionette.test.restart": True})
self.marionette.restart() self.marionette.restart()
bool_value = self.marionette.execute_script("return SpecialPowers.getBoolPref('marionette.test.restart');") self.marionette.set_context('chrome')
bool_value = self.marionette.execute_script("return Services.prefs.getBoolPref('marionette.test.restart');")
self.assertTrue(bool_value) self.assertTrue(bool_value)
def test_in_app_restart_the_browser(self): def test_in_app_restart_the_browser(self):
self.marionette.execute_script("SpecialPowers.setBoolPref('marionette.test.restart', true);") self.marionette.execute_script("Services.prefs.setBoolPref('marionette.test.restart', true);")
# A "soft" restart initiated inside the application should keep track of this pref. # A "soft" restart initiated inside the application should keep track of this pref.
self.marionette.restart(in_app=True) self.marionette.restart(in_app=True)
self.marionette.set_context('chrome')
bool_value = self.marionette.execute_script(""" bool_value = self.marionette.execute_script("""
return SpecialPowers.getBoolPref('marionette.test.restart'); return Services.prefs.getBoolPref('marionette.test.restart');
""") """)
self.assertTrue(bool_value) self.assertTrue(bool_value)
bool_value = self.marionette.execute_script(""" bool_value = self.marionette.execute_script("""
SpecialPowers.setBoolPref('marionette.test.restart', false); Services.prefs.setBoolPref('marionette.test.restart', false);
return SpecialPowers.getBoolPref('marionette.test.restart'); return Services.prefs.getBoolPref('marionette.test.restart');
""") """)
self.assertFalse(bool_value) self.assertFalse(bool_value)

Просмотреть файл

@ -1,35 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
from marionette import MarionetteTestCase
class TestSpecialPowersContent(MarionetteTestCase):
testpref = "testing.marionette.contentcharpref"
testvalue = "blabla"
def test_prefs(self):
result = self.marionette.execute_script("""
SpecialPowers.setCharPref("%(pref)s", "%(value)s");
return SpecialPowers.getCharPref("%(pref)s")
""" % {'pref': self.testpref, 'value': self.testvalue}, special_powers=True);
self.assertEqual(result, self.testvalue)
def test_prefs_after_navigate(self):
test_html = self.marionette.absolute_url("test.html")
self.marionette.navigate(test_html)
self.test_prefs()
class TestSpecialPowersChrome(TestSpecialPowersContent):
testpref = "testing.marionette.chromecharpref"
testvalue = "blabla"
def setUp(self):
super(TestSpecialPowersChrome, self).setUp()
self.marionette.set_context("chrome")
def test_prefs_after_navigate(self):
pass

Просмотреть файл

@ -8,22 +8,24 @@ from marionette import MarionetteTestCase
class TestSwitchRemoteFrame(MarionetteTestCase): class TestSwitchRemoteFrame(MarionetteTestCase):
def setUp(self): def setUp(self):
super(TestSwitchRemoteFrame, self).setUp() super(TestSwitchRemoteFrame, self).setUp()
self.oop_by_default = self.marionette.execute_script("""
try {
return SpecialPowers.getBoolPref('dom.ipc.browser_frames.oop_by_default');
}
catch(e) {}
""")
self.mozBrowserFramesEnabled = self.marionette.execute_script("""
try {
return SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
}
catch(e) {}
""")
self.marionette.execute_async_script(
'SpecialPowers.pushPrefEnv({"set": [["dom.ipc.browser_frames.oop_by_default", true], ["dom.mozBrowserFramesEnabled", true]]}, marionetteScriptFinished);')
with self.marionette.using_context('chrome'): 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.multi_process_browser = self.marionette.execute_script(""" self.multi_process_browser = self.marionette.execute_script("""
try { try {
return Services.appinfo.browserTabsRemoteAutostart; return Services.appinfo.browserTabsRemoteAutostart;
@ -31,13 +33,20 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
return false; return false;
}""") }""")
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')
def test_remote_frame(self): def test_remote_frame(self):
self.marionette.navigate(self.marionette.absolute_url("test.html")) self.marionette.navigate(self.marionette.absolute_url("test.html"))
self.marionette.push_permission('browser', True) self.marionette.push_permission('browser', True)
self.marionette.execute_script(""" self.marionette.execute_script("""
let iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
SpecialPowers.wrap(iframe).mozbrowser = true; iframe.setAttribute('mozbrowser', true);
SpecialPowers.wrap(iframe).remote = true; iframe.setAttribute('remote', true);
iframe.id = "remote_iframe"; iframe.id = "remote_iframe";
iframe.style.height = "100px"; iframe.style.height = "100px";
iframe.style.width = "100%%"; iframe.style.width = "100%%";
@ -46,9 +55,7 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
""" % self.marionette.absolute_url("test.html")) """ % self.marionette.absolute_url("test.html"))
remote_iframe = self.marionette.find_element("id", "remote_iframe") remote_iframe = self.marionette.find_element("id", "remote_iframe")
self.marionette.switch_to_frame(remote_iframe) self.marionette.switch_to_frame(remote_iframe)
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
self.assertFalse(main_process) self.assertFalse(main_process)
def test_remote_frame_revisit(self): def test_remote_frame_revisit(self):
@ -57,8 +64,8 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
self.marionette.push_permission('browser', True) self.marionette.push_permission('browser', True)
self.marionette.execute_script(""" self.marionette.execute_script("""
let iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
SpecialPowers.wrap(iframe).mozbrowser = true; iframe.setAttribute('mozbrowser', true);
SpecialPowers.wrap(iframe).remote = true; iframe.setAttribute('remote', true);
iframe.id = "remote_iframe"; iframe.id = "remote_iframe";
iframe.style.height = "100px"; iframe.style.height = "100px";
iframe.style.width = "100%%"; iframe.style.width = "100%%";
@ -67,21 +74,15 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
""" % self.marionette.absolute_url("test.html")) """ % self.marionette.absolute_url("test.html"))
self.marionette.switch_to_frame(self.marionette.find_element("id", self.marionette.switch_to_frame(self.marionette.find_element("id",
"remote_iframe")) "remote_iframe"))
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
self.assertFalse(main_process) self.assertFalse(main_process)
self.marionette.switch_to_frame() self.marionette.switch_to_frame()
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
should_be_main_process = not self.multi_process_browser should_be_main_process = not self.multi_process_browser
self.assertEqual(main_process, should_be_main_process) self.assertEqual(main_process, should_be_main_process)
self.marionette.switch_to_frame(self.marionette.find_element("id", self.marionette.switch_to_frame(self.marionette.find_element("id",
"remote_iframe")) "remote_iframe"))
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
self.assertFalse(main_process) self.assertFalse(main_process)
def test_we_can_switch_to_a_remote_frame_by_index(self): def test_we_can_switch_to_a_remote_frame_by_index(self):
@ -90,8 +91,8 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
self.marionette.push_permission('browser', True) self.marionette.push_permission('browser', True)
self.marionette.execute_script(""" self.marionette.execute_script("""
let iframe = document.createElement("iframe"); let iframe = document.createElement("iframe");
SpecialPowers.wrap(iframe).mozbrowser = true; iframe.setAttribute('mozbrowser', true);
SpecialPowers.wrap(iframe).remote = true; iframe.setAttribute('remote', true);
iframe.id = "remote_iframe"; iframe.id = "remote_iframe";
iframe.style.height = "100px"; iframe.style.height = "100px";
iframe.style.width = "100%%"; iframe.style.width = "100%%";
@ -99,36 +100,31 @@ class TestSwitchRemoteFrame(MarionetteTestCase):
document.body.appendChild(iframe); document.body.appendChild(iframe);
""" % self.marionette.absolute_url("test.html")) """ % self.marionette.absolute_url("test.html"))
self.marionette.switch_to_frame(0) self.marionette.switch_to_frame(0)
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
self.assertFalse(main_process) self.assertFalse(main_process)
self.marionette.switch_to_frame() self.marionette.switch_to_frame()
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
should_be_main_process = not self.multi_process_browser should_be_main_process = not self.multi_process_browser
self.assertEqual(main_process, should_be_main_process) self.assertEqual(main_process, should_be_main_process)
self.marionette.switch_to_frame(0) self.marionette.switch_to_frame(0)
main_process = self.marionette.execute_script(""" main_process = self.is_main_process()
return SpecialPowers.isMainProcess();
""")
self.assertFalse(main_process) self.assertFalse(main_process)
def tearDown(self): def tearDown(self):
if self.oop_by_default is None: with self.marionette.using_context('chrome'):
self.marionette.execute_script(""" if self.oop_by_default is None:
SpecialPowers.clearUserPref('dom.ipc.browser_frames.oop_by_default'); self.marionette.execute_script("""
""") Services.prefs.clearUserPref('dom.ipc.browser_frames.oop_by_default');
else: """)
self.marionette.execute_async_script( else:
'SpecialPowers.pushPrefEnv({"set": [["dom.ipc.browser_frames.oop_by_default", %s]]}, marionetteScriptFinished);' % self.marionette.execute_async_script(
('true' if self.oop_by_default else 'false')) "Services.prefs.setBoolPref('dom.ipc.browser_frames.oop_by_default', %s);" %
if self.mozBrowserFramesEnabled is None: ('true' if self.oop_by_default else 'false'))
self.marionette.execute_script(""" if self.mozBrowserFramesEnabled is None:
SpecialPowers.clearUserPref('dom.mozBrowserFramesEnabled'); self.marionette.execute_script("""
""") Services.prefs.clearUserPref('dom.mozBrowserFramesEnabled');
else: """)
self.marionette.execute_async_script( else:
'SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", %s]]}, marionetteScriptFinished);' % self.marionette.execute_async_script(
('true' if self.mozBrowserFramesEnabled else 'false')) "Services.prefs.setBoolPref('dom.mozBrowserFramesEnabled', %s);" %
('true' if self.mozBrowserFramesEnabled else 'false'))

Просмотреть файл

@ -94,7 +94,6 @@ browser = false
[test_simpletest_sanity.py] [test_simpletest_sanity.py]
[test_simpletest_chrome.js] [test_simpletest_chrome.js]
[test_simpletest_timeout.js] [test_simpletest_timeout.js]
[test_specialpowers.py]
[test_anonymous_content.py] [test_anonymous_content.py]
b2g = false b2g = false
[test_switch_frame.py] [test_switch_frame.py]

Просмотреть файл

@ -45,7 +45,6 @@ this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
const FRAME_SCRIPT = "chrome://marionette/content/listener.js"; const FRAME_SCRIPT = "chrome://marionette/content/listener.js";
const BROWSER_STARTUP_FINISHED = "browser-delayed-startup-finished"; const BROWSER_STARTUP_FINISHED = "browser-delayed-startup-finished";
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const SECURITY_PREF = "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer";
const CLICK_TO_START_PREF = "marionette.debugging.clicktostart"; const CLICK_TO_START_PREF = "marionette.debugging.clicktostart";
const CONTENT_LISTENER_PREF = "marionette.contentListener"; const CONTENT_LISTENER_PREF = "marionette.contentListener";
@ -53,7 +52,6 @@ const logger = Log.repository.getLogger("Marionette");
const uuidGen = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); const uuidGen = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
const globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"] const globalMessageManager = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageBroadcaster); .getService(Ci.nsIMessageBroadcaster);
let specialpowers = {};
// This is used to prevent newSession from returning before the telephony // This is used to prevent newSession from returning before the telephony
// API's are ready; see bug 792647. This assumes that marionette-server.js // API's are ready; see bug 792647. This assumes that marionette-server.js
@ -130,7 +128,6 @@ this.GeckoDriver = function(appName, device, emulator) {
this.currentFrameElement = null; this.currentFrameElement = null;
this.testName = null; this.testName = null;
this.mozBrowserClose = null; this.mozBrowserClose = null;
this.enabled_security_pref = false;
this.sandboxes = {}; this.sandboxes = {};
// frame ID of the current remote frame, used for mozbrowserclose events // frame ID of the current remote frame, used for mozbrowserclose events
this.oopFrameId = null; this.oopFrameId = null;
@ -510,25 +507,6 @@ GeckoDriver.prototype.newSession = function(cmd, resp) {
this.setSessionCapabilities(cmd.parameters.capabilities); this.setSessionCapabilities(cmd.parameters.capabilities);
this.scriptTimeout = 10000; this.scriptTimeout = 10000;
// SpecialPowers requires insecure automation-only features that we
// put behind a pref
let sec = false;
try {
sec = Services.prefs.getBoolPref(SECURITY_PREF);
} catch (e) {}
if (!sec) {
this.enabled_security_pref = true;
Services.prefs.setBoolPref(SECURITY_PREF, true);
}
if (!specialpowers.hasOwnProperty("specialPowersObserver")) {
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
specialpowers);
specialpowers.specialPowersObserver = new specialpowers.SpecialPowersObserver();
specialpowers.specialPowersObserver.init();
specialpowers.specialPowersObserver._loadFrameScript();
}
let registerBrowsers = this.registerPromise(); let registerBrowsers = this.registerPromise();
let browserListening = this.listeningPromise(); let browserListening = this.listeningPromise();
@ -705,15 +683,14 @@ GeckoDriver.prototype.getContext = function(cmd, resp) {
* Window in which we will execute code. * Window in which we will execute code.
* @param {Marionette} mn * @param {Marionette} mn
* Marionette test instance. * Marionette test instance.
* @param {Object} args * @param {string} sandboxName
* Arguments given by client. * The name for the sandbox. If 'system', create the sandbox
* @param {boolean} sp * with elevated privileges.
* True to enable special powers in the sandbox, false not to.
* *
* @return {nsIXPCComponents_utils_Sandbox} * @return {nsIXPCComponents_utils_Sandbox}
* Returns the sandbox. * Returns the sandbox.
*/ */
GeckoDriver.prototype.createExecuteSandbox = function(win, mn, sp, sandboxName) { GeckoDriver.prototype.createExecuteSandbox = function(win, mn, sandboxName) {
let principal = win; let principal = win;
if (sandboxName == 'system') { if (sandboxName == 'system') {
principal = Cc["@mozilla.org/systemprincipal;1"]. principal = Cc["@mozilla.org/systemprincipal;1"].
@ -735,15 +712,6 @@ GeckoDriver.prototype.createExecuteSandbox = function(win, mn, sp, sandboxName)
sb.isSystemMessageListenerReady = () => systemMessageListenerReady; sb.isSystemMessageListenerReady = () => systemMessageListenerReady;
if (sp) {
let pow = [
"chrome://specialpowers/content/specialpowersAPI.js",
"chrome://specialpowers/content/SpecialPowersObserverAPI.js",
"chrome://specialpowers/content/ChromePowers.js",
];
pow.map(s => loader.loadSubScript(s, sb));
}
this.sandboxes[sandboxName] = sb; this.sandboxes[sandboxName] = sb;
}; };
@ -821,7 +789,6 @@ GeckoDriver.prototype.execute = function(cmd, resp, directInject) {
script, script,
newSandbox, newSandbox,
args, args,
specialPowers,
filename, filename,
line} = cmd.parameters; line} = cmd.parameters;
let sandboxName = cmd.parameters.sandbox || 'default'; let sandboxName = cmd.parameters.sandbox || 'default';
@ -839,7 +806,6 @@ GeckoDriver.prototype.execute = function(cmd, resp, directInject) {
args: args, args: args,
newSandbox: newSandbox, newSandbox: newSandbox,
timeout: scriptTimeout, timeout: scriptTimeout,
specialPowers: specialPowers,
filename: filename, filename: filename,
line: line, line: line,
sandboxName: sandboxName sandboxName: sandboxName
@ -880,7 +846,6 @@ GeckoDriver.prototype.execute = function(cmd, resp, directInject) {
this.createExecuteSandbox( this.createExecuteSandbox(
win, win,
marionette, marionette,
specialPowers,
sandboxName); sandboxName);
if (!this.sandboxes[sandboxName]) { if (!this.sandboxes[sandboxName]) {
return; return;
@ -957,7 +922,6 @@ GeckoDriver.prototype.executeJSScript = function(cmd, resp) {
timeout: cmd.parameters.scriptTimeout ? timeout: cmd.parameters.scriptTimeout ?
cmd.parameters.scriptTimeout : this.scriptTimeout, cmd.parameters.scriptTimeout : this.scriptTimeout,
inactivityTimeout: cmd.parameters.inactivityTimeout, inactivityTimeout: cmd.parameters.inactivityTimeout,
specialPowers: cmd.parameters.specialPowers,
filename: cmd.parameters.filename, filename: cmd.parameters.filename,
line: cmd.parameters.line, line: cmd.parameters.line,
sandboxName: cmd.parameters.sandbox || 'default', sandboxName: cmd.parameters.sandbox || 'default',
@ -987,7 +951,6 @@ GeckoDriver.prototype.executeWithCallback = function(cmd, resp, directInject) {
newSandbox, newSandbox,
inactivityTimeout, inactivityTimeout,
scriptTimeout, scriptTimeout,
specialPowers,
filename, filename,
line} = cmd.parameters; line} = cmd.parameters;
let sandboxName = cmd.parameters.sandbox || 'default'; let sandboxName = cmd.parameters.sandbox || 'default';
@ -1007,7 +970,6 @@ GeckoDriver.prototype.executeWithCallback = function(cmd, resp, directInject) {
newSandbox: newSandbox, newSandbox: newSandbox,
timeout: scriptTimeout, timeout: scriptTimeout,
inactivityTimeout: inactivityTimeout, inactivityTimeout: inactivityTimeout,
specialPowers: specialPowers,
filename: filename, filename: filename,
line: line, line: line,
sandboxName: sandboxName, sandboxName: sandboxName,
@ -1085,8 +1047,7 @@ GeckoDriver.prototype.executeWithCallback = function(cmd, resp, directInject) {
scriptTimeout, scriptTimeout,
this.heartbeatCallback, this.heartbeatCallback,
this.testName); this.testName);
this.createExecuteSandbox(win, marionette, this.createExecuteSandbox(win, marionette, sandboxName);
specialPowers, sandboxName);
} }
if (!this.sandboxes[sandboxName]) { if (!this.sandboxes[sandboxName]) {
return; return;
@ -2439,7 +2400,6 @@ GeckoDriver.prototype.sessionTearDown = function(cmd, resp) {
winEn.getNext().messageManager.removeDelayedFrameScript(FRAME_SCRIPT); winEn.getNext().messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
} }
this.curBrowser.frameManager.removeSpecialPowers();
this.curBrowser.frameManager.removeMessageManagerListeners( this.curBrowser.frameManager.removeMessageManagerListeners(
globalMessageManager); globalMessageManager);
} }
@ -2879,6 +2839,23 @@ GeckoDriver.prototype.receiveMessage = function(message) {
false); false);
return true; return true;
case "Marionette:getFiles":
// Generates file objects to send back to the content script
// for handling file uploads.
let val = message.json.value;
let command_id = message.json.command_id;
Cu.importGlobalProperties(["File"]);
try {
let file = new File(val);
this.sendAsync("receiveFiles",
{file: file, command_id: command_id});
} catch (e) {
let err = `File not found: ${val}`;
this.sendAsync("receiveFiles",
{error: err, command_id: command_id});
}
break;
case "Marionette:emitTouchEvent": case "Marionette:emitTouchEvent":
globalMessageManager.broadcastAsyncMessage( globalMessageManager.broadcastAsyncMessage(
"MarionetteMainListener:emitTouchEvent", message.json); "MarionetteMainListener:emitTouchEvent", message.json);

Просмотреть файл

@ -1401,9 +1401,9 @@ class Marionette(object):
return unwrapped return unwrapped
def execute_js_script(self, script, script_args=None, async=True, def execute_js_script(self, script, script_args=None, async=True,
new_sandbox=True, special_powers=False, new_sandbox=True, script_timeout=None,
script_timeout=None, inactivity_timeout=None, inactivity_timeout=None, filename=None,
filename=None, sandbox='default'): sandbox='default'):
if script_args is None: if script_args is None:
script_args = [] script_args = []
args = self.wrapArguments(script_args) args = self.wrapArguments(script_args)
@ -1413,7 +1413,6 @@ class Marionette(object):
args=args, args=args,
async=async, async=async,
newSandbox=new_sandbox, newSandbox=new_sandbox,
specialPowers=special_powers,
scriptTimeout=script_timeout, scriptTimeout=script_timeout,
inactivityTimeout=inactivity_timeout, inactivityTimeout=inactivity_timeout,
filename=filename, filename=filename,
@ -1421,7 +1420,7 @@ class Marionette(object):
return self.unwrapValue(response) return self.unwrapValue(response)
def execute_script(self, script, script_args=None, new_sandbox=True, def execute_script(self, script, script_args=None, new_sandbox=True,
special_powers=False, sandbox='default', script_timeout=None): sandbox='default', script_timeout=None):
''' '''
Executes a synchronous JavaScript script, and returns the result (or None if the script does return a value). Executes a synchronous JavaScript script, and returns the result (or None if the script does return a value).
@ -1431,11 +1430,6 @@ class Marionette(object):
:param script: A string containing the JavaScript to execute. :param script: A string containing the JavaScript to execute.
:param script_args: A list of arguments to pass to the script. :param script_args: A list of arguments to pass to the script.
:param special_powers: Whether or not you want access to SpecialPowers
in your script. Set to False by default because it shouldn't really
be used, since you already have access to chrome-level commands if you
set context to chrome and do an execute_script. This method was added
only to help us run existing Mochitests.
:param sandbox: A tag referring to the sandbox you wish to use; if :param sandbox: A tag referring to the sandbox you wish to use; if
you specify a new tag, a new sandbox will be created. If you use the you specify a new tag, a new sandbox will be created. If you use the
special tag 'system', the sandbox will be created using the system special tag 'system', the sandbox will be created using the system
@ -1498,7 +1492,6 @@ class Marionette(object):
args=args, args=args,
newSandbox=new_sandbox, newSandbox=new_sandbox,
sandbox=sandbox, sandbox=sandbox,
specialPowers=special_powers,
scriptTimeout=script_timeout, scriptTimeout=script_timeout,
line=int(frame[1]), line=int(frame[1]),
filename=os.path.basename(frame[0])) filename=os.path.basename(frame[0]))
@ -1506,7 +1499,7 @@ class Marionette(object):
def execute_async_script(self, script, script_args=None, new_sandbox=True, def execute_async_script(self, script, script_args=None, new_sandbox=True,
sandbox='default', script_timeout=None, sandbox='default', script_timeout=None,
special_powers=False, debug_script=False): debug_script=False):
''' '''
Executes an asynchronous JavaScript script, and returns the result (or None if the script does return a value). Executes an asynchronous JavaScript script, and returns the result (or None if the script does return a value).
@ -1516,11 +1509,6 @@ class Marionette(object):
:param script: A string containing the JavaScript to execute. :param script: A string containing the JavaScript to execute.
:param script_args: A list of arguments to pass to the script. :param script_args: A list of arguments to pass to the script.
:param special_powers: Whether or not you want access to SpecialPowers
in your script. Set to False by default because it shouldn't really
be used, since you already have access to chrome-level commands if you
set context to chrome and do an execute_script. This method was added
only to help us run existing Mochitests.
:param sandbox: A tag referring to the sandbox you wish to use; if :param sandbox: A tag referring to the sandbox you wish to use; if
you specify a new tag, a new sandbox will be created. If you use the you specify a new tag, a new sandbox will be created. If you use the
special tag 'system', the sandbox will be created using the system special tag 'system', the sandbox will be created using the system
@ -1555,7 +1543,6 @@ class Marionette(object):
args=args, args=args,
newSandbox=new_sandbox, newSandbox=new_sandbox,
sandbox=sandbox, sandbox=sandbox,
specialPowers=special_powers,
scriptTimeout=script_timeout, scriptTimeout=script_timeout,
line=int(frame[1]), line=int(frame[1]),
filename=os.path.basename(frame[0]), filename=os.path.basename(frame[0]),

Просмотреть файл

@ -37,8 +37,7 @@ class SelectionManager(object):
if self._input_or_textarea(): if self._input_or_textarea():
# We must unwrap sel so that DOMRect could be returned to Python # We must unwrap sel so that DOMRect could be returned to Python
# side. # side.
return '''var sel = SpecialPowers.wrap(arguments[0]).editor.selection; return '''var sel = arguments[0].editor.selection;'''
sel = SpecialPowers.unwrap(sel);'''
else: else:
return '''var sel = window.getSelection();''' return '''var sel = window.getSelection();'''
@ -50,7 +49,8 @@ class SelectionManager(object):
for i in range(offset): for i in range(offset):
self.element.marionette.execute_script( self.element.marionette.execute_script(
cmd, script_args=[self.element, direction]) cmd, script_args=[self.element, direction],
sandbox='system')
def move_caret_to_front(self): def move_caret_to_front(self):
'''Move caret in the element to the front of the content.''' '''Move caret in the element to the front of the content.'''
@ -83,13 +83,17 @@ class SelectionManager(object):
''' '''
cmd = self.js_selection_cmd() +\ cmd = self.js_selection_cmd() +\
'''return sel.getRangeAt(%d).getClientRects();''' % idx '''return sel.getRangeAt(%d).getClientRects();''' % idx
return self.element.marionette.execute_script(cmd, script_args=[self.element]) return self.element.marionette.execute_script(cmd,
script_args=[self.element],
sandbox='system')
def range_count(self): def range_count(self):
'''Get selection's range count''' '''Get selection's range count'''
cmd = self.js_selection_cmd() +\ cmd = self.js_selection_cmd() +\
'''return sel.rangeCount;''' '''return sel.rangeCount;'''
return self.element.marionette.execute_script(cmd, script_args=[self.element]) return self.element.marionette.execute_script(cmd,
script_args=[self.element],
sandbox='system')
def _selection_location_helper(self, location_type): def _selection_location_helper(self, location_type):
'''Return the start and end location of the selection in the element. '''Return the start and end location of the selection in the element.
@ -200,4 +204,6 @@ class SelectionManager(object):
'''Return the selected portion of the content in the element.''' '''Return the selected portion of the content in the element.'''
cmd = self.js_selection_cmd() +\ cmd = self.js_selection_cmd() +\
'''return sel.toString();''' '''return sel.toString();'''
return self.element.marionette.execute_script(cmd, script_args=[self.element]) return self.element.marionette.execute_script(cmd,
script_args=[self.element],
sandbox='system')

Просмотреть файл

@ -13,7 +13,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader); .getService(Ci.mozIJSSubScriptLoader);
let specialpowers = {};
//list of OOP frames that has the frame script loaded //list of OOP frames that has the frame script loaded
let remoteFrames = []; let remoteFrames = [];
@ -120,11 +119,6 @@ FrameManager.prototype = {
let oopFrame = this.getOopFrame(winId, frameId); let oopFrame = this.getOopFrame(winId, frameId);
let mm = this.getFrameMM(winId, frameId); let mm = this.getFrameMM(winId, frameId);
if (!specialpowers.hasOwnProperty("specialPowersObserver")) {
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
specialpowers);
}
// See if this frame already has our frame script loaded in it; // See if this frame already has our frame script loaded in it;
// if so, just wake it up. // if so, just wake it up.
for (let i = 0; i < remoteFrames.length; i++) { for (let i = 0; i < remoteFrames.length; i++) {
@ -142,11 +136,6 @@ FrameManager.prototype = {
this.currentRemoteFrame = frame; this.currentRemoteFrame = frame;
this.addMessageManagerListeners(mm); this.addMessageManagerListeners(mm);
if (!frame.specialPowersObserver) {
frame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
frame.specialPowersObserver.init(mm);
}
mm.sendAsyncMessage("Marionette:restart"); mm.sendAsyncMessage("Marionette:restart");
return oopFrame.id; return oopFrame.id;
} }
@ -163,9 +152,6 @@ FrameManager.prototype = {
mm.loadFrameScript(FRAME_SCRIPT, true, true); mm.loadFrameScript(FRAME_SCRIPT, true, true);
aFrame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
aFrame.specialPowersObserver.init(mm);
return oopFrame.id; return oopFrame.id;
}, },
@ -182,20 +168,6 @@ FrameManager.prototype = {
this.handledModal = false; this.handledModal = false;
}, },
/**
* This function removes any SpecialPowersObservers from OOP frames.
*/
removeSpecialPowers: function FM_removeSpecialPowers() {
for (let i = 0; i < remoteFrames.length; i++) {
let frame = remoteFrames[i];
if (frame.specialPowersObserver) {
frame.specialPowersObserver.uninit();
frame.specialPowersObserver = null;
}
}
},
/** /**
* Adds message listeners to the server, * Adds message listeners to the server,
* listening for messages from content frame scripts. * listening for messages from content frame scripts.
@ -220,6 +192,7 @@ FrameManager.prototype = {
mm.addWeakMessageListener("Marionette:deleteCookie", this.server); mm.addWeakMessageListener("Marionette:deleteCookie", this.server);
mm.addWeakMessageListener("Marionette:register", this.server); mm.addWeakMessageListener("Marionette:register", this.server);
mm.addWeakMessageListener("Marionette:listenersAttached", this.server); mm.addWeakMessageListener("Marionette:listenersAttached", this.server);
mm.addWeakMessageListener("Marionette:getFiles", this.server);
mm.addWeakMessageListener("MarionetteFrame:handleModal", this); mm.addWeakMessageListener("MarionetteFrame:handleModal", this);
mm.addWeakMessageListener("MarionetteFrame:getCurrentFrameId", this); mm.addWeakMessageListener("MarionetteFrame:getCurrentFrameId", this);
mm.addWeakMessageListener("MarionetteFrame:getInterruptedState", this); mm.addWeakMessageListener("MarionetteFrame:getInterruptedState", this);
@ -248,6 +221,7 @@ FrameManager.prototype = {
mm.removeWeakMessageListener("Marionette:deleteCookie", this.server); mm.removeWeakMessageListener("Marionette:deleteCookie", this.server);
mm.removeWeakMessageListener("Marionette:listenersAttached", this.server); mm.removeWeakMessageListener("Marionette:listenersAttached", this.server);
mm.removeWeakMessageListener("Marionette:register", this.server); mm.removeWeakMessageListener("Marionette:register", this.server);
mm.removeWeakMessageListener("Marionette:getFiles", this.server);
mm.removeWeakMessageListener("MarionetteFrame:handleModal", this); mm.removeWeakMessageListener("MarionetteFrame:handleModal", this);
mm.removeWeakMessageListener("MarionetteFrame:getCurrentFrameId", this); mm.removeWeakMessageListener("MarionetteFrame:getCurrentFrameId", this);
} }

Просмотреть файл

@ -27,9 +27,6 @@ loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
loader.loadSubScript("chrome://marionette/content/atoms.js", utils); loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
loader.loadSubScript("chrome://marionette/content/sendkeys.js", utils); loader.loadSubScript("chrome://marionette/content/sendkeys.js", utils);
loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js");
loader.loadSubScript("chrome://specialpowers/content/specialpowers.js");
let marionetteLogObj = new MarionetteLogObj(); let marionetteLogObj = new MarionetteLogObj();
let isB2G = false; let isB2G = false;
@ -46,6 +43,10 @@ let accessibility = new Accessibility();
let actions = new ActionChain(utils, checkForInterrupted); let actions = new ActionChain(utils, checkForInterrupted);
let importedScripts = null; let importedScripts = null;
// Contains the last file input element that was the target of
// sendKeysToElement.
let fileInputElement;
// A dict of sandboxes used this session // A dict of sandboxes used this session
let sandboxes = {}; let sandboxes = {};
// The name of the current sandbox // The name of the current sandbox
@ -196,6 +197,7 @@ let isElementEnabledFn = dispatch(isElementEnabled);
* Start all message listeners * Start all message listeners
*/ */
function startListeners() { function startListeners() {
addMessageListenerId("Marionette:receiveFiles", receiveFiles);
addMessageListenerId("Marionette:newSession", newSession); addMessageListenerId("Marionette:newSession", newSession);
addMessageListenerId("Marionette:executeScript", executeScript); addMessageListenerId("Marionette:executeScript", executeScript);
addMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript); addMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript);
@ -300,6 +302,7 @@ function restart(msg) {
* Removes all listeners * Removes all listeners
*/ */
function deleteSession(msg) { function deleteSession(msg) {
removeMessageListenerId("Marionette:receiveFiles", receiveFiles);
removeMessageListenerId("Marionette:newSession", newSession); removeMessageListenerId("Marionette:newSession", newSession);
removeMessageListenerId("Marionette:executeScript", executeScript); removeMessageListenerId("Marionette:executeScript", executeScript);
removeMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript); removeMessageListenerId("Marionette:executeAsyncScript", executeAsyncScript);
@ -487,14 +490,6 @@ function createExecuteContentSandbox(win, timeout) {
} }
}); });
let specialPowersFn;
if (typeof win.wrappedJSObject.SpecialPowers != "undefined") {
specialPowersFn = () => win.wrappedJSObject.SpecialPowers;
} else {
specialPowersFn = () => new SpecialPowers(win);
}
XPCOMUtils.defineLazyGetter(sandbox, "SpecialPowers", specialPowersFn);
sandbox.asyncComplete = (obj, id) => { sandbox.asyncComplete = (obj, id) => {
if (id == asyncTestCommandId) { if (id == asyncTestCommandId) {
curFrame.removeEventListener("unload", onunload, false); curFrame.removeEventListener("unload", onunload, false);
@ -650,6 +645,28 @@ function executeAsyncScript(msg) {
executeWithCallback(msg); executeWithCallback(msg);
} }
/**
* Receive file objects from chrome in order to complete a
* sendKeysToElement action on a file input element.
*/
function receiveFiles(msg) {
if ('error' in msg.json) {
let err = new InvalidArgumentError(msg.json.error);
sendError(err, msg.json.command_id);
return;
}
if (!fileInputElement) {
let err = new InvalidElementStateError("receiveFiles called with no valid fileInputElement");
sendError(err, msg.json.command_id);
return;
}
let fs = Array.prototype.slice.call(fileInputElement.files);
fs.push(msg.json.file);
fileInputElement.mozSetFileArray(fs);
fileInputElement = null;
sendOk(msg.json.command_id);
}
/** /**
* Execute pure JS test. Handles both async and sync cases. * Execute pure JS test. Handles both async and sync cases.
*/ */
@ -1537,31 +1554,12 @@ function sendKeysToElement(msg) {
let el = elementManager.getKnownElement(msg.json.id, curFrame); let el = elementManager.getKnownElement(msg.json.id, curFrame);
if (el.type == "file") { if (el.type == "file") {
let p = val.join(""); let p = val.join("");
fileInputElement = el;
// for some reason using mozSetFileArray doesn't work with e10s // In e10s, we can only construct File objects in the parent process,
// enabled (probably a bug), but a workaround is to elevate the element's // so pass the filename to driver.js, which in turn passes them back
// privileges with SpecialPowers // to this frame script in receiveFiles.
// sendSyncMessage("Marionette:getFiles",
// this extra branch can be removed when the e10s bug 1149998 is fixed {value: p, command_id: command_id});
if (isRemoteBrowser()) {
let fs = Array.prototype.slice.call(el.files);
let file;
try {
file = new File(p);
} catch (e) {
let err = new InvalidArgumentError(`File not found: ${val}`);
sendError(err, command_id);
return;
}
fs.push(file);
let wel = new SpecialPowers(utils.window).wrap(el);
wel.mozSetFileArray(fs);
} else {
sendSyncMessage("Marionette:setElementValue", {value: p}, {element: el});
}
sendOk(command_id);
} else { } else {
utils.sendKeysToElement(curFrame, el, val, sendOk, sendError, command_id); utils.sendKeysToElement(curFrame, el, val, sendOk, sendError, command_id);
} }

Просмотреть файл

@ -29,7 +29,6 @@ loader.loadSubScript("chrome://marionette/content/frame-manager.js");
const logger = Log.repository.getLogger("Marionette"); const logger = Log.repository.getLogger("Marionette");
this.EXPORTED_SYMBOLS = ["MarionetteServer"]; this.EXPORTED_SYMBOLS = ["MarionetteServer"];
const SPECIAL_POWERS_PREF = "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer";
const CONTENT_LISTENER_PREF = "marionette.contentListener"; const CONTENT_LISTENER_PREF = "marionette.contentListener";
/** /**

Просмотреть файл

@ -29,6 +29,10 @@ if (cm) {
cm.deleteCategoryEntry("update-timer", "nsUpdateService", false); cm.deleteCategoryEntry("update-timer", "nsUpdateService", false);
} }
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);
function openWindow(aEvent) { function openWindow(aEvent) {
var popupIframe = aEvent.detail.frameElement; var popupIframe = aEvent.detail.frameElement;
popupIframe.id = 'popupiframe'; popupIframe.id = 'popupiframe';
@ -97,6 +101,11 @@ if (outOfProcess) {
if (chrome) { if (chrome) {
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
if (typeof(SpecialPowers) == 'undefined') {
loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js");
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserverAPI.js");
loader.loadSubScript("chrome://specialpowers/content/ChromePowers.js");
}
loader.loadSubScript("chrome://mochikit/content/browser-test.js"); loader.loadSubScript("chrome://mochikit/content/browser-test.js");
b2gStart(); b2gStart();
} }

Просмотреть файл

@ -220,6 +220,22 @@ class B2GMochitest(MochitestUtilsMixin):
Services.io.offline = false; Services.io.offline = false;
""") """)
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);
if (!testUtils.hasOwnProperty("specialPowersObserver")) {
let loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
testUtils);
testUtils.specialPowersObserver = new testUtils.SpecialPowersObserver();
testUtils.specialPowersObserver.init();
testUtils.specialPowersObserver._loadFrameScript();
}
""")
if options.chrome: if options.chrome:
self.app_ctx.dm.removeDir(self.remote_chrome_test_dir) self.app_ctx.dm.removeDir(self.remote_chrome_test_dir)
self.app_ctx.dm.mkDir(self.remote_chrome_test_dir) self.app_ctx.dm.mkDir(self.remote_chrome_test_dir)