summaryrefslogtreecommitdiffstats
path: root/browser/components/firefoxview/tests/browser/browser_dragDrop_after_opening_fxViewTab.js
blob: 9ce547238a9632cccd22217467490ad79d337cdf (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that dragging and dropping tabs into tabbrowser works as intended
 * after opening the Firefox View tab for RTL builds. There was an issue where
 * tabs from dragged links were not dropped in the correct tab indexes
 * for RTL builds because logic for RTL builds did not take into consideration
 * hidden tabs like the Firefox View tab. This test makes sure that this behavior does not reoccur.
 */
add_task(async function () {
  info("Setting browser to RTL locale");
  await SpecialPowers.pushPrefEnv({ set: [["intl.l10n.pseudo", "bidi"]] });

  // window.RTL_UI doesn't update in existing windows when this pref is changed,
  // so we need to test in a new window.
  let win = await BrowserTestUtils.openNewBrowserWindow();

  const TEST_ROOT = getRootDirectory(gTestPath).replace(
    "chrome://mochitests/content",
    "https://example.com"
  );
  let newTab = win.gBrowser.tabs[0];

  let waitForTestTabPromise = BrowserTestUtils.waitForNewTab(
    win.gBrowser,
    TEST_ROOT + "file_new_tab_page.html"
  );
  let testTab = await BrowserTestUtils.openNewForegroundTab(
    win.gBrowser,
    TEST_ROOT + "file_new_tab_page.html"
  );
  await waitForTestTabPromise;

  let linkSrcEl = win.document.querySelector("a");
  ok(linkSrcEl, "Link exists");

  let dropPromise = BrowserTestUtils.waitForEvent(
    win.gBrowser.tabContainer,
    "drop"
  );

  /**
   * There should be 2 tabs:
   * 1. new tab (auto-generated)
   * 2. test tab
   */
  is(win.gBrowser.visibleTabs.length, 2, "There should be 2 tabs");

  // Now open Firefox View tab
  info("Opening Firefox View tab");
  await openFirefoxViewTab(win);

  /**
   * There should be 2 visible tabs:
   * 1. new tab (auto-generated)
   * 2. test tab
   * Firefox View tab is hidden.
   */
  is(
    win.gBrowser.visibleTabs.length,
    2,
    "There should still be 2 visible tabs after opening Firefox View tab"
  );

  info("Switching to test tab");
  await BrowserTestUtils.switchTab(win.gBrowser, testTab);

  let waitForDraggedTabPromise = BrowserTestUtils.waitForNewTab(
    win.gBrowser,
    "https://example.com/#test"
  );

  info("Dragging link between test tab and new tab");
  EventUtils.synthesizeDrop(
    linkSrcEl,
    testTab,
    [[{ type: "text/plain", data: "https://example.com/#test" }]],
    "link",
    win,
    win,
    {
      clientX: testTab.getBoundingClientRect().right,
    }
  );

  info("Waiting for drop event");
  await dropPromise;
  info("Waiting for dragged tab to be created");
  let draggedTab = await waitForDraggedTabPromise;

  /**
   * There should be 3 visible tabs:
   * 1. new tab (auto-generated)
   * 2. new tab from dragged link
   * 3. test tab
   *
   * In RTL build, it should appear in the following order:
   * <test tab> <link dragged tab> <new tab> | <FxView tab>
   */
  is(win.gBrowser.visibleTabs.length, 3, "There should be 3 tabs");
  is(
    win.gBrowser.visibleTabs.indexOf(newTab),
    0,
    "New tab should still be rightmost visible tab"
  );
  is(
    win.gBrowser.visibleTabs.indexOf(draggedTab),
    1,
    "Dragged link should positioned at new index"
  );
  is(
    win.gBrowser.visibleTabs.indexOf(testTab),
    2,
    "Test tab should be to the left of dragged tab"
  );

  await BrowserTestUtils.closeWindow(win);
  await SpecialPowers.popPrefEnv();
});