summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/build.gradle8
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/StartActivityDrawerTest.java84
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java8
3 files changed, 73 insertions, 27 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 51c16eaa..a809e86a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -153,6 +153,7 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
+ //outdated mockito-core version due to powermock dependency
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation('org.powermock:powermock-api-mockito2:1.7.3')
{ exclude group: 'junit' exclude group: 'org.mockito' }
@@ -162,9 +163,9 @@ dependencies {
testImplementation group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.10.0'
androidTestImplementation 'org.mockito:mockito-core:2.8.9'
- androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
- androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
- androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.1'
+ androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+ androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
+ androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
//TODO: remove that library
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'
testImplementation 'junit:junit:4.12'
@@ -177,7 +178,6 @@ dependencies {
implementation 'com.jakewharton:butterknife:6.1.0'
//TODO: replace that library
compileOnly 'com.squareup.dagger:dagger-compiler:1.2.2'
- //TODO: remove that library?
implementation 'com.github.pedrovgs:renderers:1.5'
implementation 'com.intellij:annotations:12.0'
implementation 'com.google.code.gson:gson:2.8.2'
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;