mirror of
https://github.com/servo/servo.git
synced 2025-08-13 01:15:34 +01:00
Add cancellability to file manager load and related refactoring
This commit is contained in:
parent
7807895d58
commit
17ae38a318
12 changed files with 137 additions and 189 deletions
|
@ -2,8 +2,8 @@
|
|||
* 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 ipc_channel::ipc::{self, IpcSender};
|
||||
use net::filemanager_thread::{FileManagerThreadFactory, UIProvider};
|
||||
use ipc_channel::ipc;
|
||||
use net::filemanager_thread::{FileManager, UIProvider};
|
||||
use net_traits::blob_url_store::BlobURLStoreError;
|
||||
use net_traits::filemanager_thread::{FilterPattern, FileManagerThreadMsg, FileManagerThreadError, ReadFileProgress};
|
||||
use std::fs::File;
|
||||
|
@ -26,7 +26,7 @@ impl UIProvider for TestProvider {
|
|||
|
||||
#[test]
|
||||
fn test_filemanager() {
|
||||
let chan: IpcSender<FileManagerThreadMsg> = FileManagerThreadFactory::new(TEST_PROVIDER);
|
||||
let filemanager = FileManager::new(TEST_PROVIDER);
|
||||
|
||||
// Try to open a dummy file "tests/unit/net/test.jpeg" in tree
|
||||
let mut handler = File::open("test.jpeg").expect("test.jpeg is stolen");
|
||||
|
@ -41,7 +41,7 @@ fn test_filemanager() {
|
|||
{
|
||||
// Try to select a dummy file "tests/unit/net/test.jpeg"
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone(), None)).unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone(), None), None);
|
||||
let selected = rx.recv().expect("Broken channel")
|
||||
.expect("The file manager failed to find test.jpeg");
|
||||
|
||||
|
@ -52,7 +52,7 @@ fn test_filemanager() {
|
|||
// Test by reading, expecting same content
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone())).unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()), None);
|
||||
|
||||
let msg = rx2.recv().expect("Broken channel");
|
||||
|
||||
|
@ -82,7 +82,7 @@ fn test_filemanager() {
|
|||
// Delete the id
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone(), tx2)).unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone(), tx2), None);
|
||||
|
||||
let ret = rx2.recv().expect("Broken channel");
|
||||
assert!(ret.is_ok(), "DecRef is not okay");
|
||||
|
@ -91,7 +91,7 @@ fn test_filemanager() {
|
|||
// Test by reading again, expecting read error because we invalidated the id
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone())).unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()), None);
|
||||
|
||||
let msg = rx2.recv().expect("Broken channel");
|
||||
|
||||
|
@ -103,13 +103,4 @@ fn test_filemanager() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _ = chan.send(FileManagerThreadMsg::Exit);
|
||||
|
||||
{
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
let _ = chan.send(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone(), None));
|
||||
|
||||
assert!(rx.try_recv().is_err(), "The thread should not respond normally after exited");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use ipc_channel::ipc;
|
||||
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
|
||||
use net::filemanager_thread::{FileManagerThreadFactory, TFDProvider};
|
||||
use net::resource_thread::new_core_resource_thread;
|
||||
use net_traits::hosts::{parse_hostsfile, host_replacement};
|
||||
use net_traits::{CoreResourceMsg, LoadData, LoadConsumer, LoadContext};
|
||||
|
@ -16,8 +15,6 @@ use std::net::IpAddr;
|
|||
use std::sync::mpsc::channel;
|
||||
use url::Url;
|
||||
|
||||
const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
|
||||
|
||||
fn ip(s: &str) -> IpAddr {
|
||||
s.parse().unwrap()
|
||||
}
|
||||
|
@ -40,9 +37,8 @@ impl LoadOrigin for ResourceTest {
|
|||
fn test_exit() {
|
||||
let (tx, _rx) = ipc::channel().unwrap();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let filemanager_chan = FileManagerThreadFactory::new(TFD_PROVIDER);
|
||||
let (resource_thread, _) = new_core_resource_thread(
|
||||
"".to_owned(), None, ProfilerChan(tx), filemanager_chan, None);
|
||||
"".to_owned(), None, ProfilerChan(tx), None);
|
||||
resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap();
|
||||
receiver.recv().unwrap();
|
||||
}
|
||||
|
@ -51,9 +47,8 @@ fn test_exit() {
|
|||
fn test_bad_scheme() {
|
||||
let (tx, _rx) = ipc::channel().unwrap();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let filemanager_chan = FileManagerThreadFactory::new(TFD_PROVIDER);
|
||||
let (resource_thread, _) = new_core_resource_thread(
|
||||
"".to_owned(), None, ProfilerChan(tx), filemanager_chan, None);
|
||||
"".to_owned(), None, ProfilerChan(tx), None);
|
||||
let (start_chan, start) = ipc::channel().unwrap();
|
||||
let url = Url::parse("bogus://whatever").unwrap();
|
||||
resource_thread.send(CoreResourceMsg::Load(LoadData::new(LoadContext::Browsing, url, &ResourceTest),
|
||||
|
@ -232,9 +227,8 @@ fn test_cancelled_listener() {
|
|||
|
||||
let (tx, _rx) = ipc::channel().unwrap();
|
||||
let (exit_sender, exit_receiver) = ipc::channel().unwrap();
|
||||
let filemanager_chan = FileManagerThreadFactory::new(TFD_PROVIDER);
|
||||
let (resource_thread, _) = new_core_resource_thread(
|
||||
"".to_owned(), None, ProfilerChan(tx), filemanager_chan, None);
|
||||
"".to_owned(), 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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue