New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP #17808
Closed
+186
−1
Closed
WIP #17808
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.
| @@ -0,0 +1,101 @@ | ||
| /* 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/. */ | ||
|
|
||
| use script::test::DOMString; | ||
| use script::test::sizes::{parse_a_sizes_attribute, Size}; | ||
| use style::media_queries::{MediaQuery, MediaQueryType}; | ||
| use style::media_queries::Expression; | ||
| use style::servo::media_queries::{ExpressionKind, Range}; | ||
| use style::values::specified::{Length, NoCalcLength, AbsoluteLength, ViewportPercentageLength}; | ||
|
|
||
|
|
||
| pub fn test_length_for_no_default_provided(len: f32) -> Length { | ||
| let length = Length::NoCalc(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(len))); | ||
| return length; | ||
| } | ||
|
|
||
| #[test] | ||
| fn no_default_provided() { | ||
| let mut a = vec![]; | ||
| let length = test_length_for_no_default_provided(100f32); | ||
| let size = Size { query: None, length: length }; | ||
| a.push(size); | ||
| assert_eq!(parse_a_sizes_attribute(DOMString::new(), None), a); | ||
| } | ||
|
|
||
| pub fn test_length_for_default_provided(len: f32) -> Length { | ||
| let length = Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(len))); | ||
| return length; | ||
| } | ||
|
|
||
| #[test] | ||
| fn default_provided() { | ||
| let mut a = vec![]; | ||
| let length = test_length_for_default_provided(2f32); | ||
| let size = Size { query: None, length: length }; | ||
| a.push(size); | ||
wafflespeanut
Member
|
||
| assert_eq!(parse_a_sizes_attribute(DOMString::new(), Some(2)), a); | ||
| } | ||
|
|
||
| pub fn test_media_query(len: f32) -> MediaQuery { | ||
| let length = Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(len))); | ||
| let expr = Expression(ExpressionKind::Width(Range::Max(length))); | ||
| let media_query = MediaQuery { | ||
| qualifier: None, | ||
| media_type: MediaQueryType::All, | ||
| expressions: vec![expr] | ||
| }; | ||
| media_query | ||
| } | ||
|
|
||
| pub fn test_length(len: f32) -> Length { | ||
| let length = Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(len))); | ||
| return length; | ||
| } | ||
|
|
||
| #[test] | ||
| fn one_value() { | ||
| let mut a = vec![]; | ||
| let media_query = test_media_query(200f32); | ||
| let length = test_length(545f32); | ||
| let size = Size { query: Some(media_query), length: length }; | ||
| a.push(size); | ||
| assert_eq!(parse_a_sizes_attribute(DOMString::from("(max-width: 200px) 545px"), None), a); | ||
| } | ||
|
|
||
| #[test] | ||
| fn more_then_one_value() { | ||
| let media_query = test_media_query(900f32); | ||
| let length = test_length(1000f32); | ||
| let size = Size { query: Some(media_query), length: length }; | ||
| let media_query1 = test_media_query(900f32); | ||
| let length1 = test_length(50f32); | ||
| let size1 = Size { query: Some(media_query1), length: length1 }; | ||
| let a = &[size, size1]; | ||
| assert_eq!(parse_a_sizes_attribute(DOMString::from("(max-width: 900px) 1000px, (max-width: 900px) 50px"), | ||
| None), a); | ||
| } | ||
|
|
||
| #[test] | ||
| fn no_extra_whitespace() { | ||
| let mut a = vec![]; | ||
| let media_query = test_media_query(200f32); | ||
| let length = test_length(545f32); | ||
| let size = Size { query: Some(media_query), length: length }; | ||
| a.push(size); | ||
| assert_eq!(parse_a_sizes_attribute(DOMString::from("(max-width: 200px) 545px"), None), a); | ||
| } | ||
|
|
||
| #[test] | ||
| fn extra_whitespace() { | ||
| let media_query = test_media_query(900f32); | ||
| let length = test_length(1000f32); | ||
| let size = Size { query: Some(media_query), length: length }; | ||
| let media_query1 = test_media_query(900f32); | ||
| let length1 = test_length(50f32); | ||
| let size1 = Size { query: Some(media_query1), length: length1 }; | ||
| let a = &[size, size1]; | ||
| assert_eq!(parse_a_sizes_attribute(DOMString::from("(max-width: 900px) 1000px, (max-width: 900px) 50px"), | ||
| None), a); | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
nit: remove this extra newline.