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

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

Issue 2908293003: Replace deprecated base::NonThreadSafe in content/shell in favor of SequenceChecker. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « content/shell/browser/layout_test/blink_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layout_test/blink_test_controller.h" 5 #include "content/shell/browser/layout_test/blink_test_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <set> 10 #include <set>
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 switches::kEncodeBinary)) 271 switches::kEncodeBinary))
272 printer_->set_encode_binary_data(true); 272 printer_->set_encode_binary_data(true);
273 registrar_.Add(this, 273 registrar_.Add(this,
274 NOTIFICATION_RENDERER_PROCESS_CREATED, 274 NOTIFICATION_RENDERER_PROCESS_CREATED,
275 NotificationService::AllSources()); 275 NotificationService::AllSources());
276 GpuDataManager::GetInstance()->AddObserver(this); 276 GpuDataManager::GetInstance()->AddObserver(this);
277 ResetAfterLayoutTest(); 277 ResetAfterLayoutTest();
278 } 278 }
279 279
280 BlinkTestController::~BlinkTestController() { 280 BlinkTestController::~BlinkTestController() {
281 DCHECK(CalledOnValidThread()); 281 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
282 CHECK(instance_ == this); 282 CHECK(instance_ == this);
283 CHECK(test_phase_ == BETWEEN_TESTS); 283 CHECK(test_phase_ == BETWEEN_TESTS);
284 GpuDataManager::GetInstance()->RemoveObserver(this); 284 GpuDataManager::GetInstance()->RemoveObserver(this);
285 DiscardMainWindow(); 285 DiscardMainWindow();
286 instance_ = NULL; 286 instance_ = NULL;
287 } 287 }
288 288
289 bool BlinkTestController::PrepareForLayoutTest( 289 bool BlinkTestController::PrepareForLayoutTest(
290 const GURL& test_url, 290 const GURL& test_url,
291 const base::FilePath& current_working_directory, 291 const base::FilePath& current_working_directory,
292 bool enable_pixel_dumping, 292 bool enable_pixel_dumping,
293 const std::string& expected_pixel_hash) { 293 const std::string& expected_pixel_hash) {
294 DCHECK(CalledOnValidThread()); 294 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
295 test_phase_ = DURING_TEST; 295 test_phase_ = DURING_TEST;
296 current_working_directory_ = current_working_directory; 296 current_working_directory_ = current_working_directory;
297 enable_pixel_dumping_ = enable_pixel_dumping; 297 enable_pixel_dumping_ = enable_pixel_dumping;
298 expected_pixel_hash_ = expected_pixel_hash; 298 expected_pixel_hash_ = expected_pixel_hash;
299 if (test_url.spec().find("/inspector-unit/") == std::string::npos) 299 if (test_url.spec().find("/inspector-unit/") == std::string::npos)
300 test_url_ = test_url; 300 test_url_ = test_url;
301 else 301 else
302 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url); 302 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url);
303 did_send_initial_test_configuration_ = false; 303 did_send_initial_test_configuration_ = false;
304 printer_->reset(); 304 printer_->reset();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 main_window_->web_contents()->GetController().LoadURLWithParams(params); 359 main_window_->web_contents()->GetController().LoadURLWithParams(params);
360 main_window_->web_contents()->Focus(); 360 main_window_->web_contents()->Focus();
361 } 361 }
362 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( 362 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive(
363 true); 363 true);
364 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); 364 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
365 return true; 365 return true;
366 } 366 }
367 367
368 bool BlinkTestController::ResetAfterLayoutTest() { 368 bool BlinkTestController::ResetAfterLayoutTest() {
369 DCHECK(CalledOnValidThread()); 369 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
370 printer_->PrintTextFooter(); 370 printer_->PrintTextFooter();
371 printer_->PrintImageFooter(); 371 printer_->PrintImageFooter();
372 printer_->CloseStderr(); 372 printer_->CloseStderr();
373 did_send_initial_test_configuration_ = false; 373 did_send_initial_test_configuration_ = false;
374 test_phase_ = BETWEEN_TESTS; 374 test_phase_ = BETWEEN_TESTS;
375 is_compositing_test_ = false; 375 is_compositing_test_ = false;
376 enable_pixel_dumping_ = false; 376 enable_pixel_dumping_ = false;
377 expected_pixel_hash_.clear(); 377 expected_pixel_hash_.clear();
378 test_url_ = GURL(); 378 test_url_ = GURL();
379 prefs_ = WebPreferences(); 379 prefs_ = WebPreferences();
380 should_override_prefs_ = false; 380 should_override_prefs_ = false;
381 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false); 381 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false);
382 382
383 #if defined(OS_ANDROID) 383 #if defined(OS_ANDROID)
384 // Re-using the shell's main window on Android causes issues with networking 384 // Re-using the shell's main window on Android causes issues with networking
385 // requests never succeeding. See http://crbug.com/277652. 385 // requests never succeeding. See http://crbug.com/277652.
386 DiscardMainWindow(); 386 DiscardMainWindow();
387 #endif 387 #endif
388 return true; 388 return true;
389 } 389 }
390 390
391 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) { 391 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) {
392 temp_path_ = temp_path; 392 temp_path_ = temp_path;
393 } 393 }
394 394
395 void BlinkTestController::RendererUnresponsive() { 395 void BlinkTestController::RendererUnresponsive() {
396 DCHECK(CalledOnValidThread()); 396 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
397 LOG(WARNING) << "renderer unresponsive"; 397 LOG(WARNING) << "renderer unresponsive";
398 } 398 }
399 399
400 void BlinkTestController::OverrideWebkitPrefs(WebPreferences* prefs) { 400 void BlinkTestController::OverrideWebkitPrefs(WebPreferences* prefs) {
401 if (should_override_prefs_) { 401 if (should_override_prefs_) {
402 *prefs = prefs_; 402 *prefs = prefs_;
403 } else { 403 } else {
404 ApplyLayoutTestDefaultPreferences(prefs); 404 ApplyLayoutTestDefaultPreferences(prefs);
405 if (is_compositing_test_) { 405 if (is_compositing_test_) {
406 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); 406 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
(...skipping 29 matching lines...) Expand all
436 RenderFrameHost* frame, 436 RenderFrameHost* frame,
437 const BluetoothChooser::EventHandler& event_handler) { 437 const BluetoothChooser::EventHandler& event_handler) {
438 if (bluetooth_chooser_factory_) { 438 if (bluetooth_chooser_factory_) {
439 return bluetooth_chooser_factory_->RunBluetoothChooser(frame, 439 return bluetooth_chooser_factory_->RunBluetoothChooser(frame,
440 event_handler); 440 event_handler);
441 } 441 }
442 return base::MakeUnique<LayoutTestFirstDeviceBluetoothChooser>(event_handler); 442 return base::MakeUnique<LayoutTestFirstDeviceBluetoothChooser>(event_handler);
443 } 443 }
444 444
445 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { 445 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) {
446 DCHECK(CalledOnValidThread()); 446 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
447 bool handled = true; 447 bool handled = true;
448 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message) 448 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message)
449 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage) 449 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage)
450 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessageToStderr, 450 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessageToStderr,
451 OnPrintMessageToStderr) 451 OnPrintMessageToStderr)
452 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) 452 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump)
453 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiateLayoutDump, 453 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiateLayoutDump,
454 OnInitiateLayoutDump) 454 OnInitiateLayoutDump)
455 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) 455 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump)
456 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump) 456 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 render_frame_host) 494 render_frame_host)
495 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, 495 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse,
496 OnLayoutDumpResponse) 496 OnLayoutDumpResponse)
497 IPC_MESSAGE_UNHANDLED(handled = false) 497 IPC_MESSAGE_UNHANDLED(handled = false)
498 IPC_END_MESSAGE_MAP() 498 IPC_END_MESSAGE_MAP()
499 return handled; 499 return handled;
500 } 500 }
501 501
502 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, 502 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path,
503 base::ProcessId plugin_pid) { 503 base::ProcessId plugin_pid) {
504 DCHECK(CalledOnValidThread()); 504 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
505 printer_->AddErrorMessage( 505 printer_->AddErrorMessage(
506 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); 506 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid));
507 base::ThreadTaskRunnerHandle::Get()->PostTask( 507 base::ThreadTaskRunnerHandle::Get()->PostTask(
508 FROM_HERE, 508 FROM_HERE,
509 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), 509 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow),
510 base::Unretained(this))); 510 base::Unretained(this)));
511 } 511 }
512 512
513 void BlinkTestController::RenderFrameCreated( 513 void BlinkTestController::RenderFrameCreated(
514 RenderFrameHost* render_frame_host) { 514 RenderFrameHost* render_frame_host) {
515 DCHECK(CalledOnValidThread()); 515 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
516 HandleNewRenderFrameHost(render_frame_host); 516 HandleNewRenderFrameHost(render_frame_host);
517 } 517 }
518 518
519 void BlinkTestController::DevToolsProcessCrashed() { 519 void BlinkTestController::DevToolsProcessCrashed() {
520 DCHECK(CalledOnValidThread()); 520 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
521 printer_->AddErrorMessage("#CRASHED - devtools"); 521 printer_->AddErrorMessage("#CRASHED - devtools");
522 devtools_bindings_.reset(); 522 devtools_bindings_.reset();
523 if (devtools_window_) 523 if (devtools_window_)
524 devtools_window_->Close(); 524 devtools_window_->Close();
525 devtools_window_ = nullptr; 525 devtools_window_ = nullptr;
526 } 526 }
527 527
528 void BlinkTestController::WebContentsDestroyed() { 528 void BlinkTestController::WebContentsDestroyed() {
529 DCHECK(CalledOnValidThread()); 529 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
530 printer_->AddErrorMessage("FAIL: main window was destroyed"); 530 printer_->AddErrorMessage("FAIL: main window was destroyed");
531 DiscardMainWindow(); 531 DiscardMainWindow();
532 } 532 }
533 533
534 void BlinkTestController::RenderProcessHostDestroyed( 534 void BlinkTestController::RenderProcessHostDestroyed(
535 RenderProcessHost* render_process_host) { 535 RenderProcessHost* render_process_host) {
536 render_process_host_observer_.Remove(render_process_host); 536 render_process_host_observer_.Remove(render_process_host);
537 all_observed_render_process_hosts_.erase(render_process_host); 537 all_observed_render_process_hosts_.erase(render_process_host);
538 main_window_render_process_hosts_.erase(render_process_host); 538 main_window_render_process_hosts_.erase(render_process_host);
539 } 539 }
540 540
541 void BlinkTestController::RenderProcessExited( 541 void BlinkTestController::RenderProcessExited(
542 RenderProcessHost* render_process_host, 542 RenderProcessHost* render_process_host,
543 base::TerminationStatus status, 543 base::TerminationStatus status,
544 int exit_code) { 544 int exit_code) {
545 DCHECK(CalledOnValidThread()); 545 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
546 switch (status) { 546 switch (status) {
547 case base::TerminationStatus::TERMINATION_STATUS_NORMAL_TERMINATION: 547 case base::TerminationStatus::TERMINATION_STATUS_NORMAL_TERMINATION:
548 case base::TerminationStatus::TERMINATION_STATUS_STILL_RUNNING: 548 case base::TerminationStatus::TERMINATION_STATUS_STILL_RUNNING:
549 break; 549 break;
550 550
551 case base::TerminationStatus::TERMINATION_STATUS_ABNORMAL_TERMINATION: 551 case base::TerminationStatus::TERMINATION_STATUS_ABNORMAL_TERMINATION:
552 case base::TerminationStatus::TERMINATION_STATUS_LAUNCH_FAILED: 552 case base::TerminationStatus::TERMINATION_STATUS_LAUNCH_FAILED:
553 case base::TerminationStatus::TERMINATION_STATUS_PROCESS_CRASHED: 553 case base::TerminationStatus::TERMINATION_STATUS_PROCESS_CRASHED:
554 case base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED: 554 case base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED:
555 default: { 555 default: {
556 base::ProcessHandle handle = render_process_host->GetHandle(); 556 base::ProcessHandle handle = render_process_host->GetHandle();
557 if (handle != base::kNullProcessHandle) { 557 if (handle != base::kNullProcessHandle) {
558 printer_->AddErrorMessage(std::string("#CRASHED - renderer (pid ") + 558 printer_->AddErrorMessage(std::string("#CRASHED - renderer (pid ") +
559 base::IntToString(base::GetProcId(handle)) + 559 base::IntToString(base::GetProcId(handle)) +
560 ")"); 560 ")");
561 } else { 561 } else {
562 printer_->AddErrorMessage("#CRASHED - renderer"); 562 printer_->AddErrorMessage("#CRASHED - renderer");
563 } 563 }
564 564
565 DiscardMainWindow(); 565 DiscardMainWindow();
566 break; 566 break;
567 } 567 }
568 } 568 }
569 } 569 }
570 570
571 void BlinkTestController::Observe(int type, 571 void BlinkTestController::Observe(int type,
572 const NotificationSource& source, 572 const NotificationSource& source,
573 const NotificationDetails& details) { 573 const NotificationDetails& details) {
574 DCHECK(CalledOnValidThread()); 574 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
575 switch (type) { 575 switch (type) {
576 case NOTIFICATION_RENDERER_PROCESS_CREATED: { 576 case NOTIFICATION_RENDERER_PROCESS_CREATED: {
577 if (!main_window_) 577 if (!main_window_)
578 return; 578 return;
579 RenderViewHost* render_view_host = 579 RenderViewHost* render_view_host =
580 main_window_->web_contents()->GetRenderViewHost(); 580 main_window_->web_contents()->GetRenderViewHost();
581 if (!render_view_host) 581 if (!render_view_host)
582 return; 582 return;
583 RenderProcessHost* render_process_host = 583 RenderProcessHost* render_process_host =
584 Source<RenderProcessHost>(source).ptr(); 584 Source<RenderProcessHost>(source).ptr();
585 if (render_process_host != render_view_host->GetProcess()) 585 if (render_process_host != render_view_host->GetProcess())
586 return; 586 return;
587 current_pid_ = base::GetProcId(render_process_host->GetHandle()); 587 current_pid_ = base::GetProcId(render_process_host->GetHandle());
588 break; 588 break;
589 } 589 }
590 default: 590 default:
591 NOTREACHED(); 591 NOTREACHED();
592 } 592 }
593 } 593 }
594 594
595 void BlinkTestController::OnGpuProcessCrashed( 595 void BlinkTestController::OnGpuProcessCrashed(
596 base::TerminationStatus exit_code) { 596 base::TerminationStatus exit_code) {
597 DCHECK(CalledOnValidThread()); 597 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
598 printer_->AddErrorMessage("#CRASHED - gpu"); 598 printer_->AddErrorMessage("#CRASHED - gpu");
599 DiscardMainWindow(); 599 DiscardMainWindow();
600 } 600 }
601 601
602 void BlinkTestController::DiscardMainWindow() { 602 void BlinkTestController::DiscardMainWindow() {
603 // If we're running a test, we need to close all windows and exit the message 603 // If we're running a test, we need to close all windows and exit the message
604 // loop. Otherwise, we're already outside of the message loop, and we just 604 // loop. Otherwise, we're already outside of the message loop, and we just
605 // discard the main window. 605 // discard the main window.
606 devtools_bindings_.reset(); 606 devtools_bindings_.reset();
607 WebContentsObserver::Observe(NULL); 607 WebContentsObserver::Observe(NULL);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1016 }
1017 DCHECK(layout_test_control_map_[frame].get()); 1017 DCHECK(layout_test_control_map_[frame].get());
1018 return layout_test_control_map_[frame].get(); 1018 return layout_test_control_map_[frame].get();
1019 } 1019 }
1020 1020
1021 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { 1021 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) {
1022 layout_test_control_map_.erase(frame); 1022 layout_test_control_map_.erase(frame);
1023 } 1023 }
1024 1024
1025 } // namespace content 1025 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/blink_test_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698