Add KeyboardStateTestsBase and helper methods

Change-Id: I17d908b60bbf784dae7add8355f699a63f7eb90a
main
Tadashi G. Takaoka 2012-01-18 12:31:02 +09:00
parent 5731b939c7
commit 64e01baade
4 changed files with 279 additions and 393 deletions

View File

@ -16,412 +16,248 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.test.AndroidTestCase; public class KeyboardStateNonDistinctTests extends KeyboardStateTestsBase {
@Override
public class KeyboardStateNonDistinctTests extends AndroidTestCase
implements MockKeyboardSwitcher.Constants {
protected MockKeyboardSwitcher mSwitcher;
public boolean hasDistinctMultitouch() { public boolean hasDistinctMultitouch() {
return false; return false;
} }
@Override
protected void setUp() throws Exception {
super.setUp();
mSwitcher = new MockKeyboardSwitcher();
final String layoutSwitchBackSymbols = "";
mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch());
}
public void assertAlphabetNormal() {
assertTrue(mSwitcher.assertAlphabetNormal());
}
public void assertAlphabetManualShifted() {
assertTrue(mSwitcher.assertAlphabetManualShifted());
}
public void assertAlphabetAutomaticShifted() {
assertTrue(mSwitcher.assertAlphabetAutomaticShifted());
}
public void assertAlphabetShiftLocked() {
assertTrue(mSwitcher.assertAlphabetShiftLocked());
}
public void assertSymbolsNormal() {
assertTrue(mSwitcher.assertSymbolsNormal());
}
public void assertSymbolsShifted() {
assertTrue(mSwitcher.assertSymbolsShifted());
}
// Initial state test.
public void testLoadKeyboard() {
assertAlphabetNormal();
}
// Shift key in alphabet mode. // Shift key in alphabet mode.
public void testShift() { public void testShift() {
// Press/release shift key, enter into shift state. // Press/release shift key, enter into shift state.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release shift key, back to normal state. // Press/release shift key, back to normal state.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
// Press/release shift key, enter into shift state. // Press/release shift key, enter into shift state.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release letter key, snap back to normal state. // Press/release letter key, snap back to normal state.
mSwitcher.onPressKey('Z'); pressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
} }
// Shift key sliding input. // Shift key sliding input.
public void testShiftSliding() { public void testShiftSliding() {
// Press shift key. // Press and slide from shift key.
mSwitcher.onPressKey(CODE_SHIFT); pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
// Slide out shift key.
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertAlphabetManualShifted();
// Enter into letter key. // Enter/release letter key, snap back to alphabet.
mSwitcher.onPressKey('Z'); pressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
assertAlphabetManualShifted();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
}
public void enterSymbolsMode() {
// Press/release "?123" key.
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertSymbolsNormal();
}
public void leaveSymbolsMode() {
// Press/release "ABC" key.
mSwitcher.onPressKey(CODE_SYMBOL);
assertAlphabetNormal();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetNormal();
} }
// Switching between alphabet and symbols. // Switching between alphabet and symbols.
public void testAlphabetAndSymbols() { public void testAlphabetAndSymbols() {
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
leaveSymbolsMode(); pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Press/release "?123" key, back to alphabet.
pressAndReleaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED);
} }
// Switching between alphabet shift locked and symbols. // Switching between alphabet shift locked and symbols.
public void testAlphabetShiftLockedAndSymbols() { public void testAlphabetShiftLockedAndSymbols() {
enterShiftLockWithLongPressShift(); // Long press shift key, enter alphabet shift locked.
enterSymbolsMode(); longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Press/release "ABC" key, switch back to shift locked mode. // Press/release "ABC" key, switch back to shift locked mode.
mSwitcher.onPressKey(CODE_SYMBOL); pressAndReleaseKey(CODE_SYMBOL, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED);
assertAlphabetShiftLocked();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetShiftLocked();
} }
// Symbols key sliding input. // Symbols key sliding input.
public void testSymbolsSliding() { public void testSymbolsSliding() {
// Press "123?" key. // Press and slide from "123?" key.
mSwitcher.onPressKey(CODE_SYMBOL); pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
// Slide out from "123?" key.
mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING);
assertSymbolsNormal();
// Enter into letter key. // Enter/release into symbol key, snap back to alphabet.
mSwitcher.onPressKey('z'); pressAndReleaseKey('!', SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED);
assertSymbolsNormal();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('z');
mSwitcher.onReleaseKey('z');
assertAlphabetNormal();
} }
// Switching between symbols and symbols shifted. // Switching between symbols and symbols shifted.
public void testSymbolsAndSymbolsShifted() { public void testSymbolsAndSymbolsShifted() {
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Press/release "=\<" key. // Press/release "=\<" key, enter into symbols shifted.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
assertSymbolsShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsShifted();
// Press/release "?123" key. // Press/release "?123" key, enter into symbols.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsNormal();
leaveSymbolsMode();
} }
// Symbols shift sliding input // Symbols shift sliding input
public void testSymbolsShiftSliding() { public void testSymbolsShiftSliding() {
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Press "=\<" key. // Press and slide from "=\<" key.
mSwitcher.onPressKey(CODE_SHIFT); pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
assertSymbolsShifted();
// Slide out "=\<" key.
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertSymbolsShifted();
// Enter into symbol shifted letter key. // Enter/release symbol shifted letter key, snap back to symbols.
mSwitcher.onPressKey('~'); pressAndReleaseKey('~', SYMBOLS_SHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsShifted();
// Release symbol shifted letter key, snap back to symbols.
mSwitcher.onCodeInput('~');
mSwitcher.onReleaseKey('~');
assertSymbolsNormal();
} }
// Symbols shift sliding input from symbols shifted. // Symbols shift sliding input from symbols shifted.
public void testSymbolsShiftSliding2() { public void testSymbolsShiftSliding2() {
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Press/release "=\<" key. // Press/release "=\<" key, enter into symbols shifted.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, SYMBOLS_SHIFTED, SYMBOLS_SHIFTED);
assertSymbolsShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsShifted();
// Press "123?" key. // Press and slide from "123?" key.
mSwitcher.onPressKey(CODE_SHIFT); pressAndSlideFromKey(CODE_SHIFT, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
// Slide out "123?" key.
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertSymbolsNormal();
// Enter into symbol letter key. // Enter/release symbol letter key, snap back to symbols shifted.
mSwitcher.onPressKey('1'); pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_SHIFTED);
assertSymbolsNormal();
// Release symbol letter key, snap back to symbols shift.
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsShifted();
} }
// Automatic snap back to alphabet from symbols by space key. // Automatic snap back to alphabet from symbols by space key.
public void testSnapBackBySpace() { public void testSnapBackBySpace() {
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Enter a symbol letter. // Enter a symbol letter.
mSwitcher.onPressKey('1'); pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Enter space, snap back to alphabet. // Enter space, snap back to alphabet.
mSwitcher.onPressKey(CODE_SPACE); pressAndReleaseKey(CODE_SPACE, SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput(CODE_SPACE);
mSwitcher.onReleaseKey(CODE_SPACE);
assertAlphabetNormal();
} }
// TODO: Add automatic snap back to shift locked test. // TODO: Add automatic snap back to shift locked test.
// Automatic snap back to alphabet from symbols by registered letters. // Automatic snap back to alphabet from symbols by registered letters.
public void testSnapBack() { public void testSnapBack() {
// Set snap back chars.
final String snapBackChars = "'"; final String snapBackChars = "'";
final int snapBackCode = snapBackChars.codePointAt(0); final int snapBackCode = snapBackChars.codePointAt(0);
final boolean hasDistinctMultitouch = true; loadKeyboard(snapBackChars, ALPHABET_UNSHIFTED);
mSwitcher.loadKeyboard(snapBackChars, hasDistinctMultitouch);
enterSymbolsMode(); // Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
// Enter a symbol letter. // Enter a symbol letter.
mSwitcher.onPressKey('1'); pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Enter snap back letter, snap back to alphabet. // Enter snap back letter, snap back to alphabet.
mSwitcher.onPressKey(snapBackCode); pressAndReleaseKey(snapBackCode, SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput(snapBackCode);
mSwitcher.onReleaseKey(snapBackCode);
assertAlphabetNormal();
} }
// Automatic upper case test // Automatic upper case test
public void testAutomaticUpperCase() { public void testAutomaticUpperCase() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
// Update shift state with auto caps enabled. setAutoCapsMode(AUTO_CAPS);
mSwitcher.updateShiftState();
assertAlphabetAutomaticShifted();
// Press shift key. // Update shift state with auto caps enabled.
mSwitcher.onPressKey(CODE_SHIFT); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetManualShifted();
// Release shift key. // Press/release shift key, back to alphabet.
mSwitcher.onCodeInput(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
} }
// Sliding from shift key in automatic upper case. // Sliding from shift key in automatic upper case.
public void testAutomaticUpperCaseSliding() { public void testAutomaticUpperCaseSliding() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
// Update shift state with auto caps enabled. setAutoCapsMode(AUTO_CAPS);
mSwitcher.updateShiftState();
assertAlphabetAutomaticShifted();
// Press shift key. // Update shift state with auto caps enabled.
mSwitcher.onPressKey(CODE_SHIFT); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetManualShifted();
// Slide out shift key. // Press and slide from shift key.
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING); pressAndSlideFromKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
// Enter into letter key. // Enter and release letter key, back to alphabet.
mSwitcher.onPressKey('Z'); pressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
assertAlphabetManualShifted();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
} }
// Sliding from symbol key in automatic upper case. // Sliding from symbol key in automatic upper case.
public void testAutomaticUpperCaseSliding2() { public void testAutomaticUpperCaseSliding2() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
setAutoCapsMode(AUTO_CAPS);
// Update shift state with auto caps enabled. // Update shift state with auto caps enabled.
mSwitcher.updateShiftState(); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetAutomaticShifted();
// Press "123?" key. // Press and slide from "123?" key.
mSwitcher.onPressKey(CODE_SYMBOL); pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
// Slide out "123?" key.
mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING);
assertSymbolsNormal();
// Enter into symbol letter keys.
mSwitcher.onPressKey('1');
assertSymbolsNormal();
// Release symbol letter key, snap back to alphabet.
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertAlphabetNormal();
}
public void enterShiftLockWithLongPressShift() { // Enter and release symbol letter keys, back to alphabet.
// Long press shift key pressAndReleaseKey('1', SYMBOLS_UNSHIFTED, ALPHABET_UNSHIFTED);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.onCodeInput(CODE_CAPSLOCK);
assertAlphabetShiftLocked();
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetShiftLocked();
}
public void leaveShiftLockWithLongPressShift() {
// Press shift key.
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.onCodeInput(CODE_CAPSLOCK);
assertAlphabetNormal();
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
} }
// Long press shift key. // Long press shift key.
// TODO: Move long press recognizing timer/logic into KeyboardState. // TODO: Move long press recognizing timer/logic into KeyboardState.
public void testLongPressShift() { public void testLongPressShift() {
enterShiftLockWithLongPressShift(); // Long press shift key, enter alphabet shift locked.
leaveShiftLockWithLongPressShift(); longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_SHIFT_LOCKED);
// Press/release letter key, remain in shift locked.
pressAndReleaseKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED);
// Press/release letter key, remain in shift locked.
pressAndReleaseKey('B', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED);
// Press/release word separator, remain in shift locked.
pressAndReleaseKey(CODE_SPACE, ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED);
// Long press shift key, back to alphabet.
longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
} }
// Leave shift lock with single tap shift key. // Leave shift lock with single tap shift key.
public void testShiftInShiftLock() { public void testShiftInShiftLock() {
enterShiftLockWithLongPressShift(); // Long press shift key, enter alphabet shift locked.
assertAlphabetShiftLocked(); longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_SHIFT_LOCKED);
// Tap shift key. // Press/release shift key, back to alphabet.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT, SINGLE);
assertAlphabetManualShifted();
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
} }
// Double tap shift key. // Double tap shift key.
// TODO: Move double tap recognizing timer/logic into KeyboardState. // TODO: Move double tap recognizing timer/logic into KeyboardState.
public void testDoubleTapShift() { public void testDoubleTapShift() {
// First shift key tap. // First shift key tap.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Second shift key tap. // Second shift key tap.
// Double tap recognized in LatinKeyboardView.KeyTimerHandler. // Double tap recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.onCodeInput(CODE_CAPSLOCK); secondTapShiftKey(ALPHABET_SHIFT_LOCKED);
assertAlphabetShiftLocked();
// First shift key tap. // First shift key tap.
mSwitcher.onPressKey(CODE_SHIFT); pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
// Second shift key tap. // Second shift key tap.
// Second tap is ignored in LatinKeyboardView.KeyTimerHandler. // Second tap is ignored in LatinKeyboardView.KeyTimerHandler.
} }
// Update shift state. // Update shift state.
public void testUpdateShiftState() { public void testUpdateShiftState() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
setAutoCapsMode(AUTO_CAPS);
// Update shift state. // Update shift state.
mSwitcher.updateShiftState(); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetAutomaticShifted();
// Press/release letter key, back to alphabet.
pressAndReleaseKey('A', ALPHABET_AUTOMATIC_SHIFTED, ALPHABET_UNSHIFTED);
// Press/release letter key
pressAndReleaseKey('b', ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED);
// Press/release auto caps trigger letter, back to automatic shifted.
pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
} }
// Update shift state when shift locked. // Update shift state when shift locked.
public void testUpdateShiftStateInShiftLocked() { public void testUpdateShiftStateInShiftLocked() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
enterShiftLockWithLongPressShift(); setAutoCapsMode(AUTO_CAPS);
assertAlphabetShiftLocked();
// Long press shift key, enter alphabet shift locked.
longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_SHIFT_LOCKED);
// Update shift state when shift locked // Update shift state when shift locked
mSwitcher.updateShiftState(); updateShiftState(ALPHABET_SHIFT_LOCKED);
assertAlphabetShiftLocked();
} }
// TODO: Change focus test. // TODO: Change focus test.

