Bug 898743 - Ensure Cache-Control: no-store for all thumbnail_update tests. r=adw, a=test-only
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 27 Aug 2013 12:58:41 +1000
changeset 153919 0d081e6fa4560717502d1e8b3eeb8f43b84b4135
parent 153918 5ee1d298bc2d71701479f30ff4b79db53bdb003d
child 153920 42d7eed1d9bc397e8342c5952c395ba28c4a3fef
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, test-only
bugs898743
milestone25.0a2
Bug 898743 - Ensure Cache-Control: no-store for all thumbnail_update tests. r=adw, a=test-only
toolkit/components/thumbnails/test/Makefile.in
toolkit/components/thumbnails/test/browser_thumbnails_update.js
toolkit/components/thumbnails/test/thumbnails_update.sjs
--- a/toolkit/components/thumbnails/test/Makefile.in
+++ b/toolkit/components/thumbnails/test/Makefile.in
@@ -22,11 +22,12 @@ MOCHITEST_BROWSER_FILES := \
 	browser_thumbnails_bug727765.js \
 	browser_thumbnails_update.js \
 	head.js \
 	background_red.html \
 	background_red_scroll.html \
 	background_red_redirect.sjs \
 	privacy_cache_control.sjs \
 	thumbnails_background.sjs \
+	thumbnails_update.sjs \
 	$(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/components/thumbnails/test/browser_thumbnails_update.js
+++ b/toolkit/components/thumbnails/test/browser_thumbnails_update.js
@@ -1,31 +1,31 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * These tests check the auto-update facility of the thumbnail service.
  */
 
-let numNotifications = 0;
-const URL = "data:text/html;charset=utf-8,<body%20bgcolor=ff0000></body>";
+function runTests() {
+  let numNotifications = 0;
+  const URL = "http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?simple";
 
-function observe(subject, topic, data) {
-  is(topic, "page-thumbnail:create", "got expected topic");
-  is(data, URL, "data is our test URL");
-  if (++numNotifications == 2) {
-    // This is the final notification and signals test success...
-    Services.obs.removeObserver(observe, "page-thumbnail:create");
-    next();
+  function observe(subject, topic, data) {
+    is(topic, "page-thumbnail:create", "got expected topic");
+    is(data, URL, "data is our test URL");
+    if (++numNotifications == 2) {
+      // This is the final notification and signals test success...
+      Services.obs.removeObserver(observe, "page-thumbnail:create");
+      next();
+    }
   }
-}
 
-function runTests() {
   Services.obs.addObserver(observe, "page-thumbnail:create", false);
-  // Create a tab with a red background.
+  // Create a tab - we don't care what the content is.
   yield addTab(URL);
   let browser = gBrowser.selectedBrowser;
 
   // Capture the screenshot.
   PageThumbs.captureAndStore(browser, function () {
     // We've got a capture so should have seen the observer.
     is(numNotifications, 1, "got notification of item being created.");
     // The capture is now "fresh" - so requesting the URL should not cause
new file mode 100644
--- /dev/null
+++ b/toolkit/components/thumbnails/test/thumbnails_update.sjs
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// This server-side script is used for browser_thumbnails_update.  One of the
+// main things it must do in all cases is ensure a Cache-Control: no-store
+// header, so the foreground capture doesn't interfere with the testing.
+
+// If the querystring is "simple", then all it does it return some content -
+// it doesn't really matter what that content is.
+
+// Otherwise, its main role is that it must return different *content* for the
+// second request than it did for the first.
+// Also, it should be able to return an error response when requested for the
+// second response.
+// So the basic tests will be to grab the thumbnail, then request it to be
+// grabbed again:
+// * If the second request succeeded, the new thumbnail should exist.
+// * If the second request is an error, the new thumbnail should be ignored.
+
+function handleRequest(aRequest, aResponse) {
+  aResponse.setHeader("Content-Type", "text/html;charset=utf-8", false);
+  // we want to disable gBrowserThumbnails on-load capture for these responses,
+  // so set as a "no-store" response.
+  aResponse.setHeader("Cache-Control", "no-store");
+
+  // for the simple test - just return some content.
+  if (aRequest.queryString == "simple") {
+    aResponse.write("<html><body></body></html>");
+    aResponse.setStatusLine(aRequest.httpVersion, 200, "Its simply OK");
+    return;
+  }
+
+  // it's one of the more complex tests where the first request for the given
+  // URL must return different content than the second, and possibly an error
+  // response for the second
+  let doneError = getState(aRequest.queryString);
+  if (!doneError) {
+    // first request - return a response with a green body and 200 response.
+    aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's green");
+    aResponse.write("<html><body bgcolor=00ff00></body></html>");
+    // set the  state so the next request does the "second request" thing below.
+    setState(aRequest.queryString, "yep");
+  } else {
+    // second request - this will be done by the b/g service.
+    // We always return a red background, but depending on the query string we
+    // return either a 200 or 401 response.
+    if (aRequest.queryString == "fail")
+      aResponse.setStatusLine(aRequest.httpVersion, 401, "Oh no you don't");
+    else
+      aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's red");
+    aResponse.write("<html><body bgcolor=ff0000></body></html>");
+    // reset the error state incase this ends up being reused for the
+    // same url and querystring.
+    setState(aRequest.queryString, "");
+  }
+}