diff options
| author | 2018-11-27 20:08:00 +0000 | |
|---|---|---|
| committer | 2018-11-27 20:22:42 +0000 | |
| commit | 229f40a6d13a248ceaa326b92a350e4f39264b05 (patch) | |
| tree | d7578dd240cd3891bae0d7ddd16a8265e85dec2a | |
| parent | 9d03c64c97ff453821ab9d41ab5d3d3b986c3fe3 (diff) | |
Add test to detect Translate action for foreign text.
Bug: 34780395
Bug: 116020587
Test: atest android.view.textclassifier.TextClassifierTest
Change-Id: I0965d1b797fed432b552e4d9396fc140ac087c46
| -rw-r--r-- | core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java index 06ba15e8e339..6eb5d870623c 100644 --- a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java +++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import android.content.Context; +import android.content.Intent; import android.os.LocaleList; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; @@ -58,6 +59,8 @@ public class TextClassifierTest { @Parameterized.Parameter public String mTextClassifierType; + private static final TextClassificationConstants TC_CONSTANTS = + TextClassificationConstants.loadFromString(""); private static final LocaleList LOCALES = LocaleList.forLanguageTags("en-US"); private static final String NO_TYPE = null; @@ -74,7 +77,7 @@ public class TextClassifierTest { } @Test - public void testSmartSelection() { + public void testSuggestSelection() { if (isTextClassifierDisabled()) return; String text = "Contact me at droid@android.com"; @@ -95,7 +98,7 @@ public class TextClassifierTest { } @Test - public void testSmartSelection_url() { + public void testSuggestSelection_url() { if (isTextClassifierDisabled()) return; String text = "Visit http://www.android.com for more information"; @@ -151,7 +154,7 @@ public class TextClassifierTest { } @Test - public void testTextClassifyText_url() { + public void testClassifyText_url() { if (isTextClassifierDisabled()) return; String text = "Visit www.android.com for more information"; @@ -168,7 +171,7 @@ public class TextClassifierTest { } @Test - public void testTextClassifyText_address() { + public void testClassifyText_address() { if (isTextClassifierDisabled()) return; String text = "Brandschenkestrasse 110, Zürich, Switzerland"; @@ -182,7 +185,7 @@ public class TextClassifierTest { } @Test - public void testTextClassifyText_url_inCaps() { + public void testClassifyText_url_inCaps() { if (isTextClassifierDisabled()) return; String text = "Visit HTTP://ANDROID.COM for more information"; @@ -199,7 +202,7 @@ public class TextClassifierTest { } @Test - public void testTextClassifyText_date() { + public void testClassifyText_date() { if (isTextClassifierDisabled()) return; String text = "Let's meet on January 9, 2018."; @@ -216,7 +219,7 @@ public class TextClassifierTest { } @Test - public void testTextClassifyText_datetime() { + public void testClassifyText_datetime() { if (isTextClassifierDisabled()) return; String text = "Let's meet 2018/01/01 10:30:20."; @@ -234,6 +237,30 @@ public class TextClassifierTest { } @Test + public void testClassifyText_foreignText() { + LocaleList originalLocales = LocaleList.getDefault(); + LocaleList.setDefault(LocaleList.forLanguageTags("en")); + String foreignText = "これは日本語のテキストです"; + + Context context = new FakeContextBuilder() + .setIntentComponent(Intent.ACTION_TRANSLATE, FakeContextBuilder.DEFAULT_COMPONENT) + .build(); + TextClassifier classifier = new TextClassifierImpl(context, TC_CONSTANTS); + TextClassification.Request request = new TextClassification.Request.Builder( + foreignText, 0, foreignText.length()) + .setDefaultLocales(LOCALES) + .build(); + + TextClassification classification = classifier.classifyText(request); + assertEquals(1, classification.getActions().size()); + assertEquals( + context.getString(com.android.internal.R.string.translate), + classification.getActions().get(0).getTitle()); + + LocaleList.setDefault(originalLocales); + } + + @Test public void testGenerateLinks_phone() { if (isTextClassifierDisabled()) return; String text = "The number is +12122537077. See you tonight!"; |