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
This commit is contained in:
Emilio Cobos Álvarez 2019-08-23 10:14:39 +00:00
Родитель 9cd140da4a
Коммит dcb8e23c93
2 изменённых файлов: 56 добавлений и 4 удалений

Просмотреть файл

@ -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);
});

Просмотреть файл

@ -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