summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml10
-rw-r--r--assets/urls/bitmask demo.url3
-rw-r--r--assets/urls/bitmask.url3
-rw-r--r--tests/libs/android-support-v4.jarbin0 -> 627582 bytes
-rw-r--r--tests/src/se/leap/bitmaskclient/test/ConnectionManager.java33
-rw-r--r--tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java10
-rw-r--r--tests/src/se/leap/bitmaskclient/test/testDashboard.java75
7 files changed, 68 insertions, 66 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 815ddf87..6738a90c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -22,9 +22,13 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <!-- if you want to run the unit test for Dashboard you will need that you uncomment the following line -->
- <!-- <uses-permission android:name="android.permission.WRITE_SETTINGS" /> -->
-
+
+ <!-- if you want to run test, this permissions are needed. Gradle will get rid of them once we implement it. -->
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- <uses-permission android:name="com.android.vending.BILLING" /> -->
diff --git a/assets/urls/bitmask demo.url b/assets/urls/bitmask demo.url
new file mode 100644
index 00000000..1a412055
--- /dev/null
+++ b/assets/urls/bitmask demo.url
@@ -0,0 +1,3 @@
+{
+ "main_url" : "https://demo.bitmask.net/"
+}
diff --git a/assets/urls/bitmask.url b/assets/urls/bitmask.url
deleted file mode 100644
index f924301e..00000000
--- a/assets/urls/bitmask.url
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "main_url" : "https://bitmask.net/"
-} \ No newline at end of file
diff --git a/tests/libs/android-support-v4.jar b/tests/libs/android-support-v4.jar
new file mode 100644
index 00000000..96644edb
--- /dev/null
+++ b/tests/libs/android-support-v4.jar
Binary files differ
diff --git a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java
new file mode 100644
index 00000000..f1cbff19
--- /dev/null
+++ b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java
@@ -0,0 +1,33 @@
+package se.leap.bitmaskclient.test;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ConnectionManager {
+ static void setMobileDataEnabled(boolean enabled, Context context) {
+ final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ Method[] methods = conman.getClass().getMethods();
+ for (Method method : methods) {
+ if (method.getName().equals("setMobileDataEnabled")) {
+ method.setAccessible(true);
+ try {
+ method.invoke(conman, enabled);
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ static void setWifiEnabled(boolean enabled, Context context) {
+ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ wifiManager.setWifiEnabled(enabled);
+ }
+}
diff --git a/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java b/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java
index 55fd87ae..847d8cdd 100644
--- a/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java
+++ b/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java
@@ -1,15 +1,14 @@
package se.leap.bitmaskclient.test;
+import android.test.ActivityInstrumentationTestCase2;
+import android.widget.ListView;
+import com.jayway.android.robotium.solo.Solo;
import java.io.IOException;
-
import se.leap.bitmaskclient.AboutActivity;
import se.leap.bitmaskclient.ConfigurationWizard;
import se.leap.bitmaskclient.ProviderDetailFragment;
import se.leap.bitmaskclient.R;
-import android.test.ActivityInstrumentationTestCase2;
-import android.widget.ListView;
-
-import com.jayway.android.robotium.solo.Solo;
+import se.leap.bitmaskclient.test.ConnectionManager;
public class testConfigurationWizard extends ActivityInstrumentationTestCase2<ConfigurationWizard> {
@@ -24,6 +23,7 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2<Co
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
+ ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext());
}
@Override
diff --git a/tests/src/se/leap/bitmaskclient/test/testDashboard.java b/tests/src/se/leap/bitmaskclient/test/testDashboard.java
index b6c23084..269f1d18 100644
--- a/tests/src/se/leap/bitmaskclient/test/testDashboard.java
+++ b/tests/src/se/leap/bitmaskclient/test/testDashboard.java
@@ -1,8 +1,5 @@
package se.leap.bitmaskclient.test;
-import se.leap.bitmaskclient.ConfigurationWizard;
-import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.R;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -10,8 +7,11 @@ import android.content.IntentFilter;
import android.provider.Settings;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
-
import com.jayway.android.robotium.solo.Solo;
+import se.leap.bitmaskclient.ConfigurationWizard;
+import se.leap.bitmaskclient.Dashboard;
+import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.test.ConnectionManager;
public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
@@ -25,7 +25,7 @@ public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
- setAirplaneMode(false);
+ ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext());
}
@Override
@@ -39,30 +39,28 @@ public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
*/
public void testOnOffOpenVpn() {
solo.clickOnView(solo.getView(R.id.eipSwitch));
- if(!solo.waitForText("Initiating connection"))
+ if(!solo.waitForText(getActivity().getString(R.string.eip_status_start_pending)))
fail();
- if(!solo.waitForText("Authenticating"))
+ if(!solo.waitForText(getActivity().getString(R.string.state_auth)))
fail();
- if(!solo.waitForText("Connection Secure", 1, 30*1000))
+ if(!solo.waitForText(getActivity().getString(R.string.eip_state_connected), 1, 30*1000))
fail();
solo.clickOnView(solo.getView(R.id.eipSwitch));
- if(!solo.waitForText("Not running! Connection not secure"))
- fail();
- /* setAirplaneMode isn't working right now.
- setAirplaneMode(true);
- if(!solo.waitForLogMessage("Service state changed"))
- fail();
+ if(!solo.waitForText(getActivity().getString(R.string.eip_state_not_connected)))
+ fail();
+
+ ConnectionManager.setMobileDataEnabled(false, solo.getCurrentActivity().getApplicationContext());
solo.clickOnView(solo.getView(R.id.eipSwitch));
- if(!solo.waitForText("Initiating connection"))
+ if(!solo.waitForText(getActivity().getString(R.string.eip_status_start_pending)))
fail();
- if(!solo.waitForText("Waiting for usable network"))
+ if(!solo.waitForText(getActivity().getString(R.string.state_nonetwork)))
fail();
- */
+
}
- public void testLogInAndOut() {
+ public void testLogInAndOut() {
long miliseconds_to_log_in = 40 * 1000;
solo.clickOnActionBarItem(R.id.login_button);
solo.enterText(0, "parmegvtest1");
@@ -70,7 +68,7 @@ public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
solo.clickOnText("Log In");
solo.waitForDialogToClose();
solo.waitForDialogToClose(miliseconds_to_log_in);
- if(!solo.waitForText("Your own cert has been correctly downloaded."))
+ if(!solo.waitForText(getActivity().getString(R.string.succesful_authentication_message)))
fail();
solo.clickOnActionBarItem(R.string.logout_button);
@@ -78,52 +76,19 @@ public class testDashboard extends ActivityInstrumentationTestCase2<Dashboard> {
fail();
}
- public void testShowSettings() {
- solo.clickOnActionBarItem(R.id.menu_settings);
- }
-
public void testShowAbout() {
- solo.clickOnMenuItem("About");
+ solo.clickOnMenuItem(getActivity().getString(R.string.about));
solo.waitForText(getActivity().getString(R.string.repository_url_text));
solo.goBack();
- solo.clickOnMenuItem("About");
+ solo.clickOnMenuItem(getActivity().getString(R.string.about));
solo.waitForText(getActivity().getString(R.string.repository_url_text));
solo.goBack();
}
public void testSwitchProvider() {
- solo.clickOnMenuItem("Switch provider");
- solo.waitForActivity(ConfigurationWizard.class);
- solo.goBack();
-
- solo.clickOnMenuItem("Switch provider");
+ solo.clickOnMenuItem(getActivity().getString(R.string.switch_provider_menu_option));
solo.waitForActivity(ConfigurationWizard.class);
solo.goBack();
}
-
- 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);
- }
}