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 "chrome/browser/engagement/site_engagement_eviction_policy.h" | 5 #include "chrome/browser/engagement/site_engagement_eviction_policy.h" |
6 #include "chrome/browser/engagement/site_engagement_service.h" | 6 #include "chrome/browser/engagement/site_engagement_service.h" |
7 #include "content/public/test/mock_special_storage_policy.h" | 7 #include "content/public/test/mock_special_storage_policy.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 const int64 kGlobalQuota = 25 * 1024; | 12 const int64 kGlobalQuota = 25 * 1024; |
13 | 13 |
14 } // namespace | 14 } // namespace |
15 | 15 |
16 class TestSiteEngagementScoreProvider : public SiteEngagementScoreProvider { | 16 class TestSiteEngagementScoreProvider : public SiteEngagementScoreProvider { |
17 public: | 17 public: |
18 TestSiteEngagementScoreProvider() {} | 18 TestSiteEngagementScoreProvider() {} |
19 | 19 |
20 virtual ~TestSiteEngagementScoreProvider() {} | 20 virtual ~TestSiteEngagementScoreProvider() {} |
21 | 21 |
22 int GetScore(const GURL& url) override { return engagement_score_map_[url]; } | 22 double GetScore(const GURL& url) override { |
| 23 return engagement_score_map_[url]; |
| 24 } |
23 | 25 |
24 int GetTotalEngagementPoints() override { | 26 double GetTotalEngagementPoints() override { |
25 int total = 0; | 27 double total = 0; |
26 for (const auto& site : engagement_score_map_) | 28 for (const auto& site : engagement_score_map_) |
27 total += site.second; | 29 total += site.second; |
28 return total; | 30 return total; |
29 } | 31 } |
30 | 32 |
31 void SetScore(const GURL& origin, int score) { | 33 void SetScore(const GURL& origin, double score) { |
32 engagement_score_map_[origin] = score; | 34 engagement_score_map_[origin] = score; |
33 } | 35 } |
34 | 36 |
35 private: | 37 private: |
36 std::map<GURL, int> engagement_score_map_; | 38 std::map<GURL, double> engagement_score_map_; |
37 | 39 |
38 DISALLOW_COPY_AND_ASSIGN(TestSiteEngagementScoreProvider); | 40 DISALLOW_COPY_AND_ASSIGN(TestSiteEngagementScoreProvider); |
39 }; | 41 }; |
40 | 42 |
41 class SiteEngagementEvictionPolicyTest : public testing::Test { | 43 class SiteEngagementEvictionPolicyTest : public testing::Test { |
42 public: | 44 public: |
43 SiteEngagementEvictionPolicyTest() | 45 SiteEngagementEvictionPolicyTest() |
44 : score_provider_(new TestSiteEngagementScoreProvider()), | 46 : score_provider_(new TestSiteEngagementScoreProvider()), |
45 storage_policy_(new content::MockSpecialStoragePolicy()) {} | 47 storage_policy_(new content::MockSpecialStoragePolicy()) {} |
46 | 48 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); | 121 EXPECT_EQ(url2, CalculateEvictionOrigin(usage)); |
120 | 122 |
121 // Durable storage doesn't get evicted. | 123 // Durable storage doesn't get evicted. |
122 storage_policy()->AddDurable(url2); | 124 storage_policy()->AddDurable(url2); |
123 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); | 125 EXPECT_EQ(url1, CalculateEvictionOrigin(usage)); |
124 | 126 |
125 // Unlimited storage doesn't get evicted. | 127 // Unlimited storage doesn't get evicted. |
126 storage_policy()->AddUnlimited(url1); | 128 storage_policy()->AddUnlimited(url1); |
127 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); | 129 EXPECT_EQ(GURL(), CalculateEvictionOrigin(usage)); |
128 } | 130 } |
OLD | NEW |