1 /*
2  * Copyright (C) 2020 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.managedprovisioning.provisioning;
18 
19 import static androidx.test.espresso.Espresso.onView;
20 import static androidx.test.espresso.action.ViewActions.click;
21 import static androidx.test.espresso.matcher.ViewMatchers.withText;
22 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
23 
24 import static com.android.managedprovisioning.model.ProvisioningParams.EXTRA_PROVISIONING_PARAMS;
25 
26 import static org.junit.Assert.assertTrue;
27 
28 import android.content.ComponentName;
29 import android.content.Intent;
30 import android.os.RemoteException;
31 
32 import androidx.test.espresso.intent.rule.IntentsTestRule;
33 import androidx.test.filters.SmallTest;
34 import androidx.test.uiautomator.UiDevice;
35 
36 import com.android.managedprovisioning.R;
37 import com.android.managedprovisioning.TestUtils;
38 import com.android.managedprovisioning.model.ProvisioningParams;
39 
40 import org.junit.Before;
41 import org.junit.Ignore;
42 import org.junit.Rule;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.junit.runners.JUnit4;
46 
47 /**
48  * Unit tests for {@link FinancedDeviceLandingActivity}
49  */
50 @SmallTest
51 @RunWith(JUnit4.class)
52 public class FinancedDeviceLandingActivityTest {
53 
54     private static final ComponentName TEST_COMPONENT_NAME =
55             new ComponentName("test", "test");
56 
57     @Rule
58     public IntentsTestRule<FinancedDeviceLandingActivity> mActivityRule =
59             new IntentsTestRule(FinancedDeviceLandingActivity.class, true, false);
60 
61     @Before
setup()62     public void setup() throws RemoteException {
63         TestUtils.wakeupDeviceAndPressHome(UiDevice.getInstance(getInstrumentation()));
64     }
65 
66     @Ignore("b/181323689")
67     @Test
onAcceptAndContinueButtonClicked()68     public void onAcceptAndContinueButtonClicked() {
69         // GIVEN the activity launched
70         ProvisioningParams params = generateProvisioningParams();
71         launchActivityWithParams(params);
72 
73         // WHEN the user clicks Next
74         onView(withText(R.string.next)).perform(click());
75 
76         // THEN the activity should finish
77         assertTrue(mActivityRule.getActivity().isFinishing());
78     }
79 
generateProvisioningParams()80     private ProvisioningParams generateProvisioningParams() {
81         return new ProvisioningParams.Builder()
82                 .setDeviceAdminComponentName(TEST_COMPONENT_NAME)
83                 .setProvisioningAction("")
84                 .build();
85     }
86 
launchActivityWithParams(ProvisioningParams params)87     private void launchActivityWithParams(ProvisioningParams params) {
88         Intent intent = new Intent();
89         intent.putExtra(EXTRA_PROVISIONING_PARAMS, params);
90         mActivityRule.launchActivity(intent);
91     }
92 }
93