| 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/mock_screen_orientation_client.h" |
| 12 #include "components/test_runner/test_interfaces.h" |
| 13 #include "components/test_runner/test_runner.h" |
| 14 #include "components/test_runner/test_runner_for_specific_view.h" |
| 15 #include "components/test_runner/web_task.h" |
| 16 #include "components/test_runner/web_test_delegate.h" |
| 17 #include "components/test_runner/web_test_proxy.h" |
| 18 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 19 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 20 #include "third_party/WebKit/public/web/WebWidget.h" |
| 21 |
| 22 namespace test_runner { |
| 23 |
| 24 WebWidgetTestClient::WebWidgetTestClient(TestRunner* test_runner, |
| 25 WebTestProxyBase* web_test_proxy_base) |
| 26 : test_runner_(test_runner), |
| 27 web_test_proxy_base_(web_test_proxy_base), |
| 28 animation_scheduled_(false), |
| 29 weak_factory_(this) { |
| 30 DCHECK(test_runner); |
| 31 DCHECK(web_test_proxy_base); |
| 32 } |
| 33 |
| 34 WebWidgetTestClient::~WebWidgetTestClient() {} |
| 35 |
| 36 void WebWidgetTestClient::scheduleAnimation() { |
| 37 if (!test_runner_->TestIsRunning()) |
| 38 return; |
| 39 |
| 40 if (!animation_scheduled_) { |
| 41 animation_scheduled_ = true; |
| 42 test_runner_->OnAnimationScheduled(web_test_proxy_base_->web_widget()); |
| 43 |
| 44 web_test_proxy_base_->delegate()->PostDelayedTask( |
| 45 new WebCallbackTask(base::Bind(&WebWidgetTestClient::AnimateNow, |
| 46 weak_factory_.GetWeakPtr())), |
| 47 1); |
| 48 } |
| 49 } |
| 50 |
| 51 void WebWidgetTestClient::AnimateNow() { |
| 52 if (animation_scheduled_) { |
| 53 blink::WebWidget* web_widget = web_test_proxy_base_->web_widget(); |
| 54 animation_scheduled_ = false; |
| 55 test_runner_->OnAnimationBegun(web_widget); |
| 56 |
| 57 base::TimeDelta animate_time = base::TimeTicks::Now() - base::TimeTicks(); |
| 58 web_widget->beginFrame(animate_time.InSecondsF()); |
| 59 web_widget->updateAllLifecyclePhases(); |
| 60 if (blink::WebPagePopup* popup = web_widget->pagePopup()) { |
| 61 popup->beginFrame(animate_time.InSecondsF()); |
| 62 popup->updateAllLifecyclePhases(); |
| 63 } |
| 64 } |
| 65 } |
| 66 |
| 67 blink::WebScreenInfo WebWidgetTestClient::screenInfo() { |
| 68 blink::WebScreenInfo screen_info; |
| 69 MockScreenOrientationClient* mock_client = |
| 70 web_test_proxy_base_->test_interfaces() |
| 71 ->GetTestRunner() |
| 72 ->getMockScreenOrientationClient(); |
| 73 if (mock_client->IsDisabled()) { |
| 74 // Indicate to WebTestProxy that there is no test/mock info. |
| 75 screen_info.orientationType = blink::WebScreenOrientationUndefined; |
| 76 } else { |
| 77 // Override screen orientation information with mock data. |
| 78 screen_info.orientationType = mock_client->CurrentOrientationType(); |
| 79 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); |
| 80 } |
| 81 return screen_info; |
| 82 } |
| 83 |
| 84 bool WebWidgetTestClient::requestPointerLock() { |
| 85 return web_test_proxy_base_->view_test_runner()->RequestPointerLock(); |
| 86 } |
| 87 |
| 88 void WebWidgetTestClient::requestPointerUnlock() { |
| 89 web_test_proxy_base_->view_test_runner()->RequestPointerUnlock(); |
| 90 } |
| 91 |
| 92 bool WebWidgetTestClient::isPointerLocked() { |
| 93 return web_test_proxy_base_->view_test_runner()->isPointerLocked(); |
| 94 } |
| 95 |
| 96 void WebWidgetTestClient::didFocus() { |
| 97 test_runner_->SetFocus(web_test_proxy_base_->web_view(), true); |
| 98 } |
| 99 |
| 100 void WebWidgetTestClient::setToolTipText(const blink::WebString& text, |
| 101 blink::WebTextDirection direction) { |
| 102 test_runner_->setToolTipText(text); |
| 103 } |
| 104 |
| 105 void WebWidgetTestClient::resetInputMethod() { |
| 106 // If a composition text exists, then we need to let the browser process |
| 107 // to cancel the input method's ongoing composition session. |
| 108 if (web_test_proxy_base_) |
| 109 web_test_proxy_base_->web_widget()->confirmComposition(); |
| 110 } |
| 111 |
| 112 } // namespace test_runner |
| OLD | NEW |