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.
5 #include "content/shell/renderer/test_runner/TestInterfaces.h"
9 #include "base/logging.h"
10 #include "base/command_line.h"
11 #include "base/strings/stringprintf.h"
12 #include "content/shell/common/shell_switches.h"
13 #include "content/shell/renderer/test_runner/WebTestProxy.h"
14 #include "content/shell/renderer/test_runner/accessibility_controller.h"
15 #include "content/shell/renderer/test_runner/event_sender.h"
16 #include "content/shell/renderer/test_runner/gamepad_controller.h"
17 #include "content/shell/renderer/test_runner/text_input_controller.h"
18 #include "content/shell/renderer/test_runner/test_runner.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebURL.h"
21 #include "third_party/WebKit/public/web/WebCache.h"
22 #include "third_party/WebKit/public/web/WebKit.h"
23 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
24 #include "third_party/WebKit/public/web/WebView.h"
26 using namespace blink
;
27 using namespace content
;
30 namespace WebTestRunner
{
32 TestInterfaces::TestInterfaces()
33 : m_accessibilityController(new content::AccessibilityController())
34 , m_eventSender(new content::EventSender(this))
35 , m_gamepadController(new content::GamepadController())
36 , m_textInputController(new content::TextInputController())
37 , m_testRunner(new content::TestRunner(this))
40 blink::setLayoutTestMode(true);
41 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableFontSmoothing
))
42 blink::setFontSmoothingEnabledForTest(true);
44 // NOTE: please don't put feature specific enable flags here,
45 // instead add them to RuntimeEnabledFeatures.in
50 TestInterfaces::~TestInterfaces()
52 m_accessibilityController
->SetWebView(0);
53 m_eventSender
->SetWebView(0);
54 // m_gamepadController doesn't depend on WebView.
55 m_textInputController
->SetWebView(NULL
);
56 m_testRunner
->SetWebView(0, 0);
58 m_accessibilityController
->SetDelegate(0);
59 m_eventSender
->SetDelegate(0);
60 m_gamepadController
->SetDelegate(0);
61 // m_textInputController doesn't depend on WebTestDelegate.
62 m_testRunner
->SetDelegate(0);
65 void TestInterfaces::setWebView(WebView
* webView
, WebTestProxyBase
* proxy
)
68 m_accessibilityController
->SetWebView(webView
);
69 m_eventSender
->SetWebView(webView
);
70 // m_gamepadController doesn't depend on WebView.
71 m_textInputController
->SetWebView(webView
);
72 m_testRunner
->SetWebView(webView
, proxy
);
75 void TestInterfaces::setDelegate(WebTestDelegate
* delegate
)
77 m_accessibilityController
->SetDelegate(delegate
);
78 m_eventSender
->SetDelegate(delegate
);
79 m_gamepadController
->SetDelegate(delegate
);
80 // m_textInputController doesn't depend on WebTestDelegate.
81 m_testRunner
->SetDelegate(delegate
);
82 m_delegate
= delegate
;
85 void TestInterfaces::bindTo(WebFrame
* frame
)
87 m_accessibilityController
->Install(frame
);
88 m_eventSender
->Install(frame
);
89 m_gamepadController
->Install(frame
);
90 m_textInputController
->Install(frame
);
91 m_testRunner
->Install(frame
);
94 void TestInterfaces::resetTestHelperControllers()
96 m_accessibilityController
->Reset();
97 m_eventSender
->Reset();
98 m_gamepadController
->Reset();
99 // m_textInputController doesn't have any state to reset.
103 void TestInterfaces::resetAll()
105 resetTestHelperControllers();
106 m_testRunner
->Reset();
109 void TestInterfaces::setTestIsRunning(bool running
)
111 m_testRunner
->SetTestIsRunning(running
);
114 void TestInterfaces::configureForTestWithURL(const WebURL
& testURL
, bool generatePixels
)
116 string spec
= GURL(testURL
).spec();
117 m_testRunner
->setShouldGeneratePixelResults(generatePixels
);
118 if (spec
.find("loading/") != string::npos
)
119 m_testRunner
->setShouldDumpFrameLoadCallbacks(true);
120 if (spec
.find("/dumpAsText/") != string::npos
) {
121 m_testRunner
->setShouldDumpAsText(true);
122 m_testRunner
->setShouldGeneratePixelResults(false);
124 if (spec
.find("/inspector/") != string::npos
125 || spec
.find("/inspector-enabled/") != string::npos
)
126 m_testRunner
->clearDevToolsLocalStorage();
127 if (spec
.find("/inspector/") != string::npos
) {
128 // Subfolder name determines default panel to open.
129 string settings
= "";
130 string test_path
= spec
.substr(spec
.find("/inspector/") + 11);
131 size_t slash_index
= test_path
.find("/");
132 if (slash_index
!= string::npos
) {
133 settings
= base::StringPrintf(
134 "{\"lastActivePanel\":\"\\\"%s\\\"\"}",
135 test_path
.substr(0, slash_index
).c_str());
137 m_testRunner
->showDevTools(settings
, string());
139 if (spec
.find("/viewsource/") != string::npos
) {
140 m_testRunner
->setShouldEnableViewSource(true);
141 m_testRunner
->setShouldGeneratePixelResults(false);
142 m_testRunner
->setShouldDumpAsMarkup(true);
146 void TestInterfaces::windowOpened(WebTestProxyBase
* proxy
)
148 m_windowList
.push_back(proxy
);
151 void TestInterfaces::windowClosed(WebTestProxyBase
* proxy
)
153 vector
<WebTestProxyBase
*>::iterator pos
= find(m_windowList
.begin(), m_windowList
.end(), proxy
);
154 if (pos
== m_windowList
.end()) {
158 m_windowList
.erase(pos
);
161 content::AccessibilityController
* TestInterfaces::accessibilityController()
163 return m_accessibilityController
.get();
166 content::EventSender
* TestInterfaces::eventSender()
168 return m_eventSender
.get();
171 content::TestRunner
* TestInterfaces::testRunner()
173 return m_testRunner
.get();
176 WebTestDelegate
* TestInterfaces::delegate()
181 WebTestProxyBase
* TestInterfaces::proxy()
186 const vector
<WebTestProxyBase
*>& TestInterfaces::windowList()
191 WebThemeEngine
* TestInterfaces::themeEngine()
193 if (!m_testRunner
->UseMockTheme())
195 #if defined(__APPLE__)
196 if (!m_themeEngine
.get())
197 m_themeEngine
.reset(new WebTestThemeEngineMac());
199 if (!m_themeEngine
.get())
200 m_themeEngine
.reset(new WebTestThemeEngineMock());
202 return m_themeEngine
.get();