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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" | 10 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 | 51 |
52 class SiteEngagementEvictionPolicyTest : public testing::Test { | 52 class SiteEngagementEvictionPolicyTest : public testing::Test { |
53 public: | 53 public: |
54 SiteEngagementEvictionPolicyTest() | 54 SiteEngagementEvictionPolicyTest() |
55 : score_provider_(new TestSiteEngagementScoreProvider()), | 55 : score_provider_(new TestSiteEngagementScoreProvider()), |
56 storage_policy_(new content::MockSpecialStoragePolicy()) {} | 56 storage_policy_(new content::MockSpecialStoragePolicy()) {} |
57 | 57 |
58 ~SiteEngagementEvictionPolicyTest() override {} | 58 ~SiteEngagementEvictionPolicyTest() override {} |
59 | 59 |
| 60 GURL CalculateEvictionOriginWithExceptions(const std::map<GURL, int64>& usage, |
| 61 const std::set<GURL>& exceptions) { |
| 62 return SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( |
| 63 storage_policy_, score_provider_.get(), exceptions, usage, |
| 64 kGlobalQuota); |
| 65 } |
| 66 |
60 GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage) { | 67 GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage) { |
61 return SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( | 68 return CalculateEvictionOriginWithExceptions(usage, std::set<GURL>()); |
62 storage_policy_, score_provider_.get(), usage, kGlobalQuota); | |
63 } | 69 } |
64 | 70 |
65 TestSiteEngagementScoreProvider* score_provider() { | 71 TestSiteEngagementScoreProvider* score_provider() { |
66 return score_provider_.get(); | 72 return score_provider_.get(); |
67 } | 73 } |
68 | 74 |
69 content::MockSpecialStoragePolicy* storage_policy() { | 75 content::MockSpecialStoragePolicy* storage_policy() { |
70 return storage_policy_.get(); | 76 return storage_policy_.get(); |
71 } | 77 } |
72 | 78 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); | 136 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); |
131 | 137 |
132 // Durable storage doesn't get evicted. | 138 // Durable storage doesn't get evicted. |
133 storage_policy()->AddDurable(url2); | 139 storage_policy()->AddDurable(url2); |
134 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); | 140 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); |
135 | 141 |
136 // Unlimited storage doesn't get evicted. | 142 // Unlimited storage doesn't get evicted. |
137 storage_policy()->AddUnlimited(url1); | 143 storage_policy()->AddUnlimited(url1); |
138 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); | 144 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); |
139 } | 145 } |
| 146 |
| 147 TEST_F(SiteEngagementEvictionPolicyTest, Exceptions) { |
| 148 GURL url1("http://www.google.com"); |
| 149 GURL url2("http://www.example.com"); |
| 150 |
| 151 std::map<GURL, int64> usage; |
| 152 usage[url1] = 10 * 1024; |
| 153 usage[url2] = 10 * 1024; |
| 154 |
| 155 score_provider()->SetScore(url1, 50); |
| 156 score_provider()->SetScore(url2, 25); |
| 157 |
| 158 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); |
| 159 |
| 160 // The policy should respect exceptions. |
| 161 std::set<GURL> exceptions; |
| 162 exceptions.insert(url2); |
| 163 EXPECT_EQ(url1, CalculateEvictionOriginWithExceptions(usage, exceptions)); |
| 164 } |
OLD | NEW |