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