summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-23 12:31:20 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-23 12:31:20 +0000
commit0c6c4bef222291c78aa1a72252fa9eacc57a0880 (patch)
treea722338a8ba24f0b3ea63bc5019ea0dd45bf0f1d /chrome/browser/notifications
parent44f6076044d0936eb3ab7394faaee1f48e6bef9b (diff)
downloadchromium_src-0c6c4bef222291c78aa1a72252fa9eacc57a0880.zip
chromium_src-0c6c4bef222291c78aa1a72252fa9eacc57a0880.tar.gz
chromium_src-0c6c4bef222291c78aa1a72252fa9eacc57a0880.tar.bz2
Fix notification settings for file scheme
The DesktopNotificationService gets empty GURLs in case of file scheme urls. This CL deals with the that to fix breaking regression tests. The root cause of the problem remains to be fixed. BUG=76693 TEST=desktop_notification_service_unittest.cc Review URL: http://codereview.chromium.org/6719021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc19
-rw-r--r--chrome/browser/notifications/desktop_notification_service_unittest.cc38
2 files changed, 46 insertions, 11 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index e372055..a6e4eb5 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -45,8 +45,6 @@ const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK;
namespace {
-const std::string HTTP_PREFIX("http://");
-
typedef content_settings::ProviderInterface::Rules Rules;
void GetOriginsWithSettingFromContentSettingsRules(
@@ -64,17 +62,19 @@ void GetOriginsWithSettingFromContentSettingsRules(
// TODO(markusheintz): This will be removed in one of the next
// refactoring steps as this entire function will disapear.
LOG(DFATAL) << "Ignoring invalid content settings pattern: "
- << url_str;
+ << url_str;
} else if (url_str.find(ContentSettingsPattern::kDomainWildcard) == 0) {
// TODO(markusheintz): This must be changed once the UI code is
// refactored and content_settings patterns are fully supported for
// notifications settings.
LOG(DFATAL) << "Ignoring unsupported content settings pattern: "
- << url_str << ". Content settings patterns other than "
- << "hostnames (e.g. wildcard patterns) are not supported "
- << "for notification content settings yet.";
+ << url_str << ". Content settings patterns other than "
+ << "hostnames (e.g. wildcard patterns) are not supported "
+ << "for notification content settings yet.";
} else {
- origins->push_back(GURL(HTTP_PREFIX + url_str));
+ origins->push_back(
+ content_settings::NotificationProvider::ToGURL(
+ rule->requesting_url_pattern));
}
}
}
@@ -318,7 +318,7 @@ void DesktopNotificationService::StopObserving() {
void DesktopNotificationService::GrantPermission(const GURL& origin) {
ContentSettingsPattern pattern =
- ContentSettingsPattern::FromURLNoWildcard(origin);
+ content_settings::NotificationProvider::ToContentSettingsPattern(origin);
provider_->SetContentSetting(
pattern,
pattern,
@@ -335,11 +335,10 @@ void DesktopNotificationService::GrantPermission(const GURL& origin) {
origin));
}
-
void DesktopNotificationService::DenyPermission(const GURL& origin) {
// Update content settings
ContentSettingsPattern pattern =
- ContentSettingsPattern::FromURLNoWildcard(origin);
+ content_settings::NotificationProvider::ToContentSettingsPattern(origin);
provider_->SetContentSetting(
pattern,
pattern,
diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc
index 7b4a28e..3d9af1a 100644
--- a/chrome/browser/notifications/desktop_notification_service_unittest.cc
+++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -137,6 +137,42 @@ TEST_F(DesktopNotificationServiceTest, DefaultContentSettingSentToCache) {
EXPECT_EQ(CONTENT_SETTING_BLOCK, cache_->CachedDefaultContentSetting());
}
+TEST_F(DesktopNotificationServiceTest, SettingsForSchemes) {
+ GURL url("file:///html/test.html");
+
+ EXPECT_EQ(CONTENT_SETTING_ASK, cache_->CachedDefaultContentSetting());
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
+ proxy_->CacheHasPermission(cache_, url));
+
+ service_->GrantPermission(url);
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
+ proxy_->CacheHasPermission(cache_, url));
+
+ service_->DenyPermission(url);
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied,
+ proxy_->CacheHasPermission(cache_, url));
+
+ GURL https_url("https://testurl");
+ GURL http_url("http://testurl");
+ EXPECT_EQ(CONTENT_SETTING_ASK, cache_->CachedDefaultContentSetting());
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
+ proxy_->CacheHasPermission(cache_, http_url));
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
+ proxy_->CacheHasPermission(cache_, https_url));
+
+ service_->GrantPermission(https_url);
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
+ proxy_->CacheHasPermission(cache_, https_url));
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,
+ proxy_->CacheHasPermission(cache_, http_url));
+
+ service_->DenyPermission(http_url);
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionDenied,
+ proxy_->CacheHasPermission(cache_, http_url));
+ EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionAllowed,
+ proxy_->CacheHasPermission(cache_, https_url));
+}
+
TEST_F(DesktopNotificationServiceTest, GrantPermissionSentToCache) {
GURL url("http://allowed.com");
EXPECT_EQ(WebKit::WebNotificationPresenter::PermissionNotAllowed,