OLD | NEW |
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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/test/test_mock_time_task_runner.h" | 9 #include "base/test/test_mock_time_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 -1); | 155 -1); |
156 | 156 |
157 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(SwitchToMockTime()); | 157 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(SwitchToMockTime()); |
158 | 158 |
159 ASSERT_EQ(0, permission_context.permission_set_count()); | 159 ASSERT_EQ(0, permission_context.permission_set_count()); |
160 ASSERT_FALSE(permission_context.last_permission_set_persisted()); | 160 ASSERT_FALSE(permission_context.last_permission_set_persisted()); |
161 ASSERT_EQ(CONTENT_SETTING_DEFAULT, | 161 ASSERT_EQ(CONTENT_SETTING_DEFAULT, |
162 permission_context.last_permission_set_setting()); | 162 permission_context.last_permission_set_setting()); |
163 | 163 |
164 permission_context.RequestPermission( | 164 permission_context.RequestPermission( |
165 web_contents(), id, url, base::Bind(&DoNothing)); | 165 web_contents(), id, url, true /* user_gesture */, base::Bind(&DoNothing)); |
166 | 166 |
167 // Should be blocked after 1-2 seconds, but the timer is reset whenever the | 167 // Should be blocked after 1-2 seconds, but the timer is reset whenever the |
168 // tab is not visible, so these 500ms never add up to >= 1 second. | 168 // tab is not visible, so these 500ms never add up to >= 1 second. |
169 for (int n = 0; n < 10; n++) { | 169 for (int n = 0; n < 10; n++) { |
170 web_contents()->WasShown(); | 170 web_contents()->WasShown(); |
171 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(500)); | 171 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(500)); |
172 web_contents()->WasHidden(); | 172 web_contents()->WasHidden(); |
173 } | 173 } |
174 | 174 |
175 EXPECT_EQ(0, permission_context.permission_set_count()); | 175 EXPECT_EQ(0, permission_context.permission_set_count()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 content::PermissionManager* permission_manager = | 225 content::PermissionManager* permission_manager = |
226 PermissionManagerFactory::GetForProfile( | 226 PermissionManagerFactory::GetForProfile( |
227 profile()->GetOffTheRecordProfile()); | 227 profile()->GetOffTheRecordProfile()); |
228 | 228 |
229 // Request and cancel the permission via PermissionManager. That way if | 229 // Request and cancel the permission via PermissionManager. That way if |
230 // https://crbug.com/586944 regresses, then as well as the EXPECT_EQs below | 230 // https://crbug.com/586944 regresses, then as well as the EXPECT_EQs below |
231 // failing, PermissionManager::OnPermissionsRequestResponseStatus will crash. | 231 // failing, PermissionManager::OnPermissionsRequestResponseStatus will crash. |
232 int request_id = permission_manager->RequestPermission( | 232 int request_id = permission_manager->RequestPermission( |
233 content::PermissionType::NOTIFICATIONS, web_contents()->GetMainFrame(), | 233 content::PermissionType::NOTIFICATIONS, web_contents()->GetMainFrame(), |
234 url.GetOrigin(), base::Bind(&DoNothing2)); | 234 url.GetOrigin(), true /* user_gesture */, base::Bind(&DoNothing2)); |
235 | 235 |
236 permission_manager->CancelPermissionRequest(request_id); | 236 permission_manager->CancelPermissionRequest(request_id); |
237 | 237 |
238 task_runner->FastForwardBy(base::TimeDelta::FromDays(1)); | 238 task_runner->FastForwardBy(base::TimeDelta::FromDays(1)); |
239 | 239 |
240 EXPECT_EQ(0, permission_context.permission_set_count()); | 240 EXPECT_EQ(0, permission_context.permission_set_count()); |
241 EXPECT_EQ(CONTENT_SETTING_ASK, | 241 EXPECT_EQ(CONTENT_SETTING_ASK, |
242 permission_context.GetContentSettingFromMap(url, url)); | 242 permission_context.GetContentSettingFromMap(url, url)); |
243 } | 243 } |
244 | 244 |
(...skipping 13 matching lines...) Expand all Loading... |
258 1); | 258 1); |
259 | 259 |
260 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(SwitchToMockTime()); | 260 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(SwitchToMockTime()); |
261 | 261 |
262 ASSERT_EQ(0, permission_context.permission_set_count()); | 262 ASSERT_EQ(0, permission_context.permission_set_count()); |
263 ASSERT_FALSE(permission_context.last_permission_set_persisted()); | 263 ASSERT_FALSE(permission_context.last_permission_set_persisted()); |
264 ASSERT_EQ(CONTENT_SETTING_DEFAULT, | 264 ASSERT_EQ(CONTENT_SETTING_DEFAULT, |
265 permission_context.last_permission_set_setting()); | 265 permission_context.last_permission_set_setting()); |
266 | 266 |
267 permission_context.RequestPermission(web_contents(), id0, url, | 267 permission_context.RequestPermission(web_contents(), id0, url, |
| 268 true /* user_gesture */, |
268 base::Bind(&DoNothing)); | 269 base::Bind(&DoNothing)); |
269 permission_context.RequestPermission(web_contents(), id1, url, | 270 permission_context.RequestPermission(web_contents(), id1, url, |
| 271 true /* user_gesture */, |
270 base::Bind(&DoNothing)); | 272 base::Bind(&DoNothing)); |
271 | 273 |
272 EXPECT_EQ(0, permission_context.permission_set_count()); | 274 EXPECT_EQ(0, permission_context.permission_set_count()); |
273 EXPECT_EQ(CONTENT_SETTING_ASK, | 275 EXPECT_EQ(CONTENT_SETTING_ASK, |
274 permission_context.GetContentSettingFromMap(url, url)); | 276 permission_context.GetContentSettingFromMap(url, url)); |
275 | 277 |
276 // Fast forward up to 2.5 seconds. Stop as soon as the first permission | 278 // Fast forward up to 2.5 seconds. Stop as soon as the first permission |
277 // request is auto-denied. | 279 // request is auto-denied. |
278 for (int n = 0; n < 5; n++) { | 280 for (int n = 0; n < 5; n++) { |
279 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(500)); | 281 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(500)); |
(...skipping 12 matching lines...) Expand all Loading... |
292 // After another 2.5 seconds, the second permission request should also have | 294 // After another 2.5 seconds, the second permission request should also have |
293 // received a response. | 295 // received a response. |
294 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); | 296 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); |
295 EXPECT_EQ(2, permission_context.permission_set_count()); | 297 EXPECT_EQ(2, permission_context.permission_set_count()); |
296 EXPECT_TRUE(permission_context.last_permission_set_persisted()); | 298 EXPECT_TRUE(permission_context.last_permission_set_persisted()); |
297 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 299 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
298 permission_context.last_permission_set_setting()); | 300 permission_context.last_permission_set_setting()); |
299 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 301 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
300 permission_context.GetContentSettingFromMap(url, url)); | 302 permission_context.GetContentSettingFromMap(url, url)); |
301 } | 303 } |
OLD | NEW |