blob: d65c095cea63a201b3eeb11b30835356bdf0f7c2 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function test()
{
ProtocolTest.suppressStackTraces = true;
ProtocolTest.expectException(() => {
new SyncTestSuite(this);
});
ProtocolTest.expectException(() => {
new SyncTestSuite(this, {});
});
ProtocolTest.expectException(() => {
new SyncTestSuite(this, " ");
});
ProtocolTest.expectException(() => {
new SyncTestSuite("something", {});
});
let badArgsSuite = ProtocolTest.createSyncSuite("dummy");
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase();
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase("string");
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: {},
test() {
return true;
},
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: " ",
test() {
},
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test: null,
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
setup: "astd"
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
setup: 123
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
setup: Promise.resolve()
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
teardown: "astd"
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
teardown: 123
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
teardown: Promise.resolve()
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
async test() {
},
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
async setup() {
},
test() {
},
});
});
ProtocolTest.expectException(() => {
badArgsSuite.addTestCase({
name: "foo",
test() {
},
async teardown() {
},
});
});
ProtocolTest.expectException(() => {
let runEmptySuite = ProtocolTest.createSyncSuite("SyncTestSuite.RunEmptySuite");
runEmptySuite.runTestCases();
});
let runTwiceSuite = ProtocolTest.createSyncSuite("SyncTestSuite.RunTwiceSuite");
runTwiceSuite.addTestCase({
name: "DummyTest0",
test() {
return true;
},
});
ProtocolTest.expectThat(runTwiceSuite.runTestCases() === true, "Return value of runTwiceSuite.runTestCases() should be true when all tests pass.");
ProtocolTest.expectException(() => {
runTwiceSuite.runTestCases();
});
function checkResult(suite, expectedCounts) {
ProtocolTest.expectThat(suite.runTestCases(), `Return value of ${suite.name}.runTestCases() should be true even if a test case fails.`);
ProtocolTest.expectEqual(expectedCounts.runCount, suite.runCount, `${suite.name} should have executed ${expectedCounts.runCount} tests.`);
ProtocolTest.expectEqual(expectedCounts.passCount, suite.passCount, `${suite.name} should have passed ${expectedCounts.passCount} tests.`);
ProtocolTest.expectEqual(expectedCounts.failCount, suite.failCount, `${suite.name} should have failed ${expectedCounts.failCount} tests.`);
ProtocolTest.expectEqual(expectedCounts.skipCount, suite.skipCount, `${suite.name} should have skipped ${expectedCounts.skipCount} tests.`);
}
let thrownError = new Error({"token": 666});
let sequentialExecutionPhase = 0;
let sequentialExecutionSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SequentialExecution");
sequentialExecutionSuite.addTestCase({
name: "1 (Pass)",
test() {
ProtocolTest.assert(sequentialExecutionPhase === 0);
sequentialExecutionPhase = 1;
return true;
},
});
sequentialExecutionSuite.addTestCase({
name: "2 (Pass)",
test() {
ProtocolTest.assert(sequentialExecutionPhase === 1);
sequentialExecutionPhase = 2;
return true;
},
});
sequentialExecutionSuite.addTestCase({
name: "3 (Pass)",
test() {
ProtocolTest.assert(sequentialExecutionPhase === 2);
sequentialExecutionPhase = 3;
return true;
},
});
sequentialExecutionSuite.addTestCase({
name: "4 (Pass)",
test() {
ProtocolTest.assert(sequentialExecutionPhase === 3);
sequentialExecutionPhase = 4;
return true;
},
});
checkResult(sequentialExecutionSuite, {
runCount: 4,
passCount: 4,
failCount: 0,
skipCount: 0,
});
let continueOnFailureSuite = ProtocolTest.createSyncSuite("SyncTestSuite.ContinueOnFailure");
continueOnFailureSuite.addTestCase({
name: "1 (Pass)",
test() {
return true;
},
});
continueOnFailureSuite.addTestCase({
name: "2 (Fail)",
test() {
ProtocolTest.log("Throwing...");
throw {x: "ContinueOnFailure throw"};
},
});
continueOnFailureSuite.addTestCase({
name: "3 (Pass)",
test() {
return true;
},
});
continueOnFailureSuite.addTestCase({
name: "4 (Fail)",
test() {
ProtocolTest.log("Failing...");
return false;
},
});
checkResult(continueOnFailureSuite, {
runCount: 4,
passCount: 2,
failCount: 2,
skipCount: 0,
});
let setupAndTeardownPhase = 0;
let setupAndTeardownSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupAndTeardown");
setupAndTeardownSuite.addTestCase({
name: "TestWithSetupAndTeardown",
setup() {
ProtocolTest.assert(setupAndTeardownPhase === 0);
setupAndTeardownPhase = 1;
return true;
},
test() {
ProtocolTest.assert(setupAndTeardownPhase === 1);
setupAndTeardownPhase = 2;
return true;
},
teardown() {
ProtocolTest.assert(setupAndTeardownPhase === 2);
setupAndTeardownPhase = 3;
return true;
},
});
setupAndTeardownSuite.addTestCase({
name: "TestRunningAfterTeardown",
test() {
ProtocolTest.assert(setupAndTeardownPhase === 3);
return true;
},
});
checkResult(setupAndTeardownSuite, {
runCount: 2,
passCount: 2,
failCount: 0,
skipCount: 0,
});
let setupExceptionSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupException");
setupExceptionSuite.addTestCase({
name: "TestWithExceptionDuringSetup",
setup() {
ProtocolTest.log("Throwing...");
throw "SetupException throw";
},
test() {
ProtocolTest.fail("Test should not execute if its setup action threw an exception.");
return false;
},
teardown() {
ProtocolTest.fail("Teardown action should not execute if its setup action threw an exception.");
return false;
},
});
setupExceptionSuite.addTestCase({
name: "TestAfterSetupException",
setup() {
ProtocolTest.pass("Setup action should still execute if previous test's setup action threw an exception.");
return true;
},
test() {
ProtocolTest.pass("Test should still execute if previous test's setup action threw an exception.");
return true;
},
teardown() {
ProtocolTest.pass("Teardown action should still execute if previous test's setup action threw an exception.");
return true;
},
});
checkResult(setupExceptionSuite, {
runCount: 1,
passCount: 1,
failCount: 1,
skipCount: 1,
});
let setupFailureSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupFailure");
setupFailureSuite.addTestCase({
name: "TestWithFailureDuringSetup",
setup() {
ProtocolTest.log("Failing...");
return false;
},
test() {
ProtocolTest.fail("Test should not execute if its setup action failed.");
return false;
},
teardown() {
ProtocolTest.fail("Teardown action should not execute if its setup action failed.");
return false;
},
});
setupFailureSuite.addTestCase({
name: "TestAfterSetupException",
setup() {
ProtocolTest.pass("Setup action should still execute if previous test's setup action failed.");
return true;
},
test() {
ProtocolTest.pass("Test should still execute if previous test's setup action failed.");
return true;
},
teardown() {
ProtocolTest.pass("Teardown action should still execute if previous test's setup action failed.");
return true;
},
});
checkResult(setupFailureSuite, {
runCount: 1,
passCount: 1,
failCount: 1,
skipCount: 1,
});
let teardownExceptionSuite = ProtocolTest.createSyncSuite("SyncTestSuite.TeardownException");
teardownExceptionSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
test() {
return true;
},
teardown() {
ProtocolTest.log("Throwing...");
throw "TeardownException throw";
},
});
teardownExceptionSuite.addTestCase({
name: "TestAfterTeardownException",
setup() {
ProtocolTest.pass("Setup action should still execute if previous test's teardown action threw an exception.");
return true;
},
test() {
ProtocolTest.pass("Test should still execute if previous test's teardown action threw an exception.");
return true;
},
teardown() {
ProtocolTest.pass("Teardown action should still execute if previous test's teardown action threw an exception.");
return true;
},
});
checkResult(teardownExceptionSuite, {
runCount: 2,
passCount: 1,
failCount: 1,
skipCount: 0,
});
let teardownFailureSuite = ProtocolTest.createSyncSuite("SyncTestSuite.TeardownFailure");
teardownFailureSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
test() {
return true;
},
teardown() {
ProtocolTest.log("Failing...");
return false;
},
});
teardownFailureSuite.addTestCase({
name: "TestAfterTeardownException",
setup() {
ProtocolTest.pass("Setup action should still execute if previous test's teardown action failed.");
return true;
},
test() {
ProtocolTest.pass("Test should still execute if previous test's teardown action failed.");
return true;
},
teardown() {
ProtocolTest.pass("Teardown action should still execute if previous test's teardown action failed.");
return true;
},
});
checkResult(teardownFailureSuite, {
runCount: 2,
passCount: 1,
failCount: 1,
skipCount: 0,
});
ProtocolTest.completeTest();
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>