Enable new time zone picker

- Change the UI test due to UI changes

Bug: 73952488
Test: m RunSettingsRoboTest
Test: atest SettingsUITests:ZonePickerSettingsTest
Change-Id: I6d5716347e9debf429b757f1edd4118e86b70fab
This commit is contained in:
Victor Chang
2018-02-28 19:43:03 +00:00
parent b7d588f341
commit 335c0621d2
2 changed files with 22 additions and 30 deletions

View File

@@ -19,11 +19,11 @@ package com.android.settings.datetime;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.util.FeatureFlagUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.datetime.timezone.ZonePicker;
import com.android.settings.datetime.timezone.TimeZoneSettings;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.datetime.ZoneGetter;
@@ -51,7 +51,7 @@ public class TimeZonePreferenceController extends AbstractPreferenceController
return;
}
if (mZonePickerV2) {
preference.setFragment(ZonePicker.class.getName());
preference.setFragment(TimeZoneSettings.class.getName());
}
preference.setSummary(getTimeZoneOffsetAndName());
if( !((RestrictedPreference) preference).isDisabledByAdmin()) {

View File

@@ -32,8 +32,6 @@ import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.system.helpers.SettingsHelper;
import android.system.helpers.SettingsHelper.SettingsType;
import android.widget.ListView;
import android.widget.Spinner;
import org.junit.After;
import org.junit.Before;
@@ -102,16 +100,16 @@ public class ZonePickerSettingsTest {
// Test 2 time zones with no DST
@Test
public void testSelectReykjavik() throws Exception {
testSelectTimeZone("Iceland", "Reykjavik", "GMT+00:00", "Atlantic/Reykjavik");
testSelectTimeZone("Iceland", "Reykjavik", "GMT+00:00", "Atlantic/Reykjavik", true);
}
@Test
public void testSelectPhoenix() throws Exception {
testSelectTimeZone("United States", "Phoenix", "GMT-07:00", "America/Phoenix");
testSelectTimeZone("United States", "Phoenix", "GMT-07:00", "America/Phoenix", false);
}
private void testSelectTimeZone(String region, String timezone, String expectedTimeZoneOffset,
String expectedTimeZoneId) throws Exception {
String expectedTimeZoneId, boolean assumeOneTimeZoneInRegion) throws Exception {
mHelper.setIntSetting(SettingsType.GLOBAL, Settings.Global.AUTO_TIME_ZONE, 0);
SettingsHelper.launchSettingsPage(
@@ -121,16 +119,21 @@ public class ZonePickerSettingsTest {
assertTrue(selectTimeZone.isEnabled());
selectTimeZone.click();
// Select region in the dropdown list
selectScrollableItem(selectDropDownInSpinner(By.clazz(Spinner.class)),
new UiSelector().textContains(region))
wait(By.text("Region")).click();
// Speed-up the test by searching with the first 2 characters of the region name
wait(By.res("android", "search_src_text")).setText(region.substring(0, 2));
// Select region in the list
selectItemInList(new UiSelector().textContains(region))
.click();
// Select time zone
selectScrollableItem(selectTimeZoneList(),
new UiSelector().textContains(timezone))
.click();
// Only select time zone explicitly if there are more than one time zones in a region
if (!assumeOneTimeZoneInRegion) {
wait(By.text("Time Zone"));
selectItemInList(new UiSelector().textContains(timezone))
.click();
}
mDevice.pressBack();
// The select button should include the GMT offset in the summary
BySelector summarySelector = By.res("android:id/summary");
UiObject2 selectedTimeZone = selectTimeZone.findObject(summarySelector);
@@ -162,21 +165,10 @@ public class ZonePickerSettingsTest {
assertEquals(expectedTimeZoneId, TimeZone.getDefault().getID());
}
/**
* Perform click on {@link Spinner} and return the pop-up dropdown list.
* @return UiScrollable representing the pop-up dropdown after clicking on the spinner
*/
private UiScrollable selectDropDownInSpinner(BySelector spinnerSelector)
throws UiObjectNotFoundException {
UiObject2 spinner = wait(spinnerSelector);
spinner.click();
UiSelector dropDownSelector = new UiSelector().className(ListView.class);
return new UiScrollable(dropDownSelector);
}
private UiScrollable selectTimeZoneList() {
return new UiScrollable(new UiSelector().resourceId(SETTINGS_PACKAGE + ":id/tz_list"));
private UiObject selectItemInList(UiSelector childSelector) throws UiObjectNotFoundException {
UiScrollable recyclerView = new UiScrollable(
new UiSelector().resourceId(SETTINGS_PACKAGE + ":id/recycler_view"));
return selectScrollableItem(recyclerView, childSelector);
}
/**