| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 PermissionBubbleManager* GetPermissionBubbleManager() { | 166 PermissionBubbleManager* GetPermissionBubbleManager() { |
| 167 return PermissionBubbleManager::FromWebContents( | 167 return PermissionBubbleManager::FromWebContents( |
| 168 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 168 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void RequestAndAcceptPermission(); | 171 void RequestAndAcceptPermission(); |
| 172 void RequestAndDenyPermission(); | 172 void RequestAndDenyPermission(); |
| 173 | 173 |
| 174 void TryToSubscribeSuccessfully( | 174 void TryToSubscribeSuccessfully( |
| 175 const std::string& expected_push_subscription_id); | 175 const std::string& expected_push_subscription_info, |
| 176 bool use_key = true); |
| 176 | 177 |
| 177 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { | 178 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { |
| 178 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; | 179 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; |
| 179 } | 180 } |
| 180 | 181 |
| 181 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 182 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
| 182 int64_t service_worker_registration_id); | 183 int64_t service_worker_registration_id); |
| 183 | 184 |
| 184 void SendMessageAndWaitUntilHandled( | 185 void SendMessageAndWaitUntilHandled( |
| 185 const PushMessagingAppIdentifier& app_identifier, | 186 const PushMessagingAppIdentifier& app_identifier, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 248 |
| 248 void PushMessagingBrowserTest::RequestAndDenyPermission() { | 249 void PushMessagingBrowserTest::RequestAndDenyPermission() { |
| 249 std::string script_result; | 250 std::string script_result; |
| 250 GetPermissionBubbleManager()->set_auto_response_for_test( | 251 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 251 PermissionBubbleManager::DENY_ALL); | 252 PermissionBubbleManager::DENY_ALL); |
| 252 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); | 253 EXPECT_TRUE(RunScript("requestNotificationPermission();", &script_result)); |
| 253 EXPECT_EQ("permission status - denied", script_result); | 254 EXPECT_EQ("permission status - denied", script_result); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( | 257 void PushMessagingBrowserTest::TryToSubscribeSuccessfully( |
| 257 const std::string& expected_push_subscription_id) { | 258 const std::string& expected_push_subscription_info, |
| 259 bool use_key) { |
| 258 std::string script_result; | 260 std::string script_result; |
| 259 | 261 |
| 260 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 262 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 261 EXPECT_EQ("ok - service worker registered", script_result); | 263 EXPECT_EQ("ok - service worker registered", script_result); |
| 262 | 264 |
| 263 RequestAndAcceptPermission(); | 265 RequestAndAcceptPermission(); |
| 264 | 266 |
| 265 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); | 267 if (use_key) { |
| 266 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_id), | 268 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); |
| 269 } else { |
| 270 // Test backwards compatibility with old ID based subscriptions. |
| 271 EXPECT_TRUE(RunScript("subscribePushWithoutKey()", &script_result)); |
| 272 } |
| 273 |
| 274 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), |
| 267 script_result); | 275 script_result); |
| 268 } | 276 } |
| 269 | 277 |
| 270 PushMessagingAppIdentifier | 278 PushMessagingAppIdentifier |
| 271 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 279 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
| 272 int64_t service_worker_registration_id) { | 280 int64_t service_worker_registration_id) { |
| 273 GURL origin = https_server()->GetURL("/").GetOrigin(); | 281 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 274 PushMessagingAppIdentifier app_identifier = | 282 PushMessagingAppIdentifier app_identifier = |
| 275 PushMessagingAppIdentifier::FindByServiceWorker( | 283 PushMessagingAppIdentifier::FindByServiceWorker( |
| 276 GetBrowser()->profile(), origin, service_worker_registration_id); | 284 GetBrowser()->profile(), origin, service_worker_registration_id); |
| 277 EXPECT_FALSE(app_identifier.is_null()); | 285 EXPECT_FALSE(app_identifier.is_null()); |
| 278 return app_identifier; | 286 return app_identifier; |
| 279 } | 287 } |
| 280 | 288 |
| 281 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( | 289 void PushMessagingBrowserTest::SendMessageAndWaitUntilHandled( |
| 282 const PushMessagingAppIdentifier& app_identifier, | 290 const PushMessagingAppIdentifier& app_identifier, |
| 283 const gcm::IncomingMessage& message) { | 291 const gcm::IncomingMessage& message) { |
| 284 base::RunLoop run_loop; | 292 base::RunLoop run_loop; |
| 285 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 293 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
| 286 push_service()->OnMessage(app_identifier.app_id(), message); | 294 push_service()->OnMessage(app_identifier.app_id(), message); |
| 287 run_loop.Run(); | 295 run_loop.Run(); |
| 288 } | 296 } |
| 289 | 297 |
| 290 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 298 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 299 SubscribeWithoutKeySuccessNotificationsGranted) { |
| 300 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); |
| 301 |
| 302 PushMessagingAppIdentifier app_identifier = |
| 303 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 304 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 305 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 306 } |
| 307 |
| 308 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 291 SubscribeSuccessNotificationsGranted) { | 309 SubscribeSuccessNotificationsGranted) { |
| 292 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 310 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 293 | 311 |
| 294 PushMessagingAppIdentifier app_identifier = | 312 PushMessagingAppIdentifier app_identifier = |
| 295 GetAppIdentifierForServiceWorkerRegistration(0LL); | 313 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 296 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 314 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 297 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 298 } | 316 } |
| 299 | 317 |
| 300 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1301 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1284 | 1302 |
| 1285 // After dropping the last subscription background mode is still inactive. | 1303 // After dropping the last subscription background mode is still inactive. |
| 1286 std::string script_result; | 1304 std::string script_result; |
| 1287 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1305 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1288 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1306 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1289 EXPECT_EQ("unsubscribe result: true", script_result); | 1307 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1290 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1308 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1291 } | 1309 } |
| 1292 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1310 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |