Backout f2390732b6a4 (Bug 668154) for apparently turning debug mochitest-oth & mochitest-4 perma-orange
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 11 Jul 2011 17:49:03 -0700
changeset 73688 ec45982514f4f109f0a4e552e95d700ab0f4d28d
parent 73687 691294843828d5b4108559b27bfe342ce3b146ef
child 73689 8b1328c6045264dbf8ff7383d97004d0afb64c4a
push id67
push userclegnitto@mozilla.com
push dateFri, 04 Nov 2011 22:39:41 +0000
treeherdermozilla-release@04778346a3b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs668154
milestone8.0a1
backs outf2390732b6a4ab55a7030e58c5a85d8e8893bc65
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
Backout f2390732b6a4 (Bug 668154) for apparently turning debug mochitest-oth & mochitest-4 perma-orange
content/html/content/test/test_bug500885.html
content/html/content/test/test_bug592802.html
layout/forms/test/bug536567_subframe.html
layout/forms/test/test_bug36619.html
layout/forms/test/test_bug377624.html
layout/forms/test/test_bug536567.html
testing/mochitest/MockFilePicker.jsm
testing/mochitest/jar.mn
testing/mochitest/specialpowers/content/specialpowers.js
toolkit/content/tests/browser/browser_save_resend_postdata.js
toolkit/content/tests/browser/common/Makefile.in
toolkit/content/tests/browser/common/_loadAll.js
toolkit/content/tests/browser/common/mockFilePicker.js
toolkit/content/tests/browser/common/toolkitFunctions.js
toolkit/mozapps/downloads/tests/Makefile.in
toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
toolkit/mozapps/extensions/test/browser/browser_bug567127.js
toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
--- a/content/html/content/test/test_bug500885.html
+++ b/content/html/content/test/test_bug500885.html
@@ -3,33 +3,62 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=500885
 -->
 <head>
   <title>Test for Bug 500885</title>
   <script type="text/javascript" src="/MochiKit/packed.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=500885">Mozilla Bug 500885</a>
 <div>
   <input id="file" type="file" />
 </div>
 <script type="text/javascript">
 
-var MockFilePicker = SpecialPowers.MockFilePicker;
-MockFilePicker.reset();
-MockFilePicker.returnValue = MockFilePicker.returnOK;
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-var wu = SpecialPowers.DOMWindowUtils;
+function MockFilePicker() { };
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+  init: function(aParent, aTitle, aMode) { },
+  appendFilters: function(aFilterMask) { },
+  appendFilter: function(aTitle, aFilter) { },
+  defaultString: "",
+  defaultExtension: "",
+  filterIndex: 0,
+  displayDirectory: null,
+  file: null,
+  get fileURL() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  get files() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  show: function MFP_show() {
+    return Ci.nsIFilePicker.returnOK;
+  }
+};
+
+var mockFilePickerRegisterer = 
+  new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
 
 function test() {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                  .getInterface(Ci.nsIDOMWindowUtils);
+                  
+
+  mockFilePickerRegisterer.register();
   try {
     var domActivateEvents;
     var fileInput = document.getElementById("file");
     var rect = fileInput.getBoundingClientRect();
 
     fileInput.addEventListener ("DOMActivate", function (e) {
       ok("detail" in e, "DOMActivate should have .detail!");
       is(e.detail, 1, "detail should be 1!");
@@ -42,20 +71,27 @@ function test() {
     is(domActivateEvents, 1, "click on text field should only fire 1 DOMActivate event");
 
     domActivateEvents = 0;
     wu.sendMouseEvent("mousedown", rect.right - 5, rect.top + 5, 0, 1, 0);
     wu.sendMouseEvent("mouseup", rect.right - 5, rect.top + 5, 0, 1, 0);
     is(domActivateEvents, 1, "click on button should only fire 1 DOMActivate event");
 
   } finally {
-    SimpleTest.finish();
+    SimpleTest.executeSoon(unregister);
+    
   }
 }
 
+function unregister()
+{
+  mockFilePickerRegisterer.unregister();
+  SimpleTest.finish();
+}
+
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
   setTimeout(test, 0);
 };
 
 </script>
 </body>
 
--- a/content/html/content/test/test_bug592802.html
+++ b/content/html/content/test/test_bug592802.html
@@ -3,16 +3,17 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=592802
 -->
 <head>
   <title>Test for Bug 592802</title>
   <script type="application/javascript" src="/MochiKit/packed.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=592802">Mozilla Bug 592802</a>
 <p id="display"></p>
 <div id="content">
   <input id='a' type='file'>
   <input id='a2' type='file'>
@@ -21,53 +22,169 @@ https://bugzilla.mozilla.org/show_bug.cg
 <button id='b2' onclick="document.getElementById('a2').click();">Show Filepicker</button>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 592802 **/
 
 SimpleTest.waitForExplicitFinish();
 
-var MockFilePicker = SpecialPowers.MockFilePicker;
-MockFilePicker.reset();
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function simpleEnumerator(items)
+{
+  this._items = items;
+  this._nextIndex = 0;
+}
+
+simpleEnumerator.prototype = {
+  QueryInterface: function(aIID)
+  {
+    if (Ci.nsISimpleEnumerator.equals(aIID) ||
+        Ci.nsISupports.equals(aIID)) {
+      return this;
+    }
+
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  },
+
+  hasMoreElements: function()
+  {
+    return this._nextIndex < this._items.length;
+  },
+
+  getNext: function()
+  {
+    if (!this.hasMoreElements()) {
+      throw Cr.NS_ERROR_FAILURE;
+    }
+
+    return this._items[this._nextIndex++];
+  }
+};
+
+function MockFilePicker()
+{
+}
+
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  // Constants
+  returnOK: 0, // the user hits OK (select a file)
+  returnCancel: 1, // the user cancel the file selection
+  returnReplace: 2, // the user replace the selection
+
+  // Properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) { },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  get file() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+    var fileName = "592808_file";
+    var fileData = "file content";
+
+    var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
+                           .getService(Components.interfaces.nsIProperties);
+    var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
+    testFile.append(fileName);
+    var outStream = Components.
+                    classes["@mozilla.org/network/file-output-stream;1"].
+                    createInstance(Components.interfaces.nsIFileOutputStream);
+    outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
+                   0666, 0);
+    outStream.write(fileData, fileData.length);
+    outStream.close();
+
+    return testFile;
+  },
+
+  get files() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+    var fileName = "592808_file";
+    var fileData = "file content";
+
+    var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
+                           .getService(Components.interfaces.nsIProperties);
+    var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
+    testFile.append(fileName);
+    var outStream = Components.
+                    classes["@mozilla.org/network/file-output-stream;1"].
+                    createInstance(Components.interfaces.nsIFileOutputStream);
+    outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
+                   0666, 0);
+    outStream.write(fileData, fileData.length);
+    outStream.close();
+
+    return new simpleEnumerator([testFile]);
+  },
+
+  appendFilter: function(val) {},
+
+  appendFilters: function(val) {},
+
+  init: function() {},
+
+  show: function()
+  {
+    if (firstFilePickerShow) {
+      firstFilePickerShow = false;
+      return this.returnCancel;
+    } else {
+      return this.returnOK;
+    }
+  }
+};
+
+var mockFilePickerRegisterer =
+  new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
+
+mockFilePickerRegisterer.register();
 
 var testData = [
 /* visibility | display | multiple */
   [ "",       "",     false ],
   [ "hidden", "",     false ],
   [ "",       "none", false ],
   [ "",       "",     true ],
   [ "hidden", "",     true ],
   [ "",       "none", true ],
 ];
 
 var testCounter = 0;
 var testNb = testData.length;
 
