Search in sources :

Example 26 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testMultipartSmsFromBlockedEmail_noBroadcastsSent.

@Test
@MediumTest
public void testMultipartSmsFromBlockedEmail_noBroadcastsSent() {
    mFakeBlockedNumberContentProvider.mBlockedNumbers.add("1234567890@test.com");
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    // only the first SMS is configured with the display originating email address
    mInboundSmsTrackerCVPart1.put("display_originating_addr", "1234567890@test.com");
    mSmsHeader.concatRef = new SmsHeader.ConcatRef();
    doReturn(mSmsHeader).when(mGsmSmsMessage).getUserDataHeader();
    doReturn(mInboundSmsTrackerPart1).when(mTelephonyComponentFactory).makeInboundSmsTracker(nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class));
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(100);
    // State machine should go back to idle and wait for second part
    assertEquals("IdleState", getCurrentState().getName());
    doReturn(mInboundSmsTrackerPart2).when(mTelephonyComponentFactory).makeInboundSmsTracker(nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class));
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(100);
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : SmsHeader(com.android.internal.telephony.SmsHeader) Intent(android.content.Intent) AsyncResult(android.os.AsyncResult) TelephonyTest(com.android.internal.telephony.TelephonyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 27 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testBroadcastUndeliveredDeleted.

@Test
@MediumTest
public void testBroadcastUndeliveredDeleted() throws Exception {
    replaceInstance(SmsBroadcastUndelivered.class, "instance", null, null);
    SmsBroadcastUndelivered.initialize(mContext, mGsmInboundSmsHandler, mCdmaInboundSmsHandler);
    doReturn(0).when(mInboundSmsTracker).getDestPort();
    // add a fake entry to db
    ContentValues rawSms = new ContentValues();
    rawSms.put("deleted", 1);
    mContentProvider.insert(sRawUri, rawSms);
    // make it a single-part message
    doReturn(1).when(mInboundSmsTracker).getMessageCount();
    // when user unlocks the device, broadcast should not be sent for new message
    mContext.sendBroadcast(new Intent(Intent.ACTION_USER_UNLOCKED));
    waitForMs(100);
    verify(mContext, times(1)).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : ContentValues(android.content.ContentValues) Intent(android.content.Intent) TelephonyTest(com.android.internal.telephony.TelephonyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 28 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testMultiPartSmsWithIncompleteWAP.

@Test
@MediumTest
public void testMultiPartSmsWithIncompleteWAP() {
    /**
     * Test scenario: 3 messages are received with same address, ref number, count. two of the
     * messages are belonging to the same multi-part SMS and the other one is a 3GPP2WAP.
     * we should not try to merge 3gpp2wap with the multi-part SMS.
     */
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    mSmsHeader.concatRef = new SmsHeader.ConcatRef();
    doReturn(mSmsHeader).when(mGsmSmsMessage).getUserDataHeader();
    // part 2 of non-3gpp2wap arrives first
    doReturn(mInboundSmsTrackerPart2).when(mTelephonyComponentFactory).makeInboundSmsTracker(nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class));
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(200);
    // State machine should go back to idle and wait for second part
    assertEquals("IdleState", getCurrentState().getName());
    // mock a 3gpp2wap push
    prepareMultiPartSms(true);
    doReturn(mInboundSmsTrackerPart2).when(mTelephonyComponentFactory).makeInboundSmsTracker(nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class));
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(200);
    // State machine should go back to idle and wait for second part
    assertEquals("IdleState", getCurrentState().getName());
    // verify no broadcast sent.
    verify(mContext, times(0)).sendBroadcast(any(Intent.class));
    // additional copy of part 1 of non-3gpp2wap
    prepareMultiPartSms(false);
    doReturn(mInboundSmsTrackerPart1).when(mTelephonyComponentFactory).makeInboundSmsTracker(nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class));
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(200);
    // verify broadcast intents
    verifySmsIntentBroadcasts(0);
    assertEquals("IdleState", getCurrentState().getName());
    // verify there are three segments in the db and only one of them is not marked as deleted.
    assertEquals(3, mContentProvider.getNumRows());
    assertEquals(1, mContentProvider.query(sRawUri, null, "deleted=0", null, null).getCount());
}
Also used : SmsHeader(com.android.internal.telephony.SmsHeader) Intent(android.content.Intent) AsyncResult(android.os.AsyncResult) TelephonyTest(com.android.internal.telephony.TelephonyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 29 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testNewSmsFromBlockedNumber_noBroadcastsSent.

@Test
@MediumTest
public void testNewSmsFromBlockedNumber_noBroadcastsSent() {
    String blockedNumber = "1234567890";
    doReturn(blockedNumber).when(mInboundSmsTracker).getDisplayAddress();
    mFakeBlockedNumberContentProvider.mBlockedNumbers.add(blockedNumber);
    transitionFromStartupToIdle();
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(100);
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : Intent(android.content.Intent) AsyncResult(android.os.AsyncResult) TelephonyTest(com.android.internal.telephony.TelephonyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 30 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testInjectSms.

@FlakyTest
@Ignore
@Test
@MediumTest
public void testInjectSms() {
    transitionFromStartupToIdle();
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_INJECT_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(200);
    verifySmsIntentBroadcasts(0);
    // inject same SMS again, verify no broadcasts are sent
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_INJECT_SMS, new AsyncResult(null, mSmsMessage, null));
    waitForMs(100);
    verify(mContext, times(2)).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : Intent(android.content.Intent) AsyncResult(android.os.AsyncResult) FlakyTest(android.support.test.filters.FlakyTest) Ignore(org.junit.Ignore) TelephonyTest(com.android.internal.telephony.TelephonyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Aggregations

MediumTest (android.support.test.filters.MediumTest)32 Test (org.junit.Test)32 Intent (android.content.Intent)11 Handler (android.os.Handler)11 FlakyTest (android.support.test.filters.FlakyTest)11 TelephonyTest (com.android.internal.telephony.TelephonyTest)11 Parcelable (android.os.Parcelable)10 SmallTest (android.support.test.filters.SmallTest)10 AsyncResult (android.os.AsyncResult)9 View (android.view.View)9 NestedScrollView (android.support.v4.widget.NestedScrollView)8 TextView (android.widget.TextView)8 CoordinatesProvider (android.support.test.espresso.action.CoordinatesProvider)6 GeneralSwipeAction (android.support.test.espresso.action.GeneralSwipeAction)6 SmsHeader (com.android.internal.telephony.SmsHeader)5 Ignore (org.junit.Ignore)4 CustomSnackbar (android.support.design.testapp.custom.CustomSnackbar)2 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentValues (android.content.ContentValues)1 IntentFilter (android.content.IntentFilter)1