OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_path_manager.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
15 #include "base/scoped_callback_factory.h" | 15 #include "base/scoped_callback_factory.h" |
16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
17 #include "base/scoped_temp_dir.h" | 17 #include "base/scoped_temp_dir.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "webkit/fileapi/file_system_path_manager.h" |
| 21 #include "webkit/fileapi/file_system_util.h" |
20 | 22 |
21 using namespace fileapi; | 23 using namespace fileapi; |
22 | 24 |
23 namespace { | 25 class SandboxMountPointProviderOriginEnumeratorTest : public testing::Test { |
24 | |
25 // PS stands for path separator. | |
26 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
27 #define PS "\\" | |
28 #else | |
29 #define PS "/" | |
30 #endif | |
31 | |
32 struct RootPathTestCase { | |
33 fileapi::FileSystemType type; | |
34 const char* origin_url; | |
35 const char* expected_path; | |
36 }; | |
37 | |
38 const struct RootPathTest { | |
39 fileapi::FileSystemType type; | |
40 const char* origin_url; | |
41 const char* expected_path; | |
42 } kRootPathTestCases[] = { | |
43 { fileapi::kFileSystemTypeTemporary, "http://foo:1/", | |
44 "http_foo_1" PS "Temporary" }, | |
45 { fileapi::kFileSystemTypePersistent, "http://foo:1/", | |
46 "http_foo_1" PS "Persistent" }, | |
47 { fileapi::kFileSystemTypeTemporary, "http://bar.com/", | |
48 "http_bar.com_0" PS "Temporary" }, | |
49 { fileapi::kFileSystemTypePersistent, "http://bar.com/", | |
50 "http_bar.com_0" PS "Persistent" }, | |
51 { fileapi::kFileSystemTypeTemporary, "https://foo:2/", | |
52 "https_foo_2" PS "Temporary" }, | |
53 { fileapi::kFileSystemTypePersistent, "https://foo:2/", | |
54 "https_foo_2" PS "Persistent" }, | |
55 { fileapi::kFileSystemTypeTemporary, "https://bar.com/", | |
56 "https_bar.com_0" PS "Temporary" }, | |
57 { fileapi::kFileSystemTypePersistent, "https://bar.com/", | |
58 "https_bar.com_0" PS "Persistent" }, | |
59 }; | |
60 | |
61 const struct RootPathFileURITest { | |
62 fileapi::FileSystemType type; | |
63 const char* origin_url; | |
64 const char* expected_path; | |
65 } kRootPathFileURITestCases[] = { | |
66 { fileapi::kFileSystemTypeTemporary, "file:///", | |
67 "file__0" PS "Temporary" }, | |
68 { fileapi::kFileSystemTypePersistent, "file:///", | |
69 "file__0" PS "Persistent" }, | |
70 }; | |
71 | |
72 const struct CheckValidPathTest { | |
73 FilePath::StringType path; | |
74 bool expected_valid; | |
75 } kCheckValidPathTestCases[] = { | |
76 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, | |
77 { FILE_PATH_LITERAL("//etc/hosts"), false, }, | |
78 { FILE_PATH_LITERAL("foo.txt"), true, }, | |
79 { FILE_PATH_LITERAL("a/b/c"), true, }, | |
80 // Any paths that includes parent references are considered invalid. | |
81 { FILE_PATH_LITERAL(".."), false, }, | |
82 { FILE_PATH_LITERAL("tmp/.."), false, }, | |
83 { FILE_PATH_LITERAL("a/b/../c/.."), false, }, | |
84 }; | |
85 | |
86 const char* const kPathToVirtualPathTestCases[] = { | |
87 "", | |
88 "a", | |
89 "a" PS "b", | |
90 "a" PS "b" PS "c", | |
91 }; | |
92 | |
93 const struct IsRestrictedNameTest { | |
94 FilePath::StringType name; | |
95 bool expected_dangerous; | |
96 } kIsRestrictedNameTestCases[] = { | |
97 // Name that has restricted names in it. | |
98 { FILE_PATH_LITERAL("con"), true, }, | |
99 { FILE_PATH_LITERAL("Con.txt"), true, }, | |
100 { FILE_PATH_LITERAL("Prn.png"), true, }, | |
101 { FILE_PATH_LITERAL("AUX"), true, }, | |
102 { FILE_PATH_LITERAL("nUl."), true, }, | |
103 { FILE_PATH_LITERAL("coM1"), true, }, | |
104 { FILE_PATH_LITERAL("COM3.com"), true, }, | |
105 { FILE_PATH_LITERAL("cOM7"), true, }, | |
106 { FILE_PATH_LITERAL("com9"), true, }, | |
107 { FILE_PATH_LITERAL("lpT1"), true, }, | |
108 { FILE_PATH_LITERAL("LPT4.com"), true, }, | |
109 { FILE_PATH_LITERAL("lPT8"), true, }, | |
110 { FILE_PATH_LITERAL("lPT9"), true, }, | |
111 // Similar but safe cases. | |
112 { FILE_PATH_LITERAL("con3"), false, }, | |
113 { FILE_PATH_LITERAL("PrnImage.png"), false, }, | |
114 { FILE_PATH_LITERAL("AUXX"), false, }, | |
115 { FILE_PATH_LITERAL("NULL"), false, }, | |
116 { FILE_PATH_LITERAL("coM0"), false, }, | |
117 { FILE_PATH_LITERAL("COM.com"), false, }, | |
118 { FILE_PATH_LITERAL("lpT0"), false, }, | |
119 { FILE_PATH_LITERAL("LPT.com"), false, }, | |
120 | |
121 // Ends with period or whitespace. | |
122 { FILE_PATH_LITERAL("b "), true, }, | |
123 { FILE_PATH_LITERAL("b\t"), true, }, | |
124 { FILE_PATH_LITERAL("b\n"), true, }, | |
125 { FILE_PATH_LITERAL("b\r\n"), true, }, | |
126 { FILE_PATH_LITERAL("b."), true, }, | |
127 { FILE_PATH_LITERAL("b.."), true, }, | |
128 // Similar but safe cases. | |
129 { FILE_PATH_LITERAL("b c"), false, }, | |
130 { FILE_PATH_LITERAL("b\tc"), false, }, | |
131 { FILE_PATH_LITERAL("b\nc"), false, }, | |
132 { FILE_PATH_LITERAL("b\r\nc"), false, }, | |
133 { FILE_PATH_LITERAL("b c d e f"), false, }, | |
134 { FILE_PATH_LITERAL("b.c"), false, }, | |
135 { FILE_PATH_LITERAL("b..c"), false, }, | |
136 | |
137 // Name that has restricted chars in it. | |
138 { FILE_PATH_LITERAL("a\\b"), true, }, | |
139 { FILE_PATH_LITERAL("a/b"), true, }, | |
140 { FILE_PATH_LITERAL("a<b"), true, }, | |
141 { FILE_PATH_LITERAL("a>b"), true, }, | |
142 { FILE_PATH_LITERAL("a:b"), true, }, | |
143 { FILE_PATH_LITERAL("a?b"), true, }, | |
144 { FILE_PATH_LITERAL("a|b"), true, }, | |
145 { FILE_PATH_LITERAL("ab\\"), true, }, | |
146 { FILE_PATH_LITERAL("ab/.txt"), true, }, | |
147 { FILE_PATH_LITERAL("ab<.txt"), true, }, | |
148 { FILE_PATH_LITERAL("ab>.txt"), true, }, | |
149 { FILE_PATH_LITERAL("ab:.txt"), true, }, | |
150 { FILE_PATH_LITERAL("ab?.txt"), true, }, | |
151 { FILE_PATH_LITERAL("ab|.txt"), true, }, | |
152 { FILE_PATH_LITERAL("\\ab"), true, }, | |
153 { FILE_PATH_LITERAL("/ab"), true, }, | |
154 { FILE_PATH_LITERAL("<ab"), true, }, | |
155 { FILE_PATH_LITERAL(">ab"), true, }, | |
156 { FILE_PATH_LITERAL(":ab"), true, }, | |
157 { FILE_PATH_LITERAL("?ab"), true, }, | |
158 { FILE_PATH_LITERAL("|ab"), true, }, | |
159 }; | |
160 | |
161 } // namespace | |
162 | |
163 class FileSystemPathManagerTest : public testing::Test { | |
164 public: | |
165 FileSystemPathManagerTest() | |
166 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
167 } | |
168 | |
169 void SetUp() { | |
170 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | |
171 root_path_callback_status_ = false; | |
172 root_path_.clear(); | |
173 file_system_name_.clear(); | |
174 } | |
175 | |
176 protected: | |
177 FileSystemPathManager* NewPathManager( | |
178 bool incognito, | |
179 bool allow_file_access) { | |
180 return new FileSystemPathManager( | |
181 base::MessageLoopProxy::CreateForCurrentThread(), | |
182 data_dir_.path(), incognito, allow_file_access); | |
183 } | |
184 | |
185 void OnGetRootPath(bool success, | |
186 const FilePath& root_path, | |
187 const std::string& name) { | |
188 root_path_callback_status_ = success; | |
189 root_path_ = root_path; | |
190 file_system_name_ = name; | |
191 } | |
192 | |
193 bool GetRootPath(FileSystemPathManager* manager, | |
194 const GURL& origin_url, | |
195 fileapi::FileSystemType type, | |
196 bool create, | |
197 FilePath* root_path) { | |
198 manager->GetFileSystemRootPath(origin_url, type, create, | |
199 callback_factory_.NewCallback( | |
200 &FileSystemPathManagerTest::OnGetRootPath)); | |
201 MessageLoop::current()->RunAllPending(); | |
202 if (root_path) | |
203 *root_path = root_path_; | |
204 return root_path_callback_status_; | |
205 } | |
206 | |
207 bool CheckValidFileSystemPath(FileSystemPathManager* manager, | |
208 const FilePath& path) { | |
209 return manager->CrackFileSystemPath(path, NULL, NULL, NULL); | |
210 } | |
211 | |
212 FilePath data_path() { return data_dir_.path(); } | |
213 FilePath file_system_path() { | |
214 return data_dir_.path().Append( | |
215 FileSystemPathManager::kFileSystemDirectory); | |
216 } | |
217 | |
218 private: | |
219 ScopedTempDir data_dir_; | |
220 base::ScopedCallbackFactory<FileSystemPathManagerTest> callback_factory_; | |
221 | |
222 bool root_path_callback_status_; | |
223 FilePath root_path_; | |
224 std::string file_system_name_; | |
225 | |
226 DISALLOW_COPY_AND_ASSIGN(FileSystemPathManagerTest); | |
227 }; | |
228 | |
229 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) { | |
230 std::vector<FilePath> returned_root_path( | |
231 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | |
232 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
233 | |
234 // Create a new root directory. | |
235 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | |
236 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " | |
237 << kRootPathTestCases[i].expected_path); | |
238 | |
239 FilePath root_path; | |
240 EXPECT_TRUE(GetRootPath(manager.get(), | |
241 GURL(kRootPathTestCases[i].origin_url), | |
242 kRootPathTestCases[i].type, | |
243 true /* create */, &root_path)); | |
244 | |
245 FilePath expected = file_system_path().AppendASCII( | |
246 kRootPathTestCases[i].expected_path); | |
247 EXPECT_EQ(expected.value(), root_path.DirName().value()); | |
248 EXPECT_TRUE(file_util::DirectoryExists(root_path)); | |
249 ASSERT_TRUE(returned_root_path.size() > i); | |
250 returned_root_path[i] = root_path; | |
251 } | |
252 | |
253 // Get the root directory with create=false and see if we get the | |
254 // same directory. | |
255 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | |
256 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " | |
257 << kRootPathTestCases[i].expected_path); | |
258 | |
259 FilePath root_path; | |
260 EXPECT_TRUE(GetRootPath(manager.get(), | |
261 GURL(kRootPathTestCases[i].origin_url), | |
262 kRootPathTestCases[i].type, | |
263 false /* create */, &root_path)); | |
264 ASSERT_TRUE(returned_root_path.size() > i); | |
265 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); | |
266 } | |
267 } | |
268 | |
269 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamineWithNewManager) { | |
270 std::vector<FilePath> returned_root_path( | |
271 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | |
272 scoped_ptr<FileSystemPathManager> manager1(NewPathManager(false, false)); | |
273 scoped_ptr<FileSystemPathManager> manager2(NewPathManager(false, false)); | |
274 | |
275 GURL origin_url("http://foo.com:1/"); | |
276 | |
277 FilePath root_path1; | |
278 EXPECT_TRUE(GetRootPath(manager1.get(), origin_url, | |
279 kFileSystemTypeTemporary, true, &root_path1)); | |
280 FilePath root_path2; | |
281 EXPECT_TRUE(GetRootPath(manager2.get(), origin_url, | |
282 kFileSystemTypeTemporary, false, &root_path2)); | |
283 | |
284 EXPECT_EQ(root_path1.value(), root_path2.value()); | |
285 } | |
286 | |
287 TEST_F(FileSystemPathManagerTest, GetRootPathGetWithoutCreate) { | |
288 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
289 | |
290 // Try to get a root directory without creating. | |
291 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | |
292 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " | |
293 << kRootPathTestCases[i].expected_path); | |
294 EXPECT_FALSE(GetRootPath(manager.get(), | |
295 GURL(kRootPathTestCases[i].origin_url), | |
296 kRootPathTestCases[i].type, | |
297 false /* create */, NULL)); | |
298 } | |
299 } | |
300 | |
301 TEST_F(FileSystemPathManagerTest, GetRootPathInIncognito) { | |
302 scoped_ptr<FileSystemPathManager> manager(NewPathManager( | |
303 true /* incognito */, false)); | |
304 | |
305 // Try to get a root directory. | |
306 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | |
307 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " | |
308 << kRootPathTestCases[i].expected_path); | |
309 EXPECT_FALSE(GetRootPath(manager.get(), | |
310 GURL(kRootPathTestCases[i].origin_url), | |
311 kRootPathTestCases[i].type, | |
312 true /* create */, NULL)); | |
313 } | |
314 } | |
315 | |
316 TEST_F(FileSystemPathManagerTest, GetRootPathFileURI) { | |
317 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
318 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | |
319 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" | |
320 << i << " " << kRootPathFileURITestCases[i].expected_path); | |
321 EXPECT_FALSE(GetRootPath(manager.get(), | |
322 GURL(kRootPathFileURITestCases[i].origin_url), | |
323 kRootPathFileURITestCases[i].type, | |
324 true /* create */, NULL)); | |
325 } | |
326 } | |
327 | |
328 TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) { | |
329 scoped_ptr<FileSystemPathManager> manager(NewPathManager( | |
330 false, true /* allow_file_access_from_files */)); | |
331 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | |
332 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" | |
333 << i << " " << kRootPathFileURITestCases[i].expected_path); | |
334 FilePath root_path; | |
335 EXPECT_TRUE(GetRootPath(manager.get(), | |
336 GURL(kRootPathFileURITestCases[i].origin_url), | |
337 kRootPathFileURITestCases[i].type, | |
338 true /* create */, &root_path)); | |
339 FilePath expected = file_system_path().AppendASCII( | |
340 kRootPathFileURITestCases[i].expected_path); | |
341 EXPECT_EQ(expected.value(), root_path.DirName().value()); | |
342 EXPECT_TRUE(file_util::DirectoryExists(root_path)); | |
343 } | |
344 } | |
345 | |
346 TEST_F(FileSystemPathManagerTest, VirtualPathFromFileSystemPathTest) { | |
347 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
348 FilePath root_path; | |
349 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | |
350 fileapi::kFileSystemTypeTemporary, | |
351 true /* create */, &root_path)); | |
352 | |
353 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPathToVirtualPathTestCases); ++i) { | |
354 SCOPED_TRACE(testing::Message() << "PathToVirtualPath #" | |
355 << i << " " << kPathToVirtualPathTestCases[i]); | |
356 FilePath absolute_path = root_path.AppendASCII( | |
357 kPathToVirtualPathTestCases[i]); | |
358 FilePath virtual_path; | |
359 EXPECT_TRUE(manager->CrackFileSystemPath(absolute_path, NULL, NULL, | |
360 &virtual_path)); | |
361 | |
362 FilePath test_case_path; | |
363 test_case_path = test_case_path.AppendASCII( | |
364 kPathToVirtualPathTestCases[i]); | |
365 EXPECT_EQ(test_case_path.value(), virtual_path.value()); | |
366 } | |
367 } | |
368 | |
369 TEST_F(FileSystemPathManagerTest, TypeFromFileSystemPathTest) { | |
370 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
371 | |
372 FilePath root_path; | |
373 fileapi::FileSystemType type; | |
374 | |
375 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | |
376 fileapi::kFileSystemTypeTemporary, | |
377 true /* create */, &root_path)); | |
378 FilePath path = root_path.AppendASCII("test"); | |
379 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | |
380 EXPECT_EQ(fileapi::kFileSystemTypeTemporary, type); | |
381 | |
382 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | |
383 fileapi::kFileSystemTypePersistent, | |
384 true /* create */, &root_path)); | |
385 path = root_path.AppendASCII("test"); | |
386 EXPECT_TRUE(manager->CrackFileSystemPath(path, NULL, &type, NULL)); | |
387 EXPECT_EQ(fileapi::kFileSystemTypePersistent, type); | |
388 } | |
389 | |
390 TEST_F(FileSystemPathManagerTest, CheckValidPath) { | |
391 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); | |
392 FilePath root_path; | |
393 EXPECT_TRUE(GetRootPath(manager.get(), GURL("http://foo.com/"), | |
394 kFileSystemTypePersistent, true, &root_path)); | |
395 | |
396 // The root path must be valid, but upper directories or directories | |
397 // that are not in our temporary or persistent directory must be | |
398 // evaluated invalid. | |
399 EXPECT_TRUE(CheckValidFileSystemPath(manager.get(), root_path)); | |
400 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), root_path.DirName())); | |
401 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), | |
402 root_path.DirName().DirName())); | |
403 EXPECT_FALSE(CheckValidFileSystemPath(manager.get(), | |
404 root_path.DirName().DirName() | |
405 .AppendASCII("ArbitraryName") | |
406 .AppendASCII("chrome-dummy"))); | |
407 | |
408 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kCheckValidPathTestCases); ++i) { | |
409 SCOPED_TRACE(testing::Message() << "CheckValidPath #" << i << " " | |
410 << kCheckValidPathTestCases[i].path); | |
411 FilePath path(kCheckValidPathTestCases[i].path); | |
412 if (!path.IsAbsolute()) | |
413 path = root_path.Append(path); | |
414 EXPECT_EQ(kCheckValidPathTestCases[i].expected_valid, | |
415 CheckValidFileSystemPath(manager.get(), path)); | |
416 } | |
417 } | |
418 | |
419 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { | |
420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { | |
421 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " | |
422 << kIsRestrictedNameTestCases[i].name); | |
423 FilePath name(kIsRestrictedNameTestCases[i].name); | |
424 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, | |
425 FileSystemPathManager::IsRestrictedFileName(name)); | |
426 } | |
427 } | |
428 | |
429 class FileSystemPathManagerOriginEnumeratorTest : public testing::Test { | |
430 public: | 26 public: |
431 void SetUp() { | 27 void SetUp() { |
432 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 28 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
433 enumerator_.reset(new FileSystemPathManager::OriginEnumerator( | 29 enumerator_.reset(new SandboxMountPointProvider::OriginEnumerator( |
434 data_dir_.path())); | 30 data_dir_.path())); |
435 } | 31 } |
436 | 32 |
437 FileSystemPathManager::OriginEnumerator* enumerator() const { | 33 SandboxMountPointProvider::OriginEnumerator* enumerator() const { |
438 return enumerator_.get(); | 34 return enumerator_.get(); |
439 } | 35 } |
440 | 36 |
441 protected: | 37 protected: |
442 void CreateOriginTypeDirectory(const std::string& origin_identifier, | 38 void CreateOriginTypeDirectory(const std::string& origin_identifier, |
443 fileapi::FileSystemType type) { | 39 fileapi::FileSystemType type) { |
444 std::string type_string = | 40 std::string type_string = |
445 FileSystemPathManager::GetFileSystemTypeString(type); | 41 FileSystemPathManager::GetFileSystemTypeString(type); |
446 ASSERT_TRUE(!type_string.empty()); | 42 ASSERT_TRUE(!type_string.empty()); |
447 FilePath target = data_dir_.path().AppendASCII(origin_identifier) | 43 FilePath target = data_dir_.path().AppendASCII(origin_identifier) |
448 .AppendASCII(type_string); | 44 .AppendASCII(type_string); |
449 file_util::CreateDirectory(target); | 45 file_util::CreateDirectory(target); |
450 ASSERT_TRUE(file_util::DirectoryExists(target)); | 46 ASSERT_TRUE(file_util::DirectoryExists(target)); |
451 } | 47 } |
452 | 48 |
453 ScopedTempDir data_dir_; | 49 ScopedTempDir data_dir_; |
454 scoped_ptr<FileSystemPathManager::OriginEnumerator> enumerator_; | 50 scoped_ptr<SandboxMountPointProvider::OriginEnumerator> enumerator_; |
455 }; | 51 }; |
456 | 52 |
457 TEST_F(FileSystemPathManagerOriginEnumeratorTest, Empty) { | 53 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, Empty) { |
458 ASSERT_TRUE(enumerator()->Next().empty()); | 54 ASSERT_TRUE(enumerator()->Next().empty()); |
459 } | 55 } |
460 | 56 |
461 TEST_F(FileSystemPathManagerOriginEnumeratorTest, EnumerateOrigins) { | 57 TEST_F(SandboxMountPointProviderOriginEnumeratorTest, EnumerateOrigins) { |
462 const char* temporary_origins[] = { | 58 const char* temporary_origins[] = { |
463 "http_www.bar.com_0", | 59 "http_www.bar.com_0", |
464 "http_www.foo.com_0", | 60 "http_www.foo.com_0", |
465 "http_www.foo.com_80", | 61 "http_www.foo.com_80", |
466 "http_www.example.com_8080", | 62 "http_www.example.com_8080", |
467 "http_www.google.com_80", | 63 "http_www.google.com_80", |
468 }; | 64 }; |
469 const char* persistent_origins[] = { | 65 const char* persistent_origins[] = { |
470 "http_www.bar.com_0", | 66 "http_www.bar.com_0", |
471 "http_www.foo.com_8080", | 67 "http_www.foo.com_8080", |
(...skipping 23 matching lines...) Expand all Loading... |
495 } | 91 } |
496 if (enumerator()->HasPersistent()) { | 92 if (enumerator()->HasPersistent()) { |
497 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); | 93 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); |
498 ++persistent_actual_size; | 94 ++persistent_actual_size; |
499 } | 95 } |
500 } | 96 } |
501 | 97 |
502 ASSERT_EQ(temporary_size, temporary_actual_size); | 98 ASSERT_EQ(temporary_size, temporary_actual_size); |
503 ASSERT_EQ(persistent_size, persistent_actual_size); | 99 ASSERT_EQ(persistent_size, persistent_actual_size); |
504 } | 100 } |
OLD | NEW |