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