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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/guid.h" | 15 #include "base/guid.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/prefs/testing_pref_service.h" | 18 #include "base/prefs/testing_pref_service.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
22 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 22 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
24 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 24 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
25 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 25 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
26 #include "chrome/browser/domain_reliability/service_factory.h" | 26 #include "chrome/browser/domain_reliability/service_factory.h" |
| 27 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
27 #include "chrome/browser/favicon/favicon_service_factory.h" | 28 #include "chrome/browser/favicon/favicon_service_factory.h" |
28 #include "chrome/browser/history/history_service_factory.h" | 29 #include "chrome/browser/history/history_service_factory.h" |
29 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
31 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
32 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
33 #include "components/autofill/core/browser/autofill_profile.h" | 34 #include "components/autofill/core/browser/autofill_profile.h" |
34 #include "components/autofill/core/browser/autofill_test_utils.h" | 35 #include "components/autofill/core/browser/autofill_test_utils.h" |
35 #include "components/autofill/core/browser/credit_card.h" | 36 #include "components/autofill/core/browser/credit_card.h" |
36 #include "components/autofill/core/browser/personal_data_manager.h" | 37 #include "components/autofill/core/browser/personal_data_manager.h" |
37 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 38 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
38 #include "components/bookmarks/browser/bookmark_model.h" | 39 #include "components/bookmarks/browser/bookmark_model.h" |
39 #include "components/bookmarks/test/bookmark_test_helpers.h" | 40 #include "components/bookmarks/test/bookmark_test_helpers.h" |
40 #include "components/domain_reliability/clear_mode.h" | 41 #include "components/domain_reliability/clear_mode.h" |
41 #include "components/domain_reliability/monitor.h" | 42 #include "components/domain_reliability/monitor.h" |
42 #include "components/domain_reliability/service.h" | 43 #include "components/domain_reliability/service.h" |
43 #include "components/favicon/core/favicon_service.h" | 44 #include "components/favicon/core/favicon_service.h" |
44 #include "components/history/core/browser/history_service.h" | 45 #include "components/history/core/browser/history_service.h" |
45 #include "components/omnibox/browser/omnibox_pref_names.h" | 46 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 47 #include "content/public/browser/browser_context.h" |
46 #include "content/public/browser/cookie_store_factory.h" | 48 #include "content/public/browser/cookie_store_factory.h" |
47 #include "content/public/browser/dom_storage_context.h" | 49 #include "content/public/browser/dom_storage_context.h" |
48 #include "content/public/browser/local_storage_usage_info.h" | 50 #include "content/public/browser/local_storage_usage_info.h" |
49 #include "content/public/browser/storage_partition.h" | 51 #include "content/public/browser/storage_partition.h" |
| 52 #include "content/public/test/mock_download_manager.h" |
50 #include "content/public/test/test_browser_thread.h" | 53 #include "content/public/test/test_browser_thread.h" |
51 #include "content/public/test/test_browser_thread_bundle.h" | 54 #include "content/public/test/test_browser_thread_bundle.h" |
52 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
53 #include "net/cookies/cookie_store.h" | 56 #include "net/cookies/cookie_store.h" |
54 #include "net/ssl/channel_id_service.h" | 57 #include "net/ssl/channel_id_service.h" |
55 #include "net/ssl/channel_id_store.h" | 58 #include "net/ssl/channel_id_store.h" |
56 #include "net/ssl/ssl_client_cert_type.h" | 59 #include "net/ssl/ssl_client_cert_type.h" |
57 #include "net/url_request/url_request_context.h" | 60 #include "net/url_request/url_request_context.h" |
58 #include "net/url_request/url_request_context_getter.h" | 61 #include "net/url_request/url_request_context_getter.h" |
59 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
60 #include "testing/gtest/include/gtest/gtest.h" | 63 #include "testing/gtest/include/gtest/gtest.h" |
61 #include "third_party/skia/include/core/SkBitmap.h" | 64 #include "third_party/skia/include/core/SkBitmap.h" |
62 #include "ui/gfx/favicon_size.h" | 65 #include "ui/gfx/favicon_size.h" |
| 66 #include "url/origin.h" |
63 | 67 |
64 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
65 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 69 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
66 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 70 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
67 #include "chrome/browser/chromeos/settings/cros_settings.h" | 71 #include "chrome/browser/chromeos/settings/cros_settings.h" |
68 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 72 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
69 #include "chromeos/dbus/dbus_thread_manager.h" | 73 #include "chromeos/dbus/dbus_thread_manager.h" |
70 #include "chromeos/dbus/mock_cryptohome_client.h" | 74 #include "chromeos/dbus/mock_cryptohome_client.h" |
71 #endif | 75 #endif |
72 | 76 |
73 #if defined(ENABLE_EXTENSIONS) | 77 #if defined(ENABLE_EXTENSIONS) |
74 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" | 78 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" |
75 #endif | 79 #endif |
76 | 80 |
77 class MockExtensionSpecialStoragePolicy; | 81 class MockExtensionSpecialStoragePolicy; |
78 | 82 |
79 using content::BrowserThread; | 83 using content::BrowserThread; |
80 using content::StoragePartition; | 84 using content::StoragePartition; |
81 using domain_reliability::CLEAR_BEACONS; | 85 using domain_reliability::CLEAR_BEACONS; |
82 using domain_reliability::CLEAR_CONTEXTS; | 86 using domain_reliability::CLEAR_CONTEXTS; |
83 using domain_reliability::DomainReliabilityClearMode; | 87 using domain_reliability::DomainReliabilityClearMode; |
84 using domain_reliability::DomainReliabilityMonitor; | 88 using domain_reliability::DomainReliabilityMonitor; |
85 using domain_reliability::DomainReliabilityService; | 89 using domain_reliability::DomainReliabilityService; |
86 using domain_reliability::DomainReliabilityServiceFactory; | 90 using domain_reliability::DomainReliabilityServiceFactory; |
87 using testing::_; | 91 using testing::_; |
| 92 using testing::ByRef; |
88 using testing::Invoke; | 93 using testing::Invoke; |
| 94 using testing::Matcher; |
| 95 using testing::MakeMatcher; |
| 96 using testing::MatcherInterface; |
| 97 using testing::MatchResultListener; |
| 98 using testing::Return; |
89 using testing::WithArgs; | 99 using testing::WithArgs; |
90 | 100 |
91 namespace { | 101 namespace { |
92 | 102 |
93 const char kTestOrigin1[] = "http://host1:1/"; | 103 const char kTestOrigin1[] = "http://host1:1/"; |
94 const char kTestOrigin2[] = "http://host2:1/"; | 104 const char kTestOrigin2[] = "http://host2:1/"; |
95 const char kTestOrigin3[] = "http://host3:1/"; | 105 const char kTestOrigin3[] = "http://host3:1/"; |
96 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; | 106 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; |
97 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; | 107 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; |
98 | 108 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 private: | 228 private: |
219 void AsyncRunCallback(const base::Closure& callback) { | 229 void AsyncRunCallback(const base::Closure& callback) { |
220 callback.Run(); | 230 callback.Run(); |
221 } | 231 } |
222 | 232 |
223 StoragePartitionRemovalData storage_partition_removal_data_; | 233 StoragePartitionRemovalData storage_partition_removal_data_; |
224 | 234 |
225 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); | 235 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); |
226 }; | 236 }; |
227 | 237 |
| 238 // Custom matcher to verify is-same-origin relationship to given reference |
| 239 // origin. |
| 240 // (We cannot use equality-based matching because operator== is not defined for |
| 241 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.) |
| 242 class SameOriginMatcher : public MatcherInterface<const url::Origin&> { |
| 243 public: |
| 244 explicit SameOriginMatcher(const url::Origin& reference) |
| 245 : reference_(reference) {} |
| 246 |
| 247 virtual bool MatchAndExplain(const url::Origin& origin, |
| 248 MatchResultListener* listener) const { |
| 249 return reference_.IsSameOriginWith(origin); |
| 250 } |
| 251 |
| 252 virtual void DescribeTo(::std::ostream* os) const { |
| 253 *os << "is same origin with " << reference_; |
| 254 } |
| 255 |
| 256 virtual void DescribeNegationTo(::std::ostream* os) const { |
| 257 *os << "is not same origin with " << reference_; |
| 258 } |
| 259 |
| 260 private: |
| 261 const url::Origin& reference_; |
| 262 }; |
| 263 |
| 264 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) { |
| 265 return MakeMatcher(new SameOriginMatcher(reference)); |
| 266 } |
| 267 |
228 } // namespace | 268 } // namespace |
229 | 269 |
230 // Testers ------------------------------------------------------------------- | 270 // Testers ------------------------------------------------------------------- |
231 | 271 |
232 class RemoveCookieTester { | 272 class RemoveCookieTester { |
233 public: | 273 public: |
234 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) { | 274 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) { |
235 } | 275 } |
236 | 276 |
237 // Returns true, if the given cookie exists in the cookie store. | 277 // Returns true, if the given cookie exists in the cookie store. |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 // Verify and detach kludgey struct. | 833 // Verify and detach kludgey struct. |
794 EXPECT_EQ(data, profile_->GetUserData(kKey)); | 834 EXPECT_EQ(data, profile_->GetUserData(kKey)); |
795 EXPECT_TRUE(data->attached); | 835 EXPECT_TRUE(data->attached); |
796 profile_->RemoveUserData(kKey); | 836 profile_->RemoveUserData(kKey); |
797 } | 837 } |
798 | 838 |
799 TestingProfile* profile_; | 839 TestingProfile* profile_; |
800 MockDomainReliabilityService* mock_service_; | 840 MockDomainReliabilityService* mock_service_; |
801 }; | 841 }; |
802 | 842 |
| 843 class RemoveDownloadsTester { |
| 844 public: |
| 845 explicit RemoveDownloadsTester(TestingProfile* testing_profile) |
| 846 : download_manager_(new content::MockDownloadManager()), |
| 847 chrome_download_manager_delegate_(testing_profile) { |
| 848 content::BrowserContext::SetDownloadManagerForTesting(testing_profile, |
| 849 download_manager_); |
| 850 EXPECT_EQ(download_manager_, |
| 851 content::BrowserContext::GetDownloadManager(testing_profile)); |
| 852 |
| 853 EXPECT_CALL(*download_manager_, GetDelegate()) |
| 854 .WillOnce(Return(&chrome_download_manager_delegate_)); |
| 855 EXPECT_CALL(*download_manager_, Shutdown()); |
| 856 } |
| 857 |
| 858 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); } |
| 859 |
| 860 content::MockDownloadManager* download_manager() { return download_manager_; } |
| 861 |
| 862 private: |
| 863 content::MockDownloadManager* download_manager_; |
| 864 ChromeDownloadManagerDelegate chrome_download_manager_delegate_; |
| 865 |
| 866 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); |
| 867 }; |
| 868 |
803 // Test Class ---------------------------------------------------------------- | 869 // Test Class ---------------------------------------------------------------- |
804 | 870 |
805 class BrowsingDataRemoverTest : public testing::Test { | 871 class BrowsingDataRemoverTest : public testing::Test { |
806 public: | 872 public: |
807 BrowsingDataRemoverTest() | 873 BrowsingDataRemoverTest() |
808 : profile_(new TestingProfile()), | 874 : profile_(new TestingProfile()), |
809 clear_domain_reliability_tester_(GetProfile()) { | 875 clear_domain_reliability_tester_(GetProfile()) { |
810 callback_subscription_ = | 876 callback_subscription_ = |
811 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 877 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
812 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails, | 878 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails, |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 // TODO(ttuttle): This isn't actually testing the no-monitor case, since | 2045 // TODO(ttuttle): This isn't actually testing the no-monitor case, since |
1980 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed | 2046 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed |
1981 // for some unrelated test cases. This should be fixed so it tests the no- | 2047 // for some unrelated test cases. This should be fixed so it tests the no- |
1982 // monitor case again. | 2048 // monitor case again. |
1983 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | 2049 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
1984 BlockUntilBrowsingDataRemoved( | 2050 BlockUntilBrowsingDataRemoved( |
1985 BrowsingDataRemover::EVERYTHING, | 2051 BrowsingDataRemover::EVERYTHING, |
1986 BrowsingDataRemover::REMOVE_HISTORY | | 2052 BrowsingDataRemover::REMOVE_HISTORY | |
1987 BrowsingDataRemover::REMOVE_COOKIES, false); | 2053 BrowsingDataRemover::REMOVE_COOKIES, false); |
1988 } | 2054 } |
| 2055 |
| 2056 TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) { |
| 2057 RemoveDownloadsTester tester(GetProfile()); |
| 2058 const url::Origin expectedOrigin(kOrigin1); |
| 2059 |
| 2060 EXPECT_CALL(*tester.download_manager(), |
| 2061 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _)); |
| 2062 |
| 2063 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2064 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1); |
| 2065 } |
OLD | NEW |