Implement EventSource and update test expectations

This commit is contained in:
Keith Yeung 2015-12-12 22:06:21 -08:00
parent e3dd36f0f3
commit 1d62db405e
58 changed files with 543 additions and 51 deletions

View file

@ -0,0 +1,102 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::EventSourceBinding::{EventSourceInit, EventSourceMethods, Wrap};
use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
use dom::bindings::reflector::reflect_dom_object;
use dom::eventtarget::EventTarget;
use std::cell::Cell;
use url::Url;
use util::str::DOMString;
#[derive(JSTraceable, PartialEq, Copy, Clone, Debug, HeapSizeOf)]
enum EventSourceReadyState {
Connecting = 0,
Open = 1,
Closed = 2
}
#[dom_struct]
pub struct EventSource {
eventtarget: EventTarget,
url: Url,
ready_state: Cell<EventSourceReadyState>,
with_credentials: bool,
last_event_id: DOMRefCell<DOMString>
}
impl EventSource {
fn new_inherited(url: Url, with_credentials: bool) -> EventSource {
EventSource {
eventtarget: EventTarget::new_inherited(),
url: url,
ready_state: Cell::new(EventSourceReadyState::Connecting),
with_credentials: with_credentials,
last_event_id: DOMRefCell::new(DOMString::from(""))
}
}
fn new(global: GlobalRef, url: Url, with_credentials: bool) -> Root<EventSource> {
reflect_dom_object(box EventSource::new_inherited(url, with_credentials), global, Wrap)
}
pub fn Constructor(global: GlobalRef,
url_str: DOMString,
event_source_init: &EventSourceInit) -> Fallible<Root<EventSource>> {
// Steps 1-2
let base_url = global.get_url();
let url = match base_url.join(&*url_str) {
Ok(u) => u,
Err(_) => return Err(Error::Syntax)
};
// Step 3
let event_source = EventSource::new(global, url, event_source_init.withCredentials);
// Step 4
// Step 5
// Step 6
// Step 7
// Step 8
// Step 9
// Step 10
// Step 11
Ok(event_source)
// Step 12
}
}
impl EventSourceMethods for EventSource {
// https://html.spec.whatwg.org/multipage/#handler-eventsource-onopen
event_handler!(open, GetOnopen, SetOnopen);
// https://html.spec.whatwg.org/multipage/#handler-eventsource-onmessage
event_handler!(message, GetOnmessage, SetOnmessage);
// https://html.spec.whatwg.org/multipage/#handler-eventsource-onerror
event_handler!(error, GetOnerror, SetOnerror);
// https://html.spec.whatwg.org/multipage/#dom-eventsource-url
fn Url(&self) -> DOMString {
DOMString::from(self.url.serialize())
}
// https://html.spec.whatwg.org/multipage/#dom-eventsource-withcredentials
fn WithCredentials(&self) -> bool {
self.with_credentials
}
// https://html.spec.whatwg.org/multipage/#dom-eventsource-readystate
fn ReadyState(&self) -> u16 {
self.ready_state.get() as u16
}
// https://html.spec.whatwg.org/multipage/#dom-eventsource-close
fn Close(&self) {
self.ready_state.set(EventSourceReadyState::Closed);
// TODO: Terminate ongoing fetch
}
}

View file

@ -246,6 +246,7 @@ pub mod element;
pub mod errorevent; pub mod errorevent;
pub mod event; pub mod event;
pub mod eventdispatcher; pub mod eventdispatcher;
pub mod eventsource;
pub mod eventtarget; pub mod eventtarget;
pub mod file; pub mod file;
pub mod filelist; pub mod filelist;

View file

