Bug 1679887 - [cdp] Emit past console messages on Runtime.enable r=jdescottes

Emit past console messages with Runtime.consoleAPICalled as
Runtime.enable is ran. Also added new test.

Depends on D170131

Differential Revision: https://phabricator.services.mozilla.com/D170136
This commit is contained in:
CanadaHonk 2023-03-16 20:25:31 +00:00
Родитель 366960831d
Коммит 3dc5d98c1a
4 изменённых файлов: 50 добавлений и 1 удалений

Просмотреть файл

@ -115,6 +115,10 @@ export class Runtime extends ContentProcessDomain {
window: this.content,
isDefault: true,
});
for (const message of lazy.ConsoleAPIStorage.getEvents()) {
this.onConsoleLogEvent(message);
}
});
}
}

Просмотреть файл

@ -11,6 +11,7 @@ support-files =
!/remote/cdp/test/browser/chrome-remote-interface.js
!/remote/cdp/test/browser/head.js
doc_console_events.html
doc_console_events_onload.html
doc_empty.html
doc_frame.html
doc_frameset_single.html

Просмотреть файл

@ -5,6 +5,8 @@
const PAGE_CONSOLE_EVENTS =
"https://example.com/browser/remote/cdp/test/browser/runtime/doc_console_events.html";
const PAGE_CONSOLE_EVENTS_ONLOAD =
"https://example.com/browser/remote/cdp/test/browser/runtime/doc_console_events_onload.html";
add_task(async function noEventsWhenRuntimeDomainDisabled({ client }) {
await runConsoleTest(client, 0, async () => {
@ -52,6 +54,34 @@ add_task(async function consoleAPI({ client }) {
);
});
add_task(async function consoleAPIBeforeEnable({ client }) {
const { Runtime } = client;
const timeBefore = Date.now();
const check = async () => {
const events = await runConsoleTest(
client,
1,
async () => {
await Runtime.enable();
},
// Set custom before timestamp as the event is before our callback
{ timeBefore }
);
is(events[0].type, "log", "Got expected type");
is(events[0].args[0].value, "foo", "Got expected argument value");
};
// Load the page which runs a log on load
await loadURL(PAGE_CONSOLE_EVENTS_ONLOAD);
await check();
// Disable and re-enable Runtime domain, should send event again
await Runtime.disable();
await check();
});
add_task(async function consoleAPITypes({ client }) {
const expectedEvents = ["dir", "error", "log", "timeEnd", "trace", "warning"];
const levels = ["dir", "error", "log", "time", "timeEnd", "trace", "warn"];
@ -303,6 +333,8 @@ add_task(async function consoleAPIByScriptSubstack({ client }) {
});
async function runConsoleTest(client, eventCount, callback, options = {}) {
let { timeBefore } = options;
const { Runtime } = client;
const EVENT_CONSOLE_API_CALLED = "Runtime.consoleAPICalled";
@ -315,7 +347,7 @@ async function runConsoleTest(client, eventCount, callback, options = {}) {
`Received ${EVENT_CONSOLE_API_CALLED} for ${payload.type}`,
});
const timeBefore = Date.now();
timeBefore ??= Date.now();
await callback();
const consoleAPIentries = await history.record();

Просмотреть файл

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Console events onload</title>
<script>
console.log("foo");
</script>
</head>
<body>
</body>
</html>