From 2780df842f40bb45a5db67732d7ff8e08d27b933 Mon Sep 17 00:00:00 2001 From: Andrew Hurle Date: Thu, 24 May 2012 18:45:10 -0400 Subject: [PATCH] Bug 566444 - Simple test for the proxy settings dialog under preferences. r=jaws --- .../components/preferences/tests/Makefile.in | 1 + .../preferences/tests/browser_prefs_simple.js | 47 +++++++++++++++++++ dom/base/nsGlobalWindow.cpp | 13 +++-- toolkit/content/widgets/dialog.xml | 10 +++- toolkit/content/widgets/preferences.xml | 5 ++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 browser/components/preferences/tests/browser_prefs_simple.js diff --git a/browser/components/preferences/tests/Makefile.in b/browser/components/preferences/tests/Makefile.in index e6241036828a..42e18751015d 100644 --- a/browser/components/preferences/tests/Makefile.in +++ b/browser/components/preferences/tests/Makefile.in @@ -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) diff --git a/browser/components/preferences/tests/browser_prefs_simple.js b/browser/components/preferences/tests/browser_prefs_simple.js new file mode 100644 index 000000000000..aaefddc25d7f --- /dev/null +++ b/browser/components/preferences/tests/browser_prefs_simple.js @@ -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(); + +} diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 2b613b06dfa4..0db2de2c9c51 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -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) { diff --git a/toolkit/content/widgets/dialog.xml b/toolkit/content/widgets/dialog.xml index 61210a462484..24e0f35f1c71 100644 --- a/toolkit/content/widgets/dialog.xml +++ b/toolkit/content/widgets/dialog.xml @@ -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; } diff --git a/toolkit/content/widgets/preferences.xml b/toolkit/content/widgets/preferences.xml index 7e628c5b3559..6350c8fa2139 100644 --- a/toolkit/content/widgets/preferences.xml +++ b/toolkit/content/widgets/preferences.xml @@ -1031,10 +1031,13 @@