Chromium Code Reviews| 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 #include "content/shell/shell_browser_main.h" | 5 #include "content/shell/shell_browser_main.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "content/public/browser/browser_main_runner.h" | 19 #include "content/public/browser/browser_main_runner.h" |
| 20 #include "content/shell/common/shell_switches.h" | 20 #include "content/shell/common/shell_switches.h" |
| 21 #include "content/shell/common/webkit_test_helpers.h" | 21 #include "content/shell/common/webkit_test_helpers.h" |
| 22 #include "content/shell/shell.h" | 22 #include "content/shell/shell.h" |
| 23 #include "content/shell/webkit_test_controller.h" | 23 #include "content/shell/webkit_test_controller.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "webkit/support/webkit_support.h" | 25 #include "webkit/support/webkit_support.h" |
| 26 | 26 |
| 27 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 28 #include "base/android/fifo_utils.h" | |
| 28 #include "base/android/jni_android.h" | 29 #include "base/android/jni_android.h" |
| 29 #include "base/run_loop.h" | 30 #include "base/run_loop.h" |
| 30 #include "content/public/test/nested_message_pump_android.h" | 31 #include "content/public/test/nested_message_pump_android.h" |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 37 // Directory on the device where the FIFOs will be created. The value of this | |
| 38 // constant must by synchronized with that in the chromium_android.py file. | |
| 39 const char kAndroidFifoPath[] = | |
|
bulach
2013/06/19 14:42:14
see below, looks like we can gather this from java
jochen (gone - plz use gerrit)
2013/06/19 15:37:13
and it should be FILE_PATH_LITERAL(), no? also kAn
Peter Beverloo
2013/06/19 17:40:28
Done.
| |
| 40 "/data/data/org.chromium.content_shell_apk/files/"; | |
| 41 | |
| 36 // Path to search for when translating a layout test path to an URL. | 42 // Path to search for when translating a layout test path to an URL. |
| 37 const char kAndroidLayoutTestPath[] = | 43 const char kAndroidLayoutTestPath[] = |
| 38 "/data/local/tmp/third_party/WebKit/LayoutTests/"; | 44 "/data/local/tmp/third_party/WebKit/LayoutTests/"; |
| 39 | 45 |
| 40 // The base URL from which layout tests are being served on Android. | 46 // The base URL from which layout tests are being served on Android. |
| 41 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; | 47 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; |
| 42 | 48 |
| 49 void EnsureCreateFIFO(const base::FilePath& path) { | |
| 50 unlink(path.value().c_str()); | |
| 51 CHECK(base::android::CreateFIFO(path, 0666)) | |
| 52 << "Unable to create one of Android's FIFOs: " << path.value().c_str(); | |
| 53 } | |
| 54 | |
| 55 bool CreateAndroidFIFOs() { | |
| 56 // Android will need three FIFOs to communicate with the Blink test runner, | |
| 57 // one for each of [stdout, stderr, stdin]. Redirecting stdout needs to happen | |
| 58 // before redirecting stdin, which needs to happen before redirecting stderr. | |
| 59 base::FilePath files_dir(kAndroidFifoPath); | |
| 60 | |
| 61 base::FilePath stdout_fifo(files_dir.Append(base::FilePath("test.fifo"))); | |
|
jochen (gone - plz use gerrit)
2013/06/19 15:37:13
also FILE_PATH_LITERAL() instead of full filepath
Peter Beverloo
2013/06/19 17:40:28
Done.
| |
| 62 EnsureCreateFIFO(stdout_fifo); | |
| 63 | |
| 64 base::FilePath stderr_fifo(files_dir.Append(base::FilePath("stderr.fifo"))); | |
| 65 EnsureCreateFIFO(stderr_fifo); | |
| 66 | |
| 67 base::FilePath stdin_fifo(files_dir.Append(base::FilePath("stdin.fifo"))); | |
| 68 EnsureCreateFIFO(stdin_fifo); | |
| 69 | |
| 70 return base::android::RedirectStream(stdout, stdout_fifo, "w") && | |
| 71 base::android::RedirectStream(stdin, stdin_fifo, "r") && | |
| 72 base::android::RedirectStream(stderr, stderr_fifo, "w"); | |
| 73 } | |
| 74 | |
| 43 base::MessagePump* CreateMessagePumpForUI() { | 75 base::MessagePump* CreateMessagePumpForUI() { |
| 44 return new content::NestedMessagePumpAndroid(); | 76 return new content::NestedMessagePumpAndroid(); |
| 45 } | 77 } |
|
bulach
2013/06/19 14:42:14
how about moving this entire block to a shell_layo
Peter Beverloo
2013/06/19 17:40:28
Done.
| |
| 46 | 78 |
| 47 #endif | 79 #endif |
| 48 | 80 |
| 49 GURL GetURLForLayoutTest(const std::string& test_name, | 81 GURL GetURLForLayoutTest(const std::string& test_name, |
| 50 base::FilePath* current_working_directory, | 82 base::FilePath* current_working_directory, |
| 51 bool* enable_pixel_dumping, | 83 bool* enable_pixel_dumping, |
| 52 std::string* expected_pixel_hash) { | 84 std::string* expected_pixel_hash) { |
| 53 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 85 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
| 54 std::string path_or_url = test_name; | 86 std::string path_or_url = test_name; |
| 55 std::string pixel_switch; | 87 std::string pixel_switch; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 base::ScopedTempDir browser_context_path_for_layout_tests; | 169 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 138 | 170 |
| 139 if (layout_test_mode) { | 171 if (layout_test_mode) { |
| 140 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 172 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 141 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 173 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| 142 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 174 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 143 switches::kContentShellDataPath, | 175 switches::kContentShellDataPath, |
| 144 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | 176 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
| 145 | 177 |
| 146 #if defined(OS_ANDROID) | 178 #if defined(OS_ANDROID) |
| 147 // TODO(beverloo): Create the FIFOs required for Android layout tests. | |
| 148 | |
| 149 JNIEnv* env = base::android::AttachCurrentThread(); | 179 JNIEnv* env = base::android::AttachCurrentThread(); |
| 150 content::NestedMessagePumpAndroid::RegisterJni(env); | 180 content::NestedMessagePumpAndroid::RegisterJni(env); |
| 151 | 181 |
| 152 const bool success = base::MessageLoop::InitMessagePumpForUIFactory( | 182 const bool success = base::MessageLoop::InitMessagePumpForUIFactory( |
| 153 &CreateMessagePumpForUI); | 183 &CreateMessagePumpForUI); |
| 154 CHECK(success) << "Unable to initialize the message pump for Android."; | 184 CHECK(success) << "Unable to initialize the message pump for Android."; |
| 185 | |
| 186 CHECK(CreateAndroidFIFOs()) << "Unable to initialize the Android FIFOs."; | |
|
bulach
2013/06/19 14:42:14
since this one has JNI available, you can add a @C
Peter Beverloo
2013/06/19 17:40:28
Done.
| |
| 155 #endif | 187 #endif |
| 156 } | 188 } |
| 157 | 189 |
| 158 int exit_code = main_runner->Initialize(parameters); | 190 int exit_code = main_runner->Initialize(parameters); |
| 159 DCHECK(exit_code < 0) | 191 DCHECK(exit_code < 0) |
| 160 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 192 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; |
| 161 | 193 |
| 162 if (exit_code >= 0) | 194 if (exit_code >= 0) |
| 163 return exit_code; | 195 return exit_code; |
| 164 | 196 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 264 |
| 233 #if !defined(OS_ANDROID) | 265 #if !defined(OS_ANDROID) |
| 234 if (!layout_test_mode) | 266 if (!layout_test_mode) |
| 235 exit_code = main_runner->Run(); | 267 exit_code = main_runner->Run(); |
| 236 | 268 |
| 237 main_runner->Shutdown(); | 269 main_runner->Shutdown(); |
| 238 #endif | 270 #endif |
| 239 | 271 |
| 240 return exit_code; | 272 return exit_code; |
| 241 } | 273 } |
| OLD | NEW |