Java Code Examples for android.support.test.filters.MediumTest

The following are top voted examples for showing how to use android.support.test.filters.MediumTest. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: furry-sniffle   File: ViewEntertainmentTest2.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void ViewTest3() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(15000);
    onView(isRoot()).perform(swipeUp());
    Thread.sleep(2000);
    String name = "Low Cost";
    for(int i=0; i<3;i++){
        if(i==1){ name = "Medium Cost"; }
        if(i==2){ name = "High Cost"; }
        onView(withId(R.id.averageCostSpinner)).perform(click());
        onData(allOf(is(instanceOf(String.class)), is(name))).perform(click());
        onView(withId(R.id.averageCostSpinner)).check(matches(withSpinnerText(containsString(name))));
    }
}
 
Example 2
Project: furry-sniffle   File: SumTest.java   View source code 6 votes vote down vote up
@Test
  @MediumTest
  public void summarize() throws Exception {
      Sum sum = new Sum();
      assertEquals(sum.summarize("A wiki is run using wiki software, otherwise known as a wiki engine. " +
                      "A wiki engine is a type of content management system, but it differs from most other such systems, including blog software, " +
                      "in that the content is created without any defined owner or leader, and wikis have little implicit structure, " +
                      "allowing structure to emerge according to the needs of the users.[2] There are dozens of different wiki engines in use, " +
                      "both standalone and part of other software, such as bug tracking systems. Some wiki engines are open source, " +
                      "whereas others are proprietary. Some permit control over different functions (levels of access); for example, " +
                      "editing rights may permit changing, adding or removing material. Others may permit access without enforcing access control. " +
                      "Other rules may be imposed to organize content." +
              "The online encyclopedia project Wikipedia is by far the most popular wiki-based website, " +
                      "and is one of the most widely viewed sites of any kind in the world, having been ranked in the top ten since 2007.[3] " +
                      "Wikipedia is not a single wiki but rather a collection of hundreds of wikis, one for each language. " +
                      "There are tens of thousands of other wikis in use, both public and private, including wikis functioning as knowledge management resources, " +
                      "notetaking tools, community websites and intranets. The English-language Wikipedia has the largest collection of articles; as of September 2016, " +
                      "it had over five million articles. Ward Cunningham, the developer of the first wiki software")
," A wiki is run using wiki software, otherwise known as a wiki engine.  " +
                      "A wiki engine is a type of content management system, but it differs from most other such systems, " +
                      "including blog software, in that the content is created without any defined owner or leader, and wikis have little implicit structure, " +
                      "allowing structure to emerge according to the needs of the users. [2] There are dozens of different wiki engines in use, " +
                      "both standalone and part of other software, such as bug tracking systems." );

  }
 
Example 3
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testSwipeDownToHide() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 4
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testSwipeUpToExpand() {
  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),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 5
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testAutoPeekHeight() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBehavior().setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
        }
      });
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          CoordinatorLayout col = getCoordinatorLayout();
          assertThat(
              getBottomSheet().getTop(),
              is(
                  Math.min(
                      col.getWidth() * 9 / 16,
                      col.getHeight() - getBehavior().getPeekHeightMin())));
        }
      });
}
 
Example 6
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testExpandedPeekHeight() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          // Make the peek height as tall as the bottom sheet.
          BottomSheetBehavior<?> behavior = getBehavior();
          behavior.setPeekHeight(getBottomSheet().getHeight());
          assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
  // Both of these will not animate the sheet , but the state should be changed.
  checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
}
 
Example 7
Project: material-components-android   File: CustomSnackbarTest.java   View source code 6 votes vote down vote up
@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);
}
 
Example 8
Project: material-components-android   File: CustomSnackbarTest.java   View source code 6 votes vote down vote up
@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);
}
 
