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

Side by Side Diff: ppapi/proxy/websocket_resource_unittest.cc

Issue 46433002: Support using TrackedCallbacks as hints to determine the handling thread of resource reply messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_var.h" 8 #include "ppapi/c/ppb_var.h"
9 #include "ppapi/c/ppb_websocket.h" 9 #include "ppapi/c/ppb_websocket.h"
10 #include "ppapi/proxy/locking_resource_releaser.h" 10 #include "ppapi/proxy/locking_resource_releaser.h"
11 #include "ppapi/proxy/plugin_message_filter.h"
11 #include "ppapi/proxy/ppapi_messages.h" 12 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/proxy/ppapi_proxy_test.h" 13 #include "ppapi/proxy/ppapi_proxy_test.h"
13 #include "ppapi/proxy/websocket_resource.h" 14 #include "ppapi/proxy/websocket_resource.h"
14 #include "ppapi/shared_impl/ppapi_globals.h" 15 #include "ppapi/shared_impl/ppapi_globals.h"
15 #include "ppapi/shared_impl/ppb_var_shared.h" 16 #include "ppapi/shared_impl/ppb_var_shared.h"
16 #include "ppapi/shared_impl/proxy_lock.h" 17 #include "ppapi/shared_impl/proxy_lock.h"
17 #include "ppapi/shared_impl/resource_tracker.h" 18 #include "ppapi/shared_impl/resource_tracker.h"
18 #include "ppapi/shared_impl/scoped_pp_resource.h" 19 #include "ppapi/shared_impl/scoped_pp_resource.h"
19 #include "ppapi/shared_impl/scoped_pp_var.h" 20 #include "ppapi/shared_impl/scoped_pp_var.h"
20 #include "ppapi/shared_impl/tracked_callback.h" 21 #include "ppapi/shared_impl/tracked_callback.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 PpapiHostMsg_WebSocket_Connect::Schema::Param p; 78 PpapiHostMsg_WebSocket_Connect::Schema::Param p;
78 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p); 79 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p);
79 EXPECT_EQ(url, p.a); 80 EXPECT_EQ(url, p.a);
80 EXPECT_EQ(protocol0, p.b[0]); 81 EXPECT_EQ(protocol0, p.b[0]);
81 EXPECT_EQ(protocol1, p.b[1]); 82 EXPECT_EQ(protocol1, p.b[1]);
82 83
83 // Synthesize a response. 84 // Synthesize a response.
84 ResourceMessageReplyParams reply_params(params.pp_resource(), 85 ResourceMessageReplyParams reply_params(params.pp_resource(),
85 params.sequence()); 86 params.sequence());
86 reply_params.set_result(PP_OK); 87 reply_params.set_result(PP_OK);
87 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 88 PluginMessageFilter::DispatchResourceReplyForTest(
88 PpapiPluginMsg_ResourceReply(reply_params, 89 reply_params,
89 PpapiPluginMsg_WebSocket_ConnectReply(url, protocol1)))); 90 PpapiPluginMsg_WebSocket_ConnectReply(url, protocol1));
90 91
91 EXPECT_EQ(PP_OK, g_callback_result); 92 EXPECT_EQ(PP_OK, g_callback_result);
92 EXPECT_EQ(true, g_callback_called); 93 EXPECT_EQ(true, g_callback_called);
93 } 94 }
94 95
95 // Does a test for unsolicited replies. 96 // Does a test for unsolicited replies.
96 TEST_F(WebSocketResourceTest, UnsolicitedReplies) { 97 TEST_F(WebSocketResourceTest, UnsolicitedReplies) {
97 const PPB_WebSocket_1_0* websocket_iface = 98 const PPB_WebSocket_1_0* websocket_iface =
98 thunk::GetPPB_WebSocket_1_0_Thunk(); 99 thunk::GetPPB_WebSocket_1_0_Thunk();
99 100
100 LockingResourceReleaser res(websocket_iface->Create(pp_instance())); 101 LockingResourceReleaser res(websocket_iface->Create(pp_instance()));
101 102
102 // Check if BufferedAmountReply is handled. 103 // Check if BufferedAmountReply is handled.
103 ResourceMessageReplyParams reply_params(res.get(), 0); 104 ResourceMessageReplyParams reply_params(res.get(), 0);
104 reply_params.set_result(PP_OK); 105 reply_params.set_result(PP_OK);
105 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 106 PluginMessageFilter::DispatchResourceReplyForTest(
106 PpapiPluginMsg_ResourceReply( 107 reply_params,
107 reply_params, 108 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u));
108 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u))));
109 109
110 uint64_t amount = websocket_iface->GetBufferedAmount(res.get()); 110 uint64_t amount = websocket_iface->GetBufferedAmount(res.get());
111 EXPECT_EQ(19760227u, amount); 111 EXPECT_EQ(19760227u, amount);
112 112
113 // Check if StateReply is handled. 113 // Check if StateReply is handled.
114 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 114 PluginMessageFilter::DispatchResourceReplyForTest(
115 PpapiPluginMsg_ResourceReply( 115 reply_params,
116 reply_params, 116 PpapiPluginMsg_WebSocket_StateReply(
117 PpapiPluginMsg_WebSocket_StateReply( 117 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING)));
118 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING)))));
119 118
120 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res.get()); 119 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res.get());
121 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state); 120 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state);
122 } 121 }
123 122
124 TEST_F(WebSocketResourceTest, MessageError) { 123 TEST_F(WebSocketResourceTest, MessageError) {
125 const PPB_WebSocket_1_0* websocket_iface = 124 const PPB_WebSocket_1_0* websocket_iface =
126 thunk::GetPPB_WebSocket_1_0_Thunk(); 125 thunk::GetPPB_WebSocket_1_0_Thunk();
127 126
128 std::string url("ws://ws.google.com"); 127 std::string url("ws://ws.google.com");
129 PP_Var url_var = MakeStringVar(url); 128 PP_Var url_var = MakeStringVar(url);
130 129
131 LockingResourceReleaser res(websocket_iface->Create(pp_instance())); 130 LockingResourceReleaser res(websocket_iface->Create(pp_instance()));
132 131
133 // Establish the connection virtually. 132 // Establish the connection virtually.
134 int32_t result = 133 int32_t result =
135 websocket_iface->Connect(res.get(), url_var, NULL, 0, MakeCallback()); 134 websocket_iface->Connect(res.get(), url_var, NULL, 0, MakeCallback());
136 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 135 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
137 136
138 ResourceMessageCallParams params; 137 ResourceMessageCallParams params;
139 IPC::Message msg; 138 IPC::Message msg;
140 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 139 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
141 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg)); 140 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg));
142 141
143 ResourceMessageReplyParams connect_reply_params(params.pp_resource(), 142 ResourceMessageReplyParams connect_reply_params(params.pp_resource(),
144 params.sequence()); 143 params.sequence());
145 connect_reply_params.set_result(PP_OK); 144 connect_reply_params.set_result(PP_OK);
146 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 145 PluginMessageFilter::DispatchResourceReplyForTest(
147 PpapiPluginMsg_ResourceReply(connect_reply_params, 146 connect_reply_params,
148 PpapiPluginMsg_WebSocket_ConnectReply(url, std::string())))); 147 PpapiPluginMsg_WebSocket_ConnectReply(url, std::string()));
149 148
150 EXPECT_EQ(PP_OK, g_callback_result); 149 EXPECT_EQ(PP_OK, g_callback_result);
151 EXPECT_TRUE(g_callback_called); 150 EXPECT_TRUE(g_callback_called);
152 151
153 PP_Var message; 152 PP_Var message;
154 result = websocket_iface->ReceiveMessage(res.get(), &message, MakeCallback()); 153 result = websocket_iface->ReceiveMessage(res.get(), &message, MakeCallback());
155 EXPECT_FALSE(g_callback_called); 154 EXPECT_FALSE(g_callback_called);
156 155
157 // Synthesize a WebSocket_ErrorReply message. 156 // Synthesize a WebSocket_ErrorReply message.
158 ResourceMessageReplyParams error_reply_params(res.get(), 0); 157 ResourceMessageReplyParams error_reply_params(res.get(), 0);
159 error_reply_params.set_result(PP_OK); 158 error_reply_params.set_result(PP_OK);
160 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 159 PluginMessageFilter::DispatchResourceReplyForTest(
161 PpapiPluginMsg_ResourceReply(error_reply_params, 160 error_reply_params, PpapiPluginMsg_WebSocket_ErrorReply());
162 PpapiPluginMsg_WebSocket_ErrorReply())));
163 161
164 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result); 162 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result);
165 EXPECT_TRUE(g_callback_called); 163 EXPECT_TRUE(g_callback_called);
166 } 164 }
167 165
168 } // namespace proxy 166 } // namespace proxy
169 } // namespace ppapi 167 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698