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

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

Issue 1167703002: Move test runner to a component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 6 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 2014 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/json/json_writer.h"
10 #include "base/json/string_escape.h"
11 #include "base/logging.h"
12 #include "base/strings/stringprintf.h"
13 #include "base/values.h"
14 #include "content/shell/renderer/test_runner/accessibility_controller.h"
15 #include "content/shell/renderer/test_runner/app_banner_client.h"
16 #include "content/shell/renderer/test_runner/event_sender.h"
17 #include "content/shell/renderer/test_runner/gamepad_controller.h"
18 #include "content/shell/renderer/test_runner/test_runner.h"
19 #include "content/shell/renderer/test_runner/text_input_controller.h"
20 #include "content/shell/renderer/test_runner/web_test_proxy.h"
21 #include "third_party/WebKit/public/platform/WebURL.h"
22 #include "third_party/WebKit/public/web/WebCache.h"
23 #include "third_party/WebKit/public/web/WebKit.h"
24 #include "third_party/WebKit/public/web/WebView.h"
25
26 namespace content {
27
28 TestInterfaces::TestInterfaces()
29 : accessibility_controller_(new AccessibilityController()),
30 event_sender_(new EventSender(this)),
31 text_input_controller_(new TextInputController()),
32 test_runner_(new TestRunner(this)),
33 delegate_(nullptr),
34 app_banner_client_(nullptr) {
35 blink::setLayoutTestMode(true);
36 // NOTE: please don't put feature specific enable flags here,
37 // instead add them to RuntimeEnabledFeatures.in
38
39 ResetAll();
40 }
41
42 TestInterfaces::~TestInterfaces() {
43 accessibility_controller_->SetWebView(0);
44 event_sender_->SetWebView(0);
45 // gamepad_controller_ doesn't depend on WebView.
46 text_input_controller_->SetWebView(NULL);
47 test_runner_->SetWebView(0, 0);
48
49 accessibility_controller_->SetDelegate(0);
50 event_sender_->SetDelegate(0);
51 // gamepad_controller_ ignores SetDelegate(0)
52 // text_input_controller_ doesn't depend on WebTestDelegate.
53 test_runner_->SetDelegate(0);
54 }
55
56 void TestInterfaces::SetWebView(blink::WebView* web_view,
57 WebTestProxyBase* proxy) {
58 proxy_ = proxy;
59 accessibility_controller_->SetWebView(web_view);
60 event_sender_->SetWebView(web_view);
61 // gamepad_controller_ doesn't depend on WebView.
62 text_input_controller_->SetWebView(web_view);
63 test_runner_->SetWebView(web_view, proxy);
64 }
65
66 void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
67 accessibility_controller_->SetDelegate(delegate);
68 event_sender_->SetDelegate(delegate);
69 gamepad_controller_ = GamepadController::Create(delegate);
70 // text_input_controller_ doesn't depend on WebTestDelegate.
71 test_runner_->SetDelegate(delegate);
72 delegate_ = delegate;
73 }
74
75 void TestInterfaces::BindTo(blink::WebFrame* frame) {
76 accessibility_controller_->Install(frame);
77 event_sender_->Install(frame);
78 if (gamepad_controller_)
79 gamepad_controller_->Install(frame);
80 text_input_controller_->Install(frame);
81 test_runner_->Install(frame);
82 }
83
84 void TestInterfaces::ResetTestHelperControllers() {
85 accessibility_controller_->Reset();
86 event_sender_->Reset();
87 if (gamepad_controller_)
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 size_t path_start = spec.rfind("LayoutTests/");
106 if (path_start != std::string::npos)
107 spec = spec.substr(path_start);
108 test_runner_->setShouldGeneratePixelResults(generate_pixels);
109 if (spec.find("loading/") != std::string::npos)
110 test_runner_->setShouldDumpFrameLoadCallbacks(true);
111 if (spec.find("/dumpAsText/") != std::string::npos) {
112 test_runner_->setShouldDumpAsText(true);
113 test_runner_->setShouldGeneratePixelResults(false);
114 }
115 if (spec.find("/inspector/") != std::string::npos ||
116 spec.find("/inspector-enabled/") != std::string::npos)
117 test_runner_->ClearDevToolsLocalStorage();
118 if (spec.find("/inspector/") != std::string::npos) {
119 // Subfolder name determines default panel to open.
120 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
121 base::DictionaryValue settings;
122 settings.SetString("testPath", base::GetQuotedJSONString(spec));
123 std::string settings_string;
124 base::JSONWriter::Write(settings, &settings_string);
125 test_runner_->ShowDevTools(settings_string, std::string());
126 }
127 if (spec.find("/viewsource/") != std::string::npos) {
128 test_runner_->setShouldEnableViewSource(true);
129 test_runner_->setShouldGeneratePixelResults(false);
130 test_runner_->setShouldDumpAsMarkup(true);
131 }
132 }
133
134 void TestInterfaces::SetAppBannerClient(AppBannerClient* app_banner_client) {
135 app_banner_client_ = app_banner_client;
136 }
137
138 void TestInterfaces::WindowOpened(WebTestProxyBase* proxy) {
139 window_list_.push_back(proxy);
140 }
141
142 void TestInterfaces::WindowClosed(WebTestProxyBase* proxy) {
143 std::vector<WebTestProxyBase*>::iterator pos =
144 std::find(window_list_.begin(), window_list_.end(), proxy);
145 if (pos == window_list_.end()) {
146 NOTREACHED();
147 return;
148 }
149 window_list_.erase(pos);
150 }
151
152 AccessibilityController* TestInterfaces::GetAccessibilityController() {
153 return accessibility_controller_.get();
154 }
155
156 EventSender* TestInterfaces::GetEventSender() {
157 return event_sender_.get();
158 }
159
160 TestRunner* TestInterfaces::GetTestRunner() {
161 return test_runner_.get();
162 }
163
164 WebTestDelegate* TestInterfaces::GetDelegate() {
165 return delegate_;
166 }
167
168 WebTestProxyBase* TestInterfaces::GetProxy() {
169 return proxy_;
170 }
171
172 const std::vector<WebTestProxyBase*>& TestInterfaces::GetWindowList() {
173 return window_list_;
174 }
175
176 blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
177 if (!test_runner_->UseMockTheme())
178 return 0;
179 if (!theme_engine_.get())
180 theme_engine_.reset(new MockWebThemeEngine());
181 return theme_engine_.get();
182 }
183
184 AppBannerClient* TestInterfaces::GetAppBannerClient() {
185 return app_banner_client_;
186 }
187
188 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/test_interfaces.h ('k') | content/shell/renderer/test_runner/test_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698