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

Unified Diff: chrome/browser/permissions/permission_util_unittest.cc

Issue 1803973002: Content Settings: Add RevocationObserver to measure when permissions are revoked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrite patch in permissions layer Created 4 years, 9 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/permissions/permission_util_unittest.cc
diff --git a/chrome/browser/permissions/permission_util_unittest.cc b/chrome/browser/permissions/permission_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d54fb2d37785b0b226896f9143b390a68aa3db6f
--- /dev/null
+++ b/chrome/browser/permissions/permission_util_unittest.cc
@@ -0,0 +1,42 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
+#include "chrome/browser/permissions/permission_util.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class PermissionUtilTest : public testing::Test {
+ content::TestBrowserThreadBundle thread_bundle_;
+};
+
+TEST_F(PermissionUtilTest, SetContentSettingRecordRevocation) {
+ TestingProfile profile;
+ HostContentSettingsMap* map =
+ HostContentSettingsMapFactory::GetForProfile(&profile);
+ GURL host("https://example.com");
+ ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION;
+
+ // Allow->Block triggers a revocation.
+ map->SetContentSettingDefaultScope(host, host, type, "",
Bernhard Bauer 2016/03/22 10:13:30 Nit: Use an empty std::string() constructor instea
tsergeant 2016/03/22 23:55:20 Done.
+ CONTENT_SETTING_ALLOW);
+ EXPECT_TRUE(PermissionUtil::SetContentSettingRecordRevocation(
Bernhard Bauer 2016/03/22 10:13:29 If the return value is only used for tests, it mig
tsergeant 2016/03/22 23:55:20 Done. I don't want to get too deep into testing th
+ &profile, host, host, type, "", CONTENT_SETTING_BLOCK));
+
+ // Block->Allow does not trigger a revocation.
+ EXPECT_FALSE(PermissionUtil::SetContentSettingRecordRevocation(
+ &profile, host, host, type, "", CONTENT_SETTING_ALLOW));
+
+ // Allow->Default triggers a revocation when default is 'ask'.
+ map->SetDefaultContentSetting(type, CONTENT_SETTING_ASK);
+ EXPECT_TRUE(PermissionUtil::SetContentSettingRecordRevocation(
+ &profile, host, host, type, "", CONTENT_SETTING_DEFAULT));
+
+ // Allow->Default does not trigger a revocation when default is 'allow'.
+ map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW);
+ EXPECT_FALSE(PermissionUtil::SetContentSettingRecordRevocation(
+ &profile, host, host, type, "", CONTENT_SETTING_DEFAULT));
+}

Powered by Google App Engine
This is Rietveld 408576698