test: add a test for eval followed by a mouse event (#11506)

This commit is contained in:
Alex Rudenko 2023-12-08 10:38:49 +01:00 committed by GitHub
parent 1457d4b169
commit 04b879944a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 8 deletions

View File

@ -176,11 +176,13 @@ export class BidiRealm extends EventEmitter<Record<EventType, any>> {
: `${functionDeclaration}\n${sourceUrlComment}\n`;
responsePromise = this.connection.send('script.callFunction', {
functionDeclaration,
arguments: await Promise.all(
args.map(arg => {
return BidiSerializer.serialize(sandbox, arg);
})
),
arguments: args.length
? await Promise.all(
args.map(arg => {
return BidiSerializer.serialize(sandbox, arg);
})
)
: [],
target: this.target,
resultOwnership,
awaitPromise: true,

View File

@ -293,7 +293,9 @@ export class ExecutionContext {
callFunctionOnPromise = this._client.send('Runtime.callFunctionOn', {
functionDeclaration: functionDeclarationWithSourceUrl,
executionContextId: this._contextId,
arguments: await Promise.all(args.map(convertArgument.bind(this))),
arguments: args.length
? await Promise.all(args.map(convertArgument.bind(this)))
: [],
returnByValue,
awaitPromise: true,
userGesture: true,

View File

@ -31,7 +31,7 @@ import {disposeSymbol} from '../util/disposable.js';
import {Mutex} from '../util/Mutex.js';
import type {Binding} from './Binding.js';
import {type ExecutionContext, createCdpHandle} from './ExecutionContext.js';
import {ExecutionContext, createCdpHandle} from './ExecutionContext.js';
import type {CdpFrame} from './Frame.js';
import type {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
import type {WebWorker} from './WebWorker.js';
@ -147,7 +147,10 @@ export class IsolatedWorld extends Realm {
this.evaluate.name,
pageFunction
);
const context = await this.#executionContext();
let context = this.#context.value();
if (!context || !(context instanceof ExecutionContext)) {
context = await this.#executionContext();
}
return await context.evaluate(pageFunction, ...args);
}

View File

@ -2873,6 +2873,12 @@
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.close should reject all promises when page is closed",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[page.spec] Page Page.close should run beforeunload if asked for",
"platforms": ["darwin", "linux", "win32"],

View File

@ -458,4 +458,25 @@ describe('Mouse', function () {
},
]);
});
it('should evaluate before mouse event', async () => {
const {page, server} = await getTestState();
await page.goto(server.EMPTY_PAGE);
await page.goto(server.CROSS_PROCESS_PREFIX + '/input/button.html');
using button = await page.waitForSelector('button');
const point = await button!.clickablePoint();
const result = page.evaluate(() => {
return new Promise(resolve => {
document
.querySelector('button')
?.addEventListener('click', resolve, {once: true});
});
});
await page.mouse.click(point?.x, point?.y);
await result;
});
});