layout/generic/test/file_IconTestServer.sjs

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/test/file_IconTestServer.sjs	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +const Cc = Components.classes;
     1.5 +const Ci = Components.interfaces;
     1.6 +const TIMEOUT_INTERVAL_MS = 100;
     1.7 +
     1.8 +function handleRequest(request, response) {
     1.9 +
    1.10 +  // Allow us to asynchronously construct the response with timeouts
    1.11 +  // rather than forcing us to make the whole thing in one call. See
    1.12 +  // bug 396226.
    1.13 +  response.processAsync();
    1.14 +
    1.15 +  // Figure out whether the client wants to load the image, or just
    1.16 +  // to tell us to finish the previous load
    1.17 +  var query = {};
    1.18 +  request.queryString.split('&').forEach(function (val) {
    1.19 +    var [name, value] = val.split('=');
    1.20 +    query[name] = unescape(value);
    1.21 +  });
    1.22 +  if (query["continue"] == "true") {
    1.23 +
    1.24 +    // Debugging information so we can figure out the hang
    1.25 +    dump("file_IconTestServer.js DEBUG - Got continue command\n");
    1.26 +
    1.27 +    // Get the context structure and finish the old request
    1.28 +    getObjectState("context", function(obj) {
    1.29 +
    1.30 +      // magic or goop, depending on how you look at it
    1.31 +      savedCtx = obj.wrappedJSObject;
    1.32 +
    1.33 +      // Write the rest of the data
    1.34 +      savedCtx.ostream.writeFrom(savedCtx.istream, savedCtx.istream.available());
    1.35 +
    1.36 +      // Close the streams
    1.37 +      savedCtx.ostream.close();
    1.38 +      savedCtx.istream.close();
    1.39 +
    1.40 +      // Finish off 'the old response'
    1.41 +      savedCtx.response.finish();
    1.42 +    });
    1.43 +
    1.44 +    // Finish off 'the current response'
    1.45 +    response.finish();
    1.46 +    return;
    1.47 +  }
    1.48 +
    1.49 +  // Debugging information so we can figure out the hang
    1.50 +  dump("file_IconTestServer.js DEBUG - Got initial request\n");
    1.51 +
    1.52 +  // Context structure - we need to set this up properly to pass to setObjectState
    1.53 +  var ctx = {
    1.54 +    QueryInterface: function(iid) {
    1.55 +      if (iid.equals(Components.interfaces.nsISupports))
    1.56 +        return this;
    1.57 +      throw Components.results.NS_ERROR_NO_INTERFACE;
    1.58 +    }
    1.59 +  };
    1.60 +  ctx.wrappedJSObject = ctx;
    1.61 +
    1.62 +  // Save the response
    1.63 +  ctx.response = response;
    1.64 +
    1.65 +  // We're serving up a png
    1.66 +  response.setHeader("Content-Type", "image/png", false);
    1.67 +
    1.68 +  // Get the output stream
    1.69 +  ctx.ostream = response.bodyOutputStream;
    1.70 +
    1.71 +  // Ugly hack, but effective - copied from content/media/test/contentDuration1.sjs
    1.72 +  var pngFile = Components.classes["@mozilla.org/file/directory_service;1"].
    1.73 +                           getService(Components.interfaces.nsIProperties).
    1.74 +                           get("CurWorkD", Components.interfaces.nsILocalFile);
    1.75 +  var paths = "tests/layout/generic/test/file_Dolske.png";
    1.76 +  var split = paths.split("/");
    1.77 +  for(var i = 0; i < split.length; ++i) {
    1.78 +    pngFile.append(split[i]);
    1.79 +  }
    1.80 +
    1.81 +  // Get an input stream for the png data
    1.82 +  ctx.istream = Cc["@mozilla.org/network/file-input-stream;1"].
    1.83 +                      createInstance(Components.interfaces.nsIFileInputStream);
    1.84 +  ctx.istream.init(pngFile, -1, 0, 0);
    1.85 +
    1.86 +  // Write the first 10 bytes, which is just boilerplate/magic bytes
    1.87 +  ctx.ostream.writeFrom(ctx.istream, 10);
    1.88 +
    1.89 +  // Save the context structure for retrieval when we get pinged
    1.90 +  setObjectState("context", ctx);
    1.91 +
    1.92 +  // Now we play the waiting game...
    1.93 +
    1.94 +  // Debugging information so we can figure out the hang
    1.95 +  dump("file_IconTestServer.js DEBUG - Playing the waiting game\n");
    1.96 +}
    1.97 +

mercurial