Auto merge of #8622 - frewsxcv:url-plugin, r=SimonSapin

Implement 'url!(..)' macro

https://github.com/servo/rust-url/issues/136

https://github.com/servo/rust-url/pull/137

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8622)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-11-21 21:10:52 +05:30
commit ea690a2dff
30 changed files with 346 additions and 128 deletions

View file

@ -20,6 +20,9 @@ path = "../../../components/util"
[dependencies.msg]
path = "../../../components/msg"
[dependencies.plugins]
path = "../../../components/plugins"
[dependencies.devtools_traits]
path = "../../../components/devtools_traits"

View file

@ -7,7 +7,6 @@ extern crate cookie as cookie_rs;
use net::cookie::Cookie;
use net::cookie_storage::CookieStorage;
use net_traits::CookieSource;
use url::Url;
#[test]
@ -41,9 +40,9 @@ fn test_default_path() {
fn fn_cookie_constructor() {
use net_traits::CookieSource;
let url = &Url::parse("http://example.com/foo").unwrap();
let url = &url!("http://example.com/foo");
let gov_url = &Url::parse("http://gov.ac/foo").unwrap();
let gov_url = &url!("http://gov.ac/foo");
// cookie name/value test
assert!(cookie_rs::Cookie::parse(" baz ").is_err());
assert!(cookie_rs::Cookie::parse(" = bar ").is_err());
@ -79,7 +78,7 @@ fn fn_cookie_constructor() {
assert!(&cookie.cookie.domain.as_ref().unwrap()[..] == "example.com");
assert!(cookie.host_only);
let u = &Url::parse("http://example.com/foobar").unwrap();
let u = &url!("http://example.com/foobar");
let cookie = cookie_rs::Cookie::parse("foobar=value;path=/").unwrap();
assert!(Cookie::new_wrapped(cookie, u, CookieSource::HTTP).is_some());
}
@ -88,7 +87,7 @@ fn fn_cookie_constructor() {
fn test_sort_order() {
use std::cmp::Ordering;
let url = &Url::parse("http://example.com/foo").unwrap();
let url = &url!("http://example.com/foo");
let a_wrapped = cookie_rs::Cookie::parse("baz=bar; Path=/foo/bar/").unwrap();
let a = Cookie::new_wrapped(a_wrapped.clone(), url, CookieSource::HTTP).unwrap();
let a_prime = Cookie::new_wrapped(a_wrapped, url, CookieSource::HTTP).unwrap();

View file

@ -37,7 +37,7 @@ fn assert_parse(url: &'static str,
match data {
None => {
assert_eq!(progress, Done(Err("invalid data uri".to_string())));
assert_eq!(progress, Done(Err("invalid data uri".to_owned())));
}
Some(dat) => {
assert_eq!(progress, Payload(dat));
@ -74,8 +74,8 @@ fn plain_charset() {
assert_parse("data:text/plain;charset=latin1,hello",
Some(ContentType(Mime(TopLevel::Text,
SubLevel::Plain,
vec!((Attr::Charset, Value::Ext("latin1".to_string())))))),
Some("latin1".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
vec!((Attr::Charset, Value::Ext("latin1".to_owned())))))),
Some("latin1".to_owned()), Some(b"hello".iter().map(|&x| x).collect()));
}
#[test]
@ -85,7 +85,7 @@ fn plain_only_charset() {
Some(ContentType(Mime(TopLevel::Text,
SubLevel::Plain,
vec!((Attr::Charset, Value::Utf8))))),
Some("utf-8".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
Some("utf-8".to_owned()), Some(b"hello".iter().map(|&x| x).collect()));
}
#[test]
@ -101,7 +101,7 @@ fn base64() {
#[test]
fn base64_ct() {
assert_parse("data:application/octet-stream;base64,C62+7w==",
Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext("octet-stream".to_string()), vec!()))),
Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext("octet-stream".to_owned()), vec!()))),
None,
Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
}
@ -110,7 +110,7 @@ fn base64_ct() {
fn base64_charset() {
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain,
vec!((Attr::Charset, Value::Ext("koi8-r".to_string())))))),
Some("koi8-r".to_string()),
vec!((Attr::Charset, Value::Ext("koi8-r".to_owned())))))),
Some("koi8-r".to_owned()),
Some(vec!(0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4)));
}