View File

@ -25,90 +25,63 @@ public class KeyboardStateTests extends KeyboardStateNonDistinctTests {
// Shift key chording input. // Shift key chording input.
public void testShiftChording() { public void testShiftChording() {
// Press shift key and hold, enter into choring shift state. // Press shift key and hold, enter into choring shift state.
mSwitcher.onPressKey(CODE_SHIFT); pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
// Press/release letter keys. // Press/release letter keys.
mSwitcher.onPressKey('Z'); chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
mSwitcher.onCodeInput('Z', MULTI); chordingPressAndReleaseKey('X', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
mSwitcher.onReleaseKey('Z');
assertAlphabetManualShifted();
mSwitcher.onPressKey('X');
mSwitcher.onCodeInput('X', MULTI);
mSwitcher.onReleaseKey('X');
assertAlphabetManualShifted();
// Release shift key, snap back to normal state. // Release shift key, snap back to normal state.
mSwitcher.onCodeInput(CODE_SHIFT); releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
mSwitcher.onReleaseKey(CODE_SHIFT);
mSwitcher.updateShiftState();
assertAlphabetNormal();
} }
// Symbols key chording input. // Symbols key chording input.
public void testSymbolsChording() { public void testSymbolsChording() {
// Press symbols key and hold, enter into choring shift state. // Press symbols key and hold, enter into choring shift state.
mSwitcher.onPressKey(CODE_SYMBOL); pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
// Press/release symbol letter keys. // Press/release symbol letter keys.
mSwitcher.onPressKey('1'); chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
mSwitcher.onCodeInput('1', MULTI); chordingPressAndReleaseKey('2', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
mSwitcher.onPressKey('2');
mSwitcher.onCodeInput('2', MULTI);
mSwitcher.onReleaseKey('2');
assertSymbolsNormal();
// Release shift key, snap back to normal state. // Release shift key, snap back to normal state.
mSwitcher.onCodeInput(CODE_SYMBOL); releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED);
mSwitcher.onReleaseKey(CODE_SYMBOL);
mSwitcher.updateShiftState();
assertAlphabetNormal();
} }
// Chording shift key in automatic upper case. // Chording shift key in automatic upper case.
public void testAutomaticUpperCaseChording() { public void testAutomaticUpperCaseChording() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
setAutoCapsMode(AUTO_CAPS);
// Update shift state with auto caps enabled. // Update shift state with auto caps enabled.
mSwitcher.updateShiftState(); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetAutomaticShifted();
// Press shift key. // Press shift key.
mSwitcher.onPressKey(CODE_SHIFT); pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
assertAlphabetManualShifted();
// Press/release letter keys. // Press/release letter keys.
mSwitcher.onPressKey('Z'); chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
mSwitcher.onCodeInput('Z', MULTI);
mSwitcher.onReleaseKey('Z');
assertAlphabetManualShifted();
// Release shift key, snap back to alphabet. // Release shift key, snap back to alphabet.
mSwitcher.onCodeInput(CODE_SHIFT); releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
} }
// Chording symbol key in automatic upper case. // Chording symbol key in automatic upper case.
public void testAutomaticUpperCaseChrding2() { public void testAutomaticUpperCaseChording2() {
mSwitcher.setAutoCapsMode(AUTO_CAPS); // Set auto caps mode on.
setAutoCapsMode(AUTO_CAPS);
// Update shift state with auto caps enabled. // Update shift state with auto caps enabled.
mSwitcher.updateShiftState(); updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
assertAlphabetAutomaticShifted();
// Press "123?" key. // Press "123?" key.
mSwitcher.onPressKey(CODE_SYMBOL); pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
// Press/release symbol letter keys. // Press/release symbol letter keys.
mSwitcher.onPressKey('1'); chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
assertSymbolsNormal();
mSwitcher.onCodeInput('1', MULTI);
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Release "123?" key, snap back to alphabet. // Release "123?" key, snap back to alphabet.
mSwitcher.onCodeInput(CODE_SYMBOL); releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetNormal();
} }
// TODO: Multitouch test // TODO: Multitouch test

View File

@ -0,0 +1,104 @@
/*
* 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;
public abstract class KeyboardStateTestsBase extends AndroidTestCase
implements MockKeyboardSwitcher.Constants {
protected MockKeyboardSwitcher mSwitcher;
public abstract boolean hasDistinctMultitouch();
@Override
protected void setUp() throws Exception {
super.setUp();
mSwitcher = new MockKeyboardSwitcher();
mSwitcher.setAutoCapsMode(NO_AUTO_CAPS);
final String layoutSwitchBackSymbols = "";
loadKeyboard(layoutSwitchBackSymbols, ALPHABET_UNSHIFTED);
}
public void setAutoCapsMode(boolean autoCaps) {
mSwitcher.setAutoCapsMode(autoCaps);
}
public void updateShiftState(int afterUpdate) {
mSwitcher.updateShiftState();
assertEquals(afterUpdate, mSwitcher.getLayoutId());
}
public void loadKeyboard(String layoutSwitchBackSymbols, int afterLoad) {
mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch());
updateShiftState(afterLoad);
}
public void pressKey(int code, int afterPress) {
mSwitcher.onPressKey(code);
assertEquals(afterPress, mSwitcher.getLayoutId());
}
public void releaseKey(int code, int afterRelease) {
mSwitcher.onCodeInput(code, SINGLE);
mSwitcher.onReleaseKey(code, NOT_SLIDING);
assertEquals(afterRelease, mSwitcher.getLayoutId());
}
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);
assertEquals(afterRelease, mSwitcher.getLayoutId());
}
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);
assertEquals(afterSlide, mSwitcher.getLayoutId());
}
public void longPressShiftKey(int afterPress, int afterLongPress) {
// Long press shift key
mSwitcher.onPressKey(CODE_SHIFT);
assertEquals(afterPress, mSwitcher.getLayoutId());
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE);
assertEquals(afterLongPress, mSwitcher.getLayoutId());
mSwitcher.onReleaseKey(CODE_SHIFT, NOT_SLIDING);
assertEquals(afterLongPress, mSwitcher.getLayoutId());
}
public void secondTapShiftKey(int afterTap) {
mSwitcher.onCodeInput(CODE_CAPSLOCK, SINGLE);
assertEquals(afterTap, mSwitcher.getLayoutId());
}
}

View File

@ -21,10 +21,10 @@ import com.android.inputmethod.keyboard.internal.KeyboardState.SwitchActions;
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
public interface Constants { public interface Constants {
// Argument for KeyboardState.onPressKey and onReleaseKey. // Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}.
public static final boolean NOT_SLIDING = false; public static final boolean NOT_SLIDING = false;
public static final boolean SLIDING = true; public static final boolean SLIDING = true;
// Argument for KeyboardState.onCodeInput. // Argument for {@link KeyboardState#onCodeInput}.
public static final boolean SINGLE = true; public static final boolean SINGLE = true;
public static final boolean MULTI = false; public static final boolean MULTI = false;
public static final boolean NO_AUTO_CAPS = false; public static final boolean NO_AUTO_CAPS = false;
@ -34,18 +34,17 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL; public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
public static final int CODE_CAPSLOCK = Keyboard.CODE_CAPSLOCK; public static final int CODE_CAPSLOCK = Keyboard.CODE_CAPSLOCK;
public static final int CODE_SPACE = Keyboard.CODE_SPACE; public static final int CODE_SPACE = Keyboard.CODE_SPACE;
public static final int CODE_AUTO_CAPS_TRIGGER = Keyboard.CODE_SPACE;
public static final int ALPHABET_UNSHIFTED = 0;
public static final int ALPHABET_MANUAL_SHIFTED = 1;
public static final int ALPHABET_AUTOMATIC_SHIFTED = 2;
public static final int ALPHABET_SHIFT_LOCKED = 3;
public static final int SYMBOLS_UNSHIFTED = 4;
public static final int SYMBOLS_SHIFTED = 5;
} }
public static final String WORD_SEPARATORS = " ,."; private int mLayout = Constants.ALPHABET_UNSHIFTED;
private static final int ALPHABET_UNSHIFTED = 0;
private static final int ALPHABET_MANUAL_SHIFTED = 1;
private static final int ALPHABET_AUTOMATIC_SHIFTED = 2;
private static final int ALPHABET_SHIFT_LOCKED = 3;
private static final int SYMBOLS_UNSHIFTED = 4;
private static final int SYMBOLS_SHIFTED = 5;
private int mLayout = ALPHABET_UNSHIFTED;
private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS; private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS;
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS. // Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
@ -53,28 +52,8 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
private final KeyboardState mState = new KeyboardState(this); private final KeyboardState mState = new KeyboardState(this);
public boolean assertAlphabetNormal() { public int getLayoutId() {
return mLayout == ALPHABET_UNSHIFTED; return mLayout;
}
public boolean assertAlphabetManualShifted() {
return mLayout == ALPHABET_MANUAL_SHIFTED;
}
public boolean assertAlphabetAutomaticShifted() {
return mLayout == ALPHABET_AUTOMATIC_SHIFTED;
}
public boolean assertAlphabetShiftLocked() {
return mLayout == ALPHABET_SHIFT_LOCKED;
}
public boolean assertSymbolsNormal() {
return mLayout == SYMBOLS_UNSHIFTED;
}
public boolean assertSymbolsShifted() {
return mLayout == SYMBOLS_SHIFTED;
} }
public void setAutoCapsMode(boolean autoCaps) { public void setAutoCapsMode(boolean autoCaps) {
@ -83,37 +62,37 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
@Override @Override
public void setAlphabetKeyboard() { public void setAlphabetKeyboard() {
mLayout = ALPHABET_UNSHIFTED; mLayout = Constants.ALPHABET_UNSHIFTED;
} }
@Override @Override
public void setShifted(int shiftMode) { public void setShifted(int shiftMode) {
if (shiftMode == SwitchActions.UNSHIFT) { if (shiftMode == SwitchActions.UNSHIFT) {
mLayout = ALPHABET_UNSHIFTED; mLayout = Constants.ALPHABET_UNSHIFTED;
} else if (shiftMode == SwitchActions.MANUAL_SHIFT) { } else if (shiftMode == SwitchActions.MANUAL_SHIFT) {
mLayout = ALPHABET_MANUAL_SHIFTED; mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
} else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) { } else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) {
mLayout = ALPHABET_AUTOMATIC_SHIFTED; mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
} }
} }
@Override @Override
public void setShiftLocked(boolean shiftLocked) { public void setShiftLocked(boolean shiftLocked) {
if (shiftLocked) { if (shiftLocked) {
mLayout = ALPHABET_SHIFT_LOCKED; mLayout = Constants.ALPHABET_SHIFT_LOCKED;
} else { } else {
mLayout = ALPHABET_UNSHIFTED; mLayout = Constants.ALPHABET_UNSHIFTED;
} }
} }
@Override @Override
public void setSymbolsKeyboard() { public void setSymbolsKeyboard() {
mLayout = SYMBOLS_UNSHIFTED; mLayout = Constants.SYMBOLS_UNSHIFTED;
} }
@Override @Override
public void setSymbolsShiftedKeyboard() { public void setSymbolsShiftedKeyboard() {
mLayout = SYMBOLS_SHIFTED; mLayout = Constants.SYMBOLS_SHIFTED;
} }
@Override @Override
@ -134,20 +113,14 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onPressKey(code); mState.onPressKey(code);
} }
public void onReleaseKey(int code) {
onReleaseKey(code, Constants.NOT_SLIDING);
}
public void onReleaseKey(int code, boolean withSliding) { public void onReleaseKey(int code, boolean withSliding) {
mState.onReleaseKey(code, withSliding); mState.onReleaseKey(code, withSliding);
} }
public void onCodeInput(int code) {
onCodeInput(code, Constants.SINGLE);
}
public void onCodeInput(int code, boolean isSinglePointer) { public void onCodeInput(int code, boolean isSinglePointer) {
mAutoCapsState = (WORD_SEPARATORS.indexOf(code) >= 0); if (Keyboard.isLetterCode(code)) {
mAutoCapsState = (code == Constants.CODE_AUTO_CAPS_TRIGGER);
}
mState.onCodeInput(code, isSinglePointer, mAutoCapsMode && mAutoCapsState); mState.onCodeInput(code, isSinglePointer, mAutoCapsMode && mAutoCapsState);
} }