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

This commit is contained in:
Joe Drew 2012-09-06 18:05:27 -04:00
parent b4164cc128
commit acf54d18ef
4 changed files with 30 additions and 31 deletions

View File

@ -55,7 +55,6 @@ MOCHITEST_FILES = imgutils.js \
bug671906.sjs \ bug671906.sjs \
test_bug671906.html \ test_bug671906.html \
test_bug733553.html \ test_bug733553.html \
bug733553-iframe.html \
bug733553.sjs \ bug733553.sjs \
bug733553-informant.sjs \ bug733553-informant.sjs \
animated-gif2.gif \ animated-gif2.gif \

View File

@ -1,7 +0,0 @@
<html>
<head>
<title>Bug 733553 iframe</title>
<body>
<img src="bug733553.sjs" id="image1" />
</body>
</html>

View File

@ -2,14 +2,18 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
var bodyPartIndex = 0; var bodyPartIndex = -1;
var bodyParts = [ var bodyParts = [
["red.png", "image/png"], ["red.png", "image/png"],
["animated-gif2.gif", "image/gif"], ["animated-gif2.gif", "image/gif"],
["red.png", "image/png"], ["red.png", "image/png"],
["lime100x100.svg", "image/svg+xml"], ["lime100x100.svg", "image/svg+xml"],
["lime100x100.svg", "image/svg+xml"],
["animated-gif2.gif", "image/gif"], ["animated-gif2.gif", "image/gif"],
["red.png", "image/png"], ["red.png", "image/png"],
["damon.jpg", "image/jpeg"],
["damon.jpg", "application/octet-stream"],
["damon.jpg", "image/jpeg"],
["lime100x100.svg", "image/svg+xml"] ["lime100x100.svg", "image/svg+xml"]
]; ];
var timer = Components.classes["@mozilla.org/timer;1"]; var timer = Components.classes["@mozilla.org/timer;1"];
@ -34,6 +38,7 @@ function getFileAsInputStream(aFilename) {
function handleRequest(request, response) function handleRequest(request, response)
{ {
setSharedState("next-part", "-1");
response.setHeader("Content-Type", response.setHeader("Content-Type",
"multipart/x-mixed-replace;boundary=BOUNDARYOMG", false); "multipart/x-mixed-replace;boundary=BOUNDARYOMG", false);
response.setHeader("Cache-Control", "no-cache", false); response.setHeader("Cache-Control", "no-cache", false);
@ -47,13 +52,11 @@ function handleRequest(request, response)
function sendParts(response) { function sendParts(response) {
let wait = false; let wait = false;
let nextPart = parseInt(getSharedState("next-part"), 10); let nextPart = parseInt(getSharedState("next-part"), 10);
if (nextPart) { if (nextPart == bodyPartIndex) {
if (nextPart == bodyPartIndex) { // Haven't been signaled yet, remain in holding pattern
// Haven't been signaled yet, remain in holding pattern wait = true;
wait = true; } else {
} else { bodyPartIndex = nextPart;
bodyPartIndex = nextPart;
}
} }
if (bodyParts.length > bodyPartIndex) { if (bodyParts.length > bodyPartIndex) {
let callback; let callback;

View File

@ -9,7 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=733553
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head> </head>
<body> <body onload="initializeOnload()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=733553">Mozilla Bug 733553</a> <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=733553">Mozilla Bug 733553</a>
<p id="display"></p> <p id="display"></p>
<pre id="test"> <pre id="test">
@ -17,43 +17,48 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=733553
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var testIndex = 0; var testIndex = -1;
var testParts = [ var testParts = [
[1, "red.png"], [1, "red.png"],
[40, "animated-gif2.gif"], [40, "animated-gif2.gif"],
[1, "red.png"], [1, "red.png"],
[100, "lime100x100.svg"], [100, "lime100x100.svg"],
[100, "lime100x100.svg"],
[40, "animated-gif2.gif"], [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 // We'll append the part number to this, and tell the informant
const BASE_URL = "bug733553-informant.sjs?"; const BASE_URL = "bug733553-informant.sjs?";
function initializeOnload() { function initializeOnload() {
var iframeelem = document.getElementById('test-iframe'); var firstimg = document.createElement('img');
var firstimg = iframeelem.contentDocument.getElementById('image1');
firstimg.addEventListener("load", imageLoad, false); 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() { function readyForNext() {
var loader = document.getElementById("loader"); var loader = document.getElementById("loader");
if (loader) { loader.src = BASE_URL + ++testIndex;
testIndex++;
loader.src = BASE_URL + testIndex;
}
} }
function imageLoad(aEvent) { function imageLoad(aEvent) {
if (testParts.length > testIndex) { if (testParts.length > testIndex) {
var [width, fileName] = testParts[testIndex]; var [width, fileName] = testParts[testIndex];
if (aEvent.target.width == width) { is(aEvent.target.width, width,
is(aEvent.target.width, width, "Test " + testIndex + " " + fileName + " width correct");
"Test " + testIndex + " " + fileName + " width correct"); readyForNext();
readyForNext();
}
} else { } else {
aEvent.target.removeEventListener("load", imageLoad, false); aEvent.target.removeEventListener("load", imageLoad, false);
aEvent.target.removeEventListener("error", imageLoad, false);
var loader = document.getElementById("loader"); var loader = document.getElementById("loader");
readyForNext(); readyForNext();
SimpleTest.finish(); SimpleTest.finish();
@ -63,7 +68,6 @@ function imageLoad(aEvent) {
</script> </script>
</pre> </pre>
<div id="content"> <!-- style="display: none" --> <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> <iframe id="loader"></iframe>
</div> </div>
</body> </body>