зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1307534 - Test that homepanel migration keep hidden panels hidden r=sebastian
MozReview-Commit-ID: 3s4aM2g4XTi --HG-- extra : rebase_source : 285dcc75a8c827d6895b4800af806fe681a28bca
This commit is contained in:
Родитель
2d6f446c93
Коммит
49c647af94
|
@ -81,7 +81,24 @@ public class TestHomeConfigPrefsBackendMigration {
|
|||
));
|
||||
}
|
||||
|
||||
private JSONArray createConfigsForList(Context context, PanelType[] panels, int defaultIndex) throws JSONException {
|
||||
private JSONArray createDisabledConfigsForList(Context context,
|
||||
PanelType[] panels) throws JSONException {
|
||||
final JSONArray jsonPanels = new JSONArray();
|
||||
|
||||
for (int i = 0; i < panels.length; i++) {
|
||||
final PanelType panel = panels[i];
|
||||
|
||||
jsonPanels.put(HomeConfig.createBuiltinPanelConfig(context, panel,
|
||||
EnumSet.of(PanelConfig.Flags.DISABLED_PANEL)).toJSON());
|
||||
}
|
||||
|
||||
return jsonPanels;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private JSONArray createConfigsForList(Context context, PanelType[] panels,
|
||||
int defaultIndex) throws JSONException {
|
||||
if (defaultIndex < 0 || defaultIndex >= panels.length) {
|
||||
throw new IllegalArgumentException("defaultIndex must point to panel in the array");
|
||||
}
|
||||
|
@ -120,7 +137,17 @@ public class TestHomeConfigPrefsBackendMigration {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void checkListContainsExpectedPanels(JSONArray jsonPanels, PanelType[] expected) throws JSONException {
|
||||
private void checkAllPanelsAreDisabled(JSONArray jsonPanels) throws JSONException {
|
||||
for (int i = 0; i < jsonPanels.length(); i++) {
|
||||
final JSONObject jsonPanelConfig = jsonPanels.getJSONObject(i);
|
||||
final PanelConfig config = new PanelConfig(jsonPanelConfig);
|
||||
|
||||
assertTrue("Non disabled panel \"" + config.getType().name() + "\" found in list, excpected all panels to be disabled", config.isDisabled());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkListContainsExpectedPanels(JSONArray jsonPanels,
|
||||
PanelType[] expected) throws JSONException {
|
||||
// Given the short lists we have here an ArraySet might be more appropriate, but it requires API >= 23.
|
||||
final Set<PanelType> expectedSet = new HashSet<>();
|
||||
for (PanelType panelType : expected) {
|
||||
|
@ -152,7 +179,7 @@ public class TestHomeConfigPrefsBackendMigration {
|
|||
// We want to calculate the number of iterations here to make sure we cover all provided constellations.
|
||||
// Iterating over the array and manually checking for each version could result in constellations
|
||||
// being skipped if there are any gaps in the array
|
||||
final int firstTestedVersion = HomeConfigPrefsBackend.VERSION - (migrationConstellations.size() - 1);
|
||||
final int firstTestedVersion = HomeConfigPrefsBackend.VERSION - (migrationConstellations.size() - 1);
|
||||
|
||||
// The last constellation is only used for the counts / expected outputs, hence we start
|
||||
// with the second-last constellation
|
||||
|
@ -196,4 +223,42 @@ public class TestHomeConfigPrefsBackendMigration {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that if all panels are disabled, the migration retains all panels as being disabled
|
||||
// (in addition to correctly removing panels as necessary).
|
||||
@Test
|
||||
public void testMigrationRetainsAllPanelsHiddenAfter6() throws JSONException {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
|
||||
final Pair<PanelType[], PanelType[]> finalConstellation = migrationConstellations.get(HomeConfigPrefsBackend.VERSION);
|
||||
assertNotNull("It looks like you added a HomeConfig migration, please add an appropriate entry to migrationConstellations",
|
||||
finalConstellation);
|
||||
|
||||
final int firstTestedVersion = HomeConfigPrefsBackend.VERSION - (migrationConstellations.size() - 1);
|
||||
|
||||
for (int testVersion = HomeConfigPrefsBackend.VERSION - 1; testVersion >= firstTestedVersion; testVersion--) {
|
||||
final Pair<PanelType[], PanelType[]> currentConstellation = migrationConstellations.get(testVersion);
|
||||
assertNotNull("No constellation for version " + testVersion + " - you must provide a constellation for every version upgrade in the list",
|
||||
currentConstellation);
|
||||
|
||||
final PanelType[] inputList = currentConstellation.first;
|
||||
|
||||
JSONArray jsonPanels = createDisabledConfigsForList(context, inputList);
|
||||
|
||||
jsonPanels = HomeConfigPrefsBackend.migratePrefsFromVersionToVersion(context, testVersion, testVersion + 1, jsonPanels, null);
|
||||
|
||||
// All panels should remain disabled after the migration
|
||||
checkAllPanelsAreDisabled(jsonPanels);
|
||||
|
||||
// Duplicated from previous test:
|
||||
// Verify that the panels remaining after the migration correspond to the input panels
|
||||
// for the next migration
|
||||
final PanelType[] expectedOutputList = migrationConstellations.get(testVersion + 1).first;
|
||||
|
||||
assertEquals("Number of panels after migration doesn't match expected count",
|
||||
jsonPanels.length(), expectedOutputList.length);
|
||||
|
||||
checkListContainsExpectedPanels(jsonPanels, expectedOutputList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче