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

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

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

Powered by Google App Engine
This is Rietveld 408576698