Commit 4c389083 authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Commit Bot

Add unit tests for archive mount visual signals

Tests crrev.com/c/2423448.

Bug: chromium:912236
Test: browser_tests --gtest_filter=FileManagerJsTest.FileTasks
Change-Id: Iefca4742d6fb154c5c1a392d0da14af796a792a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467162Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818361}
parent 88b6afeb
......@@ -435,6 +435,8 @@ js_library("mock_progress_center") {
":progress_center",
"//ui/webui/resources/js/cr:event_target",
]
visibility +=
[ "//ui/file_manager/file_manager/foreground/js:file_tasks_unittest" ]
}
js_library("progress_center") {
......
......@@ -462,6 +462,7 @@ js_unittest("file_tasks_unittest") {
"//ui/file_manager/base/js:mock_chrome",
"//ui/file_manager/base/js:test_error_reporting",
"//ui/file_manager/file_manager/background/js:mock_crostini",
"//ui/file_manager/file_manager/background/js:mock_progress_center",
"//ui/file_manager/file_manager/common/js:mock_entry",
]
}
......
......@@ -64,6 +64,34 @@ const mockTaskHistory = /** @type {!TaskHistory} */ ({
*/
const mockFileTransferController = /** @type {!FileTransferController} */ ({});
/**
* Mock directory change tracker.
* @type {!Object}
*/
const fakeTracker = {
hasChange: false,
};
/**
* Fake url for mounted ZIP file.
* @type {string}
*/
const fakeMountedZipUrl =
'filesystem:chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/' +
'external/fakePath/test.zip';
/**
* Panel IDs for ZIP mount operations.
* @type {string}
*/
const zipMountPanelId = 'Mounting: ' + fakeMountedZipUrl;
/**
* Panel IDs for ZIP mount errors.
* @type {string}
*/
const errorZipMountPanelId = 'Cannot mount: ' + fakeMountedZipUrl;
// Set up test components.
function setUp() {
// Mock LoadTimeData strings.
......@@ -156,6 +184,7 @@ function getMockFileManager() {
alertDialog: {
showHtml: function(title, text, onOk, onCancel, onShow) {},
},
passwordDialog: /** @type {!FilesPasswordDialog} */ ({}),
speakA11yMessage: (text) => {},
}),
metadataModel: /** @type {!MetadataModel} */ ({}),
......@@ -164,9 +193,10 @@ function getMockFileManager() {
getCurrentRootType: function() {
return null;
},
changeDirectoryEntry: function(displayRoot) {}
}),
crostini: crostini,
progressCenter: /** @type {!ProgressCenter} */ ({}),
progressCenter: /** @type {!ProgressCenter} */ (new MockProgressCenter()),
};
fileManager.crostini.initVolumeManager(fileManager.volumeManager);
......@@ -759,3 +789,161 @@ async function testShareWith(done) {
done();
}
/**
* Checks that the progress center is properly updated when mounting archives
* successfully.
* @suppress {visibility}
*/
async function testMountArchiveAndChangeDirectoryNotificationSuccess(done) {
const fileManager = getMockFileManager();
// Define FileTasks instance.
const tasks = await FileTasks.create(
fileManager.volumeManager, fileManager.metadataModel,
fileManager.directoryModel, fileManager.ui, mockFileTransferController,
[], [null], mockTaskHistory, fileManager.namingController,
fileManager.crostini, fileManager.progressCenter);
fileManager.volumeManager.mountArchive = function(url, password) {
// Check: progressing state.
assertEquals(
ProgressItemState.PROGRESSING,
fileManager.progressCenter.getItemById(zipMountPanelId).state);
const volumeInfo = {resolveDisplayRoot: () => null};
return volumeInfo;
};
// Mount archive.
await tasks.mountArchiveAndChangeDirectory_(fakeTracker, fakeMountedZipUrl);
// Check: mount completed, no error.
assertEquals(
ProgressItemState.COMPLETED,
fileManager.progressCenter.getItemById(zipMountPanelId).state);
assertEquals(
undefined, fileManager.progressCenter.getItemById(errorZipMountPanelId));
done();
}
/**
* Checks that the progress center is properly updated when mounting an archive
* resolves with an error.
* @suppress {visibility}
*/
async function testMountArchiveAndChangeDirectoryNotificationInvalidArchive(
done) {
const fileManager = getMockFileManager();
// Define FileTasks instance.
const tasks = await FileTasks.create(
fileManager.volumeManager, fileManager.metadataModel,
fileManager.directoryModel, fileManager.ui, mockFileTransferController,
[], [null], mockTaskHistory, fileManager.namingController,
fileManager.crostini, fileManager.progressCenter);
fileManager.volumeManager.mountArchive = function(url, password) {
return Promise.reject(VolumeManagerCommon.VolumeError.INTERNAL);
};
// Mount archive.
await tasks.mountArchiveAndChangeDirectory_(fakeTracker, fakeMountedZipUrl);
// Check: mount is completed with an error.
assertEquals(
ProgressItemState.COMPLETED,
fileManager.progressCenter.getItemById(zipMountPanelId).state);
assertEquals(
ProgressItemState.ERROR,
fileManager.progressCenter.getItemById(errorZipMountPanelId).state);
done();
}
/**
* Checks that the progress center is properly updated when the password prompt
* for an encrypted archive is canceled.
* @suppress {visibility}
*/
async function testMountArchiveAndChangeDirectoryNotificationCancelPassword(
done) {
const fileManager = getMockFileManager();
// Define FileTasks instance.
const tasks = await FileTasks.create(
fileManager.volumeManager, fileManager.metadataModel,
fileManager.directoryModel, fileManager.ui, mockFileTransferController,
[], [null], mockTaskHistory, fileManager.namingController,
fileManager.crostini, fileManager.progressCenter);
fileManager.volumeManager.mountArchive = function(url, password) {
return Promise.reject(VolumeManagerCommon.VolumeError.NEED_PASSWORD);
};
fileManager.ui.passwordDialog.askForPassword =
async function(filename, password = null) {
return Promise.reject(FilesPasswordDialog.USER_CANCELLED);
};
// Mount archive.
await tasks.mountArchiveAndChangeDirectory_(fakeTracker, fakeMountedZipUrl);
// Check: mount is completed, no error since the user canceled the password
// prompt.
assertEquals(
ProgressItemState.COMPLETED,
fileManager.progressCenter.getItemById(zipMountPanelId).state);
assertEquals(
undefined, fileManager.progressCenter.getItemById(errorZipMountPanelId));
done();
}
/**
* Checks that the progress center is properly updated when mounting an
* encrypted archive.
* @suppress {visibility}
*/
async function testMountArchiveAndChangeDirectoryNotificationEncryptedArchive(
done) {
const fileManager = getMockFileManager();
// Define FileTasks instance.
const tasks = await FileTasks.create(
fileManager.volumeManager, fileManager.metadataModel,
fileManager.directoryModel, fileManager.ui, mockFileTransferController,
[], [null], mockTaskHistory, fileManager.namingController,
fileManager.crostini, fileManager.progressCenter);
fileManager.volumeManager.mountArchive = function(url, password) {
return new Promise((resolve, reject) => {
if (password) {
assertEquals('testpassword', password);
const volumeInfo = {resolveDisplayRoot: () => null};
resolve(volumeInfo);
} else {
reject(VolumeManagerCommon.VolumeError.NEED_PASSWORD);
}
});
};
fileManager.ui.passwordDialog.askForPassword =
async function(filename, password = null) {
return Promise.resolve('testpassword');
};
// Mount archive.
await tasks.mountArchiveAndChangeDirectory_(fakeTracker, fakeMountedZipUrl);
// Check: mount is completed, no error since the user entered a valid
// password.
assertEquals(
ProgressItemState.COMPLETED,
fileManager.progressCenter.getItemById(zipMountPanelId).state);
assertEquals(
undefined, fileManager.progressCenter.getItemById(errorZipMountPanelId));
done();
}
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