OLD | NEW |
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" | |
11 #include "ppapi/proxy/websocket_resource.h" | 10 #include "ppapi/proxy/websocket_resource.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/proxy/ppapi_proxy_test.h" | 12 #include "ppapi/proxy/ppapi_proxy_test.h" |
14 #include "ppapi/shared_impl/ppapi_globals.h" | |
15 #include "ppapi/shared_impl/ppb_var_shared.h" | 13 #include "ppapi/shared_impl/ppb_var_shared.h" |
16 #include "ppapi/shared_impl/proxy_lock.h" | |
17 #include "ppapi/shared_impl/resource_tracker.h" | |
18 #include "ppapi/shared_impl/scoped_pp_resource.h" | 14 #include "ppapi/shared_impl/scoped_pp_resource.h" |
19 #include "ppapi/shared_impl/scoped_pp_var.h" | 15 #include "ppapi/shared_impl/scoped_pp_var.h" |
20 #include "ppapi/shared_impl/tracked_callback.h" | 16 #include "ppapi/shared_impl/tracked_callback.h" |
21 #include "ppapi/shared_impl/var.h" | 17 #include "ppapi/shared_impl/var.h" |
22 #include "ppapi/thunk/thunk.h" | 18 #include "ppapi/thunk/thunk.h" |
23 | 19 |
24 namespace ppapi { | 20 namespace ppapi { |
25 namespace proxy { | 21 namespace proxy { |
26 | 22 |
27 namespace { | 23 namespace { |
(...skipping 28 matching lines...) Expand all Loading... |
56 TEST_F(WebSocketResourceTest, Connect) { | 52 TEST_F(WebSocketResourceTest, Connect) { |
57 const PPB_WebSocket_1_0* websocket_iface = | 53 const PPB_WebSocket_1_0* websocket_iface = |
58 thunk::GetPPB_WebSocket_1_0_Thunk(); | 54 thunk::GetPPB_WebSocket_1_0_Thunk(); |
59 | 55 |
60 std::string url("ws://ws.google.com"); | 56 std::string url("ws://ws.google.com"); |
61 std::string protocol0("x-foo"); | 57 std::string protocol0("x-foo"); |
62 std::string protocol1("x-bar"); | 58 std::string protocol1("x-bar"); |
63 PP_Var url_var = MakeStringVar(url); | 59 PP_Var url_var = MakeStringVar(url); |
64 PP_Var protocols[] = { MakeStringVar(protocol0), MakeStringVar(protocol1) }; | 60 PP_Var protocols[] = { MakeStringVar(protocol0), MakeStringVar(protocol1) }; |
65 | 61 |
66 LockingResourceReleaser res(websocket_iface->Create(pp_instance())); | 62 ScopedPPResource res(ScopedPPResource::PassRef(), |
| 63 websocket_iface->Create(pp_instance())); |
67 | 64 |
68 int32_t result = websocket_iface->Connect(res.get(), url_var, protocols, 2, | 65 int32_t result = |
69 MakeCallback()); | 66 websocket_iface->Connect(res, url_var, protocols, 2, MakeCallback()); |
70 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); | 67 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
71 | 68 |
72 // Should be sent a "Connect" message. | 69 // Should be sent a "Connect" message. |
73 ResourceMessageCallParams params; | 70 ResourceMessageCallParams params; |
74 IPC::Message msg; | 71 IPC::Message msg; |
75 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 72 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
76 PpapiHostMsg_WebSocket_Connect::ID, ¶ms, &msg)); | 73 PpapiHostMsg_WebSocket_Connect::ID, ¶ms, &msg)); |
77 PpapiHostMsg_WebSocket_Connect::Schema::Param p; | 74 PpapiHostMsg_WebSocket_Connect::Schema::Param p; |
78 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p); | 75 PpapiHostMsg_WebSocket_Connect::Read(&msg, &p); |
79 EXPECT_EQ(url, p.a); | 76 EXPECT_EQ(url, p.a); |
(...skipping 10 matching lines...) Expand all Loading... |
90 | 87 |
91 EXPECT_EQ(PP_OK, g_callback_result); | 88 EXPECT_EQ(PP_OK, g_callback_result); |
92 EXPECT_EQ(true, g_callback_called); | 89 EXPECT_EQ(true, g_callback_called); |
93 } | 90 } |
94 | 91 |
95 // Does a test for unsolicited replies. | 92 // Does a test for unsolicited replies. |
96 TEST_F(WebSocketResourceTest, UnsolicitedReplies) { | 93 TEST_F(WebSocketResourceTest, UnsolicitedReplies) { |
97 const PPB_WebSocket_1_0* websocket_iface = | 94 const PPB_WebSocket_1_0* websocket_iface = |
98 thunk::GetPPB_WebSocket_1_0_Thunk(); | 95 thunk::GetPPB_WebSocket_1_0_Thunk(); |
99 | 96 |
100 LockingResourceReleaser res(websocket_iface->Create(pp_instance())); | 97 ScopedPPResource res(ScopedPPResource::PassRef(), |
| 98 websocket_iface->Create(pp_instance())); |
101 | 99 |
102 // Check if BufferedAmountReply is handled. | 100 // Check if BufferedAmountReply is handled. |
103 ResourceMessageReplyParams reply_params(res.get(), 0); | 101 ResourceMessageReplyParams reply_params(res, 0); |
104 reply_params.set_result(PP_OK); | 102 reply_params.set_result(PP_OK); |
105 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 103 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( |
106 PpapiPluginMsg_ResourceReply( | 104 PpapiPluginMsg_ResourceReply( |
107 reply_params, | 105 reply_params, |
108 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u)))); | 106 PpapiPluginMsg_WebSocket_BufferedAmountReply(19760227u)))); |
109 | 107 |
110 uint64_t amount = websocket_iface->GetBufferedAmount(res.get()); | 108 uint64_t amount = websocket_iface->GetBufferedAmount(res); |
111 EXPECT_EQ(19760227u, amount); | 109 EXPECT_EQ(19760227u, amount); |
112 | 110 |
113 // Check if StateReply is handled. | 111 // Check if StateReply is handled. |
114 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 112 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( |
115 PpapiPluginMsg_ResourceReply( | 113 PpapiPluginMsg_ResourceReply( |
116 reply_params, | 114 reply_params, |
117 PpapiPluginMsg_WebSocket_StateReply( | 115 PpapiPluginMsg_WebSocket_StateReply( |
118 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING))))); | 116 static_cast<int32_t>(PP_WEBSOCKETREADYSTATE_CLOSING))))); |
119 | 117 |
120 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res.get()); | 118 PP_WebSocketReadyState state = websocket_iface->GetReadyState(res); |
121 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state); | 119 EXPECT_EQ(PP_WEBSOCKETREADYSTATE_CLOSING, state); |
122 } | 120 } |
123 | 121 |
124 TEST_F(WebSocketResourceTest, MessageError) { | 122 TEST_F(WebSocketResourceTest, MessageError) { |
125 const PPB_WebSocket_1_0* websocket_iface = | 123 const PPB_WebSocket_1_0* websocket_iface = |
126 thunk::GetPPB_WebSocket_1_0_Thunk(); | 124 thunk::GetPPB_WebSocket_1_0_Thunk(); |
127 | 125 |
128 std::string url("ws://ws.google.com"); | 126 std::string url("ws://ws.google.com"); |
129 PP_Var url_var = MakeStringVar(url); | 127 PP_Var url_var = MakeStringVar(url); |
130 | 128 |
131 LockingResourceReleaser res(websocket_iface->Create(pp_instance())); | 129 ScopedPPResource res(ScopedPPResource::PassRef(), |
| 130 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, 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, ¶ms, &msg)); | 140 PpapiHostMsg_WebSocket_Connect::ID, ¶ms, &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 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( |
147 PpapiPluginMsg_ResourceReply(connect_reply_params, | 146 PpapiPluginMsg_ResourceReply(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, &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, 0); |
159 error_reply_params.set_result(PP_OK); | 158 error_reply_params.set_result(PP_OK); |
160 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 159 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( |
161 PpapiPluginMsg_ResourceReply(error_reply_params, | 160 PpapiPluginMsg_ResourceReply(error_reply_params, |
162 PpapiPluginMsg_WebSocket_ErrorReply()))); | 161 PpapiPluginMsg_WebSocket_ErrorReply()))); |
163 | 162 |
164 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result); | 163 EXPECT_EQ(PP_ERROR_FAILED, g_callback_result); |
165 EXPECT_TRUE(g_callback_called); | 164 EXPECT_TRUE(g_callback_called); |
166 } | 165 } |
167 | 166 |
168 } // namespace proxy | 167 } // namespace proxy |
169 } // namespace ppapi | 168 } // namespace ppapi |
OLD | NEW |