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

- second round, move all remaining items
- removed SoundSettingsIntegrationTest and DashboardAdapterTest as they
are obsolete.

Fixes: 62103184
Test: make SettingsUnitTests
Change-Id: Idc2eeb285acd209ef2d00c5451fff697002e1734
This commit is contained in:
Doris Ling
2017-08-28 16:05:39 -07:00
parent 0617d139e0
commit d47606ab6d
113 changed files with 74 additions and 250 deletions

View File

@@ -0,0 +1,132 @@
/*
* Copyright (C) 2010 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 com.android.settings.Settings;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.test.ActivityInstrumentationTestCase2;
import java.util.List;
/**
* Tests for the Settings operator/manufacturer hook.
*
* Running all tests:
*
* make SettingsTests
* adb push SettingsTests.apk /system/app/SettingsTests.apk
* adb shell am instrument \
* -w com.android.settings.tests/android.test.InstrumentationTestRunner
*/
public class SettingsHookTests extends ActivityInstrumentationTestCase2<Settings> {
private static final String PACKAGE_NAME = "com.android.settings.tests.unit";
private static final String KEY_SETTINGS_ROOT = "parent";
private static final String KEY_SETTINGS_OPERATOR = "operator_settings";
private static final String KEY_SETTINGS_MANUFACTURER = "manufacturer_settings";
private static final String INTENT_OPERATOR_HOOK = "com.android.settings.OPERATOR_APPLICATION_SETTING";
private static final String INTENT_MANUFACTURER_HOOK = "com.android.settings.MANUFACTURER_APPLICATION_SETTING";
private Settings mSettings;
public SettingsHookTests() {
super("com.android.settings", Settings.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mSettings = getActivity();
}
/**
* Test that the operator/manufacturer settings hook test application is
* available and that it's installed in the device's system image.
*/
public void testSettingsHookTestAppAvailable() throws Exception {
Context context = mSettings.getApplicationContext();
PackageManager pm = context.getPackageManager();
ApplicationInfo applicationInfo = pm.getApplicationInfo(PACKAGE_NAME, 0);
assertTrue((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
}
/**
* Test that the operator test activity has registered an intent-filter for
* an action named 'android.settings.OPERATOR_APPLICATION_SETTING'.
*/
public void testOperatorIntentFilter() {
boolean result = false;
Context context = mSettings.getApplicationContext();
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(INTENT_OPERATOR_HOOK);
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : list) {
if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
result = true;
}
}
assertTrue("Intent-filter not found", result);
}
/**
* Test that the manufacturer test activity has registered an intent-filter
* for an action named 'android.settings.MANUFACTURER_APPLICATION_SETTING'.
*/
public void testManufacturerIntentFilter() {
boolean result = false;
Context context = mSettings.getApplicationContext();
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(INTENT_MANUFACTURER_HOOK);
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : list) {
if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
result = true;
}
}
assertTrue("Intent-filter not found", result);
}
/**
* Test that the operator preference is available in the Settings
* application.
*/
public void testOperatorPreferenceAvailable() {
// TODO: fix this test case to work with fragments
// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
// Preference operatorPreference = root.findPreference(KEY_SETTINGS_OPERATOR);
// assertNotNull(operatorPreference);
}
/**
* Test that the manufacturer preference is available in the Settings
* application.
*/
public void testManufacturerPreferenceAvailable() {
// TODO: fix this test case to work with fragments
// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
// Preference manufacturerHook = root.findPreference(KEY_SETTINGS_MANUFACTURER);
// assertNotNull(manufacturerHook);
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.applications;
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.test.InstrumentationTestCase;
import android.widget.TextView;
import com.android.settings.R;
import org.junit.Test;
/**
* Test for Advanced App preferences.
*/
@SmallTest
public class DefaultAppSettingsTest extends InstrumentationTestCase {
private UiDevice mDevice;
private Context mTargetContext;
private String mTargetPackage;
@Override
protected void setUp() throws Exception {
super.setUp();
mDevice = UiDevice.getInstance(getInstrumentation());
mTargetContext = getInstrumentation().getTargetContext();
mTargetPackage = mTargetContext.getPackageName();
}
@Test
public void testSelectDefaultHome_shouldLaunchHomePicker() throws Exception {
launchDefaultApps();
final String titleHomeApp = mTargetContext.getResources().getString(R.string.home_app);
mDevice.findObject(new UiSelector().text(titleHomeApp)).click();
final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId(
"com.android.settings:id/action_bar"));
final UiObject title = actionBar.getChild(
new UiSelector().className(TextView.class.getName()));
assertEquals(titleHomeApp, title.getText());
}
private void launchDefaultApps() throws Exception {
final Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setPackage(mTargetPackage)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().getContext().startActivity(settingsIntent);
final String titleApps = mTargetContext.getResources().getString(
R.string.app_and_notification_dashboard_title);
mDevice.findObject(new UiSelector().text(titleApps)).click();
final String titleAdvance = mTargetContext.getResources().getString(
R.string.advanced_section_header);
mDevice.findObject(new UiSelector().text(titleAdvance)).click();
final String titleDefaultApps = mTargetContext.getResources().getString(
R.string.app_default_dashboard_title);
mDevice.findObject(new UiSelector().text(titleDefaultApps)).click();
}
}

