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. |
47 js_code += "var plugin = document.getElementById('plugin');" | 52 js_code += "var plugin = document.getElementById('plugin');" |
48 "var message_handler = function(message_event) {" | 53 "var message_handler = function(message_event) {" |
49 " plugin.postMessage("; | 54 " if (!IsTestingMessage(message_event.data)) {" |
| 55 " plugin.postMessage("; |
50 js_code += expression; | 56 js_code += expression; |
51 js_code += " );" | 57 js_code += " );" |
| 58 " }" |
52 "};" | 59 "};" |
53 "plugin.addEventListener('message', message_handler);" | 60 "plugin.addEventListener('message', message_handler);" |
54 // Maintain an array of all event listeners, attached to the | 61 // Maintain an array of all event listeners, attached to the |
55 // plugin. This is so that we can easily remove them later (see | 62 // plugin. This is so that we can easily remove them later (see |
56 // ClearListeners()). | 63 // ClearListeners()). |
57 "if (!plugin.eventListeners) plugin.eventListeners = [];" | 64 "if (!plugin.eventListeners) plugin.eventListeners = [];" |
58 "plugin.eventListeners.push(message_handler);"; | 65 "plugin.eventListeners.push(message_handler);"; |
59 pp::Var exception; | 66 pp::Var exception; |
60 instance_->ExecuteScript(js_code, &exception); | 67 instance_->ExecuteScript(js_code, &exception); |
61 return exception.is_undefined(); | 68 return exception.is_undefined(); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // Therefore, we will do CallOnMainThread to yield control. That event should | 242 // Therefore, we will do CallOnMainThread to yield control. That event should |
236 // fire, but we should see no messages when we return. | 243 // fire, but we should see no messages when we return. |
237 TestCompletionCallback callback(instance_->pp_instance()); | 244 TestCompletionCallback callback(instance_->pp_instance()); |
238 pp::Module::Get()->core()->CallOnMainThread(0, callback); | 245 pp::Module::Get()->core()->CallOnMainThread(0, callback); |
239 callback.WaitForResult(); | 246 callback.WaitForResult(); |
240 ASSERT_TRUE(message_data_.empty()); | 247 ASSERT_TRUE(message_data_.empty()); |
241 | 248 |
242 PASS(); | 249 PASS(); |
243 } | 250 } |
244 | 251 |
OLD | NEW |