Bug 463491 - Do not reduce the popup blocker abuse level when using command event. r=jst
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 11 Aug 2011 18:31:33 +0200
changeset 74265 223d4f4bd252fac3ed3591692b84d06f27f010e8
parent 74264 5cc85a3730f87b719aa841a6041169747da5604f
child 74266 0f6ccf479e1016c81ab6b35593db7d6e864dfaf2
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersjst
bugs463491
milestone8.0a1
Bug 463491 - Do not reduce the popup blocker abuse level when using command event. r=jst
content/events/src/nsDOMEvent.cpp
dom/tests/browser/Makefile.in
dom/tests/browser/browser_popup_blocker_save_open_panel.js
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -979,19 +979,16 @@ nsDOMEvent::GetEventPopupControlState(ns
     // while handling user input. See
     // nsPresShell::HandleEventInternal() for details.
     if (nsEventStateManager::IsHandlingUserInput()) {
       switch(aEvent->message) {
       case NS_FORM_CHANGE :
         if (::PopupAllowedForEvent("change"))
           abuse = openControlled;
         break;
-      case NS_XUL_COMMAND:
-        abuse = openControlled;
-        break;
       }
     }
     break;
   case NS_KEY_EVENT :
     if (NS_IS_TRUSTED_EVENT(aEvent)) {
       PRUint32 key = static_cast<nsKeyEvent *>(aEvent)->keyCode;
       switch(aEvent->message) {
       case NS_KEY_PRESS :
--- a/dom/tests/browser/Makefile.in
+++ b/dom/tests/browser/Makefile.in
@@ -46,12 +46,13 @@ include $(topsrcdir)/config/rules.mk
 
 _BROWSER_FILES = \
 		browser_focus_steal_from_chrome.js \
 		browser_focus_steal_from_chrome_during_mousedown.js \
 		browser_autofocus_background.js \
 		browser_ConsoleAPITests.js \
 		test-console-api.html \
 		browser_autofocus_preference.js \
+		browser_popup_blocker_save_open_panel.js \
 		$(NULL)
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/browser_popup_blocker_save_open_panel.js
@@ -0,0 +1,101 @@
+/**
+ * In this test, we call the save panel with CTRL+S. When shown, we load a
+ * webpage that is going to open malicious popups. These popups should be
+ * disallowed.
+ */
+
+var gLoaded = false;
+
+Cc["@mozilla.org/moz/jssubscript-loader;1"]
+  .getService(Ci.mozIJSSubScriptLoader)
+  .loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockObjects.js",
+                 this);
+
+function MockFilePicker() { }
+
+MockFilePicker.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  init: function() { },
+
+  appendFilters: function(val) { },
+  appendFilter: function(val) { },
+
+  // 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,
+
+  // properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) { },
+  file: null,
+  get files() { return null; },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  show: function() {
+    gBrowser.selectedTab.linkedBrowser.addEventListener("load", function () {
+      gBrowser.selectedTab.linkedBrowser.removeEventListener("load", arguments.callee, true);
+      executeSoon(function() {
+        gLoaded = true;
+      });
+    }, true);
+
+    gBrowser.selectedTab.linkedBrowser.loadURI("data:text/html,<!DOCTYPE html><html><body onload='window.open(\"about:blank\", \"\", \"width=200,height=200\");'></body></html>");
+
+    let curThread = Components.classes["@mozilla.org/thread-manager;1"]
+                              .getService().currentThread;
+    while (!gLoaded) {
+      curThread.processNextEvent(true);
+    }
+
+    return this.returnCancel;
+  },
+};
+
+function test() {
+  waitForExplicitFinish();
+
+  var mockFilePickerRegisterer =
+    new MockObjectRegisterer("@mozilla.org/filepicker;1", MockFilePicker);
+  mockFilePickerRegisterer.register();
+
+  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+            .getService(Components.interfaces.nsIPrefBranch);
+  var gDisableLoadPref = prefs.getBoolPref("dom.disable_open_during_load");
+  prefs.setBoolPref("dom.disable_open_during_load", true);
+
+  gBrowser.addEventListener("DOMPopupBlocked", function() {
+    gBrowser.removeEventListener("DOMPopupBlocked", arguments.callee, true);
+    ok(true, "The popup has been blocked");
+    prefs.setBoolPref("dom.disable_open_during_load", gDisableLoadPref);
+
+    mockFilePickerRegisterer.unregister();
+
+    finish();
+  }, true)
+
+  if (navigator.platform.indexOf("Mac") == 0) {
+    // MacOS use metaKey instead of ctrlKey.
+    EventUtils.synthesizeKey("s", { metaKey: true, });
+  } else {
+    EventUtils.synthesizeKey("s", { ctrlKey: true, });
+  }
+}