|
| 1 | +(function(){ |
| 2 | + |
| 3 | + /*global YUITest, CSSLint*/ |
| 4 | + var Assert = YUITest.Assert; |
| 5 | + |
| 6 | + YUITest.TestRunner.add(new YUITest.TestCase({ |
| 7 | + |
| 8 | + name: "Bulletproof @font-face syntax tests", |
| 9 | + |
| 10 | + "Using the official bulletproof syntax should pass": function(){ |
| 11 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 12 | + "src: url('myfont-webfont.eot?') format('embedded-opentype')," + |
| 13 | + "url('myfont-webfont.woff') format('woff')," + |
| 14 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 15 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 16 | + { "bulletproof-font-face": 1 }); |
| 17 | + Assert.areEqual(0, result.messages.length); |
| 18 | + }, |
| 19 | + |
| 20 | + "Skipping the hashtag with the svgFontName and having content after .eot? should also pass": function(){ |
| 21 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 22 | + "src: url('myfont-webfont.eot?#iefix') format('embedded-opentype')," + |
| 23 | + "url('myfont-webfont.woff') format('woff')," + |
| 24 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 25 | + "url('myfont-webfont.svg') format('svg');}", |
| 26 | + { "bulletproof-font-face": 1 }); |
| 27 | + Assert.areEqual(0, result.messages.length); |
| 28 | + }, |
| 29 | + |
| 30 | + "The minified version of the code should pass": function(){ |
| 31 | + var result = CSSLint.verify("@font-face{font-family:'MyFontFamily';" + |
| 32 | + "src:url('myfont-webfont.eot?#iefix') format('embedded-opentype')," + |
| 33 | + "url('myfont-webfont.woff') format('woff')," + |
| 34 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 35 | + "url('myfont-webfont.svg#svgFontName') format('svg')}", |
| 36 | + { "bulletproof-font-face": 1 }); |
| 37 | + Assert.areEqual(0, result.messages.length); |
| 38 | + }, |
| 39 | + |
| 40 | + "Skipping one of the font types should pass": function(){ |
| 41 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 42 | + "src: url('myfont-webfont.eot?') format('embedded-opentype')," + |
| 43 | + "url('myfont-webfont.woff') format('woff')," + |
| 44 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 45 | + { "bulletproof-font-face": 1 }); |
| 46 | + Assert.areEqual(0, result.messages.length); |
| 47 | + }, |
| 48 | + |
| 49 | + |
| 50 | + "Supplying the fonts in a different order should pass": function(){ |
| 51 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 52 | + "src: url('myfont-webfont.eot?#iefix') format('embedded-opentype')," + |
| 53 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 54 | + "url('myfont-webfont.woff') format('woff')," + |
| 55 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 56 | + { "bulletproof-font-face": 1 }); |
| 57 | + Assert.areEqual(0, result.messages.length); |
| 58 | + }, |
| 59 | + |
| 60 | + "Using mixed double and single quotes should pass": function(){ |
| 61 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 62 | + "src: url(\"myfont-webfont.eot?#iefix\") format(\"embedded-opentype\")," + |
| 63 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 64 | + "url(\"myfont-webfont.woff\") format('woff')," + |
| 65 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 66 | + { "bulletproof-font-face": 1 }); |
| 67 | + Assert.areEqual(0, result.messages.length); |
| 68 | + }, |
| 69 | + |
| 70 | + "Having only one font declaration with the question mark should pass": function(){ |
| 71 | + var result = CSSLint.verify("@font-face{src:url('myfont-webfont.eot?') format('embedded-opentype');}", |
| 72 | + { "bulletproof-font-face": 1 }); |
| 73 | + Assert.areEqual(0, result.messages.length); |
| 74 | + }, |
| 75 | + |
| 76 | + "When we aren't inside an @font-face declaration the src property should not be checked": function(){ |
| 77 | + var result = CSSLint.verify(".foo .bar{src:url('baz.png');}", { "bulletproof-font-face": 1 }); |
| 78 | + Assert.areEqual(0, result.messages.length); |
| 79 | + }, |
| 80 | + |
| 81 | + "Using the advanced syntax with two src properties should pass": function(){ |
| 82 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 83 | + "src: url('webfont.eot'); /* IE9 Compat Modes */" + |
| 84 | + "src: url('myfont-webfont.eot?') format('embedded-opentype')," + |
| 85 | + "url('myfont-webfont.woff') format('woff')," + |
| 86 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 87 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 88 | + { "bulletproof-font-face": 1 }); |
| 89 | + Assert.areEqual(0, result.messages.length); |
| 90 | + }, |
| 91 | + |
| 92 | + "Leaving off the question mark should fail": function(){ |
| 93 | + var result = CSSLint.verify("@font-face { font-family: 'MyFontFamily';" + |
| 94 | + "src: url('myfont-webfont.eot') format('embedded-opentype')," + |
| 95 | + "url('myfont-webfont.woff') format('woff')," + |
| 96 | + "url('myfont-webfont.ttf') format('truetype')," + |
| 97 | + "url('myfont-webfont.svg#svgFontName') format('svg');}", |
| 98 | + { "bulletproof-font-face": 1 }); |
| 99 | + Assert.areEqual(1, result.messages.length); |
| 100 | + Assert.areEqual("warning", result.messages[0].type); |
| 101 | + Assert.areEqual("@font-face declaration doesn't follow the fontspring bulletproof syntax.", result.messages[0].message); |
| 102 | + } |
| 103 | + |
| 104 | + })); |
| 105 | +})(); |
0 commit comments