Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/task/cancelable_task_tracker.h" | 24 #include "base/task/cancelable_task_tracker.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 31 #include "chrome/browser/browsing_data/origin_filter_builder.h" | |
| 31 #include "chrome/browser/domain_reliability/service_factory.h" | 32 #include "chrome/browser/domain_reliability/service_factory.h" |
| 32 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 33 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 33 #include "chrome/browser/favicon/favicon_service_factory.h" | 34 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 34 #include "chrome/browser/history/history_service_factory.h" | 35 #include "chrome/browser/history/history_service_factory.h" |
| 35 #include "chrome/browser/password_manager/password_store_factory.h" | 36 #include "chrome/browser/password_manager/password_store_factory.h" |
| 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 37 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/test/base/testing_browser_process.h" | 39 #include "chrome/test/base/testing_browser_process.h" |
| 39 #include "chrome/test/base/testing_profile.h" | 40 #include "chrome/test/base/testing_profile.h" |
| 40 #include "components/autofill/core/browser/autofill_profile.h" | 41 #include "components/autofill/core/browser/autofill_profile.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 257 |
| 257 StoragePartitionRemovalData storage_partition_removal_data_; | 258 StoragePartitionRemovalData storage_partition_removal_data_; |
| 258 | 259 |
| 259 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | 260 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 // Custom matcher to verify is-same-origin relationship to given reference | 263 // Custom matcher to verify is-same-origin relationship to given reference |
| 263 // origin. | 264 // origin. |
| 264 // (We cannot use equality-based matching because operator== is not defined for | 265 // (We cannot use equality-based matching because operator== is not defined for |
| 265 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.) | 266 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.) |
| 267 // TODO(msramek): This is only used for backends that currently response. | |
|
Timo Reimann
2016/02/05 19:01:24
nit-pick: Sentence incomplete/grammar? I'm not ent
msramek
2016/02/10 14:30:36
Done. Sorry, I must have been interrupted while wr
| |
| 266 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { | 268 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { |
| 267 public: | 269 public: |
| 268 explicit SameOriginMatcher(const url::Origin& reference) | 270 explicit SameOriginMatcher(const url::Origin& reference) |
| 269 : reference_(reference) {} | 271 : reference_(reference) {} |
| 270 | 272 |
| 271 virtual bool MatchAndExplain(const url::Origin& origin, | 273 virtual bool MatchAndExplain(const url::Origin& origin, |
| 272 MatchResultListener* listener) const { | 274 MatchResultListener* listener) const { |
| 273 return reference_.IsSameOriginWith(origin); | 275 return reference_.IsSameOriginWith(origin); |
| 274 } | 276 } |
| 275 | 277 |
| 276 virtual void DescribeTo(::std::ostream* os) const { | 278 virtual void DescribeTo(::std::ostream* os) const { |
| 277 *os << "is same origin with " << reference_; | 279 *os << "is same origin with " << reference_; |
| 278 } | 280 } |
| 279 | 281 |
| 280 virtual void DescribeNegationTo(::std::ostream* os) const { | 282 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 281 *os << "is not same origin with " << reference_; | 283 *os << "is not same origin with " << reference_; |
| 282 } | 284 } |
| 283 | 285 |
| 284 private: | 286 private: |
| 285 const url::Origin& reference_; | 287 const url::Origin& reference_; |
| 286 }; | 288 }; |
| 287 | 289 |
| 288 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { | 290 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { |
| 289 return MakeMatcher(new SameOriginMatcher(reference)); | 291 return MakeMatcher(new SameOriginMatcher(reference)); |
| 290 } | 292 } |
| 291 | 293 |
| 294 // Custom matcher to test the equivalence of two URL filters. Since those are | |
| 295 // blackbox predicates, we can only approximate the equivalence by testing | |
| 296 // whether the filter give the same answer for several URLs. This is currently | |
| 297 // good enough for our testing purposes, to distinguish whitelists | |
| 298 // and blacklists, empty and non-empty filters and such. | |
| 299 // TODO(msramek): BrowsingDataRemover and some of its backends support URL | |
| 300 // filters, but its constructor currently only takes a single URL and constructs | |
| 301 // its own OriginFilterBuilder. If an instance of OriginFilter was passed | |
|
Timo Reimann
2016/02/05 19:01:24
We don't have OriginFilter as a class anymore, do
msramek
2016/02/10 14:30:36
Done. Nope, this is supposed to refer to url filte
| |
| 302 // to BrowsingDataRemover (what should evenetually be the case), we can | |
|
Timo Reimann
2016/02/05 19:01:24
Nit-pick: Typo (evenetually -> eventually).
msramek
2016/02/10 14:30:36
Done.
| |
| 303 // use the same instance in the test as well, and thus simply test | |
| 304 // base::Callback::Equals() in this matcher. | |
| 305 class ProbablySameFilterMatcher | |
| 306 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { | |
| 307 public: | |
| 308 explicit ProbablySameFilterMatcher( | |
| 309 const base::Callback<bool(const GURL&)>& filter) | |
| 310 : to_match_(filter) { | |
| 311 } | |
| 312 | |
| 313 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, | |
| 314 MatchResultListener* listener) const { | |
| 315 const GURL urls_to_test_[] = | |
| 316 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; | |
| 317 for (GURL url : urls_to_test_) { | |
| 318 if (filter.Run(url) != to_match_.Run(url)) { | |
| 319 *listener << "The filters differ on the URL " << url; | |
| 320 return false; | |
| 321 } | |
| 322 } | |
| 323 return true; | |
| 324 } | |
| 325 | |
| 326 virtual void DescribeTo(::std::ostream* os) const { | |
| 327 *os << "is probably the same url filter as " << &to_match_; | |
| 328 } | |
| 329 | |
| 330 virtual void DescribeNegationTo(::std::ostream* os) const { | |
| 331 *os << "is definitely NOT the same url filter as " << &to_match_; | |
| 332 } | |
| 333 | |
| 334 private: | |
| 335 const base::Callback<bool(const GURL&)>& to_match_; | |
| 336 }; | |
| 337 | |
| 338 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( | |
| 339 const base::Callback<bool(const GURL&)>& filter) { | |
| 340 return MakeMatcher(new ProbablySameFilterMatcher(filter)); | |
| 341 } | |
| 342 | |
| 292 } // namespace | 343 } // namespace |
| 293 | 344 |
| 294 // Testers ------------------------------------------------------------------- | 345 // Testers ------------------------------------------------------------------- |
| 295 | 346 |
| 296 class RemoveCookieTester { | 347 class RemoveCookieTester { |
| 297 public: | 348 public: |
| 298 RemoveCookieTester() {} | 349 RemoveCookieTester() {} |
| 299 | 350 |
| 300 // Returns true, if the given cookie exists in the cookie store. | 351 // Returns true, if the given cookie exists in the cookie store. |
| 301 bool ContainsCookie() { | 352 bool ContainsCookie() { |
| (...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2163 // monitor case again. | 2214 // monitor case again. |
| 2164 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | 2215 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
| 2165 BlockUntilBrowsingDataRemoved( | 2216 BlockUntilBrowsingDataRemoved( |
| 2166 BrowsingDataRemover::EVERYTHING, | 2217 BrowsingDataRemover::EVERYTHING, |
| 2167 BrowsingDataRemover::REMOVE_HISTORY | | 2218 BrowsingDataRemover::REMOVE_HISTORY | |
| 2168 BrowsingDataRemover::REMOVE_COOKIES, false); | 2219 BrowsingDataRemover::REMOVE_COOKIES, false); |
| 2169 } | 2220 } |
| 2170 | 2221 |
| 2171 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { | 2222 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) { |
| 2172 RemoveDownloadsTester tester(GetProfile()); | 2223 RemoveDownloadsTester tester(GetProfile()); |
| 2224 scoped_ptr<OriginFilterBuilder> builder = | |
| 2225 OriginFilterBuilder::Empty(); | |
| 2173 | 2226 |
| 2174 EXPECT_CALL(*tester.download_manager(), RemoveDownloadsBetween(_, _)); | 2227 EXPECT_CALL( |
| 2228 *tester.download_manager(), | |
| 2229 RemoveDownloadsByOriginAndTime( | |
| 2230 ProbablySameFilter(builder->GetSameOriginFilter()), _, _)); | |
| 2175 | 2231 |
| 2176 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 2232 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2177 BrowsingDataRemover::REMOVE_DOWNLOADS, false); | 2233 BrowsingDataRemover::REMOVE_DOWNLOADS, false); |
| 2178 } | 2234 } |
| 2179 | 2235 |
| 2180 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { | 2236 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { |
| 2181 RemoveDownloadsTester tester(GetProfile()); | 2237 RemoveDownloadsTester tester(GetProfile()); |
| 2182 const url::Origin expectedOrigin(kOrigin1); | 2238 std::vector<url::Origin> whitelist; |
| 2239 whitelist.push_back(url::Origin(kOrigin1)); | |
| 2240 scoped_ptr<OriginFilterBuilder> builder = | |
| 2241 OriginFilterBuilder::AsWhitelist(whitelist); | |
| 2183 | 2242 |
| 2184 EXPECT_CALL(*tester.download_manager(), | 2243 EXPECT_CALL( |
| 2185 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _)); | 2244 *tester.download_manager(), |
| 2245 RemoveDownloadsByOriginAndTime( | |
| 2246 ProbablySameFilter(builder->GetSameOriginFilter()), _, _)); | |
| 2186 | 2247 |
| 2187 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2248 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2188 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); | 2249 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); |
| 2189 } | 2250 } |
| 2190 | 2251 |
| 2191 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { | 2252 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { |
| 2192 RemovePasswordsTester tester(GetProfile()); | 2253 RemovePasswordsTester tester(GetProfile()); |
| 2193 | 2254 |
| 2194 EXPECT_CALL(*tester.store(), RemoveStatisticsCreatedBetweenImpl( | 2255 EXPECT_CALL(*tester.store(), RemoveStatisticsCreatedBetweenImpl( |
| 2195 base::Time(), base::Time::Max())); | 2256 base::Time(), base::Time::Max())); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2210 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { | 2271 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { |
| 2211 RemovePasswordsTester tester(GetProfile()); | 2272 RemovePasswordsTester tester(GetProfile()); |
| 2212 const url::Origin expectedOrigin(kOrigin1); | 2273 const url::Origin expectedOrigin(kOrigin1); |
| 2213 | 2274 |
| 2214 EXPECT_CALL(*tester.store(), | 2275 EXPECT_CALL(*tester.store(), |
| 2215 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) | 2276 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) |
| 2216 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | 2277 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 2217 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2278 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2218 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); | 2279 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); |
| 2219 } | 2280 } |
| OLD | NEW |