Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EventSource and update test expectations #9029

Merged
merged 1 commit into from Jan 6, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement EventSource and update test expectations

  • Loading branch information
KiChjang committed Jan 6, 2016
commit 1d62db405eea5fab6c48cd291f9f7f7418b0ec25
@@ -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
}
}
@@ -246,6 +246,7 @@ pub mod element;
pub mod errorevent;
pub mod event;
pub mod eventdispatcher;
pub mod eventsource;
pub mod eventtarget;
pub mod file;
pub mod filelist;
@@ -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;
};
@@ -9,6 +9,8 @@ skip: true
skip: false
[DOMEvents]
skip: false
[eventsource]
skip: false
[FileAPI]
skip: false
[html]
@@ -0,0 +1,6 @@
[eventsource-close.htm]
type: testharness
expected: TIMEOUT
[dedicated worker - EventSource: close()]
expected: TIMEOUT

@@ -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

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

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

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

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

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

[EventSource: close(), test events]
expected: TIMEOUT

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

@@ -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

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

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

@@ -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

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

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

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

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

[EventSource: reconnection, test reconnection events]
expected: TIMEOUT

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

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

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

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

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

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

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

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

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

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

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

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

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.