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

Side by Side Diff: webkit/browser/fileapi/quota/quota_backend_impl_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_backend_impl.h" 5 #include "webkit/browser/fileapi/quota/quota_backend_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/browser/fileapi/file_system_usage_cache.h" 12 #include "webkit/browser/fileapi/file_system_usage_cache.h"
13 #include "webkit/browser/fileapi/obfuscated_file_util.h" 13 #include "webkit/browser/fileapi/obfuscated_file_util.h"
14 #include "webkit/browser/quota/quota_manager_proxy.h" 14 #include "webkit/browser/quota/quota_manager_proxy.h"
15 15
16 namespace fileapi { 16 namespace fileapi {
17 17
18 namespace { 18 namespace {
19 19
20 const char kOrigin[] = "http://example.com"; 20 const char kOrigin[] = "http://example.com";
21 21
22 bool DidReserveQuota(bool accepted, 22 bool DidReserveQuota(bool accepted,
23 base::PlatformFileError* error_out, 23 base::File::Error* error_out,
24 base::PlatformFileError error) { 24 base::File::Error error) {
25 DCHECK(error_out); 25 DCHECK(error_out);
26 *error_out = error; 26 *error_out = error;
27 return accepted; 27 return accepted;
28 } 28 }
29 29
30 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { 30 class MockQuotaManagerProxy : public quota::QuotaManagerProxy {
31 public: 31 public:
32 MockQuotaManagerProxy() 32 MockQuotaManagerProxy()
33 : QuotaManagerProxy(NULL, NULL), 33 : QuotaManagerProxy(NULL, NULL),
34 storage_modified_count_(0), 34 storage_modified_count_(0),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 message_loop_.RunUntilIdle(); 101 message_loop_.RunUntilIdle();
102 } 102 }
103 103
104 protected: 104 protected:
105 void InitializeForOriginAndType(const GURL& origin, FileSystemType type) { 105 void InitializeForOriginAndType(const GURL& origin, FileSystemType type) {
106 ASSERT_TRUE(file_util_->InitOriginDatabase(origin, true /* create */)); 106 ASSERT_TRUE(file_util_->InitOriginDatabase(origin, true /* create */));
107 ASSERT_TRUE(file_util_->origin_database_ != NULL); 107 ASSERT_TRUE(file_util_->origin_database_ != NULL);
108 108
109 std::string type_string = 109 std::string type_string =
110 SandboxFileSystemBackendDelegate::GetTypeString(type); 110 SandboxFileSystemBackendDelegate::GetTypeString(type);
111 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 111 base::File::Error error = base::File::FILE_ERROR_FAILED;
112 base::FilePath path = file_util_->GetDirectoryForOriginAndType( 112 base::FilePath path = file_util_->GetDirectoryForOriginAndType(
113 origin, type_string, true /* create */, &error); 113 origin, type_string, true /* create */, &error);
114 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 114 ASSERT_EQ(base::File::FILE_OK, error);
115 115
116 ASSERT_TRUE(file_system_usage_cache_.UpdateUsage( 116 ASSERT_TRUE(file_system_usage_cache_.UpdateUsage(
117 GetUsageCachePath(origin, type), 0)); 117 GetUsageCachePath(origin, type), 0));
118 } 118 }
119 119
120 base::SequencedTaskRunner* file_task_runner() { 120 base::SequencedTaskRunner* file_task_runner() {
121 return base::MessageLoopProxy::current().get(); 121 return base::MessageLoopProxy::current().get();
122 } 122 }
123 123
124 base::FilePath GetUsageCachePath(const GURL& origin, FileSystemType type) { 124 base::FilePath GetUsageCachePath(const GURL& origin, FileSystemType type) {
125 base::FilePath path; 125 base::FilePath path;
126 base::PlatformFileError error = 126 base::File::Error error =
127 backend_->GetUsageCachePath(origin, type, &path); 127 backend_->GetUsageCachePath(origin, type, &path);
128 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 128 EXPECT_EQ(base::File::FILE_OK, error);
129 EXPECT_FALSE(path.empty()); 129 EXPECT_FALSE(path.empty());
130 return path; 130 return path;
131 } 131 }
132 132
133 base::MessageLoop message_loop_; 133 base::MessageLoop message_loop_;
134 base::ScopedTempDir data_dir_; 134 base::ScopedTempDir data_dir_;
135 scoped_ptr<ObfuscatedFileUtil> file_util_; 135 scoped_ptr<ObfuscatedFileUtil> file_util_;
136 FileSystemUsageCache file_system_usage_cache_; 136 FileSystemUsageCache file_system_usage_cache_;
137 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 137 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
138 scoped_ptr<QuotaBackendImpl> backend_; 138 scoped_ptr<QuotaBackendImpl> backend_;
139 139
140 private: 140 private:
141 DISALLOW_COPY_AND_ASSIGN(QuotaBackendImplTest); 141 DISALLOW_COPY_AND_ASSIGN(QuotaBackendImplTest);
142 }; 142 };
143 143
144 TEST_F(QuotaBackendImplTest, ReserveQuota_Basic) { 144 TEST_F(QuotaBackendImplTest, ReserveQuota_Basic) {
145 FileSystemType type = fileapi::kFileSystemTypeTemporary; 145 FileSystemType type = fileapi::kFileSystemTypeTemporary;
146 InitializeForOriginAndType(GURL(kOrigin), type); 146 InitializeForOriginAndType(GURL(kOrigin), type);
147 quota_manager_proxy_->set_quota(10000); 147 quota_manager_proxy_->set_quota(10000);
148 148
149 const int64 kDelta1 = 1000; 149 const int64 kDelta1 = 1000;
150 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 150 base::File::Error error = base::File::FILE_ERROR_FAILED;
151 backend_->ReserveQuota(GURL(kOrigin), type, kDelta1, 151 backend_->ReserveQuota(GURL(kOrigin), type, kDelta1,
152 base::Bind(&DidReserveQuota, true, &error)); 152 base::Bind(&DidReserveQuota, true, &error));
153 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 153 EXPECT_EQ(base::File::FILE_OK, error);
154 EXPECT_EQ(kDelta1, quota_manager_proxy_->usage()); 154 EXPECT_EQ(kDelta1, quota_manager_proxy_->usage());
155 155
156 const int64 kDelta2 = -300; 156 const int64 kDelta2 = -300;
157 error = base::PLATFORM_FILE_ERROR_FAILED; 157 error = base::File::FILE_ERROR_FAILED;
158 backend_->ReserveQuota(GURL(kOrigin), type, kDelta2, 158 backend_->ReserveQuota(GURL(kOrigin), type, kDelta2,
159 base::Bind(&DidReserveQuota, true, &error)); 159 base::Bind(&DidReserveQuota, true, &error));
160 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 160 EXPECT_EQ(base::File::FILE_OK, error);
161 EXPECT_EQ(kDelta1 + kDelta2, quota_manager_proxy_->usage()); 161 EXPECT_EQ(kDelta1 + kDelta2, quota_manager_proxy_->usage());
162 162
163 EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count()); 163 EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count());
164 } 164 }
165 165
166 TEST_F(QuotaBackendImplTest, ReserveQuota_NoSpace) { 166 TEST_F(QuotaBackendImplTest, ReserveQuota_NoSpace) {
167 FileSystemType type = fileapi::kFileSystemTypeTemporary; 167 FileSystemType type = fileapi::kFileSystemTypeTemporary;
168 InitializeForOriginAndType(GURL(kOrigin), type); 168 InitializeForOriginAndType(GURL(kOrigin), type);
169 quota_manager_proxy_->set_quota(100); 169 quota_manager_proxy_->set_quota(100);
170 170
171 const int64 kDelta = 1000; 171 const int64 kDelta = 1000;
172 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 172 base::File::Error error = base::File::FILE_ERROR_FAILED;
173 backend_->ReserveQuota(GURL(kOrigin), type, kDelta, 173 backend_->ReserveQuota(GURL(kOrigin), type, kDelta,
174 base::Bind(&DidReserveQuota, true, &error)); 174 base::Bind(&DidReserveQuota, true, &error));
175 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, error); 175 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, error);
176 EXPECT_EQ(0, quota_manager_proxy_->usage()); 176 EXPECT_EQ(0, quota_manager_proxy_->usage());
177 177
178 EXPECT_EQ(0, quota_manager_proxy_->storage_modified_count()); 178 EXPECT_EQ(0, quota_manager_proxy_->storage_modified_count());
179 } 179 }
180 180
181 TEST_F(QuotaBackendImplTest, ReserveQuota_Revert) { 181 TEST_F(QuotaBackendImplTest, ReserveQuota_Revert) {
182 FileSystemType type = fileapi::kFileSystemTypeTemporary; 182 FileSystemType type = fileapi::kFileSystemTypeTemporary;
183 InitializeForOriginAndType(GURL(kOrigin), type); 183 InitializeForOriginAndType(GURL(kOrigin), type);
184 quota_manager_proxy_->set_quota(10000); 184 quota_manager_proxy_->set_quota(10000);
185 185
186 const int64 kDelta = 1000; 186 const int64 kDelta = 1000;
187 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 187 base::File::Error error = base::File::FILE_ERROR_FAILED;
188 backend_->ReserveQuota(GURL(kOrigin), type, kDelta, 188 backend_->ReserveQuota(GURL(kOrigin), type, kDelta,
189 base::Bind(&DidReserveQuota, false, &error)); 189 base::Bind(&DidReserveQuota, false, &error));
190 EXPECT_EQ(base::PLATFORM_FILE_OK, error); 190 EXPECT_EQ(base::File::FILE_OK, error);
191 EXPECT_EQ(0, quota_manager_proxy_->usage()); 191 EXPECT_EQ(0, quota_manager_proxy_->usage());
192 192
193 EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count()); 193 EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count());
194 } 194 }
195 195
196 TEST_F(QuotaBackendImplTest, ReleaseReservedQuota) { 196 TEST_F(QuotaBackendImplTest, ReleaseReservedQuota) {
197 FileSystemType type = fileapi::kFileSystemTypeTemporary; 197 FileSystemType type = fileapi::kFileSystemTypeTemporary;
198 InitializeForOriginAndType(GURL(kOrigin), type); 198 InitializeForOriginAndType(GURL(kOrigin), type);
199 const int64 kInitialUsage = 2000; 199 const int64 kInitialUsage = 2000;
200 quota_manager_proxy_->set_usage(kInitialUsage); 200 quota_manager_proxy_->set_usage(kInitialUsage);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 uint32 dirty = 0; 239 uint32 dirty = 0;
240 ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty)); 240 ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty));
241 EXPECT_EQ(1u, dirty); 241 EXPECT_EQ(1u, dirty);
242 242
243 backend_->DecrementDirtyCount(GURL(kOrigin), type); 243 backend_->DecrementDirtyCount(GURL(kOrigin), type);
244 ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty)); 244 ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty));
245 EXPECT_EQ(0u, dirty); 245 EXPECT_EQ(0u, dirty);
246 } 246 }
247 247
248 } // namespace fileapi 248 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/quota/quota_backend_impl.cc ('k') | webkit/browser/fileapi/quota/quota_reservation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698