summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabs/browser_multiselect_tabs_using_Ctrl.js
blob: 93a14a87a79e2034ccc73ef86d8deb1cbf822df6 (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
add_task(async function click() {
  const initialFocusedTab = await addTab();
  await BrowserTestUtils.switchTab(gBrowser, initialFocusedTab);
  const tab = await addTab();

  await triggerClickOn(tab, { ctrlKey: true });
  ok(
    tab.multiselected && gBrowser._multiSelectedTabsSet.has(tab),
    "Tab should be (multi) selected after click"
  );
  isnot(gBrowser.selectedTab, tab, "Multi-selected tab is not focused");
  is(gBrowser.selectedTab, initialFocusedTab, "Focused tab doesn't change");

  await triggerClickOn(tab, { ctrlKey: true });
  ok(
    !tab.multiselected && !gBrowser._multiSelectedTabsSet.has(tab),
    "Tab is not (multi) selected anymore"
  );
  is(
    gBrowser.selectedTab,
    initialFocusedTab,
    "Focused tab still doesn't change"
  );

  BrowserTestUtils.removeTab(initialFocusedTab);
  BrowserTestUtils.removeTab(tab);
});

add_task(async function clearSelection() {
  const tab1 = await addTab();
  const tab2 = await addTab();
  const tab3 = await addTab();

  await BrowserTestUtils.switchTab(gBrowser, tab1);
  info("We multi-select tab2 with ctrl key down");
  await triggerClickOn(tab2, { ctrlKey: true });

  ok(
    tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1),
    "Tab1 is (multi) selected"
  );
  ok(
    tab2.multiselected && gBrowser._multiSelectedTabsSet.has(tab2),
    "Tab2 is (multi) selected"
  );
  is(gBrowser.multiSelectedTabsCount, 2, "Two tabs (multi) selected");
  isnot(tab3, gBrowser.selectedTab, "Tab3 doesn't have focus");

  info("We select tab3 with Ctrl key up");
  await triggerClickOn(tab3, { ctrlKey: false });

  ok(!tab1.multiselected, "Tab1 is not (multi) selected");
  ok(!tab2.multiselected, "Tab2 is not (multi) selected");
  is(gBrowser.multiSelectedTabsCount, 0, "Multi-selection is cleared");
  is(tab3, gBrowser.selectedTab, "Tab3 has focus");

  BrowserTestUtils.removeTab(tab1);
  BrowserTestUtils.removeTab(tab2);
  BrowserTestUtils.removeTab(tab3);
});