summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_multiselect_tabs_bookmark.js
blob: a24e72c0bbcdba6cdc423308aadfffca8a973d16 (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
81
/* 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/. */

async function addTab_example_com() {
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  const tab = BrowserTestUtils.addTab(gBrowser, "http://example.com/", {
    skipAnimation: true,
  });
  const browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);
  return tab;
}

add_task(async function test() {
  let tab1 = await addTab();
  let tab2 = await addTab();
  let tab3 = await addTab();

  let menuItemBookmarkTab = document.getElementById("context_bookmarkTab");
  let menuItemBookmarkSelectedTabs = document.getElementById(
    "context_bookmarkSelectedTabs"
  );

  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");

  await BrowserTestUtils.switchTab(gBrowser, tab1);
  await triggerClickOn(tab2, { ctrlKey: true });

  ok(tab1.multiselected, "Tab1 is multiselected");
  ok(tab2.multiselected, "Tab2 is multiselected");
  ok(!tab3.multiselected, "Tab3 is not multiselected");

  // Check the context menu with a non-multiselected tab
  updateTabContextMenu(tab3);
  is(menuItemBookmarkTab.hidden, false, "Bookmark Tab is visible");
  is(
    menuItemBookmarkSelectedTabs.hidden,
    true,
    "Bookmark Selected Tabs is hidden"
  );

  // Check the context menu with a multiselected tab and one unique page in the selection.
  updateTabContextMenu(tab2);
  is(menuItemBookmarkTab.hidden, true, "Bookmark Tab is visible");
  is(
    menuItemBookmarkSelectedTabs.hidden,
    false,
    "Bookmark Selected Tabs is hidden"
  );
  is(
    PlacesCommandHook.uniqueSelectedPages.length,
    1,
    "No more than one unique selected page"
  );

  info("Add a different page to selection");
  let tab4 = await addTab_example_com();
  await triggerClickOn(tab4, { ctrlKey: true });

  ok(tab4.multiselected, "Tab4 is multiselected");
  is(gBrowser.multiSelectedTabsCount, 3, "Three multiselected tabs");

  // Check the context menu with a multiselected tab and two unique pages in the selection.
  updateTabContextMenu(tab2);
  is(menuItemBookmarkTab.hidden, true, "Bookmark Tab is visible");
  is(
    menuItemBookmarkSelectedTabs.hidden,
    false,
    "Bookmark Selected Tabs is hidden"
  );
  is(
    PlacesCommandHook.uniqueSelectedPages.length,
    2,
    "More than one unique selected page"
  );

  for (let tab of [tab1, tab2, tab3, tab4]) {
    BrowserTestUtils.removeTab(tab);
  }
});