Example 9
Project: material-components-android   File: FabTransformationBehaviorTest.java   View source code 6 votes vote down vote up
@Test
@MediumTest
public void testRotationInExpandedState() {
  ExpandableTransformationActivity activity = activityTestRule.getActivity();
  int oldOrientation = TestUtils.getScreenOrientation(activity);

  onView(withId(R.id.fab)).perform(setExpanded(true));
  TestUtils.switchScreenOrientation(activity);
  onView(isRoot()).perform(waitUntilIdle());

  onView(withId(R.id.fab)).check(matches(not(isDisplayed())));
  onView(withId(R.id.sheet)).check(matches(isDisplayed()));
  onView(withId(R.id.scrim)).check(matches(isDisplayed()));

  TestUtils.resetScreenOrientation(activity, oldOrientation);
}
 
Example 10
Project: android-plugin-host-sdk-for-locale   File: ConditionTest.java   View source code 6 votes vote down vote up
@MediumTest
@Test
public void query_bad_state() {
    final Condition condition = getCondition();

    try {
        final Bundle bundle = new Bundle();
        bundle.putInt(PluginBundleManager.BUNDLE_EXTRA_INT_VERSION_CODE, 1);
        bundle.putInt(PluginBundleManager.BUNDLE_EXTRA_INT_RESULT_CODE,
                1); //$NON-NLS-1$

        assertThat(condition.query(getPluginInstanceData(bundle),
                com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNKNOWN),
                is(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNKNOWN));
    } finally {
        condition.destroy();
    }
}
 
Example 11
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   View source code 6 votes vote down vote up
@MediumTest
@Test
public void peekPluginMap_after_blocking() {
    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            getIntentAction());

    try {
        registry.init();
        registry.blockUntilLoaded();

        assertThat(registry.peekPluginMap(PluginType.CONDITION), notNullValue());
        assertThat(registry.peekPluginMap(PluginType.SETTING), notNullValue());
    } finally {
        registry.destroy();
    }
}
 
Example 12
Project: AndroidViewModel   File: ViewModelActivityTest.java   View source code 6 votes vote down vote up
@MediumTest
@Test
public void viewModelActivity_instance_count_test() {
    mActivityTestRule.launchActivity(VMTestActivity.makeIntent(InstrumentationRegistry.getContext(), false));

    String uniqueIdentifierActivity = mActivityTestRule.getActivity().getViewModel().getUniqueIdentifier();
    String uniqueIdentifierFragment = mActivityTestRule.getActivity().getTestFragment().getViewModel().getUniqueIdentifier();

    rotateScreen(5);

    Map<String, AbstractViewModel<? extends IView>> viewModels =
            mActivityTestRule.getActivity().getViewModelProvider().getViewModels();

    assertThat(viewModels.size(), is(2)); //activity + fragment

    assertThat(viewModels.containsKey(uniqueIdentifierActivity), is(true));
    assertThat(viewModels.containsKey(uniqueIdentifierFragment), is(true));
}
 
Example 13
Project: furry-sniffle   File: ViewOtherUserProfileTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void profileViewTests1() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(20000);
    onView(withId(R.id.displayNameTextView)).check(matches(isDisplayed()));
    onView(withId(R.id.describeEditText)).check(matches(isDisplayed()));
    onView(withId(R.id.fullNameTextView)).check(matches(isDisplayed()));
    onView(withId(R.id.imageView2)).check(matches(isDisplayed()));
}
 
Example 14
Project: furry-sniffle   File: ViewEntertainmentTest2.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void ViewTests1() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);

    onView(withId(R.id.ViewAddedAreaOwnerText)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaAddressText)).check(matches(isDisplayed()));
    onView(withId(R.id.likeFloatingActionButton)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.authorImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.navigationImageView)).check(matches(isDisplayed()));
}
 
Example 15
Project: furry-sniffle   File: ViewEntertainmentTest2.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void ViewTests2() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);
    onView(isRoot()).perform(swipeUp());
    onView(withId(R.id.descriptImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.averageCostImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaDescText)).check(matches(isDisplayed()));
    onView(withId(R.id.averageCostSpinner)).check(matches(isDisplayed()));
}
 
