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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 150 } |
151 | 151 |
152 class SiteEngagementEvictionPolicyTest : public testing::Test { | 152 class SiteEngagementEvictionPolicyTest : public testing::Test { |
153 public: | 153 public: |
154 SiteEngagementEvictionPolicyTest() | 154 SiteEngagementEvictionPolicyTest() |
155 : score_provider_(new TestSiteEngagementScoreProvider()), | 155 : score_provider_(new TestSiteEngagementScoreProvider()), |
156 storage_policy_(new content::MockSpecialStoragePolicy()) {} | 156 storage_policy_(new content::MockSpecialStoragePolicy()) {} |
157 | 157 |
158 ~SiteEngagementEvictionPolicyTest() override {} | 158 ~SiteEngagementEvictionPolicyTest() override {} |
159 | 159 |
160 GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage, | |
raymes
2015/09/22 07:16:10
nit: suggest renaming this to CalculatEvictionOrig
calamity
2015/09/23 01:55:21
Good call. Done.
| |
161 const std::set<GURL>& exceptions) { | |
162 return SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( | |
163 storage_policy_, score_provider_.get(), exceptions, usage, | |
164 kGlobalQuota); | |
165 } | |
166 | |
160 GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage) { | 167 GURL CalculateEvictionOrigin(const std::map<GURL, int64>& usage) { |
161 return SiteEngagementEvictionPolicy::CalculateEvictionOriginForTests( | 168 return CalculateEvictionOrigin(usage, std::set<GURL>()); |
162 storage_policy_, score_provider_.get(), usage, kGlobalQuota); | |
163 } | 169 } |
164 | 170 |
165 TestSiteEngagementScoreProvider* score_provider() { | 171 TestSiteEngagementScoreProvider* score_provider() { |
166 return score_provider_.get(); | 172 return score_provider_.get(); |
167 } | 173 } |
168 | 174 |
169 content::MockSpecialStoragePolicy* storage_policy() { | 175 content::MockSpecialStoragePolicy* storage_policy() { |
170 return storage_policy_.get(); | 176 return storage_policy_.get(); |
171 } | 177 } |
172 | 178 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); | 236 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); |
231 | 237 |
232 // Durable storage doesn't get evicted. | 238 // Durable storage doesn't get evicted. |
233 storage_policy()->AddDurable(url2); | 239 storage_policy()->AddDurable(url2); |
234 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); | 240 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); |
235 | 241 |
236 // Unlimited storage doesn't get evicted. | 242 // Unlimited storage doesn't get evicted. |
237 storage_policy()->AddUnlimited(url1); | 243 storage_policy()->AddUnlimited(url1); |
238 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); | 244 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); |
239 } | 245 } |
246 | |
247 TEST_F(SiteEngagementEvictionPolicyTest, Exceptions) { | |
248 GURL url1("http://www.google.com"); | |
249 GURL url2("http://www.example.com"); | |
250 | |
251 std::map<GURL, int64> usage; | |
252 usage[url1] = 10 * 1024; | |
253 usage[url2] = 10 * 1024; | |
254 | |
255 score_provider()->SetScore(url1, 50); | |
256 score_provider()->SetScore(url2, 25); | |
257 | |
258 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); | |
259 | |
260 // The policy should respect exceptions. | |
261 std::set<GURL> exceptions; | |
262 exceptions.insert(url2); | |
263 EXPECT_EQ(url1, CalculateEvictionOrigin(usage, exceptions)); | |
264 } | |
OLD | NEW |