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/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
19 #include "base/scoped_temp_dir.h" | 19 #include "base/scoped_temp_dir.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "webkit/fileapi/file_system_context.h" | 22 #include "webkit/fileapi/file_system_context.h" |
23 #include "webkit/fileapi/file_system_mount_point_provider.h" | 23 #include "webkit/fileapi/file_system_mount_point_provider.h" |
24 #include "webkit/fileapi/file_system_operation_context.h" | 24 #include "webkit/fileapi/file_system_operation_context.h" |
25 #include "webkit/fileapi/file_system_task_runners.h" | 25 #include "webkit/fileapi/file_system_task_runners.h" |
26 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 27 #include "webkit/fileapi/file_util_helper.h" |
27 #include "webkit/fileapi/mock_file_system_options.h" | 28 #include "webkit/fileapi/mock_file_system_options.h" |
28 #include "webkit/quota/mock_special_storage_policy.h" | 29 #include "webkit/quota/mock_special_storage_policy.h" |
29 | 30 |
30 namespace fileapi { | 31 namespace fileapi { |
31 | 32 |
32 class SandboxMountPointProviderOriginEnumeratorTest : public testing::Test { | 33 class SandboxMountPointProviderOriginEnumeratorTest : public testing::Test { |
33 public: | 34 public: |
34 void SetUp() { | 35 void SetUp() { |
35 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 36 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
36 sandbox_provider_.reset( | 37 sandbox_provider_.reset( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 EnsureFileExists( | 195 EnsureFileExists( |
195 root.AppendASCII(seed).AppendASCII("d 0").AppendASCII("file 1")); | 196 root.AppendASCII(seed).AppendASCII("d 0").AppendASCII("file 1")); |
196 EnsureFileExists( | 197 EnsureFileExists( |
197 root.AppendASCII(seed).AppendASCII("d 0").AppendASCII("file 2")); | 198 root.AppendASCII(seed).AppendASCII("d 0").AppendASCII("file 2")); |
198 } | 199 } |
199 | 200 |
200 FileSystemOperationContext* NewContext() { | 201 FileSystemOperationContext* NewContext() { |
201 return new FileSystemOperationContext(file_system_context_); | 202 return new FileSystemOperationContext(file_system_context_); |
202 } | 203 } |
203 | 204 |
| 205 bool PathExists(const FileSystemURL& url) { |
| 206 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 207 return FileUtilHelper::PathExists(context.get(), file_util(), url); |
| 208 } |
| 209 |
| 210 bool DirectoryExists(const FileSystemURL& url) { |
| 211 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 212 return FileUtilHelper::DirectoryExists(context.get(), file_util(), url); |
| 213 } |
| 214 |
204 std::string URLAndTypeToSeedString(const GURL& origin_url, | 215 std::string URLAndTypeToSeedString(const GURL& origin_url, |
205 fileapi::FileSystemType type) { | 216 fileapi::FileSystemType type) { |
206 return GetOriginIdentifierFromURL(origin_url) + | 217 return GetOriginIdentifierFromURL(origin_url) + |
207 GetFileSystemTypeString(type); | 218 GetFileSystemTypeString(type); |
208 } | 219 } |
209 | 220 |
210 void ValidateDataInNewFileSystem( | 221 void ValidateDataInNewFileSystem( |
211 const GURL& origin_url, fileapi::FileSystemType type) { | 222 const GURL& origin_url, fileapi::FileSystemType type) { |
212 scoped_ptr<FileSystemOperationContext> context; | 223 scoped_ptr<FileSystemOperationContext> context; |
213 FilePath seed_file_path = FilePath().AppendASCII( | 224 FilePath seed_file_path = FilePath().AppendASCII( |
214 URLAndTypeToSeedString(origin_url, type)); | 225 URLAndTypeToSeedString(origin_url, type)); |
215 | 226 |
216 FileSystemURL root(origin_url, type, FilePath()); | 227 FileSystemURL root(origin_url, type, FilePath()); |
217 FileSystemURL seed = root.WithPath(root.path().Append(seed_file_path)); | 228 FileSystemURL seed = root.WithPath(root.path().Append(seed_file_path)); |
218 | 229 |
219 context.reset(NewContext()); | 230 EXPECT_TRUE(DirectoryExists(seed)); |
220 EXPECT_TRUE(file_util()->DirectoryExists( | 231 EXPECT_TRUE(DirectoryExists( |
221 context.get(), seed)); | 232 seed.WithPath(seed.path().Append(seed_file_path)))); |
222 context.reset(NewContext()); | 233 EXPECT_TRUE(DirectoryExists( |
223 EXPECT_TRUE(file_util()->DirectoryExists( | 234 seed.WithPath(seed.path().AppendASCII("d 0")))); |
224 context.get(), seed.WithPath(seed.path().Append(seed_file_path)))); | 235 EXPECT_TRUE(DirectoryExists( |
225 context.reset(NewContext()); | 236 seed.WithPath(seed.path().AppendASCII("d 1")))); |
226 EXPECT_TRUE(file_util()->DirectoryExists( | 237 EXPECT_TRUE(PathExists( |
227 context.get(), seed.WithPath(seed.path().AppendASCII("d 0")))); | 238 root.WithPath(root.path().AppendASCII("file 0")))); |
228 context.reset(NewContext()); | 239 EXPECT_FALSE(DirectoryExists( |
229 EXPECT_TRUE(file_util()->DirectoryExists( | 240 seed.WithPath(seed.path().AppendASCII("file 0")))); |
230 context.get(), seed.WithPath(seed.path().AppendASCII("d 1")))); | 241 EXPECT_TRUE(PathExists( |
231 context.reset(NewContext()); | |
232 EXPECT_TRUE(file_util()->PathExists( | |
233 context.get(), root.WithPath(root.path().AppendASCII("file 0")))); | |
234 context.reset(NewContext()); | |
235 EXPECT_FALSE(file_util()->DirectoryExists( | |
236 context.get(), seed.WithPath(seed.path().AppendASCII("file 0")))); | |
237 context.reset(NewContext()); | |
238 EXPECT_TRUE(file_util()->PathExists( | |
239 context.get(), | |
240 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 1")))); | 242 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 1")))); |
241 context.reset(NewContext()); | 243 EXPECT_FALSE(DirectoryExists( |
242 EXPECT_FALSE(file_util()->DirectoryExists( | |
243 context.get(), | |
244 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 1")))); | 244 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 1")))); |
245 context.reset(NewContext()); | 245 EXPECT_TRUE(PathExists( |
246 EXPECT_TRUE(file_util()->PathExists( | |
247 context.get(), | |
248 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 2")))); | 246 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 2")))); |
249 context.reset(NewContext()); | 247 EXPECT_FALSE(DirectoryExists( |
250 EXPECT_FALSE(file_util()->DirectoryExists( | |
251 context.get(), | |
252 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 2")))); | 248 seed.WithPath(seed.path().AppendASCII("d 0").AppendASCII("file 2")))); |
253 } | 249 } |
254 | 250 |
255 void RunMigrationTest(int method) { | 251 void RunMigrationTest(int method) { |
256 for (size_t i = 0; i < arraysize(kMigrationTestRecords); ++i) { | 252 for (size_t i = 0; i < arraysize(kMigrationTestRecords); ++i) { |
257 const MigrationTestCaseRecord& test_case = kMigrationTestRecords[i]; | 253 const MigrationTestCaseRecord& test_case = kMigrationTestRecords[i]; |
258 const GURL& origin_url = test_case.origin; | 254 const GURL& origin_url = test_case.origin; |
259 ASSERT_TRUE(test_case.has_temporary || test_case.has_persistent); | 255 ASSERT_TRUE(test_case.has_temporary || test_case.has_persistent); |
260 if (test_case.has_temporary) { | 256 if (test_case.has_temporary) { |
261 FilePath root = sandbox_provider()->OldCreateFileSystemRootPath( | 257 FilePath root = sandbox_provider()->OldCreateFileSystemRootPath( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 384 |
389 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod8) { | 385 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod8) { |
390 RunMigrationTest(8); | 386 RunMigrationTest(8); |
391 } | 387 } |
392 | 388 |
393 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod9) { | 389 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod9) { |
394 RunMigrationTest(9); | 390 RunMigrationTest(9); |
395 } | 391 } |
396 | 392 |
397 } // namespace fileapi | 393 } // namespace fileapi |
OLD | NEW |