Bug 722995 - Part 1: Convert test_privatebrowsing_downloadLastDir.js, test_privatebrowsing_downloadLastDir_c.js, test_DownloadLastDir.js, and test_DownloadLastDirWithCPS.js to mochitest. r=ehsan
authorSaurabh Anand <saurabhanandiit@gmail.com>
Sat, 21 Jul 2012 11:20:24 +0530
changeset 111132 38183dea71ab583a39a56192fab456367683e5dd
parent 111131 8d9cff7e5c30a24520e890f63efe8cc5e4da6615
child 111133 03cd2ad254cc8e2067555cc11ec186f471c861ea
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersehsan
bugs722995
milestone19.0a1
Bug 722995 - Part 1: Convert test_privatebrowsing_downloadLastDir.js, test_privatebrowsing_downloadLastDir_c.js, test_DownloadLastDir.js, and test_DownloadLastDirWithCPS.js to mochitest. r=ehsan
browser/components/privatebrowsing/test/browser/global/Makefile.in
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_DownloadLastDirWithCPS.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir_c.js
browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir_toggle.js
toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js
toolkit/content/tests/unit/xpcshell.ini
toolkit/mozapps/downloads/tests/unit/test_DownloadLastDir.js
toolkit/mozapps/downloads/tests/unit/test_DownloadLastDirWithCPS.js
toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
toolkit/mozapps/downloads/tests/unit/xpcshell.ini
--- a/browser/components/privatebrowsing/test/browser/global/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/global/Makefile.in
@@ -9,16 +9,20 @@ VPATH		= @srcdir@
 relativesrcdir  = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_BROWSER_FILES =  \
 		head.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_crh.js \
