diff options
author | Stas Negara <snegara@google.com> | 2015-06-19 15:59:31 -0700 |
---|---|---|
committer | Stas Negara <snegara@google.com> | 2015-06-25 16:05:13 -0700 |
commit | eb276b62427e3124220d7ea2e0a920728af3dcd1 (patch) | |
tree | e99b3579166b413a4e02a81ae41b02f621d2b456 | |
parent | 1474d89678625c1d03324bab6b8c90069222083a (diff) | |
download | testing-eb276b62427e3124220d7ea2e0a920728af3dcd1.tar.gz |
Adjust the default cloud device config. to app's settings.
Also, instead of throwing exceptions for unsupported dimension
values, just check for their validity before enabling them.
This CL fixed bug b/21852776.
Change-Id: Ifcd245966dd633a17723a685313c596165167326
8 files changed, 80 insertions, 29 deletions
diff --git a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java index ccf05d1..df10c86 100644 --- a/src/com/google/gct/testing/CloudConfigurationProviderImpl.java +++ b/src/com/google/gct/testing/CloudConfigurationProviderImpl.java @@ -141,18 +141,24 @@ public class CloudConfigurationProviderImpl extends CloudConfigurationProvider { private List<? extends CloudConfiguration> getDefaultConfigurations(AndroidFacet facet, Kind kind) { if (kind == SINGLE_DEVICE) { - DeviceDimension.Device defaultDevice = DeviceDimension.getDefaultDevice(); - ApiDimension.ApiLevel defaultApi = ApiDimension.getDefaultApi(); - if (defaultDevice == null || defaultApi == null) { + CloudConfigurationImpl defaultConfiguration = + new CloudConfigurationImpl(CloudConfigurationImpl.DEFAULT_DEVICE_CONFIGURATION_ID, "", SINGLE_DEVICE, AndroidIcons.Display, facet); + defaultConfiguration.apiDimension.enableDefault(); + ImmutableList<CloudTestingType> enabledApis = defaultConfiguration.apiDimension.getEnabledTypes(); + if (enabledApis.isEmpty()) { return ImmutableList.of(); } - String defaultDeviceName = defaultDevice.getConfigurationDialogDisplayName() + " API " + defaultApi.getId(); - CloudConfigurationImpl defaultConfiguration = new CloudConfigurationImpl( - CloudConfigurationImpl.DEFAULT_DEVICE_CONFIGURATION_ID, defaultDeviceName, SINGLE_DEVICE, AndroidIcons.Display, facet); - defaultConfiguration.deviceDimension.enable(defaultDevice); - defaultConfiguration.apiDimension.enable(defaultApi); - defaultConfiguration.languageDimension.enable(LanguageDimension.getDefaultLanguage()); - defaultConfiguration.orientationDimension.enable(OrientationDimension.getDefaultOrientation()); + defaultConfiguration.deviceDimension.enableDefault(enabledApis.get(0).getId()); + defaultConfiguration.languageDimension.enableDefault(); + defaultConfiguration.orientationDimension.enableDefault(); + + ImmutableList<CloudTestingType> enabledDevices = defaultConfiguration.deviceDimension.getEnabledTypes(); + if (enabledDevices.isEmpty() || defaultConfiguration.languageDimension.getEnabledTypes().isEmpty() + || defaultConfiguration.orientationDimension.getEnabledTypes().isEmpty()) { + return ImmutableList.of(); + } + + defaultConfiguration.setName(enabledDevices.get(0).getConfigurationDialogDisplayName() + " API " + enabledApis.get(0).getId()); defaultConfiguration.setNonEditable(); return ImmutableList.of(defaultConfiguration); } diff --git a/src/com/google/gct/testing/TwoPanelTree.java b/src/com/google/gct/testing/TwoPanelTree.java index 469fca3..60a316c 100644 --- a/src/com/google/gct/testing/TwoPanelTree.java +++ b/src/com/google/gct/testing/TwoPanelTree.java @@ -615,7 +615,7 @@ public class TwoPanelTree extends MouseAdapter implements ListSelectionListener, if (tree instanceof CheckboxTree) { if (!isAnyLeafChecked((CheckboxTree) tree) && list.getSelectedIndex() != -1 - && getSelectedDimension().getEnabledTypes().size() > 0) { + && !getSelectedDimension().getEnabledTypes().isEmpty()) { // Avoid double rendering when a user tries to uncheck a radio button, which is not allowed anyway, but will cause // weird text rendering quirks. return this; @@ -715,7 +715,7 @@ public class TwoPanelTree extends MouseAdapter implements ListSelectionListener, renderer.setText(dimension.getDisplayName() + " (" + dimension.getEnabledTypes().size() + "/" + dimension.getSupportedDomain().size() + ")"); - if (dimension.getEnabledTypes().size() < 1) { + if (dimension.getEnabledTypes().isEmpty()) { renderer.setForeground(JBColor.RED); renderer.setFont(renderer.getFont().deriveFont(Font.BOLD)); } diff --git a/src/com/google/gct/testing/dimension/ApiDimension.java b/src/com/google/gct/testing/dimension/ApiDimension.java index 8e0e274..fc4d4e0 100644 --- a/src/com/google/gct/testing/dimension/ApiDimension.java +++ b/src/com/google/gct/testing/dimension/ApiDimension.java @@ -136,13 +136,25 @@ public class ApiDimension extends CloudConfigurationDimension { return FULL_DOMAIN == null || FULL_DOMAIN.isEmpty(); } - public static ApiLevel getDefaultApi() { + private static ApiLevel getDefaultApi() { if (defaultApi == null) { getFullDomain(); } return defaultApi; } + public void enableDefault() { + if (getDefaultApi() == null) { + return; + } + List<? extends CloudTestingType> appSupportedDomain = getAppSupportedDomain(); + if (appSupportedDomain.contains(defaultApi)) { + enable(defaultApi); + } else if (!appSupportedDomain.isEmpty()) { + enable(appSupportedDomain.get(0)); + } + } + @Override public String getDisplayName() { return DISPLAY_NAME; diff --git a/src/com/google/gct/testing/dimension/CloudConfigurationDimension.java b/src/com/google/gct/testing/dimension/CloudConfigurationDimension.java index 860a6de..98b7fab 100644 --- a/src/com/google/gct/testing/dimension/CloudConfigurationDimension.java +++ b/src/com/google/gct/testing/dimension/CloudConfigurationDimension.java @@ -93,8 +93,9 @@ public abstract class CloudConfigurationDimension { public void enable(CloudTestingType... types) { checkIsEditable(); for (CloudTestingType type : types) { - validateType(type); - enableType(type); + if (getSupportedDomain().contains(type)) { + enableType(type); + } } } @@ -102,8 +103,7 @@ public abstract class CloudConfigurationDimension { checkIsEditable(); Set<String> idsSet = Sets.newHashSet(ids); for (CloudTestingType type : types) { - if (idsSet.contains(type.getId())) { - validateType(type); + if (getSupportedDomain().contains(type) && idsSet.contains(type.getId())) { enableType(type); } } @@ -112,14 +112,15 @@ public abstract class CloudConfigurationDimension { public void disable(CloudTestingType... types) { checkIsEditable(); for (CloudTestingType type : types) { - validateType(type); enabledTypes.remove(type); } } public void setEnabled(CloudTestingType type, boolean isEnabled) { + if (!getSupportedDomain().contains(type)) { + return; + } checkIsEditable(); - validateType(type); if (isEnabled) { enableType(type); } else { @@ -155,12 +156,6 @@ public abstract class CloudConfigurationDimension { return ImmutableList.copyOf(enabledTypes); } - private void validateType(CloudTestingType type) { - if (!getSupportedDomain().contains(type)) { - throw new IllegalArgumentException("Type " + type + " is not supported in domain: " + getSupportedDomain()); - } - } - public boolean isEditable() { return myCloudConfiguration.isEditable(); } diff --git a/src/com/google/gct/testing/dimension/DeviceDimension.java b/src/com/google/gct/testing/dimension/DeviceDimension.java index a66e0d7..4d21823 100644 --- a/src/com/google/gct/testing/dimension/DeviceDimension.java +++ b/src/com/google/gct/testing/dimension/DeviceDimension.java @@ -59,7 +59,8 @@ public class DeviceDimension extends CloudConfigurationDimension { for (AndroidModel model : androidDeviceCatalog.getModels()) { Map<String, String> details = new HashMap<String, String>(); details.put("Display", model.getScreenX() + "x" + model.getScreenY()); - Device device = new Device(model.getId(), model.getName(), model.getManufacturer(), model.getForm(), details); + Device device = + new Device(model.getId(), model.getName(), model.getManufacturer(), model.getForm(), details, model.getSupportedVersionIds()); fullDomainBuilder.add(device); List<String> tags = model.getTags(); if (tags != null && tags.contains("default")) { @@ -80,13 +81,30 @@ public class DeviceDimension extends CloudConfigurationDimension { return FULL_DOMAIN == null || FULL_DOMAIN.isEmpty(); } - public static Device getDefaultDevice() { + private static Device getDefaultDevice() { if (defaultDevice == null) { getFullDomain(); } return defaultDevice; } + public void enableDefault(String minSupportedApiId) { + if (getDefaultDevice() == null) { + return; + } + if (defaultDevice.supportedVersionIds.contains(minSupportedApiId)) { + enable(defaultDevice); + } else { + for (CloudTestingType supportedTestingType : getAppSupportedDomain()) { + Device supportedDevice = (Device) supportedTestingType; + if (supportedDevice.isVirtual() && supportedDevice.supportedVersionIds.contains(minSupportedApiId)) { + enable(supportedDevice); + return; + } + } + } + } + @Override public String getDisplayName() { return DISPLAY_NAME; @@ -113,13 +131,15 @@ public class DeviceDimension extends CloudConfigurationDimension { private final String name; private final String manufacturer; private final String form; + private final List<String> supportedVersionIds; - public Device(String id, String name, String manufacturer, String form, Map<String, String> details) { + public Device(String id, String name, String manufacturer, String form, Map<String, String> details, List<String> supportedVersionIds) { this.id = id; this.manufacturer = manufacturer; this.name = name; this.form = form; this.details = details; + this.supportedVersionIds = supportedVersionIds; } @Override diff --git a/src/com/google/gct/testing/dimension/LanguageDimension.java b/src/com/google/gct/testing/dimension/LanguageDimension.java index 35e3581..bde5246 100644 --- a/src/com/google/gct/testing/dimension/LanguageDimension.java +++ b/src/com/google/gct/testing/dimension/LanguageDimension.java @@ -154,6 +154,18 @@ public class LanguageDimension extends CloudConfigurationDimension { return defaultLanguage; } + public void enableDefault() { + if (getDefaultLanguage() == null) { + return; + } + List<? extends CloudTestingType> appSupportedDomain = getAppSupportedDomain(); + if (appSupportedDomain.contains(defaultLanguage)) { + enable(defaultLanguage); + } else if (!appSupportedDomain.isEmpty()) { + enable(appSupportedDomain.get(0)); + } + } + public static Language getLanguage(final String locale) { try { return Iterables.find(getFullDomain(), new Predicate<Language>() { diff --git a/src/com/google/gct/testing/dimension/OrientationDimension.java b/src/com/google/gct/testing/dimension/OrientationDimension.java index 2d39dae..a3d596f 100644 --- a/src/com/google/gct/testing/dimension/OrientationDimension.java +++ b/src/com/google/gct/testing/dimension/OrientationDimension.java @@ -81,6 +81,12 @@ public class OrientationDimension extends CloudConfigurationDimension { return defaultOrientation; } + public void enableDefault() { + if (getDefaultOrientation() != null) { + enable(defaultOrientation); + } + } + @Override public String getDisplayName() { return DISPLAY_NAME; diff --git a/src/com/google/gct/testing/results/GoogleCloudTestingResultsForm.java b/src/com/google/gct/testing/results/GoogleCloudTestingResultsForm.java index cee3d3f..55a7d18 100644 --- a/src/com/google/gct/testing/results/GoogleCloudTestingResultsForm.java +++ b/src/com/google/gct/testing/results/GoogleCloudTestingResultsForm.java @@ -363,7 +363,7 @@ public class GoogleCloudTestingResultsForm extends TestResultsPanel @Override public boolean hasTestSuites() { - return getRoot().getChildren().size() > 0; + return !getRoot().getChildren().isEmpty(); } @Override |