OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/fileapi/file_system_url.h" |
10 #include "webkit/fileapi/isolated_context.h" | 11 #include "webkit/fileapi/isolated_context.h" |
11 | 12 |
12 #define FPL(x) FILE_PATH_LITERAL(x) | 13 #define FPL(x) FILE_PATH_LITERAL(x) |
13 | 14 |
14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 15 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
15 #define DRIVE FPL("C:") | 16 #define DRIVE FPL("C:") |
16 #else | 17 #else |
17 #define DRIVE | 18 #define DRIVE |
18 #endif | 19 #endif |
19 | 20 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 }; | 183 }; |
183 | 184 |
184 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 185 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
185 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { | 186 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
186 SCOPED_TRACE(testing::Message() << "Testing " | 187 SCOPED_TRACE(testing::Message() << "Testing " |
187 << kTestPaths[i].value() << " " << relatives[j].path); | 188 << kTestPaths[i].value() << " " << relatives[j].path); |
188 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) | 189 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
189 .AppendASCII(names_[i]).Append(relatives[j].path); | 190 .AppendASCII(names_[i]).Append(relatives[j].path); |
190 std::string cracked_id; | 191 std::string cracked_id; |
191 FilePath cracked_path; | 192 FilePath cracked_path; |
192 FileSystemType cracked_type; | 193 FileSystemType cracked_type; |
193 if (!relatives[j].valid) { | 194 if (!relatives[j].valid) { |
194 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 195 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
195 virtual_path, &cracked_id, &cracked_type, &cracked_path)); | 196 virtual_path, &cracked_id, &cracked_type, &cracked_path)); |
196 continue; | 197 continue; |
197 } | 198 } |
198 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 199 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
199 virtual_path, &cracked_id, &cracked_type, &cracked_path)); | 200 virtual_path, &cracked_id, &cracked_type, &cracked_path)); |
200 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) | 201 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) |
201 .NormalizePathSeparators().value(), | 202 .NormalizePathSeparators().value(), |
202 cracked_path.value()); | 203 cracked_path.value()); |
203 ASSERT_EQ(id_, cracked_id); | 204 ASSERT_EQ(id_, cracked_id); |
204 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); | 205 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); |
205 } | 206 } |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
| 210 TEST_F(IsolatedContextTest, CrackURLWithRelativePaths) { |
| 211 const struct { |
| 212 FilePath::StringType path; |
| 213 bool valid; |
| 214 } relatives[] = { |
| 215 { FPL("foo"), true }, |
| 216 { FPL("foo/bar"), true }, |
| 217 { FPL(".."), false }, |
| 218 { FPL("foo/.."), false }, |
| 219 { FPL("foo/../bar"), false }, |
| 220 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 221 # define SHOULD_FAIL_WITH_WIN_SEPARATORS false |
| 222 #else |
| 223 # define SHOULD_FAIL_WITH_WIN_SEPARATORS true |
| 224 #endif |
| 225 { FPL("foo\\..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
| 226 { FPL("foo/..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
| 227 }; |
| 228 |
| 229 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
| 230 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
| 231 SCOPED_TRACE(testing::Message() << "Testing " |
| 232 << kTestPaths[i].value() << " " << relatives[j].path); |
| 233 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
| 234 .AppendASCII(names_[i]).Append(relatives[j].path); |
| 235 |
| 236 FileSystemURL cracked = isolated_context()->CreateCrackedFileSystemURL( |
| 237 GURL("http://chromium.org"), kFileSystemTypeIsolated, virtual_path); |
| 238 |
| 239 ASSERT_EQ(relatives[j].valid, cracked.is_valid()); |
| 240 |
| 241 if (!relatives[j].valid) |
| 242 continue; |
| 243 ASSERT_EQ(GURL("http://chromium.org"), cracked.origin()); |
| 244 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) |
| 245 .NormalizePathSeparators().value(), |
| 246 cracked.path().value()); |
| 247 ASSERT_EQ(virtual_path.NormalizePathSeparators(), cracked.virtual_path()); |
| 248 ASSERT_EQ(id_, cracked.filesystem_id()); |
| 249 ASSERT_EQ(kFileSystemTypeDragged, cracked.type()); |
| 250 ASSERT_EQ(kFileSystemTypeIsolated, cracked.mount_type()); |
| 251 } |
| 252 } |
| 253 } |
| 254 |
209 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { | 255 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { |
210 std::string cracked_id; | 256 std::string cracked_id; |
211 FilePath cracked_path; | 257 FilePath cracked_path; |
212 | 258 |
213 // Trying to crack virtual root "/" returns true but with empty cracked path | 259 // Trying to crack virtual root "/" returns true but with empty cracked path |
214 // as "/" of the isolated filesystem is a pure virtual directory | 260 // as "/" of the isolated filesystem is a pure virtual directory |
215 // that has no corresponding platform directory. | 261 // that has no corresponding platform directory. |
216 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); | 262 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); |
217 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 263 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
218 virtual_path, &cracked_id, NULL, &cracked_path)); | 264 virtual_path, &cracked_id, NULL, &cracked_path)); |
219 ASSERT_EQ(FPL(""), cracked_path.value()); | 265 ASSERT_EQ(FPL(""), cracked_path.value()); |
220 ASSERT_EQ(id_, cracked_id); | 266 ASSERT_EQ(id_, cracked_id); |
221 | 267 |
222 // Trying to crack "/foo" should fail (because "foo" is not the one | 268 // Trying to crack "/foo" should fail (because "foo" is not the one |
223 // included in the kTestPaths). | 269 // included in the kTestPaths). |
224 virtual_path = isolated_context()->CreateVirtualRootPath( | 270 virtual_path = isolated_context()->CreateVirtualRootPath( |
225 id_).AppendASCII("foo"); | 271 id_).AppendASCII("foo"); |
226 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 272 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
227 virtual_path, &cracked_id, NULL, &cracked_path)); | 273 virtual_path, &cracked_id, NULL, &cracked_path)); |
228 } | 274 } |
229 | 275 |
| 276 TEST_F(IsolatedContextTest, CanHandleURL) { |
| 277 const GURL test_origin("http://chromium.org"); |
| 278 const FilePath test_path(FPL("/mount")); |
| 279 |
| 280 // Should handle isolated file system. |
| 281 EXPECT_TRUE(isolated_context()->HandlesFileSystemMountType( |
| 282 fileapi::kFileSystemTypeIsolated)); |
| 283 |
| 284 // Shouldn't handle the rest. |
| 285 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 286 fileapi::kFileSystemTypeExternal)); |
| 287 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 288 fileapi::kFileSystemTypeTemporary)); |
| 289 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 290 fileapi::kFileSystemTypePersistent)); |
| 291 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 292 fileapi::kFileSystemTypeTest)); |
| 293 // Not even if it's isolated subtype. |
| 294 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 295 fileapi::kFileSystemTypeNativeLocal)); |
| 296 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 297 fileapi::kFileSystemTypeDragged)); |
| 298 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 299 fileapi::kFileSystemTypeNativeMedia)); |
| 300 EXPECT_FALSE(isolated_context()->HandlesFileSystemMountType( |
| 301 fileapi::kFileSystemTypeDeviceMedia)); |
| 302 } |
| 303 |
230 } // namespace fileapi | 304 } // namespace fileapi |
OLD | NEW |