Skip to content

Commit

Permalink
Dispatch error event when link elements get invalid response
Browse files Browse the repository at this point in the history
  • Loading branch information
askeing committed Apr 28, 2016
1 parent a44ebd5 commit 80fd186
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions components/script/dom/htmllinkelement.rs
Expand Up @@ -15,11 +15,14 @@ use dom::bindings::refcounted::Trusted;
use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::{AttributeMutation, Element, ElementCreator};
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use hyper::header::ContentType;
use hyper::mime::{Mime, TopLevel, SubLevel};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use layout_interface::{LayoutChan, Msg};
Expand Down Expand Up @@ -273,6 +276,13 @@ impl PreInvoke for StylesheetContext {}
impl AsyncResponseListener for StylesheetContext {
fn headers_available(&mut self, metadata: Result<Metadata, NetworkError>) {
self.metadata = metadata.ok();
let content_type = self.metadata.clone().and_then(|meta| meta.content_type);
match content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Css, _))) => {},
_ => {
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
}
}
}

fn data_available(&mut self, payload: Vec<u8>) {
Expand All @@ -281,6 +291,13 @@ impl AsyncResponseListener for StylesheetContext {
}

fn response_complete(&mut self, _status: Result<(), NetworkError>) {
match _status {
Err(_) => {
self.elem.root().upcast::<EventTarget>().fire_simple_event("error");
return;
},
_ => {}
};
let data = mem::replace(&mut self.data, vec!());
let metadata = match self.metadata.take() {
Some(meta) => meta,
Expand Down
@@ -1,6 +1,6 @@
[link-style-error-01.html]
type: testharness
expected: TIMEOUT
expected: OK
[Should get an error event for a text/plain response.]
expected: TIMEOUT
expected: PASS

0 comments on commit 80fd186

Please sign in to comment.