| 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/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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/base64.h" | 13 #include "base/base64.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 24 #include "content/public/browser/devtools_agent_host.h" | 25 #include "content/public/browser/devtools_agent_host.h" |
| 25 #include "content/public/browser/dom_storage_context.h" | 26 #include "content/public/browser/dom_storage_context.h" |
| 26 #include "content/public/browser/gpu_data_manager.h" | 27 #include "content/public/browser/gpu_data_manager.h" |
| 27 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
| 28 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 DCHECK(CalledOnValidThread()); | 263 DCHECK(CalledOnValidThread()); |
| 263 test_phase_ = DURING_TEST; | 264 test_phase_ = DURING_TEST; |
| 264 current_working_directory_ = current_working_directory; | 265 current_working_directory_ = current_working_directory; |
| 265 enable_pixel_dumping_ = enable_pixel_dumping; | 266 enable_pixel_dumping_ = enable_pixel_dumping; |
| 266 expected_pixel_hash_ = expected_pixel_hash; | 267 expected_pixel_hash_ = expected_pixel_hash; |
| 267 test_url_ = test_url; | 268 test_url_ = test_url; |
| 268 did_send_initial_test_configuration_ = false; | 269 did_send_initial_test_configuration_ = false; |
| 269 printer_->reset(); | 270 printer_->reset(); |
| 270 frame_to_layout_dump_map_.clear(); | 271 frame_to_layout_dump_map_.clear(); |
| 271 render_process_host_observer_.RemoveAll(); | 272 render_process_host_observer_.RemoveAll(); |
| 273 all_observed_render_process_hosts_.clear(); |
| 274 main_window_render_process_hosts_.clear(); |
| 272 accumulated_layout_test_runtime_flags_changes_.Clear(); | 275 accumulated_layout_test_runtime_flags_changes_.Clear(); |
| 273 ShellBrowserContext* browser_context = | 276 ShellBrowserContext* browser_context = |
| 274 ShellContentBrowserClient::Get()->browser_context(); | 277 ShellContentBrowserClient::Get()->browser_context(); |
| 275 if (test_url.spec().find("compositing/") != std::string::npos) | 278 if (test_url.spec().find("compositing/") != std::string::npos) |
| 276 is_compositing_test_ = true; | 279 is_compositing_test_ = true; |
| 277 initial_size_ = Shell::GetShellDefaultSize(); | 280 initial_size_ = Shell::GetShellDefaultSize(); |
| 278 // The W3C SVG layout tests use a different size than the other layout tests. | 281 // The W3C SVG layout tests use a different size than the other layout tests. |
| 279 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) | 282 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) |
| 280 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 283 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
| 281 if (!main_window_) { | 284 if (!main_window_) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 488 |
| 486 void BlinkTestController::WebContentsDestroyed() { | 489 void BlinkTestController::WebContentsDestroyed() { |
| 487 DCHECK(CalledOnValidThread()); | 490 DCHECK(CalledOnValidThread()); |
| 488 printer_->AddErrorMessage("FAIL: main window was destroyed"); | 491 printer_->AddErrorMessage("FAIL: main window was destroyed"); |
| 489 DiscardMainWindow(); | 492 DiscardMainWindow(); |
| 490 } | 493 } |
| 491 | 494 |
| 492 void BlinkTestController::RenderProcessHostDestroyed( | 495 void BlinkTestController::RenderProcessHostDestroyed( |
| 493 RenderProcessHost* render_process_host) { | 496 RenderProcessHost* render_process_host) { |
| 494 render_process_host_observer_.Remove(render_process_host); | 497 render_process_host_observer_.Remove(render_process_host); |
| 498 all_observed_render_process_hosts_.erase(render_process_host); |
| 499 main_window_render_process_hosts_.erase(render_process_host); |
| 495 } | 500 } |
| 496 | 501 |
| 497 void BlinkTestController::RenderProcessExited( | 502 void BlinkTestController::RenderProcessExited( |
| 498 RenderProcessHost* render_process_host, | 503 RenderProcessHost* render_process_host, |
| 499 base::TerminationStatus status, | 504 base::TerminationStatus status, |
| 500 int exit_code) { | 505 int exit_code) { |
| 501 DCHECK(CalledOnValidThread()); | 506 DCHECK(CalledOnValidThread()); |
| 502 switch (status) { | 507 switch (status) { |
| 503 case base::TerminationStatus::TERMINATION_STATUS_NORMAL_TERMINATION: | 508 case base::TerminationStatus::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 504 case base::TerminationStatus::TERMINATION_STATUS_STILL_RUNNING: | 509 case base::TerminationStatus::TERMINATION_STATUS_STILL_RUNNING: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 test_phase_ = CLEAN_UP; | 572 test_phase_ = CLEAN_UP; |
| 568 } else if (main_window_) { | 573 } else if (main_window_) { |
| 569 main_window_->Close(); | 574 main_window_->Close(); |
| 570 } | 575 } |
| 571 main_window_ = NULL; | 576 main_window_ = NULL; |
| 572 current_pid_ = base::kNullProcessId; | 577 current_pid_ = base::kNullProcessId; |
| 573 } | 578 } |
| 574 | 579 |
| 575 void BlinkTestController::HandleNewRenderFrameHost(RenderFrameHost* frame) { | 580 void BlinkTestController::HandleNewRenderFrameHost(RenderFrameHost* frame) { |
| 576 RenderProcessHost* process = frame->GetProcess(); | 581 RenderProcessHost* process = frame->GetProcess(); |
| 582 bool main_window = |
| 583 WebContents::FromRenderFrameHost(frame) == main_window_->web_contents(); |
| 577 | 584 |
| 578 // Track pid of the renderer handling the main frame. | 585 // Track pid of the renderer handling the main frame. |
| 579 if (frame->GetParent() == nullptr) { | 586 if (main_window && frame->GetParent() == nullptr) { |
| 580 base::ProcessHandle process_handle = process->GetHandle(); | 587 base::ProcessHandle process_handle = process->GetHandle(); |
| 581 if (process_handle != base::kNullProcessHandle) | 588 if (process_handle != base::kNullProcessHandle) |
| 582 current_pid_ = base::GetProcId(process_handle); | 589 current_pid_ = base::GetProcId(process_handle); |
| 583 } | 590 } |
| 584 | 591 |
| 585 // Does RenderFrameHost map to a RenderFrame in a previously unknown process? | 592 // Is this the 1st time this renderer contains parts of the main test window? |
| 586 if (render_process_host_observer_.IsObserving(process)) | 593 if (main_window && !ContainsKey(main_window_render_process_hosts_, process)) { |
| 587 return; // No need to do anything more for an already known process. | 594 main_window_render_process_hosts_.insert(process); |
| 588 render_process_host_observer_.Add(process); | |
| 589 | 595 |
| 590 // Make sure the new renderer process has a test configuration shared with | 596 // Make sure the new renderer process has a test configuration shared with |
| 591 // other renderers. | 597 // other renderers. |
| 592 ShellTestConfiguration params; | 598 ShellTestConfiguration params; |
| 593 params.current_working_directory = current_working_directory_; | 599 params.current_working_directory = current_working_directory_; |
| 594 params.temp_path = temp_path_; | 600 params.temp_path = temp_path_; |
| 595 params.test_url = test_url_; | 601 params.test_url = test_url_; |
| 596 params.enable_pixel_dumping = enable_pixel_dumping_; | 602 params.enable_pixel_dumping = enable_pixel_dumping_; |
| 597 params.allow_external_pages = | 603 params.allow_external_pages = |
| 598 base::CommandLine::ForCurrentProcess()->HasSwitch( | 604 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 599 switches::kAllowExternalPages); | 605 switches::kAllowExternalPages); |
| 600 params.expected_pixel_hash = expected_pixel_hash_; | 606 params.expected_pixel_hash = expected_pixel_hash_; |
| 601 params.initial_size = initial_size_; | 607 params.initial_size = initial_size_; |
| 602 | 608 |
| 603 if (did_send_initial_test_configuration_) { | 609 if (did_send_initial_test_configuration_) { |
| 604 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( | 610 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( |
| 605 frame->GetRoutingID(), params, | 611 frame->GetRoutingID(), params, |
| 606 accumulated_layout_test_runtime_flags_changes_)); | 612 accumulated_layout_test_runtime_flags_changes_)); |
| 607 } else { | 613 } else { |
| 608 did_send_initial_test_configuration_ = true; | 614 did_send_initial_test_configuration_ = true; |
| 609 frame->Send( | 615 frame->Send( |
| 610 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); | 616 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); |
| 617 } |
| 618 } |
| 619 |
| 620 // Is this a previously unknown renderer process? |
| 621 if (!render_process_host_observer_.IsObserving(process)) { |
| 622 render_process_host_observer_.Add(process); |
| 623 all_observed_render_process_hosts_.insert(process); |
| 624 |
| 625 if (!main_window) { |
| 626 frame->Send( |
| 627 new ShellViewMsg_SetupSecondaryRenderer(frame->GetRoutingID())); |
| 628 } |
| 611 } | 629 } |
| 612 } | 630 } |
| 613 | 631 |
| 614 void BlinkTestController::OnTestFinished() { | 632 void BlinkTestController::OnTestFinished() { |
| 615 test_phase_ = CLEAN_UP; | 633 test_phase_ = CLEAN_UP; |
| 616 if (!printer_->output_finished()) | 634 if (!printer_->output_finished()) |
| 617 printer_->PrintImageFooter(); | 635 printer_->PrintImageFooter(); |
| 618 RenderViewHost* render_view_host = | 636 RenderViewHost* render_view_host = |
| 619 main_window_->web_contents()->GetRenderViewHost(); | 637 main_window_->web_contents()->GetRenderViewHost(); |
| 620 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); | 638 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 } else { | 933 } else { |
| 916 printer_->AddErrorMessage(base::StringPrintf( | 934 printer_->AddErrorMessage(base::StringPrintf( |
| 917 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", | 935 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", |
| 918 event_name.c_str())); | 936 event_name.c_str())); |
| 919 return; | 937 return; |
| 920 } | 938 } |
| 921 bluetooth_chooser_factory_->SendEvent(event, argument); | 939 bluetooth_chooser_factory_->SendEvent(event, argument); |
| 922 } | 940 } |
| 923 | 941 |
| 924 } // namespace content | 942 } // namespace content |
| OLD | NEW |