Search in sources :

Example 16 with MediumTest

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

the class CustomSnackbarTest method testMultipleCallbacks.

@Test
@MediumTest
public void testMultipleCallbacks() throws Throwable {
    final CustomSnackbar snackbar = makeCustomSnackbar().setTitle(TITLE_TEXT).setSubtitle(SUBTITLE_TEXT).setDuration(Snackbar.LENGTH_INDEFINITE);
    final BaseTransientBottomBar.BaseCallback mockCallback1 = mock(BaseTransientBottomBar.BaseCallback.class);
    final BaseTransientBottomBar.BaseCallback mockCallback2 = mock(BaseTransientBottomBar.BaseCallback.class);
    snackbar.addCallback(mockCallback1);
    snackbar.addCallback(mockCallback2);
    SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);
    verify(mockCallback1, times(1)).onShown(snackbar);
    verify(mockCallback2, times(1)).onShown(snackbar);
    SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(snackbar);
    verify(mockCallback1, times(1)).onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
    verify(mockCallback2, times(1)).onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
}
Also used : 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 17 with MediumTest

use of android.support.test.filters.MediumTest in project platform_frameworks_base by android.

the class LoaderLifecycleTest method backStackLoaderIdentityTest.

@Test
@MediumTest
public void backStackLoaderIdentityTest() throws Throwable {
    mActivityRule.runOnUiThread(() -> {
        final Handler h = new Handler();
        final FragmentHostCallback host1 = new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0);
        final FragmentController fc1 = FragmentController.createController(host1);
        fc1.attachHost(null);
        fc1.dispatchCreate();
        final FragmentManager fm1 = fc1.getFragmentManager();
        final Fragment f1 = new Fragment();
        fm1.beginTransaction().add(f1, "one").commitNow();
        final LoaderManager lm1 = f1.getLoaderManager();
        // Put the fragment on the back stack.
        fm1.beginTransaction().remove(f1).addToBackStack("backentry").commit();
        fm1.executePendingTransactions();
        fc1.dispatchActivityCreated();
        fc1.noteStateNotSaved();
        fc1.execPendingActions();
        fc1.doLoaderStart();
        fc1.dispatchStart();
        fc1.reportLoaderStart();
        fc1.dispatchResume();
        fc1.execPendingActions();
        // Bring the state back down to destroyed, simulating an activity restart
        fc1.dispatchPause();
        final Parcelable savedState = fc1.saveAllState();
        fc1.doLoaderStop(true);
        fc1.dispatchStop();
        final FragmentManagerNonConfig nonconf = fc1.retainNestedNonConfig();
        final ArrayMap<String, LoaderManager> loaderNonConfig = fc1.retainLoaderNonConfig();
        assertNotNull("loaderNonConfig was null", loaderNonConfig);
        fc1.dispatchDestroy();
        // Create the new controller and restore state
        final FragmentHostCallback host2 = new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0);
        final FragmentController fc2 = FragmentController.createController(host2);
        final FragmentManager fm2 = fc2.getFragmentManager();
        fc2.attachHost(null);
        fc2.restoreLoaderNonConfig(loaderNonConfig);
        fc2.restoreAllState(savedState, nonconf);
        fc2.dispatchCreate();
        fc2.dispatchActivityCreated();
        fc2.noteStateNotSaved();
        fc2.execPendingActions();
        fc2.doLoaderStart();
        fc2.dispatchStart();
        fc2.reportLoaderStart();
        fc2.dispatchResume();
        fc2.execPendingActions();
        assertNotSame("LoaderManager kept reference to old FragmentHostCallback", host1, lm1.getFragmentHostCallback());
        assertSame("LoaderManager did not refrence new FragmentHostCallback", host2, lm1.getFragmentHostCallback());
        // Test that the fragments are in the configuration we expect
        final Fragment restoredOne = fm2.findFragmentByTag("one");
        final LoaderManager lm2 = restoredOne.getLoaderManager();
        assertSame("didn't get same LoaderManager instance back", lm2, lm1);
        // Bring the state back down to destroyed before we finish the test
        fc2.dispatchPause();
        fc2.saveAllState();
        fc2.dispatchStop();
        fc2.dispatchDestroy();
    });
}
Also used : Handler(android.os.Handler) Parcelable(android.os.Parcelable) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 18 with MediumTest

use of android.support.test.filters.MediumTest in project platform_frameworks_base by android.

the class LoaderLifecycleTest method loaderIdentityTest.

