blob: 9390e8df7bc1a676021f95a679fbd5f03b4b029d [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function test()
{
ProtocolTest.suppressStackTraces = true;
try {
let result = new SyncTestSuite(this);
ProtocolTest.log("FAIL: instantiating SyncTestSuite requires name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating SyncTestSuite requires name argument.");
}
try {
let result = new SyncTestSuite(this, {});
ProtocolTest.log("FAIL: instantiating SyncTestSuite requires string name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating SyncTestSuite requires string name argument.");
}
try {
let result = new SyncTestSuite(this, " ");
ProtocolTest.log("FAIL: instantiating SyncTestSuite requires non-whitespace name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating SyncTestSuite requires non-whitespace name argument.");
}
try {
let result = new SyncTestSuite("something", {});
ProtocolTest.log("FAIL: instantiating SyncTestSuite requires test harness argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating SyncTestSuite requires test harness argument.");
}
let badArgsSuite = ProtocolTest.createSyncSuite("dummy");
try {
badArgsSuite.addTestCase();
ProtocolTest.log("FAIL: should not be able to add empty test case.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to add empty test case.");
}
try {
badArgsSuite.addTestCase("string");
ProtocolTest.log("FAIL: should not be able to add non-object test case.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to add non-object test case.");
}
try {
badArgsSuite.addTestCase({
name: {},
test: () => true,
});
ProtocolTest.log("FAIL: test case should require string name.");
} catch (e) {
ProtocolTest.log("PASS: test case should require string name.");
}
try {
badArgsSuite.addTestCase({
name: " ",
test() {},
});
ProtocolTest.log("FAIL: test case should require non-whitespace name.");
} catch (e) {
ProtocolTest.log("PASS: test case should require non-whitespace name.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test: null,
});
ProtocolTest.log("FAIL: test case should require test function.");
} catch (e) {
ProtocolTest.log("PASS: test case should require test function.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
setup: "astd"
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
setup: 123
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
setup: Promise.resolve()
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `setup` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `setup` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
teardown: "astd"
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
teardown: 123
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
teardown: Promise.resolve()
});
ProtocolTest.log("FAIL: should not be able to specify non-Function `teardown` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify non-Function `teardown` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
async test() {},
});
ProtocolTest.log("FAIL: should not be able to specify async `test` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify async `test` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
async setup() {},
test() {},
});
ProtocolTest.log("FAIL: should not be able to specify async `setup` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify async `setup` parameter.");
}
try {
badArgsSuite.addTestCase({
name: "foo",
test() {},
async teardown() {},
});
ProtocolTest.log("FAIL: should not be able to specify async `teardown` parameter.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to specify async `teardown` parameter.");
}
let runEmptySuite = ProtocolTest.createSyncSuite("SyncTestSuite.RunEmptySuite");
try {
runEmptySuite.runTestCases();
ProtocolTest.log("FAIL: should not be able to run empty test suite.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to run empty test suite.");
}
let runTwiceSuite = ProtocolTest.createSyncSuite("SyncTestSuite.RunTwiceSuite");
runTwiceSuite.addTestCase({
name: "DummyTest0",
description: "Check that a suite can't run more than once.",
test: () => true,
});
try {
let result = runTwiceSuite.runTestCases();
ProtocolTest.expectThat(result === true, "Return value of runTwiceSuite.runTestCases() should be true when all tests pass.");
runTwiceSuite.runTestCases(); // Try to trigger an error.
ProtocolTest.log("FAIL: should not be able to run a test suite twice.");
} catch (e) {
ProtocolTest.log("PASS: should not be able to run a test suite twice.");
}
let thrownError = new Error({"token": 666});
let sequentialExecutionSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SequentialExecution");
sequentialExecutionSuite.addTestCase({
name: "DummyTest1",
description: "Check test case execution order.",
test: () => true
});
sequentialExecutionSuite.addTestCase({
name: "DummyTest2",
description: "Check test case execution order.",
test: () => true
});
sequentialExecutionSuite.addTestCase({
name: "DummyTest3",
description: "Check test case execution order.",
test: () => true
});
sequentialExecutionSuite.addTestCase({
name: "FailingTest4",
description: "Check that test fails by throwing an Error instance.",
test() { throw thrownError; }
});
let result = sequentialExecutionSuite.runTestCases();
ProtocolTest.expectThat(result === false, "Return value of sequentialExecutionSuite.runTestCases() should be false when a test case fails.");
ProtocolTest.expectThat(sequentialExecutionSuite.runCount === 4, "sequentialExecutionSuite should have executed four tests.");
ProtocolTest.expectThat(sequentialExecutionSuite.passCount === 3, "sequentialExecutionSuite should have passed three tests.");
ProtocolTest.expectThat(sequentialExecutionSuite.failCount === 1, "sequentialExecutionSuite should have failed 1 test.");
ProtocolTest.expectThat(sequentialExecutionSuite.skipCount === 0, "sequentialExecutionSuite should have skipped zero tests.");
let abortOnFailureSuite = ProtocolTest.createSyncSuite("SyncTestSuite.AbortOnFailure");
abortOnFailureSuite.addTestCase({
name: "PassingTest5",
description: "This test is a dummy.",
test: () => true
});
abortOnFailureSuite.addTestCase({
name: "FailingTest6",
description: "This test should fail by explicitly returning `false`.",
test: () => false
});
abortOnFailureSuite.addTestCase({
name: "PassingTest7",
description: "This test should not executed when the preceding test fails.",
test: () => true
});
abortOnFailureSuite.runTestCases();
ProtocolTest.expectThat(result === false, "Return value of abortOnFailureSuite.runTestCases() should be false when a test case fails.");
ProtocolTest.expectThat(abortOnFailureSuite.runCount === 2, "abortOnFailureSuite should have executed two tests.");
ProtocolTest.expectThat(abortOnFailureSuite.passCount === 1, "abortOnFailureSuite should have passed one test.");
ProtocolTest.expectThat(abortOnFailureSuite.failCount === 1, "abortOnFailureSuite should have failed one test.");
ProtocolTest.expectThat(abortOnFailureSuite.skipCount === 1, "abortOnFailureSuite should have skipped one test.");
let setupAndTeardownSymbol = Symbol("sync-suite-setup-and-teardown-token");
window[setupAndTeardownSymbol] = 0;
let setupAndTeardownTestSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupAndTeardown");
setupAndTeardownTestSuite.addTestCase({
name: "TestWithSetupAndTeardown",
description: "Check execution order for setup and teardown actions.",
setup: () => {
window[setupAndTeardownSymbol] = 1;
return true;
},
test() {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 1, "Test should see side effects of running setup() action.");
window[setupAndTeardownSymbol] = 2;
return true;
},
teardown: () => {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 2, "Teardown should see side effects of running setup() action.");
window[setupAndTeardownSymbol] = 3;
return true;
}
});
setupAndTeardownTestSuite.addTestCase({
name: "TestRunningAfterTeardown",
description: "Check execution order for test after a teardown action.",
test() {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 3, "Test should see side effects of previous test's teardown() action.");
return true;
},
});
setupAndTeardownTestSuite.runTestCases();
let setupExceptionTestSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupException");
setupExceptionTestSuite.addTestCase({
name: "TestWithExceptionDuringSetup",
description: "Check execution order for setup action that throws an exception.",
setup: () => { throw new Error() },
test() {
ProtocolTest.assert(false, "Test should not execute if its setup action threw an exception.");
return false;
},
teardown: () => {
ProtocolTest.assert(false, "Teardown action should not execute if its setup action threw an exception.");
return false;
}
});
setupExceptionTestSuite.runTestCases();
let setupFailureTestSuite = ProtocolTest.createSyncSuite("SyncTestSuite.SetupFailure");
setupFailureTestSuite.addTestCase({
name: "TestWithFailureDuringSetup",
description: "Check execution order for setup action that has failed.",
setup: () => false,
test() {
ProtocolTest.assert(false, "Test should not execute if its setup action returned false.")
return false;
},
teardown: () => {
ProtocolTest.assert(false, "Teardown action should not execute if its setup action returned false.")
return false;
}
});
setupFailureTestSuite.runTestCases();
let teardownExceptionTestSuite = ProtocolTest.createSyncSuite("SyncTestSuite.TeardownException");
teardownExceptionTestSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
description: "Check execution order for teardown action that throws an exception.",
test: () => true,
teardown: () => { throw new Error() }
});
teardownExceptionTestSuite.addTestCase({
name: "TestAfterTeardownException",
descrption: "Check execution order for test after previous test's teardown throws an exception",
setup: () => {
ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action threw an exception.");
return false;
},
test() {
ProtocolTest.assert(false, "Test should not execute if previous test's teardown action threw an exception.");
return false;
}
});
teardownExceptionTestSuite.runTestCases();
let teardownFailureTestSuite = ProtocolTest.createSyncSuite("SyncTestSuite.TeardownFailure");
teardownFailureTestSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
description: "Check execution order for teardown action that has failed.",
test: () => true,
teardown: () => false,
});
teardownFailureTestSuite.addTestCase({
name: "TestAfterTeardownException",
descrption: "Check execution order for test after previous test's teardown throws an exception",
setup: () => {
ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action failed.");
return false;
},
test() {
ProtocolTest.assert(false, "Test should not execute if previous test's teardown action failed.");
return false;
}
});
teardownFailureTestSuite.runTestCases();
ProtocolTest.completeTest();
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>