tor-browser

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

test_bug674770-1.html (3113B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=674770
      5 -->
      6 <head>
      7  <title>Test for Bug 674770</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674770">Mozilla Bug 674770</a>
     14 <p id="display"></p>
     15 <div id="content">
     16 <a href="file_bug674770-1.html" id="link1">test</a>
     17 <div contenteditable>
     18 <a href="file_bug674770-1.html" id="link2">test</a>
     19 </div>
     20 </div>
     21 <pre id="test">
     22 <script type="application/javascript">
     23 
     24 SimpleTest.waitForExplicitFinish();
     25 SimpleTest.waitForFocus(function() {
     26  SpecialPowers.pushPrefEnv({"set": [["middlemouse.paste", true]]}, startTests);
     27 });
     28 
     29 function startTests() {
     30  var tests = [
     31    { description: "Testing link in <div>: ",
     32      target() { return document.querySelector("#link1"); },
     33      linkShouldWork: true },
     34    { description: "Testing link in <div contenteditable>: ",
     35      target() { return document.querySelector("#link2"); },
     36      linkShouldWork: false },
     37  ];
     38  var currentTest;
     39  function runNextTest() {
     40    localStorage.removeItem("clicked");
     41    currentTest = tests.shift();
     42    if (!currentTest) {
     43      SimpleTest.finish();
     44      return;
     45    }
     46    ok(true, currentTest.description + "Starting to test...");
     47    synthesizeMouseAtCenter(currentTest.target(), { button: 1 });
     48  }
     49 
     50 
     51  addEventListener("storage", function(e) {
     52    is(e.key, "clicked", currentTest.description + "Key should always be 'clicked'");
     53    is(e.newValue, "true", currentTest.description + "Value should always be 'true'");
     54    ok(currentTest.linkShouldWork, currentTest.description + "The click operation on the link " + (currentTest.linkShouldWork ? "should work" : "shouldn't work"));
     55    SimpleTest.executeSoon(runNextTest);
     56  }, false);
     57 
     58  SpecialPowers.wrap(window).addEventListener("auxclick", function(aEvent) {
     59    // When the click event should cause default action, e.g., opening the link,
     60    // the event shouldn't have been consumed except the link handler.
     61    // However, in e10s mode, it's not consumed during propagating the event but
     62    // in non-e10s mode, it's consumed during the propagation.  Therefore,
     63    // we cannot check defaultPrevented value when the link should work as is
     64    // if there is no way to detect if it's running in e10s mode or not.
     65    // So, let's skip checking Event.defaultPrevented value when the link should
     66    // work.  In such case, we should receive "storage" event later.
     67    if (currentTest.linkShouldWork) {
     68      return;
     69    }
     70 
     71    ok(SpecialPowers.defaultPreventedInAnyGroup(aEvent),
     72       currentTest.description + "The default action should be consumed because the link should work as is");
     73    if (SpecialPowers.defaultPreventedInAnyGroup(aEvent)) {
     74      // In this case, "storage" event won't be fired.
     75      SimpleTest.executeSoon(runNextTest);
     76    }
     77  }, { mozSystemGroup: true });
     78 
     79  SimpleTest.executeSoon(runNextTest);
     80 }
     81 
     82 </script>
     83 </pre>
     84 </body>
     85 </html>