| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 855 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 856 EXPECT_EQ("permission status - granted", script_result); | 856 EXPECT_EQ("permission status - granted", script_result); |
| 857 | 857 |
| 858 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 858 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 859 new content::MessageLoopRunner; | 859 new content::MessageLoopRunner; |
| 860 push_service()->SetContentSettingChangedCallbackForTesting( | 860 push_service()->SetContentSettingChangedCallbackForTesting( |
| 861 message_loop_runner->QuitClosure()); | 861 message_loop_runner->QuitClosure()); |
| 862 | 862 |
| 863 GURL origin = https_server()->GetURL("/").GetOrigin(); | 863 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 864 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 864 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 865 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 865 ->SetContentSettingDefaultScope(origin, origin, |
| 866 ContentSettingsPattern::FromURLNoWildcard(origin), | 866 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 867 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 867 std::string(), CONTENT_SETTING_DEFAULT); |
| 868 CONTENT_SETTING_DEFAULT); | |
| 869 | 868 |
| 870 message_loop_runner->Run(); | 869 message_loop_runner->Run(); |
| 871 | 870 |
| 872 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 871 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 873 EXPECT_EQ("permission status - prompt", script_result); | 872 EXPECT_EQ("permission status - prompt", script_result); |
| 874 | 873 |
| 875 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 874 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 876 EXPECT_EQ("false - not subscribed", script_result); | 875 EXPECT_EQ("false - not subscribed", script_result); |
| 877 } | 876 } |
| 878 | 877 |
| 879 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 878 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 880 DenyPushPermissionUnsubscribes) { | 879 DenyPushPermissionUnsubscribes) { |
| 881 std::string script_result; | 880 std::string script_result; |
| 882 | 881 |
| 883 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 882 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 884 | 883 |
| 885 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 884 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 886 EXPECT_EQ("true - subscribed", script_result); | 885 EXPECT_EQ("true - subscribed", script_result); |
| 887 | 886 |
| 888 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 887 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 889 EXPECT_EQ("permission status - granted", script_result); | 888 EXPECT_EQ("permission status - granted", script_result); |
| 890 | 889 |
| 891 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 890 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 892 new content::MessageLoopRunner; | 891 new content::MessageLoopRunner; |
| 893 push_service()->SetContentSettingChangedCallbackForTesting( | 892 push_service()->SetContentSettingChangedCallbackForTesting( |
| 894 message_loop_runner->QuitClosure()); | 893 message_loop_runner->QuitClosure()); |
| 895 | 894 |
| 896 GURL origin = https_server()->GetURL("/").GetOrigin(); | 895 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 897 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 896 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 898 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 897 ->SetContentSettingDefaultScope(origin, origin, |
| 899 ContentSettingsPattern::FromURLNoWildcard(origin), | 898 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 900 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 899 std::string(), CONTENT_SETTING_BLOCK); |
| 901 CONTENT_SETTING_BLOCK); | |
| 902 | 900 |
| 903 message_loop_runner->Run(); | 901 message_loop_runner->Run(); |
| 904 | 902 |
| 905 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 903 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 906 EXPECT_EQ("permission status - denied", script_result); | 904 EXPECT_EQ("permission status - denied", script_result); |
| 907 | 905 |
| 908 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 906 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 909 EXPECT_EQ("false - not subscribed", script_result); | 907 EXPECT_EQ("false - not subscribed", script_result); |
| 910 } | 908 } |
| 911 | 909 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 948 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 951 EXPECT_EQ("permission status - granted", script_result); | 949 EXPECT_EQ("permission status - granted", script_result); |
| 952 | 950 |
| 953 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 951 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 954 new content::MessageLoopRunner; | 952 new content::MessageLoopRunner; |
| 955 push_service()->SetContentSettingChangedCallbackForTesting( | 953 push_service()->SetContentSettingChangedCallbackForTesting( |
| 956 message_loop_runner->QuitClosure()); | 954 message_loop_runner->QuitClosure()); |
| 957 | 955 |
| 958 GURL origin = https_server()->GetURL("/").GetOrigin(); | 956 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 959 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 957 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 960 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 958 ->SetContentSettingDefaultScope(origin, GURL(), |
| 961 ContentSettingsPattern::Wildcard(), | 959 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 962 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 960 std::string(), CONTENT_SETTING_DEFAULT); |
| 963 CONTENT_SETTING_DEFAULT); | |
| 964 | 961 |
| 965 message_loop_runner->Run(); | 962 message_loop_runner->Run(); |
| 966 | 963 |
| 967 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 964 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 968 EXPECT_EQ("permission status - prompt", script_result); | 965 EXPECT_EQ("permission status - prompt", script_result); |
| 969 | 966 |
| 970 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 967 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 971 EXPECT_EQ("false - not subscribed", script_result); | 968 EXPECT_EQ("false - not subscribed", script_result); |
| 972 } | 969 } |
| 973 | 970 |
| 974 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 971 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 975 DenyNotificationsPermissionUnsubscribes) { | 972 DenyNotificationsPermissionUnsubscribes) { |
| 976 std::string script_result; | 973 std::string script_result; |
| 977 | 974 |
| 978 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 975 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 979 | 976 |
| 980 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 977 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 981 EXPECT_EQ("true - subscribed", script_result); | 978 EXPECT_EQ("true - subscribed", script_result); |
| 982 | 979 |
| 983 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 980 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 984 EXPECT_EQ("permission status - granted", script_result); | 981 EXPECT_EQ("permission status - granted", script_result); |
| 985 | 982 |
| 986 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 983 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 987 new content::MessageLoopRunner; | 984 new content::MessageLoopRunner; |
| 988 push_service()->SetContentSettingChangedCallbackForTesting( | 985 push_service()->SetContentSettingChangedCallbackForTesting( |
| 989 message_loop_runner->QuitClosure()); | 986 message_loop_runner->QuitClosure()); |
| 990 | 987 |
| 991 GURL origin = https_server()->GetURL("/").GetOrigin(); | 988 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 992 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 989 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 993 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 990 ->SetContentSettingDefaultScope(origin, GURL(), |
| 994 ContentSettingsPattern::Wildcard(), | 991 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 995 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 992 std::string(), CONTENT_SETTING_BLOCK); |
| 996 CONTENT_SETTING_BLOCK); | |
| 997 | 993 |
| 998 message_loop_runner->Run(); | 994 message_loop_runner->Run(); |
| 999 | 995 |
| 1000 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 996 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1001 EXPECT_EQ("permission status - denied", script_result); | 997 EXPECT_EQ("permission status - denied", script_result); |
| 1002 | 998 |
| 1003 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 999 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1004 EXPECT_EQ("false - not subscribed", script_result); | 1000 EXPECT_EQ("false - not subscribed", script_result); |
| 1005 } | 1001 } |
| 1006 | 1002 |
| 1007 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1003 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1008 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { | 1004 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { |
| 1009 std::string script_result; | 1005 std::string script_result; |
| 1010 | 1006 |
| 1011 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1007 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 1012 | 1008 |
| 1013 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1009 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1014 EXPECT_EQ("true - subscribed", script_result); | 1010 EXPECT_EQ("true - subscribed", script_result); |
| 1015 | 1011 |
| 1016 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1012 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1017 EXPECT_EQ("permission status - granted", script_result); | 1013 EXPECT_EQ("permission status - granted", script_result); |
| 1018 | 1014 |
| 1019 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1015 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1020 new content::MessageLoopRunner; | 1016 new content::MessageLoopRunner; |
| 1021 push_service()->SetContentSettingChangedCallbackForTesting( | 1017 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1022 base::BarrierClosure(2, message_loop_runner->QuitClosure())); | 1018 base::BarrierClosure(2, message_loop_runner->QuitClosure())); |
| 1023 | 1019 |
| 1024 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1020 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1025 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1021 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1026 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1022 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1027 ContentSettingsPattern::Wildcard(), | 1023 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1028 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1024 std::string(), CONTENT_SETTING_ALLOW); |
| 1029 CONTENT_SETTING_ALLOW); | |
| 1030 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1025 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1031 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1026 ->SetContentSettingDefaultScope(origin, origin, |
| 1032 ContentSettingsPattern::FromURLNoWildcard(origin), | 1027 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 1033 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1028 std::string(), CONTENT_SETTING_ALLOW); |
| 1034 CONTENT_SETTING_ALLOW); | |
| 1035 | 1029 |
| 1036 message_loop_runner->Run(); | 1030 message_loop_runner->Run(); |
| 1037 | 1031 |
| 1038 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1032 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1039 EXPECT_EQ("permission status - granted", script_result); | 1033 EXPECT_EQ("permission status - granted", script_result); |
| 1040 | 1034 |
| 1041 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1035 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1042 EXPECT_EQ("true - subscribed", script_result); | 1036 EXPECT_EQ("true - subscribed", script_result); |
| 1043 } | 1037 } |
| 1044 | 1038 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1068 ->SetContentSetting(ContentSettingsPattern::Wildcard(), | 1062 ->SetContentSetting(ContentSettingsPattern::Wildcard(), |
| 1069 ContentSettingsPattern::Wildcard(), | 1063 ContentSettingsPattern::Wildcard(), |
| 1070 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1064 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| 1071 CONTENT_SETTING_ALLOW); | 1065 CONTENT_SETTING_ALLOW); |
| 1072 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1066 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1073 ->SetContentSetting(ContentSettingsPattern::FromString("https://*"), | 1067 ->SetContentSetting(ContentSettingsPattern::FromString("https://*"), |
| 1074 ContentSettingsPattern::FromString("https://*"), | 1068 ContentSettingsPattern::FromString("https://*"), |
| 1075 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1069 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), |
| 1076 CONTENT_SETTING_ALLOW); | 1070 CONTENT_SETTING_ALLOW); |
| 1077 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1071 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1078 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1072 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1079 ContentSettingsPattern::Wildcard(), | 1073 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1080 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1074 std::string(), CONTENT_SETTING_DEFAULT); |
| 1081 CONTENT_SETTING_DEFAULT); | |
| 1082 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1075 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1083 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1076 ->SetContentSettingDefaultScope(origin, origin, |
| 1084 ContentSettingsPattern::FromURLNoWildcard(origin), | 1077 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 1085 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1078 std::string(), CONTENT_SETTING_DEFAULT); |
| 1086 CONTENT_SETTING_DEFAULT); | |
| 1087 | 1079 |
| 1088 message_loop_runner->Run(); | 1080 message_loop_runner->Run(); |
| 1089 | 1081 |
| 1090 // The two first rules should give |origin| the permission to use Push even | 1082 // The two first rules should give |origin| the permission to use Push even |
| 1091 // if the rules it used to have have been reset. | 1083 // if the rules it used to have have been reset. |
| 1092 // The Push service should not unsubcribe |origin| because at no point it was | 1084 // The Push service should not unsubcribe |origin| because at no point it was |
| 1093 // left without permission to use Push. | 1085 // left without permission to use Push. |
| 1094 | 1086 |
| 1095 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1087 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1096 EXPECT_EQ("permission status - granted", script_result); | 1088 EXPECT_EQ("permission status - granted", script_result); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1267 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1276 | 1268 |
| 1277 // After dropping the last subscription background mode is still inactive. | 1269 // After dropping the last subscription background mode is still inactive. |
| 1278 std::string script_result; | 1270 std::string script_result; |
| 1279 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1271 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1280 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1272 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1281 EXPECT_EQ("unsubscribe result: true", script_result); | 1273 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1282 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1274 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1283 } | 1275 } |
| 1284 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1276 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |