/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use properties::{parse, parse_input}; use style::computed_values::display::T as Display; use style::properties::declaration_block::PropertyDeclarationBlock; use style::properties::parse_property_declaration_list; use style::properties::{Importance, PropertyDeclaration}; use style::values::specified::url::SpecifiedUrl; use style::values::specified::NoCalcLength; use style::values::specified::{BorderSideWidth, BorderStyle, Color}; use style::values::specified::{Length, LengthPercentage, LengthPercentageOrAuto}; use style::values::RGBA; use style_traits::ToCss; use stylesheets::block_from;
// we can use margin as a base to test out the different combinations // but afterwards, we only need to to one test per "four sides shorthand" #[test] fn all_equal_properties_should_serialize_to_one_value() { letmut properties = Vec::new();
let px_70 = LengthPercentageOrAuto::Length(NoCalcLength::from_px(70f32));
properties.push(PropertyDeclaration::MarginTop(px_70.clone()));
properties.push(PropertyDeclaration::MarginRight(px_70.clone()));
properties.push(PropertyDeclaration::MarginBottom(px_70.clone()));
properties.push(PropertyDeclaration::MarginLeft(px_70));
let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "margin: 70px;");
}
let vertical_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(10f32)); let horizontal_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(5f32));
let top_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(8f32)); let bottom_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(10f32)); let horizontal_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(5f32));
let top_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(8f32)); let right_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(12f32)); let bottom_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(10f32)); let left_px = LengthPercentageOrAuto::Length(NoCalcLength::from_px(14f32));
let top_px = BorderSideWidth::Thin; let right_px = BorderSideWidth::Medium; let bottom_px = BorderSideWidth::Thick; let left_px = BorderSideWidth::Length(Length::from_px(15f32));
let serialization = shorthand_properties_to_string(properties);
// TODO: Make the rgb test show border-color as blue red instead of below tuples
assert_eq!(
serialization, "border-color: rgb(0, 0, 255) rgb(255, 0, 0);"
);
}
properties.push(PropertyDeclaration::BorderTopWidth(
BorderSideWidth::Length(Length::from_px(1.)),
));
properties.push(PropertyDeclaration::BorderTopStyle(BorderStyle::Solid)); let c = Color::Numeric {
parsed: RGBA::new(255, 0, 0, 255),
authored: Some("green".to_string().into_boxed_str()),
};
properties.push(PropertyDeclaration::BorderTopColor(c));
let serialization = shorthand_properties_to_string(properties);
assert_eq!(
serialization, "border-color: green red red; border-top: 1px solid green;"
);
}
// we can use border-top as a base to test out the different combinations // but afterwards, we only need to to one test per "directional border shorthand"
let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "border-left: 4px solid;");
}
#[test] fn border_should_serialize_correctly() { // According to https://drafts.csswg.org/css-backgrounds-3/#the-border-shorthands, // the ‘border’ shorthand resets ‘border-image’ to its initial value. To verify the // serialization of 'border' shorthand, we need to set 'border-image' as well. let block_text = "\
border-top: 4px solid; \
border-right: 4px solid; \
border-bottom: 4px solid; \
border-left: 4px solid; \
border-image: none;";
let block =
parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap();
#[test] fn serialize_multiple_backgrounds_unequal_property_lists() { // When the lengths of property values are different, the shorthand serialization // should not be used. Previously the implementation cycled values if the lists were // uneven. This is incorrect, in that we should serialize to a shorthand only when the // lists have the same length (this affects background, transition and animation). // https://github.com/servo/servo/issues/15398 ) // With background, the color is one exception as it should only appear once for // multiple backgrounds. // Below background-origin only has one value. let block_text = "\
background-color: rgb(0, 0, 255); \
background-image: url(\"http://servo/test.png\"), none; \
background-repeat: repeat-x, repeat-y; \
background-attachment: scroll, scroll; \
background-size: 70px 50px, 20px 30px; \
background-position: 7px 4px, 5px 6px; \
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 serialization = block.to_css_string();
assert_eq!(serialization, block_text);
}
#[test] fn background_position_should_be_a_valid_form_its_longhands() { // If there is any longhand consisted of both keyword and position, // the shorthand result should be the 4-value format. 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 serialization = block.to_css_string();
assert_eq!(serialization, "background-position: left 30px bottom 20px;");
// If there is no longhand consisted of both keyword and position, // the shorthand result should be the 2-value format. 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 serialization = block.to_css_string();
assert_eq!(serialization, "background-position: center 20px;");
}
}
mod quotes { pubusesuper::*;
#[test] fn should_serialize_none_correctly() { use style::properties::longhands::quotes;
#[test] fn serialize_multiple_animations_unequal_property_lists() { // When the lengths of property values are different, the shorthand serialization // should not be used. Previously the implementation cycled values if the lists were // uneven. This is incorrect, in that we should serialize to a shorthand only when the // lists have the same length (this affects background, transition and animation). // https://github.com/servo/servo/issues/15398 ) let block_text = "\
animation-name: bounce, roll, flip, jump; \
animation-duration: 1s, 0.2s; \
animation-timing-function: ease-in, linear; \
animation-delay: 0s, 1s, 0.5s; \
animation-direction: normal; \
animation-fill-mode: forwards, backwards; \
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 serialization = block.to_css_string();
assert_eq!(serialization, block_text);
}
#[test] fn serialize_multiple_without_all_properties_returns_longhand() { // timing function and direction are missing, so no shorthand is returned. let block_text = "animation-name: bounce, roll; \
animation-duration: 1s, 0.2s; \
animation-delay: 0s, 1s; \
animation-fill-mode: forwards, backwards; \
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 serialization = block.to_css_string();
assert_eq!(serialization, block_text);
}
}
mod keywords { pubusesuper::*; #[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 serialization = block.to_css_string();
assert_eq!(serialization, "--a: inherit;");
}
#[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 serialization = block.to_css_string();
assert_eq!(serialization, block_text);
}
}
mod effects { pubusesuper::*; pubuse style::properties::longhands::box_shadow::SpecifiedValue as BoxShadowList; pubuse style::values::specified::effects::{BoxShadow, SimpleShadow};
#[test] fn box_shadow_should_serialize_correctly() { use style::values::specified::length::NonNegativeLength;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.