tor-browser

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

test_bug976673.html (3181B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=976673
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 976673</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=976673">Mozilla Bug 976673</a>
     15 <p id="display"></p>
     16 <div id="content" style="display: none">
     17 
     18 </div>
     19 <pre id="test">
     20 </pre>
     21 <input id="input" onfocus="event.target.value = event.type;"
     22                  onblur="event.target.value = event.type;">
     23 <button id="button">set focus</button>
     24 <iframe id="iframe" src="http://example.org:80/tests/dom/base/test/iframe_bug976673.html"></iframe>
     25 <script>
     26 
     27 SimpleTest.waitForExplicitFinish();
     28 
     29 // In e10s mode, ContentCacheInChild tries to retrieve selected text and
     30 // caret position when IMEContentObserver notifies IME of focus.  At this time,
     31 // we hit assertion in ContentIterator.
     32 SimpleTest.expectAssertions(0, 6);
     33 
     34 window.addEventListener("mousedown", function (aEvent) { aEvent.preventDefault(); });
     35 
     36 function testSetFocus(aEventType, aCallback)
     37 {
     38  var description = "Setting focus from " + aEventType + " handler: ";
     39 
     40  var iframe = document.getElementById("iframe");
     41  iframe.contentWindow.focus();
     42 
     43  window.addEventListener("message", function (aEvent) {
     44    is(aEvent.data, "input-value: focus",
     45       description + "<input> in the iframe should get focus");
     46 
     47 
     48    var input = document.getElementById("input");
     49    input.value = "";
     50 
     51    var button = document.getElementById("button");
     52 
     53    var movingFocus = false;
     54    button.addEventListener(aEventType,
     55                            function (event) {
     56                              movingFocus = true;
     57                              input.focus();
     58                              event.preventDefault();
     59                              button.removeEventListener(aEventType, arguments.callee, true);
     60                            }, true);
     61 
     62    synthesizeMouseAtCenter(button, {});
     63 
     64    window.addEventListener("message", function (event) {
     65      if (movingFocus) {
     66        is(event.data, "input-value: blur",
     67           description + "<input> in the iframe should get blur");
     68        is(input.value, "focus",
     69           description + "<input> in the parent should get focus");
     70      } else {
     71        is(event.data, "input-value: focus",
     72           description + "<input> in the iframe should keep having focus");
     73      }
     74 
     75      setTimeout(aCallback, 0);
     76    }, {once: true});
     77 
     78    iframe.contentWindow.postMessage("check", "*");
     79  }, {once: true});
     80 
     81  iframe.contentWindow.postMessage("init", "*");
     82 }
     83 
     84 function runTests()
     85 {
     86  testSetFocus("mousedown",
     87    function () {
     88      testSetFocus("mouseup",
     89        function () {
     90          testSetFocus("click",
     91            function () {
     92              testSetFocus("DoNothing", // testing wihout moving focus by script
     93                function () {
     94                  SimpleTest.finish();
     95                });
     96            });
     97        });
     98    });
     99 }
    100 
    101 SimpleTest.waitForFocus(runTests);
    102 
    103 </script>
    104 </body>
    105 </html>