Debian Codegraph @

closure-library/closure/goog/testing/messaging/mockportnetwork.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 fake PortNetwork implementation that simply produces
17 * MockMessageChannels for all ports.
18 *
19 */
20
21 goog.setTestOnly('goog.testing.messaging.MockPortNetwork');
22 goog.provide('goog.testing.messaging.MockPortNetwork');
23
24 goog.require('goog.messaging.PortNetwork'); // interface
25 goog.require('goog.testing.messaging.MockMessageChannel');
26
27
28
29 /**
30 * The fake PortNetwork.
31 *
32 * @param {!goog.testing.MockControl} mockControl The mock control for creating
33 * the mock message channels.
34 * @constructor
35 * @implements {goog.messaging.PortNetwork}
36 * @final
37 */
38 goog.testing.messaging.MockPortNetwork = function(mockControl) {
39 /**
40 * The mock control for creating mock message channels.
41 * @type {!goog.testing.MockControl}
42 * @private
43 */
44 this.mockControl_ = mockControl;
45
46 /**
47 * The mock ports that have been created.
48 * @type {!Object<!goog.testing.messaging.MockMessageChannel>}
49 * @private
50 */
51 this.ports_ = {};
52 };
53
54
55 /**
56 * Get the mock port with the given name.
57 * @param {string} name The name of the port to get.
58 * @return {!goog.testing.messaging.MockMessageChannel} The mock port.
59 * @override
60 */
61 goog.testing.messaging.MockPortNetwork.prototype.dial = function(name) {
62 if (!(name in this.ports_)) {
63 this.ports_[name] =
64 new goog.testing.messaging.MockMessageChannel(this.mockControl_);
65 }
66 return this.ports_[name];
67 };