Back out 2 changesets (bug 1116385, bug 724353) for test_unknownContentType_delayedbutton.xul failures

Backed out changeset aaade64d3f28 (bug 724353)
Backed out changeset dca478776c91 (bug 1116385)
This commit is contained in:
Phil Ringnalda 2015-10-12 21:37:58 -07:00
Родитель 1f586b6e64
Коммит 3223175289
7 изменённых файлов: 78 добавлений и 264 удалений

Просмотреть файл

@ -10,9 +10,6 @@ const Cc = Components.classes;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper",
"resource://gre/modules/SharedPromptUtils.jsm");
this.CommonDialog = function CommonDialog(args, ui) {
@ -164,11 +161,13 @@ CommonDialog.prototype = {
this.setDefaultFocus(true);
if (this.args.enableDelay) {
this.delayHelper = new EnableDelayHelper({
disableDialog: () => this.setButtonsEnabledState(false),
enableDialog: () => this.setButtonsEnabledState(true),
focusTarget: this.ui.focusTarget
});
this.setButtonsEnabledState(false);
// Use a longer, pref-controlled delay when the dialog is first opened.
let delayTime = Services.prefs.getIntPref("security.dialog_enable_delay");
this.startOnFocusDelay(delayTime);
let self = this;
this.ui.focusTarget.addEventListener("blur", function(e) { self.onBlur(e); }, false);
this.ui.focusTarget.addEventListener("focus", function(e) { self.onFocus(e); }, false);
}
// Play a sound (unless we're tab-modal -- don't want those to feel like OS prompts).
@ -231,6 +230,44 @@ CommonDialog.prototype = {
this.ui.button3.disabled = !enabled;
},
onBlur : function (aEvent) {
if (aEvent.target != this.ui.focusTarget)
return;
this.setButtonsEnabledState(false);
// If we blur while waiting to enable the buttons, just cancel the
// timer to ensure the delay doesn't fire while not focused.
if (this.focusTimer) {
this.focusTimer.cancel();
this.focusTimer = null;
}
},
onFocus : function (aEvent) {
if (aEvent.target != this.ui.focusTarget)
return;
this.startOnFocusDelay();
},
startOnFocusDelay : function(delayTime) {
// Shouldn't already have a timer, but just in case...
if (this.focusTimer)
return;
// If no delay specified, use 250ms. (This is the normal case for when
// after the dialog has been opened and focus shifts.)
if (!delayTime)
delayTime = 250;
let self = this;
this.focusTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this.focusTimer.initWithCallback(function() { self.onFocusTimeout(); },
delayTime, Ci.nsITimer.TYPE_ONE_SHOT);
},
onFocusTimeout : function() {
this.focusTimer = null;
this.setButtonsEnabledState(true);
},
setDefaultFocus : function(isInitialLoad) {
let b = (this.args.defaultButtonNum || 0);
let button = this.ui["button" + b];

Просмотреть файл

@ -1,12 +1,10 @@
this.EXPORTED_SYMBOLS = [ "PromptUtils", "EnableDelayHelper" ];
this.EXPORTED_SYMBOLS = [ "PromptUtils" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
this.PromptUtils = {
// Fire a dialog open/close event. Used by tabbrowser to focus the
// tab which is triggering a prompt.
@ -42,110 +40,3 @@ this.PromptUtils = {
obj[propName] = propBag.getProperty(propName);
},
};
/**
* This helper handles the enabling/disabling of dialogs that might
* be subject to fast-clicking attacks. It handles the initial delayed
* enabling of the dialog, as well as disabling it on blur and reapplying
* the delay when the dialog regains focus.
*
* @param enableDialog A custom function to be called when the dialog
* is to be enabled.
* @param diableDialog A custom function to be called when the dialog
* is to be disabled.
* @param focusTarget The window used to watch focus/blur events.
*/
this.EnableDelayHelper = function({enableDialog, disableDialog, focusTarget}) {
this.enableDialog = makeSafe(enableDialog);
this.disableDialog = makeSafe(disableDialog);
this.focusTarget = focusTarget;
this.disableDialog();;
this.focusTarget.addEventListener("blur", this, false);
this.focusTarget.addEventListener("focus", this, false);
this.focusTarget.document.addEventListener("unload", this, false);
this.startOnFocusDelay();
};
this.EnableDelayHelper.prototype = {
get delayTime() {
return Services.prefs.getIntPref("security.dialog_enable_delay");
},
handleEvent : function(event) {
if (event.target != this.focusTarget &&
event.target != this.focusTarget.document)
return;
switch (event.type) {
case "blur":
this.onBlur();
break;
case "focus":
this.onFocus();
break;
case "unload":
this.onUnload();
break;
}
},
onBlur : function () {
this.disableDialog();
// If we blur while waiting to enable the buttons, just cancel the
// timer to ensure the delay doesn't fire while not focused.
if (this._focusTimer) {
this._focusTimer.cancel();
this._focusTimer = null;
}
},
onFocus : function () {
this.startOnFocusDelay();
},
onUnload: function() {
this.focusTarget.removeEventListener("blur", this, false);
this.focusTarget.removeEventListener("focus", this, false);
this.focusTarget.document.removeEventListener("unload", this, false);
if (this._focusTimer) {
this._focusTimer.cancel();
this._focusTimer = null;
}
this.focusTarget = this.enableDialog = this.disableDialog = null;
},
startOnFocusDelay : function() {
if (this._focusTimer)
return;
this._focusTimer = Cc["@mozilla.org/timer;1"]
.createInstance(Ci.nsITimer);
this._focusTimer.initWithCallback(
() => { this.onFocusTimeout(); },
this.delayTime,
Ci.nsITimer.TYPE_ONE_SHOT
);
},
onFocusTimeout : function() {
this._focusTimer = null;
this.enableDialog();
},
};
function makeSafe(fn) {
return function () {
// The dialog could be gone by now (if the user closed it),
// which makes it likely that the given fn might throw.
try {
fn();
} catch (e) { }
};
}

Просмотреть файл

@ -19,6 +19,7 @@
<dialog id="unknownContentType"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="dialog.initDialog();" onunload="if (dialog) dialog.onCancel();"
onblur="if (dialog) dialog.onBlur(event);" onfocus="dialog.onFocus(event);"
#ifdef XP_WIN
style="width: 36em;"
#else

Просмотреть файл

@ -8,9 +8,6 @@
const {utils: Cu, interfaces: Ci, classes: Cc, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper",
"resource://gre/modules/SharedPromptUtils.jsm");
///////////////////////////////////////////////////////////////////////////////
//// Helper Functions
@ -542,21 +539,25 @@ nsUnknownContentTypeDialog.prototype = {
this.mDialog.setTimeout("dialog.postShowCallback()", 0);
this.delayHelper = new EnableDelayHelper({
disableDialog: () => {
this.mDialog.document.documentElement.getButton("accept").disabled = true;
},
enableDialog: () => {
this.mDialog.document.documentElement.getButton("accept").disabled = false;
},
focusTarget: this.mDialog
});
let acceptDelay = Services.prefs.getIntPref("security.dialog_enable_delay");
this.mDialog.document.documentElement.getButton("accept").disabled = true;
this._showTimer = Components.classes["@mozilla.org/timer;1"]
.createInstance(nsITimer);
this._showTimer.initWithCallback(this, acceptDelay, nsITimer.TYPE_ONE_SHOT);
},
notify: function (aTimer) {
if (aTimer == this._showTimer) {
if (!this.mDialog) {
this.reallyShow();
} else {
// The user may have already canceled the dialog.
try {
if (!this._blurred) {
this.mDialog.document.documentElement.getButton("accept").disabled = false;
}
} catch (ex) {}
this._delayExpired = true;
}
// The timer won't release us, so we have to release it.
this._showTimer = null;
@ -640,6 +641,21 @@ nsUnknownContentTypeDialog.prototype = {
}
},
_blurred: false,
_delayExpired: false,
onBlur: function(aEvent) {
this._blurred = true;
this.mDialog.document.documentElement.getButton("accept").disabled = true;
},
onFocus: function(aEvent) {
this._blurred = false;
if (this._delayExpired) {
var script = "document.documentElement.getButton('accept').disabled = false";
this.mDialog.setTimeout(script, 250);
}
},
// Returns true if opening the default application makes sense.
openWithDefaultOK: function() {
// The checking is different on Windows...

Просмотреть файл

@ -36,5 +36,4 @@ skip-if = os != 'win' && toolkit != 'cocoa'
# disabled for very frequent orange--bug 630567
skip-if = os != 'win' || true
[test_ui_stays_open_on_alert_clickback.xul]
[test_unknownContentType_delayedbutton.xul]
[test_unknownContentType_dialog_layout.xul]

Просмотреть файл

@ -1,114 +0,0 @@
<?xml version="1.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/. -->
<!--
* The unknownContentType popup can have two different layouts depending on
* whether a helper application can be selected or not.
* This tests that both layouts have correct collapsed elements.
-->
<window title="Unknown Content Type Dialog Test"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="doTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript"
src="utils.js"/>
<script type="application/javascript"><![CDATA[
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
Components.utils.import("resource://gre/modules/Promise.jsm");
const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
const LOAD_URI = "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt";
const DIALOG_DELAY = Services.prefs.getIntPref("security.dialog_enable_delay") + 100;
let UCTObserver = {
opened: Promise.defer(),
closed: Promise.defer(),
observe: function(aSubject, aTopic, aData) {
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
switch (aTopic) {
case "domwindowopened":
win.addEventListener("load", function onLoad(event) {
win.removeEventListener("load", onLoad, false);
// Let the dialog initialize
SimpleTest.executeSoon(function() {
UCTObserver.opened.resolve(win);
});
}, false);
break;
case "domwindowclosed":
if (win.location == UCT_URI) {
this.closed.resolve();
}
break;
}
}
};
Services.ww.registerNotification(UCTObserver);
SimpleTest.waitForExplicitFinish();
function waitDelay(delay) {
return new Promise((resolve, reject) => {
window.setTimeout(resolve, delay);
});
}
function doTest() {
Task.spawn(function test_aboutCrashed() {
let frame = document.getElementById("testframe");
frame.setAttribute("src", LOAD_URI);
let uctWindow = yield UCTObserver.opened.promise;
let ok = uctWindow.document.documentElement.getButton("accept");
SimpleTest.is(ok.disabled, true, "button started disabled");
yield waitDelay(DIALOG_DELAY);
SimpleTest.is(ok.disabled, false, "button was enabled");
window.focus();
yield waitDelay(0);
SimpleTest.is(ok.disabled, true, "button was disabled");
uctWindow.focus();
yield waitDelay(0);
SimpleTest.is(ok.disabled, true, "button remained disabled");
yield waitDelay(DIALOG_DELAY);
SimpleTest.is(ok.disabled, false, "button re-enabled after delay");
uctWindow.document.documentElement.cancelDialog();
yield UCTObserver.closed.promise;
Services.ww.unregisterNotification(UCTObserver);
uctWindow = null;
UCTObserver = null;
SimpleTest.finish();
});
}
]]></script>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display:none;"></div>
<pre id="test"></pre>
</body>
<iframe xmlns="http://www.w3.org/1999/xhtml"
id="testframe">
</iframe>
</window>

Просмотреть файл

@ -31,10 +31,6 @@
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/SharedPromptUtils.jsm");
var dialog = {
//////////////////////////////////////////////////////////////////////////////
@ -45,7 +41,6 @@ var dialog = {
_itemChoose: null,
_okButton: null,
_windowCtxt: null,
_buttonDisabled: true,
//////////////////////////////////////////////////////////////////////////////
//// Methods
@ -63,6 +58,8 @@ var dialog = {
this._itemChoose = document.getElementById("item-choose");
this._okButton = document.documentElement.getButton("accept");
this.updateOKButton();
var description = {
image: document.getElementById("description-image"),
text: document.getElementById("description-text")
@ -88,18 +85,6 @@ var dialog = {
// UI is ready, lets populate our list
this.populateList();
this._delayHelper = new EnableDelayHelper({
disableDialog: () => {
this._buttonDisabled = true;
this.updateOKButton();
},
enableDialog: () => {
this._buttonDisabled = false;
this.updateOKButton();
},
focusTarget: window
});
},
/**
@ -237,8 +222,7 @@ var dialog = {
*/
updateOKButton: function updateOKButton()
{
this._okButton.disabled = this._itemChoose.selected ||
this._buttonDisabled;
this._okButton.disabled = this._itemChoose.selected;
},
/**