+		browser_privatebrowsing_downloadLastDir.js \
+		browser_privatebrowsing_downloadLastDir_c.js \
+		browser_privatebrowsing_downloadLastDir_toggle.js \
+		browser_privatebrowsing_DownloadLastDirWithCPS.js \
 		browser_privatebrowsing_geoprompt.js \
 		browser_privatebrowsing_geoprompt_page.html \
 		browser_privatebrowsing_localStorage.js \
 		browser_privatebrowsing_localStorage_before_after.js \
 		browser_privatebrowsing_localStorage_before_after_page.html \
 		browser_privatebrowsing_localStorage_before_after_page2.html \
 		browser_privatebrowsing_localStorage_page1.html \
 		browser_privatebrowsing_localStorage_page2.html \
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_DownloadLastDirWithCPS.js
@@ -0,0 +1,259 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+let gTests;
+function test() {
+  waitForExplicitFinish();
+  gTests = runTest();
+  moveAlong();
+}
+
+function moveAlong() {
+  try {
+    gTests.next();
+  } catch (x if x instanceof StopIteration) {
+    finish();
+  }
+}
+
+function waitForPB() {
+  function observer(aSubject, aTopic, aData) {
+    Services.obs.removeObserver(observer, "last-pb-context-exited", false);
+    executeSoon(moveAlong);
+  }
+  Services.obs.addObserver(observer, "last-pb-context-exited", false);
+}
+
+function runTest() {
+  let tmpScope = {};
+  Cu.import("resource://gre/modules/DownloadLastDir.jsm", tmpScope);
+  let gDownloadLastDir = tmpScope.gDownloadLastDir;
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/FileUtils.jsm", tmpScope);
+  let FileUtils = tmpScope.FileUtils;
+
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+
+  function clearHistory() {
+    // simulate clearing the private data
+    Services.obs.notifyObservers(null, "browser:purge-session-history", "");
+  }
+
+  is(typeof gDownloadLastDir, "object", "gDownloadLastDir should be a valid object");
+  is(gDownloadLastDir.file, null, "LastDir pref should be null to start with");
+
+  let tmpDir = FileUtils.getDir("TmpD", [], true);
+
+  let uri1 = Services.io.newURI("http://test1.com/", null, null);
+  let uri2 = Services.io.newURI("http://test2.com/", null, null);
+  let uri3 = Services.io.newURI("http://test3.com/", null, null);
+  let uri4 = Services.io.newURI("http://test4.com/", null, null);
+
+  function newDir() {
+    let dir = tmpDir.clone();
+    dir.append("testdir");
+    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+    return dir;
+  }
+
+  let dir1 = newDir();
+  let dir2 = newDir();
+  let dir3 = newDir();
+  try {
+    { // set up last dir
+      gDownloadLastDir.setFile(null, tmpDir);
+      is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the tmpDir");
+      isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to tmpDir");
+    }
+
+    { // set uri1 to dir1, all should now return dir1
+      // also check that a new object is returned
+      gDownloadLastDir.setFile(uri1, dir1);
+      is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should return dir1");
+      isnot(gDownloadLastDir.file, dir1, "gDownloadLastDir.file should not return dir1");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
+      isnot(gDownloadLastDir.getFile(uri1), dir1, "getFile on uri1 should not return dir1");
+      is(gDownloadLastDir.getFile(uri2).path, dir1.path, "uri2 should return dir1"); // fallback
+      isnot(gDownloadLastDir.getFile(uri2), dir1, "getFile on uri2 should not return dir1");
+      is(gDownloadLastDir.getFile(uri3).path, dir1.path, "uri3 should return dir1"); // fallback
+      isnot(gDownloadLastDir.getFile(uri3), dir1, "getFile on uri3 should not return dir1");
+      is(gDownloadLastDir.getFile(uri4).path, dir1.path, "uri4 should return dir1"); // fallback
+      isnot(gDownloadLastDir.getFile(uri4), dir1, "getFile on uri4 should not return dir1");
+    }
+
+    { // set uri2 to dir2, all except uri1 should now return dir2
+      gDownloadLastDir.setFile(uri2, dir2);
+      is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should point to dir2");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
+      is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
+      is(gDownloadLastDir.getFile(uri3).path, dir2.path, "uri3 should return dir2"); // fallback
+      is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2"); // fallback
+    }
+
+    { // set uri3 to dir3, all except uri1 and uri2 should now return dir3
+      gDownloadLastDir.setFile(uri3, dir3);
+      is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should point to dir3");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1"); // set in CPS
+      is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
+      is(gDownloadLastDir.getFile(uri3).path, dir3.path, "uri3 should return dir3"); // set in CPS
+      is(gDownloadLastDir.getFile(uri4).path, dir3.path, "uri4 should return dir4"); // fallback
+    }
+
+    { // set uri1 to dir2, all except uri3 should now return dir2
+      gDownloadLastDir.setFile(uri1, dir2);
+      is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should point to dir2");
+      is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2"); // set in CPS
+      is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2"); // set in CPS
+      is(gDownloadLastDir.getFile(uri3).path, dir3.path, "uri3 should return dir3"); // set in CPS
+      is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2"); // fallback
+    }
+
+    { // check clearHistory removes all data
+      clearHistory();
+      is(gDownloadLastDir.file, null, "clearHistory removes all data");
+      is(Services.contentPrefs.hasPref(uri1, "browser.download.lastDir"), false, "LastDir preference should be absent");
+      is(gDownloadLastDir.getFile(uri1), null, "uri1 should point to null");
+      is(gDownloadLastDir.getFile(uri2), null, "uri2 should point to null");
+      is(gDownloadLastDir.getFile(uri3), null, "uri3 should point to null");
+      is(gDownloadLastDir.getFile(uri4), null, "uri4 should point to null");
+    }
+
+    Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+
+    { // check data set outside PB mode is remembered
+      gDownloadLastDir.setFile(null, tmpDir);
+      pb.privateBrowsingEnabled = true;
+      is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to tmpDir inside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir inside PB mode");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to tmpDir outside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir outside PB mode");
+
+      clearHistory();
+    }
+
+    { // check data set using CPS outside PB mode is remembered
+      gDownloadLastDir.setFile(uri1, dir1);
+      pb.privateBrowsingEnabled = true;
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 inside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 inside PB mode");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 outside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 outside PB mode");
+
+      clearHistory();
+    }
+
+    { // check data set inside PB mode is forgotten
+      pb.privateBrowsingEnabled = true;
+      gDownloadLastDir.setFile(null, tmpDir);
+      is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should return tmpDir inside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, tmpDir.path, "uri1 should return tmpDir inside PB mode");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file, null, "LastDir should be null outside PB mode");
+      is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null outside PB mode");
+
+      clearHistory();
+    }
+
+    { // check data set using CPS inside PB mode is forgotten
+      pb.privateBrowsingEnabled = true;
+      gDownloadLastDir.setFile(uri1, dir1);
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 inside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 inside PB mode");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file, null, "LastDir should point to null outside PB mode");
+      is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null outside PB mode");
+
+      clearHistory();
+    }
+
+    { // check data set outside PB mode but changed inside is remembered correctly
+      gDownloadLastDir.setFile(uri1, dir1);
+      pb.privateBrowsingEnabled = true;
+      gDownloadLastDir.setFile(uri1, dir2);
+      is(gDownloadLastDir.file.path, dir2.path, "LastDir should point to dir2 inside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2 inside PB mode");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should point to dir1 outside PB mode");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1 outside PB mode");
+
+      // check that the last dir store got cleared
+      pb.privateBrowsingEnabled = true;
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should be cleared");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      clearHistory();
+    }
+
+    { // check clearHistory inside PB mode clears data outside PB mode
+      pb.privateBrowsingEnabled = true;
+      gDownloadLastDir.setFile(uri1, dir2);
+
+      clearHistory();
+      is(gDownloadLastDir.file, null, "LastDir should be null afer clearing history");
+      is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null");
+
+      waitForPB();
+      pb.privateBrowsingEnabled = false;
+      yield;
+      is(gDownloadLastDir.file, null, "LastDir should be null");
+      is(gDownloadLastDir.getFile(uri1), null, "uri1 should return null");
+    }
+
+    { // check that disabling CPS works
+      Services.prefs.setBoolPref("browser.download.lastDir.savePerSite", false);
+
+      gDownloadLastDir.setFile(uri1, dir1);
+      is(gDownloadLastDir.file.path, dir1.path, "LastDir should be set to dir1");
+      is(gDownloadLastDir.getFile(uri1).path, dir1.path, "uri1 should return dir1");
+      is(gDownloadLastDir.getFile(uri2).path, dir1.path, "uri2 should return dir1");
+      is(gDownloadLastDir.getFile(uri3).path, dir1.path, "uri3 should return dir1");
+      is(gDownloadLastDir.getFile(uri4).path, dir1.path, "uri4 should return dir1");
+
+      gDownloadLastDir.setFile(uri2, dir2);
+      is(gDownloadLastDir.file.path, dir2.path, "LastDir should be set to dir2");
+      is(gDownloadLastDir.getFile(uri1).path, dir2.path, "uri1 should return dir2");
+      is(gDownloadLastDir.getFile(uri2).path, dir2.path, "uri2 should return dir2");
+      is(gDownloadLastDir.getFile(uri3).path, dir2.path, "uri3 should return dir2");
+      is(gDownloadLastDir.getFile(uri4).path, dir2.path, "uri4 should return dir2");
+
+      Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
+    }
+
+    { // check that passing null to setFile clears the stored value
+      gDownloadLastDir.setFile(uri3, dir3);
+      is(gDownloadLastDir.getFile(uri3).path, dir3.path, "LastDir should be set to dir3");
+      gDownloadLastDir.setFile(uri3, null);
+      is(gDownloadLastDir.getFile(uri3), null, "uri3 should return null");
+    }
+  } finally {
+      dir1.remove(true);
+      dir2.remove(true);
+      dir3.remove(true);
+      Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
+      Services.prefs.clearUserPref("browser.download.lastDir");
+      gDownloadLastDir.cleanupPrivateFile();
+  }
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir.js
@@ -0,0 +1,98 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 test() {
+  let tempScope = {};
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/DownloadLastDir.jsm");
+  Cu.import("resource://gre/modules/FileUtils.jsm", tempScope);
+  let FileUtils = tempScope.FileUtils;
+  let MockFilePicker = SpecialPowers.MockFilePicker;
+
+  let launcher = {
+    source: Services.io.newURI("http://test1.com/file", null, null)
+  };
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+
+  MockFilePicker.init();
+   MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
+
+  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+  let prefs = Services.prefs.getBranch("browser.download.");
+  let launcherDialog = Cc["@mozilla.org/helperapplauncherdialog;1"].
+                       getService(Ci.nsIHelperAppLauncherDialog);
+  let tmpDir = FileUtils.getDir("TmpD", [], true);
+  function newDirectory() {
+    let dir = tmpDir.clone();
+    dir.append("testdir");
+    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+    return dir;
+  }
+  function newFileInDirectory(dir) {
+    let file = dir.clone();
+    file.append("testfile");
+    file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
+    return file;
+  }
+
+  let dir1 = newDirectory();
+  let dir2 = newDirectory();
+  let dir3 = newDirectory();
+  let file1 = newFileInDirectory(dir1);
+  let file2 = newFileInDirectory(dir2);
+  let file3 = newFileInDirectory(dir3);
+
+  // cleanup functions registration
+  registerCleanupFunction(function () {
+    Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+    Services.prefs.clearUserPref("browser.download.lastDir");
+    [dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
+    MockFilePicker.cleanup();
+    gDownloadLastDir.cleanupPrivateFile();
+    delete FileUtils;
+    delete gDownloadLastDir;
+  });
+
+  let context = gBrowser.selectedBrowser.contentWindow;
+
+  prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir);
+  MockFilePicker.returnFiles = [file1];
+  let file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
+  ok(!!file, "promptForSaveToFile correctly returned a file");
+  // file picker should start with browser.download.lastDir
+  is(MockFilePicker.displayDirectory.path, tmpDir.path, "File picker should start with browser.download.lastDir");
+  // browser.download.lastDir should be modified before entering the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be modified before entering the PB mode");
+  // gDownloadLastDir should be usable outside of the private browsing mode
+  is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be usable outside of the PB mode");
+
+  pb.privateBrowsingEnabled = true;
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be that set before entering PB mode");
+  MockFilePicker.returnFiles = [file2];
+  MockFilePicker.displayDirectory = null;
+  file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
+  ok(!!file, "promptForSaveToFile correctly returned a file");
+  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
+  is(MockFilePicker.displayDirectory.path, dir1.path, "Start with LastDir as set before entering the PB mode");
+  // browser.download.lastDir should not be modified inside the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should not be modified inside the PB mode");
+  // but gDownloadLastDir should be modified
+  is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should be modified inside PB mode");
+
+  pb.privateBrowsingEnabled = false;
+  // gDownloadLastDir should be cleared after leaving the private browsing mode
+  is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be cleared after leaving the PB mode");
+  MockFilePicker.returnFiles = [file3];
+  MockFilePicker.displayDirectory = null;
+  file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
+  ok(!!file, "promptForSaveToFile correctly returned a file");
+  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
+  is(MockFilePicker.displayDirectory.path, dir1.path, "Start with LastDir as set before entering the PB mode");
+  // browser.download.lastDir should be modified after leaving the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir3.path, "LastDir should be modified after leaving the PB mode");
+  // gDownloadLastDir should be usable after leaving the private browsing mode
+  is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should be usable after leaving the PB mode");
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir_c.js
@@ -0,0 +1,113 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 test() {
+  let tmpScope = {};
+  Cu.import("resource://gre/modules/DownloadLastDir.jsm");
+  Cu.import("resource://gre/modules/FileUtils.jsm", tmpScope);
+  let FileUtils = tmpScope.FileUtils;
+  Cu.import("resource://gre/modules/Services.jsm");
+  let MockFilePicker = SpecialPowers.MockFilePicker;
+
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+
+  MockFilePicker.init();
+  MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
+
+  //let stringBundleToRestore = ContentAreaUtils.stringBundle;
+  let validateFileNameToRestore = validateFileName;
+
+  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+  let prefs = Services.prefs.getBranch("browser.download.");
+  let tmpDir = FileUtils.getDir("TmpD", [], true);
+  function newDirectory() {
+    let dir = tmpDir.clone();
+    dir.append("testdir");
+    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+    return dir;
+  }
+
+  function newFileInDirectory(dir) {
+    let file = dir.clone();
+    file.append("testfile");
+    file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
+    return file;
+  }
+
+  let dir1 = newDirectory();
+  let dir2 = newDirectory();
+  let dir3 = newDirectory();
+  let file1 = newFileInDirectory(dir1);
+  let file2 = newFileInDirectory(dir2);
+  let file3 = newFileInDirectory(dir3);
+
+  // cleanup function registration
+  registerCleanupFunction(function () {
+    Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+    Services.prefs.clearUserPref("browser.download.lastDir");
+    [dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
+    MockFilePicker.cleanup();
+    //ContentAreaUtils.stringBundle = stringBundleToRestore;
+    validateFileName = validateFileNameToRestore;
+    gDownloadLastDir.cleanupPrivateFile();
+    delete FileUtils;
+    delete gDownloadLastDir;
+  });
+
+  // Overwrite stringBundle to return an object masquerading as a string bundle
+  /*delete ContentAreaUtils.stringBundle;
+  ContentAreaUtils.stringBundle = {
+    GetStringFromName: function() ""
+  };*/
+
+  // Overwrite validateFileName to validate everything
+  validateFileName = function(foo) foo;
+
+  let params = {
+    //fpTitleKey: "test",
+    fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"),
+    contentType: "text/plain",
+    saveMode: SAVEMODE_FILEONLY,
+    saveAsType: kSaveAsType_Complete,
+    file: null
+  };
+
+  prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir);
+  MockFilePicker.returnFiles = [file1];
+  MockFilePicker.displayDirectory = null;
+  ok(getTargetFile(params), "Show the file picker dialog with given params");
+  // file picker should start with browser.download.lastDir
+  is(MockFilePicker.displayDirectory.path, tmpDir.path, "file picker should start with browser.download.lastDir");
+  // browser.download.lastDir should be modified before entering the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be modified before entering PB mode");
+  // gDownloadLastDir should be usable outside of the private browsing mode
+  is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be usable outside of the PB mode");
+
+  pb.privateBrowsingEnabled = true;
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be that set before PB mode");
+  MockFilePicker.returnFiles = [file2];
+  MockFilePicker.displayDirectory = null;
+  ok(getTargetFile(params), "Show the file picker dialog with the given params");
+  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
+  is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before entering PB mode");
+  // browser.download.lastDir should not be modified inside the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should not be modified inside PB mode");
+  // but gDownloadLastDir should be modified
+  is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should be modified");
+
+  pb.privateBrowsingEnabled = false;
+  // gDownloadLastDir should be cleared after leaving the private browsing mode
+  is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be cleared after leaving PB mode");
+  MockFilePicker.returnFiles = [file3];
+  MockFilePicker.displayDirectory = null;
+  ok(getTargetFile(params), "Show the file picker dialog with the given params");
+  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
+  is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before PB mode");
+  // browser.download.lastDir should be modified after leaving the private browsing mode
+  is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir3.path, "LastDir should be modified after leaving PB mode");
+  // gDownloadLastDir should be usable after leaving the private browsing mode
+  is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should be usable after leaving PB mode");
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_downloadLastDir_toggle.js
@@ -0,0 +1,75 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 test() {
+  var tmpScope = {};
+  Cu.import("resource://gre/modules/DownloadLastDir.jsm");
+  Cu.import("resource://gre/modules/FileUtils.jsm", tmpScope);
+  Cu.import("resource://gre/modules/Services.jsm");
+  let FileUtils = tmpScope.FileUtils;
+
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+
+  function clearHistory() {
+    // simulate clearing the private data
+    Services.obs.notifyObservers(null, "browser:purge-session-history", "");
+  }
+
+  is(typeof gDownloadLastDir, "object", "gDownloadLastDir should be a valid object");
+  is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null to start with");
+  let tmpDir = FileUtils.getDir("TmpD", [], true);
+  let newDir = tmpDir.clone();
+
+  registerCleanupFunction(function () {
+    Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+    Services.prefs.clearUserPref("browser.download.lastDir");
+    newDir.remove(true);
+    gDownloadLastDir.cleanupPrivateFile();
+    delete FileUtils;
+    delete gDownloadLastDir;
+  });
+
+  newDir.append("testdir");
+  newDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
+
+  gDownloadLastDir.file = tmpDir;
+  is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the temporary directory");
+  isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to the tmpDir");
+
+  gDownloadLastDir.file = 1; // not an nsIFile
+  is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
+  gDownloadLastDir.file = tmpDir;
+
+  clearHistory();
+  is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null");
+  gDownloadLastDir.file = tmpDir;
+
+  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+
+  pb.privateBrowsingEnabled = true;
+  is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the temporary directory");
+  isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir.file should not be pointing to the tmpDir");
+
+  pb.privateBrowsingEnabled = false;
+  is(gDownloadLastDir.file.path, tmpDir.path, "LastDir should point to the tmpDir");
+  pb.privateBrowsingEnabled = true;
+
+  gDownloadLastDir.file = newDir;
+  is(gDownloadLastDir.file.path, newDir.path, "gDownloadLastDir should be modified in PB mode");
+  isnot(gDownloadLastDir.file, newDir, "gDownloadLastDir should not point to the newDir");
+
+  pb.privateBrowsingEnabled = false;
+  is(gDownloadLastDir.file.path, tmpDir.path, "gDownloadLastDir should point to the earlier directory outside PB mode");
+  isnot(gDownloadLastDir.file, tmpDir, "gDownloadLastDir should not be modifief outside PB mode");
+
+  pb.privateBrowsingEnabled = true;
+  isnot(gDownloadLastDir.file, null, "gDownloadLastDir should not be null inside PB mode");
+  clearHistory();
+  is(gDownloadLastDir.file, null, "gDownloadLastDir should be null after clearing history");
+
+  pb.privateBrowsingEnabled = false;
+  is(gDownloadLastDir.file, null, "gDownloadLastDir should be null outside PB mode");
+}
deleted file mode 100644
--- a/toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js
+++ /dev/null
@@ -1,130 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-
-function loadUtilsScript() {
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
-  Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
-}
-
-do_get_profile();
-
-let window = {};
-function run_test()
-{
-  let pb;
-  try {
-    pb = Cc["@mozilla.org/privatebrowsing;1"].
-         getService(Ci.nsIPrivateBrowsingService);
-  } catch (e) {
-    print("PB service is not available, bail out");
-    return;
-  }
-
-  loadUtilsScript();
-
-  let prefsService = Cc["@mozilla.org/preferences-service;1"].
-                     getService(Ci.nsIPrefService).
-                     QueryInterface(Ci.nsIPrefBranch);
-  prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-  let prefs = prefsService.getBranch("browser.download.");
-  let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
-  function newDirectory() {
-    let dir = tmpDir.clone();
-    dir.append("testdir" + Math.floor(Math.random() * 10000));
-    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-    return dir;
-  }
-  function newFileInDirectory(dir) {
-    let file = dir.clone();
-    file.append("testfile" + Math.floor(Math.random() * 10000));
-    file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
-    return file;
-  }
-  let dir1 = newDirectory();
-  let dir2 = newDirectory();
-  let dir3 = newDirectory();
-  let file1 = newFileInDirectory(dir1);
-  let file2 = newFileInDirectory(dir2);
-  let file3 = newFileInDirectory(dir3);
-
-  // overwrite makeFilePicker, as we don't want to create a real filepicker object
-  let fp = {
-    appendFilter: function() {},
-    appendFilters: function() {},
-    init: function() {},
-    show: function() Ci.nsIFilePicker.returnOK,
-    displayDirectory: null,
-    file: file1
-  };
-  makeFilePicker = function() fp;
-
-  // Overwrite stringBundle to return an object masquerading as a string bundle
-  delete ContentAreaUtils.stringBundle;
-  ContentAreaUtils.stringBundle = {
-    GetStringFromName: function() ""
-  };
-
-  // Overwrite validateFileName to validate everything
-  validateFileName = function(foo) foo;
-
-  let params = {
-    fpTitleKey: "test",
-    fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"),
-    contentType: "text/plain",
-    saveMode: SAVEMODE_FILEONLY,
-    saveAsType: kSaveAsType_Complete,
-    file: null
-  };
-
-  prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
-
-  do_check_true(getTargetFile(params));
-  // file picker should start with browser.download.lastDir
-  do_check_eq(fp.displayDirectory.path, tmpDir.path);
-  // browser.download.lastDir should be modified before entering the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  // gDownloadLastDir should be usable outside of the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir1.path);
-
-  pb.privateBrowsingEnabled = true;
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  fp.file = file2;
-  fp.displayDirectory = null;
-  do_check_true(getTargetFile(params));
-  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
-  do_check_eq(fp.displayDirectory.path, dir1.path);
-  // browser.download.lastDir should not be modified inside the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  // but gDownloadLastDir should be modified
-  do_check_eq(gDownloadLastDir.file.path, dir2.path);
-
-  pb.privateBrowsingEnabled = false;
-  // gDownloadLastDir should be cleared after leaving the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir1.path);
-  fp.file = file3;
-  fp.displayDirectory = null;
-  do_check_true(getTargetFile(params));
-  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
-  do_check_eq(fp.displayDirectory.path, dir1.path);
-  // browser.download.lastDir should be modified after leaving the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
-  // gDownloadLastDir should be usable after leaving the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir3.path);
-
-  // cleanup
-  Cc["@mozilla.org/observer-service;1"]
-    .getService(Ci.nsIObserverService)
-    .notifyObservers(null, "quit-application", null);
-
-  prefsService.clearUserPref("browser.privatebrowsing.keep_current_session");
-  [dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
-}
--- a/toolkit/content/tests/unit/xpcshell.ini
+++ b/toolkit/content/tests/unit/xpcshell.ini
@@ -1,9 +1,8 @@
 [DEFAULT]
 head = 
 tail = 
 
 [test_contentAreaUtils.js]
 [test_dict.js]
-[test_privatebrowsing_downloadLastDir_c.js]
 [test_propertyListsUtils.js]
 [test_task.js]
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadLastDir.js
+++ /dev/null
@@ -1,82 +0,0 @@
-/* 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 run_test()
-{
-  let Cc = Components.classes;
-  let Ci = Components.interfaces;
-  let Cu = Components.utils;
-  do_get_profile();
-  Cu.import("resource://gre/modules/DownloadLastDir.jsm");
-
-  function clearHistory() {
-    // simulate clearing the private data
-    Cc["@mozilla.org/observer-service;1"].
-    getService(Ci.nsIObserverService).
-    notifyObservers(null, "browser:purge-session-history", "");
-  }
-
-  do_check_eq(typeof gDownloadLastDir, "object");
-  do_check_eq(gDownloadLastDir.file, null);
-
-  let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
-  let newDir = tmpDir.clone();
-  newDir.append("testdir" + Math.floor(Math.random() * 10000));
-  newDir.QueryInterface(Ci.nsILocalFile);
-  newDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-
-  gDownloadLastDir.file = tmpDir;
-  do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-  do_check_neq(gDownloadLastDir.file, tmpDir);
-
-  gDownloadLastDir.file = 1; // not an nsIFile
-  do_check_eq(gDownloadLastDir.file, null);
-  gDownloadLastDir.file = tmpDir;
-
-  clearHistory();
-  do_check_eq(gDownloadLastDir.file, null);
-  gDownloadLastDir.file = tmpDir;
-
-  let pb;
-  try {
-    pb = Cc["@mozilla.org/privatebrowsing;1"].
-         getService(Ci.nsIPrivateBrowsingService);
-  } catch (e) {
-    print("PB service is not available, bail out");
-    return;
-  }
-
-  let prefs = Cc["@mozilla.org/preferences-service;1"].
-              getService(Ci.nsIPrefBranch);
-  prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-
-  pb.privateBrowsingEnabled = true;
-  do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-  do_check_neq(gDownloadLastDir.file, tmpDir);
-
-  pb.privateBrowsingEnabled = false;
-  do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-  pb.privateBrowsingEnabled = true;
-
-  gDownloadLastDir.file = newDir;
-  do_check_eq(gDownloadLastDir.file.path, newDir.path);
-  do_check_neq(gDownloadLastDir.file, newDir);
-
-  pb.privateBrowsingEnabled = false;
-  do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-  do_check_neq(gDownloadLastDir.file, tmpDir);
-
-  pb.privateBrowsingEnabled = true;
-  do_check_neq(gDownloadLastDir.file, null);
-  clearHistory();
-  do_check_eq(gDownloadLastDir.file, null);
-
-  pb.privateBrowsingEnabled = false;
-  do_check_eq(gDownloadLastDir.file, null);
-
-  prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
-  newDir.remove(true);
-}
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadLastDirWithCPS.js
+++ /dev/null
@@ -1,228 +0,0 @@
-/* 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/. */
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cu = Components.utils;
-
-Cu.import("resource://gre/modules/DownloadLastDir.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-
-do_get_profile();
-
-function run_test() {
-  function clearHistory() {
-    // simulate clearing the private data
-    Services.obs.notifyObservers(null, "browser:purge-session-history", "");
-  }
-
-  do_check_eq(typeof gDownloadLastDir, "object");
-  do_check_eq(gDownloadLastDir.file, null);
-  
-  let tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile);
-  
-  let uri1 = Services.io.newURI("http://test1.com/", null, null);
-  let uri2 = Services.io.newURI("http://test2.com/", null, null);
-  let uri3 = Services.io.newURI("http://test3.com/", null, null);
-  let uri4 = Services.io.newURI("http://test4.com/", null, null);
-
-  function newDir() {
-    let dir = tmpDir.clone();
-    dir.append("testdir" + Math.floor(Math.random() * 10000));
-    dir.QueryInterface(Ci.nsILocalFile);
-    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-    return dir;
-  }
-  
-  let dir1 = newDir();
-  let dir2 = newDir();
-  let dir3 = newDir();
-
-  try {
-    { // set up last dir
-      gDownloadLastDir.setFile(null, tmpDir);
-      do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-      do_check_neq(gDownloadLastDir.file, tmpDir);
-    }
-
-    { // set uri1 to dir1, all should now return dir1
-      // also check that a new object is returned
-      gDownloadLastDir.setFile(uri1, dir1);
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_neq(gDownloadLastDir.file, dir1);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
-      do_check_neq(gDownloadLastDir.getFile(uri1), dir1);
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir1.path); // fallback
-      do_check_neq(gDownloadLastDir.getFile(uri2), dir1);
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir1.path); // fallback
-      do_check_neq(gDownloadLastDir.getFile(uri3), dir1);
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir1.path); // fallback
-      do_check_neq(gDownloadLastDir.getFile(uri4), dir1);
-    }
-
-    { // set uri2 to dir2, all except uri1 should now return dir2
-      gDownloadLastDir.setFile(uri2, dir2);
-      do_check_eq(gDownloadLastDir.file.path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir2.path); // fallback
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path); // fallback
-    }
-
-    { // set uri3 to dir3, all except uri1 and uri2 should now return dir3
-      gDownloadLastDir.setFile(uri3, dir3);
-      do_check_eq(gDownloadLastDir.file.path, dir3.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir3.path); // fallback
-    }
-
-    { // set uri1 to dir2, all except uri3 should now return dir2
-      gDownloadLastDir.setFile(uri1, dir2);
-      do_check_eq(gDownloadLastDir.file.path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path); // set in CPS
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path); // fallback
-    }
-
-    { // check clearHistory removes all data
-      clearHistory();
-      do_check_eq(gDownloadLastDir.file, null);
-      do_check_eq(Services.contentPrefs.hasPref(uri1, "browser.download.lastDir"), false);
-      do_check_eq(gDownloadLastDir.getFile(uri1), null);
-      do_check_eq(gDownloadLastDir.getFile(uri2), null);
-      do_check_eq(gDownloadLastDir.getFile(uri3), null);
-      do_check_eq(gDownloadLastDir.getFile(uri4), null);
-    }
-
-    let pb;
-    try {
-      pb = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
-    } catch (e) {
-      print("PB service is not available, bail out");
-      return;
-    }
-
-    Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-    
-    { // check data set outside PB mode is remembered
-      gDownloadLastDir.setFile(null, tmpDir);
-      pb.privateBrowsingEnabled = true;
-      do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
-      
-      clearHistory();
-    }
-
-    { // check data set using CPS outside PB mode is remembered
-      gDownloadLastDir.setFile(uri1, dir1);
-      pb.privateBrowsingEnabled = true;
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-
-      clearHistory();
-    }
-    
-    { // check data set inside PB mode is forgotten
-      pb.privateBrowsingEnabled = true;
-      gDownloadLastDir.setFile(null, tmpDir);
-      do_check_eq(gDownloadLastDir.file.path, tmpDir.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, tmpDir.path);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file, null);
-      do_check_eq(gDownloadLastDir.getFile(uri1), null);
-      
-      clearHistory();
-    }
-    
-    { // check data set using CPS inside PB mode is forgotten
-      pb.privateBrowsingEnabled = true;
-      gDownloadLastDir.setFile(uri1, dir1);
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file, null);
-      do_check_eq(gDownloadLastDir.getFile(uri1), null);
-
-      clearHistory();
-    }
-
-    { // check data set outside PB mode but changed inside is remembered correctly
-      gDownloadLastDir.setFile(uri1, dir1);
-      pb.privateBrowsingEnabled = true;
-      gDownloadLastDir.setFile(uri1, dir2);
-      do_check_eq(gDownloadLastDir.file.path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-
-      // check that the last dir store got cleared
-      pb.privateBrowsingEnabled = true;
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-      
-      pb.privateBrowsingEnabled = false;
-      clearHistory();
-    }
-    
-    { // check clearHistory inside PB mode clears data outside PB mode
-      pb.privateBrowsingEnabled = true;
-      gDownloadLastDir.setFile(uri1, dir2);
-
-      clearHistory();
-      do_check_eq(gDownloadLastDir.file, null);
-      do_check_eq(gDownloadLastDir.getFile(uri1), null);
-
-      pb.privateBrowsingEnabled = false;
-      do_check_eq(gDownloadLastDir.file, null);
-      do_check_eq(gDownloadLastDir.getFile(uri1), null);
-    }
-
-    { // check that disabling CPS works
-      Services.prefs.setBoolPref("browser.download.lastDir.savePerSite", false);
-
-      gDownloadLastDir.setFile(uri1, dir1);
-      do_check_eq(gDownloadLastDir.file.path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir1.path);
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir1.path);
-
-      gDownloadLastDir.setFile(uri2, dir2);
-      do_check_eq(gDownloadLastDir.file.path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri1).path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri2).path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir2.path);
-      do_check_eq(gDownloadLastDir.getFile(uri4).path, dir2.path);
-
-      Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
-    }
-
-    { // check that passing null to setFile clears the stored value
-      gDownloadLastDir.setFile(uri3, dir3);
-      do_check_eq(gDownloadLastDir.getFile(uri3).path, dir3.path);
-      gDownloadLastDir.setFile(uri3, null);
-      do_check_eq(gDownloadLastDir.getFile(uri3), null);
-    }
-  } finally {
-    dir1.remove(true);
-    dir2.remove(true);
-    dir3.remove(true);
-    Services.prefs.clearUserPref("browser.download.lastDir.savePerSite");
-  }
-}
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
-const Cu = Components.utils;
-const Cr = Components.results;
-
-do_get_profile();
-
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/DownloadLastDir.jsm");
-
-let context = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
-  getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindow])
-};
-
-let launcher = {
-  source: Services.io.newURI("http://test1.com/file", null, null)
-};
-
-Cu.import("resource://test/MockFilePicker.jsm");
-MockFilePicker.init();
-MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
-
-function run_test()
-{
-  let pb;
-  try {
-    pb = Cc["@mozilla.org/privatebrowsing;1"].
-         getService(Ci.nsIPrivateBrowsingService);
-  } catch (e) {
-    print("PB service is not available, bail out");
-    return;
-  }
-
-  let prefsService = Cc["@mozilla.org/preferences-service;1"].
-                     getService(Ci.nsIPrefService).
-                     QueryInterface(Ci.nsIPrefBranch);
-  prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-  let prefs = prefsService.getBranch("browser.download.");
-  let launcherDialog = Cc["@mozilla.org/helperapplauncherdialog;1"].
-                       getService(Ci.nsIHelperAppLauncherDialog);
-  let dirSvc = Cc["@mozilla.org/file/directory_service;1"].
-               getService(Ci.nsIProperties);
-  let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
-  function newDirectory() {
-    let dir = tmpDir.clone();
-    dir.append("testdir" + Math.floor(Math.random() * 10000));
-    dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
-    return dir;
-  }
-  function newFileInDirectory(dir) {
-    let file = dir.clone();
-    file.append("testfile" + Math.floor(Math.random() * 10000));
-    file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
-    return file;
-  }
-  let dir1 = newDirectory();
-  let dir2 = newDirectory();
-  let dir3 = newDirectory();
-  let file1 = newFileInDirectory(dir1);
-  let file2 = newFileInDirectory(dir2);
-  let file3 = newFileInDirectory(dir3);
-
-  prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
-
-  MockFilePicker.returnFiles = [file1];
-  let file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
-  do_check_true(!!file);
-  // file picker should start with browser.download.lastDir
-  do_check_eq(MockFilePicker.displayDirectory.path, tmpDir.path);
-  // browser.download.lastDir should be modified before entering the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  // gDownloadLastDir should be usable outside of the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir1.path);
-
-  pb.privateBrowsingEnabled = true;
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  MockFilePicker.returnFiles = [file2];
-  MockFilePicker.displayDirectory = null;
-  file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
-  do_check_true(!!file);
-  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
-  do_check_eq(MockFilePicker.displayDirectory.path, dir1.path);
-  // browser.download.lastDir should not be modified inside the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path);
-  // but gDownloadLastDir should be modified
-  do_check_eq(gDownloadLastDir.file.path, dir2.path);
-
-  pb.privateBrowsingEnabled = false;
-  // gDownloadLastDir should be cleared after leaving the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir1.path);
-  MockFilePicker.returnFiles = [file3];
-  MockFilePicker.displayDirectory = null;
-  file = launcherDialog.promptForSaveToFile(launcher, context, null, null, null);
-  do_check_true(!!file);
-  // file picker should start with browser.download.lastDir as set before entering the private browsing mode
-  do_check_eq(MockFilePicker.displayDirectory.path, dir1.path);
-  // browser.download.lastDir should be modified after leaving the private browsing mode
-  do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path);
-  // gDownloadLastDir should be usable after leaving the private browsing mode
-  do_check_eq(gDownloadLastDir.file.path, dir3.path);
-
-  // cleanup
-  prefsService.clearUserPref("browser.privatebrowsing.keep_current_session");
-  [dir1, dir2, dir3].forEach(function(dir) dir.remove(true));
-
-  MockFilePicker.cleanup();
-}
--- a/toolkit/mozapps/downloads/tests/unit/xpcshell.ini
+++ b/toolkit/mozapps/downloads/tests/unit/xpcshell.ini
@@ -1,12 +1,9 @@
 [DEFAULT]
 head = head_downloads.js
 tail = 
 
-[test_DownloadLastDir.js]
-[test_DownloadLastDirWithCPS.js]
 [test_DownloadPaths.js]
 [test_DownloadUtils.js]
 [test_lowMinutes.js]
-[test_privatebrowsing_downloadLastDir.js]
 [test_syncedDownloadUtils.js]
 [test_unspecified_arguments.js]