OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/webkit_test_runner.h" | 5 #include "content/shell/webkit_test_runner.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
18 #include "content/public/test/layouttest_support.h" | 18 #include "content/public/test/layouttest_support.h" |
19 #include "content/shell/shell_messages.h" | 19 #include "content/shell/shell_messages.h" |
20 #include "content/shell/shell_render_process_observer.h" | 20 #include "content/shell/shell_render_process_observer.h" |
21 #include "content/shell/webkit_test_helpers.h" | 21 #include "content/shell/webkit_test_helpers.h" |
| 22 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
23 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
29 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
37 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
Task.h" | 39 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
Task.h" |
38 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestProxy.h" | 40 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web
TestProxy.h" |
39 #include "webkit/base/file_path_string_conversions.h" | 41 #include "webkit/base/file_path_string_conversions.h" |
40 #include "webkit/glue/webkit_glue.h" | 42 #include "webkit/glue/webkit_glue.h" |
41 #include "webkit/glue/webpreferences.h" | 43 #include "webkit/glue/webpreferences.h" |
42 | 44 |
43 using WebKit::Platform; | 45 using WebKit::Platform; |
44 using WebKit::WebContextMenuData; | 46 using WebKit::WebContextMenuData; |
45 using WebKit::WebDevToolsAgent; | 47 using WebKit::WebDevToolsAgent; |
46 using WebKit::WebElement; | 48 using WebKit::WebElement; |
47 using WebKit::WebFrame; | 49 using WebKit::WebFrame; |
48 using WebKit::WebGamepads; | 50 using WebKit::WebGamepads; |
| 51 using WebKit::WebIntentRequest; |
49 using WebKit::WebRect; | 52 using WebKit::WebRect; |
50 using WebKit::WebSize; | 53 using WebKit::WebSize; |
51 using WebKit::WebString; | 54 using WebKit::WebString; |
52 using WebKit::WebURL; | 55 using WebKit::WebURL; |
| 56 using WebKit::WebURLError; |
53 using WebKit::WebVector; | 57 using WebKit::WebVector; |
54 using WebKit::WebView; | 58 using WebKit::WebView; |
55 using WebTestRunner::WebPreferences; | 59 using WebTestRunner::WebPreferences; |
56 using WebTestRunner::WebTask; | 60 using WebTestRunner::WebTask; |
57 | 61 |
58 namespace content { | 62 namespace content { |
59 | 63 |
60 namespace { | 64 namespace { |
61 | 65 |
62 void InvokeTaskHelper(void* context) { | 66 void InvokeTaskHelper(void* context) { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return &prefs_; | 288 return &prefs_; |
285 } | 289 } |
286 | 290 |
287 void WebKitTestRunner::applyPreferences() { | 291 void WebKitTestRunner::applyPreferences() { |
288 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); | 292 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
289 ExportLayoutTestSpecificPreferences(prefs_, &prefs); | 293 ExportLayoutTestSpecificPreferences(prefs_, &prefs); |
290 render_view()->SetWebkitPreferences(prefs); | 294 render_view()->SetWebkitPreferences(prefs); |
291 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs)); | 295 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs)); |
292 } | 296 } |
293 | 297 |
| 298 void WebKitTestRunner::setCurrentWebIntentRequest( |
| 299 const WebIntentRequest& request) { |
| 300 intent_request_ = request; |
| 301 } |
| 302 |
| 303 WebIntentRequest* WebKitTestRunner::currentWebIntentRequest() { |
| 304 return &intent_request_; |
| 305 } |
| 306 |
| 307 std::string WebKitTestRunner::makeURLErrorDescription( |
| 308 const WebURLError& error) { |
| 309 std::string domain = error.domain.utf8(); |
| 310 int code = error.reason; |
| 311 |
| 312 if (domain == net::kErrorDomain) { |
| 313 domain = "NSURLErrorDomain"; |
| 314 switch (error.reason) { |
| 315 case net::ERR_ABORTED: |
| 316 code = -999; // NSURLErrorCancelled |
| 317 break; |
| 318 case net::ERR_UNSAFE_PORT: |
| 319 // Our unsafe port checking happens at the network stack level, but we |
| 320 // make this translation here to match the behavior of stock WebKit. |
| 321 domain = "WebKitErrorDomain"; |
| 322 code = 103; |
| 323 break; |
| 324 case net::ERR_ADDRESS_INVALID: |
| 325 case net::ERR_ADDRESS_UNREACHABLE: |
| 326 case net::ERR_NETWORK_ACCESS_DENIED: |
| 327 code = -1004; // NSURLErrorCannotConnectToHost |
| 328 break; |
| 329 } |
| 330 } else { |
| 331 DLOG(WARNING) << "Unknown error domain"; |
| 332 } |
| 333 |
| 334 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">", |
| 335 domain.c_str(), code, error.unreachableURL.spec().data()); |
| 336 } |
| 337 |
294 // WebTestRunner ------------------------------------------------------------- | 338 // WebTestRunner ------------------------------------------------------------- |
295 | 339 |
296 bool WebKitTestRunner::shouldDumpEditingCallbacks() const { | 340 bool WebKitTestRunner::shouldDumpEditingCallbacks() const { |
297 return dump_editing_callbacks_; | 341 return dump_editing_callbacks_; |
298 } | 342 } |
299 | 343 |
300 bool WebKitTestRunner::shouldDumpFrameLoadCallbacks() const { | 344 bool WebKitTestRunner::shouldDumpFrameLoadCallbacks() const { |
301 return test_is_running_ && dump_frame_load_callbacks_; | 345 return test_is_running_ && dump_frame_load_callbacks_; |
302 } | 346 } |
303 | 347 |
304 bool WebKitTestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const { | 348 bool WebKitTestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const { |
305 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_; | 349 return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_; |
306 } | 350 } |
307 | 351 |
308 bool WebKitTestRunner::stopProvisionalFrameLoads() const { | 352 bool WebKitTestRunner::stopProvisionalFrameLoads() const { |
309 return stop_provisional_frame_loads_; | 353 return stop_provisional_frame_loads_; |
310 } | 354 } |
311 | 355 |
312 bool WebKitTestRunner::shouldDumpTitleChanges() const { | 356 bool WebKitTestRunner::shouldDumpTitleChanges() const { |
313 return dump_title_changes_; | 357 return dump_title_changes_; |
314 } | 358 } |
315 | 359 |
| 360 bool WebKitTestRunner::shouldDumpResourceLoadCallbacks() const { |
| 361 return test_is_running_ && dump_resource_load_callbacks_; |
| 362 } |
| 363 |
| 364 bool WebKitTestRunner::shouldDumpResourceRequestCallbacks() const { |
| 365 return test_is_running_ && dump_resource_request_callbacks_; |
| 366 } |
| 367 |
| 368 bool WebKitTestRunner::shouldDumpResourceResponseMIMETypes() const { |
| 369 return test_is_running_ && dump_resource_response_mime_types_; |
| 370 } |
| 371 |
| 372 bool WebKitTestRunner::shouldDumpCreateView() const { |
| 373 return dump_create_view_; |
| 374 } |
| 375 |
| 376 bool WebKitTestRunner::canOpenWindows() const { |
| 377 return can_open_windows_; |
| 378 } |
| 379 |
316 // RenderViewObserver -------------------------------------------------------- | 380 // RenderViewObserver -------------------------------------------------------- |
317 | 381 |
318 void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) { | 382 void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) { |
319 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame); | 383 ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame); |
320 } | 384 } |
321 | 385 |
322 void WebKitTestRunner::DidFinishLoad(WebFrame* frame) { | 386 void WebKitTestRunner::DidFinishLoad(WebFrame* frame) { |
323 if (!frame->parent()) { | 387 if (!frame->parent()) { |
324 if (!wait_until_done_) | 388 if (!wait_until_done_) |
325 test_is_running_ = false; | 389 test_is_running_ = false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 Send(new ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload( | 451 Send(new ShellViewHostMsg_SetShouldStayOnPageAfterHandlingBeforeUnload( |
388 routing_id(), should_stay_on_page)); | 452 routing_id(), should_stay_on_page)); |
389 } | 453 } |
390 | 454 |
391 void WebKitTestRunner::WaitUntilDone() { | 455 void WebKitTestRunner::WaitUntilDone() { |
392 wait_until_done_ = true; | 456 wait_until_done_ = true; |
393 Send(new ShellViewHostMsg_WaitUntilDone(routing_id())); | 457 Send(new ShellViewHostMsg_WaitUntilDone(routing_id())); |
394 } | 458 } |
395 | 459 |
396 void WebKitTestRunner::CanOpenWindows() { | 460 void WebKitTestRunner::CanOpenWindows() { |
| 461 can_open_windows_ = true; |
397 Send(new ShellViewHostMsg_CanOpenWindows(routing_id())); | 462 Send(new ShellViewHostMsg_CanOpenWindows(routing_id())); |
398 } | 463 } |
399 | 464 |
400 void WebKitTestRunner::ShowWebInspector() { | 465 void WebKitTestRunner::ShowWebInspector() { |
401 Send(new ShellViewHostMsg_ShowWebInspector(routing_id())); | 466 Send(new ShellViewHostMsg_ShowWebInspector(routing_id())); |
402 } | 467 } |
403 | 468 |
404 void WebKitTestRunner::CloseWebInspector() { | 469 void WebKitTestRunner::CloseWebInspector() { |
405 Send(new ShellViewHostMsg_CloseWebInspector(routing_id())); | 470 Send(new ShellViewHostMsg_CloseWebInspector(routing_id())); |
406 } | 471 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 550 } |
486 | 551 |
487 void WebKitTestRunner::StopProvisionalFrameLoads() { | 552 void WebKitTestRunner::StopProvisionalFrameLoads() { |
488 stop_provisional_frame_loads_ = true; | 553 stop_provisional_frame_loads_ = true; |
489 } | 554 } |
490 | 555 |
491 void WebKitTestRunner::DumpTitleChanges() { | 556 void WebKitTestRunner::DumpTitleChanges() { |
492 dump_title_changes_ = true; | 557 dump_title_changes_ = true; |
493 } | 558 } |
494 | 559 |
| 560 void WebKitTestRunner::DumpResourceLoadCallbacks() { |
| 561 dump_resource_load_callbacks_ = true; |
| 562 } |
| 563 |
| 564 void WebKitTestRunner::DumpResourceRequestCallbacks() { |
| 565 dump_resource_request_callbacks_ = true; |
| 566 } |
| 567 |
| 568 void WebKitTestRunner::DumpResourceResponseMIMETypes() { |
| 569 dump_resource_response_mime_types_ = true; |
| 570 } |
| 571 |
| 572 void WebKitTestRunner::DumpCreateView() { |
| 573 dump_create_view_ = true; |
| 574 } |
| 575 |
495 void WebKitTestRunner::NotImplemented(const std::string& object, | 576 void WebKitTestRunner::NotImplemented(const std::string& object, |
496 const std::string& method) { | 577 const std::string& method) { |
497 Send(new ShellViewHostMsg_NotImplemented(routing_id(), object, method)); | 578 Send(new ShellViewHostMsg_NotImplemented(routing_id(), object, method)); |
498 } | 579 } |
499 | 580 |
500 void WebKitTestRunner::Reset() { | 581 void WebKitTestRunner::Reset() { |
501 prefs_.reset(); | 582 prefs_.reset(); |
502 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); | 583 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
503 ExportLayoutTestSpecificPreferences(prefs_, &prefs); | 584 ExportLayoutTestSpecificPreferences(prefs_, &prefs); |
504 render_view()->SetWebkitPreferences(prefs); | 585 render_view()->SetWebkitPreferences(prefs); |
505 dump_editing_callbacks_ = false; | 586 dump_editing_callbacks_ = false; |
506 dump_frame_load_callbacks_ = false; | 587 dump_frame_load_callbacks_ = false; |
507 dump_user_gesture_in_frame_load_callbacks_ = false; | 588 dump_user_gesture_in_frame_load_callbacks_ = false; |
508 stop_provisional_frame_loads_ = false; | 589 stop_provisional_frame_loads_ = false; |
509 dump_title_changes_ = false; | 590 dump_title_changes_ = false; |
| 591 dump_resource_load_callbacks_ = false; |
| 592 dump_resource_request_callbacks_ = false; |
| 593 dump_resource_response_mime_types_ = false; |
| 594 dump_create_view_ = false; |
| 595 can_open_windows_ = false; |
510 test_is_running_ = true; | 596 test_is_running_ = true; |
511 load_finished_ = false; | 597 load_finished_ = false; |
512 wait_until_done_ = false; | 598 wait_until_done_ = false; |
513 } | 599 } |
514 | 600 |
515 // Private methods ----------------------------------------------------------- | 601 // Private methods ----------------------------------------------------------- |
516 | 602 |
517 void WebKitTestRunner::OnCaptureTextDump(bool as_text, | 603 void WebKitTestRunner::OnCaptureTextDump(bool as_text, |
518 bool printing, | 604 bool printing, |
519 bool recursive) { | 605 bool recursive) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 PaintRect(rect); | 724 PaintRect(rect); |
639 } | 725 } |
640 CHECK(proxy_->paintRect().isEmpty()); | 726 CHECK(proxy_->paintRect().isEmpty()); |
641 } | 727 } |
642 | 728 |
643 void WebKitTestRunner::DisplayRepaintMask() { | 729 void WebKitTestRunner::DisplayRepaintMask() { |
644 GetCanvas()->drawARGB(167, 0, 0, 0); | 730 GetCanvas()->drawARGB(167, 0, 0, 0); |
645 } | 731 } |
646 | 732 |
647 } // namespace content | 733 } // namespace content |
OLD | NEW |