Give each preference screen its own activity and toolbar title
This change is in preparation for each preference screen having its own collapsible toolbar with its specific title.
Test: Subsettings open with activity transition and title changes
Bug: 187732263
Change-Id: Iac44d688539195ddb6c2aca0a96d737ce7727071
diff --git a/robolectric_tests/Android.bp b/robolectric_tests/Android.bp
index bf32362..9ed26ff 100644
--- a/robolectric_tests/Android.bp
+++ b/robolectric_tests/Android.bp
@@ -45,9 +45,14 @@
java_resources: [":launcher3-robolectric-resources"],
static_libs: [
"truth-prebuilt",
+ "androidx.test.espresso.contrib",
+ "androidx.test.espresso.core",
+ "androidx.test.espresso.intents",
+ "androidx.test.ext.junit",
"androidx.test.runner",
"androidx.test.rules",
"mockito-robolectric-prebuilt",
+ "SystemUISharedLib",
],
robolectric_prebuilt_version: "4.5.1",
instrumentation_for: "Launcher3",
diff --git a/robolectric_tests/src/com/android/launcher3/settings/SettingsActivityTest.java b/robolectric_tests/src/com/android/launcher3/settings/SettingsActivityTest.java
new file mode 100644
index 0000000..85bf28e
--- /dev/null
+++ b/robolectric_tests/src/com/android/launcher3/settings/SettingsActivityTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2021 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.android.launcher3.settings;
+
+import static androidx.preference.PreferenceFragmentCompat.ARG_PREFERENCE_ROOT;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem;
+import static androidx.test.espresso.intent.Intents.intended;
+import static androidx.test.espresso.intent.matcher.BundleMatchers.hasEntry;
+import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
+import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra;
+import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+import static androidx.test.espresso.matcher.ViewMatchers.withText;
+
+import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT;
+import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARGS;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.equalTo;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.espresso.intent.Intents;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.launcher3.R;
+import com.android.systemui.shared.plugins.PluginPrefs;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class SettingsActivityTest {
+
+ private Context mApplicationContext;
+
+ @Before
+ public void setUp() {
+ mApplicationContext = ApplicationProvider.getApplicationContext();
+ Intents.init();
+ }
+
+ @After
+ public void tearDown() {
+ Intents.release();
+ }
+
+ @Test
+ public void testSettings_aboutTap_launchesActivity() {
+ ActivityScenario.launch(SettingsActivity.class);
+ onView(withId(R.id.recycler_view)).perform(
+ actionOnItem(hasDescendant(withText("About")), click()));
+
+ intended(allOf(
+ hasComponent(SettingsActivity.class.getName()),
+ hasExtra(
+ equalTo(EXTRA_FRAGMENT_ARGS),
+ hasEntry(ARG_PREFERENCE_ROOT, "about_screen"))));
+ }
+
+ @Test
+ public void testSettings_developerOptionsTap_launchesActivityWithFragment() {
+ PluginPrefs.setHasPlugins(mApplicationContext);
+ ActivityScenario.launch(SettingsActivity.class);
+ onView(withId(R.id.recycler_view)).perform(
+ actionOnItem(hasDescendant(withText("Developer Options")), click()));
+
+ intended(allOf(
+ hasComponent(SettingsActivity.class.getName()),
+ hasExtra(EXTRA_FRAGMENT, DeveloperOptionsFragment.class.getName())));
+ }
+
+ @Test
+ public void testSettings_aboutScreenIntent() {
+ Bundle fragmentArgs = new Bundle();
+ fragmentArgs.putString(ARG_PREFERENCE_ROOT, "about_screen");
+
+ Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
+ .putExtra(EXTRA_FRAGMENT_ARGS, fragmentArgs);
+ ActivityScenario.launch(intent);
+
+ onView(withText("About")).check(matches(isDisplayed()));
+ onView(withText("Version")).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testSettings_developerOptionsFragmentIntent() {
+ Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
+ .putExtra(EXTRA_FRAGMENT, DeveloperOptionsFragment.class.getName());
+ ActivityScenario.launch(intent);
+
+ onView(withText("Developer Options")).check(matches(isDisplayed()));
+ onView(withId(R.id.filter_box)).check(matches(isDisplayed()));
+ }
+
+ @Test
+ public void testSettings_intentWithUnknownFragment() {
+ String fragmentClass = PreferenceFragmentCompat.class.getName();
+ Intent intent = new Intent(mApplicationContext, SettingsActivity.class)
+ .putExtra(EXTRA_FRAGMENT, fragmentClass);
+
+ try {
+ ActivityScenario.launch(intent);
+ Assert.fail("Should have thrown an IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).contains(fragmentClass);
+ }
+ }
+}