1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/test_runner/web_test_proxy.h"
9 #include "base/callback_helpers.h"
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/trace_event/trace_event.h"
16 #include "components/test_runner/accessibility_controller.h"
17 #include "components/test_runner/event_sender.h"
18 #include "components/test_runner/mock_color_chooser.h"
19 #include "components/test_runner/mock_credential_manager_client.h"
20 #include "components/test_runner/mock_screen_orientation_client.h"
21 #include "components/test_runner/mock_web_speech_recognizer.h"
22 #include "components/test_runner/mock_web_user_media_client.h"
23 #include "components/test_runner/spell_check_client.h"
24 #include "components/test_runner/test_interfaces.h"
25 #include "components/test_runner/test_plugin.h"
26 #include "components/test_runner/test_runner.h"
27 #include "components/test_runner/web_test_delegate.h"
28 #include "components/test_runner/web_test_interfaces.h"
29 #include "components/test_runner/web_test_runner.h"
30 // FIXME: Including platform_canvas.h here is a layering violation.
31 #include "skia/ext/platform_canvas.h"
32 #include "third_party/WebKit/public/platform/Platform.h"
33 #include "third_party/WebKit/public/platform/WebCString.h"
34 #include "third_party/WebKit/public/platform/WebClipboard.h"
35 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
36 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h"
37 #include "third_party/WebKit/public/platform/WebURLError.h"
38 #include "third_party/WebKit/public/platform/WebURLRequest.h"
39 #include "third_party/WebKit/public/platform/WebURLResponse.h"
40 #include "third_party/WebKit/public/web/WebAXEnums.h"
41 #include "third_party/WebKit/public/web/WebAXObject.h"
42 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
43 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
44 #include "third_party/WebKit/public/web/WebDataSource.h"
45 #include "third_party/WebKit/public/web/WebDocument.h"
46 #include "third_party/WebKit/public/web/WebElement.h"
47 #include "third_party/WebKit/public/web/WebHistoryItem.h"
48 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebNode.h"
50 #include "third_party/WebKit/public/web/WebPagePopup.h"
51 #include "third_party/WebKit/public/web/WebPluginParams.h"
52 #include "third_party/WebKit/public/web/WebPrintParams.h"
53 #include "third_party/WebKit/public/web/WebRange.h"
54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
55 #include "third_party/WebKit/public/web/WebView.h"
56 #include "third_party/WebKit/public/web/WebWidgetClient.h"
58 namespace test_runner
{
62 class CaptureCallback
: public blink::WebCompositeAndReadbackAsyncCallback
{
64 CaptureCallback(const base::Callback
<void(const SkBitmap
&)>& callback
);
65 virtual ~CaptureCallback();
67 void set_wait_for_popup(bool wait
) { wait_for_popup_
= wait
; }
68 void set_popup_position(const gfx::Point
& position
) {
69 popup_position_
= position
;
72 // WebCompositeAndReadbackAsyncCallback implementation.
73 virtual void didCompositeAndReadback(const SkBitmap
& bitmap
);
76 base::Callback
<void(const SkBitmap
&)> callback_
;
77 SkBitmap main_bitmap_
;
79 gfx::Point popup_position_
;
82 class LayoutAndPaintCallback
: public blink::WebLayoutAndPaintAsyncCallback
{
84 LayoutAndPaintCallback(const base::Closure
& callback
)
85 : callback_(callback
), wait_for_popup_(false) {
87 virtual ~LayoutAndPaintCallback() {
90 void set_wait_for_popup(bool wait
) { wait_for_popup_
= wait
; }
92 // WebLayoutAndPaintAsyncCallback implementation.
93 virtual void didLayoutAndPaint();
96 base::Closure callback_
;
100 class HostMethodTask
: public WebMethodTask
<WebTestProxyBase
> {
102 typedef void (WebTestProxyBase::*CallbackMethodType
)();
103 HostMethodTask(WebTestProxyBase
* object
, CallbackMethodType callback
)
104 : WebMethodTask
<WebTestProxyBase
>(object
), callback_(callback
) {}
106 void RunIfValid() override
{ (object_
->*callback_
)(); }
109 CallbackMethodType callback_
;
112 void PrintFrameDescription(WebTestDelegate
* delegate
, blink::WebFrame
* frame
) {
113 std::string name8
= frame
->uniqueName().utf8();
114 if (frame
== frame
->view()->mainFrame()) {
115 if (!name8
.length()) {
116 delegate
->PrintMessage("main frame");
119 delegate
->PrintMessage(std::string("main frame \"") + name8
+ "\"");
122 if (!name8
.length()) {
123 delegate
->PrintMessage("frame (anonymous)");
126 delegate
->PrintMessage(std::string("frame \"") + name8
+ "\"");
129 void PrintFrameuserGestureStatus(WebTestDelegate
* delegate
,
130 blink::WebFrame
* frame
,
132 bool is_user_gesture
=
133 blink::WebUserGestureIndicator::isProcessingUserGesture();
134 delegate
->PrintMessage(std::string("Frame with user gesture \"") +
135 (is_user_gesture
? "true" : "false") + "\"" + msg
);
138 // Used to write a platform neutral file:/// URL by taking the
139 // filename and its directory. (e.g., converts
140 // "file:///tmp/foo/bar.txt" to just "bar.txt").
141 std::string
DescriptionSuitableForTestResult(const std::string
& url
) {
142 if (url
.empty() || std::string::npos
== url
.find("file://"))
145 size_t pos
= url
.rfind('/');
146 if (pos
== std::string::npos
|| !pos
)
147 return "ERROR:" + url
;
148 pos
= url
.rfind('/', pos
- 1);
149 if (pos
== std::string::npos
)
150 return "ERROR:" + url
;
152 return url
.substr(pos
+ 1);
155 void PrintResponseDescription(WebTestDelegate
* delegate
,
156 const blink::WebURLResponse
& response
) {
157 if (response
.isNull()) {
158 delegate
->PrintMessage("(null)");
161 delegate
->PrintMessage(base::StringPrintf(
162 "<NSURLResponse %s, http status code %d>",
163 DescriptionSuitableForTestResult(response
.url().spec()).c_str(),
164 response
.httpStatusCode()));
167 std::string
URLDescription(const GURL
& url
) {
168 if (url
.SchemeIs(url::kFileScheme
))
169 return url
.ExtractFileName();
170 return url
.possibly_invalid_spec();
173 std::string
PriorityDescription(
174 const blink::WebURLRequest::Priority
& priority
) {
176 case blink::WebURLRequest::PriorityVeryLow
:
178 case blink::WebURLRequest::PriorityLow
:
180 case blink::WebURLRequest::PriorityMedium
:
182 case blink::WebURLRequest::PriorityHigh
:
184 case blink::WebURLRequest::PriorityVeryHigh
:
186 case blink::WebURLRequest::PriorityUnresolved
:
192 void BlockRequest(blink::WebURLRequest
& request
) {
193 request
.setURL(GURL("255.255.255.255"));
196 bool IsLocalHost(const std::string
& host
) {
197 return host
== "127.0.0.1" || host
== "localhost";
200 bool IsTestHost(const std::string
& host
) {
201 return EndsWith(host
, ".test", false);
204 bool HostIsUsedBySomeTestsToGenerateError(const std::string
& host
) {
205 return host
== "255.255.255.255";
208 // Used to write a platform neutral file:/// URL by only taking the filename
209 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt").
210 std::string
URLSuitableForTestResult(const std::string
& url
) {
211 if (url
.empty() || std::string::npos
== url
.find("file://"))
214 size_t pos
= url
.rfind('/');
215 if (pos
== std::string::npos
) {
217 pos
= url
.rfind('\\');
218 if (pos
== std::string::npos
)
224 std::string filename
= url
.substr(pos
+ 1);
225 if (filename
.empty())
226 return "file:"; // A WebKit test has this in its expected output.
230 // WebNavigationType debugging strings taken from PolicyDelegate.mm.
231 const char* kLinkClickedString
= "link clicked";
232 const char* kFormSubmittedString
= "form submitted";
233 const char* kBackForwardString
= "back/forward";
234 const char* kReloadString
= "reload";
235 const char* kFormResubmittedString
= "form resubmitted";
236 const char* kOtherString
= "other";
237 const char* kIllegalString
= "illegal value";
239 // Get a debugging string from a WebNavigationType.
240 const char* WebNavigationTypeToString(blink::WebNavigationType type
) {
242 case blink::WebNavigationTypeLinkClicked
:
243 return kLinkClickedString
;
244 case blink::WebNavigationTypeFormSubmitted
:
245 return kFormSubmittedString
;
246 case blink::WebNavigationTypeBackForward
:
247 return kBackForwardString
;
248 case blink::WebNavigationTypeReload
:
249 return kReloadString
;
250 case blink::WebNavigationTypeFormResubmitted
:
251 return kFormResubmittedString
;
252 case blink::WebNavigationTypeOther
:
255 return kIllegalString
;
258 const char* kPolicyIgnore
= "Ignore";
259 const char* kPolicyDownload
= "download";
260 const char* kPolicyCurrentTab
= "current tab";
261 const char* kPolicyNewBackgroundTab
= "new background tab";
262 const char* kPolicyNewForegroundTab
= "new foreground tab";
263 const char* kPolicyNewWindow
= "new window";
264 const char* kPolicyNewPopup
= "new popup";
266 const char* WebNavigationPolicyToString(blink::WebNavigationPolicy policy
) {
268 case blink::WebNavigationPolicyIgnore
:
269 return kPolicyIgnore
;
270 case blink::WebNavigationPolicyDownload
:
271 return kPolicyDownload
;
272 case blink::WebNavigationPolicyCurrentTab
:
273 return kPolicyCurrentTab
;
274 case blink::WebNavigationPolicyNewBackgroundTab
:
275 return kPolicyNewBackgroundTab
;
276 case blink::WebNavigationPolicyNewForegroundTab
:
277 return kPolicyNewForegroundTab
;
278 case blink::WebNavigationPolicyNewWindow
:
279 return kPolicyNewWindow
;
280 case blink::WebNavigationPolicyNewPopup
:
281 return kPolicyNewPopup
;
283 return kIllegalString
;
286 std::string
DumpFrameHeaderIfNeeded(blink::WebFrame
* frame
) {
289 // Add header for all but the main frame. Skip empty frames.
290 if (frame
->parent() && !frame
->document().documentElement().isNull()) {
291 result
.append("\n--------\nFrame: '");
292 result
.append(frame
->uniqueName().utf8().data());
293 result
.append("'\n--------\n");
299 std::string
DumpFramesAsMarkup(blink::WebFrame
* frame
, bool recursive
) {
300 std::string result
= DumpFrameHeaderIfNeeded(frame
);
301 result
.append(frame
->contentAsMarkup().utf8());
305 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
306 child
= child
->nextSibling())
307 result
.append(DumpFramesAsMarkup(child
, recursive
));
313 std::string
DumpDocumentText(blink::WebFrame
* frame
) {
314 return frame
->document().contentAsTextForTesting().utf8();
317 std::string
DumpFramesAsText(blink::WebFrame
* frame
, bool recursive
) {
318 std::string result
= DumpFrameHeaderIfNeeded(frame
);
319 result
.append(DumpDocumentText(frame
));
323 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
324 child
= child
->nextSibling())
325 result
.append(DumpFramesAsText(child
, recursive
));
331 std::string
DumpFramesAsPrintedText(blink::WebFrame
* frame
, bool recursive
) {
332 // Cannot do printed format for anything other than HTML
333 if (!frame
->document().isHTMLDocument())
334 return std::string();
336 std::string result
= DumpFrameHeaderIfNeeded(frame
);
338 frame
->layoutTreeAsText(blink::WebFrame::LayoutAsTextPrinting
).utf8());
342 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
343 child
= child
->nextSibling())
344 result
.append(DumpFramesAsPrintedText(child
, recursive
));
350 std::string
DumpFrameScrollPosition(blink::WebFrame
* frame
, bool recursive
) {
352 blink::WebSize offset
= frame
->scrollOffset();
353 if (offset
.width
> 0 || offset
.height
> 0) {
354 if (frame
->parent()) {
356 std::string("frame '") + frame
->uniqueName().utf8().data() + "' ";
359 &result
, "scrolled to %d,%d\n", offset
.width
, offset
.height
);
364 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
365 child
= child
->nextSibling())
366 result
+= DumpFrameScrollPosition(child
, recursive
);
370 std::string
DumpAllBackForwardLists(TestInterfaces
* interfaces
,
371 WebTestDelegate
* delegate
) {
373 const std::vector
<WebTestProxyBase
*>& window_list
=
374 interfaces
->GetWindowList();
375 for (size_t i
= 0; i
< window_list
.size(); ++i
)
376 result
.append(delegate
->DumpHistoryForWindow(window_list
.at(i
)));
381 WebTestProxyBase::WebTestProxyBase()
382 : web_test_interfaces_(NULL
),
383 test_interfaces_(NULL
),
386 spellcheck_(new SpellCheckClient(this)),
391 WebTestProxyBase::~WebTestProxyBase() {
392 test_interfaces_
->WindowClosed(this);
395 void WebTestProxyBase::SetInterfaces(WebTestInterfaces
* interfaces
) {
396 web_test_interfaces_
= interfaces
;
397 test_interfaces_
= interfaces
->GetTestInterfaces();
398 test_interfaces_
->WindowOpened(this);
401 WebTestInterfaces
* WebTestProxyBase::GetInterfaces() {
402 return web_test_interfaces_
;
405 void WebTestProxyBase::SetDelegate(WebTestDelegate
* delegate
) {
406 delegate_
= delegate
;
407 spellcheck_
->SetDelegate(delegate
);
408 if (speech_recognizer_
.get())
409 speech_recognizer_
->SetDelegate(delegate
);
412 WebTestDelegate
* WebTestProxyBase::GetDelegate() {
416 blink::WebView
* WebTestProxyBase::GetWebView() const {
418 // TestRunner does not support popup widgets. So |web_widget|_ is always a
420 return static_cast<blink::WebView
*>(web_widget_
);
423 void WebTestProxyBase::Reset() {
425 animate_scheduled_
= false;
426 resource_identifier_map_
.clear();
427 log_console_output_
= true;
428 accept_languages_
= "";
431 blink::WebSpellCheckClient
* WebTestProxyBase::GetSpellCheckClient() const {
432 return spellcheck_
.get();
435 blink::WebColorChooser
* WebTestProxyBase::CreateColorChooser(
436 blink::WebColorChooserClient
* client
,
437 const blink::WebColor
& color
,
438 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
) {
439 // This instance is deleted by WebCore::ColorInputType
440 return new MockColorChooser(client
, delegate_
, this);
443 bool WebTestProxyBase::RunFileChooser(
444 const blink::WebFileChooserParams
& params
,
445 blink::WebFileChooserCompletion
* completion
) {
446 delegate_
->PrintMessage("Mock: Opening a file chooser.\n");
447 // FIXME: Add ability to set file names to a file upload control.
451 void WebTestProxyBase::ShowValidationMessage(
452 const base::string16
& message
,
453 const base::string16
& sub_message
) {
454 delegate_
->PrintMessage("ValidationMessageClient: main-message=" +
455 base::UTF16ToUTF8(message
) + " sub-message=" +
456 base::UTF16ToUTF8(sub_message
) + "\n");
459 std::string
WebTestProxyBase::CaptureTree(bool debug_render_tree
) {
460 bool should_dump_custom_text
=
461 test_interfaces_
->GetTestRunner()->shouldDumpAsCustomText();
462 bool should_dump_as_text
=
463 test_interfaces_
->GetTestRunner()->shouldDumpAsText();
464 bool should_dump_as_markup
=
465 test_interfaces_
->GetTestRunner()->shouldDumpAsMarkup();
466 bool should_dump_as_printed
= test_interfaces_
->GetTestRunner()->isPrinting();
467 blink::WebFrame
* frame
= GetWebView()->mainFrame();
468 std::string data_utf8
;
469 if (should_dump_custom_text
) {
470 // Append a newline for the test driver.
471 data_utf8
= test_interfaces_
->GetTestRunner()->customDumpText() + "\n";
472 } else if (should_dump_as_text
) {
474 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsText();
475 data_utf8
= should_dump_as_printed
?
476 DumpFramesAsPrintedText(frame
, recursive
) :
477 DumpFramesAsText(frame
, recursive
);
478 } else if (should_dump_as_markup
) {
480 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsMarkup();
481 // Append a newline for the test driver.
482 data_utf8
= DumpFramesAsMarkup(frame
, recursive
);
484 bool recursive
= test_interfaces_
->GetTestRunner()
485 ->shouldDumpChildFrameScrollPositions();
486 blink::WebFrame::LayoutAsTextControls layout_text_behavior
=
487 blink::WebFrame::LayoutAsTextNormal
;
488 if (should_dump_as_printed
)
489 layout_text_behavior
|= blink::WebFrame::LayoutAsTextPrinting
;
490 if (debug_render_tree
)
491 layout_text_behavior
|= blink::WebFrame::LayoutAsTextDebug
;
492 data_utf8
= frame
->layoutTreeAsText(layout_text_behavior
).utf8();
493 data_utf8
+= DumpFrameScrollPosition(frame
, recursive
);
496 if (test_interfaces_
->GetTestRunner()->ShouldDumpBackForwardList())
497 data_utf8
+= DumpAllBackForwardLists(test_interfaces_
, delegate_
);
502 void WebTestProxyBase::DrawSelectionRect(SkCanvas
* canvas
) {
503 // See if we need to draw the selection bounds rect. Selection bounds
504 // rect is the rect enclosing the (possibly transformed) selection.
505 // The rect should be drawn after everything is laid out and painted.
506 if (!test_interfaces_
->GetTestRunner()->shouldDumpSelectionRect())
508 // If there is a selection rect - draw a red 1px border enclosing rect
509 blink::WebRect wr
= GetWebView()->mainFrame()->selectionBoundsRect();
512 // Render a red rectangle bounding selection rect
514 paint
.setColor(0xFFFF0000); // Fully opaque red
515 paint
.setStyle(SkPaint::kStroke_Style
);
516 paint
.setFlags(SkPaint::kAntiAlias_Flag
);
517 paint
.setStrokeWidth(1.0f
);
518 SkIRect rect
; // Bounding rect
519 rect
.set(wr
.x
, wr
.y
, wr
.x
+ wr
.width
, wr
.y
+ wr
.height
);
520 canvas
->drawIRect(rect
, paint
);
523 void WebTestProxyBase::SetAcceptLanguages(const std::string
& accept_languages
) {
524 bool notify
= accept_languages_
!= accept_languages
;
525 accept_languages_
= accept_languages
;
528 GetWebView()->acceptLanguagesChanged();
531 void WebTestProxyBase::CopyImageAtAndCapturePixels(
532 int x
, int y
, const base::Callback
<void(const SkBitmap
&)>& callback
) {
533 DCHECK(!callback
.is_null());
534 uint64_t sequence_number
= blink::Platform::current()->clipboard()->
535 sequenceNumber(blink::WebClipboard::Buffer());
536 GetWebView()->copyImageAt(blink::WebPoint(x
, y
));
537 if (sequence_number
== blink::Platform::current()->clipboard()->
538 sequenceNumber(blink::WebClipboard::Buffer())) {
539 SkBitmap emptyBitmap
;
540 callback
.Run(emptyBitmap
);
544 blink::WebData data
= blink::Platform::current()->clipboard()->readImage(
545 blink::WebClipboard::Buffer());
546 blink::WebImage image
= blink::WebImage::fromData(data
, blink::WebSize());
547 const SkBitmap
& bitmap
= image
.getSkBitmap();
548 SkAutoLockPixels
autoLock(bitmap
);
549 callback
.Run(bitmap
);
552 void WebTestProxyBase::CapturePixelsForPrinting(
553 const base::Callback
<void(const SkBitmap
&)>& callback
) {
554 web_widget_
->layout();
556 blink::WebSize page_size_in_pixels
= web_widget_
->size();
557 blink::WebFrame
* web_frame
= GetWebView()->mainFrame();
559 int page_count
= web_frame
->printBegin(page_size_in_pixels
);
560 int totalHeight
= page_count
* (page_size_in_pixels
.height
+ 1) - 1;
562 bool is_opaque
= false;
563 skia::RefPtr
<SkCanvas
> canvas(skia::AdoptRef(skia::TryCreateBitmapCanvas(
564 page_size_in_pixels
.width
, totalHeight
, is_opaque
)));
566 callback
.Run(SkBitmap());
569 web_frame
->printPagesWithBoundaries(canvas
.get(), page_size_in_pixels
);
570 web_frame
->printEnd();
572 DrawSelectionRect(canvas
.get());
573 SkBaseDevice
* device
= skia::GetTopDevice(*canvas
);
574 const SkBitmap
& bitmap
= device
->accessBitmap(false);
575 callback
.Run(bitmap
);
578 CaptureCallback::CaptureCallback(
579 const base::Callback
<void(const SkBitmap
&)>& callback
)
580 : callback_(callback
), wait_for_popup_(false) {
583 CaptureCallback::~CaptureCallback() {
586 void CaptureCallback::didCompositeAndReadback(const SkBitmap
& bitmap
) {
587 TRACE_EVENT2("shell",
588 "CaptureCallback::didCompositeAndReadback",
590 bitmap
.info().width(),
592 bitmap
.info().height());
593 if (!wait_for_popup_
) {
594 callback_
.Run(bitmap
);
598 if (main_bitmap_
.isNull()) {
599 bitmap
.deepCopyTo(&main_bitmap_
);
602 SkCanvas
canvas(main_bitmap_
);
603 canvas
.drawBitmap(bitmap
, popup_position_
.x(), popup_position_
.y());
604 callback_
.Run(main_bitmap_
);
608 void WebTestProxyBase::CapturePixelsAsync(
609 const base::Callback
<void(const SkBitmap
&)>& callback
) {
610 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
611 DCHECK(!callback
.is_null());
613 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
614 if (drag_image_
.isNull()) {
615 // This means the test called dumpDragImage but did not initiate a drag.
616 // Return a blank image so that the test fails.
618 bitmap
.allocN32Pixels(1, 1);
620 SkAutoLockPixels
lock(bitmap
);
621 bitmap
.eraseColor(0);
623 callback
.Run(bitmap
);
627 callback
.Run(drag_image_
.getSkBitmap());
631 if (test_interfaces_
->GetTestRunner()->isPrinting()) {
632 base::MessageLoopProxy::current()->PostTask(
634 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting
,
635 base::Unretained(this),
640 CaptureCallback
* capture_callback
= new CaptureCallback(base::Bind(
641 &WebTestProxyBase::DidCapturePixelsAsync
, base::Unretained(this),
643 web_widget_
->compositeAndReadbackAsync(capture_callback
);
644 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
645 capture_callback
->set_wait_for_popup(true);
646 capture_callback
->set_popup_position(popup
->positionRelativeToOwner());
647 popup
->compositeAndReadbackAsync(capture_callback
);
651 void WebTestProxyBase::DidCapturePixelsAsync(
652 const base::Callback
<void(const SkBitmap
&)>& callback
,
653 const SkBitmap
& bitmap
) {
654 SkCanvas
canvas(bitmap
);
655 DrawSelectionRect(&canvas
);
656 if (!callback
.is_null())
657 callback
.Run(bitmap
);
660 void WebTestProxyBase::SetLogConsoleOutput(bool enabled
) {
661 log_console_output_
= enabled
;
664 void LayoutAndPaintCallback::didLayoutAndPaint() {
665 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint");
666 if (wait_for_popup_
) {
667 wait_for_popup_
= false;
671 if (!callback_
.is_null())
676 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure
& callback
) {
677 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen");
679 LayoutAndPaintCallback
* layout_and_paint_callback
=
680 new LayoutAndPaintCallback(callback
);
681 web_widget_
->layoutAndPaintAsync(layout_and_paint_callback
);
682 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
683 layout_and_paint_callback
->set_wait_for_popup(true);
684 popup
->layoutAndPaintAsync(layout_and_paint_callback
);
688 void WebTestProxyBase::GetScreenOrientationForTesting(
689 blink::WebScreenInfo
& screen_info
) {
690 if (!screen_orientation_client_
)
692 // Override screen orientation information with mock data.
693 screen_info
.orientationType
=
694 screen_orientation_client_
->CurrentOrientationType();
695 screen_info
.orientationAngle
=
696 screen_orientation_client_
->CurrentOrientationAngle();
699 MockScreenOrientationClient
*
700 WebTestProxyBase::GetScreenOrientationClientMock() {
701 if (!screen_orientation_client_
.get()) {
702 screen_orientation_client_
.reset(new MockScreenOrientationClient
);
704 return screen_orientation_client_
.get();
707 MockWebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizerMock() {
708 if (!speech_recognizer_
.get()) {
709 speech_recognizer_
.reset(new MockWebSpeechRecognizer());
710 speech_recognizer_
->SetDelegate(delegate_
);
712 return speech_recognizer_
.get();
715 MockCredentialManagerClient
*
716 WebTestProxyBase::GetCredentialManagerClientMock() {
717 if (!credential_manager_client_
.get())
718 credential_manager_client_
.reset(new MockCredentialManagerClient());
719 return credential_manager_client_
.get();
722 void WebTestProxyBase::ScheduleAnimation() {
723 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
726 if (!animate_scheduled_
) {
727 animate_scheduled_
= true;
728 delegate_
->PostDelayedTask(
729 new HostMethodTask(this, &WebTestProxyBase::AnimateNow
), 1);
733 void WebTestProxyBase::AnimateNow() {
734 if (animate_scheduled_
) {
735 animate_scheduled_
= false;
736 web_widget_
->beginFrame(blink::WebBeginFrameArgs(0.0, 0.0, 0.0));
737 web_widget_
->layout();
738 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
739 popup
->beginFrame(blink::WebBeginFrameArgs(0.0, 0.0, 0.0));
745 void WebTestProxyBase::PostAccessibilityEvent(const blink::WebAXObject
& obj
,
746 blink::WebAXEvent event
) {
747 // Only hook the accessibility events occured during the test run.
748 // This check prevents false positives in WebLeakDetector.
749 // The pending tasks in browser/renderer message queue may trigger
750 // accessibility events,
751 // and AccessibilityController will hold on to their target nodes if we don't
753 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
756 if (event
== blink::WebAXEventFocus
)
757 test_interfaces_
->GetAccessibilityController()->SetFocusedElement(obj
);
759 const char* event_name
= NULL
;
761 case blink::WebAXEventActiveDescendantChanged
:
762 event_name
= "ActiveDescendantChanged";
764 case blink::WebAXEventAlert
:
765 event_name
= "Alert";
767 case blink::WebAXEventAriaAttributeChanged
:
768 event_name
= "AriaAttributeChanged";
770 case blink::WebAXEventAutocorrectionOccured
:
771 event_name
= "AutocorrectionOccured";
773 case blink::WebAXEventBlur
:
776 case blink::WebAXEventCheckedStateChanged
:
777 event_name
= "CheckedStateChanged";
779 case blink::WebAXEventChildrenChanged
:
780 event_name
= "ChildrenChanged";
782 case blink::WebAXEventFocus
:
783 event_name
= "Focus";
785 case blink::WebAXEventHide
:
788 case blink::WebAXEventInvalidStatusChanged
:
789 event_name
= "InvalidStatusChanged";
791 case blink::WebAXEventLayoutComplete
:
792 event_name
= "LayoutComplete";
794 case blink::WebAXEventLiveRegionChanged
:
795 event_name
= "LiveRegionChanged";
797 case blink::WebAXEventLoadComplete
:
798 event_name
= "LoadComplete";
800 case blink::WebAXEventLocationChanged
:
801 event_name
= "LocationChanged";
803 case blink::WebAXEventMenuListItemSelected
:
804 event_name
= "MenuListItemSelected";
806 case blink::WebAXEventMenuListItemUnselected
:
807 event_name
= "MenuListItemUnselected";
809 case blink::WebAXEventMenuListValueChanged
:
810 event_name
= "MenuListValueChanged";
812 case blink::WebAXEventRowCollapsed
:
813 event_name
= "RowCollapsed";
815 case blink::WebAXEventRowCountChanged
:
816 event_name
= "RowCountChanged";
818 case blink::WebAXEventRowExpanded
:
819 event_name
= "RowExpanded";
821 case blink::WebAXEventScrollPositionChanged
:
822 event_name
= "ScrollPositionChanged";
824 case blink::WebAXEventScrolledToAnchor
:
825 event_name
= "ScrolledToAnchor";
827 case blink::WebAXEventSelectedChildrenChanged
:
828 event_name
= "SelectedChildrenChanged";
830 case blink::WebAXEventSelectedTextChanged
:
831 event_name
= "SelectedTextChanged";
833 case blink::WebAXEventShow
:
836 case blink::WebAXEventTextChanged
:
837 event_name
= "TextChanged";
839 case blink::WebAXEventTextInserted
:
840 event_name
= "TextInserted";
842 case blink::WebAXEventTextRemoved
:
843 event_name
= "TextRemoved";
845 case blink::WebAXEventValueChanged
:
846 event_name
= "ValueChanged";
849 event_name
= "Unknown";
853 test_interfaces_
->GetAccessibilityController()->NotificationReceived(
856 if (test_interfaces_
->GetAccessibilityController()
857 ->ShouldLogAccessibilityEvents()) {
858 std::string
message("AccessibilityNotification - ");
859 message
+= event_name
;
861 blink::WebNode node
= obj
.node();
862 if (!node
.isNull() && node
.isElementNode()) {
863 blink::WebElement element
= node
.to
<blink::WebElement
>();
864 if (element
.hasAttribute("id")) {
866 message
+= element
.getAttribute("id").utf8().data();
870 delegate_
->PrintMessage(message
+ "\n");
874 void WebTestProxyBase::StartDragging(blink::WebLocalFrame
* frame
,
875 const blink::WebDragData
& data
,
876 blink::WebDragOperationsMask mask
,
877 const blink::WebImage
& image
,
878 const blink::WebPoint
& point
) {
879 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
880 if (drag_image_
.isNull())
883 // When running a test, we need to fake a drag drop operation otherwise
884 // Windows waits for real mouse events to know when the drag is over.
885 test_interfaces_
->GetEventSender()->DoDragDrop(data
, mask
);
888 // The output from these methods in layout test mode should match that
889 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
891 void WebTestProxyBase::DidChangeSelection(bool is_empty_callback
) {
892 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
893 delegate_
->PrintMessage(
895 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
898 void WebTestProxyBase::DidChangeContents() {
899 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
900 delegate_
->PrintMessage(
901 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
904 bool WebTestProxyBase::CreateView(blink::WebLocalFrame
* frame
,
905 const blink::WebURLRequest
& request
,
906 const blink::WebWindowFeatures
& features
,
907 const blink::WebString
& frame_name
,
908 blink::WebNavigationPolicy policy
,
909 bool suppress_opener
) {
910 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
911 delegate_
->PrintMessage("Default policy for createView for '" +
912 URLDescription(request
.url()) + "' is '" +
913 WebNavigationPolicyToString(policy
) + "'\n");
916 if (!test_interfaces_
->GetTestRunner()->canOpenWindows())
918 if (test_interfaces_
->GetTestRunner()->shouldDumpCreateView())
919 delegate_
->PrintMessage(std::string("createView(") +
920 URLDescription(request
.url()) + ")\n");
924 blink::WebPlugin
* WebTestProxyBase::CreatePlugin(
925 blink::WebLocalFrame
* frame
,
926 const blink::WebPluginParams
& params
) {
927 if (TestPlugin::IsSupportedMimeType(params
.mimeType
))
928 return TestPlugin::create(frame
, params
, delegate_
);
929 return delegate_
->CreatePluginPlaceholder(frame
, params
);
932 void WebTestProxyBase::SetStatusText(const blink::WebString
& text
) {
933 if (!test_interfaces_
->GetTestRunner()->shouldDumpStatusCallbacks())
935 delegate_
->PrintMessage(
936 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") +
937 text
.utf8().data() + "\n");
940 void WebTestProxyBase::DidStopLoading() {
941 if (test_interfaces_
->GetTestRunner()->shouldDumpProgressFinishedCallback())
942 delegate_
->PrintMessage("postProgressFinishedNotification\n");
945 void WebTestProxyBase::ShowContextMenu(
946 blink::WebLocalFrame
* frame
,
947 const blink::WebContextMenuData
& context_menu_data
) {
948 test_interfaces_
->GetEventSender()->SetContextMenuData(context_menu_data
);
951 blink::WebUserMediaClient
* WebTestProxyBase::GetUserMediaClient() {
952 if (!user_media_client_
.get())
953 user_media_client_
.reset(new MockWebUserMediaClient(delegate_
));
954 return user_media_client_
.get();
957 // Simulate a print by going into print mode and then exit straight away.
958 void WebTestProxyBase::PrintPage(blink::WebLocalFrame
* frame
) {
959 blink::WebSize page_size_in_pixels
= web_widget_
->size();
960 if (page_size_in_pixels
.isEmpty())
962 blink::WebPrintParams
printParams(page_size_in_pixels
);
963 frame
->printBegin(printParams
);
967 blink::WebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizer() {
968 return GetSpeechRecognizerMock();
971 bool WebTestProxyBase::RequestPointerLock() {
972 return test_interfaces_
->GetTestRunner()->RequestPointerLock();
975 void WebTestProxyBase::RequestPointerUnlock() {
976 test_interfaces_
->GetTestRunner()->RequestPointerUnlock();
979 bool WebTestProxyBase::IsPointerLocked() {
980 return test_interfaces_
->GetTestRunner()->isPointerLocked();
983 void WebTestProxyBase::DidFocus() {
984 delegate_
->SetFocus(this, true);
987 void WebTestProxyBase::DidBlur() {
988 delegate_
->SetFocus(this, false);
991 void WebTestProxyBase::SetToolTipText(const blink::WebString
& text
,
992 blink::WebTextDirection direction
) {
993 test_interfaces_
->GetTestRunner()->setToolTipText(text
);
996 void WebTestProxyBase::DidOpenChooser() {
1000 void WebTestProxyBase::DidCloseChooser() {
1004 bool WebTestProxyBase::IsChooserShown() {
1005 return 0 < chooser_count_
;
1008 void WebTestProxyBase::LoadURLExternally(
1009 blink::WebLocalFrame
* frame
,
1010 const blink::WebURLRequest
& request
,
1011 blink::WebNavigationPolicy policy
,
1012 const blink::WebString
& suggested_name
) {
1013 if (test_interfaces_
->GetTestRunner()->shouldWaitUntilExternalURLLoad()) {
1014 if (policy
== blink::WebNavigationPolicyDownload
) {
1015 delegate_
->PrintMessage(
1016 std::string("Downloading URL with suggested filename \"") +
1017 suggested_name
.utf8() + "\"\n");
1019 delegate_
->PrintMessage(std::string("Loading URL externally - \"") +
1020 URLDescription(request
.url()) + "\"\n");
1022 delegate_
->TestFinished();
1026 void WebTestProxyBase::DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) {
1027 if (!test_interfaces_
->GetTestRunner()->topLoadingFrame())
1028 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, false);
1030 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1031 PrintFrameDescription(delegate_
, frame
);
1032 delegate_
->PrintMessage(" - didStartProvisionalLoadForFrame\n");
1035 if (test_interfaces_
->GetTestRunner()
1036 ->shouldDumpUserGestureInFrameLoadCallbacks()) {
1037 PrintFrameuserGestureStatus(
1038 delegate_
, frame
, " - in didStartProvisionalLoadForFrame\n");
1042 void WebTestProxyBase::DidReceiveServerRedirectForProvisionalLoad(
1043 blink::WebLocalFrame
* frame
) {
1044 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1045 PrintFrameDescription(delegate_
, frame
);
1046 delegate_
->PrintMessage(
1047 " - didReceiveServerRedirectForProvisionalLoadForFrame\n");
1051 bool WebTestProxyBase::DidFailProvisionalLoad(
1052 blink::WebLocalFrame
* frame
,
1053 const blink::WebURLError
& error
,
1054 blink::WebHistoryCommitType commit_type
) {
1055 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1056 PrintFrameDescription(delegate_
, frame
);
1057 delegate_
->PrintMessage(" - didFailProvisionalLoadWithError\n");
1059 CheckDone(frame
, MainResourceLoadFailed
);
1060 return !frame
->provisionalDataSource();
1063 void WebTestProxyBase::DidCommitProvisionalLoad(
1064 blink::WebLocalFrame
* frame
,
1065 const blink::WebHistoryItem
& history_item
,
1066 blink::WebHistoryCommitType history_type
) {
1067 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1068 PrintFrameDescription(delegate_
, frame
);
1069 delegate_
->PrintMessage(" - didCommitLoadForFrame\n");
1073 void WebTestProxyBase::DidReceiveTitle(blink::WebLocalFrame
* frame
,
1074 const blink::WebString
& title
,
1075 blink::WebTextDirection direction
) {
1076 blink::WebCString title8
= title
.utf8();
1078 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1079 PrintFrameDescription(delegate_
, frame
);
1080 delegate_
->PrintMessage(std::string(" - didReceiveTitle: ") +
1081 title8
.data() + "\n");
1084 if (test_interfaces_
->GetTestRunner()->shouldDumpTitleChanges())
1085 delegate_
->PrintMessage(std::string("TITLE CHANGED: '") + title8
.data() +
1089 void WebTestProxyBase::DidChangeIcon(blink::WebLocalFrame
* frame
,
1090 blink::WebIconURL::Type icon_type
) {
1091 if (test_interfaces_
->GetTestRunner()->shouldDumpIconChanges()) {
1092 PrintFrameDescription(delegate_
, frame
);
1093 delegate_
->PrintMessage(std::string(" - didChangeIcons\n"));
1097 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame
* frame
) {
1098 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1099 PrintFrameDescription(delegate_
, frame
);
1100 delegate_
->PrintMessage(" - didFinishDocumentLoadForFrame\n");
1104 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame
* frame
) {
1105 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1106 PrintFrameDescription(delegate_
, frame
);
1107 delegate_
->PrintMessage(" - didHandleOnloadEventsForFrame\n");
1111 void WebTestProxyBase::DidFailLoad(blink::WebLocalFrame
* frame
,
1112 const blink::WebURLError
& error
,
1113 blink::WebHistoryCommitType commit_type
) {
1114 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1115 PrintFrameDescription(delegate_
, frame
);
1116 delegate_
->PrintMessage(" - didFailLoadWithError\n");
1118 CheckDone(frame
, MainResourceLoadFailed
);
1121 void WebTestProxyBase::DidFinishLoad(blink::WebLocalFrame
* frame
) {
1122 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1123 PrintFrameDescription(delegate_
, frame
);
1124 delegate_
->PrintMessage(" - didFinishLoadForFrame\n");
1126 CheckDone(frame
, LoadFinished
);
1129 void WebTestProxyBase::DidDetectXSS(blink::WebLocalFrame
* frame
,
1130 const blink::WebURL
& insecure_url
,
1131 bool did_block_entire_page
) {
1132 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks())
1133 delegate_
->PrintMessage("didDetectXSS\n");
1136 void WebTestProxyBase::DidDispatchPingLoader(blink::WebLocalFrame
* frame
,
1137 const blink::WebURL
& url
) {
1138 if (test_interfaces_
->GetTestRunner()->shouldDumpPingLoaderCallbacks())
1139 delegate_
->PrintMessage(std::string("PingLoader dispatched to '") +
1140 URLDescription(url
).c_str() + "'.\n");
1143 void WebTestProxyBase::WillRequestResource(
1144 blink::WebLocalFrame
* frame
,
1145 const blink::WebCachedURLRequest
& request
) {
1146 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceRequestCallbacks()) {
1147 PrintFrameDescription(delegate_
, frame
);
1148 delegate_
->PrintMessage(std::string(" - ") +
1149 request
.initiatorName().utf8().data());
1150 delegate_
->PrintMessage(std::string(" requested '") +
1151 URLDescription(request
.urlRequest().url()).c_str() +
1156 void WebTestProxyBase::WillSendRequest(
1157 blink::WebLocalFrame
* frame
,
1158 unsigned identifier
,
1159 blink::WebURLRequest
& request
,
1160 const blink::WebURLResponse
& redirect_response
) {
1161 // Need to use GURL for host() and SchemeIs()
1162 GURL url
= request
.url();
1163 std::string request_url
= url
.possibly_invalid_spec();
1165 GURL main_document_url
= request
.firstPartyForCookies();
1167 if (redirect_response
.isNull() &&
1168 (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks() ||
1169 test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities())) {
1170 DCHECK(resource_identifier_map_
.find(identifier
) ==
1171 resource_identifier_map_
.end());
1172 resource_identifier_map_
[identifier
] =
1173 DescriptionSuitableForTestResult(request_url
);
1176 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1177 if (resource_identifier_map_
.find(identifier
) ==
1178 resource_identifier_map_
.end())
1179 delegate_
->PrintMessage("<unknown>");
1181 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1182 delegate_
->PrintMessage(" - willSendRequest <NSURLRequest URL ");
1183 delegate_
->PrintMessage(
1184 DescriptionSuitableForTestResult(request_url
).c_str());
1185 delegate_
->PrintMessage(", main document URL ");
1186 delegate_
->PrintMessage(URLDescription(main_document_url
).c_str());
1187 delegate_
->PrintMessage(", http method ");
1188 delegate_
->PrintMessage(request
.httpMethod().utf8().data());
1189 delegate_
->PrintMessage("> redirectResponse ");
1190 PrintResponseDescription(delegate_
, redirect_response
);
1191 delegate_
->PrintMessage("\n");
1194 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1195 delegate_
->PrintMessage(
1196 DescriptionSuitableForTestResult(request_url
).c_str());
1197 delegate_
->PrintMessage(" has priority ");
1198 delegate_
->PrintMessage(PriorityDescription(request
.priority()));
1199 delegate_
->PrintMessage("\n");
1202 if (test_interfaces_
->GetTestRunner()->httpHeadersToClear()) {
1203 const std::set
<std::string
>* clearHeaders
=
1204 test_interfaces_
->GetTestRunner()->httpHeadersToClear();
1205 for (std::set
<std::string
>::const_iterator header
= clearHeaders
->begin();
1206 header
!= clearHeaders
->end();
1208 request
.clearHTTPHeaderField(blink::WebString::fromUTF8(*header
));
1211 std::string host
= url
.host();
1212 if (!host
.empty() &&
1213 (url
.SchemeIs(url::kHttpScheme
) || url
.SchemeIs(url::kHttpsScheme
))) {
1214 if (!IsLocalHost(host
) && !IsTestHost(host
) &&
1215 !HostIsUsedBySomeTestsToGenerateError(host
) &&
1216 ((!main_document_url
.SchemeIs(url::kHttpScheme
) &&
1217 !main_document_url
.SchemeIs(url::kHttpsScheme
)) ||
1218 IsLocalHost(main_document_url
.host())) &&
1219 !delegate_
->AllowExternalPages()) {
1220 delegate_
->PrintMessage(std::string("Blocked access to external URL ") +
1221 request_url
+ "\n");
1222 BlockRequest(request
);
1227 // Set the new substituted URL.
1228 request
.setURL(delegate_
->RewriteLayoutTestsURL(request
.url().spec()));
1231 void WebTestProxyBase::DidReceiveResponse(
1232 blink::WebLocalFrame
* frame
,
1233 unsigned identifier
,
1234 const blink::WebURLResponse
& response
) {
1235 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1236 if (resource_identifier_map_
.find(identifier
) ==
1237 resource_identifier_map_
.end())
1238 delegate_
->PrintMessage("<unknown>");
1240 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1241 delegate_
->PrintMessage(" - didReceiveResponse ");
1242 PrintResponseDescription(delegate_
, response
);
1243 delegate_
->PrintMessage("\n");
1245 if (test_interfaces_
->GetTestRunner()
1246 ->shouldDumpResourceResponseMIMETypes()) {
1247 GURL url
= response
.url();
1248 blink::WebString mime_type
= response
.mimeType();
1249 delegate_
->PrintMessage(url
.ExtractFileName());
1250 delegate_
->PrintMessage(" has MIME type ");
1251 // Simulate NSURLResponse's mapping of empty/unknown MIME types to
1252 // application/octet-stream
1253 delegate_
->PrintMessage(mime_type
.isEmpty() ? "application/octet-stream"
1254 : mime_type
.utf8().data());
1255 delegate_
->PrintMessage("\n");
1259 void WebTestProxyBase::DidChangeResourcePriority(
1260 blink::WebLocalFrame
* frame
,
1261 unsigned identifier
,
1262 const blink::WebURLRequest::Priority
& priority
,
1263 int intra_priority_value
) {
1264 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1265 if (resource_identifier_map_
.find(identifier
) ==
1266 resource_identifier_map_
.end())
1267 delegate_
->PrintMessage("<unknown>");
1269 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1270 delegate_
->PrintMessage(
1271 base::StringPrintf(" changed priority to %s, intra_priority %d\n",
1272 PriorityDescription(priority
).c_str(),
1273 intra_priority_value
));
1277 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame
* frame
,
1278 unsigned identifier
) {
1279 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1280 if (resource_identifier_map_
.find(identifier
) ==
1281 resource_identifier_map_
.end())
1282 delegate_
->PrintMessage("<unknown>");
1284 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1285 delegate_
->PrintMessage(" - didFinishLoading\n");
1287 resource_identifier_map_
.erase(identifier
);
1288 CheckDone(frame
, ResourceLoadCompleted
);
1291 void WebTestProxyBase::DidAddMessageToConsole(
1292 const blink::WebConsoleMessage
& message
,
1293 const blink::WebString
& source_name
,
1294 unsigned source_line
) {
1295 // This matches win DumpRenderTree's UIDelegate.cpp.
1296 if (!log_console_output_
)
1299 switch (message
.level
) {
1300 case blink::WebConsoleMessage::LevelDebug
:
1303 case blink::WebConsoleMessage::LevelLog
:
1306 case blink::WebConsoleMessage::LevelInfo
:
1309 case blink::WebConsoleMessage::LevelWarning
:
1312 case blink::WebConsoleMessage::LevelError
:
1318 delegate_
->PrintMessage(std::string("CONSOLE ") + level
+ ": ");
1320 delegate_
->PrintMessage(base::StringPrintf("line %d: ", source_line
));
1322 if (!message
.text
.isEmpty()) {
1323 std::string new_message
;
1324 new_message
= message
.text
.utf8();
1325 size_t file_protocol
= new_message
.find("file://");
1326 if (file_protocol
!= std::string::npos
) {
1327 new_message
= new_message
.substr(0, file_protocol
) +
1328 URLSuitableForTestResult(new_message
.substr(file_protocol
));
1330 delegate_
->PrintMessage(new_message
);
1332 delegate_
->PrintMessage(std::string("\n"));
1335 void WebTestProxyBase::CheckDone(blink::WebLocalFrame
* frame
,
1336 CheckDoneReason reason
) {
1337 if (frame
!= test_interfaces_
->GetTestRunner()->topLoadingFrame())
1339 if (reason
!= MainResourceLoadFailed
&&
1340 (frame
->isResourceLoadInProgress() || frame
->isLoading()))
1342 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, true);
1345 blink::WebNavigationPolicy
WebTestProxyBase::DecidePolicyForNavigation(
1346 const blink::WebFrameClient::NavigationPolicyInfo
& info
) {
1347 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
1348 delegate_
->PrintMessage("Default policy for navigation to '" +
1349 URLDescription(info
.urlRequest
.url()) + "' is '" +
1350 WebNavigationPolicyToString(info
.defaultPolicy
) +
1354 blink::WebNavigationPolicy result
;
1355 if (!test_interfaces_
->GetTestRunner()->policyDelegateEnabled())
1356 return info
.defaultPolicy
;
1358 delegate_
->PrintMessage(
1359 std::string("Policy delegate: attempt to load ") +
1360 URLDescription(info
.urlRequest
.url()) + " with navigation type '" +
1361 WebNavigationTypeToString(info
.navigationType
) + "'\n");
1362 if (test_interfaces_
->GetTestRunner()->policyDelegateIsPermissive())
1363 result
= blink::WebNavigationPolicyCurrentTab
;
1365 result
= blink::WebNavigationPolicyIgnore
;
1367 if (test_interfaces_
->GetTestRunner()->policyDelegateShouldNotifyDone()) {
1368 test_interfaces_
->GetTestRunner()->policyDelegateDone();
1369 result
= blink::WebNavigationPolicyIgnore
;
1375 bool WebTestProxyBase::WillCheckAndDispatchMessageEvent(
1376 blink::WebLocalFrame
* source_frame
,
1377 blink::WebFrame
* target_frame
,
1378 blink::WebSecurityOrigin target
,
1379 blink::WebDOMMessageEvent event
) {
1380 if (test_interfaces_
->GetTestRunner()->shouldInterceptPostMessage()) {
1381 delegate_
->PrintMessage("intercepted postMessage\n");
1388 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString
& event_name
) {
1389 if (test_interfaces_
->GetTestRunner()->shouldDumpSpellCheckCallbacks()) {
1390 delegate_
->PrintMessage(std::string("SpellCheckEvent: ") +
1391 event_name
.utf8().data() + "\n");
1395 void WebTestProxyBase::ResetInputMethod() {
1396 // If a composition text exists, then we need to let the browser process
1397 // to cancel the input method's ongoing composition session.
1399 web_widget_
->confirmComposition();
1402 blink::WebString
WebTestProxyBase::acceptLanguages() {
1403 return blink::WebString::fromUTF8(accept_languages_
);
1406 } // namespace test_runner