portcaller_test.js 1.7 KB

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