blob: 921a7410734328f3606c476d9c486c8eaa758dcb [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/audit-utilities.js"></script>
<script>
if (window.internals)
window.internals.settings.setUnhandledPromiseRejectionToConsoleEnabled(false);
function test()
{
let suite = InspectorTest.Audit.createSuite("Audit.Basic");
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Boolean.True", true, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Boolean.False", false, WI.AuditTestCaseResult.Level.Fail);
InspectorTest.Audit.addStringTest("Audit.Basic.String.Pass", WI.AuditTestCaseResult.Level.Pass, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addStringTest("Audit.Basic.String.Warn", WI.AuditTestCaseResult.Level.Warn, WI.AuditTestCaseResult.Level.Warn);
InspectorTest.Audit.addStringTest("Audit.Basic.String.Fail", WI.AuditTestCaseResult.Level.Fail, WI.AuditTestCaseResult.Level.Fail);
InspectorTest.Audit.addStringTest("Audit.Basic.String.Error", WI.AuditTestCaseResult.Level.Error, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addStringTest("Audit.Basic.String.Unsupported", WI.AuditTestCaseResult.Level.Unsupported, WI.AuditTestCaseResult.Level.Unsupported);
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Pass", {level: WI.AuditTestCaseResult.Level.Pass}, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Warn", {level: WI.AuditTestCaseResult.Level.Warn}, WI.AuditTestCaseResult.Level.Warn);
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Fail", {level: WI.AuditTestCaseResult.Level.Fail}, WI.AuditTestCaseResult.Level.Fail);
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Error", {level: WI.AuditTestCaseResult.Level.Error}, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addObjectTest("Audit.Basic.Object.Unsupported", {level: WI.AuditTestCaseResult.Level.Unsupported}, WI.AuditTestCaseResult.Level.Unsupported);
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.Boolean.True", `resolve(true)`, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.String.Pass", `resolve("${WI.AuditTestCaseResult.Level.Pass}")`, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addPromiseTest("Audit.Basic.Promise.Object.Pass", `resolve({level: "${WI.AuditTestCaseResult.Level.Pass}"})`, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Async.Boolean.True", true, WI.AuditTestCaseResult.Level.Pass, {async: true});
InspectorTest.Audit.addStringTest("Audit.Basic.Async.String.Pass", WI.AuditTestCaseResult.Level.Pass, WI.AuditTestCaseResult.Level.Pass, {async: true});
InspectorTest.Audit.addObjectTest("Audit.Basic.Async.Object.Pass", {level: WI.AuditTestCaseResult.Level.Pass}, WI.AuditTestCaseResult.Level.Pass, {async: true});
InspectorTest.Audit.addPromiseTest("Audit.Basic.Timeout.Pass", `setTimeout(resolve, 0, "${WI.AuditTestCaseResult.Level.Pass}")`, WI.AuditTestCaseResult.Level.Pass);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Undefined", undefined, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Null", null, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Number", 42, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addStringTest("Audit.Basic.Error.String", "foo", WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addObjectTest("Audit.Basic.Error.Object", {}, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addFunctionlessTest("Audit.Basic.Error.Variable", "INVALID", WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Resolved", `setTimeout(resolve, 0)`, WI.AuditTestCaseResult.Level.Error);
InspectorTest.Audit.addPromiseTest("Audit.Basic.Error.Promise.Rejected", `setTimeout(reject, 0, "rejected")`, WI.AuditTestCaseResult.Level.Error);
suite.addTestCase({
name: "Audit.Basic.Debugger",
description: "Test that a debugger statement doesn't pause when running an audit.",
test(resolve, reject) {
const level = "pass";
let audit = new WI.AuditTestCase("Audit.Basic.Debugger", `function() { debugger; return "${level}"; }`);
let paused = false;
let pausedListener = WI.debuggerManager.singleFireEventListener(WI.DebuggerManager.Event.Paused, (event) => {
paused = true;
WI.debuggerManager.resume();
});
WI.auditManager.awaitEvent(WI.AuditManager.Event.TestCompleted).then((event) => {
InspectorTest.expectFalse(paused, "Should not pause on the debugger statement.");
let results = WI.auditManager.results.lastValue;
InspectorTest.assert(results.length === 1, "There should be 1 result.");
let result = results[0];
InspectorTest.assert(result instanceof WI.AuditTestCaseResult, "Result should be a WI.AuditTestCaseResult.");
if (!result)
return;
InspectorTest.expectEqual(result.level, level, `Result should be "${level}".`);
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.Paused, pausedListener);
});
InspectorTest.log("Testing `debugger`...");
WI.auditManager.start([audit])
.then(resolve, reject);
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Testing the basic functionality of audits.</p>
</body>
</html>