Commit ef43152b authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Remove Team Drive root from directory tree instead of hiding

Remove Team Drive root from the directory tree when user has no team
drive. Fixes a bug where users could navigate to Team Drive root via
the keyboard even though the root was hidden.

Bug: 864890
Change-Id: I2f6b59ca908ae609302cb873b6b182842cedc1c4
Reviewed-on: https://chromium-review.googlesource.com/1163352
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581114}
parent d00fd143
...@@ -977,27 +977,68 @@ DriveVolumeItem.prototype.handleClick = function(e) { ...@@ -977,27 +977,68 @@ DriveVolumeItem.prototype.handleClick = function(e) {
}; };
/** /**
* Sets the hidden state of the given item depending on whether the user has any * Creates Team Drives root if there is any team drive, if there is no team
* Team Drives. * drive, then it removes the root.
* *
* Since we don't currently support any functionality with just the grand root * Since we don't currently support any functionality with just the grand root
* (e.g. you can't create a new team drive from the root yet), hide the grand * (e.g. you can't create a new team drive from the root yet), remove/don't
* root unless the user has at least one Team Drive. If there is at least one * create the grand root so it can't be reached via keyboard.
* Team Drive, show it. * If there is at least one Team Drive, add/show the Team Drives trand root.
* *
* @param {!DirectoryItem} teamDrivesGrandRootItem The item to show if there is * @return {!Promise<SubDirectoryItem>} Resolved with Team Drive Grand Root
* at least one Team Drive, or hide if not. * SubDirectoryItem instance, or undefined when it shouldn't exist.
* @private * @private
*/ */
DriveVolumeItem.prototype.setHiddenForTeamDrivesGrandRoot_ = function( DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() {
teamDrivesGrandRootItem) { return new Promise(resolve => {
var teamDriveEntry = this.volumeInfo_.teamDriveDisplayRoot; const teamDriveGrandRoot = this.volumeInfo_.teamDriveDisplayRoot;
if (!teamDriveEntry) if (!teamDriveGrandRoot) {
return; // Team Drive is disabled.
var reader = teamDriveEntry.createReader(); resolve();
reader.readEntries(function(results) { return;
metrics.recordSmallCount('TeamDrivesCount', results.length); }
teamDrivesGrandRootItem.hidden = results.length == 0;
let index;
for (var i = 0; i < this.items.length; i++) {
const entry = this.items[i] && this.items[i].entry;
if (entry && util.isSameEntry(entry, teamDriveGrandRoot)) {
index = i;
break;
}
}
const reader = teamDriveGrandRoot.createReader();
reader.readEntries(results => {
metrics.recordSmallCount('TeamDrivesCount', results.length);
// Only create grand root if there is at least 1 child/result.
if (results.length) {
if (index) {
this.items[index].hidden = false;
resolve(this.items[index]);
return;
}
// Create if it doesn't exist yet.
const label = util.getEntryLabel(
this.parentTree_.volumeManager_.getLocationInfo(
teamDriveGrandRoot),
teamDriveGrandRoot) ||
'';
const item = new SubDirectoryItem(
label, teamDriveGrandRoot, this, this.parentTree_);
this.addAt(item, 1);
item.updateSubDirectories(false);
resolve(item);
return;
} else {
// When there is no team drive, the grand root should be removed.
if (index && this.items[index].parentItem) {
this.items[index].parentItem.remove(this.items[index]);
}
resolve();
return;
}
});
}); });
}; };
...@@ -1032,21 +1073,19 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) { ...@@ -1032,21 +1073,19 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) {
} }
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
var item = new SubDirectoryItem( // Only create the team drives root if there is at least 1 team drive.
util.getEntryLabel( const entry = entries[i];
this.parentTree_.volumeManager_.getLocationInfo(entries[i]), if (entry === teamDrivesDisplayRoot) {
entries[i]) || this.createTeamDrivesGrandRoot_();
'', } else {
entries[i], this, this.parentTree_); const label =
util.getEntryLabel(
// Hide the team drives root in case we have no team drives. this.parentTree_.volumeManager_.getLocationInfo(entry), entry) ||
if (entries[i] === teamDrivesDisplayRoot) { '';
item.hidden = true; const item = new SubDirectoryItem(label, entry, this, this.parentTree_);
this.setHiddenForTeamDrivesGrandRoot_(item); this.add(item);
item.updateSubDirectories(false);
} }
this.add(item);
item.updateSubDirectories(false);
} }
// When My files is disabled Drive should be expanded by default. // When My files is disabled Drive should be expanded by default.
// TODO(crbug.com/850348): Remove this once flag is removed. // TODO(crbug.com/850348): Remove this once flag is removed.
...@@ -1065,11 +1104,18 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) { ...@@ -1065,11 +1104,18 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) {
DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) { DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
// The first item is My Drive, and the second item is Team Drives. // The first item is My Drive, and the second item is Team Drives.
// Keep in sync with |fixedEntries| in |updateSubDirectories|. // Keep in sync with |fixedEntries| in |updateSubDirectories|.
var index = util.isTeamDriveEntry(changedDirectoryEntry) ? 1 : 0; const isTeamDriveChild = util.isTeamDriveEntry(changedDirectoryEntry);
this.items[index].updateItemByEntry(changedDirectoryEntry); const index = isTeamDriveChild ? 1 : 0;
if (util.isTeamDrivesGrandRoot(changedDirectoryEntry) &&
this.volumeInfo_.teamDriveDisplayRoot) { // If Team Drive grand root has been removed and we receive an update for an
this.setHiddenForTeamDrivesGrandRoot_(this.items[index]); // team drive, we need to create the Team Drive grand root.
if (isTeamDriveChild) {
this.createTeamDrivesGrandRoot_().then(teamDriveGranRootItem => {
if (teamDriveGranRootItem)
this.items[index].updateItemByEntry(changedDirectoryEntry);
});
} else {
this.items[index].updateItemByEntry(changedDirectoryEntry);
} }
}; };
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<script src="../mock_directory_model.js"></script> <script src="../mock_directory_model.js"></script>
<script src="../mock_navigation_list_model.js"></script> <script src="../mock_navigation_list_model.js"></script>
<script src="../navigation_list_model.js"></script> <script src="../navigation_list_model.js"></script>
<script src="../constants.js"></script>
<script src="directory_tree.js"></script> <script src="directory_tree.js"></script>
<script src="directory_tree_unittest.js"></script> <script src="directory_tree_unittest.js"></script>
......
...@@ -124,7 +124,7 @@ function testCreateDirectoryTree(callback) { ...@@ -124,7 +124,7 @@ function testCreateDirectoryTree(callback) {
* *
* Google Drive * Google Drive
* - My Drive * - My Drive
* - Team Drives * - Team Drives (only if there is a child team drive).
* - Shared with me * - Shared with me
* - Offline * - Offline
* Downloads * Downloads
...@@ -194,8 +194,7 @@ function testCreateDirectoryTreeWithTeamDrive(callback) { ...@@ -194,8 +194,7 @@ function testCreateDirectoryTreeWithTeamDrive(callback) {
/** /**
* Test case for creating tree with empty Team Drives. * Test case for creating tree with empty Team Drives.
* Team Drives subtree should be hidden when the user don't have access to any * The Team Drives subtree should be removed if the user has no team drives.
* Team Drive.
* *
* @param {!function(boolean)} callback A callback function which is called with * @param {!function(boolean)} callback A callback function which is called with
* test result. * test result.
...@@ -238,21 +237,19 @@ function testCreateDirectoryTreeWithEmptyTeamDrive(callback) { ...@@ -238,21 +237,19 @@ function testCreateDirectoryTreeWithEmptyTeamDrive(callback) {
reportPromise( reportPromise(
waitUntil(function() { waitUntil(function() {
// Root entries under Drive volume is generated, plus Team Drives. // Root entries under Drive volume is generated, Team Drives isn't
// included because it has no child.
// See testCreateDirectoryTreeWithTeamDrive for detail. // See testCreateDirectoryTreeWithTeamDrive for detail.
return driveItem.items.length == 4; return driveItem.items.length == 3;
}).then(function() { }).then(function() {
var teamDrivesItemFound = false; var teamDrivesItemFound = false;
for (var i = 0; i < driveItem.items.length; i++) { for (var i = 0; i < driveItem.items.length; i++) {
if (driveItem.items[i].label == str('DRIVE_TEAM_DRIVES_LABEL')) { if (driveItem.items[i].label == str('DRIVE_TEAM_DRIVES_LABEL')) {
assertEquals(
true, driveItem.items[i].hidden,
'Team Drives node should not be shown');
teamDrivesItemFound = true; teamDrivesItemFound = true;
break; break;
} }
} }
assertTrue(teamDrivesItemFound, 'Team Drives node should be generated'); assertFalse(teamDrivesItemFound, 'Team Drives should NOT be generated');
}), }),
callback); callback);
} }
...@@ -403,7 +400,7 @@ function testAddFirstTeamDrive(callback) { ...@@ -403,7 +400,7 @@ function testAddFirstTeamDrive(callback) {
reportPromise( reportPromise(
waitUntil(() => { waitUntil(() => {
return driveItem.items.length == 4; return driveItem.items.length == 3;
}) })
.then(() => { .then(() => {
window.webkitResolveLocalFileSystemURLEntries window.webkitResolveLocalFileSystemURLEntries
...@@ -434,7 +431,7 @@ function testAddFirstTeamDrive(callback) { ...@@ -434,7 +431,7 @@ function testAddFirstTeamDrive(callback) {
/** /**
* Test removing the last team drive for a user. * Test removing the last team drive for a user.
* Team Drives subtree should be hidden after the change notification is * Team Drives subtree should be removed after the change notification is
* delivered. * delivered.
* *
* @param {!function(boolean)} callback A callback function which is called with * @param {!function(boolean)} callback A callback function which is called with
...@@ -501,14 +498,15 @@ function testRemoveLastTeamDrive(callback) { ...@@ -501,14 +498,15 @@ function testRemoveLastTeamDrive(callback) {
} }
}) })
.then(() => { .then(() => {
// Wait team drive grand root to appear.
return waitUntil(() => { return waitUntil(() => {
for (var i = 0; i < driveItem.items.length; i++) { for (var i = 0; i < driveItem.items.length; i++) {
if (driveItem.items[i].label == if (driveItem.items[i].label ==
str('DRIVE_TEAM_DRIVES_LABEL')) { str('DRIVE_TEAM_DRIVES_LABEL')) {
return driveItem.items[i].hidden; return false;
} }
} }
return false; return true;
}); });
}), }),
callback); callback);
......
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