Bug 564724 - Add tests and empty base component for nsIPrompt-related code. r=gavin

This commit is contained in:
Justin Dolske 2010-06-14 14:00:21 -07:00
Родитель 59af27f760
Коммит 2d9fa26437
8 изменённых файлов: 1304 добавлений и 0 удалений

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

@ -333,6 +333,7 @@
@BINPATH@/components/@DLL_PREFIX@dbusservice@DLL_SUFFIX@
#endif
@BINPATH@/components/nsINIProcessor.js
@BINPATH@/components/nsPrompter.js
; Modules
@BINPATH@/modules/*

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

@ -63,6 +63,7 @@ PARALLEL_DIRS += \
parentalcontrols \
passwordmgr \
places \
prompts \
startup \
statusfilter \
typeaheadfind \

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

@ -0,0 +1,50 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla code.
#
# The Initial Developer of the Original Code is the Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Justin Dolske <dolske@mozilla.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = src
ifdef ENABLE_TESTS
DIRS += test
endif
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,50 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Justin Dolske <dolske@mozilla.com> (original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = prompter
EXTRA_COMPONENTS = \
nsPrompter.js \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,81 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Justin Dolske <dolske@mozilla.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
function Prompter() {
this.init();
}
Prompter.prototype = {
classDescription : "Prompter",
contractID : "@mozilla.org/prompter;1",
classID : Components.ID("{1c978d25-b37f-43a8-a2d6-0c7a239ead87}"),
QueryInterface : XPCOMUtils.generateQI([Ci.nsISupports]),
/* ---------- private memebers ---------- */
debug : true,
init : function () {
this.log("initialized!");
},
log : function (message) {
if (!this.debug)
return;
dump("Prompter: " + message + "\n");
Services.console.logStringMessage("Prompter: " + message);
},
/* ---------- nsIPrompter ---------- */
};
var component = [Prompter];
function NSGetModule (compMgr, fileSpec) {
return XPCOMUtils.generateModule(component);
}

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

@ -0,0 +1,61 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Justin Dolske <dolske@mozilla.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = toolkit/components/prompts/test
include $(DEPTH)/config/autoconf.mk
# Module name for xpcshell tests.
MODULE = test_prompter
# Mochitest tests
MOCHI_TESTS = \
test_modal_prompts.html \
$(NULL)
MOCHI_CONTENT = \
prompt_common.js \
$(NULL)
include $(topsrcdir)/config/rules.mk
libs:: $(MOCHI_TESTS) $(MOCHI_CONTENT)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

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

@ -0,0 +1,79 @@
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Ci = Components.interfaces;
const Cc = Components.classes;
ok(Ci != null, "Access Ci");
ok(Cc != null, "Access Cc");
var didDialog;
var timer; // keep in outer scope so it's not GC'd before firing
function startCallbackTimer() {
didDialog = false;
// Delay before the callback twiddles the prompt.
const dialogDelay = 10;
// Use a timer to invoke a callback to twiddle the authentication dialog
timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT);
}
var observer = {
QueryInterface : function (iid) {
const interfaces = [Ci.nsIObserver,
Ci.nsISupports, Ci.nsISupportsWeakReference];
if (!interfaces.some( function(v) { return iid.equals(v) } ))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
observe : function (subject, topic, data) {
netscape.security.PrivilegeManager
.enablePrivilege('UniversalXPConnect');
var doc = getDialogDoc();
if (doc)
handleDialog(doc, testNum);
else
startCallbackTimer(); // try again in a bit
}
};
function getDialogDoc() {
// Find the <browser> which contains notifyWindow, by looking
// through all the open windows and all the <browsers> in each.
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
//var enumerator = wm.getEnumerator("navigator:browser");
var enumerator = wm.getXULWindowEnumerator(null);
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
var windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell;
var containedDocShells = windowDocShell.getDocShellEnumerator(
Ci.nsIDocShellTreeItem.typeChrome,
Ci.nsIDocShell.ENUMERATE_FORWARDS);
while (containedDocShells.hasMoreElements()) {
// Get the corresponding document for this docshell
var childDocShell = containedDocShells.getNext();
// We don't want it if it's not done loading.
if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
continue;
var childDoc = childDocShell.QueryInterface(Ci.nsIDocShell)
.contentViewer
.DOMDocument;
//ok(true, "Got window: " + childDoc.location.href);
if (childDoc.location.href == "chrome://global/content/commonDialog.xul")
return childDoc;
if (childDoc.location.href == "chrome://global/content/selectDialog.xul")
return childDoc;
}
}
return null;
}

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

