michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let stateBackup = ss.getBrowserState(); michael@0: michael@0: function cleanup() { michael@0: // Reset the pref michael@0: try { michael@0: Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); michael@0: } catch (e) {} michael@0: ss.setBrowserState(stateBackup); michael@0: executeSoon(finish); michael@0: } michael@0: michael@0: function test() { michael@0: /** Bug 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/ michael@0: waitForExplicitFinish(); michael@0: michael@0: // Set the pref to true so we know exactly how many tabs should be restoring at michael@0: // any given time. This guarantees that a finishing load won't start another. michael@0: Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); michael@0: michael@0: let state = { windows: [{ tabs: [ michael@0: { entries: [{ url: "http://example.org/#1" }] }, michael@0: { entries: [{ url: "http://example.org/#2" }] }, michael@0: { entries: [{ url: "http://example.org/#3" }] }, michael@0: { entries: [{ url: "http://example.org/#4" }] } michael@0: ], selected: 1 }] }; michael@0: michael@0: let tabsForEnsure = {}; michael@0: state.windows[0].tabs.forEach(function(tab) { michael@0: tabsForEnsure[tab.entries[0].url] = 1; michael@0: }); michael@0: michael@0: let tabsRestoring = 0; michael@0: let tabsRestored = 0; michael@0: michael@0: function handleEvent(aEvent) { michael@0: if (aEvent.type == "SSTabRestoring") michael@0: tabsRestoring++; michael@0: else michael@0: tabsRestored++; michael@0: michael@0: if (tabsRestoring < state.windows[0].tabs.length || michael@0: tabsRestored < 1) michael@0: return; michael@0: michael@0: gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true); michael@0: gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true); michael@0: executeSoon(function() { michael@0: checkAutocompleteResults(tabsForEnsure, cleanup); michael@0: }); michael@0: } michael@0: michael@0: // currentURI is set before SSTabRestoring is fired, so we can sucessfully check michael@0: // after that has fired for all tabs. Since 1 tab will be restored though, we michael@0: // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set. michael@0: gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true); michael@0: gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true); michael@0: ss.setBrowserState(JSON.stringify(state)); michael@0: } michael@0: michael@0: // The following was taken from browser/base/content/test/general/browser_tabMatchesInAwesomebar.js michael@0: // so that we could do the same sort of checking. michael@0: var gController = Cc["@mozilla.org/autocomplete/controller;1"]. michael@0: getService(Ci.nsIAutoCompleteController); michael@0: michael@0: function checkAutocompleteResults(aExpected, aCallback) { michael@0: gController.input = { michael@0: timeout: 10, michael@0: textValue: "", michael@0: searches: ["history"], michael@0: searchParam: "enable-actions", michael@0: popupOpen: false, michael@0: minResultsForPopup: 0, michael@0: invalidate: function() {}, michael@0: disableAutoComplete: false, michael@0: completeDefaultIndex: false, michael@0: get popup() { return this; }, michael@0: onSearchBegin: function() {}, michael@0: onSearchComplete: function () michael@0: { michael@0: info("Found " + gController.matchCount + " matches."); michael@0: // Check to see the expected uris and titles match up (in any order) michael@0: for (let i = 0; i < gController.matchCount; i++) { michael@0: let uri = gController.getValueAt(i).replace(/^moz-action:[^,]+,/i, ""); michael@0: michael@0: info("Search for '" + uri + "' in open tabs."); michael@0: ok(uri in aExpected, "Registered open page found in autocomplete."); michael@0: // Remove the found entry from expected results. michael@0: delete aExpected[uri]; michael@0: } michael@0: michael@0: // Make sure there is no reported open page that is not open. michael@0: for (let entry in aExpected) { michael@0: ok(false, "'" + entry + "' not found in autocomplete."); michael@0: } michael@0: michael@0: executeSoon(aCallback); michael@0: }, michael@0: setSelectedIndex: function() {}, michael@0: get searchCount() { return this.searches.length; }, michael@0: getSearchAt: function(aIndex) this.searches[aIndex], michael@0: QueryInterface: XPCOMUtils.generateQI([ michael@0: Ci.nsIAutoCompleteInput, michael@0: Ci.nsIAutoCompletePopup, michael@0: ]) michael@0: }; michael@0: michael@0: info("Searching open pages."); michael@0: gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage")); michael@0: }