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

Unified Diff: chrome/browser/notifications/desktop_notification_service_unittest.cc

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved encapsulation. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/desktop_notification_service_unittest.cc
diff --git a/chrome/browser/notifications/desktop_notification_service_unittest.cc b/chrome/browser/notifications/desktop_notification_service_unittest.cc
index 8351f5aefebfdcb23d2794135e838b383b71ece8..c52e03c1d418b9aeb4d3ebed9ed90381aa94e4cd 100644
--- a/chrome/browser/notifications/desktop_notification_service_unittest.cc
+++ b/chrome/browser/notifications/desktop_notification_service_unittest.cc
@@ -8,6 +8,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h"
+#include "base/test/simple_test_clock.h"
+#include "base/time/clock.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
@@ -63,3 +66,44 @@ TEST_F(DesktopNotificationServiceTest, GetNotificationsSettings) {
EXPECT_EQ(CONTENT_SETTING_ASK,
settings[4].setting);
}
+
+TEST_F(DesktopNotificationServiceTest, AuditLastUsage) {
+ GURL site("http://example.com");
+ base::SimpleTestClock test_clock_;
+ test_clock_.SetNow(base::Time::UnixEpoch() +
+ base::TimeDelta::FromSeconds(10));
+ profile()->GetHostContentSettingsMap()->SetPrefClockForTesting(&test_clock_);
+
+ // The permission shouldn't have been used yet.
+ EXPECT_EQ(profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(site),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 0);
+
+ service_->GrantPermission(site);
+
+ EXPECT_EQ(profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(site),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 10);
+
+ test_clock_.Advance(base::TimeDelta::FromSeconds(3));
+ service_->GrantPermission(site);
+
+ EXPECT_EQ(profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsageByPattern(
+ ContentSettingsPattern::FromURLNoWildcard(site),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 13);
+}

Powered by Google App Engine
This is Rietveld 408576698