OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data_remover.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" | 13 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" |
14 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/testing_pref_service.h" | 17 #include "chrome/test/base/testing_pref_service.h" |
17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/browser/notification_service.h" |
18 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
19 #include "net/base/cookie_monster.h" | 21 #include "net/base/cookie_monster.h" |
20 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
21 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "webkit/fileapi/file_system_context.h" | 25 #include "webkit/fileapi/file_system_context.h" |
24 #include "webkit/fileapi/file_system_file_util.h" | 26 #include "webkit/fileapi/file_system_file_util.h" |
25 #include "webkit/fileapi/file_system_operation_context.h" | 27 #include "webkit/fileapi/file_system_operation_context.h" |
26 #include "webkit/fileapi/file_system_path_manager.h" | 28 #include "webkit/fileapi/file_system_path_manager.h" |
27 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 29 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EXPECT_TRUE(manager->OriginHasData(kOrigin3, | 229 EXPECT_TRUE(manager->OriginHasData(kOrigin3, |
228 quota::kStorageTypeTemporary)); | 230 quota::kStorageTypeTemporary)); |
229 } | 231 } |
230 | 232 |
231 private: | 233 private: |
232 DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester); | 234 DISALLOW_COPY_AND_ASSIGN(RemoveQuotaManagedDataTester); |
233 }; | 235 }; |
234 | 236 |
235 // Test Class ---------------------------------------------------------------- | 237 // Test Class ---------------------------------------------------------------- |
236 | 238 |
237 class BrowsingDataRemoverTest : public testing::Test { | 239 class BrowsingDataRemoverTest : public testing::Test, |
| 240 public content::NotificationObserver { |
238 public: | 241 public: |
239 BrowsingDataRemoverTest() | 242 BrowsingDataRemoverTest() |
240 : ui_thread_(BrowserThread::UI, &message_loop_), | 243 : ui_thread_(BrowserThread::UI, &message_loop_), |
241 db_thread_(BrowserThread::DB, &message_loop_), | 244 db_thread_(BrowserThread::DB, &message_loop_), |
242 webkit_thread_(BrowserThread::WEBKIT, &message_loop_), | 245 webkit_thread_(BrowserThread::WEBKIT, &message_loop_), |
243 file_thread_(BrowserThread::FILE, &message_loop_), | 246 file_thread_(BrowserThread::FILE, &message_loop_), |
244 io_thread_(BrowserThread::IO, &message_loop_), | 247 io_thread_(BrowserThread::IO, &message_loop_), |
245 profile_(new TestingProfile()) { | 248 profile_(new TestingProfile()) { |
| 249 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, |
| 250 content::Source<Profile>(profile_->GetOriginalProfile())); |
246 } | 251 } |
247 | 252 |
248 virtual ~BrowsingDataRemoverTest() { | 253 virtual ~BrowsingDataRemoverTest() { |
249 } | 254 } |
250 | 255 |
251 void TearDown() { | 256 void TearDown() { |
252 // TestingProfile contains a WebKitContext. WebKitContext's destructor | 257 // TestingProfile contains a WebKitContext. WebKitContext's destructor |
253 // posts a message to the WEBKIT thread to delete some of its member | 258 // posts a message to the WEBKIT thread to delete some of its member |
254 // variables. We need to ensure that the profile is destroyed, and that | 259 // variables. We need to ensure that the profile is destroyed, and that |
255 // the message loop is cleared out, before destroying the threads and loop. | 260 // the message loop is cleared out, before destroying the threads and loop. |
256 // Otherwise we leak memory. | 261 // Otherwise we leak memory. |
257 profile_.reset(); | 262 profile_.reset(); |
258 message_loop_.RunAllPending(); | 263 message_loop_.RunAllPending(); |
259 } | 264 } |
260 | 265 |
261 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 266 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
262 int remove_mask, | 267 int remove_mask, |
263 BrowsingDataRemoverTester* tester) { | 268 BrowsingDataRemoverTester* tester) { |
264 BrowsingDataRemover* remover = new BrowsingDataRemover( | 269 BrowsingDataRemover* remover = new BrowsingDataRemover( |
265 profile_.get(), period, | 270 profile_.get(), period, |
266 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | 271 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); |
267 remover->AddObserver(tester); | 272 remover->AddObserver(tester); |
268 | 273 |
| 274 called_with_mask_ = 0; |
| 275 called_with_time_ = base::Time(); |
| 276 |
269 // BrowsingDataRemover deletes itself when it completes. | 277 // BrowsingDataRemover deletes itself when it completes. |
270 remover->Remove(remove_mask); | 278 remover->Remove(remove_mask); |
271 tester->BlockUntilNotified(); | 279 tester->BlockUntilNotified(); |
272 } | 280 } |
273 | 281 |
274 TestingProfile* GetProfile() { | 282 TestingProfile* GetProfile() { |
275 return profile_.get(); | 283 return profile_.get(); |
276 } | 284 } |
277 | 285 |
| 286 base::Time GetBeginTime() { |
| 287 return called_with_time_; |
| 288 } |
| 289 |
| 290 int GetRemovalMask() { |
| 291 return called_with_mask_; |
| 292 } |
| 293 |
278 quota::MockQuotaManager* GetMockManager() { | 294 quota::MockQuotaManager* GetMockManager() { |
279 if (profile_->GetQuotaManager() == NULL) { | 295 if (profile_->GetQuotaManager() == NULL) { |
280 profile_->SetQuotaManager(new quota::MockQuotaManager( | 296 profile_->SetQuotaManager(new quota::MockQuotaManager( |
281 profile_->IsOffTheRecord(), | 297 profile_->IsOffTheRecord(), |
282 profile_->GetPath(), | 298 profile_->GetPath(), |
283 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 299 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
284 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 300 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
285 profile_->GetExtensionSpecialStoragePolicy())); | 301 profile_->GetExtensionSpecialStoragePolicy())); |
286 } | 302 } |
287 return (quota::MockQuotaManager*) profile_->GetQuotaManager(); | 303 return (quota::MockQuotaManager*) profile_->GetQuotaManager(); |
288 } | 304 } |
289 | 305 |
| 306 // content::NotificationObserver implementation. |
| 307 virtual void Observe(int type, |
| 308 const content::NotificationSource& source, |
| 309 const content::NotificationDetails& details) OVERRIDE { |
| 310 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); |
| 311 |
| 312 // We're not taking ownership of the details object, but simply storing |
| 313 // copies of its contents. |
| 314 BrowsingDataRemoverNotificationDetail* detail_pair( |
| 315 content::Details<BrowsingDataRemoverNotificationDetail>(details).ptr()); |
| 316 called_with_time_ = detail_pair->first; |
| 317 called_with_mask_ = detail_pair->second; |
| 318 |
| 319 registrar_.RemoveAll(); |
| 320 } |
| 321 |
290 private: | 322 private: |
| 323 base::Time called_with_time_; |
| 324 int called_with_mask_; |
| 325 content::NotificationRegistrar registrar_; |
| 326 |
291 // message_loop_, as well as all the threads associated with it must be | 327 // message_loop_, as well as all the threads associated with it must be |
292 // defined before profile_ to prevent explosions. Oh how I love C++. | 328 // defined before profile_ to prevent explosions. Oh how I love C++. |
293 MessageLoopForUI message_loop_; | 329 MessageLoopForUI message_loop_; |
294 content::TestBrowserThread ui_thread_; | 330 content::TestBrowserThread ui_thread_; |
295 content::TestBrowserThread db_thread_; | 331 content::TestBrowserThread db_thread_; |
296 content::TestBrowserThread webkit_thread_; | 332 content::TestBrowserThread webkit_thread_; |
297 content::TestBrowserThread file_thread_; | 333 content::TestBrowserThread file_thread_; |
298 content::TestBrowserThread io_thread_; | 334 content::TestBrowserThread io_thread_; |
299 scoped_ptr<TestingProfile> profile_; | 335 scoped_ptr<TestingProfile> profile_; |
300 | 336 |
301 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 337 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
302 }; | 338 }; |
303 | 339 |
304 // Tests --------------------------------------------------------------------- | 340 // Tests --------------------------------------------------------------------- |
305 | 341 |
306 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { | 342 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
307 scoped_ptr<RemoveCookieTester> tester( | 343 scoped_ptr<RemoveCookieTester> tester( |
308 new RemoveCookieTester(GetProfile())); | 344 new RemoveCookieTester(GetProfile())); |
309 | 345 |
310 tester->AddCookie(); | 346 tester->AddCookie(); |
311 ASSERT_TRUE(tester->ContainsCookie()); | 347 ASSERT_TRUE(tester->ContainsCookie()); |
312 | 348 |
313 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 349 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
314 BrowsingDataRemover::REMOVE_COOKIES, tester.get()); | 350 BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
315 | 351 |
| 352 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_COOKIES); |
316 EXPECT_FALSE(tester->ContainsCookie()); | 353 EXPECT_FALSE(tester->ContainsCookie()); |
317 } | 354 } |
318 | 355 |
319 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { | 356 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { |
320 scoped_ptr<RemoveHistoryTester> tester( | 357 scoped_ptr<RemoveHistoryTester> tester( |
321 new RemoveHistoryTester(GetProfile())); | 358 new RemoveHistoryTester(GetProfile())); |
322 | 359 |
323 tester->AddHistory(kOrigin1, base::Time::Now()); | 360 tester->AddHistory(kOrigin1, base::Time::Now()); |
324 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 361 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
325 | 362 |
326 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 363 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
327 BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 364 BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
328 | 365 |
| 366 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_HISTORY); |
329 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); | 367 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); |
330 } | 368 } |
331 | 369 |
332 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { | 370 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { |
333 scoped_ptr<RemoveHistoryTester> tester( | 371 scoped_ptr<RemoveHistoryTester> tester( |
334 new RemoveHistoryTester(GetProfile())); | 372 new RemoveHistoryTester(GetProfile())); |
335 | 373 |
336 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); | 374 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); |
337 | 375 |
338 tester->AddHistory(kOrigin1, base::Time::Now()); | 376 tester->AddHistory(kOrigin1, base::Time::Now()); |
339 tester->AddHistory(kOrigin2, two_hours_ago); | 377 tester->AddHistory(kOrigin2, two_hours_ago); |
340 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 378 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
341 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 379 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
342 | 380 |
343 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 381 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
344 BrowsingDataRemover::REMOVE_HISTORY, tester.get()); | 382 BrowsingDataRemover::REMOVE_HISTORY, tester.get()); |
345 | 383 |
| 384 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_HISTORY); |
346 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); | 385 EXPECT_FALSE(tester->HistoryContainsURL(kOrigin1)); |
347 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 386 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
348 } | 387 } |
349 | 388 |
350 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { | 389 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { |
351 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 390 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
352 new RemoveQuotaManagedDataTester()); | 391 new RemoveQuotaManagedDataTester()); |
353 | 392 |
354 tester->PopulateTestQuotaManagedData(GetMockManager()); | 393 tester->PopulateTestQuotaManagedData(GetMockManager()); |
355 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 394 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
356 BrowsingDataRemover::REMOVE_SITE_DATA & | 395 BrowsingDataRemover::REMOVE_SITE_DATA & |
357 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 396 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
358 | 397 |
| 398 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 399 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
359 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 400 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
360 quota::kStorageTypeTemporary)); | 401 quota::kStorageTypeTemporary)); |
361 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 402 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
362 quota::kStorageTypeTemporary)); | 403 quota::kStorageTypeTemporary)); |
363 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 404 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
364 quota::kStorageTypeTemporary)); | 405 quota::kStorageTypeTemporary)); |
365 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 406 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
366 quota::kStorageTypePersistent)); | 407 quota::kStorageTypePersistent)); |
367 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 408 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
368 quota::kStorageTypePersistent)); | 409 quota::kStorageTypePersistent)); |
369 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 410 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
370 quota::kStorageTypePersistent)); | 411 quota::kStorageTypePersistent)); |
371 } | 412 } |
372 | 413 |
373 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) { | 414 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) { |
374 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 415 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
375 new RemoveQuotaManagedDataTester()); | 416 new RemoveQuotaManagedDataTester()); |
376 | 417 |
377 tester->PopulateTestQuotaManagedTemporaryData(GetMockManager()); | 418 tester->PopulateTestQuotaManagedTemporaryData(GetMockManager()); |
378 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 419 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
379 BrowsingDataRemover::REMOVE_SITE_DATA & | 420 BrowsingDataRemover::REMOVE_SITE_DATA & |
380 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 421 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
381 | 422 |
| 423 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 424 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
382 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 425 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
383 quota::kStorageTypeTemporary)); | 426 quota::kStorageTypeTemporary)); |
384 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 427 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
385 quota::kStorageTypeTemporary)); | 428 quota::kStorageTypeTemporary)); |
386 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 429 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
387 quota::kStorageTypeTemporary)); | 430 quota::kStorageTypeTemporary)); |
388 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 431 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
389 quota::kStorageTypePersistent)); | 432 quota::kStorageTypePersistent)); |
390 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 433 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
391 quota::kStorageTypePersistent)); | 434 quota::kStorageTypePersistent)); |
392 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 435 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
393 quota::kStorageTypePersistent)); | 436 quota::kStorageTypePersistent)); |
394 } | 437 } |
395 | 438 |
396 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) { | 439 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) { |
397 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 440 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
398 new RemoveQuotaManagedDataTester()); | 441 new RemoveQuotaManagedDataTester()); |
399 | 442 |
400 tester->PopulateTestQuotaManagedPersistentData(GetMockManager()); | 443 tester->PopulateTestQuotaManagedPersistentData(GetMockManager()); |
401 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 444 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
402 BrowsingDataRemover::REMOVE_SITE_DATA & | 445 BrowsingDataRemover::REMOVE_SITE_DATA & |
403 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 446 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
404 | 447 |
| 448 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 449 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
405 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 450 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
406 quota::kStorageTypeTemporary)); | 451 quota::kStorageTypeTemporary)); |
407 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 452 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
408 quota::kStorageTypeTemporary)); | 453 quota::kStorageTypeTemporary)); |
409 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 454 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
410 quota::kStorageTypeTemporary)); | 455 quota::kStorageTypeTemporary)); |
411 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 456 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
412 quota::kStorageTypePersistent)); | 457 quota::kStorageTypePersistent)); |
413 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 458 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
414 quota::kStorageTypePersistent)); | 459 quota::kStorageTypePersistent)); |
415 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 460 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
416 quota::kStorageTypePersistent)); | 461 quota::kStorageTypePersistent)); |
417 } | 462 } |
418 | 463 |
419 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) { | 464 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) { |
420 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 465 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
421 new RemoveQuotaManagedDataTester()); | 466 new RemoveQuotaManagedDataTester()); |
422 | 467 |
423 GetMockManager(); // Creates the QuotaManager instance. | 468 GetMockManager(); // Creates the QuotaManager instance. |
424 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 469 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
425 BrowsingDataRemover::REMOVE_SITE_DATA & | 470 BrowsingDataRemover::REMOVE_SITE_DATA & |
426 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 471 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
427 | 472 |
| 473 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 474 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
428 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 475 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
429 quota::kStorageTypeTemporary)); | 476 quota::kStorageTypeTemporary)); |
430 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 477 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
431 quota::kStorageTypeTemporary)); | 478 quota::kStorageTypeTemporary)); |
432 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 479 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
433 quota::kStorageTypeTemporary)); | 480 quota::kStorageTypeTemporary)); |
434 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 481 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
435 quota::kStorageTypePersistent)); | 482 quota::kStorageTypePersistent)); |
436 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 483 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
437 quota::kStorageTypePersistent)); | 484 quota::kStorageTypePersistent)); |
438 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 485 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
439 quota::kStorageTypePersistent)); | 486 quota::kStorageTypePersistent)); |
440 } | 487 } |
441 | 488 |
442 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { | 489 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { |
443 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 490 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
444 new RemoveQuotaManagedDataTester()); | 491 new RemoveQuotaManagedDataTester()); |
445 tester->PopulateTestQuotaManagedData(GetMockManager()); | 492 tester->PopulateTestQuotaManagedData(GetMockManager()); |
446 | 493 |
447 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, | 494 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
448 BrowsingDataRemover::REMOVE_SITE_DATA & | 495 BrowsingDataRemover::REMOVE_SITE_DATA & |
449 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 496 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
450 | 497 |
| 498 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 499 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
451 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 500 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
452 quota::kStorageTypeTemporary)); | 501 quota::kStorageTypeTemporary)); |
453 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 502 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
454 quota::kStorageTypeTemporary)); | 503 quota::kStorageTypeTemporary)); |
455 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, | 504 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
456 quota::kStorageTypeTemporary)); | 505 quota::kStorageTypeTemporary)); |
457 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 506 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
458 quota::kStorageTypePersistent)); | 507 quota::kStorageTypePersistent)); |
459 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, | 508 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, |
460 quota::kStorageTypePersistent)); | 509 quota::kStorageTypePersistent)); |
461 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, | 510 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
462 quota::kStorageTypePersistent)); | 511 quota::kStorageTypePersistent)); |
463 } | 512 } |
464 | 513 |
465 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { | 514 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { |
466 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 515 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
467 new RemoveQuotaManagedDataTester()); | 516 new RemoveQuotaManagedDataTester()); |
468 tester->PopulateTestQuotaManagedData(GetMockManager()); | 517 tester->PopulateTestQuotaManagedData(GetMockManager()); |
469 | 518 |
470 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, | 519 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, |
471 BrowsingDataRemover::REMOVE_SITE_DATA & | 520 BrowsingDataRemover::REMOVE_SITE_DATA & |
472 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 521 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
473 | 522 |
| 523 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 524 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
474 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 525 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
475 quota::kStorageTypeTemporary)); | 526 quota::kStorageTypeTemporary)); |
476 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 527 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
477 quota::kStorageTypeTemporary)); | 528 quota::kStorageTypeTemporary)); |
478 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 529 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
479 quota::kStorageTypeTemporary)); | 530 quota::kStorageTypeTemporary)); |
480 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 531 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
481 quota::kStorageTypePersistent)); | 532 quota::kStorageTypePersistent)); |
482 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, | 533 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, |
483 quota::kStorageTypePersistent)); | 534 quota::kStorageTypePersistent)); |
484 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, | 535 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, |
485 quota::kStorageTypePersistent)); | 536 quota::kStorageTypePersistent)); |
486 } | 537 } |
487 | 538 |
488 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { | 539 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { |
489 // Protect kOrigin1. | 540 // Protect kOrigin1. |
490 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = | 541 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |
491 new MockExtensionSpecialStoragePolicy; | 542 new MockExtensionSpecialStoragePolicy; |
492 mock_policy->AddProtected(kOrigin1.GetOrigin()); | 543 mock_policy->AddProtected(kOrigin1.GetOrigin()); |
493 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); | 544 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy); |
494 | 545 |
495 scoped_ptr<RemoveQuotaManagedDataTester> tester( | 546 scoped_ptr<RemoveQuotaManagedDataTester> tester( |
496 new RemoveQuotaManagedDataTester()); | 547 new RemoveQuotaManagedDataTester()); |
497 tester->PopulateTestQuotaManagedData(GetMockManager()); | 548 tester->PopulateTestQuotaManagedData(GetMockManager()); |
498 | 549 |
499 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 550 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
500 BrowsingDataRemover::REMOVE_SITE_DATA & | 551 BrowsingDataRemover::REMOVE_SITE_DATA & |
501 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); | 552 ~BrowsingDataRemover::REMOVE_LSO_DATA, tester.get()); |
502 | 553 |
| 554 EXPECT_EQ(GetRemovalMask(), BrowsingDataRemover::REMOVE_SITE_DATA & |
| 555 ~BrowsingDataRemover::REMOVE_LSO_DATA); |
503 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, | 556 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, |
504 quota::kStorageTypeTemporary)); | 557 quota::kStorageTypeTemporary)); |
505 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 558 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
506 quota::kStorageTypeTemporary)); | 559 quota::kStorageTypeTemporary)); |
507 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 560 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
508 quota::kStorageTypeTemporary)); | 561 quota::kStorageTypeTemporary)); |
509 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, | 562 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, |
510 quota::kStorageTypePersistent)); | 563 quota::kStorageTypePersistent)); |
511 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, | 564 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, |
512 quota::kStorageTypePersistent)); | 565 quota::kStorageTypePersistent)); |
513 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, | 566 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, |
514 quota::kStorageTypePersistent)); | 567 quota::kStorageTypePersistent)); |
515 } | 568 } |
516 | 569 |
517 } // namespace | 570 } // namespace |
OLD | NEW |