Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webkit/fileapi/isolated_context_unittest.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()->CrackURL(FileSystemURL(
237 GURL("http://chromium.org"), kFileSystemTypeIsolated, virtual_path));
238
239 ASSERT_EQ(relatives[j].valid, cracked.is_valid());
240 ASSERT_EQ(relatives[j].valid, cracked.is_cracked());
241
242 if (!relatives[j].valid)
243 continue;
244 ASSERT_EQ(GURL("http://chromium.org"), cracked.origin());
245 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path)
246 .NormalizePathSeparators().value(),
247 cracked.path().value());
248 ASSERT_EQ(virtual_path, cracked.virtual_path());
249 ASSERT_EQ(id_, cracked.filesystem_id());
250 ASSERT_EQ(kFileSystemTypeDragged, cracked.type());
251 ASSERT_EQ(kFileSystemTypeIsolated, cracked.mount_type());
252 }
253 }
254 }
255
209 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { 256 TEST_F(IsolatedContextTest, TestWithVirtualRoot) {
210 std::string cracked_id; 257 std::string cracked_id;
211 FilePath cracked_path; 258 FilePath cracked_path;
212 259
213 // Trying to crack virtual root "/" returns true but with empty cracked path 260 // Trying to crack virtual root "/" returns true but with empty cracked path
214 // as "/" of the isolated filesystem is a pure virtual directory 261 // as "/" of the isolated filesystem is a pure virtual directory
215 // that has no corresponding platform directory. 262 // that has no corresponding platform directory.
216 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); 263 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_);
217 ASSERT_TRUE(isolated_context()->CrackVirtualPath( 264 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
218 virtual_path, &cracked_id, NULL, &cracked_path)); 265 virtual_path, &cracked_id, NULL, &cracked_path));
219 ASSERT_EQ(FPL(""), cracked_path.value()); 266 ASSERT_EQ(FPL(""), cracked_path.value());
220 ASSERT_EQ(id_, cracked_id); 267 ASSERT_EQ(id_, cracked_id);
221 268
222 // Trying to crack "/foo" should fail (because "foo" is not the one 269 // Trying to crack "/foo" should fail (because "foo" is not the one
223 // included in the kTestPaths). 270 // included in the kTestPaths).
224 virtual_path = isolated_context()->CreateVirtualRootPath( 271 virtual_path = isolated_context()->CreateVirtualRootPath(
225 id_).AppendASCII("foo"); 272 id_).AppendASCII("foo");
226 ASSERT_FALSE(isolated_context()->CrackVirtualPath( 273 ASSERT_FALSE(isolated_context()->CrackVirtualPath(
227 virtual_path, &cracked_id, NULL, &cracked_path)); 274 virtual_path, &cracked_id, NULL, &cracked_path));
228 } 275 }
229 276
277 TEST_F(IsolatedContextTest, CanHandleURL) {
278 const GURL test_origin("http://chromium.org");
279 const FilePath test_path(FPL("/mount"));
280
281 // Shouldn't handle invalid URL.
282 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL()));
283
284 // Should handle Isolated File System.
285 EXPECT_TRUE(isolated_context()->CanHandleURL(FileSystemURL(
286 test_origin, fileapi::kFileSystemTypeIsolated, test_path)));
287
288 // Shouldn't handle the rest.
289 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
290 test_origin, fileapi::kFileSystemTypeExternal, test_path)));
291 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
292 test_origin, fileapi::kFileSystemTypeTemporary, test_path)));
293 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
294 test_origin, fileapi::kFileSystemTypePersistent, test_path)));
295 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
296 test_origin, fileapi::kFileSystemTypeTest, test_path)));
297 // Not even if it's isolated subtype.
298 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
299 test_origin, fileapi::kFileSystemTypeNativeLocal, test_path)));
300 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
301 test_origin, fileapi::kFileSystemTypeDragged, test_path)));
302 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
303 test_origin, fileapi::kFileSystemTypeNativeMedia, test_path)));
304 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL(
305 test_origin, fileapi::kFileSystemTypeDeviceMedia, test_path)));
306 }
307
230 } // namespace fileapi 308 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698