summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/windows/ia2/browser_osPicker.js
blob: b14f2d0a5f7e3c0a457c7c7d19bba6fde6c919aa (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
/* 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";

addAccessibleTask(
  `<input id="file" type="file">`,
  async function (browser, docAcc) {
    info("Focusing file input");
    await runPython(`
      global focused
      focused = WaitForWinEvent(EVENT_OBJECT_FOCUS, "file")
    `);
    const file = findAccessibleChildByID(docAcc, "file");
    file.takeFocus();
    await runPython(`
      focused.wait()
    `);
    ok(true, "file input got focus");
    info("Opening file picker");
    await runPython(`
      global focused
      focused = WaitForWinEvent(
        EVENT_OBJECT_FOCUS,
        lambda evt: getWindowClass(evt.hwnd) == "Edit"
      )
    `);
    file.doAction(0);
    await runPython(`
      global event
      event = focused.wait()
    `);
    ok(true, "Picker got focus");
    info("Dismissing picker");
    await runPython(`
      # If the picker is dismissed too quickly, it seems to re-enable the root
      # window before we do. This sleep isn't ideal, but it's more likely to
      # reproduce the case that our root window gets focus before it is enabled.
      # See bug 1883568 for further details.
      import time
      time.sleep(1)
      focused = WaitForWinEvent(EVENT_OBJECT_FOCUS, "file")
      # Sending key presses to the picker is unreliable, so use WM_CLOSE.
      pickerRoot = user32.GetAncestor(event.hwnd, GA_ROOT)
      user32.SendMessageW(pickerRoot, WM_CLOSE, 0, 0)
      focused.wait()
    `);
    ok(true, "file input got focus");
  }
);