Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: content/browser/fileapi/obfuscated_file_util_unittest.cc

Issue 579083004: FileSystem: Modify ObfucatedFileUtil to delete contents of the plugin private filesystem (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/fileapi/plugin_private_file_system_backend_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 storage_policy_.get()); 702 storage_policy_.get());
703 const FileSystemURL url = FileSystemURL::CreateForTest( 703 const FileSystemURL url = FileSystemURL::CreateForTest(
704 origin_, kFileSystemTypePersistent, base::FilePath()); 704 origin_, kFileSystemTypePersistent, base::FilePath());
705 705
706 // Create DirectoryDatabase for isolated origin. 706 // Create DirectoryDatabase for isolated origin.
707 SandboxDirectoryDatabase* db = 707 SandboxDirectoryDatabase* db =
708 file_util->GetDirectoryDatabase(url, true /* create */); 708 file_util->GetDirectoryDatabase(url, true /* create */);
709 ASSERT_TRUE(db != NULL); 709 ASSERT_TRUE(db != NULL);
710 710
711 // Destory it. 711 // Destory it.
712 ASSERT_TRUE(file_util->DestroyDirectoryDatabase( 712 file_util->DestroyDirectoryDatabase(
713 url.origin(), GetTypeString(url.type()))); 713 url.origin(), GetTypeString(url.type()));
714 ASSERT_TRUE(file_util->directories_.empty()); 714 ASSERT_TRUE(file_util->directories_.empty());
715 } 715 }
716 716
717 void GetDirectoryDatabase_IsolatedTestBody() { 717 void GetDirectoryDatabase_IsolatedTestBody() {
718 storage_policy_->AddIsolated(origin_); 718 storage_policy_->AddIsolated(origin_);
719 scoped_ptr<ObfuscatedFileUtil> file_util = CreateObfuscatedFileUtil( 719 scoped_ptr<ObfuscatedFileUtil> file_util = CreateObfuscatedFileUtil(
720 storage_policy_.get()); 720 storage_policy_.get());
721 const FileSystemURL url = FileSystemURL::CreateForTest( 721 const FileSystemURL url = FileSystemURL::CreateForTest(
722 origin_, kFileSystemTypePersistent, base::FilePath()); 722 origin_, kFileSystemTypePersistent, base::FilePath());
723 723
(...skipping 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 path_in_file, 2442 path_in_file,
2443 false /* exclusive */, 2443 false /* exclusive */,
2444 true /* recursive */)); 2444 true /* recursive */));
2445 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, 2445 ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
2446 ofu()->CreateDirectory(UnlimitedContext().get(), 2446 ofu()->CreateDirectory(UnlimitedContext().get(),
2447 path_in_file_in_file, 2447 path_in_file_in_file,
2448 false /* exclusive */, 2448 false /* exclusive */,
2449 true /* recursive */)); 2449 true /* recursive */));
2450 } 2450 }
2451 2451
2452 TEST_F(ObfuscatedFileUtilTest, DeleteDirectoryForOriginAndType) {
2453 const GURL origin1("http://www.example.com:12");
2454 const GURL origin2("http://www.example.com:1234");
2455
2456 // Create origin directories.
2457 scoped_ptr<SandboxFileSystemTestHelper> fs1(
2458 NewFileSystem(origin1, kFileSystemTypeTemporary));
2459 scoped_ptr<SandboxFileSystemTestHelper> fs2(
2460 NewFileSystem(origin1, kFileSystemTypePersistent));
2461 scoped_ptr<SandboxFileSystemTestHelper> fs3(
2462 NewFileSystem(origin2, kFileSystemTypeTemporary));
2463 scoped_ptr<SandboxFileSystemTestHelper> fs4(
2464 NewFileSystem(origin2, kFileSystemTypePersistent));
2465
2466 // Make sure directories for origin1 exist.
2467 base::File::Error error = base::File::FILE_ERROR_FAILED;
2468 ofu()->GetDirectoryForOriginAndType(
2469 origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
2470 ASSERT_EQ(base::File::FILE_OK, error);
2471 error = base::File::FILE_ERROR_FAILED;
2472 ofu()->GetDirectoryForOriginAndType(
2473 origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
2474 ASSERT_EQ(base::File::FILE_OK, error);
2475
2476 // Make sure directories for origin2 exist.
2477 error = base::File::FILE_ERROR_FAILED;
2478 ofu()->GetDirectoryForOriginAndType(
2479 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
2480 ASSERT_EQ(base::File::FILE_OK, error);
2481 error = base::File::FILE_ERROR_FAILED;
2482 ofu()->GetDirectoryForOriginAndType(
2483 origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
2484 ASSERT_EQ(base::File::FILE_OK, error);
2485
2486 // Delete a directory for origin1's persistent filesystem.
2487 ofu()->DeleteDirectoryForOriginAndType(
2488 origin1, GetTypeString(kFileSystemTypePersistent));
2489
2490 // The directory for origin1's temporary filesystem should not be removed.
2491 error = base::File::FILE_ERROR_FAILED;
2492 ofu()->GetDirectoryForOriginAndType(
2493 origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
2494 ASSERT_EQ(base::File::FILE_OK, error);
2495
2496 // The directory for origin1's persistent filesystem should be removed.
2497 error = base::File::FILE_ERROR_FAILED;
2498 ofu()->GetDirectoryForOriginAndType(
2499 origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
2500 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
2501
2502 // The directories for origin2 should not be removed.
2503 error = base::File::FILE_ERROR_FAILED;
2504 ofu()->GetDirectoryForOriginAndType(
2505 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
2506 ASSERT_EQ(base::File::FILE_OK, error);
2507 error = base::File::FILE_ERROR_FAILED;
2508 ofu()->GetDirectoryForOriginAndType(
2509 origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
2510 ASSERT_EQ(base::File::FILE_OK, error);
2511 }
2512
2513 TEST_F(ObfuscatedFileUtilTest, DeleteDirectoryForOriginAndType_DeleteAll) {
2514 const GURL origin1("http://www.example.com:12");
2515 const GURL origin2("http://www.example.com:1234");
2516
2517 // Create origin directories.
2518 scoped_ptr<SandboxFileSystemTestHelper> fs1(
2519 NewFileSystem(origin1, kFileSystemTypeTemporary));
2520 scoped_ptr<SandboxFileSystemTestHelper> fs2(
2521 NewFileSystem(origin1, kFileSystemTypePersistent));
2522 scoped_ptr<SandboxFileSystemTestHelper> fs3(
2523 NewFileSystem(origin2, kFileSystemTypeTemporary));
2524 scoped_ptr<SandboxFileSystemTestHelper> fs4(
2525 NewFileSystem(origin2, kFileSystemTypePersistent));
2526
2527 // Make sure directories for origin1 exist.
2528 base::File::Error error = base::File::FILE_ERROR_FAILED;
2529 ofu()->GetDirectoryForOriginAndType(
2530 origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
2531 ASSERT_EQ(base::File::FILE_OK, error);
2532 error = base::File::FILE_ERROR_FAILED;
2533 ofu()->GetDirectoryForOriginAndType(
2534 origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
2535 ASSERT_EQ(base::File::FILE_OK, error);
2536
2537 // Make sure directories for origin2 exist.
2538 error = base::File::FILE_ERROR_FAILED;
2539 ofu()->GetDirectoryForOriginAndType(
2540 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
2541 ASSERT_EQ(base::File::FILE_OK, error);
2542 error = base::File::FILE_ERROR_FAILED;
2543 ofu()->GetDirectoryForOriginAndType(
2544 origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
2545 ASSERT_EQ(base::File::FILE_OK, error);
2546
2547 // Delete all directories for origin1.
2548 ofu()->DeleteDirectoryForOriginAndType(origin1, std::string());
2549
2550 // The directories for origin1 should be removed.
2551 error = base::File::FILE_ERROR_FAILED;
2552 ofu()->GetDirectoryForOriginAndType(
2553 origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
2554 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
2555 error = base::File::FILE_ERROR_FAILED;
2556 ofu()->GetDirectoryForOriginAndType(
2557 origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
2558 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
2559
2560 // The directories for origin2 should not be removed.
2561 error = base::File::FILE_ERROR_FAILED;
2562 ofu()->GetDirectoryForOriginAndType(
2563 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
2564 ASSERT_EQ(base::File::FILE_OK, error);
2565 error = base::File::FILE_ERROR_FAILED;
2566 ofu()->GetDirectoryForOriginAndType(
2567 origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
2568 ASSERT_EQ(base::File::FILE_OK, error);
2569 }
2570
2452 } // namespace content 2571 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/fileapi/plugin_private_file_system_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698