browser_tabs.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. const TAB_URL = "data:text/html,<title>foo</title>";
  5. add_task(function* setup() {
  6. yield SpecialPowers.pushPrefEnv({
  7. set: [["dom.ipc.processCount", 1]]
  8. });
  9. });
  10. add_task(function* () {
  11. let { tab, document } = yield openAboutDebugging("tabs");
  12. // Wait for initial tabs list which may be empty
  13. let tabsElement = getTabList(document);
  14. if (tabsElement.querySelectorAll(".target-name").length == 0) {
  15. yield waitForMutation(tabsElement, { childList: true });
  16. }
  17. // Refresh tabsElement to get the .target-list element
  18. tabsElement = getTabList(document);
  19. let names = [...tabsElement.querySelectorAll(".target-name")];
  20. let initialTabCount = names.length;
  21. // Open a new tab in background and wait for its addition in the UI
  22. let onNewTab = waitForMutation(tabsElement, { childList: true });
  23. let newTab = yield addTab(TAB_URL, { background: true });
  24. yield onNewTab;
  25. // Check that the new tab appears in the UI, but with an empty name
  26. let newNames = [...tabsElement.querySelectorAll(".target-name")];
  27. newNames = newNames.filter(node => !names.includes(node));
  28. is(newNames.length, 1, "A new tab appeared in the list");
  29. let newTabTarget = newNames[0];
  30. // Then wait for title update, but on slow test runner, the title may already
  31. // be set to the expected value
  32. if (newTabTarget.textContent != "foo") {
  33. yield waitForContentMutation(newTabTarget);
  34. }
  35. // Check that the new tab appears in the UI
  36. is(newTabTarget.textContent, "foo", "The tab title got updated");
  37. is(newTabTarget.title, TAB_URL, "The tab tooltip is the url");
  38. // Finally, close the tab
  39. let onTabsUpdate = waitForMutation(tabsElement, { childList: true });
  40. yield removeTab(newTab);
  41. yield onTabsUpdate;
  42. // Check that the tab disappeared from the UI
  43. names = [...tabsElement.querySelectorAll("#tabs .target-name")];
  44. is(names.length, initialTabCount, "The tab disappeared from the UI");
  45. yield closeAboutDebugging(tab);
  46. });