From f9b7bebc442245a73a519375812d12d6f9787faa Mon Sep 17 00:00:00 2001 From: Jeremy Chen Date: Mon, 4 Sep 2017 22:20:45 +0800 Subject: [PATCH] stylo: Fix unit test failures caused by adding source_location member to Keyframe rule. In #18365, we add an extra source_location member to Keyframe rule, so that we can provide location information to devtool panel for Stylo. In order not to break the existing unit tests, we should add this new member to all the Keyframe rules used in our unit tests. As for the tests in stylesheets.rs, since we make the test by mocking a raw css string, there are actual source locations that we can add to the expected result. As to the tests in keyframes.rs, since we don't use raw css string, we can just add a dummy souce location for all the tests. We can further fix this if we decide to use a raw css string for the tests in keyframes.rs one day. --- tests/unit/style/keyframes.rs | 16 ++++++++++++++-- tests/unit/style/stylesheets.rs | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/unit/style/keyframes.rs b/tests/unit/style/keyframes.rs index 1cb706edf40e..e5b7132b7ac0 100644 --- a/tests/unit/style/keyframes.rs +++ b/tests/unit/style/keyframes.rs @@ -2,6 +2,7 @@ * 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 cssparser::SourceLocation; use servo_arc::Arc; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, Importance}; use style::properties::animated_properties::AnimatableLonghand; @@ -29,10 +30,12 @@ fn test_empty_keyframe() { #[test] fn test_no_property_in_keyframe() { let shared_lock = SharedRwLock::new(); + let dummy_location = SourceLocation { line: 0, column: 0 }; 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())) + block: Arc::new(shared_lock.wrap(PropertyDeclarationBlock::new())), + source_location: dummy_location, })), ]; let animation = KeyframesAnimation::from_keyframes(&keyframes, @@ -73,15 +76,18 @@ fn test_missing_property_in_initial_keyframe() { block })); + let dummy_location = SourceLocation { line: 0, column: 0 }; 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(), + source_location: dummy_location, })), Arc::new(shared_lock.wrap(Keyframe { selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(1.)]), block: declarations_on_final_keyframe.clone(), + source_location: dummy_location, })), ]; let animation = KeyframesAnimation::from_keyframes(&keyframes, @@ -133,15 +139,18 @@ fn test_missing_property_in_final_keyframe() { Importance::Normal, ))); + let dummy_location = SourceLocation { line: 0, column: 0 }; 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(), + source_location: dummy_location, })), Arc::new(shared_lock.wrap(Keyframe { selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(1.)]), block: declarations_on_final_keyframe.clone(), + source_location: dummy_location, })), ]; let animation = KeyframesAnimation::from_keyframes(&keyframes, @@ -186,14 +195,17 @@ fn test_missing_keyframe_in_both_of_initial_and_final_keyframe() { block })); + let dummy_location = SourceLocation { line: 0, column: 0 }; 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())) + block: Arc::new(shared_lock.wrap(PropertyDeclarationBlock::new())), + source_location: dummy_location, })), Arc::new(shared_lock.wrap(Keyframe { selector: KeyframeSelector::new_for_unit_testing(vec![KeyframePercentage::new(0.5)]), block: declarations.clone(), + source_location: dummy_location, })), ]; let animation = KeyframesAnimation::from_keyframes(&keyframes, diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 69063931a5e4..37eba2338d64 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -217,7 +217,11 @@ fn test_parse_stylesheet() { (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( @@ -231,6 +235,10 @@ fn test_parse_stylesheet() { vec![TimingFunction::ease()])), Importance::Normal), ]))), + source_location: SourceLocation { + line: 18, + column: 13, + }, })), ], vendor_prefix: None,