tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug795785.html (4827B)


      1 <html>
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=795785
      4 -->
      5 <head>
      6  <title>Test for Bug 795785</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <script src="/tests/SimpleTest/EventUtils.js"></script>
      9  <script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795785">Mozilla Bug 795785</a>
     14 <div id="display">
     15  <textarea style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
     16  <div contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div>
     17 </div>
     18 <div id="content" style="display: none">
     19 
     20 </div>
     21 <pre id="test">
     22 </pre>
     23 
     24 <script>
     25 "use strict";
     26 
     27 function waitForScroll() {
     28  return waitToClearOutAnyPotentialScrolls(window);
     29 }
     30 
     31 async function synthesizeKeyInEachEventLoop(aKey, aEvent, aCount) {
     32  for (let i = 0; i < aCount; i++) {
     33    synthesizeKey(aKey, aEvent);
     34    await new Promise(resolve => SimpleTest.executeSoon(resolve));
     35  }
     36 }
     37 
     38 async function sendStringOneByOne(aString) {
     39  for (const ch of aString) {
     40    sendString(ch);
     41    await new Promise(resolve => SimpleTest.executeSoon(resolve));
     42  }
     43 }
     44 
     45 async function doKeyEventTest(aSelector) {
     46  const element = document.querySelector(aSelector);
     47  if (element.value !== undefined) {
     48    element.value = "";
     49  } else {
     50    element.innerHTML = "";
     51  }
     52  element.focus();
     53  element.scrollTop = 0;
     54  await waitForScroll();
     55  is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
     56  await synthesizeKeyInEachEventLoop("KEY_Enter", {shiftKey: true}, 6);
     57  await waitForScroll();
     58  isnot(element.scrollTop, 0, `${aSelector} should be scrolled by inserting line breaks`);
     59  const oldScrollTop = element.scrollTop;
     60  await synthesizeKeyInEachEventLoop("KEY_ArrowUp", {}, 5);
     61  await waitForScroll();
     62  isnot(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by up key events`);
     63  await synthesizeKeyInEachEventLoop("KEY_ArrowDown", {}, 5);
     64  await waitForScroll();
     65  is(element.scrollTop, oldScrollTop, `${aSelector} should be scrolled by down key events`);
     66  const longWord = "aaaaaaaaaaaaaaaaaaaa";
     67  await sendStringOneByOne(longWord);
     68  await waitForScroll();
     69  isnot(element.scrollLeft, 0, `${aSelector} should be scrolled by typing long word`);
     70  const oldScrollLeft = element.scrollLeft;
     71  await synthesizeKeyInEachEventLoop("KEY_ArrowLeft", {}, longWord.length);
     72  await waitForScroll();
     73  isnot(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by left key events`);
     74  await synthesizeKeyInEachEventLoop("KEY_ArrowRight", {}, longWord.length);
     75  await waitForScroll();
     76  is(element.scrollLeft, oldScrollLeft, `${aSelector} should be scrolled by right key events`);
     77 }
     78 
     79 async function doCompositionTest(aSelector) {
     80  const element = document.querySelector(aSelector);
     81  if (element.value !== undefined) {
     82    element.value = "";
     83  } else {
     84    element.innerHTML = "";
     85  }
     86  element.focus();
     87  element.scrollTop = 0;
     88  await waitForScroll();
     89  is(element.scrollTop, 0, `${aSelector}.scrollTop should be 0`);
     90  const longCompositionString =
     91    "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" +
     92    "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" +
     93    " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" +
     94    "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " +
     95    "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" +
     96    "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" +
     97    "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" +
     98    "\u304d\u307e\u3059\u3002";
     99  synthesizeCompositionChange(
    100    {
    101      composition: {
    102        string: longCompositionString,
    103        clauses: [
    104          {
    105            length: longCompositionString.length,
    106            attr: COMPOSITION_ATTR_RAW_CLAUSE,
    107          },
    108        ],
    109      },
    110      caret: {
    111        start: longCompositionString.length,
    112        length: 0,
    113      },
    114    }
    115  );
    116  await waitForScroll();
    117  isnot(element.scrollTop, 0, `${aSelector} should be scrolled by composition`);
    118  synthesizeComposition({ type: "compositioncommit", data: "" });
    119  await waitForScroll();
    120  is(
    121    element.scrollTop,
    122    0,
    123    `${aSelector} should be scrolled back to the top by canceling composition`
    124  );
    125 }
    126 
    127 SimpleTest.waitForExplicitFinish();
    128 SimpleTest.waitForFocus(async () => {
    129  await SpecialPowers.pushPrefEnv({
    130    set: [ ["general.smoothScroll", false],
    131           ["layout.disable-pixel-alignment", true] ]
    132  });
    133  await doKeyEventTest("textarea");
    134  await doKeyEventTest("div[contenteditable]");
    135  await doCompositionTest("textarea");
    136  await doCompositionTest("div[contenteditable]");
    137  SimpleTest.finish();
    138 });
    139 </script>
    140 </body>
    141 
    142 </html>