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) { ...@@ -108,32 +108,32 @@ function createTaskController(fileSelectionHandler) {
/** /**
* Mock FileSelectionHandler. * Mock FileSelectionHandler.
* @constructor
* @extends {FileSelectionHandler} * @extends {FileSelectionHandler}
*/ */
function MockFileSelectionHandler() { class FakeFileSelectionHandler {
this.computeAdditionalCallback = function() {}; constructor() {
this.selection = /** @type {!FileSelection} */ ({}); this.selection = /** @type {!FileSelection} */ ({});
this.updateSelection([], []); this.updateSelection([], []);
} this.eventTarget_ = new cr.EventTarget();
}
MockFileSelectionHandler.prototype = /** @struct */ { computeAdditionalCallback() {}
__proto__: cr.EventTarget.prototype, updateSelection(entries, mimeTypes) {
}; this.selection = /** @type {!FileSelection} */ ({
entries: entries,
mimeTypes: mimeTypes,
computeAdditional: (metadataModel) => {
this.computeAdditionalCallback();
return new Promise((resolve) => {
resolve();
});
},
});
}
MockFileSelectionHandler.prototype.updateSelection = function( addEventListener(...args) {
entries, mimeTypes) { return this.eventTarget_.addEventListener(...args);
this.selection = /** @type {!FileSelection} */ ({ }
entries: entries, }
mimeTypes: mimeTypes,
computeAdditional: (metadataModel) => {
this.computeAdditionalCallback();
return new Promise((resolve) => {
resolve();
});
},
});
};
/** /**
* Setup test case fileManagerPrivate. * Setup test case fileManagerPrivate.
...@@ -165,7 +165,7 @@ function setupFileManagerPrivate() { ...@@ -165,7 +165,7 @@ function setupFileManagerPrivate() {
* Tests that executeEntryTask() runs the expected task. * Tests that executeEntryTask() runs the expected task.
*/ */
function testExecuteEntryTask(callback) { function testExecuteEntryTask(callback) {
var selectionHandler = new MockFileSelectionHandler(); var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId'); var fileSystem = new MockFileSystem('volumeId');
fileSystem.entries['/test.png'] = new MockFileEntry(fileSystem, '/test.png'); fileSystem.entries['/test.png'] = new MockFileEntry(fileSystem, '/test.png');
...@@ -188,7 +188,7 @@ function testExecuteEntryTask(callback) { ...@@ -188,7 +188,7 @@ function testExecuteEntryTask(callback) {
* multiple times when the selected entries are not changed. * multiple times when the selected entries are not changed.
*/ */
function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) { function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) {
var selectionHandler = new MockFileSelectionHandler(); var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId'); var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection( selectionHandler.updateSelection(
...@@ -225,7 +225,7 @@ function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) { ...@@ -225,7 +225,7 @@ function testGetFileTasksShouldNotBeCalledMultipleTimes(callback) {
* called. * called.
*/ */
function testGetFileTasksShouldNotReturnObsoletePromise(callback) { function testGetFileTasksShouldNotReturnObsoletePromise(callback) {
var selectionHandler = new MockFileSelectionHandler(); var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId'); var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection( selectionHandler.updateSelection(
...@@ -256,7 +256,7 @@ function testGetFileTasksShouldNotReturnObsoletePromise(callback) { ...@@ -256,7 +256,7 @@ function testGetFileTasksShouldNotReturnObsoletePromise(callback) {
* the getFileTasks() promise to reject. * the getFileTasks() promise to reject.
*/ */
function testGetFileTasksShouldNotCacheRejectedPromise(callback) { function testGetFileTasksShouldNotCacheRejectedPromise(callback) {
var selectionHandler = new MockFileSelectionHandler(); var selectionHandler = new FakeFileSelectionHandler();
var fileSystem = new MockFileSystem('volumeId'); var fileSystem = new MockFileSystem('volumeId');
selectionHandler.updateSelection( 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