Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(894)

Side by Side Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 1243563002: Teach the GCM Driver how to decrypt incoming messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-push-keys
Patch Set: address comment Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/push_messaging/push_messaging_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 418 ASSERT_TRUE(RunScript("isControlled()", &script_result));
419 ASSERT_EQ("false - is not controlled", script_result); 419 ASSERT_EQ("false - is not controlled", script_result);
420 420
421 LoadTestPage(); // Reload to become controlled. 421 LoadTestPage(); // Reload to become controlled.
422 422
423 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 423 ASSERT_TRUE(RunScript("isControlled()", &script_result));
424 ASSERT_EQ("true - is controlled", script_result); 424 ASSERT_EQ("true - is controlled", script_result);
425 425
426 gcm::IncomingMessage message; 426 gcm::IncomingMessage message;
427 message.sender_id = "1234567890"; 427 message.sender_id = "1234567890";
428 message.data["data"] = "testdata"; 428 message.raw_data = "testdata";
429 message.decrypted = true;
429 push_service()->OnMessage(app_identifier.app_id(), message); 430 push_service()->OnMessage(app_identifier.app_id(), message);
430 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 431 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
431 EXPECT_EQ("testdata", script_result); 432 EXPECT_EQ("testdata", script_result);
432 } 433 }
433 434
434 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { 435 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) {
435 std::string script_result; 436 std::string script_result;
436 437
437 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 438 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
438 439
(...skipping 15 matching lines...) Expand all
454 ASSERT_EQ("service worker unregistration status: true", script_result); 455 ASSERT_EQ("service worker unregistration status: true", script_result);
455 456
456 // When the push service will receive it next message, given that there is no 457 // When the push service will receive it next message, given that there is no
457 // SW available, it should unregister |app_identifier.app_id()|. 458 // SW available, it should unregister |app_identifier.app_id()|.
458 UnregistrationCallback callback; 459 UnregistrationCallback callback;
459 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run, 460 gcm_service()->SetUnregisterCallback(base::Bind(&UnregistrationCallback::Run,
460 base::Unretained(&callback))); 461 base::Unretained(&callback)));
461 462
462 gcm::IncomingMessage message; 463 gcm::IncomingMessage message;
463 message.sender_id = "1234567890"; 464 message.sender_id = "1234567890";
464 message.data["data"] = "testdata"; 465 message.raw_data = "testdata";
466 message.decrypted = true;
465 push_service()->OnMessage(app_identifier.app_id(), message); 467 push_service()->OnMessage(app_identifier.app_id(), message);
466 468
467 callback.WaitUntilSatisfied(); 469 callback.WaitUntilSatisfied();
468 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); 470 EXPECT_EQ(app_identifier.app_id(), callback.app_id());
469 471
470 // No push data should have been received. 472 // No push data should have been received.
471 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); 473 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
472 EXPECT_EQ("null", script_result); 474 EXPECT_EQ("null", script_result);
473 } 475 }
474 476
(...skipping 22 matching lines...) Expand all
497 499
498 // We'll need to specify the web_contents in which to eval script, since we're 500 // We'll need to specify the web_contents in which to eval script, since we're
499 // going to run script in a background tab. 501 // going to run script in a background tab.
500 content::WebContents* web_contents = 502 content::WebContents* web_contents =
501 GetBrowser()->tab_strip_model()->GetActiveWebContents(); 503 GetBrowser()->tab_strip_model()->GetActiveWebContents();
502 504
503 // If the site is visible in an active tab, we should not force a notification 505 // If the site is visible in an active tab, we should not force a notification
504 // to be shown. Try it twice, since we allow one mistake per 10 push events. 506 // to be shown. Try it twice, since we allow one mistake per 10 push events.
505 gcm::IncomingMessage message; 507 gcm::IncomingMessage message;
506 message.sender_id = "1234567890"; 508 message.sender_id = "1234567890";
509 message.decrypted = true;
507 for (int n = 0; n < 2; n++) { 510 for (int n = 0; n < 2; n++) {
508 message.data["data"] = "testdata"; 511 message.raw_data = "testdata";
509 SendMessageAndWaitUntilHandled(app_identifier, message); 512 SendMessageAndWaitUntilHandled(app_identifier, message);
510 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 513 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
511 EXPECT_EQ("testdata", script_result); 514 EXPECT_EQ("testdata", script_result);
512 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 515 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
513 } 516 }
514 517
515 // Open a blank foreground tab so site is no longer visible. 518 // Open a blank foreground tab so site is no longer visible.
516 ui_test_utils::NavigateToURLWithDisposition( 519 ui_test_utils::NavigateToURLWithDisposition(
517 GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB, 520 GetBrowser(), GURL("about:blank"), NEW_FOREGROUND_TAB,
518 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 521 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
519 522
520 // If the Service Worker push event handler does not show a notification, we 523 // If the Service Worker push event handler does not show a notification, we
521 // should show a forced one, but only on the 2nd occurrence since we allow one 524 // should show a forced one, but only on the 2nd occurrence since we allow one
522 // mistake per 10 push events. 525 // mistake per 10 push events.
523 message.data["data"] = "testdata"; 526 message.raw_data = "testdata";
524 SendMessageAndWaitUntilHandled(app_identifier, message); 527 SendMessageAndWaitUntilHandled(app_identifier, message);
525 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 528 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
526 EXPECT_EQ("testdata", script_result); 529 EXPECT_EQ("testdata", script_result);
527 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 530 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
528 message.data["data"] = "testdata"; 531 message.raw_data = "testdata";
529 SendMessageAndWaitUntilHandled(app_identifier, message); 532 SendMessageAndWaitUntilHandled(app_identifier, message);
530 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 533 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
531 EXPECT_EQ("testdata", script_result); 534 EXPECT_EQ("testdata", script_result);
532 535
533 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); 536 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
534 { 537 {
535 const Notification& forced_notification = 538 const Notification& forced_notification =
536 notification_manager()->GetNotificationAt(0); 539 notification_manager()->GetNotificationAt(0);
537 540
538 EXPECT_EQ(kPushMessagingForcedNotificationTag, forced_notification.tag()); 541 EXPECT_EQ(kPushMessagingForcedNotificationTag, forced_notification.tag());
539 EXPECT_TRUE(forced_notification.silent()); 542 EXPECT_TRUE(forced_notification.silent());
540 } 543 }
541 544
542 // The notification will be automatically dismissed when the developer shows 545 // The notification will be automatically dismissed when the developer shows
543 // a new notification themselves at a later point in time. 546 // a new notification themselves at a later point in time.
544 message.data["data"] = "shownotification"; 547 message.raw_data = "shownotification";
545 SendMessageAndWaitUntilHandled(app_identifier, message); 548 SendMessageAndWaitUntilHandled(app_identifier, message);
546 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 549 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
547 EXPECT_EQ("shownotification", script_result); 550 EXPECT_EQ("shownotification", script_result);
548 551
549 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); 552 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
550 { 553 {
551 const Notification& first_notification = 554 const Notification& first_notification =
552 notification_manager()->GetNotificationAt(0); 555 notification_manager()->GetNotificationAt(0);
553 556
554 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag()); 557 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag());
555 } 558 }
556 559
557 notification_manager()->CancelAll(); 560 notification_manager()->CancelAll();
558 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 561 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
559 562
560 // However if the Service Worker push event handler shows a notification, we 563 // However if the Service Worker push event handler shows a notification, we
561 // should not show a forced one. 564 // should not show a forced one.
562 message.data["data"] = "shownotification"; 565 message.raw_data = "shownotification";
563 for (int n = 0; n < 9; n++) { 566 for (int n = 0; n < 9; n++) {
564 SendMessageAndWaitUntilHandled(app_identifier, message); 567 SendMessageAndWaitUntilHandled(app_identifier, message);
565 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 568 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
566 EXPECT_EQ("shownotification", script_result); 569 EXPECT_EQ("shownotification", script_result);
567 EXPECT_EQ(1u, notification_manager()->GetNotificationCount()); 570 EXPECT_EQ(1u, notification_manager()->GetNotificationCount());
568 EXPECT_EQ("push_test_tag", 571 EXPECT_EQ("push_test_tag",
569 notification_manager()->GetNotificationAt(0).tag()); 572 notification_manager()->GetNotificationAt(0).tag());
570 notification_manager()->CancelAll(); 573 notification_manager()->CancelAll();
571 } 574 }
572 575
573 // Now that 10 push messages in a row have shown notifications, we should 576 // Now that 10 push messages in a row have shown notifications, we should
574 // allow the next one to mistakenly not show a notification. 577 // allow the next one to mistakenly not show a notification.
575 message.data["data"] = "testdata"; 578 message.raw_data = "testdata";
576 SendMessageAndWaitUntilHandled(app_identifier, message); 579 SendMessageAndWaitUntilHandled(app_identifier, message);
577 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 580 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
578 EXPECT_EQ("testdata", script_result); 581 EXPECT_EQ("testdata", script_result);
579 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 582 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
580 } 583 }
581 584
582 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 585 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
583 PushEventEnforcesUserVisibleNotificationAfterQueue) { 586 PushEventEnforcesUserVisibleNotificationAfterQueue) {
584 std::string script_result; 587 std::string script_result;
585 588
(...skipping 14 matching lines...) Expand all
600 603
601 // Fire off two push messages in sequence, only the second one of which will 604 // Fire off two push messages in sequence, only the second one of which will
602 // display a notification. The additional round-trip and I/O required by the 605 // display a notification. The additional round-trip and I/O required by the
603 // second message, which shows a notification, should give us a reasonable 606 // second message, which shows a notification, should give us a reasonable
604 // confidence that the ordering will be maintained. 607 // confidence that the ordering will be maintained.
605 608
606 std::vector<size_t> number_of_notifications_shown; 609 std::vector<size_t> number_of_notifications_shown;
607 610
608 gcm::IncomingMessage message; 611 gcm::IncomingMessage message;
609 message.sender_id = "1234567890"; 612 message.sender_id = "1234567890";
613 message.decrypted = true;
610 614
611 { 615 {
612 base::RunLoop run_loop; 616 base::RunLoop run_loop;
613 push_service()->SetMessageCallbackForTesting( 617 push_service()->SetMessageCallbackForTesting(
614 base::Bind(&PushMessagingBrowserTest::OnDeliveryFinished, 618 base::Bind(&PushMessagingBrowserTest::OnDeliveryFinished,
615 base::Unretained(this), 619 base::Unretained(this),
616 &number_of_notifications_shown, 620 &number_of_notifications_shown,
617 base::BarrierClosure(2 /* num_closures */, 621 base::BarrierClosure(2 /* num_closures */,
618 run_loop.QuitClosure()))); 622 run_loop.QuitClosure())));
619 623
620 message.data["data"] = "testdata"; 624 message.raw_data = "testdata";
621 push_service()->OnMessage(app_identifier.app_id(), message); 625 push_service()->OnMessage(app_identifier.app_id(), message);
622 626
623 message.data["data"] = "shownotification"; 627 message.raw_data = "shownotification";
624 push_service()->OnMessage(app_identifier.app_id(), message); 628 push_service()->OnMessage(app_identifier.app_id(), message);
625 629
626 run_loop.Run(); 630 run_loop.Run();
627 } 631 }
628 632
629 ASSERT_EQ(2u, number_of_notifications_shown.size()); 633 ASSERT_EQ(2u, number_of_notifications_shown.size());
630 EXPECT_EQ(0u, number_of_notifications_shown[0]); 634 EXPECT_EQ(0u, number_of_notifications_shown[0]);
631 EXPECT_EQ(1u, number_of_notifications_shown[1]); 635 EXPECT_EQ(1u, number_of_notifications_shown[1]);
632 } 636 }
633 637
(...skipping 18 matching lines...) Expand all
652 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 656 ASSERT_TRUE(RunScript("isControlled()", &script_result));
653 ASSERT_EQ("true - is controlled", script_result); 657 ASSERT_EQ("true - is controlled", script_result);
654 658
655 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 659 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
656 new content::MessageLoopRunner; 660 new content::MessageLoopRunner;
657 notification_manager()->SetNotificationAddedCallback( 661 notification_manager()->SetNotificationAddedCallback(
658 message_loop_runner->QuitClosure()); 662 message_loop_runner->QuitClosure());
659 663
660 gcm::IncomingMessage message; 664 gcm::IncomingMessage message;
661 message.sender_id = "1234567890"; 665 message.sender_id = "1234567890";
662 message.data["data"] = "shownotification-without-waituntil"; 666 message.raw_data = "shownotification-without-waituntil";
667 message.decrypted = true;
663 push_service()->OnMessage(app_identifier.app_id(), message); 668 push_service()->OnMessage(app_identifier.app_id(), message);
664 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 669 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
665 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); 670 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result);
666 671
667 message_loop_runner->Run(); 672 message_loop_runner->Run();
668 673
669 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); 674 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
670 EXPECT_EQ("push_test_tag", 675 EXPECT_EQ("push_test_tag",
671 notification_manager()->GetNotificationAt(0).tag()); 676 notification_manager()->GetNotificationAt(0).tag());
672 677
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1236 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1232 1237
1233 // After dropping the last subscription background mode is still inactive. 1238 // After dropping the last subscription background mode is still inactive.
1234 std::string script_result; 1239 std::string script_result;
1235 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); 1240 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
1236 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 1241 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1237 EXPECT_EQ("unsubscribe result: true", script_result); 1242 EXPECT_EQ("unsubscribe result: true", script_result);
1238 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1243 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1239 } 1244 }
1240 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 1245 #endif // defined(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/push_messaging/push_messaging_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698