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