Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: components/test/android/browsertests_apk/components_browser_tests_android.cc

Issue 1075783002: Enable components_browsertests on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN build and add java dependency to components/test/DEPS Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This class sets up the environment for running the content browser tests 5 // This class sets up the environment for running the content browser tests
6 // inside an android application. 6 // inside an android application.
7 7
8 #include <android/log.h> 8 #include <android/log.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include "base/android/base_jni_registrar.h" 11 #include "base/android/base_jni_registrar.h"
12 #include "base/android/fifo_utils.h" 12 #include "base/android/fifo_utils.h"
13 #include "base/android/jni_android.h" 13 #include "base/android/jni_android.h"
14 #include "base/android/jni_string.h" 14 #include "base/android/jni_string.h"
15 #include "base/android/library_loader/library_loader_hooks.h" 15 #include "base/android/library_loader/library_loader_hooks.h"
16 #include "base/android/scoped_java_ref.h" 16 #include "base/android/scoped_java_ref.h"
17 #include "base/base_switches.h" 17 #include "base/base_switches.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/strings/string_tokenizer.h" 21 #include "base/strings/string_tokenizer.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
25 #include "content/public/test/test_launcher.h" 25 #include "content/public/test/test_launcher.h"
26 #include "content/shell/android/shell_jni_registrar.h" 26 #include "jni/ComponentsBrowserTestsActivity_jni.h"
27 #include "content/shell/app/shell_main_delegate.h"
28 #include "jni/ContentBrowserTestsActivity_jni.h"
29 #include "media/base/media_switches.h" 27 #include "media/base/media_switches.h"
30 #include "testing/android/native_test/native_test_util.h" 28 #include "testing/android/native_test/native_test_util.h"
31 29
32 using testing::native_test_util::ArgsToArgv; 30 using testing::native_test_util::ArgsToArgv;
33 using testing::native_test_util::ParseArgsFromCommandLineFile; 31 using testing::native_test_util::ParseArgsFromCommandLineFile;
34 using testing::native_test_util::ScopedMainEntryLogger; 32 using testing::native_test_util::ScopedMainEntryLogger;
35 33
36 // The main function of the program to be wrapped as an apk. 34 // The main function of the program to be wrapped as an apk.
37 extern int main(int argc, char** argv); 35 extern int main(int argc, char** argv);
38 36
39 namespace { 37 namespace {
40 38
41 // The test runner script writes the command line file in 39 // The test runner script writes the command line file in
42 // "/data/local/tmp". 40 // "/data/local/tmp".
43 static const char kCommandLineFilePath[] = 41 static const char kCommandLineFilePath[] =
44 "/data/local/tmp/content-browser-tests-command-line"; 42 "/data/local/tmp/components-browser-tests-command-line";
45 43
46 } // namespace 44 } // namespace
47 45
48 namespace content { 46 namespace components {
49 47
50 // TODO(nileshagrawal): Refactor and deduplicate with 48 // TODO(jaekyun): Refactor and deduplicate with
51 // testing/android/native_test_launcher.cc 49 // testing/android/native_test/native_test_launcher.cc (http://crbug.com/476410)
52 static void RunTests(JNIEnv* env, 50 static void RunTests(JNIEnv* env,
53 jobject obj, 51 jobject obj,
54 jstring jfiles_dir, 52 jstring jfiles_dir,
55 jobject app_context) { 53 jobject app_context) {
56 // Command line basic initialization, will be fully initialized later. 54 // Command line basic initialization, will be fully initialized later.
57 static const char* const kInitialArgv[] = { "ContentBrowserTestsActivity" }; 55 static const char* const kInitialArgv[] = {"ComponentsBrowserTestsActivity"};
58 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); 56 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv);
59 57
60 // Set the application context in base. 58 // Set the application context in base.
61 base::android::ScopedJavaLocalRef<jobject> scoped_context( 59 base::android::ScopedJavaLocalRef<jobject> scoped_context(
62 env, env->NewLocalRef(app_context)); 60 env, env->NewLocalRef(app_context));
63 base::android::InitApplicationContext(env, scoped_context); 61 base::android::InitApplicationContext(env, scoped_context);
64 base::android::RegisterJni(env); 62 base::android::RegisterJni(env);
65 63
66 std::vector<std::string> args; 64 std::vector<std::string> args;
67 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args); 65 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args);
68 66
69 std::vector<char*> argv; 67 std::vector<char*> argv;
70 int argc = ArgsToArgv(args, &argv); 68 int argc = ArgsToArgv(args, &argv);
71 69
72 // Fully initialize command line with arguments. 70 // Fully initialize command line with arguments.
73 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
74 command_line->AppendArguments(base::CommandLine(argc, &argv[0]), false); 72 command_line->AppendArguments(base::CommandLine(argc, &argv[0]), false);
75 73
76 // Append required switches. 74 // Append required switches.
77 command_line->AppendSwitch(content::kSingleProcessTestsFlag); 75 command_line->AppendSwitch(content::kSingleProcessTestsFlag);
78 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); 76 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
79 command_line->AppendSwitch(switches::kUseFakeUIForMediaStream); 77 command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
80 // Specify a socket name to not conflict with the default one used 78 // Specify a socket name to not conflict with the default one used
81 // in content_shell. 79 // in content_shell.
82 command_line->AppendSwitchASCII(switches::kRemoteDebuggingSocketName, 80 command_line->AppendSwitchASCII(switches::kRemoteDebuggingSocketName,
83 "content_browsertests_devtools_remote"); 81 "components_browsertests_devtools_remote");
84 82
85 // Create fifo and redirect stdout and stderr to it. 83 // Create fifo and redirect stdout and stderr to it.
86 base::FilePath files_dir( 84 base::FilePath files_dir(
87 base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); 85 base::android::ConvertJavaStringToUTF8(env, jfiles_dir));
88 base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo"))); 86 base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo")));
89 base::android::CreateFIFO(fifo_path, 0666); 87 base::android::CreateFIFO(fifo_path, 0666);
90 base::android::RedirectStream(stdout, fifo_path, "w+"); 88 base::android::RedirectStream(stdout, fifo_path, "w+");
91 dup2(STDOUT_FILENO, STDERR_FILENO); 89 dup2(STDOUT_FILENO, STDERR_FILENO);
92 90
93 ScopedMainEntryLogger scoped_main_entry_logger; 91 ScopedMainEntryLogger scoped_main_entry_logger;
94 main(argc, &argv[0]); 92 main(argc, &argv[0]);
95 } 93 }
96 94
97 bool RegisterContentBrowserTestsAndroid(JNIEnv* env) { 95 bool RegisterComponentsBrowserTestsAndroid(JNIEnv* env) {
98 return RegisterNativesImpl(env); 96 return RegisterNativesImpl(env);
99 } 97 }
100 98
101 } // namespace content 99 } // namespace components
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698