OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
6 #include <sstream> | 6 #include <sstream> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Don't (automatically) start the eviction for testing. | 63 // Don't (automatically) start the eviction for testing. |
64 quota_manager_->eviction_disabled_ = true; | 64 quota_manager_->eviction_disabled_ = true; |
65 // Don't query the hard disk for remaining capacity. | 65 // Don't query the hard disk for remaining capacity. |
66 quota_manager_->get_disk_space_fn_ = &GetAvailableDiskSpaceForTest; | 66 quota_manager_->get_disk_space_fn_ = &GetAvailableDiskSpaceForTest; |
67 additional_callback_count_ = 0; | 67 additional_callback_count_ = 0; |
68 } | 68 } |
69 | 69 |
70 void TearDown() { | 70 void TearDown() { |
71 // Make sure the quota manager cleans up correctly. | 71 // Make sure the quota manager cleans up correctly. |
72 quota_manager_ = NULL; | 72 quota_manager_ = NULL; |
73 MessageLoop::current()->RunAllPending(); | 73 MessageLoop::current()->RunUntilIdle(); |
74 } | 74 } |
75 | 75 |
76 protected: | 76 protected: |
77 MockStorageClient* CreateClient( | 77 MockStorageClient* CreateClient( |
78 const MockOriginData* mock_data, | 78 const MockOriginData* mock_data, |
79 size_t mock_data_size, | 79 size_t mock_data_size, |
80 QuotaClient::ID id) { | 80 QuotaClient::ID id) { |
81 return new MockStorageClient(quota_manager_->proxy(), | 81 return new MockStorageClient(quota_manager_->proxy(), |
82 mock_data, id, mock_data_size); | 82 mock_data, id, mock_data_size); |
83 } | 83 } |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 { "https://foo.com:8081/", kTemp, 35 }, | 444 { "https://foo.com:8081/", kTemp, 35 }, |
445 { "http://bar.com/", kPerm, 40 }, | 445 { "http://bar.com/", kPerm, 40 }, |
446 { "http://example.com/", kPerm, 40 }, | 446 { "http://example.com/", kPerm, 40 }, |
447 }; | 447 }; |
448 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 448 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
449 QuotaClient::kFileSystem)); | 449 QuotaClient::kFileSystem)); |
450 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 450 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
451 QuotaClient::kDatabase)); | 451 QuotaClient::kDatabase)); |
452 | 452 |
453 GetUsageInfo(); | 453 GetUsageInfo(); |
454 MessageLoop::current()->RunAllPending(); | 454 MessageLoop::current()->RunUntilIdle(); |
455 | 455 |
456 EXPECT_EQ(4U, usage_info().size()); | 456 EXPECT_EQ(4U, usage_info().size()); |
457 for (size_t i = 0; i < usage_info().size(); ++i) { | 457 for (size_t i = 0; i < usage_info().size(); ++i) { |
458 const UsageInfo& info = usage_info()[i]; | 458 const UsageInfo& info = usage_info()[i]; |
459 if (info.host == "foo.com" && info.type == kTemp) { | 459 if (info.host == "foo.com" && info.type == kTemp) { |
460 EXPECT_EQ(10 + 15 + 30 + 35, info.usage); | 460 EXPECT_EQ(10 + 15 + 30 + 35, info.usage); |
461 } else if (info.host == "bar.com" && info.type == kTemp) { | 461 } else if (info.host == "bar.com" && info.type == kTemp) { |
462 EXPECT_EQ(20, info.usage); | 462 EXPECT_EQ(20, info.usage); |
463 } else if (info.host == "bar.com" && info.type == kPerm) { | 463 } else if (info.host == "bar.com" && info.type == kPerm) { |
464 EXPECT_EQ(50 + 40, info.usage); | 464 EXPECT_EQ(50 + 40, info.usage); |
465 } else if (info.host == "example.com" && info.type == kPerm) { | 465 } else if (info.host == "example.com" && info.type == kPerm) { |
466 EXPECT_EQ(40, info.usage); | 466 EXPECT_EQ(40, info.usage); |
467 } else { | 467 } else { |
468 ADD_FAILURE() | 468 ADD_FAILURE() |
469 << "Unexpected host, type: " << info.host << ", " << info.type; | 469 << "Unexpected host, type: " << info.host << ", " << info.type; |
470 } | 470 } |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { | 474 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { |
475 static const MockOriginData kData[] = { | 475 static const MockOriginData kData[] = { |
476 { "http://foo.com/", kTemp, 10 }, | 476 { "http://foo.com/", kTemp, 10 }, |
477 { "http://foo.com/", kPerm, 80 }, | 477 { "http://foo.com/", kPerm, 80 }, |
478 }; | 478 }; |
479 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 479 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
480 QuotaClient::kFileSystem)); | 480 QuotaClient::kFileSystem)); |
481 | 481 |
482 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 482 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
483 MessageLoop::current()->RunAllPending(); | 483 MessageLoop::current()->RunUntilIdle(); |
484 EXPECT_EQ(kQuotaStatusOk, status()); | 484 EXPECT_EQ(kQuotaStatusOk, status()); |
485 EXPECT_EQ(80, usage()); | 485 EXPECT_EQ(80, usage()); |
486 EXPECT_EQ(0, quota()); | 486 EXPECT_EQ(0, quota()); |
487 | 487 |
488 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 488 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
489 MessageLoop::current()->RunAllPending(); | 489 MessageLoop::current()->RunUntilIdle(); |
490 EXPECT_EQ(kQuotaStatusOk, status()); | 490 EXPECT_EQ(kQuotaStatusOk, status()); |
491 EXPECT_EQ(10, usage()); | 491 EXPECT_EQ(10, usage()); |
492 EXPECT_LE(0, quota()); | 492 EXPECT_LE(0, quota()); |
493 int64 quota_returned_for_foo = quota(); | 493 int64 quota_returned_for_foo = quota(); |
494 | 494 |
495 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); | 495 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); |
496 MessageLoop::current()->RunAllPending(); | 496 MessageLoop::current()->RunUntilIdle(); |
497 EXPECT_EQ(kQuotaStatusOk, status()); | 497 EXPECT_EQ(kQuotaStatusOk, status()); |
498 EXPECT_EQ(0, usage()); | 498 EXPECT_EQ(0, usage()); |
499 EXPECT_EQ(quota_returned_for_foo, quota()); | 499 EXPECT_EQ(quota_returned_for_foo, quota()); |
500 } | 500 } |
501 | 501 |
502 TEST_F(QuotaManagerTest, GetUsage_NoClient) { | 502 TEST_F(QuotaManagerTest, GetUsage_NoClient) { |
503 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 503 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
504 MessageLoop::current()->RunAllPending(); | 504 MessageLoop::current()->RunUntilIdle(); |
505 EXPECT_EQ(kQuotaStatusOk, status()); | 505 EXPECT_EQ(kQuotaStatusOk, status()); |
506 EXPECT_EQ(0, usage()); | 506 EXPECT_EQ(0, usage()); |
507 | 507 |
508 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 508 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
509 MessageLoop::current()->RunAllPending(); | 509 MessageLoop::current()->RunUntilIdle(); |
510 EXPECT_EQ(kQuotaStatusOk, status()); | 510 EXPECT_EQ(kQuotaStatusOk, status()); |
511 EXPECT_EQ(0, usage()); | 511 EXPECT_EQ(0, usage()); |
512 | 512 |
513 GetHostUsage("foo.com", kTemp); | 513 GetHostUsage("foo.com", kTemp); |
514 MessageLoop::current()->RunAllPending(); | 514 MessageLoop::current()->RunUntilIdle(); |
515 EXPECT_EQ(0, usage()); | 515 EXPECT_EQ(0, usage()); |
516 | 516 |
517 GetHostUsage("foo.com", kPerm); | 517 GetHostUsage("foo.com", kPerm); |
518 MessageLoop::current()->RunAllPending(); | 518 MessageLoop::current()->RunUntilIdle(); |
519 EXPECT_EQ(0, usage()); | 519 EXPECT_EQ(0, usage()); |
520 | 520 |
521 GetGlobalUsage(kTemp); | 521 GetGlobalUsage(kTemp); |
522 MessageLoop::current()->RunAllPending(); | 522 MessageLoop::current()->RunUntilIdle(); |
523 EXPECT_EQ(0, usage()); | 523 EXPECT_EQ(0, usage()); |
524 EXPECT_EQ(0, unlimited_usage()); | 524 EXPECT_EQ(0, unlimited_usage()); |
525 | 525 |
526 GetGlobalUsage(kPerm); | 526 GetGlobalUsage(kPerm); |
527 MessageLoop::current()->RunAllPending(); | 527 MessageLoop::current()->RunUntilIdle(); |
528 EXPECT_EQ(0, usage()); | 528 EXPECT_EQ(0, usage()); |
529 EXPECT_EQ(0, unlimited_usage()); | 529 EXPECT_EQ(0, unlimited_usage()); |
530 } | 530 } |
531 | 531 |
532 TEST_F(QuotaManagerTest, GetUsage_EmptyClient) { | 532 TEST_F(QuotaManagerTest, GetUsage_EmptyClient) { |
533 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | 533 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); |
534 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 534 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
535 MessageLoop::current()->RunAllPending(); | 535 MessageLoop::current()->RunUntilIdle(); |
536 EXPECT_EQ(kQuotaStatusOk, status()); | 536 EXPECT_EQ(kQuotaStatusOk, status()); |
537 EXPECT_EQ(0, usage()); | 537 EXPECT_EQ(0, usage()); |
538 | 538 |
539 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 539 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
540 MessageLoop::current()->RunAllPending(); | 540 MessageLoop::current()->RunUntilIdle(); |
541 EXPECT_EQ(kQuotaStatusOk, status()); | 541 EXPECT_EQ(kQuotaStatusOk, status()); |
542 EXPECT_EQ(0, usage()); | 542 EXPECT_EQ(0, usage()); |
543 | 543 |
544 GetHostUsage("foo.com", kTemp); | 544 GetHostUsage("foo.com", kTemp); |
545 MessageLoop::current()->RunAllPending(); | 545 MessageLoop::current()->RunUntilIdle(); |
546 EXPECT_EQ(0, usage()); | 546 EXPECT_EQ(0, usage()); |
547 | 547 |
548 GetHostUsage("foo.com", kPerm); | 548 GetHostUsage("foo.com", kPerm); |
549 MessageLoop::current()->RunAllPending(); | 549 MessageLoop::current()->RunUntilIdle(); |
550 EXPECT_EQ(0, usage()); | 550 EXPECT_EQ(0, usage()); |
551 | 551 |
552 GetGlobalUsage(kTemp); | 552 GetGlobalUsage(kTemp); |
553 MessageLoop::current()->RunAllPending(); | 553 MessageLoop::current()->RunUntilIdle(); |
554 EXPECT_EQ(0, usage()); | 554 EXPECT_EQ(0, usage()); |
555 EXPECT_EQ(0, unlimited_usage()); | 555 EXPECT_EQ(0, unlimited_usage()); |
556 | 556 |
557 GetGlobalUsage(kPerm); | 557 GetGlobalUsage(kPerm); |
558 MessageLoop::current()->RunAllPending(); | 558 MessageLoop::current()->RunUntilIdle(); |
559 EXPECT_EQ(0, usage()); | 559 EXPECT_EQ(0, usage()); |
560 EXPECT_EQ(0, unlimited_usage()); | 560 EXPECT_EQ(0, unlimited_usage()); |
561 } | 561 } |
562 | 562 |
563 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) { | 563 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_MultiOrigins) { |
564 static const MockOriginData kData[] = { | 564 static const MockOriginData kData[] = { |
565 { "http://foo.com/", kTemp, 10 }, | 565 { "http://foo.com/", kTemp, 10 }, |
566 { "http://foo.com:8080/", kTemp, 20 }, | 566 { "http://foo.com:8080/", kTemp, 20 }, |
567 { "http://bar.com/", kTemp, 5 }, | 567 { "http://bar.com/", kTemp, 5 }, |
568 { "https://bar.com/", kTemp, 7 }, | 568 { "https://bar.com/", kTemp, 7 }, |
569 { "http://baz.com/", kTemp, 30 }, | 569 { "http://baz.com/", kTemp, 30 }, |
570 { "http://foo.com/", kPerm, 40 }, | 570 { "http://foo.com/", kPerm, 40 }, |
571 }; | 571 }; |
572 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 572 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
573 QuotaClient::kFileSystem)); | 573 QuotaClient::kFileSystem)); |
574 | 574 |
575 // This time explicitly sets a temporary global quota. | 575 // This time explicitly sets a temporary global quota. |
576 SetTemporaryGlobalQuota(100); | 576 SetTemporaryGlobalQuota(100); |
577 MessageLoop::current()->RunAllPending(); | 577 MessageLoop::current()->RunUntilIdle(); |
578 EXPECT_EQ(kTemp, type()); | 578 EXPECT_EQ(kTemp, type()); |
579 EXPECT_EQ(kQuotaStatusOk, status()); | 579 EXPECT_EQ(kQuotaStatusOk, status()); |
580 EXPECT_EQ(100, quota()); | 580 EXPECT_EQ(100, quota()); |
581 | 581 |
582 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 582 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
583 MessageLoop::current()->RunAllPending(); | 583 MessageLoop::current()->RunUntilIdle(); |
584 EXPECT_EQ(kQuotaStatusOk, status()); | 584 EXPECT_EQ(kQuotaStatusOk, status()); |
585 EXPECT_EQ(10 + 20, usage()); | 585 EXPECT_EQ(10 + 20, usage()); |
586 | 586 |
587 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | 587 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
588 | 588 |
589 // The host's quota should be its full portion of the global quota | 589 // The host's quota should be its full portion of the global quota |
590 // since global usage is under the global quota. | 590 // since global usage is under the global quota. |
591 EXPECT_EQ(kPerHostQuota, quota()); | 591 EXPECT_EQ(kPerHostQuota, quota()); |
592 | 592 |
593 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); | 593 GetUsageAndQuota(GURL("http://bar.com/"), kTemp); |
594 MessageLoop::current()->RunAllPending(); | 594 MessageLoop::current()->RunUntilIdle(); |
595 EXPECT_EQ(kQuotaStatusOk, status()); | 595 EXPECT_EQ(kQuotaStatusOk, status()); |
596 EXPECT_EQ(5 + 7, usage()); | 596 EXPECT_EQ(5 + 7, usage()); |
597 EXPECT_EQ(kPerHostQuota, quota()); | 597 EXPECT_EQ(kPerHostQuota, quota()); |
598 } | 598 } |
599 | 599 |
600 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { | 600 TEST_F(QuotaManagerTest, GetUsage_MultipleClients) { |
601 static const MockOriginData kData1[] = { | 601 static const MockOriginData kData1[] = { |
602 { "http://foo.com/", kTemp, 10 }, | 602 { "http://foo.com/", kTemp, 10 }, |
603 { "http://bar.com/", kTemp, 20 }, | 603 { "http://bar.com/", kTemp, 20 }, |
604 { "http://bar.com/", kPerm, 50 }, | 604 { "http://bar.com/", kPerm, 50 }, |
605 { "http://unlimited/", kPerm, 1 }, | 605 { "http://unlimited/", kPerm, 1 }, |
606 { "http://installed/", kPerm, 1 }, | 606 { "http://installed/", kPerm, 1 }, |
607 }; | 607 }; |
608 static const MockOriginData kData2[] = { | 608 static const MockOriginData kData2[] = { |
609 { "https://foo.com/", kTemp, 30 }, | 609 { "https://foo.com/", kTemp, 30 }, |
610 { "http://example.com/", kPerm, 40 }, | 610 { "http://example.com/", kPerm, 40 }, |
611 { "http://unlimited/", kTemp, 1 }, | 611 { "http://unlimited/", kTemp, 1 }, |
612 { "http://installed/", kTemp, 1 }, | 612 { "http://installed/", kTemp, 1 }, |
613 }; | 613 }; |
614 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 614 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
615 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); | 615 mock_special_storage_policy()->AddInstalledApp(GURL("http://installed/")); |
616 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 616 RegisterClient(CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
617 QuotaClient::kFileSystem)); | 617 QuotaClient::kFileSystem)); |
618 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 618 RegisterClient(CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
619 QuotaClient::kDatabase)); | 619 QuotaClient::kDatabase)); |
620 | 620 |
621 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 621 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
622 MessageLoop::current()->RunAllPending(); | 622 MessageLoop::current()->RunUntilIdle(); |
623 EXPECT_EQ(kQuotaStatusOk, status()); | 623 EXPECT_EQ(kQuotaStatusOk, status()); |
624 EXPECT_EQ(10 + 30, usage()); | 624 EXPECT_EQ(10 + 30, usage()); |
625 | 625 |
626 GetUsageAndQuota(GURL("http://bar.com/"), kPerm); | 626 GetUsageAndQuota(GURL("http://bar.com/"), kPerm); |
627 MessageLoop::current()->RunAllPending(); | 627 MessageLoop::current()->RunUntilIdle(); |
628 EXPECT_EQ(kQuotaStatusOk, status()); | 628 EXPECT_EQ(kQuotaStatusOk, status()); |
629 EXPECT_EQ(50, usage()); | 629 EXPECT_EQ(50, usage()); |
630 | 630 |
631 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 631 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
632 MessageLoop::current()->RunAllPending(); | 632 MessageLoop::current()->RunUntilIdle(); |
633 EXPECT_EQ(kQuotaStatusOk, status()); | 633 EXPECT_EQ(kQuotaStatusOk, status()); |
634 EXPECT_EQ(1, usage()); | 634 EXPECT_EQ(1, usage()); |
635 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 635 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
636 | 636 |
637 GetUsageAndQuota(GURL("http://unlimited/"), kPerm); | 637 GetUsageAndQuota(GURL("http://unlimited/"), kPerm); |
638 MessageLoop::current()->RunAllPending(); | 638 MessageLoop::current()->RunUntilIdle(); |
639 EXPECT_EQ(kQuotaStatusOk, status()); | 639 EXPECT_EQ(kQuotaStatusOk, status()); |
640 EXPECT_EQ(1, usage()); | 640 EXPECT_EQ(1, usage()); |
641 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 641 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
642 | 642 |
643 GetAvailableSpace(); | 643 GetAvailableSpace(); |
644 MessageLoop::current()->RunAllPending(); | 644 MessageLoop::current()->RunUntilIdle(); |
645 EXPECT_EQ(kQuotaStatusOk, status()); | 645 EXPECT_EQ(kQuotaStatusOk, status()); |
646 EXPECT_LE(0, available_space()); | 646 EXPECT_LE(0, available_space()); |
647 | 647 |
648 GetUsageAndQuota(GURL("http://installed/"), kTemp); | 648 GetUsageAndQuota(GURL("http://installed/"), kTemp); |
649 MessageLoop::current()->RunAllPending(); | 649 MessageLoop::current()->RunUntilIdle(); |
650 EXPECT_EQ(kQuotaStatusOk, status()); | 650 EXPECT_EQ(kQuotaStatusOk, status()); |
651 EXPECT_EQ(1, usage()); | 651 EXPECT_EQ(1, usage()); |
652 EXPECT_EQ(available_space(), quota()); | 652 EXPECT_EQ(available_space(), quota()); |
653 | 653 |
654 GetUsageAndQuota(GURL("http://installed/"), kPerm); | 654 GetUsageAndQuota(GURL("http://installed/"), kPerm); |
655 MessageLoop::current()->RunAllPending(); | 655 MessageLoop::current()->RunUntilIdle(); |
656 EXPECT_EQ(kQuotaStatusOk, status()); | 656 EXPECT_EQ(kQuotaStatusOk, status()); |
657 EXPECT_EQ(1, usage()); | 657 EXPECT_EQ(1, usage()); |
658 EXPECT_EQ(available_space(), quota()); | 658 EXPECT_EQ(available_space(), quota()); |
659 | 659 |
660 GetGlobalUsage(kTemp); | 660 GetGlobalUsage(kTemp); |
661 MessageLoop::current()->RunAllPending(); | 661 MessageLoop::current()->RunUntilIdle(); |
662 EXPECT_EQ(kQuotaStatusOk, status()); | 662 EXPECT_EQ(kQuotaStatusOk, status()); |
663 EXPECT_EQ(10 + 20 + 30 + 1 + 1, usage()); | 663 EXPECT_EQ(10 + 20 + 30 + 1 + 1, usage()); |
664 EXPECT_EQ(2, unlimited_usage()); | 664 EXPECT_EQ(2, unlimited_usage()); |
665 | 665 |
666 GetGlobalUsage(kPerm); | 666 GetGlobalUsage(kPerm); |
667 MessageLoop::current()->RunAllPending(); | 667 MessageLoop::current()->RunUntilIdle(); |
668 EXPECT_EQ(kQuotaStatusOk, status()); | 668 EXPECT_EQ(kQuotaStatusOk, status()); |
669 EXPECT_EQ(40 + 50 + 1 + 1, usage()); | 669 EXPECT_EQ(40 + 50 + 1 + 1, usage()); |
670 EXPECT_EQ(2, unlimited_usage()); | 670 EXPECT_EQ(2, unlimited_usage()); |
671 } | 671 } |
672 | 672 |
673 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { | 673 void QuotaManagerTest::GetUsage_WithModifyTestBody(const StorageType type) { |
674 const MockOriginData data[] = { | 674 const MockOriginData data[] = { |
675 { "http://foo.com/", type, 10 }, | 675 { "http://foo.com/", type, 10 }, |
676 { "http://foo.com:1/", type, 20 }, | 676 { "http://foo.com:1/", type, 20 }, |
677 }; | 677 }; |
678 MockStorageClient* client = CreateClient(data, ARRAYSIZE_UNSAFE(data), | 678 MockStorageClient* client = CreateClient(data, ARRAYSIZE_UNSAFE(data), |
679 QuotaClient::kFileSystem); | 679 QuotaClient::kFileSystem); |
680 RegisterClient(client); | 680 RegisterClient(client); |
681 | 681 |
682 GetUsageAndQuota(GURL("http://foo.com/"), type); | 682 GetUsageAndQuota(GURL("http://foo.com/"), type); |
683 MessageLoop::current()->RunAllPending(); | 683 MessageLoop::current()->RunUntilIdle(); |
684 EXPECT_EQ(kQuotaStatusOk, status()); | 684 EXPECT_EQ(kQuotaStatusOk, status()); |
685 EXPECT_EQ(10 + 20, usage()); | 685 EXPECT_EQ(10 + 20, usage()); |
686 | 686 |
687 client->ModifyOriginAndNotify(GURL("http://foo.com/"), type, 30); | 687 client->ModifyOriginAndNotify(GURL("http://foo.com/"), type, 30); |
688 client->ModifyOriginAndNotify(GURL("http://foo.com:1/"), type, -5); | 688 client->ModifyOriginAndNotify(GURL("http://foo.com:1/"), type, -5); |
689 client->AddOriginAndNotify(GURL("https://foo.com/"), type, 1); | 689 client->AddOriginAndNotify(GURL("https://foo.com/"), type, 1); |
690 | 690 |
691 GetUsageAndQuota(GURL("http://foo.com/"), type); | 691 GetUsageAndQuota(GURL("http://foo.com/"), type); |
692 MessageLoop::current()->RunAllPending(); | 692 MessageLoop::current()->RunUntilIdle(); |
693 EXPECT_EQ(kQuotaStatusOk, status()); | 693 EXPECT_EQ(kQuotaStatusOk, status()); |
694 EXPECT_EQ(10 + 20 + 30 - 5 + 1, usage()); | 694 EXPECT_EQ(10 + 20 + 30 - 5 + 1, usage()); |
695 int foo_usage = usage(); | 695 int foo_usage = usage(); |
696 | 696 |
697 client->AddOriginAndNotify(GURL("http://bar.com/"), type, 40); | 697 client->AddOriginAndNotify(GURL("http://bar.com/"), type, 40); |
698 GetUsageAndQuota(GURL("http://bar.com/"), type); | 698 GetUsageAndQuota(GURL("http://bar.com/"), type); |
699 MessageLoop::current()->RunAllPending(); | 699 MessageLoop::current()->RunUntilIdle(); |
700 EXPECT_EQ(kQuotaStatusOk, status()); | 700 EXPECT_EQ(kQuotaStatusOk, status()); |
701 EXPECT_EQ(40, usage()); | 701 EXPECT_EQ(40, usage()); |
702 | 702 |
703 GetGlobalUsage(type); | 703 GetGlobalUsage(type); |
704 MessageLoop::current()->RunAllPending(); | 704 MessageLoop::current()->RunUntilIdle(); |
705 EXPECT_EQ(foo_usage + 40, usage()); | 705 EXPECT_EQ(foo_usage + 40, usage()); |
706 EXPECT_EQ(0, unlimited_usage()); | 706 EXPECT_EQ(0, unlimited_usage()); |
707 } | 707 } |
708 | 708 |
709 TEST_F(QuotaManagerTest, GetTemporaryUsage_WithModify) { | 709 TEST_F(QuotaManagerTest, GetTemporaryUsage_WithModify) { |
710 GetUsage_WithModifyTestBody(kTemp); | 710 GetUsage_WithModifyTestBody(kTemp); |
711 } | 711 } |
712 | 712 |
713 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { | 713 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_WithAdditionalTasks) { |
714 static const MockOriginData kData[] = { | 714 static const MockOriginData kData[] = { |
715 { "http://foo.com/", kTemp, 10 }, | 715 { "http://foo.com/", kTemp, 10 }, |
716 { "http://foo.com:8080/", kTemp, 20 }, | 716 { "http://foo.com:8080/", kTemp, 20 }, |
717 { "http://bar.com/", kTemp, 13 }, | 717 { "http://bar.com/", kTemp, 13 }, |
718 { "http://foo.com/", kPerm, 40 }, | 718 { "http://foo.com/", kPerm, 40 }, |
719 }; | 719 }; |
720 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 720 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
721 QuotaClient::kFileSystem)); | 721 QuotaClient::kFileSystem)); |
722 SetTemporaryGlobalQuota(100); | 722 SetTemporaryGlobalQuota(100); |
723 MessageLoop::current()->RunAllPending(); | 723 MessageLoop::current()->RunUntilIdle(); |
724 | 724 |
725 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | 725 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
726 | 726 |
727 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 727 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
728 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 728 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
729 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 729 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
730 MessageLoop::current()->RunAllPending(); | 730 MessageLoop::current()->RunUntilIdle(); |
731 EXPECT_EQ(kQuotaStatusOk, status()); | 731 EXPECT_EQ(kQuotaStatusOk, status()); |
732 EXPECT_EQ(10 + 20, usage()); | 732 EXPECT_EQ(10 + 20, usage()); |
733 EXPECT_EQ(kPerHostQuota, quota()); | 733 EXPECT_EQ(kPerHostQuota, quota()); |
734 | 734 |
735 set_additional_callback_count(0); | 735 set_additional_callback_count(0); |
736 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 736 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
737 kTemp); | 737 kTemp); |
738 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 738 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
739 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kTemp); | 739 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kTemp); |
740 MessageLoop::current()->RunAllPending(); | 740 MessageLoop::current()->RunUntilIdle(); |
741 EXPECT_EQ(kQuotaStatusOk, status()); | 741 EXPECT_EQ(kQuotaStatusOk, status()); |
742 EXPECT_EQ(10 + 20, usage()); | 742 EXPECT_EQ(10 + 20, usage()); |
743 EXPECT_EQ(kPerHostQuota, quota()); | 743 EXPECT_EQ(kPerHostQuota, quota()); |
744 EXPECT_EQ(2, additional_callback_count()); | 744 EXPECT_EQ(2, additional_callback_count()); |
745 } | 745 } |
746 | 746 |
747 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { | 747 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_NukeManager) { |
748 static const MockOriginData kData[] = { | 748 static const MockOriginData kData[] = { |
749 { "http://foo.com/", kTemp, 10 }, | 749 { "http://foo.com/", kTemp, 10 }, |
750 { "http://foo.com:8080/", kTemp, 20 }, | 750 { "http://foo.com:8080/", kTemp, 20 }, |
751 { "http://bar.com/", kTemp, 13 }, | 751 { "http://bar.com/", kTemp, 13 }, |
752 { "http://foo.com/", kPerm, 40 }, | 752 { "http://foo.com/", kPerm, 40 }, |
753 }; | 753 }; |
754 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 754 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
755 QuotaClient::kFileSystem)); | 755 QuotaClient::kFileSystem)); |
756 SetTemporaryGlobalQuota(100); | 756 SetTemporaryGlobalQuota(100); |
757 MessageLoop::current()->RunAllPending(); | 757 MessageLoop::current()->RunUntilIdle(); |
758 | 758 |
759 set_additional_callback_count(0); | 759 set_additional_callback_count(0); |
760 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); | 760 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); |
761 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 761 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
762 kTemp); | 762 kTemp); |
763 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), | 763 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), |
764 kTemp); | 764 kTemp); |
765 | 765 |
766 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | 766 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); |
767 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | 767 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); |
768 | 768 |
769 // Nuke before waiting for callbacks. | 769 // Nuke before waiting for callbacks. |
770 set_quota_manager(NULL); | 770 set_quota_manager(NULL); |
771 MessageLoop::current()->RunAllPending(); | 771 MessageLoop::current()->RunUntilIdle(); |
772 EXPECT_EQ(kQuotaErrorAbort, status()); | 772 EXPECT_EQ(kQuotaErrorAbort, status()); |
773 } | 773 } |
774 | 774 |
775 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { | 775 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { |
776 static const MockOriginData kData[] = { | 776 static const MockOriginData kData[] = { |
777 { "http://usage1/", kTemp, 1 }, | 777 { "http://usage1/", kTemp, 1 }, |
778 { "http://usage10/", kTemp, 10 }, | 778 { "http://usage10/", kTemp, 10 }, |
779 { "http://usage200/", kTemp, 200 }, | 779 { "http://usage200/", kTemp, 200 }, |
780 }; | 780 }; |
781 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 781 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
782 QuotaClient::kFileSystem)); | 782 QuotaClient::kFileSystem)); |
783 SetTemporaryGlobalQuota(100); | 783 SetTemporaryGlobalQuota(100); |
784 MessageLoop::current()->RunAllPending(); | 784 MessageLoop::current()->RunUntilIdle(); |
785 | 785 |
786 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; | 786 const int kPerHostQuota = 100 / QuotaManager::kPerHostTemporaryPortion; |
787 | 787 |
788 GetUsageAndQuota(GURL("http://usage1/"), kTemp); | 788 GetUsageAndQuota(GURL("http://usage1/"), kTemp); |
789 MessageLoop::current()->RunAllPending(); | 789 MessageLoop::current()->RunUntilIdle(); |
790 EXPECT_EQ(kQuotaStatusOk, status()); | 790 EXPECT_EQ(kQuotaStatusOk, status()); |
791 EXPECT_EQ(1, usage()); | 791 EXPECT_EQ(1, usage()); |
792 EXPECT_EQ(1, quota()); // should be clamped to our current usage | 792 EXPECT_EQ(1, quota()); // should be clamped to our current usage |
793 | 793 |
794 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 794 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
795 MessageLoop::current()->RunAllPending(); | 795 MessageLoop::current()->RunUntilIdle(); |
796 EXPECT_EQ(kQuotaStatusOk, status()); | 796 EXPECT_EQ(kQuotaStatusOk, status()); |
797 EXPECT_EQ(10, usage()); | 797 EXPECT_EQ(10, usage()); |
798 EXPECT_EQ(10, quota()); | 798 EXPECT_EQ(10, quota()); |
799 | 799 |
800 GetUsageAndQuota(GURL("http://usage200/"), kTemp); | 800 GetUsageAndQuota(GURL("http://usage200/"), kTemp); |
801 MessageLoop::current()->RunAllPending(); | 801 MessageLoop::current()->RunUntilIdle(); |
802 EXPECT_EQ(kQuotaStatusOk, status()); | 802 EXPECT_EQ(kQuotaStatusOk, status()); |
803 EXPECT_EQ(200, usage()); | 803 EXPECT_EQ(200, usage()); |
804 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota | 804 EXPECT_EQ(kPerHostQuota, quota()); // should be clamped to the nominal quota |
805 } | 805 } |
806 | 806 |
807 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { | 807 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) { |
808 static const MockOriginData kData[] = { | 808 static const MockOriginData kData[] = { |
809 { "http://usage10/", kTemp, 10 }, | 809 { "http://usage10/", kTemp, 10 }, |
810 { "http://usage50/", kTemp, 50 }, | 810 { "http://usage50/", kTemp, 50 }, |
811 { "http://unlimited/", kTemp, 4000 }, | 811 { "http://unlimited/", kTemp, 4000 }, |
812 }; | 812 }; |
813 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 813 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
814 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 814 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
815 QuotaClient::kFileSystem); | 815 QuotaClient::kFileSystem); |
816 RegisterClient(client); | 816 RegisterClient(client); |
817 | 817 |
818 // Test when not overbugdet. | 818 // Test when not overbugdet. |
819 SetTemporaryGlobalQuota(1000); | 819 SetTemporaryGlobalQuota(1000); |
820 MessageLoop::current()->RunAllPending(); | 820 MessageLoop::current()->RunUntilIdle(); |
821 | 821 |
822 GetGlobalUsage(kTemp); | 822 GetGlobalUsage(kTemp); |
823 MessageLoop::current()->RunAllPending(); | 823 MessageLoop::current()->RunUntilIdle(); |
824 EXPECT_EQ(10 + 50 + 4000, usage()); | 824 EXPECT_EQ(10 + 50 + 4000, usage()); |
825 EXPECT_EQ(4000, unlimited_usage()); | 825 EXPECT_EQ(4000, unlimited_usage()); |
826 | 826 |
827 const int kPerHostQuotaFor1000 = | 827 const int kPerHostQuotaFor1000 = |
828 1000 / QuotaManager::kPerHostTemporaryPortion; | 828 1000 / QuotaManager::kPerHostTemporaryPortion; |
829 | 829 |
830 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 830 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
831 MessageLoop::current()->RunAllPending(); | 831 MessageLoop::current()->RunUntilIdle(); |
832 EXPECT_EQ(kQuotaStatusOk, status()); | 832 EXPECT_EQ(kQuotaStatusOk, status()); |
833 EXPECT_EQ(10, usage()); | 833 EXPECT_EQ(10, usage()); |
834 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 834 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
835 | 835 |
836 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 836 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
837 MessageLoop::current()->RunAllPending(); | 837 MessageLoop::current()->RunUntilIdle(); |
838 EXPECT_EQ(kQuotaStatusOk, status()); | 838 EXPECT_EQ(kQuotaStatusOk, status()); |
839 EXPECT_EQ(50, usage()); | 839 EXPECT_EQ(50, usage()); |
840 EXPECT_EQ(kPerHostQuotaFor1000, quota()); | 840 EXPECT_EQ(kPerHostQuotaFor1000, quota()); |
841 | 841 |
842 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 842 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
843 MessageLoop::current()->RunAllPending(); | 843 MessageLoop::current()->RunUntilIdle(); |
844 EXPECT_EQ(kQuotaStatusOk, status()); | 844 EXPECT_EQ(kQuotaStatusOk, status()); |
845 EXPECT_EQ(4000, usage()); | 845 EXPECT_EQ(4000, usage()); |
846 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 846 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
847 | 847 |
848 // Test when overbugdet. | 848 // Test when overbugdet. |
849 SetTemporaryGlobalQuota(100); | 849 SetTemporaryGlobalQuota(100); |
850 MessageLoop::current()->RunAllPending(); | 850 MessageLoop::current()->RunUntilIdle(); |
851 | 851 |
852 const int kPerHostQuotaFor100 = | 852 const int kPerHostQuotaFor100 = |
853 100 / QuotaManager::kPerHostTemporaryPortion; | 853 100 / QuotaManager::kPerHostTemporaryPortion; |
854 | 854 |
855 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 855 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
856 MessageLoop::current()->RunAllPending(); | 856 MessageLoop::current()->RunUntilIdle(); |
857 EXPECT_EQ(kQuotaStatusOk, status()); | 857 EXPECT_EQ(kQuotaStatusOk, status()); |
858 EXPECT_EQ(10, usage()); | 858 EXPECT_EQ(10, usage()); |
859 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 859 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
860 | 860 |
861 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 861 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
862 MessageLoop::current()->RunAllPending(); | 862 MessageLoop::current()->RunUntilIdle(); |
863 EXPECT_EQ(kQuotaStatusOk, status()); | 863 EXPECT_EQ(kQuotaStatusOk, status()); |
864 EXPECT_EQ(50, usage()); | 864 EXPECT_EQ(50, usage()); |
865 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 865 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
866 | 866 |
867 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 867 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
868 MessageLoop::current()->RunAllPending(); | 868 MessageLoop::current()->RunUntilIdle(); |
869 EXPECT_EQ(kQuotaStatusOk, status()); | 869 EXPECT_EQ(kQuotaStatusOk, status()); |
870 EXPECT_EQ(4000, usage()); | 870 EXPECT_EQ(4000, usage()); |
871 EXPECT_EQ(QuotaManager::kNoLimit, quota()); | 871 EXPECT_EQ(QuotaManager::kNoLimit, quota()); |
872 | 872 |
873 // Revoke the unlimited rights and make sure the change is noticed. | 873 // Revoke the unlimited rights and make sure the change is noticed. |
874 mock_special_storage_policy()->Reset(); | 874 mock_special_storage_policy()->Reset(); |
875 mock_special_storage_policy()->NotifyChanged(); | 875 mock_special_storage_policy()->NotifyChanged(); |
876 | 876 |
877 GetGlobalUsage(kTemp); | 877 GetGlobalUsage(kTemp); |
878 MessageLoop::current()->RunAllPending(); | 878 MessageLoop::current()->RunUntilIdle(); |
879 EXPECT_EQ(10 + 50 + 4000, usage()); | 879 EXPECT_EQ(10 + 50 + 4000, usage()); |
880 EXPECT_EQ(0, unlimited_usage()); | 880 EXPECT_EQ(0, unlimited_usage()); |
881 | 881 |
882 GetUsageAndQuota(GURL("http://usage10/"), kTemp); | 882 GetUsageAndQuota(GURL("http://usage10/"), kTemp); |
883 MessageLoop::current()->RunAllPending(); | 883 MessageLoop::current()->RunUntilIdle(); |
884 EXPECT_EQ(kQuotaStatusOk, status()); | 884 EXPECT_EQ(kQuotaStatusOk, status()); |
885 EXPECT_EQ(10, usage()); | 885 EXPECT_EQ(10, usage()); |
886 EXPECT_EQ(10, quota()); // should be clamped to our current usage | 886 EXPECT_EQ(10, quota()); // should be clamped to our current usage |
887 | 887 |
888 GetUsageAndQuota(GURL("http://usage50/"), kTemp); | 888 GetUsageAndQuota(GURL("http://usage50/"), kTemp); |
889 MessageLoop::current()->RunAllPending(); | 889 MessageLoop::current()->RunUntilIdle(); |
890 EXPECT_EQ(kQuotaStatusOk, status()); | 890 EXPECT_EQ(kQuotaStatusOk, status()); |
891 EXPECT_EQ(50, usage()); | 891 EXPECT_EQ(50, usage()); |
892 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 892 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
893 | 893 |
894 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); | 894 GetUsageAndQuota(GURL("http://unlimited/"), kTemp); |
895 MessageLoop::current()->RunAllPending(); | 895 MessageLoop::current()->RunUntilIdle(); |
896 EXPECT_EQ(kQuotaStatusOk, status()); | 896 EXPECT_EQ(kQuotaStatusOk, status()); |
897 EXPECT_EQ(4000, usage()); | 897 EXPECT_EQ(4000, usage()); |
898 EXPECT_EQ(kPerHostQuotaFor100, quota()); | 898 EXPECT_EQ(kPerHostQuotaFor100, quota()); |
899 } | 899 } |
900 | 900 |
901 TEST_F(QuotaManagerTest, OriginInUse) { | 901 TEST_F(QuotaManagerTest, OriginInUse) { |
902 const GURL kFooOrigin("http://foo.com/"); | 902 const GURL kFooOrigin("http://foo.com/"); |
903 const GURL kBarOrigin("http://bar.com/"); | 903 const GURL kBarOrigin("http://bar.com/"); |
904 | 904 |
905 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); | 905 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); |
(...skipping 11 matching lines...) Expand all Loading... |
917 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin)); | 917 EXPECT_FALSE(quota_manager()->IsOriginInUse(kBarOrigin)); |
918 | 918 |
919 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin); | 919 quota_manager()->NotifyOriginNoLongerInUse(kFooOrigin); |
920 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); | 920 EXPECT_FALSE(quota_manager()->IsOriginInUse(kFooOrigin)); |
921 } | 921 } |
922 | 922 |
923 TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) { | 923 TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) { |
924 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | 924 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); |
925 | 925 |
926 GetPersistentHostQuota("foo.com"); | 926 GetPersistentHostQuota("foo.com"); |
927 MessageLoop::current()->RunAllPending(); | 927 MessageLoop::current()->RunUntilIdle(); |
928 EXPECT_EQ(0, quota()); | 928 EXPECT_EQ(0, quota()); |
929 | 929 |
930 SetPersistentHostQuota("foo.com", 100); | 930 SetPersistentHostQuota("foo.com", 100); |
931 MessageLoop::current()->RunAllPending(); | 931 MessageLoop::current()->RunUntilIdle(); |
932 EXPECT_EQ(100, quota()); | 932 EXPECT_EQ(100, quota()); |
933 | 933 |
934 GetPersistentHostQuota("foo.com"); | 934 GetPersistentHostQuota("foo.com"); |
935 SetPersistentHostQuota("foo.com", 200); | 935 SetPersistentHostQuota("foo.com", 200); |
936 GetPersistentHostQuota("foo.com"); | 936 GetPersistentHostQuota("foo.com"); |
937 SetPersistentHostQuota("foo.com", 300000000000ll); | 937 SetPersistentHostQuota("foo.com", 300000000000ll); |
938 GetPersistentHostQuota("foo.com"); | 938 GetPersistentHostQuota("foo.com"); |
939 MessageLoop::current()->RunAllPending(); | 939 MessageLoop::current()->RunUntilIdle(); |
940 EXPECT_EQ(300000000000ll, quota()); | 940 EXPECT_EQ(300000000000ll, quota()); |
941 } | 941 } |
942 | 942 |
943 TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) { | 943 TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) { |
944 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); | 944 RegisterClient(CreateClient(NULL, 0, QuotaClient::kFileSystem)); |
945 | 945 |
946 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 946 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
947 MessageLoop::current()->RunAllPending(); | 947 MessageLoop::current()->RunUntilIdle(); |
948 EXPECT_EQ(kQuotaStatusOk, status()); | 948 EXPECT_EQ(kQuotaStatusOk, status()); |
949 EXPECT_EQ(0, usage()); | 949 EXPECT_EQ(0, usage()); |
950 EXPECT_EQ(0, quota()); | 950 EXPECT_EQ(0, quota()); |
951 | 951 |
952 SetPersistentHostQuota("foo.com", 100); | 952 SetPersistentHostQuota("foo.com", 100); |
953 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 953 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
954 MessageLoop::current()->RunAllPending(); | 954 MessageLoop::current()->RunUntilIdle(); |
955 EXPECT_EQ(kQuotaStatusOk, status()); | 955 EXPECT_EQ(kQuotaStatusOk, status()); |
956 EXPECT_EQ(0, usage()); | 956 EXPECT_EQ(0, usage()); |
957 EXPECT_EQ(100, quota()); | 957 EXPECT_EQ(100, quota()); |
958 } | 958 } |
959 | 959 |
960 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { | 960 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_MultiOrigins) { |
961 static const MockOriginData kData[] = { | 961 static const MockOriginData kData[] = { |
962 { "http://foo.com/", kPerm, 10 }, | 962 { "http://foo.com/", kPerm, 10 }, |
963 { "http://foo.com:8080/", kPerm, 20 }, | 963 { "http://foo.com:8080/", kPerm, 20 }, |
964 { "https://foo.com/", kPerm, 13 }, | 964 { "https://foo.com/", kPerm, 13 }, |
965 { "https://foo.com:8081/", kPerm, 19 }, | 965 { "https://foo.com:8081/", kPerm, 19 }, |
966 { "http://bar.com/", kPerm, 5 }, | 966 { "http://bar.com/", kPerm, 5 }, |
967 { "https://bar.com/", kPerm, 7 }, | 967 { "https://bar.com/", kPerm, 7 }, |
968 { "http://baz.com/", kPerm, 30 }, | 968 { "http://baz.com/", kPerm, 30 }, |
969 { "http://foo.com/", kTemp, 40 }, | 969 { "http://foo.com/", kTemp, 40 }, |
970 }; | 970 }; |
971 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 971 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
972 QuotaClient::kFileSystem)); | 972 QuotaClient::kFileSystem)); |
973 | 973 |
974 SetPersistentHostQuota("foo.com", 100); | 974 SetPersistentHostQuota("foo.com", 100); |
975 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 975 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
976 MessageLoop::current()->RunAllPending(); | 976 MessageLoop::current()->RunUntilIdle(); |
977 EXPECT_EQ(kQuotaStatusOk, status()); | 977 EXPECT_EQ(kQuotaStatusOk, status()); |
978 EXPECT_EQ(10 + 20 + 13 + 19, usage()); | 978 EXPECT_EQ(10 + 20 + 13 + 19, usage()); |
979 EXPECT_EQ(100, quota()); | 979 EXPECT_EQ(100, quota()); |
980 } | 980 } |
981 | 981 |
982 TEST_F(QuotaManagerTest, GetPersistentUsage_WithModify) { | 982 TEST_F(QuotaManagerTest, GetPersistentUsage_WithModify) { |
983 GetUsage_WithModifyTestBody(kPerm); | 983 GetUsage_WithModifyTestBody(kPerm); |
984 } | 984 } |
985 | 985 |
986 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) { | 986 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_WithAdditionalTasks) { |
987 static const MockOriginData kData[] = { | 987 static const MockOriginData kData[] = { |
988 { "http://foo.com/", kPerm, 10 }, | 988 { "http://foo.com/", kPerm, 10 }, |
989 { "http://foo.com:8080/", kPerm, 20 }, | 989 { "http://foo.com:8080/", kPerm, 20 }, |
990 { "http://bar.com/", kPerm, 13 }, | 990 { "http://bar.com/", kPerm, 13 }, |
991 { "http://foo.com/", kTemp, 40 }, | 991 { "http://foo.com/", kTemp, 40 }, |
992 }; | 992 }; |
993 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 993 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
994 QuotaClient::kFileSystem)); | 994 QuotaClient::kFileSystem)); |
995 SetPersistentHostQuota("foo.com", 100); | 995 SetPersistentHostQuota("foo.com", 100); |
996 | 996 |
997 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 997 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
998 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 998 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
999 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 999 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
1000 MessageLoop::current()->RunAllPending(); | 1000 MessageLoop::current()->RunUntilIdle(); |
1001 EXPECT_EQ(kQuotaStatusOk, status()); | 1001 EXPECT_EQ(kQuotaStatusOk, status()); |
1002 EXPECT_EQ(10 + 20, usage()); | 1002 EXPECT_EQ(10 + 20, usage()); |
1003 EXPECT_EQ(100, quota()); | 1003 EXPECT_EQ(100, quota()); |
1004 | 1004 |
1005 set_additional_callback_count(0); | 1005 set_additional_callback_count(0); |
1006 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), | 1006 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), |
1007 kPerm); | 1007 kPerm); |
1008 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 1008 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
1009 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); | 1009 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); |
1010 MessageLoop::current()->RunAllPending(); | 1010 MessageLoop::current()->RunUntilIdle(); |
1011 EXPECT_EQ(kQuotaStatusOk, status()); | 1011 EXPECT_EQ(kQuotaStatusOk, status()); |
1012 EXPECT_EQ(10 + 20, usage()); | 1012 EXPECT_EQ(10 + 20, usage()); |
1013 EXPECT_EQ(2, additional_callback_count()); | 1013 EXPECT_EQ(2, additional_callback_count()); |
1014 } | 1014 } |
1015 | 1015 |
1016 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) { | 1016 TEST_F(QuotaManagerTest, GetPersistentUsageAndQuota_NukeManager) { |
1017 static const MockOriginData kData[] = { | 1017 static const MockOriginData kData[] = { |
1018 { "http://foo.com/", kPerm, 10 }, | 1018 { "http://foo.com/", kPerm, 10 }, |
1019 { "http://foo.com:8080/", kPerm, 20 }, | 1019 { "http://foo.com:8080/", kPerm, 20 }, |
1020 { "http://bar.com/", kPerm, 13 }, | 1020 { "http://bar.com/", kPerm, 13 }, |
1021 { "http://foo.com/", kTemp, 40 }, | 1021 { "http://foo.com/", kTemp, 40 }, |
1022 }; | 1022 }; |
1023 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1023 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1024 QuotaClient::kFileSystem)); | 1024 QuotaClient::kFileSystem)); |
1025 SetPersistentHostQuota("foo.com", 100); | 1025 SetPersistentHostQuota("foo.com", 100); |
1026 | 1026 |
1027 set_additional_callback_count(0); | 1027 set_additional_callback_count(0); |
1028 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); | 1028 GetUsageAndQuota(GURL("http://foo.com/"), kPerm); |
1029 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), kPerm); | 1029 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), kPerm); |
1030 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); | 1030 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), kPerm); |
1031 | 1031 |
1032 // Nuke before waiting for callbacks. | 1032 // Nuke before waiting for callbacks. |
1033 set_quota_manager(NULL); | 1033 set_quota_manager(NULL); |
1034 MessageLoop::current()->RunAllPending(); | 1034 MessageLoop::current()->RunUntilIdle(); |
1035 EXPECT_EQ(kQuotaErrorAbort, status()); | 1035 EXPECT_EQ(kQuotaErrorAbort, status()); |
1036 } | 1036 } |
1037 | 1037 |
1038 TEST_F(QuotaManagerTest, GetUsage_Simple) { | 1038 TEST_F(QuotaManagerTest, GetUsage_Simple) { |
1039 static const MockOriginData kData[] = { | 1039 static const MockOriginData kData[] = { |
1040 { "http://foo.com/", kPerm, 1 }, | 1040 { "http://foo.com/", kPerm, 1 }, |
1041 { "http://foo.com:1/", kPerm, 20 }, | 1041 { "http://foo.com:1/", kPerm, 20 }, |
1042 { "http://bar.com/", kTemp, 300 }, | 1042 { "http://bar.com/", kTemp, 300 }, |
1043 { "https://buz.com/", kTemp, 4000 }, | 1043 { "https://buz.com/", kTemp, 4000 }, |
1044 { "http://buz.com/", kTemp, 50000 }, | 1044 { "http://buz.com/", kTemp, 50000 }, |
1045 { "http://bar.com:1/", kPerm, 600000 }, | 1045 { "http://bar.com:1/", kPerm, 600000 }, |
1046 { "http://foo.com/", kTemp, 7000000 }, | 1046 { "http://foo.com/", kTemp, 7000000 }, |
1047 }; | 1047 }; |
1048 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1048 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1049 QuotaClient::kFileSystem)); | 1049 QuotaClient::kFileSystem)); |
1050 | 1050 |
1051 GetGlobalUsage(kPerm); | 1051 GetGlobalUsage(kPerm); |
1052 MessageLoop::current()->RunAllPending(); | 1052 MessageLoop::current()->RunUntilIdle(); |
1053 EXPECT_EQ(usage(), 1 + 20 + 600000); | 1053 EXPECT_EQ(usage(), 1 + 20 + 600000); |
1054 EXPECT_EQ(0, unlimited_usage()); | 1054 EXPECT_EQ(0, unlimited_usage()); |
1055 | 1055 |
1056 GetGlobalUsage(kTemp); | 1056 GetGlobalUsage(kTemp); |
1057 MessageLoop::current()->RunAllPending(); | 1057 MessageLoop::current()->RunUntilIdle(); |
1058 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); | 1058 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); |
1059 EXPECT_EQ(0, unlimited_usage()); | 1059 EXPECT_EQ(0, unlimited_usage()); |
1060 | 1060 |
1061 GetHostUsage("foo.com", kPerm); | 1061 GetHostUsage("foo.com", kPerm); |
1062 MessageLoop::current()->RunAllPending(); | 1062 MessageLoop::current()->RunUntilIdle(); |
1063 EXPECT_EQ(usage(), 1 + 20); | 1063 EXPECT_EQ(usage(), 1 + 20); |
1064 | 1064 |
1065 GetHostUsage("buz.com", kTemp); | 1065 GetHostUsage("buz.com", kTemp); |
1066 MessageLoop::current()->RunAllPending(); | 1066 MessageLoop::current()->RunUntilIdle(); |
1067 EXPECT_EQ(usage(), 4000 + 50000); | 1067 EXPECT_EQ(usage(), 4000 + 50000); |
1068 } | 1068 } |
1069 | 1069 |
1070 TEST_F(QuotaManagerTest, GetUsage_WithModification) { | 1070 TEST_F(QuotaManagerTest, GetUsage_WithModification) { |
1071 static const MockOriginData kData[] = { | 1071 static const MockOriginData kData[] = { |
1072 { "http://foo.com/", kPerm, 1 }, | 1072 { "http://foo.com/", kPerm, 1 }, |
1073 { "http://foo.com:1/", kPerm, 20 }, | 1073 { "http://foo.com:1/", kPerm, 20 }, |
1074 { "http://bar.com/", kTemp, 300 }, | 1074 { "http://bar.com/", kTemp, 300 }, |
1075 { "https://buz.com/", kTemp, 4000 }, | 1075 { "https://buz.com/", kTemp, 4000 }, |
1076 { "http://buz.com/", kTemp, 50000 }, | 1076 { "http://buz.com/", kTemp, 50000 }, |
1077 { "http://bar.com:1/", kPerm, 600000 }, | 1077 { "http://bar.com:1/", kPerm, 600000 }, |
1078 { "http://foo.com/", kTemp, 7000000 }, | 1078 { "http://foo.com/", kTemp, 7000000 }, |
1079 }; | 1079 }; |
1080 | 1080 |
1081 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1081 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1082 QuotaClient::kFileSystem); | 1082 QuotaClient::kFileSystem); |
1083 RegisterClient(client); | 1083 RegisterClient(client); |
1084 | 1084 |
1085 GetGlobalUsage(kPerm); | 1085 GetGlobalUsage(kPerm); |
1086 MessageLoop::current()->RunAllPending(); | 1086 MessageLoop::current()->RunUntilIdle(); |
1087 EXPECT_EQ(usage(), 1 + 20 + 600000); | 1087 EXPECT_EQ(usage(), 1 + 20 + 600000); |
1088 EXPECT_EQ(0, unlimited_usage()); | 1088 EXPECT_EQ(0, unlimited_usage()); |
1089 | 1089 |
1090 client->ModifyOriginAndNotify( | 1090 client->ModifyOriginAndNotify( |
1091 GURL("http://foo.com/"), kPerm, 80000000); | 1091 GURL("http://foo.com/"), kPerm, 80000000); |
1092 | 1092 |
1093 GetGlobalUsage(kPerm); | 1093 GetGlobalUsage(kPerm); |
1094 MessageLoop::current()->RunAllPending(); | 1094 MessageLoop::current()->RunUntilIdle(); |
1095 EXPECT_EQ(usage(), 1 + 20 + 600000 + 80000000); | 1095 EXPECT_EQ(usage(), 1 + 20 + 600000 + 80000000); |
1096 EXPECT_EQ(0, unlimited_usage()); | 1096 EXPECT_EQ(0, unlimited_usage()); |
1097 | 1097 |
1098 GetGlobalUsage(kTemp); | 1098 GetGlobalUsage(kTemp); |
1099 MessageLoop::current()->RunAllPending(); | 1099 MessageLoop::current()->RunUntilIdle(); |
1100 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); | 1100 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000); |
1101 EXPECT_EQ(0, unlimited_usage()); | 1101 EXPECT_EQ(0, unlimited_usage()); |
1102 | 1102 |
1103 client->ModifyOriginAndNotify( | 1103 client->ModifyOriginAndNotify( |
1104 GURL("http://foo.com/"), kTemp, 1); | 1104 GURL("http://foo.com/"), kTemp, 1); |
1105 | 1105 |
1106 GetGlobalUsage(kTemp); | 1106 GetGlobalUsage(kTemp); |
1107 MessageLoop::current()->RunAllPending(); | 1107 MessageLoop::current()->RunUntilIdle(); |
1108 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000 + 1); | 1108 EXPECT_EQ(usage(), 300 + 4000 + 50000 + 7000000 + 1); |
1109 EXPECT_EQ(0, unlimited_usage()); | 1109 EXPECT_EQ(0, unlimited_usage()); |
1110 | 1110 |
1111 GetHostUsage("buz.com", kTemp); | 1111 GetHostUsage("buz.com", kTemp); |
1112 MessageLoop::current()->RunAllPending(); | 1112 MessageLoop::current()->RunUntilIdle(); |
1113 EXPECT_EQ(usage(), 4000 + 50000); | 1113 EXPECT_EQ(usage(), 4000 + 50000); |
1114 | 1114 |
1115 client->ModifyOriginAndNotify( | 1115 client->ModifyOriginAndNotify( |
1116 GURL("http://buz.com/"), kTemp, 900000000); | 1116 GURL("http://buz.com/"), kTemp, 900000000); |
1117 | 1117 |
1118 GetHostUsage("buz.com", kTemp); | 1118 GetHostUsage("buz.com", kTemp); |
1119 MessageLoop::current()->RunAllPending(); | 1119 MessageLoop::current()->RunUntilIdle(); |
1120 EXPECT_EQ(usage(), 4000 + 50000 + 900000000); | 1120 EXPECT_EQ(usage(), 4000 + 50000 + 900000000); |
1121 } | 1121 } |
1122 | 1122 |
1123 TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) { | 1123 TEST_F(QuotaManagerTest, GetUsage_WithDeleteOrigin) { |
1124 static const MockOriginData kData[] = { | 1124 static const MockOriginData kData[] = { |
1125 { "http://foo.com/", kTemp, 1 }, | 1125 { "http://foo.com/", kTemp, 1 }, |
1126 { "http://foo.com:1/", kTemp, 20 }, | 1126 { "http://foo.com:1/", kTemp, 20 }, |
1127 { "http://foo.com/", kPerm, 300 }, | 1127 { "http://foo.com/", kPerm, 300 }, |
1128 { "http://bar.com/", kTemp, 4000 }, | 1128 { "http://bar.com/", kTemp, 4000 }, |
1129 }; | 1129 }; |
1130 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1130 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1131 QuotaClient::kFileSystem); | 1131 QuotaClient::kFileSystem); |
1132 RegisterClient(client); | 1132 RegisterClient(client); |
1133 | 1133 |
1134 GetGlobalUsage(kTemp); | 1134 GetGlobalUsage(kTemp); |
1135 MessageLoop::current()->RunAllPending(); | 1135 MessageLoop::current()->RunUntilIdle(); |
1136 int64 predelete_global_tmp = usage(); | 1136 int64 predelete_global_tmp = usage(); |
1137 | 1137 |
1138 GetHostUsage("foo.com", kTemp); | 1138 GetHostUsage("foo.com", kTemp); |
1139 MessageLoop::current()->RunAllPending(); | 1139 MessageLoop::current()->RunUntilIdle(); |
1140 int64 predelete_host_tmp = usage(); | 1140 int64 predelete_host_tmp = usage(); |
1141 | 1141 |
1142 GetHostUsage("foo.com", kPerm); | 1142 GetHostUsage("foo.com", kPerm); |
1143 MessageLoop::current()->RunAllPending(); | 1143 MessageLoop::current()->RunUntilIdle(); |
1144 int64 predelete_host_pers = usage(); | 1144 int64 predelete_host_pers = usage(); |
1145 | 1145 |
1146 DeleteClientOriginData(client, GURL("http://foo.com/"), | 1146 DeleteClientOriginData(client, GURL("http://foo.com/"), |
1147 kTemp); | 1147 kTemp); |
1148 MessageLoop::current()->RunAllPending(); | 1148 MessageLoop::current()->RunUntilIdle(); |
1149 EXPECT_EQ(kQuotaStatusOk, status()); | 1149 EXPECT_EQ(kQuotaStatusOk, status()); |
1150 | 1150 |
1151 GetGlobalUsage(kTemp); | 1151 GetGlobalUsage(kTemp); |
1152 MessageLoop::current()->RunAllPending(); | 1152 MessageLoop::current()->RunUntilIdle(); |
1153 EXPECT_EQ(predelete_global_tmp - 1, usage()); | 1153 EXPECT_EQ(predelete_global_tmp - 1, usage()); |
1154 | 1154 |
1155 GetHostUsage("foo.com", kTemp); | 1155 GetHostUsage("foo.com", kTemp); |
1156 MessageLoop::current()->RunAllPending(); | 1156 MessageLoop::current()->RunUntilIdle(); |
1157 EXPECT_EQ(predelete_host_tmp - 1, usage()); | 1157 EXPECT_EQ(predelete_host_tmp - 1, usage()); |
1158 | 1158 |
1159 GetHostUsage("foo.com", kPerm); | 1159 GetHostUsage("foo.com", kPerm); |
1160 MessageLoop::current()->RunAllPending(); | 1160 MessageLoop::current()->RunUntilIdle(); |
1161 EXPECT_EQ(predelete_host_pers, usage()); | 1161 EXPECT_EQ(predelete_host_pers, usage()); |
1162 } | 1162 } |
1163 | 1163 |
1164 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { | 1164 TEST_F(QuotaManagerTest, GetAvailableSpaceTest) { |
1165 GetAvailableSpace(); | 1165 GetAvailableSpace(); |
1166 MessageLoop::current()->RunAllPending(); | 1166 MessageLoop::current()->RunUntilIdle(); |
1167 EXPECT_EQ(kQuotaStatusOk, status()); | 1167 EXPECT_EQ(kQuotaStatusOk, status()); |
1168 EXPECT_LE(0, available_space()); | 1168 EXPECT_LE(0, available_space()); |
1169 } | 1169 } |
1170 | 1170 |
1171 TEST_F(QuotaManagerTest, EvictOriginData) { | 1171 TEST_F(QuotaManagerTest, EvictOriginData) { |
1172 static const MockOriginData kData1[] = { | 1172 static const MockOriginData kData1[] = { |
1173 { "http://foo.com/", kTemp, 1 }, | 1173 { "http://foo.com/", kTemp, 1 }, |
1174 { "http://foo.com:1/", kTemp, 20 }, | 1174 { "http://foo.com:1/", kTemp, 20 }, |
1175 { "http://foo.com/", kPerm, 300 }, | 1175 { "http://foo.com/", kPerm, 300 }, |
1176 { "http://bar.com/", kTemp, 4000 }, | 1176 { "http://bar.com/", kTemp, 4000 }, |
1177 }; | 1177 }; |
1178 static const MockOriginData kData2[] = { | 1178 static const MockOriginData kData2[] = { |
1179 { "http://foo.com/", kTemp, 50000 }, | 1179 { "http://foo.com/", kTemp, 50000 }, |
1180 { "http://foo.com:1/", kTemp, 6000 }, | 1180 { "http://foo.com:1/", kTemp, 6000 }, |
1181 { "http://foo.com/", kPerm, 700 }, | 1181 { "http://foo.com/", kPerm, 700 }, |
1182 { "https://foo.com/", kTemp, 80 }, | 1182 { "https://foo.com/", kTemp, 80 }, |
1183 { "http://bar.com/", kTemp, 9 }, | 1183 { "http://bar.com/", kTemp, 9 }, |
1184 }; | 1184 }; |
1185 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 1185 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
1186 QuotaClient::kFileSystem); | 1186 QuotaClient::kFileSystem); |
1187 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 1187 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
1188 QuotaClient::kDatabase); | 1188 QuotaClient::kDatabase); |
1189 RegisterClient(client1); | 1189 RegisterClient(client1); |
1190 RegisterClient(client2); | 1190 RegisterClient(client2); |
1191 | 1191 |
1192 GetGlobalUsage(kTemp); | 1192 GetGlobalUsage(kTemp); |
1193 MessageLoop::current()->RunAllPending(); | 1193 MessageLoop::current()->RunUntilIdle(); |
1194 int64 predelete_global_tmp = usage(); | 1194 int64 predelete_global_tmp = usage(); |
1195 | 1195 |
1196 GetHostUsage("foo.com", kTemp); | 1196 GetHostUsage("foo.com", kTemp); |
1197 MessageLoop::current()->RunAllPending(); | 1197 MessageLoop::current()->RunUntilIdle(); |
1198 int64 predelete_host_tmp = usage(); | 1198 int64 predelete_host_tmp = usage(); |
1199 | 1199 |
1200 GetHostUsage("foo.com", kPerm); | 1200 GetHostUsage("foo.com", kPerm); |
1201 MessageLoop::current()->RunAllPending(); | 1201 MessageLoop::current()->RunUntilIdle(); |
1202 int64 predelete_host_pers = usage(); | 1202 int64 predelete_host_pers = usage(); |
1203 | 1203 |
1204 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i) | 1204 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i) |
1205 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | 1205 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, |
1206 GURL(kData1[i].origin), kData1[i].type); | 1206 GURL(kData1[i].origin), kData1[i].type); |
1207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) | 1207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) |
1208 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | 1208 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, |
1209 GURL(kData2[i].origin), kData2[i].type); | 1209 GURL(kData2[i].origin), kData2[i].type); |
1210 MessageLoop::current()->RunAllPending(); | 1210 MessageLoop::current()->RunUntilIdle(); |
1211 | 1211 |
1212 EvictOriginData(GURL("http://foo.com/"), kTemp); | 1212 EvictOriginData(GURL("http://foo.com/"), kTemp); |
1213 MessageLoop::current()->RunAllPending(); | 1213 MessageLoop::current()->RunUntilIdle(); |
1214 | 1214 |
1215 DumpOriginInfoTable(); | 1215 DumpOriginInfoTable(); |
1216 MessageLoop::current()->RunAllPending(); | 1216 MessageLoop::current()->RunUntilIdle(); |
1217 | 1217 |
1218 typedef OriginInfoTableEntries::const_iterator iterator; | 1218 typedef OriginInfoTableEntries::const_iterator iterator; |
1219 for (iterator itr(origin_info_entries().begin()), | 1219 for (iterator itr(origin_info_entries().begin()), |
1220 end(origin_info_entries().end()); | 1220 end(origin_info_entries().end()); |
1221 itr != end; ++itr) { | 1221 itr != end; ++itr) { |
1222 if (itr->type == kTemp) | 1222 if (itr->type == kTemp) |
1223 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | 1223 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); |
1224 } | 1224 } |
1225 | 1225 |
1226 GetGlobalUsage(kTemp); | 1226 GetGlobalUsage(kTemp); |
1227 MessageLoop::current()->RunAllPending(); | 1227 MessageLoop::current()->RunUntilIdle(); |
1228 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); | 1228 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); |
1229 | 1229 |
1230 GetHostUsage("foo.com", kTemp); | 1230 GetHostUsage("foo.com", kTemp); |
1231 MessageLoop::current()->RunAllPending(); | 1231 MessageLoop::current()->RunUntilIdle(); |
1232 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); | 1232 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); |
1233 | 1233 |
1234 GetHostUsage("foo.com", kPerm); | 1234 GetHostUsage("foo.com", kPerm); |
1235 MessageLoop::current()->RunAllPending(); | 1235 MessageLoop::current()->RunUntilIdle(); |
1236 EXPECT_EQ(predelete_host_pers, usage()); | 1236 EXPECT_EQ(predelete_host_pers, usage()); |
1237 } | 1237 } |
1238 | 1238 |
1239 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { | 1239 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { |
1240 static const MockOriginData kData[] = { | 1240 static const MockOriginData kData[] = { |
1241 { "http://foo.com/", kTemp, 1 }, | 1241 { "http://foo.com/", kTemp, 1 }, |
1242 { "http://foo.com:1/", kTemp, 20 }, | 1242 { "http://foo.com:1/", kTemp, 20 }, |
1243 { "http://foo.com/", kPerm, 300 }, | 1243 { "http://foo.com/", kPerm, 300 }, |
1244 { "http://bar.com/", kTemp, 4000 }, | 1244 { "http://bar.com/", kTemp, 4000 }, |
1245 }; | 1245 }; |
1246 static const int kNumberOfTemporaryOrigins = 3; | 1246 static const int kNumberOfTemporaryOrigins = 3; |
1247 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1247 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1248 QuotaClient::kFileSystem); | 1248 QuotaClient::kFileSystem); |
1249 RegisterClient(client); | 1249 RegisterClient(client); |
1250 | 1250 |
1251 GetGlobalUsage(kTemp); | 1251 GetGlobalUsage(kTemp); |
1252 MessageLoop::current()->RunAllPending(); | 1252 MessageLoop::current()->RunUntilIdle(); |
1253 int64 predelete_global_tmp = usage(); | 1253 int64 predelete_global_tmp = usage(); |
1254 | 1254 |
1255 GetHostUsage("foo.com", kTemp); | 1255 GetHostUsage("foo.com", kTemp); |
1256 MessageLoop::current()->RunAllPending(); | 1256 MessageLoop::current()->RunUntilIdle(); |
1257 int64 predelete_host_tmp = usage(); | 1257 int64 predelete_host_tmp = usage(); |
1258 | 1258 |
1259 GetHostUsage("foo.com", kPerm); | 1259 GetHostUsage("foo.com", kPerm); |
1260 MessageLoop::current()->RunAllPending(); | 1260 MessageLoop::current()->RunUntilIdle(); |
1261 int64 predelete_host_pers = usage(); | 1261 int64 predelete_host_pers = usage(); |
1262 | 1262 |
1263 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) | 1263 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) |
1264 NotifyStorageAccessed(client, GURL(kData[i].origin), kData[i].type); | 1264 NotifyStorageAccessed(client, GURL(kData[i].origin), kData[i].type); |
1265 MessageLoop::current()->RunAllPending(); | 1265 MessageLoop::current()->RunUntilIdle(); |
1266 | 1266 |
1267 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp); | 1267 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp); |
1268 | 1268 |
1269 for (int i = 0; | 1269 for (int i = 0; |
1270 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1; | 1270 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1; |
1271 ++i) { | 1271 ++i) { |
1272 EvictOriginData(GURL("http://foo.com/"), kTemp); | 1272 EvictOriginData(GURL("http://foo.com/"), kTemp); |
1273 MessageLoop::current()->RunAllPending(); | 1273 MessageLoop::current()->RunUntilIdle(); |
1274 EXPECT_EQ(kQuotaErrorInvalidModification, status()); | 1274 EXPECT_EQ(kQuotaErrorInvalidModification, status()); |
1275 } | 1275 } |
1276 | 1276 |
1277 DumpOriginInfoTable(); | 1277 DumpOriginInfoTable(); |
1278 MessageLoop::current()->RunAllPending(); | 1278 MessageLoop::current()->RunUntilIdle(); |
1279 | 1279 |
1280 bool found_origin_in_database = false; | 1280 bool found_origin_in_database = false; |
1281 typedef OriginInfoTableEntries::const_iterator iterator; | 1281 typedef OriginInfoTableEntries::const_iterator iterator; |
1282 for (iterator itr(origin_info_entries().begin()), | 1282 for (iterator itr(origin_info_entries().begin()), |
1283 end(origin_info_entries().end()); | 1283 end(origin_info_entries().end()); |
1284 itr != end; ++itr) { | 1284 itr != end; ++itr) { |
1285 if (itr->type == kTemp && | 1285 if (itr->type == kTemp && |
1286 GURL("http://foo.com/") == itr->origin) { | 1286 GURL("http://foo.com/") == itr->origin) { |
1287 found_origin_in_database = true; | 1287 found_origin_in_database = true; |
1288 break; | 1288 break; |
1289 } | 1289 } |
1290 } | 1290 } |
1291 // The origin "http://foo.com/" should be in the database. | 1291 // The origin "http://foo.com/" should be in the database. |
1292 EXPECT_TRUE(found_origin_in_database); | 1292 EXPECT_TRUE(found_origin_in_database); |
1293 | 1293 |
1294 for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) { | 1294 for (size_t i = 0; i < kNumberOfTemporaryOrigins - 1; ++i) { |
1295 GetLRUOrigin(kTemp); | 1295 GetLRUOrigin(kTemp); |
1296 MessageLoop::current()->RunAllPending(); | 1296 MessageLoop::current()->RunUntilIdle(); |
1297 EXPECT_FALSE(lru_origin().is_empty()); | 1297 EXPECT_FALSE(lru_origin().is_empty()); |
1298 // The origin "http://foo.com/" should not be in the LRU list. | 1298 // The origin "http://foo.com/" should not be in the LRU list. |
1299 EXPECT_NE(std::string("http://foo.com/"), lru_origin().spec()); | 1299 EXPECT_NE(std::string("http://foo.com/"), lru_origin().spec()); |
1300 DeleteOriginFromDatabase(lru_origin(), kTemp); | 1300 DeleteOriginFromDatabase(lru_origin(), kTemp); |
1301 MessageLoop::current()->RunAllPending(); | 1301 MessageLoop::current()->RunUntilIdle(); |
1302 } | 1302 } |
1303 | 1303 |
1304 // Now the LRU list must be empty. | 1304 // Now the LRU list must be empty. |
1305 GetLRUOrigin(kTemp); | 1305 GetLRUOrigin(kTemp); |
1306 MessageLoop::current()->RunAllPending(); | 1306 MessageLoop::current()->RunUntilIdle(); |
1307 EXPECT_TRUE(lru_origin().is_empty()); | 1307 EXPECT_TRUE(lru_origin().is_empty()); |
1308 | 1308 |
1309 // Deleting origins from the database should not affect the results of the | 1309 // Deleting origins from the database should not affect the results of the |
1310 // following checks. | 1310 // following checks. |
1311 GetGlobalUsage(kTemp); | 1311 GetGlobalUsage(kTemp); |
1312 MessageLoop::current()->RunAllPending(); | 1312 MessageLoop::current()->RunUntilIdle(); |
1313 EXPECT_EQ(predelete_global_tmp, usage()); | 1313 EXPECT_EQ(predelete_global_tmp, usage()); |
1314 | 1314 |
1315 GetHostUsage("foo.com", kTemp); | 1315 GetHostUsage("foo.com", kTemp); |
1316 MessageLoop::current()->RunAllPending(); | 1316 MessageLoop::current()->RunUntilIdle(); |
1317 EXPECT_EQ(predelete_host_tmp, usage()); | 1317 EXPECT_EQ(predelete_host_tmp, usage()); |
1318 | 1318 |
1319 GetHostUsage("foo.com", kPerm); | 1319 GetHostUsage("foo.com", kPerm); |
1320 MessageLoop::current()->RunAllPending(); | 1320 MessageLoop::current()->RunUntilIdle(); |
1321 EXPECT_EQ(predelete_host_pers, usage()); | 1321 EXPECT_EQ(predelete_host_pers, usage()); |
1322 } | 1322 } |
1323 | 1323 |
1324 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { | 1324 TEST_F(QuotaManagerTest, GetUsageAndQuotaForEviction) { |
1325 static const MockOriginData kData[] = { | 1325 static const MockOriginData kData[] = { |
1326 { "http://foo.com/", kTemp, 1 }, | 1326 { "http://foo.com/", kTemp, 1 }, |
1327 { "http://foo.com:1/", kTemp, 20 }, | 1327 { "http://foo.com:1/", kTemp, 20 }, |
1328 { "http://foo.com/", kPerm, 300 }, | 1328 { "http://foo.com/", kPerm, 300 }, |
1329 { "http://unlimited/", kTemp, 4000 }, | 1329 { "http://unlimited/", kTemp, 4000 }, |
1330 }; | 1330 }; |
1331 | 1331 |
1332 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); | 1332 mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/")); |
1333 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1333 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1334 QuotaClient::kFileSystem); | 1334 QuotaClient::kFileSystem); |
1335 RegisterClient(client); | 1335 RegisterClient(client); |
1336 | 1336 |
1337 SetTemporaryGlobalQuota(10000000); | 1337 SetTemporaryGlobalQuota(10000000); |
1338 MessageLoop::current()->RunAllPending(); | 1338 MessageLoop::current()->RunUntilIdle(); |
1339 | 1339 |
1340 GetUsageAndQuotaForEviction(); | 1340 GetUsageAndQuotaForEviction(); |
1341 MessageLoop::current()->RunAllPending(); | 1341 MessageLoop::current()->RunUntilIdle(); |
1342 EXPECT_EQ(kQuotaStatusOk, status()); | 1342 EXPECT_EQ(kQuotaStatusOk, status()); |
1343 EXPECT_EQ(4021, usage()); | 1343 EXPECT_EQ(4021, usage()); |
1344 EXPECT_EQ(4000, unlimited_usage()); | 1344 EXPECT_EQ(4000, unlimited_usage()); |
1345 EXPECT_EQ(10000000, quota()); | 1345 EXPECT_EQ(10000000, quota()); |
1346 EXPECT_LE(0, available_space()); | 1346 EXPECT_LE(0, available_space()); |
1347 } | 1347 } |
1348 | 1348 |
1349 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { | 1349 TEST_F(QuotaManagerTest, DeleteHostDataSimple) { |
1350 static const MockOriginData kData[] = { | 1350 static const MockOriginData kData[] = { |
1351 { "http://foo.com/", kTemp, 1 }, | 1351 { "http://foo.com/", kTemp, 1 }, |
1352 }; | 1352 }; |
1353 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1353 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1354 QuotaClient::kFileSystem); | 1354 QuotaClient::kFileSystem); |
1355 RegisterClient(client); | 1355 RegisterClient(client); |
1356 | 1356 |
1357 GetGlobalUsage(kTemp); | 1357 GetGlobalUsage(kTemp); |
1358 MessageLoop::current()->RunAllPending(); | 1358 MessageLoop::current()->RunUntilIdle(); |
1359 const int64 predelete_global_tmp = usage(); | 1359 const int64 predelete_global_tmp = usage(); |
1360 | 1360 |
1361 GetHostUsage("foo.com", kTemp); | 1361 GetHostUsage("foo.com", kTemp); |
1362 MessageLoop::current()->RunAllPending(); | 1362 MessageLoop::current()->RunUntilIdle(); |
1363 int64 predelete_host_tmp = usage(); | 1363 int64 predelete_host_tmp = usage(); |
1364 | 1364 |
1365 GetHostUsage("foo.com", kPerm); | 1365 GetHostUsage("foo.com", kPerm); |
1366 MessageLoop::current()->RunAllPending(); | 1366 MessageLoop::current()->RunUntilIdle(); |
1367 int64 predelete_host_pers = usage(); | 1367 int64 predelete_host_pers = usage(); |
1368 | 1368 |
1369 DeleteHostData("", kTemp, kAllClients); | 1369 DeleteHostData("", kTemp, kAllClients); |
1370 MessageLoop::current()->RunAllPending(); | 1370 MessageLoop::current()->RunUntilIdle(); |
1371 EXPECT_EQ(kQuotaStatusOk, status()); | 1371 EXPECT_EQ(kQuotaStatusOk, status()); |
1372 | 1372 |
1373 GetGlobalUsage(kTemp); | 1373 GetGlobalUsage(kTemp); |
1374 MessageLoop::current()->RunAllPending(); | 1374 MessageLoop::current()->RunUntilIdle(); |
1375 EXPECT_EQ(predelete_global_tmp, usage()); | 1375 EXPECT_EQ(predelete_global_tmp, usage()); |
1376 | 1376 |
1377 GetHostUsage("foo.com", kTemp); | 1377 GetHostUsage("foo.com", kTemp); |
1378 MessageLoop::current()->RunAllPending(); | 1378 MessageLoop::current()->RunUntilIdle(); |
1379 EXPECT_EQ(predelete_host_tmp, usage()); | 1379 EXPECT_EQ(predelete_host_tmp, usage()); |
1380 | 1380 |
1381 GetHostUsage("foo.com", kPerm); | 1381 GetHostUsage("foo.com", kPerm); |
1382 MessageLoop::current()->RunAllPending(); | 1382 MessageLoop::current()->RunUntilIdle(); |
1383 EXPECT_EQ(predelete_host_pers, usage()); | 1383 EXPECT_EQ(predelete_host_pers, usage()); |
1384 | 1384 |
1385 DeleteHostData("foo.com", kTemp, kAllClients); | 1385 DeleteHostData("foo.com", kTemp, kAllClients); |
1386 MessageLoop::current()->RunAllPending(); | 1386 MessageLoop::current()->RunUntilIdle(); |
1387 EXPECT_EQ(kQuotaStatusOk, status()); | 1387 EXPECT_EQ(kQuotaStatusOk, status()); |
1388 | 1388 |
1389 GetGlobalUsage(kTemp); | 1389 GetGlobalUsage(kTemp); |
1390 MessageLoop::current()->RunAllPending(); | 1390 MessageLoop::current()->RunUntilIdle(); |
1391 EXPECT_EQ(predelete_global_tmp - 1, usage()); | 1391 EXPECT_EQ(predelete_global_tmp - 1, usage()); |
1392 | 1392 |
1393 GetHostUsage("foo.com", kTemp); | 1393 GetHostUsage("foo.com", kTemp); |
1394 MessageLoop::current()->RunAllPending(); | 1394 MessageLoop::current()->RunUntilIdle(); |
1395 EXPECT_EQ(predelete_host_tmp - 1, usage()); | 1395 EXPECT_EQ(predelete_host_tmp - 1, usage()); |
1396 | 1396 |
1397 GetHostUsage("foo.com", kPerm); | 1397 GetHostUsage("foo.com", kPerm); |
1398 MessageLoop::current()->RunAllPending(); | 1398 MessageLoop::current()->RunUntilIdle(); |
1399 EXPECT_EQ(predelete_host_pers, usage()); | 1399 EXPECT_EQ(predelete_host_pers, usage()); |
1400 } | 1400 } |
1401 | 1401 |
1402 TEST_F(QuotaManagerTest, DeleteHostDataMultiple) { | 1402 TEST_F(QuotaManagerTest, DeleteHostDataMultiple) { |
1403 static const MockOriginData kData1[] = { | 1403 static const MockOriginData kData1[] = { |
1404 { "http://foo.com/", kTemp, 1 }, | 1404 { "http://foo.com/", kTemp, 1 }, |
1405 { "http://foo.com:1/", kTemp, 20 }, | 1405 { "http://foo.com:1/", kTemp, 20 }, |
1406 { "http://foo.com/", kPerm, 300 }, | 1406 { "http://foo.com/", kPerm, 300 }, |
1407 { "http://bar.com/", kTemp, 4000 }, | 1407 { "http://bar.com/", kTemp, 4000 }, |
1408 }; | 1408 }; |
1409 static const MockOriginData kData2[] = { | 1409 static const MockOriginData kData2[] = { |
1410 { "http://foo.com/", kTemp, 50000 }, | 1410 { "http://foo.com/", kTemp, 50000 }, |
1411 { "http://foo.com:1/", kTemp, 6000 }, | 1411 { "http://foo.com:1/", kTemp, 6000 }, |
1412 { "http://foo.com/", kPerm, 700 }, | 1412 { "http://foo.com/", kPerm, 700 }, |
1413 { "https://foo.com/", kTemp, 80 }, | 1413 { "https://foo.com/", kTemp, 80 }, |
1414 { "http://bar.com/", kTemp, 9 }, | 1414 { "http://bar.com/", kTemp, 9 }, |
1415 }; | 1415 }; |
1416 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 1416 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
1417 QuotaClient::kFileSystem); | 1417 QuotaClient::kFileSystem); |
1418 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 1418 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
1419 QuotaClient::kDatabase); | 1419 QuotaClient::kDatabase); |
1420 RegisterClient(client1); | 1420 RegisterClient(client1); |
1421 RegisterClient(client2); | 1421 RegisterClient(client2); |
1422 | 1422 |
1423 GetGlobalUsage(kTemp); | 1423 GetGlobalUsage(kTemp); |
1424 MessageLoop::current()->RunAllPending(); | 1424 MessageLoop::current()->RunUntilIdle(); |
1425 const int64 predelete_global_tmp = usage(); | 1425 const int64 predelete_global_tmp = usage(); |
1426 | 1426 |
1427 GetHostUsage("foo.com", kTemp); | 1427 GetHostUsage("foo.com", kTemp); |
1428 MessageLoop::current()->RunAllPending(); | 1428 MessageLoop::current()->RunUntilIdle(); |
1429 const int64 predelete_foo_tmp = usage(); | 1429 const int64 predelete_foo_tmp = usage(); |
1430 | 1430 |
1431 GetHostUsage("bar.com", kTemp); | 1431 GetHostUsage("bar.com", kTemp); |
1432 MessageLoop::current()->RunAllPending(); | 1432 MessageLoop::current()->RunUntilIdle(); |
1433 const int64 predelete_bar_tmp = usage(); | 1433 const int64 predelete_bar_tmp = usage(); |
1434 | 1434 |
1435 GetHostUsage("foo.com", kPerm); | 1435 GetHostUsage("foo.com", kPerm); |
1436 MessageLoop::current()->RunAllPending(); | 1436 MessageLoop::current()->RunUntilIdle(); |
1437 const int64 predelete_foo_pers = usage(); | 1437 const int64 predelete_foo_pers = usage(); |
1438 | 1438 |
1439 GetHostUsage("bar.com", kPerm); | 1439 GetHostUsage("bar.com", kPerm); |
1440 MessageLoop::current()->RunAllPending(); | 1440 MessageLoop::current()->RunUntilIdle(); |
1441 const int64 predelete_bar_pers = usage(); | 1441 const int64 predelete_bar_pers = usage(); |
1442 | 1442 |
1443 reset_status_callback_count(); | 1443 reset_status_callback_count(); |
1444 DeleteHostData("foo.com", kTemp, kAllClients); | 1444 DeleteHostData("foo.com", kTemp, kAllClients); |
1445 DeleteHostData("bar.com", kTemp, kAllClients); | 1445 DeleteHostData("bar.com", kTemp, kAllClients); |
1446 DeleteHostData("foo.com", kTemp, kAllClients); | 1446 DeleteHostData("foo.com", kTemp, kAllClients); |
1447 MessageLoop::current()->RunAllPending(); | 1447 MessageLoop::current()->RunUntilIdle(); |
1448 | 1448 |
1449 EXPECT_EQ(3, status_callback_count()); | 1449 EXPECT_EQ(3, status_callback_count()); |
1450 | 1450 |
1451 DumpOriginInfoTable(); | 1451 DumpOriginInfoTable(); |
1452 MessageLoop::current()->RunAllPending(); | 1452 MessageLoop::current()->RunUntilIdle(); |
1453 | 1453 |
1454 typedef OriginInfoTableEntries::const_iterator iterator; | 1454 typedef OriginInfoTableEntries::const_iterator iterator; |
1455 for (iterator itr(origin_info_entries().begin()), | 1455 for (iterator itr(origin_info_entries().begin()), |
1456 end(origin_info_entries().end()); | 1456 end(origin_info_entries().end()); |
1457 itr != end; ++itr) { | 1457 itr != end; ++itr) { |
1458 if (itr->type == kTemp) { | 1458 if (itr->type == kTemp) { |
1459 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | 1459 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); |
1460 EXPECT_NE(std::string("http://foo.com:1/"), itr->origin.spec()); | 1460 EXPECT_NE(std::string("http://foo.com:1/"), itr->origin.spec()); |
1461 EXPECT_NE(std::string("https://foo.com/"), itr->origin.spec()); | 1461 EXPECT_NE(std::string("https://foo.com/"), itr->origin.spec()); |
1462 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); | 1462 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); |
1463 } | 1463 } |
1464 } | 1464 } |
1465 | 1465 |
1466 GetGlobalUsage(kTemp); | 1466 GetGlobalUsage(kTemp); |
1467 MessageLoop::current()->RunAllPending(); | 1467 MessageLoop::current()->RunUntilIdle(); |
1468 EXPECT_EQ( | 1468 EXPECT_EQ( |
1469 predelete_global_tmp - (1 + 20 + 4000 + 50000 + 6000 + 80 + 9), usage()); | 1469 predelete_global_tmp - (1 + 20 + 4000 + 50000 + 6000 + 80 + 9), usage()); |
1470 | 1470 |
1471 GetHostUsage("foo.com", kTemp); | 1471 GetHostUsage("foo.com", kTemp); |
1472 MessageLoop::current()->RunAllPending(); | 1472 MessageLoop::current()->RunUntilIdle(); |
1473 EXPECT_EQ(predelete_foo_tmp - (1 + 20 + 50000 + 6000 + 80), usage()); | 1473 EXPECT_EQ(predelete_foo_tmp - (1 + 20 + 50000 + 6000 + 80), usage()); |
1474 | 1474 |
1475 GetHostUsage("bar.com", kTemp); | 1475 GetHostUsage("bar.com", kTemp); |
1476 MessageLoop::current()->RunAllPending(); | 1476 MessageLoop::current()->RunUntilIdle(); |
1477 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); | 1477 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); |
1478 | 1478 |
1479 GetHostUsage("foo.com", kPerm); | 1479 GetHostUsage("foo.com", kPerm); |
1480 MessageLoop::current()->RunAllPending(); | 1480 MessageLoop::current()->RunUntilIdle(); |
1481 EXPECT_EQ(predelete_foo_pers, usage()); | 1481 EXPECT_EQ(predelete_foo_pers, usage()); |
1482 | 1482 |
1483 GetHostUsage("bar.com", kPerm); | 1483 GetHostUsage("bar.com", kPerm); |
1484 MessageLoop::current()->RunAllPending(); | 1484 MessageLoop::current()->RunUntilIdle(); |
1485 EXPECT_EQ(predelete_bar_pers, usage()); | 1485 EXPECT_EQ(predelete_bar_pers, usage()); |
1486 } | 1486 } |
1487 | 1487 |
1488 // Single-run DeleteOriginData cases must be well covered by | 1488 // Single-run DeleteOriginData cases must be well covered by |
1489 // EvictOriginData tests. | 1489 // EvictOriginData tests. |
1490 TEST_F(QuotaManagerTest, DeleteOriginDataMultiple) { | 1490 TEST_F(QuotaManagerTest, DeleteOriginDataMultiple) { |
1491 static const MockOriginData kData1[] = { | 1491 static const MockOriginData kData1[] = { |
1492 { "http://foo.com/", kTemp, 1 }, | 1492 { "http://foo.com/", kTemp, 1 }, |
1493 { "http://foo.com:1/", kTemp, 20 }, | 1493 { "http://foo.com:1/", kTemp, 20 }, |
1494 { "http://foo.com/", kPerm, 300 }, | 1494 { "http://foo.com/", kPerm, 300 }, |
1495 { "http://bar.com/", kTemp, 4000 }, | 1495 { "http://bar.com/", kTemp, 4000 }, |
1496 }; | 1496 }; |
1497 static const MockOriginData kData2[] = { | 1497 static const MockOriginData kData2[] = { |
1498 { "http://foo.com/", kTemp, 50000 }, | 1498 { "http://foo.com/", kTemp, 50000 }, |
1499 { "http://foo.com:1/", kTemp, 6000 }, | 1499 { "http://foo.com:1/", kTemp, 6000 }, |
1500 { "http://foo.com/", kPerm, 700 }, | 1500 { "http://foo.com/", kPerm, 700 }, |
1501 { "https://foo.com/", kTemp, 80 }, | 1501 { "https://foo.com/", kTemp, 80 }, |
1502 { "http://bar.com/", kTemp, 9 }, | 1502 { "http://bar.com/", kTemp, 9 }, |
1503 }; | 1503 }; |
1504 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), | 1504 MockStorageClient* client1 = CreateClient(kData1, ARRAYSIZE_UNSAFE(kData1), |
1505 QuotaClient::kFileSystem); | 1505 QuotaClient::kFileSystem); |
1506 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), | 1506 MockStorageClient* client2 = CreateClient(kData2, ARRAYSIZE_UNSAFE(kData2), |
1507 QuotaClient::kDatabase); | 1507 QuotaClient::kDatabase); |
1508 RegisterClient(client1); | 1508 RegisterClient(client1); |
1509 RegisterClient(client2); | 1509 RegisterClient(client2); |
1510 | 1510 |
1511 GetGlobalUsage(kTemp); | 1511 GetGlobalUsage(kTemp); |
1512 MessageLoop::current()->RunAllPending(); | 1512 MessageLoop::current()->RunUntilIdle(); |
1513 const int64 predelete_global_tmp = usage(); | 1513 const int64 predelete_global_tmp = usage(); |
1514 | 1514 |
1515 GetHostUsage("foo.com", kTemp); | 1515 GetHostUsage("foo.com", kTemp); |
1516 MessageLoop::current()->RunAllPending(); | 1516 MessageLoop::current()->RunUntilIdle(); |
1517 const int64 predelete_foo_tmp = usage(); | 1517 const int64 predelete_foo_tmp = usage(); |
1518 | 1518 |
1519 GetHostUsage("bar.com", kTemp); | 1519 GetHostUsage("bar.com", kTemp); |
1520 MessageLoop::current()->RunAllPending(); | 1520 MessageLoop::current()->RunUntilIdle(); |
1521 const int64 predelete_bar_tmp = usage(); | 1521 const int64 predelete_bar_tmp = usage(); |
1522 | 1522 |
1523 GetHostUsage("foo.com", kPerm); | 1523 GetHostUsage("foo.com", kPerm); |
1524 MessageLoop::current()->RunAllPending(); | 1524 MessageLoop::current()->RunUntilIdle(); |
1525 const int64 predelete_foo_pers = usage(); | 1525 const int64 predelete_foo_pers = usage(); |
1526 | 1526 |
1527 GetHostUsage("bar.com", kPerm); | 1527 GetHostUsage("bar.com", kPerm); |
1528 MessageLoop::current()->RunAllPending(); | 1528 MessageLoop::current()->RunUntilIdle(); |
1529 const int64 predelete_bar_pers = usage(); | 1529 const int64 predelete_bar_pers = usage(); |
1530 | 1530 |
1531 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i) | 1531 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i) |
1532 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | 1532 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, |
1533 GURL(kData1[i].origin), kData1[i].type); | 1533 GURL(kData1[i].origin), kData1[i].type); |
1534 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) | 1534 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) |
1535 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, | 1535 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, |
1536 GURL(kData2[i].origin), kData2[i].type); | 1536 GURL(kData2[i].origin), kData2[i].type); |
1537 MessageLoop::current()->RunAllPending(); | 1537 MessageLoop::current()->RunUntilIdle(); |
1538 | 1538 |
1539 reset_status_callback_count(); | 1539 reset_status_callback_count(); |
1540 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | 1540 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); |
1541 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); | 1541 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients); |
1542 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); | 1542 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients); |
1543 MessageLoop::current()->RunAllPending(); | 1543 MessageLoop::current()->RunUntilIdle(); |
1544 | 1544 |
1545 EXPECT_EQ(3, status_callback_count()); | 1545 EXPECT_EQ(3, status_callback_count()); |
1546 | 1546 |
1547 DumpOriginInfoTable(); | 1547 DumpOriginInfoTable(); |
1548 MessageLoop::current()->RunAllPending(); | 1548 MessageLoop::current()->RunUntilIdle(); |
1549 | 1549 |
1550 typedef OriginInfoTableEntries::const_iterator iterator; | 1550 typedef OriginInfoTableEntries::const_iterator iterator; |
1551 for (iterator itr(origin_info_entries().begin()), | 1551 for (iterator itr(origin_info_entries().begin()), |
1552 end(origin_info_entries().end()); | 1552 end(origin_info_entries().end()); |
1553 itr != end; ++itr) { | 1553 itr != end; ++itr) { |
1554 if (itr->type == kTemp) { | 1554 if (itr->type == kTemp) { |
1555 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | 1555 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); |
1556 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); | 1556 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); |
1557 } | 1557 } |
1558 } | 1558 } |
1559 | 1559 |
1560 GetGlobalUsage(kTemp); | 1560 GetGlobalUsage(kTemp); |
1561 MessageLoop::current()->RunAllPending(); | 1561 MessageLoop::current()->RunUntilIdle(); |
1562 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage()); | 1562 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage()); |
1563 | 1563 |
1564 GetHostUsage("foo.com", kTemp); | 1564 GetHostUsage("foo.com", kTemp); |
1565 MessageLoop::current()->RunAllPending(); | 1565 MessageLoop::current()->RunUntilIdle(); |
1566 EXPECT_EQ(predelete_foo_tmp - (1 + 50000), usage()); | 1566 EXPECT_EQ(predelete_foo_tmp - (1 + 50000), usage()); |
1567 | 1567 |
1568 GetHostUsage("bar.com", kTemp); | 1568 GetHostUsage("bar.com", kTemp); |
1569 MessageLoop::current()->RunAllPending(); | 1569 MessageLoop::current()->RunUntilIdle(); |
1570 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); | 1570 EXPECT_EQ(predelete_bar_tmp - (4000 + 9), usage()); |
1571 | 1571 |
1572 GetHostUsage("foo.com", kPerm); | 1572 GetHostUsage("foo.com", kPerm); |
1573 MessageLoop::current()->RunAllPending(); | 1573 MessageLoop::current()->RunUntilIdle(); |
1574 EXPECT_EQ(predelete_foo_pers, usage()); | 1574 EXPECT_EQ(predelete_foo_pers, usage()); |
1575 | 1575 |
1576 GetHostUsage("bar.com", kPerm); | 1576 GetHostUsage("bar.com", kPerm); |
1577 MessageLoop::current()->RunAllPending(); | 1577 MessageLoop::current()->RunUntilIdle(); |
1578 EXPECT_EQ(predelete_bar_pers, usage()); | 1578 EXPECT_EQ(predelete_bar_pers, usage()); |
1579 } | 1579 } |
1580 | 1580 |
1581 TEST_F(QuotaManagerTest, GetCachedOrigins) { | 1581 TEST_F(QuotaManagerTest, GetCachedOrigins) { |
1582 static const MockOriginData kData[] = { | 1582 static const MockOriginData kData[] = { |
1583 { "http://a.com/", kTemp, 1 }, | 1583 { "http://a.com/", kTemp, 1 }, |
1584 { "http://a.com:1/", kTemp, 20 }, | 1584 { "http://a.com:1/", kTemp, 20 }, |
1585 { "http://b.com/", kPerm, 300 }, | 1585 { "http://b.com/", kPerm, 300 }, |
1586 { "http://c.com/", kTemp, 4000 }, | 1586 { "http://c.com/", kTemp, 4000 }, |
1587 }; | 1587 }; |
1588 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1588 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1589 QuotaClient::kFileSystem); | 1589 QuotaClient::kFileSystem); |
1590 RegisterClient(client); | 1590 RegisterClient(client); |
1591 | 1591 |
1592 // TODO(kinuko): Be careful when we add cache pruner. | 1592 // TODO(kinuko): Be careful when we add cache pruner. |
1593 | 1593 |
1594 std::set<GURL> origins; | 1594 std::set<GURL> origins; |
1595 GetCachedOrigins(kTemp, &origins); | 1595 GetCachedOrigins(kTemp, &origins); |
1596 EXPECT_TRUE(origins.empty()); | 1596 EXPECT_TRUE(origins.empty()); |
1597 | 1597 |
1598 // No matter how we make queries the quota manager tries to cache all | 1598 // No matter how we make queries the quota manager tries to cache all |
1599 // the origins at startup. | 1599 // the origins at startup. |
1600 GetHostUsage("a.com", kTemp); | 1600 GetHostUsage("a.com", kTemp); |
1601 MessageLoop::current()->RunAllPending(); | 1601 MessageLoop::current()->RunUntilIdle(); |
1602 GetCachedOrigins(kTemp, &origins); | 1602 GetCachedOrigins(kTemp, &origins); |
1603 EXPECT_EQ(3U, origins.size()); | 1603 EXPECT_EQ(3U, origins.size()); |
1604 | 1604 |
1605 GetHostUsage("b.com", kTemp); | 1605 GetHostUsage("b.com", kTemp); |
1606 MessageLoop::current()->RunAllPending(); | 1606 MessageLoop::current()->RunUntilIdle(); |
1607 GetCachedOrigins(kTemp, &origins); | 1607 GetCachedOrigins(kTemp, &origins); |
1608 EXPECT_EQ(3U, origins.size()); | 1608 EXPECT_EQ(3U, origins.size()); |
1609 | 1609 |
1610 GetCachedOrigins(kPerm, &origins); | 1610 GetCachedOrigins(kPerm, &origins); |
1611 EXPECT_TRUE(origins.empty()); | 1611 EXPECT_TRUE(origins.empty()); |
1612 | 1612 |
1613 GetGlobalUsage(kTemp); | 1613 GetGlobalUsage(kTemp); |
1614 MessageLoop::current()->RunAllPending(); | 1614 MessageLoop::current()->RunUntilIdle(); |
1615 GetCachedOrigins(kTemp, &origins); | 1615 GetCachedOrigins(kTemp, &origins); |
1616 EXPECT_EQ(3U, origins.size()); | 1616 EXPECT_EQ(3U, origins.size()); |
1617 | 1617 |
1618 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) { | 1618 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) { |
1619 if (kData[i].type == kTemp) | 1619 if (kData[i].type == kTemp) |
1620 EXPECT_TRUE(origins.find(GURL(kData[i].origin)) != origins.end()); | 1620 EXPECT_TRUE(origins.find(GURL(kData[i].origin)) != origins.end()); |
1621 } | 1621 } |
1622 } | 1622 } |
1623 | 1623 |
1624 TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) { | 1624 TEST_F(QuotaManagerTest, NotifyAndLRUOrigin) { |
1625 static const MockOriginData kData[] = { | 1625 static const MockOriginData kData[] = { |
1626 { "http://a.com/", kTemp, 0 }, | 1626 { "http://a.com/", kTemp, 0 }, |
1627 { "http://a.com:1/", kTemp, 0 }, | 1627 { "http://a.com:1/", kTemp, 0 }, |
1628 { "https://a.com/", kTemp, 0 }, | 1628 { "https://a.com/", kTemp, 0 }, |
1629 { "http://b.com/", kPerm, 0 }, // persistent | 1629 { "http://b.com/", kPerm, 0 }, // persistent |
1630 { "http://c.com/", kTemp, 0 }, | 1630 { "http://c.com/", kTemp, 0 }, |
1631 }; | 1631 }; |
1632 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1632 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1633 QuotaClient::kFileSystem); | 1633 QuotaClient::kFileSystem); |
1634 RegisterClient(client); | 1634 RegisterClient(client); |
1635 | 1635 |
1636 GURL origin; | 1636 GURL origin; |
1637 GetLRUOrigin(kTemp); | 1637 GetLRUOrigin(kTemp); |
1638 MessageLoop::current()->RunAllPending(); | 1638 MessageLoop::current()->RunUntilIdle(); |
1639 EXPECT_TRUE(lru_origin().is_empty()); | 1639 EXPECT_TRUE(lru_origin().is_empty()); |
1640 | 1640 |
1641 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); | 1641 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); |
1642 GetLRUOrigin(kTemp); | 1642 GetLRUOrigin(kTemp); |
1643 MessageLoop::current()->RunAllPending(); | 1643 MessageLoop::current()->RunUntilIdle(); |
1644 EXPECT_EQ("http://a.com/", lru_origin().spec()); | 1644 EXPECT_EQ("http://a.com/", lru_origin().spec()); |
1645 | 1645 |
1646 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); | 1646 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); |
1647 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); | 1647 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); |
1648 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | 1648 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); |
1649 GetLRUOrigin(kTemp); | 1649 GetLRUOrigin(kTemp); |
1650 MessageLoop::current()->RunAllPending(); | 1650 MessageLoop::current()->RunUntilIdle(); |
1651 EXPECT_EQ("http://a.com/", lru_origin().spec()); | 1651 EXPECT_EQ("http://a.com/", lru_origin().spec()); |
1652 | 1652 |
1653 DeleteOriginFromDatabase(lru_origin(), kTemp); | 1653 DeleteOriginFromDatabase(lru_origin(), kTemp); |
1654 GetLRUOrigin(kTemp); | 1654 GetLRUOrigin(kTemp); |
1655 MessageLoop::current()->RunAllPending(); | 1655 MessageLoop::current()->RunUntilIdle(); |
1656 EXPECT_EQ("https://a.com/", lru_origin().spec()); | 1656 EXPECT_EQ("https://a.com/", lru_origin().spec()); |
1657 | 1657 |
1658 DeleteOriginFromDatabase(lru_origin(), kTemp); | 1658 DeleteOriginFromDatabase(lru_origin(), kTemp); |
1659 GetLRUOrigin(kTemp); | 1659 GetLRUOrigin(kTemp); |
1660 MessageLoop::current()->RunAllPending(); | 1660 MessageLoop::current()->RunUntilIdle(); |
1661 EXPECT_EQ("http://c.com/", lru_origin().spec()); | 1661 EXPECT_EQ("http://c.com/", lru_origin().spec()); |
1662 } | 1662 } |
1663 | 1663 |
1664 TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) { | 1664 TEST_F(QuotaManagerTest, GetLRUOriginWithOriginInUse) { |
1665 static const MockOriginData kData[] = { | 1665 static const MockOriginData kData[] = { |
1666 { "http://a.com/", kTemp, 0 }, | 1666 { "http://a.com/", kTemp, 0 }, |
1667 { "http://a.com:1/", kTemp, 0 }, | 1667 { "http://a.com:1/", kTemp, 0 }, |
1668 { "https://a.com/", kTemp, 0 }, | 1668 { "https://a.com/", kTemp, 0 }, |
1669 { "http://b.com/", kPerm, 0 }, // persistent | 1669 { "http://b.com/", kPerm, 0 }, // persistent |
1670 { "http://c.com/", kTemp, 0 }, | 1670 { "http://c.com/", kTemp, 0 }, |
1671 }; | 1671 }; |
1672 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1672 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1673 QuotaClient::kFileSystem); | 1673 QuotaClient::kFileSystem); |
1674 RegisterClient(client); | 1674 RegisterClient(client); |
1675 | 1675 |
1676 GURL origin; | 1676 GURL origin; |
1677 GetLRUOrigin(kTemp); | 1677 GetLRUOrigin(kTemp); |
1678 MessageLoop::current()->RunAllPending(); | 1678 MessageLoop::current()->RunUntilIdle(); |
1679 EXPECT_TRUE(lru_origin().is_empty()); | 1679 EXPECT_TRUE(lru_origin().is_empty()); |
1680 | 1680 |
1681 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); | 1681 NotifyStorageAccessed(client, GURL("http://a.com/"), kTemp); |
1682 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); | 1682 NotifyStorageAccessed(client, GURL("http://b.com/"), kPerm); |
1683 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); | 1683 NotifyStorageAccessed(client, GURL("https://a.com/"), kTemp); |
1684 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | 1684 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); |
1685 | 1685 |
1686 GetLRUOrigin(kTemp); | 1686 GetLRUOrigin(kTemp); |
1687 MessageLoop::current()->RunAllPending(); | 1687 MessageLoop::current()->RunUntilIdle(); |
1688 EXPECT_EQ("http://a.com/", lru_origin().spec()); | 1688 EXPECT_EQ("http://a.com/", lru_origin().spec()); |
1689 | 1689 |
1690 // Notify origin http://a.com is in use. | 1690 // Notify origin http://a.com is in use. |
1691 NotifyOriginInUse(GURL("http://a.com/")); | 1691 NotifyOriginInUse(GURL("http://a.com/")); |
1692 GetLRUOrigin(kTemp); | 1692 GetLRUOrigin(kTemp); |
1693 MessageLoop::current()->RunAllPending(); | 1693 MessageLoop::current()->RunUntilIdle(); |
1694 EXPECT_EQ("https://a.com/", lru_origin().spec()); | 1694 EXPECT_EQ("https://a.com/", lru_origin().spec()); |
1695 | 1695 |
1696 // Notify origin https://a.com is in use while GetLRUOrigin is running. | 1696 // Notify origin https://a.com is in use while GetLRUOrigin is running. |
1697 GetLRUOrigin(kTemp); | 1697 GetLRUOrigin(kTemp); |
1698 NotifyOriginInUse(GURL("https://a.com/")); | 1698 NotifyOriginInUse(GURL("https://a.com/")); |
1699 MessageLoop::current()->RunAllPending(); | 1699 MessageLoop::current()->RunUntilIdle(); |
1700 // Post-filtering must have excluded the returned origin, so we will | 1700 // Post-filtering must have excluded the returned origin, so we will |
1701 // see empty result here. | 1701 // see empty result here. |
1702 EXPECT_TRUE(lru_origin().is_empty()); | 1702 EXPECT_TRUE(lru_origin().is_empty()); |
1703 | 1703 |
1704 // Notify access for http://c.com while GetLRUOrigin is running. | 1704 // Notify access for http://c.com while GetLRUOrigin is running. |
1705 GetLRUOrigin(kTemp); | 1705 GetLRUOrigin(kTemp); |
1706 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); | 1706 NotifyStorageAccessed(client, GURL("http://c.com/"), kTemp); |
1707 MessageLoop::current()->RunAllPending(); | 1707 MessageLoop::current()->RunUntilIdle(); |
1708 // Post-filtering must have excluded the returned origin, so we will | 1708 // Post-filtering must have excluded the returned origin, so we will |
1709 // see empty result here. | 1709 // see empty result here. |
1710 EXPECT_TRUE(lru_origin().is_empty()); | 1710 EXPECT_TRUE(lru_origin().is_empty()); |
1711 | 1711 |
1712 NotifyOriginNoLongerInUse(GURL("http://a.com/")); | 1712 NotifyOriginNoLongerInUse(GURL("http://a.com/")); |
1713 NotifyOriginNoLongerInUse(GURL("https://a.com/")); | 1713 NotifyOriginNoLongerInUse(GURL("https://a.com/")); |
1714 GetLRUOrigin(kTemp); | 1714 GetLRUOrigin(kTemp); |
1715 MessageLoop::current()->RunAllPending(); | 1715 MessageLoop::current()->RunUntilIdle(); |
1716 EXPECT_EQ("http://a.com/", lru_origin().spec()); | 1716 EXPECT_EQ("http://a.com/", lru_origin().spec()); |
1717 } | 1717 } |
1718 | 1718 |
1719 TEST_F(QuotaManagerTest, GetOriginsModifiedSince) { | 1719 TEST_F(QuotaManagerTest, GetOriginsModifiedSince) { |
1720 static const MockOriginData kData[] = { | 1720 static const MockOriginData kData[] = { |
1721 { "http://a.com/", kTemp, 0 }, | 1721 { "http://a.com/", kTemp, 0 }, |
1722 { "http://a.com:1/", kTemp, 0 }, | 1722 { "http://a.com:1/", kTemp, 0 }, |
1723 { "https://a.com/", kTemp, 0 }, | 1723 { "https://a.com/", kTemp, 0 }, |
1724 { "http://b.com/", kPerm, 0 }, // persistent | 1724 { "http://b.com/", kPerm, 0 }, // persistent |
1725 { "http://c.com/", kTemp, 0 }, | 1725 { "http://c.com/", kTemp, 0 }, |
1726 }; | 1726 }; |
1727 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 1727 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
1728 QuotaClient::kFileSystem); | 1728 QuotaClient::kFileSystem); |
1729 RegisterClient(client); | 1729 RegisterClient(client); |
1730 | 1730 |
1731 GetOriginsModifiedSince(kTemp, base::Time()); | 1731 GetOriginsModifiedSince(kTemp, base::Time()); |
1732 MessageLoop::current()->RunAllPending(); | 1732 MessageLoop::current()->RunUntilIdle(); |
1733 EXPECT_TRUE(modified_origins().empty()); | 1733 EXPECT_TRUE(modified_origins().empty()); |
1734 EXPECT_EQ(modified_origins_type(), kTemp); | 1734 EXPECT_EQ(modified_origins_type(), kTemp); |
1735 | 1735 |
1736 base::Time time1 = client->IncrementMockTime(); | 1736 base::Time time1 = client->IncrementMockTime(); |
1737 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); | 1737 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); |
1738 client->ModifyOriginAndNotify(GURL("http://a.com:1/"), kTemp, 10); | 1738 client->ModifyOriginAndNotify(GURL("http://a.com:1/"), kTemp, 10); |
1739 client->ModifyOriginAndNotify(GURL("http://b.com/"), kPerm, 10); | 1739 client->ModifyOriginAndNotify(GURL("http://b.com/"), kPerm, 10); |
1740 base::Time time2 = client->IncrementMockTime(); | 1740 base::Time time2 = client->IncrementMockTime(); |
1741 client->ModifyOriginAndNotify(GURL("https://a.com/"), kTemp, 10); | 1741 client->ModifyOriginAndNotify(GURL("https://a.com/"), kTemp, 10); |
1742 client->ModifyOriginAndNotify(GURL("http://c.com/"), kTemp, 10); | 1742 client->ModifyOriginAndNotify(GURL("http://c.com/"), kTemp, 10); |
1743 base::Time time3 = client->IncrementMockTime(); | 1743 base::Time time3 = client->IncrementMockTime(); |
1744 | 1744 |
1745 GetOriginsModifiedSince(kTemp, time1); | 1745 GetOriginsModifiedSince(kTemp, time1); |
1746 MessageLoop::current()->RunAllPending(); | 1746 MessageLoop::current()->RunUntilIdle(); |
1747 EXPECT_EQ(4U, modified_origins().size()); | 1747 EXPECT_EQ(4U, modified_origins().size()); |
1748 EXPECT_EQ(modified_origins_type(), kTemp); | 1748 EXPECT_EQ(modified_origins_type(), kTemp); |
1749 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) { | 1749 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) { |
1750 if (kData[i].type == kTemp) | 1750 if (kData[i].type == kTemp) |
1751 EXPECT_EQ(1U, modified_origins().count(GURL(kData[i].origin))); | 1751 EXPECT_EQ(1U, modified_origins().count(GURL(kData[i].origin))); |
1752 } | 1752 } |
1753 | 1753 |
1754 GetOriginsModifiedSince(kTemp, time2); | 1754 GetOriginsModifiedSince(kTemp, time2); |
1755 MessageLoop::current()->RunAllPending(); | 1755 MessageLoop::current()->RunUntilIdle(); |
1756 EXPECT_EQ(2U, modified_origins().size()); | 1756 EXPECT_EQ(2U, modified_origins().size()); |
1757 | 1757 |
1758 GetOriginsModifiedSince(kTemp, time3); | 1758 GetOriginsModifiedSince(kTemp, time3); |
1759 MessageLoop::current()->RunAllPending(); | 1759 MessageLoop::current()->RunUntilIdle(); |
1760 EXPECT_TRUE(modified_origins().empty()); | 1760 EXPECT_TRUE(modified_origins().empty()); |
1761 EXPECT_EQ(modified_origins_type(), kTemp); | 1761 EXPECT_EQ(modified_origins_type(), kTemp); |
1762 | 1762 |
1763 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); | 1763 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); |
1764 | 1764 |
1765 GetOriginsModifiedSince(kTemp, time3); | 1765 GetOriginsModifiedSince(kTemp, time3); |
1766 MessageLoop::current()->RunAllPending(); | 1766 MessageLoop::current()->RunUntilIdle(); |
1767 EXPECT_EQ(1U, modified_origins().size()); | 1767 EXPECT_EQ(1U, modified_origins().size()); |
1768 EXPECT_EQ(1U, modified_origins().count(GURL("http://a.com/"))); | 1768 EXPECT_EQ(1U, modified_origins().count(GURL("http://a.com/"))); |
1769 EXPECT_EQ(modified_origins_type(), kTemp); | 1769 EXPECT_EQ(modified_origins_type(), kTemp); |
1770 } | 1770 } |
1771 | 1771 |
1772 TEST_F(QuotaManagerTest, DumpQuotaTable) { | 1772 TEST_F(QuotaManagerTest, DumpQuotaTable) { |
1773 SetPersistentHostQuota("example1.com", 1); | 1773 SetPersistentHostQuota("example1.com", 1); |
1774 SetPersistentHostQuota("example2.com", 20); | 1774 SetPersistentHostQuota("example2.com", 20); |
1775 SetPersistentHostQuota("example3.com", 300); | 1775 SetPersistentHostQuota("example3.com", 300); |
1776 MessageLoop::current()->RunAllPending(); | 1776 MessageLoop::current()->RunUntilIdle(); |
1777 | 1777 |
1778 DumpQuotaTable(); | 1778 DumpQuotaTable(); |
1779 MessageLoop::current()->RunAllPending(); | 1779 MessageLoop::current()->RunUntilIdle(); |
1780 | 1780 |
1781 const QuotaTableEntry kEntries[] = { | 1781 const QuotaTableEntry kEntries[] = { |
1782 QuotaTableEntry("example1.com", kPerm, 1), | 1782 QuotaTableEntry("example1.com", kPerm, 1), |
1783 QuotaTableEntry("example2.com", kPerm, 20), | 1783 QuotaTableEntry("example2.com", kPerm, 20), |
1784 QuotaTableEntry("example3.com", kPerm, 300), | 1784 QuotaTableEntry("example3.com", kPerm, 300), |
1785 }; | 1785 }; |
1786 std::set<QuotaTableEntry> entries | 1786 std::set<QuotaTableEntry> entries |
1787 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); | 1787 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); |
1788 | 1788 |
1789 typedef QuotaTableEntries::const_iterator iterator; | 1789 typedef QuotaTableEntries::const_iterator iterator; |
(...skipping 15 matching lines...) Expand all Loading... |
1805 GURL("http://example.com/"), | 1805 GURL("http://example.com/"), |
1806 kTemp); | 1806 kTemp); |
1807 quota_manager()->NotifyStorageAccessed( | 1807 quota_manager()->NotifyStorageAccessed( |
1808 QuotaClient::kUnknown, | 1808 QuotaClient::kUnknown, |
1809 GURL("http://example.com/"), | 1809 GURL("http://example.com/"), |
1810 kPerm); | 1810 kPerm); |
1811 quota_manager()->NotifyStorageAccessed( | 1811 quota_manager()->NotifyStorageAccessed( |
1812 QuotaClient::kUnknown, | 1812 QuotaClient::kUnknown, |
1813 GURL("http://example.com/"), | 1813 GURL("http://example.com/"), |
1814 kPerm); | 1814 kPerm); |
1815 MessageLoop::current()->RunAllPending(); | 1815 MessageLoop::current()->RunUntilIdle(); |
1816 | 1816 |
1817 DumpOriginInfoTable(); | 1817 DumpOriginInfoTable(); |
1818 MessageLoop::current()->RunAllPending(); | 1818 MessageLoop::current()->RunUntilIdle(); |
1819 | 1819 |
1820 typedef std::pair<GURL, StorageType> TypedOrigin; | 1820 typedef std::pair<GURL, StorageType> TypedOrigin; |
1821 typedef std::pair<TypedOrigin, int> Entry; | 1821 typedef std::pair<TypedOrigin, int> Entry; |
1822 const Entry kEntries[] = { | 1822 const Entry kEntries[] = { |
1823 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1), | 1823 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1), |
1824 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2), | 1824 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2), |
1825 }; | 1825 }; |
1826 std::set<Entry> entries | 1826 std::set<Entry> entries |
1827 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); | 1827 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); |
1828 | 1828 |
1829 typedef OriginInfoTableEntries::const_iterator iterator; | 1829 typedef OriginInfoTableEntries::const_iterator iterator; |
1830 for (iterator itr(origin_info_entries().begin()), | 1830 for (iterator itr(origin_info_entries().begin()), |
1831 end(origin_info_entries().end()); | 1831 end(origin_info_entries().end()); |
1832 itr != end; ++itr) { | 1832 itr != end; ++itr) { |
1833 SCOPED_TRACE(testing::Message() | 1833 SCOPED_TRACE(testing::Message() |
1834 << "host = " << itr->origin << ", " | 1834 << "host = " << itr->origin << ", " |
1835 << "type = " << itr->type << ", " | 1835 << "type = " << itr->type << ", " |
1836 << "used_count = " << itr->used_count); | 1836 << "used_count = " << itr->used_count); |
1837 EXPECT_EQ(1u, entries.erase( | 1837 EXPECT_EQ(1u, entries.erase( |
1838 make_pair(make_pair(itr->origin, itr->type), | 1838 make_pair(make_pair(itr->origin, itr->type), |
1839 itr->used_count))); | 1839 itr->used_count))); |
1840 } | 1840 } |
1841 EXPECT_TRUE(entries.empty()); | 1841 EXPECT_TRUE(entries.empty()); |
1842 } | 1842 } |
1843 | 1843 |
1844 TEST_F(QuotaManagerTest, QuotaForEmptyHost) { | 1844 TEST_F(QuotaManagerTest, QuotaForEmptyHost) { |
1845 GetPersistentHostQuota(std::string()); | 1845 GetPersistentHostQuota(std::string()); |
1846 MessageLoop::current()->RunAllPending(); | 1846 MessageLoop::current()->RunUntilIdle(); |
1847 EXPECT_EQ(kQuotaStatusOk, status()); | 1847 EXPECT_EQ(kQuotaStatusOk, status()); |
1848 EXPECT_EQ(0, quota()); | 1848 EXPECT_EQ(0, quota()); |
1849 | 1849 |
1850 SetPersistentHostQuota(std::string(), 10); | 1850 SetPersistentHostQuota(std::string(), 10); |
1851 MessageLoop::current()->RunAllPending(); | 1851 MessageLoop::current()->RunUntilIdle(); |
1852 EXPECT_EQ(kQuotaErrorNotSupported, status()); | 1852 EXPECT_EQ(kQuotaErrorNotSupported, status()); |
1853 } | 1853 } |
1854 | 1854 |
1855 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleOrigin) { | 1855 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleOrigin) { |
1856 static const MockOriginData kData1[] = { | 1856 static const MockOriginData kData1[] = { |
1857 { "http://foo.com/", kTemp, 1 }, | 1857 { "http://foo.com/", kTemp, 1 }, |
1858 }; | 1858 }; |
1859 static const MockOriginData kData2[] = { | 1859 static const MockOriginData kData2[] = { |
1860 { "http://foo.com/", kTemp, 2 }, | 1860 { "http://foo.com/", kTemp, 2 }, |
1861 }; | 1861 }; |
(...skipping 10 matching lines...) Expand all Loading... |
1872 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), | 1872 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), |
1873 QuotaClient::kDatabase); | 1873 QuotaClient::kDatabase); |
1874 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), | 1874 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), |
1875 QuotaClient::kIndexedDatabase); | 1875 QuotaClient::kIndexedDatabase); |
1876 RegisterClient(client1); | 1876 RegisterClient(client1); |
1877 RegisterClient(client2); | 1877 RegisterClient(client2); |
1878 RegisterClient(client3); | 1878 RegisterClient(client3); |
1879 RegisterClient(client4); | 1879 RegisterClient(client4); |
1880 | 1880 |
1881 GetHostUsage("foo.com", kTemp); | 1881 GetHostUsage("foo.com", kTemp); |
1882 MessageLoop::current()->RunAllPending(); | 1882 MessageLoop::current()->RunUntilIdle(); |
1883 const int64 predelete_foo_tmp = usage(); | 1883 const int64 predelete_foo_tmp = usage(); |
1884 | 1884 |
1885 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kFileSystem); | 1885 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kFileSystem); |
1886 MessageLoop::current()->RunAllPending(); | 1886 MessageLoop::current()->RunUntilIdle(); |
1887 GetHostUsage("foo.com", kTemp); | 1887 GetHostUsage("foo.com", kTemp); |
1888 MessageLoop::current()->RunAllPending(); | 1888 MessageLoop::current()->RunUntilIdle(); |
1889 EXPECT_EQ(predelete_foo_tmp - 1, usage()); | 1889 EXPECT_EQ(predelete_foo_tmp - 1, usage()); |
1890 | 1890 |
1891 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kAppcache); | 1891 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kAppcache); |
1892 MessageLoop::current()->RunAllPending(); | 1892 MessageLoop::current()->RunUntilIdle(); |
1893 GetHostUsage("foo.com", kTemp); | 1893 GetHostUsage("foo.com", kTemp); |
1894 MessageLoop::current()->RunAllPending(); | 1894 MessageLoop::current()->RunUntilIdle(); |
1895 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | 1895 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); |
1896 | 1896 |
1897 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kDatabase); | 1897 DeleteOriginData(GURL("http://foo.com/"), kTemp, QuotaClient::kDatabase); |
1898 MessageLoop::current()->RunAllPending(); | 1898 MessageLoop::current()->RunUntilIdle(); |
1899 GetHostUsage("foo.com", kTemp); | 1899 GetHostUsage("foo.com", kTemp); |
1900 MessageLoop::current()->RunAllPending(); | 1900 MessageLoop::current()->RunUntilIdle(); |
1901 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); | 1901 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); |
1902 | 1902 |
1903 DeleteOriginData(GURL("http://foo.com/"), kTemp, | 1903 DeleteOriginData(GURL("http://foo.com/"), kTemp, |
1904 QuotaClient::kIndexedDatabase); | 1904 QuotaClient::kIndexedDatabase); |
1905 MessageLoop::current()->RunAllPending(); | 1905 MessageLoop::current()->RunUntilIdle(); |
1906 GetHostUsage("foo.com", kTemp); | 1906 GetHostUsage("foo.com", kTemp); |
1907 MessageLoop::current()->RunAllPending(); | 1907 MessageLoop::current()->RunUntilIdle(); |
1908 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 1908 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
1909 } | 1909 } |
1910 | 1910 |
1911 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleHost) { | 1911 TEST_F(QuotaManagerTest, DeleteSpecificClientTypeSingleHost) { |
1912 static const MockOriginData kData1[] = { | 1912 static const MockOriginData kData1[] = { |
1913 { "http://foo.com:1111/", kTemp, 1 }, | 1913 { "http://foo.com:1111/", kTemp, 1 }, |
1914 }; | 1914 }; |
1915 static const MockOriginData kData2[] = { | 1915 static const MockOriginData kData2[] = { |
1916 { "http://foo.com:2222/", kTemp, 2 }, | 1916 { "http://foo.com:2222/", kTemp, 2 }, |
1917 }; | 1917 }; |
(...skipping 10 matching lines...) Expand all Loading... |
1928 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), | 1928 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), |
1929 QuotaClient::kDatabase); | 1929 QuotaClient::kDatabase); |
1930 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), | 1930 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), |
1931 QuotaClient::kIndexedDatabase); | 1931 QuotaClient::kIndexedDatabase); |
1932 RegisterClient(client1); | 1932 RegisterClient(client1); |
1933 RegisterClient(client2); | 1933 RegisterClient(client2); |
1934 RegisterClient(client3); | 1934 RegisterClient(client3); |
1935 RegisterClient(client4); | 1935 RegisterClient(client4); |
1936 | 1936 |
1937 GetHostUsage("foo.com", kTemp); | 1937 GetHostUsage("foo.com", kTemp); |
1938 MessageLoop::current()->RunAllPending(); | 1938 MessageLoop::current()->RunUntilIdle(); |
1939 const int64 predelete_foo_tmp = usage(); | 1939 const int64 predelete_foo_tmp = usage(); |
1940 | 1940 |
1941 DeleteHostData("foo.com", kTemp, QuotaClient::kFileSystem); | 1941 DeleteHostData("foo.com", kTemp, QuotaClient::kFileSystem); |
1942 MessageLoop::current()->RunAllPending(); | 1942 MessageLoop::current()->RunUntilIdle(); |
1943 GetHostUsage("foo.com", kTemp); | 1943 GetHostUsage("foo.com", kTemp); |
1944 MessageLoop::current()->RunAllPending(); | 1944 MessageLoop::current()->RunUntilIdle(); |
1945 EXPECT_EQ(predelete_foo_tmp - 1, usage()); | 1945 EXPECT_EQ(predelete_foo_tmp - 1, usage()); |
1946 | 1946 |
1947 DeleteHostData("foo.com", kTemp, QuotaClient::kAppcache); | 1947 DeleteHostData("foo.com", kTemp, QuotaClient::kAppcache); |
1948 MessageLoop::current()->RunAllPending(); | 1948 MessageLoop::current()->RunUntilIdle(); |
1949 GetHostUsage("foo.com", kTemp); | 1949 GetHostUsage("foo.com", kTemp); |
1950 MessageLoop::current()->RunAllPending(); | 1950 MessageLoop::current()->RunUntilIdle(); |
1951 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | 1951 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); |
1952 | 1952 |
1953 DeleteHostData("foo.com", kTemp, QuotaClient::kDatabase); | 1953 DeleteHostData("foo.com", kTemp, QuotaClient::kDatabase); |
1954 MessageLoop::current()->RunAllPending(); | 1954 MessageLoop::current()->RunUntilIdle(); |
1955 GetHostUsage("foo.com", kTemp); | 1955 GetHostUsage("foo.com", kTemp); |
1956 MessageLoop::current()->RunAllPending(); | 1956 MessageLoop::current()->RunUntilIdle(); |
1957 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); | 1957 EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); |
1958 | 1958 |
1959 DeleteHostData("foo.com", kTemp, QuotaClient::kIndexedDatabase); | 1959 DeleteHostData("foo.com", kTemp, QuotaClient::kIndexedDatabase); |
1960 MessageLoop::current()->RunAllPending(); | 1960 MessageLoop::current()->RunUntilIdle(); |
1961 GetHostUsage("foo.com", kTemp); | 1961 GetHostUsage("foo.com", kTemp); |
1962 MessageLoop::current()->RunAllPending(); | 1962 MessageLoop::current()->RunUntilIdle(); |
1963 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 1963 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
1964 } | 1964 } |
1965 | 1965 |
1966 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleOrigin) { | 1966 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleOrigin) { |
1967 static const MockOriginData kData1[] = { | 1967 static const MockOriginData kData1[] = { |
1968 { "http://foo.com/", kTemp, 1 }, | 1968 { "http://foo.com/", kTemp, 1 }, |
1969 }; | 1969 }; |
1970 static const MockOriginData kData2[] = { | 1970 static const MockOriginData kData2[] = { |
1971 { "http://foo.com/", kTemp, 2 }, | 1971 { "http://foo.com/", kTemp, 2 }, |
1972 }; | 1972 }; |
(...skipping 10 matching lines...) Expand all Loading... |
1983 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), | 1983 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), |
1984 QuotaClient::kDatabase); | 1984 QuotaClient::kDatabase); |
1985 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), | 1985 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), |
1986 QuotaClient::kIndexedDatabase); | 1986 QuotaClient::kIndexedDatabase); |
1987 RegisterClient(client1); | 1987 RegisterClient(client1); |
1988 RegisterClient(client2); | 1988 RegisterClient(client2); |
1989 RegisterClient(client3); | 1989 RegisterClient(client3); |
1990 RegisterClient(client4); | 1990 RegisterClient(client4); |
1991 | 1991 |
1992 GetHostUsage("foo.com", kTemp); | 1992 GetHostUsage("foo.com", kTemp); |
1993 MessageLoop::current()->RunAllPending(); | 1993 MessageLoop::current()->RunUntilIdle(); |
1994 const int64 predelete_foo_tmp = usage(); | 1994 const int64 predelete_foo_tmp = usage(); |
1995 | 1995 |
1996 DeleteOriginData(GURL("http://foo.com/"), kTemp, | 1996 DeleteOriginData(GURL("http://foo.com/"), kTemp, |
1997 QuotaClient::kFileSystem | QuotaClient::kDatabase); | 1997 QuotaClient::kFileSystem | QuotaClient::kDatabase); |
1998 MessageLoop::current()->RunAllPending(); | 1998 MessageLoop::current()->RunUntilIdle(); |
1999 GetHostUsage("foo.com", kTemp); | 1999 GetHostUsage("foo.com", kTemp); |
2000 MessageLoop::current()->RunAllPending(); | 2000 MessageLoop::current()->RunUntilIdle(); |
2001 EXPECT_EQ(predelete_foo_tmp - 4 - 1, usage()); | 2001 EXPECT_EQ(predelete_foo_tmp - 4 - 1, usage()); |
2002 | 2002 |
2003 DeleteOriginData(GURL("http://foo.com/"), kTemp, | 2003 DeleteOriginData(GURL("http://foo.com/"), kTemp, |
2004 QuotaClient::kAppcache | QuotaClient::kIndexedDatabase); | 2004 QuotaClient::kAppcache | QuotaClient::kIndexedDatabase); |
2005 MessageLoop::current()->RunAllPending(); | 2005 MessageLoop::current()->RunUntilIdle(); |
2006 GetHostUsage("foo.com", kTemp); | 2006 GetHostUsage("foo.com", kTemp); |
2007 MessageLoop::current()->RunAllPending(); | 2007 MessageLoop::current()->RunUntilIdle(); |
2008 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 2008 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
2009 } | 2009 } |
2010 | 2010 |
2011 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleHost) { | 2011 TEST_F(QuotaManagerTest, DeleteMultipleClientTypesSingleHost) { |
2012 static const MockOriginData kData1[] = { | 2012 static const MockOriginData kData1[] = { |
2013 { "http://foo.com:1111/", kTemp, 1 }, | 2013 { "http://foo.com:1111/", kTemp, 1 }, |
2014 }; | 2014 }; |
2015 static const MockOriginData kData2[] = { | 2015 static const MockOriginData kData2[] = { |
2016 { "http://foo.com:2222/", kTemp, 2 }, | 2016 { "http://foo.com:2222/", kTemp, 2 }, |
2017 }; | 2017 }; |
(...skipping 10 matching lines...) Expand all Loading... |
2028 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), | 2028 MockStorageClient* client3 = CreateClient(kData3, ARRAYSIZE_UNSAFE(kData3), |
2029 QuotaClient::kDatabase); | 2029 QuotaClient::kDatabase); |
2030 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), | 2030 MockStorageClient* client4 = CreateClient(kData4, ARRAYSIZE_UNSAFE(kData4), |
2031 QuotaClient::kIndexedDatabase); | 2031 QuotaClient::kIndexedDatabase); |
2032 RegisterClient(client1); | 2032 RegisterClient(client1); |
2033 RegisterClient(client2); | 2033 RegisterClient(client2); |
2034 RegisterClient(client3); | 2034 RegisterClient(client3); |
2035 RegisterClient(client4); | 2035 RegisterClient(client4); |
2036 | 2036 |
2037 GetHostUsage("foo.com", kTemp); | 2037 GetHostUsage("foo.com", kTemp); |
2038 MessageLoop::current()->RunAllPending(); | 2038 MessageLoop::current()->RunUntilIdle(); |
2039 const int64 predelete_foo_tmp = usage(); | 2039 const int64 predelete_foo_tmp = usage(); |
2040 | 2040 |
2041 DeleteHostData("foo.com", kTemp, | 2041 DeleteHostData("foo.com", kTemp, |
2042 QuotaClient::kFileSystem | QuotaClient::kAppcache); | 2042 QuotaClient::kFileSystem | QuotaClient::kAppcache); |
2043 MessageLoop::current()->RunAllPending(); | 2043 MessageLoop::current()->RunUntilIdle(); |
2044 GetHostUsage("foo.com", kTemp); | 2044 GetHostUsage("foo.com", kTemp); |
2045 MessageLoop::current()->RunAllPending(); | 2045 MessageLoop::current()->RunUntilIdle(); |
2046 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); | 2046 EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); |
2047 | 2047 |
2048 DeleteHostData("foo.com", kTemp, | 2048 DeleteHostData("foo.com", kTemp, |
2049 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); | 2049 QuotaClient::kDatabase | QuotaClient::kIndexedDatabase); |
2050 MessageLoop::current()->RunAllPending(); | 2050 MessageLoop::current()->RunUntilIdle(); |
2051 GetHostUsage("foo.com", kTemp); | 2051 GetHostUsage("foo.com", kTemp); |
2052 MessageLoop::current()->RunAllPending(); | 2052 MessageLoop::current()->RunUntilIdle(); |
2053 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); | 2053 EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); |
2054 } | 2054 } |
2055 } // namespace quota | 2055 } // namespace quota |
OLD | NEW |