Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/shell/shell_browser_main.cc

Issue 17076008: content_shell: Move BrowserTestSystemMessageHandler and use it in layout tests for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser_test_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::BrowserTestMessagePumpAndroid();
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
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::BrowserTestMessagePumpAndroid::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
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 // Android never invokes BrowserMainRunner::Run(). Instead, use a bare
214 // base::RunLoop which is closer to what's being used.
bulach 2013/06/17 17:41:22 I guess this deserves a slightly more detailed exp
Peter Beverloo 2013/06/17 18:41:56 I clarified the comment. I also agree that this c
215 base::RunLoop run_loop;
216 run_loop.Run();
217 #else
192 main_runner->Run(); 218 main_runner->Run();
219 #endif
193 220
194 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) 221 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest())
195 break; 222 break;
196 } 223 }
197 if (!ran_at_least_once) { 224 if (!ran_at_least_once) {
198 base::MessageLoop::current()->PostTask(FROM_HERE, 225 base::MessageLoop::current()->PostTask(FROM_HERE,
199 base::MessageLoop::QuitClosure()); 226 base::MessageLoop::QuitClosure());
200 main_runner->Run(); 227 main_runner->Run();
201 } 228 }
202 exit_code = 0; 229 exit_code = 0;
203 } 230 }
204 231
205 #if !defined(OS_ANDROID) 232 #if !defined(OS_ANDROID)
206 if (!layout_test_mode) 233 if (!layout_test_mode)
207 exit_code = main_runner->Run(); 234 exit_code = main_runner->Run();
208 235
209 main_runner->Shutdown(); 236 main_runner->Shutdown();
210 #endif 237 #endif
211 238
212 return exit_code; 239 return exit_code;
213 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698