diff options
author | Parménides GV <parmegv@sdf.org> | 2014-03-26 12:15:09 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-03-26 12:15:09 +0100 |
commit | c946bed3e63d9d271cd08d4c33e564a157908c36 (patch) | |
tree | e5869abb9eb941e340a7968b34225c7a58199161 /tests/src/se | |
parent | 0323676ef98b12af3c7ce20bf4101bdc900ef654 (diff) | |
parent | 8a754e30011bf60ac9bff2cf987c3fa263b3d924 (diff) |
Merge branch 'develop' into release-0.5
Diffstat (limited to 'tests/src/se')
3 files changed, 58 insertions, 60 deletions
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); - } } |