Bug 787899 - Tests for ensuring we don't mess up multipart/x-mixed-replace streams when the server lies about a part's MIME type. r=jlebar
authorJoe Drew <joe@drew.ca>
Thu, 06 Sep 2012 18:05:27 -0400
changeset 107884 31f6e5e2ca84739852cc0da6bf8b061231e4db69
parent 107883 dccfebdf756cd85a4ee416e9f2bf569b28afcb82
child 107885 eea69a3e5c1bd5dcec17bec5a45be0534440d414
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjlebar
bugs787899
milestone18.0a1
Bug 787899 - Tests for ensuring we don't mess up multipart/x-mixed-replace streams when the server lies about a part's MIME type. r=jlebar
image/test/mochitest/Makefile.in
image/test/mochitest/bug733553-iframe.html
image/test/mochitest/bug733553.sjs
image/test/mochitest/test_bug733553.html
--- a/image/test/mochitest/Makefile.in
+++ b/image/test/mochitest/Makefile.in
@@ -50,17 +50,16 @@ MOCHITEST_FILES =   imgutils.js \
                 test_bug89419-2.html \
                 test_bug552605-1.html \
                 test_bug552605-2.html \
                 bug552605.sjs \
                 bug671906-iframe.html \
                 bug671906.sjs \
                 test_bug671906.html \
                 test_bug733553.html \
-                bug733553-iframe.html \
                 bug733553.sjs \
                 bug733553-informant.sjs \
                 animated-gif2.gif \
                 test_bug767779.html \
                 bug767779.sjs \
                 animated-gif_trailing-garbage.gif \
 		test_error_events.html \
 		error-early.png \
deleted file mode 100644
--- a/image/test/mochitest/bug733553-iframe.html
+++ /dev/null
@@ -1,7 +0,0 @@
-<html>
-<head>
-<title>Bug 733553 iframe</title>
-<body>
-<img src="bug733553.sjs" id="image1" />
-</body>
-</html>
--- a/image/test/mochitest/bug733553.sjs
+++ b/image/test/mochitest/bug733553.sjs
@@ -1,20 +1,24 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-var bodyPartIndex = 0;
+var bodyPartIndex = -1;
 var bodyParts = [
   ["red.png", "image/png"],
   ["animated-gif2.gif", "image/gif"],
   ["red.png", "image/png"],
   ["lime100x100.svg", "image/svg+xml"],
+  ["lime100x100.svg", "image/svg+xml"],
   ["animated-gif2.gif", "image/gif"],
   ["red.png", "image/png"],
+  ["damon.jpg", "image/jpeg"],
+  ["damon.jpg", "application/octet-stream"],
+  ["damon.jpg", "image/jpeg"],
   ["lime100x100.svg", "image/svg+xml"]
 ];
 var timer = Components.classes["@mozilla.org/timer;1"];
 var partTimer = timer.createInstance(Components.interfaces.nsITimer);
 
 function getFileAsInputStream(aFilename) {
   var file = Components.classes["@mozilla.org/file/directory_service;1"]
              .getService(Components.interfaces.nsIProperties)
@@ -29,36 +33,35 @@ function getFileAsInputStream(aFilename)
   var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
                    .createInstance(Components.interfaces.nsIFileInputStream);
   fileStream.init(file, 1, 0, false);
   return fileStream;
 }
 
 function handleRequest(request, response)
 {
+  setSharedState("next-part", "-1");
   response.setHeader("Content-Type",
                      "multipart/x-mixed-replace;boundary=BOUNDARYOMG", false);
   response.setHeader("Cache-Control", "no-cache", false);
   response.setStatusLine(request.httpVersion, 200, "OK");
   // We're sending parts off in a delayed fashion, to let the tests occur.
   response.processAsync();
   response.write("--BOUNDARYOMG\r\n");
   sendParts(response);
 }
 
 function sendParts(response) {
   let wait = false;
   let nextPart = parseInt(getSharedState("next-part"), 10);
-  if (nextPart) {
-    if (nextPart == bodyPartIndex) {
-      // Haven't been signaled yet, remain in holding pattern
-      wait = true;
-    } else {
-      bodyPartIndex = nextPart;
-    }
+  if (nextPart == bodyPartIndex) {
+    // Haven't been signaled yet, remain in holding pattern
+    wait = true;
+  } else {
+    bodyPartIndex = nextPart;
   }
   if (bodyParts.length > bodyPartIndex) {
     let callback;
     if (!wait) {
       callback = getSendNextPart(response);
     } else {
       callback = function () { sendParts(response); };
     }
--- a/image/test/mochitest/test_bug733553.html
+++ b/image/test/mochitest/test_bug733553.html
@@ -4,67 +4,71 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=733553
 -->
 <head>
   <title>Test for Bug 733553</title>
   <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
-<body>
+<body onload="initializeOnload()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=733553">Mozilla Bug 733553</a>
 <p id="display"></p>
 <pre id="test">
 <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
-var testIndex = 0;
+var testIndex = -1;
 var testParts = [
   [1, "red.png"],
   [40, "animated-gif2.gif"],
   [1, "red.png"],
   [100, "lime100x100.svg"],
+  [100, "lime100x100.svg"],
   [40, "animated-gif2.gif"],
-  [1, "red.png"]
+  [1, "red.png"],
+  [80, "damon.jpg"],
+  [80, "damon.jpg"],
+  [80, "damon.jpg"]
 ];
 
 // We'll append the part number to this, and tell the informant
 const BASE_URL = "bug733553-informant.sjs?";
 
 function initializeOnload() {
-  var iframeelem = document.getElementById('test-iframe');
-  var firstimg = iframeelem.contentDocument.getElementById('image1');
+  var firstimg = document.createElement('img');
   firstimg.addEventListener("load", imageLoad, false);
+  firstimg.addEventListener("error", imageLoad, false);
+  firstimg.src = "bug733553.sjs";
+  document.getElementById('content').appendChild(firstimg);
+
+  // Really ready for first, but who's counting
+  readyForNext();
 }
 
 function readyForNext() {
   var loader = document.getElementById("loader");
-  if (loader) {
-    testIndex++;
-    loader.src = BASE_URL + testIndex;
-  }
+  loader.src = BASE_URL + ++testIndex;
 }
 
 function imageLoad(aEvent) {
   if (testParts.length > testIndex) {
     var [width, fileName] = testParts[testIndex];
-    if (aEvent.target.width == width) {
-      is(aEvent.target.width, width,
-         "Test " + testIndex + " " + fileName + " width correct");
-      readyForNext();
-    }
+    is(aEvent.target.width, width,
+       "Test " + testIndex + " " + fileName + " width correct");
+    readyForNext();
   } else {
     aEvent.target.removeEventListener("load", imageLoad, false);
+    aEvent.target.removeEventListener("error", imageLoad, false);
     var loader = document.getElementById("loader");
     readyForNext();
     SimpleTest.finish();
   }
 }
 
 </script>
 </pre>
 <div id="content"> <!-- style="display: none" -->
-<iframe id="test-iframe" src="http://mochi.test:8888/tests/image/test/mochitest/bug733553-iframe.html" onload="initializeOnload()"></iframe>
 <iframe id="loader"></iframe>
 </div>
 </body>
 </html>