Bug 875986, part 2 - additional test that no cookies are stored by pages captured in the background. r=adw
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 09 Sep 2013 10:25:13 +1000
changeset 146132 6bee20c2e0c6e2f7ddcdd9bebc0c9b6d7a3d0895
parent 146131 b152bdd937ebdcd13b77bd4308e14ebf86093c05
child 146134 968d0083e7d7488d1bde70b9a6fcfbe0cc37970a
push id25242
push useremorley@mozilla.com
push dateMon, 09 Sep 2013 12:13:52 +0000
treeherdermozilla-central@218d4334d29e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs875986
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 875986, part 2 - additional test that no cookies are stored by pages captured in the background. r=adw
toolkit/components/thumbnails/test/browser_thumbnails_background.js
toolkit/components/thumbnails/test/thumbnails_background.sjs
--- a/toolkit/components/thumbnails/test/browser_thumbnails_background.js
+++ b/toolkit/components/thumbnails/test/browser_thumbnails_background.js
@@ -200,17 +200,17 @@ let tests = [
     openPrivateWindow().then(function (win) {
       win.close();
       maybeFinish();
     });
 
     yield deferred.promise;
   },
 
-  function noCookies() {
+  function noCookiesSent() {
     // Visit the test page in the browser and tell it to set a cookie.
     let url = testPageURL({ setGreenCookie: true });
     let tab = gBrowser.loadOneTab(url, { inBackground: false });
     let browser = tab.linkedBrowser;
     yield onPageLoad(browser);
 
     // The root element of the page shouldn't be green yet.
     let greenStr = "rgb(0, 255, 0)";
@@ -238,16 +238,37 @@ let tests = [
             "The captured page should not be green.");
       gBrowser.removeTab(tab);
       file.remove(false);
       deferred.resolve();
     });
     yield deferred.promise;
   },
 
+  // check that if a page captured in the background attempts to set a cookie,
+  // that cookie is not saved for subsequent requests.
+  function noCookiesStored() {
+    let url = testPageURL({ setRedCookie: true });
+    yield capture(url);
+    let file = fileForURL(url);
+    ok(file.exists(), "Thumbnail file should exist after capture.");
+    // now load it up in a browser - it should *not* be red, otherwise the
+    // cookie above was saved.
+    let tab = gBrowser.loadOneTab(url, { inBackground: false });
+    let browser = tab.linkedBrowser;
+    yield onPageLoad(browser);
+
+    // The root element of the page shouldn't be red.
+    let redStr = "rgb(255, 0, 0)";
+    isnot(browser.contentDocument.documentElement.style.backgroundColor,
+          redStr,
+          "The page shouldn't be red.");
+    gBrowser.removeTab(tab);
+  },
+
   // the following tests attempt to display modal dialogs.  The test just
   // relies on the fact that if the dialog was displayed the test will hang
   // and timeout.  IOW - the tests would pass if the dialogs appear and are
   // manually closed by the user - so don't do that :)  (obviously there is
   // noone available to do that when run via tbpl etc, so this should be safe,
   // and it's tricky to use the window-watcher to check a window *does not*
   // appear - how long should the watcher be active before assuming it's not
   // going to appear?)
--- a/toolkit/components/thumbnails/test/thumbnails_background.sjs
+++ b/toolkit/components/thumbnails/test/thumbnails_background.sjs
@@ -12,20 +12,30 @@ function handleRequest(req, resp) {
   resp.setHeader("Content-Type", "text/html;charset=utf-8", false);
 
   let opts = {};
   try {
     opts = JSON.parse(decodeURIComponent(req.queryString));
   }
   catch (err) {}
 
+  if (opts.setRedCookie)
+    resp.setHeader("Set-Cookie", "red", false);
+
   if (opts.setGreenCookie)
     resp.setHeader("Set-Cookie", "green", false);
 
   if (req.hasHeader("Cookie") &&
+      req.getHeader("Cookie").split(";").indexOf("red") >= 0) {
+    resp.write('<html style="background: #f00;"></html>');
+    resp.finish();
+    return;
+  }
+
+  if (req.hasHeader("Cookie") &&
       req.getHeader("Cookie").split(";").indexOf("green") >= 0) {
     resp.write('<html style="background: #0f0;"></html>');
     resp.finish();
     return;
   }
 
   if (opts.redirect) {
     resp.setHeader("Location", opts.redirect);