@ -0,0 +1,31 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is:
* https://html.spec.whatwg.org/multipage/#eventsource
*/
[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict),
/*Exposed=(Window,Worker)*/]
interface EventSource : EventTarget {
readonly attribute DOMString url;
readonly attribute boolean withCredentials;
// ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSED = 2;
readonly attribute unsigned short readyState;
// networking
attribute EventHandler onopen;
attribute EventHandler onmessage;
attribute EventHandler onerror;
void close();
};
dictionary EventSourceInit {
boolean withCredentials = false;
};

View file

@ -9,6 +9,8 @@ skip: true
skip: false skip: false
[DOMEvents] [DOMEvents]
skip: false skip: false
[eventsource]
skip: false
[FileAPI] [FileAPI]
skip: false skip: false
[html] [html]

View file

@ -0,0 +1,6 @@
[eventsource-close.htm]
type: testharness
expected: TIMEOUT
[dedicated worker - EventSource: close()]
expected: TIMEOUT

View file

@ -0,0 +1,20 @@
[eventsource-constructor-non-same-origin.htm]
type: testharness
[dedicated worker - EventSource: constructor (act as if there is a network error) (http://example.not/)]
expected: TIMEOUT
[dedicated worker - EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: TIMEOUT
[dedicated worker - EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: TIMEOUT
[dedicated worker - EventSource: constructor (act as if there is a network error) (about:blank)]
expected: TIMEOUT
[dedicated worker - EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: TIMEOUT
[dedicated worker - EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: TIMEOUT

View file

@ -0,0 +1,5 @@
[eventsource-eventtarget.htm]
type: testharness
[dedicated worker - EventSource: addEventListener()]
expected: FAIL

View file

@ -0,0 +1,6 @@
[eventsource-onmesage.htm]
type: testharness
expected: TIMEOUT
[dedicated worker - EventSource: onmessage]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-onopen.htm]
type: testharness
expected: TIMEOUT
[dedicated worker - EventSource: onopen (announcing the connection)]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[event-data.html]
type: testharness
expected: TIMEOUT
[EventSource: lines and data parsing]
expected: TIMEOUT

View file

@ -0,0 +1,9 @@
[eventsource-close.htm]
type: testharness
expected: TIMEOUT
[EventSource: close()]
expected: TIMEOUT
[EventSource: close(), test events]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-constructor-document-domain.htm]
type: testharness
expected: TIMEOUT
[EventSource: document.domain]
expected: TIMEOUT

View file

@ -0,0 +1,20 @@
[eventsource-constructor-non-same-origin.htm]
type: testharness
[EventSource: constructor (act as if there is a network error) (http://example.not/)]
expected: TIMEOUT
[EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: TIMEOUT
[EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: TIMEOUT
[EventSource: constructor (act as if there is a network error) (about:blank)]
expected: TIMEOUT
[EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: TIMEOUT
[EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-constructor-stringify.htm]
type: testharness
expected: TIMEOUT
[EventSource: stringify argument, object]
expected: TIMEOUT

View file

@ -0,0 +1,5 @@
[eventsource-constructor-url-multi-window.htm]
type: testharness
[EventSource: resolving URLs]
expected: FAIL

View file

@ -0,0 +1,21 @@
[eventsource-cross-origin.htm]
type: testharness
expected: TIMEOUT
[EventSource: cross-origin basic use]
expected: TIMEOUT
[EventSource: cross-origin redirect use]
expected: TIMEOUT
[EventSource: cross-origin redirect use recon]
expected: TIMEOUT
[EventSource: cross-origin allow-origin: http://example.org should fail]
expected: TIMEOUT
[EventSource: cross-origin allow-origin:'' should fail]
expected: TIMEOUT
[EventSource: cross-origin No allow-origin should fail]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-eventtarget.htm]
type: testharness
expected: TIMEOUT
[EventSource: addEventListener()]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-onmessage.htm]
type: testharness
expected: TIMEOUT
[EventSource: onmessage]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[eventsource-onopen.htm]
type: testharness
expected: TIMEOUT
[EventSource: onopen (announcing the connection)]
expected: TIMEOUT

View file

@ -0,0 +1,9 @@
[eventsource-reconnect.htm]
type: testharness
expected: TIMEOUT
[EventSource: reconnection 200]
expected: TIMEOUT
[EventSource: reconnection, test reconnection events]
expected: TIMEOUT

View file

@ -0,0 +1,5 @@
[eventsource-request-cancellation.htm]
type: testharness
[EventSource: request cancellation]
expected: FAIL

View file

@ -0,0 +1,6 @@
[format-bom-2.htm]
type: testharness
expected: TIMEOUT
[EventSource: Double BOM]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-bom.htm]
type: testharness
expected: TIMEOUT
[EventSource: BOM]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-comments.htm]
type: testharness
expected: TIMEOUT
[EventSource: comment fest]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-data-before-final-empty-line.htm]
type: testharness
expected: TIMEOUT
[EventSource: a data before final empty line]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-data.htm]
type: testharness
expected: TIMEOUT
[EventSource: data field parsing]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-event-empty.htm]
type: testharness
expected: TIMEOUT
[EventSource: empty "event" field]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-event.htm]
type: testharness
expected: TIMEOUT
[EventSource: custom event name]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-id-2.htm]
type: testharness
expected: TIMEOUT
[EventSource: Last-Event-ID (2)]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-id.htm]
type: testharness
expected: TIMEOUT
[EventSource: Last-Event-ID]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-parsing.htm]
type: testharness
expected: TIMEOUT
[EventSource: field parsing]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-retry-bogus.htm]
type: testharness
expected: TIMEOUT
[EventSource: "retry" field (bogus)]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-retry-empty.htm]
type: testharness
expected: TIMEOUT
[EventSource: empty retry field]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-retry.htm]
type: testharness
expected: TIMEOUT
[EventSource: "retry" field]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-field-unknown.htm]
type: testharness
expected: TIMEOUT
[EventSource: unknown fields and parsing fun]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-leading-space.htm]
type: testharness
expected: TIMEOUT
[EventSource: leading space]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-mime-bogus.htm]
type: testharness
expected: TIMEOUT
[EventSource: bogus MIME type]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-mime-trailing-semicolon.htm]
type: testharness
expected: TIMEOUT
[EventSource: MIME type with trailing ;]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-mime-valid-bogus.htm]
type: testharness
expected: TIMEOUT
[EventSource: incorrect valid MIME type]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-newlines.htm]
type: testharness
expected: TIMEOUT
[EventSource: newline fest]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-null-character.html]
type: testharness
expected: TIMEOUT
[EventSource: null character in response]
expected: TIMEOUT

