tor-browser

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

test_sanityEventUtils.xhtml (6297B)


      1 <?xml version="1.0"?>
      2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      3   - License, v. 2.0. If a copy of the MPL was not distributed with this
      4   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      5 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
      6                 type="text/css"?>
      7 <window title="Test EventUtils functions"
      8        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      9  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10  <script type="text/javascript">
     11  var start = new Date();
     12  </script>
     13  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
     14  <script type="text/javascript">
     15  var loadTime = new Date();
     16  </script>
     17  <script type="application/javascript">
     18  <![CDATA[
     19    info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n");
     20    var testFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     21    var regularDtForDrag1 = null;
     22    var gSetDropEffect = true;
     23    var gData;
     24    var gEnter = false;
     25    var gOver  = false;
     26    var dragDrop = [[
     27      { type    : "text/plain",
     28        data    : "This is a test" }
     29    ]];
     30    // this is the expected data arrays
     31    // for testing drag of 2 items create 2 inner arrays
     32    var drag1 = [[
     33      { type  : "text/uri-list",
     34        data  : "http://www.mozilla.org/" }
     35    ]];
     36    var drag2items = [[
     37      { type  : "text/uri-list",
     38        data  : "http://www.mozilla.org/" }
     39      ],[
     40      { type  : "text/uri-list",
     41        data  : "http://www.mozilla.org/" }
     42    ]];
     43    var drag1WrongFlavor = [[
     44      { type  : "text/plain",
     45        data  : "this is text/plain" }
     46    ]];
     47    var drag2 = [[
     48      { type  : "text/plain",
     49        data  : "this is text/plain" },
     50      { type  : "text/uri-list",
     51        data  : "http://www.mozilla.org/" }
     52    ]];
     53    var drag2WrongOrder = [[
     54      { type  : "text/uri-list",
     55        data  : "http://www.mozilla.org/" },
     56      { type  : "text/plain",
     57        data  : "this is text/plain" }
     58    ]];
     59    var dragfile = [[
     60      { type    : "application/x-moz-file",
     61        data    : testFile,
     62        eqTest(actualData, expectedData) {return expectedData.equals(actualData);} },
     63      { type    : "Files",
     64        data    : null }
     65    ]];
     66 
     67    function doOnDrop(aEvent) {
     68      gData = aEvent.dataTransfer.getData(dragDrop[0][0].type);
     69      aEvent.preventDefault(); // cancels event and keeps dropEffect
     70                               // as was before event.
     71    }
     72 
     73    function doOnDragStart(aEvent) {
     74      var dt = aEvent.dataTransfer;
     75      switch (aEvent.currentTarget.id) {
     76        case "drag2" :
     77          dt.setData("text/plain", "this is text/plain");
     78          // fallthrough
     79        case "drag1" :
     80          regularDtForDrag1 = dt;
     81          dt.setData("text/uri-list", "http://www.mozilla.org/");
     82          break;
     83        case "dragfile" :
     84          dt.mozSetDataAt("application/x-moz-file", testFile, 0);
     85          break;
     86      }
     87        dt.effectAllowed = "all";
     88    }
     89 
     90    function doOnDragEnter(aEvent) {
     91      gEnter = true;
     92      aEvent.dataTransfer.effectAllowed = "all";
     93      aEvent.preventDefault(); // sets target this element
     94    }
     95 
     96    function doOnDragOver(aEvent) {
     97      gOver = true;
     98      if (gSetDropEffect)
     99        aEvent.dataTransfer.dropEffect = "copy";
    100      aEvent.preventDefault();
    101    }
    102 
    103    SimpleTest.waitForExplicitFinish();
    104    async function test() {
    105      var startTime = new Date();
    106      var result;
    107 
    108      /* test synthesizeDrop */
    109      result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, null, window);
    110      ok(gEnter, "Fired dragenter");
    111      ok(gOver,  "Fired dragover");
    112      is(result, "copy", "copy is dropEffect");
    113      is(gData, dragDrop[0][0].data, "Received valid drop data");
    114 
    115      gSetDropEffect = false;
    116      result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, "link", window);
    117      is(result, "link", "link is dropEffect");
    118      gSetDropEffect = true;
    119 
    120      $("textB").focus();
    121      var content = synthesizeQueryTextContent(0, 100);
    122      ok(content, "synthesizeQueryTextContent should not be null");
    123      ok(content.succeeded, "synthesizeQueryTextContent should succeed");
    124      is(content.text, "I haz a content", "synthesizeQueryTextContent should be 'I haz a content': " + content.text);
    125 
    126      content = synthesizeQueryCaretRect(0);
    127      ok(content, "synthesizeQueryCaretRect should not be null");
    128      ok(content.succeeded, "synthesizeQueryCaretRect should succeed");
    129 
    130      content = synthesizeQueryTextRect(0, 100);
    131      ok(content, "synthesizeQueryTextRect should not be null");
    132      ok(content.succeeded, "synthesizeQueryTextRect should succeed");
    133 
    134      content = synthesizeQueryEditorRect();
    135      ok(content, "synthesizeQueryEditorRect should not be null");
    136      ok(content.succeeded, "synthesizeQueryEditorRect should succeed");
    137 
    138      content = synthesizeCharAtPoint(0, 0);
    139      ok(content, "synthesizeCharAtPoint should not be null");
    140      ok(content.succeeded, "synthesizeCharAtPoint should succeed");
    141 
    142      content = await synthesizeSelectionSet(0, 100);
    143      ok(content, "synthesizeSelectionSet should not be null");
    144      is(content, true, "synthesizeSelectionSet should succeed");
    145 
    146      var endTime = new Date();
    147      info("\nProfile::EventUtilsRunTime: " + (endTime-startTime) + "\n");
    148      SimpleTest.finish();
    149    };
    150  ]]>
    151  </script>
    152 
    153  <body xmlns="http://www.w3.org/1999/xhtml" onload="setTimeout(test, 0)">
    154    <input id="textB" value="I haz a content"/>
    155    <p id="display"></p>
    156    <div id="content" style="display:none;"></div>
    157    <pre id="test"></pre>
    158    <div id="drag1" ondragstart="doOnDragStart(event);">Need some space here</div>
    159    <p id="display"></p>
    160    <div id="content" style="display:none;"></div>
    161    <pre id="test"></pre>
    162    <div id="dragDrop" ondragover  ="doOnDragOver(event);"
    163                    ondragenter ="doOnDragEnter(event);"
    164                    ondragleave ="doOnDragLeave(event);"
    165                    ondrop      ="doOnDrop(event);">
    166    Need some depth and height to drag here
    167    </div>
    168    <div id="drag2" ondragstart="doOnDragStart(event);">Need more space</div>
    169    <div id="dragfile" ondragstart="doOnDragStart(event);">Sure why not here too</div>
    170  </body>
    171 </window>