sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
123 lines (107 loc) • 3.36 kB
HTML
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<head>
<title>
Closure Unit Tests - goog.messaging.MultiChannel
</title>
<script src="../base.js"></script>
<script>
goog.require('goog.testing.MockControl');
goog.require('goog.testing.messaging.MockMessageChannel');
goog.require('goog.testing.mockmatchers.IgnoreArgument');
goog.require('goog.testing.jsunit');
goog.require('goog.messaging.MultiChannel');
</script>
</head>
<body>
<script>
var mockControl;
var mockChannel;
var multiChannel;
var channel1;
var channel2;
function setUp() {
mockControl = new goog.testing.MockControl();
mockChannel = new goog.testing.messaging.MockMessageChannel(mockControl);
multiChannel = new goog.messaging.MultiChannel(mockChannel);
channel0 = multiChannel.createVirtualChannel('foo');
channel1 = multiChannel.createVirtualChannel('bar');
}
function expectedFn(name, callback) {
var ignored = new goog.testing.mockmatchers.IgnoreArgument();
var fn = mockControl.createFunctionMock(name);
fn(ignored).$does(function(args) {
callback.apply(this, args);
});
return function() { fn(arguments); };
}
function notExpectedFn() {
return mockControl.createFunctionMock('notExpectedFn');
}
function assertEqualsFn() {
var expectedArgs = Array.prototype.slice.call(arguments);
return expectedFn('assertEqualsFn', function() {
assertObjectEquals(expectedArgs, Array.prototype.slice.call(arguments));
});
}
function tearDown() {
multiChannel.dispose();
mockControl.$verifyAll();
assertTrue(mockChannel.disposed);
}
function testSend0() {
mockChannel.send('foo:fooBar', {foo: 'bar'});
mockControl.$replayAll();
channel0.send('fooBar', {foo: 'bar'});
}
function testSend1() {
mockChannel.send('bar:fooBar', {foo: 'bar'});
mockControl.$replayAll();
channel1.send('fooBar', {foo: 'bar'});
}
function testReceive0() {
channel0.registerService('fooBar', assertEqualsFn('Baz bang'));
channel1.registerService('fooBar', notExpectedFn());
mockControl.$replayAll();
mockChannel.receive('foo:fooBar', 'Baz bang');
}
function testReceive1() {
channel1.registerService('fooBar', assertEqualsFn('Baz bang'));
channel0.registerService('fooBar', notExpectedFn());
mockControl.$replayAll();
mockChannel.receive('bar:fooBar', 'Baz bang');
}
function testDefaultReceive0() {
channel0.registerDefaultService(assertEqualsFn('fooBar', 'Baz bang'));
channel1.registerDefaultService(notExpectedFn());
mockControl.$replayAll();
mockChannel.receive('foo:fooBar', 'Baz bang');
}
function testDefaultReceive1() {
channel1.registerDefaultService(assertEqualsFn('fooBar', 'Baz bang'));
channel0.registerDefaultService(notExpectedFn());
mockControl.$replayAll();
mockChannel.receive('bar:fooBar', 'Baz bang');
}
function testReceiveAfterDisposed() {
channel0.registerService('fooBar', notExpectedFn());
mockControl.$replayAll();
channel0.dispose();
mockChannel.receive('foo:fooBar', 'Baz bang');
}
function testReceiveAfterParentDisposed() {
channel0.registerService('fooBar', notExpectedFn());
mockControl.$replayAll();
multiChannel.dispose();
mockChannel.receive('foo:fooBar', 'Baz bang');
}
</script>
</body>
</html>