summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-01-15 15:24:52 +0100
committerParménides GV <parmegv@sdf.org>2015-01-19 16:00:06 +0100
commit250b56762857f2e52626236d3716459786ce126d (patch)
tree12aaee0692ed2ecd0aa213d379617bbe4fa98f48
parent744272dd1d43913c8112d1dedcb0b5a9023c491e (diff)
More tests, sometimes they don't pass sometimes do
testIsValid depends on the speed of Runtime's exec: sometimes it's quick and passes (because it changes the date correctly) and sometimes is not. A waitFor doesn't fix the issue, it waits forever.
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java6
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java106
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java194
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java22
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java3
-rw-r--r--app/src/main/res/layout/provider_detail_fragment.xml1
-rw-r--r--app/src/main/res/values/strings.xml2
8 files changed, 188 insertions, 148 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java
index f1cbff19..e67dd820 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java
@@ -17,12 +17,10 @@ public class ConnectionManager {
method.setAccessible(true);
try {
method.invoke(conman, enabled);
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
- }
+ }
}
}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java
index 78ce1c81..755f83a7 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testConfigurationWizard.java
@@ -1,14 +1,10 @@
package se.leap.bitmaskclient.test;
-import android.test.ActivityInstrumentationTestCase2;
-import android.widget.ListView;
-import com.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 se.leap.bitmaskclient.test.ConnectionManager;
+import android.test.*;
+import android.widget.*;
+import com.robotium.solo.*;
+import java.io.*;
+import se.leap.bitmaskclient.*;
public class testConfigurationWizard extends ActivityInstrumentationTestCase2<ConfigurationWizard> {
@@ -19,10 +15,15 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2<Co
super(ConfigurationWizard.class);
}
+ public testConfigurationWizard(Solo solo) {
+ super(ConfigurationWizard.class);
+ this.solo = solo;
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
- solo = new Solo(getInstrumentation(), getActivity());
+ solo = new Solo(getInstrumentation(), getActivity());
ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext());
}
@@ -31,35 +32,76 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2<Co
solo.finishOpenedActivities();
}
- public void testListProviders() throws IOException {
+ public void testListProviders() {
assertEquals(solo.getCurrentViews(ListView.class).size(), 1);
-
- int number_of_available_providers = solo.getCurrentViews(ListView.class).get(0).getCount();
-
- assertEquals("Number of available providers differ", solo.getCurrentActivity().getAssets().list("urls").length + added_providers, number_of_available_providers);
+
+ assertEquals("Number of available providers differ", predefinedProviders() + added_providers, shownProviders());
}
+
+ private int shownProviders() {
+ return solo.getCurrentViews(ListView.class).get(0).getCount();
+ }
+
+ private int predefinedProviders() {
+ int predefined_providers = 0;
+ try {
+ predefined_providers = solo.getCurrentActivity().getAssets().list("urls").length;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return predefined_providers;
+ }
+
+ return predefined_providers;
+ }
public void testSelectProvider() {
- solo.clickOnText("bitmask");
- assertTrue("Provider details dialog did not appear", solo.waitForFragmentByTag(ProviderDetailFragment.TAG, 60*1000));
+ selectProvider("demo.bitmask.net");
}
-
- public void testAddNewProvider() {
- solo.clickOnActionBarItem(R.id.new_provider);
- solo.enterText(0, "calyx.net");
- solo.clickOnCheckBox(0);
- solo.clickOnText(solo.getString(R.string.save));
- //added_providers = added_providers+1;
- assertTrue("Provider details dialog did not appear", solo.waitForFragmentByTag(ProviderDetailFragment.TAG, 60*1000));
- solo.goBack();
+
+ private void selectProvider(String provider) {
+ solo.clickOnText(provider);
+ waitForProviderDetails();
+ }
+
+ private void waitForProviderDetails() {
+ String text = solo.getString(R.string.provider_details_fragment_title);
+ assertTrue("Provider details dialog did not appear", solo.waitForText(text));
+ }
+
+ public void testAddNewProvider() {
+ addProvider("calyx.net");
}
+
+ private void addProvider(String url) {
+ boolean is_new_provider = !solo.searchText(url);
+ if(is_new_provider)
+ added_providers = added_providers+1;
+ solo.clickOnActionBarItem(R.id.new_provider);
+ solo.enterText(0, url);
+ solo.clickOnCheckBox(0);
+ solo.clickOnText(solo.getString(R.string.save));
+ waitForProviderDetails();
+ solo.goBack();
+ }
public void testShowAbout() {
- solo.clickOnMenuItem(solo.getString(R.string.about));
- assertTrue("Provider details dialog did not appear", solo.waitForActivity(AboutActivity.class));
- }
-
- public void testShowSettings() {
- //TODO We still don't have the settings button
+ showAbout();
}
+
+ private void showAbout() {
+ String text = solo.getString(R.string.about);
+ solo.clickOnMenuItem(text);
+ assertTrue("Provider details dialog did not appear", solo.waitForActivity(AboutActivity.class));
+ }
+
+ protected void toDashboard(String provider) {
+ selectProvider(provider);
+ useAnonymously();
+ }
+
+ private void useAnonymously() {
+ String text = solo.getString(R.string.use_anonymously_button);
+ solo.clickOnText(text);
+ solo.waitForText(solo.getString(R.string.title_activity_dashboard));
+ }
}
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 0c7db284..91b93d42 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testDashboardIntegration.java
@@ -1,28 +1,19 @@
package se.leap.bitmaskclient.test;
-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.robotium.solo.Solo;
+import android.test.*;
+import com.robotium.solo.*;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.Scanner;
-import de.blinkt.openvpn.activities.DisconnectVPN;
-import se.leap.bitmaskclient.ConfigurationWizard;
-import se.leap.bitmaskclient.Dashboard;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.test.ConnectionManager;
+import de.blinkt.openvpn.activities.*;
+import se.leap.bitmaskclient.*;
public class testDashboardIntegration extends ActivityInstrumentationTestCase2<Dashboard> {
private Solo solo;
-
+ private Context context;
+
public testDashboardIntegration() {
super(Dashboard.class);
}
@@ -30,8 +21,12 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D
@Override
protected void setUp() throws Exception {
super.setUp();
+ context = getInstrumentation().getContext();
solo = new Solo(getInstrumentation(), getActivity());
- ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext());
+ ConnectionManager.setMobileDataEnabled(true, context);
+ solo.unlockScreen();
+ if(solo.searchText(solo.getString(R.string.configuration_wizard_title)))
+ new testConfigurationWizard(solo).toDashboard("demo.bitmask.net");
}
@Override
@@ -45,121 +40,128 @@ public class testDashboardIntegration extends ActivityInstrumentationTestCase2<D
*/
public void testOnOffOpenVpn() {
solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOn();
+ turningEipOn();
solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOff();
+ turningEipOff();
solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOn();
+ turningEipOn();
solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOff();
-
- solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOn();
-
- solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOff();
+ turningEipOff();
- solo.clickOnView(solo.getView(R.id.eipSwitch));
- testEipTurningOn();
+ /*solo.clickOnView(solo.getView(R.id.eipSwitch));
+ turningEipOn();
- testEipIsOnNoNetwork();
+ turnNetworkOff();
+ restartAdbServer(); // This doesn't work
+ */
}
- private void testEipTurningOn() {
- if(!solo.waitForText(getActivity().getString(R.string.state_auth)))
- fail();
- if(!solo.waitForText(getActivity().getString(R.string.eip_state_connected), 1, 30*1000))
- fail();
- solo.sleep(2*1000);
+ private void turningEipOn() {
+ assertAuthenticating();
+ int max_seconds_until_connected = 30;
+ assertConnected(max_seconds_until_connected);
+ solo.sleep(2*1000);
+ }
+
+ private void assertAuthenticating() {
+ String message = solo.getString(R.string.state_auth);
+ assertTrue(solo.waitForText(message));
+ }
+
+ private void assertConnected(int max_seconds_until_connected) {
+ String message = solo.getString(R.string.eip_state_connected);
+ assertTrue(solo.waitForText(message, 1, max_seconds_until_connected * 1000));
}
- private void testEipTurningOff() {
+ private void turningEipOff() {
sayOkToDisconnect();
- if(!solo.waitForText(getActivity().getString(R.string.eip_state_not_connected)))
- fail();
+ assertDisconnected();
solo.sleep(2*1000);
}
private void sayOkToDisconnect() {
- if(!solo.waitForActivity(DisconnectVPN.class))
- fail();
- solo.clickOnText(getActivity().getString(android.R.string.yes));
+ assertTrue(solo.waitForActivity(DisconnectVPN.class));
+ String yes = solo.getString(android.R.string.yes);
+ solo.clickOnText(yes);
+ }
+
+ private void assertDisconnected() {
+ String message = solo.getString(R.string.eip_state_not_connected);
+ assertTrue(solo.waitForText(message));
}
- private void testEipIsOnNoNetwork() {
- ConnectionManager.setMobileDataEnabled(false, solo.getCurrentActivity().getApplicationContext());
+ 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 testLogInAndOut() {
- long miliseconds_to_log_in = 40 * 1000;
- solo.clickOnActionBarItem(R.id.login_button);
- solo.enterText(0, "parmegvtest1");
- solo.enterText(1, " S_Zw3'-");
- solo.clickOnText("Log In");
- solo.waitForDialogToClose();
- solo.waitForDialogToClose(miliseconds_to_log_in);
- if(!solo.waitForText(getActivity().getString(R.string.succesful_authentication_message)))
- fail();
-
- solo.clickOnActionBarItem(R.string.logout_button);
- if(!solo.waitForDialogToClose())
- fail();
+ long milliseconds_to_log_in = 40 * 1000;
+ logIn("parmegvtest1", " S_Zw3'-");
+ solo.waitForDialogToClose(milliseconds_to_log_in);
+ assertSuccessfulLogin();
+
+ logOut();
}
-
- public void testShowAbout() {
- solo.clickOnMenuItem(getActivity().getString(R.string.about));
- solo.waitForText(getActivity().getString(R.string.repository_url_text));
+
+ private void logIn(String username, String password) {
+ solo.clickOnActionBarItem(R.id.login_button);
+ solo.enterText(0, username);
+ solo.enterText(1, password);
+ solo.clickOnText("Log In");
+ solo.waitForDialogToClose();
+ }
+
+ private void assertSuccessfulLogin() {
+ String message = solo.getString(R.string.succesful_authentication_message);
+ assertTrue(solo.waitForText(message));
+ }
+
+ private void logOut() {
+ solo.clickOnActionBarItem(R.string.logout_button);
+ assertTrue(solo.waitForDialogToClose());
+ }
+
+ public void testShowAbout() {
+ showAbout();
solo.goBack();
-
- solo.clickOnMenuItem(getActivity().getString(R.string.about));
- solo.waitForText(getActivity().getString(R.string.repository_url_text));
+ showAbout();
solo.goBack();
}
-
- public void testSwitchProvider() {
- solo.clickOnMenuItem(getActivity().getString(R.string.switch_provider_menu_option));
+
+ private void showAbout() {
+ String menu_item = solo.getString(R.string.about);
+ solo.clickOnMenuItem(menu_item);
+
+ String text_unique_to_about = solo.getString(R.string.repository_url_text);
+ solo.waitForText(text_unique_to_about);
+ }
+
+ public void testSwitchProvider() {
+ solo.clickOnMenuItem(solo.getString(R.string.switch_provider_menu_option));
solo.waitForActivity(ConfigurationWizard.class);
solo.goBack();
}
- public void testUpdateExpiredCertificate() {
- String certificate = "-----BEGIN CERTIFICATE-----" +
- "MIIEnDCCAoSgAwIBAgIRAOBkcbMKR0Jlw+xNalHn7aIwDQYJKoZIhvcNAQELBQAwdTEYMBYGA1UE" +
- "CgwPUmlzZXVwIE5ldHdvcmtzMRswGQYDVQQLDBJodHRwczovL3Jpc2V1cC5uZXQxPDA6BgNVBAMM" +
- "M1Jpc2V1cCBOZXR3b3JrcyBSb290IENBIChjbGllbnQgY2VydGlmaWNhdGVzIG9ubHkhKTAeFw0x" +
- "NDA5MTkwMDAwMDBaFw0xNDExMTkwMDAwMDBaMC0xKzApBgNVBAMMIlVOTElNSVRFRDcwZWhxZG9l" +
- "ZXQ2Z243bmc3eWx3ZWNxeGwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDdaKQHSwg2" +
- "Q2Uz9t5mae9BfV9Jkk+WSU6jXixsTbtLAr8gvuNcVuI0lKm2zXVqoS8aRCSsCt12vhjU/WBTSv0t" +
- "vwTaT2HQYFQ1GlVUBKssJEUpaVyQKL6LN9BA5ZODBpbhefRIX8z+02afxmNWdnOQfDtLU6nHSQLL" +
- "IUBSmgu+Y2Q3SdIBojIl9Kj0Zt6uZkhtOXZqkwLBiMr+/ukSidpcmNgbAN0eXSfVouaduzsDPQ6M" +
- "eCJTz2lhUvC0/57h5mlkNLzEjyb/pAVTtnK4zdiH6XAuCxU/AkF0yzhaiQWMG0RQb4vEx/UHjkDU" +
- "+K0GDy/qx1BmBB7C4vHLauqSXOs1AgMBAAGjbzBtMB0GA1UdDgQWBBQioBn7DdhjmtBKgQKpx/aW" +
- "XHYkGjALBgNVHQ8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwIwCQYDVR0TBAIwADAfBgNVHSME" +
- "GDAWgBQX9BvV5SoBAU1rol02CikJlmWARjANBgkqhkiG9w0BAQsFAAOCAgEAV7q102FQ62IOX84o" +
- "pPvUL3hJkGtZ5chgQwZhfl2fGtEdeqpU27Hx1jLP9o3n1z9XYaZg/d8xYhpY6Mm4rFl6hA4gk81Z" +
- "yg/A3QeUgIjOsA0Xp+RNB5ACaLjCPUtWNk5brfuelDdFHjl1noC2P3vQ9ErhUna6TKVsxxrueimO" +
- "nc3sV7YMGiVfPC7wEmhERuyhQxftIUHUy2kDCY5QgXtru6IZmc3SP4FcM8LUSC49kqmU9if2GTLo" +
- "wQZmz6T7+N5PIJWIOiDh9PyoojRo7ep9szeIZpzgxcsoE/9ed84tg36JLOWi0GOyrdzVExv0rQQt" +
- "q/NpqAe1mX5XQVbY8nwgaJ8eWIWIXIn+5RB7b+fm5ZFeM4eFyWeDk99bvS8jdH6uQP5WusL55+ft" +
- "ADtESsmBvzUEGqxk5GL4lmmeqE+vsR5TesqGjZ+yH67rR+1+Uy2mhbqJBP0E0LHwWCCPYEVfngHj" +
- "aZkDF1UVQdfc9Amc5u5J5YliWrEG80BNeJF7740Gwx69DHEIhElN+BBeeqLLYIZTKmt28/9iWbKL" +
- "vhCrz/29wLYksL1bXmyHzvzyAcDHPpO9sQrKYiP1mGRDmXJmZU3i3cgeqQFZ8+lr55wcYdMGJOcx" +
- "bz+jL0VkHdnoZdzGzelrAhZtgMtsJ/kgWYRgtFmhpYF1Xtj2MYrpBDxgQck=" +
- "-----END CERTIFICATE-----";
-
- }
+ /*public void testReboot() {
+ runAdbCommand("shell am broadcast -a android.intent.action.BOOT_COMPLETED");
+ }*/
- public void testReboot() {
+ private void runAdbCommand(String adb_command) {
try {
- String command = "adb shell am broadcast -a android.intent.action.BOOT_COMPLETED";
- Runtime.getRuntime().exec(command);
- } catch (IOException e) {
+ String command = "adb " + adb_command;
+ Runtime.getRuntime().exec(command).waitFor();
+ } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java
index 87154956..cd1d6c3b 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java
@@ -16,17 +16,17 @@
*/
package se.leap.bitmaskclient.test;
-import android.content.Context;
-import android.os.SystemClock;
-import android.test.InstrumentationTestCase;
+import android.content.*;
+import android.os.*;
+import android.test.*;
-import org.json.JSONObject;
+import org.json.*;
-import java.io.IOException;
-import java.util.Calendar;
+import java.io.*;
+import java.util.*;
-import se.leap.bitmaskclient.Provider;
-import se.leap.bitmaskclient.eip.VpnCertificateValidator;
+import se.leap.bitmaskclient.*;
+import se.leap.bitmaskclient.eip.*;
/**
* @author parmegv
@@ -64,11 +64,9 @@ public class testVpnCertificateValidator extends InstrumentationTestCase {
}
private int shellCommand(String command) {
- int result = -1;
+ int result = 0;
try {
- result = Runtime.getRuntime().exec(command).waitFor();
- } catch (InterruptedException e) {
- e.printStackTrace();
+ Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a2f886c7..0f28e11c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -94,7 +94,7 @@
</activity>
<activity
android:name="se.leap.bitmaskclient.ConfigurationWizard"
- android:label="@string/title_activity_configuration_wizard"
+ android:label="@string/configuration_wizard_title"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
<activity
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index b2898249..588b137b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -37,7 +37,6 @@ public class EipFragment extends Fragment implements Observer {
protected static final String STATUS_MESSAGE = TAG + ".status_message";
public static final String START_ON_BOOT = "start on boot";
- private View view;
@InjectView(R.id.eipSwitch)
Switch eip_switch;
@InjectView(R.id.status_message)
@@ -69,7 +68,7 @@ public class EipFragment extends Fragment implements Observer {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- view = inflater.inflate(R.layout.eip_service_fragment, container, false);
+ View view = inflater.inflate(R.layout.eip_service_fragment, container, false);
ButterKnife.inject(this, view);
if (eip_status.isConnecting())
diff --git a/app/src/main/res/layout/provider_detail_fragment.xml b/app/src/main/res/layout/provider_detail_fragment.xml
index eb90fad9..3b35bae7 100644
--- a/app/src/main/res/layout/provider_detail_fragment.xml
+++ b/app/src/main/res/layout/provider_detail_fragment.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/provider_detail_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7d03c221..1608f487 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -19,7 +19,7 @@
<string name="anonymous_secured_status">Connection secure using an anonymous certificate.</string>
<string name="authed_secured_status">Connection secure using your own certificate.</string>
<string name="eip_service_label">Encrypted Internet</string>
- <string name="title_activity_configuration_wizard">Select a service provider</string>
+ <string name="configuration_wizard_title">Select a service provider</string>
<string name="new_provider_button">Add new Provider</string>
<string name="introduce_new_provider">Add a new service provider</string>
<string name="save">Save</string>