1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/base/tests/test_bug795785.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,175 @@ 1.4 +<html> 1.5 +<!-- 1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=795785 1.7 +--> 1.8 +<head> 1.9 + <title>Test for Bug 795785</title> 1.10 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795785">Mozilla Bug 795785</a> 1.17 +<div id="display"> 1.18 + <textarea id="textarea" style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea> 1.19 + <div id="div" contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div> 1.20 +</div> 1.21 +<div id="content" style="display: none"> 1.22 + 1.23 +</div> 1.24 +<pre id="test"> 1.25 +</pre> 1.26 + 1.27 +<script class="testbody" type="application/javascript"> 1.28 + 1.29 + 1.30 +SimpleTest.waitForExplicitFinish(); 1.31 + 1.32 +// Turn off spatial navigation because it hijacks arrow key events and VK_RETURN 1.33 +// events. 1.34 +SpecialPowers.setBoolPref("snav.enabled", false); 1.35 + 1.36 +SimpleTest.waitForFocus(runTests); 1.37 + 1.38 +var textarea = document.getElementById("textarea"); 1.39 +var div = document.getElementById("div"); 1.40 + 1.41 +function hitEventLoop(aFunc, aTimes) 1.42 +{ 1.43 + if (--aTimes) { 1.44 + setTimeout(hitEventLoop, 0, aFunc, aTimes); 1.45 + } else { 1.46 + setTimeout(aFunc, 100); 1.47 + } 1.48 +} 1.49 + 1.50 +function doKeyEventTest(aElement, aElementDescription, aCallback) 1.51 +{ 1.52 + aElement.focus(); 1.53 + aElement.scrollTop = 0; 1.54 + hitEventLoop(function () { 1.55 + is(aElement.scrollTop, 0, 1.56 + aElementDescription + "'s scrollTop isn't 0"); 1.57 + synthesizeKey("VK_RETURN", { }); 1.58 + synthesizeKey("VK_RETURN", { }); 1.59 + synthesizeKey("VK_RETURN", { }); 1.60 + synthesizeKey("VK_RETURN", { }); 1.61 + synthesizeKey("VK_RETURN", { }); 1.62 + synthesizeKey("VK_RETURN", { }); 1.63 + hitEventLoop(function () { 1.64 + isnot(aElement.scrollTop, 0, 1.65 + aElementDescription + " was not scrolled by inserting line breaks"); 1.66 + var scrollTop = aElement.scrollTop; 1.67 + synthesizeKey("VK_UP", { }); 1.68 + synthesizeKey("VK_UP", { }); 1.69 + synthesizeKey("VK_UP", { }); 1.70 + synthesizeKey("VK_UP", { }); 1.71 + synthesizeKey("VK_UP", { }); 1.72 + hitEventLoop(function () { 1.73 + isnot(aElement.scrollTop, scrollTop, 1.74 + aElementDescription + " was not scrolled by up key events"); 1.75 + synthesizeKey("VK_DOWN", { }); 1.76 + synthesizeKey("VK_DOWN", { }); 1.77 + synthesizeKey("VK_DOWN", { }); 1.78 + synthesizeKey("VK_DOWN", { }); 1.79 + synthesizeKey("VK_DOWN", { }); 1.80 + hitEventLoop(function () { 1.81 + is(aElement.scrollTop, scrollTop, 1.82 + aElementDescription + " was not scrolled by down key events"); 1.83 + var longWord = "aaaaaaaaaaaaaaaaaaaa"; 1.84 + sendString(longWord); 1.85 + hitEventLoop(function () { 1.86 + isnot(aElement.scrollLeft, 0, 1.87 + aElementDescription + " was not scrolled by typing long word"); 1.88 + var scrollLeft = aElement.scrollLeft; 1.89 + var i; 1.90 + for (i = 0; i < longWord.length; i++) { 1.91 + synthesizeKey("VK_LEFT", { }); 1.92 + } 1.93 + hitEventLoop(function () { 1.94 + isnot(aElement.scrollLeft, scrollLeft, 1.95 + aElementDescription + " was not scrolled by left key events"); 1.96 + for (i = 0; i < longWord.length; i++) { 1.97 + synthesizeKey("VK_RIGHT", { }); 1.98 + } 1.99 + hitEventLoop(function () { 1.100 + is(aElement.scrollLeft, scrollLeft, 1.101 + aElementDescription + " was not scrolled by right key events"); 1.102 + aCallback(); 1.103 + }, 20); 1.104 + }, 20); 1.105 + }, 20); 1.106 + }, 20); 1.107 + }, 20); 1.108 + }, 20); 1.109 + }, 20); 1.110 +} 1.111 + 1.112 +function doCompositionTest(aElement, aElementDescription, aCallback) 1.113 +{ 1.114 + aElement.focus(); 1.115 + aElement.scrollTop = 0; 1.116 + hitEventLoop(function () { 1.117 + is(aElement.scrollTop, 0, 1.118 + aElementDescription + "'s scrollTop isn't 0"); 1.119 + synthesizeComposition({ type: "compositionstart" }); 1.120 + var str = "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" + 1.121 + "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" + 1.122 + " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" + 1.123 + "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " + 1.124 + "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" + 1.125 + "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" + 1.126 + "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" + 1.127 + "\u304d\u307e\u3059\u3002"; 1.128 + synthesizeComposition({ type: "compositionupdate", data: str }); 1.129 + synthesizeText({ 1.130 + composition: { 1.131 + string: str, 1.132 + clauses: [ 1.133 + { length: str.length, attr: COMPOSITION_ATTR_RAWINPUT } 1.134 + ] 1.135 + }, 1.136 + caret: { start: str.length, length: 0 } 1.137 + }); 1.138 + hitEventLoop(function () { 1.139 + isnot(aElement.scrollTop, 0, 1.140 + aElementDescription + " was not scrolled by composition"); 1.141 + synthesizeComposition({ type: "compositionupdate", data: "" }); 1.142 + synthesizeText({ 1.143 + composition: { string: "", clauses: [ { length: 0, attr: 0 } ] }, 1.144 + caret: { start: 0, length: 0 } 1.145 + }); 1.146 + synthesizeComposition({ type: "compositionend", data: "" }); 1.147 + hitEventLoop(function () { 1.148 + is(aElement.scrollTop, 0, 1.149 + aElementDescription + " was not scrolled back to the top by canceling composition"); 1.150 + aCallback(); 1.151 + }, 20); 1.152 + }, 20); 1.153 + }, 20); 1.154 +} 1.155 + 1.156 +function runTests() 1.157 +{ 1.158 + doKeyEventTest(textarea, "textarea", 1.159 + function () { 1.160 + textarea.value = ""; 1.161 + doKeyEventTest(div, "div (contenteditable)", 1.162 + function () { 1.163 + div.innerHTML = ""; 1.164 + doCompositionTest(textarea, "textarea", 1.165 + function () { 1.166 + doCompositionTest(div, "div (contenteditable)", 1.167 + function () { 1.168 + SimpleTest.finish(); 1.169 + }); 1.170 + }); 1.171 + }); 1.172 + }); 1.173 +} 1.174 + 1.175 +</script> 1.176 +</body> 1.177 + 1.178 +</html>