OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/sys_string_conversions.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "base/utf_string_conversions.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 14 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
16 #include "webkit/fileapi/file_system_context.h" | 15 #include "webkit/fileapi/file_system_context.h" |
17 #include "webkit/fileapi/file_system_file_util.h" | 16 #include "webkit/fileapi/file_system_file_util.h" |
18 #include "webkit/fileapi/file_system_mount_point_provider.h" | 17 #include "webkit/fileapi/file_system_mount_point_provider.h" |
19 #include "webkit/fileapi/file_system_operation.h" | 18 #include "webkit/fileapi/file_system_operation.h" |
19 #include "webkit/fileapi/file_system_quota_util.h" | |
20 #include "webkit/fileapi/file_system_test_helper.h" | 20 #include "webkit/fileapi/file_system_test_helper.h" |
21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
22 #include "webkit/fileapi/local_file_system_file_util.h" | 22 #include "webkit/fileapi/local_file_system_file_util.h" |
23 #include "webkit/fileapi/quota_file_util.h" | 23 #include "webkit/fileapi/quota_file_util.h" |
24 #include "webkit/quota/quota_manager.h" | 24 #include "webkit/quota/quota_manager.h" |
25 | 25 |
26 using quota::QuotaClient; | |
26 using quota::QuotaManager; | 27 using quota::QuotaManager; |
28 using quota::QuotaManagerProxy; | |
29 using quota::StorageType; | |
27 | 30 |
28 namespace fileapi { | 31 namespace fileapi { |
29 | 32 |
33 namespace { | |
34 | |
30 const int kFileOperationStatusNotSet = 1; | 35 const int kFileOperationStatusNotSet = 1; |
31 | 36 |
32 namespace { | |
33 | |
34 class MockQuotaManager : public QuotaManager { | 37 class MockQuotaManager : public QuotaManager { |
35 public: | 38 public: |
36 MockQuotaManager(const FilePath& base_dir) | 39 explicit MockQuotaManager(const FilePath& base_dir, |
ericu
2011/05/24 03:03:56
The explicit shouldn't be needed on a multiple-arg
kinuko
2011/05/24 03:09:32
Oops, yup, I was warned by lint before making this
| |
37 : QuotaManager(false /* is_incognito */, base_dir, | 40 const GURL& origin, |
38 base::MessageLoopProxy::CreateForCurrentThread(), | 41 StorageType type) |
39 base::MessageLoopProxy::CreateForCurrentThread()), | 42 : QuotaManager(false /* is_incognito */, base_dir, |
40 usage_(0), | 43 base::MessageLoopProxy::CreateForCurrentThread(), |
41 quota_(QuotaFileUtil::kNoLimit) {} | 44 base::MessageLoopProxy::CreateForCurrentThread()), |
45 origin_(origin), | |
46 type_(type), | |
47 usage_(0), | |
48 quota_(QuotaFileUtil::kNoLimit), | |
49 accessed_(0) {} | |
42 | 50 |
43 virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type, | 51 virtual void GetUsageAndQuota( |
44 GetUsageAndQuotaCallback* callback) { | 52 const GURL& origin, quota::StorageType type, |
53 GetUsageAndQuotaCallback* callback) { | |
54 EXPECT_EQ(origin_, origin); | |
55 EXPECT_EQ(type_, type); | |
45 callback->Run(quota::kQuotaStatusOk, usage_, quota_); | 56 callback->Run(quota::kQuotaStatusOk, usage_, quota_); |
46 delete callback; | 57 delete callback; |
47 } | 58 } |
48 | 59 |
49 void set_usage(int64 usage) { usage_ = usage; } | 60 private: |
50 void set_quota(int64 quota) { quota_ = quota; } | 61 friend class MockQuotaManagerProxy; |
62 void SetQuota(const GURL& origin, StorageType type, int64 quota) { | |
63 EXPECT_EQ(origin_, origin); | |
64 EXPECT_EQ(type_, type); | |
65 quota_ = quota; | |
66 } | |
67 | |
68 void RecordStorageAccessed(const GURL& origin, StorageType type) { | |
69 EXPECT_EQ(origin_, origin); | |
70 EXPECT_EQ(type_, type); | |
71 ++accessed_; | |
72 } | |
73 | |
74 void UpdateUsage(const GURL& origin, StorageType type, int64 delta) { | |
75 EXPECT_EQ(origin_, origin); | |
76 EXPECT_EQ(type_, type); | |
77 usage_ += delta; | |
78 } | |
79 | |
80 const GURL& origin_; | |
81 const StorageType type_; | |
82 int64 usage_; | |
83 int64 quota_; | |
84 int accessed_; | |
85 }; | |
86 | |
87 class MockQuotaManagerProxy : public QuotaManagerProxy { | |
88 public: | |
89 explicit MockQuotaManagerProxy(QuotaManager* quota_manager) | |
90 : QuotaManagerProxy(quota_manager, | |
91 base::MessageLoopProxy::CreateForCurrentThread()) {} | |
92 | |
93 // We don't mock them. | |
94 virtual void RegisterClient(QuotaClient* client) OVERRIDE {} | |
oshima
2011/05/25 20:43:38
Looks like this has to call OnQuotaManagerDestorye
| |
95 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} | |
96 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} | |
97 | |
98 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, | |
99 const GURL& origin, | |
100 StorageType type) OVERRIDE { | |
101 mock_manager()->RecordStorageAccessed(origin, type); | |
102 } | |
103 | |
104 virtual void NotifyStorageModified(QuotaClient::ID client_id, | |
105 const GURL& origin, | |
106 StorageType type, | |
107 int64 delta) OVERRIDE { | |
108 mock_manager()->UpdateUsage(origin, type, delta); | |
109 } | |
110 | |
111 int storage_accessed_count() const { | |
112 return mock_manager()->accessed_; | |
113 } | |
114 | |
115 void SetQuota(const GURL& origin, StorageType type, int64 quota) { | |
116 mock_manager()->SetQuota(origin, type, quota); | |
117 } | |
51 | 118 |
52 private: | 119 private: |
53 int64 usage_; | 120 MockQuotaManager* mock_manager() const { |
54 int64 quota_; | 121 return static_cast<MockQuotaManager*>(quota_manager()); |
122 } | |
55 }; | 123 }; |
56 | 124 |
57 FilePath UTF8ToFilePath(const std::string& str) { | 125 FilePath ASCIIToFilePath(const std::string& str) { |
58 FilePath::StringType result; | 126 return FilePath().AppendASCII(str); |
59 #if defined(OS_POSIX) | |
60 result = base::SysWideToNativeMB(UTF8ToWide(str)); | |
61 #elif defined(OS_WIN) | |
62 result = UTF8ToUTF16(str); | |
63 #endif | |
64 return FilePath(result); | |
65 } | 127 } |
66 | 128 |
67 } // namespace (anonymous) | 129 } // namespace (anonymous) |
68 | 130 |
69 // Test class for FileSystemOperation. Note that this just tests low-level | 131 // Test class for FileSystemOperation. Note that this just tests low-level |
70 // operations but doesn't test OpenFileSystem. | 132 // operations but doesn't test OpenFileSystem. |
71 class FileSystemOperationTest : public testing::Test { | 133 class FileSystemOperationTest : public testing::Test { |
72 public: | 134 public: |
73 FileSystemOperationTest() | 135 FileSystemOperationTest() |
74 : status_(kFileOperationStatusNotSet) { | 136 : status_(kFileOperationStatusNotSet) { |
75 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 137 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
76 } | 138 } |
77 | 139 |
78 FileSystemOperation* operation(); | 140 FileSystemOperation* operation(); |
79 | 141 |
80 void set_local_path(const FilePath& path) { local_path_ = path; } | |
81 const FilePath& local_path() const { return local_path_; } | |
82 void set_status(int status) { status_ = status; } | 142 void set_status(int status) { status_ = status; } |
83 int status() const { return status_; } | 143 int status() const { return status_; } |
84 void set_info(const base::PlatformFileInfo& info) { info_ = info; } | 144 void set_info(const base::PlatformFileInfo& info) { info_ = info; } |
85 const base::PlatformFileInfo& info() const { return info_; } | 145 const base::PlatformFileInfo& info() const { return info_; } |
86 void set_path(const FilePath& path) { path_ = path; } | 146 void set_path(const FilePath& path) { path_ = path; } |
87 const FilePath& path() const { return path_; } | 147 const FilePath& path() const { return path_; } |
88 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { | 148 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { |
89 entries_ = entries; | 149 entries_ = entries; |
90 } | 150 } |
91 const std::vector<base::FileUtilProxy::Entry>& entries() const { | 151 const std::vector<base::FileUtilProxy::Entry>& entries() const { |
92 return entries_; | 152 return entries_; |
93 } | 153 } |
94 | 154 |
95 virtual void SetUp(); | 155 virtual void SetUp(); |
96 virtual void TearDown(); | 156 virtual void TearDown(); |
97 | 157 |
98 protected: | 158 protected: |
99 // Common temp base for nondestructive uses. | 159 // Common temp base for nondestructive uses. |
100 ScopedTempDir base_; | 160 ScopedTempDir base_; |
101 | 161 |
102 MockQuotaManager* quota_manager() { | 162 MockQuotaManagerProxy* quota_manager_proxy() { |
103 return static_cast<MockQuotaManager*>(quota_manager_.get()); | 163 return static_cast<MockQuotaManagerProxy*>(quota_manager_proxy_.get()); |
104 } | 164 } |
105 | 165 |
106 GURL URLForPath(const FilePath& path) const { | 166 GURL URLForPath(const FilePath& path) const { |
107 return test_helper_.GetURLForPath(path); | 167 return test_helper_.GetURLForPath(path); |
108 } | 168 } |
109 | 169 |
110 FilePath PlatformPath(FilePath virtual_path) { | 170 FilePath PlatformPath(const FilePath& virtual_path) { |
111 return test_helper_.GetLocalPath(virtual_path); | 171 return test_helper_.GetLocalPath(virtual_path); |
112 } | 172 } |
113 | 173 |
114 bool VirtualFileExists(FilePath virtual_path) { | 174 bool VirtualFileExists(const FilePath& virtual_path) { |
115 return file_util::PathExists(PlatformPath(virtual_path)) && | 175 return file_util::PathExists(PlatformPath(virtual_path)) && |
116 !file_util::DirectoryExists(PlatformPath(virtual_path)); | 176 !file_util::DirectoryExists(PlatformPath(virtual_path)); |
117 } | 177 } |
118 | 178 |
119 bool VirtualDirectoryExists(FilePath virtual_path) { | 179 bool VirtualDirectoryExists(const FilePath& virtual_path) { |
120 return file_util::DirectoryExists(PlatformPath(virtual_path)); | 180 return file_util::DirectoryExists(PlatformPath(virtual_path)); |
121 } | 181 } |
122 | 182 |
123 FilePath CreateVirtualDirectory(const char* virtual_path_string) { | 183 FilePath CreateVirtualDirectory(const char* virtual_path_string) { |
124 FilePath virtual_path(UTF8ToFilePath(virtual_path_string)); | 184 FilePath virtual_path(ASCIIToFilePath(virtual_path_string)); |
125 file_util::CreateDirectory(PlatformPath(virtual_path)); | 185 file_util::CreateDirectory(PlatformPath(virtual_path)); |
126 return virtual_path; | 186 return virtual_path; |
127 } | 187 } |
128 | 188 |
129 FilePath CreateVirtualDirectoryInDir(const char* virtual_path_string, | 189 FilePath CreateVirtualDirectoryInDir(const char* virtual_path_string, |
130 const FilePath& virtual_dir_path) { | 190 const FilePath& virtual_dir_path) { |
131 FilePath virtual_path(virtual_dir_path.AppendASCII(virtual_path_string)); | 191 FilePath virtual_path(virtual_dir_path.AppendASCII(virtual_path_string)); |
132 file_util::CreateDirectory(PlatformPath(virtual_path)); | 192 file_util::CreateDirectory(PlatformPath(virtual_path)); |
133 return virtual_path; | 193 return virtual_path; |
134 } | 194 } |
(...skipping 22 matching lines...) Expand all Loading... | |
157 FilePath CreateVirtualTemporaryDir() { | 217 FilePath CreateVirtualTemporaryDir() { |
158 return CreateVirtualTemporaryDirInDir(FilePath()); | 218 return CreateVirtualTemporaryDirInDir(FilePath()); |
159 } | 219 } |
160 | 220 |
161 FileSystemTestOriginHelper test_helper_; | 221 FileSystemTestOriginHelper test_helper_; |
162 | 222 |
163 // For post-operation status. | 223 // For post-operation status. |
164 int status_; | 224 int status_; |
165 base::PlatformFileInfo info_; | 225 base::PlatformFileInfo info_; |
166 FilePath path_; | 226 FilePath path_; |
167 FilePath local_path_; | |
168 std::vector<base::FileUtilProxy::Entry> entries_; | 227 std::vector<base::FileUtilProxy::Entry> entries_; |
169 | 228 |
170 private: | 229 private: |
171 scoped_refptr<QuotaManager> quota_manager_; | 230 scoped_refptr<QuotaManager> quota_manager_; |
231 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | |
172 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 232 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
173 }; | 233 }; |
174 | 234 |
175 namespace { | 235 namespace { |
176 | 236 |
177 class MockDispatcher : public FileSystemCallbackDispatcher { | 237 class MockDispatcher : public FileSystemCallbackDispatcher { |
178 public: | 238 public: |
179 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } | 239 explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { } |
180 | 240 |
181 virtual void DidFail(base::PlatformFileError status) { | 241 virtual void DidFail(base::PlatformFileError status) { |
182 test_->set_status(status); | 242 test_->set_status(status); |
183 } | 243 } |
184 | 244 |
185 virtual void DidSucceed() { | 245 virtual void DidSucceed() { |
186 test_->set_status(base::PLATFORM_FILE_OK); | 246 test_->set_status(base::PLATFORM_FILE_OK); |
187 } | 247 } |
188 | 248 |
189 virtual void DidReadMetadata( | 249 virtual void DidReadMetadata( |
(...skipping 19 matching lines...) Expand all Loading... | |
209 } | 269 } |
210 | 270 |
211 private: | 271 private: |
212 FileSystemOperationTest* test_; | 272 FileSystemOperationTest* test_; |
213 }; | 273 }; |
214 | 274 |
215 } // namespace (anonymous) | 275 } // namespace (anonymous) |
216 | 276 |
217 void FileSystemOperationTest::SetUp() { | 277 void FileSystemOperationTest::SetUp() { |
218 FilePath base_dir = base_.path().AppendASCII("filesystem"); | 278 FilePath base_dir = base_.path().AppendASCII("filesystem"); |
219 quota_manager_ = new MockQuotaManager(base_dir); | 279 quota_manager_ = new MockQuotaManager( |
280 base_dir, test_helper_.origin(), test_helper_.storage_type()); | |
281 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); | |
220 test_helper_.SetUp(base_dir, | 282 test_helper_.SetUp(base_dir, |
221 false /* incognito */, | 283 false /* incognito */, |
222 false /* unlimited quota */, | 284 false /* unlimited quota */, |
223 quota_manager_->proxy(), | 285 quota_manager_proxy_.get(), |
224 LocalFileSystemFileUtil::GetInstance()); | 286 LocalFileSystemFileUtil::GetInstance()); |
225 } | 287 } |
226 | 288 |
227 void FileSystemOperationTest::TearDown() { | 289 void FileSystemOperationTest::TearDown() { |
228 quota_manager_ = NULL; | 290 quota_manager_ = NULL; |
291 quota_manager_proxy_ = NULL; | |
229 test_helper_.TearDown(); | 292 test_helper_.TearDown(); |
230 } | 293 } |
231 | 294 |
232 FileSystemOperation* FileSystemOperationTest::operation() { | 295 FileSystemOperation* FileSystemOperationTest::operation() { |
233 return test_helper_.NewOperation(new MockDispatcher(this)); | 296 return test_helper_.NewOperation(new MockDispatcher(this)); |
234 } | 297 } |
235 | 298 |
236 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 299 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
237 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); | 300 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); |
238 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 301 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 359 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { |
297 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 360 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
298 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 361 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
299 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 362 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
300 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 363 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
301 | 364 |
302 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); | 365 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); |
303 MessageLoop::current()->RunAllPending(); | 366 MessageLoop::current()->RunAllPending(); |
304 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 367 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
305 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 368 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
369 | |
370 // Move is considered 'write' access (for both side), and won't be counted | |
371 // as read access. | |
372 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | |
306 } | 373 } |
307 | 374 |
308 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 375 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { |
309 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 376 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
310 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 377 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
311 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 378 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
312 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 379 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
313 | 380 |
314 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); | 381 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); |
315 MessageLoop::current()->RunAllPending(); | 382 MessageLoop::current()->RunAllPending(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 } | 493 } |
427 | 494 |
428 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) { | 495 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) { |
429 base::PlatformFileInfo info; | 496 base::PlatformFileInfo info; |
430 | 497 |
431 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 498 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
432 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 499 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
433 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 500 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
434 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 501 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
435 | 502 |
436 quota_manager()->set_quota(11); | 503 quota_manager_proxy()->SetQuota(test_helper_.origin(), |
504 test_helper_.storage_type(), | |
505 11); | |
437 | 506 |
438 operation()->Truncate(URLForPath(src_file_path), 6); | 507 operation()->Truncate(URLForPath(src_file_path), 6); |
439 MessageLoop::current()->RunAllPending(); | 508 MessageLoop::current()->RunAllPending(); |
440 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 509 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
441 | 510 |
442 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); | 511 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); |
443 EXPECT_EQ(6, info.size); | 512 EXPECT_EQ(6, info.size); |
444 | 513 |
445 quota_manager()->set_usage(6); | |
446 | |
447 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 514 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); |
448 MessageLoop::current()->RunAllPending(); | 515 MessageLoop::current()->RunAllPending(); |
449 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 516 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
450 EXPECT_FALSE(VirtualFileExists(dest_file_path)); | 517 EXPECT_FALSE(VirtualFileExists(dest_file_path)); |
451 } | 518 } |
452 | 519 |
453 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { | 520 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { |
454 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 521 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
455 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 522 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
456 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 523 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
457 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); | 524 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); |
458 | 525 |
459 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 526 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); |
460 MessageLoop::current()->RunAllPending(); | 527 MessageLoop::current()->RunAllPending(); |
461 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 528 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
462 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 529 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
530 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
463 } | 531 } |
464 | 532 |
465 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 533 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { |
466 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 534 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
467 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); | 535 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); |
468 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 536 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
469 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 537 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
470 | 538 |
471 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); | 539 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); |
472 MessageLoop::current()->RunAllPending(); | 540 MessageLoop::current()->RunAllPending(); |
473 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 541 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
474 EXPECT_TRUE(VirtualFileExists(dest_file_path)); | 542 EXPECT_TRUE(VirtualFileExists(dest_file_path)); |
543 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
475 } | 544 } |
476 | 545 |
477 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 546 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
478 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 547 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
479 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 548 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
480 | 549 |
481 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 550 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); |
482 MessageLoop::current()->RunAllPending(); | 551 MessageLoop::current()->RunAllPending(); |
483 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 552 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
484 | 553 |
485 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 554 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
486 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); | 555 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); |
487 EXPECT_FALSE(VirtualDirectoryExists( | 556 EXPECT_FALSE(VirtualDirectoryExists( |
488 dest_dir_path.Append(src_dir_path.BaseName()))); | 557 dest_dir_path.Append(src_dir_path.BaseName()))); |
558 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
489 } | 559 } |
490 | 560 |
491 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 561 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
492 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 562 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
493 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); | 563 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); |
494 FilePath dest_child_dir_path(dest_parent_dir_path. | 564 FilePath dest_child_dir_path(dest_parent_dir_path. |
495 Append(FILE_PATH_LITERAL("NewDirectory"))); | 565 Append(FILE_PATH_LITERAL("NewDirectory"))); |
496 | 566 |
497 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); | 567 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); |
498 MessageLoop::current()->RunAllPending(); | 568 MessageLoop::current()->RunAllPending(); |
499 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 569 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
500 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); | 570 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); |
571 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
501 } | 572 } |
502 | 573 |
503 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 574 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
504 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 575 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
505 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); | 576 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); |
506 FilePath grandchild_file_path( | 577 FilePath grandchild_file_path( |
507 CreateVirtualTemporaryFileInDir(child_dir_path)); | 578 CreateVirtualTemporaryFileInDir(child_dir_path)); |
508 | 579 |
509 FilePath dest_dir_path(CreateVirtualTemporaryDir()); | 580 FilePath dest_dir_path(CreateVirtualTemporaryDir()); |
510 | 581 |
511 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); | 582 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); |
512 MessageLoop::current()->RunAllPending(); | 583 MessageLoop::current()->RunAllPending(); |
513 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 584 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
514 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( | 585 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( |
515 child_dir_path.BaseName()))); | 586 child_dir_path.BaseName()))); |
516 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( | 587 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( |
517 child_dir_path.BaseName()).Append( | 588 child_dir_path.BaseName()).Append( |
518 grandchild_file_path.BaseName()))); | 589 grandchild_file_path.BaseName()))); |
590 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
519 } | 591 } |
520 | 592 |
521 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { | 593 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { |
522 // Already existing file and exclusive true. | 594 // Already existing file and exclusive true. |
523 FilePath dir_path(CreateVirtualTemporaryDir()); | 595 FilePath dir_path(CreateVirtualTemporaryDir()); |
524 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 596 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
525 operation()->CreateFile(URLForPath(file_path), true); | 597 operation()->CreateFile(URLForPath(file_path), true); |
526 MessageLoop::current()->RunAllPending(); | 598 MessageLoop::current()->RunAllPending(); |
527 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 599 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
528 } | 600 } |
(...skipping 27 matching lines...) Expand all Loading... | |
556 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 628 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
557 } | 629 } |
558 | 630 |
559 TEST_F(FileSystemOperationTest, | 631 TEST_F(FileSystemOperationTest, |
560 TestCreateDirFailureDestParentDoesntExist) { | 632 TestCreateDirFailureDestParentDoesntExist) { |
561 // Dest. parent path does not exist. | 633 // Dest. parent path does not exist. |
562 FilePath nonexisting_path(FilePath( | 634 FilePath nonexisting_path(FilePath( |
563 FILE_PATH_LITERAL("DirDoesntExist"))); | 635 FILE_PATH_LITERAL("DirDoesntExist"))); |
564 FilePath nonexisting_file_path(nonexisting_path.Append( | 636 FilePath nonexisting_file_path(nonexisting_path.Append( |
565 FILE_PATH_LITERAL("FileDoesntExist"))); | 637 FILE_PATH_LITERAL("FileDoesntExist"))); |
566 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false); | 638 operation()->CreateDirectory( |
639 URLForPath(nonexisting_file_path), false, false); | |
567 MessageLoop::current()->RunAllPending(); | 640 MessageLoop::current()->RunAllPending(); |
568 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 641 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
569 } | 642 } |
570 | 643 |
571 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { | 644 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { |
572 // Exclusive and dir existing at path. | 645 // Exclusive and dir existing at path. |
573 FilePath src_dir_path(CreateVirtualTemporaryDir()); | 646 FilePath src_dir_path(CreateVirtualTemporaryDir()); |
574 operation()->CreateDirectory(URLForPath(src_dir_path), true, false); | 647 operation()->CreateDirectory(URLForPath(src_dir_path), true, false); |
575 MessageLoop::current()->RunAllPending(); | 648 MessageLoop::current()->RunAllPending(); |
576 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 649 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
(...skipping 11 matching lines...) Expand all Loading... | |
588 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { | 661 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { |
589 // Dir exists and exclusive is false. | 662 // Dir exists and exclusive is false. |
590 FilePath dir_path(CreateVirtualTemporaryDir()); | 663 FilePath dir_path(CreateVirtualTemporaryDir()); |
591 operation()->CreateDirectory(URLForPath(dir_path), false, false); | 664 operation()->CreateDirectory(URLForPath(dir_path), false, false); |
592 MessageLoop::current()->RunAllPending(); | 665 MessageLoop::current()->RunAllPending(); |
593 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 666 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
594 | 667 |
595 // Dir doesn't exist. | 668 // Dir doesn't exist. |
596 FilePath nonexisting_dir_path(FilePath( | 669 FilePath nonexisting_dir_path(FilePath( |
597 FILE_PATH_LITERAL("nonexistingdir"))); | 670 FILE_PATH_LITERAL("nonexistingdir"))); |
598 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false); | 671 operation()->CreateDirectory( |
672 URLForPath(nonexisting_dir_path), false, false); | |
599 MessageLoop::current()->RunAllPending(); | 673 MessageLoop::current()->RunAllPending(); |
600 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 674 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
601 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); | 675 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); |
602 } | 676 } |
603 | 677 |
604 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { | 678 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { |
605 // Dir doesn't exist. | 679 // Dir doesn't exist. |
606 FilePath nonexisting_dir_path(FilePath( | 680 FilePath nonexisting_dir_path(FilePath( |
607 FILE_PATH_LITERAL("nonexistingdir"))); | 681 FILE_PATH_LITERAL("nonexistingdir"))); |
608 | 682 |
609 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false); | 683 operation()->CreateDirectory( |
684 URLForPath(nonexisting_dir_path), true, false); | |
610 MessageLoop::current()->RunAllPending(); | 685 MessageLoop::current()->RunAllPending(); |
611 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 686 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
612 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); | 687 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); |
613 } | 688 } |
614 | 689 |
615 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { | 690 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { |
616 FilePath nonexisting_dir_path(FilePath( | 691 FilePath nonexisting_dir_path(FilePath( |
617 FILE_PATH_LITERAL("nonexistingdir"))); | 692 FILE_PATH_LITERAL("nonexistingdir"))); |
618 operation()->GetMetadata(URLForPath(nonexisting_dir_path)); | 693 operation()->GetMetadata(URLForPath(nonexisting_dir_path)); |
619 MessageLoop::current()->RunAllPending(); | 694 MessageLoop::current()->RunAllPending(); |
620 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 695 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
621 | 696 |
622 operation()->FileExists(URLForPath(nonexisting_dir_path)); | 697 operation()->FileExists(URLForPath(nonexisting_dir_path)); |
623 MessageLoop::current()->RunAllPending(); | 698 MessageLoop::current()->RunAllPending(); |
624 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 699 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
625 | 700 |
626 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 701 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
627 operation()->DirectoryExists(URLForPath(nonexisting_dir_path)); | 702 operation()->DirectoryExists(URLForPath(nonexisting_dir_path)); |
628 MessageLoop::current()->RunAllPending(); | 703 MessageLoop::current()->RunAllPending(); |
629 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
630 } | 705 } |
631 | 706 |
632 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { | 707 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { |
633 FilePath dir_path(CreateVirtualTemporaryDir()); | 708 FilePath dir_path(CreateVirtualTemporaryDir()); |
709 int read_access = 0; | |
634 | 710 |
635 operation()->DirectoryExists(URLForPath(dir_path)); | 711 operation()->DirectoryExists(URLForPath(dir_path)); |
636 MessageLoop::current()->RunAllPending(); | 712 MessageLoop::current()->RunAllPending(); |
637 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 713 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
714 ++read_access; | |
638 | 715 |
639 operation()->GetMetadata(URLForPath(dir_path)); | 716 operation()->GetMetadata(URLForPath(dir_path)); |
640 MessageLoop::current()->RunAllPending(); | 717 MessageLoop::current()->RunAllPending(); |
641 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 718 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
642 EXPECT_TRUE(info().is_directory); | 719 EXPECT_TRUE(info().is_directory); |
643 EXPECT_EQ(PlatformPath(dir_path), path()); | 720 EXPECT_EQ(PlatformPath(dir_path), path()); |
721 ++read_access; | |
644 | 722 |
645 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 723 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
646 operation()->FileExists(URLForPath(file_path)); | 724 operation()->FileExists(URLForPath(file_path)); |
647 MessageLoop::current()->RunAllPending(); | 725 MessageLoop::current()->RunAllPending(); |
648 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 726 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
727 ++read_access; | |
649 | 728 |
650 operation()->GetMetadata(URLForPath(file_path)); | 729 operation()->GetMetadata(URLForPath(file_path)); |
651 MessageLoop::current()->RunAllPending(); | 730 MessageLoop::current()->RunAllPending(); |
652 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 731 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
653 EXPECT_FALSE(info().is_directory); | 732 EXPECT_FALSE(info().is_directory); |
654 EXPECT_EQ(PlatformPath(file_path), path()); | 733 EXPECT_EQ(PlatformPath(file_path), path()); |
734 ++read_access; | |
735 | |
736 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); | |
655 } | 737 } |
656 | 738 |
657 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { | 739 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { |
658 FilePath dir_path(CreateVirtualTemporaryDir()); | 740 FilePath dir_path(CreateVirtualTemporaryDir()); |
659 operation()->FileExists(URLForPath(dir_path)); | 741 operation()->FileExists(URLForPath(dir_path)); |
660 MessageLoop::current()->RunAllPending(); | 742 MessageLoop::current()->RunAllPending(); |
661 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 743 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
662 | 744 |
663 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 745 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
664 ASSERT_FALSE(file_path.empty()); | 746 ASSERT_FALSE(file_path.empty()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 | 784 |
703 for (size_t i = 0; i < entries().size(); ++i) { | 785 for (size_t i = 0; i < entries().size(); ++i) { |
704 if (entries()[i].is_directory) { | 786 if (entries()[i].is_directory) { |
705 EXPECT_EQ(child_dir_path.BaseName().value(), | 787 EXPECT_EQ(child_dir_path.BaseName().value(), |
706 entries()[i].name); | 788 entries()[i].name); |
707 } else { | 789 } else { |
708 EXPECT_EQ(child_file_path.BaseName().value(), | 790 EXPECT_EQ(child_file_path.BaseName().value(), |
709 entries()[i].name); | 791 entries()[i].name); |
710 } | 792 } |
711 } | 793 } |
794 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
712 } | 795 } |
713 | 796 |
714 TEST_F(FileSystemOperationTest, TestRemoveFailure) { | 797 TEST_F(FileSystemOperationTest, TestRemoveFailure) { |
715 // Path doesn't exist. | 798 // Path doesn't exist. |
716 FilePath nonexisting_path(FilePath( | 799 FilePath nonexisting_path(FilePath( |
717 FILE_PATH_LITERAL("NonExistingDir"))); | 800 FILE_PATH_LITERAL("NonExistingDir"))); |
718 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 801 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
719 | 802 |
720 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */); | 803 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */); |
721 MessageLoop::current()->RunAllPending(); | 804 MessageLoop::current()->RunAllPending(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 // Verify deleting parent_dir. | 837 // Verify deleting parent_dir. |
755 FilePath parent_dir_path(CreateVirtualTemporaryDir()); | 838 FilePath parent_dir_path(CreateVirtualTemporaryDir()); |
756 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); | 839 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); |
757 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); | 840 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); |
758 ASSERT_FALSE(child_dir_path.empty()); | 841 ASSERT_FALSE(child_dir_path.empty()); |
759 | 842 |
760 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */); | 843 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */); |
761 MessageLoop::current()->RunAllPending(); | 844 MessageLoop::current()->RunAllPending(); |
762 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 845 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
763 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path)); | 846 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path)); |
847 | |
848 // Remove is not a 'read' access. | |
849 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); | |
764 } | 850 } |
765 | 851 |
766 TEST_F(FileSystemOperationTest, TestTruncate) { | 852 TEST_F(FileSystemOperationTest, TestTruncate) { |
767 FilePath dir_path(CreateVirtualTemporaryDir()); | 853 FilePath dir_path(CreateVirtualTemporaryDir()); |
768 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 854 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
769 | 855 |
770 char test_data[] = "test data"; | 856 char test_data[] = "test data"; |
771 int data_size = static_cast<int>(sizeof(test_data)); | 857 int data_size = static_cast<int>(sizeof(test_data)); |
772 EXPECT_EQ(data_size, | 858 EXPECT_EQ(data_size, |
773 file_util::WriteFile(PlatformPath(file_path), | 859 file_util::WriteFile(PlatformPath(file_path), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
806 operation()->Truncate(URLForPath(file_path), length); | 892 operation()->Truncate(URLForPath(file_path), length); |
807 MessageLoop::current()->RunAllPending(); | 893 MessageLoop::current()->RunAllPending(); |
808 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 894 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
809 | 895 |
810 // Check that its length is now 3 and that it contains only bits of test data. | 896 // Check that its length is now 3 and that it contains only bits of test data. |
811 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 897 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
812 EXPECT_EQ(length, info.size); | 898 EXPECT_EQ(length, info.size); |
813 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 899 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
814 for (int i = 0; i < length; ++i) | 900 for (int i = 0; i < length; ++i) |
815 EXPECT_EQ(test_data[i], data[i]); | 901 EXPECT_EQ(test_data[i], data[i]); |
902 | |
903 // Truncate is not a 'read' access. (Here expected access count is 1 | |
904 // since we made 1 read access for GetMetadata.) | |
905 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); | |
816 } | 906 } |
817 | 907 |
818 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) { | 908 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) { |
819 base::PlatformFileInfo info; | 909 base::PlatformFileInfo info; |
820 | 910 |
821 FilePath dir_path(CreateVirtualTemporaryDir()); | 911 FilePath dir_path(CreateVirtualTemporaryDir()); |
822 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); | 912 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); |
823 | 913 |
824 quota_manager()->set_quota(10); | 914 quota_manager_proxy()->SetQuota(test_helper_.origin(), |
915 test_helper_.storage_type(), | |
916 10); | |
825 | 917 |
826 operation()->Truncate(URLForPath(file_path), 10); | 918 operation()->Truncate(URLForPath(file_path), 10); |
827 MessageLoop::current()->RunAllPending(); | 919 MessageLoop::current()->RunAllPending(); |
828 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 920 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
829 | 921 |
830 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 922 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
831 EXPECT_EQ(10, info.size); | 923 EXPECT_EQ(10, info.size); |
832 | 924 |
833 quota_manager()->set_usage(10); | |
834 | |
835 operation()->Truncate(URLForPath(file_path), 11); | 925 operation()->Truncate(URLForPath(file_path), 11); |
836 MessageLoop::current()->RunAllPending(); | 926 MessageLoop::current()->RunAllPending(); |
837 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 927 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
838 | 928 |
839 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 929 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
840 EXPECT_EQ(10, info.size); | 930 EXPECT_EQ(10, info.size); |
841 } | 931 } |
842 | 932 |
843 } // namespace fileapi | 933 } // namespace fileapi |
OLD | NEW |