diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 16:25:15 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 16:25:15 +0000 |
commit | f56eed44ee5f199604fdf32cfab3d4abe183182a (patch) | |
tree | 0036230729aaf09d2f9c8fc057df006c91064505 /webkit/tools | |
parent | 789fbb7cd36822230870c3beff00fa30b532d14e (diff) | |
download | chromium_src-f56eed44ee5f199604fdf32cfab3d4abe183182a.zip chromium_src-f56eed44ee5f199604fdf32cfab3d4abe183182a.tar.gz chromium_src-f56eed44ee5f199604fdf32cfab3d4abe183182a.tar.bz2 |
Fix tests that depend on setCustomPolicyDelegate and waitForPolicyDelegate.
Changes:
1- Need to support a second parameter to setCustomPolicyDelegate that
controls whether subsequent loads are permitted or not. Previously,
we would always deny any subsequent loads.
2- Need to change the string that we produce when writing out the URL
that is impacted by a custom policy delegate. We need to write out only
the filename part of the URL. (We need to do this only for file:// URLs.)
3- Add LayoutTestController::waitForPolicyDelegate and corresponding
method on TestWebViewDelegate.
4- Improve the way we reset the TestWebViewDelegate. Now, instead of
having support for reseting individual fields, we just reallocate the
delegate. This requires adding a SetDelegate method to WebView.
BUG=9582
R=dglazkov
Review URL: http://codereview.chromium.org/56169
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools')
-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 |
6 files changed, 80 insertions, 27 deletions
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_; |