FileDocCategorySizeDatePackage
LockPatternKeyguardViewTest.javaAPI DocAndroid 1.5 API12812Wed May 06 22:42:02 BST 2009com.android.internal.policy.impl

LockPatternKeyguardViewTest

public class LockPatternKeyguardViewTest extends android.test.AndroidTestCase
Tests for {@link com.android.internal.policy.impl.LockPatternKeyguardView}, which handles the management of screens while the keyguard is showing.

Fields Summary
private MockUpdateMonitor
mUpdateMonitor
private com.android.internal.widget.LockPatternUtils
mLockPatternUtils
private TestableLockPatternKeyguardView
mLPKV
private MockKeyguardCallback
mKeyguardViewCallback
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        mUpdateMonitor = new MockUpdateMonitor(getContext());
        mLockPatternUtils = new MockLockPatternUtils();

        mLPKV = new TestableLockPatternKeyguardView(getContext(), mUpdateMonitor,
                mLockPatternUtils, new KeyguardWindowController() {
            public void setNeedsInput(boolean needsInput) {
            }
        });
        mKeyguardViewCallback = new MockKeyguardCallback();
        mLPKV.setCallback(mKeyguardViewCallback);
    
public voidtestMenuDoesntGoToUnlockScreenOnWakeWhenPukLocked()

        // PUK locked
        mUpdateMonitor.simState = SimCard.State.PUK_REQUIRED;

        // wake by menu
        mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);

        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
        MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);

        // lock screen should be only visible one
        assertEquals(View.VISIBLE, lockScreen.getVisibility());
        assertEquals(View.GONE, unlockScreen.getVisibility());
    
public voidtestMenuGoesToLockScreenWhenDeviceNotSecure()

        mLockPatternUtils.setLockPatternEnabled(false);

        // wake by menu
        mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);

        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
        MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);

        // lock screen should be only visible one
        assertEquals(View.VISIBLE, lockScreen.getVisibility());
        assertEquals(View.GONE, unlockScreen.getVisibility());
    
public voidtestScreenRequestsRecreation()

        mLPKV.wakeWhenReadyTq(0);
        mLPKV.onScreenTurnedOn();

        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);

        assertEquals(0, lockScreen.getOnPauseCount());
        assertEquals(1, lockScreen.getOnResumeCount());

        // simulate screen asking to be recreated
        mLPKV.mKeyguardScreenCallback.recreateMe();

        // should have been recreated
        assertEquals(2, mLPKV.getInjectedLockScreens().size());
        assertEquals(2, mLPKV.getInjectedUnlockScreens().size());

        // both old screens should have been cleaned up
        assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getCleanupCount());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().get(0).getCleanupCount());

        // old lock screen should have been paused
        assertEquals(1, mLPKV.getInjectedLockScreens().get(0).getOnPauseCount());
        assertEquals(0, mLPKV.getInjectedUnlockScreens().get(0).getOnPauseCount());

        // new lock screen should have been resumed
        assertEquals(1, mLPKV.getInjectedLockScreens().get(1).getOnResumeCount());
        assertEquals(0, mLPKV.getInjectedUnlockScreens().get(1).getOnResumeCount());
    
public voidtestStateAfterCreatedWhileScreenOff()


        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());

        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
        MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);

        assertEquals(0, lockScreen.getOnPauseCount());
        assertEquals(0, lockScreen.getOnResumeCount());
        assertEquals(0, lockScreen.getCleanupCount());

        assertEquals(0, unlockScreen.getOnPauseCount());
        assertEquals(0, unlockScreen.getOnResumeCount());
        assertEquals(0, unlockScreen.getCleanupCount());

        assertEquals(0, mKeyguardViewCallback.getPokeWakelockCount());
        assertEquals(0, mKeyguardViewCallback.getKeyguardDoneCount());
    
public voidtestWokenByMenuKeyWhenPatternSet()

        assertEquals(true, mLockPatternUtils.isLockPatternEnabled());

        mLPKV.wakeWhenReadyTq(KeyEvent.KEYCODE_MENU);

        // should have poked the wakelock to turn on the screen
        assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount());
        
        // shouldn't be any additional views created
        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
        MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);

        // unlock screen should be only visible one
        assertEquals(View.GONE, lockScreen.getVisibility());
        assertEquals(View.VISIBLE, unlockScreen.getVisibility());
    
public voidtestWokenByNonMenuKey()

        mLPKV.wakeWhenReadyTq(0);

        // should have poked the wakelock to turn on the screen
        assertEquals(1, mKeyguardViewCallback.getPokeWakelockCount());

        // shouldn't be any additional views created
        assertEquals(1, mLPKV.getInjectedLockScreens().size());
        assertEquals(1, mLPKV.getInjectedUnlockScreens().size());
        MockKeyguardScreen lockScreen = mLPKV.getInjectedLockScreens().get(0);
        MockKeyguardScreen unlockScreen = mLPKV.getInjectedUnlockScreens().get(0);

        // lock screen should be only visible one
        assertEquals(View.VISIBLE, lockScreen.getVisibility());
        assertEquals(View.GONE, unlockScreen.getVisibility());

        // on resume not called until screen turns on
        assertEquals(0, lockScreen.getOnPauseCount());
        assertEquals(0, lockScreen.getOnResumeCount());
        assertEquals(0, lockScreen.getCleanupCount());

        assertEquals(0, unlockScreen.getOnPauseCount());
        assertEquals(0, unlockScreen.getOnResumeCount());
        assertEquals(0, unlockScreen.getCleanupCount());

        // simulate screen turning on
        mLPKV.onScreenTurnedOn();

        assertEquals(0, lockScreen.getOnPauseCount());
        assertEquals(1, lockScreen.getOnResumeCount());
        assertEquals(0, lockScreen.getCleanupCount());

        assertEquals(0, unlockScreen.getOnPauseCount());
        assertEquals(0, unlockScreen.getOnResumeCount());
        assertEquals(0, unlockScreen.getCleanupCount());