summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_switchTab_closesUrlbarPopup.js
blob: a9b0eb7b1a2765c92ea0f9f1dd07da611c748fa6 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/**
 * Checks that switching tabs closes the urlbar popup.
 */

"use strict";

add_task(async function () {
  let tab1 = BrowserTestUtils.addTab(gBrowser);
  let tab2 = BrowserTestUtils.addTab(gBrowser);

  registerCleanupFunction(async () => {
    await PlacesUtils.history.clear();
    BrowserTestUtils.removeTab(tab1);
    BrowserTestUtils.removeTab(tab2);
  });

  // Add a couple of dummy entries to ensure the history popup will open.
  await PlacesTestUtils.addVisits([
    { uri: makeURI("http://example.com/foo") },
    { uri: makeURI("http://example.com/foo/bar") },
  ]);

  // When urlbar in a new tab is focused, and a tab switch occurs,
  // the urlbar popup should be closed
  await BrowserTestUtils.switchTab(gBrowser, tab2);
  gURLBar.focus(); // focus the urlbar in the tab we will switch to
  await BrowserTestUtils.switchTab(gBrowser, tab1);
  // Now open the popup.
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "",
  });
  // Check that the popup closes when we switch tab.
  await UrlbarTestUtils.promisePopupClose(window, () => {
    return BrowserTestUtils.switchTab(gBrowser, tab2);
  });
  Assert.ok(true, "Popup was successfully closed");
});