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;
31 TestInterfaces::TestInterfaces()
32 : m_accessibilityController(new AccessibilityController())
33 , m_eventSender(new EventSender(this))
34 , m_gamepadController(new GamepadController())
35 , m_textInputController(new TextInputController())
36 , m_testRunner(new TestRunner(this))
39 blink::setLayoutTestMode(true);
40 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableFontAntialiasing))
41 blink::setFontAntialiasingEnabledForTest(true);
43 // NOTE: please don't put feature specific enable flags here,
44 // instead add them to RuntimeEnabledFeatures.in
49 TestInterfaces::~TestInterfaces()
51 m_accessibilityController->SetWebView(0);
52 m_eventSender->SetWebView(0);
53 // m_gamepadController doesn't depend on WebView.
54 m_textInputController->SetWebView(NULL);
55 m_testRunner->SetWebView(0, 0);
57 m_accessibilityController->SetDelegate(0);
58 m_eventSender->SetDelegate(0);
59 m_gamepadController->SetDelegate(0);
60 // m_textInputController doesn't depend on WebTestDelegate.
61 m_testRunner->SetDelegate(0);
64 void TestInterfaces::setWebView(WebView* webView, WebTestProxyBase* proxy)
67 m_accessibilityController->SetWebView(webView);
68 m_eventSender->SetWebView(webView);
69 // m_gamepadController doesn't depend on WebView.
70 m_textInputController->SetWebView(webView);
71 m_testRunner->SetWebView(webView, proxy);
74 void TestInterfaces::setDelegate(WebTestDelegate* delegate)
76 m_accessibilityController->SetDelegate(delegate);
77 m_eventSender->SetDelegate(delegate);
78 m_gamepadController->SetDelegate(delegate);
79 // m_textInputController doesn't depend on WebTestDelegate.
80 m_testRunner->SetDelegate(delegate);
81 m_delegate = delegate;
84 void TestInterfaces::bindTo(WebFrame* frame)
86 m_accessibilityController->Install(frame);
87 m_eventSender->Install(frame);
88 m_gamepadController->Install(frame);
89 m_textInputController->Install(frame);
90 m_testRunner->Install(frame);
93 void TestInterfaces::resetTestHelperControllers()
95 m_accessibilityController->Reset();
96 m_eventSender->Reset();
97 m_gamepadController->Reset();
98 // m_textInputController doesn't have any state to reset.
102 void TestInterfaces::resetAll()
104 resetTestHelperControllers();
105 m_testRunner->Reset();
108 void TestInterfaces::setTestIsRunning(bool running)
110 m_testRunner->SetTestIsRunning(running);
113 void TestInterfaces::configureForTestWithURL(const WebURL& testURL, bool generatePixels)
115 string spec = GURL(testURL).spec();
116 m_testRunner->setShouldGeneratePixelResults(generatePixels);
117 if (spec.find("loading/") != string::npos)
118 m_testRunner->setShouldDumpFrameLoadCallbacks(true);
119 if (spec.find("/dumpAsText/") != string::npos) {
120 m_testRunner->setShouldDumpAsText(true);
121 m_testRunner->setShouldGeneratePixelResults(false);
123 if (spec.find("/inspector/") != string::npos
124 || spec.find("/inspector-enabled/") != string::npos)
125 m_testRunner->clearDevToolsLocalStorage();
126 if (spec.find("/inspector/") != string::npos) {
127 // Subfolder name determines default panel to open.
128 string settings = "";
129 string test_path = spec.substr(spec.find("/inspector/") + 11);
130 size_t slash_index = test_path.find("/");
131 if (slash_index != string::npos) {
132 settings = base::StringPrintf(
133 "{\"lastActivePanel\":\"\\\"%s\\\"\"}",
134 test_path.substr(0, slash_index).c_str());
136 m_testRunner->showDevTools(settings, string());
138 if (spec.find("/viewsource/") != string::npos) {
139 m_testRunner->setShouldEnableViewSource(true);
140 m_testRunner->setShouldGeneratePixelResults(false);
141 m_testRunner->setShouldDumpAsMarkup(true);
145 void TestInterfaces::windowOpened(WebTestProxyBase* proxy)
147 m_windowList.push_back(proxy);
150 void TestInterfaces::windowClosed(WebTestProxyBase* proxy)
152 vector<WebTestProxyBase*>::iterator pos = find(m_windowList.begin(), m_windowList.end(), proxy);
153 if (pos == m_windowList.end()) {
157 m_windowList.erase(pos);
160 AccessibilityController* TestInterfaces::accessibilityController()
162 return m_accessibilityController.get();
165 EventSender* TestInterfaces::eventSender()
167 return m_eventSender.get();
170 TestRunner* TestInterfaces::testRunner()
172 return m_testRunner.get();
175 WebTestDelegate* TestInterfaces::delegate()
180 WebTestProxyBase* TestInterfaces::proxy()
185 const vector<WebTestProxyBase*>& TestInterfaces::windowList()
190 WebThemeEngine* TestInterfaces::themeEngine()
192 if (!m_testRunner->UseMockTheme())
194 #if defined(__APPLE__)
195 if (!m_themeEngine.get())
196 m_themeEngine.reset(new WebTestThemeEngineMac());
198 if (!m_themeEngine.get())
199 m_themeEngine.reset(new WebTestThemeEngineMock());
201 return m_themeEngine.get();
204 } // namespace content