Skip to content

Commit

Permalink
[Files F2] Support disabled/volumeType for EntryList
Browse files Browse the repository at this point in the history
EntryList can be a placeholder for a real volume, if the
corresponding volume type is disabled, it should be disabled.

Bug: b/271485133
Test: browser_tests --gtest_filter="*ReducerVolumes"
Change-Id: Ib78cb6df67f0e7725a06bfe80f26633de91a9b21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4328808
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Wenbo Jie <wenbojie@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1119804}
  • Loading branch information
PinkyJie authored and Chromium LUCI CQ committed Mar 21, 2023
1 parent 99bbcb4 commit 68bbe7c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
24 changes: 24 additions & 0 deletions ui/file_manager/file_manager/common/js/files_app_entry_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ export class EntryList {
this.isFile = false;
this.type_name = 'EntryList';
this.fullPath = '/';

/**
* @public {boolean} EntryList can be a placeholder of a real volume (e.g.
* MyFiles or DriveFakeRootEntryList), it can be disabled if the
* corresponding volume type is disabled.
*/
this.disabled = false;
}

/**
Expand Down Expand Up @@ -316,6 +323,23 @@ export class EntryList {
getNativeEntry() {
return null;
}

/**
* EntryList can be a placeholder for the real volume (e.g. MyFiles or
* DriveFakeRootEntryList), if so this field will be the volume type of the
* volume it represents.
* @return {VolumeManagerCommon.VolumeType|null}
*/
get volumeType() {
switch (this.rootType) {
case VolumeManagerCommon.RootType.MY_FILES:
return VolumeManagerCommon.VolumeType.DOWNLOADS;
case VolumeManagerCommon.RootType.DRIVE_FAKE_ROOT:
return VolumeManagerCommon.VolumeType.DRIVE;
default:
return null;
}
}
}

/**
Expand Down
47 changes: 44 additions & 3 deletions ui/file_manager/file_manager/state/reducers/volumes_unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {EntryList, FakeEntryImpl, VolumeEntry} from '../../common/js/files_app_e
import {waitUntil} from '../../common/js/test_error_reporting.js';
import {str} from '../../common/js/util.js';
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js';
import {FileData, State} from '../../externs/ts/state.js';
import {FileData, State, Volume} from '../../externs/ts/state.js';
import {VolumeInfo} from '../../externs/volume_info.js';
import {constants} from '../../foreground/js/constants.js';
import {addVolume, removeVolume} from '../actions/volumes.js';
Expand Down Expand Up @@ -349,10 +349,51 @@ export async function testAddDisabledVolume(done: () => void) {

// Expect the volume entry is being disabled.
await waitUntil(() => {
const state = store.getState();
const volumeEntry =
getEntry(store.getState(), volumeInfo.displayRoot.toURL()) as
getEntry(state, volumeInfo.displayRoot.toURL()) as VolumeEntry;
const volume = state.volumes[volumeInfo.volumeId] as Volume;
return volumeEntry && volumeEntry.disabled === true && volume &&
volume.isDisabled === true;
});

done();
}

/**
* Tests that drive fake root entry list will be disabled if the drive volume is
* disabled in the volume manager.
*/
export async function testAddDisabledDriveVolume(done: () => void) {
const initialState = getEmptyState();
const store = setupStore(initialState);

// Dispatch an action to add drive volume.
const {volumeManager} = window.fileManager;
const driveVolumeInfo = volumeManager.getCurrentProfileVolumeInfo(
VolumeManagerCommon.VolumeType.DRIVE)!;
// DriveFS takes time to resolve.
await driveVolumeInfo.resolveDisplayRoot();
const driveVolumeMetadata = createFakeVolumeMetadata(driveVolumeInfo);
// Disable Drive volume type.
volumeManager.isDisabled = (volumeType) => {
return volumeType === VolumeManagerCommon.VolumeType.DRIVE;
};
store.dispatch(addVolume(
{volumeInfo: driveVolumeInfo, volumeMetadata: driveVolumeMetadata}));

// Expect the volume entry is being disabled.
await waitUntil(() => {
const state = store.getState();
const driveFakeRootEntryList =
getEntry(state, driveRootEntryListKey) as EntryList;
const driveVolumeEntry =
getEntry(store.getState(), driveVolumeInfo.displayRoot.toURL()) as
VolumeEntry;
return volumeEntry && volumeEntry.disabled === true;
const driveVolume = state.volumes[driveVolumeInfo.volumeId];
return driveFakeRootEntryList && driveFakeRootEntryList.disabled === true &&
driveVolumeEntry && driveVolumeEntry.disabled === true && driveVolume &&
driveVolume.isDisabled === true;
});

done();
Expand Down

0 comments on commit 68bbe7c

Please sign in to comment.