Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | var gSessionStore = Cc["@mozilla.org/browser/sessionstore;1"] |
michael@0 | 9 | .getService(Ci.nsISessionStore); |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | runTests(); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function getState() { |
michael@0 | 16 | return JSON.parse(gSessionStore.getBrowserState()); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function getTabData() { |
michael@0 | 20 | return getState().windows[0].tabs; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function isValidTabData(aData) { |
michael@0 | 24 | return aData && aData.entries && aData.entries.length && |
michael@0 | 25 | typeof aData.index == "number"; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | gTests.push({ |
michael@0 | 29 | desc: "getBrowserState tests", |
michael@0 | 30 | run: function() { |
michael@0 | 31 | // Wait for Session Manager to be initialized. |
michael@0 | 32 | yield waitForCondition(() => window.__SSID); |
michael@0 | 33 | info(window.__SSID); |
michael@0 | 34 | let tabData1 = getTabData(); |
michael@0 | 35 | ok(tabData1.every(isValidTabData), "Tab data starts out valid"); |
michael@0 | 36 | |
michael@0 | 37 | // Open a tab. |
michael@0 | 38 | let tab = Browser.addTab("about:mozilla"); |
michael@0 | 39 | let tabData2 = getTabData(); |
michael@0 | 40 | is(tabData2.length, tabData1.length, "New tab not added yet."); |
michael@0 | 41 | |
michael@0 | 42 | // Wait for the tab's session data to be initialized. |
michael@0 | 43 | yield waitForMessage("Content:SessionHistory", tab.browser.messageManager); |
michael@0 | 44 | yield waitForMs(0); |
michael@0 | 45 | let tabData3 = getTabData(); |
michael@0 | 46 | is(tabData3.length, tabData1.length + 1, "New tab added."); |
michael@0 | 47 | ok(tabData3.every(isValidTabData), "Tab data still valid"); |
michael@0 | 48 | |
michael@0 | 49 | // Close the tab. |
michael@0 | 50 | Browser.closeTab(tab, { forceClose: true } ); |
michael@0 | 51 | let tabData4 = getTabData(); |
michael@0 | 52 | is(tabData4.length, tabData1.length, "Closed tab removed."); |
michael@0 | 53 | ok(tabData4.every(isValidTabData), "Tab data valid again"); |
michael@0 | 54 | } |
michael@0 | 55 | }); |