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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iostream> | 9 #include <iostream> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/base64.h" | 12 #include "base/base64.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" |
15 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
19 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 22 #include "build/build_config.h" |
21 #include "content/public/browser/devtools_agent_host.h" | 23 #include "content/public/browser/devtools_agent_host.h" |
22 #include "content/public/browser/dom_storage_context.h" | 24 #include "content/public/browser/dom_storage_context.h" |
23 #include "content/public/browser/gpu_data_manager.h" | 25 #include "content/public/browser/gpu_data_manager.h" |
24 #include "content/public/browser/navigation_controller.h" | 26 #include "content/public/browser/navigation_controller.h" |
25 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
26 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 30 #include "content/public/browser/render_frame_host.h" |
28 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
31 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
32 #include "content/public/browser/service_worker_context.h" | 35 #include "content/public/browser/service_worker_context.h" |
33 #include "content/public/browser/storage_partition.h" | 36 #include "content/public/browser/storage_partition.h" |
34 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
35 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
37 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 40 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
38 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" | 41 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" |
39 #include "content/shell/browser/shell.h" | 42 #include "content/shell/browser/shell.h" |
40 #include "content/shell/browser/shell_browser_context.h" | 43 #include "content/shell/browser/shell_browser_context.h" |
41 #include "content/shell/browser/shell_content_browser_client.h" | 44 #include "content/shell/browser/shell_content_browser_client.h" |
42 #include "content/shell/browser/shell_devtools_frontend.h" | 45 #include "content/shell/browser/shell_devtools_frontend.h" |
43 #include "content/shell/common/shell_messages.h" | 46 #include "content/shell/common/shell_messages.h" |
44 #include "content/shell/common/shell_switches.h" | 47 #include "content/shell/common/shell_switches.h" |
45 #include "content/shell/renderer/layout_test/blink_test_helpers.h" | 48 #include "content/shell/renderer/layout_test/blink_test_helpers.h" |
46 #include "ui/gfx/codec/png_codec.h" | 49 #include "ui/gfx/codec/png_codec.h" |
47 | 50 |
48 namespace content { | 51 namespace content { |
49 | 52 |
| 53 namespace { |
| 54 |
50 const int kTestSVGWindowWidthDip = 480; | 55 const int kTestSVGWindowWidthDip = 480; |
51 const int kTestSVGWindowHeightDip = 360; | 56 const int kTestSVGWindowHeightDip = 360; |
52 | 57 |
| 58 void AppendLayoutDumpForFrame( |
| 59 const std::map<int, std::string>& frame_to_layout_dump_map, |
| 60 std::string* stitched_layout_dump, |
| 61 RenderFrameHost* target) { |
| 62 auto it = frame_to_layout_dump_map.find(target->GetFrameTreeNodeId()); |
| 63 |
| 64 // No match will happen if frames have been added since OnInitiateLayoutDump. |
| 65 if (it == frame_to_layout_dump_map.end()) |
| 66 return; |
| 67 |
| 68 const std::string& dump = it->second; |
| 69 stitched_layout_dump->append(dump); |
| 70 } |
| 71 |
| 72 } // namespace |
| 73 |
53 // BlinkTestResultPrinter ---------------------------------------------------- | 74 // BlinkTestResultPrinter ---------------------------------------------------- |
54 | 75 |
55 BlinkTestResultPrinter::BlinkTestResultPrinter(std::ostream* output, | 76 BlinkTestResultPrinter::BlinkTestResultPrinter(std::ostream* output, |
56 std::ostream* error) | 77 std::ostream* error) |
57 : state_(DURING_TEST), | 78 : state_(DURING_TEST), |
58 capture_text_only_(false), | 79 capture_text_only_(false), |
59 encode_binary_data_(false), | 80 encode_binary_data_(false), |
60 output_(output), | 81 output_(output), |
61 error_(error) { | 82 error_(error) { |
62 } | 83 } |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 const base::FilePath& current_working_directory, | 271 const base::FilePath& current_working_directory, |
251 bool enable_pixel_dumping, | 272 bool enable_pixel_dumping, |
252 const std::string& expected_pixel_hash) { | 273 const std::string& expected_pixel_hash) { |
253 DCHECK(CalledOnValidThread()); | 274 DCHECK(CalledOnValidThread()); |
254 test_phase_ = DURING_TEST; | 275 test_phase_ = DURING_TEST; |
255 current_working_directory_ = current_working_directory; | 276 current_working_directory_ = current_working_directory; |
256 enable_pixel_dumping_ = enable_pixel_dumping; | 277 enable_pixel_dumping_ = enable_pixel_dumping; |
257 expected_pixel_hash_ = expected_pixel_hash; | 278 expected_pixel_hash_ = expected_pixel_hash; |
258 test_url_ = test_url; | 279 test_url_ = test_url; |
259 printer_->reset(); | 280 printer_->reset(); |
| 281 frame_to_layout_dump_map_.clear(); |
260 ShellBrowserContext* browser_context = | 282 ShellBrowserContext* browser_context = |
261 ShellContentBrowserClient::Get()->browser_context(); | 283 ShellContentBrowserClient::Get()->browser_context(); |
262 if (test_url.spec().find("compositing/") != std::string::npos) | 284 if (test_url.spec().find("compositing/") != std::string::npos) |
263 is_compositing_test_ = true; | 285 is_compositing_test_ = true; |
264 initial_size_ = Shell::GetShellDefaultSize(); | 286 initial_size_ = Shell::GetShellDefaultSize(); |
265 // The W3C SVG layout tests use a different size than the other layout tests. | 287 // The W3C SVG layout tests use a different size than the other layout tests. |
266 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) | 288 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) |
267 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); | 289 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); |
268 if (!main_window_) { | 290 if (!main_window_) { |
269 main_window_ = content::Shell::CreateNewWindow( | 291 main_window_ = content::Shell::CreateNewWindow( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 } | 407 } |
386 return nullptr; | 408 return nullptr; |
387 } | 409 } |
388 | 410 |
389 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { | 411 bool BlinkTestController::OnMessageReceived(const IPC::Message& message) { |
390 DCHECK(CalledOnValidThread()); | 412 DCHECK(CalledOnValidThread()); |
391 bool handled = true; | 413 bool handled = true; |
392 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message) | 414 IPC_BEGIN_MESSAGE_MAP(BlinkTestController, message) |
393 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage) | 415 IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage) |
394 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) | 416 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) |
| 417 IPC_MESSAGE_HANDLER(ShellViewHostMsg_InitiateLayoutDump, |
| 418 OnInitiateLayoutDump) |
395 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) | 419 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ImageDump, OnImageDump) |
396 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump) | 420 IPC_MESSAGE_HANDLER(ShellViewHostMsg_AudioDump, OnAudioDump) |
397 IPC_MESSAGE_HANDLER(ShellViewHostMsg_OverridePreferences, | 421 IPC_MESSAGE_HANDLER(ShellViewHostMsg_OverridePreferences, |
398 OnOverridePreferences) | 422 OnOverridePreferences) |
399 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinished, OnTestFinished) | 423 IPC_MESSAGE_HANDLER(ShellViewHostMsg_TestFinished, OnTestFinished) |
400 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ClearDevToolsLocalStorage, | 424 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ClearDevToolsLocalStorage, |
401 OnClearDevToolsLocalStorage) | 425 OnClearDevToolsLocalStorage) |
402 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools) | 426 IPC_MESSAGE_HANDLER(ShellViewHostMsg_ShowDevTools, OnShowDevTools) |
403 IPC_MESSAGE_HANDLER(ShellViewHostMsg_CloseDevTools, OnCloseDevTools) | 427 IPC_MESSAGE_HANDLER(ShellViewHostMsg_CloseDevTools, OnCloseDevTools) |
404 IPC_MESSAGE_HANDLER(ShellViewHostMsg_GoToOffset, OnGoToOffset) | 428 IPC_MESSAGE_HANDLER(ShellViewHostMsg_GoToOffset, OnGoToOffset) |
(...skipping 10 matching lines...) Expand all Loading... |
415 IPC_MESSAGE_HANDLER(ShellViewHostMsg_GetBluetoothManualChooserEvents, | 439 IPC_MESSAGE_HANDLER(ShellViewHostMsg_GetBluetoothManualChooserEvents, |
416 OnGetBluetoothManualChooserEvents) | 440 OnGetBluetoothManualChooserEvents) |
417 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SendBluetoothManualChooserEvent, | 441 IPC_MESSAGE_HANDLER(ShellViewHostMsg_SendBluetoothManualChooserEvent, |
418 OnSendBluetoothManualChooserEvent) | 442 OnSendBluetoothManualChooserEvent) |
419 IPC_MESSAGE_UNHANDLED(handled = false) | 443 IPC_MESSAGE_UNHANDLED(handled = false) |
420 IPC_END_MESSAGE_MAP() | 444 IPC_END_MESSAGE_MAP() |
421 | 445 |
422 return handled; | 446 return handled; |
423 } | 447 } |
424 | 448 |
| 449 bool BlinkTestController::OnMessageReceived( |
| 450 const IPC::Message& message, |
| 451 RenderFrameHost* render_frame_host) { |
| 452 bool handled = true; |
| 453 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BlinkTestController, message, |
| 454 render_frame_host) |
| 455 IPC_MESSAGE_HANDLER(ShellViewHostMsg_LayoutDumpResponse, |
| 456 OnLayoutDumpResponse) |
| 457 IPC_MESSAGE_UNHANDLED(handled = false) |
| 458 IPC_END_MESSAGE_MAP() |
| 459 return handled; |
| 460 } |
| 461 |
425 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, | 462 void BlinkTestController::PluginCrashed(const base::FilePath& plugin_path, |
426 base::ProcessId plugin_pid) { | 463 base::ProcessId plugin_pid) { |
427 DCHECK(CalledOnValidThread()); | 464 DCHECK(CalledOnValidThread()); |
428 printer_->AddErrorMessage( | 465 printer_->AddErrorMessage( |
429 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); | 466 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); |
430 base::ThreadTaskRunnerHandle::Get()->PostTask( | 467 base::ThreadTaskRunnerHandle::Get()->PostTask( |
431 FROM_HERE, | 468 FROM_HERE, |
432 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), | 469 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), |
433 base::Unretained(this))); | 470 base::Unretained(this))); |
434 } | 471 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 printer_->PrintAudioBlock(dump); | 627 printer_->PrintAudioBlock(dump); |
591 printer_->PrintAudioFooter(); | 628 printer_->PrintAudioFooter(); |
592 } | 629 } |
593 | 630 |
594 void BlinkTestController::OnTextDump(const std::string& dump) { | 631 void BlinkTestController::OnTextDump(const std::string& dump) { |
595 printer_->PrintTextHeader(); | 632 printer_->PrintTextHeader(); |
596 printer_->PrintTextBlock(dump); | 633 printer_->PrintTextBlock(dump); |
597 printer_->PrintTextFooter(); | 634 printer_->PrintTextFooter(); |
598 } | 635 } |
599 | 636 |
| 637 void BlinkTestController::OnInitiateLayoutDump( |
| 638 test_runner::LayoutDumpFlags layout_dump_flags) { |
| 639 DCHECK(layout_dump_flags.dump_child_frames); |
| 640 pending_layout_dumps_ = main_window_->web_contents()->SendToAllFrames( |
| 641 new ShellViewMsg_LayoutDumpRequest(MSG_ROUTING_NONE, layout_dump_flags)); |
| 642 } |
| 643 |
| 644 void BlinkTestController::OnLayoutDumpResponse(RenderFrameHost* sender, |
| 645 const std::string& dump) { |
| 646 // Store the result. |
| 647 auto pair = frame_to_layout_dump_map_.insert( |
| 648 std::make_pair(sender->GetFrameTreeNodeId(), dump)); |
| 649 bool insertion_took_place = pair.second; |
| 650 DCHECK(insertion_took_place); |
| 651 |
| 652 // See if we need to wait for more responses. |
| 653 pending_layout_dumps_--; |
| 654 DCHECK_LE(0, pending_layout_dumps_); |
| 655 if (pending_layout_dumps_ > 0) |
| 656 return; |
| 657 |
| 658 // Stitch the frame-specific results in the right order. |
| 659 // TODO(lukasza): Replace with a for loop similar to crrev.com/1612503003. |
| 660 std::string stitched_layout_dump; |
| 661 main_window_->web_contents()->ForEachFrame(base::Bind( |
| 662 &AppendLayoutDumpForFrame, |
| 663 base::ConstRef(frame_to_layout_dump_map_), |
| 664 &stitched_layout_dump)); |
| 665 |
| 666 // Continue finishing the test. |
| 667 RenderViewHost* render_view_host = |
| 668 main_window_->web_contents()->GetRenderViewHost(); |
| 669 render_view_host->Send(new ShellViewMsg_LayoutDumpCompleted( |
| 670 render_view_host->GetRoutingID(), stitched_layout_dump)); |
| 671 } |
| 672 |
600 void BlinkTestController::OnPrintMessage(const std::string& message) { | 673 void BlinkTestController::OnPrintMessage(const std::string& message) { |
601 printer_->AddMessageRaw(message); | 674 printer_->AddMessageRaw(message); |
602 } | 675 } |
603 | 676 |
604 void BlinkTestController::OnOverridePreferences(const WebPreferences& prefs) { | 677 void BlinkTestController::OnOverridePreferences(const WebPreferences& prefs) { |
605 should_override_prefs_ = true; | 678 should_override_prefs_ = true; |
606 prefs_ = prefs; | 679 prefs_ = prefs; |
607 } | 680 } |
608 | 681 |
609 void BlinkTestController::OnClearDevToolsLocalStorage() { | 682 void BlinkTestController::OnClearDevToolsLocalStorage() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } else { | 842 } else { |
770 printer_->AddErrorMessage(base::StringPrintf( | 843 printer_->AddErrorMessage(base::StringPrintf( |
771 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", | 844 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", |
772 event_name.c_str())); | 845 event_name.c_str())); |
773 return; | 846 return; |
774 } | 847 } |
775 bluetooth_chooser_factory_->SendEvent(event, argument); | 848 bluetooth_chooser_factory_->SendEvent(event, argument); |
776 } | 849 } |
777 | 850 |
778 } // namespace content | 851 } // namespace content |
OLD | NEW |