Commit 97b497f5 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Generate JS module for background page

Generate JS module for //ui/file_manager/file_manager/background/js/
* file_operation_handler.js
* file_operation_handler_unittest.m.js
* file_operation_manager.js
* file_operation_manager_unittest.m.js
* trash.js
* trash_unittest.m.js

Bug: 1133186
Change-Id: I01334c52540202c1b7c22d0fd14527a1ca42cf28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610412
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840365}
parent 30d16f41
...@@ -87,11 +87,11 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerDialogBaseTest) { ...@@ -87,11 +87,11 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileManagerDialogBaseTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationHandlerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationHandlerTest) {
RunTestURL("background/js/file_operation_handler_unittest_gen.html"); RunTestURL("background/js/file_operation_handler_unittest.m_gen.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) {
RunTestURL("background/js/file_operation_manager_unittest_gen.html"); RunTestURL("background/js/file_operation_manager_unittest.m_gen.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesAppEntryTypes) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesAppEntryTypes) {
...@@ -246,7 +246,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ThumbnailModel) { ...@@ -246,7 +246,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ThumbnailModel) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, Trash) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, Trash) {
RunTestURL("background/js/trash_unittest_gen.html"); RunTestURL("background/js/trash_unittest.m_gen.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, UtilTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, UtilTest) {
......
...@@ -80,6 +80,8 @@ js_type_check("closure_compile_jsmodules") { ...@@ -80,6 +80,8 @@ js_type_check("closure_compile_jsmodules") {
":drive_sync_handler.m", ":drive_sync_handler.m",
":duplicate_finder.m", ":duplicate_finder.m",
":entry_location_impl.m", ":entry_location_impl.m",
":file_operation_handler.m",
":file_operation_manager.m",
":file_operation_util.m", ":file_operation_util.m",
":import_history.m", ":import_history.m",
":media_import_handler.m", ":media_import_handler.m",
...@@ -91,6 +93,7 @@ js_type_check("closure_compile_jsmodules") { ...@@ -91,6 +93,7 @@ js_type_check("closure_compile_jsmodules") {
":mount_metrics.m", ":mount_metrics.m",
":task_queue.m", ":task_queue.m",
":test_util_base.m", ":test_util_base.m",
":trash.m",
":volume_info_impl.m", ":volume_info_impl.m",
":volume_info_list_impl.m", ":volume_info_list_impl.m",
":volume_manager_factory.m", ":volume_manager_factory.m",
...@@ -447,12 +450,29 @@ js_library("file_operation_handler") { ...@@ -447,12 +450,29 @@ js_library("file_operation_handler") {
] ]
} }
js_unittest("file_operation_handler_unittest") { js_library("file_operation_handler.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/background/js/file_operation_handler.m.js" ]
deps = [ deps = [
":file_operation_handler", "//ui/file_manager/externs/background:file_operation_manager.m",
":mock_file_operation_manager", "//ui/file_manager/externs/background:progress_center.m",
":mock_progress_center", "//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/base/js:test_error_reporting", "//ui/file_manager/file_manager/common/js:progress_center_common.m",
"//ui/file_manager/file_manager/common/js:util.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("file_operation_handler_unittest.m") {
deps = [
":file_operation_handler.m",
":file_operation_util.m",
":mock_file_operation_manager.m",
":mock_progress_center.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/file_manager/common/js:progress_center_common.m",
"//ui/file_manager/file_manager/common/js:util.m",
] ]
} }
...@@ -490,13 +510,42 @@ js_library("file_operation_manager") { ...@@ -490,13 +510,42 @@ js_library("file_operation_manager") {
[ "//ui/file_manager/externs/background/file_operation_manager.js" ] [ "//ui/file_manager/externs/background/file_operation_manager.js" ]
} }
js_unittest("file_operation_manager_unittest") { js_library("file_operation_manager.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/background/js/file_operation_manager.m.js" ]
deps = [ deps = [
":file_operation_manager", ":file_operation_util.m",
":metadata_proxy", ":metadata_proxy.m",
"//ui/file_manager/base/js:mock_chrome", ":trash.m",
"//ui/file_manager/base/js:test_error_reporting", ":volume_manager_factory.m",
"//ui/file_manager/file_manager/common/js:mock_entry", "//ui/file_manager/externs:entry_location.m",
"//ui/file_manager/externs:files_app_entry_interfaces.m",
"//ui/file_manager/externs:volume_manager.m",
"//ui/file_manager/externs/background:file_operation_manager.m",
"//ui/file_manager/file_manager/common/js:async_util.m",
"//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/file_manager/common/js:mock_entry.m",
"//ui/file_manager/file_manager/common/js:trash.m",
"//ui/file_manager/file_manager/common/js:util.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("file_operation_manager_unittest.m") {
deps = [
":file_operation_manager.m",
":file_operation_util.m",
":volume_manager_factory.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/base/js:mock_chrome.m",
"//ui/file_manager/base/js:test_error_reporting.m",
"//ui/file_manager/externs:entry_location.m",
"//ui/file_manager/externs/background:file_operation_manager.m",
"//ui/file_manager/file_manager/common/js:file_operation_common.m",
"//ui/file_manager/file_manager/common/js:mock_entry.m",
"//ui/file_manager/file_manager/common/js:util.m",
"//ui/webui/resources/js:load_time_data.m",
] ]
} }
...@@ -908,12 +957,30 @@ js_library("trash") { ...@@ -908,12 +957,30 @@ js_library("trash") {
] ]
} }
js_unittest("trash_unittest") { js_library("trash.m") {
sources =
[ "$root_gen_dir/ui/file_manager/file_manager/background/js/trash.m.js" ]
deps = [ deps = [
":mock_volume_manager", ":file_operation_util.m",
":trash", "//ui/file_manager/externs:volume_manager.m",
"//ui/file_manager/file_manager/common/js:mock_entry", "//ui/file_manager/file_manager/common/js:trash.m",
"//ui/webui/resources/js:webui_resource_test", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:load_time_data.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("trash_unittest.m") {
deps = [
":mock_volume_manager.m",
":trash.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/base/js:volume_manager_types.m",
"//ui/file_manager/file_manager/common/js:mock_entry.m",
"//ui/file_manager/file_manager/common/js:trash.m",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:load_time_data.m",
] ]
} }
...@@ -1038,12 +1105,15 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -1038,12 +1105,15 @@ js_test_gen_html("js_test_gen_html_modules") {
":crostini_unittest.m", ":crostini_unittest.m",
":drive_sync_handler_unittest.m", ":drive_sync_handler_unittest.m",
":duplicate_finder_unittest.m", ":duplicate_finder_unittest.m",
":file_operation_handler_unittest.m",
":file_operation_manager_unittest.m",
":import_history_unittest.m", ":import_history_unittest.m",
":media_import_handler_unittest.m", ":media_import_handler_unittest.m",
":media_scanner_unittest.m", ":media_scanner_unittest.m",
":metadata_proxy_unittest.m", ":metadata_proxy_unittest.m",
":mount_metrics_unittest.m", ":mount_metrics_unittest.m",
":task_queue_unittest.m", ":task_queue_unittest.m",
":trash_unittest.m",
] ]
js_module = true js_module = true
...@@ -1059,9 +1129,6 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -1059,9 +1129,6 @@ js_test_gen_html("js_test_gen_html_modules") {
js_test_gen_html("js_test_gen_html") { js_test_gen_html("js_test_gen_html") {
deps = [ deps = [
":device_handler_unittest", ":device_handler_unittest",
":file_operation_handler_unittest",
":file_operation_manager_unittest",
":trash_unittest",
":volume_manager_unittest", ":volume_manager_unittest",
] ]
} }
...@@ -1095,6 +1162,9 @@ js_modulizer("modulize") { ...@@ -1095,6 +1162,9 @@ js_modulizer("modulize") {
"mock_media_scanner.js", "mock_media_scanner.js",
"duplicate_finder.js", "duplicate_finder.js",
"media_import_handler.js", "media_import_handler.js",
"file_operation_handler.js",
"file_operation_manager.js",
"trash.js",
] ]
namespace_rewrites = cr_namespace_rewrites namespace_rewrites = cr_namespace_rewrites
......
...@@ -2,10 +2,18 @@ ...@@ -2,10 +2,18 @@
// 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.
// clang-format off
// #import {ProgressCenter} from '../../../externs/background/progress_center.m.js';
// #import {FileOperationManager} from '../../../externs/background/file_operation_manager.m.js';
// #import {util, strf, str} from '../../common/js/util.m.js';
// #import {ProgressCenterItem, ProgressItemState, ProgressItemType} from '../../common/js/progress_center_common.m.js';
// #import {FileOperationProgressEvent} from '../../common/js/file_operation_common.m.js';
// clang-format on
/** /**
* An event handler of the background page for file operations. * An event handler of the background page for file operations.
*/ */
class FileOperationHandler { /* #export */ class FileOperationHandler {
/** /**
* @param {!FileOperationManager} fileOperationManager * @param {!FileOperationManager} fileOperationManager
* @param {!ProgressCenter} progressCenter * @param {!ProgressCenter} progressCenter
......
...@@ -2,7 +2,19 @@ ...@@ -2,7 +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.
'use strict'; // clang-format off
import { assertArrayEquals,assertEquals, assertTrue} from 'chrome://test/chai_assert.js';
import {FileOperationProgressEvent} from '../../common/js/file_operation_common.m.js';
import {ProgressItemState} from '../../common/js/progress_center_common.m.js';
import {util} from '../../common/js/util.m.js';
import {FileOperationHandler} from './file_operation_handler.m.js';
import {fileOperationUtil} from './file_operation_util.m.js';
import {MockFileOperationManager} from './mock_file_operation_manager.m.js';
import {MockProgressCenter} from './mock_progress_center.m.js';
// clang-format on
/** @type {!MockFileOperationManager} */ /** @type {!MockFileOperationManager} */
let fileOperationManager; let fileOperationManager;
...@@ -51,7 +63,7 @@ class MockDate { ...@@ -51,7 +63,7 @@ class MockDate {
} }
// Set up the test components. // Set up the test components.
function setUp() { export function setUp() {
// Mock LoadTimeData strings. // Mock LoadTimeData strings.
window.loadTimeData.data = { window.loadTimeData.data = {
COPY_FILE_NAME: 'Copying $1...', COPY_FILE_NAME: 'Copying $1...',
...@@ -74,7 +86,7 @@ function setUp() { ...@@ -74,7 +86,7 @@ function setUp() {
/** /**
* Tests copy success. * Tests copy success.
*/ */
function testCopySuccess() { export function testCopySuccess() {
// Dispatch copy event. // Dispatch copy event.
fileOperationManager.dispatchEvent( fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), { /** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
...@@ -121,7 +133,7 @@ function testCopySuccess() { ...@@ -121,7 +133,7 @@ function testCopySuccess() {
/** /**
* Tests copy cancel. * Tests copy cancel.
*/ */
function testCopyCancel() { export function testCopyCancel() {
// Dispatch copy event. // Dispatch copy event.
fileOperationManager.dispatchEvent( fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), { /** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
...@@ -170,7 +182,7 @@ function testCopyCancel() { ...@@ -170,7 +182,7 @@ function testCopyCancel() {
/** /**
* Tests target already exists error. * Tests target already exists error.
*/ */
function testCopyTargetExistsError() { export function testCopyTargetExistsError() {
// Dispatch error event. // Dispatch error event.
fileOperationManager.dispatchEvent( fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), { /** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
...@@ -199,7 +211,7 @@ function testCopyTargetExistsError() { ...@@ -199,7 +211,7 @@ function testCopyTargetExistsError() {
/** /**
* Tests file system error. * Tests file system error.
*/ */
function testCopyFileSystemError() { export function testCopyFileSystemError() {
// Dispatch error event. // Dispatch error event.
fileOperationManager.dispatchEvent( fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), { /** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
...@@ -228,7 +240,7 @@ function testCopyFileSystemError() { ...@@ -228,7 +240,7 @@ function testCopyFileSystemError() {
/** /**
* Tests unexpected error. * Tests unexpected error.
*/ */
function testCopyUnexpectedError() { export function testCopyUnexpectedError() {
// Dispatch error event. // Dispatch error event.
fileOperationManager.dispatchEvent( fileOperationManager.dispatchEvent(
/** @type {!Event} */ (Object.assign(new Event('copy-progress'), { /** @type {!Event} */ (Object.assign(new Event('copy-progress'), {
...@@ -257,7 +269,7 @@ function testCopyUnexpectedError() { ...@@ -257,7 +269,7 @@ function testCopyUnexpectedError() {
/** /**
* Tests Speedometer moving average calculations. * Tests Speedometer moving average calculations.
*/ */
function testSpeedometerMovingAverage() { export function testSpeedometerMovingAverage() {
const bufferLength = 20; const bufferLength = 20;
const speedometer = new fileOperationUtil.Speedometer(bufferLength); const speedometer = new fileOperationUtil.Speedometer(bufferLength);
const mockDate = new MockDate(); const mockDate = new MockDate();
...@@ -283,7 +295,7 @@ function testSpeedometerMovingAverage() { ...@@ -283,7 +295,7 @@ function testSpeedometerMovingAverage() {
/** /**
* Tests Speedometer buffer ring rotate and substitute. * Tests Speedometer buffer ring rotate and substitute.
*/ */
function testSpeedometerBufferRing() { export function testSpeedometerBufferRing() {
const bufferLength = 20; const bufferLength = 20;
const speedometer = new fileOperationUtil.Speedometer(bufferLength); const speedometer = new fileOperationUtil.Speedometer(bufferLength);
const mockDate = new MockDate(); const mockDate = new MockDate();
...@@ -305,4 +317,4 @@ function testSpeedometerBufferRing() { ...@@ -305,4 +317,4 @@ function testSpeedometerBufferRing() {
assertEquals(300, buffer[0]); assertEquals(300, buffer[0]);
mockDate.stop(); mockDate.stop();
} }
\ No newline at end of file
...@@ -2,12 +2,30 @@ ...@@ -2,12 +2,30 @@
// 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.
// clang-format off
// #import {TrashEntry} from '../../common/js/trash.m.js';
// #import {FakeEntry} from '../../../externs/files_app_entry_interfaces.m.js';
// #import {VolumeManager} from '../../../externs/volume_manager.m.js';
// #import {EntryLocation} from '../../../externs/entry_location.m.js';
// #import {MockEntry} from '../../common/js/mock_entry.m.js';
// #import {FileOperationManager} from '../../../externs/background/file_operation_manager.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {metadataProxy} from './metadata_proxy.m.js';
// #import {AsyncUtil} from '../../common/js/async_util.m.js';
// #import {volumeManagerFactory} from './volume_manager_factory.m.js';
// #import {FileOperationProgressEvent, FileOperationError} from '../../common/js/file_operation_common.m.js';
// #import {Trash} from './trash.m.js';
// #import {util} from '../../common/js/util.m.js';
// #import {fileOperationUtil} from './file_operation_util.m.js';
// clang-format on
/** /**
* FileOperationManagerImpl: implementation of {FileOperationManager}. * FileOperationManagerImpl: implementation of {FileOperationManager}.
* *
* @implements {FileOperationManager} * @implements {FileOperationManager}
*/ */
class FileOperationManagerImpl { /* #export */ class FileOperationManagerImpl {
constructor() { constructor() {
/** /**
* @private {VolumeManager} * @private {VolumeManager}
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// 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.
'use strict';
// clang-format off
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import { assertArrayEquals, assertEquals, assertFalse,assertTrue} from 'chrome://test/chai_assert.js';
import {installMockChrome} from '../../../base/js/mock_chrome.m.js';
import {reportPromise, waitUntil} from '../../../base/js/test_error_reporting.m.js';
import {FileOperationManager} from '../../../externs/background/file_operation_manager.m.js';
import {EntryLocation} from '../../../externs/entry_location.m.js';
import {FileOperationProgressEvent} from '../../common/js/file_operation_common.m.js';
import { joinPath, MockDirectoryEntry, MockEntry, MockFileEntry,MockFileSystem} from '../../common/js/mock_entry.m.js';
import {util} from '../../common/js/util.m.js';
import {FileOperationManagerImpl} from './file_operation_manager.m.js';
import {fileOperationUtil} from './file_operation_util.m.js';
import {volumeManagerFactory} from './volume_manager_factory.m.js';
// clang-format on
/** /**
* Mock chrome APIs. * Mock chrome APIs.
...@@ -32,7 +49,8 @@ mockChrome.fileManagerPrivate = { ...@@ -32,7 +49,8 @@ mockChrome.fileManagerPrivate = {
mockChrome.fileManagerPrivate.onCopyProgress.listener_ = null; mockChrome.fileManagerPrivate.onCopyProgress.listener_ = null;
}, },
listener_: null listener_: null
} },
}; };
/** /**
...@@ -261,9 +279,6 @@ function waitForEvents(fileOperationManager) { ...@@ -261,9 +279,6 @@ function waitForEvents(fileOperationManager) {
*/ */
let volumeManager; let volumeManager;
// eslint-disable-next-line no-var
var volumeManagerFactory = volumeManagerFactory || {};
/** /**
* Provide VolumeManager.getInstance() for FileOperationManager using mocked * Provide VolumeManager.getInstance() for FileOperationManager using mocked
* volume manager instance. * volume manager instance.
...@@ -282,17 +297,15 @@ let fileOperationManager; ...@@ -282,17 +297,15 @@ let fileOperationManager;
/** /**
* Initializes the test environment. * Initializes the test environment.
*/ */
function setUp() { export function setUp() {
// Mock LoadTimeData strings. // Mock LoadTimeData strings.
window.loadTimeData = { loadTimeData.data = {
data: { 'FILES_TRASH_ENABLED': true,
'FILES_TRASH_ENABLED': true, };
}, loadTimeData.getBoolean = function(key) {
getBoolean: function(key) { return loadTimeData.data_[key];
return window.loadTimeData.data[key];
},
getString: id => id,
}; };
loadTimeData.getString = id => id;
// Install mock chrome APIs. // Install mock chrome APIs.
installMockChrome(mockChrome); installMockChrome(mockChrome);
...@@ -302,7 +315,7 @@ function setUp() { ...@@ -302,7 +315,7 @@ function setUp() {
* Tests the fileOperationUtil.resolvePath function. * Tests the fileOperationUtil.resolvePath function.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testResolvePath(callback) { export function testResolvePath(callback) {
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
'/file': 10, '/file': 10,
...@@ -345,7 +358,7 @@ function testResolvePath(callback) { ...@@ -345,7 +358,7 @@ function testResolvePath(callback) {
/** /**
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testFindEntriesRecursively(callback) { export function testFindEntriesRecursively(callback) {
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
'/file.txt': 10, '/file.txt': 10,
...@@ -381,7 +394,7 @@ function testFindEntriesRecursively(callback) { ...@@ -381,7 +394,7 @@ function testFindEntriesRecursively(callback) {
/** /**
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testFindFilesRecursively(callback) { export function testFindFilesRecursively(callback) {
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
'/file.txt': 10, '/file.txt': 10,
...@@ -420,7 +433,7 @@ function testFindFilesRecursively(callback) { ...@@ -420,7 +433,7 @@ function testFindFilesRecursively(callback) {
/** /**
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testGatherEntriesRecursively(callback) { export function testGatherEntriesRecursively(callback) {
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
'/file.txt': 10, '/file.txt': 10,
...@@ -451,7 +464,7 @@ function testGatherEntriesRecursively(callback) { ...@@ -451,7 +464,7 @@ function testGatherEntriesRecursively(callback) {
* Tests the fileOperationUtil.deduplicatePath * Tests the fileOperationUtil.deduplicatePath
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testDeduplicatePath(callback) { export function testDeduplicatePath(callback) {
const fileSystem1 = createTestFileSystem('testVolume', {'/': DIRECTORY_SIZE}); const fileSystem1 = createTestFileSystem('testVolume', {'/': DIRECTORY_SIZE});
const fileSystem2 = createTestFileSystem('testVolume', { const fileSystem2 = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -499,7 +512,7 @@ function testDeduplicatePath(callback) { ...@@ -499,7 +512,7 @@ function testDeduplicatePath(callback) {
* Tests fileOperationManager copy. * Tests fileOperationManager copy.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testCopy(callback) { export function testCopy(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -573,7 +586,7 @@ function testCopy(callback) { ...@@ -573,7 +586,7 @@ function testCopy(callback) {
* Tests copying files when the destination volumes are same: the copy * Tests copying files when the destination volumes are same: the copy
* operations should be run sequentially. * operations should be run sequentially.
*/ */
function testCopyInSequential(callback) { export function testCopyInSequential(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -664,7 +677,7 @@ function testCopyInSequential(callback) { ...@@ -664,7 +677,7 @@ function testCopyInSequential(callback) {
* Tests copying files when the destination volumes are different: the copy * Tests copying files when the destination volumes are different: the copy
* operations should be run in parallel. * operations should be run in parallel.
*/ */
function testCopyInParallel(callback) { export function testCopyInParallel(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystemA = createTestFileSystem('volumeA', { const fileSystemA = createTestFileSystem('volumeA', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -751,7 +764,7 @@ function testCopyInParallel(callback) { ...@@ -751,7 +764,7 @@ function testCopyInParallel(callback) {
* Tests that copy operations fail when the destination volume is not * Tests that copy operations fail when the destination volume is not
* available. * available.
*/ */
function testCopyFails(callback) { export function testCopyFails(callback) {
// Prepare entries. // Prepare entries.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -801,7 +814,7 @@ function testCopyFails(callback) { ...@@ -801,7 +814,7 @@ function testCopyFails(callback) {
* Tests the fileOperationUtil.paste for move. * Tests the fileOperationUtil.paste for move.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testMove(callback) { export function testMove(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -860,7 +873,7 @@ function testMove(callback) { ...@@ -860,7 +873,7 @@ function testMove(callback) {
* Tests fileOperationManager.deleteEntries. * Tests fileOperationManager.deleteEntries.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testDelete(callback) { export function testDelete(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -897,7 +910,7 @@ function testDelete(callback) { ...@@ -897,7 +910,7 @@ function testDelete(callback) {
* Tests fileOperationManager.restore. * Tests fileOperationManager.restore.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testRestore(callback) { export function testRestore(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
...@@ -948,7 +961,7 @@ function testRestore(callback) { ...@@ -948,7 +961,7 @@ function testRestore(callback) {
* Tests fileOperationManager.zipSelection. * Tests fileOperationManager.zipSelection.
* @param {function(boolean)} callback Callback to be passed true on error. * @param {function(boolean)} callback Callback to be passed true on error.
*/ */
function testZip(callback) { export function testZip(callback) {
// Prepare entries and their resolver. // Prepare entries and their resolver.
const fileSystem = createTestFileSystem('testVolume', { const fileSystem = createTestFileSystem('testVolume', {
'/': DIRECTORY_SIZE, '/': DIRECTORY_SIZE,
......
...@@ -7,10 +7,18 @@ ...@@ -7,10 +7,18 @@
* https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html * https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html
*/ */
// clang-format off
// #import {VolumeManager} from '../../../externs/volume_manager.m.js';
// #import {fileOperationUtil} from './file_operation_util.m.js';
// #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {TrashConfig, TrashDirs, TrashEntry} from '../../common/js/trash.m.js';
// clang-format on
/** /**
* Implementation of trash. * Implementation of trash.
*/ */
class Trash { /* #export */ class Trash {
constructor() { constructor() {
/** /**
* Store TrashDirs to avoid repeated lookup, keyed by TrashConfig.id. * Store TrashDirs to avoid repeated lookup, keyed by TrashConfig.id.
......
...@@ -2,21 +2,34 @@ ...@@ -2,21 +2,34 @@
// 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 {assert} from 'chrome://resources/js/assert.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertEquals, assertFalse, assertTrue} from 'chrome://test/chai_assert.js';
import {VolumeManagerCommon} from '../../../base/js/volume_manager_types.m.js';
import {MockDirectoryEntry, MockFileEntry, MockFileSystem} from '../../common/js/mock_entry.m.js';
import {TrashDirs} from '../../common/js/trash.m.js';
import {MockVolumeManager} from './mock_volume_manager.m.js';
import {Trash} from './trash.m.js';
/** @type {!MockVolumeManager} */ /** @type {!MockVolumeManager} */
let volumeManager; let volumeManager;
/**
* State for the feature flags for faking in loadTimeData.
* @type {Object<string, boolean>}
* */
let flags = {};
// Set up the test components. // Set up the test components.
function setUp() { export function setUp() {
// Mock LoadTimeData strings. // Mock LoadTimeData strings.
window.loadTimeData = { flags = {
data: { 'FILES_TRASH_ENABLED': true,
'FILES_TRASH_ENABLED': true,
},
getBoolean: function(key) {
return window.loadTimeData.data[key];
},
getString: id => id,
}; };
loadTimeData.getBoolean = id => flags[id];
loadTimeData.getString = id => id;
volumeManager = new MockVolumeManager(); volumeManager = new MockVolumeManager();
} }
...@@ -31,7 +44,7 @@ function setUp() { ...@@ -31,7 +44,7 @@ function setUp() {
function checkRemoveFileOrDirectory( function checkRemoveFileOrDirectory(
filesTrashEnabled, rootType, path, deletePermanently, filesTrashEnabled, rootType, path, deletePermanently,
expectPermanentlyDelete) { expectPermanentlyDelete) {
window.loadTimeData.data['FILES_TRASH_ENABLED'] = filesTrashEnabled; flags['FILES_TRASH_ENABLED'] = filesTrashEnabled;
const volumeInfo = const volumeInfo =
volumeManager.createVolumeInfo(rootType, 'volumeId', 'label'); volumeManager.createVolumeInfo(rootType, 'volumeId', 'label');
const f = MockFileEntry.create(volumeInfo.fileSystem, path); const f = MockFileEntry.create(volumeInfo.fileSystem, path);
...@@ -58,7 +71,7 @@ function checkRemoveFileOrDirectory( ...@@ -58,7 +71,7 @@ function checkRemoveFileOrDirectory(
* Test that removeFileOrDirectory() correctly moves to trash, or permanently * Test that removeFileOrDirectory() correctly moves to trash, or permanently
* deletes. * deletes.
*/ */
function testRemoveFileOrDirectory() { export function testRemoveFileOrDirectory() {
// Only use trash if flag is enabled, entry is in 'downloads' volume, but not // Only use trash if flag is enabled, entry is in 'downloads' volume, but not
// in /.Trash. // in /.Trash.
...@@ -79,7 +92,7 @@ function testRemoveFileOrDirectory() { ...@@ -79,7 +92,7 @@ function testRemoveFileOrDirectory() {
* *
* @suppress {accessControls} Access permanentlyDeleteFileOrDirectory_(). * @suppress {accessControls} Access permanentlyDeleteFileOrDirectory_().
*/ */
async function testPermanentlyDeleteFileOrDirectory(done) { export async function testPermanentlyDeleteFileOrDirectory(done) {
const trash = new Trash(); const trash = new Trash();
const fs = new MockFileSystem('volumeId'); const fs = new MockFileSystem('volumeId');
const dir = MockDirectoryEntry.create(fs, '/dir'); const dir = MockDirectoryEntry.create(fs, '/dir');
...@@ -108,7 +121,7 @@ async function testPermanentlyDeleteFileOrDirectory(done) { ...@@ -108,7 +121,7 @@ async function testPermanentlyDeleteFileOrDirectory(done) {
/** /**
* Test trash in MyFiles. * Test trash in MyFiles.
*/ */
async function testMyFilesTrash(done) { export async function testMyFilesTrash(done) {
const trash = new Trash(); const trash = new Trash();
const deletePermanently = false; const deletePermanently = false;
const downloads = volumeManager.getCurrentProfileVolumeInfo( const downloads = volumeManager.getCurrentProfileVolumeInfo(
...@@ -163,7 +176,7 @@ async function testMyFilesTrash(done) { ...@@ -163,7 +176,7 @@ async function testMyFilesTrash(done) {
* Test that Downloads has its own /Downloads/.Trash since it is a separate * Test that Downloads has its own /Downloads/.Trash since it is a separate
* mount on a device and we don't want move to trash to be a copy operation. * mount on a device and we don't want move to trash to be a copy operation.
*/ */
async function testDownloadsHasOwnTrash(done) { export async function testDownloadsHasOwnTrash(done) {
const trash = new Trash(); const trash = new Trash();
const deletePermanently = false; const deletePermanently = false;
const downloads = volumeManager.getCurrentProfileVolumeInfo( const downloads = volumeManager.getCurrentProfileVolumeInfo(
...@@ -224,7 +237,7 @@ async function testDownloadsHasOwnTrash(done) { ...@@ -224,7 +237,7 @@ async function testDownloadsHasOwnTrash(done) {
/** /**
* Test crostini trash in .local/share/Trash. * Test crostini trash in .local/share/Trash.
*/ */
async function testCrostiniTrash(done) { export async function testCrostiniTrash(done) {
const trash = new Trash(); const trash = new Trash();
const deletePermanently = false; const deletePermanently = false;
const crostini = volumeManager.createVolumeInfo( const crostini = volumeManager.createVolumeInfo(
...@@ -277,7 +290,7 @@ async function testCrostiniTrash(done) { ...@@ -277,7 +290,7 @@ async function testCrostiniTrash(done) {
/** /**
* Test restore(). * Test restore().
*/ */
async function testRestore(done) { export async function testRestore(done) {
const trash = new Trash(); const trash = new Trash();
const deletePermanently = false; const deletePermanently = false;
const downloads = volumeManager.getCurrentProfileVolumeInfo( const downloads = volumeManager.getCurrentProfileVolumeInfo(
...@@ -328,7 +341,7 @@ async function testRestore(done) { ...@@ -328,7 +341,7 @@ async function testRestore(done) {
* *
* @suppress {accessControls} Access removeOldItems_() and inProgress_. * @suppress {accessControls} Access removeOldItems_() and inProgress_.
*/ */
async function testRemoveOldItems_(done) { export async function testRemoveOldItems_(done) {
const trash = new Trash(); const trash = new Trash();
const deletePermanently = false; const deletePermanently = false;
const downloads = volumeManager.getCurrentProfileVolumeInfo( const downloads = volumeManager.getCurrentProfileVolumeInfo(
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* @param {string} b Path. * @param {string} b Path.
* @return {string} Joined path. * @return {string} Joined path.
*/ */
function joinPath(a, b) { /* #export */ function joinPath(a, b) {
return a.replace(/\/+$/, '') + '/' + b.replace(/^\/+/, ''); return a.replace(/\/+$/, '') + '/' + b.replace(/^\/+/, '');
} }
......
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