Bug 490949 - Test to ensure that we reload images when they have Cache-Control: no-cache specified.
authorJoe Drew <joe@drew.ca>
Mon, 11 May 2009 15:15:42 -0400
changeset 28209 bd22fde8a8a48ac1cfe21f332ab485f987e6da87
parent 28208 b6a74601ee1dc1844dfcb882aebf0db9c48238f3
child 28210 d5cc0631c2bda4d7b9ece7b638dc2a0af91cc3a9
push id6943
push userjdrew@mozilla.com
push dateMon, 11 May 2009 19:17:19 +0000
treeherdermozilla-central@bd22fde8a8a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs490949
milestone1.9.2a1pre
Bug 490949 - Test to ensure that we reload images when they have Cache-Control: no-cache specified.
modules/libpr0n/test/mochitest/Makefile.in
modules/libpr0n/test/mochitest/blue.png
modules/libpr0n/test/mochitest/bug490949.sjs
modules/libpr0n/test/mochitest/test_bug490949.html
--- a/modules/libpr0n/test/mochitest/Makefile.in
+++ b/modules/libpr0n/test/mochitest/Makefile.in
@@ -46,12 +46,16 @@ include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = 	test_bug399925.html \
 		bug399925.gif \
                 bug468160.sjs \
                 test_bug468160.html \
                 red.png \
                 test_bug466586.html \
                 big.png \
+                blue.png \
+                test_bug490949.html \
+                bug490949-iframe.html \
+                bug490949.sjs \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8df58f3a5fc71ed2fc8d76cbe4e2629527b8292f
GIT binary patch
literal 2745
zc$@*b3P$ybP)<h;3K|Lk000e1NJLTq00031000390ssI2kattw00004XF*Lt006O%
z3;baP000U@X+uL$Nkc;*P;zf(X>4Tx02tGqk9Sy8X%@!6dvAK7B}6)xUPF}-K%|5!
zAVs<;#3Vo{A%p}JyCN#6C@RtvK}H1}aC9g#Rz$HdAU5m+G6<;S;3%S^vO)J*eRk*B
zot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a3_u~bR?+@{Yp8cBj>xbdIC)6h;Bf2AXqjsYw$9%@F
zJze;8_?h_G)bsq`lz*#yVfy07-`#)j9*-U$ekpl5{l}J9>aPyHp8dLGB4pyxoAftR
zlLc?p-yVL)e%JLr>ix)6&IkO5(vM~z+dl<-dN7?nJ^c>@nDhMTEkxM>000SaNLh0L
z01FcU01FcV0GgZ_0000CNkl<Z2-jm^koXS(0W$#@5yrGX00000NkvXXu0mjf#vwI2
new file mode 100644
--- /dev/null
+++ b/modules/libpr0n/test/mochitest/bug490949.sjs
@@ -0,0 +1,34 @@
+function handleRequest(request, response)
+{
+  var file = Components.classes["@mozilla.org/file/directory_service;1"]
+             .getService(Components.interfaces.nsIProperties)
+             .get("CurWorkD", Components.interfaces.nsIFile);
+
+  file.append("tests");
+  file.append("modules");
+  file.append("libpr0n");
+  file.append("test");
+  file.append("mochitest");
+
+  var redirectstate = "/modules/libpr0n/test/mochitest/bug490949.sjs";
+  if (getState(redirectstate) == "") {
+    file.append('blue.png');
+    setState(redirectstate, "red");
+  } else {
+    file.append('red.png');
+    setState(redirectstate, "");
+  }
+  response.setHeader("Cache-Control", "no-cache", false);
+
+  var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
+                   .createInstance(Components.interfaces.nsIFileInputStream);
+  fileStream.init(file, 1, 0, false);
+  var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1']
+                     .createInstance(Components.interfaces.nsIBinaryInputStream);
+  binaryStream.setInputStream(fileStream);
+
+  response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available());
+
+  binaryStream.close();
+  fileStream.close();
+}
new file mode 100644
--- /dev/null
+++ b/modules/libpr0n/test/mochitest/test_bug490949.html
@@ -0,0 +1,114 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=490949
+-->
+<head>
+  <title>Test for Bug 490949</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 onload="checkFirst()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=490949">Mozilla Bug 490949</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+<canvas id="canvas" width="100" height="100"> </canvas>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+var canvas = document.getElementById('canvas');
+var first, second, third;
+
+RemoteCanvas = function() {
+    this.url = "bug490949-iframe.html";
+};
+
+RemoteCanvas.CANVAS_WIDTH = 100;
+RemoteCanvas.CANVAS_HEIGHT = 100;
+
+RemoteCanvas.prototype.load = function(cb) {
+    this.cb = cb;
+
+    var windowWidth = window.innerWidth - 25;
+    var iframe;
+    iframe = document.createElement("iframe");
+    iframe.id = "test-iframe";
+    iframe.height = "10px";
+    iframe.width = windowWidth + "px";
+    iframe.style.visibility = "hidden";
+    iframe.src = this.url;
+    // Here is where the magic happens... add a listener to the
+    // frame's onload event - it will call handleEvent
+    iframe.addEventListener("load", this, true);
+    //append to the end of the page
+    window.document.body.appendChild(iframe);
+};
+
+RemoteCanvas.prototype.reload = function(cb, force) {
+    this.cb = cb;
+    window.frames[0].location.reload(force);
+}
+
+RemoteCanvas.prototype.handleEvent = function() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
+
+    // Look back up the iframe by id
+    var ldrFrame = document.getElementById("test-iframe");
+    // Get a reference to the window object you need for the canvas
+    // drawWindow method
+    var remoteWindow = ldrFrame.contentWindow;
+
+    //Draw canvas
+    canvas.style.width = RemoteCanvas.CANVAS_WIDTH + "px";
+    canvas.style.height = RemoteCanvas.CANVAS_HEIGHT + "px";
+    canvas.width = RemoteCanvas.CANVAS_WIDTH;
+    canvas.height = RemoteCanvas.CANVAS_HEIGHT;
+    var windowWidth = window.innerWidth - 25;
+    var windowHeight = window.innerHeight;
+
+    var ctx = canvas.getContext("2d");
+    ctx.clearRect(0, 0,
+                  RemoteCanvas.CANVAS_WIDTH,
+                  RemoteCanvas.CANVAS_HEIGHT);
+    ctx.save();
+    ctx.scale(RemoteCanvas.CANVAS_WIDTH / windowWidth,
+              RemoteCanvas.CANVAS_HEIGHT / windowHeight);
+    ctx.drawWindow(remoteWindow,
+                   0, 0,
+                   windowWidth, windowHeight,
+                   "rgb(0,0,0)");
+    ctx.restore();
+    this.cb();
+};
+
+function checkFirst()
+{
+  first = canvas.toDataURL();
+  remoteCanvas.reload(checkForceReload, true);
+}
+
+function checkForceReload()
+{
+  second = canvas.toDataURL();
+  ok(first != second, "We got the wrong image.");
+  remoteCanvas.reload(checkLazyReload, false);
+}
+
+function checkLazyReload()
+{
+  third = canvas.toDataURL();
+  ok(second != third, "We got the wrong image.");
+  SimpleTest.finish();
+}
+
+var remoteCanvas = new RemoteCanvas();
+remoteCanvas.load(checkFirst);
+
+</script>
+</pre>
+</body>
+</html>