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

Unified Diff: chrome/browser/services/gcm/push_messaging_browsertest.cc

Issue 930083002: Unregister with push service and SW database when permission is lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add copy ctor Created 5 years, 10 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/services/gcm/push_messaging_browsertest.cc
diff --git a/chrome/browser/services/gcm/push_messaging_browsertest.cc b/chrome/browser/services/gcm/push_messaging_browsertest.cc
index 842d9053ac6863215cb10817e51aa6f6c021a590..45445362aecde37f06c3ab4cf582d3a89e93af04 100644
--- a/chrome/browser/services/gcm/push_messaging_browsertest.cc
+++ b/chrome/browser/services/gcm/push_messaging_browsertest.cc
@@ -22,6 +22,7 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/gcm_driver/gcm_client.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
@@ -655,4 +656,243 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterUnknownError) {
" push server.", script_result);
}
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ GlobalResetPushPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ browser()->profile()->GetHostContentSettingsMap()->
+ ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - default", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ LocalResetPushPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ std::string(),
+ CONTENT_SETTING_DEFAULT);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - default", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ DenyPushPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
Bernhard Bauer 2015/02/16 22:41:05 Use an empty std::string() constructor instead of
mlamouri (slow - plz ping) 2015/02/16 23:34:35 Done.
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ std::string(),
+ CONTENT_SETTING_BLOCK);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - denied", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ GlobalResetNotificationsPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ browser()->profile()->GetHostContentSettingsMap()->
+ ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - default", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ LocalResetNotificationsPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ std::string(),
+ CONTENT_SETTING_DEFAULT);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - default", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ DenyNotificationsPermissionUnregisters) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ std::string(),
+ CONTENT_SETTING_BLOCK);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - denied", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("false - not registered", script_result);
+}
+
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ GrantAlreadyGrantedPermissionDoesNotUnregister) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ std::string(),
+ CONTENT_SETTING_ALLOW);
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ std::string(),
+ CONTENT_SETTING_ALLOW);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+}
+
+// This test is testing some non-trivial content settings rules and make sure
+// that they are respected with regards to automatic unregistration. In other
+// words, it checks that the push service does not end up unregistering origins
+// that have push permission with some non-common rules.
+IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
+ AutomaticUnregistrationFollowsContentSettingRules) {
+ std::string script_result;
+
+ TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ GURL origin = https_server()->GetURL("").GetOrigin();
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ std::string(),
+ CONTENT_SETTING_ALLOW);
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromString("https://*"),
+ ContentSettingsPattern::FromString("https://*"),
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ std::string(),
+ CONTENT_SETTING_ALLOW);
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ std::string(),
+ CONTENT_SETTING_DEFAULT);
+ browser()->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
+ std::string(),
+ CONTENT_SETTING_DEFAULT);
+
+ // The two first rules should give |origin| the permission to use Push even
+ // if the rules it used to have have been reset.
+ // The Push service should not unsubcribe |origin| because at no point it was
+ // left without permission to use Push.
+
+ ASSERT_TRUE(RunScript("hasPermission()", &script_result));
+ EXPECT_EQ("permission status - granted", script_result);
+
+ ASSERT_TRUE(RunScript("hasRegistration()", &script_result));
+ EXPECT_EQ("true - registered", script_result);
+}
+
} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698