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" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt"))); | 121 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt"))); |
122 EXPECT_FALSE(IsFileSystemProviderLocalPath( | 122 EXPECT_FALSE(IsFileSystemProviderLocalPath( |
123 base::FilePath::FromUTF8Unsafe("/provided"))); | 123 base::FilePath::FromUTF8Unsafe("/provided"))); |
124 EXPECT_FALSE( | 124 EXPECT_FALSE( |
125 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/"))); | 125 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/"))); |
126 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath())); | 126 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath())); |
127 } | 127 } |
128 | 128 |
129 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { | 129 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { |
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, |
| 132 kFileSystemId, |
| 133 kDisplayName, |
| 134 false /* writable */, |
| 135 false /* supports_notify_tag */); |
132 ASSERT_TRUE(result); | 136 ASSERT_TRUE(result); |
133 const ProvidedFileSystemInfo file_system_info = | 137 const ProvidedFileSystemInfo file_system_info = |
134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 138 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
135 kFileSystemId) | 139 kFileSystemId) |
136 ->GetFileSystemInfo(); | 140 ->GetFileSystemInfo(); |
137 | 141 |
138 const base::FilePath kFilePath = | 142 const base::FilePath kFilePath = |
139 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 143 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
140 const storage::FileSystemURL url = | 144 const storage::FileSystemURL url = |
141 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 145 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
142 EXPECT_TRUE(url.is_valid()); | 146 EXPECT_TRUE(url.is_valid()); |
143 | 147 |
144 FileSystemURLParser parser(url); | 148 FileSystemURLParser parser(url); |
145 EXPECT_TRUE(parser.Parse()); | 149 EXPECT_TRUE(parser.Parse()); |
146 | 150 |
147 ProvidedFileSystemInterface* file_system = parser.file_system(); | 151 ProvidedFileSystemInterface* file_system = parser.file_system(); |
148 ASSERT_TRUE(file_system); | 152 ASSERT_TRUE(file_system); |
149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 153 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 154 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
151 } | 155 } |
152 | 156 |
153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 157 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
154 const bool result = file_system_provider_service_->MountFileSystem( | 158 const bool result = file_system_provider_service_->MountFileSystem( |
155 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 159 kExtensionId, |
| 160 kFileSystemId, |
| 161 kDisplayName, |
| 162 false /* writable */, |
| 163 false /* supports_notify_tag */); |
156 ASSERT_TRUE(result); | 164 ASSERT_TRUE(result); |
157 const ProvidedFileSystemInfo file_system_info = | 165 const ProvidedFileSystemInfo file_system_info = |
158 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 166 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
159 kFileSystemId) | 167 kFileSystemId) |
160 ->GetFileSystemInfo(); | 168 ->GetFileSystemInfo(); |
161 | 169 |
162 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 170 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
163 const storage::FileSystemURL url = | 171 const storage::FileSystemURL url = |
164 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 172 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
165 EXPECT_TRUE(url.is_valid()); | 173 EXPECT_TRUE(url.is_valid()); |
166 | 174 |
167 FileSystemURLParser parser(url); | 175 FileSystemURLParser parser(url); |
168 EXPECT_TRUE(parser.Parse()); | 176 EXPECT_TRUE(parser.Parse()); |
169 | 177 |
170 ProvidedFileSystemInterface* file_system = parser.file_system(); | 178 ProvidedFileSystemInterface* file_system = parser.file_system(); |
171 ASSERT_TRUE(file_system); | 179 ASSERT_TRUE(file_system); |
172 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 180 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
173 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 181 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
174 } | 182 } |
175 | 183 |
176 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 184 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
177 const ProvidedFileSystemInfo file_system_info( | 185 const ProvidedFileSystemInfo file_system_info( |
178 kExtensionId, | 186 kExtensionId, |
179 kFileSystemId, | 187 kFileSystemId, |
180 kDisplayName, | 188 kDisplayName, |
181 false /* writable */, | 189 false /* writable */, |
| 190 false /* supports_notify_tag */, |
182 GetMountPath(profile_, kExtensionId, kFileSystemId)); | 191 GetMountPath(profile_, kExtensionId, kFileSystemId)); |
183 | 192 |
184 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); | 193 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); |
185 const storage::FileSystemURL url = | 194 const storage::FileSystemURL url = |
186 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 195 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
187 // It is impossible to create a cracked URL for a mount point which doesn't | 196 // 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. | 197 // exist, therefore is will always be invalid, and empty. |
189 EXPECT_FALSE(url.is_valid()); | 198 EXPECT_FALSE(url.is_valid()); |
190 | 199 |
191 FileSystemURLParser parser(url); | 200 FileSystemURLParser parser(url); |
192 EXPECT_FALSE(parser.Parse()); | 201 EXPECT_FALSE(parser.Parse()); |
193 } | 202 } |
194 | 203 |
195 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { | 204 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { |
196 const bool result = file_system_provider_service_->MountFileSystem( | 205 const bool result = file_system_provider_service_->MountFileSystem( |
197 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 206 kExtensionId, |
| 207 kFileSystemId, |
| 208 kDisplayName, |
| 209 false /* writable */, |
| 210 false /* supports_notify_tag */); |
198 ASSERT_TRUE(result); | 211 ASSERT_TRUE(result); |
199 const ProvidedFileSystemInfo file_system_info = | 212 const ProvidedFileSystemInfo file_system_info = |
200 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 213 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
201 kFileSystemId) | 214 kFileSystemId) |
202 ->GetFileSystemInfo(); | 215 ->GetFileSystemInfo(); |
203 | 216 |
204 const base::FilePath kFilePath = | 217 const base::FilePath kFilePath = |
205 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 218 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
206 const storage::FileSystemURL url = | 219 const storage::FileSystemURL url = |
207 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 220 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
(...skipping 25 matching lines...) Expand all Loading... |
233 EXPECT_TRUE(parser.Parse()); | 246 EXPECT_TRUE(parser.Parse()); |
234 | 247 |
235 ProvidedFileSystemInterface* file_system = parser.file_system(); | 248 ProvidedFileSystemInterface* file_system = parser.file_system(); |
236 ASSERT_TRUE(file_system); | 249 ASSERT_TRUE(file_system); |
237 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 250 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
238 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 251 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
239 } | 252 } |
240 | 253 |
241 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { | 254 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { |
242 const bool result = file_system_provider_service_->MountFileSystem( | 255 const bool result = file_system_provider_service_->MountFileSystem( |
243 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 256 kExtensionId, |
| 257 kFileSystemId, |
| 258 kDisplayName, |
| 259 false /* writable */, |
| 260 false /* supports_notify_tag */); |
244 ASSERT_TRUE(result); | 261 ASSERT_TRUE(result); |
245 const ProvidedFileSystemInfo file_system_info = | 262 const ProvidedFileSystemInfo file_system_info = |
246 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 263 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
247 kFileSystemId) | 264 kFileSystemId) |
248 ->GetFileSystemInfo(); | 265 ->GetFileSystemInfo(); |
249 | 266 |
250 const base::FilePath kFilePath = | 267 const base::FilePath kFilePath = |
251 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 268 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
252 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( | 269 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( |
253 base::FilePath(kFilePath.value().substr(1))); | 270 base::FilePath(kFilePath.value().substr(1))); |
254 | 271 |
255 LOG(ERROR) << kLocalFilePath.value(); | 272 LOG(ERROR) << kLocalFilePath.value(); |
256 LocalPathParser parser(profile_, kLocalFilePath); | 273 LocalPathParser parser(profile_, kLocalFilePath); |
257 EXPECT_TRUE(parser.Parse()); | 274 EXPECT_TRUE(parser.Parse()); |
258 | 275 |
259 ProvidedFileSystemInterface* file_system = parser.file_system(); | 276 ProvidedFileSystemInterface* file_system = parser.file_system(); |
260 ASSERT_TRUE(file_system); | 277 ASSERT_TRUE(file_system); |
261 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 278 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
262 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 279 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
263 } | 280 } |
264 | 281 |
265 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { | 282 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { |
266 const bool result = file_system_provider_service_->MountFileSystem( | 283 const bool result = file_system_provider_service_->MountFileSystem( |
267 kExtensionId, kFileSystemId, kDisplayName, false /* writable */); | 284 kExtensionId, |
| 285 kFileSystemId, |
| 286 kDisplayName, |
| 287 false /* writable */, |
| 288 false /* supports_notify_tag */); |
268 ASSERT_TRUE(result); | 289 ASSERT_TRUE(result); |
269 const ProvidedFileSystemInfo file_system_info = | 290 const ProvidedFileSystemInfo file_system_info = |
270 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 291 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
271 kFileSystemId) | 292 kFileSystemId) |
272 ->GetFileSystemInfo(); | 293 ->GetFileSystemInfo(); |
273 | 294 |
274 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 295 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
275 const base::FilePath kLocalFilePath = file_system_info.mount_path(); | 296 const base::FilePath kLocalFilePath = file_system_info.mount_path(); |
276 | 297 |
277 LocalPathParser parser(profile_, kLocalFilePath); | 298 LocalPathParser parser(profile_, kLocalFilePath); |
(...skipping 23 matching lines...) Expand all Loading... |
301 const base::FilePath kFilePath = | 322 const base::FilePath kFilePath = |
302 base::FilePath::FromUTF8Unsafe("provided/hello/world"); | 323 base::FilePath::FromUTF8Unsafe("provided/hello/world"); |
303 LocalPathParser parser(profile_, kFilePath); | 324 LocalPathParser parser(profile_, kFilePath); |
304 EXPECT_FALSE(parser.Parse()); | 325 EXPECT_FALSE(parser.Parse()); |
305 } | 326 } |
306 } | 327 } |
307 | 328 |
308 } // namespace util | 329 } // namespace util |
309 } // namespace file_system_provider | 330 } // namespace file_system_provider |
310 } // namespace chromeos | 331 } // namespace chromeos |
OLD | NEW |