Use regular preference theme for setup wizard
Use the regular preference theme rather than the settings specific one, because setup wizard doesn't want the space reserved for icon done in the settings theme. Also minor changes to Espresso FirstIdViewMatcher for a more descriptive message. Test: runtest --path tests/app/src/com/android/settings/dashboard/PreferenceThemeTest.java Bug: 33922083 Change-Id: Ic878ccf7b01cfa090ca4587b160e1f9dedfb8d3a
This commit is contained in:
@@ -95,6 +95,7 @@
|
||||
|
||||
<style name="PreferenceTheme.SetupWizard" parent="PreferenceTheme">
|
||||
<item name="preferenceFragmentStyle">@style/SetupWizardPreferenceFragmentStyle</item>
|
||||
<item name="preferenceStyle">@style/Preference.Material</item>
|
||||
</style>
|
||||
|
||||
<style name="SetupWizardPreferenceFragmentStyle" parent="PreferenceFragment.Material">
|
||||
|
@@ -34,7 +34,16 @@ public class FirstIdViewMatcher {
|
||||
private boolean mMatched;
|
||||
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(" is the first view that matches id.");
|
||||
String idDescription = Integer.toString(id);
|
||||
if (resources != null) {
|
||||
try {
|
||||
idDescription = resources.getResourceName(id);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
// No big deal, will just use the int value.
|
||||
idDescription = String.format("%s (resource name not found)", id);
|
||||
}
|
||||
}
|
||||
description.appendText("with first id: " + idDescription);
|
||||
}
|
||||
|
||||
public boolean matchesSafely(View view) {
|
||||
@@ -42,7 +51,7 @@ public class FirstIdViewMatcher {
|
||||
if (mMatched) {
|
||||
return false;
|
||||
} else {
|
||||
mMatched |= id == view.getId();
|
||||
mMatched = id == view.getId();
|
||||
return mMatched;
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.espresso.matcher.ViewMatchers.Visibility;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
@@ -33,9 +34,12 @@ import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.android.settings.dashboard.FirstIdViewMatcher.withFirstId;
|
||||
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class PreferenceThemeTest {
|
||||
@@ -54,10 +58,19 @@ public class PreferenceThemeTest {
|
||||
@Test
|
||||
public void startPhoneStatus_preferenceIconSpaceReserved() throws InterruptedException {
|
||||
launchPhoneStatus();
|
||||
onView(withId(android.R.id.icon_frame)).check(doesNotExist());
|
||||
onView(withId(R.id.icon_frame)).check(doesNotExist());
|
||||
onView(withFirstId(R.id.icon_container)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startSetupWizardLockScreen_preferenceIconSpaceNotReserved() {
|
||||
launchSetupWizardLockScreen();
|
||||
// Icons should not be shown, and the frame should not occupy extra space.
|
||||
onView(allOf(withId(R.id.icon_frame), withEffectiveVisibility(Visibility.VISIBLE)))
|
||||
.check(doesNotExist());
|
||||
onView(withId(R.id.icon_container)).check(doesNotExist());
|
||||
}
|
||||
|
||||
private void launchPhoneStatus() {
|
||||
final Intent settingsIntent = new Intent("android.settings.DEVICE_INFO_SETTINGS")
|
||||
.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
@@ -65,4 +78,12 @@ public class PreferenceThemeTest {
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent);
|
||||
}
|
||||
|
||||
private void launchSetupWizardLockScreen() {
|
||||
final Intent settingsIntent = new Intent("com.android.settings.SETUP_LOCK_SCREEN")
|
||||
.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
.setPackage(mTargetPackage)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user