Search in sources :

Example 6 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class BottomSheetBehaviorTest method testInvisible.

@Test
@MediumTest
public void testInvisible() throws Throwable {
    // Make the bottomsheet invisible
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            getBottomSheet().setVisibility(View.INVISIBLE);
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
    // Swipe up as if to expand it
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.VISIBLE_CENTER, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            return new float[] { view.getWidth() / 2, 0 };
        }
    }, Press.FINGER), not(ViewMatchers.isDisplayed())));
    // Check that the bottom sheet stays the same collapsed state
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
    });
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 7 with MediumTest

use of android.support.test.filters.MediumTest in project material-components-android by material-components.

the class CustomSnackbarTest method testDismissViaAnotherSnackbar.

@Test
@MediumTest
public void testDismissViaAnotherSnackbar() throws Throwable {
    final CustomSnackbar anotherSnackbar = makeCustomSnackbar().setTitle("Different title").setSubtitle("Different subtitle").setDuration(Snackbar.LENGTH_SHORT);
    // Our dismiss action is to show another snackbar (and verify that the original snackbar
    // is now dismissed with CONSECUTIVE event)
    verifyDismissCallback(onView(isAssignableFrom(Snackbar.SnackbarLayout.class)), null, new DismissAction() {

        @Override
        public void dismiss(CustomSnackbar snackbar) {
            anotherSnackbar.show();
        }
    }, Snackbar.LENGTH_LONG, Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE);
    // And dismiss the second snackbar to get back to clean state
    SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(anotherSnackbar);
}
Also used : CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) CustomSnackbar(android.support.design.testapp.custom.CustomSnackbar) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 8 with MediumTest

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

the class GsmInboundSmsHandlerTest method testMultiPartIncompleteSms.

@Test
@MediumTest
public void testMultiPartIncompleteSms() {
    /**
     * Test scenario: 2 messages are received with same address, ref number, count, and
     * seqNumber, with count = 2 and seqNumber = 1. We should not try to merge these.
     */
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    // change seqNumber in part 2 to 1
    mInboundSmsTrackerCVPart2.put("sequence", 1);
    doReturn(1).when(mInboundSmsTrackerPart2).getSequenceNumber();
    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 no broadcasts sent
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    // verify there's only 1 of the segments in the db (other should be discarded as dup)
    assertEquals(1, mContentProvider.getNumRows());
    // State machine should go back to idle
    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 9 with MediumTest

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

the class GsmInboundSmsHandlerTest method testMultiPartSms.

@FlakyTest
@Ignore
@Test
@MediumTest
public void testMultiPartSms() {
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    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 broadcast intents
    verifySmsIntentBroadcasts(0);
    // if an additional copy of one of the segments above is received, it should not be kept in
    // the db and should not be combined with any subsequent messages received from the same
    // sender
    // additional copy of part 2 of message
    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 no additional broadcasts sent
    verify(mContext, times(2)).sendBroadcast(any(Intent.class));
    // part 1 of new sms recieved from same sender with same parameters, just different
    // timestamps, should not be combined with the additional part 2 received above
    // call prepareMultiPartSms() to update timestamps
    prepareMultiPartSms(false);
    // part 1 of new sms
    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);
    // verify no additional broadcasts sent
    verify(mContext, times(2)).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : SmsHeader(com.android.internal.telephony.SmsHeader) 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)

Example 10 with MediumTest

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

the class GsmInboundSmsHandlerTest method testBroadcastUndeliveredUserLocked.

@Test
@MediumTest
public void testBroadcastUndeliveredUserLocked() throws Exception {
    replaceInstance(SmsBroadcastUndelivered.class, "instance", null, null);
    doReturn(0).when(mInboundSmsTracker).getDestPort();
    // add a fake entry to db
    mContentProvider.insert(sRawUri, mInboundSmsTrackerCV);
    // make it a single-part message
    doReturn(1).when(mInboundSmsTracker).getMessageCount();
    // user locked
    UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    doReturn(false).when(userManager).isUserUnlocked();
    SmsBroadcastUndelivered.initialize(mContext, mGsmInboundSmsHandler, mCdmaInboundSmsHandler);
    // verify that a broadcast receiver is registered for current user (user == null) based on
    // implementation in ContextFixture
    verify(mContext).registerReceiverAsUser(any(BroadcastReceiver.class), eq((UserHandle) null), any(IntentFilter.class), eq((String) null), eq((Handler) null));
    waitForMs(100);
    // verify no broadcasts sent because due to !isUserUnlocked
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    // when user unlocks the device, the message in db should be broadcast
    doReturn(true).when(userManager).isUserUnlocked();
    mContext.sendBroadcast(new Intent(Intent.ACTION_USER_UNLOCKED));
    waitForMs(100);
    verifyDataSmsIntentBroadcasts(1);
}
Also used : IntentFilter(android.content.IntentFilter) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) InboundSmsHandler(com.android.internal.telephony.InboundSmsHandler) Handler(android.os.Handler) CdmaInboundSmsHandler(com.android.internal.telephony.cdma.CdmaInboundSmsHandler) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) 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