Debian Codegraph @

closure-library/closure/goog/testing/messaging/mockmessageport.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview A simple dummy class for representing message ports in tests.
17 *
18 */
19
20 goog.setTestOnly('goog.testing.messaging.MockMessagePort');
21 goog.provide('goog.testing.messaging.MockMessagePort');
22
23 goog.require('goog.events.EventTarget');
24
25
26
27 /**
28 * Class for unit-testing code that uses MessagePorts.
29 * @param {*} id An opaque identifier, used because message ports otherwise have
30 * no distinguishing characteristics.
31 * @param {goog.testing.MockControl} mockControl The mock control used to create
32 * the method mock for #postMessage.
33 * @constructor
34 * @extends {goog.events.EventTarget}
35 * @final
36 */
37 goog.testing.messaging.MockMessagePort = function(id, mockControl) {
38 goog.testing.messaging.MockMessagePort.base(this, 'constructor');
39
40 /**
41 * An opaque identifier, used because message ports otherwise have no
42 * distinguishing characteristics.
43 * @type {*}
44 */
45 this.id = id;
46
47 /**
48 * Whether or not the port has been started.
49 * @type {boolean}
50 */
51 this.started = false;
52
53 /**
54 * Whether or not the port has been closed.
55 * @type {boolean}
56 */
57 this.closed = false;
58
59 mockControl.createMethodMock(this, 'postMessage');
60 };
61 goog.inherits(goog.testing.messaging.MockMessagePort, goog.events.EventTarget);
62
63
64 /**
65 * A mock postMessage funciton. Actually an instance of
66 * {@link goog.testing.FunctionMock}.
67 * @param {*} message The message to send.
68 * @param {Array<MessagePort>=} opt_ports Ports to send with the message.
69 */
70 goog.testing.messaging.MockMessagePort.prototype.postMessage = function(
71 message, opt_ports) {};
72
73
74 /**
75 * Starts the port.
76 */
77 goog.testing.messaging.MockMessagePort.prototype.start = function() {
78 this.started = true;
79 };
80
81
82 /**
83 * Closes the port.
84 */
85 goog.testing.messaging.MockMessagePort.prototype.close = function() {
86 this.closed = true;
87 };