1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_586068-select.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; 1.9 + 1.10 +function test() { 1.11 + TestRunner.run(); 1.12 +} 1.13 + 1.14 +function runTests() { 1.15 + Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); 1.16 + registerCleanupFunction(function () { 1.17 + Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); 1.18 + }); 1.19 + 1.20 + let state = { windows: [{ tabs: [ 1.21 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, 1.22 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, 1.23 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, 1.24 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, 1.25 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, 1.26 + { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } } 1.27 + ], selected: 1 }] }; 1.28 + 1.29 + let expectedCounts = [ 1.30 + [5, 1, 0], 1.31 + [4, 1, 1], 1.32 + [3, 1, 2], 1.33 + [2, 1, 3], 1.34 + [1, 1, 4], 1.35 + [0, 1, 5] 1.36 + ]; 1.37 + let tabOrder = [0, 5, 1, 4, 3, 2]; 1.38 + 1.39 + let loadCount = 0; 1.40 + gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { 1.41 + loadCount++; 1.42 + let expected = expectedCounts[loadCount - 1]; 1.43 + 1.44 + is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored"); 1.45 + is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring"); 1.46 + is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored"); 1.47 + 1.48 + if (loadCount < state.windows[0].tabs.length) { 1.49 + // double check that this tab was the right one 1.50 + let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq; 1.51 + let tab; 1.52 + for (let i = 0; i < window.gBrowser.tabs.length; i++) { 1.53 + if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) 1.54 + tab = window.gBrowser.tabs[i]; 1.55 + } 1.56 + 1.57 + is(ss.getTabValue(tab, "uniq"), expectedData, 1.58 + "load " + loadCount + " - correct tab was restored"); 1.59 + 1.60 + // select the next tab 1.61 + window.gBrowser.selectTabAtIndex(tabOrder[loadCount]); 1.62 + } else { 1.63 + gProgressListener.unsetCallback(); 1.64 + executeSoon(next); 1.65 + } 1.66 + }); 1.67 + 1.68 + yield ss.setBrowserState(JSON.stringify(state)); 1.69 +}