Auto merge of #11368 - izgzhen:fix-filemanager-exit, r=asajeffrey

Fix FileManager thread panic and other misc improvements

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] There are tests for these changes

Changes:

- Add shut down logic for FileManager thread
- Add an unit test for filemanager_thread

<!-- 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/11368)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-24 22:17:15 -05:00
commit 0b64586bf5
6 changed files with 46 additions and 3 deletions

View file

@ -0,0 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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;
use net_traits::filemanager_thread::{FileManagerThreadMsg, FileManagerThreadError};
#[test]
fn test_filemanager() {
let chan: IpcSender<FileManagerThreadMsg> = FileManagerThreadFactory::new();
{
let (tx, rx) = ipc::channel().unwrap();
let _ = chan.send(FileManagerThreadMsg::SelectFile(tx));
match rx.recv().unwrap() {
Err(FileManagerThreadError::InvalidSelection) => {},
_ => assert!(false, "Should be an invalid selection before dialog is implemented"),
}
}
let _ = chan.send(FileManagerThreadMsg::Exit);
{
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(_) => {},
}
}
}

View file

@ -29,3 +29,4 @@ extern crate util;
#[cfg(test)] mod resource_thread;
#[cfg(test)] mod hsts;
#[cfg(test)] mod http_loader;
#[cfg(test)] mod filemanager_thread;