OLD | NEW |
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 "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" | 11 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
13 #include "chrome/browser/chromeos/file_system_provider/service.h" | 13 #include "chrome/browser/chromeos/file_system_provider/service.h" |
14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
15 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
23 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "webkit/browser/fileapi/external_mount_points.h" | 26 #include "storage/browser/fileapi/external_mount_points.h" |
27 #include "webkit/browser/fileapi/isolated_context.h" | 27 #include "storage/browser/fileapi/isolated_context.h" |
28 | 28 |
29 namespace chromeos { | 29 namespace chromeos { |
30 namespace file_system_provider { | 30 namespace file_system_provider { |
31 namespace util { | 31 namespace util { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 35 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
36 const char kFileSystemId[] = "File/System/Id"; | 36 const char kFileSystemId[] = "File/System/Id"; |
37 const char kDisplayName[] = "Camera Pictures"; | 37 const char kDisplayName[] = "Camera Pictures"; |
38 | 38 |
39 // Creates a FileSystemURL for tests. | 39 // Creates a FileSystemURL for tests. |
40 fileapi::FileSystemURL CreateFileSystemURL( | 40 storage::FileSystemURL CreateFileSystemURL( |
41 Profile* profile, | 41 Profile* profile, |
42 const ProvidedFileSystemInfo& file_system_info, | 42 const ProvidedFileSystemInfo& file_system_info, |
43 const base::FilePath& file_path) { | 43 const base::FilePath& file_path) { |
44 const std::string origin = | 44 const std::string origin = |
45 std::string("chrome-extension://") + file_system_info.extension_id(); | 45 std::string("chrome-extension://") + file_system_info.extension_id(); |
46 const base::FilePath mount_path = file_system_info.mount_path(); | 46 const base::FilePath mount_path = file_system_info.mount_path(); |
47 const fileapi::ExternalMountPoints* const mount_points = | 47 const storage::ExternalMountPoints* const mount_points = |
48 fileapi::ExternalMountPoints::GetSystemInstance(); | 48 storage::ExternalMountPoints::GetSystemInstance(); |
49 DCHECK(mount_points); | 49 DCHECK(mount_points); |
50 DCHECK(file_path.IsAbsolute()); | 50 DCHECK(file_path.IsAbsolute()); |
51 base::FilePath relative_path(file_path.value().substr(1)); | 51 base::FilePath relative_path(file_path.value().substr(1)); |
52 return mount_points->CreateCrackedFileSystemURL( | 52 return mount_points->CreateCrackedFileSystemURL( |
53 GURL(origin), | 53 GURL(origin), |
54 fileapi::kFileSystemTypeExternal, | 54 storage::kFileSystemTypeExternal, |
55 base::FilePath(mount_path.BaseName().Append(relative_path))); | 55 base::FilePath(mount_path.BaseName().Append(relative_path))); |
56 } | 56 } |
57 | 57 |
58 // Creates a Service instance. Used to be able to destroy the service in | 58 // Creates a Service instance. Used to be able to destroy the service in |
59 // TearDown(). | 59 // TearDown(). |
60 KeyedService* CreateService(content::BrowserContext* context) { | 60 KeyedService* CreateService(content::BrowserContext* context) { |
61 return new Service(Profile::FromBrowserContext(context), | 61 return new Service(Profile::FromBrowserContext(context), |
62 extensions::ExtensionRegistry::Get(context)); | 62 extensions::ExtensionRegistry::Get(context)); |
63 } | 63 } |
64 | 64 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const bool result = file_system_provider_service_->MountFileSystem( | 130 const bool result = file_system_provider_service_->MountFileSystem( |
131 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 131 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); |
132 ASSERT_TRUE(result); | 132 ASSERT_TRUE(result); |
133 const ProvidedFileSystemInfo file_system_info = | 133 const ProvidedFileSystemInfo file_system_info = |
134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
135 kFileSystemId) | 135 kFileSystemId) |
136 ->GetFileSystemInfo(); | 136 ->GetFileSystemInfo(); |
137 | 137 |
138 const base::FilePath kFilePath = | 138 const base::FilePath kFilePath = |
139 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 139 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
140 const fileapi::FileSystemURL url = | 140 const storage::FileSystemURL url = |
141 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 141 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
142 EXPECT_TRUE(url.is_valid()); | 142 EXPECT_TRUE(url.is_valid()); |
143 | 143 |
144 FileSystemURLParser parser(url); | 144 FileSystemURLParser parser(url); |
145 EXPECT_TRUE(parser.Parse()); | 145 EXPECT_TRUE(parser.Parse()); |
146 | 146 |
147 ProvidedFileSystemInterface* file_system = parser.file_system(); | 147 ProvidedFileSystemInterface* file_system = parser.file_system(); |
148 ASSERT_TRUE(file_system); | 148 ASSERT_TRUE(file_system); |
149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
151 } | 151 } |
152 | 152 |
153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
154 const bool result = file_system_provider_service_->MountFileSystem( | 154 const bool result = file_system_provider_service_->MountFileSystem( |
155 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 155 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); |
156 ASSERT_TRUE(result); | 156 ASSERT_TRUE(result); |
157 const ProvidedFileSystemInfo file_system_info = | 157 const ProvidedFileSystemInfo file_system_info = |
158 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 158 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
159 kFileSystemId) | 159 kFileSystemId) |
160 ->GetFileSystemInfo(); | 160 ->GetFileSystemInfo(); |
161 | 161 |
162 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 162 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
163 const fileapi::FileSystemURL url = | 163 const storage::FileSystemURL url = |
164 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 164 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
165 EXPECT_TRUE(url.is_valid()); | 165 EXPECT_TRUE(url.is_valid()); |
166 | 166 |
167 FileSystemURLParser parser(url); | 167 FileSystemURLParser parser(url); |
168 EXPECT_TRUE(parser.Parse()); | 168 EXPECT_TRUE(parser.Parse()); |
169 | 169 |
170 ProvidedFileSystemInterface* file_system = parser.file_system(); | 170 ProvidedFileSystemInterface* file_system = parser.file_system(); |
171 ASSERT_TRUE(file_system); | 171 ASSERT_TRUE(file_system); |
172 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 172 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
173 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 173 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
174 } | 174 } |
175 | 175 |
176 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 176 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
177 const ProvidedFileSystemInfo file_system_info( | 177 const ProvidedFileSystemInfo file_system_info( |
178 kExtensionId, | 178 kExtensionId, |
179 kFileSystemId, | 179 kFileSystemId, |
180 kDisplayName, | 180 kDisplayName, |
181 false /* writable */, | 181 false /* writable */, |
182 GetMountPath(profile_, kExtensionId, kFileSystemId)); | 182 GetMountPath(profile_, kExtensionId, kFileSystemId)); |
183 | 183 |
184 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); | 184 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); |
185 const fileapi::FileSystemURL url = | 185 const storage::FileSystemURL url = |
186 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 186 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
187 // It is impossible to create a cracked URL for a mount point which doesn't | 187 // It is impossible to create a cracked URL for a mount point which doesn't |
188 // exist, therefore is will always be invalid, and empty. | 188 // exist, therefore is will always be invalid, and empty. |
189 EXPECT_FALSE(url.is_valid()); | 189 EXPECT_FALSE(url.is_valid()); |
190 | 190 |
191 FileSystemURLParser parser(url); | 191 FileSystemURLParser parser(url); |
192 EXPECT_FALSE(parser.Parse()); | 192 EXPECT_FALSE(parser.Parse()); |
193 } | 193 } |
194 | 194 |
195 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { | 195 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { |
196 const bool result = file_system_provider_service_->MountFileSystem( | 196 const bool result = file_system_provider_service_->MountFileSystem( |
197 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 197 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); |
198 ASSERT_TRUE(result); | 198 ASSERT_TRUE(result); |
199 const ProvidedFileSystemInfo file_system_info = | 199 const ProvidedFileSystemInfo file_system_info = |
200 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 200 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
201 kFileSystemId) | 201 kFileSystemId) |
202 ->GetFileSystemInfo(); | 202 ->GetFileSystemInfo(); |
203 | 203 |
204 const base::FilePath kFilePath = | 204 const base::FilePath kFilePath = |
205 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 205 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
206 const fileapi::FileSystemURL url = | 206 const storage::FileSystemURL url = |
207 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 207 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
208 EXPECT_TRUE(url.is_valid()); | 208 EXPECT_TRUE(url.is_valid()); |
209 | 209 |
210 // Create an isolated URL for the original one. | 210 // Create an isolated URL for the original one. |
211 fileapi::IsolatedContext* const isolated_context = | 211 storage::IsolatedContext* const isolated_context = |
212 fileapi::IsolatedContext::GetInstance(); | 212 storage::IsolatedContext::GetInstance(); |
213 const std::string isolated_file_system_id = | 213 const std::string isolated_file_system_id = |
214 isolated_context->RegisterFileSystemForPath( | 214 isolated_context->RegisterFileSystemForPath( |
215 fileapi::kFileSystemTypeProvided, | 215 storage::kFileSystemTypeProvided, |
216 url.filesystem_id(), | 216 url.filesystem_id(), |
217 url.path(), | 217 url.path(), |
218 NULL); | 218 NULL); |
219 | 219 |
220 const base::FilePath isolated_virtual_path = | 220 const base::FilePath isolated_virtual_path = |
221 isolated_context->CreateVirtualRootPath(isolated_file_system_id) | 221 isolated_context->CreateVirtualRootPath(isolated_file_system_id) |
222 .Append(kFilePath.BaseName().value()); | 222 .Append(kFilePath.BaseName().value()); |
223 | 223 |
224 const fileapi::FileSystemURL isolated_url = | 224 const storage::FileSystemURL isolated_url = |
225 isolated_context->CreateCrackedFileSystemURL( | 225 isolated_context->CreateCrackedFileSystemURL( |
226 url.origin(), | 226 url.origin(), |
227 fileapi::kFileSystemTypeIsolated, | 227 storage::kFileSystemTypeIsolated, |
228 isolated_virtual_path); | 228 isolated_virtual_path); |
229 | 229 |
230 EXPECT_TRUE(isolated_url.is_valid()); | 230 EXPECT_TRUE(isolated_url.is_valid()); |
231 | 231 |
232 FileSystemURLParser parser(isolated_url); | 232 FileSystemURLParser parser(isolated_url); |
233 EXPECT_TRUE(parser.Parse()); | 233 EXPECT_TRUE(parser.Parse()); |
234 | 234 |
235 ProvidedFileSystemInterface* file_system = parser.file_system(); | 235 ProvidedFileSystemInterface* file_system = parser.file_system(); |
236 ASSERT_TRUE(file_system); | 236 ASSERT_TRUE(file_system); |
237 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 237 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 const base::FilePath kFilePath = | 301 const base::FilePath kFilePath = |
302 base::FilePath::FromUTF8Unsafe("provided/hello/world"); | 302 base::FilePath::FromUTF8Unsafe("provided/hello/world"); |
303 LocalPathParser parser(profile_, kFilePath); | 303 LocalPathParser parser(profile_, kFilePath); |
304 EXPECT_FALSE(parser.Parse()); | 304 EXPECT_FALSE(parser.Parse()); |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 } // namespace util | 308 } // namespace util |
309 } // namespace file_system_provider | 309 } // namespace file_system_provider |
310 } // namespace chromeos | 310 } // namespace chromeos |
OLD | NEW |