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

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

Issue 16074003: [content shell] don't open new windows after printing the test results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: enum 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
« no previous file with comments | « content/shell/webkit_test_controller.h ('k') | 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 (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/webkit_test_controller.h" 5 #include "content/shell/webkit_test_controller.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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 WebKitTestController* WebKitTestController::instance_ = NULL; 164 WebKitTestController* WebKitTestController::instance_ = NULL;
165 165
166 // static 166 // static
167 WebKitTestController* WebKitTestController::Get() { 167 WebKitTestController* WebKitTestController::Get() {
168 DCHECK(instance_); 168 DCHECK(instance_);
169 return instance_; 169 return instance_;
170 } 170 }
171 171
172 WebKitTestController::WebKitTestController() 172 WebKitTestController::WebKitTestController()
173 : main_window_(NULL), 173 : main_window_(NULL),
174 is_running_test_(false) { 174 test_phase_(BETWEEN_TESTS) {
175 CHECK(!instance_); 175 CHECK(!instance_);
176 instance_ = this; 176 instance_ = this;
177 printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr)); 177 printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr));
178 registrar_.Add(this, 178 registrar_.Add(this,
179 NOTIFICATION_RENDERER_PROCESS_CREATED, 179 NOTIFICATION_RENDERER_PROCESS_CREATED,
180 NotificationService::AllSources()); 180 NotificationService::AllSources());
181 GpuDataManager::GetInstance()->AddObserver(this); 181 GpuDataManager::GetInstance()->AddObserver(this);
182 ResetAfterLayoutTest(); 182 ResetAfterLayoutTest();
183 } 183 }
184 184
185 WebKitTestController::~WebKitTestController() { 185 WebKitTestController::~WebKitTestController() {
186 DCHECK(CalledOnValidThread()); 186 DCHECK(CalledOnValidThread());
187 CHECK(instance_ == this); 187 CHECK(instance_ == this);
188 CHECK(!is_running_test_); 188 CHECK(test_phase_ == BETWEEN_TESTS);
189 GpuDataManager::GetInstance()->RemoveObserver(this); 189 GpuDataManager::GetInstance()->RemoveObserver(this);
190 DiscardMainWindow(); 190 DiscardMainWindow();
191 instance_ = NULL; 191 instance_ = NULL;
192 } 192 }
193 193
194 bool WebKitTestController::PrepareForLayoutTest( 194 bool WebKitTestController::PrepareForLayoutTest(
195 const GURL& test_url, 195 const GURL& test_url,
196 const base::FilePath& current_working_directory, 196 const base::FilePath& current_working_directory,
197 bool enable_pixel_dumping, 197 bool enable_pixel_dumping,
198 const std::string& expected_pixel_hash) { 198 const std::string& expected_pixel_hash) {
199 DCHECK(CalledOnValidThread()); 199 DCHECK(CalledOnValidThread());
200 is_running_test_ = true; 200 test_phase_ = DURING_TEST;
201 current_working_directory_ = current_working_directory; 201 current_working_directory_ = current_working_directory;
202 enable_pixel_dumping_ = enable_pixel_dumping; 202 enable_pixel_dumping_ = enable_pixel_dumping;
203 expected_pixel_hash_ = expected_pixel_hash; 203 expected_pixel_hash_ = expected_pixel_hash;
204 test_url_ = test_url; 204 test_url_ = test_url;
205 printer_->reset(); 205 printer_->reset();
206 ShellBrowserContext* browser_context = 206 ShellBrowserContext* browser_context =
207 ShellContentBrowserClient::Get()->browser_context(); 207 ShellContentBrowserClient::Get()->browser_context();
208 if (test_url.spec().find("compositing/") != std::string::npos) 208 if (test_url.spec().find("compositing/") != std::string::npos)
209 is_compositing_test_ = true; 209 is_compositing_test_ = true;
210 initial_size_ = gfx::Size( 210 initial_size_ = gfx::Size(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds + 1000)); 256 base::TimeDelta::FromMilliseconds(kTestTimeoutMilliseconds + 1000));
257 } 257 }
258 return true; 258 return true;
259 } 259 }
260 260
261 bool WebKitTestController::ResetAfterLayoutTest() { 261 bool WebKitTestController::ResetAfterLayoutTest() {
262 DCHECK(CalledOnValidThread()); 262 DCHECK(CalledOnValidThread());
263 printer_->PrintTextFooter(); 263 printer_->PrintTextFooter();
264 printer_->PrintImageFooter(); 264 printer_->PrintImageFooter();
265 send_configuration_to_next_host_ = false; 265 send_configuration_to_next_host_ = false;
266 is_running_test_ = false; 266 test_phase_ = BETWEEN_TESTS;
267 is_compositing_test_ = false; 267 is_compositing_test_ = false;
268 enable_pixel_dumping_ = false; 268 enable_pixel_dumping_ = false;
269 expected_pixel_hash_.clear(); 269 expected_pixel_hash_.clear();
270 test_url_ = GURL(); 270 test_url_ = GURL();
271 prefs_ = WebPreferences(); 271 prefs_ = WebPreferences();
272 should_override_prefs_ = false; 272 should_override_prefs_ = false;
273 watchdog_.Cancel(); 273 watchdog_.Cancel();
274 return true; 274 return true;
275 } 275 }
276 276
(...skipping 15 matching lines...) Expand all
292 CommandLine& command_line = *CommandLine::ForCurrentProcess(); 292 CommandLine& command_line = *CommandLine::ForCurrentProcess();
293 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) 293 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing))
294 prefs->accelerated_2d_canvas_enabled = true; 294 prefs->accelerated_2d_canvas_enabled = true;
295 prefs->accelerated_compositing_for_video_enabled = true; 295 prefs->accelerated_compositing_for_video_enabled = true;
296 prefs->mock_scrollbars_enabled = true; 296 prefs->mock_scrollbars_enabled = true;
297 } 297 }
298 } 298 }
299 } 299 }
300 300
301 void WebKitTestController::OpenURL(const GURL& url) { 301 void WebKitTestController::OpenURL(const GURL& url) {
302 if (test_phase_ != DURING_TEST)
303 return;
304
302 Shell::CreateNewWindow(main_window_->web_contents()->GetBrowserContext(), 305 Shell::CreateNewWindow(main_window_->web_contents()->GetBrowserContext(),
303 url, 306 url,
304 main_window_->web_contents()->GetSiteInstance(), 307 main_window_->web_contents()->GetSiteInstance(),
305 MSG_ROUTING_NONE, 308 MSG_ROUTING_NONE,
306 gfx::Size()); 309 gfx::Size());
307 } 310 }
308 311
309 void WebKitTestController::TestFinishedInSecondaryWindow() { 312 void WebKitTestController::TestFinishedInSecondaryWindow() {
310 RenderViewHost* render_view_host = 313 RenderViewHost* render_view_host =
311 main_window_->web_contents()->GetRenderViewHost(); 314 main_window_->web_contents()->GetRenderViewHost();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 printer_->AddErrorMessage( 420 printer_->AddErrorMessage(
418 "FAIL: Timed out waiting for notifyDone to be called"); 421 "FAIL: Timed out waiting for notifyDone to be called");
419 DiscardMainWindow(); 422 DiscardMainWindow();
420 } 423 }
421 424
422 void WebKitTestController::DiscardMainWindow() { 425 void WebKitTestController::DiscardMainWindow() {
423 // If we're running a test, we need to close all windows and exit the message 426 // If we're running a test, we need to close all windows and exit the message
424 // loop. Otherwise, we're already outside of the message loop, and we just 427 // loop. Otherwise, we're already outside of the message loop, and we just
425 // discard the main window. 428 // discard the main window.
426 WebContentsObserver::Observe(NULL); 429 WebContentsObserver::Observe(NULL);
427 if (is_running_test_) { 430 if (test_phase_ != BETWEEN_TESTS) {
428 Shell::CloseAllWindows(); 431 Shell::CloseAllWindows();
429 base::MessageLoop::current()->PostTask(FROM_HERE, 432 base::MessageLoop::current()->PostTask(FROM_HERE,
430 base::MessageLoop::QuitClosure()); 433 base::MessageLoop::QuitClosure());
434 test_phase_ = CLEAN_UP;
431 } else if (main_window_) { 435 } else if (main_window_) {
432 main_window_->Close(); 436 main_window_->Close();
433 } 437 }
434 main_window_ = NULL; 438 main_window_ = NULL;
435 current_pid_ = base::kNullProcessId; 439 current_pid_ = base::kNullProcessId;
436 } 440 }
437 441
438 void WebKitTestController::SendTestConfiguration() { 442 void WebKitTestController::SendTestConfiguration() {
439 RenderViewHost* render_view_host = 443 RenderViewHost* render_view_host =
440 main_window_->web_contents()->GetRenderViewHost(); 444 main_window_->web_contents()->GetRenderViewHost();
(...skipping 15 matching lines...) Expand all
456 } 460 }
457 461
458 void WebKitTestController::OnTestFinished(bool did_timeout) { 462 void WebKitTestController::OnTestFinished(bool did_timeout) {
459 watchdog_.Cancel(); 463 watchdog_.Cancel();
460 if (did_timeout) { 464 if (did_timeout) {
461 printer_->AddErrorMessage( 465 printer_->AddErrorMessage(
462 "FAIL: Timed out waiting for notifyDone to be called"); 466 "FAIL: Timed out waiting for notifyDone to be called");
463 DiscardMainWindow(); 467 DiscardMainWindow();
464 return; 468 return;
465 } 469 }
470 test_phase_ = CLEAN_UP;
466 if (!printer_->output_finished()) 471 if (!printer_->output_finished())
467 printer_->PrintImageFooter(); 472 printer_->PrintImageFooter();
468 RenderViewHost* render_view_host = 473 RenderViewHost* render_view_host =
469 main_window_->web_contents()->GetRenderViewHost(); 474 main_window_->web_contents()->GetRenderViewHost();
470 base::MessageLoop::current()->PostTask( 475 base::MessageLoop::current()->PostTask(
471 FROM_HERE, 476 FROM_HERE,
472 base::Bind(base::IgnoreResult(&WebKitTestController::Send), 477 base::Bind(base::IgnoreResult(&WebKitTestController::Send),
473 base::Unretained(this), 478 base::Unretained(this),
474 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); 479 new ShellViewMsg_Reset(render_view_host->GetRoutingID())));
475 } 480 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 619 }
615 base::MessageLoop::current()->RunUntilIdle(); 620 base::MessageLoop::current()->RunUntilIdle();
616 } 621 }
617 622
618 void WebKitTestController::OnResetDone() { 623 void WebKitTestController::OnResetDone() {
619 base::MessageLoop::current()->PostTask(FROM_HERE, 624 base::MessageLoop::current()->PostTask(FROM_HERE,
620 base::MessageLoop::QuitClosure()); 625 base::MessageLoop::QuitClosure());
621 } 626 }
622 627
623 } // namespace content 628 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/webkit_test_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698