View file

@ -0,0 +1,6 @@
[format-utf-8.htm]
type: testharness
expected: TIMEOUT
[EventSource: always UTF-8]
expected: TIMEOUT

View file

@ -0,0 +1,11 @@
[interfaces.html]
type: testharness
[EventSource interface: existence and properties of interface object]
expected: FAIL
[EventSource interface: existence and properties of interface prototype object]
expected: FAIL
[Stringification of new EventSource("http://foo")]
expected: FAIL

View file

@ -0,0 +1,6 @@
[request-accept.htm]
type: testharness
expected: TIMEOUT
[EventSource: Accept header]
expected: TIMEOUT

View file

@ -0,0 +1,9 @@
[request-cache-control.htm]
type: testharness
expected: TIMEOUT
[EventSource: Cache-Control]
expected: TIMEOUT
[EventSource: Cache-Control 1]
expected: TIMEOUT

View file

@ -0,0 +1,12 @@
[request-credentials.htm]
type: testharness
expected: TIMEOUT
[EventSource: credentials: credentials enabled]
expected: TIMEOUT
[EventSource: credentials: credentials disabled]
expected: TIMEOUT
[EventSource: credentials: credentials default]
expected: TIMEOUT

View file

@ -0,0 +1,15 @@
[request-redirect.htm]
type: testharness
expected: TIMEOUT
[EventSource: redirect (301)]
expected: TIMEOUT
[EventSource: redirect (302)]
expected: TIMEOUT
[EventSource: redirect (303)]
expected: TIMEOUT
[EventSource: redirect (307)]
expected: TIMEOUT

