def test_tapping(self): """Tapping the language menu key should switch to the previously used language. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) # Make sure the previous language is es and the current language is en self._set_keyboard_language("es") self.assertThat( keyboard._plugin_source, Eventually(Equals(self._get_plugin_path("es")))) self._set_keyboard_language("en") self.assertThat( keyboard._plugin_source, Eventually(Equals(self._get_plugin_path("en")))) keyboard.press_key("language") self.assertThat( keyboard._plugin_source, Eventually(Equals(self._get_plugin_path("es"))))
def test_selection_focus(self): """Focusing on a field with selected text should leave the text unchanged. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('This is a test') # Double tap to select a word self.pointer.click_object(text_area) self.pointer.click_object(text_area) keyboard.dismiss() self.ensure_focus_on_input(text_area) expected = 'This is a test' self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_shift_latch(self): """Double tap of the shift key must lock it 'On' until the shift key tapped again. Normally hitting shift then a letter reverts from the shifted state back to the default. If double clicked it should stay in the shifted until the shift key is clicked again. """ self.skip( "Skipping due to bug in emulator: lp:1237846" ) text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('abc') # Bug lp:1229003 and lp:1229001 sleep(.2) keyboard.press_key('shift') keyboard.press_key('shift') self.assertThat( keyboard.active_keypad_state, Eventually(Equals(KeyPadState.CAPSLOCK)) )
def test_can_type_string(self): text_area = self.launch_test_input_area(label=self.label) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type(self.input) self.assertThat(text_area.text, Eventually(Equals(self.input)))
def test_hiding(self): """Verify that the keyboard remains hidden after being dismissed from a field that is no longer enabled. """ qml = dedent(""" import QtQuick 2.4 import Ubuntu.Components 1.1 import Ubuntu.Web 0.2 Rectangle { id: window objectName: "windowRectangle" color: "lightgrey" WebView { anchors.fill: parent objectName: "webview" Component.onCompleted: { loadHtml(" <html><body><div id='scroll' style='width: 100%; height: 200%; position: absolute; background: green; visibility: hidden;'></div><input id='input' style='height: 50%; width: 100%' type='text' onkeyup=\\\"if (event.keyCode == 13) {document.getElementById('input').disabled=true; document.getElementById('scroll').style.visibility= 'visible';}\\\" style='width: 100%%; height: 100%%;' /></body></html>"); } } } """) app = self._start_qml_script(qml) webview = app.select_single(objectName='webview') self.ensure_focus_on_input(webview) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Test\n') keyboard.dismiss() pointer = Pointer(Touch.create()) pointer.drag( webview.width / 2.0, webview.height / 2.0, webview.width / 2.0, webview.height / 2.0 + 100 ) self.assertThat( keyboard.is_available, Eventually(Equals(False)) )
def test_can_type_using_key_mapping(self): text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type(self.starting_text) for key, result in zip(self.input_sequence, self.expected_text): keyboard.press_key(key) self.assertThat(text_area.text, Eventually(Equals(result)))
def test_can_type_using_state_key_mapping(self): text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText', 'Qt.ImhNoAutoUppercase']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) self._assert_keypad_name_and_state(keyboard, 'CHARACTERS', KeyPadState.NORMAL) keyboard.press_key(self.key) self._assert_keypad_name_and_state(keyboard, self.expected_keypad_name, self.expected_state)
def test_long_press(self): """Long pressing a key should enter the default extended character. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.press_key('t', long_press=True) expected = "5" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_fullstop(self): """Full stop shouldn't have space added after it in pinyin mode. """ text_area = self.launch_test_input_area(self.label, self.hints) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('pinyin.pinyin ') expected = "拼音.拼音" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_double_space_single_character(self): """Spaces should be auto-inserted after double pressing space following a single character. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Test i ') expected = "Test I. " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_single_quotes(self): """Single quotes placed around a word shouldn't get removed by autocomplete. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type("'here' 'to' ") expected = "'here' 'to' " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_autocomplete(self): """Tapping space in a field that supports auto-complete should complete a word. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Pic ') expected = "Picture " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_override(self): """After typing 'i' followed by a space it should get auto-corrected to 'I' via the override mechanism. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('i i i ') expected = "I I I " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_double_space_fullstop(self): """After tapping space twice a fullstop should be entered. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('This is a test ') expected = "This is a test. " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_layouts(self): """Test all layout plugins in freetext, url and email mode. """ text_area = self.launch_test_input_area( self.layout + " - " + self.expected_activeview, self.hints ) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) gsettings = Gio.Settings.new("com.canonical.keyboard.maliit") gsettings.set_string("active-language", self.layout) self.assertThat( gsettings.get_string("active-language"), Equals(self.layout) ) sleep(2) if self.text[-len(self.tld):] == self.tld: keyboard.type(self.text[:-len(self.tld)]) keyboard.press_key(self.tld) else: keyboard.type(self.text) self.assertThat( text_area.text, Eventually(Equals(self.text)) )
def test_restore_preedit(self): """Pressing delete after autocompleting a word should restore the original preedit state. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Helfn') sleep(2) keyboard.type(' ') expected = "Helen " self.assertThat( text_area.text, Eventually(Equals(expected)) ) keyboard.type('\b ') expected = "Helfn " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_autocomplete(self): """Test that words are auto-completed when entered into an oxide text field. """ qml = dedent(""" import QtQuick 2.4 import Ubuntu.Components 1.3 import Ubuntu.Web 0.2 Rectangle { id: window objectName: "windowRectangle" color: "lightgrey" WebView { anchors.fill: parent objectName: "webview" Component.onCompleted: { loadHtml(" <html><body><textarea id='textarea' onkeyup=\\\"document.title= document.getElementById('textarea').value;\\\" style='width: 100%; height: 100%;'> </textarea></body></html>" ); } } } """) app = self._start_qml_script(qml) webview = app.select_single(objectName='webview') self.ensure_focus_on_input(webview) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Pic ') expected = 'Picture' self.assertThat( webview.title, Eventually(Equals(expected)) )
def test_keyboard_layout(self): """The Keyboard must respond to the input type and change to be the correct state. """ text_area = self.launch_test_input_area(self.label, self.hints) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) self.assertThat( keyboard.keyboard.layoutId, Eventually(Equals(self.expected_activeview)) ) if self.text[-4:] == ".com": keyboard.type(self.text[:-4]) keyboard.press_key(".com") else: keyboard.type(self.text) self.assertThat( text_area.text, Eventually(Equals(self.text)) )
def test_visibility_reporting(self): """The keyboard should only report visibility changes once. """ # Test bug #1436076 which only occurs after maliit is restarted subprocess.check_call(['initctl', 'set-env', 'QT_LOAD_TESTABILITY=1']) subprocess.check_call(['restart', 'maliit-server']) sleep(10) qml = dedent(""" import QtQuick 2.4 import Ubuntu.Components 1.3 Rectangle { id: window objectName: "windowRectangle" color: "lightgrey" TextField { id: input; objectName: "input" anchors.centerIn: parent property int visibilityChangeCount: 0 } Connections { target: Qt.inputMethod onVisibleChanged: { input.visibilityChangeCount++; } } } """) app = self._start_qml_script(qml) text_area = app.select_single(objectName='input') self.ensure_focus_on_input(text_area) keyboard = Keyboard() keyboard.dismiss() self.assertThat( text_area.visibilityChangeCount, Eventually(Equals(2)) )
def test_shift_state_returns_to_default_after_letter_typed(self): """Pushing shift and then typing an uppercase letter must automatically shift the keyboard back into the default state. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) # Normally, type and (press_key) take care of shifting into the correct # state, we do it manually here as that's what we're testing. keyboard.type('abc') keyboard.press_key('SHIFT') keyboard.type('A') # Once the capital letter has been typed, we must be able to access the # lowercase letters, otherwise it's not in the correct state. self.assertThat( keyboard.active_keypad_state, Eventually(Equals(KeyPadState.NORMAL)) ) self.assertThat(text_area.text, Eventually(Equals('abcA')))
def test_japanese_input(self): """Test top level keys on Japanese layout. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.pointer.click_object(text_area) keyboard = Keyboard() self.assertThat(keyboard.is_available, Eventually(Equals(True))) text = "あかさたなはまやら" keyboard.type(text) keyboard.press_key('\n') self.assertThat( text_area.text, Eventually(Equals(text)) )
def test_pinyin(self): """Switching to Chinese should result in pinyin characters being entered via autocomplete regardless of layout or prediction being disabled. """ text_area = self.launch_test_input_area(self.label, self.hints) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('pinyin ') expected = "拼音" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_typing(self): """Test that typing works using a plugin loaded from a custom location. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) # The test layout has a single key that enters the word 'Test' keyboard.press_key("Test") expected = "Test" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_switching_with_preedit(self): """Switching languages whilst text is in preedit should result in that text being committed. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Hello') keyboard.press_key("language") expected = 'Hello' self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_switching_between_states(self): """The user must be able to type many different characters including spaces and backspaces. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type( 'abc gone\b\b & \bABC (123)' ) expected = "abc go & ABC (123)" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_auto_punctuation(self): """A chinese full-stop character should be entered after space has been pressed three times (once to complete the character, once more to insert a space and then again to produce a full-stop. """ text_area = self.launch_test_input_area(self.label, self.hints) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('pinyin ') expected = "拼音。 " self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_repeated_long_press(self): """The default key should stay in the middle after each long press. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.press_key('u', long_press=True) keyboard.press_key('u', long_press=True) keyboard.press_key('u', long_press=True) expected = "777" self.assertThat( text_area.text, Eventually(Equals(expected)) )
def test_shift_state_left_after_deleting_fullstop(self): """After deleting a fullstop the keyboard should return to the normal state. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type("Hello my friend. \b\b") self.assertThat( text_area.text, Eventually(Equals("Hello my friend")) ) self.assertThat( keyboard.active_keypad_state, Eventually(Equals(KeyPadState.NORMAL)) )
def test_shift_state_entered_after_fullstop(self): """After typing a fullstop followed by a space the keyboard state must automatically enter the shifted state. """ text_area = self.launch_test_input_area( input_hints=['Qt.ImhNoPredictiveText']) self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type("abc. ") self.assertThat( text_area.text, Eventually(Equals("abc. ")) ) self.assertThat( keyboard.active_keypad_state, Eventually(Equals(KeyPadState.SHIFTED)) )
def test_delete_selection(self): """Selecting a word and then pressing backspace should delete the world. """ text_area = self.launch_test_input_area() self.ensure_focus_on_input(text_area) keyboard = Keyboard() self.addCleanup(keyboard.dismiss) keyboard.type('Testing the selection deletion') # Double tap to select a word self.pointer.click_object(text_area) self.pointer.click_object(text_area) keyboard.type('\b') expected = 'Testing the deletion' self.assertThat( text_area.text, Eventually(Equals(expected)) )
def _go_to_start(self): # We override this because the text areas can have more than one line. if self._is_keyboard_osk(): from ubuntu_keyboard.emulators.keyboard import Keyboard osk = Keyboard() while self.cursorPosition != 0: # Move to the start of the line above osk.send_up_key() osk.send_home_key() else: self.keyboard.press_and_release('Ctrl+Home')
def _go_to_end(self): # We override this because the text areas can have more than one line. if self._is_keyboard_osk(): from ubuntu_keyboard.emulators.keyboard import Keyboard osk = Keyboard() while self.cursorPosition != len(self.text): # Move to the end of the line below osk.send_down_key() osk.send_end_key() else: self.keyboard.press_and_release('Ctrl+End')
def _go_to_start(self): if self._is_keyboard_osk(): from ubuntu_keyboard.emulators.keyboard import Keyboard Keyboard().send_home_key() else: self.keyboard.press_and_release('Home')
def _go_to_end(self): if self._is_keyboard_osk(): from ubuntu_keyboard.emulators.keyboard import Keyboard Keyboard().send_end_key() else: self.keyboard.press_and_release('End')
def close_osk(self): """Swipe down to close on-screen keyboard""" if is_maliit_process_running(): osk = UbuntuKeyboard() osk.dismiss()
def dismiss_osk(): if is_maliit_process_running(): osk = Keyboard() osk.dismiss()