mirror of
https://github.com/servo/servo.git
synced 2025-08-13 09:25:32 +01:00
Defined new trait ParseErrorReporter and added error_reporter member to ParserContext
This commit is contained in:
parent
8efc954531
commit
996e9e06b2
24 changed files with 194 additions and 69 deletions
|
@ -3,16 +3,28 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::{Parser, SourcePosition};
|
||||
use euclid::size::Size2D;
|
||||
use std::borrow::ToOwned;
|
||||
use style::media_queries::*;
|
||||
use style::stylesheets::{Origin, Stylesheet, CSSRuleIteratorExt};
|
||||
use style::values::specified;
|
||||
use style_traits::ParseErrorReporter;
|
||||
|
||||
pub struct CSSErrorReporterTest;
|
||||
|
||||
impl ParseErrorReporter for CSSErrorReporterTest {
|
||||
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str) {
|
||||
}
|
||||
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
|
||||
let error_reporter = Box::new(CSSErrorReporterTest);
|
||||
return error_reporter;
|
||||
}
|
||||
}
|
||||
|
||||
fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str) {
|
||||
let url = url!("http://localhost");
|
||||
let stylesheet = Stylesheet::from_str(css, url, Origin::Author);
|
||||
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest));
|
||||
let mut rule_count = 0;
|
||||
for rule in stylesheet.rules().media() {
|
||||
rule_count += 1;
|
||||
|
@ -23,7 +35,7 @@ fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaQueryList, &str)
|
|||
|
||||
fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
|
||||
let url = url!("http://localhost");
|
||||
let ss = Stylesheet::from_str(css, url, Origin::Author);
|
||||
let ss = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest));
|
||||
let rule_count = ss.effective_rules(device).style().count();
|
||||
assert!(rule_count == expected_rule_count, css.to_owned());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue