OLD | NEW |
---|---|
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 "content/browser/renderer_host/pepper/quota_reservation.h" | 5 #include "content/browser/renderer_host/pepper/quota_reservation.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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); | 75 ASSERT_TRUE(work_dir_.CreateUniqueTempDir()); |
76 | 76 |
77 reservation_manager_.reset(new QuotaReservationManager( | 77 reservation_manager_.reset(new QuotaReservationManager( |
78 scoped_ptr<QuotaReservationManager::QuotaBackend>(new FakeBackend))); | 78 scoped_ptr<QuotaReservationManager::QuotaBackend>(new FakeBackend))); |
79 } | 79 } |
80 | 80 |
81 virtual void TearDown() OVERRIDE { | 81 virtual void TearDown() OVERRIDE { |
82 reservation_manager_.reset(); | 82 reservation_manager_.reset(); |
83 } | 83 } |
84 | 84 |
85 base::FilePath MakeFilePath(base::FilePath::StringType file_name) { | 85 base::FilePath MakeFilePath(const base::FilePath::StringType& file_name) { |
bbudge
2014/01/09 13:23:50
Thanks for fixing it, but I think it can be remove
tzik
2014/01/10 05:34:08
That is used in SetFileSize(), and now used in Mak
| |
86 return work_dir_.path().Append(file_name); | 86 return work_dir_.path().Append(file_name); |
87 } | 87 } |
88 | 88 |
89 fileapi::FileSystemURL MakeFileSystemURL( | |
90 const base::FilePath::StringType& file_name) { | |
91 return fileapi::FileSystemURL::CreateForTest( | |
92 GURL(kOrigin), kType, work_dir_.path().Append(file_name)); | |
93 } | |
94 | |
89 scoped_refptr<QuotaReservation> CreateQuotaReservation( | 95 scoped_refptr<QuotaReservation> CreateQuotaReservation( |
90 scoped_refptr<fileapi::QuotaReservation> reservation, | 96 scoped_refptr<fileapi::QuotaReservation> reservation, |
91 const GURL& origin, | 97 const GURL& origin, |
92 FileSystemType type) { | 98 FileSystemType type) { |
93 // Sets reservation_ as a side effect. | 99 // Sets reservation_ as a side effect. |
94 return scoped_refptr<QuotaReservation>( | 100 return scoped_refptr<QuotaReservation>( |
95 new QuotaReservation(reservation, origin, type)); | 101 new QuotaReservation(reservation, origin, type)); |
96 } | 102 } |
97 | 103 |
98 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) { | 104 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 int64 amount = 100; | 163 int64 amount = 100; |
158 int64 reserved_quota; | 164 int64 reserved_quota; |
159 QuotaReservation::OffsetMap max_written_offsets; | 165 QuotaReservation::OffsetMap max_written_offsets; |
160 ReserveQuota(test, amount, &reserved_quota, &max_written_offsets); | 166 ReserveQuota(test, amount, &reserved_quota, &max_written_offsets); |
161 EXPECT_EQ(amount, reserved_quota); | 167 EXPECT_EQ(amount, reserved_quota); |
162 EXPECT_EQ(0U, max_written_offsets.size()); | 168 EXPECT_EQ(0U, max_written_offsets.size()); |
163 | 169 |
164 // Open a file, refresh the reservation, extend the file, and close it. | 170 // Open a file, refresh the reservation, extend the file, and close it. |
165 int64 file_size = 10; | 171 int64 file_size = 10; |
166 SetFileSize(file1_name, file_size); | 172 SetFileSize(file1_name, file_size); |
167 int64 open_file_size = test->OpenFile(kFile1ID, MakeFilePath(file1_name)); | 173 int64 open_file_size = test->OpenFile(kFile1ID, |
174 MakeFileSystemURL(file1_name)); | |
168 EXPECT_EQ(file_size, open_file_size); | 175 EXPECT_EQ(file_size, open_file_size); |
169 | 176 |
170 max_written_offsets[kFile1ID] = file_size; // 1 file open. | 177 max_written_offsets[kFile1ID] = file_size; // 1 file open. |
171 ReserveQuota(test, amount, &reserved_quota, &max_written_offsets); | 178 ReserveQuota(test, amount, &reserved_quota, &max_written_offsets); |
172 EXPECT_EQ(amount, reserved_quota); | 179 EXPECT_EQ(amount, reserved_quota); |
173 EXPECT_EQ(1U, max_written_offsets.size()); | 180 EXPECT_EQ(1U, max_written_offsets.size()); |
174 EXPECT_EQ(file_size, max_written_offsets[kFile1ID]); | 181 EXPECT_EQ(file_size, max_written_offsets[kFile1ID]); |
175 | 182 |
176 int64 new_file_size = 30; | 183 int64 new_file_size = 30; |
177 SetFileSize(file1_name, new_file_size); | 184 SetFileSize(file1_name, new_file_size); |
(...skipping 11 matching lines...) Expand all Loading... | |
189 FileSystemType type = kType; | 196 FileSystemType type = kType; |
190 | 197 |
191 scoped_refptr<fileapi::QuotaReservation> reservation( | 198 scoped_refptr<fileapi::QuotaReservation> reservation( |
192 reservation_manager()->CreateReservation(origin, type)); | 199 reservation_manager()->CreateReservation(origin, type)); |
193 scoped_refptr<QuotaReservation> test = | 200 scoped_refptr<QuotaReservation> test = |
194 CreateQuotaReservation(reservation, origin, type); | 201 CreateQuotaReservation(reservation, origin, type); |
195 | 202 |
196 // Open some files of different sizes. | 203 // Open some files of different sizes. |
197 int64 file1_size = 10; | 204 int64 file1_size = 10; |
198 SetFileSize(file1_name, file1_size); | 205 SetFileSize(file1_name, file1_size); |
199 int64 open_file1_size = test->OpenFile(kFile1ID, MakeFilePath(file1_name)); | 206 int64 open_file1_size = test->OpenFile(kFile1ID, |
207 MakeFileSystemURL(file1_name)); | |
200 EXPECT_EQ(file1_size, open_file1_size); | 208 EXPECT_EQ(file1_size, open_file1_size); |
201 int64 file2_size = 20; | 209 int64 file2_size = 20; |
202 SetFileSize(file2_name, file2_size); | 210 SetFileSize(file2_name, file2_size); |
203 int64 open_file2_size = test->OpenFile(kFile2ID, MakeFilePath(file2_name)); | 211 int64 open_file2_size = test->OpenFile(kFile2ID, |
212 MakeFileSystemURL(file2_name)); | |
204 EXPECT_EQ(file2_size, open_file2_size); | 213 EXPECT_EQ(file2_size, open_file2_size); |
205 int64 file3_size = 30; | 214 int64 file3_size = 30; |
206 SetFileSize(file3_name, file3_size); | 215 SetFileSize(file3_name, file3_size); |
207 int64 open_file3_size = test->OpenFile(kFile3ID, MakeFilePath(file3_name)); | 216 int64 open_file3_size = test->OpenFile(kFile3ID, |
217 MakeFileSystemURL(file3_name)); | |
208 EXPECT_EQ(file3_size, open_file3_size); | 218 EXPECT_EQ(file3_size, open_file3_size); |
209 | 219 |
210 // Reserve quota. | 220 // Reserve quota. |
211 int64 amount = 100; | 221 int64 amount = 100; |
212 int64 reserved_quota; | 222 int64 reserved_quota; |
213 QuotaReservation::OffsetMap max_written_offsets; | 223 QuotaReservation::OffsetMap max_written_offsets; |
214 max_written_offsets[kFile1ID] = file1_size; // 3 files open. | 224 max_written_offsets[kFile1ID] = file1_size; // 3 files open. |
215 max_written_offsets[kFile2ID] = file2_size; | 225 max_written_offsets[kFile2ID] = file2_size; |
216 max_written_offsets[kFile3ID] = file3_size; | 226 max_written_offsets[kFile3ID] = file3_size; |
217 | 227 |
(...skipping 11 matching lines...) Expand all Loading... | |
229 EXPECT_EQ(amount, reserved_quota); | 239 EXPECT_EQ(amount, reserved_quota); |
230 EXPECT_EQ(2U, max_written_offsets.size()); | 240 EXPECT_EQ(2U, max_written_offsets.size()); |
231 EXPECT_EQ(file1_size, max_written_offsets[kFile1ID]); | 241 EXPECT_EQ(file1_size, max_written_offsets[kFile1ID]); |
232 EXPECT_EQ(file3_size, max_written_offsets[kFile3ID]); | 242 EXPECT_EQ(file3_size, max_written_offsets[kFile3ID]); |
233 | 243 |
234 test->CloseFile(kFile1ID, file1_size); | 244 test->CloseFile(kFile1ID, file1_size); |
235 test->CloseFile(kFile3ID, file3_size); | 245 test->CloseFile(kFile3ID, file3_size); |
236 } | 246 } |
237 | 247 |
238 } // namespace content | 248 } // namespace content |
OLD | NEW |