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

Unified Diff: chrome/browser/geolocation/geolocation_permission_context_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: Add auditing for actual usage, too. 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/geolocation/geolocation_permission_context_unittest.cc
diff --git a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
index f011ac355f98f91ab2ed5b8955d512c218fb18c4..733be274e92fa77027e01a588a883a89e9574ddd 100644
--- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc
@@ -13,6 +13,8 @@
#include "base/memory/scoped_vector.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
+#include "base/test/simple_test_clock.h"
+#include "base/time/clock.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/permission_request_id.h"
@@ -696,3 +698,54 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
// Delete the tab contents.
DeleteContents();
}
+
+TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
+ GURL requesting_frame("http://www.example.com/geolocation");
+ NavigateAndCommit(requesting_frame);
+
+ 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()
+ ->GetLastUsage(requesting_frame.GetOrigin(),
+ requesting_frame.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ .ToDoubleT(),
+ 0);
+
+ EXPECT_EQ(0U, infobar_service()->infobar_count());
+ RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+ ASSERT_EQ(1U, infobar_service()->infobar_count());
+ infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
+ ConfirmInfoBarDelegate* infobar_delegate =
+ infobar->delegate()->AsConfirmInfoBarDelegate();
+ ASSERT_TRUE(infobar_delegate);
+ infobar_delegate->Accept();
+ CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
+ CheckPermissionMessageSent(0, true);
+
+ // Permission has been used at the starting time.
+ EXPECT_EQ(profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsage(requesting_frame.GetOrigin(),
+ requesting_frame.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ .ToDoubleT(),
+ 10);
+
+ test_clock_.Advance(base::TimeDelta::FromSeconds(3));
+ RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
+
+ // Permission has been used three seconds later.
+ EXPECT_EQ(profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsage(requesting_frame.GetOrigin(),
+ requesting_frame.GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ .ToDoubleT(),
+ 13);
+}

Powered by Google App Engine
This is Rietveld 408576698