View file

@ -6,12 +6,11 @@ use net::hsts::{HSTSList, HSTSEntry};
use net::hsts::{secure_url, preload_hsts_domains};
use net_traits::IncludeSubdomains;
use time;
use url::Url;
#[test]
fn test_hsts_entry_is_not_expired_when_it_has_no_timestamp() {
let entry = HSTSEntry {
host: "mozilla.org".to_string(),
host: "mozilla.org".to_owned(),
include_subdomains: false,
max_age: Some(20),
timestamp: None
@ -23,7 +22,7 @@ fn test_hsts_entry_is_not_expired_when_it_has_no_timestamp() {
#[test]
fn test_hsts_entry_is_not_expired_when_it_has_no_max_age() {
let entry = HSTSEntry {
host: "mozilla.org".to_string(),
host: "mozilla.org".to_owned(),
include_subdomains: false,
max_age: None,
timestamp: Some(time::get_time().sec as u64)
@ -35,7 +34,7 @@ fn test_hsts_entry_is_not_expired_when_it_has_no_max_age() {
#[test]
fn test_hsts_entry_is_expired_when_it_has_reached_its_max_age() {
let entry = HSTSEntry {
host: "mozilla.org".to_string(),
host: "mozilla.org".to_owned(),
include_subdomains: false,
max_age: Some(10),
timestamp: Some(time::get_time().sec as u64 - 20u64)
@ -47,7 +46,7 @@ fn test_hsts_entry_is_expired_when_it_has_reached_its_max_age() {
#[test]
fn test_hsts_entry_cant_be_created_with_ipv6_address_as_host() {
let entry = HSTSEntry::new(
"2001:0db8:0000:0000:0000:ff00:0042:8329".to_string(), IncludeSubdomains::NotIncluded, None
"2001:0db8:0000:0000:0000:ff00:0042:8329".to_owned(), IncludeSubdomains::NotIncluded, None
);
assert!(entry.is_none(), "able to create HSTSEntry with IPv6 host");
@ -56,7 +55,7 @@ fn test_hsts_entry_cant_be_created_with_ipv6_address_as_host() {
#[test]
fn test_hsts_entry_cant_be_created_with_ipv4_address_as_host() {
let entry = HSTSEntry::new(
"4.4.4.4".to_string(), IncludeSubdomains::NotIncluded, None
"4.4.4.4".to_owned(), IncludeSubdomains::NotIncluded, None
);
assert!(entry.is_none(), "able to create HSTSEntry with IPv4 host");
@ -65,11 +64,11 @@ fn test_hsts_entry_cant_be_created_with_ipv4_address_as_host() {
#[test]
fn test_push_entry_with_0_max_age_evicts_entry_from_list() {
let mut list = HSTSList {
entries: vec!(HSTSEntry::new("mozilla.org".to_string(),
entries: vec!(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, Some(500000u64)).unwrap())
};
list.push(HSTSEntry::new("mozilla.org".to_string(),
list.push(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, Some(0)).unwrap());
assert!(list.is_host_secure("mozilla.org") == false)
@ -78,11 +77,11 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() {
#[test]
fn test_push_entry_to_hsts_list_should_not_add_subdomains_whose_superdomain_is_already_matched() {
let mut list = HSTSList {
entries: vec!(HSTSEntry::new("mozilla.org".to_string(),
entries: vec!(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap())
};
list.push(HSTSEntry::new("servo.mozilla.org".to_string(),
list.push(HSTSEntry::new("servo.mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap());
assert!(list.entries.len() == 1)
@ -91,13 +90,13 @@ fn test_push_entry_to_hsts_list_should_not_add_subdomains_whose_superdomain_is_a
#[test]
fn test_push_entry_to_hsts_list_should_update_existing_domain_entrys_include_subdomains() {
let mut list = HSTSList {
entries: vec!(HSTSEntry::new("mozilla.org".to_string(),
entries: vec!(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap())
};
assert!(list.is_host_secure("servo.mozilla.org"));
list.push(HSTSEntry::new("mozilla.org".to_string(),
list.push(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap());
assert!(!list.is_host_secure("servo.mozilla.org"))
@ -106,11 +105,11 @@ fn test_push_entry_to_hsts_list_should_update_existing_domain_entrys_include_sub
#[test]
fn test_push_entry_to_hsts_list_should_not_create_duplicate_entry() {
let mut list = HSTSList {
entries: vec!(HSTSEntry::new("mozilla.org".to_string(),
entries: vec!(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap())
};
list.push(HSTSEntry::new("mozilla.org".to_string(),
list.push(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap());
assert!(list.entries.len() == 1)
@ -125,9 +124,9 @@ fn test_push_multiple_entrie_to_hsts_list_should_add_them_all() {
assert!(!list.is_host_secure("mozilla.org"));
assert!(!list.is_host_secure("bugzilla.org"));
list.push(HSTSEntry::new("mozilla.org".to_string(),
list.push(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap());
list.push(HSTSEntry::new("bugzilla.org".to_string(),
list.push(HSTSEntry::new("bugzilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap());
assert!(list.is_host_secure("mozilla.org"));
@ -142,7 +141,7 @@ fn test_push_entry_to_hsts_list_should_add_an_entry() {
assert!(!list.is_host_secure("mozilla.org"));
list.push(HSTSEntry::new("mozilla.org".to_string(),
list.push(HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap());
assert!(list.is_host_secure("mozilla.org"));
@ -187,7 +186,7 @@ fn test_hsts_list_with_no_entries_does_not_is_host_secure() {
#[test]
fn test_hsts_list_with_exact_domain_entry_is_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry::new("mozilla.org".to_string(),
entries: vec![HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap()]
};
@ -197,7 +196,7 @@ fn test_hsts_list_with_exact_domain_entry_is_is_host_secure() {
#[test]
fn test_hsts_list_with_subdomain_when_include_subdomains_is_true_is_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry::new("mozilla.org".to_string(),
entries: vec![HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap()]
};
@ -207,7 +206,7 @@ fn test_hsts_list_with_subdomain_when_include_subdomains_is_true_is_is_host_secu
#[test]
fn test_hsts_list_with_subdomain_when_include_subdomains_is_false_is_not_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry::new("mozilla.org".to_string(),
entries: vec![HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::NotIncluded, None).unwrap()]
};
@ -217,7 +216,7 @@ fn test_hsts_list_with_subdomain_when_include_subdomains_is_false_is_not_is_host
#[test]
fn test_hsts_list_with_subdomain_when_host_is_not_a_subdomain_is_not_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry::new("mozilla.org".to_string(),
entries: vec![HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap()]
};
@ -227,7 +226,7 @@ fn test_hsts_list_with_subdomain_when_host_is_not_a_subdomain_is_not_is_host_sec
#[test]
fn test_hsts_list_with_subdomain_when_host_is_exact_match_is_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry::new("mozilla.org".to_string(),
entries: vec![HSTSEntry::new("mozilla.org".to_owned(),
IncludeSubdomains::Included, None).unwrap()]
};
@ -238,7 +237,7 @@ fn test_hsts_list_with_subdomain_when_host_is_exact_match_is_is_host_secure() {
fn test_hsts_list_with_expired_entry_is_not_is_host_secure() {
let hsts_list = HSTSList {
entries: vec![HSTSEntry {
host: "mozilla.org".to_string(),
host: "mozilla.org".to_owned(),
include_subdomains: false,
max_age: Some(20),
timestamp: Some(time::get_time().sec as u64 - 100u64)
@ -256,7 +255,7 @@ fn test_preload_hsts_domains_well_formed() {
#[test]
fn test_secure_url_does_not_change_explicit_port() {
let url = Url::parse("http://mozilla.org:8080/").unwrap();
let url = url!("http://mozilla.org:8080/");
let secure = secure_url(&url);
assert!(secure.port().unwrap() == 8080u16);
@ -264,7 +263,7 @@ fn test_secure_url_does_not_change_explicit_port() {
#[test]
fn test_secure_url_does_not_affect_non_http_schemas() {
let url = Url::parse("file://mozilla.org").unwrap();
let url = url!("file://mozilla.org");
let secure = secure_url(&url);
assert_eq!(&secure.scheme, "file");
@ -272,7 +271,7 @@ fn test_secure_url_does_not_affect_non_http_schemas() {
#[test]
fn test_secure_url_forces_an_http_host_in_list_to_https() {
let url = Url::parse("http://mozilla.org").unwrap();
let url = url!("http://mozilla.org");
let secure = secure_url(&url);
assert_eq!(&secure.scheme, "https");

View file

@ -54,7 +54,7 @@ fn read_response(reader: &mut Read) -> String {
unsafe { buf.set_len(len); }
String::from_utf8(buf).unwrap()
},
Ok(_) => "".to_string(),
Ok(_) => "".to_owned(),
Err(e) => panic!("problem reading response {}", e)
}
}
@ -86,7 +86,7 @@ impl HttpResponse for MockResponse {
fn redirect_to(host: String) -> MockResponse {
let mut headers = Headers::new();
headers.set(Location(host.to_string()));
headers.set(Location(host.to_owned()));
MockResponse::new(
headers,
@ -236,7 +236,7 @@ fn assert_cookie_for_domain(cookie_jar: Arc<RwLock<CookieStorage>>, domain: &str
let cookies = cookie_jar.cookies_for_url(&url, CookieSource::HTTP);
if let Some(cookie_list) = cookies {
assert_eq!(cookie.to_string(), cookie_list);
assert_eq!(cookie.to_owned(), cookie_list);
} else {
assert_eq!(cookie.len(), 0);
}
@ -346,7 +346,7 @@ fn expect_devtools_http_response(devtools_port: &Receiver<DevtoolsControlMsg>) -
#[test]
fn test_check_default_headers_loaded_in_every_request() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -367,14 +367,14 @@ fn test_check_default_headers_loaded_in_every_request() {
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800u16)),
]);
headers.set(accept);
headers.set(UserAgent(DEFAULT_USER_AGENT.to_string()));
headers.set(UserAgent(DEFAULT_USER_AGENT.to_owned()));
// Testing for method.GET
let _ = load::<AssertRequestMustHaveHeaders>(load_data.clone(), hsts_list.clone(), cookie_jar.clone(), None,
&AssertMustHaveHeadersRequestFactory {
expected_headers: headers.clone(),
body: <[_]>::to_vec(&[])
}, DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
}, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
// Testing for method.POST
load_data.method = Method::Post;
@ -385,12 +385,12 @@ fn test_check_default_headers_loaded_in_every_request() {
&AssertMustHaveHeadersRequestFactory {
expected_headers: headers,
body: <[_]>::to_vec(&[])
}, DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
}, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
}
#[test]
fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length_should_be_set_to_0() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -407,7 +407,7 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length
&AssertMustIncludeHeadersRequestFactory {
expected_headers: content_length,
body: <[_]>::to_vec(&[])
}, DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
}, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
}
#[test]
@ -429,7 +429,7 @@ fn test_request_and_response_data_with_network_messages() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
let url = Url::parse("https://mozilla.com").unwrap();
let url = url!("https://mozilla.com");
let (devtools_chan, devtools_port) = mpsc::channel::<DevtoolsControlMsg>();
// This will probably have to be changed as it uses fake_root_pipeline_id which is marked for removal.
let pipeline_id = PipelineId::fake_root_pipeline_id();
@ -438,7 +438,7 @@ fn test_request_and_response_data_with_network_messages() {
request_headers.set(Host { hostname: "bar.foo".to_owned(), port: None });
load_data.headers = request_headers.clone();
let _ = load::<MockRequest>(load_data, hsts_list, cookie_jar, Some(devtools_chan), &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
// notification received from devtools
let devhttprequest = expect_devtools_http_request(&devtools_port);
@ -459,7 +459,7 @@ fn test_request_and_response_data_with_network_messages() {
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800u16)),
]);
headers.set(accept);
headers.set(UserAgent(DEFAULT_USER_AGENT.to_string()));
headers.set(UserAgent(DEFAULT_USER_AGENT.to_owned()));
let httprequest = DevtoolsHttpRequest {
url: url,
@ -504,11 +504,11 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
let url = Url::parse("https://mozilla.com").unwrap();
let url = url!("https://mozilla.com");
let (devtools_chan, devtools_port) = mpsc::channel::<DevtoolsControlMsg>();
let load_data = LoadData::new(url.clone(), None);
let _ = load::<MockRequest>(load_data, hsts_list, cookie_jar, Some(devtools_chan), &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
// notification received from devtools
assert!(devtools_port.try_recv().is_err());
@ -526,7 +526,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
fn create(&self, url: Url, method: Method) -> Result<MockRequest, LoadError> {
if url.domain().unwrap() == "mozilla.com" {
assert_eq!(Method::Post, method);
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_string())))
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_owned())))
} else {
assert_eq!(Method::Get, method);
Ok(MockRequest::new(ResponseType::Text(<[_]>::to_vec("Yay!".as_bytes()))))
@ -534,7 +534,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.method = Method::Post;
@ -542,7 +542,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
let _ = load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
}
#[test]
@ -563,7 +563,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
@ -572,7 +572,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
let mut response = load::<MockRequest>(
load_data, hsts_list, cookie_jar, None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None))
.unwrap();
@ -597,7 +597,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -607,7 +607,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
hsts_list,
cookie_jar,
None, &Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None))
.unwrap();
@ -625,7 +625,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
if url.domain().unwrap() == "mozilla.com" {
Ok(
AssertMustHaveBodyRequest::new(
ResponseType::Redirect("http://mozilla.org".to_string()),
ResponseType::Redirect("http://mozilla.org".to_owned()),
Some(<[_]>::to_vec("Body on POST!".as_bytes()))
)
)
@ -640,7 +640,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Body on POST!".as_bytes()));
@ -651,7 +651,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
load_data, hsts_list, cookie_jar,
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -670,7 +670,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
@ -682,7 +682,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar
cookie_jar,
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
assert_eq!(hsts_list.read().unwrap().is_host_secure("mozilla.com"), false);
@ -703,7 +703,7 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present
}
}
let url = Url::parse("https://mozilla.com").unwrap();
let url = url!("https://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
@ -715,7 +715,7 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present
cookie_jar,
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
assert!(hsts_list.read().unwrap().is_host_secure("mozilla.com"));
@ -736,7 +736,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -750,7 +750,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
cookie_jar.clone(),
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
assert_cookie_for_domain(cookie_jar.clone(), "http://mozilla.com", "mozillaIs=theBest");
@ -758,7 +758,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
#[test]
fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_resource_manager() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
@ -784,13 +784,13 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
&AssertMustIncludeHeadersRequestFactory {
expected_headers: cookie,
body: <[_]>::to_vec(&*load_data.data.unwrap())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
#[test]
fn test_load_sends_cookie_if_nonhttp() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -817,7 +817,7 @@ fn test_load_sends_cookie_if_nonhttp() {
&AssertMustIncludeHeadersRequestFactory {
expected_headers: headers,
body: <[_]>::to_vec(&*load_data.data.unwrap())
}, DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
}, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
}
#[test]
@ -835,7 +835,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -845,7 +845,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
cookie_jar.clone(),
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
let mut cookie_jar = cookie_jar.write().unwrap();
@ -870,12 +870,12 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
let load_data = LoadData::new(Url::parse("http://mozilla.com").unwrap(), None);
let load_data = LoadData::new(url!("http://mozilla.com"), None);
let _ = load::<MockRequest>(load_data, hsts_list,
cookie_jar.clone(),
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
assert_cookie_for_domain(cookie_jar, "http://mozilla.com", "");
@ -884,8 +884,8 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
#[test]
fn test_when_cookie_set_marked_httpsonly_secure_isnt_sent_on_http_request() {
let sec_url = Url::parse("https://mozilla.com").unwrap();
let url = Url::parse("http://mozilla.com").unwrap();
let sec_url = url!("https://mozilla.com");
let url = url!("http://mozilla.com");
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -911,14 +911,14 @@ fn test_when_cookie_set_marked_httpsonly_secure_isnt_sent_on_http_request() {
&AssertMustNotHaveHeadersRequestFactory {
headers_not_expected: vec!["Cookie".to_owned()],
body: <[_]>::to_vec(&*load_data.data.unwrap())
}, DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None));
}, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None));
}
#[test]
fn test_load_sets_content_length_to_length_of_request_body() {
let content = "This is a request body";
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec(content.as_bytes()));
@ -932,7 +932,7 @@ fn test_load_sets_content_length_to_length_of_request_body() {
None, &AssertMustIncludeHeadersRequestFactory {
expected_headers: content_len_headers,
body: <[_]>::to_vec(&*load_data.data.unwrap())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -943,7 +943,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
let mut accept_headers = Headers::new();
accept_headers.set(Accept(vec![text_html.clone()]));
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
load_data.headers.set(Accept(vec![text_html.clone()]));
@ -958,7 +958,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
&AssertMustIncludeHeadersRequestFactory {
expected_headers: accept_headers,
body: <[_]>::to_vec("Yay!".as_bytes())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -972,7 +972,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), Quality(800)),
]));
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
@ -986,7 +986,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
&AssertMustIncludeHeadersRequestFactory {
expected_headers: accept_headers,
body: <[_]>::to_vec("Yay!".as_bytes())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -995,7 +995,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
let mut accept_encoding_headers = Headers::new();
accept_encoding_headers.set(AcceptEncoding(vec![qitem(Encoding::Chunked)]));
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
load_data.headers.set(AcceptEncoding(vec![qitem(Encoding::Chunked)]));
@ -1010,7 +1010,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
&AssertMustIncludeHeadersRequestFactory {
expected_headers: accept_encoding_headers,
body: <[_]>::to_vec("Yay!".as_bytes())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -1021,7 +1021,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
qitem(Encoding::Deflate),
qitem(Encoding::EncodingExt("br".to_owned()))]));
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let mut load_data = LoadData::new(url.clone(), None);
load_data.data = Some(<[_]>::to_vec("Yay!".as_bytes()));
@ -1035,7 +1035,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
&AssertMustIncludeHeadersRequestFactory {
expected_headers: accept_encoding_headers,
body: <[_]>::to_vec("Yay!".as_bytes())
}, DEFAULT_USER_AGENT.to_string(),
}, DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None));
}
@ -1048,23 +1048,23 @@ fn test_load_errors_when_there_a_redirect_loop() {
fn create(&self, url: Url, _: Method) -> Result<MockRequest, LoadError> {
if url.domain().unwrap() == "mozilla.com" {
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_string())))
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_owned())))
} else if url.domain().unwrap() == "mozilla.org" {
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.com".to_string())))
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.com".to_owned())))
} else {
panic!("unexpected host {:?}", url)
}
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
match load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None)) {
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(LoadError::InvalidRedirect(_, msg)) => {
assert_eq!(msg, "redirect loop");
},
@ -1088,14 +1088,14 @@ fn test_load_errors_when_there_is_too_many_redirects() {
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
match load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None)) {
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(LoadError::MaxRedirects(url)) => {
assert_eq!(url.domain().unwrap(), "mozilla.com")
},
@ -1112,7 +1112,7 @@ fn test_load_follows_a_redirect() {
fn create(&self, url: Url, _: Method) -> Result<MockRequest, LoadError> {
if url.domain().unwrap() == "mozilla.com" {
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_string())))
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_owned())))
} else if url.domain().unwrap() == "mozilla.org" {
Ok(
MockRequest::new(
@ -1127,18 +1127,18 @@ fn test_load_follows_a_redirect() {
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = url!("http://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
match load::<MockRequest>(load_data, hsts_list, cookie_jar, None, &Factory,
DEFAULT_USER_AGENT.to_string(), &CancellationListener::new(None)) {
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(e) => panic!("expected to follow a redirect {:?}", e),
Ok(mut lr) => {
let response = read_response(&mut lr);
assert_eq!(response, "Yay!".to_string());
assert_eq!(response, "Yay!".to_owned());
}
}
}
@ -1149,13 +1149,13 @@ impl HttpRequestFactory for DontConnectFactory {
type R = MockRequest;
fn create(&self, url: Url, _: Method) -> Result<MockRequest, LoadError> {
Err(LoadError::Connection(url, "should not have connected".to_string()))
Err(LoadError::Connection(url, "should not have connected".to_owned()))
}
}
#[test]
fn test_load_errors_when_scheme_is_not_http_or_https() {
let url = Url::parse("ftp://not-supported").unwrap();
let url = url!("ftp://not-supported");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
@ -1166,7 +1166,7 @@ fn test_load_errors_when_scheme_is_not_http_or_https() {
cookie_jar,
None,
&DontConnectFactory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None)) {
Err(LoadError::UnsupportedScheme(_)) => {}
_ => panic!("expected ftp scheme to be unsupported")
@ -1175,7 +1175,7 @@ fn test_load_errors_when_scheme_is_not_http_or_https() {
#[test]
fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_https() {
let url = Url::parse("view-source:ftp://not-supported").unwrap();
let url = url!("view-source:ftp://not-supported");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
@ -1186,7 +1186,7 @@ fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_http
cookie_jar,
None,
&DontConnectFactory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&CancellationListener::new(None)) {
Err(LoadError::UnsupportedScheme(_)) => {}
_ => panic!("expected ftp scheme to be unsupported")
@ -1219,7 +1219,7 @@ fn test_load_errors_when_cancelled() {
let cancel_listener = CancellationListener::new(Some(cancel_resource));
cancel_sender.send(()).unwrap();
let url = Url::parse("https://mozilla.com").unwrap();
let url = url!("https://mozilla.com");
let load_data = LoadData::new(url.clone(), None);
let hsts_list = Arc::new(RwLock::new(HSTSList::new()));
let cookie_jar = Arc::new(RwLock::new(CookieStorage::new()));
@ -1229,7 +1229,7 @@ fn test_load_errors_when_cancelled() {
cookie_jar,
None,
&Factory,
DEFAULT_USER_AGENT.to_string(),
DEFAULT_USER_AGENT.to_owned(),
&cancel_listener) {
Err(LoadError::Cancelled(_, _)) => (),
_ => panic!("expected load cancelled error!")

View file

@ -2,6 +2,9 @@
* 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/. */
#![feature(plugin)]
#![plugin(plugins)]
extern crate cookie as cookie_rs;
extern crate devtools_traits;
extern crate flate2;

View file

@ -21,7 +21,7 @@ fn test_exit() {
fn test_bad_scheme() {
let resource_task = new_resource_task("".to_owned(), None);
let (start_chan, start) = ipc::channel().unwrap();
let url = Url::parse("bogus://whatever").unwrap();
let url = url!("bogus://whatever");
resource_task.send(ControlMsg::Load(LoadData::new(url, None), LoadConsumer::Channel(start_chan), None)).unwrap();
let response = start.recv().unwrap();
match response.progress_port.recv().unwrap() {
@ -161,13 +161,13 @@ fn test_replace_hosts() {
let host_table: *mut HashMap<String, String> = Box::into_raw(host_table_box);
let url = Url::parse("http://foo.bar.com:8000/foo").unwrap();
let url = url!("http://foo.bar.com:8000/foo");
assert_eq!(host_replacement(host_table, &url).domain().unwrap(), "127.0.0.1");
let url = Url::parse("http://servo.test.server").unwrap();
let url = url!("http://servo.test.server");
assert_eq!(host_replacement(host_table, &url).domain().unwrap(), "127.0.0.2");
let url = Url::parse("http://a.foo.bar.com").unwrap();
let url = url!("http://a.foo.bar.com");
assert_eq!(host_replacement(host_table, &url).domain().unwrap(), "a.foo.bar.com");
}

View file

@ -0,0 +1,15 @@
[package]
name = "plugin_tests"
version = "0.0.1"
authors = ["The Servo Project Developers"]
[lib]
name = "plugin_tests"
path = "lib.rs"
doctest = false
[dependencies.plugins]
path = "../../../components/plugins"
[dependencies.url]
version = "0.2.36"

11
tests/unit/plugin/lib.rs Normal file
View file

@ -0,0 +1,11 @@
/* 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/. */
#![feature(plugin)]
#![plugin(plugins)]
extern crate url;
#[cfg(test)]
mod url_plugin;

View file

@ -0,0 +1,24 @@
/* 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/. */
#[test]
fn test_url_plugin() {
assert_eq!("ftp://google.com/",
url!("ftp://google.com").to_string());
assert_eq!("ftp://google.com:443/",
url!("ftp://google.com:443").to_string());
assert_eq!("ftp://google.com:443/a/b/c",
url!("ftp://google.com:443/a/b/c").to_string());
assert_eq!("ftp://google.com:443/?a=b&c=d",
url!("ftp://google.com:443?a=b&c=d").to_string());
assert_eq!("http://[2001::1]/",
url!("http://[2001::1]:80").to_string());
assert_eq!("about:blank",
url!("about:blank").to_string());
}

View file

@ -8,6 +8,9 @@ name = "style_tests"
path = "lib.rs"
doctest = false
[dependencies.plugins]
path = "../../../components/plugins"
[dependencies.style]
path = "../../../components/style"

View file

@ -5,6 +5,7 @@
#![feature(plugin)]
#![cfg_attr(test, feature(core_intrinsics))]
#![plugin(string_cache_plugin)]
#![plugin(plugins)]
extern crate app_units;
extern crate cssparser;

View file

@ -8,11 +8,10 @@ use std::borrow::ToOwned;
use style::media_queries::*;
use style::stylesheets::{Origin, Stylesheet, CSSRuleIteratorExt};
use style::values::specified;
use url::Url;
fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str) {
let url = Url::parse("http://localhost").unwrap();
let url = url!("http://localhost");
let stylesheet = Stylesheet::from_str(css, url, Origin::Author);
let mut rule_count = 0;
for rule in stylesheet.rules().media() {
@ -23,7 +22,7 @@ fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str)
}
fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
let url = Url::parse("http://localhost").unwrap();
let url = url!("http://localhost");
let ss = Stylesheet::from_str(css, url, Origin::Author);
let rule_count = ss.effective_rules(device).style().count();
assert!(rule_count == expected_rule_count, css.to_owned());

View file

@ -9,7 +9,6 @@ use std::sync::Arc;
use string_cache::Atom;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, DeclaredValue, longhands};
use style::stylesheets::{CSSRule, StyleRule, Origin, Stylesheet};
use url::Url;
#[test]
@ -21,7 +20,7 @@ fn test_parse_stylesheet() {
html , body /**/ { display: block; }
#d1 > .ok { background: blue; }
";
let url = Url::parse("about::test").unwrap();
let url = url!("about::test");
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent);
assert_eq!(stylesheet, Stylesheet {
origin: Origin::UserAgent,

View file

@ -13,13 +13,10 @@ use style::values::specified::LengthOrPercentageOrAuto::{self, Auto};
use style::values::specified::ViewportPercentageLength::Vw;
use style::viewport::*;
use style_traits::viewport::*;
use url::Url;
macro_rules! stylesheet {
($css:expr, $origin:ident) => {
Stylesheet::from_str($css,
Url::parse("http://localhost").unwrap(),
Origin::$origin);
Stylesheet::from_str($css, url!("http://localhost"), Origin::$origin);
}
}
@ -280,7 +277,7 @@ fn multiple_stylesheets_cascading() {
#[test]
fn constrain_viewport() {
let url = Url::parse("http://localhost").unwrap();
let url = url!("http://localhost");
let context = ParserContext::new(Origin::Author, &url);
macro_rules! from_css {