| 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 #ifndef PPAPI_TESTS_TEST_POST_MESSAGE_H_ | 5 #ifndef PPAPI_TESTS_TEST_POST_MESSAGE_H_ |
| 6 #define PPAPI_TESTS_TEST_POST_MESSAGE_H_ | 6 #define PPAPI_TESTS_TEST_POST_MESSAGE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ppapi/c/dev/ppb_var_resource_dev.h" |
| 12 #include "ppapi/c/ppb_file_system.h" |
| 13 #include "ppapi/c/ppb_var.h" |
| 11 #include "ppapi/tests/test_case.h" | 14 #include "ppapi/tests/test_case.h" |
| 12 | 15 |
| 13 class TestPostMessage : public TestCase { | 16 class TestPostMessage : public TestCase { |
| 14 public: | 17 public: |
| 15 explicit TestPostMessage(TestingInstance* instance); | 18 explicit TestPostMessage(TestingInstance* instance); |
| 16 virtual ~TestPostMessage(); | 19 virtual ~TestPostMessage(); |
| 17 | 20 |
| 18 private: | 21 private: |
| 19 // TestCase implementation. | 22 // TestCase implementation. |
| 20 virtual bool Init(); | 23 virtual bool Init(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 | 43 |
| 41 // Clear any listeners that have been added using AddEchoingListener by | 44 // Clear any listeners that have been added using AddEchoingListener by |
| 42 // calling removeEventListener for each. | 45 // calling removeEventListener for each. |
| 43 // Returns true on success, false on failure. | 46 // Returns true on success, false on failure. |
| 44 bool ClearListeners(); | 47 bool ClearListeners(); |
| 45 | 48 |
| 46 // Wait for pending messages; return the number of messages that were pending | 49 // Wait for pending messages; return the number of messages that were pending |
| 47 // at the time of invocation. | 50 // at the time of invocation. |
| 48 int WaitForMessages(); | 51 int WaitForMessages(); |
| 49 | 52 |
| 53 // Posts a message from JavaScript to the plugin and wait for it to arrive. |
| 54 // |func| should be a JavaScript function(callback) which calls |callback| |
| 55 // with the variable to post. This function will block until the message |
| 56 // arrives on the plugin side (there is no need to use WaitForMessages()). |
| 57 // Returns the number of messages that were pending at the time of invocation. |
| 58 int PostAsyncMessageFromJavaScriptAndWait(const std::string& func); |
| 59 |
| 50 // Verifies that the given javascript assertions are true of the message | 60 // Verifies that the given javascript assertions are true of the message |
| 51 // (|test_data|) passed via PostMessage(). | 61 // (|test_data|) passed via PostMessage(). |
| 52 std::string CheckMessageProperties( | 62 std::string CheckMessageProperties( |
| 53 const pp::Var& test_data, | 63 const pp::Var& test_data, |
| 54 const std::vector<std::string>& properties_to_check); | 64 const std::vector<std::string>& properties_to_check); |
| 55 | 65 |
| 56 // Test that we can send a message from Instance::Init. Note the actual | 66 // Test that we can send a message from Instance::Init. Note the actual |
| 57 // message is sent in TestPostMessage::Init, and this test simply makes sure | 67 // message is sent in TestPostMessage::Init, and this test simply makes sure |
| 58 // we got it. | 68 // we got it. |
| 59 std::string TestSendInInit(); | 69 std::string TestSendInInit(); |
| 60 | 70 |
| 61 // Test some basic functionality; make sure we can send data successfully | 71 // Test some basic functionality; make sure we can send data successfully |
| 62 // in both directions. | 72 // in both directions. |
| 63 std::string TestSendingData(); | 73 std::string TestSendingData(); |
| 64 | 74 |
| 65 // Test sending ArrayBuffer vars in both directions. | 75 // Test sending ArrayBuffer vars in both directions. |
| 66 std::string TestSendingArrayBuffer(); | 76 std::string TestSendingArrayBuffer(); |
| 67 | 77 |
| 68 // Test sending Array vars in both directions. | 78 // Test sending Array vars in both directions. |
| 69 std::string TestSendingArray(); | 79 std::string TestSendingArray(); |
| 70 | 80 |
| 71 // Test sending Dictionary vars in both directions. | 81 // Test sending Dictionary vars in both directions. |
| 72 std::string TestSendingDictionary(); | 82 std::string TestSendingDictionary(); |
| 73 | 83 |
| 84 // Test sending Resource vars from JavaScript to the plugin. |
| 85 // TODO(mgiuca): Test sending Resource vars in both directions. |
| 86 std::string TestSendingResource(); |
| 87 |
| 74 // Test sending a complex var with references and cycles in both directions. | 88 // Test sending a complex var with references and cycles in both directions. |
| 75 std::string TestSendingComplexVar(); | 89 std::string TestSendingComplexVar(); |
| 76 | 90 |
| 77 // Test the MessageEvent object that JavaScript received to make sure it is | 91 // Test the MessageEvent object that JavaScript received to make sure it is |
| 78 // of the right type and has all the expected fields. | 92 // of the right type and has all the expected fields. |
| 79 std::string TestMessageEvent(); | 93 std::string TestMessageEvent(); |
| 80 | 94 |
| 81 // Test sending a message when no handler exists, make sure nothing happens. | 95 // Test sending a message when no handler exists, make sure nothing happens. |
| 82 std::string TestNoHandler(); | 96 std::string TestNoHandler(); |
| 83 | 97 |
| 84 // Test sending from JavaScript to the plugin with extra parameters, make sure | 98 // Test sending from JavaScript to the plugin with extra parameters, make sure |
| 85 // nothing happens. | 99 // nothing happens. |
| 86 std::string TestExtraParam(); | 100 std::string TestExtraParam(); |
| 87 | 101 |
| 88 // Test sending messages off of the main thread. | 102 // Test sending messages off of the main thread. |
| 89 std::string TestNonMainThread(); | 103 std::string TestNonMainThread(); |
| 90 | 104 |
| 91 typedef std::vector<pp::Var> VarVector; | 105 typedef std::vector<pp::Var> VarVector; |
| 92 | 106 |
| 93 // This is used to store pp::Var objects we receive via a call to | 107 // This is used to store pp::Var objects we receive via a call to |
| 94 // HandleMessage. | 108 // HandleMessage. |
| 95 VarVector message_data_; | 109 VarVector message_data_; |
| 110 |
| 111 // Interfaces for C APIs. |
| 112 const PPB_Core* core_interface_; |
| 113 const PPB_FileSystem* file_system_interface_; |
| 114 const PPB_Var* var_interface_; |
| 115 const PPB_VarResource_Dev* var_resource_interface_; |
| 96 }; | 116 }; |
| 97 | 117 |
| 98 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ | 118 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ |
| 99 | 119 |
| OLD | NEW |