Add test to detect Translate action for foreign text.
Bug: 34780395 Bug: 116020587 Test: atest android.view.textclassifier.TextClassifierTest Change-Id: I0965d1b797fed432b552e4d9396fc140ac087c46
This commit is contained in:
@@ -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.";
|
||||
@@ -233,6 +236,30 @@ public class TextClassifierTest {
|
||||
isTextClassification(classifiedText, TextClassifier.TYPE_DATE_TIME));
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
Reference in New Issue
Block a user