blob: 0081dce3d86362e21d39de34e0c601758ec3005e [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="connect-src http://invalid http://127.0.0.1">
</head>
<body>
<p>Test EventSource constructor functionality. Should print a series of PASS messages followed by DONE.</p>
<div id="result"></div>
<script>
function log(msg) {
document.getElementById("result").innerHTML += msg + "<br>";
}
if (window.testRunner) {
// Depending on timing, this test may end before or after a CSP event source
// violation is fired. Make this test deterministic by don't dumping console
// messages.
testRunner.setDumpConsoleMessages(false);
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
try {
new EventSource();
log("FAIL: no exception when trying to construct an EventSource without argument");
} catch (e) {
log("PASS: missing argument to EventSource constructor resulted in an exception (" + e + ")");
}
try {
new EventSource("");
log("FAIL: no exception when passing an empty string to the EventSource constructor");
} catch (e) {
log("PASS: passing an empty string to the EventSource constructor resulted in an exception (" + e + ")");
}
try {
new EventSource("http://webserver:eighty/");
log("FAIL: no exception when passing an invalid URL to the EventSource constructor");
} catch (e) {
log("PASS: passing an invalid URL to the EventSource constructor resulted in an exception (" + e + ")");
}
try {
new EventSource("http://disallowed.example.com/");
log("PASS: no exception when passing an URL blocked by Content Security Policy to the EventSource constructor");
} catch (e) {
log("FAIL: passing a Content-Security-Policy-blocked URL to the EventSource constructor resulted in an exception (" + e + ")");
}
try {
var es = new EventSource("http://127.0.0.1/", {"withCredentials": false});
es.close();
if (!es.withCredentials) {
log("PASS: no exception when passing a second argument to the EventSource constructor");
log("DONE");
} else
log("FAIL: the 'withCredentials' property is unexpectedly true");
} catch (e) {
log("FAIL: passing a second argument to the EventSource constructor resulted in an exception (" + e + ")");
}
if (window.testRunner)
testRunner.notifyDone();
</script>
</body>
</html>