| 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 |
goog.provide('goog.messaging.PortCallerTest'); |
| 16 |
goog.setTestOnly('goog.messaging.PortCallerTest'); |
| 17 |
|
| 18 |
goog.require('goog.events.EventTarget'); |
| 19 |
goog.require('goog.messaging.PortCaller'); |
| 20 |
goog.require('goog.messaging.PortNetwork'); |
| 21 |
goog.require('goog.testing.MockControl'); |
| 22 |
goog.require('goog.testing.jsunit'); |
| 23 |
goog.require('goog.testing.messaging.MockMessageChannel'); |
| 24 |
|
| 25 |
var mockControl; |
| 26 |
var mockChannel; |
| 27 |
var caller; |
| 28 |
|
| 29 |
function setUp() { |
| 30 |
mockControl = new goog.testing.MockControl(); |
| 31 |
mockChannel = new goog.testing.messaging.MockMessageChannel(mockControl); |
| 32 |
caller = new goog.messaging.PortCaller(mockChannel); |
| 33 |
} |
| 34 |
|
| 35 |
function tearDown() { |
| 36 |
goog.dispose(caller); |
| 37 |
mockControl.$verifyAll(); |
| 38 |
} |
| 39 |
|
| 40 |
function MockMessagePort(index, port) { |
| 41 |
MockMessagePort.base(this, 'constructor'); |
| 42 |
this.index = index; |
| 43 |
this.port = port; |
| 44 |
this.started = false; |
| 45 |
} |
| 46 |
goog.inherits(MockMessagePort, goog.events.EventTarget); |
| 47 |
|
| 48 |
|
| 49 |
MockMessagePort.prototype.start = function() { |
| 50 |
this.started = true; |
| 51 |
}; |
| 52 |
|
| 53 |
function testGetPort() { |
| 54 |
mockChannel.send( |
| 55 |
goog.messaging.PortNetwork.REQUEST_CONNECTION_SERVICE, 'foo'); |
| 56 |
mockControl.$replayAll(); |
| 57 |
caller.dial('foo'); |
| 58 |
} |