From fdbe887fc70cfdfc7cd3b5806273d1faf182f65d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 18 Jun 2013 15:24:39 +0200 Subject: [PATCH] New call tests + feature to auto fill email filed in wizard using google account email --- AndroidManifest.xml | 2 + res/layout/incoming.xml | 3 +- res/values/non_localizable_custom.xml | 1 + src/org/linphone/setup/WizardFragment.java | 19 ++- tests/src/org/linphone/test/CallsAudio.java | 114 +++++++++++++++++- tests/src/org/linphone/test/CallsVideo.java | 52 +++++++- .../org/linphone/test/ZShutdownTestEnv.java | 6 + 7 files changed, 188 insertions(+), 9 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 12556e399..afd69be70 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -34,6 +34,8 @@ + + diff --git a/res/layout/incoming.xml b/res/layout/incoming.xml index 663abddbb..1446ab81e 100644 --- a/res/layout/incoming.xml +++ b/res/layout/incoming.xml @@ -1,5 +1,6 @@ + android:layout_marginBottom="80dp" /> diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml index a37e68e4f..9a01d16cd 100644 --- a/res/values/non_localizable_custom.xml +++ b/res/values/non_localizable_custom.xml @@ -51,6 +51,7 @@ false + true false true true diff --git a/src/org/linphone/setup/WizardFragment.java b/src/org/linphone/setup/WizardFragment.java index 4309edff2..15c8ee055 100644 --- a/src/org/linphone/setup/WizardFragment.java +++ b/src/org/linphone/setup/WizardFragment.java @@ -18,17 +18,21 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.net.URL; +import java.util.regex.Pattern; import org.linphone.LinphoneManager; import org.linphone.LinphoneService; import org.linphone.R; +import android.accounts.Account; +import android.accounts.AccountManager; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.TextWatcher; +import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -86,6 +90,18 @@ public class WizardFragment extends Fragment { } }); + if (getResources().getBoolean(R.bool.pre_fill_email_in_wizard)) { + Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google"); + + for (Account account: accounts) { + if (isEmailCorrect(account.name)) { + String possibleEmail = account.name; + email.setText(possibleEmail); + break; + } + } + } + return view; } @@ -152,7 +168,8 @@ public class WizardFragment extends Fragment { } private boolean isEmailCorrect(String email) { - return email.matches("^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$"); + Pattern emailPattern = Patterns.EMAIL_ADDRESS; + return emailPattern.matcher(email).matches(); } private boolean isPasswordCorrect(String password) { diff --git a/tests/src/org/linphone/test/CallsAudio.java b/tests/src/org/linphone/test/CallsAudio.java index 2539f3ec2..d0bc75655 100644 --- a/tests/src/org/linphone/test/CallsAudio.java +++ b/tests/src/org/linphone/test/CallsAudio.java @@ -3,15 +3,19 @@ package org.linphone.test; import junit.framework.Assert; import org.linphone.InCallActivity; +import org.linphone.IncomingCallActivity; import org.linphone.LinphoneActivity; import org.linphone.LinphoneManager; import org.linphone.core.LinphoneCall; +import org.linphone.core.LinphoneCoreException; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; +import android.util.DisplayMetrics; +import android.view.View; /** * @author Sylvain Berfini @@ -174,18 +178,59 @@ public class CallsAudio extends SampleTest { LinphoneTestManager.getInstance().declineCall = false; } - @MediumTest // TODO: Remove + @SmallTest + @MediumTest @LargeTest public void testIIncomingAudioCall() { LinphoneTestManager.getInstance().declineCall = false; // Just in case LinphoneTestManager.getLc().enableVideo(false, false); + + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + solo.sleep(1000); + View topLayout = solo.getView(org.linphone.R.id.topLayout); + int topLayoutHeigh = topLayout.getMeasuredHeight(); + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int topOffset = dm.heightPixels - topLayoutHeigh; + int slidersTop = topLayoutHeigh - 80 - topOffset; // 80 is the bottom margin set in incoming.xml + solo.drag(10, topLayout.getMeasuredWidth() - 10, slidersTop, slidersTop, 10); + + assertCallIsCorrectlyRunning(); } - @MediumTest // TODO: Remove @LargeTest public void testJIncomingVideoCall() { LinphoneTestManager.getLc().enableVideo(true, true); + + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + solo.sleep(1000); + View topLayout = solo.getView(org.linphone.R.id.topLayout); + int topLayoutHeigh = topLayout.getMeasuredHeight(); + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int topOffset = dm.heightPixels - topLayoutHeigh; + int slidersTop = topLayoutHeigh - 80 - topOffset; // 80 is the bottom margin set in incoming.xml + solo.drag(10, topLayout.getMeasuredWidth() - 10, slidersTop, slidersTop, 10); + + assertCallIsCorrectlyRunning(); } @MediumTest @@ -236,7 +281,6 @@ public class CallsAudio extends SampleTest { solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class); } - @MediumTest @LargeTest public void testMSwitchOnVideoInCallIsNotAllowed() { solo.enterText(0, iContext.getString(org.linphone.test.R.string.account_test_calls_login) + "@" + iContext.getString(org.linphone.test.R.string.account_test_calls_domain)); @@ -250,6 +294,62 @@ public class CallsAudio extends SampleTest { solo.waitForActivity("LinphoneActivity", 5000); solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class); } + + @LargeTest + public void testNDeclineIncomingCall() { + LinphoneTestManager.getInstance().declineCall = false; // Just in case + LinphoneTestManager.getLc().enableVideo(false, false); + + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + solo.sleep(1000); + View topLayout = solo.getView(org.linphone.R.id.topLayout); + int topLayoutHeigh = topLayout.getMeasuredHeight(); + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int topOffset = dm.heightPixels - topLayoutHeigh; + int slidersTop = topLayoutHeigh - 80 - topOffset; // 80 is the bottom margin set in incoming.xml + solo.drag(topLayout.getMeasuredWidth() - 10, 10, slidersTop, slidersTop, 10); + } + + @MediumTest + @LargeTest + public void testOCancelledIncomingCall() { + LinphoneTestManager.getInstance().declineCall = false; // Just in case + LinphoneTestManager.getLc().enableVideo(false, false); + + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + LinphoneTestManager.getLc().terminateAllCalls(); + + solo.waitForActivity("LinphoneActivity", 5000); + solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class); + } + + @MediumTest + @LargeTest + public void testPDisplayMissedCallsNumber() { + solo.waitForActivity("LinphoneActivity", 5000); + solo.assertCurrentActivity("Expected Linphone Activity", LinphoneActivity.class); + + Assert.assertTrue(solo.searchText("1")); + } //TODO: Test each audio codec @@ -259,6 +359,11 @@ public class CallsAudio extends SampleTest { solo.sleep(2000); LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; + + if (call.getState() == LinphoneCall.State.OutgoingProgress) { + solo.sleep(3000); + } + Assert.assertEquals(LinphoneCall.State.StreamsRunning, call.getState()); } @@ -342,8 +447,7 @@ public class CallsAudio extends SampleTest { } } - private void goBackToDialerAfterCodecChanges() - { + private void goBackToDialerAfterCodecChanges() { solo.goBack(); solo.goBack(); diff --git a/tests/src/org/linphone/test/CallsVideo.java b/tests/src/org/linphone/test/CallsVideo.java index 5309d0555..f3c6afa82 100644 --- a/tests/src/org/linphone/test/CallsVideo.java +++ b/tests/src/org/linphone/test/CallsVideo.java @@ -3,15 +3,19 @@ package org.linphone.test; import junit.framework.Assert; import org.linphone.InCallActivity; +import org.linphone.IncomingCallActivity; import org.linphone.LinphoneActivity; import org.linphone.LinphoneManager; import org.linphone.core.LinphoneCall; +import org.linphone.core.LinphoneCoreException; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; +import android.util.DisplayMetrics; +import android.view.View; /** * @author Sylvain Berfini @@ -174,19 +178,58 @@ public class CallsVideo extends SampleTest { LinphoneTestManager.getInstance().declineCall = false; } - @MediumTest // TODO: Remove @LargeTest public void testIIncomingAudioCall() { LinphoneTestManager.getInstance().declineCall = false; // Just in case LinphoneTestManager.getLc().enableVideo(false, false); + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + solo.sleep(1000); + View topLayout = solo.getView(org.linphone.R.id.topLayout); + int topLayoutHeigh = topLayout.getMeasuredHeight(); + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int topOffset = dm.heightPixels - topLayoutHeigh; + int slidersTop = topLayoutHeigh - 80 - topOffset; // 80 is the bottom margin set in incoming.xml + solo.drag(10, topLayout.getMeasuredWidth() - 10, slidersTop, slidersTop, 10); + + assertCallIsCorrectlyRunning(); } - @MediumTest // TODO: Remove + @MediumTest @LargeTest public void testJIncomingVideoCall() { LinphoneTestManager.getLc().enableVideo(true, true); + + solo.sleep(2000); + try { + LinphoneTestManager.getLc().invite("sip:" + iContext.getString(org.linphone.test.R.string.account_linphone_login) + "@" + iContext.getString(org.linphone.test.R.string.account_linphone_domain)); + } catch (LinphoneCoreException e) { + e.printStackTrace(); + } + solo.waitForActivity("IncomingCallActivity", 5000); + solo.assertCurrentActivity("Expected Incoming Call Activity", IncomingCallActivity.class); + + solo.sleep(1000); + View topLayout = solo.getView(org.linphone.R.id.topLayout); + int topLayoutHeigh = topLayout.getMeasuredHeight(); + DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int topOffset = dm.heightPixels - topLayoutHeigh; + int slidersTop = topLayoutHeigh - 80 - topOffset; // 80 is the bottom margin set in incoming.xml + solo.drag(10, topLayout.getMeasuredWidth() - 10, slidersTop, slidersTop, 10); + + assertCallIsCorrectlyRunning(); } //TODO: Test each video codec @@ -262,6 +305,11 @@ public class CallsVideo extends SampleTest { solo.sleep(2000); LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; + + if (call.getState() == LinphoneCall.State.OutgoingProgress) { + solo.sleep(3000); + } + Assert.assertEquals(LinphoneCall.State.StreamsRunning, call.getState()); } diff --git a/tests/src/org/linphone/test/ZShutdownTestEnv.java b/tests/src/org/linphone/test/ZShutdownTestEnv.java index 857395f56..6b5271410 100644 --- a/tests/src/org/linphone/test/ZShutdownTestEnv.java +++ b/tests/src/org/linphone/test/ZShutdownTestEnv.java @@ -1,5 +1,10 @@ package org.linphone.test; +import static android.content.Intent.ACTION_MAIN; + +import org.linphone.LinphoneService; + +import android.content.Intent; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -14,6 +19,7 @@ public class ZShutdownTestEnv extends SampleTest { @LargeTest public void testZShutDownLinphoneCore() { LinphoneTestManager.destroy(); + aContext.stopService(new Intent(ACTION_MAIN).setClass(aContext, LinphoneService.class)); } }