summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-05-01 12:46:34 +0200
committerParménides GV <parmegv@sdf.org>2015-05-01 12:46:34 +0200
commitff679b7f20700cec2c08cb8026c585b47df3612f (patch)
tree693b8902736fff962510621687fb2d5fc1fc9df1 /app/src/androidTest/java
parent53b5cea881697d87ed655dd985368fc62a0b077b (diff)
testOnFailed()
And checks in controllers, so that if a button isn't shown, I throw a new IllegalStateException. This helps to trace the error.
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java75
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java15
2 files changed, 78 insertions, 12 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java
index 69fa01eb..40a9f656 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java
@@ -7,6 +7,8 @@ import android.widget.*;
import com.robotium.solo.*;
+import junit.framework.AssertionFailedError;
+
import de.blinkt.openvpn.activities.*;
import mbanje.kurt.fabbutton.*;
import se.leap.bitmaskclient.R;
@@ -26,16 +28,39 @@ public class VpnTestController {
turningEipOff();
}
- protected void clickVpnButton() {
- solo.clickOnView(getVpnButton());
+ protected void clickVpnButton() throws IllegalStateException {
+ Button button = getVpnButton();
+ if(!isVpnButton(button))
+ throw new IllegalStateException();
+ solo.clickOnView(button);
}
protected Button getVpnButton() {
- return (Button) solo.getView(R.id.vpn_main_button);
+ try {
+ View button_view = solo.getView(R.id.vpn_main_button);
+ if (button_view != null)
+ return (Button) button_view;
+ else
+ return new Button(solo.getCurrentActivity());
+ } catch (AssertionFailedError e) {
+ return new Button(solo.getCurrentActivity());
+ }
+ }
+
+ private boolean isVpnButton(Button button) {
+ return !button.getText().toString().isEmpty();
}
protected FabButton getVpnWholeIcon() {
- return (FabButton) solo.getView(R.id.vpn_Status_Image);
+ try {
+ View view = solo.getView(R.id.vpn_Status_Image);
+ if (view != null)
+ return (FabButton) view;
+ else
+ return null;
+ } catch (AssertionFailedError e) {
+ return null;
+ }
}
protected void turningEipOn() {
@@ -45,7 +70,7 @@ public class VpnTestController {
Condition condition = new Condition() {
@Override
public boolean isSatisfied() {
- return iconConnected();
+ return iconShowsConnected();
}
};
solo.waitForCondition(condition, max_seconds_until_connected * 1000);
@@ -53,16 +78,37 @@ public class VpnTestController {
}
private void assertInProgress() {
- ProgressRingView a = (ProgressRingView) getVpnWholeIcon().findViewById(R.id.fabbutton_ring);
+ FabButton whole_icon = getVpnWholeIcon();
+ ProgressRingView a;
+ a = whole_icon != null ?
+ (ProgressRingView) getVpnWholeIcon().findViewById(R.id.fabbutton_ring) :
+ new ProgressRingView(solo.getCurrentActivity());
BaseTestDashboard.isShownWithinConfinesOfVisibleScreen(a);
}
- private boolean iconConnected() {
- return getVpnInsideIcon().equals(getDrawable(R.drawable.ic_stat_vpn));
+ private boolean iconShowsConnected() {
+ return iconEquals(iconConnectedDrawable());
}
- private boolean iconDisconnected() {
- return getVpnInsideIcon().equals(getDrawable(R.drawable.ic_stat_vpn_offline));
+ protected boolean iconShowsDisconnected() {
+ return iconEquals(iconDisconnectedDrawable());
+ }
+
+ private boolean iconEquals(Drawable drawable) {
+ Bitmap inside_icon = getVpnInsideIcon();
+ if(inside_icon != null)
+ return inside_icon.equals(drawable);
+ else
+ return false;
+
+ }
+
+ private Drawable iconConnectedDrawable() {
+ return getDrawable(R.drawable.ic_stat_vpn);
+ }
+
+ private Drawable iconDisconnectedDrawable() {
+ return getDrawable(R.drawable.ic_stat_vpn_offline);
}
private Drawable getDrawable(int resId) {
@@ -70,7 +116,12 @@ public class VpnTestController {
}
private Bitmap getVpnInsideIcon() {
- CircleImageView a = (CircleImageView) getVpnWholeIcon().findViewById(R.id.fabbutton_circle);
+ FabButton whole_icon = getVpnWholeIcon();
+
+ CircleImageView a;
+ a = whole_icon != null ?
+ (CircleImageView) getVpnWholeIcon().findViewById(R.id.fabbutton_circle)
+ : new CircleImageView(solo.getCurrentActivity());
a.setDrawingCacheEnabled(true);
return a.getDrawingCache();
}
@@ -84,7 +135,7 @@ public class VpnTestController {
Condition condition = new Condition() {
@Override
public boolean isSatisfied() {
- return iconDisconnected();
+ return iconShowsDisconnected();
}
};
solo.waitForCondition(condition, max_seconds_until_connected * 1000);
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java
index a777d454..2f3d2614 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java
@@ -1,5 +1,9 @@
package se.leap.bitmaskclient.test;
+import java.util.Locale;
+
+import de.blinkt.openvpn.activities.LogWindow;
+
public class testVpnFragment extends BaseTestDashboard {
@Override
@@ -40,6 +44,17 @@ public class testVpnFragment extends BaseTestDashboard {
}
+ /**
+ * Run only if the trust this app dialog has not been checked.
+ * You must pay attention to the screen, because you need to cancel de dialog twice (block vpn and normal vpn)
+ */
+ public void testOnFailed() {
+ vpn_controller.clickVpnButton();
+ assertTrue(solo.waitForActivity(LogWindow.class));
+ solo.goBack();
+ vpn_controller.iconShowsDisconnected();
+ }
+
public void testVpnEveryProvider() {
String[] providers = {"demo.bitmask.net", "riseup.net", "calyx.net"};
for(String provider : providers) {