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 | |
183 // Set up a special listener that only responds to a FINISHED_WAITING string. | 175 // Set up a special listener that only responds to a FINISHED_WAITING string. |
184 // This is for use by WaitForMessages. | 176 // This is for use by WaitForMessages. |
185 std::string js_code; | 177 std::string js_code; |
186 // Note the following code is dependent on some features of test_case.html. | 178 // Note the following code is dependent on some features of test_case.html. |
187 // E.g., it is assumed that the DOM element where the plugin is embedded has | 179 // E.g., it is assumed that the DOM element where the plugin is embedded has |
188 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows | 180 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows |
189 // us to ignore the messages that are intended for use by the testing | 181 // us to ignore the messages that are intended for use by the testing |
190 // framework itself. | 182 // framework itself. |
191 js_code += "var plugin = document.getElementById('plugin');" | 183 js_code += "var plugin = document.getElementById('plugin');" |
192 "var wait_for_messages_handler = function(message_event) {" | 184 "var wait_for_messages_handler = function(message_event) {" |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 ASSERT_TRUE(received_value <= kThreadsToRun); | 901 ASSERT_TRUE(received_value <= kThreadsToRun); |
910 ++received_counts[received_value]; | 902 ++received_counts[received_value]; |
911 } | 903 } |
912 ASSERT_EQ(expected_counts, received_counts); | 904 ASSERT_EQ(expected_counts, received_counts); |
913 | 905 |
914 message_data_.clear(); | 906 message_data_.clear(); |
915 ASSERT_TRUE(ClearListeners()); | 907 ASSERT_TRUE(ClearListeners()); |
916 | 908 |
917 PASS(); | 909 PASS(); |
918 } | 910 } |
OLD | NEW |