Skip to content

Commit

Permalink
Files app: Using the script to migrate to TS
Browse files Browse the repository at this point in the history
Bug: b:289003444
Change-Id: I10d80aca795a4c5a7515de5c8c5048139f7bcffd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4979126
Reviewed-by: Wenbo Jie <wenbojie@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216734}
  • Loading branch information
Luciano Pacheco authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent 9397594 commit fd89e63
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 93 deletions.
15 changes: 0 additions & 15 deletions ui/file_manager/file_manager/common/js/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ visibility = [

group("js_modules") {
deps = [
":app_util",
":array_data_model",
":async_util",
":error_counter",
Expand All @@ -33,16 +32,6 @@ group("js_modules") {
]
}

js_library("app_util") {
deps = [
":storage",
"//ui/file_manager/file_manager/externs:file_manager_private",
"//ui/file_manager/file_manager/externs:volume_manager",
]
externs_list =
[ "//ui/file_manager/file_manager/externs/app_window_common.js" ]
}

js_library("array_data_model") {
deps = [
"//ash/webui/common/resources:assert",
Expand Down Expand Up @@ -222,10 +211,6 @@ js_unittest("util_unittest") {
]
}

js_unittest("volume_manager_types_unittest") {
deps = [ ":volume_manager_types" ]
}

js_library("volume_manager_types") {
deps = [
"//ash/webui/common/resources:assert",
Expand Down
51 changes: 0 additions & 51 deletions ui/file_manager/file_manager/common/js/app_util.js

This file was deleted.

40 changes: 40 additions & 0 deletions ui/file_manager/file_manager/common/js/app_util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {storage} from './storage.js';

/**
* Save app launch data to the local storage.
*/
export function saveAppState() {
if (!window.appState) {
return;
}

// Maps the appId to JSON serialized AppState.
const items: Record<string, string> = {};

items[window.appID] = JSON.stringify(window.appState);
storage.local.setAsync(items);
}

/**
* Updates the app state.
*
* @param currentDirectoryURL Currently opened directory as an URL.qq
* If null the value is left unchanged.
* @param selectionURL Currently selected entry as an URL. If null the
* value is left unchanged.
*/
export function updateAppState(
currentDirectoryURL: null|string, selectionURL: null|string) {
window.appState = window.appState || {};
if (currentDirectoryURL !== null) {
window.appState.currentDirectoryURL = currentDirectoryURL;
}
if (selectionURL !== null) {
window.appState.selectionURL = selectionURL;
}
saveAppState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {assertEquals, assertFalse, assertTrue} from 'chrome://webui-test/chromeos/chai_assert.js';
import {assertEquals, assertFalse, assertNotEquals, assertTrue} from 'chrome://webui-test/chromeos/chai_assert.js';

import {MockFileEntry, MockFileSystem} from './mock_entry.js';
import {VolumeManagerCommon} from './volume_manager_types.js';

// Test that every volumeType has a rootType, and that it maps back to the same
// volumeType.
export function testRootTypeFromVolumeTypeBijection() {
Object.keys(VolumeManagerCommon.VolumeType).forEach((key) => {
// @ts-ignore: error TS7053: Element implicitly has an 'any' type because
// expression of type 'string' can't be used to index type 'typeof
// VolumeType'.
const volumeType = VolumeManagerCommon.VolumeType[key];
assertTrue(volumeType !== undefined);

for (const volumeType of Object.values(VolumeManagerCommon.VolumeType)) {
// System Internal volumes do not have a corresponding root.
if (volumeType == VolumeManagerCommon.VolumeType.SYSTEM_INTERNAL) {
if (volumeType === VolumeManagerCommon.VolumeType.SYSTEM_INTERNAL) {
return;
}

const rootType = VolumeManagerCommon.getRootTypeFromVolumeType(volumeType);
assertTrue(
volumeType == VolumeManagerCommon.getVolumeTypeFromRootType(rootType));
});
assertEquals(
volumeType, VolumeManagerCommon.getVolumeTypeFromRootType(rootType));
}
}

// Test that all rootType have a corresponding volumeType, except for "fake"
// root types that do not have a volume of their own.
export function testEveryRootTypeHasAVolumeType() {
Object.keys(VolumeManagerCommon.RootType).forEach((key) => {
// @ts-ignore: error TS7053: Element implicitly has an 'any' type because
// expression of type 'string' can't be used to index type 'typeof
// RootType'.
const rootType = VolumeManagerCommon.RootType[key];
assertTrue(rootType !== undefined);

for (const rootType of Object.values(VolumeManagerCommon.RootType)) {
// The "Recent" view and "Google Drive" parent entry are not handled in the
// switch because they do not have a corresponding volume.
// TODO(tapted): Validate this against isFakeEntry(..) when
Expand All @@ -49,8 +37,8 @@ export function testEveryRootTypeHasAVolumeType() {
}

const volumeType = VolumeManagerCommon.getVolumeTypeFromRootType(rootType);
assertTrue(volumeType !== undefined);
});
assertNotEquals(volumeType, undefined);
}
}

// Tests that IsRecentArcEntry() should return true/false if an entry belongs/
Expand Down
7 changes: 7 additions & 0 deletions ui/file_manager/file_manager/definitions/file_manager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ interface FileManager {
directoryTreeNamingController: DirectoryTreeNamingController;
}

interface AppState {
currentDirectoryURL?: string;
selectionURL?: string;
}

/**
* The singleton instance for FileManager is available in the Window object.
*/
Expand All @@ -36,6 +41,8 @@ declare global {
/** Namespace used for test utils. */
test: any;

appState?: AppState;

webkitResolveLocalFileSystemURL(
url: string, successCallback: FileSystemEntryCallback,
errorCallback: ErrorCallback): void;
Expand Down
1 change: 0 additions & 1 deletion ui/file_manager/file_manager/foreground/js/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ js_library("app_state_controller") {
"ui:file_manager_ui",
"ui:list_container",
"//ash/webui/common/resources:assert",
"//ui/file_manager/file_manager/common/js:app_util",
"//ui/file_manager/file_manager/common/js:util",
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import {assert} from 'chrome://resources/ash/common/assert.js';

import {appUtil} from '../../common/js/app_util.js';
import {saveAppState, updateAppState} from '../../common/js/app_util.js';
import {DialogType} from '../../common/js/dialog_type.js';
import {isRecentRoot} from '../../common/js/entry_utils.js';
import {storage} from '../../common/js/storage.js';
Expand Down Expand Up @@ -171,7 +171,7 @@ export class AppStateController {
// @ts-ignore: error TS2339: Property 'appState' does not exist on type
// 'Window & typeof globalThis'.
window.appState.viewOptions = prefs;
appUtil.saveAppState();
saveAppState();
}
}

Expand Down Expand Up @@ -256,7 +256,7 @@ export class AppStateController {
}
}

appUtil.updateAppState(
updateAppState(
// @ts-ignore: error TS2531: Object is possibly 'null'.
this.directoryModel_.getCurrentDirEntry() ?
// @ts-ignore: error TS2531: Object is possibly 'null'.
Expand Down
4 changes: 2 additions & 2 deletions ui/file_manager/file_names.gni
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static_js_files = [
"file_manager/background/js/volume_manager_util.js",

# Files Common:
"file_manager/common/js/app_util.js",
"file_manager/common/js/array_data_model.js",
"file_manager/common/js/async_util.js",
"file_manager/common/js/error_counter.js",
Expand Down Expand Up @@ -193,6 +192,7 @@ static_js_files = [
ts_files = [
# Common.
"file_manager/common/js/api.ts",
"file_manager/common/js/app_util.ts",
"file_manager/common/js/cr_ui.ts",
"file_manager/common/js/dom_utils.ts",
"file_manager/common/js/dialog_type.ts",
Expand Down Expand Up @@ -367,6 +367,7 @@ ts_test_files = [
"file_manager/common/js/file_types_base_unittest.ts",
"file_manager/common/js/lru_cache_unittest.ts",
"file_manager/common/js/translations_unittest.ts",
"file_manager/common/js/volume_manager_types_unittest.ts",

# Containers
"file_manager/containers/breadcrumb_container_unittest.ts",
Expand Down Expand Up @@ -498,7 +499,6 @@ unittest_files = [
"file_manager/common/js/test_error_reporting.js",
"file_manager/common/js/unittest_util.js",
"file_manager/common/js/util_unittest.js",
"file_manager/common/js/volume_manager_types_unittest.js",

# Background:
"file_manager/background/js/file_operation_handler_unittest.js",
Expand Down

0 comments on commit fd89e63

Please sign in to comment.