--- a/browser/base/content/test/general/browser_clipboard.js
+++ b/browser/base/content/test/general/browser_clipboard.js
@@ -14,36 +14,34 @@ add_task(async function() {
await promiseTabLoadEvent(tab, "data:text/html," + escape(testPage));
await SimpleTest.promiseFocus(browser.contentWindowAsCPOW);
const modifier = (navigator.platform.indexOf("Mac") >= 0) ?
Components.interfaces.nsIDOMWindowUtils.MODIFIER_META :
Components.interfaces.nsIDOMWindowUtils.MODIFIER_CONTROL;
+ function sendKey(message) {
+ BrowserTestUtils.synthesizeKey(message.data.key,
+ {code: message.data.code, accelKey: true},
+ browser);
+ }
+
+ browser.messageManager.addMessageListener("Test:SendKey", sendKey);
+
// On windows, HTML clipboard includes extra data.
// The values are from widget/windows/nsDataObj.cpp.
const htmlPrefix = (navigator.platform.indexOf("Win") >= 0) ? "<html><body>\n<!--StartFragment-->" : "";
const htmlPostfix = (navigator.platform.indexOf("Win") >= 0) ? "<!--EndFragment-->\n</body>\n</html>" : "";
await ContentTask.spawn(browser, { modifier, htmlPrefix, htmlPostfix }, async function(arg) {
var doc = content.document;
var main = doc.getElementById("main");
main.focus();
- const utils = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
- .getInterface(Components.interfaces.nsIDOMWindowUtils);
-
- function sendKey(key) {
- if (utils.sendKeyEvent("keydown", key, 0, arg.modifier)) {
- utils.sendKeyEvent("keypress", key, key.charCodeAt(0), arg.modifier);
- }
- utils.sendKeyEvent("keyup", key, 0, arg.modifier);
- }
-
// Select an area of the text.
let selection = doc.getSelection();
selection.modify("move", "left", "line");
selection.modify("move", "right", "character");
selection.modify("move", "right", "character");
selection.modify("move", "right", "character");
selection.modify("extend", "right", "word");
selection.modify("extend", "right", "word");
@@ -51,17 +49,17 @@ add_task(async function() {
await new Promise((resolve, reject) => {
addEventListener("copy", function copyEvent(event) {
removeEventListener("copy", copyEvent, true);
// The data is empty as the selection is copied during the event default phase.
Assert.equal(event.clipboardData.mozItemCount, 0, "Zero items on clipboard");
resolve();
}, true);
- sendKey("c");
+ sendAsyncMessage("Test:SendKey", { key: "c", code: "KeyC" });
});
selection.modify("move", "right", "line");
await new Promise((resolve, reject) => {
addEventListener("paste", function copyEvent(event) {
removeEventListener("paste", copyEvent, true);
let clipboardData = event.clipboardData;
@@ -69,17 +67,18 @@ add_task(async function() {
Assert.equal(clipboardData.types.length, 2, "Two types on clipboard");
Assert.equal(clipboardData.types[0], "text/html", "text/html on clipboard");
Assert.equal(clipboardData.types[1], "text/plain", "text/plain on clipboard");
Assert.equal(clipboardData.getData("text/html"), arg.htmlPrefix +
"t <b>Bold</b>" + arg.htmlPostfix, "text/html value");
Assert.equal(clipboardData.getData("text/plain"), "t Bold", "text/plain value");
resolve();
}, true);
- sendKey("v");
+
+ sendAsyncMessage("Test:SendKey", {key: "v", code: "KeyV"});
});
Assert.equal(main.innerHTML, "Test <b>Bold</b> After Textt <b>Bold</b>", "Copy and paste html");
selection.modify("extend", "left", "word");
selection.modify("extend", "left", "word");
selection.modify("extend", "left", "character");
@@ -87,17 +86,18 @@ add_task(async function() {
addEventListener("cut", function copyEvent(event) {
removeEventListener("cut", copyEvent, true);
event.clipboardData.setData("text/plain", "Some text");
event.clipboardData.setData("text/html", "<i>Italic</i> ");
selection.deleteFromDocument();
event.preventDefault();
resolve();
}, true);
- sendKey("x");
+
+ sendAsyncMessage("Test:SendKey", {key: "x", code: "KeyX"});
});
selection.modify("move", "left", "line");
await new Promise((resolve, reject) => {
addEventListener("paste", function copyEvent(event) {
removeEventListener("paste", copyEvent, true);
let clipboardData = event.clipboardData;
@@ -105,17 +105,18 @@ add_task(async function() {
Assert.equal(clipboardData.types.length, 2, "Two types on clipboard 2");
Assert.equal(clipboardData.types[0], "text/html", "text/html on clipboard 2");
Assert.equal(clipboardData.types[1], "text/plain", "text/plain on clipboard 2");
Assert.equal(clipboardData.getData("text/html"), arg.htmlPrefix +
"<i>Italic</i> " + arg.htmlPostfix, "text/html value 2");
Assert.equal(clipboardData.getData("text/plain"), "Some text", "text/plain value 2");
resolve();
}, true);
- sendKey("v");
+
+ sendAsyncMessage("Test:SendKey", {key: "v", code: "KeyV"});
});
Assert.equal(main.innerHTML, "<i>Italic</i> Test <b>Bold</b> After<b></b>",
"Copy and paste html 2");
});
// Next, check that the Copy Image command works.
@@ -149,26 +150,22 @@ add_task(async function() {
if (clipboardData.getData("text/html") !== arg.htmlPrefix +
'<img id="img" tabindex="1" src="http://example.org/browser/browser/base/content/test/general/moz.png">' +
arg.htmlPostfix) {
reject("Clipboard Data did not contain an image, was " + clipboardData.getData("text/html"));
}
resolve();
}, true);
- const utils = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
- .getInterface(Components.interfaces.nsIDOMWindowUtils);
-
- if (utils.sendKeyEvent("keydown", "v", 0, arg.modifier)) {
- utils.sendKeyEvent("keypress", "v", "v".charCodeAt(0), arg.modifier);
- }
- utils.sendKeyEvent("keyup", "v", 0, arg.modifier);
+ sendAsyncMessage("Test:SendKey", {key: "v", code: "KeyV"});
});
// The new content should now include an image.
Assert.equal(main.innerHTML, '<i>Italic</i> <img id="img" tabindex="1" ' +
'src="http://example.org/browser/browser/base/content/test/general/moz.png">' +
"Test <b>Bold</b> After<b></b>", "Paste after copy image");
});
+ browser.messageManager.removeMessageListener("Test:SendKey", sendKey);
+
gBrowser.removeCurrentTab();
});
--- a/browser/components/sessionstore/test/browser_formdata.js
+++ b/browser/components/sessionstore/test/browser_formdata.js
@@ -98,28 +98,28 @@ add_task(async function test_url_check()
*/
add_task(async function test_nested() {
const URL = "data:text/html;charset=utf-8," +
"<iframe src='data:text/html;charset=utf-8," +
"<input autofocus=true>'/>";
const FORM_DATA = {
children: [{
- xpath: {"/xhtml:html/xhtml:body/xhtml:input": "M"},
+ xpath: {"/xhtml:html/xhtml:body/xhtml:input": "m"},
url: "data:text/html;charset=utf-8,<input%20autofocus=true>"
}]
};
// Create a tab with an iframe containing an input field.
let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
// Modify the input field's value.
- await sendMessage(browser, "ss-test:sendKeyEvent", {key: "m", frame: 0});
+ await BrowserTestUtils.synthesizeKey("m", {code: "KeyM"}, browser);
// Remove the tab and check that we stored form data correctly.
await promiseRemoveTab(tab);
let [{state: {formdata}}] = JSON.parse(ss.getClosedTabData(window));
is(JSON.stringify(formdata), JSON.stringify(FORM_DATA),
"formdata for iframe stored correctly");
// Restore the closed tab.
@@ -146,38 +146,38 @@ add_task(async function test_design_mode
"<script>document.designMode='on'</script>";
// Load a tab with an editable document.
let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
// Modify the document content.
- await sendMessage(browser, "ss-test:sendKeyEvent", {key: "m"});
+ await BrowserTestUtils.synthesizeKey("m", {code: "KeyM"}, browser);
// Close and restore the tab.
await promiseRemoveTab(tab);
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
await promiseTabRestored(tab);
// Check that the innerHTML value was restored.
let html = await getInnerHTML(browser);
- let expected = "<h1>Mmozilla</h1><script>document.designMode='on'</script>";
+ let expected = "<h1>mmozilla</h1><script>document.designMode='on'</script>";
is(html, expected, "editable document has been restored correctly");
// Close and restore the tab.
await promiseRemoveTab(tab);
tab = ss.undoCloseTab(window, 0);
browser = tab.linkedBrowser;
await promiseTabRestored(tab);
// Check that the innerHTML value was restored.
html = await getInnerHTML(browser);
- expected = "<h1>Mmozilla</h1><script>document.designMode='on'</script>";
+ expected = "<h1>mmozilla</h1><script>document.designMode='on'</script>";
is(html, expected, "editable document has been restored correctly");
// Cleanup.
gBrowser.removeTab(tab);
});
function getInputValue(browser, id) {
return sendMessage(browser, "ss-test:getInputValue", {id});
--- a/browser/components/sessionstore/test/content-forms.js
+++ b/browser/components/sessionstore/test/content-forms.js
@@ -45,33 +45,16 @@ function dispatchUIEvent(input, type) {
}
function defineListener(type, cb) {
addMessageListener("ss-test:" + type, function({data}) {
sendAsyncMessage("ss-test:" + type, cb(data));
});
}
-defineListener("sendKeyEvent", function(data) {
- let frame = content;
- if (data.hasOwnProperty("frame")) {
- frame = content.frames[data.frame];
- }
-
- let ifreq = frame.QueryInterface(Ci.nsIInterfaceRequestor);
- let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
-
- let keyCode = data.key.charCodeAt(0);
- let charCode = Ci.nsIDOMKeyEvent.DOM_VK_A + keyCode - "a".charCodeAt(0);
-
- utils.sendKeyEvent("keydown", keyCode, charCode, null);
- utils.sendKeyEvent("keypress", keyCode, charCode, null);
- utils.sendKeyEvent("keyup", keyCode, charCode, null);
-});
-
defineListener("getInnerHTML", function(data) {
return queryElement(data).innerHTML;
});
defineListener("getTextContent", function(data) {
return queryElement(data).textContent;
});
--- a/browser/extensions/formautofill/test/mochitest/formautofill_common.js
+++ b/browser/extensions/formautofill/test/mochitest/formautofill_common.js
@@ -1,9 +1,10 @@
/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/SimpleTest.js */
+/* import-globals-from ../../../../../testing/mochitest/tests/SimpleTest/EventUtils.js */
/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
/* eslint-disable no-unused-vars */
"use strict";
let formFillChromeScript;
let defaultTextColor;
let expectingPopup = null;
@@ -112,18 +113,18 @@ function triggerAutofillAndCheckProfile(
const expectingEvent = document.activeElement == element ? "DOMAutoComplete" : "change";
const checkFieldAutofilled = Promise.all([
new Promise(resolve => element.addEventListener("input", resolve, {once: true})),
new Promise(resolve => element.addEventListener(expectingEvent, resolve, {once: true})),
]).then(() => checkFieldValue(element, value));
promises.push(checkFieldAutofilled);
}
- // Press return key and trigger form autofill.
- doKey("return");
+ // Press Enter key and trigger form autofill.
+ synthesizeKey("KEY_Enter", {code: "Enter"});
return Promise.all(promises);
}
async function onStorageChanged(type) {
info(`expecting the storage changed: ${type}`);
return new Promise(resolve => {
formFillChromeScript.addMessageListener("formautofill-storage-changed", function onChanged(data) {
@@ -237,20 +238,20 @@ function popupShownListener() {
}
function initPopupListener() {
registerPopupShownListener(popupShownListener);
}
async function triggerPopupAndHoverItem(fieldSelector, selectIndex) {
await focusAndWaitForFieldsIdentified(fieldSelector);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
for (let i = 0; i <= selectIndex; i++) {
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
}
await notifySelectedIndex(selectIndex);
}
function formAutoFillCommonSetup() {
let chromeURL = SimpleTest.getTestFileURL("formautofill_parent_utils.js");
formFillChromeScript = SpecialPowers.loadChromeScript(chromeURL);
formFillChromeScript.addMessageListener("onpopupshown", ({results}) => {
--- a/browser/extensions/formautofill/test/mochitest/test_autofocus_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_autofocus_form.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: autocomplete on an autofocus form
@@ -33,17 +34,17 @@ initPopupListener();
async function setupAddressStorage() {
await addAddress(MOCK_STORAGE[0]);
await addAddress(MOCK_STORAGE[1]);
}
add_task(async function check_autocomplete_on_autofocus_field() {
await setupAddressStorage();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({primary: address.organization, secondary: address["street-address"]})
));
});
</script>
--- a/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form address autofill
@@ -48,134 +49,134 @@ async function setupFormHistory() {
initPopupListener();
// Form with history only.
add_task(async function history_only_menu_checking() {
await setupFormHistory();
await setInput("#tel", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["+1234567890"], false);
});
// Display history search result if less than 3 inputs are covered by all saved
// fields in the storage.
add_task(async function all_saved_fields_less_than_threshold() {
await addAddress({
email: "test@test.com",
});
await setInput("#email", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["foo@mozilla.com"], false);
await cleanUpAddresses();
});
// Form with both history and address storage.
add_task(async function check_menu_when_both_existed() {
await setupAddressStorage();
await setInput("#organization", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: address.organization,
secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
})
));
await setInput("#street-address", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
secondary: address.organization,
})
));
await setInput("#tel", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: address.tel,
secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
})
));
await setInput("#address-line1", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
secondary: address.organization,
})
));
});
// Display history search result if no matched data in addresses.
add_task(async function check_fallback_for_mismatched_field() {
await setInput("#email", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["foo@mozilla.com"], false);
});
// Display history search result if address autofill is disabled.
add_task(async function check_search_result_for_pref_off() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.formautofill.addresses.enabled", false]],
});
await setInput("#tel", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["+1234567890"], false);
await SpecialPowers.popPrefEnv();
});
// Autofill the address from dropdown menu.
add_task(async function check_fields_after_form_autofill() {
const focusedInput = await setInput("#organization", "Moz");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: address.organization,
secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
})
).slice(1));
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await triggerAutofillAndCheckProfile(MOCK_STORAGE[1]);
- doKey("escape");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
is(focusedInput.value, "Mozilla", "Filled field shouldn't be reverted by ESC key");
});
// Fallback to history search after autofill address.
add_task(async function check_fallback_after_form_autofill() {
await setInput("#tel", "", true);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["+1234567890"], false);
});
// Resume form autofill once all the autofilled fileds are changed.
add_task(async function check_form_autofill_resume() {
document.querySelector("#tel").blur();
document.querySelector("#form1").reset();
await setInput("#tel", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({
primary: address.tel,
secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
})
));
});
--- a/browser/extensions/formautofill/test/mochitest/test_basic_creditcard_autocomplete_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_basic_creditcard_autocomplete_form.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form credit card autofill
@@ -56,134 +57,134 @@ add_task(async function history_only_men
// timing to start.
//
// After test process was re-spawning to https scheme. Wait 2 secs
// to ensure the environment is ready to do storage setup.
await sleep(2000);
await setupFormHistory();
await setInput("#cc-exp-year", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["2023"], false);
});
// Display credit card result even if the number of fillable fields is less than the threshold.
add_task(async function all_saved_fields_less_than_threshold() {
await addCreditCard(reducedMockRecord);
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries([reducedMockRecord].map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await cleanUpCreditCards();
});
// Form with both history and credit card storage.
add_task(async function check_menu_when_both_existed() {
await setupCreditCardStorage();
await setInput("#cc-number", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primaryAffix: cc.ccNumberFmt.affix,
primary: cc.ccNumberFmt.label,
secondary: cc["cc-name"],
})));
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await setInput("#cc-exp-year", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-year"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await setInput("#cc-exp-month", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-month"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
await cleanUpCreditCards();
});
// Display history search result if no matched data in credit card.
add_task(async function check_fallback_for_mismatched_field() {
await addCreditCard(reducedMockRecord);
await setInput("#cc-exp-year", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["2023"], false);
await cleanUpCreditCards();
});
// Display history search result if credit card autofill is disabled.
add_task(async function check_search_result_for_pref_off() {
await setupCreditCardStorage();
await SpecialPowers.pushPrefEnv({
set: [["extensions.formautofill.creditCards.enabled", false]],
});
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["John Smith"], false);
await SpecialPowers.popPrefEnv();
});
// Autofill the credit card from dropdown menu.
add_task(async function check_fields_after_form_autofill() {
await setInput("#cc-exp-year", 202);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.slice(1).map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-exp-year"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await triggerAutofillAndCheckProfile(MOCK_STORAGE[1]);
});
// Fallback to history search after autofill address.
add_task(async function check_fallback_after_form_autofill() {
await setInput("#cc-name", "", true);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["John Smith"], false);
});
// Resume form autofill once all the autofilled fileds are changed.
add_task(async function check_form_autofill_resume() {
document.querySelector("#cc-name").blur();
document.querySelector("#form1").reset();
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
});
</script>
--- a/browser/extensions/formautofill/test/mochitest/test_clear_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_clear_form.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test form autofill - clear form button</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: clear form button
@@ -65,61 +66,61 @@ function checkIsFormCleared(patch = {})
}
}
add_task(async function simple_clear() {
await triggerPopupAndHoverItem("#organization", 0);
await triggerAutofillAndCheckProfile(MOCK_ADDR_STORAGE[0]);
await triggerPopupAndHoverItem("#tel", 0);
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkIsFormCleared();
});
add_task(async function clear_adapted_record() {
await triggerPopupAndHoverItem("#street-address", 0);
await triggerAutofillAndCheckProfile(MOCK_ADDR_STORAGE[0]);
await triggerPopupAndHoverItem("#street-address", 0);
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkIsFormCleared();
});
add_task(async function clear_modified_form() {
await triggerPopupAndHoverItem("#organization", 0);
await triggerAutofillAndCheckProfile(MOCK_ADDR_STORAGE[0]);
await setInput("#tel", "+1111111111", true);
await triggerPopupAndHoverItem("#street-address", 0);
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkIsFormCleared({tel: "+1111111111"});
});
add_task(async function clear_distinct_section() {
document.getElementById("form1").reset();
await triggerPopupAndHoverItem("#cc-name", 0);
await triggerAutofillAndCheckProfile(MOCK_CC_STORAGE[0]);
await triggerPopupAndHoverItem("#organization", 0);
await triggerAutofillAndCheckProfile(MOCK_ADDR_STORAGE[0]);
await triggerPopupAndHoverItem("#street-address", 0);
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
for (const [id, val] of Object.entries(MOCK_CC_STORAGE[0])) {
const element = document.getElementById(id);
if (!element) {
return;
}
checkFieldValue(element, val);
checkFieldHighlighted(element, true);
}
await triggerPopupAndHoverItem("#cc-name", 0);
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkIsFormCleared();
});
</script>
<p id="display"></p>
<div id="content">
--- a/browser/extensions/formautofill/test/mochitest/test_creditcard_autocomplete_off.html
+++ b/browser/extensions/formautofill/test/mochitest/test_creditcard_autocomplete_off.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form credit card autofill
@@ -45,40 +46,40 @@ async function setupFormHistory() {
initPopupListener();
// Show Form History popup for non-autocomplete="off" field only
add_task(async function history_only_menu_checking() {
await setupFormHistory();
await setInput("#cc-number", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["1234000056780000"], false);
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await notExpectPopup();
});
// Show Form Autofill popup for the credit card fields.
add_task(async function check_menu_when_both_with_autocomplete_off() {
await setupCreditCardStorage();
await setInput("#cc-number", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primaryAffix: cc.ccNumberFmt.affix,
primary: cc.ccNumberFmt.label,
secondary: cc["cc-name"],
})));
await setInput("#cc-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(patchRecordCCNumber).map(cc => JSON.stringify({
primary: cc["cc-name"],
secondary: cc.ccNumberFmt.affix + cc.ccNumberFmt.label,
})));
});
</script>
--- a/browser/extensions/formautofill/test/mochitest/test_form_changes.html
+++ b/browser/extensions/formautofill/test/mochitest/test_form_changes.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: autocomplete on an autofocus form
@@ -44,38 +45,38 @@ function addInputField(form, className)
newElem.autocomplete = className;
newElem.type = "text";
form.appendChild(newElem);
}
async function checkFormChangeHappened(formId) {
info("expecting form changed");
await focusAndWaitForFieldsIdentified(`#${formId} input[name=tel]`);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({primary: address.tel, secondary: address.name})
));
// This is for checking the changes of element count.
addInputField(document.querySelector(`#${formId}`), "address-level2");
await focusAndWaitForFieldsIdentified(`#${formId} input[name=name]`);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({primary: address.name, secondary: address["address-level2"]})
));
// This is for checking the changes of element removed and added then.
document.querySelector(`#${formId} input[name=address-level2]`).remove();
addInputField(document.querySelector(`#${formId}`), "address-level2");
await focusAndWaitForFieldsIdentified(`#${formId} input[name=address-level2]`, true);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(MOCK_STORAGE.map(address =>
JSON.stringify({primary: address["address-level2"], secondary: address.name})
));
}
add_task(async function init_storage() {
await setupAddressStorage();
--- a/browser/extensions/formautofill/test/mochitest/test_formautofill_preview_highlight.html
+++ b/browser/extensions/formautofill/test/mochitest/test_formautofill_preview_highlight.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test form autofill - preview and highlight</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: preview and highlight
@@ -49,32 +50,32 @@ add_task(async function setup_storage()
await addAddress(MOCK_STORAGE[0]);
await addAddress(MOCK_STORAGE[1]);
await addAddress(MOCK_STORAGE[2]);
});
add_task(async function check_preview() {
const focusedInput = await setInput("#organization", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkFormFieldsStyle(null);
for (let i = 0; i < MOCK_STORAGE.length; i++) {
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await notifySelectedIndex(i);
checkFormFieldsStyle(MOCK_STORAGE[i]);
}
// Navigate to the footer
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await notifySelectedIndex(MOCK_STORAGE.length);
checkFormFieldsStyle(null);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await notifySelectedIndex(-1);
checkFormFieldsStyle(null);
focusedInput.blur();
});
add_task(async function check_filled_highlight() {
await triggerPopupAndHoverItem("#organization", 0);
--- a/browser/extensions/formautofill/test/mochitest/test_multi_locale_CA_address_form.html
+++ b/browser/extensions/formautofill/test/mochitest/test_multi_locale_CA_address_form.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test basic autofill</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: simple form address autofill
@@ -83,69 +84,69 @@ function checkFormFilled(selector, addre
} else {
let converted = address[prop];
if (prop == "street-address") {
converted = FormAutofillUtils.toOneLineAddress(converted);
}
promises.push(...checkElementFilled(element, converted));
}
}
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
return Promise.all(promises);
}
async function setupAddressStorage() {
for (let address of MOCK_STORAGE) {
await addAddress(address);
}
}
initPopupListener();
// Autofill the address with address level 1 code.
add_task(async function autofill_with_level1_code() {
await setupAddressStorage();
await setInput("#organization-en", "Mozilla Toronto");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
// Replace address level 1 code with full name in English for test result
let result = Object.assign({}, MOCK_STORAGE[1], {"address-level1": "Ontario"});
await checkFormFilled("#form-en", result);
await setInput("#organization-fr", "Mozilla Vancouver");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
// Replace address level 1 code with full name in French for test result
result = Object.assign({}, MOCK_STORAGE[0], {"address-level1": "Colombie-Britannique"});
await checkFormFilled("#form-fr", result);
document.querySelector("#form-en").reset();
document.querySelector("#form-fr").reset();
});
// Autofill the address with address level 1 full name.
add_task(async function autofill_with_level1_full_name() {
await setInput("#organization-en", "ExpoCité");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
// Replace address level 1 code with full name in French for test result
let result = Object.assign({}, MOCK_STORAGE[3], {"address-level1": "Quebec"});
await checkFormFilled("#form-en", result);
await setInput("#organization-fr", "Prince of Wales Northern Heritage");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
// Replace address level 1 code with full name in English for test result
result = Object.assign({}, MOCK_STORAGE[2], {"address-level1": "Territoires du Nord-Ouest"});
await checkFormFilled("#form-fr", result);
});
</script>
<p id="display"></p>
--- a/browser/extensions/formautofill/test/mochitest/test_multiple_forms.html
+++ b/browser/extensions/formautofill/test/mochitest/test_multiple_forms.html
@@ -28,29 +28,29 @@ let MOCK_STORAGE = [{
initPopupListener();
add_task(async function setupStorage() {
await addAddress(MOCK_STORAGE[0]);
});
add_task(async function check_switch_form_popup() {
await setInput("#additional-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
// We need an intentional wait here before switching form.
await sleep();
await setInput("#organization", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
const {open: popupOpen} = await getPopupState();
is(popupOpen, false);
await sleep();
await setInput("#given-name", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
});
</script>
<div>
<form>
--- a/browser/extensions/formautofill/test/mochitest/test_on_address_submission.html
+++ b/browser/extensions/formautofill/test/mochitest/test_on_address_submission.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test autofill submit</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="formautofill_common.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Form autofill test: check if address is saved/updated correctly
@@ -67,17 +68,17 @@ add_task(async function check_storage_af
addressesInMenu.push(TEST_ADDRESSES[0]);
// let expectedAddresses = TEST_ADDRESSES.slice(0);
await onStorageChanged("add");
let matching = await checkAddresses(TEST_ADDRESSES);
ok(matching, "New address saved as expected");
await setInput("#organization", "");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(addressesInMenu.map(address =>
JSON.stringify({primary: address.organization, secondary: address["street-address"]})
));
});
// Submit another new address that is mergeable.
add_task(async function new_address_submitted_and_merged() {
@@ -102,20 +103,20 @@ add_task(async function new_address_subm
// Submit an updated autofill address and merge.
add_task(async function check_storage_after_form_submitted() {
document.querySelector("form").reset();
// Add country to second address in storage
await setInput("#country", "US");
TEST_ADDRESSES[1].country = "US";
await setInput("#organization", "Moz");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
clickOnElement("input[type=submit]");
let expectedAddresses = TEST_ADDRESSES.slice(0);
await onStorageChanged("update");
let matching = await checkAddresses(expectedAddresses);
ok(matching, "Updated address merged as expected");
});
--- a/dom/events/test/test_bug226361.xhtml
+++ b/dom/events/test/test_bug226361.xhtml
@@ -1,15 +1,16 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=226361
-->
<head>
<title>Test for Bug 226361</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body id="body1">
<p id="display">
<a id="b1" tabindex="1" href="http://home.mozilla.org">start</a><br />
<br />
@@ -32,18 +33,17 @@ https://bugzilla.mozilla.org/show_bug.cg
function setTabFocus() {
SpecialPowers.pushPrefEnv({ set: [[ "accessibility.tabfocus", 7 ]] }, doTest);
}
// =================================
var doc = document;
function tab_to(id) {
- var wu = SpecialPowers.DOMWindowUtils;
- wu.sendKeyEvent('keypress', 9, 0, 0);
+ synthesizeKey("KEY_Tab", {code: "Tab"});
is(doc.activeElement.id, id, "element with id=" + id + " should have focus");
}
function tab_iframe() {
doc = document;
tab_to('iframe');
// inside iframe
--- a/dom/events/test/test_bug238987.html
+++ b/dom/events/test/test_bug238987.html
@@ -1,50 +1,51 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=238987
-->
<head>
<title>Test for Bug 238987</title>
- <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=238987">Mozilla Bug 238987</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 238987 **/
var shouldStop = false;
- var modifier = 0;
+ var activateShift = false;
var expectedResult = "i1,i2,i3,i4,i5,i6,i7,i8,number,i9,i10,i11,i12";
var forwardFocusArray = expectedResult.split(",");
var backwardFocusArray = expectedResult.split(",");
var forwardBlurArray = expectedResult.split(",");
var backwardBlurArray = expectedResult.split(",");
// Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template,
var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4;
// but the last blur event goes to i1, not "begin".
var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3;
function handleFocus(e) {
if (e.target.id == "begin") {
- // if the modifier is set, the test is coming back from the end.
- if (modifier) {
+ // if the activateShift is set, the test is coming back from the end.
+ if (activateShift) {
shouldStop = true;
}
} else if (e.target.id == "end") {
- modifier = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
- } else if (modifier) {
+ activateShift = true;
+ } else if (activateShift) {
var expected = backwardFocusArray.pop();
ok(expected == e.target.id,
"(focus) Backward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
} else {
var expected = forwardFocusArray.shift();
is(e.target, document.activeElement, "Wrong activeElement!");
ok(expected == e.target.id,
@@ -61,17 +62,17 @@ https://bugzilla.mozilla.org/show_bug.cg
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
"|window| should not have got a focus event, " + s);
}
function handleBlur(e) {
if (e.target.id == "begin" || e.target.id == "end") {
return;
- } else if (modifier) {
+ } else if (activateShift) {
var expected = backwardBlurArray.pop();
ok(expected == e.target.id,
"(blur) backward tabbing, expected [" +
expected + "], got [" + e.target.id + "]");
} else {
var expected = forwardBlurArray.shift();
ok(expected == e.target.id,
"(blur) forward tabbing, expected [" +
@@ -85,22 +86,18 @@ https://bugzilla.mozilla.org/show_bug.cg
if ("id" in e.target) {
s = s + ", id=\"" + e.target.id + "\"";
}
ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
"|window| should not have got a blur event, " + s);
}
function tab() {
- var utils = SpecialPowers.DOMWindowUtils;
// Send tab key events.
- var key = Components.interfaces.nsIDOMKeyEvent.DOM_VK_TAB;
- utils.sendKeyEvent("keydown", key, 0, modifier);
- utils.sendKeyEvent("keypress", key, 0, modifier);
- utils.sendKeyEvent("keyup", key, 0, modifier);
+ synthesizeKey("KEY_Tab", {code: "Tab", shiftKey: activateShift});
if (shouldStop) {
// Did focus handling succeed
is(forwardFocusArray.length, 0,
"Not all forward tabbing focus tests were run, " +
forwardFocusArray.toString());
is(backwardFocusArray.length, 0,
"Not all backward tabbing focus tests were run, " +
backwardFocusArray.toString());
--- a/dom/events/test/test_bug409604.html
+++ b/dom/events/test/test_bug409604.html
@@ -1,31 +1,30 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=409604
-->
<head>
<title>Test for Bug 409604</title>
- <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body id="body">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=409604">Mozilla Bug 409604</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 409604 **/
- var modifier = SpecialPowers.Ci.nsIDOMEvent.ALT_MASK |
- SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
var expectedFocus = "a,c,d,e,f,g,h,i,j,k,l,m,n,p,x,y";
// XXX the "map" test is causing trouble, see bug 433089
var focusArray = expectedFocus.split(",");
var unfocusableElementId = "invalid";
var unfocusableTags = [
{tag: "abbr", content: "text", attribs: {title: "something"}},
{tag: "acronym", content: "text", attribs: {title: "something"}},
{tag: "address", content: "text"},
@@ -115,28 +114,26 @@ https://bugzilla.mozilla.org/show_bug.cg
function handleInvalid(e) {
ok("accessKey" in e, "(invalid) accesskey property not found on element");
ok(false, "(invalid) accesskey should not have any effect on this element: " +
e.localName);
}
function pressAccessKey(key) {
- var utils = SpecialPowers.DOMWindowUtils;
- utils.sendKeyEvent("keydown", key, key, modifier);
- utils.sendKeyEvent("keypress", key, key, modifier);
- utils.sendKeyEvent("keyup", key, key, modifier);
+ synthesizeKey(key.key, {code: key.code, altKey: true, shiftKey: true});
}
function testFocusableElements() {
for (var code = "a".charCodeAt(0); code <= "y".charCodeAt(0); ++ code) {
// XXX the "map" test is causing trouble, see bug 433089
if (code == "b".charCodeAt(0))
continue;
- pressAccessKey(code);
+ var accessChar = String.fromCharCode(code).toUpperCase();
+ pressAccessKey({key: accessChar, code: "Key" + accessChar});
}
ok(focusArray.length == 0, "(focus) unhandled elements remaining: " + focusArray.join(","));
}
function createUnfocusableElement(elem, accesskey) {
ok("tag" in elem, "invalid object passed to createUnfocusableElement: " + elem.toString());
var e = document.createElement(elem.tag);
if ("content" in elem) {
@@ -185,26 +182,26 @@ https://bugzilla.mozilla.org/show_bug.cg
el.remove();
ok(document.getElementById(unfocusableElementId) == null, "unfocusable element not properly removed");
}
function testUnfocusableElements() {
var i, e;
for (i = 0; i < unfocusableTags.length; ++ i) {
createUnfocusableElement(unfocusableTags[i], "z");
- pressAccessKey("z".charCodeAt(0));
+ pressAccessKey({key: "Z", code:"KeyZ"});
destroyUnfocusableElement();
}
for (i = 0; i < invalidElements.length; ++ i) {
e = document.getElementById(invalidElements[i]);
ok(e != null, "element with ID " + invalidElements[i] + " not found");
e.setAttribute("accesskey", "z");
e.setAttribute("onclick", "handleClick(event.target); event.preventDefault();");
e.setAttribute("onfocus", "handleInvalid(event.target);");
- pressAccessKey("z".charCodeAt(0));
+ pressAccessKey({key: "Z", code:"KeyZ"});
e.removeAttribute("accesskey");
e.removeAttribute("onclick");
e.removeAttribute("onfocus");
}
}
function start() {
testFocusableElements();
--- a/dom/events/test/test_bug450876.html
+++ b/dom/events/test/test_bug450876.html
@@ -1,15 +1,16 @@
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=450876
-->
<head>
<title>Test for Bug 450876 - Crash [@ nsEventStateManager::GetNextTabbableMapArea] with img usemap and tabindex</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450876">Mozilla Bug 450876</a>
<p id="display"><a href="#" id="a">link to focus from</a><img usemap="#a" tabindex="1"></p>
<div id="content" style="display: none">
</div>
@@ -19,17 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
/** Test for Bug 450876 **/
function doTest() {
is(document.activeElement, document.body, "body element should be focused");
document.getElementById('a').focus();
is(document.activeElement, document.getElementById('a'), "link should have focus");
is(document.hasFocus(), true, "document should be focused");
- SpecialPowers.DOMWindowUtils.sendKeyEvent('keypress', 9, 0, 0);
+ synthesizeKey("KEY_Tab", {code: "Tab"});
is(document.activeElement, document.getElementById('a'), "body element should be focused");
is(document.hasFocus(), false, "document should not be focused");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
--- a/dom/events/test/test_bug493251.html
+++ b/dom/events/test/test_bug493251.html
@@ -1,16 +1,17 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=493251
-->
<head>
<title>Test for Bug 493251</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493251">Mozilla Bug 493251</a>
<p id="display">
</p>
<div id="content" style="display: none">
@@ -31,24 +32,16 @@ https://bugzilla.mozilla.org/show_bug.cg
var keyUp = 0;
function suppressEventHandling(aSuppress) {
var utils = SpecialPowers.getDOMWindowUtils(win);
ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
utils.suppressEventHandling(aSuppress);
}
- function dispatchKeyEvent(type) {
- var utils = SpecialPowers.getDOMWindowUtils(win);
- ok(true, "Dipatching key event: type=" + type);
- utils.sendKeyEvent(type,
- SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
- 0, 0);
- }
-
function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
var utils = SpecialPowers.getDOMWindowUtils(win);
ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
", aModifiers=" + aModifiers);
utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
}
@@ -100,45 +93,39 @@ https://bugzilla.mozilla.org/show_bug.cg
win.addEventListener("mousedown",
function(e) { dumpEvent(e); ++mouseDown; }, true);
win.addEventListener("mouseup",
function(e) { dumpEvent(e); ++mouseUp; }, true);
win.addEventListener("click",
function(e) { dumpEvent(e); ++mouseClick; }, true);
ok(true, "doTest #1...");
- dispatchKeyEvent("keydown");
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ synthesizeKey("a", {code: "KeyA"}, win);
is(keyDown, 1, "Wrong number events (1)");
is(keyPress, 1, "Wrong number events (2)");
is(keyUp, 1, "Wrong number events (3)");
ok(true, "doTest #2...");
suppressEventHandling(true);
- dispatchKeyEvent("keydown");
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ synthesizeKey("a", {code: "KeyA"}, win);
is(keyDown, 1, "Wrong number events (4)");
is(keyPress, 1, "Wrong number events (5)");
is(keyUp, 1, "Wrong number events (6)");
suppressEventHandling(false);
is(keyDown, 1, "Wrong number events (7)");
is(keyPress, 1, "Wrong number events (8)");
is(keyUp, 1, "Wrong number events (9)");
setTimeout(continueTest1, 0);
}
function continueTest1() {
ok(true, "continueTest1...");
- dispatchKeyEvent("keydown");
- suppressEventHandling(true);
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ win.addEventListener("keydown", () => { suppressEventHandling(true); }, {once: true});
+ synthesizeKey("a", {code: "KeyA"}, win);
is(keyDown, 2, "Wrong number events (10)");
is(keyPress, 1, "Wrong number events (11)");
is(keyUp, 1, "Wrong number events (12)");
suppressEventHandling(false);
setTimeout(continueTest2, 0);
}
function continueTest2() {
--- a/dom/events/test/test_bug545268.html
+++ b/dom/events/test/test_bug545268.html
@@ -1,16 +1,17 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=545268
-->
<head>
<title>Test for Bug 545268</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545268">Mozilla Bug 545268</a>
<p id="display">
</p>
<div id="content" style="display: none">
@@ -28,65 +29,52 @@ https://bugzilla.mozilla.org/show_bug.cg
var mouseDown = 0;
var mouseUp = 0;
var mouseClick = 0;
var keyDown = 0;
var keyPress = 0;
var keyUp = 0;
- function dispatchKeyEvent(type) {
- var utils = SpecialPowers.getDOMWindowUtils(subwin);
- utils.sendKeyEvent(type,
- SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
- 0, 0);
- }
-
function doTest() {
var utils = SpecialPowers.getDOMWindowUtils(win);
var f = win.document.getElementById("f");
subwin = f.contentWindow;
subwin.document.getElementsByTagName("input")[0].focus();
subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
subwin.addEventListener("click", function(e) { ++mouseClick; }, true);
- dispatchKeyEvent("keydown");
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ synthesizeKey("a", {code: "KeyA"}, subwin);
is(keyDown, 1, "Wrong number events (1)");
is(keyPress, 1, "Wrong number events (2)");
is(keyUp, 1, "Wrong number events (3)");
// Test that suppressing events on the parent window prevents key
// events in the subdocument window
utils.suppressEventHandling(true);
- dispatchKeyEvent("keydown");
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ synthesizeKey("a", {code: "KeyA"}, subwin);
is(keyDown, 1, "Wrong number events (4)");
is(keyPress, 1, "Wrong number events (5)");
is(keyUp, 1, "Wrong number events (6)");
utils.suppressEventHandling(false);
is(keyDown, 1, "Wrong number events (7)");
is(keyPress, 1, "Wrong number events (8)");
is(keyUp, 1, "Wrong number events (9)");
setTimeout(continueTest1, 0);
}
function continueTest1() {
var utils = SpecialPowers.getDOMWindowUtils(win);
- dispatchKeyEvent("keydown");
- utils.suppressEventHandling(true);
- dispatchKeyEvent("keypress");
- dispatchKeyEvent("keyup");
+ subwin.addEventListener("keydown", () => { utils.suppressEventHandling(true); }, {once: true});
+ synthesizeKey("a", {code: "KeyA"}, subwin);
is(keyDown, 2, "Wrong number events (10)");
is(keyPress, 1, "Wrong number events (11)");
is(keyUp, 1, "Wrong number events (12)");
utils.suppressEventHandling(false);
setTimeout(continueTest2, 0);
}
function continueTest2() {
--- a/layout/forms/test/test_bug348236.html
+++ b/layout/forms/test/test_bug348236.html
@@ -2,16 +2,17 @@
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=348236
-->
<head>
<title>Test for Bug 348236</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style type="text/css">
#eSelect {
position: fixed; top:0; left: 350px; font-size: 24px; width: 100px
}
#eSelect option {
margin: 0; padding: 0; height: 24px
}
@@ -36,45 +37,41 @@ https://bugzilla.mozilla.org/show_bug.cg
SimpleTest.waitForExplicitFinish()
addLoadEvent(function test() {
var
CI = SpecialPowers.Components.interfaces,
WinUtils = SpecialPowers.getDOMWindowUtils(window),
sec = netscape.security,
eSelect = $("eSelect"),
- IDOMEvent = CI.nsIDOMEvent,
- IDOMKeyEvent = CI.nsIDOMKeyEvent,
timeout = 0 // Choose a larger value like 500 ms if you want to see what's happening.
- function keypressOnSelect(key, modifiers) {
+ function keypressOnSelect(key) {
WinUtils.focus(eSelect)
- WinUtils.sendKeyEvent("keyup", key, 0, modifiers)
- WinUtils.sendKeyEvent("keypress", key, 0, modifiers)
- WinUtils.sendKeyEvent("keydown", key, 0, modifiers)
+ synthesizeKey(key.key, {code: key.code, altKey: key.altKey});
}
- function testKey(key, modifiers, keyString, functionToContinue) {
+ function testKey(key, keyString, functionToContinue) {
var selectGotClick
function clickListener() { selectGotClick = true }
eSelect.selectedIndex = 0
eSelect.onchangeCount = 0
// Drop the SELECT down.
- keypressOnSelect(key, modifiers)
+ keypressOnSelect(key)
// This timeout and the following are necessary to let the sent events take effect.
setTimeout(cont1, timeout)
function cont1() {
// Move the mouse over option 3 (90 = 3 (rows) * 24 (row height) + 18).
WinUtils.sendMouseEvent("mousemove", 355, 92, 0, 0, 0, true)
setTimeout(cont2, timeout)
}
function cont2() {
// Close the select.
- keypressOnSelect(key, modifiers)
+ keypressOnSelect(key)
setTimeout(cont3, timeout)
}
function cont3() {
is(eSelect.value, "3", "Select's value should be 3 after hovering over option 3 and pressing " + keyString + ".")
is(eSelect.onchangeCount, 1, "Onchange should have fired once.")
// Simulate click on area to the left of the select.
eSelect.addEventListener("click", clickListener, true)
@@ -91,29 +88,29 @@ addLoadEvent(function test() {
}
// Quick sanity checks.
is(eSelect.value, "1", "SELECT value should be 1 after load.")
is(eSelect.selectedIndex, 0, "SELECT selectedIndex should be 0 after load.")
// Check if sending key events works.
- keypressOnSelect(IDOMKeyEvent.DOM_VK_DOWN, 0)
+ keypressOnSelect({key: "KEY_ArrowDown", code: "ArrowDown"});
is(eSelect.value, "2", "SELECT value should be 2 after pressing Down.")
// Test ALT-Down.
- testKey(IDOMKeyEvent.DOM_VK_DOWN, IDOMEvent.ALT_MASK, "ALT-Down", nextKey1)
+ testKey({key: "KEY_ArrowDown", code: "ArrowDown", altKey: true}, "ALT-Down", nextKey1)
function nextKey1() {
// Test ALT-Up.
- testKey(IDOMKeyEvent.DOM_VK_UP, IDOMEvent.ALT_MASK, "ALT-Up", nextKey2)
+ testKey({key: "KEY_ArrowUp", code: "ArrowUp", altKey: true}, "ALT-Up", nextKey2)
}
function nextKey2() {
- // Test the F4 key on OS/2 and Windows.
- if (/OS\/2|Win/i.test(navigator.platform))
- testKey(IDOMKeyEvent.DOM_VK_F4, 0, "F4", finished)
+ // Test the F4 key on Windows.
+ if (/Win/i.test(navigator.platform))
+ testKey({key: "KEY_F4", code: "F4"}, "F4", finished)
else
finished()
}
function finished() {
// Reset value to get the expected value if we reload the page.
eSelect.selectedIndex = 0
SimpleTest.finish()
}
--- a/layout/forms/test/test_bug411236.html
+++ b/layout/forms/test/test_bug411236.html
@@ -1,16 +1,17 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=411236
-->
<head>
<title>Test for Bug 411236</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411236">Mozilla Bug 411236</a>
<p id="display"></p>
<div id="content">
<input type="file" onfocus="window.oTarget = event.originalTarget;"
onclick="window.fileInputGotClick = true; return false;"
@@ -19,31 +20,22 @@ https://bugzilla.mozilla.org/show_bug.cg
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 411236 **/
window.oTarget = null;
window.fileInputGotClick = false;
-function tab() {
- var utils = SpecialPowers.DOMWindowUtils;
- // Send tab key events.
- var key = SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_TAB;
- utils.sendKeyEvent("keydown", key, 0, 0);
- utils.sendKeyEvent("keypress", key, 0, 0);
- utils.sendKeyEvent("keyup", key, 0, 0);
-}
-
function test() {
// Try to find the 'Browse...' using tabbing.
var i = 0;
while (!window.oTarget && i < 100) {
++i;
- tab();
+ synthesizeKey("KEY_Tab", {code: "Tab"});
}
if (i >= 100) {
ok(false, "Couldn't find an input element!");
SimpleTest.finish();
return;
}
--- a/layout/style/test/test_flexbox_focus_order.html
+++ b/layout/style/test/test_flexbox_focus_order.html
@@ -1,16 +1,17 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=812687
-->
<head>
<title>Test for Bug 812687: focus order of reordered flex items</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
.container { display: flex; }
#focus1 { background: yellow; }
#focus2 { background: lightgray; }
#focus3 { background: orange; }
#focus4 { background: lightblue; }
@@ -37,17 +38,16 @@ https://bugzilla.mozilla.org/show_bug.cg
</p>
<div id="content" style="display: none"></div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 812687 **/
-const gKeyCodeForTab = 9;
const gExpectedFocusedIds = [
"focus1",
"focus2",
"focus3",
"focus4",
"focus5"
];
@@ -55,17 +55,17 @@ function doTest() {
// First, we focus something just before the flex container:
document.getElementById('beforeContainer').focus();
is(document.activeElement, document.getElementById('beforeContainer'),
"explicitly-focused link should gain focus");
// And then we advance focus across the focusable things in the flex container
// and check that we traverse them in the expected order:
for (let expectedId of gExpectedFocusedIds) {
- SpecialPowers.DOMWindowUtils.sendKeyEvent('keypress', gKeyCodeForTab, 0, 0);
+ synthesizeKey("KEY_Tab", {code: "Tab"});
is(document.activeElement, document.getElementById(expectedId),
"expecting element '#" + expectedId + "' to be focused");
}
SimpleTest.finish();
}
// Before we start, we have to bump Mac to make its 'tab'-key focus behavior
--- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_open.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_open.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for permissions</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
@@ -95,18 +96,17 @@ add_task(async function downloads_open_i
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let url = await extension.awaitMessage("ready");
let win = window.open(url);
await extension.awaitMessage("page-ready");
- let winutils = SpecialPowers.getDOMWindowUtils(win);
- winutils.sendKeyEvent("keypress", KeyEvent.DOM_VK_A, 0, 0);
+ synthesizeKey("a", {code: "KeyA"}, win);
let result = await extension.awaitMessage("download-open.result");
is(result.success, false, "Opening download fails.");
is(result.error, "Invalid download id 10", "The error is informative.");
await extension.unload();
});
--- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_permissions.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_permissions.html
@@ -1,14 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for permissions</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
@@ -116,19 +117,17 @@ function makeTest(manifestPermissions, o
}
// Making a cross-origin request from a content script should fail
if (checkFetch) {
result = await testContentScript();
is(result, false, "fetch() failed from content script due to lack of host permission");
}
- // Request some permissions
- let winutils = SpecialPowers.getDOMWindowUtils(win);
- winutils.sendKeyEvent("keypress", KeyEvent.DOM_VK_A, 0, 0);
+ synthesizeKey("a", {code: "KeyA"}, win);
result = await extension.awaitMessage("request.result");
is(result, true, "permissions.request() succeeded");
// Using the cookies API from an extension page should succeed
result = await call("set-cookie");
is(result.success, true, "setting cookie succeeded");
// Making a cross-origin request from a content script should succeed
--- a/toolkit/components/passwordmgr/test/chrome/subtst_privbrowsing_4.html
+++ b/toolkit/components/passwordmgr/test/chrome/subtst_privbrowsing_4.html
@@ -1,13 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Subtest for Login Manager notifications (private browsing)</title>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
</head>
<body>
<h2>Subtest 4</h2>
<!--
Make sure that the user/pass fields have manual filling enabled
in private mode.
-->
@@ -15,23 +16,23 @@
<input id="user" name="user" type="text">
<input id="pass" name="pass" type="password">
<button type='submit'>Submit</button>
</form>
<script>
function startAutocomplete() {
userField.focus();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
setTimeout(submitForm, 100);
}
function submitForm() {
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
setTimeout(function() { form.submit(); }, 100);
}
var form = document.getElementById("form");
var userField = document.getElementById("user");
window.addEventListener("message", () => { startAutocomplete(); });
--- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_https_upgrade.html
@@ -51,18 +51,16 @@ runInParent(function addLogins() {
<!-- we presumably can't hide the content for this test. -->
<div id="content">
<iframe src="https://example.org/tests/toolkit/components/passwordmgr/test/mochitest/form_basic.html"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
-const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
-
let iframe = SpecialPowers.wrap(document.getElementsByTagName("iframe")[0]);
let iframeDoc;
let uname;
let pword;
// Restore the form to the default state.
function restoreForm() {
pword.focus();
@@ -95,123 +93,123 @@ add_task(async function setup() {
add_task(async function test_empty_first_entry() {
// Make sure initial form is empty.
checkACForm("", "");
// Trigger autocomplete popup
restoreForm();
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is initially closed");
let shownPromise = promiseACShown();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
let results = await shownPromise;
popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected");
checkArrayValues(results, ["name", "name1", "name2"], "initial");
// Check first entry
let index0Promise = notifySelectedIndex(0);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await index0Promise;
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("name", "pass");
});
add_task(async function test_empty_second_entry() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("name1", "pass1");
});
add_task(async function test_search() {
restoreForm();
let shownPromise = promiseACShown();
// We need to blur for the autocomplete controller to notice the forced value below.
uname.blur();
uname.value = "name";
uname.focus();
sendChar("1");
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
checkArrayValues(results, ["name1"], "check result deduping for 'name1'");
- doKey("down"); // first
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("name1", "pass1");
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is now closed");
});
add_task(async function test_delete_first_entry() {
restoreForm();
uname.focus();
let shownPromise = promiseACShown();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await shownPromise;
let index0Promise = notifySelectedIndex(0);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await index0Promise;
let deletionPromise = promiseStorageChanged(["removeLogin"]);
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
await deletionPromise;
checkACForm("", "");
let results = await notifyMenuChanged(2, "name1");
checkArrayValues(results, ["name1", "name2"], "two should remain after deleting the first");
let popupState = await getPopupState();
is(popupState.open, true, "Check popup stays open after deleting");
- doKey("escape");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
popupState = await getPopupState();
is(popupState.open, false, "Check popup closed upon ESC");
});
add_task(async function test_delete_duplicate_entry() {
restoreForm();
uname.focus();
let shownPromise = promiseACShown();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await shownPromise;
let index0Promise = notifySelectedIndex(0);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await index0Promise;
let deletionPromise = promiseStorageChanged(["removeLogin"]);
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
await deletionPromise;
checkACForm("", "");
is(LoginManager.countLogins("http://example.org", "http://example.org", null), 1,
"Check that the HTTP login remains");
is(LoginManager.countLogins("https://example.org", "https://example.org", null), 0,
"Check that the HTTPS login was deleted");
// Two menu items should remain as the HTTPS login should have been deleted but
// the HTTP would remain.
let results = await notifyMenuChanged(1, "name2");
checkArrayValues(results, ["name2"], "one should remain after deleting the HTTPS name1");
let popupState = await getPopupState();
is(popupState.open, true, "Check popup stays open after deleting");
- doKey("escape");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
popupState = await getPopupState();
is(popupState.open, false, "Check popup closed upon ESC");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autofocus_js.html
@@ -58,18 +58,18 @@ add_task(async function setup() {
iframeDoc = iframe.contentDocument;
SimpleTest.requestFlakyTimeout("Giving a chance for the unexpected popupshown to occur");
});
add_task(async function test_initial_focus() {
let results = await notifyMenuChanged(2, "name");
checkArrayValues(results, ["name", "name1"], "Two results");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
is(iframeDoc.getElementById("form-basic-password").value, "pass", "Check first password filled");
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is now closed");
});
// This depends on the filling from the previous test.
add_task(async function test_not_reopened_if_filled() {
--- a/toolkit/components/passwordmgr/test/mochitest/test_basic_form_autocomplete.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_basic_form_autocomplete.html
@@ -179,17 +179,16 @@ var setupScript = runInParent(function s
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
-const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
// Restore the form to the default state.
function restoreForm() {
uname.value = "";
pword.value = "";
uname.focus();
}
@@ -225,214 +224,214 @@ add_task(async function test_form1_initi
is(popupState.open, false, "Check popup is initially closed");
});
add_task(async function test_form1_menuitems() {
await SimpleTest.promiseFocus(window);
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
let expectedMenuItems = ["tempuser1",
"testuser2",
"testuser3",
"zzzuser4"];
checkArrayValues(results, expectedMenuItems, "Check all menuitems are displayed correctly.");
checkACForm("", ""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACForm("", "");
});
add_task(async function test_form1_first_entry() {
await SimpleTest.promiseFocus(window);
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
- doKey("down"); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
checkACForm("", ""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_second_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_third_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser3", "testpass3");
});
add_task(async function test_form1_fourth_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("down"); // fourth
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // fourth
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_first_entry() {
// Trigger autocomplete popup
restoreForm();
await spinEventLoop(); // let focus happen
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("down"); // fourth
- doKey("down"); // deselects
- doKey("down"); // first
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // fourth
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // deselects
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_wraparound_up_last_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("up"); // last (fourth)
- doKey("return");
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last (fourth)
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_down_up_up() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // select first entry
- doKey("up"); // selects nothing!
- doKey("up"); // select last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // selects nothing!
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // select last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_up_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down");
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("up");
- doKey("up");
- doKey("up"); // first entry
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_fill_username_without_autofill_right() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Set first entry w/o triggering autocomplete
- doKey("down"); // first
- doKey("right");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
await spinEventLoop();
checkACForm("tempuser1", ""); // empty password
});
add_task(async function test_form1_fill_username_without_autofill_left() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Set first entry w/o triggering autocomplete
- doKey("down"); // first
- doKey("left");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
checkACForm("tempuser1", ""); // empty password
});
add_task(async function test_form1_pageup_first() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry (page up)
- doKey("down"); // first
- doKey("down"); // second
- doKey("page_up"); // first
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_PageUp", {code: "PageUp"}); // first
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_pagedown_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
/* test 13 */
// Check last entry (page down)
- doKey("down"); // first
- doKey("page_down"); // last
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_PageDown", {code: "PageDown"}); // last
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_untrusted_event() {
restoreForm();
await spinEventLoop();
@@ -442,132 +441,132 @@ add_task(async function test_form1_untru
sendFakeAutocompleteEvent(uname);
await spinEventLoop();
checkACForm("zzzuser4", "");
});
add_task(async function test_form1_delete() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// XXX tried sending character "t" before/during dropdown to test
// filtering, but had no luck. Seemed like the character was getting lost.
// Setting uname.value didn't seem to work either. This works with a human
// driver, so I'm not sure what's up.
// Delete the first entry (of 4), "tempuser1"
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
var numLogins;
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 5, "Correct number of logins before deleting one");
let countChangedPromise = notifyMenuChanged(3);
var deletionPromise = promiseStorageChanged(["removeLogin"]);
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
await deletionPromise;
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 4, "Correct number of logins after deleting one");
await countChangedPromise;
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_first_after_deletion() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check the new first entry (of 3)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_delete_second() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Delete the second entry (of 3), "testuser3"
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 3, "Correct number of logins after deleting one");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_first_after_deletion2() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check the new first entry (of 2)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_delete_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
/* test 54 */
// Delete the last entry (of 2), "zzzuser4"
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 2, "Correct number of logins after deleting one");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_first_after_3_deletions() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check the only remaining entry
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_check_only_entry_remaining() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
/* test 56 */
// Delete the only remaining entry, "testuser2"
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 1, "Correct number of logins after deleting one");
// remove the login that's not shown in the list.
setupScript.sendSyncMessage("removeLogin", "login0");
});
@@ -575,92 +574,92 @@ add_task(async function test_form1_check
add_task(async function test_form2() {
// Turn our attention to form2
uname = $_(2, "uname");
pword = $_(2, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form3() {
uname = $_(3, "uname");
pword = $_(3, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form4() {
uname = $_(4, "uname");
pword = $_(4, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form5() {
uname = $_(5, "uname");
pword = $_(5, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form6() {
// (this is a control, w/o autocomplete=off, to ensure the login
// that was being suppressed would have been filled in otherwise)
uname = $_(6, "uname");
pword = $_(6, "pword");
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form6_changeUsername() {
// Test that the password field remains filled in after changing
// the username.
uname.focus();
- doKey("right");
- sendChar("X");
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
+ synthesizeKey("X", {code: "KeyX", shiftKey: true});
// Trigger the 'blur' event on uname
pword.focus();
await spinEventLoop();
checkACForm("singleuser5X", "singlepass5");
setupScript.sendSyncMessage("removeLogin", "login5");
});
@@ -681,23 +680,23 @@ add_task(async function test_form7() {
// automatically, removing it makes it more likely that we'll catch a
// future regression with form filling here.
setupScript.sendSyncMessage("removeLogin", "login6B");
});
add_task(async function test_form7_2() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
// The form changes, so we expect the old username field to get the
// selected autocomplete value, but neither the new username field nor
// the password field should have any values filled in.
await spinEventLoop();
checkACForm("form7user1", "");
is($_(7, "uname2").value, "", "Verifying empty uname2");
restoreForm(); // clear field, so reloading test doesn't fail
@@ -733,64 +732,64 @@ add_task(async function test_form9_filte
pword = $_(9, "pword");
uname.focus();
let shownPromise = promiseACShown();
sendString("form9userAB");
await shownPromise;
checkACForm("form9userAB", "");
uname.focus();
- doKey("left");
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
shownPromise = promiseACShown();
- sendChar("A");
+ synthesizeKey("A", {code: "KeyA", shiftKey: true});
let results = await shownPromise;
checkACForm("form9userAAB", "");
checkArrayValues(results, ["form9userAAB"], "Check dropdown is updated after inserting 'A'");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("form9userAAB", "form9pass");
});
add_task(async function test_form9_autocomplete_cache() {
// Note that this addLogin call will only be seen by the autocomplete
- // attempt for the sendChar if we do not successfully cache the
+ // attempt for the synthesizeKey if we do not successfully cache the
// autocomplete results.
setupScript.sendSyncMessage("addLogin", "login8C");
uname.focus();
let promise0 = notifyMenuChanged(0);
- sendChar("z");
+ synthesizeKey("z", {code: "KeyZ"});
await promise0;
let popupState = await getPopupState();
is(popupState.open, false, "Check popup shouldn't open");
// check that empty results are cached - bug 496466
promise0 = notifyMenuChanged(0);
- sendChar("z");
+ synthesizeKey("z", {code: "KeyZ"});
await promise0;
popupState = await getPopupState();
is(popupState.open, false, "Check popup stays closed due to cached empty result");
});
add_task(async function test_form11_formless() {
// Test form-less autocomplete
uname = $_(11, "uname");
pword = $_(11, "pword");
restoreForm();
checkACForm("", "");
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Trigger autocomplete
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
let processedPromise = promiseFormsProcessed();
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await processedPromise;
checkACForm("testuser", "testpass");
});
add_task(async function test_form11_open_on_trusted_focus() {
uname = $_(11, "uname");
pword = $_(11, "pword");
uname.value = "";
@@ -805,19 +804,19 @@ add_task(async function test_form11_open
ok(e.isTrusted, "Ensure event is trusted");
resolve();
});
});
const shownPromise = promiseACShown();
synthesizeMouseAtCenter(uname, {});
await firePrivEventPromise;
await shownPromise;
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
const processedPromise = promiseFormsProcessed();
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await processedPromise;
checkACForm("testuser", "testpass");
});
add_task(async function test_form12_recipes() {
await loadRecipes({
siteRecipes: [{
"hosts": ["mochi.test:8888"],
@@ -831,31 +830,31 @@ add_task(async function test_form12_reci
// First test DOMAutocomplete
// Switch the password field to type=password so _fillForm marks the username
// field for autocomplete.
pword.type = "password";
await promiseFormsProcessed();
restoreForm();
checkACForm("", "");
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser10", "testpass10");
// Now test recipes with blur on the username field.
restoreForm();
checkACForm("", "");
uname.value = "testuser10";
checkACForm("testuser10", "");
- doKey("tab");
+ synthesizeKey("KEY_Tab", {code: "Tab"});
await promiseFormsProcessed();
checkACForm("testuser10", "testpass10");
await resetRecipes();
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
@@ -82,66 +82,66 @@ add_task(async function test_empty_first
/* test 1 */
// Make sure initial form is empty.
checkACForm("", "");
// Trigger autocomplete popup
restoreForm();
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is initially closed");
let shownPromise = promiseACShown();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
let results = await shownPromise;
popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected");
checkArrayValues(results, ["name", "Name", "USER"], "initial");
// Check first entry
let index0Promise = notifySelectedIndex(0);
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await index0Promise;
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("name", "pass");
});
add_task(async function test_empty_second_entry() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("Name", "Pass");
});
add_task(async function test_empty_third_entry() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("USER", "PASS");
});
add_task(async function test_preserve_matching_username_case() {
restoreForm();
uname.value = "user";
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check that we don't clobber user-entered text when tabbing away
// (even with no autocomplete entry selected)
- doKey("tab");
+ synthesizeKey("KEY_Tab", {code: "Tab"});
await promiseFormsProcessed();
checkACForm("user", "PASS");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_autocomplete.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_autocomplete.html
@@ -178,17 +178,16 @@ var setupScript = runInParent(function s
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
-const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
// Restore the form to the default state.
function restoreForm() {
uname.value = "";
pword.value = "";
uname.focus();
}
@@ -224,226 +223,226 @@ add_task(async function test_form1_initi
is(popupState.open, false, "Check popup is initially closed");
});
add_task(async function test_form1_warning_entry() {
await SimpleTest.promiseFocus(window);
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
let expectedMenuItems = ["This connection is not secure. Logins entered here could be compromised. Learn More",
"tempuser1",
"testuser2",
"testuser3",
"zzzuser4"];
checkArrayValues(results, expectedMenuItems, "Check all menuitems are displayed correctly.");
- doKey("down"); // select insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select insecure warning
checkACForm("", ""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACForm("", "");
});
add_task(async function test_form1_first_entry() {
await SimpleTest.promiseFocus(window);
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
- doKey("down"); // skip insecure warning
- doKey("down"); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
checkACForm("", ""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_second_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("down"); // second
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_third_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser3", "testpass3");
});
add_task(async function test_form1_fourth_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("down"); // fourth
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // fourth
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_first_entry() {
// Trigger autocomplete popup
restoreForm();
await spinEventLoop(); // let focus happen
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("down"); // second
- doKey("down"); // third
- doKey("down"); // fourth
- doKey("down"); // deselects
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // third
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // fourth
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // deselects
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_wraparound_up_last_entry() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("up"); // last (fourth)
- doKey("return");
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last (fourth)
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_down_up_up() {
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // select first entry
- doKey("up"); // selects nothing!
- doKey("up"); // select last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // selects nothing!
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // select last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_wraparound_up_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down");
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("up");
- doKey("up");
- doKey("up"); // skip insecure warning
- doKey("up"); // first entry
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_fill_username_without_autofill_right() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Set first entry w/o triggering autocomplete
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("right");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
await spinEventLoop();
checkACForm("tempuser1", ""); // empty password
});
add_task(async function test_form1_fill_username_without_autofill_left() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Set first entry w/o triggering autocomplete
- doKey("down"); // skip insecure warning
- doKey("down"); // first
- doKey("left");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
checkACForm("tempuser1", ""); // empty password
});
add_task(async function test_form1_pageup_first() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// Check first entry (page up)
- doKey("down"); // first
- doKey("down"); // second
- doKey("page_up"); // first
- doKey("down"); // skip insecure warning
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // second
+ synthesizeKey("KEY_PageUp", {code: "PageUp"}); // first
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("tempuser1", "temppass1");
});
add_task(async function test_form1_pagedown_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// test 13
// Check last entry (page down)
- doKey("down"); // first
- doKey("page_down"); // last
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // first
+ synthesizeKey("KEY_PageDown", {code: "PageDown"}); // last
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_untrusted_event() {
restoreForm();
await spinEventLoop();
@@ -453,139 +452,139 @@ add_task(async function test_form1_untru
sendFakeAutocompleteEvent(uname);
await spinEventLoop();
checkACForm("zzzuser4", "");
});
add_task(async function test_form1_delete() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
// XXX tried sending character "t" before/during dropdown to test
// filtering, but had no luck. Seemed like the character was getting lost.
// Setting uname.value didn't seem to work either. This works with a human
// driver, so I'm not sure what's up.
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Delete the first entry (of 4), "tempuser1"
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
var numLogins;
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 5, "Correct number of logins before deleting one");
let countChangedPromise = notifyMenuChanged(4);
var deletionPromise = promiseStorageChanged(["removeLogin"]);
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
await deletionPromise;
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 4, "Correct number of logins after deleting one");
await countChangedPromise;
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_first_after_deletion() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check the new first entry (of 3)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_delete_second() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Delete the second entry (of 3), "testuser3"
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 3, "Correct number of logins after deleting one");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("zzzuser4", "zzzpass4");
});
add_task(async function test_form1_first_after_deletion2() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check the new first entry (of 2)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_delete_last() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// test 54
// Delete the last entry (of 2), "zzzuser4"
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 2, "Correct number of logins after deleting one");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_first_after_3_deletions() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check the only remaining entry
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser2", "testpass2");
});
add_task(async function test_form1_check_only_entry_remaining() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// test 56
// Delete the only remaining entry, "testuser2"
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkACForm("", "");
numLogins = LoginManager.countLogins("http://mochi.test:8888", "http://autocomplete:8888", null);
is(numLogins, 1, "Correct number of logins after deleting one");
// remove the login that's not shown in the list.
setupScript.sendSyncMessage("removeLogin", "login0");
});
@@ -593,96 +592,96 @@ add_task(async function test_form1_check
add_task(async function test_form2() {
// Turn our attention to form2
uname = $_(2, "uname");
pword = $_(2, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form3() {
uname = $_(3, "uname");
pword = $_(3, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form4() {
uname = $_(4, "uname");
pword = $_(4, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form5() {
uname = $_(5, "uname");
pword = $_(5, "pword");
checkACForm("singleuser5", "singlepass5");
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form6() {
// (this is a control, w/o autocomplete=off, to ensure the login
// that was being suppressed would have been filled in otherwise)
uname = $_(6, "uname");
pword = $_(6, "pword");
checkACForm("singleuser5", "singlepass5");
});
add_task(async function test_form6_changeUsername() {
// Test that the password field remains filled in after changing
// the username.
uname.focus();
- doKey("right");
- sendChar("X");
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
+ synthesizeKey("X", {code: "KeyX", shiftKey: true});
// Trigger the 'blur' event on uname
pword.focus();
await spinEventLoop();
checkACForm("singleuser5X", "singlepass5");
setupScript.sendSyncMessage("removeLogin", "login5");
});
@@ -703,24 +702,24 @@ add_task(async function test_form7() {
// automatically, removing it makes it more likely that we'll catch a
// future regression with form filling here.
setupScript.sendSyncMessage("removeLogin", "login6B");
});
add_task(async function test_form7_2() {
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
// The form changes, so we expect the old username field to get the
// selected autocomplete value, but neither the new username field nor
// the password field should have any values filled in.
await spinEventLoop();
checkACForm("form7user1", "");
is($_(7, "uname2").value, "", "Verifying empty uname2");
restoreForm(); // clear field, so reloading test doesn't fail
@@ -756,48 +755,48 @@ add_task(async function test_form9_filte
pword = $_(9, "pword");
uname.focus();
let shownPromise = promiseACShown();
sendString("form9userAB");
await shownPromise;
checkACForm("form9userAB", "");
uname.focus();
- doKey("left");
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
shownPromise = promiseACShown();
- sendChar("A");
+ synthesizeKey("A", {code: "KeyA", shiftKey: true});
let results = await shownPromise;
checkACForm("form9userAAB", "");
checkArrayValues(results, ["This connection is not secure. Logins entered here could be compromised. Learn More", "form9userAAB"],
"Check dropdown is updated after inserting 'A'");
- doKey("down"); // skip insecure warning
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("form9userAAB", "form9pass");
});
add_task(async function test_form9_autocomplete_cache() {
// Note that this addLogin call will only be seen by the autocomplete
- // attempt for the sendChar if we do not successfully cache the
+ // attempt for the synthesizeKey if we do not successfully cache the
// autocomplete results.
setupScript.sendSyncMessage("addLogin", "login8C");
uname.focus();
let promise0 = notifyMenuChanged(1);
let shownPromise = promiseACShown();
- sendChar("z");
+ synthesizeKey("z", {code: "KeyZ"});
await promise0;
await shownPromise;
let popupState = await getPopupState();
is(popupState.open, true, "Check popup should open");
// check that empty results are cached - bug 496466
promise0 = notifyMenuChanged(1);
- sendChar("z");
+ synthesizeKey("z", {code: "KeyZ"});
await promise0;
popupState = await getPopupState();
is(popupState.open, true, "Check popup stays opened due to cached empty result");
});
add_task(async function test_form11_recipes() {
await loadRecipes({
siteRecipes: [{
@@ -812,52 +811,52 @@ add_task(async function test_form11_reci
// First test DOMAutocomplete
// Switch the password field to type=password so _fillForm marks the username
// field for autocomplete.
pword.type = "password";
await promiseFormsProcessed();
restoreForm();
checkACForm("", "");
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await promiseFormsProcessed();
checkACForm("testuser10", "testpass10");
// Now test recipes with blur on the username field.
restoreForm();
checkACForm("", "");
uname.value = "testuser10";
checkACForm("testuser10", "");
- doKey("tab");
+ synthesizeKey("KEY_Tab", {code: "Tab"});
await promiseFormsProcessed();
checkACForm("testuser10", "testpass10");
await resetRecipes();
});
add_task(async function test_form12_formless() {
// Test form-less autocomplete
uname = $_(12, "uname");
pword = $_(12, "pword");
restoreForm();
checkACForm("", "");
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
- doKey("down"); // skip insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // skip insecure warning
// Trigger autocomplete
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkACForm("", ""); // value shouldn't update
let processedPromise = promiseFormsProcessed();
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await processedPromise;
checkACForm("testuser", "testpass");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_insecure_form_field_no_saved_login.html
@@ -40,17 +40,16 @@ SpecialPowers.setBoolPref(
SimpleTest.registerCleanupFunction(() => {
SpecialPowers.clearUserPref(
"security.insecure_field_warning.contextual.enabled");
});
let uname = $_(1, "uname");
let pword = $_(1, "pword");
-const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
// Restore the form to the default state.
function restoreForm() {
uname.value = "";
pword.value = "";
uname.focus();
}
@@ -78,26 +77,26 @@ add_task(async function test_form1_initi
is(popupState.open, false, "Check popup is initially closed");
});
add_task(async function test_form1_warning_entry() {
await SimpleTest.promiseFocus(window);
// Trigger autocomplete popup
restoreForm();
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
await shownPromise;
let popupState = await getPopupState();
is(popupState.open, true, "Check popup is opened");
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
- doKey("down"); // select insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select insecure warning
checkACForm("", ""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACForm("", "");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html
@@ -98,17 +98,16 @@ var setupScript = runInParent(function s
let { Services } =
SpecialPowers.Cu.import("resource://gre/modules/Services.jsm", {});
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
-const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
// Restore the form to the default state.
async function reinitializeForm(index) {
// Using innerHTML is for creating the autocomplete popup again, so the
// preference value will be applied to the constructor of
// UserAutoCompleteResult.
let form = document.getElementById("form" + index);
let temp = form.innerHTML;
@@ -167,131 +166,131 @@ add_task(async function test_form1_initi
add_task(async function test_form2_password_readonly() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", true],
["signon.autofillForms.http", true]
]});
await reinitializeForm(2);
// Trigger autocomplete popup
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is closed for a readonly field.");
});
add_task(async function test_form3_password_disabled() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", true],
["signon.autofillForms.http", true]
]});
await reinitializeForm(3);
// Trigger autocomplete popup
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is closed for a disabled field.");
});
add_task(async function test_form1_enabledInsecureFieldWarning_enabledInsecureAutoFillForm() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", true],
["signon.autofillForms.http", true]
]});
await reinitializeForm(1);
// Trigger autocomplete popup
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
let expectedMenuItems = ["This connection is not secure. Logins entered here could be compromised. Learn More",
"No username (" + DATE_NOW_STRING + ")",
"tempuser1",
"testuser2",
"testuser3",
"zzzuser4"];
checkArrayValues(results, expectedMenuItems, "Check all menuitems are displayed correctly.");
- doKey("down"); // select insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select insecure warning
checkACFormPasswordField(""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACFormPasswordField("");
});
add_task(async function test_form1_disabledInsecureFieldWarning_enabledInsecureAutoFillForm() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", false],
["signon.autofillForms.http", true]
]});
await reinitializeForm(1);
// Trigger autocomplete popup
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
let expectedMenuItems = ["No username (" + DATE_NOW_STRING + ")",
"tempuser1",
"testuser2",
"testuser3",
"zzzuser4"];
checkArrayValues(results, expectedMenuItems, "Check all menuitems are displayed correctly.");
- doKey("down"); // select first item
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select first item
checkACFormPasswordField(""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACFormPasswordField("user0pass");
});
add_task(async function test_form1_enabledInsecureFieldWarning_disabledInsecureAutoFillForm() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", true],
["signon.autofillForms.http", false]
]});
await reinitializeForm(1);
// Trigger autocomplete popup
let shownPromise = promiseACShown();
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let results = await shownPromise;
let popupState = await getPopupState();
is(popupState.selectedIndex, -1, "Check no entries are selected upon opening");
let expectedMenuItems = ["This connection is not secure. Logins entered here could be compromised. Learn More",
"No username (" + DATE_NOW_STRING + ")",
"tempuser1",
"testuser2",
"testuser3",
"zzzuser4"];
checkArrayValues(results, expectedMenuItems, "Check all menuitems are displayed correctly.");
- doKey("down"); // select insecure warning
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select insecure warning
checkACFormPasswordField(""); // value shouldn't update just by selecting
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
await spinEventLoop(); // let focus happen
checkACFormPasswordField("");
});
add_task(async function test_form1_disabledInsecureFieldWarning_disabledInsecureAutoFillForm() {
await SpecialPowers.pushPrefEnv({"set": [
["security.insecure_field_warning.contextual.enabled", false],
["signon.autofillForms.http", false]
]});
await reinitializeForm(1);
// Trigger autocomplete popup
- doKey("down"); // open
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // open
let popupState = await getPopupState();
is(popupState.open, false, "Check popup is closed with no AutoFillForms.");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/passwordmgr/test/pwmgr_common.js
+++ b/toolkit/components/passwordmgr/test/pwmgr_common.js
@@ -94,39 +94,16 @@ function checkUnmodifiedForm(formNum) {
continue;
is(ele.value, ele.defaultValue, "Test to default value of field " +
ele.name + " in form " + formNum);
}
}
/**
- * Mochitest gives us a sendKey(), but it's targeted to a specific element.
- * This basically sends an untargeted key event, to whatever's focused.
- */
-function doKey(aKey, modifier) {
- var keyName = "DOM_VK_" + aKey.toUpperCase();
- var key = KeyEvent[keyName];
-
- // undefined --> null
- if (!modifier)
- modifier = null;
-
- // Window utils for sending fake sey events.
- var wutils = SpecialPowers.wrap(window).
- QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
- getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
-
- if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
- wutils.sendKeyEvent("keypress", key, 0, modifier);
- }
- wutils.sendKeyEvent("keyup", key, 0, modifier);
-}
-
-/**
* Init with a common login
* If selfFilling is true or non-undefined, fires an event at the page so that
* the test can start checking filled-in values. Tests that check observer
* notifications might be confused by this.
*/
function commonInit(selfFilling) {
// eslint-disable-next-line mozilla/use-services
var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"].
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -40,36 +40,16 @@ function $_(formNum, name) {
if (element.hasAttribute("name") && element.getAttribute("name") != name) {
ok(false, "$_ got confused.");
return null;
}
return element;
}
-// Mochitest gives us a sendKey(), but it's targeted to a specific element.
-// This basically sends an untargeted key event, to whatever's focused.
-function doKey(aKey, modifier) {
- let keyName = "DOM_VK_" + aKey.toUpperCase();
- let key = SpecialPowers.Ci.nsIDOMKeyEvent[keyName];
-
- // undefined --> null
- if (!modifier) {
- modifier = null;
- }
-
- // Window utils for sending fake key events.
- let wutils = SpecialPowers.getDOMWindowUtils(window);
-
- if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
- wutils.sendKeyEvent("keypress", key, 0, modifier);
- }
- wutils.sendKeyEvent("keyup", key, 0, modifier);
-}
-
function registerPopupShownListener(listener) {
if (gPopupShownListener) {
ok(false, "got too many popupshownlisteners");
return;
}
gPopupShownListener = listener;
}
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -159,31 +159,31 @@ add_task(async function test_untrusted_e
]) {
// We must wait for the entire timeout for each individual test, because the
// next event in the list might prevent the popup from opening.
await expectPopupDoesNotOpen(triggerFn);
}
// A privileged key press will actually open the popup.
let popupShown = waitForNextPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await popupShown;
// The selected autocomplete item should not change from untrusted events.
for (let triggerFn of [
() => doKeyUnprivileged("down"),
() => doKeyUnprivileged("page_down"),
]) {
triggerFn();
await checkSelectedIndexAfterResponseTime(-1);
}
// A privileged key press will actually change the selected index.
let indexChanged = new Promise(resolve => notifySelectedIndex(0, resolve));
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await indexChanged;
// The selected autocomplete item should not change and it should not be
// possible to use it from untrusted events.
for (let triggerFn of [
() => doKeyUnprivileged("down"),
() => doKeyUnprivileged("page_down"),
() => doKeyUnprivileged("right"),
--- a/toolkit/components/satchel/test/test_bug_787624.html
+++ b/toolkit/components/satchel/test/test_bug_787624.html
@@ -1,13 +1,14 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Layout of Form History Autocomplete: Bug 787624</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
.container {
border: 1px solid #333;
width: 80px;
height: 26px;
@@ -68,17 +69,17 @@ add_task(async function test_popup_not_m
await new Promise(resolve => updateFormHistory([
{ op: "remove" },
{ op: "add", fieldname: "field1", value: "value1" },
{ op: "add", fieldname: "field1", value: "value2" },
], resolve));
let popupShown = waitForNextPopup();
input.focus();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await popupShown;
let newRect = input.getBoundingClientRect();
is(newRect.left, rect.left,
"autocomplete popup does not disturb the input position");
is(newRect.top, rect.top,
"autocomplete popup does not disturb the input position");
});
--- a/toolkit/components/satchel/test/test_datalist_with_caching.html
+++ b/toolkit/components/satchel/test/test_datalist_with_caching.html
@@ -98,39 +98,39 @@ function checkMenuEntries(expectedValues
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #" + i);
}
}
async function runTests() {
testNum++;
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
checkMenuEntries(["Sec", "First", "Second", "Secomundo"]);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Sec");
testNum++;
restoreForm();
sendString("Sec");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await expectPopup();
testNum++;
checkMenuEntries(["Sec", "Second", "Secomundo"]);
sendString("o");
await waitForMenuChange(2);
testNum++;
checkMenuEntries(["Second", "Secomundo"]);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Second");
SimpleTest.finish();
}
function startTest() {
setupFormHistory(runTests);
}
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -140,17 +140,16 @@ Form History test: form field autocomple
<pre id="test">
<script class="testbody" type="text/javascript">
/* import-globals-from ../../../../testing/mochitest/tests/SimpleTest/EventUtils.js */
/* import-globals-from satchel_common.js */
/** Test for Form History autocomplete **/
var input = $_(1, "field1");
-const shiftModifier = Event.SHIFT_MASK;
function setupFormHistory(aCallback) {
updateFormHistory([
{ op: "remove" },
{ op: "add", fieldname: "field1", value: "value1" },
{ op: "add", fieldname: "field1", value: "value2" },
{ op: "add", fieldname: "field1", value: "value3" },
{ op: "add", fieldname: "field1", value: "value4" },
@@ -247,203 +246,203 @@ function runTest() { // eslint-disable-l
switch (testNum) {
case 1:
// Make sure initial form is empty.
checkForm("");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 2:
checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value1");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 3:
// Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 4:
// Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value3");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 5:
// Check fourth entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 6:
// Check first entry (wraparound)
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down"); // deselects
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // deselects
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value1");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 7:
// Check the last entry via arrow-up
- doKey("up");
- doKey("return");
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 8:
// Check the last entry via arrow-up
- doKey("down"); // select first entry
- doKey("up"); // selects nothing!
- doKey("up"); // select last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}); // select first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // selects nothing!
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // select last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 9:
// Check the last entry via arrow-up (wraparound)
- doKey("down");
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("up");
- doKey("up");
- doKey("up"); // first entry
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"});
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // first entry
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // deselects
+ synthesizeKey("KEY_ArrowUp", {code: "ArrowUp"}); // last entry
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 10:
// Set first entry w/o triggering autocomplete
- doKey("down");
- doKey("right");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
checkForm("value1");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 11:
// Set first entry w/o triggering autocomplete
- doKey("down");
- doKey("left");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
checkForm("value1");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 12:
// Check first entry (page up)
- doKey("down");
- doKey("down");
- doKey("page_up");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_PageUp", {code: "PageUp"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value1");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 13:
// Check last entry (page down)
- doKey("down");
- doKey("page_down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_PageDown", {code: "PageDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
testNum = 49;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
/* Test removing entries from the dropdown */
case 50:
checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
// Delete the first entry (of 4)
setForm("value");
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
if (SpecialPowers.OS == "Darwin") {
- doKey("back_space", shiftModifier);
+ synthesizeKey("KEY_Backspace", {code: "Backspace", shiftKey: true});
} else {
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
}
// This tests that on OS X shift-backspace didn't delete the last character
// in the input (bug 480262).
waitForMenuChange(3);
break;
case 51:
@@ -451,122 +450,122 @@ function runTest() { // eslint-disable-l
countEntries("field1", "value1",
function(num) {
ok(!num, testNum + " checking that f1/v1 was deleted");
runTest();
});
break;
case 52:
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 53:
checkMenuEntries(["value2", "value3", "value4"], testNum);
// Check the new first entry (of 3)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 54:
// Delete the second entry (of 3)
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
waitForMenuChange(2);
break;
case 55:
checkForm("");
countEntries("field1", "value3",
function(num) {
ok(!num, testNum + " checking that f1/v3 was deleted");
runTest();
});
break;
case 56:
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value4");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 57:
checkMenuEntries(["value2", "value4"], testNum);
// Check the new first entry (of 2)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 58:
// Delete the last entry (of 2)
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
checkForm("");
waitForMenuChange(1);
break;
case 59:
countEntries("field1", "value4",
function(num) {
ok(!num, testNum + " checking that f1/v4 was deleted");
runTest();
});
break;
case 60:
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 61:
checkMenuEntries(["value2"], testNum);
// Check the new first entry (of 1)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value2");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 62:
// Delete the only remaining entry
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
waitForMenuChange(0);
break;
case 63:
checkForm("");
countEntries("field1", "value2",
function(num) {
ok(!num, testNum + " checking that f1/v2 was deleted");
@@ -575,54 +574,54 @@ function runTest() { // eslint-disable-l
break;
case 64:
// Look at form 2, trigger autocomplete popup
input = $_(2, "field2");
testNum = 99;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
/* Test entries with autocomplete=off */
case 100:
// Select first entry
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value1");
// Look at form 3, try to trigger autocomplete popup
input = $_(3, "field2");
restoreForm();
// Sometimes, this will fail if scrollTo(0, 0) is called, so that doesn't
// happen here. Fortunately, a different input is used from the last test,
// so a scroll should still occur.
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForScroll();
break;
case 101:
// Ensure there's no autocomplete dropdown (autocomplete=off is present)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("");
// Look at form 4, try to trigger autocomplete popup
input = $_(4, "field2");
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForMenuChange(0);
break;
case 102:
// Ensure there's no autocomplete dropdown (autocomplete=off is present)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("");
// Look at form 5, try to trigger autocomplete popup
input = $_(5, "field3");
restoreForm();
testNum = 199;
expectPopup();
input.focus();
@@ -642,51 +641,51 @@ function runTest() { // eslint-disable-l
checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
input.focus();
sendChar("\xc6");
waitForMenuChange(1);
break;
case 202:
checkMenuEntries(["aa\xe6"], testNum);
- doKey("back_space");
+ synthesizeKey("KEY_Backspace", {code: "Backspace"});
waitForMenuChange(3);
break;
case 203:
checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
- doKey("back_space");
+ synthesizeKey("KEY_Backspace", {code: "Backspace"});
waitForMenuChange(5);
break;
case 204:
checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum);
input.focus();
sendChar("z");
waitForMenuChange(2);
break;
case 205:
checkMenuEntries(["az", "aaz"], testNum);
input.focus();
- doKey("left");
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
expectPopup();
// Check case-insensitivity.
sendChar("A");
break;
case 206:
checkMenuEntries(["aaz"], testNum);
addEntry("field3", "aazq");
break;
case 207:
// check that results were cached
input.focus();
- doKey("right");
+ synthesizeKey("KEY_ArrowRight", {code: "ArrowRight"});
sendChar("q");
waitForMenuChange(0);
break;
case 208:
// check that results were cached
checkMenuEntries([], testNum);
addEntry("field3", "aazqq");
@@ -697,17 +696,17 @@ function runTest() { // eslint-disable-l
window.scrollTo(0, 0);
sendChar("q");
waitForMenuChange(0);
break;
case 210:
// check that empty results were cached - bug 496466
checkMenuEntries([], testNum);
- doKey("escape");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
// Look at form 6, try to trigger autocomplete popup
input = $_(6, "field4");
restoreForm();
testNum = 249;
expectPopup();
input.focus();
sendChar("a");
@@ -750,17 +749,17 @@ function runTest() { // eslint-disable-l
waitForMenuChange(2);
break;
case 254:
// check multi-word substring matches
checkMenuEntries(["bc d\xe6", "aba\xe6"]);
input.focus();
expectPopup();
- doKey("left");
+ synthesizeKey("KEY_ArrowLeft", {code: "ArrowLeft"});
sendChar("d");
break;
case 255:
// check inserting in multi-word searches
checkMenuEntries(["bc d\xe6"], testNum);
input.focus();
sendChar("z");
@@ -770,142 +769,142 @@ function runTest() { // eslint-disable-l
case 256:
checkMenuEntries([], testNum);
// Look at form 7, try to trigger autocomplete popup
input = $_(7, "field5");
testNum = 299;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 300:
checkMenuEntries(["1", "12", "123", "1234"], testNum);
input.maxLength = 4;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 301:
checkMenuEntries(["1", "12", "123", "1234"], testNum);
input.maxLength = 3;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 302:
checkMenuEntries(["1", "12", "123"], testNum);
input.maxLength = 2;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 303:
checkMenuEntries(["1", "12"], testNum);
input.maxLength = 1;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 304:
checkMenuEntries(["1"], testNum);
input.maxLength = 0;
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForMenuChange(0);
break;
case 305:
checkMenuEntries([], testNum);
input.maxLength = 4;
// now again with a character typed
input.focus();
sendChar("1");
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 306:
checkMenuEntries(["1", "12", "123", "1234"], testNum);
input.maxLength = 3;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 307:
checkMenuEntries(["1", "12", "123"], testNum);
input.maxLength = 2;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 308:
checkMenuEntries(["1", "12"], testNum);
input.maxLength = 1;
expectPopup();
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 309:
checkMenuEntries(["1"], testNum);
input.maxLength = 0;
- doKey("escape");
- doKey("down");
+ synthesizeKey("KEY_Escape", {code: "Escape"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForMenuChange(0);
break;
case 310:
checkMenuEntries([], testNum);
input = $_(8, "field6");
testNum = 399;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 400:
case 401:
case 402:
case 403:
checkMenuEntries(["value"], testNum);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value");
if (testNum == 400) {
input = $_(9, "field7");
} else if (testNum == 401) {
input = $_(10, "field8");
} else if (testNum == 402) {
input = $_(11, "field9");
} else if (testNum == 403) {
todo(false, "Fix input type=number");
input = $_(12, "field10");
}
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 404:
checkMenuEntries(["42"], testNum);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("42");
input = $_(14, "field11");
restoreForm();
waitForMenuChange(0);
break;
case 405:
@@ -920,108 +919,108 @@ function runTest() { // eslint-disable-l
case 406:
checkMenuEntries([]); // type=time with it's own control frame does not
// have a drop down menu for now
checkForm("");
input = $_(16, "field13");
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForMenuChange(0);
break;
case 407:
checkMenuEntries([]); // type=range does not have a drop down menu
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("30"); // default (midway between minimum (0) and maximum (64)) - step
input = $_(17, "field14");
restoreForm();
waitForMenuChange(0);
break;
case 408:
checkMenuEntries([]); // type=color does not have a drop down menu
checkForm("#000000"); // default color value
input = $_(18, "field15");
restoreForm();
expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 409:
checkMenuEntries(["2016-08"]);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("2016-08");
input = $_(19, "field16");
restoreForm();
expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 410:
checkMenuEntries(["2016-W32"]);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("2016-W32");
input = $_(20, "field17");
restoreForm();
expectPopup();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 411:
checkMenuEntries(["2016-10-21T10:10"]);
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("2016-10-21T10:10");
addEntry("field1", "value1");
break;
case 412:
input = $_(1, "field1");
// Go to test 500.
testNum = 499;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
// Check that the input event is fired.
case 500:
input.addEventListener("input", function(event) {
ok(true, testNum + " oninput should have been received");
ok(event.bubbles, testNum + " input event should bubble");
ok(event.cancelable, testNum + " input event should be cancelable");
}, {once: true});
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm("");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("value1");
testNum = 599;
setTimeout(runTest, 100);
break;
case 600:
// check we don't show autocomplete for searchbar-history
input = $_(13, "searchbar-history");
// Trigger autocomplete popup
checkForm("");
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
waitForMenuChange(0);
break;
case 601:
checkMenuEntries([], testNum);
input.blur();
SimpleTest.finish();
return;
--- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
@@ -43,17 +43,16 @@ Form History test: form field autocomple
<script class="testbody" type="text/javascript">
/* import-globals-from ../../../../testing/mochitest/tests/SimpleTest/EventUtils.js */
/* import-globals-from satchel_common.js */
/* eslint-disable complexity */
/** Test for Form History autocomplete **/
var input = $_(1, "field1");
-const shiftModifier = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
function setupFormHistory(aCallback) {
updateFormHistory([
{ op: "remove" },
{ op: "add", fieldname: "field1", value: "historyvalue" },
{ op: "add", fieldname: "field2", value: "othervalue" },
], aCallback);
}
@@ -112,260 +111,260 @@ function runTest() {
switch (testNum) {
case 1:
// Make sure initial form is empty.
checkForm("");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 2:
checkMenuEntries(["historyvalue", "PASS1", "PASS2", "final"], testNum);
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("historyvalue");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 3:
// Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 4:
// Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Reddit");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 5:
// Check fourth entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 6:
// Delete the first entry (of 3)
- doKey("down");
- doKey("delete", shiftModifier);
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Delete", {code: "Delete", shiftKey: true});
waitForMenuChange(3);
break;
case 7:
checkForm("");
countEntries("field1", "historyvalue",
function(num) {
ok(!num, testNum + " checking that form history value was deleted");
runTest();
});
break;
case 8:
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 9:
// Test deletion
checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
// Check the new first entry (of 3)
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 10:
// Test autocompletion of datalists with cached results.
sendString("PAS");
waitForMenuChange(2);
break;
case 11:
// Continuation of test 10
sendString("S1");
waitForMenuChange(1);
break;
case 12:
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
// Trigger autocomplete popup
// Look at form 3, try to trigger autocomplete popup
input.value = "";
input = $_(3, "field2");
testNum = 99;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 100:
checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 101:
// Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Reddit");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 102:
// Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 103:
checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
// Check first entry
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 104:
// Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Reddit");
// Trigger autocomplete popup
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 105:
// Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
testNum = 199;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
// Test dynamic updates.
// For some reasons, when there is an update of the list, the selection is
// lost so we need to go down like if we were at the beginning of the list
// again.
case 200:
// Removing the second element while on the first then going down and
// push enter. Value should be one from the third suggesion.
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
datalist = document.getElementById("suggest");
let toRemove = datalist.children[1];
datalist.removeChild(toRemove);
SimpleTest.executeSoon(function() {
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
// Restore the element.
datalist.insertBefore(toRemove, datalist.children[1]);
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
});
break;
case 201:
// Adding an attribute after the first one while on the first then going
// down and push enter. Value should be the on from the new suggestion.
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
datalist = document.getElementById("suggest");
let added = new Option("Foo");
datalist.insertBefore(added, datalist.children[1]);
waitForMenuChange(4);
break;
case 202:
- doKey("down");
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Foo");
// Remove the element.
datalist = document.getElementById("suggest");
datalist.removeChild(datalist.children[1]);
waitForMenuChange(0);
break;
@@ -374,18 +373,18 @@ function runTest() {
restoreForm();
datalist = document.getElementById("suggest");
prevValue = datalist.children[0].value;
datalist.children[0].value = "foo";
expectPopup();
break;
case 204:
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("foo");
datalist = document.getElementById("suggest");
datalist.children[0].value = prevValue;
waitForMenuChange(0);
break;
case 205:
@@ -394,93 +393,93 @@ function runTest() {
datalist = document.getElementById("suggest");
prevValue = datalist.children[0].getAttribute("value");
datalist.children[0].removeAttribute("value");
datalist.children[0].textContent = "foobar";
expectPopup();
break;
case 206:
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("foobar");
datalist = document.getElementById("suggest");
datalist.children[0].setAttribute("value", prevValue);
testNum = 299;
waitForMenuChange(0);
break;
// Tests for filtering (or not).
case 300:
// Filters with first letter of the word.
restoreForm();
- synthesizeKey("f", {});
+ synthesizeKey("f", {code: "KeyF"});
expectPopup();
break;
case 301:
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 302:
// Filter with a letter in the middle of the word.
- synthesizeKey("i", {});
- synthesizeKey("n", {});
+ synthesizeKey("i", {code: "KeyI"});
+ synthesizeKey("n", {code: "KeyN"});
waitForMenuChange(1);
break;
case 303:
// Continuation of test 302.
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("final");
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 304:
// Filter is disabled with mozNoFilter.
input.setAttribute("mozNoFilter", "true");
- synthesizeKey("f", {});
+ synthesizeKey("f", {code: "KeyF"});
waitForMenuChange(3); // no change
break;
case 305:
// Continuation of test 304.
- doKey("down");
- doKey("return");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"});
checkForm("Google");
input.removeAttribute("mozNoFilter");
testNum = 399;
expectPopup();
restoreForm();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
break;
case 400:
// Check that the input event is fired.
input.addEventListener("input", function(event) {
ok(true, "oninput should have been received");
ok(event.bubbles, "input event should bubble");
ok(event.cancelable, "input event should be cancelable");
checkForm("Google");
input.blur();
SimpleTest.finish();
}, {once: true});
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
checkForm("");
- doKey("return");
+ synthesizeKey("KEY_Enter", {code: "Enter"});
break;
default:
ok(false, "Unexpected invocation of test #" + testNum);
SimpleTest.finish();
}
}
--- a/toolkit/components/satchel/test/test_password_autocomplete.html
+++ b/toolkit/components/satchel/test/test_password_autocomplete.html
@@ -102,22 +102,22 @@ add_task(async function test_initialize(
add_task(async function test_secure_noFormHistoryOrWarning() {
let input = $_(1, "field1");
// The autocomplete popup should not open under any circumstances on
// type=password with password manager disabled.
for (let triggerFn of [
() => input.focus(),
() => input.click(),
- () => doKey("down"),
- () => doKey("page_down"),
- () => doKey("return"),
- () => doKey("v"),
- () => doKey(" "),
- () => doKey("back_space"),
+ () => synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"}),
+ () => synthesizeKey("KEY_PageDown", {code: "PageDown"}),
+ () => synthesizeKey("KEY_Enter", {code: "Enter"}),
+ () => synthesizeKey("v", {code: "KeyV"}),
+ () => synthesizeKey(" ", {code: "Space"}),
+ () => synthesizeKey("KEY_Backspace", {code: "Backspace"}),
]) {
ok(true, "Testing: " + triggerFn.toString());
// We must wait for the entire timeout for each individual test, because the
// next event in the list might prevent the popup from opening.
await expectPopupDoesNotOpen(triggerFn);
}
// Close the popup.
--- a/toolkit/components/satchel/test/test_popup_direction.html
+++ b/toolkit/components/satchel/test/test_popup_direction.html
@@ -1,13 +1,14 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Popup Direction</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<script type="text/javascript" src="satchel_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Test for Popup Direction
<p id="display"></p>
@@ -40,17 +41,17 @@ add_task(async function test_popup_direc
{ op: "add", fieldname: "field1", value: "value2" },
], resolve));
for (let direction of ["ltr", "rtl"]) {
document.getElementById("content").style.direction = direction;
let popupShown = waitForNextPopup();
input.focus();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
await popupShown;
let popupState = await new Promise(resolve => getPopupState(resolve));
is(popupState.direction, direction, "Direction should match.");
// Close the popup.
input.blur();
}
--- a/toolkit/components/satchel/test/test_popup_enter_event.html
+++ b/toolkit/components/satchel/test/test_popup_enter_event.html
@@ -47,19 +47,19 @@ function handleEnter(evt) {
is(input.value, expectedValue, "Check input value when enter is pressed the 2nd time");
info("form should submit with the default handler");
} else {
ok(false, "RETURN keypress shouldn't have been received when a popup item is selected");
}
}
function popupShownListener(evt) {
- doKey("down");
- doKey("return"); // select the first entry in the popup
- doKey("return"); // try to submit the form with the filled value
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
+ synthesizeKey("KEY_Enter", {code: "Enter"}); // select the first entry in the popup
+ synthesizeKey("KEY_Enter", {code: "Enter"}); // try to submit the form with the filled value
}
function runTest() {
input.addEventListener("keypress", handleEnter, true);
form.addEventListener("submit", function submitCallback(evt) {
is(input.value, expectedValue, "Check input value in the submit handler");
evt.preventDefault();
@@ -69,17 +69,17 @@ function runTest() {
SimpleTest.finish();
});
// Focus the input before adjusting.value so that the caret goes to the end
// (since OS X doesn't show the dropdown otherwise).
input.focus();
input.value = "value";
input.focus();
- doKey("down");
+ synthesizeKey("KEY_ArrowDown", {code: "ArrowDown"});
}
function startTest() {
setupFormHistory(function() {
runTest();
});
}
--- a/widget/headless/tests/test_headless.js
+++ b/widget/headless/tests/test_headless.js
@@ -131,24 +131,27 @@ add_task(function* test_snapshot_widget_
});
// Ensure keydown events are triggered on the windowless browser.
add_task(async function test_keydown() {
let windowlessBrowser = Services.appShell.createWindowlessBrowser(false);
let webNavigation = windowlessBrowser.QueryInterface(Ci.nsIWebNavigation);
let contentWindow = await loadContentWindow(webNavigation, HEADLESS_URL);
- let utils = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils);
let keydown = new Promise((resolve) => {
contentWindow.addEventListener("keydown", () => {
resolve();
}, { once: true });
})
- utils.sendKeyEvent("keydown", 65, 65, 0);
+
+ let tip = Cc["@mozilla.org/text-input-processor;1"]
+ .createInstance(Ci.nsITextInputProcessor);
+ let begun = tip.beginInputTransactionForTests(contentWindow);
+ ok(begun, "nsITextInputProcessor.beginInputTransactionForTests() should succeed");
+ tip.keydown(new contentWindow.KeyboardEvent("", {key: "a", code: "KeyA", keyCode: contentWindow.KeyboardEvent.DOM_VK_A}));
await keydown;
ok(true, "Send keydown didn't crash");
webNavigation.close();
});
// Test dragging the mouse on a button to ensure the creation of the drag