delayedframe.sjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function getFileStream(filename)
  2. {
  3. // Get the location of this sjs file, and then use that to figure out where
  4. // to find where our other files are.
  5. var self = Components.classes["@mozilla.org/file/local;1"]
  6. .createInstance(Components.interfaces.nsILocalFile);
  7. self.initWithPath(getState("__LOCATION__"));
  8. var file = self.parent;
  9. file.append(filename);
  10. dump(file.path + "\n");
  11. var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
  12. .createInstance(Components.interfaces.nsIFileInputStream);
  13. fileStream.init(file, 1, 0, false);
  14. return fileStream;
  15. }
  16. var gTimer;
  17. function handleRequest(request, response)
  18. {
  19. response.processAsync();
  20. response.setStatusLine(request.httpVersion, 200, "OK");
  21. response.setHeader("Content-Type", "image/gif", false);
  22. var firststream = getFileStream("threeframes-start.gif");
  23. response.bodyOutputStream.writeFrom(firststream, firststream.available())
  24. firststream.close();
  25. gTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  26. gTimer.initWithCallback(function()
  27. {
  28. var secondstream = getFileStream("threeframes-end.gif");
  29. response.bodyOutputStream.writeFrom(secondstream, secondstream.available())
  30. secondstream.close();
  31. response.finish();
  32. // This time needs to be longer than the animation timer in
  33. // threeframes-start.gif. That's specified as 100ms; just use 5 seconds as
  34. // a reasonable upper bound. Since this is just a crashtest, timeouts
  35. // aren't a big deal.
  36. }, 5 * 1000 /* milliseconds */, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  37. }