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 "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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 bool TestBroker::Init() { | 204 bool TestBroker::Init() { |
205 broker_interface_ = static_cast<const PPB_BrokerTrusted*>( | 205 broker_interface_ = static_cast<const PPB_BrokerTrusted*>( |
206 pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE)); | 206 pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE)); |
207 return !!broker_interface_; | 207 return !!broker_interface_; |
208 } | 208 } |
209 | 209 |
210 void TestBroker::RunTests(const std::string& filter) { | 210 void TestBroker::RunTests(const std::string& filter) { |
211 RUN_TEST(Create, filter); | 211 RUN_TEST(Create, filter); |
212 RUN_TEST(Create, filter); | 212 RUN_TEST(Create, filter); |
213 RUN_TEST(GetHandleFailure, filter); | 213 RUN_TEST(GetHandleFailure, filter); |
214 RUN_TEST(ConnectFailure, filter); | 214 RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter); |
215 RUN_TEST(ConnectAndPipe, filter); | 215 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndPipe, filter); |
216 } | 216 } |
217 | 217 |
218 std::string TestBroker::TestCreate() { | 218 std::string TestBroker::TestCreate() { |
219 // Very simplistic test to make sure we can create a broker interface. | 219 // Very simplistic test to make sure we can create a broker interface. |
220 PP_Resource broker = broker_interface_->CreateTrusted( | 220 PP_Resource broker = broker_interface_->CreateTrusted( |
221 instance_->pp_instance()); | 221 instance_->pp_instance()); |
222 ASSERT_TRUE(broker); | 222 ASSERT_TRUE(broker); |
223 | 223 |
224 ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0)); | 224 ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0)); |
225 ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker)); | 225 ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker)); |
226 | 226 |
227 PASS(); | 227 PASS(); |
228 } | 228 } |
229 | 229 |
230 // Test connection on invalid resource. | 230 // Test connection on invalid resource. |
231 std::string TestBroker::TestConnectFailure() { | 231 std::string TestBroker::TestConnectFailure() { |
232 // Callback NOT force async. Connect should fail. The callback will not be | 232 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
233 // posted so there's no need to wait for the callback to complete. | 233 callback.WaitForResult(broker_interface_->Connect(0, |
234 TestCompletionCallback cb_1(instance_->pp_instance(), false); | 234 callback.GetCallback().pp_completion_callback())); |
235 ASSERT_EQ(PP_ERROR_BADRESOURCE, | 235 CHECK_CALLBACK_BEHAVIOR(callback); |
236 broker_interface_->Connect( | 236 ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result()); |
237 0, pp::CompletionCallback(cb_1).pp_completion_callback())); | |
238 | |
239 // Callback force async. Connect will return PP_OK_COMPLETIONPENDING and the | |
240 // callback will be posted. However, the callback should fail. | |
241 TestCompletionCallback cb_2(instance_->pp_instance(), true); | |
242 ASSERT_EQ(PP_OK_COMPLETIONPENDING, | |
243 broker_interface_->Connect( | |
244 0, pp::CompletionCallback(cb_2).pp_completion_callback())); | |
245 ASSERT_EQ(PP_ERROR_BADRESOURCE, cb_2.WaitForResult()); | |
246 | 237 |
247 PASS(); | 238 PASS(); |
248 } | 239 } |
249 | 240 |
250 std::string TestBroker::TestGetHandleFailure() { | 241 std::string TestBroker::TestGetHandleFailure() { |
251 int32_t handle = kInvalidHandle; | 242 int32_t handle = kInvalidHandle; |
252 | 243 |
253 // Test getting the handle for an invalid resource. | 244 // Test getting the handle for an invalid resource. |
254 ASSERT_EQ(PP_ERROR_BADRESOURCE, broker_interface_->GetHandle(0, &handle)); | 245 ASSERT_EQ(PP_ERROR_BADRESOURCE, broker_interface_->GetHandle(0, &handle)); |
255 | 246 |
256 // Connect hasn't been called so this should fail. | 247 // Connect hasn't been called so this should fail. |
257 PP_Resource broker = broker_interface_->CreateTrusted( | 248 PP_Resource broker = broker_interface_->CreateTrusted( |
258 instance_->pp_instance()); | 249 instance_->pp_instance()); |
259 ASSERT_TRUE(broker); | 250 ASSERT_TRUE(broker); |
260 ASSERT_EQ(PP_ERROR_FAILED, broker_interface_->GetHandle(broker, &handle)); | 251 ASSERT_EQ(PP_ERROR_FAILED, broker_interface_->GetHandle(broker, &handle)); |
261 | 252 |
262 PASS(); | 253 PASS(); |
263 } | 254 } |
264 | 255 |
265 std::string TestBroker::TestConnectAndPipe() { | 256 std::string TestBroker::TestConnectAndPipe() { |
266 PP_Resource broker = broker_interface_->CreateTrusted( | 257 PP_Resource broker = broker_interface_->CreateTrusted( |
267 instance_->pp_instance()); | 258 instance_->pp_instance()); |
268 ASSERT_TRUE(broker); | 259 ASSERT_TRUE(broker); |
269 | 260 |
270 TestCompletionCallback cb_3(instance_->pp_instance()); | 261 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
271 ASSERT_EQ(PP_OK_COMPLETIONPENDING, | 262 callback.WaitForResult(broker_interface_->Connect(broker, |
272 broker_interface_->Connect( | 263 callback.GetCallback().pp_completion_callback())); |
273 broker, pp::CompletionCallback(cb_3).pp_completion_callback())); | 264 CHECK_CALLBACK_BEHAVIOR(callback); |
274 ASSERT_EQ(PP_OK, cb_3.WaitForResult()); | 265 ASSERT_EQ(PP_OK, callback.result()); |
275 | 266 |
276 int32_t handle = kInvalidHandle; | 267 int32_t handle = kInvalidHandle; |
277 ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle)); | 268 ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle)); |
278 ASSERT_NE(kInvalidHandle, handle); | 269 ASSERT_NE(kInvalidHandle, handle); |
279 | 270 |
280 PlatformFile file = IntToPlatformFile(handle); | 271 PlatformFile file = IntToPlatformFile(handle); |
281 ASSERT_TRUE(VerifyMessage(file, sizeof(kHelloMessage), kHelloMessage)); | 272 ASSERT_TRUE(VerifyMessage(file, sizeof(kHelloMessage), kHelloMessage)); |
282 ASSERT_TRUE(VerifyMessage(file, sizeof(kBrokerUnsandboxed), | 273 ASSERT_TRUE(VerifyMessage(file, sizeof(kBrokerUnsandboxed), |
283 kBrokerUnsandboxed)); | 274 kBrokerUnsandboxed)); |
284 | 275 |
285 ASSERT_TRUE(ClosePlatformFile(file)); | 276 ASSERT_TRUE(ClosePlatformFile(file)); |
286 | 277 |
287 PASS(); | 278 PASS(); |
288 } | 279 } |
OLD | NEW |