@ -0,0 +1,981 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Modal Prompts Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Prompter tests: modal prompts
<p id="display"></p>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.8">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService2);
function checkExpectedState(doc, state) {
let msg = doc.getElementById("info.body").textContent;
let icon = doc.getElementById("info.icon");
let textOuter = doc.getElementById("loginContainer");
let passOuter = doc.getElementById("password1Container");
let checkOuter = doc.getElementById("checkboxContainer");
let textField = doc.getElementById("loginTextbox");
let passField = doc.getElementById("password1Textbox");
let checkbox = doc.getElementById("checkbox");
let textValue = textField.getAttribute("value");
let passValue = passField.getAttribute("value");
is(msg, state.msg, "Checking expected message");
// XXX check title? OS X has title in content
is(icon.className, "spaced " + state.iconClass, "Checking expected icon CSS class");
is(textOuter.hidden, state.textHidden, "Checking textbox visibility");
is(passOuter.hidden, state.passHidden, "Checking passbox visibility");
is(checkOuter.hidden, state.checkHidden, "Checking checkbox visibility");
is(textValue, state.textValue, "Checking textbox value");
is(passValue, state.passValue, "Checking passbox value");
is(checkbox.label, state.checkMsg, "Checking checkbox label");
is(checkbox.checked, state.checked, "Checking checkbox checked");
}
function checkExpectedSelectState(doc, state) {
let msg = doc.getElementById("info.txt").value;
// XXX check title? OS X has title in content
let listbox = doc.getElementById("list");
is(msg, state.msg, "Checking expected message");
// XXX check title? OS X has title in content
// Compare listbox contents
let count = listbox.itemCount;
is(count, state.items.length, "Checking listbox length");
if (count)
is(listbox.selectedIndex, 0, "Checking selected index");
for (let i = 0; i < count; i++) {
let item = listbox.getItemAtIndex(i).label;
is(item, items[i], "Checking item #" + i + " label");
}
}
/*
* handleDialog
*
* Invoked a short period of time after calling startCallbackTimer(), and
* allows testing the actual prompt dialog while it's being displayed. Tests
* should call startCallbackTimer() each time the auth dialog is expected (the
* timer is a one-shot).
*/
function handleDialog(doc, testNum) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
ok(true, "--- handleDialog for test " + testNum + " ---");
let textField = doc.getElementById("loginTextbox");
let passField = doc.getElementById("password1Textbox");
let checkbox = doc.getElementById("checkbox");
let dialog = doc.getElementsByTagName("dialog")[0];
let listbox = doc.getElementById("list"); // only relevant for selectDialog
let clickOK = true;
let state;
// XXX check focused element
// XXX check text/passbox labels?
// XXX check button labels?
switch(testNum) {
case 1:
// Alert
state = {
msg : "This is the alert text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
//is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum);
//doc.commandDispatcher.rewindFocus();
//is(doc.activeElement, body, "description focusable");
break;
case 2:
// AlertCheck (null checkbox label, so it's hidden)
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
break;
case 3:
// AlertCheck
state = {
msg : "This is the alertCheck text.",
title : "TestTitle",
iconClass : "alert-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 4:
// Confirm (ok)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
break;
case 5:
// Confirm (cancel)
state = {
msg : "This is the confirm text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
clickOK = false;
break;
case 6:
// ConfirmCheck (no checkbox, ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
break;
case 7:
// ConfirmCheck (no checkbox, cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
clickOK = false;
break;
case 8:
// ConfirmCheck (ok)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 9:
// ConfirmCheck (cancel)
state = {
msg : "This is the confirmCheck text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
clickOK = false;
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 10:
// Prompt (ok, no default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
textField.setAttribute("value", "bacon");
break;
case 11:
// Prompt (ok, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "kittens",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
break;
case 12:
// Prompt (cancel, default text)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
clickOK = false;
break;
case 13:
// Prompt (cancel, default text modified)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : true,
textValue : "puppies",
passValue : "",
checkMsg : "",
checked : false,
};
checkExpectedState(doc, state);
textField.setAttribute("value", "bacon");
clickOK = false;
break;
case 14:
// Prompt (ok, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : false,
textValue : "tribbles",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 15:
// Prompt (cancel, with checkbox)
state = {
msg : "This is the prompt text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : false,
passHidden : true,
checkHidden : false,
textValue : "tribbles",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
clickOK = false;
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 16:
// PromptUsernameAndPassword (ok, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "usr",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
textField.setAttribute("value", "newusr");
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 17:
// PromptUsernameAndPassword (cancel, with checkbox)
state = {
msg : "This is the pUAP text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : false,
passHidden : false,
checkHidden : false,
textValue : "usr",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
textField.setAttribute("value", "newusr");
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 18:
// PromptPassword (ok, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : true,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 19:
// PromptPassword (cancel, with checkbox)
state = {
msg : "This is the promptPassword text.",
title : "TestTitle",
iconClass : "authentication-icon question-icon",
textHidden : true,
passHidden : false,
checkHidden : false,
textValue : "",
passValue : "ssh",
checkMsg : "Check me out!",
checked : false,
};
checkExpectedState(doc, state);
passField.setAttribute("value", "newssh");
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 20:
// Select (0 items)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : [],
};
checkExpectedSelectState(doc, state);
break;
case 21:
// Select (3 items, default ok)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
break;
case 22:
// Select (3 items, change selection, ok)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
// XXX need to trigger old code's click listener
listbox.selectedIndex = 1;
//listbox.getItemAtIndex(1).click();
break;
case 23:
// Select (3 items, cancel)
state = {
msg : "This is the select text.",
title : "TestTitle",
items : ["one", "two", "three"],
};
checkExpectedSelectState(doc, state);
clickOK = false;
break;
case 24:
// ConfirmEx (ok/cancel, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
is(dialog.getButton("accept").label, "OK", "Checking accept-button label");
is(dialog.getButton("cancel").label, "Cancel", "Checking cancel-button label");
checkExpectedState(doc, state);
break;
case 25:
// ConfirmEx (yes/no, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : true,
textValue : "",
passValue : "",
checkMsg : "",
checked : false,
};
is(dialog.getButton("accept").label, "Yes", "Checking accept-button label");
is(dialog.getButton("cancel").label, "No", "Checking cancel-button label");
checkExpectedState(doc, state);
clickOK = false;
break;
case 26:
// ConfirmEx (buttons from args, checkbox, ok)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
break;
case 27:
// ConfirmEx (buttons from args, checkbox, cancel)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
// XXX check button1 is default
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
clickOK = false;
break;
case 28:
// ConfirmEx (buttons from args, checkbox, button3)
state = {
msg : "This is the confirmEx text.",
title : "TestTitle",
iconClass : "question-icon",
textHidden : true,
passHidden : true,
checkHidden : false,
textValue : "",
passValue : "",
checkMsg : "Check me out!",
checked : false,
};
// XXX check button2 is default
is(dialog.getButton("accept").label, "butt0", "Checking accept-button label");
is(dialog.getButton("cancel").label, "butt1", "Checking cancel-button label");
is(dialog.getButton("extra1").label, "butt2", "Checking extra1-button label");
checkExpectedState(doc, state);
// XXX dumb. old code driven by oncommand.
checkbox.setChecked(true);
checkbox.doCommand();
// XXX how to click button 3?
clickOK = false;
break;
default:
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
break;
}
if (testNum == 28) {
dialog._doButtonCommand("extra1");
} else {
if (clickOK)
dialog.acceptDialog();
else
dialog.cancelDialog();
}
ok(true, "handleDialog done");
didDialog = true;
}
let testNum = 0;
let checkVal = {};
let textVal = {};
let passVal = {};
let selectVal = {};
let flags;
let isOK, clickedButton;
// ===== test 1 =====
// Alert
testNum++;
startCallbackTimer();
prompter.alert(window, "TestTitle", "This is the alert text.");
ok(didDialog, "handleDialog was invoked");
// ===== test 2 =====
// AlertCheck (null checkbox label)
testNum++;
startCallbackTimer();
prompter.alertCheck(window, "TestTitle", "This is the alertCheck text.", null, {});
ok(didDialog, "handleDialog was invoked");
// ===== test 3 =====
// AlertCheck
testNum++;
startCallbackTimer();
checkVal.value = false;
prompter.alertCheck(window, "TestTitle", "This is the alertCheck text.", "Check me out!", checkVal);
ok(didDialog, "handleDialog was invoked");
is(checkVal.value, true, "checkbox was checked");
// ===== test 4 =====
// Confirm (ok)
testNum++;
startCallbackTimer();
isOK = prompter.confirm(window, "TestTitle", "This is the confirm text.");
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 5 =====
// Confirm (cancel)
testNum++;
startCallbackTimer();
isOK = prompter.confirm(window, "TestTitle", "This is the confirm text.");
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 6 =====
// ConfirmCheck (ok, null checkbox label)
testNum++;
startCallbackTimer();
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", null, {});
is(isOK, true, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 7 =====
// ConfirmCheck (cancel, null checkbox label)
testNum++;
startCallbackTimer();
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", null, {});
is(isOK, false, "checked expected retval");
ok(didDialog, "handleDialog was invoked");
// ===== test 8 =====
// ConfirmCheck (ok)
testNum++;
startCallbackTimer();
checkVal.value = false;
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal);
is(isOK, true, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 9 =====
// ConfirmCheck (cancel)
testNum++;
startCallbackTimer();
checkVal.value = false;
isOK = prompter.confirmCheck(window, "TestTitle", "This is the confirmCheck text.", "Check me out!", checkVal);
is(isOK, false, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 10 =====
// Prompt (ok, no default text)
testNum++;
startCallbackTimer();
textVal.value = "";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
is(isOK, true, "checked expected retval");
is(textVal.value, "bacon", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 11 =====
// Prompt (ok, default text)
testNum++;
startCallbackTimer();
textVal.value = "kittens";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
is(isOK, true, "checked expected retval");
is(textVal.value, "kittens", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 12 =====
// Prompt (cancel, default text)
testNum++;
startCallbackTimer();
textVal.value = "puppies";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 13 =====
// Prompt (cancel, default text modified)
testNum++;
startCallbackTimer();
textVal.value = "puppies";
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, null, {});
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
ok(didDialog, "handleDialog was invoked");
// ===== test 14 =====
// Prompt (ok, with checkbox)
testNum++;
startCallbackTimer();
textVal.value = "tribbles";
checkVal.value = false;
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal);
is(isOK, true, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 15 =====
// Prompt (cancel, with checkbox)
testNum++;
startCallbackTimer();
textVal.value = "tribbles";
checkVal.value = false;
isOK = prompter.prompt(window, "TestTitle", "This is the prompt text.", textVal, "Check me out!", checkVal);
is(isOK, false, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 16 =====
// PromptUsernameAndPassword (ok)
// Just two tests for this, since password manager already tests this extensively.
testNum++;
startCallbackTimer();
textVal.value = "usr";
passVal.value = "ssh";
checkVal.value = false;
isOK = prompter.promptUsernameAndPassword(window, "TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal);
is(isOK, true, "checked expected retval");
is(textVal.value, "newusr", "checking expected text value");
is(passVal.value, "newssh", "checking expected pass value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 17 =====
// PromptUsernameAndPassword (cancel)
testNum++;
startCallbackTimer();
textVal.value = "usr";
passVal.value = "ssh";
checkVal.value = false;
isOK = prompter.promptUsernameAndPassword(window, "TestTitle", "This is the pUAP text.", textVal, passVal, "Check me out!", checkVal);
is(isOK, false, "checked expected retval");
is(textVal.value, "usr", "checking expected text value");
is(passVal.value, "ssh", "checking expected pass value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 18 =====
// PromptPassword (ok)
testNum++;
startCallbackTimer();
passVal.value = "ssh";
checkVal.value = false;
isOK = prompter.promptPassword(window, "TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal);
is(isOK, true, "checked expected retval");
is(passVal.value, "newssh", "checking expected pass value");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 19 =====
// PromptPassword (cancel)
testNum++;
startCallbackTimer();
passVal.value = "ssh";
checkVal.value = false;
isOK = prompter.promptPassword(window, "TestTitle", "This is the promptPassword text.", passVal, "Check me out!", checkVal);
is(isOK, false, "checked expected retval");
is(passVal.value, "ssh", "checking expected pass value");
is(checkVal.value, false, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 20 =====
// Select (0 items, ok)
testNum++;
startCallbackTimer();
items = [];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 21 =====
// Select (3 items, ok)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 22 =====
// Select (3 items, selection changed, ok)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 1, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 23 =====
// Select (3 items, cancel)
testNum++;
startCallbackTimer();
items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
is(isOK, false, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
ok(didDialog, "handleDialog was invoked");
// ===== test 24 =====
// ConfirmEx (ok/cancel, ok)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_OK_CANCEL_BUTTONS;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {});
is(clickedButton, 0, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 25 =====
// ConfirmEx (yes/no, cancel)
testNum++;
startCallbackTimer();
flags = Ci.nsIPromptService.STD_YES_NO_BUTTONS;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags, null, null, null, null, {});
is(clickedButton, 1, "checked expected button num click");
ok(didDialog, "handleDialog was invoked");
// ===== test 26 =====
// ConfirmEx (buttons from args, checkbox, ok)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
checkVal.value = false;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 0, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 27 =====
// ConfirmEx (buttons from args, checkbox, cancel)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
flags ^= Ci.nsIPromptService.BUTTON_POS_1_DEFAULT;
checkVal.value = false;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 1, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// ===== test 28 =====
// ConfirmEx (buttons from args, checkbox, button3)
testNum++;
startCallbackTimer();
let b = Ci.nsIPromptService.BUTTON_TITLE_IS_STRING;
flags = b * Ci.nsIPromptService.BUTTON_POS_2 +
b * Ci.nsIPromptService.BUTTON_POS_1 +
b * Ci.nsIPromptService.BUTTON_POS_0;
flags ^= Ci.nsIPromptService.BUTTON_POS_2_DEFAULT;
checkVal.value = false;
clickedButton = prompter.confirmEx(window, "TestTitle", "This is the confirmEx text.", flags,
"butt0", "butt1", "butt2", "Check me out!", checkVal);
is(clickedButton, 2, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
ok(didDialog, "handleDialog was invoked");
// promptAuth already tested via password manager
</script>
</pre>
</body>
</html>