mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
test(net): update test cases
This commit is contained in:
parent
f69b124444
commit
c4c0d263e9
4 changed files with 23 additions and 27 deletions
|
@ -552,12 +552,13 @@ fn test_fetch_with_hsts() {
|
|||
let mut ca_content = String::new();
|
||||
File::open(cert_path).unwrap().read_to_string(&mut ca_content).unwrap();
|
||||
let ssl_client = create_ssl_client(&ca_content);
|
||||
let (sender, _) = channel();
|
||||
|
||||
let context = FetchContext {
|
||||
state: Arc::new(HttpState::new(ssl_client)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: None,
|
||||
filemanager: FileManager::new(),
|
||||
filemanager: FileManager::new(sender),
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
};
|
||||
|
||||
|
|
|
@ -3,30 +3,20 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use ipc_channel::ipc;
|
||||
use net::filemanager_thread::{FileManager, UIProvider};
|
||||
use net::filemanager_thread::FileManager;
|
||||
use net_traits::blob_url_store::BlobURLStoreError;
|
||||
use net_traits::filemanager_thread::{FilterPattern, FileManagerThreadMsg, FileManagerThreadError, ReadFileProgress};
|
||||
use servo_config::prefs::{PrefValue, PREFS};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const TEST_PROVIDER: &'static TestProvider = &TestProvider;
|
||||
|
||||
pub struct TestProvider;
|
||||
|
||||
impl UIProvider for TestProvider {
|
||||
fn open_file_dialog(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<String> {
|
||||
Some("tests/test.jpeg".to_string())
|
||||
}
|
||||
|
||||
fn open_file_dialog_multi(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
|
||||
Some(vec!["tests/test.jpeg".to_string()])
|
||||
}
|
||||
}
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
#[test]
|
||||
fn test_filemanager() {
|
||||
let filemanager = FileManager::new();
|
||||
let (sender, _) = channel();
|
||||
let filemanager = FileManager::new(sender);
|
||||
PREFS.set("dom.testing.htmlinputelement.select_files.enabled", PrefValue::Boolean(true));
|
||||
|
||||
// Try to open a dummy file "components/net/tests/test.jpeg" in tree
|
||||
let mut handler = File::open("tests/test.jpeg").expect("test.jpeg is stolen");
|
||||
|
@ -41,8 +31,8 @@ fn test_filemanager() {
|
|||
{
|
||||
// Try to select a dummy file "components/net/tests/test.jpeg"
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone(), None),
|
||||
TEST_PROVIDER);
|
||||
filemanager.handle(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone(),
|
||||
Some("tests/test.jpeg".to_string())));
|
||||
let selected = rx.recv().expect("Broken channel")
|
||||
.expect("The file manager failed to find test.jpeg");
|
||||
|
||||
|
@ -53,8 +43,7 @@ fn test_filemanager() {
|
|||
// Test by reading, expecting same content
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()),
|
||||
TEST_PROVIDER);
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()));
|
||||
|
||||
let msg = rx2.recv().expect("Broken channel");
|
||||
|
||||
|
@ -84,8 +73,7 @@ fn test_filemanager() {
|
|||
// Delete the id
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone(), tx2),
|
||||
TEST_PROVIDER);
|
||||
filemanager.handle(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone(), tx2));
|
||||
|
||||
let ret = rx2.recv().expect("Broken channel");
|
||||
assert!(ret.is_ok(), "DecRef is not okay");
|
||||
|
@ -94,8 +82,7 @@ fn test_filemanager() {
|
|||
// Test by reading again, expecting read error because we invalidated the id
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()),
|
||||
TEST_PROVIDER);
|
||||
filemanager.handle(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), false, origin.clone()));
|
||||
|
||||
let msg = rx2.recv().expect("Broken channel");
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ extern crate msg;
|
|||
extern crate net;
|
||||
extern crate net_traits;
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
extern crate servo_config;
|
||||
extern crate servo_url;
|
||||
extern crate time;
|
||||
extern crate unicase;
|
||||
|
@ -56,11 +58,12 @@ struct FetchResponseCollector {
|
|||
|
||||
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
|
||||
let ssl_client = create_ssl_client(&resources::read_string(Resource::SSLCertificates));
|
||||
let (sender, _) = channel();
|
||||
FetchContext {
|
||||
state: Arc::new(HttpState::new(ssl_client)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: dc,
|
||||
filemanager: FileManager::new(),
|
||||
filemanager: FileManager::new(sender),
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ use net::test::parse_hostsfile;
|
|||
use net_traits::CoreResourceMsg;
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::ProfilerChan;
|
||||
use script_traits::ConstellationMsg;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
fn ip(s: &str) -> IpAddr {
|
||||
s.parse().unwrap()
|
||||
|
@ -18,9 +20,12 @@ fn ip(s: &str) -> IpAddr {
|
|||
fn test_exit() {
|
||||
let (tx, _rx) = ipc::channel().unwrap();
|
||||
let (mtx, _mrx) = ipc::channel().unwrap();
|
||||
let (constellation, _) = channel();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let (resource_thread, _private_resource_thread) = new_core_resource_thread(
|
||||
let (resource_thread, _private_resource_thread, constellation_sender) = new_core_resource_thread(
|
||||
"".into(), None, ProfilerChan(tx), MemProfilerChan(mtx), None);
|
||||
constellation_sender.send(constellation.clone()).unwrap();
|
||||
let _ = constellation.send(ConstellationMsg::Exit);
|
||||
resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap();
|
||||
receiver.recv().unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue