| 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) |
| 28 #include "base/android/jni_android.h" |
| 29 #include "base/run_loop.h" |
| 30 #include "content/public/test/nested_message_pump_android.h" |
| 31 #endif |
| 32 |
| 27 namespace { | 33 namespace { |
| 28 | 34 |
| 29 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
| 30 // Path to search for when translating a layout test path to an URL. | 36 // Path to search for when translating a layout test path to an URL. |
| 31 const char kAndroidLayoutTestPath[] = | 37 const char kAndroidLayoutTestPath[] = |
| 32 "/data/local/tmp/third_party/WebKit/LayoutTests/"; | 38 "/data/local/tmp/third_party/WebKit/LayoutTests/"; |
| 33 | 39 |
| 34 // The base URL from which layout tests are being served on Android. | 40 // The base URL from which layout tests are being served on Android. |
| 35 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; | 41 const char kAndroidLayoutTestBase[] = "http://127.0.0.1:8000/all-tests/"; |
| 42 |
| 43 base::MessagePump* CreateMessagePumpForUI() { |
| 44 return new content::NestedMessagePumpAndroid(); |
| 45 } |
| 46 |
| 36 #endif | 47 #endif |
| 37 | 48 |
| 38 GURL GetURLForLayoutTest(const std::string& test_name, | 49 GURL GetURLForLayoutTest(const std::string& test_name, |
| 39 base::FilePath* current_working_directory, | 50 base::FilePath* current_working_directory, |
| 40 bool* enable_pixel_dumping, | 51 bool* enable_pixel_dumping, |
| 41 std::string* expected_pixel_hash) { | 52 std::string* expected_pixel_hash) { |
| 42 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 53 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
| 43 std::string path_or_url = test_name; | 54 std::string path_or_url = test_name; |
| 44 std::string pixel_switch; | 55 std::string pixel_switch; |
| 45 std::string pixel_hash; | 56 std::string pixel_hash; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 129 |
| 119 } // namespace | 130 } // namespace |
| 120 | 131 |
| 121 // Main routine for running as the Browser process. | 132 // Main routine for running as the Browser process. |
| 122 int ShellBrowserMain(const content::MainFunctionParams& parameters, | 133 int ShellBrowserMain(const content::MainFunctionParams& parameters, |
| 123 scoped_ptr<content::BrowserMainRunner>& main_runner) { | 134 scoped_ptr<content::BrowserMainRunner>& main_runner) { |
| 124 bool layout_test_mode = | 135 bool layout_test_mode = |
| 125 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 136 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
| 126 base::ScopedTempDir browser_context_path_for_layout_tests; | 137 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 127 | 138 |
| 128 // TODO(beverloo): Create the FIFOs required for Android layout tests. | |
| 129 | |
| 130 if (layout_test_mode) { | 139 if (layout_test_mode) { |
| 131 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 140 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 132 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 141 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| 133 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 142 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 134 switches::kContentShellDataPath, | 143 switches::kContentShellDataPath, |
| 135 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | 144 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
| 145 |
| 146 #if defined(OS_ANDROID) |
| 147 // TODO(beverloo): Create the FIFOs required for Android layout tests. |
| 148 |
| 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 |
| 136 } | 156 } |
| 137 | 157 |
| 138 int exit_code = main_runner->Initialize(parameters); | 158 int exit_code = main_runner->Initialize(parameters); |
| 139 DCHECK(exit_code < 0) | 159 DCHECK(exit_code < 0) |
| 140 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 160 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; |
| 141 | 161 |
| 142 if (exit_code >= 0) | 162 if (exit_code >= 0) |
| 143 return exit_code; | 163 return exit_code; |
| 144 | 164 |
| 145 if (CommandLine::ForCurrentProcess()->HasSwitch( | 165 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 std::string pixel_hash; | 202 std::string pixel_hash; |
| 183 base::FilePath cwd; | 203 base::FilePath cwd; |
| 184 GURL test_url = GetURLForLayoutTest( | 204 GURL test_url = GetURLForLayoutTest( |
| 185 test_string, &cwd, &enable_pixel_dumps, &pixel_hash); | 205 test_string, &cwd, &enable_pixel_dumps, &pixel_hash); |
| 186 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( | 206 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( |
| 187 test_url, cwd, enable_pixel_dumps, pixel_hash)) { | 207 test_url, cwd, enable_pixel_dumps, pixel_hash)) { |
| 188 break; | 208 break; |
| 189 } | 209 } |
| 190 | 210 |
| 191 ran_at_least_once = true; | 211 ran_at_least_once = true; |
| 212 #if defined(OS_ANDROID) |
| 213 // The message loop on Android is provided by the system, and does not |
| 214 // offer a blocking Run() method. For layout tests, use a nested loop |
| 215 // together with a base::RunLoop so it can block until a QuitClosure. |
| 216 base::RunLoop run_loop; |
| 217 run_loop.Run(); |
| 218 #else |
| 192 main_runner->Run(); | 219 main_runner->Run(); |
| 220 #endif |
| 193 | 221 |
| 194 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) | 222 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) |
| 195 break; | 223 break; |
| 196 } | 224 } |
| 197 if (!ran_at_least_once) { | 225 if (!ran_at_least_once) { |
| 198 base::MessageLoop::current()->PostTask(FROM_HERE, | 226 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 199 base::MessageLoop::QuitClosure()); | 227 base::MessageLoop::QuitClosure()); |
| 200 main_runner->Run(); | 228 main_runner->Run(); |
| 201 } | 229 } |
| 202 exit_code = 0; | 230 exit_code = 0; |
| 203 } | 231 } |
| 204 | 232 |
| 205 #if !defined(OS_ANDROID) | 233 #if !defined(OS_ANDROID) |
| 206 if (!layout_test_mode) | 234 if (!layout_test_mode) |
| 207 exit_code = main_runner->Run(); | 235 exit_code = main_runner->Run(); |
| 208 | 236 |
| 209 main_runner->Shutdown(); | 237 main_runner->Shutdown(); |
| 210 #endif | 238 #endif |
| 211 | 239 |
| 212 return exit_code; | 240 return exit_code; |
| 213 } | 241 } |
| OLD | NEW |