fx_test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. goog.provide('goog.fxTest');
  15. goog.setTestOnly('goog.fxTest');
  16. goog.require('goog.fx.Animation');
  17. goog.require('goog.object');
  18. goog.require('goog.testing.MockClock');
  19. goog.require('goog.testing.PropertyReplacer');
  20. goog.require('goog.testing.jsunit');
  21. // TODO(arv): Add tests for the event dispatches.
  22. // TODO(arv): Add tests for the calculation of the coordinates.
  23. var clock, replacer, anim, anim2;
  24. var Animation = goog.fx.Animation;
  25. function setUpPage() {
  26. clock = new goog.testing.MockClock(true);
  27. }
  28. function tearDownPage() {
  29. clock.dispose();
  30. }
  31. function setUp() {
  32. replacer = new goog.testing.PropertyReplacer();
  33. }
  34. function tearDown() {
  35. replacer.reset();
  36. if (anim && anim.dispose) {
  37. anim.dispose();
  38. }
  39. if (anim2 && anim2.dispose) {
  40. anim2.dispose();
  41. }
  42. }
  43. function testAnimationConstructor() {
  44. assertThrows('Should throw since first arg is not an array', function() {
  45. new Animation(1, [2], 3);
  46. });
  47. assertThrows('Should throw since second arg is not an array', function() {
  48. new Animation([1], 2, 3);
  49. });
  50. assertThrows('Should throw since the length are different', function() {
  51. new Animation([0, 1], [2], 3);
  52. });
  53. }
  54. function testPlayAndStopDoesNotLeaveAnyActiveAnimations() {
  55. anim = new Animation([0], [1], 1000);
  56. assertTrue(
  57. 'There should be no active animations',
  58. goog.object.isEmpty(goog.fx.anim.activeAnimations_));
  59. anim.play();
  60. assertEquals(
  61. 'There should be one active animations', 1,
  62. goog.object.getCount(goog.fx.anim.activeAnimations_));
  63. anim.stop();
  64. assertTrue(
  65. 'There should be no active animations',
  66. goog.object.isEmpty(goog.fx.anim.activeAnimations_));
  67. anim.play();
  68. assertEquals(
  69. 'There should be one active animations', 1,
  70. goog.object.getCount(goog.fx.anim.activeAnimations_));
  71. anim.pause();
  72. assertTrue(
  73. 'There should be no active animations',
  74. goog.object.isEmpty(goog.fx.anim.activeAnimations_));
  75. }