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_post_message.h" | 5 #include "ppapi/tests/test_post_message.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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 js_code += "var plugin = document.getElementById('plugin');" | 165 js_code += "var plugin = document.getElementById('plugin');" |
166 "plugin.removeEventListener('message'," | 166 "plugin.removeEventListener('message'," |
167 " plugin.wait_for_messages_handler);" | 167 " plugin.wait_for_messages_handler);" |
168 "delete plugin.wait_for_messages_handler;"; | 168 "delete plugin.wait_for_messages_handler;"; |
169 instance_->EvalScript(js_code); | 169 instance_->EvalScript(js_code); |
170 } | 170 } |
171 | 171 |
172 bool TestPostMessage::Init() { | 172 bool TestPostMessage::Init() { |
173 bool success = CheckTestingInterface(); | 173 bool success = CheckTestingInterface(); |
174 | 174 |
| 175 // Add a post condition to tests which caches the postMessage function and |
| 176 // then calls it after the instance is destroyed. The ensures that no UAF |
| 177 // occurs because the MessageChannel may still be alive after the plugin |
| 178 // instance is destroyed (it will get garbage collected eventually). |
| 179 instance_->EvalScript("window.pluginPostMessage = " |
| 180 "document.getElementById('plugin').postMessage"); |
| 181 instance_->AddPostCondition("window.pluginPostMessage('') === undefined"); |
| 182 |
175 // Set up a special listener that only responds to a FINISHED_WAITING string. | 183 // Set up a special listener that only responds to a FINISHED_WAITING string. |
176 // This is for use by WaitForMessages. | 184 // This is for use by WaitForMessages. |
177 std::string js_code; | 185 std::string js_code; |
178 // Note the following code is dependent on some features of test_case.html. | 186 // Note the following code is dependent on some features of test_case.html. |
179 // E.g., it is assumed that the DOM element where the plugin is embedded has | 187 // E.g., it is assumed that the DOM element where the plugin is embedded has |
180 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows | 188 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows |
181 // us to ignore the messages that are intended for use by the testing | 189 // us to ignore the messages that are intended for use by the testing |
182 // framework itself. | 190 // framework itself. |
183 js_code += "var plugin = document.getElementById('plugin');" | 191 js_code += "var plugin = document.getElementById('plugin');" |
184 "var wait_for_messages_handler = function(message_event) {" | 192 "var wait_for_messages_handler = function(message_event) {" |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 ASSERT_TRUE(received_value <= kThreadsToRun); | 909 ASSERT_TRUE(received_value <= kThreadsToRun); |
902 ++received_counts[received_value]; | 910 ++received_counts[received_value]; |
903 } | 911 } |
904 ASSERT_EQ(expected_counts, received_counts); | 912 ASSERT_EQ(expected_counts, received_counts); |
905 | 913 |
906 message_data_.clear(); | 914 message_data_.clear(); |
907 ASSERT_TRUE(ClearListeners()); | 915 ASSERT_TRUE(ClearListeners()); |
908 | 916 |
909 PASS(); | 917 PASS(); |
910 } | 918 } |
OLD | NEW |