2012-01-18 03:31:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-01-18 03:31:02 +00:00
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-01-18 03:31:02 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-02-12 07:15:47 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2012-01-18 03:31:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
|
|
|
import android.test.AndroidTestCase;
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public class KeyboardStateTestsBase extends AndroidTestCase
|
2012-10-29 05:46:34 +00:00
|
|
|
implements MockKeyboardSwitcher.MockConstants {
|
2012-01-18 03:31:02 +00:00
|
|
|
protected MockKeyboardSwitcher mSwitcher;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
mSwitcher = new MockKeyboardSwitcher();
|
2012-05-18 07:45:26 +00:00
|
|
|
mSwitcher.setAutoCapsMode(CAP_MODE_OFF);
|
2012-01-18 03:31:02 +00:00
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
loadKeyboard(ALPHABET_UNSHIFTED);
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void setAutoCapsMode(final int autoCaps) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mSwitcher.setAutoCapsMode(autoCaps);
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private static void assertLayout(final String message, final int expected, final int actual) {
|
2012-05-29 06:54:05 +00:00
|
|
|
assertTrue(message + ": expected=" + MockKeyboardSwitcher.getLayoutName(expected)
|
2012-01-23 09:11:37 +00:00
|
|
|
+ " actual=" + MockKeyboardSwitcher.getLayoutName(actual),
|
|
|
|
expected == actual);
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void updateShiftState(final int afterUpdate) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mSwitcher.updateShiftState();
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterUpdate", afterUpdate, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void loadKeyboard(final int afterLoad) {
|
|
|
|
mSwitcher.loadKeyboard();
|
2012-05-29 06:54:05 +00:00
|
|
|
mSwitcher.updateShiftState();
|
|
|
|
assertLayout("afterLoad", afterLoad, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void rotateDevice(final int afterRotate) {
|
2012-01-18 07:40:28 +00:00
|
|
|
mSwitcher.saveKeyboardState();
|
2013-01-18 09:04:24 +00:00
|
|
|
mSwitcher.loadKeyboard();
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterRotate", afterRotate, mSwitcher.getLayoutId());
|
2012-01-18 07:40:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private void pressKeyWithoutTimerExpire(final int code, final boolean isSinglePointer,
|
|
|
|
final int afterPress) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mSwitcher.onPressKey(code, isSinglePointer);
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterPress", afterPress, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void pressKey(final int code, final int afterPress) {
|
2012-01-31 06:54:48 +00:00
|
|
|
mSwitcher.expireDoubleTapTimeout();
|
2012-05-17 03:55:01 +00:00
|
|
|
pressKeyWithoutTimerExpire(code, true, afterPress);
|
2012-01-31 06:54:48 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void releaseKey(final int code, final int afterRelease) {
|
2013-05-14 03:25:21 +00:00
|
|
|
mSwitcher.onCodeInput(code);
|
2012-01-18 03:31:02 +00:00
|
|
|
mSwitcher.onReleaseKey(code, NOT_SLIDING);
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void pressAndReleaseKey(final int code, final int afterPress, final int afterRelease) {
|
2012-01-18 03:31:02 +00:00
|
|
|
pressKey(code, afterPress);
|
|
|
|
releaseKey(code, afterRelease);
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void chordingPressKey(final int code, final int afterPress) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mSwitcher.expireDoubleTapTimeout();
|
|
|
|
pressKeyWithoutTimerExpire(code, false, afterPress);
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void chordingReleaseKey(final int code, final int afterRelease) {
|
2013-05-14 03:25:21 +00:00
|
|
|
mSwitcher.onCodeInput(code);
|
2012-01-18 03:31:02 +00:00
|
|
|
mSwitcher.onReleaseKey(code, NOT_SLIDING);
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void chordingPressAndReleaseKey(final int code, final int afterPress,
|
|
|
|
final int afterRelease) {
|
2012-01-18 03:31:02 +00:00
|
|
|
chordingPressKey(code, afterPress);
|
|
|
|
chordingReleaseKey(code, afterRelease);
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void pressAndSlideFromKey(final int code, final int afterPress, final int afterSlide) {
|
2012-01-18 03:31:02 +00:00
|
|
|
pressKey(code, afterPress);
|
|
|
|
mSwitcher.onReleaseKey(code, SLIDING);
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void stopSlidingOnKey(final int code, final int afterPress, final int afterSlide) {
|
|
|
|
pressKey(code, afterPress);
|
|
|
|
mSwitcher.onCodeInput(code);
|
|
|
|
mSwitcher.onReleaseKey(code, NOT_SLIDING);
|
|
|
|
mSwitcher.onFinishSlidingInput();
|
|
|
|
assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopSlidingAndCancel(final int afterCancelSliding) {
|
|
|
|
mSwitcher.onFinishSlidingInput();
|
|
|
|
assertLayout("afterCancelSliding", afterCancelSliding, mSwitcher.getLayoutId());
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void longPressKey(final int code, final int afterPress, final int afterLongPress) {
|
2012-02-01 06:07:25 +00:00
|
|
|
pressKey(code, afterPress);
|
|
|
|
mSwitcher.onLongPressTimeout(code);
|
2012-05-29 06:54:05 +00:00
|
|
|
assertLayout("afterLongPress", afterLongPress, mSwitcher.getLayoutId());
|
2012-05-29 07:34:47 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void longPressAndReleaseKey(final int code, final int afterPress,
|
|
|
|
final int afterLongPress, final int afterRelease) {
|
2012-05-29 07:34:47 +00:00
|
|
|
longPressKey(code, afterPress, afterLongPress);
|
2012-05-29 06:54:05 +00:00
|
|
|
releaseKey(code, afterRelease);
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 07:34:47 +00:00
|
|
|
public void secondPressKey(int code, int afterPress) {
|
2012-05-17 03:55:01 +00:00
|
|
|
pressKeyWithoutTimerExpire(code, true, afterPress);
|
2012-05-29 07:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void secondPressAndReleaseKey(int code, int afterPress, int afterRelease) {
|
|
|
|
secondPressKey(code, afterPress);
|
2012-01-31 06:54:48 +00:00
|
|
|
releaseKey(code, afterRelease);
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
}
|