Backed out 3 changesets (bug 1622836, bug 1271842) for mochitest failures on test_prompt.html. CLOSED TREE

Backed out changeset cdedf7ddec47 (bug 1622836)
Backed out changeset 7262ae6d42ec (bug 1271842)
Backed out changeset 091a64a38136 (bug 1271842)
This commit is contained in:
Cosmin Sabou 2020-04-21 22:06:48 +03:00
Родитель 9d0c656a33
Коммит 2dfd2276b9
19 изменённых файлов: 344 добавлений и 1728 удалений

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

@ -254,7 +254,7 @@ class PromptParent extends JSWindowActorParent {
* @resolves {Object}
* The arguments returned from the window prompt.
*/
async openWindowPrompt(args, browsingContext = this.browsingContext) {
openWindowPrompt(args, browsingContext = this.browsingContext) {
const COMMON_DIALOG = "chrome://global/content/commonDialog.xhtml";
const SELECT_DIALOG = "chrome://global/content/selectDialog.xhtml";
let uri = args.promptType == "select" ? SELECT_DIALOG : COMMON_DIALOG;
@ -296,6 +296,6 @@ class PromptParent extends JSWindowActorParent {
PromptUtils.fireDialogEvent(win, "DOMModalDialogClosed", browser);
}
}
return args;
return Promise.resolve(args);
}
}

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

@ -56,7 +56,6 @@ js_source_path = [
'toolkit/components/extensions/parent',
'toolkit/components/featuregates',
'toolkit/mozapps/extensions',
'toolkit/components/prompts/src',
]
root_for_relative_js_paths = '.'
jsdoc_config_path = 'jsdoc.json'

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

@ -1,10 +0,0 @@
=======
Prompts
=======
.. toctree::
:maxdepth: 1
nsIPromptService
nsIPromptService-reference
modalTypes

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 35 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 40 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 48 KiB

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

@ -1,95 +0,0 @@
==================
Prompt Modal Types
==================
Window Prompts
--------------
Window prompts are system prompts. They are clearly distinguishable from website
content and can be opened with or without a parent window.
While a window prompt is open, the parent window cannot be interacted with.
That means the user can not close the window or switch tabs.
Providing a parent window is optional, but highly encouraged. If you do not
pass a parent the implementation will try to find one or fallback to aborted
standalone window.
**When to use**: This should be reserved for important browser-wide messages
with the intent to block any further user interaction until the message has been
read.
**Flag**: `MODAL_TYPE_WINDOW`
.. caution::
When using window prompts, make sure they can not be spawned by web content.
We've seen `cases <https://bugzilla.mozilla.org/show_bug.cgi?id=1571003>`_
of DoS attacks in the wild where websites spammed window prompts to lock up
the browser.
This prompt type should only be used when necessary and with proper rate
limiting. Most of the time, a tab prompt can be be used.
.. figure:: modal-type-window.png
:width: 425px
:height: 230px
:alt: Screenshot of a window prompt.
Window alert prompt
Tab Prompts
-----------
Tab prompts are system prompts like window prompts. As opposed to window
prompts, they are tab modal and don't steal focus from the parent window.
Multiple tab prompts cannot be shown at the same time. When opening additional
prompts, they are FIFO queued.
When the user closes the tab or navigates to a different URI, prompts associated
with the given tab are closed.
In this case an exception will be thrown:
.. code-block::
/*
Exception: prompt aborted by user
undefined:425
*/
**When to use**: This prompt should be used for dialogs that were caused by web
content and thus should be bound to the scope and lifetime of a specific tab,
but should still look like secure browser UI. Examples are HTTP Auth prompt or
the dialog to add a new search provider for the current website.
**Flag**: `MODAL_TYPE_TAB`
.. figure:: modal-type-tab.png
:width: 425px
:height: 230px
:alt: Screenshot of a tab prompt.
Tab alert prompt
Content Prompts
---------------
Content prompts are like tab prompts, but they belong to the web content. Thus,
they are positioned in the center of the selected browser.
**When to use**: The prompt is triggered by or as a result of an action of web
content and is **not** intended to look like secure browser UI.
**Flag**: `MODAL_TYPE_CONTENT`
.. figure:: modal-type-content.png
:width: 425px
:height: 230px
:alt: Screenshot of a content prompt.
Content alert prompt
Disabling tab/content modal prompts
-----------------------------------
You can disable tab and content modal prompts and get back window-modal prompts
by setting the `prompts.tab_modal.enabled` preference to `false`.
This pref might be removed in the future.

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

@ -1,10 +0,0 @@
========================
Prompt Service Reference
========================
This is the JSDoc from the Prompter.jsm implementation. You can find the full
interface definition in
`nsIPromptService.idl <https://searchfox.org/mozilla-central/source/toolkit/components/windowwatcher/nsIPromptService.idl>`_.
.. js:autoclass:: Prompter
:members:

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

