fune/devtools/shared/webconsole/test/test_console_worker.html

83 lines
2.2 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the Console API and Workers</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for the Console API and Workers</p>
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
const expectedCachedConsoleCalls = [
{
level: "log",
filename: /console-test-worker/,
arguments: ['Log from worker init'],
},
];
const expectedConsoleAPICalls = [
{
level: "log",
arguments: ['Log was requested from worker'],
},
];
window.onload = async function () {
const {state} = await new Promise(resolve => {
attachConsoleToWorker(["ConsoleAPI"], (s) => {
resolve({state: s})
});
});
await testCachedMessages(state);
await testConsoleAPI(state);
closeDebugger(state, function() {
SimpleTest.finish();
});
};
const testCachedMessages = async function (state) {
info("testCachedMessages entered");
return new Promise(resolve => {
const onCachedConsoleAPI = (response) => {
const consoleCalls = response.messages;
info('Received cached response. Checking console calls.');
checkConsoleAPICalls(consoleCalls, expectedCachedConsoleCalls);
resolve();
};
state.webConsoleFront.getCachedMessages(["ConsoleAPI"]).then(onCachedConsoleAPI);
})
};
const testConsoleAPI = async function (state) {
info("testConsoleAPI entered");
return new Promise(resolve => {
const onConsoleAPICall = (packet) => {
info("received message level: " + packet.message.level);
checkConsoleAPICalls([packet.message], expectedConsoleAPICalls);
state.webConsoleFront.off("consoleAPICall", onConsoleAPICall);
resolve();
}
info("testConsoleAPI: adding listener for consoleAPICall");
state.webConsoleFront.on("consoleAPICall", onConsoleAPICall);
state.webConsoleFront.evaluateJSAsync("console.log('Log was requested from worker')",
() => { });
});
};
</script>
</body>
</html>