OLD | NEW |
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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 void TearDown() { | 128 void TearDown() { |
129 isolated_context()->RemoveReference(filesystem_id_); | 129 isolated_context()->RemoveReference(filesystem_id_); |
130 file_system_context_ = NULL; | 130 file_system_context_ = NULL; |
131 } | 131 } |
132 | 132 |
133 protected: | 133 protected: |
134 FileSystemContext* file_system_context() { | 134 FileSystemContext* file_system_context() { |
135 return file_system_context_.get(); | 135 return file_system_context_.get(); |
136 } | 136 } |
137 | 137 |
| 138 FileSystemURL CreateURL(const FilePath::CharType* test_case_path) { |
| 139 return file_system_context_->CreateCrackedFileSystemURL( |
| 140 origin(), |
| 141 fileapi::kFileSystemTypeIsolated, |
| 142 GetVirtualPath(test_case_path)); |
| 143 } |
| 144 |
138 IsolatedContext* isolated_context() { | 145 IsolatedContext* isolated_context() { |
139 return IsolatedContext::GetInstance(); | 146 return IsolatedContext::GetInstance(); |
140 } | 147 } |
141 | 148 |
142 FilePath root_path() { | 149 FilePath root_path() { |
143 return data_dir_.path().Append(FPL("Media Directory")); | 150 return data_dir_.path().Append(FPL("Media Directory")); |
144 } | 151 } |
145 | 152 |
| 153 FilePath GetVirtualPath(const FilePath::CharType* test_case_path) { |
| 154 return FilePath::FromUTF8Unsafe(filesystem_id_). |
| 155 Append(FPL("Media Directory")). |
| 156 Append(FilePath(test_case_path)); |
| 157 } |
| 158 |
146 FileSystemFileUtil* file_util() { | 159 FileSystemFileUtil* file_util() { |
147 return file_util_; | 160 return file_util_; |
148 } | 161 } |
149 | 162 |
150 GURL origin() { | 163 GURL origin() { |
151 return GURL("http://example.com"); | 164 return GURL("http://example.com"); |
152 } | 165 } |
153 | 166 |
154 fileapi::FileSystemType type() { | 167 fileapi::FileSystemType type() { |
155 return kFileSystemTypeNativeMedia; | 168 return kFileSystemTypeNativeMedia; |
(...skipping 14 matching lines...) Expand all Loading... |
170 | 183 |
171 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); | 184 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtilTest); |
172 }; | 185 }; |
173 | 186 |
174 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { | 187 TEST_F(NativeMediaFileUtilTest, DirectoryExistsAndFileExistsFiltering) { |
175 PopulateDirectoryWithTestCases(root_path(), | 188 PopulateDirectoryWithTestCases(root_path(), |
176 kFilteringTestCases, | 189 kFilteringTestCases, |
177 arraysize(kFilteringTestCases)); | 190 arraysize(kFilteringTestCases)); |
178 | 191 |
179 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 192 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
180 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 193 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
181 FileSystemURL url(origin(), type(), path); | |
182 FileSystemOperation* operation = NewOperation(url); | 194 FileSystemOperation* operation = NewOperation(url); |
183 | 195 |
184 base::PlatformFileError expectation = | 196 base::PlatformFileError expectation = |
185 kFilteringTestCases[i].visible ? | 197 kFilteringTestCases[i].visible ? |
186 base::PLATFORM_FILE_OK : | 198 base::PLATFORM_FILE_OK : |
187 base::PLATFORM_FILE_ERROR_NOT_FOUND; | 199 base::PLATFORM_FILE_ERROR_NOT_FOUND; |
188 | 200 |
189 std::string test_name = | 201 std::string test_name = |
190 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); | 202 base::StringPrintf("DirectoryExistsAndFileExistsFiltering %" PRIuS, i); |
191 if (kFilteringTestCases[i].is_directory) { | 203 if (kFilteringTestCases[i].is_directory) { |
192 operation->DirectoryExists( | 204 operation->DirectoryExists( |
193 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 205 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
194 } else { | 206 } else { |
195 operation->FileExists( | 207 operation->FileExists( |
196 url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 208 url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
197 } | 209 } |
198 MessageLoop::current()->RunUntilIdle(); | 210 MessageLoop::current()->RunUntilIdle(); |
199 } | 211 } |
200 } | 212 } |
201 | 213 |
202 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { | 214 TEST_F(NativeMediaFileUtilTest, ReadDirectoryFiltering) { |
203 PopulateDirectoryWithTestCases(root_path(), | 215 PopulateDirectoryWithTestCases(root_path(), |
204 kFilteringTestCases, | 216 kFilteringTestCases, |
205 arraysize(kFilteringTestCases)); | 217 arraysize(kFilteringTestCases)); |
206 | 218 |
207 std::set<FilePath::StringType> content; | 219 std::set<FilePath::StringType> content; |
208 FileSystemURL url(origin(), type(), root_path()); | 220 FileSystemURL url = CreateURL(FPL("")); |
209 bool completed = false; | 221 bool completed = false; |
210 NewOperation(url)->ReadDirectory( | 222 NewOperation(url)->ReadDirectory( |
211 url, base::Bind(&DidReadDirectory, &content, &completed)); | 223 url, base::Bind(&DidReadDirectory, &content, &completed)); |
212 MessageLoop::current()->RunUntilIdle(); | 224 MessageLoop::current()->RunUntilIdle(); |
213 EXPECT_TRUE(completed); | 225 EXPECT_TRUE(completed); |
214 EXPECT_EQ(5u, content.size()); | 226 EXPECT_EQ(5u, content.size()); |
215 | 227 |
216 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 228 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
217 FilePath::StringType name = | 229 FilePath::StringType name = |
218 FilePath(kFilteringTestCases[i].path).BaseName().value(); | 230 FilePath(kFilteringTestCases[i].path).BaseName().value(); |
219 std::set<FilePath::StringType>::const_iterator found = content.find(name); | 231 std::set<FilePath::StringType>::const_iterator found = content.find(name); |
220 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); | 232 EXPECT_EQ(kFilteringTestCases[i].visible, found != content.end()); |
221 } | 233 } |
222 } | 234 } |
223 | 235 |
224 TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { | 236 TEST_F(NativeMediaFileUtilTest, CreateFileAndCreateDirectoryFiltering) { |
225 // Run the loop twice. The second loop attempts to create files that are | 237 // Run the loop twice. The second loop attempts to create files that are |
226 // pre-existing. Though the result should be the same. | 238 // pre-existing. Though the result should be the same. |
227 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 239 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
228 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 240 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
229 FileSystemURL root_url(origin(), type(), root_path()); | 241 FileSystemURL root_url = CreateURL(FPL("")); |
230 FileSystemOperation* operation = NewOperation(root_url); | 242 FileSystemOperation* operation = NewOperation(root_url); |
231 | 243 |
232 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 244 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
233 FileSystemURL url(origin(), type(), path); | |
234 | 245 |
235 std::string test_name = base::StringPrintf( | 246 std::string test_name = base::StringPrintf( |
236 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, | 247 "CreateFileAndCreateDirectoryFiltering run %d, test %" PRIuS, |
237 loop_count, i); | 248 loop_count, i); |
238 base::PlatformFileError expectation = | 249 base::PlatformFileError expectation = |
239 kFilteringTestCases[i].visible ? | 250 kFilteringTestCases[i].visible ? |
240 base::PLATFORM_FILE_OK : | 251 base::PLATFORM_FILE_OK : |
241 base::PLATFORM_FILE_ERROR_SECURITY; | 252 base::PLATFORM_FILE_ERROR_SECURITY; |
242 if (kFilteringTestCases[i].is_directory) { | 253 if (kFilteringTestCases[i].is_directory) { |
243 operation->CreateDirectory( | 254 operation->CreateDirectory( |
244 url, false, false, | 255 url, false, false, |
245 base::Bind(&ExpectEqHelper, test_name, expectation)); | 256 base::Bind(&ExpectEqHelper, test_name, expectation)); |
246 } else { | 257 } else { |
247 operation->CreateFile( | 258 operation->CreateFile( |
248 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | 259 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
249 } | 260 } |
250 MessageLoop::current()->RunUntilIdle(); | 261 MessageLoop::current()->RunUntilIdle(); |
251 } | 262 } |
252 } | 263 } |
253 } | 264 } |
254 | 265 |
255 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { | 266 TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { |
256 FilePath dest_path = root_path().AppendASCII("dest"); | 267 FilePath dest_path = root_path().AppendASCII("dest"); |
257 FileSystemURL dest_url(origin(), type(), dest_path); | 268 FileSystemURL dest_url = CreateURL(FPL("dest")); |
258 | 269 |
259 // Run the loop twice. The first run has no source files. The second run does. | 270 // Run the loop twice. The first run has no source files. The second run does. |
260 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 271 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
261 if (loop_count == 1) { | 272 if (loop_count == 1) { |
262 PopulateDirectoryWithTestCases(root_path(), | 273 PopulateDirectoryWithTestCases(root_path(), |
263 kFilteringTestCases, | 274 kFilteringTestCases, |
264 arraysize(kFilteringTestCases)); | 275 arraysize(kFilteringTestCases)); |
265 } | 276 } |
266 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 277 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
267 // Always start with an empty destination directory. | 278 // Always start with an empty destination directory. |
268 // Copying to a non-empty destination directory is an invalid operation. | 279 // Copying to a non-empty destination directory is an invalid operation. |
269 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 280 ASSERT_TRUE(file_util::Delete(dest_path, true)); |
270 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 281 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
271 | 282 |
272 FileSystemURL root_url(origin(), type(), root_path()); | 283 FileSystemURL root_url = CreateURL(FPL("")); |
273 FileSystemOperation* operation = NewOperation(root_url); | 284 FileSystemOperation* operation = NewOperation(root_url); |
274 | 285 |
275 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 286 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
276 FileSystemURL url(origin(), type(), path); | |
277 | 287 |
278 std::string test_name = base::StringPrintf( | 288 std::string test_name = base::StringPrintf( |
279 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); | 289 "CopySourceFiltering run %d test %" PRIuS, loop_count, i); |
280 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 290 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
281 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 291 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
282 // If the source does not exist or is not visible. | 292 // If the source does not exist or is not visible. |
283 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 293 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
284 } else if (!kFilteringTestCases[i].is_directory) { | 294 } else if (!kFilteringTestCases[i].is_directory) { |
285 // Cannot copy a visible file to a directory. | 295 // Cannot copy a visible file to a directory. |
286 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 296 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
(...skipping 14 matching lines...) Expand all Loading... |
301 // directories and create new ones that should pre-exist. | 311 // directories and create new ones that should pre-exist. |
302 ASSERT_TRUE(file_util::Delete(root_path(), true)); | 312 ASSERT_TRUE(file_util::Delete(root_path(), true)); |
303 ASSERT_TRUE(file_util::CreateDirectory(root_path())); | 313 ASSERT_TRUE(file_util::CreateDirectory(root_path())); |
304 PopulateDirectoryWithTestCases(root_path(), | 314 PopulateDirectoryWithTestCases(root_path(), |
305 kFilteringTestCases, | 315 kFilteringTestCases, |
306 arraysize(kFilteringTestCases)); | 316 arraysize(kFilteringTestCases)); |
307 } | 317 } |
308 | 318 |
309 // Always create a dummy source data file. | 319 // Always create a dummy source data file. |
310 FilePath src_path = root_path().AppendASCII("foo.jpg"); | 320 FilePath src_path = root_path().AppendASCII("foo.jpg"); |
311 FileSystemURL src_url(origin(), type(), src_path); | 321 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
312 static const char kDummyData[] = "dummy"; | 322 static const char kDummyData[] = "dummy"; |
313 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 323 ASSERT_TRUE(file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
314 | 324 |
315 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 325 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
316 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | 326 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
317 // These directories do not exist in this case, so Copy() will not | 327 // These directories do not exist in this case, so Copy() will not |
318 // treat them as directories. Thus invalidating these test cases. | 328 // treat them as directories. Thus invalidating these test cases. |
319 // Continue now to avoid creating a new |operation| below that goes | 329 // Continue now to avoid creating a new |operation| below that goes |
320 // unused. | 330 // unused. |
321 continue; | 331 continue; |
322 } | 332 } |
323 FileSystemURL root_url(origin(), type(), root_path()); | 333 FileSystemURL root_url = CreateURL(FPL("")); |
324 FileSystemOperation* operation = NewOperation(root_url); | 334 FileSystemOperation* operation = NewOperation(root_url); |
325 | 335 |
326 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 336 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
327 FileSystemURL url(origin(), type(), path); | |
328 | 337 |
329 std::string test_name = base::StringPrintf( | 338 std::string test_name = base::StringPrintf( |
330 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); | 339 "CopyDestFiltering run %d test %" PRIuS, loop_count, i); |
331 base::PlatformFileError expectation; | 340 base::PlatformFileError expectation; |
332 if (loop_count == 0) { | 341 if (loop_count == 0) { |
333 // The destination path is a file here. The directory case has been | 342 // The destination path is a file here. The directory case has been |
334 // handled above. | 343 // handled above. |
335 // If the destination path does not exist and is not visible, then | 344 // If the destination path does not exist and is not visible, then |
336 // creating it would be a security violation. | 345 // creating it would be a security violation. |
337 expectation = | 346 expectation = |
(...skipping 16 matching lines...) Expand all Loading... |
354 } | 363 } |
355 operation->Copy( | 364 operation->Copy( |
356 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); | 365 src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); |
357 MessageLoop::current()->RunUntilIdle(); | 366 MessageLoop::current()->RunUntilIdle(); |
358 } | 367 } |
359 } | 368 } |
360 } | 369 } |
361 | 370 |
362 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { | 371 TEST_F(NativeMediaFileUtilTest, MoveSourceFiltering) { |
363 FilePath dest_path = root_path().AppendASCII("dest"); | 372 FilePath dest_path = root_path().AppendASCII("dest"); |
364 FileSystemURL dest_url(origin(), type(), dest_path); | 373 FileSystemURL dest_url = CreateURL(FPL("dest")); |
365 | 374 |
366 // Run the loop twice. The first run has no source files. The second run does. | 375 // Run the loop twice. The first run has no source files. The second run does. |
367 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 376 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
368 if (loop_count == 1) { | 377 if (loop_count == 1) { |
369 PopulateDirectoryWithTestCases(root_path(), | 378 PopulateDirectoryWithTestCases(root_path(), |
370 kFilteringTestCases, | 379 kFilteringTestCases, |
371 arraysize(kFilteringTestCases)); | 380 arraysize(kFilteringTestCases)); |
372 } | 381 } |
373 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 382 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
374 // Always start with an empty destination directory. | 383 // Always start with an empty destination directory. |
375 // Moving to a non-empty destination directory is an invalid operation. | 384 // Moving to a non-empty destination directory is an invalid operation. |
376 ASSERT_TRUE(file_util::Delete(dest_path, true)); | 385 ASSERT_TRUE(file_util::Delete(dest_path, true)); |
377 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); | 386 ASSERT_TRUE(file_util::CreateDirectory(dest_path)); |
378 | 387 |
379 FileSystemURL root_url(origin(), type(), root_path()); | 388 FileSystemURL root_url = CreateURL(FPL("")); |
380 FileSystemOperation* operation = NewOperation(root_url); | 389 FileSystemOperation* operation = NewOperation(root_url); |
381 | 390 |
382 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 391 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
383 FileSystemURL url(origin(), type(), path); | |
384 | 392 |
385 std::string test_name = base::StringPrintf( | 393 std::string test_name = base::StringPrintf( |
386 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); | 394 "MoveSourceFiltering run %d test %" PRIuS, loop_count, i); |
387 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 395 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
388 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 396 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
389 // If the source does not exist or is not visible. | 397 // If the source does not exist or is not visible. |
390 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 398 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
391 } else if (!kFilteringTestCases[i].is_directory) { | 399 } else if (!kFilteringTestCases[i].is_directory) { |
392 // Cannot move a visible file to a directory. | 400 // Cannot move a visible file to a directory. |
393 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 401 expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
(...skipping 23 matching lines...) Expand all Loading... |
417 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { | 425 if (loop_count == 0 && kFilteringTestCases[i].is_directory) { |
418 // These directories do not exist in this case, so Copy() will not | 426 // These directories do not exist in this case, so Copy() will not |
419 // treat them as directories. Thus invalidating these test cases. | 427 // treat them as directories. Thus invalidating these test cases. |
420 // Continue now to avoid creating a new |operation| below that goes | 428 // Continue now to avoid creating a new |operation| below that goes |
421 // unused. | 429 // unused. |
422 continue; | 430 continue; |
423 } | 431 } |
424 | 432 |
425 // Create the source file for every test case because it might get moved. | 433 // Create the source file for every test case because it might get moved. |
426 FilePath src_path = root_path().AppendASCII("foo.jpg"); | 434 FilePath src_path = root_path().AppendASCII("foo.jpg"); |
427 FileSystemURL src_url(origin(), type(), src_path); | 435 FileSystemURL src_url = CreateURL(FPL("foo.jpg")); |
428 static const char kDummyData[] = "dummy"; | 436 static const char kDummyData[] = "dummy"; |
429 ASSERT_TRUE( | 437 ASSERT_TRUE( |
430 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); | 438 file_util::WriteFile(src_path, kDummyData, strlen(kDummyData))); |
431 | 439 |
432 FileSystemURL root_url(origin(), type(), root_path()); | 440 FileSystemURL root_url = CreateURL(FPL("")); |
433 FileSystemOperation* operation = NewOperation(root_url); | 441 FileSystemOperation* operation = NewOperation(root_url); |
434 | 442 |
435 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 443 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
436 FileSystemURL url(origin(), type(), path); | |
437 | 444 |
438 std::string test_name = base::StringPrintf( | 445 std::string test_name = base::StringPrintf( |
439 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); | 446 "MoveDestFiltering run %d test %" PRIuS, loop_count, i); |
440 base::PlatformFileError expectation; | 447 base::PlatformFileError expectation; |
441 if (loop_count == 0) { | 448 if (loop_count == 0) { |
442 // The destination path is a file here. The directory case has been | 449 // The destination path is a file here. The directory case has been |
443 // handled above. | 450 // handled above. |
444 // If the destination path does not exist and is not visible, then | 451 // If the destination path does not exist and is not visible, then |
445 // creating it would be a security violation. | 452 // creating it would be a security violation. |
446 expectation = | 453 expectation = |
(...skipping 23 matching lines...) Expand all Loading... |
470 | 477 |
471 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { | 478 TEST_F(NativeMediaFileUtilTest, GetMetadataFiltering) { |
472 // Run the loop twice. The first run has no files. The second run does. | 479 // Run the loop twice. The first run has no files. The second run does. |
473 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 480 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
474 if (loop_count == 1) { | 481 if (loop_count == 1) { |
475 PopulateDirectoryWithTestCases(root_path(), | 482 PopulateDirectoryWithTestCases(root_path(), |
476 kFilteringTestCases, | 483 kFilteringTestCases, |
477 arraysize(kFilteringTestCases)); | 484 arraysize(kFilteringTestCases)); |
478 } | 485 } |
479 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 486 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
480 FileSystemURL root_url(origin(), type(), root_path()); | 487 FileSystemURL root_url = CreateURL(FPL("")); |
481 FileSystemOperation* operation = NewOperation(root_url); | 488 FileSystemOperation* operation = NewOperation(root_url); |
482 | 489 |
483 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 490 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
484 FileSystemURL url(origin(), type(), path); | |
485 | 491 |
486 std::string test_name = base::StringPrintf( | 492 std::string test_name = base::StringPrintf( |
487 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); | 493 "GetMetadataFiltering run %d test %" PRIuS, loop_count, i); |
488 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 494 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
489 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 495 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
490 // Cannot get metadata from files that do not exist or are not visible. | 496 // Cannot get metadata from files that do not exist or are not visible. |
491 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 497 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
492 } | 498 } |
493 operation->GetMetadata(url, | 499 operation->GetMetadata(url, |
494 base::Bind(&ExpectMetadataEqHelper, | 500 base::Bind(&ExpectMetadataEqHelper, |
495 test_name, | 501 test_name, |
496 expectation, | 502 expectation, |
497 kFilteringTestCases[i].is_directory)); | 503 kFilteringTestCases[i].is_directory)); |
498 MessageLoop::current()->RunUntilIdle(); | 504 MessageLoop::current()->RunUntilIdle(); |
499 } | 505 } |
500 } | 506 } |
501 } | 507 } |
502 | 508 |
503 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { | 509 TEST_F(NativeMediaFileUtilTest, RemoveFiltering) { |
504 // Run the loop twice. The first run has no files. The second run does. | 510 // Run the loop twice. The first run has no files. The second run does. |
505 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 511 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
506 if (loop_count == 1) { | 512 if (loop_count == 1) { |
507 PopulateDirectoryWithTestCases(root_path(), | 513 PopulateDirectoryWithTestCases(root_path(), |
508 kFilteringTestCases, | 514 kFilteringTestCases, |
509 arraysize(kFilteringTestCases)); | 515 arraysize(kFilteringTestCases)); |
510 } | 516 } |
511 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 517 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
512 FileSystemURL root_url(origin(), type(), root_path()); | 518 FileSystemURL root_url = CreateURL(FPL("")); |
513 FileSystemOperation* operation = NewOperation(root_url); | 519 FileSystemOperation* operation = NewOperation(root_url); |
514 | 520 |
515 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 521 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
516 FileSystemURL url(origin(), type(), path); | |
517 | 522 |
518 std::string test_name = base::StringPrintf( | 523 std::string test_name = base::StringPrintf( |
519 "RemoveFiltering run %d test %" PRIuS, loop_count, i); | 524 "RemoveFiltering run %d test %" PRIuS, loop_count, i); |
520 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 525 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
521 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 526 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
522 // Cannot remove files that do not exist or are not visible. | 527 // Cannot remove files that do not exist or are not visible. |
523 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 528 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
524 } | 529 } |
525 operation->Remove( | 530 operation->Remove( |
526 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); | 531 url, false, base::Bind(&ExpectEqHelper, test_name, expectation)); |
527 MessageLoop::current()->RunUntilIdle(); | 532 MessageLoop::current()->RunUntilIdle(); |
528 } | 533 } |
529 } | 534 } |
530 } | 535 } |
531 | 536 |
532 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { | 537 TEST_F(NativeMediaFileUtilTest, TruncateFiltering) { |
533 // Run the loop twice. The first run has no files. The second run does. | 538 // Run the loop twice. The first run has no files. The second run does. |
534 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 539 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
535 if (loop_count == 1) { | 540 if (loop_count == 1) { |
536 PopulateDirectoryWithTestCases(root_path(), | 541 PopulateDirectoryWithTestCases(root_path(), |
537 kFilteringTestCases, | 542 kFilteringTestCases, |
538 arraysize(kFilteringTestCases)); | 543 arraysize(kFilteringTestCases)); |
539 } | 544 } |
540 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 545 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
541 FileSystemURL root_url(origin(), type(), root_path()); | 546 FileSystemURL root_url = CreateURL(FPL("")); |
542 FileSystemOperation* operation = NewOperation(root_url); | 547 FileSystemOperation* operation = NewOperation(root_url); |
543 | 548 |
544 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 549 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
545 FileSystemURL url(origin(), type(), path); | |
546 | 550 |
547 std::string test_name = base::StringPrintf( | 551 std::string test_name = base::StringPrintf( |
548 "TruncateFiltering run %d test %" PRIuS, loop_count, i); | 552 "TruncateFiltering run %d test %" PRIuS, loop_count, i); |
549 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 553 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
550 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 554 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
551 // Cannot truncate files that do not exist or are not visible. | 555 // Cannot truncate files that do not exist or are not visible. |
552 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 556 expectation = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
553 } else if (kFilteringTestCases[i].is_directory) { | 557 } else if (kFilteringTestCases[i].is_directory) { |
554 // Cannot truncate directories. | 558 // Cannot truncate directories. |
555 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | 559 expectation = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
556 } | 560 } |
557 operation->Truncate( | 561 operation->Truncate( |
558 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); | 562 url, 0, base::Bind(&ExpectEqHelper, test_name, expectation)); |
559 MessageLoop::current()->RunUntilIdle(); | 563 MessageLoop::current()->RunUntilIdle(); |
560 } | 564 } |
561 } | 565 } |
562 } | 566 } |
563 | 567 |
564 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { | 568 TEST_F(NativeMediaFileUtilTest, TouchFileFiltering) { |
565 base::Time time = base::Time::Now(); | 569 base::Time time = base::Time::Now(); |
566 | 570 |
567 // Run the loop twice. The first run has no files. The second run does. | 571 // Run the loop twice. The first run has no files. The second run does. |
568 for (int loop_count = 0; loop_count < 2; ++loop_count) { | 572 for (int loop_count = 0; loop_count < 2; ++loop_count) { |
569 if (loop_count == 1) { | 573 if (loop_count == 1) { |
570 PopulateDirectoryWithTestCases(root_path(), | 574 PopulateDirectoryWithTestCases(root_path(), |
571 kFilteringTestCases, | 575 kFilteringTestCases, |
572 arraysize(kFilteringTestCases)); | 576 arraysize(kFilteringTestCases)); |
573 } | 577 } |
574 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { | 578 for (size_t i = 0; i < arraysize(kFilteringTestCases); ++i) { |
575 FileSystemURL root_url(origin(), type(), root_path()); | 579 FileSystemURL root_url = CreateURL(FPL("")); |
576 FileSystemOperation* operation = NewOperation(root_url); | 580 FileSystemOperation* operation = NewOperation(root_url); |
577 | 581 |
578 FilePath path = root_path().Append(kFilteringTestCases[i].path); | 582 FileSystemURL url = CreateURL(kFilteringTestCases[i].path); |
579 FileSystemURL url(origin(), type(), path); | |
580 | 583 |
581 std::string test_name = base::StringPrintf( | 584 std::string test_name = base::StringPrintf( |
582 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); | 585 "TouchFileFiltering run %d test %" PRIuS, loop_count, i); |
583 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; | 586 base::PlatformFileError expectation = base::PLATFORM_FILE_OK; |
584 if (loop_count == 0 || !kFilteringTestCases[i].visible) { | 587 if (loop_count == 0 || !kFilteringTestCases[i].visible) { |
585 // Files do not exists. Touch fails. | 588 // Files do not exists. Touch fails. |
586 expectation = base::PLATFORM_FILE_ERROR_FAILED; | 589 expectation = base::PLATFORM_FILE_ERROR_FAILED; |
587 } | 590 } |
588 operation->TouchFile( | 591 operation->TouchFile( |
589 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); | 592 url, time, time, base::Bind(&ExpectEqHelper, test_name, expectation)); |
590 MessageLoop::current()->RunUntilIdle(); | 593 MessageLoop::current()->RunUntilIdle(); |
591 } | 594 } |
592 } | 595 } |
593 } | 596 } |
594 | 597 |
595 } // namespace fileapi | 598 } // namespace fileapi |
OLD | NEW |