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/i18n/rtl.h"
12 #include "base/logging.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/thread_task_runner_handle.h"
17 #include "base/time/time.h"
18 #include "base/trace_event/trace_event.h"
19 #include "components/test_runner/accessibility_controller.h"
20 #include "components/test_runner/event_sender.h"
21 #include "components/test_runner/mock_color_chooser.h"
22 #include "components/test_runner/mock_credential_manager_client.h"
23 #include "components/test_runner/mock_screen_orientation_client.h"
24 #include "components/test_runner/mock_web_speech_recognizer.h"
25 #include "components/test_runner/mock_web_user_media_client.h"
26 #include "components/test_runner/spell_check_client.h"
27 #include "components/test_runner/test_interfaces.h"
28 #include "components/test_runner/test_plugin.h"
29 #include "components/test_runner/test_runner.h"
30 #include "components/test_runner/web_test_delegate.h"
31 #include "components/test_runner/web_test_interfaces.h"
32 #include "components/test_runner/web_test_runner.h"
33 // FIXME: Including platform_canvas.h here is a layering violation.
34 #include "skia/ext/platform_canvas.h"
35 #include "third_party/WebKit/public/platform/Platform.h"
36 #include "third_party/WebKit/public/platform/WebCString.h"
37 #include "third_party/WebKit/public/platform/WebClipboard.h"
38 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
39 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h"
40 #include "third_party/WebKit/public/platform/WebURLError.h"
41 #include "third_party/WebKit/public/platform/WebURLRequest.h"
42 #include "third_party/WebKit/public/platform/WebURLResponse.h"
43 #include "third_party/WebKit/public/web/WebAXEnums.h"
44 #include "third_party/WebKit/public/web/WebAXObject.h"
45 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
46 #include "third_party/WebKit/public/web/WebDataSource.h"
47 #include "third_party/WebKit/public/web/WebDocument.h"
48 #include "third_party/WebKit/public/web/WebElement.h"
49 #include "third_party/WebKit/public/web/WebHistoryItem.h"
50 #include "third_party/WebKit/public/web/WebLocalFrame.h"
51 #include "third_party/WebKit/public/web/WebNode.h"
52 #include "third_party/WebKit/public/web/WebPagePopup.h"
53 #include "third_party/WebKit/public/web/WebPluginParams.h"
54 #include "third_party/WebKit/public/web/WebPrintParams.h"
55 #include "third_party/WebKit/public/web/WebRange.h"
56 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
57 #include "third_party/WebKit/public/web/WebView.h"
58 #include "third_party/WebKit/public/web/WebWidgetClient.h"
60 namespace test_runner
{
64 class CaptureCallback
: public blink::WebCompositeAndReadbackAsyncCallback
{
66 CaptureCallback(const base::Callback
<void(const SkBitmap
&)>& callback
);
67 virtual ~CaptureCallback();
69 void set_wait_for_popup(bool wait
) { wait_for_popup_
= wait
; }
70 void set_popup_position(const gfx::Point
& position
) {
71 popup_position_
= position
;
74 // WebCompositeAndReadbackAsyncCallback implementation.
75 virtual void didCompositeAndReadback(const SkBitmap
& bitmap
);
78 base::Callback
<void(const SkBitmap
&)> callback_
;
79 SkBitmap main_bitmap_
;
81 gfx::Point popup_position_
;
84 class LayoutAndPaintCallback
: public blink::WebLayoutAndPaintAsyncCallback
{
86 LayoutAndPaintCallback(const base::Closure
& callback
)
87 : callback_(callback
), wait_for_popup_(false) {
89 virtual ~LayoutAndPaintCallback() {
92 void set_wait_for_popup(bool wait
) { wait_for_popup_
= wait
; }
94 // WebLayoutAndPaintAsyncCallback implementation.
95 virtual void didLayoutAndPaint();
98 base::Closure callback_
;
102 class HostMethodTask
: public WebMethodTask
<WebTestProxyBase
> {
104 typedef void (WebTestProxyBase::*CallbackMethodType
)();
105 HostMethodTask(WebTestProxyBase
* object
, CallbackMethodType callback
)
106 : WebMethodTask
<WebTestProxyBase
>(object
), callback_(callback
) {}
108 void RunIfValid() override
{ (object_
->*callback_
)(); }
111 CallbackMethodType callback_
;
114 void PrintFrameDescription(WebTestDelegate
* delegate
, blink::WebFrame
* frame
) {
115 std::string name8
= frame
->uniqueName().utf8();
116 if (frame
== frame
->view()->mainFrame()) {
117 if (!name8
.length()) {
118 delegate
->PrintMessage("main frame");
121 delegate
->PrintMessage(std::string("main frame \"") + name8
+ "\"");
124 if (!name8
.length()) {
125 delegate
->PrintMessage("frame (anonymous)");
128 delegate
->PrintMessage(std::string("frame \"") + name8
+ "\"");
131 void PrintFrameuserGestureStatus(WebTestDelegate
* delegate
,
132 blink::WebFrame
* frame
,
134 bool is_user_gesture
=
135 blink::WebUserGestureIndicator::isProcessingUserGesture();
136 delegate
->PrintMessage(std::string("Frame with user gesture \"") +
137 (is_user_gesture
? "true" : "false") + "\"" + msg
);
140 // Used to write a platform neutral file:/// URL by taking the
141 // filename and its directory. (e.g., converts
142 // "file:///tmp/foo/bar.txt" to just "bar.txt").
143 std::string
DescriptionSuitableForTestResult(const std::string
& url
) {
144 if (url
.empty() || std::string::npos
== url
.find("file://"))
147 size_t pos
= url
.rfind('/');
148 if (pos
== std::string::npos
|| !pos
)
149 return "ERROR:" + url
;
150 pos
= url
.rfind('/', pos
- 1);
151 if (pos
== std::string::npos
)
152 return "ERROR:" + url
;
154 return url
.substr(pos
+ 1);
157 void PrintResponseDescription(WebTestDelegate
* delegate
,
158 const blink::WebURLResponse
& response
) {
159 if (response
.isNull()) {
160 delegate
->PrintMessage("(null)");
163 delegate
->PrintMessage(base::StringPrintf(
164 "<NSURLResponse %s, http status code %d>",
165 DescriptionSuitableForTestResult(response
.url().spec()).c_str(),
166 response
.httpStatusCode()));
169 std::string
URLDescription(const GURL
& url
) {
170 if (url
.SchemeIs(url::kFileScheme
))
171 return url
.ExtractFileName();
172 return url
.possibly_invalid_spec();
175 std::string
PriorityDescription(
176 const blink::WebURLRequest::Priority
& priority
) {
178 case blink::WebURLRequest::PriorityVeryLow
:
180 case blink::WebURLRequest::PriorityLow
:
182 case blink::WebURLRequest::PriorityMedium
:
184 case blink::WebURLRequest::PriorityHigh
:
186 case blink::WebURLRequest::PriorityVeryHigh
:
188 case blink::WebURLRequest::PriorityUnresolved
:
194 void BlockRequest(blink::WebURLRequest
& request
) {
195 request
.setURL(GURL("255.255.255.255"));
198 bool IsLocalHost(const std::string
& host
) {
199 return host
== "127.0.0.1" || host
== "localhost";
202 bool IsTestHost(const std::string
& host
) {
203 return base::EndsWith(host
, ".test", base::CompareCase::INSENSITIVE_ASCII
);
206 bool HostIsUsedBySomeTestsToGenerateError(const std::string
& host
) {
207 return host
== "255.255.255.255";
210 // Used to write a platform neutral file:/// URL by only taking the filename
211 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt").
212 std::string
URLSuitableForTestResult(const std::string
& url
) {
213 if (url
.empty() || std::string::npos
== url
.find("file://"))
216 size_t pos
= url
.rfind('/');
217 if (pos
== std::string::npos
) {
219 pos
= url
.rfind('\\');
220 if (pos
== std::string::npos
)
226 std::string filename
= url
.substr(pos
+ 1);
227 if (filename
.empty())
228 return "file:"; // A WebKit test has this in its expected output.
232 // WebNavigationType debugging strings taken from PolicyDelegate.mm.
233 const char* kLinkClickedString
= "link clicked";
234 const char* kFormSubmittedString
= "form submitted";
235 const char* kBackForwardString
= "back/forward";
236 const char* kReloadString
= "reload";
237 const char* kFormResubmittedString
= "form resubmitted";
238 const char* kOtherString
= "other";
239 const char* kIllegalString
= "illegal value";
241 // Get a debugging string from a WebNavigationType.
242 const char* WebNavigationTypeToString(blink::WebNavigationType type
) {
244 case blink::WebNavigationTypeLinkClicked
:
245 return kLinkClickedString
;
246 case blink::WebNavigationTypeFormSubmitted
:
247 return kFormSubmittedString
;
248 case blink::WebNavigationTypeBackForward
:
249 return kBackForwardString
;
250 case blink::WebNavigationTypeReload
:
251 return kReloadString
;
252 case blink::WebNavigationTypeFormResubmitted
:
253 return kFormResubmittedString
;
254 case blink::WebNavigationTypeOther
:
257 return kIllegalString
;
260 const char* kPolicyIgnore
= "Ignore";
261 const char* kPolicyDownload
= "download";
262 const char* kPolicyCurrentTab
= "current tab";
263 const char* kPolicyNewBackgroundTab
= "new background tab";
264 const char* kPolicyNewForegroundTab
= "new foreground tab";
265 const char* kPolicyNewWindow
= "new window";
266 const char* kPolicyNewPopup
= "new popup";
268 const char* WebNavigationPolicyToString(blink::WebNavigationPolicy policy
) {
270 case blink::WebNavigationPolicyIgnore
:
271 return kPolicyIgnore
;
272 case blink::WebNavigationPolicyDownload
:
273 return kPolicyDownload
;
274 case blink::WebNavigationPolicyCurrentTab
:
275 return kPolicyCurrentTab
;
276 case blink::WebNavigationPolicyNewBackgroundTab
:
277 return kPolicyNewBackgroundTab
;
278 case blink::WebNavigationPolicyNewForegroundTab
:
279 return kPolicyNewForegroundTab
;
280 case blink::WebNavigationPolicyNewWindow
:
281 return kPolicyNewWindow
;
282 case blink::WebNavigationPolicyNewPopup
:
283 return kPolicyNewPopup
;
285 return kIllegalString
;
288 std::string
DumpFrameHeaderIfNeeded(blink::WebFrame
* frame
) {
291 // Add header for all but the main frame. Skip empty frames.
292 if (frame
->parent() && !frame
->document().documentElement().isNull()) {
293 result
.append("\n--------\nFrame: '");
294 result
.append(frame
->uniqueName().utf8().data());
295 result
.append("'\n--------\n");
301 std::string
DumpFramesAsMarkup(blink::WebFrame
* frame
, bool recursive
) {
302 std::string result
= DumpFrameHeaderIfNeeded(frame
);
303 result
.append(frame
->contentAsMarkup().utf8());
307 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
308 child
= child
->nextSibling())
309 result
.append(DumpFramesAsMarkup(child
, recursive
));
315 std::string
DumpDocumentText(blink::WebFrame
* frame
) {
316 return frame
->document().contentAsTextForTesting().utf8();
319 std::string
DumpFramesAsText(blink::WebFrame
* frame
, bool recursive
) {
320 std::string result
= DumpFrameHeaderIfNeeded(frame
);
321 result
.append(DumpDocumentText(frame
));
325 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
326 child
= child
->nextSibling())
327 result
.append(DumpFramesAsText(child
, recursive
));
333 std::string
DumpFramesAsPrintedText(blink::WebFrame
* frame
, bool recursive
) {
334 // Cannot do printed format for anything other than HTML
335 if (!frame
->document().isHTMLDocument())
336 return std::string();
338 std::string result
= DumpFrameHeaderIfNeeded(frame
);
340 frame
->layoutTreeAsText(blink::WebFrame::LayoutAsTextPrinting
).utf8());
344 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
345 child
= child
->nextSibling())
346 result
.append(DumpFramesAsPrintedText(child
, recursive
));
352 std::string
DumpFrameScrollPosition(blink::WebFrame
* frame
, bool recursive
) {
354 blink::WebSize offset
= frame
->scrollOffset();
355 if (offset
.width
> 0 || offset
.height
> 0) {
356 if (frame
->parent()) {
358 std::string("frame '") + frame
->uniqueName().utf8().data() + "' ";
361 &result
, "scrolled to %d,%d\n", offset
.width
, offset
.height
);
366 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
367 child
= child
->nextSibling())
368 result
+= DumpFrameScrollPosition(child
, recursive
);
372 std::string
DumpAllBackForwardLists(TestInterfaces
* interfaces
,
373 WebTestDelegate
* delegate
) {
375 const std::vector
<WebTestProxyBase
*>& window_list
=
376 interfaces
->GetWindowList();
377 for (size_t i
= 0; i
< window_list
.size(); ++i
)
378 result
.append(delegate
->DumpHistoryForWindow(window_list
.at(i
)));
383 WebTestProxyBase::WebTestProxyBase()
384 : web_test_interfaces_(NULL
),
385 test_interfaces_(NULL
),
388 spellcheck_(new SpellCheckClient(this)),
393 WebTestProxyBase::~WebTestProxyBase() {
394 test_interfaces_
->WindowClosed(this);
395 delegate_
->OnWebTestProxyBaseDestroy(this);
398 void WebTestProxyBase::SetInterfaces(WebTestInterfaces
* interfaces
) {
399 web_test_interfaces_
= interfaces
;
400 test_interfaces_
= interfaces
->GetTestInterfaces();
401 test_interfaces_
->WindowOpened(this);
404 WebTestInterfaces
* WebTestProxyBase::GetInterfaces() {
405 return web_test_interfaces_
;
408 void WebTestProxyBase::SetDelegate(WebTestDelegate
* delegate
) {
409 delegate_
= delegate
;
410 spellcheck_
->SetDelegate(delegate
);
411 if (speech_recognizer_
.get())
412 speech_recognizer_
->SetDelegate(delegate
);
415 WebTestDelegate
* WebTestProxyBase::GetDelegate() {
419 blink::WebView
* WebTestProxyBase::GetWebView() const {
421 // TestRunner does not support popup widgets. So |web_widget|_ is always a
423 return static_cast<blink::WebView
*>(web_widget_
);
426 void WebTestProxyBase::Reset() {
428 animate_scheduled_
= false;
429 resource_identifier_map_
.clear();
430 log_console_output_
= true;
431 accept_languages_
= "";
434 blink::WebSpellCheckClient
* WebTestProxyBase::GetSpellCheckClient() const {
435 return spellcheck_
.get();
438 blink::WebColorChooser
* WebTestProxyBase::CreateColorChooser(
439 blink::WebColorChooserClient
* client
,
440 const blink::WebColor
& color
,
441 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
) {
442 // This instance is deleted by WebCore::ColorInputType
443 return new MockColorChooser(client
, delegate_
, this);
446 bool WebTestProxyBase::RunFileChooser(
447 const blink::WebFileChooserParams
& params
,
448 blink::WebFileChooserCompletion
* completion
) {
449 delegate_
->PrintMessage("Mock: Opening a file chooser.\n");
450 // FIXME: Add ability to set file names to a file upload control.
454 void WebTestProxyBase::ShowValidationMessage(
455 const blink::WebString
& main_message
,
456 blink::WebTextDirection main_message_hint
,
457 const blink::WebString
& sub_message
,
458 blink::WebTextDirection sub_message_hint
) {
459 base::string16 wrapped_main_text
= main_message
;
460 base::string16 wrapped_sub_text
= sub_message
;
462 if (main_message_hint
== blink::WebTextDirectionLeftToRight
) {
464 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text
);
465 } else if (main_message_hint
== blink::WebTextDirectionRightToLeft
&&
466 !base::i18n::IsRTL()) {
467 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text
);
470 if (!wrapped_sub_text
.empty()) {
471 if (sub_message_hint
== blink::WebTextDirectionLeftToRight
) {
473 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text
);
474 } else if (sub_message_hint
== blink::WebTextDirectionRightToLeft
) {
475 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text
);
478 delegate_
->PrintMessage("ValidationMessageClient: main-message=" +
479 base::UTF16ToUTF8(wrapped_main_text
) +
481 base::UTF16ToUTF8(wrapped_sub_text
) + "\n");
484 std::string
WebTestProxyBase::CaptureTree(
485 bool debug_render_tree
,
486 bool dump_line_box_trees
) {
487 bool should_dump_custom_text
=
488 test_interfaces_
->GetTestRunner()->shouldDumpAsCustomText();
489 bool should_dump_as_text
=
490 test_interfaces_
->GetTestRunner()->shouldDumpAsText();
491 bool should_dump_as_markup
=
492 test_interfaces_
->GetTestRunner()->shouldDumpAsMarkup();
493 bool should_dump_as_printed
= test_interfaces_
->GetTestRunner()->isPrinting();
494 blink::WebFrame
* frame
= GetWebView()->mainFrame();
495 std::string data_utf8
;
496 if (should_dump_custom_text
) {
497 // Append a newline for the test driver.
498 data_utf8
= test_interfaces_
->GetTestRunner()->customDumpText() + "\n";
499 } else if (should_dump_as_text
) {
501 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsText();
502 data_utf8
= should_dump_as_printed
?
503 DumpFramesAsPrintedText(frame
, recursive
) :
504 DumpFramesAsText(frame
, recursive
);
505 } else if (should_dump_as_markup
) {
507 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsMarkup();
508 // Append a newline for the test driver.
509 data_utf8
= DumpFramesAsMarkup(frame
, recursive
);
511 bool recursive
= test_interfaces_
->GetTestRunner()
512 ->shouldDumpChildFrameScrollPositions();
513 blink::WebFrame::LayoutAsTextControls layout_text_behavior
=
514 blink::WebFrame::LayoutAsTextNormal
;
515 if (should_dump_as_printed
)
516 layout_text_behavior
|= blink::WebFrame::LayoutAsTextPrinting
;
517 if (debug_render_tree
)
518 layout_text_behavior
|= blink::WebFrame::LayoutAsTextDebug
;
519 if (dump_line_box_trees
)
520 layout_text_behavior
|= blink::WebFrame::LayoutAsTextWithLineTrees
;
521 data_utf8
= frame
->layoutTreeAsText(layout_text_behavior
).utf8();
522 data_utf8
+= DumpFrameScrollPosition(frame
, recursive
);
525 if (test_interfaces_
->GetTestRunner()->ShouldDumpBackForwardList())
526 data_utf8
+= DumpAllBackForwardLists(test_interfaces_
, delegate_
);
531 void WebTestProxyBase::DrawSelectionRect(SkCanvas
* canvas
) {
532 // See if we need to draw the selection bounds rect. Selection bounds
533 // rect is the rect enclosing the (possibly transformed) selection.
534 // The rect should be drawn after everything is laid out and painted.
535 if (!test_interfaces_
->GetTestRunner()->shouldDumpSelectionRect())
537 // If there is a selection rect - draw a red 1px border enclosing rect
538 blink::WebRect wr
= GetWebView()->mainFrame()->selectionBoundsRect();
541 // Render a red rectangle bounding selection rect
543 paint
.setColor(0xFFFF0000); // Fully opaque red
544 paint
.setStyle(SkPaint::kStroke_Style
);
545 paint
.setFlags(SkPaint::kAntiAlias_Flag
);
546 paint
.setStrokeWidth(1.0f
);
547 SkIRect rect
; // Bounding rect
548 rect
.set(wr
.x
, wr
.y
, wr
.x
+ wr
.width
, wr
.y
+ wr
.height
);
549 canvas
->drawIRect(rect
, paint
);
552 void WebTestProxyBase::SetAcceptLanguages(const std::string
& accept_languages
) {
553 bool notify
= accept_languages_
!= accept_languages
;
554 accept_languages_
= accept_languages
;
557 GetWebView()->acceptLanguagesChanged();
560 void WebTestProxyBase::CopyImageAtAndCapturePixels(
561 int x
, int y
, const base::Callback
<void(const SkBitmap
&)>& callback
) {
562 DCHECK(!callback
.is_null());
563 uint64_t sequence_number
= blink::Platform::current()->clipboard()->
564 sequenceNumber(blink::WebClipboard::Buffer());
565 GetWebView()->copyImageAt(blink::WebPoint(x
, y
));
566 if (sequence_number
== blink::Platform::current()->clipboard()->
567 sequenceNumber(blink::WebClipboard::Buffer())) {
568 SkBitmap emptyBitmap
;
569 callback
.Run(emptyBitmap
);
573 blink::WebData data
= blink::Platform::current()->clipboard()->readImage(
574 blink::WebClipboard::Buffer());
575 blink::WebImage image
= blink::WebImage::fromData(data
, blink::WebSize());
576 const SkBitmap
& bitmap
= image
.getSkBitmap();
577 SkAutoLockPixels
autoLock(bitmap
);
578 callback
.Run(bitmap
);
581 void WebTestProxyBase::CapturePixelsForPrinting(
582 const base::Callback
<void(const SkBitmap
&)>& callback
) {
583 web_widget_
->layout();
585 blink::WebSize page_size_in_pixels
= web_widget_
->size();
586 blink::WebFrame
* web_frame
= GetWebView()->mainFrame();
588 int page_count
= web_frame
->printBegin(page_size_in_pixels
);
589 int totalHeight
= page_count
* (page_size_in_pixels
.height
+ 1) - 1;
591 bool is_opaque
= false;
592 skia::RefPtr
<SkCanvas
> canvas(skia::AdoptRef(skia::TryCreateBitmapCanvas(
593 page_size_in_pixels
.width
, totalHeight
, is_opaque
)));
595 callback
.Run(SkBitmap());
598 web_frame
->printPagesWithBoundaries(canvas
.get(), page_size_in_pixels
);
599 web_frame
->printEnd();
601 DrawSelectionRect(canvas
.get());
602 SkBaseDevice
* device
= skia::GetTopDevice(*canvas
);
603 const SkBitmap
& bitmap
= device
->accessBitmap(false);
604 callback
.Run(bitmap
);
607 CaptureCallback::CaptureCallback(
608 const base::Callback
<void(const SkBitmap
&)>& callback
)
609 : callback_(callback
), wait_for_popup_(false) {
612 CaptureCallback::~CaptureCallback() {
615 void CaptureCallback::didCompositeAndReadback(const SkBitmap
& bitmap
) {
616 TRACE_EVENT2("shell",
617 "CaptureCallback::didCompositeAndReadback",
619 bitmap
.info().width(),
621 bitmap
.info().height());
622 if (!wait_for_popup_
) {
623 callback_
.Run(bitmap
);
627 if (main_bitmap_
.isNull()) {
628 bitmap
.deepCopyTo(&main_bitmap_
);
631 SkCanvas
canvas(main_bitmap_
);
632 canvas
.drawBitmap(bitmap
, popup_position_
.x(), popup_position_
.y());
633 callback_
.Run(main_bitmap_
);
637 void WebTestProxyBase::CapturePixelsAsync(
638 const base::Callback
<void(const SkBitmap
&)>& callback
) {
639 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
640 DCHECK(!callback
.is_null());
642 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
643 if (drag_image_
.isNull()) {
644 // This means the test called dumpDragImage but did not initiate a drag.
645 // Return a blank image so that the test fails.
647 bitmap
.allocN32Pixels(1, 1);
649 SkAutoLockPixels
lock(bitmap
);
650 bitmap
.eraseColor(0);
652 callback
.Run(bitmap
);
656 callback
.Run(drag_image_
.getSkBitmap());
660 if (test_interfaces_
->GetTestRunner()->isPrinting()) {
661 base::ThreadTaskRunnerHandle::Get()->PostTask(
662 FROM_HERE
, base::Bind(&WebTestProxyBase::CapturePixelsForPrinting
,
663 base::Unretained(this), callback
));
667 CaptureCallback
* capture_callback
= new CaptureCallback(base::Bind(
668 &WebTestProxyBase::DidCapturePixelsAsync
, base::Unretained(this),
670 web_widget_
->compositeAndReadbackAsync(capture_callback
);
671 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
672 capture_callback
->set_wait_for_popup(true);
673 capture_callback
->set_popup_position(popup
->positionRelativeToOwner());
674 popup
->compositeAndReadbackAsync(capture_callback
);
678 void WebTestProxyBase::DidCapturePixelsAsync(
679 const base::Callback
<void(const SkBitmap
&)>& callback
,
680 const SkBitmap
& bitmap
) {
681 SkCanvas
canvas(bitmap
);
682 DrawSelectionRect(&canvas
);
683 if (!callback
.is_null())
684 callback
.Run(bitmap
);
687 void WebTestProxyBase::SetLogConsoleOutput(bool enabled
) {
688 log_console_output_
= enabled
;
691 void LayoutAndPaintCallback::didLayoutAndPaint() {
692 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint");
693 if (wait_for_popup_
) {
694 wait_for_popup_
= false;
698 if (!callback_
.is_null())
703 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure
& callback
) {
704 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen");
706 LayoutAndPaintCallback
* layout_and_paint_callback
=
707 new LayoutAndPaintCallback(callback
);
708 web_widget_
->layoutAndPaintAsync(layout_and_paint_callback
);
709 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
710 layout_and_paint_callback
->set_wait_for_popup(true);
711 popup
->layoutAndPaintAsync(layout_and_paint_callback
);
715 void WebTestProxyBase::GetScreenOrientationForTesting(
716 blink::WebScreenInfo
& screen_info
) {
717 if (!screen_orientation_client_
)
719 // Override screen orientation information with mock data.
720 screen_info
.orientationType
=
721 screen_orientation_client_
->CurrentOrientationType();
722 screen_info
.orientationAngle
=
723 screen_orientation_client_
->CurrentOrientationAngle();
726 MockScreenOrientationClient
*
727 WebTestProxyBase::GetScreenOrientationClientMock() {
728 if (!screen_orientation_client_
.get()) {
729 screen_orientation_client_
.reset(new MockScreenOrientationClient
);
731 return screen_orientation_client_
.get();
734 MockWebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizerMock() {
735 if (!speech_recognizer_
.get()) {
736 speech_recognizer_
.reset(new MockWebSpeechRecognizer());
737 speech_recognizer_
->SetDelegate(delegate_
);
739 return speech_recognizer_
.get();
742 MockCredentialManagerClient
*
743 WebTestProxyBase::GetCredentialManagerClientMock() {
744 if (!credential_manager_client_
.get())
745 credential_manager_client_
.reset(new MockCredentialManagerClient());
746 return credential_manager_client_
.get();
749 void WebTestProxyBase::ScheduleAnimation() {
750 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
753 if (!animate_scheduled_
) {
754 animate_scheduled_
= true;
755 delegate_
->PostDelayedTask(
756 new HostMethodTask(this, &WebTestProxyBase::AnimateNow
), 1);
760 void WebTestProxyBase::AnimateNow() {
761 if (animate_scheduled_
) {
762 base::TimeDelta animate_time
= base::TimeTicks::Now() - base::TimeTicks();
763 base::TimeDelta interval
= base::TimeDelta::FromMicroseconds(16666);
764 blink::WebBeginFrameArgs
args(animate_time
.InSecondsF(),
765 (animate_time
+ interval
).InSecondsF(),
766 interval
.InSecondsF());
768 animate_scheduled_
= false;
769 web_widget_
->beginFrame(args
);
770 web_widget_
->layout();
771 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
772 popup
->beginFrame(args
);
778 void WebTestProxyBase::PostAccessibilityEvent(const blink::WebAXObject
& obj
,
779 blink::WebAXEvent event
) {
780 // Only hook the accessibility events occured during the test run.
781 // This check prevents false positives in WebLeakDetector.
782 // The pending tasks in browser/renderer message queue may trigger
783 // accessibility events,
784 // and AccessibilityController will hold on to their target nodes if we don't
786 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
789 if (event
== blink::WebAXEventFocus
)
790 test_interfaces_
->GetAccessibilityController()->SetFocusedElement(obj
);
792 const char* event_name
= NULL
;
794 case blink::WebAXEventActiveDescendantChanged
:
795 event_name
= "ActiveDescendantChanged";
797 case blink::WebAXEventAlert
:
798 event_name
= "Alert";
800 case blink::WebAXEventAriaAttributeChanged
:
801 event_name
= "AriaAttributeChanged";
803 case blink::WebAXEventAutocorrectionOccured
:
804 event_name
= "AutocorrectionOccured";
806 case blink::WebAXEventBlur
:
809 case blink::WebAXEventCheckedStateChanged
:
810 event_name
= "CheckedStateChanged";
812 case blink::WebAXEventChildrenChanged
:
813 event_name
= "ChildrenChanged";
815 case blink::WebAXEventFocus
:
816 event_name
= "Focus";
818 case blink::WebAXEventHide
:
821 case blink::WebAXEventInvalidStatusChanged
:
822 event_name
= "InvalidStatusChanged";
824 case blink::WebAXEventLayoutComplete
:
825 event_name
= "LayoutComplete";
827 case blink::WebAXEventLiveRegionChanged
:
828 event_name
= "LiveRegionChanged";
830 case blink::WebAXEventLoadComplete
:
831 event_name
= "LoadComplete";
833 case blink::WebAXEventLocationChanged
:
834 event_name
= "LocationChanged";
836 case blink::WebAXEventMenuListItemSelected
:
837 event_name
= "MenuListItemSelected";
839 case blink::WebAXEventMenuListItemUnselected
:
840 event_name
= "MenuListItemUnselected";
842 case blink::WebAXEventMenuListValueChanged
:
843 event_name
= "MenuListValueChanged";
845 case blink::WebAXEventRowCollapsed
:
846 event_name
= "RowCollapsed";
848 case blink::WebAXEventRowCountChanged
:
849 event_name
= "RowCountChanged";
851 case blink::WebAXEventRowExpanded
:
852 event_name
= "RowExpanded";
854 case blink::WebAXEventScrollPositionChanged
:
855 event_name
= "ScrollPositionChanged";
857 case blink::WebAXEventScrolledToAnchor
:
858 event_name
= "ScrolledToAnchor";
860 case blink::WebAXEventSelectedChildrenChanged
:
861 event_name
= "SelectedChildrenChanged";
863 case blink::WebAXEventSelectedTextChanged
:
864 event_name
= "SelectedTextChanged";
866 case blink::WebAXEventShow
:
869 case blink::WebAXEventTextChanged
:
870 event_name
= "TextChanged";
872 case blink::WebAXEventTextInserted
:
873 event_name
= "TextInserted";
875 case blink::WebAXEventTextRemoved
:
876 event_name
= "TextRemoved";
878 case blink::WebAXEventValueChanged
:
879 event_name
= "ValueChanged";
882 event_name
= "Unknown";
886 test_interfaces_
->GetAccessibilityController()->NotificationReceived(
889 if (test_interfaces_
->GetAccessibilityController()
890 ->ShouldLogAccessibilityEvents()) {
891 std::string
message("AccessibilityNotification - ");
892 message
+= event_name
;
894 blink::WebNode node
= obj
.node();
895 if (!node
.isNull() && node
.isElementNode()) {
896 blink::WebElement element
= node
.to
<blink::WebElement
>();
897 if (element
.hasAttribute("id")) {
899 message
+= element
.getAttribute("id").utf8().data();
903 delegate_
->PrintMessage(message
+ "\n");
907 void WebTestProxyBase::StartDragging(blink::WebLocalFrame
* frame
,
908 const blink::WebDragData
& data
,
909 blink::WebDragOperationsMask mask
,
910 const blink::WebImage
& image
,
911 const blink::WebPoint
& point
) {
912 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
913 if (drag_image_
.isNull())
916 // When running a test, we need to fake a drag drop operation otherwise
917 // Windows waits for real mouse events to know when the drag is over.
918 test_interfaces_
->GetEventSender()->DoDragDrop(data
, mask
);
921 // The output from these methods in layout test mode should match that
922 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
924 void WebTestProxyBase::DidChangeSelection(bool is_empty_callback
) {
925 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
926 delegate_
->PrintMessage(
928 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
931 void WebTestProxyBase::DidChangeContents() {
932 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
933 delegate_
->PrintMessage(
934 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
937 bool WebTestProxyBase::CreateView(blink::WebLocalFrame
* frame
,
938 const blink::WebURLRequest
& request
,
939 const blink::WebWindowFeatures
& features
,
940 const blink::WebString
& frame_name
,
941 blink::WebNavigationPolicy policy
,
942 bool suppress_opener
) {
943 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
944 delegate_
->PrintMessage("Default policy for createView for '" +
945 URLDescription(request
.url()) + "' is '" +
946 WebNavigationPolicyToString(policy
) + "'\n");
949 if (!test_interfaces_
->GetTestRunner()->canOpenWindows())
951 if (test_interfaces_
->GetTestRunner()->shouldDumpCreateView())
952 delegate_
->PrintMessage(std::string("createView(") +
953 URLDescription(request
.url()) + ")\n");
957 blink::WebPlugin
* WebTestProxyBase::CreatePlugin(
958 blink::WebLocalFrame
* frame
,
959 const blink::WebPluginParams
& params
) {
960 if (TestPlugin::IsSupportedMimeType(params
.mimeType
))
961 return TestPlugin::create(frame
, params
, delegate_
);
962 return delegate_
->CreatePluginPlaceholder(frame
, params
);
965 void WebTestProxyBase::SetStatusText(const blink::WebString
& text
) {
966 if (!test_interfaces_
->GetTestRunner()->shouldDumpStatusCallbacks())
968 delegate_
->PrintMessage(
969 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") +
970 text
.utf8().data() + "\n");
973 void WebTestProxyBase::DidStopLoading() {
974 if (test_interfaces_
->GetTestRunner()->shouldDumpProgressFinishedCallback())
975 delegate_
->PrintMessage("postProgressFinishedNotification\n");
978 void WebTestProxyBase::ShowContextMenu(
979 const blink::WebContextMenuData
& context_menu_data
) {
980 test_interfaces_
->GetEventSender()->SetContextMenuData(context_menu_data
);
983 blink::WebUserMediaClient
* WebTestProxyBase::GetUserMediaClient() {
984 if (!user_media_client_
.get())
985 user_media_client_
.reset(new MockWebUserMediaClient(delegate_
));
986 return user_media_client_
.get();
989 // Simulate a print by going into print mode and then exit straight away.
990 void WebTestProxyBase::PrintPage(blink::WebLocalFrame
* frame
) {
991 blink::WebSize page_size_in_pixels
= web_widget_
->size();
992 if (page_size_in_pixels
.isEmpty())
994 blink::WebPrintParams
printParams(page_size_in_pixels
);
995 frame
->printBegin(printParams
);
999 blink::WebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizer() {
1000 return GetSpeechRecognizerMock();
1003 bool WebTestProxyBase::RequestPointerLock() {
1004 return test_interfaces_
->GetTestRunner()->RequestPointerLock();
1007 void WebTestProxyBase::RequestPointerUnlock() {
1008 test_interfaces_
->GetTestRunner()->RequestPointerUnlock();
1011 bool WebTestProxyBase::IsPointerLocked() {
1012 return test_interfaces_
->GetTestRunner()->isPointerLocked();
1015 void WebTestProxyBase::DidFocus() {
1016 delegate_
->SetFocus(this, true);
1019 void WebTestProxyBase::DidBlur() {
1020 delegate_
->SetFocus(this, false);
1023 void WebTestProxyBase::SetToolTipText(const blink::WebString
& text
,
1024 blink::WebTextDirection direction
) {
1025 test_interfaces_
->GetTestRunner()->setToolTipText(text
);
1028 void WebTestProxyBase::DidOpenChooser() {
1032 void WebTestProxyBase::DidCloseChooser() {
1036 bool WebTestProxyBase::IsChooserShown() {
1037 return 0 < chooser_count_
;
1040 void WebTestProxyBase::LoadURLExternally(
1041 blink::WebLocalFrame
* frame
,
1042 const blink::WebURLRequest
& request
,
1043 blink::WebNavigationPolicy policy
,
1044 const blink::WebString
& suggested_name
) {
1045 if (test_interfaces_
->GetTestRunner()->shouldWaitUntilExternalURLLoad()) {
1046 if (policy
== blink::WebNavigationPolicyDownload
) {
1047 delegate_
->PrintMessage(
1048 std::string("Downloading URL with suggested filename \"") +
1049 suggested_name
.utf8() + "\"\n");
1051 delegate_
->PrintMessage(std::string("Loading URL externally - \"") +
1052 URLDescription(request
.url()) + "\"\n");
1054 delegate_
->TestFinished();
1058 void WebTestProxyBase::DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) {
1059 if (!test_interfaces_
->GetTestRunner()->topLoadingFrame())
1060 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, false);
1062 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1063 PrintFrameDescription(delegate_
, frame
);
1064 delegate_
->PrintMessage(" - didStartProvisionalLoadForFrame\n");
1067 if (test_interfaces_
->GetTestRunner()
1068 ->shouldDumpUserGestureInFrameLoadCallbacks()) {
1069 PrintFrameuserGestureStatus(
1070 delegate_
, frame
, " - in didStartProvisionalLoadForFrame\n");
1074 void WebTestProxyBase::DidReceiveServerRedirectForProvisionalLoad(
1075 blink::WebLocalFrame
* frame
) {
1076 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1077 PrintFrameDescription(delegate_
, frame
);
1078 delegate_
->PrintMessage(
1079 " - didReceiveServerRedirectForProvisionalLoadForFrame\n");
1083 bool WebTestProxyBase::DidFailProvisionalLoad(
1084 blink::WebLocalFrame
* frame
,
1085 const blink::WebURLError
& error
,
1086 blink::WebHistoryCommitType commit_type
) {
1087 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1088 PrintFrameDescription(delegate_
, frame
);
1089 delegate_
->PrintMessage(" - didFailProvisionalLoadWithError\n");
1091 CheckDone(frame
, MainResourceLoadFailed
);
1092 return !frame
->provisionalDataSource();
1095 void WebTestProxyBase::DidCommitProvisionalLoad(
1096 blink::WebLocalFrame
* frame
,
1097 const blink::WebHistoryItem
& history_item
,
1098 blink::WebHistoryCommitType history_type
) {
1099 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1100 PrintFrameDescription(delegate_
, frame
);
1101 delegate_
->PrintMessage(" - didCommitLoadForFrame\n");
1105 void WebTestProxyBase::DidReceiveTitle(blink::WebLocalFrame
* frame
,
1106 const blink::WebString
& title
,
1107 blink::WebTextDirection direction
) {
1108 blink::WebCString title8
= title
.utf8();
1110 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1111 PrintFrameDescription(delegate_
, frame
);
1112 delegate_
->PrintMessage(std::string(" - didReceiveTitle: ") +
1113 title8
.data() + "\n");
1116 if (test_interfaces_
->GetTestRunner()->shouldDumpTitleChanges())
1117 delegate_
->PrintMessage(std::string("TITLE CHANGED: '") + title8
.data() +
1121 void WebTestProxyBase::DidChangeIcon(blink::WebLocalFrame
* frame
,
1122 blink::WebIconURL::Type icon_type
) {
1123 if (test_interfaces_
->GetTestRunner()->shouldDumpIconChanges()) {
1124 PrintFrameDescription(delegate_
, frame
);
1125 delegate_
->PrintMessage(std::string(" - didChangeIcons\n"));
1129 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame
* frame
) {
1130 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1131 PrintFrameDescription(delegate_
, frame
);
1132 delegate_
->PrintMessage(" - didFinishDocumentLoadForFrame\n");
1136 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame
* frame
) {
1137 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1138 PrintFrameDescription(delegate_
, frame
);
1139 delegate_
->PrintMessage(" - didHandleOnloadEventsForFrame\n");
1143 void WebTestProxyBase::DidFailLoad(blink::WebLocalFrame
* frame
,
1144 const blink::WebURLError
& error
,
1145 blink::WebHistoryCommitType commit_type
) {
1146 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1147 PrintFrameDescription(delegate_
, frame
);
1148 delegate_
->PrintMessage(" - didFailLoadWithError\n");
1150 CheckDone(frame
, MainResourceLoadFailed
);
1153 void WebTestProxyBase::DidFinishLoad(blink::WebLocalFrame
* frame
) {
1154 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1155 PrintFrameDescription(delegate_
, frame
);
1156 delegate_
->PrintMessage(" - didFinishLoadForFrame\n");
1158 CheckDone(frame
, LoadFinished
);
1161 void WebTestProxyBase::DidDetectXSS(blink::WebLocalFrame
* frame
,
1162 const blink::WebURL
& insecure_url
,
1163 bool did_block_entire_page
) {
1164 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks())
1165 delegate_
->PrintMessage("didDetectXSS\n");
1168 void WebTestProxyBase::DidDispatchPingLoader(blink::WebLocalFrame
* frame
,
1169 const blink::WebURL
& url
) {
1170 if (test_interfaces_
->GetTestRunner()->shouldDumpPingLoaderCallbacks())
1171 delegate_
->PrintMessage(std::string("PingLoader dispatched to '") +
1172 URLDescription(url
).c_str() + "'.\n");
1175 void WebTestProxyBase::WillSendRequest(
1176 blink::WebLocalFrame
* frame
,
1177 unsigned identifier
,
1178 blink::WebURLRequest
& request
,
1179 const blink::WebURLResponse
& redirect_response
) {
1180 // Need to use GURL for host() and SchemeIs()
1181 GURL url
= request
.url();
1182 std::string request_url
= url
.possibly_invalid_spec();
1184 GURL main_document_url
= request
.firstPartyForCookies();
1186 if (redirect_response
.isNull() &&
1187 (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks() ||
1188 test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities())) {
1189 DCHECK(resource_identifier_map_
.find(identifier
) ==
1190 resource_identifier_map_
.end());
1191 resource_identifier_map_
[identifier
] =
1192 DescriptionSuitableForTestResult(request_url
);
1195 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1196 if (resource_identifier_map_
.find(identifier
) ==
1197 resource_identifier_map_
.end())
1198 delegate_
->PrintMessage("<unknown>");
1200 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1201 delegate_
->PrintMessage(" - willSendRequest <NSURLRequest URL ");
1202 delegate_
->PrintMessage(
1203 DescriptionSuitableForTestResult(request_url
).c_str());
1204 delegate_
->PrintMessage(", main document URL ");
1205 delegate_
->PrintMessage(URLDescription(main_document_url
).c_str());
1206 delegate_
->PrintMessage(", http method ");
1207 delegate_
->PrintMessage(request
.httpMethod().utf8().data());
1208 delegate_
->PrintMessage("> redirectResponse ");
1209 PrintResponseDescription(delegate_
, redirect_response
);
1210 delegate_
->PrintMessage("\n");
1213 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1214 delegate_
->PrintMessage(
1215 DescriptionSuitableForTestResult(request_url
).c_str());
1216 delegate_
->PrintMessage(" has priority ");
1217 delegate_
->PrintMessage(PriorityDescription(request
.priority()));
1218 delegate_
->PrintMessage("\n");
1221 if (test_interfaces_
->GetTestRunner()->httpHeadersToClear()) {
1222 const std::set
<std::string
>* clearHeaders
=
1223 test_interfaces_
->GetTestRunner()->httpHeadersToClear();
1224 for (std::set
<std::string
>::const_iterator header
= clearHeaders
->begin();
1225 header
!= clearHeaders
->end();
1227 request
.clearHTTPHeaderField(blink::WebString::fromUTF8(*header
));
1230 std::string host
= url
.host();
1231 if (!host
.empty() &&
1232 (url
.SchemeIs(url::kHttpScheme
) || url
.SchemeIs(url::kHttpsScheme
))) {
1233 if (!IsLocalHost(host
) && !IsTestHost(host
) &&
1234 !HostIsUsedBySomeTestsToGenerateError(host
) &&
1235 ((!main_document_url
.SchemeIs(url::kHttpScheme
) &&
1236 !main_document_url
.SchemeIs(url::kHttpsScheme
)) ||
1237 IsLocalHost(main_document_url
.host())) &&
1238 !delegate_
->AllowExternalPages()) {
1239 delegate_
->PrintMessage(std::string("Blocked access to external URL ") +
1240 request_url
+ "\n");
1241 BlockRequest(request
);
1246 // Set the new substituted URL.
1247 request
.setURL(delegate_
->RewriteLayoutTestsURL(request
.url().spec()));
1250 void WebTestProxyBase::DidReceiveResponse(
1251 blink::WebLocalFrame
* frame
,
1252 unsigned identifier
,
1253 const blink::WebURLResponse
& response
) {
1254 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1255 if (resource_identifier_map_
.find(identifier
) ==
1256 resource_identifier_map_
.end())
1257 delegate_
->PrintMessage("<unknown>");
1259 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1260 delegate_
->PrintMessage(" - didReceiveResponse ");
1261 PrintResponseDescription(delegate_
, response
);
1262 delegate_
->PrintMessage("\n");
1264 if (test_interfaces_
->GetTestRunner()
1265 ->shouldDumpResourceResponseMIMETypes()) {
1266 GURL url
= response
.url();
1267 blink::WebString mime_type
= response
.mimeType();
1268 delegate_
->PrintMessage(url
.ExtractFileName());
1269 delegate_
->PrintMessage(" has MIME type ");
1270 // Simulate NSURLResponse's mapping of empty/unknown MIME types to
1271 // application/octet-stream
1272 delegate_
->PrintMessage(mime_type
.isEmpty() ? "application/octet-stream"
1273 : mime_type
.utf8().data());
1274 delegate_
->PrintMessage("\n");
1278 void WebTestProxyBase::DidChangeResourcePriority(
1279 blink::WebLocalFrame
* frame
,
1280 unsigned identifier
,
1281 const blink::WebURLRequest::Priority
& priority
,
1282 int intra_priority_value
) {
1283 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1284 if (resource_identifier_map_
.find(identifier
) ==
1285 resource_identifier_map_
.end())
1286 delegate_
->PrintMessage("<unknown>");
1288 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1289 delegate_
->PrintMessage(
1290 base::StringPrintf(" changed priority to %s, intra_priority %d\n",
1291 PriorityDescription(priority
).c_str(),
1292 intra_priority_value
));
1296 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame
* frame
,
1297 unsigned identifier
) {
1298 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1299 if (resource_identifier_map_
.find(identifier
) ==
1300 resource_identifier_map_
.end())
1301 delegate_
->PrintMessage("<unknown>");
1303 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1304 delegate_
->PrintMessage(" - didFinishLoading\n");
1306 resource_identifier_map_
.erase(identifier
);
1307 CheckDone(frame
, ResourceLoadCompleted
);
1310 void WebTestProxyBase::DidAddMessageToConsole(
1311 const blink::WebConsoleMessage
& message
,
1312 const blink::WebString
& source_name
,
1313 unsigned source_line
) {
1314 // This matches win DumpRenderTree's UIDelegate.cpp.
1315 if (!log_console_output_
)
1318 switch (message
.level
) {
1319 case blink::WebConsoleMessage::LevelDebug
:
1322 case blink::WebConsoleMessage::LevelLog
:
1325 case blink::WebConsoleMessage::LevelInfo
:
1328 case blink::WebConsoleMessage::LevelWarning
:
1331 case blink::WebConsoleMessage::LevelError
:
1337 delegate_
->PrintMessage(std::string("CONSOLE ") + level
+ ": ");
1339 delegate_
->PrintMessage(base::StringPrintf("line %d: ", source_line
));
1341 if (!message
.text
.isEmpty()) {
1342 std::string new_message
;
1343 new_message
= message
.text
.utf8();
1344 size_t file_protocol
= new_message
.find("file://");
1345 if (file_protocol
!= std::string::npos
) {
1346 new_message
= new_message
.substr(0, file_protocol
) +
1347 URLSuitableForTestResult(new_message
.substr(file_protocol
));
1349 delegate_
->PrintMessage(new_message
);
1351 delegate_
->PrintMessage(std::string("\n"));
1354 void WebTestProxyBase::CheckDone(blink::WebLocalFrame
* frame
,
1355 CheckDoneReason reason
) {
1356 if (frame
!= test_interfaces_
->GetTestRunner()->topLoadingFrame())
1358 if (reason
!= MainResourceLoadFailed
&&
1359 (frame
->isResourceLoadInProgress() || frame
->isLoading()))
1361 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, true);
1364 blink::WebNavigationPolicy
WebTestProxyBase::DecidePolicyForNavigation(
1365 const blink::WebFrameClient::NavigationPolicyInfo
& info
) {
1366 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
1367 delegate_
->PrintMessage("Default policy for navigation to '" +
1368 URLDescription(info
.urlRequest
.url()) + "' is '" +
1369 WebNavigationPolicyToString(info
.defaultPolicy
) +
1373 blink::WebNavigationPolicy result
;
1374 if (!test_interfaces_
->GetTestRunner()->policyDelegateEnabled())
1375 return info
.defaultPolicy
;
1377 delegate_
->PrintMessage(
1378 std::string("Policy delegate: attempt to load ") +
1379 URLDescription(info
.urlRequest
.url()) + " with navigation type '" +
1380 WebNavigationTypeToString(info
.navigationType
) + "'\n");
1381 if (test_interfaces_
->GetTestRunner()->policyDelegateIsPermissive())
1382 result
= blink::WebNavigationPolicyCurrentTab
;
1384 result
= blink::WebNavigationPolicyIgnore
;
1386 if (test_interfaces_
->GetTestRunner()->policyDelegateShouldNotifyDone()) {
1387 test_interfaces_
->GetTestRunner()->policyDelegateDone();
1388 result
= blink::WebNavigationPolicyIgnore
;
1394 bool WebTestProxyBase::WillCheckAndDispatchMessageEvent(
1395 blink::WebLocalFrame
* source_frame
,
1396 blink::WebFrame
* target_frame
,
1397 blink::WebSecurityOrigin target
,
1398 blink::WebDOMMessageEvent event
) {
1399 if (test_interfaces_
->GetTestRunner()->shouldInterceptPostMessage()) {
1400 delegate_
->PrintMessage("intercepted postMessage\n");
1407 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString
& event_name
) {
1408 if (test_interfaces_
->GetTestRunner()->shouldDumpSpellCheckCallbacks()) {
1409 delegate_
->PrintMessage(std::string("SpellCheckEvent: ") +
1410 event_name
.utf8().data() + "\n");
1414 void WebTestProxyBase::ResetInputMethod() {
1415 // If a composition text exists, then we need to let the browser process
1416 // to cancel the input method's ongoing composition session.
1418 web_widget_
->confirmComposition();
1421 blink::WebString
WebTestProxyBase::acceptLanguages() {
1422 return blink::WebString::fromUTF8(accept_languages_
);
1425 } // namespace test_runner