| 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/tests/test_case.h" | 11 #include "ppapi/tests/test_case.h" |
| 12 | 12 |
| 13 class TestPostMessage : public TestCase { | 13 class TestPostMessage : public TestCase { |
| 14 public: | 14 public: |
| 15 explicit TestPostMessage(TestingInstance* instance) : TestCase(instance) {} | 15 explicit TestPostMessage(TestingInstance* instance); |
| 16 virtual ~TestPostMessage(); |
| 16 | 17 |
| 17 private: | 18 private: |
| 18 // TestCase implementation. | 19 // TestCase implementation. |
| 19 virtual bool Init(); | 20 virtual bool Init(); |
| 20 virtual void RunTest(); | 21 virtual void RunTest(); |
| 21 | 22 |
| 22 // A handler for JS->Native calls to postMessage. Simply pushes | 23 // A handler for JS->Native calls to postMessage. Simply pushes |
| 23 // the given value to the back of message_data_ | 24 // the given value to the back of message_data_ |
| 24 virtual void HandleMessage(const pp::Var& message_data); | 25 virtual void HandleMessage(const pp::Var& message_data); |
| 25 | 26 |
| 26 // Add a listener for message events which will echo back the given | 27 // Add a listener for message events which will echo back the given |
| 27 // JavaScript expression by passing it to postMessage. JavaScript Variables | 28 // JavaScript expression by passing it to postMessage. JavaScript Variables |
| 28 // available to the expression are: | 29 // available to the expression are: |
| 29 // 'plugin' - the DOM element for the test plugin. | 30 // 'plugin' - the DOM element for the test plugin. |
| 30 // 'message_event' - the message event parameter to the listener function. | 31 // 'message_event' - the message event parameter to the listener function. |
| 31 // This also adds the new listener to an array called 'eventListeners' on the | 32 // This also adds the new listener to an array called 'eventListeners' on the |
| 32 // plugin's DOM element. This is used by ClearListeners(). | 33 // plugin's DOM element. This is used by ClearListeners(). |
| 33 // Returns true on success, false on failure. | 34 // Returns true on success, false on failure. |
| 34 bool AddEchoingListener(const std::string& expression); | 35 bool AddEchoingListener(const std::string& expression); |
| 35 | 36 |
| 36 // Clear any listeners that have been added using AddEchoingListener by | 37 // Clear any listeners that have been added using AddEchoingListener by |
| 37 // calling removeEventListener for each. | 38 // calling removeEventListener for each. |
| 38 // Returns true on success, false on failure. | 39 // Returns true on success, false on failure. |
| 39 bool ClearListeners(); | 40 bool ClearListeners(); |
| 40 | 41 |
| 42 // Wait for pending messages; return the number of messages that were pending |
| 43 // at the time of invocation. |
| 44 int WaitForMessages(); |
| 45 |
| 46 // Test that we can send a message from Instance::Init. Note the actual |
| 47 // message is sent in TestPostMessage::Init, and this test simply makes sure |
| 48 // we got it. |
| 49 std::string TestSendInInit(); |
| 50 |
| 41 // Test some basic functionality; make sure we can send data successfully | 51 // Test some basic functionality; make sure we can send data successfully |
| 42 // in both directions. | 52 // in both directions. |
| 43 std::string TestSendingData(); | 53 std::string TestSendingData(); |
| 44 | 54 |
| 45 // Test the MessageEvent object that JavaScript received to make sure it is | 55 // Test the MessageEvent object that JavaScript received to make sure it is |
| 46 // of the right type and has all the expected fields. | 56 // of the right type and has all the expected fields. |
| 47 std::string TestMessageEvent(); | 57 std::string TestMessageEvent(); |
| 48 | 58 |
| 49 // Test sending a message when no handler exists, make sure nothing happens. | 59 // Test sending a message when no handler exists, make sure nothing happens. |
| 50 std::string TestNoHandler(); | 60 std::string TestNoHandler(); |
| 51 | 61 |
| 52 // Test sending from JavaScript to the plugin with extra parameters, make sure | 62 // Test sending from JavaScript to the plugin with extra parameters, make sure |
| 53 // nothing happens. | 63 // nothing happens. |
| 54 std::string TestExtraParam(); | 64 std::string TestExtraParam(); |
| 55 | 65 |
| 56 // Test sending messages off of the main thread. | 66 // Test sending messages off of the main thread. |
| 57 std::string TestNonMainThread(); | 67 std::string TestNonMainThread(); |
| 58 | 68 |
| 59 typedef std::vector<pp::Var> VarVector; | 69 typedef std::vector<pp::Var> VarVector; |
| 60 | 70 |
| 61 // This is used to store pp::Var objects we receive via a call to | 71 // This is used to store pp::Var objects we receive via a call to |
| 62 // HandleMessage. | 72 // HandleMessage. |
| 63 VarVector message_data_; | 73 VarVector message_data_; |
| 74 |
| 75 // Used by WaitForMessages. Indicates whether we have received a message |
| 76 // indicating we are finished waiting for messages for now. |
| 77 bool finished_waiting_; |
| 64 }; | 78 }; |
| 65 | 79 |
| 66 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ | 80 #endif // PPAPI_TESTS_TEST_POST_MESSAGE_H_ |
| 67 | 81 |
| OLD | NEW |