Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4292)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimationTest.java

Issue 1801363006: Adding callback for finished property animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding unit test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutTab.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimationTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimationTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..6e283aa7ff2182cc41fbc49497938bfe077a520f
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimationTest.java
@@ -0,0 +1,110 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.compositor.layouts;
+
+import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.AnimatableAnimation.createAnimation;
+
+import android.os.SystemClock;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable;
+
+/**
+ * Unit tests for {@link org.chromium.chrome.browser.compositor.layouts.ChromeAnimation}.
+ */
+public class ChromeAnimationTest extends InstrumentationTestCase
+ implements Animatable<ChromeAnimationTest.Property> {
+
+ protected enum Property {
+ FAST_ANIMATION,
+ SLOW_ANIMATION
+ }
+
+ private static final long FAST_DURATION = 100;
+ private static final long SLOW_DURATION = 1000;
+
+ private ChromeAnimation<Animatable<?>> mAnimations;
+
+ private boolean mHasFinishedFastAnimation;
+ private boolean mHasFinishedSlowAnimation;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mHasFinishedFastAnimation = false;
+ mHasFinishedSlowAnimation = false;
+ }
+
+ @Override
+ public void setProperty(Property prop, float val) {}
+
+ @Override
+ public void onPropertyAnimationFinished(Property prop) {
+ if (prop == Property.FAST_ANIMATION) {
+ mHasFinishedFastAnimation = true;
+ } else if (prop == Property.SLOW_ANIMATION) {
+ mHasFinishedSlowAnimation = true;
+ }
+ }
+
+ /**
+ * Creates an {@link org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable}
+ * and adds it to the animation.
+ * Automatically sets the start value at the beginning of the animation.
+ *
+ * @param <T> The Enum type of the Property being used
+ * @param object The object being animated
+ * @param prop The property being animated
+ * @param start The starting value of the animation
+ * @param end The ending value of the animation
+ * @param duration The duration of the animation in ms
+ * @param startTime The start time in ms
+ */
+ private <T extends Enum<?>> void addToAnimation(Animatable<T> object, T prop,
+ float start, float end, long duration, long startTime) {
+ ChromeAnimation.Animation<Animatable<?>> component = createAnimation(
+ object, prop, start, end, duration, startTime, false,
+ ChromeAnimation.getDecelerateInterpolator());
+ addToAnimation(component);
+ }
+
+ /**
+ * Appends an Animation to the current animation set and starts it immediately. If the set is
+ * already finished or doesn't exist, the animation set is also started.
+ */
+ private void addToAnimation(ChromeAnimation.Animation<Animatable<?>> component) {
+ if (mAnimations == null || mAnimations.finished()) {
+ mAnimations = new ChromeAnimation<>();
+ mAnimations.start();
+ }
+ component.start();
+ mAnimations.add(component);
+ }
+
+ @SmallTest
+ @Feature({"ContextualSearch"})
+ public void testConcurrentAnimationsFinishSeparately() {
+ addToAnimation(this, Property.FAST_ANIMATION, 0.f, 1.f, FAST_DURATION, 0);
+ addToAnimation(this, Property.SLOW_ANIMATION, 0.f, 1.f, SLOW_DURATION, 0);
+
+ // Update the animation with the current time. This will internally set the initial
+ // time of the animation to |now|.
+ long now = SystemClock.uptimeMillis();
+ mAnimations.update(now);
+
+ // Advances time to check that the fast animation will finish first.
+ mAnimations.update(now + FAST_DURATION);
+ assertTrue(mHasFinishedFastAnimation);
+ assertFalse(mHasFinishedSlowAnimation);
+
+ // Advances time to check that all animations are finished.
+ mAnimations.update(now + SLOW_DURATION);
+ assertTrue(mHasFinishedFastAnimation);
+ assertTrue(mHasFinishedSlowAnimation);
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutTab.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698