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 10 matching lines...) Expand all Loading... |
31 // 'message_event' - the message event parameter to the listener function. | 34 // 'message_event' - the message event parameter to the listener function. |
32 // This also adds the new listener to an array called 'eventListeners' on the | 35 // This also adds the new listener to an array called 'eventListeners' on the |
33 // plugin's DOM element. This is used by ClearListeners(). | 36 // plugin's DOM element. This is used by ClearListeners(). |
34 // Returns true on success, false on failure. | 37 // Returns true on success, false on failure. |
35 bool AddEchoingListener(const std::string& expression); | 38 bool AddEchoingListener(const std::string& expression); |
36 | 39 |
37 // Posts a message from JavaScript to the plugin. |func| should be a | 40 // Posts a message from JavaScript to the plugin. |func| should be a |
38 // JavaScript function which returns the variable to post. | 41 // JavaScript function which returns the variable to post. |
39 bool PostMessageFromJavaScript(const std::string& func); | 42 bool PostMessageFromJavaScript(const std::string& func); |
40 | 43 |
| 44 // Posts a message from JavaScript to the plugin. |func| should be a |
| 45 // JavaScript function(callback) which calls |callback| with the variable to |
| 46 // post. To wait for this message to be posted on the plugin side, use |
| 47 // WaitForMessagesAsync, instead of WaitForMessages. |
| 48 bool PostMessageFromJavaScriptAsync(const std::string& func); |
| 49 |
41 // Clear any listeners that have been added using AddEchoingListener by | 50 // Clear any listeners that have been added using AddEchoingListener by |
42 // calling removeEventListener for each. | 51 // calling removeEventListener for each. |
43 // Returns true on success, false on failure. | 52 // Returns true on success, false on failure. |
44 bool ClearListeners(); | 53 bool ClearListeners(); |
45 | 54 |
46 // Wait for pending messages; return the number of messages that were pending | 55 // Wait for pending messages; return the number of messages that were pending |
47 // at the time of invocation. | 56 // at the time of invocation. |
48 int WaitForMessages(); | 57 int WaitForMessages(); |
49 | 58 |
| 59 // Wait for pending messages sent by PostMessageFromJavaScriptAsync; return |
| 60 // the number of messages that were pending at the time of invocation. |
| 61 int WaitForMessagesAsync(); |
| 62 |
50 // Verifies that the given javascript assertions are true of the message | 63 // Verifies that the given javascript assertions are true of the message |
51 // (|test_data|) passed via PostMessage(). | 64 // (|test_data|) passed via PostMessage(). |
52 std::string CheckMessageProperties( | 65 std::string CheckMessageProperties( |
53 const pp::Var& test_data, | 66 const pp::Var& test_data, |
54 const std::vector<std::string>& properties_to_check); | 67 const std::vector<std::string>& properties_to_check); |
55 | 68 |
56 // Test that we can send a message from Instance::Init. Note the actual | 69 // 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 | 70 // message is sent in TestPostMessage::Init, and this test simply makes sure |
58 // we got it. | 71 // we got it. |
59 std::string TestSendInInit(); | 72 std::string TestSendInInit(); |
60 | 73 |
61 // Test some basic functionality; make sure we can send data successfully | 74 // Test some basic functionality; make sure we can send data successfully |
62 // in both directions. | 75 // in both directions. |
63 std::string TestSendingData(); | 76 std::string TestSendingData(); |
64 | 77 |
65 // Test sending ArrayBuffer vars in both directions. | 78 // Test sending ArrayBuffer vars in both directions. |
66 std::string TestSendingArrayBuffer(); | 79 std::string TestSendingArrayBuffer(); |
67 | 80 |
68 // Test sending Array vars in both directions. | 81 // Test sending Array vars in both directions. |
69 std::string TestSendingArray(); | 82 std::string TestSendingArray(); |
70 | 83 |
71 // Test sending Dictionary vars in both directions. | 84 // Test sending Dictionary vars in both directions. |
72 std::string TestSendingDictionary(); | 85 std::string TestSendingDictionary(); |
73 | 86 |
| 87 // Test sending Resource vars from JavaScript to the plugin. |
| 88 // TODO(mgiuca): Test sending Resource vars in both directions. |
| 89 std::string TestSendingResource(); |
| 90 |
74 // Test sending a complex var with references and cycles in both directions. | 91 // Test sending a complex var with references and cycles in both directions. |
75 std::string TestSendingComplexVar(); | 92 std::string TestSendingComplexVar(); |
76 | 93 |
77 // Test the MessageEvent object that JavaScript received to make sure it is | 94 // Test the MessageEvent object that JavaScript received to make sure it is |
78 // of the right type and has all the expected fields. | 95 // of the right type and has all the expected fields. |
79 std::string TestMessageEvent(); | 96 std::string TestMessageEvent(); |
80 | 97 |
81 // Test sending a message when no handler exists, make sure nothing happens. | 98 // Test sending a message when no handler exists, make sure nothing happens. |
82 std::string TestNoHandler(); | 99 std::string TestNoHandler(); |
83 | 100 |
84 // Test sending from JavaScript to the plugin with extra parameters, make sure | 101 // Test sending from JavaScript to the plugin with extra parameters, make sure |
85 // nothing happens. | 102 // nothing happens. |
86 std::string TestExtraParam(); | 103 std::string TestExtraParam(); |
87 | 104 |
88 // Test sending messages off of the main thread. | 105 // Test sending messages off of the main thread. |
89 std::string TestNonMainThread(); | 106 std::string TestNonMainThread(); |
90 | 107 |
91 typedef std::vector<pp::Var> VarVector; | 108 typedef std::vector<pp::Var> VarVector; |
92 | 109 |
93 // This is used to store pp::Var objects we receive via a call to | 110 // This is used to store pp::Var objects we receive via a call to |
94 // HandleMessage. | 111 // HandleMessage. |
95 VarVector message_data_; | 112 VarVector message_data_; |
| 113 |
| 114 // Interfaces for C APIs. |
| 115 const PPB_Core* core_interface_; |
| 116 const PPB_FileSystem* file_system_interface_; |
| 117 const PPB_Var* var_interface_; |
| 118 const PPB_VarResource_Dev* var_resource_interface_; |
96 }; | 119 }; |
97 | 120 |
98 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ | 121 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ |
99 | 122 |
OLD | NEW |