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

Side by Side Diff: content/shell/browser/layout_test/layout_test_browser_main.cc

Issue 661943002: Content Shell: Fix broken test controller lifetime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/shell_browser_main.h" 5 #include "content/shell/browser/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/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #if defined(OS_ANDROID) 142 #if defined(OS_ANDROID)
143 // There will be left-over tasks in the queue for Android because the 143 // There will be left-over tasks in the queue for Android because the
144 // main window is being destroyed. Run them before starting the next test. 144 // main window is being destroyed. Run them before starting the next test.
145 base::MessageLoop::current()->RunUntilIdle(); 145 base::MessageLoop::current()->RunUntilIdle();
146 #endif 146 #endif
147 return true; 147 return true;
148 } 148 }
149 149
150 } // namespace 150 } // namespace
151 151
152 // Main routine for running as the Browser process. 152
153
Mike West 2014/10/17 10:44:35 Oops.
153 int LayoutTestBrowserMain( 154 int LayoutTestBrowserMain(
154 const content::MainFunctionParams& parameters, 155 const content::MainFunctionParams& parameters,
155 const scoped_ptr<content::BrowserMainRunner>& main_runner) { 156 const scoped_ptr<content::BrowserMainRunner>& main_runner) {
156 base::ScopedTempDir browser_context_path_for_layout_tests; 157 base::ScopedTempDir browser_context_path_for_layout_tests;
157 158
158 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); 159 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir());
159 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); 160 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty());
160 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 161 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
161 switches::kContentShellDataPath, 162 switches::kContentShellDataPath,
162 browser_context_path_for_layout_tests.path().MaybeAsASCII()); 163 browser_context_path_for_layout_tests.path().MaybeAsASCII());
163 164
164 #if defined(OS_ANDROID) 165 #if defined(OS_ANDROID)
165 content::EnsureInitializeForAndroidLayoutTests(); 166 content::EnsureInitializeForAndroidLayoutTests();
166 #endif 167 #endif
167 168
168 int exit_code = main_runner->Initialize(parameters); 169 int exit_code = main_runner->Initialize(parameters);
169 DCHECK_LT(exit_code, 0) 170 DCHECK_LT(exit_code, 0)
170 << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain"; 171 << "BrowserMainRunner::Initialize failed in ShellBrowserMain";
Mike West 2014/10/17 10:44:35 Oops.
171 172
172 if (exit_code >= 0) 173 if (exit_code >= 0)
173 return exit_code; 174 return exit_code;
174 175
175 if (CommandLine::ForCurrentProcess()->HasSwitch( 176 if (CommandLine::ForCurrentProcess()->HasSwitch(
176 switches::kCheckLayoutTestSysDeps)) { 177 switches::kCheckLayoutTestSysDeps)) {
177 base::MessageLoop::current()->PostTask(FROM_HERE, 178 base::MessageLoop::current()->PostTask(FROM_HERE,
178 base::MessageLoop::QuitClosure()); 179 base::MessageLoop::QuitClosure());
179 main_runner->Run(); 180 main_runner->Run();
180 content::Shell::CloseAllWindows(); 181 content::Shell::CloseAllWindows();
181 main_runner->Shutdown(); 182 main_runner->Shutdown();
182 return 0; 183 return 0;
183 } 184 }
184 185
185 content::WebKitTestController test_controller; 186 // Scope the test_controller to this block: We need to execute
187 // 'main_runner->Shutdown()' before the test_controller destructs when running
188 // on Android, and after it destructs when running anywhere else.
186 { 189 {
Mike West 2014/10/17 10:44:35 Might make sense to move this to a separate functi
187 // We're outside of the message loop here, and this is a test. 190 content::WebKitTestController test_controller;
188 base::ThreadRestrictions::ScopedAllowIO allow_io; 191 {
189 base::FilePath temp_path; 192 // We're outside of the message loop here, and this is a test.
190 base::GetTempDir(&temp_path); 193 base::ThreadRestrictions::ScopedAllowIO allow_io;
191 test_controller.SetTempPath(temp_path); 194 base::FilePath temp_path;
192 } 195 base::GetTempDir(&temp_path);
193 std::string test_string; 196 test_controller.SetTempPath(temp_path);
194 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); 197 }
195 size_t command_line_position = 0; 198 std::string test_string;
196 bool ran_at_least_once = false; 199 CommandLine::StringVector args =
200 CommandLine::ForCurrentProcess()->GetArgs();
201 size_t command_line_position = 0;
202 bool ran_at_least_once = false;
197 203
198 std::cout << "#READY\n"; 204 std::cout << "#READY\n";
199 std::cout.flush(); 205 std::cout.flush();
200 206
201 while (GetNextTest(args, &command_line_position, &test_string)) { 207 while (GetNextTest(args, &command_line_position, &test_string)) {
202 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) 208 if (!RunOneTest(test_string, &ran_at_least_once, main_runner))
203 break; 209 break;
204 } 210 }
205 if (!ran_at_least_once) { 211 if (!ran_at_least_once) {
206 base::MessageLoop::current()->PostTask(FROM_HERE, 212 base::MessageLoop::current()->PostTask(FROM_HERE,
207 base::MessageLoop::QuitClosure()); 213 base::MessageLoop::QuitClosure());
208 main_runner->Run(); 214 main_runner->Run();
209 } 215 }
210 216
211 #if defined(OS_ANDROID) 217 #if defined(OS_ANDROID)
212 // Android should only execute Shutdown() here when running layout tests. 218 main_runner->Shutdown();
213 main_runner->Shutdown();
214 #endif 219 #endif
215 220
216 exit_code = 0; 221 exit_code = 0;
222 }
217 223
218 #if !defined(OS_ANDROID) 224 #if !defined(OS_ANDROID)
219 main_runner->Shutdown(); 225 main_runner->Shutdown();
220 #endif 226 #endif
221 227
222 return exit_code; 228 return exit_code;
223 } 229 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698