diff options
Diffstat (limited to 'espresso/espresso-lib-tests/src/androidTest/java/com/google/android/apps/common/testing/ui/espresso/action/SwipeActionIntegrationTest.java')
-rw-r--r-- | espresso/espresso-lib-tests/src/androidTest/java/com/google/android/apps/common/testing/ui/espresso/action/SwipeActionIntegrationTest.java | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/espresso/espresso-lib-tests/src/androidTest/java/com/google/android/apps/common/testing/ui/espresso/action/SwipeActionIntegrationTest.java b/espresso/espresso-lib-tests/src/androidTest/java/com/google/android/apps/common/testing/ui/espresso/action/SwipeActionIntegrationTest.java new file mode 100644 index 0000000..90257bc --- /dev/null +++ b/espresso/espresso-lib-tests/src/androidTest/java/com/google/android/apps/common/testing/ui/espresso/action/SwipeActionIntegrationTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.apps.common.testing.ui.espresso.action; + +import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; +import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.swipeLeft; +import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.swipeRight; +import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.hasDescendant; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; +import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; + +import com.google.android.apps.common.testing.ui.testapp.R; +import com.google.android.apps.common.testing.ui.testapp.SwipeActivity; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; + +/** + * Integration tests for swiping actions. + */ +@LargeTest +public class SwipeActionIntegrationTest extends ActivityInstrumentationTestCase2<SwipeActivity> { + + @SuppressWarnings("deprecation") + public SwipeActionIntegrationTest() { + // Keep froyo happy. + super("com.google.android.apps.common.testing.ui.testapp", SwipeActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + getActivity(); + } + + /** Tests that a small view can be swiped in both directions. */ + public void testSwipeOverSmallView() { + onView(withId(R.id.small_pager)) + .check(matches(hasDescendant(withText("Position #0")))) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #1")))) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #2")))) + .perform(swipeRight()) + .check(matches(hasDescendant(withText("Position #1")))) + .perform(swipeRight()) + .check(matches(hasDescendant(withText("Position #0")))); + } + + /** Tests that trying to swipe beyond the start of a view pager has no effect. */ + public void testSwipingRightHasNoEffectWhenAtStart() { + onView(withId(R.id.small_pager)) + .check(matches(hasDescendant(withText("Position #0")))) + .perform(swipeRight()) + .check(matches(hasDescendant(withText("Position #0")))) + .perform(swipeRight()) + .check(matches(hasDescendant(withText("Position #0")))); + } + + /** Tests that trying to swipe beyond the end of a view pager has no effect. */ + public void testSwipingLeftHasNoEffectWhenAtEnd() { + onView(withId(R.id.small_pager)) + .perform(swipeLeft()) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #2")))) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #2")))) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #2")))); + } + + /** Tests that swiping across a partially overlapped view works correctly. */ + public void testSwipeOverPartiallyOverlappedView() { + onView(withId(R.id.overlapped_pager)) + .check(matches(hasDescendant(withText("Position #0")))) + .perform(swipeLeft()) + .check(matches(hasDescendant(withText("Position #1")))) + .perform(swipeRight()) + .check(matches(hasDescendant(withText("Position #0")))); + } + + /** Tests that trying to swipe a view that doesn't respond to swipes has no effect. */ + @SuppressWarnings("unchecked") + public void testSwipeOverUnswipableView() { + onView(withId(R.id.text_simple)) + .check(matches(allOf(isDisplayed(), withText(R.string.text_simple)))) + .perform(swipeLeft()) + .check(matches(allOf(isDisplayed(), withText(R.string.text_simple)))) + .perform(swipeRight()) + .check(matches(allOf(isDisplayed(), withText(R.string.text_simple)))); + } + +} |