| 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 8407d32c1e1dc02add810aacbb885582d9805529..669124f913a858b43f727352ed8d741dbe746322 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,18 +6,16 @@
|
|
|
| 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;
|
|
|
| @@ -37,77 +35,57 @@
|
|
|
| /**
|
| * Test that calling progressBar.setProgress(# > 0) followed by progressBar.setProgress(0)
|
| - * results in a hidden progress bar.
|
| + * results in a hidden progress bar (the secondary progress needs to be 0).
|
| * @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.runOnUiThreadBlocking(new Runnable() {
|
| + ThreadUtils.runOnUiThread(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) {
|
| - }
|
| -
|
| - @Override
|
| - public void onAnimationRepeat(Animator animation) {
|
| - }
|
| -
|
| - @Override
|
| - public void onAnimationEnd(Animator animation) {
|
| - synchronized (onAnimationEnd) {
|
| - onAnimationEnd.notify();
|
| - }
|
| - }
|
| -
|
| - @Override
|
| - public void onAnimationCancel(Animator animation) {
|
| - }
|
| - });
|
| }
|
| });
|
|
|
| - // Before the actual test, ensure that the progress bar is hidden.
|
| - assertNotSame(View.VISIBLE, progressBar.get().getVisibility());
|
| + // Wait for the progress bar to be reset.
|
| + CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return progressBar.get().getProgress() == 0;
|
| + }
|
| + });
|
|
|
| - // 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);
|
| - }
|
| - });
|
| + 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);
|
| + }
|
| + });
|
|
|
| - onAnimationEnd.wait();
|
| - assertEquals(1.0f, progressBar.get().getAlpha());
|
| - assertEquals(View.VISIBLE, progressBar.get().getVisibility());
|
| - }
|
| + // Wait for the progress bar to finish any and all animations.
|
| + CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return !progressBar.get().isAnimatingForShowOrHide();
|
| + }
|
| + });
|
|
|
| - // 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());
|
| - }
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + // The secondary progress should be gone.
|
| + assertEquals("Progress bar background still visible.", 0,
|
| + progressBar.get().getSecondaryProgress());
|
| + }
|
| + });
|
| }
|
| }
|
|
|