| 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/permissions/permission_decision_auto_blocker.h" | 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "base/test/scoped_feature_list.h" | 12 #include "base/test/scoped_feature_list.h" |
| 13 #include "base/test/simple_test_clock.h" | 13 #include "base/test/simple_test_clock.h" |
| 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 15 #include "chrome/browser/permissions/permission_uma_util.h" | 15 #include "chrome/browser/permissions/permission_uma_util.h" |
| 16 #include "chrome/browser/permissions/permission_util.h" | 16 #include "chrome/browser/permissions/permission_util.h" |
| 17 #include "chrome/common/chrome_features.h" | 17 #include "chrome/common/chrome_features.h" |
| 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 20 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 21 #include "components/safe_browsing_db/test_database_manager.h" | 21 #include "components/safe_browsing_db/test_database_manager.h" |
| 22 #include "content/public/browser/permission_type.h" | |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 bool FilterGoogle(const GURL& url) { | 25 bool FilterGoogle(const GURL& url) { |
| 27 return url == "https://www.google.com/"; | 26 return url == "https://www.google.com/"; |
| 28 } | 27 } |
| 29 | 28 |
| 30 bool FilterAll(const GURL& url) { | 29 bool FilterAll(const GURL& url) { |
| 31 return true; | 30 return true; |
| 32 } | 31 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 callback_was_run_ = false; | 99 callback_was_run_ = false; |
| 101 } | 100 } |
| 102 | 101 |
| 103 void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting( | 102 void SetSafeBrowsingDatabaseManagerAndTimeoutForTesting( |
| 104 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager, | 103 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager, |
| 105 int timeout) { | 104 int timeout) { |
| 106 autoblocker_->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 105 autoblocker_->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 107 timeout); | 106 timeout); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void UpdateEmbargoedStatus(content::PermissionType permission, | 109 void UpdateEmbargoedStatus(ContentSettingsType permission, const GURL& url) { |
| 111 const GURL& url) { | |
| 112 base::RunLoop run_loop; | 110 base::RunLoop run_loop; |
| 113 autoblocker_->UpdateEmbargoedStatus( | 111 autoblocker_->UpdateEmbargoedStatus( |
| 114 permission, url, nullptr, | 112 permission, url, nullptr, |
| 115 base::Bind(&PermissionDecisionAutoBlockerUnitTest::SetLastEmbargoStatus, | 113 base::Bind(&PermissionDecisionAutoBlockerUnitTest::SetLastEmbargoStatus, |
| 116 base::Unretained(this), run_loop.QuitClosure())); | 114 base::Unretained(this), run_loop.QuitClosure())); |
| 117 run_loop.Run(); | 115 run_loop.Run(); |
| 118 } | 116 } |
| 119 | 117 |
| 120 // Manually placing an (origin, permission) pair under embargo for | 118 // Manually placing an (origin, permission) pair under embargo for |
| 121 // blacklisting. To embargo on dismissals, RecordDismissAndEmbargo can be | 119 // blacklisting. To embargo on dismissals, RecordDismissAndEmbargo can be |
| 122 // used. | 120 // used. |
| 123 void PlaceUnderBlacklistEmbargo(content::PermissionType permission, | 121 void PlaceUnderBlacklistEmbargo(ContentSettingsType permission, |
| 124 const GURL& url) { | 122 const GURL& url) { |
| 125 autoblocker_->PlaceUnderEmbargo( | 123 autoblocker_->PlaceUnderEmbargo( |
| 126 permission, url, | 124 permission, url, |
| 127 PermissionDecisionAutoBlocker::kPermissionBlacklistEmbargoKey); | 125 PermissionDecisionAutoBlocker::kPermissionBlacklistEmbargoKey); |
| 128 } | 126 } |
| 129 | 127 |
| 130 PermissionDecisionAutoBlocker* autoblocker() { return autoblocker_; } | 128 PermissionDecisionAutoBlocker* autoblocker() { return autoblocker_; } |
| 131 | 129 |
| 132 void SetLastEmbargoStatus(base::Closure quit_closure, bool status) { | 130 void SetLastEmbargoStatus(base::Closure quit_closure, bool status) { |
| 133 callback_was_run_ = true; | 131 callback_was_run_ = true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 bool last_embargoed_status_; | 157 bool last_embargoed_status_; |
| 160 bool callback_was_run_; | 158 bool callback_was_run_; |
| 161 }; | 159 }; |
| 162 | 160 |
| 163 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { | 161 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
| 164 GURL url1("https://www.google.com"); | 162 GURL url1("https://www.google.com"); |
| 165 GURL url2("https://www.example.com"); | 163 GURL url2("https://www.example.com"); |
| 166 | 164 |
| 167 // Record some dismissals. | 165 // Record some dismissals. |
| 168 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 166 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 169 url1, content::PermissionType::GEOLOCATION)); | 167 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 170 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 168 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 171 url1, content::PermissionType::GEOLOCATION)); | 169 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 172 | 170 |
| 173 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 171 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 174 url1, content::PermissionType::GEOLOCATION)); | 172 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 175 EXPECT_EQ(2, autoblocker()->GetDismissCount( | 173 EXPECT_EQ(2, autoblocker()->GetDismissCount( |
| 176 url1, content::PermissionType::GEOLOCATION)); | 174 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 177 | 175 |
| 178 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 176 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 179 url1, content::PermissionType::GEOLOCATION)); | 177 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 180 EXPECT_EQ(3, autoblocker()->GetDismissCount( | 178 EXPECT_EQ(3, autoblocker()->GetDismissCount( |
| 181 url1, content::PermissionType::GEOLOCATION)); | 179 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 182 | 180 |
| 183 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 181 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 184 url2, content::PermissionType::GEOLOCATION)); | 182 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 185 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 183 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 186 url2, content::PermissionType::GEOLOCATION)); | 184 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 187 | 185 |
| 188 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 186 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 189 url1, content::PermissionType::NOTIFICATIONS)); | 187 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 190 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 188 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 191 url1, content::PermissionType::NOTIFICATIONS)); | 189 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 192 | 190 |
| 193 // Record some ignores. | 191 // Record some ignores. |
| 194 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 192 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 195 url1, content::PermissionType::MIDI_SYSEX)); | 193 url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 196 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 194 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 197 url1, content::PermissionType::DURABLE_STORAGE)); | 195 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 198 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 196 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 199 url2, content::PermissionType::GEOLOCATION)); | 197 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 200 EXPECT_EQ(2, autoblocker()->RecordIgnore( | 198 EXPECT_EQ(2, autoblocker()->RecordIgnore( |
| 201 url2, content::PermissionType::GEOLOCATION)); | 199 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 202 | 200 |
| 203 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); | 201 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); |
| 204 | 202 |
| 205 // Expect that url1's actions are gone, but url2's remain. | 203 // Expect that url1's actions are gone, but url2's remain. |
| 206 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 204 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 207 url1, content::PermissionType::GEOLOCATION)); | 205 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 208 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 206 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 209 url1, content::PermissionType::NOTIFICATIONS)); | 207 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 210 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 208 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 211 url1, content::PermissionType::MIDI_SYSEX)); | 209 url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 212 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 210 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 213 url1, content::PermissionType::DURABLE_STORAGE)); | 211 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 214 | 212 |
| 215 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 213 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 216 url2, content::PermissionType::GEOLOCATION)); | 214 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 217 EXPECT_EQ(2, autoblocker()->GetIgnoreCount( | 215 EXPECT_EQ(2, autoblocker()->GetIgnoreCount( |
| 218 url2, content::PermissionType::GEOLOCATION)); | 216 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 219 | 217 |
| 220 // Add some more actions. | 218 // Add some more actions. |
| 221 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 219 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 222 url1, content::PermissionType::GEOLOCATION)); | 220 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 223 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 221 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 224 url1, content::PermissionType::GEOLOCATION)); | 222 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 225 | 223 |
| 226 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 224 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 227 url1, content::PermissionType::NOTIFICATIONS)); | 225 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 228 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 226 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
| 229 url1, content::PermissionType::NOTIFICATIONS)); | 227 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 230 | 228 |
| 231 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 229 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 232 url2, content::PermissionType::GEOLOCATION)); | 230 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 233 EXPECT_EQ(2, autoblocker()->GetDismissCount( | 231 EXPECT_EQ(2, autoblocker()->GetDismissCount( |
| 234 url2, content::PermissionType::GEOLOCATION)); | 232 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 235 | 233 |
| 236 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 234 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 237 url1, content::PermissionType::GEOLOCATION)); | 235 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 238 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 236 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 239 url1, content::PermissionType::NOTIFICATIONS)); | 237 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 240 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 238 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 241 url1, content::PermissionType::DURABLE_STORAGE)); | 239 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 242 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 240 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
| 243 url2, content::PermissionType::MIDI_SYSEX)); | 241 url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 244 | 242 |
| 245 // Remove everything and expect that it's all gone. | 243 // Remove everything and expect that it's all gone. |
| 246 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); | 244 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); |
| 247 | 245 |
| 248 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 246 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 249 url1, content::PermissionType::GEOLOCATION)); | 247 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 250 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 248 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 251 url1, content::PermissionType::NOTIFICATIONS)); | 249 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 252 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 250 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 253 url2, content::PermissionType::GEOLOCATION)); | 251 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 254 | 252 |
| 255 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 253 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 256 url1, content::PermissionType::GEOLOCATION)); | 254 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 257 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 255 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 258 url1, content::PermissionType::NOTIFICATIONS)); | 256 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 259 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 257 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 260 url2, content::PermissionType::GEOLOCATION)); | 258 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 261 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 259 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 262 url2, content::PermissionType::DURABLE_STORAGE)); | 260 url2, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 263 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 261 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 264 url2, content::PermissionType::MIDI_SYSEX)); | 262 url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 265 } | 263 } |
| 266 | 264 |
| 267 // Test that an origin that has been blacklisted for a permission is embargoed. | 265 // Test that an origin that has been blacklisted for a permission is embargoed. |
| 268 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { | 266 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { |
| 269 GURL url("https://www.google.com"); | 267 GURL url("https://www.google.com"); |
| 270 base::HistogramTester histograms; | 268 base::HistogramTester histograms; |
| 271 | 269 |
| 272 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 270 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 273 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 271 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
| 274 true /* enabled */); | 272 true /* enabled */); |
| 275 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 273 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
| 276 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 274 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 277 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 275 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 278 2000 /* timeout in ms */); | 276 2000 /* timeout in ms */); |
| 279 | 277 |
| 280 UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); | 278 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 281 EXPECT_TRUE(callback_was_run()); | 279 EXPECT_TRUE(callback_was_run()); |
| 282 EXPECT_TRUE(last_embargoed_status()); | 280 EXPECT_TRUE(last_embargoed_status()); |
| 283 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 281 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 284 SafeBrowsingResponse::BLACKLISTED, 1); | 282 SafeBrowsingResponse::BLACKLISTED, 1); |
| 285 histograms.ExpectTotalCount( | 283 histograms.ExpectTotalCount( |
| 286 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 284 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
| 287 } | 285 } |
| 288 | 286 |
| 289 // Test that an origin that is blacklisted for a permission will not be placed | 287 // Test that an origin that is blacklisted for a permission will not be placed |
| 290 // under embargoed for another. | 288 // under embargoed for another. |
| 291 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestRequestNotBlacklisted) { | 289 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestRequestNotBlacklisted) { |
| 292 GURL url("https://www.google.com"); | 290 GURL url("https://www.google.com"); |
| 293 clock()->SetNow(base::Time::Now()); | 291 clock()->SetNow(base::Time::Now()); |
| 294 base::HistogramTester histograms; | 292 base::HistogramTester histograms; |
| 295 | 293 |
| 296 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 294 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 297 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 295 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
| 298 true /* enabled */); | 296 true /* enabled */); |
| 299 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 297 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
| 300 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 298 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 301 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 299 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 302 0 /* timeout in ms */); | 300 0 /* timeout in ms */); |
| 303 | 301 |
| 304 UpdateEmbargoedStatus(content::PermissionType::NOTIFICATIONS, url); | 302 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
| 305 EXPECT_FALSE(last_embargoed_status()); | 303 EXPECT_FALSE(last_embargoed_status()); |
| 306 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 304 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 307 SafeBrowsingResponse::NOT_BLACKLISTED, 1); | 305 SafeBrowsingResponse::NOT_BLACKLISTED, 1); |
| 308 histograms.ExpectTotalCount( | 306 histograms.ExpectTotalCount( |
| 309 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 307 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
| 310 } | 308 } |
| 311 | 309 |
| 312 // Check that IsUnderEmbargo returns the correct value when the embargo is set | 310 // Check that IsUnderEmbargo returns the correct value when the embargo is set |
| 313 // and expires. | 311 // and expires. |
| 314 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { | 312 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
| 315 GURL url("https://www.google.com"); | 313 GURL url("https://www.google.com"); |
| 316 clock()->SetNow(base::Time::Now()); | 314 clock()->SetNow(base::Time::Now()); |
| 317 | 315 |
| 318 PlaceUnderBlacklistEmbargo(content::PermissionType::GEOLOCATION, url); | 316 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 319 EXPECT_TRUE( | 317 EXPECT_TRUE( |
| 320 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 318 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 321 | 319 |
| 322 // Check that the origin is not under embargo for a different permission. | 320 // Check that the origin is not under embargo for a different permission. |
| 323 EXPECT_FALSE(autoblocker()->IsUnderEmbargo( | 321 EXPECT_FALSE( |
| 324 content::PermissionType::NOTIFICATIONS, url)); | 322 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url)); |
| 325 | 323 |
| 326 // Confirm embargo status during the embargo period. | 324 // Confirm embargo status during the embargo period. |
| 327 clock()->Advance(base::TimeDelta::FromDays(5)); | 325 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 328 EXPECT_TRUE( | 326 EXPECT_TRUE( |
| 329 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 327 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 330 | 328 |
| 331 // Check embargo is lifted on expiry day. A small offset after the exact | 329 // Check embargo is lifted on expiry day. A small offset after the exact |
| 332 // embargo expiration date has been added to account for any precision errors | 330 // embargo expiration date has been added to account for any precision errors |
| 333 // when removing the date stored as a double from the permission dictionary. | 331 // when removing the date stored as a double from the permission dictionary. |
| 334 clock()->Advance(base::TimeDelta::FromHours(3 * 24 + 1)); | 332 clock()->Advance(base::TimeDelta::FromHours(3 * 24 + 1)); |
| 335 EXPECT_FALSE( | 333 EXPECT_FALSE( |
| 336 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 334 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 337 | 335 |
| 338 // Check embargo is lifted well after the expiry day. | 336 // Check embargo is lifted well after the expiry day. |
| 339 clock()->Advance(base::TimeDelta::FromDays(1)); | 337 clock()->Advance(base::TimeDelta::FromDays(1)); |
| 340 EXPECT_FALSE( | 338 EXPECT_FALSE( |
| 341 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 339 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 342 | 340 |
| 343 // Place under embargo again and verify the embargo status. | 341 // Place under embargo again and verify the embargo status. |
| 344 PlaceUnderBlacklistEmbargo(content::PermissionType::NOTIFICATIONS, url); | 342 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
| 345 clock()->Advance(base::TimeDelta::FromDays(1)); | 343 clock()->Advance(base::TimeDelta::FromDays(1)); |
| 346 EXPECT_TRUE(autoblocker()->IsUnderEmbargo( | 344 EXPECT_TRUE( |
| 347 content::PermissionType::NOTIFICATIONS, url)); | 345 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url)); |
| 348 } | 346 } |
| 349 | 347 |
| 350 // Tests the alternating pattern of the block on multiple dismiss behaviour. On | 348 // Tests the alternating pattern of the block on multiple dismiss behaviour. On |
| 351 // N dismissals, the origin to be embargoed for the requested permission and | 349 // N dismissals, the origin to be embargoed for the requested permission and |
| 352 // automatically blocked. Each time the embargo is lifted, the site gets another | 350 // automatically blocked. Each time the embargo is lifted, the site gets another |
| 353 // chance to request the permission, but if it is again dismissed it is placed | 351 // chance to request the permission, but if it is again dismissed it is placed |
| 354 // under embargo again and its permission requests blocked. | 352 // under embargo again and its permission requests blocked. |
| 355 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { | 353 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { |
| 356 GURL url("https://www.google.com"); | 354 GURL url("https://www.google.com"); |
| 357 clock()->SetNow(base::Time::Now()); | 355 clock()->SetNow(base::Time::Now()); |
| 358 base::HistogramTester histograms; | 356 base::HistogramTester histograms; |
| 359 | 357 |
| 360 // Record some dismisses. | 358 // Record some dismisses. |
| 361 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 359 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 362 url, content::PermissionType::GEOLOCATION)); | 360 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 363 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 361 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 364 url, content::PermissionType::GEOLOCATION)); | 362 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 365 | 363 |
| 366 // A request with < 3 prior dismisses should not be automatically blocked. | 364 // A request with < 3 prior dismisses should not be automatically blocked. |
| 367 EXPECT_FALSE( | 365 EXPECT_FALSE( |
| 368 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 366 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 369 | 367 |
| 370 // After the 3rd dismiss subsequent permission requests should be autoblocked. | 368 // After the 3rd dismiss subsequent permission requests should be autoblocked. |
| 371 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 369 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 372 url, content::PermissionType::GEOLOCATION)); | 370 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 373 EXPECT_TRUE( | 371 EXPECT_TRUE( |
| 374 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 372 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 375 | 373 |
| 376 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 374 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 377 0); | 375 0); |
| 378 histograms.ExpectTotalCount( | 376 histograms.ExpectTotalCount( |
| 379 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 377 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 380 // Accelerate time forward, check that the embargo status is lifted and the | 378 // Accelerate time forward, check that the embargo status is lifted and the |
| 381 // request won't be automatically blocked. | 379 // request won't be automatically blocked. |
| 382 clock()->Advance(base::TimeDelta::FromDays(8)); | 380 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 383 EXPECT_FALSE( | 381 EXPECT_FALSE( |
| 384 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 382 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 385 | 383 |
| 386 // Record another dismiss, subsequent requests should be autoblocked again. | 384 // Record another dismiss, subsequent requests should be autoblocked again. |
| 387 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 385 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 388 url, content::PermissionType::GEOLOCATION)); | 386 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 389 EXPECT_TRUE( | 387 EXPECT_TRUE( |
| 390 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 388 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 391 | 389 |
| 392 // Accelerate time again, check embargo is lifted and another permission | 390 // Accelerate time again, check embargo is lifted and another permission |
| 393 // request is let through. | 391 // request is let through. |
| 394 clock()->Advance(base::TimeDelta::FromDays(8)); | 392 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 395 EXPECT_FALSE( | 393 EXPECT_FALSE( |
| 396 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 394 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 397 | 395 |
| 398 // Record another dismiss, subsequent requests should be autoblocked again. | 396 // Record another dismiss, subsequent requests should be autoblocked again. |
| 399 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 397 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 400 url, content::PermissionType::GEOLOCATION)); | 398 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 401 EXPECT_TRUE( | 399 EXPECT_TRUE( |
| 402 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 400 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 403 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 401 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 404 0); | 402 0); |
| 405 histograms.ExpectTotalCount( | 403 histograms.ExpectTotalCount( |
| 406 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 404 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 407 } | 405 } |
| 408 | 406 |
| 409 // Test the logic for a combination of blacklisting and dismissal embargo. | 407 // Test the logic for a combination of blacklisting and dismissal embargo. |
| 410 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { | 408 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { |
| 411 GURL url("https://www.google.com"); | 409 GURL url("https://www.google.com"); |
| 412 clock()->SetNow(base::Time::Now()); | 410 clock()->SetNow(base::Time::Now()); |
| 413 | 411 |
| 414 // Place under blacklist embargo and check the status. | 412 // Place under blacklist embargo and check the status. |
| 415 PlaceUnderBlacklistEmbargo(content::PermissionType::GEOLOCATION, url); | 413 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 416 clock()->Advance(base::TimeDelta::FromDays(5)); | 414 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 417 EXPECT_TRUE( | 415 EXPECT_TRUE( |
| 418 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 416 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 419 | 417 |
| 420 // Record dismisses to place it under dismissal embargo. | 418 // Record dismisses to place it under dismissal embargo. |
| 421 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 419 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 422 url, content::PermissionType::GEOLOCATION)); | 420 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 423 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 421 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 424 url, content::PermissionType::GEOLOCATION)); | 422 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 425 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 423 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 426 url, content::PermissionType::GEOLOCATION)); | 424 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 427 | 425 |
| 428 // Accelerate time to a point where the blacklist embargo should be expired | 426 // Accelerate time to a point where the blacklist embargo should be expired |
| 429 // and check that dismissal embargo is still set. | 427 // and check that dismissal embargo is still set. |
| 430 clock()->Advance(base::TimeDelta::FromDays(3)); | 428 clock()->Advance(base::TimeDelta::FromDays(3)); |
| 431 EXPECT_TRUE( | 429 EXPECT_TRUE( |
| 432 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 430 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 433 } | 431 } |
| 434 | 432 |
| 435 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { | 433 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
| 436 GURL url("https://www.google.com"); | 434 GURL url("https://www.google.com"); |
| 437 clock()->SetNow(base::Time::Now()); | 435 clock()->SetNow(base::Time::Now()); |
| 438 base::HistogramTester histograms; | 436 base::HistogramTester histograms; |
| 439 | 437 |
| 440 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 438 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 441 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, | 439 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, |
| 442 true /* enabled */); | 440 true /* enabled */); |
| 443 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 441 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
| 444 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 442 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 445 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 443 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 446 0 /* timeout in ms */); | 444 0 /* timeout in ms */); |
| 447 | 445 |
| 448 UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); | 446 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 449 EXPECT_TRUE(callback_was_run()); | 447 EXPECT_TRUE(callback_was_run()); |
| 450 EXPECT_FALSE(last_embargoed_status()); | 448 EXPECT_FALSE(last_embargoed_status()); |
| 451 EXPECT_FALSE( | 449 EXPECT_FALSE( |
| 452 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 450 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 453 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 451 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 454 SafeBrowsingResponse::TIMEOUT, 1); | 452 SafeBrowsingResponse::TIMEOUT, 1); |
| 455 histograms.ExpectTotalCount( | 453 histograms.ExpectTotalCount( |
| 456 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 454 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
| 457 db_manager->SetPerformCallback(true); | 455 db_manager->SetPerformCallback(true); |
| 458 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 456 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 459 2000 /* timeout in ms */); | 457 2000 /* timeout in ms */); |
| 460 | 458 |
| 461 clock()->Advance(base::TimeDelta::FromDays(1)); | 459 clock()->Advance(base::TimeDelta::FromDays(1)); |
| 462 UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); | 460 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 463 EXPECT_TRUE(callback_was_run()); | 461 EXPECT_TRUE(callback_was_run()); |
| 464 EXPECT_TRUE(last_embargoed_status()); | 462 EXPECT_TRUE(last_embargoed_status()); |
| 465 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 463 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 466 2); | 464 2); |
| 467 histograms.ExpectTotalCount( | 465 histograms.ExpectTotalCount( |
| 468 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 2); | 466 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 2); |
| 469 histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 467 histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 470 SafeBrowsingResponse::BLACKLISTED, 1); | 468 SafeBrowsingResponse::BLACKLISTED, 1); |
| 471 clock()->Advance(base::TimeDelta::FromDays(1)); | 469 clock()->Advance(base::TimeDelta::FromDays(1)); |
| 472 EXPECT_TRUE( | 470 EXPECT_TRUE( |
| 473 autoblocker()->IsUnderEmbargo(content::PermissionType::GEOLOCATION, url)); | 471 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); |
| 474 } | 472 } |
| 475 | 473 |
| 476 // TODO(raymes): See crbug.com/681709. Remove after M60. | 474 // TODO(raymes): See crbug.com/681709. Remove after M60. |
| 477 TEST_F(PermissionDecisionAutoBlockerUnitTest, | 475 TEST_F(PermissionDecisionAutoBlockerUnitTest, |
| 478 MigrateNoDecisionCountToPermissionAutoBlockerData) { | 476 MigrateNoDecisionCountToPermissionAutoBlockerData) { |
| 479 GURL url("https://www.google.com"); | 477 GURL url("https://www.google.com"); |
| 480 auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); | 478 auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); |
| 481 | 479 |
| 482 // Write to the old content setting. | 480 // Write to the old content setting. |
| 483 base::DictionaryValue permissions_dict; | 481 base::DictionaryValue permissions_dict; |
| 484 permissions_dict.SetInteger(GetDismissKey(), 100); | 482 permissions_dict.SetInteger(GetDismissKey(), 100); |
| 485 permissions_dict.SetInteger(GetIgnoreKey(), 50); | 483 permissions_dict.SetInteger(GetIgnoreKey(), 50); |
| 486 | 484 |
| 487 base::DictionaryValue origin_dict; | 485 base::DictionaryValue origin_dict; |
| 488 origin_dict.Set( | 486 origin_dict.Set( |
| 489 PermissionUtil::GetPermissionString(content::PermissionType::GEOLOCATION), | 487 PermissionUtil::GetPermissionString(CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 490 permissions_dict.CreateDeepCopy()); | 488 permissions_dict.CreateDeepCopy()); |
| 491 map->SetWebsiteSettingDefaultScope( | 489 map->SetWebsiteSettingDefaultScope( |
| 492 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, | 490 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, |
| 493 std::string(), origin_dict.CreateDeepCopy()); | 491 std::string(), origin_dict.CreateDeepCopy()); |
| 494 | 492 |
| 495 // Nothing should be migrated yet, so the current values should be 0. | 493 // Nothing should be migrated yet, so the current values should be 0. |
| 496 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 494 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
| 497 url, content::PermissionType::GEOLOCATION)); | 495 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 498 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 496 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
| 499 url, content::PermissionType::GEOLOCATION)); | 497 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 500 | 498 |
| 501 // Trigger pref migration which happens at the creation of the | 499 // Trigger pref migration which happens at the creation of the |
| 502 // HostContentSettingsMap. | 500 // HostContentSettingsMap. |
| 503 { | 501 { |
| 504 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( | 502 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( |
| 505 profile()->GetPrefs(), false /* is_incognito_profile */, | 503 profile()->GetPrefs(), false /* is_incognito_profile */, |
| 506 false /* is_guest_profile */)); | 504 false /* is_guest_profile */)); |
| 507 temp_map->ShutdownOnUIThread(); | 505 temp_map->ShutdownOnUIThread(); |
| 508 } | 506 } |
| 509 | 507 |
| 510 // The values should now be migrated. | 508 // The values should now be migrated. |
| 511 EXPECT_EQ(100, autoblocker()->GetDismissCount( | 509 EXPECT_EQ(100, autoblocker()->GetDismissCount( |
| 512 url, content::PermissionType::GEOLOCATION)); | 510 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 513 EXPECT_EQ(50, autoblocker()->GetIgnoreCount( | 511 EXPECT_EQ(50, autoblocker()->GetIgnoreCount( |
| 514 url, content::PermissionType::GEOLOCATION)); | 512 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 515 | 513 |
| 516 // The old pref should be deleted. | 514 // The old pref should be deleted. |
| 517 std::unique_ptr<base::DictionaryValue> old_dict = | 515 std::unique_ptr<base::DictionaryValue> old_dict = |
| 518 base::DictionaryValue::From(map->GetWebsiteSetting( | 516 base::DictionaryValue::From(map->GetWebsiteSetting( |
| 519 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, | 517 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, |
| 520 std::string(), nullptr)); | 518 std::string(), nullptr)); |
| 521 EXPECT_EQ(nullptr, old_dict); | 519 EXPECT_EQ(nullptr, old_dict); |
| 522 | 520 |
| 523 // Write to the old content setting again, but with different numbers. | 521 // Write to the old content setting again, but with different numbers. |
| 524 permissions_dict.SetInteger(GetDismissKey(), 99); | 522 permissions_dict.SetInteger(GetDismissKey(), 99); |
| 525 permissions_dict.SetInteger(GetIgnoreKey(), 99); | 523 permissions_dict.SetInteger(GetIgnoreKey(), 99); |
| 526 | 524 |
| 527 origin_dict.Set( | 525 origin_dict.Set( |
| 528 PermissionUtil::GetPermissionString(content::PermissionType::GEOLOCATION), | 526 PermissionUtil::GetPermissionString(CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 529 permissions_dict.CreateDeepCopy()); | 527 permissions_dict.CreateDeepCopy()); |
| 530 map->SetWebsiteSettingDefaultScope( | 528 map->SetWebsiteSettingDefaultScope( |
| 531 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, | 529 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, |
| 532 std::string(), origin_dict.CreateDeepCopy()); | 530 std::string(), origin_dict.CreateDeepCopy()); |
| 533 | 531 |
| 534 // Ensure that migrating again does nothing. | 532 // Ensure that migrating again does nothing. |
| 535 { | 533 { |
| 536 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( | 534 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( |
| 537 profile()->GetPrefs(), false /* is_incognito_profile */, | 535 profile()->GetPrefs(), false /* is_incognito_profile */, |
| 538 false /* is_guest_profile */)); | 536 false /* is_guest_profile */)); |
| 539 temp_map->ShutdownOnUIThread(); | 537 temp_map->ShutdownOnUIThread(); |
| 540 } | 538 } |
| 541 | 539 |
| 542 EXPECT_EQ(100, autoblocker()->GetDismissCount( | 540 EXPECT_EQ(100, autoblocker()->GetDismissCount( |
| 543 url, content::PermissionType::GEOLOCATION)); | 541 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 544 EXPECT_EQ(50, autoblocker()->GetIgnoreCount( | 542 EXPECT_EQ(50, autoblocker()->GetIgnoreCount( |
| 545 url, content::PermissionType::GEOLOCATION)); | 543 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 546 } | 544 } |
| 547 | 545 |
| 548 // Test that a blacklisted permission should not be autoblocked if the database | 546 // Test that a blacklisted permission should not be autoblocked if the database |
| 549 // manager is disabled. | 547 // manager is disabled. |
| 550 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDisabledDatabaseManager) { | 548 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDisabledDatabaseManager) { |
| 551 GURL url("https://www.google.com"); | 549 GURL url("https://www.google.com"); |
| 552 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 550 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 553 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 551 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
| 554 false /* enabled */); | 552 false /* enabled */); |
| 555 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 553 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
| 556 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 554 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 557 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 555 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 558 2000 /* timeout in ms */); | 556 2000 /* timeout in ms */); |
| 559 UpdateEmbargoedStatus(content::PermissionType::GEOLOCATION, url); | 557 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 560 EXPECT_TRUE(callback_was_run()); | 558 EXPECT_TRUE(callback_was_run()); |
| 561 EXPECT_FALSE(last_embargoed_status()); | 559 EXPECT_FALSE(last_embargoed_status()); |
| 562 } | 560 } |
| 563 | 561 |
| 564 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingResponse) { | 562 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingResponse) { |
| 565 GURL url("https://www.google.com"); | 563 GURL url("https://www.google.com"); |
| 566 clock()->SetNow(base::Time::Now()); | 564 clock()->SetNow(base::Time::Now()); |
| 567 base::HistogramTester histograms; | 565 base::HistogramTester histograms; |
| 568 | 566 |
| 569 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 567 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 570 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 568 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
| 571 true /* enabled */); | 569 true /* enabled */); |
| 572 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 570 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
| 573 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 571 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 574 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 572 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 575 0 /* timeout in ms */); | 573 0 /* timeout in ms */); |
| 576 | 574 |
| 577 UpdateEmbargoedStatus(content::PermissionType::NOTIFICATIONS, url); | 575 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
| 578 EXPECT_FALSE(last_embargoed_status()); | 576 EXPECT_FALSE(last_embargoed_status()); |
| 579 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 577 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 580 SafeBrowsingResponse::NOT_BLACKLISTED, 1); | 578 SafeBrowsingResponse::NOT_BLACKLISTED, 1); |
| 581 } | 579 } |
| OLD | NEW |