Bug 613403 - Fix existing tests to work with tab-modal prompt changes. r=ehsan, a=testsonly

This commit is contained in:
Justin Dolske 2010-11-19 15:15:27 -08:00
Родитель a647c00c58
Коммит c7a4d684c3
2 изменённых файлов: 34 добавлений и 60 удалений

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

@ -45,8 +45,8 @@ function test() {
const HISTORY_SIDEBAR_TREE_ID = "historyTree";
// Initialization.
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
let os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let bs = PlacesUtils.bookmarks;
let hs = PlacesUtils.history;
let sidebarBox = document.getElementById("sidebar-box");
@ -125,22 +125,20 @@ function test() {
preFunc();
function observer(aSubject, aTopic, aData) {
if (aTopic != "domwindowopened")
return;
ww.unregisterNotification(observer);
let alertDialog = aSubject.QueryInterface(Ci.nsIDOMWindow);
alertDialog.addEventListener("load", function () {
alertDialog.removeEventListener("load", arguments.callee, false);
info("alert dialog observed as expected");
executeSoon(function () {
alertDialog.close();
info("alert dialog observed as expected");
os.removeObserver(observer, "common-dialog-loaded");
os.removeObserver(observer, "tabmodal-dialog-loaded");
aSubject.Dialog.ui.button0.click();
executeSoon(function () {
toggleSidebar(currentTest.sidebarName);
currentTest.cleanup();
postFunc();
});
}, false);
}
ww.registerNotification(observer);
os.addObserver(observer, "common-dialog-loaded", false);
os.addObserver(observer, "tabmodal-dialog-loaded", false);
// Select the inserted places item.
currentTest.selectNode(tree);
@ -160,7 +158,7 @@ function test() {
y = y.value + height.value / 2;
// Simulate the click.
EventUtils.synthesizeMouse(tree.body, x, y, {}, doc.defaultView);
// Now, wait for the domwindowopened observer to catch the alert dialog.
// Now, wait for the observer to catch the alert dialog.
// If something goes wrong, the test will time out at this stage.
// Note that for the history sidebar, the URL itself is not opened,
// and Places will show the load-js-data-url-error prompt as an alert

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

@ -25,85 +25,61 @@ SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
var gPromptInput = null;
var gPromptWindow = null;
function runTest()
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
function WindowObserver()
{
Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService).
addObserver(this, "domwindowopened", false);
}
WindowObserver.prototype = {
QueryInterface: function (iid) {
if (iid.equals(Components.interfaces.nsIObserver) ||
iid.equals(Components.interfaces.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
},
var os = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
observe: function (subject, topic, data) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (topic === "domwindowopened") {
ok(true, "prompt window is created");
gPromptWindow =
subject.QueryInterface(Components.interfaces.nsIDOMWindow);
gPromptWindow.addEventListener("load", onPromptLoad, false);
}
}
};
var observer = new WindowObserver();
os.addObserver(onPromptLoad, "common-dialog-loaded", false);
os.addObserver(onPromptLoad, "tabmodal-dialog-loaded", false);
ok(true, "opening prompt...");
prompt("summary", "text");
ok(true, "prompt is closed");
Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService).
removeObserver(observer, "domwindowopened");
SimpleTest.finish();
os.removeObserver(onPromptLoad, "tabmodal-dialog-loaded");
os.removeObserver(onPromptLoad, "common-dialog-loaded");
}
function onPromptLoad()
function onPromptLoad(subject, topic, data)
{
ok(true, "onPromptLoad is called");
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
gPromptWindow.removeEventListener("load", onPromptLoad, false);
gPromptInput = gPromptWindow.document.getElementById("loginTextbox");
gPromptInput = subject.Dialog.ui.loginTextbox;
gPromptInput.addEventListener("focus", onPromptFocus, false);
// shift focus to ensure it fires.
subject.Dialog.ui.button0.focus();
gPromptInput.focus();
}
function onPromptFocus()
{
function onPromptFocus() {
ok(true, "onPromptFocus is called");
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
gPromptInput.removeEventListener("focus", onPromptFocus, false);
var systemGroup =
Components.classes["@mozilla.org/eventlistenerservice;1"].
getService(Components.interfaces.nsIEventListenerService).
systemEventGroup;
gPromptInput.QueryInterface(Components.interfaces.nsIDOM3EventTarget);
var isPrevented = false;
var listener = {
handleEvent: function _hv(aEvent)
{
isPrevented = aEvent.getPreventDefault();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var isPrevented = aEvent.getPreventDefault();
ok(!isPrevented, "ESC key event is prevented by editor");
gPromptInput.removeGroupedEventListener("keypress", listener, false,
systemGroup);
SimpleTest.finish();
}
};
gPromptInput.addGroupedEventListener("keypress", listener, false,
systemGroup);
synthesizeKey("VK_ESCAPE", { }, gPromptWindow);
gPromptInput.removeGroupedEventListener("keypress", listener, false,
systemGroup);
ok(!isPrevented, "ESC key event is prevented by editor");
if (isPrevented) {
gPromptWindow.close();
}
ok(true, "sending key");
synthesizeKey("VK_ESCAPE", { }, gPromptInput.ownerDocument.defaultView);
}
</script>