Chromium Code Reviews| 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/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 EXPECT_EQ(1, permission_context.permission_set_count()); | 182 EXPECT_EQ(1, permission_context.permission_set_count()); |
| 183 EXPECT_TRUE(permission_context.last_permission_set_persisted()); | 183 EXPECT_TRUE(permission_context.last_permission_set_persisted()); |
| 184 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 184 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 185 permission_context.last_permission_set_setting()); | 185 permission_context.last_permission_set_setting()); |
| 186 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 186 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 187 permission_context.GetContentSettingFromMap(url, url)); | 187 permission_context.GetContentSettingFromMap(url, url)); |
| 188 | 188 |
| 189 base::MessageLoop::current()->SetTaskRunner(old_task_runner); | 189 base::MessageLoop::current()->SetTaskRunner(old_task_runner); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Tests that navigating cancels incognito permission requests without crashing. | |
| 193 TEST_F(NotificationPermissionContextTest, TestCancelledIncognitoRequest) { | |
| 194 TestNotificationPermissionContext permission_context( | |
| 195 profile()->GetOffTheRecordProfile()); | |
| 196 GURL url("https://www.example.com"); | |
| 197 NavigateAndCommit(url); | |
| 198 | |
| 199 const PermissionRequestID id(web_contents()->GetRenderProcessHost()->GetID(), | |
| 200 web_contents()->GetMainFrame()->GetRoutingID(), | |
| 201 -1); | |
| 202 | |
| 203 scoped_refptr<base::SingleThreadTaskRunner> old_task_runner( | |
|
Peter Beverloo
2016/02/16 15:28:28
The TestMockTimeTaskRunner is now being instantiat
johnme
2016/02/16 18:14:34
Done.
| |
| 204 base::MessageLoop::current()->task_runner()); | |
| 205 scoped_refptr<base::TestMockTimeTaskRunner> task_runner( | |
| 206 new base::TestMockTimeTaskRunner(base::Time::Now(), | |
| 207 base::TimeTicks::Now())); | |
| 208 base::MessageLoop::current()->SetTaskRunner(task_runner); | |
| 209 | |
| 210 permission_context.RequestPermission( | |
| 211 web_contents(), id, url, true /* user_gesture */, base::Bind(&DoNothing)); | |
| 212 | |
| 213 permission_context.CancelPermissionRequest(web_contents(), id); | |
| 214 | |
| 215 task_runner->FastForwardBy(base::TimeDelta::FromDays(1)); | |
| 216 | |
| 217 EXPECT_EQ(0, permission_context.permission_set_count()); | |
| 218 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 219 permission_context.GetContentSettingFromMap(url, url)); | |
| 220 | |
| 221 base::MessageLoop::current()->SetTaskRunner(old_task_runner); | |
| 222 } | |
| 223 | |
| 192 // Tests how multiple parallel permission requests get auto-denied in incognito. | 224 // Tests how multiple parallel permission requests get auto-denied in incognito. |
| 193 TEST_F(NotificationPermissionContextTest, TestParallelDenyInIncognito) { | 225 TEST_F(NotificationPermissionContextTest, TestParallelDenyInIncognito) { |
| 194 TestNotificationPermissionContext permission_context( | 226 TestNotificationPermissionContext permission_context( |
| 195 profile()->GetOffTheRecordProfile()); | 227 profile()->GetOffTheRecordProfile()); |
| 196 GURL url("https://www.example.com"); | 228 GURL url("https://www.example.com"); |
| 197 NavigateAndCommit(url); | 229 NavigateAndCommit(url); |
| 198 web_contents()->WasShown(); | 230 web_contents()->WasShown(); |
| 199 | 231 |
| 200 const PermissionRequestID id0(web_contents()->GetRenderProcessHost()->GetID(), | 232 const PermissionRequestID id0(web_contents()->GetRenderProcessHost()->GetID(), |
| 201 web_contents()->GetMainFrame()->GetRoutingID(), | 233 web_contents()->GetMainFrame()->GetRoutingID(), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); | 280 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); |
| 249 EXPECT_EQ(2, permission_context.permission_set_count()); | 281 EXPECT_EQ(2, permission_context.permission_set_count()); |
| 250 EXPECT_TRUE(permission_context.last_permission_set_persisted()); | 282 EXPECT_TRUE(permission_context.last_permission_set_persisted()); |
| 251 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 283 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 252 permission_context.last_permission_set_setting()); | 284 permission_context.last_permission_set_setting()); |
| 253 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 285 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 254 permission_context.GetContentSettingFromMap(url, url)); | 286 permission_context.GetContentSettingFromMap(url, url)); |
| 255 | 287 |
| 256 base::MessageLoop::current()->SetTaskRunner(old_task_runner); | 288 base::MessageLoop::current()->SetTaskRunner(old_task_runner); |
| 257 } | 289 } |
| OLD | NEW |