mockrange.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2008 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 LooseMock of goog.dom.AbstractRange.
  16. *
  17. */
  18. goog.setTestOnly('goog.testing.MockRange');
  19. goog.provide('goog.testing.MockRange');
  20. goog.require('goog.dom.AbstractRange');
  21. goog.require('goog.testing.LooseMock');
  22. /**
  23. * LooseMock of goog.dom.AbstractRange. Useful because the mock framework cannot
  24. * simply create a mock out of an abstract class, and cannot create a mock out
  25. * of classes that implements __iterator__ because it relies on the default
  26. * behavior of iterating through all of an object's properties.
  27. * @constructor
  28. * @extends {goog.testing.LooseMock}
  29. * @final
  30. */
  31. goog.testing.MockRange = function() {
  32. goog.testing.LooseMock.call(this, goog.testing.MockRange.ConcreteRange_);
  33. };
  34. goog.inherits(goog.testing.MockRange, goog.testing.LooseMock);
  35. // *** Private helper class ************************************************* //
  36. /**
  37. * Concrete subclass of goog.dom.AbstractRange that simply sets the abstract
  38. * method __iterator__ to undefined so that javascript defaults to iterating
  39. * through all of the object's properties.
  40. * @constructor
  41. * @extends {goog.dom.AbstractRange}
  42. * @private
  43. */
  44. goog.testing.MockRange.ConcreteRange_ = function() {
  45. goog.dom.AbstractRange.call(this);
  46. };
  47. goog.inherits(goog.testing.MockRange.ConcreteRange_, goog.dom.AbstractRange);
  48. /**
  49. * Undefine the iterator so the mock framework can loop through this class'
  50. * properties.
  51. * @override
  52. */
  53. goog.testing.MockRange.ConcreteRange_.prototype.__iterator__ =
  54. // This isn't really type-safe.
  55. /** @type {?} */ (undefined);