This repository has been archived by the owner on Jul 10, 2021. It is now read-only.
forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create eventsource-request-cancellation.htm
Update the file per web-platform-tests#285 issuecomment-47893559
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>EventSource: request cancellation</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<script> | ||
var test = async_test(null, {timeout: 5000}); | ||
var url = "resources/message.py?sleep=1000&message=" + encodeURIComponent("retry:1000\ndata:abc\n\n"); | ||
var es = new EventSource(url); | ||
var lastEventTime = 0; | ||
var lastEventType = ""; | ||
var readyStateAtLastEvent = -1; | ||
es.onmessage = | ||
es.onerror = | ||
es.onopen = function (event) { | ||
lastEventTime = (new Date()).getTime(); | ||
lastEventType = event.type; | ||
readyStateAtLastEvent = es.readyState; | ||
}; | ||
setTimeout(function () { | ||
if (typeof window.stop === "function") { | ||
window.stop(); | ||
} | ||
}, 100); | ||
setTimeout(function () { | ||
test.step(function () { | ||
var isActive = ((new Date()).getTime() - lastEventTime) < 2500; | ||
if (es.readyState === EventSource.CLOSED) { | ||
var message = "In case EventSource was stopped, it should not be active, and the last event should be an error event."; | ||
assert_true(!isActive, message); | ||
assert_true(lastEventType === "error", message); | ||
assert_true(readyStateAtLastEvent === EventSource.CLOSED, message); | ||
} else { | ||
assert_true(isActive, "EventSource is active, but readyState is EventSource.CLOSED."); | ||
} | ||
}); | ||
es.close(); | ||
test.done(); | ||
}, 4000); | ||
</script> | ||
</body> | ||
</html> |