summaryrefslogtreecommitdiff
path: root/tests/src/se/leap/bitmaskclient/test/testDashboard.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2013-11-22 11:57:00 +0100
committerParménides GV <parmegv@sdf.org>2013-11-22 11:57:00 +0100
commit836cf5c9a0e2d33f205c3c353e1300ee1ad03b5b (patch)
tree69034f031f4ef98cc48e4d3cc0e24775d34d4aca /tests/src/se/leap/bitmaskclient/test/testDashboard.java
parentecd01db4ca5c0000d671e888ebdf97c3fdbd51cc (diff)
Rebased onto 0.2.2
Some tests aren't passed, due to changes and UI (for example, log in dialog is no longer a menu item but an action bar item, and robotium can't find it).
Diffstat (limited to 'tests/src/se/leap/bitmaskclient/test/testDashboard.java')
-rw-r--r--tests/src/se/leap/bitmaskclient/test/testDashboard.java139
1 files changed, 139 insertions, 0 deletions
diff --git a/tests/src/se/leap/bitmaskclient/test/testDashboard.java b/tests/src/se/leap/bitmaskclient/test/testDashboard.java
new file mode 100644
index 00000000..fb9a3ba7
--- /dev/null
+++ b/tests/src/se/leap/bitmaskclient/test/testDashboard.java
@@ -0,0 +1,139 @@
+package se.leap.bitmaskclient.test;
+
+import se.leap.bitmaskclient.ConfigurationWizard;
+import se.leap.bitmaskclient.Dashboard;
+import se.leap.bitmaskclient.R;
+import se.leap.openvpn.MainActivity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.provider.Settings;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import com.jayway.android.robotium.solo.Solo;
+
+public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
+
+ private Solo solo;
+
+ public testDashboard() {
+ super(Dashboard.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ solo = new Solo(getInstrumentation(), getActivity());
+ setAirplaneMode(false);
+ }
+
+ @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() {
+ solo.clickOnView(solo.getView(R.id.eipSwitch));
+ if(!solo.waitForText("Initiating connection"))
+ fail();
+ if(!solo.waitForText("Authenticating"))
+ fail();
+ if(!solo.waitForText("Connection Secure", 1, 30*1000))
+ fail();
+
+ solo.clickOnView(solo.getView(R.id.eipSwitch));
+ if(!solo.waitForText("Not running! Connection not secure"))
+ fail();
+
+ setAirplaneMode(true);
+ if(!solo.waitForLogMessage("Service state changed"))
+ fail();
+
+ solo.clickOnView(solo.getView(R.id.eipSwitch));
+ if(!solo.waitForText("Initiating connection"))
+ fail();
+ if(!solo.waitForText("Waiting for usable network"))
+ fail();
+ }
+
+ public void testLogInAndOut() {
+ long miliseconds_to_log_in = 40 * 1000;
+ solo.clickOnMenuItem("Log In");
+ solo.enterText(0, "parmegv");
+ solo.enterText(1, " S_Zw3'-");
+ solo.clickOnText("Log In");
+ solo.waitForDialogToClose();
+ solo.waitForDialogToClose(miliseconds_to_log_in);
+ if(!solo.waitForText("Your own cert has been correctly downloaded."))
+ fail();
+
+ solo.clickOnMenuItem("Log Out");
+ if(!solo.waitForDialogToClose())
+ fail();
+ }
+
+ public void testShowSettings() {
+ solo.clickOnMenuItem("Settings");
+ }
+
+ public void testShowAbout() {
+ solo.clickOnMenuItem("About");
+ solo.waitForText("Source code and issue tracker available at https://github.com/leapcode/leap_android");
+ solo.goBack();
+
+ solo.clickOnMenuItem("About");
+ solo.waitForText("Source code and issue tracker available at https://github.com/leapcode/leap_android");
+ solo.goBack();
+ }
+
+ public void testSwitchProvider() {
+ solo.clickOnMenuItem("Switch provider");
+ solo.waitForActivity(ConfigurationWizard.class);
+ solo.goBack();
+
+ solo.clickOnMenuItem("Switch provider");
+ solo.waitForActivity(ConfigurationWizard.class);
+ solo.goBack();
+ }
+
+ public void testIcsOpenVpnInterface() {
+ solo.clickOnMenuItem("ICS OpenVPN Interface");
+ solo.waitForActivity(MainActivity.class);
+
+ solo.goBack();
+
+ solo.clickOnMenuItem("ICS OpenVPN Interface");
+ solo.waitForActivity(MainActivity.class);
+ }
+
+ private void setAirplaneMode(boolean airplane_mode) {
+ Context context = solo.getCurrentActivity().getApplicationContext();
+ boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
+ Log.d("AirplaneMode", "Service state: " + isEnabled);
+ Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, airplane_mode ? 1 : 0);
+
+ // Post an intent to reload
+ Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+ intent.putExtra("state", airplane_mode);
+ Log.d("AirplaneMode", "New Service state: " + !isEnabled);
+ solo.getCurrentActivity().sendBroadcast(intent);
+
+ IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE");
+
+ BroadcastReceiver receiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
+ Log.d("AirplaneMode", "Service state changed: " + isEnabled);
+ }
+ };
+
+ context.registerReceiver(receiver, intentFilter);
+ }
+}