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 | /* 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 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/ |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | // Set the pref to true so we know exactly how many tabs should be restoring at |
michael@0 | 21 | // any given time. This guarantees that a finishing load won't start another. |
michael@0 | 22 | Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); |
michael@0 | 23 | |
michael@0 | 24 | let state = { windows: [{ tabs: [ |
michael@0 | 25 | { entries: [{ url: "http://example.org/#1" }] }, |
michael@0 | 26 | { entries: [{ url: "http://example.org/#2" }] }, |
michael@0 | 27 | { entries: [{ url: "http://example.org/#3" }] }, |
michael@0 | 28 | { entries: [{ url: "http://example.org/#4" }] } |
michael@0 | 29 | ], selected: 1 }] }; |
michael@0 | 30 | |
michael@0 | 31 | let tabsForEnsure = {}; |
michael@0 | 32 | state.windows[0].tabs.forEach(function(tab) { |
michael@0 | 33 | tabsForEnsure[tab.entries[0].url] = 1; |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | let tabsRestoring = 0; |
michael@0 | 37 | let tabsRestored = 0; |
michael@0 | 38 | |
michael@0 | 39 | function handleEvent(aEvent) { |
michael@0 | 40 | if (aEvent.type == "SSTabRestoring") |
michael@0 | 41 | tabsRestoring++; |
michael@0 | 42 | else |
michael@0 | 43 | tabsRestored++; |
michael@0 | 44 | |
michael@0 | 45 | if (tabsRestoring < state.windows[0].tabs.length || |
michael@0 | 46 | tabsRestored < 1) |
michael@0 | 47 | return; |
michael@0 | 48 | |
michael@0 | 49 | gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true); |
michael@0 | 50 | gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true); |
michael@0 | 51 | executeSoon(function() { |
michael@0 | 52 | checkAutocompleteResults(tabsForEnsure, cleanup); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // currentURI is set before SSTabRestoring is fired, so we can sucessfully check |
michael@0 | 57 | // after that has fired for all tabs. Since 1 tab will be restored though, we |
michael@0 | 58 | // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set. |
michael@0 | 59 | gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true); |
michael@0 | 60 | gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true); |
michael@0 | 61 | ss.setBrowserState(JSON.stringify(state)); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | // The following was taken from browser/base/content/test/general/browser_tabMatchesInAwesomebar.js |
michael@0 | 65 | // so that we could do the same sort of checking. |
michael@0 | 66 | var gController = Cc["@mozilla.org/autocomplete/controller;1"]. |
michael@0 | 67 | getService(Ci.nsIAutoCompleteController); |
michael@0 | 68 | |
michael@0 | 69 | function checkAutocompleteResults(aExpected, aCallback) { |
michael@0 | 70 | gController.input = { |
michael@0 | 71 | timeout: 10, |
michael@0 | 72 | textValue: "", |
michael@0 | 73 | searches: ["history"], |
michael@0 | 74 | searchParam: "enable-actions", |
michael@0 | 75 | popupOpen: false, |
michael@0 | 76 | minResultsForPopup: 0, |
michael@0 | 77 | invalidate: function() {}, |
michael@0 | 78 | disableAutoComplete: false, |
michael@0 | 79 | completeDefaultIndex: false, |
michael@0 | 80 | get popup() { return this; }, |
michael@0 | 81 | onSearchBegin: function() {}, |
michael@0 | 82 | onSearchComplete: function () |
michael@0 | 83 | { |
michael@0 | 84 | info("Found " + gController.matchCount + " matches."); |
michael@0 | 85 | // Check to see the expected uris and titles match up (in any order) |
michael@0 | 86 | for (let i = 0; i < gController.matchCount; i++) { |
michael@0 | 87 | let uri = gController.getValueAt(i).replace(/^moz-action:[^,]+,/i, ""); |
michael@0 | 88 | |
michael@0 | 89 | info("Search for '" + uri + "' in open tabs."); |
michael@0 | 90 | ok(uri in aExpected, "Registered open page found in autocomplete."); |
michael@0 | 91 | // Remove the found entry from expected results. |
michael@0 | 92 | delete aExpected[uri]; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | // Make sure there is no reported open page that is not open. |
michael@0 | 96 | for (let entry in aExpected) { |
michael@0 | 97 | ok(false, "'" + entry + "' not found in autocomplete."); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | executeSoon(aCallback); |
michael@0 | 101 | }, |
michael@0 | 102 | setSelectedIndex: function() {}, |
michael@0 | 103 | get searchCount() { return this.searches.length; }, |
michael@0 | 104 | getSearchAt: function(aIndex) this.searches[aIndex], |
michael@0 | 105 | QueryInterface: XPCOMUtils.generateQI([ |
michael@0 | 106 | Ci.nsIAutoCompleteInput, |
michael@0 | 107 | Ci.nsIAutoCompletePopup, |
michael@0 | 108 | ]) |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | info("Searching open pages."); |
michael@0 | 112 | gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage")); |
michael@0 | 113 | } |