View File

@@ -0,0 +1,200 @@
/*
* 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.applications;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_DEFAULT;
import static android.app.AppOpsManager.MODE_ERRORED;
import static android.app.AppOpsManager.OP_REQUEST_INSTALL_PACKAGES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.List;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExternalSourcesSettingsTest {
private static final String TAG = ExternalSourcesSettingsTest.class.getSimpleName();
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
private static final long START_ACTIVITY_TIMEOUT = 5000;
private Context mContext;
private UiDevice mUiDevice;
private PackageManager mPackageManager;
private AppOpsManager mAppOpsManager;
private List<UserInfo> mProfiles;
private String mPackageName;
@Before
public void setUp() throws Exception {
mContext = InstrumentationRegistry.getTargetContext();
mPackageName = InstrumentationRegistry.getContext().getPackageName();
mPackageManager = mContext.getPackageManager();
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
mProfiles = mContext.getSystemService(UserManager.class).getProfiles(UserHandle.myUserId());
resetAppOpModeForAllProfiles();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mUiDevice.wakeUp();
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
}
private void resetAppOpModeForAllProfiles() throws Exception {
for (UserInfo user : mProfiles) {
final int uid = mPackageManager.getPackageUidAsUser(mPackageName, user.id);
mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES, uid, mPackageName, MODE_DEFAULT);
}
}
private Intent createManageExternalSourcesListIntent() {
final Intent manageExternalSourcesIntent = new Intent();
manageExternalSourcesIntent.setAction(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
return manageExternalSourcesIntent;
}
private Intent createManageExternalSourcesAppIntent(String packageName) {
final Intent intent = createManageExternalSourcesListIntent();
intent.setData(Uri.parse("package:" + packageName));
return intent;
}
private String getApplicationLabel(String packageName) throws Exception {
final ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0);
return mPackageManager.getApplicationLabel(info).toString();
}
private UiObject2 findAndVerifySwitchState(boolean checked) {
final BySelector switchSelector = By.clazz(Switch.class).res("android:id/switch_widget");
final UiObject2 switchPref = mUiDevice.wait(Until.findObject(switchSelector),
START_ACTIVITY_TIMEOUT);
assertNotNull("Switch not shown", switchPref);
assertTrue("Switch in invalid state", switchPref.isChecked() == checked);
return switchPref;
}
@Test
public void testManageExternalSourcesList() throws Exception {
final String testAppLabel = getApplicationLabel(mPackageName);
mContext.startActivity(createManageExternalSourcesListIntent());
final BySelector preferenceListSelector = By.clazz(ListView.class).res("android:id/list");
final UiObject2 preferenceList = mUiDevice.wait(Until.findObject(preferenceListSelector),
START_ACTIVITY_TIMEOUT);
assertNotNull("App list not shown", preferenceList);
final BySelector appLabelTextViewSelector = By.clazz(TextView.class)
.res("android:id/title")
.text(testAppLabel);
List<UiObject2> listOfMatchingTextViews;
do {
listOfMatchingTextViews = preferenceList.findObjects(appLabelTextViewSelector);
// assuming the number of profiles will be sufficiently small so that all the entries
// for the same package will fit in one screen at some time during the scroll.
} while (listOfMatchingTextViews.size() != mProfiles.size() &&
preferenceList.scroll(Direction.DOWN, 0.2f));
assertEquals("Test app not listed for each profile", mProfiles.size(),
listOfMatchingTextViews.size());
for (UiObject2 matchingObject : listOfMatchingTextViews) {
matchingObject.click();
findAndVerifySwitchState(true);
mUiDevice.pressBack();
}
}
private void testAppDetailScreenForAppOp(int appOpMode, int userId) throws Exception {
final String testAppLabel = getApplicationLabel(mPackageName);
final BySelector appDetailTitleSelector = By.clazz(TextView.class)
.res("com.android.settings:id/app_detail_title")
.text(testAppLabel);
mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES,
mPackageManager.getPackageUidAsUser(mPackageName, userId), mPackageName, appOpMode);
mContext.startActivityAsUser(createManageExternalSourcesAppIntent(mPackageName),
UserHandle.of(userId));
mUiDevice.wait(Until.findObject(appDetailTitleSelector), START_ACTIVITY_TIMEOUT);
findAndVerifySwitchState(appOpMode == MODE_ALLOWED || appOpMode == MODE_DEFAULT);
mUiDevice.pressBack();
}
@Test
public void testManageExternalSourcesForApp() throws Exception {
// App op MODE_DEFAULT is already tested in #testManageExternalSourcesList
for (UserInfo user : mProfiles) {
testAppDetailScreenForAppOp(MODE_ALLOWED, user.id);
testAppDetailScreenForAppOp(MODE_ERRORED, user.id);
}
}
private void testSwitchToggle(int fromAppOp, int toAppOp) throws Exception {
final int packageUid = mPackageManager.getPackageUid(mPackageName, 0);
final boolean initialState = (fromAppOp == MODE_ALLOWED || fromAppOp == MODE_DEFAULT);
mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES, packageUid, mPackageName, fromAppOp);
mContext.startActivity(createManageExternalSourcesAppIntent(mPackageName));
final UiObject2 switchPref = findAndVerifySwitchState(initialState);
switchPref.click();
Thread.sleep(1000);
assertEquals("Toggling switch did not change app op", toAppOp,
mAppOpsManager.checkOpNoThrow(OP_REQUEST_INSTALL_PACKAGES, packageUid,
mPackageName));
mUiDevice.pressBack();
}
@Test
public void testIfSwitchTogglesAppOp() throws Exception {
testSwitchToggle(MODE_ALLOWED, MODE_ERRORED);
testSwitchToggle(MODE_ERRORED, MODE_ALLOWED);
}
@After
public void tearDown() throws Exception {
mUiDevice.pressHome();
resetAppOpModeForAllProfiles();
}
}

View File

@@ -0,0 +1,40 @@
package com.android.settings.deviceinfo;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnitRunner;
import com.android.settings.R;
import com.android.settings.Settings.StorageDashboardActivity;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
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.matcher.IntentMatchers.hasExtra;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@SmallTest
public class StorageDashboardFragmentTest {
public static final String EXTRA_KEY = ":settings:show_fragment";
@Rule
public IntentsTestRule<StorageDashboardActivity> mActivityRule =
new IntentsTestRule<>(StorageDashboardActivity.class, true, true);
@Test
public void testStorageManagePreference_canClickTextView() throws InterruptedException {
// Click on the actual textbox instead of just somewhere in the preference
onView(withText(R.string.automatic_storage_manager_preference_title)).perform(click());
// Check that it worked by seeing if we switched screens
intended(hasExtra(equalTo(EXTRA_KEY),
containsString(AutomaticStorageManagerSettings.class.getName())));
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.fuelgauge;
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.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class PowerUsageSummaryTest {
private static final String BATTERY_INTENT = "android.intent.action.POWER_USAGE_SUMMARY";
@Before
public void SetUp() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.startActivitySync(new Intent(BATTERY_INTENT));
}
@Test
public void testClickLastFullCharge_shouldNotCrash() {
onView(withText(R.string.battery_last_full_charge)).perform(click());
}
@Test
public void testClickScreenUsage_shouldNotCrash() {
onView(withText(R.string.device_screen_usage)).perform(click());
}
}

View File

@@ -0,0 +1,53 @@
package com.android.settings.notification;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
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.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ZenModeSettingsIntegrationTest {
private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
private Context mContext;
private UiDevice mUiDevice;
@Before
public void setUp() throws Exception {
mContext = InstrumentationRegistry.getTargetContext();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mUiDevice.wakeUp();
mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
}
@Test
public void testAutomaticRulesAppear() {
launchZenSettings();
onView(withText("Automatic rules")).check(matches(isDisplayed()));
onView(withText("Weekend")).check(matches(isDisplayed()));
onView(withText("Add more")).check(matches(isDisplayed())).perform(click());
onView(withText("Choose rule type")).check(matches(isDisplayed()));
}
private void launchZenSettings() {
Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS)
.setPackage(mContext.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(settingsIntent);
}
}

View File

@@ -0,0 +1,236 @@
/*
* 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.password;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.AppTask;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.support.test.filters.MediumTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
import android.support.test.runner.lifecycle.Stage;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiSelector;
import android.text.format.DateUtils;
import android.view.WindowManager;
import com.android.internal.widget.LockPatternUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Collection;
import java.util.List;
/**
* Tests for {@link ChooseLockGenericTest}
*
* m SettingsTests &&
* adb install \
* -r -g ${ANDROID_PRODUCT_OUT}/data/app/SettingsTests/SettingsTests.apk &&
* adb shell am instrument -e class com.android.settings.password.ChooseLockGenericTest \
* -w com.android.settings.tests/android.support.test.runner.AndroidJUnitRunner
*/
@RunWith(AndroidJUnit4.class)
@MediumTest
public class ChooseLockGenericTest {
private static final long TIMEOUT = 5 * DateUtils.SECOND_IN_MILLIS;
private static final Intent PHISHING_ATTACK_INTENT = new Intent()
.putExtra("confirm_credentials", false)
.putExtra("password_confirmed", true);
private UiDevice mDevice;
private Context mTargetContext;
private String mSettingPackage;
@Rule
public ActivityTestRule<ChooseLockGeneric> mChooseLockGenericActivityRule =
new ActivityTestRule<>(
ChooseLockGeneric.class,
true /* enable touch at launch */,
false /* don't launch at every test */);
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(getInstrumentation());
mTargetContext = getInstrumentation().getTargetContext();
mSettingPackage = mTargetContext.getPackageName();
}
@Test
public void testConfirmLockPasswordShown_deviceWithPassword() throws Throwable {
setPassword();
try {
// GIVEN a PIN password is set on this device at set up.
// WHEN ChooseLockGeneric is launched with no extras.
mChooseLockGenericActivityRule.launchActivity(null /* No extras */);
// THEN ConfirmLockPassword.InternalActivity is shown.
final Activity activity = getCurrentActivity();
assertThat(isSecureWindow(activity)).isTrue();
assertThat(activity)
.isInstanceOf(ConfirmLockPassword.InternalActivity.class);
} finally {
finishAllAppTasks();
mDevice.waitForIdle();
clearPassword();
}
}
@Test
public void testConfirmLockPasswordShown_deviceWithPassword_phishingAttack() throws Throwable {
setPassword();
try {
// GIVEN a PIN password is set on this device at set up.
// WHEN ChooseLockGeneric is launched with extras to by-pass lock password confirmation.
mChooseLockGenericActivityRule.launchActivity(PHISHING_ATTACK_INTENT);
// THEN ConfirmLockPassword.InternalActivity is still shown.
final Activity activity = getCurrentActivity();
assertThat(isSecureWindow(activity)).isTrue();
assertThat(activity)
.isInstanceOf(ConfirmLockPassword.InternalActivity.class);
} finally {
finishAllAppTasks();
mDevice.waitForIdle();
clearPassword();
}
}
@Test
public void testForFingerprint_inflateLayout() {
mChooseLockGenericActivityRule.launchActivity(new Intent()
.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true));
assertThat(mChooseLockGenericActivityRule.getActivity().isResumed()).isTrue();
}
private Activity getCurrentActivity() throws Throwable {
getInstrumentation().waitForIdleSync();
final Activity[] activity = new Activity[1];
getInstrumentation().runOnMainSync(() -> {
Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance()
.getActivitiesInStage(Stage.RESUMED);
activity[0] = activities.iterator().next();
});
return activity[0];
}
/** Sets a PIN password, 12345, for testing. */
private void setPassword() throws Exception {
Intent newPasswordIntent = new Intent(getTargetContext(), ChooseLockGeneric.class)
.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC)
.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
"12345")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().getContext().startActivity(newPasswordIntent);
mDevice.waitForIdle();
// Ignore any interstitial options
UiObject view = new UiObject(new UiSelector()
.resourceId(mSettingPackage + ":id/encrypt_dont_require_password"));
if (view.waitForExists(TIMEOUT)) {
view.click();
mDevice.waitForIdle();
}
// Set our PIN
view = new UiObject(new UiSelector()
.resourceId(mSettingPackage + ":id/password_entry"));
assertTrue("password_entry", view.waitForExists(TIMEOUT));
// Enter it twice to confirm
enterTestPin(view);
enterTestPin(view);
// Dismiss notifications setting
view = new UiObject(new UiSelector()
.resourceId(mSettingPackage + ":id/redaction_done_button"));
if (view.waitForExists(TIMEOUT)) {
view.click();
mDevice.waitForIdle();
}
mDevice.pressBack();
assertThat(getTargetContext().getSystemService(KeyguardManager.class).isDeviceSecure())
.isTrue();
}
/** Clears the previous set PIN password. */
private void clearPassword() throws Exception {
Intent newPasswordIntent = new Intent(getTargetContext(), ChooseLockGeneric.class)
.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
getInstrumentation().getContext().startActivity(newPasswordIntent);
mDevice.waitForIdle();
// Enter current PIN
UiObject view = new UiObject(
new UiSelector().resourceId(mSettingPackage + ":id/password_entry"));
if (!view.waitForExists(TIMEOUT)) {
// Odd, maybe there is a crash dialog showing; try dismissing it
mDevice.pressBack();
mDevice.waitForIdle();
assertTrue("password_entry", view.waitForExists(TIMEOUT));
}
enterTestPin(view);
mDevice.pressBack();
assertThat(getTargetContext().getSystemService(KeyguardManager.class).isDeviceSecure())
.isFalse();
}
private void finishAllAppTasks() {
final ActivityManager activityManager =
getTargetContext().getSystemService(ActivityManager.class);
final List<AppTask> appTasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : appTasks) {
task.finishAndRemoveTask();
}
}
private void enterTestPin(UiObject view) throws Exception {
mDevice.waitForIdle();
view.setText("12345");
mDevice.pressEnter();
mDevice.waitForIdle();
}
private boolean isSecureWindow(Activity activity) {
return (activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_SECURE)
!= 0;
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2017 Google Inc.
*
* 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.password;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.pressKey;
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.isEnabled;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.CoreMatchers.not;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.runner.AndroidJUnit4;
import android.view.KeyEvent;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ChooseLockPasswordTest {
private Instrumentation mInstrumentation;
private Context mContext;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mContext = mInstrumentation.getTargetContext();
}
@Test
public void clearNotVisible_when_activityLaunchedInitially() {
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
onView(withId(R.id.clear_button)).check(matches(
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
@Test
public void clearNotEnabled_when_nothingEntered() {
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
onView(withId(R.id.clear_button)).check(matches(isDisplayed()))
.check(matches(not(isEnabled())));
}
@Test
public void clearEnabled_when_somethingEnteredToConfirm() {
mInstrumentation.startActivitySync(new Intent(mContext, ChooseLockPassword.class));
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
.perform(ViewActions.typeText("1"));
// clear should be present if text field contains content
onView(withId(R.id.clear_button)).check(matches(isDisplayed()));
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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.password;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.pressKey;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
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.runner.AndroidJUnit4;
import android.view.KeyEvent;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ConfirmLockPasswordTest {
private Instrumentation mInstrumentation;
private Context mContext;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mContext = mInstrumentation.getTargetContext();
}
@Test
public void enterWrongPin_shouldShowErrorMessage() {
mInstrumentation.startActivitySync(
new Intent(mContext, ConfirmLockPassword.class));
onView(withId(R.id.password_entry)).perform(typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
onView(withId(R.id.errorText)).check(matches(withText(R.string.lockpassword_invalid_pin)));
}
@Test
public void enterWrongPin_darkTheme_shouldShowErrorMessage() {
mInstrumentation.startActivitySync(
new Intent(mContext, ConfirmLockPassword.class)
.putExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, true));
onView(withId(R.id.password_entry)).perform(typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
onView(withId(R.id.errorText)).check(matches(withText(R.string.lockpassword_invalid_pin)));
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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.password;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.pressKey;
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.isEnabled;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.CoreMatchers.not;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.MediumTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.KeyEvent;
import com.android.settings.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class SetupChooseLockPasswordAppTest {
@Rule
public ActivityTestRule<SetupChooseLockPassword> mActivityTestRule =
new ActivityTestRule<>(
SetupChooseLockPassword.class,
true /* enable touch at launch */,
false /* don't launch at every test */);
@Test
public void testSkipDialogIsShown() throws Throwable {
SetupChooseLockPassword activity = mActivityTestRule.launchActivity(null);
onView(withId(R.id.cancel_button))
.check(matches(withText(R.string.skip_label)))
.check(matches(isDisplayed()))
.perform(click());
onView(withId(android.R.id.button1)).check(matches(isDisplayed())).perform(click());
assertThat(activity.isFinishing()).named("Is finishing").isTrue();
}
@Test
public void clearNotVisible_when_activityLaunchedInitially() {
mActivityTestRule.launchActivity(null);
onView(withId(R.id.clear_button)).check(matches(
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
@Test
public void clearNotEnabled_when_nothingEntered() throws Throwable {
mActivityTestRule.launchActivity(null);
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER));
onView(withId(R.id.clear_button)).check(matches(isDisplayed()))
.check(matches(not(isEnabled())));
}
@Test
public void clearEnabled_when_somethingEnteredToConfirm() {
mActivityTestRule.launchActivity(null);
onView(withId(R.id.password_entry)).perform(ViewActions.typeText("1234"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
.perform(ViewActions.typeText("1"));
// clear should be present if text field contains content
onView(withId(R.id.clear_button)).check(matches(isDisplayed()));
}
}

View File

@@ -0,0 +1,178 @@
/*
* Copyright (C) 2009 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.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import com.android.settings.tests.unit.R;
public class BluetoothRequestPermissionTest extends Activity {
private static final String TAG = "BluetoothRequestPermissionTest";
BluetoothAdapter mAdapter;
private ArrayAdapter<String> mMsgAdapter;
// Discoverable button alternates between 20 second timeout and no timeout.
private boolean mDiscoveryWithTimeout = true;
private class BtOnClickListener implements OnClickListener {
final boolean mEnableOnly; // enable or enable + discoverable
public BtOnClickListener(boolean enableOnly) {
mEnableOnly = enableOnly;
}
public void onClick(View v) {
requestPermission(mEnableOnly);
}
}
private class BtScanOnClickListener implements OnClickListener {
public void onClick(View v) {
Button scanButton = (Button) v;
if (mAdapter.isDiscovering()) {
mAdapter.cancelDiscovery();
scanButton.setText(R.string.start_scan);
} else {
mAdapter.startDiscovery();
scanButton.setText(R.string.stop_scan);
}
}
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.bluetooth_request_permission_test);
mAdapter = BluetoothAdapter.getDefaultAdapter();
Button enable = (Button) findViewById(R.id.enable);
enable.setOnClickListener(new BtOnClickListener(true /* enable */));
Button discoverable = (Button) findViewById(R.id.discoverable);
discoverable.setOnClickListener(new BtOnClickListener(false /* enable & discoverable */));
Button scanButton = (Button) findViewById(R.id.scan);
scanButton.setOnClickListener(new BtScanOnClickListener());
if (mAdapter.isDiscovering()) {
scanButton.setText(R.string.stop_scan);
} else {
scanButton.setText(R.string.start_scan);
}
mMsgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
ListView listView = (ListView) findViewById(R.id.msg_container);
listView.setAdapter(mMsgAdapter);
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
addMsg("Initialized");
}
void requestPermission(boolean enableOnly) {
Intent i = new Intent();
if (enableOnly) {
addMsg("Starting activity to enable bt");
i.setAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);
} else {
addMsg("Starting activity to enable bt + discovery");
i.setAction(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
// Discoverability duration toggles between 20 seconds and no timeout.
int timeout = (mDiscoveryWithTimeout ? 20 : 0);
i.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, timeout);
mDiscoveryWithTimeout = !mDiscoveryWithTimeout;
}
startActivityForResult(i, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != 1) {
Log.e(TAG, "Unexpected onActivityResult " + requestCode + " " + resultCode);
return;
}
if (resultCode == Activity.RESULT_CANCELED) {
addMsg("Result = RESULT_CANCELED");
} else if (resultCode == Activity.RESULT_OK) {
addMsg("Result = RESULT_OK (not expected for discovery)");
} else {
addMsg("Result = " + resultCode);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mReceiver);
}
private void addMsg(String msg) {
mMsgAdapter.add(msg);
Log.d(TAG, "msg");
}
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
String action = intent.getAction();
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
String stateStr = "???";
switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR)) {
case BluetoothAdapter.STATE_OFF:
stateStr = "off";
break;
case BluetoothAdapter.STATE_TURNING_ON:
stateStr = "turning on";
break;
case BluetoothAdapter.STATE_ON:
stateStr = "on";
break;
case BluetoothAdapter.STATE_TURNING_OFF:
stateStr = "turning off";
break;
}
addMsg("Bluetooth status = " + stateStr);
} else if (action.equals(BluetoothDevice.ACTION_FOUND)) {
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
addMsg("Found: " + name);
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED)) {
addMsg("Scan started...");
} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
addMsg("Scan ended");
}
}
};
}

