diff options
author | Parménides GV <parmegv@sdf.org> | 2015-06-01 10:50:02 +0200 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2015-06-01 10:50:02 +0200 |
commit | 21aa11e5e04ffef3111010140cd7336fe181de39 (patch) | |
tree | 6af11a281ce9fd4c8e70863d10093d910751bf66 /app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java | |
parent | e5e9ac6e43b9cdec0f362711bb33747ab73fc297 (diff) | |
parent | 03973cf7f9b0f8635b6835c548b192eb53a2be35 (diff) |
Merge branch 'feature/Look-for-a-better-solution-to-the-VPN-slider-#6863' into develop
Diffstat (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java')
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java | 161 |
1 files changed, 161 insertions, 0 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 new file mode 100644 index 00000000..25d81da1 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -0,0 +1,161 @@ +package se.leap.bitmaskclient.test; + +import android.graphics.*; +import android.graphics.drawable.*; +import android.view.*; +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; + +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() throws IllegalStateException { + Button button = getVpnButton(); + if(!isVpnButton(button)) + throw new IllegalStateException(); + solo.clickOnView(button); + } + + protected Button getVpnButton() { + 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() { + 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 = 120; + + Condition condition = new Condition() { + @Override + public boolean isSatisfied() { + return iconShowsConnected(); + } + }; + solo.waitForCondition(condition, max_seconds_until_connected * 1000); + sleepSeconds(2); + } + + private void assertInProgress() { + 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 iconShowsConnected() { + return iconEquals(iconConnectedDrawable()); + } + + 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) { + return solo.getCurrentActivity().getResources().getDrawable(resId); + } + + private Bitmap getVpnInsideIcon() { + 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(); + } + + protected void turningEipOff() { + okToBrowserWarning(); + sayOkToDisconnect(); + + int max_seconds_until_connected = 1; + + Condition condition = new Condition() { + @Override + public boolean isSatisfied() { + return iconShowsDisconnected(); + } + }; + 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); + } +} |