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

Side by Side Diff: ppapi/tests/test_file_ref.cc

Issue 12817009: Add Query() support to FileRef (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/tests/test_file_ref.h" 5 #include "ppapi/tests/test_file_ref.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 void TestFileRef::RunTests(const std::string& filter) { 52 void TestFileRef::RunTests(const std::string& filter) {
53 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter); 53 RUN_TEST_FORCEASYNC_AND_NOT(Create, filter);
54 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter); 54 RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType, filter);
55 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter); 55 RUN_TEST_FORCEASYNC_AND_NOT(GetName, filter);
56 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter); 56 RUN_TEST_FORCEASYNC_AND_NOT(GetPath, filter);
57 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter); 57 RUN_TEST_FORCEASYNC_AND_NOT(GetParent, filter);
58 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter); 58 RUN_TEST_FORCEASYNC_AND_NOT(MakeDirectory, filter);
59 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter); 59 RUN_TEST_FORCEASYNC_AND_NOT(QueryAndTouchFile, filter);
60 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter); 60 RUN_TEST_FORCEASYNC_AND_NOT(DeleteFileAndDirectory, filter);
61 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter); 61 RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory, filter);
62 RUN_TEST_FORCEASYNC_AND_NOT(Query, filter);
62 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet. 63 #ifndef PPAPI_OS_NACL // NaCl can't run this test yet.
63 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter); 64 RUN_TEST_FORCEASYNC_AND_NOT(FileNameEscaping, filter);
64 #endif 65 #endif
65 } 66 }
66 67
67 std::string TestFileRef::TestCreate() { 68 std::string TestFileRef::TestCreate() {
68 std::vector<std::string> invalid_paths; 69 std::vector<std::string> invalid_paths;
69 invalid_paths.push_back("invalid_path"); // no '/' at the first character 70 invalid_paths.push_back("invalid_path"); // no '/' at the first character
70 invalid_paths.push_back(""); // empty path 71 invalid_paths.push_back(""); // empty path
71 // The following are directory traversal checks 72 // The following are directory traversal checks
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 rv = callback.WaitForResult(); 673 rv = callback.WaitForResult();
673 if (rv != PP_ERROR_ABORTED) 674 if (rv != PP_ERROR_ABORTED)
674 return "FileSystem::Rename not aborted."; 675 return "FileSystem::Rename not aborted.";
675 } else if (rv != PP_OK) { 676 } else if (rv != PP_OK) {
676 return ReportError("FileSystem::Rename", rv); 677 return ReportError("FileSystem::Rename", rv);
677 } 678 }
678 679
679 PASS(); 680 PASS();
680 } 681 }
681 682
683 std::string TestFileRef::TestQuery() {
684 TestCompletionCallback callback(instance_->pp_instance());
685
686 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
687 callback.WaitForResult(file_system.Open(1024, callback));
688 CHECK_CALLBACK_BEHAVIOR(callback);
689 ASSERT_EQ(PP_OK, callback.result());
690
691 pp::FileRef file_ref(file_system, "/file");
692 pp::FileIO file_io(instance_);
693 callback.WaitForResult(file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE,
694 callback));
695 CHECK_CALLBACK_BEHAVIOR(callback);
696 ASSERT_EQ(PP_OK, callback.result());
697
698 // We touch the file so we can easily check access and modified time.
699 callback.WaitForResult(file_io.Touch(0, 0, callback));
700 CHECK_CALLBACK_BEHAVIOR(callback);
701 ASSERT_EQ(PP_OK, callback.result());
702
703 PP_FileInfo info;
704 callback.WaitForResult(file_ref.Query(&info, callback));
705 CHECK_CALLBACK_BEHAVIOR(callback);
706 ASSERT_EQ(PP_OK, callback.result());
707
708 ASSERT_EQ(0, info.size);
709 ASSERT_EQ(PP_FILETYPE_REGULAR, info.type);
710 ASSERT_EQ(PP_FILESYSTEMTYPE_LOCALTEMPORARY, info.system_type);
711 ASSERT_DOUBLE_EQ(0.0, info.last_access_time);
712 ASSERT_DOUBLE_EQ(0.0, info.last_modified_time);
713
714 pp::FileRef missing_file_ref(file_system, "/missing_file");
715 callback.WaitForResult(missing_file_ref.Query(&info, callback));
716 CHECK_CALLBACK_BEHAVIOR(callback);
717 ASSERT_EQ(PP_ERROR_FILENOTFOUND, callback.result());
718
719 PASS();
720 }
721
682 #ifndef PPAPI_OS_NACL 722 #ifndef PPAPI_OS_NACL
683 std::string TestFileRef::TestFileNameEscaping() { 723 std::string TestFileRef::TestFileNameEscaping() {
684 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 724 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
685 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 725 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
686 int32_t rv = file_system.Open(1024, callback); 726 int32_t rv = file_system.Open(1024, callback);
687 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) 727 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
688 return ReportError("FileSystem::Open force_async", rv); 728 return ReportError("FileSystem::Open force_async", rv);
689 if (rv == PP_OK_COMPLETIONPENDING) 729 if (rv == PP_OK_COMPLETIONPENDING)
690 rv = callback.WaitForResult(); 730 rv = callback.WaitForResult();
691 if (rv != PP_OK) 731 if (rv != PP_OK)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 return "Entry was not found."; 771 return "Entry was not found.";
732 if (entries.size() != 1) 772 if (entries.size() != 1)
733 return "Directory had too many entries."; 773 return "Directory had too many entries.";
734 if (entries.front().file_ref().GetName().AsString() != kTerribleName) 774 if (entries.front().file_ref().GetName().AsString() != kTerribleName)
735 return "Entry name did not match."; 775 return "Entry name did not match.";
736 } 776 }
737 777
738 PASS(); 778 PASS();
739 } 779 }
740 #endif 780 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698