Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.tests.helpers; |
michael@0 | 6 | |
michael@0 | 7 | import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertEquals; |
michael@0 | 8 | import android.view.inputmethod.ExtractedText; |
michael@0 | 9 | import android.view.inputmethod.ExtractedTextRequest; |
michael@0 | 10 | import android.view.inputmethod.InputConnection; |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * Provides helper functions for accessing the InputConnection interface |
michael@0 | 14 | */ |
michael@0 | 15 | public final class TextInputHelper { |
michael@0 | 16 | |
michael@0 | 17 | private TextInputHelper() { /* To disallow instantiation. */ } |
michael@0 | 18 | |
michael@0 | 19 | private static ExtractedText getExtractedText(final InputConnection ic) { |
michael@0 | 20 | ExtractedTextRequest req = new ExtractedTextRequest(); |
michael@0 | 21 | ExtractedText extract = ic.getExtractedText(req, 0); |
michael@0 | 22 | return extract; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | private static String getText(final InputConnection ic) { |
michael@0 | 26 | return getExtractedText(ic).text.toString(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | public static void assertText(final String message, |
michael@0 | 30 | final InputConnection ic, |
michael@0 | 31 | final String text) { |
michael@0 | 32 | fAssertEquals(message, text, getText(ic)); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | public static void assertSelection(final String message, |
michael@0 | 36 | final InputConnection ic, |
michael@0 | 37 | final int start, |
michael@0 | 38 | final int end) { |
michael@0 | 39 | ExtractedText extract = getExtractedText(ic); |
michael@0 | 40 | fAssertEquals(message, start, extract.selectionStart); |
michael@0 | 41 | fAssertEquals(message, end, extract.selectionEnd); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | public static void assertSelectionAt(final String message, |
michael@0 | 45 | final InputConnection ic, |
michael@0 | 46 | final int value) { |
michael@0 | 47 | assertSelection(message, ic, value, value); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | public static void assertTextAndSelection(final String message, |
michael@0 | 51 | final InputConnection ic, |
michael@0 | 52 | final String text, |
michael@0 | 53 | final int start, |
michael@0 | 54 | final int end) { |
michael@0 | 55 | ExtractedText extract = getExtractedText(ic); |
michael@0 | 56 | fAssertEquals(message, text, extract.text); |
michael@0 | 57 | fAssertEquals(message, start, extract.selectionStart); |
michael@0 | 58 | fAssertEquals(message, end, extract.selectionEnd); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | public static void assertTextAndSelectionAt(final String message, |
michael@0 | 62 | final InputConnection ic, |
michael@0 | 63 | final String text, |
michael@0 | 64 | final int selection) { |
michael@0 | 65 | assertTextAndSelection(message, ic, text, selection, selection); |
michael@0 | 66 | } |
michael@0 | 67 | } |