editor/libeditor/html/tests/test_bug549262.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=549262
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 549262</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549262">Mozilla Bug 549262</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 549262 **/
michael@0 21
michael@0 22 var smoothScrollPref = "general.smoothScroll";
michael@0 23 SpecialPowers.setBoolPref(smoothScrollPref, false);
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25 var win = window.open("file_bug549262.html", "_blank",
michael@0 26 "width=600,height=600,scrollbars=yes");
michael@0 27
michael@0 28 // grab the timer right at the start
michael@0 29 var cwu = SpecialPowers.getDOMWindowUtils(win);
michael@0 30 function step() {
michael@0 31 cwu.advanceTimeAndRefresh(100);
michael@0 32 }
michael@0 33
michael@0 34 SimpleTest.waitForFocus(function() {
michael@0 35 // Make sure that pressing Space when a contenteditable element is not focused
michael@0 36 // will scroll the page.
michael@0 37 var ed = win.document.getElementById("editor");
michael@0 38 var sc = win.document.querySelector("a");
michael@0 39 sc.focus();
michael@0 40 is(win.scrollY, 0, "Sanity check");
michael@0 41 synthesizeKey(" ", {}, win);
michael@0 42
michael@0 43 step();
michael@0 44
michael@0 45 isnot(win.scrollY, 0, "Page is scrolled down");
michael@0 46 is(ed.textContent, "abc", "The content of the editable element has not changed");
michael@0 47 var oldY = win.scrollY;
michael@0 48 synthesizeKey(" ", {shiftKey: true}, win);
michael@0 49
michael@0 50 step();
michael@0 51
michael@0 52 ok(win.scrollY < oldY, "Page is scrolled up");
michael@0 53 is(ed.textContent, "abc", "The content of the editable element has not changed");
michael@0 54
michael@0 55 // Make sure that pressing Space when a contenteditable element is focused
michael@0 56 // will not scroll the page, and will edit the element.
michael@0 57 ed.focus();
michael@0 58 win.getSelection().collapse(ed.firstChild, 1);
michael@0 59 oldY = win.scrollY;
michael@0 60 synthesizeKey(" ", {}, win);
michael@0 61
michael@0 62 step();
michael@0 63
michael@0 64 ok(win.scrollY <= oldY, "Page is not scrolled down");
michael@0 65 is(ed.textContent, "a bc", "The content of the editable element has changed");
michael@0 66 sc.focus();
michael@0 67 synthesizeKey(" ", {}, win);
michael@0 68
michael@0 69 step();
michael@0 70
michael@0 71 isnot(win.scrollY, 0, "Page is scrolled down");
michael@0 72 is(ed.textContent, "a bc", "The content of the editable element has not changed");
michael@0 73 ed.focus();
michael@0 74 win.getSelection().collapse(ed.firstChild, 3);
michael@0 75 synthesizeKey(" ", {shiftKey: true}, win);
michael@0 76
michael@0 77 step();
michael@0 78
michael@0 79 isnot(win.scrollY, 0, "Page is not scrolled up");
michael@0 80 is(ed.textContent, "a b c", "The content of the editable element has changed");
michael@0 81
michael@0 82 // Now let's test the down/up keys
michael@0 83 sc = document.body;
michael@0 84
michael@0 85 step();
michael@0 86
michael@0 87 ed.blur();
michael@0 88 sc.focus();
michael@0 89 oldY = win.scrollY;
michael@0 90 synthesizeKey("VK_UP", {}, win);
michael@0 91
michael@0 92 step();
michael@0 93
michael@0 94 ok(win.scrollY < oldY, "Page is scrolled up");
michael@0 95 oldY = win.scrollY;
michael@0 96 ed.focus();
michael@0 97 win.getSelection().collapse(ed.firstChild, 3);
michael@0 98 synthesizeKey("VK_UP", {}, win);
michael@0 99
michael@0 100 step();
michael@0 101
michael@0 102 is(win.scrollY, oldY, "Page is not scrolled up");
michael@0 103 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected");
michael@0 104 is(win.getSelection().focusOffset, 0, "Selection should be moved to the beginning");
michael@0 105 win.getSelection().removeAllRanges();
michael@0 106 synthesizeMouse(sc, 300, 300, {}, win);
michael@0 107 synthesizeKey("VK_DOWN", {}, win);
michael@0 108
michael@0 109 step();
michael@0 110
michael@0 111 ok(win.scrollY > oldY, "Page is scrolled down");
michael@0 112 ed.focus();
michael@0 113 win.getSelection().collapse(ed.firstChild, 3);
michael@0 114 oldY = win.scrollY;
michael@0 115 synthesizeKey("VK_DOWN", {}, win);
michael@0 116
michael@0 117 step();
michael@0 118
michael@0 119 is(win.scrollY, oldY, "Page is not scrolled down");
michael@0 120 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected");
michael@0 121 is(win.getSelection().focusOffset, ed.textContent.length, "Selection should be moved to the end");
michael@0 122
michael@0 123 win.close();
michael@0 124 SpecialPowers.clearUserPref(smoothScrollPref);
michael@0 125 cwu.restoreNormalRefresh();
michael@0 126
michael@0 127 SimpleTest.finish();
michael@0 128 }, win);
michael@0 129
michael@0 130 </script>
michael@0 131 </pre>
michael@0 132 </body>
michael@0 133 </html>

mercurial