Skip to content

Commit

Permalink
Merge pull request #205 from parkouss/fennec-profile
Browse files Browse the repository at this point in the history
use profile (and profile prefs) for fennec
  • Loading branch information
parkouss committed Mar 28, 2015
2 parents a875653 + a29b0b4 commit aaf834a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
45 changes: 31 additions & 14 deletions mozregression/launchers.py
Expand Up @@ -8,6 +8,7 @@
Define the launcher classes, responsible of running the tested applications.
"""

import os
from mozlog.structured import get_default_logger
from mozprofile import FirefoxProfile, ThunderbirdProfile, Profile
from mozrunner import Runner
Expand All @@ -26,6 +27,7 @@ class Launcher(object):
Handle the logic of downloading a build file, installing and
running an application.
"""
profile_class = Profile

@classmethod
def check_is_runnable(cls):
Expand Down Expand Up @@ -76,12 +78,22 @@ def _start(self, **kwargs):
def _stop(self):
raise NotImplementedError

def _create_profile(self, profile=None, addons=(), preferences=None):
if profile:
profile = self.profile_class(profile=profile, addons=addons,
preferences=preferences)
elif len(addons):
profile = self.profile_class(addons=addons,
preferences=preferences)
else:
profile = self.profile_class(preferences=preferences)
return profile


class MozRunnerLauncher(Launcher):
tempdir = None
runner = None
app_name = 'undefined'
profile_class = Profile
binary = None

def _install(self, dest):
Expand All @@ -91,14 +103,8 @@ def _install(self, dest):
self.app_name)

def _start(self, profile=None, addons=(), cmdargs=(), preferences=None):
if profile:
profile = self.profile_class(profile=profile, addons=addons,
preferences=preferences)
elif len(addons):
profile = self.profile_class(addons=addons,
preferences=preferences)
else:
profile = self.profile_class(preferences=preferences)
profile = self._create_profile(profile=profile, addons=addons,
preferences=preferences)

self._logger.info("Launching %s" % self.binary)
process_args = {'processOutputLine': [self._logger.debug]}
Expand Down Expand Up @@ -153,6 +159,7 @@ class FennecLauncher(Launcher):
app_info = None
adb = None
package_name = None
remote_profile = None

@classmethod
def check_is_runnable(cls):
Expand All @@ -166,9 +173,6 @@ def check_is_runnable(cls):
if not devices:
raise LauncherNotRunnable("No android device connected."
" Connect a device and try again.")
if not raw_input("WARNING: bisecting fennec builds will clobber your"
" existing profile. Type 'y' to continue:") == 'y':
raise LauncherNotRunnable('Aborted.')

def _install(self, dest):
# get info now, as dest may be removed
Expand All @@ -179,11 +183,24 @@ def _install(self, dest):
self.adb.uninstall_app(self.package_name)
self.adb.install_app(dest)

def _start(self, **kwargs):
self.adb.launch_fennec(self.package_name)
def _start(self, profile=None, addons=(), cmdargs=(), preferences=None):
# for now we don't handle addons on the profile for fennec
profile = self._create_profile(profile=profile,
preferences=preferences)
# send the profile on the device
self.remote_profile = "/".join([self.adb.test_root,
os.path.basename(profile.profile)])
if self.adb.exists(self.remote_profile):
self.adb.rm(self.remote_profile, recursive=True)
self.adb.push(profile.profile, self.remote_profile)

self.adb.launch_fennec(self.package_name,
extra_args=["-profile", self.remote_profile])

def _stop(self):
self.adb.stop_application(self.package_name)
if self.adb.exists(self.remote_profile):
self.adb.rm(self.remote_profile, recursive=True)

def get_app_info(self):
return self.app_info
26 changes: 16 additions & 10 deletions tests/unit/test_launchers.py
Expand Up @@ -108,7 +108,7 @@ class TestFennecLauncher(unittest.TestCase):
@patch('mozregression.launchers.mozversion.get_version')
@patch('mozregression.launchers.ADBAndroid')
def create_launcher(self, ADBAndroid, get_version, **kwargs):
self.adb = Mock()
self.adb = Mock(test_root='/sdcard/tmp')
ADBAndroid.return_value = self.adb
get_version.return_value = kwargs.get('version_value', {})
return launchers.FennecLauncher('/binary')
Expand All @@ -120,8 +120,16 @@ def test_install(self):

def test_start_stop(self):
launcher = self.create_launcher()
launcher.start()
self.adb.launch_fennec.assert_called_once_with("org.mozilla.fennec")
launcher.start(profile='my_profile')
self.adb.exists.assert_called_once_with('/sdcard/tmp/my_profile')
self.adb.rm.assert_called_once_with('/sdcard/tmp/my_profile',
recursive=True)
self.adb.push.assert_called_once_with(os.path.realpath('my_profile'),
'/sdcard/tmp/my_profile')
self.adb.launch_fennec.assert_called_once_with(
"org.mozilla.fennec",
extra_args=['-profile', '/sdcard/tmp/my_profile']
)
# ensure get_app_info returns something
self.assertIsNotNone(launcher.get_app_info())
launcher.stop()
Expand All @@ -132,8 +140,11 @@ def test_adb_calls_with_custom_package_name(self):
launcher = \
self.create_launcher(version_value={'package_name': pkg_name})
self.adb.uninstall_app.assert_called_once_with(pkg_name)
launcher.start()
self.adb.launch_fennec.assert_called_once_with(pkg_name)
launcher.start(profile='my_profile')
self.adb.launch_fennec.assert_called_once_with(
pkg_name,
extra_args=['-profile', '/sdcard/tmp/my_profile']
)
launcher.stop()
self.adb.stop_application.assert_called_once_with(pkg_name)

Expand All @@ -146,11 +157,6 @@ def test_check_is_runnable(self, raw_input, ADBHost):
# this won't raise errors
launchers.FennecLauncher.check_is_runnable()

# exception raised if answer is not 'y'
raw_input.return_value = 'n'
self.assertRaises(LauncherNotRunnable,
launchers.FennecLauncher.check_is_runnable)

# exception raised if there is no device
raw_input.return_value = 'y'
devices.return_value = False
Expand Down

0 comments on commit aaf834a

Please sign in to comment.