| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/async_file_util_test_helper.h" |
| 15 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" | 16 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p
rovider.h" |
| 16 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | 17 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/browser/fileapi/external_mount_points.h" | 19 #include "webkit/browser/fileapi/external_mount_points.h" |
| 19 #include "webkit/browser/fileapi/file_system_context.h" | 20 #include "webkit/browser/fileapi/file_system_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" | 21 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" |
| 21 #include "webkit/browser/fileapi/file_system_operation.h" | 22 #include "webkit/browser/fileapi/file_system_operation.h" |
| 22 #include "webkit/browser/fileapi/file_system_task_runners.h" | 23 #include "webkit/browser/fileapi/file_system_task_runners.h" |
| 23 #include "webkit/browser/fileapi/file_system_url.h" | 24 #include "webkit/browser/fileapi/file_system_url.h" |
| 24 #include "webkit/browser/fileapi/isolated_context.h" | 25 #include "webkit/browser/fileapi/isolated_context.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 file_system_context_ = | 132 file_system_context_ = |
| 132 new fileapi::FileSystemContext( | 133 new fileapi::FileSystemContext( |
| 133 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), | 134 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(), |
| 134 fileapi::ExternalMountPoints::CreateRefCounted().get(), | 135 fileapi::ExternalMountPoints::CreateRefCounted().get(), |
| 135 storage_policy, | 136 storage_policy, |
| 136 NULL, | 137 NULL, |
| 137 additional_providers.Pass(), | 138 additional_providers.Pass(), |
| 138 data_dir_.path(), | 139 data_dir_.path(), |
| 139 fileapi::CreateAllowFileAccessOptions()); | 140 fileapi::CreateAllowFileAccessOptions()); |
| 140 | 141 |
| 141 file_util_ = file_system_context_->GetFileUtil( | 142 file_util_.reset( |
| 142 fileapi::kFileSystemTypeNativeMedia); | 143 new fileapi::AsyncFileUtilTestHelper(new NativeMediaFileUtil())); |
| 143 | 144 |
| 144 filesystem_id_ = isolated_context()->RegisterFileSystemForPath( | 145 filesystem_id_ = isolated_context()->RegisterFileSystemForPath( |
| 145 fileapi::kFileSystemTypeNativeMedia, root_path(), NULL); | 146 fileapi::kFileSystemTypeNativeMedia, root_path(), NULL); |
| 146 | 147 |
| 147 isolated_context()->AddReference(filesystem_id_); | 148 isolated_context()->AddReference(filesystem_id_); |
| 148 } | 149 } |
| 149 | 150 |
| 150 virtual void TearDown() { | 151 virtual void TearDown() { |
| 151 isolated_context()->RemoveReference(filesystem_id_); | 152 isolated_context()->RemoveReference(filesystem_id_); |
| 152 file_system_context_ = NULL; | 153 file_system_context_ = NULL; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 173 } | 174 } |
| 174 | 175 |
| 175 base::FilePath GetVirtualPath( | 176 base::FilePath GetVirtualPath( |
| 176 const base::FilePath::CharType* test_case_path) { | 177 const base::FilePath::CharType* test_case_path) { |
| 177 return base::FilePath::FromUTF8Unsafe(filesystem_id_). | 178 return base::FilePath::FromUTF8Unsafe(filesystem_id_). |
| 178 Append(FPL("Media Directory")). | 179 Append(FPL("Media Directory")). |
| 179 Append(base::FilePath(test_case_path)); | 180 Append(base::FilePath(test_case_path)); |
| 180 } | 181 } |
| 181 | 182 |
| 182 fileapi::FileSystemFileUtil* file_util() { | 183 fileapi::FileSystemFileUtil* file_util() { |
| 183 return file_util_; | 184 return file_util_.get(); |
| 184 } | 185 } |
| 185 | 186 |
| 186 GURL origin() { | 187 GURL origin() { |
| 187 return GURL("http://example.com"); | 188 return GURL("http://example.com"); |
| 188 } | 189 } |
| 189 | 190 |
| 190 fileapi::FileSystemType type() { | 191 fileapi::FileSystemType type() { |
| 191 return fileapi::kFileSystemTypeNativeMedia; | 192 return fileapi::kFileSystemTypeNativeMedia; |
| 192 } | 193 } |
| 193 | 194 |
| 194 FileSystemOperation* NewOperation(const FileSystemURL& url) { | 195 FileSystemOperation* NewOperation(const FileSystemURL& url) { |
| 195 return file_system_context_->CreateFileSystemOperation(url, NULL); | 196 return file_system_context_->CreateFileSystemOperation(url, NULL); |
| 196 } | 197 } |
| 197 | 198 |
| 198 private: | 199 private: |
| 199 base::MessageLoop message_loop_; | 200 base::MessageLoop message_loop_; |
| 200 | 201 |
| 201 base::ScopedTempDir data_dir_; | 202 base::ScopedTempDir data_dir_; |
| 202 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 203 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 203 | 204 |
| 204 fileapi::FileSystemFileUtil* file_util_; | 205 scoped_ptr<fileapi::FileSystemFileUtil> file_util_; |
| 205 std::string filesystem_id_; | 206 std::string filesystem_id_; |
| 206 | 207 |
| 207 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); | 208 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); |
| 208 }; | 209 }; |
| 209 | 210 |
| 210 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { | 211 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { |
| 211 PopulateDirectoryWithTestCases(root_path(), | 212 PopulateDirectoryWithTestCases(root_path(), |
| 212 kFilteringTestCases, | 213 kFilteringTestCases, |
| 213 arraysize(kFilteringTestCases)); | 214 arraysize(kFilteringTestCases)); |
| 214 | 215 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 252 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
| 252 base::FilePath::StringType name = | 253 base::FilePath::StringType name = |
| 253 base::FilePath(kFilteringTestCases[i].path).BaseName().value(); | 254 base::FilePath(kFilteringTestCases[i].path).BaseName().value(); |
| 254 std::set<base::FilePath::StringType>::const_iterator found = | 255 std::set<base::FilePath::StringType>::const_iterator found = |
| 255 content.find(name); | 256 content.find(name); |
| 256 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); | 257 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); |
| 257 } | 258 } |
| 258 } | 259 } |
| 259 | 260 |
| 260 TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { | |
| 261 // Run the loop twice. The second loop attempts to create files that are | |
| 262 // pre-existing. Though the result should be the same. | |
| 263 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 264 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 265 FileSystemURL root_url = CreateURL(FPL("")); | |
| 266 FileSystemOperation* operation = NewOperation(root_url); | |
| 267 | |
| 268 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 269 | |
| 270 std::string test_name = base::StringPrintf( | |
| 271 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, | |
| 272 loop_count, i); | |
| 273 base::PlatformFileError expectation = | |
| 274 kFilteringTestCases[i].visible ? | |
| 275 base::PLATFORM_FILE_OK : | |
| 276 base::PLATFORM_FILE_ERROR_SECURITY; | |
| 277 if (kFilteringTestCases[i].is_directory) { | |
| 278 operation->CreateDirectory( | |
| 279 url, false, false, | |
| 280 base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 281 } else { | |
| 282 operation->CreateFile( | |
| 283 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 284 } | |
| 285 base::MessageLoop::current()->RunUntilIdle(); | |
| 286 } | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { | |
| 291 base::FilePath dest_path = root_path().AppendASCII("dest"); | |
| 292 FileSystemURL dest_url = CreateURL(FPL("dest")); | |
| 293 | |
| 294 // Run the loop twice. The first run has no source files. The second run does. | |
| 295 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 296 if (loop_count == 1) { | |
| 297 PopulateDirectoryWithTestCases(root_path(), | |
| 298 kFilteringTestCases, | |
| 299 arraysize(kFilteringTestCases)); | |
| 300 } | |
| 301 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 302 // Always start with an empty destination directory. | |
| 303 // Copying to a non-empty destination directory is an invalid operation. | |
| 304 ASSERT_TRUE(file_util::Delete(dest_path, true)); | |
| 305 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | |
| 306 | |
| 307 FileSystemURL root_url = CreateURL(FPL("")); | |
| 308 FileSystemOperation* operation = NewOperation(root_url); | |
| 309 | |
| 310 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 311 | |
| 312 std::string test_name = base::StringPrintf( | |
| 313 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); | |
| 314 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | |
| 315 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | |
| 316 // If the source does not exist or is not visible. | |
| 317 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 318 } else if (!kFilteringTestCases[i].is_directory) { | |
| 319 // Cannot copy a visible file to a directory. | |
| 320 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 321 } | |
| 322 operation->Copy( | |
| 323 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 324 base::MessageLoop::current()->RunUntilIdle(); | |
| 325 } | |
| 326 } | |
| 327 } | |
| 328 | |
| 329 TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { | |
| 330 // Run the loop twice. The first run has no destination files. | |
| 331 // The second run does. | |
| 332 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 333 if (loop_count == 1) { | |
| 334 // Reset the test directory between the two loops to remove old | |
| 335 // directories and create new ones that should pre-exist. | |
| 336 ASSERT_TRUE(file_util::Delete(root_path(), true)); | |
| 337 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | |
| 338 PopulateDirectoryWithTestCases(root_path(), | |
| 339 kFilteringTestCases, | |
| 340 arraysize(kFilteringTestCases)); | |
| 341 } | |
| 342 | |
| 343 // Always create a dummy source data file. | |
| 344 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); | |
| 345 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); | |
| 346 static const char kDummyData[] = "dummy"; | |
| 347 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | |
| 348 | |
| 349 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 350 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | |
| 351 // These directories do not exist in this case, so Copy() will not | |
| 352 // treat them as directories. Thus invalidating these test cases. | |
| 353 // Continue now to avoid creating a new |operation| below that goes | |
| 354 // unused. | |
| 355 continue; | |
| 356 } | |
| 357 FileSystemURL root_url = CreateURL(FPL("")); | |
| 358 FileSystemOperation* operation = NewOperation(root_url); | |
| 359 | |
| 360 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 361 | |
| 362 std::string test_name = base::StringPrintf( | |
| 363 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); | |
| 364 base::PlatformFileError expectation; | |
| 365 if (loop_count == 0) { | |
| 366 // The destination path is a file here. The directory case has been | |
| 367 // handled above. | |
| 368 // If the destination path does not exist and is not visible, then | |
| 369 // creating it would be a security violation. | |
| 370 expectation = | |
| 371 kFilteringTestCases[i].visible ? | |
| 372 base::PLATFORM_FILE_OK : | |
| 373 base::PLATFORM_FILE_ERROR_SECURITY; | |
| 374 } else { | |
| 375 if (!kFilteringTestCases[i].visible) { | |
| 376 // If the destination path exist and is not visible, then to the copy | |
| 377 // operation, it looks like the file needs to be created, which is a | |
| 378 // security violation. | |
| 379 expectation = base::PLATFORM_FILE_ERROR_SECURITY; | |
| 380 } else if (kFilteringTestCases[i].is_directory) { | |
| 381 // Cannot copy a file to a directory. | |
| 382 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 383 } else { | |
| 384 // Copying from a file to a visible file that exists is ok. | |
| 385 expectation = base::PLATFORM_FILE_OK; | |
| 386 } | |
| 387 } | |
| 388 operation->Copy( | |
| 389 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 390 base::MessageLoop::current()->RunUntilIdle(); | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { | |
| 396 base::FilePath dest_path = root_path().AppendASCII("dest"); | |
| 397 FileSystemURL dest_url = CreateURL(FPL("dest")); | |
| 398 | |
| 399 // Run the loop twice. The first run has no source files. The second run does. | |
| 400 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 401 if (loop_count == 1) { | |
| 402 PopulateDirectoryWithTestCases(root_path(), | |
| 403 kFilteringTestCases, | |
| 404 arraysize(kFilteringTestCases)); | |
| 405 } | |
| 406 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 407 // Always start with an empty destination directory. | |
| 408 // Moving to a non-empty destination directory is an invalid operation. | |
| 409 ASSERT_TRUE(file_util::Delete(dest_path, true)); | |
| 410 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | |
| 411 | |
| 412 FileSystemURL root_url = CreateURL(FPL("")); | |
| 413 FileSystemOperation* operation = NewOperation(root_url); | |
| 414 | |
| 415 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 416 | |
| 417 std::string test_name = base::StringPrintf( | |
| 418 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); | |
| 419 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | |
| 420 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | |
| 421 // If the source does not exist or is not visible. | |
| 422 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 423 } else if (!kFilteringTestCases[i].is_directory) { | |
| 424 // Cannot move a visible file to a directory. | |
| 425 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 426 } | |
| 427 operation->Move( | |
| 428 url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 429 base::MessageLoop::current()->RunUntilIdle(); | |
| 430 } | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 TEST_F(NativeMediaFileUtilTest, MoveDestFiltering) { | |
| 435 // Run the loop twice. The first run has no destination files. | |
| 436 // The second run does. | |
| 437 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 438 if (loop_count == 1) { | |
| 439 // Reset the test directory between the two loops to remove old | |
| 440 // directories and create new ones that should pre-exist. | |
| 441 ASSERT_TRUE(file_util::Delete(root_path(), true)); | |
| 442 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | |
| 443 PopulateDirectoryWithTestCases(root_path(), | |
| 444 kFilteringTestCases, | |
| 445 arraysize(kFilteringTestCases)); | |
| 446 } | |
| 447 | |
| 448 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 449 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | |
| 450 // These directories do not exist in this case, so Copy() will not | |
| 451 // treat them as directories. Thus invalidating these test cases. | |
| 452 // Continue now to avoid creating a new |operation| below that goes | |
| 453 // unused. | |
| 454 continue; | |
| 455 } | |
| 456 | |
| 457 // Create the source file for every test case because it might get moved. | |
| 458 base::FilePath src_path = root_path().AppendASCII("foo.jpg"); | |
| 459 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); | |
| 460 static const char kDummyData[] = "dummy"; | |
| 461 ASSERT_TRUE( | |
| 462 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | |
| 463 | |
| 464 FileSystemURL root_url = CreateURL(FPL("")); | |
| 465 FileSystemOperation* operation = NewOperation(root_url); | |
| 466 | |
| 467 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 468 | |
| 469 std::string test_name = base::StringPrintf( | |
| 470 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); | |
| 471 base::PlatformFileError expectation; | |
| 472 if (loop_count == 0) { | |
| 473 // The destination path is a file here. The directory case has been | |
| 474 // handled above. | |
| 475 // If the destination path does not exist and is not visible, then | |
| 476 // creating it would be a security violation. | |
| 477 expectation = | |
| 478 kFilteringTestCases[i].visible ? | |
| 479 base::PLATFORM_FILE_OK : | |
| 480 base::PLATFORM_FILE_ERROR_SECURITY; | |
| 481 } else { | |
| 482 if (!kFilteringTestCases[i].visible) { | |
| 483 // If the destination path exist and is not visible, then to the move | |
| 484 // operation, it looks like the file needs to be created, which is a | |
| 485 // security violation. | |
| 486 expectation = base::PLATFORM_FILE_ERROR_SECURITY; | |
| 487 } else if (kFilteringTestCases[i].is_directory) { | |
| 488 // Cannot move a file to a directory. | |
| 489 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
| 490 } else { | |
| 491 // Moving from a file to a visible file that exists is ok. | |
| 492 expectation = base::PLATFORM_FILE_OK; | |
| 493 } | |
| 494 } | |
| 495 operation->Move( | |
| 496 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 497 base::MessageLoop::current()->RunUntilIdle(); | |
| 498 } | |
| 499 } | |
| 500 } | |
| 501 | |
| 502 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { | 261 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
| 503 // Run the loop twice. The first run has no files. The second run does. | 262 // Run the loop twice. The first run has no files. The second run does. |
| 504 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 263 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
| 505 if (loop_count == 1) { | 264 if (loop_count == 1) { |
| 506 PopulateDirectoryWithTestCases(root_path(), | 265 PopulateDirectoryWithTestCases(root_path(), |
| 507 kFilteringTestCases, | 266 kFilteringTestCases, |
| 508 arraysize(kFilteringTestCases)); | 267 arraysize(kFilteringTestCases)); |
| 509 } | 268 } |
| 510 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 269 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
| 511 FileSystemURL root_url = CreateURL(FPL("")); | 270 FileSystemURL root_url = CreateURL(FPL("")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 523 operation->GetMetadata(url, | 282 operation->GetMetadata(url, |
| 524 base::Bind(&ExpectMetadataEqHelper, | 283 base::Bind(&ExpectMetadataEqHelper, |
| 525 test_name, | 284 test_name, |
| 526 expectation, | 285 expectation, |
| 527 kFilteringTestCases[i].is_directory)); | 286 kFilteringTestCases[i].is_directory)); |
| 528 base::MessageLoop::current()->RunUntilIdle(); | 287 base::MessageLoop::current()->RunUntilIdle(); |
| 529 } | 288 } |
| 530 } | 289 } |
| 531 } | 290 } |
| 532 | 291 |
| 533 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { | |
| 534 // Run the loop twice. The first run has no files. The second run does. | |
| 535 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 536 if (loop_count == 1) { | |
| 537 PopulateDirectoryWithTestCases(root_path(), | |
| 538 kFilteringTestCases, | |
| 539 arraysize(kFilteringTestCases)); | |
| 540 } | |
| 541 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 542 FileSystemURL root_url = CreateURL(FPL("")); | |
| 543 FileSystemOperation* operation = NewOperation(root_url); | |
| 544 | |
| 545 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 546 | |
| 547 std::string test_name = base::StringPrintf( | |
| 548 "RemoveFiltering run %d test %" PRIuS, loop_count, i); | |
| 549 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | |
| 550 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | |
| 551 // Cannot remove files that do not exist or are not visible. | |
| 552 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 553 } | |
| 554 operation->Remove( | |
| 555 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 556 base::MessageLoop::current()->RunUntilIdle(); | |
| 557 } | |
| 558 } | |
| 559 } | |
| 560 | |
| 561 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { | |
| 562 // Run the loop twice. The first run has no files. The second run does. | |
| 563 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 564 if (loop_count == 1) { | |
| 565 PopulateDirectoryWithTestCases(root_path(), | |
| 566 kFilteringTestCases, | |
| 567 arraysize(kFilteringTestCases)); | |
| 568 } | |
| 569 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 570 FileSystemURL root_url = CreateURL(FPL("")); | |
| 571 FileSystemOperation* operation = NewOperation(root_url); | |
| 572 | |
| 573 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 574 | |
| 575 std::string test_name = base::StringPrintf( | |
| 576 "TruncateFiltering run %d test %" PRIuS, loop_count, i); | |
| 577 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | |
| 578 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | |
| 579 // Cannot truncate files that do not exist or are not visible. | |
| 580 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 581 } else if (kFilteringTestCases[i].is_directory) { | |
| 582 // Cannot truncate directories. | |
| 583 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | |
| 584 } | |
| 585 operation->Truncate( | |
| 586 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 587 base::MessageLoop::current()->RunUntilIdle(); | |
| 588 } | |
| 589 } | |
| 590 } | |
| 591 | |
| 592 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { | |
| 593 base::Time time = base::Time::Now(); | |
| 594 | |
| 595 // Run the loop twice. The first run has no files. The second run does. | |
| 596 for (int loop_count = 0; loop_count < 2; ++loop_count) { | |
| 597 if (loop_count == 1) { | |
| 598 PopulateDirectoryWithTestCases(root_path(), | |
| 599 kFilteringTestCases, | |
| 600 arraysize(kFilteringTestCases)); | |
| 601 } | |
| 602 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | |
| 603 FileSystemURL root_url = CreateURL(FPL("")); | |
| 604 FileSystemOperation* operation = NewOperation(root_url); | |
| 605 | |
| 606 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); | |
| 607 | |
| 608 std::string test_name = base::StringPrintf( | |
| 609 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); | |
| 610 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | |
| 611 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | |
| 612 // Files do not exists. Touch fails. | |
| 613 expectation = base::PLATFORM_FILE_ERROR_FAILED; | |
| 614 } | |
| 615 operation->TouchFile( | |
| 616 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); | |
| 617 base::MessageLoop::current()->RunUntilIdle(); | |
| 618 } | |
| 619 } | |
| 620 } | |
| 621 | |
| 622 void CreateSnapshotCallback(base::PlatformFileError* error, | 292 void CreateSnapshotCallback(base::PlatformFileError* error, |
| 623 base::PlatformFileError result, const base::PlatformFileInfo&, | 293 base::PlatformFileError result, const base::PlatformFileInfo&, |
| 624 const base::FilePath&, | 294 const base::FilePath&, |
| 625 const scoped_refptr<webkit_blob::ShareableFileReference>&) { | 295 const scoped_refptr<webkit_blob::ShareableFileReference>&) { |
| 626 *error = result; | 296 *error = result; |
| 627 } | 297 } |
| 628 | 298 |
| 629 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) { | 299 TEST_F(NativeMediaFileUtilTest, CreateSnapshot) { |
| 630 PopulateDirectoryWithTestCases(root_path(), | 300 PopulateDirectoryWithTestCases(root_path(), |
| 631 kFilteringTestCases, | 301 kFilteringTestCases, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 645 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; | 315 expected_error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 646 error = base::PLATFORM_FILE_ERROR_FAILED; | 316 error = base::PLATFORM_FILE_ERROR_FAILED; |
| 647 operation->CreateSnapshotFile(url, | 317 operation->CreateSnapshotFile(url, |
| 648 base::Bind(CreateSnapshotCallback, &error)); | 318 base::Bind(CreateSnapshotCallback, &error)); |
| 649 base::MessageLoop::current()->RunUntilIdle(); | 319 base::MessageLoop::current()->RunUntilIdle(); |
| 650 ASSERT_EQ(expected_error, error); | 320 ASSERT_EQ(expected_error, error); |
| 651 } | 321 } |
| 652 } | 322 } |
| 653 | 323 |
| 654 } // namespace chrome | 324 } // namespace chrome |
| OLD | NEW |