+var firstFilePickerShow = true;
+
 function finished()
 {
+  mockFilePickerRegisterer.unregister();
+
   SimpleTest.finish();
 }
 
 SimpleTest.waitForFocus(function() {
   // mockFilePicker will simulate a cancel for the first time the file picker will be shown.
-  MockFilePicker.returnValue = MockFilePicker.returnCancel;
-
   var b2 = document.getElementById('b2');
   b2.focus(); // Be sure the element is visible.
   document.getElementById('b2').addEventListener("change", function(aEvent) {
     aEvent.target.removeEventListener("change", arguments.callee, false);
     ok(false, "When cancel is received, change should not fire");
   }, false);
-  b2.click();
+  synthesizeMouse(b2, 2, 2, {});
 
   // Now, we can launch tests when file picker isn't canceled.
-  MockFilePicker.useAnyFile();
-  MockFilePicker.returnValue = MockFilePicker.returnOK;
-
   var b = document.getElementById('b');
   b.focus(); // Be sure the element is visible.
 
   document.getElementById('a').addEventListener("change", function(aEvent) {
     ok(true, "change event correctly sent");
     ok(aEvent.bubbles, "change event should bubble");
     ok(!aEvent.cancelable, "change event should not be cancelable");
     testCounter++;
@@ -78,20 +195,20 @@ SimpleTest.waitForFocus(function() {
     } else {
       var data = testData[testCounter];
       var a = document.getElementById('a');
       a.style.visibility = data[0];
       a.style.display = data[1];
       a.multiple = data[2];
 
       SimpleTest.executeSoon(function() {
-        b.click();
+        synthesizeMouse(b, 2, 2, {});
       });
     }
   }, false);
 
-  b.click();
+  synthesizeMouse(b, 2, 2, {});
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/forms/test/bug536567_subframe.html
+++ b/layout/forms/test/bug536567_subframe.html
@@ -1,14 +1,74 @@
 <!DOCTYPE html>
 <html>
+  <head>
+    <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+    <script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
+  </head>
 <body>
 <input id="target" type="file" />
 <script type="text/javascript">
 
-window.onload = function() {
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function MockFilePicker() { };
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+  init: function(aParent, aTitle, aMode) { },
+  appendFilters: function(aFilterMask) { },
+  appendFilter: function(aTitle, aFilter) { },
+  defaultString: "",
+  defaultExtension: "",
+  filterIndex: 0,
+  displayDirectory: null,
+  get file() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    var f = window.parent.dirs[window.parent.index].clone();
+    f.append("aFile.txt");
+    return f;
+  },
+  get fileURL() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  get files() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  show: function MFP_show() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    if (this.displayDirectory)
+      window.parent.postMessage(this.displayDirectory.path, "*");
+    else
+      window.parent.postMessage("", "*");
+    mockFilePickerRegisterer.unregister();  
+    return Ci.nsIFilePicker.returnOK;
+  }
+};
+
+var mockFilePickerRegisterer =
+  new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
+
+function test() {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIDOMWindowUtils);
+
   var fileInput = document.getElementById("target");
-  fileInput.click();
+  var rect = fileInput.getBoundingClientRect();
+
+  mockFilePickerRegisterer.register();
+  try {
+    wu.sendMouseEvent("mousedown", rect.left + 5, rect.top + 5, 0, 1, 0);
+    wu.sendMouseEvent("mouseup", rect.left + 5, rect.top + 5, 0, 1, 0);
+  } catch (e) {
+    Cu.reportError(e);
+  } finally {
+  }
+}
+
+window.onload = function() {
+  setTimeout(test, 0);
 };
 
 </script>
 </body>
 </html>
--- a/layout/forms/test/test_bug36619.html
+++ b/layout/forms/test/test_bug36619.html
@@ -3,55 +3,103 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=36619
 -->
 <head>
   <title>Test for Bug 36619</title>
   <script type="application/javascript" src="/MochiKit/packed.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/mockObjects.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=36619">Mozilla Bug 36619</a>
 <p id="display"></p>
 <div id="content" style="display:none;">
   <input id='a' type='file'>
 </div>
 <button id='b' onclick="document.getElementById('a').click();">Show Filepicker</button>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 36619 **/
 
 SimpleTest.waitForExplicitFinish();
 
-var MockFilePicker = SpecialPowers.MockFilePicker;
-MockFilePicker.reset();
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function MockFilePicker()
+{
+}
+
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  // properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) { },
+  file: null,
+  get files() { return null; },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  // methods
+  appendFilter: function(val)
+  {
+  },
+
+  appendFilters: function(val)
+  {
+  },
+
+  init: function() {
+  },
+
+  show: function()
+  {
+    shown = true;
+  }
+};
+
+var mockFilePickerRegisterer =
+  new MockObjectRegisterer("@mozilla.org/filepicker;1",MockFilePicker);
+
+mockFilePickerRegisterer.register();
 
 // enable popups the first time
