Bug 870114 - Write a test that verifies that BackgroundPageThumbs uses private browsing. r=markh
authorDrew Willcoxon <adw@mozilla.com>
Fri, 31 May 2013 22:52:51 -0700
changeset 140813 cd7ca5763eac533de86f4edd8b8f861ae237fb74
parent 140812 ac0e60ed486380e9818693739d18dbcf2a86de63
child 140814 ec45e0246b831ea03cc5ba1ab2ddd5bbe6880a0b
push id3911
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 20:17:26 +0000
treeherdermozilla-aurora@7e26ca8db92b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs870114
milestone24.0a1
Bug 870114 - Write a test that verifies that BackgroundPageThumbs uses private browsing. r=markh
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
@@ -189,16 +189,53 @@ let tests = [
     let win = yield openPrivateWindow();
     let capturedURL = yield capture(url);
     is(capturedURL, url, "Captured URL should be URL passed to capture.");
     ok(!file.exists(),
        "Thumbnail file should not exist because a private window is open.");
 
     win.close();
   },
+
+  function noCookies() {
+    // 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)";
+    isnot(browser.contentDocument.documentElement.style.backgroundColor,
+          greenStr,
+          "The page shouldn't be green yet.");
+
+    // Cookie should be set now.  Reload the page to verify.  Its root element
+    // will be green if the cookie's set.
+    browser.reload();
+    yield onPageLoad(browser);
+    is(browser.contentDocument.documentElement.style.backgroundColor,
+       greenStr,
+       "The page should be green now.");
+
+    // Capture the page.  Get the image data of the capture and verify it's not
+    // green.  (Checking only the first pixel suffices.)
+    yield capture(url);
+    let file = fileForURL(url);
+    ok(file.exists(), "Thumbnail file should exist after capture.");
+
+    let deferred = imports.Promise.defer();
+    retrieveImageDataForURL(url, function ([r, g, b]) {
+      isnot([r, g, b].toString(), [0, 255, 0].toString(),
+            "The captured page should not be green.");
+      gBrowser.removeTab(tab);
+      deferred.resolve();
+    });
+    yield deferred.promise;
+  },
 ];
 
 function capture(url, options) {
   let deferred = imports.Promise.defer();
   options = options || {};
   options.onDone = function onDone(capturedURL) {
     deferred.resolve(capturedURL);
   };
@@ -234,8 +271,19 @@ function openPrivateWindow() {
   win.addEventListener("load", function load(event) {
     if (event.target == win.document) {
       win.removeEventListener("load", load);
       deferred.resolve(win);
     }
   });
   return deferred.promise;
 }
+
+function onPageLoad(browser) {
+  let deferred = imports.Promise.defer();
+  browser.addEventListener("load", function load(event) {
+    if (event.target == browser.contentWindow.document) {
+      browser.removeEventListener("load", load, true);
+      deferred.resolve();
+    }
+  }, true);
+  return deferred.promise;
+}
--- a/toolkit/components/thumbnails/test/thumbnails_background.sjs
+++ b/toolkit/components/thumbnails/test/thumbnails_background.sjs
@@ -12,16 +12,26 @@ 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.setGreenCookie)
+    resp.setHeader("Set-Cookie", "green", false);
+
+  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);
     resp.setStatusLine(null, 303, null);
     resp.finish();
     return;
   }
 
   if (opts.wait) {