Commit 62b37c19 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Cleanup share_and_manage_dialog.js integration test

- document the test helpers and their test steps.
- change share() and manage(): use more specific names.
- in the share test: wait for the file/directory entry to
  be selected before proceeding to the next step.
- in the share test: wait for share menu to close before
  trying to get the browser URL to avoid flakes.

Bug: 903587
Change-Id: I666b6c828e348a41b6053b54b6094d04fb3b9def
Reviewed-on: https://chromium-review.googlesource.com/c/1328082Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606704}
parent 6994b656
...@@ -5,25 +5,32 @@ ...@@ -5,25 +5,32 @@
'use strict'; 'use strict';
/** /**
* Test sharing dialog for a file or directory on Drive * Test 'Share with others' for a file or directory on Drive.
* @param {string} path Path for a file or a directory to be shared. *
* @param {!string} path Path of the file or directory to be shared.
* @param {!string} url Expected URL for the browser to visit.
*/ */
function share(path, expected_share_url) { function shareWithOthersExpectBrowserURL(path, url) {
var appId; let appId;
var caller = getCaller();
StepsRunner.run([ StepsRunner.run([
// Set up File Manager. // Open Files app on Drive.
function() { function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next); setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], BASIC_DRIVE_ENTRY_SET);
}, },
// Select the source file. // Select the given |path|.
function(results) { function(results) {
appId = results.windowId; appId = results.windowId;
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next); remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
}, },
// Wait for the share button. // Wait for the entry to be selected.
function(result) { function(result) {
chrome.test.assertTrue(!!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])') remoteCall.waitForElement(appId, '#share-menu-button:not([disabled])')
.then(this.next); .then(this.next);
}, },
...@@ -40,51 +47,60 @@ function share(path, expected_share_url) { ...@@ -40,51 +47,60 @@ function share(path, expected_share_url) {
'#share-menu:not([hidden]) [command="#share"]:not([disabled])'; '#share-menu:not([hidden]) [command="#share"]:not([disabled])';
remoteCall.waitForElement(appId, shareMenuItem).then(this.next); remoteCall.waitForElement(appId, shareMenuItem).then(this.next);
}, },
// Click the "Share with others" menu item to open the share dialog. // Click the "Share with others" menu item.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
const item = ['#share-menu [command="#share"]']; const shareWithOthers = '#share-menu [command="#share"]:not([disabled])';
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, item, this.next); 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. // Wait for the browser window to appear.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next); remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next);
}, },
// Check we went to the correct URL, and for Javascript errors. // Check: the browser navigated to the expected URL.
function(visitedUrl) { function(visitedUrl) {
chrome.test.assertEq(expected_share_url, visitedUrl); chrome.test.assertEq(url, visitedUrl);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next); checkIfNoErrorsOccured(this.next);
} }
]); ]);
} }
/** /**
* Test clicking 'Manage in Drive' for a file or directory on Drive. * Test 'Manage in Drive' for a file or directory on Drive.
* *
* @param {!string} path Path for a file or a directory to be shared. * @param {!string} path Path of the file or directory to be managed.
* @param {!string} expected_manage_url Expected URL for the browser to visit. * @param {!string} url Expected URL for the browser to visit.
*/ */
function manage(path, expected_manage_url) { function manageWithDriveExpectBrowserURL(path, url) {
var appId; let appId;
var caller = getCaller();
StepsRunner.run([ StepsRunner.run([
// Set up File Manager. // Open Files app on Drive.
function() { function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next); setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], BASIC_DRIVE_ENTRY_SET);
}, },
// Select the source file. // Select the given |path|.
function(results) { function(results) {
appId = results.windowId; appId = results.windowId;
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next); remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
}, },
// Wait for the file to be selected. // Wait for the entry to be selected.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result, 'selectFile failed');
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next); remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
}, },
// Right-click on the file. // Right-click the selected entry.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil( remoteCall.callRemoteTestUtil(
...@@ -92,11 +108,11 @@ function manage(path, expected_manage_url) { ...@@ -92,11 +108,11 @@ function manage(path, expected_manage_url) {
}, },
// Wait for the context menu to appear. // Wait for the context menu to appear.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])') remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next); .then(this.next);
}, },
// Wait for the "Manage in Drive" option to appear. // Wait for the "Manage in Drive" menu item to appear.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
remoteCall remoteCall
...@@ -105,7 +121,7 @@ function manage(path, expected_manage_url) { ...@@ -105,7 +121,7 @@ function manage(path, expected_manage_url) {
'[command="#manage-in-drive"]:not([hidden]):not([disabled])') '[command="#manage-in-drive"]:not([hidden]):not([disabled])')
.then(this.next); .then(this.next);
}, },
// Select "Manage in Drive". // Click the "Manage in Drive" menu item.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil( remoteCall.callRemoteTestUtil(
...@@ -115,7 +131,7 @@ function manage(path, expected_manage_url) { ...@@ -115,7 +131,7 @@ function manage(path, expected_manage_url) {
}, },
// Wait for the context menu to disappear. // Wait for the context menu to disappear.
function(result) { function(result) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result, 'fakeMouseClick failed');
remoteCall.waitForElement(appId, '#file-context-menu[hidden]') remoteCall.waitForElement(appId, '#file-context-menu[hidden]')
.then(this.next); .then(this.next);
}, },
...@@ -124,9 +140,12 @@ function manage(path, expected_manage_url) { ...@@ -124,9 +140,12 @@ function manage(path, expected_manage_url) {
chrome.test.assertTrue(!!result); chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next); remoteCall.callRemoteTestUtil('getLastVisitedURL', appId, [], this.next);
}, },
// Check we went to the correct URL, and for Javascript errors. // Check: the browser navigated to the expected URL.
function(visitedUrl) { function(visitedUrl) {
chrome.test.assertEq(expected_manage_url, visitedUrl); chrome.test.assertEq(url, visitedUrl);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next); checkIfNoErrorsOccured(this.next);
} }
]); ]);
...@@ -136,38 +155,40 @@ function manage(path, expected_manage_url) { ...@@ -136,38 +155,40 @@ function manage(path, expected_manage_url) {
* Tests sharing a file on Drive. * Tests sharing a file on Drive.
*/ */
testcase.shareFileDrive = function() { testcase.shareFileDrive = function() {
share( const URL = 'https://file_alternate_link/world.ogv?userstoinvite=%22%22';
'world.ogv', shareWithOthersExpectBrowserURL('world.ogv', URL);
'https://file_alternate_link/world.ogv?userstoinvite=%22%22');
}; };
/** /**
* Tests sharing a directory on Drive. * Tests sharing a directory on Drive.
*/ */
testcase.shareDirectoryDrive = function() { testcase.shareDirectoryDrive = function() {
share('photos', 'https://folder_alternate_link/photos?userstoinvite=%22%22'); const URL = 'https://folder_alternate_link/photos?userstoinvite=%22%22';
shareWithOthersExpectBrowserURL('photos', URL);
}; };
// TODO(sashab): Add tests for sharing a file on Team Drives. // TODO(sashab): Add tests for sharing a file on Team Drives.
/** /**
* Tests managing a hosted file (gdoc) on Drive. * Tests managing a file on Drive.
*/ */
testcase.manageHostedFileDrive = function() { testcase.manageFileDrive = function() {
manage( const URL = 'https://file_alternate_link/world.ogv';
'Test Document.gdoc', 'https://document_alternate_link/Test%20Document'); manageWithDriveExpectBrowserURL('world.ogv', URL);
}; };
/** /**
* Tests managing a hosted file on Drive. * Tests managing a directory on Drive.
*/ */
testcase.manageFileDrive = function() { testcase.manageDirectoryDrive = function() {
manage('world.ogv', 'https://file_alternate_link/world.ogv'); const URL = 'https://folder_alternate_link/photos';
manageWithDriveExpectBrowserURL('photos', URL);
}; };
/** /**
* Tests managing a directory on Drive. * Tests managing a hosted file (gdoc) on Drive.
*/ */
testcase.manageDirectoryDrive = function() { testcase.manageHostedFileDrive = function() {
manage('photos', 'https://folder_alternate_link/photos'); const URL = 'https://document_alternate_link/Test%20Document';
manageWithDriveExpectBrowserURL('Test Document.gdoc', 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