-var oldAllow = SpecialPowers.getBoolPref("dom.disable_open_during_load");
-var oldShowBar = SpecialPowers.getBoolPref("privacy.popups.showBrowserMessage");
-SpecialPowers.setBoolPref("dom.disable_open_during_load", true);
-SpecialPowers.setBoolPref("privacy.popups.showBrowserMessage", false);
+var pbi = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
+var oldAllow = pbi.getBoolPref("dom.disable_open_during_load");
+var oldShowBar = pbi.getBoolPref("privacy.popups.showBrowserMessage");
+pbi.setBoolPref("dom.disable_open_during_load", true);
+pbi.setBoolPref("privacy.popups.showBrowserMessage", false);
+
+var shown = false;
 
 function checkFirst()
 {
-  ok(MockFilePicker.shown, "File picker show method should have been called");
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  ok(shown, "File picker show method should have been called");
+  shown = false;
   document.getElementById("a").click();
   setTimeout(finishTest, 1000);
 }
 
 function finishTest()
 {
-  MockFilePicker.reset();
-  ok(!MockFilePicker.shown, "File picker show method should not have been called");
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  ok(!shown, "File picker show method should not have been called");
 
-  SpecialPowers.setBoolPref("dom.disable_open_during_load", oldAllow);
-  SpecialPowers.setBoolPref("privacy.popups.showBrowserMessage", oldShowBar);
+  mockFilePickerRegisterer.unregister();
+
+  pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
+  pbi.setBoolPref("privacy.popups.showBrowserMessage", oldShowBar);
   SimpleTest.finish();
 }
 
 SimpleTest.waitForFocus(function() {
   var b = document.getElementById('b');
   b.focus(); // Be sure the element is visible.
   synthesizeMouse(b, 2, 2, {});
   SimpleTest.executeSoon(checkFirst);
--- a/layout/forms/test/test_bug377624.html
+++ b/layout/forms/test/test_bug377624.html
@@ -28,86 +28,206 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 377624 **/
 
 SimpleTest.waitForExplicitFinish();
 
-var MockFilePicker = SpecialPowers.MockFilePicker;
-MockFilePicker.reset();
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+const Cu = Components.utils;
+
+const FILE_PICKER_CID = "@mozilla.org/filepicker;1";
+const FILE_PICKER_ID = Components.ID(Cc[FILE_PICKER_CID].number);
+const CUSTOM_FILE_PICKER_ID = Components.ID("d63dee33-fb6d-4547-a8d1-c12197655cce");
+const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 // disable popups to make sure that the popup blocker does not interfere
 // with manually opened file pickers.
-var oldAllow = SpecialPowers.getBoolPref("dom.disable_open_during_load");
-SpecialPowers.setBoolPref("dom.disable_open_during_load", false);
+var pbi = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
+var oldAllow = pbi.getBoolPref("dom.disable_open_during_load");
+pbi.setBoolPref("dom.disable_open_during_load", true);
+
+function FilePickerService()
+{
+}
+
+FilePickerService.prototype = {
+  _obs: Cc["@mozilla.org/observer-service;1"].
+        getService(Ci.nsIObserverService),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  // constants
+  modeOpen: 0,
+  modeSave: 1,
+  modeGetFolder: 2,
+  modeOpenMultiple: 3,
+  returnOK: 0,
+  returnCancel: 1,
+  returnReplace: 2,
+  filterAll: 1,
+  filterHTML: 2,
+  filterText: 4,
+  filterImages: 8,
+  filterXML: 16,
+  filterXUL: 32,
+  filterApps: 64,
+  filterAllowURLs: 128,
+  filterAudio: 256,
+  filterVideo: 512,
 
-var testData = [["a", MockFilePicker.filterImages, 1],
-                ["b", MockFilePicker.filterAudio, 1],
-                ["c", MockFilePicker.filterVideo, 1],
+  // properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) { },
+  file: null,
+  get files() { return null; },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  // methods
+  appendFilter: function(val)
+  {
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTER", val);
+  },
+
+  appendFilters: function(val)
+  {
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTERS", val);
+  },
+
+  init: function() {},
+
+  show: function()
+  {
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_SHOW", this.filterIndex);
+    return this.returnOK;
+  }
+};
+
+factory = {
+  createInstance: function(aOuter, aIid) {
+    if (aOuter != null)
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    return new FilePickerService().QueryInterface(aIid);
+  }
+};
+
+var testData = [["a", FilePickerService.prototype.filterImages, 1],
+                ["b", FilePickerService.prototype.filterAudio, 1],
+                ["c", FilePickerService.prototype.filterVideo, 1],
                 ["d", 0, 0],
                 ["e", 0, 0],
                 ["f", 0, 0],
                 ["g", 0, 0],
-                ["h", MockFilePicker.filterImages, 1],
-                ["i", MockFilePicker.filterVideo, 1],
-                ["j", MockFilePicker.filterAudio, 1],
+                ["h", FilePickerService.prototype.filterImages, 1],
+                ["i", FilePickerService.prototype.filterVideo, 1],
+                ["j", FilePickerService.prototype.filterAudio, 1],
                 ["z", 0, 0]];
 
+testData.forEach(function (datum) {
+document.getElementById(datum[0]).addEventListener("focus", function (aEvent) {
+    aEvent.target.removeEventListener("focus", arguments.callee, false);
+    synthesizeKey('VK_SPACE', {});
+  }, false);
+});
+
 var currentTest = 0;
-var appendFilterCalled;
-var filters;
-var filterIndex;
 
-function launchNextTest()
+function launchNextTest(aObserver)
 {
-  MockFilePicker.shown = false;
-  appendFilterCalled = false;
-  filters = [];
-  filterIndex = 0;
+  aObserver.shown = false;
+  aObserver.appendFilterCalled = false;
+  aObserver.filters = [];
+  aObserver.filterIndex = 0;
 
-  document.getElementById(testData[currentTest][0]).click();
+  document.getElementById(testData[currentTest][0]).focus();
 }
 
 function runTests()
 {
-  MockFilePicker.appendFilterCallback = function(filepicker, title, val)
-  {
-    this.appendFilterCalled = true;
-  };
-  MockFilePicker.appendFiltersCallback = function(filepicker, val)
-  {
-    filters.push(val);
-  };
-  MockFilePicker.showCallback = function(filepicker)
-  {
-    filterIndex = filepicker.filterIndex;
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+  Cm.registerFactory(CUSTOM_FILE_PICKER_ID,
+                     FILE_PICKER_DESCRIPTION,
+                     FILE_PICKER_CID,
+                     factory);
+
+  var obs = Cc["@mozilla.org/observer-service;1"].
+            getService(Ci.nsIObserverService);
+
+  var observer = {
+    observe: function(aSubject, aTopic, aData) {
+      switch (aTopic) {
+        case "TEST_FILEPICKER_APPENDFILTER":
+          this.appendFilterCalled = true;
+          break;
+        case "TEST_FILEPICKER_APPENDFILTERS":
+          this.filters.push(aData);
+          break;
+        case "TEST_FILEPICKER_SHOW":
+          this.shown = true;
+          this.filterIndex = aData;
+
+          SimpleTest.executeSoon(function () {
+            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
-    SimpleTest.executeSoon(function () {
-      ok(MockFilePicker.shown,
-         "File picker show method should have been called");
-      ok(!appendFilterCalled,
-         "appendFilter should not have been called");
-      is(filters.length, 1,
-         "appendFilters should have been called once");
-      is(filters[0], MockFilePicker.filterAll +
-         testData[currentTest][1],
-         "Correct filters should have been added");
-      is(filterIndex, testData[currentTest][2],
-         "File picker should show the correct filter index");
+            ok(observer.shown,
+               "File picker show method should have been called");
+            ok(!observer.appendFilterCalled,
+               "appendFilter should not have been called");
+            is(observer.filters.length, 1,
+               "appendFilters should have been called once");
+            is(observer.filters[0], FilePickerService.prototype.filterAll +
+               testData[currentTest][1],
+               "Correct filters should have been added");
+            is(observer.filterIndex, testData[currentTest][2],
+               "File picker should show the correct filter index");
+
+            if (++currentTest == testData.length) {
+              obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
+              obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
+              obs.removeObserver(observer, "TEST_FILEPICKER_SHOW", false);
+              Cm.unregisterFactory(CUSTOM_FILE_PICKER_ID, factory);
 
-      if (++currentTest == testData.length) {
-        SpecialPowers.setBoolPref("dom.disable_open_during_load", oldAllow);
-        SimpleTest.finish();
-      } else {
-        launchNextTest();
+              Cm.registerFactory(FILE_PICKER_ID,
+                                 "File Picker Service",
+                                 FILE_PICKER_CID,
+                                 null);
+                                 
+              pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
+              SimpleTest.finish();
+            } else {
+              launchNextTest(observer);
+            }
+          } );
+          break;
       }
-    } );
+    },
+    shown: false,
+    appendFilterCalled: false,
+    filters: [],
+    filterIndex: 0
   };
 
-  launchNextTest();
+  obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
+  obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
+  obs.addObserver(observer, "TEST_FILEPICKER_SHOW", false);
+
+  // We are simulating a focus then a SPACE key press to open the file picker.
+  // We were not able to do this with |synthesizeMouse|.
+  launchNextTest(observer);
 }
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/forms/test/test_bug536567.html
+++ b/layout/forms/test/test_bug536567.html
@@ -3,48 +3,47 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=536567
 -->
 <head>
   <title>Test for Bug 536567</title>
   <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a>
 <p id="display"></p>
 <iframe id="content"></iframe>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 536567 **/
 
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cm = Components.manager;
 
-Cu.import("resource://mochikit/MockFilePicker.jsm");
-MockFilePicker.reset();
-
 var ioSvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
 var prefSvc = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 var obSvc = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
 if ("@mozilla.org/privatebrowsing;1" in Cc) {
   var pbSvc = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
 }
 
 var tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile);
 var homeDir = dirSvc.get("Desk", Ci.nsILocalFile);
 prefSvc.setBoolPref("browser.privatebrowsing.keep_current_session", true);
 
 function newDir() {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
   var dir = tmpDir.clone();
   dir.append("testdir" + Math.floor(Math.random() * 10000));
   dir.QueryInterface(Ci.nsILocalFile);
   dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
   return dir;
 }
 
 var dirs = [];
@@ -92,16 +91,17 @@ var tests = [
   [2, 3, 3], //-> x
   "clear history",
   [0, 6, 0],
   [1, 6, 1],
   [2, 6, 2],
   "pb off"
 ];
 
+var index;
 var testIndex = 0;
 var content = document.getElementById('content');
 
 function runTest() {
   var test = tests[testIndex];
   if (test == undefined) {
     endTest();
   } else if (test == "pb on") {
@@ -117,52 +117,50 @@ function runTest() {
     pbSvc.privateBrowsingEnabled = false;
     testIndex++;
     runTest();
   } else if (test == "clear history") {
     obSvc.notifyObservers(null, "browser:purge-session-history", "");
     testIndex++;
     runTest();
   } else {
-    var file = dirs[test[2]].clone();
-    file.append("file.file");
-    MockFilePicker.returnFiles = [file];
+    index = test[2];
     content.setAttribute ('src', domains[test[0]] + '/tests/layout/forms/test/bug536567_subframe.html');
   }
 }
 
 function endTest() {
     prefSvc.clearUserPref("browser.privatebrowsing.keep_current_session");
     for(var i = 0; i < dirs.length - 1; i++) {
       dirs[i].remove(true);
     }
 
     SimpleTest.finish();
 }
 
-MockFilePicker.showCallback = function(filepicker) {
+window.addEventListener("message", function(event) {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
   var test = tests[testIndex];
   var returned = -1;
   for (var i = 0; i < dirs.length; i++) {
-    if (dirs[i].path == MockFilePicker.displayDirectory.path) {
+    if (dirs[i].path == event.data) {
       returned = i;
       break;
     }
   }
   if (test[1] == -1) {
     ok(false, "We should never get an unknown directory back");
   } else {
     is(returned, test[1], 'test ' + testIndex);
   }
-
-  SimpleTest.executeSoon(function() {
-    testIndex++;
-    runTest();
-  });
-};
+  
+  testIndex++;
+  runTest();
+}, false);
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
   setTimeout(runTest, 0);
 };
 
 </script>
 </pre>
deleted file mode 100644
--- a/testing/mochitest/MockFilePicker.jsm
+++ /dev/null
@@ -1,136 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mochitest Reusable Mock File Picker.
- *
- * The Initial Developer of the Original Code is
- * Geoff Lankow <geoff@darktrojan.net>.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** */
-
-var EXPORTED_SYMBOLS = ["MockFilePicker"];
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cm = Components.manager;
-const Cu = Components.utils;
-
-const CONTRACT_ID = "@mozilla.org/filepicker;1";
-const CLASS_ID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
-
-Cu.import("resource://gre/modules/FileUtils.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
-var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-
-var MockFilePickerFactory = {
-  createInstance: function(aOuter, aIID) {
-    if (aOuter)
-      throw Components.results.NS_ERROR_NO_AGGREGATION;
-    return new MockFilePickerInstance().QueryInterface(aIID);
-  },
-  lockFactory: function(aLock) {
-    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-  },
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
-};
-
-var MockFilePicker = {
-  returnOK: Ci.nsIFilePicker.returnOK,
-  returnCancel: Ci.nsIFilePicker.returnCancel,
-  returnReplace: Ci.nsIFilePicker.returnReplace,
-
-  filterAll: Ci.nsIFilePicker.filterAll,
-  filterHTML: Ci.nsIFilePicker.filterHTML,
-  filterText: Ci.nsIFilePicker.filterText,
-  filterImages: Ci.nsIFilePicker.filterImages,
-  filterXML: Ci.nsIFilePicker.filterXML,
-  filterXUL: Ci.nsIFilePicker.filterXUL,
-  filterApps: Ci.nsIFilePicker.filterApps,
-  filterAllowURLs: Ci.nsIFilePicker.filterAllowURLs,
-  filterAudio: Ci.nsIFilePicker.filterAudio,
-  filterVideo: Ci.nsIFilePicker.filterVideo,
-
-  reset: function() {
-    this.appendFilterCallback = null;
-    this.appendFiltersCallback = null;
-    this.displayDirectory = null;
-    this.mode = null;
-    this.returnFiles = [];
-    this.returnValue = null;
-    this.showCallback = null;
-    this.shown = false;
-    if (!registrar.isCIDRegistered(CLASS_ID))
-      registrar.registerFactory(CLASS_ID, "", CONTRACT_ID, MockFilePickerFactory);
-  },
-
-  useAnyFile: function() {
-    var file = FileUtils.getFile("TmpD", ["testfile"]);
-    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
-    this.returnFiles = [file];
-  }
-};
-
-function MockFilePickerInstance() { };
-MockFilePickerInstance.prototype = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
-  init: function(aParent, aTitle, aMode) {
-    MockFilePicker.mode = aMode;
-  },
-  appendFilter: function(aTitle, aFilter) {
-    if (typeof MockFilePicker.appendFilterCallback == "function")
-      MockFilePicker.appendFilterCallback(this, aTitle, aFilter);
-  },
-  appendFilters: function(aFilterMask) {
-    if (typeof MockFilePicker.appendFiltersCallback == "function")
-      MockFilePicker.appendFiltersCallback(this, aFilterMask);
-  },
-  defaultString: "",
-  defaultExtension: "",
-  filterIndex: 0,
-  displayDirectory: null,
-  get file() {
-    if (MockFilePicker.returnFiles.length >= 1)
-      return MockFilePicker.returnFiles[0];
-    return null;
-  },
-  get fileURL() {
-    if (MockFilePicker.returnFiles.length >= 1)
-      return Services.io.newFileURI(MockFilePicker.returnFiles[0]);
-    return null;
-  },
-  get files() {
-    return {
-      index: 0,
-      QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
-      hasMoreElements: function() {
-        return this.index < MockFilePicker.returnFiles.length;
-      },
-      getNext: function() {
-        return MockFilePicker.returnFiles[this.index++];
-      }
-    };
-  },
-  show: function() {
-    MockFilePicker.displayDirectory = this.displayDirectory;
-    MockFilePicker.shown = true;
-    if (typeof MockFilePicker.showCallback == "function")
-      MockFilePicker.showCallback(this);
-    return MockFilePicker.returnValue;
-  }
-};
--- a/testing/mochitest/jar.mn
+++ b/testing/mochitest/jar.mn
@@ -23,10 +23,8 @@ mochikit.jar:
   content/tests/SimpleTest/test.css (tests/SimpleTest/test.css)
   content/tests/SimpleTest/TestRunner.js (tests/SimpleTest/TestRunner.js)
   content/tests/SimpleTest/WindowSnapshot.js (tests/SimpleTest/WindowSnapshot.js)
   content/tests/SimpleTest/mockObjects.js (../../toolkit/content/tests/browser/common/mockObjects.js)
   content/tests/SimpleTest/docshell_helpers.js (../..//docshell/test/chrome/docshell_helpers.js)
 
   content/MochiKit/packed.js (MochiKit/packed.js)
 
-% resource mochikit %modules/
-  modules/MockFilePicker.jsm (MockFilePicker.jsm)
--- a/testing/mochitest/specialpowers/content/specialpowers.js
+++ b/testing/mochitest/specialpowers/content/specialpowers.js
@@ -33,23 +33,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK *****/
 /* This code is loaded in every child process that is started by mochitest in
  * order to be used as a replacement for UniversalXPConnect
  */
 
+var Ci = Components.interfaces;
 var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-
-var MockFilePicker;
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function SpecialPowers(window) {
   this.window = window;
   bindDOMWindowUtils(this, window);
   this._encounteredCrashDumpFiles = [];
   this._unexpectedCrashDumpFiles = { };
   this._crashDumpDir = null;
   this._pongHandlers = [];
@@ -311,22 +306,16 @@ SpecialPowers.prototype = {
     Components.classes["@mozilla.org/eventlistenerservice;1"].
       getService(Components.interfaces.nsIEventListenerService).
       addSystemEventListener(target, type, listener, useCapture);
   },
   removeSystemEventListener: function(target, type, listener, useCapture) {
     Components.classes["@mozilla.org/eventlistenerservice;1"].
       getService(Components.interfaces.nsIEventListenerService).
       removeSystemEventListener(target, type, listener, useCapture);
-  },
-
-  get MockFilePicker() {
-    if (!MockFilePicker)
-      Cu.import("resource://mochikit/MockFilePicker.jsm");
-    return MockFilePicker;
   }
 };
 
 // Expose everything but internal APIs (starting with underscores) to
 // web content.
 SpecialPowers.prototype.__exposedProps__ = {};
 for each (i in Object.keys(SpecialPowers.prototype).filter(function(v) {return v.charAt(0) != "_";})) {
   SpecialPowers.prototype.__exposedProps__[i] = "r";
--- a/toolkit/content/tests/browser/browser_save_resend_postdata.js
+++ b/toolkit/content/tests/browser/browser_save_resend_postdata.js
@@ -29,19 +29,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-Components.utils.import("resource://mochikit/MockFilePicker.jsm");
-MockFilePicker.reset();
-
 /**
  * Test for bug 471962 <https://bugzilla.mozilla.org/show_bug.cgi?id=471962>:
  * When saving an inner frame as file only, the POST data of the outer page is
  * sent to the address of the inner page.
  *
  * Test for bug 485196 <https://bugzilla.mozilla.org/show_bug.cgi?id=485196>:
  * Web page generated by POST is retried as GET when Save Frame As used, and the
  * page is no longer in the cache.
@@ -108,38 +105,37 @@ function test() {
         // Remove the event listener, even if an exception occurred for any
         // reason (for example, the requested element does not exist). 
         gBrowser.removeEventListener("DOMContentLoaded",
                                      testRunner.continueTest, false);
       }
 
       // Create the folder the page will be saved into.
       var destDir = createTemporarySaveDirectory();
-      var file = destDir.clone();
-      file.append("no_default_file_name");
-      MockFilePicker.returnFiles = [file];
       try {
         // Call the appropriate save function defined in contentAreaUtils.js.
+        mockFilePickerSettings.destDir = destDir;
+        mockFilePickerSettings.filterIndex = 1; // kSaveAsType_URL
         callSaveWithMockObjects(function() {
           var docToSave = innerFrame.contentDocument;
           // We call internalSave instead of saveDocument to bypass the history
           // cache.
           internalSave(docToSave.location.href, docToSave, null, null,
                        docToSave.contentType, false, null, null,
                        docToSave.referrer ? makeURI(docToSave.referrer) : null,
                        false, null);
         });
 
         // Wait for the download to finish, and exit if it wasn't successful.
         var downloadSuccess = yield;
         if (!downloadSuccess)
           throw "Unexpected failure, the inner frame couldn't be saved!";
 
         // Read the entire saved file.
-        var fileContents = readShortFile(file);
+        var fileContents = readShortFile(mockFilePickerResults.selectedFile);
 
         // Check if outer POST data is found (bug 471962).
         ok(fileContents.indexOf("inputfield=outer") === -1,
            "The saved inner frame does not contain outer POST data");
 
         // Check if inner POST data is found (bug 485196).
         ok(fileContents.indexOf("inputfield=inner") > -1,
            "The saved inner frame was generated using the correct POST data");
--- a/toolkit/content/tests/browser/common/Makefile.in
+++ b/toolkit/content/tests/browser/common/Makefile.in
@@ -42,16 +42,17 @@ VPATH          = @srcdir@
 relativesrcdir = toolkit/content/tests/browser/common
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 # If you add files here, add them to "_loadAll.js" too.
 _COMMON_FILES = \
   _loadAll.js \
+  mockFilePicker.js \
   mockObjects.js \
   mockTransferForContinuing.js \
   testRunner.js \
   toolkitFunctions.js \
   $(NULL)
 
 libs:: $(_COMMON_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
--- a/toolkit/content/tests/browser/common/_loadAll.js
+++ b/toolkit/content/tests/browser/common/_loadAll.js
@@ -51,16 +51,17 @@ void(function (scriptScope) {
   const kBaseUrl = rootDir + "common/";
 
   // If you add files here, add them to "Makefile.in" too.
   var scriptNames = [
     "mockObjects.js",
     "testRunner.js",
 
     // To be included after the files above.
+    "mockFilePicker.js",
     "mockTransferForContinuing.js",
     "toolkitFunctions.js",
   ];
 
   // Include all the required scripts.
   var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                      getService(Ci.mozIJSSubScriptLoader);
   for (let [, scriptName] in Iterator(scriptNames)) {
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/common/mockFilePicker.js
@@ -0,0 +1,116 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla XUL Toolkit Testing Code.
+ *
+ * The Initial Developer of the Original Code is
+ * Paolo Amadini <http://www.amadzone.org/>.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var mockFilePickerSettings = {
+  /**
+   * File object pointing to the directory where the files will be saved.
+   * The files will be saved with the default name, and will be overwritten
+   * if they exist.
+   */
+  destDir: null,
+
+  /**
+   * Index of the filter to be returned by the file picker, or -1 to return
+   * the filter proposed by the caller.
+   */
+  filterIndex: -1
+};
+
+var mockFilePickerResults = {
+  /**
+   * File object corresponding to the last automatically selected file.
+   */
+  selectedFile: null,
+
+  /**
+   * Index of the filter that was set on the file picker by the caller.
+   */
+  proposedFilterIndex: -1
+};
+
+/**
+ * This file picker implementation uses the global settings defined in
+ * mockFilePickerSettings, and updates the mockFilePickerResults object
+ * when its "show" method is called.
+ */
+function MockFilePicker() { };
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+  init: function(aParent, aTitle, aMode) { },
+  appendFilters: function(aFilterMask) { },
+  appendFilter: function(aTitle, aFilter) { },
+  defaultString: "",
+  defaultExtension: "",
+  filterIndex: 0,
+  displayDirectory: null,
+  file: null,
+  get fileURL() {
+    return Cc["@mozilla.org/network/io-service;1"].
+           getService(Ci.nsIIOService).newFileURI(this.file);
+  },
+  get files() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  show: function MFP_show() {
+    // Select the destination file with the specified default file name. If the
+    // default file name was never specified or was set to an empty string by
+    // the caller, ensure that a fallback file name is used.
+    this.file = mockFilePickerSettings.destDir.clone();
+    this.file.append(this.defaultString || "no_default_file_name");
+    // Store the current file picker settings for testing them later.
+    mockFilePickerResults.selectedFile = this.file.clone();
+    mockFilePickerResults.proposedFilterIndex = this.filterIndex;
+    // Select a different file filter if required.
+    if (mockFilePickerSettings.filterIndex != -1)
+      this.filterIndex = mockFilePickerSettings.filterIndex;
+    // Assume we overwrite the file if it exists.
+    return (this.file.exists() ?
+            Ci.nsIFilePicker.returnReplace :
+            Ci.nsIFilePicker.returnOK);
+  }
+};
+
+// Create an instance of a MockObjectRegisterer whose methods can be used to
+// temporarily replace the default "@mozilla.org/filepicker;1" object factory
+// with one that provides the mock implementation above. To activate the mock
+// object factory, call the "register" method. Starting from that moment, all
+// the file picker objects that are requested will be mock objects, until the
+// "unregister" method is called.
+var mockFilePickerRegisterer =
+  new MockObjectRegisterer("@mozilla.org/filepicker;1",
+                           MockFilePicker);
--- a/toolkit/content/tests/browser/common/toolkitFunctions.js
+++ b/toolkit/content/tests/browser/common/toolkitFunctions.js
@@ -59,22 +59,28 @@ function createTemporarySaveDirectory() 
  *        The function to call. This is usually the subject of the entire test
  *        being run.
  */
 function callSaveWithMockObjects(aSaveFunction) {
   // Call the provided function while the mock object factories are in place and
   // ensure that, even in case of exceptions during the function's execution,
   // the mock object factories are unregistered before proceeding with the other
   // tests in the suite.
-  mockTransferForContinuingRegisterer.register();
+  mockFilePickerRegisterer.register();
   try {
-    aSaveFunction();
+    mockTransferForContinuingRegisterer.register();
+    try {
+      aSaveFunction();
+    }
+    finally {
+      mockTransferForContinuingRegisterer.unregister();
+    }
   }
   finally {
-    mockTransferForContinuingRegisterer.unregister();
+    mockFilePickerRegisterer.unregister();
   }
 }
 
 /**
  * Reads the contents of the provided short file (up to 1 MiB).
  *
  * @param aFile
  *        nsIFile object pointing to the file to be read.
--- a/toolkit/mozapps/downloads/tests/Makefile.in
+++ b/toolkit/mozapps/downloads/tests/Makefile.in
@@ -49,11 +49,8 @@ MODULE = test_downloads
 
 XPCSHELL_TESTS = \
   unit \
   $(NULL)
 
 DIRS += chrome
 
 include $(topsrcdir)/config/rules.mk
-
-libs:: 
-	$(INSTALL) $(topsrcdir)/testing/mochitest/MockFilePicker.jsm $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit
--- a/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
+++ b/toolkit/mozapps/downloads/tests/unit/test_privatebrowsing_downloadLastDir.js
@@ -35,16 +35,21 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cu = Components.utils;
 const Cr = Components.results;
+const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+
+const FILE_PICKER_CID = "@mozilla.org/filepicker;1";
+const FILE_PICKER_ID = Components.ID("fa71ce55-6524-4744-ba75-71a4c126cfa3");
+const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
 
 // Code borrowed from toolkit/components/downloadmgr/test/unit/head_download_manager.js
 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties);
 var profileDir = null;
 try {
   profileDir = dirSvc.get("ProfD", Ci.nsIFile);
 } catch (e) { }
@@ -72,41 +77,105 @@ if (!profileDir) {
       throw Cr.NS_ERROR_NO_INTERFACE;
     }
   };
   dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
 }
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/DownloadLastDir.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
 let context = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIInterfaceRequestor]),
   getInterface: XPCOMUtils.generateQI([Ci.nsIDOMWindowInternal])
 };
 
-Cu.import("resource://test/MockFilePicker.jsm");
-MockFilePicker.reset();
-MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
+function FilePickerService() {
+}
+
+FilePickerService.prototype = {
+  _obs: Cc["@mozilla.org/observer-service;1"].
+        getService(Ci.nsIObserverService),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  // constants
+  modeOpen: 0,
+  modeSave: 1,
+  modeGetFolder: 2,
+  modeOpenMultiple: 3,
+  returnOK: 0,
+  returnCancel: 1,
+  returnReplace: 2,
+  filterAll: 1,
+  filterHTML: 2,
+  filterText: 4,
+  filterImages: 8,
+  filterXML: 16,
+  filterXUL: 32,
+  filterApps: 64,
+
+  // properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) {
+    this._obs.notifyObservers(val, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", "");
+  },
+  file: null,
+  get files() { return null; },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  // methods
+  appendFilter: function() {},
+  appendFilters: function() {},
+  init: function() {
+    var fileptr = Cc["@mozilla.org/supports-interface-pointer;1"].
+                  createInstance(Ci.nsISupportsInterfacePointer);
+    this._obs.notifyObservers(fileptr, "TEST_FILEPICKER_GETFILE", "");
+    this.file = fileptr.data.QueryInterface(fileptr.dataIID);
+  },
+  show: function() {
+    return this.returnOK;
+  }
+};
+
+let factory = {
+  createInstance: function(aOuter, aIid) {
+    if (aOuter != null)
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    return new FilePickerService().QueryInterface(aIid);
+  }
+};
 
 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;
   }
 
+  //do_load_module("filepicker.js");
+  Cm.registerFactory(FILE_PICKER_ID,
+                     FILE_PICKER_DESCRIPTION,
+                     FILE_PICKER_CID,
+                     factory);
+
   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 obs = Cc["@mozilla.org/observer-service;1"].
+            getService(Ci.nsIObserverService);
   let launcher = 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));
@@ -121,52 +190,73 @@ function run_test()
   }
   let dir1 = newDirectory();
   let dir2 = newDirectory();
   let dir3 = newDirectory();
   let file1 = newFileInDirectory(dir1);
   let file2 = newFileInDirectory(dir2);
   let file3 = newFileInDirectory(dir3);
 
+  let observer = {
+    observe: function(aSubject, aTopic, aData) {
+      switch (aTopic) {
+      case "TEST_FILEPICKER_GETFILE":
+        let fileptr = aSubject.QueryInterface(Ci.nsISupportsInterfacePointer);
+        fileptr.data = this.file;
+        fileptr.dataIID = Ci.nsILocalFile;
+        break;
+      case "TEST_FILEPICKER_SETDISPLAYDIRECTORY":
+        this.displayDirectory = aSubject.QueryInterface(Ci.nsILocalFile);
+        break;
+      }
+    },
+    file: null,
+    displayDirectory: null
+  };
+  obs.addObserver(observer, "TEST_FILEPICKER_GETFILE", false);
+  obs.addObserver(observer, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", false);
+
   prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir);
 
-  MockFilePicker.returnFiles = [file1];
+  observer.file = file1;
   let file = launcher.promptForSaveToFile(null, context, null, null, null);
   do_check_true(!!file);
   // file picker should start with browser.download.lastDir
-  do_check_eq(MockFilePicker.displayDirectory.path, tmpDir.path);
+  do_check_eq(observer.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;
+  observer.file = file2;
+  observer.displayDirectory = null;
   file = launcher.promptForSaveToFile(null, 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);
+  do_check_eq(observer.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;
+  observer.file = file3;
+  observer.displayDirectory = null;
   file = launcher.promptForSaveToFile(null, 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);
+  do_check_eq(observer.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));
   dirSvc.QueryInterface(Ci.nsIDirectoryService).unregisterProvider(provider);
+  obs.removeObserver(observer, "TEST_FILEPICKER_GETFILE", false);
+  obs.removeObserver(observer, "TEST_FILEPICKER_SETDISPLAYDIRECTORY", false);
 }
--- a/toolkit/mozapps/extensions/test/browser/browser_bug567127.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug567127.js
@@ -1,18 +1,46 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests bug 567127 - Add install button to the add-ons manager
 
-Components.utils.import("resource://mochikit/MockFilePicker.jsm");
-MockFilePicker.reset();
+
+var gFilePickerFiles = [];
+var gMockFilePickerFactory;
+var gMockFilePickerFactoryCID;
+var gManagerWindow;
+
+function MockFilePicker() { }
 
-var gManagerWindow;
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIFilePicker]),
+  init: function(aParent, aTitle, aMode) { },
+  appendFilters: function(aFilterMask) { },
+  appendFilter: function(aTitle, aFilter) { },
+  defaultString: "",
+  defaultExtension: "",
+  filterIndex: 0,
+  displayDirectory: null,
+  file: null,
+  fileURL: null,
+  get files() {
+    var i = 0;
+    return {
+      getNext: function() gFilePickerFiles[i++],
+      hasMoreElements: function() gFilePickerFiles.length > i
+    };
+  },
+  show: function() {
+    return gFilePickerFiles.length == 0 ?
+           Components.interfaces.nsIFilePicker.returnCancel :
+           Components.interfaces.nsIFilePicker.returnOK;
+  }
+};
 
 // This listens for the next opened window and checks it is of the right url.
 // opencallback is called when the new window is fully loaded
 // closecallback is called when the window is closed
 function WindowOpenListener(url, opencallback, closecallback) {
   this.url = url;
   this.opencallback = opencallback;
   this.closecallback = closecallback;
@@ -87,34 +115,45 @@ function test_confirmation(aWindow, aExp
 
   aWindow.document.documentElement.cancelDialog();
 }
 
 
 function test() {
   waitForExplicitFinish();
   
+  gMockFilePickerFactoryCID = Components.ID("{4f595df2-9108-42c6-9910-0dc392a310c9}");
+  gMockFilePickerFactory = XPCOMUtils._getFactory(MockFilePicker);
+  var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+  compReg.registerFactory(gMockFilePickerFactoryCID,
+                          "Mock FilePicker",
+                          "@mozilla.org/filepicker;1",
+                          gMockFilePickerFactory);
+
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     run_next_test();
   });
 }
 
 function end_test() {
+  var compReg = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+  compReg.unregisterFactory(gMockFilePickerFactoryCID,
+                            gMockFilePickerFactory);
   close_manager(gManagerWindow, function() {
     finish();
   });
 }
 
 
 add_test(function() {
   var filePaths = [
                    get_addon_file_url("browser_bug567127_1.xpi"),
                    get_addon_file_url("browser_bug567127_2.xpi")
                   ];
-  MockFilePicker.returnFiles = filePaths.map(function(aPath) aPath.file);
+  gFilePickerFiles = filePaths.map(function(aPath) aPath.file);
   
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, filePaths.map(function(aPath) aPath.spec));
   }, run_next_test);
   
   gManagerWindow.gViewController.doCommand("cmd_installFromFile");
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js
@@ -5,19 +5,16 @@
 // Tests various aspects of the details view
 
 var gManagerWindow;
 var gCategoryUtilities;
 var gProvider;
 
 const SETTINGS_ROWS = 8;
 
-Components.utils.import("resource://mochikit/MockFilePicker.jsm");
-MockFilePicker.reset();
-
 var observer = {
   lastData: null,
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "addon-options-displayed")
       this.lastData = aData;
   }
 };
 
@@ -199,58 +196,62 @@ add_test(function() {
     EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
     EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
     EventUtils.synthesizeKey("VK_RETURN", {}, gManagerWindow);
     input.hidePopup();
     is(input.color, "#FF9900", "Color picker should have updated value");
     is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
 
     try {
+      mockFilePickerFactory.register();
+
       ok(!settings[6].hasAttribute("first-row"), "Not the first row");
       var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
       input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
       is(input.value, "", "Label value should be empty");
 
       var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
       var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
 
-      MockFilePicker.returnFiles = [profD];
-      MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
+      _returnFile = profD;
+      _returnValue = Ci.nsIFilePicker.returnOK;
       EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
-      is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
+      is(_mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
       is(input.value, profD.path, "Label value should match file chosen");
       is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen");
 
-      MockFilePicker.returnFiles = [curProcD];
-      MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
+      _returnFile = curProcD;
+      _returnValue = Ci.nsIFilePicker.returnCancel;
       EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
-      is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
+      is(_mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
       is(input.value, profD.path, "Label value should not have changed");
       is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed");
 
       ok(!settings[7].hasAttribute("first-row"), "Not the first row");
       button = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "button");
       input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input");
       is(input.value, "", "Label value should be empty");
 
-      MockFilePicker.returnFiles = [profD];
-      MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
+      _returnFile = profD;
+      _returnValue = Ci.nsIFilePicker.returnOK;
       EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
-      is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
+      is(_mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
       is(input.value, profD.path, "Label value should match file chosen");
       is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen");
 
-      MockFilePicker.returnFiles = [curProcD];
-      MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
+      _returnFile = curProcD;
+      _returnValue = Ci.nsIFilePicker.returnCancel;
       EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
-      is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
+      is(_mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
       is(input.value, profD.path, "Label value should not have changed");
       is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed");
 
     } finally {
+      mockFilePickerFactory.unregister();
+
       button = gManagerWindow.document.getElementById("detail-prefs-btn");
       is_element_hidden(button, "Preferences button should not be visible");
 
       gCategoryUtilities.openType("extension", run_next_test);
     }
   });
 });
 
@@ -392,8 +393,65 @@ add_test(function() {
         settings = grid.querySelectorAll("rows > setting");
         is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
 
         gCategoryUtilities.openType("extension", run_next_test);
       });
     });
   });
 });
+
+var _returnFile, _returnValue, _mode;
+
+function MockFilePicker() { };
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+  init: function(aParent, aTitle, aMode) {
+    _mode = aMode;
+  },
+  appendFilters: function(aFilterMask) { },
+  appendFilter: function(aTitle, aFilter) { },
+  defaultString: "",
+  defaultExtension: "",
+  filterIndex: 0,
+  displayDirectory: null,
+  get file() {
+    return _returnFile;
+  },
+  get fileURL() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  get files() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  show: function() {
+    return _returnValue;
+  }
+};
+var mockFilePickerFactory = {
+  registrar: Components.manager.QueryInterface(Ci.nsIComponentRegistrar),
+  contractID: "@mozilla.org/filepicker;1",
+  classID: Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID(),
+
+  register: function() {
+    this.registrar.registerFactory(this.classID, "", this.contractID, this);
+  },
+
+  unregister: function() {
+    this.registrar.unregisterFactory(this.classID, this);
+  },
+
+  // nsIFactory
+  createInstance: function(aOuter, aIID) {
+    if (aOuter) {
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    }
+    return new MockFilePicker().QueryInterface(aIID);
+  },
+
+  lockFactory: function(aLock) {
+    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+  },
+
+  QueryInterface: XPCOMUtils.generateQI([
+    Ci.nsIFactory
+  ])
+};