OLD | NEW |
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/blink_test_controller.h" | 5 #include "content/shell/browser/blink_test_controller.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
16 #include "base/thread_task_runner_handle.h" | |
17 #include "content/public/browser/devtools_agent_host.h" | 15 #include "content/public/browser/devtools_agent_host.h" |
18 #include "content/public/browser/dom_storage_context.h" | 16 #include "content/public/browser/dom_storage_context.h" |
19 #include "content/public/browser/gpu_data_manager.h" | 17 #include "content/public/browser/gpu_data_manager.h" |
20 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
21 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 24 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 IPC_END_MESSAGE_MAP() | 393 IPC_END_MESSAGE_MAP() |
396 | 394 |
397 return handled; | 395 return handled; |
398 } | 396 } |
399 | 397 |
400 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, | 398 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, |
401 base::ProcessId plugin_pid) { | 399 base::ProcessId plugin_pid) { |
402 DCHECK(CalledOnValidThread()); | 400 DCHECK(CalledOnValidThread()); |
403 printer_->AddErrorMessage( | 401 printer_->AddErrorMessage( |
404 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); | 402 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); |
405 base::ThreadTaskRunnerHandle::Get()->PostTask( | 403 base::MessageLoop::current()->PostTask( |
406 FROM_HERE, | 404 FROM_HERE, |
407 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), | 405 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), |
408 base::Unretained(this))); | 406 base::Unretained(this))); |
409 } | 407 } |
410 | 408 |
411 void BlinkTestController::RenderViewCreated(RenderViewHost* render_view_host) { | 409 void BlinkTestController::RenderViewCreated(RenderViewHost* render_view_host) { |
412 DCHECK(CalledOnValidThread()); | 410 DCHECK(CalledOnValidThread()); |
413 // Might be kNullProcessHandle, in which case we will receive a notification | 411 // Might be kNullProcessHandle, in which case we will receive a notification |
414 // later when the RenderProcessHost was created. | 412 // later when the RenderProcessHost was created. |
415 if (render_view_host->GetProcess()->GetHandle() != base::kNullProcessHandle) | 413 if (render_view_host->GetProcess()->GetHandle() != base::kNullProcessHandle) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 DiscardMainWindow(); | 474 DiscardMainWindow(); |
477 } | 475 } |
478 | 476 |
479 void BlinkTestController::DiscardMainWindow() { | 477 void BlinkTestController::DiscardMainWindow() { |
480 // If we're running a test, we need to close all windows and exit the message | 478 // If we're running a test, we need to close all windows and exit the message |
481 // loop. Otherwise, we're already outside of the message loop, and we just | 479 // loop. Otherwise, we're already outside of the message loop, and we just |
482 // discard the main window. | 480 // discard the main window. |
483 WebContentsObserver::Observe(NULL); | 481 WebContentsObserver::Observe(NULL); |
484 if (test_phase_ != BETWEEN_TESTS) { | 482 if (test_phase_ != BETWEEN_TESTS) { |
485 Shell::CloseAllWindows(); | 483 Shell::CloseAllWindows(); |
486 base::ThreadTaskRunnerHandle::Get()->PostTask( | 484 base::MessageLoop::current()->PostTask(FROM_HERE, |
487 FROM_HERE, base::MessageLoop::QuitClosure()); | 485 base::MessageLoop::QuitClosure()); |
488 test_phase_ = CLEAN_UP; | 486 test_phase_ = CLEAN_UP; |
489 } else if (main_window_) { | 487 } else if (main_window_) { |
490 main_window_->Close(); | 488 main_window_->Close(); |
491 } | 489 } |
492 main_window_ = NULL; | 490 main_window_ = NULL; |
493 current_pid_ = base::kNullProcessId; | 491 current_pid_ = base::kNullProcessId; |
494 } | 492 } |
495 | 493 |
496 void BlinkTestController::SendTestConfiguration() { | 494 void BlinkTestController::SendTestConfiguration() { |
497 RenderViewHost* render_view_host = | 495 RenderViewHost* render_view_host = |
(...skipping 12 matching lines...) Expand all Loading... |
510 render_view_host->GetRoutingID(), params)); | 508 render_view_host->GetRoutingID(), params)); |
511 } | 509 } |
512 | 510 |
513 void BlinkTestController::OnTestFinished() { | 511 void BlinkTestController::OnTestFinished() { |
514 test_phase_ = CLEAN_UP; | 512 test_phase_ = CLEAN_UP; |
515 if (!printer_->output_finished()) | 513 if (!printer_->output_finished()) |
516 printer_->PrintImageFooter(); | 514 printer_->PrintImageFooter(); |
517 RenderViewHost* render_view_host = | 515 RenderViewHost* render_view_host = |
518 main_window_->web_contents()->GetRenderViewHost(); | 516 main_window_->web_contents()->GetRenderViewHost(); |
519 main_window_->web_contents()->ExitFullscreen(); | 517 main_window_->web_contents()->ExitFullscreen(); |
520 base::ThreadTaskRunnerHandle::Get()->PostTask( | 518 base::MessageLoop::current()->PostTask( |
521 FROM_HERE, | 519 FROM_HERE, |
522 base::Bind(base::IgnoreResult(&BlinkTestController::Send), | 520 base::Bind(base::IgnoreResult(&BlinkTestController::Send), |
523 base::Unretained(this), | 521 base::Unretained(this), |
524 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); | 522 new ShellViewMsg_Reset(render_view_host->GetRoutingID()))); |
525 } | 523 } |
526 | 524 |
527 void BlinkTestController::OnImageDump(const std::string& actual_pixel_hash, | 525 void BlinkTestController::OnImageDump(const std::string& actual_pixel_hash, |
528 const SkBitmap& image) { | 526 const SkBitmap& image) { |
529 SkAutoLockPixels image_lock(image); | 527 SkAutoLockPixels image_lock(image); |
530 | 528 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 if (is_leak_detection_enabled_) { | 673 if (is_leak_detection_enabled_) { |
676 if (main_window_ && main_window_->web_contents()) { | 674 if (main_window_ && main_window_->web_contents()) { |
677 RenderViewHost* render_view_host = | 675 RenderViewHost* render_view_host = |
678 main_window_->web_contents()->GetRenderViewHost(); | 676 main_window_->web_contents()->GetRenderViewHost(); |
679 render_view_host->Send( | 677 render_view_host->Send( |
680 new ShellViewMsg_TryLeakDetection(render_view_host->GetRoutingID())); | 678 new ShellViewMsg_TryLeakDetection(render_view_host->GetRoutingID())); |
681 } | 679 } |
682 return; | 680 return; |
683 } | 681 } |
684 | 682 |
685 base::ThreadTaskRunnerHandle::Get()->PostTask( | 683 base::MessageLoop::current()->PostTask(FROM_HERE, |
686 FROM_HERE, base::MessageLoop::QuitClosure()); | 684 base::MessageLoop::QuitClosure()); |
687 } | 685 } |
688 | 686 |
689 void BlinkTestController::OnLeakDetectionDone( | 687 void BlinkTestController::OnLeakDetectionDone( |
690 const LeakDetectionResult& result) { | 688 const LeakDetectionResult& result) { |
691 if (!result.leaked) { | 689 if (!result.leaked) { |
692 base::ThreadTaskRunnerHandle::Get()->PostTask( | 690 base::MessageLoop::current()->PostTask(FROM_HERE, |
693 FROM_HERE, base::MessageLoop::QuitClosure()); | 691 base::MessageLoop::QuitClosure()); |
694 return; | 692 return; |
695 } | 693 } |
696 | 694 |
697 printer_->AddErrorMessage( | 695 printer_->AddErrorMessage( |
698 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, | 696 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, |
699 result.detail.c_str())); | 697 result.detail.c_str())); |
700 CHECK(!crash_when_leak_found_); | 698 CHECK(!crash_when_leak_found_); |
701 | 699 |
702 DiscardMainWindow(); | 700 DiscardMainWindow(); |
703 } | 701 } |
704 | 702 |
705 } // namespace content | 703 } // namespace content |
OLD | NEW |