Bug 806706 - Port browser_save_link.js to the new per-window PB APIs; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 07 Nov 2012 21:14:41 -0500
changeset 112655 e5f86ee616005e3e0ea0bed887038b7b62197382
parent 112654 1ab2043a4669eda0a9088bc51b8a894bd312881c
child 112656 ed6ba763f45a78385198abc40462eea424019073
push id23833
push useremorley@mozilla.com
push dateThu, 08 Nov 2012 10:20:57 +0000
treeherdermozilla-central@e0d7b394462b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs806706
milestone19.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 806706 - Port browser_save_link.js to the new per-window PB APIs; r=jdm
browser/base/content/test/Makefile.in
browser/base/content/test/browser_save_link-perwindowpb.js
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -192,17 +192,16 @@ endif
                  browser_clearplugindata.html \
                  browser_clearplugindata_noage.html \
                  browser_popupUI.js \
                  browser_sanitizeDialog.js \
                  browser_save_video.js \
                  bug564387.html \
                  bug564387_video1.ogv \
                  bug564387_video1.ogv^headers^ \
-                 browser_save_link.js \
                  browser_save_private_link.js \
                  bug792517.html \
                  bug792517-2.html \
                  bug792517.sjs \
                  browser_scope.js \
                  browser_selectTabAtIndex.js \
                  browser_tab_dragdrop.js \
                  browser_tab_dragdrop2.js \
@@ -299,16 +298,21 @@ else
 
 # TODO: Activate after carbon test plugin lands, bug 628651
 # 		browser_maconly_carbon_mismatch_plugin.js \
 
 endif
 
 ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
 _BROWSER_FILES += \
-		browser_private_browsing_window.js \
-		$(NULL)
+                browser_private_browsing_window.js \
+                $(warning browser_save_link-perwindowpb.js disabled until bug 722850) \
+                $(NULL)
+else
+_BROWSER_FILES += \
+                browser_save_link.js \
+                $(NULL)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
copy from browser/base/content/test/browser_save_link.js
copy to browser/base/content/test/browser_save_link-perwindowpb.js
--- a/browser/base/content/test/browser_save_link.js
+++ b/browser/base/content/test/browser_save_link-perwindowpb.js
@@ -7,63 +7,62 @@ MockFilePicker.init();
 let tempScope = {};
 Cu.import("resource://gre/modules/NetUtil.jsm", tempScope);
 let NetUtil = tempScope.NetUtil;
 
 // Trigger a save of a link in public mode, then trigger an identical save
 // in private mode and ensure that the second request is differentiated from
 // the first by checking the cookies that are sent.
 
-function triggerSave(aCallback) {
+function triggerSave(aWindow, aCallback) {
   var fileName;
-  gBrowser.selectedTab = gBrowser.addTab();
-  let testBrowser = gBrowser.selectedBrowser;
+  let testBrowser = aWindow.gBrowser.selectedBrowser;
   testBrowser.loadURI("http://mochi.test:8888/browser/browser/base/content/test/bug792517-2.html");
   testBrowser.addEventListener("pageshow", function pageShown(event) {
     if (event.target.location == "about:blank")
       return;
     testBrowser.removeEventListener("pageshow", pageShown, false);
 
     executeSoon(function () {
-      document.addEventListener("popupshown", contextMenuOpened, false);
+      aWindow.document.addEventListener("popupshown", function(e) contextMenuOpened(aWindow, e), false);
 
       var link = testBrowser.contentDocument.getElementById("fff");
       EventUtils.synthesizeMouseAtCenter(link,
                                          { type: "contextmenu", button: 2 },
                                          testBrowser.contentWindow);
     });
   }, false);
 
-  function contextMenuOpened(event) {
+  function contextMenuOpened(aWindow, event) {
     event.currentTarget.removeEventListener("popupshown", contextMenuOpened, false);
 
     // Create the folder the link 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
     };
 
-    mockTransferCallback = function(a) onTransferComplete(a, destFile, destDir);
+    mockTransferCallback = function(a) onTransferComplete(aWindow, a, destFile, destDir);
 
     // Select "Save Link As" option from context menu
-    var saveLinkCommand = document.getElementById("context-savelink");
+    var saveLinkCommand = aWindow.document.getElementById("context-savelink");
     saveLinkCommand.doCommand();
 
     event.target.hidePopup();
   }
 
-  function onTransferComplete(downloadSuccess, destFile, destDir) {
+  function onTransferComplete(aWindow, downloadSuccess, destFile, destDir) {
     ok(downloadSuccess, "Link should have been downloaded successfully");
-    gBrowser.removeCurrentTab();
+    aWindow.gBrowser.removeCurrentTab();
 
     // Give the request a chance to finish
     executeSoon(function() aCallback(destFile, destDir));
   }
 }
 
 function readFile(file, callback) {
   let channel = NetUtil.newChannel(file);
@@ -77,44 +76,54 @@ function readFile(file, callback) {
                                                   inputStream.available());
     executeSoon(function() callback(content));
   });
 }
 
 function test() {
   waitForExplicitFinish();
 
-  let pb = Cc["@mozilla.org/privatebrowsing;1"]
-             .getService(Ci.nsIPrivateBrowsingService);
+  var windowsToClose = [];
+  function testOnWindow(options, callback) {
+    var win = OpenBrowserWindow(options);
+    win.addEventListener("load", function onLoad() {
+      win.removeEventListener("load", onLoad, false);
+      windowsToClose.push(win);
+      executeSoon(function() callback(win));
+    }, false);
+  }
 
   mockTransferRegisterer.register();
 
   registerCleanupFunction(function () {
     mockTransferRegisterer.unregister();
     MockFilePicker.cleanup();
-    pb.privateBrowsingEnabled = false;
-    Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+    windowsToClose.forEach(function(win) {
+      win.close();
+    });
   });
 
-  triggerSave(function(destFile, destDir) {
-    readFile(destFile, function(content) {
-      is(content, "cookie-not-present", "no cookie should be sent");
-      destDir.remove(true);
+  testOnWindow(undefined, function(win) {
+    triggerSave(win, function(destFile, destDir) {
+      readFile(destFile, function(content) {
+        is(content, "cookie-not-present", "no cookie should be sent");
+        destDir.remove(true);
 
-      Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-      pb.privateBrowsingEnabled = true;
-      triggerSave(function(destFile, destDir) {
-        readFile(destFile, function(content) {
-          is(content, "cookie-not-present", "no cookie should be sent");
-          destDir.remove(true);
-          finish();
+        testOnWindow({private: true}, function(win) {
+          triggerSave(win, function(destFile, destDir) {
+            readFile(destFile, function(content) {
+              is(content, "cookie-not-present", "no cookie should be sent");
+              destDir.remove(true);
+              finish();
+            });
+          });
         });
       });
     });
-  });  
+  });
 }
 
 Cc["@mozilla.org/moz/jssubscript-loader;1"]
   .getService(Ci.mozIJSSubScriptLoader)
   .loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js",
                  this);
 
 function createTemporarySaveDirectory() {