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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 GetBrowser()->tab_strip_model()->GetActiveWebContents()); | 211 GetBrowser()->tab_strip_model()->GetActiveWebContents()); |
212 } | 212 } |
213 | 213 |
214 void RequestAndAcceptPermission(); | 214 void RequestAndAcceptPermission(); |
215 void RequestAndDenyPermission(); | 215 void RequestAndDenyPermission(); |
216 | 216 |
217 void TryToSubscribeSuccessfully( | 217 void TryToSubscribeSuccessfully( |
218 const std::string& expected_push_subscription_info, | 218 const std::string& expected_push_subscription_info, |
219 bool use_key = true); | 219 bool use_key = true); |
220 | 220 |
221 std::string GetEndpointForSubscriptionId(const std::string& subscription_id) { | 221 std::string GetEndpointForSubscriptionId(const std::string& subscription_id, |
222 return std::string(kPushMessagingEndpoint) + "/" + subscription_id; | 222 bool standard_protocol = true) { |
| 223 return push_service()->GetEndpoint(standard_protocol).spec() + |
| 224 subscription_id; |
223 } | 225 } |
224 | 226 |
225 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( | 227 PushMessagingAppIdentifier GetAppIdentifierForServiceWorkerRegistration( |
226 int64_t service_worker_registration_id); | 228 int64_t service_worker_registration_id); |
227 | 229 |
228 void SendMessageAndWaitUntilHandled( | 230 void SendMessageAndWaitUntilHandled( |
229 const PushMessagingAppIdentifier& app_identifier, | 231 const PushMessagingAppIdentifier& app_identifier, |
230 const gcm::IncomingMessage& message); | 232 const gcm::IncomingMessage& message); |
231 | 233 |
232 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } | 234 net::EmbeddedTestServer* https_server() const { return https_server_.get(); } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (use_key) { | 319 if (use_key) { |
318 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 320 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
319 ASSERT_EQ("manifest removed", script_result); | 321 ASSERT_EQ("manifest removed", script_result); |
320 | 322 |
321 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); | 323 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
322 } else { | 324 } else { |
323 // Test backwards compatibility with old ID based subscriptions. | 325 // Test backwards compatibility with old ID based subscriptions. |
324 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 326 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
325 } | 327 } |
326 | 328 |
327 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), | 329 EXPECT_EQ( |
328 script_result); | 330 GetEndpointForSubscriptionId(expected_push_subscription_info, use_key), |
| 331 script_result); |
329 } | 332 } |
330 | 333 |
331 PushMessagingAppIdentifier | 334 PushMessagingAppIdentifier |
332 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 335 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
333 int64_t service_worker_registration_id) { | 336 int64_t service_worker_registration_id) { |
334 GURL origin = https_server()->GetURL("/").GetOrigin(); | 337 GURL origin = https_server()->GetURL("/").GetOrigin(); |
335 PushMessagingAppIdentifier app_identifier = | 338 PushMessagingAppIdentifier app_identifier = |
336 PushMessagingAppIdentifier::FindByServiceWorker( | 339 PushMessagingAppIdentifier::FindByServiceWorker( |
337 GetBrowser()->profile(), origin, service_worker_registration_id); | 340 GetBrowser()->profile(), origin, service_worker_registration_id); |
338 EXPECT_FALSE(app_identifier.is_null()); | 341 EXPECT_FALSE(app_identifier.is_null()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 521 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
519 EXPECT_EQ( | 522 EXPECT_EQ( |
520 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 523 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
521 script_result); | 524 script_result); |
522 EXPECT_NE(push_service(), GetAppHandler()); | 525 EXPECT_NE(push_service(), GetAppHandler()); |
523 | 526 |
524 // Run the subscription from the document without a key, this will trigger | 527 // Run the subscription from the document without a key, this will trigger |
525 // the code to read sender id from the manifest and will write it to the | 528 // the code to read sender id from the manifest and will write it to the |
526 // datastore. | 529 // datastore. |
527 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); | 530 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
528 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 531 EXPECT_EQ(GetEndpointForSubscriptionId("1-0", false), script_result); |
529 | 532 |
530 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 533 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
531 EXPECT_EQ("unsubscribe result: true", script_result); | 534 EXPECT_EQ("unsubscribe result: true", script_result); |
532 EXPECT_NE(push_service(), GetAppHandler()); | 535 EXPECT_NE(push_service(), GetAppHandler()); |
533 | 536 |
534 // Now run the subscribe from the service worker without a key. | 537 // Now run the subscribe from the service worker without a key. |
535 // In this case, the sender id will be read from the datastore. | 538 // In this case, the sender id will be read from the datastore. |
536 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | 539 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
537 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); | 540 EXPECT_EQ(GetEndpointForSubscriptionId("1-1", false), script_result); |
538 | 541 |
539 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 542 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
540 EXPECT_EQ("unsubscribe result: true", script_result); | 543 EXPECT_EQ("unsubscribe result: true", script_result); |
541 EXPECT_NE(push_service(), GetAppHandler()); | 544 EXPECT_NE(push_service(), GetAppHandler()); |
542 } | 545 } |
543 | 546 |
544 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 547 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
545 #if defined(OS_WIN) || defined(OS_LINUX) | 548 #if defined(OS_WIN) || defined(OS_LINUX) |
546 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 549 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
547 #else | 550 #else |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1485 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1483 | 1486 |
1484 // After dropping the last subscription background mode is still inactive. | 1487 // After dropping the last subscription background mode is still inactive. |
1485 std::string script_result; | 1488 std::string script_result; |
1486 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1489 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
1487 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1490 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1488 EXPECT_EQ("unsubscribe result: true", script_result); | 1491 EXPECT_EQ("unsubscribe result: true", script_result); |
1489 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1492 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1490 } | 1493 } |
1491 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1494 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
OLD | NEW |