blob: 90257bc59a90aa4e1923c4b657c861b66bb7c826 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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))));
}
}
|