| 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 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 | 1146 |
| 1147 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1147 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1148 EXPECT_EQ("permission status - granted", script_result); | 1148 EXPECT_EQ("permission status - granted", script_result); |
| 1149 | 1149 |
| 1150 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1150 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1151 new content::MessageLoopRunner; | 1151 new content::MessageLoopRunner; |
| 1152 push_service()->SetContentSettingChangedCallbackForTesting( | 1152 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1153 message_loop_runner->QuitClosure()); | 1153 message_loop_runner->QuitClosure()); |
| 1154 | 1154 |
| 1155 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1155 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1156 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | |
| 1157 | |
| 1158 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1159 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1156 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1160 | 1157 |
| 1161 message_loop_runner->Run(); | 1158 message_loop_runner->Run(); |
| 1162 | 1159 |
| 1163 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1160 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1164 EXPECT_EQ("permission status - prompt", script_result); | 1161 EXPECT_EQ("permission status - prompt", script_result); |
| 1165 | 1162 |
| 1166 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1163 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1167 EXPECT_EQ("false - not subscribed", script_result); | 1164 EXPECT_EQ("false - not subscribed", script_result); |
| 1168 } | 1165 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1180 EXPECT_EQ("permission status - granted", script_result); | 1177 EXPECT_EQ("permission status - granted", script_result); |
| 1181 | 1178 |
| 1182 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1179 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1183 new content::MessageLoopRunner; | 1180 new content::MessageLoopRunner; |
| 1184 push_service()->SetContentSettingChangedCallbackForTesting( | 1181 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1185 message_loop_runner->QuitClosure()); | 1182 message_loop_runner->QuitClosure()); |
| 1186 | 1183 |
| 1187 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1184 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1188 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1185 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1189 ->SetContentSettingDefaultScope(origin, origin, | 1186 ->SetContentSettingDefaultScope(origin, origin, |
| 1190 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
| 1191 std::string(), CONTENT_SETTING_DEFAULT); | |
| 1192 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1193 ->SetContentSettingDefaultScope(origin, origin, | |
| 1194 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1187 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1195 std::string(), CONTENT_SETTING_DEFAULT); | 1188 std::string(), CONTENT_SETTING_DEFAULT); |
| 1196 | 1189 |
| 1197 message_loop_runner->Run(); | 1190 message_loop_runner->Run(); |
| 1198 | 1191 |
| 1199 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1192 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1200 EXPECT_EQ("permission status - prompt", script_result); | 1193 EXPECT_EQ("permission status - prompt", script_result); |
| 1201 | 1194 |
| 1202 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1195 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1203 EXPECT_EQ("false - not subscribed", script_result); | 1196 EXPECT_EQ("false - not subscribed", script_result); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1216 EXPECT_EQ("permission status - granted", script_result); | 1209 EXPECT_EQ("permission status - granted", script_result); |
| 1217 | 1210 |
| 1218 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1211 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1219 new content::MessageLoopRunner; | 1212 new content::MessageLoopRunner; |
| 1220 push_service()->SetContentSettingChangedCallbackForTesting( | 1213 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1221 message_loop_runner->QuitClosure()); | 1214 message_loop_runner->QuitClosure()); |
| 1222 | 1215 |
| 1223 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1216 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1224 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1217 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1225 ->SetContentSettingDefaultScope(origin, origin, | 1218 ->SetContentSettingDefaultScope(origin, origin, |
| 1226 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 1219 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1227 std::string(), CONTENT_SETTING_BLOCK); | 1220 std::string(), CONTENT_SETTING_BLOCK); |
| 1228 | 1221 |
| 1229 message_loop_runner->Run(); | 1222 message_loop_runner->Run(); |
| 1230 | 1223 |
| 1231 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1224 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1232 EXPECT_EQ("permission status - denied", script_result); | 1225 EXPECT_EQ("permission status - denied", script_result); |
| 1233 | 1226 |
| 1234 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1227 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1235 EXPECT_EQ("false - not subscribed", script_result); | 1228 EXPECT_EQ("false - not subscribed", script_result); |
| 1236 } | 1229 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 | 1329 |
| 1337 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1330 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1338 EXPECT_EQ("true - subscribed", script_result); | 1331 EXPECT_EQ("true - subscribed", script_result); |
| 1339 | 1332 |
| 1340 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1333 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1341 EXPECT_EQ("permission status - granted", script_result); | 1334 EXPECT_EQ("permission status - granted", script_result); |
| 1342 | 1335 |
| 1343 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1336 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1344 new content::MessageLoopRunner; | 1337 new content::MessageLoopRunner; |
| 1345 push_service()->SetContentSettingChangedCallbackForTesting( | 1338 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1346 base::BarrierClosure(2, message_loop_runner->QuitClosure())); | 1339 base::BarrierClosure(1, message_loop_runner->QuitClosure())); |
| 1347 | 1340 |
| 1348 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1341 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1349 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1342 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1350 ->SetContentSettingDefaultScope(origin, GURL(), | 1343 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1351 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1344 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1352 std::string(), CONTENT_SETTING_ALLOW); | 1345 std::string(), CONTENT_SETTING_ALLOW); |
| 1353 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1354 ->SetContentSettingDefaultScope(origin, origin, | |
| 1355 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
| 1356 std::string(), CONTENT_SETTING_ALLOW); | |
| 1357 | 1346 |
| 1358 message_loop_runner->Run(); | 1347 message_loop_runner->Run(); |
| 1359 | 1348 |
| 1360 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1349 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1361 EXPECT_EQ("permission status - granted", script_result); | 1350 EXPECT_EQ("permission status - granted", script_result); |
| 1362 | 1351 |
| 1363 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1352 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1364 EXPECT_EQ("true - subscribed", script_result); | 1353 EXPECT_EQ("true - subscribed", script_result); |
| 1365 } | 1354 } |
| 1366 | 1355 |
| 1367 // This test is testing some non-trivial content settings rules and make sure | 1356 // This test is testing some non-trivial content settings rules and make sure |
| 1368 // that they are respected with regards to automatic unsubscription. In other | 1357 // that they are respected with regards to automatic unsubscription. In other |
| 1369 // words, it checks that the push service does not end up unsubscribing origins | 1358 // words, it checks that the push service does not end up unsubscribing origins |
| 1370 // that have push permission with some non-common rules. | 1359 // that have push permission with some non-common rules. |
| 1371 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1360 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 1372 AutomaticUnsubscriptionFollowsContentSettingRules) { | 1361 AutomaticUnsubscriptionFollowsContentSettingRules) { |
| 1373 std::string script_result; | 1362 std::string script_result; |
| 1374 | 1363 |
| 1375 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1364 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 1376 | 1365 |
| 1377 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1366 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1378 EXPECT_EQ("true - subscribed", script_result); | 1367 EXPECT_EQ("true - subscribed", script_result); |
| 1379 | 1368 |
| 1380 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1369 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1381 EXPECT_EQ("permission status - granted", script_result); | 1370 EXPECT_EQ("permission status - granted", script_result); |
| 1382 | 1371 |
| 1383 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1372 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 1384 new content::MessageLoopRunner; | 1373 new content::MessageLoopRunner; |
| 1385 push_service()->SetContentSettingChangedCallbackForTesting( | 1374 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1386 base::BarrierClosure(4, message_loop_runner->QuitClosure())); | 1375 base::BarrierClosure(2, message_loop_runner->QuitClosure())); |
| 1387 | 1376 |
| 1388 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1377 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 1389 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1378 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1390 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1379 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1391 CONTENT_SETTING_ALLOW); | 1380 CONTENT_SETTING_ALLOW); |
| 1392 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1381 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1393 ->SetContentSettingCustomScope( | |
| 1394 ContentSettingsPattern::FromString("https://*"), | |
| 1395 ContentSettingsPattern::FromString("https://*"), | |
| 1396 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string(), | |
| 1397 CONTENT_SETTING_ALLOW); | |
| 1398 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1399 ->SetContentSettingDefaultScope(origin, GURL(), | 1382 ->SetContentSettingDefaultScope(origin, GURL(), |
| 1400 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 1383 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1401 std::string(), CONTENT_SETTING_DEFAULT); | 1384 std::string(), CONTENT_SETTING_DEFAULT); |
| 1402 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1403 ->SetContentSettingDefaultScope(origin, origin, | |
| 1404 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
| 1405 std::string(), CONTENT_SETTING_DEFAULT); | |
| 1406 | 1385 |
| 1407 message_loop_runner->Run(); | 1386 message_loop_runner->Run(); |
| 1408 | 1387 |
| 1409 // The two first rules should give |origin| the permission to use Push even | 1388 // The two first rules should give |origin| the permission to use Push even |
| 1410 // if the rules it used to have have been reset. | 1389 // if the rules it used to have have been reset. |
| 1411 // The Push service should not unsubcribe |origin| because at no point it was | 1390 // The Push service should not unsubcribe |origin| because at no point it was |
| 1412 // left without permission to use Push. | 1391 // left without permission to use Push. |
| 1413 | 1392 |
| 1414 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1393 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 1415 EXPECT_EQ("permission status - granted", script_result); | 1394 EXPECT_EQ("permission status - granted", script_result); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1445 | 1424 |
| 1446 base::RunLoop run_loop; | 1425 base::RunLoop run_loop; |
| 1447 push_service()->SetContentSettingChangedCallbackForTesting( | 1426 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1448 run_loop.QuitClosure()); | 1427 run_loop.QuitClosure()); |
| 1449 | 1428 |
| 1450 // This shouldn't (asynchronously) cause a DCHECK. | 1429 // This shouldn't (asynchronously) cause a DCHECK. |
| 1451 // TODO(johnme): Get this test running on Android, which has a different | 1430 // TODO(johnme): Get this test running on Android, which has a different |
| 1452 // codepath due to sender_id being required for unsubscribing there. | 1431 // codepath due to sender_id being required for unsubscribing there. |
| 1453 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1432 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1454 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 1433 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1455 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | |
| 1456 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | |
| 1457 | 1434 |
| 1458 run_loop.Run(); | 1435 run_loop.Run(); |
| 1459 | 1436 |
| 1460 // |app_identifier| should no longer be stored in prefs. | 1437 // |app_identifier| should no longer be stored in prefs. |
| 1461 PushMessagingAppIdentifier stored_app_identifier2 = | 1438 PushMessagingAppIdentifier stored_app_identifier2 = |
| 1462 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1439 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
| 1463 app_identifier.app_id()); | 1440 app_identifier.app_id()); |
| 1464 EXPECT_TRUE(stored_app_identifier2.is_null()); | 1441 EXPECT_TRUE(stored_app_identifier2.is_null()); |
| 1465 } | 1442 } |
| 1466 | 1443 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1596 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1573 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1597 | 1574 |
| 1598 // After dropping the last subscription background mode is still inactive. | 1575 // After dropping the last subscription background mode is still inactive. |
| 1599 std::string script_result; | 1576 std::string script_result; |
| 1600 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1577 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1601 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1578 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1602 EXPECT_EQ("unsubscribe result: true", script_result); | 1579 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1603 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1580 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1604 } | 1581 } |
| 1605 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1582 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |