editor/libeditor/html/tests/test_bug549262.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug549262.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=549262
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 549262</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549262">Mozilla Bug 549262</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content">
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 549262 **/
    1.24 +
    1.25 +var smoothScrollPref = "general.smoothScroll";
    1.26 +SpecialPowers.setBoolPref(smoothScrollPref, false);
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +var win = window.open("file_bug549262.html", "_blank", 
    1.29 +                      "width=600,height=600,scrollbars=yes");
    1.30 +
    1.31 +// grab the timer right at the start
    1.32 +var cwu = SpecialPowers.getDOMWindowUtils(win);
    1.33 +function step() {
    1.34 +  cwu.advanceTimeAndRefresh(100);
    1.35 +}
    1.36 +
    1.37 +SimpleTest.waitForFocus(function() {
    1.38 +  // Make sure that pressing Space when a contenteditable element is not focused
    1.39 +  // will scroll the page.
    1.40 +  var ed = win.document.getElementById("editor");
    1.41 +  var sc = win.document.querySelector("a");
    1.42 +  sc.focus();
    1.43 +  is(win.scrollY, 0, "Sanity check");
    1.44 +  synthesizeKey(" ", {}, win);
    1.45 +
    1.46 +  step();
    1.47 +
    1.48 +  isnot(win.scrollY, 0, "Page is scrolled down");
    1.49 +  is(ed.textContent, "abc", "The content of the editable element has not changed");
    1.50 +  var oldY = win.scrollY;
    1.51 +  synthesizeKey(" ", {shiftKey: true}, win);
    1.52 +
    1.53 +  step();
    1.54 +
    1.55 +  ok(win.scrollY < oldY, "Page is scrolled up");
    1.56 +  is(ed.textContent, "abc", "The content of the editable element has not changed");
    1.57 +
    1.58 +  // Make sure that pressing Space when a contenteditable element is focused
    1.59 +  // will not scroll the page, and will edit the element.
    1.60 +  ed.focus();
    1.61 +  win.getSelection().collapse(ed.firstChild, 1);
    1.62 +  oldY = win.scrollY;
    1.63 +  synthesizeKey(" ", {}, win);
    1.64 +
    1.65 +  step();
    1.66 +
    1.67 +  ok(win.scrollY <= oldY, "Page is not scrolled down");
    1.68 +  is(ed.textContent, "a bc", "The content of the editable element has changed");
    1.69 +  sc.focus();
    1.70 +  synthesizeKey(" ", {}, win);
    1.71 +
    1.72 +  step();
    1.73 +
    1.74 +  isnot(win.scrollY, 0, "Page is scrolled down");
    1.75 +  is(ed.textContent, "a bc", "The content of the editable element has not changed");
    1.76 +  ed.focus();
    1.77 +  win.getSelection().collapse(ed.firstChild, 3);
    1.78 +  synthesizeKey(" ", {shiftKey: true}, win);
    1.79 +
    1.80 +  step();
    1.81 +
    1.82 +  isnot(win.scrollY, 0, "Page is not scrolled up");
    1.83 +  is(ed.textContent, "a b c", "The content of the editable element has changed");
    1.84 +
    1.85 +  // Now let's test the down/up keys
    1.86 +  sc = document.body;
    1.87 +
    1.88 +  step();
    1.89 +
    1.90 +  ed.blur();
    1.91 +  sc.focus();
    1.92 +  oldY = win.scrollY;
    1.93 +  synthesizeKey("VK_UP", {}, win);
    1.94 +
    1.95 +  step();
    1.96 +
    1.97 +  ok(win.scrollY < oldY, "Page is scrolled up");
    1.98 +  oldY = win.scrollY;
    1.99 +  ed.focus();
   1.100 +  win.getSelection().collapse(ed.firstChild, 3);
   1.101 +  synthesizeKey("VK_UP", {}, win);
   1.102 +
   1.103 +  step();
   1.104 +
   1.105 +  is(win.scrollY, oldY, "Page is not scrolled up");
   1.106 +  is(win.getSelection().focusNode, ed.firstChild, "Correct element selected");
   1.107 +  is(win.getSelection().focusOffset, 0, "Selection should be moved to the beginning");
   1.108 +  win.getSelection().removeAllRanges();
   1.109 +  synthesizeMouse(sc, 300, 300, {}, win);
   1.110 +  synthesizeKey("VK_DOWN", {}, win);
   1.111 +
   1.112 +  step();
   1.113 +
   1.114 +  ok(win.scrollY > oldY, "Page is scrolled down");
   1.115 +  ed.focus();
   1.116 +  win.getSelection().collapse(ed.firstChild, 3);
   1.117 +  oldY = win.scrollY;
   1.118 +  synthesizeKey("VK_DOWN", {}, win);
   1.119 +
   1.120 +  step();
   1.121 +
   1.122 +  is(win.scrollY, oldY, "Page is not scrolled down");
   1.123 +  is(win.getSelection().focusNode, ed.firstChild, "Correct element selected");
   1.124 +  is(win.getSelection().focusOffset, ed.textContent.length, "Selection should be moved to the end");
   1.125 +
   1.126 +  win.close();
   1.127 +  SpecialPowers.clearUserPref(smoothScrollPref);
   1.128 +  cwu.restoreNormalRefresh();
   1.129 +
   1.130 +  SimpleTest.finish();
   1.131 +}, win);
   1.132 +
   1.133 +</script>
   1.134 +</pre>
   1.135 +</body>
   1.136 +</html>

mercurial