| 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/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_operation_context.h" | 24 #include "webkit/fileapi/file_system_operation_context.h" |
| 24 #include "webkit/fileapi/file_system_path_manager.h" | |
| 25 #include "webkit/fileapi/file_system_util.h" | 25 #include "webkit/fileapi/file_system_util.h" |
| 26 #include "webkit/fileapi/mock_file_system_options.h" |
| 26 #include "webkit/quota/mock_special_storage_policy.h" | 27 #include "webkit/quota/mock_special_storage_policy.h" |
| 27 | 28 |
| 28 namespace fileapi { | 29 namespace fileapi { |
| 29 | 30 |
| 30 class MockFileSystemPathManager : public FileSystemPathManager { | |
| 31 public: | |
| 32 explicit MockFileSystemPathManager(const FilePath& profile_path) | |
| 33 : FileSystemPathManager(base::MessageLoopProxy::current(), | |
| 34 profile_path, NULL, false, true) {} | |
| 35 }; | |
| 36 | |
| 37 class SandboxMountPointProviderOriginEnumeratorTest : public testing::Test { | 31 class SandboxMountPointProviderOriginEnumeratorTest : public testing::Test { |
| 38 public: | 32 public: |
| 39 void SetUp() { | 33 void SetUp() { |
| 40 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 34 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 41 path_manager_.reset(new MockFileSystemPathManager(data_dir_.path())); | 35 sandbox_provider_.reset( |
| 36 new SandboxMountPointProvider( |
| 37 base::MessageLoopProxy::current(), |
| 38 data_dir_.path(), |
| 39 new MockFileSystemOptions())); |
| 42 } | 40 } |
| 43 | 41 |
| 44 SandboxMountPointProvider::OriginEnumerator* CreateEnumerator() const { | 42 SandboxMountPointProvider::OriginEnumerator* CreateEnumerator() const { |
| 45 return path_manager_->sandbox_provider()->CreateOriginEnumerator(); | 43 return sandbox_provider_->CreateOriginEnumerator(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 protected: | 46 protected: |
| 49 void CreateOriginTypeDirectory(const GURL& origin, | 47 void CreateOriginTypeDirectory(const GURL& origin, |
| 50 fileapi::FileSystemType type) { | 48 fileapi::FileSystemType type) { |
| 51 FilePath target = path_manager_->sandbox_provider()-> | 49 FilePath target = sandbox_provider_-> |
| 52 GetBaseDirectoryForOriginAndType(origin, type, true); | 50 GetBaseDirectoryForOriginAndType(origin, type, true); |
| 53 ASSERT_TRUE(!target.empty()); | 51 ASSERT_TRUE(!target.empty()); |
| 54 ASSERT_TRUE(file_util::DirectoryExists(target)); | 52 ASSERT_TRUE(file_util::DirectoryExists(target)); |
| 55 } | 53 } |
| 56 | 54 |
| 57 ScopedTempDir data_dir_; | 55 ScopedTempDir data_dir_; |
| 58 scoped_ptr<FileSystemPathManager> path_manager_; | 56 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; |
| 59 }; | 57 }; |
| 60 | 58 |
| 61 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, Empty) { | 59 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, Empty) { |
| 62 scoped_ptr<SandboxMountPointProvider::OriginEnumerator> enumerator( | 60 scoped_ptr<SandboxMountPointProvider::OriginEnumerator> enumerator( |
| 63 CreateEnumerator()); | 61 CreateEnumerator()); |
| 64 ASSERT_TRUE(enumerator->Next().is_empty()); | 62 ASSERT_TRUE(enumerator->Next().is_empty()); |
| 65 } | 63 } |
| 66 | 64 |
| 67 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, EnumerateOrigins) { | 65 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, EnumerateOrigins) { |
| 68 const char* temporary_origins[] = { | 66 const char* temporary_origins[] = { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } // anonymous namespace | 130 } // anonymous namespace |
| 133 | 131 |
| 134 class SandboxMountPointProviderMigrationTest : public testing::Test { | 132 class SandboxMountPointProviderMigrationTest : public testing::Test { |
| 135 public: | 133 public: |
| 136 SandboxMountPointProviderMigrationTest() : | 134 SandboxMountPointProviderMigrationTest() : |
| 137 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 135 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 138 } | 136 } |
| 139 | 137 |
| 140 void SetUp() { | 138 void SetUp() { |
| 141 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 139 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 142 path_manager_ = new MockFileSystemPathManager(data_dir_.path()); | |
| 143 | |
| 144 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 140 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
| 145 new quota::MockSpecialStoragePolicy; | 141 new quota::MockSpecialStoragePolicy; |
| 146 special_storage_policy->SetAllUnlimited(true); | 142 special_storage_policy->SetAllUnlimited(true); |
| 147 file_system_context_ = new FileSystemContext( | 143 file_system_context_ = new FileSystemContext( |
| 148 base::MessageLoopProxy::current(), | 144 base::MessageLoopProxy::current(), |
| 149 base::MessageLoopProxy::current(), | 145 base::MessageLoopProxy::current(), |
| 150 special_storage_policy, | 146 special_storage_policy, |
| 151 NULL, | 147 NULL, |
| 152 data_dir_.path(), | 148 data_dir_.path(), |
| 153 false, // incognito | 149 new MockFileSystemOptions()); |
| 154 true, // allow_file_access_from_files | |
| 155 path_manager_); | |
| 156 } | |
| 157 | |
| 158 FileSystemPathManager* path_manager() { | |
| 159 return path_manager_; | |
| 160 } | 150 } |
| 161 | 151 |
| 162 SandboxMountPointProvider* sandbox_provider() { | 152 SandboxMountPointProvider* sandbox_provider() { |
| 163 return path_manager()->sandbox_provider(); | 153 return file_system_context_->sandbox_provider(); |
| 164 } | 154 } |
| 165 | 155 |
| 166 FileSystemFileUtil* file_util() { | 156 FileSystemFileUtil* file_util() { |
| 167 return sandbox_provider()->GetFileUtil(); | 157 return sandbox_provider()->GetFileUtil(); |
| 168 } | 158 } |
| 169 | 159 |
| 170 void OnGetRootPath(bool success, const FilePath& unused, | 160 void OnGetRootPath(bool success, const FilePath& unused, |
| 171 const std::string& unused_also) { | 161 const std::string& unused_also) { |
| 172 EXPECT_FALSE(success); // We told it not to create. | 162 EXPECT_FALSE(success); // We told it not to create. |
| 173 } | 163 } |
| 174 | 164 |
| 175 FileSystemPathManager::GetRootPathCallback GetRootPathCallback() { | 165 FileSystemMountPointProvider::GetRootPathCallback GetRootPathCallback() { |
| 176 return base::Bind(&SandboxMountPointProviderMigrationTest::OnGetRootPath, | 166 return base::Bind(&SandboxMountPointProviderMigrationTest::OnGetRootPath, |
| 177 weak_factory_.GetWeakPtr()); | 167 weak_factory_.GetWeakPtr()); |
| 178 } | 168 } |
| 179 | 169 |
| 180 void EnsureFileExists(const FilePath& path) { | 170 void EnsureFileExists(const FilePath& path) { |
| 181 bool created = false; | 171 bool created = false; |
| 182 PlatformFileError error_code = base::PLATFORM_FILE_OK; | 172 PlatformFileError error_code = base::PLATFORM_FILE_OK; |
| 183 PlatformFile handle = base::CreatePlatformFile( | 173 PlatformFile handle = base::CreatePlatformFile( |
| 184 path, | 174 path, |
| 185 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, | 175 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 211 FileSystemOperationContext* context = new FileSystemOperationContext( | 201 FileSystemOperationContext* context = new FileSystemOperationContext( |
| 212 file_system_context_, file_util()); | 202 file_system_context_, file_util()); |
| 213 context->set_src_origin_url(origin_url); | 203 context->set_src_origin_url(origin_url); |
| 214 context->set_src_type(type); | 204 context->set_src_type(type); |
| 215 return context; | 205 return context; |
| 216 } | 206 } |
| 217 | 207 |
| 218 std::string URLAndTypeToSeedString(const GURL& origin_url, | 208 std::string URLAndTypeToSeedString(const GURL& origin_url, |
| 219 fileapi::FileSystemType type) { | 209 fileapi::FileSystemType type) { |
| 220 return GetOriginIdentifierFromURL(origin_url) + | 210 return GetOriginIdentifierFromURL(origin_url) + |
| 221 FileSystemPathManager::GetFileSystemTypeString(type); | 211 GetFileSystemTypeString(type); |
| 222 } | 212 } |
| 223 | 213 |
| 224 void ValidateDataInNewFileSystem( | 214 void ValidateDataInNewFileSystem( |
| 225 const GURL& origin_url, fileapi::FileSystemType type) { | 215 const GURL& origin_url, fileapi::FileSystemType type) { |
| 226 | 216 |
| 227 scoped_ptr<FileSystemOperationContext> context; | 217 scoped_ptr<FileSystemOperationContext> context; |
| 228 FilePath seed = FilePath().AppendASCII( | 218 FilePath seed = FilePath().AppendASCII( |
| 229 URLAndTypeToSeedString(origin_url, type)); | 219 URLAndTypeToSeedString(origin_url, type)); |
| 230 | 220 |
| 231 context.reset(NewContext(origin_url, type)); | 221 context.reset(NewContext(origin_url, type)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 ASSERT_TRUE(test_case.has_temporary || test_case.has_persistent); | 340 ASSERT_TRUE(test_case.has_temporary || test_case.has_persistent); |
| 351 if (test_case.has_temporary) | 341 if (test_case.has_temporary) |
| 352 ValidateDataInNewFileSystem(origin_url, kFileSystemTypeTemporary); | 342 ValidateDataInNewFileSystem(origin_url, kFileSystemTypeTemporary); |
| 353 if (test_case.has_persistent) | 343 if (test_case.has_persistent) |
| 354 ValidateDataInNewFileSystem(origin_url, kFileSystemTypePersistent); | 344 ValidateDataInNewFileSystem(origin_url, kFileSystemTypePersistent); |
| 355 } | 345 } |
| 356 } | 346 } |
| 357 | 347 |
| 358 protected: | 348 protected: |
| 359 ScopedTempDir data_dir_; | 349 ScopedTempDir data_dir_; |
| 360 FileSystemPathManager* path_manager_; | |
| 361 scoped_refptr<FileSystemContext> file_system_context_; | 350 scoped_refptr<FileSystemContext> file_system_context_; |
| 362 base::WeakPtrFactory<SandboxMountPointProviderMigrationTest> weak_factory_; | 351 base::WeakPtrFactory<SandboxMountPointProviderMigrationTest> weak_factory_; |
| 363 }; | 352 }; |
| 364 | 353 |
| 365 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod0) { | 354 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod0) { |
| 366 RunMigrationTest(0); | 355 RunMigrationTest(0); |
| 367 } | 356 } |
| 368 | 357 |
| 369 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod1) { | 358 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod1) { |
| 370 RunMigrationTest(1); | 359 RunMigrationTest(1); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 396 | 385 |
| 397 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod8) { | 386 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod8) { |
| 398 RunMigrationTest(8); | 387 RunMigrationTest(8); |
| 399 } | 388 } |
| 400 | 389 |
| 401 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod9) { | 390 TEST_F(SandboxMountPointProviderMigrationTest, TestMigrateViaMethod9) { |
| 402 RunMigrationTest(9); | 391 RunMigrationTest(9); |
| 403 } | 392 } |
| 404 | 393 |
| 405 } // namespace fileapi | 394 } // namespace fileapi |
| OLD | NEW |