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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.sender_id = "1234567890"; |
426 message.data["data"] = "testdata"; | 427 message.data["data"] = "testdata"; |
427 push_service()->OnMessage(app_id.app_id_guid(), message); | 428 push_service()->OnMessage(app_id.app_id_guid(), message); |
428 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 429 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
429 EXPECT_EQ("testdata", script_result); | 430 EXPECT_EQ("testdata", script_result); |
430 } | 431 } |
431 | 432 |
432 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 433 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
433 std::string script_result; | 434 std::string script_result; |
434 | 435 |
435 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); | 436 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
(...skipping 14 matching lines...) Expand all Loading... |
450 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); | 451 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); |
451 ASSERT_EQ("service worker unregistration status: true", script_result); | 452 ASSERT_EQ("service worker unregistration status: true", script_result); |
452 | 453 |
453 // When the push service will receive it next message, given that there is no | 454 // When the push service will receive it next message, given that there is no |
454 // SW available, it should unregister |app_id|. | 455 // SW available, it should unregister |app_id|. |
455 UnregistrationCallback callback; | 456 UnregistrationCallback callback; |
456 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 457 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
457 base::Unretained(&callback))); | 458 base::Unretained(&callback))); |
458 | 459 |
459 GCMClient::IncomingMessage message; | 460 GCMClient::IncomingMessage message; |
| 461 message.sender_id = "1234567890"; |
460 message.data["data"] = "testdata"; | 462 message.data["data"] = "testdata"; |
461 push_service()->OnMessage(app_id.app_id_guid(), message); | 463 push_service()->OnMessage(app_id.app_id_guid(), message); |
462 | 464 |
463 callback.WaitUntilSatisfied(); | 465 callback.WaitUntilSatisfied(); |
464 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); | 466 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
465 | 467 |
466 // No push data should have been received. | 468 // No push data should have been received. |
467 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 469 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
468 EXPECT_EQ("null", script_result); | 470 EXPECT_EQ("null", script_result); |
469 } | 471 } |
(...skipping 19 matching lines...) Expand all Loading... |
489 browser()->profile()->GetHostContentSettingsMap()-> | 491 browser()->profile()->GetHostContentSettingsMap()-> |
490 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 492 ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
491 | 493 |
492 // When the push service will receive its next message, given that there is no | 494 // When the push service will receive its next message, given that there is no |
493 // SW available, it should unregister |app_id|. | 495 // SW available, it should unregister |app_id|. |
494 UnregistrationCallback callback; | 496 UnregistrationCallback callback; |
495 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 497 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
496 base::Unretained(&callback))); | 498 base::Unretained(&callback))); |
497 | 499 |
498 GCMClient::IncomingMessage message; | 500 GCMClient::IncomingMessage message; |
| 501 message.sender_id = "1234567890"; |
499 message.data["data"] = "testdata"; | 502 message.data["data"] = "testdata"; |
500 push_service()->OnMessage(app_id.app_id_guid(), message); | 503 push_service()->OnMessage(app_id.app_id_guid(), message); |
501 | 504 |
502 callback.WaitUntilSatisfied(); | 505 callback.WaitUntilSatisfied(); |
503 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); | 506 EXPECT_EQ(app_id.app_id_guid(), callback.app_id()); |
504 | 507 |
505 // No push data should have been received. | 508 // No push data should have been received. |
506 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 509 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
507 EXPECT_EQ("null", script_result); | 510 EXPECT_EQ("null", script_result); |
508 } | 511 } |
(...skipping 21 matching lines...) Expand all Loading... |
530 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); | 533 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); |
531 | 534 |
532 // We'll need to specify the web_contents in which to eval script, since we're | 535 // 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. | 536 // going to run script in a background tab. |
534 content::WebContents* web_contents = | 537 content::WebContents* web_contents = |
535 browser()->tab_strip_model()->GetActiveWebContents(); | 538 browser()->tab_strip_model()->GetActiveWebContents(); |
536 | 539 |
537 // If the site is visible in an active tab, we should not force a notification | 540 // 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. | 541 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
539 GCMClient::IncomingMessage message; | 542 GCMClient::IncomingMessage message; |
| 543 message.sender_id = "1234567890"; |
540 for (int n = 0; n < 2; n++) { | 544 for (int n = 0; n < 2; n++) { |
541 message.data["data"] = "testdata"; | 545 message.data["data"] = "testdata"; |
542 push_service()->OnMessage(app_id.app_id_guid(), message); | 546 push_service()->OnMessage(app_id.app_id_guid(), message); |
543 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 547 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
544 EXPECT_EQ("testdata", script_result); | 548 EXPECT_EQ("testdata", script_result); |
545 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 549 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
546 } | 550 } |
547 | 551 |
548 // Open a blank foreground tab so site is no longer visible. | 552 // Open a blank foreground tab so site is no longer visible. |
549 ui_test_utils::NavigateToURLWithDisposition( | 553 ui_test_utils::NavigateToURLWithDisposition( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 LoadTestPage(); // Reload to become controlled. | 621 LoadTestPage(); // Reload to become controlled. |
618 | 622 |
619 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 623 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
620 ASSERT_EQ("true - is controlled", script_result); | 624 ASSERT_EQ("true - is controlled", script_result); |
621 | 625 |
622 NotificationAddedCallback callback; | 626 NotificationAddedCallback callback; |
623 notification_manager()->SetNotificationAddedCallback( | 627 notification_manager()->SetNotificationAddedCallback( |
624 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback))); | 628 base::Bind(&NotificationAddedCallback::Run, base::Unretained(&callback))); |
625 | 629 |
626 GCMClient::IncomingMessage message; | 630 GCMClient::IncomingMessage message; |
| 631 message.sender_id = "1234567890"; |
627 message.data["data"] = "shownotification-without-waituntil"; | 632 message.data["data"] = "shownotification-without-waituntil"; |
628 push_service()->OnMessage(app_id.app_id_guid(), message); | 633 push_service()->OnMessage(app_id.app_id_guid(), message); |
629 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 634 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
630 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); | 635 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); |
631 | 636 |
632 callback.WaitUntilSatisfied(); | 637 callback.WaitUntilSatisfied(); |
633 | 638 |
634 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 639 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
635 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), | 640 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), |
636 notification_manager()->GetNotificationAt(0).replace_id()); | 641 notification_manager()->GetNotificationAt(0).replace_id()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 | 722 |
718 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); | 723 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); |
719 | 724 |
720 ASSERT_TRUE(RunScript("unregister()", &script_result)); | 725 ASSERT_TRUE(RunScript("unregister()", &script_result)); |
721 EXPECT_EQ("unregister error: " | 726 EXPECT_EQ("unregister error: " |
722 "UnknownError: Unexpected error while trying to unregister from the" | 727 "UnknownError: Unexpected error while trying to unregister from the" |
723 " push server.", script_result); | 728 " push server.", script_result); |
724 } | 729 } |
725 | 730 |
726 } // namespace gcm | 731 } // namespace gcm |
OLD | NEW |