[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/browsing_data_remover.h" |
| 6 | |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 7 | #include <set> |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 8 | #include <vector> |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 9 | |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 75b3ac91 | 2011-10-05 18:09:30 | [diff] [blame] | 11 | #include "base/bind_helpers.h" |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 13 | #include "base/platform_file.h" |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 14 | #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 15 | #include "chrome/browser/history/history.h" |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 16 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 17 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 18 | #include "chrome/common/pref_names.h" |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 19 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 20 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 21 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 22 | #include "content/public/browser/notification_service.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 23 | #include "content/test/test_browser_thread.h" |
[email protected] | 32cb7fb | 2012-03-22 22:41:11 | [diff] [blame] | 24 | #include "net/base/server_bound_cert_service.h" |
| 25 | #include "net/base/server_bound_cert_store.h" |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 26 | #include "net/base/ssl_client_cert_type.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 27 | #include "net/cookies/cookie_monster.h" |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 28 | #include "net/url_request/url_request_context.h" |
[email protected] | acdff99 | 2011-09-02 18:06:23 | [diff] [blame] | 29 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 30 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 31 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 32 | #include "webkit/fileapi/file_system_file_util.h" |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 33 | #include "webkit/fileapi/file_system_operation_context.h" |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 34 | #include "webkit/fileapi/sandbox_mount_point_provider.h" |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 35 | #include "webkit/quota/mock_quota_manager.h" |
| 36 | #include "webkit/quota/quota_manager.h" |
| 37 | #include "webkit/quota/quota_types.h" |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 38 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 39 | using content::BrowserThread; |
| 40 | |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 41 | namespace { |
| 42 | |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 43 | const char kTestkOrigin1[] = "http://host1:1/"; |
| 44 | const char kTestkOrigin2[] = "http://host2:1/"; |
| 45 | const char kTestkOrigin3[] = "http://host3:1/"; |
| 46 | |
| 47 | const GURL kOrigin1(kTestkOrigin1); |
| 48 | const GURL kOrigin2(kTestkOrigin2); |
| 49 | const GURL kOrigin3(kTestkOrigin3); |
| 50 | |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 51 | const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
| 52 | const quota::StorageType kPersistent = quota::kStorageTypePersistent; |
| 53 | |
| 54 | const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem; |
| 55 | const quota::QuotaClient::ID kClientDB = quota::QuotaClient::kIndexedDatabase; |
| 56 | |
[email protected] | 8d4ec68 | 2012-02-17 12:20:17 | [diff] [blame] | 57 | } // namespace |
| 58 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 59 | class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer { |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 60 | public: |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 61 | BrowsingDataRemoverTester() |
| 62 | : start_(false), |
| 63 | already_quit_(false) {} |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 64 | virtual ~BrowsingDataRemoverTester() {} |
| 65 | |
| 66 | void BlockUntilNotified() { |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 67 | if (!already_quit_) { |
| 68 | DCHECK(!start_); |
| 69 | start_ = true; |
| 70 | MessageLoop::current()->Run(); |
| 71 | } else { |
| 72 | DCHECK(!start_); |
| 73 | already_quit_ = false; |
| 74 | } |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 75 | } |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 76 | |
| 77 | protected: |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 78 | // BrowsingDataRemover::Observer implementation. |
| 79 | virtual void OnBrowsingDataRemoverDone() { |
| 80 | Notify(); |
| 81 | } |
| 82 | |
| 83 | void Notify() { |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 84 | if (start_) { |
| 85 | DCHECK(!already_quit_); |
| 86 | MessageLoop::current()->Quit(); |
| 87 | start_ = false; |
| 88 | } else { |
| 89 | DCHECK(!already_quit_); |
| 90 | already_quit_ = true; |
| 91 | } |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | private: |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 95 | // Helps prevent from running message_loop, if the callback invoked |
| 96 | // immediately. |
| 97 | bool start_; |
| 98 | bool already_quit_; |
| 99 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester); |
| 101 | }; |
| 102 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 103 | // Testers ------------------------------------------------------------------- |
| 104 | |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 105 | class RemoveCookieTester : public BrowsingDataRemoverTester { |
| 106 | public: |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 107 | RemoveCookieTester() : get_cookie_success_(false) { |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Returns true, if the given cookie exists in the cookie store. |
| 111 | bool ContainsCookie() { |
| 112 | get_cookie_success_ = false; |
| 113 | monster_->GetCookiesWithOptionsAsync( |
| 114 | kOrigin1, net::CookieOptions(), |
| 115 | base::Bind(&RemoveCookieTester::GetCookieCallback, |
| 116 | base::Unretained(this))); |
| 117 | BlockUntilNotified(); |
| 118 | return get_cookie_success_; |
| 119 | } |
| 120 | |
| 121 | void AddCookie() { |
| 122 | monster_->SetCookieWithOptionsAsync( |
| 123 | kOrigin1, "A=1", net::CookieOptions(), |
| 124 | base::Bind(&RemoveCookieTester::SetCookieCallback, |
| 125 | base::Unretained(this))); |
| 126 | BlockUntilNotified(); |
| 127 | } |
| 128 | |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 129 | protected: |
| 130 | void SetMonster(net::CookieStore* monster) { |
| 131 | monster_ = monster; |
| 132 | } |
| 133 | |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 134 | private: |
| 135 | void GetCookieCallback(const std::string& cookies) { |
| 136 | if (cookies == "A=1") { |
| 137 | get_cookie_success_ = true; |
| 138 | } else { |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 139 | EXPECT_EQ("", cookies); |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 140 | get_cookie_success_ = false; |
| 141 | } |
| 142 | Notify(); |
| 143 | } |
| 144 | |
| 145 | void SetCookieCallback(bool result) { |
| 146 | ASSERT_TRUE(result); |
| 147 | Notify(); |
| 148 | } |
| 149 | |
| 150 | bool get_cookie_success_; |
| 151 | |
| 152 | net::CookieStore* monster_; |
| 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); |
| 155 | }; |
| 156 | |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 157 | class RemoveProfileCookieTester : public RemoveCookieTester { |
| 158 | public: |
| 159 | explicit RemoveProfileCookieTester(TestingProfile* profile) { |
| 160 | profile->CreateRequestContext(); |
| 161 | SetMonster(profile->GetRequestContext()->GetURLRequestContext()-> |
| 162 | cookie_store()->GetCookieMonster()); |
| 163 | } |
| 164 | }; |
| 165 | |
[email protected] | 39bbe37 | 2012-02-24 02:46:16 | [diff] [blame] | 166 | #if defined(ENABLE_SAFE_BROWSING) |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 167 | class RemoveSafeBrowsingCookieTester : public RemoveCookieTester { |
| 168 | public: |
| 169 | RemoveSafeBrowsingCookieTester() |
| 170 | : browser_process_( |
| 171 | static_cast<TestingBrowserProcess*>(g_browser_process)) { |
| 172 | scoped_refptr<SafeBrowsingService> sb_service = |
| 173 | SafeBrowsingService::CreateSafeBrowsingService(); |
| 174 | browser_process_->SetSafeBrowsingService(sb_service); |
| 175 | sb_service->Initialize(); |
| 176 | MessageLoop::current()->RunAllPending(); |
| 177 | |
| 178 | // Create a cookiemonster that does not have persistant storage, and replace |
| 179 | // the SafeBrowsingService created one with it. |
| 180 | net::CookieStore* monster = new net::CookieMonster(NULL, NULL); |
| 181 | sb_service->url_request_context()->GetURLRequestContext()-> |
| 182 | set_cookie_store(monster); |
| 183 | SetMonster(monster); |
| 184 | } |
| 185 | |
| 186 | virtual ~RemoveSafeBrowsingCookieTester() { |
| 187 | browser_process_->safe_browsing_service()->ShutDown(); |
| 188 | MessageLoop::current()->RunAllPending(); |
| 189 | browser_process_->SetSafeBrowsingService(NULL); |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | TestingBrowserProcess* browser_process_; |
| 194 | |
| 195 | DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); |
| 196 | }; |
[email protected] | 39bbe37 | 2012-02-24 02:46:16 | [diff] [blame] | 197 | #endif |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 198 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 199 | class RemoveServerBoundCertTester : public BrowsingDataRemoverTester { |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 200 | public: |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 201 | explicit RemoveServerBoundCertTester(TestingProfile* profile) { |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 202 | profile->CreateRequestContext(); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 203 | server_bound_cert_service_ = profile->GetRequestContext()-> |
| 204 | GetURLRequestContext()->server_bound_cert_service(); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 207 | int ServerBoundCertCount() { |
| 208 | return server_bound_cert_service_->cert_count(); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 211 | // Add a server bound cert for |server| with specific creation and expiry |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 212 | // times. The cert and key data will be filled with dummy values. |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 213 | void AddServerBoundCertWithTimes(const std::string& server_identifier, |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 214 | base::Time creation_time, |
| 215 | base::Time expiration_time) { |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 216 | GetCertStore()->SetServerBoundCert(server_identifier, |
| 217 | net::CLIENT_CERT_RSA_SIGN, creation_time, |
| 218 | expiration_time, "a", "b"); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 221 | // Add a server bound cert for |server|, with the current time as the |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 222 | // creation time. The cert and key data will be filled with dummy values. |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 223 | void AddServerBoundCert(const std::string& server_identifier) { |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 224 | base::Time now = base::Time::Now(); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 225 | AddServerBoundCertWithTimes(server_identifier, |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 226 | now, |
| 227 | now + base::TimeDelta::FromDays(1)); |
| 228 | } |
| 229 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 230 | net::ServerBoundCertStore* GetCertStore() { |
| 231 | return server_bound_cert_service_->GetCertStore(); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | private: |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 235 | net::ServerBoundCertService* server_bound_cert_service_; |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 236 | |
| 237 | net::SSLClientCertType type_; |
| 238 | std::string key_; |
| 239 | std::string cert_; |
| 240 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 241 | DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 242 | }; |
| 243 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 244 | class RemoveHistoryTester : public BrowsingDataRemoverTester { |
| 245 | public: |
| 246 | explicit RemoveHistoryTester(TestingProfile* profile) |
| 247 | : query_url_success_(false) { |
| 248 | profile->CreateHistoryService(true, false); |
| 249 | history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 250 | } |
| 251 | |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 252 | // Returns true, if the given URL exists in the history service. |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 253 | bool HistoryContainsURL(const GURL& url) { |
| 254 | history_service_->QueryURL( |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 255 | url, |
| 256 | true, |
| 257 | &consumer_, |
[email protected] | 75b3ac91 | 2011-10-05 18:09:30 | [diff] [blame] | 258 | base::Bind(&RemoveHistoryTester::SaveResultAndQuit, |
| 259 | base::Unretained(this))); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 260 | BlockUntilNotified(); |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 261 | return query_url_success_; |
| 262 | } |
| 263 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 264 | void AddHistory(const GURL& url, base::Time time) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 265 | history_service_->AddPage(url, time, NULL, 0, GURL(), |
| 266 | content::PAGE_TRANSITION_LINK, history::RedirectList(), |
| 267 | history::SOURCE_BROWSED, false); |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | private: |
| 271 | // Callback for HistoryService::QueryURL. |
| 272 | void SaveResultAndQuit(HistoryService::Handle, |
| 273 | bool success, |
| 274 | const history::URLRow*, |
| 275 | history::VisitVector*) { |
| 276 | query_url_success_ = success; |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 277 | Notify(); |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 280 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 281 | // For History requests. |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 282 | CancelableRequestConsumer consumer_; |
| 283 | bool query_url_success_; |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 284 | |
| 285 | // TestingProfile owns the history service; we shouldn't delete it. |
| 286 | HistoryService* history_service_; |
| 287 | |
| 288 | DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 289 | }; |
| 290 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 291 | class RemoveQuotaManagedDataTester : public BrowsingDataRemoverTester { |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 292 | public: |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 293 | RemoveQuotaManagedDataTester() {} |
| 294 | virtual ~RemoveQuotaManagedDataTester() {} |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 295 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 296 | void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) { |
| 297 | // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent |
| 298 | // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2 |
| 299 | // is modified at the beginning of time, and kOrigin3 is modified one day |
| 300 | // ago. |
| 301 | PopulateTestQuotaManagedPersistentData(manager); |
| 302 | PopulateTestQuotaManagedTemporaryData(manager); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 305 | void PopulateTestQuotaManagedPersistentData( |
| 306 | quota::MockQuotaManager* manager) { |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 307 | manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time()); |
| 308 | manager->AddOrigin(kOrigin3, kPersistent, kClientFile, |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 309 | base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 310 | |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 311 | EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile)); |
| 312 | EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile)); |
| 313 | EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile)); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 314 | } |
| 315 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 316 | void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) { |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 317 | manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now()); |
| 318 | manager->AddOrigin(kOrigin3, kTemporary, kClientFile, |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 319 | base::Time::Now() - base::TimeDelta::FromDays(1)); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 320 | |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 321 | EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile)); |
| 322 | EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile)); |
| 323 | EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile)); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | private: |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 327 | DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 328 | }; |
| 329 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 330 | // Test Class ---------------------------------------------------------------- |
| 331 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 332 | class BrowsingDataRemoverTest : public testing::Test, |
| 333 | public content::NotificationObserver { |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 334 | public: |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 335 | BrowsingDataRemoverTest() |
| 336 | : ui_thread_(BrowserThread::UI, &message_loop_), |
| 337 | db_thread_(BrowserThread::DB, &message_loop_), |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 338 | webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 339 | file_thread_(BrowserThread::FILE, &message_loop_), |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 340 | file_user_blocking_thread_( |
| 341 | BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 342 | io_thread_(BrowserThread::IO, &message_loop_), |
| 343 | profile_(new TestingProfile()) { |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 344 | registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 345 | content::Source<Profile>(profile_.get())); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | virtual ~BrowsingDataRemoverTest() { |
| 349 | } |
| 350 | |
| 351 | void TearDown() { |
[email protected] | c1fff07 | 2012-02-24 23:38:12 | [diff] [blame] | 352 | // TestingProfile contains a DOMStorageContext. BrowserContext's destructor |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 353 | // posts a message to the WEBKIT thread to delete some of its member |
| 354 | // variables. We need to ensure that the profile is destroyed, and that |
| 355 | // the message loop is cleared out, before destroying the threads and loop. |
| 356 | // Otherwise we leak memory. |
| 357 | profile_.reset(); |
| 358 | message_loop_.RunAllPending(); |
| 359 | } |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 360 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 361 | void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 362 | int remove_mask, |
| 363 | BrowsingDataRemoverTester* tester) { |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 364 | BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 365 | profile_.get(), period, |
| 366 | base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 367 | remover->OverrideQuotaManagerForTesting(GetMockManager()); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 368 | remover->AddObserver(tester); |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 369 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 370 | called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 371 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 372 | // BrowsingDataRemover deletes itself when it completes. |
| 373 | remover->Remove(remove_mask); |
| 374 | tester->BlockUntilNotified(); |
| 375 | } |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 376 | |
[email protected] | 8d4ec68 | 2012-02-17 12:20:17 | [diff] [blame] | 377 | void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 378 | int remove_mask, |
| 379 | const GURL& remove_origin, |
| 380 | BrowsingDataRemoverTester* tester) { |
| 381 | BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 382 | profile_.get(), period, |
| 383 | base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 384 | remover->OverrideQuotaManagerForTesting(GetMockManager()); |
[email protected] | 8d4ec68 | 2012-02-17 12:20:17 | [diff] [blame] | 385 | remover->AddObserver(tester); |
| 386 | |
| 387 | called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 388 | |
| 389 | // BrowsingDataRemover deletes itself when it completes. |
| 390 | remover->RemoveImpl(remove_mask, remove_origin, false); |
| 391 | tester->BlockUntilNotified(); |
| 392 | } |
| 393 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 394 | TestingProfile* GetProfile() { |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 395 | return profile_.get(); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 396 | } |
[email protected] | 9d4ca08 | 2011-05-30 16:39:41 | [diff] [blame] | 397 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 398 | base::Time GetBeginTime() { |
| 399 | return called_with_details_->removal_begin; |
| 400 | } |
| 401 | |
| 402 | int GetRemovalMask() { |
| 403 | return called_with_details_->removal_mask; |
| 404 | } |
| 405 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 406 | quota::MockQuotaManager* GetMockManager() { |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 407 | if (!quota_manager_) { |
| 408 | quota_manager_ = new quota::MockQuotaManager( |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 409 | profile_->IsOffTheRecord(), |
| 410 | profile_->GetPath(), |
| 411 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 412 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 413 | profile_->GetExtensionSpecialStoragePolicy()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 414 | } |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 415 | return quota_manager_; |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 418 | // content::NotificationObserver implementation. |
| 419 | virtual void Observe(int type, |
| 420 | const content::NotificationSource& source, |
| 421 | const content::NotificationDetails& details) OVERRIDE { |
| 422 | DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 423 | |
| 424 | // We're not taking ownership of the details object, but storing a copy of |
| 425 | // it locally. |
| 426 | called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( |
| 427 | *content::Details<BrowsingDataRemover::NotificationDetails>( |
| 428 | details).ptr())); |
| 429 | |
| 430 | registrar_.RemoveAll(); |
| 431 | } |
| 432 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 433 | private: |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 434 | scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
| 435 | content::NotificationRegistrar registrar_; |
| 436 | |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 437 | // message_loop_, as well as all the threads associated with it must be |
| 438 | // defined before profile_ to prevent explosions. Oh how I love C++. |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 439 | MessageLoopForUI message_loop_; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 440 | content::TestBrowserThread ui_thread_; |
| 441 | content::TestBrowserThread db_thread_; |
| 442 | content::TestBrowserThread webkit_thread_; |
| 443 | content::TestBrowserThread file_thread_; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 444 | content::TestBrowserThread file_user_blocking_thread_; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 445 | content::TestBrowserThread io_thread_; |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 446 | scoped_ptr<TestingProfile> profile_; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 447 | scoped_refptr<quota::MockQuotaManager> quota_manager_; |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 448 | |
| 449 | DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
| 450 | }; |
| 451 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 452 | // Tests --------------------------------------------------------------------- |
| 453 | |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 454 | TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 455 | scoped_ptr<RemoveProfileCookieTester> tester( |
| 456 | new RemoveProfileCookieTester(GetProfile())); |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 457 | |
| 458 | tester->AddCookie(); |
| 459 | ASSERT_TRUE(tester->ContainsCookie()); |
| 460 | |
| 461 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 462 | BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 463 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 464 | EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 465 | EXPECT_FALSE(tester->ContainsCookie()); |
| 466 | } |
| 467 | |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 468 | TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) { |
| 469 | scoped_ptr<RemoveProfileCookieTester> tester( |
| 470 | new RemoveProfileCookieTester(GetProfile())); |
| 471 | |
| 472 | tester->AddCookie(); |
| 473 | ASSERT_TRUE(tester->ContainsCookie()); |
| 474 | |
| 475 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 476 | BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 477 | |
| 478 | EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 479 | EXPECT_FALSE(tester->ContainsCookie()); |
| 480 | } |
| 481 | |
[email protected] | 39bbe37 | 2012-02-24 02:46:16 | [diff] [blame] | 482 | #if defined(ENABLE_SAFE_BROWSING) |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 483 | TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) { |
| 484 | scoped_ptr<RemoveSafeBrowsingCookieTester> tester( |
| 485 | new RemoveSafeBrowsingCookieTester()); |
| 486 | |
| 487 | tester->AddCookie(); |
| 488 | ASSERT_TRUE(tester->ContainsCookie()); |
| 489 | |
| 490 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 491 | BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 492 | |
| 493 | EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 494 | EXPECT_FALSE(tester->ContainsCookie()); |
| 495 | } |
| 496 | |
| 497 | TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) { |
| 498 | scoped_ptr<RemoveSafeBrowsingCookieTester> tester( |
| 499 | new RemoveSafeBrowsingCookieTester()); |
| 500 | |
| 501 | tester->AddCookie(); |
| 502 | ASSERT_TRUE(tester->ContainsCookie()); |
| 503 | |
| 504 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 505 | BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
| 506 | |
| 507 | EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); |
| 508 | // Removing with time period other than EVERYTHING should not clear safe |
| 509 | // browsing cookies. |
| 510 | EXPECT_TRUE(tester->ContainsCookie()); |
| 511 | } |
[email protected] | 39bbe37 | 2012-02-24 02:46:16 | [diff] [blame] | 512 | #endif |
[email protected] | dde7a5a | 2012-02-22 23:16:34 | [diff] [blame] | 513 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 514 | TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) { |
| 515 | scoped_ptr<RemoveServerBoundCertTester> tester( |
| 516 | new RemoveServerBoundCertTester(GetProfile())); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 517 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 518 | tester->AddServerBoundCert(kTestkOrigin1); |
| 519 | EXPECT_EQ(1, tester->ServerBoundCertCount()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 520 | |
| 521 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 522 | BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 523 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 524 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); |
| 525 | EXPECT_EQ(0, tester->ServerBoundCertCount()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 528 | TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) { |
| 529 | scoped_ptr<RemoveServerBoundCertTester> tester( |
| 530 | new RemoveServerBoundCertTester(GetProfile())); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 531 | |
| 532 | base::Time now = base::Time::Now(); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 533 | tester->AddServerBoundCert(kTestkOrigin1); |
| 534 | tester->AddServerBoundCertWithTimes(kTestkOrigin2, |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 535 | now - base::TimeDelta::FromHours(2), |
| 536 | now); |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 537 | EXPECT_EQ(2, tester->ServerBoundCertCount()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 538 | |
| 539 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 540 | BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 541 | |
[email protected] | 9c4eff2 | 2012-03-20 22:42:29 | [diff] [blame] | 542 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); |
| 543 | EXPECT_EQ(1, tester->ServerBoundCertCount()); |
| 544 | std::vector<net::ServerBoundCertStore::ServerBoundCert> certs; |
| 545 | tester->GetCertStore()->GetAllServerBoundCerts(&certs); |
| 546 | EXPECT_EQ(kTestkOrigin2, certs[0].server_identifier()); |
[email protected] | eb7974c | 2012-01-25 17:38:48 | [diff] [blame] | 547 | } |
| 548 | |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 549 | TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
| 550 | scoped_ptr<RemoveHistoryTester> tester( |
| 551 | new RemoveHistoryTester(GetProfile())); |
| 552 | |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 553 | tester->AddHistory(kOrigin1, base::Time::Now()); |
| 554 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 555 | |
| 556 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 557 | BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 558 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 559 | EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 560 | EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { |
| 564 | scoped_ptr<RemoveHistoryTester> tester( |
| 565 | new RemoveHistoryTester(GetProfile())); |
| 566 | |
| 567 | base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 568 | |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 569 | tester->AddHistory(kOrigin1, base::Time::Now()); |
| 570 | tester->AddHistory(kOrigin2, two_hours_ago); |
| 571 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 572 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 573 | |
| 574 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
[email protected] | ade9abe | 2011-09-02 17:29:12 | [diff] [blame] | 575 | BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
[email protected] | f5f665fd6 | 2011-06-01 11:39:18 | [diff] [blame] | 576 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 577 | EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 578 | EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); |
| 579 | EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 580 | } |
| 581 | |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 582 | TEST_F(BrowsingDataRemoverTest, QuotaClientMaskGeneration) { |
| 583 | EXPECT_EQ(quota::QuotaClient::kFileSystem, |
| 584 | BrowsingDataRemover::GenerateQuotaClientMask( |
| 585 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS)); |
| 586 | EXPECT_EQ(quota::QuotaClient::kDatabase, |
| 587 | BrowsingDataRemover::GenerateQuotaClientMask( |
| 588 | BrowsingDataRemover::REMOVE_WEBSQL)); |
| 589 | EXPECT_EQ(quota::QuotaClient::kAppcache, |
| 590 | BrowsingDataRemover::GenerateQuotaClientMask( |
| 591 | BrowsingDataRemover::REMOVE_APPCACHE)); |
| 592 | EXPECT_EQ(quota::QuotaClient::kIndexedDatabase, |
| 593 | BrowsingDataRemover::GenerateQuotaClientMask( |
| 594 | BrowsingDataRemover::REMOVE_INDEXEDDB)); |
| 595 | EXPECT_EQ(quota::QuotaClient::kFileSystem | |
| 596 | quota::QuotaClient::kDatabase | |
| 597 | quota::QuotaClient::kAppcache | |
| 598 | quota::QuotaClient::kIndexedDatabase, |
| 599 | BrowsingDataRemover::GenerateQuotaClientMask( |
| 600 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
| 601 | BrowsingDataRemover::REMOVE_WEBSQL | |
| 602 | BrowsingDataRemover::REMOVE_APPCACHE | |
| 603 | BrowsingDataRemover::REMOVE_INDEXEDDB)); |
| 604 | } |
| 605 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 606 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { |
| 607 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 608 | new RemoveQuotaManagedDataTester()); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 609 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 610 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 611 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 612 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 613 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 614 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 615 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 616 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 617 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 618 | kClientFile)); |
| 619 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 620 | kClientFile)); |
| 621 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 622 | kClientFile)); |
| 623 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 624 | kClientFile)); |
| 625 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 626 | kClientFile)); |
| 627 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 628 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) { |
| 632 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 633 | new RemoveQuotaManagedDataTester()); |
| 634 | |
| 635 | tester->PopulateTestQuotaManagedTemporaryData(GetMockManager()); |
| 636 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 637 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 638 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 639 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 640 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 641 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 642 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 643 | kClientFile)); |
| 644 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 645 | kClientFile)); |
| 646 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 647 | kClientFile)); |
| 648 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 649 | kClientFile)); |
| 650 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 651 | kClientFile)); |
| 652 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 653 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) { |
| 657 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 658 | new RemoveQuotaManagedDataTester()); |
| 659 | |
| 660 | tester->PopulateTestQuotaManagedPersistentData(GetMockManager()); |
| 661 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 662 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 663 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 664 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 665 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 666 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 667 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 668 | kClientFile)); |
| 669 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 670 | kClientFile)); |
| 671 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 672 | kClientFile)); |
| 673 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 674 | kClientFile)); |
| 675 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 676 | kClientFile)); |
| 677 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 678 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) { |
| 682 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 683 | new RemoveQuotaManagedDataTester()); |
| 684 | |
| 685 | GetMockManager(); // Creates the QuotaManager instance. |
| 686 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 687 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 688 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 689 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 690 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 691 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 692 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 693 | kClientFile)); |
| 694 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 695 | kClientFile)); |
| 696 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 697 | kClientFile)); |
| 698 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 699 | kClientFile)); |
| 700 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 701 | kClientFile)); |
| 702 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 703 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 704 | } |
| 705 | |
[email protected] | ddb3982 | 2012-02-17 20:23:13 | [diff] [blame] | 706 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) { |
| 707 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 708 | new RemoveQuotaManagedDataTester()); |
| 709 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 710 | |
| 711 | // Remove Origin 1. |
| 712 | BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 713 | BrowsingDataRemover::REMOVE_APPCACHE | |
| 714 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
| 715 | BrowsingDataRemover::REMOVE_INDEXEDDB | |
| 716 | BrowsingDataRemover::REMOVE_WEBSQL, kOrigin1, tester.get()); |
| 717 | |
| 718 | EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | |
| 719 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
| 720 | BrowsingDataRemover::REMOVE_INDEXEDDB | |
| 721 | BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); |
| 722 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 723 | kClientFile)); |
| 724 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 725 | kClientFile)); |
| 726 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 727 | kClientFile)); |
| 728 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 729 | kClientFile)); |
| 730 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 731 | kClientFile)); |
| 732 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 733 | kClientFile)); |
| 734 | } |
| 735 | |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 736 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { |
| 737 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 738 | new RemoveQuotaManagedDataTester()); |
| 739 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 740 | |
| 741 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 742 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 743 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 744 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 745 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 746 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 747 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 748 | kClientFile)); |
| 749 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 750 | kClientFile)); |
| 751 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 752 | kClientFile)); |
| 753 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 754 | kClientFile)); |
| 755 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 756 | kClientFile)); |
| 757 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 758 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { |
| 762 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 763 | new RemoveQuotaManagedDataTester()); |
| 764 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 765 | |
| 766 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 767 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 768 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 769 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 770 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 771 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 772 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 773 | kClientFile)); |
| 774 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 775 | kClientFile)); |
| 776 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 777 | kClientFile)); |
| 778 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 779 | kClientFile)); |
| 780 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 781 | kClientFile)); |
| 782 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 783 | kClientFile)); |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { |
| 787 | // Protect kOrigin1. |
| 788 | scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
| 789 | new MockExtensionSpecialStoragePolicy; |
| 790 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 791 | GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); |
| 792 | |
| 793 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 794 | new RemoveQuotaManagedDataTester()); |
| 795 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 796 | |
| 797 | BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
[email protected] | 4647cbe | 2011-10-11 18:45:08 | [diff] [blame] | 798 | BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 799 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get()); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 800 | |
[email protected] | 8d7554d8 | 2011-12-13 17:11:08 | [diff] [blame] | 801 | EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA & |
[email protected] | 59eca0f | 2011-12-13 19:16:39 | [diff] [blame] | 802 | ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask()); |
[email protected] | 72f4086 | 2012-02-09 19:40:27 | [diff] [blame] | 803 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 804 | kClientFile)); |
| 805 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 806 | kClientFile)); |
| 807 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 808 | kClientFile)); |
| 809 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 810 | kClientFile)); |
| 811 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 812 | kClientFile)); |
| 813 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 814 | kClientFile)); |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | ddb3982 | 2012-02-17 20:23:13 | [diff] [blame] | 817 | TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) { |
| 818 | // Protect kOrigin1. |
| 819 | scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
| 820 | new MockExtensionSpecialStoragePolicy; |
| 821 | mock_policy->AddProtected(kOrigin1.GetOrigin()); |
| 822 | GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); |
| 823 | |
| 824 | scoped_ptr<RemoveQuotaManagedDataTester> tester( |
| 825 | new RemoveQuotaManagedDataTester()); |
| 826 | tester->PopulateTestQuotaManagedData(GetMockManager()); |
| 827 | |
| 828 | // Try to remove kOrigin1. Expect failure. |
| 829 | BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 830 | BrowsingDataRemover::REMOVE_APPCACHE | |
| 831 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
| 832 | BrowsingDataRemover::REMOVE_INDEXEDDB | |
| 833 | BrowsingDataRemover::REMOVE_WEBSQL, kOrigin1, tester.get()); |
| 834 | |
| 835 | EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | |
| 836 | BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
| 837 | BrowsingDataRemover::REMOVE_INDEXEDDB | |
| 838 | BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); |
| 839 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, |
| 840 | kClientFile)); |
| 841 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, |
| 842 | kClientFile)); |
| 843 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, |
| 844 | kClientFile)); |
| 845 | EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, |
| 846 | kClientFile)); |
| 847 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, |
| 848 | kClientFile)); |
| 849 | EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, |
| 850 | kClientFile)); |
| 851 | } |
| 852 | |
[email protected] | 8d4ec68 | 2012-02-17 12:20:17 | [diff] [blame] | 853 | TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) { |
| 854 | scoped_ptr<RemoveHistoryTester> tester( |
| 855 | new RemoveHistoryTester(GetProfile())); |
| 856 | |
| 857 | base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 858 | |
| 859 | tester->AddHistory(kOrigin1, base::Time::Now()); |
| 860 | tester->AddHistory(kOrigin2, two_hours_ago); |
| 861 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 862 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 863 | |
| 864 | BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 865 | BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); |
| 866 | |
| 867 | EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 868 | EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 869 | EXPECT_FALSE(tester->HistoryContainsURL(kOrigin2)); |
| 870 | } |
| 871 | |
| 872 | TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) { |
| 873 | scoped_ptr<RemoveHistoryTester> tester( |
| 874 | new RemoveHistoryTester(GetProfile())); |
| 875 | |
| 876 | base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
| 877 | |
| 878 | tester->AddHistory(kOrigin1, base::Time::Now()); |
| 879 | tester->AddHistory(kOrigin2, two_hours_ago); |
| 880 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 881 | ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 882 | |
| 883 | BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 884 | BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); |
| 885 | |
| 886 | EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 887 | EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 888 | EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 889 | } |