| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 browser()->profile(), origin, service_worker_registration_id); | 288 browser()->profile(), origin, service_worker_registration_id); |
| 289 EXPECT_TRUE(application_id.IsValid()); | 289 EXPECT_TRUE(application_id.IsValid()); |
| 290 return application_id; | 290 return application_id; |
| 291 } | 291 } |
| 292 | 292 |
| 293 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 293 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 294 RegisterSuccessNotificationsGranted) { | 294 RegisterSuccessNotificationsGranted) { |
| 295 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 295 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 296 | 296 |
| 297 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 297 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 298 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 298 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 299 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 299 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 300 } | 300 } |
| 301 | 301 |
| 302 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 302 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 303 RegisterSuccessNotificationsPrompt) { | 303 RegisterSuccessNotificationsPrompt) { |
| 304 std::string script_result; | 304 std::string script_result; |
| 305 | 305 |
| 306 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 306 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 307 ASSERT_EQ("ok - service worker registered", script_result); | 307 ASSERT_EQ("ok - service worker registered", script_result); |
| 308 | 308 |
| 309 InfoBarResponder accepting_responder(browser(), true); | 309 InfoBarResponder accepting_responder(browser(), true); |
| 310 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 310 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
| 311 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); | 311 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); |
| 312 | 312 |
| 313 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 313 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 314 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 314 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 316 } | 316 } |
| 317 | 317 |
| 318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 319 RegisterFailureNotificationsBlocked) { | 319 RegisterFailureNotificationsBlocked) { |
| 320 std::string script_result; | 320 std::string script_result; |
| 321 | 321 |
| 322 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 322 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 323 ASSERT_EQ("ok - service worker registered", script_result); | 323 ASSERT_EQ("ok - service worker registered", script_result); |
| 324 | 324 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 354 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { | 354 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { |
| 355 std::string script_result; | 355 std::string script_result; |
| 356 | 356 |
| 357 // First, test that Service Worker registration IDs are assigned in order of | 357 // First, test that Service Worker registration IDs are assigned in order of |
| 358 // registering the Service Workers, and the (fake) push registration ids are | 358 // registering the Service Workers, and the (fake) push registration ids are |
| 359 // assigned in order of push registration (even when these orders are | 359 // assigned in order of push registration (even when these orders are |
| 360 // different). | 360 // different). |
| 361 | 361 |
| 362 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 362 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 363 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL); | 363 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL); |
| 364 EXPECT_EQ(app_id_sw0.app_id_guid, gcm_service()->last_registered_app_id()); | 364 EXPECT_EQ(app_id_sw0.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 365 | 365 |
| 366 LoadTestPage("files/push_messaging/subscope1/test.html"); | 366 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 367 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 367 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 368 ASSERT_EQ("ok - service worker registered", script_result); | 368 ASSERT_EQ("ok - service worker registered", script_result); |
| 369 | 369 |
| 370 LoadTestPage("files/push_messaging/subscope2/test.html"); | 370 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 371 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 371 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 372 ASSERT_EQ("ok - service worker registered", script_result); | 372 ASSERT_EQ("ok - service worker registered", script_result); |
| 373 | 373 |
| 374 // Note that we need to reload the page after registering, otherwise | 374 // Note that we need to reload the page after registering, otherwise |
| 375 // navigator.serviceWorker.ready is going to be resolved with the parent | 375 // navigator.serviceWorker.ready is going to be resolved with the parent |
| 376 // Service Worker which still controls the page. | 376 // Service Worker which still controls the page. |
| 377 LoadTestPage("files/push_messaging/subscope2/test.html"); | 377 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 378 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); | 378 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); |
| 379 PushMessagingApplicationId app_id_sw2 = GetServiceWorkerAppId(2LL); | 379 PushMessagingApplicationId app_id_sw2 = GetServiceWorkerAppId(2LL); |
| 380 EXPECT_EQ(app_id_sw2.app_id_guid, gcm_service()->last_registered_app_id()); | 380 EXPECT_EQ(app_id_sw2.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 381 | 381 |
| 382 LoadTestPage("files/push_messaging/subscope1/test.html"); | 382 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 383 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); | 383 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); |
| 384 PushMessagingApplicationId app_id_sw1 = GetServiceWorkerAppId(1LL); | 384 PushMessagingApplicationId app_id_sw1 = GetServiceWorkerAppId(1LL); |
| 385 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 385 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 386 | 386 |
| 387 // Now test that the Service Worker registration IDs and push registration IDs | 387 // Now test that the Service Worker registration IDs and push registration IDs |
| 388 // generated above were persisted to SW storage, by checking that they are | 388 // generated above were persisted to SW storage, by checking that they are |
| 389 // unchanged despite requesting them in a different order. | 389 // unchanged despite requesting them in a different order. |
| 390 // TODO(johnme): Ideally we would restart the browser at this point to check | 390 // TODO(johnme): Ideally we would restart the browser at this point to check |
| 391 // they were persisted to disk, but that's not currently possible since the | 391 // they were persisted to disk, but that's not currently possible since the |
| 392 // test server uses random port numbers for each test (even PRE_Foo and Foo), | 392 // test server uses random port numbers for each test (even PRE_Foo and Foo), |
| 393 // so we wouldn't be able to load the test pages with the same origin. | 393 // so we wouldn't be able to load the test pages with the same origin. |
| 394 | 394 |
| 395 LoadTestPage("files/push_messaging/subscope1/test.html"); | 395 LoadTestPage("files/push_messaging/subscope1/test.html"); |
| 396 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); | 396 TryToRegisterSuccessfully("1-2" /* expected_push_registration_id */); |
| 397 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 397 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 398 | 398 |
| 399 LoadTestPage("files/push_messaging/subscope2/test.html"); | 399 LoadTestPage("files/push_messaging/subscope2/test.html"); |
| 400 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); | 400 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); |
| 401 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 401 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 402 | 402 |
| 403 LoadTestPage(); | 403 LoadTestPage(); |
| 404 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 404 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 405 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); | 405 EXPECT_EQ(app_id_sw1.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 408 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| 409 std::string script_result; | 409 std::string script_result; |
| 410 | 410 |
| 411 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 411 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 412 | 412 |
| 413 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 413 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 414 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 414 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 415 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 415 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 416 | 416 |
| 417 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 417 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 418 ASSERT_EQ("false - is not controlled", script_result); | 418 ASSERT_EQ("false - is not controlled", script_result); |
| 419 | 419 |
| 420 LoadTestPage(); // Reload to become controlled. | 420 LoadTestPage(); // Reload to become controlled. |
| 421 | 421 |
| 422 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 422 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 423 ASSERT_EQ("true - is controlled", script_result); | 423 ASSERT_EQ("true - is controlled", script_result); |
| 424 | 424 |
| 425 GCMClient::IncomingMessage message; | 425 GCMClient::IncomingMessage message; |
| 426 message.data["data"] = "testdata"; | 426 message.data["data"] = "testdata"; |
| 427 push_service()->OnMessage(app_id.app_id_guid, message); | 427 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 428 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 428 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 429 EXPECT_EQ("testdata", script_result); | 429 EXPECT_EQ("testdata", script_result); |
| 430 } | 430 } |
| 431 | 431 |
| 432 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 432 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| 433 std::string script_result; | 433 std::string script_result; |
| 434 | 434 |
| 435 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 435 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 436 | 436 |
| 437 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 437 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 438 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 438 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 439 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 439 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 440 | 440 |
| 441 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 441 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 442 ASSERT_EQ("false - is not controlled", script_result); | 442 ASSERT_EQ("false - is not controlled", script_result); |
| 443 | 443 |
| 444 LoadTestPage(); // Reload to become controlled. | 444 LoadTestPage(); // Reload to become controlled. |
| 445 | 445 |
| 446 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 446 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 447 ASSERT_EQ("true - is controlled", script_result); | 447 ASSERT_EQ("true - is controlled", script_result); |
| 448 | 448 |
| 449 // Unregister service worker. Sending a message should now fail. | 449 // Unregister service worker. Sending a message should now fail. |
| 450 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 450 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
| 451 ASSERT_EQ("service worker unregistration status: true", script_result); | 451 ASSERT_EQ("service worker unregistration status: true", script_result); |
| 452 | 452 |
| 453 // When the push service will receive it next message, given that there is no | 453 // When the push service will receive it next message, given that there is no |
| 454 // SW available, it should unregister |app_id|. | 454 // SW available, it should unregister |app_id|. |
| 455 UnregistrationCallback callback; | 455 UnregistrationCallback callback; |
| 456 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 456 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 457 base::Unretained(&callback))); | 457 base::Unretained(&callback))); |
| 458 | 458 |
| 459 GCMClient::IncomingMessage message; | 459 GCMClient::IncomingMessage message; |
| 460 message.data["data"] = "testdata"; | 460 message.data["data"] = "testdata"; |
| 461 push_service()->OnMessage(app_id.app_id_guid, message); | 461 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 462 | 462 |
| 463 callback.WaitUntilSatisfied(); | 463 callback.WaitUntilSatisfied(); |
| 464 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 464 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
| 465 | 465 |
| 466 // No push data should have been received. | 466 // No push data should have been received. |
| 467 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 467 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 468 EXPECT_EQ("null", script_result); | 468 EXPECT_EQ("null", script_result); |
| 469 } | 469 } |
| 470 | 470 |
| 471 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { | 471 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { |
| 472 std::string script_result; | 472 std::string script_result; |
| 473 | 473 |
| 474 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 474 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 475 | 475 |
| 476 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 476 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 477 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 477 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 478 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 478 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 479 | 479 |
| 480 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 480 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 481 ASSERT_EQ("false - is not controlled", script_result); | 481 ASSERT_EQ("false - is not controlled", script_result); |
| 482 | 482 |
| 483 LoadTestPage(); // Reload to become controlled. | 483 LoadTestPage(); // Reload to become controlled. |
| 484 | 484 |
| 485 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 485 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 486 ASSERT_EQ("true - is controlled", script_result); | 486 ASSERT_EQ("true - is controlled", script_result); |
| 487 | 487 |
| 488 // Revoke Push permission. | 488 // Revoke Push permission. |
| 489 browser()->profile()->GetHostContentSettingsMap()-> | 489 browser()->profile()->GetHostContentSettingsMap()-> |
| 490 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 490 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 491 | 491 |
| 492 // When the push service will receive its next message, given that there is no | 492 // When the push service will receive its next message, given that there is no |
| 493 // SW available, it should unregister |app_id|. | 493 // SW available, it should unregister |app_id|. |
| 494 UnregistrationCallback callback; | 494 UnregistrationCallback callback; |
| 495 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 495 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
| 496 base::Unretained(&callback))); | 496 base::Unretained(&callback))); |
| 497 | 497 |
| 498 GCMClient::IncomingMessage message; | 498 GCMClient::IncomingMessage message; |
| 499 message.data["data"] = "testdata"; | 499 message.data["data"] = "testdata"; |
| 500 push_service()->OnMessage(app_id.app_id_guid, message); | 500 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 501 | 501 |
| 502 callback.WaitUntilSatisfied(); | 502 callback.WaitUntilSatisfied(); |
| 503 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); | 503 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
| 504 | 504 |
| 505 // No push data should have been received. | 505 // No push data should have been received. |
| 506 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 506 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
| 507 EXPECT_EQ("null", script_result); | 507 EXPECT_EQ("null", script_result); |
| 508 } | 508 } |
| 509 | 509 |
| 510 #if defined(ENABLE_NOTIFICATIONS) | 510 #if defined(ENABLE_NOTIFICATIONS) |
| 511 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 511 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 512 PushEventEnforcesUserVisibleNotification) { | 512 PushEventEnforcesUserVisibleNotification) { |
| 513 std::string script_result; | 513 std::string script_result; |
| 514 | 514 |
| 515 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 515 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 516 | 516 |
| 517 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 517 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 518 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 518 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 519 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 519 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 520 | 520 |
| 521 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 521 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 522 ASSERT_EQ("false - is not controlled", script_result); | 522 ASSERT_EQ("false - is not controlled", script_result); |
| 523 | 523 |
| 524 LoadTestPage(); // Reload to become controlled. | 524 LoadTestPage(); // Reload to become controlled. |
| 525 | 525 |
| 526 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 526 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 527 ASSERT_EQ("true - is controlled", script_result); | 527 ASSERT_EQ("true - is controlled", script_result); |
| 528 | 528 |
| 529 notification_manager()->CancelAll(); | 529 notification_manager()->CancelAll(); |
| 530 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 530 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 531 | 531 |
| 532 // We'll need to specify the web_contents in which to eval script, since we're | 532 // We'll need to specify the web_contents in which to eval script, since we're |
| 533 // going to run script in a background tab. | 533 // going to run script in a background tab. |
| 534 content::WebContents* web_contents = | 534 content::WebContents* web_contents = |
| 535 browser()->tab_strip_model()->GetActiveWebContents(); | 535 browser()->tab_strip_model()->GetActiveWebContents(); |
| 536 | 536 |
| 537 // If the site is visible in an active tab, we should not force a notification | 537 // If the site is visible in an active tab, we should not force a notification |
| 538 // to be shown. Try it twice, since we allow one mistake per 10 push events. | 538 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
| 539 GCMClient::IncomingMessage message; | 539 GCMClient::IncomingMessage message; |
| 540 for (int n = 0; n < 2; n++) { | 540 for (int n = 0; n < 2; n++) { |
| 541 message.data["data"] = "testdata"; | 541 message.data["data"] = "testdata"; |
| 542 push_service()->OnMessage(app_id.app_id_guid, message); | 542 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 543 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 543 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
| 544 EXPECT_EQ("testdata", script_result); | 544 EXPECT_EQ("testdata", script_result); |
| 545 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 545 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 546 } | 546 } |
| 547 | 547 |
| 548 // Open a blank foreground tab so site is no longer visible. | 548 // Open a blank foreground tab so site is no longer visible. |
| 549 ui_test_utils::NavigateToURLWithDisposition( | 549 ui_test_utils::NavigateToURLWithDisposition( |
| 550 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, | 550 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB, |
| 551 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 551 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 552 | 552 |
| 553 // If the Service Worker push event handler does not show a notification, we | 553 // If the Service Worker push event handler does not show a notification, we |
| 554 // should show a forced one, but only on the 2nd occurrence since we allow one | 554 // should show a forced one, but only on the 2nd occurrence since we allow one |
| 555 // mistake per 10 push events. | 555 // mistake per 10 push events. |
| 556 message.data["data"] = "testdata"; | 556 message.data["data"] = "testdata"; |
| 557 push_service()->OnMessage(app_id.app_id_guid, message); | 557 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 558 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 558 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 559 EXPECT_EQ("testdata", script_result); | 559 EXPECT_EQ("testdata", script_result); |
| 560 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 560 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 561 message.data["data"] = "testdata"; | 561 message.data["data"] = "testdata"; |
| 562 push_service()->OnMessage(app_id.app_id_guid, message); | 562 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 563 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 563 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 564 EXPECT_EQ("testdata", script_result); | 564 EXPECT_EQ("testdata", script_result); |
| 565 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); | 565 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 566 EXPECT_EQ(base::ASCIIToUTF16(kPushMessagingForcedNotificationTag), | 566 EXPECT_EQ(base::ASCIIToUTF16(kPushMessagingForcedNotificationTag), |
| 567 notification_manager()->GetNotificationAt(0).replace_id()); | 567 notification_manager()->GetNotificationAt(0).replace_id()); |
| 568 | 568 |
| 569 // Currently, this notification will stick around until the user or webapp | 569 // Currently, this notification will stick around until the user or webapp |
| 570 // explicitly dismisses it (though we may change this later). | 570 // explicitly dismisses it (though we may change this later). |
| 571 message.data["data"] = "shownotification"; | 571 message.data["data"] = "shownotification"; |
| 572 push_service()->OnMessage(app_id.app_id_guid, message); | 572 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 573 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 573 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 574 EXPECT_EQ("shownotification", script_result); | 574 EXPECT_EQ("shownotification", script_result); |
| 575 EXPECT_EQ(2u, notification_manager()->GetNotificationCount()); | 575 EXPECT_EQ(2u, notification_manager()->GetNotificationCount()); |
| 576 | 576 |
| 577 notification_manager()->CancelAll(); | 577 notification_manager()->CancelAll(); |
| 578 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 578 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 579 | 579 |
| 580 // However if the Service Worker push event handler shows a notification, we | 580 // However if the Service Worker push event handler shows a notification, we |
| 581 // should not show a forced one. | 581 // should not show a forced one. |
| 582 message.data["data"] = "shownotification"; | 582 message.data["data"] = "shownotification"; |
| 583 for (int n = 0; n < 9; n++) { | 583 for (int n = 0; n < 9; n++) { |
| 584 push_service()->OnMessage(app_id.app_id_guid, message); | 584 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 585 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 585 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 586 EXPECT_EQ("shownotification", script_result); | 586 EXPECT_EQ("shownotification", script_result); |
| 587 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); | 587 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 588 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), | 588 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), |
| 589 notification_manager()->GetNotificationAt(0).replace_id()); | 589 notification_manager()->GetNotificationAt(0).replace_id()); |
| 590 notification_manager()->CancelAll(); | 590 notification_manager()->CancelAll(); |
| 591 } | 591 } |
| 592 | 592 |
| 593 // Now that 10 push messages in a row have shown notifications, we should | 593 // Now that 10 push messages in a row have shown notifications, we should |
| 594 // allow the next one to mistakenly not show a notification. | 594 // allow the next one to mistakenly not show a notification. |
| 595 message.data["data"] = "testdata"; | 595 message.data["data"] = "testdata"; |
| 596 push_service()->OnMessage(app_id.app_id_guid, message); | 596 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 597 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 597 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 598 EXPECT_EQ("testdata", script_result); | 598 EXPECT_EQ("testdata", script_result); |
| 599 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 599 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
| 600 } | 600 } |
| 601 | 601 |
| 602 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 602 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 603 PushEventNotificationWithoutEventWaitUntil) { | 603 PushEventNotificationWithoutEventWaitUntil) { |
| 604 std::string script_result; | 604 std::string script_result; |
| 605 content::WebContents* web_contents = | 605 content::WebContents* web_contents = |
| 606 browser()->tab_strip_model()->GetActiveWebContents(); | 606 browser()->tab_strip_model()->GetActiveWebContents(); |
| 607 | 607 |
| 608 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 608 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| 609 | 609 |
| 610 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); | 610 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); |
| 611 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); | 611 EXPECT_EQ(app_id.app_id_guid(), gcm_service()->last_registered_app_id()); |
| 612 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 612 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 613 | 613 |
| 614 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 614 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 615 ASSERT_EQ("false - is not controlled", script_result); | 615 ASSERT_EQ("false - is not controlled", script_result); |
| 616 | 616 |
| 617 LoadTestPage(); // Reload to become controlled. | 617 LoadTestPage(); // Reload to become controlled. |
| 618 | 618 |
| 619 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 619 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| 620 ASSERT_EQ("true - is controlled", script_result); | 620 ASSERT_EQ("true - is controlled", script_result); |
| 621 | 621 |
| 622 NotificationAddedCallback callback; | 622 NotificationAddedCallback callback; |
| 623 notification_manager()->SetNotificationAddedCallback( | 623 notification_manager()->SetNotificationAddedCallback( |
| 624 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback))); | 624 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback))); |
| 625 | 625 |
| 626 GCMClient::IncomingMessage message; | 626 GCMClient::IncomingMessage message; |
| 627 message.data["data"] = "shownotification-without-waituntil"; | 627 message.data["data"] = "shownotification-without-waituntil"; |
| 628 push_service()->OnMessage(app_id.app_id_guid, message); | 628 push_service()->OnMessage(app_id.app_id_guid(), message); |
| 629 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 629 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
| 630 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); | 630 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); |
| 631 | 631 |
| 632 callback.WaitUntilSatisfied(); | 632 callback.WaitUntilSatisfied(); |
| 633 | 633 |
| 634 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 634 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
| 635 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), | 635 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), |
| 636 notification_manager()->GetNotificationAt(0).replace_id()); | 636 notification_manager()->GetNotificationAt(0).replace_id()); |
| 637 | 637 |
| 638 // Verify that the renderer process hasn't crashed. | 638 // Verify that the renderer process hasn't crashed. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 | 717 |
| 718 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 718 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
| 719 | 719 |
| 720 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 720 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
| 721 EXPECT_EQ("unregister error: " | 721 EXPECT_EQ("unregister error: " |
| 722 "UnknownError: Unexpected error while trying to unregister from the" | 722 "UnknownError: Unexpected error while trying to unregister from the" |
| 723 " push server.", script_result); | 723 " push server.", script_result); |
| 724 } | 724 } |
| 725 | 725 |
| 726 } // namespace gcm | 726 } // namespace gcm |
| OLD | NEW |