Move tests from tests/app/ to tests/unit/

- first round: move tests that currently pass

Bug: 62103184
Test: make SettingsUnitTests
Change-Id: Ief3adf88e5090621e5ec3957a71d1b56b4be186a
This commit is contained in:
Doris Ling
2017-08-09 15:52:26 -07:00
parent b5a5cc251a
commit 109bb5e59a
15 changed files with 25 additions and 27 deletions

View File

@@ -0,0 +1,145 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.Arrays;
import java.util.List;
/**
* Tests for {@link CreateShortcutTest}
*
m SettingsTests &&
adb install \
-r -g ${ANDROID_PRODUCT_OUT}/data/app/SettingsTests/SettingsTests.apk &&
adb shell am instrument -e class com.android.settings.CreateShortcutTest \
-w com.android.settings.tests/android.support.test.runner.AndroidJUnitRunner
*/
@RunWith(AndroidJUnit4.class)
@SmallTest
public class CreateShortcutTest {
private static final String SHORTCUT_ID_PREFIX = CreateShortcut.SHORTCUT_ID_PREFIX;
private Instrumentation mInstrumentation;
private Context mContext;
@Mock ShortcutManager mShortcutManager;
@Captor ArgumentCaptor<List<ShortcutInfo>> mListCaptor;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mContext = mInstrumentation.getTargetContext();
}
@Test
public void test_layoutDoesNotHaveCancelButton() {
mInstrumentation.startActivitySync(new Intent(Intent.ACTION_CREATE_SHORTCUT)
.setClassName(mContext, CreateShortcut.class.getName()));
onView(withText(R.string.cancel)).check(doesNotExist());
}
@Test
public void createResultIntent() {
CreateShortcut orgActivity = (CreateShortcut) mInstrumentation.startActivitySync(
new Intent(Intent.ACTION_CREATE_SHORTCUT)
.setClassName(mContext, CreateShortcut.class.getName()));
CreateShortcut activity = spy(orgActivity);
doReturn(mShortcutManager).when(activity).getSystemService(eq(Context.SHORTCUT_SERVICE));
when(mShortcutManager.createShortcutResultIntent(any(ShortcutInfo.class)))
.thenReturn(new Intent().putExtra("d1", "d2"));
Intent intent = CreateShortcut.getBaseIntent()
.setClass(activity, Settings.ManageApplicationsActivity.class);
ResolveInfo ri = activity.getPackageManager().resolveActivity(intent, 0);
Intent result = activity.createResultIntent(intent, ri, "dummy");
assertEquals("d2", result.getStringExtra("d1"));
assertNotNull(result.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT));
ArgumentCaptor<ShortcutInfo> infoCaptor = ArgumentCaptor.forClass(ShortcutInfo.class);
verify(mShortcutManager, times(1))
.createShortcutResultIntent(infoCaptor.capture());
String expectedId = SHORTCUT_ID_PREFIX + intent.getComponent().flattenToShortString();
assertEquals(expectedId, infoCaptor.getValue().getId());
}
@Test
public void shortcutsUpdateTask() {
mContext = spy(new ContextWrapper(mInstrumentation.getTargetContext()));
doReturn(mShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE));
List<ShortcutInfo> pinnedShortcuts = Arrays.asList(
makeShortcut("d1"), makeShortcut("d2"),
makeShortcut(Settings.ManageApplicationsActivity.class),
makeShortcut("d3"),
makeShortcut(Settings.SoundSettingsActivity.class));
when(mShortcutManager.getPinnedShortcuts()).thenReturn(pinnedShortcuts);
new CreateShortcut.ShortcutsUpdateTask(mContext).doInBackground();
verify(mShortcutManager, times(1)).updateShortcuts(mListCaptor.capture());
List<ShortcutInfo> updates = mListCaptor.getValue();
assertEquals(2, updates.size());
assertEquals(pinnedShortcuts.get(2).getId(), updates.get(0).getId());
assertEquals(pinnedShortcuts.get(4).getId(), updates.get(1).getId());
}
private ShortcutInfo makeShortcut(Class<?> className) {
ComponentName cn = new ComponentName(mContext, className);
return makeShortcut(SHORTCUT_ID_PREFIX + cn.flattenToShortString());
}
private ShortcutInfo makeShortcut(String id) {
return new ShortcutInfo.Builder(mContext, id).build();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import android.app.Instrumentation;
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 org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DisplaySettingsTest {
private Instrumentation mInstrumentation;
private Context mContext;
private UiDevice mDevice;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mContext = mInstrumentation.getTargetContext();
mDevice = UiDevice.getInstance(mInstrumentation);
}
@Test
public void launchBrightnessLevel_shouldNotCrash() {
mInstrumentation.startActivitySync(
new Intent(mContext, DisplaySettings.class));
onView(withText(mContext.getString(R.string.brightness))).perform(click());
// should not crash
mDevice.pressBack(); // dismiss the brightness dialog
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
import android.app.Instrumentation.ActivityResult;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class EncryptionInterstitialTest {
private Instrumentation mInstrumentation;
private Context mContext;
private TestActivityMonitor mActivityMonitor;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mContext = mInstrumentation.getTargetContext();
mActivityMonitor = new TestActivityMonitor();
mInstrumentation.addMonitor(mActivityMonitor);
}
@After
public void tearDown() {
mInstrumentation.removeMonitor(mActivityMonitor);
}
@Test
public void clickYes_shouldRequirePassword() {
mInstrumentation.startActivitySync(
new Intent(mContext, EncryptionInterstitial.class)
.putExtra("extra_unlock_method_intent", new Intent("test.unlock.intent")));
onView(withId(R.id.encrypt_require_password)).perform(click());
mActivityMonitor.waitForActivityWithTimeout(1000);
assertEquals(1, mActivityMonitor.getHits());
assertTrue(mActivityMonitor.mMatchedIntent.getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, false));
}
@Test
public void clickNo_shouldNotRequirePassword() {
mInstrumentation.startActivitySync(
new Intent(mContext, EncryptionInterstitial.class)
.putExtra("extra_unlock_method_intent", new Intent("test.unlock.intent")));
onView(withId(R.id.encrypt_dont_require_password)).perform(click());
mActivityMonitor.waitForActivityWithTimeout(1000);
assertEquals(1, mActivityMonitor.getHits());
assertFalse(mActivityMonitor.mMatchedIntent.getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true));
}
private static class TestActivityMonitor extends ActivityMonitor {
Intent mMatchedIntent = null;
@Override
public ActivityResult onStartActivity(Intent intent) {
if ("test.unlock.intent".equals(intent.getAction())) {
mMatchedIntent = intent;
return new ActivityResult(Activity.RESULT_OK, null);
}
return null;
}
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ManagedAccessSettingsLowRamTest {
private Instrumentation mInstrumentation;
private Context mTargetContext;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
}
@Test
public void testManagedAccessOptionsVisibility() throws Exception {
mInstrumentation.startActivitySync(new Intent(mTargetContext,
com.android.settings.Settings.SpecialAccessSettingsActivity.class));
String[] managedServiceLabels = new String[] {"Do Not Disturb access",
"VR helper services", "Notification access", "Picture-in-picture"};
for (String label : managedServiceLabels) {
if (ActivityManager.isLowRamDeviceStatic()) {
onView(withText(label)).check(doesNotExist());
} else {
onView(withText(label)).check(matches(isDisplayed()));
}
}
}
@Test
public void launchNotificationSetting_onlyWorksIfNotLowRam() {
final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
mInstrumentation.startActivitySync(intent);
final String label = "This feature is not available on this device";
if (ActivityManager.isLowRamDeviceStatic()) {
onView(withText(label)).check(matches(isDisplayed()));
} else {
onView(withText(label)).check(doesNotExist());
}
}
@Test
public void launchDndSetting_onlyWorksIfNotLowRam() {
final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
mInstrumentation.startActivitySync(intent);
final String label = "This feature is not available on this device";
if (ActivityManager.isLowRamDeviceStatic()) {
onView(withText(label)).check(matches(isDisplayed()));
} else {
onView(withText(label)).check(doesNotExist());
}
}
@Test
public void launchVrSetting_onlyWorksIfNotLowRam() {
final Intent intent = new Intent(Settings.ACTION_VR_LISTENER_SETTINGS);
mInstrumentation.startActivitySync(intent);
final String label = "This feature is not available on this device";
if (ActivityManager.isLowRamDeviceStatic()) {
onView(withText(label)).check(matches(isDisplayed()));
} else {
onView(withText(label)).check(doesNotExist());
}
}
@Test
public void launchPictureInPictureSetting_onlyWorksIfNotLowRam() {
final Intent intent = new Intent(Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS);
mInstrumentation.startActivitySync(intent);
final String label = "This feature is not available on this device";
if (ActivityManager.isLowRamDeviceStatic()) {
onView(withText(label)).check(matches(isDisplayed()));
} else {
onView(withText(label)).check(doesNotExist());
}
}
}

