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; |
| 8 |
7 import android.test.suitebuilder.annotation.MediumTest; | 9 import android.test.suitebuilder.annotation.MediumTest; |
8 | 10 |
9 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.base.test.util.Restriction; |
11 import org.chromium.chrome.shell.ChromeShellTestBase; | 14 import org.chromium.chrome.shell.ChromeShellTestBase; |
12 import org.chromium.chrome.shell.R; | 15 import org.chromium.chrome.shell.R; |
13 import org.chromium.content.browser.test.util.Criteria; | 16 import org.chromium.content.browser.test.util.Criteria; |
14 import org.chromium.content.browser.test.util.CriteriaHelper; | 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
15 | 18 |
16 import java.util.concurrent.atomic.AtomicReference; | 19 import java.util.concurrent.atomic.AtomicReference; |
17 | 20 |
18 /** | 21 /** |
19 * Tests related to the ToolbarProgressBar. | 22 * Tests related to the ToolbarProgressBar. |
20 */ | 23 */ |
21 public class ClipDrawableProgressBarTest extends ChromeShellTestBase { | 24 public class ToolbarProgressBarTest extends ChromeShellTestBase { |
22 /** | 25 /** |
23 * Test that calling progressBar.setProgress(# > 0) followed by progressBar.
setProgress(0) | 26 * Test that calling progressBar.setProgress(# > 0) followed by progressBar.
setProgress(0) |
24 * results in a hidden progress bar (the secondary progress needs to be 0). | 27 * results in a hidden progress bar (the secondary progress needs to be 0). |
25 * @throws InterruptedException | 28 * @throws InterruptedException |
26 */ | 29 */ |
27 @Feature({"Android-Toolbar"}) | 30 @Feature({"Android-Toolbar"}) |
28 @MediumTest | 31 @MediumTest |
| 32 @Restriction(RESTRICTION_TYPE_PHONE) |
29 public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedE
xception { | 33 public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedE
xception { |
30 launchChromeShellWithUrl("about:blank"); | 34 launchChromeShellWithUrl("about:blank"); |
31 waitForActiveShellToBeDoneLoading(); | 35 waitForActiveShellToBeDoneLoading(); |
32 | 36 |
33 final AtomicReference<ClipDrawableProgressBar> progressBar = | 37 final AtomicReference<ToolbarProgressBar> progressBar = |
34 new AtomicReference<ClipDrawableProgressBar>(); | 38 new AtomicReference<ToolbarProgressBar>(); |
35 ThreadUtils.runOnUiThread(new Runnable() { | 39 ThreadUtils.runOnUiThread(new Runnable() { |
36 @Override | 40 @Override |
37 public void run() { | 41 public void run() { |
38 progressBar.set( | 42 progressBar.set((ToolbarProgressBar) getActivity().findViewById(
R.id.progress)); |
39 (ClipDrawableProgressBar) getActivity().findViewById(R.i
d.progress)); | |
40 } | |
41 }); | |
42 | |
43 // Make sure that there is some progress. | |
44 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | |
45 @Override | |
46 public boolean isSatisfied() { | |
47 return progressBar.get().getProgress() > 0; | |
48 } | 43 } |
49 }); | 44 }); |
50 | 45 |
51 // Wait for the progress bar to be reset. | 46 // Wait for the progress bar to be reset. |
52 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 47 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
53 @Override | 48 @Override |
54 public boolean isSatisfied() { | 49 public boolean isSatisfied() { |
55 return progressBar.get().getProgress() == 0; | 50 return progressBar.get().getProgress() == 0; |
56 } | 51 } |
57 }); | 52 }); |
| 53 |
| 54 ThreadUtils.runOnUiThread(new Runnable() { |
| 55 @Override |
| 56 public void run() { |
| 57 assertEquals("Progress bar should be hidden to start.", 0, |
| 58 progressBar.get().getProgress()); |
| 59 progressBar.get().setProgress(10); |
| 60 assertTrue("Progress bar did not start animating", |
| 61 progressBar.get().isAnimatingForShowOrHide()); |
| 62 progressBar.get().setProgress(0); |
| 63 } |
| 64 }); |
| 65 |
| 66 // Wait for the progress bar to finish any and all animations. |
| 67 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 68 @Override |
| 69 public boolean isSatisfied() { |
| 70 return !progressBar.get().isAnimatingForShowOrHide(); |
| 71 } |
| 72 }); |
| 73 |
| 74 ThreadUtils.runOnUiThread(new Runnable() { |
| 75 @Override |
| 76 public void run() { |
| 77 // The secondary progress should be gone. |
| 78 assertEquals("Progress bar background still visible.", 0, |
| 79 progressBar.get().getSecondaryProgress()); |
| 80 } |
| 81 }); |
58 } | 82 } |
59 } | 83 } |
OLD | NEW |