View file

@ -0,0 +1,24 @@
[request-status-error.htm]
type: testharness
expected: TIMEOUT
[EventSource: incorrect HTTP status code (204)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (205)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (210)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (299)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (404)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (410)]
expected: TIMEOUT
[EventSource: incorrect HTTP status code (503)]
expected: TIMEOUT

View file

@ -0,0 +1,5 @@
[eventsource-close.htm]
type: testharness
[shared worker - EventSource: close()]
expected: FAIL

View file

@ -0,0 +1,20 @@
[eventsource-constructor-non-same-origin.htm]
type: testharness
[shared worker - EventSource: constructor (act as if there is a network error) (http://example.not)]
expected: FAIL
[shared worker - EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: FAIL
[shared worker - EventSource: constructor (act as if there is a network error) (ftp://example.not)]
expected: FAIL
[shared worker - EventSource: constructor (act as if there is a network error) (about:blank)]
expected: FAIL
[shared worker - EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: FAIL
[shared worker - EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-constructor-url-bogus.htm]
type: testharness
[shared worker - EventSource: constructor (invalid URL)]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-eventtarget.htm]
type: testharness
[shared worker - EventSource: addEventListener()]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-onmesage.htm]
type: testharness
[shared worker - EventSource: onmessage]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-onopen.htm]
type: testharness
[shared worker - EventSource: onopen (announcing the connection)]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-prototype.htm]
type: testharness
[shared worker - EventSource: prototype et al]
expected: FAIL

View file

@ -0,0 +1,5 @@
[eventsource-url.htm]
type: testharness
[shared worker - EventSource: url]
expected: FAIL

View file

@ -7755,54 +7755,6 @@
[EventSource interface: existence and properties of interface object] [EventSource interface: existence and properties of interface object]
expected: FAIL expected: FAIL
[EventSource interface object length]
expected: FAIL
[EventSource interface: existence and properties of interface prototype object]
expected: FAIL
[EventSource interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[EventSource interface: attribute url]
expected: FAIL
[EventSource interface: attribute withCredentials]
expected: FAIL
[EventSource interface: constant CONNECTING on interface object]
expected: FAIL
[EventSource interface: constant CONNECTING on interface prototype object]
expected: FAIL
[EventSource interface: constant OPEN on interface object]
expected: FAIL
[EventSource interface: constant OPEN on interface prototype object]
expected: FAIL
[EventSource interface: constant CLOSED on interface object]
expected: FAIL
[EventSource interface: constant CLOSED on interface prototype object]
expected: FAIL
[EventSource interface: attribute readyState]
expected: FAIL
[EventSource interface: attribute onopen]
expected: FAIL
[EventSource interface: attribute onmessage]
expected: FAIL
[EventSource interface: attribute onerror]
expected: FAIL
[EventSource interface: operation close()]
expected: FAIL
[WebSocket interface: existence and properties of interface object] [WebSocket interface: existence and properties of interface object]
expected: FAIL expected: FAIL
@ -9429,9 +9381,6 @@
[ImageBitmap interface object name] [ImageBitmap interface object name]
expected: FAIL expected: FAIL
[EventSource interface object name]
expected: FAIL
[MessageChannel interface object name] [MessageChannel interface object name]
expected: FAIL expected: FAIL

View file

@ -99,6 +99,7 @@ var interfaceNamesInGlobalScope = [
"Element", "Element",
"ErrorEvent", "ErrorEvent",
"Event", "Event",
"EventSource",
"EventTarget", "EventTarget",
"File", "File",
"FileList", "FileList",