mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove a test for the CoreResourceMsg::Cancel message.
This commit is contained in:
parent
15e8f4f0d4
commit
ce24edc2b3
1 changed files with 1 additions and 74 deletions
|
@ -3,36 +3,19 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use msg::constellation_msg::PipelineId;
|
|
||||||
use net::resource_thread::new_core_resource_thread;
|
use net::resource_thread::new_core_resource_thread;
|
||||||
use net_traits::{CoreResourceMsg, LoadConsumer, LoadContext, LoadData};
|
use net_traits::CoreResourceMsg;
|
||||||
use net_traits::{LoadOrigin, NetworkError, ProgressMsg, ReferrerPolicy};
|
|
||||||
use net_traits::hosts::{host_replacement, parse_hostsfile};
|
use net_traits::hosts::{host_replacement, parse_hostsfile};
|
||||||
use profile_traits::time::ProfilerChan;
|
use profile_traits::time::ProfilerChan;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
|
|
||||||
fn ip(s: &str) -> IpAddr {
|
fn ip(s: &str) -> IpAddr {
|
||||||
s.parse().unwrap()
|
s.parse().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResourceTest;
|
|
||||||
|
|
||||||
impl LoadOrigin for ResourceTest {
|
|
||||||
fn referrer_url(&self) -> Option<ServoUrl> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
fn pipeline_id(&self) -> Option<PipelineId> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_exit() {
|
fn test_exit() {
|
||||||
let (tx, _rx) = ipc::channel().unwrap();
|
let (tx, _rx) = ipc::channel().unwrap();
|
||||||
|
@ -176,59 +159,3 @@ fn test_replace_hosts() {
|
||||||
let url = ServoUrl::parse("http://a.foo.bar.com").unwrap();
|
let url = ServoUrl::parse("http://a.foo.bar.com").unwrap();
|
||||||
assert_eq!(host_replacement(&host_table, &url).host_str().unwrap(), "a.foo.bar.com");
|
assert_eq!(host_replacement(&host_table, &url).host_str().unwrap(), "a.foo.bar.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_cancelled_listener() {
|
|
||||||
use std::io::Write;
|
|
||||||
use std::net::TcpListener;
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
// http_loader always checks for headers in the response
|
|
||||||
let header = vec!["HTTP/1.1 200 OK",
|
|
||||||
"Server: test-server",
|
|
||||||
"Content-Type: text/plain",
|
|
||||||
"\r\n"];
|
|
||||||
let body = vec!["Yay!", "We're doomed!"];
|
|
||||||
|
|
||||||
// Setup a TCP server to which requests are made
|
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
||||||
let port = listener.local_addr().unwrap().port();
|
|
||||||
let (body_sender, body_receiver) = channel();
|
|
||||||
thread::spawn(move || {
|
|
||||||
if let Ok((mut stream, _)) = listener.accept() {
|
|
||||||
// immediately stream the headers once the connection has been established
|
|
||||||
let _ = stream.write(header.join("\r\n").as_bytes());
|
|
||||||
// wait for the main thread to send the body, so as to ensure that we're
|
|
||||||
// doing everything sequentially
|
|
||||||
let body_vec: Vec<&str> = body_receiver.recv().unwrap();
|
|
||||||
let _ = stream.write(body_vec.join("\r\n").as_bytes());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let (tx, _rx) = ipc::channel().unwrap();
|
|
||||||
let (exit_sender, exit_receiver) = ipc::channel().unwrap();
|
|
||||||
let (resource_thread, _) = new_core_resource_thread(
|
|
||||||
"".into(), None, ProfilerChan(tx), None);
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
|
||||||
let (id_sender, id_receiver) = ipc::channel().unwrap();
|
|
||||||
let (sync_sender, sync_receiver) = ipc::channel().unwrap();
|
|
||||||
let url = ServoUrl::parse(&format!("http://127.0.0.1:{}", port)).unwrap();
|
|
||||||
|
|
||||||
resource_thread.send(CoreResourceMsg::Load(LoadData::new(LoadContext::Browsing, url, &ResourceTest),
|
|
||||||
LoadConsumer::Channel(sender),
|
|
||||||
Some(id_sender))).unwrap();
|
|
||||||
// get the `ResourceId` and send a cancel message, which should stop the loading loop
|
|
||||||
let res_id = id_receiver.recv().unwrap();
|
|
||||||
resource_thread.send(CoreResourceMsg::Cancel(res_id)).unwrap();
|
|
||||||
// synchronize with the resource_thread loop, so that we don't simply send everything at once!
|
|
||||||
resource_thread.send(CoreResourceMsg::Synchronize(sync_sender)).unwrap();
|
|
||||||
let _ = sync_receiver.recv();
|
|
||||||
// now, let's send the body, because the connection is still active and data would be loaded
|
|
||||||
// (but, the loading has been cancelled)
|
|
||||||
let _ = body_sender.send(body);
|
|
||||||
let response = receiver.recv().unwrap();
|
|
||||||
assert_eq!(response.progress_port.recv().unwrap(),
|
|
||||||
ProgressMsg::Done(Err(NetworkError::LoadCancelled)));
|
|
||||||
resource_thread.send(CoreResourceMsg::Exit(exit_sender)).unwrap();
|
|
||||||
exit_receiver.recv().unwrap();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue