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