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"?>
3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
4 - License, v. 2.0. If a copy of the MPL was not distributed with this
5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
9 <window id="451540test"
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
11 width="600"
12 height="600"
13 title="451540 test">
15 <script type="application/javascript"><![CDATA[
16 const Ci = Components.interfaces;
17 const Cc = Components.classes;
18 const Cr = Components.results;
19 const SEARCH_TEXT = "minefield";
21 var gFindBar = null;
22 var gBrowser;
24 var sendCtrl = true;
25 var sendMeta = false;
26 if (navigator.platform.indexOf("Mac") >= 0) {
27 sendCtrl = false;
28 sendMeta = true;
29 }
31 var imports = [ "SimpleTest", "ok"];
32 for each (var name in imports) {
33 window[name] = window.opener.wrappedJSObject[name];
34 }
37 function finishTest() {
38 window.close();
39 SimpleTest.finish();
40 }
42 function startTest() {
43 gFindBar = document.getElementById("FindToolbar");
44 gBrowser = document.getElementById("content");
45 gBrowser.addEventListener("pageshow", onPageShow, false);
46 var data = 'data:text/html,<input id="inp" type="text" />';
47 data +='<textarea id="tarea"/>'
48 gBrowser.loadURI(data);
49 }
51 function goToStartOfLine(aElement) {
52 if (navigator.platform.indexOf("Mac") >= 0) {
53 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
54 false, false, true);
55 } else {
56 synthesizeKey(aElement, true, KeyEvent.DOM_VK_HOME,
57 false, false, false);
58 }
59 }
61 function resetForNextTest(aElement, aText) {
62 if (!aText)
63 aText = SEARCH_TEXT;
65 // Turn off highlighting
66 var highlightButton = gFindBar.getElement("highlight");
67 if (highlightButton.checked)
68 highlightButton.click();
70 // Initialise input
71 aElement.value = aText;
72 gFindBar._findField.value = SEARCH_TEXT;
74 // Perform search and turn on highlighting
75 gFindBar._find();
76 highlightButton.click();
78 // Move caret to start of element
79 aElement.focus();
80 goToStartOfLine(aElement);
81 }
83 function synthesizeKey(target, isKeyCode, key, ctlKey, shiftKey, metaKey) {
84 try {
85 var event = document.createEvent("KeyEvents");
86 if (isKeyCode) {
87 event.initKeyEvent("keypress", true, true, null, ctlKey, false,
88 shiftKey, metaKey, key, 0);
89 } else {
90 event.initKeyEvent("keypress", true, true, null, ctlKey, false,
91 shiftKey, metaKey, 0, key);
92 }
93 target.dispatchEvent(event);
94 } catch (e) {}
95 }
97 function testInput(aElement, aTestTypeText) {
98 // Initialise the findbar
99 var matchCase = gFindBar.getElement("find-case-sensitive");
100 if (matchCase.checked)
101 matchCase.doCommand();
103 // First check match has been correctly highlighted
104 resetForNextTest(aElement);
105 if (aElement instanceof Ci.nsIDOMNSEditableElement) {
106 var controller = aElement.editor.selectionController;
107 var selection = controller.getSelection(controller.SELECTION_FIND);
108 ok(selection.rangeCount == 1, aTestTypeText +
109 " correctly highlighted match");
111 // Test 2: check highlight removed when text added within the highlight
112 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
113 false, false, false);
114 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
115 false, false, false);
116 ok(selection.rangeCount == 0, aTestTypeText +
117 " correctly removed highlight on text insertion");
119 // Test 3: check highlighting remains when text added before highlight
120 resetForNextTest(aElement);
121 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
122 false, false, false);
123 ok(selection.rangeCount == 1, aTestTypeText +
124 " highlight correctly remained on text insertion at start");
126 // Test 4: check highlighting remains when text added after highlight
127 resetForNextTest(aElement);
128 for (var x = 0; x < SEARCH_TEXT.length; x++)
129 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
130 false, false, false);
131 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
132 false, false, false);
133 ok(selection.rangeCount == 1, aTestTypeText +
134 " highlight correctly remained on text insertion at end");
136 // Test 5: deleting text within the highlight
137 resetForNextTest(aElement);
138 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
139 false, false, false);
140 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
141 false, false, false);
142 ok(selection.rangeCount == 0, aTestTypeText +
143 " correctly removed highlight on text deletion");
145 // Test 6: deleting text at end of highlight
146 resetForNextTest(aElement, SEARCH_TEXT+"A");
147 for (var x = 0; x < aElement.value.length; x++)
148 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
149 false, false, false);
150 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
151 false, false, false);
152 ok(selection.rangeCount == 1, aTestTypeText +
153 " highlight correctly remained on text deletion at end");
155 // Test 7: deleting text at start of highlight
156 resetForNextTest(aElement, "A"+SEARCH_TEXT);
157 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
158 false, false, false);
159 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
160 false, false, false);
161 ok(selection.rangeCount == 1, aTestTypeText +
162 " highlight correctly remained on text deletion at start");
164 // Test 8: deleting selection
165 resetForNextTest(aElement);
166 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
167 false, true, false);
168 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
169 false, true, false);
170 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
171 sendCtrl, false, sendMeta);
172 ok(selection.rangeCount == 0, aTestTypeText +
173 " correctly removed highlight on selection deletion");
175 // Test 9: Multiple matches within one editor (part 1)
176 // Check second match remains highlighted after inserting text into
177 // first match, and that its highlighting gets removed when the
178 // second match is edited
179 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
180 ok(selection.rangeCount == 2, aTestTypeText +
181 " correctly highlighted both matches");
182 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
183 false, false, false);
184 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
185 false, false, false);
186 ok(selection.rangeCount == 1, aTestTypeText +
187 " correctly removed only the first highlight on text insertion");
188 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
189 sendCtrl, false, sendMeta);
190 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
191 sendCtrl, false, sendMeta);
192 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
193 false, false, false);
194 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
195 false, false, false);
196 ok(selection.rangeCount == 0, aTestTypeText +
197 " correctly removed second highlight on text insertion");
199 // Test 10: Multiple matches within one editor (part 2)
200 // Check second match remains highlighted after deleting text in
201 // first match, and that its highlighting gets removed when the
202 // second match is edited
203 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
204 ok(selection.rangeCount == 2, aTestTypeText +
205 " correctly highlighted both matches");
206 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
207 false, false, false);
208 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
209 false, false, false);
210 ok(selection.rangeCount == 1, aTestTypeText +
211 " correctly removed only the first highlight on text deletion");
212 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
213 sendCtrl, false, sendMeta);
214 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
215 sendCtrl, false, sendMeta);
216 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
217 false, false, false);
218 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
219 false, false, false);
220 ok(selection.rangeCount == 0, aTestTypeText +
221 " correctly removed second highlight on text deletion");
223 // Test 11: Multiple matches within one editor (part 3)
224 // Check second match remains highlighted after deleting selection
225 // in first match, and that second match highlighting gets correctly
226 // removed when it has a selection deleted from it
227 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
228 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
229 false, true, false);
230 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
231 false, true, false);
232 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
233 sendCtrl, false, sendMeta);
234 ok(selection.rangeCount == 1, aTestTypeText +
235 " correctly removed only first highlight on selection deletion");
236 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
237 sendCtrl, false, sendMeta);
238 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
239 sendCtrl, false, sendMeta);
240 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
241 false, true, false);
242 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
243 false, true, false);
244 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
245 sendCtrl, false, sendMeta);
246 ok(selection.rangeCount == 0, aTestTypeText +
247 " correctly removed second highlight on selection deletion");
248 }
249 }
251 function onPageShow() {
252 gBrowser.removeEventListener("load", onPageShow, true);
253 gBrowser.contentWindow.focus();
254 gFindBar.open();
255 var input = gBrowser.contentDocument.getElementById("inp");
256 testInput(input, "Input:");
257 var textarea = gBrowser.contentDocument.getElementById("tarea");
258 testInput(textarea, "Textarea:");
259 finishTest();
260 }
262 SimpleTest.waitForFocus(startTest, window);
263 ]]></script>
265 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
266 <findbar id="FindToolbar" browserid="content"/>
267 </window>