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 #ifndef COMPONENTS_TEST_RUNNER_WEB_WIDGET_TEST_PROXY_H_ |
| 6 #define COMPONENTS_TEST_RUNNER_WEB_WIDGET_TEST_PROXY_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
| 12 #include "components/test_runner/test_runner_export.h" |
| 13 #include "components/test_runner/web_widget_test_client.h" |
| 14 #include "third_party/WebKit/public/web/WebWidgetClient.h" |
| 15 |
| 16 namespace blink { |
| 17 class WebString; |
| 18 class WebWidget; |
| 19 } |
| 20 |
| 21 namespace test_runner { |
| 22 |
| 23 class TEST_RUNNER_EXPORT WebWidgetTestProxyBase { |
| 24 public: |
| 25 blink::WebWidget* web_widget() { return web_widget_; } |
| 26 void set_web_widget(blink::WebWidget* widget) { |
| 27 DCHECK(widget); |
| 28 DCHECK(!web_widget_); |
| 29 web_widget_ = widget; |
| 30 } |
| 31 |
| 32 void set_widget_test_client( |
| 33 std::unique_ptr<WebWidgetTestClient> widget_test_client) { |
| 34 DCHECK(widget_test_client); |
| 35 DCHECK(!widget_test_client_); |
| 36 widget_test_client_ = std::move(widget_test_client); |
| 37 } |
| 38 |
| 39 protected: |
| 40 WebWidgetTestProxyBase(); |
| 41 ~WebWidgetTestProxyBase(); |
| 42 |
| 43 blink::WebWidgetClient* widget_test_client() { |
| 44 return widget_test_client_.get(); |
| 45 } |
| 46 |
| 47 private: |
| 48 blink::WebWidget* web_widget_; |
| 49 std::unique_ptr<WebWidgetTestClient> widget_test_client_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(WebWidgetTestProxyBase); |
| 52 }; |
| 53 |
| 54 // WebWidgetTestProxy is used during LayoutTests and always instantiated, at |
| 55 // time of writing with Base=RenderWidget. It does not directly inherit from it |
| 56 // for layering purposes. |
| 57 // The intent of that class is to wrap RenderWidget for tests purposes in |
| 58 // order to reduce the amount of test specific code in the production code. |
| 59 // WebWidgetTestProxy is only doing the glue between RenderWidget and |
| 60 // WebWidgetTestProxyBase, that means that there is no logic living in this |
| 61 // class except deciding which base class should be called (could be both). |
| 62 // |
| 63 // Examples of usage: |
| 64 // * when a fooClient has a mock implementation, WebWidgetTestProxy can |
| 65 // override the fooClient() call and have WebWidgetTestProxyBase return the |
| 66 // mock implementation. |
| 67 // * when a value needs to be overridden by LayoutTests, WebWidgetTestProxy can |
| 68 // override RenderViewImpl's getter and call a getter from |
| 69 // WebWidgetTestProxyBase instead. In addition, WebWidgetTestProxyBase will |
| 70 // have a public setter that could be called from the TestRunner. |
| 71 template <class Base, typename... Args> |
| 72 class WebWidgetTestProxy : public Base, public WebWidgetTestProxyBase { |
| 73 public: |
| 74 explicit WebWidgetTestProxy(Args... args) : Base(args...) {} |
| 75 |
| 76 // WebWidgetClient implementation. |
| 77 blink::WebScreenInfo screenInfo() override { |
| 78 blink::WebScreenInfo info = Base::screenInfo(); |
| 79 blink::WebScreenInfo test_info = widget_test_client()->screenInfo(); |
| 80 if (test_info.orientationType != blink::WebScreenOrientationUndefined) { |
| 81 info.orientationType = test_info.orientationType; |
| 82 info.orientationAngle = test_info.orientationAngle; |
| 83 } |
| 84 return info; |
| 85 } |
| 86 void scheduleAnimation() override { |
| 87 Base::scheduleAnimation(); |
| 88 widget_test_client()->scheduleAnimation(); |
| 89 } |
| 90 bool requestPointerLock() override { |
| 91 return widget_test_client()->requestPointerLock(); |
| 92 } |
| 93 void requestPointerUnlock() override { |
| 94 widget_test_client()->requestPointerUnlock(); |
| 95 } |
| 96 bool isPointerLocked() override { |
| 97 return widget_test_client()->isPointerLocked(); |
| 98 } |
| 99 void setToolTipText(const blink::WebString& text, |
| 100 blink::WebTextDirection hint) override { |
| 101 Base::setToolTipText(text, hint); |
| 102 widget_test_client()->setToolTipText(text, hint); |
| 103 } |
| 104 void resetInputMethod() override { widget_test_client()->resetInputMethod(); } |
| 105 |
| 106 private: |
| 107 virtual ~WebWidgetTestProxy() {} |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(WebWidgetTestProxy); |
| 110 }; |
| 111 |
| 112 } // namespace test_runner |
| 113 |
| 114 #endif // COMPONENTS_TEST_RUNNER_WEB_WIDGET_TEST_PROXY_H_ |
OLD | NEW |