Urlmageddon: Use refcounted urls more often.

This commit is contained in:
Emilio Cobos Álvarez 2016-11-16 11:57:39 +01:00
parent f14e7339b5
commit 913c874cb5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
161 changed files with 1044 additions and 718 deletions

View file

@ -25,4 +25,5 @@ profile_traits = {path = "../../../components/profile_traits"}
time = "0.1"
unicase = "1.0"
url = {version = "1.2", features = ["heap_size"]}
servo_url = {path = "../../../components/url"}
util = {path = "../../../components/util"}

View file

@ -3,10 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use net::test::resolve_chrome_url;
use url::Url;
use servo_url::ServoUrl;
fn c(s: &str) -> Result<Url, ()> {
resolve_chrome_url(&Url::parse(s).unwrap())
fn c(s: &str) -> Result<ServoUrl, ()> {
resolve_chrome_url(&ServoUrl::parse(s).unwrap())
}
#[test]

View file

@ -6,7 +6,7 @@ use cookie_rs;
use net::cookie::Cookie;
use net::cookie_storage::CookieStorage;
use net_traits::CookieSource;
use url::Url;
use servo_url::ServoUrl;
#[test]
fn test_domain_match() {
@ -56,9 +56,9 @@ fn test_default_path() {
fn fn_cookie_constructor() {
use net_traits::CookieSource;
let url = &Url::parse("http://example.com/foo").unwrap();
let url = &ServoUrl::parse("http://example.com/foo").unwrap();
let gov_url = &Url::parse("http://gov.ac/foo").unwrap();
let gov_url = &ServoUrl::parse("http://gov.ac/foo").unwrap();
// cookie name/value test
assert!(cookie_rs::Cookie::parse(" baz ").is_err());
assert!(cookie_rs::Cookie::parse(" = bar ").is_err());
@ -94,7 +94,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 = &ServoUrl::parse("http://example.com/foobar").unwrap();
let cookie = cookie_rs::Cookie::parse("foobar=value;path=/").unwrap();
assert!(Cookie::new_wrapped(cookie, u, CookieSource::HTTP).is_some());
}
@ -117,7 +117,7 @@ fn delay_to_ensure_different_timestamp() {
fn test_sort_order() {
use std::cmp::Ordering;
let url = &Url::parse("http://example.com/foo").unwrap();
let url = &ServoUrl::parse("http://example.com/foo").unwrap();
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();
delay_to_ensure_different_timestamp();

View file

@ -6,12 +6,12 @@ use hyper::header::{Header, SetCookie};
use net::cookie::Cookie;
use net::cookie_storage::CookieStorage;
use net_traits::CookieSource;
use url::Url;
use servo_url::ServoUrl;
fn run(set_location: &str, set_cookies: &[&str], final_location: &str) -> String {
let mut storage = CookieStorage::new();
let url = Url::parse(set_location).unwrap();
let url = ServoUrl::parse(set_location).unwrap();
let source = CookieSource::HTTP;
// Add all cookies to the store
@ -28,7 +28,7 @@ fn run(set_location: &str, set_cookies: &[&str], final_location: &str) -> String
}
// Get cookies for the test location
let url = Url::parse(final_location).unwrap();
let url = ServoUrl::parse(final_location).unwrap();
storage.cookies_for_url(&url, source).unwrap_or("".to_string())
}

View file

@ -9,15 +9,15 @@ use hyper_serde::Serde;
use net_traits::{FetchMetadata, FilteredMetadata, NetworkError};
use net_traits::request::{Origin, Request};
use net_traits::response::ResponseBody;
use servo_url::ServoUrl;
use std::ops::Deref;
use url::Url;
#[cfg(test)]
fn assert_parse(url: &'static str,
content_type: Option<ContentType>,
charset: Option<&str>,
data: Option<&[u8]>) {
let url = Url::parse(url).unwrap();
let url = ServoUrl::parse(url).unwrap();
let origin = Origin::Origin(url.origin());
let request = Request::new(url, Some(origin), false, None);

View file

@ -25,6 +25,7 @@ use net::fetch::methods::{fetch, fetch_with_cors_cache};
use net_traits::ReferrerPolicy;
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
use servo_url::ServoUrl;
use std::fs::File;
use std::io::Read;
use std::rc::Rc;
@ -33,7 +34,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{Sender, channel};
use time::{self, Duration};
use unicase::UniCase;
use url::{Origin as UrlOrigin, Url};
use url::Origin as UrlOrigin;
use util::resource_files::resources_dir_path;
// TODO write a struct that impls Handler for storing test values
@ -84,7 +85,7 @@ fn test_fetch_response_body_matches_const_message() {
#[test]
fn test_fetch_aboutblank() {
let url = Url::parse("about:blank").unwrap();
let url = ServoUrl::parse("about:blank").unwrap();
let origin = Origin::Origin(url.origin());
let request = Request::new(url, Some(origin), false, None);
*request.referrer.borrow_mut() = Referrer::NoReferrer;
@ -109,13 +110,13 @@ fn test_fetch_blob() {
bytes: bytes.to_vec(),
};
let origin = Url::parse("http://www.example.org/").unwrap();
let origin = ServoUrl::parse("http://www.example.org/").unwrap();
let (sender, receiver) = ipc::channel().unwrap();
let message = FileManagerThreadMsg::PromoteMemory(blob_buf, true, sender, "http://www.example.org".into());
context.filemanager.handle(message, None);
let id = receiver.recv().unwrap().unwrap();
let url = Url::parse(&format!("blob:{}{}", origin.as_str(), id.simple())).unwrap();
let url = ServoUrl::parse(&format!("blob:{}{}", origin.as_str(), id.simple())).unwrap();
let request = Request::new(url, Some(Origin::Origin(origin.origin())), false, None);
@ -140,7 +141,7 @@ fn test_fetch_file() {
let mut path = resources_dir_path().expect("Cannot find resource dir");
path.push("servo.css");
let url = Url::from_file_path(path.clone()).unwrap();
let url = ServoUrl::from_file_path(path.clone()).unwrap();
let origin = Origin::Origin(url.origin());
let request = Request::new(url, Some(origin), false, None);
@ -454,7 +455,7 @@ fn test_fetch_with_local_urls_only() {
};
let (mut server, server_url) = make_server(handler);
let do_fetch = |url: Url| {
let do_fetch = |url: ServoUrl| {
let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), false, None);
*request.referrer.borrow_mut() = Referrer::NoReferrer;
@ -465,7 +466,7 @@ fn test_fetch_with_local_urls_only() {
fetch_sync(request, None)
};
let local_url = Url::parse("about:blank").unwrap();
let local_url = ServoUrl::parse("about:blank").unwrap();
let local_response = do_fetch(local_url);
let server_response = do_fetch(server_url);

View file

@ -34,6 +34,7 @@ use net_traits::{CustomResponse, LoadOrigin, Metadata, NetworkError, ReferrerPol
use net_traits::request::{Request, RequestInit, CredentialsMode, Destination};
use net_traits::response::ResponseBody;
use new_fetch_context;
use servo_url::ServoUrl;
use std::borrow::Cow;
use std::io::{self, Cursor, Read, Write};
use std::rc::Rc;
@ -41,14 +42,13 @@ use std::sync::{Arc, Mutex, RwLock, mpsc};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::Receiver;
use std::thread;
use url::Url;
const DEFAULT_USER_AGENT: &'static str = "Test-agent";
struct HttpTest;
impl LoadOrigin for HttpTest {
fn referrer_url(&self) -> Option<Url> {
fn referrer_url(&self) -> Option<ServoUrl> {
None
}
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
@ -65,8 +65,8 @@ struct LoadOriginInfo<'a> {
}
impl<'a> LoadOrigin for LoadOriginInfo<'a> {
fn referrer_url(&self) -> Option<Url> {
Some(Url::parse(self.referrer_url).unwrap())
fn referrer_url(&self) -> Option<ServoUrl> {
Some(ServoUrl::parse(self.referrer_url).unwrap())
}
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
self.referrer_policy.clone()
@ -245,7 +245,7 @@ struct AssertAuthHeaderRequestFactory {
impl HttpRequestFactory for AssertAuthHeaderRequestFactory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
let request = if headers.has::<Authorization<Basic>>() {
assert_headers_included(&self.expected_headers, &headers);
MockRequest::new(ResponseType::Text(self.body.clone()))
@ -276,7 +276,7 @@ struct AssertMustIncludeHeadersRequestFactory {
impl HttpRequestFactory for AssertMustIncludeHeadersRequestFactory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
assert_headers_included(&self.expected_headers, &headers);
Ok(MockRequest::new(ResponseType::Text(self.body.clone())))
}
@ -284,7 +284,7 @@ impl HttpRequestFactory for AssertMustIncludeHeadersRequestFactory {
fn assert_cookie_for_domain(cookie_jar: Arc<RwLock<CookieStorage>>, domain: &str, cookie: Option<&str>) {
let mut cookie_jar = cookie_jar.write().unwrap();
let url = Url::parse(&*domain).unwrap();
let url = ServoUrl::parse(&*domain).unwrap();
let cookies = cookie_jar.cookies_for_url(&url, CookieSource::HTTP);
assert_eq!(cookies.as_ref().map(|c| &**c), cookie);
}
@ -297,7 +297,7 @@ struct AssertMustNotIncludeHeadersRequestFactory {
impl HttpRequestFactory for AssertMustNotIncludeHeadersRequestFactory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
assert!(self.headers_not_expected.len() != 0);
for header in &self.headers_not_expected {
assert!(headers.get_raw(header).is_none());
@ -760,7 +760,7 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
let content = <[_]>::to_vec("Yay!".as_bytes());
let mut headers = Headers::new();
headers.set(StrictTransportSecurity::excluding_subdomains(31536000));
@ -768,7 +768,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 = ServoUrl::parse("https://mozilla.com").unwrap();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
@ -857,8 +857,8 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
#[test]
fn test_load_sends_secure_cookie_if_http_changed_to_https_due_to_entry_in_hsts_store() {
let url = Url::parse("http://mozilla.com").unwrap();
let secured_url = Url::parse("https://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let secured_url = ServoUrl::parse("https://mozilla.com").unwrap();
let ui_provider = TestProvider::new();
let http_state = HttpState::new();
{
@ -1005,8 +1005,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 = ServoUrl::parse("https://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
let ui_provider = TestProvider::new();
@ -1173,7 +1173,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
#[test]
fn test_load_errors_when_there_a_redirect_loop() {
let url_b_for_a = Arc::new(Mutex::new(None::<Url>));
let url_b_for_a = Arc::new(Mutex::new(None::<ServoUrl>));
let url_b_for_a_clone = url_b_for_a.clone();
let handler_a = move |_: HyperRequest, mut response: HyperResponse| {
response.headers_mut().set(Location(url_b_for_a_clone.lock().unwrap().as_ref().unwrap().to_string()));
@ -1211,7 +1211,7 @@ fn test_load_errors_when_there_a_redirect_loop() {
#[test]
fn test_load_succeeds_with_a_redirect_loop() {
let url_b_for_a = Arc::new(Mutex::new(None::<Url>));
let url_b_for_a = Arc::new(Mutex::new(None::<ServoUrl>));
let url_b_for_a_clone = url_b_for_a.clone();
let handled_a = AtomicBool::new(false);
let handler_a = move |_: HyperRequest, mut response: HyperResponse| {
@ -1262,7 +1262,7 @@ fn test_load_follows_a_redirect() {
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, url: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, url: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
if url.domain().unwrap() == "mozilla.com" {
Ok(MockRequest::new(ResponseType::Redirect("http://mozilla.org".to_owned())))
} else if url.domain().unwrap() == "mozilla.org" {
@ -1279,7 +1279,7 @@ fn test_load_follows_a_redirect() {
}
}
let url = Url::parse("http://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
let http_state = HttpState::new();
let ui_provider = TestProvider::new();
@ -1299,14 +1299,14 @@ struct DontConnectFactory;
impl HttpRequestFactory for DontConnectFactory {
type R = MockRequest;
fn create(&self, url: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, url: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
Err(LoadError::new(url, LoadErrorType::Connection { reason: "should not have connected".into() }))
}
}
#[test]
fn test_load_errors_when_scheme_is_not_http_or_https() {
let url = Url::parse("ftp://not-supported").unwrap();
let url = ServoUrl::parse("ftp://not-supported").unwrap();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
let http_state = HttpState::new();
@ -1325,7 +1325,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 = ServoUrl::parse("view-source:ftp://not-supported").unwrap();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
let http_state = HttpState::new();
@ -1353,7 +1353,7 @@ fn test_load_errors_when_cancelled() {
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
let mut headers = Headers::new();
headers.set(Host { hostname: "Kaboom!".to_owned(), port: None });
Ok(MockRequest::new(
@ -1368,7 +1368,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 = ServoUrl::parse("https://mozilla.com").unwrap();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
let http_state = HttpState::new();
let ui_provider = TestProvider::new();
@ -1386,15 +1386,15 @@ fn test_load_errors_when_cancelled() {
#[test]
fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
let url_x = Url::parse("http://mozilla.com").unwrap();
let url_y = Url::parse("http://mozilla.org").unwrap();
let url_x = ServoUrl::parse("http://mozilla.com").unwrap();
let url_y = ServoUrl::parse("http://mozilla.org").unwrap();
struct Factory;
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, url: Url, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, url: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
if url.domain().unwrap() == "mozilla.com" {
let mut expected_headers_x = Headers::new();
expected_headers_x.set_raw("Cookie".to_owned(),
@ -1459,14 +1459,14 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
#[test]
fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
let url = Url::parse("http://mozilla.org/initial/").unwrap();
let url = ServoUrl::parse("http://mozilla.org/initial/").unwrap();
struct Factory;
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, url: Url, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, url: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
if url.path_segments().unwrap().next().unwrap() == "initial" {
let mut initial_answer_headers = Headers::new();
initial_answer_headers.set_raw("set-cookie", vec![b"mozillaIs=theBest; path=/;".to_vec()]);
@ -1505,7 +1505,7 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
#[test]
fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
let ui_provider = TestProvider::new();
@ -1541,7 +1541,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
#[test]
fn test_auth_ui_sets_header_on_401() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
let ui_provider = TestProvider { username: "test".to_owned(), password: "test".to_owned() };
@ -1574,7 +1574,7 @@ fn test_auth_ui_sets_header_on_401() {
#[test]
fn test_auth_ui_needs_www_auth() {
let url = Url::parse("http://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
struct AuthProvider;
impl UIProvider for AuthProvider {
@ -1588,7 +1588,7 @@ fn test_auth_ui_needs_www_auth() {
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
Ok(MockRequest::new(ResponseType::NeedsAuth(Headers::new())))
}
}
@ -1610,7 +1610,7 @@ fn test_auth_ui_needs_www_auth() {
fn assert_referrer_header_matches(origin_info: &LoadOrigin,
request_url: &str,
expected_referrer: &str) {
let url = Url::parse(request_url).unwrap();
let url = ServoUrl::parse(request_url).unwrap();
let ui_provider = TestProvider::new();
let load_data = LoadData::new(LoadContext::Browsing,
@ -1631,7 +1631,7 @@ fn assert_referrer_header_matches(origin_info: &LoadOrigin,
}
fn assert_referrer_header_not_included(origin_info: &LoadOrigin, request_url: &str) {
let url = Url::parse(request_url).unwrap();
let url = ServoUrl::parse(request_url).unwrap();
let ui_provider = TestProvider::new();
let load_data = LoadData::new(LoadContext::Browsing,
@ -2039,7 +2039,7 @@ fn load_request_for_custom_response(expected_body: Vec<u8>) -> (Metadata, String
struct Factory;
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, _: Url, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
Ok(MockRequest::new(ResponseType::Dummy404))
}
}
@ -2049,7 +2049,7 @@ fn load_request_for_custom_response(expected_body: Vec<u8>) -> (Metadata, String
RawStatus(200, Cow::Borrowed("OK")),
expected_body
);
let url = Url::parse("http://mozilla.com").unwrap();
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
let ui_provider = TestProvider::new();
let load_data = LoadData::new(LoadContext::Browsing, url.clone(), &HttpTest);
@ -2087,13 +2087,13 @@ fn test_content_blocked() {
impl HttpRequestFactory for Factory {
type R = MockRequest;
fn create(&self, _url: Url, _method: Method, _: Headers) -> Result<MockRequest, LoadError> {
fn create(&self, _url: ServoUrl, _method: Method, _: Headers) -> Result<MockRequest, LoadError> {
Ok(MockRequest::new(ResponseType::Text(<[_]>::to_vec("Yay!".as_bytes()))))
}
}
let blocked_url = Url::parse("http://mozilla.com").unwrap();
let url_without_cookies = Url::parse("http://mozilla2.com").unwrap();
let blocked_url = ServoUrl::parse("http://mozilla.com").unwrap();
let url_without_cookies = ServoUrl::parse("http://mozilla2.com").unwrap();
let mut http_state = HttpState::new();
let blocked_content_list = "[{ \"trigger\": { \"url-filter\": \"https?://mozilla.com\" }, \

View file

@ -16,6 +16,7 @@ extern crate msg;
extern crate net;
extern crate net_traits;
extern crate profile_traits;
extern crate servo_url;
extern crate time;
extern crate unicase;
extern crate url;
@ -42,10 +43,10 @@ use net::test::HttpState;
use net_traits::FetchTaskTarget;
use net_traits::request::Request;
use net_traits::response::Response;
use servo_url::ServoUrl;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::thread;
use url::Url;
const DEFAULT_USER_AGENT: &'static str = "Such Browser. Very Layout. Wow.";
@ -82,10 +83,10 @@ fn fetch_sync(request: Request, dc: Option<Sender<DevtoolsControlMsg>>) -> Respo
fetch(Rc::new(request), &mut None, &new_fetch_context(dc))
}
fn make_server<H: Handler + 'static>(handler: H) -> (Listening, Url) {
fn make_server<H: Handler + 'static>(handler: H) -> (Listening, ServoUrl) {
// this is a Listening server because of handle_threads()
let server = Server::http("0.0.0.0:0").unwrap().handle_threads(handler, 1).unwrap();
let url_string = format!("http://localhost:{}", server.socket.port());
let url = Url::parse(&url_string).unwrap();
let url = ServoUrl::parse(&url_string).unwrap();
(server, url)
}

View file

@ -9,11 +9,11 @@ use net_traits::{CoreResourceMsg, LoadConsumer, LoadContext, LoadData};
use net_traits::{LoadOrigin, NetworkError, ProgressMsg, ReferrerPolicy};
use net_traits::hosts::{host_replacement, parse_hostsfile};
use profile_traits::time::ProfilerChan;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::net::IpAddr;
use std::sync::mpsc::channel;
use url::Url;
fn ip(s: &str) -> IpAddr {
s.parse().unwrap()
@ -22,7 +22,7 @@ fn ip(s: &str) -> IpAddr {
struct ResourceTest;
impl LoadOrigin for ResourceTest {
fn referrer_url(&self) -> Option<Url> {
fn referrer_url(&self) -> Option<ServoUrl> {
None
}
fn referrer_policy(&self) -> Option<ReferrerPolicy> {
@ -50,7 +50,7 @@ fn test_bad_scheme() {
let (resource_thread, _) = new_core_resource_thread(
"".into(), None, ProfilerChan(tx), None);
let (start_chan, start) = ipc::channel().unwrap();
let url = Url::parse("bogus://whatever").unwrap();
let url = ServoUrl::parse("bogus://whatever").unwrap();
resource_thread.send(CoreResourceMsg::Load(LoadData::new(LoadContext::Browsing, url, &ResourceTest),
LoadConsumer::Channel(start_chan), None)).unwrap();
@ -187,13 +187,13 @@ fn test_replace_hosts() {
host_table.insert("foo.bar.com".to_owned(), ip("127.0.0.1"));
host_table.insert("servo.test.server".to_owned(), ip("127.0.0.2"));
let url = Url::parse("http://foo.bar.com:8000/foo").unwrap();
let url = ServoUrl::parse("http://foo.bar.com:8000/foo").unwrap();
assert_eq!(host_replacement(&host_table, &url).host_str().unwrap(), "127.0.0.1");
let url = Url::parse("http://servo.test.server").unwrap();
let url = ServoUrl::parse("http://servo.test.server").unwrap();
assert_eq!(host_replacement(&host_table, &url).host_str().unwrap(), "127.0.0.2");
let url = Url::parse("http://a.foo.bar.com").unwrap();
let url = ServoUrl::parse("http://a.foo.bar.com").unwrap();
assert_eq!(host_replacement(&host_table, &url).host_str().unwrap(), "a.foo.bar.com");
}
@ -232,7 +232,7 @@ fn test_cancelled_listener() {
let (sender, receiver) = ipc::channel().unwrap();
let (id_sender, id_receiver) = ipc::channel().unwrap();
let (sync_sender, sync_receiver) = ipc::channel().unwrap();
let url = Url::parse(&format!("http://127.0.0.1:{}", port)).unwrap();
let url = ServoUrl::parse(&format!("http://127.0.0.1:{}", port)).unwrap();
resource_thread.send(CoreResourceMsg::Load(LoadData::new(LoadContext::Browsing, url, &ResourceTest),
LoadConsumer::Channel(sender),

View file

@ -13,4 +13,4 @@ doctest = false
msg = {path = "../../../components/msg"}
plugins = {path = "../../../components/plugins"}
script = {path = "../../../components/script"}
url = {version = "1.2", features = ["heap_size"]}
servo_url = {path = "../../../components/url"}

View file

@ -7,7 +7,7 @@
extern crate msg;
extern crate script;
extern crate url;
extern crate servo_url;
#[cfg(test)] mod origin;
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;

View file

@ -3,33 +3,33 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use script::origin::Origin;
use url::Url;
use servo_url::ServoUrl;
#[test]
fn same_origin() {
let a = Origin::new(&Url::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&Url::parse("http://example.com/b.html").unwrap());
let a = Origin::new(&ServoUrl::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&ServoUrl::parse("http://example.com/b.html").unwrap());
assert!(a.same_origin(&b));
assert_eq!(a.is_scheme_host_port_tuple(), true);
}
#[test]
fn identical_origin() {
let a = Origin::new(&Url::parse("http://example.com/a.html").unwrap());
let a = Origin::new(&ServoUrl::parse("http://example.com/a.html").unwrap());
assert!(a.same_origin(&a));
}
#[test]
fn cross_origin() {
let a = Origin::new(&Url::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&Url::parse("http://example.org/b.html").unwrap());
let a = Origin::new(&ServoUrl::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&ServoUrl::parse("http://example.org/b.html").unwrap());
assert!(!a.same_origin(&b));
}
#[test]
fn alias_same_origin() {
let a = Origin::new(&Url::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&Url::parse("http://example.com/b.html").unwrap());
let a = Origin::new(&ServoUrl::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&ServoUrl::parse("http://example.com/b.html").unwrap());
let c = b.alias();
assert!(a.same_origin(&c));
assert!(b.same_origin(&b));
@ -39,8 +39,8 @@ fn alias_same_origin() {
#[test]
fn alias_cross_origin() {
let a = Origin::new(&Url::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&Url::parse("http://example.org/b.html").unwrap());
let a = Origin::new(&ServoUrl::parse("http://example.com/a.html").unwrap());
let b = Origin::new(&ServoUrl::parse("http://example.org/b.html").unwrap());
let c = b.alias();
assert!(!a.same_origin(&c));
assert!(b.same_origin(&c));

View file

@ -21,5 +21,5 @@ html5ever-atoms = "0.1"
servo_atoms = {path = "../../../components/atoms"}
style = {path = "../../../components/style"}
style_traits = {path = "../../../components/style_traits"}
url = {version = "1.2", features = ["heap_size"]}
servo_url = {path = "../../../components/url"}
util = {path = "../../../components/util"}

View file

@ -15,9 +15,9 @@ extern crate parking_lot;
extern crate rustc_serialize;
extern crate selectors;
#[macro_use] extern crate servo_atoms;
extern crate servo_url;
extern crate style;
extern crate style_traits;
extern crate url;
extern crate util;
mod atomic_refcell;

View file

@ -5,6 +5,7 @@
use app_units::Au;
use cssparser::{Parser, SourcePosition};
use euclid::size::TypedSize2D;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use style::Atom;
use style::error_reporting::ParseErrorReporter;
@ -12,7 +13,6 @@ use style::media_queries::*;
use style::parser::ParserContextExtraData;
use style::stylesheets::{Stylesheet, Origin, CssRule};
use style::values::specified;
use url::Url;
pub struct CSSErrorReporterTest;
@ -25,7 +25,7 @@ impl ParseErrorReporter for CSSErrorReporterTest {
}
fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaList, &str) {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let mut rule_count = 0;
@ -48,7 +48,7 @@ fn media_queries<F>(rules: &[CssRule], f: &mut F) where F: FnMut(&MediaList) {
}
fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let ss = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let mut rule_count = 0;

View file

@ -4,16 +4,16 @@
use cssparser::Parser;
use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
use style::properties::longhands::{border_image_source, border_image_width};
use style::properties::shorthands::border_image;
use style::stylesheets::Origin;
use url::Url;
#[test]
fn border_image_shorhand_should_parse_when_all_properties_specified() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px \
round stretch");
@ -29,7 +29,7 @@ fn border_image_shorhand_should_parse_when_all_properties_specified() {
#[test]
fn border_image_shorhand_should_parse_without_width() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -44,7 +44,7 @@ fn border_image_shorhand_should_parse_without_width() {
#[test]
fn border_image_shorhand_should_parse_without_outset() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -59,7 +59,7 @@ fn border_image_shorhand_should_parse_without_outset() {
#[test]
fn border_image_shorhand_should_parse_without_width_or_outset() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -74,7 +74,7 @@ fn border_image_shorhand_should_parse_without_width_or_outset() {
#[test]
fn border_image_shorhand_should_parse_with_just_source() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue)");
let result = border_image::parse_value(&context, &mut parser).unwrap();

View file

@ -4,13 +4,13 @@
use cssparser::Parser;
use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::font_feature_settings;
use style::properties::longhands::font_feature_settings::computed_value;
use style::properties::longhands::font_feature_settings::computed_value::FeatureTagValue;
use style::stylesheets::Origin;
use style_traits::ToCss;
use url::Url;
#[test]
fn font_feature_settings_should_parse_properly() {
@ -52,7 +52,7 @@ fn font_feature_settings_should_parse_properly() {
#[test]
fn font_feature_settings_should_throw_on_bad_input() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut empty = Parser::new("");

View file

@ -8,7 +8,6 @@ use style::parser::ParserContext;
use style::stylesheets::Origin;
use style::values::specified::image::*;
use style_traits::ToCss;
use url::Url;
#[test]
fn test_linear_gradient() {

View file

@ -6,7 +6,6 @@ use cssparser::Parser;
use media_queries::CSSErrorReporterTest;
use style::parser::ParserContext;
use style::stylesheets::Origin;
use url::Url;
#[test]
fn text_emphasis_style_longhand_should_parse_properly() {

View file

@ -4,16 +4,16 @@
use cssparser::Parser;
use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::{mask_clip, mask_composite, mask_image, mask_mode};
use style::properties::longhands::{mask_origin, mask_position, mask_repeat, mask_size};
use style::properties::shorthands::mask;
use style::stylesheets::Origin;
use url::Url;
#[test]
fn mask_shorthand_should_parse_all_available_properties_when_specified() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px \
repeat-x padding-box border-box subtract");
@ -31,7 +31,7 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() {
#[test]
fn mask_shorthand_should_parse_when_some_fields_set() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("14px 40px repeat-y");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -59,7 +59,7 @@ fn mask_shorthand_should_parse_when_some_fields_set() {
#[test]
fn mask_shorthand_should_parse_position_and_size_correctly() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("7px 4px");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -81,7 +81,7 @@ fn mask_shorthand_should_parse_position_and_size_correctly() {
#[test]
fn mask_shorthand_should_parse_origin_and_clip_correctly() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("padding-box content-box");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -104,7 +104,7 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() {
#[test]
fn mask_shorthand_should_not_parse_when_mode_specified_but_image_not() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("luminance 7px 4px repeat-x padding");
assert!(mask::parse_value(&context, &mut parser).is_err());

View file

@ -36,7 +36,7 @@ macro_rules! assert_roundtrip_with_context {
assert_roundtrip_with_context!($fun, $string, $string);
};
($fun:expr,$input:expr, $output:expr) => {
let url = Url::parse("http://localhost").unwrap();
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new($input);
let parsed = $fun(&context, &mut parser)
@ -55,7 +55,7 @@ macro_rules! assert_roundtrip_with_context {
macro_rules! parse_longhand {
($name:ident, $s:expr) => {{
let url = Url::parse("http://localhost").unwrap();
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
$name::parse(&context, &mut Parser::new($s)).unwrap()
}};

View file

@ -8,6 +8,7 @@ use media_queries::CSSErrorReporterTest;
use parking_lot::RwLock;
use selectors::parser::*;
use servo_atoms::Atom;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::sync::Arc;
use std::sync::Mutex;
@ -19,7 +20,6 @@ use style::properties::Importance;
use style::properties::longhands::animation_play_state;
use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, StyleRule, KeyframesRule, Origin};
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
use url::Url;
#[test]
fn test_parse_stylesheet() {
@ -48,7 +48,7 @@ fn test_parse_stylesheet() {
animation-play-state: running; /* … except animation-play-state */
}
}";
let url = Url::parse("about::test").unwrap();
let url = ServoUrl::parse("about::test").unwrap();
let stylesheet = Stylesheet::from_str(css, url, Origin::UserAgent,
Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
@ -315,7 +315,7 @@ fn test_report_error_stylesheet() {
invalid: true;
}
";
let url = Url::parse("about::test").unwrap();
let url = ServoUrl::parse("about::test").unwrap();
let error_reporter = Box::new(CSSInvalidErrorReporterTest::new());
let errors = error_reporter.errors.clone();

View file

@ -6,6 +6,7 @@ use cssparser::Parser;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use media_queries::CSSErrorReporterTest;
use servo_url::ServoUrl;
use style::error_reporting::ParseErrorReporter;
use style::media_queries::{Device, MediaType};
use style::parser::{ParserContext, ParserContextExtraData};
@ -15,13 +16,12 @@ 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, $error_reporter:expr) => {
Box::new(Stylesheet::from_str(
$css,
Url::parse("http://localhost").unwrap(),
ServoUrl::parse("http://localhost").unwrap(),
Origin::$origin,
$error_reporter,
ParserContextExtraData::default()
@ -279,7 +279,7 @@ fn multiple_stylesheets_cascading() {
#[test]
fn constrain_viewport() {
let url = Url::parse("http://localhost").unwrap();
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
macro_rules! from_css {

View file

@ -22,7 +22,7 @@ log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "1.1.0"
parking_lot = "0.3"
selectors = "0.14"
url = "1.2"
servo_url = {path = "../../../components/url"}
style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"}
style = {path = "../../../components/style", features = ["gecko"]}

View file

@ -10,9 +10,9 @@ extern crate geckoservo;
extern crate libc;
#[macro_use] extern crate log;
extern crate parking_lot;
extern crate servo_url;
extern crate style;
extern crate style_traits;
extern crate url;
mod sanity_checks;