| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/test_runner/web_widget_test_client.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "components/test_runner/event_sender.h" | |
| 12 #include "components/test_runner/mock_screen_orientation_client.h" | |
| 13 #include "components/test_runner/test_interfaces.h" | |
| 14 #include "components/test_runner/test_runner.h" | |
| 15 #include "components/test_runner/test_runner_for_specific_view.h" | |
| 16 #include "components/test_runner/web_test_delegate.h" | |
| 17 #include "components/test_runner/web_view_test_proxy.h" | |
| 18 #include "components/test_runner/web_widget_test_proxy.h" | |
| 19 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | |
| 20 #include "third_party/WebKit/public/web/WebPagePopup.h" | |
| 21 #include "third_party/WebKit/public/web/WebWidget.h" | |
| 22 | |
| 23 namespace test_runner { | |
| 24 | |
| 25 WebWidgetTestClient::WebWidgetTestClient( | |
| 26 WebWidgetTestProxyBase* web_widget_test_proxy_base) | |
| 27 : web_widget_test_proxy_base_(web_widget_test_proxy_base), | |
| 28 animation_scheduled_(false), | |
| 29 weak_factory_(this) { | |
| 30 DCHECK(web_widget_test_proxy_base_); | |
| 31 } | |
| 32 | |
| 33 WebWidgetTestClient::~WebWidgetTestClient() {} | |
| 34 | |
| 35 void WebWidgetTestClient::scheduleAnimation() { | |
| 36 if (!test_runner()->TestIsRunning()) | |
| 37 return; | |
| 38 | |
| 39 if (!animation_scheduled_) { | |
| 40 animation_scheduled_ = true; | |
| 41 delegate()->PostDelayedTask(base::Bind(&WebWidgetTestClient::AnimateNow, | |
| 42 weak_factory_.GetWeakPtr()), | |
| 43 1); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void WebWidgetTestClient::AnimateNow() { | |
| 48 if (animation_scheduled_) { | |
| 49 blink::WebWidget* web_widget = web_widget_test_proxy_base_->web_widget(); | |
| 50 animation_scheduled_ = false; | |
| 51 base::TimeDelta animate_time = base::TimeTicks::Now() - base::TimeTicks(); | |
| 52 web_widget->beginFrame(animate_time.InSecondsF()); | |
| 53 web_widget->updateAllLifecyclePhases(); | |
| 54 if (blink::WebPagePopup* popup = web_widget->pagePopup()) { | |
| 55 popup->beginFrame(animate_time.InSecondsF()); | |
| 56 popup->updateAllLifecyclePhases(); | |
| 57 } | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 blink::WebScreenInfo WebWidgetTestClient::screenInfo() { | |
| 62 blink::WebScreenInfo screen_info; | |
| 63 MockScreenOrientationClient* mock_client = | |
| 64 test_runner()->getMockScreenOrientationClient(); | |
| 65 if (mock_client->IsDisabled()) { | |
| 66 // Indicate to WebViewTestProxy that there is no test/mock info. | |
| 67 screen_info.orientationType = blink::WebScreenOrientationUndefined; | |
| 68 } else { | |
| 69 // Override screen orientation information with mock data. | |
| 70 screen_info.orientationType = mock_client->CurrentOrientationType(); | |
| 71 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); | |
| 72 } | |
| 73 return screen_info; | |
| 74 } | |
| 75 | |
| 76 bool WebWidgetTestClient::requestPointerLock() { | |
| 77 return view_test_runner()->RequestPointerLock(); | |
| 78 } | |
| 79 | |
| 80 void WebWidgetTestClient::requestPointerUnlock() { | |
| 81 view_test_runner()->RequestPointerUnlock(); | |
| 82 } | |
| 83 | |
| 84 bool WebWidgetTestClient::isPointerLocked() { | |
| 85 return view_test_runner()->isPointerLocked(); | |
| 86 } | |
| 87 | |
| 88 void WebWidgetTestClient::setToolTipText(const blink::WebString& text, | |
| 89 blink::WebTextDirection direction) { | |
| 90 test_runner()->setToolTipText(text); | |
| 91 } | |
| 92 | |
| 93 void WebWidgetTestClient::startDragging(blink::WebReferrerPolicy policy, | |
| 94 const blink::WebDragData& data, | |
| 95 blink::WebDragOperationsMask mask, | |
| 96 const blink::WebImage& image, | |
| 97 const blink::WebPoint& point) { | |
| 98 test_runner()->setDragImage(image); | |
| 99 | |
| 100 // When running a test, we need to fake a drag drop operation otherwise | |
| 101 // Windows waits for real mouse events to know when the drag is over. | |
| 102 web_widget_test_proxy_base_->event_sender()->DoDragDrop(data, mask); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 TestRunnerForSpecificView* WebWidgetTestClient::view_test_runner() { | |
| 107 return web_widget_test_proxy_base_->web_view_test_proxy_base() | |
| 108 ->view_test_runner(); | |
| 109 } | |
| 110 | |
| 111 WebTestDelegate* WebWidgetTestClient::delegate() { | |
| 112 return web_widget_test_proxy_base_->web_view_test_proxy_base()->delegate(); | |
| 113 } | |
| 114 | |
| 115 TestRunner* WebWidgetTestClient::test_runner() { | |
| 116 return web_widget_test_proxy_base_->web_view_test_proxy_base() | |
| 117 ->test_interfaces() | |
| 118 ->GetTestRunner(); | |
| 119 } | |
| 120 | |
| 121 } // namespace test_runner | |
| OLD | NEW |