Bug 566444 - Simple test for the proxy settings dialog under preferences. r=jaws

This commit is contained in:
Andrew Hurle 2012-05-24 18:45:10 -04:00
parent f11aafa051
commit 2780df842f
5 changed files with 72 additions and 4 deletions

View File

@ -26,6 +26,7 @@ _BROWSER_FILES = \
browser_privacypane_8.js \
browser_permissions.js \
browser_chunk_permissions.js \
browser_prefs_simple.js \
$(NULL)
libs:: $(_BROWSER_FILES)

View File

@ -0,0 +1,47 @@
function test() {
waitForExplicitFinish();
let connectionURI = "chrome://browser/content/preferences/connection.xul";
let preferencesURI = "chrome://browser/content/preferences/preferences.xul";
//open pref window, open connection subdialog, accept subdialog, accept pref window
let observer = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "domwindowopened") {
let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
win.addEventListener("load", function() {
win.removeEventListener("load", arguments.callee, false);
if (win.location.href == preferencesURI) {
ok(true, "preferences window opened");
win.addEventListener("DOMModalDialogClosed", function() {
ok(true, "connection window closed");
win.document.documentElement.acceptDialog();
});
win.document.documentElement.openSubDialog(connectionURI, "", null);
}
else if (win.location.href == connectionURI) {
ok(true, "connection window opened");
win.document.getElementById("network.proxy.no_proxies_on").value = "blah";
win.document.documentElement.acceptDialog();
}
}, false);
}
else if (aTopic == "domwindowclosed") {
let win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow);
if (win.location.href == preferencesURI) {
windowWatcher.unregisterNotification(observer);
ok(true, "preferences window closed");
is(Services.prefs.getCharPref("network.proxy.no_proxies_on"), "blah", "saved pref");
finish();
}
}
}
}
var windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
windowWatcher.registerNotification(observer);
openPreferences();
}

View File

@ -6286,19 +6286,23 @@ nsGlobalWindow::CanClose()
NS_IMETHODIMP
nsGlobalWindow::Close()
{
printf("start of close\n");
FORWARD_TO_OUTER(Close, (), NS_ERROR_NOT_INITIALIZED);
if (IsFrame() || !mDocShell || IsInModalState()) {
// window.close() is called on a frame in a frameset, on a window
// that's already closed, or on a window for which there's
// currently a modal dialog open. Ignore such calls.
printf("IsFrame: %s, mDocShell: %s, IsInModalState: %s\n",
(IsFrame() ? "true" : "false"), (mDocShell ? "true" : "false"),
(IsInModalState() ? "true" : "false"));
return NS_OK;
}
if (mHavePendingClose) {
// We're going to be closed anyway; do nothing since we don't want
// to double-close
printf("mhavependingclose\n");
return NS_OK;
}
@ -6313,6 +6317,7 @@ nsGlobalWindow::Close()
// Don't allow scripts from content to close windows
// that were not opened by script
if (!mHadOriginalOpener && !nsContentUtils::IsCallerTrustedForWrite()) {
printf("disallow scripts from content\n");
bool allowClose =
Preferences::GetBool("dom.allow_scripts_to_close_windows", true);
if (!allowClose) {
@ -6344,11 +6349,12 @@ nsGlobalWindow::Close()
if (!DispatchCustomEvent("DOMWindowClose")) {
// Someone chose to prevent the default action for this event, if
// so, let's not close this window after all...
printf("prevetn default on close\n");
mInClose = wasInClose;
return NS_OK;
}
printf("calling finalclose\n");
return FinalClose();
}
@ -6599,6 +6605,7 @@ private:
void
nsGlobalWindow::LeaveModalState(nsIDOMWindow *aCallerWin)
{
printf("LeaveModalState\n");
nsGlobalWindow *topWin = GetTop();
if (!topWin) {

View File

@ -356,9 +356,17 @@
var button = this.getButton(aDlgType);
if (!button.disabled) {
var noCancel = this._fireButtonEvent(aDlgType);
dump("not disabled\n");
if (noCancel) {
dump("not canceled\n");
if (aDlgType == "accept" || aDlgType == "cancel")
window.close();
dump("closing\n");
dump("window: " + window + "\n");
dump("href: " + window.location.href + "\n");
dump("opener: " + window.opener + "\n");
dump("rv: " + window.close() + "\n");
dump("after close\n");
dump("closed: " + window.closed + "\n");
}
return noCancel;
}

View File

@ -1031,10 +1031,13 @@
<handlers>
<handler event="dialogaccept">
<![CDATA[
dump("dialog accept\n");
if (!this._fireEvent("beforeaccept", this))
return;
dump("after dialog accept\n");
if (this.type == "child" && window.opener) {
dump("child\n");
var psvc = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var instantApply = psvc.getBoolPref("browser.preferences.instantApply");
@ -1088,6 +1091,7 @@
}
}
else {
dump("parent\n");
var panes = this.preferencePanes;
for (var i = 0; i < panes.length; ++i)
panes[i].writePreferences(false);
@ -1095,6 +1099,7 @@
var psvc = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
psvc.savePrefFile(null);
dump("after parent\n");
}
]]>
</handler>