tor-browser

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

protectedPasteDataTransfer-manual.html (3423B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset='utf-8'>
      5    <title>HTML Test: paste DataTransfer protected status</title>
      6    <link rel='author' title='Nika Layzell' href='mailto:nika@thelayzells.com'>
      7    <link rel='help' href='https://html.spec.whatwg.org/multipage/#the-datatransfer-interface'>
      8    <script src="/resources/testharness.js"></script>
      9    <script src="/resources/testharnessreport.js"></script>
     10  </head>
     11 
     12  <body>
     13    <h3>Instructions</h3>
     14    <p>
     15      Select the text in the text box and press Ctrl-C followed by Ctrl-V.
     16    </p>
     17 
     18    <input type="text" id="input" value="text">
     19 
     20    <div id="log"> </div>
     21 
     22    <script>
     23      var MIME = "text/plain";
     24 
     25      var input;
     26      setup(function() {
     27        input = document.querySelector("#input");
     28      }, {explicit_done: true, explicit_timeout: true});
     29 
     30      var STATUS_PROTECTED = "protected";
     31      var STATUS_READONLY = "readonly";
     32      var STATUS_READWRITE = "readwrite";
     33      var STATUS_DISCONNECTED = "disconnected";
     34      function status(dt) {
     35        // Check if we can write to it.
     36        try {
     37          dt.setData("text/html", "_test");
     38 
     39          if (dt.getData("text/html") == "_test") {
     40            dt.clearData("text/html");
     41            assert_true(!dt.getData("text/html"), "ClearData should work...");
     42            return STATUS_READWRITE;
     43          }
     44        } catch(e) {}
     45 
     46        // If we can read the data then we're readonly
     47        if (dt.getData(MIME)) {
     48          return STATUS_READONLY;
     49        }
     50 
     51        // If we can see that items exist (and read types) then we're protected
     52        if (dt.items.length > 0) {
     53          return STATUS_PROTECTED;
     54        }
     55 
     56        // Otherwise we've been disconnected.
     57        return STATUS_DISCONNECTED;
     58      };
     59 
     60      let copy_dt = null;
     61      let paste_dt = null;
     62      on_event(input, "copy", function(e) {
     63        copy_dt = e.clipboardData;
     64        paste_dt = null;
     65        copy_dt.setData(MIME, "b");
     66 
     67        test(function() {
     68          assert_equals(status(copy_dt), STATUS_READWRITE,
     69                        "copy_dt must be readwrite during copy");
     70        }, "copy event status");
     71 
     72        e.preventDefault();
     73      });
     74      on_event(input, "paste", function(e) {
     75        paste_dt = e.clipboardData;
     76 
     77        test(function() {
     78          assert_equals(status(copy_dt), STATUS_DISCONNECTED,
     79                        "copy_dt mustbe disconnected during paste");
     80          assert_equals(status(paste_dt), STATUS_READONLY,
     81                        "paste_dt mustbe readonly during paste");
     82        }, "paste event status");
     83        test(function() {
     84          assert_not_equals(copy_dt != paste_dt,
     85                            "copy_dt must be a different DataTransfer object than paste_dt");
     86        }, "paste event identity");
     87        test(function() {
     88          assert_equals(paste_dt.getData(MIME), "b",
     89                        "the data should have been persisted");
     90        }, "paste event data");
     91 
     92        e.preventDefault();
     93 
     94        setTimeout(function() {
     95          test(function() {
     96            assert_equals(status(copy_dt), STATUS_DISCONNECTED,
     97                          "copy_dt mustbe disconnected after paste");
     98            assert_equals(status(paste_dt), STATUS_DISCONNECTED,
     99                          "paste_dt mustbe disconnected after paste");
    100          }, "after paste event status");
    101          done();
    102        }, 0);
    103      });
    104    </script>
    105  </body>
    106 </html>