summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser_tabs.js
blob: 8cdeef17d6bf1444d5732831ec44568e1d0826fa (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TAB_URL = "data:text/html,<title>foo</title>";

add_task(function* setup() {
  yield SpecialPowers.pushPrefEnv({
    set: [["dom.ipc.processCount", 1]]
  });
});

add_task(function* () {
  let { tab, document } = yield openAboutDebugging("tabs");

  // Wait for initial tabs list which may be empty
  let tabsElement = getTabList(document);
  if (tabsElement.querySelectorAll(".target-name").length == 0) {
    yield waitForMutation(tabsElement, { childList: true });
  }
  // Refresh tabsElement to get the .target-list element
  tabsElement = getTabList(document);

  let names = [...tabsElement.querySelectorAll(".target-name")];
  let initialTabCount = names.length;

  // Open a new tab in background and wait for its addition in the UI
  let onNewTab = waitForMutation(tabsElement, { childList: true });
  let newTab = yield addTab(TAB_URL, { background: true });
  yield onNewTab;

  // Check that the new tab appears in the UI, but with an empty name
  let newNames = [...tabsElement.querySelectorAll(".target-name")];
  newNames = newNames.filter(node => !names.includes(node));
  is(newNames.length, 1, "A new tab appeared in the list");
  let newTabTarget = newNames[0];

  // Then wait for title update, but on slow test runner, the title may already
  // be set to the expected value
  if (newTabTarget.textContent != "foo") {
    yield waitForContentMutation(newTabTarget);
  }

  // Check that the new tab appears in the UI
  is(newTabTarget.textContent, "foo", "The tab title got updated");
  is(newTabTarget.title, TAB_URL, "The tab tooltip is the url");

  // Finally, close the tab
  let onTabsUpdate = waitForMutation(tabsElement, { childList: true });
  yield removeTab(newTab);
  yield onTabsUpdate;

  // Check that the tab disappeared from the UI
  names = [...tabsElement.querySelectorAll("#tabs .target-name")];
  is(names.length, initialTabCount, "The tab disappeared from the UI");

  yield closeAboutDebugging(tab);
});