summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/test/browser/browser_close_tab.js
blob: f0ed806b3b2131dd727752ad42e6bef0a8141bb6 (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
/* 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/. */

const { FormHistory } = ChromeUtils.importESModule(
  "resource://gre/modules/FormHistory.sys.mjs"
);

add_task(async function test() {
  const url = `data:text/html,<input type="text" name="field1">`;

  // Open a dummy tab.
  await BrowserTestUtils.withNewTab({ gBrowser, url }, async function () {});

  await BrowserTestUtils.withNewTab(
    { gBrowser, url },
    async function (browser) {
      const { autoCompletePopup } = browser;
      const mockHistory = [{ op: "add", fieldname: "field1", value: "value1" }];

      await FormHistory.update([{ op: "remove" }, ...mockHistory]);
      await SpecialPowers.spawn(browser, [], async function () {
        const input = content.document.querySelector("input");

        input.focus();
      });

      // show popup
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await TestUtils.waitForCondition(() => {
        return autoCompletePopup.popupOpen;
      });

      gBrowser.removeCurrentTab();

      await TestUtils.waitForCondition(() => {
        return !autoCompletePopup.popupOpen;
      });

      Assert.ok(!autoCompletePopup.popupOpen, "Ensure the popup is closed.");
    }
  );
});