Replace IdleNotification calls with IdleNotificationDeadline
[chromium-blink-merge.git] / content / shell / renderer / test_runner / test_interfaces.cc
blob6b88763ad931c258581e2bfcbab6950858896708
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.
5 #include "content/shell/renderer/test_runner/test_interfaces.h"
7 #include <string>
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"
24 namespace content {
26 TestInterfaces::TestInterfaces()
27 : accessibility_controller_(new AccessibilityController()),
28 event_sender_(new EventSender(this)),
29 text_input_controller_(new TextInputController()),
30 test_runner_(new TestRunner(this)),
31 delegate_(0) {
32 blink::setLayoutTestMode(true);
33 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
34 switches::kEnableFontAntialiasing))
35 blink::setFontAntialiasingEnabledForTest(true);
37 // NOTE: please don't put feature specific enable flags here,
38 // instead add them to RuntimeEnabledFeatures.in
40 ResetAll();
43 TestInterfaces::~TestInterfaces() {
44 accessibility_controller_->SetWebView(0);
45 event_sender_->SetWebView(0);
46 // gamepad_controller_ doesn't depend on WebView.
47 text_input_controller_->SetWebView(NULL);
48 test_runner_->SetWebView(0, 0);
50 accessibility_controller_->SetDelegate(0);
51 event_sender_->SetDelegate(0);
52 // gamepad_controller_ ignores SetDelegate(0)
53 // text_input_controller_ doesn't depend on WebTestDelegate.
54 test_runner_->SetDelegate(0);
57 void TestInterfaces::SetWebView(blink::WebView* web_view,
58 WebTestProxyBase* proxy) {
59 proxy_ = proxy;
60 accessibility_controller_->SetWebView(web_view);
61 event_sender_->SetWebView(web_view);
62 // gamepad_controller_ doesn't depend on WebView.
63 text_input_controller_->SetWebView(web_view);
64 test_runner_->SetWebView(web_view, proxy);
67 void TestInterfaces::SetDelegate(WebTestDelegate* delegate) {
68 accessibility_controller_->SetDelegate(delegate);
69 event_sender_->SetDelegate(delegate);
70 gamepad_controller_ = GamepadController::Create(delegate);
71 // text_input_controller_ doesn't depend on WebTestDelegate.
72 test_runner_->SetDelegate(delegate);
73 delegate_ = delegate;
76 void TestInterfaces::BindTo(blink::WebFrame* frame) {
77 accessibility_controller_->Install(frame);
78 event_sender_->Install(frame);
79 if (gamepad_controller_)
80 gamepad_controller_->Install(frame);
81 text_input_controller_->Install(frame);
82 test_runner_->Install(frame);
85 void TestInterfaces::ResetTestHelperControllers() {
86 accessibility_controller_->Reset();
87 event_sender_->Reset();
88 if (gamepad_controller_)
89 gamepad_controller_->Reset();
90 // text_input_controller_ doesn't have any state to reset.
91 blink::WebCache::clear();
94 void TestInterfaces::ResetAll() {
95 ResetTestHelperControllers();
96 test_runner_->Reset();
99 void TestInterfaces::SetTestIsRunning(bool running) {
100 test_runner_->SetTestIsRunning(running);
103 void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
104 bool generate_pixels) {
105 std::string spec = GURL(test_url).spec();
106 size_t path_start = spec.rfind("LayoutTests/");
107 if (path_start != std::string::npos)
108 spec = spec.substr(path_start);
109 test_runner_->setShouldGeneratePixelResults(generate_pixels);
110 if (spec.find("loading/") != std::string::npos)
111 test_runner_->setShouldDumpFrameLoadCallbacks(true);
112 if (spec.find("/dumpAsText/") != std::string::npos) {
113 test_runner_->setShouldDumpAsText(true);
114 test_runner_->setShouldGeneratePixelResults(false);
116 if (spec.find("/inspector/") != std::string::npos ||
117 spec.find("/inspector-enabled/") != std::string::npos)
118 test_runner_->ClearDevToolsLocalStorage();
119 if (spec.find("/inspector/") != std::string::npos) {
120 // Subfolder name determines default panel to open.
121 std::string settings = "";
122 std::string test_path = spec.substr(spec.find("/inspector/") + 11);
123 size_t slash_index = test_path.find("/");
124 std::string test_path_setting = base::StringPrintf(
125 "\"testPath\":\"\\\"%s\\\"\"", spec.c_str());
127 // TODO(pfeldman): remove once migrated to testPath.
128 std::string last_active_panel;
129 if (slash_index != std::string::npos) {
130 last_active_panel = base::StringPrintf(
131 ",\"lastActivePanel\":\"\\\"%s\\\"\"",
132 test_path.substr(0, slash_index).c_str());
135 test_runner_->ShowDevTools(base::StringPrintf("{%s%s}",
136 test_path_setting.c_str(), last_active_panel.c_str()), std::string());
138 if (spec.find("/viewsource/") != std::string::npos) {
139 test_runner_->setShouldEnableViewSource(true);
140 test_runner_->setShouldGeneratePixelResults(false);
141 test_runner_->setShouldDumpAsMarkup(true);
145 void TestInterfaces::WindowOpened(WebTestProxyBase* proxy) {
146 window_list_.push_back(proxy);
149 void TestInterfaces::WindowClosed(WebTestProxyBase* proxy) {
150 std::vector<WebTestProxyBase*>::iterator pos =
151 std::find(window_list_.begin(), window_list_.end(), proxy);
152 if (pos == window_list_.end()) {
153 NOTREACHED();
154 return;
156 window_list_.erase(pos);
159 AccessibilityController* TestInterfaces::GetAccessibilityController() {
160 return accessibility_controller_.get();
163 EventSender* TestInterfaces::GetEventSender() {
164 return event_sender_.get();
167 TestRunner* TestInterfaces::GetTestRunner() {
168 return test_runner_.get();
171 WebTestDelegate* TestInterfaces::GetDelegate() {
172 return delegate_;
175 WebTestProxyBase* TestInterfaces::GetProxy() {
176 return proxy_;
179 const std::vector<WebTestProxyBase*>& TestInterfaces::GetWindowList() {
180 return window_list_;
183 blink::WebThemeEngine* TestInterfaces::GetThemeEngine() {
184 if (!test_runner_->UseMockTheme())
185 return 0;
186 if (!theme_engine_.get())
187 theme_engine_.reset(new MockWebThemeEngine());
188 return theme_engine_.get();
191 } // namespace content