From 27b2bad256e7a08cf647ecae37cfd80bf2310f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 3 Aug 2016 00:36:45 -0700 Subject: [PATCH] stylo: Fix and ensure alignment of restyle hints. Test it on Travis. Turns out eRestyle_LaterSiblings was not really matching, sigh... --- .travis.yml | 1 + components/style/restyle_hints.rs | 2 +- ports/geckolib/lib.rs | 1 + ports/geckolib/sanity_checks.rs | 44 +++++++++++++++++++++++++++++++ python/servo/testing_commands.py | 11 ++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 ports/geckolib/sanity_checks.rs diff --git a/.travis.yml b/.travis.yml index 7796d98cd23..d1f71944887 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ matrix: script: - ./mach build -d --verbose - ./mach build-geckolib + - ./mach test-geckolib - ./mach test-unit - ./mach test-compiletest - bash etc/ci/check_no_unwrap.sh diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index 5dcaa147453..619aa22724b 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -28,7 +28,7 @@ bitflags! { // of a good reason for that. const RESTYLE_DESCENDANTS = 0x02, #[doc = "Rerun selector matching on all later siblings of the element and all of their descendants."] - const RESTYLE_LATER_SIBLINGS = 0x04, + const RESTYLE_LATER_SIBLINGS = 0x08, } } diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index 81923a9188c..c5c31eae733 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -26,6 +26,7 @@ mod snapshot; mod snapshot_helpers; #[allow(non_snake_case)] pub mod glue; +mod sanity_checks; mod traversal; mod wrapper; diff --git a/ports/geckolib/sanity_checks.rs b/ports/geckolib/sanity_checks.rs new file mode 100644 index 00000000000..96fd1e555b3 --- /dev/null +++ b/ports/geckolib/sanity_checks.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 http://mozilla.org/MPL/2.0/. */ + +//! Different static asserts that ensure the build does what it's expected to. +//! +//! TODO: maybe cfg(test) this? + +#![allow(unused_imports)] + +use std::mem; + +macro_rules! check_enum_value { + ($a:expr, $b:expr) => { + unsafe { + mem::transmute::<[u32; $a as usize], + [u32; $b as usize]>([0; $a as usize]); + } + } +} + +// NB: It's a shame we can't do this statically with bitflags, but no +// const-fn and no other way to access the numerical value :-( +macro_rules! check_enum_value_non_static { + ($a:expr, $b:expr) => { + assert_eq!($a as usize, $b as usize); + } +} + +#[test] +fn assert_restyle_hints_match() { + use style::restyle_hints::*; // For flags + use gecko_bindings::structs::nsRestyleHint; + + check_enum_value_non_static!(nsRestyleHint::eRestyle_Self, RESTYLE_SELF.bits()); + // XXX This for Servo actually means something like an hypothetical + // Restyle_AllDescendants (but without running selector matching on the + // element). ServoRestyleManager interprets it like that, but in practice we + // should align the behavior with Gecko adding a new restyle hint, maybe? + // + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1291786 + check_enum_value_non_static!(nsRestyleHint::eRestyle_SomeDescendants, RESTYLE_DESCENDANTS.bits()); + check_enum_value_non_static!(nsRestyleHint::eRestyle_LaterSiblings, RESTYLE_LATER_SIBLINGS.bits()); +} diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 4776a9209d1..5eaad0ba7b9 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -158,6 +158,17 @@ class MachCommands(CommandBase): return suite return None + @Command('test-geckolib', + description='Test geckolib sanity checks', + category='testing') + def test_geckolib(self): + self.ensure_bootstrapped() + + env = self.build_env() + env["RUST_BACKTRACE"] = "1" + + return call(["cargo", "test"], env=env, cwd=path.join("ports", "geckolib")) + @Command('test-unit', description='Run unit tests', category='testing')