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

Unified Diff: ppapi/tests/test_file_io.cc

Issue 6228004: Fix Pepper File IO callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_file_io.cc
diff --git a/ppapi/tests/test_file_io.cc b/ppapi/tests/test_file_io.cc
index 591d6567781d95e973694fb1eb4574c4c23f0a4c..11fe62bfae36f6f6176fe0bcbc96e2b32a9ca948 100644
--- a/ppapi/tests/test_file_io.cc
+++ b/ppapi/tests/test_file_io.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/tests/test_file_io.h"
#include <stdio.h>
+#include <string.h>
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/dev/ppb_file_io_dev.h"
@@ -83,6 +84,10 @@ void TestFileIO::RunTest() {
RUN_TEST(Open);
RUN_TEST(ReadWriteSetLength);
RUN_TEST(TouchQuery);
+ RUN_TEST(AbortCalls);
+ // TODO(viettrungluu): add tests:
+ // - that PP_ERROR_PENDING is correctly returned
+ // - that operations respect the file open modes (flags)
}
std::string TestFileIO::TestOpen() {
@@ -281,5 +286,203 @@ std::string TestFileIO::TestTouchQuery() {
(info.last_modified_time != last_modified_time))
return "FileSystem::Query() has returned bad data.";
+ // Call |Query()| again, to make sure it works a second time.
+ rv = file_io.Query(&info, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileSystem::Query", rv);
+
+ PASS();
+}
+
+std::string TestFileIO::TestAbortCalls() {
brettw 2011/01/11 21:15:41 nice!
+ TestCompletionCallback callback;
+
+ pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+ pp::FileRef_Dev file_ref(file_system, "/file_abort_calls");
+ int32_t rv = file_system.Open(1024, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileSystem::Open", rv);
+
+ // First, create a file which to do ops on.
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref,
+ PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_WRITE,
+ callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ // N.B.: Should write at least 3 bytes.
+ rv = WriteEntireBuffer(&file_io, 0, "foobarbazquux");
+ if (rv != PP_OK)
+ return ReportError("FileIO::Write", rv);
+ }
+
+ // Abort |Open()|.
+ {
+ callback.reset_run_count();
+ rv = pp::FileIO_Dev().Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (callback.run_count() > 0)
+ return "FileIO::Open ran callback synchronously.";
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Open not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Open", rv);
+ }
+ }
+
+ // Abort |Query()|.
+ {
+ PP_FileInfo_Dev info = { 0 };
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.Query(&info, callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ // Save a copy and make sure |info| doesn't get written to.
+ PP_FileInfo_Dev info_copy;
+ memcpy(&info_copy, &info, sizeof(info));
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Query not aborted.";
+ if (memcmp(&info_copy, &info, sizeof(info)) != 0)
+ return "FileIO::Query wrote data after resource destruction.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Query", rv);
+ }
+ }
+
+ // Abort |Touch()|.
+ {
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_WRITE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.Touch(0, 0, callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Touch not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Touch", rv);
+ }
+ }
+
+ // Abort |Read()|.
+ {
+ char buf[3] = { 0 };
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.Read(0, buf, sizeof(buf), callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ // Save a copy and make sure |buf| doesn't get written to.
+ char buf_copy[3];
+ memcpy(&buf_copy, &buf, sizeof(buf));
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Read not aborted.";
+ if (memcmp(&buf_copy, &buf, sizeof(buf)) != 0)
+ return "FileIO::Read wrote data after resource destruction.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Read", rv);
+ }
+ }
+
+ // Abort |Write()|.
+ {
+ char buf[3] = { 0 };
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.Write(0, buf, sizeof(buf), callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Write not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Write", rv);
+ }
+ }
+
+ // Abort |SetLength()|.
+ {
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.SetLength(3, callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::SetLength not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::SetLength", rv);
+ }
+ }
+
+ // Abort |Flush()|.
+ {
+ {
+ pp::FileIO_Dev file_io;
+ rv = file_io.Open(file_ref, PP_FILEOPENFLAG_READ, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ callback.reset_run_count();
+ rv = file_io.Flush(callback);
+ } // Destroy |file_io|.
+ if (rv == PP_ERROR_WOULDBLOCK) {
+ rv = callback.WaitForResult();
+ if (rv != PP_ERROR_ABORTED)
+ return "FileIO::Flush not aborted.";
+ } else if (rv != PP_OK) {
+ return ReportError("FileIO::Flush", rv);
+ }
+ }
+
PASS();
}

Powered by Google App Engine
This is Rietveld 408576698