Bug 474527 - onbeforeaccept handler in custom extension <prefwindow> can't prevent the window from closing; r=enndeakin

This commit is contained in:
Gavin Sharp 2009-02-16 16:27:16 +01:00
Родитель daca0390d5
Коммит 2b89342d73
4 изменённых файлов: 114 добавлений и 3 удалений

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

@ -82,6 +82,8 @@ _TEST_FILES = findbar_window.xul \
test_autocomplete3.xul \
test_keys.xul \
window_keys.xul \
test_preferences_beforeaccept.xul \
window_preferences_beforeaccept.xul \
$(NULL)
ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))

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

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Preferences Window Tests"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
// No instant-apply for this test
var prefB = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefB.setBoolPref("browser.preferences.instantApply", false);
var prefWindow = openDialog("window_preferences_beforeaccept.xul", "", "", windowOnload);
function windowOnload() {
var dialogShown = prefWindow.document.getElementById("tests.beforeaccept.dialogShown");
var called = prefWindow.document.getElementById("tests.beforeaccept.called");
is(dialogShown.value, true, "dialog opened, shown pref set");
is(dialogShown.valueFromPreferences, null, "shown pref not committed");
is(called.value, null, "beforeaccept not yet called");
is(called.valueFromPreferences, null, "beforeaccept not yet called, pref not committed");
// try to accept the dialog, should fail the first time
prefWindow.document.documentElement.acceptDialog();
is(prefWindow.closed, false, "window not closed");
is(dialogShown.value, true, "shown pref still set");
is(dialogShown.valueFromPreferences, null, "shown pref still not committed");
is(called.value, true, "beforeaccept called");
is(called.valueFromPreferences, null, "called pref not committed");
// try again, this one should succeed
prefWindow.document.documentElement.acceptDialog();
is(prefWindow.closed, true, "window now closed");
is(dialogShown.valueFromPreferences, true, "shown pref committed");
is(called.valueFromPreferences, true, "called pref committed");
// clean up after ourselves
prefB.clearUserPref("browser.preferences.instantApply");
prefB.clearUserPref("tests.beforeaccept.dialogShown");
prefB.clearUserPref("tests.beforeaccept.called");
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>
</window>

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

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<!--
XUL Widget Test for preferences window
-->
<prefwindow xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="preferences window"
width="300" height="300"
windowtype="test:preferences"
buttons="accept,cancel"
onbeforeaccept="return beforeAccept();"
onload="onDialogLoad();"
>
<script type="application/javascript">
<![CDATA[
function onDialogLoad() {
var pref = document.getElementById("tests.beforeaccept.dialogShown");
pref.value = true;
// call the onload handler we were passed
window.arguments[0]();
}
function beforeAccept() {
var beforeAcceptPref = document.getElementById("tests.beforeaccept.called");
var oldValue = beforeAcceptPref.value;
beforeAcceptPref.value = true;
return !!oldValue;
}
]]>
</script>
<prefpane id="sample_pane" label="Sample Prefpane">
<preferences id="sample_preferences">
<preference id="tests.beforeaccept.called"
name="tests.beforeaccept.called"
type="bool"/>
<preference id="tests.beforeaccept.dialogShown"
name="tests.beforeaccept.dialogShown"
type="bool"/>
</preferences>
</prefpane>
<label>Test Prefpane</label>
</prefwindow>

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

@ -1032,7 +1032,7 @@
<handler event="dialogaccept">
<![CDATA[
if (!this._fireEvent("beforeaccept", this))
return;
return false;
if (this.type == "child" && window.opener) {
var psvc = Components.classes["@mozilla.org/preferences-service;1"]
@ -1096,6 +1096,8 @@
.getService(Components.interfaces.nsIPrefService);
psvc.savePrefFile(null);
}
return true;
]]>
</handler>
<handler event="command">