diff options
author | cyBerta <cyberta@riseup.net> | 2019-01-02 14:12:26 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2019-01-02 14:12:26 +0100 |
commit | 33f811f6794e481d5cbdbdc359b70e8ab9309b05 (patch) | |
tree | 852d2bba8bea87c6ba93a5d1c089825a8d25d313 /app/src | |
parent | 71a97834c7dff8dd23ecb544d512a9975843de1b (diff) |
fix instrumentation tests, update espresso test framework
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java | 84 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java | 8 |
2 files changed, 69 insertions, 23 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java index d7580c88..2d3fe6bb 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java @@ -15,8 +15,10 @@ import org.junit.runner.RunWith; import java.io.IOException; +import se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.MainActivity; import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.testutils.TestSetupHelper; import static android.support.test.InstrumentationRegistry.getInstrumentation; @@ -26,17 +28,21 @@ import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.contrib.DrawerMatchers.isClosed; import static android.support.test.espresso.contrib.DrawerMatchers.isOpen; +import static android.support.test.espresso.matcher.RootMatchers.isDialog; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.anything; +import static se.leap.bitmaskclient.Constants.FIRST_TIME_USER_DATE; +import static se.leap.bitmaskclient.Constants.LAST_DONATION_REMINDER_DATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT; import static se.leap.bitmaskclient.R.id.aboutLayout; import static se.leap.bitmaskclient.R.id.accountList; -import static se.leap.bitmaskclient.R.id.provider_list_layout; import static se.leap.bitmaskclient.R.id.drawer_layout; import static se.leap.bitmaskclient.R.id.eipServiceFragment; import static se.leap.bitmaskclient.R.id.log_layout; +import static se.leap.bitmaskclient.R.id.provider_list_layout; import static se.leap.bitmaskclient.R.id.settingsList; /** @@ -65,7 +71,8 @@ public class StartActivityDrawerTest { preferencesEditor = preferences.edit(); preferencesEditor.putString(Provider.KEY, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.json"))) .putString(Provider.CA_CERT, TestSetupHelper.getInputAsString(InstrumentationRegistry.getContext().getAssets().open("riseup.net.pem"))) - .commit(); + .putString(LAST_DONATION_REMINDER_DATE, null) + .putString(FIRST_TIME_USER_DATE, null).commit(); } @@ -89,39 +96,86 @@ public class StartActivityDrawerTest { } @Test - public void testClickProviderName_closeDrawerAndShowEipFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickProviderName_closeDrawerAndShowEipFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); onData(anything()).inAdapterView(withId(accountList)).atPosition(0).perform(click()); onView(withId(drawer_layout)).check(matches(isClosed())); onView(withId(eipServiceFragment)).check(matches(isDisplayed())); } @Test - public void testClickSwitchProvider_closeDrawerAndShowProviderListView() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testSaveBattery_closeDrawerAndShowSaveBatteryDialog() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); onData(anything()).inAdapterView(withId(settingsList)).atPosition(0).perform(click()); + onView(withText(R.string.save_battery_message)) + .inRoot(isDialog()) + .check(matches(isDisplayed())); + } + + @Test + public void testAlwaysOnVPN_closeDrawerAndShowDialog() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); + mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(1).perform(click()); + onView(withText(R.string.always_on_vpn_user_message)) + .inRoot(isDialog()) + .check(matches(isDisplayed())); + } + + @Test + public void testClickSwitchProvider_closeDrawerAndShowProviderListView() throws InterruptedException { + if (BuildConfig.FLAVOR_branding.equals("custom")) { + return; + } + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); + mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + + onData(anything()).inAdapterView(withId(settingsList)).atPosition(3).perform(click()); onView(withId(provider_list_layout)).check(matches(isDisplayed())); } @Test - public void testClickLog_closeDrawerAndShowLogFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickLog_closeDrawerAndShowLogFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); - onData(anything()).inAdapterView(withId(settingsList)).atPosition(1).perform(click()); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(getPositionBasedOnFlavor(2, 3)).perform(click()); onView(withId(log_layout)).check(matches(isDisplayed())); } @Test - public void testClickAbout_closeDrawerAndShowAboutFragment() { - preferencesEditor.putBoolean("navigation_drawer_learned", false).commit(); + public void testClickAbout_closeDrawerAndShowAboutFragment() throws InterruptedException { + preferencesEditor.putBoolean("navigation_drawer_learned", true).commit(); mActivityRule.launchActivity(intent); - - onData(anything()).inAdapterView(withId(settingsList)).atPosition(2).perform(click()); + onView(withId(drawer_layout)).check(matches(isClosed())); + onView(withId(drawer_layout)).perform(DrawerActions.open()); + onView(withId(drawer_layout)).check(matches(isOpen())); + onData(anything()).inAdapterView(withId(settingsList)).atPosition(getPositionBasedOnFlavor(4,5)).perform(click()); onView(withId(aboutLayout)).check(matches(isDisplayed())); } + + private int getPositionBasedOnFlavor(int custom, int defaultNumber) { + if (BuildConfig.FLAVOR_branding.equals("custom")) { + return custom; + } else { + return defaultNumber; + } + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java index 11582d87..44831049 100644 --- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java @@ -2,7 +2,6 @@ package se.leap.bitmaskclient.utils; import android.content.Context; import android.content.SharedPreferences; -import android.os.Looper; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -10,12 +9,6 @@ import android.support.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -31,7 +24,6 @@ import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION; import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED; import static se.leap.bitmaskclient.Constants.PROVIDER_EIP_DEFINITION; import static se.leap.bitmaskclient.Constants.PROVIDER_PRIVATE_KEY; -import static se.leap.bitmaskclient.Constants.PROVIDER_PROFILE_UUID; import static se.leap.bitmaskclient.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; |