Skip to content

Commit

Permalink
test(net): update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 27, 2018
1 parent 9ff11b9 commit d94def6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
9 changes: 4 additions & 5 deletions components/net/tests/fetch.rs
Expand Up @@ -2,7 +2,7 @@
* 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 {DEFAULT_USER_AGENT, new_fetch_context, fetch, make_server};
use {DEFAULT_USER_AGENT, new_fetch_context, create_embedder_proxy, fetch, make_server};
use devtools_traits::DevtoolsControlMsg;
use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse;
Expand Down Expand Up @@ -124,7 +124,7 @@ fn test_fetch_blob() {
use ipc_channel::ipc;
use net_traits::blob_url_store::BlobBuf;

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

let bytes = b"content";
let blob_buf = BlobBuf {
Expand Down Expand Up @@ -552,13 +552,12 @@ 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 {
let context = FetchContext {
state: Arc::new(HttpState::new(ssl_client)),
user_agent: DEFAULT_USER_AGENT.into(),
devtools_chan: None,
filemanager: FileManager::new(sender),
filemanager: FileManager::new(create_embedder_proxy()),
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
};

Expand Down
5 changes: 2 additions & 3 deletions components/net/tests/filemanager_thread.rs
Expand Up @@ -2,6 +2,7 @@
* 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 create_embedder_proxy;
use ipc_channel::ipc;
use net::filemanager_thread::FileManager;
use net_traits::blob_url_store::BlobURLStoreError;
Expand All @@ -10,12 +11,10 @@ use servo_config::prefs::{PrefValue, PREFS};
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::sync::mpsc::channel;

#[test]
fn test_filemanager() {
let (sender, _) = channel();
let filemanager = FileManager::new(sender);
let filemanager = FileManager::new(create_embedder_proxy());
PREFS.set("dom.testing.htmlinputelement.select_files.enabled", PrefValue::Boolean(true));

// Try to open a dummy file "components/net/tests/test.jpeg" in tree
Expand Down
16 changes: 8 additions & 8 deletions components/net/tests/http_loader.rs
Expand Up @@ -506,7 +506,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
pipeline_id: Some(TEST_PIPELINE_ID),
.. RequestInit::default()
});
let context = new_fetch_context(None);
let context = new_fetch_context(None, None);
let response = fetch_with_context(&mut request, &context);

let _ = server.close();
Expand All @@ -523,7 +523,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
};
let (mut server, url) = make_server(handler);

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);

Expand Down Expand Up @@ -555,7 +555,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
};
let (mut server, url) = make_server(handler);

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
Expand Down Expand Up @@ -593,7 +593,7 @@ fn test_load_sends_cookie_if_nonhttp() {
};
let (mut server, url) = make_server(handler);

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
Expand Down Expand Up @@ -631,7 +631,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
};
let (mut server, url) = make_server(handler);

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);

Expand Down Expand Up @@ -665,7 +665,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
};
let (mut server, url) = make_server(handler);

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);

Expand Down Expand Up @@ -983,7 +983,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
let url_y = ServoUrl::parse(&format!("http://mozilla.org:{}/org/", port)).unwrap();
*shared_url_y_clone.lock().unwrap() = Some(url_y.clone());

let context = new_fetch_context(None);
let context = new_fetch_context(None, None);
{
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
let cookie_x = Cookie::new_wrapped(
Expand Down Expand Up @@ -1087,7 +1087,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
credentials_mode: CredentialsMode::Include,
.. RequestInit::default()
});
let context = new_fetch_context(None);
let context = new_fetch_context(None, None);

let auth_entry = AuthCacheEntry {
user_name: "username".to_owned(),
Expand Down
37 changes: 32 additions & 5 deletions components/net/tests/main.rs
Expand Up @@ -4,6 +4,7 @@

#![cfg(test)]

extern crate compositing;
extern crate cookie as cookie_rs;
extern crate devtools_traits;
extern crate embedder_traits;
Expand All @@ -16,7 +17,6 @@ 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;
Expand All @@ -35,6 +35,7 @@ mod mime_classifier;
mod resource_thread;
mod subresource_integrity;

use compositing::compositor_thread::{EmbedderProxy, EventLoopWaker};
use devtools_traits::DevtoolsControlMsg;
use embedder_traits::resources::{self, Resource};
use hyper::server::{Handler, Listening, Server};
Expand All @@ -56,9 +57,35 @@ struct FetchResponseCollector {
sender: Sender<Response>,
}

fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
let ssl_client = create_ssl_client(&resources::read_string(Resource::SSLCertificates));
fn create_embedder_proxy() -> EmbedderProxy {
let (sender, _) = channel();
let event_loop_waker = | | {
struct DummyEventLoopWaker {
}
impl DummyEventLoopWaker {
fn new() -> DummyEventLoopWaker {
DummyEventLoopWaker { }
}
}
impl EventLoopWaker for DummyEventLoopWaker {
fn wake(&self) { }
fn clone(&self) -> Box<EventLoopWaker + Send> {
Box::new(DummyEventLoopWaker { })
}
}

Box::new(DummyEventLoopWaker::new())
};

EmbedderProxy {
sender: sender,
event_loop_waker: event_loop_waker()
}
}

fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>, fc: Option<EmbedderProxy>) -> FetchContext {
let ssl_client = create_ssl_client(&resources::read_string(Resource::SSLCertificates));
let sender = fc.unwrap_or_else(|| create_embedder_proxy());
FetchContext {
state: Arc::new(HttpState::new(ssl_client)),
user_agent: DEFAULT_USER_AGENT.into(),
Expand All @@ -79,7 +106,7 @@ impl FetchTaskTarget for FetchResponseCollector {
}

fn fetch(request: &mut Request, dc: Option<Sender<DevtoolsControlMsg>>) -> Response {
fetch_with_context(request, &new_fetch_context(dc))
fetch_with_context(request, &new_fetch_context(dc, None))
}

fn fetch_with_context(request: &mut Request, context: &FetchContext) -> Response {
Expand All @@ -99,7 +126,7 @@ fn fetch_with_cors_cache(request: &mut Request, cache: &mut CorsCache) -> Respon
sender: sender,
};

methods::fetch_with_cors_cache(request, cache, &mut target, &new_fetch_context(None));
methods::fetch_with_cors_cache(request, cache, &mut target, &new_fetch_context(None, None));

receiver.recv().unwrap()
}
Expand Down
10 changes: 3 additions & 7 deletions components/net/tests/resource_thread.rs
Expand Up @@ -2,15 +2,14 @@
* 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 create_embedder_proxy;
use ipc_channel::ipc;
use net::resource_thread::new_core_resource_thread;
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()
Expand All @@ -20,12 +19,9 @@ 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, constellation_sender) = new_core_resource_thread(
"".into(), None, ProfilerChan(tx), MemProfilerChan(mtx), None);
constellation_sender.send(constellation.clone()).unwrap();
let _ = constellation.send(ConstellationMsg::Exit);
let (resource_thread, _private_resource_thread) = new_core_resource_thread(
"".into(), None, ProfilerChan(tx), MemProfilerChan(mtx), create_embedder_proxy(), None);
resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap();
receiver.recv().unwrap();
}
Expand Down

0 comments on commit d94def6

Please sign in to comment.