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

Side by Side Diff: ppapi/tests/test_broker.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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/shared_impl/tracked_callback.cc ('k') | ppapi/tests/test_case.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 "ppapi/tests/test_broker.h" 5 #include "ppapi/tests/test_broker.h"
6 6
7 #if defined(_MSC_VER) 7 #if defined(_MSC_VER)
8 #define OS_WIN 1 8 #define OS_WIN 1
9 #include <windows.h> 9 #include <windows.h>
10 #else 10 #else
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 bool TestBroker::Init() { 205 bool TestBroker::Init() {
206 broker_interface_ = static_cast<const PPB_BrokerTrusted*>( 206 broker_interface_ = static_cast<const PPB_BrokerTrusted*>(
207 pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE)); 207 pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE));
208 return !!broker_interface_; 208 return !!broker_interface_;
209 } 209 }
210 210
211 void TestBroker::RunTests(const std::string& filter) { 211 void TestBroker::RunTests(const std::string& filter) {
212 RUN_TEST(Create, filter); 212 RUN_TEST(Create, filter);
213 RUN_TEST(Create, filter); 213 RUN_TEST(Create, filter);
214 RUN_TEST(GetHandleFailure, filter); 214 RUN_TEST(GetHandleFailure, filter);
215 RUN_TEST(ConnectFailure, filter); 215 RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter);
216 RUN_TEST(ConnectAndPipe, filter); 216 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndPipe, filter);
217 } 217 }
218 218
219 std::string TestBroker::TestCreate() { 219 std::string TestBroker::TestCreate() {
220 // Very simplistic test to make sure we can create a broker interface. 220 // Very simplistic test to make sure we can create a broker interface.
221 PP_Resource broker = broker_interface_->CreateTrusted( 221 PP_Resource broker = broker_interface_->CreateTrusted(
222 instance_->pp_instance()); 222 instance_->pp_instance());
223 ASSERT_TRUE(broker); 223 ASSERT_TRUE(broker);
224 224
225 ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0)); 225 ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0));
226 ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker)); 226 ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker));
227 227
228 PASS(); 228 PASS();
229 } 229 }
230 230
231 // Test connection on invalid resource. 231 // Test connection on invalid resource.
232 std::string TestBroker::TestConnectFailure() { 232 std::string TestBroker::TestConnectFailure() {
233 // Callback NOT force async. Connect should fail. The callback will not be 233 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
234 // posted so there's no need to wait for the callback to complete. 234 callback.WaitForResult(broker_interface_->Connect(0,
235 TestCompletionCallback cb_1(instance_->pp_instance(), false); 235 callback.GetCallback().pp_completion_callback()));
236 ASSERT_EQ(PP_ERROR_BADRESOURCE, 236 CHECK_CALLBACK_BEHAVIOR(callback);
237 broker_interface_->Connect( 237 ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result());
238 0, pp::CompletionCallback(cb_1).pp_completion_callback()));
239
240 // Callback force async. Connect will return PP_OK_COMPLETIONPENDING and the
241 // callback will be posted. However, the callback should fail.
242 TestCompletionCallback cb_2(instance_->pp_instance(), true);
243 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
244 broker_interface_->Connect(
245 0, pp::CompletionCallback(cb_2).pp_completion_callback()));
246 ASSERT_EQ(PP_ERROR_BADRESOURCE, cb_2.WaitForResult());
247 238
248 PASS(); 239 PASS();
249 } 240 }
250 241
251 std::string TestBroker::TestGetHandleFailure() { 242 std::string TestBroker::TestGetHandleFailure() {
252 int32_t handle = kInvalidHandle; 243 int32_t handle = kInvalidHandle;
253 244
254 // Test getting the handle for an invalid resource. 245 // Test getting the handle for an invalid resource.
255 ASSERT_EQ(PP_ERROR_BADRESOURCE, broker_interface_->GetHandle(0, &handle)); 246 ASSERT_EQ(PP_ERROR_BADRESOURCE, broker_interface_->GetHandle(0, &handle));
256 247
257 // Connect hasn't been called so this should fail. 248 // Connect hasn't been called so this should fail.
258 PP_Resource broker = broker_interface_->CreateTrusted( 249 PP_Resource broker = broker_interface_->CreateTrusted(
259 instance_->pp_instance()); 250 instance_->pp_instance());
260 ASSERT_TRUE(broker); 251 ASSERT_TRUE(broker);
261 ASSERT_EQ(PP_ERROR_FAILED, broker_interface_->GetHandle(broker, &handle)); 252 ASSERT_EQ(PP_ERROR_FAILED, broker_interface_->GetHandle(broker, &handle));
262 253
263 PASS(); 254 PASS();
264 } 255 }
265 256
266 std::string TestBroker::TestConnectAndPipe() { 257 std::string TestBroker::TestConnectAndPipe() {
267 PP_Resource broker = broker_interface_->CreateTrusted( 258 PP_Resource broker = broker_interface_->CreateTrusted(
268 instance_->pp_instance()); 259 instance_->pp_instance());
269 ASSERT_TRUE(broker); 260 ASSERT_TRUE(broker);
270 261
271 TestCompletionCallback cb_3(instance_->pp_instance()); 262 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
272 ASSERT_EQ(PP_OK_COMPLETIONPENDING, 263 callback.WaitForResult(broker_interface_->Connect(broker,
273 broker_interface_->Connect( 264 callback.GetCallback().pp_completion_callback()));
274 broker, pp::CompletionCallback(cb_3).pp_completion_callback())); 265 CHECK_CALLBACK_BEHAVIOR(callback);
275 ASSERT_EQ(PP_OK, cb_3.WaitForResult()); 266 ASSERT_EQ(PP_OK, callback.result());
276 267
277 int32_t handle = kInvalidHandle; 268 int32_t handle = kInvalidHandle;
278 ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle)); 269 ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle));
279 ASSERT_NE(kInvalidHandle, handle); 270 ASSERT_NE(kInvalidHandle, handle);
280 271
281 PlatformFile file = IntToPlatformFile(handle); 272 PlatformFile file = IntToPlatformFile(handle);
282 ASSERT_TRUE(VerifyMessage(file, sizeof(kHelloMessage), kHelloMessage)); 273 ASSERT_TRUE(VerifyMessage(file, sizeof(kHelloMessage), kHelloMessage));
283 ASSERT_TRUE(VerifyMessage(file, sizeof(kBrokerUnsandboxed), 274 ASSERT_TRUE(VerifyMessage(file, sizeof(kBrokerUnsandboxed),
284 kBrokerUnsandboxed)); 275 kBrokerUnsandboxed));
285 276
286 ASSERT_TRUE(ClosePlatformFile(file)); 277 ASSERT_TRUE(ClosePlatformFile(file));
287 278
288 PASS(); 279 PASS();
289 } 280 }
OLDNEW
« no previous file with comments | « ppapi/shared_impl/tracked_callback.cc ('k') | ppapi/tests/test_case.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698