| 1 |
// Copyright 2010 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.AbstractChannelTest'); |
| 16 |
goog.setTestOnly('goog.messaging.AbstractChannelTest'); |
| 17 |
|
| 18 |
goog.require('goog.messaging.AbstractChannel'); |
| 19 |
goog.require('goog.testing.MockControl'); |
| 20 |
goog.require('goog.testing.async.MockControl'); |
| 21 |
goog.require('goog.testing.jsunit'); |
| 22 |
|
| 23 |
var mockControl; |
| 24 |
var mockWorker; |
| 25 |
var asyncMockControl; |
| 26 |
var channel; |
| 27 |
|
| 28 |
function setUp() { |
| 29 |
mockControl = new goog.testing.MockControl(); |
| 30 |
asyncMockControl = new goog.testing.async.MockControl(mockControl); |
| 31 |
channel = new goog.messaging.AbstractChannel(); |
| 32 |
} |
| 33 |
|
| 34 |
function tearDown() { |
| 35 |
channel.dispose(); |
| 36 |
mockControl.$verifyAll(); |
| 37 |
} |
| 38 |
|
| 39 |
function testConnect() { |
| 40 |
channel.connect( |
| 41 |
asyncMockControl.createCallbackMock('connectCallback', function() {})); |
| 42 |
} |
| 43 |
|
| 44 |
function testIsConnected() { |
| 45 |
assertTrue('Channel should be connected by default', channel.isConnected()); |
| 46 |
} |
| 47 |
|
| 48 |
function testDeliverString() { |
| 49 |
channel.registerService( |
| 50 |
'foo', asyncMockControl.asyncAssertEquals( |
| 51 |
'should pass string to service', 'bar'), |
| 52 |
false /* opt_json */); |
| 53 |
channel.deliver('foo', 'bar'); |
| 54 |
} |
| 55 |
|
| 56 |
function testDeliverDeserializedString() { |
| 57 |
channel.registerService( |
| 58 |
'foo', asyncMockControl.asyncAssertEquals( |
| 59 |
'should pass string to service', '{"bar":"baz"}'), |
| 60 |
false /* opt_json */); |
| 61 |
channel.deliver('foo', {bar: 'baz'}); |
| 62 |
} |
| 63 |
|
| 64 |
function testDeliverObject() { |
| 65 |
channel.registerService( |
| 66 |
'foo', asyncMockControl.asyncAssertEquals( |
| 67 |
'should pass string to service', {bar: 'baz'}), |
| 68 |
true /* opt_json */); |
| 69 |
channel.deliver('foo', {bar: 'baz'}); |
| 70 |
} |
| 71 |
|
| 72 |
function testDeliverSerializedObject() { |
| 73 |
channel.registerService( |
| 74 |
'foo', asyncMockControl.asyncAssertEquals( |
| 75 |
'should pass string to service', {bar: 'baz'}), |
| 76 |
true /* opt_json */); |
| 77 |
channel.deliver('foo', '{"bar":"baz"}'); |
| 78 |
} |