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 <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/base64.h" | 13 #include "base/base64.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
21 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "components/test_runner/layout_dump_flags.h" | |
24 #include "content/public/browser/devtools_agent_host.h" | 24 #include "content/public/browser/devtools_agent_host.h" |
25 #include "content/public/browser/dom_storage_context.h" | 25 #include "content/public/browser/dom_storage_context.h" |
26 #include "content/public/browser/gpu_data_manager.h" | 26 #include "content/public/browser/gpu_data_manager.h" |
27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
263 test_phase_ = DURING_TEST; | 263 test_phase_ = DURING_TEST; |
264 current_working_directory_ = current_working_directory; | 264 current_working_directory_ = current_working_directory; |
265 enable_pixel_dumping_ = enable_pixel_dumping; | 265 enable_pixel_dumping_ = enable_pixel_dumping; |
266 expected_pixel_hash_ = expected_pixel_hash; | 266 expected_pixel_hash_ = expected_pixel_hash; |
267 test_url_ = test_url; | 267 test_url_ = test_url; |
268 did_send_initial_test_configuration_ = false; | 268 did_send_initial_test_configuration_ = false; |
269 printer_->reset(); | 269 printer_->reset(); |
270 frame_to_layout_dump_map_.clear(); | 270 frame_to_layout_dump_map_.clear(); |
271 render_process_host_observer_.RemoveAll(); | 271 render_process_host_observer_.RemoveAll(); |
| 272 accumulated_layout_dump_flags_changes_.Clear(); |
272 ShellBrowserContext* browser_context = | 273 ShellBrowserContext* browser_context = |
273 ShellContentBrowserClient::Get()->browser_context(); | 274 ShellContentBrowserClient::Get()->browser_context(); |
274 if (test_url.spec().find("compositing/") != std::string::npos) | 275 if (test_url.spec().find("compositing/") != std::string::npos) |
275 is_compositing_test_ = true; | 276 is_compositing_test_ = true; |
276 initial_size_ = Shell::GetShellDefaultSize(); | 277 initial_size_ = Shell::GetShellDefaultSize(); |
277 // The W3C SVG layout tests use a different size than the other layout tests. | 278 // The W3C SVG layout tests use a different size than the other layout tests. |
278 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) | 279 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) |
279 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 280 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
280 if (!main_window_) { | 281 if (!main_window_) { |
281 main_window_ = content::Shell::CreateNewWindow( | 282 main_window_ = content::Shell::CreateNewWindow( |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 434 |
434 return handled; | 435 return handled; |
435 } | 436 } |
436 | 437 |
437 bool BlinkTestController::OnMessageReceived( | 438 bool BlinkTestController::OnMessageReceived( |
438 const IPC::Message& message, | 439 const IPC::Message& message, |
439 RenderFrameHost* render_frame_host) { | 440 RenderFrameHost* render_frame_host) { |
440 bool handled = true; | 441 bool handled = true; |
441 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BlinkTestController, message, | 442 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BlinkTestController, message, |
442 render_frame_host) | 443 render_frame_host) |
| 444 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpFlagsChanged, |
| 445 OnLayoutDumpFlagsChanged) |
443 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, | 446 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, |
444 OnLayoutDumpResponse) | 447 OnLayoutDumpResponse) |
445 IPC_MESSAGE_UNHANDLED(handled = false) | 448 IPC_MESSAGE_UNHANDLED(handled = false) |
446 IPC_END_MESSAGE_MAP() | 449 IPC_END_MESSAGE_MAP() |
447 return handled; | 450 return handled; |
448 } | 451 } |
449 | 452 |
450 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, | 453 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, |
451 base::ProcessId plugin_pid) { | 454 base::ProcessId plugin_pid) { |
452 DCHECK(CalledOnValidThread()); | 455 DCHECK(CalledOnValidThread()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 params.test_url = test_url_; | 593 params.test_url = test_url_; |
591 params.enable_pixel_dumping = enable_pixel_dumping_; | 594 params.enable_pixel_dumping = enable_pixel_dumping_; |
592 params.allow_external_pages = | 595 params.allow_external_pages = |
593 base::CommandLine::ForCurrentProcess()->HasSwitch( | 596 base::CommandLine::ForCurrentProcess()->HasSwitch( |
594 switches::kAllowExternalPages); | 597 switches::kAllowExternalPages); |
595 params.expected_pixel_hash = expected_pixel_hash_; | 598 params.expected_pixel_hash = expected_pixel_hash_; |
596 params.initial_size = initial_size_; | 599 params.initial_size = initial_size_; |
597 | 600 |
598 if (did_send_initial_test_configuration_) { | 601 if (did_send_initial_test_configuration_) { |
599 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( | 602 frame->Send(new ShellViewMsg_ReplicateTestConfiguration( |
600 frame->GetRoutingID(), params)); | 603 frame->GetRoutingID(), params, accumulated_layout_dump_flags_changes_)); |
601 } else { | 604 } else { |
602 did_send_initial_test_configuration_ = true; | 605 did_send_initial_test_configuration_ = true; |
603 frame->Send( | 606 frame->Send( |
604 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); | 607 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params)); |
605 } | 608 } |
606 } | 609 } |
607 | 610 |
608 void BlinkTestController::OnTestFinished() { | 611 void BlinkTestController::OnTestFinished() { |
609 test_phase_ = CLEAN_UP; | 612 test_phase_ = CLEAN_UP; |
610 if (!printer_->output_finished()) | 613 if (!printer_->output_finished()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 printer_->PrintAudioBlock(dump); | 663 printer_->PrintAudioBlock(dump); |
661 printer_->PrintAudioFooter(); | 664 printer_->PrintAudioFooter(); |
662 } | 665 } |
663 | 666 |
664 void BlinkTestController::OnTextDump(const std::string& dump) { | 667 void BlinkTestController::OnTextDump(const std::string& dump) { |
665 printer_->PrintTextHeader(); | 668 printer_->PrintTextHeader(); |
666 printer_->PrintTextBlock(dump); | 669 printer_->PrintTextBlock(dump); |
667 printer_->PrintTextFooter(); | 670 printer_->PrintTextFooter(); |
668 } | 671 } |
669 | 672 |
670 void BlinkTestController::OnInitiateLayoutDump( | 673 void BlinkTestController::OnInitiateLayoutDump() { |
671 const test_runner::LayoutDumpFlags& layout_dump_flags) { | |
672 DCHECK(layout_dump_flags.dump_child_frames()); | |
673 pending_layout_dumps_ = main_window_->web_contents()->SendToAllFrames( | 674 pending_layout_dumps_ = main_window_->web_contents()->SendToAllFrames( |
674 new ShellViewMsg_LayoutDumpRequest(MSG_ROUTING_NONE, layout_dump_flags)); | 675 new ShellViewMsg_LayoutDumpRequest(MSG_ROUTING_NONE)); |
| 676 } |
| 677 |
| 678 void BlinkTestController::OnLayoutDumpFlagsChanged( |
| 679 RenderFrameHost* sender, |
| 680 const base::DictionaryValue& changed_layout_dump_flags) { |
| 681 // Stash the changes for future renderers. |
| 682 accumulated_layout_dump_flags_changes_.MergeDictionary( |
| 683 &changed_layout_dump_flags); |
| 684 |
| 685 // Only need to send the propagation message once per renderer process. |
| 686 std::set<int> already_covered_process_ids; |
| 687 |
| 688 // No need to propagate the changes back to the process that originated them. |
| 689 // (propagating them back could also clobber subsequent changes in the |
| 690 // originator). |
| 691 already_covered_process_ids.insert(sender->GetProcess()->GetID()); |
| 692 |
| 693 // Propagate the changes to all the renderer processes associated with the |
| 694 // main window. |
| 695 for (RenderFrameHost* frame : main_window_->web_contents()->GetAllFrames()) { |
| 696 bool inserted_new_item = |
| 697 already_covered_process_ids.insert(frame->GetProcess()->GetID()).second; |
| 698 if (inserted_new_item) { |
| 699 frame->Send(new ShellViewMsg_ReplicateLayoutDumpFlagsChanges( |
| 700 frame->GetRoutingID(), changed_layout_dump_flags)); |
| 701 } |
| 702 } |
675 } | 703 } |
676 | 704 |
677 void BlinkTestController::OnLayoutDumpResponse(RenderFrameHost* sender, | 705 void BlinkTestController::OnLayoutDumpResponse(RenderFrameHost* sender, |
678 const std::string& dump) { | 706 const std::string& dump) { |
679 // Store the result. | 707 // Store the result. |
680 auto pair = frame_to_layout_dump_map_.insert( | 708 auto pair = frame_to_layout_dump_map_.insert( |
681 std::make_pair(sender->GetFrameTreeNodeId(), dump)); | 709 std::make_pair(sender->GetFrameTreeNodeId(), dump)); |
682 bool insertion_took_place = pair.second; | 710 bool insertion_took_place = pair.second; |
683 DCHECK(insertion_took_place); | 711 DCHECK(insertion_took_place); |
684 | 712 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } else { | 906 } else { |
879 printer_->AddErrorMessage(base::StringPrintf( | 907 printer_->AddErrorMessage(base::StringPrintf( |
880 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", | 908 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", |
881 event_name.c_str())); | 909 event_name.c_str())); |
882 return; | 910 return; |
883 } | 911 } |
884 bluetooth_chooser_factory_->SendEvent(event, argument); | 912 bluetooth_chooser_factory_->SendEvent(event, argument); |
885 } | 913 } |
886 | 914 |
887 } // namespace content | 915 } // namespace content |
OLD | NEW |