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 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=674770
5 -->
6 <head>
7 <title>Test for Bug 674770</title>
8 <script type="application/javascript" src="/MochiKit/packed.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674770">Mozilla Bug 674770</a>
15 <p id="display"></p>
16 <div id="content">
17 <iframe id="iframe" style="display: block; height: 14em;"
18 src="data:text/html,<input id='text' value='pasted'><input id='input' style='display: block;'><p id='editor1' contenteditable>editor1:</p><p id='editor2' contenteditable>editor2:</p>"></iframe>
19 </div>
20 <pre id="test">
21 <script type="application/javascript">
23 /** Test for Bug 674770 **/
24 SimpleTest.waitForExplicitFinish();
26 var iframe = document.getElementById("iframe");
27 var frameWindow, frameDocument;
29 var gClicked = false;
30 var gClicking = null;
31 var gDoPreventDefault1 = null;
32 var gDoPreventDefault2 = null;
34 function clickEventHnalder(aEvent)
35 {
36 if (aEvent.button == 1 && aEvent.target == gClicking) {
37 gClicked = true;
38 }
39 if (gDoPreventDefault1 == aEvent.target) {
40 aEvent.preventDefault();
41 }
42 if (gDoPreventDefault2 == aEvent.target) {
43 aEvent.preventDefault();
44 }
45 }
47 // NOTE: tests need to check the result *after* the content is actually
48 // modified. Sometimes, the modification is delayed. Therefore, there
49 // are a lot of functions and SimpleTest.executeSoon()s.
51 SimpleTest.waitForFocus(function() {
52 SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
53 SpecialPowers.setBoolPref("middlemouse.paste", true);
55 frameWindow = iframe.contentWindow;
56 frameDocument = iframe.contentDocument;
58 frameDocument.getElementById("input").addEventListener("click", clickEventHnalder, false);
59 frameDocument.getElementById("editor1").addEventListener("click", clickEventHnalder, false);
60 frameDocument.getElementById("editor2").addEventListener("click", clickEventHnalder, false);
62 var text = frameDocument.getElementById("text");
64 text.focus();
66 SimpleTest.executeSoon(function() {
67 if (navigator.platform.indexOf("Linux") == 0) {
68 synthesizeKey("a", { altKey: true }, frameWindow);
69 } else {
70 synthesizeKey("a", { accelKey: true }, frameWindow);
71 }
72 // Windows and Mac don't have primary selection, we should copy the text to
73 // the global clipboard.
74 if (!SpecialPowers.supportsSelectionClipboard()) {
75 SimpleTest.waitForClipboard("pasted",
76 function() { synthesizeKey("c", { accelKey: true }, frameWindow); },
77 function() { SimpleTest.executeSoon(runInputTests1) },
78 cleanup);
79 } else {
80 // Otherwise, don't call waitForClipboard since it breaks primary
81 // selection.
82 runInputTests1();
83 }
84 });
85 });
87 function runInputTests1()
88 {
89 var input = frameDocument.getElementById("input");
91 // first, copy text.
93 // when middle clicked in focused input element, text should be pasted.
94 input.value = "";
95 input.focus();
97 SimpleTest.executeSoon(function() {
98 gClicked = false;
99 gClicking = input;
100 gDoPreventDefault1 = null;
101 gDoPreventDefault2 = null;
103 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
105 SimpleTest.executeSoon(function() {
106 todo(gClicked, "click event hasn't been fired for runInputTests1");
107 is(input.value, "pasted", "failed to paste in input element");
109 SimpleTest.executeSoon(runInputTests2);
110 });
111 });
112 }
114 function runInputTests2()
115 {
116 var input = frameDocument.getElementById("input");
118 // even if the input element hasn't had focus, middle click should set focus
119 // to it and paste the text.
120 input.value = "";
121 input.blur();
123 SimpleTest.executeSoon(function() {
124 gClicked = false;
125 gClicking = input;
126 gDoPreventDefault1 = null;
127 gDoPreventDefault2 = null;
129 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
131 SimpleTest.executeSoon(function() {
132 todo(gClicked, "click event hasn't been fired for runInputTests2");
133 is(input.value, "pasted",
134 "failed to paste in input element when it hasn't had focus yet");
136 SimpleTest.executeSoon(runInputTests3);
137 });
138 });
139 }
141 function runInputTests3()
142 {
143 var input = frameDocument.getElementById("input");
144 var editor1 = frameDocument.getElementById("editor1");
146 // preventDefault() of HTML editor's click event handler shouldn't prevent
147 // middle click pasting in input element.
148 input.value = "";
149 input.focus();
151 SimpleTest.executeSoon(function() {
152 gClicked = false;
153 gClicking = input;
154 gDoPreventDefault1 = editor1;
155 gDoPreventDefault2 = null;
157 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
159 SimpleTest.executeSoon(function() {
160 todo(gClicked, "click event hasn't been fired for runInputTests3");
161 is(input.value, "pasted",
162 "failed to paste in input element when editor1 does preventDefault()");
164 SimpleTest.executeSoon(runInputTests4);
165 });
166 });
167 }
169 function runInputTests4()
170 {
171 var input = frameDocument.getElementById("input");
172 var editor1 = frameDocument.getElementById("editor1");
174 // preventDefault() of input element's click event handler should prevent
175 // middle click pasting in it.
176 input.value = "";
177 input.focus();
179 SimpleTest.executeSoon(function() {
180 gClicked = false;
181 gClicking = input;
182 gDoPreventDefault1 = input;
183 gDoPreventDefault2 = null;
185 synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
187 SimpleTest.executeSoon(function() {
188 todo(gClicked, "click event hasn't been fired for runInputTests4");
189 todo_is(input.value, "",
190 "pasted in input element when it does preventDefault()");
192 SimpleTest.executeSoon(runContentEditableTests1);
193 });
194 });
195 }
197 function runContentEditableTests1()
198 {
199 var editor1 = frameDocument.getElementById("editor1");
201 // when middle clicked in focused contentediable editor, text should be
202 // pasted.
203 editor1.innerHTML = "editor1:";
204 editor1.focus();
206 SimpleTest.executeSoon(function() {
207 gClicked = false;
208 gClicking = editor1;
209 gDoPreventDefault1 = null;
210 gDoPreventDefault2 = null;
212 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
214 SimpleTest.executeSoon(function() {
215 todo(gClicked, "click event hasn't been fired for runContentEditableTests1");
216 is(editor1.innerHTML, "editor1:pasted",
217 "failed to paste text in contenteditable editor");
218 SimpleTest.executeSoon(runContentEditableTests2);
219 });
220 });
221 }
223 function runContentEditableTests2()
224 {
225 var editor1 = frameDocument.getElementById("editor1");
227 // even if the contenteditable editor hasn't had focus, middle click should
228 // set focus to it and paste the text.
229 editor1.innerHTML = "editor1:";
230 editor1.blur();
232 SimpleTest.executeSoon(function() {
233 gClicked = false;
234 gClicking = editor1;
235 gDoPreventDefault1 = null;
236 gDoPreventDefault2 = null;
238 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
240 SimpleTest.executeSoon(function() {
241 todo(gClicked, "click event hasn't been fired for runContentEditableTests2");
242 is(editor1.innerHTML, "editor1:pasted",
243 "failed to paste in contenteditable editor #1 when it hasn't had focus yet");
244 SimpleTest.executeSoon(runContentEditableTests3);
245 });
246 });
247 }
249 function runContentEditableTests3()
250 {
251 var editor1 = frameDocument.getElementById("editor1");
252 var editor2 = frameDocument.getElementById("editor2");
254 // When editor1 has focus but editor2 is middle clicked, should be pasted
255 // in the editor2.
256 editor1.innerHTML = "editor1:";
257 editor2.innerHTML = "editor2:";
258 editor1.focus();
260 SimpleTest.executeSoon(function() {
261 gClicked = false;
262 gClicking = editor2;
263 gDoPreventDefault1 = null;
264 gDoPreventDefault2 = null;
266 synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
268 SimpleTest.executeSoon(function() {
269 todo(gClicked, "click event hasn't been fired for runContentEditableTests3");
270 is(editor1.innerHTML, "editor1:",
271 "pasted in contenteditable editor #1 when editor2 is clicked");
272 is(editor2.innerHTML, "editor2:pasted",
273 "failed to paste in contenteditable editor #2 when editor2 is clicked");
274 SimpleTest.executeSoon(runContentEditableTests4);
275 });
276 });
277 }
279 function runContentEditableTests4()
280 {
281 var editor1 = frameDocument.getElementById("editor1");
283 // preventDefault() of editor1's click event handler should prevent
284 // middle click pasting in it.
285 editor1.innerHTML = "editor1:";
286 editor1.focus();
288 SimpleTest.executeSoon(function() {
289 gClicked = false;
290 gClicking = editor1;
291 gDoPreventDefault1 = editor1;
292 gDoPreventDefault2 = null;
294 synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
296 SimpleTest.executeSoon(function() {
297 todo(gClicked, "click event hasn't been fired for runContentEditableTests4");
298 todo_is(editor1.innerHTML, "editor1:",
299 "pasted in contenteditable editor #1 when it does preventDefault()");
300 SimpleTest.executeSoon(runContentEditableTests5);
301 });
302 });
303 }
305 function runContentEditableTests5()
306 {
307 var editor1 = frameDocument.getElementById("editor1");
308 var editor2 = frameDocument.getElementById("editor2");
310 // preventDefault() of editor1's click event handler shouldn't prevent
311 // middle click pasting in editor2.
312 editor1.innerHTML = "editor1:";
313 editor2.innerHTML = "editor2:";
314 editor2.focus();
316 SimpleTest.executeSoon(function() {
317 gClicked = false;
318 gClicking = editor2;
319 gDoPreventDefault1 = editor1;
320 gDoPreventDefault2 = null;
322 synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
324 SimpleTest.executeSoon(function() {
325 todo(gClicked, "click event hasn't been fired for runContentEditableTests5");
326 is(editor1.innerHTML, "editor1:",
327 "pasted in contenteditable editor #1?");
328 is(editor2.innerHTML, "editor2:pasted",
329 "failed to paste in contenteditable editor #2");
331 SimpleTest.executeSoon(initForBodyEditableDocumentTests);
332 });
333 });
334 }
336 function initForBodyEditableDocumentTests()
337 {
338 frameDocument.getElementById("input").removeEventListener("click", clickEventHnalder, false);
339 frameDocument.getElementById("editor1").removeEventListener("click", clickEventHnalder, false);
340 frameDocument.getElementById("editor2").removeEventListener("click", clickEventHnalder, false);
342 iframe.onload =
343 function (aEvent) { SimpleTest.executeSoon(runBodyEditableDocumentTests1); };
344 iframe.src =
345 "data:text/html,<body contenteditable>body:</body>";
346 }
348 function runBodyEditableDocumentTests1()
349 {
350 frameWindow = iframe.contentWindow;
351 frameDocument = iframe.contentDocument;
353 var body = frameDocument.body;
355 is(body.innerHTML, "body:",
356 "failed to initialize at runBodyEditableDocumentTests1");
358 // middle click on html element should cause pasting text in its body.
359 synthesizeMouseAtCenter(frameDocument.documentElement, {button: 1}, frameWindow);
361 SimpleTest.executeSoon(function() {
362 is(body.innerHTML,
363 "body:pasted",
364 "failed to paste in editable body element when clicked on html element");
366 SimpleTest.executeSoon(runBodyEditableDocumentTests2);
367 });
368 }
370 function runBodyEditableDocumentTests2()
371 {
372 frameDocument.body.innerHTML = "body:<span id='span' contenteditable='false'>non-editable</span>";
374 var body = frameDocument.body;
376 is(body.innerHTML, "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
377 "failed to initialize at runBodyEditableDocumentTests2");
379 synthesizeMouseAtCenter(frameDocument.getElementById("span"), {button: 1}, frameWindow);
381 SimpleTest.executeSoon(function() {
382 is(body.innerHTML,
383 "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
384 "pasted when middle clicked in non-editable element");
386 SimpleTest.executeSoon(cleanup);
387 });
388 }
390 function cleanup()
391 {
392 SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
393 SpecialPowers.clearUserPref("middlemouse.paste");
395 SimpleTest.finish();
396 }
398 </script>
399 </pre>
400 </body>
401 </html>