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/quota_file_util.h" | 5 #include "webkit/fileapi/quota_file_util.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 public: | 25 public: |
26 QuotaFileUtilTest() | 26 QuotaFileUtilTest() |
27 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 27 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
28 } | 28 } |
29 | 29 |
30 void SetUp() { | 30 void SetUp() { |
31 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
32 FilePath base_dir = data_dir_.path().AppendASCII("filesystem"); | 32 FilePath base_dir = data_dir_.path().AppendASCII("filesystem"); |
33 | 33 |
34 // For path translation we rely on LocalFileSystemFileUtil::GetLocalPath(). | 34 // For path translation we rely on LocalFileSystemFileUtil::GetLocalPath(). |
35 test_helper_.SetUp(base_dir, LocalFileSystemFileUtil::GetInstance()); | 35 local_test_helper_.SetUp(base_dir, LocalFileSystemFileUtil::GetInstance()); |
| 36 quota_test_helper_.SetUp(base_dir, QuotaFileUtil::GetInstance()); |
36 } | 37 } |
37 | 38 |
38 void TearDown() { | 39 void TearDown() { |
39 test_helper_.TearDown(); | 40 local_test_helper_.TearDown(); |
| 41 quota_test_helper_.TearDown(); |
40 } | 42 } |
41 | 43 |
42 protected: | 44 protected: |
43 FileSystemOperationContext* NewContext() { | 45 FileSystemOperationContext* NewContext() { |
44 return test_helper_.NewOperationContext(); | 46 return quota_test_helper_.NewOperationContext(); |
45 } | |
46 | |
47 QuotaFileUtil* FileUtil() { | |
48 return QuotaFileUtil::GetInstance(); | |
49 } | 47 } |
50 | 48 |
51 FilePath Path(const std::string& file_name) { | 49 FilePath Path(const std::string& file_name) { |
52 return test_helper_.GetLocalPathFromASCII(file_name); | 50 return local_test_helper_.GetLocalPathFromASCII(file_name); |
53 } | 51 } |
54 | 52 |
55 base::PlatformFileError CreateFile(const char* file_name, | 53 base::PlatformFileError CreateFile(const char* file_name, |
56 base::PlatformFile* file_handle, bool* created) { | 54 base::PlatformFile* file_handle, bool* created) { |
57 int file_flags = base::PLATFORM_FILE_CREATE | | 55 int file_flags = base::PLATFORM_FILE_CREATE | |
58 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; | 56 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; |
59 | 57 |
60 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 58 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
61 return FileUtil()->CreateOrOpen(context.get(), Path(file_name), | 59 return QuotaFileUtil::GetInstance()->CreateOrOpen( |
62 file_flags, file_handle, created); | 60 context.get(), Path(file_name), file_flags, file_handle, created); |
63 } | 61 } |
64 | 62 |
65 base::PlatformFileError EnsureFileExists(const char* file_name, | 63 base::PlatformFileError EnsureFileExists(const char* file_name, |
66 bool* created) { | 64 bool* created) { |
67 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 65 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
68 return FileUtil()->EnsureFileExists(context.get(), | 66 return QuotaFileUtil::GetInstance()->EnsureFileExists( |
69 Path(file_name), created); | 67 context.get(), Path(file_name), created); |
70 } | 68 } |
71 | 69 |
72 int64 GetCachedUsage() { | 70 int64 GetCachedUsage() { |
73 return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); | 71 return FileSystemUsageCache::GetUsage( |
74 } | 72 quota_test_helper_.GetUsageCachePath()); |
75 | |
76 FileSystemContext* file_system_context() const { | |
77 return test_helper_.file_system_context(); | |
78 } | 73 } |
79 | 74 |
80 private: | 75 private: |
81 ScopedTempDir data_dir_; | 76 ScopedTempDir data_dir_; |
82 FileSystemTestOriginHelper test_helper_; | 77 FileSystemTestOriginHelper local_test_helper_; |
| 78 FileSystemTestOriginHelper quota_test_helper_; |
83 base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_; | 79 base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_; |
84 | 80 |
85 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest); | 81 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest); |
86 }; | 82 }; |
87 | 83 |
88 TEST_F(QuotaFileUtilTest, CreateAndClose) { | 84 TEST_F(QuotaFileUtilTest, CreateAndClose) { |
89 const char *file_name = "test_file"; | 85 const char *file_name = "test_file"; |
90 base::PlatformFile file_handle; | 86 base::PlatformFile file_handle; |
91 bool created; | 87 bool created; |
92 ASSERT_EQ(base::PLATFORM_FILE_OK, | 88 ASSERT_EQ(base::PLATFORM_FILE_OK, |
93 CreateFile(file_name, &file_handle, &created)); | 89 CreateFile(file_name, &file_handle, &created)); |
94 ASSERT_TRUE(created); | 90 ASSERT_TRUE(created); |
95 | 91 |
96 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 92 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
97 EXPECT_EQ(base::PLATFORM_FILE_OK, | 93 EXPECT_EQ(base::PLATFORM_FILE_OK, |
98 FileUtil()->Close(context.get(), file_handle)); | 94 QuotaFileUtil::GetInstance()->Close(context.get(), file_handle)); |
99 } | 95 } |
100 | 96 |
101 TEST_F(QuotaFileUtilTest, EnsureFileExists) { | 97 TEST_F(QuotaFileUtilTest, EnsureFileExists) { |
102 const char *file_name = "foobar"; | 98 const char *file_name = "foobar"; |
103 bool created; | 99 bool created; |
104 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); | 100 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); |
105 ASSERT_TRUE(created); | 101 ASSERT_TRUE(created); |
106 | 102 |
107 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); | 103 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); |
108 EXPECT_FALSE(created); | 104 EXPECT_FALSE(created); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 context.reset(NewContext()); | 399 context.reset(NewContext()); |
404 context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit); | 400 context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit); |
405 ASSERT_EQ(base::PLATFORM_FILE_OK, | 401 ASSERT_EQ(base::PLATFORM_FILE_OK, |
406 QuotaFileUtil::GetInstance()->Delete(context.get(), | 402 QuotaFileUtil::GetInstance()->Delete(context.get(), |
407 Path(dir), | 403 Path(dir), |
408 true)); | 404 true)); |
409 ASSERT_EQ(0, GetCachedUsage()); | 405 ASSERT_EQ(0, GetCachedUsage()); |
410 } | 406 } |
411 | 407 |
412 } // namespace fileapi | 408 } // namespace fileapi |
OLD | NEW |