| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | |
| 4 <script src="../../../http/tests/inspector/elements-test.js"></script> | |
| 5 <script> | |
| 6 function test() | |
| 7 { | |
| 8 var colors = [ | |
| 9 // Each of these is red. Some may need to be clipped to [0, 255]. | |
| 10 'red', | |
| 11 '#F00', | |
| 12 'rgb(255,0,0)', | |
| 13 'rgb(300,0,0)', // clipped to rgb(255,0,0) | |
| 14 'rgb(255,-10,0)', // clipped to rgb(255,0,0) | |
| 15 'rgb(110%, 0%, 0%)', // clipped to rgb(100%,0%,0%) | |
| 16 | |
| 17 // Each of these are valid | |
| 18 'rgba(0,0,0,0.5)', | |
| 19 'hsl(-120, 100%, 50%)', | |
| 20 'hsl(-120, 200%, 200%)', // clipped to hsl(240,100%,100%) | |
| 21 'hsl(-120, -200%, -200%)', // clipped to hsl(240,100%,100%) | |
| 22 'hsla(-120, -200%, -200%, -5)', // clipped to hsla(0,0%,0%,0) | |
| 23 'hsla(240,100%,50%,0.05)', | |
| 24 'hsl(200.5,0%,50%)', | |
| 25 'hsla(200,1.5%,50%,1)', | |
| 26 | |
| 27 // Each of these has their alpha clipped [0.0, 1.0]. | |
| 28 'rgba(255, 0, 0, -5)', // clipped to rgba(255,0,0,0) | |
| 29 'rgba(255, 0, 0, 5)', // clipped to rgba(255,0,0,1) | |
| 30 ]; | |
| 31 | |
| 32 var invalidColors = [ | |
| 33 // An invalid color, eg a value for a shorthand like 'border' which can
have a color | |
| 34 'none', | |
| 35 '#0000', | |
| 36 '#00000', | |
| 37 '#ggg', | |
| 38 'rgb(a,b,c)', | |
| 39 'rgb(a,b,c,d)', | |
| 40 'rgb(1,1,1.2)', | |
| 41 'rgba(0,0,0,1%)', | |
| 42 'hsl(0,0,0)', | |
| 43 'hsl(0%, 0%, 0%)', | |
| 44 'hsl(0, 0%, 0)', | |
| 45 'hsl(a,b,c)', | |
| 46 'hsla(0,0,0,0)', | |
| 47 'hsla' | |
| 48 ]; | |
| 49 | |
| 50 InspectorTest.runTestSuite([ | |
| 51 function testColors(next) | |
| 52 { | |
| 53 for (var i = 0; i < colors.length; ++i) | |
| 54 dumpColorRepresentationsForColor(colors[i]); | |
| 55 next(); | |
| 56 }, | |
| 57 function testInvalidColors(next) | |
| 58 { | |
| 59 for (var i = 0; i < invalidColors.length; ++i) | |
| 60 dumpErrorsForInvalidColor(invalidColors[i]); | |
| 61 next(); | |
| 62 }, | |
| 63 ]); | |
| 64 | |
| 65 function dumpErrorsForInvalidColor(colorString) | |
| 66 { | |
| 67 var color = WebInspector.Color.parse(colorString); | |
| 68 if (!color) { | |
| 69 InspectorTest.addResult(""); | |
| 70 InspectorTest.addResult("SUCCESS: parsed invalid color " + colorStri
ng + " to null"); | |
| 71 } else { | |
| 72 InspectorTest.addResult(""); | |
| 73 InspectorTest.addResult("FAIL: invalid color " + colorString + " did
not parse to to null"); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 function dumpColorRepresentationsForColor(colorString) | |
| 78 { | |
| 79 var color = WebInspector.Color.parse(colorString); | |
| 80 if (!color) | |
| 81 return; | |
| 82 | |
| 83 InspectorTest.addResult(""); | |
| 84 InspectorTest.addResult("color: " + colorString); | |
| 85 InspectorTest.addResult(" simple: " + !color.hasAlpha()); | |
| 86 var cf = WebInspector.Color.Format; | |
| 87 for (var colorFormatKey in cf) { | |
| 88 var colorFormat = cf[colorFormatKey]; | |
| 89 // Simple colors do not have RGBA and HSLA representations. | |
| 90 if (!color.hasAlpha() && (colorFormat === cf.RGBA || colorFormat ===
cf.HSLA)) | |
| 91 continue; | |
| 92 // Advanced colors do not have HEX representations. | |
| 93 if (color.hasAlpha() && (colorFormat === cf.ShortHEX || colorFormat
=== cf.HEX)) | |
| 94 continue; | |
| 95 // If there is no ShortHEX then skip it. | |
| 96 if (colorFormat === cf.ShortHEX && !color.canBeShortHex()) | |
| 97 continue; | |
| 98 // If there is no nickname, then skip it. | |
| 99 if (colorFormat === cf.Nickname && !color.nickname()) | |
| 100 continue; | |
| 101 InspectorTest.addResult(' ' + colorFormat + ": " + color.asString(c
olorFormat)); | |
| 102 } | |
| 103 } | |
| 104 } | |
| 105 </script> | |
| 106 </head> | |
| 107 | |
| 108 <body onload="runTest()"> | |
| 109 <p> | |
| 110 Tests that the displayed string for colors correctly handles clipped CSS values
and RGB percentages. | |
| 111 </p> | |
| 112 | |
| 113 </body> | |
| 114 </html> | |
| OLD | NEW |