| 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 |
| 11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 25 #include "chrome/browser/notifications/message_center_display_service.h" | 25 #include "chrome/browser/notifications/message_center_display_service.h" |
| 26 #include "chrome/browser/notifications/notification_test_util.h" | 26 #include "chrome/browser/notifications/notification_test_util.h" |
| 27 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 27 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 28 #include "chrome/browser/permissions/permission_request_manager.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 30 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
| 30 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 31 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
| 31 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 32 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 32 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 33 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 33 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 34 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 34 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 35 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 38 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/features.h" | 39 #include "chrome/common/features.h" |
| 40 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
| 41 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
| 42 #include "components/content_settings/core/browser/host_content_settings_map.h" | 42 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 43 #include "components/content_settings/core/common/content_settings.h" | 43 #include "components/content_settings/core/common/content_settings.h" |
| 44 #include "components/content_settings/core/common/content_settings_types.h" | 44 #include "components/content_settings/core/common/content_settings_types.h" |
| 45 #include "components/gcm_driver/common/gcm_messages.h" | 45 #include "components/gcm_driver/common/gcm_messages.h" |
| 46 #include "components/gcm_driver/gcm_client.h" | 46 #include "components/gcm_driver/gcm_client.h" |
| 47 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 181 web_contents = GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 182 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), | 182 return content::ExecuteScriptAndExtractString(web_contents->GetMainFrame(), |
| 183 script, result); | 183 script, result); |
| 184 } | 184 } |
| 185 | 185 |
| 186 gcm::GCMAppHandler* GetAppHandler() { | 186 gcm::GCMAppHandler* GetAppHandler() { |
| 187 return gcm_service()->driver()->GetAppHandler( | 187 return gcm_service()->driver()->GetAppHandler( |
| 188 kPushMessagingAppIdentifierPrefix); | 188 kPushMessagingAppIdentifierPrefix); |
| 189 } | 189 } |
| 190 | 190 |
| 191 PermissionBubbleManager* GetPermissionBubbleManager() { | 191 PermissionRequestManager* GetPermissionRequestManager() { |
| 192 return PermissionBubbleManager::FromWebContents( | 192 return PermissionRequestManager::FromWebContents( |
| 193 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 193 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void RequestAndAcceptPermission(); | 196 void RequestAndAcceptPermission(); |
| 197 void RequestAndDenyPermission(); | 197 void RequestAndDenyPermission(); |
| 198 | 198 |
| 199 void TryToSubscribeSuccessfully( | 199 void TryToSubscribeSuccessfully( |
| 200 const std::string& expected_push_subscription_info, | 200 const std::string& expected_push_subscription_info, |
| 201 bool use_key = true); | 201 bool use_key = true); |
| 202 | 202 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 class PushMessagingBrowserTestEmptySubscriptionOptions | 260 class PushMessagingBrowserTestEmptySubscriptionOptions |
| 261 : public PushMessagingBrowserTest { | 261 : public PushMessagingBrowserTest { |
| 262 std::string GetTestURL() override { | 262 std::string GetTestURL() override { |
| 263 return "/push_messaging/test_no_subscription_options.html"; | 263 return "/push_messaging/test_no_subscription_options.html"; |
| 264 } | 264 } |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 void PushMessagingBrowserTest::RequestAndAcceptPermission() { | 267 void PushMessagingBrowserTest::RequestAndAcceptPermission() { |
| 268 std::string script_result; | 268 std::string script_result; |
| 269 GetPermissionBubbleManager()->set_auto_response_for_test( | 269 GetPermissionRequestManager()->set_auto_response_for_test( |
| 270 PermissionBubbleManager::ACCEPT_ALL); | 270 PermissionRequestManager::ACCEPT_ALL); |
| 271 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 271 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 272 EXPECT_EQ("permission status - granted", script_result); | 272 EXPECT_EQ("permission status - granted", script_result); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 275 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
| 276 std::string script_result; | 276 std::string script_result; |
| 277 GetPermissionBubbleManager()->set_auto_response_for_test( | 277 GetPermissionRequestManager()->set_auto_response_for_test( |
| 278 PermissionBubbleManager::DENY_ALL); | 278 PermissionRequestManager::DENY_ALL); |
| 279 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 279 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 280 EXPECT_EQ("permission status - denied", script_result); | 280 EXPECT_EQ("permission status - denied", script_result); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 283 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( |
| 284 const std::string& expected_push_subscription_info, | 284 const std::string& expected_push_subscription_info, |
| 285 bool use_key) { | 285 bool use_key) { |
| 286 std::string script_result; | 286 std::string script_result; |
| 287 | 287 |
| 288 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 288 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 gcm_service()->last_registered_sender_ids()[0]); | 345 gcm_service()->last_registered_sender_ids()[0]); |
| 346 } | 346 } |
| 347 | 347 |
| 348 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 348 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 349 SubscribeSuccessNotificationsPrompt) { | 349 SubscribeSuccessNotificationsPrompt) { |
| 350 std::string script_result; | 350 std::string script_result; |
| 351 | 351 |
| 352 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 352 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 353 ASSERT_EQ("ok - service worker registered", script_result); | 353 ASSERT_EQ("ok - service worker registered", script_result); |
| 354 | 354 |
| 355 GetPermissionBubbleManager()->set_auto_response_for_test( | 355 GetPermissionRequestManager()->set_auto_response_for_test( |
| 356 PermissionBubbleManager::ACCEPT_ALL); | 356 PermissionRequestManager::ACCEPT_ALL); |
| 357 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 357 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 358 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 358 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 359 | 359 |
| 360 PushMessagingAppIdentifier app_identifier = | 360 PushMessagingAppIdentifier app_identifier = |
| 361 GetAppIdentifierForServiceWorkerRegistration(0LL); | 361 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 362 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 362 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 363 EXPECT_EQ(kEncodedApplicationServerKey, | 363 EXPECT_EQ(kEncodedApplicationServerKey, |
| 364 gcm_service()->last_registered_sender_ids()[0]); | 364 gcm_service()->last_registered_sender_ids()[0]); |
| 365 } | 365 } |
| 366 | 366 |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1455 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1456 | 1456 |
| 1457 // After dropping the last subscription background mode is still inactive. | 1457 // After dropping the last subscription background mode is still inactive. |
| 1458 std::string script_result; | 1458 std::string script_result; |
| 1459 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1459 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1460 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1460 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1461 EXPECT_EQ("unsubscribe result: true", script_result); | 1461 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1462 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1462 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1463 } | 1463 } |
| 1464 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1464 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |