OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/shell/renderer/test_runner/WebTestProxy.h" | |
6 | |
7 #include <cctype> | |
8 | |
9 #include "base/callback_helpers.h" | |
10 #include "base/debug/trace_event.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" | |
14 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" | |
15 #include "content/shell/renderer/test_runner/SpellCheckClient.h" | |
16 #include "content/shell/renderer/test_runner/TestCommon.h" | |
17 #include "content/shell/renderer/test_runner/TestInterfaces.h" | |
18 #include "content/shell/renderer/test_runner/TestPlugin.h" | |
19 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
20 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" | |
21 #include "content/shell/renderer/test_runner/WebTestRunner.h" | |
22 #include "content/shell/renderer/test_runner/WebUserMediaClientMock.h" | |
23 #include "content/shell/renderer/test_runner/accessibility_controller.h" | |
24 #include "content/shell/renderer/test_runner/test_runner.h" | |
25 // FIXME: Including platform_canvas.h here is a layering violation. | |
26 #include "skia/ext/platform_canvas.h" | |
27 #include "third_party/WebKit/public/platform/WebCString.h" | |
28 #include "third_party/WebKit/public/platform/WebURLError.h" | |
29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
30 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
31 #include "third_party/WebKit/public/web/WebAXEnums.h" | |
32 #include "third_party/WebKit/public/web/WebAXObject.h" | |
33 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" | |
34 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | |
35 #include "third_party/WebKit/public/web/WebDataSource.h" | |
36 #include "third_party/WebKit/public/web/WebDocument.h" | |
37 #include "third_party/WebKit/public/web/WebElement.h" | |
38 #include "third_party/WebKit/public/web/WebHistoryItem.h" | |
39 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
40 #include "third_party/WebKit/public/web/WebMIDIClientMock.h" | |
41 #include "third_party/WebKit/public/web/WebNode.h" | |
42 #include "third_party/WebKit/public/web/WebPluginParams.h" | |
43 #include "third_party/WebKit/public/web/WebPrintParams.h" | |
44 #include "third_party/WebKit/public/web/WebRange.h" | |
45 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
46 #include "third_party/WebKit/public/web/WebView.h" | |
47 | |
48 using namespace blink; | |
49 using namespace std; | |
50 | |
51 namespace content { | |
52 | |
53 namespace { | |
54 | |
55 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { | |
56 public: | |
57 typedef void (WebTestProxyBase::*CallbackMethodType)(); | |
58 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) | |
59 : WebMethodTask<WebTestProxyBase>(object) | |
60 , m_callback(callback) | |
61 { } | |
62 | |
63 virtual void runIfValid() OVERRIDE { (m_object->*m_callback)(); } | |
64 | |
65 private: | |
66 CallbackMethodType m_callback; | |
67 }; | |
68 | |
69 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) | |
70 { | |
71 string name8 = frame->uniqueName().utf8(); | |
72 if (frame == frame->view()->mainFrame()) { | |
73 if (!name8.length()) { | |
74 delegate->printMessage("main frame"); | |
75 return; | |
76 } | |
77 delegate->printMessage(string("main frame \"") + name8 + "\""); | |
78 return; | |
79 } | |
80 if (!name8.length()) { | |
81 delegate->printMessage("frame (anonymous)"); | |
82 return; | |
83 } | |
84 delegate->printMessage(string("frame \"") + name8 + "\""); | |
85 } | |
86 | |
87 void printFrameUserGestureStatus(WebTestDelegate* delegate, WebFrame* frame, con
st char* msg) | |
88 { | |
89 bool isUserGesture = WebUserGestureIndicator::isProcessingUserGesture(); | |
90 delegate->printMessage(string("Frame with user gesture \"") + (isUserGesture
? "true" : "false") + "\"" + msg); | |
91 } | |
92 | |
93 // Used to write a platform neutral file:/// URL by taking the | |
94 // filename and its directory. (e.g., converts | |
95 // "file:///tmp/foo/bar.txt" to just "bar.txt"). | |
96 string descriptionSuitableForTestResult(const string& url) | |
97 { | |
98 if (url.empty() || string::npos == url.find("file://")) | |
99 return url; | |
100 | |
101 size_t pos = url.rfind('/'); | |
102 if (pos == string::npos || !pos) | |
103 return "ERROR:" + url; | |
104 pos = url.rfind('/', pos - 1); | |
105 if (pos == string::npos) | |
106 return "ERROR:" + url; | |
107 | |
108 return url.substr(pos + 1); | |
109 } | |
110 | |
111 void printResponseDescription(WebTestDelegate* delegate, const WebURLResponse& r
esponse) | |
112 { | |
113 if (response.isNull()) { | |
114 delegate->printMessage("(null)"); | |
115 return; | |
116 } | |
117 string url = response.url().spec(); | |
118 char data[100]; | |
119 snprintf(data, sizeof(data), "%d", response. httpStatusCode()); | |
120 delegate->printMessage(string("<NSURLResponse ") + descriptionSuitableForTes
tResult(url) + ", http status code " + data + ">"); | |
121 } | |
122 | |
123 string URLDescription(const GURL& url) | |
124 { | |
125 if (url.SchemeIs("file")) | |
126 return url.ExtractFileName(); | |
127 return url.possibly_invalid_spec(); | |
128 } | |
129 | |
130 string PriorityDescription(const WebURLRequest::Priority& priority) | |
131 { | |
132 switch (priority) { | |
133 case WebURLRequest::PriorityVeryLow: | |
134 return "VeryLow"; | |
135 case WebURLRequest::PriorityLow: | |
136 return "Low"; | |
137 case WebURLRequest::PriorityMedium: | |
138 return "Medium"; | |
139 case WebURLRequest::PriorityHigh: | |
140 return "High"; | |
141 case WebURLRequest::PriorityVeryHigh: | |
142 return "VeryHigh"; | |
143 case WebURLRequest::PriorityUnresolved: | |
144 default: | |
145 return "Unresolved"; | |
146 } | |
147 } | |
148 | |
149 void blockRequest(WebURLRequest& request) | |
150 { | |
151 request.setURL(GURL("255.255.255.255")); | |
152 } | |
153 | |
154 bool isLocalhost(const string& host) | |
155 { | |
156 return host == "127.0.0.1" || host == "localhost"; | |
157 } | |
158 | |
159 bool hostIsUsedBySomeTestsToGenerateError(const string& host) | |
160 { | |
161 return host == "255.255.255.255"; | |
162 } | |
163 | |
164 // 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"). | |
166 string urlSuitableForTestResult(const string& url) | |
167 { | |
168 if (url.empty() || string::npos == url.find("file://")) | |
169 return url; | |
170 | |
171 size_t pos = url.rfind('/'); | |
172 if (pos == string::npos) { | |
173 #ifdef WIN32 | |
174 pos = url.rfind('\\'); | |
175 if (pos == string::npos) | |
176 pos = 0; | |
177 #else | |
178 pos = 0; | |
179 #endif | |
180 } | |
181 string filename = url.substr(pos + 1); | |
182 if (filename.empty()) | |
183 return "file:"; // A WebKit test has this in its expected output. | |
184 return filename; | |
185 } | |
186 | |
187 // WebNavigationType debugging strings taken from PolicyDelegate.mm. | |
188 const char* linkClickedString = "link clicked"; | |
189 const char* formSubmittedString = "form submitted"; | |
190 const char* backForwardString = "back/forward"; | |
191 const char* reloadString = "reload"; | |
192 const char* formResubmittedString = "form resubmitted"; | |
193 const char* otherString = "other"; | |
194 const char* illegalString = "illegal value"; | |
195 | |
196 // Get a debugging string from a WebNavigationType. | |
197 const char* webNavigationTypeToString(WebNavigationType type) | |
198 { | |
199 switch (type) { | |
200 case blink::WebNavigationTypeLinkClicked: | |
201 return linkClickedString; | |
202 case blink::WebNavigationTypeFormSubmitted: | |
203 return formSubmittedString; | |
204 case blink::WebNavigationTypeBackForward: | |
205 return backForwardString; | |
206 case blink::WebNavigationTypeReload: | |
207 return reloadString; | |
208 case blink::WebNavigationTypeFormResubmitted: | |
209 return formResubmittedString; | |
210 case blink::WebNavigationTypeOther: | |
211 return otherString; | |
212 } | |
213 return illegalString; | |
214 } | |
215 | |
216 string dumpDocumentText(WebFrame* frame) | |
217 { | |
218 // We use the document element's text instead of the body text here because | |
219 // not all documents have a body, such as XML documents. | |
220 WebElement documentElement = frame->document().documentElement(); | |
221 if (documentElement.isNull()) | |
222 return string(); | |
223 return documentElement.innerText().utf8(); | |
224 } | |
225 | |
226 string dumpFramesAsText(WebFrame* frame, bool recursive) | |
227 { | |
228 string result; | |
229 | |
230 // Add header for all but the main frame. Skip empty frames. | |
231 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
232 result.append("\n--------\nFrame: '"); | |
233 result.append(frame->uniqueName().utf8().data()); | |
234 result.append("'\n--------\n"); | |
235 } | |
236 | |
237 result.append(dumpDocumentText(frame)); | |
238 result.append("\n"); | |
239 | |
240 if (recursive) { | |
241 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) | |
242 result.append(dumpFramesAsText(child, recursive)); | |
243 } | |
244 | |
245 return result; | |
246 } | |
247 | |
248 string dumpFramesAsPrintedText(WebFrame* frame, bool recursive) | |
249 { | |
250 string result; | |
251 | |
252 // Cannot do printed format for anything other than HTML | |
253 if (!frame->document().isHTMLDocument()) | |
254 return string(); | |
255 | |
256 // Add header for all but the main frame. Skip empty frames. | |
257 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
258 result.append("\n--------\nFrame: '"); | |
259 result.append(frame->uniqueName().utf8().data()); | |
260 result.append("'\n--------\n"); | |
261 } | |
262 | |
263 result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8()
); | |
264 result.append("\n"); | |
265 | |
266 if (recursive) { | |
267 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) | |
268 result.append(dumpFramesAsPrintedText(child, recursive)); | |
269 } | |
270 | |
271 return result; | |
272 } | |
273 | |
274 string dumpFrameScrollPosition(WebFrame* frame, bool recursive) | |
275 { | |
276 string result; | |
277 WebSize offset = frame->scrollOffset(); | |
278 if (offset.width > 0 || offset.height > 0) { | |
279 if (frame->parent()) | |
280 result = string("frame '") + frame->uniqueName().utf8().data() + "'
"; | |
281 char data[100]; | |
282 snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset
.height); | |
283 result += data; | |
284 } | |
285 | |
286 if (!recursive) | |
287 return result; | |
288 for (WebFrame* child = frame->firstChild(); child; child = child->nextSiblin
g()) | |
289 result += dumpFrameScrollPosition(child, recursive); | |
290 return result; | |
291 } | |
292 | |
293 string dumpAllBackForwardLists(TestInterfaces* interfaces, WebTestDelegate* dele
gate) | |
294 { | |
295 string result; | |
296 const vector<WebTestProxyBase*>& windowList = interfaces->windowList(); | |
297 for (unsigned i = 0; i < windowList.size(); ++i) | |
298 result.append(delegate->dumpHistoryForWindow(windowList.at(i))); | |
299 return result; | |
300 } | |
301 | |
302 } | |
303 | |
304 WebTestProxyBase::WebTestProxyBase() | |
305 : m_testInterfaces(0) | |
306 , m_delegate(0) | |
307 , m_webWidget(0) | |
308 , m_spellcheck(new SpellCheckClient(this)) | |
309 , m_chooserCount(0) | |
310 { | |
311 reset(); | |
312 } | |
313 | |
314 WebTestProxyBase::~WebTestProxyBase() | |
315 { | |
316 m_testInterfaces->windowClosed(this); | |
317 } | |
318 | |
319 void WebTestProxyBase::setInterfaces(WebTestInterfaces* interfaces) | |
320 { | |
321 m_testInterfaces = interfaces->testInterfaces(); | |
322 m_testInterfaces->windowOpened(this); | |
323 } | |
324 | |
325 void WebTestProxyBase::setDelegate(WebTestDelegate* delegate) | |
326 { | |
327 m_delegate = delegate; | |
328 m_spellcheck->setDelegate(delegate); | |
329 if (m_speechRecognizer.get()) | |
330 m_speechRecognizer->setDelegate(delegate); | |
331 } | |
332 | |
333 void WebTestProxyBase::setWidget(WebWidget* widget) | |
334 { | |
335 m_webWidget = widget; | |
336 } | |
337 | |
338 WebWidget* WebTestProxyBase::webWidget() | |
339 { | |
340 return m_webWidget; | |
341 } | |
342 | |
343 WebView* WebTestProxyBase::webView() | |
344 { | |
345 DCHECK(m_webWidget); | |
346 // TestRunner does not support popup widgets. So m_webWidget is always a Web
View. | |
347 return static_cast<WebView*>(m_webWidget); | |
348 } | |
349 | |
350 void WebTestProxyBase::didForceResize() | |
351 { | |
352 invalidateAll(); | |
353 discardBackingStore(); | |
354 } | |
355 | |
356 void WebTestProxyBase::reset() | |
357 { | |
358 m_paintRect = WebRect(); | |
359 m_canvas.reset(); | |
360 m_isPainting = false; | |
361 m_animateScheduled = false; | |
362 m_resourceIdentifierMap.clear(); | |
363 m_logConsoleOutput = true; | |
364 if (m_midiClient.get()) | |
365 m_midiClient->resetMock(); | |
366 } | |
367 | |
368 WebSpellCheckClient* WebTestProxyBase::spellCheckClient() const | |
369 { | |
370 return m_spellcheck.get(); | |
371 } | |
372 | |
373 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli
ent, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggest
ion>& suggestions) | |
374 { | |
375 // This instance is deleted by WebCore::ColorInputType | |
376 return new MockColorChooser(client, m_delegate, this); | |
377 } | |
378 | |
379 bool WebTestProxyBase::runFileChooser(const blink::WebFileChooserParams&, blink:
:WebFileChooserCompletion*) | |
380 { | |
381 m_delegate->printMessage("Mock: Opening a file chooser.\n"); | |
382 // FIXME: Add ability to set file names to a file upload control. | |
383 return false; | |
384 } | |
385 | |
386 void WebTestProxyBase::showValidationMessage(const WebRect&, const WebString& me
ssage, const WebString& subMessage, WebTextDirection) | |
387 { | |
388 m_delegate->printMessage(std::string("ValidationMessageClient: main-message=
") + std::string(message.utf8()) + " sub-message=" + std::string(subMessage.utf8
()) + "\n"); | |
389 } | |
390 | |
391 void WebTestProxyBase::hideValidationMessage() | |
392 { | |
393 } | |
394 | |
395 void WebTestProxyBase::moveValidationMessage(const WebRect&) | |
396 { | |
397 } | |
398 | |
399 string WebTestProxyBase::captureTree(bool debugRenderTree) | |
400 { | |
401 bool shouldDumpCustomText = m_testInterfaces->testRunner()->shouldDumpAsCust
omText(); | |
402 bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText(); | |
403 bool shouldDumpAsMarkup = m_testInterfaces->testRunner()->shouldDumpAsMarkup
(); | |
404 bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting(); | |
405 WebFrame* frame = webView()->mainFrame(); | |
406 string dataUtf8; | |
407 if (shouldDumpCustomText) { | |
408 // Append a newline for the test driver. | |
409 dataUtf8 = m_testInterfaces->testRunner()->customDumpText() + "\n"; | |
410 } else if (shouldDumpAsText) { | |
411 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAs
Text(); | |
412 dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursiv
e) : dumpFramesAsText(frame, recursive); | |
413 } else if (shouldDumpAsMarkup) { | |
414 // Append a newline for the test driver. | |
415 dataUtf8 = frame->contentAsMarkup().utf8() + "\n"; | |
416 } else { | |
417 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScr
ollPositions(); | |
418 WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTe
xtNormal; | |
419 if (shouldDumpAsPrinted) | |
420 renderTextBehavior |= WebFrame::RenderAsTextPrinting; | |
421 if (debugRenderTree) | |
422 renderTextBehavior |= WebFrame::RenderAsTextDebug; | |
423 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); | |
424 dataUtf8 += dumpFrameScrollPosition(frame, recursive); | |
425 } | |
426 | |
427 if (m_testInterfaces->testRunner()->shouldDumpBackForwardList()) | |
428 dataUtf8 += dumpAllBackForwardLists(m_testInterfaces, m_delegate); | |
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 } | |
446 | |
447 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | |
448 // See if we need to draw the selection bounds rect. Selection bounds | |
449 // rect is the rect enclosing the (possibly transformed) selection. | |
450 // The rect should be drawn after everything is laid out and painted. | |
451 if (!m_testInterfaces->testRunner()->shouldDumpSelectionRect()) | |
452 return; | |
453 // If there is a selection rect - draw a red 1px border enclosing rect | |
454 WebRect wr = webView()->mainFrame()->selectionBoundsRect(); | |
455 if (wr.isEmpty()) | |
456 return; | |
457 // Render a red rectangle bounding selection rect | |
458 SkPaint paint; | |
459 paint.setColor(0xFFFF0000); // Fully opaque red | |
460 paint.setStyle(SkPaint::kStroke_Style); | |
461 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
462 paint.setStrokeWidth(1.0f); | |
463 SkIRect rect; // Bounding rect | |
464 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); | |
465 canvas->drawIRect(rect, paint); | |
466 } | |
467 | |
468 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) { | |
469 TRACE_EVENT2("shell", | |
470 "WebTestProxyBase::didCompositeAndReadback", | |
471 "x", | |
472 bitmap.info().fWidth, | |
473 "y", | |
474 bitmap.info().fHeight); | |
475 SkCanvas canvas(bitmap); | |
476 DrawSelectionRect(&canvas); | |
477 DCHECK(!m_compositeAndReadbackCallbacks.empty()); | |
478 m_compositeAndReadbackCallbacks.front().Run(bitmap); | |
479 m_compositeAndReadbackCallbacks.pop_front(); | |
480 } | |
481 | |
482 void WebTestProxyBase::CapturePixelsForPrinting( | |
483 base::Callback<void(const SkBitmap&)> callback) { | |
484 // TODO(enne): get rid of stateful canvas(). | |
485 webWidget()->layout(); | |
486 paintPagesWithBoundaries(); | |
487 DrawSelectionRect(canvas()); | |
488 SkBaseDevice* device = skia::GetTopDevice(*canvas()); | |
489 const SkBitmap& bitmap = device->accessBitmap(false); | |
490 callback.Run(bitmap); | |
491 } | |
492 | |
493 void WebTestProxyBase::CapturePixelsAsync( | |
494 base::Callback<void(const SkBitmap&)> callback) { | |
495 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | |
496 | |
497 DCHECK(webWidget()->isAcceleratedCompositingActive()); | |
498 DCHECK(!callback.is_null()); | |
499 | |
500 if (m_testInterfaces->testRunner()->isPrinting()) { | |
501 base::MessageLoopProxy::current()->PostTask( | |
502 FROM_HERE, | |
503 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, | |
504 base::Unretained(this), | |
505 callback)); | |
506 return; | |
507 } | |
508 | |
509 m_compositeAndReadbackCallbacks.push_back(callback); | |
510 webWidget()->compositeAndReadbackAsync(this); | |
511 } | |
512 | |
513 void WebTestProxyBase::setLogConsoleOutput(bool enabled) | |
514 { | |
515 m_logConsoleOutput = enabled; | |
516 } | |
517 | |
518 void WebTestProxyBase::paintRect(const WebRect& rect) | |
519 { | |
520 DCHECK(!m_isPainting); | |
521 DCHECK(canvas()); | |
522 m_isPainting = true; | |
523 float deviceScaleFactor = webView()->deviceScaleFactor(); | |
524 int scaledX = static_cast<int>(static_cast<float>(rect.x) * deviceScaleFacto
r); | |
525 int scaledY = static_cast<int>(static_cast<float>(rect.y) * deviceScaleFacto
r); | |
526 int scaledWidth = static_cast<int>(ceil(static_cast<float>(rect.width) * dev
iceScaleFactor)); | |
527 int scaledHeight = static_cast<int>(ceil(static_cast<float>(rect.height) * d
eviceScaleFactor)); | |
528 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight); | |
529 webWidget()->paint(canvas(), deviceRect); | |
530 m_isPainting = false; | |
531 } | |
532 | |
533 void WebTestProxyBase::paintInvalidatedRegion() | |
534 { | |
535 webWidget()->animate(0.0); | |
536 webWidget()->layout(); | |
537 WebSize widgetSize = webWidget()->size(); | |
538 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height); | |
539 | |
540 // Paint the canvas if necessary. Allow painting to generate extra rects | |
541 // for the first two calls. This is necessary because some WebCore rendering | |
542 // objects update their layout only when painted. | |
543 // Store the total area painted in total_paint. Then tell the gdk window | |
544 // to update that area after we're done painting it. | |
545 for (int i = 0; i < 3; ++i) { | |
546 // rect = intersect(m_paintRect , clientRect) | |
547 WebRect damageRect = m_paintRect; | |
548 int left = max(damageRect.x, clientRect.x); | |
549 int top = max(damageRect.y, clientRect.y); | |
550 int right = min(damageRect.x + damageRect.width, clientRect.x + clientRe
ct.width); | |
551 int bottom = min(damageRect.y + damageRect.height, clientRect.y + client
Rect.height); | |
552 WebRect rect; | |
553 if (left < right && top < bottom) | |
554 rect = WebRect(left, top, right - left, bottom - top); | |
555 | |
556 m_paintRect = WebRect(); | |
557 if (rect.isEmpty()) | |
558 continue; | |
559 paintRect(rect); | |
560 } | |
561 DCHECK(m_paintRect.isEmpty()); | |
562 } | |
563 | |
564 void WebTestProxyBase::paintPagesWithBoundaries() | |
565 { | |
566 DCHECK(!m_isPainting); | |
567 DCHECK(canvas()); | |
568 m_isPainting = true; | |
569 | |
570 WebSize pageSizeInPixels = webWidget()->size(); | |
571 WebFrame* webFrame = webView()->mainFrame(); | |
572 | |
573 int pageCount = webFrame->printBegin(pageSizeInPixels); | |
574 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; | |
575 | |
576 SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, t
otalHeight, false); | |
577 if (testCanvas) { | |
578 discardBackingStore(); | |
579 m_canvas.reset(testCanvas); | |
580 } else { | |
581 webFrame->printEnd(); | |
582 return; | |
583 } | |
584 | |
585 webFrame->printPagesWithBoundaries(canvas(), pageSizeInPixels); | |
586 webFrame->printEnd(); | |
587 | |
588 m_isPainting = false; | |
589 } | |
590 | |
591 SkCanvas* WebTestProxyBase::canvas() | |
592 { | |
593 if (m_canvas.get()) | |
594 return m_canvas.get(); | |
595 WebSize widgetSize = webWidget()->size(); | |
596 float deviceScaleFactor = webView()->deviceScaleFactor(); | |
597 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width)
* deviceScaleFactor)); | |
598 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh
t) * deviceScaleFactor)); | |
599 // 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 | |
601 // the entire view. | |
602 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, false)); | |
603 return m_canvas.get(); | |
604 } | |
605 | |
606 void WebTestProxyBase::DisplayForSoftwareMode(const base::Closure& callback) { | |
607 const blink::WebSize& size = webWidget()->size(); | |
608 WebRect rect(0, 0, size.width, size.height); | |
609 m_paintRect = rect; | |
610 paintInvalidatedRegion(); | |
611 | |
612 if (!callback.is_null()) | |
613 callback.Run(); | |
614 } | |
615 | |
616 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, | |
617 const SkBitmap& bitmap) { | |
618 // Verify we actually composited. | |
619 CHECK_NE(0, bitmap.info().fWidth); | |
620 CHECK_NE(0, bitmap.info().fHeight); | |
621 if (!callback.is_null()) | |
622 callback.Run(); | |
623 } | |
624 | |
625 void WebTestProxyBase::displayAsyncThen(base::Closure callback) { | |
626 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); | |
627 | |
628 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. | |
629 if (!webWidget()->isAcceleratedCompositingActive()) { | |
630 TRACE_EVENT0("shell", | |
631 "WebTestProxyBase::displayAsyncThen " | |
632 "isAcceleratedCompositingActive false"); | |
633 base::MessageLoopProxy::current()->PostTask( | |
634 FROM_HERE, | |
635 base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, | |
636 base::Unretained(this), | |
637 callback)); | |
638 return; | |
639 } | |
640 | |
641 CapturePixelsAsync(base::Bind( | |
642 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback)); | |
643 } | |
644 | |
645 void WebTestProxyBase::discardBackingStore() | |
646 { | |
647 m_canvas.reset(); | |
648 } | |
649 | |
650 WebMIDIClientMock* WebTestProxyBase::midiClientMock() | |
651 { | |
652 if (!m_midiClient.get()) | |
653 m_midiClient.reset(new WebMIDIClientMock); | |
654 return m_midiClient.get(); | |
655 } | |
656 | |
657 MockWebSpeechRecognizer* WebTestProxyBase::speechRecognizerMock() | |
658 { | |
659 if (!m_speechRecognizer.get()) { | |
660 m_speechRecognizer.reset(new MockWebSpeechRecognizer()); | |
661 m_speechRecognizer->setDelegate(m_delegate); | |
662 } | |
663 return m_speechRecognizer.get(); | |
664 } | |
665 | |
666 void WebTestProxyBase::didInvalidateRect(const WebRect& rect) | |
667 { | |
668 // m_paintRect = m_paintRect U rect | |
669 if (rect.isEmpty()) | |
670 return; | |
671 if (m_paintRect.isEmpty()) { | |
672 m_paintRect = rect; | |
673 return; | |
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 } | |
866 | |
867 // The output from these methods in layout test mode should match that | |
868 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | |
869 | |
870 void WebTestProxyBase::didChangeSelection(bool isEmptySelection) | |
871 { | |
872 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) | |
873 m_delegate->printMessage("EDITING DELEGATE: webViewDidChangeSelection:We
bViewDidChangeSelectionNotification\n"); | |
874 } | |
875 | |
876 void WebTestProxyBase::didChangeContents() | |
877 { | |
878 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) | |
879 m_delegate->printMessage("EDITING DELEGATE: webViewDidChange:WebViewDidC
hangeNotification\n"); | |
880 } | |
881 | |
882 bool WebTestProxyBase::createView(WebLocalFrame*, const WebURLRequest& request,
const WebWindowFeatures&, const WebString&, WebNavigationPolicy, bool) | |
883 { | |
884 if (!m_testInterfaces->testRunner()->canOpenWindows()) | |
885 return false; | |
886 if (m_testInterfaces->testRunner()->shouldDumpCreateView()) | |
887 m_delegate->printMessage(string("createView(") + URLDescription(request.
url()) + ")\n"); | |
888 return true; | |
889 } | |
890 | |
891 WebPlugin* WebTestProxyBase::createPlugin(WebLocalFrame* frame, const WebPluginP
arams& params) | |
892 { | |
893 if (TestPlugin::isSupportedMimeType(params.mimeType)) | |
894 return TestPlugin::create(frame, params, m_delegate); | |
895 return 0; | |
896 } | |
897 | |
898 void WebTestProxyBase::setStatusText(const WebString& text) | |
899 { | |
900 if (!m_testInterfaces->testRunner()->shouldDumpStatusCallbacks()) | |
901 return; | |
902 m_delegate->printMessage(string("UI DELEGATE STATUS CALLBACK: setStatusText:
") + text.utf8().data() + "\n"); | |
903 } | |
904 | |
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 } | |
1327 | |
1328 } // namespace content | |
OLD | NEW |