Bug 1881419 - Don't redundantly set input box value in datetime box. r=Gijs

This was a latent bug exposed by the regressing bug (it was probably
possible to trigger it in some other ways before my patch).

Let changes just be communicated via the regular change event, otherwise
we send a redundant message which can trigger a duplicate change event,
if the change event itself modifies the input value.

Differential Revision: https://phabricator.services.mozilla.com/D202713
This commit is contained in:
Emilio Cobos Álvarez 2024-02-26 15:12:49 +00:00
Родитель 86cc27eb44
Коммит d0d46992fe
4 изменённых файлов: 56 добавлений и 6 удалений

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

@ -8,6 +8,8 @@ skip-if = [
"os == 'linux' && fission && socketprocess_networking && !debug", # high frequency intermittent, Bug 1673140
]
["browser_datetime_change_event.js"]
["browser_datetime_datepicker.js"]
fail-if = ["a11y_checks"] # Bug 1854538 clicked td.outside may not be accessible
# This file was skipped before new tests were written based on it in Bug 1676068

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

@ -0,0 +1,46 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
async function open_change_and_expect_one_change_event(page) {
await helper.openPicker(page);
let changeEventPromise = helper.promiseChange();
// Click the first item (top-left corner) of the calendar
helper.click(helper.getElement(DAYS_VIEW).children[0]);
await changeEventPromise;
await helper.closePicker();
let changeEvents = await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
function () {
return content.wrappedJSObject.changeEventCount;
}
);
is(changeEvents, 1, "Should've got one change event");
await helper.tearDown();
}
add_task(async function test_change_event_simple() {
await open_change_and_expect_one_change_event(`data:text/html,
<!doctype html>
<script>
var changeEventCount = 0;
</script>
<input type="date" id="date" onchange="changeEventCount++">
`);
});
add_task(async function test_change_event_with_mutation() {
await open_change_and_expect_one_change_event(`data:text/html,
<!doctype html>
<script>
var changeEventCount = 0;
</script>
<input type="date" id="date" onchange="this.value = ''; changeEventCount++">
`);
});

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

@ -113,15 +113,19 @@ class DateTimeTestHelper {
EventUtils.synthesizeMouseAtCenter(element, {}, this.frame.contentWindow);
}
/**
* Close the panel and the tab
*/
async tearDown() {
async closePicker() {
if (this.panel.state != "closed") {
let pickerClosePromise = this.promisePickerClosed();
this.panel.hidePopup();
await pickerClosePromise;
}
}
/**
* Close the panel and the tab
*/
async tearDown() {
await this.closePicker();
BrowserTestUtils.removeTab(this.tab);
this.tab = null;
}

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

@ -68,8 +68,6 @@ export var DateTimePickerPanel = class {
closePicker(clear) {
if (clear) {
this.element.dispatchEvent(new CustomEvent("DateTimePickerValueCleared"));
} else {
this.setInputBoxValue(true);
}
this.pickerState = {};
this.type = undefined;