mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1239330 - Support AddonManager.installTemporaryAddon() in marionette_driver.addons, r=ato
--HG-- rename : testing/marionette/client/marionette/tests/unit/mn-restartless.xpi => testing/marionette/client/marionette/tests/unit/mn-restartless-unsigned.xpi extra : rebase_source : a4ba2b7dfb756351a47d1115b9ae5f06da2a86ac
This commit is contained in:
parent
2d14b15428
commit
c6253e4e20
@ -3,6 +3,7 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from marionette import MarionetteTestCase
|
||||
from marionette_driver.addons import Addons, AddonInstallException
|
||||
@ -14,7 +15,6 @@ class TestAddons(MarionetteTestCase):
|
||||
def setUp(self):
|
||||
MarionetteTestCase.setUp(self)
|
||||
self.addons = Addons(self.marionette)
|
||||
self.addon_path = os.path.join(here, 'mn-restartless.xpi')
|
||||
|
||||
|
||||
@property
|
||||
@ -32,19 +32,27 @@ class TestAddons(MarionetteTestCase):
|
||||
|
||||
return addons
|
||||
|
||||
def test_install_and_remove_unsigned_addon(self):
|
||||
self.addons.signature_required = False
|
||||
def test_install_and_remove_temporary_unsigned_addon(self):
|
||||
addon_path = os.path.join(here, 'mn-restartless-unsigned.xpi')
|
||||
|
||||
addon_id = self.addons.install(self.addon_path)
|
||||
addon_id = self.addons.install(addon_path, temp=True)
|
||||
self.assertIn(addon_id, self.all_addon_ids)
|
||||
|
||||
self.addons.uninstall(addon_id)
|
||||
self.assertNotIn(addon_id, self.all_addon_ids)
|
||||
|
||||
self.addons.signature_required = True
|
||||
|
||||
def test_install_unsigned_addon_with_signature_required(self):
|
||||
self.signature_required = True
|
||||
def test_install_unsigned_addon(self):
|
||||
addon_path = os.path.join(here, 'mn-restartless-unsigned.xpi')
|
||||
|
||||
with self.assertRaises(AddonInstallException):
|
||||
self.addons.install(self.addon_path)
|
||||
self.addons.install(addon_path)
|
||||
|
||||
@unittest.skip("need to get the test extension signed")
|
||||
def test_install_and_remove_signed_addon(self):
|
||||
addon_path = os.path.join(here, 'mn-restartless-signed.xpi')
|
||||
|
||||
addon_id = self.addons.install(addon_path)
|
||||
self.assertIn(addon_id, self.all_addon_ids)
|
||||
|
||||
self.addons.uninstall(addon_id)
|
||||
self.assertNotIn(addon_id, self.all_addon_ids)
|
||||
|
@ -37,25 +37,8 @@ class Addons(object):
|
||||
|
||||
def __init__(self, marionette):
|
||||
self._mn = marionette
|
||||
self._signature_required = True
|
||||
|
||||
def on_restart():
|
||||
self.signature_required = self._signature_required
|
||||
self._mn.restart_handlers.append(on_restart)
|
||||
|
||||
@property
|
||||
def signature_required(self):
|
||||
"""
|
||||
Whether or not addons must be signed.
|
||||
"""
|
||||
return self._signature_required
|
||||
|
||||
@signature_required.setter
|
||||
def signature_required(self, val):
|
||||
self._mn.set_pref('xpinstall.signatures.required', val)
|
||||
self._signature_required = val
|
||||
|
||||
def install(self, path):
|
||||
def install(self, path, temp=False):
|
||||
"""Install an addon.
|
||||
|
||||
If the addon is restartless, it can be used right away. Otherwise
|
||||
@ -63,6 +46,9 @@ class Addons(object):
|
||||
will be needed.
|
||||
|
||||
:param path: A file path to the extension to be installed.
|
||||
:param temp: Install a temporary addon. Temporary addons will
|
||||
automatically be uninstalled on shutdown and do not need
|
||||
to be signed, though they must be restartless.
|
||||
:returns: The addon ID string of the newly installed addon.
|
||||
:raises: :exc:`AddonInstallException`
|
||||
"""
|
||||
@ -77,18 +63,29 @@ class Addons(object):
|
||||
|
||||
onInstallFailed: function(install) {
|
||||
marionetteScriptFinished([null, install.error]);
|
||||
},
|
||||
|
||||
onInstalled: function(addon) {
|
||||
marionetteScriptFinished([addon.id, 0]);
|
||||
}
|
||||
}
|
||||
|
||||
let file = new FileUtils.File(arguments[0]);
|
||||
AddonManager.getInstallForFile(file, function(aInstall) {
|
||||
if (aInstall.error != 0) {
|
||||
marionetteScriptFinished([null, aInstall.error]);
|
||||
}
|
||||
aInstall.addListener(listener);
|
||||
aInstall.install();
|
||||
});
|
||||
""", script_args=[path], debug_script=True)
|
||||
let temp = arguments[1];
|
||||
|
||||
if (!temp) {
|
||||
AddonManager.getInstallForFile(file, function(aInstall) {
|
||||
if (aInstall.error != 0) {
|
||||
marionetteScriptFinished([null, aInstall.error]);
|
||||
}
|
||||
aInstall.addListener(listener);
|
||||
aInstall.install();
|
||||
});
|
||||
} else {
|
||||
AddonManager.addAddonListener(listener);
|
||||
AddonManager.installTemporaryAddon(file);
|
||||
}
|
||||
""", script_args=[path, temp], debug_script=True)
|
||||
|
||||
if status:
|
||||
if status in ADDON_INSTALL_ERRORS:
|
||||
|
@ -564,7 +564,6 @@ class Marionette(object):
|
||||
self.device_serial = device_serial
|
||||
self.adb_host = adb_host
|
||||
self.adb_port = adb_port
|
||||
self.restart_handlers = []
|
||||
|
||||
startup_timeout = startup_timeout or self.DEFAULT_STARTUP_TIMEOUT
|
||||
|
||||
@ -1145,11 +1144,6 @@ class Marionette(object):
|
||||
self.start_session(session_id=self.session_id)
|
||||
self._reset_timeouts()
|
||||
|
||||
# Give consumers who depended on the old session a
|
||||
# chance to re-initialize and/or restore state.
|
||||
for handler in self.restart_handlers:
|
||||
handler()
|
||||
|
||||
def absolute_url(self, relative_url):
|
||||
'''
|
||||
Returns an absolute url for files served from Marionette's www directory.
|
||||
|
Loading…
Reference in New Issue
Block a user