diff options
Diffstat (limited to 'layout/forms/test')
53 files changed, 4032 insertions, 0 deletions
diff --git a/layout/forms/test/bug287446_subframe.html b/layout/forms/test/bug287446_subframe.html new file mode 100644 index 000000000..626430268 --- /dev/null +++ b/layout/forms/test/bug287446_subframe.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> + <head> + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> + <script> + function doIs(arg1, arg2, arg3) { + window.parent.postMessage("t " + encodeURIComponent(arg1) + " " + + encodeURIComponent(arg2) + " " + + encodeURIComponent(arg3), "*"); + } + + function $(arg) { return document.getElementById(arg); } + + window.addEventListener("message", + function(evt) { + var t = $("target"); + if (evt.data == "start") { + doIs(t.value, "Test", "Shouldn't have lost our initial value"); + t.focus(); + sendString("Foo"); + doIs(t.value, "FooTest", "Typing should work"); + window.parent.postMessage("c", "*"); + } else { + doIs(evt.data, "continue", "Unexpected message"); + doIs(t.value, "FooTest", "Shouldn't have lost our typed value"); + sendString("Bar"); + doIs(t.value, "FooBarTest", "Typing should still work"); + window.parent.postMessage("f", "*"); + } + }, + "false"); + + </script> + </head> + <body> + <input id="target" value="Test"> + </body> +</html> diff --git a/layout/forms/test/bug477700_subframe.html b/layout/forms/test/bug477700_subframe.html new file mode 100644 index 000000000..067ce68c7 --- /dev/null +++ b/layout/forms/test/bug477700_subframe.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<html> + <head> + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> + <script> + function doIs(arg1, arg2, arg3) { + window.parent.postMessage("t " + encodeURIComponent(arg1) + " " + + encodeURIComponent(arg2) + " " + + encodeURIComponent(arg3), "*"); + } + + function $(arg) { return document.getElementById(arg); } + + 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"); + (function() { + SpecialPowers.wrap(t).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement).editor.undo(1); + })() + doIs(t.value, "", "Undo should work"); + (function() { + SpecialPowers.wrap(t).QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement).editor.redo(1); + })() + doIs(t.value, "Test", "Redo should work"); + window.parent.postMessage("f", "*"); + }, + "false"); + + </script> + </head> + <body> + <input id="target"> + </body> +</html> + diff --git a/layout/forms/test/bug536567_iframe.html b/layout/forms/test/bug536567_iframe.html new file mode 100644 index 000000000..b2b2ca60a --- /dev/null +++ b/layout/forms/test/bug536567_iframe.html @@ -0,0 +1,9 @@ +<!DOCTYPE HTML>
+<html>
+ <head>
+ </head>
+ <body>
+ <iframe id="content"></iframe>
+ </body>
+</html>
+
diff --git a/layout/forms/test/bug536567_subframe.html b/layout/forms/test/bug536567_subframe.html new file mode 100644 index 000000000..c1271becf --- /dev/null +++ b/layout/forms/test/bug536567_subframe.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<body> +<input id="target" type="file" /> +<script type="text/javascript"> + +window.onload = function() { + var fileInput = document.getElementById("target"); + fileInput.click(); +}; + +</script> +</body> +</html> diff --git a/layout/forms/test/bug564115_window.html b/layout/forms/test/bug564115_window.html new file mode 100644 index 000000000..b55cc0400 --- /dev/null +++ b/layout/forms/test/bug564115_window.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Window for Bug 564115</title> +</head> +<body> +<input type="text"> +<div style="height: 10000px;"></div> +</body> +</html> diff --git a/layout/forms/test/bug665540_window.xul b/layout/forms/test/bug665540_window.xul new file mode 100644 index 000000000..f0225ef93 --- /dev/null +++ b/layout/forms/test/bug665540_window.xul @@ -0,0 +1,18 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window title="Test Select Dropdown Positioning in Fullscreen Window" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + sizemode="fullscreen"> + + <script> + opener.SimpleTest.waitForFocus(opener.childFocused, window); + </script> + + <body xmlns="http://www.w3.org/1999/xhtml"> + <select id="select" style="-moz-appearance:none"> + <option id="optiona">a</option> + <option>b</option> + </select> + </body> +</window> diff --git a/layout/forms/test/chrome.ini b/layout/forms/test/chrome.ini new file mode 100644 index 000000000..32d862eec --- /dev/null +++ b/layout/forms/test/chrome.ini @@ -0,0 +1,11 @@ +[DEFAULT] +skip-if = os == 'android' +support-files = + bug536567_iframe.html + bug536567_subframe.html + bug665540_window.xul + +[test_bug536567_perwindowpb.html] +[test_bug665540.html] +tags = fullscreen +skip-if = (os == 'linux' && bits == 64) # Bug 888164 diff --git a/layout/forms/test/mochitest.ini b/layout/forms/test/mochitest.ini new file mode 100644 index 000000000..cc8519db7 --- /dev/null +++ b/layout/forms/test/mochitest.ini @@ -0,0 +1,66 @@ +[DEFAULT] +support-files = + bug287446_subframe.html + bug477700_subframe.html + bug564115_window.html + +[test_bug231389.html] +[test_bug287446.html] +[test_bug345267.html] +[test_bug346043.html] +[test_bug348236.html] +skip-if = toolkit == 'android' || e10s || os == 'mac' # mac(select form control popup behavior is different) +[test_bug353539.html] +[test_bug365410.html] +[test_bug378670.html] +skip-if = toolkit == 'android' #TIMED_OUT +[test_bug402198.html] +[test_bug411236.html] +[test_bug446663.html] +skip-if = toolkit == 'android' +[test_bug476308.html] +[test_bug477531.html] +[test_bug477700.html] +[test_bug478219.xhtml] +skip-if = toolkit == 'android' +[test_bug534785.html] +[test_bug542914.html] +[test_bug549170.html] +[test_bug562447.html] +[test_bug563642.html] +[test_bug564115.html] +skip-if = toolkit == 'android' #TIMED_OUT +[test_bug571352.html] +skip-if = (os == 'mac' && os_version == '10.10') || toolkit == 'android' #TIMED_OUT # OS X 10.10 - bug 947690 +[test_bug572406.html] +[test_bug572649.html] +skip-if = toolkit == 'android' #TIMED_OUT +[test_bug595310.html] +[test_bug620936.html] +[test_bug644542.html] +skip-if = toolkit == 'android' #TIMED_OUT +[test_bug672810.html] +skip-if = toolkit == 'android' +[test_bug704049.html] +[test_bug717878_input_scroll.html] +[test_bug869314.html] +[test_bug903715.html] +skip-if = toolkit == 'android' || e10s #select elements don't use an in-page popup on Android +[test_bug935876.html] +# Bug 1023472 - Fails when pushed into a different chunk on Android +skip-if = toolkit == 'android' +[test_bug957562.html] +[test_bug960277.html] +[test_bug961363.html] +skip-if = toolkit == 'android' # Bug 1021644 - Fails when pushed into a different chunk on Android +[test_bug1111995.html] +[test_bug1301290.html] +skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' # b2g(resizing textarea not available in b2g) b2g-debug(resizing textarea not available in b2g) b2g-desktop(resizing textarea not available in b2g) +[test_bug1305282.html] +[test_listcontrol_search.html] +skip-if = toolkit == 'android' #select elements don't use an in-page popup on Android +[test_select_prevent_default.html] +[test_select_vertical.html] +skip-if = e10s || toolkit == 'android' # Bug 1170129 - vertical <select> popup not implemented for e10s # <select> elements don't use an in-page popup on Android +[test_textarea_resize.html] +skip-if = toolkit == 'android' diff --git a/layout/forms/test/test_bug1111995.html b/layout/forms/test/test_bug1111995.html new file mode 100644 index 000000000..74ab76b06 --- /dev/null +++ b/layout/forms/test/test_bug1111995.html @@ -0,0 +1,60 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1111995 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1111995</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"/> + <script type="application/javascript"> + + /** Test for Bug 1111995 **/ + + function doTest() { + SimpleTest.waitForExplicitFinish(); + + var clicks = 0; + var elms = document.querySelectorAll('.click'); + for (var i = 0; i < elms.length; ++i) { + var e = elms[i]; + e.addEventListener('click', function(event) { + ++clicks; + }, false); + } + + for (var i = 0; i < elms.length; ++i) { + var e = elms[i]; + synthesizeMouse(e, 3, 3, {}); + } + is(clicks, 0, "click events outside border with radius"); + + clicks = 0; + synthesizeMouse($("t3"), 17, 17, {}); + synthesizeMouse($("t4"), 17, 17, {}); + is(clicks, 2, "click events on border with radius"); + + SimpleTest.finish(); + } + </script> +</head> +<body onload="SimpleTest.waitForFocus(doTest, window)"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1111995">Mozilla Bug 1111995</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +</pre> + +<input class="click" id="t1" type=button style="width:100px; height:100px; padding:20px; border-radius:50%" value="Round button"> +<button class="click" id="t2" style="width:100px; height:100px; padding:20px; border-radius:50%">Round button</button> +<input class="click" id="t3" type=button style="width:100px; height:100px; border-width:20px; border-radius:50%" value="Round button"> +<button class="click" id="t4" style="width:100px; height:100px; border-width:20px; border-radius:50%">Round button</button> +<input class="click" id="t5" type=button style="width:100px; height:100px; border-radius:50%;overflow:hidden" value="Round button"> +<button class="click" id="t6" style="width:100px; height:100px; border-radius:50%;overflow:hidden">Round button</button> + +</body> +</html> diff --git a/layout/forms/test/test_bug1301290.html b/layout/forms/test/test_bug1301290.html new file mode 100644 index 000000000..5f226c453 --- /dev/null +++ b/layout/forms/test/test_bug1301290.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<html> + <head> + <title>Test for Bug 1301290</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"/> + <style type="text/css"> + .blue, .green { + border: none; + box-sizing: border-box; + display: block; + width: 200px; + height: 100px; + overflow: scroll; + resize: both; + } + + .blue { + background: blue; + } + + .green { + background: green; + margin-top: -100px; + } + </style> + </head> + <body> + <div class="blue"></div> + <textarea class="green" id="textarea"></textarea> + <script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + addLoadEvent(() => SimpleTest.executeSoon(function() { + var textarea = $("textarea"); + var rect = textarea.getBoundingClientRect(); + + synthesizeMouse(textarea, rect.width - 10, rect.height - 10, { type: "mousedown" }); + synthesizeMouse(textarea, rect.width + 40, rect.height + 40, { type: "mousemove" }); + synthesizeMouse(textarea, rect.width + 40, rect.height + 40, { type: "mouseup" }); + + var newrect = textarea.getBoundingClientRect(); + ok(newrect.width > rect.width, "width did not increase"); + ok(newrect.height > rect.height, "height did not increase"); + SimpleTest.finish(); + })); + </script> + </body> +</html> diff --git a/layout/forms/test/test_bug1305282.html b/layout/forms/test/test_bug1305282.html new file mode 100644 index 000000000..b43901e6c --- /dev/null +++ b/layout/forms/test/test_bug1305282.html @@ -0,0 +1,59 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=615697 +--> +<head> + <title>Test for Bug 1305282</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=1305282">Mozilla Bug 1305282</a> +<p id="display"></p> +<div id="content"> + <select> + <option>f o o</option> + <option>b a r</option> + <option>b o o</option> + </select> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 1305282 **/ + +var select = document.getElementsByTagName('select')[0]; + +select.addEventListener("change", function(aEvent) { + select.removeEventListener("change", arguments.callee, false); + is(select.selectedIndex, 1, "'b a r' option is selected"); + SimpleTest.finish(); +}, false); + +select.addEventListener("focus", function() { + select.removeEventListener("focus", arguments.callee, false); + SimpleTest.executeSoon(function () { + synthesizeKey("VK_DOWN", {}); + SimpleTest.executeSoon(function () { + synthesizeKey('b', {}); + SimpleTest.executeSoon(function () { + synthesizeKey(' ', {}); + SimpleTest.executeSoon(function () { + synthesizeKey("VK_RETURN", {}); + }); + }); + }); + }); +}, false); + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(function() { + select.focus(); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug231389.html b/layout/forms/test/test_bug231389.html new file mode 100644 index 000000000..6a6cc9e50 --- /dev/null +++ b/layout/forms/test/test_bug231389.html @@ -0,0 +1,55 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=231389 +--> +<head> + <title>Test for Bug 231389</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=231389">Mozilla Bug 231389</a> +<p id="display"> + <textarea id="area" rows="5"> + Here + is + some + very + long + text + that + we're + using + for + testing + purposes + </textarea> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 231389 **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var area = document.getElementById("area"); + var val = area.value; + var pos = val.indexOf("purposes"); + + is(area.scrollTop, 0, "The textarea should not be scrolled initially"); + area.selectionStart = pos; + area.selectionEnd = pos; + setTimeout(function() { + isnot(area.scrollTop, 0, "The textarea's insertion point should be scrolled into view"); + + SimpleTest.finish(); + }, 0); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug287446.html b/layout/forms/test/test_bug287446.html new file mode 100644 index 000000000..e551ba998 --- /dev/null +++ b/layout/forms/test/test_bug287446.html @@ -0,0 +1,75 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=287446 +--> +<head> + <title>Test for Bug 287446</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=287446">Mozilla Bug 287446</a> +<p id="display"> + <iframe id="i" + src="http://example.com/tests/layout/forms/test/bug287446_subframe.html"></iframe> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 287446 **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + isnot(window.location.host, "example.com", "test is not testing cross-site"); + var accessed = false; + try { + $("i").contentDocument.documentElement; + accessed = true; + } catch(e) {} + is(accessed, false, "Shouldn't be able to access cross-site"); + + $("i").style.display = "none"; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "none", + "toggling display failed"); + $("i").style.display = ""; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "inline", + "toggling display back failed"); + + $("i").contentWindow.postMessage("start", "*"); +}); + +function continueTest() { + $("i").style.display = "none"; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "none", + "toggling display second time failed"); + $("i").style.display = ""; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "inline", + "toggling display back second time failed"); + +$("i").contentWindow.postMessage("continue", "*"); +} + +window.addEventListener("message", + function(evt) { + var arr = evt.data.split(/ /).map(decodeURIComponent); + if (arr[0] == 't') { + is(arr[1], arr[2], arr[3]); + } else if (arr[0] == 'c') { + continueTest(); + } else if (arr[0] == 'f') { + SimpleTest.finish(); + } + }, + false); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug345267.html b/layout/forms/test/test_bug345267.html new file mode 100644 index 000000000..0c1c4c9a4 --- /dev/null +++ b/layout/forms/test/test_bug345267.html @@ -0,0 +1,98 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=345267 +--> +<head> + <title>Test for Bug 345267</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=345267">Mozilla Bug 345267</a> +<p id="display"> + <input id="d1" maxlength="3" value="abcde"> + <input id="d2" maxlength="3"> + <input id="d3" maxlength="3"> + <input id="d4" value="abcdefghijk"> + <input id="target" value="abcdefghijklm" maxlength="3"> +</p> +<div id="content" style="display: none"> + <input id="u1" maxlength="3" value="abcdef"> + <input id="u2" maxlength="3"> + <input id="u3" maxlength="3"> + <input id="u4" value="abcdefghijkl"> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 345267 **/ +SimpleTest.waitForExplicitFinish(); +// Turn off Spatial Navigation to stop if from hijacking "left" keypress event. +SpecialPowers.pushPrefEnv({"set":[['snav.enabled', false]]}, runTest); + +function runTest() { + is($("d1").value, "abcde", + "Displayed initial value should not be truncated by maxlength"); + is($("u1").value, "abcdef", + "Undisplayed initial value should not be truncated by maxlength"); + + $("d2").value = "abcdefg"; + is($("d2").value, "abcdefg", + "Displayed set value should not be truncated by maxlength"); + + $("u2").value = "abcdefgh"; + is($("u2").value, "abcdefgh", + "Undisplayed set value should not be truncated by maxlength"); + + $("d3").defaultValue = "abcdefghi"; + is($("d3").value, "abcdefghi", + "Displayed set defaultValue should not be truncated by maxlength"); + + $("u3").defaultValue = "abcdefghij"; + is($("u3").value, "abcdefghij", + "Undisplayed set defaultValue should not be truncated by maxlength"); + + $("d4").maxLength = "3"; + is($("d4").value, "abcdefghijk", + "Displayed: setting maxLength should not truncate existing value"); + + $("u4").maxLength = "3"; + is($("u4").value, "abcdefghijkl", + "Undisplayed: setting maxLength should not truncate existing value"); + + // Now start the editing tests + is($("target").value, "abcdefghijklm", "Test starting state incorrect"); + $("target").focus(); + $("target").selectionStart = $("target").selectionEnd = 13; + sendKey("back_space"); + is($("target").value, "abcdefghijkl", "Should only delete one char"); + sendKey("back_space"); + is($("target").value, "abcdefghijk", "Should only delete one char again"); + (function () { + SpecialPowers.wrap($("target")).controllers.getControllerForCommand('cmd_undo') + .doCommand('cmd_undo'); + })(); + is($("target").value, "abcdefghijklm", + "Should be able to undo deletion in the face of maxlength"); + sendString("nopq"); + is($("target").value, "abcdefghijklm", + "Typing should have no effect when already past maxlength"); + + $("target").value = ""; + sendString("abcde"); + is($("target").value, "abc", "Typing should be limited by maxlength"); + + $("target").value = ""; + sendString("ad"); + sendKey("left"); + sendString("bc"); + is($("target").value, "abd", "Typing should be limited by maxlength again"); + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> + diff --git a/layout/forms/test/test_bug346043.html b/layout/forms/test/test_bug346043.html new file mode 100644 index 000000000..f509ae1fc --- /dev/null +++ b/layout/forms/test/test_bug346043.html @@ -0,0 +1,65 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=346043 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 346043</title> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> + <script type="application/javascript"> + /** Test for Bug 346043 **/ + function test(select, index, useEscape) { + select.selectedIndex = index; + is(select.selectedIndex, index, "Selected index is broken"); + + // Open the select dropdown. + // + // Using Alt+Down (instead of a click) seems necessary to make subsequent + // mouse events work with the dropdown itself, instead of the window below + // it. + select.focus(); + synthesizeKey("VK_DOWN", {altKey: true}); + + var options = select.getElementsByTagName("option"); + synthesizeMouseAtCenter(options[1], + {type: "mousemove", clickCount: 0}); + + // Close the select dropdown. + if (useEscape) + synthesizeKey("VK_ESCAPE", {}); // Tests a different code path. + select.blur(); + is(select.selectedIndex, index, "Selected index shouldn't change"); + } + + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(function() { + test(document.getElementById("test-unselected"), -1, true); + test(document.getElementById("test-unselected"), -1, false); + test(document.getElementById("test-disabled"), 0, true); + test(document.getElementById("test-disabled"), 0, false); + SimpleTest.finish(); + }); + </script> +</head> +<body> + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=346043">Mozilla Bug 346043</a> + <p id="display"></p> + <div id="content"> + <select id="test-unselected"> + <option>A</option> + <option>B</option> + <option>C</option> + </select> + + <select id="test-disabled"> + <option disabled>A</option> + <option>B</option> + <option>C</option> + </select> + </div> + <pre id="test"></pre> +</body> +</html> diff --git a/layout/forms/test/test_bug348236.html b/layout/forms/test/test_bug348236.html new file mode 100644 index 000000000..ff89c3bd9 --- /dev/null +++ b/layout/forms/test/test_bug348236.html @@ -0,0 +1,125 @@ +<!DOCTYPE HTML> +<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> + <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 + } + </style> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=348236">Mozilla Bug 348236</a> +<p id="display"></p> +<div id="content"> + + <select id="eSelect" size="1" onchange="++this.onchangeCount"> + <option selected>1</option> + <option>2</option> + <option>3</option> + </select> +</div> +<pre id="test"> +<script type="text/javascript"> + + /** Test for Bug 348236 **/ + +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) { + WinUtils.focus(eSelect) + WinUtils.sendKeyEvent("keyup", key, 0, modifiers) + WinUtils.sendKeyEvent("keypress", key, 0, modifiers) + WinUtils.sendKeyEvent("keydown", key, 0, modifiers) + } + + function testKey(key, modifiers, keyString, functionToContinue) { + var selectGotClick + function clickListener() { selectGotClick = true } + eSelect.selectedIndex = 0 + eSelect.onchangeCount = 0 + + // Drop the SELECT down. + keypressOnSelect(key, modifiers) + // 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, 90, 0, 0, 0, true) + setTimeout(cont2, timeout) + } + function cont2() { + // Close the select. + keypressOnSelect(key, modifiers) + 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) + selectGotClick = false + WinUtils.sendMouseEvent("mousedown", 320, 0, 0, 0, 0, true) + WinUtils.sendMouseEvent("mouseup", 320, 0, 0, 0, 0, true) + setTimeout(cont4, timeout) + } + function cont4() { + eSelect.removeEventListener("click", clickListener, true) + ok(!selectGotClick, "SELECT must not capture mouse events after closing it with " + keyString + ".") + functionToContinue() + } + } + + + // 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) + 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) + function nextKey1() { + // Test ALT-Up. + testKey(IDOMKeyEvent.DOM_VK_UP, IDOMEvent.ALT_MASK, "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) + else + finished() + } + function finished() { + // Reset value to get the expected value if we reload the page. + eSelect.selectedIndex = 0 + SimpleTest.finish() + } +}) + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug353539.html b/layout/forms/test/test_bug353539.html new file mode 100644 index 000000000..6ada2b115 --- /dev/null +++ b/layout/forms/test/test_bug353539.html @@ -0,0 +1,52 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=353539 +--> +<head> + <title>Test for Bug 353539</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=353539">Mozilla Bug 353539</a> +<p id="display"> + <textarea id="area" rows="5"> + Here + is + some + very + long + text + that + we're + using + for + testing + purposes + </textarea> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 353539 **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var area = document.getElementById("area"); + + is(area.scrollTop, 0, "The textarea should not be scrolled initially"); + area.focus(); + setTimeout(function() { + is(area.scrollTop, 0, "The textarea's insertion point should not be scrolled into view"); + + SimpleTest.finish(); + }, 0); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug365410.html b/layout/forms/test/test_bug365410.html new file mode 100644 index 000000000..93a55eac6 --- /dev/null +++ b/layout/forms/test/test_bug365410.html @@ -0,0 +1,134 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=365410 +--> +<head> + <title>Test for Bug 365410</title> + <script type="application/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=365410">Mozilla Bug 365410</a> +<p id="display"> +<select id="test0" multiple="multiple"> + <option id="option">Item 1</option> + <option>Item 2</option> + <option>Item 3</option> + <option>Item 4</option> + <option>Item 5</option> + <option>Item 6</option> + <option>Item 7</option> + <option>Item 8</option> + <option>Item 9</option> + <option>Item 10</option> + <option>Item 11</option> + <option>Item 12</option> + <option>Item 13</option> + <option>Item 14</option> + <option>Item 15</option> +</select> +<select id="test1" multiple="multiple" size="1"> + <option>Item 1</option> + <option>Item 2</option> + <option>Item 3</option> + <option>Item 4</option> + <option>Item 5</option> + <option>Item 6</option> + <option>Item 7</option> + <option>Item 8</option> + <option>Item 9</option> + <option>Item 10</option> + <option>Item 11</option> + <option>Item 12</option> + <option>Item 13</option> + <option>Item 14</option> + <option>Item 15</option> +</select> +<select id="test2" multiple="multiple" size="1" style="height:0.9em"> + <option>Item 1</option> + <option>Item 2</option> + <option>Item 3</option> + <option>Item 4</option> + <option>Item 5</option> + <option>Item 6</option> + <option>Item 7</option> + <option>Item 8</option> + <option>Item 9</option> + <option>Item 10</option> + <option>Item 11</option> + <option>Item 12</option> + <option>Item 13</option> + <option>Item 14</option> + <option>Item 15</option> +</select> +<select id="test3" multiple="multiple" size="1"></select> +<select id="test4" multiple="multiple" size="1" style="height:0.9em"></select> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 365410 **/ + +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"); + is(elm.selectedIndex, index, "pageUpDownTest: selectedIndex for " + id + " is " + index); +} + +function upDownTest(id,index) { + var elm = document.getElementById(id); + elm.focus(); + elm.selectedIndex = 0; + sendKey("down"); + sendKey("down"); + sendKey("up"); + sendKey("down"); + is(elm.selectedIndex, index, "upDownTest: selectedIndex for " + id + " is " + index); +} + +function setHeight(id, h) { + var elm = document.getElementById(id); + elm.style.height = h + 'px'; +} + +function runTest() { + var h = document.getElementById("option").clientHeight; + var list5itemsHeight = h * 5.5; + setHeight("test0", list5itemsHeight); + setHeight("test1", list5itemsHeight); + setHeight("test3", list5itemsHeight); + + pageUpDownTest("test0",8); + pageUpDownTest("test1",8); + pageUpDownTest("test2",2); + pageUpDownTest("test3",-1); + pageUpDownTest("test4",-1); + upDownTest("test0",2); + upDownTest("test1",2); + upDownTest("test2",2); + upDownTest("test3",-1); + upDownTest("test4",-1); + + SimpleTest.finish(); +} + +SimpleTest.waitForExplicitFinish(); +// Turn off spatial nav so that it does not hijack the up and down events. +SimpleTest.waitForFocus(function() { + SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug378670.html b/layout/forms/test/test_bug378670.html new file mode 100644 index 000000000..098ff75be --- /dev/null +++ b/layout/forms/test/test_bug378670.html @@ -0,0 +1,55 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=378670 +--> +<head> + <title>Test for Bug 378670</title> + <script type="application/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=378670">Mozilla Bug 378670</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +Clicking on the select should not crash Mozilla +<select id="select"> +<option>1</option> +<option>2</option> +</select> + +<pre id="test"> +<script> +document.body.addEventListener('popupshowing', function(e) {e.target.parentNode.removeChild(e.target) }, true); +</script> +<script type="application/javascript"> + +/** Test for Bug 378670 **/ + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); + +function clickit() { + var select = document.getElementById('select'); + + sendMouseEvent({type:'mousedown'}, select); + sendMouseEvent({type:'mouseup'}, select); + sendMouseEvent({type:'click'}, select); + + setTimeout(finish, 200); +} + +window.addEventListener('load', clickit, false); + +function finish() +{ + ok(true, "This is a mochikit version of a crash test. To complete is to pass."); + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug402198.html b/layout/forms/test/test_bug402198.html new file mode 100644 index 000000000..647a892fb --- /dev/null +++ b/layout/forms/test/test_bug402198.html @@ -0,0 +1,77 @@ +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=402198 +--> +<head> + <title>Test for Bug 402198</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=402198">Mozilla Bug 402198</a> +<p id="display"> + <select></select> + <select><optgroup></optgroup></select> + <legend style="overflow: scroll;"> + <select></select> + </legend> + <span></span> + <span style="display: -moz-box;"> + <select></select> + </span> + <legend style=" "> + <label style="overflow: scroll; display: -moz-box;"> + <select></select> + </label> + </legend> + <legend> + <label style=" display: table;"> + <select id="a"> + <option>High Grade</option> + <option>Medium Grade</option> + </select> + </label> + </legend> + + <input> + <select multiple="multiple"></select> + <select style="overflow: scroll; display: -moz-box;"> + <optgroup></optgroup> + <optgroup style="display: table-cell;"></optgroup> + </select> +</p> + +<pre id="test"> +<script class="testbody" type="text/javascript"> +function doe3() { + document.documentElement.style.display = 'none'; + document.body.offsetHeight; + document.documentElement.style.display = ''; + document.body.offsetHeight; + + document.getElementById('a').focus(); + document.body.style.display = 'none'; + + synthesizeKey('KEY_Tab', { code: "Tab", shiftKey: true }); + + is(0, 0, "this is a crash/assertion test, so we're ok if we survived this far"); + setTimeout(function() {document.body.style.display = ''; SimpleTest.finish();}, 0); +} + +function do_test() { + setTimeout(doe3,300); +} + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); +addLoadEvent(do_test); +</script> +</pre> + +<style> +* {quotes: "quote" "quote" !important;} +</style> + +</body> +</html> diff --git a/layout/forms/test/test_bug411236.html b/layout/forms/test/test_bug411236.html new file mode 100644 index 000000000..a5369b832 --- /dev/null +++ b/layout/forms/test/test_bug411236.html @@ -0,0 +1,80 @@ +<!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> + <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;" + id="fileinput"> +</div> +<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(); + } + + if (i >= 100) { + ok(false, "Couldn't find an input element!"); + SimpleTest.finish(); + return; + } + + ok(window.oTarget instanceof HTMLButtonElement, "Should have focused an input element!") + ok(SpecialPowers.wrap(window.oTarget).type == "button", "Should have focused 'Browse...' button!"); + var e = document.createEvent("mouseevents"); + e.initMouseEvent("click", true, true, window, 0, 1, 1, 1, 1, + false, false, false, false, 0, null); + SpecialPowers.wrap(window.oTarget).dispatchEvent(e); + ok(window.fileInputGotClick, + "File input should have got a click event, but not open the file dialog."); + SimpleTest.finish(); +} + +function beginTest() { + // accessibility.tabfocus must be set to value 7 before running test also + // on a mac. + SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]}, do_test); +} + +function do_test() { + window.focus(); + document.getElementById('fileinput').focus(); + setTimeout(test, 100); +} + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); +addLoadEvent(beginTest); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug446663.html b/layout/forms/test/test_bug446663.html new file mode 100644 index 000000000..f12a47248 --- /dev/null +++ b/layout/forms/test/test_bug446663.html @@ -0,0 +1,80 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=446663 +--> +<head> + <title>Test for Bug 446663</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=446663">Mozilla Bug 446663</a> +<p id="display"> +<style>#bug446663_a:focus{overflow:hidden}</style> +<input id="bug446663_a"><input id="bug446663_b"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 446663 **/ + +function test_edit_cmds(id) { + + var elm = document.getElementById(id); + elm.focus(); + elm.select(); + SpecialPowers.wrap(elm).controllers.getControllerForCommand('cmd_cut') + .doCommand('cmd_cut'); + is(elm.value, '', id + " cut"); + + SpecialPowers.wrap(elm).controllers.getControllerForCommand('cmd_undo') + .doCommand('cmd_undo'); + is(elm.value, '123', id + " undo"); +} + +var inputHappened = false; +function inputListener() { + inputHappened = true; + $(id).removeEventListener("input", inputListener, false); +} + +var id = 'bug446663_a' +var elm = document.getElementById(id); +elm.focus(); +var x = document.body.offsetHeight; +$(id).addEventListener("input", inputListener, false); +sendChar('1'); +is(inputHappened, true, "How come no input?"); +sendChar('3'); +sendKey('LEFT') +sendChar('2'); +elm.blur(); +x = document.body.offsetHeight; +is(elm.value, '123', id + " edit"); +test_edit_cmds(id) + +id = 'bug446663_b' +elm = document.getElementById(id); +elm.focus(); +sendChar('1'); +elm.style.display = 'none' +var x = document.body.offsetHeight; +elm.style.display = 'inline' +x = document.body.offsetHeight; +sendChar('3'); +sendKey('LEFT') +sendChar('2'); +elm.blur(); +x = document.body.offsetHeight; +is(elm.value, '123', id + " edit"); +test_edit_cmds(id) + +</script> +</pre> +</body> +</html> + diff --git a/layout/forms/test/test_bug476308.html b/layout/forms/test/test_bug476308.html new file mode 100644 index 000000000..d8f572803 --- /dev/null +++ b/layout/forms/test/test_bug476308.html @@ -0,0 +1,31 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=476308 +--> +<head> + <title>Test for Bug 345267</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> + +<button style="-moz-appearance: none; width: 100px; height: 60px; background-color: red; border: 2px solid green; box-shadow: 30px 0px 3.5px black; position: absolute; top: 300px; left: 20px;" + id="button1">1</button> + +<br /> +<div style="width: 100px; height: 100px; background-color: green; border: 3px dotted blue; box-shadow: -30px -20px 0px black; position: absolute; top: 500px; left: 70px;" + id="div1">2</div> + +<script type="text/javascript"> + var elem = document.elementFromPoint(130, 310); + isnot(elem, document.getElementById("button1"), "button1's box-shadow is receiving events when it shouldn't"); + + elem = document.elementFromPoint(50, 500); + isnot(elem, document.getElementById("div1"), "div1's box-shadow is receiving events when it shouldn't"); +</script> + +</body> +</html> + diff --git a/layout/forms/test/test_bug477531.html b/layout/forms/test/test_bug477531.html new file mode 100644 index 000000000..d766d3f7d --- /dev/null +++ b/layout/forms/test/test_bug477531.html @@ -0,0 +1,65 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=477531 +--> +<head> + <title>Test for Bug 477531</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + + <style type="text/css"> + #s { + margin-left: 10px; + } + + #s:indeterminate { + margin-left: 30px; + } + </style> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=477531">Mozilla Bug 477531</a> +<p id="display"></p> +<div id="content"> + +<input type="checkbox" id="s" /> + +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 477531 **/ +is(document.defaultView.getComputedStyle($("s"), null).getPropertyValue("margin-left"), + "10px", + "Non-indeterminate checkbox should have a margin of 10px"); + +$("s").indeterminate = true; + +is(document.defaultView.getComputedStyle($("s"), null).getPropertyValue("margin-left"), + "30px", + "Indeterminate checkbox should have a margin of 30px"); + +$("s").setAttribute("type", "radio"); + +is(document.defaultView.getComputedStyle($("s"), null).getPropertyValue("margin-left"), + "30px", + "Setting an indeterminate element to type radio should give it indeterminate styles"); + +$("s").setAttribute("type", "checkbox"); + +is(document.defaultView.getComputedStyle($("s"), null).getPropertyValue("margin-left"), + "30px", + "Setting an indeterminate element to type checkbox should give it indeterminate styles"); + +$("s").indeterminate = false; + +is(document.defaultView.getComputedStyle($("s"), null).getPropertyValue("margin-left"), + "10px", + "Newly non-indeterminate checkbox should have a margin of 10px"); + +</script> +</pre> +</body> +</html> + diff --git a/layout/forms/test/test_bug477700.html b/layout/forms/test/test_bug477700.html new file mode 100644 index 000000000..45537257b --- /dev/null +++ b/layout/forms/test/test_bug477700.html @@ -0,0 +1,60 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=477700 +--> +<head> + <title>Test for Bug 477700</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=477700">Mozilla Bug 477700</a> +<p id="display"> + <iframe id="i" + src="http://example.com/tests/layout/forms/test/bug477700_subframe.html"></iframe> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 477700 **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + isnot(window.location.host, "example.com", "test is not testing cross-site"); + var accessed = false; + try { + $("i").contentDocument.documentElement; + accessed = true; + } catch(e) {} + is(accessed, false, "Shouldn't be able to access cross-site"); + + $("i").style.display = "none"; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "none", + "toggling display failed"); + $("i").style.display = ""; + document.body.offsetWidth; + is(document.defaultView.getComputedStyle($("i"), "").display, "inline", + "toggling display back failed"); + + $("i").contentWindow.postMessage("start", "*"); +}); + +window.addEventListener("message", + function(evt) { + var arr = evt.data.split(/ /).map(decodeURIComponent); + if (arr[0] == 't') { + is(arr[1], arr[2], arr[3]); + } else if (arr[0] == 'f') { + SimpleTest.finish(); + } + }, + false); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug478219.xhtml b/layout/forms/test/test_bug478219.xhtml new file mode 100644 index 000000000..42e5f07b7 --- /dev/null +++ b/layout/forms/test/test_bug478219.xhtml @@ -0,0 +1,38 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=478219 +--> +<head> + <title>Test for Bug 478219</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + <style type="text/css"> + + </style> +</head> + +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478219">Mozilla Bug 478219</a> +<input style="overflow: scroll;-moz-binding:url(#xbl);" type="image"/> +<pre id="test"> +<script class="testbody" type="text/javascript"> + var win = window.open('', '', 'width=100,height=100'); + win.close(); + is(win.closed, true, "Window should have been opened"); + is(win.opener, window, "Opened window should have as opener this window"); +</script> +</pre> + +<bindings xmlns="http://www.mozilla.org/xbl"> +<binding id="xbl" inheritstyle="false"> +<content> + +<div xmlns="http://www.w3.org/1999/xhtml" contenteditable="true"> +<style>style {-moz-binding:url(#xbl);</style> +</div> +<textarea xmlns="http://www.w3.org/1999/xhtml"></textarea> +</content> +</binding> +</bindings> +</body> +</html> diff --git a/layout/forms/test/test_bug534785.html b/layout/forms/test/test_bug534785.html new file mode 100644 index 000000000..76590798f --- /dev/null +++ b/layout/forms/test/test_bug534785.html @@ -0,0 +1,88 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=534785 +--> +<head> + <title>Test for Bug 534785</title> + <script type="application/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=534785">Mozilla Bug 534785</a> +<p id="display"></p> +<input type="text" value="test"> +<div id="reframe"> +<textarea></textarea> +<textarea>test</textarea> +<input type="text"> +<input type="text" value="test"> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 534785 **/ + +SimpleTest.waitForExplicitFinish(); + +SimpleTest.waitForFocus(function() { + var i = document.querySelector("input"); + i.addEventListener("focus", function() { + is(i.value, "test", "Sanity check"); + + is(document.activeElement, i, "Should be focused before frame reconstruction"); + synthesizeKey("1", {}); + is(i.value, "1test", "Can accept keyboard events before frame reconstruction"); + + // force frame reconstruction + i.style.display = "none"; + document.offsetHeight; + i.style.display = ""; + document.offsetHeight; + + is(document.activeElement, i, "Should be focused after frame reconstruction"); + synthesizeKey("2", {}); + is(i.value, "12test", "Can accept keyboard events after frame reconstruction"); + + // Make sure reframing happens gracefully + var reframeDiv = document.getElementById("reframe"); + var textAreaWithoutValue = reframeDiv.querySelectorAll("textarea")[0]; + var textAreaWithValue = reframeDiv.querySelectorAll("textarea")[1]; + var inputWithoutValue = reframeDiv.querySelectorAll("input")[0]; + var inputWithValue = reframeDiv.querySelectorAll("input")[1]; + reframeDiv.style.display = "none"; + document.body.offsetWidth; + reframeDiv.style.display = ""; + document.body.offsetWidth; + [textAreaWithoutValue, inputWithoutValue].forEach(function (elem) { + is(elem.value, "", "Value should persist correctly"); + }); + [textAreaWithValue, inputWithValue].forEach(function (elem) { + is(elem.value, "test", "Value should persist correctly"); + }); + [inputWithoutValue, inputWithValue].forEach(elem => elem.type = "submit"); + document.body.offsetWidth; + is(inputWithoutValue.value, "", "Value should persist correctly"); + is(inputWithValue.value, "test", "Value should persist correctly"); + [inputWithoutValue, inputWithValue].forEach(elem => elem.type = "text"); + document.body.offsetWidth; + is(inputWithoutValue.value, "", "Value should persist correctly"); + is(inputWithValue.value, "test", "Value should persist correctly"); + [inputWithoutValue, inputWithValue].forEach(elem => elem.focus()); // initialze the editor + reframeDiv.style.display = "none"; + document.body.offsetWidth; + reframeDiv.style.display = ""; + document.body.offsetWidth; + is(inputWithoutValue.value, "", "Value should persist correctly with editor"); + is(inputWithValue.value, "test", "Value should persist correctly with editor"); + + SimpleTest.finish(); + }, false); + i.focus(); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug536567_perwindowpb.html b/layout/forms/test/test_bug536567_perwindowpb.html new file mode 100644 index 000000000..8bb2f68ce --- /dev/null +++ b/layout/forms/test/test_bug536567_perwindowpb.html @@ -0,0 +1,215 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=536567 +--> +<head> + <title>Test for Bug 536567</title> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536567">Mozilla Bug 536567</a> +<p id="display"></p> +<pre id="test"> +<script type="application/javascript"> +/** Test for Bug 536567 **/ + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cu = Components.utils; +const Cm = Components.manager; + +Cu.import("resource://gre/modules/Services.jsm"); + +var MockFilePicker = SpecialPowers.MockFilePicker; +MockFilePicker.init(window); + +var tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile); +var homeDir = Services.dirsvc.get("Desk", Ci.nsILocalFile); + +function newDir() { + var dir = tmpDir.clone(); + dir.append("testdir" + Math.floor(Math.random() * 10000)); + dir.QueryInterface(Ci.nsILocalFile); + dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700); + return dir; +} + +var dirs = []; +for(var i = 0; i < 6; i++) { + dirs.push(newDir()); +} +dirs.push(homeDir); +var domains = ['http://mochi.test:8888', 'http://example.org:80', 'http://example.com:80']; +/* + * These tests take 3 args each: + * - which domain to load + * - the filePicker displayDirectory we expect to be set + * - the file to pick (in most cases this will show up in the next test, + * as indicated by the comments) + */ +var tests = [ + "clear history", + [0, 6, 0], // 0 -> 3 + [1, 6, 1], // 1 -> 4 + [2, 6, 2], // 2 -> 5 + [0, 0, 3], // 3 -> 6 + [1, 1, 1], // 4 -> 8 + [2, 2, 2], // 5 -> 9 + [0, 3, 1], // 6 -> 7 + [0, 1, 0], // 7 -> x + [1, 1, 1], // 8 -> x + [2, 2, 2], // 9 -> x + "clear history", + [0, 6, 0], // 11 -> 15 + [1, 6, 1], // 12 -> 16 + [2, 6, 2], // 13 -> 17 + "pb on", + [0, 0, 3], // 15 -> 18 + [1, 1, 4], // 16 -> 19 + [2, 2, 5], // 17 -> 20 + [0, 3, 3], // 18 -> x + [1, 4, 4], // 19 -> x + [2, 5, 5], // 20 -> x + "pb off", + [0, 0, 5], // 22 -> 26 + [1, 1, 4], // 23 -> 27 + [2, 2, 3], // 24 -> 28 + "pb on", + [0, 3, 5], // 26 -> x + [1, 4, 4], // 27 -> x + [2, 5, 3], // 28 -> x + "clear history", + // Not checking after clear history because browser.download.lastDir content + // pref is not being clear properly in private windows. + //[0, 6, 0], // 30 -> x + //[1, 6, 1], // 31 -> x + //[2, 6, 2], // 32 -> x + "pb off" +]; + +var testIndex = 0; +var content; +var normalWindow; +var privateWindow; +var normalWindowIframe; +var privateWindowIframe; + +function runTest() { + var test = tests[testIndex]; + if (test == undefined) { + endTest(); + } else if (test == "pb on") { + content = privateWindowIframe; + testIndex++; + runTest(); + } else if (test == "pb off") { + content = normalWindowIframe; + testIndex++; + runTest(); + } else if (test == "clear history") { + Services.obs.notifyObservers(null, "browser:purge-session-history", ""); + testIndex++; + runTest(); + } else { + var file = dirs[test[2]].clone(); + file.append("file.file"); + MockFilePicker.returnFiles = [file]; + content.setAttribute('src', domains[test[0]] + '/chrome/layout/forms/test/bug536567_subframe.html'); + } +} + +function endTest() { + for(var i = 0; i < dirs.length - 1; i++) { + dirs[i].remove(true); + } + + normalWindow.close(); + privateWindow.close(); + MockFilePicker.cleanup(); + SimpleTest.finish(); +} + +var mainWindow = + window.QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem). + rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIDOMWindow); +var contentPage = "http://mochi.test:8888/chrome/layout/forms/test/bug536567_iframe.html"; + +function whenDelayedStartupFinished(aWindow, aCallback) { + Services.obs.addObserver(function observer(aSubject, aTopic) { + if (aWindow == aSubject) { + Services.obs.removeObserver(observer, aTopic); + setTimeout(aCallback, 0); + } + }, "browser-delayed-startup-finished", false); +} + +function testOnWindow(aIsPrivate, aCallback) { + var win = mainWindow.OpenBrowserWindow({private: aIsPrivate}); + whenDelayedStartupFinished(win, function() { + win.addEventListener("DOMContentLoaded", function onInnerLoad() { + if (win.content.location.href != contentPage) { + win.gBrowser.loadURI(contentPage); + return; + } + win.removeEventListener("DOMContentLoaded", onInnerLoad, true); + win.gBrowser.selectedBrowser.focus(); + SimpleTest.info("DOMContentLoaded's window: " + win.location + " vs. " + window.location); + win.setTimeout(function() { aCallback(win); }, 0); + }, true); + SimpleTest.info("load's window: " + win.location + " vs. " + window.location); + win.setTimeout(function() { win.gBrowser.loadURI(contentPage); }, 0); + }); +} + +MockFilePicker.showCallback = function(filepicker) { + var test = tests[testIndex]; + var returned = -1; + for (var i = 0; i < dirs.length; i++) { + if (dirs[i].path == MockFilePicker.displayDirectory.path) { + returned = i; + break; + } + } + if (test[1] == -1) { + ok(false, "We should never get an unknown directory back"); + } else { + is(returned, test[1], 'test ' + testIndex); + } + + filepicker.window.setTimeout(function() { + testIndex++; + runTest(); + }, 0); +}; + +window.onload = function() { + SimpleTest.waitForExplicitFinish(); + testOnWindow(false, function(aWin) { + var selectedBrowser = aWin.gBrowser.selectedBrowser; + + normalWindow = aWin; + normalWindowIframe = + selectedBrowser.contentDocument.getElementById("content"); + + testOnWindow(true, function(aPrivateWin) { + selectedBrowser = aPrivateWin.gBrowser.selectedBrowser; + + privateWindow = aPrivateWin; + privateWindowIframe = + selectedBrowser.contentDocument.getElementById("content"); + + content = normalWindowIframe; + selectedBrowser.contentWindow.setTimeout(runTest, 0); + }); + }); +}; + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug542914.html b/layout/forms/test/test_bug542914.html new file mode 100644 index 000000000..dc2fadb3a --- /dev/null +++ b/layout/forms/test/test_bug542914.html @@ -0,0 +1,115 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=542914 +--> +<head> + <title>Test for Bug 542914</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=542914">Mozilla Bug 542914</a> +<p id="display"> + <input type="text" id="a" value="test"> + <input type="text" id="b"> + <input type="text" id="c"> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 542914 **/ +SimpleTest.waitForExplicitFinish(); +function runTests(callback, type) { + var a = $("a"); + + // Test that the initial value of the control is available to script + // without initilization of the editor + is(a.value, "test", "The value is available before initialization"); + // Initialize the editor + a.focus(); + // Test that the value does not change after initialization + is(a.value, "test", "The value does not change after initializtion"); + + var b = $("b"); + + // Test that the initial value is empty before initialization. + is(b.value, "", "The value is empty before initialization"); + // Make sure that the value can be changed before initialization + b.value ="some value"; + is(b.value, "some value", "The value can be changed before initialization"); + // Initialize the editor + b.focus(); + // Make sure that the value does not change after initialization + is(b.value, "some value", "The value does not change after initialization"); + // Make sure that the value does not change if the element is hidden + b.style.display = "none"; + document.body.offsetHeight; + is(b.value, "some value", "The value does not change while hidden"); + b.style.display = ""; + document.body.offsetHeight; + b.focus(); + is(b.value, "some value", "The value does not change after being shown"); + + var c = $("c"); + + // Make sure that the control accepts input events without explicit initialization + is(c.value, "", "Control is empty initially"); + c.focus(); + sendChar("a"); + 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"); + is(c.value, "ab", "Control retains caret position after being re-focused"); + + var d = document.createElement("input"); + d.setAttribute("type", type); + $("display").appendChild(d); + document.body.offsetHeight; + + // 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"); + is(d.value, "newx", "Dynamic control accepts keyboard input without explicit initialization"); + $("display").removeChild(d); + is(d.value, "newx", "Dynamic control retains value after being removed from the document"); + + callback(); +} + +var gPreviousType = "text"; +function setTypes(aType) { + var content = document.getElementById("display"); + content.innerHTML = content.innerHTML.replace(gPreviousType, aType); + gPreviousType = aType; +} + +addLoadEvent(function() { + ok(true, "Running tests on <input type=text>"); + runTests(function() { + ok(true, "Running tests on <input type=password>"); + setTypes("password"); + runTests(function() { + ok(true, "Running tests on <input type=tel>"); + setTypes("tel"); + runTests(function() { + SimpleTest.finish(); + }, "tel"); + }, "password"); + }, "text"); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug549170.html b/layout/forms/test/test_bug549170.html new file mode 100644 index 000000000..37c5bb336 --- /dev/null +++ b/layout/forms/test/test_bug549170.html @@ -0,0 +1,74 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=549170 +--> +<head> + <title>Test for Bug 549170</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 onload="window.setTimeout(runTests, 0);"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549170">Mozilla Bug 549170</a> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<input id='i' + onmouseup="mouseHandler(event);" + onmousedown="mouseHandler(event);"> +<textarea id='t' + onmouseup="mouseHandler(event);" + onmousedown="mouseHandler(event);"></textarea><br> +<input id='ip' placeholder='foo' + onmouseup="mouseHandler(event);" + onmousedown="mouseHandler(event);"> +<textarea id='tp' placeholder='foo' + onmouseup="mouseHandler(event);" + onmousedown="mouseHandler(event);"></textarea> +<pre id="test"> + +<script type="application/javascript"> + +/** Test for Bug 549170 **/ + +var gNumberOfMouseEventsCatched = 0; + +SimpleTest.waitForExplicitFinish(); + +function mouseHandler(aEvent) +{ + gNumberOfMouseEventsCatched++; + is(SpecialPowers.wrap(aEvent).originalTarget.nodeName, "DIV", "An inner div should be the target of the event"); + ok(SpecialPowers.wrap(aEvent).originalTarget.classList.contains("anonymous-div"), "the target div should be the editor div"); +} + +function checkMouseEvents(element) +{ + gNumberOfMouseEventsCatched = 0; + + synthesizeMouse(element, 5, 5, {type: "mousedown", button: 0}); + synthesizeMouse(element, 5, 5, {type: "mouseup", button: 0}); + synthesizeMouse(element, 5, 5, {type: "mousedown", button: 1}); + // NOTE: this event is going to copy the buffer on linux, this should not be a problem + synthesizeMouse(element, 5, 5, {type: "mouseup", button: 1}); + synthesizeMouse(element, 5, 5, {type: "mousedown", button: 2}); + synthesizeMouse(element, 5, 5, {type: "mouseup", button: 2}); + + is(gNumberOfMouseEventsCatched, 6, "Some mouse events have not been catched"); +} + +function runTests() +{ + checkMouseEvents(document.getElementById('i')); + checkMouseEvents(document.getElementById('t')); + checkMouseEvents(document.getElementById('ip')); + checkMouseEvents(document.getElementById('tp')); + + SimpleTest.finish(); +} + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug562447.html b/layout/forms/test/test_bug562447.html new file mode 100644 index 000000000..53f84428e --- /dev/null +++ b/layout/forms/test/test_bug562447.html @@ -0,0 +1,62 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=562447 +--> +<head> + <title>Test for Bug 562447</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + +</head> +<body> +<p><a target="_blank" href="https://bugzilla.mozilla.org/show_bug?id=562447">Mozilla Bug 562447</a> + +<input id="WhyDoYouFocusMe" + style="position: absolute; left: -50px; top: 10000px;"> + +<pre id="test"> +<script> +addLoadEvent(function() { + // Scroll down a bit + window.scrollTo(0, 5000); + + setTimeout(function() { + // Make sure that we're scrolled by 5000px + is(window.pageYOffset, 5000, "Make sure we're scrolled correctly"); + + // Scroll back up, and mess with the input box along the way + var input = document.getElementById("WhyDoYouFocusMe"); + input.focus(); + input.blur(); + window.scrollTo(0, 0); + + setTimeout(function() { + is(window.pageYOffset, 0, "Make sure we're scrolled back up correctly"); + + // Scroll back up + window.scrollTo(0, 5000); + + setTimeout(function() { + is(window.pageYOffset, 5000, "Sanity check"); + + window.scrollTo(0, 0); + input.focus(); + input.blur(); + + setTimeout(function() { + isnot(window.pageYOffset, 0, "This time we shouldn't be scrolled up"); + + SimpleTest.finish(); + }, 0); + }, 0); + }, 0); + }, 0); +}); + +SimpleTest.waitForExplicitFinish(); +</script> +</pre> + +</body> +</html> diff --git a/layout/forms/test/test_bug563642.html b/layout/forms/test/test_bug563642.html new file mode 100644 index 000000000..9c5171d70 --- /dev/null +++ b/layout/forms/test/test_bug563642.html @@ -0,0 +1,85 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=563642 +--> +<head> + <title>Test for Bug 563642</title> + <script type="application/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=563642">Mozilla Bug 563642</a> +<p id="display"> +<select id="test1" multiple="multiple" size="1"> + <option>Item 1</option> + <option>Item 2</option> + <option>Item 3</option> + <option>Item 4</option> + <option>Item 5</option> +</select> +<select id="test2" multiple="multiple" size="1"> + <option>Item 1</option> + <option disabled>Item 2</option> + <option>Item 3</option> + <option disabled>Item 4</option> + <option>Item 5</option> +</select> +<select id="test3" multiple="multiple"></select> +<select id="test4" multiple="multiple" size="1"></select> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 563642 **/ + +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"); + is(elm.selectedIndex, index, "pageUpDownTest: selectedIndex for " + id + " is " + index); +} + +function upDownTest(id,index) { + var elm = document.getElementById(id); + elm.focus(); + elm.selectedIndex = 0; + sendKey("down"); + sendKey("down"); + sendKey("down"); + sendKey("up"); + sendKey("down"); + is(elm.selectedIndex, index, "upDownTest: selectedIndex for " + id + " is " + index); +} + +function runTest() { + pageUpDownTest("test1",3); + pageUpDownTest("test2",4); + pageUpDownTest("test3",-1); + pageUpDownTest("test4",-1); + upDownTest("test1",3); + upDownTest("test2",4); + upDownTest("test3",-1); + upDownTest("test4",-1); + + SimpleTest.finish(); +} +SimpleTest.waitForExplicitFinish(); +// Turn off Spatial Navigation because it hijacks down and up key events. +SimpleTest.waitForFocus(function() { + SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest); +}) + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug564115.html b/layout/forms/test/test_bug564115.html new file mode 100644 index 000000000..5723b55d5 --- /dev/null +++ b/layout/forms/test/test_bug564115.html @@ -0,0 +1,55 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=564115 +--> +<head> + <title>Test for Bug 564115</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + +</head> +<body> +<p><a target="_blank" href="https://bugzilla.mozilla.org/show_bug?id=564115">Mozilla Bug 564115</a> + +<pre id="test"> +<script> + +const TEST_URL = "/tests/layout/forms/test/bug564115_window.html"; + +addLoadEvent(function() { + var win = open(TEST_URL, "", "width=600,height=600"); + SimpleTest.waitForFocus(function() { + var doc = win.document; + var input = doc.querySelector("input"); + + // Focus the input box, and wait for the focus to actually happen + input.focus(); + setTimeout(function() { + // Scroll down a bit + win.scrollTo(0, 5000); + + setTimeout(function() { + is(win.pageYOffset, 5000, "Page should be scrolled correctly"); + + // Refocus the window + SimpleTest.waitForFocus(function() { + SimpleTest.waitForFocus(function() { + is(win.pageYOffset, 5000, + "The page's scroll offset should not have been changed"); + + win.close(); + SimpleTest.finish(); + }, win); + }); + }, 0); + }, 0); + }, win); +}); + +SimpleTest.waitForExplicitFinish(); +</script> +</pre> + +</body> +</html> diff --git a/layout/forms/test/test_bug571352.html b/layout/forms/test/test_bug571352.html new file mode 100644 index 000000000..547ab4007 --- /dev/null +++ b/layout/forms/test/test_bug571352.html @@ -0,0 +1,86 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=571352 +--> +<head> + <title>Test for Bug 571352</title> + <script type="application/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=571352">Mozilla Bug 571352</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 571352 **/ + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(function test() { + function createList() { + $('display').innerHTML = '<select multiple><option>0<option>1<option>2<option>3<option>4<option>5</select>'; + $('display').firstChild.focus(); + } + function option(index) { + return $('display').firstChild.childNodes[index]; + } + function remove(index) { + var sel = $('display').firstChild; + sel.removeChild(sel.childNodes[index]); + } + function up() { synthesizeKey("VK_UP", {}); } + function shiftUp() { synthesizeKey("VK_UP", {shiftKey:true}); } + function down() { synthesizeKey("VK_DOWN", {}); } + function shiftDown() { synthesizeKey("VK_DOWN", {shiftKey:true}); } + function mouseEvent(index,event) { + synthesizeMouse(option(index), 5, 5, event); + } + + const click = {}; + const shiftClick = {shiftKey:true}; + const CtrlClick = {CtrlKey:true}; + createList(); + mouseEvent(0,click) + is(document.activeElement,$('display').firstChild,"<select> is focused"); + mouseEvent(2,shiftClick) + remove(0); + ok(option(0).selected && option(1).selected,"first two options are selected"); + mouseEvent(2,shiftClick) + ok(option(0).selected && option(1).selected && option(2).selected,"first three options are selected"); + shiftUp(); + ok(option(0).selected && option(1).selected,"first two options are selected"); + remove(1); + ok(option(0).selected,"first option is selected"); + shiftDown(); + ok(option(0).selected && option(1).selected,"first two options are selected"); + down(); + ok(option(2).selected,"third option is selected"); + shiftDown(); + ok(option(2).selected && option(3).selected,"third & fourth option are selected"); + remove(2); + shiftUp(); + ok(option(1).selected && option(2).selected,"2nd & third option are selected"); + remove(0); + mouseEvent(0,shiftClick) + ok(option(0).selected && option(1).selected,"all remaining 2 options are selected"); + shiftDown(); + remove(1); + ok(!option(0).selected,"first option is unselected"); + remove(0); // select is now empty + ok($('display').firstChild.firstChild==null,"all options were removed"); + + SimpleTest.finish(); +}); + + + + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug572406.html b/layout/forms/test/test_bug572406.html new file mode 100644 index 000000000..3f2693c75 --- /dev/null +++ b/layout/forms/test/test_bug572406.html @@ -0,0 +1,48 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=572406 +--> +<head> + <title>Test for Bug 572406</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body onload='runTests();'> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=572406">Mozilla Bug 572406</a> +<p id="display"></p> +<div id='content'> + <textarea id='i'>foo</textarea> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 572406 **/ + +SimpleTest.waitForExplicitFinish(); + +function runTests() +{ + var textarea = document.getElementById('i'); + + textarea.firstChild.nodeValue = "bar"; + is(textarea.value, textarea.firstChild.nodeValue, + "textarea value should be firstChild.nodeValue"); + is(textarea.defaultValue, textarea.firstChild.nodeValue, + "textarea defaultValue should be firstChild.nodeValue"); + + textarea.style.display = 'none'; + SimpleTest.executeSoon(function() { + textarea.firstChild.nodeValue = "tulip"; + is(textarea.value, textarea.firstChild.nodeValue, + "textarea value should be firstChild.nodeValue"); + is(textarea.defaultValue, textarea.firstChild.nodeValue, + "textarea defaultValue should be firstChild.nodeValue"); + SimpleTest.finish(); + }); +} + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug572649.html b/layout/forms/test/test_bug572649.html new file mode 100644 index 000000000..c6f00f3bb --- /dev/null +++ b/layout/forms/test/test_bug572649.html @@ -0,0 +1,64 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=572649 +--> +<head> + <title>Test for Bug 572649</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=572649">Mozilla Bug 572649</a> +<p id="display"> + <textarea id="area" rows="5"> + Here + is + some + very + long + text + that + we're + using + for + testing + purposes + </textarea> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 572649 **/ +SimpleTest.waitForExplicitFinish(); + +// We intermittently trigger two "Wrong parent style context" assertions +// on B2G emulator builds (bug XXXXXXX). The two frames that get incorrect +// style context parents are scroll bar parts in the <textarea>. +SimpleTest.expectAssertions(0, 2); + +addLoadEvent(function() { + var area = document.getElementById("area"); + + is(area.scrollTop, 0, "The textarea should not be scrolled initially"); + area.addEventListener("focus", function() { + area.removeEventListener("focus", arguments.callee, false); + setTimeout(function() { + is(area.scrollTop, 0, "The textarea's insertion point should not be scrolled into view"); + + SimpleTest.finish(); + }, 0); + }, false); + setTimeout(function() { + var rect = area.getBoundingClientRect(); + synthesizeMouse(area, rect.width - 5, 5, {}); + }, 0); +}); +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug595310.html b/layout/forms/test/test_bug595310.html new file mode 100644 index 000000000..295da1170 --- /dev/null +++ b/layout/forms/test/test_bug595310.html @@ -0,0 +1,69 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=595310 +--> +<head> + <title>Test for Bug 595310</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.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=595310">Mozilla Bug 595310</a> +<p id="display"></p> +<div id="content"> + <input id='i' value="bar"> + <textarea id='t'>bar</textarea> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 595310 **/ + +SimpleTest.waitForExplicitFinish(); + +addLoadEvent(function() { + // We want to compare to value="bar" and no placeholder shown. + // That is what is currently showed. + var s1 = snapshotWindow(window, false); + + var content = document.getElementById('content'); + var i = document.getElementById('i'); + var t = SpecialPowers.wrap(document.getElementById('t')); + i.value = ""; i.placeholder = "foo"; + t.value = ""; t.placeholder = "foo"; + + // Flushing. + // Note: one call would have been enough actually but I didn't want to favour + // one element... ;) + i.getBoundingClientRect(); + t.getBoundingClientRect(); + + function synthesizeDropText(aElement, aText) + { + var editor = SpecialPowers.wrap(aElement) + .QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement) + .editor + .QueryInterface(SpecialPowers.Ci.nsIPlaintextEditor); + + editor.insertText(aText); + } + + // We insert "bar" and we should only see "bar" now. + synthesizeDropText(i, "bar"); + synthesizeDropText(t, "bar"); + + var s2 = snapshotWindow(window, false); + + ok(compareSnapshots(s1, s2, true)[0], + "When setting the value, the placeholder should disappear."); + + SimpleTest.finish(); +}); + + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug620936.html b/layout/forms/test/test_bug620936.html new file mode 100644 index 000000000..5f02129ac --- /dev/null +++ b/layout/forms/test/test_bug620936.html @@ -0,0 +1,35 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=620936 +--> +<head> + <title>Test for Bug 620936</title> + <script type="application/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=620936">Mozilla Bug 620936</a> +<p id="display"></p> +<div id="content"> + <input value="foo"> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 620936 **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var i = document.querySelector("input"); + i.focus(); + i.setSelectionRange(100, 100); + is(i.selectionStart, 3, "The selection should be set to the end of the text"); + is(i.selectionEnd, 3, "The selection should be set to the end of the text"); + SimpleTest.finish(); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug644542.html b/layout/forms/test/test_bug644542.html new file mode 100644 index 000000000..dca37c390 --- /dev/null +++ b/layout/forms/test/test_bug644542.html @@ -0,0 +1,63 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=644542 +--> +<head> + <title>Test for Bug 644542</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"/> + <style type="text/css"> + select:after { + content: ' appended string'; + } + </style> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=644542">Mozilla Bug 644542</a> +<p id="display"> + <form method="post" action=""> + <select id="select"> + <option value="1">1</option> + <option value="2">2</option> + </select> + </form> +</p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 644542 **/ + +var select = document.getElementById("select"); + +var clicks = 0; + +function click() { + synthesizeMouseAtCenter(select, { }); + ++clicks; + + // At least two clicks were required for bug 644542, sometimes more; + // delay is long enough that this doesn't look like a double + // click, and also allows time for popup to show and for painting. + setTimeout(clicks < 4 ? click : done, 500); +} + +function done() { + ok(true, "No crash on opening dropdown"); + SimpleTest.finish(); +} + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); +// waitForFocus is most likely not the right thing to wait for, but +// without this the first click is ineffective (even with a reflow forced +// before synthesizeMouse). +SimpleTest.waitForFocus(click); +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug665540.html b/layout/forms/test/test_bug665540.html new file mode 100644 index 000000000..51f8f568a --- /dev/null +++ b/layout/forms/test/test_bug665540.html @@ -0,0 +1,118 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=665540 +--> +<head> + <title>Test for Bug 665540 Select dropdown position in fullscreen window</title> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> +</head> +<body onload="openFullscreenWindow()"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=665540">Mozilla Bug 665540</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 665540 **/ + +SimpleTest.waitForExplicitFinish(); + +var win; +var select; +var optiona; +var eventType = "mouseover"; +var timeoutID; +var eventOffsetX = 2; +var eventOffsetY = 2; + +function openFullscreenWindow() { + win = open("bug665540_window.xul", "_blank", "resizable=yes,chrome"); + win.addEventListener("sizemodechange", + function() { + info("sizemodechange. windowState = " + win.windowState + " fullScreen = " + win.fullScreen); + }, false); + win.addEventListener("fullscreen", + function() { + info("fullscreen event. windowState = " + win.windowState + " fullScreen = " + win.fullScreen); + }, false); + info("win.windowState = " + win.windowState); + info("win.fullScreen = " + win.fullScreen); + + // Close our window if the test times out so that it doesn't interfere + // with later tests. + timeoutID = setTimeout(function () { + ok(false, "Test timed out."); + // Provide some time for a screenshot + setTimeout(finish, 1000); + }, 20000); +} + +function childFocused() { + ok(win.fullScreen, "window should be fullscreen"); + is(win.windowState, win.STATE_FULLSCREEN, + "window state should be fullscreen"); + + // The select doesn't open if the mouse click is fired too soon + // (on X11 at least). + setTimeout(openSelect, 1000); +} + +function openSelect() { + select = win.document.getElementById("select"); + synthesizeMouseAtCenter(select, {}, win); + // A yield was required on X11 tinderbox machines. + // (Wasn't required on other platforms nor on an X11 system with kwin.) + setTimeout(checkPosition, 1000); +} + +function checkPosition() { + optiona = win.document.getElementById("optiona"); + optiona.addEventListener(eventType, eventReceived, false); + + // If the select dropdown is opened in the position where + // getBoundingClientRect() predicts, then optiona will receive the event. + // The event is received asynchronously (I don't know why), so the handler + // is removed later. + synthesizeMouse(optiona, eventOffsetX, eventOffsetY, + { type: eventType }, win); +} + +function eventReceived(event) { + clearTimeout(timeoutID); + optiona.removeEventListener(eventType, eventReceived, false); + + var rect = optiona.getBoundingClientRect(); + + // Note that fullscreen only fully covers one monitor, so win.screenX can + // be non-zero. + is(event.screenX, win.screenX + rect.left + eventOffsetX, + "event.screenX should match sent event"); + is(event.screenY, win.screenY + rect.top + eventOffsetY, + "event.screenY should match sent event"); + + finish(); +} + +function finish() { + if (select && navigator.platform.indexOf("Win") >= 0) { + todo(false, + "Should not have to close select before closing its window"); + // This avoids mochitest "Unable to restore focus" errors (bug 670053). + synthesizeMouseAtCenter(select, {}, win); + } + + is(win.windowState, win.STATE_FULLSCREEN, + "window state should still be fullscreen"); + + win.close(); + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug672810.html b/layout/forms/test/test_bug672810.html new file mode 100644 index 000000000..4a3f74134 --- /dev/null +++ b/layout/forms/test/test_bug672810.html @@ -0,0 +1,120 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=672810 +--> +<head> + <title>Test for Bug 672810</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=672810">Mozilla Bug 672810</a> +<p id="display"></p> +<div id="content"> + <select id="s1" multiple size="10"><option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x</select> + <select id="s2" size="10"><option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x</select> + <select id="s3" size="1"><option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x<option>x</select> +</div> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 672810 **/ + +SimpleTest.waitForExplicitFinish(); + +SimpleTest.waitForFocus(function() { + var sel = document.getElementsByTagName('select'); + + sel[0].addEventListener('focus', function() { + s = sel[0]; + s.removeEventListener('focus', arguments.callee, false); + synthesizeKey('VK_DOWN', {}); + is(s.selectedIndex,0, s.id + ": initial DOWN selects first option"); + synthesizeKey('VK_DOWN', {ctrlKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": CTRL+DOWN did not select 2nd option"); + synthesizeKey('VK_DOWN', {ctrlKey: true}); + synthesizeKey('VK_DOWN', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": 2nd option is still unselected"); + ok(s[2].selected,s.id + ": 3rd option is selected"); + ok(s[3].selected,s.id + ": 4th option is selected"); + ok(!s[4].selected,s.id + ": 5th option is unselected"); + synthesizeKey('VK_DOWN', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": 2nd option is still unselected"); + ok(s[2].selected,s.id + ": 3rd option is still selected"); + ok(s[3].selected,s.id + ": 4th option is still selected"); + ok(s[4].selected,s.id + ": 5th option is selected"); + ok(!s[5].selected,s.id + ": 6th option is unselected"); + synthesizeKey('VK_UP', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": 2nd option is still unselected"); + ok(s[2].selected,s.id + ": 3rd option is still selected"); + ok(s[3].selected,s.id + ": 4th option is still selected"); + ok(s[4].selected,s.id + ": 5th option is still selected"); + ok(!s[5].selected,s.id + ": 6th option is still unselected"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": 2nd option is still unselected"); + ok(s[2].selected,s.id + ": 3rd option is still selected"); + ok(!s[3].selected,s.id + ": 4th option is unselected"); + ok(s[4].selected,s.id + ": 5th option is still selected"); + ok(!s[5].selected,s.id + ": 6th option is still unselected"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,0, s.id + ": first option is still selected"); + ok(!s[1].selected,s.id + ": 2nd option is still unselected"); + ok(s[2].selected,s.id + ": 3rd option is still selected"); + ok(s[3].selected,s.id + ": 4th option is selected"); + ok(s[4].selected,s.id + ": 5th option is still selected"); + ok(!s[5].selected,s.id + ": 6th option is still unselected"); + setTimeout(function(){sel[1].focus()},0); + }, false); + sel[1].addEventListener('focus', function() { + s = sel[1]; + s.removeEventListener('focus', arguments.callee, false); + synthesizeKey('VK_DOWN', {}); + is(s.selectedIndex,0, s.id + ": initial DOWN selects first option"); + synthesizeKey('VK_DOWN', {ctrlKey: true}); + is(s.selectedIndex,1, s.id + ": 2nd option is selected"); + ok(!s[0].selected,s.id + ": CTRL+DOWN deselected first option"); + synthesizeKey('VK_DOWN', {ctrlKey: true}); + synthesizeKey('VK_DOWN', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is selected"); + ok(!s[1].selected,s.id + ": CTRL+SHIFT+DOWN deselected 2nd option"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is still selected"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is still selected"); + setTimeout(function(){sel[2].focus()},0); + }, false); + sel[2].addEventListener('focus', function() { + if (navigator.platform.indexOf("Mac") == -1) { + s = sel[2]; + s.removeEventListener('focus', arguments.callee, false); + synthesizeKey('VK_DOWN', {}); + is(s.selectedIndex,1, s.id + ": initial DOWN selects 2nd option"); + synthesizeKey('VK_DOWN', {ctrlKey: true}); + is(s.selectedIndex,2, s.id + ": 3rd option is selected"); + ok(!s[1].selected,s.id + ": CTRL+DOWN deselected 2nd option"); + synthesizeKey('VK_DOWN', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is selected"); + ok(!s[2].selected,s.id + ": CTRL+SHIFT+DOWN deselected 3rd option"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is still selected"); + synthesizeKey(' ', {ctrlKey: true, shiftKey: true}); + is(s.selectedIndex,3, s.id + ": 4th option is still selected"); + } else { + todo(false, "Make this test work on OSX"); + } + setTimeout(function(){SimpleTest.finish()},0); + }, false); + sel[0].focus(); +}); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug704049.html b/layout/forms/test/test_bug704049.html new file mode 100644 index 000000000..a779abfcd --- /dev/null +++ b/layout/forms/test/test_bug704049.html @@ -0,0 +1,50 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=704049 +--> +<head> + <title>Test for Bug 704049</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=704049">Mozilla Bug 704049</a> +<p id="display"></p> +<input type="radio" id="radio11" name="group1"> +<input type="radio" id="radio12" name="group1"> +<input type="radio" id="radio21" name="group2" checked> +<input type="radio" id="radio22" name="group2"> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 704049 **/ + +window.addEventListener("click", function (e) { e.preventDefault(); }, false); + +function doTest() +{ + var target = document.getElementById("radio11"); + synthesizeMouseAtCenter(target, {}); + is(target.checked, false, "radio11 is checked"); + target = document.getElementById("radio12"); + synthesizeMouseAtCenter(target, {}); + is(target.checked, false, "radio12 is checked"); + target = document.getElementById("radio21"); + synthesizeMouseAtCenter(target, {}); + is(target.checked, true, "radio21 is not checked"); + target = document.getElementById("radio22"); + synthesizeMouseAtCenter(target, {}); + is(target.checked, false, "radio22 is checked"); + + SimpleTest.finish(); +} + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(doTest); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug717878_input_scroll.html b/layout/forms/test/test_bug717878_input_scroll.html new file mode 100644 index 000000000..89b431b34 --- /dev/null +++ b/layout/forms/test/test_bug717878_input_scroll.html @@ -0,0 +1,82 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=717878 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 717878</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=717878">Mozilla Bug 717878</a> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<!-- size=10 and monospace font ensure there's no overflow in either direction --> +<input id="no-overflow" type="text" + size="10" + style=" + font-family: monospace; + font-size: 1em;" + value="Short"> +<!-- size=10, monospace font, and height=0.5em ensure overflow in both directions --> +<input id="overflow" type="text" + size="10" + style=" + font-family: monospace; + font-size: 1em; + height: 0.5em;" + value="This is a long string"> +<pre id="test"> +<script type="application/javascript"> + +/** Test for Bug 717878 **/ + +/** + * Test an element's scroll properties for correctness + * + * @param element Element to test + * @param prop Specify the property to test, + * i.e. "scrollLeft" or "scrollTop" + * @param propMax Specify the scrollMax property to test, + * i.e. "scrollLeftMax" or "scrollTopMax" + * @param is_overflow Specify whether the element is + * scrollable in the above direction + */ +function test_scroll(element, scroll, scrollMax, is_overflow) { + + is(element[scroll], 0, element.id + " initial " + scroll + " != 0"); + if (is_overflow) { + isnot(element[scrollMax], 0, element.id + " " + scrollMax + " == 0"); + } else { + is(element[scrollMax], 0, element.id + " " + scrollMax + " != 0"); + } + + element[scroll] = 10; + if (is_overflow) { + isnot(element[scroll], 0, element.id + " unable to scroll " + scroll); + } else { + is(element[scroll], 0, element.id + " able to scroll " + scroll); + } + + element[scroll] = element[scrollMax]; + is(element[scroll], element[scrollMax], element.id + " did not scroll to " + scrollMax); + + element[scroll] = element[scrollMax] + 10; + is(element[scroll], element[scrollMax], element.id + " scrolled past " + scrollMax); +} + +var no_overflow = document.getElementById("no-overflow"); +test_scroll(no_overflow, "scrollLeft", "scrollLeftMax", /* is_overflow */ false); +test_scroll(no_overflow, "scrollTop", "scrollTopMax", /* is_overflow */ false); + +var overflow = document.getElementById("overflow"); +test_scroll(overflow, "scrollLeft", "scrollLeftMax", /* is_overflow */ true); +test_scroll(overflow, "scrollTop", "scrollTopMax", /* is_overflow */ true); + +</script> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug869314.html b/layout/forms/test/test_bug869314.html new file mode 100644 index 000000000..9116884d6 --- /dev/null +++ b/layout/forms/test/test_bug869314.html @@ -0,0 +1,54 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=869314 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 869314</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <style type="text/css"> + .selectbox { + background-color: #00FF00; + } + </style> + +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=869314">Mozilla Bug 869314</a> +<p id="display"></p> +<div id="content"> + + <select id="selectbox1" name="non-native selectbox" class="selectbox"> + <option value="item">test item</option> + </select> + + <select id="selectbox2" name="native selectbox"> + <option value="item">test item</option> + </select> + + <script type="application/javascript"> + var Cc = SpecialPowers.Cc; + var Ci = SpecialPowers.Ci; + var sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); + var osName = sysInfo.getProperty("name"); + if (osName == "Darwin") { // Mac OS X. + // This test is for Mac only. See bug for more info. + ok(document.getElementById("selectbox1").clientWidth > + document.getElementById("selectbox2").clientWidth, + "Non-native styled combobox does not have enough space for a " + + "dropmarker!"); + } else { + // We need to call at least one test function to make the test harness + // happy. + ok(true, "Test wasn't ignored but should have been."); + } + </script> + +</div> +<pre id="test"> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_bug903715.html b/layout/forms/test/test_bug903715.html new file mode 100644 index 000000000..37d49762e --- /dev/null +++ b/layout/forms/test/test_bug903715.html @@ -0,0 +1,81 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=903715 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 903715</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=903715">Mozilla Bug 903715</a> +<p id="display"></p> +<div id="content"> + <form id="form" action="/"> + <select id="select" name="select"> + <option>1</option> + <option>2</option> + <option>3</option> + <option>4</option> + <option>5</option> + <option>6</option> + <option>7</option> + <option>8</option> + <option>9</option> + </select> + <input id="input-text" name="text" value="some text"> + <input id="input-submit" type="submit"> + </form> +</div> +<pre id="test"> +</pre> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); +SimpleTest.waitForFocus(runTests, window); + +function runTests() +{ + var form = document.getElementById("form"); + form.addEventListener("keypress", function (aEvent) { + ok(false, "keypress event shouldn't be fired when the preceding keydown event caused closing the dropdown of the select element"); + }, true); + form.addEventListener("submit", function (aEvent) { + ok(false, "submit shouldn't be performed by the Enter key press on the select element"); + aEvent.preventDefault(); + }, true); + var select = document.getElementById("select"); + select.addEventListener("change", function (aEvent) { + var input = document.getElementById("input-text"); + input.focus(); + input.select(); + }, false); + + select.focus(); + + select.addEventListener("popupshowing", function (aEvent) { + setTimeout(function () { + synthesizeKey("VK_DOWN", { }); + select.addEventListener("popuphiding", function (aEvent) { + setTimeout(function () { + // Enter key should cause closing the dropdown of the select element + // and keypress event shouldn't be fired on the input element because + // which shouldn't cause sumbmitting the form contents. + ok(true, "Test passes if there is no error"); + SimpleTest.finish(); + }, 100); + }, false); + // Close dropdown. + synthesizeKey("VK_RETURN", { }); + }, 100); + }, false); + + // Open dropdown. + synthesizeKey("VK_DOWN", { altKey: true }); +} +</script> +</body> +</html> diff --git a/layout/forms/test/test_bug935876.html b/layout/forms/test/test_bug935876.html new file mode 100644 index 000000000..bb4090211 --- /dev/null +++ b/layout/forms/test/test_bug935876.html @@ -0,0 +1,495 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=935876 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 935876</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=935876">Mozilla Bug 935876</a> +<p id="display"></p> +<div> +<select id="listbox" size="3"> + <option selected>1</option> + <option>2</option> + <option>3</option> + <option>4</option> + <option>5</option> + <option>6</option> + <option>7</option> +</select> +<select id="multipleListbox" size="3" multiple> + <option selected>1</option> + <option>2</option> + <option>3</option> + <option>4</option> + <option>5</option> + <option>6</option> + <option>7</option> +</select> +<select id="combobox"> + <option selected>1</option> + <option>2</option> + <option>3</option> + <option>4</option> + <option>5</option> + <option>6</option> + <option>7</option> +</select> +</div> +<pre id="test"> +</pre> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); + +const kIsWin = navigator.platform.indexOf("Win") == 0; +const kIsMac = navigator.platform.indexOf("Mac") == 0; +const kIsAndroid = navigator.appVersion.indexOf("Android") != 0; + +function runTests() +{ + var doPreventDefault = false; + function onKeydown(aEvent) + { + if (doPreventDefault) { + aEvent.preventDefault(); + } + } + + var keyPressEventFired = false; + function onKeypress(aEvent) + { + keyPressEventFired = true; + } + + var keyDownEventConsumedByJS = false; + var keyDownEventConsumed = false; + function onkeydownInSystemEventGroup(aEvent) + { + keyDownEventConsumedByJS = aEvent.defaultPrevented; + keyDownEventConsumed = aEvent.getPreventDefault(); + } + + function reset() + { + keyPressEventFired = false; + keyDownEventConsumedByJS = false; + keyDownEventConsumed = false; + } + + function check(aExpectingKeydownConsumed, aDescription) + { + if (doPreventDefault) { + ok(!keyPressEventFired, "keypress event shouldn't be fired for " + aDescription + + " if preventDefault() of keydown event was called"); + ok(keyDownEventConsumedByJS, "keydown event of " + aDescription + + " should be consumed in content level if preventDefault() of keydown event is called"); + ok(keyDownEventConsumed, "keydown event of " + aDescription + + " should be consumed in system level if preventDefault() of keydown event is called"); + } else if (aExpectingKeydownConsumed) { + ok(!keyPressEventFired, "keypress event shouldn't be fired for " + aDescription); + ok(!keyDownEventConsumedByJS, "keydown event of " + aDescription + " shouldn't be consumed in content level"); + ok(keyDownEventConsumed, "keydown event of " + aDescription + " should be consumed in system level"); + } else { + ok(keyPressEventFired, "keypress event should be fired for " + aDescription); + ok(!keyDownEventConsumedByJS, "keydown event of " + aDescription + " shouldn't be consumed in content level"); + ok(!keyDownEventConsumed, "keydown event of " + aDescription + " should be consumed in system level"); + } + } + + var listbox = document.getElementById("listbox"); + listbox.addEventListener("keydown", onKeydown, false); + listbox.addEventListener("keypress", onKeypress, false); + SpecialPowers.addSystemEventListener(listbox, "keydown", onkeydownInSystemEventGroup, false); + + listbox.focus(); + + [ false, true ].forEach(function (consume) { + doPreventDefault = consume; + for (var i = 0; i < listbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_DOWN", {}); + check(true, "DownArrow key on listbox #" + i); + } + + for (var i = 0; i < listbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_UP", {}); + check(true, "UpArrow key on listbox #" + i); + } + + for (var i = 0; i < listbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_RIGHT", {}); + check(true, "RightArrow key on listbox #" + i); + } + + for (var i = 0; i < listbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_LEFT", {}); + check(true, "LeftArrow key on listbox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_DOWN", {}); + check(true, "PageDown key on listbox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_UP", {}); + check(true, "PageUp key on listbox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_END", {}); + check(true, "End key on listbox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_HOME", {}); + check(true, "Home key on listbox #" + i); + } + + reset() + synthesizeKey("VK_RETURN", {}); + check(false, "Enter key on listbox"); + + reset() + synthesizeKey("VK_ESCAPE", {}); + check(false, "Esc key on listbox"); + + reset() + synthesizeKey("VK_F4", {}); + check(false, "F4 key on listbox"); + + reset() + synthesizeKey("a", {}); + check(false, "'A' key on listbox"); + }); + + listbox.removeEventListener("keydown", onKeydown, false); + listbox.removeEventListener("keypress", onKeypress, false); + SpecialPowers.removeSystemEventListener(listbox, "keydown", onkeydownInSystemEventGroup, false); + + + + var multipleListbox = document.getElementById("multipleListbox"); + multipleListbox.addEventListener("keydown", onKeydown, false); + multipleListbox.addEventListener("keypress", onKeypress, false); + SpecialPowers.addSystemEventListener(multipleListbox, "keydown", onkeydownInSystemEventGroup, false); + + multipleListbox.focus(); + + [ false, true ].forEach(function (consume) { + doPreventDefault = consume; + for (var i = 0; i < multipleListbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_DOWN", {}); + check(true, "DownArrow key on multiple listbox #" + i); + } + + for (var i = 0; i < multipleListbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_UP", {}); + check(true, "UpArrow key on multiple listbox #" + i); + } + + for (var i = 0; i < multipleListbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_RIGHT", {}); + check(true, "RightArrow key on multiple listbox #" + i); + } + + for (var i = 0; i < multipleListbox.options.length + 1; i++) { + reset() + synthesizeKey("VK_LEFT", {}); + check(true, "LeftArrow key on multiple listbox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_DOWN", {}); + check(true, "PageDown key on multiple listbox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_UP", {}); + check(true, "PageUp key on multiple listbox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_END", {}); + check(true, "End key on multiple listbox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_HOME", {}); + check(true, "Home key on multiple listbox #" + i); + } + + reset() + synthesizeKey("VK_RETURN", {}); + check(true, "Enter key on multiple listbox"); + + reset() + synthesizeKey("VK_ESCAPE", {}); + check(false, "Esc key on multiple listbox"); + + reset() + synthesizeKey("VK_F4", {}); + check(false, "F4 key on multiple listbox"); + + reset() + synthesizeKey("a", {}); + check(false, "'A' key on multiple listbox"); + }); + + multipleListbox.removeEventListener("keydown", onKeydown, false); + multipleListbox.removeEventListener("keypress", onKeypress, false); + SpecialPowers.removeSystemEventListener(multipleListbox, "keydown", onkeydownInSystemEventGroup, false); + + + + var combobox = document.getElementById("combobox"); + combobox.addEventListener("keydown", onKeydown, false); + combobox.addEventListener("keypress", onKeypress, false); + SpecialPowers.addSystemEventListener(combobox, "keydown", onkeydownInSystemEventGroup, false); + + combobox.focus(); + + [ false, true ].forEach(function (consume) { + doPreventDefault = consume; + if (!kIsMac) { + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_DOWN", {}); + check(true, "DownArrow key on combobox #" + i); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_UP", {}); + check(true, "UpArrow key on combobox #" + i); + } + } else { + todo(false, "Make this test work on OSX"); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_RIGHT", {}); + check(true, "RightArrow key on combobox #" + i); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_LEFT", {}); + check(true, "LeftArrow key on combobox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_DOWN", {}); + check(true, "PageDown key on combobox #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_UP", {}); + check(true, "PageUp key on combobox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_END", {}); + check(true, "End key on combobox #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_HOME", {}); + check(true, "Home key on combobox #" + i); + } + + reset() + synthesizeKey("VK_RETURN", {}); + check(false, "Enter key on combobox"); + + reset() + synthesizeKey("VK_ESCAPE", {}); + check(true, "Esc key on combobox"); + + if (!kIsWin) { + reset() + synthesizeKey("VK_F4", {}); + check(false, "F4 key on combobox"); + } + + reset() + synthesizeKey("a", {}); + check(false, "'A' key on combobox"); + }); + + function finish() + { + combobox.removeEventListener("keydown", onKeydown, false); + combobox.removeEventListener("keypress", onKeypress, false); + SpecialPowers.removeSystemEventListener(combobox, "keydown", onkeydownInSystemEventGroup, false); + SimpleTest.finish(); + } + + // Mac uses native popup for dropdown. Let's skip the tests for popup + // since it's not handled in nsListControlFrame. + // Similarly, Android doesn't use popup for dropdown. + if (kIsMac || kIsAndroid) { + finish(); + return; + } + + function testDropDown(aCallback) + { + testOpenDropDown(function () { + reset() + synthesizeKey("VK_DOWN", { altKey: true }); + }, function () { + check(true, "Alt + DownArrow key on combobox at opening dropdown"); + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_DOWN", {}); + check(true, "DownArrow key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_UP", {}); + check(true, "UpArrow key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_RIGHT", {}); + check(true, "RightArrow key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < combobox.options.length + 1; i++) { + reset() + synthesizeKey("VK_LEFT", {}); + check(true, "LeftArrow key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_DOWN", {}); + check(true, "PageDown key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < 4; i++) { + reset() + synthesizeKey("VK_PAGE_UP", {}); + check(true, "PageUp key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_END", {}); + check(true, "End key on combobox during dropdown open #" + i); + } + + for (var i = 0; i < 2; i++) { + reset() + synthesizeKey("VK_HOME", {}); + check(true, "Home key on combobox during dropdown open #" + i); + } + + testCloseDropDown(function () { + reset() + synthesizeKey("VK_RETURN", {}); + }, function () { + testOpenDropDown(function () { + check(true, "Enter key on combobox at closing dropdown"); + + synthesizeKey("VK_UP", { altKey: true }); + }, function () { + check(true, "Alt + UpArrow key on combobox at opening dropdown"); + + testCloseDropDown(function () { + reset() + synthesizeKey("VK_ESCAPE", {}); + }, function () { + check(true, "Esc key on combobox at closing dropdown"); + + // F4 key opens/closes dropdown only on Windows. So, other platforms + // don't need to do anymore. + if (!kIsWin) { + aCallback(); + return; + } + + testOpenDropDown(function () { + reset() + synthesizeKey("VK_F4", {}); + }, function () { + check(true, "F4 key on combobox at opening dropdown on Windows"); + + testCloseDropDown(function () { + reset() + synthesizeKey("VK_F4", {}); + }, function () { + check(true, "F4 key on combobox at closing dropdown on Windows"); + + aCallback(); + return; + }); + }); + }); + }); + }); + }); + } + + doPreventDefault = false; + testDropDown(function () { + // Even if keydown event is consumed by JS, opening/closing dropdown + // should work for a11y and security (e.g., cannot close dropdown causes + // staying top-most window on the screen). If it's blocked by JS, this + // test would cause permanent timeout. + doPreventDefault = true; + testDropDown(finish); + }); +} + +function testOpenDropDown(aTest, aOnOpenDropDown) +{ + document.addEventListener("popupshowing", function (aEvent) { + document.removeEventListener(aEvent.type, arguments.callee, false); + setTimeout(aOnOpenDropDown, 0); + }, false); + aTest(); +} + +function testCloseDropDown(aTest, aOnCloseDropDown) +{ + document.addEventListener("popuphiding", function (aEvent) { + document.removeEventListener(aEvent.type, arguments.callee, false); + setTimeout(aOnCloseDropDown, 0) + }, false); + aTest(); +} + +SimpleTest.waitForFocus(runTests); +</script> +</body> +</html> diff --git a/layout/forms/test/test_bug957562.html b/layout/forms/test/test_bug957562.html new file mode 100644 index 000000000..6c52dc5e0 --- /dev/null +++ b/layout/forms/test/test_bug957562.html @@ -0,0 +1,43 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=957562 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 903715</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=957562">Mozilla Bug 957562</a> +<p id="display"></p> +<input id="n" onfocus="kill()" type="number" style="border:20px solid black"> +<pre id="test"> +</pre> +<script type="application/javascript"> +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(runTests, window); + +var killed = false; +function kill() { + if (killed) { + return; + } + killed = true; + n.style.display = 'none'; + r = n.getBoundingClientRect(); + setTimeout(function() { + ok(true, "Didn't crash"); + SimpleTest.finish(); + }, 0); +} + +function runTests() +{ + synthesizeMouse(n, 2, 2, {}); +} +</script> +</body> +</html> diff --git a/layout/forms/test/test_bug960277.html b/layout/forms/test/test_bug960277.html new file mode 100644 index 000000000..d95e0f7cb --- /dev/null +++ b/layout/forms/test/test_bug960277.html @@ -0,0 +1,29 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=960277 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 903715</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=960277">Mozilla Bug 960277</a> +<p id="display"></p> +<fieldset style="position:relative; height:100px; margin:50px; background:blue;"> +<legend style="background:purple"> + <div id="d" style="position:absolute; background:yellow; top:0; left:0; width:50px; height:50px;"></div> +</legend> +</fieldset> +<pre id="test"> +</pre> +<script type="application/javascript"> +var rect = d.getBoundingClientRect(); +is(document.elementFromPoint(rect.left + 10, rect.top + 10), d, + "Hit testing yellow div"); +</script> +</body> +</html> diff --git a/layout/forms/test/test_bug961363.html b/layout/forms/test/test_bug961363.html new file mode 100644 index 000000000..a3c45cd9a --- /dev/null +++ b/layout/forms/test/test_bug961363.html @@ -0,0 +1,96 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=961363 +--> +<head> +<meta charset="utf-8"> +<title>Test for Bug 961363</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"/> +<script type="application/javascript"> + /** Test for Bug 961363 **/ + + SimpleTest.waitForExplicitFinish(); + + function test() { + + SimpleTest.waitForFocus(function() { + var one = [{k:"DOWN",s:[false,true,true,false]}, {k:"UP",s:[false,false,true,false]}, + {k:"RIGHT",s:[false,false,false,false]}, {k:"LEFT",s:[false,true,false,false]}, + {k:"PAGE_DOWN",s:[false,true,false,true]}, {k:"PAGE_UP",s:[false,false,false,true]}, + {k:"END",s:[false,false,false,false]}, {k:"HOME",s:[true,false,false,false]} ]; + var two_1 = [{k:"DOWN",s:[false,false,true,false]}, {k:"UP",s:[false,true,false,false]}, + {k:"RIGHT",s:[false,false,true,false]}, {k:"LEFT",s:[false,true,false,false]}, + {k:"END",s:[false,false,false,true]}, {k:"HOME",s:[true,false,false,false]} ]; + var two_2 = [{k:"PAGE_DOWN",s:[true,false,false,false]}, {k:"PAGE_UP",s:[true,false,false,false]}]; + var three_1 = [{k:"DOWN",s:[false,false,true,false]}, {k:"UP",s:[false,true,false,false]}, + {k:"RIGHT",s:[false,false,true,false]}, {k:"LEFT",s:[false,true,false,false]}, + {k:"END",s:[false,false,false,true]}, {k:"HOME",s:[true,false,false,false]} ]; + var three_2 = [{k:"PAGE_DOWN",s:[true,false,false,false]}, {k:"PAGE_UP",s:[true,false,false,false]} ]; + + function select_test(id, tests, ctrl_change) { + var element = document.getElementById(id); + element.focus(); + var previousValue = element.value; + tests.forEach(function(data) { + var key = data.k; + synthesizeKey("VK_"+key, { shiftKey:false, metaKey:false, ctrlKey:true }); + (ctrl_change ? isnot : is)(element.value, previousValue, "value should " + + (ctrl_change?"":"not ") + "have changed while testing CTRL+key " + key + " (id: " + id + ")"); + previousValue = element.value; + synthesizeKey(" ", { shiftKey:false, metaKey:false, ctrlKey:true }); + var sel = Array.prototype.slice.call(element.options).map(function(o){return o.selected}) + is(""+sel, ""+data.s, "selected options match after CTRL+SPACE (after testing CTRL+key " + key + ") for (id: " + id + ")"); + previousValue = element.value; + }); + }; + select_test("one", one, false); + select_test("two", two_1, true); + select_test("two", two_2, false); + if (navigator.platform.indexOf("Mac") == -1) { + select_test("three", three_1, true); + select_test("three", three_2, false); + } else { + todo(false, "Make these tests work on OSX"); + } + SimpleTest.finish(); + }); + } +</script> +</head> +<body onload="test();"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=961363">Mozilla Bug 961363</a> +<div> + <ul> + <li> + <select id="one" multiple size="3"> + <option>0</option> + <option selected>1</option> + <option>2</option> + <option>3</option> + </select> + </li> + <li> + <select id="two" size="3"> + <option>0</option> + <option selected>1</option> + <option>2</option> + <option>3</option> + </select> + </li> + <li> + <select id="three" size="1"> + <option>0</option> + <option selected>1</option> + <option>2</option> + <option>3</option> + </select> + </li> + </ul> +</div> +<pre id="test"> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_listcontrol_search.html b/layout/forms/test/test_listcontrol_search.html new file mode 100644 index 000000000..7f73c5f75 --- /dev/null +++ b/layout/forms/test/test_listcontrol_search.html @@ -0,0 +1,46 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=849438 +--> +<head> + <meta charset="utf-8"> + <title>Test for <select> list control search</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"/> + <script type="application/javascript"> + + /** This test will focus a select element and press a key that matches the + first non-space character of an entry. **/ + + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(function() { + var select = document.getElementsByTagName('select')[0]; + select.focus(); + synthesizeKey('a', {}); + + is(select.options[0].selected, false, "the first option isn't selected"); + is(select.options[1].selected, true, "the second option is selected"); + + select.blur(); + + SimpleTest.finish(); + }); + + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=849438">Mozilla Bug 849438</a> +<p id="display"></p> +<div id="content"> + <select> + <option>Please select an entry</option> + <option> a</option> + <option> b</option> + </select> +</div> +<pre id="test"> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_select_prevent_default.html b/layout/forms/test/test_select_prevent_default.html new file mode 100644 index 000000000..85066e3c2 --- /dev/null +++ b/layout/forms/test/test_select_prevent_default.html @@ -0,0 +1,119 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=291082 +--> +<head> +<meta charset="utf-8"> +<title>Test for Bug 291082</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"/> +<script type="application/javascript"> + /** Test for Bug 291082 **/ + + + SimpleTest.waitForExplicitFinish(); + + function preventDefault(event) { + event.preventDefault(); + } + + function test() { + // Turn off Spatial Navigation because it hijacks arrow keydown events. + SpecialPowers.pushPrefEnv({"set":[["snav.enabled", false]]}, runTest); + } + + function runTest() { + document.getElementById("keydown").addEventListener("keydown", preventDefault); + document.getElementById("keypress").addEventListener("keypress", preventDefault); + + SimpleTest.waitForFocus(function() { + if (navigator.platform.indexOf("Mac") == 0) { + todo(false, "Make this test work on OSX"); + SimpleTest.finish(); + return; + } + var testData = [ "one", "two", "three", "four", "keydown", "keypress" ]; + + // The order of the keys in otherKeys is important for the test to function properly. + var otherKeys = [ "DOWN", "UP", "RIGHT", "LEFT", "PAGE_DOWN", "PAGE_UP", + "END", "HOME" ]; + + testData.forEach(function(id) { + var element = document.getElementById(id); + element.focus(); + var previousValue = element.value; + sendChar('2'); + is(element.value, previousValue, "value should not have changed (id: " + id + ")"); + previousValue = element.value; + otherKeys.forEach(function(key) { + sendKey(key); + isnot(element.value, previousValue, "value should have changed while testing key " + key + " (id: " + id + ")"); + previousValue = element.value; + }); + }); + SimpleTest.finish(); + }); + } +</script> +</head> +<body onload="test();"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=291082">Mozilla Bug 291082</a> +<div> + <ul> + <li> + <select id="one" onkeydown="event.preventDefault();"> + <option>0</option> + <option>1</option> + <option>2</option> + </select> + select onkeydown="event.preventDefault();" + </li> + <li> + <select id="two" onkeypress="event.preventDefault();"> + <option>0</option> + <option>1</option> + <option>2</option> + </select> + select onkeypress="event.preventDefault();" + </li> + <li onkeydown="event.preventDefault();"> + <select id="three"> + <option>0</option> + <option>1</option> + <option>2</option> + </select> + li onkeydown="event.preventDefault();" + </li> + <li onkeypress="event.preventDefault();"> + <select id="four"> + <option>0</option> + <option>1</option> + <option>2</option> + </select> + li onkeypress="event.preventDefault();" + </li> + <li> + <select id="keydown"> + <option>0</option> + <option>1</option> + <option>2</option> + </select> + select.addEventListener("keydown", function(event) { event.preventDefault(); }); + </li> + <li> + <select id="keypress"> + <option>0</option> + <option>1</option> + <option>2</option> + <option>9</option> + </select> + select.addEventListener("keypress", function(event) { event.preventDefault(); }); + </li> + </ul> +</div> +<pre id="test"> +</pre> +</body> +</html> diff --git a/layout/forms/test/test_select_vertical.html b/layout/forms/test/test_select_vertical.html new file mode 100644 index 000000000..570735641 --- /dev/null +++ b/layout/forms/test/test_select_vertical.html @@ -0,0 +1,75 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Test for select popup in vertical writing mode</title> +<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> +<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> +<script> +SimpleTest.waitForExplicitFinish(); + +function test() { + SimpleTest.waitForFocus(function() { + var vlr = document.getElementById("vlr"); + var selWidth = vlr.offsetWidth; + var optWidth = vlr.children[0].offsetWidth; + + // We should be able to choose options from the vertical-lr <select> + // at positions increasingly to the right of the element itself. + is(vlr.value, "1", "(vertical-lr) initial value should be 1"); + + synthesizeMouse(vlr, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vlr, selWidth + 1.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vlr.value, "2", "(vertical-lr) new value should be 2"); + + synthesizeMouse(vlr, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vlr, selWidth + 2.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vlr.value, "3", "(vertical-lr) new value should be 3"); + + synthesizeMouse(vlr, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vlr, selWidth + 0.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vlr.value, "1", "(vertical-lr) value should be back to 1"); + + var vrl = document.getElementById("vrl"); + + // We should be able to choose options from the vertical-rl <select> + // at positions increasingly to the left of the element itself. + is(vrl.value, "1", "(vertical-rl) initial value should be 1"); + + synthesizeMouse(vrl, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vrl, -1.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vrl.value, "2", "(vertical-rl) new value should be 2"); + + synthesizeMouse(vrl, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vrl, -2.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vrl.value, "3", "(vertical-rl) new value should be 3"); + + synthesizeMouse(vrl, 5, 5, { type : "mousedown", button: 0 }); + synthesizeMouse(vrl, -0.5 * optWidth, 5, { type : "mouseup", button: 0 }); + + is(vrl.value, "1", "(vertical-rl) value should be back to 1"); + + SimpleTest.finish(); + }); +} +</script> + +<body onload="test();"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1113206">Mozilla Bug 1113206</a> +<div> + <select id="vlr" style="writing-mode: vertical-lr; margin: 80px;"> + <option value="1">one + <option value="2">two + <option value="3">three + <option value="4">four + </select> + <select id="vrl" style="writing-mode: vertical-rl; margin: 80px;"> + <option value="1">one + <option value="2">two + <option value="3">three + <option value="4">four + </select> +</div> diff --git a/layout/forms/test/test_textarea_resize.html b/layout/forms/test/test_textarea_resize.html new file mode 100644 index 000000000..c71f554e0 --- /dev/null +++ b/layout/forms/test/test_textarea_resize.html @@ -0,0 +1,102 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for Bug 477700</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> +<div id="content" style="display: none"> +</div> + +<textarea id="textarea" style="-moz-appearance: none; border: 2px solid black; padding: 3px; box-sizing: border-box; min-width: 15px; min-height: 15px;">Text</textarea> + +<pre id="test"> +<script type="application/javascript"> + +/** Test for textbox resizing **/ +SimpleTest.waitForExplicitFinish(); +addLoadEvent(() => SimpleTest.executeSoon(doTheTest)); + +// -1 means use the default value which is 'both', then test explicitly +// setting each possible value. +var currentResize = -1; +var currentBoxSizing = 0; +var currentPointer = 0; +var resizeTypes = [ "horizontal", "vertical", "none", "inherit", "both" ]; +var boxSizingTypes = [ "", "border-box" ]; +var pointerTypes = [ synthesizeMouse, synthesizeTouch] + +function doTheTest() { + runTest(pointerTypes[currentPointer]); +} + +function runTest(aPointerFunc) { + var boxSizingText = " with box sizing " + (currentBoxSizing ? boxSizingTypes[currentBoxSizing] : "content-box"); + + var textarea = $("textarea"); + var rect = textarea.getBoundingClientRect(); + var touch = aPointerFunc.name.match(/Touch/); + // -1 means use the default value of resize, i.e. "both" + var type = (currentResize == -1) ? "both" : resizeTypes[currentResize]; + // assume that the resizer is in the lower right corner + + aPointerFunc(textarea, rect.width - 10, rect.height - 10, { type: touch ? "touchstart" : "mousedown" }); + aPointerFunc(textarea, rect.width + 40, rect.height + 40, { type: touch ? "touchmove" : "mousemove" }); + + var newrect = textarea.getBoundingClientRect(); + var hchange = (type == "both" || type == "horizontal"); + var vchange = (type == "both" || type == "vertical"); + + is(Math.round(newrect.width), Math.round(rect.width + (hchange ? 50 : 0)), + type + " width has increased" + boxSizingText + " using " + aPointerFunc.name); + is(Math.round(newrect.height), Math.round(rect.height + (vchange ? 50 : 0)), + type + " height has increased" + boxSizingText + " using " + aPointerFunc.name); + + aPointerFunc(textarea, rect.width - 20, rect.height - 20, { type: touch ? "touchmove" : "mousemove" }); + + newrect = textarea.getBoundingClientRect(); + + is(Math.round(newrect.width), Math.round(rect.width - (hchange ? 10 : 0)), + type + " width has decreased" + boxSizingText + " using " + aPointerFunc.name); + is(Math.round(newrect.height), Math.round(rect.height - (vchange ? 10 : 0)), + type + " height has decreased" + boxSizingText + " using " + aPointerFunc.name); + + aPointerFunc(textarea, rect.width - 220, rect.height - 220, { type: touch ? "touchmove" : "mousemove" }); + + newrect = textarea.getBoundingClientRect(); + ok(hchange ? newrect.width >= 15 : Math.round(newrect.width) == Math.round(rect.width), + type + " width decreased below minimum" + boxSizingText + " using " + newrect.width); + ok(vchange ? newrect.height >= 15 : Math.round(newrect.height) == Math.round(rect.height), + type + " height decreased below minimum" + boxSizingText + " using " + aPointerFunc.name); + + aPointerFunc(textarea, rect.width - 8, rect.height - 8, { type: touch ? "touchend" : "mouseup" }); + + textarea.style.width = "auto"; + textarea.style.height = "auto"; + + if (currentBoxSizing++ <= boxSizingTypes.length) { + textarea.style.MozBoxSizing = boxSizingTypes[currentBoxSizing]; + SimpleTest.executeSoon(doTheTest); + } else { + currentBoxSizing = 0; + if (++currentResize < resizeTypes.length) { + textarea.style.resize = resizeTypes[currentResize]; + SimpleTest.executeSoon(doTheTest); + } else { + currentResize = -1; + textarea.style.resize = ""; + if (++currentPointer < pointerTypes.length) { + SimpleTest.executeSoon(doTheTest); + } else { + SimpleTest.finish(); + } + } + } +} + +</script> +</pre> +</body> +</html> |