Commit 10e8b7bc authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

[TTS] Remove Translation support from ContextualSearchPolicy.java

There is dead code for translation in ContextualSearchPolicy.java
due to translation handled by a separate translation class.
This CL removes the dead code.

Bug: 1137510
Change-Id: I60af0160aa24b81372038bc08cfb4ec8dcf4220a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546387
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829020}
parent fc762c5c
...@@ -31,8 +31,6 @@ import org.chromium.components.embedder_support.util.UrlConstants; ...@@ -31,8 +31,6 @@ import org.chromium.components.embedder_support.util.UrlConstants;
import java.net.URL; import java.net.URL;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
...@@ -442,60 +440,6 @@ class ContextualSearchPolicy { ...@@ -442,60 +440,6 @@ class ContextualSearchPolicy {
ChromePreferenceKeys.CONTEXTUAL_SEARCH_TAP_SINCE_OPEN_COUNT); ChromePreferenceKeys.CONTEXTUAL_SEARCH_TAP_SINCE_OPEN_COUNT);
} }
// --------------------------------------------------------------------------------------------
// Translation support.
// --------------------------------------------------------------------------------------------
/**
* Determines whether translation is needed between the given languages.
* @param sourceLanguage The source language code; language we're translating from.
* @param targetLanguages A list of target language codes; languages we might translate to.
* @return Whether translation is needed or not.
*/
boolean needsTranslation(String sourceLanguage, List<String> targetLanguages) {
// For now, we just look for a language match.
for (String targetLanguage : targetLanguages) {
if (TextUtils.equals(sourceLanguage, targetLanguage)) {
return false;
}
}
return true;
}
/**
* @return The best target language from the ordered list, or the empty string if
* none is available.
*/
String bestTargetLanguage(List<String> targetLanguages) {
return bestTargetLanguage(targetLanguages, Locale.getDefault().getCountry());
}
/**
* Determines the best language to convert into, given the ordered list of languages the user
* knows, and the UX language.
* @param targetLanguages The list of languages to consider converting to.
* @param countryOfUx The country of the UX.
* @return the best language or an empty string.
*/
@VisibleForTesting
String bestTargetLanguage(List<String> targetLanguages, String countryOfUx) {
// For now, we just return the first language, unless it's English
// (due to over-usage).
// TODO(donnd): Improve this logic. Determining the right language seems non-trivial.
// E.g. If this language doesn't match the user's server preferences, they might see a page
// in one language and the one box translation in another, which might be confusing.
// Also this logic should only apply on Android, where English setup is overused.
if (targetLanguages.size() > 1
&& TextUtils.equals(targetLanguages.get(0), Locale.ENGLISH.getLanguage())
&& !PREDOMINENTLY_ENGLISH_SPEAKING_COUNTRIES.contains(countryOfUx)) {
return targetLanguages.get(1);
} else if (targetLanguages.size() > 0) {
return targetLanguages.get(0);
} else {
return "";
}
}
/** /**
* @return The ISO country code for the user's home country, or an empty string if not * @return The ISO country code for the user's home country, or an empty string if not
* available or privacy-enabled. * available or privacy-enabled.
......
...@@ -29,7 +29,6 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule; ...@@ -29,7 +29,6 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
/** /**
* Tests for the ContextualSearchPolicy class. * Tests for the ContextualSearchPolicy class.
...@@ -53,55 +52,6 @@ public class ContextualSearchPolicyTest { ...@@ -53,55 +52,6 @@ public class ContextualSearchPolicyTest {
() -> mPolicy = new ContextualSearchPolicy(null, mMockServer)); () -> mPolicy = new ContextualSearchPolicy(null, mMockServer));
} }
@Test
@SmallTest
@Feature({"ContextualSearch"})
public void testBestTargetLanguageFromMultiple() {
ArrayList<String> list = new ArrayList<String>();
list.add("br");
list.add("de");
Assert.assertEquals("br", mPolicy.bestTargetLanguage(list));
}
@Test
@SmallTest
@Feature({"ContextualSearch"})
public void testBestTargetLanguageSkipsEnglish() {
String countryOfUx = "";
ArrayList<String> list = new ArrayList<String>();
list.add("en");
list.add("id");
Assert.assertEquals("id", mPolicy.bestTargetLanguage(list, countryOfUx));
}
@Test
@SmallTest
@Feature({"ContextualSearch"})
public void testBestTargetLanguageReturnsEnglishWhenInUS() {
String countryOfUx = "US";
ArrayList<String> list = new ArrayList<String>();
list.add("en");
list.add("id");
Assert.assertEquals("en", mPolicy.bestTargetLanguage(list, countryOfUx));
}
@Test
@SmallTest
@Feature({"ContextualSearch"})
public void testBestTargetLanguageUsesEnglishWhenOnlyChoice() {
ArrayList<String> list = new ArrayList<String>();
list.add("en");
Assert.assertEquals("en", mPolicy.bestTargetLanguage(list));
}
@Test
@SmallTest
@Feature({"ContextualSearch"})
public void testBestTargetLanguageReturnsEmptyWhenNoChoice() {
ArrayList<String> list = new ArrayList<String>();
Assert.assertEquals("", mPolicy.bestTargetLanguage(list));
}
/** Call on the UI thread to set up all the conditions needed for sending the URL. */ /** Call on the UI thread to set up all the conditions needed for sending the URL. */
private void setupAllConditionsToSendUrl() { private void setupAllConditionsToSendUrl() {
mPolicy.overrideDecidedStateForTesting(true); mPolicy.overrideDecidedStateForTesting(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment