Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite some http unit tests with fetch. #14131

Merged
merged 4 commits into from Nov 8, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Rewrite test_request_and_response_message_from_devtool_without_pipeli…

…ne_id.
  • Loading branch information
Ms2ger committed Nov 8, 2016
commit 9b1e153b3103b63985b63d759a907ee69701a1e8
@@ -547,43 +547,27 @@ fn test_request_and_response_data_with_network_messages() {
assert_eq!(devhttpresponse, httpresponse);
}

struct HttpTestNoPipeline;
impl LoadOrigin for HttpTestNoPipeline {
fn referrer_url(&self) -> Option<Url> {
None
}
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
None
}
fn pipeline_id(&self) -> Option<PipelineId> {
None
}
}

#[test]
fn test_request_and_response_message_from_devtool_without_pipeline_id() {
struct Factory;

impl HttpRequestFactory for Factory {
type R = MockRequest;

fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
let mut headers = Headers::new();
headers.set(Host { hostname: "foo.bar".to_owned(), port: None });
Ok(MockRequest::new(
ResponseType::WithHeaders(<[_]>::to_vec("Yay!".as_bytes()), headers))
)
}
}
let handler = move |_: HyperRequest, mut response: HyperResponse| {
response.headers_mut().set(Host { hostname: "foo.bar".to_owned(), port: None });
response.send(b"Yay!").unwrap();
};
let (mut server, url) = make_server(handler);

let http_state = HttpState::new();
let ui_provider = TestProvider::new();
let request = Request::from_init(RequestInit {
url: url.clone(),
method: Method::Get,
destination: Destination::Document,
origin: url.clone(),
pipeline_id: None,
.. RequestInit::default()
});
let (devtools_chan, devtools_port) = mpsc::channel();
let response = fetch_sync(request, Some(devtools_chan));
assert!(response.status.unwrap().is_success());

let url = Url::parse("https://mozilla.com").unwrap();
let (devtools_chan, devtools_port) = mpsc::channel::<DevtoolsControlMsg>();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTestNoPipeline);
let _ = load(&load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory,
DEFAULT_USER_AGENT.into(), &CancellationListener::new(None), None);
let _ = server.close();

// notification received from devtools
assert!(devtools_port.try_recv().is_err());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.