diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-10-17 00:51:18 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-10-17 00:51:18 +0000 |
commit | 6e0cb633bc159944c5fc77ea6cae76c7f1c6011e (patch) | |
tree | c0debf3cdd5ec79e9e52815500f2c04d20c69269 /tests | |
parent | 47ecbb85f3ef64669b5a56ac749afc500043e24b (diff) | |
parent | 917d434c5ce93ae86b43a3825c9cbc3541843f5e (diff) | |
download | android_packages_apps_Trebuchet-6e0cb633bc159944c5fc77ea6cae76c7f1c6011e.tar.gz android_packages_apps_Trebuchet-6e0cb633bc159944c5fc77ea6cae76c7f1c6011e.tar.bz2 android_packages_apps_Trebuchet-6e0cb633bc159944c5fc77ea6cae76c7f1c6011e.zip |
Merge "Adding tests for rotation preference Updating the gradle file to run tests directly from AndroidStudio" into ub-launcher3-burnaby-polish
am: 917d434c5c
* commit '917d434c5ce93ae86b43a3825c9cbc3541843f5e':
Adding tests for rotation preference Updating the gradle file to run tests directly from AndroidStudio
Diffstat (limited to 'tests')
-rw-r--r-- | tests/AndroidManifest.xml | 8 | ||||
-rw-r--r-- | tests/src/com/android/launcher3/InvariantDeviceProfileTest.java | 5 | ||||
-rw-r--r-- | tests/src/com/android/launcher3/RotationPreferenceTest.java | 87 |
3 files changed, 96 insertions, 4 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 42ae5a38a..8acc5e90c 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -1,4 +1,4 @@ -<?xml version="2.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2015 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,17 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" package="com.android.launcher3.tests"> + <uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/> + <application> <uses-library android:name="android.test.runner" /> </application> <instrumentation android:name="android.test.InstrumentationTestRunner" - android:targetPackage="com.android.launcher3" - android:label="Unit tests for Launcher3"> + android:targetPackage="com.android.launcher3" > </instrumentation> </manifest> diff --git a/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java b/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java index 1bc7c1190..a99ae4f95 100644 --- a/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java +++ b/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java @@ -52,9 +52,12 @@ public class InvariantDeviceProfileTest extends AndroidTestCase { public void testFindClosestDeviceProfile2() { for (InvariantDeviceProfile idf: mPredefinedDeviceProfiles) { + ArrayList<InvariantDeviceProfile> predefinedProfilesCopy = + new ArrayList<>(mPredefinedDeviceProfiles); ArrayList<InvariantDeviceProfile> closestProfiles = mInvariantProfile.findClosestDeviceProfiles( - idf.minWidthDps, idf.minHeightDps, mPredefinedDeviceProfiles); + idf.minWidthDps, idf.minHeightDps, predefinedProfilesCopy + ); assertTrue(closestProfiles.get(0).equals(idf)); } } diff --git a/tests/src/com/android/launcher3/RotationPreferenceTest.java b/tests/src/com/android/launcher3/RotationPreferenceTest.java new file mode 100644 index 000000000..5f6347557 --- /dev/null +++ b/tests/src/com/android/launcher3/RotationPreferenceTest.java @@ -0,0 +1,87 @@ +package com.android.launcher3; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Rect; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.UiDevice; +import android.support.test.uiautomator.Until; +import android.test.InstrumentationTestCase; + +/** + * Test for auto rotate preference. + */ +public class RotationPreferenceTest extends InstrumentationTestCase { + + private UiDevice mDevice; + private Context mTargetContext; + private String mTargetPackage; + + private SharedPreferences mPrefs; + private boolean mOriginalRotationValue; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mDevice = UiDevice.getInstance(getInstrumentation()); + mTargetContext = getInstrumentation().getTargetContext(); + mTargetPackage = mTargetContext.getPackageName(); + mPrefs = mTargetContext.getSharedPreferences( + LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE); + mOriginalRotationValue = mPrefs.getBoolean(Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false); + } + + @Override + protected void tearDown() throws Exception { + setRotationEnabled(mOriginalRotationValue); + super.tearDown(); + } + + public void testRotation_disabled() throws Exception { + if (mTargetContext.getResources().getBoolean(R.bool.allow_rotation)) { + // This is a tablet. The test is only valid to mobile devices. + return; + } + + setRotationEnabled(false); + mDevice.setOrientationRight(); + goToLauncher(); + + Rect hotseat = getHotseatBounds(); + assertTrue(hotseat.width() > hotseat.height()); + } + + public void testRotation_enabled() throws Exception { + if (mTargetContext.getResources().getBoolean(R.bool.allow_rotation)) { + // This is a tablet. The test is only valid to mobile devices. + return; + } + + setRotationEnabled(true); + mDevice.setOrientationRight(); + goToLauncher(); + + Rect hotseat = getHotseatBounds(); + assertTrue(hotseat.width() < hotseat.height()); + } + + private void goToLauncher() { + Intent homeIntent = new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_HOME) + .setPackage(mTargetPackage) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getInstrumentation().getContext().startActivity(homeIntent); + mDevice.wait(Until.hasObject(By.pkg(mTargetPackage).depth(0)), 3000); + } + + private void setRotationEnabled(boolean enabled) { + mPrefs.edit().putBoolean(Utilities.ALLOW_ROTATION_PREFERENCE_KEY, enabled).commit(); + } + + private Rect getHotseatBounds() { + mDevice.wait(Until.hasObject(By.res(mTargetPackage, "hotseat")), 3000); + return mDevice.findObject(By.res(mTargetPackage, "hotseat")).getVisibleBounds(); + } +} |