toDataURL.jpeg.primarycolours.html (1692B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <title>Canvas test: toDataURL.jpeg.primarycolours</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/html/canvas/resources/canvas-tests.js"></script> 7 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css"> 8 <body class="show_output"> 9 10 <h1>toDataURL.jpeg.primarycolours</h1> 11 <p class="desc">toDataURL with JPEG handles simple colours correctly</p> 12 13 14 <p class="output">Actual output:</p> 15 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 16 <p class="output expectedtext">Expected output:<p><img src="toDataURL.jpeg.primarycolours.png" class="output expected" id="expected" alt=""> 17 <ul id="d"></ul> 18 <script> 19 var t = async_test("toDataURL with JPEG handles simple colours correctly"); 20 _addTest(function(canvas, ctx) { 21 22 ctx.fillStyle = '#ff0'; 23 ctx.fillRect(0, 0, 25, 40); 24 ctx.fillStyle = '#0ff'; 25 ctx.fillRect(25, 0, 50, 40); 26 ctx.fillStyle = '#00f'; 27 ctx.fillRect(75, 0, 25, 40); 28 ctx.fillStyle = '#fff'; 29 ctx.fillRect(0, 40, 100, 10); 30 var data = canvas.toDataURL('image/jpeg'); // it is okay if this returns a PNG instead 31 ctx.fillStyle = '#f00'; 32 ctx.fillRect(0, 0, 100, 50); 33 var img = new Image(); 34 deferTest(); 35 img.onload = t.step_func_done(function () 36 { 37 ctx.drawImage(img, 0, 0); 38 _assertPixelApprox(canvas, 12,20, 255,255,0,255, 8); 39 _assertPixelApprox(canvas, 50,20, 0,255,255,255, 8); 40 _assertPixelApprox(canvas, 87,20, 0,0,255,255, 8); 41 _assertPixelApprox(canvas, 50,45, 255,255,255,255, 8); 42 }); 43 img.src = data; 44 45 46 }); 47 </script>