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

Side by Side Diff: chrome/browser/banners/app_banner_settings_helper_unittest.cc

Issue 2178833002: Add new app banner metrics using InstallableStatusCode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@banner-integrate-checker-no-refptr
Patch Set: Fix histogram name Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/banners/app_banner_metrics.h" 8 #include "chrome/browser/banners/app_banner_metrics.h"
9 #include "chrome/browser/banners/app_banner_settings_helper.h" 9 #include "chrome/browser/banners/app_banner_settings_helper.h"
10 #include "chrome/browser/engagement/site_engagement_service.h" 10 #include "chrome/browser/engagement/site_engagement_service.h"
11 #include "chrome/browser/installable/installable_logging.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "ui/base/page_transition_types.h" 15 #include "ui/base/page_transition_types.h"
15 16
16 namespace { 17 namespace {
17 18
18 const char kTestURL[] = "https://www.google.com"; 19 const char kTestURL[] = "https://www.google.com";
19 const char kSameOriginTestURL[] = "https://www.google.com/foo.html"; 20 const char kSameOriginTestURL[] = "https://www.google.com/foo.html";
20 const char kDifferentOriginTestURL[] = "https://www.example.com"; 21 const char kDifferentOriginTestURL[] = "https://www.example.com";
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 AppBannerSettingsHelper::SetEngagementWeights(2, 0.5); 507 AppBannerSettingsHelper::SetEngagementWeights(2, 0.5);
507 GURL url(kTestURL); 508 GURL url(kTestURL);
508 NavigateAndCommit(url); 509 NavigateAndCommit(url);
509 510
510 base::Time reference_time = GetReferenceTime(); 511 base::Time reference_time = GetReferenceTime();
511 base::Time second_day = reference_time + base::TimeDelta::FromDays(1); 512 base::Time second_day = reference_time + base::TimeDelta::FromDays(1);
512 base::Time third_day = reference_time + base::TimeDelta::FromDays(2); 513 base::Time third_day = reference_time + base::TimeDelta::FromDays(2);
513 base::Time fourth_day = reference_time + base::TimeDelta::FromDays(3); 514 base::Time fourth_day = reference_time + base::TimeDelta::FromDays(3);
514 515
515 // By default the banner should not be shown. 516 // By default the banner should not be shown.
516 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 517 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
517 web_contents(), url, kTestPackageName, reference_time)); 518 AppBannerSettingsHelper::ShouldShowBanner(
519 web_contents(), url, kTestPackageName, reference_time));
518 520
519 // It should take four indirect visits with a weight of 0.5 to trigger the 521 // It should take four indirect visits with a weight of 0.5 to trigger the
520 // banner. 522 // banner.
521 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 523 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
522 web_contents(), url, kTestPackageName, reference_time, 524 web_contents(), url, kTestPackageName, reference_time,
523 ui::PAGE_TRANSITION_LINK); 525 ui::PAGE_TRANSITION_LINK);
524 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 526 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
525 web_contents(), url, kTestPackageName, reference_time)); 527 AppBannerSettingsHelper::ShouldShowBanner(
528 web_contents(), url, kTestPackageName, reference_time));
526 529
527 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 530 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
528 web_contents(), url, kTestPackageName, second_day, 531 web_contents(), url, kTestPackageName, second_day,
529 ui::PAGE_TRANSITION_LINK); 532 ui::PAGE_TRANSITION_LINK);
530 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 533 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
531 web_contents(), url, kTestPackageName, second_day)); 534 AppBannerSettingsHelper::ShouldShowBanner(
535 web_contents(), url, kTestPackageName, second_day));
532 536
533 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 537 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
534 web_contents(), url, kTestPackageName, third_day, 538 web_contents(), url, kTestPackageName, third_day,
535 ui::PAGE_TRANSITION_FORM_SUBMIT); 539 ui::PAGE_TRANSITION_FORM_SUBMIT);
536 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 540 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
537 web_contents(), url, kTestPackageName, third_day)); 541 AppBannerSettingsHelper::ShouldShowBanner(
542 web_contents(), url, kTestPackageName, third_day));
538 543
539 // Visit the site again; now it should be shown. 544 // Visit the site again; now it should be shown.
540 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 545 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
541 web_contents(), url, kTestPackageName, fourth_day, 546 web_contents(), url, kTestPackageName, fourth_day,
542 ui::PAGE_TRANSITION_MANUAL_SUBFRAME); 547 ui::PAGE_TRANSITION_MANUAL_SUBFRAME);
543 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 548 EXPECT_EQ(NO_ERROR_DETECTED,
544 web_contents(), url, kTestPackageName, fourth_day)); 549 AppBannerSettingsHelper::ShouldShowBanner(
550 web_contents(), url, kTestPackageName, fourth_day));
545 } 551 }
546 552
547 TEST_F(AppBannerSettingsHelperTest, DirectEngagementWithHigherWeight) { 553 TEST_F(AppBannerSettingsHelperTest, DirectEngagementWithHigherWeight) {
548 AppBannerSettingsHelper::SetEngagementWeights(2, 0.5); 554 AppBannerSettingsHelper::SetEngagementWeights(2, 0.5);
549 GURL url(kTestURL); 555 GURL url(kTestURL);
550 NavigateAndCommit(url); 556 NavigateAndCommit(url);
551 557
552 base::Time reference_time = GetReferenceTime(); 558 base::Time reference_time = GetReferenceTime();
553 559
554 // By default the banner should not be shown. 560 // By default the banner should not be shown.
555 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 561 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
556 web_contents(), url, kTestPackageName, reference_time)); 562 AppBannerSettingsHelper::ShouldShowBanner(
563 web_contents(), url, kTestPackageName, reference_time));
557 564
558 // It should take one direct visit with a weight of 2 to trigger the banner. 565 // It should take one direct visit with a weight of 2 to trigger the banner.
559 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 566 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
560 web_contents(), url, kTestPackageName, reference_time, 567 web_contents(), url, kTestPackageName, reference_time,
561 ui::PAGE_TRANSITION_TYPED); 568 ui::PAGE_TRANSITION_TYPED);
562 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 569 EXPECT_EQ(NO_ERROR_DETECTED,
563 web_contents(), url, kTestPackageName, reference_time)); 570 AppBannerSettingsHelper::ShouldShowBanner(
571 web_contents(), url, kTestPackageName, reference_time));
564 } 572 }
565 573
566 TEST_F(AppBannerSettingsHelperTest, ShouldShowFromEngagement) { 574 TEST_F(AppBannerSettingsHelperTest, ShouldShowFromEngagement) {
567 GURL url(kTestURL); 575 GURL url(kTestURL);
568 NavigateAndCommit(url); 576 NavigateAndCommit(url);
569 577
570 base::Time reference_time = GetReferenceTime(); 578 base::Time reference_time = GetReferenceTime();
571 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1); 579 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
572 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 580 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
573 581
574 // By default the banner should not be shown. 582 // By default the banner should not be shown.
575 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 583 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
576 web_contents(), url, kTestPackageName, reference_time)); 584 AppBannerSettingsHelper::ShouldShowBanner(
585 web_contents(), url, kTestPackageName, reference_time));
577 586
578 // Visit the site once, it still should not be shown. 587 // Visit the site once, it still should not be shown.
579 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 588 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
580 web_contents(), url, kTestPackageName, one_year_ago, 589 web_contents(), url, kTestPackageName, one_year_ago,
581 ui::PAGE_TRANSITION_TYPED); 590 ui::PAGE_TRANSITION_TYPED);
582 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 591 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
583 web_contents(), url, kTestPackageName, reference_time)); 592 AppBannerSettingsHelper::ShouldShowBanner(
593 web_contents(), url, kTestPackageName, reference_time));
584 594
585 // Visit the site again after a long delay, it still should not be shown. 595 // Visit the site again after a long delay, it still should not be shown.
586 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 596 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
587 web_contents(), url, kTestPackageName, one_day_ago, 597 web_contents(), url, kTestPackageName, one_day_ago,
588 ui::PAGE_TRANSITION_TYPED); 598 ui::PAGE_TRANSITION_TYPED);
589 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 599 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
590 web_contents(), url, kTestPackageName, reference_time)); 600 AppBannerSettingsHelper::ShouldShowBanner(
601 web_contents(), url, kTestPackageName, reference_time));
591 602
592 // Visit the site again; now it should be shown. 603 // Visit the site again; now it should be shown.
593 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 604 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
594 web_contents(), url, kTestPackageName, reference_time, 605 web_contents(), url, kTestPackageName, reference_time,
595 ui::PAGE_TRANSITION_TYPED); 606 ui::PAGE_TRANSITION_TYPED);
596 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 607 EXPECT_EQ(NO_ERROR_DETECTED,
597 web_contents(), url, kTestPackageName, reference_time)); 608 AppBannerSettingsHelper::ShouldShowBanner(
609 web_contents(), url, kTestPackageName, reference_time));
598 } 610 }
599 611
600 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterBlocking) { 612 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterBlocking) {
601 GURL url(kTestURL); 613 GURL url(kTestURL);
602 NavigateAndCommit(url); 614 NavigateAndCommit(url);
603 615
604 base::Time reference_time = GetReferenceTime(); 616 base::Time reference_time = GetReferenceTime();
605 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1); 617 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
606 base::Time two_months_ago = reference_time - base::TimeDelta::FromDays(60); 618 base::Time two_months_ago = reference_time - base::TimeDelta::FromDays(60);
607 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 619 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
608 620
609 // By default the banner should not be shown. 621 // By default the banner should not be shown.
610 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 622 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
611 web_contents(), url, kTestPackageName, reference_time)); 623 AppBannerSettingsHelper::ShouldShowBanner(
624 web_contents(), url, kTestPackageName, reference_time));
612 625
613 // Record events such that the banner should show. 626 // Record events such that the banner should show.
614 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 627 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
615 web_contents(), url, kTestPackageName, one_day_ago, 628 web_contents(), url, kTestPackageName, one_day_ago,
616 ui::PAGE_TRANSITION_TYPED); 629 ui::PAGE_TRANSITION_TYPED);
617 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 630 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
618 web_contents(), url, kTestPackageName, reference_time, 631 web_contents(), url, kTestPackageName, reference_time,
619 ui::PAGE_TRANSITION_TYPED); 632 ui::PAGE_TRANSITION_TYPED);
620 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 633 EXPECT_EQ(NO_ERROR_DETECTED,
621 web_contents(), url, kTestPackageName, reference_time)); 634 AppBannerSettingsHelper::ShouldShowBanner(
635 web_contents(), url, kTestPackageName, reference_time));
622 636
623 // Block the site a long time ago. It should still be shown. 637 // Block the site a long time ago. It should still be shown.
624 AppBannerSettingsHelper::RecordBannerEvent( 638 AppBannerSettingsHelper::RecordBannerEvent(
625 web_contents(), url, kTestPackageName, 639 web_contents(), url, kTestPackageName,
626 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, one_year_ago); 640 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, one_year_ago);
627 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 641 EXPECT_EQ(NO_ERROR_DETECTED,
628 web_contents(), url, kTestPackageName, reference_time)); 642 AppBannerSettingsHelper::ShouldShowBanner(
643 web_contents(), url, kTestPackageName, reference_time));
629 644
630 // Block the site more recently. Now it should not be shown. 645 // Block the site more recently. Now it should not be shown.
631 AppBannerSettingsHelper::RecordBannerEvent( 646 AppBannerSettingsHelper::RecordBannerEvent(
632 web_contents(), url, kTestPackageName, 647 web_contents(), url, kTestPackageName,
633 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, two_months_ago); 648 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, two_months_ago);
634 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 649 EXPECT_EQ(PREVIOUSLY_BLOCKED,
635 web_contents(), url, kTestPackageName, reference_time)); 650 AppBannerSettingsHelper::ShouldShowBanner(
651 web_contents(), url, kTestPackageName, reference_time));
636 } 652 }
637 653
638 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterShowing) { 654 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterShowing) {
639 GURL url(kTestURL); 655 GURL url(kTestURL);
640 NavigateAndCommit(url); 656 NavigateAndCommit(url);
641 657
642 base::Time reference_time = GetReferenceTime(); 658 base::Time reference_time = GetReferenceTime();
643 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1); 659 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
644 base::Time three_weeks_ago = reference_time - base::TimeDelta::FromDays(21); 660 base::Time three_weeks_ago = reference_time - base::TimeDelta::FromDays(21);
645 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 661 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
646 662
647 // By default the banner should not be shown. 663 // By default the banner should not be shown.
648 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 664 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
649 web_contents(), url, kTestPackageName, reference_time)); 665 AppBannerSettingsHelper::ShouldShowBanner(
666 web_contents(), url, kTestPackageName, reference_time));
650 667
651 // Record events such that the banner should show. 668 // Record events such that the banner should show.
652 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 669 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
653 web_contents(), url, kTestPackageName, one_day_ago, 670 web_contents(), url, kTestPackageName, one_day_ago,
654 ui::PAGE_TRANSITION_TYPED); 671 ui::PAGE_TRANSITION_TYPED);
655 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 672 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
656 web_contents(), url, kTestPackageName, reference_time, 673 web_contents(), url, kTestPackageName, reference_time,
657 ui::PAGE_TRANSITION_TYPED); 674 ui::PAGE_TRANSITION_TYPED);
658 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 675 EXPECT_EQ(NO_ERROR_DETECTED,
659 web_contents(), url, kTestPackageName, reference_time)); 676 AppBannerSettingsHelper::ShouldShowBanner(
677 web_contents(), url, kTestPackageName, reference_time));
660 678
661 // Show the banner a long time ago. It should still be shown. 679 // Show the banner a long time ago. It should still be shown.
662 AppBannerSettingsHelper::RecordBannerEvent( 680 AppBannerSettingsHelper::RecordBannerEvent(
663 web_contents(), url, kTestPackageName, 681 web_contents(), url, kTestPackageName,
664 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, one_year_ago); 682 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, one_year_ago);
665 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 683 EXPECT_EQ(NO_ERROR_DETECTED,
666 web_contents(), url, kTestPackageName, reference_time)); 684 AppBannerSettingsHelper::ShouldShowBanner(
685 web_contents(), url, kTestPackageName, reference_time));
667 686
668 // Show the site more recently. Now it should not be shown. 687 // Show the site more recently. Now it should not be shown.
669 AppBannerSettingsHelper::RecordBannerEvent( 688 AppBannerSettingsHelper::RecordBannerEvent(
670 web_contents(), url, kTestPackageName, 689 web_contents(), url, kTestPackageName,
671 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, three_weeks_ago); 690 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, three_weeks_ago);
672 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 691 EXPECT_EQ(PREVIOUSLY_IGNORED,
673 web_contents(), url, kTestPackageName, reference_time)); 692 AppBannerSettingsHelper::ShouldShowBanner(
693 web_contents(), url, kTestPackageName, reference_time));
674 } 694 }
675 695
676 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterAdding) { 696 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterAdding) {
677 GURL url(kTestURL); 697 GURL url(kTestURL);
678 NavigateAndCommit(url); 698 NavigateAndCommit(url);
679 699
680 base::Time reference_time = GetReferenceTime(); 700 base::Time reference_time = GetReferenceTime();
681 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1); 701 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
682 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 702 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
683 703
684 // By default the banner should not be shown. 704 // By default the banner should not be shown.
685 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 705 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
686 web_contents(), url, kTestPackageName, reference_time)); 706 AppBannerSettingsHelper::ShouldShowBanner(
707 web_contents(), url, kTestPackageName, reference_time));
687 708
688 // Record events such that the banner should show. 709 // Record events such that the banner should show.
689 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 710 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
690 web_contents(), url, kTestPackageName, one_day_ago, 711 web_contents(), url, kTestPackageName, one_day_ago,
691 ui::PAGE_TRANSITION_TYPED); 712 ui::PAGE_TRANSITION_TYPED);
692 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 713 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
693 web_contents(), url, kTestPackageName, reference_time, 714 web_contents(), url, kTestPackageName, reference_time,
694 ui::PAGE_TRANSITION_TYPED); 715 ui::PAGE_TRANSITION_TYPED);
695 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 716 EXPECT_EQ(NO_ERROR_DETECTED,
696 web_contents(), url, kTestPackageName, reference_time)); 717 AppBannerSettingsHelper::ShouldShowBanner(
718 web_contents(), url, kTestPackageName, reference_time));
697 719
698 // Add the site a long time ago. It should not be shown. 720 // Add the site a long time ago. It should not be shown.
699 AppBannerSettingsHelper::RecordBannerEvent( 721 AppBannerSettingsHelper::RecordBannerEvent(
700 web_contents(), url, kTestPackageName, 722 web_contents(), url, kTestPackageName,
701 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 723 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
702 one_year_ago); 724 one_year_ago);
703 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 725 EXPECT_EQ(ALREADY_INSTALLED,
704 web_contents(), url, kTestPackageName, reference_time)); 726 AppBannerSettingsHelper::ShouldShowBanner(
727 web_contents(), url, kTestPackageName, reference_time));
705 } 728 }
706 729
707 TEST_F(AppBannerSettingsHelperTest, OperatesOnOrigins) { 730 TEST_F(AppBannerSettingsHelperTest, OperatesOnOrigins) {
708 GURL url(kTestURL); 731 GURL url(kTestURL);
709 NavigateAndCommit(url); 732 NavigateAndCommit(url);
710 733
711 base::Time reference_time = GetReferenceTime(); 734 base::Time reference_time = GetReferenceTime();
712 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1); 735 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
713 736
714 // By default the banner should not be shown. 737 // By default the banner should not be shown.
715 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 738 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
716 web_contents(), url, kTestPackageName, reference_time)); 739 AppBannerSettingsHelper::ShouldShowBanner(
740 web_contents(), url, kTestPackageName, reference_time));
717 741
718 // Record events such that the banner should show. 742 // Record events such that the banner should show.
719 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 743 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
720 web_contents(), url, kTestPackageName, one_day_ago, 744 web_contents(), url, kTestPackageName, one_day_ago,
721 ui::PAGE_TRANSITION_TYPED); 745 ui::PAGE_TRANSITION_TYPED);
722 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 746 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
723 web_contents(), url, kTestPackageName, reference_time, 747 web_contents(), url, kTestPackageName, reference_time,
724 ui::PAGE_TRANSITION_TYPED); 748 ui::PAGE_TRANSITION_TYPED);
725 749
726 // Navigate to another page on the same origin. 750 // Navigate to another page on the same origin.
727 url = GURL(kSameOriginTestURL); 751 url = GURL(kSameOriginTestURL);
728 NavigateAndCommit(url); 752 NavigateAndCommit(url);
729 753
730 // The banner should show as settings are per-origin. 754 // The banner should show as settings are per-origin.
731 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 755 EXPECT_EQ(NO_ERROR_DETECTED,
732 web_contents(), url, kTestPackageName, reference_time)); 756 AppBannerSettingsHelper::ShouldShowBanner(
757 web_contents(), url, kTestPackageName, reference_time));
733 } 758 }
734 759
735 TEST_F(AppBannerSettingsHelperTest, ShouldShowWithHigherTotal) { 760 TEST_F(AppBannerSettingsHelperTest, ShouldShowWithHigherTotal) {
736 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); 761 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5);
737 GURL url(kTestURL); 762 GURL url(kTestURL);
738 NavigateAndCommit(url); 763 NavigateAndCommit(url);
739 764
740 base::Time reference_time = GetReferenceTime(); 765 base::Time reference_time = GetReferenceTime();
741 base::Time second_day = reference_time + base::TimeDelta::FromDays(1); 766 base::Time second_day = reference_time + base::TimeDelta::FromDays(1);
742 base::Time third_day = reference_time + base::TimeDelta::FromDays(2); 767 base::Time third_day = reference_time + base::TimeDelta::FromDays(2);
743 base::Time fourth_day = reference_time + base::TimeDelta::FromDays(3); 768 base::Time fourth_day = reference_time + base::TimeDelta::FromDays(3);
744 base::Time fifth_day = reference_time + base::TimeDelta::FromDays(4); 769 base::Time fifth_day = reference_time + base::TimeDelta::FromDays(4);
745 770
746 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 771 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
747 web_contents(), url, kTestPackageName, reference_time)); 772 AppBannerSettingsHelper::ShouldShowBanner(
773 web_contents(), url, kTestPackageName, reference_time));
748 774
749 // It should take five visits to trigger the banner. 775 // It should take five visits to trigger the banner.
750 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 776 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
751 web_contents(), url, kTestPackageName, reference_time, 777 web_contents(), url, kTestPackageName, reference_time,
752 ui::PAGE_TRANSITION_LINK); 778 ui::PAGE_TRANSITION_LINK);
753 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 779 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
754 web_contents(), url, kTestPackageName, reference_time)); 780 AppBannerSettingsHelper::ShouldShowBanner(
781 web_contents(), url, kTestPackageName, reference_time));
755 782
756 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 783 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
757 web_contents(), url, kTestPackageName, second_day, 784 web_contents(), url, kTestPackageName, second_day,
758 ui::PAGE_TRANSITION_TYPED); 785 ui::PAGE_TRANSITION_TYPED);
759 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 786 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
760 web_contents(), url, kTestPackageName, second_day)); 787 AppBannerSettingsHelper::ShouldShowBanner(
788 web_contents(), url, kTestPackageName, reference_time));
761 789
762 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 790 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
763 web_contents(), url, kTestPackageName, third_day, 791 web_contents(), url, kTestPackageName, third_day,
764 ui::PAGE_TRANSITION_GENERATED); 792 ui::PAGE_TRANSITION_GENERATED);
765 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 793 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
766 web_contents(), url, kTestPackageName, third_day)); 794 AppBannerSettingsHelper::ShouldShowBanner(
795 web_contents(), url, kTestPackageName, reference_time));
767 796
768 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 797 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
769 web_contents(), url, kTestPackageName, fourth_day, 798 web_contents(), url, kTestPackageName, fourth_day,
770 ui::PAGE_TRANSITION_LINK); 799 ui::PAGE_TRANSITION_LINK);
771 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 800 EXPECT_EQ(INSUFFICIENT_ENGAGEMENT,
772 web_contents(), url, kTestPackageName, fourth_day)); 801 AppBannerSettingsHelper::ShouldShowBanner(
802 web_contents(), url, kTestPackageName, reference_time));
773 803
774 // Visit the site again; now it should be shown. 804 // Visit the site again; now it should be shown.
775 AppBannerSettingsHelper::RecordBannerCouldShowEvent( 805 AppBannerSettingsHelper::RecordBannerCouldShowEvent(
776 web_contents(), url, kTestPackageName, fifth_day, 806 web_contents(), url, kTestPackageName, fifth_day,
777 ui::PAGE_TRANSITION_TYPED); 807 ui::PAGE_TRANSITION_TYPED);
778 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( 808 EXPECT_EQ(NO_ERROR_DETECTED,
779 web_contents(), url, kTestPackageName, fifth_day)); 809 AppBannerSettingsHelper::ShouldShowBanner(
810 web_contents(), url, kTestPackageName, reference_time));
780 } 811 }
781 812
782 TEST_F(AppBannerSettingsHelperTest, WasLaunchedRecently) { 813 TEST_F(AppBannerSettingsHelperTest, WasLaunchedRecently) {
783 GURL url(kTestURL); 814 GURL url(kTestURL);
784 GURL url_same_origin(kSameOriginTestURL); 815 GURL url_same_origin(kSameOriginTestURL);
785 GURL url2(kDifferentOriginTestURL); 816 GURL url2(kDifferentOriginTestURL);
786 NavigateAndCommit(url); 817 NavigateAndCommit(url);
787 818
788 base::Time reference_time = GetReferenceTime(); 819 base::Time reference_time = GetReferenceTime();
789 base::Time first_day = reference_time + base::TimeDelta::FromDays(1); 820 base::Time first_day = reference_time + base::TimeDelta::FromDays(1);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url, 872 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url,
842 first_day)); 873 first_day));
843 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url, 874 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url,
844 ninth_day)); 875 ninth_day));
845 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url, 876 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url,
846 tenth_day)); 877 tenth_day));
847 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url, 878 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(web_contents(), url,
848 eleventh_day)); 879 eleventh_day));
849 880
850 } 881 }
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_settings_helper.cc ('k') | chrome/browser/installable/installable_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698