| 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> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 ~SyncNavigationStateVisitor() override {} | 121 ~SyncNavigationStateVisitor() override {} |
| 122 | 122 |
| 123 bool Visit(RenderView* render_view) override { | 123 bool Visit(RenderView* render_view) override { |
| 124 SyncNavigationState(render_view); | 124 SyncNavigationState(render_view); |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 private: | 127 private: |
| 128 DISALLOW_COPY_AND_ASSIGN(SyncNavigationStateVisitor); | 128 DISALLOW_COPY_AND_ASSIGN(SyncNavigationStateVisitor); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 class ProxyToRenderViewVisitor : public RenderViewVisitor { | |
| 132 public: | |
| 133 explicit ProxyToRenderViewVisitor(test_runner::WebTestProxyBase* proxy) | |
| 134 : proxy_(proxy), | |
| 135 render_view_(NULL) { | |
| 136 } | |
| 137 ~ProxyToRenderViewVisitor() override {} | |
| 138 | |
| 139 RenderView* render_view() const { return render_view_; } | |
| 140 | |
| 141 bool Visit(RenderView* render_view) override { | |
| 142 BlinkTestRunner* test_runner = BlinkTestRunner::Get(render_view); | |
| 143 if (!test_runner) { | |
| 144 NOTREACHED(); | |
| 145 return true; | |
| 146 } | |
| 147 if (test_runner->proxy() == proxy_) { | |
| 148 render_view_ = render_view; | |
| 149 return false; | |
| 150 } | |
| 151 return true; | |
| 152 } | |
| 153 | |
| 154 private: | |
| 155 test_runner::WebTestProxyBase* proxy_; | |
| 156 RenderView* render_view_; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(ProxyToRenderViewVisitor); | |
| 159 }; | |
| 160 | |
| 161 class UseSynchronousResizeModeVisitor : public RenderViewVisitor { | 131 class UseSynchronousResizeModeVisitor : public RenderViewVisitor { |
| 162 public: | 132 public: |
| 163 explicit UseSynchronousResizeModeVisitor(bool enable) : enable_(enable) {} | 133 explicit UseSynchronousResizeModeVisitor(bool enable) : enable_(enable) {} |
| 164 ~UseSynchronousResizeModeVisitor() override {} | 134 ~UseSynchronousResizeModeVisitor() override {} |
| 165 | 135 |
| 166 bool Visit(RenderView* render_view) override { | 136 bool Visit(RenderView* render_view) override { |
| 167 UseSynchronousResizeMode(render_view, enable_); | 137 UseSynchronousResizeMode(render_view, enable_); |
| 168 return true; | 138 return true; |
| 169 } | 139 } |
| 170 | 140 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 479 |
| 510 void BlinkTestRunner::ClearGeofencingMockProvider() { | 480 void BlinkTestRunner::ClearGeofencingMockProvider() { |
| 511 content::ClearGeofencingMockProvider(); | 481 content::ClearGeofencingMockProvider(); |
| 512 } | 482 } |
| 513 | 483 |
| 514 void BlinkTestRunner::SetGeofencingMockPosition(double latitude, | 484 void BlinkTestRunner::SetGeofencingMockPosition(double latitude, |
| 515 double longitude) { | 485 double longitude) { |
| 516 content::SetGeofencingMockPosition(latitude, longitude); | 486 content::SetGeofencingMockPosition(latitude, longitude); |
| 517 } | 487 } |
| 518 | 488 |
| 519 void BlinkTestRunner::SetFocus(test_runner::WebTestProxyBase* proxy, | 489 void BlinkTestRunner::SetFocus(blink::WebView* web_view, bool focus) { |
| 520 bool focus) { | 490 RenderView* render_view = RenderView::FromWebView(web_view); |
| 521 ProxyToRenderViewVisitor visitor(proxy); | 491 if (!render_view) { |
| 522 RenderView::ForEach(&visitor); | |
| 523 if (!visitor.render_view()) { | |
| 524 NOTREACHED(); | 492 NOTREACHED(); |
| 525 return; | 493 return; |
| 526 } | 494 } |
| 527 | 495 |
| 528 // Check whether the focused view was closed meanwhile. | 496 // Check whether the focused view was closed meanwhile. |
| 529 if (!BlinkTestRunner::Get(focused_view_)) | 497 if (!BlinkTestRunner::Get(focused_view_)) |
| 530 focused_view_ = NULL; | 498 focused_view_ = NULL; |
| 531 | 499 |
| 532 if (focus) { | 500 if (focus) { |
| 533 if (focused_view_ != visitor.render_view()) { | 501 if (focused_view_ != render_view) { |
| 534 if (focused_view_) | 502 if (focused_view_) |
| 535 SetFocusAndActivate(focused_view_, false); | 503 SetFocusAndActivate(focused_view_, false); |
| 536 SetFocusAndActivate(visitor.render_view(), true); | 504 SetFocusAndActivate(render_view, true); |
| 537 focused_view_ = visitor.render_view(); | 505 focused_view_ = render_view; |
| 538 } | 506 } |
| 539 } else { | 507 } else { |
| 540 if (focused_view_ == visitor.render_view()) { | 508 if (focused_view_ == render_view) { |
| 541 SetFocusAndActivate(visitor.render_view(), false); | 509 SetFocusAndActivate(render_view, false); |
| 542 focused_view_ = NULL; | 510 focused_view_ = NULL; |
| 543 } | 511 } |
| 544 } | 512 } |
| 545 } | 513 } |
| 546 | 514 |
| 547 void BlinkTestRunner::SetAcceptAllCookies(bool accept) { | 515 void BlinkTestRunner::SetAcceptAllCookies(bool accept) { |
| 548 Send(new LayoutTestHostMsg_AcceptAllCookies(routing_id(), accept)); | 516 Send(new LayoutTestHostMsg_AcceptAllCookies(routing_id(), accept)); |
| 549 } | 517 } |
| 550 | 518 |
| 551 std::string BlinkTestRunner::PathToLocalResource(const std::string& resource) { | 519 std::string BlinkTestRunner::PathToLocalResource(const std::string& resource) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 } | 778 } |
| 811 | 779 |
| 812 void BlinkTestRunner::DidFailProvisionalLoad(WebLocalFrame* frame, | 780 void BlinkTestRunner::DidFailProvisionalLoad(WebLocalFrame* frame, |
| 813 const WebURLError& error) { | 781 const WebURLError& error) { |
| 814 focus_on_next_commit_ = false; | 782 focus_on_next_commit_ = false; |
| 815 } | 783 } |
| 816 | 784 |
| 817 // Public methods - ----------------------------------------------------------- | 785 // Public methods - ----------------------------------------------------------- |
| 818 | 786 |
| 819 void BlinkTestRunner::Reset(bool for_new_test) { | 787 void BlinkTestRunner::Reset(bool for_new_test) { |
| 820 // The proxy_ is always non-NULL, it is set right after construction. | |
| 821 proxy_->set_widget(render_view()->GetWebView()); | |
| 822 proxy_->Reset(); | |
| 823 prefs_.Reset(); | 788 prefs_.Reset(); |
| 824 routing_ids_.clear(); | 789 routing_ids_.clear(); |
| 825 session_histories_.clear(); | 790 session_histories_.clear(); |
| 826 current_entry_indexes_.clear(); | 791 current_entry_indexes_.clear(); |
| 827 | 792 |
| 828 render_view()->ClearEditCommands(); | 793 render_view()->ClearEditCommands(); |
| 829 if (for_new_test) { | 794 if (for_new_test) { |
| 830 if (render_view()->GetWebView()->mainFrame()->isWebLocalFrame()) | 795 if (render_view()->GetWebView()->mainFrame()->isWebLocalFrame()) |
| 831 render_view()->GetWebView()->mainFrame()->setName(WebString()); | 796 render_view()->GetWebView()->mainFrame()->setName(WebString()); |
| 832 render_view()->GetWebView()->mainFrame()->clearOpener(); | 797 render_view()->GetWebView()->mainFrame()->clearOpener(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 params.enable_pixel_dumping); | 930 params.enable_pixel_dumping); |
| 966 } | 931 } |
| 967 | 932 |
| 968 void BlinkTestRunner::OnSetTestConfiguration( | 933 void BlinkTestRunner::OnSetTestConfiguration( |
| 969 const ShellTestConfiguration& params) { | 934 const ShellTestConfiguration& params) { |
| 970 OnReplicateTestConfiguration(params); | 935 OnReplicateTestConfiguration(params); |
| 971 | 936 |
| 972 ForceResizeRenderView( | 937 ForceResizeRenderView( |
| 973 render_view(), | 938 render_view(), |
| 974 WebSize(params.initial_size.width(), params.initial_size.height())); | 939 WebSize(params.initial_size.width(), params.initial_size.height())); |
| 975 SetFocus(proxy_, true); | 940 SetFocus(proxy_->web_view(), true); |
| 976 } | 941 } |
| 977 | 942 |
| 978 void BlinkTestRunner::OnSessionHistory( | 943 void BlinkTestRunner::OnSessionHistory( |
| 979 const std::vector<int>& routing_ids, | 944 const std::vector<int>& routing_ids, |
| 980 const std::vector<std::vector<PageState>>& session_histories, | 945 const std::vector<std::vector<PageState>>& session_histories, |
| 981 const std::vector<unsigned>& current_entry_indexes) { | 946 const std::vector<unsigned>& current_entry_indexes) { |
| 982 routing_ids_ = routing_ids; | 947 routing_ids_ = routing_ids; |
| 983 session_histories_ = session_histories; | 948 session_histories_ = session_histories; |
| 984 current_entry_indexes_ = current_entry_indexes; | 949 current_entry_indexes_ = current_entry_indexes; |
| 985 CaptureDump(); | 950 CaptureDump(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 get_bluetooth_events_callbacks_.pop_front(); | 982 get_bluetooth_events_callbacks_.pop_front(); |
| 1018 callback.Run(events); | 983 callback.Run(events); |
| 1019 } | 984 } |
| 1020 | 985 |
| 1021 void BlinkTestRunner::ReportLeakDetectionResult( | 986 void BlinkTestRunner::ReportLeakDetectionResult( |
| 1022 const LeakDetectionResult& report) { | 987 const LeakDetectionResult& report) { |
| 1023 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); | 988 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); |
| 1024 } | 989 } |
| 1025 | 990 |
| 1026 } // namespace content | 991 } // namespace content |
| OLD | NEW |