diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 19:33:34 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 19:33:34 +0000 |
commit | 33410c838b3d0ad411bb16b905e0188eacb40fb9 (patch) | |
tree | 52a98500792b161b07cf510159958eb5af7956cf /webkit | |
parent | 79d3f1e0cd308344a0b59c28e4d305252267a409 (diff) | |
download | chromium_src-33410c838b3d0ad411bb16b905e0188eacb40fb9.zip chromium_src-33410c838b3d0ad411bb16b905e0188eacb40fb9.tar.gz chromium_src-33410c838b3d0ad411bb16b905e0188eacb40fb9.tar.bz2 |
Enable support for notifications layout tests in test shell.
BUG=none
TEST=notifications layout tests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=44372
Reverted.
Review URL: http://codereview.chromium.org/1549039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44515 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/support/test_webkit_client.cc | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 13 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/notification_presenter.cc | 76 | ||||
-rw-r--r-- | webkit/tools/test_shell/notification_presenter.h | 45 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 3 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 7 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.h | 1 |
11 files changed, 158 insertions, 1 deletions
diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc index 7f0eed2..7581b19 100644 --- a/webkit/support/test_webkit_client.cc +++ b/webkit/support/test_webkit_client.cc @@ -67,6 +67,7 @@ TestWebKitClient::TestWebKitClient() { WebKit::WebRuntimeFeatures::enableSockets(true); WebKit::WebRuntimeFeatures::enableApplicationCache(true); WebKit::WebRuntimeFeatures::enableDatabase(true); + WebKit::WebRuntimeFeatures::enableNotifications(true); // Load libraries for media and enable the media player. bool enable_media = false; diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index 257ab41..08eb371 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -25,6 +25,7 @@ #include "webkit/glue/dom_operations.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" +#include "webkit/tools/test_shell/notification_presenter.h" #include "webkit/tools/test_shell/simple_database_system.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/test_navigation_controller.h" @@ -135,6 +136,7 @@ LayoutTestController::LayoutTestController(TestShell* shell) : BindMethod("pageNumberForElementById", &LayoutTestController::pageNumberForElementById); BindMethod("numberOfPages", &LayoutTestController::numberOfPages); BindMethod("dumpSelectionRect", &LayoutTestController::dumpSelectionRect); + BindMethod("grantDesktopNotificationPermission", &LayoutTestController::grantDesktopNotificationPermission); // The following are stubs. BindMethod("dumpAsWebArchive", &LayoutTestController::dumpAsWebArchive); @@ -825,6 +827,17 @@ void LayoutTestController::callShouldCloseOnWebView( result->Set(rv); } +void LayoutTestController::grantDesktopNotificationPermission( + const CppArgumentList& args, CppVariant* result) { + if (args.size() != 1 || !args[0].isString()) { + result->Set(false); + return; + } + std::string origin = args[0].ToString(); + shell_->notification_presenter()->grantPermission(origin); + result->Set(true); +} + // // Unimplemented stubs // diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h index acb855e..e6c4fd7 100644 --- a/webkit/tools/test_shell/layout_test_controller.h +++ b/webkit/tools/test_shell/layout_test_controller.h @@ -187,6 +187,10 @@ class LayoutTestController : public CppBoundClass { void dumpSelectionRect(const CppArgumentList& args, CppVariant* result); + // Grants permission for desktop notifications to an origin + void grantDesktopNotificationPermission(const CppArgumentList& args, + CppVariant* result); + // The following are only stubs. TODO(pamg): Implement any of these that // are needed to pass the layout tests. void dumpAsWebArchive(const CppArgumentList& args, CppVariant* result); diff --git a/webkit/tools/test_shell/notification_presenter.cc b/webkit/tools/test_shell/notification_presenter.cc new file mode 100644 index 0000000..2727a55 --- /dev/null +++ b/webkit/tools/test_shell/notification_presenter.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/tools/test_shell/notification_presenter.h" + +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebNotification.h" +#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPermissionCallback.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" + +using WebKit::WebNotification; +using WebKit::WebNotificationPresenter; +using WebKit::WebNotificationPermissionCallback; +using WebKit::WebSecurityOrigin; +using WebKit::WebString; +using WebKit::WebURL; + +void TestNotificationPresenter::grantPermission(const std::string& origin) { + // Make sure it's in the form of an origin. + GURL url(origin); + allowed_origins_.insert(url.GetOrigin().spec()); +} + +// The output from all these methods matches what DumpRenderTree produces. +bool TestNotificationPresenter::show(const WebNotification& notification) { + if (notification.isHTML()) { + printf("DESKTOP NOTIFICATION: contents at %s\n", + notification.url().spec().data()); + } else { + printf("DESKTOP NOTIFICATION: icon %s, title %s, text %s\n", + notification.icon().utf8().data(), + notification.title().utf8().data(), + notification.body().utf8().data()); + } + + WebNotification event_target(notification); + event_target.dispatchDisplayEvent(); + return true; +} + +void TestNotificationPresenter::cancel(const WebNotification& notification) { + WebString identifier; + if (notification.isHTML()) + identifier = notification.url().spec().utf16(); + else + identifier = notification.title(); + + printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); + WebNotification event_target(notification); + event_target.dispatchCloseEvent(false); +} + +void TestNotificationPresenter::objectDestroyed( + const WebKit::WebNotification& notification) { + // Nothing to do. Not storing the objects. +} + +WebNotificationPresenter::Permission TestNotificationPresenter::checkPermission( + const WebURL& url) { + // Check with the layout test controller + std::string origin = static_cast<GURL>(url).GetOrigin().spec(); + bool allowed = allowed_origins_.find(origin) != allowed_origins_.end(); + return allowed ? WebNotificationPresenter::PermissionAllowed + : WebNotificationPresenter::PermissionDenied; +} + +void TestNotificationPresenter::requestPermission( + const WebSecurityOrigin& origin, + WebNotificationPermissionCallback* callback) { + printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", + origin.toString().utf8().data()); + callback->permissionRequestComplete(); +} diff --git a/webkit/tools/test_shell/notification_presenter.h b/webkit/tools/test_shell/notification_presenter.h new file mode 100644 index 0000000..07d7978 --- /dev/null +++ b/webkit/tools/test_shell/notification_presenter.h @@ -0,0 +1,45 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_ +#define WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_ + +#include <set> +#include <string> + +#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h" +#include "webkit/tools/test_shell/test_shell.h" + +// A class that implements NotificationPresenter for the test shell. +class TestNotificationPresenter : public WebKit::WebNotificationPresenter { + public: + explicit TestNotificationPresenter(TestShell* shell) + : shell_(shell) { + } + + // Called by the LayoutTestController to simulate a user granting + // permission. + void grantPermission(const std::string& origin); + + // WebKit::WebNotificationPresenter interface + virtual bool show(const WebKit::WebNotification&); + virtual void cancel(const WebKit::WebNotification&); + virtual void objectDestroyed(const WebKit::WebNotification&); + virtual Permission checkPermission(const WebKit::WebURL& url); + virtual void requestPermission(const WebKit::WebSecurityOrigin& origin, + WebKit::WebNotificationPermissionCallback* callback); + + void Reset() { + allowed_origins_.clear(); + } + + private: + // Non-owned pointer. The NotificationPresenter is owned by the test shell. + TestShell* shell_; + + // List of allowed origins. + std::set<std::string> allowed_origins_; +}; + +#endif // WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_ diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index d529ba7..577fd1d 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -46,6 +46,7 @@ #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" #include "webkit/tools/test_shell/accessibility_controller.h" +#include "webkit/tools/test_shell/notification_presenter.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell_devtools_agent.h" @@ -134,6 +135,7 @@ TestShell::TestShell() plain_text_controller_.reset(new PlainTextController(this)); text_input_controller_.reset(new TextInputController(this)); navigation_controller_.reset(new TestNavigationController(this)); + notification_presenter_.reset(new TestNotificationPresenter(this)); URLRequestFilter* filter = URLRequestFilter::GetInstance(); filter->AddHostnameHandler("test-shell-resource", "inspector", @@ -623,6 +625,7 @@ void TestShell::ResetTestController() { accessibility_controller_->Reset(); layout_test_controller_->Reset(); event_sending_controller_->Reset(); + notification_presenter_->Reset(); delegate_->Reset(); } diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 79a8242..54a587b 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -69,6 +69,8 @@ 'layout_test_controller.h', 'mock_spellcheck.cc', 'mock_spellcheck.h', + 'notification_presenter.cc', + 'notification_presenter.h', 'plain_text_controller.cc', 'plain_text_controller.h', 'resource.h', diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 12227a0..f07b5a1 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -54,6 +54,7 @@ class FilePath; class GURL; class TestNavigationEntry; class TestNavigationController; +class TestNotificationPresenter; class TestShellDevToolsAgent; class TestShellDevToolsClient; class TestWebViewDelegate; @@ -159,6 +160,9 @@ public: EventSendingController* event_sending_controller() { return event_sending_controller_.get(); } + TestNotificationPresenter* notification_presenter() { + return notification_presenter_.get(); + } // Resets the LayoutTestController and EventSendingController. Should be // called before loading a page, since some end-editing event notifications @@ -388,6 +392,7 @@ private: scoped_ptr<PlainTextController> plain_text_controller_; scoped_ptr<TextInputController> text_input_controller_; scoped_ptr<TestNavigationController> navigation_controller_; + scoped_ptr<TestNotificationPresenter> notification_presenter_; scoped_ptr<TestWebViewDelegate> delegate_; scoped_ptr<TestWebViewDelegate> popup_delegate_; @@ -427,4 +432,3 @@ private: }; #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ - diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index ace35ab..a1073ad 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -63,6 +63,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { WebKit::WebRuntimeFeatures::enableDatabase(true); WebKit::WebRuntimeFeatures::enableWebGL(true); WebKit::WebRuntimeFeatures::enablePushState(true); + WebKit::WebRuntimeFeatures::enableNotifications(true); // Load libraries for media and enable the media player. FilePath module_path; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 45d5903..d05f8b01 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -29,6 +29,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" +#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h" #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h" #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" @@ -52,6 +53,7 @@ #include "webkit/support/webkit_support.h" #include "webkit/tools/test_shell/accessibility_controller.h" #include "webkit/tools/test_shell/mock_spellcheck.h" +#include "webkit/tools/test_shell/notification_presenter.h" #include "webkit/tools/test_shell/simple_appcache_system.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" @@ -84,6 +86,7 @@ using WebKit::WebMediaPlayerClient; using WebKit::WebNavigationType; using WebKit::WebNavigationPolicy; using WebKit::WebNode; +using WebKit::WebNotificationPresenter; using WebKit::WebPlugin; using WebKit::WebPluginParams; using WebKit::WebPoint; @@ -609,6 +612,10 @@ void TestWebViewDelegate::focusAccessibilityObject( shell_->accessibility_controller()->SetFocusedElement(object); } +WebNotificationPresenter* TestWebViewDelegate::notificationPresenter() { + return shell_->notification_presenter(); +} + // WebWidgetClient ----------------------------------------------------------- void TestWebViewDelegate::didInvalidateRect(const WebRect& rect) { diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 16b042b..c3c9105 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -133,6 +133,7 @@ class TestWebViewDelegate : public WebKit::WebViewClient, virtual int historyForwardListCount(); virtual void focusAccessibilityObject( const WebKit::WebAccessibilityObject& object); + virtual WebKit::WebNotificationPresenter* notificationPresenter(); // WebKit::WebWidgetClient virtual void didInvalidateRect(const WebKit::WebRect& rect); |