diff options
Diffstat (limited to 'app/src/androidTest')
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java | 54 | ||||
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java | 5 |
2 files changed, 49 insertions, 10 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java index 4817adbb..0a76638f 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java @@ -19,10 +19,12 @@ package se.leap.bitmaskclient.test; import android.app.*; import android.content.*; import android.test.*; -import android.test.suitebuilder.annotation.*; import org.json.*; +import java.io.IOException; +import java.util.Arrays; + import se.leap.bitmaskclient.*; import se.leap.bitmaskclient.eip.*; @@ -42,14 +44,13 @@ public class TestGatewaysManager extends InstrumentationTestCase { @Override protected void setUp() throws Exception { + super.setUp(); context = getInstrumentation().getContext(); assets = new FromAssets(context); mockGatewaysManager(); mockRealGateway(); - super.setUp(); } - @MediumTest public void testFromEipServiceJson() { gateways_manager.fromEipServiceJson(eip_definition); assertEquals(2, gateways_manager.size()); @@ -57,13 +58,31 @@ public class TestGatewaysManager extends InstrumentationTestCase { assertEquals(2, gateways_manager.size()); } - @SmallTest + public void testOrderOfGateways_UDP_TCP() { + String[] protocolsInOrder = {"udp", "tcp"}; + manipulateSupportedProtocols(protocolsInOrder); + gateways_manager.fromEipServiceJson(eip_definition); + gateways_manager.addFromString(gateway.toString()); + assertTrue(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]")); + assertFalse(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]")); + } + + public void testOrderOfGateways_TCP_UDP() { + String[] protocolsInOrder = {"tcp", "udp"}; + manipulateSupportedProtocols(protocolsInOrder); + gateways_manager.fromEipServiceJson(eip_definition); + gateways_manager.addFromString(gateway.toString()); + assertFalse(gateways_manager.select().toString().contains("[\"udp\",\"tcp\"]")); + assertTrue(gateways_manager.select().toString().contains("[\"tcp\",\"udp\"]")); + } + public void testAddFromString() { gateways_manager.addFromString(""); + assertEquals(0, gateways_manager.size()); gateways_manager.addFromString(gateway.toString()); + assertEquals(1, gateways_manager.size()); } - @MediumTest public void testRemoveDuplicate() { gateways_manager.addFromString(gateway.toString()); assertEquals(1, gateways_manager.size()); @@ -73,7 +92,6 @@ public class TestGatewaysManager extends InstrumentationTestCase { assertEquals(1, gateways_manager.size()); } - @MediumTest public void testToString() { assertEquals("[]", gateways_manager.toString()); @@ -81,7 +99,6 @@ public class TestGatewaysManager extends InstrumentationTestCase { assertEquals("[" + gateway.toString() + "]", gateways_manager.toString()); } - @SmallTest public void testIsEmpty() { assertTrue(gateways_manager.isEmpty()); gateways_manager.addFromString(""); @@ -107,6 +124,29 @@ public class TestGatewaysManager extends InstrumentationTestCase { } } + private void manipulateSupportedProtocols(String[] protocols) { + try { + eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE)); + JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE)); + JSONArray protocolJsonArray = new JSONArray(Arrays.asList(protocols)); + JSONArray gateways = eip_definition.getJSONArray("gateways"); + for (int i = 0; i < gateways.length(); i++) { + JSONObject gatewayJson = gateways.getJSONObject(i); + JSONObject capabilitiesJson = gatewayJson.getJSONObject("capabilities"); + capabilitiesJson.put("protocols", protocolJsonArray); + gatewayJson.put("protocols", protocolJsonArray); + } + this.gateway = new Gateway(eip_definition, secrets, gateways.getJSONObject(0)); + } catch (JSONException e) { + e.printStackTrace(); + assertFalse(true); + } catch (IOException e) { + e.printStackTrace(); + assertFalse(true); + } + + } + private void mockArtificialGateway() { try { eip_definition = new JSONObject(assets.toString(TestConstants.EIP_DEFINITION_FILE)); 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 d339ab26..93b1da47 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -33,7 +33,7 @@ public class VpnTestController { Button button = getVpnButton(); if(!isVpnButton(button)) throw new IllegalStateException(); - solo.clickOnView(button); + solo.clickOnButton(String.valueOf(button.getText())); } protected Button getVpnButton() { @@ -93,8 +93,6 @@ public class VpnTestController { protected void turningEipOff() { okToBrowserWarning(); - sayOkToDisconnect(); - int max_seconds_until_connected = 120; Condition condition = new Condition() { @@ -123,6 +121,7 @@ public class VpnTestController { solo.clickOnButton(disconnect); } + @SuppressWarnings("unused") private void sayOkToDisconnect() throws IllegalStateException { boolean disconnect_vpn_appeared = solo.waitForActivity(DisconnectVPN.class); if(disconnect_vpn_appeared){ |