• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings;
18 
19 import static android.support.test.espresso.Espresso.onView;
20 import static android.support.test.espresso.action.ViewActions.pressKey;
21 import static android.support.test.espresso.action.ViewActions.typeText;
22 import static android.support.test.espresso.assertion.ViewAssertions.matches;
23 import static android.support.test.espresso.matcher.ViewMatchers.withId;
24 import static android.support.test.espresso.matcher.ViewMatchers.withText;
25 
26 import android.app.Instrumentation;
27 import android.content.Context;
28 import android.content.Intent;
29 import android.support.test.InstrumentationRegistry;
30 import android.support.test.runner.AndroidJUnit4;
31 import android.view.KeyEvent;
32 
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 @RunWith(AndroidJUnit4.class)
38 public class ConfirmLockPasswordTest {
39 
40     private Instrumentation mInstrumentation;
41     private Context mContext;
42 
43     @Before
setUp()44     public void setUp() {
45         mInstrumentation = InstrumentationRegistry.getInstrumentation();
46         mContext = mInstrumentation.getTargetContext();
47     }
48 
49     @Test
enterWrongPin_shouldShowErrorMessage()50     public void enterWrongPin_shouldShowErrorMessage() {
51         mInstrumentation.startActivitySync(
52                 new Intent(mContext, ConfirmLockPassword.class));
53         onView(withId(R.id.password_entry)).perform(typeText("1234"))
54                 .perform(pressKey(KeyEvent.KEYCODE_ENTER));
55         onView(withId(R.id.errorText)).check(matches(withText(R.string.lockpassword_invalid_pin)));
56     }
57 
58     @Test
enterWrongPin_darkTheme_shouldShowErrorMessage()59     public void enterWrongPin_darkTheme_shouldShowErrorMessage() {
60         mInstrumentation.startActivitySync(
61                 new Intent(mContext, ConfirmLockPassword.class)
62                         .putExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, true));
63         onView(withId(R.id.password_entry)).perform(typeText("1234"))
64                 .perform(pressKey(KeyEvent.KEYCODE_ENTER));
65         onView(withId(R.id.errorText)).check(matches(withText(R.string.lockpassword_invalid_pin)));
66     }
67 }
68