Commit 39ae2942 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Remove type ArrayDataModel from NavigationListModel

Change NavigationListModel constructor to accept only
FolderShortcutsDataModel in shortcutListModel argument because
NavigationListModel uses methods specific to FolderShortcutsDataModel
that aren't available on ArrayDataModel.

Add method asFolderShortcutsDataModel() to MockFolderShortcutDataModel
to type cast to FolderShortcutsDataModel to pass the mock to
NavigationListModel.

NOTE: Currently MockFolderShortcutDataModel doesn't implement the whole
FolderShortcutsDataModel API, it rather implements the API needed by the
tests.

Fixes: 931481
Change-Id: Iac0c08dcb900fd2a16249baa6eb16c7d8c137a18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056003
Commit-Queue: Noel Gordon <noel@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741379}
parent 1c15bbc4
......@@ -193,6 +193,7 @@ js_library("mock_directory_model") {
js_library("mock_folder_shortcut_data_model") {
testonly = true
deps = [
":folder_shortcuts_data_model",
"//ui/file_manager/file_manager/common/js:mock_entry",
"//ui/webui/resources/js/cr/ui:array_data_model",
]
......
......@@ -8,6 +8,22 @@
* Mock FolderShortcutDataModel.
*/
class MockFolderShortcutDataModel extends cr.ui.ArrayDataModel {
/**
* @param {!Array} array
*/
constructor(array) {
super(array);
}
/**
* @return {!FolderShortcutsDataModel}
* @public
*/
asFolderShortcutsDataModel() {
const instance = /** @type {!Object} */ (this);
return /** @type {!FolderShortcutsDataModel} */ (instance);
}
/**
* Mock function for FolderShortcutDataModel.compare().
* @param {MockEntry} a First parameter to be compared.
......
......@@ -169,8 +169,8 @@ class NavigationModelFakeItem extends NavigationModelItem {
class NavigationListModel extends cr.EventTarget {
/**
* @param {!VolumeManager} volumeManager VolumeManager instance.
* @param {(!cr.ui.ArrayDataModel|!FolderShortcutsDataModel)}
* shortcutListModel The list of folder shortcut.
* @param {!FolderShortcutsDataModel} shortcutListModel The list of folder
* shortcut.
* @param {NavigationModelFakeItem} recentModelItem Recent folder.
* @param {!DirectoryModel} directoryModel
* @param {!AndroidAppListModel} androidAppListModel
......@@ -187,7 +187,7 @@ class NavigationListModel extends cr.EventTarget {
this.volumeManager_ = volumeManager;
/**
* @private {(!cr.ui.ArrayDataModel|!FolderShortcutsDataModel)}
* @private {!FolderShortcutsDataModel}
* @const
*/
this.shortcutListModel_ = shortcutListModel;
......
......@@ -84,8 +84,8 @@ function testModel() {
createFakeAndroidAppListModel(['android:app1', 'android:app2']);
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModelWithApps);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModelWithApps);
model.linuxFilesItem = crostiniFakeItem;
assertEquals(6, model.length);
......@@ -124,8 +124,8 @@ function testNoRecentOrLinuxFiles() {
const recentItem = null;
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
assertEquals(3, model.length);
assertEquals(
......@@ -148,8 +148,8 @@ function testAddAndRemoveShortcuts() {
const recentItem = null;
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
assertEquals(3, model.length);
......@@ -211,8 +211,8 @@ function testAddAndRemoveVolumes() {
const recentItem = null;
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
assertEquals(3, model.length);
......@@ -358,8 +358,8 @@ function testOrderAndNestItems() {
// Constructor already calls orderAndNestItems_.
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModelWithApps);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModelWithApps);
// Check items order and that MTP/Archive/Removable respect the original
// order.
......@@ -479,8 +479,8 @@ function testMyFilesVolumeEnabled(callback) {
// Constructor already calls orderAndNestItems_.
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
model.linuxFilesItem = crostiniFakeItem;
assertEquals(2, model.length);
......@@ -536,8 +536,8 @@ function testMultipleUsbPartitionsGrouping() {
'partition3', 'device/path/1'));
const model = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
// Check that the common root shows 3 partitions.
let groupedUsbs = /** @type NavigationModelFakeItem */ (model.item(2));
......
......@@ -443,8 +443,8 @@ function testUpdateSubElementsFromListSections() {
const shortcutListModel = new MockFolderShortcutDataModel([]);
const androidAppListModel = createFakeAndroidAppListModel(['android:app1']);
const treeModel = new NavigationListModel(
volumeManager, shortcutListModel, recentItem, directoryModel,
androidAppListModel);
volumeManager, shortcutListModel.asFolderShortcutsDataModel(), recentItem,
directoryModel, androidAppListModel);
const myFilesItem = treeModel.item(0);
const driveItem = treeModel.item(1);
const androidAppItem = treeModel.item(2);
......
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