| 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 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 863 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 864 EXPECT_EQ("permission status - granted", script_result); | 864 EXPECT_EQ("permission status - granted", script_result); |
| 865 | 865 |
| 866 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 866 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 867 new content::MessageLoopRunner; | 867 new content::MessageLoopRunner; |
| 868 push_service()->SetContentSettingChangedCallbackForTesting( | 868 push_service()->SetContentSettingChangedCallbackForTesting( |
| 869 message_loop_runner->QuitClosure()); | 869 message_loop_runner->QuitClosure()); |
| 870 | 870 |
| 871 GURL origin = https_server()->GetURL("/").GetOrigin(); | 871 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 872 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 872 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 873 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 873 ->SetContentSettingDefaultScope(origin, origin, |
| 874 ContentSettingsPattern::FromURLNoWildcard(origin), | 874 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 875 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 875 std::string(), CONTENT_SETTING_DEFAULT); |
| 876 CONTENT_SETTING_DEFAULT); | |
| 877 | 876 |
| 878 message_loop_runner->Run(); | 877 message_loop_runner->Run(); |
| 879 | 878 |
| 880 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 879 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 881 EXPECT_EQ("permission status - prompt", script_result); | 880 EXPECT_EQ("permission status - prompt", script_result); |
| 882 | 881 |
| 883 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 882 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 884 EXPECT_EQ("false - not subscribed", script_result); | 883 EXPECT_EQ("false - not subscribed", script_result); |
| 885 } | 884 } |
| 886 | 885 |
| 887 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 886 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 888 DenyPushPermissionUnsubscribes) { | 887 DenyPushPermissionUnsubscribes) { |
| 889 std::string script_result; | 888 std::string script_result; |
| 890 | 889 |
| 891 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 890 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 892 | 891 |
| 893 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 892 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 894 EXPECT_EQ("true - subscribed", script_result); | 893 EXPECT_EQ("true - subscribed", script_result); |
| 895 | 894 |
| 896 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 895 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 897 EXPECT_EQ("permission status - granted", script_result); | 896 EXPECT_EQ("permission status - granted", script_result); |
| 898 | 897 |
| 899 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 898 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 900 new content::MessageLoopRunner; | 899 new content::MessageLoopRunner; |
| 901 push_service()->SetContentSettingChangedCallbackForTesting( | 900 push_service()->SetContentSettingChangedCallbackForTesting( |
| 902 message_loop_runner->QuitClosure()); | 901 message_loop_runner->QuitClosure()); |
| 903 | 902 |
| 904 GURL origin = https_server()->GetURL("/").GetOrigin(); | 903 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 905 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 904 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 906 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 905 ->SetContentSettingDefaultScope(origin, origin, |
| 907 ContentSettingsPattern::FromURLNoWildcard(origin), | 906 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 908 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 907 std::string(), CONTENT_SETTING_BLOCK); |
| 909 CONTENT_SETTING_BLOCK); | |
| 910 | 908 |
| 911 message_loop_runner->Run(); | 909 message_loop_runner->Run(); |
| 912 | 910 |
| 913 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 911 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 914 EXPECT_EQ("permission status - denied", script_result); | 912 EXPECT_EQ("permission status - denied", script_result); |
| 915 | 913 |
| 916 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 914 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 917 EXPECT_EQ("false - not subscribed", script_result); | 915 EXPECT_EQ("false - not subscribed", script_result); |
| 918 } | 916 } |
| 919 | 917 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 956 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 959 EXPECT_EQ("permission status - granted", script_result); | 957 EXPECT_EQ("permission status - granted", script_result); |
| 960 | 958 |
| 961 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 959 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 962 new content::MessageLoopRunner; | 960 new content::MessageLoopRunner; |
| 963 push_service()->SetContentSettingChangedCallbackForTesting( | 961 push_service()->SetContentSettingChangedCallbackForTesting( |
| 964 message_loop_runner->QuitClosure()); | 962 message_loop_runner->QuitClosure()); |
| 965 | 963 |
| 966 GURL origin = https_server()->GetURL("/").GetOrigin(); | 964 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 967 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 965 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 968 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 966 ->SetContentSettingDefaultScope(origin, GURL(), |
| 969 ContentSettingsPattern::Wildcard(), | 967 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 970 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 968 std::string(), CONTENT_SETTING_DEFAULT); |
| 971 CONTENT_SETTING_DEFAULT); | |
| 972 | 969 |
| 973 message_loop_runner->Run(); | 970 message_loop_runner->Run(); |
| 974 | 971 |
| 975 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 972 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 976 EXPECT_EQ("permission status - prompt", script_result); | 973 EXPECT_EQ("permission status - prompt", script_result); |
| 977 | 974 |
| 978 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 975 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 979 EXPECT_EQ("false - not subscribed", script_result); | 976 EXPECT_EQ("false - not subscribed", script_result); |
| 980 } | 977 } |
| 981 | 978 |
| 982 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 979 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 983 DenyNotificationsPermissionUnsubscribes) { | 980 DenyNotificationsPermissionUnsubscribes) { |
| 984 std::string script_result; | 981 std::string script_result; |
| 985 | 982 |
| 986 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 983 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 987 | 984 |
| 988 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 985 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 989 EXPECT_EQ("true - subscribed", script_result); | 986 EXPECT_EQ("true - subscribed", script_result); |
| 990 | 987 |
| 991 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 988 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 992 EXPECT_EQ("permission status - granted", script_result); | 989 EXPECT_EQ("permission status - granted", script_result); |
| 993 | 990 |
| 994 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 991 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 995 new content::MessageLoopRunner; | 992 new content::MessageLoopRunner; |
| 996 push_service()->SetContentSettingChangedCallbackForTesting( | 993 push_service()->SetContentSettingChangedCallbackForTesting( |
| 997 message_loop_runner->QuitClosure()); | 994 message_loop_runner->QuitClosure()); |
| 998 | 995 |
| 999 GURL origin = https_server()->GetURL("/").GetOrigin(); | 996 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1000 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 997 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1001 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 998 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1002 ContentSettingsPattern::Wildcard(), | 999 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1003 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1000 std::string(), CONTENT_SETTING_BLOCK); |
| 1004 CONTENT_SETTING_BLOCK); | |
| 1005 | 1001 |
| 1006 message_loop_runner->Run(); | 1002 message_loop_runner->Run(); |
| 1007 | 1003 |
| 1008 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1004 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1009 EXPECT_EQ("permission status - denied", script_result); | 1005 EXPECT_EQ("permission status - denied", script_result); |
| 1010 | 1006 |
| 1011 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1007 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1012 EXPECT_EQ("false - not subscribed", script_result); | 1008 EXPECT_EQ("false - not subscribed", script_result); |
| 1013 } | 1009 } |
| 1014 | 1010 |
| 1015 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1011 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1016 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { | 1012 GrantAlreadyGrantedPermissionDoesNotUnsubscribe) { |
| 1017 std::string script_result; | 1013 std::string script_result; |
| 1018 | 1014 |
| 1019 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1015 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 1020 | 1016 |
| 1021 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1017 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1022 EXPECT_EQ("true - subscribed", script_result); | 1018 EXPECT_EQ("true - subscribed", script_result); |
| 1023 | 1019 |
| 1024 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1020 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1025 EXPECT_EQ("permission status - granted", script_result); | 1021 EXPECT_EQ("permission status - granted", script_result); |
| 1026 | 1022 |
| 1027 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1023 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1028 new content::MessageLoopRunner; | 1024 new content::MessageLoopRunner; |
| 1029 push_service()->SetContentSettingChangedCallbackForTesting( | 1025 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1030 base::BarrierClosure(2, message_loop_runner->QuitClosure())); | 1026 base::BarrierClosure(2, message_loop_runner->QuitClosure())); |
| 1031 | 1027 |
| 1032 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1028 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1033 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1029 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1034 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1030 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1035 ContentSettingsPattern::Wildcard(), | 1031 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1036 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1032 std::string(), CONTENT_SETTING_ALLOW); |
| 1037 CONTENT_SETTING_ALLOW); | |
| 1038 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1033 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1039 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1034 ->SetContentSettingDefaultScope(origin, origin, |
| 1040 ContentSettingsPattern::FromURLNoWildcard(origin), | 1035 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 1041 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1036 std::string(), CONTENT_SETTING_ALLOW); |
| 1042 CONTENT_SETTING_ALLOW); | |
| 1043 | 1037 |
| 1044 message_loop_runner->Run(); | 1038 message_loop_runner->Run(); |
| 1045 | 1039 |
| 1046 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1040 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1047 EXPECT_EQ("permission status - granted", script_result); | 1041 EXPECT_EQ("permission status - granted", script_result); |
| 1048 | 1042 |
| 1049 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1043 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1050 EXPECT_EQ("true - subscribed", script_result); | 1044 EXPECT_EQ("true - subscribed", script_result); |
| 1051 } | 1045 } |
| 1052 | 1046 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1066 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1060 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1067 EXPECT_EQ("permission status - granted", script_result); | 1061 EXPECT_EQ("permission status - granted", script_result); |
| 1068 | 1062 |
| 1069 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1063 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1070 new content::MessageLoopRunner; | 1064 new content::MessageLoopRunner; |
| 1071 push_service()->SetContentSettingChangedCallbackForTesting( | 1065 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1072 base::BarrierClosure(4, message_loop_runner->QuitClosure())); | 1066 base::BarrierClosure(4, message_loop_runner->QuitClosure())); |
| 1073 | 1067 |
| 1074 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1068 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1075 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1069 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1076 ->SetContentSetting(ContentSettingsPattern::Wildcard(), | 1070 ->SetContentSettingCustomScope(ContentSettingsPattern::Wildcard(), |
| 1077 ContentSettingsPattern::Wildcard(), | 1071 ContentSettingsPattern::Wildcard(), |
| 1078 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1072 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1079 CONTENT_SETTING_ALLOW); | 1073 std::string(), CONTENT_SETTING_ALLOW); |
| 1080 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1074 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1081 ->SetContentSetting(ContentSettingsPattern::FromString("https://*"), | 1075 ->SetContentSettingCustomScope( |
| 1082 ContentSettingsPattern::FromString("https://*"), | 1076 ContentSettingsPattern::FromString("https://*"), |
| 1083 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1077 ContentSettingsPattern::FromString("https://*"), |
| 1084 CONTENT_SETTING_ALLOW); | 1078 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), |
| 1079 CONTENT_SETTING_ALLOW); |
| 1085 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1080 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1086 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1081 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1087 ContentSettingsPattern::Wildcard(), | 1082 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1088 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), | 1083 std::string(), CONTENT_SETTING_DEFAULT); |
| 1089 CONTENT_SETTING_DEFAULT); | |
| 1090 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1084 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1091 ->SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(origin), | 1085 ->SetContentSettingDefaultScope(origin, origin, |
| 1092 ContentSettingsPattern::FromURLNoWildcard(origin), | 1086 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 1093 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | 1087 std::string(), CONTENT_SETTING_DEFAULT); |
| 1094 CONTENT_SETTING_DEFAULT); | |
| 1095 | 1088 |
| 1096 message_loop_runner->Run(); | 1089 message_loop_runner->Run(); |
| 1097 | 1090 |
| 1098 // The two first rules should give |origin| the permission to use Push even | 1091 // The two first rules should give |origin| the permission to use Push even |
| 1099 // if the rules it used to have have been reset. | 1092 // if the rules it used to have have been reset. |
| 1100 // The Push service should not unsubcribe |origin| because at no point it was | 1093 // The Push service should not unsubcribe |origin| because at no point it was |
| 1101 // left without permission to use Push. | 1094 // left without permission to use Push. |
| 1102 | 1095 |
| 1103 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1096 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1104 EXPECT_EQ("permission status - granted", script_result); | 1097 EXPECT_EQ("permission status - granted", script_result); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1276 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1284 | 1277 |
| 1285 // After dropping the last subscription background mode is still inactive. | 1278 // After dropping the last subscription background mode is still inactive. |
| 1286 std::string script_result; | 1279 std::string script_result; |
| 1287 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1280 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1288 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1281 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1289 EXPECT_EQ("unsubscribe result: true", script_result); | 1282 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1290 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1283 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1291 } | 1284 } |
| 1292 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1285 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |