blob: 833fd24cd1f81a4dff05aa2e00ff4d233eae29ce [file] [log] [blame]
[email protected]e7e46732012-01-05 11:45:551// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9d4ca082011-05-30 16:39:412// 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]2261e7b72011-07-12 13:43:557#include <set>
[email protected]eb7974c2012-01-25 17:38:488#include <vector>
[email protected]2261e7b72011-07-12 13:43:559
[email protected]ade9abe2011-09-02 17:29:1210#include "base/bind.h"
[email protected]75b3ac912011-10-05 18:09:3011#include "base/bind_helpers.h"
[email protected]9d4ca082011-05-30 16:39:4112#include "base/message_loop.h"
[email protected]cdba46992011-06-07 11:51:3913#include "base/platform_file.h"
[email protected]2261e7b72011-07-12 13:43:5514#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
[email protected]9d4ca082011-05-30 16:39:4115#include "chrome/browser/history/history.h"
[email protected]dde7a5a2012-02-22 23:16:3416#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]8d7554d82011-12-13 17:11:0817#include "chrome/common/chrome_notification_types.h"
[email protected]dceaa912011-09-06 17:17:2318#include "chrome/common/pref_names.h"
[email protected]dde7a5a2012-02-22 23:16:3419#include "chrome/test/base/testing_browser_process.h"
[email protected]dceaa912011-09-06 17:17:2320#include "chrome/test/base/testing_pref_service.h"
[email protected]a4ff9eae2011-08-01 19:58:1621#include "chrome/test/base/testing_profile.h"
[email protected]8d7554d82011-12-13 17:11:0822#include "content/public/browser/notification_service.h"
[email protected]c38831a12011-10-28 12:44:4923#include "content/test/test_browser_thread.h"
[email protected]32cb7fb2012-03-22 22:41:1124#include "net/base/server_bound_cert_service.h"
25#include "net/base/server_bound_cert_store.h"
[email protected]eb7974c2012-01-25 17:38:4826#include "net/base/ssl_client_cert_type.h"
[email protected]aa84a7e2012-03-15 21:29:0627#include "net/cookies/cookie_monster.h"
[email protected]ade9abe2011-09-02 17:29:1228#include "net/url_request/url_request_context.h"
[email protected]acdff992011-09-02 18:06:2329#include "net/url_request/url_request_context_getter.h"
[email protected]9d4ca082011-05-30 16:39:4130#include "testing/gtest/include/gtest/gtest.h"
[email protected]cdba46992011-06-07 11:51:3931#include "webkit/fileapi/file_system_context.h"
[email protected]cdba46992011-06-07 11:51:3932#include "webkit/fileapi/file_system_file_util.h"
[email protected]94704172011-08-01 16:23:4033#include "webkit/fileapi/file_system_operation_context.h"
[email protected]cdba46992011-06-07 11:51:3934#include "webkit/fileapi/sandbox_mount_point_provider.h"
[email protected]94704172011-08-01 16:23:4035#include "webkit/quota/mock_quota_manager.h"
36#include "webkit/quota/quota_manager.h"
37#include "webkit/quota/quota_types.h"
[email protected]9d4ca082011-05-30 16:39:4138
[email protected]631bb742011-11-02 11:29:3939using content::BrowserThread;
40
[email protected]9d4ca082011-05-30 16:39:4141namespace {
42
[email protected]cdba46992011-06-07 11:51:3943const char kTestkOrigin1[] = "http://host1:1/";
44const char kTestkOrigin2[] = "http://host2:1/";
45const char kTestkOrigin3[] = "http://host3:1/";
46
47const GURL kOrigin1(kTestkOrigin1);
48const GURL kOrigin2(kTestkOrigin2);
49const GURL kOrigin3(kTestkOrigin3);
50
[email protected]72f40862012-02-09 19:40:2751const quota::StorageType kTemporary = quota::kStorageTypeTemporary;
52const quota::StorageType kPersistent = quota::kStorageTypePersistent;
53
54const quota::QuotaClient::ID kClientFile = quota::QuotaClient::kFileSystem;
55const quota::QuotaClient::ID kClientDB = quota::QuotaClient::kIndexedDatabase;
56
[email protected]8d4ec682012-02-17 12:20:1757} // namespace
58
[email protected]f5f665fd62011-06-01 11:39:1859class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
[email protected]9d4ca082011-05-30 16:39:4160 public:
[email protected]ade9abe2011-09-02 17:29:1261 BrowsingDataRemoverTester()
62 : start_(false),
63 already_quit_(false) {}
[email protected]f5f665fd62011-06-01 11:39:1864 virtual ~BrowsingDataRemoverTester() {}
65
66 void BlockUntilNotified() {
[email protected]ade9abe2011-09-02 17:29:1267 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]9d4ca082011-05-30 16:39:4175 }
[email protected]9d4ca082011-05-30 16:39:4176
77 protected:
[email protected]f5f665fd62011-06-01 11:39:1878 // BrowsingDataRemover::Observer implementation.
79 virtual void OnBrowsingDataRemoverDone() {
80 Notify();
81 }
82
83 void Notify() {
[email protected]ade9abe2011-09-02 17:29:1284 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]f5f665fd62011-06-01 11:39:1892 }
93
94 private:
[email protected]ade9abe2011-09-02 17:29:1295 // Helps prevent from running message_loop, if the callback invoked
96 // immediately.
97 bool start_;
98 bool already_quit_;
99
[email protected]f5f665fd62011-06-01 11:39:18100 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester);
101};
102
[email protected]94704172011-08-01 16:23:40103// Testers -------------------------------------------------------------------
104
[email protected]ade9abe2011-09-02 17:29:12105class RemoveCookieTester : public BrowsingDataRemoverTester {
106 public:
[email protected]dde7a5a2012-02-22 23:16:34107 RemoveCookieTester() : get_cookie_success_(false) {
[email protected]ade9abe2011-09-02 17:29:12108 }
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]dde7a5a2012-02-22 23:16:34129 protected:
130 void SetMonster(net::CookieStore* monster) {
131 monster_ = monster;
132 }
133
[email protected]ade9abe2011-09-02 17:29:12134 private:
135 void GetCookieCallback(const std::string& cookies) {
136 if (cookies == "A=1") {
137 get_cookie_success_ = true;
138 } else {
[email protected]8d7554d82011-12-13 17:11:08139 EXPECT_EQ("", cookies);
[email protected]ade9abe2011-09-02 17:29:12140 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]dde7a5a2012-02-22 23:16:34157class 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]39bbe372012-02-24 02:46:16166#if defined(ENABLE_SAFE_BROWSING)
[email protected]dde7a5a2012-02-22 23:16:34167class 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]39bbe372012-02-24 02:46:16197#endif
[email protected]dde7a5a2012-02-22 23:16:34198
[email protected]9c4eff22012-03-20 22:42:29199class RemoveServerBoundCertTester : public BrowsingDataRemoverTester {
[email protected]eb7974c2012-01-25 17:38:48200 public:
[email protected]9c4eff22012-03-20 22:42:29201 explicit RemoveServerBoundCertTester(TestingProfile* profile) {
[email protected]eb7974c2012-01-25 17:38:48202 profile->CreateRequestContext();
[email protected]9c4eff22012-03-20 22:42:29203 server_bound_cert_service_ = profile->GetRequestContext()->
204 GetURLRequestContext()->server_bound_cert_service();
[email protected]eb7974c2012-01-25 17:38:48205 }
206
[email protected]9c4eff22012-03-20 22:42:29207 int ServerBoundCertCount() {
208 return server_bound_cert_service_->cert_count();
[email protected]eb7974c2012-01-25 17:38:48209 }
210
[email protected]9c4eff22012-03-20 22:42:29211 // Add a server bound cert for |server| with specific creation and expiry
[email protected]eb7974c2012-01-25 17:38:48212 // times. The cert and key data will be filled with dummy values.
[email protected]9c4eff22012-03-20 22:42:29213 void AddServerBoundCertWithTimes(const std::string& server_identifier,
[email protected]eb7974c2012-01-25 17:38:48214 base::Time creation_time,
215 base::Time expiration_time) {
[email protected]9c4eff22012-03-20 22:42:29216 GetCertStore()->SetServerBoundCert(server_identifier,
217 net::CLIENT_CERT_RSA_SIGN, creation_time,
218 expiration_time, "a", "b");
[email protected]eb7974c2012-01-25 17:38:48219 }
220
[email protected]9c4eff22012-03-20 22:42:29221 // Add a server bound cert for |server|, with the current time as the
[email protected]eb7974c2012-01-25 17:38:48222 // creation time. The cert and key data will be filled with dummy values.
[email protected]9c4eff22012-03-20 22:42:29223 void AddServerBoundCert(const std::string& server_identifier) {
[email protected]eb7974c2012-01-25 17:38:48224 base::Time now = base::Time::Now();
[email protected]9c4eff22012-03-20 22:42:29225 AddServerBoundCertWithTimes(server_identifier,
[email protected]eb7974c2012-01-25 17:38:48226 now,
227 now + base::TimeDelta::FromDays(1));
228 }
229
[email protected]9c4eff22012-03-20 22:42:29230 net::ServerBoundCertStore* GetCertStore() {
231 return server_bound_cert_service_->GetCertStore();
[email protected]eb7974c2012-01-25 17:38:48232 }
233
234 private:
[email protected]9c4eff22012-03-20 22:42:29235 net::ServerBoundCertService* server_bound_cert_service_;
[email protected]eb7974c2012-01-25 17:38:48236
237 net::SSLClientCertType type_;
238 std::string key_;
239 std::string cert_;
240
[email protected]9c4eff22012-03-20 22:42:29241 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester);
[email protected]eb7974c2012-01-25 17:38:48242};
243
[email protected]f5f665fd62011-06-01 11:39:18244class 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]9d4ca082011-05-30 16:39:41252 // Returns true, if the given URL exists in the history service.
[email protected]f5f665fd62011-06-01 11:39:18253 bool HistoryContainsURL(const GURL& url) {
254 history_service_->QueryURL(
[email protected]9d4ca082011-05-30 16:39:41255 url,
256 true,
257 &consumer_,
[email protected]75b3ac912011-10-05 18:09:30258 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
259 base::Unretained(this)));
[email protected]f5f665fd62011-06-01 11:39:18260 BlockUntilNotified();
[email protected]9d4ca082011-05-30 16:39:41261 return query_url_success_;
262 }
263
[email protected]f5f665fd62011-06-01 11:39:18264 void AddHistory(const GURL& url, base::Time time) {
[email protected]2905f742011-10-13 03:51:58265 history_service_->AddPage(url, time, NULL, 0, GURL(),
266 content::PAGE_TRANSITION_LINK, history::RedirectList(),
267 history::SOURCE_BROWSED, false);
[email protected]9d4ca082011-05-30 16:39:41268 }
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]f5f665fd62011-06-01 11:39:18277 Notify();
[email protected]9d4ca082011-05-30 16:39:41278 }
279
[email protected]9d4ca082011-05-30 16:39:41280
[email protected]f5f665fd62011-06-01 11:39:18281 // For History requests.
[email protected]9d4ca082011-05-30 16:39:41282 CancelableRequestConsumer consumer_;
283 bool query_url_success_;
[email protected]f5f665fd62011-06-01 11:39:18284
285 // TestingProfile owns the history service; we shouldn't delete it.
286 HistoryService* history_service_;
287
288 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
[email protected]9d4ca082011-05-30 16:39:41289};
290
[email protected]94704172011-08-01 16:23:40291class RemoveQuotaManagedDataTester : public BrowsingDataRemoverTester {
[email protected]cdba46992011-06-07 11:51:39292 public:
[email protected]94704172011-08-01 16:23:40293 RemoveQuotaManagedDataTester() {}
294 virtual ~RemoveQuotaManagedDataTester() {}
[email protected]cdba46992011-06-07 11:51:39295
[email protected]94704172011-08-01 16:23:40296 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]cdba46992011-06-07 11:51:39303 }
304
[email protected]94704172011-08-01 16:23:40305 void PopulateTestQuotaManagedPersistentData(
306 quota::MockQuotaManager* manager) {
[email protected]72f40862012-02-09 19:40:27307 manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time());
308 manager->AddOrigin(kOrigin3, kPersistent, kClientFile,
[email protected]94704172011-08-01 16:23:40309 base::Time::Now() - base::TimeDelta::FromDays(1));
310
[email protected]72f40862012-02-09 19:40:27311 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]cdba46992011-06-07 11:51:39314 }
315
[email protected]94704172011-08-01 16:23:40316 void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) {
[email protected]72f40862012-02-09 19:40:27317 manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now());
318 manager->AddOrigin(kOrigin3, kTemporary, kClientFile,
[email protected]94704172011-08-01 16:23:40319 base::Time::Now() - base::TimeDelta::FromDays(1));
[email protected]cdba46992011-06-07 11:51:39320
[email protected]72f40862012-02-09 19:40:27321 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]cdba46992011-06-07 11:51:39324 }
325
326 private:
[email protected]94704172011-08-01 16:23:40327 DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester);
[email protected]cdba46992011-06-07 11:51:39328};
329
[email protected]94704172011-08-01 16:23:40330// Test Class ----------------------------------------------------------------
331
[email protected]8d7554d82011-12-13 17:11:08332class BrowsingDataRemoverTest : public testing::Test,
333 public content::NotificationObserver {
[email protected]f5f665fd62011-06-01 11:39:18334 public:
[email protected]cdba46992011-06-07 11:51:39335 BrowsingDataRemoverTest()
336 : ui_thread_(BrowserThread::UI, &message_loop_),
337 db_thread_(BrowserThread::DB, &message_loop_),
[email protected]e1dd5622011-12-20 12:28:58338 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
[email protected]cdba46992011-06-07 11:51:39339 file_thread_(BrowserThread::FILE, &message_loop_),
[email protected]55eb70e762012-02-20 17:38:39340 file_user_blocking_thread_(
341 BrowserThread::FILE_USER_BLOCKING, &message_loop_),
[email protected]cdba46992011-06-07 11:51:39342 io_thread_(BrowserThread::IO, &message_loop_),
343 profile_(new TestingProfile()) {
[email protected]8d7554d82011-12-13 17:11:08344 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
345 content::Source<Profile>(profile_.get()));
[email protected]cdba46992011-06-07 11:51:39346 }
347
348 virtual ~BrowsingDataRemoverTest() {
349 }
350
351 void TearDown() {
[email protected]c1fff072012-02-24 23:38:12352 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
[email protected]cdba46992011-06-07 11:51:39353 // 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]9d4ca082011-05-30 16:39:41360
[email protected]f5f665fd62011-06-01 11:39:18361 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
[email protected]f5f665fd62011-06-01 11:39:18362 int remove_mask,
363 BrowsingDataRemoverTester* tester) {
[email protected]ade9abe2011-09-02 17:29:12364 BrowsingDataRemover* remover = new BrowsingDataRemover(
365 profile_.get(), period,
366 base::Time::Now() + base::TimeDelta::FromMilliseconds(10));
[email protected]55eb70e762012-02-20 17:38:39367 remover->OverrideQuotaManagerForTesting(GetMockManager());
[email protected]f5f665fd62011-06-01 11:39:18368 remover->AddObserver(tester);
[email protected]9d4ca082011-05-30 16:39:41369
[email protected]8d7554d82011-12-13 17:11:08370 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
371
[email protected]f5f665fd62011-06-01 11:39:18372 // BrowsingDataRemover deletes itself when it completes.
373 remover->Remove(remove_mask);
374 tester->BlockUntilNotified();
375 }
[email protected]9d4ca082011-05-30 16:39:41376
[email protected]8d4ec682012-02-17 12:20:17377 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]55eb70e762012-02-20 17:38:39384 remover->OverrideQuotaManagerForTesting(GetMockManager());
[email protected]8d4ec682012-02-17 12:20:17385 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]f5f665fd62011-06-01 11:39:18394 TestingProfile* GetProfile() {
[email protected]cdba46992011-06-07 11:51:39395 return profile_.get();
[email protected]f5f665fd62011-06-01 11:39:18396 }
[email protected]9d4ca082011-05-30 16:39:41397
[email protected]8d7554d82011-12-13 17:11:08398 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]94704172011-08-01 16:23:40406 quota::MockQuotaManager* GetMockManager() {
[email protected]55eb70e762012-02-20 17:38:39407 if (!quota_manager_) {
408 quota_manager_ = new quota::MockQuotaManager(
[email protected]94704172011-08-01 16:23:40409 profile_->IsOffTheRecord(),
410 profile_->GetPath(),
411 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
412 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
[email protected]55eb70e762012-02-20 17:38:39413 profile_->GetExtensionSpecialStoragePolicy());
[email protected]94704172011-08-01 16:23:40414 }
[email protected]55eb70e762012-02-20 17:38:39415 return quota_manager_;
[email protected]94704172011-08-01 16:23:40416 }
417
[email protected]8d7554d82011-12-13 17:11:08418 // 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]f5f665fd62011-06-01 11:39:18433 private:
[email protected]8d7554d82011-12-13 17:11:08434 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
435 content::NotificationRegistrar registrar_;
436
[email protected]cdba46992011-06-07 11:51:39437 // 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]f5f665fd62011-06-01 11:39:18439 MessageLoopForUI message_loop_;
[email protected]c38831a12011-10-28 12:44:49440 content::TestBrowserThread ui_thread_;
441 content::TestBrowserThread db_thread_;
442 content::TestBrowserThread webkit_thread_;
443 content::TestBrowserThread file_thread_;
[email protected]55eb70e762012-02-20 17:38:39444 content::TestBrowserThread file_user_blocking_thread_;
[email protected]c38831a12011-10-28 12:44:49445 content::TestBrowserThread io_thread_;
[email protected]cdba46992011-06-07 11:51:39446 scoped_ptr<TestingProfile> profile_;
[email protected]55eb70e762012-02-20 17:38:39447 scoped_refptr<quota::MockQuotaManager> quota_manager_;
[email protected]f5f665fd62011-06-01 11:39:18448
449 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
450};
451
[email protected]94704172011-08-01 16:23:40452// Tests ---------------------------------------------------------------------
453
[email protected]ade9abe2011-09-02 17:29:12454TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
[email protected]dde7a5a2012-02-22 23:16:34455 scoped_ptr<RemoveProfileCookieTester> tester(
456 new RemoveProfileCookieTester(GetProfile()));
[email protected]ade9abe2011-09-02 17:29:12457
458 tester->AddCookie();
459 ASSERT_TRUE(tester->ContainsCookie());
460
461 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08462 BrowsingDataRemover::REMOVE_COOKIES, tester.get());
[email protected]ade9abe2011-09-02 17:29:12463
[email protected]8d7554d82011-12-13 17:11:08464 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
[email protected]ade9abe2011-09-02 17:29:12465 EXPECT_FALSE(tester->ContainsCookie());
466}
467
[email protected]dde7a5a2012-02-22 23:16:34468TEST_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]39bbe372012-02-24 02:46:16482#if defined(ENABLE_SAFE_BROWSING)
[email protected]dde7a5a2012-02-22 23:16:34483TEST_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
497TEST_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]39bbe372012-02-24 02:46:16512#endif
[email protected]dde7a5a2012-02-22 23:16:34513
[email protected]9c4eff22012-03-20 22:42:29514TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) {
515 scoped_ptr<RemoveServerBoundCertTester> tester(
516 new RemoveServerBoundCertTester(GetProfile()));
[email protected]eb7974c2012-01-25 17:38:48517
[email protected]9c4eff22012-03-20 22:42:29518 tester->AddServerBoundCert(kTestkOrigin1);
519 EXPECT_EQ(1, tester->ServerBoundCertCount());
[email protected]eb7974c2012-01-25 17:38:48520
521 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]9c4eff22012-03-20 22:42:29522 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get());
[email protected]eb7974c2012-01-25 17:38:48523
[email protected]9c4eff22012-03-20 22:42:29524 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
525 EXPECT_EQ(0, tester->ServerBoundCertCount());
[email protected]eb7974c2012-01-25 17:38:48526}
527
[email protected]9c4eff22012-03-20 22:42:29528TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) {
529 scoped_ptr<RemoveServerBoundCertTester> tester(
530 new RemoveServerBoundCertTester(GetProfile()));
[email protected]eb7974c2012-01-25 17:38:48531
532 base::Time now = base::Time::Now();
[email protected]9c4eff22012-03-20 22:42:29533 tester->AddServerBoundCert(kTestkOrigin1);
534 tester->AddServerBoundCertWithTimes(kTestkOrigin2,
[email protected]eb7974c2012-01-25 17:38:48535 now - base::TimeDelta::FromHours(2),
536 now);
[email protected]9c4eff22012-03-20 22:42:29537 EXPECT_EQ(2, tester->ServerBoundCertCount());
[email protected]eb7974c2012-01-25 17:38:48538
539 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
[email protected]9c4eff22012-03-20 22:42:29540 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, tester.get());
[email protected]eb7974c2012-01-25 17:38:48541
[email protected]9c4eff22012-03-20 22:42:29542 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]eb7974c2012-01-25 17:38:48547}
548
[email protected]f5f665fd62011-06-01 11:39:18549TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
550 scoped_ptr<RemoveHistoryTester> tester(
551 new RemoveHistoryTester(GetProfile()));
552
[email protected]cdba46992011-06-07 11:51:39553 tester->AddHistory(kOrigin1, base::Time::Now());
554 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
[email protected]f5f665fd62011-06-01 11:39:18555
556 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]ade9abe2011-09-02 17:29:12557 BrowsingDataRemover::REMOVE_HISTORY, tester.get());
[email protected]f5f665fd62011-06-01 11:39:18558
[email protected]8d7554d82011-12-13 17:11:08559 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
[email protected]cdba46992011-06-07 11:51:39560 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1));
[email protected]f5f665fd62011-06-01 11:39:18561}
562
563TEST_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]cdba46992011-06-07 11:51:39569 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]f5f665fd62011-06-01 11:39:18573
574 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
[email protected]ade9abe2011-09-02 17:29:12575 BrowsingDataRemover::REMOVE_HISTORY, tester.get());
[email protected]f5f665fd62011-06-01 11:39:18576
[email protected]8d7554d82011-12-13 17:11:08577 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
[email protected]cdba46992011-06-07 11:51:39578 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1));
579 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
580}
581
[email protected]72f40862012-02-09 19:40:27582TEST_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]94704172011-08-01 16:23:40606TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
607 scoped_ptr<RemoveQuotaManagedDataTester> tester(
608 new RemoveQuotaManagedDataTester());
[email protected]cdba46992011-06-07 11:51:39609
[email protected]94704172011-08-01 16:23:40610 tester->PopulateTestQuotaManagedData(GetMockManager());
611 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08612 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39613 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40614
[email protected]8d7554d82011-12-13 17:11:08615 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39616 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27617 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]94704172011-08-01 16:23:40629}
630
631TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
632 scoped_ptr<RemoveQuotaManagedDataTester> tester(
633 new RemoveQuotaManagedDataTester());
634
635 tester->PopulateTestQuotaManagedTemporaryData(GetMockManager());
636 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08637 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39638 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40639
[email protected]8d7554d82011-12-13 17:11:08640 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39641 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27642 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]94704172011-08-01 16:23:40654}
655
656TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
657 scoped_ptr<RemoveQuotaManagedDataTester> tester(
658 new RemoveQuotaManagedDataTester());
659
660 tester->PopulateTestQuotaManagedPersistentData(GetMockManager());
661 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08662 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39663 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40664
[email protected]8d7554d82011-12-13 17:11:08665 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39666 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27667 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]94704172011-08-01 16:23:40679}
680
681TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
682 scoped_ptr<RemoveQuotaManagedDataTester> tester(
683 new RemoveQuotaManagedDataTester());
684
685 GetMockManager(); // Creates the QuotaManager instance.
686 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08687 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39688 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40689
[email protected]8d7554d82011-12-13 17:11:08690 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39691 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27692 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]94704172011-08-01 16:23:40704}
705
[email protected]ddb39822012-02-17 20:23:13706TEST_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]94704172011-08-01 16:23:40736TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
737 scoped_ptr<RemoveQuotaManagedDataTester> tester(
738 new RemoveQuotaManagedDataTester());
739 tester->PopulateTestQuotaManagedData(GetMockManager());
740
741 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
[email protected]4647cbe2011-10-11 18:45:08742 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39743 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40744
[email protected]8d7554d82011-12-13 17:11:08745 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39746 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27747 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]94704172011-08-01 16:23:40759}
760
761TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
762 scoped_ptr<RemoveQuotaManagedDataTester> tester(
763 new RemoveQuotaManagedDataTester());
764 tester->PopulateTestQuotaManagedData(GetMockManager());
765
766 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
[email protected]4647cbe2011-10-11 18:45:08767 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39768 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]94704172011-08-01 16:23:40769
[email protected]8d7554d82011-12-13 17:11:08770 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39771 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27772 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]94704172011-08-01 16:23:40784}
785
786TEST_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]cdba46992011-06-07 11:51:39796
797 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
[email protected]4647cbe2011-10-11 18:45:08798 BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39799 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
[email protected]cdba46992011-06-07 11:51:39800
[email protected]8d7554d82011-12-13 17:11:08801 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
[email protected]59eca0f2011-12-13 19:16:39802 ~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
[email protected]72f40862012-02-09 19:40:27803 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]2261e7b72011-07-12 13:43:55815}
816
[email protected]ddb39822012-02-17 20:23:13817TEST_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]8d4ec682012-02-17 12:20:17853TEST_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
872TEST_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}