Commit 1b0914ce authored by Andrew Luo's avatar Andrew Luo Committed by Commit Bot

Add use-webview-provider option.

Test: test_runner.py instrumentation ... --use-webview-provider /path/to/webview/apk

Bug: 914553
Change-Id: I061e69e4484442055a74a14f225a5cefd0419a2e
Reviewed-on: https://chromium-review.googlesource.com/c/1396849
Commit-Queue: Andrew Luo <aluo@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630138}
parent 3efbeec4
......@@ -513,6 +513,9 @@ class InstrumentationTestInstance(test_instance.TestInstance):
self._replace_system_package = None
self._initializeReplaceSystemPackageAttributes(args)
self._use_webview_provider = None
self._initializeUseWebviewProviderAttributes(args)
self._external_shard_index = args.test_launcher_shard_index
self._total_external_shards = args.test_launcher_total_shards
......@@ -711,6 +714,12 @@ class InstrumentationTestInstance(test_instance.TestInstance):
return
self._replace_system_package = args.replace_system_package
def _initializeUseWebviewProviderAttributes(self, args):
if (not hasattr(args, 'use_webview_provider')
or not args.use_webview_provider):
return
self._use_webview_provider = args.use_webview_provider
@property
def additional_apks(self):
return self._additional_apks
......@@ -771,6 +780,10 @@ class InstrumentationTestInstance(test_instance.TestInstance):
def replace_system_package(self):
return self._replace_system_package
@property
def use_webview_provider(self):
return self._use_webview_provider
@property
def screenshot_dir(self):
return self._screenshot_dir
......
......@@ -20,6 +20,7 @@ from devil.android import flag_changer
from devil.android.sdk import shared_prefs
from devil.android import logcat_monitor
from devil.android.tools import system_app
from devil.android.tools import webview_app
from devil.utils import reraiser_thread
from incremental_install import installer
from pylib import constants
......@@ -128,6 +129,7 @@ class LocalDeviceInstrumentationTestRun(
self._flag_changers = {}
self._replace_package_contextmanager = None
self._shared_prefs_to_restore = []
self._use_webview_contextmanager = None
#override
def TestPackage(self):
......@@ -163,6 +165,27 @@ class LocalDeviceInstrumentationTestRun(
steps.append(replace_package)
if self._test_instance.use_webview_provider:
@trace_event.traced
def use_webview_provider(dev):
# We need the context manager to be applied before modifying any
# shared preference files in case the replacement APK needs to be
# set up, and it needs to be applied while the test is running.
# Thus, it needs to be applied early during setup, but must still be
# applied during _RunTest, which isn't possible using 'with' without
# applying the context manager up in test_runner. Instead, we
# manually invoke its __enter__ and __exit__ methods in setup and
# teardown.
self._use_webview_contextmanager = webview_app.UseWebViewProvider(
dev, self._test_instance.use_webview_provider)
# Pylint is not smart enough to realize that this field has
# an __enter__ method, and will complain loudly.
# pylint: disable=no-member
self._use_webview_contextmanager.__enter__()
# pylint: enable=no-member
steps.append(use_webview_provider)
def install_helper(apk, permissions):
@instrumentation_tracing.no_tracing
@trace_event.traced("apk_path")
......@@ -348,8 +371,16 @@ class LocalDeviceInstrumentationTestRun(
for pref_to_restore in self._shared_prefs_to_restore:
pref_to_restore.Commit(force_commit=True)
# Context manager exit handlers are applied in reverse order
# of the enter handlers
if self._use_webview_contextmanager:
# See pylint-related comment above with __enter__()
# pylint: disable=no-member
self._use_webview_contextmanager.__exit__(*sys.exc_info())
# pylint: enable=no-member
if self._replace_package_contextmanager:
# See pylint-related commend above with __enter__()
# See pylint-related comment above with __enter__()
# pylint: disable=no-member
self._replace_package_contextmanager.__exit__(*sys.exc_info())
# pylint: enable=no-member
......
......@@ -434,6 +434,14 @@ def AddInstrumentationTestOptions(parser):
'the first element being the package and the second the path to the '
'replacement APK. Only supports replacing one package. Example: '
'--replace-system-package com.example.app,path/to/some.apk')
parser.add_argument(
'--use-webview-provider',
type=_RealPath, default=None,
help='Use this apk as the webview provider during test. '
'The original provider will be restored if possible, '
"on Nougat the provider can't be determined and so "
'the system will choose the default provider.')
parser.add_argument(
'--runtime-deps-path',
dest='runtime_deps_path', type=os.path.realpath,
......@@ -1024,6 +1032,14 @@ def main():
parser.error('--replace-system-package and --enable-concurrent-adb cannot '
'be used together')
# --use-webview-provider has the potential to cause issues if
# --enable-concurrent-adb is set, so disallow that combination
if (hasattr(args, 'use_webview_provider') and
hasattr(args, 'enable_concurrent_adb') and args.use_webview_provider and
args.enable_concurrent_adb):
parser.error('--use-webview-provider and --enable-concurrent-adb cannot '
'be used together')
if (getattr(args, 'jacoco', False) and
not getattr(args, 'coverage_dir', '')):
parser.error('--jacoco requires --coverage-dir')
......
......@@ -62,6 +62,7 @@
../../third_party/catapult/devil/devil/android/tools/device_status.py
../../third_party/catapult/devil/devil/android/tools/script_common.py
../../third_party/catapult/devil/devil/android/tools/system_app.py
../../third_party/catapult/devil/devil/android/tools/webview_app.py
../../third_party/catapult/devil/devil/android/valgrind_tools/__init__.py
../../third_party/catapult/devil/devil/android/valgrind_tools/base_tool.py
../../third_party/catapult/devil/devil/base_error.py
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment