Commit 99aaf9dd authored by weinig@apple.com's avatar weinig@apple.com

JavaScriptCore: Added ENABLE_EVENTSOURCE flag.

https://bugs.webkit.org/show_bug.cgi?id=14997

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2009-08-15
Reviewed by Sam Weinig.

* Configurations/FeatureDefines.xcconfig:

WebCore: Added implementation of the EventSource object that enables
server-sent events from HTML5.
http://dev.w3.org/html5/eventsource/
https://bugs.webkit.org/show_bug.cgi?id=14997

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2009-08-15
Reviewed by Sam Weinig.

Tests: fast/eventsource/eventsource-attribute-listeners.html
       fast/eventsource/eventsource-constructor.html
       http/tests/eventsource/eventsource-bad-mime-type.html
       http/tests/eventsource/eventsource-parse-event-stream.html
       http/tests/eventsource/eventsource-reconnect.html
       http/tests/eventsource/eventsource-status-code-states.html
       http/tests/eventsource/workers/eventsource-simple.html

* Configurations/FeatureDefines.xcconfig:
* DerivedSources.cpp:
* DerivedSources.make:
* GNUmakefile.am:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::eventSource):
* bindings/js/JSEventSourceConstructor.cpp: Added.
(WebCore::):
(WebCore::JSEventSourceConstructor::JSEventSourceConstructor):
(WebCore::constructEventSource):
(WebCore::JSEventSourceConstructor::getConstructData):
* bindings/js/JSEventSourceConstructor.h: Added.
(WebCore::JSEventSourceConstructor::classInfo):
* bindings/js/JSEventSourceCustom.cpp: Added.
(WebCore::JSEventSource::markChildren):
(WebCore::JSEventSource::addEventListener):
(WebCore::JSEventSource::removeEventListener):
* bindings/js/JSEventTarget.cpp:
(WebCore::toJS):
(WebCore::toEventTarget):
* bindings/js/JSWorkerContextCustom.cpp:
(WebCore::JSWorkerContext::eventSource):
* dom/EventNames.h:
* dom/EventTarget.cpp:
(WebCore::EventTarget::toEventSource):
* dom/EventTarget.h:
* page/DOMWindow.idl:
* page/EventSource.cpp: Added.
(WebCore::EventSource::EventSource):
(WebCore::EventSource::~EventSource):
(WebCore::EventSource::connect):
(WebCore::EventSource::endRequest):
(WebCore::EventSource::scheduleReconnect):
(WebCore::EventSource::reconnectTimerFired):
(WebCore::EventSource::url):
(WebCore::EventSource::readyState):
(WebCore::EventSource::close):
(WebCore::EventSource::scriptExecutionContext):
(WebCore::EventSource::addEventListener):
(WebCore::EventSource::removeEventListener):
(WebCore::EventSource::dispatchEvent):
(WebCore::EventSource::didReceiveResponse):
(WebCore::EventSource::didReceiveData):
(WebCore::EventSource::didFinishLoading):
(WebCore::EventSource::didFail):
(WebCore::EventSource::didFailRedirectCheck):
(WebCore::EventSource::parseEventStream):
(WebCore::EventSource::parseEventStreamLine):
(WebCore::EventSource::dispatchGenericEvent):
(WebCore::EventSource::dispatchMessageEvent):
(WebCore::EventSource::stop):
* page/EventSource.h: Added.
(WebCore::EventSource::create):
(WebCore::EventSource::):
(WebCore::EventSource::setOnopen):
(WebCore::EventSource::onopen):
(WebCore::EventSource::setOnmessage):
(WebCore::EventSource::onmessage):
(WebCore::EventSource::setOnerror):
(WebCore::EventSource::onerror):
(WebCore::EventSource::toEventSource):
(WebCore::EventSource::eventListeners):
(WebCore::EventSource::refEventTarget):
(WebCore::EventSource::derefEventTarget):
* page/EventSource.idl: Added.
* workers/WorkerContext.idl:

WebKit/mac: Added ENABLE_EVENTSOURCE flag.
https://bugs.webkit.org/show_bug.cgi?id=14997

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2009-08-15
Reviewed by Sam Weinig.

