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

Side by Side Diff: content/test/layout_tests/runner/TestInterfaces.cpp

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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 | Annotate | Revision Log
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 /*
6 * Copyright (C) 2012 Google Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Google Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "content/test/layout_tests/runner/TestInterfaces.h"
36
37 #include <string>
38
39 #include "content/public/test/layout_tests/WebTestProxy.h"
40 #include "content/test/layout_tests/runner/AccessibilityController.h"
41 #include "content/test/layout_tests/runner/EventSender.h"
42 #include "content/test/layout_tests/runner/GamepadController.h"
43 #include "content/test/layout_tests/runner/TestRunner.h"
44 #include "content/test/layout_tests/runner/TextInputController.h"
45 #include "third_party/WebKit/public/platform/WebString.h"
46 #include "third_party/WebKit/public/platform/WebURL.h"
47 #include "third_party/WebKit/public/web/WebCache.h"
48 #include "third_party/WebKit/public/web/WebKit.h"
49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
50 #include "third_party/WebKit/public/web/WebView.h"
51
52 using namespace blink;
53 using namespace std;
54
55 namespace WebTestRunner {
56
57 TestInterfaces::TestInterfaces()
58 : m_accessibilityController(new AccessibilityController())
59 , m_eventSender(new EventSender(this))
60 , m_gamepadController(new GamepadController())
61 , m_textInputController(new TextInputController())
62 , m_testRunner(new TestRunner(this))
63 , m_delegate(0)
64 {
65 blink::setLayoutTestMode(true);
66
67 // NOTE: please don't put feature specific enable flags here,
68 // instead add them to RuntimeEnabledFeatures.in
69
70 resetAll();
71 }
72
73 TestInterfaces::~TestInterfaces()
74 {
75 m_accessibilityController->setWebView(0);
76 m_eventSender->setWebView(0);
77 // m_gamepadController doesn't depend on WebView.
78 m_textInputController->setWebView(0);
79 m_testRunner->setWebView(0, 0);
80
81 m_accessibilityController->setDelegate(0);
82 m_eventSender->setDelegate(0);
83 m_gamepadController->setDelegate(0);
84 // m_textInputController doesn't depend on WebTestDelegate.
85 m_testRunner->setDelegate(0);
86 }
87
88 void TestInterfaces::setWebView(WebView* webView, WebTestProxyBase* proxy)
89 {
90 m_proxy = proxy;
91 m_accessibilityController->setWebView(webView);
92 m_eventSender->setWebView(webView);
93 // m_gamepadController doesn't depend on WebView.
94 m_textInputController->setWebView(webView);
95 m_testRunner->setWebView(webView, proxy);
96 }
97
98 void TestInterfaces::setDelegate(WebTestDelegate* delegate)
99 {
100 m_accessibilityController->setDelegate(delegate);
101 m_eventSender->setDelegate(delegate);
102 m_gamepadController->setDelegate(delegate);
103 // m_textInputController doesn't depend on WebTestDelegate.
104 m_testRunner->setDelegate(delegate);
105 m_delegate = delegate;
106 }
107
108 void TestInterfaces::bindTo(WebFrame* frame)
109 {
110 m_accessibilityController->bindToJavascript(frame, WebString::fromUTF8("acce ssibilityController"));
111 m_eventSender->bindToJavascript(frame, WebString::fromUTF8("eventSender"));
112 m_gamepadController->bindToJavascript(frame, WebString::fromUTF8("gamepadCon troller"));
113 m_textInputController->bindToJavascript(frame, WebString::fromUTF8("textInpu tController"));
114 m_testRunner->bindToJavascript(frame, WebString::fromUTF8("testRunner"));
115 m_testRunner->bindToJavascript(frame, WebString::fromUTF8("layoutTestControl ler"));
116 }
117
118 void TestInterfaces::resetTestHelperControllers()
119 {
120 m_accessibilityController->reset();
121 m_eventSender->reset();
122 m_gamepadController->reset();
123 // m_textInputController doesn't have any state to reset.
124 WebCache::clear();
125 }
126
127 void TestInterfaces::resetAll()
128 {
129 resetTestHelperControllers();
130 m_testRunner->reset();
131 }
132
133 void TestInterfaces::setTestIsRunning(bool running)
134 {
135 m_testRunner->setTestIsRunning(running);
136 }
137
138 void TestInterfaces::configureForTestWithURL(const WebURL& testURL, bool generat ePixels)
139 {
140 string spec = GURL(testURL).spec();
141 m_testRunner->setShouldGeneratePixelResults(generatePixels);
142 if (spec.find("loading/") != string::npos)
143 m_testRunner->setShouldDumpFrameLoadCallbacks(true);
144 if (spec.find("/dumpAsText/") != string::npos) {
145 m_testRunner->setShouldDumpAsText(true);
146 m_testRunner->setShouldGeneratePixelResults(false);
147 }
148 if (spec.find("/inspector/") != string::npos)
149 m_testRunner->showDevTools();
150 if (spec.find("/viewsource/") != string::npos) {
151 m_testRunner->setShouldEnableViewSource(true);
152 m_testRunner->setShouldGeneratePixelResults(false);
153 m_testRunner->setShouldDumpAsMarkup(true);
154 }
155 }
156
157 void TestInterfaces::windowOpened(WebTestProxyBase* proxy)
158 {
159 m_windowList.push_back(proxy);
160 }
161
162 void TestInterfaces::windowClosed(WebTestProxyBase* proxy)
163 {
164 vector<WebTestProxyBase*>::iterator pos = find(m_windowList.begin(), m_windo wList.end(), proxy);
165 if (pos == m_windowList.end()) {
166 BLINK_ASSERT_NOT_REACHED();
167 return;
168 }
169 m_windowList.erase(pos);
170 }
171
172 AccessibilityController* TestInterfaces::accessibilityController()
173 {
174 return m_accessibilityController.get();
175 }
176
177 EventSender* TestInterfaces::eventSender()
178 {
179 return m_eventSender.get();
180 }
181
182 TestRunner* TestInterfaces::testRunner()
183 {
184 return m_testRunner.get();
185 }
186
187 WebTestDelegate* TestInterfaces::delegate()
188 {
189 return m_delegate;
190 }
191
192 WebTestProxyBase* TestInterfaces::proxy()
193 {
194 return m_proxy;
195 }
196
197 const vector<WebTestProxyBase*>& TestInterfaces::windowList()
198 {
199 return m_windowList;
200 }
201
202 WebThemeEngine* TestInterfaces::themeEngine()
203 {
204 #if defined(USE_DEFAULT_RENDER_THEME) || !(defined(WIN32) || defined(__APPLE__) || defined(ANDROID))
205 if (!m_themeEngine.get())
206 m_themeEngine.reset(new WebTestThemeEngineMock());
207 return m_themeEngine.get();
208 #elif defined(WIN32)
209 if (!m_themeEngine.get())
210 m_themeEngine.reset(new WebTestThemeEngineWin());
211 return m_themeEngine.get();
212 #elif defined(__APPLE__)
213 if (!m_themeEngine.get())
214 m_themeEngine.reset(new WebTestThemeEngineMac());
215 return m_themeEngine.get();
216 #else
217 return 0;
218 #endif
219 }
220
221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698