diff options
Diffstat (limited to 'devtools/shared/webconsole/test/chrome/test_throw.html')
-rw-r--r-- | devtools/shared/webconsole/test/chrome/test_throw.html | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/devtools/shared/webconsole/test/chrome/test_throw.html b/devtools/shared/webconsole/test/chrome/test_throw.html new file mode 100644 index 0000000000..123519174a --- /dev/null +++ b/devtools/shared/webconsole/test/chrome/test_throw.html @@ -0,0 +1,92 @@ +<!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(); + +async function startTest() +{ + removeEventListener("load", startTest); + const {state} = await attachConsoleToTab([]); + onAttach(state); +} + +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(DevToolsServer.LONG_STRING_LENGTH + 1).join("a"), + shortedString = longString.substring(0, + DevToolsServer.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> |