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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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"
(...skipping 23 matching lines...) Expand all
34 case kFileSystemTypeIsolated: 34 case kFileSystemTypeIsolated:
35 return IsolatedContext::GetInstance()->CreateCrackedFileSystemURL( 35 return IsolatedContext::GetInstance()->CreateCrackedFileSystemURL(
36 url.origin(), url.type(), url.path()); 36 url.origin(), url.type(), url.path());
37 default: 37 default:
38 return url; 38 return url;
39 } 39 }
40 } 40 }
41 41
42 FileSystemURL CreateExternalFileSystemURL(const GURL& origin, 42 FileSystemURL CreateExternalFileSystemURL(const GURL& origin,
43 FileSystemType type, 43 FileSystemType type,
44 const FilePath& path) { 44 const base::FilePath& path) {
45 return ExternalMountPoints::GetSystemInstance()->CreateCrackedFileSystemURL( 45 return ExternalMountPoints::GetSystemInstance()->CreateCrackedFileSystemURL(
46 origin, type, path); 46 origin, type, path);
47 } 47 }
48 48
49 std::string NormalizedUTF8Path(const FilePath& path) { 49 std::string NormalizedUTF8Path(const base::FilePath& path) {
50 return path.NormalizePathSeparators().AsUTF8Unsafe(); 50 return path.NormalizePathSeparators().AsUTF8Unsafe();
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 TEST(FileSystemURLTest, ParsePersistent) { 55 TEST(FileSystemURLTest, ParsePersistent) {
56 FileSystemURL url = CreateFileSystemURL( 56 FileSystemURL url = CreateFileSystemURL(
57 "filesystem:http://chromium.org/persistent/directory/file"); 57 "filesystem:http://chromium.org/persistent/directory/file");
58 ASSERT_TRUE(url.is_valid()); 58 ASSERT_TRUE(url.is_valid());
59 EXPECT_EQ("http://chromium.org/", url.origin().spec()); 59 EXPECT_EQ("http://chromium.org/", url.origin().spec());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 const FileSystemURL a = CreateFileSystemURL( 133 const FileSystemURL a = CreateFileSystemURL(
134 "filesystem:http://chromium.org/temporary/dir a/file a"); 134 "filesystem:http://chromium.org/temporary/dir a/file a");
135 const FileSystemURL b = CreateFileSystemURL( 135 const FileSystemURL b = CreateFileSystemURL(
136 "filesystem:http://chromium.org/persistent/dir a/file a"); 136 "filesystem:http://chromium.org/persistent/dir a/file a");
137 EXPECT_EQ(a.type() < b.type(), compare(a, b)); 137 EXPECT_EQ(a.type() < b.type(), compare(a, b));
138 EXPECT_EQ(b.type() < a.type(), compare(b, a)); 138 EXPECT_EQ(b.type() < a.type(), compare(b, a));
139 } 139 }
140 140
141 TEST(FileSystemURLTest, WithPath) { 141 TEST(FileSystemURLTest, WithPath) {
142 const GURL kURL("filesystem:http://chromium.org/temporary/dir"); 142 const GURL kURL("filesystem:http://chromium.org/temporary/dir");
143 const FilePath::StringType paths[] = { 143 const base::FilePath::StringType paths[] = {
144 FPL("dir a"), 144 FPL("dir a"),
145 FPL("dir a/file 1"), 145 FPL("dir a/file 1"),
146 FPL("dir a/dir b"), 146 FPL("dir a/dir b"),
147 FPL("dir a/dir b/file 2"), 147 FPL("dir a/dir b/file 2"),
148 }; 148 };
149 149
150 const FileSystemURL base = FileSystemURL::CreateForTest(kURL); 150 const FileSystemURL base = FileSystemURL::CreateForTest(kURL);
151 for (size_t i = 0; i < arraysize(paths); ++i) { 151 for (size_t i = 0; i < arraysize(paths); ++i) {
152 const FileSystemURL url = base.WithPath(FilePath(paths[i])); 152 const FileSystemURL url = base.WithPath(base::FilePath(paths[i]));
153 EXPECT_EQ(paths[i], url.path().value()); 153 EXPECT_EQ(paths[i], url.path().value());
154 EXPECT_EQ(base.origin().spec(), url.origin().spec()); 154 EXPECT_EQ(base.origin().spec(), url.origin().spec());
155 EXPECT_EQ(base.type(), url.type()); 155 EXPECT_EQ(base.type(), url.type());
156 EXPECT_EQ(base.mount_type(), url.mount_type()); 156 EXPECT_EQ(base.mount_type(), url.mount_type());
157 EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); 157 EXPECT_EQ(base.filesystem_id(), url.filesystem_id());
158 } 158 }
159 } 159 }
160 160
161 TEST(FileSystemURLTest, WithPathForExternal) { 161 TEST(FileSystemURLTest, WithPathForExternal) {
162 const std::string kId = "foo"; 162 const std::string kId = "foo";
163 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, FilePath()); 163 ScopedExternalFileSystem scoped_fs(kId, kFileSystemTypeSyncable, base::FilePat h());
164 const FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath(); 164 const base::FilePath kVirtualRoot = scoped_fs.GetVirtualRootPath();
165 165
166 const FilePath::CharType kBasePath[] = FPL("dir"); 166 const base::FilePath::CharType kBasePath[] = FPL("dir");
167 const FilePath::StringType paths[] = { 167 const base::FilePath::StringType paths[] = {
168 FPL("dir a"), 168 FPL("dir a"),
169 FPL("dir a/file 1"), 169 FPL("dir a/file 1"),
170 FPL("dir a/dir b"), 170 FPL("dir a/dir b"),
171 FPL("dir a/dir b/file 2"), 171 FPL("dir a/dir b/file 2"),
172 }; 172 };
173 173
174 const FileSystemURL base = FileSystemURL::CreateForTest( 174 const FileSystemURL base = FileSystemURL::CreateForTest(
175 GURL("http://example.com/"), 175 GURL("http://example.com/"),
176 kFileSystemTypeExternal, 176 kFileSystemTypeExternal,
177 kVirtualRoot.Append(kBasePath)); 177 kVirtualRoot.Append(kBasePath));
178 178
179 for (size_t i = 0; i < arraysize(paths); ++i) { 179 for (size_t i = 0; i < arraysize(paths); ++i) {
180 const FileSystemURL url = base.WithPath(FilePath(paths[i])); 180 const FileSystemURL url = base.WithPath(base::FilePath(paths[i]));
181 EXPECT_EQ(paths[i], url.path().value()); 181 EXPECT_EQ(paths[i], url.path().value());
182 EXPECT_EQ(base.origin().spec(), url.origin().spec()); 182 EXPECT_EQ(base.origin().spec(), url.origin().spec());
183 EXPECT_EQ(base.type(), url.type()); 183 EXPECT_EQ(base.type(), url.type());
184 EXPECT_EQ(base.mount_type(), url.mount_type()); 184 EXPECT_EQ(base.mount_type(), url.mount_type());
185 EXPECT_EQ(base.filesystem_id(), url.filesystem_id()); 185 EXPECT_EQ(base.filesystem_id(), url.filesystem_id());
186 } 186 }
187 } 187 }
188 188
189 TEST(FileSystemURLTest, IsParent) { 189 TEST(FileSystemURLTest, IsParent) {
190 ScopedExternalFileSystem scoped1("foo", kFileSystemTypeSyncable, FilePath()); 190 ScopedExternalFileSystem scoped1("foo", kFileSystemTypeSyncable, base::FilePat h());
191 ScopedExternalFileSystem scoped2("bar", kFileSystemTypeSyncable, FilePath()); 191 ScopedExternalFileSystem scoped2("bar", kFileSystemTypeSyncable, base::FilePat h());
192 192
193 const std::string root1 = GetFileSystemRootURI( 193 const std::string root1 = GetFileSystemRootURI(
194 GURL("http://example.com"), kFileSystemTypeTemporary).spec(); 194 GURL("http://example.com"), kFileSystemTypeTemporary).spec();
195 const std::string root2 = GetSyncableFileSystemRootURI( 195 const std::string root2 = GetSyncableFileSystemRootURI(
196 GURL("http://example.com"), "foo").spec(); 196 GURL("http://example.com"), "foo").spec();
197 const std::string root3 = GetSyncableFileSystemRootURI( 197 const std::string root3 = GetSyncableFileSystemRootURI(
198 GURL("http://example.com"), "bar").spec(); 198 GURL("http://example.com"), "bar").spec();
199 const std::string root4 = GetFileSystemRootURI( 199 const std::string root4 = GetFileSystemRootURI(
200 GURL("http://chromium.org"), kFileSystemTypeTemporary).spec(); 200 GURL("http://chromium.org"), kFileSystemTypeTemporary).spec();
201 201
(...skipping 23 matching lines...) Expand all
225 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( 225 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
226 CreateFileSystemURL(root3 + child))); 226 CreateFileSystemURL(root3 + child)));
227 227
228 // False case: different origins. 228 // False case: different origins.
229 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent( 229 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
230 CreateFileSystemURL(root4 + child))); 230 CreateFileSystemURL(root4 + child)));
231 } 231 }
232 232
233 TEST(FileSystemURLTest, DebugString) { 233 TEST(FileSystemURLTest, DebugString) {
234 const GURL kOrigin("http://example.com"); 234 const GURL kOrigin("http://example.com");
235 const FilePath kPath(FPL("dir/file")); 235 const base::FilePath kPath(FPL("dir/file"));
236 236
237 const FileSystemURL kURL1 = FileSystemURL::CreateForTest( 237 const FileSystemURL kURL1 = FileSystemURL::CreateForTest(
238 kOrigin, kFileSystemTypeTemporary, kPath); 238 kOrigin, kFileSystemTypeTemporary, kPath);
239 EXPECT_EQ("filesystem:http://example.com/temporary/" + 239 EXPECT_EQ("filesystem:http://example.com/temporary/" +
240 NormalizedUTF8Path(kPath), 240 NormalizedUTF8Path(kPath),
241 kURL1.DebugString()); 241 kURL1.DebugString());
242 242
243 const FilePath kRoot(DRIVE FPL("/root")); 243 const base::FilePath kRoot(DRIVE FPL("/root"));
244 ScopedExternalFileSystem scoped_fs("foo", 244 ScopedExternalFileSystem scoped_fs("foo",
245 kFileSystemTypeNativeLocal, 245 kFileSystemTypeNativeLocal,
246 kRoot.NormalizePathSeparators()); 246 kRoot.NormalizePathSeparators());
247 const FileSystemURL kURL2(CreateExternalFileSystemURL( 247 const FileSystemURL kURL2(CreateExternalFileSystemURL(
248 kOrigin, 248 kOrigin,
249 kFileSystemTypeExternal, 249 kFileSystemTypeExternal,
250 scoped_fs.GetVirtualRootPath().Append(kPath))); 250 scoped_fs.GetVirtualRootPath().Append(kPath)));
251 EXPECT_EQ("filesystem:http://example.com/external/" + 251 EXPECT_EQ("filesystem:http://example.com/external/" +
252 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) + 252 NormalizedUTF8Path(scoped_fs.GetVirtualRootPath().Append(kPath)) +
253 " (NativeLocal@foo:" + 253 " (NativeLocal@foo:" +
254 NormalizedUTF8Path(kRoot.Append(kPath)) + ")", 254 NormalizedUTF8Path(kRoot.Append(kPath)) + ")",
255 kURL2.DebugString()); 255 kURL2.DebugString());
256 } 256 }
257 257
258 } // namespace fileapi 258 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job_unittest.cc ('k') | webkit/fileapi/file_system_usage_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698