| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_callback_factory.h" | 12 #include "base/memory/scoped_callback_factory.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
| 15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
| 16 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 19 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_path_manager.h" | 20 #include "webkit/fileapi/file_system_path_manager.h" |
| 21 #include "webkit/fileapi/file_system_test_helper.h" | 21 #include "webkit/fileapi/file_system_test_helper.h" |
| 22 #include "webkit/fileapi/file_system_usage_cache.h" | 22 #include "webkit/fileapi/file_system_usage_cache.h" |
| 23 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 23 #include "webkit/fileapi/obfuscated_file_util.h" |
| 24 #include "webkit/quota/mock_special_storage_policy.h" | 24 #include "webkit/quota/mock_special_storage_policy.h" |
| 25 #include "webkit/quota/quota_manager.h" | 25 #include "webkit/quota/quota_manager.h" |
| 26 #include "webkit/quota/quota_types.h" | 26 #include "webkit/quota/quota_types.h" |
| 27 | 27 |
| 28 using namespace fileapi; | 28 using namespace fileapi; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 FilePath UTF8ToFilePath(const std::string& str) { | 32 FilePath UTF8ToFilePath(const std::string& str) { |
| 33 FilePath::StringType result; | 33 FilePath::StringType result; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 {"file://", false, true}, | 121 {"file://", false, true}, |
| 122 {"http://example.com:8000", false, true}, | 122 {"http://example.com:8000", false, true}, |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace (anonymous) | 125 } // namespace (anonymous) |
| 126 | 126 |
| 127 // TODO(ericu): The vast majority of this and the other FSFU subclass tests | 127 // TODO(ericu): The vast majority of this and the other FSFU subclass tests |
| 128 // could theoretically be shared. It would basically be a FSFU interface | 128 // could theoretically be shared. It would basically be a FSFU interface |
| 129 // compliance test, and only the subclass-specific bits that look into the | 129 // compliance test, and only the subclass-specific bits that look into the |
| 130 // implementation would need to be written per-subclass. | 130 // implementation would need to be written per-subclass. |
| 131 class ObfuscatedFileSystemFileUtilTest : public testing::Test { | 131 class ObfuscatedFileUtilTest : public testing::Test { |
| 132 public: | 132 public: |
| 133 ObfuscatedFileSystemFileUtilTest() | 133 ObfuscatedFileUtilTest() |
| 134 : origin_(GURL("http://www.example.com")), | 134 : origin_(GURL("http://www.example.com")), |
| 135 type_(kFileSystemTypeTemporary), | 135 type_(kFileSystemTypeTemporary), |
| 136 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 136 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 137 test_helper_(origin_, type_), | 137 test_helper_(origin_, type_), |
| 138 quota_status_(quota::kQuotaStatusUnknown), | 138 quota_status_(quota::kQuotaStatusUnknown), |
| 139 usage_(-1) { | 139 usage_(-1) { |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SetUp() { | 142 void SetUp() { |
| 143 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 143 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 base::MessageLoopProxy::current(), | 156 base::MessageLoopProxy::current(), |
| 157 base::MessageLoopProxy::current(), | 157 base::MessageLoopProxy::current(), |
| 158 new quota::MockSpecialStoragePolicy(), | 158 new quota::MockSpecialStoragePolicy(), |
| 159 quota_manager_->proxy(), | 159 quota_manager_->proxy(), |
| 160 data_dir_.path(), | 160 data_dir_.path(), |
| 161 false /* incognito */, | 161 false /* incognito */, |
| 162 true /* allow_file_access_from_files */, | 162 true /* allow_file_access_from_files */, |
| 163 false /* unlimited_quota */, | 163 false /* unlimited_quota */, |
| 164 NULL /* path_manager */); | 164 NULL /* path_manager */); |
| 165 | 165 |
| 166 obfuscated_file_system_file_util_ = | 166 obfuscated_file_util_ = static_cast<ObfuscatedFileUtil*>( |
| 167 static_cast<ObfuscatedFileSystemFileUtil*>( | 167 file_system_context_->path_manager()->GetFileUtil(type_)); |
| 168 file_system_context_->path_manager()->GetFileSystemFileUtil(type_)); | |
| 169 | |
| 170 | 168 |
| 171 test_helper_.SetUp(file_system_context_.get(), | 169 test_helper_.SetUp(file_system_context_.get(), |
| 172 obfuscated_file_system_file_util_.get()); | 170 obfuscated_file_util_.get()); |
| 173 } | 171 } |
| 174 | 172 |
| 175 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { | 173 FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) { |
| 176 FileSystemOperationContext* context; | 174 FileSystemOperationContext* context; |
| 177 if (helper) | 175 if (helper) |
| 178 context = helper->NewOperationContext(); | 176 context = helper->NewOperationContext(); |
| 179 else | 177 else |
| 180 context = test_helper_.NewOperationContext(); | 178 context = test_helper_.NewOperationContext(); |
| 181 context->set_allowed_bytes_growth(1024 * 1024); // Big enough for all tests. | 179 context->set_allowed_bytes_growth(1024 * 1024); // Big enough for all tests. |
| 182 return context; | 180 return context; |
| 183 } | 181 } |
| 184 | 182 |
| 185 // This can only be used after SetUp has run and created file_system_context_ | 183 // This can only be used after SetUp has run and created file_system_context_ |
| 186 // and obfuscated_file_system_file_util_. | 184 // and obfuscated_file_util_. |
| 187 // Use this for tests which need to run in multiple origins; we need a test | 185 // Use this for tests which need to run in multiple origins; we need a test |
| 188 // helper per origin. | 186 // helper per origin. |
| 189 FileSystemTestOriginHelper* NewHelper( | 187 FileSystemTestOriginHelper* NewHelper( |
| 190 const GURL& origin, fileapi::FileSystemType type) { | 188 const GURL& origin, fileapi::FileSystemType type) { |
| 191 FileSystemTestOriginHelper* helper = | 189 FileSystemTestOriginHelper* helper = |
| 192 new FileSystemTestOriginHelper(origin, type); | 190 new FileSystemTestOriginHelper(origin, type); |
| 193 | 191 |
| 194 helper->SetUp(file_system_context_.get(), | 192 helper->SetUp(file_system_context_.get(), |
| 195 obfuscated_file_system_file_util_.get()); | 193 obfuscated_file_util_.get()); |
| 196 return helper; | 194 return helper; |
| 197 } | 195 } |
| 198 | 196 |
| 199 ObfuscatedFileSystemFileUtil* ofsfu() { | 197 ObfuscatedFileUtil* ofu() { |
| 200 return obfuscated_file_system_file_util_.get(); | 198 return obfuscated_file_util_.get(); |
| 201 } | 199 } |
| 202 | 200 |
| 203 const FilePath& test_directory() const { | 201 const FilePath& test_directory() const { |
| 204 return data_dir_.path(); | 202 return data_dir_.path(); |
| 205 } | 203 } |
| 206 | 204 |
| 207 const GURL& origin() const { | 205 const GURL& origin() const { |
| 208 return origin_; | 206 return origin_; |
| 209 } | 207 } |
| 210 | 208 |
| 211 fileapi::FileSystemType type() const { | 209 fileapi::FileSystemType type() const { |
| 212 return type_; | 210 return type_; |
| 213 } | 211 } |
| 214 | 212 |
| 215 void GetUsageFromQuotaManager() { | 213 void GetUsageFromQuotaManager() { |
| 216 quota_manager_->GetUsageAndQuota( | 214 quota_manager_->GetUsageAndQuota( |
| 217 origin(), test_helper_.storage_type(), | 215 origin(), test_helper_.storage_type(), |
| 218 callback_factory_.NewCallback( | 216 callback_factory_.NewCallback( |
| 219 &ObfuscatedFileSystemFileUtilTest::OnGetUsage)); | 217 &ObfuscatedFileUtilTest::OnGetUsage)); |
| 220 MessageLoop::current()->RunAllPending(); | 218 MessageLoop::current()->RunAllPending(); |
| 221 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); | 219 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); |
| 222 } | 220 } |
| 223 | 221 |
| 224 void RevokeUsageCache() { | 222 void RevokeUsageCache() { |
| 225 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); | 223 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); |
| 226 ASSERT_TRUE(test_helper_.RevokeUsageCache()); | 224 ASSERT_TRUE(test_helper_.RevokeUsageCache()); |
| 227 } | 225 } |
| 228 | 226 |
| 229 int64 SizeInUsageFile() { | 227 int64 SizeInUsageFile() { |
| 230 return test_helper_.GetCachedOriginUsage(); | 228 return test_helper_.GetCachedOriginUsage(); |
| 231 } | 229 } |
| 232 | 230 |
| 233 int64 usage() const { return usage_; } | 231 int64 usage() const { return usage_; } |
| 234 | 232 |
| 235 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) { | 233 void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) { |
| 236 EXPECT_EQ(quota::kQuotaStatusOk, status); | 234 EXPECT_EQ(quota::kQuotaStatusOk, status); |
| 237 quota_status_ = status; | 235 quota_status_ = status; |
| 238 usage_ = usage; | 236 usage_ = usage; |
| 239 } | 237 } |
| 240 | 238 |
| 241 void CheckFileAndCloseHandle( | 239 void CheckFileAndCloseHandle( |
| 242 const FilePath& virtual_path, PlatformFile file_handle) { | 240 const FilePath& virtual_path, PlatformFile file_handle) { |
| 243 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 241 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 244 FilePath local_path; | 242 FilePath local_path; |
| 245 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 243 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( |
| 246 context.get(), virtual_path, &local_path)); | 244 context.get(), virtual_path, &local_path)); |
| 247 | 245 |
| 248 base::PlatformFileInfo file_info0; | 246 base::PlatformFileInfo file_info0; |
| 249 FilePath data_path; | 247 FilePath data_path; |
| 250 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 248 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 251 context.get(), virtual_path, &file_info0, &data_path)); | 249 context.get(), virtual_path, &file_info0, &data_path)); |
| 252 EXPECT_EQ(data_path, local_path); | 250 EXPECT_EQ(data_path, local_path); |
| 253 EXPECT_TRUE(FileExists(data_path)); | 251 EXPECT_TRUE(FileExists(data_path)); |
| 254 EXPECT_EQ(0, GetSize(data_path)); | 252 EXPECT_EQ(0, GetSize(data_path)); |
| 255 | 253 |
| 256 const char data[] = "test data"; | 254 const char data[] = "test data"; |
| 257 const int length = arraysize(data) - 1; | 255 const int length = arraysize(data) - 1; |
| 258 | 256 |
| 259 if (base::kInvalidPlatformFileValue == file_handle) { | 257 if (base::kInvalidPlatformFileValue == file_handle) { |
| 260 bool created = true; | 258 bool created = true; |
| 261 PlatformFileError error; | 259 PlatformFileError error; |
| 262 file_handle = base::CreatePlatformFile( | 260 file_handle = base::CreatePlatformFile( |
| 263 data_path, | 261 data_path, |
| 264 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | 262 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, |
| 265 &created, | 263 &created, |
| 266 &error); | 264 &error); |
| 267 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 265 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
| 268 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | 266 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
| 269 EXPECT_FALSE(created); | 267 EXPECT_FALSE(created); |
| 270 } | 268 } |
| 271 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); | 269 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); |
| 272 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 270 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
| 273 | 271 |
| 274 base::PlatformFileInfo file_info1; | 272 base::PlatformFileInfo file_info1; |
| 275 EXPECT_EQ(length, GetSize(data_path)); | 273 EXPECT_EQ(length, GetSize(data_path)); |
| 276 context.reset(NewContext(NULL)); | 274 context.reset(NewContext(NULL)); |
| 277 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 275 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 278 context.get(), virtual_path, &file_info1, &data_path)); | 276 context.get(), virtual_path, &file_info1, &data_path)); |
| 279 EXPECT_EQ(data_path, local_path); | 277 EXPECT_EQ(data_path, local_path); |
| 280 | 278 |
| 281 EXPECT_FALSE(file_info0.is_directory); | 279 EXPECT_FALSE(file_info0.is_directory); |
| 282 EXPECT_FALSE(file_info1.is_directory); | 280 EXPECT_FALSE(file_info1.is_directory); |
| 283 EXPECT_FALSE(file_info0.is_symbolic_link); | 281 EXPECT_FALSE(file_info0.is_symbolic_link); |
| 284 EXPECT_FALSE(file_info1.is_symbolic_link); | 282 EXPECT_FALSE(file_info1.is_symbolic_link); |
| 285 EXPECT_EQ(0, file_info0.size); | 283 EXPECT_EQ(0, file_info0.size); |
| 286 EXPECT_EQ(length, file_info1.size); | 284 EXPECT_EQ(length, file_info1.size); |
| 287 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); | 285 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); |
| 288 | 286 |
| 289 context.reset(NewContext(NULL)); | 287 context.reset(NewContext(NULL)); |
| 290 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 288 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( |
| 291 context.get(), virtual_path, length * 2)); | 289 context.get(), virtual_path, length * 2)); |
| 292 EXPECT_EQ(length * 2, GetSize(data_path)); | 290 EXPECT_EQ(length * 2, GetSize(data_path)); |
| 293 | 291 |
| 294 context.reset(NewContext(NULL)); | 292 context.reset(NewContext(NULL)); |
| 295 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 293 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( |
| 296 context.get(), virtual_path, 0)); | 294 context.get(), virtual_path, 0)); |
| 297 EXPECT_EQ(0, GetSize(data_path)); | 295 EXPECT_EQ(0, GetSize(data_path)); |
| 298 } | 296 } |
| 299 | 297 |
| 300 void ValidateTestDirectory( | 298 void ValidateTestDirectory( |
| 301 const FilePath& root_path, | 299 const FilePath& root_path, |
| 302 const std::set<FilePath::StringType>& files, | 300 const std::set<FilePath::StringType>& files, |
| 303 const std::set<FilePath::StringType>& directories) { | 301 const std::set<FilePath::StringType>& directories) { |
| 304 scoped_ptr<FileSystemOperationContext> context; | 302 scoped_ptr<FileSystemOperationContext> context; |
| 305 std::set<FilePath::StringType>::const_iterator iter; | 303 std::set<FilePath::StringType>::const_iterator iter; |
| 306 for (iter = files.begin(); iter != files.end(); ++iter) { | 304 for (iter = files.begin(); iter != files.end(); ++iter) { |
| 307 bool created = true; | 305 bool created = true; |
| 308 context.reset(NewContext(NULL)); | 306 context.reset(NewContext(NULL)); |
| 309 ASSERT_EQ(base::PLATFORM_FILE_OK, | 307 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 310 ofsfu()->EnsureFileExists( | 308 ofu()->EnsureFileExists( |
| 311 context.get(), root_path.Append(*iter), | 309 context.get(), root_path.Append(*iter), |
| 312 &created)); | 310 &created)); |
| 313 ASSERT_FALSE(created); | 311 ASSERT_FALSE(created); |
| 314 } | 312 } |
| 315 for (iter = directories.begin(); iter != directories.end(); ++iter) { | 313 for (iter = directories.begin(); iter != directories.end(); ++iter) { |
| 316 context.reset(NewContext(NULL)); | 314 context.reset(NewContext(NULL)); |
| 317 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), | 315 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), |
| 318 root_path.Append(*iter))); | 316 root_path.Append(*iter))); |
| 319 } | 317 } |
| 320 } | 318 } |
| 321 | 319 |
| 322 void FillTestDirectory( | 320 void FillTestDirectory( |
| 323 const FilePath& root_path, | 321 const FilePath& root_path, |
| 324 std::set<FilePath::StringType>* files, | 322 std::set<FilePath::StringType>* files, |
| 325 std::set<FilePath::StringType>* directories) { | 323 std::set<FilePath::StringType>* directories) { |
| 326 scoped_ptr<FileSystemOperationContext> context; | 324 scoped_ptr<FileSystemOperationContext> context; |
| 327 context.reset(NewContext(NULL)); | 325 context.reset(NewContext(NULL)); |
| 328 std::vector<base::FileUtilProxy::Entry> entries; | 326 std::vector<base::FileUtilProxy::Entry> entries; |
| 329 EXPECT_EQ(base::PLATFORM_FILE_OK, | 327 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 330 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 328 ofu()->ReadDirectory(context.get(), root_path, &entries)); |
| 331 EXPECT_EQ(0UL, entries.size()); | 329 EXPECT_EQ(0UL, entries.size()); |
| 332 | 330 |
| 333 files->clear(); | 331 files->clear(); |
| 334 files->insert(FILE_PATH_LITERAL("first")); | 332 files->insert(FILE_PATH_LITERAL("first")); |
| 335 files->insert(FILE_PATH_LITERAL("second")); | 333 files->insert(FILE_PATH_LITERAL("second")); |
| 336 files->insert(FILE_PATH_LITERAL("third")); | 334 files->insert(FILE_PATH_LITERAL("third")); |
| 337 directories->clear(); | 335 directories->clear(); |
| 338 directories->insert(FILE_PATH_LITERAL("fourth")); | 336 directories->insert(FILE_PATH_LITERAL("fourth")); |
| 339 directories->insert(FILE_PATH_LITERAL("fifth")); | 337 directories->insert(FILE_PATH_LITERAL("fifth")); |
| 340 directories->insert(FILE_PATH_LITERAL("sixth")); | 338 directories->insert(FILE_PATH_LITERAL("sixth")); |
| 341 std::set<FilePath::StringType>::iterator iter; | 339 std::set<FilePath::StringType>::iterator iter; |
| 342 for (iter = files->begin(); iter != files->end(); ++iter) { | 340 for (iter = files->begin(); iter != files->end(); ++iter) { |
| 343 bool created = false; | 341 bool created = false; |
| 344 context.reset(NewContext(NULL)); | 342 context.reset(NewContext(NULL)); |
| 345 ASSERT_EQ(base::PLATFORM_FILE_OK, | 343 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 346 ofsfu()->EnsureFileExists( | 344 ofu()->EnsureFileExists( |
| 347 context.get(), root_path.Append(*iter), &created)); | 345 context.get(), root_path.Append(*iter), &created)); |
| 348 ASSERT_TRUE(created); | 346 ASSERT_TRUE(created); |
| 349 } | 347 } |
| 350 for (iter = directories->begin(); iter != directories->end(); ++iter) { | 348 for (iter = directories->begin(); iter != directories->end(); ++iter) { |
| 351 bool exclusive = true; | 349 bool exclusive = true; |
| 352 bool recursive = false; | 350 bool recursive = false; |
| 353 context.reset(NewContext(NULL)); | 351 context.reset(NewContext(NULL)); |
| 354 EXPECT_EQ(base::PLATFORM_FILE_OK, | 352 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 355 ofsfu()->CreateDirectory( | 353 ofu()->CreateDirectory( |
| 356 context.get(), root_path.Append(*iter), exclusive, recursive)); | 354 context.get(), root_path.Append(*iter), exclusive, recursive)); |
| 357 } | 355 } |
| 358 ValidateTestDirectory(root_path, *files, *directories); | 356 ValidateTestDirectory(root_path, *files, *directories); |
| 359 } | 357 } |
| 360 | 358 |
| 361 void TestReadDirectoryHelper(const FilePath& root_path) { | 359 void TestReadDirectoryHelper(const FilePath& root_path) { |
| 362 std::set<FilePath::StringType> files; | 360 std::set<FilePath::StringType> files; |
| 363 std::set<FilePath::StringType> directories; | 361 std::set<FilePath::StringType> directories; |
| 364 FillTestDirectory(root_path, &files, &directories); | 362 FillTestDirectory(root_path, &files, &directories); |
| 365 | 363 |
| 366 scoped_ptr<FileSystemOperationContext> context; | 364 scoped_ptr<FileSystemOperationContext> context; |
| 367 std::vector<base::FileUtilProxy::Entry> entries; | 365 std::vector<base::FileUtilProxy::Entry> entries; |
| 368 context.reset(NewContext(NULL)); | 366 context.reset(NewContext(NULL)); |
| 369 EXPECT_EQ(base::PLATFORM_FILE_OK, | 367 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 370 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); | 368 ofu()->ReadDirectory(context.get(), root_path, &entries)); |
| 371 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; | 369 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; |
| 372 EXPECT_EQ(files.size() + directories.size(), entries.size()); | 370 EXPECT_EQ(files.size() + directories.size(), entries.size()); |
| 373 for (entry_iter = entries.begin(); entry_iter != entries.end(); | 371 for (entry_iter = entries.begin(); entry_iter != entries.end(); |
| 374 ++entry_iter) { | 372 ++entry_iter) { |
| 375 const base::FileUtilProxy::Entry& entry = *entry_iter; | 373 const base::FileUtilProxy::Entry& entry = *entry_iter; |
| 376 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); | 374 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); |
| 377 if (iter != files.end()) { | 375 if (iter != files.end()) { |
| 378 EXPECT_FALSE(entry.is_directory); | 376 EXPECT_FALSE(entry.is_directory); |
| 379 files.erase(iter); | 377 files.erase(iter); |
| 380 continue; | 378 continue; |
| 381 } | 379 } |
| 382 iter = directories.find(entry.name); | 380 iter = directories.find(entry.name); |
| 383 EXPECT_FALSE(directories.end() == iter); | 381 EXPECT_FALSE(directories.end() == iter); |
| 384 EXPECT_TRUE(entry.is_directory); | 382 EXPECT_TRUE(entry.is_directory); |
| 385 directories.erase(iter); | 383 directories.erase(iter); |
| 386 } | 384 } |
| 387 } | 385 } |
| 388 | 386 |
| 389 void TestTouchHelper(const FilePath& path, bool new_file) { | 387 void TestTouchHelper(const FilePath& path, bool new_file) { |
| 390 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 388 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
| 391 base::Time last_modified_time = base::Time::Now(); | 389 base::Time last_modified_time = base::Time::Now(); |
| 392 scoped_ptr<FileSystemOperationContext> context; | 390 scoped_ptr<FileSystemOperationContext> context; |
| 393 | 391 |
| 394 if (new_file) { | 392 if (new_file) { |
| 395 // Verify that file creation requires sufficient quota for the path. | 393 // Verify that file creation requires sufficient quota for the path. |
| 396 context.reset(NewContext(NULL)); | 394 context.reset(NewContext(NULL)); |
| 397 context->set_allowed_bytes_growth( | 395 context->set_allowed_bytes_growth( |
| 398 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path) - 1); | 396 ObfuscatedFileUtil::ComputeFilePathCost(path) - 1); |
| 399 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 397 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 400 ofsfu()->Touch( | 398 ofu()->Touch( |
| 401 context.get(), path, last_access_time, last_modified_time)); | 399 context.get(), path, last_access_time, last_modified_time)); |
| 402 } | 400 } |
| 403 | 401 |
| 404 context.reset(NewContext(NULL)); | 402 context.reset(NewContext(NULL)); |
| 405 context->set_allowed_bytes_growth( | 403 context->set_allowed_bytes_growth( |
| 406 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path)); | 404 ObfuscatedFileUtil::ComputeFilePathCost(path)); |
| 407 EXPECT_EQ(base::PLATFORM_FILE_OK, | 405 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 408 ofsfu()->Touch( | 406 ofu()->Touch( |
| 409 context.get(), path, last_access_time, last_modified_time)); | 407 context.get(), path, last_access_time, last_modified_time)); |
| 410 FilePath local_path; | 408 FilePath local_path; |
| 411 base::PlatformFileInfo file_info; | 409 base::PlatformFileInfo file_info; |
| 412 context.reset(NewContext(NULL)); | 410 context.reset(NewContext(NULL)); |
| 413 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 411 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 414 context.get(), path, &file_info, &local_path)); | 412 context.get(), path, &file_info, &local_path)); |
| 415 // We compare as time_t here to lower our resolution, to avoid false | 413 // We compare as time_t here to lower our resolution, to avoid false |
| 416 // negatives caused by conversion to the local filesystem's native | 414 // negatives caused by conversion to the local filesystem's native |
| 417 // representation and back. | 415 // representation and back. |
| 418 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 416 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
| 419 | 417 |
| 420 context.reset(NewContext(NULL)); | 418 context.reset(NewContext(NULL)); |
| 421 last_modified_time += base::TimeDelta::FromHours(1); | 419 last_modified_time += base::TimeDelta::FromHours(1); |
| 422 EXPECT_EQ(base::PLATFORM_FILE_OK, | 420 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 423 ofsfu()->Touch( | 421 ofu()->Touch( |
| 424 context.get(), path, last_access_time, last_modified_time)); | 422 context.get(), path, last_access_time, last_modified_time)); |
| 425 context.reset(NewContext(NULL)); | 423 context.reset(NewContext(NULL)); |
| 426 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 424 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 427 context.get(), path, &file_info, &local_path)); | 425 context.get(), path, &file_info, &local_path)); |
| 428 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); | 426 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); |
| 429 } | 427 } |
| 430 | 428 |
| 431 void TestCopyInForeignFileHelper(bool overwrite) { | 429 void TestCopyInForeignFileHelper(bool overwrite) { |
| 432 ScopedTempDir source_dir; | 430 ScopedTempDir source_dir; |
| 433 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 431 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
| 434 FilePath root_path = source_dir.path(); | 432 FilePath root_path = source_dir.path(); |
| 435 FilePath src_path = root_path.AppendASCII("file_name"); | 433 FilePath src_path = root_path.AppendASCII("file_name"); |
| 436 FilePath dest_path(FILE_PATH_LITERAL("new file")); | 434 FilePath dest_path(FILE_PATH_LITERAL("new file")); |
| 437 int64 src_file_length = 87; | 435 int64 src_file_length = 87; |
| 438 | 436 |
| 439 base::PlatformFileError error_code; | 437 base::PlatformFileError error_code; |
| 440 bool created = false; | 438 bool created = false; |
| 441 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 439 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
| 442 base::PlatformFile file_handle = | 440 base::PlatformFile file_handle = |
| 443 base::CreatePlatformFile( | 441 base::CreatePlatformFile( |
| 444 src_path, file_flags, &created, &error_code); | 442 src_path, file_flags, &created, &error_code); |
| 445 EXPECT_TRUE(created); | 443 EXPECT_TRUE(created); |
| 446 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | 444 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
| 447 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 445 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
| 448 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); | 446 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); |
| 449 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 447 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
| 450 | 448 |
| 451 scoped_ptr<FileSystemOperationContext> context; | 449 scoped_ptr<FileSystemOperationContext> context; |
| 452 | 450 |
| 453 if (overwrite) { | 451 if (overwrite) { |
| 454 context.reset(NewContext(NULL)); | 452 context.reset(NewContext(NULL)); |
| 455 EXPECT_EQ(base::PLATFORM_FILE_OK, | 453 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 456 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 454 ofu()->EnsureFileExists(context.get(), dest_path, &created)); |
| 457 EXPECT_TRUE(created); | 455 EXPECT_TRUE(created); |
| 458 } | 456 } |
| 459 | 457 |
| 460 const int64 path_cost = | 458 const int64 path_cost = |
| 461 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(dest_path); | 459 ObfuscatedFileUtil::ComputeFilePathCost(dest_path); |
| 462 if (!overwrite) { | 460 if (!overwrite) { |
| 463 // Verify that file creation requires sufficient quota for the path. | 461 // Verify that file creation requires sufficient quota for the path. |
| 464 context.reset(NewContext(NULL)); | 462 context.reset(NewContext(NULL)); |
| 465 context->set_allowed_bytes_growth(path_cost + src_file_length - 1); | 463 context->set_allowed_bytes_growth(path_cost + src_file_length - 1); |
| 466 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 464 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 467 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); | 465 ofu()->CopyInForeignFile(context.get(), src_path, dest_path)); |
| 468 } | 466 } |
| 469 | 467 |
| 470 context.reset(NewContext(NULL)); | 468 context.reset(NewContext(NULL)); |
| 471 context->set_allowed_bytes_growth(path_cost + src_file_length); | 469 context->set_allowed_bytes_growth(path_cost + src_file_length); |
| 472 EXPECT_EQ(base::PLATFORM_FILE_OK, | 470 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 473 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); | 471 ofu()->CopyInForeignFile(context.get(), src_path, dest_path)); |
| 474 | 472 |
| 475 context.reset(NewContext(NULL)); | 473 context.reset(NewContext(NULL)); |
| 476 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); | 474 EXPECT_TRUE(ofu()->PathExists(context.get(), dest_path)); |
| 477 context.reset(NewContext(NULL)); | 475 context.reset(NewContext(NULL)); |
| 478 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 476 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path)); |
| 479 context.reset(NewContext(NULL)); | 477 context.reset(NewContext(NULL)); |
| 480 base::PlatformFileInfo file_info; | 478 base::PlatformFileInfo file_info; |
| 481 FilePath data_path; | 479 FilePath data_path; |
| 482 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 480 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 483 context.get(), dest_path, &file_info, &data_path)); | 481 context.get(), dest_path, &file_info, &data_path)); |
| 484 EXPECT_NE(data_path, src_path); | 482 EXPECT_NE(data_path, src_path); |
| 485 EXPECT_TRUE(FileExists(data_path)); | 483 EXPECT_TRUE(FileExists(data_path)); |
| 486 EXPECT_EQ(src_file_length, GetSize(data_path)); | 484 EXPECT_EQ(src_file_length, GetSize(data_path)); |
| 487 | 485 |
| 488 EXPECT_EQ(base::PLATFORM_FILE_OK, | 486 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 489 ofsfu()->DeleteFile(context.get(), dest_path)); | 487 ofu()->DeleteFile(context.get(), dest_path)); |
| 490 } | 488 } |
| 491 | 489 |
| 492 private: | 490 private: |
| 493 ScopedTempDir data_dir_; | 491 ScopedTempDir data_dir_; |
| 494 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; | 492 scoped_refptr<ObfuscatedFileUtil> obfuscated_file_util_; |
| 495 scoped_refptr<quota::QuotaManager> quota_manager_; | 493 scoped_refptr<quota::QuotaManager> quota_manager_; |
| 496 scoped_refptr<FileSystemContext> file_system_context_; | 494 scoped_refptr<FileSystemContext> file_system_context_; |
| 497 GURL origin_; | 495 GURL origin_; |
| 498 fileapi::FileSystemType type_; | 496 fileapi::FileSystemType type_; |
| 499 base::ScopedCallbackFactory<ObfuscatedFileSystemFileUtilTest> | 497 base::ScopedCallbackFactory<ObfuscatedFileUtilTest> |
| 500 callback_factory_; | 498 callback_factory_; |
| 501 FileSystemTestOriginHelper test_helper_; | 499 FileSystemTestOriginHelper test_helper_; |
| 502 quota::QuotaStatusCode quota_status_; | 500 quota::QuotaStatusCode quota_status_; |
| 503 int64 usage_; | 501 int64 usage_; |
| 504 | 502 |
| 505 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); | 503 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); |
| 506 }; | 504 }; |
| 507 | 505 |
| 508 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { | 506 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { |
| 509 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; | 507 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; |
| 510 bool created; | 508 bool created; |
| 511 FilePath path = UTF8ToFilePath("fake/file"); | 509 FilePath path = UTF8ToFilePath("fake/file"); |
| 512 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 510 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 513 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 511 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
| 514 | 512 |
| 515 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 513 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 516 ofsfu()->CreateOrOpen( | 514 ofu()->CreateOrOpen( |
| 517 context.get(), path, file_flags, &file_handle, | 515 context.get(), path, file_flags, &file_handle, |
| 518 &created)); | 516 &created)); |
| 519 | 517 |
| 520 context.reset(NewContext(NULL)); | 518 context.reset(NewContext(NULL)); |
| 521 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 519 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 522 ofsfu()->DeleteFile(context.get(), path)); | 520 ofu()->DeleteFile(context.get(), path)); |
| 523 | 521 |
| 524 path = UTF8ToFilePath("test file"); | 522 path = UTF8ToFilePath("test file"); |
| 525 | 523 |
| 526 // Verify that file creation requires sufficient quota for the path. | 524 // Verify that file creation requires sufficient quota for the path. |
| 527 context.reset(NewContext(NULL)); | 525 context.reset(NewContext(NULL)); |
| 528 context->set_allowed_bytes_growth( | 526 context->set_allowed_bytes_growth( |
| 529 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path) - 1); | 527 ObfuscatedFileUtil::ComputeFilePathCost(path) - 1); |
| 530 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 528 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 531 ofsfu()->CreateOrOpen( | 529 ofu()->CreateOrOpen( |
| 532 context.get(), path, file_flags, &file_handle, &created)); | 530 context.get(), path, file_flags, &file_handle, &created)); |
| 533 | 531 |
| 534 context.reset(NewContext(NULL)); | 532 context.reset(NewContext(NULL)); |
| 535 context->set_allowed_bytes_growth( | 533 context->set_allowed_bytes_growth( |
| 536 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path)); | 534 ObfuscatedFileUtil::ComputeFilePathCost(path)); |
| 537 ASSERT_EQ(base::PLATFORM_FILE_OK, | 535 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 538 ofsfu()->CreateOrOpen( | 536 ofu()->CreateOrOpen( |
| 539 context.get(), path, file_flags, &file_handle, &created)); | 537 context.get(), path, file_flags, &file_handle, &created)); |
| 540 ASSERT_TRUE(created); | 538 ASSERT_TRUE(created); |
| 541 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 539 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
| 542 | 540 |
| 543 CheckFileAndCloseHandle(path, file_handle); | 541 CheckFileAndCloseHandle(path, file_handle); |
| 544 | 542 |
| 545 context.reset(NewContext(NULL)); | 543 context.reset(NewContext(NULL)); |
| 546 FilePath local_path; | 544 FilePath local_path; |
| 547 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 545 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( |
| 548 context.get(), path, &local_path)); | 546 context.get(), path, &local_path)); |
| 549 EXPECT_TRUE(file_util::PathExists(local_path)); | 547 EXPECT_TRUE(file_util::PathExists(local_path)); |
| 550 | 548 |
| 551 // Verify that deleting a file isn't stopped by zero quota, and that it frees | 549 // Verify that deleting a file isn't stopped by zero quota, and that it frees |
| 552 // up quote from its path. | 550 // up quote from its path. |
| 553 context.reset(NewContext(NULL)); | 551 context.reset(NewContext(NULL)); |
| 554 context->set_allowed_bytes_growth(0); | 552 context->set_allowed_bytes_growth(0); |
| 555 EXPECT_EQ(base::PLATFORM_FILE_OK, | 553 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 556 ofsfu()->DeleteFile(context.get(), path)); | 554 ofu()->DeleteFile(context.get(), path)); |
| 557 EXPECT_FALSE(file_util::PathExists(local_path)); | 555 EXPECT_FALSE(file_util::PathExists(local_path)); |
| 558 EXPECT_EQ(ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path), | 556 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path), |
| 559 context->allowed_bytes_growth()); | 557 context->allowed_bytes_growth()); |
| 560 | 558 |
| 561 context.reset(NewContext(NULL)); | 559 context.reset(NewContext(NULL)); |
| 562 bool exclusive = true; | 560 bool exclusive = true; |
| 563 bool recursive = true; | 561 bool recursive = true; |
| 564 FilePath directory_path = UTF8ToFilePath("series/of/directories"); | 562 FilePath directory_path = UTF8ToFilePath("series/of/directories"); |
| 565 path = directory_path.AppendASCII("file name"); | 563 path = directory_path.AppendASCII("file name"); |
| 566 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 564 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 567 context.get(), directory_path, exclusive, recursive)); | 565 context.get(), directory_path, exclusive, recursive)); |
| 568 | 566 |
| 569 context.reset(NewContext(NULL)); | 567 context.reset(NewContext(NULL)); |
| 570 file_handle = base::kInvalidPlatformFileValue; | 568 file_handle = base::kInvalidPlatformFileValue; |
| 571 ASSERT_EQ(base::PLATFORM_FILE_OK, | 569 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 572 ofsfu()->CreateOrOpen( | 570 ofu()->CreateOrOpen( |
| 573 context.get(), path, file_flags, &file_handle, &created)); | 571 context.get(), path, file_flags, &file_handle, &created)); |
| 574 ASSERT_TRUE(created); | 572 ASSERT_TRUE(created); |
| 575 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); | 573 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); |
| 576 | 574 |
| 577 CheckFileAndCloseHandle(path, file_handle); | 575 CheckFileAndCloseHandle(path, file_handle); |
| 578 | 576 |
| 579 context.reset(NewContext(NULL)); | 577 context.reset(NewContext(NULL)); |
| 580 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 578 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( |
| 581 context.get(), path, &local_path)); | 579 context.get(), path, &local_path)); |
| 582 EXPECT_TRUE(file_util::PathExists(local_path)); | 580 EXPECT_TRUE(file_util::PathExists(local_path)); |
| 583 | 581 |
| 584 context.reset(NewContext(NULL)); | 582 context.reset(NewContext(NULL)); |
| 585 EXPECT_EQ(base::PLATFORM_FILE_OK, | 583 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 586 ofsfu()->DeleteFile(context.get(), path)); | 584 ofu()->DeleteFile(context.get(), path)); |
| 587 EXPECT_FALSE(file_util::PathExists(local_path)); | 585 EXPECT_FALSE(file_util::PathExists(local_path)); |
| 588 } | 586 } |
| 589 | 587 |
| 590 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { | 588 TEST_F(ObfuscatedFileUtilTest, TestTruncate) { |
| 591 bool created = false; | 589 bool created = false; |
| 592 FilePath path = UTF8ToFilePath("file"); | 590 FilePath path = UTF8ToFilePath("file"); |
| 593 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 591 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 594 | 592 |
| 595 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 593 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 596 ofsfu()->Truncate(context.get(), path, 4)); | 594 ofu()->Truncate(context.get(), path, 4)); |
| 597 | 595 |
| 598 context.reset(NewContext(NULL)); | 596 context.reset(NewContext(NULL)); |
| 599 ASSERT_EQ(base::PLATFORM_FILE_OK, | 597 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 600 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 598 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 601 ASSERT_TRUE(created); | 599 ASSERT_TRUE(created); |
| 602 | 600 |
| 603 context.reset(NewContext(NULL)); | 601 context.reset(NewContext(NULL)); |
| 604 FilePath local_path; | 602 FilePath local_path; |
| 605 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( | 603 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( |
| 606 context.get(), path, &local_path)); | 604 context.get(), path, &local_path)); |
| 607 EXPECT_EQ(0, GetSize(local_path)); | 605 EXPECT_EQ(0, GetSize(local_path)); |
| 608 | 606 |
| 609 context.reset(NewContext(NULL)); | 607 context.reset(NewContext(NULL)); |
| 610 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 608 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( |
| 611 context.get(), path, 10)); | 609 context.get(), path, 10)); |
| 612 EXPECT_EQ(10, GetSize(local_path)); | 610 EXPECT_EQ(10, GetSize(local_path)); |
| 613 | 611 |
| 614 context.reset(NewContext(NULL)); | 612 context.reset(NewContext(NULL)); |
| 615 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( | 613 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate( |
| 616 context.get(), path, 1)); | 614 context.get(), path, 1)); |
| 617 EXPECT_EQ(1, GetSize(local_path)); | 615 EXPECT_EQ(1, GetSize(local_path)); |
| 618 | 616 |
| 619 context.reset(NewContext(NULL)); | 617 context.reset(NewContext(NULL)); |
| 620 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 618 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path)); |
| 621 context.reset(NewContext(NULL)); | 619 context.reset(NewContext(NULL)); |
| 622 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 620 EXPECT_TRUE(ofu()->PathExists(context.get(), path)); |
| 623 } | 621 } |
| 624 | 622 |
| 625 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { | 623 TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) { |
| 626 FilePath path = UTF8ToFilePath("fake/file"); | 624 FilePath path = UTF8ToFilePath("fake/file"); |
| 627 bool created = false; | 625 bool created = false; |
| 628 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 626 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 629 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 627 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 630 ofsfu()->EnsureFileExists( | 628 ofu()->EnsureFileExists( |
| 631 context.get(), path, &created)); | 629 context.get(), path, &created)); |
| 632 | 630 |
| 633 // Verify that file creation requires sufficient quota for the path. | 631 // Verify that file creation requires sufficient quota for the path. |
| 634 context.reset(NewContext(NULL)); | 632 context.reset(NewContext(NULL)); |
| 635 path = UTF8ToFilePath("test file"); | 633 path = UTF8ToFilePath("test file"); |
| 636 created = false; | 634 created = false; |
| 637 context->set_allowed_bytes_growth( | 635 context->set_allowed_bytes_growth( |
| 638 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path) - 1); | 636 ObfuscatedFileUtil::ComputeFilePathCost(path) - 1); |
| 639 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 637 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 640 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 638 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 641 ASSERT_FALSE(created); | 639 ASSERT_FALSE(created); |
| 642 | 640 |
| 643 context.reset(NewContext(NULL)); | 641 context.reset(NewContext(NULL)); |
| 644 context->set_allowed_bytes_growth( | 642 context->set_allowed_bytes_growth( |
| 645 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path)); | 643 ObfuscatedFileUtil::ComputeFilePathCost(path)); |
| 646 ASSERT_EQ(base::PLATFORM_FILE_OK, | 644 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 647 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 645 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 648 ASSERT_TRUE(created); | 646 ASSERT_TRUE(created); |
| 649 | 647 |
| 650 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); | 648 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); |
| 651 | 649 |
| 652 context.reset(NewContext(NULL)); | 650 context.reset(NewContext(NULL)); |
| 653 ASSERT_EQ(base::PLATFORM_FILE_OK, | 651 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 654 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 652 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 655 ASSERT_FALSE(created); | 653 ASSERT_FALSE(created); |
| 656 | 654 |
| 657 // Also test in a subdirectory. | 655 // Also test in a subdirectory. |
| 658 path = UTF8ToFilePath("path/to/file.txt"); | 656 path = UTF8ToFilePath("path/to/file.txt"); |
| 659 context.reset(NewContext(NULL)); | 657 context.reset(NewContext(NULL)); |
| 660 bool exclusive = true; | 658 bool exclusive = true; |
| 661 bool recursive = true; | 659 bool recursive = true; |
| 662 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 660 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 663 context.get(), path.DirName(), exclusive, recursive)); | 661 context.get(), path.DirName(), exclusive, recursive)); |
| 664 | 662 |
| 665 context.reset(NewContext(NULL)); | 663 context.reset(NewContext(NULL)); |
| 666 ASSERT_EQ(base::PLATFORM_FILE_OK, | 664 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 667 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 665 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 668 ASSERT_TRUE(created); | 666 ASSERT_TRUE(created); |
| 669 context.reset(NewContext(NULL)); | 667 context.reset(NewContext(NULL)); |
| 670 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 668 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path)); |
| 671 context.reset(NewContext(NULL)); | 669 context.reset(NewContext(NULL)); |
| 672 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 670 EXPECT_TRUE(ofu()->PathExists(context.get(), path)); |
| 673 } | 671 } |
| 674 | 672 |
| 675 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { | 673 TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) { |
| 676 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 674 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 677 | 675 |
| 678 bool exclusive = false; | 676 bool exclusive = false; |
| 679 bool recursive = false; | 677 bool recursive = false; |
| 680 FilePath path = UTF8ToFilePath("foo/bar"); | 678 FilePath path = UTF8ToFilePath("foo/bar"); |
| 681 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( | 679 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CreateDirectory( |
| 682 context.get(), path, exclusive, recursive)); | 680 context.get(), path, exclusive, recursive)); |
| 683 | 681 |
| 684 context.reset(NewContext(NULL)); | 682 context.reset(NewContext(NULL)); |
| 685 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 683 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 686 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 684 ofu()->DeleteSingleDirectory(context.get(), path)); |
| 687 | 685 |
| 688 FilePath root = UTF8ToFilePath(""); | 686 FilePath root = UTF8ToFilePath(""); |
| 689 context.reset(NewContext(NULL)); | 687 context.reset(NewContext(NULL)); |
| 690 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 688 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path)); |
| 691 context.reset(NewContext(NULL)); | 689 context.reset(NewContext(NULL)); |
| 692 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 690 EXPECT_FALSE(ofu()->PathExists(context.get(), path)); |
| 693 context.reset(NewContext(NULL)); | 691 context.reset(NewContext(NULL)); |
| 694 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 692 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), root)); |
| 695 | 693 |
| 696 context.reset(NewContext(NULL)); | 694 context.reset(NewContext(NULL)); |
| 697 exclusive = false; | 695 exclusive = false; |
| 698 recursive = true; | 696 recursive = true; |
| 699 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 697 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 700 context.get(), path, exclusive, recursive)); | 698 context.get(), path, exclusive, recursive)); |
| 701 | 699 |
| 702 context.reset(NewContext(NULL)); | 700 context.reset(NewContext(NULL)); |
| 703 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 701 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path)); |
| 704 context.reset(NewContext(NULL)); | 702 context.reset(NewContext(NULL)); |
| 705 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 703 EXPECT_TRUE(ofu()->PathExists(context.get(), path)); |
| 706 context.reset(NewContext(NULL)); | 704 context.reset(NewContext(NULL)); |
| 707 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); | 705 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), root)); |
| 708 context.reset(NewContext(NULL)); | 706 context.reset(NewContext(NULL)); |
| 709 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); | 707 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path.DirName())); |
| 710 context.reset(NewContext(NULL)); | 708 context.reset(NewContext(NULL)); |
| 711 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); | 709 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), path.DirName())); |
| 712 | 710 |
| 713 // Can't remove a non-empty directory. | 711 // Can't remove a non-empty directory. |
| 714 context.reset(NewContext(NULL)); | 712 context.reset(NewContext(NULL)); |
| 715 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 713 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
| 716 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); | 714 ofu()->DeleteSingleDirectory(context.get(), path.DirName())); |
| 717 | 715 |
| 718 base::PlatformFileInfo file_info; | 716 base::PlatformFileInfo file_info; |
| 719 FilePath local_path; | 717 FilePath local_path; |
| 720 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 718 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 721 context.get(), path, &file_info, &local_path)); | 719 context.get(), path, &file_info, &local_path)); |
| 722 EXPECT_TRUE(local_path.empty()); | 720 EXPECT_TRUE(local_path.empty()); |
| 723 EXPECT_TRUE(file_info.is_directory); | 721 EXPECT_TRUE(file_info.is_directory); |
| 724 EXPECT_FALSE(file_info.is_symbolic_link); | 722 EXPECT_FALSE(file_info.is_symbolic_link); |
| 725 | 723 |
| 726 // Same create again should succeed, since exclusive is false. | 724 // Same create again should succeed, since exclusive is false. |
| 727 context.reset(NewContext(NULL)); | 725 context.reset(NewContext(NULL)); |
| 728 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 726 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 729 context.get(), path, exclusive, recursive)); | 727 context.get(), path, exclusive, recursive)); |
| 730 | 728 |
| 731 exclusive = true; | 729 exclusive = true; |
| 732 recursive = true; | 730 recursive = true; |
| 733 context.reset(NewContext(NULL)); | 731 context.reset(NewContext(NULL)); |
| 734 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 732 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( |
| 735 context.get(), path, exclusive, recursive)); | 733 context.get(), path, exclusive, recursive)); |
| 736 | 734 |
| 737 // Verify that deleting a directory isn't stopped by zero quota, and that it | 735 // Verify that deleting a directory isn't stopped by zero quota, and that it |
| 738 // frees up quota from its path. | 736 // frees up quota from its path. |
| 739 context.reset(NewContext(NULL)); | 737 context.reset(NewContext(NULL)); |
| 740 context->set_allowed_bytes_growth(0); | 738 context->set_allowed_bytes_growth(0); |
| 741 EXPECT_EQ(base::PLATFORM_FILE_OK, | 739 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 742 ofsfu()->DeleteSingleDirectory(context.get(), path)); | 740 ofu()->DeleteSingleDirectory(context.get(), path)); |
| 743 EXPECT_EQ(ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path), | 741 EXPECT_EQ(ObfuscatedFileUtil::ComputeFilePathCost(path), |
| 744 context->allowed_bytes_growth()); | 742 context->allowed_bytes_growth()); |
| 745 | 743 |
| 746 path = UTF8ToFilePath("foo/bop"); | 744 path = UTF8ToFilePath("foo/bop"); |
| 747 | 745 |
| 748 context.reset(NewContext(NULL)); | 746 context.reset(NewContext(NULL)); |
| 749 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 747 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path)); |
| 750 context.reset(NewContext(NULL)); | 748 context.reset(NewContext(NULL)); |
| 751 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 749 EXPECT_FALSE(ofu()->PathExists(context.get(), path)); |
| 752 context.reset(NewContext(NULL)); | 750 context.reset(NewContext(NULL)); |
| 753 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 751 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), path)); |
| 754 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 752 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo( |
| 755 context.get(), path, &file_info, &local_path)); | 753 context.get(), path, &file_info, &local_path)); |
| 756 | 754 |
| 757 // Verify that file creation requires sufficient quota for the path. | 755 // Verify that file creation requires sufficient quota for the path. |
| 758 exclusive = true; | 756 exclusive = true; |
| 759 recursive = false; | 757 recursive = false; |
| 760 context.reset(NewContext(NULL)); | 758 context.reset(NewContext(NULL)); |
| 761 context->set_allowed_bytes_growth( | 759 context->set_allowed_bytes_growth( |
| 762 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path) - 1); | 760 ObfuscatedFileUtil::ComputeFilePathCost(path) - 1); |
| 763 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofsfu()->CreateDirectory( | 761 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, ofu()->CreateDirectory( |
| 764 context.get(), path, exclusive, recursive)); | 762 context.get(), path, exclusive, recursive)); |
| 765 | 763 |
| 766 context.reset(NewContext(NULL)); | 764 context.reset(NewContext(NULL)); |
| 767 context->set_allowed_bytes_growth( | 765 context->set_allowed_bytes_growth( |
| 768 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path)); | 766 ObfuscatedFileUtil::ComputeFilePathCost(path)); |
| 769 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 767 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 770 context.get(), path, exclusive, recursive)); | 768 context.get(), path, exclusive, recursive)); |
| 771 | 769 |
| 772 context.reset(NewContext(NULL)); | 770 context.reset(NewContext(NULL)); |
| 773 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 771 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path)); |
| 774 context.reset(NewContext(NULL)); | 772 context.reset(NewContext(NULL)); |
| 775 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 773 EXPECT_TRUE(ofu()->PathExists(context.get(), path)); |
| 776 | 774 |
| 777 exclusive = true; | 775 exclusive = true; |
| 778 recursive = false; | 776 recursive = false; |
| 779 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 777 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( |
| 780 context.get(), path, exclusive, recursive)); | 778 context.get(), path, exclusive, recursive)); |
| 781 | 779 |
| 782 exclusive = true; | 780 exclusive = true; |
| 783 recursive = false; | 781 recursive = false; |
| 784 path = UTF8ToFilePath("foo"); | 782 path = UTF8ToFilePath("foo"); |
| 785 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 783 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( |
| 786 context.get(), path, exclusive, recursive)); | 784 context.get(), path, exclusive, recursive)); |
| 787 | 785 |
| 788 path = UTF8ToFilePath("blah"); | 786 path = UTF8ToFilePath("blah"); |
| 789 | 787 |
| 790 context.reset(NewContext(NULL)); | 788 context.reset(NewContext(NULL)); |
| 791 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); | 789 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path)); |
| 792 context.reset(NewContext(NULL)); | 790 context.reset(NewContext(NULL)); |
| 793 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); | 791 EXPECT_FALSE(ofu()->PathExists(context.get(), path)); |
| 794 | 792 |
| 795 exclusive = true; | 793 exclusive = true; |
| 796 recursive = false; | 794 recursive = false; |
| 797 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 795 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 798 context.get(), path, exclusive, recursive)); | 796 context.get(), path, exclusive, recursive)); |
| 799 | 797 |
| 800 context.reset(NewContext(NULL)); | 798 context.reset(NewContext(NULL)); |
| 801 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); | 799 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path)); |
| 802 context.reset(NewContext(NULL)); | 800 context.reset(NewContext(NULL)); |
| 803 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); | 801 EXPECT_TRUE(ofu()->PathExists(context.get(), path)); |
| 804 | 802 |
| 805 exclusive = true; | 803 exclusive = true; |
| 806 recursive = false; | 804 recursive = false; |
| 807 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( | 805 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory( |
| 808 context.get(), path, exclusive, recursive)); | 806 context.get(), path, exclusive, recursive)); |
| 809 } | 807 } |
| 810 | 808 |
| 811 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { | 809 TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) { |
| 812 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 810 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 813 bool exclusive = true; | 811 bool exclusive = true; |
| 814 bool recursive = true; | 812 bool recursive = true; |
| 815 FilePath path = UTF8ToFilePath("directory/to/use"); | 813 FilePath path = UTF8ToFilePath("directory/to/use"); |
| 816 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 814 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 817 context.get(), path, exclusive, recursive)); | 815 context.get(), path, exclusive, recursive)); |
| 818 TestReadDirectoryHelper(path); | 816 TestReadDirectoryHelper(path); |
| 819 } | 817 } |
| 820 | 818 |
| 821 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { | 819 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithSlash) { |
| 822 TestReadDirectoryHelper(UTF8ToFilePath("")); | 820 TestReadDirectoryHelper(UTF8ToFilePath("")); |
| 823 } | 821 } |
| 824 | 822 |
| 825 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { | 823 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithEmptyString) { |
| 826 TestReadDirectoryHelper(UTF8ToFilePath("/")); | 824 TestReadDirectoryHelper(UTF8ToFilePath("/")); |
| 827 } | 825 } |
| 828 | 826 |
| 829 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { | 827 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) { |
| 830 FilePath path = UTF8ToFilePath("file"); | 828 FilePath path = UTF8ToFilePath("file"); |
| 831 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 829 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 832 | 830 |
| 833 bool created = false; | 831 bool created = false; |
| 834 ASSERT_EQ(base::PLATFORM_FILE_OK, | 832 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 835 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 833 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 836 ASSERT_TRUE(created); | 834 ASSERT_TRUE(created); |
| 837 | 835 |
| 838 context.reset(NewContext(NULL)); | 836 context.reset(NewContext(NULL)); |
| 839 std::vector<base::FileUtilProxy::Entry> entries; | 837 std::vector<base::FileUtilProxy::Entry> entries; |
| 840 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 838 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 841 ofsfu()->ReadDirectory(context.get(), path, &entries)); | 839 ofu()->ReadDirectory(context.get(), path, &entries)); |
| 842 | 840 |
| 843 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); | 841 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), path)); |
| 844 } | 842 } |
| 845 | 843 |
| 846 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { | 844 TEST_F(ObfuscatedFileUtilTest, TestTouch) { |
| 847 FilePath path = UTF8ToFilePath("fake/file"); | 845 FilePath path = UTF8ToFilePath("fake/file"); |
| 848 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. | 846 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. |
| 849 base::Time last_modified_time = base::Time::Now(); | 847 base::Time last_modified_time = base::Time::Now(); |
| 850 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 848 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 851 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 849 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 852 ofsfu()->Touch( | 850 ofu()->Touch( |
| 853 context.get(), path, last_access_time, last_modified_time)); | 851 context.get(), path, last_access_time, last_modified_time)); |
| 854 | 852 |
| 855 // Touch will create a file if it's not there but its parent is. | 853 // Touch will create a file if it's not there but its parent is. |
| 856 bool new_file = true; | 854 bool new_file = true; |
| 857 path = UTF8ToFilePath("file name"); | 855 path = UTF8ToFilePath("file name"); |
| 858 TestTouchHelper(path, new_file); | 856 TestTouchHelper(path, new_file); |
| 859 | 857 |
| 860 bool exclusive = true; | 858 bool exclusive = true; |
| 861 bool recursive = true; | 859 bool recursive = true; |
| 862 path = UTF8ToFilePath("directory/to/use"); | 860 path = UTF8ToFilePath("directory/to/use"); |
| 863 context.reset(NewContext(NULL)); | 861 context.reset(NewContext(NULL)); |
| 864 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 862 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 865 context.get(), path, exclusive, recursive)); | 863 context.get(), path, exclusive, recursive)); |
| 866 new_file = false; | 864 new_file = false; |
| 867 TestTouchHelper(path, new_file); | 865 TestTouchHelper(path, new_file); |
| 868 } | 866 } |
| 869 | 867 |
| 870 TEST_F(ObfuscatedFileSystemFileUtilTest, TestPathQuotas) { | 868 TEST_F(ObfuscatedFileUtilTest, TestPathQuotas) { |
| 871 FilePath path = UTF8ToFilePath("fake/file"); | 869 FilePath path = UTF8ToFilePath("fake/file"); |
| 872 base::Time last_access_time = base::Time::Now(); | 870 base::Time last_access_time = base::Time::Now(); |
| 873 base::Time last_modified_time = base::Time::Now(); | 871 base::Time last_modified_time = base::Time::Now(); |
| 874 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 872 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 875 | 873 |
| 876 // Touch will create a file if it's not there but its parent is. | 874 // Touch will create a file if it's not there but its parent is. |
| 877 path = UTF8ToFilePath("file name"); | 875 path = UTF8ToFilePath("file name"); |
| 878 context->set_allowed_bytes_growth(5); | 876 context->set_allowed_bytes_growth(5); |
| 879 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 877 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 880 ofsfu()->Touch( | 878 ofu()->Touch( |
| 881 context.get(), path, last_access_time, last_modified_time)); | 879 context.get(), path, last_access_time, last_modified_time)); |
| 882 context->set_allowed_bytes_growth(1024); | 880 context->set_allowed_bytes_growth(1024); |
| 883 EXPECT_EQ(base::PLATFORM_FILE_OK, | 881 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 884 ofsfu()->Touch( | 882 ofu()->Touch( |
| 885 context.get(), path, last_access_time, last_modified_time)); | 883 context.get(), path, last_access_time, last_modified_time)); |
| 886 int64 path_cost = ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); | 884 int64 path_cost = ObfuscatedFileUtil::ComputeFilePathCost(path); |
| 887 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); | 885 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| 888 | 886 |
| 889 context->set_allowed_bytes_growth(1024); | 887 context->set_allowed_bytes_growth(1024); |
| 890 bool exclusive = true; | 888 bool exclusive = true; |
| 891 bool recursive = true; | 889 bool recursive = true; |
| 892 path = UTF8ToFilePath("directory/to/use"); | 890 path = UTF8ToFilePath("directory/to/use"); |
| 893 std::vector<FilePath::StringType> components; | 891 std::vector<FilePath::StringType> components; |
| 894 path.GetComponents(&components); | 892 path.GetComponents(&components); |
| 895 path_cost = 0; | 893 path_cost = 0; |
| 896 for (std::vector<FilePath::StringType>::iterator iter = components.begin(); | 894 for (std::vector<FilePath::StringType>::iterator iter = components.begin(); |
| 897 iter != components.end(); ++iter) { | 895 iter != components.end(); ++iter) { |
| 898 path_cost += ObfuscatedFileSystemFileUtil::ComputeFilePathCost( | 896 path_cost += ObfuscatedFileUtil::ComputeFilePathCost( |
| 899 FilePath(*iter)); | 897 FilePath(*iter)); |
| 900 } | 898 } |
| 901 context.reset(NewContext(NULL)); | 899 context.reset(NewContext(NULL)); |
| 902 context->set_allowed_bytes_growth(1024); | 900 context->set_allowed_bytes_growth(1024); |
| 903 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 901 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 904 context.get(), path, exclusive, recursive)); | 902 context.get(), path, exclusive, recursive)); |
| 905 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); | 903 EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth()); |
| 906 } | 904 } |
| 907 | 905 |
| 908 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { | 906 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { |
| 909 FilePath source_path = UTF8ToFilePath("path0.txt"); | 907 FilePath source_path = UTF8ToFilePath("path0.txt"); |
| 910 FilePath dest_path = UTF8ToFilePath("path1.txt"); | 908 FilePath dest_path = UTF8ToFilePath("path1.txt"); |
| 911 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 909 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 912 | 910 |
| 913 bool is_copy_not_move = false; | 911 bool is_copy_not_move = false; |
| 914 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 912 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 915 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 913 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| 916 is_copy_not_move)); | 914 is_copy_not_move)); |
| 917 context.reset(NewContext(NULL)); | 915 context.reset(NewContext(NULL)); |
| 918 is_copy_not_move = true; | 916 is_copy_not_move = true; |
| 919 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 917 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 920 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 918 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| 921 is_copy_not_move)); | 919 is_copy_not_move)); |
| 922 source_path = UTF8ToFilePath("dir/dir/file"); | 920 source_path = UTF8ToFilePath("dir/dir/file"); |
| 923 bool exclusive = true; | 921 bool exclusive = true; |
| 924 bool recursive = true; | 922 bool recursive = true; |
| 925 context.reset(NewContext(NULL)); | 923 context.reset(NewContext(NULL)); |
| 926 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 924 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 927 context.get(), source_path.DirName(), exclusive, recursive)); | 925 context.get(), source_path.DirName(), exclusive, recursive)); |
| 928 is_copy_not_move = false; | 926 is_copy_not_move = false; |
| 929 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 927 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 930 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 928 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| 931 is_copy_not_move)); | 929 is_copy_not_move)); |
| 932 context.reset(NewContext(NULL)); | 930 context.reset(NewContext(NULL)); |
| 933 is_copy_not_move = true; | 931 is_copy_not_move = true; |
| 934 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 932 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 935 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, | 933 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path, |
| 936 is_copy_not_move)); | 934 is_copy_not_move)); |
| 937 } | 935 } |
| 938 | 936 |
| 939 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { | 937 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { |
| 940 const int64 kSourceLength = 5; | 938 const int64 kSourceLength = 5; |
| 941 const int64 kDestLength = 50; | 939 const int64 kDestLength = 50; |
| 942 | 940 |
| 943 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { | 941 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { |
| 944 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); | 942 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); |
| 945 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; | 943 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; |
| 946 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << | 944 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << |
| 947 test_case.is_copy_not_move); | 945 test_case.is_copy_not_move); |
| 948 SCOPED_TRACE(testing::Message() << "\t source_path " << | 946 SCOPED_TRACE(testing::Message() << "\t source_path " << |
| 949 test_case.source_path); | 947 test_case.source_path); |
| 950 SCOPED_TRACE(testing::Message() << "\t dest_path " << | 948 SCOPED_TRACE(testing::Message() << "\t dest_path " << |
| 951 test_case.dest_path); | 949 test_case.dest_path); |
| 952 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << | 950 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << |
| 953 test_case.cause_overwrite); | 951 test_case.cause_overwrite); |
| 954 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 952 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 955 | 953 |
| 956 bool exclusive = false; | 954 bool exclusive = false; |
| 957 bool recursive = true; | 955 bool recursive = true; |
| 958 FilePath source_path = UTF8ToFilePath(test_case.source_path); | 956 FilePath source_path = UTF8ToFilePath(test_case.source_path); |
| 959 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); | 957 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); |
| 960 | 958 |
| 961 context.reset(NewContext(NULL)); | 959 context.reset(NewContext(NULL)); |
| 962 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 960 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 963 context.get(), source_path.DirName(), exclusive, recursive)); | 961 context.get(), source_path.DirName(), exclusive, recursive)); |
| 964 context.reset(NewContext(NULL)); | 962 context.reset(NewContext(NULL)); |
| 965 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 963 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 966 context.get(), dest_path.DirName(), exclusive, recursive)); | 964 context.get(), dest_path.DirName(), exclusive, recursive)); |
| 967 | 965 |
| 968 bool created = false; | 966 bool created = false; |
| 969 context.reset(NewContext(NULL)); | 967 context.reset(NewContext(NULL)); |
| 970 ASSERT_EQ(base::PLATFORM_FILE_OK, | 968 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 971 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); | 969 ofu()->EnsureFileExists(context.get(), source_path, &created)); |
| 972 ASSERT_TRUE(created); | 970 ASSERT_TRUE(created); |
| 973 context.reset(NewContext(NULL)); | 971 context.reset(NewContext(NULL)); |
| 974 ASSERT_EQ(base::PLATFORM_FILE_OK, | 972 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 975 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); | 973 ofu()->Truncate(context.get(), source_path, kSourceLength)); |
| 976 | 974 |
| 977 if (test_case.cause_overwrite) { | 975 if (test_case.cause_overwrite) { |
| 978 context.reset(NewContext(NULL)); | 976 context.reset(NewContext(NULL)); |
| 979 created = false; | 977 created = false; |
| 980 ASSERT_EQ(base::PLATFORM_FILE_OK, | 978 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 981 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); | 979 ofu()->EnsureFileExists(context.get(), dest_path, &created)); |
| 982 ASSERT_TRUE(created); | 980 ASSERT_TRUE(created); |
| 983 context.reset(NewContext(NULL)); | 981 context.reset(NewContext(NULL)); |
| 984 ASSERT_EQ(base::PLATFORM_FILE_OK, | 982 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 985 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); | 983 ofu()->Truncate(context.get(), dest_path, kDestLength)); |
| 986 } | 984 } |
| 987 | 985 |
| 988 context.reset(NewContext(NULL)); | 986 context.reset(NewContext(NULL)); |
| 989 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), | 987 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile(context.get(), |
| 990 source_path, dest_path, test_case.is_copy_not_move)); | 988 source_path, dest_path, test_case.is_copy_not_move)); |
| 991 if (test_case.is_copy_not_move) { | 989 if (test_case.is_copy_not_move) { |
| 992 base::PlatformFileInfo file_info; | 990 base::PlatformFileInfo file_info; |
| 993 FilePath local_path; | 991 FilePath local_path; |
| 994 context.reset(NewContext(NULL)); | 992 context.reset(NewContext(NULL)); |
| 995 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 993 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 996 context.get(), source_path, &file_info, &local_path)); | 994 context.get(), source_path, &file_info, &local_path)); |
| 997 EXPECT_EQ(kSourceLength, file_info.size); | 995 EXPECT_EQ(kSourceLength, file_info.size); |
| 998 EXPECT_EQ(base::PLATFORM_FILE_OK, | 996 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 999 ofsfu()->DeleteFile(context.get(), source_path)); | 997 ofu()->DeleteFile(context.get(), source_path)); |
| 1000 } else { | 998 } else { |
| 1001 base::PlatformFileInfo file_info; | 999 base::PlatformFileInfo file_info; |
| 1002 FilePath local_path; | 1000 FilePath local_path; |
| 1003 context.reset(NewContext(NULL)); | 1001 context.reset(NewContext(NULL)); |
| 1004 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( | 1002 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo( |
| 1005 context.get(), source_path, &file_info, &local_path)); | 1003 context.get(), source_path, &file_info, &local_path)); |
| 1006 } | 1004 } |
| 1007 base::PlatformFileInfo file_info; | 1005 base::PlatformFileInfo file_info; |
| 1008 FilePath local_path; | 1006 FilePath local_path; |
| 1009 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( | 1007 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo( |
| 1010 context.get(), dest_path, &file_info, &local_path)); | 1008 context.get(), dest_path, &file_info, &local_path)); |
| 1011 EXPECT_EQ(kSourceLength, file_info.size); | 1009 EXPECT_EQ(kSourceLength, file_info.size); |
| 1012 | 1010 |
| 1013 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1011 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1014 ofsfu()->DeleteFile(context.get(), dest_path)); | 1012 ofu()->DeleteFile(context.get(), dest_path)); |
| 1015 } | 1013 } |
| 1016 } | 1014 } |
| 1017 | 1015 |
| 1018 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyPathQuotas) { | 1016 TEST_F(ObfuscatedFileUtilTest, TestCopyPathQuotas) { |
| 1019 FilePath src_path = UTF8ToFilePath("src path"); | 1017 FilePath src_path = UTF8ToFilePath("src path"); |
| 1020 FilePath dest_path = UTF8ToFilePath("destination path"); | 1018 FilePath dest_path = UTF8ToFilePath("destination path"); |
| 1021 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1019 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1022 bool created = false; | 1020 bool created = false; |
| 1023 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->EnsureFileExists( | 1021 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( |
| 1024 context.get(), src_path, &created)); | 1022 context.get(), src_path, &created)); |
| 1025 | 1023 |
| 1026 bool is_copy = true; | 1024 bool is_copy = true; |
| 1027 // Copy, no overwrite. | 1025 // Copy, no overwrite. |
| 1028 context->set_allowed_bytes_growth( | 1026 context->set_allowed_bytes_growth( |
| 1029 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(dest_path) - 1); | 1027 ObfuscatedFileUtil::ComputeFilePathCost(dest_path) - 1); |
| 1030 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 1028 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 1031 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1029 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1032 context.reset(NewContext(NULL)); | 1030 context.reset(NewContext(NULL)); |
| 1033 context->set_allowed_bytes_growth( | 1031 context->set_allowed_bytes_growth( |
| 1034 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(dest_path)); | 1032 ObfuscatedFileUtil::ComputeFilePathCost(dest_path)); |
| 1035 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1033 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1036 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1034 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1037 | 1035 |
| 1038 // Copy, with overwrite. | 1036 // Copy, with overwrite. |
| 1039 context.reset(NewContext(NULL)); | 1037 context.reset(NewContext(NULL)); |
| 1040 context->set_allowed_bytes_growth(0); | 1038 context->set_allowed_bytes_growth(0); |
| 1041 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1039 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1042 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1040 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1043 } | 1041 } |
| 1044 | 1042 |
| 1045 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMovePathQuotasWithRename) { | 1043 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) { |
| 1046 FilePath src_path = UTF8ToFilePath("src path"); | 1044 FilePath src_path = UTF8ToFilePath("src path"); |
| 1047 FilePath dest_path = UTF8ToFilePath("destination path"); | 1045 FilePath dest_path = UTF8ToFilePath("destination path"); |
| 1048 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1046 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1049 bool created = false; | 1047 bool created = false; |
| 1050 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->EnsureFileExists( | 1048 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( |
| 1051 context.get(), src_path, &created)); | 1049 context.get(), src_path, &created)); |
| 1052 | 1050 |
| 1053 bool is_copy = false; | 1051 bool is_copy = false; |
| 1054 // Move, rename, no overwrite. | 1052 // Move, rename, no overwrite. |
| 1055 context.reset(NewContext(NULL)); | 1053 context.reset(NewContext(NULL)); |
| 1056 context->set_allowed_bytes_growth( | 1054 context->set_allowed_bytes_growth( |
| 1057 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(dest_path) - | 1055 ObfuscatedFileUtil::ComputeFilePathCost(dest_path) - |
| 1058 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(src_path) - 1); | 1056 ObfuscatedFileUtil::ComputeFilePathCost(src_path) - 1); |
| 1059 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, | 1057 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, |
| 1060 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1058 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1061 context.reset(NewContext(NULL)); | 1059 context.reset(NewContext(NULL)); |
| 1062 context->set_allowed_bytes_growth( | 1060 context->set_allowed_bytes_growth( |
| 1063 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(dest_path) - | 1061 ObfuscatedFileUtil::ComputeFilePathCost(dest_path) - |
| 1064 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(src_path)); | 1062 ObfuscatedFileUtil::ComputeFilePathCost(src_path)); |
| 1065 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1063 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1066 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1064 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1067 | 1065 |
| 1068 context.reset(NewContext(NULL)); | 1066 context.reset(NewContext(NULL)); |
| 1069 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->EnsureFileExists( | 1067 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( |
| 1070 context.get(), src_path, &created)); | 1068 context.get(), src_path, &created)); |
| 1071 | 1069 |
| 1072 // Move, rename, with overwrite. | 1070 // Move, rename, with overwrite. |
| 1073 context.reset(NewContext(NULL)); | 1071 context.reset(NewContext(NULL)); |
| 1074 context->set_allowed_bytes_growth(0); | 1072 context->set_allowed_bytes_growth(0); |
| 1075 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1073 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1076 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1074 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1077 } | 1075 } |
| 1078 | 1076 |
| 1079 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMovePathQuotasWithoutRename) { | 1077 TEST_F(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) { |
| 1080 FilePath src_path = UTF8ToFilePath("src path"); | 1078 FilePath src_path = UTF8ToFilePath("src path"); |
| 1081 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1079 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1082 bool created = false; | 1080 bool created = false; |
| 1083 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->EnsureFileExists( | 1081 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( |
| 1084 context.get(), src_path, &created)); | 1082 context.get(), src_path, &created)); |
| 1085 | 1083 |
| 1086 bool exclusive = true; | 1084 bool exclusive = true; |
| 1087 bool recursive = false; | 1085 bool recursive = false; |
| 1088 FilePath dir_path = UTF8ToFilePath("directory path"); | 1086 FilePath dir_path = UTF8ToFilePath("directory path"); |
| 1089 context.reset(NewContext(NULL)); | 1087 context.reset(NewContext(NULL)); |
| 1090 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 1088 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 1091 context.get(), dir_path, exclusive, recursive)); | 1089 context.get(), dir_path, exclusive, recursive)); |
| 1092 | 1090 |
| 1093 FilePath dest_path = dir_path.Append(src_path); | 1091 FilePath dest_path = dir_path.Append(src_path); |
| 1094 | 1092 |
| 1095 bool is_copy = false; | 1093 bool is_copy = false; |
| 1096 int64 allowed_bytes_growth = -1000; // Over quota, this should still work. | 1094 int64 allowed_bytes_growth = -1000; // Over quota, this should still work. |
| 1097 // Move, no rename, no overwrite. | 1095 // Move, no rename, no overwrite. |
| 1098 context.reset(NewContext(NULL)); | 1096 context.reset(NewContext(NULL)); |
| 1099 context->set_allowed_bytes_growth(allowed_bytes_growth); | 1097 context->set_allowed_bytes_growth(allowed_bytes_growth); |
| 1100 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1098 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1101 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1099 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1102 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth()); | 1100 EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth()); |
| 1103 | 1101 |
| 1104 // Move, no rename, with overwrite. | 1102 // Move, no rename, with overwrite. |
| 1105 context.reset(NewContext(NULL)); | 1103 context.reset(NewContext(NULL)); |
| 1106 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->EnsureFileExists( | 1104 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( |
| 1107 context.get(), src_path, &created)); | 1105 context.get(), src_path, &created)); |
| 1108 context.reset(NewContext(NULL)); | 1106 context.reset(NewContext(NULL)); |
| 1109 context->set_allowed_bytes_growth(allowed_bytes_growth); | 1107 context->set_allowed_bytes_growth(allowed_bytes_growth); |
| 1110 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1108 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1111 ofsfu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); | 1109 ofu()->CopyOrMoveFile(context.get(), src_path, dest_path, is_copy)); |
| 1112 EXPECT_EQ( | 1110 EXPECT_EQ( |
| 1113 allowed_bytes_growth + | 1111 allowed_bytes_growth + |
| 1114 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(src_path), | 1112 ObfuscatedFileUtil::ComputeFilePathCost(src_path), |
| 1115 context->allowed_bytes_growth()); | 1113 context->allowed_bytes_growth()); |
| 1116 } | 1114 } |
| 1117 | 1115 |
| 1118 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { | 1116 TEST_F(ObfuscatedFileUtilTest, TestCopyInForeignFile) { |
| 1119 TestCopyInForeignFileHelper(false /* overwrite */); | 1117 TestCopyInForeignFileHelper(false /* overwrite */); |
| 1120 TestCopyInForeignFileHelper(true /* overwrite */); | 1118 TestCopyInForeignFileHelper(true /* overwrite */); |
| 1121 } | 1119 } |
| 1122 | 1120 |
| 1123 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { | 1121 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) { |
| 1124 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1122 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1125 FilePath src_path = UTF8ToFilePath("source dir"); | 1123 FilePath src_path = UTF8ToFilePath("source dir"); |
| 1126 bool exclusive = true; | 1124 bool exclusive = true; |
| 1127 bool recursive = false; | 1125 bool recursive = false; |
| 1128 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( | 1126 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory( |
| 1129 context.get(), src_path, exclusive, recursive)); | 1127 context.get(), src_path, exclusive, recursive)); |
| 1130 | 1128 |
| 1131 std::set<FilePath::StringType> files; | 1129 std::set<FilePath::StringType> files; |
| 1132 std::set<FilePath::StringType> directories; | 1130 std::set<FilePath::StringType> directories; |
| 1133 FillTestDirectory(src_path, &files, &directories); | 1131 FillTestDirectory(src_path, &files, &directories); |
| 1134 | 1132 |
| 1135 FilePath dest_path = UTF8ToFilePath("destination dir"); | 1133 FilePath dest_path = UTF8ToFilePath("destination dir"); |
| 1136 | 1134 |
| 1137 context.reset(NewContext(NULL)); | 1135 context.reset(NewContext(NULL)); |
| 1138 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 1136 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path)); |
| 1139 context.reset(NewContext(NULL)); | 1137 context.reset(NewContext(NULL)); |
| 1140 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1138 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1141 ofsfu()->Copy(context.get(), src_path, dest_path)); | 1139 ofu()->Copy(context.get(), src_path, dest_path)); |
| 1142 | 1140 |
| 1143 ValidateTestDirectory(dest_path, files, directories); | 1141 ValidateTestDirectory(dest_path, files, directories); |
| 1144 context.reset(NewContext(NULL)); | 1142 context.reset(NewContext(NULL)); |
| 1145 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); | 1143 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), src_path)); |
| 1146 context.reset(NewContext(NULL)); | 1144 context.reset(NewContext(NULL)); |
| 1147 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 1145 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), dest_path)); |
| 1148 context.reset(NewContext(NULL)); | 1146 context.reset(NewContext(NULL)); |
| 1149 recursive = true; | 1147 recursive = true; |
| 1150 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1148 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1151 ofsfu()->Delete(context.get(), dest_path, recursive)); | 1149 ofu()->Delete(context.get(), dest_path, recursive)); |
| 1152 context.reset(NewContext(NULL)); | 1150 context.reset(NewContext(NULL)); |
| 1153 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 1151 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path)); |
| 1154 } | 1152 } |
| 1155 | 1153 |
| 1156 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { | 1154 TEST_F(ObfuscatedFileUtilTest, TestMigration) { |
| 1157 ScopedTempDir source_dir; | 1155 ScopedTempDir source_dir; |
| 1158 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); | 1156 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
| 1159 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); | 1157 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
| 1160 ASSERT_TRUE(file_util::CreateDirectory(root_path)); | 1158 ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
| 1161 | 1159 |
| 1162 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 1160 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 1163 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); | 1161 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); |
| 1164 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; | 1162 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 1165 FilePath local_src_path = root_path.Append(test_case.path); | 1163 FilePath local_src_path = root_path.Append(test_case.path); |
| 1166 if (test_case.is_directory) { | 1164 if (test_case.is_directory) { |
| 1167 ASSERT_TRUE( | 1165 ASSERT_TRUE( |
| 1168 file_util::CreateDirectory(local_src_path)); | 1166 file_util::CreateDirectory(local_src_path)); |
| 1169 } else { | 1167 } else { |
| 1170 base::PlatformFileError error_code; | 1168 base::PlatformFileError error_code; |
| 1171 bool created = false; | 1169 bool created = false; |
| 1172 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; | 1170 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
| 1173 base::PlatformFile file_handle = | 1171 base::PlatformFile file_handle = |
| 1174 base::CreatePlatformFile( | 1172 base::CreatePlatformFile( |
| 1175 local_src_path, file_flags, &created, &error_code); | 1173 local_src_path, file_flags, &created, &error_code); |
| 1176 EXPECT_TRUE(created); | 1174 EXPECT_TRUE(created); |
| 1177 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); | 1175 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); |
| 1178 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); | 1176 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
| 1179 ASSERT_TRUE( | 1177 ASSERT_TRUE( |
| 1180 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); | 1178 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); |
| 1181 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); | 1179 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
| 1182 } | 1180 } |
| 1183 } | 1181 } |
| 1184 | 1182 |
| 1185 EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin(), type(), root_path)); | 1183 EXPECT_TRUE(ofu()->MigrateFromOldSandbox(origin(), type(), root_path)); |
| 1186 | 1184 |
| 1187 FilePath new_root = | 1185 FilePath new_root = |
| 1188 test_directory().AppendASCII("File System").AppendASCII("000").Append( | 1186 test_directory().AppendASCII("File System").AppendASCII("000").Append( |
| 1189 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); | 1187 ofu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); |
| 1190 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 1188 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 1191 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); | 1189 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); |
| 1192 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; | 1190 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 1193 FilePath local_data_path = new_root.Append(test_case.path); | 1191 FilePath local_data_path = new_root.Append(test_case.path); |
| 1194 #if defined(OS_WIN) | 1192 #if defined(OS_WIN) |
| 1195 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); | 1193 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); |
| 1196 #endif | 1194 #endif |
| 1197 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1195 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1198 base::PlatformFileInfo ofsfu_file_info; | 1196 base::PlatformFileInfo ofu_file_info; |
| 1199 FilePath data_path; | 1197 FilePath data_path; |
| 1200 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); | 1198 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
| 1201 EXPECT_EQ(base::PLATFORM_FILE_OK, | 1199 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 1202 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), | 1200 ofu()->GetFileInfo(context.get(), FilePath(test_case.path), |
| 1203 &ofsfu_file_info, &data_path)); | 1201 &ofu_file_info, &data_path)); |
| 1204 if (test_case.is_directory) { | 1202 if (test_case.is_directory) { |
| 1205 EXPECT_TRUE(ofsfu_file_info.is_directory); | 1203 EXPECT_TRUE(ofu_file_info.is_directory); |
| 1206 } else { | 1204 } else { |
| 1207 base::PlatformFileInfo platform_file_info; | 1205 base::PlatformFileInfo platform_file_info; |
| 1208 SCOPED_TRACE(testing::Message() << "local_data_path is " << | 1206 SCOPED_TRACE(testing::Message() << "local_data_path is " << |
| 1209 local_data_path.value()); | 1207 local_data_path.value()); |
| 1210 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); | 1208 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); |
| 1211 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); | 1209 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
| 1212 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); | 1210 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
| 1213 EXPECT_FALSE(platform_file_info.is_directory); | 1211 EXPECT_FALSE(platform_file_info.is_directory); |
| 1214 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1212 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1215 EXPECT_EQ(local_data_path, data_path); | 1213 EXPECT_EQ(local_data_path, data_path); |
| 1216 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); | 1214 EXPECT_EQ(platform_file_info.size, ofu_file_info.size); |
| 1217 EXPECT_FALSE(ofsfu_file_info.is_directory); | 1215 EXPECT_FALSE(ofu_file_info.is_directory); |
| 1218 } | 1216 } |
| 1219 } | 1217 } |
| 1220 } | 1218 } |
| 1221 | 1219 |
| 1222 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { | 1220 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) { |
| 1223 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> | 1221 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> |
| 1224 enumerator(ofsfu()->CreateOriginEnumerator()); | 1222 enumerator(ofu()->CreateOriginEnumerator()); |
| 1225 // The test helper starts out with a single filesystem. | 1223 // The test helper starts out with a single filesystem. |
| 1226 EXPECT_TRUE(enumerator.get()); | 1224 EXPECT_TRUE(enumerator.get()); |
| 1227 EXPECT_EQ(origin(), enumerator->Next()); | 1225 EXPECT_EQ(origin(), enumerator->Next()); |
| 1228 ASSERT_TRUE(type() == kFileSystemTypeTemporary); | 1226 ASSERT_TRUE(type() == kFileSystemTypeTemporary); |
| 1229 EXPECT_TRUE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); | 1227 EXPECT_TRUE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); |
| 1230 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); | 1228 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); |
| 1231 EXPECT_EQ(GURL(), enumerator->Next()); | 1229 EXPECT_EQ(GURL(), enumerator->Next()); |
| 1232 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); | 1230 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); |
| 1233 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); | 1231 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); |
| 1234 | 1232 |
| 1235 std::set<GURL> origins_expected; | 1233 std::set<GURL> origins_expected; |
| 1236 origins_expected.insert(origin()); | 1234 origins_expected.insert(origin()); |
| 1237 | 1235 |
| 1238 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { | 1236 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { |
| 1239 SCOPED_TRACE(testing::Message() << | 1237 SCOPED_TRACE(testing::Message() << |
| 1240 "Validating kOriginEnumerationTestRecords " << i); | 1238 "Validating kOriginEnumerationTestRecords " << i); |
| 1241 const OriginEnumerationTestRecord& record = | 1239 const OriginEnumerationTestRecord& record = |
| 1242 kOriginEnumerationTestRecords[i]; | 1240 kOriginEnumerationTestRecords[i]; |
| 1243 GURL origin_url(record.origin_url); | 1241 GURL origin_url(record.origin_url); |
| 1244 origins_expected.insert(origin_url); | 1242 origins_expected.insert(origin_url); |
| 1245 if (record.has_temporary) { | 1243 if (record.has_temporary) { |
| 1246 scoped_ptr<FileSystemTestOriginHelper> helper( | 1244 scoped_ptr<FileSystemTestOriginHelper> helper( |
| 1247 NewHelper(origin_url, kFileSystemTypeTemporary)); | 1245 NewHelper(origin_url, kFileSystemTypeTemporary)); |
| 1248 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); | 1246 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
| 1249 context->set_src_origin_url(origin_url); | 1247 context->set_src_origin_url(origin_url); |
| 1250 context->set_src_type(kFileSystemTypeTemporary); | 1248 context->set_src_type(kFileSystemTypeTemporary); |
| 1251 bool created = false; | 1249 bool created = false; |
| 1252 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1250 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1253 ofsfu()->EnsureFileExists(context.get(), | 1251 ofu()->EnsureFileExists(context.get(), |
| 1254 FilePath().AppendASCII("file"), &created)); | 1252 FilePath().AppendASCII("file"), &created)); |
| 1255 EXPECT_TRUE(created); | 1253 EXPECT_TRUE(created); |
| 1256 } | 1254 } |
| 1257 if (record.has_persistent) { | 1255 if (record.has_persistent) { |
| 1258 scoped_ptr<FileSystemTestOriginHelper> helper( | 1256 scoped_ptr<FileSystemTestOriginHelper> helper( |
| 1259 NewHelper(origin_url, kFileSystemTypePersistent)); | 1257 NewHelper(origin_url, kFileSystemTypePersistent)); |
| 1260 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); | 1258 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); |
| 1261 context->set_src_origin_url(origin_url); | 1259 context->set_src_origin_url(origin_url); |
| 1262 context->set_src_type(kFileSystemTypePersistent); | 1260 context->set_src_type(kFileSystemTypePersistent); |
| 1263 bool created = false; | 1261 bool created = false; |
| 1264 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1262 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1265 ofsfu()->EnsureFileExists(context.get(), | 1263 ofu()->EnsureFileExists(context.get(), |
| 1266 FilePath().AppendASCII("file"), &created)); | 1264 FilePath().AppendASCII("file"), &created)); |
| 1267 EXPECT_TRUE(created); | 1265 EXPECT_TRUE(created); |
| 1268 } | 1266 } |
| 1269 } | 1267 } |
| 1270 enumerator.reset(ofsfu()->CreateOriginEnumerator()); | 1268 enumerator.reset(ofu()->CreateOriginEnumerator()); |
| 1271 EXPECT_TRUE(enumerator.get()); | 1269 EXPECT_TRUE(enumerator.get()); |
| 1272 std::set<GURL> origins_found; | 1270 std::set<GURL> origins_found; |
| 1273 GURL origin_url; | 1271 GURL origin_url; |
| 1274 while (!(origin_url = enumerator->Next()).is_empty()) { | 1272 while (!(origin_url = enumerator->Next()).is_empty()) { |
| 1275 origins_found.insert(origin_url); | 1273 origins_found.insert(origin_url); |
| 1276 SCOPED_TRACE(testing::Message() << "Handling " << origin_url.spec()); | 1274 SCOPED_TRACE(testing::Message() << "Handling " << origin_url.spec()); |
| 1277 bool found = false; | 1275 bool found = false; |
| 1278 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords); | 1276 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords); |
| 1279 ++i) { | 1277 ++i) { |
| 1280 const OriginEnumerationTestRecord& record = | 1278 const OriginEnumerationTestRecord& record = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1299 EXPECT_TRUE(found); | 1297 EXPECT_TRUE(found); |
| 1300 } | 1298 } |
| 1301 | 1299 |
| 1302 std::set<GURL> diff; | 1300 std::set<GURL> diff; |
| 1303 std::set_symmetric_difference(origins_expected.begin(), | 1301 std::set_symmetric_difference(origins_expected.begin(), |
| 1304 origins_expected.end(), origins_found.begin(), origins_found.end(), | 1302 origins_expected.end(), origins_found.begin(), origins_found.end(), |
| 1305 inserter(diff, diff.begin())); | 1303 inserter(diff, diff.begin())); |
| 1306 EXPECT_TRUE(diff.empty()); | 1304 EXPECT_TRUE(diff.empty()); |
| 1307 } | 1305 } |
| 1308 | 1306 |
| 1309 TEST_F(ObfuscatedFileSystemFileUtilTest, TestRevokeUsageCache) { | 1307 TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) { |
| 1310 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); | 1308 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); |
| 1311 | 1309 |
| 1312 int64 expected_quota = 0; | 1310 int64 expected_quota = 0; |
| 1313 | 1311 |
| 1314 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { | 1312 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 1315 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); | 1313 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); |
| 1316 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; | 1314 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 1317 FilePath path(test_case.path); | 1315 FilePath path(test_case.path); |
| 1318 expected_quota += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); | 1316 expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(path); |
| 1319 if (test_case.is_directory) { | 1317 if (test_case.is_directory) { |
| 1320 bool exclusive = true; | 1318 bool exclusive = true; |
| 1321 bool recursive = false; | 1319 bool recursive = false; |
| 1322 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1320 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1323 ofsfu()->CreateDirectory(context.get(), path, exclusive, recursive)); | 1321 ofu()->CreateDirectory(context.get(), path, exclusive, recursive)); |
| 1324 } else { | 1322 } else { |
| 1325 bool created = false; | 1323 bool created = false; |
| 1326 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1324 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1327 ofsfu()->EnsureFileExists(context.get(), path, &created)); | 1325 ofu()->EnsureFileExists(context.get(), path, &created)); |
| 1328 ASSERT_TRUE(created); | 1326 ASSERT_TRUE(created); |
| 1329 ASSERT_EQ(base::PLATFORM_FILE_OK, | 1327 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 1330 ofsfu()->Truncate(context.get(), path, | 1328 ofu()->Truncate(context.get(), path, |
| 1331 test_case.data_file_size)); | 1329 test_case.data_file_size)); |
| 1332 expected_quota += test_case.data_file_size; | 1330 expected_quota += test_case.data_file_size; |
| 1333 } | 1331 } |
| 1334 } | 1332 } |
| 1335 EXPECT_EQ(expected_quota, SizeInUsageFile()); | 1333 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
| 1336 RevokeUsageCache(); | 1334 RevokeUsageCache(); |
| 1337 EXPECT_EQ(-1, SizeInUsageFile()); | 1335 EXPECT_EQ(-1, SizeInUsageFile()); |
| 1338 GetUsageFromQuotaManager(); | 1336 GetUsageFromQuotaManager(); |
| 1339 EXPECT_EQ(expected_quota, SizeInUsageFile()); | 1337 EXPECT_EQ(expected_quota, SizeInUsageFile()); |
| 1340 EXPECT_EQ(expected_quota, usage()); | 1338 EXPECT_EQ(expected_quota, usage()); |
| 1341 } | 1339 } |
| OLD | NEW |