diff --git a/browser/base/content/test/general/browser_selectpopup.js b/browser/base/content/test/general/browser_selectpopup.js index 94e11e960559..984565099abe 100644 --- a/browser/base/content/test/general/browser_selectpopup.js +++ b/browser/base/content/test/general/browser_selectpopup.js @@ -6,7 +6,7 @@ // to implement the dropdown list. const PAGECONTENT = - "" + " " + " " + " " + + " " + ""; -function openSelectPopup(selectPopup) +function openSelectPopup(selectPopup, withMouse) { - return new Promise((resolve, reject) => { - selectPopup.addEventListener("popupshown", function popupListener(event) { - selectPopup.removeEventListener("popupshown", popupListener, false) - resolve(); - }, false); - setTimeout(() => EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true, code: "ArrowDown" }), 1500); - }); + let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown"); + + if (withMouse) { + return Promise.all([popupShownPromise, + BrowserTestUtils.synthesizeMouseAtCenter("select", { }, gBrowser.selectedBrowser)]); + } + + setTimeout(() => EventUtils.synthesizeKey("KEY_ArrowDown", { altKey: true, code: "ArrowDown" }), 1500); + return popupShownPromise; } -function hideSelectPopup(selectPopup) +function hideSelectPopup(selectPopup, withEscape) { - return new Promise((resolve, reject) => { - selectPopup.addEventListener("popuphidden", function popupListener(event) { - selectPopup.removeEventListener("popuphidden", popupListener, false) - resolve(); - }, false); + let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popuphidden"); + + if (withEscape) { + EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }); + } + else { EventUtils.synthesizeKey("KEY_Enter", { code: "Enter" }); + } + + return popupShownPromise; +} + +function getChangeEvents() +{ + return ContentTask.spawn(gBrowser.selectedBrowser, {}, function() { + return content.wrappedJSObject.gChangeEvents; }); } @@ -90,9 +102,28 @@ add_task(function*() { is(menulist.menuBoxObject.activeChild, menulist.getItemAtIndex(3), "Select item 3 again"); is(menulist.selectedIndex, isWindows ? 3 : 1, "Select item 3 selectedIndex"); + is((yield getChangeEvents()), 0, "Before closed - number of change events"); + yield hideSelectPopup(selectPopup); is(menulist.selectedIndex, 3, "Item 3 still selected"); + is((yield getChangeEvents()), 1, "After closed - number of change events"); + + // Opening and closing the popup without changing the value should not fire a change event. + yield openSelectPopup(selectPopup, true); + yield hideSelectPopup(selectPopup, true); + is((yield getChangeEvents()), 1, "Open and close with no change - number of change events"); + EventUtils.synthesizeKey("VK_TAB", { }); + EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); + is((yield getChangeEvents()), 1, "Tab away from select with no change - number of change events"); + + yield openSelectPopup(selectPopup, true); + EventUtils.synthesizeKey("KEY_ArrowDown", { code: "ArrowDown" }); + yield hideSelectPopup(selectPopup, true); + is((yield getChangeEvents()), isWindows ? 2 : 1, "Open and close with change - number of change events"); + EventUtils.synthesizeKey("VK_TAB", { }); + EventUtils.synthesizeKey("VK_TAB", { shiftKey: true }); + is((yield getChangeEvents()), isWindows ? 2 : 1, "Tab away from select with change - number of change events"); gBrowser.removeCurrentTab(); }); diff --git a/toolkit/modules/SelectContentHelper.jsm b/toolkit/modules/SelectContentHelper.jsm index 533798df5025..b360bcf995a7 100644 --- a/toolkit/modules/SelectContentHelper.jsm +++ b/toolkit/modules/SelectContentHelper.jsm @@ -66,7 +66,7 @@ this.SelectContentHelper.prototype = { break; case "Forms:DismissedDropDown": - if (this.initialSelection != this.element.item[this.element.selectedIndex]) { + if (this.initialSelection != this.element.item(this.element.selectedIndex)) { let event = this.element.ownerDocument.createEvent("Events"); event.initEvent("change", true, true); this.element.dispatchEvent(event);