| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 22 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 23 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 23 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 26 #include "chrome/browser/engagement/site_engagement_service.h" | 26 #include "chrome/browser/engagement/site_engagement_service.h" |
| 27 #include "chrome/browser/lifetime/keep_alive_registry.h" | 27 #include "chrome/browser/lifetime/keep_alive_registry.h" |
| 28 #include "chrome/browser/lifetime/keep_alive_types.h" | 28 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 29 #include "chrome/browser/notifications/message_center_display_service.h" | 29 #include "chrome/browser/notifications/message_center_display_service.h" |
| 30 #include "chrome/browser/notifications/notification_test_util.h" | 30 #include "chrome/browser/notifications/notification_test_util.h" |
| 31 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 31 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 32 #include "chrome/browser/permissions/permission_request_manager.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 34 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
| 34 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 35 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
| 35 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 36 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 36 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 37 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 37 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 38 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 38 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 39 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 39 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 41 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 41 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/features.h" | 43 #include "chrome/common/features.h" |
| 44 #include "chrome/test/base/in_process_browser_test.h" | 44 #include "chrome/test/base/in_process_browser_test.h" |
| 45 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
| 46 #include "components/content_settings/core/browser/host_content_settings_map.h" | 46 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 47 #include "components/content_settings/core/common/content_settings.h" | 47 #include "components/content_settings/core/common/content_settings.h" |
| 48 #include "components/content_settings/core/common/content_settings_types.h" | 48 #include "components/content_settings/core/common/content_settings_types.h" |
| 49 #include "components/gcm_driver/common/gcm_messages.h" | 49 #include "components/gcm_driver/common/gcm_messages.h" |
| 50 #include "components/gcm_driver/gcm_client.h" | 50 #include "components/gcm_driver/gcm_client.h" |
| 51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 200 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 201 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), | 201 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), |
| 202 script, result); | 202 script, result); |
| 203 } | 203 } |
| 204 | 204 |
| 205 gcm::GCMAppHandler* GetAppHandler() { | 205 gcm::GCMAppHandler* GetAppHandler() { |
| 206 return gcm_service()->driver()->GetAppHandler( | 206 return gcm_service()->driver()->GetAppHandler( |
| 207 kPushMessagingAppIdentifierPrefix); | 207 kPushMessagingAppIdentifierPrefix); |
| 208 } | 208 } |
| 209 | 209 |
| 210 PermissionBubbleManager* GetPermissionBubbleManager() { | 210 PermissionRequestManager* GetPermissionRequestManager() { |
| 211 return PermissionBubbleManager::FromWebContents( | 211 return PermissionRequestManager::FromWebContents( |
| 212 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 212 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void RequestAndAcceptPermission(); | 215 void RequestAndAcceptPermission(); |
| 216 void RequestAndDenyPermission(); | 216 void RequestAndDenyPermission(); |
| 217 | 217 |
| 218 void TryToSubscribeSuccessfully( | 218 void TryToSubscribeSuccessfully( |
| 219 const std::string& expected_push_subscription_info, | 219 const std::string& expected_push_subscription_info, |
| 220 bool use_key = true); | 220 bool use_key = true); |
| 221 | 221 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 class PushMessagingBrowserTestEmptySubscriptionOptions | 290 class PushMessagingBrowserTestEmptySubscriptionOptions |
| 291 : public PushMessagingBrowserTest { | 291 : public PushMessagingBrowserTest { |
| 292 std::string GetTestURL() override { | 292 std::string GetTestURL() override { |
| 293 return "/push_messaging/test_no_subscription_options.html"; | 293 return "/push_messaging/test_no_subscription_options.html"; |
| 294 } | 294 } |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 void PushMessagingBrowserTest::RequestAndAcceptPermission() { | 297 void PushMessagingBrowserTest::RequestAndAcceptPermission() { |
| 298 std::string script_result; | 298 std::string script_result; |
| 299 GetPermissionBubbleManager()->set_auto_response_for_test( | 299 GetPermissionRequestManager()->set_auto_response_for_test( |
| 300 PermissionBubbleManager::ACCEPT_ALL); | 300 PermissionRequestManager::ACCEPT_ALL); |
| 301 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 301 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 302 EXPECT_EQ("permission status - granted", script_result); | 302 EXPECT_EQ("permission status - granted", script_result); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 305 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
| 306 std::string script_result; | 306 std::string script_result; |
| 307 GetPermissionBubbleManager()->set_auto_response_for_test( | 307 GetPermissionRequestManager()->set_auto_response_for_test( |
| 308 PermissionBubbleManager::DENY_ALL); | 308 PermissionRequestManager::DENY_ALL); |
| 309 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 309 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 310 EXPECT_EQ("permission status - denied", script_result); | 310 EXPECT_EQ("permission status - denied", script_result); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 313 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( |
| 314 const std::string& expected_push_subscription_info, | 314 const std::string& expected_push_subscription_info, |
| 315 bool use_key) { | 315 bool use_key) { |
| 316 std::string script_result; | 316 std::string script_result; |
| 317 | 317 |
| 318 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 318 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 gcm_service()->last_registered_sender_ids()[0]); | 376 gcm_service()->last_registered_sender_ids()[0]); |
| 377 } | 377 } |
| 378 | 378 |
| 379 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 379 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 380 SubscribeSuccessNotificationsPrompt) { | 380 SubscribeSuccessNotificationsPrompt) { |
| 381 std::string script_result; | 381 std::string script_result; |
| 382 | 382 |
| 383 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 383 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 384 ASSERT_EQ("ok - service worker registered", script_result); | 384 ASSERT_EQ("ok - service worker registered", script_result); |
| 385 | 385 |
| 386 GetPermissionBubbleManager()->set_auto_response_for_test( | 386 GetPermissionRequestManager()->set_auto_response_for_test( |
| 387 PermissionBubbleManager::ACCEPT_ALL); | 387 PermissionRequestManager::ACCEPT_ALL); |
| 388 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 388 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 389 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 389 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 390 | 390 |
| 391 PushMessagingAppIdentifier app_identifier = | 391 PushMessagingAppIdentifier app_identifier = |
| 392 GetAppIdentifierForServiceWorkerRegistration(0LL); | 392 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 393 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 393 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 394 EXPECT_EQ(kEncodedApplicationServerKey, | 394 EXPECT_EQ(kEncodedApplicationServerKey, |
| 395 gcm_service()->last_registered_sender_ids()[0]); | 395 gcm_service()->last_registered_sender_ids()[0]); |
| 396 } | 396 } |
| 397 | 397 |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1591 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1592 | 1592 |
| 1593 // After dropping the last subscription background mode is still inactive. | 1593 // After dropping the last subscription background mode is still inactive. |
| 1594 std::string script_result; | 1594 std::string script_result; |
| 1595 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1595 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1596 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1596 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1597 EXPECT_EQ("unsubscribe result: true", script_result); | 1597 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1598 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1598 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1599 } | 1599 } |
| 1600 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1600 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |