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

Side by Side Diff: content/browser/renderer_host/pepper/quota_reservation_unittest.cc

Issue 345673002: Fully qualify all references to fileapi::FileSystemType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix FileSystemType instances I missed Created 6 years, 6 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 "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/file.h" 10 #include "base/files/file.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/browser/fileapi/quota/quota_reservation.h" 15 #include "webkit/browser/fileapi/quota/quota_reservation.h"
16 16
17 using fileapi::FileSystemType;
18 using fileapi::QuotaReservationManager; 17 using fileapi::QuotaReservationManager;
19 18
20 namespace content { 19 namespace content {
21 20
22 namespace { 21 namespace {
23 22
24 const char kOrigin[] = "http://example.com"; 23 const char kOrigin[] = "http://example.com";
25 const FileSystemType kType = fileapi::kFileSystemTypeTemporary; 24 const fileapi::FileSystemType kType = fileapi::kFileSystemTypeTemporary;
26 25
27 const base::FilePath::StringType file1_name = FILE_PATH_LITERAL("file1"); 26 const base::FilePath::StringType file1_name = FILE_PATH_LITERAL("file1");
28 const base::FilePath::StringType file2_name = FILE_PATH_LITERAL("file2"); 27 const base::FilePath::StringType file2_name = FILE_PATH_LITERAL("file2");
29 const base::FilePath::StringType file3_name = FILE_PATH_LITERAL("file3"); 28 const base::FilePath::StringType file3_name = FILE_PATH_LITERAL("file3");
30 const int kFile1ID = 1; 29 const int kFile1ID = 1;
31 const int kFile2ID = 2; 30 const int kFile2ID = 2;
32 const int kFile3ID = 3; 31 const int kFile3ID = 3;
33 32
34 class FakeBackend : public QuotaReservationManager::QuotaBackend { 33 class FakeBackend : public QuotaReservationManager::QuotaBackend {
35 public: 34 public:
36 FakeBackend() {} 35 FakeBackend() {}
37 virtual ~FakeBackend() {} 36 virtual ~FakeBackend() {}
38 37
39 virtual void ReserveQuota( 38 virtual void ReserveQuota(
40 const GURL& origin, 39 const GURL& origin,
41 FileSystemType type, 40 fileapi::FileSystemType type,
42 int64 delta, 41 int64 delta,
43 const QuotaReservationManager::ReserveQuotaCallback& callback) OVERRIDE { 42 const QuotaReservationManager::ReserveQuotaCallback& callback) OVERRIDE {
44 base::MessageLoopProxy::current()->PostTask( 43 base::MessageLoopProxy::current()->PostTask(
45 FROM_HERE, 44 FROM_HERE,
46 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta)); 45 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta));
47 } 46 }
48 47
49 virtual void ReleaseReservedQuota(const GURL& origin, 48 virtual void ReleaseReservedQuota(const GURL& origin,
50 FileSystemType type, 49 fileapi::FileSystemType type,
51 int64 size) OVERRIDE {} 50 int64 size) OVERRIDE {}
52 51
53 virtual void CommitQuotaUsage(const GURL& origin, 52 virtual void CommitQuotaUsage(const GURL& origin,
54 FileSystemType type, 53 fileapi::FileSystemType type,
55 int64 delta) OVERRIDE {} 54 int64 delta) OVERRIDE {}
56 55
57 virtual void IncrementDirtyCount(const GURL& origin, 56 virtual void IncrementDirtyCount(const GURL& origin,
58 FileSystemType type) OVERRIDE {} 57 fileapi::FileSystemType type) OVERRIDE {}
59 virtual void DecrementDirtyCount(const GURL& origin, 58 virtual void DecrementDirtyCount(const GURL& origin,
60 FileSystemType type) OVERRIDE {} 59 fileapi::FileSystemType type) OVERRIDE {}
61 60
62 private: 61 private:
63 DISALLOW_COPY_AND_ASSIGN(FakeBackend); 62 DISALLOW_COPY_AND_ASSIGN(FakeBackend);
64 }; 63 };
65 64
66 } // namespace 65 } // namespace
67 66
68 class QuotaReservationTest : public testing::Test { 67 class QuotaReservationTest : public testing::Test {
69 public: 68 public:
70 QuotaReservationTest() {} 69 QuotaReservationTest() {}
(...skipping 17 matching lines...) Expand all
88 87
89 fileapi::FileSystemURL MakeFileSystemURL( 88 fileapi::FileSystemURL MakeFileSystemURL(
90 const base::FilePath::StringType& file_name) { 89 const base::FilePath::StringType& file_name) {
91 return fileapi::FileSystemURL::CreateForTest( 90 return fileapi::FileSystemURL::CreateForTest(
92 GURL(kOrigin), kType, MakeFilePath(file_name)); 91 GURL(kOrigin), kType, MakeFilePath(file_name));
93 } 92 }
94 93
95 scoped_refptr<QuotaReservation> CreateQuotaReservation( 94 scoped_refptr<QuotaReservation> CreateQuotaReservation(
96 scoped_refptr<fileapi::QuotaReservation> reservation, 95 scoped_refptr<fileapi::QuotaReservation> reservation,
97 const GURL& origin, 96 const GURL& origin,
98 FileSystemType type) { 97 fileapi::FileSystemType type) {
99 // Sets reservation_ as a side effect. 98 // Sets reservation_ as a side effect.
100 return scoped_refptr<QuotaReservation>( 99 return scoped_refptr<QuotaReservation>(
101 new QuotaReservation(reservation, origin, type)); 100 new QuotaReservation(reservation, origin, type));
102 } 101 }
103 102
104 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) { 103 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) {
105 base::File file(MakeFilePath(file_name), 104 base::File file(MakeFilePath(file_name),
106 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); 105 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE);
107 ASSERT_TRUE(file.IsValid()); 106 ASSERT_TRUE(file.IsValid());
108 ASSERT_TRUE(file.SetLength(size)); 107 ASSERT_TRUE(file.SetLength(size));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 *file_growths, 141 *file_growths,
143 base::Bind(&GotReservedQuota, reserved_quota, file_growths)); 142 base::Bind(&GotReservedQuota, reserved_quota, file_growths));
144 base::RunLoop().RunUntilIdle(); 143 base::RunLoop().RunUntilIdle();
145 } 144 }
146 145
147 // Tests that: 146 // Tests that:
148 // 1) We can reserve quota with no files open. 147 // 1) We can reserve quota with no files open.
149 // 2) Open a file, grow it, close it, and reserve quota with correct sizes. 148 // 2) Open a file, grow it, close it, and reserve quota with correct sizes.
150 TEST_F(QuotaReservationTest, ReserveQuota) { 149 TEST_F(QuotaReservationTest, ReserveQuota) {
151 GURL origin(kOrigin); 150 GURL origin(kOrigin);
152 FileSystemType type = kType; 151 fileapi::FileSystemType type = kType;
153 152
154 scoped_refptr<fileapi::QuotaReservation> reservation( 153 scoped_refptr<fileapi::QuotaReservation> reservation(
155 reservation_manager()->CreateReservation(origin, type)); 154 reservation_manager()->CreateReservation(origin, type));
156 scoped_refptr<QuotaReservation> test = 155 scoped_refptr<QuotaReservation> test =
157 CreateQuotaReservation(reservation, origin, type); 156 CreateQuotaReservation(reservation, origin, type);
158 157
159 // Reserve quota with no files open. 158 // Reserve quota with no files open.
160 int64 amount = 100; 159 int64 amount = 100;
161 int64 reserved_quota; 160 int64 reserved_quota;
162 ppapi::FileGrowthMap file_growths; 161 ppapi::FileGrowthMap file_growths;
(...skipping 20 matching lines...) Expand all
183 EXPECT_EQ(amount, reservation->remaining_quota()); 182 EXPECT_EQ(amount, reservation->remaining_quota());
184 test->CloseFile(kFile1ID, ppapi::FileGrowth(new_file_size, 0)); 183 test->CloseFile(kFile1ID, ppapi::FileGrowth(new_file_size, 0));
185 EXPECT_EQ(amount - (new_file_size - file_size), 184 EXPECT_EQ(amount - (new_file_size - file_size),
186 reservation->remaining_quota()); 185 reservation->remaining_quota());
187 } 186 }
188 187
189 // Tests that: 188 // Tests that:
190 // 1) We can open and close multiple files. 189 // 1) We can open and close multiple files.
191 TEST_F(QuotaReservationTest, MultipleFiles) { 190 TEST_F(QuotaReservationTest, MultipleFiles) {
192 GURL origin(kOrigin); 191 GURL origin(kOrigin);
193 FileSystemType type = kType; 192 fileapi::FileSystemType type = kType;
194 193
195 scoped_refptr<fileapi::QuotaReservation> reservation( 194 scoped_refptr<fileapi::QuotaReservation> reservation(
196 reservation_manager()->CreateReservation(origin, type)); 195 reservation_manager()->CreateReservation(origin, type));
197 scoped_refptr<QuotaReservation> test = 196 scoped_refptr<QuotaReservation> test =
198 CreateQuotaReservation(reservation, origin, type); 197 CreateQuotaReservation(reservation, origin, type);
199 198
200 // Open some files of different sizes. 199 // Open some files of different sizes.
201 int64 file1_size = 10; 200 int64 file1_size = 10;
202 SetFileSize(file1_name, file1_size); 201 SetFileSize(file1_name, file1_size);
203 int64 open_file1_size = 202 int64 open_file1_size =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 EXPECT_EQ(amount, reserved_quota); 235 EXPECT_EQ(amount, reserved_quota);
237 EXPECT_EQ(2U, file_growths.size()); 236 EXPECT_EQ(2U, file_growths.size());
238 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset); 237 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset);
239 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset); 238 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset);
240 239
241 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0)); 240 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0));
242 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0)); 241 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0));
243 } 242 }
244 243
245 } // namespace content 244 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/quota/quota_reservation_manager_unittest.cc ('k') | content/common/fileapi/file_system_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698