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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/mount_path_util_unittest.cc

Issue 294073007: [fsp] Let extensions decide about the file system id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h" 9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h"
10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
(...skipping 12 matching lines...) Expand all
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "webkit/browser/fileapi/external_mount_points.h" 24 #include "webkit/browser/fileapi/external_mount_points.h"
25 25
26 namespace chromeos { 26 namespace chromeos {
27 namespace file_system_provider { 27 namespace file_system_provider {
28 namespace util { 28 namespace util {
29 29
30 namespace { 30 namespace {
31 31
32 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; 32 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
33 const char kFileSystemId[] = "File/System/Id";
33 const char kFileSystemName[] = "Camera Pictures"; 34 const char kFileSystemName[] = "Camera Pictures";
34 35
35 // Creates a FileSystemURL for tests. 36 // Creates a FileSystemURL for tests.
36 fileapi::FileSystemURL CreateFileSystemURL(Profile* profile, 37 fileapi::FileSystemURL CreateFileSystemURL(
37 const std::string& extension_id, 38 Profile* profile,
38 int file_system_id, 39 const ProvidedFileSystemInfo& file_system_info,
39 const base::FilePath& file_path) { 40 const base::FilePath& file_path) {
40 const std::string origin = std::string("chrome-extension://") + kExtensionId; 41 const std::string origin =
41 const base::FilePath mount_path = 42 std::string("chrome-extension://") + file_system_info.extension_id();
42 util::GetMountPath(profile, extension_id, file_system_id); 43 const base::FilePath mount_path = file_system_info.mount_path();
43 const fileapi::ExternalMountPoints* const mount_points = 44 const fileapi::ExternalMountPoints* const mount_points =
44 fileapi::ExternalMountPoints::GetSystemInstance(); 45 fileapi::ExternalMountPoints::GetSystemInstance();
45 DCHECK(mount_points); 46 DCHECK(mount_points);
46 DCHECK(file_path.IsAbsolute()); 47 DCHECK(file_path.IsAbsolute());
47 base::FilePath relative_path(file_path.value().substr(1)); 48 base::FilePath relative_path(file_path.value().substr(1));
48 return mount_points->CreateCrackedFileSystemURL( 49 return mount_points->CreateCrackedFileSystemURL(
49 GURL(origin), 50 GURL(origin),
50 fileapi::kFileSystemTypeExternal, 51 fileapi::kFileSystemTypeExternal,
51 base::FilePath(mount_path.BaseName().Append(relative_path))); 52 base::FilePath(mount_path.BaseName().Append(relative_path)));
52 } 53 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 88
88 content::TestBrowserThreadBundle thread_bundle_; 89 content::TestBrowserThreadBundle thread_bundle_;
89 scoped_ptr<TestingProfileManager> profile_manager_; 90 scoped_ptr<TestingProfileManager> profile_manager_;
90 TestingProfile* profile_; // Owned by TestingProfileManager. 91 TestingProfile* profile_; // Owned by TestingProfileManager.
91 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; 92 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
92 FakeUserManager* user_manager_; 93 FakeUserManager* user_manager_;
93 Service* file_system_provider_service_; // Owned by its factory. 94 Service* file_system_provider_service_; // Owned by its factory.
94 }; 95 };
95 96
96 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) { 97 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) {
97 const std::string kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj";
98 const int kFileSystemId = 1;
99
100 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId); 98 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId);
101 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash", 99 const std::string expected =
102 result.AsUTF8Unsafe()); 100 "/provided/mbflcebpggnecokmikipoihdbecnjfoj:"
101 "File%2FSystem%2FId:testing-profile-hash";
102 EXPECT_EQ(expected, result.AsUTF8Unsafe());
103 } 103 }
104 104
105 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { 105 TEST_F(FileSystemProviderMountPathUtilTest, Parser) {
106 const int file_system_id = file_system_provider_service_->MountFileSystem( 106 const bool result = file_system_provider_service_->MountFileSystem(
107 kExtensionId, kFileSystemName); 107 kExtensionId, kFileSystemId, kFileSystemName);
108 EXPECT_LT(0, file_system_id); 108 ASSERT_TRUE(result);
109 const ProvidedFileSystemInfo file_system_info =
110 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
111 kFileSystemId)
112 ->GetFileSystemInfo();
109 113
110 const base::FilePath kFilePath = 114 const base::FilePath kFilePath =
111 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); 115 base::FilePath::FromUTF8Unsafe("/hello/world.txt");
112 const fileapi::FileSystemURL url = 116 const fileapi::FileSystemURL url =
113 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); 117 CreateFileSystemURL(profile_, file_system_info, kFilePath);
114 EXPECT_TRUE(url.is_valid()); 118 EXPECT_TRUE(url.is_valid());
115 119
116 FileSystemURLParser parser(url); 120 FileSystemURLParser parser(url);
117 EXPECT_TRUE(parser.Parse()); 121 EXPECT_TRUE(parser.Parse());
118 122
119 ProvidedFileSystemInterface* file_system = parser.file_system(); 123 ProvidedFileSystemInterface* file_system = parser.file_system();
120 ASSERT_TRUE(file_system); 124 ASSERT_TRUE(file_system);
121 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); 125 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
122 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 126 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
123 } 127 }
124 128
125 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { 129 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) {
126 const int file_system_id = file_system_provider_service_->MountFileSystem( 130 const bool result = file_system_provider_service_->MountFileSystem(
127 kExtensionId, kFileSystemName); 131 kExtensionId, kFileSystemId, kFileSystemName);
128 EXPECT_LT(0, file_system_id); 132 ASSERT_TRUE(result);
133 const ProvidedFileSystemInfo file_system_info =
134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId,
135 kFileSystemId)
136 ->GetFileSystemInfo();
129 137
130 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); 138 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/");
131 const fileapi::FileSystemURL url = 139 const fileapi::FileSystemURL url =
132 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); 140 CreateFileSystemURL(profile_, file_system_info, kFilePath);
133 EXPECT_TRUE(url.is_valid()); 141 EXPECT_TRUE(url.is_valid());
134 142
135 FileSystemURLParser parser(url); 143 FileSystemURLParser parser(url);
136 EXPECT_TRUE(parser.Parse()); 144 EXPECT_TRUE(parser.Parse());
137 145
138 ProvidedFileSystemInterface* file_system = parser.file_system(); 146 ProvidedFileSystemInterface* file_system = parser.file_system();
139 ASSERT_TRUE(file_system); 147 ASSERT_TRUE(file_system);
140 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); 148 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id());
141 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); 149 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe());
142 } 150 }
143 151
144 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { 152 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) {
145 const int file_system_id = file_system_provider_service_->MountFileSystem( 153 const ProvidedFileSystemInfo file_system_info(
146 kExtensionId, kFileSystemName); 154 kExtensionId,
147 EXPECT_LT(0, file_system_id); 155 kFileSystemId,
156 kFileSystemName,
157 GetMountPath(profile_, kExtensionId, kFileSystemId));
148 158
149 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); 159 const base::FilePath file_path = base::FilePath::FromUTF8Unsafe("/hello");
150 const fileapi::FileSystemURL url = CreateFileSystemURL( 160 const fileapi::FileSystemURL url =
151 profile_, kExtensionId, file_system_id + 1, kFilePath); 161 CreateFileSystemURL(profile_, file_system_info, file_path);
152 // It is impossible to create a cracked URL for a mount point which doesn't 162 // It is impossible to create a cracked URL for a mount point which doesn't
153 // exist, therefore is will always be invalid, and empty. 163 // exist, therefore is will always be invalid, and empty.
154 EXPECT_FALSE(url.is_valid()); 164 EXPECT_FALSE(url.is_valid());
155 165
156 FileSystemURLParser parser(url); 166 FileSystemURLParser parser(url);
157 EXPECT_FALSE(parser.Parse()); 167 EXPECT_FALSE(parser.Parse());
158 } 168 }
159 169
160 } // namespace util 170 } // namespace util
161 } // namespace file_system_provider 171 } // namespace file_system_provider
162 } // namespace chromeos 172 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698