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

Unified Diff: ppapi/tests/test_flash_file.cc

Issue 11450025: Revert 171389 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_flash_file.h ('k') | ppapi/thunk/ppb_file_ref_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_flash_file.cc
diff --git a/ppapi/tests/test_flash_file.cc b/ppapi/tests/test_flash_file.cc
index ac88b34b83d7f551edeea5c6692da5a12a289ce3..86100d96ddd4120eab6d396ef854051e5879d3f9 100644
--- a/ppapi/tests/test_flash_file.cc
+++ b/ppapi/tests/test_flash_file.cc
@@ -4,6 +4,11 @@
#include "ppapi/tests/test_flash_file.h"
+#include <algorithm>
+#include <vector>
+
+#include "ppapi/c/pp_file_info.h"
+#include "ppapi/c/ppb_file_io.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/private/flash_file.h"
#include "ppapi/tests/testing_instance.h"
@@ -74,6 +79,18 @@ bool ReadFile(PP_FileHandle file_handle, std::string* contents) {
return result;
}
+bool DirEntryEqual(FileModuleLocal::DirEntry i,
+ FileModuleLocal::DirEntry j) {
+ return i.name == j.name && i.is_dir == j.is_dir;
+}
+
+bool DirEntryLessThan(FileModuleLocal::DirEntry i,
+ FileModuleLocal::DirEntry j) {
+ if (i.name == j.name)
+ return i.is_dir < j.is_dir;
+ return i.name < j.name;
+}
+
} // namespace
REGISTER_TEST_CASE(FlashFile);
@@ -90,15 +107,204 @@ bool TestFlashFile::Init() {
}
void TestFlashFile::RunTests(const std::string& filter) {
+ RUN_TEST(OpenFile, filter);
+ RUN_TEST(RenameFile, filter);
+ RUN_TEST(DeleteFileOrDir, filter);
+ RUN_TEST(CreateDir, filter);
+ RUN_TEST(QueryFile, filter);
+ RUN_TEST(GetDirContents, filter);
RUN_TEST(CreateTemporaryFile, filter);
}
-std::string TestFlashFile::TestCreateTemporaryFile() {
- ASSERT_TRUE(FileModuleLocal::IsCreateTemporaryFileAvailable());
-
+void TestFlashFile::SetUp() {
+ // Clear out existing test data.
+ FileModuleLocal::DeleteFileOrDir(instance_, std::string(), true);
// Make sure that the root directory exists.
FileModuleLocal::CreateDir(instance_, std::string());
+}
+
+std::string TestFlashFile::TestOpenFile() {
+ SetUp();
+ std::string filename = "abc.txt";
+ PP_FileHandle file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+
+ std::string contents = "This is file.";
+ std::string read_contents;
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ ASSERT_FALSE(ReadFile(file_handle, &read_contents));
+ CloseFileHandle(file_handle);
+
+ file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_READ);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+
+ ASSERT_FALSE(WriteFile(file_handle, contents));
+ ASSERT_TRUE(ReadFile(file_handle, &read_contents));
+ ASSERT_EQ(contents, read_contents);
+ CloseFileHandle(file_handle);
+
+ PASS();
+}
+
+std::string TestFlashFile::TestRenameFile() {
+ SetUp();
+ std::string filename = "abc.txt";
+ std::string new_filename = "abc_new.txt";
+ std::string contents = "This is file.";
+ std::string read_contents;
+
+ PP_FileHandle file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ CloseFileHandle(file_handle);
+
+ ASSERT_TRUE(FileModuleLocal::RenameFile(instance_, filename, new_filename));
+
+ file_handle = FileModuleLocal::OpenFile(instance_,
+ new_filename,
+ PP_FILEOPENFLAG_READ);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(ReadFile(file_handle, &read_contents));
+ ASSERT_EQ(contents, read_contents);
+ CloseFileHandle(file_handle);
+
+ // Check that the old file no longer exists.
+ PP_FileInfo unused;
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, filename, &unused));
+
+ PASS();
+}
+std::string TestFlashFile::TestDeleteFileOrDir() {
+ SetUp();
+ std::string filename = "abc.txt";
+ std::string dirname = "def";
+ std::string contents = "This is file.";
+
+ // Test file deletion.
+ PP_FileHandle file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ CloseFileHandle(file_handle);
+ ASSERT_TRUE(FileModuleLocal::DeleteFileOrDir(instance_, filename, false));
+ PP_FileInfo unused;
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, filename, &unused));
+
+ // Test directory deletion.
+ ASSERT_TRUE(FileModuleLocal::CreateDir(instance_, dirname));
+ ASSERT_TRUE(FileModuleLocal::DeleteFileOrDir(instance_, dirname, false));
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, dirname, &unused));
+
+ // Test recursive directory deletion.
+ ASSERT_TRUE(FileModuleLocal::CreateDir(instance_, dirname));
+ file_handle = FileModuleLocal::OpenFile(
+ instance_, dirname + "/" + filename,
+ PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ CloseFileHandle(file_handle);
+ ASSERT_FALSE(FileModuleLocal::DeleteFileOrDir(instance_, dirname, false));
+ ASSERT_TRUE(FileModuleLocal::DeleteFileOrDir(instance_, dirname, true));
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, filename, &unused));
+
+ PASS();
+}
+
+std::string TestFlashFile::TestCreateDir() {
+ SetUp();
+ std::string dirname = "abc";
+ PP_FileInfo info;
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, dirname, &info));
+ ASSERT_TRUE(FileModuleLocal::CreateDir(instance_, dirname));
+ ASSERT_TRUE(FileModuleLocal::QueryFile(instance_, dirname, &info));
+ ASSERT_EQ(info.type, PP_FILETYPE_DIRECTORY);
+
+ PASS();
+}
+
+std::string TestFlashFile::TestQueryFile() {
+ std::string filename = "abc.txt";
+ std::string dirname = "def";
+ std::string contents = "This is file.";
+ PP_FileInfo info;
+
+ // Test querying a file.
+ PP_FileHandle file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ CloseFileHandle(file_handle);
+ ASSERT_TRUE(FileModuleLocal::QueryFile(instance_, filename, &info));
+ ASSERT_EQ(static_cast<size_t>(info.size), contents.size());
+ ASSERT_EQ(info.type, PP_FILETYPE_REGULAR);
+ // TODO(raymes): Test the other fields.
+
+ // Test querying a directory.
+ ASSERT_TRUE(FileModuleLocal::CreateDir(instance_, dirname));
+ ASSERT_TRUE(FileModuleLocal::QueryFile(instance_, dirname, &info));
+ ASSERT_EQ(info.type, PP_FILETYPE_DIRECTORY);
+ // TODO(raymes): Test the other fields.
+
+ // Test querying a non-existent file.
+ ASSERT_FALSE(FileModuleLocal::QueryFile(instance_, "xx", &info));
+
+ PASS();
+}
+
+std::string TestFlashFile::TestGetDirContents() {
+ SetUp();
+ std::vector<FileModuleLocal::DirEntry> result;
+ ASSERT_TRUE(FileModuleLocal::GetDirContents(instance_, std::string(),
+ &result));
+ ASSERT_EQ(result.size(), 1);
+ ASSERT_EQ(result[0].name, "..");
+ ASSERT_EQ(result[0].is_dir, true);
+
+ std::string filename = "abc.txt";
+ std::string dirname = "def";
+ std::string contents = "This is file.";
+ PP_FileHandle file_handle = FileModuleLocal::OpenFile(instance_,
+ filename,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE);
+ ASSERT_NE(PP_kInvalidFileHandle, file_handle);
+ ASSERT_TRUE(WriteFile(file_handle, contents));
+ CloseFileHandle(file_handle);
+ ASSERT_TRUE(FileModuleLocal::CreateDir(instance_, dirname));
+
+ ASSERT_TRUE(FileModuleLocal::GetDirContents(instance_, "", &result));
+ FileModuleLocal::DirEntry expected[] =
+ { {"..", true},
+ {filename, false},
+ {dirname, true}
+ };
+ size_t expected_size = sizeof(expected) / sizeof(expected[0]);
+
+ std::sort(expected, expected + expected_size, DirEntryLessThan);
+ std::sort(result.begin(), result.end(), DirEntryLessThan);
+
+ ASSERT_EQ(expected_size, result.size());
+ ASSERT_TRUE(std::equal(expected, expected + expected_size, result.begin(),
+ DirEntryEqual));
+
+ PASS();
+}
+
+std::string TestFlashFile::TestCreateTemporaryFile() {
+ SetUp();
size_t before_create = 0;
ASSERT_SUBTEST_SUCCESS(GetItemCountUnderModuleLocalRoot(&before_create));
« no previous file with comments | « ppapi/tests/test_flash_file.h ('k') | ppapi/thunk/ppb_file_ref_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698