diff options
Diffstat (limited to 'components')
7 files changed, 25 insertions, 178 deletions
diff --git a/components/BUILD.gn b/components/BUILD.gn index 700e862..61b0867 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -342,17 +342,6 @@ repack("components_tests_pak") { ] } -if (is_android) { - import("//build/config/android/rules.gni") - - generate_jni("components_browsertests_jni_headers") { - jni_package = "components_browsertests/shell" - sources = [ - "test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java", - ] - } -} - test("components_browsertests") { sources = [ "autofill/content/browser/risk/fingerprint_browsertest.cc", @@ -394,10 +383,7 @@ test("components_browsertests") { "test/android/browsertests_apk/components_browser_tests_jni_onload.cc", ] sources -= [ "autofill/content/browser/risk/fingerprint_browsertest.cc" ] - deps += [ - ":components_browsertests_jni_headers", - "//testing/android/native_test:native_test_util", - ] + deps += [ "//testing/android/native_test:native_test_support" ] use_launcher = false } diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 623dd94..00d8805 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -1209,17 +1209,6 @@ 'includes': [ '../build/android/jinja_template.gypi' ], }, { - 'target_name': 'components_browsertests_jni_headers', - 'type': 'none', - 'sources': [ - 'test/android/browsertests_apk/src/org/chromium/components_browsertests_apk/ComponentsBrowserTestsActivity.java', - ], - 'variables': { - 'jni_gen_package': 'content/shell', - }, - 'includes': [ '../build/jni_generator.gypi' ], - }, - { # TODO(GN) 'target_name': 'components_browsertests_apk', 'type': 'none', @@ -1233,14 +1222,13 @@ 'components_browsertests', ], 'variables': { - 'apk_name': 'components_browsertests', + 'test_suite_name': 'components_browsertests', 'java_in_dir': 'test/android/browsertests_apk', 'android_manifest_path': '<(SHARED_INTERMEDIATE_DIR)/components_browsertests_manifest/AndroidManifest.xml', 'resource_dir': 'test/android/browsertests_apk/res', - 'native_lib_target': 'libcomponents_browsertests', 'asset_location': '<(PRODUCT_DIR)/components_browsertests_apk_shell/assets', }, - 'includes': [ '../build/java_apk.gypi' ], + 'includes': [ '../build/apk_browsertest.gypi' ], }, ], }], @@ -1326,16 +1314,13 @@ 'conditions': [ ['OS == "android"', { 'sources' : [ - 'test/android/browsertests_apk/components_browser_tests_android.cc', - 'test/android/browsertests_apk/components_browser_tests_android.h', 'test/android/browsertests_apk/components_browser_tests_jni_onload.cc', ], 'sources!': [ 'autofill/content/browser/risk/fingerprint_browsertest.cc', ], 'dependencies': [ - '../testing/android/native_test.gyp:native_test_util', - 'components_browsertests_jni_headers', + '../testing/android/native_test.gyp:native_test_support', ], }], ['OS == "linux"', { diff --git a/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 index 3ac010d..97dae9e 100644 --- a/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 +++ b/components/test/android/browsertests_apk/AndroidManifest.xml.jinja2 @@ -47,6 +47,10 @@ {% endfor %} </application> + <instrumentation android:name="org.chromium.native_test.NativeTestInstrumentationTestRunner" + android:label="ComponentsBrowserTests" + android:targetPackage="org.chromium.components_browsertests_apk"/> + <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"/> diff --git a/components/test/android/browsertests_apk/components_browser_tests_android.cc b/components/test/android/browsertests_apk/components_browser_tests_android.cc deleted file mode 100644 index baf8efe..0000000 --- a/components/test/android/browsertests_apk/components_browser_tests_android.cc +++ /dev/null @@ -1,99 +0,0 @@ -// 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 deleted file mode 100644 index a989706..0000000 --- a/components/test/android/browsertests_apk/components_browser_tests_android.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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 index e47b840..6b15e3c 100644 --- a/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc +++ b/components/test/android/browsertests_apk/components_browser_tests_jni_onload.cc @@ -2,21 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/android/base_jni_registrar.h" #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" +#include "testing/android/native_test/native_test_launcher.h" namespace { bool RegisterJNI(JNIEnv* env) { - return content::android::RegisterShellJni(env) && - content::NestedMessagePumpAndroid::RegisterJni(env) && - components::RegisterComponentsBrowserTestsAndroid(env); + return base::android::RegisterJni(env) && + content::android::RegisterShellJni(env) && + content::NestedMessagePumpAndroid::RegisterJni(env) && + testing::android::RegisterNativeTestJNI(env); } bool Init() { 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 index bbf2461..ae94edc 100644 --- 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 @@ -4,43 +4,44 @@ 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.Log; 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.native_test.NativeBrowserTestActivity; 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"; +public class ComponentsBrowserTestsActivity extends NativeBrowserTestActivity { + private static final String TAG = Log.makeTag("native_test"); private ShellManager mShellManager; private WindowAndroid mWindowAndroid; @Override - @SuppressFBWarnings("DM_EXIT") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + appendCommandLineFlags( + "--remote-debugging-socket-name components_browsertests_devtools_remote"); + } + @Override + @SuppressFBWarnings("DM_EXIT") + protected void initializeBrowserProcess() { try { LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); } catch (ProcessInitException e) { - Log.i(TAG, "Cannot load components_browsertests:" + e); + Log.e(TAG, "Cannot load components_browsertests.", e); System.exit(-1); } BrowserStartupController.get(getApplicationContext(), LibraryProcessType.PROCESS_BROWSER) @@ -55,21 +56,5 @@ public class ComponentsBrowserTestsActivity extends Activity { 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); } |