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

Unified Diff: chrome/browser/geolocation/geolocation_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/geolocation/geolocation_browsertest.cc
diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc
index 196f908310ea361922cf062845c9f8d23079d45d..3c3b738d70ddf0215f60fb419b03eecf15b164ea 100644
--- a/chrome/browser/geolocation/geolocation_browsertest.cc
+++ b/chrome/browser/geolocation/geolocation_browsertest.cc
@@ -8,6 +8,8 @@
#include "base/strings/string_number_conversions.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/chrome_notification_types.h"
#include "chrome/browser/content_settings/content_settings_usages_state.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
@@ -769,3 +771,48 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) {
current_browser()->tab_strip_model()->GetActiveWebContents(), script);
EXPECT_EQ(result, true);
}
+
+IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) {
+ ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
+ base::SimpleTestClock* clock_ = new base::SimpleTestClock();
Bernhard Bauer 2014/07/17 09:11:48 Same here.
+ current_browser()
+ ->profile()
+ ->GetHostContentSettingsMap()
+ ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_));
+ clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10));
+
+ // Setting the permission should trigger the last usage.
+ current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(current_url()),
+ ContentSettingsPattern::FromURLNoWildcard(current_url()),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ std::string(),
+ CONTENT_SETTING_ALLOW);
+
+ // Permission has been used at the starting time.
+ EXPECT_EQ(current_browser()
+ ->profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsage(current_url().GetOrigin(),
+ current_url().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ .ToDoubleT(),
+ 10);
+
+ clock_->Advance(base::TimeDelta::FromSeconds(3));
+
+ // Watching should trigger the last usage update.
+ SetFrameHost("");
+ AddGeolocationWatch(false);
+ CheckGeoposition(fake_latitude(), fake_longitude());
+
+ // Last usage has been updated.
+ EXPECT_EQ(current_browser()
+ ->profile()
+ ->GetHostContentSettingsMap()
+ ->GetLastUsage(current_url().GetOrigin(),
+ current_url().GetOrigin(),
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ .ToDoubleT(),
+ 13);
+}

Powered by Google App Engine
This is Rietveld 408576698