| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "content/public/test/browser_test_utils.h" | 48 #include "content/public/test/browser_test_utils.h" |
| 49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
| 50 #include "net/test/embedded_test_server/embedded_test_server.h" | 50 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 51 #include "ui/base/window_open_disposition.h" | 51 #include "ui/base/window_open_disposition.h" |
| 52 | 52 |
| 53 #if BUILDFLAG(ENABLE_BACKGROUND) | 53 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 54 #include "chrome/browser/background/background_mode_manager.h" | 54 #include "chrome/browser/background/background_mode_manager.h" |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 |
| 59 // NIST P-256 public key made available to tests. Must be an uncompressed |
| 60 // point in accordance with SEC1 2.3.3. |
| 61 // Note: Although the key itself is only 65 bytes, we pad it with a 0x00 to |
| 62 // make dcheck happy when it compares input and output as strings. |
| 63 const uint8_t kApplicationServerKey[66] = { |
| 64 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, |
| 65 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, |
| 66 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, |
| 67 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13, |
| 68 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76, |
| 69 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD, 0x00}; |
| 70 |
| 71 const char* getTestApplicationServerKey() { |
| 72 return reinterpret_cast<const char*>(kApplicationServerKey); |
| 73 } |
| 74 |
| 58 // Class to instantiate on the stack that is meant to be used with | 75 // Class to instantiate on the stack that is meant to be used with |
| 59 // FakeGCMProfileService. The ::Run() method follows the signature of | 76 // FakeGCMProfileService. The ::Run() method follows the signature of |
| 60 // FakeGCMProfileService::UnregisterCallback. | 77 // FakeGCMProfileService::UnregisterCallback. |
| 61 class UnregistrationCallback { | 78 class UnregistrationCallback { |
| 62 public: | 79 public: |
| 63 UnregistrationCallback() | 80 UnregistrationCallback() |
| 64 : message_loop_runner_(new content::MessageLoopRunner) {} | 81 : message_loop_runner_(new content::MessageLoopRunner) {} |
| 65 | 82 |
| 66 void Run(const std::string& app_id) { | 83 void Run(const std::string& app_id) { |
| 67 app_id_ = app_id; | 84 app_id_ = app_id; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 #if defined(ENABLE_NOTIFICATIONS) | 111 #if defined(ENABLE_NOTIFICATIONS) |
| 95 notification_manager_.reset(new StubNotificationUIManager); | 112 notification_manager_.reset(new StubNotificationUIManager); |
| 96 notification_service()->SetNotificationUIManagerForTesting( | 113 notification_service()->SetNotificationUIManagerForTesting( |
| 97 notification_manager()); | 114 notification_manager()); |
| 98 #endif | 115 #endif |
| 99 | 116 |
| 100 InProcessBrowserTest::SetUp(); | 117 InProcessBrowserTest::SetUp(); |
| 101 } | 118 } |
| 102 | 119 |
| 103 void SetUpCommandLine(base::CommandLine* command_line) override { | 120 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 104 // Enable experiemntal features for subscription restrictions. | 121 // Enable experimental features for subscription restrictions. |
| 105 command_line->AppendSwitch( | 122 command_line->AppendSwitch( |
| 106 switches::kEnableExperimentalWebPlatformFeatures); | 123 switches::kEnableExperimentalWebPlatformFeatures); |
| 107 InProcessBrowserTest::SetUpCommandLine(command_line); | 124 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 108 } | 125 } |
| 109 | 126 |
| 110 // InProcessBrowserTest: | 127 // InProcessBrowserTest: |
| 111 void SetUpOnMainThread() override { | 128 void SetUpOnMainThread() override { |
| 112 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 129 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 113 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 130 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 114 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 131 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 const std::string& expected_push_subscription_info, | 275 const std::string& expected_push_subscription_info, |
| 259 bool use_key) { | 276 bool use_key) { |
| 260 std::string script_result; | 277 std::string script_result; |
| 261 | 278 |
| 262 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 279 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 263 EXPECT_EQ("ok - service worker registered", script_result); | 280 EXPECT_EQ("ok - service worker registered", script_result); |
| 264 | 281 |
| 265 RequestAndAcceptPermission(); | 282 RequestAndAcceptPermission(); |
| 266 | 283 |
| 267 if (use_key) { | 284 if (use_key) { |
| 268 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); | 285 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| 286 ASSERT_EQ("manifest removed", script_result); |
| 287 |
| 288 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 269 } else { | 289 } else { |
| 270 // Test backwards compatibility with old ID based subscriptions. | 290 // Test backwards compatibility with old ID based subscriptions. |
| 271 EXPECT_TRUE(RunScript("subscribePushWithoutKey()", &script_result)); | 291 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 272 } | 292 } |
| 273 | 293 |
| 274 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), | 294 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), |
| 275 script_result); | 295 script_result); |
| 276 } | 296 } |
| 277 | 297 |
| 278 PushMessagingAppIdentifier | 298 PushMessagingAppIdentifier |
| 279 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( | 299 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( |
| 280 int64_t service_worker_registration_id) { | 300 int64_t service_worker_registration_id) { |
| 281 GURL origin = https_server()->GetURL("/").GetOrigin(); | 301 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 305 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 325 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 306 } | 326 } |
| 307 | 327 |
| 308 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 328 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 309 SubscribeSuccessNotificationsGranted) { | 329 SubscribeSuccessNotificationsGranted) { |
| 310 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 330 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 311 | 331 |
| 312 PushMessagingAppIdentifier app_identifier = | 332 PushMessagingAppIdentifier app_identifier = |
| 313 GetAppIdentifierForServiceWorkerRegistration(0LL); | 333 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 314 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 334 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 335 EXPECT_EQ(getTestApplicationServerKey(), |
| 336 gcm_service()->last_registered_sender_ids()[0]); |
| 316 } | 337 } |
| 317 | 338 |
| 318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 339 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 319 SubscribeSuccessNotificationsPrompt) { | 340 SubscribeSuccessNotificationsPrompt) { |
| 320 std::string script_result; | 341 std::string script_result; |
| 321 | 342 |
| 322 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 343 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 323 ASSERT_EQ("ok - service worker registered", script_result); | 344 ASSERT_EQ("ok - service worker registered", script_result); |
| 324 | 345 |
| 325 GetPermissionBubbleManager()->set_auto_response_for_test( | 346 GetPermissionBubbleManager()->set_auto_response_for_test( |
| 326 PermissionBubbleManager::ACCEPT_ALL); | 347 PermissionBubbleManager::ACCEPT_ALL); |
| 327 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 348 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 328 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 349 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 329 | 350 |
| 330 PushMessagingAppIdentifier app_identifier = | 351 PushMessagingAppIdentifier app_identifier = |
| 331 GetAppIdentifierForServiceWorkerRegistration(0LL); | 352 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 332 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 353 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 333 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 354 EXPECT_EQ(getTestApplicationServerKey(), |
| 355 gcm_service()->last_registered_sender_ids()[0]); |
| 334 } | 356 } |
| 335 | 357 |
| 336 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { | 358 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { |
| 337 std::string script_result; | 359 std::string script_result; |
| 338 | 360 |
| 339 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 361 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 340 ASSERT_EQ("ok - service worker registered", script_result); | 362 ASSERT_EQ("ok - service worker registered", script_result); |
| 341 | 363 |
| 342 RequestAndAcceptPermission(); | 364 RequestAndAcceptPermission(); |
| 343 | 365 |
| 344 ASSERT_TRUE(RunScript("subscribePushBadKey()", &script_result)); | 366 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); |
| 345 EXPECT_EQ( | 367 EXPECT_EQ( |
| 346 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " | 368 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " |
| 347 "The provided applicationServerKey is not valid.", | 369 "The provided applicationServerKey is not valid.", |
| 348 script_result); | 370 script_result); |
| 349 } | 371 } |
| 350 | 372 |
| 351 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 373 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 352 SubscribeFailureNotificationsBlocked) { | 374 SubscribeFailureNotificationsBlocked) { |
| 353 std::string script_result; | 375 std::string script_result; |
| 354 | 376 |
| 355 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 377 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 356 ASSERT_EQ("ok - service worker registered", script_result); | 378 ASSERT_EQ("ok - service worker registered", script_result); |
| 357 | 379 |
| 358 RequestAndDenyPermission(); | 380 RequestAndDenyPermission(); |
| 359 | 381 |
| 360 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 382 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 361 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 383 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 362 script_result); | 384 script_result); |
| 363 } | 385 } |
| 364 | 386 |
| 365 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { | 387 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { |
| 366 std::string script_result; | 388 std::string script_result; |
| 367 | 389 |
| 368 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 390 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 369 ASSERT_EQ("ok - service worker registered", script_result); | 391 ASSERT_EQ("ok - service worker registered", script_result); |
| 370 | 392 |
| 371 RequestAndAcceptPermission(); | 393 RequestAndAcceptPermission(); |
| 372 | 394 |
| 373 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 395 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
| 374 ASSERT_EQ("manifest removed", script_result); | 396 ASSERT_EQ("manifest removed", script_result); |
| 375 | 397 |
| 376 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 398 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 377 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing", | 399 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing", |
| 378 script_result); | 400 script_result); |
| 379 } | 401 } |
| 380 | 402 |
| 381 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { | 403 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { |
| 382 std::string script_result; | 404 std::string script_result; |
| 383 | 405 |
| 384 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 406 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 385 ASSERT_EQ("ok - service worker registered", script_result); | 407 ASSERT_EQ("ok - service worker registered", script_result); |
| 386 | 408 |
| 387 RequestAndAcceptPermission(); | 409 RequestAndAcceptPermission(); |
| 388 | 410 |
| 389 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); | 411 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); |
| 390 ASSERT_EQ("sender id removed from manifest", script_result); | 412 ASSERT_EQ("sender id removed from manifest", script_result); |
| 391 | 413 |
| 392 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 414 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 393 EXPECT_EQ( | 415 EXPECT_EQ( |
| 394 "AbortError - Registration failed - gcm_sender_id not found in manifest", | 416 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 395 script_result); | 417 script_result); |
| 396 } | 418 } |
| 397 | 419 |
| 398 // TODO(johnme): Test subscribing from a worker - see https://crbug.com/437298. | |
| 399 | |
| 400 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, | 420 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, |
| 401 RegisterFailureEmptyPushSubscriptionOptions) { | 421 RegisterFailureEmptyPushSubscriptionOptions) { |
| 402 std::string script_result; | 422 std::string script_result; |
| 403 | 423 |
| 404 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 424 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 405 ASSERT_EQ("ok - service worker registered", script_result); | 425 ASSERT_EQ("ok - service worker registered", script_result); |
| 406 | 426 |
| 407 RequestAndAcceptPermission(); | 427 RequestAndAcceptPermission(); |
| 408 | 428 |
| 409 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 429 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 410 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 430 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 411 script_result); | 431 script_result); |
| 412 } | 432 } |
| 413 | 433 |
| 434 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) { |
| 435 std::string script_result; |
| 436 |
| 437 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 438 ASSERT_EQ("ok - service worker registered", script_result); |
| 439 |
| 440 RequestAndAcceptPermission(); |
| 441 |
| 442 LoadTestPage(); // Reload to become controlled. |
| 443 |
| 444 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 445 ASSERT_EQ("true - is controlled", script_result); |
| 446 |
| 447 // Try to subscribe from a worker without a key. This should fail. |
| 448 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 449 EXPECT_EQ( |
| 450 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 451 script_result); |
| 452 // Now run the subscribe from the service worker with a key. This |
| 453 // should succeed, and write the key to the datastore. |
| 454 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result)); |
| 455 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 456 |
| 457 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 458 EXPECT_EQ("unsubscribe result: true", script_result); |
| 459 EXPECT_NE(push_service(), GetAppHandler()); |
| 460 |
| 461 // Now run the subscribe from the service worker without a key. |
| 462 // In this case, the key will be read from the datastore. |
| 463 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 464 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); |
| 465 |
| 466 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 467 EXPECT_EQ("unsubscribe result: true", script_result); |
| 468 EXPECT_NE(push_service(), GetAppHandler()); |
| 469 } |
| 470 |
| 471 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) { |
| 472 std::string script_result; |
| 473 |
| 474 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 475 ASSERT_EQ("ok - service worker registered", script_result); |
| 476 |
| 477 RequestAndAcceptPermission(); |
| 478 |
| 479 LoadTestPage(); // Reload to become controlled. |
| 480 |
| 481 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 482 ASSERT_EQ("true - is controlled", script_result); |
| 483 |
| 484 // Try to subscribe from a worker without a key. This should fail. |
| 485 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 486 EXPECT_EQ( |
| 487 "AbortError - Registration failed - gcm_sender_id not found in manifest", |
| 488 script_result); |
| 489 EXPECT_NE(push_service(), GetAppHandler()); |
| 490 |
| 491 // Run the subscription from the document without a key, this will trigger |
| 492 // the code to read sender id from the manifest and will write it to the |
| 493 // datastore. |
| 494 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result)); |
| 495 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 496 |
| 497 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 498 EXPECT_EQ("unsubscribe result: true", script_result); |
| 499 EXPECT_NE(push_service(), GetAppHandler()); |
| 500 |
| 501 // Now run the subscribe from the service worker without a key. |
| 502 // In this case, the sender id will be read from the datastore. |
| 503 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result)); |
| 504 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result); |
| 505 |
| 506 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 507 EXPECT_EQ("unsubscribe result: true", script_result); |
| 508 EXPECT_NE(push_service(), GetAppHandler()); |
| 509 } |
| 510 |
| 414 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). | 511 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). |
| 415 #if defined(OS_WIN) || defined(OS_LINUX) | 512 #if defined(OS_WIN) || defined(OS_LINUX) |
| 416 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted | 513 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted |
| 417 #else | 514 #else |
| 418 #define MAYBE_SubscribePersisted SubscribePersisted | 515 #define MAYBE_SubscribePersisted SubscribePersisted |
| 419 #endif | 516 #endif |
| 420 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { | 517 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { |
| 421 std::string script_result; | 518 std::string script_result; |
| 422 | 519 |
| 423 // First, test that Service Worker registration IDs are assigned in order of | 520 // First, test that Service Worker registration IDs are assigned in order of |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 596 } |
| 500 | 597 |
| 501 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 598 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| 502 std::string script_result; | 599 std::string script_result; |
| 503 | 600 |
| 504 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 601 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 505 | 602 |
| 506 PushMessagingAppIdentifier app_identifier = | 603 PushMessagingAppIdentifier app_identifier = |
| 507 GetAppIdentifierForServiceWorkerRegistration(0LL); | 604 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 508 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 605 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 509 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 606 EXPECT_EQ(getTestApplicationServerKey(), |
| 607 gcm_service()->last_registered_sender_ids()[0]); |
| 510 | 608 |
| 511 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 609 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 512 ASSERT_EQ("false - is not controlled", script_result); | 610 ASSERT_EQ("false - is not controlled", script_result); |
| 513 | 611 |
| 514 LoadTestPage(); // Reload to become controlled. | 612 LoadTestPage(); // Reload to become controlled. |
| 515 | 613 |
| 516 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 614 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 517 ASSERT_EQ("true - is controlled", script_result); | 615 ASSERT_EQ("true - is controlled", script_result); |
| 518 | 616 |
| 519 gcm::IncomingMessage message; | 617 gcm::IncomingMessage message; |
| 520 message.sender_id = "1234567890"; | 618 message.sender_id = std::string(getTestApplicationServerKey()); |
| 521 message.raw_data = "testdata"; | 619 message.raw_data = "testdata"; |
| 522 message.decrypted = true; | 620 message.decrypted = true; |
| 523 push_service()->OnMessage(app_identifier.app_id(), message); | 621 push_service()->OnMessage(app_identifier.app_id(), message); |
| 524 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 622 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 525 EXPECT_EQ("testdata", script_result); | 623 EXPECT_EQ("testdata", script_result); |
| 526 } | 624 } |
| 527 | 625 |
| 528 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { | 626 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { |
| 529 std::string script_result; | 627 std::string script_result; |
| 530 | 628 |
| 531 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 629 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 532 | 630 |
| 533 PushMessagingAppIdentifier app_identifier = | 631 PushMessagingAppIdentifier app_identifier = |
| 534 GetAppIdentifierForServiceWorkerRegistration(0LL); | 632 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 535 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 633 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 536 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 634 EXPECT_EQ(getTestApplicationServerKey(), |
| 635 gcm_service()->last_registered_sender_ids()[0]); |
| 537 | 636 |
| 538 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 637 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 539 ASSERT_EQ("false - is not controlled", script_result); | 638 ASSERT_EQ("false - is not controlled", script_result); |
| 540 | 639 |
| 541 LoadTestPage(); // Reload to become controlled. | 640 LoadTestPage(); // Reload to become controlled. |
| 542 | 641 |
| 543 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 642 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 544 ASSERT_EQ("true - is controlled", script_result); | 643 ASSERT_EQ("true - is controlled", script_result); |
| 545 | 644 |
| 546 gcm::IncomingMessage message; | 645 gcm::IncomingMessage message; |
| 547 message.sender_id = "1234567890"; | 646 message.sender_id = std::string(getTestApplicationServerKey()); |
| 548 message.decrypted = false; | 647 message.decrypted = false; |
| 549 | 648 |
| 550 push_service()->OnMessage(app_identifier.app_id(), message); | 649 push_service()->OnMessage(app_identifier.app_id(), message); |
| 551 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 650 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 552 EXPECT_EQ("[NULL]", script_result); | 651 EXPECT_EQ("[NULL]", script_result); |
| 553 } | 652 } |
| 554 | 653 |
| 555 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 654 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| 556 std::string script_result; | 655 std::string script_result; |
| 557 | 656 |
| 558 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 657 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 559 | 658 |
| 560 PushMessagingAppIdentifier app_identifier = | 659 PushMessagingAppIdentifier app_identifier = |
| 561 GetAppIdentifierForServiceWorkerRegistration(0LL); | 660 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 562 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 661 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 563 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 662 EXPECT_EQ(getTestApplicationServerKey(), |
| 663 gcm_service()->last_registered_sender_ids()[0]); |
| 564 | 664 |
| 565 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 665 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 566 ASSERT_EQ("false - is not controlled", script_result); | 666 ASSERT_EQ("false - is not controlled", script_result); |
| 567 | 667 |
| 568 LoadTestPage(); // Reload to become controlled. | 668 LoadTestPage(); // Reload to become controlled. |
| 569 | 669 |
| 570 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 670 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 571 ASSERT_EQ("true - is controlled", script_result); | 671 ASSERT_EQ("true - is controlled", script_result); |
| 572 | 672 |
| 573 // Unregister service worker. Sending a message should now fail. | 673 // Unregister service worker. Sending a message should now fail. |
| 574 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 674 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 575 ASSERT_EQ("service worker unregistration status: true", script_result); | 675 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 576 | 676 |
| 577 // When the push service will receive it next message, given that there is no | 677 // When the push service will receive it next message, given that there is no |
| 578 // SW available, it should unregister |app_identifier.app_id()|. | 678 // SW available, it should unregister |app_identifier.app_id()|. |
| 579 UnregistrationCallback callback; | 679 UnregistrationCallback callback; |
| 580 gcm_service()->SetUnregisterCallback( | 680 gcm_service()->SetUnregisterCallback( |
| 581 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); | 681 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); |
| 582 | 682 |
| 583 gcm::IncomingMessage message; | 683 gcm::IncomingMessage message; |
| 584 message.sender_id = "1234567890"; | 684 message.sender_id = std::string(getTestApplicationServerKey()); |
| 585 message.raw_data = "testdata"; | 685 message.raw_data = "testdata"; |
| 586 message.decrypted = true; | 686 message.decrypted = true; |
| 587 push_service()->OnMessage(app_identifier.app_id(), message); | 687 push_service()->OnMessage(app_identifier.app_id(), message); |
| 588 | 688 |
| 589 callback.WaitUntilSatisfied(); | 689 callback.WaitUntilSatisfied(); |
| 590 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); | 690 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); |
| 591 | 691 |
| 592 // No push data should have been received. | 692 // No push data should have been received. |
| 593 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 693 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 594 EXPECT_EQ("null", script_result); | 694 EXPECT_EQ("null", script_result); |
| 595 } | 695 } |
| 596 | 696 |
| 597 #if defined(ENABLE_NOTIFICATIONS) | 697 #if defined(ENABLE_NOTIFICATIONS) |
| 598 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 698 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 599 PushEventEnforcesUserVisibleNotification) { | 699 PushEventEnforcesUserVisibleNotification) { |
| 600 std::string script_result; | 700 std::string script_result; |
| 601 | 701 |
| 602 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 702 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 603 | 703 |
| 604 PushMessagingAppIdentifier app_identifier = | 704 PushMessagingAppIdentifier app_identifier = |
| 605 GetAppIdentifierForServiceWorkerRegistration(0LL); | 705 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 606 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 706 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 607 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 707 EXPECT_EQ(getTestApplicationServerKey(), |
| 708 gcm_service()->last_registered_sender_ids()[0]); |
| 608 | 709 |
| 609 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 710 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 610 ASSERT_EQ("false - is not controlled", script_result); | 711 ASSERT_EQ("false - is not controlled", script_result); |
| 611 | 712 |
| 612 LoadTestPage(); // Reload to become controlled. | 713 LoadTestPage(); // Reload to become controlled. |
| 613 | 714 |
| 614 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 715 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 615 ASSERT_EQ("true - is controlled", script_result); | 716 ASSERT_EQ("true - is controlled", script_result); |
| 616 | 717 |
| 617 notification_manager()->CancelAll(); | 718 notification_manager()->CancelAll(); |
| 618 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 719 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 619 | 720 |
| 620 // We'll need to specify the web_contents in which to eval script, since we're | 721 // We'll need to specify the web_contents in which to eval script, since we're |
| 621 // going to run script in a background tab. | 722 // going to run script in a background tab. |
| 622 content::WebContents* web_contents = | 723 content::WebContents* web_contents = |
| 623 GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 724 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 624 | 725 |
| 625 // If the site is visible in an active tab, we should not force a notification | 726 // If the site is visible in an active tab, we should not force a notification |
| 626 // to be shown. Try it twice, since we allow one mistake per 10 push events. | 727 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
| 627 gcm::IncomingMessage message; | 728 gcm::IncomingMessage message; |
| 628 message.sender_id = "1234567890"; | 729 message.sender_id = std::string(getTestApplicationServerKey()); |
| 629 message.decrypted = true; | 730 message.decrypted = true; |
| 630 for (int n = 0; n < 2; n++) { | 731 for (int n = 0; n < 2; n++) { |
| 631 message.raw_data = "testdata"; | 732 message.raw_data = "testdata"; |
| 632 SendMessageAndWaitUntilHandled(app_identifier, message); | 733 SendMessageAndWaitUntilHandled(app_identifier, message); |
| 633 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 734 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 634 EXPECT_EQ("testdata", script_result); | 735 EXPECT_EQ("testdata", script_result); |
| 635 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 736 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 636 } | 737 } |
| 637 | 738 |
| 638 // Open a blank foreground tab so site is no longer visible. | 739 // Open a blank foreground tab so site is no longer visible. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 805 |
| 705 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 806 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 706 PushEventEnforcesUserVisibleNotificationAfterQueue) { | 807 PushEventEnforcesUserVisibleNotificationAfterQueue) { |
| 707 std::string script_result; | 808 std::string script_result; |
| 708 | 809 |
| 709 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 810 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 710 | 811 |
| 711 PushMessagingAppIdentifier app_identifier = | 812 PushMessagingAppIdentifier app_identifier = |
| 712 GetAppIdentifierForServiceWorkerRegistration(0LL); | 813 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 713 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 814 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 714 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 815 EXPECT_EQ(getTestApplicationServerKey(), |
| 816 gcm_service()->last_registered_sender_ids()[0]); |
| 715 | 817 |
| 716 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 818 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 717 ASSERT_EQ("false - is not controlled", script_result); | 819 ASSERT_EQ("false - is not controlled", script_result); |
| 718 | 820 |
| 719 LoadTestPage(); // Reload to become controlled. | 821 LoadTestPage(); // Reload to become controlled. |
| 720 | 822 |
| 721 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 823 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 722 ASSERT_EQ("true - is controlled", script_result); | 824 ASSERT_EQ("true - is controlled", script_result); |
| 723 | 825 |
| 724 // Fire off two push messages in sequence, only the second one of which will | 826 // Fire off two push messages in sequence, only the second one of which will |
| 725 // display a notification. The additional round-trip and I/O required by the | 827 // display a notification. The additional round-trip and I/O required by the |
| 726 // second message, which shows a notification, should give us a reasonable | 828 // second message, which shows a notification, should give us a reasonable |
| 727 // confidence that the ordering will be maintained. | 829 // confidence that the ordering will be maintained. |
| 728 | 830 |
| 729 std::vector<size_t> number_of_notifications_shown; | 831 std::vector<size_t> number_of_notifications_shown; |
| 730 | 832 |
| 731 gcm::IncomingMessage message; | 833 gcm::IncomingMessage message; |
| 732 message.sender_id = "1234567890"; | 834 message.sender_id = std::string(getTestApplicationServerKey()); |
| 733 message.decrypted = true; | 835 message.decrypted = true; |
| 734 | 836 |
| 735 { | 837 { |
| 736 base::RunLoop run_loop; | 838 base::RunLoop run_loop; |
| 737 push_service()->SetMessageCallbackForTesting(base::Bind( | 839 push_service()->SetMessageCallbackForTesting(base::Bind( |
| 738 &PushMessagingBrowserTest::OnDeliveryFinished, base::Unretained(this), | 840 &PushMessagingBrowserTest::OnDeliveryFinished, base::Unretained(this), |
| 739 &number_of_notifications_shown, | 841 &number_of_notifications_shown, |
| 740 base::BarrierClosure(2 /* num_closures */, run_loop.QuitClosure()))); | 842 base::BarrierClosure(2 /* num_closures */, run_loop.QuitClosure()))); |
| 741 | 843 |
| 742 message.raw_data = "testdata"; | 844 message.raw_data = "testdata"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 757 PushEventNotificationWithoutEventWaitUntil) { | 859 PushEventNotificationWithoutEventWaitUntil) { |
| 758 std::string script_result; | 860 std::string script_result; |
| 759 content::WebContents* web_contents = | 861 content::WebContents* web_contents = |
| 760 GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 862 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 761 | 863 |
| 762 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 864 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 763 | 865 |
| 764 PushMessagingAppIdentifier app_identifier = | 866 PushMessagingAppIdentifier app_identifier = |
| 765 GetAppIdentifierForServiceWorkerRegistration(0LL); | 867 GetAppIdentifierForServiceWorkerRegistration(0LL); |
| 766 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); | 868 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); |
| 767 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 869 EXPECT_EQ(getTestApplicationServerKey(), |
| 870 gcm_service()->last_registered_sender_ids()[0]); |
| 768 | 871 |
| 769 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 872 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 770 ASSERT_EQ("false - is not controlled", script_result); | 873 ASSERT_EQ("false - is not controlled", script_result); |
| 771 | 874 |
| 772 LoadTestPage(); // Reload to become controlled. | 875 LoadTestPage(); // Reload to become controlled. |
| 773 | 876 |
| 774 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 877 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 775 ASSERT_EQ("true - is controlled", script_result); | 878 ASSERT_EQ("true - is controlled", script_result); |
| 776 | 879 |
| 777 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 880 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 778 new content::MessageLoopRunner; | 881 new content::MessageLoopRunner; |
| 779 notification_manager()->SetNotificationAddedCallback( | 882 notification_manager()->SetNotificationAddedCallback( |
| 780 message_loop_runner->QuitClosure()); | 883 message_loop_runner->QuitClosure()); |
| 781 | 884 |
| 782 gcm::IncomingMessage message; | 885 gcm::IncomingMessage message; |
| 783 message.sender_id = "1234567890"; | 886 message.sender_id = std::string(getTestApplicationServerKey()); |
| 784 message.raw_data = "shownotification-without-waituntil"; | 887 message.raw_data = "shownotification-without-waituntil"; |
| 785 message.decrypted = true; | 888 message.decrypted = true; |
| 786 push_service()->OnMessage(app_identifier.app_id(), message); | 889 push_service()->OnMessage(app_identifier.app_id(), message); |
| 787 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 890 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 788 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); | 891 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); |
| 789 | 892 |
| 790 message_loop_runner->Run(); | 893 message_loop_runner->Run(); |
| 791 | 894 |
| 792 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 895 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 793 EXPECT_EQ("push_test_tag", | 896 EXPECT_EQ("push_test_tag", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 810 } | 913 } |
| 811 | 914 |
| 812 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { | 915 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { |
| 813 std::string script_result; | 916 std::string script_result; |
| 814 | 917 |
| 815 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 918 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 816 ASSERT_EQ("ok - service worker registered", script_result); | 919 ASSERT_EQ("ok - service worker registered", script_result); |
| 817 | 920 |
| 818 RequestAndAcceptPermission(); | 921 RequestAndAcceptPermission(); |
| 819 | 922 |
| 820 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 923 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 821 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); | 924 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); |
| 822 | 925 |
| 823 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 926 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 824 EXPECT_EQ("permission status - granted", script_result); | 927 EXPECT_EQ("permission status - granted", script_result); |
| 825 } | 928 } |
| 826 | 929 |
| 827 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { | 930 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { |
| 828 std::string script_result; | 931 std::string script_result; |
| 829 | 932 |
| 830 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 933 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 831 ASSERT_EQ("ok - service worker registered", script_result); | 934 ASSERT_EQ("ok - service worker registered", script_result); |
| 832 | 935 |
| 833 RequestAndDenyPermission(); | 936 RequestAndDenyPermission(); |
| 834 | 937 |
| 835 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); | 938 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); |
| 836 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", | 939 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", |
| 837 script_result); | 940 script_result); |
| 838 | 941 |
| 839 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 942 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 840 EXPECT_EQ("permission status - denied", script_result); | 943 EXPECT_EQ("permission status - denied", script_result); |
| 841 } | 944 } |
| 842 | 945 |
| 843 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { | 946 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { |
| 844 std::string script_result; | 947 std::string script_result; |
| 845 | 948 |
| 846 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 949 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 847 EXPECT_EQ("ok - service worker registered", script_result); | 950 EXPECT_EQ("ok - service worker registered", script_result); |
| 848 | 951 |
| 849 // Resolves true if there was a subscription. | 952 // Resolves true if there was a subscription. |
| 850 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 953 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); |
| 851 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 954 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 852 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 955 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 853 EXPECT_EQ("unsubscribe result: true", script_result); | 956 EXPECT_EQ("unsubscribe result: true", script_result); |
| 854 | 957 |
| 855 // Resolves false if there was no longer a subscription. | 958 // Resolves false if there was no longer a subscription. |
| 856 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 959 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 857 EXPECT_EQ("unsubscribe result: false", script_result); | 960 EXPECT_EQ("unsubscribe result: false", script_result); |
| 858 | 961 |
| 859 // Doesn't reject if there was a network error (deactivates subscription | 962 // Doesn't reject if there was a network error (deactivates subscription |
| 860 // locally anyway). | 963 // locally anyway). |
| 861 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); | 964 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */, false); |
| 862 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); | 965 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); |
| 863 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 966 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 864 EXPECT_EQ("unsubscribe result: true", script_result); | 967 EXPECT_EQ("unsubscribe result: true", script_result); |
| 865 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 968 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 866 EXPECT_EQ("false - not subscribed", script_result); | 969 EXPECT_EQ("false - not subscribed", script_result); |
| 867 | 970 |
| 868 // Doesn't reject if there were other push service errors (deactivates | 971 // Doesn't reject if there were other push service errors (deactivates |
| 869 // subscription locally anyway). | 972 // subscription locally anyway). |
| 870 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); | 973 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */, false); |
| 871 gcm_service()->AddExpectedUnregisterResponse( | 974 gcm_service()->AddExpectedUnregisterResponse( |
| 872 gcm::GCMClient::INVALID_PARAMETER); | 975 gcm::GCMClient::INVALID_PARAMETER); |
| 873 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 976 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 874 EXPECT_EQ("unsubscribe result: true", script_result); | 977 EXPECT_EQ("unsubscribe result: true", script_result); |
| 875 | 978 |
| 876 // Unsubscribing (with an existing reference to a PushSubscription), after | 979 // Unsubscribing (with an existing reference to a PushSubscription), after |
| 877 // unregistering the Service Worker, just means push subscription isn't found. | 980 // unregistering the Service Worker, just means push subscription isn't found. |
| 878 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */); | 981 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */, false); |
| 879 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 982 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 880 ASSERT_EQ("service worker unregistration status: true", script_result); | 983 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 881 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 984 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 882 EXPECT_EQ("unsubscribe result: false", script_result); | 985 EXPECT_EQ("unsubscribe result: false", script_result); |
| 883 } | 986 } |
| 884 | 987 |
| 885 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 988 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 886 GlobalResetPushPermissionUnsubscribes) { | 989 GlobalResetPushPermissionUnsubscribes) { |
| 887 std::string script_result; | 990 std::string script_result; |
| 888 | 991 |
| 889 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 992 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
| 890 | 993 |
| 891 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 994 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 892 EXPECT_EQ("true - subscribed", script_result); | 995 EXPECT_EQ("true - subscribed", script_result); |
| 893 | 996 |
| 894 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 997 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 895 EXPECT_EQ("permission status - granted", script_result); | 998 EXPECT_EQ("permission status - granted", script_result); |
| 896 | 999 |
| 897 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1000 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 898 new content::MessageLoopRunner; | 1001 new content::MessageLoopRunner; |
| 899 push_service()->SetContentSettingChangedCallbackForTesting( | 1002 push_service()->SetContentSettingChangedCallbackForTesting( |
| 900 message_loop_runner->QuitClosure()); | 1003 message_loop_runner->QuitClosure()); |
| 901 | 1004 |
| 902 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1005 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 903 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 1006 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 904 | 1007 |
| 1008 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1009 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1010 |
| 905 message_loop_runner->Run(); | 1011 message_loop_runner->Run(); |
| 906 | 1012 |
| 907 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1013 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 908 EXPECT_EQ("permission status - prompt", script_result); | 1014 EXPECT_EQ("permission status - prompt", script_result); |
| 909 | 1015 |
| 910 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1016 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 911 EXPECT_EQ("false - not subscribed", script_result); | 1017 EXPECT_EQ("false - not subscribed", script_result); |
| 912 } | 1018 } |
| 913 | 1019 |
| 914 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 1020 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 926 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 1032 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 927 new content::MessageLoopRunner; | 1033 new content::MessageLoopRunner; |
| 928 push_service()->SetContentSettingChangedCallbackForTesting( | 1034 push_service()->SetContentSettingChangedCallbackForTesting( |
| 929 message_loop_runner->QuitClosure()); | 1035 message_loop_runner->QuitClosure()); |
| 930 | 1036 |
| 931 GURL origin = https_server()->GetURL("/").GetOrigin(); | 1037 GURL origin = https_server()->GetURL("/").GetOrigin(); |
| 932 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1038 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 933 ->SetContentSettingDefaultScope(origin, origin, | 1039 ->SetContentSettingDefaultScope(origin, origin, |
| 934 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 1040 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 935 std::string(), CONTENT_SETTING_DEFAULT); | 1041 std::string(), CONTENT_SETTING_DEFAULT); |
| 1042 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1043 ->SetContentSettingDefaultScope(origin, origin, |
| 1044 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1045 std::string(), CONTENT_SETTING_DEFAULT); |
| 936 | 1046 |
| 937 message_loop_runner->Run(); | 1047 message_loop_runner->Run(); |
| 938 | 1048 |
| 939 ASSERT_TRUE(RunScript("permissionState()", &script_result)); | 1049 ASSERT_TRUE(RunScript("permissionState()", &script_result)); |
| 940 EXPECT_EQ("permission status - prompt", script_result); | 1050 EXPECT_EQ("permission status - prompt", script_result); |
| 941 | 1051 |
| 942 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1052 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
| 943 EXPECT_EQ("false - not subscribed", script_result); | 1053 EXPECT_EQ("false - not subscribed", script_result); |
| 944 } | 1054 } |
| 945 | 1055 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 observer.BlockUntilCompletion(); | 1295 observer.BlockUntilCompletion(); |
| 1186 | 1296 |
| 1187 base::RunLoop run_loop; | 1297 base::RunLoop run_loop; |
| 1188 push_service()->SetContentSettingChangedCallbackForTesting( | 1298 push_service()->SetContentSettingChangedCallbackForTesting( |
| 1189 run_loop.QuitClosure()); | 1299 run_loop.QuitClosure()); |
| 1190 | 1300 |
| 1191 // This shouldn't (asynchronously) cause a DCHECK. | 1301 // This shouldn't (asynchronously) cause a DCHECK. |
| 1192 // TODO(johnme): Get this test running on Android, which has a different | 1302 // TODO(johnme): Get this test running on Android, which has a different |
| 1193 // codepath due to sender_id being required for unsubscribing there. | 1303 // codepath due to sender_id being required for unsubscribing there. |
| 1194 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) | 1304 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1305 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 1306 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) |
| 1195 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 1307 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 1196 | 1308 |
| 1197 run_loop.Run(); | 1309 run_loop.Run(); |
| 1198 | 1310 |
| 1199 // |app_identifier| should no longer be stored in prefs. | 1311 // |app_identifier| should no longer be stored in prefs. |
| 1200 PushMessagingAppIdentifier stored_app_identifier2 = | 1312 PushMessagingAppIdentifier stored_app_identifier2 = |
| 1201 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), | 1313 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), |
| 1202 app_identifier.app_id()); | 1314 app_identifier.app_id()); |
| 1203 EXPECT_TRUE(stored_app_identifier2.is_null()); | 1315 EXPECT_TRUE(stored_app_identifier2.is_null()); |
| 1204 } | 1316 } |
| 1205 | 1317 |
| 1206 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { | 1318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { |
| 1207 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 1319 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false); |
| 1208 | 1320 |
| 1209 std::string first_public_key; | 1321 std::string first_public_key; |
| 1210 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); | 1322 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); |
| 1211 EXPECT_GE(first_public_key.size(), 32u); | 1323 EXPECT_GE(first_public_key.size(), 32u); |
| 1212 | 1324 |
| 1213 std::string script_result; | 1325 std::string script_result; |
| 1214 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1326 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1215 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1327 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1216 EXPECT_EQ("unsubscribe result: true", script_result); | 1328 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1217 | 1329 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1447 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1336 | 1448 |
| 1337 // After dropping the last subscription background mode is still inactive. | 1449 // After dropping the last subscription background mode is still inactive. |
| 1338 std::string script_result; | 1450 std::string script_result; |
| 1339 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1451 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
| 1340 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1452 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
| 1341 EXPECT_EQ("unsubscribe result: true", script_result); | 1453 EXPECT_EQ("unsubscribe result: true", script_result); |
| 1342 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1454 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
| 1343 } | 1455 } |
| 1344 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1456 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
| OLD | NEW |