* Configurations/FeatureDefines.xcconfig:

WebKitTools: Added EventSource to the build script (default on).
https://bugs.webkit.org/show_bug.cgi?id=14997 

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2009-08-14
Reviewed by Sam Weinig.

* Scripts/build-webkit:

LayoutTests: Tests for EventSource.
https://bugs.webkit.org/show_bug.cgi?id=14997 

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2009-08-14
Reviewed by Sam Weinig.

* fast/eventsource: Added.
* fast/eventsource/eventsource-attribute-listeners-expected.txt: Added.
* fast/eventsource/eventsource-attribute-listeners.html: Added.
* fast/eventsource/eventsource-constructor-expected.txt: Added.
* fast/eventsource/eventsource-constructor.html: Added.
* http/tests/eventsource: Added.
* http/tests/eventsource/eventsource-bad-mime-type-expected.txt: Added.
* http/tests/eventsource/eventsource-bad-mime-type.html: Added.
* http/tests/eventsource/eventsource-parse-event-stream-expected.txt: Added.
* http/tests/eventsource/eventsource-parse-event-stream.html: Added.
* http/tests/eventsource/eventsource-reconnect-expected.txt: Added.
* http/tests/eventsource/eventsource-reconnect.html: Added.
* http/tests/eventsource/eventsource-status-code-states-expected.txt: Added.
* http/tests/eventsource/eventsource-status-code-states.html: Added.
* http/tests/eventsource/resources: Added.
* http/tests/eventsource/resources/bad-mime-type.asis: Added.
* http/tests/eventsource/resources/event-stream.php: Added.
* http/tests/eventsource/resources/reconnect.php: Added.
* http/tests/eventsource/resources/simple-event-stream.asis: Added.
* http/tests/eventsource/resources/status-codes.php: Added.
* http/tests/eventsource/workers: Added.
* http/tests/eventsource/workers/eventsource-simple-expected.txt: Added.
* http/tests/eventsource/workers/eventsource-simple.html: Added.
* http/tests/eventsource/workers/resources: Added.
* http/tests/eventsource/workers/resources/simple-worker.js: Added.
(es.onmessage):
(es.onerror):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47323 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7ad29f4
2009-08-15 Adam Bergkvist <adam.bergkvist@ericsson.com>
Reviewed by Sam Weinig.
Added ENABLE_EVENTSOURCE flag.
https://bugs.webkit.org/show_bug.cgi?id=14997
* Configurations/FeatureDefines.xcconfig:
2009-08-14 Gavin Barraclough <barraclough@apple.com>
Reviewed by NOBODY (build fix).
......
......@@ -36,6 +36,7 @@ ENABLE_CHANNEL_MESSAGING = ENABLE_CHANNEL_MESSAGING;
ENABLE_DATABASE = ENABLE_DATABASE;
ENABLE_DATAGRID = ENABLE_DATAGRID;
ENABLE_DOM_STORAGE = ENABLE_DOM_STORAGE;
ENABLE_EVENTSOURCE = ENABLE_EVENTSOURCE;
ENABLE_FILTERS = ;
ENABLE_GEOLOCATION = ;
ENABLE_ICONDATABASE = ENABLE_ICONDATABASE;
......@@ -58,4 +59,4 @@ ENABLE_WORKERS = ENABLE_WORKERS;
ENABLE_XPATH = ENABLE_XPATH;
ENABLE_XSLT = ENABLE_XSLT;
FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_DATABASE) $(ENABLE_DATAGRID) $(ENABLE_DOM_STORAGE) $(ENABLE_FILTERS) $(ENABLE_GEOLOCATION) $(ENABLE_ICONDATABASE) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_NOTIFICATIONS) $(ENABLE_OFFLINE_WEB_APPLICATIONS) $(ENABLE_RUBY) $(ENABLE_SHARED_WORKERS) $(ENABLE_SVG) $(ENABLE_SVG_ANIMATION) $(ENABLE_SVG_AS_IMAGE) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_SVG_FOREIGN_OBJECT) $(ENABLE_SVG_USE) $(ENABLE_VIDEO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WML) $(ENABLE_WORKERS) $(ENABLE_XPATH) $(ENABLE_XSLT);
FEATURE_DEFINES = $(ENABLE_3D_RENDERING) $(ENABLE_CHANNEL_MESSAGING) $(ENABLE_DATABASE) $(ENABLE_DATAGRID) $(ENABLE_DOM_STORAGE) $(ENABLE_EVENTSOURCE) $(ENABLE_FILTERS) $(ENABLE_GEOLOCATION) $(ENABLE_ICONDATABASE) $(ENABLE_JAVASCRIPT_DEBUGGER) $(ENABLE_NOTIFICATIONS) $(ENABLE_OFFLINE_WEB_APPLICATIONS) $(ENABLE_RUBY) $(ENABLE_SHARED_WORKERS) $(ENABLE_SVG) $(ENABLE_SVG_ANIMATION) $(ENABLE_SVG_AS_IMAGE) $(ENABLE_SVG_DOM_OBJC_BINDINGS) $(ENABLE_SVG_FONTS) $(ENABLE_SVG_FOREIGN_OBJECT) $(ENABLE_SVG_USE) $(ENABLE_VIDEO) $(ENABLE_WEB_SOCKETS) $(ENABLE_WML) $(ENABLE_WORKERS) $(ENABLE_XPATH) $(ENABLE_XSLT);
2009-08-14 Adam Bergkvist <adam.bergkvist@ericsson.com>
Reviewed by Sam Weinig.
Tests for EventSource.
https://bugs.webkit.org/show_bug.cgi?id=14997
* fast/eventsource: Added.
* fast/eventsource/eventsource-attribute-listeners-expected.txt: Added.
* fast/eventsource/eventsource-attribute-listeners.html: Added.
* fast/eventsource/eventsource-constructor-expected.txt: Added.
* fast/eventsource/eventsource-constructor.html: Added.
* http/tests/eventsource: Added.
* http/tests/eventsource/eventsource-bad-mime-type-expected.txt: Added.
* http/tests/eventsource/eventsource-bad-mime-type.html: Added.
* http/tests/eventsource/eventsource-parse-event-stream-expected.txt: Added.
* http/tests/eventsource/eventsource-parse-event-stream.html: Added.
* http/tests/eventsource/eventsource-reconnect-expected.txt: Added.
* http/tests/eventsource/eventsource-reconnect.html: Added.
* http/tests/eventsource/eventsource-status-code-states-expected.txt: Added.
* http/tests/eventsource/eventsource-status-code-states.html: Added.
* http/tests/eventsource/resources: Added.
* http/tests/eventsource/resources/bad-mime-type.asis: Added.
* http/tests/eventsource/resources/event-stream.php: Added.
* http/tests/eventsource/resources/reconnect.php: Added.
* http/tests/eventsource/resources/simple-event-stream.asis: Added.
* http/tests/eventsource/resources/status-codes.php: Added.
* http/tests/eventsource/workers: Added.
* http/tests/eventsource/workers/eventsource-simple-expected.txt: Added.
* http/tests/eventsource/workers/eventsource-simple.html: Added.
* http/tests/eventsource/workers/resources: Added.
* http/tests/eventsource/workers/resources/simple-worker.js: Added.
(es.onmessage):
(es.onerror):
2009-08-14 Jon Honeycutt <jhoneycutt@apple.com>
Remove two tests from the skipped list that don't exist.
......
......@@ -857,6 +857,15 @@ window.EventException [object EventExceptionConstructor]
window.EventException.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventException.prototype [object EventExceptionPrototype]
window.EventException.prototype.UNSPECIFIED_EVENT_TYPE_ERR [number]
window.EventSource [object EventSourceContructor]
window.EventSource.prototype [object EventSourcePrototype]
window.EventSource.prototype.CLOSED [number]
window.EventSource.prototype.CONNECTING [number]
window.EventSource.prototype.OPEN [number]
window.EventSource.prototype.addEventListener [function]
window.EventSource.prototype.close [function]
window.EventSource.prototype.dispatchEvent [function]
window.EventSource.prototype.removeEventListener [function]
window.File [object FileConstructor]
window.File.prototype [object FilePrototype]
window.FileList [object FileListConstructor]
......
......@@ -77,6 +77,7 @@ PASS DataGridColumnListConstructor from inner.document.activeElement.childNodes.
PASS DataGridColumnListPrototype from inner.document.activeElement.childNodes.14.columns.__proto__
PASS DocumentPrototype from inner.document.__proto__.__proto__
PASS ElementPrototype from inner.document.activeElement.lastElementChild.__proto__.__proto__
PASS EventSourceContructor from inner.EventSource
FAIL Function from inner.document.location.pathname.constructor
PASS HTMLAnchorElement from inner.document.activeElement.firstElementChild
PASS HTMLAnchorElementConstructor from inner.document.activeElement.firstElementChild.constructor
......
......@@ -77,6 +77,8 @@ PASS inner.Event.isInner is true
PASS inner.Event.constructor.isInner is true
PASS inner.EventException.isInner is true
PASS inner.EventException.constructor.isInner is true
PASS inner.EventSource.isInner is true
PASS inner.EventSource.constructor.isInner is true
PASS inner.File.isInner is true
PASS inner.File.constructor.isInner is true
PASS inner.FileList.isInner is true
......
Test EventSource attribute listener functionality. Should print a series of PASS messages followed by DONE.
PASS: attribute listeners are initially null
PASS: setting and getting attribute listener works
PASS: resetting attribute listener works
PASS: dispatching event on an EventSource triggers attribute listener
DONE
<html>
<body>
<p>Test EventSource attribute listener 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.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var es = new EventSource("eventsource");
if (es.onopen == null && es.onmessage == null && es.onerror == null)
log("PASS: attribute listeners are initially null");
else
log("FAIL: attribute listeners are not null initially");
var a = function () {};
es.onopen = a;
if (es.onopen == a)
log("PASS: setting and getting attribute listener works");
else
log("FAIL: setting/getting attribute listener does not work");
var b = function () {};
es.onopen = b;
if (es.onopen == b)
log("PASS: resetting attribute listener works");
else
log("FAIL: resetting attribute listener does not work");
var flag = false;
es.onmessage = function (e) { flag = (e.data == "hello"); };
var evt = document.createEvent("MessageEvent");
evt.initMessageEvent("message", false, false, "hello", null, null, null, null);
es.dispatchEvent(evt);
if (flag) {
log("PASS: dispatching event on an EventSource triggers attribute listener");
log("DONE");
}
else
log("FAIL: dispatching event on an EventSource does not trigger attribute listener");
if (window.layoutTestController)
layoutTestController.notifyDone();
</script>
</body>
</html>
Test EventSource constructor functionality. Should print a series of PASS messages followed by DONE.
PASS: missing argument to EventSource constructor resulted in an exception (SyntaxError: Not enough arguments)
PASS: passing an empty string to the EventSource constructor resulted in an exception (Error: SYNTAX_ERR: DOM Exception 12)
PASS: passing an invalid URL to the EventSource constructor resulted in an exception (Error: SYNTAX_ERR: DOM Exception 12)
DONE
<html>
<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.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
try {
new EventSource();
log("FAIL: no exception when trying to construct an EventSource without argument");
}
catch (ex) {
log("PASS: missing argument to EventSource constructor resulted in an exception (" + ex + ")");
}
try {
new EventSource("");
log("FAIL: no exception when passing an empty string to the EventSource constructor");
}
catch (ex) {
log("PASS: passing an empty string to the EventSource constructor resulted in an exception (" + ex + ")");
}
try {
new EventSource("http://webserver:eighty/");
log("FAIL: no exception when passing an invalid URL to the EventSource constructor");
}
catch (ex) {
log("PASS: passing an invalid URL to the EventSource constructor resulted in an exception (" + ex + ")");
log("DONE");
}
if (window.layoutTestController)
layoutTestController.notifyDone();
</script>
</body>
</html>
Test EventSource with an event-stream with incorrect mime-type.
PASS
<html>
<body>
<p>Test EventSource with an event-stream with incorrect mime-type.</p>
<div id="result"></div>
<script>
function log(msg) {
document.getElementById("result").innerHTML += msg + "<br>";
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var es = new EventSource("resources/bad-mime-type.asis");
es.onopen = function (evt) {
log("FAIL: got unexpected open event");
end();
};
es.onmessage = function (evt) {
log("FAIL: got unexpected message event");
end();
};
es.onerror = function () {
if (es.readyState == es.CLOSED)
log("PASS");
else
log("FAIL: invalid state");
end();
};
function end() {
es.close();
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
Test EventSource text/event-stream parsing. Should print a series of PASS messages followed by DONE.
PASS: got open event
PASS: received event with data "simple"
PASS: received event with data spanning multiple lines
PASS: received event and lastEventId is "1"
PASS: received event and lastEventId is still "1"
PASS: received event and lastEventId has been cleared
PASS: got open event from server
PASS: received event and the event name has been reset
PASS: received event with data that contains a colon and a carriage return
DONE
<html>
<body>
<p>Test EventSource text/event-stream parsing. 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.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var count = 0;
var es = new EventSource("resources/event-stream.php");
es.onopen = function (evt) {
if (!evt.data)
log("PASS: got open event");
else
log("PASS: got open event from server");
};
es.onmessage = function (evt) {
switch(count++) {
case 0:
if (evt.data == "simple")
log("PASS: received event with data \"simple\"");
break;
case 1:
if (evt.data == "spanning\nmultiple\n\nlines\n")
log("PASS: received event with data spanning multiple lines");
break;
case 2:
if (evt.data == "id is 1" && evt.lastEventId == "1")
log("PASS: received event and lastEventId is \"1\"");
break
case 3:
if (evt.data == "id is still 1" && evt.lastEventId == "1")
log("PASS: received event and lastEventId is still \"1\"");
break;
case 4:
if (evt.data == "no id" && evt.lastEventId == "")
log("PASS: received event and lastEventId has been cleared");
break;
case 5:
if (evt.data == "a message event with the name \"message\"")
log("PASS: received event and the event name has been reset");
break;
case 6:
if (evt.data == "a line ending with crlf\na line with a : (colon)\na line with a \r (carriage return)")
log("PASS: received event with data that contains a colon and a carriage return");
break;
default:
log("FAIL: got unexpected event");
es.close();
}
};
es.onerror = function () {
es.close();
if (count != 7)
log("FAIL: got unexpected error event");
else
log("DONE");
if (window.layoutTestController)
layoutTestController.notifyDone();
};
</script>
</body>
</html>
Test EventSource reconnect after end of event stream. Should print a series of PASS messages followed by DONE.
PASS: state is CONNECTING
PASS: state is OPEN
PASS: got lastEventId "77"
PASS: state is CONNECTING
PASS: state is OPEN
PASS: Last-Event-ID header was correct
PASS: state is CLOSED
DONE
<html>
<body>
<p>Test EventSource reconnect after end of event stream. 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>";
}
var stateNames = ["CONNECTING", "OPEN", "CLOSED"];
for (var i in stateNames)
eval("var " + stateNames[i] + " = " + i);
var retryTimeout;
function checkReadyState(es, desiredState) {
var currState = es.readyState;
if (currState == desiredState)
log("PASS: state is " + stateNames[desiredState]);
else
log("FAIL: bad state (" + stateNames[currState] + ", should be " + stateNames[desiredState] + ")");
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var errCount = 0;
var es = new EventSource("resources/reconnect.php");
checkReadyState(es, CONNECTING);
es.onopen = function (evt) {
checkReadyState(es, OPEN);
};
es.onmessage = function (evt) {
if (!errCount) {
if (evt.lastEventId == "77")
log("PASS: got lastEventId \"77\"");
else
log("FAIL: unexpected lastEventId \"" + evt.lastEventId + "\"");
} else {
if (evt.data == "77")
log("PASS: Last-Event-ID header was correct");
else
log("FAIL: Last-Event-ID header was incorrect/missing");
}
};
es.onerror = function () {
errCount++;
if (errCount < 2) {
checkReadyState(es, CONNECTING);
retryTimeout = setTimeout(end, 1000);
return;
}
clearTimeout(retryTimeout);
retryTimeout = null;
end();
};
function end() {
es.close();
if (retryTimeout)
log("FAIL: did not reconnect in time");
else {
checkReadyState(es, CLOSED);
log("DONE");
}
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
Test EventSource states for different status codes. Should print a series of PASS messages followed by DONE.
PASS: status code 200 resulted in states CONNECTING, OPEN, OPEN, CONNECTING, CLOSED
PASS: status code 204 resulted in states CONNECTING, CONNECTING, CLOSED
PASS: status code 205 resulted in states CONNECTING, CONNECTING, CLOSED
PASS: status code 202 resulted in states CONNECTING, CONNECTING, CLOSED
PASS: status code 301 resulted in states CONNECTING, OPEN, OPEN, CONNECTING, CLOSED
PASS: status code 302 resulted in states CONNECTING, OPEN, OPEN, CONNECTING, CLOSED
PASS: status code 303 resulted in states CONNECTING, OPEN, OPEN, CONNECTING, CLOSED
PASS: status code 307 resulted in states CONNECTING, OPEN, OPEN, CONNECTING, CLOSED
PASS: status code 404 resulted in states CONNECTING, CLOSED, CLOSED
DONE
<html>
<body>
<p>Test EventSource states for different status codes. 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>";
}
function arrayCompare(a1, a2) {
if (a1.length != a2.length)
return false;
for (var i = 0; i < a1.length; i++)
if (a1[i] != a2[i])
return false;
return true;
}
var stateNames = ["CONNECTING", "OPEN", "CLOSED"];
for (var i in stateNames)
eval("var " + stateNames[i] + " = " + i);
var tests = [{"code": 200, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING, CLOSED]},
{"code": 204, "expectedStates": [CONNECTING,,, CONNECTING, CLOSED]},
{"code": 205, "expectedStates": [CONNECTING,,, CONNECTING, CLOSED]},
{"code": 202, "expectedStates": [CONNECTING,,, CONNECTING, CLOSED]}, // other 2xx
{"code": 301, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING, CLOSED]},
{"code": 302, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING, CLOSED]},
{"code": 303, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING, CLOSED]},
{"code": 307, "expectedStates": [CONNECTING, OPEN, OPEN, CONNECTING, CLOSED]},
{"code": 404, "expectedStates": [CONNECTING,,, CLOSED, CLOSED]}]; // any other
var count = 0;
function runTest() {
if (count >= tests.length) {
log("DONE");
if (window.layoutTestController)
layoutTestController.notifyDone();
return;
}
var states = [];
var es = new EventSource("resources/status-codes.php?status-code=" + tests[count].code);
states[0] = es.readyState;
es.onopen = function () {
states[1] = es.readyState;
};
es.onmessage = function (evt) {
states[2] = es.readyState;
};
es.onerror = function () {
states[3] = es.readyState;
es.close();
states[4] = es.readyState;
var result = arrayCompare(states, tests[count].expectedStates) ? "PASS" : "FAIL";
result += ": status code " + tests[count].code + " resulted in states ";
for (var i in states)
result += (i != 0 ? ", " : "") + stateNames[states[i]];
log(result);
setTimeout(runTest, 0);
count++;
};
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
runTest();
</script>
</body>
</html>
Content-Type: text/bogus
data: should not trigger an event
<?php
header("Content-Type: text/event-stream");
?>
: a comment (ignored)
this line will be ignored since there is no field and the line itself is not a field
field: an unknown field that will be ignored
:another commment
data : this line will be ignored since there is a space after data
data
data:
data
: no dispatch since data buffer is empty
data: simple
data: spanning
data:multiple
data
data: lines
data
id: 1
data: id is 1
data: id is still 1
id
data: no id
event: open
data: a message event with the name "open"
<?php flush(); echo "da"; flush(); ?>
ta: a message event with the name "message"
<?php echo "data: a line ending with crlf\r\n"; ?>
data: a line with a : (colon)
<?php echo "data: a line with a \r (carriage return)\n"; ?>
retry: 10000
: reconnection time set to 10 seconds
retry: one thousand