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

Side by Side Diff: chrome/browser/engagement/important_sites_util_unittest.cc

Issue 2393103002: [Durable] Updated Durable heuristic to use 'important sites' (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/preferences/important_sites_util.h" 5 #include <chrome/browser/engagement/important_sites_util.h>
michaeln 2016/10/05 23:27:45 ditto <>'s and blank line
dmurph 2016/10/06 01:01:59 Done.
6
7 #include <memory> 6 #include <memory>
8 #include <utility> 7 #include <utility>
9 8
10 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
13 #include "base/metrics/sample_vector.h" 12 #include "base/metrics/sample_vector.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 std::vector<ImportantDomainInfo> important_sites = 250 std::vector<ImportantDomainInfo> important_sites =
252 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), 251 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
253 kNumImportantSites); 252 kNumImportantSites);
254 std::vector<std::string> expected_sorted_domains = {"google.com"}; 253 std::vector<std::string> expected_sorted_domains = {"google.com"};
255 std::vector<GURL> expected_sorted_origins = {url1}; 254 std::vector<GURL> expected_sorted_origins = {url1};
256 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, 255 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
257 important_sites); 256 important_sites);
258 ASSERT_EQ(1u, important_sites.size()); 257 ASSERT_EQ(1u, important_sites.size());
259 // Record ignore twice. 258 // Record ignore twice.
260 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 259 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
261 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 260 profile(), std::vector<std::string>(), std::vector<int32_t>(),
261 {"google.com"}, {important_sites[0].reason_bitfield});
262 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 262 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
263 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 263 profile(), std::vector<std::string>(), std::vector<int32_t>(),
264 {"google.com"}, {important_sites[0].reason_bitfield});
264 265
265 // Important fetch 2. 266 // Important fetch 2.
266 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 267 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
267 profile(), kNumImportantSites); 268 profile(), kNumImportantSites);
268 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, 269 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
269 important_sites); 270 important_sites);
270 // We shouldn't blacklist after first two times. 271 // We shouldn't blacklist after first two times.
271 ASSERT_EQ(1u, important_sites.size()); 272 ASSERT_EQ(1u, important_sites.size());
272 273
273 // Record ignore 3rd time. 274 // Record ignore 3rd time.
274 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 275 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
275 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 276 profile(), std::vector<std::string>(), std::vector<int32_t>(),
277 {"google.com"}, {important_sites[0].reason_bitfield});
276 278
277 // Important fetch 3. We should be blacklisted now. 279 // Important fetch 3. We should be blacklisted now.
278 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 280 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
279 profile(), kNumImportantSites); 281 profile(), kNumImportantSites);
280 ASSERT_EQ(0u, important_sites.size()); 282 ASSERT_EQ(0u, important_sites.size());
281 } 283 }
282 284
283 TEST_F(ImportantSitesUtilTest, BlacklistingReset) { 285 TEST_F(ImportantSitesUtilTest, BlacklistingReset) {
284 SiteEngagementService* service = SiteEngagementService::Get(profile()); 286 SiteEngagementService* service = SiteEngagementService::Get(profile());
285 ASSERT_TRUE(service); 287 ASSERT_TRUE(service);
286 288
287 GURL url1("http://www.google.com/"); 289 GURL url1("http://www.google.com/");
288 290
289 // Set a bunch of positive signals. 291 // Set a bunch of positive signals.
290 service->ResetScoreForURL(url1, 5); 292 service->ResetScoreForURL(url1, 5);
291 AddBookmark(url1); 293 AddBookmark(url1);
292 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, 294 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW,
293 url1); 295 url1);
294 296
295 std::vector<ImportantDomainInfo> important_sites = 297 std::vector<ImportantDomainInfo> important_sites =
296 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), 298 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
297 kNumImportantSites); 299 kNumImportantSites);
298 300
299 // Record ignored twice. 301 // Record ignored twice.
300 ASSERT_EQ(1u, important_sites.size()); 302 ASSERT_EQ(1u, important_sites.size());
301 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 303 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
302 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 304 profile(), std::vector<std::string>(), std::vector<int32_t>(),
305 {"google.com"}, {important_sites[0].reason_bitfield});
303 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 306 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
304 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 307 profile(), std::vector<std::string>(), std::vector<int32_t>(),
308 {"google.com"}, {important_sites[0].reason_bitfield});
305 309
306 // Important fetch, we should still be there. 310 // Important fetch, we should still be there.
307 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 311 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
308 profile(), kNumImportantSites); 312 profile(), kNumImportantSites);
309 std::vector<std::string> expected_sorted_domains = {"google.com"}; 313 std::vector<std::string> expected_sorted_domains = {"google.com"};
310 std::vector<GURL> expected_sorted_origins = {url1}; 314 std::vector<GURL> expected_sorted_origins = {url1};
311 ASSERT_EQ(1u, important_sites.size()); 315 ASSERT_EQ(1u, important_sites.size());
312 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, 316 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
313 important_sites); 317 important_sites);
314 318
315 // Record NOT ignored. 319 // Record NOT ignored.
316 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 320 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
317 profile(), {"google.com"}, {important_sites[0].reason_bitfield}, {}, {}); 321 profile(), {"google.com"}, {important_sites[0].reason_bitfield},
322 std::vector<std::string>(), std::vector<int32_t>());
318 323
319 // Record ignored twice again. 324 // Record ignored twice again.
320 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 325 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
321 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 326 profile(), std::vector<std::string>(), std::vector<int32_t>(),
327 {"google.com"}, {important_sites[0].reason_bitfield});
322 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 328 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
323 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 329 profile(), std::vector<std::string>(), std::vector<int32_t>(),
330 {"google.com"}, {important_sites[0].reason_bitfield});
324 331
325 // Important fetch, we should still be there. 332 // Important fetch, we should still be there.
326 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 333 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
327 profile(), kNumImportantSites); 334 profile(), kNumImportantSites);
328 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, 335 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
329 important_sites); 336 important_sites);
330 337
331 // Record ignored 3rd time in a row. 338 // Record ignored 3rd time in a row.
332 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 339 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
333 profile(), {}, {}, {"google.com"}, {important_sites[0].reason_bitfield}); 340 profile(), std::vector<std::string>(), std::vector<int32_t>(),
341 {"google.com"}, {important_sites[0].reason_bitfield});
334 342
335 // Blacklisted now. 343 // Blacklisted now.
336 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 344 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
337 profile(), kNumImportantSites); 345 profile(), kNumImportantSites);
338 EXPECT_EQ(0u, important_sites.size()); 346 EXPECT_EQ(0u, important_sites.size());
339 } 347 }
340 348
341 TEST_F(ImportantSitesUtilTest, Metrics) { 349 TEST_F(ImportantSitesUtilTest, Metrics) {
342 SiteEngagementService* service = SiteEngagementService::Get(profile()); 350 SiteEngagementService* service = SiteEngagementService::Get(profile());
343 ASSERT_TRUE(service); 351 ASSERT_TRUE(service);
(...skipping 12 matching lines...) Expand all
356 364
357 std::vector<ImportantDomainInfo> important_sites = 365 std::vector<ImportantDomainInfo> important_sites =
358 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), 366 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
359 kNumImportantSites); 367 kNumImportantSites);
360 368
361 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( 369 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites(
362 profile(), {"google.com", "youtube.com"}, 370 profile(), {"google.com", "youtube.com"},
363 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield}, 371 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield},
364 {"bad.com"}, {important_sites[2].reason_bitfield}); 372 {"bad.com"}, {important_sites[2].reason_bitfield});
365 373
366 EXPECT_THAT(histogram_tester.GetAllSamples( 374 EXPECT_THAT(
367 "Storage.ImportantSites.CBDChosenReason"), 375 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDChosenReason"),
368 testing::ElementsAre( 376 testing::ElementsAre(base::Bucket(ENGAGEMENT, 1),
369 base::Bucket(ENGAGEMENT, 1), 377 base::Bucket(BOOKMARKS, 1),
370 base::Bucket(BOOKMARKS, 1), 378 base::Bucket(NOTIFICATIONS, 1)));
371 base::Bucket(NOTIFICATIONS, 1)));
372 379
373 EXPECT_THAT( 380 EXPECT_THAT(
374 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"), 381 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"),
375 testing::ElementsAre(base::Bucket(BOOKMARKS, 1))); 382 testing::ElementsAre(base::Bucket(BOOKMARKS, 1)));
376 383
377 // Bookmarks are "unknown", as they were added after the crossed reasons. 384 // Bookmarks are "unknown", as they were added after the crossed reasons.
378 EXPECT_THAT(histogram_tester.GetAllSamples( 385 EXPECT_THAT(histogram_tester.GetAllSamples(
379 "Storage.BlacklistedImportantSites.Reason"), 386 "Storage.BlacklistedImportantSites.Reason"),
380 testing::ElementsAre( 387 testing::ElementsAre(
381 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1), 388 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1),
382 base::Bucket(CROSSED_REASON_UNKNOWN, 1))); 389 base::Bucket(CROSSED_REASON_UNKNOWN, 1)));
383 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698