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) { |
59 pixel_switch = path_or_url.substr(separator_position + 1); | 44 pixel_switch = path_or_url.substr(separator_position + 1); |
60 path_or_url.erase(separator_position); | 45 path_or_url.erase(separator_position); |
61 } | 46 } |
62 separator_position = pixel_switch.find('\''); | 47 separator_position = pixel_switch.find('\''); |
63 if (separator_position != std::string::npos) { | 48 if (separator_position != std::string::npos) { |
64 pixel_hash = pixel_switch.substr(separator_position + 1); | 49 pixel_hash = pixel_switch.substr(separator_position + 1); |
65 pixel_switch.erase(separator_position); | 50 pixel_switch.erase(separator_position); |
66 } | 51 } |
67 if (enable_pixel_dumping) { | 52 if (enable_pixel_dumping) { |
68 *enable_pixel_dumping = | 53 *enable_pixel_dumping = |
69 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); | 54 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); |
70 } | 55 } |
71 if (expected_pixel_hash) | 56 if (expected_pixel_hash) |
72 *expected_pixel_hash = pixel_hash; | 57 *expected_pixel_hash = pixel_hash; |
73 | 58 |
| 59 GURL test_url; |
74 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
75 // On Android, all passed tests will be paths to a local temporary directory. | 61 if (content::GetTestUrlForAndroid(path_or_url, &test_url)) |
76 // However, because we can't transfer all test files to the device, translate | 62 return test_url; |
77 // those paths to a local, forwarded URL so the host can serve them. | |
78 if (path_or_url.find(kAndroidLayoutTestPath) != std::string::npos) { | |
79 std::string test_location(kAndroidLayoutTestBase); | |
80 test_location.append(path_or_url.substr(strlen(kAndroidLayoutTestPath))); | |
81 | |
82 return GURL(test_location); | |
83 } | |
84 #endif | 63 #endif |
85 | 64 |
86 GURL test_url(path_or_url); | 65 test_url = GURL(path_or_url); |
87 if (!(test_url.is_valid() && test_url.has_scheme())) { | 66 if (!(test_url.is_valid() && test_url.has_scheme())) { |
88 // We're outside of the message loop here, and this is a test. | 67 // We're outside of the message loop here, and this is a test. |
89 base::ThreadRestrictions::ScopedAllowIO allow_io; | 68 base::ThreadRestrictions::ScopedAllowIO allow_io; |
90 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
91 std::wstring wide_path_or_url = | 70 std::wstring wide_path_or_url = |
92 base::SysNativeMBToWide(path_or_url); | 71 base::SysNativeMBToWide(path_or_url); |
93 base::FilePath local_file(wide_path_or_url); | 72 base::FilePath local_file(wide_path_or_url); |
94 #else | 73 #else |
95 base::FilePath local_file(path_or_url); | 74 base::FilePath local_file(path_or_url); |
96 #endif | 75 #endif |
(...skipping 26 matching lines...) Expand all Loading... |
123 *test = WideToUTF8(args[(*position)++]); | 102 *test = WideToUTF8(args[(*position)++]); |
124 #else | 103 #else |
125 *test = args[(*position)++]; | 104 *test = args[(*position)++]; |
126 #endif | 105 #endif |
127 return true; | 106 return true; |
128 } | 107 } |
129 | 108 |
130 } // namespace | 109 } // namespace |
131 | 110 |
132 // Main routine for running as the Browser process. | 111 // Main routine for running as the Browser process. |
133 int ShellBrowserMain(const content::MainFunctionParams& parameters, | 112 int ShellBrowserMain( |
134 scoped_ptr<content::BrowserMainRunner>& main_runner) { | 113 const content::MainFunctionParams& parameters, |
| 114 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
135 bool layout_test_mode = | 115 bool layout_test_mode = |
136 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 116 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
137 base::ScopedTempDir browser_context_path_for_layout_tests; | 117 base::ScopedTempDir browser_context_path_for_layout_tests; |
138 | 118 |
139 if (layout_test_mode) { | 119 if (layout_test_mode) { |
140 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 120 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
141 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 121 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
142 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 122 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
143 switches::kContentShellDataPath, | 123 switches::kContentShellDataPath, |
144 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | 124 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
145 | 125 |
146 #if defined(OS_ANDROID) | 126 #if defined(OS_ANDROID) |
147 // TODO(beverloo): Create the FIFOs required for Android layout tests. | 127 content::EnsureInitializeForAndroidLayoutTests(); |
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 | 128 #endif |
156 } | 129 } |
157 | 130 |
158 int exit_code = main_runner->Initialize(parameters); | 131 int exit_code = main_runner->Initialize(parameters); |
159 DCHECK(exit_code < 0) | 132 DCHECK_LT(exit_code, 0) |
160 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 133 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; |
161 | 134 |
162 if (exit_code >= 0) | 135 if (exit_code >= 0) |
163 return exit_code; | 136 return exit_code; |
164 | 137 |
165 if (CommandLine::ForCurrentProcess()->HasSwitch( | 138 if (CommandLine::ForCurrentProcess()->HasSwitch( |
166 switches::kCheckLayoutTestSysDeps)) { | 139 switches::kCheckLayoutTestSysDeps)) { |
167 base::MessageLoop::current()->PostTask(FROM_HERE, | 140 base::MessageLoop::current()->PostTask(FROM_HERE, |
168 base::MessageLoop::QuitClosure()); | 141 base::MessageLoop::QuitClosure()); |
169 main_runner->Run(); | 142 main_runner->Run(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 205 |
233 #if !defined(OS_ANDROID) | 206 #if !defined(OS_ANDROID) |
234 if (!layout_test_mode) | 207 if (!layout_test_mode) |
235 exit_code = main_runner->Run(); | 208 exit_code = main_runner->Run(); |
236 | 209 |
237 main_runner->Shutdown(); | 210 main_runner->Shutdown(); |
238 #endif | 211 #endif |
239 | 212 |
240 return exit_code; | 213 return exit_code; |
241 } | 214 } |
OLD | NEW |