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

Unified Diff: webkit/fileapi/transient_file_util_unittest.cc

Issue 14493007: Add Transient FileSystem which goes away after its snapsot file is gone (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « webkit/fileapi/transient_file_util.cc ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/transient_file_util_unittest.cc
diff --git a/webkit/fileapi/transient_file_util_unittest.cc b/webkit/fileapi/transient_file_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..845aa704880490bb5ffd754ce1701db52a7c7ced
--- /dev/null
+++ b/webkit/fileapi/transient_file_util_unittest.cc
@@ -0,0 +1,122 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/platform_file.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/blob/scoped_file.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/isolated_context.h"
+#include "webkit/fileapi/mock_file_system_context.h"
+#include "webkit/fileapi/transient_file_util.h"
+
+namespace fileapi {
+
+class TransientFileUtilTest : public testing::Test {
+ public:
+ TransientFileUtilTest() {}
+ virtual ~TransientFileUtilTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ file_system_context_ = CreateFileSystemContextForTesting(
+ NULL, base::FilePath("dummy"));
+ transient_file_util_.reset(new TransientFileUtil);
+
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ file_system_context_ = NULL;
+ MessageLoop::current()->RunUntilIdle();
+ }
+
+ void CreateAndRegisterTemporaryFile(
+ FileSystemURL* file_url,
+ base::FilePath* file_path) {
+ EXPECT_TRUE(
+ file_util::CreateTemporaryFileInDir(data_dir_.path(), file_path));
+ IsolatedContext* isolated_context = IsolatedContext::GetInstance();
+ std::string name = "tmp";
+ std::string fsid = isolated_context->RegisterFileSystemForPath(
+ kFileSystemTypeForTransientFile,
+ *file_path,
+ &name);
+ ASSERT_TRUE(!fsid.empty());
+ base::FilePath virtual_path = isolated_context->CreateVirtualRootPath(
+ fsid).AppendASCII(name);
+ *file_url = file_system_context_->CreateCrackedFileSystemURL(
+ GURL("http://foo"),
+ kFileSystemTypeIsolated,
+ virtual_path);
+ }
+
+ scoped_ptr<FileSystemOperationContext> NewOperationContext() {
+ return make_scoped_ptr(
+ new FileSystemOperationContext(file_system_context_));
+ }
+
+ FileSystemFileUtil* file_util() { return transient_file_util_.get(); }
+
+ private:
+ MessageLoop message_loop_;
+ base::ScopedTempDir data_dir_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+ scoped_ptr<TransientFileUtil> transient_file_util_;
+
+ DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest);
+};
+
+TEST_F(TransientFileUtilTest, TransientFile) {
+ FileSystemURL temp_url;
+ base::FilePath temp_path;
+
+ CreateAndRegisterTemporaryFile(&temp_url, &temp_path);
+
+ base::PlatformFileError error;
+ base::PlatformFileInfo file_info;
+ base::FilePath path;
+
+ // Make sure the file is there.
+ ASSERT_TRUE(temp_url.is_valid());
+ ASSERT_TRUE(file_util::PathExists(temp_path));
+ ASSERT_FALSE(file_util::DirectoryExists(temp_path));
+
+ // Create a snapshot file.
+ {
+ webkit_blob::ScopedFile scoped_file =
+ file_util()->CreateSnapshotFile(NewOperationContext().get(),
+ temp_url,
+ &error,
+ &file_info,
+ &path);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, error);
+ ASSERT_EQ(temp_path, path);
+ ASSERT_FALSE(file_info.is_directory);
+
+ // The file should be still there.
+ ASSERT_TRUE(file_util::PathExists(temp_path));
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ file_util()->GetFileInfo(NewOperationContext().get(),
+ temp_url, &file_info, &path));
+ ASSERT_EQ(temp_path, path);
+ ASSERT_FALSE(file_info.is_directory);
+ }
+
+ // The file's now scoped out.
+ MessageLoop::current()->RunUntilIdle();
+
+ // Now the temporary file and the transient filesystem must be gone too.
+ ASSERT_FALSE(file_util::PathExists(temp_path));
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ file_util()->GetFileInfo(NewOperationContext().get(),
+ temp_url, &file_info, &path));
+}
+
+} // namespace fileapi
« no previous file with comments | « webkit/fileapi/transient_file_util.cc ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698