use of com.nextcloud.client.account.UserAccountManager in project android by nextcloud.
the class LoginIT method tearDown.
@AfterClass
public static void tearDown() {
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
if (accountManager.getAccounts().length > 0) {
accountManager.removeAllAccounts();
}
}
use of com.nextcloud.client.account.UserAccountManager in project android by nextcloud.
the class LoginIT method login.
@Test
public void login() throws InterruptedException {
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
String baseUrl = arguments.getString("TEST_SERVER_URL");
String loginName = arguments.getString("TEST_SERVER_USERNAME");
String password = arguments.getString("TEST_SERVER_PASSWORD");
onView(withId(R.id.login)).perform(click());
onView(withId(R.id.host_url_input)).perform(typeText(baseUrl));
onView(withId(R.id.host_url_input)).perform(typeTextIntoFocusedView("\n"));
Thread.sleep(3000);
onWebView().forceJavascriptEnabled();
// click on login
onWebView().withElement(findElement(Locator.XPATH, "//p[@id='redirect-link']/a")).perform(webClick());
// username
onWebView().withElement(findElement(Locator.XPATH, "//input[@id='user']")).perform(DriverAtoms.webKeys(loginName));
// password
onWebView().withElement(findElement(Locator.XPATH, "//input[@id='password']")).perform(DriverAtoms.webKeys(password));
// click login
onWebView().withElement(findElement(Locator.XPATH, "//input[@id='submit-form']")).perform(webClick());
Thread.sleep(2000);
// grant access
onWebView().withElement(findElement(Locator.XPATH, "//input[@type='submit']")).perform(webClick());
Thread.sleep(5 * 1000);
// check for account
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
assertEquals(1, accountManager.getAccounts().length);
Account account = accountManager.getAccounts()[0];
// account.name is loginName@baseUrl (without protocol)
assertEquals(loginName, account.name.split("@")[0]);
assertEquals(baseUrl.split("//")[1], account.name.split("@")[1]);
}
use of com.nextcloud.client.account.UserAccountManager in project android by nextcloud.
the class DialogFragmentIT method testAccountChooserDialogWithStatusDisabled.
@Test
@ScreenshotTest
public void testAccountChooserDialogWithStatusDisabled() throws AccountUtils.AccountNotFoundException {
AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccounts()) {
accountManager.removeAccountExplicitly(account);
}
Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount, "password", null);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDisplayActivity fda = getFileDisplayActivity();
UserAccountManager userAccountManager = fda.getUserAccountManager();
User newUser = userAccountManager.getUser(newAccount.name).get();
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
OCCapability capability = new OCCapability();
capability.setUserStatus(CapabilityBooleanType.FALSE);
fileDataStorageManager.saveCapabilities(capability);
ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
showDialog(fda, sut);
}
use of com.nextcloud.client.account.UserAccountManager in project android by nextcloud.
the class DrawerActivityIT method beforeClass.
@BeforeClass
public static void beforeClass() {
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
Uri baseUrl = Uri.parse(arguments.getString("TEST_SERVER_URL"));
AccountManager platformAccountManager = AccountManager.get(targetContext);
UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
for (Account account : platformAccountManager.getAccounts()) {
platformAccountManager.removeAccountExplicitly(account);
}
String loginName = "user1";
String password = "user1";
Account temp = new Account(loginName + "@" + baseUrl, MainApp.getAccountType(targetContext));
platformAccountManager.addAccountExplicitly(temp, password, null);
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(UserAccountManager.ACCOUNT_VERSION));
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, baseUrl.toString());
// same as userId
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, loginName);
account1 = userAccountManager.getAccountByName(loginName + "@" + baseUrl);
user1 = userAccountManager.getUser(account1.name).orElseThrow(IllegalAccessError::new);
loginName = "user2";
password = "user2";
temp = new Account(loginName + "@" + baseUrl, MainApp.getAccountType(targetContext));
platformAccountManager.addAccountExplicitly(temp, password, null);
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(UserAccountManager.ACCOUNT_VERSION));
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, baseUrl.toString());
// same as userId
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, loginName);
account2 = userAccountManager.getAccountByName(loginName + "@" + baseUrl);
account2Name = loginName + "@" + baseUrl;
account2DisplayName = "User Two@" + baseUrl;
}
use of com.nextcloud.client.account.UserAccountManager in project android by nextcloud.
the class DialogFragmentIT method testAccountChooserDialog.
@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
FileDisplayActivity activity = getFileDisplayActivity();
UserAccountManager userAccountManager = activity.getUserAccountManager();
AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
accountManager.removeAccountExplicitly(account);
}
Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount, "password", null);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount2, "password", null);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
OCCapability capability = new OCCapability();
capability.setUserStatus(CapabilityBooleanType.TRUE);
capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
fileDataStorageManager.saveCapabilities(capability);
ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
showDialog(activity, sut);
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "dnd");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "online");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "fun");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "offline");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "away");
}
Aggregations