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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
6 #include "chrome/test/base/testing_profile.h"
7 #include "components/content_settings/core/browser/host_content_settings_map.h"
8 #include "components/content_settings/core/common/content_settings.h"
9 #include "components/content_settings/core/common/content_settings_types.h"
10 #include "components/content_settings/core/common/permission_request_id.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 const char kEmbedder[] = "https://example.org";
15
16 namespace gcm {
17
18 class TestPushMessagingPermissionContext
19 : public PushMessagingPermissionContext {
20 public:
21 static const GURL kEmbedderUrl;
Bernhard Bauer 2014/11/17 13:46:01 Remove this now that you use GURL(kEmbedder)?
Miguel Garcia 2014/11/17 14:26:44 Done.
22
23 explicit TestPushMessagingPermissionContext(Profile* profile)
24 : PushMessagingPermissionContext(profile),
25 was_persisted_(false),
26 permission_granted_(false) {}
27
28 bool was_persisted() const { return was_persisted_; }
29 bool was_granted() const { return permission_granted_; }
30
31 // PushMessagingPermissionContext:
32 void DecidePermission(content::WebContents* web_contents,
33 const PermissionRequestID& id,
34 const GURL& requesting_origin,
35 const GURL& embedder_origin,
36 bool user_gesture,
37 const BrowserPermissionCallback& callback) override {
38 PushMessagingPermissionContext::DecidePermission(
39 web_contents, id, requesting_origin, embedder_origin, user_gesture,
40 callback);
41 }
42
43 private:
44 // PushMessagingPermissionContext:
45 void NotifyPermissionSet(const PermissionRequestID& id,
46 const GURL& requesting_origin,
47 const GURL& embedder_origin,
48 const BrowserPermissionCallback& callback,
49 bool persist,
50 bool allowed) override {
51 was_persisted_ = persist;
52 permission_granted_ = allowed;
53 }
54
55 bool was_persisted_;
56 bool permission_granted_;
57 };
58
59 const GURL TestPushMessagingPermissionContext::kEmbedderUrl(kEmbedder);
60
61 class PushMessagingPermissionContextTest : public testing::Test {
62 public:
63 PushMessagingPermissionContextTest() {}
64
65 protected:
66 void SetContentSetting(ContentSettingsType setting, ContentSetting value) {
67 ContentSettingsPattern pattern =
68 ContentSettingsPattern::FromString(kEmbedder);
69 HostContentSettingsMap* host_content_settings_map =
70 profile_.GetHostContentSettingsMap();
71 host_content_settings_map->SetContentSetting(pattern, pattern, setting,
72 std::string(), value);
73 }
74 TestingProfile profile_;
75 content::TestBrowserThreadBundle thread_bundle_;
76
77 private:
78 void SetUp() override {
79 HostContentSettingsMap* host_content_settings_map =
80 profile_.GetHostContentSettingsMap();
81 host_content_settings_map->SetDefaultContentSetting(
82 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
83 host_content_settings_map->SetDefaultContentSetting(
84 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ASK);
85 }
86 };
87
88 TEST_F(PushMessagingPermissionContextTest, HasPermissionPrompt) {
89 PushMessagingPermissionContext context(&profile_);
90 EXPECT_EQ(CONTENT_SETTING_ASK,
91 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
92
93 // Just granting notifications should still prompt
94 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
95
96 EXPECT_EQ(CONTENT_SETTING_ASK,
97 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
98
99 // Just granting push should still prompt
100 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
101 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
102 CONTENT_SETTING_ALLOW);
103
104 EXPECT_EQ(CONTENT_SETTING_ASK,
105 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
106 }
107
108 TEST_F(PushMessagingPermissionContextTest, HasPermissionDeny) {
109 PushMessagingPermissionContext context(&profile_);
110 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK);
111 EXPECT_EQ(CONTENT_SETTING_BLOCK,
112 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
113 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
114 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
115 CONTENT_SETTING_BLOCK);
116 EXPECT_EQ(CONTENT_SETTING_BLOCK,
117 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
118 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
119 EXPECT_EQ(CONTENT_SETTING_BLOCK,
120 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
121
122 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ASK);
123 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
124 CONTENT_SETTING_BLOCK);
125 EXPECT_EQ(CONTENT_SETTING_BLOCK,
126 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
127 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
128 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
129 CONTENT_SETTING_BLOCK);
130 EXPECT_EQ(CONTENT_SETTING_BLOCK,
131 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
132 }
133
134 TEST_F(PushMessagingPermissionContextTest, HasPermissionAccept) {
135 PushMessagingPermissionContext context(&profile_);
136 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
137 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
138 CONTENT_SETTING_ALLOW);
139 EXPECT_EQ(CONTENT_SETTING_ALLOW,
140 context.GetPermissionStatus(GURL(kEmbedder), GURL(kEmbedder)));
141 }
142
143 TEST_F(PushMessagingPermissionContextTest, DecidePermission) {
144 TestPushMessagingPermissionContext context(&profile_);
145 PermissionRequestID request_id(-1, -1, -1, GURL(kEmbedder));
146 BrowserPermissionCallback callback;
147
148 context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
149 true, callback);
150 EXPECT_FALSE(context.was_persisted());
151 EXPECT_FALSE(context.was_granted());
152
153 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK);
154 context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
155 true, callback);
156 EXPECT_FALSE(context.was_persisted());
157 EXPECT_FALSE(context.was_granted());
158 SetContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
159 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
160 CONTENT_SETTING_BLOCK);
161 context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
162 true, callback);
163 EXPECT_FALSE(context.was_persisted());
164 EXPECT_FALSE(context.was_granted());
165 SetContentSetting(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, CONTENT_SETTING_ASK);
166 context.DecidePermission(NULL, request_id, GURL(kEmbedder), GURL(kEmbedder),
167 true, callback);
168 EXPECT_TRUE(context.was_persisted());
169 EXPECT_TRUE(context.was_granted());
170 }
171
172 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/push_messaging_permission_context.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698