summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_607016.js
blob: 68e9d3fb6e3bc62178c4ee9ac4e794d0c6faaab5 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"use strict";

var stateBackup = ss.getBrowserState();

add_task(async function () {
  /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
  ignoreAllUncaughtExceptions();

  // Set the pref to true so we know exactly how many tabs should be restoring at
  // any given time. This guarantees that a finishing load won't start another.
  Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
  // Don't restore tabs lazily.
  Services.prefs.setBoolPref("browser.sessionstore.restore_tabs_lazily", false);

  let state = {
    windows: [
      {
        tabs: [
          {
            entries: [
              { url: "http://example.org#1", triggeringPrincipal_base64 },
            ],
            extData: { uniq: r() },
          },
          {
            entries: [
              { url: "http://example.org#2", triggeringPrincipal_base64 },
            ],
            extData: { uniq: r() },
          }, // overwriting
          {
            entries: [
              { url: "http://example.org#3", triggeringPrincipal_base64 },
            ],
            extData: { uniq: r() },
          }, // hiding
          {
            entries: [
              { url: "http://example.org#4", triggeringPrincipal_base64 },
            ],
            extData: { uniq: r() },
          }, // adding
          {
            entries: [
              { url: "http://example.org#5", triggeringPrincipal_base64 },
            ],
            extData: { uniq: r() },
          }, // deleting
          {
            entries: [
              { url: "http://example.org#6", triggeringPrincipal_base64 },
            ],
          }, // creating
        ],
        selected: 1,
      },
    ],
  };

  async function progressCallback() {
    let curState = JSON.parse(ss.getBrowserState());
    for (let i = 0; i < curState.windows[0].tabs.length; i++) {
      let tabState = state.windows[0].tabs[i];
      let tabCurState = curState.windows[0].tabs[i];
      if (tabState.extData) {
        is(
          tabCurState.extData.uniq,
          tabState.extData.uniq,
          "sanity check that tab has correct extData"
        );
      } else {
        // We aren't expecting there to be any data on extData, but panorama
        // may be setting something, so we need to make sure that if we do have
        // data, we just don't have anything for "uniq".
        ok(
          !("extData" in tabCurState) || !("uniq" in tabCurState.extData),
          "sanity check that tab doesn't have extData or extData doesn't have 'uniq'"
        );
      }
    }

    // Now we'll set a new unique value on 1 of the tabs
    let newUniq = r();
    ss.setCustomTabValue(gBrowser.tabs[1], "uniq", newUniq);
    let tabState = JSON.parse(ss.getTabState(gBrowser.tabs[1]));
    is(
      tabState.extData.uniq,
      newUniq,
      "(overwriting) new data is stored in extData"
    );

    // hide the next tab before closing it
    gBrowser.hideTab(gBrowser.tabs[2]);
    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[2]));
    ok(tabState.hidden, "(hiding) tab data has hidden == true");

    // set data that's not in a conflicting key
    let stillUniq = r();
    ss.setCustomTabValue(gBrowser.tabs[3], "stillUniq", stillUniq);
    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[3]));
    is(
      tabState.extData.stillUniq,
      stillUniq,
      "(adding) new data is stored in extData"
    );

    // remove the uniq value and make sure it's not there in the closed data
    ss.deleteCustomTabValue(gBrowser.tabs[4], "uniq");
    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[4]));
    // Since Panorama might have put data in, first check if there is extData.
    // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
    if ("extData" in tabState) {
      ok(
        !("uniq" in tabState.extData),
        "(deleting) uniq not in existing extData"
      );
    } else {
      ok(true, "(deleting) no data is stored in extData");
    }

    // set unique data on the tab that never had any set, make sure that's saved
    let newUniq2 = r();
    ss.setCustomTabValue(gBrowser.tabs[5], "uniq", newUniq2);
    tabState = JSON.parse(ss.getTabState(gBrowser.tabs[5]));
    is(
      tabState.extData.uniq,
      newUniq2,
      "(creating) new data is stored in extData where there was none"
    );

    while (gBrowser.tabs.length > 1) {
      BrowserTestUtils.removeTab(gBrowser.tabs[1]);
    }
  }

  // Set the test state.
  await setBrowserState(state);

  // Wait until the selected tab is restored and all others are pending.
  await Promise.all(
    Array.from(gBrowser.tabs, tab => {
      return tab == gBrowser.selectedTab
        ? promiseTabRestored(tab)
        : promiseTabRestoring(tab);
    })
  );

  // Kick off the actual tests.
  await progressCallback();

  // Cleanup.
  Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
  Services.prefs.clearUserPref("browser.sessionstore.restore_tabs_lazily");
  await promiseBrowserState(stateBackup);
});