OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.widget; | |
6 | |
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE; | |
8 | |
9 import android.test.suitebuilder.annotation.MediumTest; | |
10 | |
11 import org.chromium.base.ThreadUtils; | |
12 import org.chromium.base.test.util.Feature; | |
13 import org.chromium.base.test.util.Restriction; | |
14 import org.chromium.chrome.shell.ChromeShellTestBase; | |
15 import org.chromium.chrome.shell.R; | |
16 import org.chromium.content.browser.test.util.Criteria; | |
17 import org.chromium.content.browser.test.util.CriteriaHelper; | |
18 | |
19 import java.util.concurrent.atomic.AtomicReference; | |
20 | |
21 /** | |
22 * Tests related to the ToolbarProgressBar. | |
23 */ | |
24 public class ToolbarProgressBarTest extends ChromeShellTestBase { | |
25 /** | |
26 * Test that calling progressBar.setProgress(# > 0) followed by progressBar.
setProgress(0) | |
27 * results in a hidden progress bar (the secondary progress needs to be 0). | |
28 * @throws InterruptedException | |
29 */ | |
30 @Feature({"Android-Toolbar"}) | |
31 @MediumTest | |
32 @Restriction(RESTRICTION_TYPE_PHONE) | |
33 public void testProgressBarDisappearsAfterFastShowHide() throws InterruptedE
xception { | |
34 launchChromeShellWithUrl("about:blank"); | |
35 waitForActiveShellToBeDoneLoading(); | |
36 | |
37 final AtomicReference<ToolbarProgressBar> progressBar = | |
38 new AtomicReference<ToolbarProgressBar>(); | |
39 ThreadUtils.runOnUiThread(new Runnable() { | |
40 @Override | |
41 public void run() { | |
42 progressBar.set((ToolbarProgressBar) getActivity().findViewById(
R.id.progress)); | |
43 } | |
44 }); | |
45 | |
46 // Wait for the progress bar to be reset. | |
47 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | |
48 @Override | |
49 public boolean isSatisfied() { | |
50 return progressBar.get().getProgress() == 0; | |
51 } | |
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 }); | |
82 } | |
83 } | |
OLD | NEW |