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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #include "net/ssl/channel_id_service.h" | 67 #include "net/ssl/channel_id_service.h" |
68 #include "net/ssl/channel_id_store.h" | 68 #include "net/ssl/channel_id_store.h" |
69 #include "net/ssl/ssl_client_cert_type.h" | 69 #include "net/ssl/ssl_client_cert_type.h" |
70 #include "net/url_request/url_request_context.h" | 70 #include "net/url_request/url_request_context.h" |
71 #include "net/url_request/url_request_context_getter.h" | 71 #include "net/url_request/url_request_context_getter.h" |
72 #include "testing/gmock/include/gmock/gmock.h" | 72 #include "testing/gmock/include/gmock/gmock.h" |
73 #include "testing/gtest/include/gtest/gtest.h" | 73 #include "testing/gtest/include/gtest/gtest.h" |
74 #include "third_party/skia/include/core/SkBitmap.h" | 74 #include "third_party/skia/include/core/SkBitmap.h" |
75 #include "ui/gfx/favicon_size.h" | 75 #include "ui/gfx/favicon_size.h" |
76 #include "url/origin.h" | 76 #include "url/origin.h" |
| 77 #include "url/origin_filter.h" |
77 | 78 |
78 #if defined(OS_CHROMEOS) | 79 #if defined(OS_CHROMEOS) |
79 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 80 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
80 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 81 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
81 #include "chrome/browser/chromeos/settings/cros_settings.h" | 82 #include "chrome/browser/chromeos/settings/cros_settings.h" |
82 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 83 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
83 #include "chromeos/dbus/dbus_thread_manager.h" | 84 #include "chromeos/dbus/dbus_thread_manager.h" |
84 #include "chromeos/dbus/mock_cryptohome_client.h" | 85 #include "chromeos/dbus/mock_cryptohome_client.h" |
85 #include "components/signin/core/account_id/account_id.h" | 86 #include "components/signin/core/account_id/account_id.h" |
86 #endif | 87 #endif |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 private: | 253 private: |
253 void AsyncRunCallback(const base::Closure& callback) { | 254 void AsyncRunCallback(const base::Closure& callback) { |
254 callback.Run(); | 255 callback.Run(); |
255 } | 256 } |
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 the equivalence of two origin filters. |
263 // origin. | 264 class FilterMatcher : public MatcherInterface<const url::OriginFilter*> { |
264 // (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 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { | |
267 public: | 265 public: |
268 explicit SameOriginMatcher(const url::Origin& reference) | 266 explicit FilterMatcher(const url::OriginFilter* filter) : to_match_(filter) { |
269 : reference_(reference) {} | 267 } |
270 | 268 |
271 virtual bool MatchAndExplain(const url::Origin& origin, | 269 virtual bool MatchAndExplain(const url::OriginFilter* filter, |
272 MatchResultListener* listener) const { | 270 MatchResultListener* listener) const { |
273 return reference_.IsSameOriginWith(origin); | 271 if (!filter) { |
| 272 *listener << "which is NULL."; |
| 273 return false; |
| 274 } |
| 275 return *filter == *to_match_; |
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 equal to " << *to_match_; |
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 equal to " << *to_match_; |
282 } | 284 } |
283 | 285 |
284 private: | 286 private: |
285 const url::Origin& reference_; | 287 const url::OriginFilter* to_match_; |
286 }; | 288 }; |
287 | 289 |
288 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { | 290 inline Matcher<const url::OriginFilter*> SameFilter( |
289 return MakeMatcher(new SameOriginMatcher(reference)); | 291 const url::OriginFilter* filter) { |
| 292 return MakeMatcher(new FilterMatcher(filter)); |
290 } | 293 } |
291 | 294 |
292 } // namespace | 295 } // namespace |
293 | 296 |
294 // Testers ------------------------------------------------------------------- | 297 // Testers ------------------------------------------------------------------- |
295 | 298 |
296 class RemoveCookieTester { | 299 class RemoveCookieTester { |
297 public: | 300 public: |
298 RemoveCookieTester() {} | 301 RemoveCookieTester() {} |
299 | 302 |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2139 // for some unrelated test cases. This should be fixed so it tests the no- | 2142 // for some unrelated test cases. This should be fixed so it tests the no- |
2140 // monitor case again. | 2143 // monitor case again. |
2141 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | 2144 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
2142 BlockUntilBrowsingDataRemoved( | 2145 BlockUntilBrowsingDataRemoved( |
2143 BrowsingDataRemover::EVERYTHING, | 2146 BrowsingDataRemover::EVERYTHING, |
2144 BrowsingDataRemover::REMOVE_HISTORY | | 2147 BrowsingDataRemover::REMOVE_HISTORY | |
2145 BrowsingDataRemover::REMOVE_COOKIES, false); | 2148 BrowsingDataRemover::REMOVE_COOKIES, false); |
2146 } | 2149 } |
2147 | 2150 |
2148 TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) { | 2151 TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) { |
| 2152 std::vector<url::Origin> whitelist; |
| 2153 whitelist.push_back(url::Origin(kOrigin1)); |
| 2154 scoped_ptr<url::OriginFilter> filter = |
| 2155 url::OriginFilter::AsWhitelist(whitelist); |
2149 RemoveDownloadsTester tester(GetProfile()); | 2156 RemoveDownloadsTester tester(GetProfile()); |
2150 const url::Origin expectedOrigin(kOrigin1); | |
2151 | 2157 |
2152 EXPECT_CALL(*tester.download_manager(), | 2158 EXPECT_CALL( |
2153 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _)); | 2159 *tester.download_manager(), |
| 2160 RemoveDownloadsByOriginAndTime(SameFilter(filter.get()), _, _)); |
2154 | 2161 |
2155 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2162 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
2156 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); | 2163 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); |
2157 } | 2164 } |
2158 | 2165 |
2159 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { | 2166 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) { |
2160 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( | 2167 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
2161 GetProfile(), | 2168 GetProfile(), |
2162 password_manager::BuildPasswordStore< | 2169 password_manager::BuildPasswordStore< |
2163 content::BrowserContext, password_manager::MockPasswordStore>); | 2170 content::BrowserContext, password_manager::MockPasswordStore>); |
2164 password_manager::MockPasswordStore* store = | 2171 password_manager::MockPasswordStore* store = |
2165 static_cast<password_manager::MockPasswordStore*>( | 2172 static_cast<password_manager::MockPasswordStore*>( |
2166 PasswordStoreFactory::GetInstance() | 2173 PasswordStoreFactory::GetInstance() |
2167 ->GetForProfile(GetProfile(), ServiceAccessType::EXPLICIT_ACCESS) | 2174 ->GetForProfile(GetProfile(), ServiceAccessType::EXPLICIT_ACCESS) |
2168 .get()); | 2175 .get()); |
2169 EXPECT_CALL(*store, RemoveStatisticsCreatedBetweenImpl(base::Time(), | 2176 EXPECT_CALL(*store, RemoveStatisticsCreatedBetweenImpl(base::Time(), |
2170 base::Time::Max())); | 2177 base::Time::Max())); |
2171 BlockUntilBrowsingDataRemoved( | 2178 BlockUntilBrowsingDataRemoved( |
2172 BrowsingDataRemover::EVERYTHING, | 2179 BrowsingDataRemover::EVERYTHING, |
2173 BrowsingDataRemover::REMOVE_HISTORY, false); | 2180 BrowsingDataRemover::REMOVE_HISTORY, false); |
2174 } | 2181 } |
OLD | NEW |