OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_message_handler.h" | 5 #include "ppapi/tests/test_message_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 ppb_messaging_if_ = static_cast<const PPB_Messaging_1_2*>( | 214 ppb_messaging_if_ = static_cast<const PPB_Messaging_1_2*>( |
215 pp::Module::Get()->GetBrowserInterface(PPB_MESSAGING_INTERFACE_1_2)); | 215 pp::Module::Get()->GetBrowserInterface(PPB_MESSAGING_INTERFACE_1_2)); |
216 return ppb_messaging_if_ && | 216 return ppb_messaging_if_ && |
217 CheckTestingInterface() && | 217 CheckTestingInterface() && |
218 handler_thread_.Start(); | 218 handler_thread_.Start(); |
219 } | 219 } |
220 | 220 |
221 void TestMessageHandler::RunTests(const std::string& filter) { | 221 void TestMessageHandler::RunTests(const std::string& filter) { |
222 RUN_TEST(RegisterErrorConditions, filter); | 222 RUN_TEST(RegisterErrorConditions, filter); |
223 RUN_TEST(PostMessageAndAwaitResponse, filter); | 223 RUN_TEST(PostMessageAndAwaitResponse, filter); |
| 224 RUN_TEST(ArrayBuffer, filter); |
224 RUN_TEST(Exceptions, filter); | 225 RUN_TEST(Exceptions, filter); |
225 } | 226 } |
226 | 227 |
227 void TestMessageHandler::HandleMessage(const pp::Var& message_data) { | 228 void TestMessageHandler::HandleMessage(const pp::Var& message_data) { |
228 if (instance()->current_test_name() == "Exceptions") { | 229 if (instance()->current_test_name() == "Exceptions") { |
229 // For TestPostMessageAndAwaitResponse(), all messages should go to the | 230 // For TestPostMessageAndAwaitResponse(), all messages should go to the |
230 // background thread message handler. | 231 // background thread message handler. |
231 assert(false); | 232 assert(false); |
232 } else { | 233 } else { |
233 // Any subtest causing a message to arrive here must wait for it before | 234 // Any subtest causing a message to arrive here must wait for it before |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 298 } |
298 instance_->EvalScript(js_code); | 299 instance_->EvalScript(js_code); |
299 instance_->EvalScript("plugin.postMessage('FINISHED_TEST');\n"); | 300 instance_->EvalScript("plugin.postMessage('FINISHED_TEST');\n"); |
300 handler.WaitForTestFinishedMessage(); | 301 handler.WaitForTestFinishedMessage(); |
301 handler.Unregister(); | 302 handler.Unregister(); |
302 ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy()); | 303 ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy()); |
303 | 304 |
304 PASS(); | 305 PASS(); |
305 } | 306 } |
306 | 307 |
| 308 std::string TestMessageHandler::TestArrayBuffer() { |
| 309 // Set the array buffer shared memory threshold so that some of the |
| 310 // ArrayBuffer values will be sent as shared memory. |
| 311 ScopedArrayBufferSizeSetter setter(testing_interface_, |
| 312 instance_->pp_instance(), |
| 313 200); |
| 314 const char* const sizes[] = { "0", "128", "1024", "4096", NULL }; |
| 315 MyMessageHandler handler(instance(), |
| 316 handler_thread_.message_loop()); |
| 317 handler.Register(); |
| 318 std::string js_code("var plugin = document.getElementById('plugin');\n"); |
| 319 js_code += "var result = undefined;\n"; |
| 320 js_code += "var param = undefined;\n"; |
| 321 for (size_t i = 0; sizes[i]; ++i) { |
| 322 js_code += "param = new ArrayBuffer("; |
| 323 js_code += sizes[i]; |
| 324 js_code += ");"; |
| 325 // TODO(dmichael): It would be better to set specific values in param. |
| 326 js_code += "result = plugin.postMessageAndAwaitResponse(param);"; |
| 327 js_code += "if (!deepCompare(result, param))\n"; |
| 328 js_code += " InternalError(\" Failed postMessageAndAwaitResponse for "; |
| 329 js_code += "ArrayBuffer of size: "; |
| 330 js_code += sizes[i]; |
| 331 js_code += " result: \" + result);\n"; |
| 332 } |
| 333 instance_->EvalScript(js_code); |
| 334 instance_->EvalScript("plugin.postMessage('FINISHED_TEST');\n"); |
| 335 handler.WaitForTestFinishedMessage(); |
| 336 handler.Unregister(); |
| 337 ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy()); |
| 338 |
| 339 PASS(); |
| 340 } |
| 341 |
307 std::string TestMessageHandler::TestExceptions() { | 342 std::string TestMessageHandler::TestExceptions() { |
308 MyMessageHandler handler(instance(), | 343 MyMessageHandler handler(instance(), |
309 handler_thread_.message_loop()); | 344 handler_thread_.message_loop()); |
310 { | 345 { |
311 // First, try sending a blocking message when there is no handler | 346 // First, try sending a blocking message when there is no handler |
312 // registered. It should throw an exception. | 347 // registered. It should throw an exception. |
313 std::string js_code( | 348 std::string js_code( |
314 "var plugin = document.getElementById('plugin');\n" | 349 "var plugin = document.getElementById('plugin');\n" |
315 "var caught_exception = false;\n" | 350 "var caught_exception = false;\n" |
316 "try {\n" | 351 "try {\n" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 398 } |
364 | 399 |
365 pp::Var TestMessageHandler::WaitForMessage() { | 400 pp::Var TestMessageHandler::WaitForMessage() { |
366 message_received_.Wait(); | 401 message_received_.Wait(); |
367 pp::Var var_to_return = last_message_; | 402 pp::Var var_to_return = last_message_; |
368 last_message_ = pp::Var(); | 403 last_message_ = pp::Var(); |
369 message_received_.Reset(); | 404 message_received_.Reset(); |
370 return var_to_return; | 405 return var_to_return; |
371 } | 406 } |
372 | 407 |
OLD | NEW |