tor-browser

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

test_scroll_selection_into_view.html (4751B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for scrolling selection into view</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 var win;
     14 const nsISelectionController = SpecialPowers.Ci.nsISelectionController;
     15 
     16 function controllerForWindow(aWin) {
     17  return SpecialPowers.wrap(aWin)
     18    .docShell
     19    .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
     20    .getInterface(SpecialPowers.Ci.nsISelectionDisplay)
     21    .QueryInterface(SpecialPowers.Ci.nsISelectionController);
     22 }
     23 
     24 function testCollapsed(id, flags, startAt, expected) {
     25  var c = win.document.getElementById("c" + id);
     26  var target = win.document.getElementById("target" + id);
     27  var controller;
     28  if (target.contentDocument) {
     29    controller = controllerForWindow(target.contentWindow);
     30    target = target.contentDocument.getElementById("target" + id);
     31  } else {
     32    controller = controllerForWindow(win);
     33  }
     34  var selection = controller.getSelection(nsISelectionController.SELECTION_NORMAL);
     35  selection.collapse(target.parentNode, 0);
     36  c.scrollTop = startAt;
     37  try {
     38    controller.scrollSelectionIntoView(
     39      nsISelectionController.SELECTION_NORMAL,
     40      nsISelectionController.SELECTION_FOCUS_REGION,
     41      nsISelectionController.SCROLL_SYNCHRONOUS | flags
     42    );
     43  } catch (e) {}
     44  is(c.scrollTop, expected, "Scrolling " + target.id +
     45     " into view with flags " + flags + ", starting at " + startAt);
     46 }
     47 
     48 function doTest() {
     49  // Test scrolling an element smaller than the scrollport
     50  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_START, 0, 400);
     51  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_END, 0, 220);
     52  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_NEAREST, 0, 220);
     53  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_START, 500, 400);
     54  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_END, 500, 220);
     55  testCollapsed("1", nsISelectionController.SCROLL_VERTICAL_NEAREST, 500, 400);
     56 
     57  // overflow:hidden elements should not be scrolled by selection
     58  // scrolling-into-view
     59  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_START, 0, 0);
     60  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_END, 0, 0);
     61  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_NEAREST, 0, 0);
     62  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_START, 500, 500);
     63  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_END, 500, 500);
     64  testCollapsed("2", nsISelectionController.SCROLL_VERTICAL_NEAREST, 500, 500);
     65 
     66  // Test scrolling an element larger than the scrollport
     67  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_START, 0, 400);
     68  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_END, 0, 500);
     69  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_NEAREST, 0, 400);
     70  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_START, 1000, 400);
     71  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_END, 1000, 500);
     72  // If the element can't be completely visible, show as much as possible,
     73  // and don't hide anything which was initially visible.
     74  testCollapsed("3", nsISelectionController.SCROLL_VERTICAL_NEAREST, 1000, 500);
     75 
     76  // Test scrolling an element larger than the scrollport
     77  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_START, 0, 400);
     78  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_END, 0, 500);
     79  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_NEAREST, 0, 400);
     80  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_START, 1000, 400);
     81  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_END, 1000, 500);
     82  // If the element can't be completely visible, show as much as possible,
     83  // and don't hide anything which was initially visible.
     84  testCollapsed("4", nsISelectionController.SCROLL_VERTICAL_NEAREST, 1000, 500);
     85 
     86  // Test that scrolling a translated element into view takes
     87  // account of the transform.
     88  testCollapsed("5", nsISelectionController.SCROLL_VERTICAL_START, 0, 400);
     89 
     90  // Test that scrolling a scaled element into view takes
     91  // account of the transform.
     92  testCollapsed("6", nsISelectionController.SCROLL_VERTICAL_START, 0, 150);
     93 
     94  // Test that scrolling an element with a translated, scrolling container
     95  // into view takes account of the transform.
     96  testCollapsed("7", nsISelectionController.SCROLL_VERTICAL_START, 0, 400);
     97 
     98  win.close();
     99  SimpleTest.finish();
    100 }
    101 
    102 function openWindow() {
    103  win = open("scroll_selection_into_view_window.html", "_blank", "width=500,height=350");
    104 }
    105 
    106 SimpleTest.waitForExplicitFinish();
    107 addLoadEvent(openWindow);
    108 </script>
    109 </pre>
    110 </body>
    111 
    112 </html>