OLD | NEW |
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/android/preferences/important_sites_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 64 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
65 content_settings::ResourceIdentifier(), setting); | 65 content_settings::ResourceIdentifier(), setting); |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 base::ScopedTempDir temp_dir_; | 69 base::ScopedTempDir temp_dir_; |
70 }; | 70 }; |
71 | 71 |
72 TEST_F(ImportantSitesUtilTest, TestNoImportantSites) { | 72 TEST_F(ImportantSitesUtilTest, TestNoImportantSites) { |
73 EXPECT_TRUE(ImportantSitesUtil::GetImportantRegisterableDomains( | 73 EXPECT_TRUE(ImportantSitesUtil::GetImportantRegisterableDomains( |
74 profile(), kNumImportantSites) | 74 profile(), kNumImportantSites, nullptr) |
75 .empty()); | 75 .empty()); |
76 } | 76 } |
77 | 77 |
78 TEST_F(ImportantSitesUtilTest, NotificationsThenEngagement) { | 78 TEST_F(ImportantSitesUtilTest, NotificationsThenEngagement) { |
79 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 79 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
80 ASSERT_TRUE(service); | 80 ASSERT_TRUE(service); |
81 | 81 |
82 GURL url1("http://www.google.com/"); | 82 GURL url1("http://www.google.com/"); |
83 GURL url2("https://www.google.com/"); | 83 GURL url2("https://www.google.com/"); |
84 GURL url3("https://drive.google.com/"); | 84 GURL url3("https://drive.google.com/"); |
85 GURL url4("https://www.chrome.com/"); | 85 GURL url4("https://www.chrome.com/"); |
86 GURL url5("https://www.example.com/"); | 86 GURL url5("https://www.example.com/"); |
87 GURL url6("https://youtube.com/"); | 87 GURL url6("https://youtube.com/"); |
88 GURL url7("https://foo.bar/"); | 88 GURL url7("https://foo.bar/"); |
89 | 89 |
90 service->ResetScoreForURL(url1, 5); | 90 service->ResetScoreForURL(url1, 5); |
91 service->ResetScoreForURL(url2, 2); // Below medium engagement (5). | 91 service->ResetScoreForURL(url2, 2); // Below medium engagement (5). |
92 service->ResetScoreForURL(url3, 7); | 92 service->ResetScoreForURL(url3, 7); |
93 service->ResetScoreForURL(url4, 8); | 93 service->ResetScoreForURL(url4, 8); |
94 service->ResetScoreForURL(url5, 9); | 94 service->ResetScoreForURL(url5, 9); |
95 service->ResetScoreForURL(url6, 1); // Below the medium engagement (5). | 95 service->ResetScoreForURL(url6, 1); // Below the medium engagement (5). |
96 service->ResetScoreForURL(url7, 11); | 96 service->ResetScoreForURL(url7, 11); |
97 | 97 |
98 // Here we should have: | 98 // Here we should have: |
99 // 1: removed domains below minimum engagement, | 99 // 1: removed domains below minimum engagement, |
100 // 2: combined the google.com entries, and | 100 // 2: combined the google.com entries, and |
101 // 3: sorted by the score. | 101 // 3: sorted by the score. |
102 std::vector<std::string> expected_sorted_domains = { | 102 std::vector<std::string> expected_sorted_domains = { |
103 "foo.bar", "example.com", "chrome.com", "google.com"}; | 103 "foo.bar", "example.com", "chrome.com", "google.com"}; |
| 104 std::vector<GURL> example_origins; |
104 EXPECT_THAT(ImportantSitesUtil::GetImportantRegisterableDomains( | 105 EXPECT_THAT(ImportantSitesUtil::GetImportantRegisterableDomains( |
105 profile(), kNumImportantSites), | 106 profile(), kNumImportantSites, &example_origins), |
106 ::testing::ElementsAreArray(expected_sorted_domains)); | 107 ::testing::ElementsAreArray(expected_sorted_domains)); |
| 108 std::vector<GURL> expected_sorted_origins = {url7, url5, url4, url3}; |
| 109 EXPECT_THAT(example_origins, |
| 110 ::testing::ElementsAreArray(expected_sorted_origins)); |
107 | 111 |
108 // Test that notifications get moved to the front. | 112 // Test that notifications get moved to the front. |
109 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 113 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
110 url6); | 114 url6); |
111 // BLOCK'ed sites don't count. We want to make sure we only bump sites that | 115 // BLOCK'ed sites don't count. We want to make sure we only bump sites that |
112 // were granted the permsion. | 116 // were granted the permsion. |
113 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK, | 117 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK, |
114 url1); | 118 url1); |
115 | 119 |
116 // Same as above, but the site with notifications should be at the front. | 120 // Same as above, but the site with notifications should be at the front. |
117 expected_sorted_domains = {"youtube.com", "foo.bar", "example.com", | 121 expected_sorted_domains = {"youtube.com", "foo.bar", "example.com", |
118 "chrome.com", "google.com"}; | 122 "chrome.com", "google.com"}; |
| 123 example_origins.clear(); |
119 EXPECT_THAT(ImportantSitesUtil::GetImportantRegisterableDomains( | 124 EXPECT_THAT(ImportantSitesUtil::GetImportantRegisterableDomains( |
120 profile(), kNumImportantSites), | 125 profile(), kNumImportantSites, &example_origins), |
| 126 ::testing::ElementsAreArray(expected_sorted_domains)); |
| 127 expected_sorted_origins = {url6, url7, url5, url4, url3}; |
| 128 EXPECT_THAT(example_origins, |
| 129 ::testing::ElementsAreArray(expected_sorted_origins)); |
| 130 } |
| 131 |
| 132 TEST_F(ImportantSitesUtilTest, TestNoOriginPopulation) { |
| 133 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 134 ASSERT_TRUE(service); |
| 135 |
| 136 GURL url1("http://www.google.com/"); |
| 137 |
| 138 service->ResetScoreForURL(url1, 5); |
| 139 |
| 140 std::vector<std::string> expected_sorted_domains = {"google.com"}; |
| 141 EXPECT_THAT(ImportantSitesUtil::GetImportantRegisterableDomains( |
| 142 profile(), kNumImportantSites, nullptr), |
121 ::testing::ElementsAreArray(expected_sorted_domains)); | 143 ::testing::ElementsAreArray(expected_sorted_domains)); |
122 } | 144 } |
OLD | NEW |