@Test
@MediumTest
public void loaderIdentityTest() throws Throwable {
    mActivityRule.runOnUiThread(() -> {
        final Handler h = new Handler();
        final FragmentController fc1 = FragmentController.createController(new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0));
        fc1.attachHost(null);
        fc1.dispatchCreate();
        final FragmentManager fm1 = fc1.getFragmentManager();
        final Fragment f1 = new Fragment();
        fm1.beginTransaction().add(f1, "one").commitNow();
        // Removing and re-adding a fragment completely will destroy its LoaderManager.
        // Keep the first one here to confirm this later.
        final LoaderManager lm1 = f1.getLoaderManager();
        // Remove the fragment, add a second one, and re-add the first to
        // force its internal index to change. The tests below should still remain consistent.
        final Fragment f2 = new Fragment();
        fm1.beginTransaction().remove(f1).commitNow();
        fm1.beginTransaction().add(f2, "two").commitNow();
        fm1.beginTransaction().add(f1, "one").commitNow();
        // We'll check this to see if we get the same instance back later
        // as passed through NonConfigurationInstance. If the keys stay consistent
        // across fragment remove/re-add, this will be consistent.
        final LoaderManager lm12 = f1.getLoaderManager();
        assertNotSame("fully removed and re-added fragment got same LoaderManager", lm1, lm12);
        fc1.dispatchActivityCreated();
        fc1.noteStateNotSaved();
        fc1.execPendingActions();
        fc1.doLoaderStart();
        fc1.dispatchStart();
        fc1.reportLoaderStart();
        fc1.dispatchResume();
        fc1.execPendingActions();
        // Bring the state back down to destroyed, simulating an activity restart
        fc1.dispatchPause();
        final Parcelable savedState = fc1.saveAllState();
        fc1.doLoaderStop(true);
        fc1.dispatchStop();
        final FragmentManagerNonConfig nonconf = fc1.retainNestedNonConfig();
        final ArrayMap<String, LoaderManager> loaderNonConfig = fc1.retainLoaderNonConfig();
        assertNotNull("loaderNonConfig was null", loaderNonConfig);
        fc1.dispatchDestroy();
        // Create the new controller and restore state
        final FragmentController fc2 = FragmentController.createController(new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0));
        final FragmentManager fm2 = fc2.getFragmentManager();
        fc2.attachHost(null);
        // Make sure nothing blows up on a null here
        fc2.restoreLoaderNonConfig(null);
        // for real this time
        fc2.restoreLoaderNonConfig(loaderNonConfig);
        fc2.restoreAllState(savedState, nonconf);
        fc2.dispatchCreate();
        fc2.dispatchActivityCreated();
        fc2.noteStateNotSaved();
        fc2.execPendingActions();
        fc2.doLoaderStart();
        fc2.dispatchStart();
        fc2.reportLoaderStart();
        fc2.dispatchResume();
        fc2.execPendingActions();
        // Test that the fragments are in the configuration we expect
        final Fragment restoredOne = fm2.findFragmentByTag("one");
        final LoaderManager lm2 = restoredOne.getLoaderManager();
        assertSame("didn't get same LoaderManager instance back", lm2, lm12);
        // Bring the state back down to destroyed before we finish the test
        fc2.dispatchPause();
        fc2.saveAllState();
        fc2.dispatchStop();
        fc2.dispatchDestroy();
    });
}
Also used : Handler(android.os.Handler) Parcelable(android.os.Parcelable) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 19 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_base by DirtyUnicorns.

the class LoaderLifecycleTest method backStackLoaderIdentityTest.

@Test
@MediumTest
public void backStackLoaderIdentityTest() throws Throwable {
    mActivityRule.runOnUiThread(() -> {
        final Handler h = new Handler();
        final FragmentHostCallback host1 = new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0);
        final FragmentController fc1 = FragmentController.createController(host1);
        fc1.attachHost(null);
        fc1.dispatchCreate();
        final FragmentManager fm1 = fc1.getFragmentManager();
        final Fragment f1 = new Fragment();
        fm1.beginTransaction().add(f1, "one").commitNow();
        final LoaderManager lm1 = f1.getLoaderManager();
        // Put the fragment on the back stack.
        fm1.beginTransaction().remove(f1).addToBackStack("backentry").commit();
        fm1.executePendingTransactions();
        fc1.dispatchActivityCreated();
        fc1.noteStateNotSaved();
        fc1.execPendingActions();
        fc1.doLoaderStart();
        fc1.dispatchStart();
        fc1.reportLoaderStart();
        fc1.dispatchResume();
        fc1.execPendingActions();
        // Bring the state back down to destroyed, simulating an activity restart
        fc1.dispatchPause();
        final Parcelable savedState = fc1.saveAllState();
        fc1.doLoaderStop(true);
        fc1.dispatchStop();
        final FragmentManagerNonConfig nonconf = fc1.retainNestedNonConfig();
        final ArrayMap<String, LoaderManager> loaderNonConfig = fc1.retainLoaderNonConfig();
        assertNotNull("loaderNonConfig was null", loaderNonConfig);
        fc1.dispatchDestroy();
        // Create the new controller and restore state
        final FragmentHostCallback host2 = new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0);
        final FragmentController fc2 = FragmentController.createController(host2);
        final FragmentManager fm2 = fc2.getFragmentManager();
        fc2.attachHost(null);
        fc2.restoreLoaderNonConfig(loaderNonConfig);
        fc2.restoreAllState(savedState, nonconf);
        fc2.dispatchCreate();
        fc2.dispatchActivityCreated();
        fc2.noteStateNotSaved();
        fc2.execPendingActions();
        fc2.doLoaderStart();
        fc2.dispatchStart();
        fc2.reportLoaderStart();
        fc2.dispatchResume();
        fc2.execPendingActions();
        assertNotSame("LoaderManager kept reference to old FragmentHostCallback", host1, lm1.getFragmentHostCallback());
        assertSame("LoaderManager did not refrence new FragmentHostCallback", host2, lm1.getFragmentHostCallback());
        // Test that the fragments are in the configuration we expect
        final Fragment restoredOne = fm2.findFragmentByTag("one");
        final LoaderManager lm2 = restoredOne.getLoaderManager();
        assertSame("didn't get same LoaderManager instance back", lm2, lm1);
        // Bring the state back down to destroyed before we finish the test
        fc2.dispatchPause();
        fc2.saveAllState();
        fc2.dispatchStop();
        fc2.dispatchDestroy();
    });
}
Also used : Handler(android.os.Handler) Parcelable(android.os.Parcelable) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 20 with MediumTest

