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

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

Issue 6864040: Fixed file/directory url resolution for external mount point provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_system_path_manager.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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 { fileapi::kFileSystemTypePersistent, "http://bar.com/", 52 { fileapi::kFileSystemTypePersistent, "http://bar.com/",
53 "http_bar.com_0" PS "Persistent" }, 53 "http_bar.com_0" PS "Persistent" },
54 { fileapi::kFileSystemTypeTemporary, "https://foo:2/", 54 { fileapi::kFileSystemTypeTemporary, "https://foo:2/",
55 "https_foo_2" PS "Temporary" }, 55 "https_foo_2" PS "Temporary" },
56 { fileapi::kFileSystemTypePersistent, "https://foo:2/", 56 { fileapi::kFileSystemTypePersistent, "https://foo:2/",
57 "https_foo_2" PS "Persistent" }, 57 "https_foo_2" PS "Persistent" },
58 { fileapi::kFileSystemTypeTemporary, "https://bar.com/", 58 { fileapi::kFileSystemTypeTemporary, "https://bar.com/",
59 "https_bar.com_0" PS "Temporary" }, 59 "https_bar.com_0" PS "Temporary" },
60 { fileapi::kFileSystemTypePersistent, "https://bar.com/", 60 { fileapi::kFileSystemTypePersistent, "https://bar.com/",
61 "https_bar.com_0" PS "Persistent" }, 61 "https_bar.com_0" PS "Persistent" },
62 #if defined(OS_CHROMEOS)
63 { fileapi::kFileSystemTypeExternal, "chrome-extension://foo/",
ericu 2011/04/18 20:35:56 Fix indent.
64 "chrome-extension__0" PS "External" },
65 #endif
62 }; 66 };
63 67
64 const struct RootPathFileURITest { 68 const struct RootPathFileURITest {
65 fileapi::FileSystemType type; 69 fileapi::FileSystemType type;
66 const char* origin_url; 70 const char* origin_url;
67 const char* expected_path; 71 const char* expected_path;
72 const char* virtual_path;
68 } kRootPathFileURITestCases[] = { 73 } kRootPathFileURITestCases[] = {
69 { fileapi::kFileSystemTypeTemporary, "file:///", 74 { fileapi::kFileSystemTypeTemporary, "file:///",
70 "file__0" PS "Temporary" }, 75 "file__0" PS "Temporary", NULL },
71 { fileapi::kFileSystemTypePersistent, "file:///", 76 { fileapi::kFileSystemTypePersistent, "file:///",
72 "file__0" PS "Persistent" }, 77 "file__0" PS "Persistent", NULL },
73 // TODO(zelidrag): Add fileapi::kFileSystemTypeLocal test cases here once 78 #if defined(OS_CHROMEOS)
74 // we fix ChromeOS build of this test. 79 { fileapi::kFileSystemTypeExternal, "chrome-extension://foo/",
80 "chrome-extension__0" PS "External", "tmp/test.txt" },
81 #endif
75 }; 82 };
76 83
77 const struct CheckValidPathTest { 84 const struct CheckValidPathTest {
78 FilePath::StringType path; 85 FilePath::StringType path;
79 bool expected_valid; 86 bool expected_valid;
80 } kCheckValidPathTestCases[] = { 87 } kCheckValidPathTestCases[] = {
81 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, }, 88 { FILE_PATH_LITERAL("//tmp/foo.txt"), false, },
82 { FILE_PATH_LITERAL("//etc/hosts"), false, }, 89 { FILE_PATH_LITERAL("//etc/hosts"), false, },
83 { FILE_PATH_LITERAL("foo.txt"), true, }, 90 { FILE_PATH_LITERAL("foo.txt"), true, },
84 { FILE_PATH_LITERAL("a/b/c"), true, }, 91 { FILE_PATH_LITERAL("a/b/c"), true, },
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 197 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
191 root_path_callback_status_ = false; 198 root_path_callback_status_ = false;
192 root_path_.clear(); 199 root_path_.clear();
193 file_system_name_.clear(); 200 file_system_name_.clear();
194 } 201 }
195 202
196 protected: 203 protected:
197 FileSystemPathManager* NewPathManager( 204 FileSystemPathManager* NewPathManager(
198 bool incognito, 205 bool incognito,
199 bool allow_file_access) { 206 bool allow_file_access) {
200 return new FileSystemPathManager( 207 FileSystemPathManager* manager = new FileSystemPathManager(
201 base::MessageLoopProxy::CreateForCurrentThread(), 208 base::MessageLoopProxy::CreateForCurrentThread(),
202 data_dir_.path(), 209 data_dir_.path(),
203 scoped_refptr<quota::SpecialStoragePolicy>( 210 scoped_refptr<quota::SpecialStoragePolicy>(
204 new TestSpecialStoragePolicy()), 211 new TestSpecialStoragePolicy()),
205 incognito, 212 incognito,
206 allow_file_access); 213 allow_file_access);
214 #if defined(OS_CHROMEOS)
215 fileapi::ExternalFileSystemMountPointProvider* ext_provider =
216 manager->external_provider();
217 ext_provider->AddMountPoint(FilePath("/tmp"));
218 #endif
219 return manager;
207 } 220 }
208 221
209 void OnGetRootPath(bool success, 222 void OnGetRootPath(bool success,
210 const FilePath& root_path, 223 const FilePath& root_path,
211 const std::string& name) { 224 const std::string& name) {
212 root_path_callback_status_ = success; 225 root_path_callback_status_ = success;
213 root_path_ = root_path; 226 root_path_ = root_path;
214 file_system_name_ = name; 227 file_system_name_ = name;
215 } 228 }
216 229
217 bool GetRootPath(FileSystemPathManager* manager, 230 bool GetRootPath(FileSystemPathManager* manager,
218 const GURL& origin_url, 231 const GURL& origin_url,
219 fileapi::FileSystemType type, 232 fileapi::FileSystemType type,
220 bool create, 233 bool create,
234 bool is_file_system,
235 const FilePath& virtual_path,
221 FilePath* root_path) { 236 FilePath* root_path) {
222 manager->GetFileSystemRootPath(origin_url, type, create, 237 manager->GetFileSystemRootPath(origin_url, type, create, is_file_system,
223 callback_factory_.NewCallback( 238 virtual_path, callback_factory_.NewCallback(
224 &FileSystemPathManagerTest::OnGetRootPath)); 239 &FileSystemPathManagerTest::OnGetRootPath));
225 MessageLoop::current()->RunAllPending(); 240 MessageLoop::current()->RunAllPending();
226 if (root_path) 241 if (root_path)
227 *root_path = root_path_; 242 *root_path = root_path_;
228 return root_path_callback_status_; 243 return root_path_callback_status_;
229 } 244 }
230 245
231 FilePath data_path() { return data_dir_.path(); } 246 FilePath data_path() { return data_dir_.path(); }
232 FilePath file_system_path() { 247 FilePath file_system_path() {
233 return data_dir_.path().Append( 248 return data_dir_.path().Append(
234 SandboxMountPointProvider::kFileSystemDirectory); 249 SandboxMountPointProvider::kFileSystemDirectory);
235 } 250 }
251 FilePath external_file_system_path() {
252 return FilePath(fileapi::kExternalDir);
253 }
236 254
237 private: 255 private:
238 ScopedTempDir data_dir_; 256 ScopedTempDir data_dir_;
239 base::ScopedCallbackFactory<FileSystemPathManagerTest> callback_factory_; 257 base::ScopedCallbackFactory<FileSystemPathManagerTest> callback_factory_;
240 258
241 bool root_path_callback_status_; 259 bool root_path_callback_status_;
242 FilePath root_path_; 260 FilePath root_path_;
243 std::string file_system_name_; 261 std::string file_system_name_;
244 262
245 DISALLOW_COPY_AND_ASSIGN(FileSystemPathManagerTest); 263 DISALLOW_COPY_AND_ASSIGN(FileSystemPathManagerTest);
246 }; 264 };
247 265
248 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) { 266 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamine) {
249 std::vector<FilePath> returned_root_path( 267 std::vector<FilePath> returned_root_path(
250 ARRAYSIZE_UNSAFE(kRootPathTestCases)); 268 ARRAYSIZE_UNSAFE(kRootPathTestCases));
251 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 269 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
252 270
253 // Create a new root directory. 271 // Create a new root directory.
254 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { 272 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
255 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " 273 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " "
256 << kRootPathTestCases[i].expected_path); 274 << kRootPathTestCases[i].expected_path);
257 275
258 FilePath root_path; 276 FilePath root_path;
259 EXPECT_TRUE(GetRootPath(manager.get(), 277 EXPECT_TRUE(GetRootPath(manager.get(),
260 GURL(kRootPathTestCases[i].origin_url), 278 GURL(kRootPathTestCases[i].origin_url),
261 kRootPathTestCases[i].type, 279 kRootPathTestCases[i].type,
262 true /* create */, &root_path)); 280 true /* create */, true /* is_file_system */,
281 FilePath(),
282 &root_path));
263 283
264 FilePath expected = file_system_path().AppendASCII( 284 if (kRootPathTestCases[i].type != fileapi::kFileSystemTypeExternal) {
265 kRootPathTestCases[i].expected_path); 285 FilePath expected = file_system_path().AppendASCII(
266 EXPECT_EQ(expected.value(), root_path.DirName().value()); 286 kRootPathTestCases[i].expected_path);
267 EXPECT_TRUE(file_util::DirectoryExists(root_path)); 287 EXPECT_EQ(expected.value(), root_path.DirName().value());
288 EXPECT_TRUE(file_util::DirectoryExists(root_path));
289 } else {
290 // External file system root path is virtual one and does not match
291 // anything from the actual file system.
292 EXPECT_EQ(external_file_system_path().value(),
293 root_path.value());
294 }
268 ASSERT_TRUE(returned_root_path.size() > i); 295 ASSERT_TRUE(returned_root_path.size() > i);
269 returned_root_path[i] = root_path; 296 returned_root_path[i] = root_path;
270 } 297 }
271 298
272 // Get the root directory with create=false and see if we get the 299 // Get the root directory with create=false and see if we get the
273 // same directory. 300 // same directory.
274 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { 301 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
275 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " 302 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " "
276 << kRootPathTestCases[i].expected_path); 303 << kRootPathTestCases[i].expected_path);
277 304
278 FilePath root_path; 305 FilePath root_path;
279 EXPECT_TRUE(GetRootPath(manager.get(), 306 EXPECT_TRUE(GetRootPath(manager.get(),
280 GURL(kRootPathTestCases[i].origin_url), 307 GURL(kRootPathTestCases[i].origin_url),
281 kRootPathTestCases[i].type, 308 kRootPathTestCases[i].type,
282 false /* create */, &root_path)); 309 false /* create */, true /* is_file_system */,
310 FilePath(), &root_path));
283 ASSERT_TRUE(returned_root_path.size() > i); 311 ASSERT_TRUE(returned_root_path.size() > i);
284 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); 312 EXPECT_EQ(returned_root_path[i].value(), root_path.value());
285 } 313 }
286 } 314 }
287 315
288 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamineWithNewManager) { 316 TEST_F(FileSystemPathManagerTest, GetRootPathCreateAndExamineWithNewManager) {
289 std::vector<FilePath> returned_root_path( 317 std::vector<FilePath> returned_root_path(
290 ARRAYSIZE_UNSAFE(kRootPathTestCases)); 318 ARRAYSIZE_UNSAFE(kRootPathTestCases));
291 scoped_ptr<FileSystemPathManager> manager1(NewPathManager(false, false)); 319 scoped_ptr<FileSystemPathManager> manager1(NewPathManager(false, false));
292 scoped_ptr<FileSystemPathManager> manager2(NewPathManager(false, false)); 320 scoped_ptr<FileSystemPathManager> manager2(NewPathManager(false, false));
293 321
294 GURL origin_url("http://foo.com:1/"); 322 GURL origin_url("http://foo.com:1/");
295 323
296 FilePath root_path1; 324 FilePath root_path1;
297 EXPECT_TRUE(GetRootPath(manager1.get(), origin_url, 325 EXPECT_TRUE(GetRootPath(manager1.get(), origin_url,
298 kFileSystemTypeTemporary, true, &root_path1)); 326 kFileSystemTypeTemporary, true, false, FilePath(),
327 &root_path1));
299 FilePath root_path2; 328 FilePath root_path2;
300 EXPECT_TRUE(GetRootPath(manager2.get(), origin_url, 329 EXPECT_TRUE(GetRootPath(manager2.get(), origin_url,
301 kFileSystemTypeTemporary, false, &root_path2)); 330 kFileSystemTypeTemporary, false, false, FilePath(),
331 &root_path2));
302 332
303 EXPECT_EQ(root_path1.value(), root_path2.value()); 333 EXPECT_EQ(root_path1.value(), root_path2.value());
304 } 334 }
305 335
306 TEST_F(FileSystemPathManagerTest, GetRootPathGetWithoutCreate) { 336 TEST_F(FileSystemPathManagerTest, GetRootPathGetWithoutCreate) {
307 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 337 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
308 338
309 // Try to get a root directory without creating. 339 // Try to get a root directory without creating.
310 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { 340 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
311 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " 341 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " "
312 << kRootPathTestCases[i].expected_path); 342 << kRootPathTestCases[i].expected_path);
313 EXPECT_FALSE(GetRootPath(manager.get(), 343 EXPECT_FALSE(GetRootPath(manager.get(),
314 GURL(kRootPathTestCases[i].origin_url), 344 GURL(kRootPathTestCases[i].origin_url),
315 kRootPathTestCases[i].type, 345 kRootPathTestCases[i].type,
316 false /* create */, NULL)); 346 false /* create */, false /* is_file_system */,
347 FilePath(), NULL));
317 } 348 }
318 } 349 }
319 350
320 TEST_F(FileSystemPathManagerTest, GetRootPathInIncognito) { 351 TEST_F(FileSystemPathManagerTest, GetRootPathInIncognito) {
321 scoped_ptr<FileSystemPathManager> manager(NewPathManager( 352 scoped_ptr<FileSystemPathManager> manager(NewPathManager(
322 true /* incognito */, false)); 353 true /* incognito */, false));
323 354
324 // Try to get a root directory. 355 // Try to get a root directory.
325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { 356 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) {
326 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " 357 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " "
327 << kRootPathTestCases[i].expected_path); 358 << kRootPathTestCases[i].expected_path);
328 EXPECT_FALSE(GetRootPath(manager.get(), 359 EXPECT_FALSE(GetRootPath(manager.get(),
329 GURL(kRootPathTestCases[i].origin_url), 360 GURL(kRootPathTestCases[i].origin_url),
330 kRootPathTestCases[i].type, 361 kRootPathTestCases[i].type,
331 true /* create */, NULL)); 362 true /* create */, false /* is_file_system */,
363 FilePath(), NULL));
332 } 364 }
333 } 365 }
334 366
335 TEST_F(FileSystemPathManagerTest, GetRootPathFileURI) { 367 TEST_F(FileSystemPathManagerTest, GetRootPathFileURI) {
336 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 368 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
337 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { 369 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) {
338 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" 370 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #"
339 << i << " " << kRootPathFileURITestCases[i].expected_path); 371 << i << " " << kRootPathFileURITestCases[i].expected_path);
340 EXPECT_FALSE(GetRootPath(manager.get(), 372 EXPECT_FALSE(GetRootPath(manager.get(),
341 GURL(kRootPathFileURITestCases[i].origin_url), 373 GURL(kRootPathFileURITestCases[i].origin_url),
342 kRootPathFileURITestCases[i].type, 374 kRootPathFileURITestCases[i].type,
343 true /* create */, NULL)); 375 true /* create */, false /* is_file_system */,
376 FilePath(), NULL));
344 } 377 }
345 } 378 }
346 379
347 TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) { 380 TEST_F(FileSystemPathManagerTest, GetRootPathFileURIWithAllowFlag) {
348 scoped_ptr<FileSystemPathManager> manager(NewPathManager( 381 scoped_ptr<FileSystemPathManager> manager(NewPathManager(
349 false, true /* allow_file_access_from_files */)); 382 false, true /* allow_file_access_from_files */));
350 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { 383 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) {
351 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" 384 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #"
352 << i << " " << kRootPathFileURITestCases[i].expected_path); 385 << i << " " << kRootPathFileURITestCases[i].expected_path);
353 FilePath root_path; 386 FilePath root_path;
354 EXPECT_TRUE(GetRootPath(manager.get(), 387 EXPECT_TRUE(GetRootPath(manager.get(),
355 GURL(kRootPathFileURITestCases[i].origin_url), 388 GURL(kRootPathFileURITestCases[i].origin_url),
356 kRootPathFileURITestCases[i].type, 389 kRootPathFileURITestCases[i].type,
357 true /* create */, &root_path)); 390 true /* create */, false /* is_file_system */,
358 FilePath expected = file_system_path().AppendASCII( 391 FilePath(kRootPathFileURITestCases[i].virtual_path),
359 kRootPathFileURITestCases[i].expected_path); 392 &root_path));
360 EXPECT_EQ(expected.value(), root_path.DirName().value()); 393 if (kRootPathFileURITestCases[i].type != fileapi::kFileSystemTypeExternal) {
394 FilePath expected = file_system_path().AppendASCII(
395 kRootPathFileURITestCases[i].expected_path);
396 EXPECT_EQ(expected.value(), root_path.DirName().value());
397 } else {
398 FilePath expected = external_file_system_path();
399 EXPECT_EQ(expected.value(), root_path.value());
400 }
361 EXPECT_TRUE(file_util::DirectoryExists(root_path)); 401 EXPECT_TRUE(file_util::DirectoryExists(root_path));
362 } 402 }
363 } 403 }
364 404
365 TEST_F(FileSystemPathManagerTest, IsRestrictedName) { 405 TEST_F(FileSystemPathManagerTest, IsRestrictedName) {
366 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false)); 406 scoped_ptr<FileSystemPathManager> manager(NewPathManager(false, false));
367 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { 407 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
368 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " 408 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
369 << kIsRestrictedNameTestCases[i].name); 409 << kIsRestrictedNameTestCases[i].name);
370 FilePath name(kIsRestrictedNameTestCases[i].name); 410 FilePath name(kIsRestrictedNameTestCases[i].name);
371 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, 411 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
372 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name)); 412 manager->IsRestrictedFileName(kFileSystemTypeTemporary, name));
373 } 413 }
374 } 414 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698