Index: ppapi/tests/test_post_message.cc |
diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc |
index 8c67ee5a7c1b8907c89d6d86708ba8145cccba1f..373ab70e331e86cebe6ac3cc068808f21082b866 100644 |
--- a/ppapi/tests/test_post_message.cc |
+++ b/ppapi/tests/test_post_message.cc |
@@ -238,6 +238,16 @@ bool TestPostMessage::AddEchoingListener(const std::string& expression) { |
return true; |
} |
+bool TestPostMessage::PostMessageFromJavaScript(const std::string& func) { |
+ std::string js_code; |
+ js_code += "var plugin = document.getElementById('plugin');" |
+ " plugin.postMessage("; |
dmichael (off chromium)
2013/06/04 16:59:10
nit: inner code should line up with "var", not "pl
raymes
2013/06/04 19:36:06
Done.
|
+ js_code += func + "()"; |
+ js_code += " );"; |
+ instance_->EvalScript(js_code); |
+ return true; |
+} |
+ |
bool TestPostMessage::ClearListeners() { |
std::string js_code; |
js_code += "var plugin = document.getElementById('plugin');" |
@@ -531,7 +541,6 @@ std::string TestPostMessage::TestSendingComplexVar() { |
dictionary.Set(pp::Var("bar"), string); |
dictionary.Set(pp::Var("abc"), pp::Var(kTestInt)); |
dictionary.Set(pp::Var("def"), pp::Var()); |
- dictionary.Set(pp::Var("dictionary"), dictionary); // Self-reference. |
// Reference to array. |
pp::VarArray_Dev array; |
@@ -544,11 +553,6 @@ std::string TestPostMessage::TestSendingComplexVar() { |
dictionary.Set(pp::Var("array-ref1"), array); |
dictionary.Set(pp::Var("array-ref2"), array); |
- // Set up a (dictionary -> array -> dictionary) cycle. |
- pp::VarArray_Dev array2; |
- array2.Set(0, dictionary); |
- dictionary.Set(pp::Var("array2"), array2); |
- |
// Set up the JavaScript message event listener to echo the data part of the |
// message event back to us. |
ASSERT_TRUE(AddEchoingListener("message_event.data")); |
@@ -561,15 +565,40 @@ std::string TestPostMessage::TestSendingComplexVar() { |
pp::VarDictionary_Dev result(message_data_.back()); |
ASSERT_TRUE(VarsEqual(dictionary, message_data_.back())); |
+ message_data_.clear(); |
+ WaitForMessages(); |
+ ASSERT_TRUE(ClearListeners()); |
+ |
+ // Set up a (dictionary -> array -> dictionary) cycle. Cycles shouldn't be |
+ // transmitted. |
+ pp::VarArray_Dev array2; |
+ array2.Set(0, dictionary); |
+ dictionary.Set(pp::Var("array2"), array2); |
+ |
+ ASSERT_TRUE(AddEchoingListener("message_event.data")); |
+ message_data_.clear(); |
+ instance_->PostMessage(dictionary); |
+ // PostMessage is asynchronous, so we should not receive a response yet. |
+ ASSERT_EQ(message_data_.size(), 0); |
+ ASSERT_EQ(WaitForMessages(), 1); |
+ ASSERT_TRUE(message_data_.back().is_undefined()); |
+ |
// Break the cycles. |
- dictionary.Delete(pp::Var("dictionary")); |
dictionary.Delete(pp::Var("array2")); |
- result.Delete(pp::Var("dictionary")); |
- result.Delete(pp::Var("array2")); |
message_data_.clear(); |
ASSERT_TRUE(ClearListeners()); |
+ // Test sending a cycle from JavaScript to the plugin. |
+ PostMessageFromJavaScript("function() { var x = []; x[0] = x; return x; }"); |
+ ASSERT_EQ(message_data_.size(), 0); |
+ ASSERT_EQ(WaitForMessages(), 1); |
+ ASSERT_TRUE(message_data_.back().is_undefined()); |
+ |
+ message_data_.clear(); |
+ WaitForMessages(); |
+ ASSERT_TRUE(ClearListeners()); |
+ |
PASS(); |
} |