1 /*
2  * Copyright (C) 2016 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.users;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.support.test.filters.SmallTest;
21 import android.support.test.uiautomator.UiDevice;
22 import android.support.test.uiautomator.UiObject;
23 import android.support.test.uiautomator.UiSelector;
24 import android.support.test.uiautomator.UiScrollable;
25 import android.test.InstrumentationTestCase;
26 
27 import com.android.settings.R;
28 
29 import org.junit.Test;
30 
31 @SmallTest
32 public class UserSettingsTest extends InstrumentationTestCase {
33 
34     private static final String USER_AND_ACCOUNTS = "User & accounts";
35     private static final String USERS = "Users";
36     private static final String EMERGNENCY_INFO = "Emergency information";
37     private static final String ADD_USERS_WHEN_LOCKED = "Add users";
38 
39     private UiDevice mDevice;
40     private Context mContext;
41     private String mTargetPackage;
42 
43     @Override
setUp()44     protected void setUp() throws Exception {
45         super.setUp();
46         mDevice = UiDevice.getInstance(getInstrumentation());
47         mContext = getInstrumentation().getTargetContext();
48         mTargetPackage = mContext.getPackageName();
49     }
50 
51     @Test
testEmergencyInfoNotExists()52     public void testEmergencyInfoNotExists() throws Exception {
53         launchUserSettings();
54         UiObject emergencyInfoPreference =
55             mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
56         assertFalse(emergencyInfoPreference.exists());
57     }
58 
59     @Test
testAddUsersWhenLockedNotExists()60     public void testAddUsersWhenLockedNotExists() throws Exception {
61         launchUserSettings();
62         UiObject addUsersPreference =
63             mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
64         assertFalse(addUsersPreference.exists());
65     }
66 
launchSettings()67     private void launchSettings() {
68         Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
69                 .addCategory(Intent.CATEGORY_LAUNCHER)
70                 .setPackage(mTargetPackage)
71                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72         getInstrumentation().getContext().startActivity(settingsIntent);
73     }
74 
launchUserSettings()75     private void launchUserSettings() throws Exception  {
76         launchSettings();
77         final UiScrollable settings = new UiScrollable(
78                 new UiSelector().packageName(mTargetPackage).scrollable(true));
79         final String titleUsersAndAccounts = USER_AND_ACCOUNTS;
80         settings.scrollTextIntoView(titleUsersAndAccounts);
81         mDevice.findObject(new UiSelector().text(titleUsersAndAccounts)).click();
82         mDevice.findObject(new UiSelector().text(USERS)).click();
83     }
84 
85 }
86