Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: content/browser/storage_partition_impl_unittest.cc

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/storage_partition_impl_map.cc ('k') | content/browser/streams/stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/location.h" 6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
11 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/gpu/shader_disk_cache.h" 10 #include "content/browser/gpu/shader_disk_cache.h"
13 #include "content/browser/quota/mock_quota_manager.h" 11 #include "content/browser/quota/mock_quota_manager.h"
14 #include "content/browser/storage_partition_impl.h" 12 #include "content/browser/storage_partition_impl.h"
15 #include "content/public/browser/local_storage_usage_info.h" 13 #include "content/public/browser/local_storage_usage_info.h"
16 #include "content/public/browser/storage_partition.h" 14 #include "content/public/browser/storage_partition.h"
17 #include "content/public/test/mock_special_storage_policy.h" 15 #include "content/public/test/mock_special_storage_policy.h"
18 #include "content/public/test/test_browser_context.h" 16 #include "content/public/test/test_browser_context.h"
19 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 scoped_refptr<ShaderDiskCache> cache_; 396 scoped_refptr<ShaderDiskCache> cache_;
399 }; 397 };
400 398
401 // Tests --------------------------------------------------------------------- 399 // Tests ---------------------------------------------------------------------
402 400
403 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { 401 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
404 InitCache(); 402 InitCache();
405 EXPECT_EQ(1u, Size()); 403 EXPECT_EQ(1u, Size());
406 404
407 base::RunLoop run_loop; 405 base::RunLoop run_loop;
408 base::ThreadTaskRunnerHandle::Get()->PostTask( 406 base::MessageLoop::current()->PostTask(
409 FROM_HERE, 407 FROM_HERE, base::Bind(
410 base::Bind(&ClearData, 408 &ClearData,
411 BrowserContext::GetDefaultStoragePartition(browser_context()), 409 BrowserContext::GetDefaultStoragePartition(browser_context()),
412 &run_loop)); 410 &run_loop));
413 run_loop.Run(); 411 run_loop.Run();
414 EXPECT_EQ(0u, Size()); 412 EXPECT_EQ(0u, Size());
415 } 413 }
416 414
417 TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) { 415 TEST_F(StoragePartitionImplTest, QuotaClientMaskGeneration) {
418 EXPECT_EQ(storage::QuotaClient::kFileSystem, 416 EXPECT_EQ(storage::QuotaClient::kFileSystem,
419 StoragePartitionImpl::GenerateQuotaClientMask( 417 StoragePartitionImpl::GenerateQuotaClientMask(
420 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS)); 418 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS));
421 EXPECT_EQ(storage::QuotaClient::kDatabase, 419 EXPECT_EQ(storage::QuotaClient::kDatabase,
422 StoragePartitionImpl::GenerateQuotaClientMask( 420 StoragePartitionImpl::GenerateQuotaClientMask(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 468
471 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { 469 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) {
472 PopulateTestQuotaManagedData(GetMockManager()); 470 PopulateTestQuotaManagedData(GetMockManager());
473 471
474 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 472 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
475 BrowserContext::GetDefaultStoragePartition(browser_context())); 473 BrowserContext::GetDefaultStoragePartition(browser_context()));
476 partition->OverrideQuotaManagerForTesting( 474 partition->OverrideQuotaManagerForTesting(
477 GetMockManager()); 475 GetMockManager());
478 476
479 base::RunLoop run_loop; 477 base::RunLoop run_loop;
480 base::ThreadTaskRunnerHandle::Get()->PostTask( 478 base::MessageLoop::current()->PostTask(
481 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); 479 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop));
482 run_loop.Run(); 480 run_loop.Run();
483 481
484 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 482 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
485 kClientFile)); 483 kClientFile));
486 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 484 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
487 kClientFile)); 485 kClientFile));
488 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 486 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
489 kClientFile)); 487 kClientFile));
490 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 488 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
491 kClientFile)); 489 kClientFile));
492 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 490 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
493 kClientFile)); 491 kClientFile));
494 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 492 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
495 kClientFile)); 493 kClientFile));
496 } 494 }
497 495
498 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) { 496 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
499 PopulateTestQuotaManagedTemporaryData(GetMockManager()); 497 PopulateTestQuotaManagedTemporaryData(GetMockManager());
500 498
501 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 499 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
502 BrowserContext::GetDefaultStoragePartition(browser_context())); 500 BrowserContext::GetDefaultStoragePartition(browser_context()));
503 partition->OverrideQuotaManagerForTesting( 501 partition->OverrideQuotaManagerForTesting(
504 GetMockManager()); 502 GetMockManager());
505 503
506 base::RunLoop run_loop; 504 base::RunLoop run_loop;
507 base::ThreadTaskRunnerHandle::Get()->PostTask( 505 base::MessageLoop::current()->PostTask(
508 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); 506 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop));
509 run_loop.Run(); 507 run_loop.Run();
510 508
511 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 509 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
512 kClientFile)); 510 kClientFile));
513 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 511 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
514 kClientFile)); 512 kClientFile));
515 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 513 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
516 kClientFile)); 514 kClientFile));
517 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 515 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
518 kClientFile)); 516 kClientFile));
519 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 517 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
520 kClientFile)); 518 kClientFile));
521 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 519 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
522 kClientFile)); 520 kClientFile));
523 } 521 }
524 522
525 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) { 523 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
526 PopulateTestQuotaManagedPersistentData(GetMockManager()); 524 PopulateTestQuotaManagedPersistentData(GetMockManager());
527 525
528 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 526 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
529 BrowserContext::GetDefaultStoragePartition(browser_context())); 527 BrowserContext::GetDefaultStoragePartition(browser_context()));
530 partition->OverrideQuotaManagerForTesting( 528 partition->OverrideQuotaManagerForTesting(
531 GetMockManager()); 529 GetMockManager());
532 530
533 base::RunLoop run_loop; 531 base::RunLoop run_loop;
534 base::ThreadTaskRunnerHandle::Get()->PostTask( 532 base::MessageLoop::current()->PostTask(
535 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); 533 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop));
536 run_loop.Run(); 534 run_loop.Run();
537 535
538 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 536 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
539 kClientFile)); 537 kClientFile));
540 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 538 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
541 kClientFile)); 539 kClientFile));
542 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 540 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
543 kClientFile)); 541 kClientFile));
544 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 542 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
545 kClientFile)); 543 kClientFile));
546 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 544 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
547 kClientFile)); 545 kClientFile));
548 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 546 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
549 kClientFile)); 547 kClientFile));
550 } 548 }
551 549
552 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) { 550 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverNeither) {
553 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 551 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
554 BrowserContext::GetDefaultStoragePartition(browser_context())); 552 BrowserContext::GetDefaultStoragePartition(browser_context()));
555 partition->OverrideQuotaManagerForTesting( 553 partition->OverrideQuotaManagerForTesting(
556 GetMockManager()); 554 GetMockManager());
557 555
558 base::RunLoop run_loop; 556 base::RunLoop run_loop;
559 base::ThreadTaskRunnerHandle::Get()->PostTask( 557 base::MessageLoop::current()->PostTask(
560 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop)); 558 FROM_HERE, base::Bind(&ClearQuotaData, partition, &run_loop));
561 run_loop.Run(); 559 run_loop.Run();
562 560
563 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 561 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
564 kClientFile)); 562 kClientFile));
565 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 563 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
566 kClientFile)); 564 kClientFile));
567 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 565 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
568 kClientFile)); 566 kClientFile));
569 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 567 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
570 kClientFile)); 568 kClientFile));
571 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 569 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
572 kClientFile)); 570 kClientFile));
573 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 571 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
574 kClientFile)); 572 kClientFile));
575 } 573 }
576 574
577 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) { 575 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
578 PopulateTestQuotaManagedData(GetMockManager()); 576 PopulateTestQuotaManagedData(GetMockManager());
579 577
580 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 578 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
581 BrowserContext::GetDefaultStoragePartition(browser_context())); 579 BrowserContext::GetDefaultStoragePartition(browser_context()));
582 partition->OverrideQuotaManagerForTesting( 580 partition->OverrideQuotaManagerForTesting(
583 GetMockManager()); 581 GetMockManager());
584 582
585 base::RunLoop run_loop; 583 base::RunLoop run_loop;
586 base::ThreadTaskRunnerHandle::Get()->PostTask( 584 base::MessageLoop::current()->PostTask(
587 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin, partition, kOrigin1, 585 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
588 base::Time(), &run_loop)); 586 partition, kOrigin1, base::Time(),
587 &run_loop));
589 run_loop.Run(); 588 run_loop.Run();
590 589
591 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 590 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
592 kClientFile)); 591 kClientFile));
593 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 592 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
594 kClientFile)); 593 kClientFile));
595 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 594 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
596 kClientFile)); 595 kClientFile));
597 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 596 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
598 kClientFile)); 597 kClientFile));
599 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 598 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
600 kClientFile)); 599 kClientFile));
601 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 600 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
602 kClientFile)); 601 kClientFile));
603 } 602 }
604 603
605 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) { 604 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastHour) {
606 PopulateTestQuotaManagedData(GetMockManager()); 605 PopulateTestQuotaManagedData(GetMockManager());
607 606
608 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 607 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
609 BrowserContext::GetDefaultStoragePartition(browser_context())); 608 BrowserContext::GetDefaultStoragePartition(browser_context()));
610 partition->OverrideQuotaManagerForTesting( 609 partition->OverrideQuotaManagerForTesting(
611 GetMockManager()); 610 GetMockManager());
612 611
613 base::RunLoop run_loop; 612 base::RunLoop run_loop;
614 base::ThreadTaskRunnerHandle::Get()->PostTask( 613 base::MessageLoop::current()->PostTask(
615 FROM_HERE, 614 FROM_HERE, base::Bind(&ClearQuotaDataForOrigin,
616 base::Bind(&ClearQuotaDataForOrigin, partition, GURL(), 615 partition, GURL(),
617 base::Time::Now() - base::TimeDelta::FromHours(1), &run_loop)); 616 base::Time::Now() - base::TimeDelta::FromHours(1),
617 &run_loop));
618 run_loop.Run(); 618 run_loop.Run();
619 619
620 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 620 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
621 kClientFile)); 621 kClientFile));
622 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 622 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
623 kClientFile)); 623 kClientFile));
624 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 624 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
625 kClientFile)); 625 kClientFile));
626 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 626 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
627 kClientFile)); 627 kClientFile));
628 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 628 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
629 kClientFile)); 629 kClientFile));
630 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 630 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
631 kClientFile)); 631 kClientFile));
632 } 632 }
633 633
634 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) { 634 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForLastWeek) {
635 PopulateTestQuotaManagedData(GetMockManager()); 635 PopulateTestQuotaManagedData(GetMockManager());
636 636
637 base::RunLoop run_loop; 637 base::RunLoop run_loop;
638 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 638 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
639 BrowserContext::GetDefaultStoragePartition(browser_context())); 639 BrowserContext::GetDefaultStoragePartition(browser_context()));
640 partition->OverrideQuotaManagerForTesting( 640 partition->OverrideQuotaManagerForTesting(
641 GetMockManager()); 641 GetMockManager());
642 base::ThreadTaskRunnerHandle::Get()->PostTask( 642 base::MessageLoop::current()->PostTask(
643 FROM_HERE, 643 FROM_HERE, base::Bind(&ClearQuotaDataForNonPersistent,
644 base::Bind(&ClearQuotaDataForNonPersistent, partition, 644 partition,
645 base::Time::Now() - base::TimeDelta::FromDays(7), &run_loop)); 645 base::Time::Now() - base::TimeDelta::FromDays(7),
646 &run_loop));
646 run_loop.Run(); 647 run_loop.Run();
647 648
648 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 649 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
649 kClientFile)); 650 kClientFile));
650 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 651 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
651 kClientFile)); 652 kClientFile));
652 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 653 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
653 kClientFile)); 654 kClientFile));
654 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 655 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
655 kClientFile)); 656 kClientFile));
(...skipping 11 matching lines...) Expand all
667 668
668 PopulateTestQuotaManagedData(GetMockManager()); 669 PopulateTestQuotaManagedData(GetMockManager());
669 670
670 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 671 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
671 BrowserContext::GetDefaultStoragePartition(browser_context())); 672 BrowserContext::GetDefaultStoragePartition(browser_context()));
672 partition->OverrideQuotaManagerForTesting( 673 partition->OverrideQuotaManagerForTesting(
673 GetMockManager()); 674 GetMockManager());
674 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); 675 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get());
675 676
676 base::RunLoop run_loop; 677 base::RunLoop run_loop;
677 base::ThreadTaskRunnerHandle::Get()->PostTask( 678 base::MessageLoop::current()->PostTask(
678 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), 679 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
680 partition, GURL(),
679 base::Bind(&DoesOriginMatchForUnprotectedWeb), 681 base::Bind(&DoesOriginMatchForUnprotectedWeb),
680 base::Time(), &run_loop)); 682 base::Time(), &run_loop));
681 run_loop.Run(); 683 run_loop.Run();
682 684
683 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 685 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
684 kClientFile)); 686 kClientFile));
685 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 687 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
686 kClientFile)); 688 kClientFile));
687 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 689 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
688 kClientFile)); 690 kClientFile));
(...skipping 14 matching lines...) Expand all
703 PopulateTestQuotaManagedData(GetMockManager()); 705 PopulateTestQuotaManagedData(GetMockManager());
704 706
705 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 707 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
706 BrowserContext::GetDefaultStoragePartition(browser_context())); 708 BrowserContext::GetDefaultStoragePartition(browser_context()));
707 partition->OverrideQuotaManagerForTesting( 709 partition->OverrideQuotaManagerForTesting(
708 GetMockManager()); 710 GetMockManager());
709 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); 711 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get());
710 712
711 // Try to remove kOrigin1. Expect failure. 713 // Try to remove kOrigin1. Expect failure.
712 base::RunLoop run_loop; 714 base::RunLoop run_loop;
713 base::ThreadTaskRunnerHandle::Get()->PostTask( 715 base::MessageLoop::current()->PostTask(
714 FROM_HERE, 716 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
715 base::Bind(&ClearQuotaDataWithOriginMatcher, partition, kOrigin1, 717 partition, kOrigin1,
716 base::Bind(&DoesOriginMatchForUnprotectedWeb), base::Time(), 718 base::Bind(&DoesOriginMatchForUnprotectedWeb),
717 &run_loop)); 719 base::Time(), &run_loop));
718 run_loop.Run(); 720 run_loop.Run();
719 721
720 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 722 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
721 kClientFile)); 723 kClientFile));
722 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 724 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
723 kClientFile)); 725 kClientFile));
724 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 726 EXPECT_TRUE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
725 kClientFile)); 727 kClientFile));
726 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 728 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
727 kClientFile)); 729 kClientFile));
(...skipping 11 matching lines...) Expand all
739 741
740 PopulateTestQuotaManagedData(GetMockManager()); 742 PopulateTestQuotaManagedData(GetMockManager());
741 743
742 // Try to remove kOrigin1. Expect success. 744 // Try to remove kOrigin1. Expect success.
743 base::RunLoop run_loop; 745 base::RunLoop run_loop;
744 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 746 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
745 BrowserContext::GetDefaultStoragePartition(browser_context())); 747 BrowserContext::GetDefaultStoragePartition(browser_context()));
746 partition->OverrideQuotaManagerForTesting( 748 partition->OverrideQuotaManagerForTesting(
747 GetMockManager()); 749 GetMockManager());
748 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); 750 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get());
749 base::ThreadTaskRunnerHandle::Get()->PostTask( 751 base::MessageLoop::current()->PostTask(
750 FROM_HERE, 752 FROM_HERE,
751 base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), 753 base::Bind(&ClearQuotaDataWithOriginMatcher,
754 partition, GURL(),
752 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), 755 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
753 base::Time(), &run_loop)); 756 base::Time(), &run_loop));
754 run_loop.Run(); 757 run_loop.Run();
755 758
756 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary, 759 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kTemporary,
757 kClientFile)); 760 kClientFile));
758 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary, 761 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kTemporary,
759 kClientFile)); 762 kClientFile));
760 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary, 763 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kTemporary,
761 kClientFile)); 764 kClientFile));
762 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent, 765 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin1, kPersistent,
763 kClientFile)); 766 kClientFile));
764 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent, 767 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin2, kPersistent,
765 kClientFile)); 768 kClientFile));
766 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent, 769 EXPECT_FALSE(GetMockManager()->OriginHasData(kOrigin3, kPersistent,
767 kClientFile)); 770 kClientFile));
768 } 771 }
769 772
770 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) { 773 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedIgnoreDevTools) {
771 PopulateTestQuotaManagedNonBrowsingData(GetMockManager()); 774 PopulateTestQuotaManagedNonBrowsingData(GetMockManager());
772 775
773 base::RunLoop run_loop; 776 base::RunLoop run_loop;
774 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 777 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
775 BrowserContext::GetDefaultStoragePartition(browser_context())); 778 BrowserContext::GetDefaultStoragePartition(browser_context()));
776 partition->OverrideQuotaManagerForTesting( 779 partition->OverrideQuotaManagerForTesting(
777 GetMockManager()); 780 GetMockManager());
778 base::ThreadTaskRunnerHandle::Get()->PostTask( 781 base::MessageLoop::current()->PostTask(
779 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher, partition, GURL(), 782 FROM_HERE, base::Bind(&ClearQuotaDataWithOriginMatcher,
783 partition, GURL(),
780 base::Bind(&DoesOriginMatchUnprotected), 784 base::Bind(&DoesOriginMatchUnprotected),
781 base::Time(), &run_loop)); 785 base::Time(), &run_loop));
782 run_loop.Run(); 786 run_loop.Run();
783 787
784 // Check that devtools data isn't removed. 788 // Check that devtools data isn't removed.
785 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary, 789 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kTemporary,
786 kClientFile)); 790 kClientFile));
787 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent, 791 EXPECT_TRUE(GetMockManager()->OriginHasData(kOriginDevTools, kPersistent,
788 kClientFile)); 792 kClientFile));
789 } 793 }
790 794
791 TEST_F(StoragePartitionImplTest, RemoveCookieForever) { 795 TEST_F(StoragePartitionImplTest, RemoveCookieForever) {
792 RemoveCookieTester tester(browser_context()); 796 RemoveCookieTester tester(browser_context());
793 797
794 tester.AddCookie(); 798 tester.AddCookie();
795 ASSERT_TRUE(tester.ContainsCookie()); 799 ASSERT_TRUE(tester.ContainsCookie());
796 800
797 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 801 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
798 BrowserContext::GetDefaultStoragePartition(browser_context())); 802 BrowserContext::GetDefaultStoragePartition(browser_context()));
799 partition->SetURLRequestContext(browser_context()->GetRequestContext()); 803 partition->SetURLRequestContext(browser_context()->GetRequestContext());
800 804
801 base::RunLoop run_loop; 805 base::RunLoop run_loop;
802 base::ThreadTaskRunnerHandle::Get()->PostTask( 806 base::MessageLoop::current()->PostTask(
803 FROM_HERE, base::Bind(&ClearCookies, partition, base::Time(), 807 FROM_HERE, base::Bind(&ClearCookies,
804 base::Time::Max(), &run_loop)); 808 partition, base::Time(), base::Time::Max(),
809 &run_loop));
805 run_loop.Run(); 810 run_loop.Run();
806 811
807 EXPECT_FALSE(tester.ContainsCookie()); 812 EXPECT_FALSE(tester.ContainsCookie());
808 } 813 }
809 814
810 TEST_F(StoragePartitionImplTest, RemoveCookieLastHour) { 815 TEST_F(StoragePartitionImplTest, RemoveCookieLastHour) {
811 RemoveCookieTester tester(browser_context()); 816 RemoveCookieTester tester(browser_context());
812 817
813 tester.AddCookie(); 818 tester.AddCookie();
814 ASSERT_TRUE(tester.ContainsCookie()); 819 ASSERT_TRUE(tester.ContainsCookie());
815 820
816 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 821 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
817 BrowserContext::GetDefaultStoragePartition(browser_context())); 822 BrowserContext::GetDefaultStoragePartition(browser_context()));
818 base::Time an_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1); 823 base::Time an_hour_ago = base::Time::Now() - base::TimeDelta::FromHours(1);
819 partition->SetURLRequestContext(browser_context()->GetRequestContext()); 824 partition->SetURLRequestContext(browser_context()->GetRequestContext());
820 825
821 base::RunLoop run_loop; 826 base::RunLoop run_loop;
822 base::ThreadTaskRunnerHandle::Get()->PostTask( 827 base::MessageLoop::current()->PostTask(
823 FROM_HERE, base::Bind(&ClearCookies, partition, an_hour_ago, 828 FROM_HERE, base::Bind(&ClearCookies,
824 base::Time::Max(), &run_loop)); 829 partition, an_hour_ago, base::Time::Max(),
830 &run_loop));
825 run_loop.Run(); 831 run_loop.Run();
826 832
827 EXPECT_FALSE(tester.ContainsCookie()); 833 EXPECT_FALSE(tester.ContainsCookie());
828 } 834 }
829 835
830 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) { 836 TEST_F(StoragePartitionImplTest, RemoveUnprotectedLocalStorageForever) {
831 // Protect kOrigin1. 837 // Protect kOrigin1.
832 scoped_refptr<MockSpecialStoragePolicy> mock_policy = 838 scoped_refptr<MockSpecialStoragePolicy> mock_policy =
833 new MockSpecialStoragePolicy; 839 new MockSpecialStoragePolicy;
834 mock_policy->AddProtected(kOrigin1.GetOrigin()); 840 mock_policy->AddProtected(kOrigin1.GetOrigin());
835 841
836 RemoveLocalStorageTester tester(browser_context()); 842 RemoveLocalStorageTester tester(browser_context());
837 843
838 tester.AddDOMStorageTestData(); 844 tester.AddDOMStorageTestData();
839 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); 845 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1));
840 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); 846 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2));
841 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 847 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
842 848
843 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 849 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
844 BrowserContext::GetDefaultStoragePartition(browser_context())); 850 BrowserContext::GetDefaultStoragePartition(browser_context()));
845 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); 851 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get());
846 852
847 base::RunLoop run_loop; 853 base::RunLoop run_loop;
848 base::ThreadTaskRunnerHandle::Get()->PostTask( 854 base::MessageLoop::current()->PostTask(
849 FROM_HERE, 855 FROM_HERE,
850 base::Bind(&ClearStuff, 856 base::Bind(&ClearStuff,
851 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, 857 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE,
852 partition, base::Time(), base::Time::Max(), 858 partition, base::Time(), base::Time::Max(),
853 base::Bind(&DoesOriginMatchForUnprotectedWeb), &run_loop)); 859 base::Bind(&DoesOriginMatchForUnprotectedWeb),
860 &run_loop));
854 run_loop.Run(); 861 run_loop.Run();
855 862
856 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); 863 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1));
857 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); 864 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2));
858 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3)); 865 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3));
859 } 866 }
860 867
861 TEST_F(StoragePartitionImplTest, RemoveProtectedLocalStorageForever) { 868 TEST_F(StoragePartitionImplTest, RemoveProtectedLocalStorageForever) {
862 // Protect kOrigin1. 869 // Protect kOrigin1.
863 scoped_refptr<MockSpecialStoragePolicy> mock_policy = 870 scoped_refptr<MockSpecialStoragePolicy> mock_policy =
864 new MockSpecialStoragePolicy; 871 new MockSpecialStoragePolicy;
865 mock_policy->AddProtected(kOrigin1.GetOrigin()); 872 mock_policy->AddProtected(kOrigin1.GetOrigin());
866 873
867 RemoveLocalStorageTester tester(browser_context()); 874 RemoveLocalStorageTester tester(browser_context());
868 875
869 tester.AddDOMStorageTestData(); 876 tester.AddDOMStorageTestData();
870 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); 877 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1));
871 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); 878 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2));
872 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 879 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
873 880
874 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 881 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
875 BrowserContext::GetDefaultStoragePartition(browser_context())); 882 BrowserContext::GetDefaultStoragePartition(browser_context()));
876 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get()); 883 partition->OverrideSpecialStoragePolicyForTesting(mock_policy.get());
877 884
878 base::RunLoop run_loop; 885 base::RunLoop run_loop;
879 base::ThreadTaskRunnerHandle::Get()->PostTask( 886 base::MessageLoop::current()->PostTask(
880 FROM_HERE, 887 FROM_HERE,
881 base::Bind(&ClearStuff, 888 base::Bind(&ClearStuff,
882 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, 889 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE,
883 partition, base::Time(), base::Time::Max(), 890 partition, base::Time(), base::Time::Max(),
884 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), 891 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
885 &run_loop)); 892 &run_loop));
886 run_loop.Run(); 893 run_loop.Run();
887 894
888 // Even if kOrigin1 is protected, it will be deleted since we specify 895 // Even if kOrigin1 is protected, it will be deleted since we specify
889 // ClearData to delete protected data. 896 // ClearData to delete protected data.
890 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); 897 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1));
891 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); 898 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2));
892 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3)); 899 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin3));
893 } 900 }
894 901
895 TEST_F(StoragePartitionImplTest, RemoveLocalStorageForLastWeek) { 902 TEST_F(StoragePartitionImplTest, RemoveLocalStorageForLastWeek) {
896 RemoveLocalStorageTester tester(browser_context()); 903 RemoveLocalStorageTester tester(browser_context());
897 904
898 tester.AddDOMStorageTestData(); 905 tester.AddDOMStorageTestData();
899 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1)); 906 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin1));
900 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2)); 907 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin2));
901 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 908 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
902 909
903 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 910 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
904 BrowserContext::GetDefaultStoragePartition(browser_context())); 911 BrowserContext::GetDefaultStoragePartition(browser_context()));
905 base::Time a_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); 912 base::Time a_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7);
906 913
907 base::RunLoop run_loop; 914 base::RunLoop run_loop;
908 base::ThreadTaskRunnerHandle::Get()->PostTask( 915 base::MessageLoop::current()->PostTask(
909 FROM_HERE, 916 FROM_HERE,
910 base::Bind(&ClearStuff, 917 base::Bind(&ClearStuff,
911 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE, 918 StoragePartitionImpl::REMOVE_DATA_MASK_LOCAL_STORAGE,
912 partition, a_week_ago, base::Time::Max(), 919 partition, a_week_ago, base::Time::Max(),
913 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb), 920 base::Bind(&DoesOriginMatchForBothProtectedAndUnprotectedWeb),
914 &run_loop)); 921 &run_loop));
915 run_loop.Run(); 922 run_loop.Run();
916 923
917 // kOrigin1 and kOrigin2 do not have age more than a week. 924 // kOrigin1 and kOrigin2 do not have age more than a week.
918 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); 925 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1));
919 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); 926 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2));
920 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); 927 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3));
921 } 928 }
922 929
923 } // namespace content 930 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl_map.cc ('k') | content/browser/streams/stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698