Commit e3a46e71 authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Chromium LUCI CQ

Files app: Generate JS modules for //u/f/f/f/j/file_manager_commands.js

In //ui/file_manager/file_manager/foreground/js/:
- file_manager_commands.js
- file_manager_commands_unittest.m.js

Import cr.ui.Command as CrUiCommand to avoid name conflict with
Command class defined in file_manager_commands.js

Bug: 1133186
Change-Id: Iae1c3d0cd6ef889293c01a3239c98289c2d16257
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2629150
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Auto-Submit: Jeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843941}
parent 5acc024c
...@@ -79,7 +79,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileListSelectionModelTest) { ...@@ -79,7 +79,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileListSelectionModelTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerCommandsTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerCommandsTest) {
RunTestURL("foreground/js/file_manager_commands_unittest_gen.html"); RunTestURL("foreground/js/file_manager_commands_unittest.m_gen.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerDialogBaseTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerDialogBaseTest) {
......
...@@ -61,7 +61,6 @@ group("unit_test_data") { ...@@ -61,7 +61,6 @@ group("unit_test_data") {
"file_manager/background/js:js_test_gen_html_modules", "file_manager/background/js:js_test_gen_html_modules",
"file_manager/common/js:js_test_gen_html_modules", "file_manager/common/js:js_test_gen_html_modules",
"file_manager/foreground/elements:js_test_gen_html_modules", "file_manager/foreground/elements:js_test_gen_html_modules",
"file_manager/foreground/js:js_test_gen_html",
"file_manager/foreground/js:js_test_gen_html_modules", "file_manager/foreground/js:js_test_gen_html_modules",
"file_manager/foreground/js/metadata:js_test_gen_html_modules", "file_manager/foreground/js/metadata:js_test_gen_html_modules",
"file_manager/foreground/js/ui:js_test_gen_html_modules", "file_manager/foreground/js/ui:js_test_gen_html_modules",
......
...@@ -21,7 +21,6 @@ group("closure_compile") { ...@@ -21,7 +21,6 @@ group("closure_compile") {
":closure_compile_jsmodules", ":closure_compile_jsmodules",
":closure_compile_module", ":closure_compile_module",
":js_test_gen_html_modules_type_check_auto", ":js_test_gen_html_modules_type_check_auto",
":js_test_gen_html_type_check_auto",
":test_support_type_check", ":test_support_type_check",
] ]
} }
...@@ -43,6 +42,7 @@ js_type_check("closure_compile_jsmodules") { ...@@ -43,6 +42,7 @@ js_type_check("closure_compile_jsmodules") {
":fake_android_app_list_model.m", ":fake_android_app_list_model.m",
":fake_file_selection_handler.m", ":fake_file_selection_handler.m",
":file_list_model.m", ":file_list_model.m",
":file_manager_commands.m",
":file_selection.m", ":file_selection.m",
":file_tasks.m", ":file_tasks.m",
":file_transfer_controller.m", ":file_transfer_controller.m",
...@@ -734,11 +734,52 @@ js_library("file_manager_commands") { ...@@ -734,11 +734,52 @@ js_library("file_manager_commands") {
] ]
} }
js_unittest("file_manager_commands_unittest") { js_library("file_manager_commands.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/foreground/js/file_manager_commands.m.js" ]
deps = [ deps = [
":file_manager_commands", ":actions_model.m",
"//ui/file_manager/file_manager/background/js:mock_volume_manager", ":constants.m",
"//ui/webui/resources/js:webui_resource_test", ":dialog_type.m",
":directory_model.m",
":file_selection.m",
":file_tasks.m",
":holding_space_util.m",
":path_component.m",
"ui:directory_tree.m",
"ui:files_confirm_dialog.m",
"ui:suggest_apps_dialog.m",
"//ui/file_manager/base/js:volume_manager_types.m",
"//ui/file_manager/externs:command_handler_deps.m",
"//ui/file_manager/externs:files_app_entry_interfaces.m",
"//ui/file_manager/externs:volume_info.m",
"//ui/file_manager/externs:volume_manager.m",
"//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/file_manager/common/js:file_type.m",
"//ui/file_manager/file_manager/common/js:files_app_entry_types.m",
"//ui/file_manager/file_manager/common/js:metrics.m",
"//ui/file_manager/file_manager/common/js:progress_center_common.m",
"//ui/file_manager/file_manager/common/js:trash.m",
"//ui/file_manager/file_manager/common/js:util.m",
"//ui/file_manager/file_manager/foreground/elements:files_format_dialog.m",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js/cr/ui:command.m",
"//ui/webui/resources/js/cr/ui:context_menu_handler.m",
"//ui/webui/resources/js/cr/ui:list.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("file_manager_commands_unittest.m") {
deps = [
":file_manager_commands.m",
":file_tasks.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/base/js:mock_chrome.m",
"//ui/file_manager/base/js:volume_manager_types.m",
"//ui/file_manager/file_manager/background/js:mock_volume_manager.m",
"//ui/file_manager/file_manager/common/js:mock_entry.m",
"//ui/webui/resources/js:load_time_data.m",
] ]
} }
...@@ -1686,6 +1727,7 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -1686,6 +1727,7 @@ js_test_gen_html("js_test_gen_html_modules") {
":actions_model_unittest.m", ":actions_model_unittest.m",
":directory_contents_unittest.m", ":directory_contents_unittest.m",
":file_list_model_unittest.m", ":file_list_model_unittest.m",
":file_manager_commands_unittest.m",
":file_tasks_unittest.m", ":file_tasks_unittest.m",
":file_transfer_controller_unittest.m", ":file_transfer_controller_unittest.m",
":file_type_filters_controller_unittest.m", ":file_type_filters_controller_unittest.m",
...@@ -1709,11 +1751,6 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -1709,11 +1751,6 @@ js_test_gen_html("js_test_gen_html_modules") {
] ]
} }
js_test_gen_html("js_test_gen_html") {
deps = [ ":file_manager_commands_unittest" ]
mocks = [ "$externs_path/file_manager_private.js" ]
}
js_modulizer("modulize") { js_modulizer("modulize") {
input_files = [ input_files = [
"actions_controller.js", "actions_controller.js",
...@@ -1730,6 +1767,7 @@ js_modulizer("modulize") { ...@@ -1730,6 +1767,7 @@ js_modulizer("modulize") {
"fake_android_app_list_model.js", "fake_android_app_list_model.js",
"fake_file_selection_handler.js", "fake_file_selection_handler.js",
"file_list_model.js", "file_list_model.js",
"file_manager_commands.js",
"file_selection.js", "file_selection.js",
"file_tasks.js", "file_tasks.js",
"file_transfer_controller.js", "file_transfer_controller.js",
...@@ -1771,5 +1809,6 @@ js_modulizer("modulize") { ...@@ -1771,5 +1809,6 @@ js_modulizer("modulize") {
"cr.ui.MultiMenu|MultiMenu", "cr.ui.MultiMenu|MultiMenu",
"cr.ui.ComboButton|ComboButton", "cr.ui.ComboButton|ComboButton",
"cr.filebrowser.DefaultTaskDialog|DefaultTaskDialog", "cr.filebrowser.DefaultTaskDialog|DefaultTaskDialog",
"cr.ui.Command|CrUiCommand",
] ]
} }
...@@ -2,11 +2,47 @@ ...@@ -2,11 +2,47 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/**
* @fileoverview
* @suppress {uselessCode} Temporary suppress because of the line exporting.
*/
// clang-format off
// #import {TrashEntry} from '../../common/js/trash.m.js';
// #import {FileOperationProgressEvent} from '../../common/js/file_operation_common.m.js';
// #import {FilesConfirmDialog} from './ui/files_confirm_dialog.m.js';
// #import {VolumeManager} from '../../../externs/volume_manager.m.js';
// #import {FileSelection, FileSelectionHandler} from './file_selection.m.js';
// #import {VolumeInfo} from '../../../externs/volume_info.m.js';
// #import {DirectoryModel} from './directory_model.m.js';
// #import {FakeEntry, FilesAppEntry, FilesAppDirEntry} from '../../../externs/files_app_entry_interfaces.m.js';
// #import {CommandHandlerDeps} from '../../../externs/command_handler_deps.m.js';
// #import {FileType} from '../../common/js/file_type.m.js';
// #import {SuggestAppsDialog} from './ui/suggest_apps_dialog.m.js';
// #import {constants} from './constants.m.js';
// #import {ProgressCenterItem, ProgressItemState} from '../../common/js/progress_center_common.m.js';
// #import {ActionsModel} from './actions_model.m.js';
// #import {PathComponent} from './path_component.m.js';
// #import {HoldingSpaceUtil} from './holding_space_util.m.js';
// #import {DirectoryTree, DirectoryItem} from './ui/directory_tree.m.js';
// #import {EntryList} from '../../common/js/files_app_entry_types.m.js';
// #import {contextMenuHandler} from 'chrome://resources/js/cr/ui/context_menu_handler.m.js';
// #import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js';
// #import {util, str, strf} from '../../common/js/util.m.js';
// #import {DialogType} from './dialog_type.m.js';
// #import {List} from 'chrome://resources/js/cr/ui/list.m.js';
// #import {FileTasks} from './file_tasks.m.js';
// #import {metrics} from '../../common/js/metrics.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {Command as CrUiCommand} from 'chrome://resources/js/cr/ui/command.m.js';
// clang-format on
/** /**
* A command. * A command.
* @abstract * @abstract
*/ */
class Command { /* #export */ class Command {
/** /**
* Handles the execute event. * Handles the execute event.
* @param {!Event} event Command event. * @param {!Event} event Command event.
...@@ -409,7 +445,7 @@ CommandUtil.getEventEntry = (event, fileManager) => { ...@@ -409,7 +445,7 @@ CommandUtil.getEventEntry = (event, fileManager) => {
/** /**
* Handle of the command events. * Handle of the command events.
*/ */
class CommandHandler { /* #export */ class CommandHandler {
/** /**
* @param {!CommandHandlerDeps} fileManager Classes |CommandHalder| depends. * @param {!CommandHandlerDeps} fileManager Classes |CommandHalder| depends.
* @param {!FileSelectionHandler} selectionHandler * @param {!FileSelectionHandler} selectionHandler
...@@ -433,7 +469,9 @@ class CommandHandler { ...@@ -433,7 +469,9 @@ class CommandHandler {
// Decorate command tags in the document. // Decorate command tags in the document.
const commands = fileManager.document.querySelectorAll('command'); const commands = fileManager.document.querySelectorAll('command');
for (let i = 0; i < commands.length; i++) { for (let i = 0; i < commands.length; i++) {
cr.ui.Command.decorate(commands[i]); if (cr.ui.Command.decorate) {
cr.ui.Command.decorate(commands[i]);
}
this.commands_[commands[i].id] = commands[i]; this.commands_[commands[i].id] = commands[i];
} }
...@@ -1500,6 +1538,7 @@ CommandHandler.COMMANDS_['rename'] = new class extends Command { ...@@ -1500,6 +1538,7 @@ CommandHandler.COMMANDS_['rename'] = new class extends Command {
const removable = const removable =
location.rootType === VolumeManagerCommon.RootType.REMOVABLE; location.rootType === VolumeManagerCommon.RootType.REMOVABLE;
event.canExecute = removable && writable && event.canExecute = removable && writable &&
volumeInfo.diskFileSystemType &&
CommandHandler.RENAME_DISK_FILE_SYSTEM_SUPPORT_.indexOf( CommandHandler.RENAME_DISK_FILE_SYSTEM_SUPPORT_.indexOf(
volumeInfo.diskFileSystemType) > -1; volumeInfo.diskFileSystemType) > -1;
event.command.setHidden(!removable); event.command.setHidden(!removable);
...@@ -2915,3 +2954,6 @@ CommandHandler.COMMANDS_['new-service'] = new class extends Command { ...@@ -2915,3 +2954,6 @@ CommandHandler.COMMANDS_['new-service'] = new class extends Command {
!chrome.extension.inIncognitoContext); !chrome.extension.inIncognitoContext);
} }
}; };
// eslint-disable-next-line semi,no-extra-semi
/* #export */ {CommandUtil};
...@@ -2,10 +2,19 @@ ...@@ -2,10 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertArrayEquals, assertEquals, assertNotEquals, assertTrue} from 'chrome://test/chai_assert.js';
import {installMockChrome} from '../../../base/js/mock_chrome.m.js';
import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js';
import {MockVolumeManager} from '../../background/js/mock_volume_manager.m.js';
import {MockDirectoryEntry, MockEntry} from '../../common/js/mock_entry.m.js';
import {CommandHandler, CommandUtil} from './file_manager_commands.m.js';
import {FileTasks} from './file_tasks.m.js';
/** /**
* Checks that a correct sharing action source is extracted from an event. * Checks that a correct sharing action source is extracted from an event.
*/ */
function testGetSharingActionSource() { export function testGetSharingActionSource() {
const testData = [ const testData = [
{ {
event: {target: {id: CommandUtil.SharingActionElementId.CONTEXT_MENU}}, event: {target: {id: CommandUtil.SharingActionElementId.CONTEXT_MENU}},
...@@ -34,10 +43,10 @@ function testGetSharingActionSource() { ...@@ -34,10 +43,10 @@ function testGetSharingActionSource() {
* Checks that the `toggle-holding-space` command is appropriately enabled/ * Checks that the `toggle-holding-space` command is appropriately enabled/
* disabled given the current selection state and executes as expected. * disabled given the current selection state and executes as expected.
*/ */
function testToggleHoldingSpaceCommand() { export function testToggleHoldingSpaceCommand() {
// Verify `toggle-holding-space` command exists. // Verify `toggle-holding-space` command exists.
const command = CommandHandler.getCommand('toggle-holding-space'); const command = CommandHandler.getCommand('toggle-holding-space');
assertNotEqual(command, undefined); assertNotEquals(command, undefined);
// Enable the holding space feature and provide strings. // Enable the holding space feature and provide strings.
loadTimeData.data = { loadTimeData.data = {
...@@ -46,10 +55,18 @@ function testToggleHoldingSpaceCommand() { ...@@ -46,10 +55,18 @@ function testToggleHoldingSpaceCommand() {
HOLDING_SPACE_UNPIN_TO_SHELF_COMMAND_LABEL: 'Unpin to shelf', HOLDING_SPACE_UNPIN_TO_SHELF_COMMAND_LABEL: 'Unpin to shelf',
}; };
// Mock private API. /**
chrome.fileManagerPrivate.getHoldingSpaceState = (callback) => { * Mock chrome APIs.
callback({itemUrls: []}); * @type {Object}
*/
const mockChrome = {
fileManagerPrivate: {
getHoldingSpaceState: (callback) => {
callback({itemUrls: []});
},
},
}; };
installMockChrome(mockChrome);
// Mock volume manager. // Mock volume manager.
const volumeManager = new MockVolumeManager(); const volumeManager = new MockVolumeManager();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// #import {VolumeInfo} from '../../../externs/volume_info.m.js'; // #import {VolumeInfo} from '../../../externs/volume_info.m.js';
// #import {List} from 'chrome://resources/js/cr/ui/list.m.js'; // #import {List} from 'chrome://resources/js/cr/ui/list.m.js';
// #import {FilesAppDirEntry, FakeEntry, FilesAppEntry} from '../../../externs/files_app_entry_interfaces.m.js'; // #import {FilesAppDirEntry, FakeEntry, FilesAppEntry} from '../../../externs/files_app_entry_interfaces.m.js';
// #import {Command} from 'chrome://resources/js/cr/ui/command.m.js'; // #import {Command as CrUiCommand} from 'chrome://resources/js/cr/ui/command.m.js';
// #import {VolumeManager} from '../../../externs/volume_manager.m.js'; // #import {VolumeManager} from '../../../externs/volume_manager.m.js';
// #import {DirectoryModel} from './directory_model.m.js'; // #import {DirectoryModel} from './directory_model.m.js';
// #import {ThumbnailModel} from './metadata/thumbnail_model.m.js'; // #import {ThumbnailModel} from './metadata/thumbnail_model.m.js';
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// #import {strf, util, str} from '../../common/js/util.m.js'; // #import {strf, util, str} from '../../common/js/util.m.js';
// #import {FileTasks} from './file_tasks.m.js'; // #import {FileTasks} from './file_tasks.m.js';
// #import {FileSelectionHandler, FileSelection} from './file_selection.m.js'; // #import {FileSelectionHandler, FileSelection} from './file_selection.m.js';
// #import {Command} from 'chrome://resources/js/cr/ui/command.m.js'; // #import {Command as CrUiCommand} from 'chrome://resources/js/cr/ui/command.m.js';
// #import {assert, assertInstanceof, assertNotReached} from 'chrome://resources/js/assert.m.js'; // #import {assert, assertInstanceof, assertNotReached} from 'chrome://resources/js/assert.m.js';
// #import {TaskHistory} from './task_history.m.js'; // #import {TaskHistory} from './task_history.m.js';
// #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; // #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// #import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js'; // #import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js';
// #import {util, str, strf} from '../../common/js/util.m.js'; // #import {util, str, strf} from '../../common/js/util.m.js';
// #import {FileSelectionHandler} from './file_selection.m.js'; // #import {FileSelectionHandler} from './file_selection.m.js';
// #import {Command} from 'chrome://resources/js/cr/ui/command.m.js'; // #import {Command as CrUiCommand} from 'chrome://resources/js/cr/ui/command.m.js';
// #import {assert, assertInstanceof} from 'chrome://resources/js/assert.m.js'; // #import {assert, assertInstanceof} from 'chrome://resources/js/assert.m.js';
// #import {queryRequiredElement} from 'chrome://resources/js/util.m.js'; // #import {queryRequiredElement} from 'chrome://resources/js/util.m.js';
// clang-format on // clang-format on
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// #import {Command} from 'chrome://resources/js/cr/ui/command.m.js'; // clang-format off
// #import {Command as CrUiCommand} from 'chrome://resources/js/cr/ui/command.m.js';
// #import {dispatchPropertyChange} from 'chrome://resources/js/cr.m.js'; // #import {dispatchPropertyChange} from 'chrome://resources/js/cr.m.js';
// clang-format on
/** /**
* Sets 'hidden' property of a cr.ui.Command instance and dispatches * Sets 'hidden' property of a cr.ui.Command instance and dispatches
......
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