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

Side by Side Diff: webkit/chromeos/fileapi/cros_mount_point_provider_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/chromeos/fileapi/cros_mount_point_provider.h" 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop.h"
12 #include "base/stringprintf.h"
10 #include "chromeos/dbus/cros_disks_client.h" 13 #include "chromeos/dbus/cros_disks_client.h"
11 #include "googleurl/src/url_util.h" 14 #include "googleurl/src/url_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webkit/fileapi/external_mount_points.h" 16 #include "webkit/fileapi/external_mount_points.h"
14 #include "webkit/fileapi/file_permission_policy.h" 17 #include "webkit/fileapi/file_permission_policy.h"
18 #include "webkit/fileapi/file_system_context.h"
19 #include "webkit/fileapi/file_system_mount_point_provider.h"
20 #include "webkit/fileapi/file_system_task_runners.h"
15 #include "webkit/fileapi/file_system_url.h" 21 #include "webkit/fileapi/file_system_url.h"
16 #include "webkit/fileapi/isolated_context.h" 22 #include "webkit/fileapi/isolated_context.h"
23 #include "webkit/fileapi/mock_file_system_options.h"
17 #include "webkit/quota/mock_special_storage_policy.h" 24 #include "webkit/quota/mock_special_storage_policy.h"
18 25
19 #define FPL(x) FILE_PATH_LITERAL(x) 26 #define FPL(x) FILE_PATH_LITERAL(x)
20 27
28 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
29 #define DRIVE FPL("C:")
30 #else
31 #define DRIVE
32 #endif
33
21 using fileapi::ExternalMountPoints; 34 using fileapi::ExternalMountPoints;
22 using fileapi::FileSystemURL; 35 using fileapi::FileSystemURL;
36 using fileapi::FileSystemContext;
23 37
24 namespace { 38 namespace {
25 39
26 FileSystemURL CreateFileSystemURL(const std::string& extension, 40 FileSystemURL CreateFileSystemURL(const std::string& extension,
27 const char* path, 41 const char* path,
28 ExternalMountPoints* mount_points) { 42 ExternalMountPoints* mount_points) {
29 return mount_points->CreateCrackedFileSystemURL( 43 return mount_points->CreateCrackedFileSystemURL(
30 GURL("chrome-extension://" + extension + "/"), 44 GURL("chrome-extension://" + extension + "/"),
31 fileapi::kFileSystemTypeExternal, 45 fileapi::kFileSystemTypeExternal,
32 base::FilePath::FromUTF8Unsafe(path)); 46 base::FilePath::FromUTF8Unsafe(path));
33 } 47 }
34 48
49 GURL CreateRawFileSystemURL(const std::string& type_str,
50 const std::string& fs_id) {
51 std::string url_str = base::StringPrintf(
52 "filesystem:http://chromium.org/%s/%s/root/file",
53 type_str.c_str(),
54 fs_id.c_str());
55 return GURL(url_str);
56 }
57
58 fileapi::FileSystemContext* CreateFileSystemContextForTest(
59 ExternalMountPoints* external_mount_points) {
60 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers;
61 additional_providers.push_back(
62 new chromeos::CrosMountPointProvider(
63 make_scoped_refptr(new quota::MockSpecialStoragePolicy()),
64 external_mount_points,
65 ExternalMountPoints::GetSystemInstance()));
66 std::vector<fileapi::MountPoints*> additional_mount_points;
67 additional_mount_points.push_back(external_mount_points);
68 return new fileapi::FileSystemContext(
69 fileapi::FileSystemTaskRunners::CreateMockTaskRunners(),
70 NULL,
71 additional_providers.Pass(),
72 additional_mount_points,
73 base::FilePath(FILE_PATH_LITERAL("dummy")),
74 fileapi::CreateAllowFileAccessOptions());
75 }
76
77 void ExpectFileSystemURLMatches(const fileapi::FileSystemURL& url,
78 const GURL& expect_origin,
79 fileapi::FileSystemType expect_mount_type,
80 fileapi::FileSystemType expect_type,
81 const base::FilePath& expect_path,
82 const base::FilePath& expect_virtual_path,
83 const std::string& expect_filesystem_id) {
84 EXPECT_TRUE(url.is_valid());
85
86 EXPECT_EQ(expect_origin, url.origin());
87 EXPECT_EQ(expect_mount_type, url.mount_type());
88 EXPECT_EQ(expect_type, url.type());
89 EXPECT_EQ(expect_path, url.path());
90 EXPECT_EQ(expect_virtual_path, url.virtual_path());
91 EXPECT_EQ(expect_filesystem_id, url.filesystem_id());
92 }
93
35 TEST(CrosMountPointProviderTest, DefaultMountPoints) { 94 TEST(CrosMountPointProviderTest, DefaultMountPoints) {
36 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 95 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
37 new quota::MockSpecialStoragePolicy(); 96 new quota::MockSpecialStoragePolicy();
38 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 97 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
39 fileapi::ExternalMountPoints::CreateRefCounted()); 98 fileapi::ExternalMountPoints::CreateRefCounted());
40 chromeos::CrosMountPointProvider provider( 99 chromeos::CrosMountPointProvider provider(
41 storage_policy, 100 storage_policy,
42 mount_points.get(), 101 mount_points.get(),
43 fileapi::ExternalMountPoints::GetSystemInstance()); 102 fileapi::ExternalMountPoints::GetSystemInstance());
44 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories(); 103 std::vector<base::FilePath> root_dirs = provider.GetRootDirectories();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // fails. 351 // fails.
293 if (!kTestCases[i].success) 352 if (!kTestCases[i].success)
294 continue; 353 continue;
295 354
296 base::FilePath expected_virtual_path(kTestCases[i].virtual_path); 355 base::FilePath expected_virtual_path(kTestCases[i].virtual_path);
297 EXPECT_EQ(expected_virtual_path, virtual_path) 356 EXPECT_EQ(expected_virtual_path, virtual_path)
298 << "Resolving " << kTestCases[i].local_path; 357 << "Resolving " << kTestCases[i].local_path;
299 } 358 }
300 } 359 }
301 360
361 TEST(CrosMountPointProvider, CrosMountPonitProviderKeepsMountPointsAlive) {
tzik 2013/04/17 12:06:04 s/Ponit/Point/
kinuko 2013/04/17 14:27:29 Removed these CrOS changes from this patch.
362 scoped_refptr<ExternalMountPoints> mount_points =
363 ExternalMountPoints::CreateRefCounted();
364
365 // Register system external mount point.
366 ASSERT_TRUE(mount_points->RegisterFileSystem(
367 "system",
368 fileapi::kFileSystemTypeNativeLocal,
369 base::FilePath(DRIVE FPL("/test/sys/"))));
370
371 base::MessageLoop message_loop;
372 scoped_refptr<fileapi::FileSystemContext> file_system_context(
373 CreateFileSystemContextForTest(mount_points.get()));
374
375 // Release a MountPoints reference created in the test.
376 mount_points = NULL;
377
378 // CrosMountPointProvider should keep a reference to the |mount_points|, so it
379 // should be able to resolve the URL.
380 FileSystemURL cracked_external = file_system_context->CrackURL(
381 CreateRawFileSystemURL("external", "system"));
382
383 const char kTestOrigin[] = "http://chromium.org/";
384 ExpectFileSystemURLMatches(
385 cracked_external,
386 GURL(kTestOrigin),
387 fileapi::kFileSystemTypeExternal,
388 fileapi::kFileSystemTypeNativeLocal,
389 base::FilePath(
390 DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(),
391 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(),
392 "system");
393
394 file_system_context = NULL;
395 message_loop.RunUntilIdle();
396
397 // No need to revoke the registered filesystem since |mount_points| lifetime
398 // is bound to this test.
399 }
400
302 } // namespace 401 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698