Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/layout_test/blink_test_runner.h" | 5 #include "content/shell/renderer/layout_test/blink_test_runner.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <clocale> | 9 #include <clocale> |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/base64.h" | 13 #include "base/base64.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/debug/debugger.h" | 16 #include "base/debug/debugger.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/guid.h" | |
| 18 #include "base/location.h" | 19 #include "base/location.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/md5.h" | 21 #include "base/md5.h" |
| 21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/thread_task_runner_handle.h" | 28 #include "base/thread_task_runner_handle.h" |
| 28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 29 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 30 #include "components/plugins/renderer/plugin_placeholder.h" | 31 #include "components/plugins/renderer/plugin_placeholder.h" |
| 31 #include "components/test_runner/app_banner_client.h" | 32 #include "components/test_runner/app_banner_client.h" |
| 32 #include "components/test_runner/gamepad_controller.h" | 33 #include "components/test_runner/gamepad_controller.h" |
| 33 #include "components/test_runner/layout_dump.h" | 34 #include "components/test_runner/layout_dump.h" |
| 34 #include "components/test_runner/layout_dump_flags.h" | 35 #include "components/test_runner/layout_dump_flags.h" |
| 35 #include "components/test_runner/mock_screen_orientation_client.h" | 36 #include "components/test_runner/mock_screen_orientation_client.h" |
| 36 #include "components/test_runner/test_interfaces.h" | 37 #include "components/test_runner/test_interfaces.h" |
| 38 #include "components/test_runner/tracked_dictionary.h" | |
| 37 #include "components/test_runner/web_task.h" | 39 #include "components/test_runner/web_task.h" |
| 38 #include "components/test_runner/web_test_interfaces.h" | 40 #include "components/test_runner/web_test_interfaces.h" |
| 39 #include "components/test_runner/web_test_proxy.h" | 41 #include "components/test_runner/web_test_proxy.h" |
| 40 #include "components/test_runner/web_test_runner.h" | 42 #include "components/test_runner/web_test_runner.h" |
| 41 #include "content/public/common/content_switches.h" | 43 #include "content/public/common/content_switches.h" |
| 42 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
| 43 #include "content/public/common/web_preferences.h" | 45 #include "content/public/common/web_preferences.h" |
| 44 #include "content/public/renderer/media_stream_api.h" | 46 #include "content/public/renderer/media_stream_api.h" |
| 45 #include "content/public/renderer/render_frame.h" | 47 #include "content/public/renderer/render_frame.h" |
| 46 #include "content/public/renderer/render_view.h" | 48 #include "content/public/renderer/render_view.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 247 |
| 246 } // namespace | 248 } // namespace |
| 247 | 249 |
| 248 BlinkTestRunner::BlinkTestRunner(RenderView* render_view) | 250 BlinkTestRunner::BlinkTestRunner(RenderView* render_view) |
| 249 : RenderViewObserver(render_view), | 251 : RenderViewObserver(render_view), |
| 250 RenderViewObserverTracker<BlinkTestRunner>(render_view), | 252 RenderViewObserverTracker<BlinkTestRunner>(render_view), |
| 251 proxy_(NULL), | 253 proxy_(NULL), |
| 252 focused_view_(NULL), | 254 focused_view_(NULL), |
| 253 is_main_window_(false), | 255 is_main_window_(false), |
| 254 focus_on_next_commit_(false), | 256 focus_on_next_commit_(false), |
| 255 leak_detector_(new LeakDetector(this)) { | 257 leak_detector_(new LeakDetector(this)), |
| 256 } | 258 guid_(base::GenerateGUID()) {} |
| 257 | 259 |
| 258 BlinkTestRunner::~BlinkTestRunner() { | 260 BlinkTestRunner::~BlinkTestRunner() { |
| 259 } | 261 } |
| 260 | 262 |
| 261 // WebTestDelegate ----------------------------------------------------------- | 263 // WebTestDelegate ----------------------------------------------------------- |
| 262 | 264 |
| 263 void BlinkTestRunner::ClearEditCommand() { | 265 void BlinkTestRunner::ClearEditCommand() { |
| 264 render_view()->ClearEditCommands(); | 266 render_view()->ClearEditCommands(); |
| 265 } | 267 } |
| 266 | 268 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 result = result.substr(0, strlen("file:///")) + | 605 result = result.substr(0, strlen("file:///")) + |
| 604 result.substr(strlen("file:////")); | 606 result.substr(strlen("file:////")); |
| 605 } | 607 } |
| 606 return RewriteLayoutTestsURL(result).string().utf8(); | 608 return RewriteLayoutTestsURL(result).string().utf8(); |
| 607 } | 609 } |
| 608 | 610 |
| 609 void BlinkTestRunner::SetLocale(const std::string& locale) { | 611 void BlinkTestRunner::SetLocale(const std::string& locale) { |
| 610 setlocale(LC_ALL, locale.c_str()); | 612 setlocale(LC_ALL, locale.c_str()); |
| 611 } | 613 } |
| 612 | 614 |
| 615 void BlinkTestRunner::OnLayoutDumpFlagsChanged( | |
| 616 test_runner::LayoutDumpFlags* layout_dump_flags) { | |
| 617 // Ignore changes that happen before we got the initial, accumulated | |
| 618 // layout flag changes in ShellViewMsg_ReplicateTestConfiguration. | |
| 619 if (!is_main_window_) | |
| 620 return; | |
| 621 | |
| 622 const base::DictionaryValue& changed_values = | |
| 623 layout_dump_flags->tracked_dictionary().changed_values(); | |
| 624 Send(new ShellViewHostMsg_LayoutDumpFlagsChanged(routing_id(), changed_values, | |
| 625 guid_)); | |
| 626 layout_dump_flags->tracked_dictionary().ResetChangeTracking(); | |
| 627 } | |
| 628 | |
| 613 void BlinkTestRunner::TestFinished() { | 629 void BlinkTestRunner::TestFinished() { |
| 614 if (!is_main_window_ || !render_view()->GetMainRenderFrame()) { | 630 if (!is_main_window_ || !render_view()->GetMainRenderFrame()) { |
| 615 Send(new ShellViewHostMsg_TestFinishedInSecondaryRenderer(routing_id())); | 631 Send(new ShellViewHostMsg_TestFinishedInSecondaryRenderer(routing_id())); |
| 616 return; | 632 return; |
| 617 } | 633 } |
| 618 test_runner::WebTestInterfaces* interfaces = | 634 test_runner::WebTestInterfaces* interfaces = |
| 619 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); | 635 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); |
| 620 interfaces->SetTestIsRunning(false); | 636 interfaces->SetTestIsRunning(false); |
| 621 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { | 637 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { |
| 622 SyncNavigationStateVisitor visitor; | 638 SyncNavigationStateVisitor visitor; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 | 905 |
| 890 const test_runner::LayoutDumpFlags& layout_dump_flags = | 906 const test_runner::LayoutDumpFlags& layout_dump_flags = |
| 891 interfaces->TestRunner()->GetLayoutDumpFlags(); | 907 interfaces->TestRunner()->GetLayoutDumpFlags(); |
| 892 if (!layout_dump_flags.dump_child_frames()) { | 908 if (!layout_dump_flags.dump_child_frames()) { |
| 893 std::string layout_dump = DumpLayout( | 909 std::string layout_dump = DumpLayout( |
| 894 render_view()->GetMainRenderFrame()->GetWebFrame(), layout_dump_flags); | 910 render_view()->GetMainRenderFrame()->GetWebFrame(), layout_dump_flags); |
| 895 OnLayoutDumpCompleted(layout_dump); | 911 OnLayoutDumpCompleted(layout_dump); |
| 896 return; | 912 return; |
| 897 } | 913 } |
| 898 | 914 |
| 899 Send( | 915 Send(new ShellViewHostMsg_InitiateLayoutDump(routing_id())); |
| 900 new ShellViewHostMsg_InitiateLayoutDump(routing_id(), layout_dump_flags)); | |
| 901 // OnLayoutDumpCompleted will be eventually called by an IPC from the browser. | 916 // OnLayoutDumpCompleted will be eventually called by an IPC from the browser. |
| 902 } | 917 } |
| 903 | 918 |
| 904 void BlinkTestRunner::OnLayoutDumpCompleted(std::string completed_layout_dump) { | 919 void BlinkTestRunner::OnLayoutDumpCompleted(std::string completed_layout_dump) { |
| 905 test_runner::WebTestInterfaces* interfaces = | 920 test_runner::WebTestInterfaces* interfaces = |
| 906 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); | 921 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); |
| 907 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { | 922 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) { |
| 908 completed_layout_dump.append(proxy()->DumpBackForwardLists()); | 923 completed_layout_dump.append(proxy()->DumpBackForwardLists()); |
| 909 } | 924 } |
| 910 | 925 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 | 977 |
| 963 void BlinkTestRunner::CaptureDumpComplete() { | 978 void BlinkTestRunner::CaptureDumpComplete() { |
| 964 render_view()->GetWebView()->mainFrame()->stopLoading(); | 979 render_view()->GetWebView()->mainFrame()->stopLoading(); |
| 965 | 980 |
| 966 base::ThreadTaskRunnerHandle::Get()->PostTask( | 981 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 967 FROM_HERE, base::Bind(base::IgnoreResult(&BlinkTestRunner::Send), | 982 FROM_HERE, base::Bind(base::IgnoreResult(&BlinkTestRunner::Send), |
| 968 base::Unretained(this), | 983 base::Unretained(this), |
| 969 new ShellViewHostMsg_TestFinished(routing_id()))); | 984 new ShellViewHostMsg_TestFinished(routing_id()))); |
| 970 } | 985 } |
| 971 | 986 |
| 972 void BlinkTestRunner::OnReplicateTestConfiguration( | 987 void BlinkTestRunner::SetTestConfiguration( |
| 973 const ShellTestConfiguration& params) { | 988 const ShellTestConfiguration& params) { |
| 974 test_config_ = params; | 989 test_config_ = params; |
| 975 is_main_window_ = true; | 990 is_main_window_ = true; |
| 976 | 991 |
| 977 test_runner::WebTestInterfaces* interfaces = | 992 test_runner::WebTestInterfaces* interfaces = |
| 978 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); | 993 LayoutTestRenderProcessObserver::GetInstance()->test_interfaces(); |
| 979 interfaces->SetTestIsRunning(true); | 994 interfaces->SetTestIsRunning(true); |
| 980 interfaces->ConfigureForTestWithURL(params.test_url, | 995 interfaces->ConfigureForTestWithURL(params.test_url, |
| 981 params.enable_pixel_dumping); | 996 params.enable_pixel_dumping); |
| 982 } | 997 } |
| 983 | 998 |
| 999 void BlinkTestRunner::OnReplicateTestConfiguration( | |
| 1000 const ShellTestConfiguration& params, | |
| 1001 const base::DictionaryValue& accumulated_layout_dump_flags_changes) { | |
| 1002 SetTestConfiguration(params); | |
| 1003 LayoutTestRenderProcessObserver::GetInstance() | |
| 1004 ->test_interfaces() | |
| 1005 ->TestRunner() | |
| 1006 ->ReplicateLayoutDumpFlagsChanges(accumulated_layout_dump_flags_changes); | |
| 1007 } | |
| 1008 | |
| 984 void BlinkTestRunner::OnSetTestConfiguration( | 1009 void BlinkTestRunner::OnSetTestConfiguration( |
| 985 const ShellTestConfiguration& params) { | 1010 const ShellTestConfiguration& params) { |
| 986 OnReplicateTestConfiguration(params); | 1011 SetTestConfiguration(params); |
| 987 | 1012 |
| 988 ForceResizeRenderView( | 1013 ForceResizeRenderView( |
| 989 render_view(), | 1014 render_view(), |
| 990 WebSize(params.initial_size.width(), params.initial_size.height())); | 1015 WebSize(params.initial_size.width(), params.initial_size.height())); |
| 991 SetFocus(proxy_, true); | 1016 SetFocus(proxy_, true); |
| 992 } | 1017 } |
| 993 | 1018 |
| 1019 void BlinkTestRunner::OnReplicateLayoutDumpFlagsChanges( | |
| 1020 const base::DictionaryValue& changed_layout_dump_flags, | |
| 1021 const std::string& change_originator_guid) { | |
| 1022 if (change_originator_guid == guid_) | |
| 1023 return; | |
|
Łukasz Anforowicz
2016/03/03 21:46:34
We want to avoid consuming change notification bro
| |
| 1024 | |
| 1025 LayoutTestRenderProcessObserver::GetInstance() | |
| 1026 ->test_interfaces() | |
| 1027 ->TestRunner() | |
| 1028 ->ReplicateLayoutDumpFlagsChanges(changed_layout_dump_flags); | |
| 1029 } | |
| 1030 | |
| 994 void BlinkTestRunner::OnSessionHistory( | 1031 void BlinkTestRunner::OnSessionHistory( |
| 995 const std::vector<int>& routing_ids, | 1032 const std::vector<int>& routing_ids, |
| 996 const std::vector<std::vector<PageState>>& session_histories, | 1033 const std::vector<std::vector<PageState>>& session_histories, |
| 997 const std::vector<unsigned>& current_entry_indexes) { | 1034 const std::vector<unsigned>& current_entry_indexes) { |
| 998 routing_ids_ = routing_ids; | 1035 routing_ids_ = routing_ids; |
| 999 session_histories_ = session_histories; | 1036 session_histories_ = session_histories; |
| 1000 current_entry_indexes_ = current_entry_indexes; | 1037 current_entry_indexes_ = current_entry_indexes; |
| 1001 CaptureDump(); | 1038 CaptureDump(); |
| 1002 } | 1039 } |
| 1003 | 1040 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1033 get_bluetooth_events_callbacks_.pop_front(); | 1070 get_bluetooth_events_callbacks_.pop_front(); |
| 1034 callback.Run(events); | 1071 callback.Run(events); |
| 1035 } | 1072 } |
| 1036 | 1073 |
| 1037 void BlinkTestRunner::ReportLeakDetectionResult( | 1074 void BlinkTestRunner::ReportLeakDetectionResult( |
| 1038 const LeakDetectionResult& report) { | 1075 const LeakDetectionResult& report) { |
| 1039 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); | 1076 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); |
| 1040 } | 1077 } |
| 1041 | 1078 |
| 1042 } // namespace content | 1079 } // namespace content |
| OLD | NEW |