abstractchannel_test.js 2.4 KB

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