xhriopool.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * @fileoverview An XhrIo pool that uses a single mock XHR object for testing.
  16. *
  17. */
  18. goog.setTestOnly('goog.testing.net.XhrIoPool');
  19. goog.provide('goog.testing.net.XhrIoPool');
  20. goog.require('goog.net.XhrIoPool');
  21. goog.require('goog.testing.net.XhrIo');
  22. /**
  23. * A pool containing a single mock XhrIo object.
  24. *
  25. * @param {goog.testing.net.XhrIo=} opt_xhr The mock XhrIo object.
  26. * @constructor
  27. * @extends {goog.net.XhrIoPool}
  28. * @final
  29. */
  30. goog.testing.net.XhrIoPool = function(opt_xhr) {
  31. /**
  32. * The mock XhrIo object.
  33. * @type {!goog.testing.net.XhrIo}
  34. * @private
  35. */
  36. this.xhr_ = opt_xhr || new goog.testing.net.XhrIo();
  37. // Run this after setting xhr_ because xhr_ is used to initialize the pool.
  38. goog.testing.net.XhrIoPool.base(this, 'constructor', undefined, 1, 1);
  39. };
  40. goog.inherits(goog.testing.net.XhrIoPool, goog.net.XhrIoPool);
  41. /**
  42. * @override
  43. * @suppress {invalidCasts}
  44. */
  45. goog.testing.net.XhrIoPool.prototype.createObject = function() {
  46. return (/** @type {!goog.net.XhrIo} */ (this.xhr_));
  47. };
  48. /**
  49. * Get the mock XhrIo used by this pool.
  50. *
  51. * @return {!goog.testing.net.XhrIo} The mock XhrIo.
  52. */
  53. goog.testing.net.XhrIoPool.prototype.getXhr = function() {
  54. return this.xhr_;
  55. };