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

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

Issue 2735333002: Rename SiteEngagementService::ResetScoreForURL. (Closed)
Patch Set: Created 3 years, 9 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 "chrome/browser/banners/app_banner_metrics.h" 5 #include "chrome/browser/banners/app_banner_metrics.h"
6 #include "chrome/browser/banners/app_banner_settings_helper.h" 6 #include "chrome/browser/banners/app_banner_settings_helper.h"
7 #include "chrome/browser/engagement/site_engagement_service.h" 7 #include "chrome/browser/engagement/site_engagement_service.h"
8 #include "chrome/browser/installable/installable_logging.h" 8 #include "chrome/browser/installable/installable_logging.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 TEST_F(AppBannerSettingsHelperTest, ShouldShowFromEngagement) { 86 TEST_F(AppBannerSettingsHelperTest, ShouldShowFromEngagement) {
87 GURL url(kTestURL); 87 GURL url(kTestURL);
88 SiteEngagementService* service = SiteEngagementService::Get(profile()); 88 SiteEngagementService* service = SiteEngagementService::Get(profile());
89 89
90 // By default the banner should not be shown. 90 // By default the banner should not be shown.
91 EXPECT_FALSE( 91 EXPECT_FALSE(
92 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 92 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
93 93
94 // Add 1 engagement, it still should not be shown. 94 // Add 1 engagement, it still should not be shown.
95 service->ResetScoreForURL(url, 1); 95 service->ResetBaseScoreForURL(url, 1);
96 EXPECT_FALSE( 96 EXPECT_FALSE(
97 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 97 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
98 98
99 // Add 1 more engagement; now it should be shown. 99 // Add 1 more engagement; now it should be shown.
100 service->ResetScoreForURL(url, 2); 100 service->ResetBaseScoreForURL(url, 2);
101 EXPECT_TRUE( 101 EXPECT_TRUE(
102 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 102 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
103 } 103 }
104 104
105 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterBlocking) { 105 TEST_F(AppBannerSettingsHelperTest, ShouldNotShowAfterBlocking) {
106 GURL url(kTestURL); 106 GURL url(kTestURL);
107 NavigateAndCommit(url); 107 NavigateAndCommit(url);
108 SiteEngagementService* service = SiteEngagementService::Get(profile()); 108 SiteEngagementService* service = SiteEngagementService::Get(profile());
109 109
110 base::Time reference_time = GetReferenceTime(); 110 base::Time reference_time = GetReferenceTime();
111 base::Time two_months_ago = reference_time - base::TimeDelta::FromDays(60); 111 base::Time two_months_ago = reference_time - base::TimeDelta::FromDays(60);
112 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 112 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
113 113
114 // By default the banner should not be shown. 114 // By default the banner should not be shown.
115 EXPECT_FALSE( 115 EXPECT_FALSE(
116 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 116 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
117 117
118 // Add engagement such that the banner should show. 118 // Add engagement such that the banner should show.
119 service->ResetScoreForURL(url, 4); 119 service->ResetBaseScoreForURL(url, 4);
120 EXPECT_TRUE( 120 EXPECT_TRUE(
121 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 121 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
122 EXPECT_EQ(NO_ERROR_DETECTED, 122 EXPECT_EQ(NO_ERROR_DETECTED,
123 AppBannerSettingsHelper::ShouldShowBanner( 123 AppBannerSettingsHelper::ShouldShowBanner(
124 web_contents(), url, kTestPackageName, reference_time)); 124 web_contents(), url, kTestPackageName, reference_time));
125 125
126 // Block the site a long time ago. It should still be shown. 126 // Block the site a long time ago. It should still be shown.
127 AppBannerSettingsHelper::RecordBannerEvent( 127 AppBannerSettingsHelper::RecordBannerEvent(
128 web_contents(), url, kTestPackageName, 128 web_contents(), url, kTestPackageName,
129 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, one_year_ago); 129 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, one_year_ago);
(...skipping 24 matching lines...) Expand all
154 154
155 base::Time reference_time = GetReferenceTime(); 155 base::Time reference_time = GetReferenceTime();
156 base::Time one_week_ago = reference_time - base::TimeDelta::FromDays(7); 156 base::Time one_week_ago = reference_time - base::TimeDelta::FromDays(7);
157 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 157 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
158 158
159 // By default the banner should not be shown. 159 // By default the banner should not be shown.
160 EXPECT_FALSE( 160 EXPECT_FALSE(
161 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 161 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
162 162
163 // Add engagement such that the banner should show. 163 // Add engagement such that the banner should show.
164 service->ResetScoreForURL(url, 4); 164 service->ResetBaseScoreForURL(url, 4);
165 EXPECT_TRUE( 165 EXPECT_TRUE(
166 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 166 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
167 EXPECT_EQ(NO_ERROR_DETECTED, 167 EXPECT_EQ(NO_ERROR_DETECTED,
168 AppBannerSettingsHelper::ShouldShowBanner( 168 AppBannerSettingsHelper::ShouldShowBanner(
169 web_contents(), url, kTestPackageName, reference_time)); 169 web_contents(), url, kTestPackageName, reference_time));
170 170
171 // Show the banner a long time ago. It should still be shown. 171 // Show the banner a long time ago. It should still be shown.
172 AppBannerSettingsHelper::RecordBannerEvent( 172 AppBannerSettingsHelper::RecordBannerEvent(
173 web_contents(), url, kTestPackageName, 173 web_contents(), url, kTestPackageName,
174 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, one_year_ago); 174 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, one_year_ago);
(...skipping 22 matching lines...) Expand all
197 SiteEngagementService* service = SiteEngagementService::Get(profile()); 197 SiteEngagementService* service = SiteEngagementService::Get(profile());
198 198
199 base::Time reference_time = GetReferenceTime(); 199 base::Time reference_time = GetReferenceTime();
200 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366); 200 base::Time one_year_ago = reference_time - base::TimeDelta::FromDays(366);
201 201
202 // By default the banner should not be shown. 202 // By default the banner should not be shown.
203 EXPECT_FALSE( 203 EXPECT_FALSE(
204 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 204 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
205 205
206 // Add engagement such that the banner should show. 206 // Add engagement such that the banner should show.
207 service->ResetScoreForURL(url, 4); 207 service->ResetBaseScoreForURL(url, 4);
208 EXPECT_TRUE( 208 EXPECT_TRUE(
209 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 209 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
210 EXPECT_EQ(NO_ERROR_DETECTED, 210 EXPECT_EQ(NO_ERROR_DETECTED,
211 AppBannerSettingsHelper::ShouldShowBanner( 211 AppBannerSettingsHelper::ShouldShowBanner(
212 web_contents(), url, kTestPackageName, reference_time)); 212 web_contents(), url, kTestPackageName, reference_time));
213 213
214 // Add the site a long time ago. It should not be shown. 214 // Add the site a long time ago. It should not be shown.
215 AppBannerSettingsHelper::RecordBannerEvent( 215 AppBannerSettingsHelper::RecordBannerEvent(
216 web_contents(), url, kTestPackageName, 216 web_contents(), url, kTestPackageName,
217 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 217 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
218 one_year_ago); 218 one_year_ago);
219 EXPECT_EQ(ALREADY_INSTALLED, 219 EXPECT_EQ(ALREADY_INSTALLED,
220 AppBannerSettingsHelper::ShouldShowBanner( 220 AppBannerSettingsHelper::ShouldShowBanner(
221 web_contents(), url, kTestPackageName, reference_time)); 221 web_contents(), url, kTestPackageName, reference_time));
222 } 222 }
223 223
224 TEST_F(AppBannerSettingsHelperTest, OperatesOnOrigins) { 224 TEST_F(AppBannerSettingsHelperTest, OperatesOnOrigins) {
225 GURL url(kTestURL); 225 GURL url(kTestURL);
226 SiteEngagementService* service = SiteEngagementService::Get(profile()); 226 SiteEngagementService* service = SiteEngagementService::Get(profile());
227 227
228 // By default the banner should not be shown. 228 // By default the banner should not be shown.
229 EXPECT_FALSE( 229 EXPECT_FALSE(
230 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 230 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
231 231
232 // Add engagement such that the banner should show. 232 // Add engagement such that the banner should show.
233 service->ResetScoreForURL(url, 4); 233 service->ResetBaseScoreForURL(url, 4);
234 EXPECT_TRUE( 234 EXPECT_TRUE(
235 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 235 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
236 236
237 // Try another page on the same origin. 237 // Try another page on the same origin.
238 url = GURL(kSameOriginTestURL); 238 url = GURL(kSameOriginTestURL);
239 239
240 // The banner should show as settings are per-origin. 240 // The banner should show as settings are per-origin.
241 EXPECT_TRUE( 241 EXPECT_TRUE(
242 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 242 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
243 EXPECT_EQ(NO_ERROR_DETECTED, 243 EXPECT_EQ(NO_ERROR_DETECTED,
244 AppBannerSettingsHelper::ShouldShowBanner( 244 AppBannerSettingsHelper::ShouldShowBanner(
245 web_contents(), url, kTestPackageName, GetReferenceTime())); 245 web_contents(), url, kTestPackageName, GetReferenceTime()));
246 } 246 }
247 247
248 TEST_F(AppBannerSettingsHelperTest, ShouldShowWithHigherTotal) { 248 TEST_F(AppBannerSettingsHelperTest, ShouldShowWithHigherTotal) {
249 AppBannerSettingsHelper::SetTotalEngagementToTrigger(10); 249 AppBannerSettingsHelper::SetTotalEngagementToTrigger(10);
250 GURL url(kTestURL); 250 GURL url(kTestURL);
251 SiteEngagementService* service = SiteEngagementService::Get(profile()); 251 SiteEngagementService* service = SiteEngagementService::Get(profile());
252 252
253 // By default the banner should not be shown. 253 // By default the banner should not be shown.
254 EXPECT_FALSE( 254 EXPECT_FALSE(
255 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 255 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
256 256
257 // Add engagement such that the banner should show. 257 // Add engagement such that the banner should show.
258 service->ResetScoreForURL(url, 2); 258 service->ResetBaseScoreForURL(url, 2);
259 EXPECT_FALSE( 259 EXPECT_FALSE(
260 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 260 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
261 261
262 service->ResetScoreForURL(url, 4); 262 service->ResetBaseScoreForURL(url, 4);
263 EXPECT_FALSE( 263 EXPECT_FALSE(
264 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 264 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
265 265
266 service->ResetScoreForURL(url, 6); 266 service->ResetBaseScoreForURL(url, 6);
267 EXPECT_FALSE( 267 EXPECT_FALSE(
268 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 268 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
269 269
270 service->ResetScoreForURL(url, 8); 270 service->ResetBaseScoreForURL(url, 8);
271 EXPECT_FALSE( 271 EXPECT_FALSE(
272 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 272 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
273 273
274 service->ResetScoreForURL(url, 10); 274 service->ResetBaseScoreForURL(url, 10);
275 EXPECT_TRUE( 275 EXPECT_TRUE(
276 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url))); 276 AppBannerSettingsHelper::HasSufficientEngagement(service->GetScore(url)));
277 277
278 EXPECT_EQ(NO_ERROR_DETECTED, 278 EXPECT_EQ(NO_ERROR_DETECTED,
279 AppBannerSettingsHelper::ShouldShowBanner( 279 AppBannerSettingsHelper::ShouldShowBanner(
280 web_contents(), url, kTestPackageName, GetReferenceTime())); 280 web_contents(), url, kTestPackageName, GetReferenceTime()));
281 } 281 }
282 282
283 TEST_F(AppBannerSettingsHelperTest, WasLaunchedRecently) { 283 TEST_F(AppBannerSettingsHelperTest, WasLaunchedRecently) {
284 GURL url(kTestURL); 284 GURL url(kTestURL);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 first_day); 341 first_day);
342 EXPECT_TRUE( 342 EXPECT_TRUE(
343 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, first_day)); 343 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, first_day));
344 EXPECT_TRUE( 344 EXPECT_TRUE(
345 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, ninth_day)); 345 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, ninth_day));
346 EXPECT_TRUE( 346 EXPECT_TRUE(
347 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, tenth_day)); 347 AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, tenth_day));
348 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(profile(), url, 348 EXPECT_TRUE(AppBannerSettingsHelper::WasLaunchedRecently(profile(), url,
349 eleventh_day)); 349 eleventh_day));
350 } 350 }
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager_browsertest.cc ('k') | chrome/browser/budget_service/budget_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698