gecko-dev/toolkit/devtools/webconsole/test/test_page_errors.html

98 lines
2.4 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for page errors</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript;version=1.8" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for page errors</p>
<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
let expectedPageErrors = [];
function doPageErrors()
{
expectedPageErrors = [
{
errorMessage: /fooColor/,
sourceName: /test_page_errors/,
category: "CSS Parser",
timeStamp: /^\d+$/,
error: false,
warning: true,
exception: false,
strict: false,
},
{
errorMessage: /doTheImpossible/,
sourceName: /test_page_errors/,
category: "chrome javascript",
timeStamp: /^\d+$/,
error: false,
warning: false,
exception: true,
strict: false,
},
];
let container = document.createElement("script");
document.body.appendChild(container);
container.textContent = "document.body.style.color = 'fooColor';";
document.body.removeChild(container);
SimpleTest.expectUncaughtException();
container = document.createElement("script");
document.body.appendChild(container);
container.textContent = "document.doTheImpossible();";
document.body.removeChild(container);
}
function startTest()
{
removeEventListener("load", startTest);
attachConsole(["PageError"], onAttach);
}
function onAttach(aState, aResponse)
{
onPageError = onPageError.bind(null, aState);
aState.dbgClient.addListener("pageError", onPageError);
doPageErrors();
}
let pageErrors = [];
function onPageError(aState, aType, aPacket)
{
is(aPacket.from, aState.actor, "page error actor");
pageErrors.push(aPacket.pageError);
if (pageErrors.length != expectedPageErrors.length) {
return;
}
aState.dbgClient.removeListener("pageError", onPageError);
expectedPageErrors.forEach(function(aMessage, aIndex) {
info("checking received page error #" + aIndex);
checkObject(pageErrors[aIndex], expectedPageErrors[aIndex]);
});
closeDebugger(aState, function() {
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>