1 // Copyright (c) 2012 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 "content/shell/renderer/webkit_test_runner.h"
11 #include "base/base64.h"
12 #include "base/command_line.h"
13 #include "base/debug/debugger.h"
14 #include "base/files/file_path.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/sys_string_conversions.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/url_constants.h"
25 #include "content/public/common/web_preferences.h"
26 #include "content/public/renderer/render_view.h"
27 #include "content/public/renderer/render_view_visitor.h"
28 #include "content/public/renderer/renderer_gamepad_provider.h"
29 #include "content/public/test/layouttest_support.h"
30 #include "content/shell/common/shell_messages.h"
31 #include "content/shell/common/shell_switches.h"
32 #include "content/shell/common/webkit_test_helpers.h"
33 #include "content/shell/renderer/gc_controller.h"
34 #include "content/shell/renderer/leak_detector.h"
35 #include "content/shell/renderer/shell_render_process_observer.h"
36 #include "content/shell/renderer/test_runner/WebTask.h"
37 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
38 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
39 #include "content/shell/renderer/test_runner/web_test_proxy.h"
40 #include "content/shell/renderer/test_runner/web_test_runner.h"
41 #include "net/base/filename_util.h"
42 #include "net/base/net_errors.h"
43 #include "skia/ext/platform_canvas.h"
44 #include "third_party/WebKit/public/platform/Platform.h"
45 #include "third_party/WebKit/public/platform/WebCString.h"
46 #include "third_party/WebKit/public/platform/WebPoint.h"
47 #include "third_party/WebKit/public/platform/WebRect.h"
48 #include "third_party/WebKit/public/platform/WebSize.h"
49 #include "third_party/WebKit/public/platform/WebString.h"
50 #include "third_party/WebKit/public/platform/WebURL.h"
51 #include "third_party/WebKit/public/platform/WebURLError.h"
52 #include "third_party/WebKit/public/platform/WebURLRequest.h"
53 #include "third_party/WebKit/public/platform/WebURLResponse.h"
54 #include "third_party/WebKit/public/web/WebArrayBufferView.h"
55 #include "third_party/WebKit/public/web/WebContextMenuData.h"
56 #include "third_party/WebKit/public/web/WebDataSource.h"
57 #include "third_party/WebKit/public/web/WebDevToolsAgent.h"
58 #include "third_party/WebKit/public/web/WebDocument.h"
59 #include "third_party/WebKit/public/web/WebElement.h"
60 #include "third_party/WebKit/public/web/WebHistoryItem.h"
61 #include "third_party/WebKit/public/web/WebKit.h"
62 #include "third_party/WebKit/public/web/WebLeakDetector.h"
63 #include "third_party/WebKit/public/web/WebLocalFrame.h"
64 #include "third_party/WebKit/public/web/WebScriptSource.h"
65 #include "third_party/WebKit/public/web/WebTestingSupport.h"
66 #include "third_party/WebKit/public/web/WebView.h"
67 #include "ui/gfx/rect.h"
69 using blink::Platform
;
70 using blink::WebArrayBufferView
;
71 using blink::WebContextMenuData
;
72 using blink::WebDevToolsAgent
;
73 using blink::WebDeviceMotionData
;
74 using blink::WebDeviceOrientationData
;
75 using blink::WebElement
;
76 using blink::WebLocalFrame
;
77 using blink::WebHistoryItem
;
78 using blink::WebLocalFrame
;
79 using blink::WebPoint
;
81 using blink::WebScriptSource
;
83 using blink::WebString
;
85 using blink::WebURLError
;
86 using blink::WebURLRequest
;
87 using blink::WebScreenOrientationType
;
88 using blink::WebTestingSupport
;
89 using blink::WebVector
;
96 void InvokeTaskHelper(void* context
) {
97 WebTask
* task
= reinterpret_cast<WebTask
*>(context
);
102 class SyncNavigationStateVisitor
: public RenderViewVisitor
{
104 SyncNavigationStateVisitor() {}
105 virtual ~SyncNavigationStateVisitor() {}
107 virtual bool Visit(RenderView
* render_view
) OVERRIDE
{
108 SyncNavigationState(render_view
);
112 DISALLOW_COPY_AND_ASSIGN(SyncNavigationStateVisitor
);
115 class ProxyToRenderViewVisitor
: public RenderViewVisitor
{
117 explicit ProxyToRenderViewVisitor(WebTestProxyBase
* proxy
)
121 virtual ~ProxyToRenderViewVisitor() {}
123 RenderView
* render_view() const { return render_view_
; }
125 virtual bool Visit(RenderView
* render_view
) OVERRIDE
{
126 WebKitTestRunner
* test_runner
= WebKitTestRunner::Get(render_view
);
131 if (test_runner
->proxy() == proxy_
) {
132 render_view_
= render_view
;
139 WebTestProxyBase
* proxy_
;
140 RenderView
* render_view_
;
142 DISALLOW_COPY_AND_ASSIGN(ProxyToRenderViewVisitor
);
145 class NavigateAwayVisitor
: public RenderViewVisitor
{
147 explicit NavigateAwayVisitor(RenderView
* main_render_view
)
148 : main_render_view_(main_render_view
) {}
149 virtual ~NavigateAwayVisitor() {}
151 virtual bool Visit(RenderView
* render_view
) OVERRIDE
{
152 if (render_view
== main_render_view_
)
154 render_view
->GetWebView()->mainFrame()->loadRequest(
155 WebURLRequest(GURL(url::kAboutBlankURL
)));
160 RenderView
* main_render_view_
;
162 DISALLOW_COPY_AND_ASSIGN(NavigateAwayVisitor
);
165 class UseSynchronousResizeModeVisitor
: public RenderViewVisitor
{
167 explicit UseSynchronousResizeModeVisitor(bool enable
) : enable_(enable
) {}
168 virtual ~UseSynchronousResizeModeVisitor() {}
170 virtual bool Visit(RenderView
* render_view
) OVERRIDE
{
171 UseSynchronousResizeMode(render_view
, enable_
);
181 WebKitTestRunner::WebKitTestRunner(RenderView
* render_view
)
182 : RenderViewObserver(render_view
),
183 RenderViewObserverTracker
<WebKitTestRunner
>(render_view
),
186 is_main_window_(false),
187 focus_on_next_commit_(false),
188 leak_detector_(new LeakDetector(this)) {
191 WebKitTestRunner::~WebKitTestRunner() {
194 // WebTestDelegate -----------------------------------------------------------
196 void WebKitTestRunner::clearEditCommand() {
197 render_view()->ClearEditCommands();
200 void WebKitTestRunner::setEditCommand(const std::string
& name
,
201 const std::string
& value
) {
202 render_view()->SetEditCommandForNextKeyEvent(name
, value
);
205 void WebKitTestRunner::setGamepadProvider(
206 scoped_ptr
<RendererGamepadProvider
> provider
) {
207 SetMockGamepadProvider(provider
.Pass());
210 void WebKitTestRunner::setDeviceLightData(const double data
) {
211 SetMockDeviceLightData(data
);
214 void WebKitTestRunner::setDeviceMotionData(const WebDeviceMotionData
& data
) {
215 SetMockDeviceMotionData(data
);
218 void WebKitTestRunner::setDeviceOrientationData(
219 const WebDeviceOrientationData
& data
) {
220 SetMockDeviceOrientationData(data
);
223 void WebKitTestRunner::setScreenOrientation(
224 const WebScreenOrientationType
& orientation
) {
225 MockScreenOrientationClient
* mock_client
=
226 proxy()->GetScreenOrientationClientMock();
227 mock_client
->UpdateDeviceOrientation(render_view()->GetWebView()->mainFrame(),
231 void WebKitTestRunner::resetScreenOrientation() {
232 MockScreenOrientationClient
* mock_client
=
233 proxy()->GetScreenOrientationClientMock();
234 mock_client
->ResetData();
237 void WebKitTestRunner::didChangeBatteryStatus(
238 const blink::WebBatteryStatus
& status
) {
239 MockBatteryStatusChanged(status
);
242 void WebKitTestRunner::printMessage(const std::string
& message
) {
243 Send(new ShellViewHostMsg_PrintMessage(routing_id(), message
));
246 void WebKitTestRunner::postTask(WebTask
* task
) {
247 Platform::current()->callOnMainThread(InvokeTaskHelper
, task
);
250 void WebKitTestRunner::postDelayedTask(WebTask
* task
, long long ms
) {
251 base::MessageLoop::current()->PostDelayedTask(
253 base::Bind(&WebTask::run
, base::Owned(task
)),
254 base::TimeDelta::FromMilliseconds(ms
));
257 WebString
WebKitTestRunner::registerIsolatedFileSystem(
258 const blink::WebVector
<blink::WebString
>& absolute_filenames
) {
259 std::vector
<base::FilePath
> files
;
260 for (size_t i
= 0; i
< absolute_filenames
.size(); ++i
)
261 files
.push_back(base::FilePath::FromUTF16Unsafe(absolute_filenames
[i
]));
262 std::string filesystem_id
;
263 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem(
264 routing_id(), files
, &filesystem_id
));
265 return WebString::fromUTF8(filesystem_id
);
268 long long WebKitTestRunner::getCurrentTimeInMillisecond() {
269 return base::TimeDelta(base::Time::Now() -
270 base::Time::UnixEpoch()).ToInternalValue() /
271 base::Time::kMicrosecondsPerMillisecond
;
274 WebString
WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
275 const std::string
& utf8_path
) {
276 base::FilePath path
= base::FilePath::FromUTF8Unsafe(utf8_path
);
277 if (!path
.IsAbsolute()) {
279 net::FilePathToFileURL(test_config_
.current_working_directory
.Append(
280 FILE_PATH_LITERAL("foo")));
281 net::FileURLToFilePath(base_url
.Resolve(utf8_path
), &path
);
283 return path
.AsUTF16Unsafe();
286 WebURL
WebKitTestRunner::localFileToDataURL(const WebURL
& file_url
) {
287 base::FilePath local_path
;
288 if (!net::FileURLToFilePath(file_url
, &local_path
))
291 std::string contents
;
292 Send(new ShellViewHostMsg_ReadFileToString(
293 routing_id(), local_path
, &contents
));
295 std::string contents_base64
;
296 base::Base64Encode(contents
, &contents_base64
);
298 const char data_url_prefix
[] = "data:text/css:charset=utf-8;base64,";
299 return WebURL(GURL(data_url_prefix
+ contents_base64
));
302 WebURL
WebKitTestRunner::rewriteLayoutTestsURL(const std::string
& utf8_url
) {
303 const char kPrefix
[] = "file:///tmp/LayoutTests/";
304 const int kPrefixLen
= arraysize(kPrefix
) - 1;
306 if (utf8_url
.compare(0, kPrefixLen
, kPrefix
, kPrefixLen
))
307 return WebURL(GURL(utf8_url
));
309 base::FilePath replace_path
=
310 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
311 FILE_PATH_LITERAL("LayoutTests/"));
313 std::string utf8_path
= base::WideToUTF8(replace_path
.value());
315 std::string utf8_path
=
316 base::WideToUTF8(base::SysNativeMBToWide(replace_path
.value()));
318 std::string new_url
=
319 std::string("file://") + utf8_path
+ utf8_url
.substr(kPrefixLen
);
320 return WebURL(GURL(new_url
));
323 TestPreferences
* WebKitTestRunner::preferences() {
327 void WebKitTestRunner::applyPreferences() {
328 WebPreferences prefs
= render_view()->GetWebkitPreferences();
329 ExportLayoutTestSpecificPreferences(prefs_
, &prefs
);
330 render_view()->SetWebkitPreferences(prefs
);
331 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs
));
334 std::string
WebKitTestRunner::makeURLErrorDescription(
335 const WebURLError
& error
) {
336 std::string domain
= error
.domain
.utf8();
337 int code
= error
.reason
;
339 if (domain
== net::kErrorDomain
) {
340 domain
= "NSURLErrorDomain";
341 switch (error
.reason
) {
342 case net::ERR_ABORTED
:
343 code
= -999; // NSURLErrorCancelled
345 case net::ERR_UNSAFE_PORT
:
346 // Our unsafe port checking happens at the network stack level, but we
347 // make this translation here to match the behavior of stock WebKit.
348 domain
= "WebKitErrorDomain";
351 case net::ERR_ADDRESS_INVALID
:
352 case net::ERR_ADDRESS_UNREACHABLE
:
353 case net::ERR_NETWORK_ACCESS_DENIED
:
354 code
= -1004; // NSURLErrorCannotConnectToHost
358 DLOG(WARNING
) << "Unknown error domain";
361 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">",
362 domain
.c_str(), code
, error
.unreachableURL
.spec().data());
365 void WebKitTestRunner::useUnfortunateSynchronousResizeMode(bool enable
) {
366 UseSynchronousResizeModeVisitor
visitor(enable
);
367 RenderView::ForEach(&visitor
);
370 void WebKitTestRunner::enableAutoResizeMode(const WebSize
& min_size
,
371 const WebSize
& max_size
) {
372 EnableAutoResizeMode(render_view(), min_size
, max_size
);
375 void WebKitTestRunner::disableAutoResizeMode(const WebSize
& new_size
) {
376 DisableAutoResizeMode(render_view(), new_size
);
377 if (!new_size
.isEmpty())
378 ForceResizeRenderView(render_view(), new_size
);
381 void WebKitTestRunner::clearDevToolsLocalStorage() {
382 Send(new ShellViewHostMsg_ClearDevToolsLocalStorage(routing_id()));
385 void WebKitTestRunner::showDevTools(const std::string
& settings
,
386 const std::string
& frontend_url
) {
387 Send(new ShellViewHostMsg_ShowDevTools(
388 routing_id(), settings
, frontend_url
));
391 void WebKitTestRunner::closeDevTools() {
392 Send(new ShellViewHostMsg_CloseDevTools(routing_id()));
393 WebDevToolsAgent
* agent
= render_view()->GetWebView()->devToolsAgent();
398 void WebKitTestRunner::evaluateInWebInspector(long call_id
,
399 const std::string
& script
) {
400 WebDevToolsAgent
* agent
= render_view()->GetWebView()->devToolsAgent();
402 agent
->evaluateInWebInspector(call_id
, WebString::fromUTF8(script
));
405 void WebKitTestRunner::clearAllDatabases() {
406 Send(new ShellViewHostMsg_ClearAllDatabases(routing_id()));
409 void WebKitTestRunner::setDatabaseQuota(int quota
) {
410 Send(new ShellViewHostMsg_SetDatabaseQuota(routing_id(), quota
));
413 blink::WebNotificationPresenter::Permission
414 WebKitTestRunner::checkWebNotificationPermission(const GURL
& origin
) {
415 int permission
= blink::WebNotificationPresenter::PermissionNotAllowed
;
416 Send(new ShellViewHostMsg_CheckWebNotificationPermission(
420 return static_cast<blink::WebNotificationPresenter::Permission
>(permission
);
423 void WebKitTestRunner::grantWebNotificationPermission(const GURL
& origin
,
424 bool permission_granted
) {
425 Send(new ShellViewHostMsg_GrantWebNotificationPermission(
426 routing_id(), origin
, permission_granted
));
429 void WebKitTestRunner::clearWebNotificationPermissions() {
430 Send(new ShellViewHostMsg_ClearWebNotificationPermissions(routing_id()));
433 void WebKitTestRunner::setDeviceScaleFactor(float factor
) {
434 SetDeviceScaleFactor(render_view(), factor
);
437 void WebKitTestRunner::setDeviceColorProfile(const std::string
& name
) {
438 SetDeviceColorProfile(render_view(), name
);
441 void WebKitTestRunner::setFocus(WebTestProxyBase
* proxy
, bool focus
) {
442 ProxyToRenderViewVisitor
visitor(proxy
);
443 RenderView::ForEach(&visitor
);
444 if (!visitor
.render_view()) {
449 // Check whether the focused view was closed meanwhile.
450 if (!WebKitTestRunner::Get(focused_view_
))
451 focused_view_
= NULL
;
454 if (focused_view_
!= visitor
.render_view()) {
456 SetFocusAndActivate(focused_view_
, false);
457 SetFocusAndActivate(visitor
.render_view(), true);
458 focused_view_
= visitor
.render_view();
461 if (focused_view_
== visitor
.render_view()) {
462 SetFocusAndActivate(visitor
.render_view(), false);
463 focused_view_
= NULL
;
468 void WebKitTestRunner::setAcceptAllCookies(bool accept
) {
469 Send(new ShellViewHostMsg_AcceptAllCookies(routing_id(), accept
));
472 std::string
WebKitTestRunner::pathToLocalResource(const std::string
& resource
) {
474 if (resource
.find("/tmp/") == 0) {
475 // We want a temp file.
476 GURL base_url
= net::FilePathToFileURL(test_config_
.temp_path
);
477 return base_url
.Resolve(resource
.substr(strlen("/tmp/"))).spec();
481 // Some layout tests use file://// which we resolve as a UNC path. Normalize
482 // them to just file:///.
483 std::string result
= resource
;
484 while (base::StringToLowerASCII(result
).find("file:////") == 0) {
485 result
= result
.substr(0, strlen("file:///")) +
486 result
.substr(strlen("file:////"));
488 return rewriteLayoutTestsURL(result
).spec();
491 void WebKitTestRunner::setLocale(const std::string
& locale
) {
492 setlocale(LC_ALL
, locale
.c_str());
495 void WebKitTestRunner::testFinished() {
496 if (!is_main_window_
) {
497 Send(new ShellViewHostMsg_TestFinishedInSecondaryWindow(routing_id()));
500 WebTestInterfaces
* interfaces
=
501 ShellRenderProcessObserver::GetInstance()->test_interfaces();
502 interfaces
->setTestIsRunning(false);
503 if (interfaces
->testRunner()->ShouldDumpBackForwardList()) {
504 SyncNavigationStateVisitor visitor
;
505 RenderView::ForEach(&visitor
);
506 Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id()));
512 void WebKitTestRunner::closeRemainingWindows() {
513 NavigateAwayVisitor
visitor(render_view());
514 RenderView::ForEach(&visitor
);
515 Send(new ShellViewHostMsg_CloseRemainingWindows(routing_id()));
518 void WebKitTestRunner::deleteAllCookies() {
519 Send(new ShellViewHostMsg_DeleteAllCookies(routing_id()));
522 int WebKitTestRunner::navigationEntryCount() {
523 return GetLocalSessionHistoryLength(render_view());
526 void WebKitTestRunner::goToOffset(int offset
) {
527 Send(new ShellViewHostMsg_GoToOffset(routing_id(), offset
));
530 void WebKitTestRunner::reload() {
531 Send(new ShellViewHostMsg_Reload(routing_id()));
534 void WebKitTestRunner::loadURLForFrame(const WebURL
& url
,
535 const std::string
& frame_name
) {
536 Send(new ShellViewHostMsg_LoadURLForFrame(
537 routing_id(), url
, frame_name
));
540 bool WebKitTestRunner::allowExternalPages() {
541 return test_config_
.allow_external_pages
;
544 std::string
WebKitTestRunner::dumpHistoryForWindow(WebTestProxyBase
* proxy
) {
546 std::vector
<int>::iterator id
;
547 for (id
= routing_ids_
.begin(); id
!= routing_ids_
.end(); ++id
, ++pos
) {
548 RenderView
* render_view
= RenderView::FromRoutingID(*id
);
553 if (WebKitTestRunner::Get(render_view
)->proxy() == proxy
)
557 if (id
== routing_ids_
.end()) {
559 return std::string();
561 return DumpBackForwardList(session_histories_
[pos
],
562 current_entry_indexes_
[pos
]);
565 // RenderViewObserver --------------------------------------------------------
567 void WebKitTestRunner::DidClearWindowObject(WebLocalFrame
* frame
) {
568 WebTestingSupport::injectInternalsObject(frame
);
569 ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame
);
570 GCController::Install(frame
);
573 bool WebKitTestRunner::OnMessageReceived(const IPC::Message
& message
) {
575 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner
, message
)
576 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration
,
577 OnSetTestConfiguration
)
578 IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory
, OnSessionHistory
)
579 IPC_MESSAGE_HANDLER(ShellViewMsg_Reset
, OnReset
)
580 IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone
, OnNotifyDone
)
581 IPC_MESSAGE_HANDLER(ShellViewMsg_TryLeakDetection
, OnTryLeakDetection
)
582 IPC_MESSAGE_UNHANDLED(handled
= false)
583 IPC_END_MESSAGE_MAP()
588 void WebKitTestRunner::Navigate(const GURL
& url
) {
589 focus_on_next_commit_
= true;
590 if (!is_main_window_
&&
591 ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) {
592 WebTestInterfaces
* interfaces
=
593 ShellRenderProcessObserver::GetInstance()->test_interfaces();
594 interfaces
->setTestIsRunning(true);
595 interfaces
->configureForTestWithURL(GURL(), false);
596 ForceResizeRenderView(render_view(), WebSize(800, 600));
600 void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame
* frame
,
601 bool is_new_navigation
) {
602 if (!focus_on_next_commit_
)
604 focus_on_next_commit_
= false;
605 render_view()->GetWebView()->setFocusedFrame(frame
);
608 void WebKitTestRunner::DidFailProvisionalLoad(WebLocalFrame
* frame
,
609 const WebURLError
& error
) {
610 focus_on_next_commit_
= false;
613 // Public methods - -----------------------------------------------------------
615 void WebKitTestRunner::Reset() {
616 // The proxy_ is always non-NULL, it is set right after construction.
617 proxy_
->set_widget(render_view()->GetWebView());
620 routing_ids_
.clear();
621 session_histories_
.clear();
622 current_entry_indexes_
.clear();
624 render_view()->ClearEditCommands();
625 render_view()->GetWebView()->mainFrame()->setName(WebString());
626 render_view()->GetWebView()->mainFrame()->clearOpener();
627 render_view()->GetWebView()->setPageScaleFactorLimits(-1, -1);
628 render_view()->GetWebView()->setPageScaleFactor(1, WebPoint(0, 0));
630 // Resetting the internals object also overrides the WebPreferences, so we
631 // have to sync them to WebKit again.
632 WebTestingSupport::resetInternalsObject(
633 render_view()->GetWebView()->mainFrame()->toWebLocalFrame());
634 render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences());
637 // Private methods -----------------------------------------------------------
639 void WebKitTestRunner::CaptureDump() {
640 WebTestInterfaces
* interfaces
=
641 ShellRenderProcessObserver::GetInstance()->test_interfaces();
642 TRACE_EVENT0("shell", "WebKitTestRunner::CaptureDump");
644 if (interfaces
->testRunner()->ShouldDumpAsAudio()) {
645 std::vector
<unsigned char> vector_data
;
646 interfaces
->testRunner()->GetAudioData(&vector_data
);
647 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data
));
649 Send(new ShellViewHostMsg_TextDump(routing_id(),
650 proxy()->CaptureTree(false)));
652 if (test_config_
.enable_pixel_dumping
&&
653 interfaces
->testRunner()->ShouldGeneratePixelResults()) {
654 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive());
655 proxy()->CapturePixelsAsync(base::Bind(
656 &WebKitTestRunner::CaptureDumpPixels
, base::Unretained(this)));
661 CaptureDumpComplete();
664 void WebKitTestRunner::CaptureDumpPixels(const SkBitmap
& snapshot
) {
665 DCHECK_NE(0, snapshot
.info().fWidth
);
666 DCHECK_NE(0, snapshot
.info().fHeight
);
668 SkAutoLockPixels
snapshot_lock(snapshot
);
669 base::MD5Digest digest
;
670 base::MD5Sum(snapshot
.getPixels(), snapshot
.getSize(), &digest
);
671 std::string actual_pixel_hash
= base::MD5DigestToBase16(digest
);
673 if (actual_pixel_hash
== test_config_
.expected_pixel_hash
) {
674 SkBitmap empty_image
;
675 Send(new ShellViewHostMsg_ImageDump(
676 routing_id(), actual_pixel_hash
, empty_image
));
678 Send(new ShellViewHostMsg_ImageDump(
679 routing_id(), actual_pixel_hash
, snapshot
));
682 CaptureDumpComplete();
685 void WebKitTestRunner::CaptureDumpComplete() {
686 render_view()->GetWebView()->mainFrame()->stopLoading();
688 base::MessageLoop::current()->PostTask(
690 base::Bind(base::IgnoreResult(&WebKitTestRunner::Send
),
691 base::Unretained(this),
692 new ShellViewHostMsg_TestFinished(routing_id())));
695 void WebKitTestRunner::OnSetTestConfiguration(
696 const ShellTestConfiguration
& params
) {
697 test_config_
= params
;
698 is_main_window_
= true;
700 ForceResizeRenderView(
702 WebSize(params
.initial_size
.width(), params
.initial_size
.height()));
703 setFocus(proxy_
, true);
705 WebTestInterfaces
* interfaces
=
706 ShellRenderProcessObserver::GetInstance()->test_interfaces();
707 interfaces
->setTestIsRunning(true);
708 interfaces
->configureForTestWithURL(params
.test_url
,
709 params
.enable_pixel_dumping
);
712 void WebKitTestRunner::OnSessionHistory(
713 const std::vector
<int>& routing_ids
,
714 const std::vector
<std::vector
<PageState
> >& session_histories
,
715 const std::vector
<unsigned>& current_entry_indexes
) {
716 routing_ids_
= routing_ids
;
717 session_histories_
= session_histories
;
718 current_entry_indexes_
= current_entry_indexes
;
722 void WebKitTestRunner::OnReset() {
723 ShellRenderProcessObserver::GetInstance()->test_interfaces()->resetAll();
725 // Navigating to about:blank will make sure that no new loads are initiated
727 render_view()->GetWebView()->mainFrame()->loadRequest(
728 WebURLRequest(GURL(url::kAboutBlankURL
)));
729 Send(new ShellViewHostMsg_ResetDone(routing_id()));
732 void WebKitTestRunner::OnNotifyDone() {
733 render_view()->GetWebView()->mainFrame()->executeScript(
734 WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();")));
737 void WebKitTestRunner::OnTryLeakDetection() {
738 WebLocalFrame
* main_frame
=
739 render_view()->GetWebView()->mainFrame()->toWebLocalFrame();
740 DCHECK_EQ(GURL(url::kAboutBlankURL
), GURL(main_frame
->document().url()));
741 DCHECK(!main_frame
->isLoading());
743 leak_detector_
->TryLeakDetection(main_frame
);
746 void WebKitTestRunner::ReportLeakDetectionResult(
747 const LeakDetectionResult
& report
) {
748 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report
));
751 } // namespace content