Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | <html class="reftest-wait"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>Image reftest wrapper</title> |
michael@0 | 4 | <link rel="stylesheet" href="ImageDocument.css"> |
michael@0 | 5 | <style type="text/css"> |
michael@0 | 6 | #image_from_encoder { background-color: rgb(10, 100, 250); } |
michael@0 | 7 | </style> |
michael@0 | 8 | |
michael@0 | 9 | <script> |
michael@0 | 10 | // Parse out the URL command line params |
michael@0 | 11 | // Valid options are: |
michael@0 | 12 | // - img=<reference image to use> |
michael@0 | 13 | // - mime=<mime type> |
michael@0 | 14 | // - options=<canvas toDataURL encoder options> |
michael@0 | 15 | // Example: |
michael@0 | 16 | // encoder.html?img=escape(reference_image.png) |
michael@0 | 17 | // &mime=escape(image/ico) |
michael@0 | 18 | // &options=escape(-moz-parse-options:bpp=24;format=png) |
michael@0 | 19 | var getVars = {}; |
michael@0 | 20 | function buildValue(sValue) |
michael@0 | 21 | { |
michael@0 | 22 | if (/^\s*$/.test(sValue)) { |
michael@0 | 23 | return null; |
michael@0 | 24 | } |
michael@0 | 25 | if (/^(true|false)$/i.test(sValue)) { |
michael@0 | 26 | return sValue.toLowerCase() === "true"; |
michael@0 | 27 | } |
michael@0 | 28 | if (isFinite(sValue)) { |
michael@0 | 29 | return parseFloat(sValue); |
michael@0 | 30 | } |
michael@0 | 31 | if (isFinite(Date.parse(sValue))) { |
michael@0 | 32 | return new Date(sValue); |
michael@0 | 33 | } |
michael@0 | 34 | return sValue; |
michael@0 | 35 | } |
michael@0 | 36 | if (window.location.search.length > 1) { |
michael@0 | 37 | var couple, couples = window.location.search.substr(1).split("&"); |
michael@0 | 38 | for (var couplId = 0; couplId < couples.length; couplId++) { |
michael@0 | 39 | couple = couples[couplId].split("="); |
michael@0 | 40 | getVars[unescape(couple[0])] = couple.length > 1 ? |
michael@0 | 41 | buildValue(unescape(couple[1])) : null; |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | // Create the image that we will load the reference image to |
michael@0 | 46 | var img = new Image(); |
michael@0 | 47 | |
michael@0 | 48 | // Create the canvas that we will draw the image img onto and |
michael@0 | 49 | // eventually call toDataURL to invoke the encoder on |
michael@0 | 50 | var canvas = document.createElement("canvas"); |
michael@0 | 51 | |
michael@0 | 52 | // Starts the test by loading the reference image |
michael@0 | 53 | function runTest() |
michael@0 | 54 | { |
michael@0 | 55 | // Load the reference image to start the test |
michael@0 | 56 | img.onload = onReferenceImageLoad; |
michael@0 | 57 | img.onerror = onReferenceImageLoad; |
michael@0 | 58 | img.src = getVars.img; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // Once the encoded image from the canvas is loaded we can |
michael@0 | 62 | // let the reftest compare |
michael@0 | 63 | function onEncodedImageLoad() |
michael@0 | 64 | { |
michael@0 | 65 | document.documentElement.removeAttribute("class"); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // Once the image loads async, we then draw the image onto the canvas, |
michael@0 | 69 | // and call canvas.toDataURL to invoke the encoder, and then set a new |
michael@0 | 70 | // image to the encoded data URL |
michael@0 | 71 | function onReferenceImageLoad() |
michael@0 | 72 | { |
michael@0 | 73 | // mimeType will hold the mime type of which encoder to invoke |
michael@0 | 74 | var mimeType = getVars.mime; |
michael@0 | 75 | // parseOptions will hold the encoder options to use |
michael@0 | 76 | var parseOptions = getVars.options; |
michael@0 | 77 | |
michael@0 | 78 | // Obtain the canvas and draw the reference image |
michael@0 | 79 | canvas.width = img.width; |
michael@0 | 80 | canvas.height = img.height; |
michael@0 | 81 | var ctx = canvas.getContext('2d') |
michael@0 | 82 | ctx.drawImage(img, 0, 0); |
michael@0 | 83 | |
michael@0 | 84 | // Obtain the data URL with parsing options if specified |
michael@0 | 85 | var dataURL; |
michael@0 | 86 | if (parseOptions) |
michael@0 | 87 | dataURL = canvas.toDataURL(mimeType, parseOptions); |
michael@0 | 88 | else |
michael@0 | 89 | dataURL = canvas.toDataURL(mimeType); |
michael@0 | 90 | |
michael@0 | 91 | // Setup async image loaded events |
michael@0 | 92 | var image_from_encoder = document.getElementById('image_from_encoder'); |
michael@0 | 93 | image_from_encoder.onload = onEncodedImageLoad; |
michael@0 | 94 | image_from_encoder.onerror = onEncodedImageLoad; |
michael@0 | 95 | |
michael@0 | 96 | // Only set the image if we have the correct mime type |
michael@0 | 97 | // because we want to fail the ref test if toDataURL fell |
michael@0 | 98 | // back to image/png |
michael@0 | 99 | if (dataURL.substring(0, mimeType.length+5) == "data:" + mimeType) { |
michael@0 | 100 | // Set the image to the BMP data URL |
michael@0 | 101 | image_from_encoder.src = dataURL; |
michael@0 | 102 | } else { |
michael@0 | 103 | // Blank image so that we won't have to timeout the reftest |
michael@0 | 104 | image_from_encoder.src = "data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D"; |
michael@0 | 105 | } |
michael@0 | 106 | }; |
michael@0 | 107 | </script> |
michael@0 | 108 | </head> |
michael@0 | 109 | |
michael@0 | 110 | <body onload="runTest()"> |
michael@0 | 111 | <img id="image_from_encoder"> |
michael@0 | 112 | </body> |
michael@0 | 113 | </html> |