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