summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_page_title.js
blob: 9f84e67a94b3047d16bb08afa2b18dc74080f503 (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
"use strict";

const URL = "data:text/html,<title>initial title</title>";

add_task(async function () {
  // Create a new tab.
  let tab = BrowserTestUtils.addTab(gBrowser, URL);
  await promiseBrowserLoaded(tab.linkedBrowser);

  // Remove the tab.
  await promiseRemoveTabAndSessionState(tab);

  // Check the title.
  let [
    {
      state: { entries },
    },
  ] = ss.getClosedTabDataForWindow(window);
  is(entries[0].title, "initial title", "correct title");
});

add_task(async function () {
  // Create a new tab.
  let tab = BrowserTestUtils.addTab(gBrowser, URL);
  let browser = tab.linkedBrowser;
  await promiseBrowserLoaded(browser);

  // Flush to ensure we collected the initial title.
  await TabStateFlusher.flush(browser);

  // Set a new title.
  await SpecialPowers.spawn(browser, [], async function () {
    return new Promise(resolve => {
      docShell.chromeEventHandler.addEventListener(
        "DOMTitleChanged",
        () => resolve(),
        { once: true }
      );

      content.document.title = "new title";
    });
  });

  // Remove the tab.
  await promiseRemoveTabAndSessionState(tab);

  // Check the title.
  let [
    {
      state: { entries },
    },
  ] = ss.getClosedTabDataForWindow(window);
  is(entries[0].title, "new title", "correct title");
});