Add test to verify Users settings shows in secondary user.
- also update launch sequence for Users settings tests as Users settings has been moved inside system settings and the preference title has changed. - and change the test to run with AndroidJUnit4. Change-Id: I049b83f9ae4b2724608af267e8900dd9e6749874 Fixes: 34774778 Test: make SettingsUnitTests
This commit is contained in:
@@ -15,34 +15,47 @@
|
||||
*/
|
||||
package com.android.settings.users;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
import android.support.test.uiautomator.UiScrollable;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class UserSettingsTest extends InstrumentationTestCase {
|
||||
public class UserSettingsTest {
|
||||
|
||||
private static final String USER_AND_ACCOUNTS = "Users & accounts";
|
||||
private static final String USERS = "Users";
|
||||
private static final String SYSTEM = "System";
|
||||
private static final String ADVANCED = "Advanced";
|
||||
private static final String USERS = "Multiple users";
|
||||
private static final String EMERGNENCY_INFO = "Emergency information";
|
||||
private static final String ADD_USERS_WHEN_LOCKED = "Add users";
|
||||
private static final String SWITCH_USER_BUTTON = "com.android.systemui:id/multi_user_switch";
|
||||
private static final String SETTINGS_BUTTON = "com.android.systemui:id/settings_button";
|
||||
private static final String PRIMARY_USER = "Owner";
|
||||
private static final String GUEST_USER = "Guest";
|
||||
private static final String ADD_GUEST = "Add guest";
|
||||
private static final String CONTINUE = "Yes, continue";
|
||||
|
||||
private UiDevice mDevice;
|
||||
private Context mContext;
|
||||
private String mTargetPackage;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mDevice = UiDevice.getInstance(getInstrumentation());
|
||||
mContext = getInstrumentation().getTargetContext();
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
mTargetPackage = mContext.getPackageName();
|
||||
}
|
||||
|
||||
@@ -51,7 +64,8 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
||||
launchUserSettings();
|
||||
UiObject emergencyInfoPreference =
|
||||
mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
|
||||
assertFalse(emergencyInfoPreference.exists());
|
||||
|
||||
assertThat(emergencyInfoPreference.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +73,32 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
||||
launchUserSettings();
|
||||
UiObject addUsersPreference =
|
||||
mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
|
||||
assertFalse(addUsersPreference.exists());
|
||||
assertThat(addUsersPreference.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsersExistsOnSecondaryUser() throws Exception {
|
||||
// switch to guest user
|
||||
switchToOrCreateGuest();
|
||||
// launch settings (launch from intent doesn't work, hence launch from quick settings)
|
||||
mDevice.openQuickSettings();
|
||||
mDevice.findObject(new UiSelector().resourceId(SETTINGS_BUTTON)).click();
|
||||
// launch system settings and expand whole screen
|
||||
final UiScrollable settings = new UiScrollable(
|
||||
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
||||
final String titleSystem = SYSTEM;
|
||||
settings.scrollTextIntoView(titleSystem);
|
||||
mDevice.findObject(new UiSelector().text(titleSystem)).click();
|
||||
mDevice.findObject(new UiSelector().text(ADVANCED)).click();
|
||||
|
||||
final boolean hasUsersSettings = mDevice.findObject(new UiSelector().text(USERS)).exists();
|
||||
|
||||
// switch back to primary user
|
||||
mDevice.openQuickSettings();
|
||||
mDevice.findObject(new UiSelector().resourceId(SWITCH_USER_BUTTON)).click();
|
||||
mDevice.findObject(new UiSelector().text(PRIMARY_USER)).click();
|
||||
|
||||
assertThat(hasUsersSettings).isTrue();
|
||||
}
|
||||
|
||||
private void launchSettings() {
|
||||
@@ -67,17 +106,34 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
.setPackage(mTargetPackage)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
getInstrumentation().getContext().startActivity(settingsIntent);
|
||||
mContext.startActivity(settingsIntent);
|
||||
}
|
||||
|
||||
private void launchUserSettings() throws Exception {
|
||||
launchSettings();
|
||||
final UiScrollable settings = new UiScrollable(
|
||||
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
||||
final String titleUsersAndAccounts = USER_AND_ACCOUNTS;
|
||||
settings.scrollTextIntoView(titleUsersAndAccounts);
|
||||
mDevice.findObject(new UiSelector().text(titleUsersAndAccounts)).click();
|
||||
final String titleSystem = SYSTEM;
|
||||
settings.scrollTextIntoView(titleSystem);
|
||||
mDevice.findObject(new UiSelector().text(titleSystem)).click();
|
||||
mDevice.findObject(new UiSelector().text(ADVANCED)).click();
|
||||
mDevice.findObject(new UiSelector().text(USERS)).click();
|
||||
}
|
||||
|
||||
private void switchToOrCreateGuest() throws UiObjectNotFoundException {
|
||||
mDevice.openQuickSettings();
|
||||
mDevice.findObject(new UiSelector().resourceId(SWITCH_USER_BUTTON)).click();
|
||||
// if no existing guest user, select "Add guest", otherwise select "Guest"
|
||||
final UiObject addGuest = mDevice.findObject(new UiSelector().text(ADD_GUEST));
|
||||
if (addGuest.exists()) {
|
||||
addGuest.click();
|
||||
mDevice.waitForIdle();
|
||||
mDevice.pressBack();
|
||||
} else {
|
||||
mDevice.findObject(new UiSelector().text(GUEST_USER)).click();
|
||||
mDevice.waitForIdle();
|
||||
mDevice.findObject(new UiSelector().text(CONTINUE)).click();
|
||||
mDevice.waitForIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user