Format remaining files

This commit is contained in:
Pyfisch 2018-11-06 13:01:35 +01:00
parent bf47f90da6
commit cb07debcb6
252 changed files with 5944 additions and 3744 deletions

View file

@ -31,7 +31,9 @@ use style::values::specified::{LengthOrPercentageOrAuto, PositionComponent};
use style::values::specified::TimingFunction;
pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock
where I: IntoIterator<Item=(PropertyDeclaration, Importance)> {
where
I: IntoIterator<Item = (PropertyDeclaration, Importance)>,
{
let mut block = PropertyDeclarationBlock::new();
for (d, i) in iterable {
block.push(d, i);
@ -69,8 +71,17 @@ fn test_parse_stylesheet() {
let url = ServoUrl::parse("about::test").unwrap();
let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty()));
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
None, None, QuirksMode::NoQuirks, 0);
let stylesheet = Stylesheet::from_str(
css,
url.clone(),
Origin::UserAgent,
media,
lock,
None,
None,
QuirksMode::NoQuirks,
0,
);
let mut namespaces = Namespaces::default();
namespaces.default = Some(ns!(html));
let expected = Stylesheet {
@ -79,180 +90,245 @@ fn test_parse_stylesheet() {
namespaces: RwLock::new(namespaces),
url_data: RwLock::new(url),
quirks_mode: QuirksMode::NoQuirks,
rules: CssRules::new(vec![
CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule {
prefix: None,
url: NsAtom::from("http://www.w3.org/1999/xhtml"),
source_location: SourceLocation {
line: 1,
column: 19,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec!(
Selector::from_vec(vec!(
Component::DefaultNamespace(NsAtom::from("http://www.w3.org/1999/xhtml")),
Component::LocalName(LocalName {
name: local_name!("input"),
lower_name: local_name!("input"),
}),
Component::AttributeInNoNamespace {
local_name: local_name!("type"),
operator: AttrSelectorOperator::Equal,
value: "hidden".to_owned(),
case_sensitivity: ParsedCaseSensitivity::AsciiCaseInsensitive,
never_matches: false,
}
), (0 << 20) + (1 << 10) + (1 << 0))
)),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(
PropertyDeclaration::Display(longhands::display::SpecifiedValue::None),
Importance::Important,
),
(
PropertyDeclaration::Custom(CustomDeclaration {
name: Atom::from("a"),
value: CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Inherit),
}),
Importance::Important,
),
]))),
source_location: SourceLocation {
line: 3,
column: 9,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec!(
Selector::from_vec(vec!(
Component::DefaultNamespace(NsAtom::from("http://www.w3.org/1999/xhtml")),
rules: CssRules::new(
vec![
CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule {
prefix: None,
url: NsAtom::from("http://www.w3.org/1999/xhtml"),
source_location: SourceLocation {
line: 1,
column: 19,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec![Selector::from_vec(
vec![
Component::DefaultNamespace(NsAtom::from(
"http://www.w3.org/1999/xhtml",
)),
Component::LocalName(LocalName {
name: local_name!("html"),
lower_name: local_name!("html"),
name: local_name!("input"),
lower_name: local_name!("input"),
}),
), (0 << 20) + (0 << 10) + (1 << 0)),
Selector::from_vec(vec!(
Component::DefaultNamespace(NsAtom::from("http://www.w3.org/1999/xhtml")),
Component::LocalName(LocalName {
name: local_name!("body"),
lower_name: local_name!("body"),
})
), (0 << 20) + (0 << 10) + (1 << 0)
),
)),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(PropertyDeclaration::Display(longhands::display::SpecifiedValue::Block),
Importance::Normal),
]))),
source_location: SourceLocation {
line: 11,
column: 9,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec!(
Selector::from_vec(vec!(
Component::DefaultNamespace(NsAtom::from("http://www.w3.org/1999/xhtml")),
Component::ID(Atom::from("d1")),
Component::Combinator(Combinator::Child),
Component::DefaultNamespace(NsAtom::from("http://www.w3.org/1999/xhtml")),
Component::Class(Atom::from("ok"))
), (1 << 20) + (1 << 10) + (0 << 0))
)),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(PropertyDeclaration::BackgroundColor(
longhands::background_color::SpecifiedValue::Numeric {
authored: Some("blue".to_owned().into_boxed_str()),
parsed: cssparser::RGBA::new(0, 0, 255, 255),
}
),
Importance::Normal),
(PropertyDeclaration::BackgroundPositionX(
longhands::background_position_x::SpecifiedValue(
vec![PositionComponent::zero()])),
Importance::Normal),
(PropertyDeclaration::BackgroundPositionY(
longhands::background_position_y::SpecifiedValue(
vec![PositionComponent::zero()])),
Importance::Normal),
(PropertyDeclaration::BackgroundRepeat(
longhands::background_repeat::SpecifiedValue(
vec![longhands::background_repeat::single_value
::get_initial_specified_value()])),
Importance::Normal),
(PropertyDeclaration::BackgroundAttachment(
longhands::background_attachment::SpecifiedValue(
vec![longhands::background_attachment::single_value
::get_initial_specified_value()])),
Importance::Normal),
(PropertyDeclaration::BackgroundImage(
longhands::background_image::SpecifiedValue(
vec![longhands::background_image::single_value
::get_initial_specified_value()])),
Importance::Normal),
(PropertyDeclaration::BackgroundSize(
longhands::background_size::SpecifiedValue(
vec![longhands::background_size::single_value
::get_initial_specified_value()])),
Importance::Normal),
(PropertyDeclaration::BackgroundOrigin(
longhands::background_origin::SpecifiedValue(
vec![longhands::background_origin::single_value
::get_initial_specified_value()])),
Importance::Normal),
(PropertyDeclaration::BackgroundClip(
longhands::background_clip::SpecifiedValue(
vec![longhands::background_clip::single_value
::get_initial_specified_value()])),
Importance::Normal),
]))),
source_location: SourceLocation {
line: 15,
column: 9,
},
}))),
CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {
name: KeyframesName::Ident(CustomIdent("foo".into())),
keyframes: vec![
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(
vec![KeyframePercentage::new(0.)]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(0.))),
Importance::Normal),
]))),
source_location: SourceLocation {
line: 17,
column: 13,
},
})),
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(
vec![KeyframePercentage::new(1.)]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(1.))),
Importance::Normal),
(PropertyDeclaration::AnimationTimingFunction(
animation_timing_function::SpecifiedValue(
vec![TimingFunction::ease()])),
Importance::Normal),
]))),
source_location: SourceLocation {
line: 18,
column: 13,
},
})),
],
vendor_prefix: None,
source_location: SourceLocation {
line: 16,
column: 19,
},
})))
], &stylesheet.shared_lock),
Component::AttributeInNoNamespace {
local_name: local_name!("type"),
operator: AttrSelectorOperator::Equal,
value: "hidden".to_owned(),
case_sensitivity: ParsedCaseSensitivity::AsciiCaseInsensitive,
never_matches: false,
},
],
(0 << 20) + (1 << 10) + (1 << 0),
)]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(
PropertyDeclaration::Display(
longhands::display::SpecifiedValue::None,
),
Importance::Important,
),
(
PropertyDeclaration::Custom(CustomDeclaration {
name: Atom::from("a"),
value: CustomDeclarationValue::CSSWideKeyword(
CSSWideKeyword::Inherit,
),
}),
Importance::Important,
),
]))),
source_location: SourceLocation { line: 3, column: 9 },
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec![
Selector::from_vec(
vec![
Component::DefaultNamespace(NsAtom::from(
"http://www.w3.org/1999/xhtml",
)),
Component::LocalName(LocalName {
name: local_name!("html"),
lower_name: local_name!("html"),
}),
],
(0 << 20) + (0 << 10) + (1 << 0),
),
Selector::from_vec(
vec![
Component::DefaultNamespace(NsAtom::from(
"http://www.w3.org/1999/xhtml",
)),
Component::LocalName(LocalName {
name: local_name!("body"),
lower_name: local_name!("body"),
}),
],
(0 << 20) + (0 << 10) + (1 << 0),
),
]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![(
PropertyDeclaration::Display(longhands::display::SpecifiedValue::Block),
Importance::Normal,
)]))),
source_location: SourceLocation {
line: 11,
column: 9,
},
}))),
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
selectors: SelectorList::from_vec(vec![Selector::from_vec(
vec![
Component::DefaultNamespace(NsAtom::from(
"http://www.w3.org/1999/xhtml",
)),
Component::ID(Atom::from("d1")),
Component::Combinator(Combinator::Child),
Component::DefaultNamespace(NsAtom::from(
"http://www.w3.org/1999/xhtml",
)),
Component::Class(Atom::from("ok")),
],
(1 << 20) + (1 << 10) + (0 << 0),
)]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(
PropertyDeclaration::BackgroundColor(
longhands::background_color::SpecifiedValue::Numeric {
authored: Some("blue".to_owned().into_boxed_str()),
parsed: cssparser::RGBA::new(0, 0, 255, 255),
},
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundPositionX(
longhands::background_position_x::SpecifiedValue(vec![
PositionComponent::zero(),
]),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundPositionY(
longhands::background_position_y::SpecifiedValue(vec![
PositionComponent::zero(),
]),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundRepeat(
longhands::background_repeat::SpecifiedValue(
vec![longhands::background_repeat::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundAttachment(
longhands::background_attachment::SpecifiedValue(
vec![longhands::background_attachment::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundImage(
longhands::background_image::SpecifiedValue(
vec![longhands::background_image::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundSize(
longhands::background_size::SpecifiedValue(
vec![longhands::background_size::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundOrigin(
longhands::background_origin::SpecifiedValue(
vec![longhands::background_origin::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
(
PropertyDeclaration::BackgroundClip(
longhands::background_clip::SpecifiedValue(
vec![longhands::background_clip::single_value
::get_initial_specified_value()],
),
),
Importance::Normal,
),
]))),
source_location: SourceLocation {
line: 15,
column: 9,
},
}))),
CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {
name: KeyframesName::Ident(CustomIdent("foo".into())),
keyframes: vec![
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(vec![
KeyframePercentage::new(0.),
]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![(
PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(0.)),
),
Importance::Normal,
)]))),
source_location: SourceLocation {
line: 17,
column: 13,
},
})),
Arc::new(stylesheet.shared_lock.wrap(Keyframe {
selector: KeyframeSelector::new_for_unit_testing(vec![
KeyframePercentage::new(1.),
]),
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
(
PropertyDeclaration::Width(
LengthOrPercentageOrAuto::Percentage(Percentage(1.)),
),
Importance::Normal,
),
(
PropertyDeclaration::AnimationTimingFunction(
animation_timing_function::SpecifiedValue(vec![
TimingFunction::ease(),
]),
),
Importance::Normal,
),
]))),
source_location: SourceLocation {
line: 18,
column: 13,
},
})),
],
vendor_prefix: None,
source_location: SourceLocation {
line: 16,
column: 19,
},
}))),
],
&stylesheet.shared_lock,
),
source_map_url: RwLock::new(None),
source_url: RwLock::new(None),
},
@ -266,10 +342,10 @@ fn test_parse_stylesheet() {
#[derive(Debug)]
struct CSSError {
pub url : ServoUrl,
pub url: ServoUrl,
pub line: u32,
pub column: u32,
pub message: String
pub message: String,
}
struct TestingErrorReporter {
@ -285,11 +361,21 @@ impl TestingErrorReporter {
fn assert_messages_contain(&self, expected_errors: &[(u32, u32, &str)]) {
let errors = self.errors.borrow();
for (i, (error, &(line, column, message))) in errors.iter().zip(expected_errors).enumerate() {
assert_eq!((error.line, error.column), (line, column),
"line/column numbers of the {}th error: {:?}", i + 1, error.message);
assert!(error.message.contains(message),
"{:?} does not contain {:?}", error.message, message);
for (i, (error, &(line, column, message))) in errors.iter().zip(expected_errors).enumerate()
{
assert_eq!(
(error.line, error.column),
(line, column),
"line/column numbers of the {}th error: {:?}",
i + 1,
error.message
);
assert!(
error.message.contains(message),
"{:?} does not contain {:?}",
error.message,
message
);
}
if errors.len() < expected_errors.len() {
panic!("Missing errors: {:#?}", &expected_errors[errors.len()..]);
@ -301,22 +387,16 @@ impl TestingErrorReporter {
}
impl ParseErrorReporter for TestingErrorReporter {
fn report_error(&self,
url: &ServoUrl,
location: SourceLocation,
error: ContextualParseError) {
self.errors.borrow_mut().push(
CSSError{
url: url.clone(),
line: location.line,
column: location.column,
message: error.to_string(),
}
)
fn report_error(&self, url: &ServoUrl, location: SourceLocation, error: ContextualParseError) {
self.errors.borrow_mut().push(CSSError {
url: url.clone(),
line: location.line,
column: location.column,
message: error.to_string(),
})
}
}
#[test]
fn test_report_error_stylesheet() {
PREFS.set("layout.viewport.enabled", PrefValue::Boolean(true));
@ -342,29 +422,50 @@ fn test_report_error_stylesheet() {
let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty()));
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
None, Some(&error_reporter), QuirksMode::NoQuirks, 5);
Stylesheet::from_str(
css,
url.clone(),
Origin::UserAgent,
media,
lock,
None,
Some(&error_reporter),
QuirksMode::NoQuirks,
5,
);
error_reporter.assert_messages_contain(&[
(8, 18, "Unsupported property declaration: 'display: invalid;'"),
(9, 27, "Unsupported property declaration: 'background-image:"), // FIXME: column should be around 56
(
8,
18,
"Unsupported property declaration: 'display: invalid;'",
),
(
9,
27,
"Unsupported property declaration: 'background-image:",
), // FIXME: column should be around 56
(10, 17, "Unsupported property declaration: 'invalid: true;'"),
(12, 28, "Invalid media rule"),
(13, 30, "Unsupported @font-face descriptor declaration"),
// When @counter-style is supported, this should be replaced with two errors
(14, 19, "Invalid rule: '@counter-style "),
// When @font-feature-values is supported, this should be replaced with two errors
(15, 25, "Invalid rule: '@font-feature-values "),
(16, 13, "Invalid rule: '@invalid'"),
(17, 29, "Invalid rule: '@invalid'"),
(18, 34, "Invalid rule: '@supports "),
(19, 26, "Invalid keyframe rule: 'from invalid '"),
(19, 52, "Unsupported keyframe property declaration: 'margin: 0 invalid 0;'"),
(20, 29, "Unsupported @viewport descriptor declaration: 'width: 320px invalid auto;'"),
(
19,
52,
"Unsupported keyframe property declaration: 'margin: 0 invalid 0;'",
),
(
20,
29,
"Unsupported @viewport descriptor declaration: 'width: 320px invalid auto;'",
),
]);
assert_eq!(error_reporter.errors.borrow()[0].url, url);
@ -384,28 +485,50 @@ fn test_no_report_unrecognized_vendor_properties() {
let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty()));
Stylesheet::from_str(css, url, Origin::UserAgent, media, lock,
None, Some(&error_reporter), QuirksMode::NoQuirks, 0);
Stylesheet::from_str(
css,
url,
Origin::UserAgent,
media,
lock,
None,
Some(&error_reporter),
QuirksMode::NoQuirks,
0,
);
error_reporter.assert_messages_contain(&[
(4, 31, "Unsupported property declaration: '-moz-background-color: red;'"),
]);
error_reporter.assert_messages_contain(&[(
4,
31,
"Unsupported property declaration: '-moz-background-color: red;'",
)]);
}
#[test]
fn test_source_map_url() {
let tests = vec![
("", None),
("/*# sourceMappingURL=something */", Some("something".to_string())),
(
"/*# sourceMappingURL=something */",
Some("something".to_string()),
),
];
for test in tests {
let url = ServoUrl::parse("about::test").unwrap();
let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty()));
let stylesheet = Stylesheet::from_str(test.0, url.clone(), Origin::UserAgent, media, lock,
None, None, QuirksMode::NoQuirks,
0);
let stylesheet = Stylesheet::from_str(
test.0,
url.clone(),
Origin::UserAgent,
media,
lock,
None,
None,
QuirksMode::NoQuirks,
0,
);
let url_opt = stylesheet.contents.source_map_url.read();
assert_eq!(*url_opt, test.1);
}
@ -422,9 +545,17 @@ fn test_source_url() {
let url = ServoUrl::parse("about::test").unwrap();
let lock = SharedRwLock::new();
let media = Arc::new(lock.wrap(MediaList::empty()));
let stylesheet = Stylesheet::from_str(test.0, url.clone(), Origin::UserAgent, media, lock,
None, None, QuirksMode::NoQuirks,
0);
let stylesheet = Stylesheet::from_str(
test.0,
url.clone(),
Origin::UserAgent,
media,
lock,
None,
None,
QuirksMode::NoQuirks,
0,
);
let url_opt = stylesheet.contents.source_url.read();
assert_eq!(*url_opt, test.1);
}