AuthenticatorActivityTest.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.BuildConfig;
  27. import com.owncloud.android.R;
  28. import org.junit.Rule;
  29. import org.junit.Test;
  30. import org.junit.runner.RunWith;
  31. import static android.support.test.espresso.Espresso.onView;
  32. import static android.support.test.espresso.action.ViewActions.click;
  33. import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
  34. import static android.support.test.espresso.action.ViewActions.typeText;
  35. import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
  36. import static android.support.test.espresso.matcher.ViewMatchers.withId;
  37. import static android.support.test.espresso.assertion.ViewAssertions.matches;
  38. import static org.hamcrest.Matchers.not;
  39. @RunWith(AndroidJUnit4.class)
  40. @LargeTest
  41. public class AuthenticatorActivityTest {
  42. public static final String EXTRA_ACTION = "ACTION";
  43. public static final String EXTRA_ACCOUNT = "ACCOUNT";
  44. @Rule
  45. public ActivityTestRule<AuthenticatorActivity> mActivityRule = new ActivityTestRule<AuthenticatorActivity>(
  46. AuthenticatorActivity.class){
  47. @Override
  48. protected Intent getActivityIntent() {
  49. Context targetContext = InstrumentationRegistry.getInstrumentation()
  50. .getTargetContext();
  51. Intent result = new Intent(targetContext, AuthenticatorActivity.class);
  52. result.putExtra(EXTRA_ACTION, "");
  53. result.putExtra(EXTRA_ACCOUNT, "");
  54. return result;
  55. }
  56. };
  57. @Test
  58. public void check_login() {
  59. // Check that login button is disabled
  60. onView(withId(R.id.buttonOK))
  61. .check(matches(not(isEnabled())));
  62. // Type server url
  63. onView(withId(R.id.hostUrlInput))
  64. .perform(typeText(BuildConfig.TEST_SERVER_URL), closeSoftKeyboard());
  65. onView(withId(R.id.account_username)).perform(click());
  66. // Type user
  67. onView(withId(R.id.account_username))
  68. .perform(typeText(BuildConfig.TEST_USER), closeSoftKeyboard());
  69. // Type user pass
  70. onView(withId(R.id.account_password))
  71. .perform(typeText(BuildConfig.TEST_PASSWORD), closeSoftKeyboard());
  72. onView(withId(R.id.buttonOK)).perform(click());
  73. // Check that login button is now enabled
  74. onView(withId(R.id.buttonOK)).check(matches(isEnabled()));
  75. }
  76. }