Chromium Code Reviews| Index: ppapi/tests/test_post_message.cc |
| diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc |
| index b1e30b23a2c106c8e0a0852f525b9a29ee7728b4..766e185a326bb03eb08ecc0e604b16e1a9150c4f 100644 |
| --- a/ppapi/tests/test_post_message.cc |
| +++ b/ppapi/tests/test_post_message.cc |
| @@ -161,6 +161,18 @@ TestPostMessage::~TestPostMessage() { |
| bool TestPostMessage::Init() { |
| bool success = CheckTestingInterface(); |
| + core_interface_ = static_cast<const PPB_Core*>( |
| + pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); |
| + file_system_interface_ = static_cast<const PPB_FileSystem*>( |
| + pp::Module::Get()->GetBrowserInterface(PPB_FILESYSTEM_INTERFACE)); |
| + var_interface_ = static_cast<const PPB_Var*>( |
| + pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); |
| + var_resource_interface_ = static_cast<const PPB_VarResource_Dev*>( |
| + pp::Module::Get()->GetBrowserInterface(PPB_VAR_RESOURCE_DEV_INTERFACE)); |
| + if (!core_interface_ || !file_system_interface_ || !var_interface_ || |
| + !var_resource_interface_) |
| + return false; |
| + |
| // Set up a special listener that only responds to a FINISHED_WAITING string. |
| // This is for use by WaitForMessages. |
| std::string js_code; |
| @@ -201,6 +213,7 @@ void TestPostMessage::RunTests(const std::string& filter) { |
| RUN_TEST(SendingArrayBuffer, filter); |
| RUN_TEST(SendingArray, filter); |
| RUN_TEST(SendingDictionary, filter); |
| + RUN_TEST(SendingResource, filter); |
| RUN_TEST(SendingComplexVar, filter); |
| RUN_TEST(MessageEvent, filter); |
| RUN_TEST(NoHandler, filter); |
| @@ -253,6 +266,21 @@ bool TestPostMessage::PostMessageFromJavaScript(const std::string& func) { |
| return true; |
| } |
| +bool TestPostMessage::PostMessageFromJavaScriptAsync(const std::string& func) { |
| + // After the |func| calls callback, post both the given |message|, as well as |
| + // the special message FINISHED_WAITING_MESSAGE. This ensures that |
| + // WaitForMessagesAsync correctly waits until the callback is called. |
| + std::string js_code; |
| + js_code += "var plugin = document.getElementById('plugin');" |
| + "var callback = function(message) {" |
| + " plugin.postMessage(message);" |
| + " plugin.postMessage('" FINISHED_WAITING_MESSAGE "');" |
| + "};"; |
| + js_code += "(" + func + ")(callback);"; |
| + instance_->EvalScript(js_code); |
| + return true; |
| +} |
| + |
| bool TestPostMessage::ClearListeners() { |
| std::string js_code; |
| js_code += "var plugin = document.getElementById('plugin');" |
| @@ -276,6 +304,18 @@ int TestPostMessage::WaitForMessages() { |
| return message_data_.size() - message_size_before; |
| } |
| +int TestPostMessage::WaitForMessagesAsync() { |
| + size_t message_size_before = message_data_.size(); |
| + // Unlike WaitForMessages, we do not post FINISHED_WAITING_MESSAGE. This is |
| + // because PostMessageFromJavaScriptAsync will post it for us, when the |
| + // asynchronous operation completes. |
| + testing_interface_->RunMessageLoop(instance_->pp_instance()); |
| + // Now that the FINISHED_WAITING_MESSAGE has been echoed back to us, we know |
| + // that all pending messages have been slurped up. Return the number we |
| + // received (which may be zero). |
| + return message_data_.size() - message_size_before; |
| +} |
| + |
| std::string TestPostMessage::CheckMessageProperties( |
| const pp::Var& test_data, |
| const std::vector<std::string>& properties_to_check) { |
| @@ -533,6 +573,39 @@ std::string TestPostMessage::TestSendingDictionary() { |
| PASS(); |
| } |
| +std::string TestPostMessage::TestSendingResource() { |
| + // Clean up after previous tests. This also swallows the message sent by Init |
| + // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' |
| + // should start with these. |
| + WaitForMessages(); |
| + message_data_.clear(); |
| + ASSERT_TRUE(ClearListeners()); |
| + |
| + // Test sending a DOMFileSystem from JavaScript to the plugin. |
| + ASSERT_TRUE(AddEchoingListener("message_event.data")); |
| + PostMessageFromJavaScriptAsync( |
| + "function(callback) { " |
| + " window.webkitRequestFileSystem(window.TEMPORARY, 1024, callback);" |
| + "}"); |
| + ASSERT_EQ(message_data_.size(), 0); |
| + ASSERT_EQ(WaitForMessagesAsync(), 1); |
| + // TODO(mgiuca): Use the C++ API instead of the C API, when it is available. |
| + PP_Var var = message_data_.back().Detach(); |
| + PP_Resource result = var_resource_interface_->VarToResource(var); |
| + ASSERT_TRUE(file_system_interface_->IsFileSystem(result)); |
|
raymes
2013/10/22 05:59:21
Can we test some properties of the file system mat
Matt Giuca
2013/10/23 08:05:54
Done. (I just want you to know how hard this was!)
|
| + core_interface_->ReleaseResource(result); |
| + var_interface_->Release(var); |
| + |
| + WaitForMessages(); |
| + message_data_.clear(); |
| + ASSERT_TRUE(ClearListeners()); |
| + |
| + // TODO(mgiuca): Test roundtrip from plugin to JS and back, when the plugin to |
| + // JS support is available. |
| + |
| + PASS(); |
| +} |
| + |
| std::string TestPostMessage::TestSendingComplexVar() { |
| // Clean up after previous tests. This also swallows the message sent by Init |
| // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' |