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/jni_android.h" | |
| 29 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 30 #include "content/public/test/nested_message_pump_android.h" | 29 #include "content/shell/shell_layout_tests_android.h" |
| 31 #endif | 30 #endif |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 #if defined(OS_ANDROID) | |
| 36 // Path to search for when translating a layout test path to an URL. | |
| 37 const char kAndroidLayoutTestPath[] = | |
| 38 "/data/local/tmp/third_party/WebKit/LayoutTests/"; | |
| 39 | |
| 40 // The base URL from which layout tests are being served on Android. | |
| 41 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; | |
| 42 | |
| 43 base::MessagePump* CreateMessagePumpForUI() { | |
| 44 return new content::NestedMessagePumpAndroid(); | |
| 45 } | |
| 46 | |
| 47 #endif | |
| 48 | |
| 49 GURL GetURLForLayoutTest(const std::string& test_name, | 34 GURL GetURLForLayoutTest(const std::string& test_name, |
| 50 base::FilePath* current_working_directory, | 35 base::FilePath* current_working_directory, |
| 51 bool* enable_pixel_dumping, | 36 bool* enable_pixel_dumping, |
| 52 std::string* expected_pixel_hash) { | 37 std::string* expected_pixel_hash) { |
| 53 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 38 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
| 54 std::string path_or_url = test_name; | 39 std::string path_or_url = test_name; |
| 55 std::string pixel_switch; | 40 std::string pixel_switch; |
| 56 std::string pixel_hash; | 41 std::string pixel_hash; |
| 57 std::string::size_type separator_position = path_or_url.find('\''); | 42 std::string::size_type separator_position = path_or_url.find('\''); |
| 58 if (separator_position != std::string::npos) { | 43 if (separator_position != std::string::npos) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 73 | 58 |
| 74 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
| 75 // On Android, all passed tests will be paths to a local temporary directory. | 60 // On Android, all passed tests will be paths to a local temporary directory. |
| 76 // However, because we can't transfer all test files to the device, translate | 61 // However, because we can't transfer all test files to the device, translate |
| 77 // those paths to a local, forwarded URL so the host can serve them. | 62 // those paths to a local, forwarded URL so the host can serve them. |
| 78 if (path_or_url.find(kAndroidLayoutTestPath) != std::string::npos) { | 63 if (path_or_url.find(kAndroidLayoutTestPath) != std::string::npos) { |
| 79 std::string test_location(kAndroidLayoutTestBase); | 64 std::string test_location(kAndroidLayoutTestBase); |
| 80 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); | 65 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); |
| 81 | 66 |
| 82 return GURL(test_location); | 67 return GURL(test_location); |
| 83 } | 68 } |
|
bulach
2013/06/19 17:57:42
nit: move this out to a separate function in the o
Peter Beverloo
2013/06/19 19:48:32
Done.
| |
| 84 #endif | 69 #endif |
| 85 | 70 |
| 86 GURL test_url(path_or_url); | 71 GURL test_url(path_or_url); |
| 87 if (!(test_url.is_valid() && test_url.has_scheme())) { | 72 if (!(test_url.is_valid() && test_url.has_scheme())) { |
| 88 // We're outside of the message loop here, and this is a test. | 73 // We're outside of the message loop here, and this is a test. |
| 89 base::ThreadRestrictions::ScopedAllowIO allow_io; | 74 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 90 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 91 std::wstring wide_path_or_url = | 76 std::wstring wide_path_or_url = |
| 92 base::SysNativeMBToWide(path_or_url); | 77 base::SysNativeMBToWide(path_or_url); |
| 93 base::FilePath local_file(wide_path_or_url); | 78 base::FilePath local_file(wide_path_or_url); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 124 #else | 109 #else |
| 125 *test = args[(*position)++]; | 110 *test = args[(*position)++]; |
| 126 #endif | 111 #endif |
| 127 return true; | 112 return true; |
| 128 } | 113 } |
| 129 | 114 |
| 130 } // namespace | 115 } // namespace |
| 131 | 116 |
| 132 // Main routine for running as the Browser process. | 117 // Main routine for running as the Browser process. |
| 133 int ShellBrowserMain(const content::MainFunctionParams& parameters, | 118 int ShellBrowserMain(const content::MainFunctionParams& parameters, |
| 134 scoped_ptr<content::BrowserMainRunner>& main_runner) { | 119 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
| 135 bool layout_test_mode = | 120 bool layout_test_mode = |
| 136 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 121 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
| 137 base::ScopedTempDir browser_context_path_for_layout_tests; | 122 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 138 | 123 |
| 139 if (layout_test_mode) { | 124 if (layout_test_mode) { |
| 140 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 125 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 141 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 126 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| 142 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 127 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 143 switches::kContentShellDataPath, | 128 switches::kContentShellDataPath, |
| 144 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | 129 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
| 145 | 130 |
| 146 #if defined(OS_ANDROID) | 131 #if defined(OS_ANDROID) |
| 147 // TODO(beverloo): Create the FIFOs required for Android layout tests. | 132 EnsureCreateAndroidNestedMessagePump(); |
| 148 | 133 EnsureCreateAndroidFIFOs(); |
|
bulach
2013/06/19 17:57:42
nit: just expose one function, like "InitializeFor
Peter Beverloo
2013/06/19 19:48:32
Done.
| |
| 149 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 150 content::NestedMessagePumpAndroid::RegisterJni(env); | |
| 151 | |
| 152 const bool success = base::MessageLoop::InitMessagePumpForUIFactory( | |
| 153 &CreateMessagePumpForUI); | |
| 154 CHECK(success) << "Unable to initialize the message pump for Android."; | |
| 155 #endif | 134 #endif |
| 156 } | 135 } |
| 157 | 136 |
| 158 int exit_code = main_runner->Initialize(parameters); | 137 int exit_code = main_runner->Initialize(parameters); |
| 159 DCHECK(exit_code < 0) | 138 DCHECK_LT(exit_code, 0) |
| 160 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 139 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; |
| 161 | 140 |
| 162 if (exit_code >= 0) | 141 if (exit_code >= 0) |
| 163 return exit_code; | 142 return exit_code; |
| 164 | 143 |
| 165 if (CommandLine::ForCurrentProcess()->HasSwitch( | 144 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 166 switches::kCheckLayoutTestSysDeps)) { | 145 switches::kCheckLayoutTestSysDeps)) { |
| 167 base::MessageLoop::current()->PostTask(FROM_HERE, | 146 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 168 base::MessageLoop::QuitClosure()); | 147 base::MessageLoop::QuitClosure()); |
| 169 main_runner->Run(); | 148 main_runner->Run(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 211 |
| 233 #if !defined(OS_ANDROID) | 212 #if !defined(OS_ANDROID) |
| 234 if (!layout_test_mode) | 213 if (!layout_test_mode) |
| 235 exit_code = main_runner->Run(); | 214 exit_code = main_runner->Run(); |
| 236 | 215 |
| 237 main_runner->Shutdown(); | 216 main_runner->Shutdown(); |
| 238 #endif | 217 #endif |
| 239 | 218 |
| 240 return exit_code; | 219 return exit_code; |
| 241 } | 220 } |
| OLD | NEW |