use of android.support.test.filters.MediumTest in project android_frameworks_base by DirtyUnicorns.

the class LoaderLifecycleTest method loaderIdentityTest.

@Test
@MediumTest
public void loaderIdentityTest() throws Throwable {
    mActivityRule.runOnUiThread(() -> {
        final Handler h = new Handler();
        final FragmentController fc1 = FragmentController.createController(new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0));
        fc1.attachHost(null);
        fc1.dispatchCreate();
        final FragmentManager fm1 = fc1.getFragmentManager();
        final Fragment f1 = new Fragment();
        fm1.beginTransaction().add(f1, "one").commitNow();
        // Removing and re-adding a fragment completely will destroy its LoaderManager.
        // Keep the first one here to confirm this later.
        final LoaderManager lm1 = f1.getLoaderManager();
        // Remove the fragment, add a second one, and re-add the first to
        // force its internal index to change. The tests below should still remain consistent.
        final Fragment f2 = new Fragment();
        fm1.beginTransaction().remove(f1).commitNow();
        fm1.beginTransaction().add(f2, "two").commitNow();
        fm1.beginTransaction().add(f1, "one").commitNow();
        // We'll check this to see if we get the same instance back later
        // as passed through NonConfigurationInstance. If the keys stay consistent
        // across fragment remove/re-add, this will be consistent.
        final LoaderManager lm12 = f1.getLoaderManager();
        assertNotSame("fully removed and re-added fragment got same LoaderManager", lm1, lm12);
        fc1.dispatchActivityCreated();
        fc1.noteStateNotSaved();
        fc1.execPendingActions();
        fc1.doLoaderStart();
        fc1.dispatchStart();
        fc1.reportLoaderStart();
        fc1.dispatchResume();
        fc1.execPendingActions();
        // Bring the state back down to destroyed, simulating an activity restart
        fc1.dispatchPause();
        final Parcelable savedState = fc1.saveAllState();
        fc1.doLoaderStop(true);
        fc1.dispatchStop();
        final FragmentManagerNonConfig nonconf = fc1.retainNestedNonConfig();
        final ArrayMap<String, LoaderManager> loaderNonConfig = fc1.retainLoaderNonConfig();
        assertNotNull("loaderNonConfig was null", loaderNonConfig);
        fc1.dispatchDestroy();
        // Create the new controller and restore state
        final FragmentController fc2 = FragmentController.createController(new TestFragmentHostCallback(mActivityRule.getActivity(), h, 0));
        final FragmentManager fm2 = fc2.getFragmentManager();
        fc2.attachHost(null);
        // Make sure nothing blows up on a null here
        fc2.restoreLoaderNonConfig(null);
        // for real this time
        fc2.restoreLoaderNonConfig(loaderNonConfig);
        fc2.restoreAllState(savedState, nonconf);
        fc2.dispatchCreate();
        fc2.dispatchActivityCreated();
        fc2.noteStateNotSaved();
        fc2.execPendingActions();
        fc2.doLoaderStart();
        fc2.dispatchStart();
        fc2.reportLoaderStart();
        fc2.dispatchResume();
        fc2.execPendingActions();
        // Test that the fragments are in the configuration we expect
        final Fragment restoredOne = fm2.findFragmentByTag("one");
        final LoaderManager lm2 = restoredOne.getLoaderManager();
        assertSame("didn't get same LoaderManager instance back", lm2, lm12);
        // Bring the state back down to destroyed before we finish the test
        fc2.dispatchPause();
        fc2.saveAllState();
        fc2.dispatchStop();
        fc2.dispatchDestroy();
    });
}
Also used : Handler(android.os.Handler) Parcelable(android.os.Parcelable) 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