diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/prompts/test/test_modal_select.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/prompts/test/test_modal_select.html')
-rw-r--r-- | toolkit/components/prompts/test/test_modal_select.html | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/toolkit/components/prompts/test/test_modal_select.html b/toolkit/components/prompts/test/test_modal_select.html new file mode 100644 index 000000000..1e008d0f4 --- /dev/null +++ b/toolkit/components/prompts/test/test_modal_select.html @@ -0,0 +1,146 @@ +<!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/SpawnTask.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"> + +let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Ci.nsIPromptService2); + +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; +let state, action; + +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: action, isSelect: true}); + }); +} + + +// ===== +add_task(function* test_select_empty_list() { + info("Starting test: Select (0 items, ok)"); + state = { + msg : "This is the select text.", + title : "TestTitle", + items : [], + }; + action = { + buttonClick: "ok", + }; + promptDone = handlePrompt(state, action); + 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, -1, "checking selected index"); + + yield promptDone; +}); + +// ===== +add_task(function* test_select_ok() { + info("Starting test: Select (3 items, ok)"); + state = { + msg : "This is the select text.", + title : "TestTitle", + items : ["one", "two", "three"], + }; + action = { + buttonClick: "ok", + }; + promptDone = handlePrompt(state, action); + 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"); + + yield promptDone; +}); + +// ===== +add_task(function* test_select_item() { + info("Starting test: Select (3 items, selection changed, ok)"); + state = { + msg : "This is the select text.", + title : "TestTitle", + items : ["one", "two", "three"], + }; + action = { + buttonClick: "ok", + selectItem: 1, + }; + promptDone = handlePrompt(state, action); + 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"); + + yield promptDone; +}); + +// ===== +add_task(function* test_cancel_prompt() { + info("Starting test: Select (3 items, cancel)"); + state = { + msg : "This is the select text.", + title : "TestTitle", + items : ["one", "two", "three"], + }; + action = { + buttonClick: "cancel", + }; + promptDone = handlePrompt(state, action); + 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"); + + yield promptDone; +}); + +</script> +</pre> +</body> +</html> |