diff options
-rw-r--r-- | webkit/glue/webview.h | 3 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 25 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.h | 7 | ||||
-rwxr-xr-x | webkit/tools/test_shell/test_shell.cc | 9 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 13 | ||||
-rwxr-xr-x | webkit/tools/test_shell/test_webview_delegate.cc | 36 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 17 |
9 files changed, 88 insertions, 27 deletions
diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 4a569d6..fb557e9 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -52,6 +52,9 @@ class WebView : public WebWidget { // it, it will be NULL during closing of the view. virtual WebViewDelegate* GetDelegate() = 0; + // Changes the delegate for this WebView. It is valid to set this to NULL. + virtual void SetDelegate(WebViewDelegate* delegate) = 0; + // Instructs the EditorClient whether to pass editing notifications on to a // delegate, if one is present. This allows embedders that haven't // overridden any editor delegate methods to avoid the performance impact of diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index b2792b8..15da11f 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -894,6 +894,10 @@ WebViewDelegate* WebViewImpl::GetDelegate() { return delegate_; } +void WebViewImpl::SetDelegate(WebViewDelegate* delegate) { + delegate_ = delegate; +} + WebFrame* WebViewImpl::GetMainFrame() { return main_frame(); } diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 539e125..d080909 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -56,6 +56,7 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { virtual bool ShouldClose(); virtual void Close(); virtual WebViewDelegate* GetDelegate(); + virtual void SetDelegate(WebViewDelegate*); virtual void SetUseEditorDelegate(bool value); virtual void SetTabKeyCyclesThroughElements(bool value); virtual WebFrame* GetMainFrame(); diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 114fc3c..a7a4d25 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -113,6 +113,8 @@ LayoutTestController::LayoutTestController(TestShell* shell) { BindMethod("pauseTransitionAtTimeOnElementWithId", &LayoutTestController::pauseTransitionAtTimeOnElementWithId); BindMethod("elementDoesAutoCompleteForElementWithId", &LayoutTestController::elementDoesAutoCompleteForElementWithId); BindMethod("numberOfActiveAnimations", &LayoutTestController::numberOfActiveAnimations); + BindMethod("setCustomPolicyDelegate", &LayoutTestController::setCustomPolicyDelegate); + BindMethod("waitForPolicyDelegate", &LayoutTestController::waitForPolicyDelegate); // The following are stubs. BindMethod("dumpAsWebArchive", &LayoutTestController::dumpAsWebArchive); @@ -130,7 +132,6 @@ LayoutTestController::LayoutTestController(TestShell* shell) { BindMethod("setCallCloseOnWebViews", &LayoutTestController::setCallCloseOnWebViews); BindMethod("setPrivateBrowsingEnabled", &LayoutTestController::setPrivateBrowsingEnabled); BindMethod("setUseDashboardCompatibilityMode", &LayoutTestController::setUseDashboardCompatibilityMode); - BindMethod("setCustomPolicyDelegate", &LayoutTestController::setCustomPolicyDelegate); // This typo (missing 'i') is intentional as it matches the typo in the layout test // see: LayoutTests/fast/canvas/fill-stroke-clip-reset-path.html. @@ -454,6 +455,15 @@ void LayoutTestController::LocationChangeDone() { work_queue_.ProcessWorkSoon(); } +void LayoutTestController::PolicyDelegateDone() { + if (!shell_->layout_test_mode()) + return; + + DCHECK(wait_until_done_); + shell_->TestFinished(); + wait_until_done_ = false; +} + void LayoutTestController::setCanOpenWindows( const CppArgumentList& args, CppVariant* result) { can_open_windows_ = true; @@ -560,12 +570,23 @@ void LayoutTestController::setUseDashboardCompatibilityMode( void LayoutTestController::setCustomPolicyDelegate( const CppArgumentList& args, CppVariant* result) { if (args.size() > 0 && args[0].isBool()) { - shell_->delegate()->SetCustomPolicyDelegate(args[0].value.boolValue); + bool enable = args[0].value.boolValue; + bool permissive = false; + if (args.size() > 1 && args[1].isBool()) + permissive = args[1].value.boolValue; + shell_->delegate()->SetCustomPolicyDelegate(enable, permissive); } result->SetNull(); } +void LayoutTestController::waitForPolicyDelegate( + const CppArgumentList& args, CppVariant* result) { + shell_->delegate()->WaitForPolicyDelegate(); + wait_until_done_ = true; + result->SetNull(); +} + void LayoutTestController::pathToLocalResource( const CppArgumentList& args, CppVariant* result) { result->SetNull(); diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h index 3f56bce..4522c84 100644 --- a/webkit/tools/test_shell/layout_test_controller.h +++ b/webkit/tools/test_shell/layout_test_controller.h @@ -110,6 +110,9 @@ class LayoutTestController : public CppBoundClass { // don't actually want to open the mail program. void setCustomPolicyDelegate(const CppArgumentList& args, CppVariant* result); + // Delays completion of the test until the policy delegate runs. + void waitForPolicyDelegate(const CppArgumentList& args, CppVariant* result); + // Converts a URL starting with file:///tmp/ to the local mapping. void pathToLocalResource(const CppArgumentList& args, CppVariant* result); @@ -206,6 +209,10 @@ class LayoutTestController : public CppBoundClass { // Called by the webview delegate when the toplevel frame load is done. void LocationChangeDone(); + // Called by the webview delegate when the policy delegate runs if the + // waitForPolicyDelegate was called. + void PolicyDelegateDone(); + // Reinitializes all static values. The Reset() method should be called // before the start of each test (currently from // TestShell::RunFileTest). diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 42193e8..8ac1e06 100755 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -449,6 +449,15 @@ void TestShell::SizeToDefault() { SizeTo(kTestWindowWidth, kTestWindowHeight); } +void TestShell::ResetTestController() { + layout_test_controller_->Reset(); + event_sending_controller_->Reset(); + + // Reset state in the test webview delegate. + delegate_ = new TestWebViewDelegate(this); + webView()->SetDelegate(delegate_); +} + void TestShell::LoadURL(const wchar_t* url) { LoadURLForFrame(url, NULL); } diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 0777ae0..11c8daf 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -118,18 +118,7 @@ public: // may arrive after the previous page has finished dumping its text and // therefore end up in the next test's results if the messages are still // enabled. - void ResetTestController() { - layout_test_controller_->Reset(); - event_sending_controller_->Reset(); - - // Reset state in the test webview delegate. - delegate()->SetSmartInsertDeleteEnabled(true); -#if defined(OS_WIN) - delegate()->SetSelectTrailingWhitespaceEnabled(true); -#else - delegate()->SetSelectTrailingWhitespaceEnabled(false); -#endif - } + void ResetTestController(); // Passes options from LayoutTestController through to the delegate (or // any other caller). diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 40c1c89..fe33461 100755 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -136,20 +136,25 @@ WindowOpenDisposition TestWebViewDelegate::DispositionForNavigationAction( WebNavigationType type, WindowOpenDisposition disposition, bool is_redirect) { - if (is_custom_policy_delegate_) { + WindowOpenDisposition result; + if (policy_delegate_enabled_) { std::wstring frame_name = frame->GetName(); + std::string url_description; + if (request->GetURL().SchemeIs("file")) { + url_description = request->GetURL().ExtractFileName(); + } else { + url_description = request->GetURL().spec(); + } printf("Policy delegate: attempt to load %s with navigation type '%s'\n", - request->GetURL().spec().c_str(), WebNavigationTypeToString(type)); - return IGNORE_ACTION; + url_description.c_str(), WebNavigationTypeToString(type)); + result = policy_delegate_is_permissive_ ? CURRENT_TAB : IGNORE_ACTION; + if (policy_delegate_should_notify_done_) + shell_->layout_test_controller()->PolicyDelegateDone(); } else { - return WebViewDelegate::DispositionForNavigationAction( - webview, frame, request, type, disposition, is_redirect); + result = WebViewDelegate::DispositionForNavigationAction( + webview, frame, request, type, disposition, is_redirect); } -} - - -void TestWebViewDelegate::SetCustomPolicyDelegate(bool isCustom) { - is_custom_policy_delegate_ = isCustom; + return result; } void TestWebViewDelegate::AssignIdentifierToRequest(WebView* webview, @@ -747,6 +752,17 @@ void TestWebViewDelegate::RegisterDragDrop() { #endif } +void TestWebViewDelegate::SetCustomPolicyDelegate(bool is_custom, + bool is_permissive) { + policy_delegate_enabled_ = is_custom; + policy_delegate_is_permissive_ = is_permissive; +} + +void TestWebViewDelegate::WaitForPolicyDelegate() { + policy_delegate_enabled_ = true; + policy_delegate_should_notify_done_ = true; +} + // Private methods ----------------------------------------------------------- void TestWebViewDelegate::UpdateAddressBar(WebView* webView) { diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index c11186f..5481376 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -56,7 +56,9 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, typedef std::vector<CapturedContextMenuEvent> CapturedContextMenuEvents; TestWebViewDelegate(TestShell* shell) - : is_custom_policy_delegate_(false), + : policy_delegate_enabled_(false), + policy_delegate_is_permissive_(false), + policy_delegate_should_notify_done_(false), shell_(shell), top_loading_frame_(NULL), page_id_(-1), @@ -204,7 +206,6 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, WebNavigationType type, WindowOpenDisposition disposition, bool is_redirect); - void SetCustomPolicyDelegate(bool isCustom); virtual WebHistoryItem* GetHistoryEntryAtOffset(int offset); virtual int GetHistoryBackListCount(); virtual int GetHistoryForwardListCount(); @@ -260,6 +261,9 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, // Sets the webview as a drop target. void RegisterDragDrop(); + void SetCustomPolicyDelegate(bool is_custom, bool is_permissive); + void WaitForPolicyDelegate(); + protected: // Called the title of the page changes. // Can be used to update the title of the window. @@ -297,7 +301,14 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, // Causes navigation actions just printout the intended navigation instead // of taking you to the page. This is used for cases like mailto, where you // don't actually want to open the mail program. - bool is_custom_policy_delegate_; + bool policy_delegate_enabled_; + + // Toggles the behavior of the policy delegate. If true, then navigations + // will be allowed. Otherwise, they will be ignored (dropped). + bool policy_delegate_is_permissive_; + + // If true, the policy delegate will signal layout test completion. + bool policy_delegate_should_notify_done_; // Non-owning pointer. The delegate is owned by the host. TestShell* shell_; |