From 5cc63073c78f0792ea462f0c2119ce5d361e9c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 1 May 2015 11:25:40 +0200 Subject: Separated tests for VpnFragment. --- .../leap/bitmaskclient/test/VpnTestController.java | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java new file mode 100644 index 00000000..69fa01eb --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -0,0 +1,114 @@ +package se.leap.bitmaskclient.test; + +import android.graphics.*; +import android.graphics.drawable.*; +import android.view.*; +import android.widget.*; + +import com.robotium.solo.*; + +import de.blinkt.openvpn.activities.*; +import mbanje.kurt.fabbutton.*; +import se.leap.bitmaskclient.R; + +public class VpnTestController { + + private final Solo solo; + + public VpnTestController(Solo solo) { + this.solo = solo; + } + + protected void turnVpnOndAndOff(String provider) { + clickVpnButton(); + turningEipOn(); + clickVpnButton(); + turningEipOff(); + } + + protected void clickVpnButton() { + solo.clickOnView(getVpnButton()); + } + + protected Button getVpnButton() { + return (Button) solo.getView(R.id.vpn_main_button); + } + + protected FabButton getVpnWholeIcon() { + return (FabButton) solo.getView(R.id.vpn_Status_Image); + } + + protected void turningEipOn() { + assertInProgress(); + int max_seconds_until_connected = 30; + + Condition condition = new Condition() { + @Override + public boolean isSatisfied() { + return iconConnected(); + } + }; + solo.waitForCondition(condition, max_seconds_until_connected * 1000); + sleepSeconds(2); + } + + private void assertInProgress() { + ProgressRingView a = (ProgressRingView) getVpnWholeIcon().findViewById(R.id.fabbutton_ring); + BaseTestDashboard.isShownWithinConfinesOfVisibleScreen(a); + } + + private boolean iconConnected() { + return getVpnInsideIcon().equals(getDrawable(R.drawable.ic_stat_vpn)); + } + + private boolean iconDisconnected() { + return getVpnInsideIcon().equals(getDrawable(R.drawable.ic_stat_vpn_offline)); + } + + private Drawable getDrawable(int resId) { + return solo.getCurrentActivity().getResources().getDrawable(resId); + } + + private Bitmap getVpnInsideIcon() { + CircleImageView a = (CircleImageView) getVpnWholeIcon().findViewById(R.id.fabbutton_circle); + a.setDrawingCacheEnabled(true); + return a.getDrawingCache(); + } + + protected void turningEipOff() { + okToBrowserWarning(); + sayOkToDisconnect(); + + int max_seconds_until_connected = 1; + + Condition condition = new Condition() { + @Override + public boolean isSatisfied() { + return iconDisconnected(); + } + }; + solo.waitForCondition(condition, max_seconds_until_connected * 1000); + sleepSeconds(2); + } + + private void okToBrowserWarning() { + solo.waitForDialogToOpen(); + clickYes(); + } + + private void clickYes() { + String yes = solo.getString(android.R.string.yes); + solo.clickOnText(yes); + } + + private void sayOkToDisconnect() throws IllegalStateException { + boolean disconnect_vpn_appeared = solo.waitForActivity(DisconnectVPN.class); + if(disconnect_vpn_appeared) + clickYes(); + else throw new IllegalStateException(); + } + + void sleepSeconds(int seconds) { + solo.sleep(seconds * 1000); + } +} -- cgit v1.2.3 From ff679b7f20700cec2c08cb8026c585b47df3612f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Fri, 1 May 2015 12:46:34 +0200 Subject: testOnFailed() And checks in controllers, so that if a button isn't shown, I throw a new IllegalStateException. This helps to trace the error. --- .../leap/bitmaskclient/test/VpnTestController.java | 75 ++++++++++++++++++---- 1 file changed, 63 insertions(+), 12 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java') 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); -- cgit v1.2.3 From fcc8c55139143092005ffa5b56df2f4320fd9ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Mon, 1 Jun 2015 10:18:33 +0200 Subject: Update robotium + increase wait times Sometimes, the emulator is so slow (I wish genymotion was open source...) that even though everything's going OK tests fail because they don't wait enough. --- .../java/se/leap/bitmaskclient/test/VpnTestController.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java') 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 40a9f656..25d81da1 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -52,20 +52,16 @@ public class VpnTestController { } protected FabButton getVpnWholeIcon() { - try { - View view = solo.getView(R.id.vpn_Status_Image); - if (view != null) - return (FabButton) view; - else - return null; - } catch (AssertionFailedError e) { + View view = solo.getView(R.id.vpn_Status_Image); + if (view != null) + return (FabButton) view; + else return null; - } } protected void turningEipOn() { assertInProgress(); - int max_seconds_until_connected = 30; + int max_seconds_until_connected = 120; Condition condition = new Condition() { @Override -- cgit v1.2.3