Defined new trait ParseErrorReporter and added error_reporter member to ParserContext

This commit is contained in:
GauriGNaik 2015-10-26 11:31:28 -04:00 committed by Josh Matthews
parent 8efc954531
commit 996e9e06b2
24 changed files with 194 additions and 69 deletions

View file

@ -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());
}