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/barrier_closure.h" | 8 #include "base/barrier_closure.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 413 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
414 ASSERT_EQ("false - is not controlled", script_result); | 414 ASSERT_EQ("false - is not controlled", script_result); |
415 | 415 |
416 LoadTestPage(); // Reload to become controlled. | 416 LoadTestPage(); // Reload to become controlled. |
417 | 417 |
418 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 418 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
419 ASSERT_EQ("true - is controlled", script_result); | 419 ASSERT_EQ("true - is controlled", script_result); |
420 | 420 |
421 gcm::IncomingMessage message; | 421 gcm::IncomingMessage message; |
422 message.sender_id = "1234567890"; | 422 message.sender_id = "1234567890"; |
423 message.data["data"] = "testdata"; | 423 message.raw_data = "testdata"; |
424 push_service()->OnMessage(app_identifier.app_id(), message); | 424 push_service()->OnMessage(app_identifier.app_id(), message); |
425 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 425 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
426 EXPECT_EQ("testdata", script_result); | 426 EXPECT_EQ("testdata", script_result); |
427 } | 427 } |
428 | 428 |
429 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { | 429 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
430 std::string script_result; | 430 std::string script_result; |
431 | 431 |
432 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 432 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
433 | 433 |
(...skipping 15 matching lines...) Expand all Loading... |
449 ASSERT_EQ("service worker unregistration status: true", script_result); | 449 ASSERT_EQ("service worker unregistration status: true", script_result); |
450 | 450 |
451 // When the push service will receive it next message, given that there is no | 451 // When the push service will receive it next message, given that there is no |
452 // SW available, it should unregister |app_identifier.app_id()|. | 452 // SW available, it should unregister |app_identifier.app_id()|. |
453 UnregistrationCallback callback; | 453 UnregistrationCallback callback; |
454 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, | 454 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, |
455 base::Unretained(&callback))); | 455 base::Unretained(&callback))); |
456 | 456 |
457 gcm::IncomingMessage message; | 457 gcm::IncomingMessage message; |
458 message.sender_id = "1234567890"; | 458 message.sender_id = "1234567890"; |
459 message.data["data"] = "testdata"; | 459 message.raw_data = "testdata"; |
460 push_service()->OnMessage(app_identifier.app_id(), message); | 460 push_service()->OnMessage(app_identifier.app_id(), message); |
461 | 461 |
462 callback.WaitUntilSatisfied(); | 462 callback.WaitUntilSatisfied(); |
463 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); | 463 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); |
464 | 464 |
465 // No push data should have been received. | 465 // No push data should have been received. |
466 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); | 466 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); |
467 EXPECT_EQ("null", script_result); | 467 EXPECT_EQ("null", script_result); |
468 } | 468 } |
469 | 469 |
(...skipping 23 matching lines...) Expand all Loading... |
493 // We'll need to specify the web_contents in which to eval script, since we're | 493 // We'll need to specify the web_contents in which to eval script, since we're |
494 // going to run script in a background tab. | 494 // going to run script in a background tab. |
495 content::WebContents* web_contents = | 495 content::WebContents* web_contents = |
496 GetBrowser()->tab_strip_model()->GetActiveWebContents(); | 496 GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
497 | 497 |
498 // If the site is visible in an active tab, we should not force a notification | 498 // If the site is visible in an active tab, we should not force a notification |
499 // to be shown. Try it twice, since we allow one mistake per 10 push events. | 499 // to be shown. Try it twice, since we allow one mistake per 10 push events. |
500 gcm::IncomingMessage message; | 500 gcm::IncomingMessage message; |
501 message.sender_id = "1234567890"; | 501 message.sender_id = "1234567890"; |
502 for (int n = 0; n < 2; n++) { | 502 for (int n = 0; n < 2; n++) { |
503 message.data["data"] = "testdata"; | 503 message.raw_data = "testdata"; |
504 SendMessageAndWaitUntilHandled(app_identifier, message); | 504 SendMessageAndWaitUntilHandled(app_identifier, message); |
505 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); | 505 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); |
506 EXPECT_EQ("testdata", script_result); | 506 EXPECT_EQ("testdata", script_result); |
507 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 507 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
508 } | 508 } |
509 | 509 |
510 // Open a blank foreground tab so site is no longer visible. | 510 // Open a blank foreground tab so site is no longer visible. |
511 ui_test_utils::NavigateToURLWithDisposition( | 511 ui_test_utils::NavigateToURLWithDisposition( |
512 GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB, | 512 GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB, |
513 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 513 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
514 | 514 |
515 // If the Service Worker push event handler does not show a notification, we | 515 // If the Service Worker push event handler does not show a notification, we |
516 // should show a forced one, but only on the 2nd occurrence since we allow one | 516 // should show a forced one, but only on the 2nd occurrence since we allow one |
517 // mistake per 10 push events. | 517 // mistake per 10 push events. |
518 message.data["data"] = "testdata"; | 518 message.raw_data = "testdata"; |
519 SendMessageAndWaitUntilHandled(app_identifier, message); | 519 SendMessageAndWaitUntilHandled(app_identifier, message); |
520 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 520 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
521 EXPECT_EQ("testdata", script_result); | 521 EXPECT_EQ("testdata", script_result); |
522 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 522 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
523 message.data["data"] = "testdata"; | 523 message.raw_data = "testdata"; |
524 SendMessageAndWaitUntilHandled(app_identifier, message); | 524 SendMessageAndWaitUntilHandled(app_identifier, message); |
525 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 525 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
526 EXPECT_EQ("testdata", script_result); | 526 EXPECT_EQ("testdata", script_result); |
527 | 527 |
528 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 528 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
529 { | 529 { |
530 const Notification& forced_notification = | 530 const Notification& forced_notification = |
531 notification_manager()->GetNotificationAt(0); | 531 notification_manager()->GetNotificationAt(0); |
532 | 532 |
533 EXPECT_EQ(kPushMessagingForcedNotificationTag, forced_notification.tag()); | 533 EXPECT_EQ(kPushMessagingForcedNotificationTag, forced_notification.tag()); |
534 EXPECT_TRUE(forced_notification.silent()); | 534 EXPECT_TRUE(forced_notification.silent()); |
535 } | 535 } |
536 | 536 |
537 // The notification will be automatically dismissed when the developer shows | 537 // The notification will be automatically dismissed when the developer shows |
538 // a new notification themselves at a later point in time. | 538 // a new notification themselves at a later point in time. |
539 message.data["data"] = "shownotification"; | 539 message.raw_data = "shownotification"; |
540 SendMessageAndWaitUntilHandled(app_identifier, message); | 540 SendMessageAndWaitUntilHandled(app_identifier, message); |
541 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 541 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
542 EXPECT_EQ("shownotification", script_result); | 542 EXPECT_EQ("shownotification", script_result); |
543 | 543 |
544 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 544 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
545 { | 545 { |
546 const Notification& first_notification = | 546 const Notification& first_notification = |
547 notification_manager()->GetNotificationAt(0); | 547 notification_manager()->GetNotificationAt(0); |
548 | 548 |
549 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag()); | 549 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag()); |
550 } | 550 } |
551 | 551 |
552 notification_manager()->CancelAll(); | 552 notification_manager()->CancelAll(); |
553 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 553 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
554 | 554 |
555 // However if the Service Worker push event handler shows a notification, we | 555 // However if the Service Worker push event handler shows a notification, we |
556 // should not show a forced one. | 556 // should not show a forced one. |
557 message.data["data"] = "shownotification"; | 557 message.raw_data = "shownotification"; |
558 for (int n = 0; n < 9; n++) { | 558 for (int n = 0; n < 9; n++) { |
559 SendMessageAndWaitUntilHandled(app_identifier, message); | 559 SendMessageAndWaitUntilHandled(app_identifier, message); |
560 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 560 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
561 EXPECT_EQ("shownotification", script_result); | 561 EXPECT_EQ("shownotification", script_result); |
562 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); | 562 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); |
563 EXPECT_EQ("push_test_tag", | 563 EXPECT_EQ("push_test_tag", |
564 notification_manager()->GetNotificationAt(0).tag()); | 564 notification_manager()->GetNotificationAt(0).tag()); |
565 notification_manager()->CancelAll(); | 565 notification_manager()->CancelAll(); |
566 } | 566 } |
567 | 567 |
568 // Now that 10 push messages in a row have shown notifications, we should | 568 // Now that 10 push messages in a row have shown notifications, we should |
569 // allow the next one to mistakenly not show a notification. | 569 // allow the next one to mistakenly not show a notification. |
570 message.data["data"] = "testdata"; | 570 message.raw_data = "testdata"; |
571 SendMessageAndWaitUntilHandled(app_identifier, message); | 571 SendMessageAndWaitUntilHandled(app_identifier, message); |
572 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 572 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
573 EXPECT_EQ("testdata", script_result); | 573 EXPECT_EQ("testdata", script_result); |
574 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); | 574 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); |
575 } | 575 } |
576 | 576 |
577 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 577 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
578 PushEventEnforcesUserVisibleNotificationAfterQueue) { | 578 PushEventEnforcesUserVisibleNotificationAfterQueue) { |
579 std::string script_result; | 579 std::string script_result; |
580 | 580 |
(...skipping 24 matching lines...) Expand all Loading... |
605 | 605 |
606 { | 606 { |
607 base::RunLoop run_loop; | 607 base::RunLoop run_loop; |
608 push_service()->SetMessageCallbackForTesting( | 608 push_service()->SetMessageCallbackForTesting( |
609 base::Bind(&PushMessagingBrowserTest::OnDeliveryFinished, | 609 base::Bind(&PushMessagingBrowserTest::OnDeliveryFinished, |
610 base::Unretained(this), | 610 base::Unretained(this), |
611 &number_of_notifications_shown, | 611 &number_of_notifications_shown, |
612 base::BarrierClosure(2 /* num_closures */, | 612 base::BarrierClosure(2 /* num_closures */, |
613 run_loop.QuitClosure()))); | 613 run_loop.QuitClosure()))); |
614 | 614 |
615 message.data["data"] = "testdata"; | 615 message.raw_data = "testdata"; |
616 push_service()->OnMessage(app_identifier.app_id(), message); | 616 push_service()->OnMessage(app_identifier.app_id(), message); |
617 | 617 |
618 message.data["data"] = "shownotification"; | 618 message.raw_data = "shownotification"; |
619 push_service()->OnMessage(app_identifier.app_id(), message); | 619 push_service()->OnMessage(app_identifier.app_id(), message); |
620 | 620 |
621 run_loop.Run(); | 621 run_loop.Run(); |
622 } | 622 } |
623 | 623 |
624 ASSERT_EQ(2u, number_of_notifications_shown.size()); | 624 ASSERT_EQ(2u, number_of_notifications_shown.size()); |
625 EXPECT_EQ(0u, number_of_notifications_shown[0]); | 625 EXPECT_EQ(0u, number_of_notifications_shown[0]); |
626 EXPECT_EQ(1u, number_of_notifications_shown[1]); | 626 EXPECT_EQ(1u, number_of_notifications_shown[1]); |
627 } | 627 } |
628 | 628 |
(...skipping 18 matching lines...) Expand all Loading... |
647 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 647 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
648 ASSERT_EQ("true - is controlled", script_result); | 648 ASSERT_EQ("true - is controlled", script_result); |
649 | 649 |
650 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 650 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
651 new content::MessageLoopRunner; | 651 new content::MessageLoopRunner; |
652 notification_manager()->SetNotificationAddedCallback( | 652 notification_manager()->SetNotificationAddedCallback( |
653 message_loop_runner->QuitClosure()); | 653 message_loop_runner->QuitClosure()); |
654 | 654 |
655 gcm::IncomingMessage message; | 655 gcm::IncomingMessage message; |
656 message.sender_id = "1234567890"; | 656 message.sender_id = "1234567890"; |
657 message.data["data"] = "shownotification-without-waituntil"; | 657 message.raw_data = "shownotification-without-waituntil"; |
658 push_service()->OnMessage(app_identifier.app_id(), message); | 658 push_service()->OnMessage(app_identifier.app_id(), message); |
659 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 659 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
660 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); | 660 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); |
661 | 661 |
662 message_loop_runner->Run(); | 662 message_loop_runner->Run(); |
663 | 663 |
664 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 664 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
665 EXPECT_EQ("push_test_tag", | 665 EXPECT_EQ("push_test_tag", |
666 notification_manager()->GetNotificationAt(0).tag()); | 666 notification_manager()->GetNotificationAt(0).tag()); |
667 | 667 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 std::string script_result; | 1139 std::string script_result; |
1140 | 1140 |
1141 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 1141 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
1142 ASSERT_EQ("ok - service worker registered", script_result); | 1142 ASSERT_EQ("ok - service worker registered", script_result); |
1143 | 1143 |
1144 // In Incognito mode the promise returned by getSubscription should not hang, | 1144 // In Incognito mode the promise returned by getSubscription should not hang, |
1145 // it should just fulfill with null. | 1145 // it should just fulfill with null. |
1146 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); | 1146 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); |
1147 ASSERT_EQ("false - not subscribed", script_result); | 1147 ASSERT_EQ("false - not subscribed", script_result); |
1148 } | 1148 } |
OLD | NEW |