Tests for Bug 36619 r=sicking a=blocking
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 27 Aug 2010 11:49:10 -0400
changeset 51582 a8328013a77313de8bf058463cc2d8ddbe63139c
parent 51581 af7d35e5d336396844d00cc1c09463be9fb76668
child 51584 e225bc9577606d9b51a7bb6c7931836abce8fc82
push idunknown
push userunknown
push dateunknown
reviewerssicking, blocking
bugs36619
milestone2.0b5pre
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
Tests for Bug 36619 r=sicking a=blocking
content/html/content/test/test_bug500885.html
layout/forms/test/Makefile.in
layout/forms/test/bug536567_subframe.html
layout/forms/test/test_bug36619.html
layout/forms/test/test_bug377624.html
--- a/content/html/content/test/test_bug500885.html
+++ b/content/html/content/test/test_bug500885.html
@@ -47,25 +47,25 @@ MockFilePicker.prototype = {
   get files() {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
   show: function MFP_show() {
     return Ci.nsIFilePicker.returnOK;
   }
 };
 
-var mockFilePickerRegisterer =
+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 () {
       domActivateEvents++;
@@ -77,18 +77,24 @@ 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 {
-    mockFilePickerRegisterer.unregister();
+    SimpleTest.executeSoon(unregister);
+    
   }
+}
+
+function unregister()
+{
+  mockFilePickerRegisterer.unregister();
   SimpleTest.finish();
 }
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
   setTimeout(test, 0);
 };
 
--- a/layout/forms/test/Makefile.in
+++ b/layout/forms/test/Makefile.in
@@ -68,12 +68,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug549170.html \
 		test_bug562447.html \
 		test_bug563642.html \
 		test_bug564115.html \
 		bug564115_window.html \
 		test_bug377624.html \
 		test_bug571352.html \
 		test_bug572406.html \
+		test_bug36619.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
--- a/layout/forms/test/bug536567_subframe.html
+++ b/layout/forms/test/bug536567_subframe.html
@@ -25,31 +25,34 @@ MockFilePicker.prototype = {
   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() {
@@ -62,17 +65,16 @@ function test() {
 
   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 {
-    mockFilePickerRegisterer.unregister();
   }
 }
 
 window.onload = function() {
   setTimeout(test, 0);
 };
 
 </script>
new file mode 100644
--- /dev/null
+++ b/layout/forms/test/test_bug36619.html
@@ -0,0 +1,120 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+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>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body onload="runTests();">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=36619">Mozilla Bug 36619</a>
+<p id="display"></p>
+<div id="content">
+  <input id='a' type='file'>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 36619 **/
+
+SimpleTest.waitForExplicitFinish();
+
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+const Cu = Components.utils;
+
+Cc["@mozilla.org/moz/jssubscript-loader;1"]
+  .getService(Ci.mozIJSSubScriptLoader)
+  .loadSubScript("chrome://mochikit/content/browser/toolkit/content/tests/browser/common/mockObjects.js", this);
+
+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 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()
+{
+  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()
+{
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  ok(!shown,
+    "File picker show method should not have been called");
+    
+  mockFilePickerRegisterer.unregister();
+                                 
+  pbi.setBoolPref("dom.disable_open_during_load", oldAllow);
+  pbi.setBoolPref("privacy.popups.showBrowserMessage", oldShowBar);
+  SimpleTest.finish();
+}
+  
+function runTests()
+{
+  document.getElementById("a").click();
+  SimpleTest.executeSoon(checkFirst);
+}
+
+</script>
+</pre>
+</body>
+</html>
--- a/layout/forms/test/test_bug377624.html
+++ b/layout/forms/test/test_bug377624.html
@@ -41,16 +41,22 @@ 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 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]),
@@ -87,23 +93,25 @@ FilePickerService.prototype = {
   // 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)
@@ -192,17 +200,18 @@ function runTests()
               obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
               obs.removeObserver(observer, "TEST_FILEPICKER_SHOW", false);
               Cm.unregisterFactory(CUSTOM_FILE_PICKER_ID, factory);
 
               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;
       }
     },