| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import android.perftests.utils.BenchmarkState; |
| 20 |
import android.perftests.utils.PerfStatusReporter; |
| 21 |
import android.perftests.utils.PerfTestActivity; |
| 22 |
|
| 23 |
import androidx.test.filters.LargeTest; |
| 24 |
import androidx.test.rule.ActivityTestRule; |
| 25 |
|
| 26 |
import org.junit.Rule; |
| 27 |
import org.junit.Test; |
| 28 |
import org.junit.runner.RunWith; |
| 29 |
import org.junit.runners.Parameterized; |
| 30 |
import org.junit.runners.Parameterized.Parameters; |
| 31 |
|
| 32 |
import java.util.Arrays; |
| 33 |
import java.util.Collection; |
| 34 |
import java.util.Locale; |
| 35 |
|
| 36 |
@LargeTest |
| 37 |
@RunWith(Parameterized.class) |
| 38 |
public class TextViewSetTextLocalePerfTest { |
| 39 |
@Parameters(name = "{0}") |
| 40 |
public static Collection locales() { |
| 41 |
return Arrays.asList(new Object[][] { |
| 42 |
{ "SameLocale", "en-US", "en-US" }, |
| 43 |
{ "DifferentLocale", "en-US", "ja-JP"} |
| 44 |
}); |
| 45 |
} |
| 46 |
|
| 47 |
private String mMetricKey; |
| 48 |
private Locale mFirstLocale; |
| 49 |
private Locale mSecondLocale; |
| 50 |
|
| 51 |
public TextViewSetTextLocalePerfTest( |
| 52 |
String metricKey, String firstLocale, String secondLocale) { |
| 53 |
mMetricKey = metricKey; |
| 54 |
mFirstLocale = Locale.forLanguageTag(firstLocale); |
| 55 |
mSecondLocale = Locale.forLanguageTag(secondLocale); |
| 56 |
} |
| 57 |
|
| 58 |
@Rule |
| 59 |
public ActivityTestRule<PerfTestActivity> mActivityRule = |
| 60 |
new ActivityTestRule<>(PerfTestActivity.class); |
| 61 |
|
| 62 |
@Rule |
| 63 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 64 |
|
| 65 |
@Test |
| 66 |
public void testSetTextLocale() { |
| 67 |
TextView textView = new TextView(mActivityRule.getActivity()); |
| 68 |
|
| 69 |
BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 70 |
|
| 71 |
while (state.keepRunning()) { |
| 72 |
textView.setTextLocale(mFirstLocale); |
| 73 |
textView.setTextLocale(mSecondLocale); |
| 74 |
} |
| 75 |
} |
| 76 |
} |