mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Give up on test_parse_stylesheet.
It's not particularly useful.
This commit is contained in:
parent
add08518cd
commit
36c39d53f7
4 changed files with 3 additions and 272 deletions
|
@ -15,7 +15,6 @@ app_units = "0.7"
|
|||
cssparser = "0.25"
|
||||
euclid = "0.19"
|
||||
html5ever = "0.23"
|
||||
parking_lot = "0.8"
|
||||
rayon = "1"
|
||||
serde_json = "1.0"
|
||||
selectors = {path = "../../../components/selectors"}
|
||||
|
|
|
@ -10,7 +10,6 @@ extern crate cssparser;
|
|||
extern crate euclid;
|
||||
#[macro_use]
|
||||
extern crate html5ever;
|
||||
extern crate parking_lot;
|
||||
extern crate rayon;
|
||||
extern crate selectors;
|
||||
extern crate serde_json;
|
||||
|
|
|
@ -2,283 +2,17 @@
|
|||
* 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::{self, SourceLocation};
|
||||
use html5ever::Namespace as NsAtom;
|
||||
use parking_lot::RwLock;
|
||||
use selectors::attr::*;
|
||||
use selectors::parser::*;
|
||||
use cssparser::SourceLocation;
|
||||
use servo_arc::Arc;
|
||||
use servo_atoms::Atom;
|
||||
use servo_config::set_pref;
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use style::context::QuirksMode;
|
||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use style::media_queries::MediaList;
|
||||
use style::properties::longhands;
|
||||
use style::properties::{CSSWideKeyword, CustomDeclaration};
|
||||
use style::properties::{CustomDeclarationValue, Importance};
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{
|
||||
CssRule, CssRules, NamespaceRule, StyleRule, Stylesheet, StylesheetContents,
|
||||
};
|
||||
use style::stylesheets::{Namespaces, Origin};
|
||||
use style::values::specified::PositionComponent;
|
||||
|
||||
pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock
|
||||
where
|
||||
I: IntoIterator<Item = (PropertyDeclaration, Importance)>,
|
||||
{
|
||||
let mut block = PropertyDeclarationBlock::new();
|
||||
for (d, i) in iterable {
|
||||
block.push(d, i);
|
||||
}
|
||||
block
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_stylesheet() {
|
||||
let css = r"
|
||||
@namespace url(http://www.w3.org/1999/xhtml);
|
||||
/* FIXME: only if scripting is enabled */
|
||||
input[type=hidden i] {
|
||||
display: block !important;
|
||||
display: none !important;
|
||||
display: inline;
|
||||
--a: b !important;
|
||||
--a: inherit !important;
|
||||
--a: c;
|
||||
}
|
||||
html , body /**/ {
|
||||
display: none;
|
||||
display: block;
|
||||
}
|
||||
#d1 > .ok { background: blue; }
|
||||
}";
|
||||
let url = ServoUrl::parse("about::test").unwrap();
|
||||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
css,
|
||||
url.clone(),
|
||||
Origin::UserAgent,
|
||||
media,
|
||||
lock,
|
||||
None,
|
||||
None,
|
||||
QuirksMode::NoQuirks,
|
||||
0,
|
||||
);
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
contents: StylesheetContents {
|
||||
origin: Origin::UserAgent,
|
||||
namespaces: RwLock::new(namespaces),
|
||||
url_data: RwLock::new(url),
|
||||
quirks_mode: QuirksMode::NoQuirks,
|
||||
rules: CssRules::new(
|
||||
vec![
|
||||
CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule {
|
||||
prefix: None,
|
||||
url: NsAtom::from("http://www.w3.org/1999/xhtml"),
|
||||
source_location: SourceLocation {
|
||||
line: 1,
|
||||
column: 19,
|
||||
},
|
||||
}))),
|
||||
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
|
||||
selectors: SelectorList::from_vec(vec![Selector::from_vec(
|
||||
vec![
|
||||
Component::DefaultNamespace(NsAtom::from(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
)),
|
||||
Component::LocalName(LocalName {
|
||||
name: local_name!("input"),
|
||||
lower_name: local_name!("input"),
|
||||
}),
|
||||
Component::AttributeInNoNamespace {
|
||||
local_name: local_name!("type"),
|
||||
operator: AttrSelectorOperator::Equal,
|
||||
value: "hidden".to_owned(),
|
||||
case_sensitivity: ParsedCaseSensitivity::AsciiCaseInsensitive,
|
||||
never_matches: false,
|
||||
},
|
||||
],
|
||||
(0 << 20) + (1 << 10) + (1 << 0),
|
||||
)]),
|
||||
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
|
||||
(
|
||||
PropertyDeclaration::Display(
|
||||
longhands::display::SpecifiedValue::None,
|
||||
),
|
||||
Importance::Important,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::Custom(CustomDeclaration {
|
||||
name: Atom::from("a"),
|
||||
value: CustomDeclarationValue::CSSWideKeyword(
|
||||
CSSWideKeyword::Inherit,
|
||||
),
|
||||
}),
|
||||
Importance::Important,
|
||||
),
|
||||
]))),
|
||||
source_location: SourceLocation { line: 3, column: 9 },
|
||||
}))),
|
||||
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
|
||||
selectors: SelectorList::from_vec(vec![
|
||||
Selector::from_vec(
|
||||
vec![
|
||||
Component::DefaultNamespace(NsAtom::from(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
)),
|
||||
Component::LocalName(LocalName {
|
||||
name: local_name!("html"),
|
||||
lower_name: local_name!("html"),
|
||||
}),
|
||||
],
|
||||
(0 << 20) + (0 << 10) + (1 << 0),
|
||||
),
|
||||
Selector::from_vec(
|
||||
vec![
|
||||
Component::DefaultNamespace(NsAtom::from(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
)),
|
||||
Component::LocalName(LocalName {
|
||||
name: local_name!("body"),
|
||||
lower_name: local_name!("body"),
|
||||
}),
|
||||
],
|
||||
(0 << 20) + (0 << 10) + (1 << 0),
|
||||
),
|
||||
]),
|
||||
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![(
|
||||
PropertyDeclaration::Display(longhands::display::SpecifiedValue::Block),
|
||||
Importance::Normal,
|
||||
)]))),
|
||||
source_location: SourceLocation {
|
||||
line: 11,
|
||||
column: 9,
|
||||
},
|
||||
}))),
|
||||
CssRule::Style(Arc::new(stylesheet.shared_lock.wrap(StyleRule {
|
||||
selectors: SelectorList::from_vec(vec![Selector::from_vec(
|
||||
vec![
|
||||
Component::DefaultNamespace(NsAtom::from(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
)),
|
||||
Component::ID(Atom::from("d1")),
|
||||
Component::Combinator(Combinator::Child),
|
||||
Component::DefaultNamespace(NsAtom::from(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
)),
|
||||
Component::Class(Atom::from("ok")),
|
||||
],
|
||||
(1 << 20) + (1 << 10) + (0 << 0),
|
||||
)]),
|
||||
block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![
|
||||
(
|
||||
PropertyDeclaration::BackgroundColor(
|
||||
longhands::background_color::SpecifiedValue::Numeric {
|
||||
authored: Some("blue".to_owned().into_boxed_str()),
|
||||
parsed: cssparser::RGBA::new(0, 0, 255, 255),
|
||||
},
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundPositionX(
|
||||
longhands::background_position_x::SpecifiedValue(vec![
|
||||
PositionComponent::zero(),
|
||||
].into()),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundPositionY(
|
||||
longhands::background_position_y::SpecifiedValue(vec![
|
||||
PositionComponent::zero(),
|
||||
].into()),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundRepeat(
|
||||
longhands::background_repeat::SpecifiedValue(
|
||||
vec![longhands::background_repeat::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundAttachment(
|
||||
longhands::background_attachment::SpecifiedValue(
|
||||
vec![longhands::background_attachment::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundImage(
|
||||
longhands::background_image::SpecifiedValue(
|
||||
vec![longhands::background_image::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundSize(
|
||||
longhands::background_size::SpecifiedValue(
|
||||
vec![longhands::background_size::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundOrigin(
|
||||
longhands::background_origin::SpecifiedValue(
|
||||
vec![longhands::background_origin::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
(
|
||||
PropertyDeclaration::BackgroundClip(
|
||||
longhands::background_clip::SpecifiedValue(
|
||||
vec![longhands::background_clip::single_value
|
||||
::get_initial_specified_value()].into(),
|
||||
),
|
||||
),
|
||||
Importance::Normal,
|
||||
),
|
||||
]))),
|
||||
source_location: SourceLocation {
|
||||
line: 15,
|
||||
column: 9,
|
||||
},
|
||||
}))),
|
||||
],
|
||||
&stylesheet.shared_lock,
|
||||
),
|
||||
source_map_url: RwLock::new(None),
|
||||
source_url: RwLock::new(None),
|
||||
},
|
||||
media: Arc::new(stylesheet.shared_lock.wrap(MediaList::empty())),
|
||||
shared_lock: stylesheet.shared_lock.clone(),
|
||||
disabled: AtomicBool::new(false),
|
||||
};
|
||||
|
||||
assert_eq!(format!("{:#?}", stylesheet), format!("{:#?}", expected));
|
||||
}
|
||||
use style::stylesheets::Stylesheet;
|
||||
use style::stylesheets::Origin;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CSSError {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue