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 "storage/browser/fileapi/quota/quota_reservation_manager.h" | 5 #include "storage/browser/fileapi/quota/quota_reservation_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 class FakeBackend : public QuotaReservationManager::QuotaBackend { | 45 class FakeBackend : public QuotaReservationManager::QuotaBackend { |
46 public: | 46 public: |
47 FakeBackend() | 47 FakeBackend() |
48 : on_memory_usage_(kInitialFileSize), | 48 : on_memory_usage_(kInitialFileSize), |
49 on_disk_usage_(kInitialFileSize) {} | 49 on_disk_usage_(kInitialFileSize) {} |
50 virtual ~FakeBackend() {} | 50 virtual ~FakeBackend() {} |
51 | 51 |
52 virtual void ReserveQuota(const GURL& origin, | 52 virtual void ReserveQuota(const GURL& origin, |
53 storage::FileSystemType type, | 53 storage::FileSystemType type, |
54 int64 delta, | 54 int64 delta, |
55 const ReserveQuotaCallback& callback) OVERRIDE { | 55 const ReserveQuotaCallback& callback) override { |
56 EXPECT_EQ(GURL(kOrigin), origin); | 56 EXPECT_EQ(GURL(kOrigin), origin); |
57 EXPECT_EQ(kType, type); | 57 EXPECT_EQ(kType, type); |
58 on_memory_usage_ += delta; | 58 on_memory_usage_ += delta; |
59 base::MessageLoopProxy::current()->PostTask( | 59 base::MessageLoopProxy::current()->PostTask( |
60 FROM_HERE, | 60 FROM_HERE, |
61 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta)); | 61 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta)); |
62 } | 62 } |
63 | 63 |
64 virtual void ReleaseReservedQuota(const GURL& origin, | 64 virtual void ReleaseReservedQuota(const GURL& origin, |
65 storage::FileSystemType type, | 65 storage::FileSystemType type, |
66 int64 size) OVERRIDE { | 66 int64 size) override { |
67 EXPECT_LE(0, size); | 67 EXPECT_LE(0, size); |
68 EXPECT_EQ(GURL(kOrigin), origin); | 68 EXPECT_EQ(GURL(kOrigin), origin); |
69 EXPECT_EQ(kType, type); | 69 EXPECT_EQ(kType, type); |
70 on_memory_usage_ -= size; | 70 on_memory_usage_ -= size; |
71 } | 71 } |
72 | 72 |
73 virtual void CommitQuotaUsage(const GURL& origin, | 73 virtual void CommitQuotaUsage(const GURL& origin, |
74 storage::FileSystemType type, | 74 storage::FileSystemType type, |
75 int64 delta) OVERRIDE { | 75 int64 delta) override { |
76 EXPECT_EQ(GURL(kOrigin), origin); | 76 EXPECT_EQ(GURL(kOrigin), origin); |
77 EXPECT_EQ(kType, type); | 77 EXPECT_EQ(kType, type); |
78 on_disk_usage_ += delta; | 78 on_disk_usage_ += delta; |
79 on_memory_usage_ += delta; | 79 on_memory_usage_ += delta; |
80 } | 80 } |
81 | 81 |
82 virtual void IncrementDirtyCount(const GURL& origin, | 82 virtual void IncrementDirtyCount(const GURL& origin, |
83 storage::FileSystemType type) OVERRIDE {} | 83 storage::FileSystemType type) override {} |
84 virtual void DecrementDirtyCount(const GURL& origin, | 84 virtual void DecrementDirtyCount(const GURL& origin, |
85 storage::FileSystemType type) OVERRIDE {} | 85 storage::FileSystemType type) override {} |
86 | 86 |
87 int64 on_memory_usage() { return on_memory_usage_; } | 87 int64 on_memory_usage() { return on_memory_usage_; } |
88 int64 on_disk_usage() { return on_disk_usage_; } | 88 int64 on_disk_usage() { return on_disk_usage_; } |
89 | 89 |
90 private: | 90 private: |
91 int64 on_memory_usage_; | 91 int64 on_memory_usage_; |
92 int64 on_disk_usage_; | 92 int64 on_disk_usage_; |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(FakeBackend); | 94 DISALLOW_COPY_AND_ASSIGN(FakeBackend); |
95 }; | 95 }; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_TRUE(done); | 175 EXPECT_TRUE(done); |
176 } | 176 } |
177 | 177 |
178 } // namespace | 178 } // namespace |
179 | 179 |
180 class QuotaReservationManagerTest : public testing::Test { | 180 class QuotaReservationManagerTest : public testing::Test { |
181 public: | 181 public: |
182 QuotaReservationManagerTest() {} | 182 QuotaReservationManagerTest() {} |
183 virtual ~QuotaReservationManagerTest() {} | 183 virtual ~QuotaReservationManagerTest() {} |
184 | 184 |
185 virtual void SetUp() OVERRIDE { | 185 virtual void SetUp() override { |
186 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); | 186 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); |
187 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge")); | 187 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge")); |
188 SetFileSize(file_path_, kInitialFileSize); | 188 SetFileSize(file_path_, kInitialFileSize); |
189 | 189 |
190 scoped_ptr<QuotaReservationManager::QuotaBackend> backend(new FakeBackend); | 190 scoped_ptr<QuotaReservationManager::QuotaBackend> backend(new FakeBackend); |
191 reservation_manager_.reset(new QuotaReservationManager(backend.Pass())); | 191 reservation_manager_.reset(new QuotaReservationManager(backend.Pass())); |
192 } | 192 } |
193 | 193 |
194 virtual void TearDown() OVERRIDE { | 194 virtual void TearDown() override { |
195 reservation_manager_.reset(); | 195 reservation_manager_.reset(); |
196 } | 196 } |
197 | 197 |
198 FakeBackend* fake_backend() { | 198 FakeBackend* fake_backend() { |
199 return static_cast<FakeBackend*>(reservation_manager_->backend_.get()); | 199 return static_cast<FakeBackend*>(reservation_manager_->backend_.get()); |
200 } | 200 } |
201 | 201 |
202 QuotaReservationManager* reservation_manager() { | 202 QuotaReservationManager* reservation_manager() { |
203 return reservation_manager_.get(); | 203 return reservation_manager_.get(); |
204 } | 204 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 358 |
359 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path())); | 359 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path())); |
360 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage()); | 360 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage()); |
361 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage()); | 361 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage()); |
362 | 362 |
363 reservation2 = NULL; | 363 reservation2 = NULL; |
364 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage()); | 364 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage()); |
365 } | 365 } |
366 | 366 |
367 } // namespace content | 367 } // namespace content |
OLD | NEW |