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

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

Issue 12378050: PPAPI: Remove threading options; it's always on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PDFResource unit test Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/printing_resource_unittest.cc ('k') | ppapi/shared_impl/resource_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 6 #include "base/message_loop.h"
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_websocket.h" 8 #include "ppapi/c/ppb_websocket.h"
9 #include "ppapi/c/ppb_var.h" 9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/proxy/locking_resource_releaser.h"
10 #include "ppapi/proxy/websocket_resource.h" 11 #include "ppapi/proxy/websocket_resource.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"
14 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/ppb_var_shared.h" 15 #include "ppapi/shared_impl/ppb_var_shared.h"
16 #include "ppapi/shared_impl/proxy_lock.h"
17 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/shared_impl/scoped_pp_resource.h" 18 #include "ppapi/shared_impl/scoped_pp_resource.h"
15 #include "ppapi/shared_impl/scoped_pp_var.h" 19 #include "ppapi/shared_impl/scoped_pp_var.h"
16 #include "ppapi/shared_impl/tracked_callback.h" 20 #include "ppapi/shared_impl/tracked_callback.h"
17 #include "ppapi/shared_impl/var.h" 21 #include "ppapi/shared_impl/var.h"
18 #include "ppapi/thunk/thunk.h" 22 #include "ppapi/thunk/thunk.h"
19 23
20 namespace ppapi { 24 namespace ppapi {
21 namespace proxy { 25 namespace proxy {
22 26
23 namespace { 27 namespace {
(...skipping 28 matching lines...) Expand all
52 TEST_F(WebSocketResourceTest, Connect) { 56 TEST_F(WebSocketResourceTest, Connect) {
53 const PPB_WebSocket_1_0* websocket_iface = 57 const PPB_WebSocket_1_0* websocket_iface =
54 thunk::GetPPB_WebSocket_1_0_Thunk(); 58 thunk::GetPPB_WebSocket_1_0_Thunk();
55 59
56 std::string url("ws://ws.google.com"); 60 std::string url("ws://ws.google.com");
57 std::string protocol0("x-foo"); 61 std::string protocol0("x-foo");
58 std::string protocol1("x-bar"); 62 std::string protocol1("x-bar");
59 PP_Var url_var = MakeStringVar(url); 63 PP_Var url_var = MakeStringVar(url);
60 PP_Var protocols[] = { MakeStringVar(protocol0), MakeStringVar(protocol1) }; 64 PP_Var protocols[] = { MakeStringVar(protocol0), MakeStringVar(protocol1) };
61 65
62 ScopedPPResource res(ScopedPPResource::PassRef(), 66 LockingResourceReleaser res(websocket_iface->Create(pp_instance()));
63 websocket_iface->Create(pp_instance()));
64 67
65 int32_t result = 68 int32_t result = websocket_iface->Connect(res.get(), url_var, protocols, 2,
66 websocket_iface->Connect(res, url_var, protocols, 2, MakeCallback()); 69 MakeCallback());
67 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 70 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
68 71
69 // Should be sent a "Connect" message. 72 // Should be sent a "Connect" message.
70 ResourceMessageCallParams params; 73 ResourceMessageCallParams params;
71 IPC::Message msg; 74 IPC::Message msg;
72 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 75 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
73 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg)); 76 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg));
74 PpapiHostMsg_WebSocket_Connect::Schema::Param p; 77 PpapiHostMsg_WebSocket_Connect::Schema::Param p;
75 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p); 78 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p);
76 EXPECT_EQ(url, p.a); 79 EXPECT_EQ(url, p.a);
(...skipping 10 matching lines...) Expand all
87 90
88 EXPECT_EQ(PP_OK, g_callback_result); 91 EXPECT_EQ(PP_OK, g_callback_result);
89 EXPECT_EQ(true, g_callback_called); 92 EXPECT_EQ(true, g_callback_called);
90 } 93 }
91 94
92 // Does a test for unsolicited replies. 95 // Does a test for unsolicited replies.
93 TEST_F(WebSocketResourceTest, UnsolicitedReplies) { 96 TEST_F(WebSocketResourceTest, UnsolicitedReplies) {
94 const PPB_WebSocket_1_0* websocket_iface = 97 const PPB_WebSocket_1_0* websocket_iface =
95 thunk::GetPPB_WebSocket_1_0_Thunk(); 98 thunk::GetPPB_WebSocket_1_0_Thunk();
96 99
97 ScopedPPResource res(ScopedPPResource::PassRef(), 100 LockingResourceReleaser res(websocket_iface->Create(pp_instance()));
98 websocket_iface->Create(pp_instance()));
99 101
100 // Check if BufferedAmountReply is handled. 102 // Check if BufferedAmountReply is handled.
101 ResourceMessageReplyParams reply_params(res, 0); 103 ResourceMessageReplyParams reply_params(res.get(), 0);
102 reply_params.set_result(PP_OK); 104 reply_params.set_result(PP_OK);
103 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 105 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(
104 PpapiPluginMsg_ResourceReply( 106 PpapiPluginMsg_ResourceReply(
105 reply_params, 107 reply_params,
106 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u)))); 108 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u))));
107 109
108 uint64_t amount = websocket_iface->GetBufferedAmount(res); 110 uint64_t amount = websocket_iface->GetBufferedAmount(res.get());
109 EXPECT_EQ(19760227u, amount); 111 EXPECT_EQ(19760227u, amount);
110 112
111 // Check if StateReply is handled. 113 // Check if StateReply is handled.
112 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 114 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(
113 PpapiPluginMsg_ResourceReply( 115 PpapiPluginMsg_ResourceReply(
114 reply_params, 116 reply_params,
115 PpapiPluginMsg_WebSocket_StateReply( 117 PpapiPluginMsg_WebSocket_StateReply(
116 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING))))); 118 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING)))));
117 119
118 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res); 120 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res.get());
119 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state); 121 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state);
120 } 122 }
121 123
122 TEST_F(WebSocketResourceTest, MessageError) { 124 TEST_F(WebSocketResourceTest, MessageError) {
123 const PPB_WebSocket_1_0* websocket_iface = 125 const PPB_WebSocket_1_0* websocket_iface =
124 thunk::GetPPB_WebSocket_1_0_Thunk(); 126 thunk::GetPPB_WebSocket_1_0_Thunk();
125 127
126 std::string url("ws://ws.google.com"); 128 std::string url("ws://ws.google.com");
127 PP_Var url_var = MakeStringVar(url); 129 PP_Var url_var = MakeStringVar(url);
128 130
129 ScopedPPResource res(ScopedPPResource::PassRef(), 131 LockingResourceReleaser res(websocket_iface->Create(pp_instance()));
130 websocket_iface->Create(pp_instance()));
131 132
132 // Establish the connection virtually. 133 // Establish the connection virtually.
133 int32_t result = 134 int32_t result =
134 websocket_iface->Connect(res, url_var, NULL, 0, MakeCallback()); 135 websocket_iface->Connect(res.get(), url_var, NULL, 0, MakeCallback());
135 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 136 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
136 137
137 ResourceMessageCallParams params; 138 ResourceMessageCallParams params;
138 IPC::Message msg; 139 IPC::Message msg;
139 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 140 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
140 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg)); 141 PpapiHostMsg_WebSocket_Connect::ID, &params, &msg));
141 142
142 ResourceMessageReplyParams connect_reply_params(params.pp_resource(), 143 ResourceMessageReplyParams connect_reply_params(params.pp_resource(),
143 params.sequence()); 144 params.sequence());
144 connect_reply_params.set_result(PP_OK); 145 connect_reply_params.set_result(PP_OK);
145 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 146 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(
146 PpapiPluginMsg_ResourceReply(connect_reply_params, 147 PpapiPluginMsg_ResourceReply(connect_reply_params,
147 PpapiPluginMsg_WebSocket_ConnectReply(url, std::string())))); 148 PpapiPluginMsg_WebSocket_ConnectReply(url, std::string()))));
148 149
149 EXPECT_EQ(PP_OK, g_callback_result); 150 EXPECT_EQ(PP_OK, g_callback_result);
150 EXPECT_TRUE(g_callback_called); 151 EXPECT_TRUE(g_callback_called);
151 152
152 PP_Var message; 153 PP_Var message;
153 result = websocket_iface->ReceiveMessage(res, &message, MakeCallback()); 154 result = websocket_iface->ReceiveMessage(res.get(), &message, MakeCallback());
154 EXPECT_FALSE(g_callback_called); 155 EXPECT_FALSE(g_callback_called);
155 156
156 // Synthesize a WebSocket_ErrorReply message. 157 // Synthesize a WebSocket_ErrorReply message.
157 ResourceMessageReplyParams error_reply_params(res, 0); 158 ResourceMessageReplyParams error_reply_params(res.get(), 0);
158 error_reply_params.set_result(PP_OK); 159 error_reply_params.set_result(PP_OK);
159 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( 160 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(
160 PpapiPluginMsg_ResourceReply(error_reply_params, 161 PpapiPluginMsg_ResourceReply(error_reply_params,
161 PpapiPluginMsg_WebSocket_ErrorReply()))); 162 PpapiPluginMsg_WebSocket_ErrorReply())));
162 163
163 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result); 164 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result);
164 EXPECT_TRUE(g_callback_called); 165 EXPECT_TRUE(g_callback_called);
165 } 166 }
166 167
167 } // namespace proxy 168 } // namespace proxy
168 } // namespace ppapi 169 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/printing_resource_unittest.cc ('k') | ppapi/shared_impl/resource_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698