summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 17:56:52 +0000
committerpeter@chromium.org <peter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 17:56:52 +0000
commit446e16c3e929ac152b21d353199fad42ba948b06 (patch)
tree43c88009741a8f6dbf40a7d61423a89be9f23304
parent2c397908d3c8555269f5516f8eb24dd5100a4449 (diff)
downloadchromium_src-446e16c3e929ac152b21d353199fad42ba948b06.zip
chromium_src-446e16c3e929ac152b21d353199fad42ba948b06.tar.gz
chromium_src-446e16c3e929ac152b21d353199fad42ba948b06.tar.bz2
Notification.permission's default value of "default" should be testable.
If no permission request has been answered yet, the Notification.permission string of the Web Notification API should be set to "default". The presenter used for testing can currently only return "allowed" or "denied". BUG=349015 Review URL: https://codereview.chromium.org/183663021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256273 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/shell/renderer/test_runner/TestRunner.cpp13
-rw-r--r--content/shell/renderer/test_runner/notification_presenter.cc14
-rw-r--r--content/shell/renderer/test_runner/notification_presenter.h8
3 files changed, 22 insertions, 13 deletions
diff --git a/content/shell/renderer/test_runner/TestRunner.cpp b/content/shell/renderer/test_runner/TestRunner.cpp
index 2584a3b..74d35df 100644
--- a/content/shell/renderer/test_runner/TestRunner.cpp
+++ b/content/shell/renderer/test_runner/TestRunner.cpp
@@ -1821,12 +1821,15 @@ void TestRunner::setMIDISysExPermission(const CppArgumentList& arguments, CppVar
void TestRunner::grantWebNotificationPermission(const CppArgumentList& arguments, CppVariant* result)
{
- if (arguments.size() != 1 || !arguments[0].isString()) {
- result->set(false);
+ result->setNull();
+ if (arguments.size() < 1 || !arguments[0].isString())
return;
- }
- notification_presenter_->GrantPermission(arguments[0].toString());
- result->set(true);
+
+ bool permissionGranted = true;
+ if (arguments.size() == 2 && arguments[1].isBool())
+ permissionGranted = arguments[1].toBoolean();
+
+ notification_presenter_->GrantPermission(arguments[0].toString(), permissionGranted);
}
void TestRunner::simulateLegacyWebNotificationClick(const CppArgumentList& arguments, CppVariant* result)
diff --git a/content/shell/renderer/test_runner/notification_presenter.cc b/content/shell/renderer/test_runner/notification_presenter.cc
index d6f4a25..e6362d3 100644
--- a/content/shell/renderer/test_runner/notification_presenter.cc
+++ b/content/shell/renderer/test_runner/notification_presenter.cc
@@ -37,8 +37,9 @@ NotificationPresenter::NotificationPresenter() : delegate_(0) {}
NotificationPresenter::~NotificationPresenter() {}
-void NotificationPresenter::GrantPermission(const std::string& origin) {
- allowed_origins_.insert(origin);
+void NotificationPresenter::GrantPermission(const std::string& origin,
+ bool permission_granted) {
+ known_origins_[origin] = permission_granted;
}
bool NotificationPresenter::SimulateClick(const std::string& title) {
@@ -63,7 +64,7 @@ void NotificationPresenter::CancelAllActiveNotifications() {
void NotificationPresenter::Reset() {
// TODO(peter): Ensure that |active_notifications_| is empty as well.
- allowed_origins_.clear();
+ known_origins_.clear();
}
bool NotificationPresenter::show(const WebNotification& notification) {
@@ -121,7 +122,12 @@ void NotificationPresenter::objectDestroyed(
WebNotificationPresenter::Permission NotificationPresenter::checkPermission(
const WebSecurityOrigin& security_origin) {
const std::string origin = security_origin.toString().utf8();
- if (allowed_origins_.find(origin) != allowed_origins_.end())
+ const KnownOriginMap::iterator it = known_origins_.find(origin);
+ if (it == known_origins_.end())
+ return WebNotificationPresenter::PermissionNotAllowed;
+
+ // Values in |known_origins_| indicate whether permission has been granted.
+ if (it->second)
return WebNotificationPresenter::PermissionAllowed;
return WebNotificationPresenter::PermissionDenied;
diff --git a/content/shell/renderer/test_runner/notification_presenter.h b/content/shell/renderer/test_runner/notification_presenter.h
index 9730f4a..ac30181 100644
--- a/content/shell/renderer/test_runner/notification_presenter.h
+++ b/content/shell/renderer/test_runner/notification_presenter.h
@@ -6,7 +6,6 @@
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_NOTIFICATION_PRESENTER_H_
#include <map>
-#include <set>
#include <string>
#include "base/basictypes.h"
@@ -26,7 +25,7 @@ class NotificationPresenter : public blink::WebNotificationPresenter {
virtual ~NotificationPresenter();
// Called by the TestRunner to simulate a user granting permission.
- void GrantPermission(const std::string& origin);
+ void GrantPermission(const std::string& origin, bool permission_granted);
// Called by the TestRunner to simulate a user clicking on a notification.
bool SimulateClick(const std::string& title);
@@ -54,8 +53,9 @@ class NotificationPresenter : public blink::WebNotificationPresenter {
private:
WebTestRunner::WebTestDelegate* delegate_;
- // Set of origins which are allowed to show notifications.
- std::set<std::string> allowed_origins_;
+ // Map of known origins and whether they are allowed to show notifications.
+ typedef std::map<std::string, bool> KnownOriginMap;
+ KnownOriginMap known_origins_;
// Map of currently active notifications.
typedef std::map<std::string, blink::WebNotification> ActiveNotificationMap;