Commit b480f886 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Split zip volumes apart from provided volume type

Bug: 846591
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Icbadc037d959c4f61912624835ff3ec8929d4a41
Reviewed-on: https://chromium-review.googlesource.com/1137807
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575201}
parent eddfcff9
......@@ -391,6 +391,23 @@ function NavigationListModel(
// in list.js.
}
/**
* ZipArchiver mounts zip files as PROVIDED volume type.
* This is a special case for zip volumes to be able to split them apart from
* PROVIDED.
* @const
*/
NavigationListModel.ZIP_VOLUME_TYPE = '_ZIP_VOLUME_';
/**
* Extension id that can mount zip files.
* @const
*/
NavigationListModel.ZIP_EXTENSION_IDS = [
'dmboannefpncccogfdikhmhpmdnddgoe', // ZipArchiver
'oedeeodfidgoollimchfdnbmhcpnklnd', // ZipUnpacker
];
/**
* NavigationList inherits cr.EventTarget.
*/
......@@ -473,7 +490,7 @@ NavigationListModel.prototype.flatNavigationItems_ = function() {
* 4.1. Downloads
* 4.2. Play files (android volume) (if enabled).
* 4.3. Linux files (crostini volume or fake item) (if enabled).
* 5. Other volumes (MTP, ARCHIVE, REMOVABLE).
* 5. Other volumes (MTP, ARCHIVE, REMOVABLE, Zip volumes).
* 6. Drive volumes.
* 7. Other FSP (File System Provider) (when mounted).
* 8. Add new services if (it exists).
......@@ -489,17 +506,33 @@ NavigationListModel.prototype.orderAndNestItems_ = function() {
for (let i = 0; i < volumeList.length; i++) {
const volumeType = volumeList[i].volumeInfo.volumeType;
volumeList[i].originalOrder = i;
let providedType;
let volumeId;
switch (volumeType) {
case VolumeManagerCommon.VolumeType.CROSTINI:
case VolumeManagerCommon.VolumeType.DOWNLOADS:
case VolumeManagerCommon.VolumeType.ANDROID_FILES:
volumeIndexes[volumeType] = i;
break;
case VolumeManagerCommon.VolumeType.PROVIDED:
// ZipArchiver mounts zip files as PROVIDED volume type, however we
// want to display mounted zip files the same way as archive, so
// splitting them apart from PROVIDED.
volumeId = volumeList[i].volumeInfo.volumeId;
providedType = VolumeManagerCommon.VolumeType.PROVIDED;
if (NavigationListModel.ZIP_EXTENSION_IDS.some(
extension_id => volumeId.includes(extension_id)))
providedType = NavigationListModel.ZIP_VOLUME_TYPE;
if (!volumeIndexes[providedType]) {
volumeIndexes[providedType] = [i];
} else {
volumeIndexes[providedType].push(i);
}
break;
case VolumeManagerCommon.VolumeType.REMOVABLE:
case VolumeManagerCommon.VolumeType.ARCHIVE:
case VolumeManagerCommon.VolumeType.MTP:
case VolumeManagerCommon.VolumeType.DRIVE:
case VolumeManagerCommon.VolumeType.PROVIDED:
case VolumeManagerCommon.VolumeType.MEDIA_VIEW:
if (!volumeIndexes[volumeType]) {
volumeIndexes[volumeType] = [i];
......@@ -610,11 +643,13 @@ NavigationListModel.prototype.orderAndNestItems_ = function() {
// Join MEDIA_VIEW, MTP, ARCHIVE and REMOVABLE. These types belong to same
// section.
const zipIndexes = volumeIndexes[NavigationListModel.ZIP_VOLUME_TYPE] || [];
const otherVolumes =
[].concat(
getVolumes(VolumeManagerCommon.VolumeType.REMOVABLE),
getVolumes(VolumeManagerCommon.VolumeType.ARCHIVE),
getVolumes(VolumeManagerCommon.VolumeType.MTP))
getVolumes(VolumeManagerCommon.VolumeType.MTP),
zipIndexes.map(idx => volumeList[idx]))
.sort((volume1, volume2) => {
return volume1.originalOrder - volume2.originalOrder;
});
......
......@@ -175,6 +175,9 @@ function testOrderAndNestItems() {
'recent-label', NavigationModelItemType.RECENT,
{toURL: () => 'fake-entry://recent'});
const addNewServicesItem = null;
const zipVolumeId = 'provided:dmboannefpncccogfdikhmhpmdnddgoe:' +
'~%2FDownloads%2Fazip_file%2Ezip:' +
'096eaa592ea7e8ffb9a27435e50dabd6c809c125';
// Create different volumes.
volumeManager.volumeInfoList.push(
......@@ -185,7 +188,7 @@ function testOrderAndNestItems() {
VolumeManagerCommon.VolumeType.PROVIDED, 'provided:prov1'));
volumeManager.volumeInfoList.push(
MockVolumeManagerWrapper.createMockVolumeInfo(
VolumeManagerCommon.VolumeType.ARCHIVE, 'archive:a-zip'));
VolumeManagerCommon.VolumeType.ARCHIVE, 'archive:a-rar'));
volumeManager.volumeInfoList.push(
MockVolumeManagerWrapper.createMockVolumeInfo(
VolumeManagerCommon.VolumeType.REMOVABLE, 'removable:fuga'));
......@@ -207,6 +210,10 @@ function testOrderAndNestItems() {
volumeManager.volumeInfoList.push(
MockVolumeManagerWrapper.createMockVolumeInfo(
VolumeManagerCommon.VolumeType.MEDIA_VIEW, 'media_view:audio_root'));
// ZipArchiver mounts zip files as PROVIDED volume type.
volumeManager.volumeInfoList.push(
MockVolumeManagerWrapper.createMockVolumeInfo(
VolumeManagerCommon.VolumeType.PROVIDED, zipVolumeId));
// Navigation items built above:
// 1. fake-entry://recent
......@@ -223,9 +230,10 @@ function testOrderAndNestItems() {
// 9. archive:a-rar - mounted as archive
// 10. removable:fuga
// 11. mtp:a-phone
// 12. Drive - from setup()
// 13. provided:prov1
// 14. provided:prov2
// 12. provided:"zip" - mounted as provided: $zipVolumeId
// 13. Drive - from setup()
// 14. provided:prov1
// 15. provided:prov2
// Constructor already calls orderAndNestItems_.
const model = new NavigationListModel(
......@@ -233,7 +241,7 @@ function testOrderAndNestItems() {
// Check items order and that MTP/Archive/Removable respect the original
// order.
assertEquals(14, model.length);
assertEquals(15, model.length);
assertEquals('recent-label', model.item(0).label);
assertEquals('media_view:images_root', model.item(1).label);
......@@ -243,14 +251,16 @@ function testOrderAndNestItems() {
assertEquals('shortcut', model.item(4).label);
assertEquals('shortcut2', model.item(5).label);
assertEquals('My Files', model.item(6).label);
assertEquals('removable:hoge', model.item(7).label);
assertEquals('archive:a-zip', model.item(8).label);
assertEquals('archive:a-rar', model.item(8).label);
assertEquals('removable:fuga', model.item(9).label);
assertEquals('mtp:a-phone', model.item(10).label);
assertEquals(zipVolumeId, model.item(11).label);
assertEquals('My Drive', model.item(11).label);
assertEquals('provided:prov1', model.item(12).label);
assertEquals('provided:prov2', model.item(13).label);
assertEquals('My Drive', model.item(12).label);
assertEquals('provided:prov1', model.item(13).label);
assertEquals('provided:prov2', model.item(14).label);
// Check NavigationSection, which defaults to TOP.
// recent-label.
......@@ -273,20 +283,22 @@ function testOrderAndNestItems() {
// MTP/Archive/Removable are grouped together.
// removable:hoge.
assertEquals(NavigationSection.REMOVABLE, model.item(7).section);
// archive:a-zip.
// archive:a-rar.
assertEquals(NavigationSection.REMOVABLE, model.item(8).section);
// removable:fuga.
assertEquals(NavigationSection.REMOVABLE, model.item(9).section);
// mtp:a-phone.
assertEquals(NavigationSection.REMOVABLE, model.item(10).section);
// archive:"zip" - $zipVolumeId
assertEquals(NavigationSection.REMOVABLE, model.item(11).section);
// Drive and FSP are grouped together.
// My Drive.
assertEquals(NavigationSection.CLOUD, model.item(11).section);
// provided:prov1.
assertEquals(NavigationSection.CLOUD, model.item(12).section);
// provided:prov2.
// provided:prov1.
assertEquals(NavigationSection.CLOUD, model.item(13).section);
// provided:prov2.
assertEquals(NavigationSection.CLOUD, model.item(14).section);
const myFilesModel = model.item(6);
// Re-order again.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment