| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). | 63 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). |
| 64 class UsageMockQuotaManager : public QuotaManager { | 64 class UsageMockQuotaManager : public QuotaManager { |
| 65 public: | 65 public: |
| 66 UsageMockQuotaManager(SpecialStoragePolicy* special_storage_policy) | 66 UsageMockQuotaManager(SpecialStoragePolicy* special_storage_policy) |
| 67 : QuotaManager(false, | 67 : QuotaManager(false, |
| 68 base::FilePath(), | 68 base::FilePath(), |
| 69 base::ThreadTaskRunnerHandle::Get().get(), | 69 base::ThreadTaskRunnerHandle::Get().get(), |
| 70 base::ThreadTaskRunnerHandle::Get().get(), | 70 base::ThreadTaskRunnerHandle::Get().get(), |
| 71 special_storage_policy), | 71 special_storage_policy, |
| 72 storage::GetQuotaSettingsFunc()), |
| 72 callback_usage_(0), | 73 callback_usage_(0), |
| 73 callback_quota_(0), | 74 callback_quota_(0), |
| 74 callback_status_(kQuotaStatusOk), | 75 callback_status_(kQuotaStatusOk), |
| 75 initialized_(false) {} | 76 initialized_(false) {} |
| 76 | 77 |
| 77 void SetCallbackParams(int64_t usage, int64_t quota, QuotaStatusCode status) { | 78 void SetCallbackParams(int64_t usage, int64_t quota, QuotaStatusCode status) { |
| 78 initialized_ = true; | 79 initialized_ = true; |
| 79 callback_quota_ = quota; | 80 callback_quota_ = quota; |
| 80 callback_usage_ = usage; | 81 callback_usage_ = usage; |
| 81 callback_status_ = status; | 82 callback_status_ = status; |
| 82 } | 83 } |
| 83 | 84 |
| 84 void InvokeCallback() { | 85 void InvokeCallback() { |
| 85 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); | 86 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void GetUsageAndQuotaForWebApps( | 89 void GetUsageAndQuotaForWebApps( |
| 89 const GURL& origin, | 90 const GURL& origin, |
| 90 StorageType type, | 91 StorageType type, |
| 91 const GetUsageAndQuotaCallback& callback) override { | 92 const UsageAndQuotaCallback& callback) override { |
| 92 if (initialized_) | 93 if (initialized_) |
| 93 callback.Run(callback_status_, callback_usage_, callback_quota_); | 94 callback.Run(callback_status_, callback_usage_, callback_quota_); |
| 94 else | 95 else |
| 95 delayed_callback_ = callback; | 96 delayed_callback_ = callback; |
| 96 } | 97 } |
| 97 | 98 |
| 98 protected: | 99 protected: |
| 99 ~UsageMockQuotaManager() override {} | 100 ~UsageMockQuotaManager() override {} |
| 100 | 101 |
| 101 private: | 102 private: |
| 102 int64_t callback_usage_; | 103 int64_t callback_usage_; |
| 103 int64_t callback_quota_; | 104 int64_t callback_quota_; |
| 104 QuotaStatusCode callback_status_; | 105 QuotaStatusCode callback_status_; |
| 105 bool initialized_; | 106 bool initialized_; |
| 106 GetUsageAndQuotaCallback delayed_callback_; | 107 UsageAndQuotaCallback delayed_callback_; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace | 110 } // namespace |
| 110 | 111 |
| 111 class StorageMonitorTestBase : public testing::Test { | 112 class StorageMonitorTestBase : public testing::Test { |
| 112 protected: | 113 protected: |
| 113 void DispatchPendingEvents(StorageObserverList& observer_list) { | 114 void DispatchPendingEvents(StorageObserverList& observer_list) { |
| 114 observer_list.DispatchPendingEvent(); | 115 observer_list.DispatchPendingEvent(); |
| 115 } | 116 } |
| 116 | 117 |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 643 |
| 643 // Integration test for QuotaManager and StorageMonitor: | 644 // Integration test for QuotaManager and StorageMonitor: |
| 644 | 645 |
| 645 class StorageMonitorIntegrationTest : public testing::Test { | 646 class StorageMonitorIntegrationTest : public testing::Test { |
| 646 public: | 647 public: |
| 647 void SetUp() override { | 648 void SetUp() override { |
| 648 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 649 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 649 storage_policy_ = new MockSpecialStoragePolicy(); | 650 storage_policy_ = new MockSpecialStoragePolicy(); |
| 650 quota_manager_ = new QuotaManager( | 651 quota_manager_ = new QuotaManager( |
| 651 false, data_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get(), | 652 false, data_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get(), |
| 652 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get()); | 653 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get(), |
| 654 storage::GetQuotaSettingsFunc()); |
| 653 | 655 |
| 654 client_ = new MockStorageClient(quota_manager_->proxy(), | 656 client_ = new MockStorageClient(quota_manager_->proxy(), |
| 655 NULL, | 657 NULL, |
| 656 QuotaClient::kFileSystem, | 658 QuotaClient::kFileSystem, |
| 657 0); | 659 0); |
| 658 | 660 |
| 659 quota_manager_->proxy()->RegisterClient(client_); | 661 quota_manager_->proxy()->RegisterClient(client_); |
| 660 } | 662 } |
| 661 | 663 |
| 662 void TearDown() override { | 664 void TearDown() override { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 base::RunLoop().RunUntilIdle(); | 696 base::RunLoop().RunUntilIdle(); |
| 695 | 697 |
| 696 // Verify that the observer receives it. | 698 // Verify that the observer receives it. |
| 697 ASSERT_EQ(1, mock_observer.EventCount()); | 699 ASSERT_EQ(1, mock_observer.EventCount()); |
| 698 const StorageObserver::Event& event = mock_observer.LastEvent(); | 700 const StorageObserver::Event& event = mock_observer.LastEvent(); |
| 699 EXPECT_EQ(params.filter, event.filter); | 701 EXPECT_EQ(params.filter, event.filter); |
| 700 EXPECT_EQ(kTestUsage, event.usage); | 702 EXPECT_EQ(kTestUsage, event.usage); |
| 701 } | 703 } |
| 702 | 704 |
| 703 } // namespace content | 705 } // namespace content |
| OLD | NEW |