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

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

Issue 61593002: Quota: Implement QuotaBackendImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build and test Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "webkit/browser/fileapi/quota/quota_reservation_manager.h" 5 #include "webkit/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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 FileSystemType type, 57 FileSystemType type,
58 int64 delta, 58 int64 delta,
59 const StatusCallback& callback) OVERRIDE { 59 const StatusCallback& callback) OVERRIDE {
60 EXPECT_EQ(GURL(kOrigin), origin); 60 EXPECT_EQ(GURL(kOrigin), origin);
61 EXPECT_EQ(kType, type); 61 EXPECT_EQ(kType, type);
62 on_disk_usage_ += delta; 62 on_disk_usage_ += delta;
63 base::MessageLoopProxy::current()->PostTask( 63 base::MessageLoopProxy::current()->PostTask(
64 FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK)); 64 FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK));
65 } 65 }
66 66
67 virtual void IncreaseDirtyCount(const GURL& origin, 67 virtual void IncrementDirtyCount(const GURL& origin,
68 FileSystemType type) OVERRIDE {} 68 FileSystemType type) OVERRIDE {}
69 virtual void DecreaseDirtyCount(const GURL& origin, 69 virtual void DecrementDirtyCount(const GURL& origin,
70 FileSystemType type) OVERRIDE {} 70 FileSystemType type) OVERRIDE {}
71 71
72 int64 on_memory_usage() { return on_memory_usage_; } 72 int64 on_memory_usage() { return on_memory_usage_; }
73 int64 on_disk_usage() { return on_disk_usage_; } 73 int64 on_disk_usage() { return on_disk_usage_; }
74 74
75 private: 75 private:
76 int64 on_memory_usage_; 76 int64 on_memory_usage_;
77 int64 on_disk_usage_; 77 int64 on_disk_usage_;
78 78
79 DISALLOW_COPY_AND_ASSIGN(FakeBackend); 79 DISALLOW_COPY_AND_ASSIGN(FakeBackend);
80 }; 80 };
(...skipping 18 matching lines...) Expand all
99 class QuotaReservationManagerTest : public testing::Test { 99 class QuotaReservationManagerTest : public testing::Test {
100 public: 100 public:
101 QuotaReservationManagerTest() {} 101 QuotaReservationManagerTest() {}
102 virtual ~QuotaReservationManagerTest() {} 102 virtual ~QuotaReservationManagerTest() {}
103 103
104 virtual void SetUp() OVERRIDE { 104 virtual void SetUp() OVERRIDE {
105 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); 105 ASSERT_TRUE(work_dir_.CreateUniqueTempDir());
106 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge")); 106 file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge"));
107 SetFileSize(kInitialFileSize); 107 SetFileSize(kInitialFileSize);
108 108
109 fake_backend_.reset(new FakeBackend); 109 fake_backend_ = new FakeBackend;
110 reservation_manager_.reset(new QuotaReservationManager( 110 reservation_manager_.reset(new QuotaReservationManager(fake_backend_));
111 fake_backend_.get()));
112 } 111 }
113 112
114 virtual void TearDown() OVERRIDE { 113 virtual void TearDown() OVERRIDE {
115 reservation_manager_.reset(); 114 reservation_manager_.reset();
116 fake_backend_.reset();
117 } 115 }
118 116
119 int64 GetFileSize() { 117 int64 GetFileSize() {
120 int64 size = 0; 118 int64 size = 0;
121 file_util::GetFileSize(file_path_, &size); 119 file_util::GetFileSize(file_path_, &size);
122 return size; 120 return size;
123 } 121 }
124 122
125 void SetFileSize(int64 size) { 123 void SetFileSize(int64 size) {
126 bool created = false; 124 bool created = false;
127 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 125 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
128 base::PlatformFile file = CreatePlatformFile( 126 base::PlatformFile file = CreatePlatformFile(
129 file_path_, 127 file_path_,
130 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, 128 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
131 &created, &error); 129 &created, &error);
132 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 130 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
133 ASSERT_TRUE(base::TruncatePlatformFile(file, size)); 131 ASSERT_TRUE(base::TruncatePlatformFile(file, size));
134 ASSERT_TRUE(base::ClosePlatformFile(file)); 132 ASSERT_TRUE(base::ClosePlatformFile(file));
135 } 133 }
136 134
137 void ExtendFileTo(int64 size) { 135 void ExtendFileTo(int64 size) {
138 if (GetFileSize() < size) 136 if (GetFileSize() < size)
139 SetFileSize(size); 137 SetFileSize(size);
140 } 138 }
141 139
142 FakeBackend* fake_backend() { 140 FakeBackend* fake_backend() {
143 return fake_backend_.get(); 141 return fake_backend_;
144 } 142 }
145 143
146 QuotaReservationManager* reservation_manager() { 144 QuotaReservationManager* reservation_manager() {
147 return reservation_manager_.get(); 145 return reservation_manager_.get();
148 } 146 }
149 147
150 const base::FilePath& file_path() const { 148 const base::FilePath& file_path() const {
151 return file_path_; 149 return file_path_;
152 } 150 }
153 151
154 private: 152 private:
155 base::MessageLoop message_loop_; 153 base::MessageLoop message_loop_;
156 base::ScopedTempDir work_dir_; 154 base::ScopedTempDir work_dir_;
157 base::FilePath file_path_; 155 base::FilePath file_path_;
158 scoped_ptr<FakeBackend> fake_backend_;
159 scoped_ptr<QuotaReservationManager> reservation_manager_; 156 scoped_ptr<QuotaReservationManager> reservation_manager_;
160 157
158 // Owned by QuotaReservationManager.
159 FakeBackend* fake_backend_;
160
161 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest); 161 DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest);
162 }; 162 };
163 163
164 TEST_F(QuotaReservationManagerTest, BasicTest) { 164 TEST_F(QuotaReservationManagerTest, BasicTest) {
165 GURL origin(kOrigin); 165 GURL origin(kOrigin);
166 FileSystemType type = kType; 166 FileSystemType type = kType;
167 167
168 // Create Reservation channel for the origin and type. 168 // Create Reservation channel for the origin and type.
169 // Reservation holds remaining quota reservation and provides a method to 169 // Reservation holds remaining quota reservation and provides a method to
170 // refresh it. 170 // refresh it.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 356
357 EXPECT_EQ(400, GetFileSize()); 357 EXPECT_EQ(400, GetFileSize());
358 EXPECT_EQ(0, fake_backend()->on_memory_usage()); 358 EXPECT_EQ(0, fake_backend()->on_memory_usage());
359 EXPECT_EQ(400 - kInitialFileSize, fake_backend()->on_disk_usage()); 359 EXPECT_EQ(400 - kInitialFileSize, fake_backend()->on_disk_usage());
360 } 360 }
361 361
362 // TODO(tzik): Add Truncate test. 362 // TODO(tzik): Add Truncate test.
363 // TODO(tzik): Add PluginCrash test and DropReservationManager test. 363 // TODO(tzik): Add PluginCrash test and DropReservationManager test.
364 364
365 } // namespace fileapi 365 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698