diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /servo/tests/unit/style/custom_properties.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/tests/unit/style/custom_properties.rs')
-rw-r--r-- | servo/tests/unit/style/custom_properties.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/servo/tests/unit/style/custom_properties.rs b/servo/tests/unit/style/custom_properties.rs new file mode 100644 index 0000000000..f04d4ff6b7 --- /dev/null +++ b/servo/tests/unit/style/custom_properties.rs @@ -0,0 +1,44 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ + +use cssparser::{Parser, ParserInput}; +use servo_arc::Arc; +use style::custom_properties::{Name, SpecifiedValue, CustomPropertiesMap, CustomPropertiesBuilder, CssEnvironment}; +use style::properties::CustomDeclarationValue; +use test::{self, Bencher}; + +fn cascade( + name_and_value: &[(&str, &str)], + inherited: Option<&Arc<CustomPropertiesMap>>, +) -> Option<Arc<CustomPropertiesMap>> { + let values = name_and_value.iter().map(|&(name, value)| { + let mut input = ParserInput::new(value); + let mut parser = Parser::new(&mut input); + (Name::from(name), SpecifiedValue::parse(&mut parser).unwrap()) + }).collect::<Vec<_>>(); + + let env = CssEnvironment; + let mut builder = CustomPropertiesBuilder::new(inherited, &env); + + for &(ref name, ref val) in &values { + builder.cascade(name, &CustomDeclarationValue::Value(val.clone())); + } + + builder.build() +} + +#[bench] +fn cascade_custom_simple(b: &mut Bencher) { + b.iter(|| { + let parent = cascade(&[ + ("foo", "10px"), + ("bar", "100px"), + ], None); + + test::black_box(cascade(&[ + ("baz", "calc(40em + 4px)"), + ("bazz", "calc(30em + 4px)"), + ], parent.as_ref())) + }) +} |