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

Side by Side Diff: content/shell/renderer/test_runner/test_interfaces.cc

Issue 458723002: TestInterfaces to chromium c++ style, rename methods and remove un-used header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated Created 6 years, 4 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 2013 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 "content/shell/renderer/test_runner/test_interfaces.h"
6
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h"
12 #include "content/shell/common/shell_switches.h"
13 #include "content/shell/renderer/test_runner/accessibility_controller.h"
14 #include "content/shell/renderer/test_runner/event_sender.h"
15 #include "content/shell/renderer/test_runner/gamepad_controller.h"
16 #include "content/shell/renderer/test_runner/test_runner.h"
17 #include "content/shell/renderer/test_runner/text_input_controller.h"
18 #include "content/shell/renderer/test_runner/web_test_proxy.h"
19 #include "third_party/WebKit/public/platform/WebURL.h"
20 #include "third_party/WebKit/public/web/WebCache.h"
21 #include "third_party/WebKit/public/web/WebKit.h"
22 #include "third_party/WebKit/public/web/WebView.h"
23
24 namespace content {
25
26 TestInterfaces::TestInterfaces()
27 : accessibility_controller_(new AccessibilityController()),
28 event_sender_(new EventSender(this)),
29 gamepad_controller_(new GamepadController()),
30 text_input_controller_(new TextInputController()),
31 test_runner_(new TestRunner(this)),
32 delegate_(0) {
33 blink::setLayoutTestMode(true);
34 if (CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kEnableFontAntialiasing))
36 blink::setFontAntialiasingEnabledForTest(true);
37
38 // NOTE: please don't put feature specific enable flags here,
39 // instead add them to RuntimeEnabledFeatures.in
40
41 ResetAll();
42 }
43
44 TestInterfaces::~TestInterfaces() {
45 accessibility_controller_->SetWebView(0);
46 event_sender_->SetWebView(0);
47 // gamepad_controller_ doesn't depend on WebView.
48 text_input_controller_->SetWebView(NULL);
49 test_runner_->SetWebView(0, 0);
50
51 accessibility_controller_->SetDelegate(0);
52 event_sender_->SetDelegate(0);
53 gamepad_controller_->SetDelegate(0);
54 // text_input_controller_ doesn't depend on WebTestDelegate.
55 test_runner_->SetDelegate(0);
56 }
57
58 void TestInterfaces::SetWebView(blink::WebView* web_view,
59 WebTestProxyBase* proxy) {
60 proxy_ = proxy;
61 accessibility_controller_->SetWebView(web_view);
62 event_sender_->SetWebView(web_view);
63 // gamepad_controller_ doesn't depend on WebView.
64 text_input_controller_->SetWebView(web_view);
65 test_runner_->SetWebView(web_view, proxy);
66 }
67
68 void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
69 accessibility_controller_->SetDelegate(delegate);
70 event_sender_->SetDelegate(delegate);
71 gamepad_controller_->SetDelegate(delegate);
72 // text_input_controller_ doesn't depend on WebTestDelegate.
73 test_runner_->SetDelegate(delegate);
74 delegate_ = delegate;
75 }
76
77 void TestInterfaces::BindTo(blink::WebFrame* frame) {
78 accessibility_controller_->Install(frame);
79 event_sender_->Install(frame);
80 gamepad_controller_->Install(frame);
81 text_input_controller_->Install(frame);
82 test_runner_->Install(frame);
83 }
84
85 void TestInterfaces::ResetTestHelperControllers() {
86 accessibility_controller_->Reset();
87 event_sender_->Reset();
88 gamepad_controller_->Reset();
89 // text_input_controller_ doesn't have any state to reset.
90 blink::WebCache::clear();
91 }
92
93 void TestInterfaces::ResetAll() {
94 ResetTestHelperControllers();
95 test_runner_->Reset();
96 }
97
98 void TestInterfaces::SetTestIsRunning(bool running) {
99 test_runner_->SetTestIsRunning(running);
100 }
101
102 void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
103 bool generate_pixels) {
104 std::string spec = GURL(test_url).spec();
105 test_runner_->setShouldGeneratePixelResults(generate_pixels);
106 if (spec.find("loading/") != std::string::npos)
107 test_runner_->setShouldDumpFrameLoadCallbacks(true);
108 if (spec.find("/dumpAsText/") != std::string::npos) {
109 test_runner_->setShouldDumpAsText(true);
110 test_runner_->setShouldGeneratePixelResults(false);
111 }
112 if (spec.find("/inspector/") != std::string::npos ||
113 spec.find("/inspector-enabled/") != std::string::npos)
114 test_runner_->clearDevToolsLocalStorage();
115 if (spec.find("/inspector/") != std::string::npos) {
116 // Subfolder name determines default panel to open.
117 std::string settings = "";
118 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
119 size_t slash_index = test_path.find("/");
120 if (slash_index != std::string::npos) {
121 settings = base::StringPrintf("{\"lastActivePanel\":\"\\\"%s\\\"\"}",
122 test_path.substr(0, slash_index).c_str());
123 }
124 test_runner_->showDevTools(settings, std::string());
125 }
126 if (spec.find("/viewsource/") != std::string::npos) {
127 test_runner_->setShouldEnableViewSource(true);
128 test_runner_->setShouldGeneratePixelResults(false);
129 test_runner_->setShouldDumpAsMarkup(true);
130 }
131 }
132
133 void TestInterfaces::WindowOpened(WebTestProxyBase* proxy) {
134 window_list_.push_back(proxy);
135 }
136
137 void TestInterfaces::WindowClosed(WebTestProxyBase* proxy) {
138 std::vector<WebTestProxyBase*>::iterator pos =
139 std::find(window_list_.begin(), window_list_.end(), proxy);
140 if (pos == window_list_.end()) {
141 NOTREACHED();
142 return;
143 }
144 window_list_.erase(pos);
145 }
146
147 AccessibilityController* TestInterfaces::GetAccessibilityController() {
148 return accessibility_controller_.get();
149 }
150
151 EventSender* TestInterfaces::GetEventSender() {
152 return event_sender_.get();
153 }
154
155 TestRunner* TestInterfaces::GetTestRunner() {
156 return test_runner_.get();
157 }
158
159 WebTestDelegate* TestInterfaces::GetDelegate() {
160 return delegate_;
161 }
162
163 WebTestProxyBase* TestInterfaces::GetProxy() {
164 return proxy_;
165 }
166
167 const std::vector<WebTestProxyBase*>& TestInterfaces::GetWindowList() {
168 return window_list_;
169 }
170
171 blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
172 if (!test_runner_->UseMockTheme())
173 return 0;
174 #if defined(OS_MACOSX)
175 if (!theme_engine_.get())
176 theme_engine_.reset(new MockWebThemeEngineMac());
177 #else
178 if (!theme_engine_.get())
179 theme_engine_.reset(new MockWebThemeEngine());
180 #endif
181 return theme_engine_.get();
182 }
183
184 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/test_interfaces.h ('k') | content/shell/renderer/test_runner/test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698