| 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" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 FileSystemTestOriginHelper test_helper_; | 242 FileSystemTestOriginHelper test_helper_; |
| 243 | 243 |
| 244 // For post-operation status. | 244 // For post-operation status. |
| 245 int status_; | 245 int status_; |
| 246 base::PlatformFileInfo info_; | 246 base::PlatformFileInfo info_; |
| 247 FilePath path_; | 247 FilePath path_; |
| 248 std::vector<base::FileUtilProxy::Entry> entries_; | 248 std::vector<base::FileUtilProxy::Entry> entries_; |
| 249 | 249 |
| 250 private: | 250 private: |
| 251 scoped_ptr<LocalFileSystemFileUtil> local_file_util_; |
| 251 scoped_refptr<QuotaManager> quota_manager_; | 252 scoped_refptr<QuotaManager> quota_manager_; |
| 252 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 253 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
| 253 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 254 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
| 254 }; | 255 }; |
| 255 | 256 |
| 256 namespace { | 257 namespace { |
| 257 | 258 |
| 258 class MockDispatcher : public FileSystemCallbackDispatcher { | 259 class MockDispatcher : public FileSystemCallbackDispatcher { |
| 259 public: | 260 public: |
| 260 explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { } | 261 explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 290 } | 291 } |
| 291 | 292 |
| 292 private: | 293 private: |
| 293 FileSystemOperationTest* test_; | 294 FileSystemOperationTest* test_; |
| 294 }; | 295 }; |
| 295 | 296 |
| 296 } // namespace (anonymous) | 297 } // namespace (anonymous) |
| 297 | 298 |
| 298 void FileSystemOperationTest::SetUp() { | 299 void FileSystemOperationTest::SetUp() { |
| 299 FilePath base_dir = base_.path().AppendASCII("filesystem"); | 300 FilePath base_dir = base_.path().AppendASCII("filesystem"); |
| 301 local_file_util_.reset( |
| 302 new LocalFileSystemFileUtil(QuotaFileUtil::GetInstance())); |
| 300 quota_manager_ = new MockQuotaManager( | 303 quota_manager_ = new MockQuotaManager( |
| 301 base_dir, test_helper_.origin(), test_helper_.storage_type()); | 304 base_dir, test_helper_.origin(), test_helper_.storage_type()); |
| 302 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); | 305 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); |
| 303 test_helper_.SetUp(base_dir, | 306 test_helper_.SetUp(base_dir, |
| 304 false /* incognito */, | 307 false /* incognito */, |
| 305 false /* unlimited quota */, | 308 false /* unlimited quota */, |
| 306 quota_manager_proxy_.get(), | 309 quota_manager_proxy_.get(), |
| 307 LocalFileSystemFileUtil::GetInstance()); | 310 local_file_util_.get()); |
| 308 } | 311 } |
| 309 | 312 |
| 310 void FileSystemOperationTest::TearDown() { | 313 void FileSystemOperationTest::TearDown() { |
| 311 // Let the client go away before dropping a ref of the quota manager proxy. | 314 // Let the client go away before dropping a ref of the quota manager proxy. |
| 312 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 315 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
| 313 quota_manager_ = NULL; | 316 quota_manager_ = NULL; |
| 314 quota_manager_proxy_ = NULL; | 317 quota_manager_proxy_ = NULL; |
| 315 test_helper_.TearDown(); | 318 test_helper_.TearDown(); |
| 319 local_file_util_.reset(); |
| 316 } | 320 } |
| 317 | 321 |
| 318 FileSystemOperation* FileSystemOperationTest::operation() { | 322 FileSystemOperation* FileSystemOperationTest::operation() { |
| 319 return test_helper_.NewOperation(new MockDispatcher(this)); | 323 return test_helper_.NewOperation(new MockDispatcher(this)); |
| 320 } | 324 } |
| 321 | 325 |
| 322 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 326 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
| 323 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); | 327 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); |
| 324 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 328 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); |
| 325 operation()->Move(src, dest); | 329 operation()->Move(src, dest); |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 | 951 |
| 948 operation()->Truncate(URLForPath(file_path), 11); | 952 operation()->Truncate(URLForPath(file_path), 11); |
| 949 MessageLoop::current()->RunAllPending(); | 953 MessageLoop::current()->RunAllPending(); |
| 950 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 954 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 951 | 955 |
| 952 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 956 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
| 953 EXPECT_EQ(10, info.size); | 957 EXPECT_EQ(10, info.size); |
| 954 } | 958 } |
| 955 | 959 |
| 956 } // namespace fileapi | 960 } // namespace fileapi |
| OLD | NEW |