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 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/engagement/site_engagement_service.h" | 26 #include "chrome/browser/engagement/site_engagement_service.h" |
27 #include "chrome/browser/gcm/fake_gcm_profile_service.h" | 27 #include "chrome/browser/gcm/fake_gcm_profile_service.h" |
28 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 28 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
29 #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" | 29 #include "chrome/browser/gcm/instance_id/instance_id_profile_service.h" |
30 #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" | 30 #include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h" |
31 #include "chrome/browser/lifetime/keep_alive_registry.h" | 31 #include "chrome/browser/lifetime/keep_alive_registry.h" |
32 #include "chrome/browser/lifetime/keep_alive_types.h" | 32 #include "chrome/browser/lifetime/keep_alive_types.h" |
33 #include "chrome/browser/notifications/message_center_display_service.h" | 33 #include "chrome/browser/notifications/message_center_display_service.h" |
34 #include "chrome/browser/notifications/notification_test_util.h" | 34 #include "chrome/browser/notifications/notification_test_util.h" |
35 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 35 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 36 #include "chrome/browser/permissions/permission_context_base.h" |
36 #include "chrome/browser/permissions/permission_request_manager.h" | 37 #include "chrome/browser/permissions/permission_request_manager.h" |
37 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
38 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 39 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
39 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 40 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
40 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 41 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
41 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 42 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
42 #include "chrome/browser/ui/browser.h" | 43 #include "chrome/browser/ui/browser.h" |
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
44 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
45 #include "chrome/common/features.h" | 46 #include "chrome/common/features.h" |
46 #include "chrome/test/base/in_process_browser_test.h" | 47 #include "chrome/test/base/in_process_browser_test.h" |
47 #include "chrome/test/base/ui_test_utils.h" | 48 #include "chrome/test/base/ui_test_utils.h" |
48 #include "components/content_settings/core/browser/host_content_settings_map.h" | 49 #include "components/content_settings/core/browser/host_content_settings_map.h" |
49 #include "components/content_settings/core/common/content_settings.h" | 50 #include "components/content_settings/core/common/content_settings.h" |
50 #include "components/content_settings/core/common/content_settings_types.h" | 51 #include "components/content_settings/core/common/content_settings_types.h" |
51 #include "components/gcm_driver/common/gcm_messages.h" | 52 #include "components/gcm_driver/common/gcm_messages.h" |
52 #include "components/gcm_driver/gcm_client.h" | 53 #include "components/gcm_driver/gcm_client.h" |
53 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" | 54 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" |
54 #include "components/gcm_driver/instance_id/instance_id_driver.h" | 55 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
| 56 #include "components/variations/variations_associated_data.h" |
55 #include "content/public/browser/browsing_data_remover.h" | 57 #include "content/public/browser/browsing_data_remover.h" |
56 #include "content/public/browser/notification_service.h" | 58 #include "content/public/browser/notification_service.h" |
57 #include "content/public/browser/web_contents.h" | 59 #include "content/public/browser/web_contents.h" |
58 #include "content/public/common/content_switches.h" | 60 #include "content/public/common/content_switches.h" |
59 #include "content/public/common/push_subscription_options.h" | 61 #include "content/public/common/push_subscription_options.h" |
60 #include "content/public/test/browser_test_utils.h" | 62 #include "content/public/test/browser_test_utils.h" |
61 #include "content/public/test/browsing_data_remover_test_util.h" | 63 #include "content/public/test/browsing_data_remover_test_util.h" |
62 #include "content/public/test/test_utils.h" | 64 #include "content/public/test/test_utils.h" |
63 #include "net/test/embedded_test_server/embedded_test_server.h" | 65 #include "net/test/embedded_test_server/embedded_test_server.h" |
64 #include "testing/gmock/include/gmock/gmock.h" | 66 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1283 GURL origin = https_server()->GetURL("/").GetOrigin(); |
1282 PushMessagingAppIdentifier app_identifier_afterwards = | 1284 PushMessagingAppIdentifier app_identifier_afterwards = |
1283 PushMessagingAppIdentifier::FindByServiceWorker(GetBrowser()->profile(), | 1285 PushMessagingAppIdentifier::FindByServiceWorker(GetBrowser()->profile(), |
1284 origin, 0LL); | 1286 origin, 0LL); |
1285 EXPECT_TRUE(app_identifier_afterwards.is_null()); | 1287 EXPECT_TRUE(app_identifier_afterwards.is_null()); |
1286 histogram_tester_.ExpectUniqueSample( | 1288 histogram_tester_.ExpectUniqueSample( |
1287 "PushMessaging.UnregistrationReason", | 1289 "PushMessaging.UnregistrationReason", |
1288 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED, 1); | 1290 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED, 1); |
1289 } | 1291 } |
1290 | 1292 |
| 1293 // Tests that an activated kill switch will not result in subscriptions being |
| 1294 // unsubscribed upon receiving a message. |
| 1295 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventDuringKillSwitch) { |
| 1296 std::string script_result; |
| 1297 |
| 1298 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
| 1299 PushMessagingAppIdentifier app_identifier = |
| 1300 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 1301 |
| 1302 LoadTestPage(); // Reload to become controlled. |
| 1303 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 1304 ASSERT_EQ("true - is controlled", script_result); |
| 1305 |
| 1306 // Enable the kill switch for the Push Notifications permission. |
| 1307 std::map<std::string, std::string> params; |
| 1308 params["PushMessaging"] = |
| 1309 PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| 1310 variations::AssociateVariationParams( |
| 1311 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup", |
| 1312 params); |
| 1313 base::FieldTrialList::CreateFieldTrial( |
| 1314 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup"); |
| 1315 |
| 1316 // Now try to deliver a message. |
| 1317 gcm::IncomingMessage message; |
| 1318 message.sender_id = GetTestApplicationServerKey(); |
| 1319 message.raw_data = "testdata"; |
| 1320 message.decrypted = true; |
| 1321 SendMessageAndWaitUntilHandled(app_identifier, message); |
| 1322 |
| 1323 // No push data should have been received. |
| 1324 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 1325 EXPECT_EQ("null", script_result); |
| 1326 |
| 1327 // Check that we record this case in UMA. |
| 1328 histogram_tester_.ExpectUniqueSample( |
| 1329 "PushMessaging.DeliveryStatus", |
| 1330 content::PUSH_DELIVERY_STATUS_PERMISSION_SUSPENDED, 1); |
| 1331 |
| 1332 // The kill switch should not unsubscribe the given permission however. |
| 1333 EXPECT_NE(app_identifier.app_id(), gcm_driver_->last_deletetoken_app_id()); |
| 1334 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 1335 EXPECT_EQ("true - subscribed", script_result); |
| 1336 } |
| 1337 |
1291 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1338 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
1292 PushEventEnforcesUserVisibleNotification) { | 1339 PushEventEnforcesUserVisibleNotification) { |
1293 std::string script_result; | 1340 std::string script_result; |
1294 | 1341 |
1295 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); | 1342 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); |
1296 PushMessagingAppIdentifier app_identifier = | 1343 PushMessagingAppIdentifier app_identifier = |
1297 GetAppIdentifierForServiceWorkerRegistration(0LL); | 1344 GetAppIdentifierForServiceWorkerRegistration(0LL); |
1298 | 1345 |
1299 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 1346 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
1300 ASSERT_EQ("false - is not controlled", script_result); | 1347 ASSERT_EQ("false - is not controlled", script_result); |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2405 push_service()->SetUnsubscribeCallbackForTesting(run_loop.QuitClosure()); | 2452 push_service()->SetUnsubscribeCallbackForTesting(run_loop.QuitClosure()); |
2406 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 2453 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
2407 EXPECT_EQ("unsubscribe result: true", script_result); | 2454 EXPECT_EQ("unsubscribe result: true", script_result); |
2408 // Background mode is only guaranteed to have updated once the unsubscribe | 2455 // Background mode is only guaranteed to have updated once the unsubscribe |
2409 // callback for testing has been run (PushSubscription.unsubscribe() usually | 2456 // callback for testing has been run (PushSubscription.unsubscribe() usually |
2410 // resolves before that, in order to avoid blocking on network retries etc). | 2457 // resolves before that, in order to avoid blocking on network retries etc). |
2411 run_loop.Run(); | 2458 run_loop.Run(); |
2412 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 2459 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
2413 } | 2460 } |
2414 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 2461 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
OLD | NEW |