mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Auto merge of #11552 - izgzhen:add-testing-fix-filemanager, r=Manishearth
Improve implementation and add testing regarding file manager thread First there is a more completed unit test. And in the test running, I found a runtime error `Serde(Custom("bincode does not support Deserializer::deserialize))` when reading response from file manage thread. I analyzed a bit and found that it is probably caused by the `Uuid` field. I temporarily work around it by making the `Id` essentially a string wrapped inside `SelectedFileId`. Related to PR #11131. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11552) <!-- Reviewable:end -->
This commit is contained in:
commit
6f9016cf3e
7 changed files with 100 additions and 73 deletions
|
@ -5,18 +5,60 @@
|
|||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net::filemanager_thread::FileManagerThreadFactory;
|
||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerThreadError};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn test_filemanager() {
|
||||
let chan: IpcSender<FileManagerThreadMsg> = FileManagerThreadFactory::new();
|
||||
|
||||
{
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
let _ = chan.send(FileManagerThreadMsg::SelectFile(tx));
|
||||
// Try to open a dummy file "tests/unit/net/test.txt" in tree
|
||||
let mut handler = File::open("test.txt").expect("test.txt is stolen");
|
||||
let mut test_file_content = vec![];
|
||||
|
||||
match rx.recv().unwrap() {
|
||||
Err(FileManagerThreadError::InvalidSelection) => {},
|
||||
_ => assert!(false, "Should be an invalid selection before dialog is implemented"),
|
||||
handler.read_to_end(&mut test_file_content)
|
||||
.expect("Read tests/unit/net/test.txt error");
|
||||
|
||||
|
||||
{
|
||||
// Try to select a dummy file "tests/unit/net/test.txt"
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::SelectFile(tx)).unwrap();
|
||||
let selected = rx.recv().expect("File manager channel is broken")
|
||||
.expect("The file manager failed to find test.txt");
|
||||
|
||||
// Expecting attributes conforming the spec
|
||||
assert!(selected.filename == PathBuf::from("test.txt"));
|
||||
assert!(selected.type_string == "text/plain".to_string());
|
||||
|
||||
// Test by reading, expecting same content
|
||||
{
|
||||
let (tx2, rx2) = ipc::channel().unwrap();
|
||||
chan.send(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone())).unwrap();
|
||||
|
||||
let msg = rx2.recv().expect("File manager channel is broken");
|
||||
|
||||
let vec = msg.expect("File manager reading failure is unexpected");
|
||||
assert!(test_file_content == vec, "Read content differs");
|
||||
}
|
||||
|
||||
// Delete the id
|
||||
chan.send(FileManagerThreadMsg::DeleteFileID(selected.id.clone())).unwrap();
|
||||
|
||||
// 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())).unwrap();
|
||||
|
||||
let msg = rx2.recv().expect("File manager channel is broken");
|
||||
|
||||
match msg {
|
||||
Err(FileManagerThreadError::ReadFileError) => {},
|
||||
other => {
|
||||
assert!(false, "Get unexpected response after deleting the id: {:?}", other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,9 +68,6 @@ fn test_filemanager() {
|
|||
let (tx, rx) = ipc::channel().unwrap();
|
||||
let _ = chan.send(FileManagerThreadMsg::SelectFile(tx));
|
||||
|
||||
match rx.try_recv() {
|
||||
Ok(_) => assert!(false, "The thread should not response fine after exited"),
|
||||
Err(_) => {},
|
||||
}
|
||||
assert!(rx.try_recv().is_err(), "The thread should not respond normally after exited");
|
||||
}
|
||||
}
|
||||
|
|
1
tests/unit/net/test.txt
Normal file
1
tests/unit/net/test.txt
Normal file
|
@ -0,0 +1 @@
|
|||
hello, servo
|
Loading…
Add table
Add a link
Reference in a new issue