mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #12577 - izgzhen:fm-chunked, r=Manishearth
Chunked ReadFile from file manager + Introduce a `ReadFileProgress` sender in the `ReadFile` msg to file manager, and implement the related I/O operations + Change `tests/unit/net/test.jpeg` from a 4.8K file to a 39K file to better test the chunked reading (Since one chunk is maximally 8129 Bytes). r? @Manishearth <!-- 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 - [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="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12577) <!-- Reviewable:end -->
This commit is contained in:
commit
b41bf4f1f3
7 changed files with 163 additions and 57 deletions
|
@ -5,7 +5,7 @@
|
|||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net::filemanager_thread::{FileManagerThreadFactory, UIProvider};
|
||||
use net_traits::blob_url_store::BlobURLStoreError;
|
||||
use net_traits::filemanager_thread::{FilterPattern, FileManagerThreadMsg, FileManagerThreadError};
|
||||
use net_traits::filemanager_thread::{FilterPattern, FileManagerThreadMsg, FileManagerThreadError, ReadFileProgress};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
@ -16,11 +16,11 @@ struct TestProvider;
|
|||
|
||||
impl UIProvider for TestProvider {
|
||||
fn open_file_dialog(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<String> {
|
||||
Some("test.txt".to_string())
|
||||
Some("test.jpeg".to_string())
|
||||
}
|
||||
|
||||
fn open_file_dialog_multi(&self, _path: &str, _patterns: Vec<FilterPattern>) -> Option<Vec<String>> {
|
||||
Some(vec!["test.txt".to_string()])
|
||||
Some(vec!["test.jpeg".to_string()])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,26 +28,26 @@ impl UIProvider for TestProvider {
|
|||
fn test_filemanager() {
|
||||
let chan: IpcSender<FileManagerThreadMsg> = FileManagerThreadFactory::new(TEST_PROVIDER);
|
||||
|
||||
// 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");
|
||||
// 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");
|
||||
let mut test_file_content = vec![];
|
||||
|
||||
handler.read_to_end(&mut test_file_content)
|
||||
.expect("Read tests/unit/net/test.txt error");
|
||||
.expect("Read tests/unit/net/test.jpeg error");
|
||||
|
||||
let patterns = vec![FilterPattern(".txt".to_string())];
|
||||
let origin = "test.com".to_string();
|
||||
|
||||
{
|
||||
// Try to select a dummy file "tests/unit/net/test.txt"
|
||||
// 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();
|
||||
let selected = rx.recv().expect("Broken channel")
|
||||
.expect("The file manager failed to find test.txt");
|
||||
.expect("The file manager failed to find test.jpeg");
|
||||
|
||||
// Expecting attributes conforming the spec
|
||||
assert!(selected.filename == PathBuf::from("test.txt"));
|
||||
assert!(selected.type_string == "text/plain".to_string());
|
||||
assert_eq!(selected.filename, PathBuf::from("test.jpeg"));
|
||||
assert_eq!(selected.type_string, "image/jpeg".to_string());
|
||||
|
||||
// Test by reading, expecting same content
|
||||
{
|
||||
|
@ -56,8 +56,27 @@ fn test_filemanager() {
|
|||
|
||||
let msg = rx2.recv().expect("Broken channel");
|
||||
|
||||
let blob_buf = msg.expect("File manager reading failure is unexpected");
|
||||
assert_eq!(test_file_content, blob_buf.bytes, "Read content differs");
|
||||
if let ReadFileProgress::Meta(blob_buf) = msg.expect("File manager reading failure is unexpected") {
|
||||
let mut bytes = blob_buf.bytes;
|
||||
|
||||
loop {
|
||||
match rx2.recv().expect("Broken channel").expect("File manager reading failure is unexpected") {
|
||||
ReadFileProgress::Meta(_) => {
|
||||
panic!("Invalid FileManager reply");
|
||||
}
|
||||
ReadFileProgress::Partial(mut bytes_in) => {
|
||||
bytes.append(&mut bytes_in);
|
||||
}
|
||||
ReadFileProgress::EOF => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(test_file_content, bytes, "Read content differs");
|
||||
} else {
|
||||
panic!("Invalid FileManager reply");
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the id
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 61 KiB |
|
@ -1 +0,0 @@
|
|||
hello, servo
|
Loading…
Add table
Add a link
Reference in a new issue