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

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

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test on Win 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 "webkit/fileapi/file_system_url.h" 5 #include "webkit/fileapi/file_system_url.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/fileapi/external_mount_points.h" 10 #include "webkit/fileapi/external_mount_points.h"
11 #include "webkit/fileapi/file_system_types.h" 11 #include "webkit/fileapi/file_system_types.h"
12 #include "webkit/fileapi/file_system_util.h" 12 #include "webkit/fileapi/file_system_util.h"
13 #include "webkit/fileapi/isolated_context.h" 13 #include "webkit/fileapi/isolated_context.h"
14 #include "webkit/fileapi/syncable/syncable_file_system_util.h" 14 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
15 15
16 #define FPL FILE_PATH_LITERAL 16 #define FPL FILE_PATH_LITERAL
17 17
18 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 18 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
19 #define DRIVE FPL("C:") 19 #define DRIVE FPL("C:")
20 #else 20 #else
21 #define DRIVE FPL("/a/") 21 #define DRIVE FPL("/a/")
22 #endif 22 #endif
23 23
24 namespace fileapi { 24 namespace fileapi {
25 25
26 namespace { 26 namespace {
27 27
28 FileSystemURL CreateFileSystemURL(const std::string& url_string) { 28 FileSystemURL CreateFileSystemURL(const std::string& url_string) {
29 return FileSystemURL(GURL(url_string)); 29 FileSystemURL url = FileSystemURL::CreateForTest(GURL(url_string));
30 switch (url.type()) {
31 case kFileSystemTypeExternal:
32 return ExternalMountPoints::GetSystemInstance()->
33 CreateCrackedFileSystemURL(url.origin(), url.type(), url.path());
34 case kFileSystemTypeIsolated:
35 return IsolatedContext::GetInstance()->CreateCrackedFileSystemURL(
36 url.origin(), url.type(), url.path());
37 default:
38 return url;
39 }
40 }
41
42 FileSystemURL CreateExternalFileSystemURL(const GURL& origin,
43 FileSystemType type,
44 const FilePath& path) {
45 return ExternalMountPoints::GetSystemInstance()->CreateCrackedFileSystemURL(
46 origin, type, path);
30 } 47 }
31 48
32 std::string NormalizedUTF8Path(const FilePath& path) { 49 std::string NormalizedUTF8Path(const FilePath& path) {
33 return path.NormalizePathSeparators().AsUTF8Unsafe(); 50 return path.NormalizePathSeparators().AsUTF8Unsafe();
34 } 51 }
35 52
36 } // namespace 53 } // namespace
37 54
38 TEST(FileSystemURLTest, ParsePersistent) { 55 TEST(FileSystemURLTest, ParsePersistent) {
39 FileSystemURL url = CreateFileSystemURL( 56 FileSystemURL url = CreateFileSystemURL(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"), 118 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"),
102 GURL("filesystem:http://chromium.com/temporary/dir a/file a"), 119 GURL("filesystem:http://chromium.com/temporary/dir a/file a"),
103 GURL("filesystem:https://chromium.org/temporary/dir a/file a") 120 GURL("filesystem:https://chromium.org/temporary/dir a/file a")
104 }; 121 };
105 122
106 FileSystemURL::Comparator compare; 123 FileSystemURL::Comparator compare;
107 for (size_t i = 0; i < arraysize(urls); ++i) { 124 for (size_t i = 0; i < arraysize(urls); ++i) {
108 for (size_t j = 0; j < arraysize(urls); ++j) { 125 for (size_t j = 0; j < arraysize(urls); ++j) {
109 SCOPED_TRACE(testing::Message() << i << " < " << j); 126 SCOPED_TRACE(testing::Message() << i << " < " << j);
110 EXPECT_EQ(urls[i] < urls[j], 127 EXPECT_EQ(urls[i] < urls[j],
111 compare(FileSystemURL(urls[i]), FileSystemURL(urls[j]))); 128 compare(FileSystemURL::CreateForTest(urls[i]),
129 FileSystemURL::CreateForTest(urls[j])));
112 } 130 }
113 } 131 }
114 132
115 const FileSystemURL a = CreateFileSystemURL( 133 const FileSystemURL a = CreateFileSystemURL(
116 "filesystem:http://chromium.org/temporary/dir a/file a"); 134 "filesystem:http://chromium.org/temporary/dir a/file a");
117 const FileSystemURL b = CreateFileSystemURL( 135 const FileSystemURL b = CreateFileSystemURL(
118 "filesystem:http://chromium.org/persistent/dir a/file a"); 136 "filesystem:http://chromium.org/persistent/dir a/file a");
119 EXPECT_EQ(a.type() < b.type(), compare(a, b)); 137 EXPECT_EQ(a.type() < b.type(), compare(a, b));
120 EXPECT_EQ(b.type() < a.type(), compare(b, a)); 138 EXPECT_EQ(b.type() < a.type(), compare(b, a));
121 } 139 }
122 140
123 TEST(FileSystemURLTest, WithPath) { 141 TEST(FileSystemURLTest, WithPath) {
124 const GURL kURL("filesystem:http://chromium.org/temporary/dir"); 142 const GURL kURL("filesystem:http://chromium.org/temporary/dir");
125 const FilePath::StringType paths[] = { 143 const FilePath::StringType paths[] = {
126 FPL("dir a"), 144 FPL("dir a"),
127 FPL("dir a/file 1"), 145 FPL("dir a/file 1"),
128 FPL("dir a/dir b"), 146 FPL("dir a/dir b"),
129 FPL("dir a/dir b/file 2"), 147 FPL("dir a/dir b/file 2"),
130 }; 148 };
131 149
132 const FileSystemURL base = FileSystemURL(kURL); 150 const FileSystemURL base = FileSystemURL::CreateForTest(kURL);
133 for (size_t i = 0; i < arraysize(paths); ++i) { 151 for (size_t i = 0; i < arraysize(paths); ++i) {
134 const FileSystemURL url = base.WithPath(FilePath(paths[i])); 152 const FileSystemURL url = base.WithPath(FilePath(paths[i]));
135 EXPECT_EQ(paths[i], url.path().value()); 153 EXPECT_EQ(paths[i], url.path().value());
136 EXPECT_EQ(base.origin().spec(), url.origin().spec()); 154 EXPECT_EQ(base.origin().spec(), url.origin().spec());
137 EXPECT_EQ(base.type(), url.type()); 155 EXPECT_EQ(base.type(), url.type());
138 EXPECT_EQ(base.mount_type(), url.mount_type()); 156 EXPECT_EQ(base.mount_type(), url.mount_type());
139 EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); 157 EXPECT_EQ(base.filesystem_id(), url.filesystem_id());
140 } 158 }
141 } 159 }
142 160
143 TEST(FileSystemURLTest, WithPathForExternal) { 161 TEST(FileSystemURLTest, WithPathForExternal) {
144 const std::string kId = "foo"; 162 const std::string kId = "foo";
145 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, FilePath()); 163 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, FilePath());
146 const FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath(); 164 const FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath();
147 165
148 const FilePath::CharType kBasePath[] = FPL("dir"); 166 const FilePath::CharType kBasePath[] = FPL("dir");
149 const FilePath::StringType paths[] = { 167 const FilePath::StringType paths[] = {
150 FPL("dir a"), 168 FPL("dir a"),
151 FPL("dir a/file 1"), 169 FPL("dir a/file 1"),
152 FPL("dir a/dir b"), 170 FPL("dir a/dir b"),
153 FPL("dir a/dir b/file 2"), 171 FPL("dir a/dir b/file 2"),
154 }; 172 };
155 173
156 const FileSystemURL base = FileSystemURL( 174 const FileSystemURL base = FileSystemURL::CreateForTest(
157 GURL("http://example.com/"), 175 GURL("http://example.com/"),
158 kFileSystemTypeExternal, 176 kFileSystemTypeExternal,
159 kVirtualRoot.Append(kBasePath)); 177 kVirtualRoot.Append(kBasePath));
160 178
161 for (size_t i = 0; i < arraysize(paths); ++i) { 179 for (size_t i = 0; i < arraysize(paths); ++i) {
162 const FileSystemURL url = base.WithPath(FilePath(paths[i])); 180 const FileSystemURL url = base.WithPath(FilePath(paths[i]));
163 EXPECT_EQ(paths[i], url.path().value()); 181 EXPECT_EQ(paths[i], url.path().value());
164 EXPECT_EQ(base.origin().spec(), url.origin().spec()); 182 EXPECT_EQ(base.origin().spec(), url.origin().spec());
165 EXPECT_EQ(base.type(), url.type()); 183 EXPECT_EQ(base.type(), url.type());
166 EXPECT_EQ(base.mount_type(), url.mount_type()); 184 EXPECT_EQ(base.mount_type(), url.mount_type());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 227
210 // False case: different origins. 228 // False case: different origins.
211 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( 229 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
212 CreateFileSystemURL(root4 + child))); 230 CreateFileSystemURL(root4 + child)));
213 } 231 }
214 232
215 TEST(FileSystemURLTest, DebugString) { 233 TEST(FileSystemURLTest, DebugString) {
216 const GURL kOrigin("http://example.com"); 234 const GURL kOrigin("http://example.com");
217 const FilePath kPath(FPL("dir/file")); 235 const FilePath kPath(FPL("dir/file"));
218 236
219 const FileSystemURL kURL1(kOrigin, kFileSystemTypeTemporary, kPath); 237 const FileSystemURL kURL1 = FileSystemURL::CreateForTest(
238 kOrigin, kFileSystemTypeTemporary, kPath);
220 EXPECT_EQ("filesystem:http://example.com/temporary/" + 239 EXPECT_EQ("filesystem:http://example.com/temporary/" +
221 NormalizedUTF8Path(kPath), 240 NormalizedUTF8Path(kPath),
222 kURL1.DebugString()); 241 kURL1.DebugString());
223 242
224 const FilePath kRoot(DRIVE FPL("/root")); 243 const FilePath kRoot(DRIVE FPL("/root"));
225 ScopedExternalFileSystem scoped_fs("foo", 244 ScopedExternalFileSystem scoped_fs("foo",
226 kFileSystemTypeNativeLocal, 245 kFileSystemTypeNativeLocal,
227 kRoot.NormalizePathSeparators()); 246 kRoot.NormalizePathSeparators());
228 const FileSystemURL kURL2(kOrigin, kFileSystemTypeExternal, 247 const FileSystemURL kURL2(CreateExternalFileSystemURL(
229 scoped_fs.GetVirtualRootPath().Append(kPath)); 248 kOrigin,
249 kFileSystemTypeExternal,
250 scoped_fs.GetVirtualRootPath().Append(kPath)));
230 EXPECT_EQ("filesystem:http://example.com/external/" + 251 EXPECT_EQ("filesystem:http://example.com/external/" +
231 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + 252 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) +
232 " (NativeLocal@foo:" + 253 " (NativeLocal@foo:" +
233 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", 254 NormalizedUTF8Path(kRoot.Append(kPath)) + ")",
234 kURL2.DebugString()); 255 kURL2.DebugString());
235 } 256 }
236 257
237 } // namespace fileapi 258 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job_unittest.cc ('k') | webkit/fileapi/isolated_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698