mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
test: add a test for eval followed by a mouse event (#11506)
This commit is contained in:
parent
1457d4b169
commit
04b879944a
@ -176,11 +176,13 @@ export class BidiRealm extends EventEmitter<Record<EventType, any>> {
|
|||||||
: `${functionDeclaration}\n${sourceUrlComment}\n`;
|
: `${functionDeclaration}\n${sourceUrlComment}\n`;
|
||||||
responsePromise = this.connection.send('script.callFunction', {
|
responsePromise = this.connection.send('script.callFunction', {
|
||||||
functionDeclaration,
|
functionDeclaration,
|
||||||
arguments: await Promise.all(
|
arguments: args.length
|
||||||
|
? await Promise.all(
|
||||||
args.map(arg => {
|
args.map(arg => {
|
||||||
return BidiSerializer.serialize(sandbox, arg);
|
return BidiSerializer.serialize(sandbox, arg);
|
||||||
})
|
})
|
||||||
),
|
)
|
||||||
|
: [],
|
||||||
target: this.target,
|
target: this.target,
|
||||||
resultOwnership,
|
resultOwnership,
|
||||||
awaitPromise: true,
|
awaitPromise: true,
|
||||||
|
@ -293,7 +293,9 @@ export class ExecutionContext {
|
|||||||
callFunctionOnPromise = this._client.send('Runtime.callFunctionOn', {
|
callFunctionOnPromise = this._client.send('Runtime.callFunctionOn', {
|
||||||
functionDeclaration: functionDeclarationWithSourceUrl,
|
functionDeclaration: functionDeclarationWithSourceUrl,
|
||||||
executionContextId: this._contextId,
|
executionContextId: this._contextId,
|
||||||
arguments: await Promise.all(args.map(convertArgument.bind(this))),
|
arguments: args.length
|
||||||
|
? await Promise.all(args.map(convertArgument.bind(this)))
|
||||||
|
: [],
|
||||||
returnByValue,
|
returnByValue,
|
||||||
awaitPromise: true,
|
awaitPromise: true,
|
||||||
userGesture: true,
|
userGesture: true,
|
||||||
|
@ -31,7 +31,7 @@ import {disposeSymbol} from '../util/disposable.js';
|
|||||||
import {Mutex} from '../util/Mutex.js';
|
import {Mutex} from '../util/Mutex.js';
|
||||||
|
|
||||||
import type {Binding} from './Binding.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 {CdpFrame} from './Frame.js';
|
||||||
import type {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
|
import type {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
|
||||||
import type {WebWorker} from './WebWorker.js';
|
import type {WebWorker} from './WebWorker.js';
|
||||||
@ -147,7 +147,10 @@ export class IsolatedWorld extends Realm {
|
|||||||
this.evaluate.name,
|
this.evaluate.name,
|
||||||
pageFunction
|
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);
|
return await context.evaluate(pageFunction, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2873,6 +2873,12 @@
|
|||||||
"parameters": ["chrome", "webDriverBiDi"],
|
"parameters": ["chrome", "webDriverBiDi"],
|
||||||
"expectations": ["PASS"]
|
"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",
|
"testIdPattern": "[page.spec] Page Page.close should run beforeunload if asked for",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
@ -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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user