Commit 51574954 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert share_and_manage_dialog.js to use async-await.

Bug: 909056
Change-Id: I285bf68f024899c169b87129f988b7a5f82c1cd3
Reviewed-on: https://chromium-review.googlesource.com/c/1354749
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612144}
parent 4b8ad57a
......@@ -11,92 +11,59 @@
* @param {!string} url Expected URL for the browser to visit.
* @param {!string|undefined} teamDrive If set, the team drive to switch to.
*/
function shareWithOthersExpectBrowserURL(path, url, teamDrive = undefined) {
let appId;
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
},
// Navigate to the specified team drive if one is specified.
function(results) {
appId = results.windowId;
if (teamDrive === undefined) {
this.next();
return;
}
remoteCall
.navigateWithDirectoryTree(
appId,
teamDrive === '' ? '/team_drives' : `/team_drives/${teamDrive}`,
'Team Drives', 'drive')
.then(this.next);
},
// Wait for the file list to update if we navigated.
function() {
if (teamDrive === undefined) {
this.next();
return;
}
remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length)
.then(this.next);
},
// Select the given |path|.
function() {
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the entry to be selected.
function(result) {
chrome.test.assertTrue(!!result, 'selectFile failed');
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
},
// Wait for the share button to appear.
function() {
remoteCall.waitForElement(appId, '#share-menu-button:not([disabled])')
.then(this.next);
},
// Click the share button to open share menu.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#share-menu-button'], this.next);
},
// Check: the "Share with others" menu item should be shown enabled.
function(result) {
chrome.test.assertTrue(!!result);
const shareMenuItem =
'#share-menu:not([hidden]) [command="#share"]:not([disabled])';
remoteCall.waitForElement(appId, shareMenuItem).then(this.next);
},
// Click the "Share with others" menu item.
function(result) {
chrome.test.assertTrue(!!result);
const shareWithOthers = '#share-menu [command="#share"]:not([disabled])';
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [shareWithOthers], this.next);
},
// Wait for the share menu to disappear.
function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#share-menu[hidden]').then(this.next);
},
// Wait for the browser window to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next);
},
// Check: the browser navigated to the expected URL.
function(visitedUrl) {
chrome.test.assertEq(url, visitedUrl);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
async function shareWithOthersExpectBrowserURL(
path, url, teamDrive = undefined) {
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
// Navigate to the specified team drive if one is specified.
if (teamDrive !== undefined) {
await remoteCall.navigateWithDirectoryTree(
appId, teamDrive === '' ? '/team_drives' : `/team_drives/${teamDrive}`,
'Team Drives', 'drive');
// Wait for the file list to update.
await remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length);
}
// Select the given |path|.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [path]),
'selectFile failed');
// Wait for the entry to be selected.
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Wait for the share button to appear.
chrome.test.assertTrue(!!await remoteCall.waitForElement(
appId, '#share-menu-button:not([disabled])'));
// Click the share button to open share menu.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#share-menu-button']));
// Check: the "Share with others" menu item should be shown enabled.
const shareMenuItem =
'#share-menu:not([hidden]) [command="#share"]:not([disabled])';
chrome.test.assertTrue(
!!await remoteCall.waitForElement(appId, shareMenuItem));
// Click the "Share with others" menu item.
const shareWithOthers = '#share-menu [command="#share"]:not([disabled])';
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [shareWithOthers]),
'fakeMouseClick failed');
// Wait for the share menu to disappear.
chrome.test.assertTrue(
!!await remoteCall.waitForElement(appId, '#share-menu[hidden]'));
// Wait for the browser window to appear and navigate to the expected URL.
chrome.test.assertEq(
url, await remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, []));
}
/**
......@@ -106,97 +73,61 @@ function shareWithOthersExpectBrowserURL(path, url, teamDrive = undefined) {
* @param {!string} url Expected URL for the browser to visit.
* @param {!string|undefined} teamDrive If set, the team drive to switch to.
*/
function manageWithDriveExpectBrowserURL(path, url, teamDrive = undefined) {
let appId;
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
},
// Navigate to the specified team drive if one is specified.
function(results) {
appId = results.windowId;
if (teamDrive === undefined) {
this.next();
return;
}
remoteCall
.navigateWithDirectoryTree(
appId,
teamDrive === '' ? '/team_drives' : `/team_drives/${teamDrive}`,
'Team Drives', 'drive')
.then(this.next);
},
// Wait for the file list to update if we navigated.
function() {
if (teamDrive === undefined) {
this.next();
return;
}
remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length)
.then(this.next);
},
// Select the given |path|.
function() {
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the entry to be selected.
function(result) {
chrome.test.assertTrue(!!result, 'selectFile failed');
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
},
// Right-click the selected entry.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]'], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the "Manage in Drive" menu item to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForElement(
appId,
'[command="#manage-in-drive"]:not([hidden]):not([disabled])')
.then(this.next);
},
// Click the "Manage in Drive" menu item.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
async function manageWithDriveExpectBrowserURL(
path, url, teamDrive = undefined) {
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
// Navigate to the specified team drive if one is specified.
if (teamDrive !== undefined) {
await remoteCall.navigateWithDirectoryTree(
appId, teamDrive === '' ? '/team_drives' : `/team_drives/${teamDrive}`,
'Team Drives', 'drive');
// Wait for the file list to update.
await remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length);
}
// Select the given |path|.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [path]),
'selectFile failed');
// Wait for the entry to be selected.
chrome.test.assertTrue(
!!await remoteCall.waitForElement(appId, '.table-row[selected]'));
// Right-click the selected entry.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']),
'fakeMouseClick failed');
// Wait for the context menu to appear.
chrome.test.assertTrue(!!await remoteCall.waitForElement(
appId, '#file-context-menu:not([hidden])'));
// Wait for the "Manage in Drive" menu item to appear.
chrome.test.assertTrue(!!await remoteCall.waitForElement(
appId, '[command="#manage-in-drive"]:not([hidden]):not([disabled])'));
// Click the "Manage in Drive" menu item.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['[command="#manage-in-drive"]:not([hidden]):not([disabled])'],
this.next);
},
// Wait for the context menu to disappear.
function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#file-context-menu[hidden]')
.then(this.next);
},
// Wait for the browser window to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next);
},
// Check: the browser navigated to the expected URL.
function(visitedUrl) {
chrome.test.assertEq(url, visitedUrl);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
['[command="#manage-in-drive"]:not([hidden]):not([disabled])']),
'fakeMouseClick failed');
// Wait for the context menu to disappear.
chrome.test.assertTrue(
!!await remoteCall.waitForElement(appId, '#file-context-menu[hidden]'));
// Wait for the browser window to appear and navigate to the expected URL.
chrome.test.assertEq(
url, await remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, []));
}
/**
......@@ -204,7 +135,7 @@ function manageWithDriveExpectBrowserURL(path, url, teamDrive = undefined) {
*/
testcase.shareFileDrive = function() {
const URL = 'https://file_alternate_link/world.ogv?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('world.ogv', URL);
return shareWithOthersExpectBrowserURL('world.ogv', URL);
};
/**
......@@ -212,7 +143,7 @@ testcase.shareFileDrive = function() {
*/
testcase.shareDirectoryDrive = function() {
const URL = 'https://folder_alternate_link/photos?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('photos', URL);
return shareWithOthersExpectBrowserURL('photos', URL);
};
/**
......@@ -221,7 +152,7 @@ testcase.shareDirectoryDrive = function() {
testcase.shareHostedFileDrive = function() {
const URL =
'https://document_alternate_link/Test%20Document?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('Test Document.gdoc', URL);
return shareWithOthersExpectBrowserURL('Test Document.gdoc', URL);
};
/**
......@@ -229,7 +160,7 @@ testcase.shareHostedFileDrive = function() {
*/
testcase.manageFileDrive = function() {
const URL = 'https://file_alternate_link/world.ogv';
manageWithDriveExpectBrowserURL('world.ogv', URL);
return manageWithDriveExpectBrowserURL('world.ogv', URL);
};
/**
......@@ -237,7 +168,7 @@ testcase.manageFileDrive = function() {
*/
testcase.manageDirectoryDrive = function() {
const URL = 'https://folder_alternate_link/photos';
manageWithDriveExpectBrowserURL('photos', URL);
return manageWithDriveExpectBrowserURL('photos', URL);
};
/**
......@@ -245,7 +176,7 @@ testcase.manageDirectoryDrive = function() {
*/
testcase.manageHostedFileDrive = function() {
const URL = 'https://document_alternate_link/Test%20Document';
manageWithDriveExpectBrowserURL('Test Document.gdoc', URL);
return manageWithDriveExpectBrowserURL('Test Document.gdoc', URL);
};
/**
......@@ -254,69 +185,51 @@ testcase.manageHostedFileDrive = function() {
testcase.shareFileTeamDrive = function() {
const URL =
'https://file_alternate_link/teamDriveAFile.txt?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('teamDriveAFile.txt', URL, 'Team Drive A');
return shareWithOthersExpectBrowserURL(
'teamDriveAFile.txt', URL, 'Team Drive A');
};
/**
* Tests that sharing a directory in a team drive is not allowed.
*/
testcase.shareDirectoryTeamDrive = function() {
let appId;
testcase.shareDirectoryTeamDrive = async function() {
const teamDrive = 'Team Drive A';
const path = 'teamDriveADirectory';
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
},
// Navigate to the team drive.
function(results) {
appId = results.windowId;
remoteCall
.navigateWithDirectoryTree(
appId, `/team_drives/${teamDrive}`, 'Team Drives', 'drive')
.then(this.next);
},
// Wait for the file list to update.
function() {
remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length)
.then(this.next);
},
// Select the given |path|.
function() {
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the entry to be selected.
function(result) {
chrome.test.assertTrue(!!result, 'selectFile failed');
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
},
// Right-click the selected entry.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]'], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the "Share" menu item to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForElement(appId, '[command="#share"]:not([hidden])[disabled]')
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [],
BASIC_DRIVE_ENTRY_SET.concat(TEAM_DRIVE_ENTRY_SET));
// Navigate to the team drive.
await remoteCall.navigateWithDirectoryTree(
appId, `/team_drives/${teamDrive}`, 'Team Drives', 'drive');
// Wait for the file list to update.
await remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length);
// Select the given |path|.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [path]),
'selectFile failed');
// Wait for the entry to be selected.
chrome.test.assertTrue(
!!await remoteCall.waitForElement(appId, '.table-row[selected]'));
// Right-click the selected entry.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']),
'fakeMouseClick failed');
// Wait for the context menu to appear.
chrome.test.assertTrue(!!await remoteCall.waitForElement(
appId, '#file-context-menu:not([hidden])'));
// Wait for the "Share" menu item to appear.
await remoteCall.waitForElement(
appId, '[command="#share"]:not([hidden])[disabled]');
};
/**
......@@ -325,7 +238,7 @@ testcase.shareDirectoryTeamDrive = function() {
testcase.shareHostedFileTeamDrive = function() {
const URL =
'https://document_alternate_link/teamDriveAHostedDoc?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL(
return shareWithOthersExpectBrowserURL(
'teamDriveAHostedDoc.gdoc', URL, 'Team Drive A');
};
......@@ -334,7 +247,8 @@ testcase.shareHostedFileTeamDrive = function() {
*/
testcase.manageFileTeamDrive = function() {
const URL = 'https://file_alternate_link/teamDriveAFile.txt';
manageWithDriveExpectBrowserURL('teamDriveAFile.txt', URL, 'Team Drive A');
return manageWithDriveExpectBrowserURL(
'teamDriveAFile.txt', URL, 'Team Drive A');
};
/**
......@@ -342,7 +256,8 @@ testcase.manageFileTeamDrive = function() {
*/
testcase.manageDirectoryTeamDrive = function() {
const URL = 'https://folder_alternate_link/teamDriveADirectory';
manageWithDriveExpectBrowserURL('teamDriveADirectory', URL, 'Team Drive A');
return manageWithDriveExpectBrowserURL(
'teamDriveADirectory', URL, 'Team Drive A');
};
/**
......@@ -350,7 +265,7 @@ testcase.manageDirectoryTeamDrive = function() {
*/
testcase.manageHostedFileTeamDrive = function() {
const URL = 'https://document_alternate_link/teamDriveAHostedDoc';
manageWithDriveExpectBrowserURL(
return manageWithDriveExpectBrowserURL(
'teamDriveAHostedDoc.gdoc', URL, 'Team Drive A');
};
......@@ -359,7 +274,7 @@ testcase.manageHostedFileTeamDrive = function() {
*/
testcase.manageTeamDrive = function() {
const URL = 'https://folder_alternate_link/Team%20Drive%20A';
manageWithDriveExpectBrowserURL('Team Drive A', URL, '');
return manageWithDriveExpectBrowserURL('Team Drive A', URL, '');
};
/**
......@@ -368,5 +283,5 @@ testcase.manageTeamDrive = function() {
testcase.shareTeamDrive = function() {
const URL =
'https://folder_alternate_link/Team%20Drive%20A?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('Team Drive A', URL, '');
return shareWithOthersExpectBrowserURL('Team Drive A', URL, '');
};
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