| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 203 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { | 203 std::string GetEndpointForSubscriptionId(const std::string& subscription_id, |
| 204 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; | 204 bool standard_protocol = true) { |
| 205 return push_service()->GetEndpoint(standard_protocol).spec() + |
| 206 subscription_id; |
| 205 } | 207 } |
| 206 | 208 |
| 207 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 209 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
| 208 int64_t service_worker_registration_id); | 210 int64_t service_worker_registration_id); |
| 209 | 211 |
| 210 void SendMessageAndWaitUntilHandled( | 212 void SendMessageAndWaitUntilHandled( |
| 211 const PushMessagingAppIdentifier& app_identifier, | 213 const PushMessagingAppIdentifier& app_identifier, |
| 212 const gcm::IncomingMessage& message); | 214 const gcm::IncomingMessage& message); |
| 213 | 215 |
| 214 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } | 216 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (use_key) { | 295 if (use_key) { |
| 294 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 296 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| 295 ASSERT_EQ("manifest removed", script_result); | 297 ASSERT_EQ("manifest removed", script_result); |
| 296 | 298 |
| 297 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 299 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 298 } else { | 300 } else { |
| 299 // Test backwards compatibility with old ID based subscriptions. | 301 // Test backwards compatibility with old ID based subscriptions. |
| 300 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 302 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 301 } | 303 } |
| 302 | 304 |
| 303 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), | 305 EXPECT_EQ( |
| 304 script_result); | 306 GetEndpointForSubscriptionId(expected_push_subscription_info, use_key), |
| 307 script_result); |
| 305 } | 308 } |
| 306 | 309 |
| 307 PushMessagingAppIdentifier | 310 PushMessagingAppIdentifier |
| 308 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 311 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
| 309 int64_t service_worker_registration_id) { | 312 int64_t service_worker_registration_id) { |
| 310 GURL origin = https_server()->GetURL("/").GetOrigin(); | 313 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 311 PushMessagingAppIdentifier app_identifier = | 314 PushMessagingAppIdentifier app_identifier = |
| 312 PushMessagingAppIdentifier::FindByServiceWorker( | 315 PushMessagingAppIdentifier::FindByServiceWorker( |
| 313 GetBrowser()->profile(), origin, service_worker_registration_id); | 316 GetBrowser()->profile(), origin, service_worker_registration_id); |
| 314 EXPECT_FALSE(app_identifier.is_null()); | 317 EXPECT_FALSE(app_identifier.is_null()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 497 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 495 EXPECT_EQ( | 498 EXPECT_EQ( |
| 496 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 499 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 497 script_result); | 500 script_result); |
| 498 EXPECT_NE(push_service(), GetAppHandler()); | 501 EXPECT_NE(push_service(), GetAppHandler()); |
| 499 | 502 |
| 500 // Run the subscription from the document without a key, this will trigger | 503 // Run the subscription from the document without a key, this will trigger |
| 501 // the code to read sender id from the manifest and will write it to the | 504 // the code to read sender id from the manifest and will write it to the |
| 502 // datastore. | 505 // datastore. |
| 503 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 506 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 504 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 507 EXPECT_EQ(GetEndpointForSubscriptionId("1-0", false), script_result); |
| 505 | 508 |
| 506 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 509 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 507 EXPECT_EQ("unsubscribe result: true", script_result); | 510 EXPECT_EQ("unsubscribe result: true", script_result); |
| 508 EXPECT_NE(push_service(), GetAppHandler()); | 511 EXPECT_NE(push_service(), GetAppHandler()); |
| 509 | 512 |
| 510 // Now run the subscribe from the service worker without a key. | 513 // Now run the subscribe from the service worker without a key. |
| 511 // In this case, the sender id will be read from the datastore. | 514 // In this case, the sender id will be read from the datastore. |
| 512 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 515 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 513 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); | 516 EXPECT_EQ(GetEndpointForSubscriptionId("1-1", false), script_result); |
| 514 | 517 |
| 515 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 518 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 516 EXPECT_EQ("unsubscribe result: true", script_result); | 519 EXPECT_EQ("unsubscribe result: true", script_result); |
| 517 EXPECT_NE(push_service(), GetAppHandler()); | 520 EXPECT_NE(push_service(), GetAppHandler()); |
| 518 } | 521 } |
| 519 | 522 |
| 520 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 523 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
| 521 #if defined(OS_WIN) || defined(OS_LINUX) | 524 #if defined(OS_WIN) || defined(OS_LINUX) |
| 522 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 525 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
| 523 #else | 526 #else |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1458 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1456 | 1459 |
| 1457 // After dropping the last subscription background mode is still inactive. | 1460 // After dropping the last subscription background mode is still inactive. |
| 1458 std::string script_result; | 1461 std::string script_result; |
| 1459 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1462 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1460 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1463 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1461 EXPECT_EQ("unsubscribe result: true", script_result); | 1464 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1462 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1465 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1463 } | 1466 } |
| 1464 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1467 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |