Commit 342faed0 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Refactor DirectoryTree part 2 of 2

This is part of a reverted CL crrev.com/c/1300993, this is the part
that had caused flakiness on MSAN.

Change EntryList |updateSubDirectories| method to read its content
using FS API, which turns it into async. EntryList is used by MyFiles
so Downloads folder appearance is delayed comparing to previous
approach. Some tests expected Downloads to be readily available then
they become flaky, crrev.com/c/1313709 fixes this for most tests.

Fix unittest that started failing because it metadataModel was null.

Bug: 899664, 889511
Change-Id: If7cf4dea331938cb5919ef4a0ebaa73afaa2ec20
Reviewed-on: https://chromium-review.googlesource.com/c/1313711Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604779}
parent 01aafe52
...@@ -745,26 +745,43 @@ EntryListItem.prototype = { ...@@ -745,26 +745,43 @@ EntryListItem.prototype = {
*/ */
EntryListItem.prototype.updateSubDirectories = function( EntryListItem.prototype.updateSubDirectories = function(
recursive, opt_successCallback, opt_errorCallback) { recursive, opt_successCallback, opt_errorCallback) {
if (!this.entry) { if (!this.entry || this.entry.createReader === undefined) {
opt_errorCallback && opt_errorCallback(); opt_errorCallback && opt_errorCallback();
return; return;
} }
this.entries_ = []; this.entries_ = [];
if (this.entry && this.entry.children) { const onSuccess = (entries) => {
for (let childEntry of this.entry.children) { this.entries_ = entries;
if (childEntry instanceof VolumeEntry) { this.updateSubElementsFromList(recursive);
// For VolumeEntry we want to display its root. if (this.entries_.length > 0)
this.entries_.push(childEntry.rootEntry); this.expanded = true;
} else { opt_successCallback && opt_successCallback();
this.entries_.push(childEntry); // TODO(lucmult): Remove this log once flakiness is fixed.
console.log('EntryListItem children loaded.');
};
const reader = this.entry.createReader();
const entries = [];
const readEntry = () => {
reader.readEntries((results) => {
if (!results.length) {
onSuccess(this.sortEntries(entries));
return;
} }
} for (let i = 0; i < results.length; i++) {
} const entry = results[i];
if (this.entries_.length > 0) { if (entry.isDirectory) {
this.expanded = true; // For VolumeEntry we want to display its root.
} if (entry instanceof VolumeEntry) {
this.updateSubElementsFromList(recursive); entries.push(entry.rootEntry);
opt_successCallback && opt_successCallback(); } else {
entries.push(entry);
}
}
}
readEntry();
});
};
readEntry();
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -501,8 +501,9 @@ function testUpdateSubElementsFromListSections() { ...@@ -501,8 +501,9 @@ function testUpdateSubElementsFromListSections() {
assertEquals(NavigationSection.MY_FILES, myFilesItem.section); assertEquals(NavigationSection.MY_FILES, myFilesItem.section);
assertEquals(NavigationSection.CLOUD, driveItem.section); assertEquals(NavigationSection.CLOUD, driveItem.section);
const metadataModel = mockMetadataModel();
DirectoryTree.decorate(directoryTree, directoryModel, volumeManager, DirectoryTree.decorate(directoryTree, directoryModel, volumeManager,
null, fileOperationManager, true); metadataModel, fileOperationManager, true);
directoryTree.dataModel = treeModel; directoryTree.dataModel = treeModel;
directoryTree.updateSubElementsFromList(false); directoryTree.updateSubElementsFromList(false);
...@@ -958,9 +959,10 @@ function testInsideMyDriveAndInsideDrive(callback) { ...@@ -958,9 +959,10 @@ function testInsideMyDriveAndInsideDrive(callback) {
.webkitResolveLocalFileSystemURLEntries['filesystem:downloads/folder1'] = .webkitResolveLocalFileSystemURLEntries['filesystem:downloads/folder1'] =
new MockDirectoryEntry(downloadsFileSystem, '/folder1'); new MockDirectoryEntry(downloadsFileSystem, '/folder1');
const metadataModel = mockMetadataModel();
DirectoryTree.decorate( DirectoryTree.decorate(
directoryTree, directoryModel, volumeManager, null, fileOperationManager, directoryTree, directoryModel, volumeManager, metadataModel,
true); fileOperationManager, true);
directoryTree.dataModel = new MockNavigationListModel(volumeManager); directoryTree.dataModel = new MockNavigationListModel(volumeManager);
directoryTree.redraw(true); directoryTree.redraw(true);
......
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