From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- toolkit/content/tests/browser/datetime/browser.ini | 74 +++ .../browser/datetime/browser_datetime_blur.js | 265 +++++++++ .../datetime/browser_datetime_datepicker.js | 369 ++++++++++++ .../datetime/browser_datetime_datepicker_clear.js | 56 ++ .../datetime/browser_datetime_datepicker_focus.js | 191 +++++++ .../datetime/browser_datetime_datepicker_keynav.js | 576 +++++++++++++++++++ .../datetime/browser_datetime_datepicker_markup.js | 483 ++++++++++++++++ .../browser_datetime_datepicker_min_max.js | 405 ++++++++++++++ .../browser_datetime_datepicker_monthyear.js | 209 +++++++ .../browser_datetime_datepicker_mousenav.js | 201 +++++++ .../browser_datetime_datepicker_prev_next_month.js | 534 ++++++++++++++++++ .../datetime/browser_datetime_showPicker.js | 52 ++ .../browser/datetime/browser_datetime_toplevel.js | 27 + .../tests/browser/datetime/browser_spinner.js | 180 ++++++ .../browser/datetime/browser_spinner_keynav.js | 622 +++++++++++++++++++++ toolkit/content/tests/browser/datetime/head.js | 441 +++++++++++++++ 16 files changed, 4685 insertions(+) create mode 100644 toolkit/content/tests/browser/datetime/browser.ini create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_blur.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_clear.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_focus.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_keynav.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_markup.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_min_max.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_monthyear.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_mousenav.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_datepicker_prev_next_month.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_showPicker.js create mode 100644 toolkit/content/tests/browser/datetime/browser_datetime_toplevel.js create mode 100644 toolkit/content/tests/browser/datetime/browser_spinner.js create mode 100644 toolkit/content/tests/browser/datetime/browser_spinner_keynav.js create mode 100644 toolkit/content/tests/browser/datetime/head.js (limited to 'toolkit/content/tests/browser/datetime') diff --git a/toolkit/content/tests/browser/datetime/browser.ini b/toolkit/content/tests/browser/datetime/browser.ini new file mode 100644 index 0000000000..e4991df5f0 --- /dev/null +++ b/toolkit/content/tests/browser/datetime/browser.ini @@ -0,0 +1,74 @@ +[DEFAULT] +support-files = + head.js + +[browser_datetime_blur.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 +[browser_datetime_datepicker.js] +# This file was skipped before new tests were written based on it in Bug 1676068 +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_clear.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_focus.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_keynav.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_markup.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_min_max.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 +[browser_datetime_datepicker_monthyear.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_datetime_datepicker_mousenav.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 +[browser_datetime_datepicker_prev_next_month.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 +[browser_datetime_showPicker.js] +# do not skip +[browser_datetime_toplevel.js] +[browser_spinner.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 +[browser_spinner_keynav.js] +skip-if = + tsan # Frequently times out on TSan + os == "win" && asan && fission # fails on asan/fission + os == "linux" && fission && socketprocess_networking && !debug # high frequency intermittent, Bug 1673140 diff --git a/toolkit/content/tests/browser/datetime/browser_datetime_blur.js b/toolkit/content/tests/browser/datetime/browser_datetime_blur.js new file mode 100644 index 0000000000..0671661e31 --- /dev/null +++ b/toolkit/content/tests/browser/datetime/browser_datetime_blur.js @@ -0,0 +1,265 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PAGE_CONTENT = `data:text/html, + + + + `; + +function getBlurEvents() { + return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + return content.wrappedJSObject.gBlurEvents; + }); +} + +function getDateFocusEvents() { + return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + return content.wrappedJSObject.gDateFocusEvents; + }); +} + +function getTextFocusEvents() { + return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + return content.wrappedJSObject.gTextFocusEvents; + }); +} + +/** + * Test that when a picker panel is opened by an input + * the input is not blurred + */ +add_task(async function test_parent_blur() { + info( + "Test that when a picker panel is opened by an input the parent is not blurred" + ); + + // Set "prefers-reduced-motion" media to "reduce" + // to avoid intermittent scroll failures (1803612, 1803687) + await SpecialPowers.pushPrefEnv({ + set: [["ui.prefersReducedMotion", 1]], + }); + Assert.ok( + matchMedia("(prefers-reduced-motion: reduce)").matches, + "The reduce motion mode is active" + ); + + await helper.openPicker(PAGE_CONTENT, false, "showPicker"); + + Assert.equal( + await getDateFocusEvents(), + 0, + "Date input field is not calling a focus event when the '.showPicker()' method is called" + ); + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { + const input = content.document.querySelector("#date"); + + Assert.ok( + !input.matches(":focus"), + `The keyboard focus is not placed on the date input after showPicker is called` + ); + }); + + let closedOnEsc = helper.promisePickerClosed(); + + // Close a date picker + EventUtils.synthesizeKey("KEY_Escape", {}); + + await closedOnEsc; + + Assert.equal( + helper.panel.state, + "closed", + "Panel should be closed on Escape" + ); + Assert.equal( + await getDateFocusEvents(), + 0, + "Date input field is not focused when its picker is dismissed with Escape key" + ); + Assert.equal( + await getBlurEvents(), + 0, + "Date input field is not blurred when the picker is closed with Escape key" + ); + + // Ensure focus is on the input field + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { + const input = content.document.querySelector("#date"); + + input.focus(); + + Assert.ok( + input.matches(":focus"), + `The keyboard focus is placed on the date input field` + ); + }); + Assert.equal( + await getDateFocusEvents(), + 1, + "A focus event was fired on the Date input field" + ); + + let readyOnKey = helper.waitForPickerReady(); + + // Open a date picker + EventUtils.synthesizeKey(" ", {}); + + await readyOnKey; + + Assert.equal( + helper.panel.state, + "open", + "Date picker panel should be opened" + ); + Assert.equal( + helper.panel + .querySelector("#dateTimePopupFrame") + .contentDocument.activeElement.getAttribute("role"), + "gridcell", + "The picker is opened and a calendar day is focused" + ); + + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { + const input = content.document.querySelector("#date"); + + Assert.ok( + input.matches(":focus"), + `The keyboard focus is retained on the date input field` + ); + Assert.equal( + input, + content.document.activeElement, + "Input field does not loose focus when its picker is opened and focused" + ); + }); + + Assert.equal( + await getBlurEvents(), + 0, + "Date input field is not blurred when its picker is opened and focused" + ); + Assert.equal( + await getDateFocusEvents(), + 1, + "No new focus events were fired on the Date input while its picker is opened" + ); + + info( + `Test that the date input field is not blurred after interacting + with a month-year panel` + ); + + // Move focus from the today's date to the month-year toggle button: + EventUtils.synthesizeKey("KEY_Tab", { repeat: 3 }); + + Assert.ok( + helper.getElement(BTN_MONTH_YEAR).matches(":focus"), + "The month-year toggle button is focused" + ); + + // Open the month-year selection panel: + EventUtils.synthesizeKey(" ", {}); + + Assert.equal( + helper.getElement(BTN_MONTH_YEAR).getAttribute("aria-expanded"), + "true", + "Month-year button is expanded when the spinners are shown" + ); + Assert.ok( + BrowserTestUtils.is_visible(helper.getElement(MONTH_YEAR_VIEW)), + "Month-year selection panel is visible" + ); + + // Move focus from the month-year toggle button to the year spinner: + EventUtils.synthesizeKey("KEY_Tab", { repeat: 2 }); + + // Change the year spinner value from February 2023 to March 2023: + EventUtils.synthesizeKey("KEY_ArrowDown", {}); + + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { + const input = content.document.querySelector("#date"); + + Assert.ok( + input.matches(":focus"), + `The keyboard focus is retained on the date input field` + ); + Assert.equal( + input, + content.document.activeElement, + "Input field does not loose focus when the month-year picker is opened and interacted with" + ); + }); + + Assert.equal( + await getBlurEvents(), + 0, + "Date input field is not blurred after interacting with a month-year panel" + ); + + info(`Test that when a picker panel is opened and then it is closed + with a click on the other field, the focus is updated`); + + let closedOnClick = helper.promisePickerClosed(); + + // Close a picker by clicking on another input + await BrowserTestUtils.synthesizeMouseAtCenter( + "#text", + {}, + gBrowser.selectedBrowser + ); + + await closedOnClick; + + Assert.equal( + helper.panel.state, + "closed", + "Panel should be closed when another element is clicked" + ); + + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => { + const inputText = content.document.querySelector("#text"); + const inputDate = content.document.querySelector("#date"); + + Assert.ok( + inputText.matches(":focus"), + `The keyboard focus is moved to the text input field` + ); + Assert.equal( + inputText, + content.document.activeElement, + "Text input field gains a focus when clicked" + ); + Assert.ok( + !inputDate.matches(":focus"), + `The keyboard focus is moved from the date input field` + ); + Assert.notEqual( + inputDate, + content.document.activeElement, + "Date input field is not focused anymore" + ); + }); + + Assert.equal( + await getBlurEvents(), + 1, + "Date input field is blurred when focus is moved to the text input field" + ); + Assert.equal( + await getTextFocusEvents(), + 1, + "Text input field is focused when it is clicked" + ); + Assert.equal( + await getDateFocusEvents(), + 1, + "No new focus events were fired on the Date input after its picker was closed" + ); + + await helper.tearDown(); + // Clear the prefers-reduced-motion pref from the test profile: + await SpecialPowers.popPrefEnv(); +}); diff --git a/toolkit/content/tests/browser/datetime/browser_datetime_datepicker.js b/toolkit/content/tests/browser/datetime/browser_datetime_datepicker.js new file mode 100644 index 0000000000..b7c4df8d2a --- /dev/null +++ b/toolkit/content/tests/browser/datetime/browser_datetime_datepicker.js @@ -0,0 +1,369 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +// Create a list of abbreviations for calendar class names +const W = "weekend", + O = "outside", + S = "selection", + R = "out-of-range", + T = "today", + P = "off-step"; + +// Calendar classlist for 2016-12. Used to verify the classNames are correct. +const calendarClasslist_201612 = [ + [W, O], + [O], + [O], + [O], + [], + [], + [W], + [W], + [], + [], + [], + [], + [], + [W], + [W], + [], + [], + [], + [S], + [], + [W], + [W], + [], + [], + [], + [], + [], + [W], + [W], + [], + [], + [], + [], + [], + [W], + [W, O], + [O], + [O], + [O], + [O], + [O], + [W, O], +]; + +/** + * Test that date picker opens to today's date when input field is blank + */ +add_task(async function test_datepicker_today() { + info("Test that date picker opens to today's date when input field is blank"); + + const date = new Date(); + + await helper.openPicker("data:text/html, "); + + if (date.getMonth() === new Date().getMonth()) { + Assert.equal( + helper.getElement(MONTH_YEAR).textContent, + DATE_FORMAT_LOCAL(date), + "Today's date is opened" + ); + Assert.equal( + helper.getElement(DAY_TODAY).getAttribute("aria-current"), + "date", + "Today's date is programmatically current" + ); + Assert.equal( + helper.getElement(DAY_TODAY).getAttribute("tabindex"), + "0", + "Today's date is included in the focus order, when nothing is selected" + ); + } else { + Assert.ok( + true, + "Skipping datepicker today test if month changes when opening picker." + ); + } + + await helper.tearDown(); +}); + +/** + * Test that date picker opens to the correct month, with calendar days + * displayed correctly, given a date value is set. + */ +add_task(async function test_datepicker_open() { + info("Test the date picker markup with a set input date value"); + + const inputValue = "2016-12-15"; + + await helper.openPicker( + `data:text/html, ` + ); + + Assert.equal( + helper.getElement(MONTH_YEAR).textContent, + DATE_FORMAT(new Date(inputValue)), + "2016-12-15 date is opened" + ); + + Assert.deepEqual( + getCalendarText(), + [ + "27", + "28", + "29", + "30", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + ], + "Calendar text for 2016-12 is correct" + ); + Assert.deepEqual( + getCalendarClassList(), + calendarClasslist_201612, + "2016-12 classNames of the picker are correct" + ); + Assert.equal( + helper.getElement(DAY_SELECTED).getAttribute("aria-selected"), + "true", + "Chosen date is programmatically selected" + ); + Assert.equal( + helper.getElement(DAY_SELECTED).getAttribute("tabindex"), + "0", + "Selected date is included in the focus order" + ); + + await helper.tearDown(); +}); + +/** + * Ensure that the datepicker popup appears correctly positioned when + * the input field has been transformed. + */ +add_task(async function test_datepicker_transformed_position() { + const inputValue = "2016-12-15"; + + const style = + "transform: translateX(7px) translateY(13px); border-top: 2px; border-left: 5px; margin: 30px;"; + const iframeContent = ``; + await helper.openPicker( + "data:text/html,