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 com.android.settings.password; 18 19import static android.support.test.espresso.Espresso.onView; 20import static android.support.test.espresso.action.ViewActions.click; 21import static android.support.test.espresso.action.ViewActions.pressKey; 22import static android.support.test.espresso.assertion.ViewAssertions.matches; 23import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 24import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; 25import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; 26import static android.support.test.espresso.matcher.ViewMatchers.withId; 27import static android.support.test.espresso.matcher.ViewMatchers.withText; 28 29import static com.google.common.truth.Truth.assertThat; 30 31import static org.hamcrest.CoreMatchers.not; 32 33import android.support.test.espresso.action.ViewActions; 34import android.support.test.espresso.matcher.ViewMatchers; 35import android.support.test.filters.MediumTest; 36import android.support.test.rule.ActivityTestRule; 37import android.support.test.runner.AndroidJUnit4; 38import android.view.KeyEvent; 39 40import com.android.settings.R; 41 42import org.junit.Rule; 43import org.junit.Test; 44import org.junit.runner.RunWith; 45 46@RunWith(AndroidJUnit4.class) 47@MediumTest 48public class SetupChooseLockPasswordAppTest { 49 50 @Rule 51 public ActivityTestRule<SetupChooseLockPassword> mActivityTestRule = 52 new ActivityTestRule<>( 53 SetupChooseLockPassword.class, 54 true /* enable touch at launch */, 55 false /* don't launch at every test */); 56 57 @Test 58 public void testSkipDialogIsShown() throws Throwable { 59 SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null); 60 61 onView(withId(R.id.cancel_button)) 62 .check(matches(withText(R.string.skip_label))) 63 .check(matches(isDisplayed())) 64 .perform(click()); 65 onView(withId(android.R.id.button1)).check(matches(isDisplayed())).perform(click()); 66 67 assertThat(activity.isFinishing()).named("Is finishing").isTrue(); 68 } 69 70 @Test 71 public void clearNotVisible_when_activityLaunchedInitially() { 72 mActivityTestRule.launchActivity(null); 73 onView(withId(R.id.clear_button)).check(matches( 74 withEffectiveVisibility(ViewMatchers.Visibility.GONE))); 75 } 76 77 @Test 78 public void clearNotEnabled_when_nothingEntered() throws Throwable { 79 mActivityTestRule.launchActivity(null); 80 onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234")) 81 .perform(pressKey(KeyEvent.KEYCODE_ENTER)); 82 onView(withId(R.id.clear_button)).check(matches(isDisplayed())) 83 .check(matches(not(isEnabled()))); 84 } 85 86 @Test 87 public void clearEnabled_when_somethingEnteredToConfirm() { 88 mActivityTestRule.launchActivity(null); 89 onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234")) 90 .perform(pressKey(KeyEvent.KEYCODE_ENTER)) 91 .perform(ViewActions.typeText("1")); 92 // clear should be present if text field contains content 93 onView(withId(R.id.clear_button)).check(matches(isDisplayed())); 94 } 95} 96