layout/reftests/backgrounds/background-referrer.sjs

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 const BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", "nsIBinaryOutputStream", "setOutputStream");
michael@0 2
michael@0 3 /*
michael@0 4 # Python used to generate the following byte array
michael@0 5 def toHex(n):
michael@0 6 if n < 16: return "0x" + hex(n)[2:].upper()
michael@0 7 return "0x" + hex(n)[2:].upper()
michael@0 8
michael@0 9 def hexFile(name):
michael@0 10 f = open(name, "rb")
michael@0 11 try:
michael@0 12 while True:
michael@0 13 print toHex(ord(f.read(1))) + ", ",
michael@0 14 except:
michael@0 15 pass
michael@0 16
michael@0 17 hexFile("layout/reftests/backgrounds/background-referrer-image.png")
michael@0 18 */
michael@0 19
michael@0 20 const IMAGE_DATA =
michael@0 21 [
michael@0 22 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00,
michael@0 23 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00,
michael@0 24 0x00, 0x64, 0x08, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x02, 0x03,
michael@0 25 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE,
michael@0 26 0x1C, 0xE9, 0x00, 0x00, 0x00, 0x9E, 0x49, 0x44, 0x41, 0x54, 0x78,
michael@0 27 0xDA, 0xED, 0xD0, 0x31, 0x01, 0x00, 0x00, 0x08, 0x03, 0xA0, 0x69,
michael@0 28 0xFF, 0xCE, 0x5A, 0xC1, 0xCF, 0x07, 0x22, 0x50, 0x99, 0x70, 0xD4,
michael@0 29 0x0A, 0x64, 0xC9, 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x05, 0xB2, 0x64,
michael@0 30 0xC9, 0x92, 0x25, 0x4B, 0x96, 0x02, 0x59, 0xB2, 0x64, 0xC9, 0x92,
michael@0 31 0x25, 0x4B, 0x81, 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0xA5, 0x40,
michael@0 32 0x96, 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x52, 0x20, 0x4B, 0x96, 0x2C,
michael@0 33 0x59, 0xB2, 0x64, 0x29, 0x90, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0xB2,
michael@0 34 0x14, 0xC8, 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0x0A, 0x64, 0xC9,
michael@0 35 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x05, 0xB2, 0x64, 0xC9, 0x92, 0x25,
michael@0 36 0x4B, 0x96, 0x02, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0x25, 0x4B, 0x81,
michael@0 37 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0xA5, 0x40, 0x96, 0x2C, 0x59,
michael@0 38 0xB2, 0x64, 0xC9, 0x52, 0x20, 0x4B, 0x96, 0x2C, 0x59, 0xB2, 0x64,
michael@0 39 0x29, 0x90, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0xB2, 0x14, 0xC8, 0x92,
michael@0 40 0x25, 0x4B, 0x96, 0x2C, 0x59, 0x0A, 0x64, 0xC9, 0xFA, 0xB6, 0x89,
michael@0 41 0x5F, 0x01, 0xC7, 0x24, 0x83, 0xB2, 0x0C, 0x00, 0x00, 0x00, 0x00,
michael@0 42 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82,
michael@0 43 ];
michael@0 44
michael@0 45 function handleRequest(request, response)
michael@0 46 {
michael@0 47 response.setHeader("Content-Type", "text/plain", false);
michael@0 48 response.setHeader("Cache-Control", "no-cache", false);
michael@0 49
michael@0 50 var referrer = request.hasHeader("Referer") ?
michael@0 51 request.getHeader("Referer") : "";
michael@0 52
michael@0 53 // Test url looks like:
michael@0 54 // http://localhost:port/timestamp/number/background-referrer.html
michael@0 55 // Except in Android, where it looks like:
michael@0 56 // http://A.B.C.D:port/timestamp/number/background-referrer.html
michael@0 57 // where A.B.C.D is the IP address of the box the reftest HTTP server is
michael@0 58 // running on. And maybe that will change. So just test for ending in
michael@0 59 // "/background-referrer.html".
michael@0 60 if (/\/background-referrer.html$/.test(referrer))
michael@0 61 {
michael@0 62 response.setHeader("Content-Type", "image/png", false);
michael@0 63
michael@0 64 var stream = new BinaryOutputStream(response.bodyOutputStream);
michael@0 65 stream.writeByteArray(IMAGE_DATA, IMAGE_DATA.length);
michael@0 66 }
michael@0 67 else
michael@0 68 {
michael@0 69 response.setStatusLine(request.httpVersion, 404, "Not found");
michael@0 70 response.write("Accept header contained: " + accept);
michael@0 71 }
michael@0 72 }

mercurial