[e2e] Fix selection after delete

Discovered a race condition when running e2e in SLOWMO. This CL fixes
the race condition by ensuring that the old content is definitely
grabbed before the backspace key is pressed.

Change-Id: I6f39f18b8352ed03a1b6e4c067a2e526589b4ace
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2130789
Commit-Queue: Paul Lewis <aerotwist@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
This commit is contained in:
Paul Lewis
2020-04-01 11:24:59 +00:00
committed by Commit Bot
parent ca63eb417e
commit 48dc466eea
2 changed files with 6 additions and 8 deletions
+4 -5
View File
@@ -5,14 +5,14 @@
import {describe, it} from 'mocha';
import {click, getBrowserAndPages, resetPages, resourcesPath, waitFor, waitForElementWithTextContent} from '../../shared/helper.js';
import {assertContentOfSelectedElementsNode, expandSelectedNodeRecursively, waitForSelectedNodeChange} from '../helpers/elements-helpers.js';
import {assertContentOfSelectedElementsNode, expandSelectedNodeRecursively, getContentOfSelectedNode, waitForSelectedNodeChange} from '../helpers/elements-helpers.js';
describe('The Elements tab', async () => {
beforeEach(async () => {
await resetPages();
});
it('can delete stuff', async () => {
it('can delete elements in the tree', async () => {
const {target, frontend} = getBrowserAndPages();
await target.goto(`${resourcesPath}/elements/selection-after-delete.html`);
@@ -40,10 +40,9 @@ describe('The Elements tab', async () => {
do {
const nextVal = expected.shift() || '';
// Start watching for the node change before hitting backspace.
const elementChanged = waitForSelectedNodeChange();
const initialValue = await getContentOfSelectedNode();
await frontend.keyboard.press('Backspace');
await elementChanged;
await waitForSelectedNodeChange(initialValue);
await assertContentOfSelectedElementsNode(nextVal);
} while (expected.length);
+2 -3
View File
@@ -24,16 +24,15 @@ export const getContentOfSelectedNode = async () => {
return await selectedNode.evaluate(node => node.textContent);
};
export const waitForSelectedNodeChange = async (maxTotalTimeout = 1000) => {
export const waitForSelectedNodeChange = async (initialValue: string, maxTotalTimeout = 1000) => {
if (maxTotalTimeout === 0) {
maxTotalTimeout = Number.POSITIVE_INFINITY;
}
const start = performance.now();
const initialNodeContent = await getContentOfSelectedNode();
do {
const currentContent = await getContentOfSelectedNode();
if (currentContent !== initialNodeContent) {
if (currentContent !== initialValue) {
return currentContent;
}