dom/tests/mochitest/general/test_paste_selection.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for middle-click to paste selection with paste events</title>
michael@0 5 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <p id="display"></p>
michael@0 12 <input id="copy-area" value="CLIPBOARD">
michael@0 13 <input id="paste-selection-area" value="" onpaste="pastedSelection(event)">
michael@0 14 <input id="paste-global-area" value="" onpaste="pastedGlobal(event)">
michael@0 15
michael@0 16 <script>
michael@0 17
michael@0 18 var supportsSelectionClipboard = SpecialPowers.supportsSelectionClipboard();
michael@0 19
michael@0 20 function checkSelectionClipboardText(count)
michael@0 21 {
michael@0 22 if ((!supportsSelectionClipboard ||
michael@0 23 SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard) == "COPY TEXT") &&
michael@0 24 SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kGlobalClipboard) == "CLIPBOARD") {
michael@0 25 pasteArea();
michael@0 26 return;
michael@0 27 }
michael@0 28
michael@0 29 if (count > 10) {
michael@0 30 ok(false, "could not set clipboards");
michael@0 31 pasteArea();
michael@0 32 SimpleTest.finish();
michael@0 33 return;
michael@0 34 }
michael@0 35
michael@0 36 setTimeout(checkSelectionClipboardText, 5, count + 1);
michael@0 37 }
michael@0 38
michael@0 39 function selectArea()
michael@0 40 {
michael@0 41 var copyArea = document.getElementById("copy-area");
michael@0 42 copyArea.focus();
michael@0 43 copyArea.select();
michael@0 44 synthesizeKey("x", { accelKey: true });
michael@0 45
michael@0 46 if (supportsSelectionClipboard) {
michael@0 47 var clipboardHelper = SpecialPowers.Cc["@mozilla.org/widget/clipboardhelper;1"]
michael@0 48 .getService(SpecialPowers.Ci.nsIClipboardHelper);
michael@0 49 clipboardHelper.copyStringToClipboard("COPY TEXT",
michael@0 50 SpecialPowers.Ci.nsIClipboard.kSelectionClipboard,
michael@0 51 document);
michael@0 52 }
michael@0 53
michael@0 54 setTimeout(checkSelectionClipboardText, 50, 0);
michael@0 55 }
michael@0 56
michael@0 57 var selectionPasted = false;
michael@0 58 var globalPasted = false;
michael@0 59
michael@0 60 function pasteArea()
michael@0 61 {
michael@0 62 var pasteArea = document.getElementById("paste-selection-area");
michael@0 63 pasteArea.focus();
michael@0 64 synthesizeMouse(pasteArea, 8, 8, { button: 1 });
michael@0 65
michael@0 66 var usesMouseButtonPaste = SpecialPowers.getBoolPref("middlemouse.paste");
michael@0 67 if (usesMouseButtonPaste) {
michael@0 68 // The data transfer should contain the selection data when the selection clipboard is supported,
michael@0 69 // not the global clipboard data.
michael@0 70 var expectedText = supportsSelectionClipboard ? "COPY TEXT" : "CLIPBOARD";
michael@0 71 is(document.getElementById("paste-selection-area").value, expectedText, "data pasted properly from selection");
michael@0 72 ok(selectionPasted, "selection event fired");
michael@0 73 }
michael@0 74 else {
michael@0 75 is(pasteArea.value, "", "data not pasted when middle click not supported");
michael@0 76 }
michael@0 77
michael@0 78 var pasteArea = document.getElementById("paste-global-area");
michael@0 79 pasteArea.focus();
michael@0 80 synthesizeKey("v", { accelKey: true });
michael@0 81
michael@0 82 ok(globalPasted, "global event fired");
michael@0 83 is(document.getElementById("paste-global-area").value, "CLIPBOARD", "data pasted properly from global clipboard");
michael@0 84 SimpleTest.finish();
michael@0 85 }
michael@0 86
michael@0 87 function pastedSelection(event)
michael@0 88 {
michael@0 89 ok(SpecialPowers.getBoolPref("middlemouse.paste"), "paste on middle click is valid");
michael@0 90
michael@0 91 // Mac and Windows shouldn't get here as the middle mouse preference is false by default
michael@0 92 ok(navigator.platform.indexOf("Mac") == -1 && navigator.platform.indexOf("Win") == -1, "middle click enabled on right platforms");
michael@0 93
michael@0 94 var expectedText = supportsSelectionClipboard ? "COPY TEXT" : "CLIPBOARD";
michael@0 95 is(event.clipboardData.getData("text/plain"), expectedText, "data pasted properly from selection");
michael@0 96
michael@0 97 selectionPasted = true;
michael@0 98 }
michael@0 99
michael@0 100 function pastedGlobal(event)
michael@0 101 {
michael@0 102 // The data transfer should contain the global data.
michael@0 103 is(event.clipboardData.getData("text/plain"), "CLIPBOARD", "data correct in global clipboard data transfer");
michael@0 104 globalPasted = true;
michael@0 105 }
michael@0 106
michael@0 107 SimpleTest.waitForExplicitFinish();
michael@0 108 SimpleTest.waitForFocus(selectArea);
michael@0 109 </script>
michael@0 110
michael@0 111 </pre>
michael@0 112 </body>
michael@0 113 </html>
michael@0 114

mercurial