Skip to content

Commit

Permalink
Add test case for {background|mask}-position.
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: B6torf6dw5N
  • Loading branch information
kuoe0 committed Apr 14, 2017
1 parent 2358e46 commit e52b6b8
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions tests/unit/style/properties/serialization.rs
Expand Up @@ -660,7 +660,7 @@ mod shorthand_serialization {
background-attachment: scroll; \
background-size: 70px 50px; \
background-position-x: 7px; \
background-position-y: 4px; \
background-position-y: bottom 4px; \
background-origin: border-box; \
background-clip: padding-box;";

Expand All @@ -671,7 +671,7 @@ mod shorthand_serialization {
assert_eq!(
serialization,
"background: rgb(255, 0, 0) url(\"http://servo/test.png\") repeat-x \
scroll 7px 4px / 70px 50px border-box padding-box;"
scroll left 7px bottom 4px / 70px 50px border-box padding-box;"
);
}

Expand Down Expand Up @@ -749,6 +749,27 @@ mod shorthand_serialization {

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 mask {
Expand All @@ -762,7 +783,7 @@ mod shorthand_serialization {
use style::properties::longhands::mask_repeat as repeat;
use style::properties::longhands::mask_size as size;
use style::values::specified::Image;
use style::values::specified::position::{HorizontalPosition, VerticalPosition};
use style::values::specified::position::{HorizontalPosition, VerticalPosition, Keyword};
use super::*;

macro_rules! single_vec_value_typedef {
Expand Down Expand Up @@ -805,7 +826,7 @@ mod shorthand_serialization {
);
let position_y = single_vec_value_typedef!(position_y,
VerticalPosition {
keyword: None,
keyword: Some(Keyword::Bottom),
position: Some(LengthOrPercentage::Length(NoCalcLength::from_px(4f32))),
}
);
Expand Down Expand Up @@ -837,7 +858,7 @@ mod shorthand_serialization {
let serialization = shorthand_properties_to_string(properties);
assert_eq!(
serialization,
"mask: url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px \
"mask: url(\"http://servo/test.png\") luminance left 7px bottom 4px / 70px 50px \
repeat-x padding-box border-box subtract;"
);
}
Expand Down Expand Up @@ -905,6 +926,27 @@ mod shorthand_serialization {
let serialization = block.to_css_string();
assert_eq!(serialization, block_text);
}

#[test]
fn mask_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 = "\
mask-position-x: 30px;\
mask-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, "mask-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 = "\
mask-position-x: center;\
mask-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, "mask-position: center 20px;");
}
}

mod scroll_snap_type {
Expand Down

0 comments on commit e52b6b8

Please sign in to comment.