toolkit/content/tests/chrome/test_menulist.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.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4
michael@0 5 <window title="Menulist Tests"
michael@0 6 onload="setTimeout(testtag_menulists, 0);"
michael@0 7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 8
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 11 <script type="application/javascript" src="xul_selectcontrol.js"></script>
michael@0 12
michael@0 13 <vbox id="scroller" style="overflow: auto" height="60">
michael@0 14 <menulist id="menulist" onpopupshown="test_menulist_open(this, this.parentNode)"
michael@0 15 onpopuphidden="$('menulist-in-listbox').open = true;">
michael@0 16 <menupopup id="menulist-popup"/>
michael@0 17 </menulist>
michael@0 18 <button label="Two"/>
michael@0 19 <button label="Three"/>
michael@0 20 </vbox>
michael@0 21 <listbox id="scroller-in-listbox" style="overflow: auto" height="60">
michael@0 22 <listitem allowevents="true">
michael@0 23 <menulist id="menulist-in-listbox" onpopupshown="test_menulist_open(this, this.parentNode.parentNode)"
michael@0 24 onpopuphidden="SimpleTest.executeSoon(checkScrollAndFinish)">
michael@0 25 <menupopup id="menulist-in-listbox-popup">
michael@0 26 <menuitem label="One" value="one"/>
michael@0 27 <menuitem label="Two" value="two"/>
michael@0 28 </menupopup>
michael@0 29 </menulist>
michael@0 30 </listitem>
michael@0 31 <listitem label="Two"/>
michael@0 32 <listitem label="Three"/>
michael@0 33 <listitem label="Four"/>
michael@0 34 <listitem label="Five"/>
michael@0 35 <listitem label="Six"/>
michael@0 36 </listbox>
michael@0 37
michael@0 38 <hbox>
michael@0 39 <menulist id="menulist-size">
michael@0 40 <menupopup>
michael@0 41 <menuitem label="Menuitem Label" width="200"/>
michael@0 42 </menupopup>
michael@0 43 </menulist>
michael@0 44 </hbox>
michael@0 45
michael@0 46 <menulist id="menulist-editable" editable="true">
michael@0 47 <menupopup id="menulist-popup-editable"/>
michael@0 48 </menulist>
michael@0 49
michael@0 50 <menulist id="menulist-initwithvalue" value="two">
michael@0 51 <menupopup>
michael@0 52 <menuitem label="One" value="one"/>
michael@0 53 <menuitem label="Two" value="two"/>
michael@0 54 <menuitem label="Three" value="three"/>
michael@0 55 </menupopup>
michael@0 56 </menulist>
michael@0 57 <menulist id="menulist-initwithselected" value="two">
michael@0 58 <menupopup>
michael@0 59 <menuitem label="One" value="one"/>
michael@0 60 <menuitem label="Two" value="two"/>
michael@0 61 <menuitem label="Three" value="three" selected="true"/>
michael@0 62 </menupopup>
michael@0 63 </menulist>
michael@0 64 <menulist id="menulist-editable-initwithvalue" editable="true" value="Two">
michael@0 65 <menupopup>
michael@0 66 <menuitem label="One" value="one"/>
michael@0 67 <menuitem label="Two" value="two"/>
michael@0 68 <menuitem label="Three" value="three"/>
michael@0 69 </menupopup>
michael@0 70 </menulist>
michael@0 71 <menulist id="menulist-editable-initwithselected" editable="true" value="two">
michael@0 72 <menupopup>
michael@0 73 <menuitem label="One" value="one"/>
michael@0 74 <menuitem label="Two" value="two"/>
michael@0 75 <menuitem label="Three" value="three" selected="true"/>
michael@0 76 </menupopup>
michael@0 77 </menulist>
michael@0 78
michael@0 79 <script class="testbody" type="application/javascript">
michael@0 80 <![CDATA[
michael@0 81
michael@0 82 SimpleTest.waitForExplicitFinish();
michael@0 83
michael@0 84 function testtag_menulists()
michael@0 85 {
michael@0 86 testtag_menulist_UI_start($("menulist"), false);
michael@0 87 testtag_menulist_UI_start($("menulist-editable"), true);
michael@0 88
michael@0 89 // bug 566154, the menulist width should account for vertical scrollbar
michael@0 90 ok(document.getElementById("menulist-size").getBoundingClientRect().width >= 210,
michael@0 91 "menulist popup width includes scrollbar width");
michael@0 92
michael@0 93 $("menulist").open = true;
michael@0 94 }
michael@0 95
michael@0 96 function testtag_menulist_UI_start(element, editable)
michael@0 97 {
michael@0 98 var testprefix = editable ? "editable" : "";
michael@0 99
michael@0 100 // check the menupopup property
michael@0 101 var popup = element.menupopup;
michael@0 102 ok(popup && popup.localName == "menupopup" &&
michael@0 103 popup.parentNode == element, testprefix + " menupopup");
michael@0 104
michael@0 105 // test the interfaces that menulist implements
michael@0 106 test_nsIDOMXULMenuListElement(element, testprefix, editable);
michael@0 107
michael@0 108 element.value = "";
michael@0 109
michael@0 110 test_nsIDOMXULSelectControlElement(element, "menuitem",
michael@0 111 editable ? "editable" : null);
michael@0 112 }
michael@0 113
michael@0 114 function test_nsIDOMXULMenuListElement(element, testprefix, editable)
michael@0 115 {
michael@0 116 is(element.open, false, testprefix + " open");
michael@0 117 is(element.editable, editable, testprefix + " editable");
michael@0 118
michael@0 119 if (editable) {
michael@0 120 var inputField = element.inputField;
michael@0 121 is(inputField &&
michael@0 122 inputField instanceof Components.interfaces.nsIDOMHTMLInputElement,
michael@0 123 true, testprefix + " inputField");
michael@0 124
michael@0 125 // check if the select method works
michael@0 126 inputField.select();
michael@0 127 is(inputField.selectionStart, 0, testprefix + " empty select selectionStart");
michael@0 128 is(inputField.selectionEnd, 0, testprefix + " empty select selectionEnd");
michael@0 129
michael@0 130 element.value = "Some Text";
michael@0 131 inputField.select();
michael@0 132 is(inputField.selectionStart, 0, testprefix + " empty select selectionStart");
michael@0 133 is(inputField.selectionEnd, 9, testprefix + " empty select selectionEnd");
michael@0 134 }
michael@0 135 else {
michael@0 136 is(element.inputField, null , testprefix + " inputField");
michael@0 137 }
michael@0 138
michael@0 139 element.appendItem("Item One", "one");
michael@0 140 var seconditem = element.appendItem("Item Two", "two");
michael@0 141 var thirditem = element.appendItem("Item Three", "three");
michael@0 142 element.appendItem("Item Four", "four");
michael@0 143
michael@0 144 seconditem.image = "happy.png";
michael@0 145 seconditem.setAttribute("description", "This is the second description");
michael@0 146 thirditem.image = "happy.png";
michael@0 147 thirditem.setAttribute("description", "This is the third description");
michael@0 148
michael@0 149 // check the image and description properties
michael@0 150 // editable menulists don't use the image or description properties currently
michael@0 151 if (editable) {
michael@0 152 element.selectedIndex = 1;
michael@0 153 is(element.image, "", testprefix + " image set to selected");
michael@0 154 is(element.description, "", testprefix + " description set to selected");
michael@0 155 }
michael@0 156 else {
michael@0 157 element.selectedIndex = 1;
michael@0 158 is(element.image, "happy.png", testprefix + " image set to selected");
michael@0 159 is(element.description, "This is the second description", testprefix + " description set to selected");
michael@0 160 element.selectedIndex = -1;
michael@0 161 is(element.image, "", testprefix + " image set when none selected");
michael@0 162 is(element.description, "", testprefix + " description set when none selected");
michael@0 163 element.selectedIndex = 2;
michael@0 164 is(element.image, "happy.png", testprefix + " image set to selected again");
michael@0 165 is(element.description, "This is the third description", testprefix + " description set to selected again");
michael@0 166
michael@0 167 // check that changing the properties of the selected item changes the menulist's properties
michael@0 168 thirditem.label = "Item Number Three";
michael@0 169 is(element.label, "Item Number Three", testprefix + " label modified");
michael@0 170 thirditem.value = "item-three";
michael@0 171 is(element.value, "item-three", testprefix + " value modified");
michael@0 172 thirditem.image = "smile.png";
michael@0 173 is(element.image, "smile.png", testprefix + " image modified");
michael@0 174 thirditem.setAttribute("description", "Changed description");
michael@0 175 is(element.description, "Changed description", testprefix + " description modified");
michael@0 176 seconditem.label = "Changed Label 2";
michael@0 177 is(element.label, "Item Number Three", testprefix + " label of another item modified");
michael@0 178
michael@0 179 element.selectedIndex = 0;
michael@0 180 is(element.image, "", testprefix + " image set to selected with no image");
michael@0 181 is(element.description, "", testprefix + " description set to selected with no description");
michael@0 182 }
michael@0 183
michael@0 184 // check the removeAllItems method
michael@0 185 element.appendItem("An Item", "anitem");
michael@0 186 element.appendItem("Another Item", "anotheritem");
michael@0 187 element.removeAllItems();
michael@0 188 is(element.itemCount, 0, testprefix + " removeAllItems");
michael@0 189 }
michael@0 190
michael@0 191 function test_menulist_open(element, scroller)
michael@0 192 {
michael@0 193 element.appendItem("Scroll Item 1", "scrollitem1");
michael@0 194 element.appendItem("Scroll Item 2", "scrollitem2");
michael@0 195 element.focus();
michael@0 196
michael@0 197 /*
michael@0 198 // bug 530504, mousewheel while menulist is open should not scroll menulist
michael@0 199 // items or parent
michael@0 200 var scrolled = false;
michael@0 201 var mouseScrolled = function (event) { scrolled = true; }
michael@0 202 window.addEventListener("DOMMouseScroll", mouseScrolled, false);
michael@0 203 synthesizeWheel(element, 2, 2, { deltaY: 10,
michael@0 204 deltaMode: WheelEvent.DOM_DELTA_LINE });
michael@0 205 is(scrolled, true, "mousescroll " + element.id);
michael@0 206 is(scroller.scrollTop, 0, "scroll position on mousescroll " + element.id);
michael@0 207 window.removeEventListener("DOMMouseScroll", mouseScrolled, false);
michael@0 208 */
michael@0 209
michael@0 210 // bug 543065, hovering the mouse over an item should highlight it and not
michael@0 211 // scroll the parent
michael@0 212 var item = element.menupopup.childNodes[1];
michael@0 213
michael@0 214 synthesizeMouse(element.menupopup.childNodes[1], 2, 2, { type: "mousemove" });
michael@0 215 synthesizeMouse(element.menupopup.childNodes[1], 6, 6, { type: "mousemove" });
michael@0 216 is(element.menuBoxObject.activeChild, item, "activeChild after menu highlight " + element.id);
michael@0 217 is(scroller.scrollTop, 0, "scroll position after menu highlight " + element.id);
michael@0 218
michael@0 219 element.open = false;
michael@0 220 }
michael@0 221
michael@0 222 function checkScrollAndFinish()
michael@0 223 {
michael@0 224 is($("scroller").scrollTop, 0, "mousewheel on menulist does not scroll vbox parent");
michael@0 225 is($("scroller-in-listbox").scrollTop, 0, "mousewheel on menulist does not scroll listbox parent");
michael@0 226
michael@0 227 // bug 561243, outline causes the mouse click to be targeted incorrectly
michael@0 228 var editableMenulist = $("menulist-editable");
michael@0 229 editableMenulist.className = "outlined";
michael@0 230
michael@0 231 synthesizeMouse(editableMenulist.inputField, 25, 8, { type: "mousedown" });
michael@0 232 synthesizeMouse(editableMenulist.inputField, 25, 8, { type: "mouseup" });
michael@0 233 isnot(editableMenulist.inputField.selectionStart, editableMenulist.inputField.textLength,
michael@0 234 "mouse event on editable menulist with outline caret position");
michael@0 235
michael@0 236 SimpleTest.finish();
michael@0 237 }
michael@0 238
michael@0 239 ]]>
michael@0 240 </script>
michael@0 241
michael@0 242 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 243 <style>
michael@0 244 .outlined > .menulist-editable-box { outline: 1px solid black; }
michael@0 245 </style>
michael@0 246 <p id="display">
michael@0 247 </p>
michael@0 248 <div id="content" style="display: none">
michael@0 249 </div>
michael@0 250 <pre id="test">
michael@0 251 </pre>
michael@0 252 </body>
michael@0 253
michael@0 254 </window>

mercurial