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