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

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

mercurial