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

Side by Side Diff: content/browser/quota/storage_monitor_unittest.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::GetTemporaryStorageConfigurationFunc()),
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) {
77 }
76 78
77 void SetCallbackParams(int64_t usage, int64_t quota, QuotaStatusCode status) { 79 void SetCallbackParams(int64_t usage, int64_t quota, QuotaStatusCode status) {
78 initialized_ = true; 80 initialized_ = true;
79 callback_quota_ = quota; 81 callback_quota_ = quota;
80 callback_usage_ = usage; 82 callback_usage_ = usage;
81 callback_status_ = status; 83 callback_status_ = status;
82 } 84 }
83 85
84 void InvokeCallback() { 86 void InvokeCallback() {
85 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_); 87 delayed_callback_.Run(callback_status_, callback_usage_, callback_quota_);
86 } 88 }
87 89
88 void GetUsageAndQuotaForWebApps( 90 void GetUsageAndQuotaForWebApps(
89 const GURL& origin, 91 const GURL& origin,
90 StorageType type, 92 StorageType type,
91 const GetUsageAndQuotaCallback& callback) override { 93 const UsageAndQuotaCallback& callback) override {
92 if (initialized_) 94 if (initialized_)
93 callback.Run(callback_status_, callback_usage_, callback_quota_); 95 callback.Run(callback_status_, callback_usage_, callback_quota_);
94 else 96 else
95 delayed_callback_ = callback; 97 delayed_callback_ = callback;
96 } 98 }
97 99
98 protected: 100 protected:
99 ~UsageMockQuotaManager() override {} 101 ~UsageMockQuotaManager() override {}
100 102
101 private: 103 private:
102 int64_t callback_usage_; 104 int64_t callback_usage_;
103 int64_t callback_quota_; 105 int64_t callback_quota_;
104 QuotaStatusCode callback_status_; 106 QuotaStatusCode callback_status_;
105 bool initialized_; 107 bool initialized_;
106 GetUsageAndQuotaCallback delayed_callback_; 108 UsageAndQuotaCallback delayed_callback_;
107 }; 109 };
108 110
109 } // namespace 111 } // namespace
110 112
111 class StorageMonitorTestBase : public testing::Test { 113 class StorageMonitorTestBase : public testing::Test {
112 protected: 114 protected:
113 void DispatchPendingEvents(StorageObserverList& observer_list) { 115 void DispatchPendingEvents(StorageObserverList& observer_list) {
114 observer_list.DispatchPendingEvent(); 116 observer_list.DispatchPendingEvent();
115 } 117 }
116 118
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 644
643 // Integration test for QuotaManager and StorageMonitor: 645 // Integration test for QuotaManager and StorageMonitor:
644 646
645 class StorageMonitorIntegrationTest : public testing::Test { 647 class StorageMonitorIntegrationTest : public testing::Test {
646 public: 648 public:
647 void SetUp() override { 649 void SetUp() override {
648 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 650 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
649 storage_policy_ = new MockSpecialStoragePolicy(); 651 storage_policy_ = new MockSpecialStoragePolicy();
650 quota_manager_ = new QuotaManager( 652 quota_manager_ = new QuotaManager(
651 false, data_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get(), 653 false, data_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get(),
652 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get()); 654 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get(),
655 storage::GetTemporaryStorageConfigurationFunc());
653 656
654 client_ = new MockStorageClient(quota_manager_->proxy(), 657 client_ = new MockStorageClient(quota_manager_->proxy(),
655 NULL, 658 NULL,
656 QuotaClient::kFileSystem, 659 QuotaClient::kFileSystem,
657 0); 660 0);
658 661
659 quota_manager_->proxy()->RegisterClient(client_); 662 quota_manager_->proxy()->RegisterClient(client_);
660 } 663 }
661 664
662 void TearDown() override { 665 void TearDown() override {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 base::RunLoop().RunUntilIdle(); 697 base::RunLoop().RunUntilIdle();
695 698
696 // Verify that the observer receives it. 699 // Verify that the observer receives it.
697 ASSERT_EQ(1, mock_observer.EventCount()); 700 ASSERT_EQ(1, mock_observer.EventCount());
698 const StorageObserver::Event& event = mock_observer.LastEvent(); 701 const StorageObserver::Event& event = mock_observer.LastEvent();
699 EXPECT_EQ(params.filter, event.filter); 702 EXPECT_EQ(params.filter, event.filter);
700 EXPECT_EQ(kTestUsage, event.usage); 703 EXPECT_EQ(kTestUsage, event.usage);
701 } 704 }
702 705
703 } // namespace content 706 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698