Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: dom/console/tests/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
add_task(async function test_shouldLog_maxLogLevel() {
let ci = console.createInstance({ maxLogLevel: "Warn" });
Assert.ok(
ci.shouldLog("Error"),
"Should return true for logging a higher level"
);
Assert.ok(
ci.shouldLog("Warn"),
"Should return true for logging the same level"
);
Assert.ok(
!ci.shouldLog("Debug"),
"Should return false for logging a lower level;"
);
});
add_task(async function test_shouldLog_maxLogLevelPref() {
Services.prefs.setStringPref("test.log", "Warn");
let ci = console.createInstance({ maxLogLevelPref: "test.log" });
Assert.ok(
!ci.shouldLog("Debug"),
"Should return false for logging a lower level;"
);
Services.prefs.setStringPref("test.log", "Debug");
Assert.ok(
ci.shouldLog("Debug"),
"Should return true for logging a lower level after pref update"
);
});
add_task(async function test_shouldLog_env() {
//
// +---------+------------------+-----------------+
// | Numeric | NSPR Logging | Mozilla Logging |
// +---------+------------------+-----------------+
// | 0 | PR_LOG_NONE | Disabled |
// | 1 | PR_LOG_ALWAYS | Error |
// | 2 | PR_LOG_ERROR | Warning |
// | 3 | PR_LOG_WARNING | Info |
// | 4 | PR_LOG_DEBUG | Debug |
// | 5 | PR_LOG_DEBUG + 1 | Verbose |
// +---------+------------------+-----------------+
const tests = [
{
mozLogLevel: 0,
maxLogLevel: "Off",
shouldLog: [],
shouldNotLog: ["Error", "Warn", "Info", "Debug", "Trace"],
},
{
mozLogLevel: 1,
maxLogLevel: "Off",
shouldLog: ["Error"],
shouldNotLog: ["Warn", "Info", "Debug", "Trace"],
},
{
mozLogLevel: 2,
maxLogLevel: "Off",
shouldLog: ["Error", "Warn"],
shouldNotLog: ["Info", "Debug", "Trace"],
},
{
mozLogLevel: 3,
maxLogLevel: "Off",
shouldLog: ["Error", "Warn", "Info"],
shouldNotLog: ["Debug", "Trace"],
},
{
mozLogLevel: 4,
maxLogLevel: "Off",
shouldLog: ["Error", "Warn", "Info", "Debug"],
shouldNotLog: ["Trace"],
},
{
mozLogLevel: 5,
maxLogLevel: "Off",
shouldLog: ["Error", "Warn", "Info", "Debug", "Trace"],
shouldNotLog: [],
},
// Also check that MOZ_LOG doesn't prevent regular logging
{
mozLogLevel: 0,
maxLogLevel: "All",
shouldLog: ["Error", "Warn", "Info", "Debug", "Trace"],
shouldNotLog: [],
},
{
mozLogLevel: 0,
maxLogLevel: "Warn",
shouldLog: ["Error", "Warn"],
shouldNotLog: ["Info", "Debug", "Trace"],
},
];
for (const test of tests) {
let mozLogCi = console.createInstance({
prefix: "shouldlogtest_" + test.mozLogLevel,
maxLogLevel: test.maxLogLevel,
});
for (const level of test.shouldNotLog) {
Assert.ok(
!mozLogCi.shouldLog(level),
`Should return false for "${level}" with MOZ_LOG=${test.mozLogLevel} and maxLogLevel=${test.maxLogLevel}`
);
}
for (const level of test.shouldLog) {
Assert.ok(
mozLogCi.shouldLog(level),
`Should return true for "${level}" with MOZ_LOG=${test.mozLogLevel} and maxLogLevel=${test.maxLogLevel}`
);
}
}
});