summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_687710_2.js
blob: 81d3c55379b50d8b2fa94454ac7579db870dfb31 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that the fix for bug 687710 isn't too aggressive -- shentries which are
// cousins should be able to share bfcache entries.

var stateBackup = ss.getBrowserState();

var state = {
  entries: [
    {
      docIdentifier: 1,
      url: "http://example.com?1",
      triggeringPrincipal_base64,
      children: [
        {
          docIdentifier: 10,
          url: "http://example.com?10",
          triggeringPrincipal_base64,
        },
      ],
    },
    {
      docIdentifier: 1,
      url: "http://example.com?1#a",
      triggeringPrincipal_base64,
      children: [
        {
          docIdentifier: 10,
          url: "http://example.com?10#aa",
          triggeringPrincipal_base64,
        },
      ],
    },
  ],
};

add_task(async function test() {
  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
  await promiseTabState(tab, state);
  if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
    await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
      function compareEntries(i, j, history) {
        let e1 = history.getEntryAtIndex(i);
        let e2 = history.getEntryAtIndex(j);

        ok(e1.sharesDocumentWith(e2), `${i} should share doc with ${j}`);
        is(e1.childCount, e2.childCount, `Child count mismatch (${i}, ${j})`);

        for (let c = 0; c < e1.childCount; c++) {
          let c1 = e1.GetChildAt(c);
          let c2 = e2.GetChildAt(c);

          ok(
            c1.sharesDocumentWith(c2),
            `Cousins should share documents. (${i}, ${j}, ${c})`
          );
        }
      }

      let history = docShell.browsingContext.childSessionHistory.legacySHistory;

      is(history.count, 2, "history.count");
      for (let i = 0; i < history.count; i++) {
        for (let j = 0; j < history.count; j++) {
          compareEntries(i, j, history);
        }
      }
    });
  } else {
    function compareEntries(i, j, history) {
      let e1 = history.getEntryAtIndex(i);
      let e2 = history.getEntryAtIndex(j);

      ok(e1.sharesDocumentWith(e2), `${i} should share doc with ${j}`);
      is(e1.childCount, e2.childCount, `Child count mismatch (${i}, ${j})`);

      for (let c = 0; c < e1.childCount; c++) {
        let c1 = e1.GetChildAt(c);
        let c2 = e2.GetChildAt(c);

        ok(
          c1.sharesDocumentWith(c2),
          `Cousins should share documents. (${i}, ${j}, ${c})`
        );
      }
    }

    let history = tab.linkedBrowser.browsingContext.sessionHistory;

    is(history.count, 2, "history.count");
    for (let i = 0; i < history.count; i++) {
      for (let j = 0; j < history.count; j++) {
        compareEntries(i, j, history);
      }
    }
  }

  ss.setBrowserState(stateBackup);
});