Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * This test ensures that closed tabs are merged when restoring |
michael@0 | 6 | * a window state without overwriting tabs. |
michael@0 | 7 | */ |
michael@0 | 8 | add_task(function () { |
michael@0 | 9 | const initialState = { |
michael@0 | 10 | windows: [{ |
michael@0 | 11 | tabs: [ |
michael@0 | 12 | { entries: [{ url: "about:blank" }] } |
michael@0 | 13 | ], |
michael@0 | 14 | _closedTabs: [ |
michael@0 | 15 | { state: { entries: [{ ID: 1000, url: "about:blank" }]} }, |
michael@0 | 16 | { state: { entries: [{ ID: 1001, url: "about:blank" }]} } |
michael@0 | 17 | ] |
michael@0 | 18 | }] |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | const restoreState = { |
michael@0 | 22 | windows: [{ |
michael@0 | 23 | tabs: [ |
michael@0 | 24 | { entries: [{ url: "about:robots" }] } |
michael@0 | 25 | ], |
michael@0 | 26 | _closedTabs: [ |
michael@0 | 27 | { state: { entries: [{ ID: 1002, url: "about:robots" }]} }, |
michael@0 | 28 | { state: { entries: [{ ID: 1003, url: "about:robots" }]} }, |
michael@0 | 29 | { state: { entries: [{ ID: 1004, url: "about:robots" }]} } |
michael@0 | 30 | ] |
michael@0 | 31 | }] |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | const maxTabsUndo = 4; |
michael@0 | 35 | gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", maxTabsUndo); |
michael@0 | 36 | |
michael@0 | 37 | // Open a new window and restore it to an initial state. |
michael@0 | 38 | let win = yield promiseNewWindowLoaded({private: false}); |
michael@0 | 39 | SessionStore.setWindowState(win, JSON.stringify(initialState), true); |
michael@0 | 40 | is(SessionStore.getClosedTabCount(win), 2, "2 closed tabs after restoring initial state"); |
michael@0 | 41 | |
michael@0 | 42 | // Restore the new state but do not overwrite existing tabs (this should |
michael@0 | 43 | // cause the closed tabs to be merged). |
michael@0 | 44 | SessionStore.setWindowState(win, JSON.stringify(restoreState), false); |
michael@0 | 45 | |
michael@0 | 46 | // Verify the windows closed tab data is correct. |
michael@0 | 47 | let iClosed = initialState.windows[0]._closedTabs; |
michael@0 | 48 | let rClosed = restoreState.windows[0]._closedTabs; |
michael@0 | 49 | let cData = JSON.parse(SessionStore.getClosedTabData(win)); |
michael@0 | 50 | |
michael@0 | 51 | is(cData.length, Math.min(iClosed.length + rClosed.length, maxTabsUndo), |
michael@0 | 52 | "Number of closed tabs is correct"); |
michael@0 | 53 | |
michael@0 | 54 | // When the closed tabs are merged the restored tabs are considered to be |
michael@0 | 55 | // closed more recently. |
michael@0 | 56 | for (let i = 0; i < cData.length; i++) { |
michael@0 | 57 | if (i < rClosed.length) { |
michael@0 | 58 | is(cData[i].state.entries[0].ID, rClosed[i].state.entries[0].ID, |
michael@0 | 59 | "Closed tab entry matches"); |
michael@0 | 60 | } else { |
michael@0 | 61 | is(cData[i].state.entries[0].ID, iClosed[i - rClosed.length].state.entries[0].ID, |
michael@0 | 62 | "Closed tab entry matches"); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // Clean up. |
michael@0 | 67 | gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); |
michael@0 | 68 | win.close(); |
michael@0 | 69 | }); |
michael@0 | 70 | |
michael@0 | 71 |