summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPallavi Angampally <pallavi@google.com>2017-03-29 17:36:58 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-29 17:36:58 +0000
commitdca103ca598b3b84859851dd377b80288367108f (patch)
tree918ed33164f45d55c62431d36e5f645a36f6d4bf
parent6d813b9c64fe8ae62cd690a1d9f5bfda3f827866 (diff)
parent757f81789d82e606493648467ef817f8abdb14d3 (diff)
downloadadt-infra-dca103ca598b3b84859851dd377b80288367108f.tar.gz
Merge "Test: Functionality of "Reset app preferences"" am: c9564922ed
am: 757f81789d Change-Id: I6a0b27af46a4fec5f9431397c8fefeb68513d3b3
-rw-r--r--system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java
index ac9adb71..04b8aa5e 100644
--- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java
+++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java
@@ -20,6 +20,7 @@ import com.android.devtools.systemimage.uitest.annotations.TestInfo;
import com.android.devtools.systemimage.uitest.common.Res;
import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework;
import com.android.devtools.systemimage.uitest.utils.AppLauncher;
+import com.android.devtools.systemimage.uitest.utils.AppManager;
import com.android.devtools.systemimage.uitest.utils.DeveloperOptionsManager;
import com.android.devtools.systemimage.uitest.utils.SettingsUtil;
import com.android.devtools.systemimage.uitest.utils.UiAutomatorPlus;
@@ -45,6 +46,9 @@ import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
+import android.widget.LinearLayout;
+import android.widget.Switch;
+import android.widget.TextView;
/**
* Test class for Android Settings page on Google API images.
@@ -794,4 +798,152 @@ public class SettingsTest {
gotoCameraApp();
Assert.assertTrue(verifyCameraAppDisabled());
}
+
+ /**
+ * To verify that "Reset app preferences" restores permission restrictions.
+ * <p>
+ * This is run to qualify releases. Please involve the test team in substantial changes.
+ * <p>
+ * TR ID: C14578841
+ * <p>
+ * <pre>
+ * Test Steps:
+ * 1. Launch an emulator avd with wipe data.
+ * 2. Open Settings > Apps.
+ * 3. Open the menu (3 vertical dots) and tap on "Show System".
+ * 4. Tap on any app, say Maps and select "Permissions".
+ * 5. Enable all available permissions for the app.
+ * 6. Press back button.
+ * 7. Open the menu > Reset app preferences > Reset apps.
+ * Verify:
+ * 1. App settings for Maps are reset to default (Verify that Permissions and notification
+ * settings for Maps are cleared).
+ * </pre>
+ */
+ @Test
+ @TestInfo(id = "C14578841")
+ public void modifyAndResetAppPermissions() throws Exception {
+
+ Instrumentation instrumentation = testFramework.getInstrumentation();
+ UiDevice device = testFramework.getDevice();
+
+ String appName = "Maps";
+ String contactsText = "Contacts";
+ String locationText = "Location";
+ String phoneText = "Phone";
+ String storageText = "Storage";
+
+ // Variables to store the state of permissions.
+ boolean contactsSwitchState;
+ boolean locationSwitchState;
+ boolean phoneSwitchState;
+ boolean storageSwitchState;
+
+ //Check for Deny alert dialog button for location permissions.
+ UiObject denyButton;
+
+ if(testFramework.getApi() < 23){
+ return;
+ }
+
+ //Open System apps list.
+ AppManager.openSystemAppList(instrumentation);
+
+ // Find and click "Maps" in apps list.
+ UiScrollable itemList =
+ new UiScrollable(
+ new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)
+ );
+ itemList.setAsVerticalList();
+
+ itemList.scrollIntoView(new UiSelector().text(appName));
+ itemList.getChildByText(new UiSelector().className(TextView.class.getName()), appName)
+ .clickAndWaitForNewWindow();
+
+ //Get application info list.
+ UiScrollable appInfoList =
+ new UiScrollable(
+ new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)
+ );
+
+ //Choose permissions to edit them.
+ appInfoList.getChildByText(new UiSelector().
+ className(TextView.class.getName()),"Permissions").clickAndWaitForNewWindow();
+
+ UiScrollable permissionList;
+ if(testFramework.getApi() > 23 ){
+ permissionList =
+ new UiScrollable(
+ new UiSelector().resourceIdMatches(Res.ANDROID_LIST_RES)
+ );
+ } else {
+ permissionList =
+ new UiScrollable(
+ new UiSelector().
+ resourceIdMatches("com.android.packageinstaller:id/list")
+ );
+ }
+
+ //Get switch widgets UiObjects.
+ UiObject contactSwitch =
+ findObjectByRelative(permissionList,contactsText,LinearLayout.class.getName());
+ UiObject locationSwitch =
+ findObjectByRelative(permissionList,locationText,LinearLayout.class.getName());
+ UiObject phoneSwitch =
+ findObjectByRelative(permissionList,phoneText,LinearLayout.class.getName());
+ UiObject storageSwitch =
+ findObjectByRelative(permissionList,storageText,LinearLayout.class.getName());
+
+ //Store current permissions state of switch widgets.
+ contactsSwitchState = contactSwitch.isChecked();
+ locationSwitchState = locationSwitch.isChecked();
+ phoneSwitchState = phoneSwitch.isChecked();
+ storageSwitchState = storageSwitch.isChecked();
+
+ //Modify application permission.
+ contactSwitch.click();
+ phoneSwitch.click();
+ storageSwitch.click();
+ locationSwitch.clickAndWaitForNewWindow();
+
+ device.findObject(new UiSelector().textStartsWith("Deny")).clickAndWaitForNewWindow();
+
+ //Go back two times to go to system apps page to reset permissions.
+ device.pressBack();
+ device.pressBack();
+
+ //Reset app preferences from overflow menu.
+ device.pressMenu();
+ device.findObject(
+ new UiSelector().textContains("Reset app preferences")).clickAndWaitForNewWindow();
+ device.findObject(new UiSelector().textContains("RESET APPS")).clickAndWaitForNewWindow();
+
+ //Open Maps info.
+ itemList.scrollIntoView(new UiSelector().text(appName));
+ itemList.getChildByText(new UiSelector().className(TextView.class.getName()), appName)
+ .clickAndWaitForNewWindow();
+
+ //Open permission and verify Contacts,Location,Phone and Storage.
+ //Verify that all the permission for the app are reset.
+ appInfoList.getChildByText(new UiSelector().
+ className(TextView.class.getName()),"Permissions").clickAndWaitForNewWindow();
+
+ assertEquals(contactsSwitchState,
+ findObjectByRelative(
+ permissionList,"Contacts",LinearLayout.class.getName()).isChecked());
+ assertEquals(locationSwitchState,
+ findObjectByRelative(
+ permissionList,"Location",LinearLayout.class.getName()).isChecked());
+ assertEquals(phoneSwitchState,
+ findObjectByRelative(
+ permissionList,"Phone",LinearLayout.class.getName()).isChecked());
+ assertEquals(storageSwitchState,
+ findObjectByRelative(
+ permissionList,"Storage",LinearLayout.class.getName()).isChecked());
+ }
+
+ private UiObject findObjectByRelative(UiScrollable verticalList, String childText, String classType) throws Exception{
+ UiObject uiObject = verticalList.getChildByText(new UiSelector().className(classType),childText);
+ return uiObject.getChild(new UiSelector().className(Switch.class.getName()));
+ }
}