Commit 92ad5f16 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Prevent copy, cut and paste when a dialog is displayed.

Bug: 731021
Change-Id: I3a894b0c8e225ed031537a908cdc5a914293b4b7
Reviewed-on: https://chromium-review.googlesource.com/c/1345679
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610312}
parent 3af9e36a
...@@ -318,6 +318,7 @@ WRAPPED_INSTANTIATE_TEST_CASE_P( ...@@ -318,6 +318,7 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestCase("keyboardCopyDrive").DisableDriveFs(), TestCase("keyboardCopyDrive").DisableDriveFs(),
TestCase("keyboardCopyDrive").EnableDriveFs(), TestCase("keyboardCopyDrive").EnableDriveFs(),
TestCase("keyboardSelectDriveDirectoryTree"), TestCase("keyboardSelectDriveDirectoryTree"),
TestCase("keyboardDisableCopyWhenDialogDisplayed"),
TestCase("renameFileDownloads").InGuestMode(), TestCase("renameFileDownloads").InGuestMode(),
TestCase("renameFileDownloads"), TestCase("renameFileDownloads"),
TestCase("renameFileDrive").DisableDriveFs(), TestCase("renameFileDrive").DisableDriveFs(),
......
...@@ -1306,6 +1306,19 @@ FileTransferController.prototype.isDocumentWideEvent_ = function() { ...@@ -1306,6 +1306,19 @@ FileTransferController.prototype.isDocumentWideEvent_ = function() {
this.document_.activeElement.type.toLowerCase() !== 'text'; this.document_.activeElement.type.toLowerCase() !== 'text';
}; };
/**
* @return {boolean} Returns true if there is a dialog showing that we should
* treat as modal, false otherwise.
* @private
*/
FileTransferController.prototype.isModalDialogBeingDisplayed_ = function() {
// Do not allow Cut or Copy if a modal dialog is being displayed.
if (document.querySelector('.cr-dialog-container.shown') !== null) {
return true;
}
return false;
};
/** /**
* @param {boolean} isMove True for move operation. * @param {boolean} isMove True for move operation.
* @param {!Event} event * @param {!Event} event
...@@ -1416,6 +1429,10 @@ FileTransferController.prototype.canCutOrCopy_ = function(isMove) { ...@@ -1416,6 +1429,10 @@ FileTransferController.prototype.canCutOrCopy_ = function(isMove) {
metadata[0].canDelete !== false; metadata[0].canDelete !== false;
} }
if (this.isModalDialogBeingDisplayed_()) {
return false;
}
return isMove ? this.canCutOrDrag_() : this.canCopyOrDrag_() ; return isMove ? this.canCutOrDrag_() : this.canCopyOrDrag_() ;
}; };
......
...@@ -411,3 +411,72 @@ testcase.keyboardSelectDriveDirectoryTree = function() { ...@@ -411,3 +411,72 @@ testcase.keyboardSelectDriveDirectoryTree = function() {
}, },
]); ]);
}; };
/**
* Tests that while the delete dialog is displayed, it is not possible to press
* CONTROL-C to copy a file.
*/
testcase.keyboardDisableCopyWhenDialogDisplayed = function() {
let appId = null;
StepsRunner.run([
// Open Files app.
function() {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.hello], []);
},
// Select a file for deletion.
function(result) {
appId = result.windowId;
remoteCall.callRemoteTestUtil(
'selectFile', appId, ['hello.txt'], 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);
},
// Start delete to bring up the delete dialog.
function(result) {
// Click delete button in the toolbar.
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['button#delete-button'], this.next);
},
// Confirm that the delete confirmation dialog is shown.
function(result) {
remoteCall.waitForElement(appId, '.cr-dialog-container.shown')
.then(this.next);
},
// Try to copy file. We need to use execCommand as the command handler that
// interprets key strokes will drop events if there is a dialog on screen.
function() {
remoteCall.callRemoteTestUtil('execCommand', appId, ['copy'], this.next);
},
// Press Cancel button to stop the delete operation.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['button.cr-dialog-cancel'], this.next);
},
// Wait for dialog to disappear.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElementLost(appId, '.cr-dialog-container.shown')
.then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
const key = ['#file-list', 'v', true, false, false];
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next);
},
// Check no files were pasted.
function(result) {
chrome.test.assertTrue(result);
const files = TestEntryInfo.getExpectedRows([ENTRIES.hello]);
remoteCall.waitForFiles(appId, files).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
};
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