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

Unified Diff: chrome/browser/content_settings/permission_context_base_unittest.cc

Issue 819463002: Implement RevokePermission() method in PermissionService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add crbug references Created 5 years, 11 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/content_settings/permission_context_base_unittest.cc
diff --git a/chrome/browser/content_settings/permission_context_base_unittest.cc b/chrome/browser/content_settings/permission_context_base_unittest.cc
index ab3a31d46fa7c5705908ad1ebe00fe021919bc09..b99bfa43abe06ce09058e92f9b3e53cb3954f623 100644
--- a/chrome/browser/content_settings/permission_context_base_unittest.cc
+++ b/chrome/browser/content_settings/permission_context_base_unittest.cc
@@ -121,7 +121,7 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
profile()->GetHostContentSettingsMap()->GetContentSetting(
url.GetOrigin(), url.GetOrigin(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
- EXPECT_EQ(CONTENT_SETTING_ALLOW , setting);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
}
void TestAskAndDismiss_TestContent() {
@@ -149,7 +149,7 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
profile()->GetHostContentSettingsMap()->GetContentSetting(
url.GetOrigin(), url.GetOrigin(),
CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string());
- EXPECT_EQ(CONTENT_SETTING_ASK , setting);
+ EXPECT_EQ(CONTENT_SETTING_ASK, setting);
}
void TestRequestPermissionInvalidUrl(ContentSettingsType type) {
@@ -178,6 +178,45 @@ class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
EXPECT_EQ(CONTENT_SETTING_ASK, setting);
}
+ void TestGrantAndRevoke_TestContent(ContentSettingsType type,
+ ContentSetting expected_default) {
+ TestPermissionContext permission_context(profile(), type);
+ GURL url("http://www.google.com");
+ content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
+
+ const PermissionRequestID id(
+ web_contents()->GetRenderProcessHost()->GetID(),
+ web_contents()->GetRenderViewHost()->GetRoutingID(),
+ -1, GURL());
+ permission_context.RequestPermission(
+ web_contents(),
+ id, url, true,
+ base::Bind(&TestPermissionContext::TrackPermissionDecision,
+ base::Unretained(&permission_context)));
+
+ RespondToPermission(&permission_context, id, url, true);
+ EXPECT_TRUE(permission_context.permission_set());
+ EXPECT_TRUE(permission_context.permission_granted());
+ EXPECT_TRUE(permission_context.tab_context_updated());
+
+ ContentSetting setting =
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ url.GetOrigin(), url.GetOrigin(),
+ type, std::string());
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
+
+ // Try to reset permission.
+ permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin());
+ ContentSetting setting_after_reset =
+ profile()->GetHostContentSettingsMap()->GetContentSetting(
+ url.GetOrigin(), url.GetOrigin(),
+ type, std::string());
+ ContentSetting default_setting =
+ profile()->GetHostContentSettingsMap()->GetDefaultContentSetting(
+ type, nullptr);
+ EXPECT_EQ(default_setting, setting_after_reset);
+ }
+
private:
// ChromeRenderViewHostTestHarness:
void SetUp() override {
@@ -217,3 +256,38 @@ TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) {
CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
#endif
}
+
+// Simulates granting and revoking of permissions.
+TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) {
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTING_ASK);
+ // TODO(timvolodine): notification permissions seem to work differently with
+ // infobars and bubbles (crbug.com/453784).
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
+ CONTENT_SETTING_ASK);
+ // TODO(timvolodine): infobars does not seem to implement push messaging
+ // permissions (crbug.com/453788).
+#if defined(OS_ANDROID)
+ TestGrantAndRevoke_TestContent(
+ CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
+#endif
+}
+
+// Simulates granting and revoking of permissions using permission bubbles.
+TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithBubbles) {
+ StartUsingPermissionBubble();
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTING_ASK);
+#if defined(ENABLE_NOTIFICATIONS)
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ CONTENT_SETTING_ASK);
+#endif
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
+ CONTENT_SETTING_ASK);
+ TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ CONTENT_SETTING_ASK);
+#if defined(OS_ANDROID)
Nico 2015/01/30 17:32:34 This is the same TODO as in the previous test, rig
timvolodine 2015/02/02 12:25:54 those todo's are for the infobar related tests, I'
+ TestGrantAndRevoke_TestContent(
+ CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
+#endif
+}
« no previous file with comments | « chrome/browser/content_settings/permission_context_base.cc ('k') | content/browser/permissions/permission_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698