summaryrefslogtreecommitdiffstats
path: root/components/test
diff options
context:
space:
mode:
authorjaekyun <jaekyun@chromium.org>2015-04-22 21:22:48 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-23 04:22:48 +0000
commit4ba34ff136727244ead91780152b3248fe7ce0fd (patch)
tree7d92757a191a5873c0dbdfe3579cd0818d26c434 /components/test
parentc32d8a85648b9e19320368f1dd91ddaca814fd0e (diff)
downloadchromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.zip
chromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.tar.gz
chromium_src-4ba34ff136727244ead91780152b3248fe7ce0fd.tar.bz2
Enable components_browsertests on Android
BUG=465351 Review URL: https://codereview.chromium.org/1075783002 Cr-Commit-Position: refs/heads/master@{#326449}
Diffstat (limited to 'components/test')
-rw-r--r--components/test/DEPS10
-rw-r--r--components/test/android/OWNERS3
-rw-r--r--components/test/android/browsertests_apk/AndroidManifest.xml.jinja260
-rw-r--r--components/test/android/browsertests_apk/components_browser_tests_android.cc99
-rw-r--r--components/test/android/browsertests_apk/components_browser_tests_android.h16
-rw-r--r--components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc40
-rw-r--r--components/test/android/browsertests_apk/res/layout/test_activity.xml16
-rw-r--r--components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java75
-rw-r--r--components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java32
9 files changed, 351 insertions, 0 deletions
diff --git a/components/test/DEPS b/components/test/DEPS
index ad35ec8..ec6ab2f 100644
--- a/components/test/DEPS
+++ b/components/test/DEPS
@@ -2,7 +2,17 @@ include_rules = [
# To initialize the global data of content_settings.
"+components/content_settings/core/common",
"+components/invalidation/android/component_jni_registrar.h",
+ "+content/public/android/java/src/org/chromium/content/browser",
+ "+content/public/app/content_jni_onload.h",
+ "+content/public/app/content_main.h",
+ "+content/public/common/content_switches.h",
"+content/public/test",
+ "+content/shell/android/java/src/org/chromium/content_shell",
+ "+content/shell/android/shell_jni_registrar.h",
+ "+content/shell/app/shell_main_delegate.h",
+ "+jni",
+ "+media/base/media_switches.h",
+ "+ui/android/java/src/org/chromium/ui/base",
"+ui/base/android/ui_base_jni_registrar.h",
"+ui/base/resource/resource_bundle.h",
"+ui/base/ui_base_paths.h",
diff --git a/components/test/android/OWNERS b/components/test/android/OWNERS
new file mode 100644
index 0000000..c43b4b3
--- /dev/null
+++ b/components/test/android/OWNERS
@@ -0,0 +1,3 @@
+jaekyun@chromium.org
+sievers@chromium.org
+tedchoc@chromium.org
diff --git a/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2
new file mode 100644
index 0000000..3ac010d
--- /dev/null
+++ b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.chromium.components_browsertests_apk">
+
+ <application android:name="ComponentsBrowserTestsApplication"
+ android:label="ComponentsBrowserTests">
+ <activity android:name="ComponentsBrowserTestsActivity"
+ android:launchMode="singleTask"
+ android:theme="@android:style/Theme.Holo.Light.NoActionBar"
+ android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
+ android:hardwareAccelerated="true">
+ <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 = 20 %}
+ <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 = 3 %}
+ <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>
+
+ <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
+ <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"/>
+</manifest>
diff --git a/components/test/android/browsertests_apk/components_browser_tests_android.cc b/components/test/android/browsertests_apk/components_browser_tests_android.cc
new file mode 100644
index 0000000..baf8efe
--- /dev/null
+++ b/components/test/android/browsertests_apk/components_browser_tests_android.cc
@@ -0,0 +1,99 @@
+// 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.
+
+// This class sets up the environment for running the content browser tests
+// inside an android application.
+
+#include <android/log.h>
+#include <unistd.h>
+
+#include "base/android/base_jni_registrar.h"
+#include "base/android/fifo_utils.h"
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/library_loader/library_loader_hooks.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/base_switches.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/strings/string_tokenizer.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/test_launcher.h"
+#include "jni/ComponentsBrowserTestsActivity_jni.h"
+#include "media/base/media_switches.h"
+#include "testing/android/native_test/native_test_util.h"
+
+using testing::native_test_util::ArgsToArgv;
+using testing::native_test_util::ParseArgsFromCommandLineFile;
+using testing::native_test_util::ScopedMainEntryLogger;
+
+// The main function of the program to be wrapped as an apk.
+extern int main(int argc, char** argv);
+
+namespace {
+
+// The test runner script writes the command line file in
+// "/data/local/tmp".
+static const char kCommandLineFilePath[] =
+ "/data/local/tmp/components-browser-tests-command-line";
+
+} // namespace
+
+namespace components {
+
+// TODO(jaekyun): Refactor and deduplicate with
+// testing/android/native_test/native_test_launcher.cc (http://crbug.com/476410)
+static void RunTests(JNIEnv* env,
+ jobject obj,
+ jstring jfiles_dir,
+ jobject app_context) {
+ // Command line basic initialization, will be fully initialized later.
+ static const char* const kInitialArgv[] = {"ComponentsBrowserTestsActivity"};
+ base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv);
+
+ // Set the application context in base.
+ base::android::ScopedJavaLocalRef<jobject> scoped_context(
+ env, env->NewLocalRef(app_context));
+ base::android::InitApplicationContext(env, scoped_context);
+ base::android::RegisterJni(env);
+
+ std::vector<std::string> args;
+ ParseArgsFromCommandLineFile(kCommandLineFilePath, &args);
+
+ std::vector<char*> argv;
+ int argc = ArgsToArgv(args, &argv);
+
+ // Fully initialize command line with arguments.
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ command_line->AppendArguments(base::CommandLine(argc, &argv[0]), false);
+
+ // Append required switches.
+ command_line->AppendSwitch(content::kSingleProcessTestsFlag);
+ command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
+ command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
+ // Specify a socket name to not conflict with the default one used
+ // in content_shell.
+ command_line->AppendSwitchASCII(switches::kRemoteDebuggingSocketName,
+ "components_browsertests_devtools_remote");
+
+ // Create fifo and redirect stdout and stderr to it.
+ base::FilePath files_dir(
+ base::android::ConvertJavaStringToUTF8(env, jfiles_dir));
+ base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo")));
+ base::android::CreateFIFO(fifo_path, 0666);
+ base::android::RedirectStream(stdout, fifo_path, "w+");
+ dup2(STDOUT_FILENO, STDERR_FILENO);
+
+ ScopedMainEntryLogger scoped_main_entry_logger;
+ main(argc, &argv[0]);
+}
+
+bool RegisterComponentsBrowserTestsAndroid(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace components
diff --git a/components/test/android/browsertests_apk/components_browser_tests_android.h b/components/test/android/browsertests_apk/components_browser_tests_android.h
new file mode 100644
index 0000000..a989706
--- /dev/null
+++ b/components/test/android/browsertests_apk/components_browser_tests_android.h
@@ -0,0 +1,16 @@
+// 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.
+
+#ifndef COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_
+#define COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_
+
+#include <jni.h>
+
+namespace components {
+
+bool RegisterComponentsBrowserTestsAndroid(JNIEnv* env);
+
+} // namespace components
+
+#endif // COMPONENTS_TEST_ANDROID_BROWSERTESTS_APK_COMPONENTS_BROWSER_TESTS_ANDROID_H_
diff --git a/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc b/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc
new file mode 100644
index 0000000..e47b840
--- /dev/null
+++ b/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc
@@ -0,0 +1,40 @@
+// 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 "base/android/jni_android.h"
+#include "base/bind.h"
+#include "components/test/android/browsertests_apk/components_browser_tests_android.h"
+#include "content/public/app/content_jni_onload.h"
+#include "content/public/app/content_main.h"
+#include "content/public/test/nested_message_pump_android.h"
+#include "content/shell/android/shell_jni_registrar.h"
+#include "content/shell/app/shell_main_delegate.h"
+
+namespace {
+
+bool RegisterJNI(JNIEnv* env) {
+ return content::android::RegisterShellJni(env) &&
+ content::NestedMessagePumpAndroid::RegisterJni(env) &&
+ components::RegisterComponentsBrowserTestsAndroid(env);
+}
+
+bool Init() {
+ content::SetContentMainDelegate(new content::ShellMainDelegate());
+ return true;
+}
+
+} // namespace
+
+// This is called by the VM when the shared library is first loaded.
+JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ std::vector<base::android::RegisterCallback> register_callbacks;
+ register_callbacks.push_back(base::Bind(&RegisterJNI));
+ std::vector<base::android::InitCallback> init_callbacks;
+ init_callbacks.push_back(base::Bind(&Init));
+ if (!content::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
+ !content::android::OnJNIOnLoadInit(init_callbacks)) {
+ return -1;
+ }
+ return JNI_VERSION_1_4;
+}
diff --git a/components/test/android/browsertests_apk/res/layout/test_activity.xml b/components/test/android/browsertests_apk/res/layout/test_activity.xml
new file mode 100644
index 0000000..227ce1f
--- /dev/null
+++ b/components/test/android/browsertests_apk/res/layout/test_activity.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+ -->
+
+<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>
diff --git a/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java
new file mode 100644
index 0000000..bbf2461
--- /dev/null
+++ b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java
@@ -0,0 +1,75 @@
+// 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.components_browsertests_apk;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.Window;
+import android.view.WindowManager;
+
+import org.chromium.base.JNINamespace;
+import org.chromium.base.annotations.SuppressFBWarnings;
+import org.chromium.base.library_loader.LibraryLoader;
+import org.chromium.base.library_loader.LibraryProcessType;
+import org.chromium.base.library_loader.ProcessInitException;
+import org.chromium.content.browser.BrowserStartupController;
+import org.chromium.content_shell.ShellManager;
+import org.chromium.ui.base.ActivityWindowAndroid;
+import org.chromium.ui.base.WindowAndroid;
+
+/**
+ * Android activity for running components browser tests
+ */
+@JNINamespace("components")
+public class ComponentsBrowserTestsActivity extends Activity {
+ private static final String TAG = "ComponentsBrowserTestsActivity";
+
+ private ShellManager mShellManager;
+ private WindowAndroid mWindowAndroid;
+
+ @Override
+ @SuppressFBWarnings("DM_EXIT")
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ try {
+ LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
+ } catch (ProcessInitException e) {
+ Log.i(TAG, "Cannot load components_browsertests:" + e);
+ System.exit(-1);
+ }
+ BrowserStartupController.get(getApplicationContext(), LibraryProcessType.PROCESS_BROWSER)
+ .initChromiumBrowserProcessForTests();
+
+ setContentView(R.layout.test_activity);
+ mShellManager = (ShellManager) findViewById(R.id.shell_container);
+ mWindowAndroid = new ActivityWindowAndroid(this);
+ mShellManager.setWindow(mWindowAndroid, false);
+
+ Window wind = this.getWindow();
+ wind.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
+ wind.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
+ wind.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ Log.i(TAG, "Running tests");
+ runTests();
+ Log.i(TAG, "Tests finished.");
+ finish();
+ }
+ });
+ }
+
+ private void runTests() {
+ nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext());
+ }
+
+ private native void nativeRunTests(String filesDir, Context appContext);
+}
diff --git a/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java
new file mode 100644
index 0000000..91ee597
--- /dev/null
+++ b/components/test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsApplication.java
@@ -0,0 +1,32 @@
+// 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.components_browsertests_apk;
+
+import android.content.Context;
+
+import org.chromium.base.BaseChromiumApplication;
+import org.chromium.base.PathUtils;
+import org.chromium.base.ResourceExtractor;
+
+/**
+ * A basic content browser tests {@link android.app.Application}.
+ */
+public class ComponentsBrowserTestsApplication extends BaseChromiumApplication {
+ private static final String[] MANDATORY_PAK_FILES =
+ new String[] {"components_tests_resources.pak", "content_shell.pak", "icudtl.dat",
+ "natives_blob.bin", "snapshot_blob.bin"};
+ private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "components_shell";
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ initializeApplicationParameters(this);
+ }
+
+ public static void initializeApplicationParameters(Context context) {
+ ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES);
+ PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, context);
+ }
+}