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

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

Issue 11648027: Extract external file systems handling from isolated context. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gypi file 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/isolated_context.h" 10 #include "webkit/fileapi/isolated_context.h"
11 11
12 #define FPL(x) FILE_PATH_LITERAL(x) 12 #define FPL(x) FILE_PATH_LITERAL(x)
13 13
14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 14 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
15 #define DRIVE FPL("C:") 15 #define DRIVE FPL("C:")
16 #else 16 #else
17 #define DRIVE 17 #define DRIVE
18 #endif 18 #endif
19 19
20 namespace fileapi { 20 namespace fileapi {
21 21
22 typedef IsolatedContext::FileInfo FileInfo; 22 typedef IsolatedContext::MountPointInfo FileInfo;
23 23
24 namespace { 24 namespace {
25 25
26 const FilePath kTestPaths[] = { 26 const FilePath kTestPaths[] = {
27 FilePath(DRIVE FPL("/a/b.txt")), 27 FilePath(DRIVE FPL("/a/b.txt")),
28 FilePath(DRIVE FPL("/c/d/e")), 28 FilePath(DRIVE FPL("/c/d/e")),
29 FilePath(DRIVE FPL("/h/")), 29 FilePath(DRIVE FPL("/h/")),
30 FilePath(DRIVE FPL("/")), 30 FilePath(DRIVE FPL("/")),
31 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 31 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
32 FilePath(DRIVE FPL("\\foo\\bar")), 32 FilePath(DRIVE FPL("\\foo\\bar")),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 // See if the name of each registered kTestPaths (that is what we 89 // See if the name of each registered kTestPaths (that is what we
90 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as 90 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as
91 // a valid virtual path in the isolated filesystem. 91 // a valid virtual path in the isolated filesystem.
92 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { 92 for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
93 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) 93 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_)
94 .AppendASCII(names_[i]); 94 .AppendASCII(names_[i]);
95 std::string cracked_id; 95 std::string cracked_id;
96 FilePath cracked_path; 96 FilePath cracked_path;
97 FileSystemType cracked_type; 97 FileSystemType cracked_type;
98 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 98 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
99 virtual_path, &cracked_id, &cracked_type, &cracked_path)); 99 virtual_path, &cracked_id, &cracked_type, &cracked_path));
100 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), 100 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(),
101 cracked_path.value()); 101 cracked_path.value());
102 ASSERT_EQ(id_, cracked_id); 102 ASSERT_EQ(id_, cracked_id);
103 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); 103 ASSERT_EQ(kFileSystemTypeDragged, cracked_type);
104 } 104 }
105 105
106 // Make sure GetRegisteredPath returns false for id_ since it is 106 // Make sure GetRegisteredPath returns false for id_ since it is
107 // registered for dragged files. 107 // registered for dragged files.
108 FilePath path; 108 FilePath path;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { 184 for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
185 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { 185 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) {
186 SCOPED_TRACE(testing::Message() << "Testing " 186 SCOPED_TRACE(testing::Message() << "Testing "
187 << kTestPaths[i].value() << " " << relatives[j].path); 187 << kTestPaths[i].value() << " " << relatives[j].path);
188 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) 188 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_)
189 .AppendASCII(names_[i]).Append(relatives[j].path); 189 .AppendASCII(names_[i]).Append(relatives[j].path);
190 std::string cracked_id; 190 std::string cracked_id;
191 FilePath cracked_path; 191 FilePath cracked_path;
192 FileSystemType cracked_type; 192 FileSystemType cracked_type;
193 if (!relatives[j].valid) { 193 if (!relatives[j].valid) {
194 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( 194 ASSERT_FALSE(isolated_context()->CrackVirtualPath(
195 virtual_path, &cracked_id, &cracked_type, &cracked_path)); 195 virtual_path, &cracked_id, &cracked_type, &cracked_path));
196 continue; 196 continue;
197 } 197 }
198 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 198 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
199 virtual_path, &cracked_id, &cracked_type, &cracked_path)); 199 virtual_path, &cracked_id, &cracked_type, &cracked_path));
200 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) 200 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path)
201 .NormalizePathSeparators().value(), 201 .NormalizePathSeparators().value(),
202 cracked_path.value()); 202 cracked_path.value());
203 ASSERT_EQ(id_, cracked_id); 203 ASSERT_EQ(id_, cracked_id);
204 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); 204 ASSERT_EQ(kFileSystemTypeDragged, cracked_type);
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { 209 TEST_F(IsolatedContextTest, TestWithVirtualRoot) {
210 std::string cracked_id; 210 std::string cracked_id;
211 FilePath cracked_path; 211 FilePath cracked_path;
212 212
213 // Trying to crack virtual root "/" returns true but with empty cracked path 213 // Trying to crack virtual root "/" returns true but with empty cracked path
214 // as "/" of the isolated filesystem is a pure virtual directory 214 // as "/" of the isolated filesystem is a pure virtual directory
215 // that has no corresponding platform directory. 215 // that has no corresponding platform directory.
216 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); 216 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_);
217 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( 217 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
218 virtual_path, &cracked_id, NULL, &cracked_path)); 218 virtual_path, &cracked_id, NULL, &cracked_path));
219 ASSERT_EQ(FPL(""), cracked_path.value()); 219 ASSERT_EQ(FPL(""), cracked_path.value());
220 ASSERT_EQ(id_, cracked_id); 220 ASSERT_EQ(id_, cracked_id);
221 221
222 // Trying to crack "/foo" should fail (because "foo" is not the one 222 // Trying to crack "/foo" should fail (because "foo" is not the one
223 // included in the kTestPaths). 223 // included in the kTestPaths).
224 virtual_path = isolated_context()->CreateVirtualRootPath( 224 virtual_path = isolated_context()->CreateVirtualRootPath(
225 id_).AppendASCII("foo"); 225 id_).AppendASCII("foo");
226 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( 226 ASSERT_FALSE(isolated_context()->CrackVirtualPath(
227 virtual_path, &cracked_id, NULL, &cracked_path)); 227 virtual_path, &cracked_id, NULL, &cracked_path));
228 } 228 }
229 229
230 } // namespace fileapi 230 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698