1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/reftests/backgrounds/delay-image-response.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +const BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", "nsIBinaryOutputStream", "setOutputStream"); 1.5 +/* This data is picked from image/test/reftest/generic/check-header.sjs */ 1.6 +const IMAGE_DATA = 1.7 + [ 1.8 + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 1.9 + 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 1.10 + 0x00, 0x64, 0x08, 0x02, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x02, 0x03, 1.11 + 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 1.12 + 0x1C, 0xE9, 0x00, 0x00, 0x00, 0x9E, 0x49, 0x44, 0x41, 0x54, 0x78, 1.13 + 0xDA, 0xED, 0xD0, 0x31, 0x01, 0x00, 0x00, 0x08, 0x03, 0xA0, 0x69, 1.14 + 0xFF, 0xCE, 0x5A, 0xC1, 0xCF, 0x07, 0x22, 0x50, 0x99, 0x70, 0xD4, 1.15 + 0x0A, 0x64, 0xC9, 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x05, 0xB2, 0x64, 1.16 + 0xC9, 0x92, 0x25, 0x4B, 0x96, 0x02, 0x59, 0xB2, 0x64, 0xC9, 0x92, 1.17 + 0x25, 0x4B, 0x81, 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0xA5, 0x40, 1.18 + 0x96, 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x52, 0x20, 0x4B, 0x96, 0x2C, 1.19 + 0x59, 0xB2, 0x64, 0x29, 0x90, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0xB2, 1.20 + 0x14, 0xC8, 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0x0A, 0x64, 0xC9, 1.21 + 0x92, 0x25, 0x4B, 0x96, 0x2C, 0x05, 0xB2, 0x64, 0xC9, 0x92, 0x25, 1.22 + 0x4B, 0x96, 0x02, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0x25, 0x4B, 0x81, 1.23 + 0x2C, 0x59, 0xB2, 0x64, 0xC9, 0x92, 0xA5, 0x40, 0x96, 0x2C, 0x59, 1.24 + 0xB2, 0x64, 0xC9, 0x52, 0x20, 0x4B, 0x96, 0x2C, 0x59, 0xB2, 0x64, 1.25 + 0x29, 0x90, 0x25, 0x4B, 0x96, 0x2C, 0x59, 0xB2, 0x14, 0xC8, 0x92, 1.26 + 0x25, 0x4B, 0x96, 0x2C, 0x59, 0x0A, 0x64, 0xC9, 0xFA, 0xB6, 0x89, 1.27 + 0x5F, 0x01, 0xC7, 0x24, 0x83, 0xB2, 0x0C, 0x00, 0x00, 0x00, 0x00, 1.28 + 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82, 1.29 + ]; 1.30 + 1.31 +/** 1.32 + * The timer is needed when a delay is set. We need it to be out of the method 1.33 + * so it is not eaten alive by the GC. 1.34 + */ 1.35 +var timer; 1.36 + 1.37 +function handleRequest(request, response) { 1.38 + var query = {}; 1.39 + request.queryString.split('&').forEach(function (val) { 1.40 + var [name, value] = val.split('='); 1.41 + query[name] = unescape(value); 1.42 + }); 1.43 + 1.44 + response.setStatusLine(request.httpVersion, 200, "OK"); 1.45 + response.setHeader("Content-Type", "image/png", false); 1.46 + 1.47 + function imageWrite() { 1.48 + var stream = new BinaryOutputStream(response.bodyOutputStream); 1.49 + stream.writeByteArray(IMAGE_DATA, IMAGE_DATA.length); 1.50 + } 1.51 + 1.52 + // If there is no delay, we write the image and leave. 1.53 + if (!("delay" in query)) { 1.54 + imageWrite(); 1.55 + return; 1.56 + } 1.57 + 1.58 + // If there is a delay, we create a timer which, when it fires, will write 1.59 + // image and leave. 1.60 + response.processAsync(); 1.61 + const nsITimer = Components.interfaces.nsITimer; 1.62 + 1.63 + timer = Components.classes["@mozilla.org/timer;1"].createInstance(nsITimer); 1.64 + timer.initWithCallback(function() { 1.65 + imageWrite(); 1.66 + response.finish(); 1.67 + }, query["delay"], nsITimer.TYPE_ONE_SHOT); 1.68 +}