blob: 939837190be8e859e8af71d20c1f9fa0236ee7df [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
<script>
function test()
{
try {
let result = new AsyncTestSuite(this);
ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating AsyncTestSuite requires name argument.");
}
try {
let result = new AsyncTestSuite(this, {});
ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires string name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating AsyncTestSuite requires string name argument.");
}
try {
let result = new AsyncTestSuite(this, " ");
ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires non-whitespace name argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating AsyncTestSuite requires non-whitespace name argument.");
}
try {
let result = new AsyncTestSuite("something", {});
ProtocolTest.log("FAIL: instantiating AsyncTestSuite requires test harness argument.");
} catch (e) {
ProtocolTest.log("PASS: instantiating AsyncTestSuite requires test harness argument.");
}
let badArgsSuite = ProtocolTest.createAsyncSuite("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: () => {},
});
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: {}
});
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: {}
});
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.");
}
let runEmptySuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.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.createAsyncSuite("AsyncTestSuite.RunTwiceSuite");
runTwiceSuite.addTestCase({
name: "DummyTest0",
description: "Check that a suite can't run more than once.",
test: (resolve, reject) => { resolve(); }
});
let result = runTwiceSuite.runTestCases();
try {
// Test cases won't run in this event loop; this call should still throw.
// Later tests are chained to this suite to avoid nondeterminism.
runTwiceSuite.runTestCases();
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 rejectToken = {"token": 666};
let thrownError = new Error(rejectToken);
let sequentialExecutionSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SequentialExecution");
sequentialExecutionSuite.addTestCase({
name: "DummyTest1",
description: "Check test case execution order.",
test: (resolve, reject) => { resolve(); }
});
sequentialExecutionSuite.addTestCase({
name: "DummyTest2",
description: "Check test case execution order.",
test: (resolve, reject) => { resolve(); }
});
sequentialExecutionSuite.addTestCase({
name: "DummyTest3",
description: "Check test case execution order.",
test: (resolve, reject) => { resolve(); }
});
sequentialExecutionSuite.addTestCase({
name: "FailingTest4",
description: "Check that test fails by throwing an Error instance.",
test: (resolve, reject) => { throw thrownError; }
});
let abortOnFailureSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AbortOnFailure");
abortOnFailureSuite.addTestCase({
name: "PassingTest5",
description: "This test is a dummy.",
test: (resolve, reject) => { resolve(); }
});
abortOnFailureSuite.addTestCase({
name: "FailingTest6",
description: "This test should fail by explicitly calling the `reject` callback.",
test: (resolve, reject) => { reject(rejectToken); }
});
abortOnFailureSuite.addTestCase({
name: "PassingTest7",
description: "This test should not executed when the preceding test fails.",
test: (resolve, reject) => { resolve(); }
});
result = result.then(() => {
let promise = sequentialExecutionSuite.runTestCases();
ProtocolTest.expectThat(result instanceof Promise, "AsyncTestSuite.RunTestCases() should return a Promise.");
return promise;
});
result = result.then(function resolved() {
ProtocolTest.log("FAIL: Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails.");
ProtocolTest.expectThat(e === thrownError, "Promise from sequentialExecutionSuite.runTestCases() should reject without altering its result value.");
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.");
return Promise.resolve(); // Continue this test.
});
result = result.then(() => {
return abortOnFailureSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("FAIL: Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails.");
ProtocolTest.expectThat(e === rejectToken, "Promise from abortOnFailureSuite.runTestCases() should reject without altering its result value.");
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.");
return Promise.resolve(); // Continue this test.
});
var setupAndTeardownSymbol = Symbol("async-suite-setup-and-teardown-token");
window[setupAndTeardownSymbol] = 0;
let setupAndTeardownTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupAndTeardown");
setupAndTeardownTestSuite.addTestCase({
name: "TestWithSetupAndTeardown",
description: "Check execution order for setup and teardown actions.",
setup: (resolve, reject) => {
window[setupAndTeardownSymbol] = 1;
resolve();
},
test: (resolve, reject) => {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 1, "Test should see side effects of running setup() action.");
window[setupAndTeardownSymbol] = 2;
resolve();
},
teardown: (resolve, reject) => {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 2, "Teardown should see side effects of running setup() action.");
window[setupAndTeardownSymbol] = 3;
resolve();
}
});
setupAndTeardownTestSuite.addTestCase({
name: "TestRunningAfterTeardown",
description: "Check execution order for test after a teardown action.",
test: (resolve, reject) => {
ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 3, "Test should see side effects of previous test's teardown() action.");
resolve();
},
});
result = result.then(() => {
return setupAndTeardownTestSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("PASS: Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("FAIL: Promise from setupAndTeardownTestSuite.runTestCases() should resolve.");
return Promise.resolve(); // Continue this test.
});
let setupExceptionTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupException");
setupExceptionTestSuite.addTestCase({
name: "TestWithExceptionDuringSetup",
description: "Check execution order for setup action that throws an exception.",
setup: (resolve, reject) => { throw new Error() },
test: (resolve, reject) => {
ProtocolTest.assert(false, "Test should not execute if its setup action threw an exception.");
reject();
},
teardown: (resolve, reject) => {
ProtocolTest.assert(false, "Teardown action should not execute if its setup action threw an exception.");
reject();
}
});
result = result.then(() => {
return setupExceptionTestSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("FAIL: Promise from setupExceptionTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from setupExceptionTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
});
let setupFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupFailure");
setupFailureTestSuite.addTestCase({
name: "TestWithFailureDuringSetup",
description: "Check execution order for setup action that has failed.",
setup: (resolve, reject) => { reject(); },
test: (resolve, reject) => {
ProtocolTest.assert(false, "Test should not execute if its setup action failed.")
reject();
},
teardown: (resolve, reject) => {
ProtocolTest.assert(false, "Teardown action should not execute if its setup action failed.")
reject();
}
});
result = result.then(() => {
return setupFailureTestSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("FAIL: Promise from setupFailureTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from setupFailureTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
});
let teardownExceptionTestSuite = ProtocolTest.createAsyncSuite("SyncTestSuite.TeardownException");
teardownExceptionTestSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
description: "Check execution order for teardown action that throws an exception.",
test: (resolve, reject) => { resolve(); },
teardown: (resolve, reject) => { throw new Error() }
});
teardownExceptionTestSuite.addTestCase({
name: "TestAfterTeardownException",
descrption: "Check execution order for test after previous test's teardown throws an exception.",
setup: (resolve, reject) => {
ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action threw an exception.");
reject();
},
test: (resolve, reject) => {
ProtocolTest.assert(false, "Test should not execute if previous test's teardown action threw an exception.");
reject();
}
});
result = result.then(() => {
return teardownExceptionTestSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("FAIL: Promise from teardownExceptionTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from teardownExceptionTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
});
let teardownFailureTestSuite = ProtocolTest.createAsyncSuite("SyncTestSuite.TeardownFailure");
teardownFailureTestSuite.addTestCase({
name: "TestWithExceptionDuringTeardown",
description: "Check execution order for teardown action that has failed.",
test: (resolve, reject) => { resolve(); },
teardown: (resolve, reject) => { reject(); },
});
teardownFailureTestSuite.addTestCase({
name: "TestAfterTeardownException",
description: "Check execution order for test after previous test's teardown throws an exception",
setup: (resolve, reject) => {
ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action failed.");
reject();
},
test: (resolve, reject) => {
ProtocolTest.assert(false, "Test should not execute if previous test's teardown action failed.");
reject();
}
});
result = result.then(() => {
return teardownFailureTestSuite.runTestCases();
}).then(function resolved() {
ProtocolTest.log("FAIL: Promise from teardownFailureTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
}, function rejected(e) {
ProtocolTest.log("PASS: Promise from teardownFailureTestSuite.runTestCases() should reject.");
return Promise.resolve(); // Continue this test.
});
// This will finish the test whether the chain was resolved or rejected.
result = result.then(() => { ProtocolTest.completeTest(); });
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>