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