summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/datetime/browser_datetime_datepicker_clear.js
blob: 3c3de2dc981d600914590e9145c27dee4cd98def (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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";

async function testClear(key) {
  const inputValue = "2023-03-03";
  await helper.openPicker(
    `data:text/html, <input type="date" value="${inputValue}">`
  );
  let browser = helper.tab.linkedBrowser;

  Assert.equal(helper.panel.state, "open", "Panel should be opened");

  let closed = helper.promisePickerClosed();

  // Clear the input fields
  if (key) {
    // Move focus from the selected date to the Clear button:
    EventUtils.synthesizeKey("KEY_Tab", {});

    Assert.ok(
      helper.getElement(BTN_CLEAR).matches(":focus"),
      "The Clear button can receive keyboard focus"
    );

    EventUtils.synthesizeKey(key, {});
  } else {
    helper.click(helper.getElement(BTN_CLEAR));
  }

  await closed;

  await SpecialPowers.spawn(browser, [], () => {
    is(
      content.document.querySelector("input").value,
      "",
      "The input value is reset after the Clear button is pressed"
    );
  });

  await helper.tearDown();
}

add_task(async function test_datepicker_clear_keyboard() {
  await testClear(" ");
});

add_task(async function test_datepicker_clear_keyboard_enter() {
  await testClear("KEY_Enter");
});

add_task(async function test_datepicker_clear_mouse() {
  await testClear();
});