Index: chrome/browser/browsing_data_remover_unittest.cc |
diff --git a/chrome/browser/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data_remover_unittest.cc |
index 043af118cb6b007b7479326f615c60ba6a18ede9..7486274c40fc4ecdea2fc6e7be225311c73241ee 100644 |
--- a/chrome/browser/browsing_data_remover_unittest.cc |
+++ b/chrome/browser/browsing_data_remover_unittest.cc |
@@ -20,7 +20,25 @@ |
#include "webkit/fileapi/file_system_operation_context.h" |
#include "webkit/fileapi/file_system_file_util.h" |
#include "webkit/fileapi/file_system_path_manager.h" |
+#include "webkit/fileapi/file_system_test_helper.h" |
#include "webkit/fileapi/sandbox_mount_point_provider.h" |
+#include "webkit/quota/quota_client.h" |
+#include "webkit/quota/quota_manager.h" |
+#include "webkit/quota/quota_types.h" |
+ |
+// Outside the anon. namespace so that it can be friends with |
+// quota::QuotaManager. |
+class BrowsingDataRemoverFileSystemTesterHelper { |
+ public: |
+ static void SetQuotaModified(quota::QuotaManager* manager, const GURL& origin, |
+ quota::StorageType type, const base::Time& modified) { |
+ manager->NotifyStorageModifiedInternal(quota::QuotaClient::kFileSystem, |
+ origin, type, 0, modified); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverFileSystemTesterHelper); |
+}; |
namespace { |
@@ -126,7 +144,8 @@ class RemoveFileSystemTester : public BrowsingDataRemoverTester { |
virtual void PopulateTestFileSystemData(TestingProfile* profile) { |
// Set up kOrigin1 with a temporary file system, kOrigin2 with a persistent |
// file system, and kOrigin3 with both. |
- sandbox_ = profile->GetFileSystemContext()->path_manager()-> |
+ profile_ = profile; |
+ sandbox_ = profile_->GetFileSystemContext()->path_manager()-> |
sandbox_provider(); |
CreateDirectoryForOriginAndType(kOrigin1, |
@@ -138,6 +157,16 @@ class RemoveFileSystemTester : public BrowsingDataRemoverTester { |
CreateDirectoryForOriginAndType(kOrigin3, |
fileapi::kFileSystemTypePersistent); |
+ FilePath temp(FILE_PATH_LITERAL("/tempfile.tmp")); |
+ TouchTestFileForOriginAndType(kOrigin1, fileapi::kFileSystemTypeTemporary, |
+ temp, base::Time::Now()); |
+ TouchTestFileForOriginAndType(kOrigin2, fileapi::kFileSystemTypePersistent, |
+ temp, base::Time::Now()); |
+ TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypePersistent, |
+ temp, base::Time::Now()); |
+ TouchTestFileForOriginAndType(kOrigin3, fileapi::kFileSystemTypeTemporary, |
+ temp, base::Time::Now()); |
+ |
EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, |
fileapi::kFileSystemTypePersistent)); |
EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, |
@@ -154,13 +183,46 @@ class RemoveFileSystemTester : public BrowsingDataRemoverTester { |
void CreateDirectoryForOriginAndType(const GURL& origin, |
fileapi::FileSystemType type) { |
+ fileapi::FileSystemTestOriginHelper helper(origin, type); |
+ helper.SetUp(profile_->GetFileSystemContext(), |
+ sandbox_->GetFileSystemFileUtil()); |
FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread( |
origin, type, FilePath(), true); |
EXPECT_TRUE(file_util::DirectoryExists(target)); |
} |
+ void TouchTestFileForOriginAndType(const GURL& origin, |
+ fileapi::FileSystemType type, |
+ const FilePath& path, |
+ const base::Time& modified) { |
+ // We can use a raw pointer here for the same reason that `sandbox_` can be |
+ // a raw pointer: everything is destroyed when the profile destroys the |
+ // FileSystemContext in which they each live. |
+ fileapi::FileSystemFileUtil* file_util = sandbox_->GetFileSystemFileUtil(); |
+ |
+ // The operation context, though, we'll have to destroy ourselves. |
+ scoped_ptr<fileapi::FileSystemOperationContext> |
+ op_context(new fileapi::FileSystemOperationContext( |
+ profile_->GetFileSystemContext(), file_util)); |
+ op_context->set_src_origin_url(origin); |
+ op_context->set_src_type(type); |
+ |
+ bool created; |
+ base::PlatformFileError status = file_util->EnsureFileExists( |
+ op_context.get(), path, &created); |
+ BrowsingDataRemoverFileSystemTesterHelper::SetQuotaModified( |
+ profile_->GetQuotaManager(), origin, |
+ type == fileapi::kFileSystemTypeTemporary ? |
+ quota::kStorageTypeTemporary : quota::kStorageTypePersistent, |
+ modified); |
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status); |
+ EXPECT_TRUE(created); |
+ } |
+ |
private: |
+ // We own neither of these pointers; we shouldn't destroy them. |
fileapi::SandboxMountPointProvider* sandbox_; |
+ TestingProfile* profile_; |
bool found_file_system_; |
DISALLOW_COPY_AND_ASSIGN(RemoveFileSystemTester); |
@@ -360,6 +422,28 @@ TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForever) { |
fileapi::kFileSystemTypeTemporary)); |
} |
+TEST_F(BrowsingDataRemoverTest, RemoveFileSystemsForLastHour) { |
+ scoped_ptr<RemoveFileSystemTester> tester(new RemoveFileSystemTester()); |
+ |
+ tester->PopulateTestFileSystemData(GetProfile()); |
+ |
+ BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, |
+ base::Time::Now(), BrowsingDataRemover::REMOVE_COOKIES, tester.get()); |
+ |
+ EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, |
+ fileapi::kFileSystemTypePersistent)); |
+ EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin1, |
+ fileapi::kFileSystemTypeTemporary)); |
+ EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin2, |
+ fileapi::kFileSystemTypePersistent)); |
+ EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin2, |
+ fileapi::kFileSystemTypeTemporary)); |
+ EXPECT_TRUE(tester->FileSystemContainsOriginAndType(kOrigin3, |
+ fileapi::kFileSystemTypePersistent)); |
+ EXPECT_FALSE(tester->FileSystemContainsOriginAndType(kOrigin3, |
+ fileapi::kFileSystemTypeTemporary)); |
+} |
+ |
TEST_F(BrowsingDataRemoverTest, RemoveAppCacheForever) { |
// Set up ChromeAppCacheService with a single protected origin |
scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = |