fune/toolkit/components/prompts/test/test_modal_select.html
2018-06-16 08:21:33 +00:00

143 lines
4.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Modal Prompts Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/AddTask.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">
const { Services } = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm");
function checkPromptState(promptState, expectedState) {
// XXX check title? OS X has title in content
// XXX check focused element
// XXX check button labels?
is(promptState.msg, expectedState.msg, "Checking expected message");
// Compare listbox contents
is(promptState.items.length, expectedState.items.length, "Checking listbox length");
if (promptState.items.length)
is(promptState.selectedIndex, 0, "Checking selected index");
for (let i = 0; i < promptState.items; i++) {
is(promptState.items[i], expectedState.items[i], "Checking list item #" + i);
}
}
let selectVal = {};
let isOK;
function handlePrompt(state, action) {
return new Promise(resolve => {
gChromeScript.addMessageListener("promptHandled", function handled(msg) {
gChromeScript.removeMessageListener("promptHandled", handled);
checkPromptState(msg.promptState, state);
resolve(true);
});
gChromeScript.sendAsyncMessage("handlePrompt", { action, isSelect: true});
});
}
// =====
add_task(async function test_select_empty_list() {
info("Starting test: Select (0 items, ok)");
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: [],
};
let action = {
buttonClick: "ok",
};
let promptDone = handlePrompt(state, action);
let items = [];
selectVal.value = null; // outparam, just making sure.
isOK = Services.prompt.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");
await promptDone;
});
// =====
add_task(async function test_select_ok() {
info("Starting test: Select (3 items, ok)");
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
let action = {
buttonClick: "ok",
};
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = Services.prompt.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");
await promptDone;
});
// =====
add_task(async function test_select_item() {
info("Starting test: Select (3 items, selection changed, ok)");
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
let action = {
buttonClick: "ok",
selectItem: 1,
};
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = Services.prompt.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");
await promptDone;
});
// =====
add_task(async function test_cancel_prompt() {
info("Starting test: Select (3 items, cancel)");
let state = {
msg: "This is the select text.",
title: "TestTitle",
items: ["one", "two", "three"],
};
let action = {
buttonClick: "cancel",
};
let promptDone = handlePrompt(state, action);
let items = ["one", "two", "three"];
selectVal.value = null; // outparam, just making sure.
isOK = Services.prompt.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");
await promptDone;
});
</script>
</pre>
</body>
</html>