Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(844)

Unified Diff: chrome/browser/services/gcm/push_messaging_permission_context_unittest.cc

Issue 718203004: [PUSH] Merge notifications and push messaging prompts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/push_messaging_permission_context_unittest.cc
diff --git a/chrome/browser/services/gcm/push_messaging_permission_context_unittest.cc b/chrome/browser/services/gcm/push_messaging_permission_context_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dea666d5c01df09419a0e66ea7825252990da15d
--- /dev/null
+++ b/chrome/browser/services/gcm/push_messaging_permission_context_unittest.cc
@@ -0,0 +1,168 @@
+// Copyright 2014 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 "chrome/browser/services/gcm/push_messaging_permission_context.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+#include "components/content_settings/core/common/permission_request_id.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+const char kEmbedder[] = "https://example.org";
+
+namespace gcm {
+
+class TestPushMessagingPermissionContext
+ : public PushMessagingPermissionContext {
+ public:
+ explicit TestPushMessagingPermissionContext(Profile* profile)
+ : PushMessagingPermissionContext(profile),
+ was_persisted_(false),
+ permission_granted_(false) {}
+
+ bool was_persisted() const { return was_persisted_; }
+ bool was_granted() const { return permission_granted_; }
+
+ // PushMessagingPermissionContext:
+ void DecidePermission(content::WebContents* web_contents,
+ const PermissionRequestID& id,
+ const GURL& requesting_origin,
+ const GURL& embedder_origin,
+ bool user_gesture,
+ const BrowserPermissionCallback& callback) override {
+ PushMessagingPermissionContext::DecidePermission(
+ web_contents, id, requesting_origin, embedder_origin, user_gesture,
+ callback);
+ }
+
+ private:
+ // PushMessagingPermissionContext:
+ void NotifyPermissionSet(const PermissionRequestID& id,
+ const GURL& requesting_origin,
+ const GURL& embedder_origin,
+ const BrowserPermissionCallback& callback,
+ bool persist,
+ bool allowed) override {
+ was_persisted_ = persist;
+ permission_granted_ = allowed;
+ }
+
+ bool was_persisted_;
+ bool permission_granted_;
+};
+
+class PushMessagingPermissionContextTest : public testing::Test {
+ public:
+ PushMessagingPermissionContextTest() {}
+
+ protected:
+ void SetContentSetting(ContentSettingsType setting, ContentSetting value) {
+ ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(kEmbedder);
+ HostContentSettingsMap* host_content_settings_map =
+ profile_.GetHostContentSettingsMap();
+ host_content_settings_map->SetContentSetting(pattern, pattern, setting,
fgorski 2014/11/17 18:24:06 nit: move all of the parameters to the new line
Miguel Garcia 2014/11/18 10:47:30 this is what clank cl format has decided...
+ std::string(), value);
+ }
fgorski 2014/11/17 18:24:06 nit: new line
Miguel Garcia 2014/11/18 10:47:30 Done.
+ TestingProfile profile_;
+ content::TestBrowserThreadBundle thread_bundle_;
+
+ private:
+ void SetUp() override {
fgorski 2014/11/17 18:24:07 SetUp is typically public
Miguel Garcia 2014/11/18 10:47:30 Ok, I made it public but would like to understand
+ HostContentSettingsMap* host_content_settings_map =
+ profile_.GetHostContentSettingsMap();
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ASK);
+ }
+};
+
+TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
+ PushMessagingPermissionContext context(&profile_);
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+
+ // Just granting notifications should still prompt
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
+
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+
+ // Just granting push should still prompt
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_ALLOW);
+
+ EXPECT_EQ(CONTENT_SETTING_ASK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+}
+
+TEST_F(PushMessagingPermissionContextTest, HasPermissionDeny) {
+ PushMessagingPermissionContext context(&profile_);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
fgorski 2014/11/17 18:24:06 I think you are already testing for that in 114-11
Miguel Garcia 2014/11/18 10:47:30 Indeed, removed this duplicated check.
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+}
+
+TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) {
+ PushMessagingPermissionContext context(&profile_);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_ALLOW);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
+}
+
+TEST_F(PushMessagingPermissionContextTest, DecidePermission) {
+ TestPushMessagingPermissionContext context(&profile_);
+ PermissionRequestID request_id(-1, -1, -1, GURL(kEmbedder));
+ BrowserPermissionCallback callback;
+
+ context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
+ true, callback);
+ EXPECT_FALSE(context.was_persisted());
+ EXPECT_FALSE(context.was_granted());
+
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK);
+ context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
+ true, callback);
+ EXPECT_FALSE(context.was_persisted());
+ EXPECT_FALSE(context.was_granted());
+ SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_BLOCK);
+ context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
+ true, callback);
+ EXPECT_FALSE(context.was_persisted());
+ EXPECT_FALSE(context.was_granted());
+ SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ASK);
+ context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
+ true, callback);
+ EXPECT_TRUE(context.was_persisted());
+ EXPECT_TRUE(context.was_granted());
+}
+
+} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698