OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.widget; | 5 package org.chromium.chrome.browser.widget; |
6 | 6 |
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; |
8 | 8 |
| 9 import android.animation.Animator; |
| 10 import android.animation.Animator.AnimatorListener; |
9 import android.test.suitebuilder.annotation.MediumTest; | 11 import android.test.suitebuilder.annotation.MediumTest; |
| 12 import android.view.View; |
10 | 13 |
11 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.base.annotations.SuppressFBWarnings; |
12 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
13 import org.chromium.base.test.util.Restriction; | 17 import org.chromium.base.test.util.Restriction; |
14 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
15 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
16 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
17 import org.chromium.content.browser.test.util.Criteria; | |
18 import org.chromium.content.browser.test.util.CriteriaHelper; | |
19 | 21 |
20 import java.util.concurrent.atomic.AtomicReference; | 22 import java.util.concurrent.atomic.AtomicReference; |
21 | 23 |
22 /** | 24 /** |
23 * Tests related to the ToolbarProgressBar. | 25 * Tests related to the ToolbarProgressBar. |
24 */ | 26 */ |
25 public class ToolbarProgressBarTest extends ChromeActivityTestCaseBase<ChromeAct
ivity> { | 27 public class ToolbarProgressBarTest extends ChromeActivityTestCaseBase<ChromeAct
ivity> { |
26 | 28 |
27 public ToolbarProgressBarTest() { | 29 public ToolbarProgressBarTest() { |
28 super(ChromeActivity.class); | 30 super(ChromeActivity.class); |
29 } | 31 } |
30 | 32 |
31 @Override | 33 @Override |
32 public void startMainActivity() throws InterruptedException { | 34 public void startMainActivity() throws InterruptedException { |
33 startMainActivityOnBlankPage(); | 35 startMainActivityOnBlankPage(); |
34 } | 36 } |
35 | 37 |
36 /** | 38 /** |
37 * Test that calling progressBar.setProgress(# > 0) followed by progressBar.
setProgress(0) | 39 * Test that calling progressBar.setProgress(# > 0) followed by progressBar.
setProgress(0) |
38 * results in a hidden progress bar (the secondary progress needs to be 0). | 40 * results in a hidden progress bar. |
39 * @throws InterruptedException | 41 * @throws InterruptedException |
40 */ | 42 */ |
41 @Feature({"Android-Toolbar"}) | 43 @Feature({"Android-Toolbar"}) |
42 @MediumTest | 44 @MediumTest |
43 @Restriction(RESTRICTION_TYPE_PHONE) | 45 @Restriction(RESTRICTION_TYPE_PHONE) |
| 46 @SuppressFBWarnings({"WA_NOT_IN_LOOP", "UW_UNCOND_WAIT"}) |
44 public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedE
xception { | 47 public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedE
xception { |
| 48 // onAnimationEnd will be signaled on progress bar showing/hiding animat
ion end. |
| 49 final Object onAnimationEnd = new Object(); |
45 final AtomicReference<ToolbarProgressBar> progressBar = | 50 final AtomicReference<ToolbarProgressBar> progressBar = |
46 new AtomicReference<ToolbarProgressBar>(); | 51 new AtomicReference<ToolbarProgressBar>(); |
47 ThreadUtils.runOnUiThread(new Runnable() { | 52 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
48 @Override | 53 @Override |
49 public void run() { | 54 public void run() { |
50 progressBar.set((ToolbarProgressBar) getActivity().findViewById(
R.id.progress)); | 55 progressBar.set((ToolbarProgressBar) getActivity().findViewById(
R.id.progress)); |
| 56 progressBar.get().setAlphaAnimationDuration(10); |
| 57 progressBar.get().setHidingDelay(10); |
| 58 progressBar.get().animate().setListener(new AnimatorListener() { |
| 59 @Override |
| 60 public void onAnimationStart(Animator animation) { |
| 61 } |
| 62 |
| 63 @Override |
| 64 public void onAnimationRepeat(Animator animation) { |
| 65 } |
| 66 |
| 67 @Override |
| 68 public void onAnimationEnd(Animator animation) { |
| 69 synchronized (onAnimationEnd) { |
| 70 onAnimationEnd.notify(); |
| 71 } |
| 72 } |
| 73 |
| 74 @Override |
| 75 public void onAnimationCancel(Animator animation) { |
| 76 } |
| 77 }); |
51 } | 78 } |
52 }); | 79 }); |
53 | 80 |
54 // Wait for the progress bar to be reset. | 81 // Before the actual test, ensure that the progress bar is hidden. |
55 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 82 assertNotSame(View.VISIBLE, progressBar.get().getVisibility()); |
56 @Override | |
57 public boolean isSatisfied() { | |
58 return progressBar.get().getProgress() == 0; | |
59 } | |
60 }); | |
61 | 83 |
62 ThreadUtils.runOnUiThread(new Runnable() { | 84 // Make some progress and check that the progress bar is fully visible. |
63 @Override | 85 synchronized (onAnimationEnd) { |
64 public void run() { | 86 ThreadUtils.runOnUiThread(new Runnable() { |
65 assertEquals("Progress bar should be hidden to start.", 0, | 87 @Override |
66 progressBar.get().getProgress()); | 88 public void run() { |
67 progressBar.get().setProgress(10); | 89 progressBar.get().start(); |
68 assertTrue("Progress bar did not start animating", | 90 progressBar.get().setProgress(0.5f); |
69 progressBar.get().isAnimatingForShowOrHide()); | 91 } |
70 progressBar.get().setProgress(0); | 92 }); |
71 } | |
72 }); | |
73 | 93 |
74 // Wait for the progress bar to finish any and all animations. | 94 onAnimationEnd.wait(); |
75 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 95 assertEquals(1.0f, progressBar.get().getAlpha()); |
76 @Override | 96 assertEquals(View.VISIBLE, progressBar.get().getVisibility()); |
77 public boolean isSatisfied() { | 97 } |
78 return !progressBar.get().isAnimatingForShowOrHide(); | |
79 } | |
80 }); | |
81 | 98 |
82 ThreadUtils.runOnUiThread(new Runnable() { | 99 // Clear progress and check that the progress bar is hidden. |
83 @Override | 100 synchronized (onAnimationEnd) { |
84 public void run() { | 101 ThreadUtils.runOnUiThread(new Runnable() { |
85 // The secondary progress should be gone. | 102 @Override |
86 assertEquals("Progress bar background still visible.", 0, | 103 public void run() { |
87 progressBar.get().getSecondaryProgress()); | 104 progressBar.get().finish(true); |
88 } | 105 } |
89 }); | 106 }); |
| 107 |
| 108 onAnimationEnd.wait(); |
| 109 assertEquals(0.0f, progressBar.get().getAlpha()); |
| 110 assertNotSame(View.VISIBLE, progressBar.get().getVisibility()); |
| 111 } |
90 } | 112 } |
91 } | 113 } |
OLD | NEW |