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

Side by Side Diff: components/previews/previews_black_list_item_unittest.cc

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: tbansal comments Created 4 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/previews/previews_black_list_item.h"
6
7 #include <memory>
8
9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 using PreviewsBlackListItemTest = testing::Test;
15
16 } // namespace
17
18 namespace previews {
19
20 TEST_F(PreviewsBlackListItemTest, BlackListState) {
21 const int history = 4;
22 const int threshold = 2;
23 const base::TimeDelta duration = base::TimeDelta::FromSeconds(30);
24 const base::Time now = base::Time::UnixEpoch();
25 const base::TimeDelta delay_between_entries = base::TimeDelta::FromSeconds(1);
26 const base::Time later = now + duration + (delay_between_entries * 3);
27
28 std::unique_ptr<PreviewsBlackListItem> black_list_item(
29 new PreviewsBlackListItem(history, threshold, duration));
30
31 // Empty black list item should report that the host is allowed.
32 EXPECT_FALSE(black_list_item->IsBlackListed(now));
33 EXPECT_FALSE(black_list_item->IsBlackListed(later));
34
35 black_list_item->AddPreviewNavigation(true, now);
36 // Black list item of size less that |threshold| should report that the host
37 // is allowed.
38 EXPECT_FALSE(black_list_item->IsBlackListed(now));
39 EXPECT_FALSE(black_list_item->IsBlackListed(later));
40
41 black_list_item->AddPreviewNavigation(true, now + delay_between_entries);
42 // Black list item with |threshold| fresh entries should report the host as
43 // disallowed.
44 EXPECT_TRUE(black_list_item->IsBlackListed(now));
45 // Black list item with only entries from longer than |duration| ago should
46 // report the host is allowed.
47 EXPECT_FALSE(black_list_item->IsBlackListed(later));
48 black_list_item->AddPreviewNavigation(true,
49 later - (delay_between_entries * 2));
50 // Black list item with a fresh opt out and total number of opt outs larger
51 // than |threshold| should report the host is disallowed.
52 EXPECT_TRUE(black_list_item->IsBlackListed(later));
53
54 // The black list item should maintain entries based on time, so adding
55 // |history| entries should not push out newer entries.
56 black_list_item->AddPreviewNavigation(true,
57 later - delay_between_entries * 2);
58 black_list_item->AddPreviewNavigation(false,
59 later - delay_between_entries * 3);
60 black_list_item->AddPreviewNavigation(false,
61 later - delay_between_entries * 3);
62 black_list_item->AddPreviewNavigation(false,
63 later - delay_between_entries * 3);
64 black_list_item->AddPreviewNavigation(false,
65 later - delay_between_entries * 3);
66 EXPECT_TRUE(black_list_item->IsBlackListed(later));
67
68 // The black list item should maintain entries based on time, so adding
69 // |history| newer entries should push out older entries.
70 black_list_item->AddPreviewNavigation(false,
71 later - delay_between_entries * 1);
72 black_list_item->AddPreviewNavigation(false,
73 later - delay_between_entries * 1);
74 black_list_item->AddPreviewNavigation(false,
75 later - delay_between_entries * 1);
76 black_list_item->AddPreviewNavigation(false,
77 later - delay_between_entries * 1);
78 EXPECT_FALSE(black_list_item->IsBlackListed(later));
79 }
80
81 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698