Commit 3ff721ae authored by Alex Danilo's avatar Alex Danilo Committed by Commit Bot

Integration test for propagation of error dismiss

Test for CL:1943777 behavior.

The background page for FilesApp stores state for file operations in
progress, as well as error states. This information is propagated to
all the Files App foreground windows during their lifetime, and also
propagated to any newly created foreground windows.

The background progress center has 2 callback functions for changing
state - one for cancel of an operation in progress, the other for
dismissal of an error state.

This test triggers an error state, simulates a click on the 'dismiss'
button on the error panel that is displayed in the foreground window. It
then closes the foreground window and opens a new one to check the error
panel is not displayed. Detection of the lack of an error panel is done
by triggering a copy operation that never ends and checking for that
panel. If the error had persisted, it would be present when the copy
panel appeared.

Bug: 990919
Tests: browser_tests --gtest_filter="*transferDismissedErrorIsRemembered"
Change-Id: I38789d4e621801c8a03c9e7f606d841830332b1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1950372
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723597}
parent 2c4f8f8e
...@@ -576,7 +576,8 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -576,7 +576,8 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
TestCase("transferFromDownloadsToDownloads"), TestCase("transferFromDownloadsToDownloads"),
TestCase("transferDeletedFile"), TestCase("transferDeletedFile"),
TestCase("transferInfoIsRemembered"), TestCase("transferInfoIsRemembered"),
TestCase("transferToUsbHasDestinationText"))); TestCase("transferToUsbHasDestinationText"),
TestCase("transferDismissedErrorIsRemembered")));
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
RestorePrefs, /* restore_prefs.js */ RestorePrefs, /* restore_prefs.js */
......
...@@ -493,6 +493,7 @@ js_library("runtime_loaded_test_util") { ...@@ -493,6 +493,7 @@ js_library("runtime_loaded_test_util") {
deps = [ deps = [
":app_windows", ":app_windows",
":file_operation_util",
":test_util_base", ":test_util_base",
"//ui/file_manager/base/js:error_counter", "//ui/file_manager/base/js:error_counter",
] ]
......
...@@ -286,7 +286,7 @@ fileOperationUtil.findEntriesRecursively = (entry, onResultCallback) => { ...@@ -286,7 +286,7 @@ fileOperationUtil.findEntriesRecursively = (entry, onResultCallback) => {
}; };
/** @param {!DirectoryEntry} directory */ /** @param {!DirectoryEntry} directory */
var processDirectory = directory => { const processDirectory = directory => {
// All scanning stops when an error is encountered. // All scanning stops when an error is encountered.
if (scanError) { if (scanError) {
return; return;
...@@ -347,6 +347,12 @@ fileOperationUtil.listEntries = (directory, callback) => { ...@@ -347,6 +347,12 @@ fileOperationUtil.listEntries = (directory, callback) => {
}); });
}; };
/**
* When set, forces all file operations to complete with an error.
* @type {boolean}
*/
fileOperationUtil.forceErrorForTest = false;
/** /**
* Copies source to parent with the name newName recursively. * Copies source to parent with the name newName recursively.
* This should work very similar to FileSystem API's copyTo. The difference is; * This should work very similar to FileSystem API's copyTo. The difference is;
...@@ -396,6 +402,15 @@ fileOperationUtil.copyTo = ...@@ -396,6 +402,15 @@ fileOperationUtil.copyTo =
return; return;
} }
if (window.IN_TEST && fileOperationUtil.forceErrorForTest) {
chrome.fileManagerPrivate.onCopyProgress.removeListener(
onCopyProgress);
const forceErrorForTest = util.FileError.INVALID_STATE_ERR;
errorCallback(util.createDOMError(forceErrorForTest));
callback();
return;
}
switch (status.type) { switch (status.type) {
case 'begin_copy_entry': case 'begin_copy_entry':
callback(); callback();
...@@ -1307,21 +1322,21 @@ fileOperationUtil.EventRouter = class extends cr.EventTarget { ...@@ -1307,21 +1322,21 @@ fileOperationUtil.EventRouter = class extends cr.EventTarget {
dispatchEntryChangedEvent_() { dispatchEntryChangedEvent_() {
const deletedEntries = []; const deletedEntries = [];
const createdEntries = []; const createdEntries = [];
for (var url in this.pendingDeletedEntries_) { for (const url in this.pendingDeletedEntries_) {
deletedEntries.push(this.pendingDeletedEntries_[url]); deletedEntries.push(this.pendingDeletedEntries_[url]);
} }
for (var url in this.pendingCreatedEntries_) { for (const url in this.pendingCreatedEntries_) {
createdEntries.push(this.pendingCreatedEntries_[url]); createdEntries.push(this.pendingCreatedEntries_[url]);
} }
if (deletedEntries.length > 0) { if (deletedEntries.length > 0) {
var event = new Event('entries-changed'); const event = new Event('entries-changed');
event.kind = util.EntryChangedKind.DELETED; event.kind = util.EntryChangedKind.DELETED;
event.entries = deletedEntries; event.entries = deletedEntries;
this.dispatchEvent(event); this.dispatchEvent(event);
this.pendingDeletedEntries_ = {}; this.pendingDeletedEntries_ = {};
} }
if (createdEntries.length > 0) { if (createdEntries.length > 0) {
var event = new Event('entries-changed'); const event = new Event('entries-changed');
event.kind = util.EntryChangedKind.CREATED; event.kind = util.EntryChangedKind.CREATED;
event.entries = createdEntries; event.entries = createdEntries;
this.dispatchEvent(event); this.dispatchEvent(event);
......
...@@ -988,6 +988,15 @@ test.util.async.getVolumesCount = callback => { ...@@ -988,6 +988,15 @@ test.util.async.getVolumesCount = callback => {
}); });
}; };
/**
* Sets/Resets a flag that causes file copy operations to always fail in test.
* @param {boolean} enable True to force errors.
*/
test.util.sync.forceErrorsOnFileOperations = (contentWindow, enable) => {
fileOperationUtil.forceErrorForTest = enable;
return enable;
};
/** /**
* Updates the preferences. * Updates the preferences.
* @param {chrome.fileManagerPrivate.PreferencesChange} preferences Preferences * @param {chrome.fileManagerPrivate.PreferencesChange} preferences Preferences
......
...@@ -171,7 +171,7 @@ async function transferBetweenVolumes(transferInfo) { ...@@ -171,7 +171,7 @@ async function transferBetweenVolumes(transferInfo) {
'selectFile', appId, [transferInfo.fileToTransfer.nameText])); 'selectFile', appId, [transferInfo.fileToTransfer.nameText]));
// Copy the file. // Copy the file.
let transferCommand = transferInfo.isMove ? 'cut' : 'copy'; const transferCommand = transferInfo.isMove ? 'cut' : 'copy';
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'execCommand', appId, [transferCommand])); 'execCommand', appId, [transferCommand]));
...@@ -663,7 +663,7 @@ testcase.transferToUsbHasDestinationText = async () => { ...@@ -663,7 +663,7 @@ testcase.transferToUsbHasDestinationText = async () => {
const entry = ENTRIES.hello; const entry = ENTRIES.hello;
// Open files app. // Open files app.
let appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS, [entry], []); const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS, [entry], []);
// Mount a USB volume. // Mount a USB volume.
await sendTestMessage({name: 'mountFakeUsbEmpty'}); await sendTestMessage({name: 'mountFakeUsbEmpty'});
...@@ -696,3 +696,71 @@ testcase.transferToUsbHasDestinationText = async () => { ...@@ -696,3 +696,71 @@ testcase.transferToUsbHasDestinationText = async () => {
appId, ['#progress-panel', 'xf-panel-item']); appId, ['#progress-panel', 'xf-panel-item']);
chrome.test.assertEq('To fake-usb', panel.attributes['secondary-text']); chrome.test.assertEq('To fake-usb', panel.attributes['secondary-text']);
}; };
/**
* Tests that dismissing an error notification on the foreground
* page is propagated to the background page.
*/
testcase.transferDismissedErrorIsRemembered = async () => {
const DOWNLOADS_QUERY = '#directory-tree [entry-label="Downloads"]';
const entry = ENTRIES.hello;
// Open Files app on Drive.
let appId =
await setupAndWaitUntilReady(RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET);
// Select a file to copy.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [entry.nameText]));
// Copy the file.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('execCommand', appId, ['copy']));
// Force all file copy operations to trigger an error.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'forceErrorsOnFileOperations', appId, [true]));
// Select Downloads.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectInDirectoryTree', appId, [DOWNLOADS_QUERY]));
// Paste the file to begin a copy operation.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('execCommand', appId, ['paste']));
// Check: an error feedback panel with failure status should appear.
const errorPanel = await remoteCall.waitForElement(
appId, ['#progress-panel', 'xf-panel-item']);
chrome.test.assertEq('failure', errorPanel.attributes['status']);
// Press the dismiss button on the error feedback panel.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
[['#progress-panel', 'xf-panel-item', 'xf-button#secondary-action']]));
// Close the Files app window.
await remoteCall.closeWindowAndWait(appId);
// Open a Files app window again.
appId =
await setupAndWaitUntilReady(RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET);
// Turn off the error generation for file operations.
chrome.test.assertFalse(await remoteCall.callRemoteTestUtil(
'forceErrorsOnFileOperations', appId, [false]));
// Tell the background page to never finish the file copy.
await remoteCall.callRemoteTestUtil(
'progressCenterNeverNotifyCompleted', appId, []);
// Paste the file to begin a copy operation.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('execCommand', appId, ['paste']));
// Check: the first feedback panel item should be a progress panel.
// If the error persisted then we'd see a summary panel here.
const progressPanel = await remoteCall.waitForElement(
appId, ['#progress-panel', 'xf-panel-item']);
chrome.test.assertEq('progress', progressPanel.attributes['indicator']);
};
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