Back out changeset 105e0e4b9d80 (bug 1263031) for Windows failures in browser_save_private_link_perwindowpb.js
authorPhil Ringnalda <philringnalda@gmail.com>
Mon, 11 Apr 2016 21:43:17 -0700
changeset 292805 7116915548728dd89dd80455daee47f1adff2e0c
parent 292804 272ee64663d27060d414e2ce825d5c458e6fb039
child 292806 49d7fb650c9dde7cf6e4b2c7aa578a4a11e83f83
child 292895 adbe62e4a9748eb9570e9bf72eaf7bd19af4da2b
push id74979
push usercbook@mozilla.com
push dateTue, 12 Apr 2016 11:53:25 +0000
treeherdermozilla-inbound@cb2b8b7bc47f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1263031
milestone48.0a1
backs out105e0e4b9d800048ff535543b0c5f01919612a3c
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
Back out changeset 105e0e4b9d80 (bug 1263031) for Windows failures in browser_save_private_link_perwindowpb.js
browser/base/content/test/general/browser_save_private_link_perwindowpb.js
--- a/browser/base/content/test/general/browser_save_private_link_perwindowpb.js
+++ b/browser/base/content/test/general/browser_save_private_link_perwindowpb.js
@@ -1,114 +1,140 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-function createTemporarySaveDirectory() {
-  var saveDir = Cc["@mozilla.org/file/directory_service;1"]
-                  .getService(Ci.nsIProperties)
-                  .get("TmpD", Ci.nsIFile);
-  saveDir.append("testsavedir");
-  if (!saveDir.exists())
-    saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
-  return saveDir;
-}
+var {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", null);
 
-function promiseNoCacheEntry() {
+function test() {
+  // initialization
+  waitForExplicitFinish();
+  let windowsToClose = [];
+  let testURI = "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.html";
+  let fileName;
+  let MockFilePicker = SpecialPowers.MockFilePicker;
   let cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
               .getService(Ci.nsICacheStorageService);
-  cache.clear();
-  return new Promise((resolve, reject) => {
-    let entries = 0;
+
+  function checkDiskCacheFor(filename, goon) {
     Visitor.prototype = {
       onCacheStorageInfo: function(num, consumption)
       {
         info("disk storage contains " + num + " entries");
-        entries += num;
       },
       onCacheEntryInfo: function(uri)
       {
-        let urispec = uri.asciiSpec;
-        ok(false, "web content present in disk cache " + urispec);
+        var urispec = uri.asciiSpec;
+        info(urispec);
+        is(urispec.includes(filename), false, "web content present in disk cache");
       },
-      onCacheEntryVisitCompleted: function() {
-        is(entries, 0, "no content cached");
-        resolve();
+      onCacheEntryVisitCompleted: function()
+      {
+        goon();
       }
     };
     function Visitor() {}
 
-    let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", null);
-    let storage = cache.diskCacheStorage(LoadContextInfo.default, false);
+    var storage = cache.diskCacheStorage(LoadContextInfo.default, false);
     storage.asyncVisitStorage(new Visitor(), true /* Do walk entries */);
-  });
-}
+  }
+
+  function onTransferComplete(downloadSuccess) {
+    ok(downloadSuccess, "Image file should have been downloaded successfully");
+
+    // Give the request a chance to finish and create a cache entry
+    executeSoon(function() {
+      checkDiskCacheFor(fileName, finish);
+      mockTransferCallback = null;
+    });
+  }
+
+  function createTemporarySaveDirectory() {
+    var saveDir = Cc["@mozilla.org/file/directory_service;1"]
+                    .getService(Ci.nsIProperties)
+                    .get("TmpD", Ci.nsIFile);
+    saveDir.append("testsavedir");
+    if (!saveDir.exists())
+      saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+    return saveDir;
+  }
+
+  function doTest(aIsPrivateMode, aWindow, aCallback) {
+    function contextMenuOpened(event) {
+      cache.clear();
 
-function promiseImageDownloaded() {
-  return new Promise((resolve, reject) => {
-    let fileName;
-    let MockFilePicker = SpecialPowers.MockFilePicker;
-    MockFilePicker.init(window);
+      aWindow.document.removeEventListener("popupshown", contextMenuOpened);
+
+      // Create the folder the image will be saved into.
+      var destDir = createTemporarySaveDirectory();
+      var destFile = destDir.clone();
+
+      MockFilePicker.displayDirectory = destDir;
+      MockFilePicker.showCallback = function(fp) {
+        fileName = fp.defaultString;
+        destFile.append (fileName);
+        MockFilePicker.returnFiles = [destFile];
+        MockFilePicker.filterIndex = 1; // kSaveAsType_URL
+      };
 
-    function onTransferComplete(downloadSuccess) {
-      ok(downloadSuccess, "Image file should have been downloaded successfully ");
+      mockTransferCallback = onTransferComplete;
+      mockTransferRegisterer.register();
 
-      // Give the request a chance to finish and create a cache entry
-      resolve(fileName);
+      registerCleanupFunction(function () {
+        mockTransferRegisterer.unregister();
+        MockFilePicker.cleanup();
+        destDir.remove(true);
+      });
+
+      // Select "Save Image As" option from context menu
+      var saveVideoCommand = aWindow.document.getElementById("context-saveimage");
+      saveVideoCommand.doCommand();
+
+      event.target.hidePopup();
     }
 
-    // Create the folder the image will be saved into.
-    var destDir = createTemporarySaveDirectory();
-    var destFile = destDir.clone();
+    aWindow.gBrowser.addEventListener("pageshow", function pageShown(event) {
+      // If data: --url PAC file isn't loaded soon enough, we may get about:privatebrowsing loaded
+      if (event.target.location == "about:blank" ||
+          event.target.location == "about:privatebrowsing") {
+        aWindow.gBrowser.selectedBrowser.loadURI(testURI);
+        return;
+      }
+      aWindow.gBrowser.removeEventListener("pageshow", pageShown);
+
+      waitForFocus(function () {
+        aWindow.document.addEventListener("popupshown", contextMenuOpened, false);
+        var img = aWindow.gBrowser.selectedBrowser.contentDocument.getElementById("img");
+        EventUtils.synthesizeMouseAtCenter(img,
+                                           { type: "contextmenu", button: 2 },
+                                           aWindow.gBrowser.contentWindow);
+      }, aWindow.gBrowser.selectedBrowser);
+    });
+  }
 
-    MockFilePicker.displayDirectory = destDir;
-    MockFilePicker.showCallback = function(fp) {
-      fileName = fp.defaultString;
-      destFile.append (fileName);
-      MockFilePicker.returnFiles = [destFile];
-      MockFilePicker.filterIndex = 1; // kSaveAsType_URL
-    };
+  function testOnWindow(aOptions, aCallback) {
+    whenNewWindowLoaded(aOptions, function(aWin) {
+      windowsToClose.push(aWin);
+      // execute should only be called when need, like when you are opening
+      // web pages on the test. If calling executeSoon() is not necesary, then
+      // call whenNewWindowLoaded() instead of testOnWindow() on your test.
+      executeSoon(() => aCallback(aWin));
+    });
+  };
 
-    mockTransferCallback = onTransferComplete;
-    mockTransferRegisterer.register();
+   // this function is called after calling finish() on the test.
+  registerCleanupFunction(function() {
+    windowsToClose.forEach(function(aWin) {
+      aWin.close();
+    });
+  });
 
-    registerCleanupFunction(function () {
-      mockTransferCallback = null;
-      mockTransferRegisterer.unregister();
-      MockFilePicker.cleanup();
-      destDir.remove(true);
-    });
-
+  MockFilePicker.init(window);
+  // then test when on private mode
+  testOnWindow({private: true}, function(aWin) {
+    doTest(true, aWin, finish);
   });
 }
 
-add_task(function* () {
-  let testURI = "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.html";
-  let privateWindow = yield BrowserTestUtils.openNewBrowserWindow({private: true});
-  let tab = yield BrowserTestUtils.openNewForegroundTab(privateWindow.gBrowser, testURI);
-
-  let contextMenu = privateWindow.document.getElementById("contentAreaContextMenu");
-  let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
-  let popupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#img", {
-    type: "contextmenu",
-    button: 2
-  }, tab.linkedBrowser);
-  yield popupShown;
-
-  let imageDownloaded = promiseImageDownloaded();
-  // Select "Save Image As" option from context menu
-  privateWindow.document.getElementById("context-saveimage").doCommand();
-
-  contextMenu.hidePopup();
-  yield popupHidden;
-
-  // wait for image download
-  yield imageDownloaded;
-  yield promiseNoCacheEntry();
-
-  yield BrowserTestUtils.closeWindow(privateWindow);
-});
-
 Cc["@mozilla.org/moz/jssubscript-loader;1"]
   .getService(Ci.mozIJSSubScriptLoader)
   .loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js",
                  this);