зеркало из https://github.com/mozilla/gecko-dev.git
Bug 760193 - Add console.assert; r=msucan
This commit is contained in:
Родитель
89c65d62ea
Коммит
7573898c07
|
@ -71,6 +71,7 @@ const COMPAT = {
|
|||
const CONSOLE_API_LEVELS_TO_SEVERITIES = {
|
||||
error: "error",
|
||||
exception: "error",
|
||||
assert: "error",
|
||||
warn: "warning",
|
||||
info: "info",
|
||||
log: "log",
|
||||
|
|
|
@ -60,6 +60,7 @@ support-files =
|
|||
test-bug-869003-iframe.html
|
||||
test-bug-869003-top-window.html
|
||||
test-closures.html
|
||||
test-console-assert.html
|
||||
test-console-extras.html
|
||||
test-console-replaced-api.html
|
||||
test-console.html
|
||||
|
@ -135,6 +136,7 @@ support-files =
|
|||
[browser_warn_user_about_replaced_api.js]
|
||||
[browser_webconsole_abbreviate_source_url.js]
|
||||
[browser_webconsole_allow_mixedcontent_securityerrors.js]
|
||||
[browser_webconsole_assert.js]
|
||||
[browser_webconsole_basic_net_logging.js]
|
||||
[browser_webconsole_block_mixedcontent_securityerrors.js]
|
||||
[browser_webconsole_bug_579412_input_focus.js]
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test that console.assert() works as expected (i.e. outputs only on falsy
|
||||
// asserts). See bug 760193.
|
||||
|
||||
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-assert.html";
|
||||
|
||||
function test() {
|
||||
addTab(TEST_URI);
|
||||
browser.addEventListener("load", function onLoad() {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
openConsole(null, consoleOpened);
|
||||
}, true);
|
||||
}
|
||||
|
||||
function consoleOpened(hud) {
|
||||
waitForMessages({
|
||||
webconsole: hud,
|
||||
messages: [{
|
||||
text: "start",
|
||||
category: CATEGORY_WEBDEV,
|
||||
severity: SEVERITY_LOG,
|
||||
},
|
||||
{
|
||||
text: "false assert",
|
||||
category: CATEGORY_WEBDEV,
|
||||
severity: SEVERITY_ERROR,
|
||||
},
|
||||
{
|
||||
text: "falsy assert",
|
||||
category: CATEGORY_WEBDEV,
|
||||
severity: SEVERITY_ERROR,
|
||||
},
|
||||
{
|
||||
text: "end",
|
||||
category: CATEGORY_WEBDEV,
|
||||
severity: SEVERITY_LOG,
|
||||
}],
|
||||
}).then(() => {
|
||||
let nodes = hud.outputNode.querySelectorAll(".message");
|
||||
is(nodes.length, 4, "only four messages are displayed, no output from the true assert");
|
||||
finishTest();
|
||||
});
|
||||
|
||||
let button = content.document.querySelector("button");
|
||||
ok(button, "we have the button");
|
||||
EventUtils.sendMouseEvent({ type: "click" }, button, content);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html dir="ltr" xml:lang="en-US" lang="en-US">
|
||||
<head>
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<meta charset="utf-8">
|
||||
<title>console.assert() test</title>
|
||||
<script type="text/javascript">
|
||||
function test() {
|
||||
console.log("start");
|
||||
console.assert(false, "false assert");
|
||||
console.assert(0, "falsy assert");
|
||||
console.assert(true, "true assert");
|
||||
console.log("end");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>test console.assert()</p>
|
||||
<button onclick="test();">test console.assert()</button>
|
||||
</body>
|
||||
</html>
|
|
@ -5,7 +5,6 @@
|
|||
<script type="text/javascript">
|
||||
function test() {
|
||||
console.log("start");
|
||||
console.assert()
|
||||
console.clear()
|
||||
console.dirxml()
|
||||
console.profile()
|
||||
|
|
|
@ -118,6 +118,7 @@ const MESSAGE_PREFERENCE_KEYS = [
|
|||
const LEVELS = {
|
||||
error: SEVERITY_ERROR,
|
||||
exception: SEVERITY_ERROR,
|
||||
assert: SEVERITY_ERROR,
|
||||
warn: SEVERITY_WARNING,
|
||||
info: SEVERITY_INFO,
|
||||
log: SEVERITY_LOG,
|
||||
|
@ -1171,6 +1172,7 @@ WebConsoleFrame.prototype = {
|
|||
case "warn":
|
||||
case "error":
|
||||
case "exception":
|
||||
case "assert":
|
||||
case "debug": {
|
||||
let msg = new Messages.ConsoleGeneric(aMessage);
|
||||
node = msg.init(this.output).render().element;
|
||||
|
|
|
@ -132,6 +132,12 @@ ConsoleAPI.prototype = {
|
|||
Services.obs.notifyObservers(consoleEvent, "console-api-profiler",
|
||||
null);
|
||||
},
|
||||
assert: function CA_assert() {
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
if(!args.shift()) {
|
||||
self.queueCall("assert", args);
|
||||
}
|
||||
},
|
||||
__exposedProps__: {
|
||||
log: "r",
|
||||
info: "r",
|
||||
|
@ -147,7 +153,8 @@ ConsoleAPI.prototype = {
|
|||
time: "r",
|
||||
timeEnd: "r",
|
||||
profile: "r",
|
||||
profileEnd: "r"
|
||||
profileEnd: "r",
|
||||
assert: "r"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -174,6 +181,7 @@ ConsoleAPI.prototype = {
|
|||
timeEnd: genPropDesc('timeEnd'),
|
||||
profile: genPropDesc('profile'),
|
||||
profileEnd: genPropDesc('profileEnd'),
|
||||
assert: genPropDesc('assert'),
|
||||
__noSuchMethod__: { enumerable: true, configurable: true, writable: true,
|
||||
value: function() {} },
|
||||
__mozillaConsole__: { value: true }
|
||||
|
@ -295,6 +303,7 @@ ConsoleAPI.prototype = {
|
|||
case "error":
|
||||
case "exception":
|
||||
case "debug":
|
||||
case "assert":
|
||||
consoleEvent.arguments = this.processArguments(args);
|
||||
break;
|
||||
case "trace":
|
||||
|
|
|
@ -132,7 +132,7 @@ function testConsoleGroup(aMessageObject) {
|
|||
"expected level received");
|
||||
|
||||
is(aMessageObject.functionName, "testGroups", "functionName matches");
|
||||
ok(aMessageObject.lineNumber >= 45 && aMessageObject.lineNumber <= 48,
|
||||
ok(aMessageObject.lineNumber >= 45 && aMessageObject.lineNumber <= 49,
|
||||
"lineNumber matches");
|
||||
if (aMessageObject.level == "groupCollapsed") {
|
||||
is(aMessageObject.groupName, "a group", "groupCollapsed groupName matches");
|
||||
|
@ -258,6 +258,10 @@ function observeConsoleTest() {
|
|||
win.console.log("omg %o foo %o", obj, 4, obj2);
|
||||
yield undefined;
|
||||
|
||||
expect("assert", "message");
|
||||
win.console.assert(false, "message");
|
||||
yield undefined;
|
||||
|
||||
startTraceTest();
|
||||
yield undefined;
|
||||
|
||||
|
@ -282,6 +286,7 @@ function consoleAPISanityTest() {
|
|||
ok(win.console.groupEnd, "console.groupEnd is here");
|
||||
ok(win.console.time, "console.time is here");
|
||||
ok(win.console.timeEnd, "console.timeEnd is here");
|
||||
ok(win.console.assert, "console.assert is here");
|
||||
}
|
||||
|
||||
function startTimeTest() {
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
console.warn(str);
|
||||
console.error(str);
|
||||
console.exception(str);
|
||||
console.assert(false, str);
|
||||
}
|
||||
|
||||
function testGroups() {
|
||||
|
|
|
@ -35,6 +35,7 @@ function doTest() {
|
|||
"timeEnd": "function",
|
||||
"profile": "function",
|
||||
"profileEnd": "function",
|
||||
"assert": "function",
|
||||
"__noSuchMethod__": "function"
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче