2011-12-09 11:18:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 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;
|
|
|
|
|
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
|
|
|
|
public class KeyboardStateTests extends AndroidTestCase {
|
2012-01-13 11:02:05 +00:00
|
|
|
private MockKeyboardSwitcher mSwitcher;
|
2011-12-09 11:18:39 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher = new MockKeyboardSwitcher();
|
2011-12-09 11:18:39 +00:00
|
|
|
|
2012-01-13 11:02:05 +00:00
|
|
|
final String layoutSwitchBackSymbols = "";
|
2011-12-09 11:18:39 +00:00
|
|
|
// TODO: Unit tests for non-distinct multi touch device.
|
|
|
|
final boolean hasDistinctMultitouch = true;
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch);
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Argument for KeyboardState.onPressShift and onReleaseShift.
|
|
|
|
private static final boolean NOT_SLIDING = false;
|
|
|
|
private static final boolean SLIDING = true;
|
|
|
|
// Argument for KeyboardState.onCodeInput.
|
|
|
|
private static final boolean SINGLE = true;
|
|
|
|
private static final boolean MULTI = false;
|
2012-01-16 06:07:58 +00:00
|
|
|
static final boolean NO_AUTO_CAPS = false;
|
2011-12-26 14:40:09 +00:00
|
|
|
private static final boolean AUTO_CAPS = true;
|
2011-12-09 11:18:39 +00:00
|
|
|
|
|
|
|
private void assertAlphabetNormal() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertAlphabetNormal());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertAlphabetManualShifted() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertAlphabetManualShifted());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertAlphabetAutomaticShifted() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertAlphabetAutomaticShifted());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertAlphabetShiftLocked() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertAlphabetShiftLocked());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertSymbolsNormal() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertSymbolsNormal());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertSymbolsShifted() {
|
2012-01-16 06:07:58 +00:00
|
|
|
assertTrue(mSwitcher.assertSymbolsShifted());
|
2011-12-09 11:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initial state test.
|
|
|
|
public void testLoadKeyboard() {
|
|
|
|
assertAlphabetNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shift key in alphabet mode.
|
|
|
|
public void testShift() {
|
|
|
|
// Press/release shift key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
|
|
|
|
|
|
|
// Press/release shift key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
|
|
|
|
// TODO: Sliding test
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switching between alphabet and symbols.
|
|
|
|
public void testAlphabetAndSymbols() {
|
|
|
|
// Press/release "?123" key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsNormal();
|
|
|
|
|
|
|
|
// Press/release "ABC" key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
|
|
|
|
// TODO: Sliding test
|
|
|
|
// TODO: Snap back test
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switching between symbols and symbols shifted.
|
|
|
|
public void testSymbolsAndSymbolsShifted() {
|
|
|
|
// Press/release "?123" key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsNormal();
|
|
|
|
|
|
|
|
// Press/release "=\<" key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertSymbolsShifted();
|
|
|
|
|
|
|
|
// Press/release "ABC" key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseSymbol();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
|
|
|
|
// TODO: Sliding test
|
|
|
|
// TODO: Snap back test
|
|
|
|
}
|
|
|
|
|
|
|
|
// Automatic upper case test
|
|
|
|
public void testAutomaticUpperCase() {
|
2012-01-16 06:07:58 +00:00
|
|
|
mSwitcher.setAutoCapsMode(AUTO_CAPS);
|
2011-12-09 11:18:39 +00:00
|
|
|
// Update shift state with auto caps enabled.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.updateShiftState();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetAutomaticShifted();
|
|
|
|
|
|
|
|
// Press shift key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
|
|
|
// Release shift key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
|
|
|
|
// TODO: Chording test.
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: UpdateShiftState with shift locked, etc.
|
|
|
|
|
|
|
|
// TODO: Multitouch test
|
|
|
|
|
|
|
|
// TODO: Change focus test.
|
|
|
|
|
|
|
|
// TODO: Change orientation test.
|
|
|
|
|
|
|
|
// Long press shift key.
|
|
|
|
// TODO: Move long press recognizing timer/logic into KeyboardState.
|
|
|
|
public void testLongPressShift() {
|
|
|
|
// Long press shift key
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
|
|
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.toggleCapsLock();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetShiftLocked();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetShiftLocked();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetShiftLocked();
|
|
|
|
|
|
|
|
// Long press shift key.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
|
|
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.toggleCapsLock();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double tap shift key.
|
|
|
|
// TODO: Move double tap recognizing timer/logic into KeyboardState.
|
|
|
|
public void testDoubleTapShift() {
|
|
|
|
// First shift key tap.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
|
|
|
// Second shift key tap.
|
|
|
|
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.toggleCapsLock();
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetShiftLocked();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetShiftLocked();
|
|
|
|
|
|
|
|
// First shift key tap.
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onPressShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetManualShifted();
|
2012-01-13 11:02:05 +00:00
|
|
|
mSwitcher.onReleaseShift(NOT_SLIDING);
|
2011-12-09 11:18:39 +00:00
|
|
|
assertAlphabetNormal();
|
|
|
|
// Second shift key tap.
|
|
|
|
// Second tap is ignored in LatinKeyboardView.KeyTimerHandler.
|
|
|
|
}
|
|
|
|
}
|