Chromium Code Reviews| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 #if defined(ENABLE_NOTIFICATIONS) | 94 #if defined(ENABLE_NOTIFICATIONS) |
| 95 notification_manager_.reset(new StubNotificationUIManager); | 95 notification_manager_.reset(new StubNotificationUIManager); |
| 96 notification_service()->SetNotificationUIManagerForTesting( | 96 notification_service()->SetNotificationUIManagerForTesting( |
| 97 notification_manager()); | 97 notification_manager()); |
| 98 #endif | 98 #endif |
| 99 | 99 |
| 100 InProcessBrowserTest::SetUp(); | 100 InProcessBrowserTest::SetUp(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void SetUpCommandLine(base::CommandLine* command_line) override { | 103 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 104 // Enable experiemntal features for subscription restrictions. | 104 // Enable experimental features for subscription restrictions. |
| 105 command_line->AppendSwitch( | 105 command_line->AppendSwitch( |
| 106 switches::kEnableExperimentalWebPlatformFeatures); | 106 switches::kEnableExperimentalWebPlatformFeatures); |
| 107 InProcessBrowserTest::SetUpCommandLine(command_line); | 107 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // InProcessBrowserTest: | 110 // InProcessBrowserTest: |
| 111 void SetUpOnMainThread() override { | 111 void SetUpOnMainThread() override { |
| 112 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 112 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 113 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 113 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 114 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 114 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 | 388 |
| 389 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); | 389 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); |
| 390 ASSERT_EQ("sender id removed from manifest", script_result); | 390 ASSERT_EQ("sender id removed from manifest", script_result); |
| 391 | 391 |
| 392 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 392 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); |
| 393 EXPECT_EQ( | 393 EXPECT_EQ( |
| 394 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 394 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 395 script_result); | 395 script_result); |
| 396 } | 396 } |
| 397 | 397 |
| 398 // TODO(johnme): Test subscribing from a worker - see https://crbug.com/437298. | |
| 399 | |
| 400 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, | 398 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, |
| 401 RegisterFailureEmptyPushSubscriptionOptions) { | 399 RegisterFailureEmptyPushSubscriptionOptions) { |
| 402 std::string script_result; | 400 std::string script_result; |
| 403 | 401 |
| 404 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 402 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 405 ASSERT_EQ("ok - service worker registered", script_result); | 403 ASSERT_EQ("ok - service worker registered", script_result); |
| 406 | 404 |
| 407 RequestAndAcceptPermission(); | 405 RequestAndAcceptPermission(); |
| 408 | 406 |
| 409 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 407 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); |
| 410 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 408 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 411 script_result); | 409 script_result); |
| 412 } | 410 } |
| 413 | 411 |
| 412 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, WorkerSubscribeSuccessful) { | |
|
Michael van Ouwerkerk
2016/03/22 11:31:37
Not all attempts in this test are successful. Mayb
harkness
2016/03/24 16:56:23
Done.
| |
| 413 std::string script_result; | |
| 414 | |
| 415 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | |
| 416 ASSERT_EQ("ok - service worker registered", script_result); | |
| 417 | |
| 418 RequestAndAcceptPermission(); | |
| 419 | |
| 420 LoadTestPage(); // Reload to become controlled. | |
| 421 | |
| 422 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | |
| 423 ASSERT_EQ("true - is controlled", script_result); | |
| 424 | |
| 425 // Try to subscribe from a worker without a key. This should fail. | |
| 426 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | |
| 427 EXPECT_EQ( | |
| 428 "AbortError - Registration failed - gcm_sender_id not found in manifest", | |
| 429 script_result); | |
| 430 | |
| 431 // Run the subscription from the document without a key, this will | |
| 432 // trigger the code to read the manifest. | |
| 433 ASSERT_TRUE(RunScript("subscribePushWithoutKey()", &script_result)); | |
|
Michael van Ouwerkerk
2016/03/22 11:31:37
For clarity it might help to rename subscribePushW
harkness
2016/03/24 16:56:23
Done.
| |
| 434 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | |
| 435 | |
| 436 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 437 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 438 EXPECT_NE(push_service(), GetAppHandler()); | |
| 439 | |
| 440 // Now run the subscribe from the service worker without a key. | |
| 441 // In this case, the key will be read from the datastore. | |
|
Michael van Ouwerkerk
2016/03/22 11:31:37
I think no application server key has been provide
harkness
2016/03/24 16:56:23
Good point! In fact, this was hiding an actual cod
| |
| 442 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); | |
| 443 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); | |
| 444 | |
| 445 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 446 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 447 EXPECT_NE(push_service(), GetAppHandler()); | |
| 448 | |
| 449 // Now run the subscribe from the service worker with a key. | |
| 450 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); | |
| 451 EXPECT_EQ(GetEndpointForSubscriptionId("1-2"), script_result); | |
| 452 | |
| 453 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | |
| 454 EXPECT_EQ("unsubscribe result: true", script_result); | |
| 455 EXPECT_NE(push_service(), GetAppHandler()); | |
| 456 } | |
| 457 | |
| 414 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 458 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
| 415 #if defined(OS_WIN) || defined(OS_LINUX) | 459 #if defined(OS_WIN) || defined(OS_LINUX) |
| 416 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 460 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
| 417 #else | 461 #else |
| 418 #define MAYBE_SubscribePersisted SubscribePersisted | 462 #define MAYBE_SubscribePersisted SubscribePersisted |
| 419 #endif | 463 #endif |
| 420 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { | 464 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { |
| 421 std::string script_result; | 465 std::string script_result; |
| 422 | 466 |
| 423 // First, test that Service Worker registration IDs are assigned in order of | 467 // First, test that Service Worker registration IDs are assigned in order of |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1379 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1336 | 1380 |
| 1337 // After dropping the last subscription background mode is still inactive. | 1381 // After dropping the last subscription background mode is still inactive. |
| 1338 std::string script_result; | 1382 std::string script_result; |
| 1339 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1383 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1340 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1384 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1341 EXPECT_EQ("unsubscribe result: true", script_result); | 1385 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1342 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1386 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1343 } | 1387 } |
| 1344 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1388 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |