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

const URL = "data:text/html;charset=utf-8,<a href=%23>clickme</a>";

add_task(function* test_duplicate() {
  // Create new tab.
  let tab = gBrowser.addTab(URL);
  let browser = tab.linkedBrowser;
  yield promiseBrowserLoaded(browser);

  // Flush to empty any queued update messages.
  yield TabStateFlusher.flush(browser);

  // Click the link to navigate, this will add second shistory entry.
  yield ContentTask.spawn(browser, null, function* () {
    return new Promise(resolve => {
      addEventListener("hashchange", function onHashChange() {
        removeEventListener("hashchange", onHashChange);
        resolve();
      });

      // Click the link.
      content.document.querySelector("a").click();
    });
  });

  // Duplicate the tab.
  let tab2 = ss.duplicateTab(window, tab);

  // Wait until the tab has fully restored.
  yield promiseTabRestored(tab2);
  yield TabStateFlusher.flush(tab2.linkedBrowser);

  // There should be two history entries now.
  let {entries} = JSON.parse(ss.getTabState(tab2));
  is(entries.length, 2, "there are two shistory entries");

  // Cleanup.
  yield promiseRemoveTab(tab2);
  yield promiseRemoveTab(tab);
});

add_task(function* test_duplicate_remove() {
  // Create new tab.
  let tab = gBrowser.addTab(URL);
  let browser = tab.linkedBrowser;
  yield promiseBrowserLoaded(browser);

  // Flush to empty any queued update messages.
  yield TabStateFlusher.flush(browser);

  // Click the link to navigate, this will add second shistory entry.
  yield ContentTask.spawn(browser, null, function* () {
    return new Promise(resolve => {
      addEventListener("hashchange", function onHashChange() {
        removeEventListener("hashchange", onHashChange);
        resolve();
      });

      // Click the link.
      content.document.querySelector("a").click();
    });
  });

  // Duplicate the tab.
  let tab2 = ss.duplicateTab(window, tab);

  // Before the duplication finished, remove the tab.
  yield Promise.all([promiseRemoveTab(tab), promiseTabRestored(tab2)]);
  yield TabStateFlusher.flush(tab2.linkedBrowser);

  // There should be two history entries now.
  let {entries} = JSON.parse(ss.getTabState(tab2));
  is(entries.length, 2, "there are two shistory entries");

  // Cleanup.
  yield promiseRemoveTab(tab2);
});