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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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 | 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/file.h"
10 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/browser/fileapi/quota/open_file_handle.h" 15 #include "webkit/browser/fileapi/quota/open_file_handle.h"
15 #include "webkit/browser/fileapi/quota/quota_reservation.h" 16 #include "webkit/browser/fileapi/quota/quota_reservation.h"
16 17
17 namespace fileapi { 18 namespace fileapi {
18 19
19 namespace { 20 namespace {
20 21
21 const char kOrigin[] = "http://example.com"; 22 const char kOrigin[] = "http://example.com";
22 const FileSystemType kType = kFileSystemTypeTemporary; 23 const FileSystemType kType = kFileSystemTypeTemporary;
23 const int64 kInitialFileSize = 1; 24 const int64 kInitialFileSize = 1;
24 25
25 typedef QuotaReservationManager::ReserveQuotaCallback ReserveQuotaCallback; 26 typedef QuotaReservationManager::ReserveQuotaCallback ReserveQuotaCallback;
26 27
27 int64 GetFileSize(const base::FilePath& path) { 28 int64 GetFileSize(const base::FilePath& path) {
28 int64 size = 0; 29 int64 size = 0;
29 base::GetFileSize(path, &size); 30 base::GetFileSize(path, &size);
30 return size; 31 return size;
31 } 32 }
32 33
33 void SetFileSize(const base::FilePath& path, int64 size) { 34 void SetFileSize(const base::FilePath& path, int64 size) {
34 bool created = false; 35 base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE);
35 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 36 ASSERT_TRUE(file.IsValid());
36 base::PlatformFile file = CreatePlatformFile( 37 ASSERT_TRUE(file.SetLength(size));
37 path,
38 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
39 &created, &error);
40 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
41 ASSERT_TRUE(base::TruncatePlatformFile(file, size));
42 ASSERT_TRUE(base::ClosePlatformFile(file));
43 } 38 }
44 39
45 class FakeBackend : public QuotaReservationManager::QuotaBackend { 40 class FakeBackend : public QuotaReservationManager::QuotaBackend {
46 public: 41 public:
47 FakeBackend() 42 FakeBackend()
48 : on_memory_usage_(kInitialFileSize), 43 : on_memory_usage_(kInitialFileSize),
49 on_disk_usage_(kInitialFileSize) {} 44 on_disk_usage_(kInitialFileSize) {}
50 virtual ~FakeBackend() {} 45 virtual ~FakeBackend() {}
51 46
52 virtual void ReserveQuota(const GURL& origin, 47 virtual void ReserveQuota(const GURL& origin,
53 FileSystemType type, 48 FileSystemType type,
54 int64 delta, 49 int64 delta,
55 const ReserveQuotaCallback& callback) OVERRIDE { 50 const ReserveQuotaCallback& callback) OVERRIDE {
56 EXPECT_EQ(GURL(kOrigin), origin); 51 EXPECT_EQ(GURL(kOrigin), origin);
57 EXPECT_EQ(kType, type); 52 EXPECT_EQ(kType, type);
58 on_memory_usage_ += delta; 53 on_memory_usage_ += delta;
59 base::MessageLoopProxy::current()->PostTask( 54 base::MessageLoopProxy::current()->PostTask(
60 FROM_HERE, 55 FROM_HERE,
61 base::Bind(base::IgnoreResult(callback), base::PLATFORM_FILE_OK)); 56 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK));
62 } 57 }
63 58
64 virtual void ReleaseReservedQuota(const GURL& origin, 59 virtual void ReleaseReservedQuota(const GURL& origin,
65 FileSystemType type, 60 FileSystemType type,
66 int64 size) OVERRIDE { 61 int64 size) OVERRIDE {
67 EXPECT_LE(0, size); 62 EXPECT_LE(0, size);
68 EXPECT_EQ(GURL(kOrigin), origin); 63 EXPECT_EQ(GURL(kOrigin), origin);
69 EXPECT_EQ(kType, type); 64 EXPECT_EQ(kType, type);
70 on_memory_usage_ -= size; 65 on_memory_usage_ -= size;
71 } 66 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 148 }
154 149
155 private: 150 private:
156 scoped_ptr<OpenFileHandle> handle_; 151 scoped_ptr<OpenFileHandle> handle_;
157 base::FilePath path_; 152 base::FilePath path_;
158 int64 max_written_offset_; 153 int64 max_written_offset_;
159 int64 append_mode_write_amount_; 154 int64 append_mode_write_amount_;
160 bool dirty_; 155 bool dirty_;
161 }; 156 };
162 157
163 void ExpectSuccess(bool* done, base::PlatformFileError error) { 158 void ExpectSuccess(bool* done, base::File::Error error) {
164 EXPECT_FALSE(*done); 159 EXPECT_FALSE(*done);
165 *done = true; 160 *done = true;
166 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 161 EXPECT_EQ(base::File::FILE_OK, error);
167 } 162 }
168 163
169 void RefreshReservation(QuotaReservation* reservation, int64 size) { 164 void RefreshReservation(QuotaReservation* reservation, int64 size) {
170 DCHECK(reservation); 165 DCHECK(reservation);
171 166
172 bool done = false; 167 bool done = false;
173 reservation->RefreshReservation(size, base::Bind(&ExpectSuccess, &done)); 168 reservation->RefreshReservation(size, base::Bind(&ExpectSuccess, &done));
174 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
175 EXPECT_TRUE(done); 170 EXPECT_TRUE(done);
176 } 171 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 353
359 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path())); 354 EXPECT_EQ(kInitialFileSize + 10, GetFileSize(file_path()));
360 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage()); 355 EXPECT_EQ(kInitialFileSize + 15 + 20, fake_backend()->on_memory_usage());
361 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage()); 356 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_disk_usage());
362 357
363 reservation2 = NULL; 358 reservation2 = NULL;
364 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage()); 359 EXPECT_EQ(kInitialFileSize + 10, fake_backend()->on_memory_usage());
365 } 360 }
366 361
367 } // namespace fileapi 362 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/quota/quota_reservation_manager.h ('k') | webkit/browser/fileapi/recursive_operation_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698