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

Side by Side Diff: chrome/browser/notifications/notification_permission_context_unittest.cc

Issue 2686463002: Add a source to the result of PermissionContextBase::GetPermissionStatus (Closed)
Patch Set: Add a source to the result of PermissionContextBase::GetPermissionStatus Created 3 years, 10 months 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/notification_permission_context.h" 5 #include "chrome/browser/notifications/notification_permission_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 9 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 GURL requesting_origin("https://example.com"); 111 GURL requesting_origin("https://example.com");
112 GURL embedding_origin("https://chrome.com"); 112 GURL embedding_origin("https://chrome.com");
113 GURL different_origin("https://foobar.com"); 113 GURL different_origin("https://foobar.com");
114 114
115 NotificationPermissionContext context(profile(), 115 NotificationPermissionContext context(profile(),
116 content::PermissionType::NOTIFICATIONS); 116 content::PermissionType::NOTIFICATIONS);
117 UpdateContentSetting(&context, requesting_origin, embedding_origin, 117 UpdateContentSetting(&context, requesting_origin, embedding_origin,
118 CONTENT_SETTING_ALLOW); 118 CONTENT_SETTING_ALLOW);
119 119
120 EXPECT_EQ(CONTENT_SETTING_ALLOW, 120 EXPECT_EQ(CONTENT_SETTING_ALLOW,
121 context.GetPermissionStatus(requesting_origin, embedding_origin)); 121 context.GetPermissionStatus(requesting_origin, embedding_origin)
122 .content_setting);
122 123
123 EXPECT_EQ(CONTENT_SETTING_ALLOW, 124 EXPECT_EQ(CONTENT_SETTING_ALLOW,
124 context.GetPermissionStatus(requesting_origin, different_origin)); 125 context.GetPermissionStatus(requesting_origin, different_origin)
126 .content_setting);
125 127
126 context.ResetPermission(requesting_origin, embedding_origin); 128 context.ResetPermission(requesting_origin, embedding_origin);
127 129
128 EXPECT_EQ(CONTENT_SETTING_ASK, 130 EXPECT_EQ(CONTENT_SETTING_ASK,
129 context.GetPermissionStatus(requesting_origin, embedding_origin)); 131 context.GetPermissionStatus(requesting_origin, embedding_origin)
132 .content_setting);
130 133
131 EXPECT_EQ(CONTENT_SETTING_ASK, 134 EXPECT_EQ(CONTENT_SETTING_ASK,
132 context.GetPermissionStatus(requesting_origin, different_origin)); 135 context.GetPermissionStatus(requesting_origin, different_origin)
136 .content_setting);
133 } 137 }
134 138
135 // Push messaging permission requests should only succeed for top level origins 139 // Push messaging permission requests should only succeed for top level origins
136 // (embedding origin == requesting origin). 140 // (embedding origin == requesting origin).
137 TEST_F(NotificationPermissionContextTest, PushTopLevelOriginOnly) { 141 TEST_F(NotificationPermissionContextTest, PushTopLevelOriginOnly) {
138 GURL requesting_origin("https://example.com"); 142 GURL requesting_origin("https://example.com");
139 GURL embedding_origin("https://chrome.com"); 143 GURL embedding_origin("https://chrome.com");
140 144
141 NotificationPermissionContext context( 145 NotificationPermissionContext context(
142 profile(), content::PermissionType::PUSH_MESSAGING); 146 profile(), content::PermissionType::PUSH_MESSAGING);
143 UpdateContentSetting(&context, requesting_origin, embedding_origin, 147 UpdateContentSetting(&context, requesting_origin, embedding_origin,
144 CONTENT_SETTING_ALLOW); 148 CONTENT_SETTING_ALLOW);
145 149
146 EXPECT_EQ(CONTENT_SETTING_BLOCK, 150 EXPECT_EQ(CONTENT_SETTING_BLOCK,
147 context.GetPermissionStatus(requesting_origin, embedding_origin)); 151 context.GetPermissionStatus(requesting_origin, embedding_origin)
152 .content_setting);
148 153
149 context.ResetPermission(requesting_origin, embedding_origin); 154 context.ResetPermission(requesting_origin, embedding_origin);
150 155
151 UpdateContentSetting(&context, embedding_origin, embedding_origin, 156 UpdateContentSetting(&context, embedding_origin, embedding_origin,
152 CONTENT_SETTING_ALLOW); 157 CONTENT_SETTING_ALLOW);
153 158
154 EXPECT_EQ(CONTENT_SETTING_ALLOW, 159 EXPECT_EQ(CONTENT_SETTING_ALLOW,
155 context.GetPermissionStatus(embedding_origin, embedding_origin)); 160 context.GetPermissionStatus(embedding_origin, embedding_origin)
161 .content_setting);
156 162
157 context.ResetPermission(embedding_origin, embedding_origin); 163 context.ResetPermission(embedding_origin, embedding_origin);
158 164
159 EXPECT_EQ(CONTENT_SETTING_ASK, 165 EXPECT_EQ(CONTENT_SETTING_ASK,
160 context.GetPermissionStatus(embedding_origin, embedding_origin)); 166 context.GetPermissionStatus(embedding_origin, embedding_origin)
167 .content_setting);
161 } 168 }
162 169
163 // Web Notifications do not require a secure origin when requesting permission. 170 // Web Notifications do not require a secure origin when requesting permission.
164 // See https://crbug.com/404095. 171 // See https://crbug.com/404095.
165 TEST_F(NotificationPermissionContextTest, NoSecureOriginRequirement) { 172 TEST_F(NotificationPermissionContextTest, NoSecureOriginRequirement) {
166 GURL origin("http://example.com"); 173 GURL origin("http://example.com");
167 174
168 NotificationPermissionContext context(profile(), 175 NotificationPermissionContext context(profile(),
169 content::PermissionType::NOTIFICATIONS); 176 content::PermissionType::NOTIFICATIONS);
170 EXPECT_EQ(CONTENT_SETTING_ASK, 177 EXPECT_EQ(CONTENT_SETTING_ASK,
171 context.GetPermissionStatus(origin, origin)); 178 context.GetPermissionStatus(origin, origin).content_setting);
172 179
173 UpdateContentSetting(&context, origin, origin, CONTENT_SETTING_ALLOW); 180 UpdateContentSetting(&context, origin, origin, CONTENT_SETTING_ALLOW);
174 181
175 EXPECT_EQ(CONTENT_SETTING_ALLOW, 182 EXPECT_EQ(CONTENT_SETTING_ALLOW,
176 context.GetPermissionStatus(origin, origin)); 183 context.GetPermissionStatus(origin, origin).content_setting);
177 } 184 }
178 185
179 // Push notifications requires a secure origin to acquire permission. 186 // Push notifications requires a secure origin to acquire permission.
180 TEST_F(NotificationPermissionContextTest, PushSecureOriginRequirement) { 187 TEST_F(NotificationPermissionContextTest, PushSecureOriginRequirement) {
181 GURL origin("http://example.com"); 188 GURL origin("http://example.com");
182 GURL secure_origin("https://example.com"); 189 GURL secure_origin("https://example.com");
183 190
184 NotificationPermissionContext context( 191 NotificationPermissionContext context(
185 profile(), content::PermissionType::PUSH_MESSAGING); 192 profile(), content::PermissionType::PUSH_MESSAGING);
186 EXPECT_EQ(CONTENT_SETTING_BLOCK, context.GetPermissionStatus(origin, origin)); 193 EXPECT_EQ(CONTENT_SETTING_BLOCK,
194 context.GetPermissionStatus(origin, origin).content_setting);
187 195
188 UpdateContentSetting(&context, origin, origin, CONTENT_SETTING_ALLOW); 196 UpdateContentSetting(&context, origin, origin, CONTENT_SETTING_ALLOW);
189 197
190 EXPECT_EQ(CONTENT_SETTING_BLOCK, context.GetPermissionStatus(origin, origin)); 198 EXPECT_EQ(CONTENT_SETTING_BLOCK,
199 context.GetPermissionStatus(origin, origin).content_setting);
191 200
192 EXPECT_EQ(CONTENT_SETTING_ASK, 201 EXPECT_EQ(CONTENT_SETTING_ASK,
193 context.GetPermissionStatus(secure_origin, secure_origin)); 202 context.GetPermissionStatus(secure_origin, secure_origin)
203 .content_setting);
194 204
195 UpdateContentSetting(&context, secure_origin, secure_origin, 205 UpdateContentSetting(&context, secure_origin, secure_origin,
196 CONTENT_SETTING_ALLOW); 206 CONTENT_SETTING_ALLOW);
197 207
198 EXPECT_EQ(CONTENT_SETTING_ALLOW, 208 EXPECT_EQ(CONTENT_SETTING_ALLOW,
199 context.GetPermissionStatus(secure_origin, secure_origin)); 209 context.GetPermissionStatus(secure_origin, secure_origin)
210 .content_setting);
200 } 211 }
201 212
202 // Tests auto-denial after a time delay in incognito. 213 // Tests auto-denial after a time delay in incognito.
203 TEST_F(NotificationPermissionContextTest, TestDenyInIncognitoAfterDelay) { 214 TEST_F(NotificationPermissionContextTest, TestDenyInIncognitoAfterDelay) {
204 TestNotificationPermissionContext permission_context( 215 TestNotificationPermissionContext permission_context(
205 profile()->GetOffTheRecordProfile()); 216 profile()->GetOffTheRecordProfile());
206 GURL url("https://www.example.com"); 217 GURL url("https://www.example.com");
207 NavigateAndCommit(url); 218 NavigateAndCommit(url);
208 219
209 const PermissionRequestID id(web_contents()->GetRenderProcessHost()->GetID(), 220 const PermissionRequestID id(web_contents()->GetRenderProcessHost()->GetID(),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // After another 2.5 seconds, the second permission request should also have 361 // After another 2.5 seconds, the second permission request should also have
351 // received a response. 362 // received a response.
352 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); 363 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500));
353 EXPECT_EQ(2, permission_context.permission_set_count()); 364 EXPECT_EQ(2, permission_context.permission_set_count());
354 EXPECT_TRUE(permission_context.last_permission_set_persisted()); 365 EXPECT_TRUE(permission_context.last_permission_set_persisted());
355 EXPECT_EQ(CONTENT_SETTING_BLOCK, 366 EXPECT_EQ(CONTENT_SETTING_BLOCK,
356 permission_context.last_permission_set_setting()); 367 permission_context.last_permission_set_setting());
357 EXPECT_EQ(CONTENT_SETTING_BLOCK, 368 EXPECT_EQ(CONTENT_SETTING_BLOCK,
358 permission_context.GetContentSettingFromMap(url, url)); 369 permission_context.GetContentSettingFromMap(url, url));
359 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698