OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 quota_status_(storage::kQuotaStatusUnknown), | 158 quota_status_(storage::kQuotaStatusUnknown), |
159 usage_(-1), | 159 usage_(-1), |
160 weak_factory_(this) {} | 160 weak_factory_(this) {} |
161 | 161 |
162 void SetUp() override { | 162 void SetUp() override { |
163 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 163 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
164 | 164 |
165 storage_policy_ = new MockSpecialStoragePolicy(); | 165 storage_policy_ = new MockSpecialStoragePolicy(); |
166 | 166 |
167 quota_manager_ = new storage::QuotaManager( | 167 quota_manager_ = new storage::QuotaManager( |
168 false /* is_incognito */, data_dir_.path(), | 168 false /* is_incognito */, data_dir_.GetPath(), |
169 base::ThreadTaskRunnerHandle::Get().get(), | 169 base::ThreadTaskRunnerHandle::Get().get(), |
170 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get()); | 170 base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get()); |
171 | 171 |
172 // Every time we create a new sandbox_file_system helper, | 172 // Every time we create a new sandbox_file_system helper, |
173 // it creates another context, which creates another path manager, | 173 // it creates another context, which creates another path manager, |
174 // another sandbox_backend, and another OFU. | 174 // another sandbox_backend, and another OFU. |
175 // We need to pass in the context to skip all that. | 175 // We need to pass in the context to skip all that. |
176 file_system_context_ = CreateFileSystemContextForTesting( | 176 file_system_context_ = CreateFileSystemContextForTesting( |
177 quota_manager_->proxy(), | 177 quota_manager_->proxy(), data_dir_.GetPath()); |
178 data_dir_.path()); | |
179 | 178 |
180 sandbox_file_system_.SetUp(file_system_context_.get()); | 179 sandbox_file_system_.SetUp(file_system_context_.get()); |
181 | 180 |
182 change_observers_ = | 181 change_observers_ = |
183 storage::MockFileChangeObserver::CreateList(&change_observer_); | 182 storage::MockFileChangeObserver::CreateList(&change_observer_); |
184 } | 183 } |
185 | 184 |
186 void TearDown() override { | 185 void TearDown() override { |
187 quota_manager_ = NULL; | 186 quota_manager_ = NULL; |
188 sandbox_file_system_.TearDown(); | 187 sandbox_file_system_.TearDown(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return std::unique_ptr<ObfuscatedFileUtil>( | 239 return std::unique_ptr<ObfuscatedFileUtil>( |
241 ObfuscatedFileUtil::CreateForTesting( | 240 ObfuscatedFileUtil::CreateForTesting( |
242 storage_policy, data_dir_path(), NULL, | 241 storage_policy, data_dir_path(), NULL, |
243 base::ThreadTaskRunnerHandle::Get().get())); | 242 base::ThreadTaskRunnerHandle::Get().get())); |
244 } | 243 } |
245 | 244 |
246 ObfuscatedFileUtil* ofu() { | 245 ObfuscatedFileUtil* ofu() { |
247 return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util()); | 246 return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util()); |
248 } | 247 } |
249 | 248 |
250 const base::FilePath& test_directory() const { | 249 const base::FilePath& test_directory() const { return data_dir_.GetPath(); } |
251 return data_dir_.path(); | |
252 } | |
253 | 250 |
254 const GURL& origin() const { | 251 const GURL& origin() const { |
255 return origin_; | 252 return origin_; |
256 } | 253 } |
257 | 254 |
258 storage::FileSystemType type() const { return type_; } | 255 storage::FileSystemType type() const { return type_; } |
259 | 256 |
260 std::string type_string() const { | 257 std::string type_string() const { |
261 return GetTypeString(type_); | 258 return GetTypeString(type_); |
262 } | 259 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 EXPECT_EQ(base::File::FILE_OK, | 541 EXPECT_EQ(base::File::FILE_OK, |
545 ofu()->GetFileInfo(context.get(), url, &file_info, &local_path)); | 542 ofu()->GetFileInfo(context.get(), url, &file_info, &local_path)); |
546 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 543 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
547 if (is_file) // Directories in OFU don't support atime. | 544 if (is_file) // Directories in OFU don't support atime. |
548 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); | 545 EXPECT_EQ(file_info.last_accessed.ToTimeT(), last_access_time.ToTimeT()); |
549 } | 546 } |
550 | 547 |
551 void TestCopyInForeignFileHelper(bool overwrite) { | 548 void TestCopyInForeignFileHelper(bool overwrite) { |
552 base::ScopedTempDir source_dir; | 549 base::ScopedTempDir source_dir; |
553 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 550 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
554 base::FilePath root_file_path = source_dir.path(); | 551 base::FilePath root_file_path = source_dir.GetPath(); |
555 base::FilePath src_file_path = root_file_path.AppendASCII("file_name"); | 552 base::FilePath src_file_path = root_file_path.AppendASCII("file_name"); |
556 FileSystemURL dest_url = CreateURLFromUTF8("new file"); | 553 FileSystemURL dest_url = CreateURLFromUTF8("new file"); |
557 int64_t src_file_length = 87; | 554 int64_t src_file_length = 87; |
558 | 555 |
559 base::File file(src_file_path, | 556 base::File file(src_file_path, |
560 base::File::FLAG_CREATE | base::File::FLAG_WRITE); | 557 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
561 ASSERT_TRUE(file.IsValid()); | 558 ASSERT_TRUE(file.IsValid()); |
562 EXPECT_TRUE(file.created()); | 559 EXPECT_TRUE(file.created()); |
563 ASSERT_TRUE(file.SetLength(src_file_length)); | 560 ASSERT_TRUE(file.SetLength(src_file_length)); |
564 file.Close(); | 561 file.Close(); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 | 790 |
794 int64_t ComputeCurrentUsage() { | 791 int64_t ComputeCurrentUsage() { |
795 return sandbox_file_system_.ComputeCurrentOriginUsage() - | 792 return sandbox_file_system_.ComputeCurrentOriginUsage() - |
796 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); | 793 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); |
797 } | 794 } |
798 | 795 |
799 FileSystemContext* file_system_context() { | 796 FileSystemContext* file_system_context() { |
800 return sandbox_file_system_.file_system_context(); | 797 return sandbox_file_system_.file_system_context(); |
801 } | 798 } |
802 | 799 |
803 const base::FilePath& data_dir_path() const { | 800 const base::FilePath& data_dir_path() const { return data_dir_.GetPath(); } |
804 return data_dir_.path(); | |
805 } | |
806 | 801 |
807 protected: | 802 protected: |
808 base::ScopedTempDir data_dir_; | 803 base::ScopedTempDir data_dir_; |
809 base::MessageLoopForIO message_loop_; | 804 base::MessageLoopForIO message_loop_; |
810 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 805 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
811 scoped_refptr<storage::QuotaManager> quota_manager_; | 806 scoped_refptr<storage::QuotaManager> quota_manager_; |
812 scoped_refptr<FileSystemContext> file_system_context_; | 807 scoped_refptr<FileSystemContext> file_system_context_; |
813 GURL origin_; | 808 GURL origin_; |
814 storage::FileSystemType type_; | 809 storage::FileSystemType type_; |
815 SandboxFileSystemTestHelper sandbox_file_system_; | 810 SandboxFileSystemTestHelper sandbox_file_system_; |
(...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 ofu()->GetDirectoryForOriginAndType( | 2567 ofu()->GetDirectoryForOriginAndType( |
2573 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error); | 2568 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error); |
2574 ASSERT_EQ(base::File::FILE_OK, error); | 2569 ASSERT_EQ(base::File::FILE_OK, error); |
2575 error = base::File::FILE_ERROR_FAILED; | 2570 error = base::File::FILE_ERROR_FAILED; |
2576 ofu()->GetDirectoryForOriginAndType( | 2571 ofu()->GetDirectoryForOriginAndType( |
2577 origin2, GetTypeString(kFileSystemTypePersistent), false, &error); | 2572 origin2, GetTypeString(kFileSystemTypePersistent), false, &error); |
2578 ASSERT_EQ(base::File::FILE_OK, error); | 2573 ASSERT_EQ(base::File::FILE_OK, error); |
2579 } | 2574 } |
2580 | 2575 |
2581 } // namespace content | 2576 } // namespace content |
OLD | NEW |