Move JUnit tests not from telephony settings into legacy directory.
In order to enable the junit tests as a blocking presubmit, we want to ensure that all tests within this directory are being actively maintained. A number of these tests were migrated to robolectric sometime in 2017-2018, and because they are no longer maintained this CL moves them into a separate folder, so that they will not be included in the presubmit. Please verify that this is the appropriate action to take for these tests. In the future, the settings team may decide to delete this legacy directory entirely. Note that AutoSelectPreferenceControllerTest.setChecked_isChecked_showProgressDialog is currently failing, but we can fix it in a separate CL. Test: make SettingsUnitTests && adb install -r out/target/product/shamu/testcases/SettingsUnitTests/arm64/SettingsUnitTests.apk Change-Id: Iafc15b9ac69b5ca2fec76d3c0c7e247ea0017d49
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.accounts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
||||
import android.support.test.uiautomator.UiScrollable;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class AccountsSettingsTest {
|
||||
|
||||
private static final String ACCOUNTS = "Accounts";
|
||||
private static final String ACCOUNT_TYPE = "com.settingstest.account-prefs";
|
||||
private static final String PREF_TITLE = "Test preference for external account";
|
||||
|
||||
private UiDevice mDevice;
|
||||
private Context mContext;
|
||||
private String mTargetPackage;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
mContext = InstrumentationRegistry.getTargetContext();
|
||||
mTargetPackage = mContext.getPackageName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExternalAccountInfoExists() throws UiObjectNotFoundException {
|
||||
// add a test account
|
||||
final String testAccountName = "Test Account";
|
||||
final Account account = new Account(testAccountName, ACCOUNT_TYPE);
|
||||
final AccountManager accountManager = AccountManager.get(mContext);
|
||||
final boolean accountAdded =
|
||||
accountManager.addAccountExplicitly(account, null /* password */, null /* userdata */);
|
||||
assertThat(accountAdded).isTrue();
|
||||
|
||||
// launch Accounts Settings and select the test account
|
||||
launchAccountsSettings();
|
||||
mDevice.findObject(new UiSelector().text(testAccountName)).click();
|
||||
final UiObject testPreference = mDevice.findObject(new UiSelector().text(PREF_TITLE));
|
||||
// remove test account
|
||||
accountManager.removeAccountExplicitly(account);
|
||||
|
||||
assertThat(testPreference.exists()).isTrue();
|
||||
}
|
||||
|
||||
private void launchAccountsSettings() throws UiObjectNotFoundException {
|
||||
// launch settings
|
||||
Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
.setPackage(mTargetPackage)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(settingsIntent);
|
||||
// selects Accounts
|
||||
final UiScrollable settings = new UiScrollable(
|
||||
new UiSelector().packageName(mTargetPackage).scrollable(true));
|
||||
final String titleAccounts = ACCOUNTS;
|
||||
settings.scrollTextIntoView(titleAccounts);
|
||||
mDevice.findObject(new UiSelector().text(titleAccounts)).click();
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.accounts;
|
||||
|
||||
import android.accounts.AbstractAccountAuthenticator;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountAuthenticatorResponse;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class Authenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
public Authenticator(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle editProperties(AccountAuthenticatorResponse r, String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings,
|
||||
Bundle bundle) throws NetworkErrorException {
|
||||
final Bundle result = new Bundle();
|
||||
result.putString(AccountManager.KEY_ACCOUNT_NAME, "Test Account");
|
||||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, s);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)
|
||||
throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle getAuthToken(AccountAuthenticatorResponse r, Account account, String s,
|
||||
Bundle bundle) throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthTokenLabel(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle updateCredentials(AccountAuthenticatorResponse r, Account account, String s,
|
||||
Bundle bundle) throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)
|
||||
throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.accounts;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class TestAuthService extends Service {
|
||||
|
||||
private Authenticator mAuthenticator;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
mAuthenticator = new Authenticator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return mAuthenticator.getIBinder();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user