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

Unified Diff: chrome/browser/browsing_data_remover_unittest.cc

Issue 7129018: Time-based removal of temporary file systems via BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FILE_PATH_LITERAL macro. Created 9 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e55e87b1976a19a3d236f0fcab3f13c6bcfed299..92b9591a1c1cfd5ff21cc388673583a308991f32 100644
--- a/chrome/browser/browsing_data_remover_unittest.cc
+++ b/chrome/browser/browsing_data_remover_unittest.cc
@@ -13,6 +13,7 @@
#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"
namespace {
@@ -116,7 +117,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,
@@ -128,6 +130,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,
@@ -144,13 +156,41 @@ class RemoveFileSystemTester : public BrowsingDataRemoverTester {
void CreateDirectoryForOriginAndType(const GURL& origin,
fileapi::FileSystemType type) {
+ fileapi::FileSystemTestOriginHelper helper(origin, type);
+ helper.SetUp(profile_->GetFileSystemContext(),
+ sandbox_->GetFileSystemFileUtil());
kinuko 2011/06/15 11:25:14 nit: indent
FilePath target = sandbox_->ValidateFileSystemRootAndGetPathOnFileThread(
origin, type, FilePath(), true);
kinuko 2011/06/15 11:25:14 helper.SetUp performs this internally.
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);
kinuko 2011/06/15 11:25:14 nit: you could also call helper.NewOperationContex
+
+ bool created;
+ base::PlatformFileError status = file_util->EnsureFileExists(
+ op_context.get(), path, &created);
+ 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);
@@ -264,4 +304,26 @@ 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));
kinuko 2011/06/15 11:25:14 Is there any chance that any of the files are not
+ 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));
+}
+
} // namespace
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698