Commit dcb8e23c authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1561882 - Make sure to dispatch input and change consistently even if the...

Bug 1561882 - Make sure to dispatch input and change consistently even if the first causes us to get uninited. r=mconley,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D43061

--HG--
extra : moz-landing-system : lando
parent 9cd140da
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -1172,3 +1172,50 @@ add_task(async function test_handling_user_input() {

  BrowserTestUtils.removeTab(tab);
});

// Test that input and change events are dispatched consistently (bug 1561882).
add_task(async function test_event_destroys_popup() {
  const PAGE_CONTENT = `
<!doctype html>
<select>
  <option>a</option>
  <option>b</option>
</select>
<script>
gChangeEvents = 0;
gInputEvents = 0;
let select = document.querySelector("select");
  select.addEventListener("input", function() {
    gInputEvents++;
    this.style.display = "none";
    this.getBoundingClientRect();
  })
  select.addEventListener("change", function() {
    gChangeEvents++;
  })
</script>`;

  const pageUrl = "data:text/html," + escape(PAGE_CONTENT);
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);

  let menulist = document.getElementById("ContentSelectDropdown");
  let selectPopup = menulist.menupopup;

  // Test change and input events get handled consistently
  await openSelectPopup(selectPopup, "click");
  EventUtils.synthesizeKey("KEY_ArrowDown");
  await hideSelectPopup(selectPopup);

  is(
    await getChangeEvents(),
    1,
    "Should get change and input events consistently"
  );
  is(
    await getInputEvents(),
    1,
    "Should get change and input events consistently (input)"
  );

  BrowserTestUtils.removeTab(tab);
});
+9 −4
Original line number Diff line number Diff line
@@ -212,7 +212,12 @@ this.SelectContentHelper.prototype = {
        }

        let win = this.element.ownerGlobal;
        let selectedOption = this.element.item(this.element.selectedIndex);

        // Running arbitrary script below (dispatching events for example) can
        // close us, but we should still send events consistently.
        let element = this.element;

        let selectedOption = element.item(element.selectedIndex);

        // For ordering of events, we're using non-e10s as our guide here,
        // since the spec isn't exactly clear. In non-e10s:
@@ -229,7 +234,7 @@ this.SelectContentHelper.prototype = {

        // Clear active document no matter user selects via keyboard or mouse
        InspectorUtils.removeContentState(
          this.element,
          element,
          kStateActive,
          /* aClearActiveDocument */ true
        );
@@ -239,12 +244,12 @@ this.SelectContentHelper.prototype = {
          let inputEvent = new win.Event("input", {
            bubbles: true,
          });
          this.element.dispatchEvent(inputEvent);
          element.dispatchEvent(inputEvent);

          let changeEvent = new win.Event("change", {
            bubbles: true,
          });
          this.element.dispatchEvent(changeEvent);
          element.dispatchEvent(changeEvent);
        }

        // Fire click event