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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
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 base::RunLoop().RunUntilIdle(); |
83 } | 84 } |
84 | 85 |
85 base::FilePath MakeFilePath(const base::FilePath::StringType& file_name) { | 86 base::FilePath MakeFilePath(const base::FilePath::StringType& file_name) { |
86 return work_dir_.path().Append(file_name); | 87 return work_dir_.path().Append(file_name); |
87 } | 88 } |
88 | 89 |
89 fileapi::FileSystemURL MakeFileSystemURL( | 90 fileapi::FileSystemURL MakeFileSystemURL( |
90 const base::FilePath::StringType& file_name) { | 91 const base::FilePath::StringType& file_name) { |
91 return fileapi::FileSystemURL::CreateForTest( | 92 return fileapi::FileSystemURL::CreateForTest( |
92 GURL(kOrigin), kType, MakeFilePath(file_name)); | 93 GURL(kOrigin), kType, MakeFilePath(file_name)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 *max_written_offsets, | 144 *max_written_offsets, |
144 base::Bind(&GotReservedQuota, | 145 base::Bind(&GotReservedQuota, |
145 reserved_quota, | 146 reserved_quota, |
146 max_written_offsets)); | 147 max_written_offsets)); |
147 base::RunLoop().RunUntilIdle(); | 148 base::RunLoop().RunUntilIdle(); |
148 } | 149 } |
149 | 150 |
150 // Tests that: | 151 // Tests that: |
151 // 1) We can reserve quota with no files open. | 152 // 1) We can reserve quota with no files open. |
152 // 2) Open a file, grow it, close it, and reserve quota with correct sizes. | 153 // 2) Open a file, grow it, close it, and reserve quota with correct sizes. |
153 TEST_F(QuotaReservationTest, DISABLED_ReserveQuota) { | 154 TEST_F(QuotaReservationTest, ReserveQuota) { |
154 GURL origin(kOrigin); | 155 GURL origin(kOrigin); |
155 FileSystemType type = kType; | 156 FileSystemType type = kType; |
156 | 157 |
157 scoped_refptr<fileapi::QuotaReservation> reservation( | 158 scoped_refptr<fileapi::QuotaReservation> reservation( |
158 reservation_manager()->CreateReservation(origin, type)); | 159 reservation_manager()->CreateReservation(origin, type)); |
159 scoped_refptr<QuotaReservation> test = | 160 scoped_refptr<QuotaReservation> test = |
160 CreateQuotaReservation(reservation, origin, type); | 161 CreateQuotaReservation(reservation, origin, type); |
161 | 162 |
162 // Reserve quota with no files open. | 163 // Reserve quota with no files open. |
163 int64 amount = 100; | 164 int64 amount = 100; |
(...skipping 20 matching lines...) Expand all Loading... |
184 SetFileSize(file1_name, new_file_size); | 185 SetFileSize(file1_name, new_file_size); |
185 | 186 |
186 EXPECT_EQ(amount, reservation->remaining_quota()); | 187 EXPECT_EQ(amount, reservation->remaining_quota()); |
187 test->CloseFile(kFile1ID, new_file_size); | 188 test->CloseFile(kFile1ID, new_file_size); |
188 EXPECT_EQ(amount - (new_file_size - file_size), | 189 EXPECT_EQ(amount - (new_file_size - file_size), |
189 reservation->remaining_quota()); | 190 reservation->remaining_quota()); |
190 } | 191 } |
191 | 192 |
192 // Tests that: | 193 // Tests that: |
193 // 1) We can open and close multiple files. | 194 // 1) We can open and close multiple files. |
194 TEST_F(QuotaReservationTest, DISABLED_MultipleFiles) { | 195 TEST_F(QuotaReservationTest, MultipleFiles) { |
195 GURL origin(kOrigin); | 196 GURL origin(kOrigin); |
196 FileSystemType type = kType; | 197 FileSystemType type = kType; |
197 | 198 |
198 scoped_refptr<fileapi::QuotaReservation> reservation( | 199 scoped_refptr<fileapi::QuotaReservation> reservation( |
199 reservation_manager()->CreateReservation(origin, type)); | 200 reservation_manager()->CreateReservation(origin, type)); |
200 scoped_refptr<QuotaReservation> test = | 201 scoped_refptr<QuotaReservation> test = |
201 CreateQuotaReservation(reservation, origin, type); | 202 CreateQuotaReservation(reservation, origin, type); |
202 | 203 |
203 // Open some files of different sizes. | 204 // Open some files of different sizes. |
204 int64 file1_size = 10; | 205 int64 file1_size = 10; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 EXPECT_EQ(amount, reserved_quota); | 240 EXPECT_EQ(amount, reserved_quota); |
240 EXPECT_EQ(2U, max_written_offsets.size()); | 241 EXPECT_EQ(2U, max_written_offsets.size()); |
241 EXPECT_EQ(file1_size, max_written_offsets[kFile1ID]); | 242 EXPECT_EQ(file1_size, max_written_offsets[kFile1ID]); |
242 EXPECT_EQ(file3_size, max_written_offsets[kFile3ID]); | 243 EXPECT_EQ(file3_size, max_written_offsets[kFile3ID]); |
243 | 244 |
244 test->CloseFile(kFile1ID, file1_size); | 245 test->CloseFile(kFile1ID, file1_size); |
245 test->CloseFile(kFile3ID, file3_size); | 246 test->CloseFile(kFile3ID, file3_size); |
246 } | 247 } |
247 | 248 |
248 } // namespace content | 249 } // namespace content |
OLD | NEW |