OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 : status_(kFileOperationStatusNotSet), | 51 : status_(kFileOperationStatusNotSet), |
52 next_unique_path_suffix_(0) { | 52 next_unique_path_suffix_(0) { |
53 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 53 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
54 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); | 54 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); |
55 } | 55 } |
56 | 56 |
57 LocalFileSystemOperation* operation(); | 57 LocalFileSystemOperation* operation(); |
58 | 58 |
59 int status() const { return status_; } | 59 int status() const { return status_; } |
60 const base::PlatformFileInfo& info() const { return info_; } | 60 const base::PlatformFileInfo& info() const { return info_; } |
61 const FilePath& path() const { return path_; } | 61 const base::FilePath& path() const { return path_; } |
62 const std::vector<base::FileUtilProxy::Entry>& entries() const { | 62 const std::vector<base::FileUtilProxy::Entry>& entries() const { |
63 return entries_; | 63 return entries_; |
64 } | 64 } |
65 const ShareableFileReference* shareable_file_ref() const { | 65 const ShareableFileReference* shareable_file_ref() const { |
66 return shareable_file_ref_; | 66 return shareable_file_ref_; |
67 } | 67 } |
68 | 68 |
69 virtual void SetUp() OVERRIDE; | 69 virtual void SetUp() OVERRIDE; |
70 virtual void TearDown() OVERRIDE; | 70 virtual void TearDown() OVERRIDE; |
71 | 71 |
(...skipping 22 matching lines...) Expand all Loading... |
94 return &change_observer_; | 94 return &change_observer_; |
95 } | 95 } |
96 | 96 |
97 FileSystemOperationContext* NewContext() { | 97 FileSystemOperationContext* NewContext() { |
98 FileSystemOperationContext* context = test_helper_.NewOperationContext(); | 98 FileSystemOperationContext* context = test_helper_.NewOperationContext(); |
99 // Grant enough quota for all test cases. | 99 // Grant enough quota for all test cases. |
100 context->set_allowed_bytes_growth(1000000); | 100 context->set_allowed_bytes_growth(1000000); |
101 return context; | 101 return context; |
102 } | 102 } |
103 | 103 |
104 FileSystemURL URLForPath(const FilePath& path) const { | 104 FileSystemURL URLForPath(const base::FilePath& path) const { |
105 return test_helper_.CreateURL(path); | 105 return test_helper_.CreateURL(path); |
106 } | 106 } |
107 | 107 |
108 FilePath PlatformPath(const FilePath& virtual_path) { | 108 base::FilePath PlatformPath(const base::FilePath& virtual_path) { |
109 return test_helper_.GetLocalPath(virtual_path); | 109 return test_helper_.GetLocalPath(virtual_path); |
110 } | 110 } |
111 | 111 |
112 bool FileExists(const FilePath& virtual_path) { | 112 bool FileExists(const base::FilePath& virtual_path) { |
113 FileSystemURL url = test_helper_.CreateURL(virtual_path); | 113 FileSystemURL url = test_helper_.CreateURL(virtual_path); |
114 base::PlatformFileInfo file_info; | 114 base::PlatformFileInfo file_info; |
115 FilePath platform_path; | 115 base::FilePath platform_path; |
116 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 116 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
117 base::PlatformFileError error = file_util()->GetFileInfo( | 117 base::PlatformFileError error = file_util()->GetFileInfo( |
118 context.get(), url, &file_info, &platform_path); | 118 context.get(), url, &file_info, &platform_path); |
119 return error == base::PLATFORM_FILE_OK && !file_info.is_directory; | 119 return error == base::PLATFORM_FILE_OK && !file_info.is_directory; |
120 } | 120 } |
121 | 121 |
122 bool DirectoryExists(const FilePath& virtual_path) { | 122 bool DirectoryExists(const base::FilePath& virtual_path) { |
123 FileSystemURL url = test_helper_.CreateURL(virtual_path); | 123 FileSystemURL url = test_helper_.CreateURL(virtual_path); |
124 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 124 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
125 return FileUtilHelper::DirectoryExists(context.get(), file_util(), url); | 125 return FileUtilHelper::DirectoryExists(context.get(), file_util(), url); |
126 } | 126 } |
127 | 127 |
128 FilePath CreateUniqueFileInDir(const FilePath& virtual_dir_path) { | 128 base::FilePath CreateUniqueFileInDir(const base::FilePath& virtual_dir_path) { |
129 FilePath file_name = FilePath::FromUTF8Unsafe( | 129 base::FilePath file_name = base::FilePath::FromUTF8Unsafe( |
130 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); | 130 "tmpfile-" + base::IntToString(next_unique_path_suffix_++)); |
131 FileSystemURL url = test_helper_.CreateURL( | 131 FileSystemURL url = test_helper_.CreateURL( |
132 virtual_dir_path.Append(file_name)); | 132 virtual_dir_path.Append(file_name)); |
133 | 133 |
134 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 134 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
135 bool created; | 135 bool created; |
136 EXPECT_EQ(base::PLATFORM_FILE_OK, | 136 EXPECT_EQ(base::PLATFORM_FILE_OK, |
137 file_util()->EnsureFileExists(context.get(), url, &created)); | 137 file_util()->EnsureFileExists(context.get(), url, &created)); |
138 EXPECT_TRUE(created); | 138 EXPECT_TRUE(created); |
139 return url.path(); | 139 return url.path(); |
140 } | 140 } |
141 | 141 |
142 FilePath CreateUniqueDirInDir(const FilePath& virtual_dir_path) { | 142 base::FilePath CreateUniqueDirInDir(const base::FilePath& virtual_dir_path) { |
143 FilePath dir_name = FilePath::FromUTF8Unsafe( | 143 base::FilePath dir_name = base::FilePath::FromUTF8Unsafe( |
144 "tmpdir-" + base::IntToString(next_unique_path_suffix_++)); | 144 "tmpdir-" + base::IntToString(next_unique_path_suffix_++)); |
145 FileSystemURL url = test_helper_.CreateURL( | 145 FileSystemURL url = test_helper_.CreateURL( |
146 virtual_dir_path.Append(dir_name)); | 146 virtual_dir_path.Append(dir_name)); |
147 | 147 |
148 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 148 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
149 EXPECT_EQ(base::PLATFORM_FILE_OK, | 149 EXPECT_EQ(base::PLATFORM_FILE_OK, |
150 file_util()->CreateDirectory(context.get(), url, false, true)); | 150 file_util()->CreateDirectory(context.get(), url, false, true)); |
151 return url.path(); | 151 return url.path(); |
152 } | 152 } |
153 | 153 |
154 FilePath CreateUniqueDir() { | 154 base::FilePath CreateUniqueDir() { |
155 return CreateUniqueDirInDir(FilePath()); | 155 return CreateUniqueDirInDir(base::FilePath()); |
156 } | 156 } |
157 | 157 |
158 LocalFileSystemTestOriginHelper test_helper_; | 158 LocalFileSystemTestOriginHelper test_helper_; |
159 | 159 |
160 // Callbacks for recording test results. | 160 // Callbacks for recording test results. |
161 FileSystemOperation::StatusCallback RecordStatusCallback() { | 161 FileSystemOperation::StatusCallback RecordStatusCallback() { |
162 return base::Bind(&LocalFileSystemOperationTest::DidFinish, AsWeakPtr()); | 162 return base::Bind(&LocalFileSystemOperationTest::DidFinish, AsWeakPtr()); |
163 } | 163 } |
164 | 164 |
165 FileSystemOperation::ReadDirectoryCallback | 165 FileSystemOperation::ReadDirectoryCallback |
(...skipping 19 matching lines...) Expand all Loading... |
185 void DidReadDirectory( | 185 void DidReadDirectory( |
186 base::PlatformFileError status, | 186 base::PlatformFileError status, |
187 const std::vector<base::FileUtilProxy::Entry>& entries, | 187 const std::vector<base::FileUtilProxy::Entry>& entries, |
188 bool /* has_more */) { | 188 bool /* has_more */) { |
189 entries_ = entries; | 189 entries_ = entries; |
190 status_ = status; | 190 status_ = status; |
191 } | 191 } |
192 | 192 |
193 void DidGetMetadata(base::PlatformFileError status, | 193 void DidGetMetadata(base::PlatformFileError status, |
194 const base::PlatformFileInfo& info, | 194 const base::PlatformFileInfo& info, |
195 const FilePath& platform_path) { | 195 const base::FilePath& platform_path) { |
196 info_ = info; | 196 info_ = info; |
197 path_ = platform_path; | 197 path_ = platform_path; |
198 status_ = status; | 198 status_ = status; |
199 } | 199 } |
200 | 200 |
201 void DidCreateSnapshotFile( | 201 void DidCreateSnapshotFile( |
202 base::PlatformFileError status, | 202 base::PlatformFileError status, |
203 const base::PlatformFileInfo& info, | 203 const base::PlatformFileInfo& info, |
204 const FilePath& platform_path, | 204 const base::FilePath& platform_path, |
205 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { | 205 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { |
206 info_ = info; | 206 info_ = info; |
207 path_ = platform_path; | 207 path_ = platform_path; |
208 status_ = status; | 208 status_ = status; |
209 shareable_file_ref_ = shareable_file_ref; | 209 shareable_file_ref_ = shareable_file_ref; |
210 } | 210 } |
211 | 211 |
212 static void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, | 212 static void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, |
213 int64* usage_out, | 213 int64* usage_out, |
214 int64* quota_out, | 214 int64* quota_out, |
(...skipping 14 matching lines...) Expand all Loading... |
229 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; | 229 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; |
230 quota_manager_->GetUsageAndQuota( | 230 quota_manager_->GetUsageAndQuota( |
231 test_helper_.origin(), | 231 test_helper_.origin(), |
232 test_helper_.storage_type(), | 232 test_helper_.storage_type(), |
233 base::Bind(&LocalFileSystemOperationTest::DidGetUsageAndQuota, | 233 base::Bind(&LocalFileSystemOperationTest::DidGetUsageAndQuota, |
234 &status, usage, quota)); | 234 &status, usage, quota)); |
235 MessageLoop::current()->RunUntilIdle(); | 235 MessageLoop::current()->RunUntilIdle(); |
236 ASSERT_EQ(quota::kQuotaStatusOk, status); | 236 ASSERT_EQ(quota::kQuotaStatusOk, status); |
237 } | 237 } |
238 | 238 |
239 void GenerateUniquePathInDir(const FilePath& dir, | 239 void GenerateUniquePathInDir(const base::FilePath& dir, |
240 FilePath* file_path, | 240 base::FilePath* file_path, |
241 int64* path_cost) { | 241 int64* path_cost) { |
242 int64 base_usage; | 242 int64 base_usage; |
243 GetUsageAndQuota(&base_usage, NULL); | 243 GetUsageAndQuota(&base_usage, NULL); |
244 *file_path = CreateUniqueFileInDir(dir); | 244 *file_path = CreateUniqueFileInDir(dir); |
245 operation()->Remove(URLForPath(*file_path), | 245 operation()->Remove(URLForPath(*file_path), |
246 false /* recursive */, | 246 false /* recursive */, |
247 base::Bind(&AssertFileErrorEq, | 247 base::Bind(&AssertFileErrorEq, |
248 base::PLATFORM_FILE_OK)); | 248 base::PLATFORM_FILE_OK)); |
249 MessageLoop::current()->RunUntilIdle(); | 249 MessageLoop::current()->RunUntilIdle(); |
250 | 250 |
(...skipping 14 matching lines...) Expand all Loading... |
265 int64 quota; | 265 int64 quota; |
266 GetUsageAndQuota(NULL, "a); | 266 GetUsageAndQuota(NULL, "a); |
267 quota_manager()->SetQuota(test_helper_.origin(), | 267 quota_manager()->SetQuota(test_helper_.origin(), |
268 test_helper_.storage_type(), | 268 test_helper_.storage_type(), |
269 quota + quota_delta); | 269 quota + quota_delta); |
270 } | 270 } |
271 | 271 |
272 // For post-operation status. | 272 // For post-operation status. |
273 int status_; | 273 int status_; |
274 base::PlatformFileInfo info_; | 274 base::PlatformFileInfo info_; |
275 FilePath path_; | 275 base::FilePath path_; |
276 std::vector<base::FileUtilProxy::Entry> entries_; | 276 std::vector<base::FileUtilProxy::Entry> entries_; |
277 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 277 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
278 | 278 |
279 private: | 279 private: |
280 MessageLoop message_loop_; | 280 MessageLoop message_loop_; |
281 scoped_refptr<QuotaManager> quota_manager_; | 281 scoped_refptr<QuotaManager> quota_manager_; |
282 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 282 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
283 | 283 |
284 MockFileChangeObserver change_observer_; | 284 MockFileChangeObserver change_observer_; |
285 ChangeObserverList change_observers_; | 285 ChangeObserverList change_observers_; |
286 | 286 |
287 int next_unique_path_suffix_; | 287 int next_unique_path_suffix_; |
288 | 288 |
289 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); | 289 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); |
290 }; | 290 }; |
291 | 291 |
292 void LocalFileSystemOperationTest::SetUp() { | 292 void LocalFileSystemOperationTest::SetUp() { |
293 FilePath base_dir = base_.path().AppendASCII("filesystem"); | 293 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); |
294 quota_manager_ = new quota::MockQuotaManager( | 294 quota_manager_ = new quota::MockQuotaManager( |
295 false /* is_incognito */, base_dir, | 295 false /* is_incognito */, base_dir, |
296 base::MessageLoopProxy::current(), | 296 base::MessageLoopProxy::current(), |
297 base::MessageLoopProxy::current(), | 297 base::MessageLoopProxy::current(), |
298 NULL /* special storage policy */); | 298 NULL /* special storage policy */); |
299 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( | 299 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( |
300 quota_manager(), | 300 quota_manager(), |
301 base::MessageLoopProxy::current()); | 301 base::MessageLoopProxy::current()); |
302 test_helper_.SetUp(base_dir, | 302 test_helper_.SetUp(base_dir, |
303 false /* unlimited quota */, | 303 false /* unlimited quota */, |
304 quota_manager_proxy_.get()); | 304 quota_manager_proxy_.get()); |
305 } | 305 } |
306 | 306 |
307 void LocalFileSystemOperationTest::TearDown() { | 307 void LocalFileSystemOperationTest::TearDown() { |
308 // Let the client go away before dropping a ref of the quota manager proxy. | 308 // Let the client go away before dropping a ref of the quota manager proxy. |
309 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 309 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
310 quota_manager_ = NULL; | 310 quota_manager_ = NULL; |
311 quota_manager_proxy_ = NULL; | 311 quota_manager_proxy_ = NULL; |
312 test_helper_.TearDown(); | 312 test_helper_.TearDown(); |
313 } | 313 } |
314 | 314 |
315 LocalFileSystemOperation* LocalFileSystemOperationTest::operation() { | 315 LocalFileSystemOperation* LocalFileSystemOperationTest::operation() { |
316 LocalFileSystemOperation* operation = test_helper_.NewOperation(); | 316 LocalFileSystemOperation* operation = test_helper_.NewOperation(); |
317 operation->operation_context()->set_change_observers(change_observers()); | 317 operation->operation_context()->set_change_observers(change_observers()); |
318 return operation; | 318 return operation; |
319 } | 319 } |
320 | 320 |
321 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 321 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
322 FileSystemURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); | 322 FileSystemURL src(URLForPath(base::FilePath(FILE_PATH_LITERAL("a")))); |
323 FileSystemURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 323 FileSystemURL dest(URLForPath(base::FilePath(FILE_PATH_LITERAL("b")))); |
324 change_observer()->ResetCount(); | 324 change_observer()->ResetCount(); |
325 operation()->Move(src, dest, RecordStatusCallback()); | 325 operation()->Move(src, dest, RecordStatusCallback()); |
326 MessageLoop::current()->RunUntilIdle(); | 326 MessageLoop::current()->RunUntilIdle(); |
327 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 327 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
328 EXPECT_TRUE(change_observer()->HasNoChange()); | 328 EXPECT_TRUE(change_observer()->HasNoChange()); |
329 } | 329 } |
330 | 330 |
331 TEST_F(LocalFileSystemOperationTest, TestMoveFailureContainsPath) { | 331 TEST_F(LocalFileSystemOperationTest, TestMoveFailureContainsPath) { |
332 FilePath src_dir_path(CreateUniqueDir()); | 332 base::FilePath src_dir_path(CreateUniqueDir()); |
333 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); | 333 base::FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); |
334 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 334 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
335 RecordStatusCallback()); | 335 RecordStatusCallback()); |
336 MessageLoop::current()->RunUntilIdle(); | 336 MessageLoop::current()->RunUntilIdle(); |
337 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 337 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
338 EXPECT_TRUE(change_observer()->HasNoChange()); | 338 EXPECT_TRUE(change_observer()->HasNoChange()); |
339 } | 339 } |
340 | 340 |
341 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { | 341 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { |
342 // Src exists and is dir. Dest is a file. | 342 // Src exists and is dir. Dest is a file. |
343 FilePath src_dir_path(CreateUniqueDir()); | 343 base::FilePath src_dir_path(CreateUniqueDir()); |
344 FilePath dest_dir_path(CreateUniqueDir()); | 344 base::FilePath dest_dir_path(CreateUniqueDir()); |
345 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 345 base::FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
346 | 346 |
347 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path), | 347 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path), |
348 RecordStatusCallback()); | 348 RecordStatusCallback()); |
349 MessageLoop::current()->RunUntilIdle(); | 349 MessageLoop::current()->RunUntilIdle(); |
350 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 350 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
351 EXPECT_TRUE(change_observer()->HasNoChange()); | 351 EXPECT_TRUE(change_observer()->HasNoChange()); |
352 } | 352 } |
353 | 353 |
354 TEST_F(LocalFileSystemOperationTest, | 354 TEST_F(LocalFileSystemOperationTest, |
355 TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 355 TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
356 // Src exists and is a directory. Dest is a non-empty directory. | 356 // Src exists and is a directory. Dest is a non-empty directory. |
357 FilePath src_dir_path(CreateUniqueDir()); | 357 base::FilePath src_dir_path(CreateUniqueDir()); |
358 FilePath dest_dir_path(CreateUniqueDir()); | 358 base::FilePath dest_dir_path(CreateUniqueDir()); |
359 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); | 359 base::FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); |
360 | 360 |
361 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 361 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
362 RecordStatusCallback()); | 362 RecordStatusCallback()); |
363 MessageLoop::current()->RunUntilIdle(); | 363 MessageLoop::current()->RunUntilIdle(); |
364 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 364 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
365 EXPECT_TRUE(change_observer()->HasNoChange()); | 365 EXPECT_TRUE(change_observer()->HasNoChange()); |
366 } | 366 } |
367 | 367 |
368 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { | 368 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { |
369 // Src exists and is a file. Dest is a directory. | 369 // Src exists and is a file. Dest is a directory. |
370 FilePath src_dir_path(CreateUniqueDir()); | 370 base::FilePath src_dir_path(CreateUniqueDir()); |
371 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 371 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
372 FilePath dest_dir_path(CreateUniqueDir()); | 372 base::FilePath dest_dir_path(CreateUniqueDir()); |
373 | 373 |
374 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path), | 374 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path), |
375 RecordStatusCallback()); | 375 RecordStatusCallback()); |
376 MessageLoop::current()->RunUntilIdle(); | 376 MessageLoop::current()->RunUntilIdle(); |
377 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 377 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
378 EXPECT_TRUE(change_observer()->HasNoChange()); | 378 EXPECT_TRUE(change_observer()->HasNoChange()); |
379 } | 379 } |
380 | 380 |
381 TEST_F(LocalFileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { | 381 TEST_F(LocalFileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { |
382 // Dest. parent path does not exist. | 382 // Dest. parent path does not exist. |
383 FilePath src_dir_path(CreateUniqueDir()); | 383 base::FilePath src_dir_path(CreateUniqueDir()); |
384 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). | 384 base::FilePath nonexisting_file = base::FilePath(FILE_PATH_LITERAL("Nonexistin
gDir")). |
385 Append(FILE_PATH_LITERAL("NonexistingFile")); | 385 Append(FILE_PATH_LITERAL("NonexistingFile")); |
386 | 386 |
387 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file), | 387 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file), |
388 RecordStatusCallback()); | 388 RecordStatusCallback()); |
389 MessageLoop::current()->RunUntilIdle(); | 389 MessageLoop::current()->RunUntilIdle(); |
390 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 390 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
391 EXPECT_TRUE(change_observer()->HasNoChange()); | 391 EXPECT_TRUE(change_observer()->HasNoChange()); |
392 } | 392 } |
393 | 393 |
394 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 394 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { |
395 FilePath src_dir_path(CreateUniqueDir()); | 395 base::FilePath src_dir_path(CreateUniqueDir()); |
396 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 396 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
397 FilePath dest_dir_path(CreateUniqueDir()); | 397 base::FilePath dest_dir_path(CreateUniqueDir()); |
398 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 398 base::FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
399 | 399 |
400 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), | 400 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
401 RecordStatusCallback()); | 401 RecordStatusCallback()); |
402 MessageLoop::current()->RunUntilIdle(); | 402 MessageLoop::current()->RunUntilIdle(); |
403 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 403 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
404 EXPECT_TRUE(FileExists(dest_file_path)); | 404 EXPECT_TRUE(FileExists(dest_file_path)); |
405 | 405 |
406 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 406 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
407 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 407 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
408 EXPECT_TRUE(change_observer()->HasNoChange()); | 408 EXPECT_TRUE(change_observer()->HasNoChange()); |
409 | 409 |
410 // Move is considered 'write' access (for both side), and won't be counted | 410 // Move is considered 'write' access (for both side), and won't be counted |
411 // as read access. | 411 // as read access. |
412 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); | 412 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); |
413 } | 413 } |
414 | 414 |
415 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 415 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { |
416 FilePath src_dir_path(CreateUniqueDir()); | 416 base::FilePath src_dir_path(CreateUniqueDir()); |
417 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 417 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
418 FilePath dest_dir_path(CreateUniqueDir()); | 418 base::FilePath dest_dir_path(CreateUniqueDir()); |
419 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 419 base::FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"
))); |
420 | 420 |
421 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), | 421 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
422 RecordStatusCallback()); | 422 RecordStatusCallback()); |
423 MessageLoop::current()->RunUntilIdle(); | 423 MessageLoop::current()->RunUntilIdle(); |
424 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 424 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
425 EXPECT_TRUE(FileExists(dest_file_path)); | 425 EXPECT_TRUE(FileExists(dest_file_path)); |
426 | 426 |
427 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 427 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
428 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 428 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
429 EXPECT_TRUE(change_observer()->HasNoChange()); | 429 EXPECT_TRUE(change_observer()->HasNoChange()); |
430 } | 430 } |
431 | 431 |
432 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { | 432 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { |
433 FilePath src_dir_path(CreateUniqueDir()); | 433 base::FilePath src_dir_path(CreateUniqueDir()); |
434 FilePath dest_dir_path(CreateUniqueDir()); | 434 base::FilePath dest_dir_path(CreateUniqueDir()); |
435 | 435 |
436 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 436 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
437 RecordStatusCallback()); | 437 RecordStatusCallback()); |
438 MessageLoop::current()->RunUntilIdle(); | 438 MessageLoop::current()->RunUntilIdle(); |
439 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 439 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
440 EXPECT_FALSE(DirectoryExists(src_dir_path)); | 440 EXPECT_FALSE(DirectoryExists(src_dir_path)); |
441 | 441 |
442 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 442 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
443 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 443 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
444 EXPECT_TRUE(change_observer()->HasNoChange()); | 444 EXPECT_TRUE(change_observer()->HasNoChange()); |
445 | 445 |
446 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 446 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
447 EXPECT_TRUE(DirectoryExists(dest_dir_path)); | 447 EXPECT_TRUE(DirectoryExists(dest_dir_path)); |
448 EXPECT_FALSE(DirectoryExists( | 448 EXPECT_FALSE(DirectoryExists( |
449 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); | 449 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
450 } | 450 } |
451 | 451 |
452 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { | 452 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { |
453 FilePath src_dir_path(CreateUniqueDir()); | 453 base::FilePath src_dir_path(CreateUniqueDir()); |
454 FilePath dest_parent_dir_path(CreateUniqueDir()); | 454 base::FilePath dest_parent_dir_path(CreateUniqueDir()); |
455 FilePath dest_child_dir_path(dest_parent_dir_path. | 455 base::FilePath dest_child_dir_path(dest_parent_dir_path. |
456 Append(FILE_PATH_LITERAL("NewDirectory"))); | 456 Append(FILE_PATH_LITERAL("NewDirectory"))); |
457 | 457 |
458 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 458 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
459 RecordStatusCallback()); | 459 RecordStatusCallback()); |
460 MessageLoop::current()->RunUntilIdle(); | 460 MessageLoop::current()->RunUntilIdle(); |
461 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 461 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
462 EXPECT_FALSE(DirectoryExists(src_dir_path)); | 462 EXPECT_FALSE(DirectoryExists(src_dir_path)); |
463 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); | 463 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); |
464 | 464 |
465 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 465 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
466 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 466 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
467 EXPECT_TRUE(change_observer()->HasNoChange()); | 467 EXPECT_TRUE(change_observer()->HasNoChange()); |
468 } | 468 } |
469 | 469 |
470 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { | 470 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { |
471 FilePath src_dir_path(CreateUniqueDir()); | 471 base::FilePath src_dir_path(CreateUniqueDir()); |
472 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); | 472 base::FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); |
473 FilePath grandchild_file_path( | 473 base::FilePath grandchild_file_path( |
474 CreateUniqueFileInDir(child_dir_path)); | 474 CreateUniqueFileInDir(child_dir_path)); |
475 | 475 |
476 FilePath dest_dir_path(CreateUniqueDir()); | 476 base::FilePath dest_dir_path(CreateUniqueDir()); |
477 | 477 |
478 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 478 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
479 RecordStatusCallback()); | 479 RecordStatusCallback()); |
480 MessageLoop::current()->RunUntilIdle(); | 480 MessageLoop::current()->RunUntilIdle(); |
481 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 481 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
482 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( | 482 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( |
483 VirtualPath::BaseName(child_dir_path)))); | 483 VirtualPath::BaseName(child_dir_path)))); |
484 EXPECT_TRUE(FileExists(dest_dir_path.Append( | 484 EXPECT_TRUE(FileExists(dest_dir_path.Append( |
485 VirtualPath::BaseName(child_dir_path)).Append( | 485 VirtualPath::BaseName(child_dir_path)).Append( |
486 VirtualPath::BaseName(grandchild_file_path)))); | 486 VirtualPath::BaseName(grandchild_file_path)))); |
487 | 487 |
488 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); | 488 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); |
489 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 489 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
490 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 490 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
491 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 491 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
492 EXPECT_TRUE(change_observer()->HasNoChange()); | 492 EXPECT_TRUE(change_observer()->HasNoChange()); |
493 } | 493 } |
494 | 494 |
495 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 495 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDoesntExist) { |
496 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), | 496 operation()->Copy(URLForPath(base::FilePath(FILE_PATH_LITERAL("a"))), |
497 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), | 497 URLForPath(base::FilePath(FILE_PATH_LITERAL("b"))), |
498 RecordStatusCallback()); | 498 RecordStatusCallback()); |
499 MessageLoop::current()->RunUntilIdle(); | 499 MessageLoop::current()->RunUntilIdle(); |
500 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 500 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
501 EXPECT_TRUE(change_observer()->HasNoChange()); | 501 EXPECT_TRUE(change_observer()->HasNoChange()); |
502 } | 502 } |
503 | 503 |
504 TEST_F(LocalFileSystemOperationTest, TestCopyFailureContainsPath) { | 504 TEST_F(LocalFileSystemOperationTest, TestCopyFailureContainsPath) { |
505 FilePath src_dir_path(CreateUniqueDir()); | 505 base::FilePath src_dir_path(CreateUniqueDir()); |
506 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); | 506 base::FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); |
507 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 507 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
508 RecordStatusCallback()); | 508 RecordStatusCallback()); |
509 MessageLoop::current()->RunUntilIdle(); | 509 MessageLoop::current()->RunUntilIdle(); |
510 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 510 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
511 EXPECT_TRUE(change_observer()->HasNoChange()); | 511 EXPECT_TRUE(change_observer()->HasNoChange()); |
512 } | 512 } |
513 | 513 |
514 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { | 514 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { |
515 // Src exists and is dir. Dest is a file. | 515 // Src exists and is dir. Dest is a file. |
516 FilePath src_dir_path(CreateUniqueDir()); | 516 base::FilePath src_dir_path(CreateUniqueDir()); |
517 FilePath dest_dir_path(CreateUniqueDir()); | 517 base::FilePath dest_dir_path(CreateUniqueDir()); |
518 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 518 base::FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
519 | 519 |
520 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path), | 520 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path), |
521 RecordStatusCallback()); | 521 RecordStatusCallback()); |
522 MessageLoop::current()->RunUntilIdle(); | 522 MessageLoop::current()->RunUntilIdle(); |
523 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 523 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
524 EXPECT_TRUE(change_observer()->HasNoChange()); | 524 EXPECT_TRUE(change_observer()->HasNoChange()); |
525 } | 525 } |
526 | 526 |
527 TEST_F(LocalFileSystemOperationTest, | 527 TEST_F(LocalFileSystemOperationTest, |
528 TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 528 TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
529 // Src exists and is a directory. Dest is a non-empty directory. | 529 // Src exists and is a directory. Dest is a non-empty directory. |
530 FilePath src_dir_path(CreateUniqueDir()); | 530 base::FilePath src_dir_path(CreateUniqueDir()); |
531 FilePath dest_dir_path(CreateUniqueDir()); | 531 base::FilePath dest_dir_path(CreateUniqueDir()); |
532 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); | 532 base::FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); |
533 | 533 |
534 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 534 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
535 RecordStatusCallback()); | 535 RecordStatusCallback()); |
536 MessageLoop::current()->RunUntilIdle(); | 536 MessageLoop::current()->RunUntilIdle(); |
537 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 537 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
538 EXPECT_TRUE(change_observer()->HasNoChange()); | 538 EXPECT_TRUE(change_observer()->HasNoChange()); |
539 } | 539 } |
540 | 540 |
541 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { | 541 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { |
542 // Src exists and is a file. Dest is a directory. | 542 // Src exists and is a file. Dest is a directory. |
543 FilePath src_dir_path(CreateUniqueDir()); | 543 base::FilePath src_dir_path(CreateUniqueDir()); |
544 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 544 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
545 FilePath dest_dir_path(CreateUniqueDir()); | 545 base::FilePath dest_dir_path(CreateUniqueDir()); |
546 | 546 |
547 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path), | 547 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path), |
548 RecordStatusCallback()); | 548 RecordStatusCallback()); |
549 MessageLoop::current()->RunUntilIdle(); | 549 MessageLoop::current()->RunUntilIdle(); |
550 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 550 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
551 EXPECT_TRUE(change_observer()->HasNoChange()); | 551 EXPECT_TRUE(change_observer()->HasNoChange()); |
552 } | 552 } |
553 | 553 |
554 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 554 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { |
555 // Dest. parent path does not exist. | 555 // Dest. parent path does not exist. |
556 FilePath src_dir_path(CreateUniqueDir()); | 556 base::FilePath src_dir_path(CreateUniqueDir()); |
557 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); | 557 base::FilePath nonexisting_path = base::FilePath(FILE_PATH_LITERAL("DontExistD
ir")); |
558 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 558 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
559 FilePath nonexisting_file_path(nonexisting_path.Append( | 559 base::FilePath nonexisting_file_path(nonexisting_path.Append( |
560 FILE_PATH_LITERAL("DontExistFile"))); | 560 FILE_PATH_LITERAL("DontExistFile"))); |
561 | 561 |
562 operation()->Copy(URLForPath(src_dir_path), | 562 operation()->Copy(URLForPath(src_dir_path), |
563 URLForPath(nonexisting_file_path), | 563 URLForPath(nonexisting_file_path), |
564 RecordStatusCallback()); | 564 RecordStatusCallback()); |
565 MessageLoop::current()->RunUntilIdle(); | 565 MessageLoop::current()->RunUntilIdle(); |
566 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 566 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
567 EXPECT_TRUE(change_observer()->HasNoChange()); | 567 EXPECT_TRUE(change_observer()->HasNoChange()); |
568 } | 568 } |
569 | 569 |
570 TEST_F(LocalFileSystemOperationTest, TestCopyFailureByQuota) { | 570 TEST_F(LocalFileSystemOperationTest, TestCopyFailureByQuota) { |
571 base::PlatformFileInfo info; | 571 base::PlatformFileInfo info; |
572 | 572 |
573 FilePath src_dir_path(CreateUniqueDir()); | 573 base::FilePath src_dir_path(CreateUniqueDir()); |
574 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 574 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
575 FilePath dest_dir_path(CreateUniqueDir()); | 575 base::FilePath dest_dir_path(CreateUniqueDir()); |
576 | 576 |
577 FilePath dest_file_path; | 577 base::FilePath dest_file_path; |
578 int64 dest_path_cost; | 578 int64 dest_path_cost; |
579 GenerateUniquePathInDir(dest_dir_path, &dest_file_path, &dest_path_cost); | 579 GenerateUniquePathInDir(dest_dir_path, &dest_file_path, &dest_path_cost); |
580 | 580 |
581 GrantQuotaForCurrentUsage(); | 581 GrantQuotaForCurrentUsage(); |
582 AddQuota(6); | 582 AddQuota(6); |
583 | 583 |
584 operation()->Truncate(URLForPath(src_file_path), 6, | 584 operation()->Truncate(URLForPath(src_file_path), 6, |
585 RecordStatusCallback()); | 585 RecordStatusCallback()); |
586 MessageLoop::current()->RunUntilIdle(); | 586 MessageLoop::current()->RunUntilIdle(); |
587 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 587 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
588 | 588 |
589 AddQuota(6 + dest_path_cost - 1); | 589 AddQuota(6 + dest_path_cost - 1); |
590 | 590 |
591 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); | 591 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); |
592 EXPECT_EQ(6, info.size); | 592 EXPECT_EQ(6, info.size); |
593 | 593 |
594 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 594 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
595 RecordStatusCallback()); | 595 RecordStatusCallback()); |
596 MessageLoop::current()->RunUntilIdle(); | 596 MessageLoop::current()->RunUntilIdle(); |
597 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 597 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
598 EXPECT_FALSE(FileExists(dest_file_path)); | 598 EXPECT_FALSE(FileExists(dest_file_path)); |
599 } | 599 } |
600 | 600 |
601 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { | 601 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { |
602 FilePath src_dir_path(CreateUniqueDir()); | 602 base::FilePath src_dir_path(CreateUniqueDir()); |
603 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 603 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
604 FilePath dest_dir_path(CreateUniqueDir()); | 604 base::FilePath dest_dir_path(CreateUniqueDir()); |
605 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 605 base::FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
606 | 606 |
607 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 607 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
608 RecordStatusCallback()); | 608 RecordStatusCallback()); |
609 MessageLoop::current()->RunUntilIdle(); | 609 MessageLoop::current()->RunUntilIdle(); |
610 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 610 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
611 EXPECT_TRUE(FileExists(dest_file_path)); | 611 EXPECT_TRUE(FileExists(dest_file_path)); |
612 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 612 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
613 | 613 |
614 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 614 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
615 EXPECT_TRUE(change_observer()->HasNoChange()); | 615 EXPECT_TRUE(change_observer()->HasNoChange()); |
616 } | 616 } |
617 | 617 |
618 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 618 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { |
619 FilePath src_dir_path(CreateUniqueDir()); | 619 base::FilePath src_dir_path(CreateUniqueDir()); |
620 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 620 base::FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
621 FilePath dest_dir_path(CreateUniqueDir()); | 621 base::FilePath dest_dir_path(CreateUniqueDir()); |
622 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 622 base::FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"
))); |
623 | 623 |
624 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 624 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
625 RecordStatusCallback()); | 625 RecordStatusCallback()); |
626 MessageLoop::current()->RunUntilIdle(); | 626 MessageLoop::current()->RunUntilIdle(); |
627 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 627 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
628 EXPECT_TRUE(FileExists(dest_file_path)); | 628 EXPECT_TRUE(FileExists(dest_file_path)); |
629 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 629 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
630 | 630 |
631 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 631 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
632 EXPECT_TRUE(change_observer()->HasNoChange()); | 632 EXPECT_TRUE(change_observer()->HasNoChange()); |
633 } | 633 } |
634 | 634 |
635 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 635 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
636 FilePath src_dir_path(CreateUniqueDir()); | 636 base::FilePath src_dir_path(CreateUniqueDir()); |
637 FilePath dest_dir_path(CreateUniqueDir()); | 637 base::FilePath dest_dir_path(CreateUniqueDir()); |
638 | 638 |
639 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 639 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
640 RecordStatusCallback()); | 640 RecordStatusCallback()); |
641 MessageLoop::current()->RunUntilIdle(); | 641 MessageLoop::current()->RunUntilIdle(); |
642 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 642 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
643 | 643 |
644 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 644 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
645 EXPECT_TRUE(DirectoryExists(dest_dir_path)); | 645 EXPECT_TRUE(DirectoryExists(dest_dir_path)); |
646 EXPECT_FALSE(DirectoryExists( | 646 EXPECT_FALSE(DirectoryExists( |
647 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); | 647 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
648 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 648 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
649 | 649 |
650 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 650 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
651 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 651 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
652 EXPECT_TRUE(change_observer()->HasNoChange()); | 652 EXPECT_TRUE(change_observer()->HasNoChange()); |
653 } | 653 } |
654 | 654 |
655 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 655 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
656 FilePath src_dir_path(CreateUniqueDir()); | 656 base::FilePath src_dir_path(CreateUniqueDir()); |
657 FilePath dest_parent_dir_path(CreateUniqueDir()); | 657 base::FilePath dest_parent_dir_path(CreateUniqueDir()); |
658 FilePath dest_child_dir_path(dest_parent_dir_path. | 658 base::FilePath dest_child_dir_path(dest_parent_dir_path. |
659 Append(FILE_PATH_LITERAL("NewDirectory"))); | 659 Append(FILE_PATH_LITERAL("NewDirectory"))); |
660 | 660 |
661 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 661 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
662 RecordStatusCallback()); | 662 RecordStatusCallback()); |
663 MessageLoop::current()->RunUntilIdle(); | 663 MessageLoop::current()->RunUntilIdle(); |
664 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 664 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
665 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); | 665 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); |
666 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 666 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
667 | 667 |
668 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 668 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
669 EXPECT_TRUE(change_observer()->HasNoChange()); | 669 EXPECT_TRUE(change_observer()->HasNoChange()); |
670 } | 670 } |
671 | 671 |
672 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 672 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
673 FilePath src_dir_path(CreateUniqueDir()); | 673 base::FilePath src_dir_path(CreateUniqueDir()); |
674 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); | 674 base::FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); |
675 FilePath grandchild_file_path( | 675 base::FilePath grandchild_file_path( |
676 CreateUniqueFileInDir(child_dir_path)); | 676 CreateUniqueFileInDir(child_dir_path)); |
677 | 677 |
678 FilePath dest_dir_path(CreateUniqueDir()); | 678 base::FilePath dest_dir_path(CreateUniqueDir()); |
679 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 679 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
680 RecordStatusCallback()); | 680 RecordStatusCallback()); |
681 MessageLoop::current()->RunUntilIdle(); | 681 MessageLoop::current()->RunUntilIdle(); |
682 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 682 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
683 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( | 683 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( |
684 VirtualPath::BaseName(child_dir_path)))); | 684 VirtualPath::BaseName(child_dir_path)))); |
685 EXPECT_TRUE(FileExists(dest_dir_path.Append( | 685 EXPECT_TRUE(FileExists(dest_dir_path.Append( |
686 VirtualPath::BaseName(child_dir_path)).Append( | 686 VirtualPath::BaseName(child_dir_path)).Append( |
687 VirtualPath::BaseName(grandchild_file_path)))); | 687 VirtualPath::BaseName(grandchild_file_path)))); |
688 | 688 |
689 // For recursive copy we may record multiple read access. | 689 // For recursive copy we may record multiple read access. |
690 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); | 690 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); |
691 | 691 |
692 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 692 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
693 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 693 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
694 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 694 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
695 EXPECT_TRUE(change_observer()->HasNoChange()); | 695 EXPECT_TRUE(change_observer()->HasNoChange()); |
696 } | 696 } |
697 | 697 |
698 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileSuccess) { | 698 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileSuccess) { |
699 FilePath src_local_disk_file_path; | 699 base::FilePath src_local_disk_file_path; |
700 file_util::CreateTemporaryFile(&src_local_disk_file_path); | 700 file_util::CreateTemporaryFile(&src_local_disk_file_path); |
701 const char test_data[] = "foo"; | 701 const char test_data[] = "foo"; |
702 int data_size = ARRAYSIZE_UNSAFE(test_data); | 702 int data_size = ARRAYSIZE_UNSAFE(test_data); |
703 file_util::WriteFile(src_local_disk_file_path, test_data, data_size); | 703 file_util::WriteFile(src_local_disk_file_path, test_data, data_size); |
704 FilePath dest_dir_path(CreateUniqueDir()); | 704 base::FilePath dest_dir_path(CreateUniqueDir()); |
705 FilePath dest_file_path(dest_dir_path.Append( | 705 base::FilePath dest_file_path(dest_dir_path.Append( |
706 src_local_disk_file_path.BaseName())); | 706 src_local_disk_file_path.BaseName())); |
707 FileSystemURL dest_file_url = URLForPath(dest_file_path); | 707 FileSystemURL dest_file_url = URLForPath(dest_file_path); |
708 int64 before_usage; | 708 int64 before_usage; |
709 GetUsageAndQuota(&before_usage, NULL); | 709 GetUsageAndQuota(&before_usage, NULL); |
710 | 710 |
711 // Check that the file copied and corresponding usage increased. | 711 // Check that the file copied and corresponding usage increased. |
712 operation()->CopyInForeignFile(src_local_disk_file_path, | 712 operation()->CopyInForeignFile(src_local_disk_file_path, |
713 dest_file_url, | 713 dest_file_url, |
714 RecordStatusCallback()); | 714 RecordStatusCallback()); |
715 MessageLoop::current()->RunUntilIdle(); | 715 MessageLoop::current()->RunUntilIdle(); |
716 EXPECT_EQ(1, change_observer()->create_file_count()); | 716 EXPECT_EQ(1, change_observer()->create_file_count()); |
717 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 717 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
718 EXPECT_TRUE(FileExists(dest_file_path)); | 718 EXPECT_TRUE(FileExists(dest_file_path)); |
719 int64 after_usage; | 719 int64 after_usage; |
720 GetUsageAndQuota(&after_usage, NULL); | 720 GetUsageAndQuota(&after_usage, NULL); |
721 EXPECT_GT(after_usage, before_usage); | 721 EXPECT_GT(after_usage, before_usage); |
722 | 722 |
723 // Compare contents of src and copied file. | 723 // Compare contents of src and copied file. |
724 char buffer[100]; | 724 char buffer[100]; |
725 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath(dest_file_path), | 725 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath(dest_file_path), |
726 buffer, data_size)); | 726 buffer, data_size)); |
727 for (int i = 0; i < data_size; ++i) | 727 for (int i = 0; i < data_size; ++i) |
728 EXPECT_EQ(test_data[i], buffer[i]); | 728 EXPECT_EQ(test_data[i], buffer[i]); |
729 } | 729 } |
730 | 730 |
731 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileFailureByQuota) { | 731 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileFailureByQuota) { |
732 FilePath src_local_disk_file_path; | 732 base::FilePath src_local_disk_file_path; |
733 file_util::CreateTemporaryFile(&src_local_disk_file_path); | 733 file_util::CreateTemporaryFile(&src_local_disk_file_path); |
734 const char test_data[] = "foo"; | 734 const char test_data[] = "foo"; |
735 file_util::WriteFile(src_local_disk_file_path, test_data, | 735 file_util::WriteFile(src_local_disk_file_path, test_data, |
736 ARRAYSIZE_UNSAFE(test_data)); | 736 ARRAYSIZE_UNSAFE(test_data)); |
737 | 737 |
738 FilePath dest_dir_path(CreateUniqueDir()); | 738 base::FilePath dest_dir_path(CreateUniqueDir()); |
739 FilePath dest_file_path(dest_dir_path.Append( | 739 base::FilePath dest_file_path(dest_dir_path.Append( |
740 src_local_disk_file_path.BaseName())); | 740 src_local_disk_file_path.BaseName())); |
741 FileSystemURL dest_file_url = URLForPath(dest_file_path); | 741 FileSystemURL dest_file_url = URLForPath(dest_file_path); |
742 | 742 |
743 // Set quota of 0 which should force copy to fail by quota. | 743 // Set quota of 0 which should force copy to fail by quota. |
744 quota_manager()->SetQuota(dest_file_url.origin(), | 744 quota_manager()->SetQuota(dest_file_url.origin(), |
745 test_helper_.storage_type(), | 745 test_helper_.storage_type(), |
746 static_cast<int64>(0)); | 746 static_cast<int64>(0)); |
747 operation()->CopyInForeignFile(src_local_disk_file_path, | 747 operation()->CopyInForeignFile(src_local_disk_file_path, |
748 dest_file_url, | 748 dest_file_url, |
749 RecordStatusCallback()); | 749 RecordStatusCallback()); |
750 MessageLoop::current()->RunUntilIdle(); | 750 MessageLoop::current()->RunUntilIdle(); |
751 | 751 |
752 EXPECT_TRUE(!FileExists(dest_file_path)); | 752 EXPECT_TRUE(!FileExists(dest_file_path)); |
753 EXPECT_EQ(0, change_observer()->create_file_count()); | 753 EXPECT_EQ(0, change_observer()->create_file_count()); |
754 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 754 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
755 } | 755 } |
756 | 756 |
757 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { | 757 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { |
758 // Already existing file and exclusive true. | 758 // Already existing file and exclusive true. |
759 FilePath dir_path(CreateUniqueDir()); | 759 base::FilePath dir_path(CreateUniqueDir()); |
760 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 760 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
761 operation()->CreateFile(URLForPath(file_path), true, | 761 operation()->CreateFile(URLForPath(file_path), true, |
762 RecordStatusCallback()); | 762 RecordStatusCallback()); |
763 MessageLoop::current()->RunUntilIdle(); | 763 MessageLoop::current()->RunUntilIdle(); |
764 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 764 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
765 EXPECT_TRUE(change_observer()->HasNoChange()); | 765 EXPECT_TRUE(change_observer()->HasNoChange()); |
766 } | 766 } |
767 | 767 |
768 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileExists) { | 768 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileExists) { |
769 // Already existing file and exclusive false. | 769 // Already existing file and exclusive false. |
770 FilePath dir_path(CreateUniqueDir()); | 770 base::FilePath dir_path(CreateUniqueDir()); |
771 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 771 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
772 operation()->CreateFile(URLForPath(file_path), false, | 772 operation()->CreateFile(URLForPath(file_path), false, |
773 RecordStatusCallback()); | 773 RecordStatusCallback()); |
774 MessageLoop::current()->RunUntilIdle(); | 774 MessageLoop::current()->RunUntilIdle(); |
775 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 775 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
776 EXPECT_TRUE(FileExists(file_path)); | 776 EXPECT_TRUE(FileExists(file_path)); |
777 | 777 |
778 // The file was already there; did nothing. | 778 // The file was already there; did nothing. |
779 EXPECT_TRUE(change_observer()->HasNoChange()); | 779 EXPECT_TRUE(change_observer()->HasNoChange()); |
780 } | 780 } |
781 | 781 |
782 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessExclusive) { | 782 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessExclusive) { |
783 // File doesn't exist but exclusive is true. | 783 // File doesn't exist but exclusive is true. |
784 FilePath dir_path(CreateUniqueDir()); | 784 base::FilePath dir_path(CreateUniqueDir()); |
785 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 785 base::FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))
); |
786 operation()->CreateFile(URLForPath(file_path), true, | 786 operation()->CreateFile(URLForPath(file_path), true, |
787 RecordStatusCallback()); | 787 RecordStatusCallback()); |
788 MessageLoop::current()->RunUntilIdle(); | 788 MessageLoop::current()->RunUntilIdle(); |
789 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 789 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
790 EXPECT_TRUE(FileExists(file_path)); | 790 EXPECT_TRUE(FileExists(file_path)); |
791 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 791 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
792 } | 792 } |
793 | 793 |
794 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { | 794 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { |
795 // Non existing file. | 795 // Non existing file. |
796 FilePath dir_path(CreateUniqueDir()); | 796 base::FilePath dir_path(CreateUniqueDir()); |
797 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 797 base::FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))
); |
798 operation()->CreateFile(URLForPath(file_path), false, | 798 operation()->CreateFile(URLForPath(file_path), false, |
799 RecordStatusCallback()); | 799 RecordStatusCallback()); |
800 MessageLoop::current()->RunUntilIdle(); | 800 MessageLoop::current()->RunUntilIdle(); |
801 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 801 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
802 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 802 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
803 } | 803 } |
804 | 804 |
805 TEST_F(LocalFileSystemOperationTest, | 805 TEST_F(LocalFileSystemOperationTest, |
806 TestCreateDirFailureDestParentDoesntExist) { | 806 TestCreateDirFailureDestParentDoesntExist) { |
807 // Dest. parent path does not exist. | 807 // Dest. parent path does not exist. |
808 FilePath nonexisting_path(FilePath( | 808 base::FilePath nonexisting_path(base::FilePath( |
809 FILE_PATH_LITERAL("DirDoesntExist"))); | 809 FILE_PATH_LITERAL("DirDoesntExist"))); |
810 FilePath nonexisting_file_path(nonexisting_path.Append( | 810 base::FilePath nonexisting_file_path(nonexisting_path.Append( |
811 FILE_PATH_LITERAL("FileDoesntExist"))); | 811 FILE_PATH_LITERAL("FileDoesntExist"))); |
812 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false, | 812 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false, |
813 RecordStatusCallback()); | 813 RecordStatusCallback()); |
814 MessageLoop::current()->RunUntilIdle(); | 814 MessageLoop::current()->RunUntilIdle(); |
815 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 815 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
816 EXPECT_TRUE(change_observer()->HasNoChange()); | 816 EXPECT_TRUE(change_observer()->HasNoChange()); |
817 } | 817 } |
818 | 818 |
819 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureDirExists) { | 819 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureDirExists) { |
820 // Exclusive and dir existing at path. | 820 // Exclusive and dir existing at path. |
821 FilePath src_dir_path(CreateUniqueDir()); | 821 base::FilePath src_dir_path(CreateUniqueDir()); |
822 operation()->CreateDirectory(URLForPath(src_dir_path), true, false, | 822 operation()->CreateDirectory(URLForPath(src_dir_path), true, false, |
823 RecordStatusCallback()); | 823 RecordStatusCallback()); |
824 MessageLoop::current()->RunUntilIdle(); | 824 MessageLoop::current()->RunUntilIdle(); |
825 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 825 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
826 EXPECT_TRUE(change_observer()->HasNoChange()); | 826 EXPECT_TRUE(change_observer()->HasNoChange()); |
827 } | 827 } |
828 | 828 |
829 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureFileExists) { | 829 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureFileExists) { |
830 // Exclusive true and file existing at path. | 830 // Exclusive true and file existing at path. |
831 FilePath dir_path(CreateUniqueDir()); | 831 base::FilePath dir_path(CreateUniqueDir()); |
832 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 832 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
833 operation()->CreateDirectory(URLForPath(file_path), true, false, | 833 operation()->CreateDirectory(URLForPath(file_path), true, false, |
834 RecordStatusCallback()); | 834 RecordStatusCallback()); |
835 MessageLoop::current()->RunUntilIdle(); | 835 MessageLoop::current()->RunUntilIdle(); |
836 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 836 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
837 EXPECT_TRUE(change_observer()->HasNoChange()); | 837 EXPECT_TRUE(change_observer()->HasNoChange()); |
838 } | 838 } |
839 | 839 |
840 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccess) { | 840 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccess) { |
841 // Dir exists and exclusive is false. | 841 // Dir exists and exclusive is false. |
842 FilePath dir_path(CreateUniqueDir()); | 842 base::FilePath dir_path(CreateUniqueDir()); |
843 operation()->CreateDirectory(URLForPath(dir_path), false, false, | 843 operation()->CreateDirectory(URLForPath(dir_path), false, false, |
844 RecordStatusCallback()); | 844 RecordStatusCallback()); |
845 MessageLoop::current()->RunUntilIdle(); | 845 MessageLoop::current()->RunUntilIdle(); |
846 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 846 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
847 EXPECT_TRUE(change_observer()->HasNoChange()); | 847 EXPECT_TRUE(change_observer()->HasNoChange()); |
848 | 848 |
849 // Dir doesn't exist. | 849 // Dir doesn't exist. |
850 FilePath nonexisting_dir_path(FilePath( | 850 base::FilePath nonexisting_dir_path(base::FilePath( |
851 FILE_PATH_LITERAL("nonexistingdir"))); | 851 FILE_PATH_LITERAL("nonexistingdir"))); |
852 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false, | 852 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false, |
853 RecordStatusCallback()); | 853 RecordStatusCallback()); |
854 MessageLoop::current()->RunUntilIdle(); | 854 MessageLoop::current()->RunUntilIdle(); |
855 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 855 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
856 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); | 856 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); |
857 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 857 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
858 } | 858 } |
859 | 859 |
860 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccessExclusive) { | 860 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccessExclusive) { |
861 // Dir doesn't exist. | 861 // Dir doesn't exist. |
862 FilePath nonexisting_dir_path(FilePath( | 862 base::FilePath nonexisting_dir_path(base::FilePath( |
863 FILE_PATH_LITERAL("nonexistingdir"))); | 863 FILE_PATH_LITERAL("nonexistingdir"))); |
864 | 864 |
865 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false, | 865 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false, |
866 RecordStatusCallback()); | 866 RecordStatusCallback()); |
867 MessageLoop::current()->RunUntilIdle(); | 867 MessageLoop::current()->RunUntilIdle(); |
868 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 868 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
869 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); | 869 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); |
870 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 870 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
871 EXPECT_TRUE(change_observer()->HasNoChange()); | 871 EXPECT_TRUE(change_observer()->HasNoChange()); |
872 } | 872 } |
873 | 873 |
874 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataFailure) { | 874 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataFailure) { |
875 FilePath nonexisting_dir_path(FilePath( | 875 base::FilePath nonexisting_dir_path(base::FilePath( |
876 FILE_PATH_LITERAL("nonexistingdir"))); | 876 FILE_PATH_LITERAL("nonexistingdir"))); |
877 operation()->GetMetadata(URLForPath(nonexisting_dir_path), | 877 operation()->GetMetadata(URLForPath(nonexisting_dir_path), |
878 RecordMetadataCallback()); | 878 RecordMetadataCallback()); |
879 MessageLoop::current()->RunUntilIdle(); | 879 MessageLoop::current()->RunUntilIdle(); |
880 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 880 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
881 | 881 |
882 operation()->FileExists(URLForPath(nonexisting_dir_path), | 882 operation()->FileExists(URLForPath(nonexisting_dir_path), |
883 RecordStatusCallback()); | 883 RecordStatusCallback()); |
884 MessageLoop::current()->RunUntilIdle(); | 884 MessageLoop::current()->RunUntilIdle(); |
885 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 885 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
886 | 886 |
887 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 887 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
888 operation()->DirectoryExists(URLForPath(nonexisting_dir_path), | 888 operation()->DirectoryExists(URLForPath(nonexisting_dir_path), |
889 RecordStatusCallback()); | 889 RecordStatusCallback()); |
890 MessageLoop::current()->RunUntilIdle(); | 890 MessageLoop::current()->RunUntilIdle(); |
891 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 891 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
892 EXPECT_TRUE(change_observer()->HasNoChange()); | 892 EXPECT_TRUE(change_observer()->HasNoChange()); |
893 } | 893 } |
894 | 894 |
895 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { | 895 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { |
896 FilePath dir_path(CreateUniqueDir()); | 896 base::FilePath dir_path(CreateUniqueDir()); |
897 int read_access = 0; | 897 int read_access = 0; |
898 | 898 |
899 operation()->DirectoryExists(URLForPath(dir_path), | 899 operation()->DirectoryExists(URLForPath(dir_path), |
900 RecordStatusCallback()); | 900 RecordStatusCallback()); |
901 MessageLoop::current()->RunUntilIdle(); | 901 MessageLoop::current()->RunUntilIdle(); |
902 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 902 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
903 ++read_access; | 903 ++read_access; |
904 | 904 |
905 operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback()); | 905 operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback()); |
906 MessageLoop::current()->RunUntilIdle(); | 906 MessageLoop::current()->RunUntilIdle(); |
907 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 907 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
908 EXPECT_TRUE(info().is_directory); | 908 EXPECT_TRUE(info().is_directory); |
909 EXPECT_EQ(FilePath(), path()); | 909 EXPECT_EQ(base::FilePath(), path()); |
910 ++read_access; | 910 ++read_access; |
911 | 911 |
912 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 912 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
913 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); | 913 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); |
914 MessageLoop::current()->RunUntilIdle(); | 914 MessageLoop::current()->RunUntilIdle(); |
915 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 915 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
916 ++read_access; | 916 ++read_access; |
917 | 917 |
918 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); | 918 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); |
919 MessageLoop::current()->RunUntilIdle(); | 919 MessageLoop::current()->RunUntilIdle(); |
920 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 920 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
921 EXPECT_FALSE(info().is_directory); | 921 EXPECT_FALSE(info().is_directory); |
922 EXPECT_EQ(PlatformPath(file_path), path()); | 922 EXPECT_EQ(PlatformPath(file_path), path()); |
923 ++read_access; | 923 ++read_access; |
924 | 924 |
925 EXPECT_EQ(read_access, | 925 EXPECT_EQ(read_access, |
926 quota_manager_proxy()->notify_storage_accessed_count()); | 926 quota_manager_proxy()->notify_storage_accessed_count()); |
927 EXPECT_TRUE(change_observer()->HasNoChange()); | 927 EXPECT_TRUE(change_observer()->HasNoChange()); |
928 } | 928 } |
929 | 929 |
930 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { | 930 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { |
931 FilePath dir_path(CreateUniqueDir()); | 931 base::FilePath dir_path(CreateUniqueDir()); |
932 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); | 932 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); |
933 MessageLoop::current()->RunUntilIdle(); | 933 MessageLoop::current()->RunUntilIdle(); |
934 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 934 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
935 | 935 |
936 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 936 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
937 ASSERT_FALSE(file_path.empty()); | 937 ASSERT_FALSE(file_path.empty()); |
938 operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback()); | 938 operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback()); |
939 MessageLoop::current()->RunUntilIdle(); | 939 MessageLoop::current()->RunUntilIdle(); |
940 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 940 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
941 } | 941 } |
942 | 942 |
943 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { | 943 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { |
944 // Path doesn't exist | 944 // Path doesn't exist |
945 FilePath nonexisting_dir_path(FilePath( | 945 base::FilePath nonexisting_dir_path(base::FilePath( |
946 FILE_PATH_LITERAL("NonExistingDir"))); | 946 FILE_PATH_LITERAL("NonExistingDir"))); |
947 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 947 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
948 operation()->ReadDirectory(URLForPath(nonexisting_dir_path), | 948 operation()->ReadDirectory(URLForPath(nonexisting_dir_path), |
949 RecordReadDirectoryCallback()); | 949 RecordReadDirectoryCallback()); |
950 MessageLoop::current()->RunUntilIdle(); | 950 MessageLoop::current()->RunUntilIdle(); |
951 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 951 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
952 | 952 |
953 // File exists. | 953 // File exists. |
954 FilePath dir_path(CreateUniqueDir()); | 954 base::FilePath dir_path(CreateUniqueDir()); |
955 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 955 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
956 operation()->ReadDirectory(URLForPath(file_path), | 956 operation()->ReadDirectory(URLForPath(file_path), |
957 RecordReadDirectoryCallback()); | 957 RecordReadDirectoryCallback()); |
958 MessageLoop::current()->RunUntilIdle(); | 958 MessageLoop::current()->RunUntilIdle(); |
959 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 959 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
960 EXPECT_TRUE(change_observer()->HasNoChange()); | 960 EXPECT_TRUE(change_observer()->HasNoChange()); |
961 } | 961 } |
962 | 962 |
963 TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) { | 963 TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) { |
964 // parent_dir | 964 // parent_dir |
965 // | | | 965 // | | |
966 // child_dir child_file | 966 // child_dir child_file |
967 // Verify reading parent_dir. | 967 // Verify reading parent_dir. |
968 FilePath parent_dir_path(CreateUniqueDir()); | 968 base::FilePath parent_dir_path(CreateUniqueDir()); |
969 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 969 base::FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
970 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 970 base::FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
971 ASSERT_FALSE(child_dir_path.empty()); | 971 ASSERT_FALSE(child_dir_path.empty()); |
972 | 972 |
973 operation()->ReadDirectory(URLForPath(parent_dir_path), | 973 operation()->ReadDirectory(URLForPath(parent_dir_path), |
974 RecordReadDirectoryCallback()); | 974 RecordReadDirectoryCallback()); |
975 MessageLoop::current()->RunUntilIdle(); | 975 MessageLoop::current()->RunUntilIdle(); |
976 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 976 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
977 EXPECT_EQ(2u, entries().size()); | 977 EXPECT_EQ(2u, entries().size()); |
978 | 978 |
979 for (size_t i = 0; i < entries().size(); ++i) { | 979 for (size_t i = 0; i < entries().size(); ++i) { |
980 if (entries()[i].is_directory) { | 980 if (entries()[i].is_directory) { |
981 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), | 981 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), |
982 entries()[i].name); | 982 entries()[i].name); |
983 } else { | 983 } else { |
984 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), | 984 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), |
985 entries()[i].name); | 985 entries()[i].name); |
986 } | 986 } |
987 } | 987 } |
988 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 988 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
989 EXPECT_TRUE(change_observer()->HasNoChange()); | 989 EXPECT_TRUE(change_observer()->HasNoChange()); |
990 } | 990 } |
991 | 991 |
992 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { | 992 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { |
993 // Path doesn't exist. | 993 // Path doesn't exist. |
994 FilePath nonexisting_path(FilePath( | 994 base::FilePath nonexisting_path(base::FilePath( |
995 FILE_PATH_LITERAL("NonExistingDir"))); | 995 FILE_PATH_LITERAL("NonExistingDir"))); |
996 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 996 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
997 | 997 |
998 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, | 998 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, |
999 RecordStatusCallback()); | 999 RecordStatusCallback()); |
1000 MessageLoop::current()->RunUntilIdle(); | 1000 MessageLoop::current()->RunUntilIdle(); |
1001 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 1001 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
1002 | 1002 |
1003 // It's an error to try to remove a non-empty directory if recursive flag | 1003 // It's an error to try to remove a non-empty directory if recursive flag |
1004 // is false. | 1004 // is false. |
1005 // parent_dir | 1005 // parent_dir |
1006 // | | | 1006 // | | |
1007 // child_dir child_file | 1007 // child_dir child_file |
1008 // Verify deleting parent_dir. | 1008 // Verify deleting parent_dir. |
1009 FilePath parent_dir_path(CreateUniqueDir()); | 1009 base::FilePath parent_dir_path(CreateUniqueDir()); |
1010 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 1010 base::FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
1011 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 1011 base::FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
1012 ASSERT_FALSE(child_dir_path.empty()); | 1012 ASSERT_FALSE(child_dir_path.empty()); |
1013 | 1013 |
1014 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */, | 1014 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */, |
1015 RecordStatusCallback()); | 1015 RecordStatusCallback()); |
1016 MessageLoop::current()->RunUntilIdle(); | 1016 MessageLoop::current()->RunUntilIdle(); |
1017 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 1017 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
1018 status()); | 1018 status()); |
1019 EXPECT_TRUE(change_observer()->HasNoChange()); | 1019 EXPECT_TRUE(change_observer()->HasNoChange()); |
1020 } | 1020 } |
1021 | 1021 |
1022 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) { | 1022 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) { |
1023 FilePath empty_dir_path(CreateUniqueDir()); | 1023 base::FilePath empty_dir_path(CreateUniqueDir()); |
1024 EXPECT_TRUE(DirectoryExists(empty_dir_path)); | 1024 EXPECT_TRUE(DirectoryExists(empty_dir_path)); |
1025 | 1025 |
1026 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */, | 1026 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */, |
1027 RecordStatusCallback()); | 1027 RecordStatusCallback()); |
1028 MessageLoop::current()->RunUntilIdle(); | 1028 MessageLoop::current()->RunUntilIdle(); |
1029 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1029 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1030 EXPECT_FALSE(DirectoryExists(empty_dir_path)); | 1030 EXPECT_FALSE(DirectoryExists(empty_dir_path)); |
1031 | 1031 |
1032 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 1032 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
1033 EXPECT_TRUE(change_observer()->HasNoChange()); | 1033 EXPECT_TRUE(change_observer()->HasNoChange()); |
1034 | 1034 |
1035 // Removing a non-empty directory with recursive flag == true should be ok. | 1035 // Removing a non-empty directory with recursive flag == true should be ok. |
1036 // parent_dir | 1036 // parent_dir |
1037 // | | | 1037 // | | |
1038 // child_dir child_file | 1038 // child_dir child_file |
1039 // Verify deleting parent_dir. | 1039 // Verify deleting parent_dir. |
1040 FilePath parent_dir_path(CreateUniqueDir()); | 1040 base::FilePath parent_dir_path(CreateUniqueDir()); |
1041 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 1041 base::FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
1042 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 1042 base::FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
1043 ASSERT_FALSE(child_dir_path.empty()); | 1043 ASSERT_FALSE(child_dir_path.empty()); |
1044 | 1044 |
1045 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, | 1045 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, |
1046 RecordStatusCallback()); | 1046 RecordStatusCallback()); |
1047 MessageLoop::current()->RunUntilIdle(); | 1047 MessageLoop::current()->RunUntilIdle(); |
1048 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1048 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1049 EXPECT_FALSE(DirectoryExists(parent_dir_path)); | 1049 EXPECT_FALSE(DirectoryExists(parent_dir_path)); |
1050 | 1050 |
1051 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 1051 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
1052 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 1052 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
1053 EXPECT_TRUE(change_observer()->HasNoChange()); | 1053 EXPECT_TRUE(change_observer()->HasNoChange()); |
1054 } | 1054 } |
1055 | 1055 |
1056 TEST_F(LocalFileSystemOperationTest, TestTruncate) { | 1056 TEST_F(LocalFileSystemOperationTest, TestTruncate) { |
1057 FilePath dir_path(CreateUniqueDir()); | 1057 base::FilePath dir_path(CreateUniqueDir()); |
1058 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1058 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1059 | 1059 |
1060 char test_data[] = "test data"; | 1060 char test_data[] = "test data"; |
1061 int data_size = static_cast<int>(sizeof(test_data)); | 1061 int data_size = static_cast<int>(sizeof(test_data)); |
1062 EXPECT_EQ(data_size, | 1062 EXPECT_EQ(data_size, |
1063 file_util::WriteFile(PlatformPath(file_path), | 1063 file_util::WriteFile(PlatformPath(file_path), |
1064 test_data, data_size)); | 1064 test_data, data_size)); |
1065 | 1065 |
1066 // Check that its length is the size of the data written. | 1066 // Check that its length is the size of the data written. |
1067 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); | 1067 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); |
1068 MessageLoop::current()->RunUntilIdle(); | 1068 MessageLoop::current()->RunUntilIdle(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 EXPECT_EQ(test_data[i], data[i]); | 1111 EXPECT_EQ(test_data[i], data[i]); |
1112 | 1112 |
1113 // Truncate is not a 'read' access. (Here expected access count is 1 | 1113 // Truncate is not a 'read' access. (Here expected access count is 1 |
1114 // since we made 1 read access for GetMetadata.) | 1114 // since we made 1 read access for GetMetadata.) |
1115 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 1115 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
1116 } | 1116 } |
1117 | 1117 |
1118 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { | 1118 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { |
1119 base::PlatformFileInfo info; | 1119 base::PlatformFileInfo info; |
1120 | 1120 |
1121 FilePath dir_path(CreateUniqueDir()); | 1121 base::FilePath dir_path(CreateUniqueDir()); |
1122 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1122 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1123 | 1123 |
1124 GrantQuotaForCurrentUsage(); | 1124 GrantQuotaForCurrentUsage(); |
1125 AddQuota(10); | 1125 AddQuota(10); |
1126 | 1126 |
1127 operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback()); | 1127 operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback()); |
1128 MessageLoop::current()->RunUntilIdle(); | 1128 MessageLoop::current()->RunUntilIdle(); |
1129 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1129 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1130 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1130 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1131 EXPECT_TRUE(change_observer()->HasNoChange()); | 1131 EXPECT_TRUE(change_observer()->HasNoChange()); |
1132 | 1132 |
1133 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1133 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1134 EXPECT_EQ(10, info.size); | 1134 EXPECT_EQ(10, info.size); |
1135 | 1135 |
1136 operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback()); | 1136 operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback()); |
1137 MessageLoop::current()->RunUntilIdle(); | 1137 MessageLoop::current()->RunUntilIdle(); |
1138 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 1138 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
1139 EXPECT_TRUE(change_observer()->HasNoChange()); | 1139 EXPECT_TRUE(change_observer()->HasNoChange()); |
1140 | 1140 |
1141 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1141 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1142 EXPECT_EQ(10, info.size); | 1142 EXPECT_EQ(10, info.size); |
1143 } | 1143 } |
1144 | 1144 |
1145 TEST_F(LocalFileSystemOperationTest, TestTouchFile) { | 1145 TEST_F(LocalFileSystemOperationTest, TestTouchFile) { |
1146 FilePath file_path(CreateUniqueFileInDir(FilePath())); | 1146 base::FilePath file_path(CreateUniqueFileInDir(base::FilePath())); |
1147 FilePath platform_path = PlatformPath(file_path); | 1147 base::FilePath platform_path = PlatformPath(file_path); |
1148 | 1148 |
1149 base::PlatformFileInfo info; | 1149 base::PlatformFileInfo info; |
1150 | 1150 |
1151 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1151 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
1152 EXPECT_FALSE(info.is_directory); | 1152 EXPECT_FALSE(info.is_directory); |
1153 EXPECT_EQ(0, info.size); | 1153 EXPECT_EQ(0, info.size); |
1154 const base::Time last_modified = info.last_modified; | 1154 const base::Time last_modified = info.last_modified; |
1155 const base::Time last_accessed = info.last_accessed; | 1155 const base::Time last_accessed = info.last_accessed; |
1156 | 1156 |
1157 const base::Time new_modified_time = base::Time::UnixEpoch(); | 1157 const base::Time new_modified_time = base::Time::UnixEpoch(); |
(...skipping 11 matching lines...) Expand all Loading... |
1169 | 1169 |
1170 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1170 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
1171 // We compare as time_t here to lower our resolution, to avoid false | 1171 // We compare as time_t here to lower our resolution, to avoid false |
1172 // negatives caused by conversion to the local filesystem's native | 1172 // negatives caused by conversion to the local filesystem's native |
1173 // representation and back. | 1173 // representation and back. |
1174 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1174 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
1175 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1175 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
1176 } | 1176 } |
1177 | 1177 |
1178 TEST_F(LocalFileSystemOperationTest, TestCreateSnapshotFile) { | 1178 TEST_F(LocalFileSystemOperationTest, TestCreateSnapshotFile) { |
1179 FilePath dir_path(CreateUniqueDir()); | 1179 base::FilePath dir_path(CreateUniqueDir()); |
1180 | 1180 |
1181 // Create a file for the testing. | 1181 // Create a file for the testing. |
1182 operation()->DirectoryExists(URLForPath(dir_path), | 1182 operation()->DirectoryExists(URLForPath(dir_path), |
1183 RecordStatusCallback()); | 1183 RecordStatusCallback()); |
1184 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1184 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1185 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); | 1185 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); |
1186 MessageLoop::current()->RunUntilIdle(); | 1186 MessageLoop::current()->RunUntilIdle(); |
1187 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1187 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1188 | 1188 |
1189 // See if we can get a 'snapshot' file info for the file. | 1189 // See if we can get a 'snapshot' file info for the file. |
1190 // Since LocalFileSystemOperation assumes the file exists in the local | 1190 // Since LocalFileSystemOperation assumes the file exists in the local |
1191 // directory it should just returns the same metadata and platform_path | 1191 // directory it should just returns the same metadata and platform_path |
1192 // as the file itself. | 1192 // as the file itself. |
1193 operation()->CreateSnapshotFile(URLForPath(file_path), | 1193 operation()->CreateSnapshotFile(URLForPath(file_path), |
1194 RecordSnapshotFileCallback()); | 1194 RecordSnapshotFileCallback()); |
1195 MessageLoop::current()->RunUntilIdle(); | 1195 MessageLoop::current()->RunUntilIdle(); |
1196 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1196 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1197 EXPECT_FALSE(info().is_directory); | 1197 EXPECT_FALSE(info().is_directory); |
1198 EXPECT_EQ(PlatformPath(file_path), path()); | 1198 EXPECT_EQ(PlatformPath(file_path), path()); |
1199 EXPECT_TRUE(change_observer()->HasNoChange()); | 1199 EXPECT_TRUE(change_observer()->HasNoChange()); |
1200 | 1200 |
1201 // The FileSystemOpration implementation does not create a | 1201 // The FileSystemOpration implementation does not create a |
1202 // shareable file reference. | 1202 // shareable file reference. |
1203 EXPECT_EQ(NULL, shareable_file_ref()); | 1203 EXPECT_EQ(NULL, shareable_file_ref()); |
1204 } | 1204 } |
1205 | 1205 |
1206 } // namespace fileapi | 1206 } // namespace fileapi |
OLD | NEW |