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_util.h" | 16 #include "base/file_util.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.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/public/app/content_main.h" |
| 24 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/test/test_launcher.h" |
24 #include "content/shell/android/shell_jni_registrar.h" | 26 #include "content/shell/android/shell_jni_registrar.h" |
25 #include "content/shell/shell_main_delegate.h" | 27 #include "content/shell/shell_main_delegate.h" |
26 #include "content/test/browser_test_message_pump_android.h" | 28 #include "content/test/browser_test_message_pump_android.h" |
27 #include "jni/ContentBrowserTestsActivity_jni.h" | 29 #include "jni/ContentBrowserTestsActivity_jni.h" |
28 #include "testing/android/native_test_util.h" | 30 #include "testing/android/native_test_util.h" |
29 | 31 |
30 using testing::native_test_util::ArgsToArgv; | 32 using testing::native_test_util::ArgsToArgv; |
31 using testing::native_test_util::CreateFIFO; | 33 using testing::native_test_util::CreateFIFO; |
32 using testing::native_test_util::ParseArgsFromCommandLineFile; | 34 using testing::native_test_util::ParseArgsFromCommandLineFile; |
33 using testing::native_test_util::RedirectStream; | 35 using testing::native_test_util::RedirectStream; |
(...skipping 28 matching lines...) Expand all Loading... |
62 base::android::InitApplicationContext(scoped_context); | 64 base::android::InitApplicationContext(scoped_context); |
63 base::android::RegisterJni(env); | 65 base::android::RegisterJni(env); |
64 | 66 |
65 std::vector<std::string> args; | 67 std::vector<std::string> args; |
66 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args); | 68 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args); |
67 | 69 |
68 std::vector<char*> argv; | 70 std::vector<char*> argv; |
69 int argc = ArgsToArgv(args, &argv); | 71 int argc = ArgsToArgv(args, &argv); |
70 | 72 |
71 // Fully initialize command line with arguments. | 73 // Fully initialize command line with arguments. |
72 CommandLine::ForCurrentProcess()->AppendArguments( | 74 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
73 CommandLine(argc, &argv[0]), false); | 75 command_line->AppendArguments(CommandLine(argc, &argv[0]), false); |
| 76 |
| 77 // Append required switches. |
| 78 command_line->AppendSwitch(content::kSingleProcessTestsFlag); |
| 79 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
74 | 80 |
75 // Create fifo and redirect stdout and stderr to it. | 81 // Create fifo and redirect stdout and stderr to it. |
76 base::FilePath files_dir( | 82 base::FilePath files_dir( |
77 base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); | 83 base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); |
78 base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo"))); | 84 base::FilePath fifo_path(files_dir.Append(base::FilePath("test.fifo"))); |
79 CreateFIFO(fifo_path.value().c_str()); | 85 CreateFIFO(fifo_path.value().c_str()); |
80 RedirectStream(stdout, fifo_path.value().c_str(), "w"); | 86 RedirectStream(stdout, fifo_path.value().c_str(), "w"); |
81 dup2(STDOUT_FILENO, STDERR_FILENO); | 87 dup2(STDOUT_FILENO, STDERR_FILENO); |
82 | 88 |
83 ScopedMainEntryLogger scoped_main_entry_logger; | 89 ScopedMainEntryLogger scoped_main_entry_logger; |
(...skipping 14 matching lines...) Expand all Loading... |
98 | 104 |
99 if (!content::BrowserTestMessagePumpAndroid::RegisterJni(env)) | 105 if (!content::BrowserTestMessagePumpAndroid::RegisterJni(env)) |
100 return -1; | 106 return -1; |
101 | 107 |
102 if (!content::RegisterNativesImpl(env)) | 108 if (!content::RegisterNativesImpl(env)) |
103 return -1; | 109 return -1; |
104 | 110 |
105 content::SetContentMainDelegate(new content::ShellMainDelegate()); | 111 content::SetContentMainDelegate(new content::ShellMainDelegate()); |
106 return JNI_VERSION_1_4; | 112 return JNI_VERSION_1_4; |
107 } | 113 } |
OLD | NEW |