summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/browser/browser_oneOffs_contextMenu.js
blob: 60d46608cd1f866df21ff3c6c8c5486e0bf9900e (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that the right-click menu works correctly for the one-off buttons.
 */

const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";

let gMaxResults;

XPCOMUtils.defineLazyGetter(this, "oneOffSearchButtons", () => {
  return UrlbarTestUtils.getOneOffSearchButtons(window);
});

let originalEngine;
let newEngine;

// The one-off context menu should not be shown.
add_task(async function contextMenu_not_shown() {
  // Add a popupshown listener on the context menu that sets this
  // popupshownFired boolean.
  let popupshownFired = false;
  let onPopupshown = () => {
    popupshownFired = true;
  };
  let contextMenu = oneOffSearchButtons.querySelector(
    ".search-one-offs-context-menu"
  );
  contextMenu.addEventListener("popupshown", onPopupshown);

  // Do a search to open the view.
  await UrlbarTestUtils.promiseAutocompleteResultPopup({
    window,
    value: "foo",
  });

  // First, try to open the context menu on a remote engine.
  let allOneOffs = oneOffSearchButtons.getSelectableButtons(true);
  Assert.greater(allOneOffs.length, 0, "There should be at least one one-off");
  Assert.ok(
    allOneOffs[0].engine,
    "The first one-off should be a remote one-off"
  );
  EventUtils.synthesizeMouseAtCenter(allOneOffs[0], {
    type: "contextmenu",
    button: 2,
  });
  let timeout = 500;
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, timeout));
  Assert.ok(
    !popupshownFired,
    "popupshown should not be fired on a remote one-off"
  );

  // Now try to open the context menu on a local one-off.
  let localOneOffs = oneOffSearchButtons.localButtons;
  Assert.greater(
    localOneOffs.length,
    0,
    "There should be at least one local one-off"
  );
  EventUtils.synthesizeMouseAtCenter(localOneOffs[0], {
    type: "contextmenu",
    button: 2,
  });
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, timeout));
  Assert.ok(
    !popupshownFired,
    "popupshown should not be fired on a local one-off"
  );

  contextMenu.removeEventListener("popupshown", onPopupshown);
  await UrlbarTestUtils.promisePopupClose(window);
  await SpecialPowers.popPrefEnv();
});