OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 9 |
10 #include "base/android/base_jni_registrar.h" | 10 #include "base/android/base_jni_registrar.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
14 #include "base/base_switches.h" | 14 #include "base/base_switches.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
21 #include "base/strings/string_tokenizer.h" | 21 #include "base/strings/string_tokenizer.h" |
22 #include "content/public/app/android_library_loader_hooks.h" | 22 #include "content/public/app/android_library_loader_hooks.h" |
| 23 #include "content/public/app/content_main.h" |
23 #include "content/shell/android/shell_jni_registrar.h" | 24 #include "content/shell/android/shell_jni_registrar.h" |
| 25 #include "content/shell/shell_main_delegate.h" |
| 26 #include "content/test/browser_test_message_pump_android.h" |
24 #include "jni/ContentBrowserTestsActivity_jni.h" | 27 #include "jni/ContentBrowserTestsActivity_jni.h" |
25 #include "testing/android/native_test_util.h" | 28 #include "testing/android/native_test_util.h" |
26 | 29 |
27 using testing::native_test_util::ArgsToArgv; | 30 using testing::native_test_util::ArgsToArgv; |
28 using testing::native_test_util::CreateFIFO; | 31 using testing::native_test_util::CreateFIFO; |
29 using testing::native_test_util::ParseArgsFromCommandLineFile; | 32 using testing::native_test_util::ParseArgsFromCommandLineFile; |
30 using testing::native_test_util::RedirectStream; | 33 using testing::native_test_util::RedirectStream; |
31 using testing::native_test_util::ScopedMainEntryLogger; | 34 using testing::native_test_util::ScopedMainEntryLogger; |
32 | 35 |
33 // The main function of the program to be wrapped as an apk. | 36 // The main function of the program to be wrapped as an apk. |
34 extern int main(int argc, char** argv); | 37 extern int main(int argc, char** argv); |
35 | 38 |
36 namespace { | 39 namespace { |
37 | 40 |
38 // The test runner script writes the command line file in | 41 // The test runner script writes the command line file in |
39 // "/data/local/tmp". | 42 // "/data/local/tmp". |
40 static const char kCommandLineFilePath[] = | 43 static const char kCommandLineFilePath[] = |
41 "/data/local/tmp/content-browser-tests-command-line"; | 44 "/data/local/tmp/content-browser-tests-command-line"; |
42 | 45 |
43 } // namespace | 46 } // namespace |
44 | 47 |
| 48 namespace content { |
| 49 |
45 static void RunTests(JNIEnv* env, | 50 static void RunTests(JNIEnv* env, |
46 jobject obj, | 51 jobject obj, |
47 jstring jfiles_dir, | 52 jstring jfiles_dir, |
48 jobject app_context) { | 53 jobject app_context) { |
49 | 54 |
50 // Command line basic initialization, will be fully initialized later. | 55 // Command line basic initialization, will be fully initialized later. |
51 static const char* const kInitialArgv[] = { "ContentBrowserTestsActivity" }; | 56 static const char* const kInitialArgv[] = { "ContentBrowserTestsActivity" }; |
52 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); | 57 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); |
53 | 58 |
54 // Set the application context in base. | 59 // Set the application context in base. |
(...skipping 15 matching lines...) Expand all Loading... |
70 // Create fifo and redirect stdout and stderr to it. | 75 // Create fifo and redirect stdout and stderr to it. |
71 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); | 76 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); |
72 FilePath fifo_path(files_dir.Append(FilePath("test.fifo"))); | 77 FilePath fifo_path(files_dir.Append(FilePath("test.fifo"))); |
73 CreateFIFO(fifo_path.value().c_str()); | 78 CreateFIFO(fifo_path.value().c_str()); |
74 RedirectStream(stdout, fifo_path.value().c_str(), "w"); | 79 RedirectStream(stdout, fifo_path.value().c_str(), "w"); |
75 dup2(STDOUT_FILENO, STDERR_FILENO); | 80 dup2(STDOUT_FILENO, STDERR_FILENO); |
76 | 81 |
77 ScopedMainEntryLogger scoped_main_entry_logger; | 82 ScopedMainEntryLogger scoped_main_entry_logger; |
78 main(argc, &argv[0]); | 83 main(argc, &argv[0]); |
79 } | 84 } |
| 85 } // namespace content |
80 | 86 |
81 // This is called by the VM when the shared library is first loaded. | 87 // This is called by the VM when the shared library is first loaded. |
82 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 88 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
83 base::android::InitVM(vm); | 89 base::android::InitVM(vm); |
84 JNIEnv* env = base::android::AttachCurrentThread(); | 90 JNIEnv* env = base::android::AttachCurrentThread(); |
85 | 91 |
86 if (!content::RegisterLibraryLoaderEntryHook(env)) | 92 if (!content::RegisterLibraryLoaderEntryHook(env)) |
87 return -1; | 93 return -1; |
88 | 94 |
89 if (!content::android::RegisterShellJni(env)) | 95 if (!content::android::RegisterShellJni(env)) |
90 return -1; | 96 return -1; |
91 | 97 |
92 if (!RegisterNativesImpl(env)) | 98 if (!content::BrowserTestMessagePumpAndroid::RegisterJni(env)) |
93 return -1; | 99 return -1; |
94 | 100 |
| 101 if (!content::RegisterNativesImpl(env)) |
| 102 return -1; |
| 103 |
| 104 content::SetContentMainDelegate(new content::ShellMainDelegate()); |
95 return JNI_VERSION_1_4; | 105 return JNI_VERSION_1_4; |
96 } | 106 } |
OLD | NEW |