Commit 49f6f871 authored by Josh Simmons's avatar Josh Simmons Committed by Commit Bot

Refactor checks for Quick View being open into common helper

Multiple places in the code check for Quick View being open
after performing a series of actions that should open it. These
have been refactored in a single helper function.

Bug: 1058289
Change-Id: I8a55d141895395637d6679fe7ad22df3c50baf7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086469
Commit-Queue: Josh Simmons <simmonsjosh@google.com>
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746689}
parent a8bb7a70
......@@ -21,6 +21,30 @@
SELECTION_MENU: 2,
};
/**
* Waits for Quick View dialog to be open.
*
* @param {string} appId Files app windowId.
*/
async function waitQuickViewOpen(appId) {
const caller = getCaller();
function checkQuickViewElementsDisplayBlock(elements) {
const haveElements = Array.isArray(elements) && elements.length !== 0;
if (!haveElements || elements[0].styles.display !== 'block') {
return pending(caller, 'Waiting for Quick View to open.');
}
return;
}
await repeatUntil(async () => {
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
}
/**
* Waits for Quick View dialog to be closed.
*
......@@ -53,16 +77,6 @@
* @param {string} name File name.
*/
async function openQuickView(appId, name) {
const caller = getCaller();
function checkQuickViewElementsDisplayBlock(elements) {
const haveElements = Array.isArray(elements) && elements.length !== 0;
if (!haveElements || elements[0].styles.display !== 'block') {
return pending(caller, 'Waiting for Quick View to open.');
}
return;
}
// Select file |name| in the file list.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [name]),
......@@ -75,12 +89,7 @@
'fakeKeyDown failed');
// Check: the Quick View dialog should be shown.
await repeatUntil(async () => {
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
return waitQuickViewOpen(appId);
}
/**
......@@ -105,17 +114,7 @@
await remoteCall.waitAndClickElement(appId, getInfoMenuItem);
// Check: the Quick View dialog should be shown.
const caller = getCaller();
await repeatUntil(async () => {
const query = ['#quick-view', '#dialog[open]'];
const elements = await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [query, ['display']]);
const haveElements = Array.isArray(elements) && elements.length !== 0;
if (!haveElements || elements[0].styles.display !== 'block') {
return pending(caller, 'Waiting for Quick View to open.');
}
return true;
});
await waitQuickViewOpen(appId);
}
/**
......@@ -126,16 +125,6 @@
* @param {Array<string>} names File names.
*/
async function openQuickViewMultipleSelection(appId, names) {
const caller = getCaller();
function checkQuickViewElementsDisplayBlock(elements) {
const haveElements = Array.isArray(elements) && elements.length !== 0;
if (!haveElements || elements[0].styles.display !== 'block') {
return pending(caller, 'Waiting for Quick View to open.');
}
return;
}
// Get the file-list rows that are check-selected (multi-selected).
const selectedRows = await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, ['#file-list li[selected]']);
......@@ -152,12 +141,7 @@
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space);
// Check: the Quick View dialog should be shown.
await repeatUntil(async () => {
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
await waitQuickViewOpen(appId);
}
/**
......@@ -2222,25 +2206,12 @@
!!await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, ctrlA),
'Ctrl+A failed');
function checkQuickViewElementsDisplayBlock(elements) {
const haveElements = Array.isArray(elements) && elements.length !== 0;
if (!haveElements || elements[0].styles.display !== 'block') {
return pending(caller, 'Waiting for Quick View to open.');
}
return;
}
// Open Quick View via its keyboard shortcut.
const space = ['#file-list', ' ', false, false, false];
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space);
// Check: the Quick View dialog should be shown.
await repeatUntil(async () => {
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
await waitQuickViewOpen(appId);
// Press the up arrow to go to the last file in the selection.
const quickViewArrowUp = ['#quick-view', 'ArrowUp', false, false, false];
......
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