View File

@@ -0,0 +1,70 @@
package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroupAdapter;
import com.android.settings.accessibility.AccessibilitySettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class SettingsPreferenceFragmentTest {
private Instrumentation mInstrumentation;
private Context mTargetContext;
@Before
public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
}
@Test
public void testHighlightCaptions() throws InterruptedException {
final String prefKey = "captioning_preference_screen";
Bundle args = new Bundle();
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, prefKey);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(mTargetContext, SubSettings.class);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT,
"com.android.settings.accessibility.AccessibilitySettings");
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
AccessibilitySettings fragment = (AccessibilitySettings)
activity.getFragmentManager().getFragments().get(0);
// Allow time for highlight from post-delay.
Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
if (!fragment.mPreferenceHighlighted) {
Thread.sleep(SettingsPreferenceFragment.DELAY_HIGHLIGHT_DURATION_MILLIS);
}
int prefPosition = -1;
PreferenceGroupAdapter adapter = (PreferenceGroupAdapter)
fragment.getListView().getAdapter();
for (int n = 0, count = adapter.getItemCount(); n < count; n++) {
final Preference preference = adapter.getItem(n);
final String preferenceKey = preference.getKey();
if (preferenceKey.equals(prefKey)) {
prefPosition = n;
break;
}
}
assertThat(fragment.mAdapter.initialHighlightedPosition).isEqualTo(prefPosition);
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PackageUtilTest {
private static final String ALL_USERS_APP_NAME = "com.google.allusers.app";
private static final String ONE_USER_APP_NAME = "com.google.oneuser.app";
private static final int USER1_ID = 1;
private static final int USER2_ID = 11;
@Mock
private PackageManager mMockPackageManager;
@Mock
private UserManager mMockUserManager;
private InstalledAppDetails.PackageUtil mPackageUtil;
private List<UserInfo> mUserInfos;
@Before
public void setUp() throws PackageManager.NameNotFoundException {
MockitoAnnotations.initMocks(this);
mUserInfos = new ArrayList<>();
mUserInfos.add(new UserInfo(USER1_ID, "lei", 0));
mUserInfos.add(new UserInfo(USER2_ID, "yue", 0));
when(mMockUserManager.getUsers(true)).thenReturn(mUserInfos);
ApplicationInfo usersApp = new ApplicationInfo();
usersApp.flags = ApplicationInfo.FLAG_INSTALLED;
when(mMockPackageManager.getApplicationInfoAsUser(
ALL_USERS_APP_NAME, PackageManager.GET_META_DATA, USER1_ID))
.thenReturn(usersApp);
when(mMockPackageManager.getApplicationInfoAsUser(
ALL_USERS_APP_NAME, PackageManager.GET_META_DATA, USER2_ID))
.thenReturn(usersApp);
when(mMockPackageManager.getApplicationInfoAsUser(
ONE_USER_APP_NAME, PackageManager.GET_META_DATA, USER1_ID))
.thenReturn(usersApp);
when(mMockPackageManager.getApplicationInfoAsUser(
ONE_USER_APP_NAME, PackageManager.GET_META_DATA, USER2_ID))
.thenThrow(new PackageManager.NameNotFoundException());
mPackageUtil = new InstalledAppDetails.PackageUtil();
}
@Test
public void testCountPackageInUsers_twoUsersInstalled_returnTwo() {
assertEquals(2, mPackageUtil.countPackageInUsers(
mMockPackageManager, mMockUserManager, ALL_USERS_APP_NAME));
}
@Test
public void testCountPackageInUsers_oneUsersInstalled_returnOne() {
assertEquals(1, mPackageUtil.countPackageInUsers(
mMockPackageManager, mMockUserManager, ONE_USER_APP_NAME));
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import static org.mockito.Mockito.when;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import com.android.settings.SettingsActivity;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class BluetoothDeviceDetailsRotationTest {
private Context mContext;
private UiDevice mUiDevice;
private Instrumentation mInstrumentation;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private CachedBluetoothDevice mCachedDevice;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocalBluetoothManager mBluetoothManager;
private String mDeviceAddress;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mContext = InstrumentationRegistry.getTargetContext();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mDeviceAddress = "AA:BB:CC:DD:EE:FF";
when(mCachedDevice.getAddress()).thenReturn(mDeviceAddress);
when(mCachedDevice.getName()).thenReturn("Mock Device");
BluetoothDeviceDetailsFragment.sTestDataFactory =
new BluetoothDeviceDetailsFragment.TestDataFactory() {
@Override
public CachedBluetoothDevice getDevice(String deviceAddress) {
return mCachedDevice;
}
@Override
public LocalBluetoothManager getManager(Context context) {
return mBluetoothManager;
}
};
}
@Test
public void rotation() {
Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS");
SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
Bundle args = new Bundle(1);
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, mDeviceAddress);
activity.startPreferencePanel(null, BluetoothDeviceDetailsFragment.class.getName(), args,
0, null, null, 0);
try {
mUiDevice.setOrientationLeft();
mUiDevice.setOrientationNatural();
mUiDevice.setOrientationRight();
mUiDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DevicePickerActivityTest {
private Instrumentation mInstrumentation;
@Before
public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
}
@Test
public void startActivityNoCrash() {
mInstrumentation.startActivitySync(
new Intent("android.bluetooth.devicepicker.action.LAUNCH"));
// No crash
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fingerprint;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.app.Instrumentation.ActivityResult;
import android.content.ComponentName;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.settings.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class FingerprintEnrollFinishTest {
@Rule
public IntentsTestRule<FingerprintEnrollFinish> mActivityRule =
new IntentsTestRule<>(FingerprintEnrollFinish.class);
@Test
public void clickAddAnother_shouldLaunchEnrolling() {
final ComponentName enrollingComponent = new ComponentName(
getTargetContext(),
FingerprintEnrollEnrolling.class);
intending(hasComponent(enrollingComponent))
.respondWith(new ActivityResult(Activity.RESULT_CANCELED, null));
onView(withId(R.id.add_another_button)).perform(click());
intended(hasComponent(enrollingComponent));
assertFalse(mActivityRule.getActivity().isFinishing());
}
@Test
public void clickAddAnother_shouldPropagateResults() {
final ComponentName enrollingComponent = new ComponentName(
getTargetContext(),
FingerprintEnrollEnrolling.class);
intending(hasComponent(enrollingComponent))
.respondWith(new ActivityResult(Activity.RESULT_OK, null));
onView(withId(R.id.add_another_button)).perform(click());
intended(hasComponent(enrollingComponent));
assertTrue(mActivityRule.getActivity().isFinishing());
}
@Test
public void clickNext_shouldFinish() {
onView(withId(R.id.next_button)).perform(click());
assertTrue(mActivityRule.getActivity().isFinishing());
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.allOf;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppNotificationSettingsTest {
private Context mTargetContext;
private Instrumentation mInstrumentation;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
}
@Test
public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
mInstrumentation.startActivitySync(intent);
onView(allOf(withId(android.R.id.button1),
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.check(doesNotExist());
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.search;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.core.AllOf.allOf;
import android.support.test.filters.SmallTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.SearchView;
import com.android.settings.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class SearchFragmentEspressoTest {
@Rule
public ActivityTestRule<SearchActivity> mActivityRule =
new ActivityTestRule<>(SearchActivity.class, true, true);
@Test
public void test_OpenKeyboardOnSearchLaunch() {
onView(allOf(hasFocus(), withId(R.id.search_view)))
.check(matches(withClassName(containsString(SearchView.class.getName()))));
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.tests;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PrivateVolumeSettingsTest {
@Test
public void test_ManageStorageNotShown() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.startActivitySync(
new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS));
onView(withText(com.android.settings.R.string.storage_menu_manage)).check(doesNotExist());
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.tests;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class SettingsRestoreAfterCloseTest {
private static final String PACKAGE_SETTINGS = "com.android.settings";
private static final int TIME_OUT = 2000;
private boolean mAlwaysFinish;
@Before
public void setUp() throws Exception {
// To make sure when we press home button, the activity will be destroyed by OS
Context context = InstrumentationRegistry.getContext();
mAlwaysFinish = Settings.Global.getInt(
context.getContentResolver(), Settings.Global
.ALWAYS_FINISH_ACTIVITIES, 0)
!= 0;
ActivityManager.getService().setAlwaysFinish(true);
}
@After
public void tearDown() throws Exception {
ActivityManager.getService().setAlwaysFinish(mAlwaysFinish);
}
@Test
public void testRtlStability_AppCloseAndReOpen_shouldNotCrash() throws Exception {
final UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation
());
uiDevice.pressHome();
// Open the settings app
startSettingsMainActivity(uiDevice);
// Press home button
uiDevice.pressHome();
final String launcherPackage = uiDevice.getLauncherPackageName();
uiDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), TIME_OUT);
// Open the settings again
startSettingsMainActivity(uiDevice);
}
private void startSettingsMainActivity(UiDevice uiDevice) {
Context context = InstrumentationRegistry.getContext();
context.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
uiDevice.wait(Until.hasObject(By.pkg(PACKAGE_SETTINGS).depth(0)), TIME_OUT);
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.users;
import android.content.Context;
import android.content.Intent;
import android.support.test.filters.SmallTest;
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 org.junit.Test;
@SmallTest
public class UserSettingsTest extends InstrumentationTestCase {
private static final String USER_AND_ACCOUNTS = "Users & accounts";
private static final String USERS = "Users";
private static final String EMERGNENCY_INFO = "Emergency information";
private static final String ADD_USERS_WHEN_LOCKED = "Add users";
private UiDevice mDevice;
private Context mContext;
private String mTargetPackage;
@Override
protected void setUp() throws Exception {
super.setUp();
mDevice = UiDevice.getInstance(getInstrumentation());
mContext = getInstrumentation().getTargetContext();
mTargetPackage = mContext.getPackageName();
}
@Test
public void testEmergencyInfoNotExists() throws Exception {
launchUserSettings();
UiObject emergencyInfoPreference =
mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
assertFalse(emergencyInfoPreference.exists());
}
@Test
public void testAddUsersWhenLockedNotExists() throws Exception {
launchUserSettings();
UiObject addUsersPreference =
mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
assertFalse(addUsersPreference.exists());
}
private void launchSettings() {
Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setPackage(mTargetPackage)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().getContext().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();
mDevice.findObject(new UiSelector().text(USERS)).click();
}
}