• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.settings;
18 
19 import static androidx.preference.PreferenceFragmentCompat.ARG_PREFERENCE_ROOT;
20 import static androidx.test.espresso.Espresso.onView;
21 import static androidx.test.espresso.action.ViewActions.click;
22 import static androidx.test.espresso.assertion.ViewAssertions.matches;
23 import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem;
24 import static androidx.test.espresso.intent.Intents.intended;
25 import static androidx.test.espresso.intent.matcher.BundleMatchers.hasEntry;
26 import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
27 import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra;
28 import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
29 import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
30 import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
31 import static androidx.test.espresso.matcher.ViewMatchers.withId;
32 import static androidx.test.espresso.matcher.ViewMatchers.withText;
33 
34 import static com.android.launcher3.settings.SettingsActivity.DEVELOPER_OPTIONS_KEY;
35 import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARGS;
36 import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ROOT_KEY;
37 
38 import static com.google.common.truth.Truth.assertThat;
39 
40 import static org.hamcrest.Matchers.allOf;
41 import static org.hamcrest.Matchers.equalTo;
42 
43 import android.content.Context;
44 import android.content.Intent;
45 import android.os.Bundle;
46 
47 import androidx.test.core.app.ActivityScenario;
48 import androidx.test.core.app.ApplicationProvider;
49 import androidx.test.espresso.intent.Intents;
50 import androidx.test.ext.junit.runners.AndroidJUnit4;
51 
52 import com.android.launcher3.R;
53 import com.android.systemui.shared.plugins.PluginPrefs;
54 
55 import org.junit.After;
56 import org.junit.Before;
57 import org.junit.Ignore;
58 import org.junit.Test;
59 import org.junit.runner.RunWith;
60 
61 @RunWith(AndroidJUnit4.class)
62 public class SettingsActivityTest {
63 
64     private Context mApplicationContext;
65 
66     @Before
setUp()67     public void setUp() {
68         mApplicationContext = ApplicationProvider.getApplicationContext();
69         Intents.init();
70     }
71 
72     @After
tearDown()73     public void tearDown() {
74         Intents.release();
75     }
76 
77     @Test
78     @Ignore  // b/199309785
testSettings_aboutTap_launchesActivity()79     public void testSettings_aboutTap_launchesActivity() {
80         ActivityScenario.launch(SettingsActivity.class);
81         onView(withId(R.id.recycler_view)).perform(
82                 actionOnItem(hasDescendant(withText("About")), click()));
83 
84         intended(allOf(
85                 hasComponent(SettingsActivity.class.getName()),
86                 hasExtra(
87                         equalTo(EXTRA_FRAGMENT_ARGS),
88                         hasEntry(ARG_PREFERENCE_ROOT, "about_screen"))));
89     }
90 
91     @Test
92     @Ignore  // b/199309785
testSettings_developerOptionsTap_launchesActivityWithFragment()93     public void testSettings_developerOptionsTap_launchesActivityWithFragment() {
94         PluginPrefs.setHasPlugins(mApplicationContext);
95         ActivityScenario.launch(SettingsActivity.class);
96         onView(withId(R.id.recycler_view)).perform(
97                 actionOnItem(hasDescendant(withText("Developer Options")), click()));
98 
99         intended(allOf(
100                 hasComponent(SettingsActivity.class.getName()),
101                 hasExtra(EXTRA_FRAGMENT_ROOT_KEY, DEVELOPER_OPTIONS_KEY)));
102     }
103 
104     @Test
105     @Ignore  // b/199309785
testSettings_aboutScreenIntent()106     public void testSettings_aboutScreenIntent() {
107         Bundle fragmentArgs = new Bundle();
108         fragmentArgs.putString(ARG_PREFERENCE_ROOT, "about_screen");
109 
110         Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
111                 .putExtra(EXTRA_FRAGMENT_ARGS, fragmentArgs);
112         ActivityScenario.launch(intent);
113 
114         onView(withText("About")).check(matches(isDisplayed()));
115         onView(withText("Version")).check(matches(isDisplayed()));
116         onView(withContentDescription("Navigate up")).check(matches(isDisplayed()));
117     }
118 
119     @Test
120     @Ignore  // b/199309785
testSettings_developerOptionsFragmentIntent()121     public void testSettings_developerOptionsFragmentIntent() {
122         Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
123                 .putExtra(EXTRA_FRAGMENT_ROOT_KEY, DEVELOPER_OPTIONS_KEY);
124         ActivityScenario.launch(intent);
125 
126         onView(withText("Developer Options")).check(matches(isDisplayed()));
127         onView(withId(R.id.filter_box)).check(matches(isDisplayed()));
128         onView(withContentDescription("Navigate up")).check(matches(isDisplayed()));
129     }
130 
131     @Test
132     @Ignore  // b/199309785
testSettings_backButtonFinishesActivity()133     public void testSettings_backButtonFinishesActivity() {
134         Bundle fragmentArgs = new Bundle();
135         fragmentArgs.putString(ARG_PREFERENCE_ROOT, "about_screen");
136         Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
137                 .putExtra(EXTRA_FRAGMENT_ARGS, fragmentArgs);
138         ActivityScenario<SettingsActivity> scenario = ActivityScenario.launch(intent);
139 
140         onView(withContentDescription("Navigate up")).perform(click());
141         scenario.onActivity(activity -> assertThat(activity.isFinishing()).isTrue());
142     }
143 }
144