Permalink
Browse files

A bunch more tests.

  • Loading branch information...
1 parent b8d4fe1 commit 6c70758ca1c2399605e2fdec2c82de4337d78b9b @zachleat zachleat committed Dec 30, 2013
Showing with 48 additions and 7 deletions.
  1. +5 −3 src/respond.js
  2. +10 −0 test/unit/test-with-dpr.css
  3. +33 −4 test/unit/tests.js
View
@@ -42,13 +42,15 @@
return;
}
req.send( null );
+ },
+ isUnsupportedMediaQuery = function( query ) {
+ return query.replace( respond.regex.minmaxwh, '' ).match( respond.regex.other );
};
//expose for testing
respond.ajax = ajax;
respond.queue = requestQueue;
-
- // expose for testing
+ respond.unsupportedmq = isUnsupportedMediaQuery;
respond.regex = {
media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,
keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,
@@ -263,7 +265,7 @@
for( var j = 0; j < eql; j++ ){
thisq = eachq[ j ];
- if( thisq.replace( respond.regex.minmaxwh, '' ).match( respond.regex.other ) ) {
+ if( isUnsupportedMediaQuery( thisq ) ) {
continue;
}
@@ -0,0 +1,10 @@
+@media
+only screen and (max-width: 1004px) and (min--moz-device-pixel-ratio: 1.5),
+only screen and (max-width: 1004px) and (-moz-min-device-pixel-ratio: 1.5),
+only screen and (max-width: 1004px) and (-o-min-device-pixel-ratio: 3/2),
+only screen and (max-width: 1004px) and (-webkit-min-device-pixel-ratio: 1.5),
+only screen and (max-width: 1004px) and (min-device-pixel-ratio: 1.5),
+only screen and (max-width: 1004px) and (min-resolution: 1.5dppx) {
+
+
+}
View
@@ -209,15 +209,44 @@ window.onload = function(){
mq;
for( var j = 0, k = others.length; j<k; j++ ) {
- str = '@media only screen and (max-width: 1319px) and ' + others[ j ] + ' {}';
+ str = 'only screen and (max-width: 1319px) and ' + others[ j ] + ' {}';
mq = str.match( respond.regex.minmaxwh );
equal( mq && mq[ 0 ], '(max-width: 1319px)' );
- equal( str.replace( respond.regex.minmaxwh, '' ).match( respond.regex.other )[ 0 ], others[ j ] );
+ equal( respond.unsupportedmq( str )[ 0 ], others[ j ] );
- equal( ( '@media only screen and (max-width: 1319px) and (min-width: 1px) and ' + others[ j ] + ' {}' ).replace( respond.regex.minmaxwh, '' ).match( respond.regex.other )[ 0 ], others[ j ] );
- equal( ( '@media only screen and (max-width: 1319px) and (min-height: 1px) and ' + others[ j ] + ' {}' ).replace( respond.regex.minmaxwh, '' ).match( respond.regex.other )[ 0 ], others[ j ] );
+ equal( ( 'only screen and (max-width: 1319px) and (min-width: 1px) and ' + others[ j ] + ' {}' ).replace( respond.regex.minmaxwh, '' ).match( respond.regex.other )[ 0 ], others[ j ] );
+ equal( ( 'only screen and (max-width: 1319px) and (min-height: 1px) and ' + others[ j ] + ' {}' ).replace( respond.regex.minmaxwh, '' ).match( respond.regex.other )[ 0 ], others[ j ] );
}
});
+
+ // At this point the media queries are already divided by commas
+ test( 'Issue #181: unsupported MQ tests', function() {
+ // should pass
+ strictEqual( respond.unsupportedmq( '(min-width: 1151px)' ), null );
+ strictEqual( respond.unsupportedmq( 'all and (max-width: 699px) and (min-width: 520px)' ), null );
+ strictEqual( respond.unsupportedmq( 'print' ), null );
+
+ // source: http://www.w3.org/TR/css3-mediaqueries/
+ // should fail: looks for anything in parens that is not min/max-height/width
+ ok( respond.unsupportedmq( 'all and (orientation:portrait)' ) );
+ ok( respond.unsupportedmq( 'screen and (device-aspect-ratio: 16/9)' ) );
+ ok( respond.unsupportedmq( 'all and (color)' ) );
+ ok( respond.unsupportedmq( 'all and (min-color: 1)' ) );
+ ok( respond.unsupportedmq( 'all and (monochrome)' ) );
+ ok( respond.unsupportedmq( 'print and (min-resolution: 300dpi)' ) );
+ ok( respond.unsupportedmq( 'tv and (scan: progressive)' ) );
+ ok( respond.unsupportedmq( 'handheld and (grid) and (device-max-height: 7em)' ) );
+ });
+
+ asyncTest( 'Issue #181: full MQ with DPR', function() {
+ queueRequest( function() {
+ respond.ajax( getNormalizedUrl( 'test-with-dpr.css' ),
+ function( data ) {
+ ok( respond.unsupportedmq( data ) );
+ start();
+ });
+ });
+ });
}
};

0 comments on commit 6c70758

Please sign in to comment.