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;
|
package com.android.settings.users;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.support.test.filters.SmallTest;
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import android.support.test.uiautomator.UiDevice;
|
import android.support.test.uiautomator.UiDevice;
|
||||||
import android.support.test.uiautomator.UiObject;
|
import android.support.test.uiautomator.UiObject;
|
||||||
import android.support.test.uiautomator.UiSelector;
|
import android.support.test.uiautomator.UiSelector;
|
||||||
import android.support.test.uiautomator.UiScrollable;
|
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.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class UserSettingsTest extends InstrumentationTestCase {
|
public class UserSettingsTest {
|
||||||
|
|
||||||
private static final String USER_AND_ACCOUNTS = "Users & accounts";
|
private static final String SYSTEM = "System";
|
||||||
private static final String USERS = "Users";
|
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 EMERGNENCY_INFO = "Emergency information";
|
||||||
private static final String ADD_USERS_WHEN_LOCKED = "Add users";
|
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 UiDevice mDevice;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private String mTargetPackage;
|
private String mTargetPackage;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() {
|
||||||
super.setUp();
|
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||||
mDevice = UiDevice.getInstance(getInstrumentation());
|
mContext = InstrumentationRegistry.getTargetContext();
|
||||||
mContext = getInstrumentation().getTargetContext();
|
|
||||||
mTargetPackage = mContext.getPackageName();
|
mTargetPackage = mContext.getPackageName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +64,8 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
|||||||
launchUserSettings();
|
launchUserSettings();
|
||||||
UiObject emergencyInfoPreference =
|
UiObject emergencyInfoPreference =
|
||||||
mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
|
mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
|
||||||
assertFalse(emergencyInfoPreference.exists());
|
|
||||||
|
assertThat(emergencyInfoPreference.exists()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -59,7 +73,32 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
|||||||
launchUserSettings();
|
launchUserSettings();
|
||||||
UiObject addUsersPreference =
|
UiObject addUsersPreference =
|
||||||
mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
|
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() {
|
private void launchSettings() {
|
||||||
@@ -67,17 +106,34 @@ public class UserSettingsTest extends InstrumentationTestCase {
|
|||||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
.setPackage(mTargetPackage)
|
.setPackage(mTargetPackage)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
getInstrumentation().getContext().startActivity(settingsIntent);
|
mContext.startActivity(settingsIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchUserSettings() throws Exception {
|
private void launchUserSettings() throws Exception {
|
||||||
launchSettings();
|
launchSettings();
|
||||||
final UiScrollable settings = new UiScrollable(
|
final UiScrollable settings = new UiScrollable(
|
||||||
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
||||||
final String titleUsersAndAccounts = USER_AND_ACCOUNTS;
|
final String titleSystem = SYSTEM;
|
||||||
settings.scrollTextIntoView(titleUsersAndAccounts);
|
settings.scrollTextIntoView(titleSystem);
|
||||||
mDevice.findObject(new UiSelector().text(titleUsersAndAccounts)).click();
|
mDevice.findObject(new UiSelector().text(titleSystem)).click();
|
||||||
|
mDevice.findObject(new UiSelector().text(ADVANCED)).click();
|
||||||
mDevice.findObject(new UiSelector().text(USERS)).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