Merge "Remove the feature flag and dead code for the old time zone picker" am: 6bb4b5ca43

am: 78e132773a

Change-Id: Ie8890265b7dd1b5248ccef4dbb0f6fd58da55f85
This commit is contained in:
Neil Fuller
2018-11-13 02:03:38 -08:00
committed by android-build-merger
10 changed files with 1 additions and 568 deletions

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2016 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.settings;
import static com.google.common.truth.Truth.assertThat;
import android.text.Spanned;
import android.text.style.TtsSpan;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.android.settings.datetime.ZonePicker;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowLibcoreTimeZoneNames;
import com.android.settings.testutils.shadow.ShadowTimeZoneNames;
import com.android.settings.testutils.shadow.ShadowZoneGetterData;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {
ShadowLibcoreTimeZoneNames.class,
ShadowLibcoreTimeZoneNames.ShadowZoneStringsCache.class,
ShadowTimeZoneNames.class,
ShadowZoneGetterData.class,
}
)
public class ZonePickerTest {
@Test
public void testConstructTimeZoneAdapter() {
final SimpleAdapter adapter =
ZonePicker.constructTimezoneAdapter(RuntimeEnvironment.application, true);
assertThat(adapter).isNotNull();
ViewGroup parent = new FrameLayout(RuntimeEnvironment.application);
ViewGroup convertView = new FrameLayout(RuntimeEnvironment.application);
TextView text1 = new TextView(RuntimeEnvironment.application);
text1.setId(android.R.id.text1);
convertView.addView(text1);
TextView text2 = new TextView(RuntimeEnvironment.application);
text2.setId(android.R.id.text2);
convertView.addView(text2);
adapter.getView(0, convertView, parent);
final CharSequence text = text2.getText();
assertThat(text).isInstanceOf(Spanned.class);
final TtsSpan[] spans = ((Spanned) text).getSpans(0, text.length(), TtsSpan.class);
// GMT offset label should have TTS spans
assertThat(spans.length).isGreaterThan(0);
}
}

View File

@@ -1,109 +0,0 @@
package com.android.settings.datetime;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.datetime.ZoneGetter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZonePickerComparatorTest {
// Strings in Chinese are sorted by alphabet order of their Pinyin.
// "伦敦" -> "lundun"; "纽约" -> "niuyue"; "悉尼" -> "xini"
// "开罗" -> "kailuo"; "雅典" -> "yadian"; "上海" -> "shanghai"
private static final String[] TEST_CHINESE_NAME =
{"伦敦", "纽约", "悉尼", "开罗", "雅典", "上海"};
private static final String[] ORDERED_CHINESE_NAME =
{"开罗", "伦敦", "纽约", "上海", "悉尼", "雅典"};
private static final String[] TEST_ENGLISH_NAME =
{"London", "New York", "Sydney", "Cairo", "Athens", "Shanghai"};
private static final String[] ORDERED_ENGLISH_NAME =
{"Athens", "Cairo", "London", "New York", "Shanghai", "Sydney"};
private static final Locale INIT_LOCALE = Locale.getDefault();
private Map<String, List<String>> mTestDataMap;
private List<Map<String, Object>> mTestList;
@Before
public void setUp() {
mTestDataMap = new HashMap<>();
mTestDataMap.put("zh_CN", Arrays.asList(TEST_CHINESE_NAME));
mTestDataMap.put("en_US", Arrays.asList(TEST_ENGLISH_NAME));
}
@After
public void tearDown() {
Locale.setDefault(INIT_LOCALE);
}
@Test
public void testComparator_sortChineseString() {
String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
mTestList = getMockZonesList("zh_CN");
Locale.setDefault(new Locale("zh"));
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_CHINESE_NAME[i]);
}
}
@Test
public void testComparator_sortEnglishString() {
String sortKey = ZoneGetter.KEY_DISPLAY_LABEL;
mTestList = getMockZonesList("en_US");
Locale.setDefault(new Locale("en"));
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey).toString()).isEqualTo(ORDERED_ENGLISH_NAME[i]);
}
}
@Test
public void testComparator_sortInteger() {
String sortKey = ZoneGetter.KEY_OFFSET;
// TestList of any locale can be selected to test integer sorting.
mTestList = getMockZonesList("en_US");
mTestList.sort(new ZonePicker.MyComparator(sortKey));
for (int i = 0; i < mTestList.size(); i++) {
assertThat(mTestList.get(i).get(sortKey)).isEqualTo(i);
}
}
private List<Map<String, Object>> getMockZonesList(String locale) {
List<Map<String, Object>> zones = new ArrayList<>();
List<String> testData = mTestDataMap.get(locale);
TimeZone tz = TimeZone.getDefault();
int testSize = testData.size();
for (int i = 0; i < testSize; i++) {
zones.add(createMockDisplayEntry(tz, "GMT+08:00", testData.get(i), testSize - i - 1));
}
return zones;
}
private Map<String, Object> createMockDisplayEntry(
TimeZone tz, CharSequence gmtOffsetText, CharSequence displayName, int offsetMillis) {
Map<String, Object> map = new HashMap<>();
map.put(ZoneGetter.KEY_ID, tz.getID());
map.put(ZoneGetter.KEY_DISPLAYNAME, displayName.toString());
map.put(ZoneGetter.KEY_DISPLAY_LABEL, displayName);
map.put(ZoneGetter.KEY_GMT, gmtOffsetText.toString());
map.put(ZoneGetter.KEY_OFFSET_LABEL, gmtOffsetText);
map.put(ZoneGetter.KEY_OFFSET, offsetMillis);
return map;
}
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2017 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.settings.datetime;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowZoneGetter;
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZonePickerTest {
private Activity mActivity;
private ZonePicker mZonePicker;
@Before
public void setUp() {
mActivity = Robolectric.setupActivity(Activity.class);
mZonePicker = spy(ZonePicker.class);
ReflectionHelpers.setField(mZonePicker, "mVisibilityLoggerMixin",
mock(VisibilityLoggerMixin.class));
}
@Test
@Config(shadows = ShadowZoneGetter.class)
public void testLaunch() {
// Shouldn't crash
mActivity.getFragmentManager().beginTransaction().add(mZonePicker, "test_tag").commit();
// Should render
verify(mZonePicker).onCreateView(
nullable(LayoutInflater.class),
nullable(ViewGroup.class),
nullable(Bundle.class));
}
}