diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java | 80 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/VpnFragment.java | 4 |
2 files changed, 27 insertions, 57 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 index 39ab37dd..9dcb4da1 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -1,18 +1,18 @@ package se.leap.bitmaskclient.test; -import android.graphics.*; -import android.graphics.drawable.*; -import android.view.*; -import android.widget.*; +import android.view.View; +import android.widget.Button; -import com.robotium.solo.*; +import com.robotium.solo.Condition; +import com.robotium.solo.Solo; -import junit.framework.AssertionFailedError; - -import de.blinkt.openvpn.activities.*; -import mbanje.kurt.fabbutton.*; +import de.blinkt.openvpn.activities.DisconnectVPN; +import mbanje.kurt.fabbutton.FabButton; +import mbanje.kurt.fabbutton.ProgressRingView; import se.leap.bitmaskclient.R; +import static junit.framework.Assert.assertTrue; + public class VpnTestController { private final Solo solo; @@ -21,7 +21,7 @@ public class VpnTestController { this.solo = solo; } - protected void turnVpnOndAndOff(String provider) { + protected void turnVpnOndAndOff() { clickVpnButton(); turningEipOn(); clickVpnButton(); @@ -36,19 +36,15 @@ public class VpnTestController { } 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()); - } + 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.getText().toString().isEmpty(); + return button != null && !button.getText().toString().isEmpty(); } protected FabButton getVpnWholeIcon() { @@ -69,7 +65,7 @@ public class VpnTestController { return iconShowsConnected(); } }; - solo.waitForCondition(condition, max_seconds_until_connected * 1000); + assertTrue("condition iconShowsConnected not fulfilled within " + max_seconds_until_connected * 1000 + " seconds." , solo.waitForCondition(condition, max_seconds_until_connected * 1000)); sleepSeconds(2); } @@ -83,43 +79,13 @@ public class VpnTestController { } private boolean iconShowsConnected() { - return iconEquals(iconConnectedDrawable()); + View vpnIconView = getVpnWholeIcon(); + return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn); } 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(); + View vpnIconView = getVpnWholeIcon(); + return vpnIconView.getTag().equals(R.drawable.ic_stat_vpn_offline); } protected void turningEipOff() { @@ -134,12 +100,12 @@ public class VpnTestController { return iconShowsDisconnected(); } }; - solo.waitForCondition(condition, max_seconds_until_connected * 1000); + assertTrue(solo.waitForCondition(condition, max_seconds_until_connected * 1000)); sleepSeconds(2); } private void okToBrowserWarning() { - solo.waitForDialogToOpen(); + assertTrue(solo.waitForDialogToOpen()); clickYes(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index 9210c6ec..6ffeacc1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -49,6 +49,7 @@ public class VpnFragment extends Fragment implements Observer { private static EipStatus eip_status; private boolean wants_to_connect; + //FIXME: replace with onAttach(Context context) public void onAttach(Activity activity) { super.onAttach(activity); @@ -254,12 +255,15 @@ public class VpnFragment extends Fragment implements Observer { if(eip_status.isConnecting()) { vpn_status_image.showProgress(true); vpn_status_image.setIcon(R.drawable.ic_stat_vpn_empty_halo, R.drawable.ic_stat_vpn_empty_halo); + vpn_status_image.setTag(R.drawable.ic_stat_vpn_empty_halo); } else { vpn_status_image.showProgress(false); vpn_status_image.setIcon(R.drawable.ic_stat_vpn, R.drawable.ic_stat_vpn); + vpn_status_image.setTag(R.drawable.ic_stat_vpn); } } else { vpn_status_image.setIcon(R.drawable.ic_stat_vpn_offline, R.drawable.ic_stat_vpn_offline); + vpn_status_image.setTag(R.drawable.ic_stat_vpn_offline); vpn_status_image.showProgress(false); } } |