Skip to content

Commit

Permalink
launchers: pass URL arg to android launchers (bug 1852787)
Browse files Browse the repository at this point in the history
- add support for URL arg in andoird launchers
- add tests
  • Loading branch information
zzzeid committed Sep 26, 2023
1 parent 3193ec6 commit d0cfe59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
20 changes: 14 additions & 6 deletions mozregression/launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,14 @@ def _start(
self.adb.rm(self.remote_profile, recursive=True)
LOG.debug("Pushing profile to device (%s -> %s)" % (profile.profile, self.remote_profile))
self.adb.push(profile.profile, self.remote_profile)
self._launch()
if cmdargs and len(cmdargs) == 1 and not cmdargs[0].startswith("-"):
url = cmdargs[0]
else:
url = None
if isinstance(self, (FenixLauncher, FennecLauncher, FocusLauncher)):
self._launch(url)
else:
self._launch()

def _wait(self):
while self.adb.process_exist(self.package_name):
Expand Down Expand Up @@ -527,31 +534,32 @@ class FennecLauncher(AndroidLauncher):
def _get_package_name(self):
return "org.mozilla.fennec"

def _launch(self):
def _launch(self, url=None):
LOG.debug("Launching fennec")
self.launch_browser(self.package_name, "org.mozilla.gecko.BrowserApp")
self.launch_browser(self.package_name, "org.mozilla.gecko.BrowserApp", url=url)


@REGISTRY.register("fenix")
class FenixLauncher(AndroidLauncher):
def _get_package_name(self):
return "org.mozilla.fenix"

def _launch(self):
def _launch(self, url=None):
LOG.debug("Launching fenix")
self.launch_browser(self.package_name, ".IntentReceiverActivity")
self.launch_browser(self.package_name, ".IntentReceiverActivity", url=url)


@REGISTRY.register("focus")
class FocusLauncher(AndroidLauncher):
def _get_package_name(self):
return "org.mozilla.focus.nightly"

def _launch(self):
def _launch(self, url=None):
LOG.debug("Launching focus")
self.launch_browser(
self.package_name,
"org.mozilla.focus.activity.IntentReceiverActivity",
url=url,
)


Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_launchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,25 @@ def proc_exists(name):
launcher.wait()
self.adb.process_exist.assert_called_with(package_name)

def test_start_with_url(self, launcher_class, package_name, intended_activity, **kwargs):
with patch(
f"mozregression.launchers.{launcher_class.__name__}._create_profile"
) as _create_profile:
# Force use of existing profile
_create_profile.return_value = self.profile
launcher = self.create_launcher(launcher_class=launcher_class)
launcher.start(profile="my_profile", cmdargs=("https://example.org/",))
self.adb.launch_application.assert_called_once_with(
package_name,
intended_activity,
"android.intent.action.VIEW",
url="https://example.org/",
extras={"args": f"-profile {self.remote_profile_path}"},
wait=True,
fail_if_running=True,
timeout=None,
)


class Zipfile(object):
def __init__(self, *a):
Expand Down

0 comments on commit d0cfe59

Please sign in to comment.