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