Bug 1186398, perform correct check when comparing if the select value has changed, r=felipe

This commit is contained in:
Neil Deakin 2015-07-27 07:33:55 -04:00
Родитель c6c40b4b8f
Коммит 16c5043427
2 изменённых файлов: 48 добавлений и 17 удалений

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

@ -6,7 +6,7 @@
// to implement the dropdown list.
const PAGECONTENT =
"<html><body onload='document.body.firstChild.focus()'><select>" +
"<html><body onload='gChangeEvents = 0; document.body.firstChild.focus()'><select onchange='gChangeEvents++'>" +
" <optgroup label='First Group'>" +
" <option value=One>One" +
" <option value=Two>Two" +
@ -20,28 +20,40 @@ const PAGECONTENT =
" <optgroup label='Third Group'>" +
" <option value=Seven>Seven" +
" <option value=Eight>Eight" +
" </optgroup>" +
" </optgroup></select><input>" +
"</body></html>";
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();
});

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

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