mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Devirtualize CSS error reporting.
This commit is contained in:
parent
2e775abfa4
commit
1297c0ff51
28 changed files with 255 additions and 211 deletions
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use parsing::parse;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::{Parse, ParserContext};
|
||||
|
@ -41,8 +40,7 @@ fn test_parsing_modes() {
|
|||
|
||||
// In SVG length mode, non-zero lengths are assumed to be px.
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||
let context = ParserContext::new(Origin::Author, &url,
|
||||
Some(CssRuleType::Style), PARSING_MODE_ALLOW_UNITLESS_LENGTH,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut input = ParserInput::new("1");
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//! Tests for parsing and serialization of values/properties
|
||||
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
|
@ -20,8 +19,7 @@ where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, Parse
|
|||
fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
|
||||
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> {
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
|
||||
let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Style),
|
||||
PARSING_MODE_DEFAULT,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut parser = Parser::new(input);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use app_units::Au;
|
||||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::ParserContext;
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
|
@ -23,8 +22,7 @@ fn length_has_viewport_percentage() {
|
|||
fn test_parsing_allo_all_numeric_values() {
|
||||
// In SVG length mode, non-zero lengths are assumed to be px.
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter,
|
||||
let context = ParserContext::new(Origin::Author, &url,
|
||||
Some(CssRuleType::Style), PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES,
|
||||
QuirksMode::NoQuirks);
|
||||
let mut input = ParserInput::new("-1");
|
||||
|
|
|
@ -7,5 +7,5 @@ use style::properties::longhands::background_size;
|
|||
|
||||
#[test]
|
||||
fn background_size_should_reject_negative_values() {
|
||||
assert!(parse(background_size::parse, "-40% -40%").is_err());
|
||||
assert!(parse(|c, _, i| background_size::parse(c, i), "-40% -40%").is_err());
|
||||
}
|
||||
|
|
|
@ -5,25 +5,32 @@
|
|||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{ParserContext, ParserErrorContext};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ParseError};
|
||||
|
||||
fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>>
|
||||
where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, ParseError<'static>> {
|
||||
where F: for<'t> Fn(&ParserContext,
|
||||
&ParserErrorContext<CSSErrorReporterTest>,
|
||||
&mut Parser<'static, 't>) -> Result<T, ParseError<'static>>
|
||||
{
|
||||
let mut input = ParserInput::new(s);
|
||||
parse_input(f, &mut input)
|
||||
}
|
||||
|
||||
fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
|
||||
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> {
|
||||
where F: Fn(&ParserContext,
|
||||
&ParserErrorContext<CSSErrorReporterTest>,
|
||||
&mut Parser<'i, 't>) -> Result<T, ParseError<'i>>
|
||||
{
|
||||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
|
||||
let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Style),
|
||||
PARSING_MODE_DEFAULT,
|
||||
QuirksMode::NoQuirks);
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let error_context = ParserErrorContext { error_reporter: &reporter };
|
||||
let mut parser = Parser::new(input);
|
||||
f(&context, &mut parser)
|
||||
f(&context, &error_context, &mut parser)
|
||||
}
|
||||
|
||||
macro_rules! assert_roundtrip_with_context {
|
||||
|
@ -31,7 +38,7 @@ macro_rules! assert_roundtrip_with_context {
|
|||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let serialized = parse(|context, _, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
|
@ -40,7 +47,7 @@ macro_rules! assert_roundtrip_with_context {
|
|||
}, $input).unwrap();
|
||||
|
||||
let mut input = ::cssparser::ParserInput::new(&serialized);
|
||||
let unwrapped = parse_input(|context, i| {
|
||||
let unwrapped = parse_input(|context, _, i| {
|
||||
let re_parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
|
|
|
@ -426,7 +426,7 @@ mod shorthand_serialization {
|
|||
border-left: 4px solid; \
|
||||
border-image: none;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -568,7 +568,7 @@ mod shorthand_serialization {
|
|||
background-origin: border-box; \
|
||||
background-clip: padding-box;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -592,7 +592,7 @@ mod shorthand_serialization {
|
|||
background-origin: padding-box; \
|
||||
background-clip: padding-box;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -616,7 +616,7 @@ mod shorthand_serialization {
|
|||
background-origin: border-box, padding-box; \
|
||||
background-clip: padding-box, padding-box;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -647,7 +647,7 @@ mod shorthand_serialization {
|
|||
background-origin: border-box; \
|
||||
background-clip: padding-box, padding-box;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -661,7 +661,7 @@ mod shorthand_serialization {
|
|||
let block_text = "\
|
||||
background-position-x: 30px;\
|
||||
background-position-y: bottom 20px;";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, "background-position: left 30px bottom 20px;");
|
||||
|
||||
|
@ -670,7 +670,7 @@ mod shorthand_serialization {
|
|||
let block_text = "\
|
||||
background-position-x: center;\
|
||||
background-position-y: 20px;";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, "background-position: center 20px;");
|
||||
}
|
||||
|
@ -755,7 +755,7 @@ mod shorthand_serialization {
|
|||
animation-iteration-count: infinite;\
|
||||
animation-play-state: paused;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -774,7 +774,7 @@ mod shorthand_serialization {
|
|||
animation-iteration-count: infinite, 2;\
|
||||
animation-play-state: paused, running;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -800,7 +800,7 @@ mod shorthand_serialization {
|
|||
animation-iteration-count: infinite, 2; \
|
||||
animation-play-state: paused, running;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -817,7 +817,7 @@ mod shorthand_serialization {
|
|||
animation-iteration-count: infinite, 2; \
|
||||
animation-play-state: paused, running;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -835,7 +835,7 @@ mod shorthand_serialization {
|
|||
transition-delay: 4s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2);";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -849,7 +849,7 @@ mod shorthand_serialization {
|
|||
transition-delay: 4s, 5s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -871,7 +871,7 @@ mod shorthand_serialization {
|
|||
transition-delay: 4s, 5s; \
|
||||
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
|
||||
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -884,7 +884,7 @@ mod shorthand_serialization {
|
|||
transition-duration: 3s; \
|
||||
transition-delay: 4s; \
|
||||
transition-timing-function: steps(2, start);";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -897,7 +897,7 @@ mod shorthand_serialization {
|
|||
transition-duration: 3s; \
|
||||
transition-delay: 4s; \
|
||||
transition-timing-function: frames(2);";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
|
||||
|
@ -910,7 +910,7 @@ mod shorthand_serialization {
|
|||
#[test]
|
||||
fn css_wide_keywords_should_be_parsed() {
|
||||
let block_text = "--a:inherit;";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, "--a: inherit;");
|
||||
|
@ -919,7 +919,7 @@ mod shorthand_serialization {
|
|||
#[test]
|
||||
fn non_keyword_custom_property_should_be_unparsed() {
|
||||
let block_text = "--main-color: #06c;";
|
||||
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
|
||||
let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
|
||||
|
||||
let serialization = block.to_css_string();
|
||||
assert_eq!(serialization, block_text);
|
||||
|
@ -949,7 +949,7 @@ mod shorthand_serialization {
|
|||
let shadow_decl = BoxShadowList(vec![shadow_val]);
|
||||
properties.push(PropertyDeclaration::BoxShadow(shadow_decl));
|
||||
let shadow_css = "box-shadow: 1px 2px 3px 4px;";
|
||||
let shadow = parse(|c, i| Ok(parse_property_declaration_list(c, i)), shadow_css).unwrap();
|
||||
let shadow = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), shadow_css).unwrap();
|
||||
|
||||
assert_eq!(shadow.to_css_string(), shadow_css);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use servo_config::prefs::{PREFS, PrefValue};
|
|||
use servo_url::ServoUrl;
|
||||
use style::context::QuirksMode;
|
||||
use style::media_queries::{Device, MediaList, MediaType};
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::parser::{Parse, ParserContext, ParserErrorContext};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{CssRuleType, Stylesheet, StylesheetInDocument, Origin};
|
||||
use style::stylesheets::viewport_rule::*;
|
||||
|
@ -302,14 +302,14 @@ fn multiple_stylesheets_cascading() {
|
|||
#[test]
|
||||
fn constrain_viewport() {
|
||||
let url = ServoUrl::parse("http://localhost").unwrap();
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Viewport),
|
||||
let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Viewport),
|
||||
PARSING_MODE_DEFAULT,
|
||||
QuirksMode::NoQuirks);
|
||||
let error_context = ParserErrorContext { error_reporter: &CSSErrorReporterTest };
|
||||
|
||||
macro_rules! from_css {
|
||||
($css:expr) => {
|
||||
&ViewportRule::parse(&context, &mut Parser::new(&mut $css)).unwrap()
|
||||
&ViewportRule::parse(&context, &error_context, &mut Parser::new(&mut $css)).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue