This source file includes following definitions.
- Feature
- testNoChanges
- Feature
- testBasicLanguageChanges
- Feature
- testInvalidLanguageChanges
- Feature
- testBasicOptionsChanges
- Feature
- testInvalidOptionsChanges
package org.chromium.chrome.browser.translate;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.infobar.TranslateOptions;
public class TranslateOptionsTest extends AndroidTestCase {
private static final String[] languages = {"English", "Spanish", "French"};
private static final boolean ALWAYS_TRANSLATE = true;
@SmallTest
@Feature({"Translate"})
public void testNoChanges() {
TranslateOptions options = new TranslateOptions(0, 1, languages, ALWAYS_TRANSLATE, false);
assertEquals("English", options.sourceLanguage());
assertEquals("Spanish", options.targetLanguage());
assertEquals(0, options.sourceLanguageIndex());
assertEquals(1, options.targetLanguageIndex());
assertFalse(options.neverTranslateLanguageState());
assertTrue(options.alwaysTranslateLanguageState());
assertFalse(options.neverTranslateDomainState());
assertFalse(options.optionsChanged());
}
@SmallTest
@Feature({"Translate"})
public void testBasicLanguageChanges() {
TranslateOptions options = new TranslateOptions(0, 1, languages, !ALWAYS_TRANSLATE, true);
options.setTargetLanguage(2);
options.setSourceLanguage(1);
assertEquals("Spanish", options.sourceLanguage());
assertEquals("French", options.targetLanguage());
assertEquals(1, options.sourceLanguageIndex());
assertEquals(2, options.targetLanguageIndex());
assertTrue(options.triggeredFromMenu());
assertTrue(options.optionsChanged());
options.setSourceLanguage(0);
options.setTargetLanguage(1);
assertFalse(options.optionsChanged());
}
@SmallTest
@Feature({"Translate"})
public void testInvalidLanguageChanges() {
TranslateOptions options = new TranslateOptions(0, 1, languages, ALWAYS_TRANSLATE, false);
assertFalse(options.setTargetLanguage(0));
assertFalse(options.optionsChanged());
assertFalse(options.setTargetLanguage(23));
assertFalse(options.optionsChanged());
assertFalse(options.setSourceLanguage(1));
assertFalse(options.optionsChanged());
assertFalse(options.setSourceLanguage(23));
assertFalse(options.optionsChanged());
}
@SmallTest
@Feature({"Translate"})
public void testBasicOptionsChanges() {
TranslateOptions options = new TranslateOptions(0, 1, languages, !ALWAYS_TRANSLATE, false);
assertFalse(options.optionsChanged());
options.toggleNeverTranslateDomainState(true);
assertTrue(options.neverTranslateDomainState());
assertFalse(options.alwaysTranslateLanguageState());
assertFalse(options.neverTranslateLanguageState());
assertTrue(options.optionsChanged());
options.toggleNeverTranslateDomainState(false);
assertFalse(options.neverTranslateDomainState());
assertFalse(options.neverTranslateLanguageState());
assertFalse(options.alwaysTranslateLanguageState());
assertFalse(options.optionsChanged());
options.toggleAlwaysTranslateLanguageState(true);
assertFalse(options.neverTranslateDomainState());
assertFalse(options.neverTranslateLanguageState());
assertTrue(options.alwaysTranslateLanguageState());
assertTrue(options.optionsChanged());
}
@SmallTest
@Feature({"Translate"})
public void testInvalidOptionsChanges() {
TranslateOptions options = new TranslateOptions(0, 1, languages, ALWAYS_TRANSLATE, false);
assertFalse(options.toggleNeverTranslateLanguageState(true));
assertTrue(options.toggleNeverTranslateDomainState(true));
assertTrue(options.optionsChanged());
assertTrue(options.toggleAlwaysTranslateLanguageState(false));
assertTrue(options.toggleNeverTranslateLanguageState(true));
assertTrue(options.toggleNeverTranslateDomainState(true));
assertFalse(options.toggleAlwaysTranslateLanguageState(true));
}
}