| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/message_loop/message_loop_proxy.h" | |
| 10 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/public/test/mock_special_storage_policy.h" | 10 #include "content/public/test/mock_special_storage_policy.h" |
| 12 #include "content/public/test/mock_storage_client.h" | 11 #include "content/public/test/mock_storage_client.h" |
| 13 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 14 #include "storage/browser/quota/quota_manager.h" | 13 #include "storage/browser/quota/quota_manager.h" |
| 15 #include "storage/browser/quota/quota_manager_proxy.h" | 14 #include "storage/browser/quota/quota_manager_proxy.h" |
| 16 #include "storage/browser/quota/storage_monitor.h" | 15 #include "storage/browser/quota/storage_monitor.h" |
| 17 #include "storage/browser/quota/storage_observer.h" | 16 #include "storage/browser/quota/storage_observer.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| 20 using storage::HostStorageObservers; | 19 using storage::HostStorageObservers; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 55 } |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 std::vector<StorageObserver::Event> events_; | 58 std::vector<StorageObserver::Event> events_; |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). | 61 // A mock quota manager for overriding GetUsageAndQuotaForWebApps(). |
| 63 class UsageMockQuotaManager : public QuotaManager { | 62 class UsageMockQuotaManager : public QuotaManager { |
| 64 public: | 63 public: |
| 65 UsageMockQuotaManager(SpecialStoragePolicy* special_storage_policy) | 64 UsageMockQuotaManager(SpecialStoragePolicy* special_storage_policy) |
| 66 : QuotaManager( | 65 : QuotaManager(false, |
| 67 false, | 66 base::FilePath(), |
| 68 base::FilePath(), | 67 base::ThreadTaskRunnerHandle::Get().get(), |
| 69 base::MessageLoopProxy::current().get(), | 68 base::ThreadTaskRunnerHandle::Get().get(), |
| 70 base::MessageLoopProxy::current().get(), | 69 special_storage_policy), |
| 71 special_storage_policy), | |
| 72 callback_usage_(0), | 70 callback_usage_(0), |
| 73 callback_quota_(0), | 71 callback_quota_(0), |
| 74 callback_status_(kQuotaStatusOk), | 72 callback_status_(kQuotaStatusOk), |
| 75 initialized_(false) { | 73 initialized_(false) {} |
| 76 } | |
| 77 | 74 |
| 78 void SetCallbackParams(int64 usage, int64 quota, QuotaStatusCode status) { | 75 void SetCallbackParams(int64 usage, int64 quota, QuotaStatusCode status) { |
| 79 initialized_ = true; | 76 initialized_ = true; |
| 80 callback_quota_ = quota; | 77 callback_quota_ = quota; |
| 81 callback_usage_ = usage; | 78 callback_usage_ = usage; |
| 82 callback_status_ = status; | 79 callback_status_ = status; |
| 83 } | 80 } |
| 84 | 81 |
| 85 void InvokeCallback() { | 82 void InvokeCallback() { |
| 86 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); | 83 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } | 639 } |
| 643 | 640 |
| 644 // Integration test for QuotaManager and StorageMonitor: | 641 // Integration test for QuotaManager and StorageMonitor: |
| 645 | 642 |
| 646 class StorageMonitorIntegrationTest : public testing::Test { | 643 class StorageMonitorIntegrationTest : public testing::Test { |
| 647 public: | 644 public: |
| 648 void SetUp() override { | 645 void SetUp() override { |
| 649 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 646 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 650 storage_policy_ = new MockSpecialStoragePolicy(); | 647 storage_policy_ = new MockSpecialStoragePolicy(); |
| 651 quota_manager_ = new QuotaManager( | 648 quota_manager_ = new QuotaManager( |
| 652 false, | 649 false, data_dir_.path(), base::ThreadTaskRunnerHandle::Get().get(), |
| 653 data_dir_.path(), | 650 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get()); |
| 654 base::MessageLoopProxy::current().get(), | |
| 655 base::MessageLoopProxy::current().get(), | |
| 656 storage_policy_.get()); | |
| 657 | 651 |
| 658 client_ = new MockStorageClient(quota_manager_->proxy(), | 652 client_ = new MockStorageClient(quota_manager_->proxy(), |
| 659 NULL, | 653 NULL, |
| 660 QuotaClient::kFileSystem, | 654 QuotaClient::kFileSystem, |
| 661 0); | 655 0); |
| 662 | 656 |
| 663 quota_manager_->proxy()->RegisterClient(client_); | 657 quota_manager_->proxy()->RegisterClient(client_); |
| 664 } | 658 } |
| 665 | 659 |
| 666 void TearDown() override { | 660 void TearDown() override { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 base::RunLoop().RunUntilIdle(); | 692 base::RunLoop().RunUntilIdle(); |
| 699 | 693 |
| 700 // Verify that the observer receives it. | 694 // Verify that the observer receives it. |
| 701 ASSERT_EQ(1, mock_observer.EventCount()); | 695 ASSERT_EQ(1, mock_observer.EventCount()); |
| 702 const StorageObserver::Event& event = mock_observer.LastEvent(); | 696 const StorageObserver::Event& event = mock_observer.LastEvent(); |
| 703 EXPECT_EQ(params.filter, event.filter); | 697 EXPECT_EQ(params.filter, event.filter); |
| 704 EXPECT_EQ(kTestUsage, event.usage); | 698 EXPECT_EQ(kTestUsage, event.usage); |
| 705 } | 699 } |
| 706 | 700 |
| 707 } // namespace content | 701 } // namespace content |
| OLD | NEW |