OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/WebTestProxy.h" | 5 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "content/shell/renderer/test_runner/event_sender.h" | |
13 #include "content/shell/renderer/test_runner/MockColorChooser.h" | 12 #include "content/shell/renderer/test_runner/MockColorChooser.h" |
14 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" | 13 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" |
15 #include "content/shell/renderer/test_runner/SpellCheckClient.h" | 14 #include "content/shell/renderer/test_runner/SpellCheckClient.h" |
16 #include "content/shell/renderer/test_runner/TestCommon.h" | 15 #include "content/shell/renderer/test_runner/TestCommon.h" |
17 #include "content/shell/renderer/test_runner/TestInterfaces.h" | 16 #include "content/shell/renderer/test_runner/TestInterfaces.h" |
18 #include "content/shell/renderer/test_runner/TestPlugin.h" | 17 #include "content/shell/renderer/test_runner/TestPlugin.h" |
19 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 18 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
20 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" | 19 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" |
21 #include "content/shell/renderer/test_runner/WebTestRunner.h" | 20 #include "content/shell/renderer/test_runner/WebTestRunner.h" |
22 #include "content/shell/renderer/test_runner/WebUserMediaClientMock.h" | 21 #include "content/shell/renderer/test_runner/WebUserMediaClientMock.h" |
23 #include "content/shell/renderer/test_runner/accessibility_controller.h" | 22 #include "content/shell/renderer/test_runner/accessibility_controller.h" |
| 23 #include "content/shell/renderer/test_runner/event_sender.h" |
24 #include "content/shell/renderer/test_runner/test_runner.h" | 24 #include "content/shell/renderer/test_runner/test_runner.h" |
25 // FIXME: Including platform_canvas.h here is a layering violation. | 25 // FIXME: Including platform_canvas.h here is a layering violation. |
26 #include "skia/ext/platform_canvas.h" | 26 #include "skia/ext/platform_canvas.h" |
27 #include "third_party/WebKit/public/platform/WebCString.h" | 27 #include "third_party/WebKit/public/platform/WebCString.h" |
28 #include "third_party/WebKit/public/platform/WebURLError.h" | 28 #include "third_party/WebKit/public/platform/WebURLError.h" |
29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
30 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 30 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
31 #include "third_party/WebKit/public/web/WebAXEnums.h" | 31 #include "third_party/WebKit/public/web/WebAXEnums.h" |
32 #include "third_party/WebKit/public/web/WebAXObject.h" | 32 #include "third_party/WebKit/public/web/WebAXObject.h" |
33 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" | 33 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" |
(...skipping 12 matching lines...) Expand all Loading... |
46 #include "third_party/WebKit/public/web/WebView.h" | 46 #include "third_party/WebKit/public/web/WebView.h" |
47 | 47 |
48 using namespace blink; | 48 using namespace blink; |
49 using namespace std; | 49 using namespace std; |
50 | 50 |
51 namespace content { | 51 namespace content { |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { | 55 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { |
56 public: | 56 public: |
57 typedef void (WebTestProxyBase::*CallbackMethodType)(); | 57 typedef void (WebTestProxyBase::*CallbackMethodType)(); |
58 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) | 58 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) |
59 : WebMethodTask<WebTestProxyBase>(object) | 59 : WebMethodTask<WebTestProxyBase>(object), m_callback(callback) {} |
60 , m_callback(callback) | |
61 { } | |
62 | 60 |
63 virtual void runIfValid() OVERRIDE { (m_object->*m_callback)(); } | 61 virtual void runIfValid() OVERRIDE { (m_object->*m_callback)(); } |
64 | 62 |
65 private: | 63 private: |
66 CallbackMethodType m_callback; | 64 CallbackMethodType m_callback; |
67 }; | 65 }; |
68 | 66 |
69 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) | 67 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) { |
70 { | 68 string name8 = frame->uniqueName().utf8(); |
71 string name8 = frame->uniqueName().utf8(); | 69 if (frame == frame->view()->mainFrame()) { |
72 if (frame == frame->view()->mainFrame()) { | 70 if (!name8.length()) { |
73 if (!name8.length()) { | 71 delegate->printMessage("main frame"); |
74 delegate->printMessage("main frame"); | 72 return; |
75 return; | |
76 } | |
77 delegate->printMessage(string("main frame \"") + name8 + "\""); | |
78 return; | |
79 } | 73 } |
80 if (!name8.length()) { | 74 delegate->printMessage(string("main frame \"") + name8 + "\""); |
81 delegate->printMessage("frame (anonymous)"); | 75 return; |
82 return; | 76 } |
83 } | 77 if (!name8.length()) { |
84 delegate->printMessage(string("frame \"") + name8 + "\""); | 78 delegate->printMessage("frame (anonymous)"); |
| 79 return; |
| 80 } |
| 81 delegate->printMessage(string("frame \"") + name8 + "\""); |
85 } | 82 } |
86 | 83 |
87 void printFrameUserGestureStatus(WebTestDelegate* delegate, WebFrame* frame, con
st char* msg) | 84 void printFrameUserGestureStatus(WebTestDelegate* delegate, WebFrame* frame, |
88 { | 85 const char* msg) { |
89 bool isUserGesture = WebUserGestureIndicator::isProcessingUserGesture(); | 86 bool isUserGesture = WebUserGestureIndicator::isProcessingUserGesture(); |
90 delegate->printMessage(string("Frame with user gesture \"") + (isUserGesture
? "true" : "false") + "\"" + msg); | 87 delegate->printMessage(string("Frame with user gesture \"") + |
| 88 (isUserGesture ? "true" : "false") + "\"" + msg); |
91 } | 89 } |
92 | 90 |
93 // Used to write a platform neutral file:/// URL by taking the | 91 // Used to write a platform neutral file:/// URL by taking the |
94 // filename and its directory. (e.g., converts | 92 // filename and its directory. (e.g., converts |
95 // "file:///tmp/foo/bar.txt" to just "bar.txt"). | 93 // "file:///tmp/foo/bar.txt" to just "bar.txt"). |
96 string descriptionSuitableForTestResult(const string& url) | 94 string descriptionSuitableForTestResult(const string& url) { |
97 { | 95 if (url.empty() || string::npos == url.find("file://")) return url; |
98 if (url.empty() || string::npos == url.find("file://")) | |
99 return url; | |
100 | 96 |
101 size_t pos = url.rfind('/'); | 97 size_t pos = url.rfind('/'); |
102 if (pos == string::npos || !pos) | 98 if (pos == string::npos || !pos) return "ERROR:" + url; |
103 return "ERROR:" + url; | 99 pos = url.rfind('/', pos - 1); |
104 pos = url.rfind('/', pos - 1); | 100 if (pos == string::npos) return "ERROR:" + url; |
105 if (pos == string::npos) | |
106 return "ERROR:" + url; | |
107 | 101 |
108 return url.substr(pos + 1); | 102 return url.substr(pos + 1); |
109 } | 103 } |
110 | 104 |
111 void printResponseDescription(WebTestDelegate* delegate, const WebURLResponse& r
esponse) | 105 void printResponseDescription(WebTestDelegate* delegate, |
112 { | 106 const WebURLResponse& response) { |
113 if (response.isNull()) { | 107 if (response.isNull()) { |
114 delegate->printMessage("(null)"); | 108 delegate->printMessage("(null)"); |
115 return; | 109 return; |
116 } | 110 } |
117 string url = response.url().spec(); | 111 string url = response.url().spec(); |
118 char data[100]; | 112 char data[100]; |
119 snprintf(data, sizeof(data), "%d", response. httpStatusCode()); | 113 snprintf(data, sizeof(data), "%d", response.httpStatusCode()); |
120 delegate->printMessage(string("<NSURLResponse ") + descriptionSuitableForTes
tResult(url) + ", http status code " + data + ">"); | 114 delegate->printMessage(string("<NSURLResponse ") + |
| 115 descriptionSuitableForTestResult(url) + |
| 116 ", http status code " + data + ">"); |
121 } | 117 } |
122 | 118 |
123 string URLDescription(const GURL& url) | 119 string URLDescription(const GURL& url) { |
124 { | 120 if (url.SchemeIs("file")) return url.ExtractFileName(); |
125 if (url.SchemeIs("file")) | 121 return url.possibly_invalid_spec(); |
126 return url.ExtractFileName(); | |
127 return url.possibly_invalid_spec(); | |
128 } | 122 } |
129 | 123 |
130 string PriorityDescription(const WebURLRequest::Priority& priority) | 124 string PriorityDescription(const WebURLRequest::Priority& priority) { |
131 { | 125 switch (priority) { |
132 switch (priority) { | |
133 case WebURLRequest::PriorityVeryLow: | 126 case WebURLRequest::PriorityVeryLow: |
134 return "VeryLow"; | 127 return "VeryLow"; |
135 case WebURLRequest::PriorityLow: | 128 case WebURLRequest::PriorityLow: |
136 return "Low"; | 129 return "Low"; |
137 case WebURLRequest::PriorityMedium: | 130 case WebURLRequest::PriorityMedium: |
138 return "Medium"; | 131 return "Medium"; |
139 case WebURLRequest::PriorityHigh: | 132 case WebURLRequest::PriorityHigh: |
140 return "High"; | 133 return "High"; |
141 case WebURLRequest::PriorityVeryHigh: | 134 case WebURLRequest::PriorityVeryHigh: |
142 return "VeryHigh"; | 135 return "VeryHigh"; |
143 case WebURLRequest::PriorityUnresolved: | 136 case WebURLRequest::PriorityUnresolved: |
144 default: | 137 default: |
145 return "Unresolved"; | 138 return "Unresolved"; |
146 } | 139 } |
147 } | 140 } |
148 | 141 |
149 void blockRequest(WebURLRequest& request) | 142 void blockRequest(WebURLRequest& request) { |
150 { | 143 request.setURL(GURL("255.255.255.255")); |
151 request.setURL(GURL("255.255.255.255")); | |
152 } | 144 } |
153 | 145 |
154 bool isLocalhost(const string& host) | 146 bool isLocalhost(const string& host) { |
155 { | 147 return host == "127.0.0.1" || host == "localhost"; |
156 return host == "127.0.0.1" || host == "localhost"; | |
157 } | 148 } |
158 | 149 |
159 bool hostIsUsedBySomeTestsToGenerateError(const string& host) | 150 bool hostIsUsedBySomeTestsToGenerateError(const string& host) { |
160 { | 151 return host == "255.255.255.255"; |
161 return host == "255.255.255.255"; | |
162 } | 152 } |
163 | 153 |
164 // Used to write a platform neutral file:/// URL by only taking the filename | 154 // Used to write a platform neutral file:/// URL by only taking the filename |
165 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). | 155 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). |
166 string urlSuitableForTestResult(const string& url) | 156 string urlSuitableForTestResult(const string& url) { |
167 { | 157 if (url.empty() || string::npos == url.find("file://")) return url; |
168 if (url.empty() || string::npos == url.find("file://")) | |
169 return url; | |
170 | 158 |
171 size_t pos = url.rfind('/'); | 159 size_t pos = url.rfind('/'); |
172 if (pos == string::npos) { | 160 if (pos == string::npos) { |
173 #ifdef WIN32 | 161 #ifdef WIN32 |
174 pos = url.rfind('\\'); | 162 pos = url.rfind('\\'); |
175 if (pos == string::npos) | 163 if (pos == string::npos) pos = 0; |
176 pos = 0; | |
177 #else | 164 #else |
178 pos = 0; | 165 pos = 0; |
179 #endif | 166 #endif |
180 } | 167 } |
181 string filename = url.substr(pos + 1); | 168 string filename = url.substr(pos + 1); |
182 if (filename.empty()) | 169 if (filename.empty()) |
183 return "file:"; // A WebKit test has this in its expected output. | 170 return "file:"; // A WebKit test has this in its expected output. |
184 return filename; | 171 return filename; |
185 } | 172 } |
186 | 173 |
187 // WebNavigationType debugging strings taken from PolicyDelegate.mm. | 174 // WebNavigationType debugging strings taken from PolicyDelegate.mm. |
188 const char* linkClickedString = "link clicked"; | 175 const char* linkClickedString = "link clicked"; |
189 const char* formSubmittedString = "form submitted"; | 176 const char* formSubmittedString = "form submitted"; |
190 const char* backForwardString = "back/forward"; | 177 const char* backForwardString = "back/forward"; |
191 const char* reloadString = "reload"; | 178 const char* reloadString = "reload"; |
192 const char* formResubmittedString = "form resubmitted"; | 179 const char* formResubmittedString = "form resubmitted"; |
193 const char* otherString = "other"; | 180 const char* otherString = "other"; |
194 const char* illegalString = "illegal value"; | 181 const char* illegalString = "illegal value"; |
195 | 182 |
196 // Get a debugging string from a WebNavigationType. | 183 // Get a debugging string from a WebNavigationType. |
197 const char* webNavigationTypeToString(WebNavigationType type) | 184 const char* webNavigationTypeToString(WebNavigationType type) { |
198 { | 185 switch (type) { |
199 switch (type) { | |
200 case blink::WebNavigationTypeLinkClicked: | 186 case blink::WebNavigationTypeLinkClicked: |
201 return linkClickedString; | 187 return linkClickedString; |
202 case blink::WebNavigationTypeFormSubmitted: | 188 case blink::WebNavigationTypeFormSubmitted: |
203 return formSubmittedString; | 189 return formSubmittedString; |
204 case blink::WebNavigationTypeBackForward: | 190 case blink::WebNavigationTypeBackForward: |
205 return backForwardString; | 191 return backForwardString; |
206 case blink::WebNavigationTypeReload: | 192 case blink::WebNavigationTypeReload: |
207 return reloadString; | 193 return reloadString; |
208 case blink::WebNavigationTypeFormResubmitted: | 194 case blink::WebNavigationTypeFormResubmitted: |
209 return formResubmittedString; | 195 return formResubmittedString; |
210 case blink::WebNavigationTypeOther: | 196 case blink::WebNavigationTypeOther: |
211 return otherString; | 197 return otherString; |
212 } | 198 } |
213 return illegalString; | 199 return illegalString; |
214 } | 200 } |
215 | 201 |
216 string dumpDocumentText(WebFrame* frame) | 202 string dumpDocumentText(WebFrame* frame) { |
217 { | 203 // We use the document element's text instead of the body text here because |
218 // We use the document element's text instead of the body text here because | 204 // not all documents have a body, such as XML documents. |
219 // not all documents have a body, such as XML documents. | 205 WebElement documentElement = frame->document().documentElement(); |
220 WebElement documentElement = frame->document().documentElement(); | 206 if (documentElement.isNull()) return string(); |
221 if (documentElement.isNull()) | 207 return documentElement.innerText().utf8(); |
222 return string(); | 208 } |
223 return documentElement.innerText().utf8(); | 209 |
224 } | 210 string dumpFramesAsText(WebFrame* frame, bool recursive) { |
225 | 211 string result; |
226 string dumpFramesAsText(WebFrame* frame, bool recursive) | 212 |
227 { | 213 // Add header for all but the main frame. Skip empty frames. |
228 string result; | 214 if (frame->parent() && !frame->document().documentElement().isNull()) { |
229 | 215 result.append("\n--------\nFrame: '"); |
230 // Add header for all but the main frame. Skip empty frames. | 216 result.append(frame->uniqueName().utf8().data()); |
231 if (frame->parent() && !frame->document().documentElement().isNull()) { | 217 result.append("'\n--------\n"); |
232 result.append("\n--------\nFrame: '"); | 218 } |
233 result.append(frame->uniqueName().utf8().data()); | 219 |
234 result.append("'\n--------\n"); | 220 result.append(dumpDocumentText(frame)); |
235 } | 221 result.append("\n"); |
236 | 222 |
237 result.append(dumpDocumentText(frame)); | 223 if (recursive) { |
238 result.append("\n"); | 224 for (WebFrame* child = frame->firstChild(); child; |
239 | 225 child = child->nextSibling()) |
240 if (recursive) { | 226 result.append(dumpFramesAsText(child, recursive)); |
241 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) | 227 } |
242 result.append(dumpFramesAsText(child, recursive)); | 228 |
243 } | 229 return result; |
244 | 230 } |
245 return result; | 231 |
246 } | 232 string dumpFramesAsPrintedText(WebFrame* frame, bool recursive) { |
247 | 233 string result; |
248 string dumpFramesAsPrintedText(WebFrame* frame, bool recursive) | 234 |
249 { | 235 // Cannot do printed format for anything other than HTML |
250 string result; | 236 if (!frame->document().isHTMLDocument()) return string(); |
251 | 237 |
252 // Cannot do printed format for anything other than HTML | 238 // Add header for all but the main frame. Skip empty frames. |
253 if (!frame->document().isHTMLDocument()) | 239 if (frame->parent() && !frame->document().documentElement().isNull()) { |
254 return string(); | 240 result.append("\n--------\nFrame: '"); |
255 | 241 result.append(frame->uniqueName().utf8().data()); |
256 // Add header for all but the main frame. Skip empty frames. | 242 result.append("'\n--------\n"); |
257 if (frame->parent() && !frame->document().documentElement().isNull()) { | 243 } |
258 result.append("\n--------\nFrame: '"); | 244 |
259 result.append(frame->uniqueName().utf8().data()); | 245 result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8()); |
260 result.append("'\n--------\n"); | 246 result.append("\n"); |
261 } | 247 |
262 | 248 if (recursive) { |
263 result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8()
); | 249 for (WebFrame* child = frame->firstChild(); child; |
264 result.append("\n"); | 250 child = child->nextSibling()) |
265 | 251 result.append(dumpFramesAsPrintedText(child, recursive)); |
266 if (recursive) { | 252 } |
267 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) | 253 |
268 result.append(dumpFramesAsPrintedText(child, recursive)); | 254 return result; |
269 } | 255 } |
270 | 256 |
271 return result; | 257 string dumpFrameScrollPosition(WebFrame* frame, bool recursive) { |
272 } | 258 string result; |
273 | 259 WebSize offset = frame->scrollOffset(); |
274 string dumpFrameScrollPosition(WebFrame* frame, bool recursive) | 260 if (offset.width > 0 || offset.height > 0) { |
275 { | 261 if (frame->parent()) |
276 string result; | 262 result = string("frame '") + frame->uniqueName().utf8().data() + "' "; |
277 WebSize offset = frame->scrollOffset(); | 263 char data[100]; |
278 if (offset.width > 0 || offset.height > 0) { | 264 snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, |
279 if (frame->parent()) | 265 offset.height); |
280 result = string("frame '") + frame->uniqueName().utf8().data() + "'
"; | 266 result += data; |
281 char data[100]; | 267 } |
282 snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset
.height); | 268 |
283 result += data; | 269 if (!recursive) return result; |
284 } | 270 for (WebFrame* child = frame->firstChild(); child; |
285 | 271 child = child->nextSibling()) |
286 if (!recursive) | 272 result += dumpFrameScrollPosition(child, recursive); |
287 return result; | 273 return result; |
288 for (WebFrame* child = frame->firstChild(); child; child = child->nextSiblin
g()) | 274 } |
289 result += dumpFrameScrollPosition(child, recursive); | 275 |
290 return result; | 276 string dumpAllBackForwardLists(TestInterfaces* interfaces, |
291 } | 277 WebTestDelegate* delegate) { |
292 | 278 string result; |
293 string dumpAllBackForwardLists(TestInterfaces* interfaces, WebTestDelegate* dele
gate) | 279 const vector<WebTestProxyBase*>& windowList = interfaces->windowList(); |
294 { | 280 for (unsigned i = 0; i < windowList.size(); ++i) |
295 string result; | 281 result.append(delegate->dumpHistoryForWindow(windowList.at(i))); |
296 const vector<WebTestProxyBase*>& windowList = interfaces->windowList(); | 282 return result; |
297 for (unsigned i = 0; i < windowList.size(); ++i) | 283 } |
298 result.append(delegate->dumpHistoryForWindow(windowList.at(i))); | |
299 return result; | |
300 } | |
301 | |
302 } | 284 } |
303 | 285 |
304 WebTestProxyBase::WebTestProxyBase() | 286 WebTestProxyBase::WebTestProxyBase() |
305 : m_testInterfaces(0) | 287 : test_interfaces_(NULL), |
306 , m_delegate(0) | 288 delegate_(NULL), |
307 , m_webWidget(0) | 289 web_widget_(NULL), |
308 , m_spellcheck(new SpellCheckClient(this)) | 290 spellcheck_(new SpellCheckClient(this)), |
309 , m_chooserCount(0) | 291 chooser_count_(0) { |
310 { | 292 Reset(); |
311 reset(); | 293 } |
312 } | 294 |
313 | 295 WebTestProxyBase::~WebTestProxyBase() { test_interfaces_->windowClosed(this); } |
314 WebTestProxyBase::~WebTestProxyBase() | 296 |
315 { | 297 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { |
316 m_testInterfaces->windowClosed(this); | 298 test_interfaces_ = interfaces->testInterfaces(); |
317 } | 299 test_interfaces_->windowOpened(this); |
318 | 300 } |
319 void WebTestProxyBase::setInterfaces(WebTestInterfaces* interfaces) | 301 |
320 { | 302 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { |
321 m_testInterfaces = interfaces->testInterfaces(); | 303 delegate_ = delegate; |
322 m_testInterfaces->windowOpened(this); | 304 spellcheck_->setDelegate(delegate); |
323 } | 305 if (m_speechRecognizer.get()) m_speechRecognizer->setDelegate(delegate); |
324 | 306 } |
325 void WebTestProxyBase::setDelegate(WebTestDelegate* delegate) | 307 |
326 { | 308 WebView* WebTestProxyBase::GetWebView() const { |
327 m_delegate = delegate; | 309 DCHECK(web_widget_); |
328 m_spellcheck->setDelegate(delegate); | 310 // TestRunner does not support popup widgets. So |web_widget|_ is always a |
329 if (m_speechRecognizer.get()) | 311 // WebView. |
330 m_speechRecognizer->setDelegate(delegate); | 312 return static_cast<WebView*>(web_widget_); |
331 } | 313 } |
332 | 314 |
333 void WebTestProxyBase::setWidget(WebWidget* widget) | 315 void WebTestProxyBase::DidForceResize() { |
334 { | 316 InvalidateAll(); |
335 m_webWidget = widget; | 317 DiscardBackingStore(); |
336 } | 318 } |
337 | 319 |
338 WebWidget* WebTestProxyBase::webWidget() | 320 void WebTestProxyBase::Reset() { |
339 { | 321 paint_rect_ = WebRect(); |
340 return m_webWidget; | 322 canvas_.reset(); |
341 } | 323 is_painting_ = false; |
342 | 324 animate_scheduled_ = false; |
343 WebView* WebTestProxyBase::webView() | 325 resource_identifier_map_.clear(); |
344 { | 326 log_console_output_ = true; |
345 DCHECK(m_webWidget); | 327 if (m_midiClient.get()) m_midiClient->resetMock(); |
346 // TestRunner does not support popup widgets. So m_webWidget is always a Web
View. | 328 } |
347 return static_cast<WebView*>(m_webWidget); | 329 |
348 } | 330 WebSpellCheckClient* WebTestProxyBase::GetSpellCheckClient() const { |
349 | 331 return spellcheck_.get(); |
350 void WebTestProxyBase::didForceResize() | 332 } |
351 { | 333 |
352 invalidateAll(); | 334 WebColorChooser* WebTestProxyBase::CreateColorChooser( |
353 discardBackingStore(); | 335 WebColorChooserClient* client, const blink::WebColor& color, |
354 } | 336 const blink::WebVector<blink::WebColorSuggestion>& suggestions) { |
355 | 337 // This instance is deleted by WebCore::ColorInputType |
356 void WebTestProxyBase::reset() | 338 return new MockColorChooser(client, delegate_, this); |
357 { | 339 } |
358 m_paintRect = WebRect(); | 340 |
359 m_canvas.reset(); | 341 bool WebTestProxyBase::RunFileChooser(const blink::WebFileChooserParams&, |
360 m_isPainting = false; | 342 blink::WebFileChooserCompletion*) { |
361 m_animateScheduled = false; | 343 delegate_->printMessage("Mock: Opening a file chooser.\n"); |
362 m_resourceIdentifierMap.clear(); | 344 // FIXME: Add ability to set file names to a file upload control. |
363 m_logConsoleOutput = true; | 345 return false; |
364 if (m_midiClient.get()) | 346 } |
365 m_midiClient->resetMock(); | 347 |
366 } | 348 void WebTestProxyBase::ShowValidationMessage(const WebRect&, |
367 | 349 const WebString& message, |
368 WebSpellCheckClient* WebTestProxyBase::spellCheckClient() const | 350 const WebString& subMessage, |
369 { | 351 WebTextDirection) { |
370 return m_spellcheck.get(); | 352 delegate_->printMessage( |
371 } | 353 std::string("ValidationMessageClient: main-message=") + |
372 | 354 std::string(message.utf8()) + " sub-message=" + |
373 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli
ent, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggest
ion>& suggestions) | 355 std::string(subMessage.utf8()) + "\n"); |
374 { | 356 } |
375 // This instance is deleted by WebCore::ColorInputType | 357 |
376 return new MockColorChooser(client, m_delegate, this); | 358 void WebTestProxyBase::HideValidationMessage() {} |
377 } | 359 |
378 | 360 void WebTestProxyBase::MoveValidationMessage(const WebRect&) {} |
379 bool WebTestProxyBase::runFileChooser(const blink::WebFileChooserParams&, blink:
:WebFileChooserCompletion*) | 361 |
380 { | 362 string WebTestProxyBase::CaptureTree(bool debugRenderTree) { |
381 m_delegate->printMessage("Mock: Opening a file chooser.\n"); | 363 bool shouldDumpCustomText = |
382 // FIXME: Add ability to set file names to a file upload control. | 364 test_interfaces_->testRunner()->shouldDumpAsCustomText(); |
383 return false; | 365 bool shouldDumpAsText = test_interfaces_->testRunner()->shouldDumpAsText(); |
384 } | 366 bool shouldDumpAsMarkup = |
385 | 367 test_interfaces_->testRunner()->shouldDumpAsMarkup(); |
386 void WebTestProxyBase::showValidationMessage(const WebRect&, const WebString& me
ssage, const WebString& subMessage, WebTextDirection) | 368 bool shouldDumpAsPrinted = test_interfaces_->testRunner()->isPrinting(); |
387 { | 369 WebFrame* frame = GetWebView()->mainFrame(); |
388 m_delegate->printMessage(std::string("ValidationMessageClient: main-message=
") + std::string(message.utf8()) + " sub-message=" + std::string(subMessage.utf8
()) + "\n"); | 370 string dataUtf8; |
389 } | 371 if (shouldDumpCustomText) { |
390 | 372 // Append a newline for the test driver. |
391 void WebTestProxyBase::hideValidationMessage() | 373 dataUtf8 = test_interfaces_->testRunner()->customDumpText() + "\n"; |
392 { | 374 } else if (shouldDumpAsText) { |
393 } | 375 bool recursive = |
394 | 376 test_interfaces_->testRunner()->shouldDumpChildFramesAsText(); |
395 void WebTestProxyBase::moveValidationMessage(const WebRect&) | 377 dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) |
396 { | 378 : dumpFramesAsText(frame, recursive); |
397 } | 379 } else if (shouldDumpAsMarkup) { |
398 | 380 // Append a newline for the test driver. |
399 string WebTestProxyBase::captureTree(bool debugRenderTree) | 381 dataUtf8 = frame->contentAsMarkup().utf8() + "\n"; |
400 { | 382 } else { |
401 bool shouldDumpCustomText = m_testInterfaces->testRunner()->shouldDumpAsCust
omText(); | 383 bool recursive = |
402 bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText(); | 384 test_interfaces_->testRunner()->shouldDumpChildFrameScrollPositions(); |
403 bool shouldDumpAsMarkup = m_testInterfaces->testRunner()->shouldDumpAsMarkup
(); | 385 WebFrame::RenderAsTextControls renderTextBehavior = |
404 bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting(); | 386 WebFrame::RenderAsTextNormal; |
405 WebFrame* frame = webView()->mainFrame(); | 387 if (shouldDumpAsPrinted) |
406 string dataUtf8; | 388 renderTextBehavior |= WebFrame::RenderAsTextPrinting; |
407 if (shouldDumpCustomText) { | 389 if (debugRenderTree) renderTextBehavior |= WebFrame::RenderAsTextDebug; |
408 // Append a newline for the test driver. | 390 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); |
409 dataUtf8 = m_testInterfaces->testRunner()->customDumpText() + "\n"; | 391 dataUtf8 += dumpFrameScrollPosition(frame, recursive); |
410 } else if (shouldDumpAsText) { | 392 } |
411 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAs
Text(); | 393 |
412 dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursiv
e) : dumpFramesAsText(frame, recursive); | 394 if (test_interfaces_->testRunner()->shouldDumpBackForwardList()) |
413 } else if (shouldDumpAsMarkup) { | 395 dataUtf8 += dumpAllBackForwardLists(test_interfaces_, delegate_); |
414 // Append a newline for the test driver. | 396 |
415 dataUtf8 = frame->contentAsMarkup().utf8() + "\n"; | 397 return dataUtf8; |
416 } else { | 398 } |
417 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScr
ollPositions(); | 399 |
418 WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTe
xtNormal; | 400 SkCanvas* WebTestProxyBase::CapturePixels() { |
419 if (shouldDumpAsPrinted) | 401 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixels"); |
420 renderTextBehavior |= WebFrame::RenderAsTextPrinting; | 402 web_widget_->layout(); |
421 if (debugRenderTree) | 403 if (test_interfaces_->testRunner()->isPrinting()) |
422 renderTextBehavior |= WebFrame::RenderAsTextDebug; | 404 PaintPagesWithBoundaries(); |
423 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); | 405 else |
424 dataUtf8 += dumpFrameScrollPosition(frame, recursive); | 406 PaintInvalidatedRegion(); |
425 } | 407 |
426 | 408 DrawSelectionRect(GetCanvas()); |
427 if (m_testInterfaces->testRunner()->shouldDumpBackForwardList()) | 409 |
428 dataUtf8 += dumpAllBackForwardLists(m_testInterfaces, m_delegate); | 410 return GetCanvas(); |
429 | |
430 return dataUtf8; | |
431 } | |
432 | |
433 SkCanvas* WebTestProxyBase::capturePixels() | |
434 { | |
435 TRACE_EVENT0("shell", "WebTestProxyBase::capturePixels"); | |
436 webWidget()->layout(); | |
437 if (m_testInterfaces->testRunner()->isPrinting()) | |
438 paintPagesWithBoundaries(); | |
439 else | |
440 paintInvalidatedRegion(); | |
441 | |
442 DrawSelectionRect(canvas()); | |
443 | |
444 return canvas(); | |
445 } | 411 } |
446 | 412 |
447 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | 413 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
448 // See if we need to draw the selection bounds rect. Selection bounds | 414 // See if we need to draw the selection bounds rect. Selection bounds |
449 // rect is the rect enclosing the (possibly transformed) selection. | 415 // rect is the rect enclosing the (possibly transformed) selection. |
450 // The rect should be drawn after everything is laid out and painted. | 416 // The rect should be drawn after everything is laid out and painted. |
451 if (!m_testInterfaces->testRunner()->shouldDumpSelectionRect()) | 417 if (!test_interfaces_->testRunner()->shouldDumpSelectionRect()) return; |
452 return; | |
453 // If there is a selection rect - draw a red 1px border enclosing rect | 418 // If there is a selection rect - draw a red 1px border enclosing rect |
454 WebRect wr = webView()->mainFrame()->selectionBoundsRect(); | 419 WebRect wr = GetWebView()->mainFrame()->selectionBoundsRect(); |
455 if (wr.isEmpty()) | 420 if (wr.isEmpty()) return; |
456 return; | |
457 // Render a red rectangle bounding selection rect | 421 // Render a red rectangle bounding selection rect |
458 SkPaint paint; | 422 SkPaint paint; |
459 paint.setColor(0xFFFF0000); // Fully opaque red | 423 paint.setColor(0xFFFF0000); // Fully opaque red |
460 paint.setStyle(SkPaint::kStroke_Style); | 424 paint.setStyle(SkPaint::kStroke_Style); |
461 paint.setFlags(SkPaint::kAntiAlias_Flag); | 425 paint.setFlags(SkPaint::kAntiAlias_Flag); |
462 paint.setStrokeWidth(1.0f); | 426 paint.setStrokeWidth(1.0f); |
463 SkIRect rect; // Bounding rect | 427 SkIRect rect; // Bounding rect |
464 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); | 428 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); |
465 canvas->drawIRect(rect, paint); | 429 canvas->drawIRect(rect, paint); |
466 } | 430 } |
467 | 431 |
468 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { | 432 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { |
469 TRACE_EVENT2("shell", | 433 TRACE_EVENT2("shell", "WebTestProxyBase::didCompositeAndReadback", "x", |
470 "WebTestProxyBase::didCompositeAndReadback", | 434 bitmap.info().fWidth, "y", bitmap.info().fHeight); |
471 "x", | |
472 bitmap.info().fWidth, | |
473 "y", | |
474 bitmap.info().fHeight); | |
475 SkCanvas canvas(bitmap); | 435 SkCanvas canvas(bitmap); |
476 DrawSelectionRect(&canvas); | 436 DrawSelectionRect(&canvas); |
477 DCHECK(!m_compositeAndReadbackCallbacks.empty()); | 437 DCHECK(!composite_and_readback_callbacks_.empty()); |
478 m_compositeAndReadbackCallbacks.front().Run(bitmap); | 438 composite_and_readback_callbacks_.front().Run(bitmap); |
479 m_compositeAndReadbackCallbacks.pop_front(); | 439 composite_and_readback_callbacks_.pop_front(); |
480 } | 440 } |
481 | 441 |
482 void WebTestProxyBase::CapturePixelsForPrinting( | 442 void WebTestProxyBase::CapturePixelsForPrinting( |
483 base::Callback<void(const SkBitmap&)> callback) { | 443 const base::Callback<void(const SkBitmap&)>& callback) { |
484 // TODO(enne): get rid of stateful canvas(). | 444 // TODO(enne): get rid of stateful canvas(). |
485 webWidget()->layout(); | 445 web_widget_->layout(); |
486 paintPagesWithBoundaries(); | 446 PaintPagesWithBoundaries(); |
487 DrawSelectionRect(canvas()); | 447 DrawSelectionRect(GetCanvas()); |
488 SkBaseDevice* device = skia::GetTopDevice(*canvas()); | 448 SkBaseDevice* device = skia::GetTopDevice(*GetCanvas()); |
489 const SkBitmap& bitmap = device->accessBitmap(false); | 449 const SkBitmap& bitmap = device->accessBitmap(false); |
490 callback.Run(bitmap); | 450 callback.Run(bitmap); |
491 } | 451 } |
492 | 452 |
493 void WebTestProxyBase::CapturePixelsAsync( | 453 void WebTestProxyBase::CapturePixelsAsync( |
494 base::Callback<void(const SkBitmap&)> callback) { | 454 const base::Callback<void(const SkBitmap&)>& callback) { |
495 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | 455 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); |
496 | 456 |
497 DCHECK(webWidget()->isAcceleratedCompositingActive()); | 457 DCHECK(web_widget_->isAcceleratedCompositingActive()); |
498 DCHECK(!callback.is_null()); | 458 DCHECK(!callback.is_null()); |
499 | 459 |
500 if (m_testInterfaces->testRunner()->isPrinting()) { | 460 if (test_interfaces_->testRunner()->isPrinting()) { |
501 base::MessageLoopProxy::current()->PostTask( | 461 base::MessageLoopProxy::current()->PostTask( |
502 FROM_HERE, | 462 FROM_HERE, base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, |
503 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, | 463 base::Unretained(this), callback)); |
504 base::Unretained(this), | |
505 callback)); | |
506 return; | 464 return; |
507 } | 465 } |
508 | 466 |
509 m_compositeAndReadbackCallbacks.push_back(callback); | 467 composite_and_readback_callbacks_.push_back(callback); |
510 webWidget()->compositeAndReadbackAsync(this); | 468 web_widget_->compositeAndReadbackAsync(this); |
511 } | 469 } |
512 | 470 |
513 void WebTestProxyBase::setLogConsoleOutput(bool enabled) | 471 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { |
514 { | 472 log_console_output_ = enabled; |
515 m_logConsoleOutput = enabled; | |
516 } | 473 } |
517 | 474 |
518 void WebTestProxyBase::paintRect(const WebRect& rect) | 475 void WebTestProxyBase::PaintRect(const WebRect& rect) { |
519 { | 476 DCHECK(!is_painting_); |
520 DCHECK(!m_isPainting); | 477 DCHECK(GetCanvas()); |
521 DCHECK(canvas()); | 478 is_painting_ = true; |
522 m_isPainting = true; | 479 float deviceScaleFactor = GetWebView()->deviceScaleFactor(); |
523 float deviceScaleFactor = webView()->deviceScaleFactor(); | 480 int scaledX = |
524 int scaledX = static_cast<int>(static_cast<float>(rect.x) * deviceScaleFacto
r); | 481 static_cast<int>(static_cast<float>(rect.x) * deviceScaleFactor); |
525 int scaledY = static_cast<int>(static_cast<float>(rect.y) * deviceScaleFacto
r); | 482 int scaledY = |
526 int scaledWidth = static_cast<int>(ceil(static_cast<float>(rect.width) * dev
iceScaleFactor)); | 483 static_cast<int>(static_cast<float>(rect.y) * deviceScaleFactor); |
527 int scaledHeight = static_cast<int>(ceil(static_cast<float>(rect.height) * d
eviceScaleFactor)); | 484 int scaledWidth = static_cast<int>( |
528 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight); | 485 ceil(static_cast<float>(rect.width) * deviceScaleFactor)); |
529 webWidget()->paint(canvas(), deviceRect); | 486 int scaledHeight = static_cast<int>( |
530 m_isPainting = false; | 487 ceil(static_cast<float>(rect.height) * deviceScaleFactor)); |
| 488 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight); |
| 489 web_widget_->paint(GetCanvas(), deviceRect); |
| 490 is_painting_ = false; |
531 } | 491 } |
532 | 492 |
533 void WebTestProxyBase::paintInvalidatedRegion() | 493 void WebTestProxyBase::PaintInvalidatedRegion() { |
534 { | 494 web_widget_->animate(0.0); |
535 webWidget()->animate(0.0); | 495 web_widget_->layout(); |
536 webWidget()->layout(); | 496 WebSize widgetSize = web_widget_->size(); |
537 WebSize widgetSize = webWidget()->size(); | 497 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height); |
538 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height); | |
539 | 498 |
540 // Paint the canvas if necessary. Allow painting to generate extra rects | 499 // Paint the canvas if necessary. Allow painting to generate extra rects |
541 // for the first two calls. This is necessary because some WebCore rendering | 500 // for the first two calls. This is necessary because some WebCore rendering |
542 // objects update their layout only when painted. | 501 // objects update their layout only when painted. |
543 // Store the total area painted in total_paint. Then tell the gdk window | 502 // Store the total area painted in total_paint. Then tell the gdk window |
544 // to update that area after we're done painting it. | 503 // to update that area after we're done painting it. |
545 for (int i = 0; i < 3; ++i) { | 504 for (int i = 0; i < 3; ++i) { |
546 // rect = intersect(m_paintRect , clientRect) | 505 // rect = intersect(paint_rect_ , clientRect) |
547 WebRect damageRect = m_paintRect; | 506 WebRect damageRect = paint_rect_; |
548 int left = max(damageRect.x, clientRect.x); | 507 int left = max(damageRect.x, clientRect.x); |
549 int top = max(damageRect.y, clientRect.y); | 508 int top = max(damageRect.y, clientRect.y); |
550 int right = min(damageRect.x + damageRect.width, clientRect.x + clientRe
ct.width); | 509 int right = |
551 int bottom = min(damageRect.y + damageRect.height, clientRect.y + client
Rect.height); | 510 min(damageRect.x + damageRect.width, clientRect.x + clientRect.width); |
552 WebRect rect; | 511 int bottom = |
553 if (left < right && top < bottom) | 512 min(damageRect.y + damageRect.height, clientRect.y + clientRect.height); |
554 rect = WebRect(left, top, right - left, bottom - top); | 513 WebRect rect; |
| 514 if (left < right && top < bottom) |
| 515 rect = WebRect(left, top, right - left, bottom - top); |
555 | 516 |
556 m_paintRect = WebRect(); | 517 paint_rect_ = WebRect(); |
557 if (rect.isEmpty()) | 518 if (rect.isEmpty()) continue; |
558 continue; | 519 PaintRect(rect); |
559 paintRect(rect); | 520 } |
560 } | 521 DCHECK(paint_rect_.isEmpty()); |
561 DCHECK(m_paintRect.isEmpty()); | |
562 } | 522 } |
563 | 523 |
564 void WebTestProxyBase::paintPagesWithBoundaries() | 524 void WebTestProxyBase::PaintPagesWithBoundaries() { |
565 { | 525 DCHECK(!is_painting_); |
566 DCHECK(!m_isPainting); | 526 DCHECK(GetCanvas()); |
567 DCHECK(canvas()); | 527 is_painting_ = true; |
568 m_isPainting = true; | |
569 | 528 |
570 WebSize pageSizeInPixels = webWidget()->size(); | 529 WebSize pageSizeInPixels = web_widget_->size(); |
571 WebFrame* webFrame = webView()->mainFrame(); | 530 WebFrame* webFrame = GetWebView()->mainFrame(); |
572 | 531 |
573 int pageCount = webFrame->printBegin(pageSizeInPixels); | 532 int pageCount = webFrame->printBegin(pageSizeInPixels); |
574 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; | 533 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; |
575 | 534 |
576 SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, t
otalHeight, false); | 535 SkCanvas* testCanvas = |
577 if (testCanvas) { | 536 skia::TryCreateBitmapCanvas(pageSizeInPixels.width, totalHeight, false); |
578 discardBackingStore(); | 537 if (testCanvas) { |
579 m_canvas.reset(testCanvas); | 538 DiscardBackingStore(); |
580 } else { | 539 canvas_.reset(testCanvas); |
581 webFrame->printEnd(); | 540 } else { |
582 return; | 541 webFrame->printEnd(); |
583 } | 542 return; |
| 543 } |
584 | 544 |
585 webFrame->printPagesWithBoundaries(canvas(), pageSizeInPixels); | 545 webFrame->printPagesWithBoundaries(GetCanvas(), pageSizeInPixels); |
586 webFrame->printEnd(); | 546 webFrame->printEnd(); |
587 | 547 |
588 m_isPainting = false; | 548 is_painting_ = false; |
589 } | 549 } |
590 | 550 |
591 SkCanvas* WebTestProxyBase::canvas() | 551 SkCanvas* WebTestProxyBase::GetCanvas() { |
592 { | 552 if (canvas_.get()) return canvas_.get(); |
593 if (m_canvas.get()) | 553 WebSize widgetSize = web_widget_->size(); |
594 return m_canvas.get(); | 554 float deviceScaleFactor = GetWebView()->deviceScaleFactor(); |
595 WebSize widgetSize = webWidget()->size(); | 555 int scaledWidth = static_cast<int>( |
596 float deviceScaleFactor = webView()->deviceScaleFactor(); | 556 ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor)); |
597 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width)
* deviceScaleFactor)); | 557 int scaledHeight = static_cast<int>( |
598 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh
t) * deviceScaleFactor)); | 558 ceil(static_cast<float>(widgetSize.height) * deviceScaleFactor)); |
599 // We're allocating the canvas to be non-opaque (third parameter), so we | 559 // We're allocating the canvas to be non-opaque (third parameter), so we |
600 // don't end up with uninitialized memory if a layout test doesn't damage | 560 // don't end up with uninitialized memory if a layout test doesn't damage |
601 // the entire view. | 561 // the entire view. |
602 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); | 562 canvas_.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); |
603 return m_canvas.get(); | 563 return canvas_.get(); |
604 } | 564 } |
605 | 565 |
606 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { | 566 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { |
607 const blink::WebSize& size = webWidget()->size(); | 567 const blink::WebSize& size = web_widget_->size(); |
608 WebRect rect(0, 0, size.width, size.height); | 568 WebRect rect(0, 0, size.width, size.height); |
609 m_paintRect = rect; | 569 paint_rect_ = rect; |
610 paintInvalidatedRegion(); | 570 PaintInvalidatedRegion(); |
611 | 571 |
612 if (!callback.is_null()) | 572 if (!callback.is_null()) callback.Run(); |
613 callback.Run(); | |
614 } | 573 } |
615 | 574 |
616 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, | 575 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, |
617 const SkBitmap& bitmap) { | 576 const SkBitmap& bitmap) { |
618 // Verify we actually composited. | 577 // Verify we actually composited. |
619 CHECK_NE(0, bitmap.info().fWidth); | 578 CHECK_NE(0, bitmap.info().fWidth); |
620 CHECK_NE(0, bitmap.info().fHeight); | 579 CHECK_NE(0, bitmap.info().fHeight); |
621 if (!callback.is_null()) | 580 if (!callback.is_null()) callback.Run(); |
622 callback.Run(); | 581 } |
623 } | 582 |
624 | 583 void WebTestProxyBase::DisplayAsyncThen(const base::Closure& callback) { |
625 void WebTestProxyBase::displayAsyncThen(base::Closure callback) { | 584 TRACE_EVENT0("shell", "WebTestProxyBase::DisplayAsyncThen"); |
626 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); | |
627 | 585 |
628 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. | 586 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. |
629 if (!webWidget()->isAcceleratedCompositingActive()) { | 587 if (!web_widget_->isAcceleratedCompositingActive()) { |
630 TRACE_EVENT0("shell", | 588 TRACE_EVENT0("shell", |
631 "WebTestProxyBase::displayAsyncThen " | 589 "WebTestProxyBase::DisplayAsyncThen " |
632 "isAcceleratedCompositingActive false"); | 590 "isAcceleratedCompositingActive false"); |
633 base::MessageLoopProxy::current()->PostTask( | 591 base::MessageLoopProxy::current()->PostTask( |
634 FROM_HERE, | 592 FROM_HERE, base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, |
635 base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, | 593 base::Unretained(this), callback)); |
636 base::Unretained(this), | |
637 callback)); | |
638 return; | 594 return; |
639 } | 595 } |
640 | 596 |
641 CapturePixelsAsync(base::Bind( | 597 CapturePixelsAsync(base::Bind(&WebTestProxyBase::DidDisplayAsync, |
642 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback)); | 598 base::Unretained(this), callback)); |
643 } | 599 } |
644 | 600 |
645 void WebTestProxyBase::discardBackingStore() | 601 void WebTestProxyBase::DiscardBackingStore() { canvas_.reset(); } |
646 { | 602 |
647 m_canvas.reset(); | 603 WebMIDIClientMock* WebTestProxyBase::GetMIDIClientMock() { |
648 } | 604 if (!m_midiClient.get()) m_midiClient.reset(new WebMIDIClientMock); |
649 | 605 return m_midiClient.get(); |
650 WebMIDIClientMock* WebTestProxyBase::midiClientMock() | 606 } |
651 { | 607 |
652 if (!m_midiClient.get()) | 608 MockWebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizerMock() { |
653 m_midiClient.reset(new WebMIDIClientMock); | 609 if (!m_speechRecognizer.get()) { |
654 return m_midiClient.get(); | 610 m_speechRecognizer.reset(new MockWebSpeechRecognizer()); |
655 } | 611 m_speechRecognizer->setDelegate(delegate_); |
656 | 612 } |
657 MockWebSpeechRecognizer* WebTestProxyBase::speechRecognizerMock() | 613 return m_speechRecognizer.get(); |
658 { | 614 } |
659 if (!m_speechRecognizer.get()) { | 615 |
660 m_speechRecognizer.reset(new MockWebSpeechRecognizer()); | 616 void WebTestProxyBase::DidInvalidateRect(const WebRect& rect) { |
661 m_speechRecognizer->setDelegate(m_delegate); | 617 // paint_rect_ = paint_rect_ U rect |
| 618 if (rect.isEmpty()) return; |
| 619 if (paint_rect_.isEmpty()) { |
| 620 paint_rect_ = rect; |
| 621 return; |
| 622 } |
| 623 int left = min(paint_rect_.x, rect.x); |
| 624 int top = min(paint_rect_.y, rect.y); |
| 625 int right = max(paint_rect_.x + paint_rect_.width, rect.x + rect.width); |
| 626 int bottom = max(paint_rect_.y + paint_rect_.height, rect.y + rect.height); |
| 627 paint_rect_ = WebRect(left, top, right - left, bottom - top); |
| 628 } |
| 629 |
| 630 void WebTestProxyBase::DidScrollRect(int, int, const WebRect& clipRect) { |
| 631 DidInvalidateRect(clipRect); |
| 632 } |
| 633 |
| 634 void WebTestProxyBase::InvalidateAll() { |
| 635 paint_rect_ = WebRect(0, 0, INT_MAX, INT_MAX); |
| 636 } |
| 637 |
| 638 void WebTestProxyBase::ScheduleComposite() { InvalidateAll(); } |
| 639 |
| 640 void WebTestProxyBase::ScheduleAnimation() { |
| 641 if (!test_interfaces_->testRunner()->TestIsRunning()) return; |
| 642 |
| 643 if (!animate_scheduled_) { |
| 644 animate_scheduled_ = true; |
| 645 delegate_->postDelayedTask( |
| 646 new HostMethodTask(this, &WebTestProxyBase::AnimateNow), 1); |
| 647 } |
| 648 } |
| 649 |
| 650 void WebTestProxyBase::AnimateNow() { |
| 651 if (animate_scheduled_) { |
| 652 animate_scheduled_ = false; |
| 653 web_widget_->animate(0.0); |
| 654 web_widget_->layout(); |
| 655 } |
| 656 } |
| 657 |
| 658 bool WebTestProxyBase::IsCompositorFramePending() const { |
| 659 return animate_scheduled_ || !paint_rect_.isEmpty(); |
| 660 } |
| 661 |
| 662 void WebTestProxyBase::Show(WebNavigationPolicy) { InvalidateAll(); } |
| 663 |
| 664 void WebTestProxyBase::SetWindowRect(const WebRect& rect) { |
| 665 InvalidateAll(); |
| 666 DiscardBackingStore(); |
| 667 } |
| 668 |
| 669 void WebTestProxyBase::DidAutoResize(const WebSize&) { InvalidateAll(); } |
| 670 |
| 671 void WebTestProxyBase::PostAccessibilityEvent(const blink::WebAXObject& obj, |
| 672 blink::WebAXEvent event) { |
| 673 // Only hook the accessibility events occured during the test run. |
| 674 // This check prevents false positives in WebLeakDetector. |
| 675 // The pending tasks in browser/renderer message queue may trigger |
| 676 // accessibility events, |
| 677 // and AccessibilityController will hold on to their target nodes if we don't |
| 678 // ignore them here. |
| 679 if (!test_interfaces_->testRunner()->TestIsRunning()) return; |
| 680 |
| 681 if (event == blink::WebAXEventFocus) |
| 682 test_interfaces_->accessibilityController()->SetFocusedElement(obj); |
| 683 |
| 684 const char* eventName = NULL; |
| 685 switch (event) { |
| 686 case blink::WebAXEventActiveDescendantChanged: |
| 687 eventName = "ActiveDescendantChanged"; |
| 688 break; |
| 689 case blink::WebAXEventAlert: |
| 690 eventName = "Alert"; |
| 691 break; |
| 692 case blink::WebAXEventAriaAttributeChanged: |
| 693 eventName = "AriaAttributeChanged"; |
| 694 break; |
| 695 case blink::WebAXEventAutocorrectionOccured: |
| 696 eventName = "AutocorrectionOccured"; |
| 697 break; |
| 698 case blink::WebAXEventBlur: |
| 699 eventName = "Blur"; |
| 700 break; |
| 701 case blink::WebAXEventCheckedStateChanged: |
| 702 eventName = "CheckedStateChanged"; |
| 703 break; |
| 704 case blink::WebAXEventChildrenChanged: |
| 705 eventName = "ChildrenChanged"; |
| 706 break; |
| 707 case blink::WebAXEventFocus: |
| 708 eventName = "Focus"; |
| 709 break; |
| 710 case blink::WebAXEventHide: |
| 711 eventName = "Hide"; |
| 712 break; |
| 713 case blink::WebAXEventInvalidStatusChanged: |
| 714 eventName = "InvalidStatusChanged"; |
| 715 break; |
| 716 case blink::WebAXEventLayoutComplete: |
| 717 eventName = "LayoutComplete"; |
| 718 break; |
| 719 case blink::WebAXEventLiveRegionChanged: |
| 720 eventName = "LiveRegionChanged"; |
| 721 break; |
| 722 case blink::WebAXEventLoadComplete: |
| 723 eventName = "LoadComplete"; |
| 724 break; |
| 725 case blink::WebAXEventLocationChanged: |
| 726 eventName = "LocationChanged"; |
| 727 break; |
| 728 case blink::WebAXEventMenuListItemSelected: |
| 729 eventName = "MenuListItemSelected"; |
| 730 break; |
| 731 case blink::WebAXEventMenuListValueChanged: |
| 732 eventName = "MenuListValueChanged"; |
| 733 break; |
| 734 case blink::WebAXEventRowCollapsed: |
| 735 eventName = "RowCollapsed"; |
| 736 break; |
| 737 case blink::WebAXEventRowCountChanged: |
| 738 eventName = "RowCountChanged"; |
| 739 break; |
| 740 case blink::WebAXEventRowExpanded: |
| 741 eventName = "RowExpanded"; |
| 742 break; |
| 743 case blink::WebAXEventScrollPositionChanged: |
| 744 eventName = "ScrollPositionChanged"; |
| 745 break; |
| 746 case blink::WebAXEventScrolledToAnchor: |
| 747 eventName = "ScrolledToAnchor"; |
| 748 break; |
| 749 case blink::WebAXEventSelectedChildrenChanged: |
| 750 eventName = "SelectedChildrenChanged"; |
| 751 break; |
| 752 case blink::WebAXEventSelectedTextChanged: |
| 753 eventName = "SelectedTextChanged"; |
| 754 break; |
| 755 case blink::WebAXEventShow: |
| 756 eventName = "Show"; |
| 757 break; |
| 758 case blink::WebAXEventTextChanged: |
| 759 eventName = "TextChanged"; |
| 760 break; |
| 761 case blink::WebAXEventTextInserted: |
| 762 eventName = "TextInserted"; |
| 763 break; |
| 764 case blink::WebAXEventTextRemoved: |
| 765 eventName = "TextRemoved"; |
| 766 break; |
| 767 case blink::WebAXEventValueChanged: |
| 768 eventName = "ValueChanged"; |
| 769 break; |
| 770 default: |
| 771 eventName = "Unknown"; |
| 772 break; |
| 773 } |
| 774 |
| 775 test_interfaces_->accessibilityController()->NotificationReceived(obj, |
| 776 eventName); |
| 777 |
| 778 if (test_interfaces_->accessibilityController() |
| 779 ->ShouldLogAccessibilityEvents()) { |
| 780 string message("AccessibilityNotification - "); |
| 781 message += eventName; |
| 782 |
| 783 blink::WebNode node = obj.node(); |
| 784 if (!node.isNull() && node.isElementNode()) { |
| 785 blink::WebElement element = node.to<blink::WebElement>(); |
| 786 if (element.hasAttribute("id")) { |
| 787 message += " - id:"; |
| 788 message += element.getAttribute("id").utf8().data(); |
| 789 } |
662 } | 790 } |
663 return m_speechRecognizer.get(); | 791 |
664 } | 792 delegate_->printMessage(message + "\n"); |
665 | 793 } |
666 void WebTestProxyBase::didInvalidateRect(const WebRect& rect) | 794 } |
667 { | 795 |
668 // m_paintRect = m_paintRect U rect | 796 void WebTestProxyBase::StartDragging(WebLocalFrame*, const WebDragData& data, |
669 if (rect.isEmpty()) | 797 WebDragOperationsMask mask, |
670 return; | 798 const WebImage&, const WebPoint&) { |
671 if (m_paintRect.isEmpty()) { | 799 // When running a test, we need to fake a drag drop operation otherwise |
672 m_paintRect = rect; | 800 // Windows waits for real mouse events to know when the drag is over. |
673 return; | 801 test_interfaces_->eventSender()->DoDragDrop(data, mask); |
674 } | |
675 int left = min(m_paintRect.x, rect.x); | |
676 int top = min(m_paintRect.y, rect.y); | |
677 int right = max(m_paintRect.x + m_paintRect.width, rect.x + rect.width); | |
678 int bottom = max(m_paintRect.y + m_paintRect.height, rect.y + rect.height); | |
679 m_paintRect = WebRect(left, top, right - left, bottom - top); | |
680 } | |
681 | |
682 void WebTestProxyBase::didScrollRect(int, int, const WebRect& clipRect) | |
683 { | |
684 didInvalidateRect(clipRect); | |
685 } | |
686 | |
687 void WebTestProxyBase::invalidateAll() | |
688 { | |
689 m_paintRect = WebRect(0, 0, INT_MAX, INT_MAX); | |
690 } | |
691 | |
692 void WebTestProxyBase::scheduleComposite() | |
693 { | |
694 invalidateAll(); | |
695 } | |
696 | |
697 void WebTestProxyBase::scheduleAnimation() | |
698 { | |
699 if (!m_testInterfaces->testRunner()->TestIsRunning()) | |
700 return; | |
701 | |
702 if (!m_animateScheduled) { | |
703 m_animateScheduled = true; | |
704 m_delegate->postDelayedTask(new HostMethodTask(this, &WebTestProxyBase::
animateNow), 1); | |
705 } | |
706 } | |
707 | |
708 void WebTestProxyBase::animateNow() | |
709 { | |
710 if (m_animateScheduled) { | |
711 m_animateScheduled = false; | |
712 webWidget()->animate(0.0); | |
713 webWidget()->layout(); | |
714 } | |
715 } | |
716 | |
717 bool WebTestProxyBase::isCompositorFramePending() const | |
718 { | |
719 return m_animateScheduled || !m_paintRect.isEmpty(); | |
720 } | |
721 | |
722 void WebTestProxyBase::show(WebNavigationPolicy) | |
723 { | |
724 invalidateAll(); | |
725 } | |
726 | |
727 void WebTestProxyBase::setWindowRect(const WebRect& rect) | |
728 { | |
729 invalidateAll(); | |
730 discardBackingStore(); | |
731 } | |
732 | |
733 void WebTestProxyBase::didAutoResize(const WebSize&) | |
734 { | |
735 invalidateAll(); | |
736 } | |
737 | |
738 void WebTestProxyBase::postAccessibilityEvent(const blink::WebAXObject& obj, bli
nk::WebAXEvent event) | |
739 { | |
740 // Only hook the accessibility events occured during the test run. | |
741 // This check prevents false positives in WebLeakDetector. | |
742 // The pending tasks in browser/renderer message queue may trigger accessibi
lity events, | |
743 // and AccessibilityController will hold on to their target nodes if we don'
t ignore them here. | |
744 if (!m_testInterfaces->testRunner()->TestIsRunning()) | |
745 return; | |
746 | |
747 if (event == blink::WebAXEventFocus) | |
748 m_testInterfaces->accessibilityController()->SetFocusedElement(obj); | |
749 | |
750 const char* eventName = 0; | |
751 switch (event) { | |
752 case blink::WebAXEventActiveDescendantChanged: | |
753 eventName = "ActiveDescendantChanged"; | |
754 break; | |
755 case blink::WebAXEventAlert: | |
756 eventName = "Alert"; | |
757 break; | |
758 case blink::WebAXEventAriaAttributeChanged: | |
759 eventName = "AriaAttributeChanged"; | |
760 break; | |
761 case blink::WebAXEventAutocorrectionOccured: | |
762 eventName = "AutocorrectionOccured"; | |
763 break; | |
764 case blink::WebAXEventBlur: | |
765 eventName = "Blur"; | |
766 break; | |
767 case blink::WebAXEventCheckedStateChanged: | |
768 eventName = "CheckedStateChanged"; | |
769 break; | |
770 case blink::WebAXEventChildrenChanged: | |
771 eventName = "ChildrenChanged"; | |
772 break; | |
773 case blink::WebAXEventFocus: | |
774 eventName = "Focus"; | |
775 break; | |
776 case blink::WebAXEventHide: | |
777 eventName = "Hide"; | |
778 break; | |
779 case blink::WebAXEventInvalidStatusChanged: | |
780 eventName = "InvalidStatusChanged"; | |
781 break; | |
782 case blink::WebAXEventLayoutComplete: | |
783 eventName = "LayoutComplete"; | |
784 break; | |
785 case blink::WebAXEventLiveRegionChanged: | |
786 eventName = "LiveRegionChanged"; | |
787 break; | |
788 case blink::WebAXEventLoadComplete: | |
789 eventName = "LoadComplete"; | |
790 break; | |
791 case blink::WebAXEventLocationChanged: | |
792 eventName = "LocationChanged"; | |
793 break; | |
794 case blink::WebAXEventMenuListItemSelected: | |
795 eventName = "MenuListItemSelected"; | |
796 break; | |
797 case blink::WebAXEventMenuListValueChanged: | |
798 eventName = "MenuListValueChanged"; | |
799 break; | |
800 case blink::WebAXEventRowCollapsed: | |
801 eventName = "RowCollapsed"; | |
802 break; | |
803 case blink::WebAXEventRowCountChanged: | |
804 eventName = "RowCountChanged"; | |
805 break; | |
806 case blink::WebAXEventRowExpanded: | |
807 eventName = "RowExpanded"; | |
808 break; | |
809 case blink::WebAXEventScrollPositionChanged: | |
810 eventName = "ScrollPositionChanged"; | |
811 break; | |
812 case blink::WebAXEventScrolledToAnchor: | |
813 eventName = "ScrolledToAnchor"; | |
814 break; | |
815 case blink::WebAXEventSelectedChildrenChanged: | |
816 eventName = "SelectedChildrenChanged"; | |
817 break; | |
818 case blink::WebAXEventSelectedTextChanged: | |
819 eventName = "SelectedTextChanged"; | |
820 break; | |
821 case blink::WebAXEventShow: | |
822 eventName = "Show"; | |
823 break; | |
824 case blink::WebAXEventTextChanged: | |
825 eventName = "TextChanged"; | |
826 break; | |
827 case blink::WebAXEventTextInserted: | |
828 eventName = "TextInserted"; | |
829 break; | |
830 case blink::WebAXEventTextRemoved: | |
831 eventName = "TextRemoved"; | |
832 break; | |
833 case blink::WebAXEventValueChanged: | |
834 eventName = "ValueChanged"; | |
835 break; | |
836 default: | |
837 eventName = "Unknown"; | |
838 break; | |
839 } | |
840 | |
841 m_testInterfaces->accessibilityController()->NotificationReceived(obj, event
Name); | |
842 | |
843 if (m_testInterfaces->accessibilityController()->ShouldLogAccessibilityEvent
s()) { | |
844 string message("AccessibilityNotification - "); | |
845 message += eventName; | |
846 | |
847 blink::WebNode node = obj.node(); | |
848 if (!node.isNull() && node.isElementNode()) { | |
849 blink::WebElement element = node.to<blink::WebElement>(); | |
850 if (element.hasAttribute("id")) { | |
851 message += " - id:"; | |
852 message += element.getAttribute("id").utf8().data(); | |
853 } | |
854 } | |
855 | |
856 m_delegate->printMessage(message + "\n"); | |
857 } | |
858 } | |
859 | |
860 void WebTestProxyBase::startDragging(WebLocalFrame*, const WebDragData& data, We
bDragOperationsMask mask, const WebImage&, const WebPoint&) | |
861 { | |
862 // When running a test, we need to fake a drag drop operation otherwise | |
863 // Windows waits for real mouse events to know when the drag is over. | |
864 m_testInterfaces->eventSender()->DoDragDrop(data, mask); | |
865 } | 802 } |
866 | 803 |
867 // The output from these methods in layout test mode should match that | 804 // The output from these methods in layout test mode should match that |
868 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | 805 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
869 | 806 |
870 void WebTestProxyBase::didChangeSelection(bool isEmptySelection) | 807 void WebTestProxyBase::DidChangeSelection(bool isEmptySelection) { |
871 { | 808 if (test_interfaces_->testRunner()->shouldDumpEditingCallbacks()) |
872 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) | 809 delegate_->printMessage( |
873 m_delegate->printMessage("EDITING DELEGATE: webViewDidChangeSelection:We
bViewDidChangeSelectionNotification\n"); | 810 "EDITING DELEGATE: " |
874 } | 811 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); |
875 | 812 } |
876 void WebTestProxyBase::didChangeContents() | 813 |
877 { | 814 void WebTestProxyBase::DidChangeContents() { |
878 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) | 815 if (test_interfaces_->testRunner()->shouldDumpEditingCallbacks()) |
879 m_delegate->printMessage("EDITING DELEGATE: webViewDidChange:WebViewDidC
hangeNotification\n"); | 816 delegate_->printMessage( |
880 } | 817 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); |
881 | 818 } |
882 bool WebTestProxyBase::createView(WebLocalFrame*, const WebURLRequest& request,
const WebWindowFeatures&, const WebString&, WebNavigationPolicy, bool) | 819 |
883 { | 820 bool WebTestProxyBase::CreateView(WebLocalFrame*, const WebURLRequest& request, |
884 if (!m_testInterfaces->testRunner()->canOpenWindows()) | 821 const WebWindowFeatures&, const WebString&, |
885 return false; | 822 WebNavigationPolicy, bool) { |
886 if (m_testInterfaces->testRunner()->shouldDumpCreateView()) | 823 if (!test_interfaces_->testRunner()->canOpenWindows()) return false; |
887 m_delegate->printMessage(string("createView(") + URLDescription(request.
url()) + ")\n"); | 824 if (test_interfaces_->testRunner()->shouldDumpCreateView()) |
| 825 delegate_->printMessage(string("createView(") + |
| 826 URLDescription(request.url()) + ")\n"); |
| 827 return true; |
| 828 } |
| 829 |
| 830 WebPlugin* WebTestProxyBase::CreatePlugin(WebLocalFrame* frame, |
| 831 const WebPluginParams& params) { |
| 832 if (TestPlugin::isSupportedMimeType(params.mimeType)) |
| 833 return TestPlugin::create(frame, params, delegate_); |
| 834 return 0; |
| 835 } |
| 836 |
| 837 void WebTestProxyBase::SetStatusText(const WebString& text) { |
| 838 if (!test_interfaces_->testRunner()->shouldDumpStatusCallbacks()) return; |
| 839 delegate_->printMessage( |
| 840 string("UI DELEGATE STATUS CALLBACK: setStatusText:") + |
| 841 text.utf8().data() + "\n"); |
| 842 } |
| 843 |
| 844 void WebTestProxyBase::DidStopLoading() { |
| 845 if (test_interfaces_->testRunner()->shouldDumpProgressFinishedCallback()) |
| 846 delegate_->printMessage("postProgressFinishedNotification\n"); |
| 847 } |
| 848 |
| 849 void WebTestProxyBase::ShowContextMenu( |
| 850 WebLocalFrame*, const WebContextMenuData& contextMenuData) { |
| 851 test_interfaces_->eventSender()->SetContextMenuData(contextMenuData); |
| 852 } |
| 853 |
| 854 WebUserMediaClient* WebTestProxyBase::GetUserMediaClient() { |
| 855 if (!user_media_client_.get()) |
| 856 user_media_client_.reset(new WebUserMediaClientMock(delegate_)); |
| 857 return user_media_client_.get(); |
| 858 } |
| 859 |
| 860 // Simulate a print by going into print mode and then exit straight away. |
| 861 void WebTestProxyBase::PrintPage(WebLocalFrame* frame) { |
| 862 WebSize pageSizeInPixels = web_widget_->size(); |
| 863 if (pageSizeInPixels.isEmpty()) return; |
| 864 WebPrintParams printParams(pageSizeInPixels); |
| 865 frame->printBegin(printParams); |
| 866 frame->printEnd(); |
| 867 } |
| 868 |
| 869 WebNotificationPresenter* WebTestProxyBase::GetNotificationPresenter() { |
| 870 return test_interfaces_->testRunner()->notification_presenter(); |
| 871 } |
| 872 |
| 873 WebMIDIClient* WebTestProxyBase::GetWebMIDIClient() { |
| 874 return GetMIDIClientMock(); |
| 875 } |
| 876 |
| 877 WebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizer() { |
| 878 return GetSpeechRecognizerMock(); |
| 879 } |
| 880 |
| 881 bool WebTestProxyBase::RequestPointerLock() { |
| 882 return test_interfaces_->testRunner()->RequestPointerLock(); |
| 883 } |
| 884 |
| 885 void WebTestProxyBase::RequestPointerUnlock() { |
| 886 test_interfaces_->testRunner()->RequestPointerUnlock(); |
| 887 } |
| 888 |
| 889 bool WebTestProxyBase::IsPointerLocked() { |
| 890 return test_interfaces_->testRunner()->isPointerLocked(); |
| 891 } |
| 892 |
| 893 void WebTestProxyBase::DidFocus() { delegate_->setFocus(this, true); } |
| 894 |
| 895 void WebTestProxyBase::DidBlur() { delegate_->setFocus(this, false); } |
| 896 |
| 897 void WebTestProxyBase::SetToolTipText(const WebString& text, WebTextDirection) { |
| 898 test_interfaces_->testRunner()->setToolTipText(text); |
| 899 } |
| 900 |
| 901 void WebTestProxyBase::DidOpenChooser() { chooser_count_++; } |
| 902 |
| 903 void WebTestProxyBase::DidCloseChooser() { chooser_count_--; } |
| 904 |
| 905 bool WebTestProxyBase::IsChooserShown() { return 0 < chooser_count_; } |
| 906 |
| 907 void WebTestProxyBase::LoadURLExternally(WebLocalFrame* frame, |
| 908 const WebURLRequest& request, |
| 909 WebNavigationPolicy policy, |
| 910 const WebString& suggested_name) { |
| 911 if (test_interfaces_->testRunner()->shouldWaitUntilExternalURLLoad()) { |
| 912 if (policy == WebNavigationPolicyDownload) { |
| 913 delegate_->printMessage( |
| 914 string("Downloading URL with suggested filename \"") + |
| 915 suggested_name.utf8() + "\"\n"); |
| 916 } else { |
| 917 delegate_->printMessage(string("Loading URL externally - \"") + |
| 918 URLDescription(request.url()) + "\"\n"); |
| 919 } |
| 920 delegate_->testFinished(); |
| 921 } |
| 922 } |
| 923 |
| 924 void WebTestProxyBase::DidStartProvisionalLoad(WebLocalFrame* frame) { |
| 925 if (!test_interfaces_->testRunner()->topLoadingFrame()) |
| 926 test_interfaces_->testRunner()->setTopLoadingFrame(frame, false); |
| 927 |
| 928 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 929 printFrameDescription(delegate_, frame); |
| 930 delegate_->printMessage(" - didStartProvisionalLoadForFrame\n"); |
| 931 } |
| 932 |
| 933 if (test_interfaces_->testRunner() |
| 934 ->shouldDumpUserGestureInFrameLoadCallbacks()) |
| 935 printFrameUserGestureStatus(delegate_, frame, |
| 936 " - in didStartProvisionalLoadForFrame\n"); |
| 937 } |
| 938 |
| 939 void WebTestProxyBase::DidReceiveServerRedirectForProvisionalLoad( |
| 940 WebLocalFrame* frame) { |
| 941 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 942 printFrameDescription(delegate_, frame); |
| 943 delegate_->printMessage( |
| 944 " - didReceiveServerRedirectForProvisionalLoadForFrame\n"); |
| 945 } |
| 946 } |
| 947 |
| 948 bool WebTestProxyBase::DidFailProvisionalLoad(WebLocalFrame* frame, |
| 949 const WebURLError&) { |
| 950 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 951 printFrameDescription(delegate_, frame); |
| 952 delegate_->printMessage(" - didFailProvisionalLoadWithError\n"); |
| 953 } |
| 954 LocationChangeDone(frame); |
| 955 return !frame->provisionalDataSource(); |
| 956 } |
| 957 |
| 958 void WebTestProxyBase::DidCommitProvisionalLoad(WebLocalFrame* frame, |
| 959 const WebHistoryItem&, |
| 960 blink::WebHistoryCommitType) { |
| 961 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 962 printFrameDescription(delegate_, frame); |
| 963 delegate_->printMessage(" - didCommitLoadForFrame\n"); |
| 964 } |
| 965 } |
| 966 |
| 967 void WebTestProxyBase::DidReceiveTitle(WebLocalFrame* frame, |
| 968 const WebString& title, |
| 969 WebTextDirection direction) { |
| 970 WebCString title8 = title.utf8(); |
| 971 |
| 972 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 973 printFrameDescription(delegate_, frame); |
| 974 delegate_->printMessage(string(" - didReceiveTitle: ") + title8.data() + |
| 975 "\n"); |
| 976 } |
| 977 |
| 978 if (test_interfaces_->testRunner()->shouldDumpTitleChanges()) |
| 979 delegate_->printMessage(string("TITLE CHANGED: '") + title8.data() + "'\n"); |
| 980 } |
| 981 |
| 982 void WebTestProxyBase::DidChangeIcon(WebLocalFrame* frame, WebIconURL::Type) { |
| 983 if (test_interfaces_->testRunner()->shouldDumpIconChanges()) { |
| 984 printFrameDescription(delegate_, frame); |
| 985 delegate_->printMessage(string(" - didChangeIcons\n")); |
| 986 } |
| 987 } |
| 988 |
| 989 void WebTestProxyBase::DidFinishDocumentLoad(WebLocalFrame* frame) { |
| 990 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 991 printFrameDescription(delegate_, frame); |
| 992 delegate_->printMessage(" - didFinishDocumentLoadForFrame\n"); |
| 993 } else { |
| 994 unsigned pendingUnloadEvents = frame->unloadListenerCount(); |
| 995 if (pendingUnloadEvents) { |
| 996 printFrameDescription(delegate_, frame); |
| 997 char buffer[100]; |
| 998 snprintf(buffer, sizeof(buffer), " - has %u onunload handler(s)\n", |
| 999 pendingUnloadEvents); |
| 1000 delegate_->printMessage(buffer); |
| 1001 } |
| 1002 } |
| 1003 } |
| 1004 |
| 1005 void WebTestProxyBase::DidHandleOnloadEvents(WebLocalFrame* frame) { |
| 1006 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1007 printFrameDescription(delegate_, frame); |
| 1008 delegate_->printMessage(" - didHandleOnloadEventsForFrame\n"); |
| 1009 } |
| 1010 } |
| 1011 |
| 1012 void WebTestProxyBase::DidFailLoad(WebLocalFrame* frame, const WebURLError&) { |
| 1013 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1014 printFrameDescription(delegate_, frame); |
| 1015 delegate_->printMessage(" - didFailLoadWithError\n"); |
| 1016 } |
| 1017 LocationChangeDone(frame); |
| 1018 } |
| 1019 |
| 1020 void WebTestProxyBase::DidFinishLoad(WebLocalFrame* frame) { |
| 1021 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1022 printFrameDescription(delegate_, frame); |
| 1023 delegate_->printMessage(" - didFinishLoadForFrame\n"); |
| 1024 } |
| 1025 LocationChangeDone(frame); |
| 1026 } |
| 1027 |
| 1028 void WebTestProxyBase::DidDetectXSS(WebLocalFrame*, const WebURL&, bool) { |
| 1029 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) |
| 1030 delegate_->printMessage("didDetectXSS\n"); |
| 1031 } |
| 1032 |
| 1033 void WebTestProxyBase::DidDispatchPingLoader(WebLocalFrame*, |
| 1034 const WebURL& url) { |
| 1035 if (test_interfaces_->testRunner()->shouldDumpPingLoaderCallbacks()) |
| 1036 delegate_->printMessage(string("PingLoader dispatched to '") + |
| 1037 URLDescription(url).c_str() + "'.\n"); |
| 1038 } |
| 1039 |
| 1040 void WebTestProxyBase::WillRequestResource( |
| 1041 WebLocalFrame* frame, const blink::WebCachedURLRequest& request) { |
| 1042 if (test_interfaces_->testRunner()->shouldDumpResourceRequestCallbacks()) { |
| 1043 printFrameDescription(delegate_, frame); |
| 1044 delegate_->printMessage(string(" - ") + |
| 1045 request.initiatorName().utf8().data()); |
| 1046 delegate_->printMessage(string(" requested '") + |
| 1047 URLDescription(request.urlRequest().url()).c_str() + |
| 1048 "'\n"); |
| 1049 } |
| 1050 } |
| 1051 |
| 1052 void WebTestProxyBase::WillSendRequest( |
| 1053 WebLocalFrame*, unsigned identifier, blink::WebURLRequest& request, |
| 1054 const blink::WebURLResponse& redirectResponse) { |
| 1055 // Need to use GURL for host() and SchemeIs() |
| 1056 GURL url = request.url(); |
| 1057 string requestURL = url.possibly_invalid_spec(); |
| 1058 |
| 1059 GURL mainDocumentURL = request.firstPartyForCookies(); |
| 1060 |
| 1061 if (redirectResponse.isNull() && |
| 1062 (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks() || |
| 1063 test_interfaces_->testRunner()->shouldDumpResourcePriorities())) { |
| 1064 DCHECK(resource_identifier_map_.find(identifier) == |
| 1065 resource_identifier_map_.end()); |
| 1066 resource_identifier_map_[identifier] = |
| 1067 descriptionSuitableForTestResult(requestURL); |
| 1068 } |
| 1069 |
| 1070 if (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1071 if (resource_identifier_map_.find(identifier) == |
| 1072 resource_identifier_map_.end()) |
| 1073 delegate_->printMessage("<unknown>"); |
| 1074 else |
| 1075 delegate_->printMessage(resource_identifier_map_[identifier]); |
| 1076 delegate_->printMessage(" - willSendRequest <NSURLRequest URL "); |
| 1077 delegate_->printMessage( |
| 1078 descriptionSuitableForTestResult(requestURL).c_str()); |
| 1079 delegate_->printMessage(", main document URL "); |
| 1080 delegate_->printMessage(URLDescription(mainDocumentURL).c_str()); |
| 1081 delegate_->printMessage(", http method "); |
| 1082 delegate_->printMessage(request.httpMethod().utf8().data()); |
| 1083 delegate_->printMessage("> redirectResponse "); |
| 1084 printResponseDescription(delegate_, redirectResponse); |
| 1085 delegate_->printMessage("\n"); |
| 1086 } |
| 1087 |
| 1088 if (test_interfaces_->testRunner()->shouldDumpResourcePriorities()) { |
| 1089 delegate_->printMessage( |
| 1090 descriptionSuitableForTestResult(requestURL).c_str()); |
| 1091 delegate_->printMessage(" has priority "); |
| 1092 delegate_->printMessage(PriorityDescription(request.priority())); |
| 1093 delegate_->printMessage("\n"); |
| 1094 } |
| 1095 |
| 1096 if (test_interfaces_->testRunner()->httpHeadersToClear()) { |
| 1097 const set<string>* clearHeaders = |
| 1098 test_interfaces_->testRunner()->httpHeadersToClear(); |
| 1099 for (set<string>::const_iterator header = clearHeaders->begin(); |
| 1100 header != clearHeaders->end(); ++header) |
| 1101 request.clearHTTPHeaderField(WebString::fromUTF8(*header)); |
| 1102 } |
| 1103 |
| 1104 string host = url.host(); |
| 1105 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { |
| 1106 if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host) && |
| 1107 ((!mainDocumentURL.SchemeIs("http") && |
| 1108 !mainDocumentURL.SchemeIs("https")) || |
| 1109 isLocalhost(mainDocumentURL.host())) && |
| 1110 !delegate_->allowExternalPages()) { |
| 1111 delegate_->printMessage(string("Blocked access to external URL ") + |
| 1112 requestURL + "\n"); |
| 1113 blockRequest(request); |
| 1114 return; |
| 1115 } |
| 1116 } |
| 1117 |
| 1118 // Set the new substituted URL. |
| 1119 request.setURL(delegate_->rewriteLayoutTestsURL(request.url().spec())); |
| 1120 } |
| 1121 |
| 1122 void WebTestProxyBase::DidReceiveResponse( |
| 1123 WebLocalFrame*, unsigned identifier, |
| 1124 const blink::WebURLResponse& response) { |
| 1125 if (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1126 if (resource_identifier_map_.find(identifier) == |
| 1127 resource_identifier_map_.end()) |
| 1128 delegate_->printMessage("<unknown>"); |
| 1129 else |
| 1130 delegate_->printMessage(resource_identifier_map_[identifier]); |
| 1131 delegate_->printMessage(" - didReceiveResponse "); |
| 1132 printResponseDescription(delegate_, response); |
| 1133 delegate_->printMessage("\n"); |
| 1134 } |
| 1135 if (test_interfaces_->testRunner()->shouldDumpResourceResponseMIMETypes()) { |
| 1136 GURL url = response.url(); |
| 1137 WebString mimeType = response.mimeType(); |
| 1138 delegate_->printMessage(url.ExtractFileName()); |
| 1139 delegate_->printMessage(" has MIME type "); |
| 1140 // Simulate NSURLResponse's mapping of empty/unknown MIME types to |
| 1141 // application/octet-stream |
| 1142 delegate_->printMessage(mimeType.isEmpty() ? "application/octet-stream" |
| 1143 : mimeType.utf8().data()); |
| 1144 delegate_->printMessage("\n"); |
| 1145 } |
| 1146 } |
| 1147 |
| 1148 void WebTestProxyBase::DidChangeResourcePriority( |
| 1149 WebLocalFrame*, unsigned identifier, |
| 1150 const blink::WebURLRequest::Priority& priority, int intra_priority_value) { |
| 1151 if (test_interfaces_->testRunner()->shouldDumpResourcePriorities()) { |
| 1152 if (resource_identifier_map_.find(identifier) == |
| 1153 resource_identifier_map_.end()) |
| 1154 delegate_->printMessage("<unknown>"); |
| 1155 else |
| 1156 delegate_->printMessage(resource_identifier_map_[identifier]); |
| 1157 delegate_->printMessage(" changed priority to "); |
| 1158 delegate_->printMessage(PriorityDescription(priority)); |
| 1159 char buffer[64]; |
| 1160 snprintf(buffer, sizeof(buffer), ", intra_priority %d", |
| 1161 intra_priority_value); |
| 1162 delegate_->printMessage(buffer); |
| 1163 delegate_->printMessage("\n"); |
| 1164 } |
| 1165 } |
| 1166 |
| 1167 void WebTestProxyBase::DidFinishResourceLoad(WebLocalFrame*, |
| 1168 unsigned identifier) { |
| 1169 if (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1170 if (resource_identifier_map_.find(identifier) == |
| 1171 resource_identifier_map_.end()) |
| 1172 delegate_->printMessage("<unknown>"); |
| 1173 else |
| 1174 delegate_->printMessage(resource_identifier_map_[identifier]); |
| 1175 delegate_->printMessage(" - didFinishLoading\n"); |
| 1176 } |
| 1177 resource_identifier_map_.erase(identifier); |
| 1178 } |
| 1179 |
| 1180 void WebTestProxyBase::DidAddMessageToConsole(const WebConsoleMessage& message, |
| 1181 const WebString& sourceName, |
| 1182 unsigned sourceLine) { |
| 1183 // This matches win DumpRenderTree's UIDelegate.cpp. |
| 1184 if (!log_console_output_) return; |
| 1185 string level; |
| 1186 switch (message.level) { |
| 1187 case WebConsoleMessage::LevelDebug: |
| 1188 level = "DEBUG"; |
| 1189 break; |
| 1190 case WebConsoleMessage::LevelLog: |
| 1191 level = "MESSAGE"; |
| 1192 break; |
| 1193 case WebConsoleMessage::LevelInfo: |
| 1194 level = "INFO"; |
| 1195 break; |
| 1196 case WebConsoleMessage::LevelWarning: |
| 1197 level = "WARNING"; |
| 1198 break; |
| 1199 case WebConsoleMessage::LevelError: |
| 1200 level = "ERROR"; |
| 1201 break; |
| 1202 } |
| 1203 delegate_->printMessage(string("CONSOLE ") + level + ": "); |
| 1204 if (sourceLine) { |
| 1205 char buffer[40]; |
| 1206 snprintf(buffer, sizeof(buffer), "line %d: ", sourceLine); |
| 1207 delegate_->printMessage(buffer); |
| 1208 } |
| 1209 if (!message.text.isEmpty()) { |
| 1210 string newMessage; |
| 1211 newMessage = message.text.utf8(); |
| 1212 size_t fileProtocol = newMessage.find("file://"); |
| 1213 if (fileProtocol != string::npos) { |
| 1214 newMessage = newMessage.substr(0, fileProtocol) + |
| 1215 urlSuitableForTestResult(newMessage.substr(fileProtocol)); |
| 1216 } |
| 1217 delegate_->printMessage(newMessage); |
| 1218 } |
| 1219 delegate_->printMessage(string("\n")); |
| 1220 } |
| 1221 |
| 1222 void WebTestProxyBase::LocationChangeDone(WebFrame* frame) { |
| 1223 if (frame != test_interfaces_->testRunner()->topLoadingFrame()) return; |
| 1224 test_interfaces_->testRunner()->setTopLoadingFrame(frame, true); |
| 1225 } |
| 1226 |
| 1227 WebNavigationPolicy WebTestProxyBase::DecidePolicyForNavigation( |
| 1228 WebLocalFrame*, WebDataSource::ExtraData*, const WebURLRequest& request, |
| 1229 WebNavigationType type, WebNavigationPolicy defaultPolicy, |
| 1230 bool isRedirect) { |
| 1231 WebNavigationPolicy result; |
| 1232 if (!test_interfaces_->testRunner()->policyDelegateEnabled()) |
| 1233 return defaultPolicy; |
| 1234 |
| 1235 delegate_->printMessage(string("Policy delegate: attempt to load ") + |
| 1236 URLDescription(request.url()) + |
| 1237 " with navigation type '" + |
| 1238 webNavigationTypeToString(type) + "'\n"); |
| 1239 if (test_interfaces_->testRunner()->policyDelegateIsPermissive()) |
| 1240 result = blink::WebNavigationPolicyCurrentTab; |
| 1241 else |
| 1242 result = blink::WebNavigationPolicyIgnore; |
| 1243 |
| 1244 if (test_interfaces_->testRunner()->policyDelegateShouldNotifyDone()) |
| 1245 test_interfaces_->testRunner()->policyDelegateDone(); |
| 1246 return result; |
| 1247 } |
| 1248 |
| 1249 bool WebTestProxyBase::WillCheckAndDispatchMessageEvent(WebLocalFrame*, |
| 1250 WebFrame*, |
| 1251 WebSecurityOrigin, |
| 1252 WebDOMMessageEvent) { |
| 1253 if (test_interfaces_->testRunner()->shouldInterceptPostMessage()) { |
| 1254 delegate_->printMessage("intercepted postMessage\n"); |
888 return true; | 1255 return true; |
889 } | 1256 } |
890 | 1257 |
891 WebPlugin* WebTestProxyBase::createPlugin(WebLocalFrame* frame, const WebPluginP
arams& params) | 1258 return false; |
892 { | 1259 } |
893 if (TestPlugin::isSupportedMimeType(params.mimeType)) | 1260 |
894 return TestPlugin::create(frame, params, m_delegate); | 1261 void WebTestProxyBase::PostSpellCheckEvent(const WebString& eventName) { |
895 return 0; | 1262 if (test_interfaces_->testRunner()->shouldDumpSpellCheckCallbacks()) { |
896 } | 1263 delegate_->printMessage(string("SpellCheckEvent: ") + |
897 | 1264 eventName.utf8().data() + "\n"); |
898 void WebTestProxyBase::setStatusText(const WebString& text) | 1265 } |
899 { | 1266 } |
900 if (!m_testInterfaces->testRunner()->shouldDumpStatusCallbacks()) | 1267 |
901 return; | 1268 void WebTestProxyBase::ResetInputMethod() { |
902 m_delegate->printMessage(string("UI DELEGATE STATUS CALLBACK: setStatusText:
") + text.utf8().data() + "\n"); | 1269 // If a composition text exists, then we need to let the browser process |
903 } | 1270 // to cancel the input method's ongoing composition session. |
904 | 1271 if (web_widget_) web_widget_->confirmComposition(); |
905 void WebTestProxyBase::didStopLoading() | |
906 { | |
907 if (m_testInterfaces->testRunner()->shouldDumpProgressFinishedCallback()) | |
908 m_delegate->printMessage("postProgressFinishedNotification\n"); | |
909 } | |
910 | |
911 void WebTestProxyBase::showContextMenu(WebLocalFrame*, const WebContextMenuData&
contextMenuData) | |
912 { | |
913 m_testInterfaces->eventSender()->SetContextMenuData(contextMenuData); | |
914 } | |
915 | |
916 WebUserMediaClient* WebTestProxyBase::userMediaClient() | |
917 { | |
918 if (!m_userMediaClient.get()) | |
919 m_userMediaClient.reset(new WebUserMediaClientMock(m_delegate)); | |
920 return m_userMediaClient.get(); | |
921 } | |
922 | |
923 // Simulate a print by going into print mode and then exit straight away. | |
924 void WebTestProxyBase::printPage(WebLocalFrame* frame) | |
925 { | |
926 WebSize pageSizeInPixels = webWidget()->size(); | |
927 if (pageSizeInPixels.isEmpty()) | |
928 return; | |
929 WebPrintParams printParams(pageSizeInPixels); | |
930 frame->printBegin(printParams); | |
931 frame->printEnd(); | |
932 } | |
933 | |
934 WebNotificationPresenter* WebTestProxyBase::notificationPresenter() | |
935 { | |
936 return m_testInterfaces->testRunner()->notification_presenter(); | |
937 } | |
938 | |
939 WebMIDIClient* WebTestProxyBase::webMIDIClient() | |
940 { | |
941 return midiClientMock(); | |
942 } | |
943 | |
944 WebSpeechRecognizer* WebTestProxyBase::speechRecognizer() | |
945 { | |
946 return speechRecognizerMock(); | |
947 } | |
948 | |
949 bool WebTestProxyBase::requestPointerLock() | |
950 { | |
951 return m_testInterfaces->testRunner()->RequestPointerLock(); | |
952 } | |
953 | |
954 void WebTestProxyBase::requestPointerUnlock() | |
955 { | |
956 m_testInterfaces->testRunner()->RequestPointerUnlock(); | |
957 } | |
958 | |
959 bool WebTestProxyBase::isPointerLocked() | |
960 { | |
961 return m_testInterfaces->testRunner()->isPointerLocked(); | |
962 } | |
963 | |
964 void WebTestProxyBase::didFocus() | |
965 { | |
966 m_delegate->setFocus(this, true); | |
967 } | |
968 | |
969 void WebTestProxyBase::didBlur() | |
970 { | |
971 m_delegate->setFocus(this, false); | |
972 } | |
973 | |
974 void WebTestProxyBase::setToolTipText(const WebString& text, WebTextDirection) | |
975 { | |
976 m_testInterfaces->testRunner()->setToolTipText(text); | |
977 } | |
978 | |
979 void WebTestProxyBase::didOpenChooser() | |
980 { | |
981 m_chooserCount++; | |
982 } | |
983 | |
984 void WebTestProxyBase::didCloseChooser() | |
985 { | |
986 m_chooserCount--; | |
987 } | |
988 | |
989 bool WebTestProxyBase::isChooserShown() | |
990 { | |
991 return 0 < m_chooserCount; | |
992 } | |
993 | |
994 void WebTestProxyBase::loadURLExternally(WebLocalFrame* frame, const WebURLReque
st& request, WebNavigationPolicy policy, const WebString& suggested_name) | |
995 { | |
996 if (m_testInterfaces->testRunner()->shouldWaitUntilExternalURLLoad()) { | |
997 if (policy == WebNavigationPolicyDownload) { | |
998 m_delegate->printMessage(string("Downloading URL with suggested file
name \"") + suggested_name.utf8() + "\"\n"); | |
999 } else { | |
1000 m_delegate->printMessage(string("Loading URL externally - \"") + URL
Description(request.url()) + "\"\n"); | |
1001 } | |
1002 m_delegate->testFinished(); | |
1003 } | |
1004 } | |
1005 | |
1006 void WebTestProxyBase::didStartProvisionalLoad(WebLocalFrame* frame) | |
1007 { | |
1008 if (!m_testInterfaces->testRunner()->topLoadingFrame()) | |
1009 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, false); | |
1010 | |
1011 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1012 printFrameDescription(m_delegate, frame); | |
1013 m_delegate->printMessage(" - didStartProvisionalLoadForFrame\n"); | |
1014 } | |
1015 | |
1016 if (m_testInterfaces->testRunner()->shouldDumpUserGestureInFrameLoadCallback
s()) | |
1017 printFrameUserGestureStatus(m_delegate, frame, " - in didStartProvisiona
lLoadForFrame\n"); | |
1018 } | |
1019 | |
1020 void WebTestProxyBase::didReceiveServerRedirectForProvisionalLoad(WebLocalFrame*
frame) | |
1021 { | |
1022 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1023 printFrameDescription(m_delegate, frame); | |
1024 m_delegate->printMessage(" - didReceiveServerRedirectForProvisionalLoadF
orFrame\n"); | |
1025 } | |
1026 } | |
1027 | |
1028 bool WebTestProxyBase::didFailProvisionalLoad(WebLocalFrame* frame, const WebURL
Error&) | |
1029 { | |
1030 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1031 printFrameDescription(m_delegate, frame); | |
1032 m_delegate->printMessage(" - didFailProvisionalLoadWithError\n"); | |
1033 } | |
1034 locationChangeDone(frame); | |
1035 return !frame->provisionalDataSource(); | |
1036 } | |
1037 | |
1038 void WebTestProxyBase::didCommitProvisionalLoad(WebLocalFrame* frame, const WebH
istoryItem&, blink::WebHistoryCommitType) | |
1039 { | |
1040 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1041 printFrameDescription(m_delegate, frame); | |
1042 m_delegate->printMessage(" - didCommitLoadForFrame\n"); | |
1043 } | |
1044 } | |
1045 | |
1046 void WebTestProxyBase::didReceiveTitle(WebLocalFrame* frame, const WebString& ti
tle, WebTextDirection direction) | |
1047 { | |
1048 WebCString title8 = title.utf8(); | |
1049 | |
1050 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1051 printFrameDescription(m_delegate, frame); | |
1052 m_delegate->printMessage(string(" - didReceiveTitle: ") + title8.data()
+ "\n"); | |
1053 } | |
1054 | |
1055 if (m_testInterfaces->testRunner()->shouldDumpTitleChanges()) | |
1056 m_delegate->printMessage(string("TITLE CHANGED: '") + title8.data() + "'
\n"); | |
1057 } | |
1058 | |
1059 void WebTestProxyBase::didChangeIcon(WebLocalFrame* frame, WebIconURL::Type) | |
1060 { | |
1061 if (m_testInterfaces->testRunner()->shouldDumpIconChanges()) { | |
1062 printFrameDescription(m_delegate, frame); | |
1063 m_delegate->printMessage(string(" - didChangeIcons\n")); | |
1064 } | |
1065 } | |
1066 | |
1067 void WebTestProxyBase::didFinishDocumentLoad(WebLocalFrame* frame) | |
1068 { | |
1069 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1070 printFrameDescription(m_delegate, frame); | |
1071 m_delegate->printMessage(" - didFinishDocumentLoadForFrame\n"); | |
1072 } else { | |
1073 unsigned pendingUnloadEvents = frame->unloadListenerCount(); | |
1074 if (pendingUnloadEvents) { | |
1075 printFrameDescription(m_delegate, frame); | |
1076 char buffer[100]; | |
1077 snprintf(buffer, sizeof(buffer), " - has %u onunload handler(s)\n",
pendingUnloadEvents); | |
1078 m_delegate->printMessage(buffer); | |
1079 } | |
1080 } | |
1081 } | |
1082 | |
1083 void WebTestProxyBase::didHandleOnloadEvents(WebLocalFrame* frame) | |
1084 { | |
1085 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1086 printFrameDescription(m_delegate, frame); | |
1087 m_delegate->printMessage(" - didHandleOnloadEventsForFrame\n"); | |
1088 } | |
1089 } | |
1090 | |
1091 void WebTestProxyBase::didFailLoad(WebLocalFrame* frame, const WebURLError&) | |
1092 { | |
1093 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1094 printFrameDescription(m_delegate, frame); | |
1095 m_delegate->printMessage(" - didFailLoadWithError\n"); | |
1096 } | |
1097 locationChangeDone(frame); | |
1098 } | |
1099 | |
1100 void WebTestProxyBase::didFinishLoad(WebLocalFrame* frame) | |
1101 { | |
1102 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { | |
1103 printFrameDescription(m_delegate, frame); | |
1104 m_delegate->printMessage(" - didFinishLoadForFrame\n"); | |
1105 } | |
1106 locationChangeDone(frame); | |
1107 } | |
1108 | |
1109 void WebTestProxyBase::didDetectXSS(WebLocalFrame*, const WebURL&, bool) | |
1110 { | |
1111 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) | |
1112 m_delegate->printMessage("didDetectXSS\n"); | |
1113 } | |
1114 | |
1115 void WebTestProxyBase::didDispatchPingLoader(WebLocalFrame*, const WebURL& url) | |
1116 { | |
1117 if (m_testInterfaces->testRunner()->shouldDumpPingLoaderCallbacks()) | |
1118 m_delegate->printMessage(string("PingLoader dispatched to '") + URLDescr
iption(url).c_str() + "'.\n"); | |
1119 } | |
1120 | |
1121 void WebTestProxyBase::willRequestResource(WebLocalFrame* frame, const blink::We
bCachedURLRequest& request) | |
1122 { | |
1123 if (m_testInterfaces->testRunner()->shouldDumpResourceRequestCallbacks()) { | |
1124 printFrameDescription(m_delegate, frame); | |
1125 m_delegate->printMessage(string(" - ") + request.initiatorName().utf8().
data()); | |
1126 m_delegate->printMessage(string(" requested '") + URLDescription(request
.urlRequest().url()).c_str() + "'\n"); | |
1127 } | |
1128 } | |
1129 | |
1130 void WebTestProxyBase::willSendRequest(WebLocalFrame*, unsigned identifier, blin
k::WebURLRequest& request, const blink::WebURLResponse& redirectResponse) | |
1131 { | |
1132 // Need to use GURL for host() and SchemeIs() | |
1133 GURL url = request.url(); | |
1134 string requestURL = url.possibly_invalid_spec(); | |
1135 | |
1136 GURL mainDocumentURL = request.firstPartyForCookies(); | |
1137 | |
1138 if (redirectResponse.isNull() && (m_testInterfaces->testRunner()->shouldDump
ResourceLoadCallbacks() || m_testInterfaces->testRunner()->shouldDumpResourcePri
orities())) { | |
1139 DCHECK(m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierM
ap.end()); | |
1140 m_resourceIdentifierMap[identifier] = descriptionSuitableForTestResult(r
equestURL); | |
1141 } | |
1142 | |
1143 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { | |
1144 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) | |
1145 m_delegate->printMessage("<unknown>"); | |
1146 else | |
1147 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); | |
1148 m_delegate->printMessage(" - willSendRequest <NSURLRequest URL "); | |
1149 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_
str()); | |
1150 m_delegate->printMessage(", main document URL "); | |
1151 m_delegate->printMessage(URLDescription(mainDocumentURL).c_str()); | |
1152 m_delegate->printMessage(", http method "); | |
1153 m_delegate->printMessage(request.httpMethod().utf8().data()); | |
1154 m_delegate->printMessage("> redirectResponse "); | |
1155 printResponseDescription(m_delegate, redirectResponse); | |
1156 m_delegate->printMessage("\n"); | |
1157 } | |
1158 | |
1159 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) { | |
1160 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_
str()); | |
1161 m_delegate->printMessage(" has priority "); | |
1162 m_delegate->printMessage(PriorityDescription(request.priority())); | |
1163 m_delegate->printMessage("\n"); | |
1164 } | |
1165 | |
1166 if (m_testInterfaces->testRunner()->httpHeadersToClear()) { | |
1167 const set<string> *clearHeaders = m_testInterfaces->testRunner()->httpHe
adersToClear(); | |
1168 for (set<string>::const_iterator header = clearHeaders->begin(); header
!= clearHeaders->end(); ++header) | |
1169 request.clearHTTPHeaderField(WebString::fromUTF8(*header)); | |
1170 } | |
1171 | |
1172 string host = url.host(); | |
1173 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { | |
1174 if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host) | |
1175 && ((!mainDocumentURL.SchemeIs("http") && !mainDocumentURL.SchemeIs(
"https")) || isLocalhost(mainDocumentURL.host())) | |
1176 && !m_delegate->allowExternalPages()) { | |
1177 m_delegate->printMessage(string("Blocked access to external URL ") +
requestURL + "\n"); | |
1178 blockRequest(request); | |
1179 return; | |
1180 } | |
1181 } | |
1182 | |
1183 // Set the new substituted URL. | |
1184 request.setURL(m_delegate->rewriteLayoutTestsURL(request.url().spec())); | |
1185 } | |
1186 | |
1187 void WebTestProxyBase::didReceiveResponse(WebLocalFrame*, unsigned identifier, c
onst blink::WebURLResponse& response) | |
1188 { | |
1189 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { | |
1190 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) | |
1191 m_delegate->printMessage("<unknown>"); | |
1192 else | |
1193 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); | |
1194 m_delegate->printMessage(" - didReceiveResponse "); | |
1195 printResponseDescription(m_delegate, response); | |
1196 m_delegate->printMessage("\n"); | |
1197 } | |
1198 if (m_testInterfaces->testRunner()->shouldDumpResourceResponseMIMETypes()) { | |
1199 GURL url = response.url(); | |
1200 WebString mimeType = response.mimeType(); | |
1201 m_delegate->printMessage(url.ExtractFileName()); | |
1202 m_delegate->printMessage(" has MIME type "); | |
1203 // Simulate NSURLResponse's mapping of empty/unknown MIME types to appli
cation/octet-stream | |
1204 m_delegate->printMessage(mimeType.isEmpty() ? "application/octet-stream"
: mimeType.utf8().data()); | |
1205 m_delegate->printMessage("\n"); | |
1206 } | |
1207 } | |
1208 | |
1209 void WebTestProxyBase::didChangeResourcePriority(WebLocalFrame*, unsigned identi
fier, const blink::WebURLRequest::Priority& priority, int intra_priority_value) | |
1210 { | |
1211 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) { | |
1212 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) | |
1213 m_delegate->printMessage("<unknown>"); | |
1214 else | |
1215 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); | |
1216 m_delegate->printMessage(" changed priority to "); | |
1217 m_delegate->printMessage(PriorityDescription(priority)); | |
1218 char buffer[64]; | |
1219 snprintf(buffer, sizeof(buffer), ", intra_priority %d", intra_priority_v
alue); | |
1220 m_delegate->printMessage(buffer); | |
1221 m_delegate->printMessage("\n"); | |
1222 } | |
1223 } | |
1224 | |
1225 void WebTestProxyBase::didFinishResourceLoad(WebLocalFrame*, unsigned identifier
) | |
1226 { | |
1227 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { | |
1228 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) | |
1229 m_delegate->printMessage("<unknown>"); | |
1230 else | |
1231 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); | |
1232 m_delegate->printMessage(" - didFinishLoading\n"); | |
1233 } | |
1234 m_resourceIdentifierMap.erase(identifier); | |
1235 } | |
1236 | |
1237 void WebTestProxyBase::didAddMessageToConsole(const WebConsoleMessage& message,
const WebString& sourceName, unsigned sourceLine) | |
1238 { | |
1239 // This matches win DumpRenderTree's UIDelegate.cpp. | |
1240 if (!m_logConsoleOutput) | |
1241 return; | |
1242 string level; | |
1243 switch (message.level) { | |
1244 case WebConsoleMessage::LevelDebug: | |
1245 level = "DEBUG"; | |
1246 break; | |
1247 case WebConsoleMessage::LevelLog: | |
1248 level = "MESSAGE"; | |
1249 break; | |
1250 case WebConsoleMessage::LevelInfo: | |
1251 level = "INFO"; | |
1252 break; | |
1253 case WebConsoleMessage::LevelWarning: | |
1254 level = "WARNING"; | |
1255 break; | |
1256 case WebConsoleMessage::LevelError: | |
1257 level = "ERROR"; | |
1258 break; | |
1259 } | |
1260 m_delegate->printMessage(string("CONSOLE ") + level + ": "); | |
1261 if (sourceLine) { | |
1262 char buffer[40]; | |
1263 snprintf(buffer, sizeof(buffer), "line %d: ", sourceLine); | |
1264 m_delegate->printMessage(buffer); | |
1265 } | |
1266 if (!message.text.isEmpty()) { | |
1267 string newMessage; | |
1268 newMessage = message.text.utf8(); | |
1269 size_t fileProtocol = newMessage.find("file://"); | |
1270 if (fileProtocol != string::npos) { | |
1271 newMessage = newMessage.substr(0, fileProtocol) | |
1272 + urlSuitableForTestResult(newMessage.substr(fileProtocol)); | |
1273 } | |
1274 m_delegate->printMessage(newMessage); | |
1275 } | |
1276 m_delegate->printMessage(string("\n")); | |
1277 } | |
1278 | |
1279 void WebTestProxyBase::locationChangeDone(WebFrame* frame) | |
1280 { | |
1281 if (frame != m_testInterfaces->testRunner()->topLoadingFrame()) | |
1282 return; | |
1283 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, true); | |
1284 } | |
1285 | |
1286 WebNavigationPolicy WebTestProxyBase::decidePolicyForNavigation(WebLocalFrame*,
WebDataSource::ExtraData*, const WebURLRequest& request, WebNavigationType type,
WebNavigationPolicy defaultPolicy, bool isRedirect) | |
1287 { | |
1288 WebNavigationPolicy result; | |
1289 if (!m_testInterfaces->testRunner()->policyDelegateEnabled()) | |
1290 return defaultPolicy; | |
1291 | |
1292 m_delegate->printMessage(string("Policy delegate: attempt to load ") + URLDe
scription(request.url()) + " with navigation type '" + webNavigationTypeToString
(type) + "'\n"); | |
1293 if (m_testInterfaces->testRunner()->policyDelegateIsPermissive()) | |
1294 result = blink::WebNavigationPolicyCurrentTab; | |
1295 else | |
1296 result = blink::WebNavigationPolicyIgnore; | |
1297 | |
1298 if (m_testInterfaces->testRunner()->policyDelegateShouldNotifyDone()) | |
1299 m_testInterfaces->testRunner()->policyDelegateDone(); | |
1300 return result; | |
1301 } | |
1302 | |
1303 bool WebTestProxyBase::willCheckAndDispatchMessageEvent(WebLocalFrame*, WebFrame
*, WebSecurityOrigin, WebDOMMessageEvent) | |
1304 { | |
1305 if (m_testInterfaces->testRunner()->shouldInterceptPostMessage()) { | |
1306 m_delegate->printMessage("intercepted postMessage\n"); | |
1307 return true; | |
1308 } | |
1309 | |
1310 return false; | |
1311 } | |
1312 | |
1313 void WebTestProxyBase::postSpellCheckEvent(const WebString& eventName) | |
1314 { | |
1315 if (m_testInterfaces->testRunner()->shouldDumpSpellCheckCallbacks()) { | |
1316 m_delegate->printMessage(string("SpellCheckEvent: ") + eventName.utf8().
data() + "\n"); | |
1317 } | |
1318 } | |
1319 | |
1320 void WebTestProxyBase::resetInputMethod() | |
1321 { | |
1322 // If a composition text exists, then we need to let the browser process | |
1323 // to cancel the input method's ongoing composition session. | |
1324 if (m_webWidget) | |
1325 m_webWidget->confirmComposition(); | |
1326 } | 1272 } |
1327 | 1273 |
1328 } // namespace content | 1274 } // namespace content |
OLD | NEW |