tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_clipboard_disallowed.html (1623B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Clipboard Events</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script src="/tests/SimpleTest/EventUtils.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <p id="display"></p>
     11 <input id="input" value="INPUT TEXT" oncopy="checkAllowed(event)">
     12 
     13 <script>
     14 function doTest()
     15 {
     16  document.getElementById("input").focus();
     17  synthesizeKey("c", {accelKey: 1});
     18 }
     19 
     20 function checkAllowed(event)
     21 {
     22  let clipboardData = event.clipboardData;
     23 
     24  let disallowedTypes = [
     25    "application/x-moz-file",
     26    "application/x-moz-file-promise",
     27    "application/x-moz-file-promise-url",
     28    "application/x-moz-file-promise-dest-filename",
     29    "application/x-moz-file-promise-dir",
     30    "application/x-moz-nativeimage",
     31    "text/x-moz-requestmime",
     32    "text/x-moz-place",
     33    "text/x-moz-place-container",
     34    "text/x-moz-some-made-up-type",
     35  ];
     36 
     37  for (let type of disallowedTypes) {
     38    let exception;
     39    try {
     40      clipboardData.setData(type, "Test");
     41    } catch(ex) {
     42      exception = ex;
     43    }
     44    is(String(exception).indexOf("SecurityError"), 0, "Cannot set " + type);
     45  }
     46 
     47  let allowedTypes = [
     48    "application/something",
     49    "x-moz-/something",
     50    "something/ax-moz-",
     51  ];
     52 
     53  for (let type of allowedTypes) {
     54    let exception = null;
     55    try {
     56      clipboardData.setData(type, "This is data");
     57    } catch(ex) {
     58      exception = ex;
     59    }
     60    is(exception, null, "Can set " + type);
     61  }
     62 
     63  SimpleTest.finish();
     64 }
     65 
     66 SimpleTest.waitForExplicitFinish();
     67 SimpleTest.waitForFocus(doTest);
     68 </script>