Commit b793785e authored by danakj's avatar danakj Committed by Commit Bot

Add a java skeleton for running chrome browser tests on Android.

This adds a ChromeBrowserTests java activity and application, based on
content and components browser tests. It additionally sets up a
ChromeBrowserInitializer which is needed before running the native
setup of ChromeBrowserMainParts etc.

The JNI_Onload runs the Chrome Android production path to set up a
ContentShellDelegate, and unsets the product version number afterward
as tests do no expect to have a version number.

The test_activity.xml layout refers to a ShellManager as the java
pieces are setting up the same UI as content-based browser tests for
now. We will need to use more Chrome java pieces for the UI in order
for tests to call out to java probably. But this gives a baseline
framework that runs the //chrome C++ code in an Android browser test.

We still need a BrowserTestBase subclass to provide the Test class
so that we may begin writing browser tests on Android.

We standardize the java code for content and components browser tests
while writing the ChromeBrowserTestsApplication, based on the code
in ChromeApplication and NativeUnitTest.

In order to depend on NestedMessagePumpAndroid in browser tests, but
not depend on WebTestSupport, we split the web_test_support target into
two parts, and we depend on the NestedMessagePumpAndroid in each place
it is used directly, which are the onload.cc files for each android
browser test target. We remove dependencies on web_test_support from
everywhere but content_shell_lib, where it is used.

R=jam@chromium.org

