| 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/webkit_test_controller.h" | 5 #include "content/shell/browser/webkit_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" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 DCHECK(instance_); | 198 DCHECK(instance_); |
| 199 return instance_; | 199 return instance_; |
| 200 } | 200 } |
| 201 | 201 |
| 202 WebKitTestController::WebKitTestController() | 202 WebKitTestController::WebKitTestController() |
| 203 : main_window_(NULL), | 203 : main_window_(NULL), |
| 204 test_phase_(BETWEEN_TESTS), | 204 test_phase_(BETWEEN_TESTS), |
| 205 is_leak_detection_enabled_( | 205 is_leak_detection_enabled_( |
| 206 base::CommandLine::ForCurrentProcess()->HasSwitch( | 206 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 207 switches::kEnableLeakDetection)), | 207 switches::kEnableLeakDetection)), |
| 208 crash_when_leak_found_(false) { | 208 crash_when_leak_found_(false), |
| 209 devtools_frontend_(NULL) { |
| 209 CHECK(!instance_); | 210 CHECK(!instance_); |
| 210 instance_ = this; | 211 instance_ = this; |
| 211 | 212 |
| 212 if (is_leak_detection_enabled_) { | 213 if (is_leak_detection_enabled_) { |
| 213 std::string switchValue = | 214 std::string switchValue = |
| 214 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 215 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 215 switches::kEnableLeakDetection); | 216 switches::kEnableLeakDetection); |
| 216 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; | 217 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; |
| 217 } | 218 } |
| 218 | 219 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 base::IntToString(current_pid_) + ")"); | 427 base::IntToString(current_pid_) + ")"); |
| 427 } else { | 428 } else { |
| 428 printer_->AddErrorMessage("#CRASHED - renderer"); | 429 printer_->AddErrorMessage("#CRASHED - renderer"); |
| 429 } | 430 } |
| 430 DiscardMainWindow(); | 431 DiscardMainWindow(); |
| 431 } | 432 } |
| 432 | 433 |
| 433 void WebKitTestController::DevToolsProcessCrashed() { | 434 void WebKitTestController::DevToolsProcessCrashed() { |
| 434 DCHECK(CalledOnValidThread()); | 435 DCHECK(CalledOnValidThread()); |
| 435 printer_->AddErrorMessage("#CRASHED - devtools"); | 436 printer_->AddErrorMessage("#CRASHED - devtools"); |
| 436 DiscardMainWindow(); | 437 if (devtools_frontend_) |
| 438 devtools_frontend_->Close(); |
| 439 devtools_frontend_ = NULL; |
| 437 } | 440 } |
| 438 | 441 |
| 439 void WebKitTestController::WebContentsDestroyed() { | 442 void WebKitTestController::WebContentsDestroyed() { |
| 440 DCHECK(CalledOnValidThread()); | 443 DCHECK(CalledOnValidThread()); |
| 441 printer_->AddErrorMessage("FAIL: main window was destroyed"); | 444 printer_->AddErrorMessage("FAIL: main window was destroyed"); |
| 442 DiscardMainWindow(); | 445 DiscardMainWindow(); |
| 443 } | 446 } |
| 444 | 447 |
| 445 void WebKitTestController::Observe(int type, | 448 void WebKitTestController::Observe(int type, |
| 446 const NotificationSource& source, | 449 const NotificationSource& source, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 ShellContentBrowserClient::Get()->browser_context(); | 582 ShellContentBrowserClient::Get()->browser_context(); |
| 580 StoragePartition* storage_partition = | 583 StoragePartition* storage_partition = |
| 581 BrowserContext::GetStoragePartition(browser_context, NULL); | 584 BrowserContext::GetStoragePartition(browser_context, NULL); |
| 582 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( | 585 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( |
| 583 content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("", "") | 586 content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("", "") |
| 584 .GetOrigin()); | 587 .GetOrigin()); |
| 585 } | 588 } |
| 586 | 589 |
| 587 void WebKitTestController::OnShowDevTools(const std::string& settings, | 590 void WebKitTestController::OnShowDevTools(const std::string& settings, |
| 588 const std::string& frontend_url) { | 591 const std::string& frontend_url) { |
| 589 main_window_->ShowDevToolsForTest(settings, frontend_url); | 592 if (!devtools_frontend_) { |
| 593 devtools_frontend_ = LayoutTestDevToolsFrontend::Show( |
| 594 main_window_->web_contents(), settings, frontend_url); |
| 595 } else { |
| 596 devtools_frontend_->ReuseFrontend( |
| 597 main_window_->web_contents(), settings, frontend_url); |
| 598 } |
| 599 devtools_frontend_->Activate(); |
| 600 devtools_frontend_->Focus(); |
| 590 } | 601 } |
| 591 | 602 |
| 592 void WebKitTestController::OnCloseDevTools() { | 603 void WebKitTestController::OnCloseDevTools() { |
| 593 main_window_->CloseDevTools(); | 604 if (devtools_frontend_) |
| 605 devtools_frontend_->DisconnectFromTarget(); |
| 594 } | 606 } |
| 595 | 607 |
| 596 void WebKitTestController::OnGoToOffset(int offset) { | 608 void WebKitTestController::OnGoToOffset(int offset) { |
| 597 main_window_->GoBackOrForward(offset); | 609 main_window_->GoBackOrForward(offset); |
| 598 } | 610 } |
| 599 | 611 |
| 600 void WebKitTestController::OnReload() { | 612 void WebKitTestController::OnReload() { |
| 601 main_window_->Reload(); | 613 main_window_->Reload(); |
| 602 } | 614 } |
| 603 | 615 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 658 |
| 647 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), | 659 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), |
| 648 routing_ids, | 660 routing_ids, |
| 649 session_histories, | 661 session_histories, |
| 650 current_entry_indexes)); | 662 current_entry_indexes)); |
| 651 } | 663 } |
| 652 | 664 |
| 653 void WebKitTestController::OnCloseRemainingWindows() { | 665 void WebKitTestController::OnCloseRemainingWindows() { |
| 654 DevToolsAgentHost::DetachAllClients(); | 666 DevToolsAgentHost::DetachAllClients(); |
| 655 std::vector<Shell*> open_windows(Shell::windows()); | 667 std::vector<Shell*> open_windows(Shell::windows()); |
| 668 Shell* devtools_shell = devtools_frontend_ ? |
| 669 devtools_frontend_->frontend_shell() : NULL; |
| 656 for (size_t i = 0; i < open_windows.size(); ++i) { | 670 for (size_t i = 0; i < open_windows.size(); ++i) { |
| 657 if (open_windows[i] != main_window_) | 671 if (open_windows[i] != main_window_ && open_windows[i] != devtools_shell) |
| 658 open_windows[i]->Close(); | 672 open_windows[i]->Close(); |
| 659 } | 673 } |
| 660 base::MessageLoop::current()->RunUntilIdle(); | 674 base::MessageLoop::current()->RunUntilIdle(); |
| 661 } | 675 } |
| 662 | 676 |
| 663 void WebKitTestController::OnResetDone() { | 677 void WebKitTestController::OnResetDone() { |
| 664 if (is_leak_detection_enabled_) { | 678 if (is_leak_detection_enabled_) { |
| 665 if (main_window_ && main_window_->web_contents()) { | 679 if (main_window_ && main_window_->web_contents()) { |
| 666 RenderViewHost* render_view_host = | 680 RenderViewHost* render_view_host = |
| 667 main_window_->web_contents()->GetRenderViewHost(); | 681 main_window_->web_contents()->GetRenderViewHost(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 685 | 699 |
| 686 printer_->AddErrorMessage( | 700 printer_->AddErrorMessage( |
| 687 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, | 701 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, |
| 688 result.detail.c_str())); | 702 result.detail.c_str())); |
| 689 CHECK(!crash_when_leak_found_); | 703 CHECK(!crash_when_leak_found_); |
| 690 | 704 |
| 691 DiscardMainWindow(); | 705 DiscardMainWindow(); |
| 692 } | 706 } |
| 693 | 707 |
| 694 } // namespace content | 708 } // namespace content |
| OLD | NEW |