Index: chrome/android/javatests/src/org/chromium/chrome/browser/widget/ToolbarProgressBarTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/widget/ToolbarProgressBarTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/ToolbarProgressBarTest.java |
index 669124f913a858b43f727352ed8d741dbe746322..8407d32c1e1dc02add810aacbb885582d9805529 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/widget/ToolbarProgressBarTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/ToolbarProgressBarTest.java |
@@ -6,16 +6,18 @@ package org.chromium.chrome.browser.widget; |
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; |
+import android.animation.Animator; |
+import android.animation.Animator.AnimatorListener; |
import android.test.suitebuilder.annotation.MediumTest; |
+import android.view.View; |
import org.chromium.base.ThreadUtils; |
+import org.chromium.base.annotations.SuppressFBWarnings; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.Restriction; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.ChromeActivity; |
import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
-import org.chromium.content.browser.test.util.Criteria; |
-import org.chromium.content.browser.test.util.CriteriaHelper; |
import java.util.concurrent.atomic.AtomicReference; |
@@ -35,57 +37,77 @@ public class ToolbarProgressBarTest extends ChromeActivityTestCaseBase<ChromeAct |
/** |
* Test that calling progressBar.setProgress(# > 0) followed by progressBar.setProgress(0) |
- * results in a hidden progress bar (the secondary progress needs to be 0). |
+ * results in a hidden progress bar. |
* @throws InterruptedException |
*/ |
@Feature({"Android-Toolbar"}) |
@MediumTest |
@Restriction(RESTRICTION_TYPE_PHONE) |
+ @SuppressFBWarnings({"WA_NOT_IN_LOOP", "UW_UNCOND_WAIT"}) |
public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedException { |
+ // onAnimationEnd will be signaled on progress bar showing/hiding animation end. |
+ final Object onAnimationEnd = new Object(); |
final AtomicReference<ToolbarProgressBar> progressBar = |
new AtomicReference<ToolbarProgressBar>(); |
- ThreadUtils.runOnUiThread(new Runnable() { |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
progressBar.set((ToolbarProgressBar) getActivity().findViewById(R.id.progress)); |
- } |
- }); |
+ progressBar.get().setAlphaAnimationDuration(10); |
+ progressBar.get().setHidingDelay(10); |
+ progressBar.get().animate().setListener(new AnimatorListener() { |
+ @Override |
+ public void onAnimationStart(Animator animation) { |
+ } |
- // Wait for the progress bar to be reset. |
- CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
- @Override |
- public boolean isSatisfied() { |
- return progressBar.get().getProgress() == 0; |
- } |
- }); |
+ @Override |
+ public void onAnimationRepeat(Animator animation) { |
+ } |
- ThreadUtils.runOnUiThread(new Runnable() { |
- @Override |
- public void run() { |
- assertEquals("Progress bar should be hidden to start.", 0, |
- progressBar.get().getProgress()); |
- progressBar.get().setProgress(10); |
- assertTrue("Progress bar did not start animating", |
- progressBar.get().isAnimatingForShowOrHide()); |
- progressBar.get().setProgress(0); |
- } |
- }); |
+ @Override |
+ public void onAnimationEnd(Animator animation) { |
+ synchronized (onAnimationEnd) { |
+ onAnimationEnd.notify(); |
+ } |
+ } |
- // Wait for the progress bar to finish any and all animations. |
- CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
- @Override |
- public boolean isSatisfied() { |
- return !progressBar.get().isAnimatingForShowOrHide(); |
+ @Override |
+ public void onAnimationCancel(Animator animation) { |
+ } |
+ }); |
} |
}); |
- ThreadUtils.runOnUiThread(new Runnable() { |
- @Override |
- public void run() { |
- // The secondary progress should be gone. |
- assertEquals("Progress bar background still visible.", 0, |
- progressBar.get().getSecondaryProgress()); |
- } |
- }); |
+ // Before the actual test, ensure that the progress bar is hidden. |
+ assertNotSame(View.VISIBLE, progressBar.get().getVisibility()); |
+ |
+ // Make some progress and check that the progress bar is fully visible. |
+ synchronized (onAnimationEnd) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ progressBar.get().start(); |
+ progressBar.get().setProgress(0.5f); |
+ } |
+ }); |
+ |
+ onAnimationEnd.wait(); |
+ assertEquals(1.0f, progressBar.get().getAlpha()); |
+ assertEquals(View.VISIBLE, progressBar.get().getVisibility()); |
+ } |
+ |
+ // Clear progress and check that the progress bar is hidden. |
+ synchronized (onAnimationEnd) { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ progressBar.get().finish(true); |
+ } |
+ }); |
+ |
+ onAnimationEnd.wait(); |
+ assertEquals(0.0f, progressBar.get().getAlpha()); |
+ assertNotSame(View.VISIBLE, progressBar.get().getVisibility()); |
+ } |
} |
} |