19ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes/*
29ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * Copyright (C) 2016 The Android Open Source Project
39ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes *
49ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * Licensed under the Apache License, Version 2.0 (the "License");
59ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * you may not use this file except in compliance with the License.
69ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * You may obtain a copy of the License at
79ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes *
89ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes *      http://www.apache.org/licenses/LICENSE-2.0
99ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes *
109ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * Unless required by applicable law or agreed to in writing, software
119ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * distributed under the License is distributed on an "AS IS" BASIS,
129ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * See the License for the specific language governing permissions and
149ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes * limitations under the License.
159ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes */
169ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
179ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banespackage android.support.design.widget;
189ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
1946c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banesimport static android.support.design.testutils.TestUtilsActions.setCompoundDrawablesRelative;
208a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport static android.support.design.testutils.TestUtilsActions.setEnabled;
2146c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banesimport static android.support.design.testutils.TestUtilsMatchers.withCompoundDrawable;
229ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.design.testutils.TextInputLayoutActions.setError;
239ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.design.testutils.TextInputLayoutActions.setErrorEnabled;
248a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport static android.support.design.testutils.TextInputLayoutActions
258a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        .setPasswordVisibilityToggleEnabled;
269ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.Espresso.onView;
27ddf46923b9487ac3a021f01b55d96136d811e8beChris Banesimport static android.support.test.espresso.action.ViewActions.click;
288a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport static android.support.test.espresso.action.ViewActions.typeText;
299ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
309ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.assertion.ViewAssertions.matches;
319ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
328a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
339ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.matcher.ViewMatchers.withId;
349ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banesimport static android.support.test.espresso.matcher.ViewMatchers.withText;
358a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
36ddf46923b9487ac3a021f01b55d96136d811e8beChris Banesimport static org.hamcrest.Matchers.not;
37ddf46923b9487ac3a021f01b55d96136d811e8beChris Banesimport static org.junit.Assert.assertEquals;
38ddf46923b9487ac3a021f01b55d96136d811e8beChris Banesimport static org.junit.Assert.assertNotEquals;
398a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport static org.junit.Assert.assertTrue;
408a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
418a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.app.Activity;
4246c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banesimport android.graphics.Color;
4346c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banesimport android.graphics.drawable.ColorDrawable;
4446c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banesimport android.graphics.drawable.Drawable;
458a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.support.design.test.R;
461ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viveretteimport android.support.test.annotation.UiThreadTest;
478a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.support.test.espresso.NoMatchingViewException;
488a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.support.test.espresso.ViewAssertion;
498a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.test.suitebuilder.annotation.SmallTest;
508a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.view.View;
518a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport android.widget.EditText;
528a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
538a40d691aa783c2e85298e895a3e51e98606aa85Chris Banesimport org.junit.Test;
549ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
559ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes@SmallTest
569ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banespublic class TextInputLayoutTest extends BaseInstrumentationTestCase<TextInputLayoutActivity> {
579ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
589ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    private static final String ERROR_MESSAGE_1 = "An error has occured";
599ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    private static final String ERROR_MESSAGE_2 = "Some other error has occured";
609ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
61ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    private static final String INPUT_TEXT = "Random input text";
62ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
639ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    public TextInputLayoutTest() {
649ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        super(TextInputLayoutActivity.class);
659ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    }
669ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
679ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    @Test
688a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    public void testTypingTextCollapsesHint() {
698a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Type some text
708a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext)).perform(typeText(INPUT_TEXT));
718a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // ...and check that the hint has collapsed
728a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput)).check(isHintExpanded(false));
738a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    }
748a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
758a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    @Test
769ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    public void testSetErrorEnablesErrorIsDisplayed() {
779ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withId(R.id.textinput)).perform(setError(ERROR_MESSAGE_1));
789ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withText(ERROR_MESSAGE_1)).check(matches(isDisplayed()));
799ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    }
809ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
819ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    @Test
829ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    public void testDisabledErrorIsNotDisplayed() {
839ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        // First show an error, and then disable error functionality
849ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withId(R.id.textinput))
859ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes                .perform(setError(ERROR_MESSAGE_1))
869ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes                .perform(setErrorEnabled(false));
879ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
889ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        // Check that the error is no longer there
899ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withText(ERROR_MESSAGE_1)).check(doesNotExist());
909ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    }
919ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
929ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    @Test
939ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    public void testSetErrorOnDisabledSetErrorIsDisplayed() {
949ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        // First show an error, and then disable error functionality
959ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withId(R.id.textinput))
969ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes                .perform(setError(ERROR_MESSAGE_1))
979ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes                .perform(setErrorEnabled(false));
989ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
999ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        // Now show a different error message
1009ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withId(R.id.textinput)).perform(setError(ERROR_MESSAGE_2));
1019ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        // And check that it is displayed
1029ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes        onView(withText(ERROR_MESSAGE_2)).check(matches(isDisplayed()));
1039ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes    }
1049ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes
105ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    @Test
106ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    public void testPasswordToggleClick() {
1078a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Type some text on the EditText
1088a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext_pwd)).perform(typeText(INPUT_TEXT));
109ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
110ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        final Activity activity = mActivityTestRule.getActivity();
111ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        final EditText textInput = (EditText) activity.findViewById(R.id.textinput_edittext_pwd);
112ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
113ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Assert that the password is disguised
114f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
115ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
116ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Now click the toggle button
117ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        onView(withId(R.id.text_input_password_toggle)).perform(click());
118ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
119ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // And assert that the password is not disguised
120f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
121ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    }
122ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
123ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    @Test
124ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    public void testPasswordToggleDisable() {
125ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        final Activity activity = mActivityTestRule.getActivity();
126ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        final EditText textInput = (EditText) activity.findViewById(R.id.textinput_edittext_pwd);
127ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
128ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Set some text on the EditText
1298a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext_pwd))
1308a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                .perform(typeText(INPUT_TEXT));
131ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Assert that the password is disguised
132f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
133ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
134ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Disable the password toggle
135f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        onView(withId(R.id.textinput_password))
136ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes                .perform(setPasswordVisibilityToggleEnabled(false));
137ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes
138ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        // Check that the password toggle view is not visible
139ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes        onView(withId(R.id.text_input_password_toggle)).check(matches(not(isDisplayed())));
140f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        // ...and that the password is disguised still
141f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
142f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes    }
143f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes
144f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes    @Test
145f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes    public void testPasswordToggleDisableWhenVisible() {
146f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        final Activity activity = mActivityTestRule.getActivity();
147f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        final EditText textInput = (EditText) activity.findViewById(R.id.textinput_edittext_pwd);
148f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes
1498a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Type some text on the EditText
1508a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext_pwd)).perform(typeText(INPUT_TEXT));
151f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        // Assert that the password is disguised
152f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
153f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes
154f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        // Now click the toggle button
155f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        onView(withId(R.id.text_input_password_toggle)).perform(click());
156f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        // Disable the password toggle
157f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        onView(withId(R.id.textinput_password))
158f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes                .perform(setPasswordVisibilityToggleEnabled(false));
159f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes
160f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        // Check that the password is disguised again
161f660f826c9f2607ccdb8729ca9026015df0d654bChris Banes        assertNotEquals(INPUT_TEXT, textInput.getLayout().getText().toString());
162ddf46923b9487ac3a021f01b55d96136d811e8beChris Banes    }
1638a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
1648a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    @Test
16546c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes    public void testPasswordToggleMaintainsCompoundDrawables() {
16646c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        // Set a known set of test compound drawables on the EditText
16746c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        final Drawable start = new ColorDrawable(Color.RED);
16846c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        final Drawable top = new ColorDrawable(Color.GREEN);
16946c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        final Drawable end = new ColorDrawable(Color.BLUE);
17046c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        final Drawable bottom = new ColorDrawable(Color.BLACK);
17146c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        onView(withId(R.id.textinput_edittext_pwd))
17246c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .perform(setCompoundDrawablesRelative(start, top, end, bottom));
17346c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes
17446c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        // Enable the password toggle and check that the start, top and bottom drawables are
17546c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        // maintained
17646c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        onView(withId(R.id.textinput_password))
17746c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .perform(setPasswordVisibilityToggleEnabled(true));
17846c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        onView(withId(R.id.textinput_edittext_pwd))
17946c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(0, start)))
18046c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(1, top)))
18146c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(not(withCompoundDrawable(2, end))))
18246c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(3, bottom)));
18346c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes
18446c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        // Now disable the password toggle and check that all of the original compound drawables
18546c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        // are set
18646c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        onView(withId(R.id.textinput_password))
18746c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .perform(setPasswordVisibilityToggleEnabled(false));
18846c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes        onView(withId(R.id.textinput_edittext_pwd))
18946c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(0, start)))
19046c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(1, top)))
19146c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(2, end)))
19246c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes                .check(matches(withCompoundDrawable(3, bottom)));
19346c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes    }
19446c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes
19546c7710bb85caf75eb26940d82ece7797f1fc8d7Chris Banes    @Test
1968a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    public void testSetEnabledFalse() {
1978a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // First click on the EditText, so that it is focused and the hint collapses...
1988a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext)).perform(click());
1998a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
2008a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Now disable the TextInputLayout and check that the hint expands
2018a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput))
2028a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                .perform(setEnabled(false))
2038a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                .check(isHintExpanded(true));
2048a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
2058a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Finally check that the EditText is no longer enabled
2068a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext)).check(matches(not(isEnabled())));
2078a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    }
2088a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
2098a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    @Test
2108a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    public void testSetEnabledFalseWithText() {
2118a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // First set some text, then disable the TextInputLayout
2128a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext))
2138a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                .perform(typeText(INPUT_TEXT));
2148a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput)).perform(setEnabled(false));
2158a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
2168a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        // Now check that the EditText is no longer enabled
2178a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        onView(withId(R.id.textinput_edittext)).check(matches(not(isEnabled())));
2188a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    }
2198a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes
2201ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette    /**
2211ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette     * Regression test for b/31663756.
2221ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette     */
2231ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette    @UiThreadTest
2241ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette    @Test
2251ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette    public void testDrawableStateChanged() {
2261ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette        final Activity activity = mActivityTestRule.getActivity();
2271ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette        final TextInputLayout layout = (TextInputLayout) activity.findViewById(R.id.textinput);
2281ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette
2291ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette        // Force a drawable state change.
2301ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette        layout.drawableStateChanged();
2311ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette    }
2321ad6282d03b18ea53c1fe06c687751354cdafa75Alan Viverette
2338a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    static ViewAssertion isHintExpanded(final boolean expanded) {
2348a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        return new ViewAssertion() {
2358a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes            @Override
2368a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes            public void check(View view, NoMatchingViewException noViewFoundException) {
2378a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                assertTrue(view instanceof TextInputLayout);
2388a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes                assertEquals(expanded, ((TextInputLayout) view).isHintExpanded());
2398a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes            }
2408a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes        };
2418a40d691aa783c2e85298e895a3e51e98606aa85Chris Banes    }
2429ba4dbeb02db9c222f39f77b9a335d9deabde98fChris Banes}
243