toolkit/content/tests/chrome/test_richlist_direction.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     4 <!--
     5   XUL Widget Test for listbox direction
     6   -->
     7 <window title="Listbox direction test"
     8         onload="test_richlistbox()"
     9         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    10   <script type="application/javascript"
    11           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    12   <script type="application/javascript"
    13           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    15   <richlistbox seltype="multiple" id="richlistbox" flex="1" minheight="80" maxheight="80" height="80" />
    17   <!-- test results are displayed in the html:body -->
    18   <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
    20 <script type="application/javascript">
    21 <![CDATA[
    23 SimpleTest.waitForExplicitFinish();
    25 var richListBox = document.getElementById("richlistbox");
    27 function getScrollIndexAmount(aDirection) {
    28   return (4 * aDirection + richListBox.currentIndex);
    29 }
    31 function test_richlistbox()
    32 {
    33   richListBox.minHeight = richListBox.maxHeight = richListBox.height =
    34     80 + (80 - richListBox.scrollBoxObject.height);
    35   var height = richListBox.scrollBoxObject.height;
    36   var item;
    37   do {
    38     item = richListBox.appendItem("Test", "");
    39     item.height = item.minHeight = item.maxHeight = Math.floor(height / 4);
    40   } while (item.getBoundingClientRect().bottom < (height * 2))
    41   richListBox.appendItem("Test", "");
    42   richListBox.firstChild.nextSibling.id = "list-box-first";
    43   richListBox.lastChild.previousSibling.id = "list-box-last";
    45   // direction = "reverse", the values here are backwards due to the fact that
    46   // richlistboxes respond differently when a user initiates a selection
    47   richListBox.dir = "reverse";
    48   var count = richListBox.itemCount;
    49   richListBox.focus();
    50   richListBox.selectedIndex = count - 1;
    51   sendKey("DOWN");
    52   is(richListBox.currentIndex, count - 2, "Selection should move to the next item");
    53   sendKey("UP");
    54   is(richListBox.currentIndex, count - 1, "Selection should move to the previous item");
    55   sendKey("END");
    56   is(richListBox.currentIndex, 0, "Selection should move to the last item");
    57   sendKey("HOME");
    58   is(richListBox.currentIndex, count - 1, "Selection should move to the first item");
    59   var currentIndex = richListBox.currentIndex;
    60   var index = getScrollIndexAmount(-1);
    61   sendKey("PAGE_DOWN");
    62   is(richListBox.currentIndex, index, "Selection should move to one page down");
    63   ok(richListBox.currentIndex < currentIndex, "Selection should move downwards");
    64   sendKey("END");
    65   currentIndex = richListBox.currentIndex;
    66   index = getScrollIndexAmount(1);
    67   sendKey("PAGE_UP");
    68   is(richListBox.currentIndex, index, "Selection should move to one page up");
    69   ok(richListBox.currentIndex > currentIndex, "Selection should move upwards");
    70   richListBox.selectedItem = richListBox.lastChild;
    71   richListBox.focus();
    72   synthesizeKey("VK_DOWN", {shiftKey: true, type: "keypress"}, window);
    73   let items = [richListBox.selectedItems[0],
    74                richListBox.selectedItems[1]];
    75   is(items[0], richListBox.lastChild, "The last element should still be selected");
    76   is(items[1], richListBox.lastChild.previousSibling, "Both elements should now be selected");
    77   richListBox.clearSelection();
    78   richListBox.selectedItem = richListBox.lastChild;
    79   sendMouseEvent({type: "click", shiftKey: true, clickCount: 1},
    80                  "list-box-last",
    81                  window);
    82   items = [richListBox.selectedItems[0],
    83            richListBox.selectedItems[1]];
    84   is(items[0], richListBox.lastChild, "The last element should still be selected");
    85   is(items[1], richListBox.lastChild.previousSibling, "Both elements should now be selected");
    86   richListBox.addEventListener("keypress", function(aEvent) {
    87     richListBox.removeEventListener("keypress", arguments.callee, true);
    88     aEvent.preventDefault();
    89   }, true);
    90   richListBox.selectedIndex = 1;
    91   sendKey("HOME");
    92   is(richListBox.selectedIndex, 1, "A stopped event should return indexing to normal");
    94   // direction = "normal"
    95   richListBox.dir = "normal";
    96   richListBox.selectedIndex = 0;
    97   sendKey("DOWN");
    98   is(richListBox.currentIndex, 1, "Selection should move to the next item");
    99   sendKey("UP");
   100   is(richListBox.currentIndex, 0, "Selection should move to the previous item");
   101   sendKey("END");
   102   is(richListBox.currentIndex, count - 1, "Selection should move to the last item");
   103   sendKey("HOME");
   104   is(richListBox.currentIndex, 0, "Selection should move to the first item");
   105   var currentIndex = richListBox.currentIndex;
   106   var index = richListBox.scrollOnePage(1);
   107   sendKey("PAGE_DOWN");
   108   is(richListBox.currentIndex, index, "Selection should move to one page down");
   109   ok(richListBox.currentIndex > currentIndex, "Selection should move downwards");
   110   sendKey("END");
   111   currentIndex = richListBox.currentIndex;
   112   index = richListBox.scrollOnePage(-1) + richListBox.currentIndex;
   113   sendKey("PAGE_UP");
   114   is(richListBox.currentIndex, index, "Selection should move to one page up");
   115   ok(richListBox.currentIndex < currentIndex, "Selection should move upwards");
   116   richListBox.selectedItem = richListBox.firstChild;
   117   richListBox.focus();
   118   synthesizeKey("VK_DOWN", {shiftKey: true, type: "keypress"}, window);
   119   items = [richListBox.selectedItems[0],
   120            richListBox.selectedItems[1]];
   121   is(items[0], richListBox.firstChild, "The last element should still be selected");
   122   is(items[1], richListBox.firstChild.nextSibling, "Both elements should now be selected");
   123   richListBox.clearSelection();
   124   richListBox.selectedItem = richListBox.firstChild;
   125   sendMouseEvent({type: "click", shiftKey: true, clickCount: 1},
   126                  "list-box-first",
   127                  window);
   128   items = [richListBox.selectedItems[0],
   129            richListBox.selectedItems[1]];
   130   is(items[0], richListBox.firstChild, "The last element should still be selected");
   131   is(items[1], richListBox.firstChild.nextSibling, "Both elements should now be selected");
   132   SimpleTest.finish();
   133 }
   135 ]]>
   136 </script>
   138 </window>

mercurial