Merge "Allow appending static preferences to RadioButtonPickerFragment"
This commit is contained in:
committed by
Android (Google) Code Review
commit
e4128eca14
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/battery_saver_schedule_settings_title"
|
||||
settings:staticPreferenceLocation="append">
|
||||
</PreferenceScreen >
|
@@ -18,6 +18,7 @@ package com.android.settings.core;
|
||||
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils
|
||||
.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_APPEND;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEYWORDS;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SEARCHABLE;
|
||||
@@ -315,6 +316,32 @@ public class PreferenceXmlParserUtilsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void extractMetadata_requestAppendProperty_shouldDefaultToFalse()
|
||||
throws Exception {
|
||||
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||
R.xml.display_settings,
|
||||
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
assertThat(bundle.getBoolean(METADATA_APPEND)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void extractMetadata_requestAppendProperty_shouldReturnCorrectValue()
|
||||
throws Exception {
|
||||
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||
R.xml.battery_saver_schedule_settings,
|
||||
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
assertThat(bundle.getBoolean(METADATA_APPEND)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resId the ID for the XML preference
|
||||
* @return an XML resource parser that points to the start tag
|
||||
|
@@ -209,6 +209,7 @@ public class ColorModePreferenceFragmentTest {
|
||||
|
||||
@Test
|
||||
public void onCreatePreferences_useNewTitle_shouldAddColorModePreferences() {
|
||||
when(mFragment.getContext()).thenReturn(RuntimeEnvironment.application);
|
||||
doNothing().when(mFragment).addPreferencesFromResource(anyInt());
|
||||
doNothing().when(mFragment).updateCandidates();
|
||||
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.widget;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -37,7 +38,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@@ -98,6 +101,26 @@ public class RadioButtonPickerFragmentTest {
|
||||
assertThat(mFragment.setDefaultKeyCalled).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticPreferencesPrepended_addedFirst() {
|
||||
mFragment.mAppendStaticPreferences = false;
|
||||
mFragment.updateCandidates();
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(mFragment);
|
||||
inOrder.verify(mFragment).addStaticPreferences(any());
|
||||
inOrder.verify(mFragment).getRadioButtonPreferenceCustomLayoutResId();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticPreferencesAppended_addedLast() {
|
||||
mFragment.mAppendStaticPreferences = true;
|
||||
mFragment.updateCandidates();
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(mFragment);
|
||||
inOrder.verify(mFragment).mayCheckOnlyRadioButton();
|
||||
inOrder.verify(mFragment).addStaticPreferences(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveNoCustomPreferenceLayout() {
|
||||
assertThat(mFragment.getRadioButtonPreferenceCustomLayoutResId()).isEqualTo(0);
|
||||
|
Reference in New Issue
Block a user