dom/tests/browser/browser_focus_steal_from_chrome_during_mousedown.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 function test() {
     2   waitForExplicitFinish();
     4   const kTestURI =
     5     "data:text/html," +
     6     "<script type=\"text/javascript\">" +
     7     "  function onMouseDown(aEvent) {" +
     8     "    document.getElementById('willBeFocused').focus();" +
     9     "    aEvent.preventDefault();" +
    10     "  }" +
    11     "</script>" +
    12     "<body id=\"body\">" +
    13     "<button id=\"eventTarget\" onmousedown=\"onMouseDown(event);\">click here</button>" +
    14     "<input id=\"willBeFocused\"></body>";
    16   let tab = gBrowser.addTab();
    17   gBrowser.selectedTab = tab;
    19   // Set the focus to the contents.
    20   tab.linkedBrowser.focus();
    21   // Load on the tab
    22   tab.linkedBrowser.addEventListener("load", onLoadTab, true);
    23   tab.linkedBrowser.loadURI(kTestURI);
    25   function onLoadTab() {
    26     tab.linkedBrowser.removeEventListener("load", onLoadTab, true);
    27     setTimeout(doTest, 0);
    28   }
    30   function doTest() {
    31     let fm = Components.classes["@mozilla.org/focus-manager;1"].
    32                         getService(Components.interfaces.nsIFocusManager);
    33     let eventTarget =
    34       tab.linkedBrowser.contentDocument.getElementById("eventTarget");
    36     for (var button = 0; button < 3; button++) {
    37       // Set focus to a chrome element before synthesizing a mouse down event.
    38       document.getElementById("urlbar").focus();
    40       is(fm.focusedElement, document.getElementById("urlbar").inputField,
    41          "Failed to move focus to search bar: button=" +
    42          button);
    44       EventUtils.synthesizeMouse(eventTarget, 10, 10, { "button": button },
    45                                  tab.linkedBrowser.contentWindow);
    47       let e = tab.linkedBrowser.contentDocument.activeElement;
    48       is(e.id, "willBeFocused",
    49          "The input element isn't active element: button=" + button);
    51       is(fm.focusedElement, e,
    52          "The active element isn't focused element in App level: button=" +
    53          button);
    54     }
    56     gBrowser.removeTab(tab);
    57     finish();
    58   }
    59 }

mercurial