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 97025a1f2d
commit 6eb034cf51
4 changed files with 30 additions and 31 deletions

View File

@ -55,7 +55,6 @@ MOCHITEST_FILES = imgutils.js \
bug671906.sjs \
test_bug671906.html \
test_bug733553.html \
bug733553-iframe.html \
bug733553.sjs \
bug733553-informant.sjs \
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/
*/
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"];
@ -34,6 +38,7 @@ function getFileAsInputStream(aFilename) {
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);
@ -47,13 +52,11 @@ function handleRequest(request, 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;

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>
<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">
@ -17,43 +17,48 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=733553
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();
@ -63,7 +68,6 @@ function imageLoad(aEvent) {
</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>