image/test/mochitest/bug767779.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 var timer = Components.classes["@mozilla.org/timer;1"];
michael@0 6 var partTimer = timer.createInstance(Components.interfaces.nsITimer);
michael@0 7
michael@0 8 function getFileAsInputStream(aFilename) {
michael@0 9 var file = Components.classes["@mozilla.org/file/directory_service;1"]
michael@0 10 .getService(Components.interfaces.nsIProperties)
michael@0 11 .get("CurWorkD", Components.interfaces.nsIFile);
michael@0 12
michael@0 13 file.append("tests");
michael@0 14 file.append("image");
michael@0 15 file.append("test");
michael@0 16 file.append("mochitest");
michael@0 17 file.append(aFilename);
michael@0 18
michael@0 19 var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
michael@0 20 .createInstance(Components.interfaces.nsIFileInputStream);
michael@0 21 fileStream.init(file, 1, 0, false);
michael@0 22 return fileStream;
michael@0 23 }
michael@0 24
michael@0 25 function handleRequest(request, response)
michael@0 26 {
michael@0 27 response.setHeader("Content-Type", "image/gif", false);
michael@0 28 response.setHeader("Cache-Control", "no-cache", false);
michael@0 29 response.setStatusLine(request.httpVersion, 200, "OK");
michael@0 30 // We're sending data off in a delayed fashion
michael@0 31 response.processAsync();
michael@0 32 var inputStream = getFileAsInputStream("animated-gif_trailing-garbage.gif");
michael@0 33 var available = inputStream.available(); // = 4029 bytes
michael@0 34 // Send the good data at once
michael@0 35 response.bodyOutputStream.writeFrom(inputStream, 285);
michael@0 36 sendParts(inputStream, response);
michael@0 37 }
michael@0 38
michael@0 39 function sendParts(inputStream, response) {
michael@0 40 // 3744 left, send in 8 chunks of 468 each
michael@0 41 partTimer.initWithCallback(getSendNextPart(inputStream, response), 500,
michael@0 42 Components.interfaces.nsITimer.TYPE_ONE_SHOT);
michael@0 43 }
michael@0 44
michael@0 45 function getSendNextPart(inputStream, response) {
michael@0 46 return function () {
michael@0 47 response.bodyOutputStream.writeFrom(inputStream, 468);
michael@0 48 if (!inputStream.available()) {
michael@0 49 inputStream.close();
michael@0 50 response.finish();
michael@0 51 } else {
michael@0 52 sendParts(inputStream, response);
michael@0 53 }
michael@0 54 };
michael@0 55 }
michael@0 56

mercurial