summaryrefslogtreecommitdiffstats
path: root/servo/ports/geckolib/tests/specified_values.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /servo/ports/geckolib/tests/specified_values.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servo/ports/geckolib/tests/specified_values.rs')
-rw-r--r--servo/ports/geckolib/tests/specified_values.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/servo/ports/geckolib/tests/specified_values.rs b/servo/ports/geckolib/tests/specified_values.rs
new file mode 100644
index 0000000000..744bf1fd80
--- /dev/null
+++ b/servo/ports/geckolib/tests/specified_values.rs
@@ -0,0 +1,50 @@
+/* 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/. */
+
+#[cfg(all(test, target_pointer_width = "64"))]
+#[test]
+fn size_of_specified_values() {
+ use std::mem::size_of;
+ use style;
+
+ let threshold = 24;
+
+ let mut bad_properties = vec![];
+
+ macro_rules! check_property {
+ ( $( { $name: ident, $boxed: expr } )+ ) => {
+ $(
+ let size = size_of::<style::properties::longhands::$name::SpecifiedValue>();
+ let is_boxed = $boxed;
+ if (!is_boxed && size > threshold) || (is_boxed && size <= threshold) {
+ bad_properties.push((stringify!($name), size, is_boxed));
+ }
+ )+
+ }
+ }
+
+ longhand_properties_idents!(check_property);
+
+ let mut failing_messages = vec![];
+
+ for bad_prop in bad_properties {
+ if !bad_prop.2 {
+ failing_messages.push(
+ format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
+ currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \
+ increasing the size may negative affect style system performance. Please consider \
+ using `boxed=\"True\"` in this longhand.",
+ bad_prop.0, bad_prop.1, threshold));
+ } else if bad_prop.2 {
+ failing_messages.push(
+ format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
+ The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
+ bad_prop.0, bad_prop.1, threshold));
+ }
+ }
+
+ if !failing_messages.is_empty() {
+ panic!("{}", failing_messages.join("\n\n"));
+ }
+}