2012-01-18 03:31:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
|
|
|
import android.test.AndroidTestCase;
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public class KeyboardStateTestsBase extends AndroidTestCase
|
2012-01-18 03:31:02 +00:00
|
|
|
implements MockKeyboardSwitcher.Constants {
|
|
|
|
protected MockKeyboardSwitcher mSwitcher;
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
private String mLayoutSwitchBackSymbols = "";
|
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
mSwitcher = new MockKeyboardSwitcher();
|
|
|
|
mSwitcher.setAutoCapsMode(NO_AUTO_CAPS);
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
loadKeyboard(ALPHABET_UNSHIFTED);
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutoCapsMode(boolean autoCaps) {
|
|
|
|
mSwitcher.setAutoCapsMode(autoCaps);
|
|
|
|
}
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public void setLayoutSwitchBackSymbols(String switchBackSymbols) {
|
|
|
|
mLayoutSwitchBackSymbols = switchBackSymbols;
|
|
|
|
}
|
|
|
|
|
2012-01-23 09:11:37 +00:00
|
|
|
private static void assertLayout(int expected, int actual) {
|
|
|
|
assertTrue("expected=" + MockKeyboardSwitcher.getLayoutName(expected)
|
|
|
|
+ " actual=" + MockKeyboardSwitcher.getLayoutName(actual),
|
|
|
|
expected == actual);
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
public void updateShiftState(int afterUpdate) {
|
|
|
|
mSwitcher.updateShiftState();
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterUpdate, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public void loadKeyboard(int afterLoad) {
|
|
|
|
mSwitcher.loadKeyboard(mLayoutSwitchBackSymbols);
|
2012-01-18 03:31:02 +00:00
|
|
|
updateShiftState(afterLoad);
|
|
|
|
}
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public void rotateDevice(int afterRotate) {
|
|
|
|
mSwitcher.saveKeyboardState();
|
|
|
|
mSwitcher.loadKeyboard(mLayoutSwitchBackSymbols);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterRotate, mSwitcher.getLayoutId());
|
2012-01-18 07:40:28 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
public void pressKey(int code, int afterPress) {
|
|
|
|
mSwitcher.onPressKey(code);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterPress, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void releaseKey(int code, int afterRelease) {
|
|
|
|
mSwitcher.onCodeInput(code, SINGLE);
|
|
|
|
mSwitcher.onReleaseKey(code, NOT_SLIDING);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterRelease, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void pressAndReleaseKey(int code, int afterPress, int afterRelease) {
|
|
|
|
pressKey(code, afterPress);
|
|
|
|
releaseKey(code, afterRelease);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void chordingPressKey(int code, int afterPress) {
|
|
|
|
pressKey(code, afterPress);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void chordingReleaseKey(int code, int afterRelease) {
|
|
|
|
mSwitcher.onCodeInput(code, MULTI);
|
|
|
|
mSwitcher.onReleaseKey(code, NOT_SLIDING);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterRelease, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void chordingPressAndReleaseKey(int code, int afterPress, int afterRelease) {
|
|
|
|
chordingPressKey(code, afterPress);
|
|
|
|
chordingReleaseKey(code, afterRelease);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pressAndSlideFromKey(int code, int afterPress, int afterSlide) {
|
|
|
|
pressKey(code, afterPress);
|
|
|
|
mSwitcher.onReleaseKey(code, SLIDING);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterSlide, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void longPressShiftKey(int afterPress, int afterLongPress) {
|
|
|
|
// Long press shift key
|
|
|
|
mSwitcher.onPressKey(CODE_SHIFT);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterPress, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
|
|
|
mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterLongPress, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
mSwitcher.onReleaseKey(CODE_SHIFT, NOT_SLIDING);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterLongPress, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void secondTapShiftKey(int afterTap) {
|
|
|
|
mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE);
|
2012-01-23 09:11:37 +00:00
|
|
|
assertLayout(afterTap, mSwitcher.getLayoutId());
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
|
|
|
}
|