| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 EXPECT_FALSE(IsFileSystemProviderLocalPath( | 120 EXPECT_FALSE(IsFileSystemProviderLocalPath( |
| 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 base::File::Error result = |
| 131 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); | 131 file_system_provider_service_->MountFileSystem( |
| 132 ASSERT_TRUE(result); | 132 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); |
| 133 ASSERT_EQ(base::File::FILE_OK, result); |
| 133 const ProvidedFileSystemInfo file_system_info = | 134 const ProvidedFileSystemInfo file_system_info = |
| 134 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 135 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 135 kFileSystemId) | 136 kFileSystemId) |
| 136 ->GetFileSystemInfo(); | 137 ->GetFileSystemInfo(); |
| 137 | 138 |
| 138 const base::FilePath kFilePath = | 139 const base::FilePath kFilePath = |
| 139 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 140 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
| 140 const storage::FileSystemURL url = | 141 const storage::FileSystemURL url = |
| 141 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 142 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
| 142 EXPECT_TRUE(url.is_valid()); | 143 EXPECT_TRUE(url.is_valid()); |
| 143 | 144 |
| 144 FileSystemURLParser parser(url); | 145 FileSystemURLParser parser(url); |
| 145 EXPECT_TRUE(parser.Parse()); | 146 EXPECT_TRUE(parser.Parse()); |
| 146 | 147 |
| 147 ProvidedFileSystemInterface* file_system = parser.file_system(); | 148 ProvidedFileSystemInterface* file_system = parser.file_system(); |
| 148 ASSERT_TRUE(file_system); | 149 ASSERT_TRUE(file_system); |
| 149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 150 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
| 150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 151 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 154 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
| 154 const bool result = file_system_provider_service_->MountFileSystem( | 155 const base::File::Error result = |
| 155 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); | 156 file_system_provider_service_->MountFileSystem( |
| 156 ASSERT_TRUE(result); | 157 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); |
| 158 ASSERT_EQ(base::File::FILE_OK, result); |
| 157 const ProvidedFileSystemInfo file_system_info = | 159 const ProvidedFileSystemInfo file_system_info = |
| 158 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 160 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 159 kFileSystemId) | 161 kFileSystemId) |
| 160 ->GetFileSystemInfo(); | 162 ->GetFileSystemInfo(); |
| 161 | 163 |
| 162 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 164 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
| 163 const storage::FileSystemURL url = | 165 const storage::FileSystemURL url = |
| 164 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 166 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
| 165 EXPECT_TRUE(url.is_valid()); | 167 EXPECT_TRUE(url.is_valid()); |
| 166 | 168 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 184 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 186 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
| 185 // 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 |
| 186 // exist, therefore is will always be invalid, and empty. | 188 // exist, therefore is will always be invalid, and empty. |
| 187 EXPECT_FALSE(url.is_valid()); | 189 EXPECT_FALSE(url.is_valid()); |
| 188 | 190 |
| 189 FileSystemURLParser parser(url); | 191 FileSystemURLParser parser(url); |
| 190 EXPECT_FALSE(parser.Parse()); | 192 EXPECT_FALSE(parser.Parse()); |
| 191 } | 193 } |
| 192 | 194 |
| 193 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { | 195 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { |
| 194 const bool result = file_system_provider_service_->MountFileSystem( | 196 const base::File::Error result = |
| 195 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); | 197 file_system_provider_service_->MountFileSystem( |
| 196 ASSERT_TRUE(result); | 198 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); |
| 199 ASSERT_EQ(base::File::FILE_OK, result); |
| 197 const ProvidedFileSystemInfo file_system_info = | 200 const ProvidedFileSystemInfo file_system_info = |
| 198 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 201 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 199 kFileSystemId) | 202 kFileSystemId) |
| 200 ->GetFileSystemInfo(); | 203 ->GetFileSystemInfo(); |
| 201 | 204 |
| 202 const base::FilePath kFilePath = | 205 const base::FilePath kFilePath = |
| 203 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 206 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
| 204 const storage::FileSystemURL url = | 207 const storage::FileSystemURL url = |
| 205 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 208 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
| 206 EXPECT_TRUE(url.is_valid()); | 209 EXPECT_TRUE(url.is_valid()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 230 FileSystemURLParser parser(isolated_url); | 233 FileSystemURLParser parser(isolated_url); |
| 231 EXPECT_TRUE(parser.Parse()); | 234 EXPECT_TRUE(parser.Parse()); |
| 232 | 235 |
| 233 ProvidedFileSystemInterface* file_system = parser.file_system(); | 236 ProvidedFileSystemInterface* file_system = parser.file_system(); |
| 234 ASSERT_TRUE(file_system); | 237 ASSERT_TRUE(file_system); |
| 235 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 238 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
| 236 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 239 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
| 237 } | 240 } |
| 238 | 241 |
| 239 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { | 242 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { |
| 240 const bool result = file_system_provider_service_->MountFileSystem( | 243 const base::File::Error result = |
| 241 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); | 244 file_system_provider_service_->MountFileSystem( |
| 242 ASSERT_TRUE(result); | 245 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); |
| 246 ASSERT_EQ(base::File::FILE_OK, result); |
| 243 const ProvidedFileSystemInfo file_system_info = | 247 const ProvidedFileSystemInfo file_system_info = |
| 244 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 248 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 245 kFileSystemId) | 249 kFileSystemId) |
| 246 ->GetFileSystemInfo(); | 250 ->GetFileSystemInfo(); |
| 247 | 251 |
| 248 const base::FilePath kFilePath = | 252 const base::FilePath kFilePath = |
| 249 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 253 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
| 250 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( | 254 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( |
| 251 base::FilePath(kFilePath.value().substr(1))); | 255 base::FilePath(kFilePath.value().substr(1))); |
| 252 | 256 |
| 253 LOG(ERROR) << kLocalFilePath.value(); | 257 LOG(ERROR) << kLocalFilePath.value(); |
| 254 LocalPathParser parser(profile_, kLocalFilePath); | 258 LocalPathParser parser(profile_, kLocalFilePath); |
| 255 EXPECT_TRUE(parser.Parse()); | 259 EXPECT_TRUE(parser.Parse()); |
| 256 | 260 |
| 257 ProvidedFileSystemInterface* file_system = parser.file_system(); | 261 ProvidedFileSystemInterface* file_system = parser.file_system(); |
| 258 ASSERT_TRUE(file_system); | 262 ASSERT_TRUE(file_system); |
| 259 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 263 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
| 260 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 264 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
| 261 } | 265 } |
| 262 | 266 |
| 263 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { | 267 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { |
| 264 const bool result = file_system_provider_service_->MountFileSystem( | 268 const base::File::Error result = |
| 265 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); | 269 file_system_provider_service_->MountFileSystem( |
| 266 ASSERT_TRUE(result); | 270 kExtensionId, MountOptions(kFileSystemId, kDisplayName)); |
| 271 ASSERT_EQ(base::File::FILE_OK, result); |
| 267 const ProvidedFileSystemInfo file_system_info = | 272 const ProvidedFileSystemInfo file_system_info = |
| 268 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 273 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 269 kFileSystemId) | 274 kFileSystemId) |
| 270 ->GetFileSystemInfo(); | 275 ->GetFileSystemInfo(); |
| 271 | 276 |
| 272 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 277 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
| 273 const base::FilePath kLocalFilePath = file_system_info.mount_path(); | 278 const base::FilePath kLocalFilePath = file_system_info.mount_path(); |
| 274 | 279 |
| 275 LocalPathParser parser(profile_, kLocalFilePath); | 280 LocalPathParser parser(profile_, kLocalFilePath); |
| 276 EXPECT_TRUE(parser.Parse()); | 281 EXPECT_TRUE(parser.Parse()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 299 const base::FilePath kFilePath = | 304 const base::FilePath kFilePath = |
| 300 base::FilePath::FromUTF8Unsafe("provided/hello/world"); | 305 base::FilePath::FromUTF8Unsafe("provided/hello/world"); |
| 301 LocalPathParser parser(profile_, kFilePath); | 306 LocalPathParser parser(profile_, kFilePath); |
| 302 EXPECT_FALSE(parser.Parse()); | 307 EXPECT_FALSE(parser.Parse()); |
| 303 } | 308 } |
| 304 } | 309 } |
| 305 | 310 |
| 306 } // namespace util | 311 } // namespace util |
| 307 } // namespace file_system_provider | 312 } // namespace file_system_provider |
| 308 } // namespace chromeos | 313 } // namespace chromeos |
| OLD | NEW |