Example 16
Project: furry-sniffle   File: ViewEntertainmentTest2.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void ViewTest4() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);
    onView(isRoot()).perform(swipeUp());
    onView(withId(R.id.comment_recyclerView)).check(matches(isDisplayed()));
    onView(withId(R.id.commentEditText)).check(matches(isDisplayed()));
    onView(withId(R.id.commentImageButton)).check(matches(isDisplayed()));

}
 
Example 17
Project: furry-sniffle   File: createPasswordTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void test1() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(click());
    onView(withId(R.id.loginEmailEditText)).perform(typeText("[email protected]"));
    //onView(withId(R.id.loginPasswordEditText)).perform(click()).perform(typeText("sandile11"));
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 18
Project: furry-sniffle   File: createPasswordTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void test2() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(typeText("[email protected]"), closeSoftKeyboard());
    onView(withId(R.id.loginPasswordEditText)).perform(typeText("sandile11"), closeSoftKeyboard());
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 19
Project: furry-sniffle   File: createPasswordTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void test3() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(click()).perform(typeText("[email protected]"));
    onView(withId(R.id.loginPasswordEditText)).perform(click()).perform(typeText("sandile11"));
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 20
Project: furry-sniffle   File: MainTest1.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void signOutTest() throws InterruptedException {
    Thread.sleep(6000);
    mAuth.signOut();
    Thread.sleep(2000);
    login();
    Thread.sleep(2000);
}
 
Example 21
Project: furry-sniffle   File: CreateProfileTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void test1() throws InterruptedException{
    Thread.sleep(3000);
    onView(withId(R.id.displayNameEditText)).check(matches(isClickable()));
    onView(withId(R.id.setupPictureButton)).check(matches(isClickable()));

    onView(withId(R.id.displayNameEditText)).perform(typeText(displayName),pressBack());
    onView(withId(R.id.fullNameEditText)).perform(typeText(fullName),pressBack());
}
 
Example 22
Project: android-EmojiCompat   File: MainActivityTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void allTextsDisplayed() throws Exception {
    @StringRes final int[] resIds = {
            R.string.emoji_text_view,
            R.string.emoji_edit_text,
            R.string.emoji_button,
            R.string.regular_text_view,
            R.string.custom_text_view,
    };
    for (int resId : resIds) {
        final String text = rule.getActivity().getString(resId, MainActivity.EMOJI);
        onView(withText(text)).check(matches(isDisplayed()));
    }
}
 
Example 23
Project: AndroidRTC   File: SurfaceTextureHelperTest.java   View source code 5 votes vote down vote up
/**
 * Test disposing the SurfaceTextureHelper, but keep trying to produce more texture frames. No
 * frames should be delivered to the listener.
 */
@Test
@MediumTest
public void testDispose() throws InterruptedException {
  // Create SurfaceTextureHelper and listener.
  final SurfaceTextureHelper surfaceTextureHelper =
      SurfaceTextureHelper.create("SurfaceTextureHelper test" /* threadName */, null);
  final MockTextureListener listener = new MockTextureListener();
  surfaceTextureHelper.startListening(listener);
  // Create EglBase with the SurfaceTexture as target EGLSurface.
  final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN);
  eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
  eglBase.makeCurrent();
  // Assert no frame has been received yet.
  assertFalse(listener.waitForNewFrame(1));
  // Draw and wait for one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  // swapBuffers() will ultimately trigger onTextureFrameAvailable().
  eglBase.swapBuffers();
  listener.waitForNewFrame();
  surfaceTextureHelper.returnTextureFrame();

  // Dispose - we should not receive any textures after this.
  surfaceTextureHelper.dispose();

  // Draw one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  eglBase.swapBuffers();
  // swapBuffers() should not trigger onTextureFrameAvailable() because disposed has been called.
  // Assert that no OES texture was delivered.
  assertFalse(listener.waitForNewFrame(500));

  eglBase.release();
}
 
Example 24
Project: AndroidRTC   File: SurfaceTextureHelperTest.java   View source code 5 votes vote down vote up
/**
 * Call stopListening(), but keep trying to produce more texture frames. No frames should be
 * delivered to the listener.
 */
