SettingsFragmentTest fix
About a week ago, the root fragment name check against the config value was added for determining whether to show the back icon or the application icon in the action bar. Along with that change, we started tagging fragments to retrieve the root fragment by its tag for the said comparison.
This change did not make it into BaseTestActivity used for tests, which led to the action bar always returning back icon since the root fragment couldn't be retrieved with a tag.
bug: 132073547
Test: run robolectric test.
Change-Id: Id71a90ff2bb73dee0cce7aac623a0e2acd3e8df5
diff --git a/tests/robotests/src/com/android/car/settings/common/SettingsFragmentTest.java b/tests/robotests/src/com/android/car/settings/common/SettingsFragmentTest.java
index cf11631..a19e3dd 100644
--- a/tests/robotests/src/com/android/car/settings/common/SettingsFragmentTest.java
+++ b/tests/robotests/src/com/android/car/settings/common/SettingsFragmentTest.java
@@ -37,6 +37,7 @@
import com.android.car.settings.CarSettingsRobolectricTestRunner;
import com.android.car.settings.R;
+import com.android.car.settings.testutils.DummyFragment;
import com.android.car.settings.testutils.FragmentController;
import org.junit.Before;
@@ -272,7 +273,7 @@
@Test
public void onActivityCreated_hasAppIconIfRoot() {
mFragmentController.setup();
- TestSettingsFragment otherFragment = new TestSettingsFragment();
+ DummyFragment otherFragment = new DummyFragment();
mFragment.launchFragment(otherFragment);
FrameLayout actionBarContainer =
diff --git a/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java b/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
index ac770b9..5fff6f9 100644
--- a/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
+++ b/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
@@ -58,9 +58,10 @@
throw new IllegalArgumentException(
"cannot launch dialogs with launchFragment() - use showDialog() instead");
}
+ String tag = Integer.toString(getSupportFragmentManager().getBackStackEntryCount());
getSupportFragmentManager()
.beginTransaction()
- .replace(R.id.fragment_container, fragment)
+ .replace(R.id.fragment_container, fragment, tag)
.addToBackStack(null)
.commit();
}
diff --git a/tests/robotests/src/com/android/car/settings/testutils/DummyFragment.java b/tests/robotests/src/com/android/car/settings/testutils/DummyFragment.java
index ec93bee..dc6cfba 100644
--- a/tests/robotests/src/com/android/car/settings/testutils/DummyFragment.java
+++ b/tests/robotests/src/com/android/car/settings/testutils/DummyFragment.java
@@ -16,10 +16,15 @@
package com.android.car.settings.testutils;
-import androidx.fragment.app.Fragment;
+import com.android.car.settings.R;
+import com.android.car.settings.common.SettingsFragment;
/**
* Empty Fragment.
*/
-public class DummyFragment extends Fragment {
+public class DummyFragment extends SettingsFragment {
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.settings_fragment;
+ }
}