• 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 package com.android.settings.fingerprint;
17 
18 import static android.support.test.InstrumentationRegistry.getTargetContext;
19 import static android.support.test.espresso.Espresso.onView;
20 import static android.support.test.espresso.action.ViewActions.click;
21 import static android.support.test.espresso.intent.Intents.intended;
22 import static android.support.test.espresso.intent.Intents.intending;
23 import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
24 import static android.support.test.espresso.matcher.ViewMatchers.withId;
25 
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
28 
29 import android.app.Activity;
30 import android.app.Instrumentation.ActivityResult;
31 import android.content.ComponentName;
32 import android.support.test.espresso.intent.rule.IntentsTestRule;
33 import android.support.test.filters.SmallTest;
34 import android.support.test.runner.AndroidJUnit4;
35 
36 import com.android.settings.R;
37 
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 
42 @RunWith(AndroidJUnit4.class)
43 @SmallTest
44 public class FingerprintEnrollFinishTest {
45 
46     @Rule
47     public IntentsTestRule<FingerprintEnrollFinish> mActivityRule =
48             new IntentsTestRule<>(FingerprintEnrollFinish.class);
49 
50     @Test
clickAddAnother_shouldLaunchEnrolling()51     public void clickAddAnother_shouldLaunchEnrolling() {
52         final ComponentName enrollingComponent = new ComponentName(
53                 getTargetContext(),
54                 FingerprintEnrollEnrolling.class);
55 
56         intending(hasComponent(enrollingComponent))
57                 .respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
58 
59         onView(withId(R.id.add_another_button)).perform(click());
60 
61         intended(hasComponent(enrollingComponent));
62         assertFalse(mActivityRule.getActivity().isFinishing());
63     }
64 
65     @Test
clickAddAnother_shouldPropagateResults()66     public void clickAddAnother_shouldPropagateResults() {
67         final ComponentName enrollingComponent = new ComponentName(
68                 getTargetContext(),
69                 FingerprintEnrollEnrolling.class);
70 
71         intending(hasComponent(enrollingComponent))
72                 .respondWith(new ActivityResult(Activity.RESULT_OK, null));
73 
74         onView(withId(R.id.add_another_button)).perform(click());
75 
76         intended(hasComponent(enrollingComponent));
77         assertTrue(mActivityRule.getActivity().isFinishing());
78     }
79 
80     @Test
clickNext_shouldFinish()81     public void clickNext_shouldFinish() {
82         onView(withId(R.id.next_button)).perform(click());
83         assertTrue(mActivityRule.getActivity().isFinishing());
84     }
85 }