| OLD | NEW |
| 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" |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | 769 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( |
| 770 web_contents(), url, kTestPackageName, fourth_day)); | 770 web_contents(), url, kTestPackageName, fourth_day)); |
| 771 | 771 |
| 772 // Visit the site again; now it should be shown. | 772 // Visit the site again; now it should be shown. |
| 773 AppBannerSettingsHelper::RecordBannerCouldShowEvent( | 773 AppBannerSettingsHelper::RecordBannerCouldShowEvent( |
| 774 web_contents(), url, kTestPackageName, fifth_day, | 774 web_contents(), url, kTestPackageName, fifth_day, |
| 775 ui::PAGE_TRANSITION_TYPED); | 775 ui::PAGE_TRANSITION_TYPED); |
| 776 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( | 776 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( |
| 777 web_contents(), url, kTestPackageName, fifth_day)); | 777 web_contents(), url, kTestPackageName, fifth_day)); |
| 778 } | 778 } |
| 779 | |
| 780 // Test that the banner triggers correctly using site engagement. | |
| 781 TEST_F(AppBannerSettingsHelperTest, SiteEngagementTrigger) { | |
| 782 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 783 command_line->AppendSwitch(switches::kEnableSiteEngagementAppBanner); | |
| 784 | |
| 785 SiteEngagementService* service = SiteEngagementService::Get(profile()); | |
| 786 DCHECK(service); | |
| 787 | |
| 788 // Not used, but needed for method call. | |
| 789 base::Time reference_time = GetReferenceTime(); | |
| 790 GURL url(kTestURL); | |
| 791 | |
| 792 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 793 web_contents(), url, kTestPackageName, reference_time)); | |
| 794 | |
| 795 service->AddPoints(url, 1); | |
| 796 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 797 web_contents(), url, kTestPackageName, reference_time)); | |
| 798 | |
| 799 service->AddPoints(url, 1); | |
| 800 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 801 web_contents(), url, kTestPackageName, reference_time)); | |
| 802 | |
| 803 AppBannerSettingsHelper::SetTotalEngagementToTrigger(5); | |
| 804 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 805 web_contents(), url, kTestPackageName, reference_time)); | |
| 806 | |
| 807 service->AddPoints(url, 1.5); | |
| 808 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 809 web_contents(), url, kTestPackageName, reference_time)); | |
| 810 | |
| 811 service->AddPoints(url, 0.5); | |
| 812 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 813 web_contents(), url, kTestPackageName, reference_time)); | |
| 814 | |
| 815 service->AddPoints(url, 1.5); | |
| 816 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner( | |
| 817 web_contents(), url, kTestPackageName, reference_time)); | |
| 818 } | |
| OLD | NEW |