tests for devtools integration with network requests/responses

This commit is contained in:
Prabhjyot Singh Sodhi 2015-09-01 22:55:57 +05:30
parent e04c2c78ee
commit 920bb5e4b8
8 changed files with 136 additions and 23 deletions

View file

@ -9,13 +9,14 @@
extern crate hyper;
use actor::{Actor, ActorMessageStatus, ActorRegistry};
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
use hyper::header::Headers;
use hyper::http::RawStatus;
use hyper::method::Method;
use protocol::JsonPacketStream;
use rustc_serialize::json;
use std::net::TcpStream;
use url::Url;
struct HttpRequest {
url: String,
@ -125,18 +126,18 @@ impl NetworkEventActor {
}
}
pub fn add_request(&mut self, url: Url, method: Method, headers: Headers, body: Option<Vec<u8>>) {
self.request.url = url.serialize();
self.request.method = method.clone();
self.request.headers = headers.clone();
self.request.body = body;
pub fn add_request(&mut self, request: DevtoolsHttpRequest) {
self.request.url = request.url.serialize();
self.request.method = request.method.clone();
self.request.headers = request.headers.clone();
self.request.body = request.body;
}
pub fn add_response(&mut self, headers: Option<Headers>, status: Option<RawStatus>, body: Option<Vec<u8>>) {
self.response.headers = headers.clone();
self.response.status = status.clone();
self.response.body = body.clone();
}
pub fn add_response(&mut self, response: DevtoolsHttpResponse) {
self.response.headers = response.headers.clone();
self.response.status = response.status.clone();
self.response.body = response.body.clone();
}
pub fn event_actor(&self) -> EventActor {
// TODO: Send the correct values for startedDateTime, isXHR, private

View file

@ -335,9 +335,9 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let actor = actors.find_mut::<NetworkEventActor>(&netevent_actor_name);
match network_event {
NetworkEvent::HttpRequest(url, method, headers, body) => {
NetworkEvent::HttpRequest(httprequest) => {
//Store the request information in the actor
actor.add_request(url, method, headers, body);
actor.add_request(httprequest);
//Send a networkEvent message to the client
let msg = NetworkEventMsg {
@ -349,9 +349,9 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
stream.write_json_packet(&msg);
}
}
NetworkEvent::HttpResponse(headers, status, body) => {
NetworkEvent::HttpResponse(httpresponse) => {
//Store the response information in the actor
actor.add_response(headers, status, body);
actor.add_response(httpresponse);
//Send a networkEventUpdate (responseStart) to the client
let msg = NetworkEventUpdateMsg {