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

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

Issue 15859007: Move browser-specific FileAPI code from webkit/fileapi to webkit/browser/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dump_file_system build fix Created 7 years, 7 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
« no previous file with comments | « webkit/fileapi/file_system_url.cc ('k') | webkit/fileapi/file_system_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/fileapi/file_system_url.h"
6
7 #include "base/files/file_path.h"
8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/fileapi/file_system_types.h"
11 #include "webkit/fileapi/file_system_util.h"
12 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
13
14 #define FPL FILE_PATH_LITERAL
15
16 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
17 #define DRIVE FPL("C:")
18 #else
19 #define DRIVE FPL("/a/")
20 #endif
21
22 namespace fileapi {
23
24 namespace {
25
26 FileSystemURL CreateFileSystemURL(const std::string& url_string) {
27 FileSystemURL url = FileSystemURL::CreateForTest(GURL(url_string));
28 EXPECT_TRUE(url.type() != kFileSystemTypeExternal &&
29 url.type() != kFileSystemTypeIsolated);
30 return url;
31 }
32
33 std::string NormalizedUTF8Path(const base::FilePath& path) {
34 return path.NormalizePathSeparators().AsUTF8Unsafe();
35 }
36
37 } // namespace
38
39 TEST(FileSystemURLTest, ParsePersistent) {
40 FileSystemURL url = CreateFileSystemURL(
41 "filesystem:http://chromium.org/persistent/directory/file");
42 ASSERT_TRUE(url.is_valid());
43 EXPECT_EQ("http://chromium.org/", url.origin().spec());
44 EXPECT_EQ(kFileSystemTypePersistent, url.type());
45 EXPECT_EQ(FPL("file"), VirtualPath::BaseName(url.path()).value());
46 EXPECT_EQ(FPL("directory"), url.path().DirName().value());
47 }
48
49 TEST(FileSystemURLTest, ParseTemporary) {
50 FileSystemURL url = CreateFileSystemURL(
51 "filesystem:http://chromium.org/temporary/directory/file");
52 ASSERT_TRUE(url.is_valid());
53 EXPECT_EQ("http://chromium.org/", url.origin().spec());
54 EXPECT_EQ(kFileSystemTypeTemporary, url.type());
55 EXPECT_EQ(FPL("file"), VirtualPath::BaseName(url.path()).value());
56 EXPECT_EQ(FPL("directory"), url.path().DirName().value());
57 }
58
59 TEST(FileSystemURLTest, EnsureFilePathIsRelative) {
60 FileSystemURL url = CreateFileSystemURL(
61 "filesystem:http://chromium.org/temporary/////directory/file");
62 ASSERT_TRUE(url.is_valid());
63 EXPECT_EQ("http://chromium.org/", url.origin().spec());
64 EXPECT_EQ(kFileSystemTypeTemporary, url.type());
65 EXPECT_EQ(FPL("file"), VirtualPath::BaseName(url.path()).value());
66 EXPECT_EQ(FPL("directory"), url.path().DirName().value());
67 EXPECT_FALSE(url.path().IsAbsolute());
68 }
69
70 TEST(FileSystemURLTest, RejectBadSchemes) {
71 EXPECT_FALSE(CreateFileSystemURL("http://chromium.org/").is_valid());
72 EXPECT_FALSE(CreateFileSystemURL("https://chromium.org/").is_valid());
73 EXPECT_FALSE(CreateFileSystemURL("file:///foo/bar").is_valid());
74 EXPECT_FALSE(CreateFileSystemURL("foobar:///foo/bar").is_valid());
75 }
76
77 TEST(FileSystemURLTest, UnescapePath) {
78 FileSystemURL url = CreateFileSystemURL(
79 "filesystem:http://chromium.org/persistent/%7Echromium/space%20bar");
80 ASSERT_TRUE(url.is_valid());
81 EXPECT_EQ(FPL("space bar"), VirtualPath::BaseName(url.path()).value());
82 EXPECT_EQ(FPL("~chromium"), url.path().DirName().value());
83 }
84
85 TEST(FileSystemURLTest, RejectBadType) {
86 EXPECT_FALSE(CreateFileSystemURL(
87 "filesystem:http://c.org/foobar/file").is_valid());
88 }
89
90 TEST(FileSystemURLTest, RejectMalformedURL) {
91 EXPECT_FALSE(CreateFileSystemURL("filesystem:///foobar/file").is_valid());
92 EXPECT_FALSE(CreateFileSystemURL("filesystem:foobar/file").is_valid());
93 }
94
95 TEST(FileSystemURLTest, CompareURLs) {
96 const GURL urls[] = {
97 GURL("filesystem:http://chromium.org/temporary/dir a/file a"),
98 GURL("filesystem:http://chromium.org/temporary/dir a/file a"),
99 GURL("filesystem:http://chromium.org/temporary/dir a/file b"),
100 GURL("filesystem:http://chromium.org/temporary/dir a/file aa"),
101 GURL("filesystem:http://chromium.org/temporary/dir b/file a"),
102 GURL("filesystem:http://chromium.org/temporary/dir aa/file b"),
103 GURL("filesystem:http://chromium.com/temporary/dir a/file a"),
104 GURL("filesystem:https://chromium.org/temporary/dir a/file a")
105 };
106
107 FileSystemURL::Comparator compare;
108 for (size_t i = 0; i < arraysize(urls); ++i) {
109 for (size_t j = 0; j < arraysize(urls); ++j) {
110 SCOPED_TRACE(testing::Message() << i << " < " << j);
111 EXPECT_EQ(urls[i] < urls[j],
112 compare(FileSystemURL::CreateForTest(urls[i]),
113 FileSystemURL::CreateForTest(urls[j])));
114 }
115 }
116
117 const FileSystemURL a = CreateFileSystemURL(
118 "filesystem:http://chromium.org/temporary/dir a/file a");
119 const FileSystemURL b = CreateFileSystemURL(
120 "filesystem:http://chromium.org/persistent/dir a/file a");
121 EXPECT_EQ(a.type() < b.type(), compare(a, b));
122 EXPECT_EQ(b.type() < a.type(), compare(b, a));
123 }
124
125 TEST(FileSystemURLTest, IsParent) {
126 const std::string root1 = GetFileSystemRootURI(
127 GURL("http://example.com"), kFileSystemTypeTemporary).spec();
128 const std::string root2 = GetFileSystemRootURI(
129 GURL("http://example.com"), kFileSystemTypePersistent).spec();
130 const std::string root3 = GetFileSystemRootURI(
131 GURL("http://chromium.org"), kFileSystemTypeTemporary).spec();
132
133 const std::string parent("dir");
134 const std::string child("dir/child");
135 const std::string other("other");
136
137 // True cases.
138 EXPECT_TRUE(CreateFileSystemURL(root1 + parent).IsParent(
139 CreateFileSystemURL(root1 + child)));
140 EXPECT_TRUE(CreateFileSystemURL(root2 + parent).IsParent(
141 CreateFileSystemURL(root2 + child)));
142
143 // False cases: the path is not a child.
144 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
145 CreateFileSystemURL(root1 + other)));
146 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
147 CreateFileSystemURL(root1 + parent)));
148 EXPECT_FALSE(CreateFileSystemURL(root1 + child).IsParent(
149 CreateFileSystemURL(root1 + parent)));
150
151 // False case: different types.
152 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
153 CreateFileSystemURL(root2 + child)));
154
155 // False case: different origins.
156 EXPECT_FALSE(CreateFileSystemURL(root1 + parent).IsParent(
157 CreateFileSystemURL(root3 + child)));
158 }
159
160 TEST(FileSystemURLTest, DebugString) {
161 const GURL kOrigin("http://example.com");
162 const base::FilePath kPath(FPL("dir/file"));
163
164 const FileSystemURL kURL1 = FileSystemURL::CreateForTest(
165 kOrigin, kFileSystemTypeTemporary, kPath);
166 EXPECT_EQ("filesystem:http://example.com/temporary/" +
167 NormalizedUTF8Path(kPath),
168 kURL1.DebugString());
169 }
170
171 TEST(FileSystemURLTest, IsInSameFileSystem) {
172 FileSystemURL url_foo_temp_a = FileSystemURL::CreateForTest(
173 GURL("http://foo"), kFileSystemTypeTemporary,
174 base::FilePath::FromUTF8Unsafe("a"));
175 FileSystemURL url_foo_temp_b = FileSystemURL::CreateForTest(
176 GURL("http://foo"), kFileSystemTypeTemporary,
177 base::FilePath::FromUTF8Unsafe("b"));
178 FileSystemURL url_foo_perm_a = FileSystemURL::CreateForTest(
179 GURL("http://foo"), kFileSystemTypePersistent,
180 base::FilePath::FromUTF8Unsafe("a"));
181 FileSystemURL url_bar_temp_a = FileSystemURL::CreateForTest(
182 GURL("http://bar"), kFileSystemTypeTemporary,
183 base::FilePath::FromUTF8Unsafe("a"));
184 FileSystemURL url_bar_perm_a = FileSystemURL::CreateForTest(
185 GURL("http://bar"), kFileSystemTypePersistent,
186 base::FilePath::FromUTF8Unsafe("a"));
187
188 EXPECT_TRUE(url_foo_temp_a.IsInSameFileSystem(url_foo_temp_a));
189 EXPECT_TRUE(url_foo_temp_a.IsInSameFileSystem(url_foo_temp_b));
190 EXPECT_FALSE(url_foo_temp_a.IsInSameFileSystem(url_foo_perm_a));
191 EXPECT_FALSE(url_foo_temp_a.IsInSameFileSystem(url_bar_temp_a));
192 EXPECT_FALSE(url_foo_temp_a.IsInSameFileSystem(url_bar_perm_a));
193 }
194
195 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url.cc ('k') | webkit/fileapi/file_system_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698