-
Notifications
You must be signed in to change notification settings - Fork 314
/
ActionBarTest.java
105 lines (85 loc) · 3.39 KB
/
ActionBarTest.java
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
/*
* 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 androidx.test.ui.app;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import android.test.ActivityInstrumentationTestCase2;
import androidx.test.filters.LargeTest;
/**
* Demonstrates Espresso with action bar and contextual action mode.
* {@link openActionBarOverflowOrOptionsMenu()} opens the overflow menu from an action bar.
* {@link openContextualActionModeOverflowMenu()} opens the overflow menu from an contextual action
* mode.
*/
@LargeTest
public class ActionBarTest extends ActivityInstrumentationTestCase2<ActionBarTestActivity> {
@SuppressWarnings("deprecation")
public ActionBarTest() {
// This constructor was deprecated - but we want to support lower API levels.
super("androidx.test.ui.app", ActionBarTestActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
}
@SuppressWarnings("unchecked")
public void testClickActionBarItem() {
onView(withId(R.id.hide_contextual_action_bar))
.perform(click());
onView(withId(R.id.action_save))
.perform(click());
onView(withId(R.id.text_action_bar_result))
.check(matches(withText("Save")));
}
@SuppressWarnings("unchecked")
public void testClickActionModeItem() {
onView(withId(R.id.show_contextual_action_bar))
.perform(click());
onView((withId(R.id.action_lock)))
.perform(click());
onView(withId(R.id.text_action_bar_result))
.check(matches(withText("Lock")));
}
@SuppressWarnings("unchecked")
public void testActionBarOverflow() {
onView(withId(R.id.hide_contextual_action_bar))
.perform(click());
// Open the overflow menu from action bar
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
onView(withText("World"))
.perform(click());
onView(withId(R.id.text_action_bar_result))
.check(matches(withText("World")));
}
@SuppressWarnings("unchecked")
public void testActionModeOverflow() {
onView(withId(R.id.show_contextual_action_bar))
.perform(click());
// Open the overflow menu from contextual action mode.
openContextualActionModeOverflowMenu();
onView(withText("Key"))
.perform(click());
onView(withId(R.id.text_action_bar_result))
.check(matches(withText("Key")));
}
}