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. --- .../test/testDashboardIntegration.java | 164 ++------------------- 1 file changed, 10 insertions(+), 154 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java') 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 @@ -16,138 +16,14 @@ 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() { -- cgit v1.2.3