browser/components/sessionstore/test/browser_607016.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 let stateBackup = ss.getBrowserState();
michael@0 6
michael@0 7 function cleanup() {
michael@0 8 // Reset the pref
michael@0 9 try {
michael@0 10 Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
michael@0 11 } catch (e) {}
michael@0 12 ss.setBrowserState(stateBackup);
michael@0 13 executeSoon(finish);
michael@0 14 }
michael@0 15
michael@0 16 function test() {
michael@0 17 /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
michael@0 18 waitForExplicitFinish();
michael@0 19 ignoreAllUncaughtExceptions();
michael@0 20
michael@0 21 // Set the pref to true so we know exactly how many tabs should be restoring at
michael@0 22 // any given time. This guarantees that a finishing load won't start another.
michael@0 23 Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
michael@0 24
michael@0 25 // We have our own progress listener for this test, which we'll attach before our state is set
michael@0 26 let progressListener = {
michael@0 27 onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
michael@0 28 if (aBrowser.__SS_restoreState == TAB_STATE_RESTORING &&
michael@0 29 aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
michael@0 30 aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
michael@0 31 aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW)
michael@0 32 progressCallback(aBrowser);
michael@0 33 }
michael@0 34 }
michael@0 35
michael@0 36 let state = { windows: [{ tabs: [
michael@0 37 { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
michael@0 38 { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting
michael@0 39 { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding
michael@0 40 { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }, // adding
michael@0 41 { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, // deleting
michael@0 42 { entries: [{ url: "http://example.org#6" }] } // creating
michael@0 43 ], selected: 1 }] };
michael@0 44
michael@0 45 function progressCallback(aBrowser) {
michael@0 46 // We'll remove the progress listener after the first one because we aren't
michael@0 47 // loading any other tabs
michael@0 48 window.gBrowser.removeTabsProgressListener(progressListener);
michael@0 49
michael@0 50 let curState = JSON.parse(ss.getBrowserState());
michael@0 51 for (let i = 0; i < curState.windows[0].tabs.length; i++) {
michael@0 52 let tabState = state.windows[0].tabs[i];
michael@0 53 let tabCurState = curState.windows[0].tabs[i];
michael@0 54 if (tabState.extData) {
michael@0 55 is(tabCurState.extData["uniq"], tabState.extData["uniq"],
michael@0 56 "sanity check that tab has correct extData");
michael@0 57 }
michael@0 58 else {
michael@0 59 // We aren't expecting there to be any data on extData, but panorama
michael@0 60 // may be setting something, so we need to make sure that if we do have
michael@0 61 // data, we just don't have anything for "uniq".
michael@0 62 ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData),
michael@0 63 "sanity check that tab doesn't have extData or extData doesn't have 'uniq'");
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 // Now we'll set a new unique value on 1 of the tabs
michael@0 68 let newUniq = r();
michael@0 69 ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq);
michael@0 70 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 71 let closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
michael@0 72 is(closedTabData.state.extData.uniq, newUniq,
michael@0 73 "(overwriting) new data is stored in extData");
michael@0 74
michael@0 75 // hide the next tab before closing it
michael@0 76 gBrowser.hideTab(gBrowser.tabs[1]);
michael@0 77 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 78 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
michael@0 79 ok(closedTabData.state.hidden, "(hiding) tab data has hidden == true");
michael@0 80
michael@0 81 // set data that's not in a conflicting key
michael@0 82 let stillUniq = r();
michael@0 83 ss.setTabValue(gBrowser.tabs[1], "stillUniq", stillUniq);
michael@0 84 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 85 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
michael@0 86 is(closedTabData.state.extData.stillUniq, stillUniq,
michael@0 87 "(adding) new data is stored in extData");
michael@0 88
michael@0 89 // remove the uniq value and make sure it's not there in the closed data
michael@0 90 ss.deleteTabValue(gBrowser.tabs[1], "uniq");
michael@0 91 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 92 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
michael@0 93 // Since Panorama might have put data in, first check if there is extData.
michael@0 94 // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
michael@0 95 if ("extData" in closedTabData.state) {
michael@0 96 ok(!("uniq" in closedTabData.state.extData),
michael@0 97 "(deleting) uniq not in existing extData");
michael@0 98 }
michael@0 99 else {
michael@0 100 ok(true, "(deleting) no data is stored in extData");
michael@0 101 }
michael@0 102
michael@0 103 // set unique data on the tab that never had any set, make sure that's saved
michael@0 104 let newUniq2 = r();
michael@0 105 ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq2);
michael@0 106 gBrowser.removeTab(gBrowser.tabs[1]);
michael@0 107 closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0];
michael@0 108 is(closedTabData.state.extData.uniq, newUniq2,
michael@0 109 "(creating) new data is stored in extData where there was none");
michael@0 110
michael@0 111 cleanup();
michael@0 112 }
michael@0 113
michael@0 114 window.gBrowser.addTabsProgressListener(progressListener);
michael@0 115 ss.setBrowserState(JSON.stringify(state));
michael@0 116 }
michael@0 117

mercurial