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

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

Issue 2368913003: Populate storage_unittests target. (Closed)
Patch Set: Removed unnecessary include from storage/browser/blob/blob_storage_context_unittest.cc. Created 4 years, 2 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
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 "content/public/test/test_file_system_context.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 "testing/gtest/include/gtest/gtest.h"
20
21 using storage::FileSystemURL;
22
23 namespace content {
24
25 class TransientFileUtilTest : public testing::Test {
26 public:
27 TransientFileUtilTest() {}
28 ~TransientFileUtilTest() override {}
29
30 void SetUp() override {
31 file_system_context_ = CreateFileSystemContextForTesting(
32 NULL, base::FilePath(FILE_PATH_LITERAL("dummy")));
33 transient_file_util_.reset(new storage::TransientFileUtil);
34
35 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
36 }
37
38 void TearDown() override {
39 file_system_context_ = NULL;
40 base::RunLoop().RunUntilIdle();
41 }
42
43 void CreateAndRegisterTemporaryFile(
44 FileSystemURL* file_url,
45 base::FilePath* file_path) {
46 EXPECT_TRUE(base::CreateTemporaryFileInDir(data_dir_.GetPath(), file_path));
47 storage::IsolatedContext* isolated_context =
48 storage::IsolatedContext::GetInstance();
49 std::string name = "tmp";
50 std::string fsid = isolated_context->RegisterFileSystemForPath(
51 storage::kFileSystemTypeForTransientFile,
52 std::string(),
53 *file_path,
54 &name);
55 ASSERT_TRUE(!fsid.empty());
56 base::FilePath virtual_path = isolated_context->CreateVirtualRootPath(
57 fsid).AppendASCII(name);
58 *file_url = file_system_context_->CreateCrackedFileSystemURL(
59 GURL("http://foo"), storage::kFileSystemTypeIsolated, virtual_path);
60 }
61
62 std::unique_ptr<storage::FileSystemOperationContext> NewOperationContext() {
63 return base::MakeUnique<storage::FileSystemOperationContext>(
64 file_system_context_.get());
65 }
66
67 storage::FileSystemFileUtil* file_util() {
68 return transient_file_util_.get();
69 }
70
71 private:
72 base::MessageLoop message_loop_;
73 base::ScopedTempDir data_dir_;
74 scoped_refptr<storage::FileSystemContext> file_system_context_;
75 std::unique_ptr<storage::TransientFileUtil> transient_file_util_;
76
77 DISALLOW_COPY_AND_ASSIGN(TransientFileUtilTest);
78 };
79
80 TEST_F(TransientFileUtilTest, TransientFile) {
81 FileSystemURL temp_url;
82 base::FilePath temp_path;
83
84 CreateAndRegisterTemporaryFile(&temp_url, &temp_path);
85
86 base::File::Error error;
87 base::File::Info file_info;
88 base::FilePath path;
89
90 // Make sure the file is there.
91 ASSERT_TRUE(temp_url.is_valid());
92 ASSERT_TRUE(base::PathExists(temp_path));
93 ASSERT_FALSE(base::DirectoryExists(temp_path));
94
95 // Create a snapshot file.
96 {
97 storage::ScopedFile scoped_file = file_util()->CreateSnapshotFile(
98 NewOperationContext().get(), temp_url, &error, &file_info, &path);
99 ASSERT_EQ(base::File::FILE_OK, error);
100 ASSERT_EQ(temp_path, path);
101 ASSERT_FALSE(file_info.is_directory);
102
103 // The file should be still there.
104 ASSERT_TRUE(base::PathExists(temp_path));
105 ASSERT_EQ(base::File::FILE_OK,
106 file_util()->GetFileInfo(NewOperationContext().get(),
107 temp_url, &file_info, &path));
108 ASSERT_EQ(temp_path, path);
109 ASSERT_FALSE(file_info.is_directory);
110 }
111
112 // The file's now scoped out.
113 base::RunLoop().RunUntilIdle();
114
115 // Now the temporary file and the transient filesystem must be gone too.
116 ASSERT_FALSE(base::PathExists(temp_path));
117 ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND,
118 file_util()->GetFileInfo(NewOperationContext().get(),
119 temp_url, &file_info, &path));
120 }
121
122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698