AuthenticatorActivityTest.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * Copyright (C) 2015 ownCloud Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2,
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package com.owncloud.android.authentication;
  20. import android.content.Context;
  21. import android.content.Intent;
  22. import android.support.test.InstrumentationRegistry;
  23. import android.support.test.rule.ActivityTestRule;
  24. import android.support.test.runner.AndroidJUnit4;
  25. import android.test.suitebuilder.annotation.LargeTest;
  26. import com.owncloud.android.R;
  27. import org.junit.Rule;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import static android.support.test.espresso.Espresso.onView;
  31. import static android.support.test.espresso.action.ViewActions.click;
  32. import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
  33. import static android.support.test.espresso.action.ViewActions.typeText;
  34. import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
  35. import static android.support.test.espresso.matcher.ViewMatchers.withId;
  36. import static android.support.test.espresso.assertion.ViewAssertions.matches;
  37. import static org.hamcrest.Matchers.not;
  38. @RunWith(AndroidJUnit4.class)
  39. @LargeTest
  40. public class AuthenticatorActivityTest {
  41. public static final String EXTRA_ACTION = "ACTION";
  42. public static final String EXTRA_ACCOUNT = "ACCOUNT";
  43. public static final String TEST_USER = ""; // Fill with custom values
  44. public static final String TEST_PASSWORD = ""; // Fill with custom values
  45. public static final String TEST_SERVER_URL = ""; // Fill with custom values
  46. @Rule
  47. public ActivityTestRule<AuthenticatorActivity> mActivityRule = new ActivityTestRule<AuthenticatorActivity>(
  48. AuthenticatorActivity.class){
  49. @Override
  50. protected Intent getActivityIntent() {
  51. Context targetContext = InstrumentationRegistry.getInstrumentation()
  52. .getTargetContext();
  53. Intent result = new Intent(targetContext, AuthenticatorActivity.class);
  54. result.putExtra(EXTRA_ACTION, "");
  55. result.putExtra(EXTRA_ACCOUNT, "");
  56. return result;
  57. }
  58. };
  59. @Test
  60. public void check_login() {
  61. // Check that login button is disabled
  62. onView(withId(R.id.buttonOK))
  63. .check(matches(not(isEnabled())));
  64. // Type server url
  65. onView(withId(R.id.hostUrlInput))
  66. .perform(typeText(TEST_SERVER_URL), closeSoftKeyboard());
  67. onView(withId(R.id.account_username)).perform(click());
  68. // Type user
  69. onView(withId(R.id.account_username))
  70. .perform(typeText(TEST_USER), closeSoftKeyboard());
  71. // Type user pass
  72. onView(withId(R.id.account_password))
  73. .perform(typeText(TEST_PASSWORD), closeSoftKeyboard());
  74. onView(withId(R.id.buttonOK)).perform(click());
  75. // Check that login button is now enabled
  76. onView(withId(R.id.buttonOK)).check(matches(isEnabled()));
  77. }
  78. }