Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: components/test_runner/web_widget_test_proxy.h

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 WebLocalFrame;
18 class WebString;
19 class WebWidget;
20 }
21
22 namespace test_runner {
23
24 class EventSender;
25 class WebViewTestProxyBase;
26
27 class TEST_RUNNER_EXPORT WebWidgetTestProxyBase {
28 public:
29 blink::WebWidget* web_widget() { return web_widget_; }
30 void set_web_widget(blink::WebWidget* widget) {
31 DCHECK(widget);
32 DCHECK(!web_widget_);
33 web_widget_ = widget;
34 }
35
36 void set_widget_test_client(
37 std::unique_ptr<WebWidgetTestClient> widget_test_client) {
38 DCHECK(widget_test_client);
39 DCHECK(!widget_test_client_);
40 widget_test_client_ = std::move(widget_test_client);
41 }
42
43 WebViewTestProxyBase* web_view_test_proxy_base() const {
44 return web_view_test_proxy_base_;
45 }
46 void set_web_view_test_proxy_base(
47 WebViewTestProxyBase* web_view_test_proxy_base) {
48 DCHECK(web_view_test_proxy_base);
49 DCHECK(!web_view_test_proxy_base_);
50 web_view_test_proxy_base_ = web_view_test_proxy_base;
51 }
52
53 EventSender* event_sender() { return event_sender_.get(); }
54
55 void Reset();
56 void BindTo(blink::WebLocalFrame* frame);
57
58 protected:
59 WebWidgetTestProxyBase();
60 ~WebWidgetTestProxyBase();
61
62 blink::WebWidgetClient* widget_test_client() {
63 return widget_test_client_.get();
64 }
65
66 private:
67 blink::WebWidget* web_widget_;
68 WebViewTestProxyBase* web_view_test_proxy_base_;
69 std::unique_ptr<WebWidgetTestClient> widget_test_client_;
70 std::unique_ptr<EventSender> event_sender_;
71
72 DISALLOW_COPY_AND_ASSIGN(WebWidgetTestProxyBase);
73 };
74
75 // WebWidgetTestProxy is used during LayoutTests and always instantiated, at
76 // time of writing with Base=RenderWidget. It does not directly inherit from it
77 // for layering purposes.
78 // The intent of that class is to wrap RenderWidget for tests purposes in
79 // order to reduce the amount of test specific code in the production code.
80 // WebWidgetTestProxy is only doing the glue between RenderWidget and
81 // WebWidgetTestProxyBase, that means that there is no logic living in this
82 // class except deciding which base class should be called (could be both).
83 //
84 // Examples of usage:
85 // * when a fooClient has a mock implementation, WebWidgetTestProxy can
86 // override the fooClient() call and have WebWidgetTestProxyBase return the
87 // mock implementation.
88 // * when a value needs to be overridden by LayoutTests, WebWidgetTestProxy can
89 // override RenderViewImpl's getter and call a getter from
90 // WebWidgetTestProxyBase instead. In addition, WebWidgetTestProxyBase will
91 // have a public setter that could be called from the TestRunner.
92 template <class Base, typename... Args>
93 class WebWidgetTestProxy : public Base, public WebWidgetTestProxyBase {
94 public:
95 explicit WebWidgetTestProxy(Args... args) : Base(args...) {}
96
97 // WebWidgetClient implementation.
98 blink::WebScreenInfo screenInfo() override {
99 blink::WebScreenInfo info = Base::screenInfo();
100 blink::WebScreenInfo test_info = widget_test_client()->screenInfo();
101 if (test_info.orientationType != blink::WebScreenOrientationUndefined) {
102 info.orientationType = test_info.orientationType;
103 info.orientationAngle = test_info.orientationAngle;
104 }
105 return info;
106 }
107 void scheduleAnimation() override {
108 Base::scheduleAnimation();
109 widget_test_client()->scheduleAnimation();
110 }
111 bool requestPointerLock() override {
112 return widget_test_client()->requestPointerLock();
113 }
114 void requestPointerUnlock() override {
115 widget_test_client()->requestPointerUnlock();
116 }
117 bool isPointerLocked() override {
118 return widget_test_client()->isPointerLocked();
119 }
120 void setToolTipText(const blink::WebString& text,
121 blink::WebTextDirection hint) override {
122 Base::setToolTipText(text, hint);
123 widget_test_client()->setToolTipText(text, hint);
124 }
125 void startDragging(blink::WebReferrerPolicy policy,
126 const blink::WebDragData& data,
127 blink::WebDragOperationsMask mask,
128 const blink::WebImage& image,
129 const blink::WebPoint& point) override {
130 widget_test_client()->startDragging(policy, data, mask, image, point);
131 // Don't forward this call to Base because we don't want to do a real
132 // drag-and-drop.
133 }
134
135 private:
136 virtual ~WebWidgetTestProxy() {}
137
138 DISALLOW_COPY_AND_ASSIGN(WebWidgetTestProxy);
139 };
140
141 } // namespace test_runner
142
143 #endif // COMPONENTS_TEST_RUNNER_WEB_WIDGET_TEST_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698