View File

@@ -0,0 +1,74 @@
/*
* 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.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.UiDevice;
import org.junit.runner.RunWith;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import org.junit.Test;
import com.android.settings.R;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DrawOverlayDetailsTest {
private final static String PACKAGE_SYSTEM_UI = "com.android.systemui";
@Test
public void testSystemUiDrawOverlayDetails_Disabled() throws Exception{
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.startActivitySync(new Intent(android.provider.Settings
.ACTION_MANAGE_OVERLAY_PERMISSION));
final Context targetContext = instrumentation.getTargetContext();
final PackageManager packageManager = targetContext.getPackageManager();
final String appName = (String) packageManager.getApplicationLabel(packageManager
.getApplicationInfo(PACKAGE_SYSTEM_UI, PackageManager.GET_META_DATA));
final UiDevice device = UiDevice.getInstance(instrumentation);
device.waitForIdle();
openActionBarOverflowOrOptionsMenu(targetContext);
onView(withText(targetContext.getString(R.string.menu_show_system))).perform(click());
device.waitForIdle();
final UiScrollable settings = new UiScrollable(
new UiSelector().packageName(targetContext.getPackageName()).scrollable(true));
settings.scrollTextIntoView(appName);
onView(withText(appName)).perform(click());
onView(withText(targetContext.getString(R.string.permit_draw_overlay))).check(matches
(not(isEnabled())));
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.Context;
import android.content.Intent;
import android.os.BatteryManager;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import com.android.settings.R;
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.*;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class KeepOnScreenTest {
private static int EXPECTED_FLAG = BatteryManager.BATTERY_PLUGGED_AC
| BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS;
@Test
public void testStayAwake_turnOn_StayAwakeWhileWirelessCharging() throws Exception{
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
instrumentation.startActivitySync(new Intent(android.provider.Settings
.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
final Context targetContext = instrumentation.getTargetContext();
final int prevFlag = Settings.Global.getInt(targetContext.getContentResolver(), Settings
.Global.STAY_ON_WHILE_PLUGGED_IN);
// Turn on "Stay Awake" if needed
if (prevFlag == 0) {
onView(withText(R.string.keep_screen_on)).perform(click());
}
final int currentFlag = Settings.Global.getInt(targetContext.getContentResolver(), Settings
.Global.STAY_ON_WHILE_PLUGGED_IN);
assertEquals(EXPECTED_FLAG, currentFlag);
// Since this app doesn't have permission(and shouldn't have) to change global setting, we
// can only tearDown in this way
if (prevFlag != currentFlag) {
onView(withText(R.string.keep_screen_on)).perform(click());
}
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2010 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.Activity;
import android.os.Bundle;
import com.android.settings.tests.unit.R;
public class Manufacturer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.manufacturer_main);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2010 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.Activity;
import android.os.Bundle;
import com.android.settings.tests.unit.R;
public class Operator extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.operator_main);
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2007 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.Activity;
import android.test.LaunchPerformanceBase;
import android.os.Bundle;
import java.util.Map;
/**
* Instrumentation class for Settings launch performance testing.
*/
public class SettingsLaunchPerformance extends LaunchPerformanceBase {
public static final String LOG_TAG = "SettingsLaunchPerformance";
public SettingsLaunchPerformance() {
super();
}
@Override
public void onCreate(Bundle arguments) {
super.onCreate(arguments);
mIntent.setClassName(getTargetContext(), "com.android.settings.Settings");
start();
}
/**
* Calls LaunchApp and finish.
*/
@Override
public void onStart() {
super.onStart();
LaunchApp();
finish(Activity.RESULT_OK, mResults);
}
}

View File

@@ -66,15 +66,15 @@ public class WifiTetherSettingsTest {
@Test
public void launchTetherSettings_shouldHaveAllFields() {
launchWifiTetherActivity();
onView(withText("Network name")).check(matches(isDisplayed()));
onView(withText("Password")).check(matches(isDisplayed()));
onView(withText("Select AP Band")).check(matches(isDisplayed()));
onView(withText("Hotspot name")).check(matches(isDisplayed()));
onView(withText("Hotspot password")).check(matches(isDisplayed()));
onView(withText("AP Band")).check(matches(isDisplayed()));
}
private void launchWifiTetherActivity() {
mInstrumentation.startActivitySync(mTetherActivityIntent);
onView(withText("Portable WiFi hotspot")).perform();
UiObject2 item = mDevice.wait(Until.findObject(By.text("Portable WiFi hotspot")), TIMEOUT);
onView(withText("WiFi hotspot")).perform();
UiObject2 item = mDevice.wait(Until.findObject(By.text("WiFi hotspot")), TIMEOUT);
item.click();
}
}