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.

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

mercurial