summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java4
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java6
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java114
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java164
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java59
5 files changed, 189 insertions, 158 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java
index 263d83d5..a6519175 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboard.java
@@ -14,6 +14,7 @@ public abstract class BaseTestDashboard extends ActivityInstrumentationTestCase2
Solo solo;
Context context;
UserStatusTestController user_status_controller;
+ VpnTestController vpn_controller;
public BaseTestDashboard() { super(Dashboard.class); }
@@ -23,6 +24,7 @@ public abstract class BaseTestDashboard extends ActivityInstrumentationTestCase2
context = getInstrumentation().getContext();
solo = new Solo(getInstrumentation(), getActivity());
user_status_controller = new UserStatusTestController(solo);
+ vpn_controller = new VpnTestController(solo);
ConnectionManager.setMobileDataEnabled(true, context);
solo.unlockScreen();
if (solo.searchText(solo.getString(R.string.configuration_wizard_title)))
@@ -51,7 +53,7 @@ public abstract class BaseTestDashboard extends ActivityInstrumentationTestCase2
assertTrue(solo.waitForActivity(Dashboard.class, 5000));
}
- boolean isShownWithinConfinesOfVisibleScreen(View view) {
+ static boolean isShownWithinConfinesOfVisibleScreen(View view) {
Rect scrollBounds = new Rect();
view.getHitRect(scrollBounds);
return view.getLocalVisibleRect(scrollBounds);
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java
index a8b6bfe8..dea81d73 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java
@@ -1,10 +1,10 @@
package se.leap.bitmaskclient.test;
-import android.view.View;
+import android.view.*;
-import com.robotium.solo.Solo;
+import com.robotium.solo.*;
-import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.*;
public class UserStatusTestController {
private final Solo solo;
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);
+ }
+}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java
index 085e3c6b..fea6bf77 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java
@@ -17,137 +17,13 @@ import se.leap.bitmaskclient.*;
public class testDashboardIntegration extends BaseTestDashboard {
@Override
- protected void setUp() throws Exception {
- super.setUp();
- Screenshot.initialize(solo);
- }
-
- @Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
}
- /**
- * This test will fail if Android does not trust VPN connection.
- * I cannot automate that dialog.
- */
- public void testOnOffOpenVpn() {
- Screenshot.take("Initial UI");
- clickVpnButton();
- Screenshot.setTimeToSleep(5);
- Screenshot.takeWithSleep("Turning VPN on");
- turningEipOn();
- Screenshot.setTimeToSleep(0.5);
- Screenshot.takeWithSleep("VPN turned on");
-
- clickVpnButton();
- turningEipOff();
- Screenshot.take("VPN turned off");
-
- clickVpnButton();
- turningEipOn();
-
- clickVpnButton();
- turningEipOff();
-
- /*clickVpnButton();;
- turningEipOn();
-
- turnNetworkOff();
- restartAdbServer(); // This doesn't work
- */
-
- }
-
- private void clickVpnButton() {
- solo.clickOnView(getVpnButton());
- }
-
- private Button getVpnButton() {
- return (Button) solo.getView(R.id.vpn_main_button);
- }
-
- private FabButton getVpnWholeIcon() {
- return (FabButton) solo.getView(R.id.vpn_Status_Image);
- }
-
- private 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);
- assertTrue(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 getActivity().getResources().getDrawable(resId);
- }
-
- private Bitmap getVpnInsideIcon() {
- CircleImageView a = (CircleImageView) getVpnWholeIcon().findViewById(R.id.fabbutton_circle);
- a.setDrawingCacheEnabled(true);
- return a.getDrawingCache();
- }
-
- private 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() {
- assertTrue(solo.waitForActivity(DisconnectVPN.class));
- clickYes();
- }
-
- private void turnNetworkOff() {
- ConnectionManager.setMobileDataEnabled(false, context);
- if (!solo.waitForText(getActivity().getString(R.string.eip_state_not_connected), 1, 15 * 1000))
- fail();
- }
-
- private void restartAdbServer() {
- runAdbCommand("kill-server");
- runAdbCommand("start-server");
+ public void testSwitchProvider() {
+ tapSwitchProvider();
+ solo.goBack();
}
public void testShowAbout() {
@@ -168,35 +44,15 @@ public class testDashboardIntegration extends BaseTestDashboard {
solo.clickOnMenuItem(menu_item);
}
- public void testSwitchProvider() {
- tapSwitchProvider();
- solo.goBack();
- }
-
- public void testVpnEveryProvider() {
- changeAndTestProvider("demo.bitmask.net");
- changeAndTestProvider("riseup.net");
- changeAndTestProvider("calyx.net");
- }
-
- private void changeAndTestProvider(String provider) {
- changeProvider(provider);
- sleepSeconds(1);
- clickVpnButton();
- turningEipOn();
- clickVpnButton();
- turningEipOff();
- }
-
- private void sleepSeconds(int seconds) {
- solo.sleep(seconds * 1000);
+ private void turnNetworkOff() {
+ ConnectionManager.setMobileDataEnabled(false, context);
+ if (!solo.waitForText(getActivity().getString(R.string.eip_state_not_connected), 1, 15 * 1000))
+ fail();
}
- public void testVpnIconIsDisplayed() {
- assertTrue(isShownWithinConfinesOfVisibleScreen(getVpnWholeIcon()));
- }
- public void testVpnButtonIsDisplayed() {
- assertTrue(isShownWithinConfinesOfVisibleScreen(getVpnButton()));
+ private void restartAdbServer() {
+ runAdbCommand("kill-server");
+ runAdbCommand("start-server");
}
/*public void testReboot() {
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java
new file mode 100644
index 00000000..9926dbef
--- /dev/null
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnFragment.java
@@ -0,0 +1,59 @@
+package se.leap.bitmaskclient.test;
+
+public class testVpnFragment extends BaseTestDashboard {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Screenshot.initialize(solo);
+ }
+
+ /**
+ * This test will fail if Android does not trust VPN connection.
+ * I cannot automate that dialog.
+ */
+ public void testOnOffOpenVpn() {
+ Screenshot.take("Initial UI");
+ vpn_controller.clickVpnButton();
+ Screenshot.setTimeToSleep(5);
+ Screenshot.takeWithSleep("Turning VPN on");
+ vpn_controller.turningEipOn();
+ Screenshot.setTimeToSleep(0.5);
+ Screenshot.takeWithSleep("VPN turned on");
+
+ vpn_controller.clickVpnButton();
+ vpn_controller.turningEipOff();
+ Screenshot.take("VPN turned off");
+
+ vpn_controller.clickVpnButton();
+ vpn_controller.turningEipOn();
+
+ vpn_controller.clickVpnButton();
+ vpn_controller.turningEipOff();
+
+ /*clickVpnButton();;
+ turningEipOn();
+
+ turnNetworkOff();
+ restartAdbServer(); // This doesn't work
+ */
+
+ }
+
+ public void testVpnEveryProvider() {
+ String[] providers = {"demo.bitmask.net", "riseup.net", "calyx.net"};
+ for(String provider : providers) {
+ changeProvider(provider);
+ vpn_controller.sleepSeconds(1);
+ vpn_controller.turnVpnOndAndOff(provider);
+ vpn_controller.sleepSeconds(1);
+ }
+ }
+
+ public void testVpnIconIsDisplayed() {
+ assertTrue(isShownWithinConfinesOfVisibleScreen(vpn_controller.getVpnWholeIcon()));
+ }
+ public void testVpnButtonIsDisplayed() {
+ assertTrue(isShownWithinConfinesOfVisibleScreen(vpn_controller.getVpnButton()));
+ }
+}