| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 28 #include "webkit/browser/fileapi/obfuscated_file_util.h" |
| 29 #include "webkit/browser/fileapi/sandbox_directory_database.h" | 29 #include "webkit/browser/fileapi/sandbox_directory_database.h" |
| 30 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 30 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
| 31 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" | 31 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
| 32 #include "webkit/browser/fileapi/sandbox_origin_database.h" | 32 #include "webkit/browser/fileapi/sandbox_origin_database.h" |
| 33 #include "webkit/browser/quota/quota_manager.h" | 33 #include "webkit/browser/quota/quota_manager.h" |
| 34 #include "webkit/common/database/database_identifier.h" | 34 #include "webkit/common/database/database_identifier.h" |
| 35 #include "webkit/common/quota/quota_types.h" | 35 #include "webkit/common/quota/quota_types.h" |
| 36 | 36 |
| 37 using content::AsyncFileTestHelper; | 37 using content::AsyncFileTestHelper; |
| 38 using fileapi::FileSystemContext; | 38 using storage::FileSystemContext; |
| 39 using fileapi::FileSystemOperation; | 39 using storage::FileSystemOperation; |
| 40 using fileapi::FileSystemOperationContext; | 40 using storage::FileSystemOperationContext; |
| 41 using fileapi::FileSystemURL; | 41 using storage::FileSystemURL; |
| 42 using fileapi::ObfuscatedFileUtil; | 42 using storage::ObfuscatedFileUtil; |
| 43 using fileapi::SandboxDirectoryDatabase; | 43 using storage::SandboxDirectoryDatabase; |
| 44 using fileapi::SandboxIsolatedOriginDatabase; | 44 using storage::SandboxIsolatedOriginDatabase; |
| 45 using fileapi::kFileSystemTypeTemporary; | 45 using storage::kFileSystemTypeTemporary; |
| 46 using fileapi::kFileSystemTypePersistent; | 46 using storage::kFileSystemTypePersistent; |
| 47 | 47 |
| 48 namespace content { | 48 namespace content { |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 bool FileExists(const base::FilePath& path) { | 52 bool FileExists(const base::FilePath& path) { |
| 53 return base::PathExists(path) && !base::DirectoryExists(path); | 53 return base::PathExists(path) && !base::DirectoryExists(path); |
| 54 } | 54 } |
| 55 | 55 |
| 56 int64 GetSize(const base::FilePath& path) { | 56 int64 GetSize(const base::FilePath& path) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 FileSystemURL FileSystemURLAppendUTF8( | 114 FileSystemURL FileSystemURLAppendUTF8( |
| 115 const FileSystemURL& url, const std::string& child) { | 115 const FileSystemURL& url, const std::string& child) { |
| 116 return FileSystemURL::CreateForTest( | 116 return FileSystemURL::CreateForTest( |
| 117 url.origin(), | 117 url.origin(), |
| 118 url.mount_type(), | 118 url.mount_type(), |
| 119 url.virtual_path().Append(base::FilePath::FromUTF8Unsafe(child))); | 119 url.virtual_path().Append(base::FilePath::FromUTF8Unsafe(child))); |
| 120 } | 120 } |
| 121 | 121 |
| 122 FileSystemURL FileSystemURLDirName(const FileSystemURL& url) { | 122 FileSystemURL FileSystemURLDirName(const FileSystemURL& url) { |
| 123 return FileSystemURL::CreateForTest( | 123 return FileSystemURL::CreateForTest( |
| 124 url.origin(), url.mount_type(), | 124 url.origin(), |
| 125 fileapi::VirtualPath::DirName(url.virtual_path())); | 125 url.mount_type(), |
| 126 storage::VirtualPath::DirName(url.virtual_path())); |
| 126 } | 127 } |
| 127 | 128 |
| 128 std::string GetTypeString(fileapi::FileSystemType type) { | 129 std::string GetTypeString(storage::FileSystemType type) { |
| 129 return fileapi::SandboxFileSystemBackendDelegate::GetTypeString(type); | 130 return storage::SandboxFileSystemBackendDelegate::GetTypeString(type); |
| 130 } | 131 } |
| 131 | 132 |
| 132 bool HasFileSystemType(ObfuscatedFileUtil::AbstractOriginEnumerator* enumerator, | 133 bool HasFileSystemType(ObfuscatedFileUtil::AbstractOriginEnumerator* enumerator, |
| 133 fileapi::FileSystemType type) { | 134 storage::FileSystemType type) { |
| 134 return enumerator->HasTypeDirectory(GetTypeString(type)); | 135 return enumerator->HasTypeDirectory(GetTypeString(type)); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 // TODO(ericu): The vast majority of this and the other FSFU subclass tests | 140 // TODO(ericu): The vast majority of this and the other FSFU subclass tests |
| 140 // could theoretically be shared. It would basically be a FSFU interface | 141 // could theoretically be shared. It would basically be a FSFU interface |
| 141 // compliance test, and only the subclass-specific bits that look into the | 142 // compliance test, and only the subclass-specific bits that look into the |
| 142 // implementation would need to be written per-subclass. | 143 // implementation would need to be written per-subclass. |
| 143 class ObfuscatedFileUtilTest : public testing::Test { | 144 class ObfuscatedFileUtilTest : public testing::Test { |
| 144 public: | 145 public: |
| 145 ObfuscatedFileUtilTest() | 146 ObfuscatedFileUtilTest() |
| 146 : origin_(GURL("http://www.example.com")), | 147 : origin_(GURL("http://www.example.com")), |
| 147 type_(fileapi::kFileSystemTypeTemporary), | 148 type_(storage::kFileSystemTypeTemporary), |
| 148 weak_factory_(this), | 149 weak_factory_(this), |
| 149 sandbox_file_system_(origin_, type_), | 150 sandbox_file_system_(origin_, type_), |
| 150 quota_status_(quota::kQuotaStatusUnknown), | 151 quota_status_(storage::kQuotaStatusUnknown), |
| 151 usage_(-1) { | 152 usage_(-1) {} |
| 152 } | |
| 153 | 153 |
| 154 virtual void SetUp() { | 154 virtual void SetUp() { |
| 155 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 155 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 156 | 156 |
| 157 storage_policy_ = new MockSpecialStoragePolicy(); | 157 storage_policy_ = new MockSpecialStoragePolicy(); |
| 158 | 158 |
| 159 quota_manager_ = | 159 quota_manager_ = |
| 160 new quota::QuotaManager(false /* is_incognito */, | 160 new storage::QuotaManager(false /* is_incognito */, |
| 161 data_dir_.path(), | 161 data_dir_.path(), |
| 162 base::MessageLoopProxy::current().get(), | 162 base::MessageLoopProxy::current().get(), |
| 163 base::MessageLoopProxy::current().get(), | 163 base::MessageLoopProxy::current().get(), |
| 164 storage_policy_.get()); | 164 storage_policy_.get()); |
| 165 | 165 |
| 166 // Every time we create a new sandbox_file_system helper, | 166 // Every time we create a new sandbox_file_system helper, |
| 167 // it creates another context, which creates another path manager, | 167 // it creates another context, which creates another path manager, |
| 168 // another sandbox_backend, and another OFU. | 168 // another sandbox_backend, and another OFU. |
| 169 // We need to pass in the context to skip all that. | 169 // We need to pass in the context to skip all that. |
| 170 file_system_context_ = CreateFileSystemContextForTesting( | 170 file_system_context_ = CreateFileSystemContextForTesting( |
| 171 quota_manager_->proxy(), | 171 quota_manager_->proxy(), |
| 172 data_dir_.path()); | 172 data_dir_.path()); |
| 173 | 173 |
| 174 sandbox_file_system_.SetUp(file_system_context_.get()); | 174 sandbox_file_system_.SetUp(file_system_context_.get()); |
| 175 | 175 |
| 176 change_observers_ = fileapi::MockFileChangeObserver::CreateList( | 176 change_observers_ = |
| 177 &change_observer_); | 177 storage::MockFileChangeObserver::CreateList(&change_observer_); |
| 178 } | 178 } |
| 179 | 179 |
| 180 virtual void TearDown() { | 180 virtual void TearDown() { |
| 181 quota_manager_ = NULL; | 181 quota_manager_ = NULL; |
| 182 sandbox_file_system_.TearDown(); | 182 sandbox_file_system_.TearDown(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 scoped_ptr<FileSystemOperationContext> LimitedContext( | 185 scoped_ptr<FileSystemOperationContext> LimitedContext( |
| 186 int64 allowed_bytes_growth) { | 186 int64 allowed_bytes_growth) { |
| 187 scoped_ptr<FileSystemOperationContext> context( | 187 scoped_ptr<FileSystemOperationContext> context( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 201 if (file_system) | 201 if (file_system) |
| 202 context = file_system->NewOperationContext(); | 202 context = file_system->NewOperationContext(); |
| 203 else | 203 else |
| 204 context = sandbox_file_system_.NewOperationContext(); | 204 context = sandbox_file_system_.NewOperationContext(); |
| 205 // Setting allowed_bytes_growth big enough for all tests. | 205 // Setting allowed_bytes_growth big enough for all tests. |
| 206 context->set_allowed_bytes_growth(1024 * 1024); | 206 context->set_allowed_bytes_growth(1024 * 1024); |
| 207 context->set_change_observers(change_observers()); | 207 context->set_change_observers(change_observers()); |
| 208 return context; | 208 return context; |
| 209 } | 209 } |
| 210 | 210 |
| 211 const fileapi::ChangeObserverList& change_observers() const { | 211 const storage::ChangeObserverList& change_observers() const { |
| 212 return change_observers_; | 212 return change_observers_; |
| 213 } | 213 } |
| 214 | 214 |
| 215 fileapi::MockFileChangeObserver* change_observer() { | 215 storage::MockFileChangeObserver* change_observer() { |
| 216 return &change_observer_; | 216 return &change_observer_; |
| 217 } | 217 } |
| 218 | 218 |
| 219 // This can only be used after SetUp has run and created file_system_context_ | 219 // This can only be used after SetUp has run and created file_system_context_ |
| 220 // and obfuscated_file_util_. | 220 // and obfuscated_file_util_. |
| 221 // Use this for tests which need to run in multiple origins; we need a test | 221 // Use this for tests which need to run in multiple origins; we need a test |
| 222 // helper per origin. | 222 // helper per origin. |
| 223 SandboxFileSystemTestHelper* NewFileSystem( | 223 SandboxFileSystemTestHelper* NewFileSystem(const GURL& origin, |
| 224 const GURL& origin, fileapi::FileSystemType type) { | 224 storage::FileSystemType type) { |
| 225 SandboxFileSystemTestHelper* file_system = | 225 SandboxFileSystemTestHelper* file_system = |
| 226 new SandboxFileSystemTestHelper(origin, type); | 226 new SandboxFileSystemTestHelper(origin, type); |
| 227 | 227 |
| 228 file_system->SetUp(file_system_context_.get()); | 228 file_system->SetUp(file_system_context_.get()); |
| 229 return file_system; | 229 return file_system; |
| 230 } | 230 } |
| 231 | 231 |
| 232 scoped_ptr<ObfuscatedFileUtil> CreateObfuscatedFileUtil( | 232 scoped_ptr<ObfuscatedFileUtil> CreateObfuscatedFileUtil( |
| 233 quota::SpecialStoragePolicy* storage_policy) { | 233 storage::SpecialStoragePolicy* storage_policy) { |
| 234 return scoped_ptr<ObfuscatedFileUtil>( | 234 return scoped_ptr<ObfuscatedFileUtil>( |
| 235 ObfuscatedFileUtil::CreateForTesting( | 235 ObfuscatedFileUtil::CreateForTesting( |
| 236 storage_policy, data_dir_path(), NULL, | 236 storage_policy, data_dir_path(), NULL, |
| 237 base::MessageLoopProxy::current().get())); | 237 base::MessageLoopProxy::current().get())); |
| 238 } | 238 } |
| 239 | 239 |
| 240 ObfuscatedFileUtil* ofu() { | 240 ObfuscatedFileUtil* ofu() { |
| 241 return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util()); | 241 return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 const base::FilePath& test_directory() const { | 244 const base::FilePath& test_directory() const { |
| 245 return data_dir_.path(); | 245 return data_dir_.path(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 const GURL& origin() const { | 248 const GURL& origin() const { |
| 249 return origin_; | 249 return origin_; |
| 250 } | 250 } |
| 251 | 251 |
| 252 fileapi::FileSystemType type() const { | 252 storage::FileSystemType type() const { return type_; } |
| 253 return type_; | |
| 254 } | |
| 255 | 253 |
| 256 std::string type_string() const { | 254 std::string type_string() const { |
| 257 return GetTypeString(type_); | 255 return GetTypeString(type_); |
| 258 } | 256 } |
| 259 | 257 |
| 260 int64 ComputeTotalFileSize() { | 258 int64 ComputeTotalFileSize() { |
| 261 return sandbox_file_system_.ComputeCurrentOriginUsage() - | 259 return sandbox_file_system_.ComputeCurrentOriginUsage() - |
| 262 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); | 260 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); |
| 263 } | 261 } |
| 264 | 262 |
| 265 void GetUsageFromQuotaManager() { | 263 void GetUsageFromQuotaManager() { |
| 266 int64 quota = -1; | 264 int64 quota = -1; |
| 267 quota_status_ = | 265 quota_status_ = |
| 268 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), | 266 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), |
| 269 origin(), | 267 origin(), |
| 270 sandbox_file_system_.type(), | 268 sandbox_file_system_.type(), |
| 271 &usage_, | 269 &usage_, |
| 272 "a); | 270 "a); |
| 273 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); | 271 EXPECT_EQ(storage::kQuotaStatusOk, quota_status_); |
| 274 } | 272 } |
| 275 | 273 |
| 276 void RevokeUsageCache() { | 274 void RevokeUsageCache() { |
| 277 quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type()); | 275 quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type()); |
| 278 usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath()); | 276 usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath()); |
| 279 } | 277 } |
| 280 | 278 |
| 281 int64 SizeByQuotaUtil() { | 279 int64 SizeByQuotaUtil() { |
| 282 return sandbox_file_system_.GetCachedOriginUsage(); | 280 return sandbox_file_system_.GetCachedOriginUsage(); |
| 283 } | 281 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 296 base::File::Error error = ofu()->GetFileInfo( | 294 base::File::Error error = ofu()->GetFileInfo( |
| 297 context.get(), url, &file_info, &platform_path); | 295 context.get(), url, &file_info, &platform_path); |
| 298 return error == base::File::FILE_OK; | 296 return error == base::File::FILE_OK; |
| 299 } | 297 } |
| 300 | 298 |
| 301 bool DirectoryExists(const FileSystemURL& url) { | 299 bool DirectoryExists(const FileSystemURL& url) { |
| 302 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); | 300 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); |
| 303 } | 301 } |
| 304 | 302 |
| 305 int64 usage() const { return usage_; } | 303 int64 usage() const { return usage_; } |
| 306 fileapi::FileSystemUsageCache* usage_cache() { | 304 storage::FileSystemUsageCache* usage_cache() { |
| 307 return sandbox_file_system_.usage_cache(); | 305 return sandbox_file_system_.usage_cache(); |
| 308 } | 306 } |
| 309 | 307 |
| 310 FileSystemURL CreateURLFromUTF8(const std::string& path) { | 308 FileSystemURL CreateURLFromUTF8(const std::string& path) { |
| 311 return sandbox_file_system_.CreateURLFromUTF8(path); | 309 return sandbox_file_system_.CreateURLFromUTF8(path); |
| 312 } | 310 } |
| 313 | 311 |
| 314 int64 PathCost(const FileSystemURL& url) { | 312 int64 PathCost(const FileSystemURL& url) { |
| 315 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); | 313 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); |
| 316 } | 314 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 int64 usage = sandbox_file_system_.GetCachedOriginUsage(); | 431 int64 usage = sandbox_file_system_.GetCachedOriginUsage(); |
| 434 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( | 432 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( |
| 435 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage)); | 433 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage)); |
| 436 } | 434 } |
| 437 | 435 |
| 438 void FillTestDirectory( | 436 void FillTestDirectory( |
| 439 const FileSystemURL& root_url, | 437 const FileSystemURL& root_url, |
| 440 std::set<base::FilePath::StringType>* files, | 438 std::set<base::FilePath::StringType>* files, |
| 441 std::set<base::FilePath::StringType>* directories) { | 439 std::set<base::FilePath::StringType>* directories) { |
| 442 scoped_ptr<FileSystemOperationContext> context; | 440 scoped_ptr<FileSystemOperationContext> context; |
| 443 std::vector<fileapi::DirectoryEntry> entries; | 441 std::vector<storage::DirectoryEntry> entries; |
| 444 EXPECT_EQ(base::File::FILE_OK, | 442 EXPECT_EQ(base::File::FILE_OK, |
| 445 AsyncFileTestHelper::ReadDirectory(file_system_context(), | 443 AsyncFileTestHelper::ReadDirectory(file_system_context(), |
| 446 root_url, &entries)); | 444 root_url, &entries)); |
| 447 EXPECT_EQ(0UL, entries.size()); | 445 EXPECT_EQ(0UL, entries.size()); |
| 448 | 446 |
| 449 files->clear(); | 447 files->clear(); |
| 450 files->insert(FILE_PATH_LITERAL("first")); | 448 files->insert(FILE_PATH_LITERAL("first")); |
| 451 files->insert(FILE_PATH_LITERAL("second")); | 449 files->insert(FILE_PATH_LITERAL("second")); |
| 452 files->insert(FILE_PATH_LITERAL("third")); | 450 files->insert(FILE_PATH_LITERAL("third")); |
| 453 directories->clear(); | 451 directories->clear(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 475 } | 473 } |
| 476 ValidateTestDirectory(root_url, *files, *directories); | 474 ValidateTestDirectory(root_url, *files, *directories); |
| 477 } | 475 } |
| 478 | 476 |
| 479 void TestReadDirectoryHelper(const FileSystemURL& root_url) { | 477 void TestReadDirectoryHelper(const FileSystemURL& root_url) { |
| 480 std::set<base::FilePath::StringType> files; | 478 std::set<base::FilePath::StringType> files; |
| 481 std::set<base::FilePath::StringType> directories; | 479 std::set<base::FilePath::StringType> directories; |
| 482 FillTestDirectory(root_url, &files, &directories); | 480 FillTestDirectory(root_url, &files, &directories); |
| 483 | 481 |
| 484 scoped_ptr<FileSystemOperationContext> context; | 482 scoped_ptr<FileSystemOperationContext> context; |
| 485 std::vector<fileapi::DirectoryEntry> entries; | 483 std::vector<storage::DirectoryEntry> entries; |
| 486 context.reset(NewContext(NULL)); | 484 context.reset(NewContext(NULL)); |
| 487 EXPECT_EQ(base::File::FILE_OK, | 485 EXPECT_EQ(base::File::FILE_OK, |
| 488 AsyncFileTestHelper::ReadDirectory( | 486 AsyncFileTestHelper::ReadDirectory( |
| 489 file_system_context(), root_url, &entries)); | 487 file_system_context(), root_url, &entries)); |
| 490 std::vector<fileapi::DirectoryEntry>::iterator entry_iter; | 488 std::vector<storage::DirectoryEntry>::iterator entry_iter; |
| 491 EXPECT_EQ(files.size() + directories.size(), entries.size()); | 489 EXPECT_EQ(files.size() + directories.size(), entries.size()); |
| 492 EXPECT_TRUE(change_observer()->HasNoChange()); | 490 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 493 for (entry_iter = entries.begin(); entry_iter != entries.end(); | 491 for (entry_iter = entries.begin(); entry_iter != entries.end(); |
| 494 ++entry_iter) { | 492 ++entry_iter) { |
| 495 const fileapi::DirectoryEntry& entry = *entry_iter; | 493 const storage::DirectoryEntry& entry = *entry_iter; |
| 496 std::set<base::FilePath::StringType>::iterator iter = | 494 std::set<base::FilePath::StringType>::iterator iter = |
| 497 files.find(entry.name); | 495 files.find(entry.name); |
| 498 if (iter != files.end()) { | 496 if (iter != files.end()) { |
| 499 EXPECT_FALSE(entry.is_directory); | 497 EXPECT_FALSE(entry.is_directory); |
| 500 files.erase(iter); | 498 files.erase(iter); |
| 501 continue; | 499 continue; |
| 502 } | 500 } |
| 503 iter = directories.find(entry.name); | 501 iter = directories.find(entry.name); |
| 504 EXPECT_FALSE(directories.end() == iter); | 502 EXPECT_FALSE(directories.end() == iter); |
| 505 EXPECT_TRUE(entry.is_directory); | 503 EXPECT_TRUE(entry.is_directory); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 ASSERT_EQ(db, db2); | 736 ASSERT_EQ(db, db2); |
| 739 } | 737 } |
| 740 | 738 |
| 741 void MigrationBackFromIsolatedTestBody() { | 739 void MigrationBackFromIsolatedTestBody() { |
| 742 std::string kFakeDirectoryData("0123456789"); | 740 std::string kFakeDirectoryData("0123456789"); |
| 743 base::FilePath old_directory_db_path; | 741 base::FilePath old_directory_db_path; |
| 744 | 742 |
| 745 // Initialize the directory with one origin using | 743 // Initialize the directory with one origin using |
| 746 // SandboxIsolatedOriginDatabase. | 744 // SandboxIsolatedOriginDatabase. |
| 747 { | 745 { |
| 748 std::string origin_string = | 746 std::string origin_string = storage::GetIdentifierFromOrigin(origin_); |
| 749 webkit_database::GetIdentifierFromOrigin(origin_); | |
| 750 SandboxIsolatedOriginDatabase database_old( | 747 SandboxIsolatedOriginDatabase database_old( |
| 751 origin_string, data_dir_path(), | 748 origin_string, data_dir_path(), |
| 752 base::FilePath( | 749 base::FilePath( |
| 753 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory)); | 750 SandboxIsolatedOriginDatabase::kObsoleteOriginDirectory)); |
| 754 base::FilePath path; | 751 base::FilePath path; |
| 755 EXPECT_TRUE(database_old.GetPathForOrigin(origin_string, &path)); | 752 EXPECT_TRUE(database_old.GetPathForOrigin(origin_string, &path)); |
| 756 EXPECT_FALSE(path.empty()); | 753 EXPECT_FALSE(path.empty()); |
| 757 | 754 |
| 758 // Populate the origin directory with some fake data. | 755 // Populate the origin directory with some fake data. |
| 759 old_directory_db_path = data_dir_path().Append(path); | 756 old_directory_db_path = data_dir_path().Append(path); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 } | 791 } |
| 795 | 792 |
| 796 const base::FilePath& data_dir_path() const { | 793 const base::FilePath& data_dir_path() const { |
| 797 return data_dir_.path(); | 794 return data_dir_.path(); |
| 798 } | 795 } |
| 799 | 796 |
| 800 protected: | 797 protected: |
| 801 base::ScopedTempDir data_dir_; | 798 base::ScopedTempDir data_dir_; |
| 802 base::MessageLoop message_loop_; | 799 base::MessageLoop message_loop_; |
| 803 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; | 800 scoped_refptr<MockSpecialStoragePolicy> storage_policy_; |
| 804 scoped_refptr<quota::QuotaManager> quota_manager_; | 801 scoped_refptr<storage::QuotaManager> quota_manager_; |
| 805 scoped_refptr<FileSystemContext> file_system_context_; | 802 scoped_refptr<FileSystemContext> file_system_context_; |
| 806 GURL origin_; | 803 GURL origin_; |
| 807 fileapi::FileSystemType type_; | 804 storage::FileSystemType type_; |
| 808 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; | 805 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; |
| 809 SandboxFileSystemTestHelper sandbox_file_system_; | 806 SandboxFileSystemTestHelper sandbox_file_system_; |
| 810 quota::QuotaStatusCode quota_status_; | 807 storage::QuotaStatusCode quota_status_; |
| 811 int64 usage_; | 808 int64 usage_; |
| 812 fileapi::MockFileChangeObserver change_observer_; | 809 storage::MockFileChangeObserver change_observer_; |
| 813 fileapi::ChangeObserverList change_observers_; | 810 storage::ChangeObserverList change_observers_; |
| 814 | 811 |
| 815 private: | 812 private: |
| 816 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); | 813 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); |
| 817 }; | 814 }; |
| 818 | 815 |
| 819 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { | 816 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { |
| 820 FileSystemURL url = CreateURLFromUTF8("fake/file"); | 817 FileSystemURL url = CreateURLFromUTF8("fake/file"); |
| 821 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 818 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 822 int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; | 819 int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE; |
| 823 | 820 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 | 1207 |
| 1211 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { | 1208 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { |
| 1212 FileSystemURL url = CreateURLFromUTF8("file"); | 1209 FileSystemURL url = CreateURLFromUTF8("file"); |
| 1213 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1210 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1214 | 1211 |
| 1215 bool created = false; | 1212 bool created = false; |
| 1216 ASSERT_EQ(base::File::FILE_OK, | 1213 ASSERT_EQ(base::File::FILE_OK, |
| 1217 ofu()->EnsureFileExists(context.get(), url, &created)); | 1214 ofu()->EnsureFileExists(context.get(), url, &created)); |
| 1218 ASSERT_TRUE(created); | 1215 ASSERT_TRUE(created); |
| 1219 | 1216 |
| 1220 std::vector<fileapi::DirectoryEntry> entries; | 1217 std::vector<storage::DirectoryEntry> entries; |
| 1221 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, | 1218 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, |
| 1222 AsyncFileTestHelper::ReadDirectory(file_system_context(), url, | 1219 AsyncFileTestHelper::ReadDirectory(file_system_context(), url, |
| 1223 &entries)); | 1220 &entries)); |
| 1224 | 1221 |
| 1225 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); | 1222 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), url)); |
| 1226 } | 1223 } |
| 1227 | 1224 |
| 1228 TEST_F(ObfuscatedFileUtilTest, TestTouch) { | 1225 TEST_F(ObfuscatedFileUtilTest, TestTouch) { |
| 1229 FileSystemURL url = CreateURLFromUTF8("file"); | 1226 FileSystemURL url = CreateURLFromUTF8("file"); |
| 1230 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1227 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 scoped_ptr<FileSystemOperationContext> context; | 1785 scoped_ptr<FileSystemOperationContext> context; |
| 1789 | 1786 |
| 1790 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { | 1787 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) { |
| 1791 bool created = false; | 1788 bool created = false; |
| 1792 context.reset(NewContext(NULL)); | 1789 context.reset(NewContext(NULL)); |
| 1793 EXPECT_EQ(base::File::FILE_OK, | 1790 EXPECT_EQ(base::File::FILE_OK, |
| 1794 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); | 1791 ofu()->EnsureFileExists(context.get(), kPath[i], &created)); |
| 1795 EXPECT_TRUE(created); | 1792 EXPECT_TRUE(created); |
| 1796 } | 1793 } |
| 1797 | 1794 |
| 1798 std::vector<fileapi::DirectoryEntry> entries; | 1795 std::vector<storage::DirectoryEntry> entries; |
| 1799 EXPECT_EQ(base::File::FILE_OK, | 1796 EXPECT_EQ(base::File::FILE_OK, |
| 1800 AsyncFileTestHelper::ReadDirectory( | 1797 AsyncFileTestHelper::ReadDirectory( |
| 1801 file_system_context(), empty_path, &entries)); | 1798 file_system_context(), empty_path, &entries)); |
| 1802 EXPECT_EQ(3u, entries.size()); | 1799 EXPECT_EQ(3u, entries.size()); |
| 1803 | 1800 |
| 1804 base::FilePath local_path; | 1801 base::FilePath local_path; |
| 1805 EXPECT_EQ(base::File::FILE_OK, | 1802 EXPECT_EQ(base::File::FILE_OK, |
| 1806 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); | 1803 ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path)); |
| 1807 EXPECT_TRUE(base::DeleteFile(local_path, false)); | 1804 EXPECT_TRUE(base::DeleteFile(local_path, false)); |
| 1808 | 1805 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 ofu()->GetLocalFilePath(context.get(), url1, &file_path)); | 2030 ofu()->GetLocalFilePath(context.get(), url1, &file_path)); |
| 2034 EXPECT_FALSE(file_path.empty()); | 2031 EXPECT_FALSE(file_path.empty()); |
| 2035 | 2032 |
| 2036 context.reset(NewContext(NULL)); | 2033 context.reset(NewContext(NULL)); |
| 2037 EXPECT_EQ(base::File::FILE_OK, | 2034 EXPECT_EQ(base::File::FILE_OK, |
| 2038 ofu()->Touch(context.get(), url1, | 2035 ofu()->Touch(context.get(), url1, |
| 2039 base::Time::Now() + base::TimeDelta::FromHours(1), | 2036 base::Time::Now() + base::TimeDelta::FromHours(1), |
| 2040 base::Time())); | 2037 base::Time())); |
| 2041 | 2038 |
| 2042 context.reset(NewContext(NULL)); | 2039 context.reset(NewContext(NULL)); |
| 2043 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> file_enum( | 2040 scoped_ptr<storage::FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
| 2044 ofu()->CreateFileEnumerator(context.get(), dir, false)); | 2041 ofu()->CreateFileEnumerator(context.get(), dir, false)); |
| 2045 | 2042 |
| 2046 int count = 0; | 2043 int count = 0; |
| 2047 base::FilePath file_path_each; | 2044 base::FilePath file_path_each; |
| 2048 while (!(file_path_each = file_enum->Next()).empty()) { | 2045 while (!(file_path_each = file_enum->Next()).empty()) { |
| 2049 context.reset(NewContext(NULL)); | 2046 context.reset(NewContext(NULL)); |
| 2050 base::File::Info file_info; | 2047 base::File::Info file_info; |
| 2051 base::FilePath file_path; | 2048 base::FilePath file_path; |
| 2052 EXPECT_EQ(base::File::FILE_OK, | 2049 EXPECT_EQ(base::File::FILE_OK, |
| 2053 ofu()->GetFileInfo(context.get(), | 2050 ofu()->GetFileInfo(context.get(), |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 false /* exclusive */, | 2444 false /* exclusive */, |
| 2448 true /* recursive */)); | 2445 true /* recursive */)); |
| 2449 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, | 2446 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, |
| 2450 ofu()->CreateDirectory(UnlimitedContext().get(), | 2447 ofu()->CreateDirectory(UnlimitedContext().get(), |
| 2451 path_in_file_in_file, | 2448 path_in_file_in_file, |
| 2452 false /* exclusive */, | 2449 false /* exclusive */, |
| 2453 true /* recursive */)); | 2450 true /* recursive */)); |
| 2454 } | 2451 } |
| 2455 | 2452 |
| 2456 } // namespace content | 2453 } // namespace content |
| OLD | NEW |