@ -1,195 +0,0 @@
==============
Prompt Service
==============
The `nsIPromptService` provides methods for opening various types of prompts.
See the `interface documentation <nsIPromptService-reference.html>`_ for a list
of prompt types.
Every prompt method has 3 different versions:
- **Prompt by window**:
This is considered the legacy way of prompting and only works if the window
you want to prompt for is in the same process.
Only supports window prompts.
- **Prompt by browsing context (synchronous)**:
Use a browsing context as parent for the prompt. Works cross process from
parent and content process.
- **Prompt by browsing context (asynchronous)**:
Returns a promise which resolves once the prompt closes.
The synchronous prompt methods use call by reference (XPCOM `inout` or `out`) to
return the updated prompt arguments to the caller.
When prompting async the arguments are passed in by value. Prompt results are
returned in an `nsIPropertyBag` when the Promise resolves.
.. note::
If you don't provide a parent window or browsing context the prompt service
will fallback to a window prompt.
The same goes for browsing contexts of chrome windows, because there is no
clear association to a browser / tab.
Examples
--------
JavaScript Sync
~~~~~~~~~~~~~~~
Here is an example of opening a confirm prompt from JavaScript. We are in the
parent process and we want to show a tab prompt:
.. code-block:: javascript
// Get the browsing context for the currently selected tab
let browsingContext = gBrowser.selectedBrowser.browsingContext;
// Specify prompt type, can be MODAL_TYPE_TAB, MODAL_TYPE_CONTENT,
// MODAL_TYPE_WINDOW
let modalType = Services.prompt.MODAL_TYPE_TAB;
// Object for checkbox state to pass by reference.
let check = { value: false };
// Prompt synchronously and store result
let confirmed = Services.prompt.confirmCheckBC(browsingContext, modalType,
"My Title", "Hello, World!", "Check this box if you agree", check);
// check.value now contains final checkbox state
// confirmed is a boolean which indicates whether the user pressed ok (true)
// or cancel (false)
console.debug("User checked checkbox?", check.value);
console.debug("User confirmed prompt?", confirmed);
JavaScript Async
~~~~~~~~~~~~~~~~
The same prompt as above, but called async:
.. code-block:: javascript
// Get the browsing context for the currently selected tab
let browsingContext = gBrowser.selectedBrowser.browsingContext;
// Specify prompt type, can be MODAL_TYPE_TAB, MODAL_TYPE_CONTENT,
// MODAL_TYPE_WINDOW
let modalType = Services.prompt.MODAL_TYPE_TAB;
// Note that the checkbox state variable is not an object in this case,
because we get the checkbox result via the result object.
let check = false;
// Prompt asynchronously and await result
let propBag = await Services.prompt.asyncConfirmCheck(browsingContext,
modalType,
"My Title",
"Hello, World!",
"Check this box if you agree",
check);
let ok = propBag.getProperty("ok");
let checked = propBag.getProperty("checked");
// ok is the boolean indicating if the user clicked "ok" (true) or
// "cancel" (false).
// checked is a boolean indicating the final checkbox state
console.debug("User checked checkbox?", checked);
console.debug("User confirmed prompt?", ok);
C++ Sync
~~~~~~~~
.. code-block:: c++
nsCOMPtr<nsIPromptService> promptSvc =
do_GetService("@mozilla.org/embedcomp/prompt-service;1");
if(!promptSvc) {
// Error handling
return;
}
// Assuming you have the browsing context as a member.
// You might need to get the browsing context from somewhere else.
BrowsingContext* bc = mBrowsingContext;
bool ok;
bool checked = false;
nsresult rv = promptSvc->confirmCheck(mBrowsingContext,
nsIPromptService::MODAL_TYPE_TAB,
NS_LITERAL_CSTRING("My Title")
NS_LITERAL_CSTRING("Hello, World!"),
NS_LITERAL_CSTRING("Check this box if you agree"),
&checked, &ok);
// ok is the boolean indicating if the user clicked "ok" (true) or
// "cancel" (false).
// checked is a boolean indicating the final checkbox state
C++ Async
~~~~~~~~~
.. code-block:: c++
nsCOMPtr<nsIPromptService> promptSvc =
do_GetService("@mozilla.org/embedcomp/prompt-service;1");
if(!promptSvc) {
// Error handling
return;
}
bool checked = false;
Promise* promise;
// Assuming you have the browsing context as a member.
// You might need to get the browsing context from somewhere else.
BrowsingContext* bc = mBrowsingContext;
// As opposed to the sync case, here we pass the checked flag by value
nsresult rv = promptSvc->confirmCheckAsync(mBrowsingContext,
nsIPromptService::MODAL_TYPE_TAB, NS_LITERAL_CSTRING("My Title"),
NS_LITERAL_CSTRING("Hello, World!"),
NS_LITERAL_CSTRING("Check this box if you agree"),
checked, promise);
// Attach a promise handler
RefPtr<PromptHandler> handler = new PromptHandler(promise);
promise->AppendNativeHandler(handler);
Then, in your promise handler callback function:
.. code-block:: c++
void PromptHandler::ResolvedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue) {
JS::Rooted<JSObject*> detailObj(aCx, &aValue.toObject());
// Convert the JSObject back to a property bag
nsresult rv;
nsCOMPtr<nsIPropertyBag2> propBag;
rv = UnwrapArg<nsIPropertyBag2>(aCx, detailObj, getter_AddRefs(propBag));
if (NS_FAILED(rv)) return;
bool ok;
bool checked;
propBag->GetPropertyAsBool(NS_LITERAL_STRING("ok"), &ok);
propBag->GetPropertyAsBool(NS_LITERAL_STRING("checked"), &checked);
// ok is the boolean indicating if the user clicked "ok" (true) or
// "cancel" (false).
// checked is a boolean indicating the final checkbox state.
}
For a full list of prompt methods check
`nsIPromptService reference <nsIPromptService-reference.html>`_.

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

