Commit 3d4f3ff1 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Convert file_selection.js to es6 classes

Used lebab to convert to ES6 class with the following command:
lebab --replace \
 ui/file_manager/file_manager/foreground/js/file_selection.js \
 --transform class

Manual fixes:
- Fix closure markup to go to constructor() instead of class
definition.
- Fix Mock class to be ES6 class too, since closure doesn't allow
old style classes to extends from ES6 classes.
- Rename MockFileSelectionHandler to FakeSelectionHandler. This fake
lies to closure by saying that it extends FileSelectionHandler to allow
it to be passed as FileSelectionHandler in closure compilation.
- Add addEventListener() method to FakeFileSelectionHandler to fix
tests that use this method.

Bug: 778674
Change-Id: I39fb5ef7d7d8ef9c7fbc2b64244a26b9ebe23584
Reviewed-on: https://chromium-review.googlesource.com/c/1457700Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629911}
parent c471f24e
......@@ -108,32 +108,32 @@ function createTaskController(fileSelectionHandler) {
/**
* Mock FileSelectionHandler.
* @constructor
* @extends {FileSelectionHandler}
*/
function MockFileSelectionHandler() {
this.computeAdditionalCallback = function() {};
this.selection = /** @type {!FileSelection} */ ({});
this.updateSelection([], []);
}
MockFileSelectionHandler.prototype = /** @struct */ {
__proto__: cr.EventTarget.prototype,
};
class FakeFileSelectionHandler {
constructor() {
this.selection = /** @type {!FileSelection} */ ({});
this.updateSelection([], []);
this.eventTarget_ = new cr.EventTarget();
}
computeAdditionalCallback() {}
updateSelection(entries, mimeTypes) {
this.selection = /** @type {!FileSelection} */ ({
entries: entries,
mimeTypes: mimeTypes,
computeAdditional: (metadataModel) => {
this.computeAdditionalCallback();
return new Promise((resolve) => {
resolve();
});
},
});
}
MockFileSelectionHandler.prototype.updateSelection = function(
entries, mimeTypes) {
this.selection = /** @type {!FileSelection} */ ({
entries: entries,
mimeTypes: mimeTypes,
computeAdditional: (metadataModel) => {
this.computeAdditionalCallback();
return new Promise((resolve) => {
resolve();
});
},
});
};
addEventListener(...args) {
return this.eventTarget_.addEventListener(...args);
}
}
/**
* Setup test case fileManagerPrivate.
......@@ -165,7 +165,7 @@ function setupFileManagerPrivate() {
* Tests that executeEntryTask() runs the expected task.
*/
function testExecuteEntryTask(callback) {
var selectionHandler = new MockFileSelectionHandler();
var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId');
fileSystem.entries['/test.png'] = new MockFileEntry(fileSystem, '/test.png');
......@@ -188,7 +188,7 @@ function testExecuteEntryTask(callback) {
* multiple times when the selected entries are not changed.
*/
function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) {
var selectionHandler = new MockFileSelectionHandler();
var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection(
......@@ -225,7 +225,7 @@ function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) {
* called.
*/
function testGetFileTasksShouldNotReturnObsoletePromise(callback) {
var selectionHandler = new MockFileSelectionHandler();
var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection(
......@@ -256,7 +256,7 @@ function testGetFileTasksShouldNotReturnObsoletePromise(callback) {
* the getFileTasks() promise to reject.
*/
function testGetFileTasksShouldNotCacheRejectedPromise(callback) {
var selectionHandler = new MockFileSelectionHandler();
var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection(
......
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