@Test
@MediumTest
public void testStopListening() throws InterruptedException {
  // Create SurfaceTextureHelper and listener.
  final SurfaceTextureHelper surfaceTextureHelper =
      SurfaceTextureHelper.create("SurfaceTextureHelper test" /* threadName */, null);
  final MockTextureListener listener = new MockTextureListener();
  surfaceTextureHelper.startListening(listener);
  // Create EglBase with the SurfaceTexture as target EGLSurface.
  final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN);
  eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
  eglBase.makeCurrent();
  // Assert no frame has been received yet.
  assertFalse(listener.waitForNewFrame(1));
  // Draw and wait for one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  // swapBuffers() will ultimately trigger onTextureFrameAvailable().
  eglBase.swapBuffers();
  listener.waitForNewFrame();
  surfaceTextureHelper.returnTextureFrame();

  // Stop listening - we should not receive any textures after this.
  surfaceTextureHelper.stopListening();

  // Draw one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  eglBase.swapBuffers();
  // swapBuffers() should not trigger onTextureFrameAvailable() because disposed has been called.
  // Assert that no OES texture was delivered.
  assertFalse(listener.waitForNewFrame(500));

  surfaceTextureHelper.dispose();
  eglBase.release();
}
 
Example 25
Project: Presenter-Client-Android   File: MainActivityTest.java   View source code 5 votes vote down vote up
/**
 * Verify that the settings activity can be started from main menu.
 */
@Test
@MediumTest
public void startSettingsActivity() {
    CharSequence settingsTitle =
            InstrumentationRegistry.getTargetContext().getString(R.string.settings);

    onView(withId(R.id.settings)).perform(click());
    onView(isAssignableFrom(Toolbar.class))
            .check(matches(withToolbarTitle(is(settingsTitle))));
}
 
Example 26
Project: Presenter-Client-Android   File: MainActivityTest.java   View source code 5 votes vote down vote up
/**
 * Verify that the about activity can be started from main menu.
 */
@Test
@MediumTest
public void startAboutActivity() {
    CharSequence aboutTitle =
            InstrumentationRegistry.getTargetContext().getString(R.string.about,
                    InstrumentationRegistry.getTargetContext().getString(R.string.app_name));

    onView(withId(R.id.about)).perform(click());
    onView(isAssignableFrom(Toolbar.class))
            .check(matches(withToolbarTitle(is(aboutTitle))));
}
 
Example 27
Project: material-components-android   File: FloatingActionButtonTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testShowHide() {
  onView(withId(R.id.fab_standard))
      .perform(setVisibility(View.GONE))
      .perform(showThenHide())
      .check(matches(not(isDisplayed())));
}
 
Example 28
Project: material-components-android   File: FloatingActionButtonTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testOnClickListener() {
    final View.OnClickListener listener = mock(View.OnClickListener.class);
    final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard);
    view.setOnClickListener(listener);

    // Click on the fab
    onView(withId(R.id.fab_standard)).perform(click());

    // And verify that the listener was invoked once
    verify(listener, times(1)).onClick(view);
}
 
Example 29
Project: material-components-android   File: FloatingActionButtonTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testElevationOnPressed() {
  onView(withId(R.id.fab_standard)).perform(setPressed(true));
  // It's unclear why the 21+ state list animator is not affected by loopMainThreadUntilIdle().
  onView(isRoot()).perform(waitFor(1000));
  onView(withId(R.id.fab_standard)).check(matches(hasTranslationZ()));
}
 
Example 30
Project: material-components-android   File: FloatingActionButtonTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testInstanceState() throws Throwable {
  FloatingActionButtonActivity activity = activityTestRule.getActivity();

  onView(withId(R.id.fab_standard)).perform(setExpanded(false));
  ActivityUtils.recreateActivity(activityTestRule, activity);
  ActivityUtils.waitForExecution(activityTestRule);
  onView(withId(R.id.fab_standard)).check(matches(not(isExpanded())));

  onView(withId(R.id.fab_standard)).perform(setExpanded(true));
  ActivityUtils.recreateActivity(activityTestRule, activity);
  ActivityUtils.waitForExecution(activityTestRule);
  onView(withId(R.id.fab_standard)).check(matches(isExpanded()));
}
 
