1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.design.widget;
18
19import static android.support.test.InstrumentationRegistry.getContext;
20import static android.support.test.espresso.Espresso.onView;
21import static android.support.test.espresso.action.ViewActions.typeText;
22import static android.support.test.espresso.matcher.ViewMatchers.withId;
23
24import android.content.Context;
25import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.support.design.test.R;
28import android.support.test.filters.MediumTest;
29
30import org.junit.AfterClass;
31import org.junit.BeforeClass;
32import org.junit.Test;
33
34import java.util.Locale;
35
36@MediumTest
37public class TextInputLayoutPseudoLocaleTest extends
38        BaseInstrumentationTestCase<TextInputLayoutActivity> {
39
40    private static final String ORIGINAL_LANGUAGE = Locale.getDefault().getLanguage();
41    private static final String ORIGINAL_COUNTRY = Locale.getDefault().getLanguage();
42
43    @BeforeClass
44    public static void setup() {
45        // Change language to pseudo locale.
46        setLocale("ar", "XB", getContext());
47    }
48
49    public TextInputLayoutPseudoLocaleTest() {
50        super(TextInputLayoutActivity.class);
51    }
52
53    private static void setLocale(String language,  String country,  Context context) {
54        context = context.getApplicationContext();
55        Resources resources = context.getResources();
56        Configuration configuration = resources.getConfiguration();
57        configuration.setLocale(new Locale(language, country));
58        resources.updateConfiguration(configuration, resources.getDisplayMetrics());
59    }
60
61    @Test
62    public void testSimpleEdit() {
63        // Type some text
64        onView(withId(R.id.textinput_edittext)).perform(typeText("123"));
65    }
66
67    @AfterClass
68    public static void  cleanup() {
69        setLocale(ORIGINAL_LANGUAGE, ORIGINAL_COUNTRY, getContext());
70    }
71}
72