Skip to content

Commit

Permalink
style: Smoke-test the dependency tracking logic.
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: J5HWdS1H49s
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
  • Loading branch information
emilio committed Apr 13, 2017
1 parent 9e33cd5 commit a0c2bdf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -22,6 +22,7 @@ matrix:
- bash etc/ci/lockfile_changed.sh
- bash etc/ci/manifest_changed.sh
- ./mach cargo test -p selectors
- ./mach cargo test -p style
cache:
directories:
- .cargo
Expand Down
24 changes: 23 additions & 1 deletion components/selectors/parser.rs
Expand Up @@ -1164,7 +1164,7 @@ pub mod tests {
impl SelectorMethods for PseudoClass {
type Impl = DummySelectorImpl;

fn visit<V>(&self, visitor: &mut V) -> bool
fn visit<V>(&self, _visitor: &mut V) -> bool
where V: SelectorVisitor<Impl = Self::Impl> { true }
}

Expand Down Expand Up @@ -1501,4 +1501,26 @@ pub mod tests {
specificity: specificity(1, 1, 0),
}))));
}

struct TestVisitor {
seen: Vec<String>,
}

impl SelectorVisitor for TestVisitor {
type Impl = DummySelectorImpl;

fn visit_simple_selector(&mut self, s: &SimpleSelector<DummySelectorImpl>) -> bool {
let mut dest = String::new();
s.to_css(&mut dest).unwrap();
self.seen.push(dest);
true
}
}

#[test]
fn visitor() {
let mut test_visitor = TestVisitor { seen: vec![], };
parse(":not(:hover) ~ label").unwrap().0[0].visit(&mut test_visitor);
assert!(test_visitor.seen.contains(&":hover".into()));
}
}
1 change: 0 additions & 1 deletion components/selectors/visitor.rs
Expand Up @@ -7,7 +7,6 @@
#![deny(missing_docs)]

use parser::{AttrSelector, Combinator, ComplexSelector, SelectorImpl, SimpleSelector};
use std::sync::Arc;

/// A trait to visit selector properties.
///
Expand Down
49 changes: 40 additions & 9 deletions components/style/restyle_hints.rs
Expand Up @@ -279,7 +279,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
fn match_non_ts_pseudo_class<F>(&self,
pseudo_class: &NonTSPseudoClass,
relations: &mut StyleRelations,
_: &mut F)
_setter: &mut F)
-> bool
where F: FnMut(&Self, ElementSelectorFlags),
{
Expand All @@ -293,12 +293,12 @@ impl<'a, E> Element for ElementWrapper<'a, E>
self,
None,
relations,
setter)
_setter)
})
}
}

let flag = SelectorImpl::pseudo_class_state_flag(pseudo_class);
let flag = pseudo_class.state_flag();
if flag.is_empty() {
return self.element.match_non_ts_pseudo_class(pseudo_class,
relations,
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>

fn selector_to_state(sel: &SimpleSelector<SelectorImpl>) -> ElementState {
match *sel {
SimpleSelector::NonTSPseudoClass(ref pc) => SelectorImpl::pseudo_class_state_flag(pc),
SimpleSelector::NonTSPseudoClass(ref pc) => pc.state_flag(),
_ => ElementState::empty(),
}
}
Expand Down Expand Up @@ -505,6 +505,7 @@ impl SelectorVisitor for SensitivitiesVisitor {
combinator: Option<Combinator>) -> bool {
self.hint |= combinator_to_restyle_hint(combinator);
self.needs_revalidation |= self.hint.contains(RESTYLE_LATER_SIBLINGS);

true
}

Expand Down Expand Up @@ -577,21 +578,28 @@ impl DependencySet {
ss.visit(&mut sensitivities_visitor);
}

sensitivities_visitor.hint |= combinator_to_restyle_hint(combinator);
needs_revalidation |= sensitivities_visitor.needs_revalidation;

if !sensitivities_visitor.sensitivities.is_empty() {
let SensitivitiesVisitor {
sensitivities,
mut hint,
..
} = sensitivities_visitor;

hint |= combinator_to_restyle_hint(combinator);

if !sensitivities.is_empty() {
self.add_dependency(Dependency {
sensitivities: sensitivities_visitor.sensitivities,
hint: sensitivities_visitor.hint,
sensitivities: sensitivities,
hint: hint,
selector: current.clone(),
})
}

match current.next {
Some((ref next, next_combinator)) => {
combinator = Some(next_combinator);
current = next;
combinator = Some(next_combinator);
}
None => break,
}
Expand Down Expand Up @@ -697,3 +705,26 @@ impl DependencySet {
}
}
}

#[test]
#[cfg(all(test, feature = "servo"))]
fn smoke_restyle_hints() {
use cssparser::Parser;
use selector_parser::SelectorParser;
use stylesheets::{Origin, Namespaces};
let namespaces = Namespaces::default();
let parser = SelectorParser {
stylesheet_origin: Origin::Author,
namespaces: &namespaces,
};

let mut dependencies = DependencySet::new();

let mut p = Parser::new(":not(:active) ~ label");
let selector = Arc::new(ComplexSelector::parse(&parser, &mut p).unwrap());
dependencies.note_selector(&selector);
assert_eq!(dependencies.len(), 1);
assert_eq!(dependencies.state_deps.len(), 1);
assert!(!dependencies.state_deps[0].sensitivities.states.is_empty());
assert!(dependencies.state_deps[0].hint.contains(RESTYLE_LATER_SIBLINGS));
}

0 comments on commit a0c2bdf

Please sign in to comment.