| 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/renderer/webkit_test_runner.h" | 5 #include "content/shell/renderer/webkit_test_runner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <clocale> | 8 #include <clocale> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "third_party/WebKit/public/platform/WebURL.h" | 48 #include "third_party/WebKit/public/platform/WebURL.h" |
| 49 #include "third_party/WebKit/public/platform/WebURLError.h" | 49 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 50 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 50 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 51 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 51 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 52 #include "third_party/WebKit/public/web/WebArrayBufferView.h" | 52 #include "third_party/WebKit/public/web/WebArrayBufferView.h" |
| 53 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 53 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 54 #include "third_party/WebKit/public/web/WebDataSource.h" | 54 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 55 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" | 55 #include "third_party/WebKit/public/web/WebDevToolsAgent.h" |
| 56 #include "third_party/WebKit/public/web/WebDocument.h" | 56 #include "third_party/WebKit/public/web/WebDocument.h" |
| 57 #include "third_party/WebKit/public/web/WebElement.h" | 57 #include "third_party/WebKit/public/web/WebElement.h" |
| 58 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 59 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 58 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 60 #include "third_party/WebKit/public/web/WebKit.h" | 59 #include "third_party/WebKit/public/web/WebKit.h" |
| 61 #include "third_party/WebKit/public/web/WebLeakDetector.h" | 60 #include "third_party/WebKit/public/web/WebLeakDetector.h" |
| 61 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 62 #include "third_party/WebKit/public/web/WebScriptSource.h" | 62 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 63 #include "third_party/WebKit/public/web/WebTestingSupport.h" | 63 #include "third_party/WebKit/public/web/WebTestingSupport.h" |
| 64 #include "third_party/WebKit/public/web/WebView.h" | 64 #include "third_party/WebKit/public/web/WebView.h" |
| 65 #include "ui/gfx/rect.h" | 65 #include "ui/gfx/rect.h" |
| 66 #include "webkit/common/webpreferences.h" | 66 #include "webkit/common/webpreferences.h" |
| 67 | 67 |
| 68 using blink::Platform; | 68 using blink::Platform; |
| 69 using blink::WebArrayBufferView; | 69 using blink::WebArrayBufferView; |
| 70 using blink::WebContextMenuData; | 70 using blink::WebContextMenuData; |
| 71 using blink::WebDevToolsAgent; | 71 using blink::WebDevToolsAgent; |
| 72 using blink::WebDeviceMotionData; | 72 using blink::WebDeviceMotionData; |
| 73 using blink::WebDeviceOrientationData; | 73 using blink::WebDeviceOrientationData; |
| 74 using blink::WebElement; | 74 using blink::WebElement; |
| 75 using blink::WebFrame; | 75 using blink::WebLocalFrame; |
| 76 using blink::WebGamepads; | 76 using blink::WebGamepads; |
| 77 using blink::WebHistoryItem; | 77 using blink::WebHistoryItem; |
| 78 using blink::WebLocalFrame; |
| 78 using blink::WebPoint; | 79 using blink::WebPoint; |
| 79 using blink::WebRect; | 80 using blink::WebRect; |
| 80 using blink::WebScriptSource; | 81 using blink::WebScriptSource; |
| 81 using blink::WebSize; | 82 using blink::WebSize; |
| 82 using blink::WebString; | 83 using blink::WebString; |
| 83 using blink::WebURL; | 84 using blink::WebURL; |
| 84 using blink::WebURLError; | 85 using blink::WebURLError; |
| 85 using blink::WebURLRequest; | 86 using blink::WebURLRequest; |
| 86 using blink::WebScreenOrientation; | 87 using blink::WebScreenOrientation; |
| 87 using blink::WebTestingSupport; | 88 using blink::WebTestingSupport; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 WebVector<WebHistoryItem> result(num_entries); | 564 WebVector<WebHistoryItem> result(num_entries); |
| 564 for (size_t entry = 0; entry < num_entries; ++entry) { | 565 for (size_t entry = 0; entry < num_entries; ++entry) { |
| 565 result[entry] = | 566 result[entry] = |
| 566 PageStateToHistoryItem(session_histories_[pos][entry]); | 567 PageStateToHistoryItem(session_histories_[pos][entry]); |
| 567 } | 568 } |
| 568 history->swap(result); | 569 history->swap(result); |
| 569 } | 570 } |
| 570 | 571 |
| 571 // RenderViewObserver -------------------------------------------------------- | 572 // RenderViewObserver -------------------------------------------------------- |
| 572 | 573 |
| 573 void WebKitTestRunner::DidClearWindowObject(WebFrame* frame, int world_id) { | 574 void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame, |
| 575 int world_id) { |
| 574 WebTestingSupport::injectInternalsObject(frame); | 576 WebTestingSupport::injectInternalsObject(frame); |
| 575 if (world_id == 0) { | 577 if (world_id == 0) { |
| 576 ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame); | 578 ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame); |
| 577 GCController::Install(frame); | 579 GCController::Install(frame); |
| 578 } | 580 } |
| 579 } | 581 } |
| 580 | 582 |
| 581 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { | 583 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { |
| 582 bool handled = true; | 584 bool handled = true; |
| 583 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) | 585 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 598 if (!is_main_window_ && | 600 if (!is_main_window_ && |
| 599 ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) { | 601 ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) { |
| 600 WebTestInterfaces* interfaces = | 602 WebTestInterfaces* interfaces = |
| 601 ShellRenderProcessObserver::GetInstance()->test_interfaces(); | 603 ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 602 interfaces->setTestIsRunning(true); | 604 interfaces->setTestIsRunning(true); |
| 603 interfaces->configureForTestWithURL(GURL(), false); | 605 interfaces->configureForTestWithURL(GURL(), false); |
| 604 ForceResizeRenderView(render_view(), WebSize(800, 600)); | 606 ForceResizeRenderView(render_view(), WebSize(800, 600)); |
| 605 } | 607 } |
| 606 } | 608 } |
| 607 | 609 |
| 608 void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame, | 610 void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame, |
| 609 bool is_new_navigation) { | 611 bool is_new_navigation) { |
| 610 if (!focus_on_next_commit_) | 612 if (!focus_on_next_commit_) |
| 611 return; | 613 return; |
| 612 focus_on_next_commit_ = false; | 614 focus_on_next_commit_ = false; |
| 613 render_view()->GetWebView()->setFocusedFrame(frame); | 615 render_view()->GetWebView()->setFocusedFrame(frame); |
| 614 } | 616 } |
| 615 | 617 |
| 616 void WebKitTestRunner::DidFailProvisionalLoad(WebFrame* frame, | 618 void WebKitTestRunner::DidFailProvisionalLoad(WebLocalFrame* frame, |
| 617 const WebURLError& error) { | 619 const WebURLError& error) { |
| 618 focus_on_next_commit_ = false; | 620 focus_on_next_commit_ = false; |
| 619 } | 621 } |
| 620 | 622 |
| 621 // Public methods - ----------------------------------------------------------- | 623 // Public methods - ----------------------------------------------------------- |
| 622 | 624 |
| 623 void WebKitTestRunner::Reset() { | 625 void WebKitTestRunner::Reset() { |
| 624 // The proxy_ is always non-NULL, it is set right after construction. | 626 // The proxy_ is always non-NULL, it is set right after construction. |
| 625 proxy_->setWidget(render_view()->GetWebView()); | 627 proxy_->setWidget(render_view()->GetWebView()); |
| 626 proxy_->reset(); | 628 proxy_->reset(); |
| 627 prefs_.reset(); | 629 prefs_.reset(); |
| 628 routing_ids_.clear(); | 630 routing_ids_.clear(); |
| 629 session_histories_.clear(); | 631 session_histories_.clear(); |
| 630 current_entry_indexes_.clear(); | 632 current_entry_indexes_.clear(); |
| 631 | 633 |
| 632 render_view()->ClearEditCommands(); | 634 render_view()->ClearEditCommands(); |
| 633 render_view()->GetWebView()->mainFrame()->setName(WebString()); | 635 render_view()->GetWebView()->mainFrame()->setName(WebString()); |
| 634 render_view()->GetWebView()->mainFrame()->clearOpener(); | 636 render_view()->GetWebView()->mainFrame()->clearOpener(); |
| 635 render_view()->GetWebView()->setPageScaleFactorLimits(-1, -1); | 637 render_view()->GetWebView()->setPageScaleFactorLimits(-1, -1); |
| 636 render_view()->GetWebView()->setPageScaleFactor(1, WebPoint(0, 0)); | 638 render_view()->GetWebView()->setPageScaleFactor(1, WebPoint(0, 0)); |
| 637 | 639 |
| 638 // Resetting the internals object also overrides the WebPreferences, so we | 640 // Resetting the internals object also overrides the WebPreferences, so we |
| 639 // have to sync them to WebKit again. | 641 // have to sync them to WebKit again. |
| 640 WebTestingSupport::resetInternalsObject( | 642 WebTestingSupport::resetInternalsObject( |
| 641 render_view()->GetWebView()->mainFrame()); | 643 render_view()->GetWebView()->mainFrame()->toWebLocalFrame()); |
| 642 render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences()); | 644 render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences()); |
| 643 } | 645 } |
| 644 | 646 |
| 645 // Private methods ----------------------------------------------------------- | 647 // Private methods ----------------------------------------------------------- |
| 646 | 648 |
| 647 void WebKitTestRunner::CaptureDump() { | 649 void WebKitTestRunner::CaptureDump() { |
| 648 WebTestInterfaces* interfaces = | 650 WebTestInterfaces* interfaces = |
| 649 ShellRenderProcessObserver::GetInstance()->test_interfaces(); | 651 ShellRenderProcessObserver::GetInstance()->test_interfaces(); |
| 650 | 652 |
| 651 if (interfaces->testRunner()->shouldDumpAsAudio()) { | 653 if (interfaces->testRunner()->shouldDumpAsAudio()) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();"))); | 730 WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();"))); |
| 729 } | 731 } |
| 730 | 732 |
| 731 void WebKitTestRunner::OnTryLeakDetection() { | 733 void WebKitTestRunner::OnTryLeakDetection() { |
| 732 base::MessageLoop::current()->PostTask( | 734 base::MessageLoop::current()->PostTask( |
| 733 FROM_HERE, | 735 FROM_HERE, |
| 734 base::Bind(&WebKitTestRunner::TryLeakDetection, base::Unretained(this))); | 736 base::Bind(&WebKitTestRunner::TryLeakDetection, base::Unretained(this))); |
| 735 } | 737 } |
| 736 | 738 |
| 737 void WebKitTestRunner::TryLeakDetection() { | 739 void WebKitTestRunner::TryLeakDetection() { |
| 738 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 740 WebLocalFrame* main_frame = |
| 741 render_view()->GetWebView()->mainFrame()->toWebLocalFrame(); |
| 739 DCHECK_EQ(GURL(kAboutBlankURL), GURL(main_frame->document().url())); | 742 DCHECK_EQ(GURL(kAboutBlankURL), GURL(main_frame->document().url())); |
| 740 DCHECK(!main_frame->isLoading()); | 743 DCHECK(!main_frame->isLoading()); |
| 741 | 744 |
| 742 LeakDetectionResult result = leak_detector_->TryLeakDetection( | 745 LeakDetectionResult result = leak_detector_->TryLeakDetection(main_frame); |
| 743 render_view()->GetWebView()->mainFrame()); | |
| 744 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), result)); | 746 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), result)); |
| 745 } | 747 } |
| 746 | 748 |
| 747 } // namespace content | 749 } // namespace content |
| OLD | NEW |