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

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

Issue 2813353003: Move some File API backend unit tests next to the files that they cover. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « content/browser/fileapi/sandbox_file_system_backend_unittest.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h"
13 #include "base/test/scoped_task_environment.h"
14 #include "storage/browser/blob/scoped_file.h"
15 #include "storage/browser/fileapi/file_system_context.h"
16 #include "storage/browser/fileapi/file_system_operation_context.h"
17 #include "storage/browser/fileapi/isolated_context.h"
18 #include "storage/browser/fileapi/transient_file_util.h"
19 #include "storage/browser/test/test_file_system_context.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 using storage::FileSystemURL;
23
24 namespace content {
25
26 class TransientFileUtilTest : public testing::Test {
27 public:
28 TransientFileUtilTest() {}
29 ~TransientFileUtilTest() override {}
30
31 void SetUp() override {
32 file_system_context_ = CreateFileSystemContextForTesting(
33 NULL, base::FilePath(FILE_PATH_LITERAL("dummy")));
34 transient_file_util_.reset(new storage::TransientFileUtil);
35
36 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
37 }
38
39 void TearDown() override {
40 file_system_context_ = NULL;
41 base::RunLoop().RunUntilIdle();
42 }
43
44 void CreateAndRegisterTemporaryFile(
45 FileSystemURL* file_url,
46 base::FilePath* file_path) {
47 EXPECT_TRUE(base::CreateTemporaryFileInDir(data_dir_.GetPath(), file_path));
48 storage::IsolatedContext* isolated_context =
49 storage::IsolatedContext::GetInstance();
50 std::string name = "tmp";
51 std::string fsid = isolated_context->RegisterFileSystemForPath(
52 storage::kFileSystemTypeForTransientFile,
53 std::string(),
54 *file_path,
55 &name);
56 ASSERT_TRUE(!fsid.empty());
57 base::FilePath virtual_path = isolated_context->CreateVirtualRootPath(
58 fsid).AppendASCII(name);
59 *file_url = file_system_context_->CreateCrackedFileSystemURL(
60 GURL("http://foo"), storage::kFileSystemTypeIsolated, virtual_path);
61 }
62
63 std::unique_ptr<storage::FileSystemOperationContext> NewOperationContext() {
64 return base::MakeUnique<storage::FileSystemOperationContext>(
65 file_system_context_.get());
66 }
67
68 storage::FileSystemFileUtil* file_util() {
69 return transient_file_util_.get();
70 }
71
72 private:
73 base::test::ScopedTaskEnvironment scoped_task_environment_;
74 base::ScopedTempDir data_dir_;
75 scoped_refptr<storage::FileSystemContext> file_system_context_;
76 std::unique_ptr<storage::TransientFileUtil> transient_file_util_;
77
78 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest);
79 };
80
81 TEST_F(TransientFileUtilTest, TransientFile) {
82 FileSystemURL temp_url;
83 base::FilePath temp_path;
84
85 CreateAndRegisterTemporaryFile(&temp_url, &temp_path);
86
87 base::File::Error error;
88 base::File::Info file_info;
89 base::FilePath path;
90
91 // Make sure the file is there.
92 ASSERT_TRUE(temp_url.is_valid());
93 ASSERT_TRUE(base::PathExists(temp_path));
94 ASSERT_FALSE(base::DirectoryExists(temp_path));
95
96 // Create a snapshot file.
97 {
98 storage::ScopedFile scoped_file = file_util()->CreateSnapshotFile(
99 NewOperationContext().get(), temp_url, &error, &file_info, &path);
100 ASSERT_EQ(base::File::FILE_OK, error);
101 ASSERT_EQ(temp_path, path);
102 ASSERT_FALSE(file_info.is_directory);
103
104 // The file should be still there.
105 ASSERT_TRUE(base::PathExists(temp_path));
106 ASSERT_EQ(base::File::FILE_OK,
107 file_util()->GetFileInfo(NewOperationContext().get(),
108 temp_url, &file_info, &path));
109 ASSERT_EQ(temp_path, path);
110 ASSERT_FALSE(file_info.is_directory);
111 }
112
113 // The file's now scoped out.
114 base::RunLoop().RunUntilIdle();
115
116 // Now the temporary file and the transient filesystem must be gone too.
117 ASSERT_FALSE(base::PathExists(temp_path));
118 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND,
119 file_util()->GetFileInfo(NewOperationContext().get(),
120 temp_url, &file_info, &path));
121 }
122
123 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/sandbox_file_system_backend_unittest.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698