Bug: 961849
Change-Id: I4212482849eaf52dc8b8c22070806572215a8905
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633212
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665950}
parent 945f8ff6
......@@ -29,47 +29,44 @@ DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT',
PACKAGE_INFO = dict(chrome.PACKAGE_INFO)
PACKAGE_INFO.update({
'legacy_browser': chrome.PackageInfo(
'com.google.android.browser',
'com.android.browser.BrowserActivity',
None,
None),
'chromecast_shell': chrome.PackageInfo(
'com.google.android.apps.mediashell',
'com.google.android.apps.mediashell.MediaShellActivity',
'castshell-command-line',
None),
'android_webview_shell': chrome.PackageInfo(
'org.chromium.android_webview.shell',
'org.chromium.android_webview.shell.AwShellActivity',
'android-webview-command-line',
None),
'gtest': chrome.PackageInfo(
'org.chromium.native_test',
'org.chromium.native_test.NativeUnitTestActivity',
'chrome-native-tests-command-line',
None),
'components_browsertests': chrome.PackageInfo(
'org.chromium.components_browsertests_apk',
('org.chromium.components_browsertests_apk' +
'.ComponentsBrowserTestsActivity'),
'chrome-native-tests-command-line',
None),
'content_browsertests': chrome.PackageInfo(
'legacy_browser':
chrome.PackageInfo('com.google.android.browser',
'com.android.browser.BrowserActivity', None, None),
'chromecast_shell':
chrome.PackageInfo('com.google.android.apps.mediashell',
'com.google.android.apps.mediashell.MediaShellActivity',
'castshell-command-line', None),
'android_webview_shell':
chrome.PackageInfo('org.chromium.android_webview.shell',
'org.chromium.android_webview.shell.AwShellActivity',
'android-webview-command-line', None),
'gtest':
chrome.PackageInfo('org.chromium.native_test',
'org.chromium.native_test.NativeUnitTestActivity',
'chrome-native-tests-command-line', None),
'android_browsertests':
chrome.PackageInfo('org.chromium.android_browsertests_apk',
('org.chromium.android_browsertests_apk' +
'.ChromeBrowserTestsActivity'),
'chrome-native-tests-command-line', None),
'components_browsertests':
chrome.PackageInfo('org.chromium.components_browsertests_apk',
('org.chromium.components_browsertests_apk' +
'.ComponentsBrowserTestsActivity'),
'chrome-native-tests-command-line', None),
'content_browsertests':
chrome.PackageInfo(
'org.chromium.content_browsertests_apk',
'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
'chrome-native-tests-command-line',
None),
'chromedriver_webview_shell': chrome.PackageInfo(
'org.chromium.chromedriver_webview_shell',
'org.chromium.chromedriver_webview_shell.Main',
None,
None),
'android_webview_cts': chrome.PackageInfo(
'com.android.webview',
'com.android.cts.webkit.WebViewStartupCtsActivity',
'webview-command-line',
None),
'chrome-native-tests-command-line', None),
'chromedriver_webview_shell':
chrome.PackageInfo('org.chromium.chromedriver_webview_shell',
'org.chromium.chromedriver_webview_shell.Main', None,
None),
'android_webview_cts':
chrome.PackageInfo('com.android.webview',
'com.android.cts.webkit.WebViewStartupCtsActivity',
'webview-command-line', None),
})
......
......@@ -141,7 +141,6 @@ static_library("test_support") {
"//base/test:test_support",
"//chrome:resources",
"//chrome:strings",
"//chrome/app:test_support",
#"//chrome/app/theme:theme_resources",
"//chrome/browser:test_support",
......@@ -223,6 +222,9 @@ static_library("test_support") {
}
} else {
public_deps += [
# Android uses //chrome:chrome_android_core instead of the //chrome/app
# target.
"//chrome/app:test_support",
"//components/ukm:test_support",
"//components/zoom:test_support",
]
......@@ -457,15 +459,24 @@ if (is_android) {
"CHROME_VERSION_MAJOR=" + chrome_version_major,
]
use_default_launcher = false
android_manifest =
"${target_gen_dir}/android_browsertests_manifest/AndroidManifest.xml"
android_manifest_dep = ":android_browsertests_manifest"
deps = [
":android_browsertests_java",
":test_support",
":test_support_ui_android",
"//chrome:chrome_android_core",
"//chrome/android:app_hooks_java",
"//chrome/android:chrome_java",
"//content/test:android_test_message_pump_support",
]
sources = []
sources = [
"android/browsertests_apk/android_browsertests_jni_onload.cc",
# TODO(crbug.com/961849): Write an Android browser test and put it here.
]
}
static_library("test_support_ui_android") {
......@@ -482,6 +493,35 @@ if (is_android) {
"//content/public/browser",
]
}
android_library("android_browsertests_java") {
testonly = true
deps = [
":android_browsertests_java_resources",
"//base:base_java",
"//base:base_java_test_support",
"//chrome/android:chrome_java",
"//content/shell/android:content_shell_browsertests_java",
"//testing/android/native_test:native_test_java",
]
java_files = [
"android/browsertests_apk/src/org/chromium/android_browsertests_apk/ChromeBrowserTestsActivity.java",
"android/browsertests_apk/src/org/chromium/android_browsertests_apk/ChromeBrowserTestsApplication.java",
]
}
android_resources("android_browsertests_java_resources") {
testonly = true
resource_dirs = [ "//chrome/test/android/browsertests_apk/res" ]
custom_package = "org.chromium.android_browsertests_apk"
}
jinja_template("android_browsertests_manifest") {
testonly = true
input = "//chrome/test/android/browsertests_apk/AndroidManifest.xml.jinja2"
output =
"${target_gen_dir}/android_browsertests_manifest/AndroidManifest.xml"
}
}
if (!is_android) {
......@@ -3361,6 +3401,7 @@ test("unit_tests") {
]
deps += [
"//base:base_java",
"//chrome:chrome_android_core",
"//chrome/android:app_hooks_java",
"//chrome/android:chrome_java",
"//chrome/android/features/media_router:java",
......@@ -5464,6 +5505,8 @@ test("chrome_app_unittests") {
"../app/android/chrome_main_delegate_android.cc",
"../app/android/chrome_main_delegate_android.h",
"../app/android/chrome_main_delegate_android_unittest.cc",
"../app/chrome_main_delegate.cc",
"../app/chrome_main_delegate.h",
"../app/chrome_watcher_client_unittest_win.cc",
"../app/chrome_watcher_client_win.cc",
"../app/chrome_watcher_command_line_win.cc",
......@@ -5476,8 +5519,10 @@ test("chrome_app_unittests") {
"//base/test:test_support",
"//chrome/browser",
"//chrome/child",
"//chrome/gpu",
"//components/crash/core/common",
"//components/flags_ui:switches",
"//components/tracing",
]
if (!is_fuchsia) {
# TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.chromium.android_browsertests_apk">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:name="ChromeBrowserTestsApplication"
android:label="ChromeBrowserTests">
<activity android:name="ChromeBrowserTestsActivity"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:hardwareAccelerated="true"
android:process=":test_process">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- The following service entries exist in order to allow us to
start more than one sandboxed process. -->
<!-- NOTE: If you change the values of "android:process" for any of the below services,
you also need to update kHelperProcessExecutableName in chrome_constants.cc. -->
{% set num_sandboxed_services = 40 %}
<meta-data android:name="org.chromium.content.browser.NUM_SANDBOXED_SERVICES"
android:value="{{ num_sandboxed_services }}"/>
{% for i in range(num_sandboxed_services) %}
<service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}"
android:process=":sandboxed_process{{ i }}"
android:isolatedProcess="true"
android:exported="false" />
{% endfor %}
{% set num_privileged_services = 5 %}
<meta-data android:name="org.chromium.content.browser.NUM_PRIVILEGED_SERVICES"
android:value="{{ num_privileged_services }}"/>
{% for i in range(num_privileged_services) %}
<service android:name="org.chromium.content.app.PrivilegedProcessService{{ i }}"
android:process=":privileged_process{{ i }}"
android:isolatedProcess="false"
android:exported="false" />
{% endfor %}
</application>
<instrumentation android:name="org.chromium.native_test.NativeTestInstrumentationTestRunner"
android:label="ChromeBrowserTests"
android:targetPackage="org.chromium.android_browsertests_apk"
chromium-junit3="true"/>
</manifest>
include_rules = [
"+content/shell/android/browsertests/src/org/chromium/content_shell/browsertests",
]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/android/jni_android.h"
#include "base/android/library_loader/library_loader_hooks.h"
#include "base/message_loop/message_loop.h"
#include "chrome/app/android/chrome_jni_onload.h"
#include "content/public/test/nested_message_pump_android.h"
// This is called by the VM when the shared library is first loaded.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
base::android::InitVM(vm);
if (!android::OnJNIOnLoadInit())
return -1;
// chrome's OnJNIOnLoadInit will set the product version number, but tests do
// not have a version so they expect the version number to be "" in java. We
// reset the value back to empty string here, and hope that no code in between
// depended on it.
base::android::SetVersionNumber("");
// This needs to be done before base::TestSuite::Initialize() is called,
// as it also tries to set MessagePumpForUIFactory.
base::MessagePump::OverrideMessagePumpForUIFactory(
[]() -> std::unique_ptr<base::MessagePump> {
return std::make_unique<content::NestedMessagePumpAndroid>();
});
// Other browser test implementations of JNI_OnLoad set the
// ContentMainDelegate here, but //chrome's OnJNIOnLoadInit will already set
// the delegate, so we do not repeat that here.
return JNI_VERSION_1_4;
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<org.chromium.content_shell.ShellManager
android:id="@+id/shell_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_browsertests_apk;
import android.os.Bundle;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.browser.init.BrowserParts;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.EmptyBrowserParts;
import org.chromium.content_shell.browsertests.ContentShellBrowserTestActivity;
import java.io.File;
/**
* Android activity for running chrome browser tests.
*/
public class ChromeBrowserTestsActivity extends ContentShellBrowserTestActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appendCommandLineFlags(
"--remote-debugging-socket-name android_browsertests_devtools_remote");
}
@Override
protected void initializeBrowserProcess() {
// TODO(danakj): This sets up some of the Chrome Java stuff.
// AsyncInitializationActivity normally does this for the ChromeActivity.
// We skip handlePostNativeStartup() for now, which runs child processes.
// We should probably be a SynchronousInitializationActivity, which would
// run both of these from onCreate(). But it's not clear yet how we
// should be initializing the Chrome UI code (esp ChromeWindow and
// CompositorViewHolder) vs using ContentShellBrowserTestActivity and
// its ShellManager.
BrowserParts parts = new EmptyBrowserParts() {};
ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePreNativeStartup(parts);
super.initializeBrowserProcess();
}
@Override
protected File getPrivateDataDirectory() {
// TODO(agrieve): We should not be touching the side-loaded test data directory.
// https://crbug.com/617734
return new File(UrlUtils.getIsolatedTestRoot(),
ChromeBrowserTestsApplication.PRIVATE_DATA_DIRECTORY_SUFFIX);
}
@Override
protected int getTestActivityViewId() {
return R.layout.test_activity;
}
@Override
protected int getShellManagerViewId() {
return R.id.shell_container;
}
}
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_browsertests_apk;
import android.content.Context;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.PathUtils;
import org.chromium.chrome.browser.metrics.UmaUtils;
import org.chromium.native_test.NativeBrowserTestApplication;
/**
* A basic chrome.browser.tests {@link android.app.Application}.
*
* TODO(danakj): This class sets up some of the things that ChromeApplication
* does but we should maybe subclass ChromeApplication or share code. There are
* many things missing from attachBaseContext() that ChromeApplication sets up
* and it's not clear yet if they are needed or not.
*/
public class ChromeBrowserTestsApplication extends NativeBrowserTestApplication {
static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome";
@Override
protected void attachBaseContext(Context base) {
boolean isBrowserProcess = isBrowserProcess();
if (isBrowserProcess) UmaUtils.recordMainEntryPointTime();
super.attachBaseContext(base);
if (isBrowserProcess) {
ApplicationStatus.initialize(this);
// Test-only stuff, see also NativeUnitTest.java.
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
}
}
}
......@@ -549,8 +549,8 @@ if (!is_ios) {
"//components/autofill_assistant/browser",
"//components/autofill_assistant/browser:proto",
"//components/download/internal/common:internal_java",
"//content/public/test/android:web_test_java_support",
"//content/test:web_test_support",
"//content/public/test/android:android_test_message_pump_support_java",
"//content/test:android_test_message_pump_support",
"//testing/android/native_test:native_test_support",
]
use_default_launcher = false
......
......@@ -4,34 +4,27 @@
package org.chromium.components_browsertests_apk;
import android.app.Application;
import android.content.Context;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildConfig;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.multidex.ChromiumMultiDexInstaller;
import org.chromium.native_test.NativeBrowserTestApplication;
/**
* A basic content_public.browser.tests {@link android.app.Application}.
*/
public class ComponentsBrowserTestsApplication extends Application {
public class ComponentsBrowserTestsApplication extends NativeBrowserTestApplication {
static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "components_shell";
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ContextUtils.initApplicationContext(this);
// The test harness runs in the main process, and browser in :test_process.
boolean isMainProcess = !ContextUtils.getProcessName().contains(":");
boolean isBrowserProcess = ContextUtils.getProcessName().contains(":test");
if (BuildConfig.IS_MULTIDEX_ENABLED && (isMainProcess || isBrowserProcess)) {
ChromiumMultiDexInstaller.install(this);
}
if (isBrowserProcess) {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
if (isBrowserProcess()) {
ApplicationStatus.initialize(this);
// Test-only stuff, see also NativeUnitTest.java.
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
}
}
}
......@@ -8,7 +8,7 @@ generate_jni("test_support_content_jni_headers") {
]
}
android_library("web_test_java_support") {
android_library("android_test_message_pump_support_java") {
testonly = true
deps = [
"//base:base_java",
......@@ -19,7 +19,7 @@ android_library("web_test_java_support") {
android_library("content_java_test_support") {
testonly = true
deps = [
":web_test_java_support",
":android_test_message_pump_support_java",
"//base:base_java",
"//base:base_java_test_support",
"//content/public/android:content_java",
......
......@@ -408,6 +408,7 @@ jumbo_static_library("content_shell_lib") {
"//base/test:test_support",
"//components/embedder_support/android:view",
"//content/shell/android:content_shell_jni_headers",
"//content/test:android_test_message_pump_support",
"//mojo/public/java/system:test_support",
"//ui/android",
]
......
......@@ -172,7 +172,7 @@ android_apk("content_shell_apk") {
"//base:base_java_test_support",
"//components/crash/android:java",
"//content/public/android:content_java",
"//content/public/test/android:web_test_java_support",
"//content/public/test/android:android_test_message_pump_support_java",
"//media/capture/video/android:capture_java",
"//net/android:net_java",
"//services/shape_detection:shape_detection_java",
......
......@@ -4,34 +4,27 @@
package org.chromium.content_browsertests_apk;
import android.app.Application;
import android.content.Context;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.BuildConfig;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.multidex.ChromiumMultiDexInstaller;
import org.chromium.native_test.NativeBrowserTestApplication;
/**
* A basic content_public.browser.tests {@link android.app.Application}.
*/
public class ContentBrowserTestsApplication extends Application {
public class ContentBrowserTestsApplication extends NativeBrowserTestApplication {
static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_shell";
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ContextUtils.initApplicationContext(this);
// content_browsertests needs secondary dex in order to run EmbeddedTestServer in a
// privileged process.
if (BuildConfig.IS_MULTIDEX_ENABLED) {
ChromiumMultiDexInstaller.install(this);
}
// The test harness runs in the main process, and browser in :test_process.
if (ContextUtils.getProcessName().contains(":test")) {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
if (isBrowserProcess()) {
ApplicationStatus.initialize(this);
// Test-only stuff, see also NativeUnitTest.java.
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
}
}
}
......@@ -573,7 +573,6 @@ jumbo_static_library("browsertest_support") {
deps = [
":test_support",
":web_test_support",
"//base",
"//base:i18n",
"//base/test:test_config",
......@@ -643,6 +642,31 @@ mojom("test_interfaces") {
]
}
if (is_android) {
static_library("android_test_message_pump_support") {
testonly = true
# See comment at the top of //content/BUILD.gn for why this is disabled in
# component builds.
if (is_component_build) {
check_includes = false
}
sources = [
"../public/test/nested_message_pump_android.cc",
"../public/test/nested_message_pump_android.h",
]
public_deps = [
"//base",
]
deps = [
"//content/public/test/android:test_support_content_jni_headers",
]
}
}
static_library("web_test_support") {
testonly = true
......@@ -653,8 +677,6 @@ static_library("web_test_support") {
}
sources = [
"../public/test/nested_message_pump_android.cc",
"../public/test/nested_message_pump_android.h",
"../public/test/web_test_support.h",
"web_test_support.cc",
]
......@@ -678,10 +700,6 @@ static_library("web_test_support") {
"//ui/gfx/geometry",
"//v8",
]
if (is_android) {
deps += [ "//content/public/test/android:test_support_content_jni_headers" ]
}
}
static_library("test_runner_support") {
......@@ -1215,6 +1233,7 @@ test("content_browsertests") {
"../browser/pointer_lock_browsertest.h",
]
deps += [
":android_test_message_pump_support",
":content_browsertests_java",
"//content/shell:content_shell_lib",
"//content/shell/android:content_shell_assets",
......
......@@ -97,6 +97,8 @@ display log messages to the `LogCat` pane.
<classpathentry kind="src" path="android_webview/test/shell/src"/>
<classpathentry kind="src" path="android_webview/unittestjava/src"/>
<classpathentry kind="src" path="android_webview/javatests/src"/>
<classpathentry kind="src" path="chrome/test/android/browsertests_apk/src"/>
<classpathentry kind="src" path="components/test/android/browsertests_apk/src"/>
<classpathentry kind="src" path="content/public/test/android/javatests/src"/>
<classpathentry kind="src" path="content/public/android/java/src"/>
<classpathentry kind="src" path="content/public/android/javatests/src"/>
......
......@@ -54,6 +54,7 @@ android_library("native_test_java") {
java_files = [
"java/src/org/chromium/native_test/NativeTestApplication.java",
"java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
"java/src/org/chromium/native_test/NativeBrowserTestApplication.java",
"java/src/org/chromium/native_test/NativeTest.java",
"java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
"java/src/org/chromium/native_test/NativeUnitTest.java",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.native_test;
import android.app.Application;
import android.content.Context;
import org.chromium.base.BuildConfig;
import org.chromium.base.ContextUtils;
import org.chromium.base.multidex.ChromiumMultiDexInstaller;
/**
* An {@link android.app.Application} for running native browser tests.
*/
public abstract class NativeBrowserTestApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ContextUtils.initApplicationContext(this);
if (isMainProcess() || isBrowserProcess()) {
// We need secondary dex in order to run EmbeddedTestServer in a
// privileged process.
if (BuildConfig.IS_MULTIDEX_ENABLED) ChromiumMultiDexInstaller.install(this);
}
}
protected static boolean isMainProcess() {
// The test harness runs in the main process, and browser in :test_process.
return !ContextUtils.getProcessName().contains(":");
}
protected static boolean isBrowserProcess() {
// The test harness runs in the main process, and browser in :test_process.
return ContextUtils.getProcessName().contains(":test");
}
}
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