OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.compositor.layouts; | 5 package org.chromium.chrome.browser.compositor.layouts; |
6 | 6 |
7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani
matableAnimation.createAnimation; | 7 import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Ani
matableAnimation.createAnimation; |
8 | 8 |
9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
11 import android.test.InstrumentationTestCase; | 11 |
| 12 import org.junit.Assert; |
| 13 import org.junit.Before; |
| 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; |
12 | 16 |
13 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
14 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable
; | 18 import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable
; |
| 19 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
15 | 20 |
16 /** | 21 /** |
17 * Unit tests for {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn
imation}. | 22 * Unit tests for {@link org.chromium.chrome.browser.compositor.layouts.ChromeAn
imation}. |
18 */ | 23 */ |
19 public class ChromeAnimationTest extends InstrumentationTestCase | 24 @RunWith(ChromeJUnit4ClassRunner.class) |
20 implements Animatable<ChromeAnimationTest.Property> { | 25 public class ChromeAnimationTest implements Animatable<ChromeAnimationTest.Prope
rty> { |
21 | |
22 protected enum Property { | 26 protected enum Property { |
23 FAST_ANIMATION, | 27 FAST_ANIMATION, |
24 SLOW_ANIMATION | 28 SLOW_ANIMATION |
25 } | 29 } |
26 | 30 |
27 private static final long FAST_DURATION = 100; | 31 private static final long FAST_DURATION = 100; |
28 private static final long SLOW_DURATION = 1000; | 32 private static final long SLOW_DURATION = 1000; |
29 | 33 |
30 private ChromeAnimation<Animatable<?>> mAnimations; | 34 private ChromeAnimation<Animatable<?>> mAnimations; |
31 | 35 |
32 private boolean mHasFinishedFastAnimation; | 36 private boolean mHasFinishedFastAnimation; |
33 private boolean mHasFinishedSlowAnimation; | 37 private boolean mHasFinishedSlowAnimation; |
34 | 38 |
35 @Override | 39 @Before |
36 protected void setUp() throws Exception { | 40 public void setUp() throws Exception { |
37 super.setUp(); | |
38 | |
39 mHasFinishedFastAnimation = false; | 41 mHasFinishedFastAnimation = false; |
40 mHasFinishedSlowAnimation = false; | 42 mHasFinishedSlowAnimation = false; |
41 } | 43 } |
42 | 44 |
43 @Override | 45 @Override |
44 public void setProperty(Property prop, float val) {} | 46 public void setProperty(Property prop, float val) {} |
45 | 47 |
46 @Override | 48 @Override |
47 public void onPropertyAnimationFinished(Property prop) { | 49 public void onPropertyAnimationFinished(Property prop) { |
48 if (prop == Property.FAST_ANIMATION) { | 50 if (prop == Property.FAST_ANIMATION) { |
(...skipping 30 matching lines...) Expand all Loading... |
79 */ | 81 */ |
80 private void addToAnimation(ChromeAnimation.Animation<Animatable<?>> compone
nt) { | 82 private void addToAnimation(ChromeAnimation.Animation<Animatable<?>> compone
nt) { |
81 if (mAnimations == null || mAnimations.finished()) { | 83 if (mAnimations == null || mAnimations.finished()) { |
82 mAnimations = new ChromeAnimation<>(); | 84 mAnimations = new ChromeAnimation<>(); |
83 mAnimations.start(); | 85 mAnimations.start(); |
84 } | 86 } |
85 component.start(); | 87 component.start(); |
86 mAnimations.add(component); | 88 mAnimations.add(component); |
87 } | 89 } |
88 | 90 |
| 91 @Test |
89 @SmallTest | 92 @SmallTest |
90 @Feature({"ContextualSearch"}) | 93 @Feature({"ContextualSearch"}) |
91 public void testConcurrentAnimationsFinishSeparately() { | 94 public void testConcurrentAnimationsFinishSeparately() { |
92 addToAnimation(this, Property.FAST_ANIMATION, 0.f, 1.f, FAST_DURATION, 0
); | 95 addToAnimation(this, Property.FAST_ANIMATION, 0.f, 1.f, FAST_DURATION, 0
); |
93 addToAnimation(this, Property.SLOW_ANIMATION, 0.f, 1.f, SLOW_DURATION, 0
); | 96 addToAnimation(this, Property.SLOW_ANIMATION, 0.f, 1.f, SLOW_DURATION, 0
); |
94 | 97 |
95 // Update the animation with the current time. This will internally set
the initial | 98 // Update the animation with the current time. This will internally set
the initial |
96 // time of the animation to |now|. | 99 // time of the animation to |now|. |
97 long now = SystemClock.uptimeMillis(); | 100 long now = SystemClock.uptimeMillis(); |
98 mAnimations.update(now); | 101 mAnimations.update(now); |
99 | 102 |
100 // Advances time to check that the fast animation will finish first. | 103 // Advances time to check that the fast animation will finish first. |
101 mAnimations.update(now + FAST_DURATION); | 104 mAnimations.update(now + FAST_DURATION); |
102 assertTrue(mHasFinishedFastAnimation); | 105 Assert.assertTrue(mHasFinishedFastAnimation); |
103 assertFalse(mHasFinishedSlowAnimation); | 106 Assert.assertFalse(mHasFinishedSlowAnimation); |
104 | 107 |
105 // Advances time to check that all animations are finished. | 108 // Advances time to check that all animations are finished. |
106 mAnimations.update(now + SLOW_DURATION); | 109 mAnimations.update(now + SLOW_DURATION); |
107 assertTrue(mHasFinishedFastAnimation); | 110 Assert.assertTrue(mHasFinishedFastAnimation); |
108 assertTrue(mHasFinishedSlowAnimation); | 111 Assert.assertTrue(mHasFinishedSlowAnimation); |
109 } | 112 } |
110 } | 113 } |
OLD | NEW |