Pepper: Change ResourceMessageTestSink API for getting multiple messages.
- Remove GetNext* methods.
- Add GetAll* methods, returning a vector of Params/Msg pairs.
BUG=
Review URL: https://codereview.chromium.org/127243002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243907 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/file_system_resource_unittest.cc b/ppapi/proxy/file_system_resource_unittest.cc
index 6828f7a..e60a808f 100644
--- a/ppapi/proxy/file_system_resource_unittest.cc
+++ b/ppapi/proxy/file_system_resource_unittest.cc
@@ -20,6 +20,7 @@
#include "ppapi/thunk/ppb_file_system_api.h"
#include "ppapi/thunk/thunk.h"
+using ppapi::proxy::ResourceMessageTestSink;
using ppapi::thunk::EnterResource;
using ppapi::thunk::PPB_FileSystem_API;
@@ -98,17 +99,15 @@
PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &cb));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- // Should have sent two "open" messages to the browser and renderer.
- ResourceMessageCallParams params1, params2;
- IPC::Message msg1, msg2;
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms1, &msg1));
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms2, &msg2));
+ // Should have sent two new "open" messages to the browser and renderer.
+ ResourceMessageTestSink::ResourceCallVector open_messages =
+ sink().GetAllResourceCallsMatching(PpapiHostMsg_FileSystem_Open::ID);
+ ASSERT_EQ(2U, open_messages.size());
+ sink().ClearMessages();
// The resource is expecting two replies.
- SendOpenReply(params1, PP_OK);
- SendOpenReply(params2, PP_OK);
+ SendOpenReply(open_messages[0].first, PP_OK);
+ SendOpenReply(open_messages[1].first, PP_OK);
ASSERT_TRUE(cb.called());
ASSERT_EQ(PP_OK, cb.result());
@@ -130,8 +129,9 @@
// Should have sent an "open" message.
ResourceMessageCallParams params;
IPC::Message msg;
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
PpapiHostMsg_FileIO_Open::ID, ¶ms, &msg));
+ sink().ClearMessages();
// Send a success reply.
ResourceMessageReplyParams reply_params(params.pp_resource(),
@@ -162,15 +162,13 @@
PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &cb));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- ResourceMessageCallParams params1, params2;
- IPC::Message msg1, msg2;
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms1, &msg1));
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms2, &msg2));
+ ResourceMessageTestSink::ResourceCallVector open_messages =
+ sink().GetAllResourceCallsMatching(PpapiHostMsg_FileSystem_Open::ID);
+ ASSERT_EQ(2U, open_messages.size());
+ sink().ClearMessages();
- SendOpenReply(params1, PP_ERROR_FAILED);
- SendOpenReply(params2, PP_OK);
+ SendOpenReply(open_messages[0].first, PP_ERROR_FAILED);
+ SendOpenReply(open_messages[1].first, PP_OK);
ASSERT_TRUE(cb.called());
ASSERT_EQ(PP_ERROR_FAILED, cb.result());
@@ -187,15 +185,13 @@
PP_MakeCompletionCallback(&MockCompletionCallback::Callback, &cb));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- ResourceMessageCallParams params1, params2;
- IPC::Message msg1, msg2;
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms1, &msg1));
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
- PpapiHostMsg_FileSystem_Open::ID, ¶ms2, &msg2));
+ ResourceMessageTestSink::ResourceCallVector open_messages =
+ sink().GetAllResourceCallsMatching(PpapiHostMsg_FileSystem_Open::ID);
+ ASSERT_EQ(2U, open_messages.size());
+ sink().ClearMessages();
- SendOpenReply(params1, PP_OK);
- SendOpenReply(params2, PP_ERROR_FAILED);
+ SendOpenReply(open_messages[0].first, PP_OK);
+ SendOpenReply(open_messages[1].first, PP_ERROR_FAILED);
ASSERT_TRUE(cb.called());
ASSERT_EQ(PP_ERROR_FAILED, cb.result());
@@ -237,8 +233,10 @@
// and a map of all currently open files to their max written offsets.
ResourceMessageCallParams params;
IPC::Message msg;
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg));
+ sink().ClearMessages();
+
int64_t amount = 0;
FileOffsetMap max_written_offsets;
ASSERT_TRUE(UnpackMessage<PpapiHostMsg_FileSystem_ReserveQuota>(
@@ -248,16 +246,18 @@
ASSERT_EQ(0, max_written_offsets[file_io1.get()]);
ASSERT_EQ(0, max_written_offsets[file_io2.get()]);
- // Make another request.
+ // Make another request while the "reserve quota" message is pending.
MockRequestQuotaCallback cb2;
result = file_system_api->RequestQuota(
kQuotaRequestAmount2,
base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb2)));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
-
+ // No new "reserve quota" message should be sent while one is pending.
+ ASSERT_FALSE(sink().GetFirstResourceCallMatching(
+ PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg));
{
ProxyAutoUnlock unlock_to_prevent_deadlock;
- // Reply with quota reservation amount sufficient to cover the two requests.
+ // Reply with quota reservation amount sufficient to cover both requests.
// Both callbacks should be called with the requests granted.
SendReply(params,
PP_OK,
@@ -283,8 +283,9 @@
base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb2)));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg));
+ sink().ClearMessages();
{
ProxyAutoUnlock unlock_to_prevent_deadlock;
// Reply with quota reservation amount insufficient to cover the first
@@ -313,8 +314,9 @@
base::Bind(&MockRequestQuotaCallback::Callback, base::Unretained(&cb2)));
ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg));
+ sink().ClearMessages();
{
ProxyAutoUnlock unlock_to_prevent_deadlock;
// Reply with quota reservation amount sufficient only to cover the first
@@ -330,8 +332,9 @@
ASSERT_FALSE(cb2.called());
// Another request message should have been sent.
- ASSERT_TRUE(sink().GetNextResourceCallMatching(
+ ASSERT_TRUE(sink().GetFirstResourceCallMatching(
PpapiHostMsg_FileSystem_ReserveQuota::ID, ¶ms, &msg));
+ sink().ClearMessages();
{
ProxyAutoUnlock unlock_to_prevent_deadlock;
// Reply with quota reservation amount sufficient to cover the second
diff --git a/ppapi/proxy/resource_message_test_sink.cc b/ppapi/proxy/resource_message_test_sink.cc
index 75a4739..a17e1d5 100644
--- a/ppapi/proxy/resource_message_test_sink.cc
+++ b/ppapi/proxy/resource_message_test_sink.cc
@@ -13,37 +13,29 @@
namespace {
-// Backend for GetFirstResource[Call|Reply]Matching.
+// Backend for GetAllResource[Calls|Replies]Matching.
template<class WrapperMessage, class Params>
-int GetNextResourceMessageMatching(const ResourceMessageTestSink& sink,
- uint32 id,
- int start_index,
- Params* params,
- IPC::Message* nested_msg) {
- if (start_index < 0)
- return -1;
- int message_count = static_cast<int>(sink.message_count());
- for (int i = start_index; i < message_count; i++) {
+std::vector<std::pair<Params, IPC::Message> >
+GetAllResourceMessagesMatching(const ResourceMessageTestSink& sink,
+ uint32 id) {
+ std::vector<std::pair<Params, IPC::Message> > result;
+ for (size_t i = 0; i < sink.message_count(); i++) {
const IPC::Message* msg = sink.GetMessageAt(i);
if (msg->type() == WrapperMessage::ID) {
Params cur_params;
IPC::Message cur_msg;
WrapperMessage::Read(msg, &cur_params, &cur_msg);
if (cur_msg.type() == id) {
- *params = cur_params;
- *nested_msg = cur_msg;
- return i;
+ result.push_back(std::make_pair(cur_params, cur_msg));
}
}
}
- return -1;
+ return result;
}
} // namespace
-ResourceMessageTestSink::ResourceMessageTestSink()
- : next_resource_call_(0),
- next_resource_reply_(0) {
+ResourceMessageTestSink::ResourceMessageTestSink() {
}
ResourceMessageTestSink::~ResourceMessageTestSink() {
@@ -77,48 +69,42 @@
uint32 id,
ResourceMessageCallParams* params,
IPC::Message* nested_msg) const {
- int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall,
- ResourceMessageCallParams>(
- *this, id, 0 /* start_index */, params, nested_msg);
- return index >= 0;
+ ResourceCallVector matching_messages =
+ GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
+ ResourceMessageCallParams>(*this, id);
+ if (matching_messages.empty())
+ return false;
+
+ *params = matching_messages[0].first;
+ *nested_msg = matching_messages[0].second;
+ return true;
}
bool ResourceMessageTestSink::GetFirstResourceReplyMatching(
uint32 id,
ResourceMessageReplyParams* params,
IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply,
- ResourceMessageReplyParams>(
- *this, id, 0 /* start_index */, params, nested_msg);
- return index >= 0;
+ ResourceReplyVector matching_messages =
+ GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
+ ResourceMessageReplyParams>(*this, id);
+ if (matching_messages.empty())
+ return false;
+
+ *params = matching_messages[0].first;
+ *nested_msg = matching_messages[0].second;
+ return true;
}
-bool ResourceMessageTestSink::GetNextResourceCallMatching(
- uint32 id,
- ResourceMessageCallParams* params,
- IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiHostMsg_ResourceCall,
- ResourceMessageCallParams>(
- *this, id, next_resource_call_, params, nested_msg);
- if (index >= 0) {
- next_resource_call_ = index + 1;
- return true;
- }
- return false;
+ResourceMessageTestSink::ResourceCallVector
+ResourceMessageTestSink::GetAllResourceCallsMatching(uint32 id) {
+ return GetAllResourceMessagesMatching<PpapiHostMsg_ResourceCall,
+ ResourceMessageCallParams>(*this, id);
}
-bool ResourceMessageTestSink::GetNextResourceReplyMatching(
- uint32 id,
- ResourceMessageReplyParams* params,
- IPC::Message* nested_msg) {
- int index = GetNextResourceMessageMatching<PpapiPluginMsg_ResourceReply,
- ResourceMessageReplyParams>(
- *this, id, next_resource_reply_, params, nested_msg);
- if (index >= 0) {
- next_resource_reply_ = index + 1;
- return true;
- }
- return false;
+ResourceMessageTestSink::ResourceReplyVector
+ResourceMessageTestSink::GetAllResourceRepliesMatching(uint32 id) {
+ return GetAllResourceMessagesMatching<PpapiPluginMsg_ResourceReply,
+ ResourceMessageReplyParams>(*this, id);
}
ResourceSyncCallHandler::ResourceSyncCallHandler(
diff --git a/ppapi/proxy/resource_message_test_sink.h b/ppapi/proxy/resource_message_test_sink.h
index ff6fa7d..2593aaae 100644
--- a/ppapi/proxy/resource_message_test_sink.h
+++ b/ppapi/proxy/resource_message_test_sink.h
@@ -33,7 +33,7 @@
// Searches the queue for the first resource call message with a nested
// message matching the given ID. On success, returns true and populates the
- // givem params and nested message.
+ // given params and nested message.
bool GetFirstResourceCallMatching(
uint32 id,
ResourceMessageCallParams* params,
@@ -45,25 +45,19 @@
ResourceMessageReplyParams* params,
IPC::Message* nested_msg);
- // Searches the queue for the next resource call message with a nested
- // message matching the given ID. On success, returns true and populates the
- // givem params and nested message. The first time this is called, it is
- // equivalent to GetFirstResourceCallMatching.
- bool GetNextResourceCallMatching(
- uint32 id,
- ResourceMessageCallParams* params,
- IPC::Message* nested_msg);
+ // Searches the queue for all resource call messages with a nested message
+ // matching the given ID.
+ typedef std::pair<ResourceMessageCallParams, IPC::Message> ResourceCall;
+ typedef std::vector<ResourceCall> ResourceCallVector;
+ ResourceCallVector GetAllResourceCallsMatching(uint32 id);
- // Like GetNextResourceCallMatching except for replies.
- bool GetNextResourceReplyMatching(
- uint32 id,
- ResourceMessageReplyParams* params,
- IPC::Message* nested_msg);
+ // Like GetAllResourceCallsMatching except for replies.
+ typedef std::pair<ResourceMessageReplyParams, IPC::Message> ResourceReply;
+ typedef std::vector<ResourceReply> ResourceReplyVector;
+ ResourceReplyVector GetAllResourceRepliesMatching(uint32 id);
private:
scoped_ptr<IPC::Message> sync_reply_msg_;
- int next_resource_call_;
- int next_resource_reply_;
};
// This is a message handler which generates reply messages for synchronous