@ -10,12 +10,6 @@ with Files('**'):
DIRS += ['src']
SPHINX_TREES['prompts'] = 'docs'
with Files('docs/**'):
SCHEDULES.exclusive = ['docs']
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
JAR_MANIFESTS += ['jar.mn']

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,9 +0,0 @@
[DEFAULT]
support-files =
prompt_common.js
chromeScript.js
[test_modal_prompts.html]
skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) #android: TIMED_OUT (For Linux : 950636)
[test_modal_select.html]
skip-if = toolkit == 'android' #android: TIMED_OUT

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

@ -13,3 +13,7 @@ skip-if = toolkit == 'android' #TIMED_OUT
skip-if = toolkit == 'android' || verify
[test_dom_prompts.html]
skip-if = toolkit == 'android' #android: bug 1267092
[test_modal_prompts.html]
skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) #android: TIMED_OUT (For Linux : 950636)
[test_modal_select.html]
skip-if = toolkit == 'android' #android: TIMED_OUT

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

@ -1,12 +1,9 @@
const { Cc, Ci } = SpecialPowers;
const { propBagToObject } = ChromeUtils.import(
"resource://gre/modules/BrowserUtils.jsm"
).BrowserUtils;
function hasTabModalPrompts() {
var prefName = "prompts.tab_modal.enabled";
const Services = SpecialPowers.Services;
var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm")
.Services;
return (
Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
Services.prefs.getBoolPref(prefName)
@ -22,133 +19,6 @@ var gChromeScript = SpecialPowers.loadChromeScript(
);
SimpleTest.registerCleanupFunction(() => gChromeScript.destroy());
async function runPromptCombinations(window, testFunc) {
let util = new PromptTestUtil(window);
let run = () => {
info(
`Running tests (isTabModal=${isTabModal}, usePromptService=${util.usePromptService}, useBrowsingContext=${util.useBrowsingContext}, useAsync=${util.useAsync})`
);
return testFunc(util);
};
// Prompt service with dom window parent only supports window prompts
util.usePromptService = true;
util.useBrowsingContext = false;
isTabModal = false;
util.modalType = Ci.nsIPrompt.MODAL_TYPE_WINDOW;
util.useAsync = false;
await run();
let modalTypes = [Ci.nsIPrompt.MODAL_TYPE_WINDOW];
// if tab/content prompts are disabled by pref, only test window prompts
if (SpecialPowers.getBoolPref("prompts.tab_modal.enabled")) {
modalTypes.push(Ci.nsIPrompt.MODAL_TYPE_TAB);
modalTypes.push(Ci.nsIPrompt.MODAL_TYPE_CONTENT);
}
for (let type of modalTypes) {
util.modalType = type;
isTabModal = type !== Ci.nsIPrompt.MODAL_TYPE_WINDOW;
// Prompt service with browsing context sync
util.usePromptService = true;
util.useBrowsingContext = true;
util.useAsync = false;
await run();
// Prompt service with browsing context async
util.usePromptService = true;
util.useBrowsingContext = true;
util.useAsync = true;
await run();
// nsIPrompt
// modalType is set via nsIWritablePropertyBag (legacy)
util.usePromptService = false;
util.useBrowsingContext = false;
util.useAsync = false;
await run();
}
}
class PromptTestUtil {
constructor(window) {
this.window = window;
this.browsingContext = SpecialPowers.wrap(
window
).windowGlobalChild.browsingContext;
this.promptService = SpecialPowers.Services.prompt;
this.nsPrompt = Cc["@mozilla.org/prompter;1"]
.getService(Ci.nsIPromptFactory)
.getPrompt(window, Ci.nsIPrompt);
this.usePromptService = null;
this.useBrowsingContext = null;
this.useAsync = null;
this.modalType = null;
}
get _prompter() {
if (this.usePromptService) {
return this.promptService;
}
return this.nsPrompt;
}
async prompt(funcName, promptArgs) {
if (
this.useBrowsingContext == null ||
this.usePromptService == null ||
this.useAsync == null ||
this.modalType == null
) {
throw new Error("Not initialized");
}
let args = [];
if (this.usePromptService) {
if (this.useBrowsingContext) {
if (this.useAsync) {
funcName = `async${funcName[0].toUpperCase()}${funcName.substring(
1
)}`;
} else {
funcName += "BC";
}
args = [this.browsingContext, this.modalType];
} else {
args = [this.window];
}
} else {
let bag = this.nsPrompt.QueryInterface(Ci.nsIWritablePropertyBag2);
bag.setPropertyAsUint32("modalType", this.modalType);
}
// Append the prompt arguments
args = args.concat(promptArgs);
let interfaceName = this.usePromptService ? "Services.prompt" : "prompt";
ok(
this._prompter[funcName],
`${interfaceName} should have method ${funcName}.`
);
info(`Calling ${interfaceName}.${funcName}(${args})`);
let result = this._prompter[funcName](...args);
is(
this.useAsync,
result != null &&
result.constructor != null &&
result.constructor.name === "Promise",
"If method is async it should return a promise."
);
if (this.useAsync) {
let propBag = await result;
return propBag && propBagToObject(propBag);
}
return result;
}
}
function onloadPromiseFor(id) {
var iframe = document.getElementById(id);
return new Promise(resolve => {

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

@ -1,34 +1,72 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<title>Modal Prompts Test</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="prompt_common.js"></script>
</head>
<body>
Prompter tests: modal prompts
<p id="display"></p>
<head>
<title>Modal Prompts Test</title>
<script 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>
<div id="content" style="display: none">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<pre id="test">
<script class="testbody" type="text/javascript">
/* eslint-disable complexity */
async function runTests(util) {
async function runTests() {
const { NetUtil } = SpecialPowers.Cu.import(
"resource://gre/modules/NetUtil.jsm"
);
const { Services } = SpecialPowers.Cu.import(
"resource://gre/modules/Services.jsm"
);
let state, action, promptDone;
ok(
true,
"Running tests (isTabModal=" +
isTabModal +
", usePromptService=" +
usePromptService +
", useBrowsingContext=" +
useBrowsingContext +
")"
);
let browsingContext = SpecialPowers.wrap(window).windowGlobalChild
.browsingContext;
let promptArgs;
let prompter = Cc["@mozilla.org/prompter;1"]
.getService(Ci.nsIPromptFactory)
.getPrompt(window, Ci.nsIPrompt);
let checkVal = {};
let textVal = {};
let passVal = {};
let flags;
let isOK;
let isOK, clickedButton;
function doPrompt(funcName) {
let subject;
if (usePromptService) {
subject = Services.prompt;
if (useBrowsingContext) {
funcName += "BC";
promptArgs.unshift(browsingContext, modalType);
} else {
promptArgs.unshift(window);
}
} else {
subject = prompter;
let bag = prompter.QueryInterface(Ci.nsIWritablePropertyBag2);
bag.setPropertyAsUint32("modalType", modalType);
}
return subject[funcName](...promptArgs);
}
// =====
info("Starting test: Alert");
@ -54,7 +92,7 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = ["TestTitle", "This is the alert text."];
await util.prompt("alert", promptArgs);
doPrompt("alert");
await promptDone;
@ -81,13 +119,8 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = [
"TestTitle",
"This is the alertCheck text.",
null,
util.useAsync ? false : {},
];
util.prompt("alertCheck", promptArgs);
promptArgs = ["TestTitle", "This is the alertCheck text.", null, {}];
doPrompt("alertCheck");
await promptDone;
@ -120,14 +153,10 @@ async function runTests(util) {
"TestTitle",
"This is the alertCheck text.",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
let result = await util.prompt("alertCheck", promptArgs);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"checkbox was checked"
);
doPrompt("alertCheck");
is(checkVal.value, true, "checkbox was checked");
await promptDone;
@ -155,8 +184,8 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = ["TestTitle", "This is the confirm text."];
result = await util.prompt("confirm", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
isOK = doPrompt("confirm");
is(isOK, true, "checked expected retval");
await promptDone;
@ -184,8 +213,8 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = ["TestTitle", "This is the confirm text."];
result = await util.prompt("confirm", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
isOK = doPrompt("confirm");
is(isOK, false, "checked expected retval");
await promptDone;
@ -212,14 +241,9 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = [
"TestTitle",
"This is the confirmCheck text.",
null,
util.useAsync ? false : {},
];
result = await util.prompt("confirmCheck", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}];
isOK = doPrompt("confirmCheck");
is(isOK, true, "checked expected retval");
await promptDone;
@ -246,14 +270,9 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = [
"TestTitle",
"This is the confirmCheck text.",
null,
util.useAsync ? false : {},
];
result = await util.prompt("confirmCheck", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
promptArgs = ["TestTitle", "This is the confirmCheck text.", null, {}];
isOK = doPrompt("confirmCheck");
is(isOK, false, "checked expected retval");
await promptDone;
@ -286,15 +305,11 @@ async function runTests(util) {
"TestTitle",
"This is the confirmCheck text.",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("confirmCheck", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
isOK = doPrompt("confirmCheck");
is(isOK, true, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -327,15 +342,11 @@ async function runTests(util) {
"TestTitle",
"This is the confirmCheck text.",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("confirmCheck", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
isOK = doPrompt("confirmCheck");
is(isOK, false, "checked expected retval");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -364,14 +375,10 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
textVal.value = "";
promptArgs = ["TestTitle", "This is the prompt text.", util.useAsync ? textVal.value : textVal , null, util.useAsync ? false : {}];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"bacon",
"checking expected text value"
);
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
isOK = doPrompt("prompt");
is(isOK, true, "checked expected retval");
is(textVal.value, "bacon", "checking expected text value");
await promptDone;
@ -399,14 +406,10 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
textVal.value = "kittens";
promptArgs = ["TestTitle", "This is the prompt text.", util.useAsync ? textVal.value : textVal, null, util.useAsync ? false : {}];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"kittens",
"checking expected text value"
);
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
isOK = doPrompt("prompt");
is(isOK, true, "checked expected retval");
is(textVal.value, "kittens", "checking expected text value");
await promptDone;
@ -434,14 +437,10 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
textVal.value = "puppies";
promptArgs = ["TestTitle", "This is the prompt text.", util.useAsync ? textVal.value : textVal, null, util.useAsync ? false : {}];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"puppies",
"checking expected text value"
);
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
isOK = doPrompt("prompt");
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
await promptDone;
@ -470,14 +469,10 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
textVal.value = "puppies";
promptArgs = ["TestTitle", "This is the prompt text.", util.useAsync ? textVal.value : textVal, null, util.useAsync ? false : {}];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"puppies",
"checking expected text value"
);
promptArgs = ["TestTitle", "This is the prompt text.", textVal, null, {}];
isOK = doPrompt("prompt");
is(isOK, false, "checked expected retval");
is(textVal.value, "puppies", "checking expected text value");
await promptDone;
@ -510,22 +505,14 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the prompt text.",
util.useAsync ? textVal.value : textVal,
textVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"tribbles",
"checking expected text value"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
isOK = doPrompt("prompt");
is(isOK, true, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -550,6 +537,7 @@ async function runTests(util) {
buttonClick: "cancel",
setCheckbox: true,
};
promptDone = handlePrompt(state, action);
textVal.value = "tribbles";
@ -557,21 +545,14 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the prompt text.",
util.useAsync ? textVal.value : textVal,
textVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("prompt", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
is(
util.useAsync ? result.value : textVal.value,
"tribbles",
"checking expected text value"
);
ok(
util.useAsync ? result.checked : !checkVal.value,
"expected checkbox setting"
);
isOK = doPrompt("prompt");
is(isOK, false, "checked expected retval");
is(textVal.value, "tribbles", "checking expected text value");
is(checkVal.value, false, "expected checkbox setting");
await promptDone;
@ -608,28 +589,16 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the pUAP text.",
util.useAsync ? textVal.value : textVal,
util.useAsync ? passVal.value : passVal,
textVal,
passVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("promptUsernameAndPassword", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.user : textVal.value,
"newusr",
"checking expected text value"
);
is(
util.useAsync ? result.pass : passVal.value,
"newssh",
"checking expected pass value"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
isOK = doPrompt("promptUsernameAndPassword");
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");
await promptDone;
@ -665,25 +634,16 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the pUAP text.",
util.useAsync ? textVal.value : textVal,
util.useAsync ? passVal.value : passVal,
textVal,
passVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("promptUsernameAndPassword", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
ok(
(util.useAsync && result.user == "newusr") || textVal.value == "usr",
"checking expected text value"
);
ok(
(util.useAsync && result.pass == "newpass") || passVal.value == "ssh",
"checking expected pass value"
);
ok(
util.useAsync ? result.checked : !checkVal.value,
"expected checkbox setting"
);
isOK = doPrompt("promptUsernameAndPassword");
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");
await promptDone;
@ -717,22 +677,14 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the promptPassword text.",
util.useAsync ? passVal.value : passVal,
passVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("promptPassword", promptArgs);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(
util.useAsync ? result.pass : passVal.value,
"newssh",
"checking expected pass value"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
isOK = doPrompt("promptPassword");
is(isOK, true, "checked expected retval");
is(passVal.value, "newssh", "checking expected pass value");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -766,20 +718,14 @@ async function runTests(util) {
promptArgs = [
"TestTitle",
"This is the promptPassword text.",
util.useAsync ? passVal.value : passVal,
passVal,
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("promptPassword", promptArgs);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
ok(
(util.useAsync && result.pass == "newssh") || passVal.value == "ssh",
"checking expected pass value"
);
ok(
util.useAsync ? result.checked : !checkVal.value,
"expected checkbox setting"
);
isOK = doPrompt("promptPassword");
is(isOK, false, "checked expected retval");
is(passVal.value, "ssh", "checking expected pass value");
is(checkVal.value, false, "expected checkbox setting");
await promptDone;
@ -817,14 +763,10 @@ async function runTests(util) {
null,
null,
null,
util.useAsync ? false : {},
{},
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
0,
"checked expected button num click"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 0, "checked expected button num click");
await promptDone;
@ -862,14 +804,10 @@ async function runTests(util) {
null,
null,
null,
util.useAsync ? false : {},
{},
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
1,
"checked expected button num click"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 1, "checked expected button num click");
await promptDone;
@ -914,19 +852,11 @@ async function runTests(util) {
"butt1",
"butt2",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
0,
"checked expected button num click"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 0, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -972,19 +902,11 @@ async function runTests(util) {
"butt1",
"butt2",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
1,
"checked expected button num click"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 1, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -1030,19 +952,11 @@ async function runTests(util) {
"butt1",
"butt2",
"Check me out!",
util.useAsync ? checkVal.value : checkVal,
checkVal,
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
2,
"checked expected button num click"
);
is(
util.useAsync ? result.checked : checkVal.value,
true,
"expected checkbox setting"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 2, "checked expected button num click");
is(checkVal.value, true, "expected checkbox setting");
await promptDone;
@ -1071,7 +985,7 @@ async function runTests(util) {
promptDone = handlePrompt(state, action);
promptArgs = ["TestTitle", "This is the alert text."];
await util.prompt("alert", promptArgs);
doPrompt("alert");
await promptDone;
}
@ -1119,14 +1033,10 @@ async function runTests(util) {
null,
null,
null,
util.useAsync ? false : {},
{},
];
result = await util.prompt("confirmEx", promptArgs);
is(
util.useAsync ? result.buttonNumClicked : result,
0,
"checked expected button num click"
);
clickedButton = doPrompt("confirmEx");
is(clickedButton, 0, "checked expected button num click");
await promptDone;
}
@ -1171,12 +1081,12 @@ async function runTests(util) {
textField: "username",
passField: "password",
};
if (util.usePromptService && !util.useAsync) {
if (usePromptService) {
promptDone = handlePrompt(state, action);
checkVal.value = false;
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
isOK = await util.prompt("promptAuth", promptArgs);
isOK = doPrompt("promptAuth");
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
@ -1213,7 +1123,7 @@ async function runTests(util) {
textField: "username",
passField: "password",
};
if (util.usePromptService && !util.useAsync) {
if (usePromptService) {
promptDone = handlePrompt(state, action);
checkVal.value = false;
@ -1223,7 +1133,7 @@ async function runTests(util) {
authinfo.username = "";
authinfo.password = "";
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
isOK = await util.prompt("promptAuth", promptArgs);
isOK = doPrompt("promptAuth");
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
@ -1266,11 +1176,11 @@ async function runTests(util) {
textField: "username",
passField: "password",
};
if (util.usePromptService && !util.useAsync) {
if (usePromptService) {
promptDone = handlePrompt(state, action);
checkVal.value = false;
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
isOK = await util.prompt("promptAuth", promptArgs);
isOK = doPrompt("promptAuth");
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
@ -1313,12 +1223,12 @@ async function runTests(util) {
textField: "username",
passField: "password",
};
if (util.usePromptService && !util.useAsync) {
if (usePromptService) {
promptDone = handlePrompt(state, action);
checkVal.value = false;
promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
isOK = await util.prompt("promptAuth", promptArgs);
isOK = doPrompt("promptAuth");
is(isOK, true, "checked expected retval");
is(authinfo.username, "username", "checking filled username");
is(authinfo.password, "password", "checking filled password");
@ -1328,12 +1238,44 @@ async function runTests(util) {
}
}
let promptArgs;
let usePromptService;
let useBrowsingContext;
let modalType;
add_task(async function runPromptTests() {
await runPromptCombinations(window, runTests);
info("Process type: " + SpecialPowers.Services.appinfo.processType);
// Prompt service with dom window parent only supports window prompts
usePromptService = true;
useBrowsingContext = false;
isTabModal = false;
modalType = Ci.nsIPrompt.MODAL_TYPE_WINDOW;
await runTests();
let modalTypes = [Ci.nsIPrompt.MODAL_TYPE_WINDOW];
// if tab/content prompts are disabled by pref, only test window prompts
if (SpecialPowers.getBoolPref("prompts.tab_modal.enabled")) {
modalTypes.push(Ci.nsIPrompt.MODAL_TYPE_TAB);
modalTypes.push(Ci.nsIPrompt.MODAL_TYPE_CONTENT);
}
for (let type of modalTypes) {
modalType = type;
isTabModal = type !== Ci.nsIPrompt.MODAL_TYPE_WINDOW;
// Prompt service with browsing context
usePromptService = true;
useBrowsingContext = true;
await runTests();
// nsIPrompt
// modalType is set via nsIWritablePropertyBag (legacy)
usePromptService = false;
useBrowsingContext = false;
await runTests();
}
});
</script>
</pre>
</body>
</body>
</html>

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

@ -2,8 +2,9 @@
<html>
<head>
<title>Modal Prompts Test</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script 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
@ -49,14 +50,9 @@ function handlePrompt(state, action) {
});
}
async function runTests(util) {
// Select prompt does not support tab or content prompts yet. See Bug 1622817.
if(util.modalType != Ci.nsIPrompt.MODAL_TYPE_WINDOW) {
info('Skipping modal type for select prompt...');
return;
}
// Empty list
// =====
add_task(async function test_select_empty_list() {
info("Starting test: Select (0 items, ok)");
let state = {
msg: "This is the select text.",
@ -69,69 +65,75 @@ async function runTests(util) {
let promptDone = handlePrompt(state, action);
let items = [];
selectVal.value = null; // outparam, just making sure.
let result = await util.prompt("select", ["TestTitle", "This is the select text.", items, util.useAsync ? false : selectVal]);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(util.useAsync ? result.selected : selectVal.value, -1, "checking selected index");
await promptDone;
isOK = Services.prompt.select(window, "TestTitle", "This is the select text.", items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, -1, "checking selected index");
// ok
await promptDone;
});
// =====
add_task(async function test_select_ok() {
info("Starting test: Select (3 items, ok)");
state = {
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
action = {
let action = {
buttonClick: "ok",
};
promptDone = handlePrompt(state, action);
items = ["one", "two", "three"];
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
result = await util.prompt("select", ["TestTitle", "This is the select text.", items, util.useAsync ? false : selectVal]);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(util.useAsync ? result.selected : selectVal.value, 0, "checking selected index");
await promptDone;
isOK = Services.prompt.select(window, "TestTitle", "This is the select text.", items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
// select item
await promptDone;
});
// =====
add_task(async function test_select_item() {
info("Starting test: Select (3 items, selection changed, ok)");
state = {
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
action = {
let action = {
buttonClick: "ok",
selectItem: 1,
};
promptDone = handlePrompt(state, action);
items = ["one", "two", "three"];
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
result = await util.prompt("select", ["TestTitle", "This is the select text.", items, util.useAsync ? false : selectVal]);
is(util.useAsync ? result.ok : result, true, "checked expected retval");
is(util.useAsync ? result.selected : selectVal.value, 1, "checking selected index");
await promptDone;
isOK = Services.prompt.select(window, "TestTitle", "This is the select text.", items, selectVal);
is(isOK, true, "checked expected retval");
is(selectVal.value, 1, "checking selected index");
// cancel prompt
await promptDone;
});
// =====
add_task(async function test_cancel_prompt() {
info("Starting test: Select (3 items, cancel)");
state = {
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
action = {
let action = {
buttonClick: "cancel",
};
promptDone = handlePrompt(state, action);
items = ["one", "two", "three"];
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
result = await util.prompt("select", ["TestTitle", "This is the select text.", items, util.useAsync ? false : selectVal]);
is(util.useAsync ? result.ok : result, false, "checked expected retval");
ok(util.useAsync && result.selected == -1 || selectVal.value == 0, "checking selected index");
await promptDone;
}
isOK = Services.prompt.select(window, "TestTitle", "This is the select text.", items, selectVal);
is(isOK, false, "checked expected retval");
is(selectVal.value, 0, "checking selected index");
add_task(async function runPromptTests() {
await runPromptCombinations(window, runTests);
await promptDone;
});
</script>

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

@ -59,27 +59,10 @@ interface nsIPromptService : nsISupports
void alert(in mozIDOMWindowProxy aParent,
in wstring aDialogTitle,
in wstring aText);
/**
* Like alert, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
void alertBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText);
/**
* Async version of alertBC
*
* @return A promise which resolves when the prompt is dismissed.
*/
Promise asyncAlert(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText);
/**
* Puts up an alert dialog with an OK button and a labeled checkbox.
@ -101,33 +84,12 @@ interface nsIPromptService : nsISupports
in wstring aText,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like alertCheck, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
void alertCheckBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of alertCheckBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { checked: boolean }
*/
Promise asyncAlertCheck(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Puts up a dialog with OK and Cancel buttons.
@ -144,29 +106,10 @@ interface nsIPromptService : nsISupports
boolean confirm(in mozIDOMWindowProxy aParent,
in wstring aDialogTitle,
in wstring aText);
/**
* Like confirm, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean confirmBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText);
/**
* Async version of confirmBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { ok: boolean }
*/
Promise asyncConfirm(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText);
/**
* Puts up a dialog with OK and Cancel buttons and a labeled checkbox.
@ -190,33 +133,12 @@ interface nsIPromptService : nsISupports
in wstring aText,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like confirmCheck, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean confirmCheckBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of confirmCheckBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { ok: boolean, checked: boolean }
*/
Promise asyncConfirmCheck(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Button Flags
@ -330,14 +252,6 @@ interface nsIPromptService : nsISupports
in wstring aButton2Title,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like confirmEx, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
int32_t confirmExBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
@ -348,23 +262,7 @@ interface nsIPromptService : nsISupports
in wstring aButton2Title,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of confirmExBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { checked: boolean, buttonNumClicked: int }
*/
Promise asyncConfirmEx(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in unsigned long aButtonFlags,
in wstring aButton0Title,
in wstring aButton1Title,
in wstring aButton2Title,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Puts up a dialog with an edit field and an optional, labeled checkbox.
*
@ -393,14 +291,6 @@ interface nsIPromptService : nsISupports
inout wstring aValue,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like prompt, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean promptBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
@ -408,20 +298,6 @@ interface nsIPromptService : nsISupports
inout wstring aValue,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of promptBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { checked: boolean, value: string, ok: boolean }
*/
Promise asyncPrompt(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aValue,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Puts up a dialog with an edit field, a password field, and an optional,
@ -458,14 +334,6 @@ interface nsIPromptService : nsISupports
inout wstring aPassword,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like promptUsernameAndPassword, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean promptUsernameAndPasswordBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
@ -474,21 +342,6 @@ interface nsIPromptService : nsISupports
inout wstring aPassword,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of promptUsernameAndPasswordBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { checked: boolean, user: string, pass: string, ok: boolean }
*/
Promise asyncPromptUsernameAndPassword(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aUsername,
in wstring aPassword,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Puts up a dialog with a password field and an optional, labeled checkbox.
@ -518,14 +371,6 @@ interface nsIPromptService : nsISupports
inout wstring aPassword,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Like promptPassword, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean promptPasswordBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
@ -533,20 +378,7 @@ interface nsIPromptService : nsISupports
inout wstring aPassword,
in wstring aCheckMsg,
inout boolean aCheckState);
/**
* Async version of promptPasswordBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { checked: boolean, pass: string, ok: boolean }
*/
Promise asyncPromptPassword(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in wstring aPassword,
in wstring aCheckMsg,
in boolean aCheckState);
/**
* Puts up a dialog box which has a list box of strings from which the user
* may make a single selection.
@ -570,32 +402,12 @@ interface nsIPromptService : nsISupports
in wstring aText,
in Array<AString> aSelectList,
out long aOutSelection);
/**
* Like select, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean selectBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in Array<AString> aSelectList,
out long aOutSelection);
/**
* Async version of selectBC
*
* @return A promise which resolves when the prompt is dismissed.
*
* @resolves nsIPropertyBag { selected: int, ok: boolean }
*/
Promise asyncSelect(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in wstring aDialogTitle,
in wstring aText,
in Array<AString> aSelectList);
// NOTE: These functions differ from their nsIAuthPrompt counterparts by
// having additional checkbox parameters
@ -611,14 +423,6 @@ interface nsIPromptService : nsISupports
in nsIAuthInformation authInfo,
in wstring checkboxLabel,
inout boolean checkValue);
/**
* Like promptAuth, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
boolean promptAuthBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in nsIChannel aChannel,
@ -626,6 +430,7 @@ interface nsIPromptService : nsISupports
in nsIAuthInformation authInfo,
in wstring checkboxLabel,
inout boolean checkValue);
nsICancelable asyncPromptAuth(in mozIDOMWindowProxy aParent,
in nsIChannel aChannel,
in nsIAuthPromptCallback aCallback,
@ -634,14 +439,6 @@ interface nsIPromptService : nsISupports
in nsIAuthInformation authInfo,
in wstring checkboxLabel,
inout boolean checkValue);
/**
* Like asyncPromptAuth, but with a BrowsingContext as parent.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
* @param modalType
* Whether the prompt should be window, tab or content modal.
*/
nsICancelable asyncPromptAuthBC(in BrowsingContext aBrowsingContext,
in unsigned long modalType,
in nsIChannel aChannel,

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

@ -13,7 +13,6 @@ This is the nascent documentation of the Toolkit code that is shared across Fire
components/featuregates/featuregates/index
search/index
components/normandy/normandy/index
components/prompts/prompts/index
modules/subprocess/toolkit_modules/subprocess/index
components/telemetry/index
components/glean/index

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

@ -888,66 +888,4 @@ var BrowserUtils = {
.getHistogramById("FX_NUMBER_OF_UNIQUE_SITE_ORIGINS_ALL_TABS")
.add(count);
},
/**
* Converts a property bag to object.
* @param {nsIPropertyBag} bag - The property bag to convert
* @returns {Object} - The object representation of the nsIPropertyBag
*/
propBagToObject(bag) {
function toValue(property) {
if (typeof property != "object") {
return property;
}
if (Array.isArray(property)) {
return property.map(this.toValue, this);
}
if (property && property instanceof Ci.nsIPropertyBag) {
return this.propBagToObject(property);
}
return property;
}
if (!(bag instanceof Ci.nsIPropertyBag)) {
throw new TypeError("Not a property bag");
}
let result = {};
for (let { name, value: property } of bag.enumerator) {
let value = toValue(property);
result[name] = value;
}
return result;
},
/**
* Converts an object to a property bag.
* @param {Object} obj - The object to convert.
* @returns {nsIPropertyBag} - The property bag representation of the object.
*/
objectToPropBag(obj) {
function fromValue(value) {
if (typeof value == "function") {
return null; // Emulating the behavior of JSON.stringify with functions
}
if (Array.isArray(value)) {
return value.map(this.fromValue, this);
}
if (value == null || typeof value != "object") {
// Auto-converted to nsIVariant
return value;
}
return this.objectToPropBag(value);
}
if (obj == null || typeof obj != "object") {
throw new TypeError("Invalid object: " + obj);
}
let bag = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
Ci.nsIWritablePropertyBag
);
for (let k of Object.keys(obj)) {
let value = fromValue(obj[k]);
bag.setProperty(k, value);
}
return bag;
},
};