diff --git a/browser/base/content/test/browser_sanitizeDialog_treeView.js b/browser/base/content/test/browser_sanitizeDialog_treeView.js index 654ac7bc5d45..9abe1d6a7406 100644 --- a/browser/base/content/test/browser_sanitizeDialog_treeView.js +++ b/browser/base/content/test/browser_sanitizeDialog_treeView.js @@ -401,9 +401,8 @@ WindowHelper.prototype = { let key = aDelta < 0 ? "UP" : "DOWN"; let abs = Math.abs(aDelta); let treechildren = this.getTree().treeBoxObject.treeBody; - treechildren.focus(); for (let i = 0; i < abs; i++) { - EventUtils.sendKey(key); + EventUtils.sendKey(key, treechildren); } }, diff --git a/browser/devtools/styleinspector/test/browser/browser_ruleview_editor.js b/browser/devtools/styleinspector/test/browser/browser_ruleview_editor.js index 181d67eb3db8..0aad26422486 100644 --- a/browser/devtools/styleinspector/test/browser/browser_ruleview_editor.js +++ b/browser/devtools/styleinspector/test/browser/browser_ruleview_editor.js @@ -41,7 +41,7 @@ function testReturnCommit() start: function() { is(span.inplaceEditor.input.value, "explicit initial", "Explicit initial value should be used."); span.inplaceEditor.input.value = "Test Value"; - EventUtils.sendKey("return"); + EventUtils.sendKey("return", span.inplaceEditor.input); }, done: expectDone("Test Value", true, testBlurCommit) }); @@ -74,7 +74,7 @@ function testAdvanceCharCommit() start: function() { let input = span.inplaceEditor.input; for each (let ch in "Test:") { - EventUtils.sendChar(ch); + EventUtils.sendChar(ch, input); } }, done: expectDone("Test", true, testEscapeCancel) @@ -91,7 +91,7 @@ function testEscapeCancel() initial: "initial text", start: function() { span.inplaceEditor.input.value = "Test Value"; - EventUtils.sendKey("escape"); + EventUtils.sendKey("escape", span.inplaceEditor.input); }, done: expectDone("initial text", false, finishTest) }); diff --git a/browser/devtools/styleinspector/test/browser/browser_ruleview_ui.js b/browser/devtools/styleinspector/test/browser/browser_ruleview_ui.js index c0767aaffe02..636d5dc5f891 100644 --- a/browser/devtools/styleinspector/test/browser/browser_ruleview_ui.js +++ b/browser/devtools/styleinspector/test/browser/browser_ruleview_ui.js @@ -120,7 +120,7 @@ function testCreateNew() aEditor.input.blur(); }); - EventUtils.sendKey("return", ruleDialog); + EventUtils.sendKey("return", input); }); EventUtils.synthesizeMouse(elementRuleEditor.closeBrace, 1, 1, @@ -148,11 +148,11 @@ function testEditProperty() }); for each (let ch in "red;") { - EventUtils.sendChar(ch, ruleDialog); + EventUtils.sendChar(ch, input); } }); for each (let ch in "border-color:") { - EventUtils.sendChar(ch, ruleDialog); + EventUtils.sendChar(ch, input); } }); diff --git a/content/html/content/test/test_bug388794.html b/content/html/content/test/test_bug388794.html index 866adabcca98..a6cc4778c071 100644 --- a/content/html/content/test/test_bug388794.html +++ b/content/html/content/test/test_bug388794.html @@ -62,8 +62,7 @@ var hrefs = { function submitForm(idNum) { $("test"+idNum).setAttribute("onload", "frameLoaded(this)"); - $("test" + idNum + "image").focus(); - sendKey("return"); + sendKey("return", "test" + idNum + "image"); } function submitFormMouse(idNum) { diff --git a/content/html/content/test/test_bug424698.html b/content/html/content/test/test_bug424698.html index 9bd6ea5ff3aa..a8f046d9527e 100644 --- a/content/html/content/test/test_bug424698.html +++ b/content/html/content/test/test_bug424698.html @@ -76,7 +76,7 @@ is(i.value, "test3", "Setting textarea defaultValue after hide/show should work" i = $("target2"); i.focus(); // Otherwise editor gets confused when we send the key events is(i.value, "", "Textarea value should be empty string in second control"); -sendString("2test2"); +sendString("2test2", "target2"); is(i.value, "2test2", 'We just typed the string "2test2"'); i.defaultValue = "2test3"; is(i.value, "2test2", "Setting textarea defaultValue after typing should not work"); diff --git a/content/html/content/test/test_bug558788-1.html b/content/html/content/test/test_bug558788-1.html index 94b7a5f00ea5..4e999b1f9650 100644 --- a/content/html/content/test/test_bug558788-1.html +++ b/content/html/content/test/test_bug558788-1.html @@ -121,7 +121,7 @@ function checkInputEmail() synthesizeKey("a", {}); checkInvalidApplies(element); - sendString("@b.c"); + sendString("@b.c", element); checkValidApplies(element); synthesizeKey("VK_BACK_SPACE", {}); @@ -151,7 +151,7 @@ function checkInputURL() synthesizeKey("h", {}); checkInvalidApplies(element); - sendString("ttp://mozilla.org"); + sendString("ttp://mozilla.org", element); checkValidApplies(element); for (var i=0; i<13; ++i) { diff --git a/docshell/test/navigation/test_bug386782.html b/docshell/test/navigation/test_bug386782.html index 609d7912a983..9d474d0a5f6b 100644 --- a/docshell/test/navigation/test_bug386782.html +++ b/docshell/test/navigation/test_bug386782.html @@ -66,7 +66,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=386782 // WARNING: If the following test fails, give the setTimeout() in the onload() // a bit longer; the doc hasn't had enough time to setup its editor. is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Is doc setup yet"); - sendString('EDITED ', gTest.window); + + sendChar('E', gTest.window.document.body); + sendChar('D', gTest.window.document.body); + sendChar('I', gTest.window.document.body); + sendChar('T', gTest.window.document.body); + sendChar('E', gTest.window.document.body); + sendChar('D', gTest.window.document.body); + sendChar(' ', gTest.window.document.body); is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Editing failed."); gTest.window.location = 'data:text/html;charset=utf-8,SomeOtherDocument'; @@ -96,7 +103,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=386782 // Check that we can still edit the page. gTest.window.document.body.focus(); - sendString('TWICE ', gTest.window); + sendChar('T', gTest.window.document.body); + sendChar('W', gTest.window.document.body); + sendChar('I', gTest.window.document.body); + sendChar('C', gTest.window.document.body); + sendChar('E', gTest.window.document.body); + sendChar(' ', gTest.window.document.body); is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterSecondEdit, "Can we still edit?"); gTest.window.close(); diff --git a/docshell/test/navigation/test_bug430624.html b/docshell/test/navigation/test_bug430624.html index 9fc92e4cd305..31c5b8648d04 100644 --- a/docshell/test/navigation/test_bug430624.html +++ b/docshell/test/navigation/test_bug430624.html @@ -36,8 +36,12 @@ function onReload() { function doTest() { var bodyElement = window.frames[0].frameElement.contentDocument.body; - bodyElement.focus(); - sendString('Still ', window.frames[0].frameElement.contentWindow); + sendChar('S', bodyElement); + sendChar('t', bodyElement); + sendChar('i', bodyElement); + sendChar('l', bodyElement); + sendChar('l', bodyElement); + sendChar(' ', bodyElement); is(bodyElement.innerHTML, "Still contentEditable", "Check we're contentEditable after reload"); diff --git a/docshell/test/navigation/test_bug430723.html b/docshell/test/navigation/test_bug430723.html index 0179f4cdb3f4..5e18b10d23d5 100644 --- a/docshell/test/navigation/test_bug430723.html +++ b/docshell/test/navigation/test_bug430723.html @@ -62,20 +62,15 @@ var step1 =function() { // Navigate down and up. is(testWindow.document.body.scrollTop, 0, "Page1: Ensure we scrollpane is at the top before we start scrolling."); - testWindow.focus(); sendKey('DOWN', testWindow); - SimpleTest.executeSoon(function() { - isnot(testWindow.document.body.scrollTop, 0, - "Page1: Ensure we can scroll down."); - sendKey('UP', testWindow); - SimpleTest.executeSoon(function() { - is(testWindow.document.body.scrollTop, 0, - "Page1: Ensure we can scroll up, back to the top."); - - // Nav to blue box page. This should fire step2. - testWindow.location = gTallBlueBoxURI; - }); - }); + sendKey('UP', testWindow); + setTimeout(function() { + is(testWindow.document.body.scrollTop, 0, + "Page1: Ensure we can scroll down and up, back to the top."); + + // Nav to blue box page. This should fire step2. + testWindow.location = gTallBlueBoxURI; + }, 0); } @@ -85,7 +80,6 @@ var step2 =function() { // Scroll around a bit. is(testWindow.document.body.scrollTop, 0, "Page2: Ensure we scrollpane is at the top before we start scrolling."); - testWindow.focus(); sendKey('DOWN', testWindow); sendKey('DOWN', testWindow); sendKey('DOWN', testWindow); @@ -105,7 +99,6 @@ var step3 =function() { // Check we can still scroll with the keys. is(testWindow.document.body.scrollTop, 0, "Page1Again: Ensure scroll pane at top before we scroll."); - testWindow.focus(); sendKey('DOWN', testWindow); setTimeout(function() { isnot(testWindow.document.body.scrollTop, 0, diff --git a/editor/composer/test/test_bug389350.html b/editor/composer/test/test_bug389350.html index bf1d514addbf..1400d3c1b980 100644 --- a/editor/composer/test/test_bug389350.html +++ b/editor/composer/test/test_bug389350.html @@ -15,7 +15,9 @@ function runTest() { e.contentDocument.designMode='on'; e.style.display='block'; e.focus(); - sendString('abc'); + sendChar('a', e.contentDocument); + sendChar('b', e.contentDocument); + sendChar('c', e.contentDocument); var expected = "abc"; var result = e.contentDocument.documentElement.innerHTML; is(result, expected, "iframe with designmode on had incorrect content"); diff --git a/editor/libeditor/html/tests/test_bug432225.html b/editor/libeditor/html/tests/test_bug432225.html index afda7fbd61fd..91deb43270f9 100644 --- a/editor/libeditor/html/tests/test_bug432225.html +++ b/editor/libeditor/html/tests/test_bug432225.html @@ -58,7 +58,12 @@ function addWords(aLimit) { return; } getEdit().focus(); - sendString('aa OK '); + sendChar('a', editDoc()); + sendChar('a', editDoc()); + sendChar(' ', editDoc()); + sendChar('O', editDoc()); + sendChar('K', editDoc()); + sendChar(' ', editDoc()); gMisspeltWords.push("aa"); setTimeout(function() { addWords(aLimit-1); }, 0); } diff --git a/editor/libeditor/html/tests/test_bug455992.html b/editor/libeditor/html/tests/test_bug455992.html index d4f4be27ba8f..16fb67defa83 100644 --- a/editor/libeditor/html/tests/test_bug455992.html +++ b/editor/libeditor/html/tests/test_bug455992.html @@ -27,7 +27,7 @@ function runTest() { function test_begin_bs(e) { const msg = "BACKSPACE at beginning of contenteditable inline element"; var before = e.parentNode.childNodes[0].nodeValue; - sendKey("back_space"); + sendKey("back_space", e); is(e.parentNode.childNodes[0].nodeValue, before, msg + " with id=" + e.id); is(e.innerHTML, "X", msg + " with id=" + e.id); } @@ -35,7 +35,7 @@ function runTest() { function test_begin_space(e) { const msg = "SPACE at beginning of contenteditable inline element"; var before = e.parentNode.childNodes[0].nodeValue; - sendChar(" "); + sendChar(" ", e); is(e.parentNode.childNodes[0].nodeValue, before, msg + " with id=" + e.id); is(e.innerHTML, " X", msg + " with id=" + e.id); } @@ -43,8 +43,8 @@ function runTest() { function test_end_delete(e) { const msg = "DEL at end of contenteditable inline element"; var before = e.parentNode.childNodes[2].nodeValue; - sendKey("right"); - sendKey("delete"); + sendKey("right", e); + sendKey("delete", e); is(e.parentNode.childNodes[2].nodeValue, before, msg + " with id=" + e.id); is(e.innerHTML, "X", msg + " with id=" + e.id); } @@ -52,8 +52,8 @@ function runTest() { function test_end_space(e) { const msg = "SPACE at end of contenteditable inline element"; var before = e.parentNode.childNodes[2].nodeValue; - sendKey("right"); - sendChar(" "); + sendKey("right", e); + sendChar(" ", e); is(e.parentNode.childNodes[2].nodeValue, before, msg + " with id=" + e.id); is(e.innerHTML, "X" + (e.tagName=="SPAN" ? " " : "
"), msg + " with id=" + e.id); } diff --git a/editor/libeditor/html/tests/test_bug456244.html b/editor/libeditor/html/tests/test_bug456244.html index d85970f3f53c..89883b981042 100644 --- a/editor/libeditor/html/tests/test_bug456244.html +++ b/editor/libeditor/html/tests/test_bug456244.html @@ -27,9 +27,9 @@ function runTest() { function test_end_bs(e) { const msg = "Deleting all text in contenteditable inline element"; var before = e.parentNode.childNodes[0].nodeValue; - sendKey("right"); - sendKey("back_space"); - sendKey("back_space"); + sendKey("right", e); + sendKey("back_space", e); + sendKey("back_space", e); is(e.parentNode.childNodes[0].nodeValue, before, msg + " with id=" + e.id); is(e.innerHTML, "", msg + " with id=" + e.id); } @@ -43,8 +43,8 @@ function runTest() { var doc = e.contentDocument; doc.body.setAttribute("contenteditable", "true"); doc.body.focus(); - sendKey("right"); - sendKey("back_space"); + sendKey("right", doc.body); + sendKey("back_space", doc.body); is(doc.body.innerHTML, "
", msg + " with id=" + e.id); } diff --git a/editor/libeditor/html/tests/test_bug487524.html b/editor/libeditor/html/tests/test_bug487524.html index 8f4b83b812e2..82c116150e35 100644 --- a/editor/libeditor/html/tests/test_bug487524.html +++ b/editor/libeditor/html/tests/test_bug487524.html @@ -31,7 +31,7 @@ function runTest() { range.setEnd(li1.nextSibling,0); selection.addRange(range); - sendKey('delete'); + sendKey('delete', li1); is(doc.body.innerHTML,'','delete 1st LI'); var li2 = setupIframe(i1,'','li2') @@ -43,7 +43,7 @@ function runTest() { range.setEnd(li2.nextSibling.firstChild,0); selection.addRange(range); - sendKey('delete'); + sendKey('delete', li2); is(doc.body.innerHTML,'','delete 2nd LI'); SimpleTest.finish(); diff --git a/editor/libeditor/html/tests/test_bug607584.xul b/editor/libeditor/html/tests/test_bug607584.xul index 1bea95d760f6..dec88720550d 100644 --- a/editor/libeditor/html/tests/test_bug607584.xul +++ b/editor/libeditor/html/tests/test_bug607584.xul @@ -57,13 +57,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=607584 { var editor = this.mEditor.getEditor(this.mEditor.contentWindow); if (editor) { - this.mEditor.focus(); editor instanceof Components.interfaces.nsIHTMLEditor; editor.returnInParagraphCreatesNewParagraph = true; editor.insertHTML("

this is a paragraph carrying id 'foo'

"); var p = editor.document.getElementById('foo') editor.beginningOfDocument(); - sendKey("return"); + sendKey("return", p); var firstP = p.parentNode.firstElementChild; var lastP = p.parentNode.lastElementChild; var isOk = firstP.nodeName.toLowerCase() == "p" && diff --git a/editor/libeditor/text/tests/test_bug641466.html b/editor/libeditor/text/tests/test_bug641466.html index 4a77b0b8962f..73aff98301b8 100644 --- a/editor/libeditor/text/tests/test_bug641466.html +++ b/editor/libeditor/text/tests/test_bug641466.html @@ -26,10 +26,10 @@ SimpleTest.waitForFocus(function() { element.focus(); element.selectionStart = 4; element.selectionEnd = 4; - synthesizeKey("VK_BACK_SPACE", {}); - synthesizeKey("VK_BACK_SPACE", {}); - synthesizeKey("VK_BACK_SPACE", {}); - synthesizeKey("VK_BACK_SPACE", {}); + synthesizeKey("VK_BACKSPACE", {}); + synthesizeKey("VK_BACKSPACE", {}); + synthesizeKey("VK_BACKSPACE", {}); + synthesizeKey("VK_BACKSPACE", {}); ok(element.value, "", "4 backspaces should delete all of the characters in the " + element.localName); } diff --git a/layout/base/tests/bug106855-1-ref.html b/layout/base/tests/bug106855-1-ref.html index 7bfb81815f1f..3344ad1a4924 100644 --- a/layout/base/tests/bug106855-1-ref.html +++ b/layout/base/tests/bug106855-1-ref.html @@ -17,10 +17,10 @@ y var area = document.getElementById('t'); area.focus(); - sendKey('RIGHT'); // now after "A" - sendKey('RIGHT'); // - sendKey('RIGHT'); // - sendKey('RIGHT'); // now at the last line + sendKey('RIGHT', window); // now after "A" + sendKey('RIGHT', window); // + sendKey('RIGHT', window); // + sendKey('RIGHT', window); // now at the last line diff --git a/layout/base/tests/bug106855-1.html b/layout/base/tests/bug106855-1.html index 7d5cae7b6bd1..8ccb55757aaf 100644 --- a/layout/base/tests/bug106855-1.html +++ b/layout/base/tests/bug106855-1.html @@ -17,9 +17,9 @@ y var area = document.getElementById('t'); area.focus(); - sendKey('DOWN'); // now after "A" - sendKey('DOWN'); // - sendKey('DOWN'); // now at the last line + sendKey('DOWN', window); // now after "A" + sendKey('DOWN', window); // + sendKey('DOWN', window); // now at the last line diff --git a/layout/base/tests/bug106855-2.html b/layout/base/tests/bug106855-2.html index 40c13f353564..2390169ef490 100644 --- a/layout/base/tests/bug106855-2.html +++ b/layout/base/tests/bug106855-2.html @@ -17,10 +17,10 @@ y var area = document.getElementById('t'); area.focus(); - sendKey('DOWN'); // now after "A" - sendKey('DOWN'); // - sendKey('DOWN'); // - sendKey('DOWN'); // now at the last line + sendKey('DOWN', window); // now after "A" + sendKey('DOWN', window); // + sendKey('DOWN', window); // + sendKey('DOWN', window); // now at the last line diff --git a/layout/base/tests/bug240933-1.html b/layout/base/tests/bug240933-1.html index 1872d532d732..7db3b4fca291 100644 --- a/layout/base/tests/bug240933-1.html +++ b/layout/base/tests/bug240933-1.html @@ -7,7 +7,7 @@ var area = document.getElementById('t'); area.focus(); - sendKey('ENTER'); // press Enter once + sendKey('ENTER', "t"); // press Enter once diff --git a/layout/base/tests/bug240933-2.html b/layout/base/tests/bug240933-2.html index a685c009e89a..6c2feecb4392 100644 --- a/layout/base/tests/bug240933-2.html +++ b/layout/base/tests/bug240933-2.html @@ -7,9 +7,9 @@ var area = document.getElementById('t'); area.focus(); - sendKey('ENTER'); // press Enter twice - sendKey('ENTER'); - sendKey('BACK_SPACE'); // press Backspace once + sendKey('ENTER', "t"); // press Enter twice + sendKey('ENTER', "t"); + sendKey('BACK_SPACE', "t"); // press Backspace once diff --git a/layout/base/tests/bug482484.html b/layout/base/tests/bug482484.html index ee65dc5d22bf..f5d122e6ae31 100644 --- a/layout/base/tests/bug482484.html +++ b/layout/base/tests/bug482484.html @@ -15,8 +15,8 @@ range.setEnd(p.firstChild, 0); sel.addRange(range); - sendKey('UP'); // move UP - sendChar('A'); // insert "A" + sendKey('UP', div); // move UP + sendChar('A', div); // insert "A" diff --git a/layout/base/tests/bug512295-1.html b/layout/base/tests/bug512295-1.html index de547e6c301f..77c21e4d90be 100644 --- a/layout/base/tests/bug512295-1.html +++ b/layout/base/tests/bug512295-1.html @@ -19,12 +19,12 @@ x sel.addRange(range); p.parentNode.focus(); - sendKey('DOWN'); // now after "1" - sendKey('DOWN'); // now make sure we get to the end - sendKey('DOWN'); // now make sure we get to the end - sendKey('DOWN'); // now make sure we get to the end - sendKey('DOWN'); // now make sure we get to the end - sendKey('DOWN'); // now make sure we get to the end + sendKey('DOWN', window); // now after "1" + sendKey('DOWN', window); // now make sure we get to the end + sendKey('DOWN', window); // now make sure we get to the end + sendKey('DOWN', window); // now make sure we get to the end + sendKey('DOWN', window); // now make sure we get to the end + sendKey('DOWN', window); // now make sure we get to the end diff --git a/layout/base/tests/bug512295-2.html b/layout/base/tests/bug512295-2.html index 51f283f3900e..ba0afbaa3a77 100644 --- a/layout/base/tests/bug512295-2.html +++ b/layout/base/tests/bug512295-2.html @@ -19,12 +19,12 @@ x sel.addRange(range); p.parentNode.focus(); - sendKey('DOWN'); // now after "1" - sendKey('DOWN'); // now below the P element - sendKey('UP'); // now before the "1" - sendKey('UP'); // now before the "A" - sendKey('UP'); // now before the "A" - sendKey('UP'); // now before the "A" + sendKey('DOWN', window); // now after "1" + sendKey('DOWN', window); // now below the P element + sendKey('UP', window); // now before the "1" + sendKey('UP', window); // now before the "A" + sendKey('UP', window); // now before the "A" + sendKey('UP', window); // now before the "A" diff --git a/layout/base/tests/bug602141-1.html b/layout/base/tests/bug602141-1.html index 2e79165dc215..dd76e1989d2d 100644 --- a/layout/base/tests/bug602141-1.html +++ b/layout/base/tests/bug602141-1.html @@ -15,7 +15,7 @@ sel.addRange(range); x.focus(); - sendKey('RIGHT'); // Try to move the caret one position to the right + sendKey('RIGHT', window); // Try to move the caret one position to the right diff --git a/layout/base/tests/bug602141-2.html b/layout/base/tests/bug602141-2.html index 260863b7cc80..2efc8867276c 100644 --- a/layout/base/tests/bug602141-2.html +++ b/layout/base/tests/bug602141-2.html @@ -17,7 +17,7 @@ sel.addRange(range); x.focus(); - sendKey('RIGHT'); // Try to move the caret one position to the right + sendKey('RIGHT', window); // Try to move the caret one position to the right diff --git a/layout/base/tests/bug602141-3.html b/layout/base/tests/bug602141-3.html index 5ba542677f9d..f1e5761ddb85 100644 --- a/layout/base/tests/bug602141-3.html +++ b/layout/base/tests/bug602141-3.html @@ -15,7 +15,7 @@ noteditablenavigable|unnavigable
diff --git a/layout/base/tests/bug602141-4.html b/layout/base/tests/bug602141-4.html index 6ff5c480f9ba..68a0b08f0aa8 100644 --- a/layout/base/tests/bug602141-4.html +++ b/layout/base/tests/bug602141-4.html @@ -15,7 +15,7 @@ sel.addRange(range); x.focus(); - sendKey('RIGHT'); // Try to move the caret one position to the right + sendKey('RIGHT', window); // Try to move the caret one position to the right diff --git a/layout/base/tests/bug612271-1.html b/layout/base/tests/bug612271-1.html index 7b79bef2d707..3204bc7fee53 100644 --- a/layout/base/tests/bug612271-1.html +++ b/layout/base/tests/bug612271-1.html @@ -8,7 +8,7 @@ var t = document.querySelector("textarea"); t.focus(); t.selectionStart = t.selectionEnd = t.value.length; - sendKey('ENTER'); + sendKey('ENTER', "target"); document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd)); diff --git a/layout/base/tests/bug612271-2.html b/layout/base/tests/bug612271-2.html index d3801384b686..3acb1ec1e165 100644 --- a/layout/base/tests/bug612271-2.html +++ b/layout/base/tests/bug612271-2.html @@ -8,7 +8,7 @@ var t = document.querySelector("textarea"); t.focus(); t.selectionStart = t.selectionEnd = t.value.length; - sendKey('ENTER'); + sendKey('ENTER', "target"); document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd)); diff --git a/layout/base/tests/bug612271-3.html b/layout/base/tests/bug612271-3.html index 1bfe5ce0e8d0..626701ef3d66 100644 --- a/layout/base/tests/bug612271-3.html +++ b/layout/base/tests/bug612271-3.html @@ -8,7 +8,7 @@ var t = document.querySelector("textarea"); t.focus(); t.selectionStart = t.selectionEnd = t.value.length; - sendKey('ENTER'); + sendKey('ENTER', "target"); document.body.appendChild(document.createTextNode(t.selectionStart + " - " + t.selectionEnd)); diff --git a/layout/base/tests/bug613433-1.html b/layout/base/tests/bug613433-1.html index 37e83a78b258..9d9ce57aa778 100644 --- a/layout/base/tests/bug613433-1.html +++ b/layout/base/tests/bug613433-1.html @@ -12,8 +12,8 @@ function test() { document.querySelector("div").focus(); // type a character, then press backspace to delete it - sendChar("X"); - sendKey("BACK_SPACE"); + sendKey("X", "div1"); + sendKey("BACK_SPACE", "div1"); document.documentElement.removeAttribute("class"); } diff --git a/layout/base/tests/bug613433-2.html b/layout/base/tests/bug613433-2.html index 9eb093ff445e..ae64e4afd77e 100644 --- a/layout/base/tests/bug613433-2.html +++ b/layout/base/tests/bug613433-2.html @@ -12,8 +12,8 @@ function test() { document.querySelector("div").focus(); // type a character, then press backspace to delete it - sendChar("X"); - sendKey("BACK_SPACE"); + sendKey("X", "div1"); + sendKey("BACK_SPACE", "div1"); document.documentElement.removeAttribute("class"); } diff --git a/layout/base/tests/bug613433-3.html b/layout/base/tests/bug613433-3.html index e7d1bc5609e8..dcc9802aebbb 100644 --- a/layout/base/tests/bug613433-3.html +++ b/layout/base/tests/bug613433-3.html @@ -12,8 +12,8 @@ function test() { document.querySelector("div").focus(); // type a character, then press backspace to delete it - sendChar("X"); - sendKey("BACK_SPACE"); + sendKey("X", "div1"); + sendKey("BACK_SPACE", "div1"); document.documentElement.removeAttribute("class"); } diff --git a/layout/forms/test/bug477700_subframe.html b/layout/forms/test/bug477700_subframe.html index 96f9c62ae78c..6d2c23641dd8 100644 --- a/layout/forms/test/bug477700_subframe.html +++ b/layout/forms/test/bug477700_subframe.html @@ -14,7 +14,6 @@ window.addEventListener("message", function(evt) { doIs(evt.data, "start", "Unexpected message"); - $("target").focus(); sendString("Test"); var t = $("target"); doIs(t.value, "Test", "Typing should work"); diff --git a/layout/forms/test/test_bug345267.html b/layout/forms/test/test_bug345267.html index 3f01b525db74..72e9b16453b7 100644 --- a/layout/forms/test/test_bug345267.html +++ b/layout/forms/test/test_bug345267.html @@ -83,7 +83,7 @@ is($("target").value, "abc", "Typing should be limited by maxlength"); $("target").value = ""; sendString("ad"); sendKey("left"); -sendString("bc"); +sendString("bc") is($("target").value, "abd", "Typing should be limited by maxlength again"); diff --git a/layout/forms/test/test_bug365410.html b/layout/forms/test/test_bug365410.html index 19c5fb68a2af..c27c5ffbe164 100644 --- a/layout/forms/test/test_bug365410.html +++ b/layout/forms/test/test_bug365410.html @@ -78,10 +78,10 @@ function pageUpDownTest(id,index) { var elm = document.getElementById(id); elm.focus(); elm.selectedIndex = 0; - sendKey("page_down"); - sendKey("page_down"); - sendKey("page_up"); - sendKey("page_down"); + sendKey("page_down", elm); + sendKey("page_down", elm); + sendKey("page_up", elm); + sendKey("page_down", elm); is(elm.selectedIndex, index, "pageUpDownTest: selectedIndex for " + id + " is " + index); } @@ -89,10 +89,10 @@ function upDownTest(id,index) { var elm = document.getElementById(id); elm.focus(); elm.selectedIndex = 0; - sendKey("down"); - sendKey("down"); - sendKey("up"); - sendKey("down"); + sendKey("down", elm); + sendKey("down", elm); + sendKey("up", elm); + sendKey("down", elm); is(elm.selectedIndex, index, "upDownTest: selectedIndex for " + id + " is " + index); } diff --git a/layout/forms/test/test_bug446663.html b/layout/forms/test/test_bug446663.html index f27b6830c602..dde0d4b67516 100644 --- a/layout/forms/test/test_bug446663.html +++ b/layout/forms/test/test_bug446663.html @@ -48,11 +48,11 @@ var elm = document.getElementById(id); elm.focus(); var x = document.body.offsetHeight; $(id).addEventListener("input", inputListener, false); -sendChar('1'); +sendChar('1',elm); is(inputHappened, true, "How come no input?"); -sendChar('3'); -sendKey('LEFT') -sendChar('2'); +sendChar('3',elm); +sendKey('LEFT',elm) +sendChar('2',elm); elm.blur(); x = document.body.offsetHeight; is(elm.value, '123', id + " edit"); @@ -61,14 +61,14 @@ test_edit_cmds(id) id = 'bug446663_b' elm = document.getElementById(id); elm.focus(); -sendChar('1'); +sendChar('1',elm); elm.style.display = 'none' var x = document.body.offsetHeight; elm.style.display = 'inline' x = document.body.offsetHeight; -sendChar('3'); -sendKey('LEFT') -sendChar('2'); +sendChar('3',elm); +sendKey('LEFT',elm) +sendChar('2',elm); elm.blur(); x = document.body.offsetHeight; is(elm.value, '123', id + " edit"); diff --git a/layout/forms/test/test_bug542914.html b/layout/forms/test/test_bug542914.html index 91ceee7ce09e..7b1e357001a7 100644 --- a/layout/forms/test/test_bug542914.html +++ b/layout/forms/test/test_bug542914.html @@ -59,14 +59,13 @@ function runTests(callback, type) { // Make sure that the control accepts input events without explicit initialization is(c.value, "", "Control is empty initially"); - c.focus(); - sendChar("a"); + sendChar("a", c); is(c.value, "a", "Control accepts input without explicit initialization"); // Make sure that the control retains its caret position c.focus(); c.blur(); c.focus(); - sendChar("b"); + sendChar("b", c); is(c.value, "ab", "Control retains caret position after being re-focused"); var d = document.createElement("input"); @@ -77,9 +76,8 @@ function runTests(callback, type) { // Make sure dynamically injected inputs work as expected is(d.value, "", "Dynamic control's initial value should be empty"); d.value = "new"; - d.focus(); is(d.value, "new", "Dynamic control's value can be set before initialization"); - sendChar("x"); + sendChar("x", d); is(d.value, "xnew", "Dynamic control accepts keyboard input without explicit initialization"); $("display").removeChild(d); is(d.value, "xnew", "Dynamic control retains value after being removed from the document"); diff --git a/layout/forms/test/test_bug563642.html b/layout/forms/test/test_bug563642.html index 916435c4ff56..0cf12b6ec6da 100644 --- a/layout/forms/test/test_bug563642.html +++ b/layout/forms/test/test_bug563642.html @@ -41,11 +41,11 @@ function pageUpDownTest(id,index) { var elm = document.getElementById(id); elm.focus(); elm.selectedIndex = 0; - sendKey("page_down"); - sendKey("page_down"); - sendKey("page_down"); - sendKey("page_up"); - sendKey("page_down"); + sendKey("page_down", elm); + sendKey("page_down", elm); + sendKey("page_down", elm); + sendKey("page_up", elm); + sendKey("page_down", elm); is(elm.selectedIndex, index, "pageUpDownTest: selectedIndex for " + id + " is " + index); } @@ -53,11 +53,11 @@ function upDownTest(id,index) { var elm = document.getElementById(id); elm.focus(); elm.selectedIndex = 0; - sendKey("down"); - sendKey("down"); - sendKey("down"); - sendKey("up"); - sendKey("down"); + sendKey("down", elm); + sendKey("down", elm); + sendKey("down", elm); + sendKey("up", elm); + sendKey("down", elm); is(elm.selectedIndex, index, "upDownTest: selectedIndex for " + id + " is " + index); } diff --git a/layout/generic/test/test_bug633762.html b/layout/generic/test/test_bug633762.html index f31b52138494..8059c277ec57 100644 --- a/layout/generic/test/test_bug633762.html +++ b/layout/generic/test/test_bug633762.html @@ -34,7 +34,7 @@ function runTests() { // record scrolltop scrollTopBefore = doc.body.scrollTop; // send up arrow key event - sendKey("UP"); + sendKey("UP", doc.body); setTimeout("finish();", 0); } diff --git a/mobile/xul/chrome/tests/browser_escape.js b/mobile/xul/chrome/tests/browser_escape.js index a08272725c94..5b17f0340f5e 100644 --- a/mobile/xul/chrome/tests/browser_escape.js +++ b/mobile/xul/chrome/tests/browser_escape.js @@ -98,7 +98,7 @@ function testReturnToOwner() { tab1 = Browser.addTab("about:blank", true); tab2 = Browser.addTab("about:blank", true, tab1); is(Browser.selectedTab, tab2, "tab2 is selected"); - EventUtils.sendKey("ESCAPE"); + EventUtils.sendKey("ESCAPE", window); is(Browser.selectedTab, tab1, "tab1 is selected"); closeTabs(); testContextMenu(); diff --git a/mobile/xul/chrome/tests/browser_select.js b/mobile/xul/chrome/tests/browser_select.js index ccf0fd29959b..f9aca619ccc4 100644 --- a/mobile/xul/chrome/tests/browser_select.js +++ b/mobile/xul/chrome/tests/browser_select.js @@ -47,7 +47,7 @@ function closeSelect() { let selectui = document.getElementById("select-container"); is(selectui.hidden, false, "Select UI should be open"); - EventUtils.sendKey("ESCAPE"); + EventUtils.sendKey("ESCAPE", window); waitFor(tapOnMultiSelect, function() { return document.getElementById("select-container").hidden == true; }); } @@ -70,7 +70,7 @@ function onUIReady() { is(selectui.hidden, false, "Select UI should be open"); is(SelectHelperUI._selectedIndexes, 7, "Select UI should have the 8th option selected:" + SelectHelperUI._selectedIndexes); - EventUtils.sendKey("ESCAPE"); + EventUtils.sendKey("ESCAPE", window); // Close our tab when finished Browser.closeTab(new_tab); diff --git a/testing/mochitest/tests/SimpleTest/EventUtils.js b/testing/mochitest/tests/SimpleTest/EventUtils.js index 099cb8e1a451..d2ea6d4bdc4f 100644 --- a/testing/mochitest/tests/SimpleTest/EventUtils.js +++ b/testing/mochitest/tests/SimpleTest/EventUtils.js @@ -73,39 +73,105 @@ function sendMouseEvent(aEvent, aTarget, aWindow) { } /** - * Send the char aChar to the focused element. This method handles casing of - * chars (sends the right charcode, and sends a shift key for uppercase chars). - * No other modifiers are handled at this point. + * Send the char aChar to the node with id aTarget. If aTarget is not + * provided, use "target". This method handles casing of chars (sends the + * right charcode, and sends a shift key for uppercase chars). No other + * modifiers are handled at this point. * * For now this method only works for English letters (lower and upper case) * and the digits 0-9. + * + * Returns true if the keypress event was accepted (no calls to preventDefault + * or anything like that), false otherwise. */ -function sendChar(aChar, aWindow) { +function sendChar(aChar, aTarget) { // DOM event charcodes match ASCII (JS charcodes) for a-zA-Z0-9. var hasShift = (aChar == aChar.toUpperCase()); - synthesizeKey(aChar, { shiftKey: hasShift }, aWindow); + var charCode = aChar.charCodeAt(0); + var keyCode = charCode; + if (!hasShift) { + // For lowercase letters, the keyCode is actually 32 less than the charCode + keyCode -= 0x20; + } + + return __doEventDispatch(aTarget, charCode, keyCode, hasShift); } /** - * Send the string aStr to the focused element. + * Send the string aStr to the node with id aTarget. If aTarget is not + * provided, use "target". * * For now this method only works for English letters (lower and upper case) * and the digits 0-9. */ -function sendString(aStr, aWindow) { +function sendString(aStr, aTarget) { for (var i = 0; i < aStr.length; ++i) { - sendChar(aStr.charAt(i), aWindow); + sendChar(aStr.charAt(i), aTarget); } } /** - * Send the non-character key aKey to the focused node. The name of the key - * should be a lowercase version of the part that comes after "DOM_VK_" in the - * KeyEvent constant name for this key. No modifiers are handled at this point. + * Send the non-character key aKey to the node with id aTarget. If aTarget is + * not provided, use "target". The name of the key should be a lowercase + * version of the part that comes after "DOM_VK_" in the KeyEvent constant + * name for this key. No modifiers are handled at this point. + * + * Returns true if the keypress event was accepted (no calls to preventDefault + * or anything like that), false otherwise. */ -function sendKey(aKey, aWindow) { - keyName = "VK_" + aKey.toUpperCase(); - synthesizeKey(keyName, { shiftKey: false }, aWindow); +function sendKey(aKey, aTarget) { + keyName = "DOM_VK_" + aKey.toUpperCase(); + + if (!KeyEvent[keyName]) { + throw "Unknown key: " + keyName; + } + + return __doEventDispatch(aTarget, 0, KeyEvent[keyName], false); +} + +/** + * Actually perform event dispatch given a charCode, keyCode, and boolean for + * whether "shift" was pressed. Send the event to the node with id aTarget. If + * aTarget is not provided, use "target". + * + * Returns true if the keypress event was accepted (no calls to preventDefault + * or anything like that), false otherwise. + */ +function __doEventDispatch(aTarget, aCharCode, aKeyCode, aHasShift) { + if (aTarget === undefined) { + aTarget = "target"; + } + + var event = document.createEvent("KeyEvents"); + event.initKeyEvent("keydown", true, true, document.defaultView, + false, false, aHasShift, false, + aKeyCode, 0); + var accepted = SpecialPowers.dispatchEvent(window, aTarget, event); + + // Preventing the default keydown action also prevents the default + // keypress action. + event = document.createEvent("KeyEvents"); + if (aCharCode) { + event.initKeyEvent("keypress", true, true, document.defaultView, + false, false, aHasShift, false, + 0, aCharCode); + } else { + event.initKeyEvent("keypress", true, true, document.defaultView, + false, false, aHasShift, false, + aKeyCode, 0); + } + if (!accepted) { + event.preventDefault(); + } + accepted = SpecialPowers.dispatchEvent(window, aTarget, event); + + // Always send keyup + var event = document.createEvent("KeyEvents"); + event.initKeyEvent("keyup", true, true, document.defaultView, + false, false, aHasShift, false, + aKeyCode, 0); + SpecialPowers.dispatchEvent(window, aTarget, event); + return accepted; } /** @@ -327,12 +393,9 @@ function synthesizeKey(aKey, aEvent, aWindow) var utils = _getDOMWindowUtils(aWindow); if (utils) { var keyCode = 0, charCode = 0; - if (aKey.indexOf("VK_") == 0) { + if (aKey.indexOf("VK_") == 0) keyCode = KeyEvent["DOM_" + aKey]; - if (!keyCode) { - throw "Unknown key: " + aKey; - } - } else { + else { charCode = aKey.charCodeAt(0); keyCode = _computeKeyCodeFromChar(aKey.charAt(0)); } @@ -347,7 +410,6 @@ function synthesizeKey(aKey, aEvent, aWindow) } else { var keyDownDefaultHappened = utils.sendKeyEvent("keydown", keyCode, 0, modifiers); - // XXX Shouldn't dispatch keypress event if the key is a modifier key. utils.sendKeyEvent("keypress", charCode ? 0 : keyCode, charCode, modifiers, !keyDownDefaultHappened); utils.sendKeyEvent("keyup", keyCode, 0, modifiers); diff --git a/testing/mochitest/tests/test_sanity.html b/testing/mochitest/tests/test_sanity.html index 6b4bcc759e57..7c949f3d9fd2 100644 --- a/testing/mochitest/tests/test_sanity.html +++ b/testing/mochitest/tests/test_sanity.html @@ -44,13 +44,13 @@ is(press2, true, "synthesizeKey should dispatch keyPress with default prevented" var press3 = false; $("testKeyEvent3").focus(); -sendChar("x") +sendChar("x", "testKeyEvent3") is($("testKeyEvent3").value, "x", "sendChar should work"); is(press3, true, "sendChar should dispatch keyPress"); var press4 = false; $("testKeyEvent4").focus(); -sendChar("x") +sendChar("x", "testKeyEvent4") is($("testKeyEvent4").value, "", "sendChar should respect keydown preventDefault"); is(press4, true, "sendChar should dispatch keyPress with default prevented"); diff --git a/testing/mochitest/tests/test_sanityEventUtils.html b/testing/mochitest/tests/test_sanityEventUtils.html index 47dacfb1f4ef..850e0d6113d8 100644 --- a/testing/mochitest/tests/test_sanityEventUtils.html +++ b/testing/mochitest/tests/test_sanityEventUtils.html @@ -46,19 +46,17 @@ function starttest() { check = false; $("testKeyEvent").addEventListener("keypress", function() { check = true; }, false); $("testKeyEvent").focus(); - sendChar("x"); + sendChar("x", "testKeyEvent"); is($("testKeyEvent").value, "x", "sendChar should work"); is(check, true, "sendChar should dispatch keyPress"); $("testKeyEvent").value = ""; - $("testStrEvent").focus(); - sendString("string"); + sendString("string", "testStrEvent"); is($("testStrEvent").value, "string", "sendString should work"); $("testStrEvent").value = ""; check = false; - $("testKeyEvent").focus(); - sendKey("DOWN"); + sendKey("DOWN", "testKeyEvent"); is(check, true, "sendKey should dispatch keyPress"); /* test synthesizeMouse* */ diff --git a/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html b/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html index 8f2e62ebc77a..f8a68d07b603 100644 --- a/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html +++ b/toolkit/components/passwordmgr/test/test_basic_form_autocomplete.html @@ -643,7 +643,7 @@ function runTest(testNum) { // the username. uname.focus(); doKey("right"); - sendChar("X"); + sendChar("X", uname); // Trigger the 'blur' event on uname pword.focus(); checkACForm("sXingleuser5", "singlepass5"); @@ -722,15 +722,14 @@ function runTest(testNum) { pwmgr.removeLogin(login7); testNum = 699; - gNextTestWillOpenPopup = true; + gNextTestWillOpenPopup = false; break; case 700: // Turn our attention to form9 to test the dropdown - bug 497541 uname = $_(9, "uname"); pword = $_(9, "pword"); - uname.focus(); - sendString("form9userAB"); + sendString("form9userAB", uname); gNextTestWillOpenPopup = true; break; @@ -738,7 +737,7 @@ function runTest(testNum) { checkACForm("form9userAB", ""); uname.focus(); doKey("left"); - sendChar("A"); + sendChar("A", uname); gNextTestWillOpenPopup = false; break; @@ -754,8 +753,7 @@ function runTest(testNum) { case 703: pwmgr.addLogin(login8C); - uname.focus(); - sendChar("z"); + sendChar("z", uname); gNextTestWillOpenPopup = false; break; diff --git a/toolkit/components/satchel/test/test_form_autocomplete.html b/toolkit/components/satchel/test/test_form_autocomplete.html index ef027ad7465e..872591b932ae 100644 --- a/toolkit/components/satchel/test/test_form_autocomplete.html +++ b/toolkit/components/satchel/test/test_form_autocomplete.html @@ -477,22 +477,19 @@ function runTest(testNum) { input = $_(5, "field3"); restoreForm(); testNum = 199; - input.focus(); - sendChar("a"); + sendChar("a", input); break; /* Test filtering as characters are typed. */ case 200: checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"]); - input.focus(); - sendChar("a"); + sendChar("a", input); break; case 201: checkMenuEntries(["aa", "aaz", "aa\xe6"]); - input.focus(); - sendChar("\xc6"); + sendChar("\xc6", input); break; case 202: @@ -507,31 +504,27 @@ function runTest(testNum) { case 204: checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"]); - input.focus(); - sendChar("z"); + sendChar("z", input); break; case 205: ok(getMenuEntries().length > 0, "checking typing in middle of text"); - input.focus(); doKey("left"); - sendChar("a"); + sendChar("a", input); break; case 206: checkMenuEntries(["aaz"]); fh.addEntry("field3", "aazq"); - input.focus(); doKey("right"); - sendChar("q"); + sendChar("q", input); break; case 207: // check that results were cached checkMenuEntries([]); fh.addEntry("field3", "aazqq"); - input.focus(); - sendChar("q"); + sendChar("q", input); break; case 208: @@ -543,8 +536,7 @@ function runTest(testNum) { input = $_(6, "field4"); restoreForm(); testNum = 249; - input.focus(); - sendChar("a"); + sendChar("a", input); break; /* Test substring matches and word boundary bonuses */ @@ -552,8 +544,7 @@ function runTest(testNum) { case 250: // alphabetical results for first character checkMenuEntries(["aa a\xe6", "aba\xe6", "a\xe6"]); - input.focus(); - sendChar("\xc6"); + sendChar("\xc6", input); break; case 251: @@ -562,36 +553,31 @@ function runTest(testNum) { checkMenuEntries(["a\xe6", "aa a\xe6", "aba\xe6"]); restoreForm(); - input.focus(); - sendChar("b"); + sendChar("b", input); break; case 252: checkMenuEntries(["bc d\xe6"]); - input.focus(); - sendChar(" "); + sendChar(" ", input); break; case 253: // check that trailing space has no effect after single char. checkMenuEntries(["bc d\xe6"]); - input.focus(); - sendChar("\xc6"); + sendChar("\xc6", input); break; case 254: // check multi-word substring matches checkMenuEntries(["bc d\xe6", "aba\xe6"]); - input.focus(); doKey("left"); - sendChar("d"); + sendChar("d", input); break; case 255: // check inserting in multi-word searches checkMenuEntries(["bc d\xe6"]); - input.focus(); - sendChar("z"); + sendChar("z", input); break; case 256: @@ -644,8 +630,7 @@ function runTest(testNum) { input.maxLength = 4; // now again with a character typed - input.focus(); - sendChar("1"); + sendChar("1", input); doKey("escape"); doKey("down"); break; diff --git a/toolkit/content/tests/chrome/test_hiddenitems.xul b/toolkit/content/tests/chrome/test_hiddenitems.xul index 7e44852df931..b03780003f07 100644 --- a/toolkit/content/tests/chrome/test_hiddenitems.xul +++ b/toolkit/content/tests/chrome/test_hiddenitems.xul @@ -44,20 +44,19 @@ SimpleTest.waitForExplicitFinish(); function testListbox(id) { var listbox = document.getElementById(id); - listbox.focus(); is(listbox.getRowCount(), 7, id + ": Returned the wrong number of rows"); is(listbox.getItemAtIndex(2).id, id + "_item3", id + ": Should still return hidden items"); listbox.selectedIndex = 0; is(listbox.selectedItem.id, id + "_item1", id + ": First item was not selected"); - sendKey("DOWN"); + sendKey("DOWN", id); is(listbox.selectedItem.id, id + "_item2", id + ": Down didn't move to second item"); - sendKey("DOWN"); + sendKey("DOWN", id); is(listbox.selectedItem.id, id + "_item4", id + ": Down didn't skip hidden item"); - sendKey("DOWN"); + sendKey("DOWN", id); is(listbox.selectedItem.id, id + "_item6", id + ": Down didn't skip collapsed item"); - sendKey("UP"); + sendKey("UP", id); is(listbox.selectedItem.id, id + "_item4", id + ": Up didn't skip collapsed item"); - sendKey("UP"); + sendKey("UP", id); is(listbox.selectedItem.id, id + "_item2", id + ": Up didn't skip hidden item"); listbox.selectAll(); is(listbox.selectedItems.length, 7, id + ": Should have still selected all items"); @@ -66,7 +65,7 @@ function testListbox(id) listbox.selectedIndex = 2; ok(listbox.selectedItem == listbox.getItemAtIndex(2), id + ": Should have selected the hidden item"); listbox.selectedIndex = 0; - sendKey("END"); + sendKey("END", id); is(listbox.selectedItem.id, id + "_item6", id + ": Should have moved to the last unhidden item"); sendMouseEvent({type: 'click'}, id + "_item1"); ok(listbox.selectedItem == listbox.getItemAtIndex(0), id + ": Should have selected the first item"); @@ -74,9 +73,9 @@ function testListbox(id) sendMouseEvent({type: 'click', shiftKey: true}, id + "_item6"); is(listbox.selectedItems.length, 4, id + ": Should have selected all visible items"); listbox.selectedIndex = 0; - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item6", id + ": Page down should go to the last visible item"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item1", id + ": Page up should go to the first visible item"); } diff --git a/toolkit/content/tests/chrome/test_hiddenpaging.xul b/toolkit/content/tests/chrome/test_hiddenpaging.xul index 912494b46495..bd56385a51f5 100644 --- a/toolkit/content/tests/chrome/test_hiddenpaging.xul +++ b/toolkit/content/tests/chrome/test_hiddenpaging.xul @@ -71,24 +71,23 @@ function testRichlistbox() { var id = "richlistbox"; var listbox = document.getElementById(id); - listbox.focus(); listbox.selectedIndex = 0; - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item7", id + ": Page down should go to the item one visible page away"); is(listbox.getIndexOfFirstVisibleRow(), 6, id + ": Page down should have scrolled down a visible page"); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item11", id + ": Second page down should go to the item two visible pages away"); is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end"); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item"); is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item10", id + ": Page up should go to the item one visible page away"); is(listbox.getIndexOfFirstVisibleRow(), 5, id + ": Page up should scroll up a visible page"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item6", id + ": Second page up should go to the item two visible pages away"); is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item"); is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all"); } @@ -106,25 +105,24 @@ function testListbox() var rowHeight = listbox.firstChild.getBoundingClientRect().height; - listbox.focus(); listbox.selectedIndex = 0; - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item8", id + ": Page down should go to the item one visible page away"); is(listbox.getIndexOfFirstVisibleRow(), 7, id + ": Page down should have scrolled down a visible page"); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item13", id + ": Second page down should go to the item two visible pages away"); is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Second page down should not scroll beyond the end"); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", id); is(listbox.selectedItem.id, id + "_item14", id + ": Third page down should go to the last visible item"); is(listbox.getIndexOfFirstVisibleRow(), 9, id + ": Third page down should not have scrolled at all"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item9", id + ": Page up should go to the item one visible page away"); // the listScrollbox seems to go haywire when scrolling up with hidden listitems todo_is(listbox.getIndexOfFirstVisibleRow(), 3, id + ": Page up should scroll up a visible page"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item2", id + ": Second page up should go to the item two visible pages away"); is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Second page up should not scroll beyond the start"); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", id); is(listbox.selectedItem.id, id + "_item1", id + ": Third page up should return to the first visible item"); is(listbox.getIndexOfFirstVisibleRow(), 0, id + ": Third page up should not have scrolled at all"); diff --git a/toolkit/content/tests/chrome/test_richlist_direction.xul b/toolkit/content/tests/chrome/test_richlist_direction.xul index 05e31fa61a8d..3d03a9da922a 100644 --- a/toolkit/content/tests/chrome/test_richlist_direction.xul +++ b/toolkit/content/tests/chrome/test_richlist_direction.xul @@ -46,25 +46,24 @@ function test_richlistbox() // richlistboxes respond differently when a user initiates a selection richListBox.dir = "reverse"; var count = richListBox.itemCount; - richListBox.focus(); richListBox.selectedIndex = count - 1; - sendKey("DOWN"); + sendKey("DOWN", richListBox); is(richListBox.currentIndex, count - 2, "Selection should move to the next item"); - sendKey("UP"); + sendKey("UP", richListBox); is(richListBox.currentIndex, count - 1, "Selection should move to the previous item"); - sendKey("END"); + sendKey("END", richListBox); is(richListBox.currentIndex, 0, "Selection should move to the last item"); - sendKey("HOME"); + sendKey("HOME", richListBox); is(richListBox.currentIndex, count - 1, "Selection should move to the first item"); var currentIndex = richListBox.currentIndex; var index = getScrollIndexAmount(-1); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", richListBox); is(richListBox.currentIndex, index, "Selection should move to one page down"); ok(richListBox.currentIndex < currentIndex, "Selection should move downwards"); - sendKey("END"); + sendKey("END", richListBox); currentIndex = richListBox.currentIndex; index = getScrollIndexAmount(1); - sendKey("PAGE_UP"); + sendKey("PAGE_UP", richListBox); is(richListBox.currentIndex, index, "Selection should move to one page up"); ok(richListBox.currentIndex > currentIndex, "Selection should move upwards"); richListBox.selectedItem = richListBox.lastChild; @@ -88,29 +87,29 @@ function test_richlistbox() aEvent.preventDefault(); }, true); richListBox.selectedIndex = 1; - sendKey("HOME"); + sendKey("HOME", richListBox); is(richListBox.selectedIndex, 1, "A stopped event should return indexing to normal"); // direction = "normal" richListBox.dir = "normal"; richListBox.selectedIndex = 0; - sendKey("DOWN"); + sendKey("DOWN", richListBox); is(richListBox.currentIndex, 1, "Selection should move to the next item"); - sendKey("UP"); + sendKey("UP", richListBox); is(richListBox.currentIndex, 0, "Selection should move to the previous item"); - sendKey("END"); + sendKey("END", richListBox); is(richListBox.currentIndex, count - 1, "Selection should move to the last item"); - sendKey("HOME"); + sendKey("HOME", richListBox); is(richListBox.currentIndex, 0, "Selection should move to the first item"); var currentIndex = richListBox.currentIndex; var index = richListBox.scrollOnePage(1); - sendKey("PAGE_DOWN"); + sendKey("PAGE_DOWN", richListBox); is(richListBox.currentIndex, index, "Selection should move to one page down"); ok(richListBox.currentIndex > currentIndex, "Selection should move downwards"); - sendKey("END"); + sendKey("END", richListBox); currentIndex = richListBox.currentIndex; index = richListBox.scrollOnePage(-1) + richListBox.currentIndex; - sendKey("PAGE_UP"); + sendKey("PAGE_UP", richListBox); is(richListBox.currentIndex, index, "Selection should move to one page up"); ok(richListBox.currentIndex < currentIndex, "Selection should move upwards"); richListBox.selectedItem = richListBox.firstChild;