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 @@ ...@@ -21,6 +21,30 @@
SELECTION_MENU: 2, 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. * Waits for Quick View dialog to be closed.
* *
...@@ -53,16 +77,6 @@ ...@@ -53,16 +77,6 @@
* @param {string} name File name. * @param {string} name File name.
*/ */
async function openQuickView(appId, 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. // Select file |name| in the file list.
chrome.test.assertTrue( chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [name]), !!await remoteCall.callRemoteTestUtil('selectFile', appId, [name]),
...@@ -75,12 +89,7 @@ ...@@ -75,12 +89,7 @@
'fakeKeyDown failed'); 'fakeKeyDown failed');
// Check: the Quick View dialog should be shown. // Check: the Quick View dialog should be shown.
await repeatUntil(async () => { return waitQuickViewOpen(appId);
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
} }
/** /**
...@@ -105,17 +114,7 @@ ...@@ -105,17 +114,7 @@
await remoteCall.waitAndClickElement(appId, getInfoMenuItem); await remoteCall.waitAndClickElement(appId, getInfoMenuItem);
// Check: the Quick View dialog should be shown. // Check: the Quick View dialog should be shown.
const caller = getCaller(); await waitQuickViewOpen(appId);
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;
});
} }
/** /**
...@@ -126,16 +125,6 @@ ...@@ -126,16 +125,6 @@
* @param {Array<string>} names File names. * @param {Array<string>} names File names.
*/ */
async function openQuickViewMultipleSelection(appId, 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). // Get the file-list rows that are check-selected (multi-selected).
const selectedRows = await remoteCall.callRemoteTestUtil( const selectedRows = await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, ['#file-list li[selected]']); 'deepQueryAllElements', appId, ['#file-list li[selected]']);
...@@ -152,12 +141,7 @@ ...@@ -152,12 +141,7 @@
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space);
// Check: the Quick View dialog should be shown. // Check: the Quick View dialog should be shown.
await repeatUntil(async () => { await waitQuickViewOpen(appId);
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
} }
/** /**
...@@ -2222,25 +2206,12 @@ ...@@ -2222,25 +2206,12 @@
!!await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, ctrlA), !!await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, ctrlA),
'Ctrl+A failed'); '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. // Open Quick View via its keyboard shortcut.
const space = ['#file-list', ' ', false, false, false]; const space = ['#file-list', ' ', false, false, false];
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, space);
// Check: the Quick View dialog should be shown. // Check: the Quick View dialog should be shown.
await repeatUntil(async () => { await waitQuickViewOpen(appId);
const elements = ['#quick-view', '#dialog[open]'];
return checkQuickViewElementsDisplayBlock(
await remoteCall.callRemoteTestUtil(
'deepQueryAllElements', appId, [elements, ['display']]));
});
// Press the up arrow to go to the last file in the selection. // Press the up arrow to go to the last file in the selection.
const quickViewArrowUp = ['#quick-view', 'ArrowUp', false, false, false]; 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