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

Unified Diff: ppapi/shared_impl/tracked_callback_unittest.cc

Issue 22646005: Do PPB_FileIO Query and Read in the plugin process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Defer buffer allocation until we read. Created 7 years, 4 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
« ppapi/proxy/file_io_resource.cc ('K') | « ppapi/shared_impl/tracked_callback.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/tracked_callback_unittest.cc
diff --git a/ppapi/shared_impl/tracked_callback_unittest.cc b/ppapi/shared_impl/tracked_callback_unittest.cc
index a9961f015b5ea5d70bad76c25679fbc6d61acd3d..9ceb96e7cf7734a40d27ee0e0c946b9532f14e51 100644
--- a/ppapi/shared_impl/tracked_callback_unittest.cc
+++ b/ppapi/shared_impl/tracked_callback_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "ppapi/c/pp_completion_callback.h"
@@ -37,11 +38,20 @@ class TrackedCallbackTest : public testing::Test {
PP_Instance pp_instance_;
};
+// All valid results (PP_OK, PP_ERROR_...) are nonpositive.
+const int32_t kInitializedResultValue = 1;
+const int32_t kOverrideResultValue = 2;
+
struct CallbackRunInfo {
- // All valid results (PP_OK, PP_ERROR_...) are nonpositive.
- CallbackRunInfo() : run_count(0), result(1) {}
+ CallbackRunInfo()
+ : run_count(0),
+ result(kInitializedResultValue),
+ completion_task_run_count(0),
+ completion_task_result(kInitializedResultValue) {}
unsigned run_count;
int32_t result;
+ unsigned completion_task_run_count;
+ int32_t completion_task_result;
};
void TestCallback(void* user_data, int32_t result) {
@@ -144,18 +154,38 @@ class CallbackMockResource : public Resource {
this,
PP_MakeCompletionCallback(&TestCallback, &info_did_run_));
EXPECT_EQ(0U, info_did_run_.run_count);
+ EXPECT_EQ(0U, info_did_run_.completion_task_run_count);
+
+ // In order to test that the completion task can override the callback
+ // result, we need to test callbacks with and without a completion task.
+ callback_did_run_with_completion_task_ = new TrackedCallback(
+ this,
+ PP_MakeCompletionCallback(&TestCallback,
+ &info_did_run_with_completion_task_));
+ callback_did_run_with_completion_task_->set_completion_task(
+ Bind(&CallbackMockResource::CompletionTask, this,
+ &info_did_run_with_completion_task_));
+ EXPECT_EQ(0U, info_did_run_with_completion_task_.run_count);
+ EXPECT_EQ(0U, info_did_run_with_completion_task_.completion_task_run_count);
callback_did_abort_ = new TrackedCallback(
this,
PP_MakeCompletionCallback(&TestCallback, &info_did_abort_));
+ callback_did_abort_->set_completion_task(
+ Bind(&CallbackMockResource::CompletionTask, this, &info_did_abort_));
EXPECT_EQ(0U, info_did_abort_.run_count);
+ EXPECT_EQ(0U, info_did_abort_.completion_task_run_count);
callback_didnt_run_ = new TrackedCallback(
this,
PP_MakeCompletionCallback(&TestCallback, &info_didnt_run_));
+ callback_didnt_run_->set_completion_task(
+ Bind(&CallbackMockResource::CompletionTask, this, &info_didnt_run_));
EXPECT_EQ(0U, info_didnt_run_.run_count);
+ EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count);
callback_did_run_->Run(PP_OK);
+ callback_did_run_with_completion_task_->Run(PP_OK);
callback_did_abort_->Abort();
CheckIntermediateState();
@@ -163,13 +193,34 @@ class CallbackMockResource : public Resource {
return resource_id;
}
+ int32_t CompletionTask(CallbackRunInfo* info, int32_t result) {
+ // We should run before the callback.
+ EXPECT_EQ(0U, info->run_count);
+ info->completion_task_run_count++;
+ if (info->completion_task_run_count == 1)
+ info->completion_task_result = result;
+ return kOverrideResultValue;
+ }
+
void CheckIntermediateState() {
EXPECT_EQ(1U, info_did_run_.run_count);
EXPECT_EQ(PP_OK, info_did_run_.result);
+ EXPECT_EQ(0U, info_did_run_.completion_task_run_count);
+
+ EXPECT_EQ(1U, info_did_run_with_completion_task_.run_count);
+ // completion task should override the result.
+ EXPECT_EQ(kOverrideResultValue, info_did_run_with_completion_task_.result);
+ EXPECT_EQ(1U, info_did_run_with_completion_task_.completion_task_run_count);
+ EXPECT_EQ(PP_OK,
+ info_did_run_with_completion_task_.completion_task_result);
EXPECT_EQ(1U, info_did_abort_.run_count);
+ // completion task shouldn't override an abort.
EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.result);
+ EXPECT_EQ(1U, info_did_abort_.completion_task_run_count);
+ EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.completion_task_result);
+ EXPECT_EQ(0U, info_didnt_run_.completion_task_run_count);
EXPECT_EQ(0U, info_didnt_run_.run_count);
}
@@ -185,6 +236,9 @@ class CallbackMockResource : public Resource {
scoped_refptr<TrackedCallback> callback_did_run_;
CallbackRunInfo info_did_run_;
+ scoped_refptr<TrackedCallback> callback_did_run_with_completion_task_;
+ CallbackRunInfo info_did_run_with_completion_task_;
+
scoped_refptr<TrackedCallback> callback_did_abort_;
CallbackRunInfo info_did_abort_;
« ppapi/proxy/file_io_resource.cc ('K') | « ppapi/shared_impl/tracked_callback.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698