From d0d46992fe06f7578ec1b1f2ce6e694d0b49ddab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Feb 2024 15:12:49 +0000 Subject: [PATCH] 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 --- .../tests/browser/datetime/browser.toml | 2 + .../datetime/browser_datetime_change_event.js | 46 +++++++++++++++++++ .../content/tests/browser/datetime/head.js | 12 +++-- toolkit/modules/DateTimePickerPanel.sys.mjs | 2 - 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_change_event.js diff --git a/toolkit/content/tests/browser/datetime/browser.toml b/toolkit/content/tests/browser/datetime/browser.toml index 6e8580ddc447..8e5157a34068 100644 --- a/toolkit/content/tests/browser/datetime/browser.toml +++ b/toolkit/content/tests/browser/datetime/browser.toml @@ -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 diff --git a/toolkit/content/tests/browser/datetime/browser_datetime_change_event.js b/toolkit/content/tests/browser/datetime/browser_datetime_change_event.js new file mode 100644 index 000000000000..920653778ac8 --- /dev/null +++ b/toolkit/content/tests/browser/datetime/browser_datetime_change_event.js @@ -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, + + + + `); +}); + +add_task(async function test_change_event_with_mutation() { + await open_change_and_expect_one_change_event(`data:text/html, + + + + `); +}); diff --git a/toolkit/content/tests/browser/datetime/head.js b/toolkit/content/tests/browser/datetime/head.js index bbef72873cab..46e2c78af57c 100644 --- a/toolkit/content/tests/browser/datetime/head.js +++ b/toolkit/content/tests/browser/datetime/head.js @@ -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; } diff --git a/toolkit/modules/DateTimePickerPanel.sys.mjs b/toolkit/modules/DateTimePickerPanel.sys.mjs index 8d67cb0d8e4e..f20f2c1668d6 100644 --- a/toolkit/modules/DateTimePickerPanel.sys.mjs +++ b/toolkit/modules/DateTimePickerPanel.sys.mjs @@ -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;