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

Side by Side Diff: storage/browser/fileapi/quota/quota_reservation_manager_unittest.cc

Issue 2776273002: Move some quota tests next to the files they cover. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « storage/browser/fileapi/quota/quota_backend_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 void SetFileSize(const base::FilePath& path, int64_t size) { 46 void SetFileSize(const base::FilePath& path, int64_t size) {
47 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); 47 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE);
48 ASSERT_TRUE(file.IsValid()); 48 ASSERT_TRUE(file.IsValid());
49 ASSERT_TRUE(file.SetLength(size)); 49 ASSERT_TRUE(file.SetLength(size));
50 } 50 }
51 51
52 class FakeBackend : public QuotaReservationManager::QuotaBackend { 52 class FakeBackend : public QuotaReservationManager::QuotaBackend {
53 public: 53 public:
54 FakeBackend() 54 FakeBackend()
55 : on_memory_usage_(kInitialFileSize), 55 : on_memory_usage_(kInitialFileSize), on_disk_usage_(kInitialFileSize) {}
56 on_disk_usage_(kInitialFileSize) {}
57 ~FakeBackend() override {} 56 ~FakeBackend() override {}
58 57
59 void ReserveQuota(const GURL& origin, 58 void ReserveQuota(const GURL& origin,
60 storage::FileSystemType type, 59 storage::FileSystemType type,
61 int64_t delta, 60 int64_t delta,
62 const ReserveQuotaCallback& callback) override { 61 const ReserveQuotaCallback& callback) override {
63 EXPECT_EQ(GURL(kOrigin), origin); 62 EXPECT_EQ(GURL(kOrigin), origin);
64 EXPECT_EQ(kType, type); 63 EXPECT_EQ(kType, type);
65 on_memory_usage_ += delta; 64 on_memory_usage_ += delta;
66 base::ThreadTaskRunnerHandle::Get()->PostTask( 65 base::ThreadTaskRunnerHandle::Get()->PostTask(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 146 }
148 147
149 void ReportUsage() { 148 void ReportUsage() {
150 handle_->UpdateMaxWrittenOffset(max_written_offset_); 149 handle_->UpdateMaxWrittenOffset(max_written_offset_);
151 handle_->AddAppendModeWriteAmount(append_mode_write_amount_); 150 handle_->AddAppendModeWriteAmount(append_mode_write_amount_);
152 max_written_offset_ = handle_->GetEstimatedFileSize(); 151 max_written_offset_ = handle_->GetEstimatedFileSize();
153 append_mode_write_amount_ = 0; 152 append_mode_write_amount_ = 0;
154 dirty_ = false; 153 dirty_ = false;
155 } 154 }
156 155
157 void ClearWithoutUsageReport() { 156 void ClearWithoutUsageReport() { handle_.reset(); }
158 handle_.reset();
159 }
160 157
161 private: 158 private:
162 std::unique_ptr<OpenFileHandle> handle_; 159 std::unique_ptr<OpenFileHandle> handle_;
163 base::FilePath path_; 160 base::FilePath path_;
164 int64_t max_written_offset_; 161 int64_t max_written_offset_;
165 int64_t append_mode_write_amount_; 162 int64_t append_mode_write_amount_;
166 bool dirty_; 163 bool dirty_;
167 }; 164 };
168 165
169 void ExpectSuccess(bool* done, base::File::Error error) { 166 void ExpectSuccess(bool* done, base::File::Error error) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 void TearDown() override { reservation_manager_.reset(); } 198 void TearDown() override { reservation_manager_.reset(); }
202 199
203 FakeBackend* fake_backend() { 200 FakeBackend* fake_backend() {
204 return static_cast<FakeBackend*>(reservation_manager_->backend_.get()); 201 return static_cast<FakeBackend*>(reservation_manager_->backend_.get());
205 } 202 }
206 203
207 QuotaReservationManager* reservation_manager() { 204 QuotaReservationManager* reservation_manager() {
208 return reservation_manager_.get(); 205 return reservation_manager_.get();
209 } 206 }
210 207
211 const base::FilePath& file_path() const { 208 const base::FilePath& file_path() const { return file_path_; }
212 return file_path_;
213 }
214 209
215 private: 210 private:
216 base::MessageLoop message_loop_; 211 base::MessageLoop message_loop_;
217 base::ScopedTempDir work_dir_; 212 base::ScopedTempDir work_dir_;
218 base::FilePath file_path_; 213 base::FilePath file_path_;
219 std::unique_ptr<QuotaReservationManager> reservation_manager_; 214 std::unique_ptr<QuotaReservationManager> reservation_manager_;
220 215
221 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest); 216 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest);
222 }; 217 };
223 218
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 358
364 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path())); 359 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path()));
365 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage()); 360 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage());
366 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage()); 361 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage());
367 362
368 reservation2 = NULL; 363 reservation2 = NULL;
369 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage()); 364 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage());
370 } 365 }
371 366
372 } // namespace content 367 } // namespace content
OLDNEW
« no previous file with comments | « storage/browser/fileapi/quota/quota_backend_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698