1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/browsing_data_remover.h"
#include <set>
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
#include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
#include "chrome/browser/history/history.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
#include "content/test/test_browser_thread.h"
#include "net/base/cookie_monster.h"
#include "net/base/origin_bound_cert_service.h"
#include "net/base/origin_bound_cert_store.h"
#include "net/base/ssl_client_cert_type.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/quota/mock_quota_manager.h"
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/quota_types.h"
using content::BrowserThread;
namespace {
const char kTestkOrigin1[] = "http://host1:1/";
const char kTestkOrigin2[] = "http://host2:1/";
const char kTestkOrigin3[] = "http://host3:1/";
const GURL kOrigin1(kTestkOrigin1);
const GURL kOrigin2(kTestkOrigin2);
const GURL kOrigin3(kTestkOrigin3);
class BrowsingDataRemoverTester : public BrowsingDataRemover::Observer {
public:
BrowsingDataRemoverTester()
: start_(false),
already_quit_(false) {}
virtual ~BrowsingDataRemoverTester() {}
void BlockUntilNotified() {
if (!already_quit_) {
DCHECK(!start_);
start_ = true;
MessageLoop::current()->Run();
} else {
DCHECK(!start_);
already_quit_ = false;
}
}
protected:
// BrowsingDataRemover::Observer implementation.
virtual void OnBrowsingDataRemoverDone() {
Notify();
}
void Notify() {
if (start_) {
DCHECK(!already_quit_);
MessageLoop::current()->Quit();
start_ = false;
} else {
DCHECK(!already_quit_);
already_quit_ = true;
}
}
private:
// Helps prevent from running message_loop, if the callback invoked
// immediately.
bool start_;
bool already_quit_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTester);
};
// Testers -------------------------------------------------------------------
class RemoveCookieTester : public BrowsingDataRemoverTester {
public:
explicit RemoveCookieTester(TestingProfile* profile)
: get_cookie_success_(false) {
profile->CreateRequestContext();
monster_ = profile->GetRequestContext()->GetURLRequestContext()->
cookie_store()->GetCookieMonster();
}
// Returns true, if the given cookie exists in the cookie store.
bool ContainsCookie() {
get_cookie_success_ = false;
monster_->GetCookiesWithOptionsAsync(
kOrigin1, net::CookieOptions(),
base::Bind(&RemoveCookieTester::GetCookieCallback,
base::Unretained(this)));
BlockUntilNotified();
return get_cookie_success_;
}
void AddCookie() {
monster_->SetCookieWithOptionsAsync(
kOrigin1, "A=1", net::CookieOptions(),
base::Bind(&RemoveCookieTester::SetCookieCallback,
base::Unretained(this)));
BlockUntilNotified();
}
private:
void GetCookieCallback(const std::string& cookies) {
if (cookies == "A=1") {
get_cookie_success_ = true;
} else {
EXPECT_EQ("", cookies);
get_cookie_success_ = false;
}
Notify();
}
void SetCookieCallback(bool result) {
ASSERT_TRUE(result);
Notify();
}
bool get_cookie_success_;
net::CookieStore* monster_;
DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
};
class RemoveOriginBoundCertTester : public BrowsingDataRemoverTester {
public:
explicit RemoveOriginBoundCertTester(TestingProfile* profile) {
profile->CreateRequestContext();
ob_cert_service_ = profile->GetRequestContext()->GetURLRequestContext()->
origin_bound_cert_service();
}
int OriginBoundCertCount() {
return ob_cert_service_->cert_count();
}
// Add an origin bound cert for |origin| with specific creation and expiry
// times. The cert and key data will be filled with dummy values.
void AddOriginBoundCertWithTimes(const std::string& origin,
base::Time creation_time,
base::Time expiration_time) {
GetCertStore()->SetOriginBoundCert(origin, net::CLIENT_CERT_RSA_SIGN,
creation_time, expiration_time,
"a", "b");
}
// Add an origin bound cert for |origin|, with the current time as the
// creation time. The cert and key data will be filled with dummy values.
void AddOriginBoundCert(const std::string& origin) {
base::Time now = base::Time::Now();
AddOriginBoundCertWithTimes(origin,
now,
now + base::TimeDelta::FromDays(1));
}
net::OriginBoundCertStore* GetCertStore() {
return ob_cert_service_->GetCertStore();
}
private:
net::OriginBoundCertService* ob_cert_service_;
net::SSLClientCertType type_;
std::string key_;
std::string cert_;
DISALLOW_COPY_AND_ASSIGN(RemoveOriginBoundCertTester);
};
class RemoveHistoryTester : public BrowsingDataRemoverTester {
public:
explicit RemoveHistoryTester(TestingProfile* profile)
: query_url_success_(false) {
profile->CreateHistoryService(true, false);
history_service_ = profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
}
// Returns true, if the given URL exists in the history service.
bool HistoryContainsURL(const GURL& url) {
history_service_->QueryURL(
url,
true,
&consumer_,
base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
base::Unretained(this)));
BlockUntilNotified();
return query_url_success_;
}
void AddHistory(const GURL& url, base::Time time) {
history_service_->AddPage(url, time, NULL, 0, GURL(),
content::PAGE_TRANSITION_LINK, history::RedirectList(),
history::SOURCE_BROWSED, false);
}
private:
// Callback for HistoryService::QueryURL.
void SaveResultAndQuit(HistoryService::Handle,
bool success,
const history::URLRow*,
history::VisitVector*) {
query_url_success_ = success;
Notify();
}
// For History requests.
CancelableRequestConsumer consumer_;
bool query_url_success_;
// TestingProfile owns the history service; we shouldn't delete it.
HistoryService* history_service_;
DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
};
class RemoveQuotaManagedDataTester : public BrowsingDataRemoverTester {
public:
RemoveQuotaManagedDataTester() {}
virtual ~RemoveQuotaManagedDataTester() {}
void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) {
// Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent
// quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2
// is modified at the beginning of time, and kOrigin3 is modified one day
// ago.
PopulateTestQuotaManagedPersistentData(manager);
PopulateTestQuotaManagedTemporaryData(manager);
}
void PopulateTestQuotaManagedPersistentData(
quota::MockQuotaManager* manager) {
manager->AddOrigin(kOrigin2, quota::kStorageTypePersistent,
base::Time());
manager->AddOrigin(kOrigin3, quota::kStorageTypePersistent,
base::Time::Now() - base::TimeDelta::FromDays(1));
EXPECT_FALSE(manager->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_TRUE(manager->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_TRUE(manager->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) {
manager->AddOrigin(kOrigin1, quota::kStorageTypeTemporary,
base::Time::Now());
manager->AddOrigin(kOrigin3, quota::kStorageTypeTemporary,
base::Time::Now() - base::TimeDelta::FromDays(1));
EXPECT_TRUE(manager->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(manager->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_TRUE(manager->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
}
private:
DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester);
};
// Test Class ----------------------------------------------------------------
class BrowsingDataRemoverTest : public testing::Test,
public content::NotificationObserver {
public:
BrowsingDataRemoverTest()
: ui_thread_(BrowserThread::UI, &message_loop_),
db_thread_(BrowserThread::DB, &message_loop_),
webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_),
profile_(new TestingProfile()) {
registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
content::Source<Profile>(profile_.get()));
}
virtual ~BrowsingDataRemoverTest() {
}
void TearDown() {
// TestingProfile contains a WebKitContext. WebKitContext's destructor
// posts a message to the WEBKIT thread to delete some of its member
// variables. We need to ensure that the profile is destroyed, and that
// the message loop is cleared out, before destroying the threads and loop.
// Otherwise we leak memory.
profile_.reset();
message_loop_.RunAllPending();
}
void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
int remove_mask,
BrowsingDataRemoverTester* tester) {
BrowsingDataRemover* remover = new BrowsingDataRemover(
profile_.get(), period,
base::Time::Now() + base::TimeDelta::FromMilliseconds(10));
remover->AddObserver(tester);
called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
// BrowsingDataRemover deletes itself when it completes.
remover->Remove(remove_mask);
tester->BlockUntilNotified();
}
TestingProfile* GetProfile() {
return profile_.get();
}
base::Time GetBeginTime() {
return called_with_details_->removal_begin;
}
int GetRemovalMask() {
return called_with_details_->removal_mask;
}
quota::MockQuotaManager* GetMockManager() {
if (profile_->GetQuotaManager() == NULL) {
profile_->SetQuotaManager(new quota::MockQuotaManager(
profile_->IsOffTheRecord(),
profile_->GetPath(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
profile_->GetExtensionSpecialStoragePolicy()));
}
return (quota::MockQuotaManager*) profile_->GetQuotaManager();
}
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
// We're not taking ownership of the details object, but storing a copy of
// it locally.
called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
*content::Details<BrowsingDataRemover::NotificationDetails>(
details).ptr()));
registrar_.RemoveAll();
}
private:
scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
content::NotificationRegistrar registrar_;
// message_loop_, as well as all the threads associated with it must be
// defined before profile_ to prevent explosions. Oh how I love C++.
MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
content::TestBrowserThread webkit_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
scoped_ptr<TestingProfile> profile_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
};
// Tests ---------------------------------------------------------------------
TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
scoped_ptr<RemoveCookieTester> tester(
new RemoveCookieTester(GetProfile()));
tester->AddCookie();
ASSERT_TRUE(tester->ContainsCookie());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_COOKIES, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
EXPECT_FALSE(tester->ContainsCookie());
}
TEST_F(BrowsingDataRemoverTest, RemoveOriginBoundCertForever) {
scoped_ptr<RemoveOriginBoundCertTester> tester(
new RemoveOriginBoundCertTester(GetProfile()));
tester->AddOriginBoundCert(kTestkOrigin1);
EXPECT_EQ(1, tester->OriginBoundCertCount());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, GetRemovalMask());
EXPECT_EQ(0, tester->OriginBoundCertCount());
}
TEST_F(BrowsingDataRemoverTest, RemoveOriginBoundCertLastHour) {
scoped_ptr<RemoveOriginBoundCertTester> tester(
new RemoveOriginBoundCertTester(GetProfile()));
base::Time now = base::Time::Now();
tester->AddOriginBoundCert(kTestkOrigin1);
tester->AddOriginBoundCertWithTimes(kTestkOrigin2,
now - base::TimeDelta::FromHours(2),
now);
EXPECT_EQ(2, tester->OriginBoundCertCount());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_ORIGIN_BOUND_CERTS, GetRemovalMask());
EXPECT_EQ(1, tester->OriginBoundCertCount());
std::vector<net::OriginBoundCertStore::OriginBoundCert> certs;
tester->GetCertStore()->GetAllOriginBoundCerts(&certs);
EXPECT_EQ(kTestkOrigin2, certs[0].origin());
}
TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
scoped_ptr<RemoveHistoryTester> tester(
new RemoveHistoryTester(GetProfile()));
tester->AddHistory(kOrigin1, base::Time::Now());
ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_HISTORY, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1));
}
TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
scoped_ptr<RemoveHistoryTester> tester(
new RemoveHistoryTester(GetProfile()));
base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
tester->AddHistory(kOrigin1, base::Time::Now());
tester->AddHistory(kOrigin2, two_hours_ago);
ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1));
ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2));
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_HISTORY, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1));
EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedTemporaryData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedPersistentData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
GetMockManager(); // Creates the QuotaManager instance.
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
// Protect kOrigin1.
scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
new MockExtensionSpecialStoragePolicy;
mock_policy->AddProtected(kOrigin1.GetOrigin());
GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy);
scoped_ptr<RemoveQuotaManagedDataTester> tester(
new RemoveQuotaManagedDataTester());
tester->PopulateTestQuotaManagedData(GetMockManager());
BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, tester.get());
EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA, GetRemovalMask());
EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypeTemporary));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2,
quota::kStorageTypePersistent));
EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3,
quota::kStorageTypePersistent));
}
} // namespace
|