AuthenticatorActivityTest.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.net.Uri;
  23. import android.support.test.InstrumentationRegistry;
  24. import android.support.test.rule.ActivityTestRule;
  25. import android.support.test.runner.AndroidJUnit4;
  26. import android.test.suitebuilder.annotation.LargeTest;
  27. <<<<<<< HEAD
  28. import com.owncloud.android.BuildConfig;
  29. =======
  30. import static org.junit.Assert.assertTrue;
  31. import com.owncloud.android.ui.activity.FileActivity;
  32. >>>>>>> add asserts
  33. import com.owncloud.android.R;
  34. //import android.support.v7.app.AppCompat
  35. import org.junit.Rule;
  36. import org.junit.Test;
  37. import org.junit.runner.RunWith;
  38. import static org.junit.Assert.assertTrue;
  39. import java.lang.reflect.Field;
  40. import android.app.Activity;
  41. import java.lang.reflect.Field;
  42. import android.app.Activity;
  43. import static android.support.test.espresso.Espresso.onView;
  44. import static android.support.test.espresso.action.ViewActions.click;
  45. import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
  46. import static android.support.test.espresso.action.ViewActions.typeText;
  47. import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
  48. import static android.support.test.espresso.matcher.ViewMatchers.withId;
  49. import static android.support.test.espresso.assertion.ViewAssertions.matches;
  50. import static org.hamcrest.Matchers.not;
  51. @RunWith(AndroidJUnit4.class)
  52. @LargeTest
  53. public class AuthenticatorActivityTest {
  54. public static final String EXTRA_ACTION = "ACTION";
  55. public static final String EXTRA_ACCOUNT = "ACCOUNT";
  56. private int mResultCode = -2;
  57. private int WAIT_LOGIN = 5000;
  58. private static String errorMessage = "Activity not finished";
  59. @Rule
  60. public ActivityTestRule<AuthenticatorActivity> mActivityRule = new ActivityTestRule<AuthenticatorActivity>(
  61. AuthenticatorActivity.class){
  62. @Override
  63. protected Intent getActivityIntent() {
  64. targetContext = InstrumentationRegistry.getInstrumentation()
  65. .getTargetContext();
  66. Intent result = new Intent(targetContext, AuthenticatorActivity.class);
  67. result.putExtra(EXTRA_ACTION, "");
  68. result.putExtra(EXTRA_ACCOUNT, "");
  69. return result;
  70. }
  71. };
  72. @Test
  73. public void check_login() {
  74. // Check that login button is disabled
  75. onView(withId(R.id.buttonOK))
  76. .check(matches(not(isEnabled())));
  77. // Type server url
  78. onView(withId(R.id.hostUrlInput))
  79. .perform(typeText(BuildConfig.TEST_SERVER_URL), closeSoftKeyboard());
  80. onView(withId(R.id.account_username)).perform(click());
  81. // Type user
  82. onView(withId(R.id.account_username))
  83. .perform(typeText(BuildConfig.TEST_USER), closeSoftKeyboard());
  84. // Type user pass
  85. onView(withId(R.id.account_password))
  86. .perform(typeText(BuildConfig.TEST_PASSWORD), closeSoftKeyboard());
  87. onView(withId(R.id.buttonOK)).perform(click());
  88. // Check that the Activity ends after clicking
  89. try {
  90. Thread.sleep(WAIT_LOGIN);
  91. Field f = Activity.class.getDeclaredField("mResultCode");
  92. f.setAccessible(true);
  93. mResultCode = f.getInt(mActivityRule.getActivity());
  94. } catch (Exception e){
  95. e.printStackTrace();
  96. }
  97. assertTrue(errorMessage, mResultCode == Activity.RESULT_OK);
  98. }
  99. }