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
;
289 std::string
DumpFrameHeaderIfNeeded(blink::WebFrame
* frame
) {
292 // Add header for all but the main frame. Skip empty frames.
293 if (frame
->parent() && !frame
->document().documentElement().isNull()) {
294 result
.append("\n--------\nFrame: '");
295 result
.append(frame
->uniqueName().utf8().data());
296 result
.append("'\n--------\n");
302 std::string
DumpFramesAsMarkup(blink::WebFrame
* frame
, bool recursive
) {
303 std::string result
= DumpFrameHeaderIfNeeded(frame
);
304 result
.append(frame
->contentAsMarkup().utf8());
308 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
309 child
= child
->nextSibling())
310 result
.append(DumpFramesAsMarkup(child
, recursive
));
316 std::string
DumpDocumentText(blink::WebFrame
* frame
) {
317 return frame
->document().contentAsTextForTesting().utf8();
320 std::string
DumpFramesAsText(blink::WebFrame
* frame
, bool recursive
) {
321 std::string result
= DumpFrameHeaderIfNeeded(frame
);
322 result
.append(DumpDocumentText(frame
));
326 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
327 child
= child
->nextSibling())
328 result
.append(DumpFramesAsText(child
, recursive
));
334 std::string
DumpFramesAsPrintedText(blink::WebFrame
* frame
, bool recursive
) {
335 // Cannot do printed format for anything other than HTML
336 if (!frame
->document().isHTMLDocument())
337 return std::string();
339 std::string result
= DumpFrameHeaderIfNeeded(frame
);
341 frame
->layoutTreeAsText(blink::WebFrame::LayoutAsTextPrinting
).utf8());
345 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
346 child
= child
->nextSibling())
347 result
.append(DumpFramesAsPrintedText(child
, recursive
));
353 std::string
DumpFrameScrollPosition(blink::WebFrame
* frame
, bool recursive
) {
355 blink::WebSize offset
= frame
->scrollOffset();
356 if (offset
.width
> 0 || offset
.height
> 0) {
357 if (frame
->parent()) {
359 std::string("frame '") + frame
->uniqueName().utf8().data() + "' ";
362 &result
, "scrolled to %d,%d\n", offset
.width
, offset
.height
);
367 for (blink::WebFrame
* child
= frame
->firstChild(); child
;
368 child
= child
->nextSibling())
369 result
+= DumpFrameScrollPosition(child
, recursive
);
373 std::string
DumpAllBackForwardLists(TestInterfaces
* interfaces
,
374 WebTestDelegate
* delegate
) {
376 const std::vector
<WebTestProxyBase
*>& window_list
=
377 interfaces
->GetWindowList();
378 for (size_t i
= 0; i
< window_list
.size(); ++i
)
379 result
.append(delegate
->DumpHistoryForWindow(window_list
.at(i
)));
384 WebTestProxyBase::WebTestProxyBase()
385 : web_test_interfaces_(NULL
),
386 test_interfaces_(NULL
),
389 spellcheck_(new SpellCheckClient(this)),
394 WebTestProxyBase::~WebTestProxyBase() {
395 test_interfaces_
->WindowClosed(this);
396 delegate_
->OnWebTestProxyBaseDestroy(this);
399 void WebTestProxyBase::SetInterfaces(WebTestInterfaces
* interfaces
) {
400 web_test_interfaces_
= interfaces
;
401 test_interfaces_
= interfaces
->GetTestInterfaces();
402 test_interfaces_
->WindowOpened(this);
405 WebTestInterfaces
* WebTestProxyBase::GetInterfaces() {
406 return web_test_interfaces_
;
409 void WebTestProxyBase::SetDelegate(WebTestDelegate
* delegate
) {
410 delegate_
= delegate
;
411 spellcheck_
->SetDelegate(delegate
);
412 if (speech_recognizer_
.get())
413 speech_recognizer_
->SetDelegate(delegate
);
416 WebTestDelegate
* WebTestProxyBase::GetDelegate() {
420 blink::WebView
* WebTestProxyBase::GetWebView() const {
422 // TestRunner does not support popup widgets. So |web_widget|_ is always a
424 return static_cast<blink::WebView
*>(web_widget_
);
427 void WebTestProxyBase::Reset() {
429 animate_scheduled_
= false;
430 resource_identifier_map_
.clear();
431 log_console_output_
= true;
432 accept_languages_
= "";
435 blink::WebSpellCheckClient
* WebTestProxyBase::GetSpellCheckClient() const {
436 return spellcheck_
.get();
439 blink::WebColorChooser
* WebTestProxyBase::CreateColorChooser(
440 blink::WebColorChooserClient
* client
,
441 const blink::WebColor
& color
,
442 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
) {
443 // This instance is deleted by WebCore::ColorInputType
444 return new MockColorChooser(client
, delegate_
, this);
447 bool WebTestProxyBase::RunFileChooser(
448 const blink::WebFileChooserParams
& params
,
449 blink::WebFileChooserCompletion
* completion
) {
450 delegate_
->PrintMessage("Mock: Opening a file chooser.\n");
451 // FIXME: Add ability to set file names to a file upload control.
455 void WebTestProxyBase::ShowValidationMessage(
456 const blink::WebString
& main_message
,
457 blink::WebTextDirection main_message_hint
,
458 const blink::WebString
& sub_message
,
459 blink::WebTextDirection sub_message_hint
) {
460 base::string16 wrapped_main_text
= main_message
;
461 base::string16 wrapped_sub_text
= sub_message
;
463 if (main_message_hint
== blink::WebTextDirectionLeftToRight
) {
465 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text
);
466 } else if (main_message_hint
== blink::WebTextDirectionRightToLeft
&&
467 !base::i18n::IsRTL()) {
468 base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text
);
471 if (!wrapped_sub_text
.empty()) {
472 if (sub_message_hint
== blink::WebTextDirectionLeftToRight
) {
474 base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text
);
475 } else if (sub_message_hint
== blink::WebTextDirectionRightToLeft
) {
476 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text
);
479 delegate_
->PrintMessage("ValidationMessageClient: main-message=" +
480 base::UTF16ToUTF8(wrapped_main_text
) +
482 base::UTF16ToUTF8(wrapped_sub_text
) + "\n");
485 std::string
WebTestProxyBase::CaptureTree(
486 bool debug_render_tree
,
487 bool dump_line_box_trees
) {
488 bool should_dump_custom_text
=
489 test_interfaces_
->GetTestRunner()->shouldDumpAsCustomText();
490 bool should_dump_as_text
=
491 test_interfaces_
->GetTestRunner()->shouldDumpAsText();
492 bool should_dump_as_markup
=
493 test_interfaces_
->GetTestRunner()->shouldDumpAsMarkup();
494 bool should_dump_as_printed
= test_interfaces_
->GetTestRunner()->isPrinting();
495 blink::WebFrame
* frame
= GetWebView()->mainFrame();
496 std::string data_utf8
;
497 if (should_dump_custom_text
) {
498 // Append a newline for the test driver.
499 data_utf8
= test_interfaces_
->GetTestRunner()->customDumpText() + "\n";
500 } else if (should_dump_as_text
) {
502 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsText();
503 data_utf8
= should_dump_as_printed
?
504 DumpFramesAsPrintedText(frame
, recursive
) :
505 DumpFramesAsText(frame
, recursive
);
506 } else if (should_dump_as_markup
) {
508 test_interfaces_
->GetTestRunner()->shouldDumpChildFramesAsMarkup();
509 // Append a newline for the test driver.
510 data_utf8
= DumpFramesAsMarkup(frame
, recursive
);
512 bool recursive
= test_interfaces_
->GetTestRunner()
513 ->shouldDumpChildFrameScrollPositions();
514 blink::WebFrame::LayoutAsTextControls layout_text_behavior
=
515 blink::WebFrame::LayoutAsTextNormal
;
516 if (should_dump_as_printed
)
517 layout_text_behavior
|= blink::WebFrame::LayoutAsTextPrinting
;
518 if (debug_render_tree
)
519 layout_text_behavior
|= blink::WebFrame::LayoutAsTextDebug
;
520 if (dump_line_box_trees
)
521 layout_text_behavior
|= blink::WebFrame::LayoutAsTextWithLineTrees
;
522 data_utf8
= frame
->layoutTreeAsText(layout_text_behavior
).utf8();
523 data_utf8
+= DumpFrameScrollPosition(frame
, recursive
);
526 if (test_interfaces_
->GetTestRunner()->ShouldDumpBackForwardList())
527 data_utf8
+= DumpAllBackForwardLists(test_interfaces_
, delegate_
);
532 void WebTestProxyBase::DrawSelectionRect(SkCanvas
* canvas
) {
533 // See if we need to draw the selection bounds rect. Selection bounds
534 // rect is the rect enclosing the (possibly transformed) selection.
535 // The rect should be drawn after everything is laid out and painted.
536 if (!test_interfaces_
->GetTestRunner()->shouldDumpSelectionRect())
538 // If there is a selection rect - draw a red 1px border enclosing rect
539 blink::WebRect wr
= GetWebView()->mainFrame()->selectionBoundsRect();
542 // Render a red rectangle bounding selection rect
544 paint
.setColor(0xFFFF0000); // Fully opaque red
545 paint
.setStyle(SkPaint::kStroke_Style
);
546 paint
.setFlags(SkPaint::kAntiAlias_Flag
);
547 paint
.setStrokeWidth(1.0f
);
548 SkIRect rect
; // Bounding rect
549 rect
.set(wr
.x
, wr
.y
, wr
.x
+ wr
.width
, wr
.y
+ wr
.height
);
550 canvas
->drawIRect(rect
, paint
);
553 void WebTestProxyBase::SetAcceptLanguages(const std::string
& accept_languages
) {
554 bool notify
= accept_languages_
!= accept_languages
;
555 accept_languages_
= accept_languages
;
558 GetWebView()->acceptLanguagesChanged();
561 void WebTestProxyBase::CopyImageAtAndCapturePixels(
562 int x
, int y
, const base::Callback
<void(const SkBitmap
&)>& callback
) {
563 DCHECK(!callback
.is_null());
564 uint64_t sequence_number
= blink::Platform::current()->clipboard()->
565 sequenceNumber(blink::WebClipboard::Buffer());
566 GetWebView()->copyImageAt(blink::WebPoint(x
, y
));
567 if (sequence_number
== blink::Platform::current()->clipboard()->
568 sequenceNumber(blink::WebClipboard::Buffer())) {
569 SkBitmap emptyBitmap
;
570 callback
.Run(emptyBitmap
);
574 blink::WebData data
= blink::Platform::current()->clipboard()->readImage(
575 blink::WebClipboard::Buffer());
576 blink::WebImage image
= blink::WebImage::fromData(data
, blink::WebSize());
577 const SkBitmap
& bitmap
= image
.getSkBitmap();
578 SkAutoLockPixels
autoLock(bitmap
);
579 callback
.Run(bitmap
);
582 void WebTestProxyBase::CapturePixelsForPrinting(
583 const base::Callback
<void(const SkBitmap
&)>& callback
) {
584 web_widget_
->layout();
586 blink::WebSize page_size_in_pixels
= web_widget_
->size();
587 blink::WebFrame
* web_frame
= GetWebView()->mainFrame();
589 int page_count
= web_frame
->printBegin(page_size_in_pixels
);
590 int totalHeight
= page_count
* (page_size_in_pixels
.height
+ 1) - 1;
592 bool is_opaque
= false;
593 skia::RefPtr
<SkCanvas
> canvas(skia::AdoptRef(skia::TryCreateBitmapCanvas(
594 page_size_in_pixels
.width
, totalHeight
, is_opaque
)));
596 callback
.Run(SkBitmap());
599 web_frame
->printPagesWithBoundaries(canvas
.get(), page_size_in_pixels
);
600 web_frame
->printEnd();
602 DrawSelectionRect(canvas
.get());
603 SkBaseDevice
* device
= skia::GetTopDevice(*canvas
);
604 const SkBitmap
& bitmap
= device
->accessBitmap(false);
605 callback
.Run(bitmap
);
608 CaptureCallback::CaptureCallback(
609 const base::Callback
<void(const SkBitmap
&)>& callback
)
610 : callback_(callback
), wait_for_popup_(false) {
613 CaptureCallback::~CaptureCallback() {
616 void CaptureCallback::didCompositeAndReadback(const SkBitmap
& bitmap
) {
617 TRACE_EVENT2("shell",
618 "CaptureCallback::didCompositeAndReadback",
620 bitmap
.info().width(),
622 bitmap
.info().height());
623 if (!wait_for_popup_
) {
624 callback_
.Run(bitmap
);
628 if (main_bitmap_
.isNull()) {
629 bitmap
.deepCopyTo(&main_bitmap_
);
632 SkCanvas
canvas(main_bitmap_
);
633 canvas
.drawBitmap(bitmap
, popup_position_
.x(), popup_position_
.y());
634 callback_
.Run(main_bitmap_
);
638 void WebTestProxyBase::CapturePixelsAsync(
639 const base::Callback
<void(const SkBitmap
&)>& callback
) {
640 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
641 DCHECK(!callback
.is_null());
643 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
644 if (drag_image_
.isNull()) {
645 // This means the test called dumpDragImage but did not initiate a drag.
646 // Return a blank image so that the test fails.
648 bitmap
.allocN32Pixels(1, 1);
650 SkAutoLockPixels
lock(bitmap
);
651 bitmap
.eraseColor(0);
653 callback
.Run(bitmap
);
657 callback
.Run(drag_image_
.getSkBitmap());
661 if (test_interfaces_
->GetTestRunner()->isPrinting()) {
662 base::ThreadTaskRunnerHandle::Get()->PostTask(
663 FROM_HERE
, base::Bind(&WebTestProxyBase::CapturePixelsForPrinting
,
664 base::Unretained(this), callback
));
668 CaptureCallback
* capture_callback
= new CaptureCallback(base::Bind(
669 &WebTestProxyBase::DidCapturePixelsAsync
, base::Unretained(this),
671 web_widget_
->compositeAndReadbackAsync(capture_callback
);
672 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
673 capture_callback
->set_wait_for_popup(true);
674 capture_callback
->set_popup_position(popup
->positionRelativeToOwner());
675 popup
->compositeAndReadbackAsync(capture_callback
);
679 void WebTestProxyBase::DidCapturePixelsAsync(
680 const base::Callback
<void(const SkBitmap
&)>& callback
,
681 const SkBitmap
& bitmap
) {
682 SkCanvas
canvas(bitmap
);
683 DrawSelectionRect(&canvas
);
684 if (!callback
.is_null())
685 callback
.Run(bitmap
);
688 void WebTestProxyBase::SetLogConsoleOutput(bool enabled
) {
689 log_console_output_
= enabled
;
692 void LayoutAndPaintCallback::didLayoutAndPaint() {
693 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint");
694 if (wait_for_popup_
) {
695 wait_for_popup_
= false;
699 if (!callback_
.is_null())
704 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure
& callback
) {
705 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen");
707 LayoutAndPaintCallback
* layout_and_paint_callback
=
708 new LayoutAndPaintCallback(callback
);
709 web_widget_
->layoutAndPaintAsync(layout_and_paint_callback
);
710 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
711 layout_and_paint_callback
->set_wait_for_popup(true);
712 popup
->layoutAndPaintAsync(layout_and_paint_callback
);
716 void WebTestProxyBase::GetScreenOrientationForTesting(
717 blink::WebScreenInfo
& screen_info
) {
718 if (!screen_orientation_client_
)
720 // Override screen orientation information with mock data.
721 screen_info
.orientationType
=
722 screen_orientation_client_
->CurrentOrientationType();
723 screen_info
.orientationAngle
=
724 screen_orientation_client_
->CurrentOrientationAngle();
727 MockScreenOrientationClient
*
728 WebTestProxyBase::GetScreenOrientationClientMock() {
729 if (!screen_orientation_client_
.get()) {
730 screen_orientation_client_
.reset(new MockScreenOrientationClient
);
732 return screen_orientation_client_
.get();
735 MockWebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizerMock() {
736 if (!speech_recognizer_
.get()) {
737 speech_recognizer_
.reset(new MockWebSpeechRecognizer());
738 speech_recognizer_
->SetDelegate(delegate_
);
740 return speech_recognizer_
.get();
743 MockCredentialManagerClient
*
744 WebTestProxyBase::GetCredentialManagerClientMock() {
745 if (!credential_manager_client_
.get())
746 credential_manager_client_
.reset(new MockCredentialManagerClient());
747 return credential_manager_client_
.get();
750 void WebTestProxyBase::ScheduleAnimation() {
751 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
754 if (!animate_scheduled_
) {
755 animate_scheduled_
= true;
756 delegate_
->PostDelayedTask(
757 new HostMethodTask(this, &WebTestProxyBase::AnimateNow
), 1);
761 void WebTestProxyBase::AnimateNow() {
762 if (animate_scheduled_
) {
763 base::TimeDelta animate_time
= base::TimeTicks::Now() - base::TimeTicks();
764 base::TimeDelta interval
= base::TimeDelta::FromMicroseconds(16666);
765 blink::WebBeginFrameArgs
args(animate_time
.InSecondsF(),
766 (animate_time
+ interval
).InSecondsF(),
767 interval
.InSecondsF());
769 animate_scheduled_
= false;
770 web_widget_
->beginFrame(args
);
771 web_widget_
->layout();
772 if (blink::WebPagePopup
* popup
= web_widget_
->pagePopup()) {
773 popup
->beginFrame(args
);
779 void WebTestProxyBase::PostAccessibilityEvent(const blink::WebAXObject
& obj
,
780 blink::WebAXEvent event
) {
781 // Only hook the accessibility events occured during the test run.
782 // This check prevents false positives in WebLeakDetector.
783 // The pending tasks in browser/renderer message queue may trigger
784 // accessibility events,
785 // and AccessibilityController will hold on to their target nodes if we don't
787 if (!test_interfaces_
->GetTestRunner()->TestIsRunning())
790 if (event
== blink::WebAXEventFocus
)
791 test_interfaces_
->GetAccessibilityController()->SetFocusedElement(obj
);
793 const char* event_name
= NULL
;
795 case blink::WebAXEventActiveDescendantChanged
:
796 event_name
= "ActiveDescendantChanged";
798 case blink::WebAXEventAlert
:
799 event_name
= "Alert";
801 case blink::WebAXEventAriaAttributeChanged
:
802 event_name
= "AriaAttributeChanged";
804 case blink::WebAXEventAutocorrectionOccured
:
805 event_name
= "AutocorrectionOccured";
807 case blink::WebAXEventBlur
:
810 case blink::WebAXEventCheckedStateChanged
:
811 event_name
= "CheckedStateChanged";
813 case blink::WebAXEventChildrenChanged
:
814 event_name
= "ChildrenChanged";
816 case blink::WebAXEventFocus
:
817 event_name
= "Focus";
819 case blink::WebAXEventHide
:
822 case blink::WebAXEventInvalidStatusChanged
:
823 event_name
= "InvalidStatusChanged";
825 case blink::WebAXEventLayoutComplete
:
826 event_name
= "LayoutComplete";
828 case blink::WebAXEventLiveRegionChanged
:
829 event_name
= "LiveRegionChanged";
831 case blink::WebAXEventLoadComplete
:
832 event_name
= "LoadComplete";
834 case blink::WebAXEventLocationChanged
:
835 event_name
= "LocationChanged";
837 case blink::WebAXEventMenuListItemSelected
:
838 event_name
= "MenuListItemSelected";
840 case blink::WebAXEventMenuListItemUnselected
:
841 event_name
= "MenuListItemUnselected";
843 case blink::WebAXEventMenuListValueChanged
:
844 event_name
= "MenuListValueChanged";
846 case blink::WebAXEventRowCollapsed
:
847 event_name
= "RowCollapsed";
849 case blink::WebAXEventRowCountChanged
:
850 event_name
= "RowCountChanged";
852 case blink::WebAXEventRowExpanded
:
853 event_name
= "RowExpanded";
855 case blink::WebAXEventScrollPositionChanged
:
856 event_name
= "ScrollPositionChanged";
858 case blink::WebAXEventScrolledToAnchor
:
859 event_name
= "ScrolledToAnchor";
861 case blink::WebAXEventSelectedChildrenChanged
:
862 event_name
= "SelectedChildrenChanged";
864 case blink::WebAXEventSelectedTextChanged
:
865 event_name
= "SelectedTextChanged";
867 case blink::WebAXEventShow
:
870 case blink::WebAXEventTextChanged
:
871 event_name
= "TextChanged";
873 case blink::WebAXEventTextInserted
:
874 event_name
= "TextInserted";
876 case blink::WebAXEventTextRemoved
:
877 event_name
= "TextRemoved";
879 case blink::WebAXEventValueChanged
:
880 event_name
= "ValueChanged";
883 event_name
= "Unknown";
887 test_interfaces_
->GetAccessibilityController()->NotificationReceived(
890 if (test_interfaces_
->GetAccessibilityController()
891 ->ShouldLogAccessibilityEvents()) {
892 std::string
message("AccessibilityNotification - ");
893 message
+= event_name
;
895 blink::WebNode node
= obj
.node();
896 if (!node
.isNull() && node
.isElementNode()) {
897 blink::WebElement element
= node
.to
<blink::WebElement
>();
898 if (element
.hasAttribute("id")) {
900 message
+= element
.getAttribute("id").utf8().data();
904 delegate_
->PrintMessage(message
+ "\n");
908 void WebTestProxyBase::StartDragging(blink::WebLocalFrame
* frame
,
909 const blink::WebDragData
& data
,
910 blink::WebDragOperationsMask mask
,
911 const blink::WebImage
& image
,
912 const blink::WebPoint
& point
) {
913 if (test_interfaces_
->GetTestRunner()->shouldDumpDragImage()) {
914 if (drag_image_
.isNull())
917 // When running a test, we need to fake a drag drop operation otherwise
918 // Windows waits for real mouse events to know when the drag is over.
919 test_interfaces_
->GetEventSender()->DoDragDrop(data
, mask
);
922 // The output from these methods in layout test mode should match that
923 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree.
925 void WebTestProxyBase::DidChangeSelection(bool is_empty_callback
) {
926 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
927 delegate_
->PrintMessage(
929 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
932 void WebTestProxyBase::DidChangeContents() {
933 if (test_interfaces_
->GetTestRunner()->shouldDumpEditingCallbacks())
934 delegate_
->PrintMessage(
935 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
938 bool WebTestProxyBase::CreateView(blink::WebLocalFrame
* frame
,
939 const blink::WebURLRequest
& request
,
940 const blink::WebWindowFeatures
& features
,
941 const blink::WebString
& frame_name
,
942 blink::WebNavigationPolicy policy
,
943 bool suppress_opener
) {
944 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
945 delegate_
->PrintMessage("Default policy for createView for '" +
946 URLDescription(request
.url()) + "' is '" +
947 WebNavigationPolicyToString(policy
) + "'\n");
950 if (!test_interfaces_
->GetTestRunner()->canOpenWindows())
952 if (test_interfaces_
->GetTestRunner()->shouldDumpCreateView())
953 delegate_
->PrintMessage(std::string("createView(") +
954 URLDescription(request
.url()) + ")\n");
958 blink::WebPlugin
* WebTestProxyBase::CreatePlugin(
959 blink::WebLocalFrame
* frame
,
960 const blink::WebPluginParams
& params
) {
961 if (TestPlugin::IsSupportedMimeType(params
.mimeType
))
962 return TestPlugin::create(frame
, params
, delegate_
);
963 return delegate_
->CreatePluginPlaceholder(frame
, params
);
966 void WebTestProxyBase::SetStatusText(const blink::WebString
& text
) {
967 if (!test_interfaces_
->GetTestRunner()->shouldDumpStatusCallbacks())
969 delegate_
->PrintMessage(
970 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") +
971 text
.utf8().data() + "\n");
974 void WebTestProxyBase::DidStopLoading() {
975 if (test_interfaces_
->GetTestRunner()->shouldDumpProgressFinishedCallback())
976 delegate_
->PrintMessage("postProgressFinishedNotification\n");
979 void WebTestProxyBase::ShowContextMenu(
980 const blink::WebContextMenuData
& context_menu_data
) {
981 test_interfaces_
->GetEventSender()->SetContextMenuData(context_menu_data
);
984 blink::WebUserMediaClient
* WebTestProxyBase::GetUserMediaClient() {
985 if (!user_media_client_
.get())
986 user_media_client_
.reset(new MockWebUserMediaClient(delegate_
));
987 return user_media_client_
.get();
990 // Simulate a print by going into print mode and then exit straight away.
991 void WebTestProxyBase::PrintPage(blink::WebLocalFrame
* frame
) {
992 blink::WebSize page_size_in_pixels
= web_widget_
->size();
993 if (page_size_in_pixels
.isEmpty())
995 blink::WebPrintParams
printParams(page_size_in_pixels
);
996 frame
->printBegin(printParams
);
1000 blink::WebSpeechRecognizer
* WebTestProxyBase::GetSpeechRecognizer() {
1001 return GetSpeechRecognizerMock();
1004 bool WebTestProxyBase::RequestPointerLock() {
1005 return test_interfaces_
->GetTestRunner()->RequestPointerLock();
1008 void WebTestProxyBase::RequestPointerUnlock() {
1009 test_interfaces_
->GetTestRunner()->RequestPointerUnlock();
1012 bool WebTestProxyBase::IsPointerLocked() {
1013 return test_interfaces_
->GetTestRunner()->isPointerLocked();
1016 void WebTestProxyBase::DidFocus() {
1017 delegate_
->SetFocus(this, true);
1020 void WebTestProxyBase::DidBlur() {
1021 delegate_
->SetFocus(this, false);
1024 void WebTestProxyBase::SetToolTipText(const blink::WebString
& text
,
1025 blink::WebTextDirection direction
) {
1026 test_interfaces_
->GetTestRunner()->setToolTipText(text
);
1029 void WebTestProxyBase::DidOpenChooser() {
1033 void WebTestProxyBase::DidCloseChooser() {
1037 bool WebTestProxyBase::IsChooserShown() {
1038 return 0 < chooser_count_
;
1041 void WebTestProxyBase::LoadURLExternally(
1042 blink::WebLocalFrame
* frame
,
1043 const blink::WebURLRequest
& request
,
1044 blink::WebNavigationPolicy policy
,
1045 const blink::WebString
& suggested_name
) {
1046 if (test_interfaces_
->GetTestRunner()->shouldWaitUntilExternalURLLoad()) {
1047 if (policy
== blink::WebNavigationPolicyDownload
) {
1048 delegate_
->PrintMessage(
1049 std::string("Downloading URL with suggested filename \"") +
1050 suggested_name
.utf8() + "\"\n");
1052 delegate_
->PrintMessage(std::string("Loading URL externally - \"") +
1053 URLDescription(request
.url()) + "\"\n");
1055 delegate_
->TestFinished();
1059 void WebTestProxyBase::DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) {
1060 if (!test_interfaces_
->GetTestRunner()->topLoadingFrame())
1061 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, false);
1063 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1064 PrintFrameDescription(delegate_
, frame
);
1065 delegate_
->PrintMessage(" - didStartProvisionalLoadForFrame\n");
1068 if (test_interfaces_
->GetTestRunner()
1069 ->shouldDumpUserGestureInFrameLoadCallbacks()) {
1070 PrintFrameuserGestureStatus(
1071 delegate_
, frame
, " - in didStartProvisionalLoadForFrame\n");
1075 void WebTestProxyBase::DidReceiveServerRedirectForProvisionalLoad(
1076 blink::WebLocalFrame
* frame
) {
1077 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1078 PrintFrameDescription(delegate_
, frame
);
1079 delegate_
->PrintMessage(
1080 " - didReceiveServerRedirectForProvisionalLoadForFrame\n");
1084 bool WebTestProxyBase::DidFailProvisionalLoad(
1085 blink::WebLocalFrame
* frame
,
1086 const blink::WebURLError
& error
,
1087 blink::WebHistoryCommitType commit_type
) {
1088 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1089 PrintFrameDescription(delegate_
, frame
);
1090 delegate_
->PrintMessage(" - didFailProvisionalLoadWithError\n");
1092 CheckDone(frame
, MainResourceLoadFailed
);
1093 return !frame
->provisionalDataSource();
1096 void WebTestProxyBase::DidCommitProvisionalLoad(
1097 blink::WebLocalFrame
* frame
,
1098 const blink::WebHistoryItem
& history_item
,
1099 blink::WebHistoryCommitType history_type
) {
1100 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1101 PrintFrameDescription(delegate_
, frame
);
1102 delegate_
->PrintMessage(" - didCommitLoadForFrame\n");
1106 void WebTestProxyBase::DidReceiveTitle(blink::WebLocalFrame
* frame
,
1107 const blink::WebString
& title
,
1108 blink::WebTextDirection direction
) {
1109 blink::WebCString title8
= title
.utf8();
1111 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1112 PrintFrameDescription(delegate_
, frame
);
1113 delegate_
->PrintMessage(std::string(" - didReceiveTitle: ") +
1114 title8
.data() + "\n");
1117 if (test_interfaces_
->GetTestRunner()->shouldDumpTitleChanges())
1118 delegate_
->PrintMessage(std::string("TITLE CHANGED: '") + title8
.data() +
1122 void WebTestProxyBase::DidChangeIcon(blink::WebLocalFrame
* frame
,
1123 blink::WebIconURL::Type icon_type
) {
1124 if (test_interfaces_
->GetTestRunner()->shouldDumpIconChanges()) {
1125 PrintFrameDescription(delegate_
, frame
);
1126 delegate_
->PrintMessage(std::string(" - didChangeIcons\n"));
1130 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame
* frame
) {
1131 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1132 PrintFrameDescription(delegate_
, frame
);
1133 delegate_
->PrintMessage(" - didFinishDocumentLoadForFrame\n");
1137 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame
* frame
) {
1138 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1139 PrintFrameDescription(delegate_
, frame
);
1140 delegate_
->PrintMessage(" - didHandleOnloadEventsForFrame\n");
1144 void WebTestProxyBase::DidFailLoad(blink::WebLocalFrame
* frame
,
1145 const blink::WebURLError
& error
,
1146 blink::WebHistoryCommitType commit_type
) {
1147 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1148 PrintFrameDescription(delegate_
, frame
);
1149 delegate_
->PrintMessage(" - didFailLoadWithError\n");
1151 CheckDone(frame
, MainResourceLoadFailed
);
1154 void WebTestProxyBase::DidFinishLoad(blink::WebLocalFrame
* frame
) {
1155 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks()) {
1156 PrintFrameDescription(delegate_
, frame
);
1157 delegate_
->PrintMessage(" - didFinishLoadForFrame\n");
1159 CheckDone(frame
, LoadFinished
);
1162 void WebTestProxyBase::DidDetectXSS(blink::WebLocalFrame
* frame
,
1163 const blink::WebURL
& insecure_url
,
1164 bool did_block_entire_page
) {
1165 if (test_interfaces_
->GetTestRunner()->shouldDumpFrameLoadCallbacks())
1166 delegate_
->PrintMessage("didDetectXSS\n");
1169 void WebTestProxyBase::DidDispatchPingLoader(blink::WebLocalFrame
* frame
,
1170 const blink::WebURL
& url
) {
1171 if (test_interfaces_
->GetTestRunner()->shouldDumpPingLoaderCallbacks())
1172 delegate_
->PrintMessage(std::string("PingLoader dispatched to '") +
1173 URLDescription(url
).c_str() + "'.\n");
1176 void WebTestProxyBase::WillSendRequest(
1177 blink::WebLocalFrame
* frame
,
1178 unsigned identifier
,
1179 blink::WebURLRequest
& request
,
1180 const blink::WebURLResponse
& redirect_response
) {
1181 // Need to use GURL for host() and SchemeIs()
1182 GURL url
= request
.url();
1183 std::string request_url
= url
.possibly_invalid_spec();
1185 GURL main_document_url
= request
.firstPartyForCookies();
1187 if (redirect_response
.isNull() &&
1188 (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks() ||
1189 test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities())) {
1190 DCHECK(resource_identifier_map_
.find(identifier
) ==
1191 resource_identifier_map_
.end());
1192 resource_identifier_map_
[identifier
] =
1193 DescriptionSuitableForTestResult(request_url
);
1196 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1197 if (resource_identifier_map_
.find(identifier
) ==
1198 resource_identifier_map_
.end())
1199 delegate_
->PrintMessage("<unknown>");
1201 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1202 delegate_
->PrintMessage(" - willSendRequest <NSURLRequest URL ");
1203 delegate_
->PrintMessage(
1204 DescriptionSuitableForTestResult(request_url
).c_str());
1205 delegate_
->PrintMessage(", main document URL ");
1206 delegate_
->PrintMessage(URLDescription(main_document_url
).c_str());
1207 delegate_
->PrintMessage(", http method ");
1208 delegate_
->PrintMessage(request
.httpMethod().utf8().data());
1209 delegate_
->PrintMessage("> redirectResponse ");
1210 PrintResponseDescription(delegate_
, redirect_response
);
1211 delegate_
->PrintMessage("\n");
1214 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1215 delegate_
->PrintMessage(
1216 DescriptionSuitableForTestResult(request_url
).c_str());
1217 delegate_
->PrintMessage(" has priority ");
1218 delegate_
->PrintMessage(PriorityDescription(request
.priority()));
1219 delegate_
->PrintMessage("\n");
1222 if (test_interfaces_
->GetTestRunner()->httpHeadersToClear()) {
1223 const std::set
<std::string
>* clearHeaders
=
1224 test_interfaces_
->GetTestRunner()->httpHeadersToClear();
1225 for (std::set
<std::string
>::const_iterator header
= clearHeaders
->begin();
1226 header
!= clearHeaders
->end();
1228 request
.clearHTTPHeaderField(blink::WebString::fromUTF8(*header
));
1231 std::string host
= url
.host();
1232 if (!host
.empty() &&
1233 (url
.SchemeIs(url::kHttpScheme
) || url
.SchemeIs(url::kHttpsScheme
))) {
1234 if (!IsLocalHost(host
) && !IsTestHost(host
) &&
1235 !HostIsUsedBySomeTestsToGenerateError(host
) &&
1236 ((!main_document_url
.SchemeIs(url::kHttpScheme
) &&
1237 !main_document_url
.SchemeIs(url::kHttpsScheme
)) ||
1238 IsLocalHost(main_document_url
.host())) &&
1239 !delegate_
->AllowExternalPages()) {
1240 delegate_
->PrintMessage(std::string("Blocked access to external URL ") +
1241 request_url
+ "\n");
1242 BlockRequest(request
);
1247 // Set the new substituted URL.
1248 request
.setURL(delegate_
->RewriteLayoutTestsURL(request
.url().spec()));
1251 void WebTestProxyBase::DidReceiveResponse(
1252 blink::WebLocalFrame
* frame
,
1253 unsigned identifier
,
1254 const blink::WebURLResponse
& response
) {
1255 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1256 if (resource_identifier_map_
.find(identifier
) ==
1257 resource_identifier_map_
.end())
1258 delegate_
->PrintMessage("<unknown>");
1260 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1261 delegate_
->PrintMessage(" - didReceiveResponse ");
1262 PrintResponseDescription(delegate_
, response
);
1263 delegate_
->PrintMessage("\n");
1265 if (test_interfaces_
->GetTestRunner()
1266 ->shouldDumpResourceResponseMIMETypes()) {
1267 GURL url
= response
.url();
1268 blink::WebString mime_type
= response
.mimeType();
1269 delegate_
->PrintMessage(url
.ExtractFileName());
1270 delegate_
->PrintMessage(" has MIME type ");
1271 // Simulate NSURLResponse's mapping of empty/unknown MIME types to
1272 // application/octet-stream
1273 delegate_
->PrintMessage(mime_type
.isEmpty() ? "application/octet-stream"
1274 : mime_type
.utf8().data());
1275 delegate_
->PrintMessage("\n");
1279 void WebTestProxyBase::DidChangeResourcePriority(
1280 blink::WebLocalFrame
* frame
,
1281 unsigned identifier
,
1282 const blink::WebURLRequest::Priority
& priority
,
1283 int intra_priority_value
) {
1284 if (test_interfaces_
->GetTestRunner()->shouldDumpResourcePriorities()) {
1285 if (resource_identifier_map_
.find(identifier
) ==
1286 resource_identifier_map_
.end())
1287 delegate_
->PrintMessage("<unknown>");
1289 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1290 delegate_
->PrintMessage(
1291 base::StringPrintf(" changed priority to %s, intra_priority %d\n",
1292 PriorityDescription(priority
).c_str(),
1293 intra_priority_value
));
1297 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame
* frame
,
1298 unsigned identifier
) {
1299 if (test_interfaces_
->GetTestRunner()->shouldDumpResourceLoadCallbacks()) {
1300 if (resource_identifier_map_
.find(identifier
) ==
1301 resource_identifier_map_
.end())
1302 delegate_
->PrintMessage("<unknown>");
1304 delegate_
->PrintMessage(resource_identifier_map_
[identifier
]);
1305 delegate_
->PrintMessage(" - didFinishLoading\n");
1307 resource_identifier_map_
.erase(identifier
);
1308 CheckDone(frame
, ResourceLoadCompleted
);
1311 void WebTestProxyBase::DidAddMessageToConsole(
1312 const blink::WebConsoleMessage
& message
,
1313 const blink::WebString
& source_name
,
1314 unsigned source_line
) {
1315 // This matches win DumpRenderTree's UIDelegate.cpp.
1316 if (!log_console_output_
)
1319 switch (message
.level
) {
1320 case blink::WebConsoleMessage::LevelDebug
:
1323 case blink::WebConsoleMessage::LevelLog
:
1326 case blink::WebConsoleMessage::LevelInfo
:
1329 case blink::WebConsoleMessage::LevelWarning
:
1332 case blink::WebConsoleMessage::LevelError
:
1338 delegate_
->PrintMessage(std::string("CONSOLE ") + level
+ ": ");
1340 delegate_
->PrintMessage(base::StringPrintf("line %d: ", source_line
));
1342 if (!message
.text
.isEmpty()) {
1343 std::string new_message
;
1344 new_message
= message
.text
.utf8();
1345 size_t file_protocol
= new_message
.find("file://");
1346 if (file_protocol
!= std::string::npos
) {
1347 new_message
= new_message
.substr(0, file_protocol
) +
1348 URLSuitableForTestResult(new_message
.substr(file_protocol
));
1350 delegate_
->PrintMessage(new_message
);
1352 delegate_
->PrintMessage(std::string("\n"));
1355 void WebTestProxyBase::CheckDone(blink::WebLocalFrame
* frame
,
1356 CheckDoneReason reason
) {
1357 if (frame
!= test_interfaces_
->GetTestRunner()->topLoadingFrame())
1359 if (reason
!= MainResourceLoadFailed
&&
1360 (frame
->isResourceLoadInProgress() || frame
->isLoading()))
1362 test_interfaces_
->GetTestRunner()->setTopLoadingFrame(frame
, true);
1365 blink::WebNavigationPolicy
WebTestProxyBase::DecidePolicyForNavigation(
1366 const blink::WebFrameClient::NavigationPolicyInfo
& info
) {
1367 if (test_interfaces_
->GetTestRunner()->shouldDumpNavigationPolicy()) {
1368 delegate_
->PrintMessage("Default policy for navigation to '" +
1369 URLDescription(info
.urlRequest
.url()) + "' is '" +
1370 WebNavigationPolicyToString(info
.defaultPolicy
) +
1374 blink::WebNavigationPolicy result
;
1375 if (!test_interfaces_
->GetTestRunner()->policyDelegateEnabled())
1376 return info
.defaultPolicy
;
1378 delegate_
->PrintMessage(
1379 std::string("Policy delegate: attempt to load ") +
1380 URLDescription(info
.urlRequest
.url()) + " with navigation type '" +
1381 WebNavigationTypeToString(info
.navigationType
) + "'\n");
1382 if (test_interfaces_
->GetTestRunner()->policyDelegateIsPermissive())
1383 result
= blink::WebNavigationPolicyCurrentTab
;
1385 result
= blink::WebNavigationPolicyIgnore
;
1387 if (test_interfaces_
->GetTestRunner()->policyDelegateShouldNotifyDone()) {
1388 test_interfaces_
->GetTestRunner()->policyDelegateDone();
1389 result
= blink::WebNavigationPolicyIgnore
;
1395 bool WebTestProxyBase::WillCheckAndDispatchMessageEvent(
1396 blink::WebLocalFrame
* source_frame
,
1397 blink::WebFrame
* target_frame
,
1398 blink::WebSecurityOrigin target
,
1399 blink::WebDOMMessageEvent event
) {
1400 if (test_interfaces_
->GetTestRunner()->shouldInterceptPostMessage()) {
1401 delegate_
->PrintMessage("intercepted postMessage\n");
1408 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString
& event_name
) {
1409 if (test_interfaces_
->GetTestRunner()->shouldDumpSpellCheckCallbacks()) {
1410 delegate_
->PrintMessage(std::string("SpellCheckEvent: ") +
1411 event_name
.utf8().data() + "\n");
1415 void WebTestProxyBase::ResetInputMethod() {
1416 // If a composition text exists, then we need to let the browser process
1417 // to cancel the input method's ongoing composition session.
1419 web_widget_
->confirmComposition();
1422 blink::WebString
WebTestProxyBase::acceptLanguages() {
1423 return blink::WebString::fromUTF8(accept_languages_
);
1426 } // namespace test_runner