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

Unified Diff: chrome/browser/notifications/notification_browsertest.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: Jam nits. Created 6 years, 5 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/notification_browsertest.cc
diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc
index af06140d92d68968295cc665c21f0d6e263ced15..cacc5e81701375d08e8cc098bfed152074dc07d8 100644
--- a/chrome/browser/notifications/notification_browsertest.cc
+++ b/chrome/browser/notifications/notification_browsertest.cc
@@ -13,8 +13,11 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/simple_test_clock.h"
+#include "base/time/clock.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
@@ -778,3 +781,37 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, MAYBE_TestNotificationReplacement) {
EXPECT_EQ(base::ASCIIToUTF16("Body2"),
(*notifications.rbegin())->message());
}
+
+IN_PROC_BROWSER_TEST_F(NotificationsTest, TestLastUsage) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ HostContentSettingsMap* settings_map =
+ browser()->profile()->GetHostContentSettingsMap();
+ base::SimpleTestClock* clock = new base::SimpleTestClock();
+ settings_map->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock));
+ clock->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10));
+
+ // Creates a simple notification.
+ AllowAllOrigins();
+ ui_test_utils::NavigateToURL(browser(), GetTestPageURL());
+
+ std::string result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
+ GetTestPageURL().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 10);
+
+ clock->Advance(base::TimeDelta::FromSeconds(3));
+
+ result = CreateSimpleNotification(browser(), true);
+ EXPECT_NE("-1", result);
+
+ EXPECT_EQ(settings_map->GetLastUsage(GetTestPageURL().GetOrigin(),
+ GetTestPageURL().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS)
+ .ToDoubleT(),
+ 13);
+}

Powered by Google App Engine
This is Rietveld 408576698