If there are multiple prefixed/non-prefixed @keyframes with the same name; * non-prefixed rule overrides earlier rules. * prefixed rule overrides earlier prefixed rules. <!-- Please describe your changes on the following line: --> This is PR of https://bugzilla.mozilla.org/show_bug.cgi?id=1356779 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 85aba7ab14c64e16836c234158748d0cd7f435fd
231 lines
9.1 KiB
Rust
231 lines
9.1 KiB
Rust
/* 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::sync::Arc;
|
|
use style::keyframes::{Keyframe, KeyframesAnimation, KeyframePercentage, KeyframeSelector};
|
|
use style::keyframes::{KeyframesStep, KeyframesStepValue};
|
|
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, Importance};
|
|
use style::properties::animated_properties::TransitionProperty;
|
|
use style::shared_lock::SharedRwLock;
|
|
use style::values::specified::{LengthOrPercentageOrAuto, NoCalcLength};
|
|
|
|
#[test]
|
|
fn test_empty_keyframe() {
|
|
let shared_lock = SharedRwLock::new();
|
|
let keyframes = vec![];
|
|
let animation = KeyframesAnimation::from_keyframes(&keyframes,
|
|
/* vendor_prefix = */ None,
|
|
&shared_lock.read());
|
|
let expected = KeyframesAnimation {
|
|
steps: vec![],
|
|
properties_changed: vec![],
|
|
vendor_prefix: None,
|
|
};
|
|
|
|
assert_eq!(format!("{:#?}", animation), format!("{:#?}", expected));
|
|
}
|
|
|
|
#[test]
|
|
fn test_no_property_in_keyframe() {
|
|
let shared_lock = SharedRwLock::new();
|
|
let keyframes = vec![
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(1.)]),
|
|
block: Arc::new(shared_lock.wrap(PropertyDeclarationBlock::new()))
|
|
})),
|
|
];
|
|
let animation = KeyframesAnimation::from_keyframes(&keyframes,
|
|
/* vendor_prefix = */ None,
|
|
&shared_lock.read());
|
|
let expected = KeyframesAnimation {
|
|
steps: vec![],
|
|
properties_changed: vec![],
|
|
vendor_prefix: None,
|
|
};
|
|
|
|
assert_eq!(format!("{:#?}", animation), format!("{:#?}", expected));
|
|
}
|
|
|
|
#[test]
|
|
fn test_missing_property_in_initial_keyframe() {
|
|
let shared_lock = SharedRwLock::new();
|
|
let declarations_on_initial_keyframe =
|
|
Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one(
|
|
PropertyDeclaration::Width(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
)));
|
|
|
|
let declarations_on_final_keyframe =
|
|
Arc::new(shared_lock.wrap({
|
|
let mut block = PropertyDeclarationBlock::new();
|
|
block.push(
|
|
PropertyDeclaration::Width(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block.push(
|
|
PropertyDeclaration::Height(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block
|
|
}));
|
|
|
|
let keyframes = vec![
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(0.)]),
|
|
block: declarations_on_initial_keyframe.clone(),
|
|
})),
|
|
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(1.)]),
|
|
block: declarations_on_final_keyframe.clone(),
|
|
})),
|
|
];
|
|
let animation = KeyframesAnimation::from_keyframes(&keyframes,
|
|
/* vendor_prefix = */ None,
|
|
&shared_lock.read());
|
|
let expected = KeyframesAnimation {
|
|
steps: vec![
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(0.),
|
|
value: KeyframesStepValue::Declarations { block: declarations_on_initial_keyframe },
|
|
declared_timing_function: false,
|
|
},
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(1.),
|
|
value: KeyframesStepValue::Declarations { block: declarations_on_final_keyframe },
|
|
declared_timing_function: false,
|
|
},
|
|
],
|
|
properties_changed: vec![TransitionProperty::Width, TransitionProperty::Height],
|
|
vendor_prefix: None,
|
|
};
|
|
|
|
assert_eq!(format!("{:#?}", animation), format!("{:#?}", expected));
|
|
}
|
|
|
|
#[test]
|
|
fn test_missing_property_in_final_keyframe() {
|
|
let shared_lock = SharedRwLock::new();
|
|
let declarations_on_initial_keyframe =
|
|
Arc::new(shared_lock.wrap({
|
|
let mut block = PropertyDeclarationBlock::new();
|
|
block.push(
|
|
PropertyDeclaration::Width(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block.push(
|
|
PropertyDeclaration::Height(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block
|
|
}));
|
|
|
|
let declarations_on_final_keyframe =
|
|
Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one(
|
|
PropertyDeclaration::Height(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal,
|
|
)));
|
|
|
|
let keyframes = vec![
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(0.)]),
|
|
block: declarations_on_initial_keyframe.clone(),
|
|
})),
|
|
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(1.)]),
|
|
block: declarations_on_final_keyframe.clone(),
|
|
})),
|
|
];
|
|
let animation = KeyframesAnimation::from_keyframes(&keyframes,
|
|
/* vendor_prefix = */ None,
|
|
&shared_lock.read());
|
|
let expected = KeyframesAnimation {
|
|
steps: vec![
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(0.),
|
|
value: KeyframesStepValue::Declarations { block: declarations_on_initial_keyframe },
|
|
declared_timing_function: false,
|
|
},
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(1.),
|
|
value: KeyframesStepValue::Declarations { block: declarations_on_final_keyframe },
|
|
declared_timing_function: false,
|
|
},
|
|
],
|
|
properties_changed: vec![TransitionProperty::Width, TransitionProperty::Height],
|
|
vendor_prefix: None,
|
|
};
|
|
|
|
assert_eq!(format!("{:#?}", animation), format!("{:#?}", expected));
|
|
}
|
|
|
|
#[test]
|
|
fn test_missing_keyframe_in_both_of_initial_and_final_keyframe() {
|
|
let shared_lock = SharedRwLock::new();
|
|
let declarations =
|
|
Arc::new(shared_lock.wrap({
|
|
let mut block = PropertyDeclarationBlock::new();
|
|
block.push(
|
|
PropertyDeclaration::Width(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block.push(
|
|
PropertyDeclaration::Height(
|
|
LengthOrPercentageOrAuto::Length(NoCalcLength::from_px(20f32))),
|
|
Importance::Normal
|
|
);
|
|
block
|
|
}));
|
|
|
|
let keyframes = vec![
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(0.)]),
|
|
block: Arc::new(shared_lock.wrap(PropertyDeclarationBlock::new()))
|
|
})),
|
|
Arc::new(shared_lock.wrap(Keyframe {
|
|
selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(0.5)]),
|
|
block: declarations.clone(),
|
|
})),
|
|
];
|
|
let animation = KeyframesAnimation::from_keyframes(&keyframes,
|
|
/* vendor_prefix = */ None,
|
|
&shared_lock.read());
|
|
let expected = KeyframesAnimation {
|
|
steps: vec![
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(0.),
|
|
value: KeyframesStepValue::Declarations {
|
|
block: Arc::new(shared_lock.wrap(
|
|
// XXX: Should we use ComputedValues in this case?
|
|
PropertyDeclarationBlock::new()
|
|
))
|
|
},
|
|
declared_timing_function: false,
|
|
},
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(0.5),
|
|
value: KeyframesStepValue::Declarations { block: declarations },
|
|
declared_timing_function: false,
|
|
},
|
|
KeyframesStep {
|
|
start_percentage: KeyframePercentage(1.),
|
|
value: KeyframesStepValue::ComputedValues,
|
|
declared_timing_function: false,
|
|
}
|
|
],
|
|
properties_changed: vec![TransitionProperty::Width, TransitionProperty::Height],
|
|
vendor_prefix: None,
|
|
};
|
|
|
|
assert_eq!(format!("{:#?}", animation), format!("{:#?}", expected));
|
|
}
|