aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/compositing/constellation.rs2
-rw-r--r--components/plugins/Cargo.toml3
-rw-r--r--components/plugins/lib.rs4
-rw-r--r--components/plugins/url_plugin.rs141
-rw-r--r--components/script/dom/document.rs2
-rw-r--r--components/script/dom/htmliframeelement.rs2
-rw-r--r--components/script/script_task.rs2
-rw-r--r--components/servo/Cargo.lock12
-rw-r--r--components/servo/Cargo.toml3
-rw-r--r--components/style/font_face.rs2
-rw-r--r--components/style/parser.rs2
-rw-r--r--components/style/selector_matching.rs2
-rw-r--r--components/util/opts.rs2
-rw-r--r--ports/cef/Cargo.lock1
-rw-r--r--ports/gonk/Cargo.lock1
-rw-r--r--tests/unit/net/Cargo.toml3
-rw-r--r--tests/unit/net/cookie.rs9
-rw-r--r--tests/unit/net/data_loader.rs14
-rw-r--r--tests/unit/net/hsts.rs51
-rw-r--r--tests/unit/net/http_loader.rs136
-rw-r--r--tests/unit/net/lib.rs3
-rw-r--r--tests/unit/net/resource_task.rs8
-rw-r--r--tests/unit/plugin/Cargo.toml15
-rw-r--r--tests/unit/plugin/lib.rs11
-rw-r--r--tests/unit/plugin/url_plugin.rs24
-rw-r--r--tests/unit/style/Cargo.toml3
-rw-r--r--tests/unit/style/lib.rs1
-rw-r--r--tests/unit/style/media_queries.rs5
-rw-r--r--tests/unit/style/stylesheets.rs3
-rw-r--r--tests/unit/style/viewport.rs7
30 files changed, 346 insertions, 128 deletions
diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs
index 2084ace9701..1055aabaa26 100644
--- a/components/compositing/constellation.rs
+++ b/components/compositing/constellation.rs
@@ -701,7 +701,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
parent_info,
window_size,
None,
- LoadData::new(Url::parse("about:failure").unwrap()));
+ LoadData::new(url!("about:failure")));
self.push_pending_frame(new_pipeline_id, Some(pipeline_id));
}
diff --git a/components/plugins/Cargo.toml b/components/plugins/Cargo.toml
index 9e317316984..f697fe45cf7 100644
--- a/components/plugins/Cargo.toml
+++ b/components/plugins/Cargo.toml
@@ -16,5 +16,8 @@ git = "https://github.com/Manishearth/rust-clippy"
branch = "servo"
optional = true
+[dependencies.url]
+version = "0.2.36"
+
[features]
default = []
diff --git a/components/plugins/lib.rs b/components/plugins/lib.rs
index bb328c9441a..d52ad866879 100644
--- a/components/plugins/lib.rs
+++ b/components/plugins/lib.rs
@@ -26,6 +26,8 @@ extern crate tenacious;
#[cfg(feature = "clippy")]
extern crate clippy;
+extern crate url;
+
use rustc::plugin::Registry;
use syntax::ext::base::*;
use syntax::feature_gate::AttributeType::Whitelisted;
@@ -41,6 +43,7 @@ pub mod lints;
pub mod reflector;
/// Utilities for writing plugins
pub mod casing;
+mod url_plugin;
pub mod utils;
#[plugin_registrar]
@@ -51,6 +54,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_syntax_extension(intern("derive_HeapSizeOf"), MultiDecorator(box heap_size::expand_heap_size));
reg.register_macro("to_lower", casing::expand_lower);
reg.register_macro("to_upper", casing::expand_upper);
+ reg.register_macro("url", url_plugin::expand_url);
reg.register_late_lint_pass(box lints::transmute_type::TransmutePass);
reg.register_late_lint_pass(box lints::unrooted_must_root::UnrootedPass::new());
reg.register_late_lint_pass(box lints::privatize::PrivatizePass);
diff --git a/components/plugins/url_plugin.rs b/components/plugins/url_plugin.rs
new file mode 100644
index 00000000000..8ae06624c4b
--- /dev/null
+++ b/components/plugins/url_plugin.rs
@@ -0,0 +1,141 @@
+/* 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 std::error::Error;
+use syntax;
+use syntax::ast::{TokenTree, ExprLit, LitStr, Expr};
+use syntax::codemap::Span;
+use syntax::ext::base::{ExtCtxt, MacResult, MacEager, DummyResult};
+use syntax::ext::build::AstBuilder;
+use syntax::fold::Folder;
+use syntax::parse;
+use syntax::parse::token::InternedString;
+use url::{Url, Host, RelativeSchemeData, SchemeData};
+
+pub fn expand_url(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
+ -> Box<MacResult + 'static> {
+ let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_vec());
+ let query_expr = cx.expander().fold_expr(parser.parse_expr());
+
+ // Ensure a str literal was passed to the macro
+ let query = match parse_str_lit(&query_expr) {
+ Some(query) => query,
+ None => {
+ cx.span_err(query_expr.span, "'url!' expected string literal");
+ return DummyResult::any(sp)
+ },
+ };
+
+ // Parse the str literal
+ let Url { scheme, scheme_data, query, fragment } = match Url::parse(&query) {
+ Ok(url) => url,
+ Err(error) => {
+ cx.span_err(query_expr.span, error.description());
+ return DummyResult::any(sp)
+ }
+ };
+
+ let scheme_data_expr = cx.expr_scheme_data(sp, scheme_data);
+ let query_expr = cx.expr_option_string(sp, query);
+ let fragment_expr = cx.expr_option_string(sp, fragment);
+
+ let url_expr = quote_expr!(cx, {
+ ::url::Url {
+ scheme: $scheme.to_owned(),
+ scheme_data: $scheme_data_expr,
+ query: $query_expr,
+ fragment: $fragment_expr,
+ }
+ });
+
+ MacEager::expr(url_expr)
+}
+
+fn parse_str_lit(e: &Expr) -> Option<InternedString> {
+ if let ExprLit(ref lit) = e.node {
+ if let LitStr(ref s, _) = lit.node {
+ return Some(s.clone());
+ }
+ }
+ None
+}
+
+trait ExtCtxtHelpers {
+ fn expr_scheme_data(&self, sp: Span, scheme_data: SchemeData) -> syntax::ptr::P<Expr>;
+ fn expr_option_string(&self, sp: Span, string: Option<String>) -> syntax::ptr::P<Expr>;
+ fn expr_option_u16(&self, sp: Span, unsigned: Option<u16>) -> syntax::ptr::P<Expr>;
+ fn expr_host(&self, sp: Span, host: Host) -> syntax::ptr::P<Expr>;
+ fn expr_slice_u16(&self, sp: Span, unsigned: &[u16]) -> syntax::ptr::P<Expr>;
+ fn expr_vec_string(&self, sp: Span, strings: Vec<String>) -> syntax::ptr::P<Expr>;
+}
+
+impl<'a> ExtCtxtHelpers for ExtCtxt<'a> {
+ fn expr_scheme_data(&self, sp: Span, scheme_data: SchemeData) -> syntax::ptr::P<Expr> {
+ match scheme_data {
+ SchemeData::Relative(
+ RelativeSchemeData { username, password, host, port, default_port, path }) =>
+ {
+ let password_expr = self.expr_option_string(sp, password);
+ let host_expr = self.expr_host(sp, host);
+ let port_expr = self.expr_option_u16(sp, port);
+ let default_port_expr = self.expr_option_u16(sp, default_port);
+ let path_expr = self.expr_vec_string(sp, path);
+
+ quote_expr!(self,
+ ::url::SchemeData::Relative(
+ ::url::RelativeSchemeData {
+ username: $username.to_owned(),
+ password: $password_expr,
+ host: $host_expr,
+ port: $port_expr,
+ default_port: $default_port_expr,
+ path: $path_expr.to_owned(),
+ }
+ ))
+ },
+ SchemeData::NonRelative(ref scheme_data) => {
+ quote_expr!(self, ::url::SchemeData::NonRelative($scheme_data.to_owned()))
+ },
+ }
+ }
+
+ fn expr_option_string(&self, sp: Span, string: Option<String>) -> syntax::ptr::P<Expr> {
+ match string {
+ Some(string) => quote_expr!(self, Some($string.to_owned())),
+ None => self.expr_none(sp),
+ }
+ }
+
+ fn expr_option_u16(&self, sp: Span, unsigned: Option<u16>) -> syntax::ptr::P<Expr> {
+ match unsigned {
+ Some(unsigned) => quote_expr!(self, Some($unsigned)),
+ None => self.expr_none(sp),
+ }
+ }
+
+ fn expr_host(&self, sp: Span, host: Host) -> syntax::ptr::P<Expr> {
+ match host {
+ Host::Domain(domain) => quote_expr!(self, ::url::Host::Domain(String::from($domain))),
+ Host::Ipv6(address) => {
+ let pieces_expr = self.expr_slice_u16(sp, &address.pieces);
+ quote_expr!(self,
+ ::url::Host::Ipv6(
+ ::url::Ipv6Address {
+ pieces: $pieces_expr.to_owned()
+ }
+ ))
+ },
+ }
+ }
+
+ fn expr_slice_u16(&self, sp: Span, unsigned: &[u16]) -> syntax::ptr::P<Expr> {
+ let unsigned = unsigned.iter().map(|p| quote_expr!(self, $p)).collect();
+ self.expr_vec_slice(sp, unsigned)
+ }
+
+ fn expr_vec_string(&self, sp: Span, strings: Vec<String>) -> syntax::ptr::P<Expr> {
+ let strings = strings.iter().map(|p| quote_expr!(self, $p.to_owned())).collect();
+ self.expr_vec(sp, strings)
+ }
+}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 585b93f1912..34a7846b543 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -1388,7 +1388,7 @@ impl Document {
source: DocumentSource,
doc_loader: DocumentLoader)
-> Document {
- let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
+ let url = url.unwrap_or_else(|| url!("about:blank"));
let (ready_state, domcontentloaded_dispatched) = if source == DocumentSource::FromParser {
(DocumentReadyState::Loading, false)
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index b3e62ef434b..7d14dfe916d 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -124,7 +124,7 @@ impl HTMLIFrameElement {
pub fn process_the_iframe_attributes(&self) {
let url = match self.get_url() {
Some(url) => url.clone(),
- None => Url::parse("about:blank").unwrap(),
+ None => url!("about:blank"),
};
self.navigate_child_browsing_context(url);
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index 043c0574be1..dd1cf1a546c 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -1967,7 +1967,7 @@ impl ScriptTask {
};
if load_data.url.scheme == "javascript" {
- load_data.url = Url::parse("about:blank").unwrap();
+ load_data.url = url!("about:blank");
}
resource_task.send(ControlMsg::Load(NetLoadData {
diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock
index 92b083fdf50..b95310c217a 100644
--- a/components/servo/Cargo.lock
+++ b/components/servo/Cargo.lock
@@ -28,6 +28,7 @@ dependencies = [
"net_traits 0.0.1",
"net_traits_tests 0.0.1",
"offscreen_gl_context 0.1.0 (git+https://github.com/ecoal95/rust-offscreen-rendering-context)",
+ "plugin_tests 0.0.1",
"profile 0.0.1",
"profile_traits 0.0.1",
"script 0.0.1",
@@ -1223,6 +1224,7 @@ dependencies = [
"msg 0.0.1",
"net 0.0.1",
"net_traits 0.0.1",
+ "plugins 0.0.1",
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@@ -1389,10 +1391,19 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "plugin_tests"
+version = "0.0.1"
+dependencies = [
+ "plugins 0.0.1",
+ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "plugins"
version = "0.0.1"
dependencies = [
"tenacious 0.0.11 (git+https://github.com/Manishearth/rust-tenacious)",
+ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1770,6 +1781,7 @@ dependencies = [
"app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "plugins 0.0.1",
"selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache_plugin 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml
index b17a137a16c..5d2222b8aa1 100644
--- a/components/servo/Cargo.toml
+++ b/components/servo/Cargo.toml
@@ -29,6 +29,9 @@ path = "../../tests/unit/net"
[dev-dependencies.net_traits_tests]
path = "../../tests/unit/net_traits"
+[dev-dependencies.plugin_tests]
+path = "../../tests/unit/plugin"
+
[dev-dependencies.script_tests]
path = "../../tests/unit/script"
diff --git a/components/style/font_face.rs b/components/style/font_face.rs
index ff4f2993d81..52abb82c3cf 100644
--- a/components/style/font_face.rs
+++ b/components/style/font_face.rs
@@ -112,7 +112,7 @@ fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source,
}
let url = try!(input.expect_url());
let url = UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else(
- |_error| Url::parse("about:invalid").unwrap());
+ |_error| url!("about:invalid"));
// Parsing optional format()
let format_hints = if input.try(|input| input.expect_function_matching("format")).is_ok() {
diff --git a/components/style/parser.rs b/components/style/parser.rs
index f189c7c5d93..67f35fa0976 100644
--- a/components/style/parser.rs
+++ b/components/style/parser.rs
@@ -31,7 +31,7 @@ impl<'a> ParserContext<'a> {
impl<'a> ParserContext<'a> {
pub fn parse_url(&self, input: &str) -> Url {
UrlParser::new().base_url(self.base_url).parse(input)
- .unwrap_or_else(|_| Url::parse("about:invalid").unwrap())
+ .unwrap_or_else(|_| url!("about:invalid"))
}
}
diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs
index e8887163b61..f4b2168fc26 100644
--- a/components/style/selector_matching.rs
+++ b/components/style/selector_matching.rs
@@ -61,7 +61,7 @@ lazy_static! {
Ok(res) => {
Stylesheet::from_bytes(
&res,
- Url::parse("chrome:///quirks-mode.css").unwrap(),
+ url!("chrome:///quirks-mode.css"),
None,
None,
Origin::UserAgent)
diff --git a/components/util/opts.rs b/components/util/opts.rs
index 761568de42d..1b74e142408 100644
--- a/components/util/opts.rs
+++ b/components/util/opts.rs
@@ -440,7 +440,7 @@ const DEFAULT_USER_AGENT: UserAgent = UserAgent::Desktop;
pub fn default_opts() -> Opts {
Opts {
is_running_problem_test: false,
- url: Some(Url::parse("about:blank").unwrap()),
+ url: Some(url!("about:blank")),
paint_threads: 1,
gpu_painting: false,
tile_size: 512,
diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock
index 7178aed16ca..dc3d6efdced 100644
--- a/ports/cef/Cargo.lock
+++ b/ports/cef/Cargo.lock
@@ -1319,6 +1319,7 @@ name = "plugins"
version = "0.0.1"
dependencies = [
"tenacious 0.0.11 (git+https://github.com/Manishearth/rust-tenacious)",
+ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock
index f94e3e5ccc1..d77c6c10ed5 100644
--- a/ports/gonk/Cargo.lock
+++ b/ports/gonk/Cargo.lock
@@ -1299,6 +1299,7 @@ name = "plugins"
version = "0.0.1"
dependencies = [
"tenacious 0.0.11 (git+https://github.com/Manishearth/rust-tenacious)",
+ "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/tests/unit/net/Cargo.toml b/tests/unit/net/Cargo.toml
index 815e7ddff2f..87bd03c1fa6 100644
--- a/tests/unit/net/Cargo.toml
+++ b/tests/unit/net/Cargo.toml
@@ -20,6 +20,9 @@ path = "../../../components/util"
[dependencies.msg]
path = "../../../components/msg"
+[dependencies.plugins]
+path = "../../../components/plugins"
+
[dependencies.devtools_traits]
path = "../../../components/devtools_traits"
diff --git a/tests/unit/net/cookie.rs b/tests/unit/net/cookie.rs
index edf93ba2e05..c2e1486aa3c 100644
--- a/tests/unit/net/cookie.rs
+++ b/tests/unit/net/cookie.rs
@@ -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();
diff --git a/tests/unit/net/data_loader.rs b/tests/unit/net/data_loader.rs
index 588c3c32f0b..828c771238f 100644
--- a/tests/unit/net/data_loader.rs
+++ b/tests/unit/net/data_loader.rs
@@ -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)));
}
diff --git a/tests/unit/net/hsts.rs b/tests/unit/net/hsts.rs
index 1fec5c5e80c..16de7db6203 100644
--- a/tests/unit/net/hsts.rs
+++ b/tests/unit/net/hsts.rs
@@ -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");
diff --git a/tests/unit/net/http_loader.rs b/tests/unit/net/http_loader.rs
index 0d76e7cffb2..ed541b67046 100644
--- a/tests/unit/net/http_loader.rs
+++ b/tests/unit/net/http_loader.rs
@@ -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!")
diff --git a/tests/unit/net/lib.rs b/tests/unit/net/lib.rs
index 3c64ef96157..88cd164e980 100644
--- a/tests/unit/net/lib.rs
+++ b/tests/unit/net/lib.rs
@@ -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;
diff --git a/tests/unit/net/resource_task.rs b/tests/unit/net/resource_task.rs
index 18d6a086e11..c72dc66ba22 100644
--- a/tests/unit/net/resource_task.rs
+++ b/tests/unit/net/resource_task.rs
@@ -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");
}
diff --git a/tests/unit/plugin/Cargo.toml b/tests/unit/plugin/Cargo.toml
new file mode 100644
index 00000000000..3ea2ebd8672
--- /dev/null
+++ b/tests/unit/plugin/Cargo.toml
@@ -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"
diff --git a/tests/unit/plugin/lib.rs b/tests/unit/plugin/lib.rs
new file mode 100644
index 00000000000..6e2a9155081
--- /dev/null
+++ b/tests/unit/plugin/lib.rs
@@ -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;
diff --git a/tests/unit/plugin/url_plugin.rs b/tests/unit/plugin/url_plugin.rs
new file mode 100644
index 00000000000..911a53e84e8
--- /dev/null
+++ b/tests/unit/plugin/url_plugin.rs
@@ -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());
+}
diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml
index 30140cecbd7..2f6b022584e 100644
--- a/tests/unit/style/Cargo.toml
+++ b/tests/unit/style/Cargo.toml
@@ -8,6 +8,9 @@ name = "style_tests"
path = "lib.rs"
doctest = false
+[dependencies.plugins]
+path = "../../../components/plugins"
+
[dependencies.style]
path = "../../../components/style"
diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs
index e3b6684f4b9..9c4f9fba23f 100644
--- a/tests/unit/style/lib.rs
+++ b/tests/unit/style/lib.rs
@@ -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;
diff --git a/tests/unit/style/media_queries.rs b/tests/unit/style/media_queries.rs
index 2841a7b6cda..6a3d79baba4 100644
--- a/tests/unit/style/media_queries.rs
+++ b/tests/unit/style/media_queries.rs
@@ -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());
diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs
index d6a9c6d30ce..7d7e2ad1830 100644
--- a/tests/unit/style/stylesheets.rs
+++ b/tests/unit/style/stylesheets.rs
@@ -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,
diff --git a/tests/unit/style/viewport.rs b/tests/unit/style/viewport.rs
index 31ae0a9e6c2..f3f70fde710 100644
--- a/tests/unit/style/viewport.rs
+++ b/tests/unit/style/viewport.rs
@@ -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 {