Example 31
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testHalfExpandedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed());
  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),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 32
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testCollapsedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
  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),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 33
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@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));
        }
      });
}
 
Example 34
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testAutoPeekHeightHide() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBehavior().setHideable(true);
          getBehavior().setPeekHeight(0);
          getBehavior().setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
        }
      });
  checkSetState(BottomSheetBehavior.STATE_HIDDEN, not(ViewMatchers.isDisplayed()));
}
 
Example 35
Project: material-components-android   File: BottomSheetBehaviorTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testDynamicContent() throws Throwable {
  registerIdlingResourceCallback();
  try {
    activityTestRule.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            ViewGroup.LayoutParams params = getBottomSheet().getLayoutParams();
            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            getBottomSheet().setLayoutParams(params);
            View view = new View(getBottomSheet().getContext());
            int size = getBehavior().getPeekHeight() * 2;
            getBottomSheet().addView(view, new ViewGroup.LayoutParams(size, size));
            assertThat(getBottomSheet().getChildCount(), is(1));
            // Shrink the content height.
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            lp.height = (int) (size * 0.8);
            view.setLayoutParams(lp);
            // Immediately expand the bottom sheet.
            getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
          }
        });
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
    // Make sure that the bottom sheet is not floating above the bottom.
    assertThat(getBottomSheet().getBottom(), is(getCoordinatorLayout().getBottom()));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 36
Project: material-components-android   File: CustomSnackbarTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaSwipe() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      swipeRight(),
      null,
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_SWIPE);
}
 
Example 37
Project: material-components-android   File: CustomSnackbarTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaSwipeRtl() throws Throwable {
  onView(withId(R.id.col)).perform(setLayoutDirection(ViewCompat.LAYOUT_DIRECTION_RTL));
  if (ViewCompat.getLayoutDirection(coordinatorLayout) == ViewCompat.LAYOUT_DIRECTION_RTL) {
    // On devices that support RTL layout, the start-to-end dismiss swipe is done
    // with swipeLeft() action
    verifyDismissCallback(
        onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
        swipeLeft(),
        null,
        Snackbar.LENGTH_LONG,
        Snackbar.Callback.DISMISS_EVENT_SWIPE);
  }
}
 
Example 38
Project: material-components-android   File: CustomSnackbarTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaApi() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      null,
      new DismissAction() {
        @Override
        public void dismiss(CustomSnackbar snackbar) {
          snackbar.dismiss();
        }
      },
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_MANUAL);
}
 
Example 39
Project: material-components-android   File: CustomSnackbarTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaTimeout() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      null,
      null,
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_TIMEOUT);
}
 
Example 40
Project: material-components-android   File: BottomSheetDialogTest.java   View source code 5 votes vote down vote up
@Test
@MediumTest
public void testHideThenShow() throws Throwable {
  // Hide the bottom sheet and wait for the dialog to be canceled.
  final DialogInterface.OnCancelListener onCancelListener =
      mock(DialogInterface.OnCancelListener.class);
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          showDialog();
          dialog.setOnCancelListener(onCancelListener);
        }
      });
  Espresso.onView(ViewMatchers.withId(R.id.design_bottom_sheet))
      .perform(setState(BottomSheetBehavior.STATE_HIDDEN));
  verify(onCancelListener, timeout(3000)).onCancel(any(DialogInterface.class));
  // Reshow the same dialog instance and wait for the bottom sheet to be collapsed.
  final BottomSheetBehavior.BottomSheetCallback callback =
      mock(BottomSheetBehavior.BottomSheetCallback.class);
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          BottomSheetBehavior.from(dialog.findViewById(R.id.design_bottom_sheet))
              .setBottomSheetCallback(callback);
          dialog.show(); // Show the same dialog again.
        }
      });
  verify(callback, timeout(3000))
      .onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_SETTLING));
  verify(callback, timeout(3000))
      .onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_COLLAPSED));
}