This source file includes following definitions.
- waitAndExpire
- set
- notifyAnimationFinished
- addInfoBarAnimationFinished
- swapInfoBarAnimationFinished
- removeInfoBarAnimationFinished
package org.chromium.chrome.test.util;
import android.os.SystemClock;
import org.chromium.chrome.browser.infobar.AnimationHelper;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import java.util.concurrent.TimeUnit;
public class InfoBarTestAnimationListener implements InfoBarContainer.InfoBarAnimationListener {
private static long WAIT_MILLIS = TimeUnit.SECONDS.toMillis(5);
private static class ConditionalWait {
private volatile Boolean mCondition;
private Object mLock;
ConditionalWait() {
mCondition = false;
mLock = new Object();
}
public boolean waitAndExpire(long millis) throws InterruptedException {
synchronized(mLock) {
while (!mCondition && millis > 0) {
long start = SystemClock.elapsedRealtime();
mLock.wait(millis);
millis -= (SystemClock.elapsedRealtime() - start);
}
boolean result = mCondition;
mCondition = false;
return result;
}
}
public void set(boolean value) {
synchronized(mLock) {
mCondition = value;
if (value) {
mLock.notify();
}
}
}
}
private ConditionalWait mAddAnimationFinished;
private ConditionalWait mSwapAnimationFinished;
private ConditionalWait mRemoveAnimationFinished;
public InfoBarTestAnimationListener() {
mAddAnimationFinished = new ConditionalWait();
mSwapAnimationFinished = new ConditionalWait();
mRemoveAnimationFinished = new ConditionalWait();
}
@Override
public void notifyAnimationFinished(int animationType) {
switch(animationType) {
case AnimationHelper.ANIMATION_TYPE_SHOW:
mAddAnimationFinished.set(true);
break;
case AnimationHelper.ANIMATION_TYPE_SWAP:
mSwapAnimationFinished.set(true);
break;
case AnimationHelper.ANIMATION_TYPE_HIDE:
mRemoveAnimationFinished.set(true);
break;
default:
throw new UnsupportedOperationException(
"Animation finished for unknown type " + animationType);
}
}
public boolean addInfoBarAnimationFinished() throws InterruptedException {
return mAddAnimationFinished.waitAndExpire(WAIT_MILLIS);
}
public boolean swapInfoBarAnimationFinished() throws InterruptedException {
return mSwapAnimationFinished.waitAndExpire(WAIT_MILLIS);
}
public boolean removeInfoBarAnimationFinished() throws InterruptedException {
return mRemoveAnimationFinished.waitAndExpire(WAIT_MILLIS);
}
}