| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_post_message.h" | 5 #include "ppapi/tests/test_post_message.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ppapi/c/dev/ppb_testing_dev.h" | 9 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 RUN_TEST(ExtraParam); | 37 RUN_TEST(ExtraParam); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void TestPostMessage::HandleMessage(const pp::Var& message_data) { | 40 void TestPostMessage::HandleMessage(const pp::Var& message_data) { |
| 41 message_data_.push_back(message_data); | 41 message_data_.push_back(message_data); |
| 42 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 42 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool TestPostMessage::AddEchoingListener(const std::string& expression) { | 45 bool TestPostMessage::AddEchoingListener(const std::string& expression) { |
| 46 std::string js_code; | 46 std::string js_code; |
| 47 // Note the following code is dependent on some features of test_case.html. | |
| 48 // E.g., it is assumed that the DOM element where the plugin is embedded has | |
| 49 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows | |
| 50 // us to ignore the messages that are intended for use by the testing | |
| 51 // framework itself. | |
| 52 js_code += "var plugin = document.getElementById('plugin');" | 47 js_code += "var plugin = document.getElementById('plugin');" |
| 53 "var message_handler = function(message_event) {" | 48 "var message_handler = function(message_event) {" |
| 54 " if (!IsTestingMessage(message_event.data)) {" | 49 " plugin.postMessage("; |
| 55 " plugin.postMessage("; | |
| 56 js_code += expression; | 50 js_code += expression; |
| 57 js_code += " );" | 51 js_code += " );" |
| 58 " }" | |
| 59 "};" | 52 "};" |
| 60 "plugin.addEventListener('message', message_handler);" | 53 "plugin.addEventListener('message', message_handler);" |
| 61 // Maintain an array of all event listeners, attached to the | 54 // Maintain an array of all event listeners, attached to the |
| 62 // plugin. This is so that we can easily remove them later (see | 55 // plugin. This is so that we can easily remove them later (see |
| 63 // ClearListeners()). | 56 // ClearListeners()). |
| 64 "if (!plugin.eventListeners) plugin.eventListeners = [];" | 57 "if (!plugin.eventListeners) plugin.eventListeners = [];" |
| 65 "plugin.eventListeners.push(message_handler);"; | 58 "plugin.eventListeners.push(message_handler);"; |
| 66 pp::Var exception; | 59 pp::Var exception; |
| 67 instance_->ExecuteScript(js_code, &exception); | 60 instance_->ExecuteScript(js_code, &exception); |
| 68 return exception.is_undefined(); | 61 return exception.is_undefined(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Therefore, we will do CallOnMainThread to yield control. That event should | 235 // Therefore, we will do CallOnMainThread to yield control. That event should |
| 243 // fire, but we should see no messages when we return. | 236 // fire, but we should see no messages when we return. |
| 244 TestCompletionCallback callback(instance_->pp_instance()); | 237 TestCompletionCallback callback(instance_->pp_instance()); |
| 245 pp::Module::Get()->core()->CallOnMainThread(0, callback); | 238 pp::Module::Get()->core()->CallOnMainThread(0, callback); |
| 246 callback.WaitForResult(); | 239 callback.WaitForResult(); |
| 247 ASSERT_TRUE(message_data_.empty()); | 240 ASSERT_TRUE(message_data_.empty()); |
| 248 | 241 |
| 249 PASS(); | 242 PASS(); |
| 250 } | 243 } |
| 251 | 244 |
| OLD | NEW |