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