summaryrefslogtreecommitdiff
path: root/app/src/androidTest/legacy/VpnTestController.java
diff options
context:
space:
mode:
authorfupduck <fupduck@riseup.net>2018-02-06 05:53:09 -0800
committerfupduck <fupduck@riseup.net>2018-02-06 05:53:09 -0800
commitedd34192484f4eb618fdcc2a68b18168c155d63c (patch)
treed884f63e74911d2ea2cf7bc864414a623e15a2b3 /app/src/androidTest/legacy/VpnTestController.java
parentc0848bac7ac44f4b09f9e5d66ab71f079cb0f514 (diff)
parentd2d61a16fd2a3ea0fd42073de98d1311b184444d (diff)
Merge branch '#8832_update_ics-openvpn' into '0.9.8'
#8832 update ics openvpn See merge request leap/bitmask_android!33
Diffstat (limited to 'app/src/androidTest/legacy/VpnTestController.java')
-rw-r--r--app/src/androidTest/legacy/VpnTestController.java137
1 files changed, 137 insertions, 0 deletions
diff --git a/app/src/androidTest/legacy/VpnTestController.java b/app/src/androidTest/legacy/VpnTestController.java
new file mode 100644
index 00000000..4c6a6370
--- /dev/null
+++ b/app/src/androidTest/legacy/VpnTestController.java
@@ -0,0 +1,137 @@
+package se.leap.bitmaskclient.test;
+
+import android.view.View;
+import android.widget.Button;
+
+import com.robotium.solo.Condition;
+import com.robotium.solo.Solo;
+
+import de.blinkt.openvpn.activities.DisconnectVPN;
+import mbanje.kurt.fabbutton.ProgressRingView;
+import se.leap.bitmaskclient.Dashboard;
+import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.userstatus.FabButton;
+
+import static junit.framework.Assert.assertTrue;
+
+public class VpnTestController {
+
+ private final Solo solo;
+
+ public VpnTestController(Solo solo) {
+ this.solo = solo;
+ }
+
+ protected void turnVpnOnAndOff() {
+ clickVpnButton();
+ turningEipOn();
+ clickVpnButton();
+ turningEipOff();
+ }
+
+ protected void clickVpnButton() throws IllegalStateException {
+ Button button = getVpnButton();
+ if(!isVpnButton(button))
+ throw new IllegalStateException();
+ solo.clickOnButton(String.valueOf(button.getText()));
+ }
+
+ protected Button getVpnButton() {
+ View button_view = solo.getView(R.id.vpn_main_button);
+ if (button_view != null)
+ return (Button) button_view;
+ else
+ return null;
+ }
+
+ private boolean isVpnButton(Button button) {
+ return button != null && !button.getText().toString().isEmpty();
+ }
+
+ protected FabButton getVpnWholeIcon() {
+ assertTrue(solo.waitForActivity(Dashboard.class, 5 * 1000));
+
+ 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();
+ }
+ };
+ assertTrue("condition iconShowsConnected not fulfilled within " + max_seconds_until_connected + " seconds." , 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());
+ BaseTestDashboardFragment.isShownWithinConfinesOfVisibleScreen(a);
+ }
+
+ private boolean iconShowsConnected() {
+ View vpnIconView = getVpnWholeIcon();
+ return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn);
+ }
+
+ protected boolean iconShowsDisconnected() {
+ View vpnIconView = getVpnWholeIcon();
+ return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn_offline);
+ }
+
+ protected void turningEipOff() {
+ okToBrowserWarning();
+ int max_seconds_until_connected = 120;
+
+ Condition condition = new Condition() {
+ @Override
+ public boolean isSatisfied() {
+ return iconShowsDisconnected();
+ }
+ };
+ assertTrue(solo.waitForCondition(condition, max_seconds_until_connected * 1000));
+ sleepSeconds(2);
+ }
+
+ private void okToBrowserWarning() {
+ assertTrue(solo.waitForDialogToOpen());
+ clickYes();
+ solo.waitForDialogToClose();
+ }
+
+ private void clickYes() {
+ String yes = solo.getString(android.R.string.yes);
+ solo.clickOnButton(yes);
+ }
+
+ private void clickDisconnect() {
+ String disconnect = solo.getString(R.string.cancel_connection);
+ solo.clickOnButton(disconnect);
+ }
+
+ @SuppressWarnings("unused")
+ private void sayOkToDisconnect() throws IllegalStateException {
+ boolean disconnect_vpn_appeared = solo.waitForActivity(DisconnectVPN.class);
+ if(disconnect_vpn_appeared){
+ clickDisconnect();
+ solo.waitForDialogToClose();
+ }
+ else throw new IllegalStateException();
+ }
+
+ void sleepSeconds(int seconds) {
+ solo.sleep(seconds * 1000);
+ }
+}