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

91 lines
2.6 KiB
HTML

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Web Console throw tests</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>Web Console throw tests</p>
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsoleToTab([], onAttach);
}
function onAttach(aState)
{
const tests = [];
const falsyValues = ["-0", "null", "undefined", "Infinity", "-Infinity", "NaN"];
falsyValues.forEach(function(value) {
tests.push(async function() {
const response = await aState.webConsoleFront.evaluateJSAsync("throw " + value + ";")
const type = response.exception.type;
is(type, value, "exception.type for throw " + value);
nextTest();
});
});
const identityTestValues = [false, 0];
identityTestValues.forEach(function(value) {
tests.push(async function() {
const response = await aState.webConsoleFront.evaluateJSAsync("throw " + value + ";")
const exception = response.exception;
is(exception, value, "response.exception for throw " + value);
nextTest();
});
});
const longString = Array(DebuggerServer.LONG_STRING_LENGTH + 1).join("a"),
shortedString = longString.substring(0,
DebuggerServer.LONG_STRING_INITIAL_LENGTH
);
tests.push(async function() {
const response = await aState.webConsoleFront.evaluateJSAsync("throw '" + longString + "';")
is(response.exception.initial, shortedString,
"exception.initial for throw longString"
);
is(response.exceptionMessage.initial, shortedString,
"exceptionMessage.initial for throw longString"
);
nextTest();
});
const symbolTestValues = [
["Symbol.iterator", "Symbol(Symbol.iterator)"],
["Symbol('foo')", "Symbol(foo)"],
["Symbol()", "Symbol()"],
];
symbolTestValues.forEach(function([expr, message]) {
tests.push(async function() {
const response = await aState.webConsoleFront.evaluateJSAsync("throw " + expr + ";");
is(response.exceptionMessage, message,
"response.exception for throw " + expr);
nextTest();
});
});
runTests(tests, endTest.bind(null, aState));
}
function endTest(aState)
{
closeDebugger(aState, function() {
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>