summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_file_ref.cc
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 00:45:43 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-21 00:45:43 +0000
commit64264efa8b4a0bf37b19042f295f9990a7f388c9 (patch)
tree5e7cbf44e04f00388078da62d6e0eed878da3d6d /ppapi/tests/test_file_ref.cc
parentc85b0ba71b5a55647b01de9d345e46896979033d (diff)
downloadchromium_src-64264efa8b4a0bf37b19042f295f9990a7f388c9.zip
chromium_src-64264efa8b4a0bf37b19042f295f9990a7f388c9.tar.gz
chromium_src-64264efa8b4a0bf37b19042f295f9990a7f388c9.tar.bz2
Properly cancel PPAPI callbacks.
This sets up infrastructure to properly cancel PPAPI callbacks (which have particular semantics), and converts a couple things to use them. BUG= TEST=test_shell_tests and PPAPI tests Review URL: http://codereview.chromium.org/5562008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_file_ref.cc')
-rw-r--r--ppapi/tests/test_file_ref.cc140
1 files changed, 136 insertions, 4 deletions
diff --git a/ppapi/tests/test_file_ref.cc b/ppapi/tests/test_file_ref.cc
index b1062a7..a81b8ed2 100644
--- a/ppapi/tests/test_file_ref.cc
+++ b/ppapi/tests/test_file_ref.cc
@@ -246,6 +246,7 @@ std::string TestFileRef::TestGetParent() {
std::string TestFileRef::TestMakeDirectory() {
TestCompletionCallback callback;
+ // Open.
pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
int32_t rv = file_system.Open(1024, callback);
if (rv == PP_ERROR_WOULDBLOCK)
@@ -253,6 +254,21 @@ std::string TestFileRef::TestMakeDirectory() {
if (rv != PP_OK)
return ReportError("FileSystem::Open", rv);
+ // Open aborted (see the DirectoryReader test for comments).
+ callback.reset_run_count();
+ rv = pp::FileSystem_Dev(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY)
+ .Open(1024, callback);
+ if (callback.run_count() > 0)
+ return "FileSystem::Open ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::Open not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::Open", rv);
+ }
+
+ // MakeDirectory.
pp::FileRef_Dev dir_ref(file_system, "/test_dir_make_directory");
rv = dir_ref.MakeDirectory(callback);
if (rv == PP_ERROR_WOULDBLOCK)
@@ -260,6 +276,21 @@ std::string TestFileRef::TestMakeDirectory() {
if (rv != PP_OK)
return ReportError("FileSystem::MakeDirectory", rv);
+ // MakeDirectory aborted.
+ callback.reset_run_count();
+ rv = pp::FileRef_Dev(file_system, "/test_dir_make_abort")
+ .MakeDirectory(callback);
+ if (callback.run_count() > 0)
+ return "FileSystem::MakeDirectory ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::MakeDirectory not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::MakeDirectory", rv);
+ }
+
+ // MakeDirectoryIncludingAncestors.
dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_1/dir_make_dir_2");
rv = dir_ref.MakeDirectoryIncludingAncestors(callback);
if (rv == PP_ERROR_WOULDBLOCK)
@@ -267,13 +298,31 @@ std::string TestFileRef::TestMakeDirectory() {
if (rv != PP_OK)
return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv);
+ // MakeDirectoryIncludingAncestors aborted.
+ callback.reset_run_count();
+ rv = pp::FileRef_Dev(file_system, "/dir_make_abort_1/dir_make_abort_2")
+ .MakeDirectoryIncludingAncestors(callback);
+ if (callback.run_count() > 0) {
+ return "FileSystem::MakeDirectoryIncludingAncestors "
+ "ran callback synchronously.";
+ }
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::MakeDirectoryIncludingAncestors not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv);
+ }
+
+ // MakeDirectory with nested path.
dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_3/dir_make_dir_4");
rv = dir_ref.MakeDirectory(callback);
if (rv == PP_ERROR_WOULDBLOCK)
rv = callback.WaitForResult();
- if (rv == PP_OK)
- return "Calling FileSystem::MakeDirectory() with a nested directory path " \
- "should have failed.";
+ if (rv == PP_OK) {
+ return "Calling FileSystem::MakeDirectory() with a nested directory path "
+ "should have failed.";
+ }
return "";
}
@@ -304,6 +353,7 @@ std::string TestFileRef::TestQueryAndTouchFile() {
if (rv != 4)
return ReportError("FileIO::Write", rv);
+ // Touch.
// last_access_time's granularity is 1 day
// last_modified_time's granularity is 2 seconds
const PP_Time last_access_time = 123 * 24 * 3600.0;
@@ -314,6 +364,21 @@ std::string TestFileRef::TestQueryAndTouchFile() {
if (rv != PP_OK)
return ReportError("FileSystem::Touch", rv);
+ // Touch aborted.
+ callback.reset_run_count();
+ rv = pp::FileRef_Dev(file_system, "/file_touch_abort")
+ .Touch(last_access_time, last_modified_time, callback);
+ if (callback.run_count() > 0)
+ return "FileSystem::Touch ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::Touch not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::Touch", rv);
+ }
+
+ // Query.
PP_FileInfo_Dev info;
rv = file_ref.Query(&info, callback);
if (rv == PP_ERROR_WOULDBLOCK)
@@ -328,6 +393,21 @@ std::string TestFileRef::TestQueryAndTouchFile() {
(info.last_modified_time != last_modified_time))
return "FileSystem::Query() has returned bad data.";
+ // Cancellation test.
+ // TODO(viettrungluu): this test causes a bunch of LOG(WARNING)s; investigate.
+ callback.reset_run_count();
+ // TODO(viettrungluu): check |info| for late writes.
+ rv = pp::FileRef_Dev(file_system, "/file_touch").Query(&info, callback);
+ if (callback.run_count() > 0)
+ return "FileSystem::Query ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::Query not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::Query", rv);
+ }
+
return "";
}
@@ -374,7 +454,9 @@ std::string TestFileRef::TestDeleteFileAndDirectory() {
if (rv != PP_OK)
return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv);
- rv = nested_dir_ref.GetParent().Delete(callback);
+ // Hang on to a ref to the parent; otherwise the callback will be aborted.
+ pp::FileRef_Dev parent_dir_ref = nested_dir_ref.GetParent();
+ rv = parent_dir_ref.Delete(callback);
if (rv == PP_ERROR_WOULDBLOCK)
rv = callback.WaitForResult();
if (rv != PP_ERROR_FAILED)
@@ -387,6 +469,29 @@ std::string TestFileRef::TestDeleteFileAndDirectory() {
if (rv != PP_ERROR_FILENOTFOUND)
return ReportError("FileSystem::Delete", rv);
+ // Delete aborted.
+ {
+ pp::FileRef_Dev file_ref_abort(file_system, "/file_delete_abort");
+ pp::FileIO_Dev file_io_abort;
+ rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_ref_abort.Delete(callback);
+ }
+ if (callback.run_count() > 0)
+ return "FileSystem::Delete ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::Delete not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::Delete", rv);
+ }
+
return "";
}
@@ -442,5 +547,32 @@ std::string TestFileRef::TestRenameFileAndDirectory() {
if (rv != PP_ERROR_FAILED)
return ReportError("FileSystem::Rename", rv);
+ // Rename aborted.
+ // TODO(viettrungluu): Figure out what we want to do if the target file
+ // resource is destroyed before completion.
+ pp::FileRef_Dev target_file_ref_abort(file_system,
+ "/target_file_rename_abort");
+ {
+ pp::FileRef_Dev file_ref_abort(file_system, "/file_rename_abort");
+ pp::FileIO_Dev file_io_abort;
+ rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_ref_abort.Rename(target_file_ref_abort, callback);
+ }
+ if (callback.run_count() > 0)
+ return "FileSystem::Rename ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileSystem::Rename not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileSystem::Rename", rv);
+ }
+
return "";
}