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

Side by Side Diff: webkit/fileapi/file_system_context_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) 2013 The Chromium Authors. All rights reserved. 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 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_context.h" 5 #include "webkit/fileapi/file_system_context.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 10 matching lines...) Expand all
21 #define DRIVE FPL("C:") 21 #define DRIVE FPL("C:")
22 #else 22 #else
23 #define DRIVE 23 #define DRIVE
24 #endif 24 #endif
25 25
26 namespace fileapi { 26 namespace fileapi {
27 27
28 namespace { 28 namespace {
29 29
30 const char kTestOrigin[] = "http://chromium.org/"; 30 const char kTestOrigin[] = "http://chromium.org/";
31 const FilePath::CharType kVirtualPathNoRoot[] = FPL("root/file"); 31 const base::FilePath::CharType kVirtualPathNoRoot[] = FPL("root/file");
32 32
33 GURL CreateRawFileSystemURL(const std::string& type_str, 33 GURL CreateRawFileSystemURL(const std::string& type_str,
34 const std::string& fs_id) { 34 const std::string& fs_id) {
35 std::string url_str = base::StringPrintf( 35 std::string url_str = base::StringPrintf(
36 "filesystem:http://chromium.org/%s/%s/root/file", 36 "filesystem:http://chromium.org/%s/%s/root/file",
37 type_str.c_str(), 37 type_str.c_str(),
38 fs_id.c_str()); 38 fs_id.c_str());
39 return GURL(url_str); 39 return GURL(url_str);
40 } 40 }
41 41
(...skipping 24 matching lines...) Expand all
66 mock_quota_manager_->proxy(), 66 mock_quota_manager_->proxy(),
67 data_dir_.path(), 67 data_dir_.path(),
68 CreateAllowFileAccessOptions()); 68 CreateAllowFileAccessOptions());
69 } 69 }
70 70
71 // Verifies a *valid* filesystem url has expected values. 71 // Verifies a *valid* filesystem url has expected values.
72 void ExpectFileSystemURLMatches(const FileSystemURL& url, 72 void ExpectFileSystemURLMatches(const FileSystemURL& url,
73 const GURL& expect_origin, 73 const GURL& expect_origin,
74 FileSystemType expect_mount_type, 74 FileSystemType expect_mount_type,
75 FileSystemType expect_type, 75 FileSystemType expect_type,
76 const FilePath& expect_path, 76 const base::FilePath& expect_path,
77 const FilePath& expect_virtual_path, 77 const base::FilePath& expect_virtual_path,
78 const std::string& expect_filesystem_id) { 78 const std::string& expect_filesystem_id) {
79 EXPECT_TRUE(url.is_valid()); 79 EXPECT_TRUE(url.is_valid());
80 80
81 EXPECT_EQ(expect_origin, url.origin()); 81 EXPECT_EQ(expect_origin, url.origin());
82 EXPECT_EQ(expect_mount_type, url.mount_type()); 82 EXPECT_EQ(expect_mount_type, url.mount_type());
83 EXPECT_EQ(expect_type, url.type()); 83 EXPECT_EQ(expect_type, url.type());
84 EXPECT_EQ(expect_path, url.path()); 84 EXPECT_EQ(expect_path, url.path());
85 EXPECT_EQ(expect_virtual_path, url.virtual_path()); 85 EXPECT_EQ(expect_virtual_path, url.virtual_path());
86 EXPECT_EQ(expect_filesystem_id, url.filesystem_id()); 86 EXPECT_EQ(expect_filesystem_id, url.filesystem_id());
87 } 87 }
(...skipping 10 matching lines...) Expand all
98 #if !defined(OS_CHROMEOS) 98 #if !defined(OS_CHROMEOS)
99 TEST_F(FileSystemContextTest, NullExternalMountPoints) { 99 TEST_F(FileSystemContextTest, NullExternalMountPoints) {
100 scoped_refptr<FileSystemContext> file_system_context( 100 scoped_refptr<FileSystemContext> file_system_context(
101 CreateFileSystemContextForTest(NULL)); 101 CreateFileSystemContextForTest(NULL));
102 102
103 // Cracking system external mount and isolated mount points should work. 103 // Cracking system external mount and isolated mount points should work.
104 std::string isolated_name = "root"; 104 std::string isolated_name = "root";
105 std::string isolated_id = 105 std::string isolated_id =
106 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 106 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
107 kFileSystemTypeNativeLocal, 107 kFileSystemTypeNativeLocal,
108 FilePath(DRIVE FPL("/test/isolated/root")), 108 base::FilePath(DRIVE FPL("/test/isolated/root")),
109 &isolated_name); 109 &isolated_name);
110 // Register system external mount point. 110 // Register system external mount point.
111 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 111 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
112 "system", 112 "system",
113 kFileSystemTypeNativeLocal, 113 kFileSystemTypeNativeLocal,
114 FilePath(DRIVE FPL("/test/sys/")))); 114 base::FilePath(DRIVE FPL("/test/sys/"))));
115 115
116 FileSystemURL cracked_isolated = file_system_context->CrackURL( 116 FileSystemURL cracked_isolated = file_system_context->CrackURL(
117 CreateRawFileSystemURL("isolated", isolated_id)); 117 CreateRawFileSystemURL("isolated", isolated_id));
118 118
119 ExpectFileSystemURLMatches( 119 ExpectFileSystemURLMatches(
120 cracked_isolated, 120 cracked_isolated,
121 GURL(kTestOrigin), 121 GURL(kTestOrigin),
122 kFileSystemTypeIsolated, 122 kFileSystemTypeIsolated,
123 kFileSystemTypeNativeLocal, 123 kFileSystemTypeNativeLocal,
124 FilePath(DRIVE FPL("/test/isolated/root/file")).NormalizePathSeparators(), 124 base::FilePath(DRIVE FPL("/test/isolated/root/file")).NormalizePathSeparat ors(),
125 FilePath::FromUTF8Unsafe(isolated_id).Append(FPL("root/file")). 125 base::FilePath::FromUTF8Unsafe(isolated_id).Append(FPL("root/file")).
126 NormalizePathSeparators(), 126 NormalizePathSeparators(),
127 isolated_id); 127 isolated_id);
128 128
129 FileSystemURL cracked_external = file_system_context->CrackURL( 129 FileSystemURL cracked_external = file_system_context->CrackURL(
130 CreateRawFileSystemURL("external", "system")); 130 CreateRawFileSystemURL("external", "system"));
131 131
132 ExpectFileSystemURLMatches( 132 ExpectFileSystemURLMatches(
133 cracked_external, 133 cracked_external,
134 GURL(kTestOrigin), 134 GURL(kTestOrigin),
135 kFileSystemTypeExternal, 135 kFileSystemTypeExternal,
136 kFileSystemTypeNativeLocal, 136 kFileSystemTypeNativeLocal,
137 FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), 137 base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators() ,
138 FilePath(FPL("system/root/file")).NormalizePathSeparators(), 138 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(),
139 "system"); 139 "system");
140 140
141 141
142 IsolatedContext::GetInstance()->RevokeFileSystem(isolated_id); 142 IsolatedContext::GetInstance()->RevokeFileSystem(isolated_id);
143 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system"); 143 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
144 } 144 }
145 #endif // !defiend(OS_CHROMEOS) 145 #endif // !defiend(OS_CHROMEOS)
146 146
147 TEST_F(FileSystemContextTest, FileSystemContextKeepsMountPointsAlive) { 147 TEST_F(FileSystemContextTest, FileSystemContextKeepsMountPointsAlive) {
148 scoped_refptr<ExternalMountPoints> mount_points = 148 scoped_refptr<ExternalMountPoints> mount_points =
149 ExternalMountPoints::CreateRefCounted(); 149 ExternalMountPoints::CreateRefCounted();
150 150
151 // Register system external mount point. 151 // Register system external mount point.
152 ASSERT_TRUE(mount_points->RegisterFileSystem( 152 ASSERT_TRUE(mount_points->RegisterFileSystem(
153 "system", 153 "system",
154 kFileSystemTypeNativeLocal, 154 kFileSystemTypeNativeLocal,
155 FilePath(DRIVE FPL("/test/sys/")))); 155 base::FilePath(DRIVE FPL("/test/sys/"))));
156 156
157 scoped_refptr<FileSystemContext> file_system_context( 157 scoped_refptr<FileSystemContext> file_system_context(
158 CreateFileSystemContextForTest(mount_points.get())); 158 CreateFileSystemContextForTest(mount_points.get()));
159 159
160 // Release a MountPoints reference created in the test. 160 // Release a MountPoints reference created in the test.
161 mount_points = NULL; 161 mount_points = NULL;
162 162
163 // FileSystemContext should keep a reference to the |mount_points|, so it 163 // FileSystemContext should keep a reference to the |mount_points|, so it
164 // should be able to resolve the URL. 164 // should be able to resolve the URL.
165 FileSystemURL cracked_external = file_system_context->CrackURL( 165 FileSystemURL cracked_external = file_system_context->CrackURL(
166 CreateRawFileSystemURL("external", "system")); 166 CreateRawFileSystemURL("external", "system"));
167 167
168 ExpectFileSystemURLMatches( 168 ExpectFileSystemURLMatches(
169 cracked_external, 169 cracked_external,
170 GURL(kTestOrigin), 170 GURL(kTestOrigin),
171 kFileSystemTypeExternal, 171 kFileSystemTypeExternal,
172 kFileSystemTypeNativeLocal, 172 kFileSystemTypeNativeLocal,
173 FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators(), 173 base::FilePath(DRIVE FPL("/test/sys/root/file")).NormalizePathSeparators() ,
174 FilePath(FPL("system/root/file")).NormalizePathSeparators(), 174 base::FilePath(FPL("system/root/file")).NormalizePathSeparators(),
175 "system"); 175 "system");
176 176
177 // No need to revoke the registered filesystem since |mount_points| lifetime 177 // No need to revoke the registered filesystem since |mount_points| lifetime
178 // is bound to this test. 178 // is bound to this test.
179 } 179 }
180 180
181 TEST_F(FileSystemContextTest, CrackFileSystemURL) { 181 TEST_F(FileSystemContextTest, CrackFileSystemURL) {
182 scoped_refptr<ExternalMountPoints> external_mount_points( 182 scoped_refptr<ExternalMountPoints> external_mount_points(
183 ExternalMountPoints::CreateRefCounted()); 183 ExternalMountPoints::CreateRefCounted());
184 scoped_refptr<FileSystemContext> file_system_context( 184 scoped_refptr<FileSystemContext> file_system_context(
185 CreateFileSystemContextForTest(external_mount_points)); 185 CreateFileSystemContextForTest(external_mount_points));
186 186
187 // Register an isolated mount point. 187 // Register an isolated mount point.
188 std::string isolated_file_system_name = "root"; 188 std::string isolated_file_system_name = "root";
189 const std::string kIsolatedFileSystemID = 189 const std::string kIsolatedFileSystemID =
190 IsolatedContext::GetInstance()->RegisterFileSystemForPath( 190 IsolatedContext::GetInstance()->RegisterFileSystemForPath(
191 kFileSystemTypeNativeLocal, 191 kFileSystemTypeNativeLocal,
192 FilePath(DRIVE FPL("/test/isolated/root")), 192 base::FilePath(DRIVE FPL("/test/isolated/root")),
193 &isolated_file_system_name); 193 &isolated_file_system_name);
194 // Register system external mount point. 194 // Register system external mount point.
195 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 195 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
196 "system", 196 "system",
197 kFileSystemTypeDrive, 197 kFileSystemTypeDrive,
198 FilePath(DRIVE FPL("/test/sys/")))); 198 base::FilePath(DRIVE FPL("/test/sys/"))));
199 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 199 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
200 "ext", 200 "ext",
201 kFileSystemTypeNativeLocal, 201 kFileSystemTypeNativeLocal,
202 FilePath(DRIVE FPL("/test/ext")))); 202 base::FilePath(DRIVE FPL("/test/ext"))));
203 // Register a system external mount point with the same name/id as the 203 // Register a system external mount point with the same name/id as the
204 // registered isolated mount point. 204 // registered isolated mount point.
205 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 205 ASSERT_TRUE(ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
206 kIsolatedFileSystemID, 206 kIsolatedFileSystemID,
207 kFileSystemTypeRestrictedNativeLocal, 207 kFileSystemTypeRestrictedNativeLocal,
208 FilePath(DRIVE FPL("/test/system/isolated")))); 208 base::FilePath(DRIVE FPL("/test/system/isolated"))));
209 // Add a mount points with the same name as a system mount point to 209 // Add a mount points with the same name as a system mount point to
210 // FileSystemContext's external mount points. 210 // FileSystemContext's external mount points.
211 ASSERT_TRUE(external_mount_points->RegisterFileSystem( 211 ASSERT_TRUE(external_mount_points->RegisterFileSystem(
212 "ext", 212 "ext",
213 kFileSystemTypeNativeLocal, 213 kFileSystemTypeNativeLocal,
214 FilePath(DRIVE FPL("/test/local/ext/")))); 214 base::FilePath(DRIVE FPL("/test/local/ext/"))));
215 215
216 const GURL kTestOrigin = GURL("http://chromium.org/"); 216 const GURL kTestOrigin = GURL("http://chromium.org/");
217 const FilePath kVirtualPathNoRoot = FilePath(FPL("root/file")); 217 const base::FilePath kVirtualPathNoRoot = base::FilePath(FPL("root/file"));
218 218
219 struct TestCase { 219 struct TestCase {
220 // Test case values. 220 // Test case values.
221 std::string root; 221 std::string root;
222 std::string type_str; 222 std::string type_str;
223 223
224 // Expected test results. 224 // Expected test results.
225 bool expect_is_valid; 225 bool expect_is_valid;
226 FileSystemType expect_mount_type; 226 FileSystemType expect_mount_type;
227 FileSystemType expect_type; 227 FileSystemType expect_type;
228 const FilePath::CharType* expect_path; 228 const base::FilePath::CharType* expect_path;
229 bool expect_virtual_path_empty; 229 bool expect_virtual_path_empty;
230 std::string expect_filesystem_id; 230 std::string expect_filesystem_id;
231 }; 231 };
232 232
233 const TestCase kTestCases[] = { 233 const TestCase kTestCases[] = {
234 // Following should not be handled by the url crackers: 234 // Following should not be handled by the url crackers:
235 { 235 {
236 "pers_mount", "persistent", true /* is_valid */, 236 "pers_mount", "persistent", true /* is_valid */,
237 kFileSystemTypePersistent, kFileSystemTypePersistent, 237 kFileSystemTypePersistent, kFileSystemTypePersistent,
238 FPL("pers_mount/root/file"), true /* virtual path empty */, 238 FPL("pers_mount/root/file"), true /* virtual path empty */,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Test for URL with non-existing filesystem id. 283 // Test for URL with non-existing filesystem id.
284 { 284 {
285 "invalid", "external", false /* is_valid */, 285 "invalid", "external", false /* is_valid */,
286 // The rest of values will be ignored. 286 // The rest of values will be ignored.
287 kFileSystemTypeUnknown, kFileSystemTypeUnknown, FPL(""), true, 287 kFileSystemTypeUnknown, kFileSystemTypeUnknown, FPL(""), true,
288 std::string() 288 std::string()
289 }, 289 },
290 }; 290 };
291 291
292 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 292 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
293 const FilePath virtual_path = 293 const base::FilePath virtual_path =
294 FilePath::FromUTF8Unsafe(kTestCases[i].root).Append(kVirtualPathNoRoot); 294 base::FilePath::FromUTF8Unsafe(kTestCases[i].root).Append(kVirtualPathNo Root);
295 295
296 GURL raw_url = 296 GURL raw_url =
297 CreateRawFileSystemURL(kTestCases[i].type_str, kTestCases[i].root); 297 CreateRawFileSystemURL(kTestCases[i].type_str, kTestCases[i].root);
298 FileSystemURL cracked_url = file_system_context->CrackURL(raw_url); 298 FileSystemURL cracked_url = file_system_context->CrackURL(raw_url);
299 299
300 SCOPED_TRACE(testing::Message() << "Test case " << i << ": " 300 SCOPED_TRACE(testing::Message() << "Test case " << i << ": "
301 << "Cracking URL: " << raw_url); 301 << "Cracking URL: " << raw_url);
302 302
303 EXPECT_EQ(kTestCases[i].expect_is_valid, cracked_url.is_valid()); 303 EXPECT_EQ(kTestCases[i].expect_is_valid, cracked_url.is_valid());
304 if (!kTestCases[i].expect_is_valid) 304 if (!kTestCases[i].expect_is_valid)
305 continue; 305 continue;
306 306
307 ExpectFileSystemURLMatches( 307 ExpectFileSystemURLMatches(
308 cracked_url, 308 cracked_url,
309 GURL(kTestOrigin), 309 GURL(kTestOrigin),
310 kTestCases[i].expect_mount_type, 310 kTestCases[i].expect_mount_type,
311 kTestCases[i].expect_type, 311 kTestCases[i].expect_type,
312 FilePath(kTestCases[i].expect_path).NormalizePathSeparators(), 312 base::FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
313 kTestCases[i].expect_virtual_path_empty ? 313 kTestCases[i].expect_virtual_path_empty ?
314 FilePath() : virtual_path.NormalizePathSeparators(), 314 base::FilePath() : virtual_path.NormalizePathSeparators(),
315 kTestCases[i].expect_filesystem_id); 315 kTestCases[i].expect_filesystem_id);
316 } 316 }
317 317
318 IsolatedContext::GetInstance()->RevokeFileSystemByPath( 318 IsolatedContext::GetInstance()->RevokeFileSystemByPath(
319 FilePath(DRIVE FPL("/test/isolated/root"))); 319 base::FilePath(DRIVE FPL("/test/isolated/root")));
320 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system"); 320 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("system");
321 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("ext"); 321 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem("ext");
322 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 322 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(
323 kIsolatedFileSystemID); 323 kIsolatedFileSystemID);
324 } 324 }
325 325
326 } // namespace 326 } // namespace
327 327
328 } // namespace fileapi 328 } // namespace fileapi
329 329
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_context.cc ('k') | webkit/fileapi/file_system_database_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698