OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/simple_test_clock.h" |
| 12 #include "base/time/clock.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
11 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" | 18 #include "third_party/WebKit/public/web/WebNotificationPresenter.h" |
16 | 19 |
17 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { | 20 class DesktopNotificationServiceTest : public ChromeRenderViewHostTestHarness { |
18 protected: | 21 protected: |
19 virtual void SetUp() { | 22 virtual void SetUp() { |
20 ChromeRenderViewHostTestHarness::SetUp(); | 23 ChromeRenderViewHostTestHarness::SetUp(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( | 59 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard( |
57 GURL("http://denied2.com")), | 60 GURL("http://denied2.com")), |
58 settings[3].primary_pattern); | 61 settings[3].primary_pattern); |
59 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 62 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
60 settings[3].setting); | 63 settings[3].setting); |
61 EXPECT_EQ(ContentSettingsPattern::Wildcard(), | 64 EXPECT_EQ(ContentSettingsPattern::Wildcard(), |
62 settings[4].primary_pattern); | 65 settings[4].primary_pattern); |
63 EXPECT_EQ(CONTENT_SETTING_ASK, | 66 EXPECT_EQ(CONTENT_SETTING_ASK, |
64 settings[4].setting); | 67 settings[4].setting); |
65 } | 68 } |
| 69 |
| 70 TEST_F(DesktopNotificationServiceTest, AuditLastUsage) { |
| 71 GURL site("http://example.com"); |
| 72 base::SimpleTestClock test_clock_; |
| 73 test_clock_.SetNow(base::Time::UnixEpoch() + |
| 74 base::TimeDelta::FromSeconds(10)); |
| 75 profile()->GetHostContentSettingsMap()->SetPrefClockForTesting(&test_clock_); |
| 76 |
| 77 // The permission shouldn't have been used yet. |
| 78 EXPECT_EQ(profile() |
| 79 ->GetHostContentSettingsMap() |
| 80 ->GetLastUsageByPattern( |
| 81 ContentSettingsPattern::FromURLNoWildcard(site), |
| 82 ContentSettingsPattern::Wildcard(), |
| 83 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 84 .ToDoubleT(), |
| 85 0); |
| 86 |
| 87 service_->GrantPermission(site); |
| 88 |
| 89 EXPECT_EQ(profile() |
| 90 ->GetHostContentSettingsMap() |
| 91 ->GetLastUsageByPattern( |
| 92 ContentSettingsPattern::FromURLNoWildcard(site), |
| 93 ContentSettingsPattern::Wildcard(), |
| 94 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 95 .ToDoubleT(), |
| 96 10); |
| 97 |
| 98 test_clock_.Advance(base::TimeDelta::FromSeconds(3)); |
| 99 service_->GrantPermission(site); |
| 100 |
| 101 EXPECT_EQ(profile() |
| 102 ->GetHostContentSettingsMap() |
| 103 ->GetLastUsageByPattern( |
| 104 ContentSettingsPattern::FromURLNoWildcard(site), |
| 105 ContentSettingsPattern::Wildcard(), |
| 106 CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 107 .ToDoubleT(), |
| 108 13); |
| 109 } |
OLD | NEW |