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

Side by Side Diff: content/shell/renderer/test_runner/WebTestProxy.cpp

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/WebTestProxy.h"
6
7 #include <cctype>
8
9 #include "content/shell/renderer/test_runner/AccessibilityController.h"
10 #include "content/shell/renderer/test_runner/EventSender.h"
11 #include "content/shell/renderer/test_runner/MockColorChooser.h"
12 #include "content/shell/renderer/test_runner/MockWebSpeechInputController.h"
13 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
14 #include "content/shell/renderer/test_runner/SpellCheckClient.h"
15 #include "content/shell/renderer/test_runner/TestCommon.h"
16 #include "content/shell/renderer/test_runner/TestInterfaces.h"
17 #include "content/shell/renderer/test_runner/TestPlugin.h"
18 #include "content/shell/renderer/test_runner/TestRunner.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 // FIXME: Including platform_canvas.h here is a layering violation.
24 #include "skia/ext/platform_canvas.h"
25 #include "third_party/WebKit/public/platform/WebCString.h"
26 #include "third_party/WebKit/public/platform/WebURLError.h"
27 #include "third_party/WebKit/public/platform/WebURLRequest.h"
28 #include "third_party/WebKit/public/platform/WebURLResponse.h"
29 #include "third_party/WebKit/public/web/WebAXEnums.h"
30 #include "third_party/WebKit/public/web/WebAXObject.h"
31 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
32 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
33 #include "third_party/WebKit/public/web/WebDataSource.h"
34 #include "third_party/WebKit/public/web/WebDocument.h"
35 #include "third_party/WebKit/public/web/WebElement.h"
36 #include "third_party/WebKit/public/web/WebFrame.h"
37 #include "third_party/WebKit/public/web/WebGeolocationClientMock.h"
38 #include "third_party/WebKit/public/web/WebHistoryItem.h"
39 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
40 #include "third_party/WebKit/public/web/WebNode.h"
41 #include "third_party/WebKit/public/web/WebPluginParams.h"
42 #include "third_party/WebKit/public/web/WebPrintParams.h"
43 #include "third_party/WebKit/public/web/WebRange.h"
44 #include "third_party/WebKit/public/web/WebScriptController.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 WebTestRunner {
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() { (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 struct ToLower {
294 char16 operator()(char16 c) { return tolower(c); }
295 };
296
297 // Returns True if item1 < item2.
298 bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& i tem2)
299 {
300 string16 target1 = item1.target();
301 string16 target2 = item2.target();
302 std::transform(target1.begin(), target1.end(), target1.begin(), ToLower());
303 std::transform(target2.begin(), target2.end(), target2.begin(), ToLower());
304 return target1 < target2;
305 }
306
307 string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent)
308 {
309 string result;
310
311 if (isCurrent) {
312 result.append("curr->");
313 result.append(indent - 6, ' '); // 6 == "curr->".length()
314 } else
315 result.append(indent, ' ');
316
317 string url = normalizeLayoutTestURL(item.urlString().utf8());
318 result.append(url);
319 if (!item.target().isEmpty()) {
320 result.append(" (in frame \"");
321 result.append(item.target().utf8());
322 result.append("\")");
323 }
324 result.append("\n");
325
326 const WebVector<WebHistoryItem>& children = item.children();
327 if (!children.isEmpty()) {
328 // Must sort to eliminate arbitrary result ordering which defeats
329 // reproducible testing.
330 // FIXME: WebVector should probably just be a std::vector!!
331 std::vector<WebHistoryItem> sortedChildren;
332 for (size_t i = 0; i < children.size(); ++i)
333 sortedChildren.push_back(children[i]);
334 std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompa reLess);
335 for (size_t i = 0; i < sortedChildren.size(); ++i)
336 result += dumpHistoryItem(sortedChildren[i], indent + 4, false);
337 }
338
339 return result;
340 }
341
342 void dumpBackForwardList(const WebVector<WebHistoryItem>& history, size_t curren tEntryIndex, string& result)
343 {
344 result.append("\n============== Back Forward List ==============\n");
345 for (size_t index = 0; index < history.size(); ++index)
346 result.append(dumpHistoryItem(history[index], 8, index == currentEntryIn dex));
347 result.append("===============================================\n");
348 }
349
350 string dumpAllBackForwardLists(TestInterfaces* interfaces, WebTestDelegate* dele gate)
351 {
352 string result;
353 const vector<WebTestProxyBase*>& windowList = interfaces->windowList();
354 for (unsigned i = 0; i < windowList.size(); ++i) {
355 size_t currentEntryIndex = 0;
356 WebVector<WebHistoryItem> history;
357 delegate->captureHistoryForWindow(windowList.at(i), &history, &currentEn tryIndex);
358 dumpBackForwardList(history, currentEntryIndex, result);
359 }
360 return result;
361 }
362
363 }
364
365 WebTestProxyBase::WebTestProxyBase()
366 : m_testInterfaces(0)
367 , m_delegate(0)
368 , m_webWidget(0)
369 , m_spellcheck(new SpellCheckClient(this))
370 , m_chooserCount(0)
371 {
372 reset();
373 }
374
375 WebTestProxyBase::~WebTestProxyBase()
376 {
377 m_testInterfaces->windowClosed(this);
378 }
379
380 void WebTestProxyBase::setInterfaces(WebTestInterfaces* interfaces)
381 {
382 m_testInterfaces = interfaces->testInterfaces();
383 m_testInterfaces->windowOpened(this);
384 }
385
386 void WebTestProxyBase::setDelegate(WebTestDelegate* delegate)
387 {
388 m_delegate = delegate;
389 m_spellcheck->setDelegate(delegate);
390 #if ENABLE_INPUT_SPEECH
391 if (m_speechInputController.get())
392 m_speechInputController->setDelegate(delegate);
393 #endif
394 if (m_speechRecognizer.get())
395 m_speechRecognizer->setDelegate(delegate);
396 }
397
398 void WebTestProxyBase::setWidget(WebWidget* widget)
399 {
400 m_webWidget = widget;
401 }
402
403 WebWidget* WebTestProxyBase::webWidget()
404 {
405 return m_webWidget;
406 }
407
408 WebView* WebTestProxyBase::webView()
409 {
410 BLINK_ASSERT(m_webWidget);
411 // TestRunner does not support popup widgets. So m_webWidget is always a Web View.
412 return static_cast<WebView*>(m_webWidget);
413 }
414
415 void WebTestProxyBase::didForceResize()
416 {
417 invalidateAll();
418 discardBackingStore();
419 }
420
421 void WebTestProxyBase::reset()
422 {
423 m_paintRect = WebRect();
424 m_canvas.reset();
425 m_isPainting = false;
426 m_animateScheduled = false;
427 m_resourceIdentifierMap.clear();
428 m_logConsoleOutput = true;
429 if (m_geolocationClient.get())
430 m_geolocationClient->resetMock();
431 if (m_midiClient.get())
432 m_midiClient->resetMock();
433 #if ENABLE_INPUT_SPEECH
434 if (m_speechInputController.get())
435 m_speechInputController->clearResults();
436 #endif
437 }
438
439 WebSpellCheckClient* WebTestProxyBase::spellCheckClient() const
440 {
441 return m_spellcheck.get();
442 }
443
444 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli ent, const blink::WebColor& color)
445 {
446 // This instance is deleted by WebCore::ColorInputType
447 return new MockColorChooser(client, m_delegate, this);
448 }
449
450 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli ent, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggest ion>& suggestions)
451 {
452 // This instance is deleted by WebCore::ColorInputType
453 return new MockColorChooser(client, m_delegate, this);
454 }
455
456 bool WebTestProxyBase::runFileChooser(const blink::WebFileChooserParams&, blink: :WebFileChooserCompletion*)
457 {
458 m_delegate->printMessage("Mock: Opening a file chooser.\n");
459 // FIXME: Add ability to set file names to a file upload control.
460 return false;
461 }
462
463 void WebTestProxyBase::showValidationMessage(const WebRect&, const WebString& me ssage, const WebString& subMessage, WebTextDirection)
464 {
465 m_delegate->printMessage(std::string("ValidationMessageClient: main-message= ") + std::string(message.utf8()) + " sub-message=" + std::string(subMessage.utf8 ()) + "\n");
466 }
467
468 void WebTestProxyBase::hideValidationMessage()
469 {
470 }
471
472 void WebTestProxyBase::moveValidationMessage(const WebRect&)
473 {
474 }
475
476 string WebTestProxyBase::captureTree(bool debugRenderTree)
477 {
478 WebScriptController::flushConsoleMessages();
479
480 bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText();
481 bool shouldDumpAsMarkup = m_testInterfaces->testRunner()->shouldDumpAsMarkup ();
482 bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting();
483 WebFrame* frame = webView()->mainFrame();
484 string dataUtf8;
485 if (shouldDumpAsText) {
486 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAs Text();
487 dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursiv e) : dumpFramesAsText(frame, recursive);
488 } else if (shouldDumpAsMarkup) {
489 // Append a newline for the test driver.
490 dataUtf8 = frame->contentAsMarkup().utf8() + "\n";
491 } else {
492 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScr ollPositions();
493 WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTe xtNormal;
494 if (shouldDumpAsPrinted)
495 renderTextBehavior |= WebFrame::RenderAsTextPrinting;
496 if (debugRenderTree)
497 renderTextBehavior |= WebFrame::RenderAsTextDebug;
498 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8();
499 dataUtf8 += dumpFrameScrollPosition(frame, recursive);
500 }
501
502 if (m_testInterfaces->testRunner()->shouldDumpBackForwardList())
503 dataUtf8 += dumpAllBackForwardLists(m_testInterfaces, m_delegate);
504
505 return dataUtf8;
506 }
507
508 SkCanvas* WebTestProxyBase::capturePixels()
509 {
510 webWidget()->layout();
511 if (m_testInterfaces->testRunner()->testRepaint()) {
512 WebSize viewSize = webWidget()->size();
513 int width = viewSize.width;
514 int height = viewSize.height;
515 if (m_testInterfaces->testRunner()->sweepHorizontally()) {
516 for (WebRect column(0, 0, 1, height); column.x < width; column.x++)
517 paintRect(column);
518 } else {
519 for (WebRect line(0, 0, width, 1); line.y < height; line.y++)
520 paintRect(line);
521 }
522 } else if (m_testInterfaces->testRunner()->isPrinting())
523 paintPagesWithBoundaries();
524 else
525 paintInvalidatedRegion();
526
527 // See if we need to draw the selection bounds rect. Selection bounds
528 // rect is the rect enclosing the (possibly transformed) selection.
529 // The rect should be drawn after everything is laid out and painted.
530 if (m_testInterfaces->testRunner()->shouldDumpSelectionRect()) {
531 // If there is a selection rect - draw a red 1px border enclosing rect
532 WebRect wr = webView()->mainFrame()->selectionBoundsRect();
533 if (!wr.isEmpty()) {
534 // Render a red rectangle bounding selection rect
535 SkPaint paint;
536 paint.setColor(0xFFFF0000); // Fully opaque red
537 paint.setStyle(SkPaint::kStroke_Style);
538 paint.setFlags(SkPaint::kAntiAlias_Flag);
539 paint.setStrokeWidth(1.0f);
540 SkIRect rect; // Bounding rect
541 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
542 canvas()->drawIRect(rect, paint);
543 }
544 }
545
546 return canvas();
547 }
548
549 void WebTestProxyBase::setLogConsoleOutput(bool enabled)
550 {
551 m_logConsoleOutput = enabled;
552 }
553
554 void WebTestProxyBase::paintRect(const WebRect& rect)
555 {
556 BLINK_ASSERT(!m_isPainting);
557 BLINK_ASSERT(canvas());
558 m_isPainting = true;
559 float deviceScaleFactor = webView()->deviceScaleFactor();
560 int scaledX = static_cast<int>(static_cast<float>(rect.x) * deviceScaleFacto r);
561 int scaledY = static_cast<int>(static_cast<float>(rect.y) * deviceScaleFacto r);
562 int scaledWidth = static_cast<int>(ceil(static_cast<float>(rect.width) * dev iceScaleFactor));
563 int scaledHeight = static_cast<int>(ceil(static_cast<float>(rect.height) * d eviceScaleFactor));
564 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight);
565 webWidget()->paint(canvas(), deviceRect);
566 m_isPainting = false;
567 }
568
569 void WebTestProxyBase::paintInvalidatedRegion()
570 {
571 webWidget()->animate(0.0);
572 webWidget()->layout();
573 WebSize widgetSize = webWidget()->size();
574 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height);
575
576 // Paint the canvas if necessary. Allow painting to generate extra rects
577 // for the first two calls. This is necessary because some WebCore rendering
578 // objects update their layout only when painted.
579 // Store the total area painted in total_paint. Then tell the gdk window
580 // to update that area after we're done painting it.
581 for (int i = 0; i < 3; ++i) {
582 // rect = intersect(m_paintRect , clientRect)
583 WebRect damageRect = m_paintRect;
584 int left = max(damageRect.x, clientRect.x);
585 int top = max(damageRect.y, clientRect.y);
586 int right = min(damageRect.x + damageRect.width, clientRect.x + clientRe ct.width);
587 int bottom = min(damageRect.y + damageRect.height, clientRect.y + client Rect.height);
588 WebRect rect;
589 if (left < right && top < bottom)
590 rect = WebRect(left, top, right - left, bottom - top);
591
592 m_paintRect = WebRect();
593 if (rect.isEmpty())
594 continue;
595 paintRect(rect);
596 }
597 BLINK_ASSERT(m_paintRect.isEmpty());
598 }
599
600 void WebTestProxyBase::paintPagesWithBoundaries()
601 {
602 BLINK_ASSERT(!m_isPainting);
603 BLINK_ASSERT(canvas());
604 m_isPainting = true;
605
606 WebSize pageSizeInPixels = webWidget()->size();
607 WebFrame* webFrame = webView()->mainFrame();
608
609 int pageCount = webFrame->printBegin(pageSizeInPixels);
610 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1;
611
612 SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, t otalHeight, true);
613 if (testCanvas) {
614 discardBackingStore();
615 m_canvas.reset(testCanvas);
616 } else {
617 webFrame->printEnd();
618 return;
619 }
620
621 webFrame->printPagesWithBoundaries(canvas(), pageSizeInPixels);
622 webFrame->printEnd();
623
624 m_isPainting = false;
625 }
626
627 SkCanvas* WebTestProxyBase::canvas()
628 {
629 if (m_canvas.get())
630 return m_canvas.get();
631 WebSize widgetSize = webWidget()->size();
632 float deviceScaleFactor = webView()->deviceScaleFactor();
633 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width) * deviceScaleFactor));
634 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh t) * deviceScaleFactor));
635 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, true));
636 return m_canvas.get();
637 }
638
639 // Paints the entire canvas a semi-transparent black (grayish). This is used
640 // by the layout tests in fast/repaint. The alpha value matches upstream.
641 void WebTestProxyBase::displayRepaintMask()
642 {
643 canvas()->drawARGB(167, 0, 0, 0);
644 }
645
646 void WebTestProxyBase::display()
647 {
648 const blink::WebSize& size = webWidget()->size();
649 WebRect rect(0, 0, size.width, size.height);
650 m_paintRect = rect;
651 paintInvalidatedRegion();
652 displayRepaintMask();
653 }
654
655 void WebTestProxyBase::displayInvalidatedRegion()
656 {
657 paintInvalidatedRegion();
658 displayRepaintMask();
659 }
660
661 void WebTestProxyBase::discardBackingStore()
662 {
663 m_canvas.reset();
664 }
665
666 WebGeolocationClientMock* WebTestProxyBase::geolocationClientMock()
667 {
668 if (!m_geolocationClient.get())
669 m_geolocationClient.reset(WebGeolocationClientMock::create());
670 return m_geolocationClient.get();
671 }
672
673 WebMIDIClientMock* WebTestProxyBase::midiClientMock()
674 {
675 if (!m_midiClient.get())
676 m_midiClient.reset(new WebMIDIClientMock);
677 return m_midiClient.get();
678 }
679
680 #if ENABLE_INPUT_SPEECH
681 MockWebSpeechInputController* WebTestProxyBase::speechInputControllerMock()
682 {
683 BLINK_ASSERT(m_speechInputController.get());
684 return m_speechInputController.get();
685 }
686 #endif
687
688 MockWebSpeechRecognizer* WebTestProxyBase::speechRecognizerMock()
689 {
690 if (!m_speechRecognizer.get()) {
691 m_speechRecognizer.reset(new MockWebSpeechRecognizer());
692 m_speechRecognizer->setDelegate(m_delegate);
693 }
694 return m_speechRecognizer.get();
695 }
696
697 void WebTestProxyBase::didInvalidateRect(const WebRect& rect)
698 {
699 // m_paintRect = m_paintRect U rect
700 if (rect.isEmpty())
701 return;
702 if (m_paintRect.isEmpty()) {
703 m_paintRect = rect;
704 return;
705 }
706 int left = min(m_paintRect.x, rect.x);
707 int top = min(m_paintRect.y, rect.y);
708 int right = max(m_paintRect.x + m_paintRect.width, rect.x + rect.width);
709 int bottom = max(m_paintRect.y + m_paintRect.height, rect.y + rect.height);
710 m_paintRect = WebRect(left, top, right - left, bottom - top);
711 }
712
713 void WebTestProxyBase::didScrollRect(int, int, const WebRect& clipRect)
714 {
715 didInvalidateRect(clipRect);
716 }
717
718 void WebTestProxyBase::invalidateAll()
719 {
720 m_paintRect = WebRect(0, 0, INT_MAX, INT_MAX);
721 }
722
723 void WebTestProxyBase::scheduleComposite()
724 {
725 invalidateAll();
726 }
727
728 void WebTestProxyBase::scheduleAnimation()
729 {
730 if (!m_testInterfaces->testRunner()->testIsRunning())
731 return;
732
733 if (!m_animateScheduled) {
734 m_animateScheduled = true;
735 m_delegate->postDelayedTask(new HostMethodTask(this, &WebTestProxyBase:: animateNow), 1);
736 }
737 }
738
739 void WebTestProxyBase::animateNow()
740 {
741 if (m_animateScheduled) {
742 m_animateScheduled = false;
743 webWidget()->animate(0.0);
744 }
745 }
746
747 void WebTestProxyBase::show(WebNavigationPolicy)
748 {
749 invalidateAll();
750 }
751
752 void WebTestProxyBase::setWindowRect(const WebRect& rect)
753 {
754 invalidateAll();
755 discardBackingStore();
756 }
757
758 void WebTestProxyBase::didAutoResize(const WebSize&)
759 {
760 invalidateAll();
761 }
762
763 void WebTestProxyBase::postAccessibilityEvent(const blink::WebAXObject& obj, bli nk::WebAXEvent event)
764 {
765 if (event == blink::WebAXEventFocus)
766 m_testInterfaces->accessibilityController()->setFocusedElement(obj);
767
768 const char* eventName = 0;
769 switch (event) {
770 case blink::WebAXEventActiveDescendantChanged:
771 eventName = "ActiveDescendantChanged";
772 break;
773 case blink::WebAXEventAlert:
774 eventName = "Alert";
775 break;
776 case blink::WebAXEventAriaAttributeChanged:
777 eventName = "AriaAttributeChanged";
778 break;
779 case blink::WebAXEventAutocorrectionOccured:
780 eventName = "AutocorrectionOccured";
781 break;
782 case blink::WebAXEventBlur:
783 eventName = "Blur";
784 break;
785 case blink::WebAXEventCheckedStateChanged:
786 eventName = "CheckedStateChanged";
787 break;
788 case blink::WebAXEventChildrenChanged:
789 eventName = "ChildrenChanged";
790 break;
791 case blink::WebAXEventFocus:
792 eventName = "Focus";
793 break;
794 case blink::WebAXEventHide:
795 eventName = "Hide";
796 break;
797 case blink::WebAXEventInvalidStatusChanged:
798 eventName = "InvalidStatusChanged";
799 break;
800 case blink::WebAXEventLayoutComplete:
801 eventName = "LayoutComplete";
802 break;
803 case blink::WebAXEventLiveRegionChanged:
804 eventName = "LiveRegionChanged";
805 break;
806 case blink::WebAXEventLoadComplete:
807 eventName = "LoadComplete";
808 break;
809 case blink::WebAXEventLocationChanged:
810 eventName = "LocationChanged";
811 break;
812 case blink::WebAXEventMenuListItemSelected:
813 eventName = "MenuListItemSelected";
814 break;
815 case blink::WebAXEventMenuListValueChanged:
816 eventName = "MenuListValueChanged";
817 break;
818 case blink::WebAXEventRowCollapsed:
819 eventName = "RowCollapsed";
820 break;
821 case blink::WebAXEventRowCountChanged:
822 eventName = "RowCountChanged";
823 break;
824 case blink::WebAXEventRowExpanded:
825 eventName = "RowExpanded";
826 break;
827 case blink::WebAXEventScrolledToAnchor:
828 eventName = "ScrolledToAnchor";
829 break;
830 case blink::WebAXEventSelectedChildrenChanged:
831 eventName = "SelectedChildrenChanged";
832 break;
833 case blink::WebAXEventSelectedTextChanged:
834 eventName = "SelectedTextChanged";
835 break;
836 case blink::WebAXEventShow:
837 eventName = "Show";
838 break;
839 case blink::WebAXEventTextChanged:
840 eventName = "TextChanged";
841 break;
842 case blink::WebAXEventTextInserted:
843 eventName = "TextInserted";
844 break;
845 case blink::WebAXEventTextRemoved:
846 eventName = "TextRemoved";
847 break;
848 case blink::WebAXEventValueChanged:
849 eventName = "ValueChanged";
850 break;
851 }
852
853 m_testInterfaces->accessibilityController()->notificationReceived(obj, event Name);
854
855 if (m_testInterfaces->accessibilityController()->shouldLogAccessibilityEvent s()) {
856 string message("AccessibilityNotification - ");
857 message += eventName;
858
859 blink::WebNode node = obj.node();
860 if (!node.isNull() && node.isElementNode()) {
861 blink::WebElement element = node.to<blink::WebElement>();
862 if (element.hasAttribute("id")) {
863 message += " - id:";
864 message += element.getAttribute("id").utf8().data();
865 }
866 }
867
868 m_delegate->printMessage(message + "\n");
869 }
870 }
871
872 void WebTestProxyBase::startDragging(WebFrame*, const WebDragData& data, WebDrag OperationsMask mask, const WebImage&, const WebPoint&)
873 {
874 // When running a test, we need to fake a drag drop operation otherwise
875 // Windows waits for real mouse events to know when the drag is over.
876 m_testInterfaces->eventSender()->doDragDrop(data, mask);
877 }
878
879 // The output from these methods in layout test mode should match that
880 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
881
882 void WebTestProxyBase::didChangeSelection(bool isEmptySelection)
883 {
884 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks())
885 m_delegate->printMessage("EDITING DELEGATE: webViewDidChangeSelection:We bViewDidChangeSelectionNotification\n");
886 }
887
888 void WebTestProxyBase::didChangeContents()
889 {
890 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks())
891 m_delegate->printMessage("EDITING DELEGATE: webViewDidChange:WebViewDidC hangeNotification\n");
892 }
893
894 bool WebTestProxyBase::createView(WebFrame*, const WebURLRequest& request, const WebWindowFeatures&, const WebString&, WebNavigationPolicy, bool)
895 {
896 if (!m_testInterfaces->testRunner()->canOpenWindows())
897 return false;
898 if (m_testInterfaces->testRunner()->shouldDumpCreateView())
899 m_delegate->printMessage(string("createView(") + URLDescription(request. url()) + ")\n");
900 return true;
901 }
902
903 WebPlugin* WebTestProxyBase::createPlugin(WebFrame* frame, const WebPluginParams & params)
904 {
905 if (params.mimeType == TestPlugin::mimeType())
906 return TestPlugin::create(frame, params, m_delegate);
907 return 0;
908 }
909
910 void WebTestProxyBase::setStatusText(const WebString& text)
911 {
912 if (!m_testInterfaces->testRunner()->shouldDumpStatusCallbacks())
913 return;
914 m_delegate->printMessage(string("UI DELEGATE STATUS CALLBACK: setStatusText: ") + text.utf8().data() + "\n");
915 }
916
917 void WebTestProxyBase::didStopLoading()
918 {
919 if (m_testInterfaces->testRunner()->shouldDumpProgressFinishedCallback())
920 m_delegate->printMessage("postProgressFinishedNotification\n");
921 }
922
923 void WebTestProxyBase::showContextMenu(WebFrame*, const WebContextMenuData& cont extMenuData)
924 {
925 m_testInterfaces->eventSender()->setContextMenuData(contextMenuData);
926 }
927
928 WebUserMediaClient* WebTestProxyBase::userMediaClient()
929 {
930 if (!m_userMediaClient.get())
931 m_userMediaClient.reset(new WebUserMediaClientMock(m_delegate));
932 return m_userMediaClient.get();
933 }
934
935 // Simulate a print by going into print mode and then exit straight away.
936 void WebTestProxyBase::printPage(WebFrame* frame)
937 {
938 WebSize pageSizeInPixels = webWidget()->size();
939 if (pageSizeInPixels.isEmpty())
940 return;
941 WebPrintParams printParams(pageSizeInPixels);
942 frame->printBegin(printParams);
943 frame->printEnd();
944 }
945
946 WebNotificationPresenter* WebTestProxyBase::notificationPresenter()
947 {
948 return m_testInterfaces->testRunner()->notificationPresenter();
949 }
950
951 WebGeolocationClient* WebTestProxyBase::geolocationClient()
952 {
953 return geolocationClientMock();
954 }
955
956 WebMIDIClient* WebTestProxyBase::webMIDIClient()
957 {
958 return midiClientMock();
959 }
960
961 WebSpeechInputController* WebTestProxyBase::speechInputController(WebSpeechInput Listener* listener)
962 {
963 #if ENABLE_INPUT_SPEECH
964 if (!m_speechInputController.get()) {
965 m_speechInputController.reset(new MockWebSpeechInputController(listener) );
966 m_speechInputController->setDelegate(m_delegate);
967 }
968 return m_speechInputController.get();
969 #else
970 BLINK_ASSERT(listener);
971 return 0;
972 #endif
973 }
974
975 WebSpeechRecognizer* WebTestProxyBase::speechRecognizer()
976 {
977 return speechRecognizerMock();
978 }
979
980 bool WebTestProxyBase::requestPointerLock()
981 {
982 return m_testInterfaces->testRunner()->requestPointerLock();
983 }
984
985 void WebTestProxyBase::requestPointerUnlock()
986 {
987 m_testInterfaces->testRunner()->requestPointerUnlock();
988 }
989
990 bool WebTestProxyBase::isPointerLocked()
991 {
992 return m_testInterfaces->testRunner()->isPointerLocked();
993 }
994
995 void WebTestProxyBase::didFocus()
996 {
997 m_delegate->setFocus(this, true);
998 }
999
1000 void WebTestProxyBase::didBlur()
1001 {
1002 m_delegate->setFocus(this, false);
1003 }
1004
1005 void WebTestProxyBase::setToolTipText(const WebString& text, WebTextDirection)
1006 {
1007 m_testInterfaces->testRunner()->setToolTipText(text);
1008 }
1009
1010 void WebTestProxyBase::didOpenChooser()
1011 {
1012 m_chooserCount++;
1013 }
1014
1015 void WebTestProxyBase::didCloseChooser()
1016 {
1017 m_chooserCount--;
1018 }
1019
1020 bool WebTestProxyBase::isChooserShown()
1021 {
1022 return 0 < m_chooserCount;
1023 }
1024
1025 void WebTestProxyBase::didStartProvisionalLoad(WebFrame* frame)
1026 {
1027 if (!m_testInterfaces->testRunner()->topLoadingFrame())
1028 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, false);
1029
1030 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1031 printFrameDescription(m_delegate, frame);
1032 m_delegate->printMessage(" - didStartProvisionalLoadForFrame\n");
1033 }
1034
1035 if (m_testInterfaces->testRunner()->shouldDumpUserGestureInFrameLoadCallback s())
1036 printFrameUserGestureStatus(m_delegate, frame, " - in didStartProvisiona lLoadForFrame\n");
1037 }
1038
1039 void WebTestProxyBase::didReceiveServerRedirectForProvisionalLoad(WebFrame* fram e)
1040 {
1041 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1042 printFrameDescription(m_delegate, frame);
1043 m_delegate->printMessage(" - didReceiveServerRedirectForProvisionalLoadF orFrame\n");
1044 }
1045 }
1046
1047 bool WebTestProxyBase::didFailProvisionalLoad(WebFrame* frame, const WebURLError &)
1048 {
1049 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1050 printFrameDescription(m_delegate, frame);
1051 m_delegate->printMessage(" - didFailProvisionalLoadWithError\n");
1052 }
1053 locationChangeDone(frame);
1054 return !frame->provisionalDataSource();
1055 }
1056
1057 void WebTestProxyBase::didCommitProvisionalLoad(WebFrame* frame, bool)
1058 {
1059 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1060 printFrameDescription(m_delegate, frame);
1061 m_delegate->printMessage(" - didCommitLoadForFrame\n");
1062 }
1063 }
1064
1065 void WebTestProxyBase::didReceiveTitle(WebFrame* frame, const WebString& title, WebTextDirection direction)
1066 {
1067 WebCString title8 = title.utf8();
1068
1069 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1070 printFrameDescription(m_delegate, frame);
1071 m_delegate->printMessage(string(" - didReceiveTitle: ") + title8.data() + "\n");
1072 }
1073
1074 if (m_testInterfaces->testRunner()->shouldDumpTitleChanges())
1075 m_delegate->printMessage(string("TITLE CHANGED: '") + title8.data() + "' \n");
1076 }
1077
1078 void WebTestProxyBase::didChangeIcon(WebFrame* frame, WebIconURL::Type)
1079 {
1080 if (m_testInterfaces->testRunner()->shouldDumpIconChanges()) {
1081 printFrameDescription(m_delegate, frame);
1082 m_delegate->printMessage(string(" - didChangeIcons\n"));
1083 }
1084 }
1085
1086 void WebTestProxyBase::didFinishDocumentLoad(WebFrame* frame)
1087 {
1088 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1089 printFrameDescription(m_delegate, frame);
1090 m_delegate->printMessage(" - didFinishDocumentLoadForFrame\n");
1091 } else {
1092 unsigned pendingUnloadEvents = frame->unloadListenerCount();
1093 if (pendingUnloadEvents) {
1094 printFrameDescription(m_delegate, frame);
1095 char buffer[100];
1096 snprintf(buffer, sizeof(buffer), " - has %u onunload handler(s)\n", pendingUnloadEvents);
1097 m_delegate->printMessage(buffer);
1098 }
1099 }
1100 }
1101
1102 void WebTestProxyBase::didHandleOnloadEvents(WebFrame* frame)
1103 {
1104 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1105 printFrameDescription(m_delegate, frame);
1106 m_delegate->printMessage(" - didHandleOnloadEventsForFrame\n");
1107 }
1108 }
1109
1110 void WebTestProxyBase::didFailLoad(WebFrame* frame, const WebURLError&)
1111 {
1112 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1113 printFrameDescription(m_delegate, frame);
1114 m_delegate->printMessage(" - didFailLoadWithError\n");
1115 }
1116 locationChangeDone(frame);
1117 }
1118
1119 void WebTestProxyBase::didFinishLoad(WebFrame* frame)
1120 {
1121 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) {
1122 printFrameDescription(m_delegate, frame);
1123 m_delegate->printMessage(" - didFinishLoadForFrame\n");
1124 }
1125 locationChangeDone(frame);
1126 }
1127
1128 void WebTestProxyBase::didDetectXSS(WebFrame*, const WebURL&, bool)
1129 {
1130 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks())
1131 m_delegate->printMessage("didDetectXSS\n");
1132 }
1133
1134 void WebTestProxyBase::didDispatchPingLoader(WebFrame*, const WebURL& url)
1135 {
1136 if (m_testInterfaces->testRunner()->shouldDumpPingLoaderCallbacks())
1137 m_delegate->printMessage(string("PingLoader dispatched to '") + URLDescr iption(url).c_str() + "'.\n");
1138 }
1139
1140 void WebTestProxyBase::willRequestResource(WebFrame* frame, const blink::WebCach edURLRequest& request)
1141 {
1142 if (m_testInterfaces->testRunner()->shouldDumpResourceRequestCallbacks()) {
1143 printFrameDescription(m_delegate, frame);
1144 m_delegate->printMessage(string(" - ") + request.initiatorName().utf8(). data());
1145 m_delegate->printMessage(string(" requested '") + URLDescription(request .urlRequest().url()).c_str() + "'\n");
1146 }
1147 }
1148
1149 void WebTestProxyBase::willSendRequest(WebFrame*, unsigned identifier, blink::We bURLRequest& request, const blink::WebURLResponse& redirectResponse)
1150 {
1151 // Need to use GURL for host() and SchemeIs()
1152 GURL url = request.url();
1153 string requestURL = url.possibly_invalid_spec();
1154
1155 GURL mainDocumentURL = request.firstPartyForCookies();
1156
1157 if (redirectResponse.isNull() && (m_testInterfaces->testRunner()->shouldDump ResourceLoadCallbacks() || m_testInterfaces->testRunner()->shouldDumpResourcePri orities())) {
1158 BLINK_ASSERT(m_resourceIdentifierMap.find(identifier) == m_resourceIdent ifierMap.end());
1159 m_resourceIdentifierMap[identifier] = descriptionSuitableForTestResult(r equestURL);
1160 }
1161
1162 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
1163 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap. end())
1164 m_delegate->printMessage("<unknown>");
1165 else
1166 m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
1167 m_delegate->printMessage(" - willSendRequest <NSURLRequest URL ");
1168 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_ str());
1169 m_delegate->printMessage(", main document URL ");
1170 m_delegate->printMessage(URLDescription(mainDocumentURL).c_str());
1171 m_delegate->printMessage(", http method ");
1172 m_delegate->printMessage(request.httpMethod().utf8().data());
1173 m_delegate->printMessage("> redirectResponse ");
1174 printResponseDescription(m_delegate, redirectResponse);
1175 m_delegate->printMessage("\n");
1176 }
1177
1178 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) {
1179 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_ str());
1180 m_delegate->printMessage(" has priority ");
1181 m_delegate->printMessage(PriorityDescription(request.priority()));
1182 m_delegate->printMessage("\n");
1183 }
1184
1185 if (m_testInterfaces->testRunner()->httpHeadersToClear()) {
1186 const set<string> *clearHeaders = m_testInterfaces->testRunner()->httpHe adersToClear();
1187 for (set<string>::const_iterator header = clearHeaders->begin(); header != clearHeaders->end(); ++header)
1188 request.clearHTTPHeaderField(WebString::fromUTF8(*header));
1189 }
1190
1191 string host = url.host();
1192 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) {
1193 if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host)
1194 && ((!mainDocumentURL.SchemeIs("http") && !mainDocumentURL.SchemeIs( "https")) || isLocalhost(mainDocumentURL.host()))
1195 && !m_delegate->allowExternalPages()) {
1196 m_delegate->printMessage(string("Blocked access to external URL ") + requestURL + "\n");
1197 blockRequest(request);
1198 return;
1199 }
1200 }
1201
1202 // Set the new substituted URL.
1203 request.setURL(m_delegate->rewriteLayoutTestsURL(request.url().spec()));
1204 }
1205
1206 void WebTestProxyBase::didReceiveResponse(WebFrame*, unsigned identifier, const blink::WebURLResponse& response)
1207 {
1208 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
1209 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap. end())
1210 m_delegate->printMessage("<unknown>");
1211 else
1212 m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
1213 m_delegate->printMessage(" - didReceiveResponse ");
1214 printResponseDescription(m_delegate, response);
1215 m_delegate->printMessage("\n");
1216 }
1217 if (m_testInterfaces->testRunner()->shouldDumpResourceResponseMIMETypes()) {
1218 GURL url = response.url();
1219 WebString mimeType = response.mimeType();
1220 m_delegate->printMessage(url.ExtractFileName());
1221 m_delegate->printMessage(" has MIME type ");
1222 // Simulate NSURLResponse's mapping of empty/unknown MIME types to appli cation/octet-stream
1223 m_delegate->printMessage(mimeType.isEmpty() ? "application/octet-stream" : mimeType.utf8().data());
1224 m_delegate->printMessage("\n");
1225 }
1226 }
1227
1228 void WebTestProxyBase::didChangeResourcePriority(WebFrame*, unsigned identifier, const blink::WebURLRequest::Priority& priority)
1229 {
1230 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) {
1231 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap. end())
1232 m_delegate->printMessage("<unknown>");
1233 else
1234 m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
1235 m_delegate->printMessage(" changed priority to ");
1236 m_delegate->printMessage(PriorityDescription(priority));
1237 m_delegate->printMessage("\n");
1238 }
1239 }
1240
1241 void WebTestProxyBase::didFinishResourceLoad(WebFrame*, unsigned identifier)
1242 {
1243 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
1244 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap. end())
1245 m_delegate->printMessage("<unknown>");
1246 else
1247 m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
1248 m_delegate->printMessage(" - didFinishLoading\n");
1249 }
1250 m_resourceIdentifierMap.erase(identifier);
1251 }
1252
1253 void WebTestProxyBase::didAddMessageToConsole(const WebConsoleMessage& message, const WebString& sourceName, unsigned sourceLine)
1254 {
1255 // This matches win DumpRenderTree's UIDelegate.cpp.
1256 if (!m_logConsoleOutput)
1257 return;
1258 string level;
1259 switch (message.level) {
1260 case WebConsoleMessage::LevelDebug:
1261 level = "DEBUG";
1262 break;
1263 case WebConsoleMessage::LevelLog:
1264 level = "MESSAGE";
1265 break;
1266 case WebConsoleMessage::LevelInfo:
1267 level = "INFO";
1268 break;
1269 case WebConsoleMessage::LevelWarning:
1270 level = "WARNING";
1271 break;
1272 case WebConsoleMessage::LevelError:
1273 level = "ERROR";
1274 break;
1275 }
1276 m_delegate->printMessage(string("CONSOLE ") + level + ": ");
1277 if (sourceLine) {
1278 char buffer[40];
1279 snprintf(buffer, sizeof(buffer), "line %d: ", sourceLine);
1280 m_delegate->printMessage(buffer);
1281 }
1282 if (!message.text.isEmpty()) {
1283 string newMessage;
1284 newMessage = message.text.utf8();
1285 size_t fileProtocol = newMessage.find("file://");
1286 if (fileProtocol != string::npos) {
1287 newMessage = newMessage.substr(0, fileProtocol)
1288 + urlSuitableForTestResult(newMessage.substr(fileProtocol));
1289 }
1290 m_delegate->printMessage(newMessage);
1291 }
1292 m_delegate->printMessage(string("\n"));
1293 }
1294
1295 void WebTestProxyBase::runModalAlertDialog(WebFrame*, const WebString& message)
1296 {
1297 m_delegate->printMessage(string("ALERT: ") + message.utf8().data() + "\n");
1298 }
1299
1300 bool WebTestProxyBase::runModalConfirmDialog(WebFrame*, const WebString& message )
1301 {
1302 m_delegate->printMessage(string("CONFIRM: ") + message.utf8().data() + "\n") ;
1303 return true;
1304 }
1305
1306 bool WebTestProxyBase::runModalPromptDialog(WebFrame* frame, const WebString& me ssage, const WebString& defaultValue, WebString*)
1307 {
1308 m_delegate->printMessage(string("PROMPT: ") + message.utf8().data() + ", def ault text: " + defaultValue.utf8().data() + "\n");
1309 return true;
1310 }
1311
1312 bool WebTestProxyBase::runModalBeforeUnloadDialog(WebFrame*, const WebString& me ssage)
1313 {
1314 m_delegate->printMessage(string("CONFIRM NAVIGATION: ") + message.utf8().dat a() + "\n");
1315 return !m_testInterfaces->testRunner()->shouldStayOnPageAfterHandlingBeforeU nload();
1316 }
1317
1318 void WebTestProxyBase::locationChangeDone(WebFrame* frame)
1319 {
1320 if (frame != m_testInterfaces->testRunner()->topLoadingFrame())
1321 return;
1322 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, true);
1323 }
1324
1325 WebNavigationPolicy WebTestProxyBase::decidePolicyForNavigation(WebFrame*, WebDa taSource::ExtraData*, const WebURLRequest& request, WebNavigationType type, WebN avigationPolicy defaultPolicy, bool isRedirect)
1326 {
1327 WebNavigationPolicy result;
1328 if (!m_testInterfaces->testRunner()->policyDelegateEnabled())
1329 return defaultPolicy;
1330
1331 m_delegate->printMessage(string("Policy delegate: attempt to load ") + URLDe scription(request.url()) + " with navigation type '" + webNavigationTypeToString (type) + "'\n");
1332 if (m_testInterfaces->testRunner()->policyDelegateIsPermissive())
1333 result = blink::WebNavigationPolicyCurrentTab;
1334 else
1335 result = blink::WebNavigationPolicyIgnore;
1336
1337 if (m_testInterfaces->testRunner()->policyDelegateShouldNotifyDone())
1338 m_testInterfaces->testRunner()->policyDelegateDone();
1339 return result;
1340 }
1341
1342 bool WebTestProxyBase::willCheckAndDispatchMessageEvent(WebFrame*, WebFrame*, We bSecurityOrigin, WebDOMMessageEvent)
1343 {
1344 if (m_testInterfaces->testRunner()->shouldInterceptPostMessage()) {
1345 m_delegate->printMessage("intercepted postMessage\n");
1346 return true;
1347 }
1348
1349 return false;
1350 }
1351
1352 void WebTestProxyBase::postSpellCheckEvent(const WebString& eventName)
1353 {
1354 if (m_testInterfaces->testRunner()->shouldDumpSpellCheckCallbacks()) {
1355 m_delegate->printMessage(string("SpellCheckEvent: ") + eventName.utf8(). data() + "\n");
1356 }
1357 }
1358
1359 void WebTestProxyBase::resetInputMethod()
1360 {
1361 // If a composition text exists, then we need to let the browser process
1362 // to cancel the input method's ongoing composition session.
1363 if (m_webWidget)
1364 m_webWidget->confirmComposition();
1365 }
1366
1367 }
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/WebTestProxy.h ('k') | content/shell/renderer/test_runner/WebTestRunner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698