Chromium Code Reviews| 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..3d3ea174d58c72e580271ab7b83194064a6b2899 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(); |
| + 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 servire should not unsubcribe |origin| because at no point it was |
|
johnme
2015/02/16 20:27:44
servire -> service
mlamouri (slow - plz ping)
2015/02/16 20:46:03
Done.
|
| + // 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 |