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

Side by Side Diff: webkit/fileapi/file_system_context_unittest.cc

Issue 14096022: Make MountPointProvider pluggable from outside webkit/fileapi (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/fileapi/file_system_context.h" 5 #include "webkit/fileapi/file_system_context.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/fileapi/external_mount_points.h" 11 #include "webkit/fileapi/external_mount_points.h"
12 #include "webkit/fileapi/file_system_mount_point_provider.h"
12 #include "webkit/fileapi/file_system_task_runners.h" 13 #include "webkit/fileapi/file_system_task_runners.h"
13 #include "webkit/fileapi/isolated_context.h" 14 #include "webkit/fileapi/isolated_context.h"
14 #include "webkit/fileapi/mock_file_system_options.h" 15 #include "webkit/fileapi/mock_file_system_options.h"
15 #include "webkit/quota/mock_quota_manager.h" 16 #include "webkit/quota/mock_quota_manager.h"
16 #include "webkit/quota/mock_special_storage_policy.h" 17 #include "webkit/quota/mock_special_storage_policy.h"
17 18
18 #define FPL(x) FILE_PATH_LITERAL(x) 19 #define FPL(x) FILE_PATH_LITERAL(x)
19 20
20 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 21 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
21 #define DRIVE FPL("C:") 22 #define DRIVE FPL("C:")
(...skipping 17 matching lines...) Expand all
39 return GURL(url_str); 40 return GURL(url_str);
40 } 41 }
41 42
42 class FileSystemContextTest : public testing::Test { 43 class FileSystemContextTest : public testing::Test {
43 public: 44 public:
44 FileSystemContextTest() {} 45 FileSystemContextTest() {}
45 46
46 virtual void SetUp() { 47 virtual void SetUp() {
47 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 48 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
48 49
49 storage_policy_ = new quota::MockSpecialStoragePolicy();
50
51 mock_quota_manager_ = new quota::MockQuotaManager( 50 mock_quota_manager_ = new quota::MockQuotaManager(
52 false /* is_incognito */, 51 false /* is_incognito */,
53 data_dir_.path(), 52 data_dir_.path(),
54 base::MessageLoopProxy::current(), 53 base::MessageLoopProxy::current(),
55 base::MessageLoopProxy::current(), 54 base::MessageLoopProxy::current(),
56 storage_policy_); 55 new quota::MockSpecialStoragePolicy());
57 } 56 }
58 57
59 protected: 58 protected:
60 FileSystemContext* CreateFileSystemContextForTest( 59 FileSystemContext* CreateFileSystemContextForTest(
61 ExternalMountPoints* external_mount_points) { 60 ExternalMountPoints* external_mount_points) {
61 std::vector<MountPoints*> additional_mount_points;
62 if (external_mount_points)
63 additional_mount_points.push_back(external_mount_points);
62 return new FileSystemContext( 64 return new FileSystemContext(
63 FileSystemTaskRunners::CreateMockTaskRunners(), 65 FileSystemTaskRunners::CreateMockTaskRunners(),
64 external_mount_points,
65 storage_policy_,
66 mock_quota_manager_->proxy(), 66 mock_quota_manager_->proxy(),
67 ScopedVector<FileSystemMountPointProvider>(),
68 additional_mount_points,
67 data_dir_.path(), 69 data_dir_.path(),
68 CreateAllowFileAccessOptions()); 70 CreateAllowFileAccessOptions());
69 } 71 }
70 72
71 // Verifies a *valid* filesystem url has expected values. 73 // Verifies a *valid* filesystem url has expected values.
72 void ExpectFileSystemURLMatches(const FileSystemURL& url, 74 void ExpectFileSystemURLMatches(const FileSystemURL& url,
73 const GURL& expect_origin, 75 const GURL& expect_origin,
74 FileSystemType expect_mount_type, 76 FileSystemType expect_mount_type,
75 FileSystemType expect_type, 77 FileSystemType expect_type,
76 const base::FilePath& expect_path, 78 const base::FilePath& expect_path,
77 const base::FilePath& expect_virtual_path, 79 const base::FilePath& expect_virtual_path,
78 const std::string& expect_filesystem_id) { 80 const std::string& expect_filesystem_id) {
79 EXPECT_TRUE(url.is_valid()); 81 EXPECT_TRUE(url.is_valid());
80 82
81 EXPECT_EQ(expect_origin, url.origin()); 83 EXPECT_EQ(expect_origin, url.origin());
82 EXPECT_EQ(expect_mount_type, url.mount_type()); 84 EXPECT_EQ(expect_mount_type, url.mount_type());
83 EXPECT_EQ(expect_type, url.type()); 85 EXPECT_EQ(expect_type, url.type());
84 EXPECT_EQ(expect_path, url.path()); 86 EXPECT_EQ(expect_path, url.path());
85 EXPECT_EQ(expect_virtual_path, url.virtual_path()); 87 EXPECT_EQ(expect_virtual_path, url.virtual_path());
86 EXPECT_EQ(expect_filesystem_id, url.filesystem_id()); 88 EXPECT_EQ(expect_filesystem_id, url.filesystem_id());
87 } 89 }
88 90
89 private: 91 private:
90 base::ScopedTempDir data_dir_; 92 base::ScopedTempDir data_dir_;
91 MessageLoop message_loop_; 93 MessageLoop message_loop_;
92 scoped_refptr<quota::SpecialStoragePolicy> storage_policy_;
93 scoped_refptr<quota::MockQuotaManager> mock_quota_manager_; 94 scoped_refptr<quota::MockQuotaManager> mock_quota_manager_;
94 }; 95 };
95 96
96 // It is not valid to pass NULL ExternalMountPoints to FileSystemContext on
97 // ChromeOS.
98 #if !defined(OS_CHROMEOS)
99 TEST_F(FileSystemContextTest, NullExternalMountPoints) { 97 TEST_F(FileSystemContextTest, NullExternalMountPoints) {
100 scoped_refptr<FileSystemContext> file_system_context( 98 scoped_refptr<FileSystemContext> file_system_context(
101 CreateFileSystemContextForTest(NULL)); 99 CreateFileSystemContextForTest(NULL));
102 100
103 // Cracking system external mount and isolated mount points should work. 101 // Cracking system external mount and isolated mount points should work.
104 std::string isolated_name = "root"; 102 std::string isolated_name = "root";
105 std::string isolated_id = 103 std::string isolated_id =
106 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 104 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
107 kFileSystemTypeNativeLocal, 105 kFileSystemTypeNativeLocal,
108 base::FilePath(DRIVE FPL("/test/isolated/root")), 106 base::FilePath(DRIVE FPL("/test/isolated/root")),
109 &isolated_name); 107 &isolated_name);
110 // Register system external mount point. 108 // Register system external mount point.
111 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 109 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
112 "system", 110 "system",
113 kFileSystemTypeNativeLocal, 111 kFileSystemTypeNativeLocal,
114 base::FilePath(DRIVE FPL("/test/sys/")))); 112 base::FilePath(DRIVE FPL("/test/sys/"))));
115 113
116 FileSystemURL cracked_isolated = file_system_context->CrackURL( 114 FileSystemURL cracked_isolated = file_system_context->CrackURL(
117 CreateRawFileSystemURL("isolated", isolated_id)); 115 CreateRawFileSystemURL("isolated", isolated_id));
118 116
119 ExpectFileSystemURLMatches( 117 ExpectFileSystemURLMatches(
120 cracked_isolated, 118 cracked_isolated,
121 GURL(kTestOrigin), 119 GURL(kTestOrigin),
122 kFileSystemTypeIsolated, 120 kFileSystemTypeIsolated,
123 kFileSystemTypeNativeLocal, 121 kFileSystemTypeNativeLocal,
124 base::FilePath(DRIVE FPL("/test/isolated/root/file")).NormalizePathSeparat ors(), 122 base::FilePath(
123 DRIVE FPL("/test/isolated/root/file")).NormalizePathSeparators(),
125 base::FilePath::FromUTF8Unsafe(isolated_id).Append(FPL("root/file")). 124 base::FilePath::FromUTF8Unsafe(isolated_id).Append(FPL("root/file")).
126 NormalizePathSeparators(), 125 NormalizePathSeparators(),
127 isolated_id); 126 isolated_id);
128 127
129 FileSystemURL cracked_external = file_system_context->CrackURL( 128 FileSystemURL cracked_external = file_system_context->CrackURL(
130 CreateRawFileSystemURL("external", "system")); 129 CreateRawFileSystemURL("external", "system"));
131 130
132 ExpectFileSystemURLMatches( 131 ExpectFileSystemURLMatches(
133 cracked_external, 132 cracked_external,
134 GURL(kTestOrigin), 133 GURL(kTestOrigin),
135 kFileSystemTypeExternal, 134 kFileSystemTypeExternal,
136 kFileSystemTypeNativeLocal, 135 kFileSystemTypeNativeLocal,
137 base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators() , 136 base::FilePath(
137 DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(),
138 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(), 138 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(),
139 "system"); 139 "system");
140 140
141 141
142 IsolatedContext::GetInstance()->RevokeFileSystem(isolated_id); 142 IsolatedContext::GetInstance()->RevokeFileSystem(isolated_id);
143 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system"); 143 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
144 } 144 }
145 #endif // !defiend(OS_CHROMEOS)
146
147 TEST_F(FileSystemContextTest, FileSystemContextKeepsMountPointsAlive) {
148 scoped_refptr<ExternalMountPoints> mount_points =
149 ExternalMountPoints::CreateRefCounted();
150
151 // Register system external mount point.
152 ASSERT_TRUE(mount_points->RegisterFileSystem(
153 "system",
154 kFileSystemTypeNativeLocal,
155 base::FilePath(DRIVE FPL("/test/sys/"))));
156
157 scoped_refptr<FileSystemContext> file_system_context(
158 CreateFileSystemContextForTest(mount_points.get()));
159
160 // Release a MountPoints reference created in the test.
161 mount_points = NULL;
162
163 // FileSystemContext should keep a reference to the |mount_points|, so it
164 // should be able to resolve the URL.
165 FileSystemURL cracked_external = file_system_context->CrackURL(
166 CreateRawFileSystemURL("external", "system"));
167
168 ExpectFileSystemURLMatches(
169 cracked_external,
170 GURL(kTestOrigin),
171 kFileSystemTypeExternal,
172 kFileSystemTypeNativeLocal,
173 base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators() ,
174 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(),
175 "system");
176
177 // No need to revoke the registered filesystem since |mount_points| lifetime
178 // is bound to this test.
179 }
180 145
181 TEST_F(FileSystemContextTest, CrackFileSystemURL) { 146 TEST_F(FileSystemContextTest, CrackFileSystemURL) {
182 scoped_refptr<ExternalMountPoints> external_mount_points( 147 scoped_refptr<ExternalMountPoints> external_mount_points(
183 ExternalMountPoints::CreateRefCounted()); 148 ExternalMountPoints::CreateRefCounted());
184 scoped_refptr<FileSystemContext> file_system_context( 149 scoped_refptr<FileSystemContext> file_system_context(
185 CreateFileSystemContextForTest(external_mount_points)); 150 CreateFileSystemContextForTest(external_mount_points));
186 151
187 // Register an isolated mount point. 152 // Register an isolated mount point.
188 std::string isolated_file_system_name = "root"; 153 std::string isolated_file_system_name = "root";
189 const std::string kIsolatedFileSystemID = 154 const std::string kIsolatedFileSystemID =
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 base::FilePath(DRIVE FPL("/test/isolated/root"))); 281 base::FilePath(DRIVE FPL("/test/isolated/root")));
317 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system"); 282 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
318 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("ext"); 283 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("ext");
319 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 284 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
320 kIsolatedFileSystemID); 285 kIsolatedFileSystemID);
321 } 286 }
322 287
323 } // namespace 288 } // namespace
324 289
325 } // namespace fileapi 290 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698