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

Side by Side Diff: webkit/fileapi/external_mount_points_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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/external_mount_points.h"
6
7 #include <string>
8
9 #include "base/file_path.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 #define FPL FILE_PATH_LITERAL
13
14 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
15 #define DRIVE FPL("C:")
16 #else
17 #define DRIVE
18 #endif
19
20 namespace {
21
22 TEST(ExternalMountPointsTest, AddMountPoint) {
23 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
24 fileapi::ExternalMountPoints::CreateRefCounted());
25
26 struct TestCase {
27 // The mount point's name.
28 const char* const name;
29 // The mount point's path.
30 const FilePath::CharType* const path;
31 // Whether the mount point registration should succeed.
32 bool success;
33 // Path returned by GetRegisteredPath. NULL if the method is expected to
34 // fail.
35 const FilePath::CharType* const registered_path;
36 };
37
38 const TestCase kTestCases[] = {
39 // Valid mount point.
40 { "test", DRIVE FPL("/foo/test"), true, DRIVE FPL("/foo/test") },
41 // Valid mount point with only one path component.
42 { "bbb", DRIVE FPL("/bbb"), true, DRIVE FPL("/bbb") },
43 // Existing mount point path is substring of the mount points path.
44 { "test11", DRIVE FPL("/foo/test11"), true, DRIVE FPL("/foo/test11") },
45 // Path substring of an existing path.
46 { "test1", DRIVE FPL("/foo/test1"), true, DRIVE FPL("/foo/test1") },
47 // Empty mount point name and path.
48 { "", DRIVE FPL(""), false, NULL },
49 // Empty mount point name.
50 { "", DRIVE FPL("/ddd"), false, NULL },
51 // Empty mount point path.
52 { "empty_path", FPL(""), true, FPL("") },
53 // Name different from path's base name.
54 { "not_base_name", DRIVE FPL("/x/y/z"), true, DRIVE FPL("/x/y/z") },
55 // References parent.
56 { "invalid", DRIVE FPL("../foo/invalid"), false, NULL },
57 // Relative path.
58 { "relative", DRIVE FPL("foo/relative"), false, NULL },
59 // Existing mount point path.
60 { "path_exists", DRIVE FPL("/foo/test"), false, NULL },
61 // Mount point with the same name exists.
62 { "test", DRIVE FPL("/foo/a/test_name_exists"), false,
63 DRIVE FPL("/foo/test") },
64 // Child of an existing mount point.
65 { "a1", DRIVE FPL("/foo/test/a"), false, NULL },
66 // Parent of an existing mount point.
67 { "foo1", DRIVE FPL("/foo"), false, NULL },
68 // Bit bigger depth.
69 { "g", DRIVE FPL("/foo/a/b/c/d/e/f/g"), true,
70 DRIVE FPL("/foo/a/b/c/d/e/f/g") },
71 // Sibling mount point (with similar name) exists.
72 { "ff", DRIVE FPL("/foo/a/b/c/d/e/ff"), true,
73 DRIVE FPL("/foo/a/b/c/d/e/ff") },
74 // Lexicographically last among existing mount points.
75 { "yyy", DRIVE FPL("/zzz/yyy"), true, DRIVE FPL("/zzz/yyy") },
76 // Parent of the lexicographically last mount point.
77 { "zzz1", DRIVE FPL("/zzz"), false, NULL },
78 // Child of the lexicographically last mount point.
79 { "xxx1", DRIVE FPL("/zzz/yyy/xxx"), false, NULL },
80 // Lexicographically first among existing mount points.
81 { "b", DRIVE FPL("/a/b"), true, DRIVE FPL("/a/b") },
82 // Parent of lexicographically first mount point.
83 { "a2", DRIVE FPL("/a"), false, NULL },
84 // Child of lexicographically last mount point.
85 { "c1", DRIVE FPL("/a/b/c"), false, NULL },
86 // Parent to all of the mount points.
87 { "root", DRIVE FPL("/"), false, NULL },
88 // Path contains .. component.
89 { "funky", DRIVE FPL("/tt/fun/../funky"), false, NULL },
90 // Windows separators.
91 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
92 { "win", DRIVE FPL("\\try\\separators\\win"), true,
93 DRIVE FPL("\\try\\separators\\win") },
94 { "win1", DRIVE FPL("\\try/separators\\win1"), true,
95 DRIVE FPL("\\try/separators\\win1") },
96 { "win2", DRIVE FPL("\\try/separators\\win"), false, NULL },
97 #else
98 { "win", DRIVE FPL("\\separators\\win"), false, NULL },
99 { "win1", DRIVE FPL("\\try/separators\\win1"), false, NULL },
100 #endif
101 // Win separators, but relative path.
102 { "win2", DRIVE FPL("try\\separators\\win2"), false, NULL },
103 };
104
105 // Test adding mount points.
106 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
107 EXPECT_EQ(kTestCases[i].success,
108 mount_points->RegisterFileSystem(
109 kTestCases[i].name,
110 fileapi::kFileSystemTypeNativeLocal,
111 FilePath(kTestCases[i].path)))
112 << "Adding mount point: " << kTestCases[i].name << " with path "
113 << kTestCases[i].path;
114 }
115
116 // Test that final mount point presence state is as expected.
117 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
118 FilePath found_path;
119 EXPECT_EQ(kTestCases[i].registered_path != NULL,
120 mount_points->GetRegisteredPath(kTestCases[i].name, &found_path))
121 << "Test case: " << i;
122
123 if (kTestCases[i].registered_path) {
124 FilePath expected_path(kTestCases[i].registered_path);
125 EXPECT_EQ(expected_path.NormalizePathSeparators(), found_path);
126 }
127 }
128 }
129
130 TEST(ExternalMountPointsTest, GetVirtualPath) {
131 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
132 fileapi::ExternalMountPoints::CreateRefCounted());
133
134 mount_points->RegisterFileSystem("c",
135 fileapi::kFileSystemTypeNativeLocal,
136 FilePath(DRIVE FPL("/a/b/c")));
137 // Note that "/a/b/c" < "/a/b/c(1)" < "/a/b/c/".
138 mount_points->RegisterFileSystem("c(1)",
139 fileapi::kFileSystemTypeNativeLocal,
140 FilePath(DRIVE FPL("/a/b/c(1)")));
141 mount_points->RegisterFileSystem("x",
142 fileapi::kFileSystemTypeNativeLocal,
143 FilePath(DRIVE FPL("/z/y/x")));
144 mount_points->RegisterFileSystem("o",
145 fileapi::kFileSystemTypeNativeLocal,
146 FilePath(DRIVE FPL("/m/n/o")));
147 // A mount point whose name does not match its path base name.
148 mount_points->RegisterFileSystem("mount",
149 fileapi::kFileSystemTypeNativeLocal,
150 FilePath(DRIVE FPL("/root/foo")));
151 // A mount point with an empty path.
152 mount_points->RegisterFileSystem("empty_path",
153 fileapi::kFileSystemTypeNativeLocal,
154 FilePath(FPL("")));
155
156 struct TestCase {
157 const FilePath::CharType* const local_path;
158 bool success;
159 const FilePath::CharType* const virtual_path;
160 };
161
162 const TestCase kTestCases[] = {
163 // Empty path.
164 { FPL(""), false, FPL("") },
165 // No registered mount point (but is parent to a mount point).
166 { DRIVE FPL("/a/b"), false, FPL("") },
167 // No registered mount point (but is parent to a mount point).
168 { DRIVE FPL("/z/y"), false, FPL("") },
169 // No registered mount point (but is parent to a mount point).
170 { DRIVE FPL("/m/n"), false, FPL("") },
171 // No registered mount point.
172 { DRIVE FPL("/foo/mount"), false, FPL("") },
173 // An existing mount point path is substring.
174 { DRIVE FPL("/a/b/c1"), false, FPL("") },
175 // No leading /.
176 { DRIVE FPL("a/b/c"), false, FPL("") },
177 // Sibling to a root path.
178 { DRIVE FPL("/a/b/d/e"), false, FPL("") },
179 // Sibling to a root path.
180 { DRIVE FPL("/z/y/v/u"), false, FPL("") },
181 // Sibling to a root path.
182 { DRIVE FPL("/m/n/p/q"), false, FPL("") },
183 // Mount point root path.
184 { DRIVE FPL("/a/b/c"), true, FPL("c") },
185 // Mount point root path.
186 { DRIVE FPL("/z/y/x"), true, FPL("x") },
187 // Mount point root path.
188 { DRIVE FPL("/m/n/o"), true, FPL("o") },
189 // Mount point child path.
190 { DRIVE FPL("/a/b/c/d/e"), true, FPL("c/d/e") },
191 // Mount point child path.
192 { DRIVE FPL("/z/y/x/v/u"), true, FPL("x/v/u") },
193 // Mount point child path.
194 { DRIVE FPL("/m/n/o/p/q"), true, FPL("o/p/q") },
195 // Name doesn't match mount point path base name.
196 { DRIVE FPL("/root/foo/a/b/c"), true, FPL("mount/a/b/c") },
197 { DRIVE FPL("/root/foo"), true, FPL("mount") },
198 // Mount point contains character whose ASCII code is smaller than file path
199 // separator's.
200 { DRIVE FPL("/a/b/c(1)/d/e"), true, FPL("c(1)/d/e") },
201 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
202 // Path with win separators mixed in.
203 { DRIVE FPL("/a\\b\\c/d"), true, FPL("c/d") },
204 #endif
205 };
206
207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
208 // Initialize virtual path with a value.
209 FilePath virtual_path(DRIVE FPL("/mount"));
210 FilePath local_path(kTestCases[i].local_path);
211 EXPECT_EQ(kTestCases[i].success,
212 mount_points->GetVirtualPath(local_path, &virtual_path))
213 << "Resolving " << kTestCases[i].local_path;
214
215 // There are no guarantees for |virtual_path| value if |GetVirtualPath|
216 // fails.
217 if (!kTestCases[i].success)
218 continue;
219
220 FilePath expected_virtual_path(kTestCases[i].virtual_path);
221 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
222 << "Resolving " << kTestCases[i].local_path;
223 }
224 }
225
226 } // namespace
227
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698