dom/tests/browser/browser_focus_steal_from_chrome_during_mousedown.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/browser/browser_focus_steal_from_chrome_during_mousedown.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +function test() {
     1.5 +  waitForExplicitFinish();
     1.6 +
     1.7 +  const kTestURI =
     1.8 +    "data:text/html," +
     1.9 +    "<script type=\"text/javascript\">" +
    1.10 +    "  function onMouseDown(aEvent) {" +
    1.11 +    "    document.getElementById('willBeFocused').focus();" +
    1.12 +    "    aEvent.preventDefault();" +
    1.13 +    "  }" +
    1.14 +    "</script>" +
    1.15 +    "<body id=\"body\">" +
    1.16 +    "<button id=\"eventTarget\" onmousedown=\"onMouseDown(event);\">click here</button>" +
    1.17 +    "<input id=\"willBeFocused\"></body>";
    1.18 +
    1.19 +  let tab = gBrowser.addTab();
    1.20 +  gBrowser.selectedTab = tab;
    1.21 +
    1.22 +  // Set the focus to the contents.
    1.23 +  tab.linkedBrowser.focus();
    1.24 +  // Load on the tab
    1.25 +  tab.linkedBrowser.addEventListener("load", onLoadTab, true);
    1.26 +  tab.linkedBrowser.loadURI(kTestURI);
    1.27 +
    1.28 +  function onLoadTab() {
    1.29 +    tab.linkedBrowser.removeEventListener("load", onLoadTab, true);
    1.30 +    setTimeout(doTest, 0);
    1.31 +  }
    1.32 +
    1.33 +  function doTest() {
    1.34 +    let fm = Components.classes["@mozilla.org/focus-manager;1"].
    1.35 +                        getService(Components.interfaces.nsIFocusManager);
    1.36 +    let eventTarget =
    1.37 +      tab.linkedBrowser.contentDocument.getElementById("eventTarget");
    1.38 +
    1.39 +    for (var button = 0; button < 3; button++) {
    1.40 +      // Set focus to a chrome element before synthesizing a mouse down event.
    1.41 +      document.getElementById("urlbar").focus();
    1.42 +
    1.43 +      is(fm.focusedElement, document.getElementById("urlbar").inputField,
    1.44 +         "Failed to move focus to search bar: button=" +
    1.45 +         button);
    1.46 +
    1.47 +      EventUtils.synthesizeMouse(eventTarget, 10, 10, { "button": button },
    1.48 +                                 tab.linkedBrowser.contentWindow);
    1.49 +
    1.50 +      let e = tab.linkedBrowser.contentDocument.activeElement;
    1.51 +      is(e.id, "willBeFocused",
    1.52 +         "The input element isn't active element: button=" + button);
    1.53 +
    1.54 +      is(fm.focusedElement, e,
    1.55 +         "The active element isn't focused element in App level: button=" +
    1.56 +         button);
    1.57 +    }
    1.58 +
    1.59 +    gBrowser.removeTab(tab);
    1.60 +    finish();
    1.61 +  }
    1.62 +}

mercurial